MC: rename Win64EHFrameInfo to WinEH::FrameInfo

The frame information stored in this structure is driven by the requirements for
Windows NT unwinding rather than Windows 64 specifically.  As a result, this
type can be shared across multiple architectures (ARM, AXP, MIPS, PPC, SH).
Rename this class in preparation for adding support for supporting unwinding
information for Windows on ARM.

Take the opportunity to constify the members as everything except the
ChainedParent is read-only.  This required some adjustment to the label
handling.

llvm-svn: 214663
This commit is contained in:
Saleem Abdulrasool 2014-08-03 18:51:17 +00:00
parent 90c2681a28
commit 7b26bbada1
6 changed files with 78 additions and 50 deletions

View File

@ -181,8 +181,8 @@ class MCStreamer {
MCSymbol *EmitCFICommon();
std::vector<MCWinFrameInfo *> WinFrameInfos;
MCWinFrameInfo *CurrentWinFrameInfo;
std::vector<WinEH::FrameInfo *> WinFrameInfos;
WinEH::FrameInfo *CurrentWinFrameInfo;
void EnsureValidWinFrameInfo();
// SymbolOrdering - Tracks an index to represent the order
@ -204,7 +204,7 @@ protected:
virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
MCWinFrameInfo *getCurrentWinFrameInfo() {
WinEH::FrameInfo *getCurrentWinFrameInfo() {
return CurrentWinFrameInfo;
}
@ -238,7 +238,7 @@ public:
}
unsigned getNumWinFrameInfos() { return WinFrameInfos.size(); }
ArrayRef<MCWinFrameInfo *> getWinFrameInfos() const {
ArrayRef<WinEH::FrameInfo *> getWinFrameInfos() const {
return WinFrameInfos;
}

View File

@ -54,25 +54,6 @@ struct Instruction {
};
}
struct MCWinFrameInfo {
MCWinFrameInfo()
: Begin(nullptr), End(nullptr),ExceptionHandler(nullptr),
Function(nullptr), PrologEnd(nullptr), Symbol(nullptr),
HandlesUnwind(false), HandlesExceptions(false), LastFrameInst(-1),
ChainedParent(nullptr), Instructions() {}
MCSymbol *Begin;
MCSymbol *End;
const MCSymbol *ExceptionHandler;
const MCSymbol *Function;
MCSymbol *PrologEnd;
MCSymbol *Symbol;
bool HandlesUnwind;
bool HandlesExceptions;
int LastFrameInst;
MCWinFrameInfo *ChainedParent;
std::vector<WinEH::Instruction> Instructions;
};
class MCWin64EHUnwindEmitter {
public:
static StringRef GetSectionSuffix(const MCSymbol *func);
@ -80,7 +61,7 @@ struct Instruction {
// This emits the unwind info sections (.pdata and .xdata in PE/COFF).
//
static void Emit(MCStreamer &streamer);
static void EmitUnwindInfo(MCStreamer &streamer, MCWinFrameInfo *info);
static void EmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info);
};
} // end namespace llvm

View File

@ -10,6 +10,8 @@
#ifndef LLVM_MC_MCWINEH_H
#define LLVM_MC_MCWINEH_H
#include <vector>
namespace llvm {
class MCSymbol;
@ -23,6 +25,39 @@ struct Instruction {
Instruction(unsigned Op, MCSymbol *L, unsigned Reg, unsigned Off)
: Label(L), Offset(Off), Register(Reg), Operation(Op) {}
};
struct FrameInfo {
const MCSymbol *Begin;
const MCSymbol *End;
const MCSymbol *ExceptionHandler;
const MCSymbol *Function;
const MCSymbol *PrologEnd;
const MCSymbol *Symbol;
bool HandlesUnwind;
bool HandlesExceptions;
int LastFrameInst;
const FrameInfo *ChainedParent;
std::vector<Instruction> Instructions;
FrameInfo()
: Begin(nullptr), End(nullptr), ExceptionHandler(nullptr),
Function(nullptr), PrologEnd(nullptr), Symbol(nullptr),
HandlesUnwind(false), HandlesExceptions(false), LastFrameInst(-1),
ChainedParent(nullptr), Instructions() {}
FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel)
: Begin(BeginFuncEHLabel), End(nullptr), ExceptionHandler(nullptr),
Function(Function), PrologEnd(nullptr), Symbol(nullptr),
HandlesUnwind(false), HandlesExceptions(false), LastFrameInst(-1),
ChainedParent(nullptr), Instructions() {}
FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel,
const FrameInfo *ChainedParent)
: Begin(BeginFuncEHLabel), End(nullptr), ExceptionHandler(nullptr),
Function(Function), PrologEnd(nullptr), Symbol(nullptr),
HandlesUnwind(false), HandlesExceptions(false), LastFrameInst(-1),
ChainedParent(ChainedParent), Instructions() {}
};
}
}

View File

