FLANG
DebugTypeGenerator.h
1//===-- DebugTypeGenerator.h -- type conversion ------------------- 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// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef FORTRAN_OPTIMIZER_TRANSFORMS_DEBUGTYPEGENERATOR_H
14#define FORTRAN_OPTIMIZER_TRANSFORMS_DEBUGTYPEGENERATOR_H
15
16#include "flang/Optimizer/CodeGen/CGOps.h"
17#include "flang/Optimizer/CodeGen/TypeConverter.h"
18#include "flang/Optimizer/Dialect/FIRType.h"
19#include "flang/Optimizer/Dialect/Support/FIRContext.h"
20#include "flang/Optimizer/Dialect/Support/KindMapping.h"
21#include "flang/Optimizer/Support/DataLayout.h"
22#include "llvm/Support/Debug.h"
23
24namespace fir {
25
28public:
29 DebugTypeGenerator(mlir::ModuleOp module, mlir::SymbolTable *symbolTable,
30 const mlir::DataLayout &dl);
31
32 mlir::LLVM::DITypeAttr convertType(mlir::Type Ty,
33 mlir::LLVM::DIFileAttr fileAttr,
34 mlir::LLVM::DIScopeAttr scope,
35 fir::cg::XDeclareOp declOp);
36
37private:
38 mlir::LLVM::DITypeAttr convertRecordType(fir::RecordType Ty,
39 mlir::LLVM::DIFileAttr fileAttr,
40 mlir::LLVM::DIScopeAttr scope,
41 fir::cg::XDeclareOp declOp);
42 mlir::LLVM::DITypeAttr convertTupleType(mlir::TupleType Ty,
43 mlir::LLVM::DIFileAttr fileAttr,
44 mlir::LLVM::DIScopeAttr scope,
45 fir::cg::XDeclareOp declOp);
46 mlir::LLVM::DITypeAttr convertSequenceType(fir::SequenceType seqTy,
47 mlir::LLVM::DIFileAttr fileAttr,
48 mlir::LLVM::DIScopeAttr scope,
49 fir::cg::XDeclareOp declOp);
50 mlir::LLVM::DITypeAttr convertVectorType(fir::VectorType vecTy,
51 mlir::LLVM::DIFileAttr fileAttr,
52 mlir::LLVM::DIScopeAttr scope,
53 fir::cg::XDeclareOp declOp);
54
59 mlir::LLVM::DITypeAttr convertBoxedSequenceType(
60 fir::SequenceType seqTy, mlir::LLVM::DIFileAttr fileAttr,
61 mlir::LLVM::DIScopeAttr scope, fir::cg::XDeclareOp declOp,
62 bool genAllocated, bool genAssociated);
63 mlir::LLVM::DITypeAttr convertCharacterType(fir::CharacterType charTy,
64 mlir::LLVM::DIFileAttr fileAttr,
65 mlir::LLVM::DIScopeAttr scope,
66 fir::cg::XDeclareOp declOp,
67 bool hasDescriptor);
68
69 mlir::LLVM::DITypeAttr convertPointerLikeType(mlir::Type elTy,
70 mlir::LLVM::DIFileAttr fileAttr,
71 mlir::LLVM::DIScopeAttr scope,
72 fir::cg::XDeclareOp declOp,
73 bool genAllocated,
74 bool genAssociated);
75 mlir::LLVM::DILocalVariableAttr
76 generateArtificialVariable(mlir::MLIRContext *context, mlir::Value Val,
77 mlir::LLVM::DIFileAttr fileAttr,
78 mlir::LLVM::DIScopeAttr scope,
79 fir::cg::XDeclareOp declOp);
80 std::pair<std::uint64_t, unsigned short>
81 getFieldSizeAndAlign(mlir::Type fieldTy);
82
83 mlir::ModuleOp module;
84 mlir::SymbolTable *symbolTable;
85 const mlir::DataLayout *dataLayout;
86 KindMapping kindMapping;
87 fir::LLVMTypeConverter llvmTypeConverter;
88 std::uint64_t dimsSize;
89 std::uint64_t dimsOffset;
90 std::uint64_t ptrSize;
91 std::uint64_t lenOffset;
92 std::uint64_t rankOffset;
93 std::uint64_t rankSize;
94 llvm::DenseMap<mlir::Type, mlir::LLVM::DITypeAttr> typeCache;
95};
96
97} // namespace fir
98
99static uint32_t getLineFromLoc(mlir::Location loc) {
100 uint32_t line = 1;
101 if (auto fileLoc = mlir::dyn_cast<mlir::FileLineColLoc>(loc))
102 line = fileLoc.getLine();
103 return line;
104}
105
106#endif // FORTRAN_OPTIMIZER_TRANSFORMS_DEBUGTYPEGENERATOR_H
This converts FIR/mlir type to DITypeAttr.
Definition: DebugTypeGenerator.h:27
Definition: KindMapping.h:48
Definition: TypeConverter.h:50
Definition: AbstractConverter.h:31