Index: include/llvm/CodeGen/MIRYamlMapping.h =================================================================== --- include/llvm/CodeGen/MIRYamlMapping.h +++ include/llvm/CodeGen/MIRYamlMapping.h @@ -283,6 +283,9 @@ bool IsAliased = false; StringValue CalleeSavedRegister; bool CalleeSavedRestored = true; + StringValue DebugVar; + StringValue DebugExpr; + StringValue DebugLoc; bool operator==(const FixedMachineStackObject &Other) const { return ID == Other.ID && Type == Other.Type && Offset == Other.Offset && @@ -290,7 +293,9 @@ StackID == Other.StackID && IsImmutable == Other.IsImmutable && IsAliased == Other.IsAliased && CalleeSavedRegister == Other.CalleeSavedRegister && - CalleeSavedRestored == Other.CalleeSavedRestored; + CalleeSavedRestored == Other.CalleeSavedRestored && + DebugVar == Other.DebugVar && DebugExpr == Other.DebugExpr + && DebugLoc == Other.DebugLoc; } }; @@ -321,6 +326,12 @@ StringValue()); // Don't print it out when it's empty. YamlIO.mapOptional("callee-saved-restored", Object.CalleeSavedRestored, true); + YamlIO.mapOptional("di-variable", Object.DebugVar, + StringValue()); // Don't print it out when it's empty. + YamlIO.mapOptional("di-expression", Object.DebugExpr, + StringValue()); // Don't print it out when it's empty. + YamlIO.mapOptional("di-location", Object.DebugLoc, + StringValue()); // Don't print it out when it's empty. } static const bool flow = true; Index: include/llvm/CodeGen/MachineFunction.h =================================================================== --- include/llvm/CodeGen/MachineFunction.h +++ include/llvm/CodeGen/MachineFunction.h @@ -349,11 +349,11 @@ struct VariableDbgInfo { const DILocalVariable *Var; const DIExpression *Expr; - unsigned Slot; + int Slot; const DILocation *Loc; VariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr, - unsigned Slot, const DILocation *Loc) + int Slot, const DILocation *Loc) : Var(Var), Expr(Expr), Slot(Slot), Loc(Loc) {} }; using VariableDbgInfoMapTy = SmallVector; @@ -860,7 +860,7 @@ /// Collect information used to emit debugging information of a variable. void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr, - unsigned Slot, const DILocation *Loc) { + int Slot, const DILocation *Loc) { VariableDbgInfos.emplace_back(Var, Expr, Slot, Loc); } Index: lib/CodeGen/MIRParser/MIRParser.cpp =================================================================== --- lib/CodeGen/MIRParser/MIRParser.cpp +++ lib/CodeGen/MIRParser/MIRParser.cpp @@ -122,8 +122,9 @@ const yaml::StringValue &RegisterSource, bool IsRestored, int FrameIdx); + template bool parseStackObjectsDebugInfo(PerFunctionMIParsingState &PFS, - const yaml::MachineStackObject &Object, + const T &Object, int FrameIdx); bool initializeConstantPool(PerFunctionMIParsingState &PFS, @@ -616,6 +617,8 @@ if (parseCalleeSavedRegister(PFS, CSIInfo, Object.CalleeSavedRegister, Object.CalleeSavedRestored, ObjectIdx)) return true; + if (parseStackObjectsDebugInfo(PFS, Object, ObjectIdx)) + return true; } // Initialize the ordinary frame objects. @@ -700,11 +703,11 @@ return false; } +template bool MIRParserImpl::parseStackObjectsDebugInfo(PerFunctionMIParsingState &PFS, - const yaml::MachineStackObject &Object, int FrameIdx) { + const T &Object, int FrameIdx) { // Debug information can only be attached to stack objects; Fixed stack // objects aren't supported. - assert(FrameIdx >= 0 && "Expected a stack object frame index"); MDNode *Var = nullptr, *Expr = nullptr, *Loc = nullptr; if (parseMDNode(PFS, Var, Object.DebugVar) || parseMDNode(PFS, Expr, Object.DebugExpr) || @@ -719,7 +722,7 @@ typecheckMDNode(DIExpr, Expr, Object.DebugExpr, "DIExpression", *this) || typecheckMDNode(DILoc, Loc, Object.DebugLoc, "DILocation", *this)) return true; - PFS.MF.setVariableDbgInfo(DIVar, DIExpr, unsigned(FrameIdx), DILoc); + PFS.MF.setVariableDbgInfo(DIVar, DIExpr, FrameIdx, DILoc); return false; } Index: lib/CodeGen/MIRPrinter.cpp =================================================================== --- lib/CodeGen/MIRPrinter.cpp +++ lib/CodeGen/MIRPrinter.cpp @@ -256,6 +256,25 @@ OS << printRegClassOrBank(Reg, RegInfo, TRI); } +template +static void +printStackObjectDbgInfo(const MachineFunction::VariableDbgInfo &DebugVar, + T &Object, ModuleSlotTracker &MST) { + { + raw_string_ostream StrOS(Object.DebugVar.Value); + DebugVar.Var->printAsOperand(StrOS, MST); + } + + { + raw_string_ostream StrOS(Object.DebugExpr.Value); + DebugVar.Expr->printAsOperand(StrOS, MST); + } + + { + raw_string_ostream StrOS(Object.DebugLoc.Value); + DebugVar.Loc->printAsOperand(StrOS, MST); + } +} void MIRPrinter::convert(yaml::MachineFunction &MF, const MachineRegisterInfo &RegInfo, @@ -421,19 +440,12 @@ assert(StackObjectInfo != StackObjectOperandMapping.end() && "Invalid stack object index"); const FrameIndexOperand &StackObject = StackObjectInfo->second; - assert(!StackObject.IsFixed && "Expected a non-fixed stack object"); - auto &Object = YMF.StackObjects[StackObject.ID]; - { - raw_string_ostream StrOS(Object.DebugVar.Value); - DebugVar.Var->printAsOperand(StrOS, MST); - } - { - raw_string_ostream StrOS(Object.DebugExpr.Value); - DebugVar.Expr->printAsOperand(StrOS, MST); - } - { - raw_string_ostream StrOS(Object.DebugLoc.Value); - DebugVar.Loc->printAsOperand(StrOS, MST); + if (StackObject.IsFixed) { + auto &Object = YMF.FixedStackObjects[StackObject.ID]; + printStackObjectDbgInfo(DebugVar, Object, MST); + } else { + auto &Object = YMF.StackObjects[StackObject.ID]; + printStackObjectDbgInfo(DebugVar, Object, MST); } } } Index: test/CodeGen/MIR/X86/callee-saved-info.mir =================================================================== --- test/CodeGen/MIR/X86/callee-saved-info.mir +++ test/CodeGen/MIR/X86/callee-saved-info.mir @@ -50,7 +50,7 @@ adjustsStack: true hasCalls: true # CHECK: fixedStack: -# CHECK: callee-saved-register: '$rbx', callee-saved-restored: true } +# CHECK: callee-saved-register: '$rbx', callee-saved-restored: true fixedStack: - { id: 0, type: spill-slot, offset: -16, size: 8, alignment: 16, callee-saved-register: '$rbx' } # CHECK: stack: Index: test/CodeGen/MIR/X86/fixed-stack-di.mir =================================================================== --- /dev/null +++ test/CodeGen/MIR/X86/fixed-stack-di.mir @@ -0,0 +1,41 @@ +# RUN: llc -mtriple=x86_64-apple-unknown -run-pass none %s -o /dev/null + +--- | + + target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" + target triple = "x86_64-apple-unknown" + + declare void @llvm.dbg.declare(metadata, metadata, metadata) #0 + + define hidden void @foo(i32* byval %dstRect) { + entry: + call void @llvm.dbg.declare(metadata i32* %dstRect, metadata !3, metadata !DIExpression()), !dbg !5 + unreachable + } + + attributes #0 = { nounwind readnone speculatable } + + !llvm.dbg.cu = !{!0} + !llvm.module.flags = !{!2} + + !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1) + !1 = !DIFile(filename: "file.cpp", directory: "/dir") + !2 = !{i32 2, !"Debug Info Version", i32 3} + !3 = !DILocalVariable(name: "dstRect", scope: !4) + !4 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !0, file: !1, line: 42, unit: !0) + !5 = !DILocation(line: 42, column: 85, scope: !4) + +... +--- +name: foo +alignment: 4 +tracksRegLiveness: true +frameInfo: + maxAlignment: 8 +fixedStack: + - { id: 0, size: 4, alignment: 16, stack-id: 0, di-variable: '!3', di-expression: '!DIExpression()', + di-location: '!5' } +body: | + bb.0.entry: + +... Index: test/CodeGen/MIR/X86/spill-slot-fixed-stack-objects.mir =================================================================== --- test/CodeGen/MIR/X86/spill-slot-fixed-stack-objects.mir +++ test/CodeGen/MIR/X86/spill-slot-fixed-stack-objects.mir @@ -20,7 +20,8 @@ maxAlignment: 4 # CHECK: fixedStack: # CHECK-NEXT: - { id: 0, type: spill-slot, offset: 0, size: 4, alignment: 4, stack-id: 0, -# CHECK-NEXT: callee-saved-register: '', callee-saved-restored: true } +# CHECK-NEXT: callee-saved-register: '', callee-saved-restored: true, di-variable: '', +# CHECK-NEXT: di-expression: '', di-location: '' } fixedStack: - { id: 0, type: spill-slot, offset: 0, size: 4, alignment: 4 } stack: Index: test/CodeGen/X86/fixed-stack-di-mir.ll =================================================================== --- /dev/null +++ test/CodeGen/X86/fixed-stack-di-mir.ll @@ -0,0 +1,29 @@ +; RUN: llc -mtriple=x86_64-apple-unknown -stop-before=expand-isel-pseudos %s -o - -simplify-mir | FileCheck %s +target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-unknown" + +declare void @llvm.dbg.declare(metadata, metadata, metadata) #0 + +define hidden void @foo(i32* byval %dstRect) { +; CHECK-LABEL: name: foo +entry: + call void @llvm.dbg.declare(metadata i32* %dstRect, metadata !3, metadata !DIExpression()), !dbg !5 +; CHECK: fixedStack: +; CHECK: id: 0 +; CHECK: di-variable: '!3' +; CHECK: di-expression: '!DIExpression()' +; CHECK: di-location: '!5' + unreachable +} + +attributes #0 = { nounwind readnone speculatable } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!2} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1) +!1 = !DIFile(filename: "file.cpp", directory: "/dir") +!2 = !{i32 2, !"Debug Info Version", i32 3} +!3 = !DILocalVariable(name: "dstRect", scope: !4) +!4 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !0, file: !1, line: 42, unit: !0) +!5 = !DILocation(line: 42, column: 85, scope: !4)