MLIR
17.0.0git
|
Implementation class for module translation. More...
#include "mlir/Target/LLVMIR/ModuleTranslation.h"
Classes | |
struct | SaveStack |
RAII object calling stackPush/stackPop on construction/destruction. More... | |
class | StackFrame |
Common CRTP base class for ModuleTranslation stack frames. More... | |
class | StackFrameBase |
Concrete CRTP base class for ModuleTranslation stack frames. More... | |
Public Member Functions | |
void | mapFunction (StringRef name, llvm::Function *func) |
Stores the mapping between a function name and its LLVM IR representation. More... | |
llvm::Function * | lookupFunction (StringRef name) const |
Finds an LLVM IR function by its name. More... | |
void | mapValue (Value mlir, llvm::Value *llvm) |
Stores the mapping between an MLIR value and its LLVM IR counterpart. More... | |
llvm::Value *& | mapValue (Value value) |
Provides write-once access to store the LLVM IR value corresponding to the given MLIR value. More... | |
llvm::Value * | lookupValue (Value value) const |
Finds an LLVM IR value corresponding to the given MLIR value. More... | |
SmallVector< llvm::Value * > | lookupValues (ValueRange values) |
Looks up remapped a list of remapped values. More... | |
void | mapBlock (Block *mlir, llvm::BasicBlock *llvm) |
Stores the mapping between an MLIR block and LLVM IR basic block. More... | |
llvm::BasicBlock * | lookupBlock (Block *block) const |
Finds an LLVM IR basic block that corresponds to the given MLIR block. More... | |
void | mapBranch (Operation *mlir, llvm::Instruction *llvm) |
Stores the mapping between an MLIR operation with successors and a corresponding LLVM IR instruction. More... | |
llvm::Instruction * | lookupBranch (Operation *op) const |
Finds an LLVM IR instruction that corresponds to the given MLIR operation with successors. More... | |
void | forgetMapping (Region ®ion) |
Removes the mapping for blocks contained in the region and values defined in these blocks. More... | |
llvm::MDNode * | getAccessGroup (Operation &opInst, SymbolRefAttr accessGroupRef) const |
Returns the LLVM metadata corresponding to a reference to an mlir LLVM dialect access group operation. More... | |
llvm::MDNode * | getAliasScope (Operation &opInst, SymbolRefAttr aliasScopeRef) const |
Returns the LLVM metadata corresponding to a reference to an mlir LLVM dialect alias scope operation. More... | |
llvm::MDNode * | lookupLoopOptionsMetadata (Attribute options) const |
Returns the LLVM metadata corresponding to a llvm loop's codegen options attribute. More... | |
void | mapLoopOptionsMetadata (Attribute options, llvm::MDNode *metadata) |
void | setAccessGroupsMetadata (Operation *op, llvm::Instruction *inst) |
void | setAliasScopeMetadata (Operation *op, llvm::Instruction *inst) |
void | setTBAAMetadata (Operation *op, llvm::Instruction *inst) |
Sets LLVM TBAA metadata for memory operations that have TBAA attributes. More... | |
llvm::Type * | convertType (Type type) |
Converts the type from MLIR LLVM dialect to LLVM. More... | |
MLIRContext & | getContext () |
Returns the MLIR context of the module being translated. More... | |
llvm::LLVMContext & | getLLVMContext () const |
Returns the LLVM context in which the IR is being constructed. More... | |
llvm::GlobalValue * | lookupGlobal (Operation *op) |
Finds an LLVM IR global value that corresponds to the given MLIR operation defining a global value. More... | |
llvm::OpenMPIRBuilder * | getOpenMPBuilder () |
Returns the OpenMP IR builder associated with the LLVM IR module being constructed. More... | |
const llvm::DILocation * | translateLoc (Location loc, llvm::DILocalScope *scope) |
Translates the given location. More... | |
llvm::Metadata * | translateDebugInfo (LLVM::DINodeAttr attr) |
Translates the given LLVM debug info metadata. More... | |
LogicalResult | convertBlock (Block &bb, bool ignoreArguments, llvm::IRBuilderBase &builder) |
Translates the contents of the given block to LLVM IR using this translator. More... | |
llvm::NamedMDNode * | getOrInsertNamedModuleMetadata (StringRef name) |
Gets the named metadata in the LLVM IR module being constructed, creating it if it does not exist. More... | |
template<typename T , typename... Args> | |
void | stackPush (Args &&...args) |
Creates a stack frame of type T on ModuleTranslation stack. More... | |
void | stackPop () |
Pops the last element from the ModuleTranslation stack. More... | |
template<typename T > | |
WalkResult | stackWalk (llvm::function_ref< WalkResult(const T &)> callback) const |
Calls callback for every ModuleTranslation stack frame of type T starting from the top of the stack. More... | |
SymbolTableCollection & | symbolTable () |
Friends | |
std::unique_ptr< llvm::Module > | mlir::translateModuleToLLVMIR (Operation *, llvm::LLVMContext &, StringRef) |
Implementation class for module translation.
Holds a reference to the module being translated, and the mappings between the original and the translated functions, basic blocks and values. It is practically easier to hold these mappings in one class since the conversion of control flow operations needs to look up block and function mappings.
Definition at line 53 of file ModuleTranslation.h.
LogicalResult ModuleTranslation::convertBlock | ( | Block & | bb, |
bool | ignoreArguments, | ||
llvm::IRBuilderBase & | builder | ||
) |
Translates the contents of the given block to LLVM IR using this translator.
Convert block to LLVM IR.
The LLVM IR basic block corresponding to the given block is expected to exist in the mapping of this translator. Uses builder
to translate the IR, leaving it at the end of the block. If ignoreArguments
is set, does not produce PHI nodes for the block arguments. Otherwise, the PHI nodes are constructed for block arguments but are not connected to the predecessors that may not exist yet.
Unless ignoreArguments
is set, emit PHI nodes to define values corresponding to the MLIR block arguments. These nodes are not connected to the source basic blocks, which may not exist yet. Uses builder
to construct the LLVM IR. Expects the LLVM IR basic block to have been created for bb
and included in the block mapping. Inserts new instructions at the end of the block and leaves builder
in a state suitable for further insertion into the end of the block.
Definition at line 581 of file ModuleTranslation.cpp.
References convertType(), mlir::emitError(), mlir::failed(), mlir::failure(), mlir::Block::front(), mlir::Block::getArguments(), mlir::Operation::getLoc(), mlir::Block::getPredecessors(), mlir::LLVM::isCompatibleType(), lookupBlock(), mapValue(), and mlir::success().
Referenced by convertDataOp(), convertOmpAtomicCapture(), convertOmpAtomicUpdate(), convertOmpOpRegions(), and inlineConvertOmpRegions().
llvm::Type * ModuleTranslation::convertType | ( | Type | type | ) |
Converts the type from MLIR LLVM dialect to LLVM.
Definition at line 1231 of file ModuleTranslation.cpp.
References mlir::LLVM::TypeToLLVMIRTranslator::translateType().
Referenced by convertBlock(), convertOmpAtomicCapture(), convertOmpAtomicRead(), convertOmpAtomicUpdate(), convertOmpAtomicWrite(), convertOmpOpRegions(), convertOmpReductionOp(), convertOmpWsLoop(), convertOperationImpl(), and getOverloadedDeclaration().
void ModuleTranslation::forgetMapping | ( | Region & | region | ) |
Removes the mapping for blocks contained in the region and values defined in these blocks.
Definition at line 422 of file ModuleTranslation.cpp.
Referenced by convertOmpOpRegions(), and inlineConvertOmpRegions().
llvm::MDNode * ModuleTranslation::getAccessGroup | ( | Operation & | opInst, |
SymbolRefAttr | accessGroupRef | ||
) | const |
Returns the LLVM metadata corresponding to a reference to an mlir LLVM dialect access group operation.
Definition at line 999 of file ModuleTranslation.cpp.
References mlir::Operation::getParentOp(), and mlir::SymbolTable::lookupNearestSymbolFrom().
Referenced by setAccessGroupsMetadata(), and setLoopMetadata().
llvm::MDNode * ModuleTranslation::getAliasScope | ( | Operation & | opInst, |
SymbolRefAttr | aliasScopeRef | ||
) | const |
Returns the LLVM metadata corresponding to a reference to an mlir LLVM dialect alias scope operation.
Definition at line 1080 of file ModuleTranslation.cpp.
References mlir::Operation::getParentOp(), and mlir::SymbolTable::lookupNearestSymbolFrom().
Referenced by setAliasScopeMetadata().
|
inline |
Returns the MLIR context of the module being translated.
Definition at line 159 of file ModuleTranslation.h.
References mlir::Operation::getContext().
Referenced by convertOperationImpl().
|
inline |
Returns the LLVM context in which the IR is being constructed.
Definition at line 162 of file ModuleTranslation.h.
Referenced by convertBranchWeights(), convertOmpCritical(), convertOperationImpl(), and mlir::LLVM::detail::getLLVMConstant().
|
inline |
Returns the OpenMP IR builder associated with the LLVM IR module being constructed.
Definition at line 172 of file ModuleTranslation.h.
Referenced by convertDataOp(), convertOmpAtomicCapture(), convertOmpAtomicRead(), convertOmpAtomicUpdate(), convertOmpAtomicWrite(), convertOmpCritical(), convertOmpMaster(), convertOmpOrdered(), convertOmpOrderedRegion(), convertOmpParallel(), convertOmpSections(), convertOmpSimdLoop(), convertOmpSingle(), convertOmpTaskgroupOp(), convertOmpTaskOp(), convertOmpThreadprivate(), convertOmpWsLoop(), convertStandaloneDataOp(), and processOperands().
llvm::NamedMDNode * ModuleTranslation::getOrInsertNamedModuleMetadata | ( | StringRef | name | ) |
Gets the named metadata in the LLVM IR module being constructed, creating it if it does not exist.
Definition at line 1254 of file ModuleTranslation.cpp.
|
inline |
Finds an LLVM IR basic block that corresponds to the given MLIR block.
Definition at line 99 of file ModuleTranslation.h.
Referenced by mlir::LLVM::detail::connectPHINodes(), convertBlock(), convertDataOp(), convertOmpOpRegions(), and convertOperationImpl().
|
inline |
Finds an LLVM IR instruction that corresponds to the given MLIR operation with successors.
Definition at line 114 of file ModuleTranslation.h.
Referenced by mlir::LLVM::detail::connectPHINodes().
|
inline |
Finds an LLVM IR function by its name.
Definition at line 67 of file ModuleTranslation.h.
Referenced by convertDataOp(), convertOperationImpl(), convertStandaloneDataOp(), and mlir::LLVM::detail::getLLVMConstant().
|
inline |
Finds an LLVM IR global value that corresponds to the given MLIR operation defining a global value.
Definition at line 166 of file ModuleTranslation.h.
Referenced by convertOmpThreadprivate(), and convertOperationImpl().
|
inline |
Returns the LLVM metadata corresponding to a llvm loop's codegen options attribute.
Definition at line 134 of file ModuleTranslation.h.
References options.
Referenced by setLoopMetadata().
|
inline |
Finds an LLVM IR value corresponding to the given MLIR value.
Definition at line 84 of file ModuleTranslation.h.
Referenced by mlir::LLVM::detail::connectPHINodes(), convertOmpAtomicCapture(), convertOmpAtomicRead(), convertOmpAtomicUpdate(), convertOmpAtomicWrite(), convertOmpOpRegions(), convertOmpParallel(), convertOmpReductionOp(), convertOmpSimdLoop(), convertOmpWsLoop(), convertOperationImpl(), lookupValues(), and processOperands().
SmallVector< llvm::Value * > ModuleTranslation::lookupValues | ( | ValueRange | values | ) |
Looks up remapped a list of remapped values.
A helper to look up remapped operands in the value remapping table.
Definition at line 1236 of file ModuleTranslation.cpp.
References lookupValue().
Referenced by convertCallLLVMIntrinsicOp(), convertOmpOrdered(), convertOperationImpl(), and inlineConvertOmpRegions().
|
inline |
Stores the mapping between an MLIR block and LLVM IR basic block.
Definition at line 92 of file ModuleTranslation.h.
Referenced by convertDataOp(), convertOmpAtomicCapture(), convertOmpAtomicUpdate(), convertOmpOpRegions(), and inlineConvertOmpRegions().
|
inline |
Stores the mapping between an MLIR operation with successors and a corresponding LLVM IR instruction.
Definition at line 105 of file ModuleTranslation.h.
Referenced by convertOperationImpl().
|
inline |
Stores the mapping between a function name and its LLVM IR representation.
Definition at line 59 of file ModuleTranslation.h.
|
inline |
Definition at line 138 of file ModuleTranslation.h.
References options.
Referenced by setLoopMetadata().
|
inline |
Stores the mapping between an MLIR value and its LLVM IR counterpart.
Definition at line 72 of file ModuleTranslation.h.
References mapValue().
Referenced by convertBlock(), convertCallLLVMIntrinsicOp(), convertOmpAtomicCapture(), convertOmpAtomicUpdate(), convertOmpReductionOp(), convertOmpSimdLoop(), convertOmpThreadprivate(), convertOmpWsLoop(), convertOperationImpl(), makeAtomicReductionGen(), makeReductionGen(), and mapValue().
|
inline |
Provides write-once access to store the LLVM IR value corresponding to the given MLIR value.
Definition at line 76 of file ModuleTranslation.h.
void ModuleTranslation::setAccessGroupsMetadata | ( | Operation * | op, |
llvm::Instruction * | inst | ||
) |
Definition at line 1021 of file ModuleTranslation.cpp.
References getAccessGroup(), and mlir::Operation::getAttrOfType().
void ModuleTranslation::setAliasScopeMetadata | ( | Operation * | op, |
llvm::Instruction * | inst | ||
) |
Definition at line 1091 of file ModuleTranslation.cpp.
References getAliasScope(), and mlir::Operation::getAttrOfType().
void ModuleTranslation::setTBAAMetadata | ( | Operation * | op, |
llvm::Instruction * | inst | ||
) |
Sets LLVM TBAA metadata for memory operations that have TBAA attributes.
Definition at line 1120 of file ModuleTranslation.cpp.
References mlir::Operation::emitWarning(), and mlir::Operation::getAttrOfType().
|
inline |
Pops the last element from the ModuleTranslation stack.
Definition at line 241 of file ModuleTranslation.h.
Referenced by mlir::LLVM::ModuleTranslation::SaveStack< T >::~SaveStack().
|
inline |
Creates a stack frame of type T
on ModuleTranslation stack.
T
must be derived from StackFrameBase<T>
and constructible from the provided arguments. Doing this before entering the region of the op being translated makes the frame available when translating ops within that region.
Definition at line 233 of file ModuleTranslation.h.
Referenced by mlir::LLVM::ModuleTranslation::SaveStack< T >::SaveStack().
|
inline |
Calls callback
for every ModuleTranslation stack frame of type T
starting from the top of the stack.
Definition at line 247 of file ModuleTranslation.h.
References mlir::WalkResult::advance(), mlir::WalkResult::skip(), and mlir::WalkResult::wasInterrupted().
Referenced by convertOmpReductionOp(), and findAllocaInsertPoint().
|
inline |
Definition at line 276 of file ModuleTranslation.h.
Referenced by convertOmpThreadprivate(), and convertOperationImpl().
llvm::Metadata * ModuleTranslation::translateDebugInfo | ( | LLVM::DINodeAttr | attr | ) |
Translates the given LLVM debug info metadata.
Definition at line 1249 of file ModuleTranslation.cpp.
const llvm::DILocation * ModuleTranslation::translateLoc | ( | Location | loc, |
llvm::DILocalScope * | scope | ||
) |
Translates the given location.
Definition at line 1245 of file ModuleTranslation.cpp.
|
friend |