@@ -72,7 +72,7 @@ static LogicalResult convertIntrinsicImpl(OpBuilder &odsBuilder,
72
72
static ArrayRef<unsigned > getSupportedMetadataImpl () {
73
73
static const SmallVector<unsigned > convertibleMetadata = {
74
74
llvm::LLVMContext::MD_prof, llvm::LLVMContext::MD_tbaa,
75
- llvm::LLVMContext::MD_access_group};
75
+ llvm::LLVMContext::MD_access_group, llvm::LLVMContext::MD_loop };
76
76
return convertibleMetadata;
77
77
}
78
78
@@ -141,28 +141,38 @@ static LogicalResult setTBAAAttr(const llvm::MDNode *node, Operation *op,
141
141
return success ();
142
142
}
143
143
144
- // / Searches the symbol references pointing to the access group operations that
145
- // / map to the access group nodes starting from the access group metadata
144
+ // / Looks up all the symbol references pointing to the access group operations
145
+ // / that map to the access group nodes starting from the access group metadata
146
146
// / `node`, and attaches all of them to the imported operation if the lookups
147
147
// / succeed. Returns failure otherwise.
148
148
static LogicalResult setAccessGroupAttr (const llvm::MDNode *node, Operation *op,
149
149
LLVM::ModuleImport &moduleImport) {
150
- // An access group node is either access group or an access group list.
151
- SmallVector<Attribute> accessGroups;
152
- if (!node->getNumOperands ())
153
- accessGroups.push_back (moduleImport.lookupAccessGroupAttr (node));
154
- for (const llvm::MDOperand &operand : node->operands ()) {
155
- auto *node = cast<llvm::MDNode>(operand.get ());
156
- accessGroups.push_back (moduleImport.lookupAccessGroupAttr (node));
157
- }
158
- // Exit if one of the access group node lookups failed.
159
- if (llvm::is_contained (accessGroups, nullptr ))
150
+ FailureOr<SmallVector<SymbolRefAttr>> accessGroups =
151
+ moduleImport.lookupAccessGroupAttrs (node);
152
+ if (failed (accessGroups))
160
153
return failure ();
161
154
155
+ SmallVector<Attribute> accessGroupAttrs (accessGroups->begin (),
156
+ accessGroups->end ());
162
157
op->setAttr (LLVMDialect::getAccessGroupsAttrName (),
163
- ArrayAttr::get (op->getContext (), accessGroups ));
158
+ ArrayAttr::get (op->getContext (), accessGroupAttrs ));
164
159
return success ();
165
160
}
161
+
162
+ // / Converts the given loop metadata node to an MLIR loop annotation attribute
163
+ // / and attaches it to the imported operation if the translation succeeds.
164
+ // / Returns failure otherwise.
165
+ static LogicalResult setLoopAttr (const llvm::MDNode *node, Operation *op,
166
+ LLVM::ModuleImport &moduleImport) {
167
+ LoopAnnotationAttr attr =
168
+ moduleImport.translateLoopAnnotationAttr (node, op->getLoc ());
169
+ if (!attr)
170
+ return failure ();
171
+
172
+ op->setAttr (LLVMDialect::getLoopAttrName (), attr);
173
+ return success ();
174
+ }
175
+
166
176
namespace {
167
177
168
178
// / Implementation of the dialect interface that converts operations belonging
@@ -191,6 +201,8 @@ class LLVMDialectLLVMIRImportInterface : public LLVMImportDialectInterface {
191
201
return setTBAAAttr (node, op, moduleImport);
192
202
if (kind == llvm::LLVMContext::MD_access_group)
193
203
return setAccessGroupAttr (node, op, moduleImport);
204
+ if (kind == llvm::LLVMContext::MD_loop)
205
+ return setLoopAttr (node, op, moduleImport);
194
206
195
207
// A handler for a supported metadata kind is missing.
196
208
llvm_unreachable (" unknown metadata type" );
0 commit comments