[Mlir-commits] [mlir] 05927eb - [mlir][LLVM] Tidy up DebugTranslation casting
River Riddle
llvmlistbot at llvm.org
Thu Jan 19 17:43:01 PST 2023
Author: River Riddle
Date: 2023-01-19T17:42:45-08:00
New Revision: 05927eb5ff986e619f155c05727ed1fa478d2c4e
URL: https://github.com/llvm/llvm-project/commit/05927eb5ff986e619f155c05727ed1fa478d2c4e
DIFF: https://github.com/llvm/llvm-project/commit/05927eb5ff986e619f155c05727ed1fa478d2c4e.diff
LOG: [mlir][LLVM] Tidy up DebugTranslation casting
Add a specific class for local scope attributes and remove
some unnecessary casts.
Added:
Modified:
mlir/include/mlir/Dialect/LLVMIR/LLVMAttrs.h
mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
mlir/lib/Target/LLVMIR/DebugTranslation.cpp
mlir/lib/Target/LLVMIR/DebugTranslation.h
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrs.h b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrs.h
index fd2d184e45202..d6619ac8c9b9e 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrs.h
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrs.h
@@ -42,6 +42,16 @@ class DIScopeAttr : public DINodeAttr {
static bool classof(Attribute attr);
};
+/// This class represents a LLVM attribute that describes a local debug info
+/// scope.
+class DILocalScopeAttr : public DIScopeAttr {
+public:
+ using DIScopeAttr::DIScopeAttr;
+
+ /// Support LLVM type casting.
+ static bool classof(Attribute attr);
+};
+
/// This class represents a LLVM attribute that describes a debug info type.
class DITypeAttr : public DINodeAttr {
public:
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
index 275f3194c3638..3b6b67a137a95 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
@@ -55,8 +55,15 @@ bool DINodeAttr::classof(Attribute attr) {
bool DIScopeAttr::classof(Attribute attr) {
return llvm::isa<DICompileUnitAttr, DICompositeTypeAttr, DIFileAttr,
- DILexicalBlockAttr, DILexicalBlockFileAttr,
- DISubprogramAttr>(attr);
+ DILexicalBlockFileAttr, DILocalScopeAttr>(attr);
+}
+
+//===----------------------------------------------------------------------===//
+// DILocalScopeAttr
+//===----------------------------------------------------------------------===//
+
+bool DILocalScopeAttr::classof(Attribute attr) {
+ return llvm::isa<DILexicalBlockAttr, DISubprogramAttr>(attr);
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
index 96f8880204ff4..fd80a773df8e7 100644
--- a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
@@ -153,6 +153,10 @@ DebugTranslation::translateImpl(DILexicalBlockFileAttr attr) {
attr.getDiscriminator());
}
+llvm::DILocalScope *DebugTranslation::translateImpl(DILocalScopeAttr attr) {
+ return cast<llvm::DILocalScope>(translate(DINodeAttr(attr)));
+}
+
llvm::DILocalVariable *
DebugTranslation::translateImpl(DILocalVariableAttr attr) {
return llvm::DILocalVariable::get(
@@ -283,8 +287,8 @@ DebugTranslation::translateLoc(Location loc, llvm::DILocalScope *scope,
// Check for a scope encoded with the location.
if (auto scopedAttr =
- fusedLoc.getMetadata().dyn_cast_or_null<LLVM::DIScopeAttr>())
- scope = cast<llvm::DILocalScope>(translate(scopedAttr));
+ fusedLoc.getMetadata().dyn_cast_or_null<LLVM::DILocalScopeAttr>())
+ scope = translate(scopedAttr);
// For fused locations, merge each of the nodes.
llvmLoc = translateLoc(locations.front(), scope, inlinedAt);
@@ -294,11 +298,10 @@ DebugTranslation::translateLoc(Location loc, llvm::DILocalScope *scope,
}
} else if (auto nameLoc = loc.dyn_cast<NameLoc>()) {
- llvmLoc = translateLoc(loc.cast<NameLoc>().getChildLoc(), scope, inlinedAt);
+ llvmLoc = translateLoc(nameLoc.getChildLoc(), scope, inlinedAt);
} else if (auto opaqueLoc = loc.dyn_cast<OpaqueLoc>()) {
- llvmLoc = translateLoc(loc.cast<OpaqueLoc>().getFallbackLocation(), scope,
- inlinedAt);
+ llvmLoc = translateLoc(opaqueLoc.getFallbackLocation(), scope, inlinedAt);
} else {
llvm_unreachable("unknown location kind");
}
diff --git a/mlir/lib/Target/LLVMIR/DebugTranslation.h b/mlir/lib/Target/LLVMIR/DebugTranslation.h
index f9c87ba09b589..b62bd2bab4cea 100644
--- a/mlir/lib/Target/LLVMIR/DebugTranslation.h
+++ b/mlir/lib/Target/LLVMIR/DebugTranslation.h
@@ -69,6 +69,7 @@ class DebugTranslation {
llvm::DIFile *translateImpl(DIFileAttr attr);
llvm::DILexicalBlock *translateImpl(DILexicalBlockAttr attr);
llvm::DILexicalBlockFile *translateImpl(DILexicalBlockFileAttr attr);
+ llvm::DILocalScope *translateImpl(DILocalScopeAttr attr);
llvm::DILocalVariable *translateImpl(DILocalVariableAttr attr);
llvm::DIScope *translateImpl(DIScopeAttr attr);
llvm::DISubprogram *translateImpl(DISubprogramAttr attr);
More information about the Mlir-commits
mailing list