30class SPIRVTargetAttrImpl
31 :
public gpu::TargetAttrInterface::FallbackModel<SPIRVTargetAttrImpl> {
33 std::optional<SmallVector<char, 0>>
34 serializeToObject(Attribute attribute, Operation *module,
35 const gpu::TargetOptions &
options)
const;
37 Attribute createObject(Attribute attribute, Operation *module,
38 const SmallVector<char, 0> &
object,
39 const gpu::TargetOptions &
options)
const;
59std::optional<SmallVector<char, 0>> SPIRVTargetAttrImpl::serializeToObject(
64 auto gpuMod = dyn_cast<gpu::GPUModuleOp>(module);
66 module->emitError("expected to be a gpu.module op");
69 auto spvMods = gpuMod.getOps<spirv::ModuleOp>();
73 auto spvMod = *spvMods.begin();
79 spvMod.emitError() <<
"failed to serialize SPIR-V module";
83 SmallVector<char, 0> spvData(spvBinary.size() *
sizeof(uint32_t), 0);
84 std::memcpy(spvData.data(), spvBinary.data(), spvData.size());
92SPIRVTargetAttrImpl::createObject(Attribute attribute, Operation *module,
93 const SmallVector<char, 0> &
object,
94 const gpu::TargetOptions &
options)
const {
95 gpu::CompilationTarget format =
options.getCompilationTarget();
96 DictionaryAttr objectProps;
98 return builder.getAttr<gpu::ObjectAttr>(
100 builder.getStringAttr(StringRef(
object.data(),
object.size())),
101 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.