@ -1109,7 +1109,7 @@ void MCAsmStreamer::EmitWinEHHandlerData() {
// cause the section switch to be visible in the emitted assembly.
// We only do this so the section switch that terminates the handler
// data block is visible.
MCWinFrameInfo *CurFrame = getCurrentWinFrameInfo();
WinEH::FrameInfo *CurFrame = getCurrentWinFrameInfo();
StringRef suffix=MCWin64EHUnwindEmitter::GetSectionSuffix(CurFrame->Function);
const MCSection *xdataSect = getWin64EHTableSection(suffix, getContext());
if (xdataSect)

View File

@ -429,11 +429,11 @@ void MCStreamer::EnsureValidWinFrameInfo() {
void MCStreamer::EmitWinCFIStartProc(const MCSymbol *Symbol) {
if (CurrentWinFrameInfo && !CurrentWinFrameInfo->End)
report_fatal_error("Starting a function before ending the previous one!");
MCWinFrameInfo *Frame = new MCWinFrameInfo;
Frame->Begin = getContext().CreateTempSymbol();
Frame->Function = Symbol;
EmitLabel(Frame->Begin);
WinFrameInfos.push_back(Frame);
MCSymbol *StartProc = getContext().CreateTempSymbol();
EmitLabel(StartProc);
WinFrameInfos.push_back(new WinEH::FrameInfo(Symbol, StartProc));
CurrentWinFrameInfo = WinFrameInfos.back();
}
@ -441,18 +441,20 @@ void MCStreamer::EmitWinCFIEndProc() {
EnsureValidWinFrameInfo();
if (CurrentWinFrameInfo->ChainedParent)
report_fatal_error("Not all chained regions terminated!");
CurrentWinFrameInfo->End = getContext().CreateTempSymbol();
EmitLabel(CurrentWinFrameInfo->End);
MCSymbol *Label = getContext().CreateTempSymbol();
EmitLabel(Label);
CurrentWinFrameInfo->End = Label;
}
void MCStreamer::EmitWinCFIStartChained() {
EnsureValidWinFrameInfo();
MCWinFrameInfo *Frame = new MCWinFrameInfo;
Frame->Begin = getContext().CreateTempSymbol();
Frame->Function = CurrentWinFrameInfo->Function;
Frame->ChainedParent = CurrentWinFrameInfo;
EmitLabel(Frame->Begin);
WinFrameInfos.push_back(Frame);
MCSymbol *StartProc = getContext().CreateTempSymbol();
EmitLabel(StartProc);
WinFrameInfos.push_back(new WinEH::FrameInfo(CurrentWinFrameInfo->Function,
StartProc, CurrentWinFrameInfo));
CurrentWinFrameInfo = WinFrameInfos.back();
}
@ -460,9 +462,13 @@ void MCStreamer::EmitWinCFIEndChained() {
EnsureValidWinFrameInfo();
if (!CurrentWinFrameInfo->ChainedParent)
report_fatal_error("End of a chained region outside a chained region!");
CurrentWinFrameInfo->End = getContext().CreateTempSymbol();
EmitLabel(CurrentWinFrameInfo->End);
CurrentWinFrameInfo = CurrentWinFrameInfo->ChainedParent;
MCSymbol *Label = getContext().CreateTempSymbol();
EmitLabel(Label);
CurrentWinFrameInfo->End = Label;
CurrentWinFrameInfo =
const_cast<WinEH::FrameInfo *>(CurrentWinFrameInfo->ChainedParent);
}
void MCStreamer::EmitWinEHHandler(const MCSymbol *Sym, bool Unwind,
@ -567,8 +573,11 @@ void MCStreamer::EmitWinCFIPushFrame(bool Code) {
void MCStreamer::EmitWinCFIEndProlog() {
EnsureValidWinFrameInfo();
CurrentWinFrameInfo->PrologEnd = getContext().CreateTempSymbol();
EmitLabel(CurrentWinFrameInfo->PrologEnd);
MCSymbol *Label = getContext().CreateTempSymbol();
EmitLabel(Label);
CurrentWinFrameInfo->PrologEnd = Label;
}
void MCStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) {

View File

@ -56,7 +56,7 @@ static void EmitAbsDifference(MCStreamer &Streamer, const MCSymbol *LHS,
Streamer.EmitAbsValue(Diff, 1);
}
static void EmitUnwindCode(MCStreamer &streamer, MCSymbol *begin,
static void EmitUnwindCode(MCStreamer &streamer, const MCSymbol *begin,
WinEH::Instruction &inst) {
uint8_t b2;
uint16_t w;
@ -136,7 +136,7 @@ static void EmitSymbolRefWithOfs(MCStreamer &streamer,
}
static void EmitRuntimeFunction(MCStreamer &streamer,
const MCWinFrameInfo *info) {
const WinEH::FrameInfo *info) {
MCContext &context = streamer.getContext();
streamer.EmitValueToAlignment(4);
@ -147,14 +147,17 @@ static void EmitRuntimeFunction(MCStreamer &streamer,
context), 4);
}
static void EmitUnwindInfo(MCStreamer &streamer, MCWinFrameInfo *info) {
static void EmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info) {
// If this UNWIND_INFO already has a symbol, it's already been emitted.
if (info->Symbol) return;
if (info->Symbol)
return;
MCContext &context = streamer.getContext();
MCSymbol *Label = context.CreateTempSymbol();
streamer.EmitValueToAlignment(4);
info->Symbol = context.CreateTempSymbol();
streamer.EmitLabel(info->Symbol);
streamer.EmitLabel(Label);
info->Symbol = Label;
// Upper 3 bits are the version number (currently 1).
uint8_t flags = 0x01;
@ -256,7 +259,7 @@ static const MCSection *getWin64EHFuncTableSection(StringRef suffix,
}
void MCWin64EHUnwindEmitter::EmitUnwindInfo(MCStreamer &streamer,
MCWinFrameInfo *info) {
WinEH::FrameInfo *info) {
// Switch sections (the static function above is meant to be called from
// here and from Emit().
MCContext &context = streamer.getContext();