1//===- TemporaryStack.cpp ---- temporary stack runtime API calls ----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "flang/Optimizer/Builder/Runtime/TemporaryStack.h"
10#include "flang/Optimizer/Builder/FIRBuilder.h"
11#include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
12#include "flang/Runtime/temporary-stack.h"
13
14using namespace Fortran::runtime;
15
16mlir::Value fir::runtime::genCreateValueStack(mlir::Location loc,
17 fir::FirOpBuilder &builder) {
18 mlir::func::FuncOp func =
19 fir::runtime::getRuntimeFunc<mkRTKey(CreateValueStack)>(loc, builder);
20 mlir::FunctionType funcType = func.getFunctionType();
21 mlir::Value sourceFile = fir::factory::locationToFilename(builder, loc);
22 mlir::Value sourceLine =
23 fir::factory::locationToLineNo(builder, loc, funcType.getInput(1));
24 auto args = fir::runtime::createArguments(builder, loc, funcType, sourceFile,
25 sourceLine);
26 return builder.create<fir::CallOp>(loc, func, args).getResult(0);
27}
28
29void fir::runtime::genPushValue(mlir::Location loc, fir::FirOpBuilder &builder,
30 mlir::Value opaquePtr, mlir::Value boxValue) {
31 mlir::func::FuncOp func =
32 fir::runtime::getRuntimeFunc<mkRTKey(PushValue)>(loc, builder);
33 mlir::FunctionType funcType = func.getFunctionType();
34 auto args = fir::runtime::createArguments(builder, loc, funcType, opaquePtr,
35 boxValue);
36 builder.create<fir::CallOp>(loc, func, args);
37}
38
39void fir::runtime::genValueAt(mlir::Location loc, fir::FirOpBuilder &builder,
40 mlir::Value opaquePtr, mlir::Value i,
41 mlir::Value retValueBox) {
42 mlir::func::FuncOp func =
43 fir::runtime::getRuntimeFunc<mkRTKey(ValueAt)>(loc, builder);
44 mlir::FunctionType funcType = func.getFunctionType();
45 auto args = fir::runtime::createArguments(builder, loc, funcType, opaquePtr,
46 i, retValueBox);
47 builder.create<fir::CallOp>(loc, func, args);
48}
49
50void fir::runtime::genDestroyValueStack(mlir::Location loc,
51 fir::FirOpBuilder &builder,
52 mlir::Value opaquePtr) {
53 mlir::func::FuncOp func =
54 fir::runtime::getRuntimeFunc<mkRTKey(DestroyValueStack)>(loc, builder);
55 mlir::FunctionType funcType = func.getFunctionType();
56 auto args = fir::runtime::createArguments(builder, loc, funcType, opaquePtr);
57 builder.create<fir::CallOp>(loc, func, args);
58}
59
60mlir::Value fir::runtime::genCreateDescriptorStack(mlir::Location loc,
61 fir::FirOpBuilder &builder) {
62 mlir::func::FuncOp func =
63 fir::runtime::getRuntimeFunc<mkRTKey(CreateDescriptorStack)>(loc,
64 builder);
65 mlir::FunctionType funcType = func.getFunctionType();
66 mlir::Value sourceFile = fir::factory::locationToFilename(builder, loc);
67 mlir::Value sourceLine =
68 fir::factory::locationToLineNo(builder, loc, funcType.getInput(1));
69 auto args = fir::runtime::createArguments(builder, loc, funcType, sourceFile,
70 sourceLine);
71 return builder.create<fir::CallOp>(loc, func, args).getResult(0);
72}
73
74void fir::runtime::genPushDescriptor(mlir::Location loc,
75 fir::FirOpBuilder &builder,
76 mlir::Value opaquePtr,
77 mlir::Value boxDescriptor) {
78 mlir::func::FuncOp func =
79 fir::runtime::getRuntimeFunc<mkRTKey(PushDescriptor)>(loc, builder);
80 mlir::FunctionType funcType = func.getFunctionType();
81 auto args = fir::runtime::createArguments(builder, loc, funcType, opaquePtr,
82 boxDescriptor);
83 builder.create<fir::CallOp>(loc, func, args);
84}
85
86void fir::runtime::genDescriptorAt(mlir::Location loc,
87 fir::FirOpBuilder &builder,
88 mlir::Value opaquePtr, mlir::Value i,
89 mlir::Value retDescriptorBox) {
90 mlir::func::FuncOp func =
91 fir::runtime::getRuntimeFunc<mkRTKey(DescriptorAt)>(loc, builder);
92 mlir::FunctionType funcType = func.getFunctionType();
93 auto args = fir::runtime::createArguments(builder, loc, funcType, opaquePtr,
94 i, retDescriptorBox);
95 builder.create<fir::CallOp>(loc, func, args);
96}
97
98void fir::runtime::genDestroyDescriptorStack(mlir::Location loc,
99 fir::FirOpBuilder &builder,
100 mlir::Value opaquePtr) {
101 mlir::func::FuncOp func =
102 fir::runtime::getRuntimeFunc<mkRTKey(DestroyDescriptorStack)>(loc,
103 builder);
104 mlir::FunctionType funcType = func.getFunctionType();
105 auto args = fir::runtime::createArguments(builder, loc, funcType, opaquePtr);
106 builder.create<fir::CallOp>(loc, func, args);
107}
108

source code of flang/lib/Optimizer/Builder/Runtime/TemporaryStack.cpp