Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions mlir/include/mlir/Target/LLVMIR/ModuleImport.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ class ModuleImport {
/// Converts `value` to a float attribute. Asserts if the matching fails.
FloatAttr matchFloatAttr(llvm::Value *value);

/// Converts `value` to a local variable attribute. Asserts if the matching
/// fails.
DILocalVariableAttr matchLocalVariableAttr(llvm::Value *value);
/// Converts `valOrVariable` to a local variable attribute. Asserts if the
/// matching fails.
DILocalVariableAttr matchLocalVariableAttr(
llvm::PointerUnion<llvm::Value *, llvm::DILocalVariable *> valOrVariable);

/// Converts `value` to a label attribute. Asserts if the matching fails.
DILabelAttr matchLabelAttr(llvm::Value *value);
Expand Down Expand Up @@ -281,6 +282,9 @@ class ModuleImport {
/// after the function conversion has finished.
void addDebugIntrinsic(llvm::CallInst *intrinsic);

/// Similar to `addDebugIntrinsic`, but for debug records.
void addDebugRecord(llvm::DbgRecord *debugRecord);

/// Converts the LLVM values for an intrinsic to mixed MLIR values and
/// attributes for LLVM_IntrOpBase. Attributes correspond to LLVM immargs. The
/// list `immArgPositions` contains the positions of immargs on the LLVM
Expand Down Expand Up @@ -339,9 +343,26 @@ class ModuleImport {
/// Converts all debug intrinsics in `debugIntrinsics`. Assumes that the
/// function containing the intrinsics has been fully converted to MLIR.
LogicalResult processDebugIntrinsics();
/// Converts all debug records in `debugRecords`. Assumes that the
/// function containing the record has been fully converted to MLIR.
LogicalResult processDebugRecords();
/// Converts a single debug intrinsic.
LogicalResult processDebugIntrinsic(llvm::DbgVariableIntrinsic *dbgIntr,
DominanceInfo &domInfo);
/// Converts a single debug record.
LogicalResult processDebugRecord(llvm::DbgRecord &debugRecord,
DominanceInfo &domInfo);
/// Process arguments for declare/value operation insertion. `localVarAttr`
/// and `localExprAttr` are the attained attributes after importing the debug
/// variable and expressions. This also sets the builder insertion point to be
/// used by these operations.
std::tuple<DILocalVariableAttr, DIExpressionAttr, Value>
processDebugOpArgumentsAndInsertionPt(
Location loc, bool hasArgList, bool isKillLocation,
llvm::function_ref<FailureOr<Value>()> convertArgOperandToValue,
llvm::Value *address,
llvm::PointerUnion<llvm::Value *, llvm::DILocalVariable *> variable,
llvm::DIExpression *expression, DominanceInfo &domInfo);
/// Converts LLMV IR asm inline call operand's attributes into an array of
/// MLIR attributes to be utilized in `llvm.inline_asm`.
ArrayAttr convertAsmInlineOperandAttrs(const llvm::CallBase &llvmCall);
Expand Down Expand Up @@ -485,6 +506,9 @@ class ModuleImport {
/// Function-local list of debug intrinsics that need to be imported after the
/// function conversion has finished.
SetVector<llvm::Instruction *> debugIntrinsics;
/// Function-local list of debug records that need to be imported after the
/// function conversion has finished.
SetVector<llvm::DbgRecord *> debugRecords;
/// Mapping between LLVM alias scope and domain metadata nodes and
/// attributes in the LLVM dialect corresponding to these nodes.
DenseMap<const llvm::MDNode *, Attribute> aliasScopeMapping;
Expand Down
14 changes: 12 additions & 2 deletions mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ void registerFromLLVMIRTranslation() {
llvm::cl::desc("Emit expensive warnings during LLVM IR import "
"(discouraged: testing only!)"),
llvm::cl::init(false));
static llvm::cl::opt<bool> convertDebugRecToIntrinsics(
"convert-debug-rec-to-intrinsics",
llvm::cl::desc("Change the input LLVM module to use old debug intrinsics "
"instead of records "
"via convertFromNewDbgValues, this happens "
"before importing the debug information"
"(discouraged: to be removed soon!)"),
llvm::cl::init(false));
static llvm::cl::opt<bool> dropDICompositeTypeElements(
"drop-di-composite-type-elements",
llvm::cl::desc(
Expand Down Expand Up @@ -69,8 +77,10 @@ void registerFromLLVMIRTranslation() {
if (llvm::verifyModule(*llvmModule, &llvm::errs()))
return nullptr;

// Debug records are not currently supported in the LLVM IR translator.
llvmModule->convertFromNewDbgValues();
// Now that the translation supports importing debug records directly,
// make it the default, but allow the user to override to old behavior.
if (!convertDebugRecToIntrinsics)
llvmModule->convertFromNewDbgValues();

return translateLLVMIRToModule(
std::move(llvmModule), context, emitExpensiveWarnings,
Expand Down
Loading
Loading