[Mlir-commits] [mlir] 2ea6bb6 - [mlir][llvm] Use interfaces in the translation to LLVMIR.
Tobias Gysi
llvmlistbot at llvm.org
Thu Mar 2 04:02:05 PST 2023
Author: Tobias Gysi
Date: 2023-03-02T13:00:57+01:00
New Revision: 2ea6bb645eff7219c10eda83866bd27c1da462e1
URL: https://github.com/llvm/llvm-project/commit/2ea6bb645eff7219c10eda83866bd27c1da462e1
DIFF: https://github.com/llvm/llvm-project/commit/2ea6bb645eff7219c10eda83866bd27c1da462e1.diff
LOG: [mlir][llvm] Use interfaces in the translation to LLVMIR.
The revision consistently uses the AliasAnalysisOp and AccessGroupOp
interfaces in the translation from MLIR to LLVMIR. It thus drops the
last string based lookups of alias scope and access group attributes.
Depends on D144851
Reviewed By: Dinistro
Differential Revision: https://reviews.llvm.org/D145037
Added:
Modified:
mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.cpp
mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.h
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h b/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
index 90168a1e3011d..67091257a3cf9 100644
--- a/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
+++ b/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
@@ -126,10 +126,12 @@ class ModuleTranslation {
llvm::MDNode *getAliasScope(Operation *op, SymbolRefAttr aliasScopeRef) const;
// Sets LLVM metadata for memory operations that are in a parallel loop.
- void setAccessGroupsMetadata(Operation *op, llvm::Instruction *inst);
+ void setAccessGroupsMetadata(AccessGroupOpInterface op,
+ llvm::Instruction *inst);
// Sets LLVM metadata for memory operations that have alias scope information.
- void setAliasScopeMetadata(Operation *op, llvm::Instruction *inst);
+ void setAliasScopeMetadata(AliasAnalysisOpInterface op,
+ llvm::Instruction *inst);
/// Sets LLVM TBAA metadata for memory operations that have TBAA attributes.
void setTBAAMetadata(AliasAnalysisOpInterface op, llvm::Instruction *inst);
diff --git a/mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.cpp b/mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.cpp
index 4a535dcc3a8d3..6abcf6964abed 100644
--- a/mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.cpp
@@ -278,8 +278,8 @@ LoopAnnotationTranslation::getAccessGroup(Operation *op,
}
llvm::MDNode *
-LoopAnnotationTranslation::getAccessGroups(Operation *op,
- ArrayAttr accessGroupRefs) const {
+LoopAnnotationTranslation::getAccessGroups(AccessGroupOpInterface op) const {
+ ArrayAttr accessGroupRefs = op.getAccessGroupsOrNull();
if (!accessGroupRefs || accessGroupRefs.empty())
return nullptr;
diff --git a/mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.h b/mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.h
index 4de54f3998300..e663f64b061fc 100644
--- a/mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.h
+++ b/mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.h
@@ -39,10 +39,9 @@ class LoopAnnotationTranslation {
llvm::MDNode *getAccessGroup(Operation *op,
SymbolRefAttr accessGroupRef) const;
- /// Returns the LLVM metadata corresponding to a list of symbol reference to
- /// an mlir LLVM dialect access group operation. Returns nullptr if
- /// `accessGroupRefs` is null or empty.
- llvm::MDNode *getAccessGroups(Operation *op, ArrayAttr accessGroupRefs) const;
+ /// Returns the LLVM metadata corresponding to the access group operations
+ /// referenced by the AccessGroupOpInterface or null if there are none.
+ llvm::MDNode *getAccessGroups(AccessGroupOpInterface op) const;
private:
/// Returns the LLVM metadata corresponding to a llvm loop metadata attribute.
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index 164cd1f3e2bb9..15e7318f55f10 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -998,17 +998,10 @@ LogicalResult ModuleTranslation::createAccessGroupMetadata() {
return loopAnnotationTranslation->createAccessGroupMetadata();
}
-void ModuleTranslation::setAccessGroupsMetadata(Operation *op,
+void ModuleTranslation::setAccessGroupsMetadata(AccessGroupOpInterface op,
llvm::Instruction *inst) {
- auto populateGroupsMetadata = [&](ArrayAttr groupRefs) {
- if (llvm::MDNode *node =
- loopAnnotationTranslation->getAccessGroups(op, groupRefs))
- inst->setMetadata(llvm::LLVMContext::MD_access_group, node);
- };
-
- auto groupRefs =
- op->getAttrOfType<ArrayAttr>(LLVMDialect::getAccessGroupsAttrName());
- populateGroupsMetadata(groupRefs);
+ if (llvm::MDNode *node = loopAnnotationTranslation->getAccessGroups(op))
+ inst->setMetadata(llvm::LLVMContext::MD_access_group, node);
}
LogicalResult ModuleTranslation::createAliasScopeMetadata() {
@@ -1060,7 +1053,7 @@ ModuleTranslation::getAliasScope(Operation *op,
return aliasScopeMetadataMapping.lookup(aliasScopeOp);
}
-void ModuleTranslation::setAliasScopeMetadata(Operation *op,
+void ModuleTranslation::setAliasScopeMetadata(AliasAnalysisOpInterface op,
llvm::Instruction *inst) {
auto populateScopeMetadata = [&](ArrayAttr scopeRefs, unsigned kind) {
if (!scopeRefs || scopeRefs.empty())
@@ -1073,13 +1066,10 @@ void ModuleTranslation::setAliasScopeMetadata(Operation *op,
inst->setMetadata(kind, node);
};
- auto aliasScopeRefs =
- op->getAttrOfType<ArrayAttr>(LLVMDialect::getAliasScopesAttrName());
- populateScopeMetadata(aliasScopeRefs, llvm::LLVMContext::MD_alias_scope);
-
- auto noaliasScopeRefs =
- op->getAttrOfType<ArrayAttr>(LLVMDialect::getNoAliasScopesAttrName());
- populateScopeMetadata(noaliasScopeRefs, llvm::LLVMContext::MD_noalias);
+ populateScopeMetadata(op.getAliasScopesOrNull(),
+ llvm::LLVMContext::MD_alias_scope);
+ populateScopeMetadata(op.getNoAliasScopesOrNull(),
+ llvm::LLVMContext::MD_noalias);
}
llvm::MDNode *ModuleTranslation::getTBAANode(Operation *op,
More information about the Mlir-commits
mailing list