Output exception call-sites in address order, as required by the unwinding

runtime.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37104 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan Sands 2007-05-16 12:12:23 +00:00
parent aeafca0a25
commit 53c3a333a4

View File

@ -13,6 +13,7 @@
#include "llvm/CodeGen/DwarfWriter.h" #include "llvm/CodeGen/DwarfWriter.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/UniqueVector.h" #include "llvm/ADT/UniqueVector.h"
@ -31,6 +32,7 @@
#include "llvm/Target/MRegisterInfo.h" #include "llvm/Target/MRegisterInfo.h"
#include "llvm/Target/TargetData.h" #include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetFrameInfo.h" #include "llvm/Target/TargetFrameInfo.h"
#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h" #include "llvm/Target/TargetOptions.h"
#include <ostream> #include <ostream>
@ -2911,6 +2913,21 @@ private:
/// found the the frame is unwound and handling continues. /// found the the frame is unwound and handling continues.
/// 3. Type id table contains references to all the C++ typeinfo for all /// 3. Type id table contains references to all the C++ typeinfo for all
/// catches in the function. This tables is reversed indexed base 1. /// catches in the function. This tables is reversed indexed base 1.
struct KeyInfo {
static inline unsigned getEmptyKey() { return -1U; }
static inline unsigned getTombstoneKey() { return -2U; }
static unsigned getHashValue(const unsigned &Key) { return Key; }
static bool isPod() { return true; }
};
struct PadSite {
unsigned PadIndex;
unsigned SiteIndex;
};
typedef DenseMap<unsigned, PadSite, KeyInfo> PadMapType;
void EmitExceptionTable() { void EmitExceptionTable() {
// Map all labels and get rid of any dead landing pads. // Map all labels and get rid of any dead landing pads.
MMI->TidyLandingPads(); MMI->TidyLandingPads();
@ -3014,17 +3031,44 @@ private:
Asm->EmitULEB128Bytes(SizeSites); Asm->EmitULEB128Bytes(SizeSites);
Asm->EOL("Call-site table length"); Asm->EOL("Call-site table length");
// Emit the landing pad site information. // Emit the landing pad site information in order of address.
PadMapType PadMap;
for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) { for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
const LandingPadInfo &LandingPad = LandingPads[i]; const LandingPadInfo &LandingPad = LandingPads[i];
for (unsigned j=0, E = LandingPad.BeginLabels.size(); j != E; ++j) { for (unsigned j=0, E = LandingPad.BeginLabels.size(); j != E; ++j) {
EmitSectionOffset("label", "eh_func_begin", unsigned BeginLabel = LandingPad.BeginLabels[j];
LandingPad.BeginLabels[j], SubprogramCount, assert(!PadMap.count(BeginLabel) && "duplicate landing pad labels!");
PadSite P = { i, j };
PadMap[BeginLabel] = P;
}
}
for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
I != E; ++I) {
for (MachineBasicBlock::const_iterator MI = I->begin(), E = I->end();
MI != E; ++MI) {
if (MI->getOpcode() != TargetInstrInfo::LABEL)
continue;
unsigned BeginLabel = MI->getOperand(0).getImmedValue();
PadMapType::iterator L = PadMap.find(BeginLabel);
if (L == PadMap.end())
continue;
PadSite P = L->second;
const LandingPadInfo &LandingPad = LandingPads[P.PadIndex];
assert(BeginLabel == LandingPad.BeginLabels[P.SiteIndex] &&
"Inconsistent landing pad map!");
EmitSectionOffset("label", "eh_func_begin", BeginLabel, SubprogramCount,
false, true); false, true);
Asm->EOL("Region start"); Asm->EOL("Region start");
EmitDifference("label", LandingPad.EndLabels[j], EmitDifference("label", LandingPad.EndLabels[P.SiteIndex],
"label", LandingPad.BeginLabels[j]); "label", BeginLabel);
Asm->EOL("Region length"); Asm->EOL("Region length");
if (LandingPad.TypeIds.empty()) { if (LandingPad.TypeIds.empty()) {
@ -3038,7 +3082,7 @@ private:
} }
Asm->EOL("Landing pad"); Asm->EOL("Landing pad");
Asm->EmitULEB128Bytes(Actions[i]); Asm->EmitULEB128Bytes(Actions[P.PadIndex]);
Asm->EOL("Action"); Asm->EOL("Action");
} }
} }