MLIR 24.0.0git
DebugImporter.cpp
Go to the documentation of this file.
1//===- DebugImporter.cpp - LLVM to MLIR Debug conversion ------------------===//
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#include "DebugImporter.h"
11#include "mlir/IR/Attributes.h"
13#include "mlir/IR/Location.h"
14#include "llvm/ADT/STLExtras.h"
15#include "llvm/ADT/TypeSwitch.h"
16#include "llvm/BinaryFormat/Dwarf.h"
17#include "llvm/IR/Constants.h"
18#include "llvm/IR/DebugInfoMetadata.h"
19#include "llvm/IR/Metadata.h"
20
21using namespace mlir;
22using namespace mlir::LLVM;
23using namespace mlir::LLVM::detail;
24
25DebugImporter::DebugImporter(ModuleOp mlirModule,
26 bool dropDICompositeTypeElements)
27 : cache([&](llvm::DINode *node) { return createRecSelf(node); }),
28 context(mlirModule.getContext()), mlirModule(mlirModule),
29 dropDICompositeTypeElements(dropDICompositeTypeElements) {}
30
32 llvm::DISubprogram *subprogram = func->getSubprogram();
33 if (!subprogram)
34 return UnknownLoc::get(context);
35
36 // Add a fused location to link the subprogram information.
37 StringAttr fileName = StringAttr::get(context, subprogram->getFilename());
39 {FileLineColLoc::get(fileName, subprogram->getLine(), /*column=*/0)},
40 translate(subprogram), context);
41}
42
43//===----------------------------------------------------------------------===//
44// Attributes
45//===----------------------------------------------------------------------===//
46
47DIBasicTypeAttr DebugImporter::translateImpl(llvm::DIBasicType *node) {
48 return DIBasicTypeAttr::get(context, node->getTag(),
49 getStringAttrOrNull(node->getRawName()),
50 node->getSizeInBits(), node->getEncoding());
51}
52
53DICompileUnitAttr DebugImporter::translateImpl(llvm::DICompileUnit *node) {
54 std::optional<DIEmissionKind> emissionKind =
55 symbolizeDIEmissionKind(node->getEmissionKind());
56 std::optional<DINameTableKind> nameTableKind = symbolizeDINameTableKind(
57 static_cast<
58 std::underlying_type_t<llvm::DICompileUnit::DebugNameTableKind>>(
59 node->getNameTableKind()));
61 if (node->getImportedEntities()) {
62 for (llvm::DIImportedEntity *importedEntity : node->getImportedEntities())
63 if (DINodeAttr nodeAttr =
64 translate(static_cast<llvm::DINode *>(importedEntity)))
65 imports.push_back(nodeAttr);
66 }
67 llvm::DISourceLanguageName sourceLanguage = node->getSourceLanguage();
68 DISourceLanguageNameAttr sourceLanguageAttr;
69 if (sourceLanguage.hasVersionedName()) {
70 sourceLanguageAttr = DISourceLanguageNameAttr::get(
71 context, /*language=*/0, sourceLanguage.getName(),
72 sourceLanguage.getVersion(), sourceLanguage.getDialect());
73 } else {
74 sourceLanguageAttr = DISourceLanguageNameAttr::get(
75 context, sourceLanguage.getName(), /*name=*/0,
76 /*version=*/std::nullopt, sourceLanguage.getDialect());
77 }
78 return DICompileUnitAttr::get(
79 context, /*recId=*/DistinctAttr{}, /*isRecSelf=*/false,
80 getOrCreateDistinctID(node), sourceLanguageAttr,
81 translate(node->getFile()), getStringAttrOrNull(node->getRawProducer()),
82 node->isOptimized(), emissionKind.value(),
83 node->isDebugInfoForProfiling(), nameTableKind.value(),
84 getStringAttrOrNull(node->getRawSplitDebugFilename()), imports);
85}
86
87DICompositeTypeAttr DebugImporter::translateImpl(llvm::DICompositeType *node) {
88 std::optional<DIFlags> flags = symbolizeDIFlags(node->getFlags());
89 SmallVector<DINodeAttr> elements;
90
91 // A vector always requires an element.
92 bool isVectorType = flags && bitEnumContainsAll(*flags, DIFlags::Vector);
93 if (isVectorType || !dropDICompositeTypeElements) {
94 for (llvm::DINode *element : node->getElements()) {
95 assert(element && "expected a non-null element type");
96 elements.push_back(translate(element));
97 }
98 }
99 // Drop the elements parameter if any of the elements are invalid.
100 if (llvm::is_contained(elements, nullptr))
101 elements.clear();
102 DITypeAttr baseType = translate(node->getBaseType());
103 // Arrays require a base type, otherwise the debug metadata is considered to
104 // be malformed.
105 if (node->getTag() == llvm::dwarf::DW_TAG_array_type && !baseType)
106 return nullptr;
107 return DICompositeTypeAttr::get(
108 context, node->getTag(), getStringAttrOrNull(node->getRawName()),
109 translate(node->getFile()), node->getLine(), translate(node->getScope()),
110 baseType, flags.value_or(DIFlags::Zero), node->getSizeInBits(),
111 node->getAlignInBits(), translateExpression(node->getDataLocationExp()),
112 translateExpression(node->getRankExp()),
113 translateExpression(node->getAllocatedExp()),
114 translateExpression(node->getAssociatedExp()),
115 getStringAttrOrNull(node->getRawIdentifier()),
116 translate(node->getDiscriminator()), elements);
117}
118
119DIDerivedTypeAttr DebugImporter::translateImpl(llvm::DIDerivedType *node) {
120 // Return nullptr if the base type is invalid.
121 DITypeAttr baseType = translate(node->getBaseType());
122 if (node->getBaseType() && !baseType)
123 return nullptr;
124 llvm::Metadata *rawExtraData = node->getExtraData();
125 Attribute extraData;
126 if (auto *extraDataNode = dyn_cast_or_null<llvm::DINode>(rawExtraData)) {
127 extraData = translate(extraDataNode);
128 } else if (auto *constantAsMetadata =
129 dyn_cast_or_null<llvm::ConstantAsMetadata>(rawExtraData)) {
130 if (auto *constantInt =
131 dyn_cast<llvm::ConstantInt>(constantAsMetadata->getValue())) {
132 const APInt &value = constantInt->getValue();
133 extraData = IntegerAttr::get(
134 IntegerType::get(context, value.getBitWidth()), value);
135 }
136 }
137 return DIDerivedTypeAttr::get(
138 context, node->getTag(), getStringAttrOrNull(node->getRawName()),
139 translate(node->getFile()), node->getLine(), translate(node->getScope()),
140 baseType, node->getSizeInBits(), node->getAlignInBits(),
141 node->getOffsetInBits(), node->getDWARFAddressSpace(),
142 symbolizeDIFlags(node->getFlags()).value_or(DIFlags::Zero), extraData);
143}
144
145DIEnumeratorAttr DebugImporter::translateImpl(llvm::DIEnumerator *node) {
146 const APInt &value = node->getValue();
147 auto valueAttr =
148 IntegerAttr::get(IntegerType::get(context, value.getBitWidth()), value);
149 return DIEnumeratorAttr::get(context, getStringAttrOrNull(node->getRawName()),
150 valueAttr, node->isUnsigned());
151}
152
153DIStringTypeAttr DebugImporter::translateImpl(llvm::DIStringType *node) {
154 return DIStringTypeAttr::get(
155 context, node->getTag(), getStringAttrOrNull(node->getRawName()),
156 node->getSizeInBits(), node->getAlignInBits(),
157 translate(node->getStringLength()),
158 translateExpression(node->getStringLengthExp()),
159 translateExpression(node->getStringLocationExp()), node->getEncoding(),
160 translate(node->getCharType()));
161}
162
163DIFileAttr DebugImporter::translateImpl(llvm::DIFile *node) {
164 return DIFileAttr::get(context, node->getFilename(), node->getDirectory());
165}
166
167DILabelAttr DebugImporter::translateImpl(llvm::DILabel *node) {
168 // Return nullptr if the scope or type is a cyclic dependency.
169 DIScopeAttr scope = translate(node->getScope());
170 if (node->getScope() && !scope)
171 return nullptr;
172 return DILabelAttr::get(context, scope,
173 getStringAttrOrNull(node->getRawName()),
174 translate(node->getFile()), node->getLine());
175}
176
177DILexicalBlockAttr DebugImporter::translateImpl(llvm::DILexicalBlock *node) {
178 // Return nullptr if the scope or type is a cyclic dependency.
179 DIScopeAttr scope = translate(node->getScope());
180 if (node->getScope() && !scope)
181 return nullptr;
182 return DILexicalBlockAttr::get(context, scope, translate(node->getFile()),
183 node->getLine(), node->getColumn());
184}
185
186DILexicalBlockFileAttr
187DebugImporter::translateImpl(llvm::DILexicalBlockFile *node) {
188 // Return nullptr if the scope or type is a cyclic dependency.
189 DIScopeAttr scope = translate(node->getScope());
190 if (node->getScope() && !scope)
191 return nullptr;
192 return DILexicalBlockFileAttr::get(context, scope, translate(node->getFile()),
193 node->getDiscriminator());
194}
195
196DIGlobalVariableAttr
197DebugImporter::translateImpl(llvm::DIGlobalVariable *node) {
198 // Names of DIGlobalVariables can be empty. MLIR models them as null, instead
199 // of empty strings, so this special handling is necessary.
200 auto convertToStringAttr = [&](StringRef name) -> StringAttr {
201 if (name.empty())
202 return {};
203 return StringAttr::get(context, node->getName());
204 };
205 return DIGlobalVariableAttr::get(
206 context, translate(node->getScope()),
207 convertToStringAttr(node->getName()),
208 convertToStringAttr(node->getLinkageName()), translate(node->getFile()),
209 node->getLine(), translate(node->getType()), node->isLocalToUnit(),
210 node->isDefinition(), node->getAlignInBits());
211}
212
213DILocalVariableAttr DebugImporter::translateImpl(llvm::DILocalVariable *node) {
214 // Return nullptr if the scope or type is a cyclic dependency.
215 DIScopeAttr scope = translate(node->getScope());
216 if (node->getScope() && !scope)
217 return nullptr;
218 return DILocalVariableAttr::get(
219 context, scope, getStringAttrOrNull(node->getRawName()),
220 translate(node->getFile()), node->getLine(), node->getArg(),
221 node->getAlignInBits(), translate(node->getType()),
222 symbolizeDIFlags(node->getFlags()).value_or(DIFlags::Zero));
223}
224
225DIVariableAttr DebugImporter::translateImpl(llvm::DIVariable *node) {
226 return cast<DIVariableAttr>(translate(static_cast<llvm::DINode *>(node)));
227}
228
229DIScopeAttr DebugImporter::translateImpl(llvm::DIScope *node) {
230 return cast<DIScopeAttr>(translate(static_cast<llvm::DINode *>(node)));
231}
232
233DIModuleAttr DebugImporter::translateImpl(llvm::DIModule *node) {
234 return DIModuleAttr::get(
235 context, translate(node->getFile()), translate(node->getScope()),
236 getStringAttrOrNull(node->getRawName()),
237 getStringAttrOrNull(node->getRawConfigurationMacros()),
238 getStringAttrOrNull(node->getRawIncludePath()),
239 getStringAttrOrNull(node->getRawAPINotesFile()), node->getLineNo(),
240 node->getIsDecl());
241}
242
243DINamespaceAttr DebugImporter::translateImpl(llvm::DINamespace *node) {
244 return DINamespaceAttr::get(context, getStringAttrOrNull(node->getRawName()),
245 translate(node->getScope()),
246 node->getExportSymbols());
247}
248
249DIImportedEntityAttr
250DebugImporter::translateImpl(llvm::DIImportedEntity *node) {
251 SmallVector<DINodeAttr> elements;
252 for (llvm::DINode *element : node->getElements()) {
253 assert(element && "expected a non-null element type");
254 elements.push_back(translate(element));
255 }
256
257 return DIImportedEntityAttr::get(
258 context, node->getTag(), translate(node->getScope()),
259 translate(node->getEntity()), translate(node->getFile()), node->getLine(),
260 getStringAttrOrNull(node->getRawName()), elements);
261}
262
263DISubprogramAttr DebugImporter::translateImpl(llvm::DISubprogram *node) {
264 // Only definitions require a distinct identifier.
265 mlir::DistinctAttr id;
266 if (node->isDistinct())
267 id = getOrCreateDistinctID(node);
268
269 // Return nullptr if the scope or type is invalid.
270 DIScopeAttr scope = translate(node->getScope());
271 if (node->getScope() && !scope)
272 return nullptr;
273 std::optional<DISubprogramFlags> subprogramFlags =
274 symbolizeDISubprogramFlags(node->getSubprogram()->getSPFlags());
275 assert(subprogramFlags && "expected valid subprogram flags");
276 DISubroutineTypeAttr type = translate(node->getType());
277 if (node->getType() && !type)
278 return nullptr;
279
280 // Convert the retained nodes but drop all of them if one of them is invalid.
281 SmallVector<Attribute> retainedNodes;
282 auto add = [this, &retainedNodes](llvm::DINode *retainedNode) {
283 retainedNodes.push_back(translate(retainedNode));
284 };
285 auto addGVE = [](llvm::DIGlobalVariableExpression *GVE) {
286 // FIXME Import DIGlobalVariableExpressions from retainedNodes without
287 // duplicating them.
288 };
289 node->forEachRetainedNode(add, add, add, add, addGVE);
290 if (llvm::is_contained(retainedNodes, nullptr))
291 retainedNodes.clear();
292
293 SmallVector<DINodeAttr> annotations;
294 // We currently only support `string` values for annotations on the MLIR side.
295 // Theoretically we could support other primitives, but LLVM is not using
296 // other types in practice.
297 if (llvm::DINodeArray rawAnns = node->getAnnotations(); rawAnns) {
298 for (size_t i = 0, e = rawAnns->getNumOperands(); i < e; ++i) {
299 const llvm::MDTuple *tuple = cast<llvm::MDTuple>(rawAnns->getOperand(i));
300 if (tuple->getNumOperands() != 2)
301 continue;
302 const llvm::MDString *name = cast<llvm::MDString>(tuple->getOperand(0));
303 const llvm::MDString *value =
304 dyn_cast<llvm::MDString>(tuple->getOperand(1));
305 if (name && value) {
306 annotations.push_back(DIAnnotationAttr::get(
307 context, StringAttr::get(context, name->getString()),
308 StringAttr::get(context, value->getString())));
309 }
310 }
311 }
312
313 return DISubprogramAttr::get(context, id, translate(node->getUnit()), scope,
314 getStringAttrOrNull(node->getRawName()),
315 getStringAttrOrNull(node->getRawLinkageName()),
316 translate(node->getFile()), node->getLine(),
317 node->getScopeLine(), *subprogramFlags, type,
318 retainedNodes, annotations);
319}
320
321DISubrangeAttr DebugImporter::translateImpl(llvm::DISubrange *node) {
322 auto getAttrOrNull = [&](llvm::DISubrange::BoundType data) -> Attribute {
323 if (data.isNull())
324 return nullptr;
325 if (auto *constInt = dyn_cast<llvm::ConstantInt *>(data))
326 return IntegerAttr::get(IntegerType::get(context, 64),
327 constInt->getSExtValue());
328 if (auto *expr = dyn_cast<llvm::DIExpression *>(data))
329 return translateExpression(expr);
330 if (auto *var = dyn_cast<llvm::DIVariable *>(data)) {
331 if (auto *local = dyn_cast<llvm::DILocalVariable>(var))
332 return translate(local);
333 if (auto *global = dyn_cast<llvm::DIGlobalVariable>(var))
334 return translate(global);
335 return nullptr;
336 }
337 return nullptr;
338 };
339 Attribute count = getAttrOrNull(node->getCount());
340 Attribute upperBound = getAttrOrNull(node->getUpperBound());
341 // Either count or the upper bound needs to be present. Otherwise, the
342 // metadata is invalid. The conversion might fail due to unsupported DI nodes.
343 if (!count && !upperBound)
344 return {};
345 return DISubrangeAttr::get(context, count,
346 getAttrOrNull(node->getLowerBound()), upperBound,
347 getAttrOrNull(node->getStride()));
348}
349
350DICommonBlockAttr DebugImporter::translateImpl(llvm::DICommonBlock *node) {
351 return DICommonBlockAttr::get(context, translate(node->getScope()),
352 translate(node->getDecl()),
353 getStringAttrOrNull(node->getRawName()),
354 translate(node->getFile()), node->getLineNo());
355}
356
357DIGenericSubrangeAttr
358DebugImporter::translateImpl(llvm::DIGenericSubrange *node) {
359 auto getAttrOrNull =
360 [&](llvm::DIGenericSubrange::BoundType data) -> Attribute {
361 if (data.isNull())
362 return nullptr;
363 if (auto *expr = dyn_cast<llvm::DIExpression *>(data))
364 return translateExpression(expr);
365 if (auto *var = dyn_cast<llvm::DIVariable *>(data)) {
366 if (auto *local = dyn_cast<llvm::DILocalVariable>(var))
367 return translate(local);
368 if (auto *global = dyn_cast<llvm::DIGlobalVariable>(var))
369 return translate(global);
370 return nullptr;
371 }
372 return nullptr;
373 };
374 Attribute count = getAttrOrNull(node->getCount());
375 Attribute upperBound = getAttrOrNull(node->getUpperBound());
376 Attribute lowerBound = getAttrOrNull(node->getLowerBound());
377 Attribute stride = getAttrOrNull(node->getStride());
378 // Either count or the upper bound needs to be present. Otherwise, the
379 // metadata is invalid.
380 if (!count && !upperBound)
381 return {};
382 return DIGenericSubrangeAttr::get(context, count, lowerBound, upperBound,
383 stride);
384}
385
386DISubroutineTypeAttr
387DebugImporter::translateImpl(llvm::DISubroutineType *node) {
388 SmallVector<DITypeAttr> types;
389 for (llvm::DIType *type : node->getTypeArray()) {
390 if (!type) {
391 // A nullptr entry may appear at the beginning or the end of the
392 // subroutine types list modeling either a void result type or the type of
393 // a variadic argument. Translate the nullptr to an explicit
394 // DINullTypeAttr since the attribute list cannot contain a nullptr entry.
395 types.push_back(DINullTypeAttr::get(context));
396 continue;
397 }
398 types.push_back(translate(type));
399 }
400 // Return nullptr if any of the types is invalid.
401 if (llvm::is_contained(types, nullptr))
402 return nullptr;
403 return DISubroutineTypeAttr::get(context, node->getCC(), types);
404}
405
406DITypeAttr DebugImporter::translateImpl(llvm::DIType *node) {
407 return cast<DITypeAttr>(translate(static_cast<llvm::DINode *>(node)));
408}
409
411 if (!node)
412 return nullptr;
413
414 // Check for a cached instance.
415 auto cacheEntry = cache.lookupOrInit(node);
416 if (std::optional<DINodeAttr> result = cacheEntry.get())
417 return *result;
418
419 // Convert the debug metadata if possible.
420 auto translateNode = [this](llvm::DINode *node) -> DINodeAttr {
421 if (auto *casted = dyn_cast<llvm::DIBasicType>(node))
422 return translateImpl(casted);
423 if (auto *casted = dyn_cast<llvm::DICommonBlock>(node))
424 return translateImpl(casted);
425 if (auto *casted = dyn_cast<llvm::DICompileUnit>(node))
426 return translateImpl(casted);
427 if (auto *casted = dyn_cast<llvm::DICompositeType>(node))
428 return translateImpl(casted);
429 if (auto *casted = dyn_cast<llvm::DIDerivedType>(node))
430 return translateImpl(casted);
431 if (auto *casted = dyn_cast<llvm::DIEnumerator>(node))
432 return translateImpl(casted);
433 if (auto *casted = dyn_cast<llvm::DIStringType>(node))
434 return translateImpl(casted);
435 if (auto *casted = dyn_cast<llvm::DIFile>(node))
436 return translateImpl(casted);
437 if (auto *casted = dyn_cast<llvm::DIGlobalVariable>(node))
438 return translateImpl(casted);
439 if (auto *casted = dyn_cast<llvm::DIImportedEntity>(node))
440 return translateImpl(casted);
441 if (auto *casted = dyn_cast<llvm::DILabel>(node))
442 return translateImpl(casted);
443 if (auto *casted = dyn_cast<llvm::DILexicalBlock>(node))
444 return translateImpl(casted);
445 if (auto *casted = dyn_cast<llvm::DILexicalBlockFile>(node))
446 return translateImpl(casted);
447 if (auto *casted = dyn_cast<llvm::DILocalVariable>(node))
448 return translateImpl(casted);
449 if (auto *casted = dyn_cast<llvm::DIModule>(node))
450 return translateImpl(casted);
451 if (auto *casted = dyn_cast<llvm::DINamespace>(node))
452 return translateImpl(casted);
453 if (auto *casted = dyn_cast<llvm::DISubprogram>(node))
454 return translateImpl(casted);
455 if (auto *casted = dyn_cast<llvm::DISubrange>(node))
456 return translateImpl(casted);
457 if (auto *casted = dyn_cast<llvm::DIGenericSubrange>(node))
458 return translateImpl(casted);
459 if (auto *casted = dyn_cast<llvm::DISubroutineType>(node))
460 return translateImpl(casted);
461 return nullptr;
462 };
463 if (DINodeAttr attr = translateNode(node)) {
464 // If this node was repeated, lookup its recursive ID and assign it to the
465 // base result.
466 if (cacheEntry.wasRepeated()) {
467 DistinctAttr recId = nodeToRecId.lookup(node);
468 auto recType = cast<DIRecursiveTypeAttrInterface>(attr);
469 attr = cast<DINodeAttr>(recType.withRecId(recId));
470 }
471 cacheEntry.resolve(attr);
472 return attr;
473 }
474 cacheEntry.resolve(nullptr);
475 return nullptr;
476}
477
478/// Get the `getRecSelf` constructor for the translated node if it participates
479/// in CyclicReplacerCache cycle breaking (recursive composite types,
480/// subprograms, or compile units).
481static function_ref<DIRecursiveTypeAttrInterface(DistinctAttr)>
482getRecSelfConstructor(llvm::DINode *node) {
483 using CtorType = function_ref<DIRecursiveTypeAttrInterface(DistinctAttr)>;
485 .Case([&](llvm::DICompositeType *) {
486 return CtorType(DICompositeTypeAttr::getRecSelf);
487 })
488 .Case([&](llvm::DISubprogram *) {
489 return CtorType(DISubprogramAttr::getRecSelf);
490 })
491 .Case([&](llvm::DICompileUnit *) {
492 return CtorType(DICompileUnitAttr::getRecSelf);
493 })
494 .Default(CtorType());
495}
496
497std::optional<DINodeAttr> DebugImporter::createRecSelf(llvm::DINode *node) {
498 auto recSelfCtor = getRecSelfConstructor(node);
499 if (!recSelfCtor)
500 return std::nullopt;
501
502 // The original node may have already been assigned a recursive ID from
503 // a different self-reference. Use that if possible.
504 DistinctAttr recId = nodeToRecId.lookup(node);
505 if (!recId) {
506 recId = DistinctAttr::create(UnitAttr::get(context));
507 nodeToRecId[node] = recId;
508 }
509 DIRecursiveTypeAttrInterface recSelf = recSelfCtor(recId);
510 return cast<DINodeAttr>(recSelf);
511}
512
513//===----------------------------------------------------------------------===//
514// Locations
515//===----------------------------------------------------------------------===//
516
517Location DebugImporter::translateLoc(llvm::DILocation *loc) {
518 if (!loc)
519 return UnknownLoc::get(context);
520
521 // Get the file location of the instruction.
522 Location result = FileLineColLoc::get(context, loc->getFilename(),
523 loc->getLine(), loc->getColumn());
524
525 // Add scope information.
526 assert(loc->getScope() && "expected non-null scope");
528 context);
529
530 // Add call site information, if available.
531 if (llvm::DILocation *inlinedAt = loc->getInlinedAt())
532 result = CallSiteLoc::get(result, translateLoc(inlinedAt));
533
534 return result;
535}
536
537DIExpressionAttr DebugImporter::translateExpression(llvm::DIExpression *node) {
538 if (!node)
539 return nullptr;
540
542
543 // Begin processing the operations.
544 for (const llvm::DIExpression::ExprOperand &op : node->expr_ops()) {
545 SmallVector<uint64_t> operands;
546 operands.reserve(op.getNumArgs());
547 for (const auto &i : llvm::seq(op.getNumArgs()))
548 operands.push_back(op.getArg(i));
549 const auto attr = DIExpressionElemAttr::get(context, op.getOp(), operands);
550 ops.push_back(attr);
551 }
552 return DIExpressionAttr::get(context, ops);
553}
554
556 llvm::DIGlobalVariableExpression *node) {
557 return DIGlobalVariableExpressionAttr::get(
558 context, translate(node->getVariable()),
559 translateExpression(node->getExpression()));
560}
561
562StringAttr DebugImporter::getStringAttrOrNull(llvm::MDString *stringNode) {
563 if (!stringNode)
564 return StringAttr();
565 return StringAttr::get(context, stringNode->getString());
566}
567
568DistinctAttr DebugImporter::getOrCreateDistinctID(llvm::DINode *node) {
569 DistinctAttr &id = nodeToDistinctAttr[node];
570 if (!id)
571 id = DistinctAttr::create(UnitAttr::get(context));
572 return id;
573}
static function_ref< DIRecursiveTypeAttrInterface(DistinctAttr)> getRecSelfConstructor(llvm::DINode *node)
Get the getRecSelf constructor for the translated node if it participates in CyclicReplacerCache cycl...
#define add(a, b)
An attribute that associates a referenced attribute with a unique identifier.
static DistinctAttr create(Attribute referencedAttr)
Creates a distinct attribute that associates a referenced attribute with a unique identifier.
static FileLineColLoc get(StringAttr filename, unsigned line, unsigned column)
Definition Location.cpp:161
This class represents a fused location whose metadata is known to be an instance of the given type.
Definition Location.h:151
This class represents the base attribute for all debug info attributes.
Definition LLVMAttrs.h:29
DINodeAttr translate(llvm::DINode *node)
Translates the given LLVM debug metadata to MLIR.
DIExpressionAttr translateExpression(llvm::DIExpression *node)
Translates the LLVM DWARF expression metadata to MLIR.
DIGlobalVariableExpressionAttr translateGlobalVariableExpression(llvm::DIGlobalVariableExpression *node)
Translates the LLVM DWARF global variable expression metadata to MLIR.
Location translateLoc(llvm::DILocation *loc)
Translates the given LLVM debug location to an MLIR location.
Location translateFuncLocation(llvm::Function *func)
Translates the debug information for the given function into a Location.
DebugImporter(ModuleOp mlirModule, bool dropDICompositeTypeElements)
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition CallGraph.h:229
Include the generated interface declarations.
llvm::TypeSwitch< T, ResultT > TypeSwitch
Definition LLVM.h:147
llvm::function_ref< Fn > function_ref
Definition LLVM.h:155