FLANG

CharacterExpr.h
1 //===-- Lower/CharacterExpr.h -- lowering of characters ---------*- 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_LOWER_CHARACTEREXPR_H
10 #define FORTRAN_LOWER_CHARACTEREXPR_H
11
12 #include "flang/Lower/FIRBuilder.h"
13 #include "flang/Lower/Support/BoxValue.h"
14
15 namespace Fortran::lower {
16
18 class CharacterExprHelper {
19 public:
21 explicit CharacterExprHelper(FirOpBuilder &builder, mlir::Location loc)
22 : builder{builder}, loc{loc} {}
23 CharacterExprHelper(const CharacterExprHelper &) = delete;
24
31
34 void createCopy(mlir::Value dest, mlir::Value src, mlir::Value count);
35
40 void createPadding(mlir::Value str, mlir::Value lower, mlir::Value upper);
41
44 mlir::Value createSubstring(mlir::Value str,
45 llvm::ArrayRef<mlir::Value> bounds);
46
48 mlir::Value createBlankConstant(fir::CharacterType type);
49
52 void createAssign(mlir::Value lhs, mlir::Value rhs);
53
56 void createAssign(mlir::Value lptr, mlir::Value llen, mlir::Value rptr,
57 mlir::Value rlen);
58
60 mlir::Value createConcatenate(mlir::Value lhs, mlir::Value rhs);
61
63 mlir::Value createLenTrim(mlir::Value str);
64
68 mlir::Value createEmboxChar(mlir::Value addr, mlir::Value len);
69
71 std::pair<mlir::Value, mlir::Value> createUnboxChar(mlir::Value boxChar);
72
75 mlir::Value createCharacterTemp(mlir::Type type, mlir::Value len);
76
79 mlir::Value createCharacterTemp(mlir::Type type, int len) {
80 return createTemp(type, len);
81 }
82
90 std::pair<mlir::Value, mlir::Value> materializeCharacter(mlir::Value str);
91
94 static bool isCharacterLiteral(mlir::Type type);
95
100 static bool isCharacter(mlir::Type type);
101
103 static int getCharacterKind(mlir::Type type);
104
107 mlir::Type getLengthType() { return builder.getIndexType(); }
108
119 fir::ExtendedValue toExtendedValue(mlir::Value character,
120 mlir::Value len = {});
121
122 private:
123 fir::CharBoxValue materializeValue(const fir::CharBoxValue &str);
124 fir::CharBoxValue toDataLengthPair(mlir::Value character);
125 mlir::Type getReferenceType(const fir::CharBoxValue &c) const;
126 mlir::Value createEmbox(const fir::CharBoxValue &str);
127 mlir::Value createLoadCharAt(const fir::CharBoxValue &str, mlir::Value index);
128 void createStoreCharAt(const fir::CharBoxValue &str, mlir::Value index,
129 mlir::Value c);
130 void createCopy(const fir::CharBoxValue &dest, const fir::CharBoxValue &src,
131 mlir::Value count);
132 void createPadding(const fir::CharBoxValue &str, mlir::Value lower,
133 mlir::Value upper);
134 fir::CharBoxValue createTemp(mlir::Type type, mlir::Value len);
135 void createLengthOneAssign(const fir::CharBoxValue &lhs,
136 const fir::CharBoxValue &rhs);
137 void createAssign(const fir::CharBoxValue &lhs, const fir::CharBoxValue &rhs);
138 fir::CharBoxValue createConcatenate(const fir::CharBoxValue &lhs,
139 const fir::CharBoxValue &rhs);
140 fir::CharBoxValue createSubstring(const fir::CharBoxValue &str,
141 llvm::ArrayRef<mlir::Value> bounds);
142 mlir::Value createLenTrim(const fir::CharBoxValue &str);
143 mlir::Value createTemp(mlir::Type type, int len);
144 mlir::Value createBlankConstantCode(fir::CharacterType type);
145
146 private:
147 FirOpBuilder &builder;
148 mlir::Location loc;
149 };
150
151 } // namespace Fortran::lower
152
153 #endif // FORTRAN_LOWER_CHARACTEREXPR_H
Fortran::lower::CharacterExprHelper::getLengthType
mlir::Type getLengthType()
Definition: CharacterExpr.h:107
Fortran::lower::CharacterExprHelper::CharacterExprHelper
CharacterExprHelper(FirOpBuilder &builder, mlir::Location loc)
Constructor.
Definition: CharacterExpr.h:21
Fortran::lower::CharacterExprHelper::isCharacterLiteral
static bool isCharacterLiteral(mlir::Type type)
Definition: CharacterExpr.cpp:466
Fortran::lower::CharacterExprHelper::isCharacter
static bool isCharacter(mlir::Type type)
Definition: CharacterExpr.cpp:473
Fortran::lower::CharacterExprHelper::createCharacterTemp
mlir::Value createCharacterTemp(mlir::Type type, int len)
Definition: CharacterExpr.h:79
Fortran::lower::CharacterExprHelper::createSubstring
mlir::Value createSubstring(mlir::Value str, llvm::ArrayRef< mlir::Value > bounds)
Definition: CharacterExpr.cpp:411
Fortran::lower::CharacterExprHelper::createCharacterTemp
mlir::Value createCharacterTemp(mlir::Type type, mlir::Value len)
Definition: CharacterExpr.cpp:453
Fortran::lower::CharacterExprHelper::toExtendedValue
fir::ExtendedValue toExtendedValue(mlir::Value character, mlir::Value len={})
Definition: CharacterExpr.cpp:77
Fortran::lower::CharacterExprHelper::createUnboxChar
std::pair< mlir::Value, mlir::Value > createUnboxChar(mlir::Value boxChar)
Unbox boxchar into (fir.ref<fir.char<kind>>, getLengthType()).
Definition: CharacterExpr.cpp:447
Fortran::lower::CharacterExprHelper::createEmboxChar
mlir::Value createEmboxChar(mlir::Value addr, mlir::Value len)
Definition: CharacterExpr.cpp:441
llvm::ArrayRef
Definition: FIRType.h:20
fir::CharacterType
Definition: FIRType.h:126
fir::CharBoxValue
Definition: BoxValue.h:59
Fortran::lower::CharacterExprHelper
Helper to facilitate lowering of CHARACTER in FIR.
Definition: CharacterExpr.h:18
Fortran::lower::CharacterExprHelper::getCharacterKind
static int getCharacterKind(mlir::Type type)
Extract the kind of a character type.
Definition: CharacterExpr.cpp:484
Fortran::lower::CharacterExprHelper::materializeCharacter
std::pair< mlir::Value, mlir::Value > materializeCharacter(mlir::Value str)
Definition: CharacterExpr.cpp:459
Fortran::lower::CharacterExprHelper::createConcatenate
mlir::Value createConcatenate(mlir::Value lhs, mlir::Value rhs)
Create lhs // rhs in temp obtained with fir.alloca.
Definition: CharacterExpr.cpp:434
Fortran::lower::CharacterExprHelper::createCopy
void createCopy(mlir::Value dest, mlir::Value src, mlir::Value count)
Definition: CharacterExpr.cpp:399
Fortran::lower::CharacterExprHelper::createAssign
void createAssign(mlir::Value lhs, mlir::Value rhs)
Definition: CharacterExpr.cpp:416
Fortran::lower::FirOpBuilder
Definition: FIRBuilder.h:39
fir::ExtendedValue
Definition: BoxValue.h:210
Fortran::lower::CharacterExprHelper::createPadding
void createPadding(mlir::Value str, mlir::Value lower, mlir::Value upper)
Definition: CharacterExpr.cpp:405
Fortran::lower::CharacterExprHelper::createLenTrim
mlir::Value createLenTrim(mlir::Value str)
LEN_TRIM intrinsic.
Definition: CharacterExpr.cpp:422
Fortran::lower::CharacterExprHelper::createBlankConstant
mlir::Value createBlankConstant(fir::CharacterType type)
Return blank character of given type !fir.char<kind>
Definition: CharacterExpr.cpp:394