#include "mlir/Target/LLVMIR/ModuleTranslation.h"
#include "AttrKindDetail.h"
#include "DebugTranslation.h"
#include "LoopAnnotationTranslation.h"
#include "mlir/Analysis/TopologicalSortUtils.h"
#include "mlir/Dialect/DLTI/DLTI.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/LLVMIR/LLVMInterfaces.h"
#include "mlir/Dialect/LLVMIR/Transforms/DIExpressionLegalization.h"
#include "mlir/Dialect/LLVMIR/Transforms/LegalizeForExport.h"
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
#include "mlir/Dialect/OpenMP/OpenMPInterfaces.h"
#include "mlir/IR/AttrTypeSubElements.h"
#include "mlir/IR/Attributes.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/DialectResourceBlobManager.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/PostOrderIterator.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/TypeSwitch.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/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"
#include <optional>
#define DEBUG_TYPE …
usingnamespacemlir;
usingnamespacemlir::LLVM;
usingnamespacemlir::LLVM::detail;
extern llvm::cl::opt<bool> UseNewDbgInfoFormat;
#include "mlir/Dialect/LLVMIR/LLVMConversionEnumsToLLVM.inc"
namespace {
class InstructionCapturingInserter : public llvm::IRBuilderCallbackInserter { … };
CapturingIRBuilder;
}
InstructionCapturingInserter::CollectionScope::CollectionScope(
llvm::IRBuilderBase &irBuilder, bool isBuilderCapturing) { … }
InstructionCapturingInserter::CollectionScope::~CollectionScope() { … }
static FailureOr<llvm::DataLayout>
translateDataLayout(DataLayoutSpecInterface attribute,
const DataLayout &dataLayout,
std::optional<Location> loc = std::nullopt) { … }
static llvm::Constant *
buildSequentialConstant(ArrayRef<llvm::Constant *> &constants,
ArrayRef<int64_t> shape, llvm::Type *type,
Location loc) { … }
static llvm::Type *getInnermostElementType(llvm::Type *type) { … }
static llvm::Constant *
convertDenseElementsAttr(Location loc, DenseElementsAttr denseElementsAttr,
llvm::Type *llvmType,
const ModuleTranslation &moduleTranslation) { … }
static llvm::Constant *convertDenseResourceElementsAttr(
Location loc, DenseResourceElementsAttr denseResourceAttr,
llvm::Type *llvmType, const ModuleTranslation &moduleTranslation) { … }
llvm::Constant *mlir::LLVM::detail::getLLVMConstant(
llvm::Type *llvmType, Attribute attr, Location loc,
const ModuleTranslation &moduleTranslation) { … }
ModuleTranslation::ModuleTranslation(Operation *module,
std::unique_ptr<llvm::Module> llvmModule)
: … { … }
ModuleTranslation::~ModuleTranslation() { … }
void ModuleTranslation::forgetMapping(Region ®ion) { … }
static Value getPHISourceValue(Block *current, Block *pred,
unsigned numArguments, unsigned index) { … }
void mlir::LLVM::detail::connectPHINodes(Region ®ion,
const ModuleTranslation &state) { … }
llvm::CallInst *mlir::LLVM::detail::createIntrinsicCall(
llvm::IRBuilderBase &builder, llvm::Intrinsic::ID intrinsic,
ArrayRef<llvm::Value *> args, ArrayRef<llvm::Type *> tys) { … }
llvm::CallInst *mlir::LLVM::detail::createIntrinsicCall(
llvm::IRBuilderBase &builder, ModuleTranslation &moduleTranslation,
Operation *intrOp, llvm::Intrinsic::ID intrinsic, unsigned numResults,
ArrayRef<unsigned> overloadedResults, ArrayRef<unsigned> overloadedOperands,
ArrayRef<unsigned> immArgPositions,
ArrayRef<StringLiteral> immArgAttrNames) { … }
LogicalResult ModuleTranslation::convertOperation(Operation &op,
llvm::IRBuilderBase &builder,
bool recordInsertions) { … }
LogicalResult ModuleTranslation::convertBlockImpl(Block &bb,
bool ignoreArguments,
llvm::IRBuilderBase &builder,
bool recordInsertions) { … }
static Block &getModuleBody(Operation *module) { … }
static bool shouldDropGlobalInitializer(llvm::GlobalValue::LinkageTypes linkage,
llvm::Constant *cst) { … }
static void addRuntimePreemptionSpecifier(bool dsoLocalRequested,
llvm::GlobalValue *gv) { … }
LogicalResult ModuleTranslation::convertGlobals() { … }
static LogicalResult checkedAddLLVMFnAttribute(Location loc,
llvm::Function *llvmFunc,
StringRef key,
StringRef value = StringRef()) { … }
static llvm::Metadata *convertIntegerToMetadata(llvm::LLVMContext &context,
const llvm::APInt &value) { … }
static llvm::MDNode *convertIntegerToMDNode(llvm::LLVMContext &context,
const llvm::APInt &value) { … }
static llvm::MDNode *convertVecTypeHintToMDNode(llvm::LLVMContext &context,
llvm::Type *type,
bool isSigned) { … }
static llvm::MDNode *convertIntegerArrayToMDNode(llvm::LLVMContext &context,
ArrayRef<int32_t> values) { … }
static LogicalResult
forwardPassthroughAttributes(Location loc, std::optional<ArrayAttr> attributes,
llvm::Function *llvmFunc) { … }
LogicalResult ModuleTranslation::convertOneFunction(LLVMFuncOp func) { … }
LogicalResult ModuleTranslation::convertDialectAttributes(
Operation *op, ArrayRef<llvm::Instruction *> instructions) { … }
static void convertFunctionMemoryAttributes(LLVMFuncOp func,
llvm::Function *llvmFunc) { … }
static void convertFunctionAttributes(LLVMFuncOp func,
llvm::Function *llvmFunc) { … }
static void convertFunctionKernelAttributes(LLVMFuncOp func,
llvm::Function *llvmFunc,
ModuleTranslation &translation) { … }
FailureOr<llvm::AttrBuilder>
ModuleTranslation::convertParameterAttrs(LLVMFuncOp func, int argIdx,
DictionaryAttr paramAttrs) { … }
LogicalResult ModuleTranslation::convertFunctionSignatures() { … }
LogicalResult ModuleTranslation::convertFunctions() { … }
LogicalResult ModuleTranslation::convertComdats() { … }
void ModuleTranslation::setAccessGroupsMetadata(AccessGroupOpInterface op,
llvm::Instruction *inst) { … }
llvm::MDNode *
ModuleTranslation::getOrCreateAliasScope(AliasScopeAttr aliasScopeAttr) { … }
llvm::MDNode *ModuleTranslation::getOrCreateAliasScopes(
ArrayRef<AliasScopeAttr> aliasScopeAttrs) { … }
void ModuleTranslation::setAliasScopeMetadata(AliasAnalysisOpInterface op,
llvm::Instruction *inst) { … }
llvm::MDNode *ModuleTranslation::getTBAANode(TBAATagAttr tbaaAttr) const { … }
void ModuleTranslation::setTBAAMetadata(AliasAnalysisOpInterface op,
llvm::Instruction *inst) { … }
void ModuleTranslation::setBranchWeightsMetadata(BranchWeightOpInterface op) { … }
LogicalResult ModuleTranslation::createTBAAMetadata() { … }
LogicalResult ModuleTranslation::createIdentMetadata() { … }
void ModuleTranslation::setLoopMetadata(Operation *op,
llvm::Instruction *inst) { … }
llvm::Type *ModuleTranslation::convertType(Type type) { … }
SmallVector<llvm::Value *> ModuleTranslation::lookupValues(ValueRange values) { … }
llvm::OpenMPIRBuilder *ModuleTranslation::getOpenMPBuilder() { … }
llvm::DILocation *ModuleTranslation::translateLoc(Location loc,
llvm::DILocalScope *scope) { … }
llvm::DIExpression *
ModuleTranslation::translateExpression(LLVM::DIExpressionAttr attr) { … }
llvm::DIGlobalVariableExpression *
ModuleTranslation::translateGlobalVariableExpression(
LLVM::DIGlobalVariableExpressionAttr attr) { … }
llvm::Metadata *ModuleTranslation::translateDebugInfo(LLVM::DINodeAttr attr) { … }
llvm::RoundingMode
ModuleTranslation::translateRoundingMode(LLVM::RoundingMode rounding) { … }
llvm::fp::ExceptionBehavior ModuleTranslation::translateFPExceptionBehavior(
LLVM::FPExceptionBehavior exceptionBehavior) { … }
llvm::NamedMDNode *
ModuleTranslation::getOrInsertNamedModuleMetadata(StringRef name) { … }
void ModuleTranslation::StackFrame::anchor() { … }
static std::unique_ptr<llvm::Module>
prepareLLVMModule(Operation *m, llvm::LLVMContext &llvmContext,
StringRef name) { … }
std::unique_ptr<llvm::Module>
mlir::translateModuleToLLVMIR(Operation *module, llvm::LLVMContext &llvmContext,
StringRef name, bool disableVerification) { … }