Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -2064,28 +2064,57 @@ // LocalSym record, see SymbolRecord.h for more info. MCSymbol *LocalBegin = MMI->getContext().createTempSymbol(), *LocalEnd = MMI->getContext().createTempSymbol(); - OS.AddComment("Record length"); - OS.emitAbsoluteSymbolDiff(LocalEnd, LocalBegin, 2); - OS.EmitLabel(LocalBegin); - - OS.AddComment("Record kind: S_LOCAL"); - OS.EmitIntValue(unsigned(SymbolKind::S_LOCAL), 2); - + bool NeedToEmitRanges = !Var.DefRanges.empty(); + TypeIndex TI = getCompleteTypeIndex(Var.DIVar->getType()); LocalSymFlags Flags = LocalSymFlags::None; if (Var.DIVar->isParameter()) Flags |= LocalSymFlags::IsParameter; if (Var.DefRanges.empty()) Flags |= LocalSymFlags::IsOptimizedOut; + OS.AddComment("Record length"); + OS.emitAbsoluteSymbolDiff(LocalEnd, LocalBegin, 2); + OS.EmitLabel(LocalBegin); + if (Var.DefRanges.size() == 1 && Var.DefRanges[0].Ranges.size() == 1 && + Flags == LocalSymFlags::None && Var.DefRanges[0].StructOffset == 0) { + auto &DefRange = Var.DefRanges[0]; + if (DefRange.InMemory) { + NeedToEmitRanges = false; + if (DefRange.CVRegister == uint16_t(codeview::RegisterId::EBP)) { + OS.AddComment("Record kind: S_BPREL32"); + OS.EmitIntValue(unsigned(SymbolKind::S_BPREL32), 2); + } else { + OS.AddComment("Record kind: S_REGREL32"); + OS.EmitIntValue(unsigned(SymbolKind::S_REGREL32), 2); + } + OS.EmitIntValue(DefRange.DataOffset, 4); + OS.AddComment("TypeIndex"); + OS.EmitIntValue(TI.getIndex(), 4); + if (DefRange.CVRegister != uint16_t(codeview::RegisterId::EBP)) + OS.EmitIntValue(DefRange.CVRegister, 2); + } else { + NeedToEmitRanges = false; + OS.AddComment("Record kind: S_REGISTER"); + OS.EmitIntValue(unsigned(SymbolKind::S_REGISTER), 2); + OS.AddComment("TypeIndex"); + OS.EmitIntValue(TI.getIndex(), 4); + OS.EmitIntValue(DefRange.CVRegister, 2); + } + } else { + OS.AddComment("Record kind: S_LOCAL"); + OS.EmitIntValue(unsigned(SymbolKind::S_LOCAL), 2); + OS.AddComment("TypeIndex"); + OS.EmitIntValue(TI.getIndex(), 4); + OS.AddComment("Flags"); + OS.EmitIntValue(static_cast(Flags), 2); + } - OS.AddComment("TypeIndex"); - TypeIndex TI = getCompleteTypeIndex(Var.DIVar->getType()); - OS.EmitIntValue(TI.getIndex(), 4); - OS.AddComment("Flags"); - OS.EmitIntValue(static_cast(Flags), 2); // Truncate the name so we won't overflow the record length field. emitNullTerminatedSymbolName(OS, Var.DIVar->getName()); OS.EmitLabel(LocalEnd); + if (!NeedToEmitRanges) + return; + // Calculate the on disk prefix of the appropriate def range record. The // records and on disk formats are described in SymbolRecords.h. BytePrefix // should be big enough to hold all forms without memory allocation. Index: llvm/lib/DebugInfo/CodeView/SymbolDumper.cpp =================================================================== --- llvm/lib/DebugInfo/CodeView/SymbolDumper.cpp +++ llvm/lib/DebugInfo/CodeView/SymbolDumper.cpp @@ -489,7 +489,7 @@ Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, RegisterSym &Register) { printTypeIndex("Type", Register.Index); - W.printEnum("Seg", uint16_t(Register.Register), getRegisterNames()); + W.printEnum("Register", uint16_t(Register.Register), getRegisterNames()); W.printString("Name", Register.Name); return Error::success(); } Index: llvm/lib/ObjectYAML/CodeViewYAMLSymbols.cpp =================================================================== --- llvm/lib/ObjectYAML/CodeViewYAMLSymbols.cpp +++ llvm/lib/ObjectYAML/CodeViewYAMLSymbols.cpp @@ -316,7 +316,7 @@ template <> void SymbolRecordImpl::map(IO &IO) { IO.mapRequired("Type", Symbol.Index); - IO.mapRequired("Seg", Symbol.Register); + IO.mapRequired("Register", Symbol.Register); IO.mapRequired("Name", Symbol.Name); } Index: llvm/test/DebugInfo/COFF/local-variables.ll =================================================================== --- llvm/test/DebugInfo/COFF/local-variables.ll +++ llvm/test/DebugInfo/COFF/local-variables.ll @@ -72,29 +72,21 @@ ; ASM: .short 1 # Flags ; ASM: .asciz "param" ; ASM: .cv_def_range [[prologue_end]] [[param_end]], "E\021O\001\000\0004\000\000\000" -; ASM: .short 4414 # Record kind: S_LOCAL +; ASM: .short 4369 # Record kind: S_REGREL32 ; ASM: .long 116 # TypeIndex -; ASM: .short 0 # Flags ; ASM: .asciz "a" -; ASM: .cv_def_range [[if_start]] [[else_start]], "E\021O\001\000\000(\000\000\000" -; ASM: .short 4414 # Record kind: S_LOCAL +; ASM: .short 4369 # Record kind: S_REGREL32 ; ASM: .long 116 # TypeIndex -; ASM: .short 0 # Flags ; ASM: .asciz "b" -; ASM: .cv_def_range [[else_start]] [[else_end]], "E\021O\001\000\000$\000\000\000" ; ASM: .short 4429 # Record kind: S_INLINESITE -; ASM: .short 4414 # Record kind: S_LOCAL +; ASM: .short 4369 # Record kind: S_REGREL32 ; ASM: .long 116 # TypeIndex -; ASM: .short 0 # Flags ; ASM: .asciz "v" -; ASM: .cv_def_range [[inline_site1]] [[else_start]], "E\021O\001\000\000,\000\000\000" ; ASM: .short 4430 # Record kind: S_INLINESITE_END ; ASM: .short 4429 # Record kind: S_INLINESITE -; ASM: .short 4414 # Record kind: S_LOCAL +; ASM: .short 4369 # Record kind: S_REGREL32 ; ASM: .long 116 # TypeIndex -; ASM: .short 0 # Flags ; ASM: .asciz "v" -; ASM: .cv_def_range [[inline_site2]] [[else_end]], "E\021O\001\000\0000\000\000\000" ; ASM: .short 4430 # Record kind: S_INLINESITE_END ; OBJ: Subsection [ @@ -121,40 +113,18 @@ ; OBJ: Range: 0x4F ; OBJ: } ; OBJ: } -; OBJ: LocalSym { +; OBJ: RegRelativeSym { +; OBJ: Offset: 0x28 ; OBJ: Type: int (0x74) -; OBJ: Flags [ (0x0) -; OBJ: ] +; OBJ: Register: RSP (0x14F) ; OBJ: VarName: a ; OBJ: } -; OBJ: DefRangeRegisterRelSym { -; OBJ: BaseRegister: 335 -; OBJ: HasSpilledUDTMember: No -; OBJ: OffsetInParent: 0 -; OBJ: BasePointerOffset: 40 -; OBJ: LocalVariableAddrRange { -; OBJ: OffsetStart: .text+0xC -; OBJ: ISectStart: 0x0 -; OBJ: Range: 0x21 -; OBJ: } -; OBJ: } -; OBJ: LocalSym { +; OBJ: RegRelativeSym { +; OBJ: Offset: 0x24 ; OBJ: Type: int (0x74) -; OBJ: Flags [ (0x0) -; OBJ: ] +; OBJ: Register: RSP (0x14F) ; OBJ: VarName: b ; OBJ: } -; OBJ: DefRangeRegisterRelSym { -; OBJ: BaseRegister: 335 -; OBJ: HasSpilledUDTMember: No -; OBJ: OffsetInParent: 0 -; OBJ: BasePointerOffset: 36 -; OBJ: LocalVariableAddrRange { -; OBJ: OffsetStart: .text+0x2D -; OBJ: ISectStart: 0x0 -; OBJ: Range: 0x1F -; OBJ: } -; OBJ: } ; OBJ: InlineSiteSym { ; OBJ: PtrParent: 0x0 ; OBJ: PtrEnd: 0x0 @@ -166,23 +136,12 @@ ; OBJ: ChangeCodeLength: 0xC ; OBJ: ] ; OBJ: } -; OBJ: LocalSym { +; OBJ: RegRelativeSym { +; OBJ: Offset: 0x2C ; OBJ: Type: int (0x74) -; OBJ: Flags [ (0x0) -; OBJ: ] +; OBJ: Register: RSP (0x14F) ; OBJ: VarName: v ; OBJ: } -; OBJ: DefRangeRegisterRelSym { -; OBJ: BaseRegister: 335 -; OBJ: HasSpilledUDTMember: No -; OBJ: OffsetInParent: 0 -; OBJ: BasePointerOffset: 44 -; OBJ: LocalVariableAddrRange { -; OBJ: OffsetStart: .text+0x14 -; OBJ: ISectStart: 0x0 -; OBJ: Range: 0x19 -; OBJ: } -; OBJ: } ; OBJ: InlineSiteEnd { ; OBJ: } ; OBJ: InlineSiteSym { @@ -196,23 +155,12 @@ ; OBJ: ChangeCodeLength: 0xA ; OBJ: ] ; OBJ: } -; OBJ: LocalSym { +; OBJ: RegRelativeSym { +; OBJ: Offset: 0x30 ; OBJ: Type: int (0x74) -; OBJ: Flags [ (0x0) -; OBJ: ] +; OBJ: Register: RSP (0x14F) ; OBJ: VarName: v ; OBJ: } -; OBJ: DefRangeRegisterRelSym { -; OBJ: BaseRegister: 335 -; OBJ: HasSpilledUDTMember: No -; OBJ: OffsetInParent: 0 -; OBJ: BasePointerOffset: 48 -; OBJ: LocalVariableAddrRange { -; OBJ: OffsetStart: .text+0x35 -; OBJ: ISectStart: 0x0 -; OBJ: Range: 0x17 -; OBJ: } -; OBJ: } ; OBJ: InlineSiteEnd { ; OBJ: } ; OBJ: ProcEnd Index: llvm/test/DebugInfo/COFF/parameter-order.ll =================================================================== --- llvm/test/DebugInfo/COFF/parameter-order.ll +++ llvm/test/DebugInfo/COFF/parameter-order.ll @@ -30,17 +30,13 @@ ; ASM: .asciz "c" ; ASM: .cv_def_range -; ASM: .short 4414 # Record kind: S_LOCAL +; ASM: .short 4369 # Record kind: S_REGREL32 ; ASM: .long 116 # TypeIndex -; ASM: .short 0 # Flags ; ASM: .asciz "d" -; ASM: .cv_def_range -; ASM: .short 4414 # Record kind: S_LOCAL +; ASM: .short 4369 # Record kind: S_REGREL32 ; ASM: .long 116 # TypeIndex -; ASM: .short 0 # Flags ; ASM: .asciz "e" -; ASM: .cv_def_range ; ModuleID = 't.cpp' Index: llvm/test/DebugInfo/COFF/register-variables.ll =================================================================== --- llvm/test/DebugInfo/COFF/register-variables.ll +++ llvm/test/DebugInfo/COFF/register-variables.ll @@ -60,23 +60,22 @@ ; ASM: .asciz "p" ; ASM: .cv_def_range .Lfunc_begin0 [[p_ecx_esi]], "A\021\022\000\000\000" ; ASM: .cv_def_range [[p_ecx_esi]] [[func_end]], "A\021\027\000\000\000" -; ASM: .short 4414 # Record kind: S_LOCAL +; ASM: .short 4358 # Record kind: S_REGISTER +; ASM: .short 17 ; ASM: .asciz "a" -; ASM: .cv_def_range [[after_getint]] [[after_inc_eax]], "A\021\021\000\000\000" -; ASM: .short 4414 # Record kind: S_LOCAL +; ASM: .short 4358 # Record kind: S_REGISTER +; ASM: .short 17 ; ASM: .asciz "c" -; ASM: .cv_def_range [[after_getint]] [[after_je]], "A\021\021\000\000\000" -; ASM: .short 4414 # Record kind: S_LOCAL +; ASM: .short 4358 # Record kind: S_REGISTER +; ASM: .short 17 ; ASM: .asciz "b" -; ASM: .cv_def_range [[after_inc_eax]] [[after_if]], "A\021\021\000\000\000" - ; ASM: .short 4429 # Record kind: S_INLINESITE ; ASM: .short 4414 # Record kind: S_LOCAL ; ASM: .asciz "a" ; ASM: .cv_def_range [[after_getint]] [[after_inc_eax]], "A\021\021\000\000\000" -; ASM: .short 4414 # Record kind: S_LOCAL +; ASM: .short 4358 # Record kind: S_REGISTER +; ASM: .short 17 ; ASM: .asciz "b" -; ASM: .cv_def_range [[after_inc_eax]] [[after_if]], "A\021\021\000\000\000" ; ASM: .short 4430 # Record kind: S_INLINESITE_END ; OBJ: Subsection [ @@ -107,47 +106,20 @@ ; OBJ: Range: 0x19 ; OBJ: } ; OBJ: } -; OBJ: LocalSym { +; OBJ: RegisterSym { ; OBJ: Type: int (0x74) -; OBJ: Flags [ (0x0) -; OBJ: ] -; OBJ: VarName: a +; OBJ: Register: EAX (0x11) +; OBJ: Name: a ; OBJ: } -; OBJ: DefRangeRegisterSym { -; OBJ: Register: 17 -; OBJ: LocalVariableAddrRange { -; OBJ: OffsetStart: .text+0xC -; OBJ: ISectStart: 0x0 -; OBJ: Range: 0x7 -; OBJ: } -; OBJ: } -; OBJ: LocalSym { +; OBJ: RegisterSym { ; OBJ: Type: int (0x74) -; OBJ: Flags [ (0x0) -; OBJ: ] -; OBJ: VarName: c +; OBJ: Register: EAX (0x11) +; OBJ: Name: c ; OBJ: } -; OBJ: DefRangeRegisterSym { -; OBJ: Register: 17 -; OBJ: LocalVariableAddrRange { -; OBJ: OffsetStart: .text+0xC -; OBJ: ISectStart: 0x0 -; OBJ: Range: 0x4 -; OBJ: } -; OBJ: } -; OBJ: LocalSym { +; OBJ: RegisterSym { ; OBJ: Type: int (0x74) -; OBJ: Flags [ (0x0) -; OBJ: ] -; OBJ: VarName: b -; OBJ: } -; OBJ: DefRangeRegisterSym { -; OBJ: Register: 17 -; OBJ: MayHaveNoName: 0 -; OBJ: OffsetStart: .text+0x13 -; OBJ: ISectStart: 0x0 -; OBJ: Range: 0x6 -; OBJ: } +; OBJ: Register: EAX (0x11) +; OBJ: Name: b ; OBJ: } ; OBJ: InlineSiteSym { ; OBJ: PtrParent: 0x0 @@ -169,19 +141,10 @@ ; OBJ: Range: 0x7 ; OBJ: } ; OBJ: } -; OBJ: LocalSym { +; OBJ: RegisterSym { ; OBJ: Type: int (0x74) -; OBJ: Flags [ (0x0) -; OBJ: ] -; OBJ: VarName: b -; OBJ: } -; OBJ: DefRangeRegisterSym { -; OBJ: Register: 17 -; OBJ: LocalVariableAddrRange { -; OBJ: OffsetStart: .text+0x13 -; OBJ: ISectStart: 0x0 -; OBJ: Range: 0x6 -; OBJ: } +; OBJ: Register: EAX (0x11) +; OBJ: Name: b ; OBJ: } ; OBJ: InlineSiteEnd { ; OBJ: } Index: llvm/test/DebugInfo/COFF/typedef.ll =================================================================== --- llvm/test/DebugInfo/COFF/typedef.ll +++ llvm/test/DebugInfo/COFF/typedef.ll @@ -2,11 +2,9 @@ ; CHECK: CodeViewDebugInfo [ ; CHECK: Subsection [ -; CHECK: LocalSym { +; CHECK: RegRelativeSym { ; CHECK: Type: wchar_t (0x71) -; CHECK: Flags [ (0x0) -; CHECK: ] -; CHECK: VarName: foo +; CHECK: Name: foo ; CHECK: } ; CHECK: Subsection [ ; CHECK: SubSectionType: Symbols (0xF1) Index: llvm/test/DebugInfo/COFF/types-array.ll =================================================================== --- llvm/test/DebugInfo/COFF/types-array.ll +++ llvm/test/DebugInfo/COFF/types-array.ll @@ -61,23 +61,11 @@ ; CHECK: DisplayName: f ; CHECK: LinkageName: ?f@@YAXXZ ; CHECK: } -; CHECK: LocalSym { +; CHECK: BPRelativeSym { +; CHECK: Offset: -20 ; CHECK: Type: 0x1003 -; CHECK: Flags [ (0x0) -; CHECK: ] ; CHECK: VarName: a ; CHECK: } -; CHECK: DefRangeRegisterRelSym { -; CHECK: BaseRegister: 22 -; CHECK: HasSpilledUDTMember: No -; CHECK: OffsetInParent: 0 -; CHECK: BasePointerOffset: -20 -; CHECK: LocalVariableAddrRange { -; CHECK: OffsetStart: .text+0x3 -; CHECK: ISectStart: 0x0 -; CHECK: Range: 0x36 -; CHECK: } -; CHECK: } ; CHECK: ProcEnd { ; CHECK: } ; CHECK: ] Index: llvm/test/DebugInfo/COFF/types-basic.ll =================================================================== --- llvm/test/DebugInfo/COFF/types-basic.ll +++ llvm/test/DebugInfo/COFF/types-basic.ll @@ -250,48 +250,59 @@ ; CHECK: ] ; CHECK: VarName: p3 ; CHECK: } -; CHECK: LocalSym { +; CHECK: RegRelativeSym { ; CHECK: Type: int (0x74) +; CHECK: Register: RSP (0x14F) ; CHECK: VarName: v1 ; CHECK: } -; CHECK: LocalSym { +; CHECK: RegRelativeSym { ; CHECK: Type: int* (0x674) +; CHECK: Register: RSP (0x14F) ; CHECK: VarName: v2 ; CHECK: } -; CHECK: LocalSym { +; CHECK: RegRelativeSym { ; CHECK: Type: const int* (0x1004) +; CHECK: Register: RSP (0x14F) ; CHECK: VarName: v21 ; CHECK: } -; CHECK: LocalSym { +; CHECK: RegRelativeSym { ; CHECK: Type: void* (0x603) +; CHECK: Register: RSP (0x14F) ; CHECK: VarName: v3 ; CHECK: } -; CHECK: LocalSym { +; CHECK: RegRelativeSym { ; CHECK: Type: int A::* (0x1006) +; CHECK: Register: RSP (0x14F) ; CHECK: VarName: v4 ; CHECK: } -; CHECK: LocalSym { +; CHECK: RegRelativeSym { ; CHECK: Type: void A::() A::* (0x100E) +; CHECK: Register: RSP (0x14F) ; CHECK: VarName: v5 ; CHECK: } -; CHECK: LocalSym { +; CHECK: RegRelativeSym { ; CHECK: Type: long (0x12) +; CHECK: Register: RSP (0x14F) ; CHECK: VarName: l1 ; CHECK: } -; CHECK: LocalSym { +; CHECK: RegRelativeSym { ; CHECK: Type: long (0x12) +; CHECK: Register: RSP (0x14F) ; CHECK: VarName: l2 ; CHECK: } -; CHECK: LocalSym { +; CHECK: RegRelativeSym { ; CHECK: Type: unsigned long (0x22) +; CHECK: Register: RSP (0x14F) ; CHECK: VarName: l3 ; CHECK: } -; CHECK: LocalSym { +; CHECK: RegRelativeSym { ; CHECK: Type: unsigned long (0x22) +; CHECK: Register: RSP (0x14F) ; CHECK: VarName: l4 ; CHECK: } -; CHECK: LocalSym { +; CHECK: RegRelativeSym { ; CHECK: Type: const void* (0x1010) +; CHECK: Register: RSP (0x14F) ; CHECK: VarName: v6 ; CHECK: } ; CHECK: ProcEnd { @@ -303,46 +314,39 @@ ; CHECK: DisplayName: CharTypes ; CHECK: LinkageName: ?CharTypes@@YAXXZ ; CHECK: } -; CHECK: LocalSym { +; CHECK: RegRelativeSym { ; CHECK: Type: wchar_t (0x71) -; CHECK: Flags [ (0x0) -; CHECK: ] +; CHECK: Register: RSP (0x14F) ; CHECK: VarName: w ; CHECK: } -; CHECK: LocalSym { +; CHECK: RegRelativeSym { ; CHECK: Type: unsigned short (0x21) -; CHECK: Flags [ (0x0) -; CHECK: ] +; CHECK: Register: RSP (0x14F) ; CHECK: VarName: us ; CHECK: } -; CHECK: LocalSym { +; CHECK: RegRelativeSym { ; CHECK: Type: char (0x70) -; CHECK: Flags [ (0x0) -; CHECK: ] +; CHECK: Register: RSP (0x14F) ; CHECK: VarName: c ; CHECK: } -; CHECK: LocalSym { +; CHECK: RegRelativeSym { ; CHECK: Type: unsigned char (0x20) -; CHECK: Flags [ (0x0) -; CHECK: ] +; CHECK: Register: RSP (0x14F) ; CHECK: VarName: uc ; CHECK: } -; CHECK: LocalSym { +; CHECK: RegRelativeSym { ; CHECK: Type: signed char (0x10) -; CHECK: Flags [ (0x0) -; CHECK: ] +; CHECK: Register: RSP (0x14F) ; CHECK: VarName: sc ; CHECK: } -; CHECK: LocalSym { +; CHECK: RegRelativeSym { ; CHECK: Type: char16_t (0x7A) -; CHECK: Flags [ (0x0) -; CHECK: ] +; CHECK: Register: RSP (0x14F) ; CHECK: VarName: c16 ; CHECK: } -; CHECK: LocalSym { +; CHECK: RegRelativeSym { ; CHECK: Type: char32_t (0x7B) -; CHECK: Flags [ (0x0) -; CHECK: ] +; CHECK: Register: RSP (0x14F) ; CHECK: VarName: c32 ; CHECK: } ; CHECK: ProcEnd {