#include "JITDwarfEmitter.h"
#include "llvm/Function.h"
#include "llvm/ADT/DenseMap.h"
-#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/MachineCodeEmitter.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineLocation.h"
unsigned PointerSize = TD->getPointerSize();
int stackGrowth = stackGrowthDirection == TargetFrameInfo::StackGrowsUp ?
PointerSize : -PointerSize;
- bool IsLocal = BaseLabelPtr;
+ bool IsLocal = false;
+ unsigned BaseLabelID = 0;
for (unsigned i = 0, N = Moves.size(); i < N; ++i) {
const MachineMove &Move = Moves[i];
const MachineLocation &Src = Move.getSource();
// Advance row if new location.
- if (BaseLabelPtr && LabelID && (BaseLabelPtr != LabelPtr || !IsLocal)) {
+ if (BaseLabelPtr && LabelID && (BaseLabelID != LabelID || !IsLocal)) {
MCE->emitByte(dwarf::DW_CFA_advance_loc4);
- if (PointerSize == 8) {
- MCE->emitInt64(LabelPtr - BaseLabelPtr);
- } else {
- MCE->emitInt32(LabelPtr - BaseLabelPtr);
- }
+ MCE->emitInt32(LabelPtr - BaseLabelPtr);
+ BaseLabelID = LabelID;
BaseLabelPtr = LabelPtr;
IsLocal = true;
}
// If advancing cfa.
- if (Dst.isRegister() && Dst.getRegister() == MachineLocation::VirtualFP) {
- if (!Src.isRegister()) {
- if (Src.getRegister() == MachineLocation::VirtualFP) {
+ if (Dst.isReg() && Dst.getReg() == MachineLocation::VirtualFP) {
+ if (!Src.isReg()) {
+ if (Src.getReg() == MachineLocation::VirtualFP) {
MCE->emitByte(dwarf::DW_CFA_def_cfa_offset);
} else {
MCE->emitByte(dwarf::DW_CFA_def_cfa);
- MCE->emitULEB128Bytes(RI->getDwarfRegNum(Src.getRegister(), true));
+ MCE->emitULEB128Bytes(RI->getDwarfRegNum(Src.getReg(), true));
}
int Offset = -Src.getOffset();
} else {
assert(0 && "Machine move no supported yet.");
}
- } else if (Src.isRegister() &&
- Src.getRegister() == MachineLocation::VirtualFP) {
- if (Dst.isRegister()) {
+ } else if (Src.isReg() &&
+ Src.getReg() == MachineLocation::VirtualFP) {
+ if (Dst.isReg()) {
MCE->emitByte(dwarf::DW_CFA_def_cfa_register);
- MCE->emitULEB128Bytes(RI->getDwarfRegNum(Dst.getRegister(), true));
+ MCE->emitULEB128Bytes(RI->getDwarfRegNum(Dst.getReg(), true));
} else {
assert(0 && "Machine move no supported yet.");
}
} else {
- unsigned Reg = RI->getDwarfRegNum(Src.getRegister(), true);
+ unsigned Reg = RI->getDwarfRegNum(Src.getReg(), true);
int Offset = Dst.getOffset() / stackGrowth;
if (Offset < 0) {
return LSize < RSize;
}
+namespace {
+
struct KeyInfo {
static inline unsigned getEmptyKey() { return -1U; }
static inline unsigned getTombstoneKey() { return -2U; }
unsigned Action;
};
+}
+
unsigned char* JITDwarfEmitter::EmitExceptionTable(MachineFunction* MF,
unsigned char* StartFunction,
unsigned char* EndFunction) const {
for(std::vector<unsigned>::const_iterator I = FilterIds.begin(),
E = FilterIds.end(); I != E; ++I) {
FilterOffsets.push_back(Offset);
- Offset -= AsmPrinter::SizeULEB128(*I);
+ Offset -= TargetAsmInfo::getULEB128Size(*I);
}
// Compute the actions table and gather the first action index for each
const unsigned SizePrevIds = LandingPads[i-1]->TypeIds.size();
assert(Actions.size());
PrevAction = &Actions.back();
- SizeAction = AsmPrinter::SizeSLEB128(PrevAction->NextAction) +
- AsmPrinter::SizeSLEB128(PrevAction->ValueForTypeID);
+ SizeAction = TargetAsmInfo::getSLEB128Size(PrevAction->NextAction) +
+ TargetAsmInfo::getSLEB128Size(PrevAction->ValueForTypeID);
for (unsigned j = NumShared; j != SizePrevIds; ++j) {
- SizeAction -= AsmPrinter::SizeSLEB128(PrevAction->ValueForTypeID);
+ SizeAction -= TargetAsmInfo::getSLEB128Size(PrevAction->ValueForTypeID);
SizeAction += -PrevAction->NextAction;
PrevAction = PrevAction->Previous;
}
int TypeID = TypeIds[I];
assert(-1-TypeID < (int)FilterOffsets.size() && "Unknown filter id!");
int ValueForTypeID = TypeID < 0 ? FilterOffsets[-1 - TypeID] : TypeID;
- unsigned SizeTypeID = AsmPrinter::SizeSLEB128(ValueForTypeID);
+ unsigned SizeTypeID = TargetAsmInfo::getSLEB128Size(ValueForTypeID);
int NextAction = SizeAction ? -(SizeAction + SizeTypeID) : 0;
- SizeAction = SizeTypeID + AsmPrinter::SizeSLEB128(NextAction);
+ SizeAction = SizeTypeID + TargetAsmInfo::getSLEB128Size(NextAction);
SizeSiteActions += SizeAction;
ActionEntry Action = {ValueForTypeID, NextAction, PrevAction};
I != E; ++I) {
for (MachineBasicBlock::const_iterator MI = I->begin(), E = I->end();
MI != E; ++MI) {
- if (MI->getOpcode() != TargetInstrInfo::LABEL) {
+ if (!MI->isLabel()) {
MayThrow |= MI->getDesc().isCall();
continue;
}
// Try to merge with the previous call-site.
if (CallSites.size()) {
- CallSiteEntry &Prev = CallSites[CallSites.size()-1];
+ CallSiteEntry &Prev = CallSites.back();
if (Site.PadLabel == Prev.PadLabel && Site.Action == Prev.Action) {
// Extend the range of the previous entry.
Prev.EndLabel = Site.EndLabel;
sizeof(int32_t) + // Site length.
sizeof(int32_t)); // Landing pad.
for (unsigned i = 0, e = CallSites.size(); i < e; ++i)
- SizeSites += AsmPrinter::SizeULEB128(CallSites[i].Action);
+ SizeSites += TargetAsmInfo::getULEB128Size(CallSites[i].Action);
unsigned SizeTypes = TypeInfos.size() * TD->getPointerSize();
unsigned TypeOffset = sizeof(int8_t) + // Call site format
// Call-site table length
- AsmPrinter::SizeULEB128(SizeSites) +
+ TargetAsmInfo::getULEB128Size(SizeSites) +
SizeSites + SizeActions + SizeTypes;
unsigned TotalSize = sizeof(int8_t) + // LPStart format
sizeof(int8_t) + // TType format
- AsmPrinter::SizeULEB128(TypeOffset) + // TType base offset
+ TargetAsmInfo::getULEB128Size(TypeOffset) + // TType base offset
TypeOffset;
unsigned SizeAlign = (4 - TotalSize) & 3;
if (!S.BeginLabel) {
BeginLabelPtr = (intptr_t)StartFunction;
- if (TD->getPointerSize() == sizeof(int32_t))
- MCE->emitInt32(0);
- else
- MCE->emitInt64(0);
+ MCE->emitInt32(0);
} else {
BeginLabelPtr = MCE->getLabelAddress(S.BeginLabel);
- if (TD->getPointerSize() == sizeof(int32_t))
- MCE->emitInt32(BeginLabelPtr - (intptr_t)StartFunction);
- else
- MCE->emitInt64(BeginLabelPtr - (intptr_t)StartFunction);
+ MCE->emitInt32(BeginLabelPtr - (intptr_t)StartFunction);
}
// Asm->EOL("Region start");
if (!S.EndLabel) {
EndLabelPtr = (intptr_t)EndFunction;
- if (TD->getPointerSize() == sizeof(int32_t))
- MCE->emitInt32((intptr_t)EndFunction - BeginLabelPtr);
- else
- MCE->emitInt64((intptr_t)EndFunction - BeginLabelPtr);
+ MCE->emitInt32((intptr_t)EndFunction - BeginLabelPtr);
} else {
EndLabelPtr = MCE->getLabelAddress(S.EndLabel);
- if (TD->getPointerSize() == sizeof(int32_t))
- MCE->emitInt32(EndLabelPtr - BeginLabelPtr);
- else
- MCE->emitInt64(EndLabelPtr - BeginLabelPtr);
+ MCE->emitInt32(EndLabelPtr - BeginLabelPtr);
}
//Asm->EOL("Region length");
if (!S.PadLabel) {
- if (TD->getPointerSize() == sizeof(int32_t))
- MCE->emitInt32(0);
- else
- MCE->emitInt64(0);
+ MCE->emitInt32(0);
} else {
unsigned PadLabelPtr = MCE->getLabelAddress(S.PadLabel);
- if (TD->getPointerSize() == sizeof(int32_t))
- MCE->emitInt32(PadLabelPtr - (intptr_t)StartFunction);
- else
- MCE->emitInt64(PadLabelPtr - (intptr_t)StartFunction);
+ MCE->emitInt32(PadLabelPtr - (intptr_t)StartFunction);
}
// Asm->EOL("Landing pad");
unsigned char* StartCommonPtr = (unsigned char*)MCE->getCurrentPCValue();
// EH Common Frame header
- MCE->allocateSpace(PointerSize, 0);
+ MCE->allocateSpace(4, 0);
unsigned char* FrameCommonBeginPtr = (unsigned char*)MCE->getCurrentPCValue();
MCE->emitInt32((int)0);
MCE->emitByte(dwarf::DW_CIE_VERSION);
if (Personality) {
MCE->emitULEB128Bytes(7);
- if (needsIndirectEncoding)
- MCE->emitByte(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4 |
- dwarf::DW_EH_PE_indirect);
- else
- MCE->emitByte(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4);
-
- if (PointerSize == 8)
- MCE->emitInt64((intptr_t)Jit.getPointerToGlobal(Personality) -
- MCE->getCurrentPCValue());
- else
- MCE->emitInt32((intptr_t)Jit.getPointerToGlobal(Personality) -
- MCE->getCurrentPCValue());
+ // Direct encoding, because we use the function pointer. Not relative,
+ // because the current PC value may be bigger than the personality
+ // function pointer.
+ MCE->emitByte(dwarf::DW_EH_PE_sdata4);
+
+ MCE->emitInt32(((intptr_t)Jit.getPointerToGlobal(Personality)));
- MCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel);
- MCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel);
+ MCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4);
+ MCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4);
} else {
MCE->emitULEB128Bytes(1);
- MCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel);
+ MCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4);
}
std::vector<MachineMove> Moves;
RI->getInitialFrameState(Moves);
EmitFrameMoves(0, Moves);
- MCE->emitAlignment(4);
+ MCE->emitAlignment(PointerSize);
- MCE->emitAt((uintptr_t*)StartCommonPtr,
+ MCE->emitInt32At((uintptr_t*)StartCommonPtr,
(uintptr_t)((unsigned char*)MCE->getCurrentPCValue() -
FrameCommonBeginPtr));
// EH frame header.
unsigned char* StartEHPtr = (unsigned char*)MCE->getCurrentPCValue();
- MCE->allocateSpace(PointerSize, 0);
+ MCE->allocateSpace(4, 0);
unsigned char* FrameBeginPtr = (unsigned char*)MCE->getCurrentPCValue();
// FDE CIE Offset
- if (PointerSize == 8) {
- MCE->emitInt64(FrameBeginPtr - StartCommonPtr);
- MCE->emitInt64(StartFunction - (unsigned char*)MCE->getCurrentPCValue());
- MCE->emitInt64(EndFunction - StartFunction);
- } else {
- MCE->emitInt32(FrameBeginPtr - StartCommonPtr);
- MCE->emitInt32(StartFunction - (unsigned char*)MCE->getCurrentPCValue());
- MCE->emitInt32(EndFunction - StartFunction);
- }
+ MCE->emitInt32(FrameBeginPtr - StartCommonPtr);
+ MCE->emitInt32(StartFunction - (unsigned char*)MCE->getCurrentPCValue());
+ MCE->emitInt32(EndFunction - StartFunction);
// If there is a personality and landing pads then point to the language
// specific data area in the exception table.
MCE->emitULEB128Bytes(4);
if (!MMI->getLandingPads().empty()) {
- if (PointerSize == 8)
- MCE->emitInt64(ExceptionTable - (unsigned char*)MCE->getCurrentPCValue());
- else
- MCE->emitInt32(ExceptionTable - (unsigned char*)MCE->getCurrentPCValue());
- } else if (PointerSize == 8) {
- MCE->emitInt64((int)0);
+ MCE->emitInt32(ExceptionTable - (unsigned char*)MCE->getCurrentPCValue());
} else {
MCE->emitInt32((int)0);
}
// frame.
EmitFrameMoves((intptr_t)StartFunction, MMI->getFrameMoves());
- MCE->emitAlignment(4);
+ MCE->emitAlignment(PointerSize);
// Indicate the size of the table
- MCE->emitAt((uintptr_t*)StartEHPtr,
+ MCE->emitInt32At((uintptr_t*)StartEHPtr,
(uintptr_t)((unsigned char*)MCE->getCurrentPCValue() -
StartEHPtr));
FinalSize += GetExceptionTableSizeInBytes(&F);
const std::vector<Function *> Personalities = MMI->getPersonalities();
- FinalSize += GetCommonEHFrameSizeInBytes(Personalities[MMI->getPersonalityIndex()]);
+ FinalSize +=
+ GetCommonEHFrameSizeInBytes(Personalities[MMI->getPersonalityIndex()]);
- FinalSize += GetEHFrameSizeInBytes(Personalities[MMI->getPersonalityIndex()], StartFunction);
+ FinalSize += GetEHFrameSizeInBytes(Personalities[MMI->getPersonalityIndex()],
+ StartFunction);
return FinalSize;
}
// If there is a personality and landing pads then point to the language
// specific data area in the exception table.
if (MMI->getPersonalityIndex()) {
- FinalSize += AsmPrinter::SizeULEB128(4);
+ FinalSize += TargetAsmInfo::getULEB128Size(4);
FinalSize += PointerSize;
} else {
- FinalSize += AsmPrinter::SizeULEB128(0);
+ FinalSize += TargetAsmInfo::getULEB128Size(0);
}
// Indicate locations of function specific callee saved registers in
FinalSize += 4;
FinalSize += 1;
FinalSize += Personality ? 5 : 3; // "zPLR" or "zR"
- FinalSize += AsmPrinter::SizeULEB128(1);
- FinalSize += AsmPrinter::SizeSLEB128(stackGrowth);
+ FinalSize += TargetAsmInfo::getULEB128Size(1);
+ FinalSize += TargetAsmInfo::getSLEB128Size(stackGrowth);
FinalSize += 1;
if (Personality) {
- FinalSize += AsmPrinter::SizeULEB128(7);
+ FinalSize += TargetAsmInfo::getULEB128Size(7);
// Encoding
FinalSize+= 1;
//Personality
FinalSize += PointerSize;
- FinalSize += AsmPrinter::SizeULEB128(dwarf::DW_EH_PE_pcrel);
- FinalSize += AsmPrinter::SizeULEB128(dwarf::DW_EH_PE_pcrel);
+ FinalSize += TargetAsmInfo::getULEB128Size(dwarf::DW_EH_PE_pcrel);
+ FinalSize += TargetAsmInfo::getULEB128Size(dwarf::DW_EH_PE_pcrel);
} else {
- FinalSize += AsmPrinter::SizeULEB128(1);
- FinalSize += AsmPrinter::SizeULEB128(dwarf::DW_EH_PE_pcrel);
+ FinalSize += TargetAsmInfo::getULEB128Size(1);
+ FinalSize += TargetAsmInfo::getULEB128Size(dwarf::DW_EH_PE_pcrel);
}
std::vector<MachineMove> Moves;
}
// If advancing cfa.
- if (Dst.isRegister() && Dst.getRegister() == MachineLocation::VirtualFP) {
- if (!Src.isRegister()) {
- if (Src.getRegister() == MachineLocation::VirtualFP) {
+ if (Dst.isReg() && Dst.getReg() == MachineLocation::VirtualFP) {
+ if (!Src.isReg()) {
+ if (Src.getReg() == MachineLocation::VirtualFP) {
++FinalSize;
} else {
++FinalSize;
- unsigned RegNum = RI->getDwarfRegNum(Src.getRegister(), true);
- FinalSize += AsmPrinter::SizeULEB128(RegNum);
+ unsigned RegNum = RI->getDwarfRegNum(Src.getReg(), true);
+ FinalSize += TargetAsmInfo::getULEB128Size(RegNum);
}
int Offset = -Src.getOffset();
- FinalSize += AsmPrinter::SizeULEB128(Offset);
+ FinalSize += TargetAsmInfo::getULEB128Size(Offset);
} else {
assert(0 && "Machine move no supported yet.");
}
- } else if (Src.isRegister() &&
- Src.getRegister() == MachineLocation::VirtualFP) {
- if (Dst.isRegister()) {
+ } else if (Src.isReg() &&
+ Src.getReg() == MachineLocation::VirtualFP) {
+ if (Dst.isReg()) {
++FinalSize;
- unsigned RegNum = RI->getDwarfRegNum(Dst.getRegister(), true);
- FinalSize += AsmPrinter::SizeULEB128(RegNum);
+ unsigned RegNum = RI->getDwarfRegNum(Dst.getReg(), true);
+ FinalSize += TargetAsmInfo::getULEB128Size(RegNum);
} else {
assert(0 && "Machine move no supported yet.");
}
} else {
- unsigned Reg = RI->getDwarfRegNum(Src.getRegister(), true);
+ unsigned Reg = RI->getDwarfRegNum(Src.getReg(), true);
int Offset = Dst.getOffset() / stackGrowth;
if (Offset < 0) {
++FinalSize;
- FinalSize += AsmPrinter::SizeULEB128(Reg);
- FinalSize += AsmPrinter::SizeSLEB128(Offset);
+ FinalSize += TargetAsmInfo::getULEB128Size(Reg);
+ FinalSize += TargetAsmInfo::getSLEB128Size(Offset);
} else if (Reg < 64) {
++FinalSize;
- FinalSize += AsmPrinter::SizeULEB128(Offset);
+ FinalSize += TargetAsmInfo::getULEB128Size(Offset);
} else {
++FinalSize;
- FinalSize += AsmPrinter::SizeULEB128(Reg);
- FinalSize += AsmPrinter::SizeULEB128(Offset);
+ FinalSize += TargetAsmInfo::getULEB128Size(Reg);
+ FinalSize += TargetAsmInfo::getULEB128Size(Offset);
}
}
}
for(std::vector<unsigned>::const_iterator I = FilterIds.begin(),
E = FilterIds.end(); I != E; ++I) {
FilterOffsets.push_back(Offset);
- Offset -= AsmPrinter::SizeULEB128(*I);
+ Offset -= TargetAsmInfo::getULEB128Size(*I);
}
// Compute the actions table and gather the first action index for each
const unsigned SizePrevIds = LandingPads[i-1]->TypeIds.size();
assert(Actions.size());
PrevAction = &Actions.back();
- SizeAction = AsmPrinter::SizeSLEB128(PrevAction->NextAction) +
- AsmPrinter::SizeSLEB128(PrevAction->ValueForTypeID);
+ SizeAction = TargetAsmInfo::getSLEB128Size(PrevAction->NextAction) +
+ TargetAsmInfo::getSLEB128Size(PrevAction->ValueForTypeID);
for (unsigned j = NumShared; j != SizePrevIds; ++j) {
- SizeAction -= AsmPrinter::SizeSLEB128(PrevAction->ValueForTypeID);
+ SizeAction -= TargetAsmInfo::getSLEB128Size(PrevAction->ValueForTypeID);
SizeAction += -PrevAction->NextAction;
PrevAction = PrevAction->Previous;
}
int TypeID = TypeIds[I];
assert(-1-TypeID < (int)FilterOffsets.size() && "Unknown filter id!");
int ValueForTypeID = TypeID < 0 ? FilterOffsets[-1 - TypeID] : TypeID;
- unsigned SizeTypeID = AsmPrinter::SizeSLEB128(ValueForTypeID);
+ unsigned SizeTypeID = TargetAsmInfo::getSLEB128Size(ValueForTypeID);
int NextAction = SizeAction ? -(SizeAction + SizeTypeID) : 0;
- SizeAction = SizeTypeID + AsmPrinter::SizeSLEB128(NextAction);
+ SizeAction = SizeTypeID + TargetAsmInfo::getSLEB128Size(NextAction);
SizeSiteActions += SizeAction;
ActionEntry Action = {ValueForTypeID, NextAction, PrevAction};
I != E; ++I) {
for (MachineBasicBlock::const_iterator MI = I->begin(), E = I->end();
MI != E; ++MI) {
- if (MI->getOpcode() != TargetInstrInfo::LABEL) {
+ if (!MI->isLabel()) {
MayThrow |= MI->getDesc().isCall();
continue;
}
// Try to merge with the previous call-site.
if (CallSites.size()) {
- CallSiteEntry &Prev = CallSites[CallSites.size()-1];
+ CallSiteEntry &Prev = CallSites.back();
if (Site.PadLabel == Prev.PadLabel && Site.Action == Prev.Action) {
// Extend the range of the previous entry.
Prev.EndLabel = Site.EndLabel;
sizeof(int32_t) + // Site length.
sizeof(int32_t)); // Landing pad.
for (unsigned i = 0, e = CallSites.size(); i < e; ++i)
- SizeSites += AsmPrinter::SizeULEB128(CallSites[i].Action);
+ SizeSites += TargetAsmInfo::getULEB128Size(CallSites[i].Action);
unsigned SizeTypes = TypeInfos.size() * TD->getPointerSize();
unsigned TypeOffset = sizeof(int8_t) + // Call site format
// Call-site table length
- AsmPrinter::SizeULEB128(SizeSites) +
+ TargetAsmInfo::getULEB128Size(SizeSites) +
SizeSites + SizeActions + SizeTypes;
unsigned TotalSize = sizeof(int8_t) + // LPStart format
sizeof(int8_t) + // TType format
- AsmPrinter::SizeULEB128(TypeOffset) + // TType base offset
+ TargetAsmInfo::getULEB128Size(TypeOffset) + // TType base offset
TypeOffset;
unsigned SizeAlign = (4 - TotalSize) & 3;
// Asm->EOL("Landing pad");
FinalSize += PointerSize;
- FinalSize += AsmPrinter::SizeULEB128(S.Action);
+ FinalSize += TargetAsmInfo::getULEB128Size(S.Action);
// Asm->EOL("Action");
}
ActionEntry &Action = Actions[I];
//Asm->EOL("TypeInfo index");
- FinalSize += AsmPrinter::SizeSLEB128(Action.ValueForTypeID);
+ FinalSize += TargetAsmInfo::getSLEB128Size(Action.ValueForTypeID);
//Asm->EOL("Next action");
- FinalSize += AsmPrinter::SizeSLEB128(Action.NextAction);
+ FinalSize += TargetAsmInfo::getSLEB128Size(Action.NextAction);
}
// Emit the type ids.
// Emit the filter typeids.
for (unsigned j = 0, M = FilterIds.size(); j < M; ++j) {
unsigned TypeID = FilterIds[j];
- FinalSize += AsmPrinter::SizeULEB128(TypeID);
+ FinalSize += TargetAsmInfo::getULEB128Size(TypeID);
//Asm->EOL("Filter TypeInfo index");
}