MLIR  19.0.0git
Classes | Public Member Functions | Friends | List of all members
mlir::LLVM::ModuleTranslation Class Reference

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 mapCall (Operation *mlir, llvm::CallInst *llvm)
 Stores a mapping between an MLIR call operation and a corresponding LLVM call instruction. More...
 
llvm::CallInst * lookupCall (Operation *op) const
 Finds an LLVM call instruction that corresponds to the given MLIR call operation. More...
 
void forgetMapping (Region &region)
 Removes the mapping for blocks contained in the region and values defined in these blocks. More...
 
llvm::MDNode * getOrCreateAliasScope (AliasScopeAttr aliasScopeAttr)
 Returns the LLVM metadata corresponding to a mlir LLVM dialect alias scope attribute. More...
 
llvm::MDNode * getOrCreateAliasScopes (ArrayRef< AliasScopeAttr > aliasScopeAttrs)
 Returns the LLVM metadata corresponding to an array of mlir LLVM dialect alias scope attributes. More...
 
void setAccessGroupsMetadata (AccessGroupOpInterface op, llvm::Instruction *inst)
 
void setAliasScopeMetadata (AliasAnalysisOpInterface op, llvm::Instruction *inst)
 
void setTBAAMetadata (AliasAnalysisOpInterface op, llvm::Instruction *inst)
 Sets LLVM TBAA metadata for memory operations that have TBAA attributes. More...
 
void setBranchWeightsMetadata (BranchWeightOpInterface op)
 Sets LLVM profiling metadata for operations that have branch weights. More...
 
void setLoopMetadata (Operation *op, llvm::Instruction *inst)
 Sets LLVM loop metadata for branch operations that have a loop annotation attribute. More...
 
llvm::Type * convertType (Type type)
 Converts the type from MLIR LLVM dialect to LLVM. More...
 
MLIRContextgetContext ()
 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...
 
llvm::Module * getLLVMModule ()
 Returns the LLVM module in which the IR is being constructed. More...
 
llvm::DILocation * translateLoc (Location loc, llvm::DILocalScope *scope)
 Translates the given location. More...
 
llvm::DIExpression * translateExpression (LLVM::DIExpressionAttr attr)
 Translates the given LLVM DWARF expression metadata. More...
 
llvm::DIGlobalVariableExpression * translateGlobalVariableExpression (LLVM::DIGlobalVariableExpressionAttr attr)
 Translates the given LLVM global variable expression metadata. More...
 
llvm::Metadata * translateDebugInfo (LLVM::DINodeAttr attr)
 Translates the given LLVM debug info metadata. More...
 
llvm::RoundingMode translateRoundingMode (LLVM::RoundingMode rounding)
 Translates the given LLVM rounding mode metadata. More...
 
llvm::fp::ExceptionBehavior translateFPExceptionBehavior (LLVM::FPExceptionBehavior exceptionBehavior)
 Translates the given LLVM FP exception behavior 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...
 
SymbolTableCollectionsymbolTable ()
 

Friends

std::unique_ptr< llvm::Module > mlir::translateModuleToLLVMIR (Operation *, llvm::LLVMContext &, StringRef)
 

Detailed Description

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 58 of file ModuleTranslation.h.

Member Function Documentation

◆ convertBlock()

LogicalResult mlir::LLVM::ModuleTranslation::convertBlock ( Block bb,
bool  ignoreArguments,
llvm::IRBuilderBase &  builder 
)
inline

Translates the contents of the given block to LLVM IR using this translator.

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.

Definition at line 218 of file ModuleTranslation.h.

Referenced by convertOmpAtomicCapture(), convertOmpAtomicUpdate(), convertOmpOpRegions(), and inlineConvertOmpRegions().

◆ convertType()

llvm::Type * ModuleTranslation::convertType ( Type  type)

◆ forgetMapping()

void ModuleTranslation::forgetMapping ( Region region)

Removes the mapping for blocks contained in the region and values defined in these blocks.

Definition at line 702 of file ModuleTranslation.cpp.

Referenced by convertOmpOpRegions(), convertOmpParallel(), convertOmpWsloop(), inlineConvertOmpRegions(), and inlineOmpRegionCleanup().

◆ getContext()

MLIRContext& mlir::LLVM::ModuleTranslation::getContext ( )
inline

Returns the MLIR context of the module being translated.

Definition at line 173 of file ModuleTranslation.h.

References mlir::Operation::getContext().

Referenced by convertOmpParallel(), convertOperationImpl(), and createVL().

◆ getLLVMContext()

llvm::LLVMContext& mlir::LLVM::ModuleTranslation::getLLVMContext ( ) const
inline

Returns the LLVM context in which the IR is being constructed.

Definition at line 176 of file ModuleTranslation.h.

Referenced by convertOmpCritical(), convertOperationImpl(), mlir::LLVM::detail::getLLVMConstant(), getOrCreateAliasScopes(), and getXlenType().

◆ getLLVMModule()

