xref: /llvm-project/flang/include/flang/Optimizer/Builder/Runtime/Character.h (revision 6c8d8d10455a3d38a92102ae3a94e1c06d3eb363)
1 //===-- Character.h -- generate calls to character runtime API --*- C++ -*-===//
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 #ifndef FORTRAN_OPTIMIZER_BUILDER_RUNTIME_CHARACTER_H
10 #define FORTRAN_OPTIMIZER_BUILDER_RUNTIME_CHARACTER_H
11 
12 #include "mlir/Dialect/Arith/IR/Arith.h"
13 #include "mlir/Dialect/Func/IR/FuncOps.h"
14 
15 namespace fir {
16 class ExtendedValue;
17 class FirOpBuilder;
18 } // namespace fir
19 
20 namespace fir::runtime {
21 
22 /// Generate a call to the `ADJUSTL` runtime.
23 /// This calls the simple runtime entry point that then calls into the more
24 /// complex runtime cases handling left or right adjustments.
25 ///
26 /// \p resultBox must be an unallocated allocatable used for the temporary
27 /// result. \p StringBox must be a `fir.box` describing the `ADJUSTL` string
28 /// argument. Note that the \p genAdjust() helper is called to do the majority
29 /// of the lowering work.
30 void genAdjustL(fir::FirOpBuilder &builder, mlir::Location loc,
31                 mlir::Value resultBox, mlir::Value stringBox);
32 
33 /// Generate a call to the `ADJUSTR` runtime.
34 /// This calls the simple runtime entry point that then calls into the more
35 /// complex runtime cases handling left or right adjustments.
36 ///
37 /// \p resultBox must be an unallocated allocatable used for the temporary
38 /// result.  \p StringBox must be a fir.box describing the adjustr string
39 /// argument. Note that the \p genAdjust() helper is called to do the majority
40 /// of the lowering work.
41 void genAdjustR(fir::FirOpBuilder &builder, mlir::Location loc,
42                 mlir::Value resultBox, mlir::Value stringBox);
43 
44 /// Generate call to a character comparison for two ssa-values of type
45 /// `boxchar`.
46 mlir::Value genCharCompare(fir::FirOpBuilder &builder, mlir::Location loc,
47                            mlir::arith::CmpIPredicate cmp,
48                            const fir::ExtendedValue &lhs,
49                            const fir::ExtendedValue &rhs);
50 
51 /// Generate call to a character comparison op for two unboxed variables. There
52 /// are 4 arguments, 2 for the lhs and 2 for the rhs. Each CHARACTER must pass a
53 /// reference to its buffer (`ref<char<K>>`) and its LEN type parameter (some
54 /// integral type).
55 mlir::Value genCharCompare(fir::FirOpBuilder &builder, mlir::Location loc,
56                            mlir::arith::CmpIPredicate cmp, mlir::Value lhsBuff,
57                            mlir::Value lhsLen, mlir::Value rhsBuff,
58                            mlir::Value rhsLen);
59 
60 /// Generate call to INDEX runtime.
61 /// This calls the simple runtime entry points based on the KIND of the string.
62 /// No descriptors are used.
63 mlir::Value genIndex(fir::FirOpBuilder &builder, mlir::Location loc, int kind,
64                      mlir::Value stringBase, mlir::Value stringLen,
65                      mlir::Value substringBase, mlir::Value substringLen,
66                      mlir::Value back);
67 
68 /// Generate call to INDEX runtime.
69 /// This calls the descriptor based runtime call implementation for the index
70 /// intrinsic.
71 void genIndexDescriptor(fir::FirOpBuilder &builder, mlir::Location loc,
72                         mlir::Value resultBox, mlir::Value stringBox,
73                         mlir::Value substringBox, mlir::Value backOpt,
74                         mlir::Value kind);
75 
76 /// Generate call to repeat runtime.
77 ///   \p resultBox must be an unallocated allocatable used for the temporary
78 ///   result. \p stringBox must be a fir.box describing repeat string argument.
79 ///   \p ncopies must be a value representing the number of copies.
80 /// The runtime will always allocate the resultBox.
81 void genRepeat(fir::FirOpBuilder &builder, mlir::Location loc,
82                mlir::Value resultBox, mlir::Value stringBox,
83                mlir::Value ncopies);
84 
85 /// Generate call to trim runtime.
86 ///   \p resultBox must be an unallocated allocatable used for the temporary
87 ///   result. \p stringBox must be a fir.box describing trim string argument.
88 /// The runtime will always allocate the resultBox.
89 void genTrim(fir::FirOpBuilder &builder, mlir::Location loc,
90              mlir::Value resultBox, mlir::Value stringBox);
91 
92 /// Generate call to scan runtime.
93 /// This calls the descriptor based runtime call implementation of the scan
94 /// intrinsics.
95 void genScanDescriptor(fir::FirOpBuilder &builder, mlir::Location loc,
96                        mlir::Value resultBox, mlir::Value stringBox,
97                        mlir::Value setBox, mlir::Value backBox,
98                        mlir::Value kind);
99 
100 /// Generate call to the scan runtime routine that is specialized on
101 /// \param kind.
102 /// The \param kind represents the kind of the elements in the strings.
103 mlir::Value genScan(fir::FirOpBuilder &builder, mlir::Location loc, int kind,
104                     mlir::Value stringBase, mlir::Value stringLen,
105                     mlir::Value setBase, mlir::Value setLen, mlir::Value back);
106 
107 /// Generate call to verify runtime.
108 /// This calls the descriptor based runtime call implementation of the scan
109 /// intrinsics.
110 void genVerifyDescriptor(fir::FirOpBuilder &builder, mlir::Location loc,
111                          mlir::Value resultBox, mlir::Value stringBox,
112                          mlir::Value setBox, mlir::Value backBox,
113                          mlir::Value kind);
114 
115 /// Generate call to the verify runtime routine that is specialized on
116 /// \param kind.
117 /// The \param kind represents the kind of the elements in the strings.
118 mlir::Value genVerify(fir::FirOpBuilder &builder, mlir::Location loc, int kind,
119                       mlir::Value stringBase, mlir::Value stringLen,
120                       mlir::Value setBase, mlir::Value setLen,
121                       mlir::Value back);
122 
123 } // namespace fir::runtime
124 
125 #endif // FORTRAN_OPTIMIZER_BUILDER_RUNTIME_CHARACTER_H
126