@@ -92,83 +92,90 @@ class MLIRDebugInfoHelper
92
92
93
93
mlir::Location getCompileUnit (mlir::Location location, StringRef producerName, bool isOptimized) {
94
94
95
- auto file = dyn_cast<mlir::LLVM::DIFileAttr>(debugScope.lookup (FILE_DEBUG_SCOPE));
96
-
97
- unsigned sourceLanguage = llvm::dwarf::DW_LANG_C;
98
- auto producer = builder.getStringAttr (producerName);
99
- auto emissionKind = mlir::LLVM::DIEmissionKind::Full;
100
- auto compileUnit = mlir::LLVM::DICompileUnitAttr::get (builder.getContext (), sourceLanguage, file, producer, isOptimized, emissionKind);
101
-
102
- debugScope.insert (CU_DEBUG_SCOPE, compileUnit);
103
- debugScope.insert (DEBUG_SCOPE, file);
95
+ if (auto file = dyn_cast_or_null<mlir::LLVM::DIFileAttr>(debugScope.lookup (FILE_DEBUG_SCOPE)))
96
+ {
97
+ unsigned sourceLanguage = llvm::dwarf::DW_LANG_C;
98
+ auto producer = builder.getStringAttr (producerName);
99
+ auto emissionKind = mlir::LLVM::DIEmissionKind::Full;
100
+ auto compileUnit = mlir::LLVM::DICompileUnitAttr::get (builder.getContext (), sourceLanguage, file, producer, isOptimized, emissionKind);
101
+
102
+ debugScope.insert (CU_DEBUG_SCOPE, compileUnit);
103
+ debugScope.insert (DEBUG_SCOPE, file);
104
+
105
+ return combine (location, compileUnit);
106
+ }
104
107
105
- return combine ( location, compileUnit) ;
108
+ return location;
106
109
}
107
110
108
111
mlir::Location getSubprogram (mlir::Location functionLocation, StringRef functionName, mlir::Location functionBlockLocation) {
109
112
110
- auto [line, column] = LocationHelper::getLineAndColumn (functionLocation);
111
- auto [scopeLine, scopeColumn] = LocationHelper::getLineAndColumn (functionBlockLocation);
112
-
113
- auto compileUnitAttr = dyn_cast<mlir::LLVM::DICompileUnitAttr>(debugScope.lookup (CU_DEBUG_SCOPE));
114
- if (auto scopeAttr = dyn_cast_or_null<mlir::LLVM::DIScopeAttr>(debugScope.lookup (DEBUG_SCOPE)))
113
+ if (auto compileUnitAttr = dyn_cast_or_null<mlir::LLVM::DICompileUnitAttr>(debugScope.lookup (CU_DEBUG_SCOPE)))
115
114
{
116
- // if (scopeAttr.isa<mlir::LLVM::DILexicalBlockAttr>())
117
- // {
118
- // auto file = dyn_cast<mlir::LLVM::DIFileAttr>(debugScope.lookup(FILE_DEBUG_SCOPE));
119
-
120
- // // create new scope: DICompositeType
121
- // //unsigned tag, StringAttr name, DIFileAttr file, uint32_t line, DIScopeAttr scope,
122
- // //DITypeAttr baseType, DIFlags flags, uint64_t sizeInBits, uint64_t alignInBits, ::llvm::ArrayRef<DINodeAttr> elements
123
- // auto compositeTypeAttr = mlir::LLVM::DICompositeTypeAttr::get(
124
- // builder.getContext(), llvm::dwarf::DW_TAG_class_type, builder.getStringAttr("nested_function"),
125
- // file, line, scopeAttr, mlir::LLVM::DITypeAttr(), mlir::LLVM::DIFlags::TypePassByValue | mlir::LLVM::DIFlags::NonTrivial, 0/*sizeInBits*/,
126
- // 8/*alignInBits*/, {/*Add elements here*/});
127
-
128
- // //debugScope.insert(DEBUG_SCOPE, compositeTypeAttr);
129
- // }
130
-
131
- auto subprogramFlags = mlir::LLVM::DISubprogramFlags::Definition;
132
- if (compileUnitAttr.getIsOptimized ())
115
+ if (auto scopeAttr = dyn_cast_or_null<mlir::LLVM::DIScopeAttr>(debugScope.lookup (DEBUG_SCOPE)))
133
116
{
134
- subprogramFlags = subprogramFlags | mlir::LLVM::DISubprogramFlags::Optimized;
117
+ auto [line, column] = LocationHelper::getLineAndColumn (functionLocation);
118
+ auto [scopeLine, scopeColumn] = LocationHelper::getLineAndColumn (functionBlockLocation);
119
+
120
+ // if (scopeAttr.isa<mlir::LLVM::DILexicalBlockAttr>())
121
+ // {
122
+ // auto file = dyn_cast<mlir::LLVM::DIFileAttr>(debugScope.lookup(FILE_DEBUG_SCOPE));
123
+
124
+ // // create new scope: DICompositeType
125
+ // //unsigned tag, StringAttr name, DIFileAttr file, uint32_t line, DIScopeAttr scope,
126
+ // //DITypeAttr baseType, DIFlags flags, uint64_t sizeInBits, uint64_t alignInBits, ::llvm::ArrayRef<DINodeAttr> elements
127
+ // auto compositeTypeAttr = mlir::LLVM::DICompositeTypeAttr::get(
128
+ // builder.getContext(), llvm::dwarf::DW_TAG_class_type, builder.getStringAttr("nested_function"),
129
+ // file, line, scopeAttr, mlir::LLVM::DITypeAttr(), mlir::LLVM::DIFlags::TypePassByValue | mlir::LLVM::DIFlags::NonTrivial, 0/*sizeInBits*/,
130
+ // 8/*alignInBits*/, {/*Add elements here*/});
131
+
132
+ // //debugScope.insert(DEBUG_SCOPE, compositeTypeAttr);
133
+ // }
134
+
135
+ auto subprogramFlags = mlir::LLVM::DISubprogramFlags::Definition;
136
+ if (compileUnitAttr.getIsOptimized ())
137
+ {
138
+ subprogramFlags = subprogramFlags | mlir::LLVM::DISubprogramFlags::Optimized;
139
+ }
140
+
141
+ // add return types
142
+ auto type = mlir::LLVM::DISubroutineTypeAttr::get (builder.getContext (), llvm::dwarf::DW_CC_normal, {/* Add Types here*/ });
143
+
144
+ auto funcNameAttr = builder.getStringAttr (functionName);
145
+ auto subprogramAttr = mlir::LLVM::DISubprogramAttr::get (
146
+ builder.getContext (), compileUnitAttr, scopeAttr,
147
+ funcNameAttr, funcNameAttr,
148
+ compileUnitAttr.getFile (), line, scopeLine, subprogramFlags, type);
149
+
150
+ debugScope.insert (SUBPROGRAM_DEBUG_SCOPE, subprogramAttr);
151
+ debugScope.insert (DEBUG_SCOPE, subprogramAttr);
152
+
153
+ return combine (functionLocation, subprogramAttr);
135
154
}
136
-
137
- // add return types
138
- auto type = mlir::LLVM::DISubroutineTypeAttr::get (builder.getContext (), llvm::dwarf::DW_CC_normal, {/* Add Types here*/ });
139
-
140
- auto funcNameAttr = builder.getStringAttr (functionName);
141
- auto subprogramAttr = mlir::LLVM::DISubprogramAttr::get (
142
- builder.getContext (), compileUnitAttr, scopeAttr,
143
- funcNameAttr, funcNameAttr,
144
- compileUnitAttr.getFile (), line, scopeLine, subprogramFlags, type);
145
-
146
- debugScope.insert (SUBPROGRAM_DEBUG_SCOPE, subprogramAttr);
147
- debugScope.insert (DEBUG_SCOPE, subprogramAttr);
148
-
149
- return combine (functionLocation, subprogramAttr);
150
155
}
151
156
152
157
return functionLocation;
153
158
}
154
159
155
160
void setLexicalBlock (mlir::Location blockLocation) {
156
161
157
- auto fileAttr = dyn_cast<mlir::LLVM::DIFileAttr>(debugScope.lookup (FILE_DEBUG_SCOPE));
158
- if (auto scopeAttr = dyn_cast_or_null<mlir::LLVM::DIScopeAttr>(debugScope.lookup (DEBUG_SCOPE)))
162
+ if (auto fileAttr = dyn_cast_or_null<mlir::LLVM::DIFileAttr>(debugScope.lookup (FILE_DEBUG_SCOPE)))
159
163
{
160
- auto [scopeLine, scopeColumn] = LocationHelper::getLineAndColumn (blockLocation);
161
-
162
- auto lexicalBlockAttr =
163
- mlir::LLVM::DILexicalBlockAttr::get (
164
- builder.getContext (),
165
- scopeAttr,
166
- fileAttr,
167
- scopeLine,
168
- scopeColumn);
169
-
170
- debugScope.insert (BLOCK_DEBUG_SCOPE, lexicalBlockAttr);
171
- debugScope.insert (DEBUG_SCOPE, lexicalBlockAttr);
164
+ if (auto scopeAttr = dyn_cast_or_null<mlir::LLVM::DIScopeAttr>(debugScope.lookup (DEBUG_SCOPE)))
165
+ {
166
+ auto [scopeLine, scopeColumn] = LocationHelper::getLineAndColumn (blockLocation);
167
+
168
+ auto lexicalBlockAttr =
169
+ mlir::LLVM::DILexicalBlockAttr::get (
170
+ builder.getContext (),
171
+ scopeAttr,
172
+ fileAttr,
173
+ scopeLine,
174
+ scopeColumn);
175
+
176
+ debugScope.insert (BLOCK_DEBUG_SCOPE, lexicalBlockAttr);
177
+ debugScope.insert (DEBUG_SCOPE, lexicalBlockAttr);
178
+ }
172
179
}
173
180
}
174
181
0 commit comments