Skip to content

Commit 3f0ef27

Browse files
[MLIR][LLVM] Debug info: import debug records directly (#167812)
Effectively means we don't need to call into `llvmModule->convertFromNewDbgValues()` anymore. Added a flag to allow users to access the old behavior.
1 parent 8e4209a commit 3f0ef27

File tree

4 files changed

+308
-65
lines changed

4 files changed

+308
-65
lines changed

mlir/include/mlir/Target/LLVMIR/ModuleImport.h

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,10 @@ class ModuleImport {
163163
/// Converts `value` to a float attribute. Asserts if the matching fails.
164164
FloatAttr matchFloatAttr(llvm::Value *value);
165165

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

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

285+
/// Similar to `addDebugIntrinsic`, but for debug records.
286+
void addDebugRecord(llvm::DbgRecord *debugRecord);
287+
284288
/// Converts the LLVM values for an intrinsic to mixed MLIR values and
285289
/// attributes for LLVM_IntrOpBase. Attributes correspond to LLVM immargs. The
286290
/// list `immArgPositions` contains the positions of immargs on the LLVM
@@ -339,9 +343,26 @@ class ModuleImport {
339343
/// Converts all debug intrinsics in `debugIntrinsics`. Assumes that the
340344
/// function containing the intrinsics has been fully converted to MLIR.
341345
LogicalResult processDebugIntrinsics();
346+
/// Converts all debug records in `debugRecords`. Assumes that the
347+
/// function containing the record has been fully converted to MLIR.
348+
LogicalResult processDebugRecords();
342349
/// Converts a single debug intrinsic.
343350
LogicalResult processDebugIntrinsic(llvm::DbgVariableIntrinsic *dbgIntr,
344351
DominanceInfo &domInfo);
352+
/// Converts a single debug record.
353+
LogicalResult processDebugRecord(llvm::DbgRecord &debugRecord,
354+
DominanceInfo &domInfo);
355+
/// Process arguments for declare/value operation insertion. `localVarAttr`
356+
/// and `localExprAttr` are the attained attributes after importing the debug
357+
/// variable and expressions. This also sets the builder insertion point to be
358+
/// used by these operations.
359+
std::tuple<DILocalVariableAttr, DIExpressionAttr, Value>
360+
processDebugOpArgumentsAndInsertionPt(
361+
Location loc, bool hasArgList, bool isKillLocation,
362+
llvm::function_ref<FailureOr<Value>()> convertArgOperandToValue,
363+
llvm::Value *address,
364+
llvm::PointerUnion<llvm::Value *, llvm::DILocalVariable *> variable,
365+
llvm::DIExpression *expression, DominanceInfo &domInfo);
345366
/// Converts LLMV IR asm inline call operand's attributes into an array of
346367
/// MLIR attributes to be utilized in `llvm.inline_asm`.
347368
ArrayAttr convertAsmInlineOperandAttrs(const llvm::CallBase &llvmCall);
@@ -485,6 +506,9 @@ class ModuleImport {
485506
/// Function-local list of debug intrinsics that need to be imported after the
486507
/// function conversion has finished.
487508
SetVector<llvm::Instruction *> debugIntrinsics;
509+
/// Function-local list of debug records that need to be imported after the
510+
/// function conversion has finished.
511+
SetVector<llvm::DbgRecord *> debugRecords;
488512
/// Mapping between LLVM alias scope and domain metadata nodes and
489513
/// attributes in the LLVM dialect corresponding to these nodes.
490514
DenseMap<const llvm::MDNode *, Attribute> aliasScopeMapping;

mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ void registerFromLLVMIRTranslation() {
3030
llvm::cl::desc("Emit expensive warnings during LLVM IR import "
3131
"(discouraged: testing only!)"),
3232
llvm::cl::init(false));
33+
static llvm::cl::opt<bool> convertDebugRecToIntrinsics(
34+
"convert-debug-rec-to-intrinsics",
35+
llvm::cl::desc("Change the input LLVM module to use old debug intrinsics "
36+
"instead of records "
37+
"via convertFromNewDbgValues, this happens "
38+
"before importing the debug information"
39+
"(discouraged: to be removed soon!)"),
40+
llvm::cl::init(false));
3341
static llvm::cl::opt<bool> dropDICompositeTypeElements(
3442
"drop-di-composite-type-elements",
3543
llvm::cl::desc(
@@ -69,8 +77,10 @@ void registerFromLLVMIRTranslation() {
6977
if (llvm::verifyModule(*llvmModule, &llvm::errs()))
7078
return nullptr;
7179

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

7585
return translateLLVMIRToModule(
7686
std::move(llvmModule), context, emitExpensiveWarnings,

0 commit comments

Comments
 (0)