@@ -37,7 +37,8 @@ LLVMTypeConverter::LLVMTypeConverter(mlir::ModuleOp module, bool applyTBAA)
37
37
specifics (CodeGenSpecifics::get(module .getContext(),
38
38
getTargetTriple (module ),
39
39
getKindMapping (module ))),
40
- tbaaBuilder (module ->getContext (), applyTBAA) {
40
+ tbaaBuilder (
41
+ std::make_unique<TBAABuilder>(module ->getContext (), applyTBAA)) {
41
42
LLVM_DEBUG (llvm::dbgs () << " FIR type converter\n " );
42
43
43
44
// Each conversion should return a value of type mlir::Type.
@@ -155,20 +156,19 @@ LLVMTypeConverter::LLVMTypeConverter(mlir::ModuleOp module, bool applyTBAA)
155
156
156
157
// i32 is used here because LLVM wants i32 constants when indexing into struct
157
158
// types. Indexing into other aggregate types is more flexible.
158
- mlir::Type LLVMTypeConverter::offsetType () {
159
+ mlir::Type LLVMTypeConverter::offsetType () const {
159
160
return mlir::IntegerType::get (&getContext (), 32 );
160
161
}
161
162
162
163
// i64 can be used to index into aggregates like arrays
163
- mlir::Type LLVMTypeConverter::indexType () {
164
+ mlir::Type LLVMTypeConverter::indexType () const {
164
165
return mlir::IntegerType::get (&getContext (), 64 );
165
166
}
166
167
167
168
// fir.type<name(p : TY'...){f : TY...}> --> llvm<"%name = { ty... }">
168
- std::optional<mlir::LogicalResult>
169
- LLVMTypeConverter::convertRecordType (fir::RecordType derived,
170
- llvm::SmallVectorImpl<mlir::Type> &results,
171
- llvm::ArrayRef<mlir::Type> callStack) {
169
+ std::optional<mlir::LogicalResult> LLVMTypeConverter::convertRecordType (
170
+ fir::RecordType derived, llvm::SmallVectorImpl<mlir::Type> &results,
171
+ llvm::ArrayRef<mlir::Type> callStack) const {
172
172
auto name = derived.getName ();
173
173
auto st = mlir::LLVM::LLVMStructType::getIdentified (&getContext (), name);
174
174
if (llvm::count (callStack, derived) > 1 ) {
@@ -192,14 +192,14 @@ LLVMTypeConverter::convertRecordType(fir::RecordType derived,
192
192
193
193
// Is an extended descriptor needed given the element type of a fir.box type ?
194
194
// Extended descriptors are required for derived types.
195
- bool LLVMTypeConverter::requiresExtendedDesc (mlir::Type boxElementType) {
195
+ bool LLVMTypeConverter::requiresExtendedDesc (mlir::Type boxElementType) const {
196
196
auto eleTy = fir::unwrapSequenceType (boxElementType);
197
197
return eleTy.isa <fir::RecordType>();
198
198
}
199
199
200
200
// This corresponds to the descriptor as defined in ISO_Fortran_binding.h and
201
201
// the addendum defined in descriptor.h.
202
- mlir::Type LLVMTypeConverter::convertBoxType (BaseBoxType box, int rank) {
202
+ mlir::Type LLVMTypeConverter::convertBoxType (BaseBoxType box, int rank) const {
203
203
// (base_addr*, elem_len, version, rank, type, attribute, f18Addendum, [dim]
204
204
llvm::SmallVector<mlir::Type> dataDescFields;
205
205
mlir::Type ele = box.getEleTy ();
@@ -269,14 +269,14 @@ mlir::Type LLVMTypeConverter::convertBoxType(BaseBoxType box, int rank) {
269
269
270
270
// / Convert fir.box type to the corresponding llvm struct type instead of a
271
271
// / pointer to this struct type.
272
- mlir::Type LLVMTypeConverter::convertBoxTypeAsStruct (BaseBoxType box) {
272
+ mlir::Type LLVMTypeConverter::convertBoxTypeAsStruct (BaseBoxType box) const {
273
273
return convertBoxType (box)
274
274
.cast <mlir::LLVM::LLVMPointerType>()
275
275
.getElementType ();
276
276
}
277
277
278
278
// fir.boxproc<any> --> llvm<"{ any*, i8* }">
279
- mlir::Type LLVMTypeConverter::convertBoxProcType (BoxProcType boxproc) {
279
+ mlir::Type LLVMTypeConverter::convertBoxProcType (BoxProcType boxproc) const {
280
280
auto funcTy = convertType (boxproc.getEleTy ());
281
281
auto i8PtrTy = mlir::LLVM::LLVMPointerType::get (
282
282
mlir::IntegerType::get (&getContext (), 8 ));
@@ -285,13 +285,13 @@ mlir::Type LLVMTypeConverter::convertBoxProcType(BoxProcType boxproc) {
285
285
/* isPacked=*/ false );
286
286
}
287
287
288
- unsigned LLVMTypeConverter::characterBitsize (fir::CharacterType charTy) {
288
+ unsigned LLVMTypeConverter::characterBitsize (fir::CharacterType charTy) const {
289
289
return kindMapping.getCharacterBitsize (charTy.getFKind ());
290
290
}
291
291
292
292
// fir.char<k,?> --> llvm<"ix"> where ix is scaled by kind mapping
293
293
// fir.char<k,n> --> llvm.array<n x "ix">
294
- mlir::Type LLVMTypeConverter::convertCharType (fir::CharacterType charTy) {
294
+ mlir::Type LLVMTypeConverter::convertCharType (fir::CharacterType charTy) const {
295
295
auto iTy = mlir::IntegerType::get (&getContext (), characterBitsize (charTy));
296
296
if (charTy.getLen () == fir::CharacterType::unknownLen ())
297
297
return iTy;
@@ -300,13 +300,13 @@ mlir::Type LLVMTypeConverter::convertCharType(fir::CharacterType charTy) {
300
300
301
301
// convert a front-end kind value to either a std or LLVM IR dialect type
302
302
// fir.real<n> --> llvm.anyfloat where anyfloat is a kind mapping
303
- mlir::Type LLVMTypeConverter::convertRealType (fir::KindTy kind) {
303
+ mlir::Type LLVMTypeConverter::convertRealType (fir::KindTy kind) const {
304
304
return fir::fromRealTypeID (&getContext (), kindMapping.getRealTypeID (kind),
305
305
kind);
306
306
}
307
307
308
308
// fir.array<c ... :any> --> llvm<"[...[c x any]]">
309
- mlir::Type LLVMTypeConverter::convertSequenceType (SequenceType seq) {
309
+ mlir::Type LLVMTypeConverter::convertSequenceType (SequenceType seq) const {
310
310
auto baseTy = convertType (seq.getEleTy ());
311
311
if (characterWithDynamicLen (seq.getEleTy ()))
312
312
return mlir::LLVM::LLVMPointerType::get (baseTy);
@@ -328,7 +328,8 @@ mlir::Type LLVMTypeConverter::convertSequenceType(SequenceType seq) {
328
328
// fir.tdesc<any> --> llvm<"i8*">
329
329
// TODO: For now use a void*, however pointer identity is not sufficient for
330
330
// the f18 object v. class distinction (F2003).
331
- mlir::Type LLVMTypeConverter::convertTypeDescType (mlir::MLIRContext *ctx) {
331
+ mlir::Type
332
+ LLVMTypeConverter::convertTypeDescType (mlir::MLIRContext *ctx) const {
332
333
return mlir::LLVM::LLVMPointerType::get (
333
334
mlir::IntegerType::get (&getContext (), 8 ));
334
335
}
@@ -337,8 +338,8 @@ mlir::Type LLVMTypeConverter::convertTypeDescType(mlir::MLIRContext *ctx) {
337
338
void LLVMTypeConverter::attachTBAATag (mlir::LLVM::AliasAnalysisOpInterface op,
338
339
mlir::Type baseFIRType,
339
340
mlir::Type accessFIRType,
340
- mlir::LLVM::GEPOp gep) {
341
- tbaaBuilder. attachTBAATag (op, baseFIRType, accessFIRType, gep);
341
+ mlir::LLVM::GEPOp gep) const {
342
+ tbaaBuilder-> attachTBAATag (op, baseFIRType, accessFIRType, gep);
342
343
}
343
344
344
345
} // namespace fir
0 commit comments