change EH related stuff (other than EH_LABEL) to use MCSymbol

instead of label ID's.  This cleans up and regularizes a bunch 
of code and makes way for future progress.

Unfortunately, this pointed out to me that JITDwarfEmitter.cpp
is largely copy and paste from DwarfException/MachineModuleInfo
and other places.  This is very sad and disturbing. :(

One major change here is that TidyLandingPads moved from being
called in DwarfException::BeginFunction to being called in
DwarfException::EndFunction.  There should not be any 
functionality change from doing this, but I'm not an EH expert.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98459 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2010-03-14 01:41:15 +00:00
parent bf2d4c034d
commit 1611273351
14 changed files with 139 additions and 159 deletions

View File

@ -35,7 +35,7 @@ class MachineRelocation;
class Value;
class GlobalValue;
class Function;
/// JITCodeEmitter - This class defines two sorts of methods: those for
/// emitting the actual bytes of machine code, and those for emitting auxillary
/// structures, such as jump tables, relocations, etc.
@ -242,7 +242,7 @@ public:
/// emitLabel - Emits a label
virtual void emitLabel(uint64_t LabelID) = 0;
virtual void emitLabel(MCSymbol *Label) = 0;
/// allocateSpace - Allocate a block of space in the current output buffer,
/// returning null (and setting conditions to indicate buffer overflow) on
@ -316,10 +316,10 @@ public:
///
virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) const= 0;
/// getLabelAddress - Return the address of the specified LabelID, only usable
/// after the LabelID has been emitted.
/// getLabelAddress - Return the address of the specified Label, only usable
/// after the Label has been emitted.
///
virtual uintptr_t getLabelAddress(uint64_t LabelID) const = 0;
virtual uintptr_t getLabelAddress(MCSymbol *Label) const = 0;
/// Specifies the MachineModuleInfo object. This is used for exception handling
/// purposes.

View File

@ -31,6 +31,7 @@ class MachineRelocation;
class Value;
class GlobalValue;
class Function;
class MCSymbol;
/// MachineCodeEmitter - This class defines two sorts of methods: those for
/// emitting the actual bytes of machine code, and those for emitting auxillary
@ -247,7 +248,7 @@ public:
virtual void processDebugLoc(DebugLoc DL, bool BeforePrintintInsn) {}
/// emitLabel - Emits a label
virtual void emitLabel(uint64_t LabelID) = 0;
virtual void emitLabel(MCSymbol *Label) = 0;
/// allocateSpace - Allocate a block of space in the current output buffer,
/// returning null (and setting conditions to indicate buffer overflow) on
@ -316,10 +317,10 @@ public:
///
virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) const= 0;
/// getLabelAddress - Return the address of the specified LabelID, only usable
/// getLabelAddress - Return the address of the specified Label, only usable
/// after the LabelID has been emitted.
///
virtual uintptr_t getLabelAddress(uint64_t LabelID) const = 0;
virtual uintptr_t getLabelAddress(MCSymbol *Label) const = 0;
/// Specifies the MachineModuleInfo object. This is used for exception handling
/// purposes.

View File