llvm::Module* mlir::LLVM::ModuleTranslation::getLLVMModule ( )
inline

Returns the LLVM module in which the IR is being constructed.

Definition at line 189 of file ModuleTranslation.h.

Referenced by convertLinkerOptionsOp(), and getRefPtrIfDeclareTarget().

◆ getOpenMPBuilder()

llvm::OpenMPIRBuilder * ModuleTranslation::getOpenMPBuilder ( )

◆ getOrCreateAliasScope()

llvm::MDNode * ModuleTranslation::getOrCreateAliasScope ( AliasScopeAttr  aliasScopeAttr)

Returns the LLVM metadata corresponding to a mlir LLVM dialect alias scope attribute.

Creates the metadata node if it has not been converted before.

Definition at line 1521 of file ModuleTranslation.cpp.

References mlir::get().

Referenced by getOrCreateAliasScopes().

◆ getOrCreateAliasScopes()

llvm::MDNode * ModuleTranslation::getOrCreateAliasScopes ( ArrayRef< AliasScopeAttr >  aliasScopeAttrs)

Returns the LLVM metadata corresponding to an array of mlir LLVM dialect alias scope attributes.

Creates the metadata nodes if they have not been converted before.

Definition at line 1555 of file ModuleTranslation.cpp.

References mlir::get(), getLLVMContext(), and getOrCreateAliasScope().

◆ getOrInsertNamedModuleMetadata()

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 1746 of file ModuleTranslation.cpp.

◆ lookupBlock()

llvm::BasicBlock* mlir::LLVM::ModuleTranslation::lookupBlock ( Block block) const
inline

Finds an LLVM IR basic block that corresponds to the given MLIR block.

Definition at line 104 of file ModuleTranslation.h.

Referenced by convertOmpOpRegions(), and convertOperationImpl().

◆ lookupBranch()

llvm::Instruction* mlir::LLVM::ModuleTranslation::lookupBranch ( Operation op) const
inline

Finds an LLVM IR instruction that corresponds to the given MLIR operation with successors.

Definition at line 119 of file ModuleTranslation.h.

◆ lookupCall()

llvm::CallInst* mlir::LLVM::ModuleTranslation::lookupCall ( Operation op) const
inline

Finds an LLVM call instruction that corresponds to the given MLIR call operation.

Definition at line 133 of file ModuleTranslation.h.

◆ lookupFunction()

llvm::Function* mlir::LLVM::ModuleTranslation::lookupFunction ( StringRef  name) const
inline

Finds an LLVM IR function by its name.

Definition at line 72 of file ModuleTranslation.h.

Referenced by convertOmpSingle(), convertOmpTarget(), convertOperationImpl(), and mlir::LLVM::detail::getLLVMConstant().

◆ lookupGlobal()

llvm::GlobalValue* mlir::LLVM::ModuleTranslation::lookupGlobal ( Operation op)
inline

Finds an LLVM IR global value that corresponds to the given MLIR operation defining a global value.

Definition at line 180 of file ModuleTranslation.h.

Referenced by convertOmpThreadprivate(), and convertOperationImpl().

◆ lookupValue()

llvm::Value* mlir::LLVM::ModuleTranslation::lookupValue ( Value  value) const
inline

◆ lookupValues()

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 1688 of file ModuleTranslation.cpp.

References lookupValue().

Referenced by convertOmpOrdered(), convertOperationImpl(), mlir::LLVM::detail::createIntrinsicCall(), and inlineConvertOmpRegions().

◆ mapBlock()

void mlir::LLVM::ModuleTranslation::mapBlock ( Block mlir,
llvm::BasicBlock *  llvm 
)
inline

Stores the mapping between an MLIR block and LLVM IR basic block.

Definition at line 97 of file ModuleTranslation.h.

Referenced by convertOmpAtomicCapture(), convertOmpAtomicUpdate(), convertOmpOpRegions(), and inlineConvertOmpRegions().

◆ mapBranch()

void mlir::LLVM::ModuleTranslation::mapBranch ( Operation mlir,
llvm::Instruction *  llvm 
)
inline

Stores the mapping between an MLIR operation with successors and a corresponding LLVM IR instruction.

Definition at line 110 of file ModuleTranslation.h.

Referenced by convertOperationImpl().

◆ mapCall()

void mlir::LLVM::ModuleTranslation::mapCall ( Operation mlir,
llvm::CallInst *  llvm 
)
inline

Stores a mapping between an MLIR call operation and a corresponding LLVM call instruction.

Definition at line 125 of file ModuleTranslation.h.

Referenced by convertOperationImpl().

◆ mapFunction()

void mlir::LLVM::ModuleTranslation::mapFunction ( StringRef  name,
llvm::Function *  func 
)
inline

Stores the mapping between a function name and its LLVM IR representation.

Definition at line 64 of file ModuleTranslation.h.

◆ mapValue() [1/2]

void mlir::LLVM::ModuleTranslation::mapValue ( Value  mlir,
llvm::Value *  llvm 
)
inline

◆ mapValue() [2/2]

