[llvm-commits] [llvm] r132177 - in /llvm/trunk: include/llvm/MC/MCWin64EH.h lib/MC/MCStreamer.cpp lib/MC/MCWin64EH.cpp
Charles Davis
cdavis at mines.edu
Thu May 26 20:25:01 PDT 2011
Author: cdavis
Date: Thu May 26 22:25:01 2011
New Revision: 132177
URL: http://llvm.org/viewvc/llvm-project?rev=132177&view=rev
Log:
Start keeping track of where the various unwind instructions are in the prolog.
Use them to calculate the offset inside the prolog. Emit this value when
emitting the unwind codes.
Modified:
llvm/trunk/include/llvm/MC/MCWin64EH.h
llvm/trunk/lib/MC/MCStreamer.cpp
llvm/trunk/lib/MC/MCWin64EH.cpp
Modified: llvm/trunk/include/llvm/MC/MCWin64EH.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCWin64EH.h?rev=132177&r1=132176&r2=132177&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCWin64EH.h (original)
+++ llvm/trunk/include/llvm/MC/MCWin64EH.h Thu May 26 22:25:01 2011
@@ -28,30 +28,31 @@
typedef Win64EH::UnwindOpcodes OpType;
private:
OpType Operation;
+ MCSymbol *Label;
unsigned Offset;
unsigned Register;
public:
- MCWin64EHInstruction(OpType Op, unsigned Reg)
- : Operation(Op), Offset(0), Register(Reg) {
- assert(Op == Win64EH::UOP_PushNonVol);
+ MCWin64EHInstruction(OpType Op, MCSymbol *L, unsigned Reg)
+ : Operation(Op), Label(L), Offset(0), Register(Reg) {
+ assert(Op == Win64EH::UOP_PushNonVol);
}
- MCWin64EHInstruction(unsigned Size)
+ MCWin64EHInstruction(MCSymbol *L, unsigned Size)
: Operation(Size>128 ? Win64EH::UOP_AllocLarge : Win64EH::UOP_AllocSmall),
- Offset(Size) { }
- MCWin64EHInstruction(OpType Op, unsigned Reg,
- unsigned Off)
- : Operation(Op), Offset(Off), Register(Reg) {
+ Label(L), Offset(Size) { }
+ MCWin64EHInstruction(OpType Op, MCSymbol *L, unsigned Reg, unsigned Off)
+ : Operation(Op), Label(L), Offset(Off), Register(Reg) {
assert(Op == Win64EH::UOP_SetFPReg ||
Op == Win64EH::UOP_SaveNonVol ||
Op == Win64EH::UOP_SaveNonVolBig ||
Op == Win64EH::UOP_SaveXMM128 ||
Op == Win64EH::UOP_SaveXMM128Big);
}
- MCWin64EHInstruction(OpType Op, bool Code)
- : Operation(Op), Offset(Code ? 1 : 0) {
+ MCWin64EHInstruction(OpType Op, MCSymbol *L, bool Code)
+ : Operation(Op), Label(L), Offset(Code ? 1 : 0) {
assert(Op == Win64EH::UOP_PushMachFrame);
}
OpType getOperation() const { return Operation; }
+ MCSymbol *getLabel() const { return Label; }
unsigned getOffset() const { return Offset; }
unsigned getSize() const { return Offset; }
unsigned getRegister() const { return Register; }
Modified: llvm/trunk/lib/MC/MCStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=132177&r1=132176&r2=132177&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCStreamer.cpp Thu May 26 22:25:01 2011
@@ -385,7 +385,9 @@
void MCStreamer::EmitWin64EHPushReg(unsigned Register) {
EnsureValidW64UnwindInfo();
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
- MCWin64EHInstruction Inst(Win64EH::UOP_PushNonVol, Register);
+ MCSymbol *Label = getContext().CreateTempSymbol();
+ MCWin64EHInstruction Inst(Win64EH::UOP_PushNonVol, Label, Register);
+ EmitLabel(Label);
CurFrame->Instructions.push_back(Inst);
}
@@ -396,7 +398,7 @@
report_fatal_error("Frame register and offset already specified!");
if (Offset & 0x0F)
report_fatal_error("Misaligned frame pointer offset!");
- MCWin64EHInstruction Inst(Win64EH::UOP_SetFPReg, Register, Offset);
+ MCWin64EHInstruction Inst(Win64EH::UOP_SetFPReg, NULL, Register, Offset);
CurFrame->LastFrameInst = CurFrame->Instructions.size();
CurFrame->Instructions.push_back(Inst);
}
@@ -406,7 +408,9 @@
if (Size & 7)
report_fatal_error("Misaligned stack allocation!");
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
- MCWin64EHInstruction Inst(Size);
+ MCSymbol *Label = getContext().CreateTempSymbol();
+ MCWin64EHInstruction Inst(Label, Size);
+ EmitLabel(Label);
CurFrame->Instructions.push_back(Inst);
}
@@ -415,9 +419,11 @@
if (Offset & 7)
report_fatal_error("Misaligned saved register offset!");
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
+ MCSymbol *Label = getContext().CreateTempSymbol();
MCWin64EHInstruction Inst(
Offset > 512*1024-8 ? Win64EH::UOP_SaveNonVolBig : Win64EH::UOP_SaveNonVol,
- Register, Offset);
+ Label, Register, Offset);
+ EmitLabel(Label);
CurFrame->Instructions.push_back(Inst);
}
@@ -426,9 +432,11 @@
if (Offset & 0x0F)
report_fatal_error("Misaligned saved vector register offset!");
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
+ MCSymbol *Label = getContext().CreateTempSymbol();
MCWin64EHInstruction Inst(
Offset > 512*1024-16 ? Win64EH::UOP_SaveXMM128Big : Win64EH::UOP_SaveXMM128,
- Register, Offset);
+ Label, Register, Offset);
+ EmitLabel(Label);
CurFrame->Instructions.push_back(Inst);
}
@@ -437,7 +445,9 @@
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
if (CurFrame->Instructions.size() > 0)
report_fatal_error("If present, PushMachFrame must be the first UOP");
- MCWin64EHInstruction Inst(Win64EH::UOP_PushMachFrame, Code);
+ MCSymbol *Label = getContext().CreateTempSymbol();
+ MCWin64EHInstruction Inst(Win64EH::UOP_PushMachFrame, Label, Code);
+ EmitLabel(Label);
CurFrame->Instructions.push_back(Inst);
}
Modified: llvm/trunk/lib/MC/MCWin64EH.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCWin64EH.cpp?rev=132177&r1=132176&r2=132177&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCWin64EH.cpp (original)
+++ llvm/trunk/lib/MC/MCWin64EH.cpp Thu May 26 22:25:01 2011
@@ -47,18 +47,31 @@
return count;
}
-static void EmitUnwindCode(MCStreamer &streamer, MCWin64EHInstruction &inst) {
+static void EmitAbsDifference(MCStreamer &streamer, MCSymbol *lhs,
+ MCSymbol *rhs) {
+ MCContext &context = streamer.getContext();
+ const MCExpr *diff = MCBinaryExpr::CreateSub(MCSymbolRefExpr::Create(
+ lhs, context),
+ MCSymbolRefExpr::Create(
+ rhs, context),
+ context);
+ streamer.EmitAbsValue(diff, 1);
+
+}
+
+static void EmitUnwindCode(MCStreamer &streamer, MCSymbol *begin,
+ MCWin64EHInstruction &inst) {
uint8_t b1, b2;
uint16_t w;
b2 = (inst.getOperation() & 0x0F) << 4;
switch (inst.getOperation()) {
case Win64EH::UOP_PushNonVol:
- streamer.EmitIntValue(0, 1);
+ EmitAbsDifference(streamer, inst.getLabel(), begin);
b2 |= inst.getRegister() & 0x0F;
streamer.EmitIntValue(b2, 1);
break;
case Win64EH::UOP_AllocLarge:
- streamer.EmitIntValue(0, 1);
+ EmitAbsDifference(streamer, inst.getLabel(), begin);
if (inst.getSize() > 512*1024-8) {
b2 |= 1;
streamer.EmitIntValue(b2, 1);
@@ -72,8 +85,8 @@
streamer.EmitIntValue(w, 2);
break;
case Win64EH::UOP_AllocSmall:
- b2 |= (inst.getSize() >> 3) & 0x0F;
- streamer.EmitIntValue(0, 1);
+ b2 |= ((inst.getSize()-8) >> 3) & 0x0F;
+ EmitAbsDifference(streamer, inst.getLabel(), begin);
streamer.EmitIntValue(b2, 1);
break;
case Win64EH::UOP_SetFPReg:
@@ -84,7 +97,7 @@
case Win64EH::UOP_SaveNonVol:
case Win64EH::UOP_SaveXMM128:
b2 |= inst.getRegister() & 0x0F;
- streamer.EmitIntValue(0, 1);
+ EmitAbsDifference(streamer, inst.getLabel(), begin);
streamer.EmitIntValue(b2, 1);
w = inst.getOffset() >> 3;
if (inst.getOperation() == Win64EH::UOP_SaveXMM128)
@@ -94,7 +107,7 @@
case Win64EH::UOP_SaveNonVolBig:
case Win64EH::UOP_SaveXMM128Big:
b2 |= inst.getRegister() & 0x0F;
- streamer.EmitIntValue(0, 1);
+ EmitAbsDifference(streamer, inst.getLabel(), begin);
streamer.EmitIntValue(b2, 1);
if (inst.getOperation() == Win64EH::UOP_SaveXMM128Big)
w = inst.getOffset() & 0xFFF0;
@@ -107,7 +120,7 @@
case Win64EH::UOP_PushMachFrame:
if (inst.isPushCodeFrame())
b2 |= 1;
- streamer.EmitIntValue(0, 1);
+ EmitAbsDifference(streamer, inst.getLabel(), begin);
streamer.EmitIntValue(b2, 1);
break;
}
@@ -144,13 +157,7 @@
}
streamer.EmitIntValue(flags, 1);
- // Build up the prolog size expression.
- const MCExpr *prologSize = MCBinaryExpr::CreateSub(MCSymbolRefExpr::Create(
- info->PrologEnd, context),
- MCSymbolRefExpr::Create(
- info->Begin, context),
- context);
- streamer.EmitAbsValue(prologSize, 1);
+ EmitAbsDifference(streamer, info->PrologEnd, info->Begin);
uint8_t numCodes = CountOfUnwindCodes(info->Instructions);
streamer.EmitIntValue(numCodes, 1);
@@ -169,7 +176,7 @@
for (uint8_t c = 0; c < numInst; ++c) {
MCWin64EHInstruction inst = info->Instructions.back();
info->Instructions.pop_back();
- EmitUnwindCode(streamer, inst);
+ EmitUnwindCode(streamer, info->Begin, inst);
}
if (flags & Win64EH::UNW_ChainInfo)
More information about the llvm-commits
mailing list