20 #include "llvm/ADT/TypeSwitch.h"
21 #include "llvm/IR/Constants.h"
22 #include "llvm/IR/LLVMContext.h"
23 #include "llvm/IR/Metadata.h"
25 #include "llvm/IR/ConstantRange.h"
26 #include "llvm/IR/IRBuilder.h"
27 #include "llvm/Support/raw_ostream.h"
35 class XeVMDialectLLVMIRTranslationInterface
44 LLVM::ModuleTranslation &moduleTranslation)
const final {
45 StringRef attrName = attribute.getName().getValue();
46 if (attrName == mlir::xevm::XeVMDialect::getCacheControlsAttrName()) {
47 auto cacheControlsArray = dyn_cast<ArrayAttr>(attribute.getValue());
48 if (cacheControlsArray.size() != 2) {
49 return op->emitOpError(
50 "Expected both L1 and L3 cache control attributes!");
52 if (instructions.size() != 1) {
53 return op->emitOpError(
"Expecting a single instruction");
55 return handleDecorationCacheControl(instructions.front(),
56 cacheControlsArray.getValue());
58 auto func = dyn_cast<LLVM::LLVMFuncOp>(op);
66 static LogicalResult handleDecorationCacheControl(llvm::Instruction *inst,
69 llvm::LLVMContext &ctx = inst->getContext();
70 llvm::Type *i32Ty = llvm::IntegerType::getInt32Ty(ctx);
72 attrs, std::back_inserter(decorations),
73 [&ctx, i32Ty](
Attribute attr) -> llvm::Metadata * {
74 auto valuesArray = dyn_cast<ArrayAttr>(attr).getValue();
75 std::array<llvm::Metadata *, 4> metadata;
77 valuesArray, metadata.begin(), [i32Ty](
Attribute valueAttr) {
78 return llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
79 i32Ty, cast<IntegerAttr>(valueAttr).getValue()));
83 constexpr llvm::StringLiteral decorationCacheControlMDName =
84 "spirv.DecorationCacheControlINTEL";
85 inst->setMetadata(decorationCacheControlMDName,
93 registry.
insert<xevm::XeVMDialect>();
95 dialect->addInterfaces<XeVMDialectLLVMIRTranslationInterface>();
Attributes are known-constant values of operations.
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.
Base class for dialect interfaces providing translation to LLVM IR.
LLVMTranslationDialectInterface(Dialect *dialect)
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.
NamedAttribute represents a combination of a name and an Attribute value.
Operation is the basic unit of execution within MLIR.
Include the generated interface declarations.
void registerXeVMDialectTranslation(mlir::DialectRegistry ®istry)
Register the XeVM dialect and the translation from it to the LLVM IR in the given registry;.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...