llvm::Value*& mlir::LLVM::ModuleTranslation::mapValue ( Value  value)
inline

Provides write-once access to store the LLVM IR value corresponding to the given MLIR value.

Definition at line 81 of file ModuleTranslation.h.

◆ setAccessGroupsMetadata()

void ModuleTranslation::setAccessGroupsMetadata ( AccessGroupOpInterface  op,
llvm::Instruction *  inst 
)

Definition at line 1514 of file ModuleTranslation.cpp.

Referenced by convertOperationImpl().

◆ setAliasScopeMetadata()

void ModuleTranslation::setAliasScopeMetadata ( AliasAnalysisOpInterface  op,
llvm::Instruction *  inst 
)

Definition at line 1564 of file ModuleTranslation.cpp.

Referenced by convertOperationImpl().

◆ setBranchWeightsMetadata()

void ModuleTranslation::setBranchWeightsMetadata ( BranchWeightOpInterface  op)

Sets LLVM profiling metadata for operations that have branch weights.

Definition at line 1604 of file ModuleTranslation.cpp.

◆ setLoopMetadata()

void ModuleTranslation::setLoopMetadata ( Operation op,
llvm::Instruction *  inst 
)

Sets LLVM loop metadata for branch operations that have a loop annotation attribute.

Definition at line 1670 of file ModuleTranslation.cpp.

Referenced by convertOperationImpl().

◆ setTBAAMetadata()

void ModuleTranslation::setTBAAMetadata ( AliasAnalysisOpInterface  op,
llvm::Instruction *  inst 
)

Sets LLVM TBAA metadata for memory operations that have TBAA attributes.

Definition at line 1584 of file ModuleTranslation.cpp.

Referenced by convertOperationImpl().

◆ stackPop()

void mlir::LLVM::ModuleTranslation::stackPop ( )
inline

Pops the last element from the ModuleTranslation stack.

Definition at line 269 of file ModuleTranslation.h.

Referenced by mlir::LLVM::ModuleTranslation::SaveStack< T >::~SaveStack().

◆ stackPush()

template<typename T , typename... Args>
void mlir::LLVM::ModuleTranslation::stackPush ( Args &&...  args)
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 261 of file ModuleTranslation.h.

Referenced by mlir::LLVM::ModuleTranslation::SaveStack< T >::SaveStack().

◆ stackWalk()

template<typename T >
WalkResult mlir::LLVM::ModuleTranslation::stackWalk ( llvm::function_ref< WalkResult(const T &)>  callback) const
inline

Calls callback for every ModuleTranslation stack frame of type T starting from the top of the stack.

Definition at line 275 of file ModuleTranslation.h.

References mlir::WalkResult::advance(), mlir::WalkResult::skip(), and mlir::WalkResult::wasInterrupted().

Referenced by findAllocaInsertPoint().

◆ symbolTable()

SymbolTableCollection& mlir::LLVM::ModuleTranslation::symbolTable ( )
inline

Definition at line 304 of file ModuleTranslation.h.

Referenced by convertOmpThreadprivate(), and convertOperationImpl().

◆ translateDebugInfo()

llvm::Metadata * ModuleTranslation::translateDebugInfo ( LLVM::DINodeAttr  attr)

Translates the given LLVM debug info metadata.

Definition at line 1731 of file ModuleTranslation.cpp.

◆ translateExpression()

llvm::DIExpression * ModuleTranslation::translateExpression ( LLVM::DIExpressionAttr  attr)

Translates the given LLVM DWARF expression metadata.

Definition at line 1721 of file ModuleTranslation.cpp.

◆ translateFPExceptionBehavior()

llvm::fp::ExceptionBehavior ModuleTranslation::translateFPExceptionBehavior ( LLVM::FPExceptionBehavior  exceptionBehavior)

Translates the given LLVM FP exception behavior metadata.

Definition at line 1740 of file ModuleTranslation.cpp.

◆ translateGlobalVariableExpression()

llvm::DIGlobalVariableExpression * ModuleTranslation::translateGlobalVariableExpression ( LLVM::DIGlobalVariableExpressionAttr  attr)

Translates the given LLVM global variable expression metadata.

Definition at line 1726 of file ModuleTranslation.cpp.

◆ translateLoc()

llvm::DILocation * ModuleTranslation::translateLoc ( Location  loc,
llvm::DILocalScope *  scope 
)

Translates the given location.

Definition at line 1715 of file ModuleTranslation.cpp.

◆ translateRoundingMode()

llvm::RoundingMode ModuleTranslation::translateRoundingMode ( LLVM::RoundingMode  rounding)

Translates the given LLVM rounding mode metadata.

Definition at line 1736 of file ModuleTranslation.cpp.

Friends And Related Function Documentation

◆ mlir::translateModuleToLLVMIR

std::unique_ptr<llvm::Module> mlir::translateModuleToLLVMIR ( Operation ,
llvm::LLVMContext &  ,
StringRef   
)
friend

The documentation for this class was generated from the following files: