#include "mlir/Support/LLVM.h"
#include "mlir/Target/LLVMIR/LLVMTranslationInterface.h"
#include "mlir/Target/LLVMIR/TypeToLLVM.h"
-#include "llvm/ADT/TypeSwitch.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/SetVector.h"
void ModuleTranslation::setAccessGroupsMetadata(Operation *op,
llvm::Instruction *inst) {
- auto populateGroupsMetadata = [&](std::optional<ArrayAttr> groupRefs) {
- if (!groupRefs || groupRefs->empty())
+ auto populateGroupsMetadata = [&](ArrayAttr groupRefs) {
+ if (!groupRefs || groupRefs.empty())
return;
llvm::Module *module = inst->getModule();
SmallVector<llvm::Metadata *> groupMDs;
- for (SymbolRefAttr groupRef : groupRefs->getAsRange<SymbolRefAttr>())
+ for (SymbolRefAttr groupRef : groupRefs.getAsRange<SymbolRefAttr>())
groupMDs.push_back(getAccessGroup(op, groupRef));
llvm::MDNode *node = nullptr;
inst->setMetadata(llvm::LLVMContext::MD_access_group, node);
};
- llvm::TypeSwitch<Operation *>(op)
- .Case<LoadOp, StoreOp>(
- [&](auto memOp) { populateGroupsMetadata(memOp.getAccessGroups()); })
- .Default([](auto) { llvm_unreachable("expected LoadOp or StoreOp"); });
+ auto groupRefs =
+ op->getAttrOfType<ArrayAttr>(LLVMDialect::getAccessGroupsAttrName());
+ populateGroupsMetadata(groupRefs);
}
LogicalResult ModuleTranslation::createAliasScopeMetadata() {
void ModuleTranslation::setAliasScopeMetadata(Operation *op,
llvm::Instruction *inst) {
- auto populateScopeMetadata = [&](std::optional<ArrayAttr> scopeRefs,
- unsigned kind) {
- if (!scopeRefs || scopeRefs->empty())
+ auto populateScopeMetadata = [&](ArrayAttr scopeRefs, unsigned kind) {
+ if (!scopeRefs || scopeRefs.empty())
return;
llvm::Module *module = inst->getModule();
SmallVector<llvm::Metadata *> scopeMDs;
- for (SymbolRefAttr scopeRef : scopeRefs->getAsRange<SymbolRefAttr>())
+ for (SymbolRefAttr scopeRef : scopeRefs.getAsRange<SymbolRefAttr>())
scopeMDs.push_back(getAliasScope(op, scopeRef));
llvm::MDNode *node = llvm::MDNode::get(module->getContext(), scopeMDs);
inst->setMetadata(kind, node);
};
- llvm::TypeSwitch<Operation *>(op)
- .Case<LoadOp, StoreOp>([&](auto memOp) {
- populateScopeMetadata(memOp.getAliasScopes(),
- llvm::LLVMContext::MD_alias_scope);
- populateScopeMetadata(memOp.getNoaliasScopes(),
- llvm::LLVMContext::MD_noalias);
- })
- .Default([](auto) { llvm_unreachable("expected LoadOp or StoreOp"); });
+ 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);
}
llvm::MDNode *ModuleTranslation::getTBAANode(Operation *op,