[llvm-commits] [llvm] r168532 - in /llvm/trunk: include/llvm/MC/MCDwarf.h lib/MC/MCDwarf.cpp lib/MC/MCStreamer.cpp

Jim Grosbach grosbach at apple.com
Wed Nov 28 13:00:55 PST 2012


Hi Rafael,

One question below:

On Nov 23, 2012, at 6:01 PM, Rafael Espindola <rafael.espindola at gmail.com> wrote:

> Author: rafael
> Date: Fri Nov 23 20:01:08 2012
> New Revision: 168532
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=168532&view=rev
> Log:
> Refactor how MCCFIInstructions are created.
> 
> Give MCCFIInstruction a single, private constructor and add helper static
> methods that create each type of cfi instruction. This is is preparation
> for changing its representation. The representation with a pair
> MachineLocations older than MC and has been abused quiet a bit to support
> more cfi instructions.
> 
> Modified:
>    llvm/trunk/include/llvm/MC/MCDwarf.h
>    llvm/trunk/lib/MC/MCDwarf.cpp
>    llvm/trunk/lib/MC/MCStreamer.cpp
> 
> Modified: llvm/trunk/include/llvm/MC/MCDwarf.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCDwarf.h?rev=168532&r1=168531&r2=168532&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/MC/MCDwarf.h (original)
> +++ llvm/trunk/include/llvm/MC/MCDwarf.h Fri Nov 23 20:01:08 2012
> @@ -275,28 +275,100 @@
>     MachineLocation Destination;
>     MachineLocation Source;
>     std::vector<char> Values;
> +    MCCFIInstruction(OpType Op, MCSymbol *L, const MachineLocation &D,
> +                     const MachineLocation &S, StringRef V) :
> +      Operation(Op), Label(L), Destination(D), Source(S),
> +      Values(V.begin(), V.end()) {
> +    }
> +
>   public:
> -    MCCFIInstruction(OpType Op, MCSymbol *L)
> -      : Operation(Op), Label(L) {
> -      assert(Op == RememberState || Op == RestoreState);
> -    }
> -    MCCFIInstruction(OpType Op, MCSymbol *L, unsigned Register)
> -      : Operation(Op), Label(L), Destination(Register) {
> -      assert(Op == SameValue || Op == Restore || Op == Undefined);
> -    }
> -    MCCFIInstruction(MCSymbol *L, const MachineLocation &D,
> -                     const MachineLocation &S)
> -      : Operation(Move), Label(L), Destination(D), Source(S) {
> +    static MCCFIInstruction
> +    createCFIOffset(MCSymbol *L, unsigned Register, int Offset) {
> +      MachineLocation Dest(Register, Offset);
> +      MachineLocation Source(Register, Offset);
> +
> +      MCCFIInstruction Ret(Move, L, Dest, Source, "");
> +      return Ret;
>     }
> -    MCCFIInstruction(OpType Op, MCSymbol *L, const MachineLocation &D,
> -                     const MachineLocation &S)
> -      : Operation(Op), Label(L), Destination(D), Source(S) {
> -      assert(Op == RelMove);
> -    }
> -    MCCFIInstruction(OpType Op, MCSymbol *L, StringRef Vals)
> -      : Operation(Op), Label(L), Values(Vals.begin(), Vals.end()) {
> -      assert(Op == Escape);
> +
> +    static MCCFIInstruction
> +    createDefCfaRegister(MCSymbol *L, unsigned Register) {
> +      MachineLocation Dest(Register);
> +      MachineLocation Source(MachineLocation::VirtualFP);
> +      MCCFIInstruction Ret(Move, L, Dest, Source, "");
> +      return Ret;
> +    }
> +
> +    static MCCFIInstruction createDefCfaOffset(MCSymbol *L, int Offset) {
> +      MachineLocation Dest(MachineLocation::VirtualFP);
> +      MachineLocation Source(MachineLocation::VirtualFP, -Offset);
> +      MCCFIInstruction Ret(Move, L, Dest, Source, "");
> +      return Ret;
> +    }
> +
> +    static MCCFIInstruction
> +    createDefCfa(MCSymbol *L, unsigned Register, int Offset) {
> +      MachineLocation Dest(MachineLocation::VirtualFP);
> +      MachineLocation Source(Register, -Offset);
> +      MCCFIInstruction Ret(Move, L, Dest, Source, "");
> +      return Ret;
> +    }
> +
> +    static MCCFIInstruction createUndefined(MCSymbol *L, unsigned Register) {
> +      MachineLocation Dummy;
> +      MachineLocation Dest(Register);
> +      MCCFIInstruction Ret(Undefined, L, Dest, Dummy, "");
> +      return Ret;
> +    }
> +
> +    static MCCFIInstruction createRestore(MCSymbol *L, unsigned Register) {
> +      MachineLocation Dummy;
> +      MachineLocation Dest(Register);
> +      MCCFIInstruction Ret(Restore, L, Dest, Dummy, "");
> +      return Ret;
>     }
> +
> +    static MCCFIInstruction createSameValue(MCSymbol *L, unsigned Register) {
> +      MachineLocation Dummy;
> +      MachineLocation Dest(Register);
> +      MCCFIInstruction Ret(SameValue, L, Dest, Dummy, "");
> +      return Ret;
> +    }
> +
> +    static MCCFIInstruction createRestoreState(MCSymbol *L) {
> +      MachineLocation Dummy;
> +      MCCFIInstruction Ret(RestoreState, L, Dummy, Dummy, "");
> +      return Ret;
> +    }
> +
> +    static MCCFIInstruction createRememberState(MCSymbol *L) {
> +      MachineLocation Dummy;
> +      MCCFIInstruction Ret(RememberState, L, Dummy, Dummy, "");
> +      return Ret;
> +    }
> +
> +    static MCCFIInstruction
> +    createRelOffset(MCSymbol *L, unsigned Register, int Offset) {
> +      MachineLocation Dest(Register, Offset);
> +      MachineLocation Source(Register, Offset);
> +      MCCFIInstruction Ret(RelMove, L, Dest, Source, "");
> +      return Ret;
> +    }
> +
> +    static MCCFIInstruction
> +    createAdjustCfaOffset(MCSymbol *L, int Adjustment) {
> +      MachineLocation Dest(MachineLocation::VirtualFP);
> +      MachineLocation Source(MachineLocation::VirtualFP, Adjustment);
> +      MCCFIInstruction Ret(RelMove, L, Dest, Source, "");
> +      return Ret;
> +    }
> +
> +    static MCCFIInstruction createEscape(MCSymbol *L, StringRef Vals) {
> +      MachineLocation Dummy;
> +      MCCFIInstruction Ret(Escape, L, Dummy, Dummy, Vals);
> +      return Ret;
> +    }
> +
>     OpType getOperation() const { return Operation; }
>     MCSymbol *getLabel() const { return Label; }
>     const MachineLocation &getDestination() const { return Destination; }
> 
> Modified: llvm/trunk/lib/MC/MCDwarf.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=168532&r1=168531&r2=168532&view=diff
> ==============================================================================
> --- llvm/trunk/lib/MC/MCDwarf.cpp (original)
> +++ llvm/trunk/lib/MC/MCDwarf.cpp Fri Nov 23 20:01:08 2012
> @@ -1264,8 +1264,21 @@
>       TranslateMachineLocation(MRI, Moves[i].getDestination());
>     const MachineLocation &Src =
>       TranslateMachineLocation(MRI, Moves[i].getSource());
> -    MCCFIInstruction Inst(Label, Dst, Src);
> -    Instructions.push_back(Inst);
> +
> +    if (Dst.isReg()) {
> +      assert(Dst.getReg() == MachineLocation::VirtualFP);
> +      assert(!Src.isReg());
> +      MCCFIInstruction Inst =
> +        MCCFIInstruction::createDefCfa(Label, Src.getReg(), -Src.getOffset());

The assert(!Src.isReg()) immediately followed by Src.getReg() seems odd. Is it correct? If so, can you add some comments and maybe a message to the asserts explaining what's actually going wrong if they fire?

-Jim

> +      Instructions.push_back(Inst);
> +    } else {
> +      assert(Src.isReg());
> +      unsigned Reg = Src.getReg();
> +      int Offset = Dst.getOffset();
> +      MCCFIInstruction Inst =
> +        MCCFIInstruction::createCFIOffset(Label, Reg, Offset);
> +      Instructions.push_back(Inst);
> +    }
>   }
> 
>   EmitCFIInstructions(streamer, Instructions, NULL);
> 
> Modified: llvm/trunk/lib/MC/MCStreamer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=168532&r1=168531&r2=168532&view=diff
> ==============================================================================
> --- llvm/trunk/lib/MC/MCStreamer.cpp (original)
> +++ llvm/trunk/lib/MC/MCStreamer.cpp Fri Nov 23 20:01:08 2012
> @@ -239,9 +239,8 @@
>   MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
>   MCSymbol *Label = getContext().CreateTempSymbol();
>   EmitLabel(Label);
> -  MachineLocation Dest(MachineLocation::VirtualFP);
> -  MachineLocation Source(Register, -Offset);
> -  MCCFIInstruction Instruction(Label, Dest, Source);
> +  MCCFIInstruction Instruction =
> +    MCCFIInstruction::createDefCfa(Label, Register, Offset);
>   CurFrame->Instructions.push_back(Instruction);
> }
> 
> @@ -250,9 +249,8 @@
>   MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
>   MCSymbol *Label = getContext().CreateTempSymbol();
>   EmitLabel(Label);
> -  MachineLocation Dest(MachineLocation::VirtualFP);
> -  MachineLocation Source(MachineLocation::VirtualFP, -Offset);
> -  MCCFIInstruction Instruction(Label, Dest, Source);
> +  MCCFIInstruction Instruction =
> +    MCCFIInstruction::createDefCfaOffset(Label, Offset);
>   CurFrame->Instructions.push_back(Instruction);
> }
> 
> @@ -261,9 +259,8 @@
>   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);
> +  MCCFIInstruction Instruction =
> +    MCCFIInstruction::createAdjustCfaOffset(Label, Adjustment);
>   CurFrame->Instructions.push_back(Instruction);
> }
> 
> @@ -272,9 +269,8 @@
>   MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
>   MCSymbol *Label = getContext().CreateTempSymbol();
>   EmitLabel(Label);
> -  MachineLocation Dest(Register);
> -  MachineLocation Source(MachineLocation::VirtualFP);
> -  MCCFIInstruction Instruction(Label, Dest, Source);
> +  MCCFIInstruction Instruction =
> +    MCCFIInstruction::createDefCfaRegister(Label, Register);
>   CurFrame->Instructions.push_back(Instruction);
> }
> 
> @@ -283,9 +279,8 @@
>   MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
>   MCSymbol *Label = getContext().CreateTempSymbol();
>   EmitLabel(Label);
> -  MachineLocation Dest(Register, Offset);
> -  MachineLocation Source(Register, Offset);
> -  MCCFIInstruction Instruction(Label, Dest, Source);
> +  MCCFIInstruction Instruction =
> +    MCCFIInstruction::createCFIOffset(Label, Register, Offset);
>   CurFrame->Instructions.push_back(Instruction);
> }
> 
> @@ -294,9 +289,8 @@
>   MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
>   MCSymbol *Label = getContext().CreateTempSymbol();
>   EmitLabel(Label);
> -  MachineLocation Dest(Register, Offset);
> -  MachineLocation Source(Register, Offset);
> -  MCCFIInstruction Instruction(MCCFIInstruction::RelMove, Label, Dest, Source);
> +  MCCFIInstruction Instruction =
> +    MCCFIInstruction::createRelOffset(Label, Register, Offset);
>   CurFrame->Instructions.push_back(Instruction);
> }
> 
> @@ -320,7 +314,7 @@
>   MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
>   MCSymbol *Label = getContext().CreateTempSymbol();
>   EmitLabel(Label);
> -  MCCFIInstruction Instruction(MCCFIInstruction::RememberState, Label);
> +  MCCFIInstruction Instruction = MCCFIInstruction::createRememberState(Label);
>   CurFrame->Instructions.push_back(Instruction);
> }
> 
> @@ -330,7 +324,7 @@
>   MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
>   MCSymbol *Label = getContext().CreateTempSymbol();
>   EmitLabel(Label);
> -  MCCFIInstruction Instruction(MCCFIInstruction::RestoreState, Label);
> +  MCCFIInstruction Instruction = MCCFIInstruction::createRestoreState(Label);
>   CurFrame->Instructions.push_back(Instruction);
> }
> 
> @@ -339,7 +333,8 @@
>   MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
>   MCSymbol *Label = getContext().CreateTempSymbol();
>   EmitLabel(Label);
> -  MCCFIInstruction Instruction(MCCFIInstruction::SameValue, Label, Register);
> +  MCCFIInstruction Instruction =
> +    MCCFIInstruction::createSameValue(Label, Register);
>   CurFrame->Instructions.push_back(Instruction);
> }
> 
> @@ -348,7 +343,8 @@
>   MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
>   MCSymbol *Label = getContext().CreateTempSymbol();
>   EmitLabel(Label);
> -  MCCFIInstruction Instruction(MCCFIInstruction::Restore, Label, Register);
> +  MCCFIInstruction Instruction =
> +    MCCFIInstruction::createRestore(Label, Register);
>   CurFrame->Instructions.push_back(Instruction);
> }
> 
> @@ -357,7 +353,7 @@
>   MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
>   MCSymbol *Label = getContext().CreateTempSymbol();
>   EmitLabel(Label);
> -  MCCFIInstruction Instruction(MCCFIInstruction::Escape, Label, Values);
> +  MCCFIInstruction Instruction = MCCFIInstruction::createEscape(Label, Values);
>   CurFrame->Instructions.push_back(Instruction);
> }
> 
> @@ -372,7 +368,8 @@
>   MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
>   MCSymbol *Label = getContext().CreateTempSymbol();
>   EmitLabel(Label);
> -  MCCFIInstruction Instruction(MCCFIInstruction::Undefined, Label, Register);
> +  MCCFIInstruction Instruction =
> +    MCCFIInstruction::createUndefined(Label, Register);
>   CurFrame->Instructions.push_back(Instruction);
> }
> 
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list