19 #include "llvm/IR/IRBuilder.h" 20 #include "llvm/IR/IntrinsicsAMDGPU.h" 21 #include "llvm/Support/raw_ostream.h" 32 StringRef fnName,
int parameter) {
33 llvm::Module *module = builder.GetInsertBlock()->getModule();
34 llvm::FunctionType *functionType = llvm::FunctionType::get(
35 llvm::Type::getInt64Ty(module->getContext()),
36 llvm::Type::getInt32Ty(module->getContext()),
38 llvm::Function *fn = dyn_cast<llvm::Function>(
39 module->getOrInsertFunction(fnName, functionType).getCallee());
40 llvm::Value *fnOp0 = llvm::ConstantInt::get(
41 llvm::Type::getInt32Ty(module->getContext()), parameter);
48 class ROCDLDialectLLVMIRTranslationInterface
56 convertOperation(
Operation *op, llvm::IRBuilderBase &builder,
59 #include "mlir/Dialect/LLVMIR/ROCDLConversions.inc" 68 if (attribute.
getName() == ROCDL::ROCDLDialect::getKernelFuncAttrName()) {
69 auto func = dyn_cast<LLVM::LLVMFuncOp>(op);
79 llvm::Function *llvmFunc =
81 llvmFunc->setCallingConv(llvm::CallingConv::AMDGPU_KERNEL);
82 if (!llvmFunc->hasFnAttribute(
"amdgpu-flat-work-group-size")) {
83 llvmFunc->addFnAttr(
"amdgpu-flat-work-group-size",
"1, 256");
85 llvmFunc->addFnAttr(
"amdgpu-implicitarg-num-bytes",
"56");
88 if (
"rocdl.max_flat_work_group_size" == attribute.
getName()) {
89 auto func = dyn_cast<LLVM::LLVMFuncOp>(op);
96 llvm::Function *llvmFunc =
99 llvm::raw_svector_ostream attrValueStream(llvmAttrValue);
100 attrValueStream <<
"1, " <<
value.getInt();
101 llvmFunc->addFnAttr(
"amdgpu-flat-work-group-size", llvmAttrValue);
109 registry.
insert<ROCDL::ROCDLDialect>();
111 dialect->addInterfaces<ROCDLDialectLLVMIRTranslationInterface>();
Include the generated interface declarations.
Operation is a basic unit of execution within MLIR.
Attribute getValue() const
Return the value of the attribute.
void appendDialectRegistry(const DialectRegistry ®istry)
Append the contents of the given dialect registry to the registry associated with this context...
void registerROCDLDialectTranslation(DialectRegistry ®istry)
Register the ROCDL dialect and the translation from it to the LLVM IR in the given registry;...
static constexpr const bool value
NamedAttribute represents a combination of a name and an Attribute value.
llvm::Value * 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.
Implementation class for module translation.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
void addExtension(std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
This class represents an efficient way to signal success or failure.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
Base class for dialect interfaces providing translation to LLVM IR.
StringAttr getName() const
Return the name of the attribute.
llvm::Function * lookupFunction(StringRef name) const
Finds an LLVM IR function by its name.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
MLIRContext is the top-level object for a collection of MLIR operations.
LLVMTranslationDialectInterface(Dialect *dialect)
static llvm::Value * createDeviceFunctionCall(llvm::IRBuilderBase &builder, StringRef fnName, int parameter)