20 #include "llvm/IR/IRBuilder.h"
21 #include "llvm/IR/IntrinsicsRISCV.h"
30 LLVM::ModuleTranslation &moduleTranslation) {
31 auto intAttr = cast<IntegerAttr>(opcodeAttr);
32 unsigned xlenWidth = cast<IntegerType>(intAttr.getType()).getWidth();
33 return llvm::Type::getIntNTy(moduleTranslation.getLLVMContext(), xlenWidth);
38 static llvm::Value *
createVL(llvm::IRBuilderBase &builder, llvm::Value *vl,
39 VectorType vtype, llvm::Type *xlen,
Location loc,
40 LLVM::ModuleTranslation &moduleTranslation) {
42 assert(vtype.isScalable() &&
43 "vl parameter must be set for scalable vectors");
44 return builder.CreateZExtOrTrunc(vl, xlen);
47 assert(vtype.getRank() == 1 &&
"Only 1-d fixed vectors are supported");
52 loc, moduleTranslation);
58 class VCIXDialectLLVMIRTranslationInterface
66 convertOperation(
Operation *op, llvm::IRBuilderBase &builder,
67 LLVM::ModuleTranslation &moduleTranslation)
const final {
69 #include "mlir/Dialect/LLVMIR/VCIXConversions.inc"
77 registry.
insert<vcix::VCIXDialect>();
79 dialect->addInterfaces<VCIXDialectLLVMIRTranslationInterface>();
static llvm::Value * createVL(llvm::IRBuilderBase &builder, llvm::Value *vl, VectorType vtype, llvm::Type *xlen, Location loc, LLVM::ModuleTranslation &moduleTranslation)
Return VL for VCIX intrinsic.
static llvm::Type * getXlenType(Attribute opcodeAttr, LLVM::ModuleTranslation &moduleTranslation)
Infer XLen type from opcode's type.
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)
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
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.
llvm::CallInst * createIntrinsicCall(llvm::IRBuilderBase &builder, llvm::Intrinsic::ID intrinsic, ArrayRef< llvm::Value * > args={}, ArrayRef< llvm::Type * > tys={})
Creates a call to an LLVM IR intrinsic function with the given arguments.
llvm::Constant * getLLVMConstant(llvm::Type *llvmType, Attribute attr, Location loc, const ModuleTranslation &moduleTranslation)
Create an LLVM IR constant of llvmType from the MLIR attribute attr.
Include the generated interface declarations.
void registerVCIXDialectTranslation(DialectRegistry ®istry)
Register the VCIX 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...