@ -77,18 +77,15 @@ protected:
/// the current function.
///
struct LandingPadInfo {
MachineBasicBlock *LandingPadBlock; // Landing pad block.
SmallVector<unsigned, 1> BeginLabels; // Labels prior to invoke.
SmallVector<unsigned, 1> EndLabels; // Labels after invoke.
unsigned LandingPadLabel; // Label at beginning of landing pad.
Function *Personality; // Personality function.
std::vector<int> TypeIds; // List of type ids (filters negative)
MachineBasicBlock *LandingPadBlock; // Landing pad block.
SmallVector<MCSymbol*, 1> BeginLabels; // Labels prior to invoke.
SmallVector<MCSymbol*, 1> EndLabels; // Labels after invoke.
MCSymbol *LandingPadLabel; // Label at beginning of landing pad.
Function *Personality; // Personality function.
std::vector<int> TypeIds; // List of type ids (filters negative)
explicit LandingPadInfo(MachineBasicBlock *MBB)
: LandingPadBlock(MBB)
, LandingPadLabel(0)
, Personality(NULL)
{}
: LandingPadBlock(MBB), LandingPadLabel(0), Personality(0) {}
};
//===----------------------------------------------------------------------===//
@ -121,7 +118,7 @@ class MachineModuleInfo : public ImmutablePass {
// Map of invoke call site index values to associated begin EH_LABEL for
// the current function.
DenseMap<unsigned, unsigned> CallSiteMap;
DenseMap<MCSymbol*, unsigned> CallSiteMap;
// The current call site index being processed, if any. 0 if none.
unsigned CurCallSite;
@ -215,6 +212,9 @@ public:
return ID;
}
/// getLabelSym - Turn a label ID into a symbol.
MCSymbol *getLabelSym(unsigned ID);
/// InvalidateLabel - Inhibit use of the specified label # from
/// MachineModuleInfo, for example because the code was deleted.
void InvalidateLabel(unsigned LabelID) {
@ -245,8 +245,8 @@ public:
/// addInvoke - Provide the begin and end labels of an invoke style call and
/// associate it with a try landing pad block.
void addInvoke(MachineBasicBlock *LandingPad, unsigned BeginLabel,
unsigned EndLabel);
void addInvoke(MachineBasicBlock *LandingPad,
MCSymbol *BeginLabel, MCSymbol *EndLabel);
/// addLandingPad - Add a new panding pad. Returns the label ID for the
/// landing pad entry.
@ -305,12 +305,12 @@ public:
}
/// setCallSiteBeginLabel - Map the begin label for a call site
void setCallSiteBeginLabel(unsigned BeginLabel, unsigned Site) {
void setCallSiteBeginLabel(MCSymbol *BeginLabel, unsigned Site) {
CallSiteMap[BeginLabel] = Site;
}
/// getCallSiteBeginLabel - Get the call site number for a begin label
unsigned getCallSiteBeginLabel(unsigned BeginLabel) {
unsigned getCallSiteBeginLabel(MCSymbol *BeginLabel) {
assert(CallSiteMap.count(BeginLabel) &&
"Missing call site number for EH_LABEL!");
return CallSiteMap[BeginLabel];

View File

@ -137,13 +137,6 @@ public:
/// emitted.
virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) const;
/// emitLabel - Emits a label
virtual void emitLabel(uint64_t LabelID) = 0;
/// getLabelAddress - Return the address of the specified LabelID, only usable
/// after the LabelID has been emitted.
virtual uintptr_t getLabelAddress(uint64_t LabelID) const = 0;
/// emitJumpTables - Emit all the jump tables for a given jump table info
/// record to the appropriate section.
virtual void emitJumpTables(MachineJumpTableInfo *MJTI) = 0;

View File

@ -454,7 +454,7 @@ ComputeCallSiteTable(SmallVectorImpl<CallSiteEntry> &CallSites,
const SmallVectorImpl<const LandingPadInfo *> &LandingPads,
const SmallVectorImpl<unsigned> &FirstActions) {
// The end label of the previous invoke or nounwind try-range.
unsigned LastLabel = 0;
MCSymbol *LastLabel = 0;
// Whether there is a potentially throwing instruction (currently this means
// an ordinary call) between the end of the previous try-range and now.
@ -475,8 +475,9 @@ ComputeCallSiteTable(SmallVectorImpl<CallSiteEntry> &CallSites,
continue;
}
unsigned BeginLabel = MI->getOperand(0).getImm();
assert(BeginLabel && "Invalid label!");
unsigned BeginLabelNo = MI->getOperand(0).getImm();
assert(BeginLabelNo && "Invalid label!");
MCSymbol *BeginLabel = getDWLabel("label", BeginLabelNo);
// End of the previous try-range?
if (BeginLabel == LastLabel)
@ -580,7 +581,6 @@ void DwarfException::EmitExceptionTable() {
const std::vector<GlobalVariable *> &TypeInfos = MMI->getTypeInfos();
const std::vector<unsigned> &FilterIds = MMI->getFilterIds();
const std::vector<LandingPadInfo> &PadInfos = MMI->getLandingPads();
if (PadInfos.empty()) return;
// Sort the landing pads in order of their type ids. This is used to fold
// duplicate actions.
@ -605,7 +605,7 @@ void DwarfException::EmitExceptionTable() {
for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
const LandingPadInfo *LandingPad = LandingPads[i];
for (unsigned j = 0, E = LandingPad->BeginLabels.size(); j != E; ++j) {
unsigned BeginLabel = LandingPad->BeginLabels[j];
MCSymbol *BeginLabel = LandingPad->BeginLabels[j];
assert(!PadMap.count(BeginLabel) && "Duplicate landing pad labels!");
PadRange P = { i, j };
PadMap[BeginLabel] = P;
@ -790,45 +790,33 @@ void DwarfException::EmitExceptionTable() {
for (SmallVectorImpl<CallSiteEntry>::const_iterator
I = CallSites.begin(), E = CallSites.end(); I != E; ++I) {
const CallSiteEntry &S = *I;
const char *BeginTag;
unsigned BeginNumber;
if (!S.BeginLabel) {
BeginTag = "eh_func_begin";
BeginNumber = SubprogramCount;
} else {
BeginTag = "label";
BeginNumber = S.BeginLabel;
}
MCSymbol *EHFuncBeginSym = getDWLabel("eh_func_begin", SubprogramCount);
MCSymbol *BeginLabel = S.BeginLabel;
if (BeginLabel == 0)
BeginLabel = EHFuncBeginSym;
MCSymbol *EndLabel = S.EndLabel;
if (EndLabel == 0)
EndLabel = getDWLabel("eh_func_end", SubprogramCount);
// Offset of the call site relative to the previous call site, counted in
// number of 16-byte bundles. The first call site is counted relative to
// the start of the procedure fragment.
Asm->OutStreamer.AddComment("Region start");
EmitSectionOffset(getDWLabel(BeginTag, BeginNumber),
getDWLabel("eh_func_begin", SubprogramCount),
true, true);
EmitSectionOffset(EHFuncBeginSym, EndLabel, true);
Asm->OutStreamer.AddComment("Region length");
if (!S.EndLabel)
EmitDifference(getDWLabel("eh_func_end", SubprogramCount),
getDWLabel(BeginTag, BeginNumber),
true);
else
EmitDifference(getDWLabel("label", S.EndLabel),
getDWLabel(BeginTag, BeginNumber), true);
EmitDifference(EndLabel, BeginLabel, true);
// Offset of the landing pad, counted in 16-byte bundles relative to the
// @LPStart address.
Asm->OutStreamer.AddComment("Landing pad");
if (!S.PadLabel) {
if (!S.PadLabel)
Asm->OutStreamer.EmitIntValue(0, 4/*size*/, 0/*addrspace*/);
} else {
EmitSectionOffset(getDWLabel("label", S.PadLabel),
getDWLabel("eh_func_begin", SubprogramCount),
true, true);
}
else
EmitSectionOffset(S.PadLabel, EHFuncBeginSym, true, true);
// Offset of the first associated action record, relative to the start of
// the action table. This value is biased by 1 (1 indicates the start of
@ -928,16 +916,11 @@ void DwarfException::BeginFunction(const MachineFunction *MF) {
this->MF = MF;
shouldEmitTable = shouldEmitMoves = false;
// Map all labels and get rid of any dead landing pads.
MMI->TidyLandingPads();
// If any landing pads survive, we need an EH table.
if (!MMI->getLandingPads().empty())
shouldEmitTable = true;
shouldEmitTable = !MMI->getLandingPads().empty();
// See if we need frame move info.
if (!MF->getFunction()->doesNotThrow() || UnwindTablesMandatory)
shouldEmitMoves = true;
shouldEmitMoves = !MF->getFunction()->doesNotThrow() || UnwindTablesMandatory;
if (shouldEmitMoves || shouldEmitTable)
// Assumes in correct section after the entry point.
@ -959,7 +942,16 @@ void DwarfException::EndFunction() {
ExceptionTimer->startTimer();
Asm->OutStreamer.EmitLabel(getDWLabel("eh_func_end", SubprogramCount));
EmitExceptionTable();
// Record if this personality index uses a landing pad.
bool HasLandingPad = !MMI->getLandingPads().empty();
UsesLSDA[MMI->getPersonalityIndex()] |= HasLandingPad;
// Map all labels and get rid of any dead landing pads.
MMI->TidyLandingPads();
if (HasLandingPad)
EmitExceptionTable();
const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
MCSymbol *FunctionEHSym =
@ -974,9 +966,6 @@ void DwarfException::EndFunction() {
MMI->getFrameMoves(),
MF->getFunction()));
// Record if this personality index uses a landing pad.
UsesLSDA[MMI->getPersonalityIndex()] |= !MMI->getLandingPads().empty();
if (TimePassesIsEnabled)
ExceptionTimer->stopTimer();
}

View File

@ -111,13 +111,6 @@ class DwarfException : public DwarfPrinter {
/// PadLT - Order landing pads lexicographically by type id.
static bool PadLT(const LandingPadInfo *L, const LandingPadInfo *R);
struct KeyInfo {
static inline unsigned getEmptyKey() { return -1U; }
static inline unsigned getTombstoneKey() { return -2U; }
static unsigned getHashValue(const unsigned &Key) { return Key; }
static bool isEqual(unsigned LHS, unsigned RHS) { return LHS == RHS; }
};
/// PadRange - Structure holding a try-range and the associated landing pad.
struct PadRange {
// The index of the landing pad.
@ -126,7 +119,7 @@ class DwarfException : public DwarfPrinter {
unsigned RangeIndex;
};
typedef DenseMap<unsigned, PadRange, KeyInfo> RangeMapType;
typedef DenseMap<MCSymbol *, PadRange> RangeMapType;
/// ActionEntry - Structure describing an entry in the actions table.
struct ActionEntry {
@ -138,11 +131,11 @@ class DwarfException : public DwarfPrinter {
/// CallSiteEntry - Structure describing an entry in the call-site table.
struct CallSiteEntry {
// The 'try-range' is BeginLabel .. EndLabel.
unsigned BeginLabel; // zero indicates the start of the function.
unsigned EndLabel; // zero indicates the end of the function.
MCSymbol *BeginLabel; // zero indicates the start of the function.
MCSymbol *EndLabel; // zero indicates the end of the function.
// The landing pad starts at PadLabel.
unsigned PadLabel; // zero indicates that there is no landing pad.
MCSymbol *PadLabel; // zero indicates that there is no landing pad.
unsigned Action;
};

View File

@ -57,13 +57,13 @@ namespace llvm {
bool finishFunction(MachineFunction &F);
/// emitLabel - Emits a label
virtual void emitLabel(uint64_t LabelID) {
virtual void emitLabel(MCSymbol *Label) {
assert("emitLabel not implemented");
}
/// getLabelAddress - Return the address of the specified LabelID,
/// only usable after the LabelID has been emitted.
virtual uintptr_t getLabelAddress(uint64_t Label) const {
virtual uintptr_t getLabelAddress(MCSymbol *Label) const {
assert("getLabelAddress not implemented");
return 0;
}

View File

@ -10,6 +10,11 @@
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/GlobalVariable.h"
#include "llvm/Intrinsics.h"
#include "llvm/Instructions.h"
#include "llvm/Module.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineFunction.h"
@ -17,11 +22,8 @@
#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/DerivedTypes.h"
#include "llvm/GlobalVariable.h"
#include "llvm/Intrinsics.h"
#include "llvm/Instructions.h"
#include "llvm/Module.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/ErrorHandling.h"
using namespace llvm;
@ -68,6 +70,12 @@ bool MachineModuleInfo::doFinalization() {
return false;
}
/// getLabelSym - Turn a label ID into a symbol.
MCSymbol *MachineModuleInfo::getLabelSym(unsigned ID) {
return Context.GetOrCreateTemporarySymbol
(Twine(Context.getAsmInfo().getPrivateGlobalPrefix()) + "Label" +Twine(ID));
}
/// EndFunction - Discard function meta information.
///
void MachineModuleInfo::EndFunction() {
@ -123,7 +131,7 @@ LandingPadInfo &MachineModuleInfo::getOrCreateLandingPadInfo
/// addInvoke - Provide the begin and end labels of an invoke style call and
/// associate it with a try landing pad block.
void MachineModuleInfo::addInvoke(MachineBasicBlock *LandingPad,
unsigned BeginLabel, unsigned EndLabel) {
MCSymbol *BeginLabel, MCSymbol *EndLabel) {
LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
LP.BeginLabels.push_back(BeginLabel);
LP.EndLabels.push_back(EndLabel);
@ -132,10 +140,11 @@ void MachineModuleInfo::addInvoke(MachineBasicBlock *LandingPad,
/// addLandingPad - Provide the label of a try LandingPad block.
///
unsigned MachineModuleInfo::addLandingPad(MachineBasicBlock *LandingPad) {
unsigned LandingPadLabel = NextLabelID();
unsigned LandingPadID = NextLabelID();
MCSymbol *LandingPadLabel = getLabelSym(LandingPadID);
LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
LP.LandingPadLabel = LandingPadLabel;
return LandingPadLabel;
return LandingPadID;
}
/// addPersonality - Provide the personality function for the exception
@ -189,7 +198,7 @@ void MachineModuleInfo::addCleanup(MachineBasicBlock *LandingPad) {
void MachineModuleInfo::TidyLandingPads() {
for (unsigned i = 0; i != LandingPads.size(); ) {
LandingPadInfo &LandingPad = LandingPads[i];
if (isLabelDeleted(LandingPad.LandingPadLabel))
if (LandingPad.LandingPadLabel && !LandingPad.LandingPadLabel->isDefined())
LandingPad.LandingPadLabel = 0;
// Special case: we *should* emit LPs with null LP MBB. This indicates
@ -199,16 +208,14 @@ void MachineModuleInfo::TidyLandingPads() {
continue;
}
for (unsigned j=0; j != LandingPads[i].BeginLabels.size(); ) {
unsigned BeginLabel = LandingPad.BeginLabels[j];
unsigned EndLabel = LandingPad.EndLabels[j];
if (isLabelDeleted(BeginLabel) || isLabelDeleted(EndLabel)) {
LandingPad.BeginLabels.erase(LandingPad.BeginLabels.begin() + j);
LandingPad.EndLabels.erase(LandingPad.EndLabels.begin() + j);
continue;
}
++j;
for (unsigned j = 0, e = LandingPads[i].BeginLabels.size(); j != e; ++j) {
MCSymbol *BeginLabel = LandingPad.BeginLabels[j];
MCSymbol *EndLabel = LandingPad.EndLabels[j];
if (BeginLabel->isDefined() && EndLabel->isDefined()) continue;
LandingPad.BeginLabels.erase(LandingPad.BeginLabels.begin() + j);
LandingPad.EndLabels.erase(LandingPad.EndLabels.begin() + j);
--j, --e;
}
// Remove landing pads with no try-ranges.
@ -222,7 +229,6 @@ void MachineModuleInfo::TidyLandingPads() {
if (!LandingPad.LandingPadBlock ||
(LandingPad.TypeIds.size() == 1 && !LandingPad.TypeIds[0]))
LandingPad.TypeIds.clear();
++i;
}
}

View File

@ -4302,7 +4302,7 @@ void SelectionDAGBuilder::LowerCallTo(CallSite CS, SDValue Callee,
const FunctionType *FTy = cast<FunctionType>(PT->getElementType());
const Type *RetTy = FTy->getReturnType();
MachineModuleInfo *MMI = DAG.getMachineModuleInfo();
unsigned BeginLabel = 0, EndLabel = 0;
MCSymbol *BeginLabel = 0;
TargetLowering::ArgListTy Args;
TargetLowering::ArgListEntry Entry;
@ -4362,7 +4362,8 @@ void SelectionDAGBuilder::LowerCallTo(CallSite CS, SDValue Callee,
if (LandingPad && MMI) {
// Insert a label before the invoke call to mark the try range. This can be
// used to detect deletion of the invoke via the MachineModuleInfo.
BeginLabel = MMI->NextLabelID();
unsigned BeginLabelID = MMI->NextLabelID();
BeginLabel = MMI->getLabelSym(BeginLabelID);
// For SjLj, keep track of which landing pads go with which invokes
// so as to maintain the ordering of pads in the LSDA.
@ -4377,7 +4378,7 @@ void SelectionDAGBuilder::LowerCallTo(CallSite CS, SDValue Callee,
// this call might not return.
(void)getRoot();
DAG.setRoot(DAG.getLabel(ISD::EH_LABEL, getCurDebugLoc(),
getControlRoot(), BeginLabel));
getControlRoot(), BeginLabelID));
}
// Check if target-independent constraints permit a tail call here.
@ -4465,9 +4466,10 @@ void SelectionDAGBuilder::LowerCallTo(CallSite CS, SDValue Callee,
if (LandingPad && MMI) {
// Insert a label at the end of the invoke call to mark the try range. This
// can be used to detect deletion of the invoke via the MachineModuleInfo.
EndLabel = MMI->NextLabelID();
unsigned EndLabelID = MMI->NextLabelID();
MCSymbol *EndLabel = MMI->getLabelSym(EndLabelID);
DAG.setRoot(DAG.getLabel(ISD::EH_LABEL, getCurDebugLoc(),
getRoot(), EndLabel));
getRoot(), EndLabelID));
// Inform MachineModuleInfo of range.
MMI->addInvoke(LandingPad, BeginLabel, EndLabel);

View File

@ -23,6 +23,7 @@
#include "llvm/ExecutionEngine/JITMemoryManager.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Target/TargetFrameInfo.h"
@ -73,15 +74,14 @@ JITDwarfEmitter::EmitFrameMoves(intptr_t BaseLabelPtr,
for (unsigned i = 0, N = Moves.size(); i < N; ++i) {
const MachineMove &Move = Moves[i];
unsigned LabelID = Move.getLabelID();
MCSymbol *Label = LabelID ? MMI->getLabelSym(LabelID) : 0;
if (LabelID) {
// Throw out move if the label is invalid.
if (MMI->isLabelDeleted(LabelID))
continue;
}
// Throw out move if the label is invalid.
if (Label && !Label->isDefined())
continue;
intptr_t LabelPtr = 0;
if (LabelID) LabelPtr = JCE->getLabelAddress(LabelID);
if (LabelID) LabelPtr = JCE->getLabelAddress(Label);
const MachineLocation &Dst = Move.getDestination();
const MachineLocation &Src = Move.getSource();
@ -169,13 +169,6 @@ static bool PadLT(const LandingPadInfo *L, const LandingPadInfo *R) {
namespace {
struct KeyInfo {
static inline unsigned getEmptyKey() { return -1U; }
static inline unsigned getTombstoneKey() { return -2U; }
static unsigned getHashValue(const unsigned &Key) { return Key; }
static bool isEqual(unsigned LHS, unsigned RHS) { return LHS == RHS; }
};
/// ActionEntry - Structure describing an entry in the actions table.
struct ActionEntry {
int ValueForTypeID; // The value to write - may not be equal to the type id.
@ -191,13 +184,13 @@ struct PadRange {
unsigned RangeIndex;
};
typedef DenseMap<unsigned, PadRange, KeyInfo> RangeMapType;
typedef DenseMap<MCSymbol*, PadRange> RangeMapType;
/// CallSiteEntry - Structure describing an entry in the call-site table.
struct CallSiteEntry {
unsigned BeginLabel; // zero indicates the start of the function.
unsigned EndLabel; // zero indicates the end of the function.
unsigned PadLabel; // zero indicates that there is no landing pad.
MCSymbol *BeginLabel; // zero indicates the start of the function.
MCSymbol *EndLabel; // zero indicates the end of the function.
MCSymbol *PadLabel; // zero indicates that there is no landing pad.
unsigned Action;
};
@ -308,7 +301,7 @@ unsigned char* JITDwarfEmitter::EmitExceptionTable(MachineFunction* MF,
for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
const LandingPadInfo *LandingPad = LandingPads[i];
for (unsigned j=0, E = LandingPad->BeginLabels.size(); j != E; ++j) {
unsigned BeginLabel = LandingPad->BeginLabels[j];
MCSymbol *BeginLabel = LandingPad->BeginLabels[j];
assert(!PadMap.count(BeginLabel) && "Duplicate landing pad labels!");
PadRange P = { i, j };
PadMap[BeginLabel] = P;
@ -316,7 +309,7 @@ unsigned char* JITDwarfEmitter::EmitExceptionTable(MachineFunction* MF,
}
bool MayThrow = false;
unsigned LastLabel = 0;
MCSymbol *LastLabel = 0;
for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
I != E; ++I) {
for (MachineBasicBlock::const_iterator MI = I->begin(), E = I->end();
@ -326,7 +319,8 @@ unsigned char* JITDwarfEmitter::EmitExceptionTable(MachineFunction* MF,
continue;
}
unsigned BeginLabel = MI->getOperand(0).getImm();
unsigned BeginLabelID = MI->getOperand(0).getImm();
MCSymbol *BeginLabel = MMI->getLabelSym(BeginLabelID);
assert(BeginLabel && "Invalid label!");
if (BeginLabel == LastLabel)
@ -719,15 +713,14 @@ JITDwarfEmitter::GetFrameMovesSizeInBytes(intptr_t BaseLabelPtr,
for (unsigned i = 0, N = Moves.size(); i < N; ++i) {
const MachineMove &Move = Moves[i];
unsigned LabelID = Move.getLabelID();
MCSymbol *Label = LabelID ? MMI->getLabelSym(LabelID) : 0;
if (LabelID) {
// Throw out move if the label is invalid.
if (MMI->isLabelDeleted(LabelID))
continue;
}
// Throw out move if the label is invalid.
if (Label && !Label->isDefined())
continue;
intptr_t LabelPtr = 0;
if (LabelID) LabelPtr = JCE->getLabelAddress(LabelID);
if (LabelID) LabelPtr = JCE->getLabelAddress(Label);
const MachineLocation &Dst = Move.getDestination();
const MachineLocation &Src = Move.getSource();
@ -891,7 +884,7 @@ JITDwarfEmitter::GetExceptionTableSizeInBytes(MachineFunction* MF) const {
for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
const LandingPadInfo *LandingPad = LandingPads[i];
for (unsigned j=0, E = LandingPad->BeginLabels.size(); j != E; ++j) {
unsigned BeginLabel = LandingPad->BeginLabels[j];
MCSymbol *BeginLabel = LandingPad->BeginLabels[j];
assert(!PadMap.count(BeginLabel) && "Duplicate landing pad labels!");
PadRange P = { i, j };
PadMap[BeginLabel] = P;
@ -899,7 +892,7 @@ JITDwarfEmitter::GetExceptionTableSizeInBytes(MachineFunction* MF) const {
}
bool MayThrow = false;
unsigned LastLabel = 0;
MCSymbol *LastLabel = 0;
for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
I != E; ++I) {
for (MachineBasicBlock::const_iterator MI = I->begin(), E = I->end();
@ -909,9 +902,10 @@ JITDwarfEmitter::GetExceptionTableSizeInBytes(MachineFunction* MF) const {
continue;
}
unsigned BeginLabel = MI->getOperand(0).getImm();
assert(BeginLabel && "Invalid label!");
unsigned BeginLabelID = MI->getOperand(0).getImm();
assert(BeginLabelID && "Invalid label!");
MCSymbol *BeginLabel = MMI->getLabelSym(BeginLabelID);
if (BeginLabel == LastLabel)
MayThrow = false;

View File

@ -341,7 +341,7 @@ namespace {
/// LabelLocations - This vector is a mapping from Label ID's to their
/// address.
std::vector<uintptr_t> LabelLocations;
DenseMap<MCSymbol*, uintptr_t> LabelLocations;
/// MMI - Machine module info for exception informations
MachineModuleInfo* MMI;
@ -459,16 +459,13 @@ namespace {
virtual void processDebugLoc(DebugLoc DL, bool BeforePrintingInsn);
virtual void emitLabel(uint64_t LabelID) {
if (LabelLocations.size() <= LabelID)
LabelLocations.resize((LabelID+1)*2);
LabelLocations[LabelID] = getCurrentPCValue();
virtual void emitLabel(MCSymbol *Label) {
LabelLocations[Label] = getCurrentPCValue();
}
virtual uintptr_t getLabelAddress(uint64_t LabelID) const {
assert(LabelLocations.size() > (unsigned)LabelID &&
LabelLocations[LabelID] && "Label not emitted!");
return LabelLocations[LabelID];
virtual uintptr_t getLabelAddress(MCSymbol *Label) const {
assert(LabelLocations.count(Label) && "Label not emitted!");
return LabelLocations.find(Label)->second;
}
virtual void setModuleInfo(MachineModuleInfo* Info) {

View File

@ -51,6 +51,7 @@ namespace {
const ARMSubtarget *Subtarget;
TargetMachine &TM;
JITCodeEmitter &MCE;
MachineModuleInfo *MMI;
const std::vector<MachineConstantPoolEntry> *MCPEs;
const std::vector<MachineJumpTableEntry> *MJTEs;
bool IsPIC;
@ -182,7 +183,8 @@ bool ARMCodeEmitter::runOnMachineFunction(MachineFunction &MF) {
if (MF.getJumpTableInfo()) MJTEs = &MF.getJumpTableInfo()->getJumpTables();
IsPIC = TM.getRelocationModel() == Reloc::PIC_;
JTI->Initialize(MF, IsPIC);
MCE.setModuleInfo(&getAnalysis<MachineModuleInfo>());
MMI = &getAnalysis<MachineModuleInfo>();
MCE.setModuleInfo(MMI);
do {
DEBUG(errs() << "JITTing function '"
@ -563,7 +565,7 @@ void ARMCodeEmitter::emitPseudoInstruction(const MachineInstr &MI) {
}
case TargetOpcode::DBG_LABEL:
case TargetOpcode::EH_LABEL:
MCE.emitLabel(MI.getOperand(0).getImm());
MCE.emitLabel(MMI->getLabelSym(MI.getOperand(0).getImm()));
break;
case TargetOpcode::IMPLICIT_DEF:
case TargetOpcode::KILL:

View File

@ -30,6 +30,7 @@ namespace {
class PPCCodeEmitter : public MachineFunctionPass {
TargetMachine &TM;
JITCodeEmitter &MCE;
MachineModuleInfo *MMI;
void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<MachineModuleInfo>();
@ -87,7 +88,8 @@ bool PPCCodeEmitter::runOnMachineFunction(MachineFunction &MF) {
MF.getTarget().getRelocationModel() != Reloc::Static) &&
"JIT relocation model must be set to static or default!");
MCE.setModuleInfo(&getAnalysis<MachineModuleInfo>());
MMI = &getAnalysis<MachineModuleInfo>();
MCE.setModuleInfo(MMI);
do {
MovePCtoLROffset = 0;
MCE.startFunction(MF);
@ -110,7 +112,7 @@ void PPCCodeEmitter::emitBasicBlock(MachineBasicBlock &MBB) {
break;
case TargetOpcode::DBG_LABEL:
case TargetOpcode::EH_LABEL:
MCE.emitLabel(MI.getOperand(0).getImm());
MCE.emitLabel(MMI->getLabelSym(MI.getOperand(0).getImm()));
break;
case TargetOpcode::IMPLICIT_DEF:
case TargetOpcode::KILL:

View File

@ -46,6 +46,7 @@ namespace {
const TargetData *TD;
X86TargetMachine &TM;
CodeEmitter &MCE;
MachineModuleInfo *MMI;
intptr_t PICBaseOffset;
bool Is64BitMode;
bool IsPIC;
@ -115,8 +116,8 @@ FunctionPass *llvm::createX86JITCodeEmitterPass(X86TargetMachine &TM,
template<class CodeEmitter>
bool Emitter<CodeEmitter>::runOnMachineFunction(MachineFunction &MF) {
MCE.setModuleInfo(&getAnalysis<MachineModuleInfo>());
MMI = &getAnalysis<MachineModuleInfo>();
MCE.setModuleInfo(MMI);
II = TM.getInstrInfo();
TD = TM.getTargetData();
@ -604,7 +605,7 @@ void Emitter<CodeEmitter>::emitInstruction(const MachineInstr &MI,
case TargetOpcode::DBG_LABEL:
case TargetOpcode::EH_LABEL:
case TargetOpcode::GC_LABEL:
MCE.emitLabel(MI.getOperand(0).getImm());
MCE.emitLabel(MMI->getLabelSym(MI.getOperand(0).getImm()));
break;
case TargetOpcode::IMPLICIT_DEF:
case TargetOpcode::KILL: