2008-02-13 18:39:37 +00:00
|
|
|
//===----- JITDwarfEmitter.cpp - Write dwarf tables into memory -----------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines a JITDwarfEmitter object that is used by the JIT to
|
|
|
|
// write dwarf tables to memory.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "JIT.h"
|
|
|
|
#include "JITDwarfEmitter.h"
|
|
|
|
#include "llvm/Function.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2009-05-30 20:51:52 +00:00
|
|
|
#include "llvm/CodeGen/JITCodeEmitter.h"
|
2008-02-13 18:39:37 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineLocation.h"
|
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
|
|
|
#include "llvm/ExecutionEngine/JITMemoryManager.h"
|
2009-07-11 20:10:48 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-08-22 20:48:53 +00:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2010-03-14 01:41:15 +00:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2008-02-13 18:39:37 +00:00
|
|
|
#include "llvm/Target/TargetData.h"
|
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
|
|
|
#include "llvm/Target/TargetFrameInfo.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
2009-09-21 05:58:35 +00:00
|
|
|
JITDwarfEmitter::JITDwarfEmitter(JIT& theJit) : MMI(0), Jit(theJit) {}
|
2008-02-13 18:39:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
unsigned char* JITDwarfEmitter::EmitDwarfTable(MachineFunction& F,
|
2009-05-30 20:51:52 +00:00
|
|
|
JITCodeEmitter& jce,
|
2008-02-13 18:39:37 +00:00
|
|
|
unsigned char* StartFunction,
|
Implement the JIT side of the GDB JIT debugging interface. To enable this
feature, either build the JIT in debug mode to enable it by default or pass
-jit-emit-debug to lli.
Right now, the only debug information that this communicates to GDB is call
frame information, since it's already being generated to support exceptions in
the JIT. Eventually, when DWARF generation isn't tied so tightly to AsmPrinter,
it will be easy to push that information to GDB through this interface.
Here's a step-by-step breakdown of how the feature works:
- The JIT generates the machine code and DWARF call frame info
(.eh_frame/.debug_frame) for a function into memory.
- The JIT copies that info into an in-memory ELF file with a symbol for the
function.
- The JIT creates a code entry pointing to the ELF buffer and adds it to a
linked list hanging off of a global descriptor at a special symbol that GDB
knows about.
- The JIT calls a function marked noinline that GDB knows about and has put an
internal breakpoint in.
- GDB catches the breakpoint and reads the global descriptor to look for new
code.
- When sees there is new code, it reads the ELF from the inferior's memory and
adds it to itself as an object file.
- The JIT continues, and the next time we stop the program, we are able to
produce a proper backtrace.
Consider running the following program through the JIT:
#include <stdio.h>
void baz(short z) {
long w = z + 1;
printf("%d, %x\n", w, *((int*)NULL)); // SEGFAULT here
}
void bar(short y) {
int z = y + 1;
baz(z);
}
void foo(char x) {
short y = x + 1;
bar(y);
}
int main(int argc, char** argv) {
char x = 1;
foo(x);
}
Here is a backtrace before this patch:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x2aaaabdfbd10 (LWP 25476)]
0x00002aaaabe7d1a8 in ?? ()
(gdb) bt
#0 0x00002aaaabe7d1a8 in ?? ()
#1 0x0000000000000003 in ?? ()
#2 0x0000000000000004 in ?? ()
#3 0x00032aaaabe7cfd0 in ?? ()
#4 0x00002aaaabe7d12c in ?? ()
#5 0x00022aaa00000003 in ?? ()
#6 0x00002aaaabe7d0aa in ?? ()
#7 0x01000002abe7cff0 in ?? ()
#8 0x00002aaaabe7d02c in ?? ()
#9 0x0100000000000001 in ?? ()
#10 0x00000000014388e0 in ?? ()
#11 0x00007fff00000001 in ?? ()
#12 0x0000000000b870a2 in llvm::JIT::runFunction (this=0x1405b70,
F=0x14024e0, ArgValues=@0x7fffffffe050)
at /home/rnk/llvm-gdb/lib/ExecutionEngine/JIT/JIT.cpp:395
#13 0x0000000000baa4c5 in llvm::ExecutionEngine::runFunctionAsMain
(this=0x1405b70, Fn=0x14024e0, argv=@0x13f06f8, envp=0x7fffffffe3b0)
at /home/rnk/llvm-gdb/lib/ExecutionEngine/ExecutionEngine.cpp:377
#14 0x00000000007ebd52 in main (argc=2, argv=0x7fffffffe398,
envp=0x7fffffffe3b0) at /home/rnk/llvm-gdb/tools/lli/lli.cpp:208
And a backtrace after this patch:
Program received signal SIGSEGV, Segmentation fault.
0x00002aaaabe7d1a8 in baz ()
(gdb) bt
#0 0x00002aaaabe7d1a8 in baz ()
#1 0x00002aaaabe7d12c in bar ()
#2 0x00002aaaabe7d0aa in foo ()
#3 0x00002aaaabe7d02c in main ()
#4 0x0000000000b870a2 in llvm::JIT::runFunction (this=0x1405b70,
F=0x14024e0, ArgValues=...)
at /home/rnk/llvm-gdb/lib/ExecutionEngine/JIT/JIT.cpp:395
#5 0x0000000000baa4c5 in llvm::ExecutionEngine::runFunctionAsMain
(this=0x1405b70, Fn=0x14024e0, argv=..., envp=0x7fffffffe3c0)
at /home/rnk/llvm-gdb/lib/ExecutionEngine/ExecutionEngine.cpp:377
#6 0x00000000007ebd52 in main (argc=2, argv=0x7fffffffe3a8,
envp=0x7fffffffe3c0) at /home/rnk/llvm-gdb/tools/lli/lli.cpp:208
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82418 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-20 23:52:43 +00:00
|
|
|
unsigned char* EndFunction,
|
|
|
|
unsigned char* &EHFramePtr) {
|
2009-09-21 05:58:35 +00:00
|
|
|
assert(MMI && "MachineModuleInfo not registered!");
|
|
|
|
|
2008-02-13 18:39:37 +00:00
|
|
|
const TargetMachine& TM = F.getTarget();
|
|
|
|
TD = TM.getTargetData();
|
|
|
|
stackGrowthDirection = TM.getFrameInfo()->getStackGrowthDirection();
|
|
|
|
RI = TM.getRegisterInfo();
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE = &jce;
|
2008-02-13 18:39:37 +00:00
|
|
|
|
|
|
|
unsigned char* ExceptionTable = EmitExceptionTable(&F, StartFunction,
|
|
|
|
EndFunction);
|
|
|
|
|
|
|
|
unsigned char* Result = 0;
|
|
|
|
|
2010-04-15 01:51:59 +00:00
|
|
|
const std::vector<const Function *> Personalities = MMI->getPersonalities();
|
2008-02-13 18:39:37 +00:00
|
|
|
EHFramePtr = EmitCommonEHFrame(Personalities[MMI->getPersonalityIndex()]);
|
|
|
|
|
|
|
|
Result = EmitEHFrame(Personalities[MMI->getPersonalityIndex()], EHFramePtr,
|
|
|
|
StartFunction, EndFunction, ExceptionTable);
|
2009-09-09 00:11:02 +00:00
|
|
|
|
2008-02-13 18:39:37 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-20 17:44:19 +00:00
|
|
|
void
|
|
|
|
JITDwarfEmitter::EmitFrameMoves(intptr_t BaseLabelPtr,
|
|
|
|
const std::vector<MachineMove> &Moves) const {
|
2008-02-13 18:39:37 +00:00
|
|
|
unsigned PointerSize = TD->getPointerSize();
|
|
|
|
int stackGrowth = stackGrowthDirection == TargetFrameInfo::StackGrowsUp ?
|
|
|
|
PointerSize : -PointerSize;
|
2010-03-14 08:12:40 +00:00
|
|
|
MCSymbol *BaseLabel = 0;
|
2008-02-13 18:39:37 +00:00
|
|
|
|
|
|
|
for (unsigned i = 0, N = Moves.size(); i < N; ++i) {
|
|
|
|
const MachineMove &Move = Moves[i];
|
2010-03-14 08:12:40 +00:00
|
|
|
MCSymbol *Label = Move.getLabel();
|
2008-02-13 18:39:37 +00:00
|
|
|
|
2010-03-14 01:41:15 +00:00
|
|
|
// Throw out move if the label is invalid.
|
2010-04-18 00:56:05 +00:00
|
|
|
if (Label && (*JCE->getLabelLocations())[Label] == 0)
|
2010-03-14 01:41:15 +00:00
|
|
|
continue;
|
2008-02-13 18:39:37 +00:00
|
|
|
|
|
|
|
intptr_t LabelPtr = 0;
|
2010-03-14 08:12:40 +00:00
|
|
|
if (Label) LabelPtr = JCE->getLabelAddress(Label);
|
2008-02-13 18:39:37 +00:00
|
|
|
|
|
|
|
const MachineLocation &Dst = Move.getDestination();
|
|
|
|
const MachineLocation &Src = Move.getSource();
|
|
|
|
|
|
|
|
// Advance row if new location.
|
2010-03-14 08:12:40 +00:00
|
|
|
if (BaseLabelPtr && Label && BaseLabel != Label) {
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitByte(dwarf::DW_CFA_advance_loc4);
|
|
|
|
JCE->emitInt32(LabelPtr - BaseLabelPtr);
|
2008-02-13 18:39:37 +00:00
|
|
|
|
2010-03-14 08:12:40 +00:00
|
|
|
BaseLabel = Label;
|
2008-02-13 18:39:37 +00:00
|
|
|
BaseLabelPtr = LabelPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If advancing cfa.
|
2008-10-03 17:11:57 +00:00
|
|
|
if (Dst.isReg() && Dst.getReg() == MachineLocation::VirtualFP) {
|
|
|
|
if (!Src.isReg()) {
|
|
|
|
if (Src.getReg() == MachineLocation::VirtualFP) {
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitByte(dwarf::DW_CFA_def_cfa_offset);
|
2008-02-13 18:39:37 +00:00
|
|
|
} else {
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitByte(dwarf::DW_CFA_def_cfa);
|
|
|
|
JCE->emitULEB128Bytes(RI->getDwarfRegNum(Src.getReg(), true));
|
2008-02-13 18:39:37 +00:00
|
|
|
}
|
|
|
|
|
2009-09-09 00:11:02 +00:00
|
|
|
JCE->emitULEB128Bytes(-Src.getOffset());
|
2008-02-13 18:39:37 +00:00
|
|
|
} else {
|
2009-09-09 00:11:02 +00:00
|
|
|
llvm_unreachable("Machine move not supported yet.");
|
2008-02-13 18:39:37 +00:00
|
|
|
}
|
2008-10-03 17:11:57 +00:00
|
|
|
} else if (Src.isReg() &&
|
|
|
|
Src.getReg() == MachineLocation::VirtualFP) {
|
|
|
|
if (Dst.isReg()) {
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitByte(dwarf::DW_CFA_def_cfa_register);
|
|
|
|
JCE->emitULEB128Bytes(RI->getDwarfRegNum(Dst.getReg(), true));
|
2008-02-13 18:39:37 +00:00
|
|
|
} else {
|
2009-09-09 00:11:02 +00:00
|
|
|
llvm_unreachable("Machine move not supported yet.");
|
2008-02-13 18:39:37 +00:00
|
|
|
}
|
|
|
|
} else {
|
2008-10-03 17:11:57 +00:00
|
|
|
unsigned Reg = RI->getDwarfRegNum(Src.getReg(), true);
|
2008-02-13 18:39:37 +00:00
|
|
|
int Offset = Dst.getOffset() / stackGrowth;
|
|
|
|
|
|
|
|
if (Offset < 0) {
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitByte(dwarf::DW_CFA_offset_extended_sf);
|
|
|
|
JCE->emitULEB128Bytes(Reg);
|
|
|
|
JCE->emitSLEB128Bytes(Offset);
|
2008-02-13 18:39:37 +00:00
|
|
|
} else if (Reg < 64) {
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitByte(dwarf::DW_CFA_offset + Reg);
|
|
|
|
JCE->emitULEB128Bytes(Offset);
|
2008-02-13 18:39:37 +00:00
|
|
|
} else {
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitByte(dwarf::DW_CFA_offset_extended);
|
|
|
|
JCE->emitULEB128Bytes(Reg);
|
|
|
|
JCE->emitULEB128Bytes(Offset);
|
2008-02-13 18:39:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// SharedTypeIds - How many leading type ids two landing pads have in common.
|
|
|
|
static unsigned SharedTypeIds(const LandingPadInfo *L,
|
|
|
|
const LandingPadInfo *R) {
|
|
|
|
const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds;
|
|
|
|
unsigned LSize = LIds.size(), RSize = RIds.size();
|
|
|
|
unsigned MinSize = LSize < RSize ? LSize : RSize;
|
|
|
|
unsigned Count = 0;
|
|
|
|
|
|
|
|
for (; Count != MinSize; ++Count)
|
|
|
|
if (LIds[Count] != RIds[Count])
|
|
|
|
return Count;
|
|
|
|
|
|
|
|
return Count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// PadLT - Order landing pads lexicographically by type id.
|
|
|
|
static bool PadLT(const LandingPadInfo *L, const LandingPadInfo *R) {
|
|
|
|
const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds;
|
|
|
|
unsigned LSize = LIds.size(), RSize = RIds.size();
|
|
|
|
unsigned MinSize = LSize < RSize ? LSize : RSize;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i != MinSize; ++i)
|
|
|
|
if (LIds[i] != RIds[i])
|
|
|
|
return LIds[i] < RIds[i];
|
|
|
|
|
|
|
|
return LSize < RSize;
|
|
|
|
}
|
|
|
|
|
2008-05-13 00:00:25 +00:00
|
|
|
namespace {
|
|
|
|
|
2008-02-13 18:39:37 +00:00
|
|
|
/// 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.
|
|
|
|
int NextAction;
|
|
|
|
struct ActionEntry *Previous;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// PadRange - Structure holding a try-range and the associated landing pad.
|
|
|
|
struct PadRange {
|
|
|
|
// The index of the landing pad.
|
|
|
|
unsigned PadIndex;
|
|
|
|
// The index of the begin and end labels in the landing pad's label lists.
|
|
|
|
unsigned RangeIndex;
|
|
|
|
};
|
|
|
|
|
2010-03-14 01:41:15 +00:00
|
|
|
typedef DenseMap<MCSymbol*, PadRange> RangeMapType;
|
2008-02-13 18:39:37 +00:00
|
|
|
|
|
|
|
/// CallSiteEntry - Structure describing an entry in the call-site table.
|
|
|
|
struct CallSiteEntry {
|
2010-03-14 01:41:15 +00:00
|
|
|
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.
|
2008-02-13 18:39:37 +00:00
|
|
|
unsigned Action;
|
|
|
|
};
|
|
|
|
|
2008-05-13 00:00:25 +00:00
|
|
|
}
|
|
|
|
|
2008-02-13 18:39:37 +00:00
|
|
|
unsigned char* JITDwarfEmitter::EmitExceptionTable(MachineFunction* MF,
|
|
|
|
unsigned char* StartFunction,
|
2008-04-20 17:44:19 +00:00
|
|
|
unsigned char* EndFunction) const {
|
2009-09-21 05:58:35 +00:00
|
|
|
assert(MMI && "MachineModuleInfo not registered!");
|
|
|
|
|
2008-02-13 18:39:37 +00:00
|
|
|
// Map all labels and get rid of any dead landing pads.
|
2010-04-16 08:46:10 +00:00
|
|
|
MMI->TidyLandingPads(JCE->getLabelLocations());
|
2008-02-13 18:39:37 +00:00
|
|
|
|
2010-04-15 01:51:59 +00:00
|
|
|
const std::vector<const GlobalVariable *> &TypeInfos = MMI->getTypeInfos();
|
2008-02-13 18:39:37 +00:00
|
|
|
const std::vector<unsigned> &FilterIds = MMI->getFilterIds();
|
|
|
|
const std::vector<LandingPadInfo> &PadInfos = MMI->getLandingPads();
|
|
|
|
if (PadInfos.empty()) return 0;
|
|
|
|
|
|
|
|
// Sort the landing pads in order of their type ids. This is used to fold
|
|
|
|
// duplicate actions.
|
|
|
|
SmallVector<const LandingPadInfo *, 64> LandingPads;
|
|
|
|
LandingPads.reserve(PadInfos.size());
|
|
|
|
for (unsigned i = 0, N = PadInfos.size(); i != N; ++i)
|
|
|
|
LandingPads.push_back(&PadInfos[i]);
|
|
|
|
std::sort(LandingPads.begin(), LandingPads.end(), PadLT);
|
|
|
|
|
|
|
|
// Negative type ids index into FilterIds, positive type ids index into
|
|
|
|
// TypeInfos. The value written for a positive type id is just the type
|
|
|
|
// id itself. For a negative type id, however, the value written is the
|
|
|
|
// (negative) byte offset of the corresponding FilterIds entry. The byte
|
|
|
|
// offset is usually equal to the type id, because the FilterIds entries
|
|
|
|
// are written using a variable width encoding which outputs one byte per
|
|
|
|
// entry as long as the value written is not too large, but can differ.
|
|
|
|
// This kind of complication does not occur for positive type ids because
|
|
|
|
// type infos are output using a fixed width encoding.
|
|
|
|
// FilterOffsets[i] holds the byte offset corresponding to FilterIds[i].
|
|
|
|
SmallVector<int, 16> FilterOffsets;
|
|
|
|
FilterOffsets.reserve(FilterIds.size());
|
|
|
|
int Offset = -1;
|
|
|
|
for(std::vector<unsigned>::const_iterator I = FilterIds.begin(),
|
|
|
|
E = FilterIds.end(); I != E; ++I) {
|
|
|
|
FilterOffsets.push_back(Offset);
|
2009-08-22 20:48:53 +00:00
|
|
|
Offset -= MCAsmInfo::getULEB128Size(*I);
|
2008-02-13 18:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the actions table and gather the first action index for each
|
|
|
|
// landing pad site.
|
|
|
|
SmallVector<ActionEntry, 32> Actions;
|
|
|
|
SmallVector<unsigned, 64> FirstActions;
|
|
|
|
FirstActions.reserve(LandingPads.size());
|
|
|
|
|
|
|
|
int FirstAction = 0;
|
|
|
|
unsigned SizeActions = 0;
|
|
|
|
for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
|
|
|
|
const LandingPadInfo *LP = LandingPads[i];
|
|
|
|
const std::vector<int> &TypeIds = LP->TypeIds;
|
|
|
|
const unsigned NumShared = i ? SharedTypeIds(LP, LandingPads[i-1]) : 0;
|
|
|
|
unsigned SizeSiteActions = 0;
|
|
|
|
|
|
|
|
if (NumShared < TypeIds.size()) {
|
|
|
|
unsigned SizeAction = 0;
|
|
|
|
ActionEntry *PrevAction = 0;
|
|
|
|
|
|
|
|
if (NumShared) {
|
|
|
|
const unsigned SizePrevIds = LandingPads[i-1]->TypeIds.size();
|
|
|
|
assert(Actions.size());
|
|
|
|
PrevAction = &Actions.back();
|
2009-08-22 20:48:53 +00:00
|
|
|
SizeAction = MCAsmInfo::getSLEB128Size(PrevAction->NextAction) +
|
|
|
|
MCAsmInfo::getSLEB128Size(PrevAction->ValueForTypeID);
|
2008-02-13 18:39:37 +00:00
|
|
|
for (unsigned j = NumShared; j != SizePrevIds; ++j) {
|
2009-08-22 20:48:53 +00:00
|
|
|
SizeAction -= MCAsmInfo::getSLEB128Size(PrevAction->ValueForTypeID);
|
2008-02-13 18:39:37 +00:00
|
|
|
SizeAction += -PrevAction->NextAction;
|
|
|
|
PrevAction = PrevAction->Previous;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the actions.
|
|
|
|
for (unsigned I = NumShared, M = TypeIds.size(); I != M; ++I) {
|
|
|
|
int TypeID = TypeIds[I];
|
|
|
|
assert(-1-TypeID < (int)FilterOffsets.size() && "Unknown filter id!");
|
|
|
|
int ValueForTypeID = TypeID < 0 ? FilterOffsets[-1 - TypeID] : TypeID;
|
2009-08-22 20:48:53 +00:00
|
|
|
unsigned SizeTypeID = MCAsmInfo::getSLEB128Size(ValueForTypeID);
|
2008-02-13 18:39:37 +00:00
|
|
|
|
|
|
|
int NextAction = SizeAction ? -(SizeAction + SizeTypeID) : 0;
|
2009-08-22 20:48:53 +00:00
|
|
|
SizeAction = SizeTypeID + MCAsmInfo::getSLEB128Size(NextAction);
|
2008-02-13 18:39:37 +00:00
|
|
|
SizeSiteActions += SizeAction;
|
|
|
|
|
|
|
|
ActionEntry Action = {ValueForTypeID, NextAction, PrevAction};
|
|
|
|
Actions.push_back(Action);
|
|
|
|
|
|
|
|
PrevAction = &Actions.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Record the first action of the landing pad site.
|
|
|
|
FirstAction = SizeActions + SizeSiteActions - SizeAction + 1;
|
|
|
|
} // else identical - re-use previous FirstAction
|
|
|
|
|
|
|
|
FirstActions.push_back(FirstAction);
|
|
|
|
|
|
|
|
// Compute this sites contribution to size.
|
|
|
|
SizeActions += SizeSiteActions;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the call-site table. Entries must be ordered by address.
|
|
|
|
SmallVector<CallSiteEntry, 64> CallSites;
|
|
|
|
|
|
|
|
RangeMapType PadMap;
|
|
|
|
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) {
|
2010-03-14 01:41:15 +00:00
|
|
|
MCSymbol *BeginLabel = LandingPad->BeginLabels[j];
|
2008-02-13 18:39:37 +00:00
|
|
|
assert(!PadMap.count(BeginLabel) && "Duplicate landing pad labels!");
|
|
|
|
PadRange P = { i, j };
|
|
|
|
PadMap[BeginLabel] = P;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MayThrow = false;
|
2010-03-14 01:41:15 +00:00
|
|
|
MCSymbol *LastLabel = 0;
|
2008-02-13 18:39:37 +00:00
|
|
|
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) {
|
2008-07-01 00:05:16 +00:00
|
|
|
if (!MI->isLabel()) {
|
2008-02-13 18:39:37 +00:00
|
|
|
MayThrow |= MI->getDesc().isCall();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-03-14 08:28:48 +00:00
|
|
|
MCSymbol *BeginLabel = MI->getOperand(0).getMCSymbol();
|
2008-02-13 18:39:37 +00:00
|
|
|
assert(BeginLabel && "Invalid label!");
|
|
|
|
|
|
|
|
if (BeginLabel == LastLabel)
|
|
|
|
MayThrow = false;
|
|
|
|
|
|
|
|
RangeMapType::iterator L = PadMap.find(BeginLabel);
|
|
|
|
|
|
|
|
if (L == PadMap.end())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
PadRange P = L->second;
|
|
|
|
const LandingPadInfo *LandingPad = LandingPads[P.PadIndex];
|
|
|
|
|
|
|
|
assert(BeginLabel == LandingPad->BeginLabels[P.RangeIndex] &&
|
|
|
|
"Inconsistent landing pad map!");
|
|
|
|
|
|
|
|
// If some instruction between the previous try-range and this one may
|
|
|
|
// throw, create a call-site entry with no landing pad for the region
|
|
|
|
// between the try-ranges.
|
|
|
|
if (MayThrow) {
|
|
|
|
CallSiteEntry Site = {LastLabel, BeginLabel, 0, 0};
|
|
|
|
CallSites.push_back(Site);
|
|
|
|
}
|
|
|
|
|
|
|
|
LastLabel = LandingPad->EndLabels[P.RangeIndex];
|
|
|
|
CallSiteEntry Site = {BeginLabel, LastLabel,
|
|
|
|
LandingPad->LandingPadLabel, FirstActions[P.PadIndex]};
|
|
|
|
|
|
|
|
assert(Site.BeginLabel && Site.EndLabel && Site.PadLabel &&
|
|
|
|
"Invalid landing pad!");
|
|
|
|
|
|
|
|
// Try to merge with the previous call-site.
|
|
|
|
if (CallSites.size()) {
|
2008-06-21 22:00:54 +00:00
|
|
|
CallSiteEntry &Prev = CallSites.back();
|
2008-02-13 18:39:37 +00:00
|
|
|
if (Site.PadLabel == Prev.PadLabel && Site.Action == Prev.Action) {
|
|
|
|
// Extend the range of the previous entry.
|
|
|
|
Prev.EndLabel = Site.EndLabel;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, create a new call-site.
|
|
|
|
CallSites.push_back(Site);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If some instruction between the previous try-range and the end of the
|
|
|
|
// function may throw, create a call-site entry with no landing pad for the
|
|
|
|
// region following the try-range.
|
|
|
|
if (MayThrow) {
|
|
|
|
CallSiteEntry Site = {LastLabel, 0, 0, 0};
|
|
|
|
CallSites.push_back(Site);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Final tallies.
|
|
|
|
unsigned SizeSites = CallSites.size() * (sizeof(int32_t) + // Site start.
|
|
|
|
sizeof(int32_t) + // Site length.
|
|
|
|
sizeof(int32_t)); // Landing pad.
|
|
|
|
for (unsigned i = 0, e = CallSites.size(); i < e; ++i)
|
2009-08-22 20:48:53 +00:00
|
|
|
SizeSites += MCAsmInfo::getULEB128Size(CallSites[i].Action);
|
2008-02-13 18:39:37 +00:00
|
|
|
|
|
|
|
unsigned SizeTypes = TypeInfos.size() * TD->getPointerSize();
|
|
|
|
|
|
|
|
unsigned TypeOffset = sizeof(int8_t) + // Call site format
|
|
|
|
// Call-site table length
|
2009-08-22 20:48:53 +00:00
|
|
|
MCAsmInfo::getULEB128Size(SizeSites) +
|
2008-02-13 18:39:37 +00:00
|
|
|
SizeSites + SizeActions + SizeTypes;
|
|
|
|
|
|
|
|
// Begin the exception table.
|
2009-08-21 21:03:57 +00:00
|
|
|
JCE->emitAlignmentWithFill(4, 0);
|
|
|
|
// Asm->EOL("Padding");
|
|
|
|
|
2009-05-30 20:51:52 +00:00
|
|
|
unsigned char* DwarfExceptionTable = (unsigned char*)JCE->getCurrentPCValue();
|
2008-02-13 18:39:37 +00:00
|
|
|
|
|
|
|
// Emit the header.
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitByte(dwarf::DW_EH_PE_omit);
|
2008-02-13 18:39:37 +00:00
|
|
|
// Asm->EOL("LPStart format (DW_EH_PE_omit)");
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitByte(dwarf::DW_EH_PE_absptr);
|
2008-02-13 18:39:37 +00:00
|
|
|
// Asm->EOL("TType format (DW_EH_PE_absptr)");
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitULEB128Bytes(TypeOffset);
|
2008-02-13 18:39:37 +00:00
|
|
|
// Asm->EOL("TType base offset");
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitByte(dwarf::DW_EH_PE_udata4);
|
2008-02-13 18:39:37 +00:00
|
|
|
// Asm->EOL("Call site format (DW_EH_PE_udata4)");
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitULEB128Bytes(SizeSites);
|
2008-02-13 18:39:37 +00:00
|
|
|
// Asm->EOL("Call-site table length");
|
|
|
|
|
|
|
|
// Emit the landing pad site information.
|
|
|
|
for (unsigned i = 0; i < CallSites.size(); ++i) {
|
|
|
|
CallSiteEntry &S = CallSites[i];
|
|
|
|
intptr_t BeginLabelPtr = 0;
|
|
|
|
intptr_t EndLabelPtr = 0;
|
|
|
|
|
|
|
|
if (!S.BeginLabel) {
|
|
|
|
BeginLabelPtr = (intptr_t)StartFunction;
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitInt32(0);
|
2008-02-13 18:39:37 +00:00
|
|
|
} else {
|
2009-05-30 20:51:52 +00:00
|
|
|
BeginLabelPtr = JCE->getLabelAddress(S.BeginLabel);
|
|
|
|
JCE->emitInt32(BeginLabelPtr - (intptr_t)StartFunction);
|
2008-02-13 18:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Asm->EOL("Region start");
|
|
|
|
|
2009-12-28 01:53:00 +00:00
|
|
|
if (!S.EndLabel)
|
2008-02-13 18:39:37 +00:00
|
|
|
EndLabelPtr = (intptr_t)EndFunction;
|
2009-12-28 01:53:00 +00:00
|
|
|
else
|
2009-05-30 20:51:52 +00:00
|
|
|
EndLabelPtr = JCE->getLabelAddress(S.EndLabel);
|
2009-12-28 01:53:00 +00:00
|
|
|
|
|
|
|
JCE->emitInt32(EndLabelPtr - BeginLabelPtr);
|
2008-02-13 18:39:37 +00:00
|
|
|
//Asm->EOL("Region length");
|
|
|
|
|
|
|
|
if (!S.PadLabel) {
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitInt32(0);
|
2008-02-13 18:39:37 +00:00
|
|
|
} else {
|
2009-05-30 20:51:52 +00:00
|
|
|
unsigned PadLabelPtr = JCE->getLabelAddress(S.PadLabel);
|
|
|
|
JCE->emitInt32(PadLabelPtr - (intptr_t)StartFunction);
|
2008-02-13 18:39:37 +00:00
|
|
|
}
|
|
|
|
// Asm->EOL("Landing pad");
|
|
|
|
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitULEB128Bytes(S.Action);
|
2008-02-13 18:39:37 +00:00
|
|
|
// Asm->EOL("Action");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit the actions.
|
|
|
|
for (unsigned I = 0, N = Actions.size(); I != N; ++I) {
|
|
|
|
ActionEntry &Action = Actions[I];
|
|
|
|
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitSLEB128Bytes(Action.ValueForTypeID);
|
2008-02-13 18:39:37 +00:00
|
|
|
//Asm->EOL("TypeInfo index");
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitSLEB128Bytes(Action.NextAction);
|
2008-02-13 18:39:37 +00:00
|
|
|
//Asm->EOL("Next action");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit the type ids.
|
|
|
|
for (unsigned M = TypeInfos.size(); M; --M) {
|
2010-04-15 01:51:59 +00:00
|
|
|
const GlobalVariable *GV = TypeInfos[M - 1];
|
2008-02-13 18:39:37 +00:00
|
|
|
|
|
|
|
if (GV) {
|
2009-09-09 00:11:02 +00:00
|
|
|
if (TD->getPointerSize() == sizeof(int32_t))
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitInt32((intptr_t)Jit.getOrEmitGlobalVariable(GV));
|
2009-09-09 00:11:02 +00:00
|
|
|
else
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitInt64((intptr_t)Jit.getOrEmitGlobalVariable(GV));
|
2008-02-13 18:39:37 +00:00
|
|
|
} else {
|
|
|
|
if (TD->getPointerSize() == sizeof(int32_t))
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitInt32(0);
|
2008-02-13 18:39:37 +00:00
|
|
|
else
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitInt64(0);
|
2008-02-13 18:39:37 +00:00
|
|
|
}
|
|
|
|
// Asm->EOL("TypeInfo");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit the filter typeids.
|
|
|
|
for (unsigned j = 0, M = FilterIds.size(); j < M; ++j) {
|
|
|
|
unsigned TypeID = FilterIds[j];
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitULEB128Bytes(TypeID);
|
2008-02-13 18:39:37 +00:00
|
|
|
//Asm->EOL("Filter TypeInfo index");
|
|
|
|
}
|
2009-08-21 21:03:57 +00:00
|
|
|
|
|
|
|
JCE->emitAlignmentWithFill(4, 0);
|
2008-02-13 18:39:37 +00:00
|
|
|
|
|
|
|
return DwarfExceptionTable;
|
|
|
|
}
|
|
|
|
|
2008-04-20 17:44:19 +00:00
|
|
|
unsigned char*
|
|
|
|
JITDwarfEmitter::EmitCommonEHFrame(const Function* Personality) const {
|
2008-02-13 18:39:37 +00:00
|
|
|
unsigned PointerSize = TD->getPointerSize();
|
|
|
|
int stackGrowth = stackGrowthDirection == TargetFrameInfo::StackGrowsUp ?
|
|
|
|
PointerSize : -PointerSize;
|
|
|
|
|
2009-05-30 20:51:52 +00:00
|
|
|
unsigned char* StartCommonPtr = (unsigned char*)JCE->getCurrentPCValue();
|
2008-02-13 18:39:37 +00:00
|
|
|
// EH Common Frame header
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->allocateSpace(4, 0);
|
|
|
|
unsigned char* FrameCommonBeginPtr = (unsigned char*)JCE->getCurrentPCValue();
|
|
|
|
JCE->emitInt32((int)0);
|
|
|
|
JCE->emitByte(dwarf::DW_CIE_VERSION);
|
|
|
|
JCE->emitString(Personality ? "zPLR" : "zR");
|
|
|
|
JCE->emitULEB128Bytes(1);
|
|
|
|
JCE->emitSLEB128Bytes(stackGrowth);
|
|
|
|
JCE->emitByte(RI->getDwarfRegNum(RI->getRARegister(), true));
|
2009-09-09 00:11:02 +00:00
|
|
|
|
2008-02-13 18:39:37 +00:00
|
|
|
if (Personality) {
|
2009-02-15 20:49:23 +00:00
|
|
|
// Augmentation Size: 3 small ULEBs of one byte each, and the personality
|
|
|
|
// function which size is PointerSize.
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitULEB128Bytes(3 + PointerSize);
|
2008-02-13 18:39:37 +00:00
|
|
|
|
2009-02-15 20:49:23 +00:00
|
|
|
// We set the encoding of the personality as direct encoding because we use
|
|
|
|
// the function pointer. The encoding is not relative because the current
|
|
|
|
// PC value may be bigger than the personality function pointer.
|
|
|
|
if (PointerSize == 4) {
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitByte(dwarf::DW_EH_PE_sdata4);
|
|
|
|
JCE->emitInt32(((intptr_t)Jit.getPointerToGlobal(Personality)));
|
2009-02-15 20:49:23 +00:00
|
|
|
} else {
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitByte(dwarf::DW_EH_PE_sdata8);
|
|
|
|
JCE->emitInt64(((intptr_t)Jit.getPointerToGlobal(Personality)));
|
2009-02-15 20:49:23 +00:00
|
|
|
}
|
2009-09-09 00:11:02 +00:00
|
|
|
|
2010-02-16 00:58:02 +00:00
|
|
|
// LSDA encoding: This must match the encoding used in EmitEHFrame ()
|
|
|
|
if (PointerSize == 4)
|
|
|
|
JCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4);
|
|
|
|
else
|
|
|
|
JCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8);
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4);
|
2008-02-13 18:39:37 +00:00
|
|
|
} else {
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitULEB128Bytes(1);
|
|
|
|
JCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4);
|
2008-02-13 18:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<MachineMove> Moves;
|
|
|
|
RI->getInitialFrameState(Moves);
|
|
|
|
EmitFrameMoves(0, Moves);
|
2009-08-21 21:03:57 +00:00
|
|
|
|
|
|
|
JCE->emitAlignmentWithFill(PointerSize, dwarf::DW_CFA_nop);
|
|
|
|
|
|
|
|
JCE->emitInt32At((uintptr_t*)StartCommonPtr,
|
|
|
|
(uintptr_t)((unsigned char*)JCE->getCurrentPCValue() -
|
|
|
|
FrameCommonBeginPtr));
|
2008-02-13 18:39:37 +00:00
|
|
|
|
|
|
|
return StartCommonPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-20 17:44:19 +00:00
|
|
|
unsigned char*
|
|
|
|
JITDwarfEmitter::EmitEHFrame(const Function* Personality,
|
|
|
|
unsigned char* StartCommonPtr,
|
|
|
|
unsigned char* StartFunction,
|
|
|
|
unsigned char* EndFunction,
|
|
|
|
unsigned char* ExceptionTable) const {
|
2008-02-13 18:39:37 +00:00
|
|
|
unsigned PointerSize = TD->getPointerSize();
|
|
|
|
|
|
|
|
// EH frame header.
|
2009-05-30 20:51:52 +00:00
|
|
|
unsigned char* StartEHPtr = (unsigned char*)JCE->getCurrentPCValue();
|
|
|
|
JCE->allocateSpace(4, 0);
|
|
|
|
unsigned char* FrameBeginPtr = (unsigned char*)JCE->getCurrentPCValue();
|
2008-02-13 18:39:37 +00:00
|
|
|
// FDE CIE Offset
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitInt32(FrameBeginPtr - StartCommonPtr);
|
|
|
|
JCE->emitInt32(StartFunction - (unsigned char*)JCE->getCurrentPCValue());
|
|
|
|
JCE->emitInt32(EndFunction - StartFunction);
|
2008-02-13 18:39:37 +00:00
|
|
|
|
|
|
|
// If there is a personality and landing pads then point to the language
|
|
|
|
// specific data area in the exception table.
|
2009-09-09 00:11:02 +00:00
|
|
|
if (Personality) {
|
|
|
|
JCE->emitULEB128Bytes(PointerSize == 4 ? 4 : 8);
|
2008-02-13 18:39:37 +00:00
|
|
|
|
2009-09-09 00:11:02 +00:00
|
|
|
if (PointerSize == 4) {
|
|
|
|
if (!MMI->getLandingPads().empty())
|
|
|
|
JCE->emitInt32(ExceptionTable-(unsigned char*)JCE->getCurrentPCValue());
|
|
|
|
else
|
|
|
|
JCE->emitInt32((int)0);
|
2008-02-13 18:39:37 +00:00
|
|
|
} else {
|
2009-09-09 00:11:02 +00:00
|
|
|
if (!MMI->getLandingPads().empty())
|
|
|
|
JCE->emitInt64(ExceptionTable-(unsigned char*)JCE->getCurrentPCValue());
|
|
|
|
else
|
|
|
|
JCE->emitInt64((int)0);
|
2008-02-13 18:39:37 +00:00
|
|
|
}
|
|
|
|
} else {
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitULEB128Bytes(0);
|
2008-02-13 18:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Indicate locations of function specific callee saved registers in
|
|
|
|
// frame.
|
|
|
|
EmitFrameMoves((intptr_t)StartFunction, MMI->getFrameMoves());
|
2009-08-21 21:03:57 +00:00
|
|
|
|
|
|
|
JCE->emitAlignmentWithFill(PointerSize, dwarf::DW_CFA_nop);
|
|
|
|
|
2008-02-13 18:39:37 +00:00
|
|
|
// Indicate the size of the table
|
2009-08-21 21:03:57 +00:00
|
|
|
JCE->emitInt32At((uintptr_t*)StartEHPtr,
|
|
|
|
(uintptr_t)((unsigned char*)JCE->getCurrentPCValue() -
|
|
|
|
StartEHPtr));
|
|
|
|
|
2008-02-13 18:39:37 +00:00
|
|
|
// Double zeroes for the unwind runtime
|
|
|
|
if (PointerSize == 8) {
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitInt64(0);
|
|
|
|
JCE->emitInt64(0);
|
2008-02-13 18:39:37 +00:00
|
|
|
} else {
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE->emitInt32(0);
|
|
|
|
JCE->emitInt32(0);
|
2008-02-13 18:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return StartEHPtr;
|
|
|
|
}
|
2008-04-18 20:59:31 +00:00
|
|
|
|
2008-04-20 17:44:19 +00:00
|
|
|
unsigned JITDwarfEmitter::GetDwarfTableSizeInBytes(MachineFunction& F,
|
2009-05-30 20:51:52 +00:00
|
|
|
JITCodeEmitter& jce,
|
2008-04-18 20:59:31 +00:00
|
|
|
unsigned char* StartFunction,
|
|
|
|
unsigned char* EndFunction) {
|
|
|
|
const TargetMachine& TM = F.getTarget();
|
|
|
|
TD = TM.getTargetData();
|
|
|
|
stackGrowthDirection = TM.getFrameInfo()->getStackGrowthDirection();
|
|
|
|
RI = TM.getRegisterInfo();
|
2009-05-30 20:51:52 +00:00
|
|
|
JCE = &jce;
|
2008-04-18 20:59:31 +00:00
|
|
|
unsigned FinalSize = 0;
|
|
|
|
|
2008-04-20 17:44:19 +00:00
|
|
|
FinalSize += GetExceptionTableSizeInBytes(&F);
|
2008-04-18 20:59:31 +00:00
|
|
|
|
2010-04-15 01:51:59 +00:00
|
|
|
const std::vector<const Function *> Personalities = MMI->getPersonalities();
|
2008-11-18 10:44:46 +00:00
|
|
|
FinalSize +=
|
|
|
|
GetCommonEHFrameSizeInBytes(Personalities[MMI->getPersonalityIndex()]);
|
2008-04-18 20:59:31 +00:00
|
|
|
|
2008-11-18 10:44:46 +00:00
|
|
|
FinalSize += GetEHFrameSizeInBytes(Personalities[MMI->getPersonalityIndex()],
|
|
|
|
StartFunction);
|
2009-09-09 00:11:02 +00:00
|
|
|
|
2008-04-18 20:59:31 +00:00
|
|
|
return FinalSize;
|
|
|
|
}
|
|
|
|
|
2008-04-20 17:44:19 +00:00
|
|
|
/// RoundUpToAlign - Add the specified alignment to FinalSize and returns
|
|
|
|
/// the new value.
|
|
|
|
static unsigned RoundUpToAlign(unsigned FinalSize, unsigned Alignment) {
|
2008-04-18 20:59:31 +00:00
|
|
|
if (Alignment == 0) Alignment = 1;
|
2008-04-20 23:39:44 +00:00
|
|
|
// Since we do not know where the buffer will be allocated, be pessimistic.
|
|
|
|
return FinalSize + Alignment;
|
2008-04-18 20:59:31 +00:00
|
|
|
}
|
|
|
|
|
2008-04-20 17:44:19 +00:00
|
|
|
unsigned
|
|
|
|
JITDwarfEmitter::GetEHFrameSizeInBytes(const Function* Personality,
|
|
|
|
unsigned char* StartFunction) const {
|
2008-04-18 20:59:31 +00:00
|
|
|
unsigned PointerSize = TD->getPointerSize();
|
|
|
|
unsigned FinalSize = 0;
|
|
|
|
// EH frame header.
|
|
|
|
FinalSize += PointerSize;
|
|
|
|
// FDE CIE Offset
|
|
|
|
FinalSize += 3 * PointerSize;
|
|
|
|
// If there is a personality and landing pads then point to the language
|
|
|
|
// specific data area in the exception table.
|
2009-09-09 00:11:02 +00:00
|
|
|
if (Personality) {
|
2009-08-22 20:48:53 +00:00
|
|
|
FinalSize += MCAsmInfo::getULEB128Size(4);
|
2008-04-18 20:59:31 +00:00
|
|
|
FinalSize += PointerSize;
|
|
|
|
} else {
|
2009-08-22 20:48:53 +00:00
|
|
|
FinalSize += MCAsmInfo::getULEB128Size(0);
|
2008-04-18 20:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Indicate locations of function specific callee saved registers in
|
|
|
|
// frame.
|
2008-04-20 17:44:19 +00:00
|
|
|
FinalSize += GetFrameMovesSizeInBytes((intptr_t)StartFunction,
|
|
|
|
MMI->getFrameMoves());
|
2008-04-18 20:59:31 +00:00
|
|
|
|
2008-04-20 17:44:19 +00:00
|
|
|
FinalSize = RoundUpToAlign(FinalSize, 4);
|
2008-04-18 20:59:31 +00:00
|
|
|
|
|
|
|
// Double zeroes for the unwind runtime
|
|
|
|
FinalSize += 2 * PointerSize;
|
|
|
|
|
|
|
|
return FinalSize;
|
|
|
|
}
|
|
|
|
|
2008-04-20 17:44:19 +00:00
|
|
|
unsigned JITDwarfEmitter::GetCommonEHFrameSizeInBytes(const Function* Personality)
|
|
|
|
const {
|
2008-04-18 20:59:31 +00:00
|
|
|
|
|
|
|
unsigned PointerSize = TD->getPointerSize();
|
|
|
|
int stackGrowth = stackGrowthDirection == TargetFrameInfo::StackGrowsUp ?
|
|
|
|
PointerSize : -PointerSize;
|
|
|
|
unsigned FinalSize = 0;
|
|
|
|
// EH Common Frame header
|
|
|
|
FinalSize += PointerSize;
|
|
|
|
FinalSize += 4;
|
|
|
|
FinalSize += 1;
|
2008-04-20 17:44:19 +00:00
|
|
|
FinalSize += Personality ? 5 : 3; // "zPLR" or "zR"
|
2009-08-22 20:48:53 +00:00
|
|
|
FinalSize += MCAsmInfo::getULEB128Size(1);
|
|
|
|
FinalSize += MCAsmInfo::getSLEB128Size(stackGrowth);
|
2008-04-18 20:59:31 +00:00
|
|
|
FinalSize += 1;
|
|
|
|
|
|
|
|
if (Personality) {
|
2009-08-22 20:48:53 +00:00
|
|
|
FinalSize += MCAsmInfo::getULEB128Size(7);
|
2008-04-18 20:59:31 +00:00
|
|
|
|
|
|
|
// Encoding
|
|
|
|
FinalSize+= 1;
|
|
|
|
//Personality
|
|
|
|
FinalSize += PointerSize;
|
|
|
|
|
2009-08-22 20:48:53 +00:00
|
|
|
FinalSize += MCAsmInfo::getULEB128Size(dwarf::DW_EH_PE_pcrel);
|
|
|
|
FinalSize += MCAsmInfo::getULEB128Size(dwarf::DW_EH_PE_pcrel);
|
2008-04-18 20:59:31 +00:00
|
|
|
|
|
|
|
} else {
|
2009-08-22 20:48:53 +00:00
|
|
|
FinalSize += MCAsmInfo::getULEB128Size(1);
|
|
|
|
FinalSize += MCAsmInfo::getULEB128Size(dwarf::DW_EH_PE_pcrel);
|
2008-04-18 20:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<MachineMove> Moves;
|
|
|
|
RI->getInitialFrameState(Moves);
|
2008-04-20 17:44:19 +00:00
|
|
|
FinalSize += GetFrameMovesSizeInBytes(0, Moves);
|
|
|
|
FinalSize = RoundUpToAlign(FinalSize, 4);
|
2008-04-18 20:59:31 +00:00
|
|
|
return FinalSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned
|
2008-04-20 17:44:19 +00:00
|
|
|
JITDwarfEmitter::GetFrameMovesSizeInBytes(intptr_t BaseLabelPtr,
|
|
|
|
const std::vector<MachineMove> &Moves) const {
|
2008-04-18 20:59:31 +00:00
|
|
|
unsigned PointerSize = TD->getPointerSize();
|
|
|
|
int stackGrowth = stackGrowthDirection == TargetFrameInfo::StackGrowsUp ?
|
|
|
|
PointerSize : -PointerSize;
|
|
|
|
bool IsLocal = BaseLabelPtr;
|
|
|
|
unsigned FinalSize = 0;
|
|
|
|
|
|
|
|
for (unsigned i = 0, N = Moves.size(); i < N; ++i) {
|
|
|
|
const MachineMove &Move = Moves[i];
|
2010-03-14 08:12:40 +00:00
|
|
|
MCSymbol *Label = Move.getLabel();
|
2008-04-18 20:59:31 +00:00
|
|
|
|
2010-03-14 01:41:15 +00:00
|
|
|
// Throw out move if the label is invalid.
|
2010-04-18 00:56:05 +00:00
|
|
|
if (Label && (*JCE->getLabelLocations())[Label] == 0)
|
2010-03-14 01:41:15 +00:00
|
|
|
continue;
|
2008-04-18 20:59:31 +00:00
|
|
|
|
|
|
|
intptr_t LabelPtr = 0;
|
2010-03-14 08:12:40 +00:00
|
|
|
if (Label) LabelPtr = JCE->getLabelAddress(Label);
|
2008-04-18 20:59:31 +00:00
|
|
|
|
|
|
|
const MachineLocation &Dst = Move.getDestination();
|
|
|
|
const MachineLocation &Src = Move.getSource();
|
|
|
|
|
|
|
|
// Advance row if new location.
|
2010-03-14 08:12:40 +00:00
|
|
|
if (BaseLabelPtr && Label && (BaseLabelPtr != LabelPtr || !IsLocal)) {
|
2008-04-18 20:59:31 +00:00
|
|
|
FinalSize++;
|
|
|
|
FinalSize += PointerSize;
|
|
|
|
BaseLabelPtr = LabelPtr;
|
|
|
|
IsLocal = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If advancing cfa.
|
2008-10-03 17:11:57 +00:00
|
|
|
if (Dst.isReg() && Dst.getReg() == MachineLocation::VirtualFP) {
|
|
|
|
if (!Src.isReg()) {
|
|
|
|
if (Src.getReg() == MachineLocation::VirtualFP) {
|
2008-04-18 20:59:31 +00:00
|
|
|
++FinalSize;
|
|
|
|
} else {
|
|
|
|
++FinalSize;
|
2008-10-03 17:11:57 +00:00
|
|
|
unsigned RegNum = RI->getDwarfRegNum(Src.getReg(), true);
|
2009-08-22 20:48:53 +00:00
|
|
|
FinalSize += MCAsmInfo::getULEB128Size(RegNum);
|
2008-04-18 20:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Offset = -Src.getOffset();
|
|
|
|
|
2009-08-22 20:48:53 +00:00
|
|
|
FinalSize += MCAsmInfo::getULEB128Size(Offset);
|
2008-04-18 20:59:31 +00:00
|
|
|
} else {
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Machine move no supported yet.");
|
2008-04-18 20:59:31 +00:00
|
|
|
}
|
2008-10-03 17:11:57 +00:00
|
|
|
} else if (Src.isReg() &&
|
|
|
|
Src.getReg() == MachineLocation::VirtualFP) {
|
|
|
|
if (Dst.isReg()) {
|
2008-04-20 17:44:19 +00:00
|
|
|
++FinalSize;
|
2008-10-03 17:11:57 +00:00
|
|
|
unsigned RegNum = RI->getDwarfRegNum(Dst.getReg(), true);
|
2009-08-22 20:48:53 +00:00
|
|
|
FinalSize += MCAsmInfo::getULEB128Size(RegNum);
|
2008-04-18 20:59:31 +00:00
|
|
|
} else {
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Machine move no supported yet.");
|
2008-04-18 20:59:31 +00:00
|
|
|
}
|
|
|
|
} else {
|
2008-10-03 17:11:57 +00:00
|
|
|
unsigned Reg = RI->getDwarfRegNum(Src.getReg(), true);
|
2008-04-18 20:59:31 +00:00
|
|
|
int Offset = Dst.getOffset() / stackGrowth;
|
|
|
|
|
|
|
|
if (Offset < 0) {
|
|
|
|
++FinalSize;
|
2009-08-22 20:48:53 +00:00
|
|
|
FinalSize += MCAsmInfo::getULEB128Size(Reg);
|
|
|
|
FinalSize += MCAsmInfo::getSLEB128Size(Offset);
|
2008-04-18 20:59:31 +00:00
|
|
|
} else if (Reg < 64) {
|
|
|
|
++FinalSize;
|
2009-08-22 20:48:53 +00:00
|
|
|
FinalSize += MCAsmInfo::getULEB128Size(Offset);
|
2008-04-18 20:59:31 +00:00
|
|
|
} else {
|
|
|
|
++FinalSize;
|
2009-08-22 20:48:53 +00:00
|
|
|
FinalSize += MCAsmInfo::getULEB128Size(Reg);
|
|
|
|
FinalSize += MCAsmInfo::getULEB128Size(Offset);
|
2008-04-18 20:59:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FinalSize;
|
|
|
|
}
|
|
|
|
|
2008-04-20 17:44:19 +00:00
|
|
|
unsigned
|
|
|
|
JITDwarfEmitter::GetExceptionTableSizeInBytes(MachineFunction* MF) const {
|
2008-04-18 20:59:31 +00:00
|
|
|
unsigned FinalSize = 0;
|
|
|
|
|
|
|
|
// Map all labels and get rid of any dead landing pads.
|
2010-04-16 08:46:10 +00:00
|
|
|
MMI->TidyLandingPads(JCE->getLabelLocations());
|
2008-04-18 20:59:31 +00:00
|
|
|
|
2010-04-15 01:51:59 +00:00
|
|
|
const std::vector<const GlobalVariable *> &TypeInfos = MMI->getTypeInfos();
|
2008-04-18 20:59:31 +00:00
|
|
|
const std::vector<unsigned> &FilterIds = MMI->getFilterIds();
|
|
|
|
const std::vector<LandingPadInfo> &PadInfos = MMI->getLandingPads();
|
|
|
|
if (PadInfos.empty()) return 0;
|
|
|
|
|
|
|
|
// Sort the landing pads in order of their type ids. This is used to fold
|
|
|
|
// duplicate actions.
|
|
|
|
SmallVector<const LandingPadInfo *, 64> LandingPads;
|
|
|
|
LandingPads.reserve(PadInfos.size());
|
|
|
|
for (unsigned i = 0, N = PadInfos.size(); i != N; ++i)
|
|
|
|
LandingPads.push_back(&PadInfos[i]);
|
|
|
|
std::sort(LandingPads.begin(), LandingPads.end(), PadLT);
|
|
|
|
|
|
|
|
// Negative type ids index into FilterIds, positive type ids index into
|
|
|
|
// TypeInfos. The value written for a positive type id is just the type
|
|
|
|
// id itself. For a negative type id, however, the value written is the
|
|
|
|
// (negative) byte offset of the corresponding FilterIds entry. The byte
|
|
|
|
// offset is usually equal to the type id, because the FilterIds entries
|
|
|
|
// are written using a variable width encoding which outputs one byte per
|
|
|
|
// entry as long as the value written is not too large, but can differ.
|
|
|
|
// This kind of complication does not occur for positive type ids because
|
|
|
|
// type infos are output using a fixed width encoding.
|
|
|
|
// FilterOffsets[i] holds the byte offset corresponding to FilterIds[i].
|
|
|
|
SmallVector<int, 16> FilterOffsets;
|
|
|
|
FilterOffsets.reserve(FilterIds.size());
|
|
|
|
int Offset = -1;
|
|
|
|
for(std::vector<unsigned>::const_iterator I = FilterIds.begin(),
|
|
|
|
E = FilterIds.end(); I != E; ++I) {
|
|
|
|
FilterOffsets.push_back(Offset);
|
2009-08-22 20:48:53 +00:00
|
|
|
Offset -= MCAsmInfo::getULEB128Size(*I);
|
2008-04-18 20:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the actions table and gather the first action index for each
|
|
|
|
// landing pad site.
|
|
|
|
SmallVector<ActionEntry, 32> Actions;
|
|
|
|
SmallVector<unsigned, 64> FirstActions;
|
|
|
|
FirstActions.reserve(LandingPads.size());
|
|
|
|
|
|
|
|
int FirstAction = 0;
|
|
|
|
unsigned SizeActions = 0;
|
|
|
|
for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
|
|
|
|
const LandingPadInfo *LP = LandingPads[i];
|
|
|
|
const std::vector<int> &TypeIds = LP->TypeIds;
|
|
|
|
const unsigned NumShared = i ? SharedTypeIds(LP, LandingPads[i-1]) : 0;
|
|
|
|
unsigned SizeSiteActions = 0;
|
|
|
|
|
|
|
|
if (NumShared < TypeIds.size()) {
|
|
|
|
unsigned SizeAction = 0;
|
|
|
|
ActionEntry *PrevAction = 0;
|
|
|
|
|
|
|
|
if (NumShared) {
|
|
|
|
const unsigned SizePrevIds = LandingPads[i-1]->TypeIds.size();
|
|
|
|
assert(Actions.size());
|
|
|
|
PrevAction = &Actions.back();
|
2009-08-22 20:48:53 +00:00
|
|
|
SizeAction = MCAsmInfo::getSLEB128Size(PrevAction->NextAction) +
|
|
|
|
MCAsmInfo::getSLEB128Size(PrevAction->ValueForTypeID);
|
2008-04-18 20:59:31 +00:00
|
|
|
for (unsigned j = NumShared; j != SizePrevIds; ++j) {
|
2009-08-22 20:48:53 +00:00
|
|
|
SizeAction -= MCAsmInfo::getSLEB128Size(PrevAction->ValueForTypeID);
|
2008-04-18 20:59:31 +00:00
|
|
|
SizeAction += -PrevAction->NextAction;
|
|
|
|
PrevAction = PrevAction->Previous;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the actions.
|
|
|
|
for (unsigned I = NumShared, M = TypeIds.size(); I != M; ++I) {
|
|
|
|
int TypeID = TypeIds[I];
|
|
|
|
assert(-1-TypeID < (int)FilterOffsets.size() && "Unknown filter id!");
|
|
|
|
int ValueForTypeID = TypeID < 0 ? FilterOffsets[-1 - TypeID] : TypeID;
|
2009-08-22 20:48:53 +00:00
|
|
|
unsigned SizeTypeID = MCAsmInfo::getSLEB128Size(ValueForTypeID);
|
2008-04-18 20:59:31 +00:00
|
|
|
|
|
|
|
int NextAction = SizeAction ? -(SizeAction + SizeTypeID) : 0;
|
2009-08-22 20:48:53 +00:00
|
|
|
SizeAction = SizeTypeID + MCAsmInfo::getSLEB128Size(NextAction);
|
2008-04-18 20:59:31 +00:00
|
|
|
SizeSiteActions += SizeAction;
|
|
|
|
|
|
|
|
ActionEntry Action = {ValueForTypeID, NextAction, PrevAction};
|
|
|
|
Actions.push_back(Action);
|
|
|
|
|
|
|
|
PrevAction = &Actions.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Record the first action of the landing pad site.
|
|
|
|
FirstAction = SizeActions + SizeSiteActions - SizeAction + 1;
|
|
|
|
} // else identical - re-use previous FirstAction
|
|
|
|
|
|
|
|
FirstActions.push_back(FirstAction);
|
|
|
|
|
|
|
|
// Compute this sites contribution to size.
|
|
|
|
SizeActions += SizeSiteActions;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the call-site table. Entries must be ordered by address.
|
|
|
|
SmallVector<CallSiteEntry, 64> CallSites;
|
|
|
|
|
|
|
|
RangeMapType PadMap;
|
|
|
|
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) {
|
2010-03-14 01:41:15 +00:00
|
|
|
MCSymbol *BeginLabel = LandingPad->BeginLabels[j];
|
2008-04-18 20:59:31 +00:00
|
|
|
assert(!PadMap.count(BeginLabel) && "Duplicate landing pad labels!");
|
|
|
|
PadRange P = { i, j };
|
|
|
|
PadMap[BeginLabel] = P;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MayThrow = false;
|
2010-03-14 01:41:15 +00:00
|
|
|
MCSymbol *LastLabel = 0;
|
2008-04-18 20:59:31 +00:00
|
|
|
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) {
|
2008-07-01 00:05:16 +00:00
|
|
|
if (!MI->isLabel()) {
|
2008-04-18 20:59:31 +00:00
|
|
|
MayThrow |= MI->getDesc().isCall();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-03-14 08:28:48 +00:00
|
|
|
MCSymbol *BeginLabel = MI->getOperand(0).getMCSymbol();
|
2010-03-14 01:41:15 +00:00
|
|
|
|
2008-04-18 20:59:31 +00:00
|
|
|
if (BeginLabel == LastLabel)
|
|
|
|
MayThrow = false;
|
|
|
|
|
|
|
|
RangeMapType::iterator L = PadMap.find(BeginLabel);
|
|
|
|
|
|
|
|
if (L == PadMap.end())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
PadRange P = L->second;
|
|
|
|
const LandingPadInfo *LandingPad = LandingPads[P.PadIndex];
|
|
|
|
|
|
|
|
assert(BeginLabel == LandingPad->BeginLabels[P.RangeIndex] &&
|
|
|
|
"Inconsistent landing pad map!");
|
|
|
|
|
|
|
|
// If some instruction between the previous try-range and this one may
|
|
|
|
// throw, create a call-site entry with no landing pad for the region
|
|
|
|
// between the try-ranges.
|
|
|
|
if (MayThrow) {
|
|
|
|
CallSiteEntry Site = {LastLabel, BeginLabel, 0, 0};
|
|
|
|
CallSites.push_back(Site);
|
|
|
|
}
|
|
|
|
|
|
|
|
LastLabel = LandingPad->EndLabels[P.RangeIndex];
|
|
|
|
CallSiteEntry Site = {BeginLabel, LastLabel,
|
|
|
|
LandingPad->LandingPadLabel, FirstActions[P.PadIndex]};
|
|
|
|
|
|
|
|
assert(Site.BeginLabel && Site.EndLabel && Site.PadLabel &&
|
|
|
|
"Invalid landing pad!");
|
|
|
|
|
|
|
|
// Try to merge with the previous call-site.
|
|
|
|
if (CallSites.size()) {
|
2008-06-21 22:00:54 +00:00
|
|
|
CallSiteEntry &Prev = CallSites.back();
|
2008-04-18 20:59:31 +00:00
|
|
|
if (Site.PadLabel == Prev.PadLabel && Site.Action == Prev.Action) {
|
|
|
|
// Extend the range of the previous entry.
|
|
|
|
Prev.EndLabel = Site.EndLabel;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, create a new call-site.
|
|
|
|
CallSites.push_back(Site);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If some instruction between the previous try-range and the end of the
|
|
|
|
// function may throw, create a call-site entry with no landing pad for the
|
|
|
|
// region following the try-range.
|
|
|
|
if (MayThrow) {
|
|
|
|
CallSiteEntry Site = {LastLabel, 0, 0, 0};
|
|
|
|
CallSites.push_back(Site);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Final tallies.
|
|
|
|
unsigned SizeSites = CallSites.size() * (sizeof(int32_t) + // Site start.
|
|
|
|
sizeof(int32_t) + // Site length.
|
|
|
|
sizeof(int32_t)); // Landing pad.
|
|
|
|
for (unsigned i = 0, e = CallSites.size(); i < e; ++i)
|
2009-08-22 20:48:53 +00:00
|
|
|
SizeSites += MCAsmInfo::getULEB128Size(CallSites[i].Action);
|
2008-04-18 20:59:31 +00:00
|
|
|
|
|
|
|
unsigned SizeTypes = TypeInfos.size() * TD->getPointerSize();
|
|
|
|
|
|
|
|
unsigned TypeOffset = sizeof(int8_t) + // Call site format
|
|
|
|
// Call-site table length
|
2009-08-22 20:48:53 +00:00
|
|
|
MCAsmInfo::getULEB128Size(SizeSites) +
|
2008-04-18 20:59:31 +00:00
|
|
|
SizeSites + SizeActions + SizeTypes;
|
|
|
|
|
|
|
|
unsigned TotalSize = sizeof(int8_t) + // LPStart format
|
|
|
|
sizeof(int8_t) + // TType format
|
2009-08-22 20:48:53 +00:00
|
|
|
MCAsmInfo::getULEB128Size(TypeOffset) + // TType base offset
|
2008-04-18 20:59:31 +00:00
|
|
|
TypeOffset;
|
|
|
|
|
|
|
|
unsigned SizeAlign = (4 - TotalSize) & 3;
|
|
|
|
|
|
|
|
// Begin the exception table.
|
2008-04-20 17:44:19 +00:00
|
|
|
FinalSize = RoundUpToAlign(FinalSize, 4);
|
2008-04-18 20:59:31 +00:00
|
|
|
for (unsigned i = 0; i != SizeAlign; ++i) {
|
|
|
|
++FinalSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned PointerSize = TD->getPointerSize();
|
|
|
|
|
|
|
|
// Emit the header.
|
|
|
|
++FinalSize;
|
|
|
|
// Asm->EOL("LPStart format (DW_EH_PE_omit)");
|
|
|
|
++FinalSize;
|
|
|
|
// Asm->EOL("TType format (DW_EH_PE_absptr)");
|
|
|
|
++FinalSize;
|
|
|
|
// Asm->EOL("TType base offset");
|
|
|
|
++FinalSize;
|
|
|
|
// Asm->EOL("Call site format (DW_EH_PE_udata4)");
|
|
|
|
++FinalSize;
|
|
|
|
// Asm->EOL("Call-site table length");
|
|
|
|
|
|
|
|
// Emit the landing pad site information.
|
|
|
|
for (unsigned i = 0; i < CallSites.size(); ++i) {
|
|
|
|
CallSiteEntry &S = CallSites[i];
|
|
|
|
|
|
|
|
// Asm->EOL("Region start");
|
|
|
|
FinalSize += PointerSize;
|
|
|
|
|
|
|
|
//Asm->EOL("Region length");
|
|
|
|
FinalSize += PointerSize;
|
|
|
|
|
|
|
|
// Asm->EOL("Landing pad");
|
|
|
|
FinalSize += PointerSize;
|
|
|
|
|
2009-08-22 20:48:53 +00:00
|
|
|
FinalSize += MCAsmInfo::getULEB128Size(S.Action);
|
2008-04-18 20:59:31 +00:00
|
|
|
// Asm->EOL("Action");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit the actions.
|
|
|
|
for (unsigned I = 0, N = Actions.size(); I != N; ++I) {
|
|
|
|
ActionEntry &Action = Actions[I];
|
|
|
|
|
|
|
|
//Asm->EOL("TypeInfo index");
|
2009-08-22 20:48:53 +00:00
|
|
|
FinalSize += MCAsmInfo::getSLEB128Size(Action.ValueForTypeID);
|
2008-04-18 20:59:31 +00:00
|
|
|
//Asm->EOL("Next action");
|
2009-08-22 20:48:53 +00:00
|
|
|
FinalSize += MCAsmInfo::getSLEB128Size(Action.NextAction);
|
2008-04-18 20:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Emit the type ids.
|
|
|
|
for (unsigned M = TypeInfos.size(); M; --M) {
|
|
|
|
// Asm->EOL("TypeInfo");
|
|
|
|
FinalSize += PointerSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit the filter typeids.
|
|
|
|
for (unsigned j = 0, M = FilterIds.size(); j < M; ++j) {
|
|
|
|
unsigned TypeID = FilterIds[j];
|
2009-08-22 20:48:53 +00:00
|
|
|
FinalSize += MCAsmInfo::getULEB128Size(TypeID);
|
2008-04-18 20:59:31 +00:00
|
|
|
//Asm->EOL("Filter TypeInfo index");
|
|
|
|
}
|
|
|
|
|
2008-04-20 17:44:19 +00:00
|
|
|
FinalSize = RoundUpToAlign(FinalSize, 4);
|
2008-04-18 20:59:31 +00:00
|
|
|
|
|
|
|
return FinalSize;
|
|
|
|
}
|