30class SPIRVTargetAttrImpl
31 :
public gpu::TargetAttrInterface::FallbackModel<SPIRVTargetAttrImpl> {
33 std::optional<mlir::gpu::SerializedObject>
34 serializeToObject(Attribute attribute, Operation *module,
35 const gpu::TargetOptions &
options)
const;
37 Attribute createObject(Attribute attribute, Operation *module,
38 const mlir::gpu::SerializedObject &
object,
39 const gpu::TargetOptions &
options)
const;
59std::optional<mlir::gpu::SerializedObject>
60SPIRVTargetAttrImpl::serializeToObject(
65 auto gpuMod = dyn_cast<gpu::GPUModuleOp>(module);
67 module->emitError("expected to be a gpu.module op");
70 auto spvMods = gpuMod.getOps<spirv::ModuleOp>();
74 auto spvMod = *spvMods.begin();
80 spvMod.emitError() <<
"failed to serialize SPIR-V module";
84 SmallVector<char, 0> spvData(spvBinary.size() *
sizeof(uint32_t), 0);
85 std::memcpy(spvData.data(), spvBinary.data(), spvData.size());
88 return gpu::SerializedObject{std::move(spvData)};
93SPIRVTargetAttrImpl::createObject(Attribute attribute, Operation *module,
94 const mlir::gpu::SerializedObject &
object,
95 const gpu::TargetOptions &
options)
const {
96 gpu::CompilationTarget format =
options.getCompilationTarget();
97 DictionaryAttr objectProps;
99 return builder.getAttr<gpu::ObjectAttr>(
101 builder.getStringAttr(
102 StringRef(
object.getObject().data(),
object.getObject().size())),
103 objectProps,
nullptr);
static llvm::ManagedStatic< PassManagerOptions > options
Attributes are known-constant values of operations.
MLIRContext * getContext() const
Return the context this attribute belongs to.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
bool addExtension(TypeID extensionID, std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
MLIRContext is the top-level object for a collection of MLIR operations.
void appendDialectRegistry(const DialectRegistry ®istry)
Append the contents of the given dialect registry to the registry associated with this context.
Operation is the basic unit of execution within MLIR.
static void attachInterface(MLIRContext &context)
This class serves as an opaque interface for passing options to the TargetAttrInterface methods.
LogicalResult serialize(ModuleOp moduleOp, SmallVectorImpl< uint32_t > &binary, const SerializationOptions &options={})
Serializes the given SPIR-V moduleOp and writes to binary.
void registerSPIRVTargetInterfaceExternalModels(DialectRegistry ®istry)
Registers the TargetAttrInterface for the #spirv.target_env attribute in the given registry.
Include the generated interface declarations.