#include "mlir/Target/LLVMIR/ModuleImport.h"
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/Target/LLVMIR/Import.h"
#include "AttrKindDetail.h"
#include "DataLayoutImporter.h"
#include "DebugImporter.h"
#include "LoopAnnotationImporter.h"
#include "mlir/Dialect/DLTI/DLTI.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/Matchers.h"
#include "mlir/Interfaces/DataLayoutInterfaces.h"
#include "mlir/Tools/mlir-translate/Translation.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/IR/Comdat.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/InlineAsm.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Operator.h"
#include "llvm/Support/ModRef.h"
usingnamespacemlir;
usingnamespacemlir::LLVM;
usingnamespacemlir::LLVM::detail;
#include "mlir/Dialect/LLVMIR/LLVMConversionEnumsFromLLVM.inc"
static std::string diag(const llvm::Value &value) { … }
static std::string diagMD(const llvm::Metadata *node,
const llvm::Module *module) { … }
static constexpr StringRef getGlobalCtorsVarName() { … }
static constexpr StringRef getNamelessGlobalPrefix() { … }
static constexpr StringRef getGlobalDtorsVarName() { … }
static constexpr StringRef getGlobalComdatOpName() { … }
static StringRef getLLVMSyncScope(llvm::Instruction *inst) { … }
static SmallVector<int64_t> getPositionFromIndices(ArrayRef<unsigned> indices) { … }
static LogicalResult convertInstructionImpl(OpBuilder &odsBuilder,
llvm::Instruction *inst,
ModuleImport &moduleImport,
LLVMImportInterface &iface) { … }
static SetVector<llvm::BasicBlock *>
getTopologicallySortedBlocks(ArrayRef<llvm::BasicBlock *> basicBlocks) { … }
ModuleImport::ModuleImport(ModuleOp mlirModule,
std::unique_ptr<llvm::Module> llvmModule,
bool emitExpensiveWarnings,
bool importEmptyDICompositeTypes)
: … { … }
ComdatOp ModuleImport::getGlobalComdatOp() { … }
LogicalResult ModuleImport::processTBAAMetadata(const llvm::MDNode *node) { … }
LogicalResult
ModuleImport::processAccessGroupMetadata(const llvm::MDNode *node) { … }
LogicalResult
ModuleImport::processAliasScopeMetadata(const llvm::MDNode *node) { … }
FailureOr<SmallVector<AliasScopeAttr>>
ModuleImport::lookupAliasScopeAttrs(const llvm::MDNode *node) const { … }
void ModuleImport::addDebugIntrinsic(llvm::CallInst *intrinsic) { … }
LogicalResult ModuleImport::convertLinkerOptionsMetadata() { … }
LogicalResult ModuleImport::convertIdentMetadata() { … }
LogicalResult ModuleImport::convertMetadata() { … }
void ModuleImport::processComdat(const llvm::Comdat *comdat) { … }
LogicalResult ModuleImport::convertComdats() { … }
LogicalResult ModuleImport::convertGlobals() { … }
LogicalResult ModuleImport::convertDataLayout() { … }
LogicalResult ModuleImport::convertFunctions() { … }
void ModuleImport::setNonDebugMetadataAttrs(llvm::Instruction *inst,
Operation *op) { … }
void ModuleImport::setIntegerOverflowFlags(llvm::Instruction *inst,
Operation *op) const { … }
void ModuleImport::setFastmathFlagsAttr(llvm::Instruction *inst,
Operation *op) const { … }
static bool isScalarType(Type type) { … }
static Type getVectorTypeForAttr(Type type, ArrayRef<int64_t> arrayShape = { … }
Type ModuleImport::getBuiltinTypeForAttr(Type type) { … }
static TypedAttr getScalarConstantAsAttr(OpBuilder &builder,
llvm::Constant *constScalar) { … }
static SmallVector<Attribute>
getSequenceConstantAsAttrs(OpBuilder &builder,
llvm::ConstantDataSequential *constSequence) { … }
Attribute ModuleImport::getConstantAsAttr(llvm::Constant *constant) { … }
LogicalResult ModuleImport::convertGlobal(llvm::GlobalVariable *globalVar) { … }
LogicalResult
ModuleImport::convertGlobalCtorsAndDtors(llvm::GlobalVariable *globalVar) { … }
SetVector<llvm::Constant *>
ModuleImport::getConstantsToConvert(llvm::Constant *constant) { … }
FailureOr<Value> ModuleImport::convertConstant(llvm::Constant *constant) { … }
FailureOr<Value> ModuleImport::convertConstantExpr(llvm::Constant *constant) { … }
FailureOr<Value> ModuleImport::convertValue(llvm::Value *value) { … }
FailureOr<Value> ModuleImport::convertMetadataValue(llvm::Value *value) { … }
FailureOr<SmallVector<Value>>
ModuleImport::convertValues(ArrayRef<llvm::Value *> values) { … }
LogicalResult ModuleImport::convertIntrinsicArguments(
ArrayRef<llvm::Value *> values, ArrayRef<unsigned> immArgPositions,
ArrayRef<StringLiteral> immArgAttrNames, SmallVectorImpl<Value> &valuesOut,
SmallVectorImpl<NamedAttribute> &attrsOut) { … }
IntegerAttr ModuleImport::matchIntegerAttr(llvm::Value *value) { … }
FloatAttr ModuleImport::matchFloatAttr(llvm::Value *value) { … }
DILocalVariableAttr ModuleImport::matchLocalVariableAttr(llvm::Value *value) { … }
DILabelAttr ModuleImport::matchLabelAttr(llvm::Value *value) { … }
FPExceptionBehaviorAttr
ModuleImport::matchFPExceptionBehaviorAttr(llvm::Value *value) { … }
RoundingModeAttr ModuleImport::matchRoundingModeAttr(llvm::Value *value) { … }
FailureOr<SmallVector<AliasScopeAttr>>
ModuleImport::matchAliasScopeAttrs(llvm::Value *value) { … }
Location ModuleImport::translateLoc(llvm::DILocation *loc) { … }
LogicalResult
ModuleImport::convertBranchArgs(llvm::Instruction *branch,
llvm::BasicBlock *target,
SmallVectorImpl<Value> &blockArguments) { … }
LogicalResult
ModuleImport::convertCallTypeAndOperands(llvm::CallBase *callInst,
SmallVectorImpl<Type> &types,
SmallVectorImpl<Value> &operands) { … }
LogicalResult ModuleImport::convertIntrinsic(llvm::CallInst *inst) { … }
LogicalResult ModuleImport::convertInstruction(llvm::Instruction *inst) { … }
LogicalResult ModuleImport::processInstruction(llvm::Instruction *inst) { … }
FlatSymbolRefAttr ModuleImport::getPersonalityAsAttr(llvm::Function *f) { … }
static void processMemoryEffects(llvm::Function *func, LLVMFuncOp funcOp) { … }
static constexpr std::array kExplicitAttributes{ … };
static void processPassthroughAttrs(llvm::Function *func, LLVMFuncOp funcOp) { … }
void ModuleImport::processFunctionAttributes(llvm::Function *func,
LLVMFuncOp funcOp) { … }
DictionaryAttr
ModuleImport::convertParameterAttribute(llvm::AttributeSet llvmParamAttrs,
OpBuilder &builder) { … }
void ModuleImport::convertParameterAttributes(llvm::Function *func,
LLVMFuncOp funcOp,
OpBuilder &builder) { … }
LogicalResult ModuleImport::processFunction(llvm::Function *func) { … }
static bool isMetadataKillLocation(llvm::DbgVariableIntrinsic *dbgIntr) { … }
LogicalResult
ModuleImport::processDebugIntrinsic(llvm::DbgVariableIntrinsic *dbgIntr,
DominanceInfo &domInfo) { … }
LogicalResult ModuleImport::processDebugIntrinsics() { … }
LogicalResult ModuleImport::processBasicBlock(llvm::BasicBlock *bb,
Block *block) { … }
FailureOr<SmallVector<AccessGroupAttr>>
ModuleImport::lookupAccessGroupAttrs(const llvm::MDNode *node) const { … }
LoopAnnotationAttr
ModuleImport::translateLoopAnnotationAttr(const llvm::MDNode *node,
Location loc) const { … }
OwningOpRef<ModuleOp>
mlir::translateLLVMIRToModule(std::unique_ptr<llvm::Module> llvmModule,
MLIRContext *context, bool emitExpensiveWarnings,
bool dropDICompositeTypeElements) { … }