Remove LastOffset from the asm parser.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129378 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/MC/MCDwarf.cpp b/lib/MC/MCDwarf.cpp
index 84f4a3f..8770c8f 100644
--- a/lib/MC/MCDwarf.cpp
+++ b/lib/MC/MCDwarf.cpp
@@ -523,6 +523,7 @@
   case MCCFIInstruction::RelMove: {
     const MachineLocation &Dst = Instr.getDestination();
     const MachineLocation &Src = Instr.getSource();
+    const bool IsRelative = Instr.getOperation() == MCCFIInstruction::RelMove;
 
     // If advancing cfa.
     if (Dst.isReg() && Dst.getReg() == MachineLocation::VirtualFP) {
@@ -535,7 +536,11 @@
         Streamer.EmitULEB128IntValue(Src.getReg());
       }
 
-      CFAOffset = -Src.getOffset();
+      if (IsRelative)
+        CFAOffset += Src.getOffset();
+      else
+        CFAOffset = -Src.getOffset();
+
       Streamer.EmitULEB128IntValue(CFAOffset, 1);
       return;
     }
@@ -549,7 +554,6 @@
 
     unsigned Reg = Src.getReg();
 
-    const bool IsRelative = Instr.getOperation() == MCCFIInstruction::RelMove;
     int Offset = Dst.getOffset();
     if (IsRelative)
       Offset -= CFAOffset;
diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp
index 87b7cd6..04c1f8b 100644
--- a/lib/MC/MCParser/AsmParser.cpp
+++ b/lib/MC/MCParser/AsmParser.cpp
@@ -81,11 +81,6 @@
   MCAsmParserExtension *GenericParser;
   MCAsmParserExtension *PlatformParser;
 
-  // FIXME: This is not the best place to store this. To handle a (for example)
-  // .cfi_rel_offset before a .cfi_def_cfa_offset we need to know the initial
-  // frame state.
-  int64_t LastOffset;
-
   /// This is the current buffer index we're lexing from as managed by the
   /// SourceMgr object.
   int CurBuffer;
@@ -145,14 +140,6 @@
 
   /// }
 
-  int64_t adjustLastOffset(int64_t Adjustment) {
-    LastOffset += Adjustment;
-    return LastOffset;
-  }
-  void setLastOffset(int64_t Offset) {
-    LastOffset = Offset;
-  }
-
 private:
   void CheckForValidSection();
 
@@ -337,7 +324,7 @@
 AsmParser::AsmParser(const Target &T, SourceMgr &_SM, MCContext &_Ctx,
                      MCStreamer &_Out, const MCAsmInfo &_MAI)
   : Lexer(_MAI), Ctx(_Ctx), Out(_Out), SrcMgr(_SM),
-    GenericParser(new GenericAsmParser), PlatformParser(0), LastOffset(0),
+    GenericParser(new GenericAsmParser), PlatformParser(0),
     CurBuffer(0), MacrosEnabled(true) {
   Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer));
 
@@ -2334,8 +2321,6 @@
   if (getParser().ParseAbsoluteExpression(Offset))
     return true;
 
-  getParser().setLastOffset(Offset);
-
   return getStreamer().EmitCFIDefCfaOffset(Offset);
 }
 
@@ -2347,9 +2332,8 @@
   if (getParser().ParseAbsoluteExpression(Adjustment))
     return true;
 
-  int64_t Offset = getParser().adjustLastOffset(Adjustment);
-
-  return getStreamer().EmitCFIDefCfaOffset(Offset);
+  getStreamer().EmitCFIAdjustCfaOffset(Adjustment);
+  return false;
 }
 
 /// ParseDirectiveCFIDefCfaRegister
diff --git a/lib/MC/MCStreamer.cpp b/lib/MC/MCStreamer.cpp
index 92e76c9..a02e9ac 100644
--- a/lib/MC/MCStreamer.cpp
+++ b/lib/MC/MCStreamer.cpp
@@ -197,6 +197,17 @@
   return false;
 }
 
+void MCStreamer::EmitCFIAdjustCfaOffset(int64_t Adjustment) {
+  EnsureValidFrame();
+  MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
+  MCSymbol *Label = getContext().CreateTempSymbol();
+  EmitLabel(Label);
+  MachineLocation Dest(MachineLocation::VirtualFP);
+  MachineLocation Source(MachineLocation::VirtualFP, Adjustment);
+  MCCFIInstruction Instruction(MCCFIInstruction::RelMove, Label, Dest, Source);
+  CurFrame->Instructions.push_back(Instruction);
+}
+
 bool MCStreamer::EmitCFIDefCfaRegister(int64_t Register) {
   EnsureValidFrame();
   MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();