MLIR
15.0.0git
|
#include "mlir/Target/LLVMIR/ModuleTranslation.h"
#include "DebugTranslation.h"
#include "mlir/Dialect/DLTI/DLTI.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/LLVMIR/Transforms/LegalizeForExport.h"
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/RegionGraphTraits.h"
#include "mlir/Support/LLVM.h"
#include "mlir/Target/LLVMIR/LLVMTranslationInterface.h"
#include "mlir/Target/LLVMIR/TypeToLLVM.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InlineAsm.h"
#include "llvm/IR/IntrinsicsNVPTX.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"
#include "mlir/Dialect/LLVMIR/LLVMConversionEnumsToLLVM.inc"
Go to the source code of this file.
Functions | |
FailureOr< llvm::DataLayout > | translateDataLayout (DataLayoutSpecInterface attribute, const DataLayout &dataLayout, Optional< Location > loc=llvm::None) |
Translates the given data layout spec attribute to the LLVM IR data layout. More... | |
static llvm::Constant * | buildSequentialConstant (ArrayRef< llvm::Constant *> &constants, ArrayRef< int64_t > shape, llvm::Type *type, Location loc) |
Builds a constant of a sequential LLVM type type , potentially containing other sequential types recursively, from the individual constant values provided in constants . More... | |
static llvm::Type * | getInnermostElementType (llvm::Type *type) |
Returns the first non-sequential type nested in sequential types. More... | |
static llvm::Constant * | convertDenseElementsAttr (Location loc, DenseElementsAttr denseElementsAttr, llvm::Type *llvmType, const ModuleTranslation &moduleTranslation) |
Convert a dense elements attribute to an LLVM IR constant using its raw data storage if possible. More... | |
static Value | getPHISourceValue (Block *current, Block *pred, unsigned numArguments, unsigned index) |
Get the SSA value passed to the current block from the terminator operation of its predecessor. More... | |
static Block & | getModuleBody (Operation *module) |
A helper method to get the single Block in an operation honoring LLVM's module requirements. More... | |
static bool | shouldDropGlobalInitializer (llvm::GlobalValue::LinkageTypes linkage, llvm::Constant *cst) |
A helper method to decide if a constant must not be set as a global variable initializer. More... | |
static void | addRuntimePreemptionSpecifier (bool dsoLocalRequested, llvm::GlobalValue *gv) |
Sets the runtime preemption specifier of gv to dso_local if dsoLocalRequested is true, otherwise it is left unchanged. More... | |
static LogicalResult | checkedAddLLVMFnAttribute (Location loc, llvm::Function *llvmFunc, StringRef key, StringRef value=StringRef()) |
Attempts to add an attribute identified by key , optionally with the given value to LLVM function llvmFunc . More... | |
static LogicalResult | forwardPassthroughAttributes (Location loc, Optional< ArrayAttr > attributes, llvm::Function *llvmFunc) |
Attaches the attributes listed in the given array attribute to llvmFunc . More... | |
static std::unique_ptr< llvm::Module > | prepareLLVMModule (Operation *m, llvm::LLVMContext &llvmContext, StringRef name) |
|
static |
Sets the runtime preemption specifier of gv
to dso_local if dsoLocalRequested
is true, otherwise it is left unchanged.
Definition at line 625 of file ModuleTranslation.cpp.
References mlir::Constant, mlir::emitError(), mlir::failed(), mlir::failure(), mlir::LLVM::detail::getLLVMConstant(), mlir::Operation::getLoc(), getModuleBody(), mlir::Operation::getResult(), shouldDropGlobalInitializer(), and mlir::success().
Referenced by forwardPassthroughAttributes().
|
static |
Builds a constant of a sequential LLVM type type
, potentially containing other sequential types recursively, from the individual constant values provided in constants
.
shape
contains the number of elements in nested sequential types. Reports errors at loc
and returns nullptr on error.
Definition at line 132 of file ModuleTranslation.cpp.
References mlir::Constant, and mlir::emitError().
Referenced by convertDenseElementsAttr(), and mlir::LLVM::detail::getLLVMConstant().
|
static |
Attempts to add an attribute identified by key
, optionally with the given value
to LLVM function llvmFunc
.
Reports errors at loc
if any. If the attribute has a kind known to LLVM IR, create the attribute of this kind, otherwise keep it as a string attribute. Performs additional checks for attributes known to have or not have a value in order to avoid assertions inside LLVM upon construction.
Definition at line 733 of file ModuleTranslation.cpp.
Referenced by forwardPassthroughAttributes().
|
static |
Convert a dense elements attribute to an LLVM IR constant using its raw data storage if possible.
This supports elements attributes of tensor or vector type and avoids constructing separate objects for individual values of the innermost dimension. Constants for other dimensions are still constructed recursively. Returns null if constructing from raw data is not supported for this type, e.g., element type is not a power-of-two-sized primitive. Reports other errors at loc
.
Definition at line 187 of file ModuleTranslation.cpp.
References buildSequentialConstant(), mlir::Constant, getInnermostElementType(), mlir::LLVM::detail::getLLVMConstant(), mlir::DenseElementsAttr::getNumElements(), mlir::DenseElementsAttr::getRawData(), mlir::DenseElementsAttr::getSplatValue(), mlir::DenseElementsAttr::getType(), and mlir::DenseElementsAttr::isSplat().
Referenced by mlir::LLVM::detail::getLLVMConstant().
|
static |
Attaches the attributes listed in the given array attribute to llvmFunc
.
Reports error to loc
if any and returns immediately. Expects attributes
to be an array attribute containing either string attributes, treated as value-less LLVM attributes, or array attributes containing two string attributes, with the first string being the name of the corresponding LLVM attribute and the second string beings its value. Note that even integer attributes are expected to have their values expressed as strings.
Definition at line 773 of file ModuleTranslation.cpp.
References addRuntimePreemptionSpecifier(), checkedAddLLVMFnAttribute(), mlir::LLVM::detail::connectPHINodes(), mlir::Constant, mlir::Type::dyn_cast(), mlir::emitError(), mlir::failed(), mlir::failure(), mlir::Operation::getDialectAttrs(), mlir::function_interface_impl::getFunctionType(), mlir::LLVM::detail::getLLVMConstant(), getModuleBody(), mlir::LLVM::detail::getTopologicallySortedBlocks(), mlir::Value::getType(), and mlir::success().
|
static |
Returns the first non-sequential type nested in sequential types.
Definition at line 167 of file ModuleTranslation.cpp.
References mlir::Constant.
Referenced by convertDenseElementsAttr(), and mlir::LLVM::detail::getLLVMConstant().
A helper method to get the single Block in an operation honoring LLVM's module requirements.
Definition at line 608 of file ModuleTranslation.cpp.
References mlir::Region::front(), and mlir::Operation::getRegion().
Referenced by addRuntimePreemptionSpecifier(), forwardPassthroughAttributes(), and prepareLLVMModule().
|
static |
Get the SSA value passed to the current block from the terminator operation of its predecessor.
Definition at line 433 of file ModuleTranslation.cpp.
References mlir::detail::enumerate(), mlir::Operation::getNumSuccessors(), mlir::Operation::getOperand(), mlir::Operation::getSuccessor(), and mlir::Block::getTerminator().
Referenced by mlir::LLVM::detail::connectPHINodes().
|
static |
Definition at line 1093 of file ModuleTranslation.cpp.
References mlir::LLVM::ensureDistinctSuccessors(), mlir::failed(), mlir::Operation::getAttr(), mlir::Operation::getContext(), mlir::Operation::getLoc(), getModuleBody(), mlir::MLIRContext::getOrLoadDialect(), mlir::mod(), mlir::LLVM::satisfiesLLVMModule(), mlir::translateDataLayout(), and mlir::translateModuleToLLVMIR().
|
static |
A helper method to decide if a constant must not be set as a global variable initializer.
For an external linkage variable, the variable with an initializer is considered externally visible and defined in this module, the variable without an initializer is externally available and is defined elsewhere.
Definition at line 617 of file ModuleTranslation.cpp.
Referenced by addRuntimePreemptionSpecifier().
FailureOr<llvm::DataLayout> translateDataLayout | ( | DataLayoutSpecInterface | attribute, |
const DataLayout & | dataLayout, | ||
Optional< Location > | loc = llvm::None |
||
) |
Translates the given data layout spec attribute to the LLVM IR data layout.
Only integer, float and endianness entries are currently supported.
Definition at line 57 of file ModuleTranslation.cpp.
References mlir::Constant, mlir::emitError(), mlir::failed(), mlir::failure(), mlir::DataLayout::getTypeABIAlignment(), mlir::DataLayout::getTypePreferredAlignment(), mlir::DataLayout::getTypeSizeInBits(), and value.