From 529a01df02ad221e8e55097a8ee36b85234eb078 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Sat, 24 Nov 2012 02:18:49 +0000 Subject: [PATCH] Move a bit of duplicated code into a helper function. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168533 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCStreamer.h | 1 + lib/MC/MCStreamer.cpp | 75 ++++++++++++++---------------------- 2 files changed, 30 insertions(+), 46 deletions(-) diff --git a/include/llvm/MC/MCStreamer.h b/include/llvm/MC/MCStreamer.h index b5c8008cd60..47cea038c37 100644 --- a/include/llvm/MC/MCStreamer.h +++ b/include/llvm/MC/MCStreamer.h @@ -55,6 +55,7 @@ namespace llvm { std::vector FrameInfos; MCDwarfFrameInfo *getCurrentFrameInfo(); + MCSymbol *EmitCFICommon(); void EnsureValidFrame(); std::vector W64UnwindInfos; diff --git a/lib/MC/MCStreamer.cpp b/lib/MC/MCStreamer.cpp index b8e768cbc87..a771800c8b1 100644 --- a/lib/MC/MCStreamer.cpp +++ b/lib/MC/MCStreamer.cpp @@ -234,63 +234,58 @@ void MCStreamer::RecordProcEnd(MCDwarfFrameInfo &Frame) { EmitLabel(Frame.End); } -void MCStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) { +MCSymbol *MCStreamer::EmitCFICommon() { EnsureValidFrame(); - MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); MCSymbol *Label = getContext().CreateTempSymbol(); EmitLabel(Label); + return Label; +} + +void MCStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) { + MCSymbol *Label = EmitCFICommon(); MCCFIInstruction Instruction = MCCFIInstruction::createDefCfa(Label, Register, Offset); + MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); CurFrame->Instructions.push_back(Instruction); } void MCStreamer::EmitCFIDefCfaOffset(int64_t Offset) { - EnsureValidFrame(); - MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); - MCSymbol *Label = getContext().CreateTempSymbol(); - EmitLabel(Label); + MCSymbol *Label = EmitCFICommon(); MCCFIInstruction Instruction = MCCFIInstruction::createDefCfaOffset(Label, Offset); + MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); CurFrame->Instructions.push_back(Instruction); } void MCStreamer::EmitCFIAdjustCfaOffset(int64_t Adjustment) { - EnsureValidFrame(); - MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); - MCSymbol *Label = getContext().CreateTempSymbol(); - EmitLabel(Label); + MCSymbol *Label = EmitCFICommon(); MCCFIInstruction Instruction = MCCFIInstruction::createAdjustCfaOffset(Label, Adjustment); + MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); CurFrame->Instructions.push_back(Instruction); } void MCStreamer::EmitCFIDefCfaRegister(int64_t Register) { - EnsureValidFrame(); - MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); - MCSymbol *Label = getContext().CreateTempSymbol(); - EmitLabel(Label); + MCSymbol *Label = EmitCFICommon(); MCCFIInstruction Instruction = MCCFIInstruction::createDefCfaRegister(Label, Register); + MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); CurFrame->Instructions.push_back(Instruction); } void MCStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) { - EnsureValidFrame(); - MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); - MCSymbol *Label = getContext().CreateTempSymbol(); - EmitLabel(Label); + MCSymbol *Label = EmitCFICommon(); MCCFIInstruction Instruction = MCCFIInstruction::createCFIOffset(Label, Register, Offset); + MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); CurFrame->Instructions.push_back(Instruction); } void MCStreamer::EmitCFIRelOffset(int64_t Register, int64_t Offset) { - EnsureValidFrame(); - MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); - MCSymbol *Label = getContext().CreateTempSymbol(); - EmitLabel(Label); + MCSymbol *Label = EmitCFICommon(); MCCFIInstruction Instruction = MCCFIInstruction::createRelOffset(Label, Register, Offset); + MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); CurFrame->Instructions.push_back(Instruction); } @@ -310,50 +305,40 @@ void MCStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) { } void MCStreamer::EmitCFIRememberState() { - EnsureValidFrame(); - MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); - MCSymbol *Label = getContext().CreateTempSymbol(); - EmitLabel(Label); + MCSymbol *Label = EmitCFICommon(); MCCFIInstruction Instruction = MCCFIInstruction::createRememberState(Label); + MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); CurFrame->Instructions.push_back(Instruction); } void MCStreamer::EmitCFIRestoreState() { // FIXME: Error if there is no matching cfi_remember_state. - EnsureValidFrame(); - MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); - MCSymbol *Label = getContext().CreateTempSymbol(); - EmitLabel(Label); + MCSymbol *Label = EmitCFICommon(); MCCFIInstruction Instruction = MCCFIInstruction::createRestoreState(Label); + MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); CurFrame->Instructions.push_back(Instruction); } void MCStreamer::EmitCFISameValue(int64_t Register) { - EnsureValidFrame(); - MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); - MCSymbol *Label = getContext().CreateTempSymbol(); - EmitLabel(Label); + MCSymbol *Label = EmitCFICommon(); MCCFIInstruction Instruction = MCCFIInstruction::createSameValue(Label, Register); + MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); CurFrame->Instructions.push_back(Instruction); } void MCStreamer::EmitCFIRestore(int64_t Register) { - EnsureValidFrame(); - MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); - MCSymbol *Label = getContext().CreateTempSymbol(); - EmitLabel(Label); + MCSymbol *Label = EmitCFICommon(); MCCFIInstruction Instruction = MCCFIInstruction::createRestore(Label, Register); + MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); CurFrame->Instructions.push_back(Instruction); } void MCStreamer::EmitCFIEscape(StringRef Values) { - EnsureValidFrame(); - MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); - MCSymbol *Label = getContext().CreateTempSymbol(); - EmitLabel(Label); + MCSymbol *Label = EmitCFICommon(); MCCFIInstruction Instruction = MCCFIInstruction::createEscape(Label, Values); + MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); CurFrame->Instructions.push_back(Instruction); } @@ -364,12 +349,10 @@ void MCStreamer::EmitCFISignalFrame() { } void MCStreamer::EmitCFIUndefined(int64_t Register) { - EnsureValidFrame(); - MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); - MCSymbol *Label = getContext().CreateTempSymbol(); - EmitLabel(Label); + MCSymbol *Label = EmitCFICommon(); MCCFIInstruction Instruction = MCCFIInstruction::createUndefined(Label, Register); + MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo(); CurFrame->Instructions.push_back(Instruction); }