1 | //===-- Assign.cpp -- generate assignment 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/Assign.h" |
10 | #include "flang/Optimizer/Builder/FIRBuilder.h" |
11 | #include "flang/Optimizer/Builder/Runtime/RTBuilder.h" |
12 | #include "flang/Runtime/assign.h" |
13 | |
14 | using namespace Fortran::runtime; |
15 | |
16 | void fir::runtime::genAssign(fir::FirOpBuilder &builder, mlir::Location loc, |
17 | mlir::Value destBox, mlir::Value sourceBox) { |
18 | auto func = fir::runtime::getRuntimeFunc<mkRTKey(Assign)>(loc, builder); |
19 | auto fTy = func.getFunctionType(); |
20 | auto sourceFile = fir::factory::locationToFilename(builder, loc); |
21 | auto sourceLine = |
22 | fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); |
23 | auto args = fir::runtime::createArguments(builder, loc, fTy, destBox, |
24 | sourceBox, sourceFile, sourceLine); |
25 | builder.create<fir::CallOp>(loc, func, args); |
26 | } |
27 | |
28 | void fir::runtime::genAssignPolymorphic(fir::FirOpBuilder &builder, |
29 | mlir::Location loc, mlir::Value destBox, |
30 | mlir::Value sourceBox) { |
31 | auto func = |
32 | fir::runtime::getRuntimeFunc<mkRTKey(AssignPolymorphic)>(loc, builder); |
33 | auto fTy = func.getFunctionType(); |
34 | auto sourceFile = fir::factory::locationToFilename(builder, loc); |
35 | auto sourceLine = |
36 | fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); |
37 | auto args = fir::runtime::createArguments(builder, loc, fTy, destBox, |
38 | sourceBox, sourceFile, sourceLine); |
39 | builder.create<fir::CallOp>(loc, func, args); |
40 | } |
41 | |
42 | void fir::runtime::genAssignExplicitLengthCharacter(fir::FirOpBuilder &builder, |
43 | mlir::Location loc, |
44 | mlir::Value destBox, |
45 | mlir::Value sourceBox) { |
46 | auto func = |
47 | fir::runtime::getRuntimeFunc<mkRTKey(AssignExplicitLengthCharacter)>( |
48 | loc, builder); |
49 | auto fTy = func.getFunctionType(); |
50 | auto sourceFile = fir::factory::locationToFilename(builder, loc); |
51 | auto sourceLine = |
52 | fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); |
53 | auto args = fir::runtime::createArguments(builder, loc, fTy, destBox, |
54 | sourceBox, sourceFile, sourceLine); |
55 | builder.create<fir::CallOp>(loc, func, args); |
56 | } |
57 | |
58 | void fir::runtime::genAssignTemporary(fir::FirOpBuilder &builder, |
59 | mlir::Location loc, mlir::Value destBox, |
60 | mlir::Value sourceBox) { |
61 | auto func = |
62 | fir::runtime::getRuntimeFunc<mkRTKey(AssignTemporary)>(loc, builder); |
63 | auto fTy = func.getFunctionType(); |
64 | auto sourceFile = fir::factory::locationToFilename(builder, loc); |
65 | auto sourceLine = |
66 | fir::factory::locationToLineNo(builder, loc, fTy.getInput(3)); |
67 | auto args = fir::runtime::createArguments(builder, loc, fTy, destBox, |
68 | sourceBox, sourceFile, sourceLine); |
69 | builder.create<fir::CallOp>(loc, func, args); |
70 | } |
71 | |
72 | void fir::runtime::genCopyOutAssign(fir::FirOpBuilder &builder, |
73 | mlir::Location loc, mlir::Value destBox, |
74 | mlir::Value sourceBox, bool skipToInit) { |
75 | auto func = |
76 | fir::runtime::getRuntimeFunc<mkRTKey(CopyOutAssign)>(loc, builder); |
77 | auto fTy = func.getFunctionType(); |
78 | auto sourceFile = fir::factory::locationToFilename(builder, loc); |
79 | auto sourceLine = |
80 | fir::factory::locationToLineNo(builder, loc, fTy.getInput(4)); |
81 | auto i1Ty = builder.getIntegerType(1); |
82 | auto skipToInitVal = builder.createIntegerConstant(loc, i1Ty, skipToInit); |
83 | auto args = |
84 | fir::runtime::createArguments(builder, loc, fTy, destBox, sourceBox, |
85 | skipToInitVal, sourceFile, sourceLine); |
86 | builder.create<fir::CallOp>(loc, func, args); |
87 | } |
88 | |