@@ -102,6 +102,7 @@ TEST_F(MLIRTargetLLVM, SKIP_WITHOUT_NATIVE(SerializeToLLVMBitcode)) {
102
102
std::optional<SmallVector<char , 0 >>
103
103
TargetAttrImpl::serializeToObject (Attribute attribute, Operation *module ,
104
104
const gpu::TargetOptions &options) const {
105
+ // Set a dummy attr to be retrieved by `createObject`.
105
106
module ->setAttr (" serialize_attr" , UnitAttr::get (module ->getContext ()));
106
107
std::string targetTriple = llvm::sys::getProcessTriple ();
107
108
LLVM::ModuleToObject serializer (*module , targetTriple, " " , " " );
@@ -112,13 +113,18 @@ Attribute
112
113
TargetAttrImpl::createObject (Attribute attribute, Operation *module ,
113
114
const SmallVector<char , 0 > &object,
114
115
const gpu::TargetOptions &options) const {
116
+ // Create a GPU object with the GPU module dictionary as the object
117
+ // properties.
115
118
return gpu::ObjectAttr::get (
116
119
module ->getContext (), attribute, gpu::CompilationTarget::Offload,
117
120
StringAttr::get (module ->getContext (),
118
121
StringRef (object.data (), object.size ())),
119
122
module ->getAttrDictionary ());
120
123
}
121
124
125
+ // This test checks the correct functioning of `TargetAttrInterface` as an API.
126
+ // In particular, it shows how `TargetAttrInterface::createObject` can leverage
127
+ // the `module` operation argument to retrieve information from the module.
122
128
TEST_F (MLIRTargetLLVM, SKIP_WITHOUT_NATIVE(TargetAttrAPI)) {
123
129
MLIRContext context (registry);
124
130
context.loadAllAvailableDialects ();
0 commit comments