[Mlir-commits] [mlir] [mlir][debug] Support DIGenericSubrange. (PR #113441)
Tobias Gysi
llvmlistbot at llvm.org
Wed Oct 30 11:52:51 PDT 2024
================
@@ -309,6 +309,35 @@ DICommonBlockAttr DebugImporter::translateImpl(llvm::DICommonBlock *node) {
translate(node->getFile()), node->getLineNo());
}
+DIGenericSubrangeAttr
+DebugImporter::translateImpl(llvm::DIGenericSubrange *node) {
+ auto getAttrOrNull =
+ [&](llvm::DIGenericSubrange::BoundType data) -> Attribute {
+ if (data.isNull())
+ return nullptr;
+ if (auto *expr = dyn_cast<llvm::DIExpression *>(data))
+ return translateExpression(expr);
+ if (auto *var = dyn_cast<llvm::DIVariable *>(data)) {
+ if (auto *local = dyn_cast<llvm::DILocalVariable>(var))
+ return translate(local);
+ if (auto *global = dyn_cast<llvm::DIGlobalVariable>(var))
+ return translate(global);
+ return nullptr;
+ }
+ return nullptr;
+ };
+ Attribute count = getAttrOrNull(node->getCount());
+ Attribute upperBound = getAttrOrNull(node->getUpperBound());
+ Attribute lowerBound = getAttrOrNull(node->getLowerBound());
+ Attribute stride = getAttrOrNull(node->getStride());
+ // DIGenericSubrangeAttr requires lowerBound, stride and one of count or
+ // upperBound.
+ if (!lowerBound || !stride || (!count && !upperBound))
+ return {};
----------------
gysit wrote:
I would expect that the attribute verifier of DIGenericSubrangeAttr already verifies that lowerBound and stride are non-null since they are not optional attribute parameters? There have been issues with attribute verifiers in the past, so I am not a 100% sure this works as expected (if you roundtrip an attribute without a stride or lowerBound does this produce an error?). Anyways, if you prefer the more complete logic I am fine with it.
Note that long term verifiers are preferable over silently dropping stuff during the import. Especially since verifiers also work when generating the debug info in MLIR. There may still be technical issues with attribute verifiers though.
https://github.com/llvm/llvm-project/pull/113441
More information about the Mlir-commits
mailing list