mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 05:01:59 +01:00
[stackmaps] More extraction of common code [NFCI]
General cleanup before starting to work on the part I want to actually change. llvm-svn: 279586
This commit is contained in:
parent
8f5cdd38cc
commit
9893373aa7
@ -31,9 +31,20 @@ public:
|
|||||||
/// Enumerate the meta operands.
|
/// Enumerate the meta operands.
|
||||||
enum { IDPos, NBytesPos };
|
enum { IDPos, NBytesPos };
|
||||||
|
|
||||||
|
private:
|
||||||
|
const MachineInstr* MI;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit StackMapOpers(const MachineInstr *MI);
|
explicit StackMapOpers(const MachineInstr *MI);
|
||||||
|
|
||||||
|
/// Return the ID for the given stackmap
|
||||||
|
uint64_t getID() const { return MI->getOperand(IDPos).getImm(); }
|
||||||
|
|
||||||
|
/// Return the number of patchable bytes the given stackmap should emit.
|
||||||
|
uint32_t getNumPatchBytes() const {
|
||||||
|
return MI->getOperand(NBytesPos).getImm();
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the operand index of the variable list of non-argument operands.
|
/// Get the operand index of the variable list of non-argument operands.
|
||||||
/// These hold the "live state".
|
/// These hold the "live state".
|
||||||
unsigned getVarIdx() const {
|
unsigned getVarIdx() const {
|
||||||
@ -66,28 +77,50 @@ private:
|
|||||||
bool HasDef;
|
bool HasDef;
|
||||||
bool IsAnyReg;
|
bool IsAnyReg;
|
||||||
|
|
||||||
|
unsigned getMetaIdx(unsigned Pos = 0) const {
|
||||||
|
assert(Pos < MetaEnd && "Meta operand index out of range.");
|
||||||
|
return (HasDef ? 1 : 0) + Pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
const MachineOperand &getMetaOper(unsigned Pos) const {
|
||||||
|
return MI->getOperand(getMetaIdx(Pos));
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PatchPointOpers(const MachineInstr *MI);
|
explicit PatchPointOpers(const MachineInstr *MI);
|
||||||
|
|
||||||
bool isAnyReg() const { return IsAnyReg; }
|
bool isAnyReg() const { return IsAnyReg; }
|
||||||
bool hasDef() const { return HasDef; }
|
bool hasDef() const { return HasDef; }
|
||||||
|
|
||||||
unsigned getMetaIdx(unsigned Pos = 0) const {
|
/// Return the ID for the given patchpoint.
|
||||||
assert(Pos < MetaEnd && "Meta operand index out of range.");
|
uint64_t getID() const { return getMetaOper(IDPos).getImm(); }
|
||||||
return (HasDef ? 1 : 0) + Pos;
|
|
||||||
|
/// Return the number of patchable bytes the given patchpoint should emit.
|
||||||
|
uint32_t getNumPatchBytes() const {
|
||||||
|
return getMetaOper(NBytesPos).getImm();
|
||||||
}
|
}
|
||||||
|
|
||||||
const MachineOperand &getMetaOper(unsigned Pos) {
|
/// Returns the target of the underlying call.
|
||||||
return MI->getOperand(getMetaIdx(Pos));
|
const MachineOperand &getCallTarget() const {
|
||||||
|
return getMetaOper(TargetPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the calling convention
|
||||||
|
CallingConv::ID getCallingConv() const {
|
||||||
|
return getMetaOper(CCPos).getImm();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned getArgIdx() const { return getMetaIdx() + MetaEnd; }
|
unsigned getArgIdx() const { return getMetaIdx() + MetaEnd; }
|
||||||
|
|
||||||
|
/// Return the number of call arguments
|
||||||
|
uint32_t getNumCallArgs() const {
|
||||||
|
return MI->getOperand(getMetaIdx(NArgPos)).getImm();
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the operand index of the variable list of non-argument operands.
|
/// Get the operand index of the variable list of non-argument operands.
|
||||||
/// These hold the "live state".
|
/// These hold the "live state".
|
||||||
unsigned getVarIdx() const {
|
unsigned getVarIdx() const {
|
||||||
return getMetaIdx() + MetaEnd +
|
return getMetaIdx() + MetaEnd + getNumCallArgs();
|
||||||
MI->getOperand(getMetaIdx(NArgPos)).getImm();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the index at which stack map locations will be recorded.
|
/// Get the index at which stack map locations will be recorded.
|
||||||
|
@ -35,7 +35,8 @@ static cl::opt<int> StackMapVersion(
|
|||||||
|
|
||||||
const char *StackMaps::WSMP = "Stack Maps: ";
|
const char *StackMaps::WSMP = "Stack Maps: ";
|
||||||
|
|
||||||
StackMapOpers::StackMapOpers(const MachineInstr *MI) {
|
StackMapOpers::StackMapOpers(const MachineInstr *MI)
|
||||||
|
: MI(MI) {
|
||||||
assert(getVarIdx() <= MI->getNumOperands() &&
|
assert(getVarIdx() <= MI->getNumOperands() &&
|
||||||
"invalid stackmap definition");
|
"invalid stackmap definition");
|
||||||
}
|
}
|
||||||
@ -43,8 +44,7 @@ StackMapOpers::StackMapOpers(const MachineInstr *MI) {
|
|||||||
PatchPointOpers::PatchPointOpers(const MachineInstr *MI)
|
PatchPointOpers::PatchPointOpers(const MachineInstr *MI)
|
||||||
: MI(MI), HasDef(MI->getOperand(0).isReg() && MI->getOperand(0).isDef() &&
|
: MI(MI), HasDef(MI->getOperand(0).isReg() && MI->getOperand(0).isDef() &&
|
||||||
!MI->getOperand(0).isImplicit()),
|
!MI->getOperand(0).isImplicit()),
|
||||||
IsAnyReg(MI->getOperand(getMetaIdx(CCPos)).getImm() ==
|
IsAnyReg(getCallingConv() == CallingConv::AnyReg) {
|
||||||
CallingConv::AnyReg) {
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
unsigned CheckStartIdx = 0, e = MI->getNumOperands();
|
unsigned CheckStartIdx = 0, e = MI->getNumOperands();
|
||||||
while (CheckStartIdx < e && MI->getOperand(CheckStartIdx).isReg() &&
|
while (CheckStartIdx < e && MI->getOperand(CheckStartIdx).isReg() &&
|
||||||
@ -358,8 +358,7 @@ void StackMaps::recordPatchPoint(const MachineInstr &MI) {
|
|||||||
assert(MI.getOpcode() == TargetOpcode::PATCHPOINT && "expected patchpoint");
|
assert(MI.getOpcode() == TargetOpcode::PATCHPOINT && "expected patchpoint");
|
||||||
|
|
||||||
PatchPointOpers opers(&MI);
|
PatchPointOpers opers(&MI);
|
||||||
const int64_t ID = opers.getMetaOper(PatchPointOpers::IDPos).getImm();
|
const int64_t ID = opers.getID();
|
||||||
|
|
||||||
auto MOI = std::next(MI.operands_begin(), opers.getStackMapStartIdx());
|
auto MOI = std::next(MI.operands_begin(), opers.getStackMapStartIdx());
|
||||||
recordStackMapOpers(MI, ID, MOI, MI.operands_end(),
|
recordStackMapOpers(MI, ID, MOI, MI.operands_end(),
|
||||||
opers.isAnyReg() && opers.hasDef());
|
opers.isAnyReg() && opers.hasDef());
|
||||||
@ -368,7 +367,7 @@ void StackMaps::recordPatchPoint(const MachineInstr &MI) {
|
|||||||
// verify anyregcc
|
// verify anyregcc
|
||||||
auto &Locations = CSInfos.back().Locations;
|
auto &Locations = CSInfos.back().Locations;
|
||||||
if (opers.isAnyReg()) {
|
if (opers.isAnyReg()) {
|
||||||
unsigned NArgs = opers.getMetaOper(PatchPointOpers::NArgPos).getImm();
|
unsigned NArgs = opers.getNumCallArgs();
|
||||||
for (unsigned i = 0, e = (opers.hasDef() ? NArgs + 1 : NArgs); i != e; ++i)
|
for (unsigned i = 0, e = (opers.hasDef() ? NArgs + 1 : NArgs); i != e; ++i)
|
||||||
assert(Locations[i].Type == Location::Register &&
|
assert(Locations[i].Type == Location::Register &&
|
||||||
"anyreg arg must be in reg.");
|
"anyreg arg must be in reg.");
|
||||||
|
@ -386,7 +386,7 @@ void AArch64AsmPrinter::LowerPATCHPOINT(MCStreamer &OutStreamer, StackMaps &SM,
|
|||||||
|
|
||||||
PatchPointOpers Opers(&MI);
|
PatchPointOpers Opers(&MI);
|
||||||
|
|
||||||
int64_t CallTarget = Opers.getMetaOper(PatchPointOpers::TargetPos).getImm();
|
int64_t CallTarget = Opers.getCallTarget().getImm();
|
||||||
unsigned EncodedBytes = 0;
|
unsigned EncodedBytes = 0;
|
||||||
if (CallTarget) {
|
if (CallTarget) {
|
||||||
assert((CallTarget & 0xFFFFFFFFFFFF) == CallTarget &&
|
assert((CallTarget & 0xFFFFFFFFFFFF) == CallTarget &&
|
||||||
@ -411,7 +411,7 @@ void AArch64AsmPrinter::LowerPATCHPOINT(MCStreamer &OutStreamer, StackMaps &SM,
|
|||||||
EmitToStreamer(OutStreamer, MCInstBuilder(AArch64::BLR).addReg(ScratchReg));
|
EmitToStreamer(OutStreamer, MCInstBuilder(AArch64::BLR).addReg(ScratchReg));
|
||||||
}
|
}
|
||||||
// Emit padding.
|
// Emit padding.
|
||||||
unsigned NumBytes = Opers.getMetaOper(PatchPointOpers::NBytesPos).getImm();
|
unsigned NumBytes = Opers.getNumPatchBytes();
|
||||||
assert(NumBytes >= EncodedBytes &&
|
assert(NumBytes >= EncodedBytes &&
|
||||||
"Patchpoint can't request size less than the length of a call.");
|
"Patchpoint can't request size less than the length of a call.");
|
||||||
assert((NumBytes - EncodedBytes) % 4 == 0 &&
|
assert((NumBytes - EncodedBytes) % 4 == 0 &&
|
||||||
|
@ -347,11 +347,10 @@ void PPCAsmPrinter::LowerPATCHPOINT(StackMaps &SM, const MachineInstr &MI) {
|
|||||||
PatchPointOpers Opers(&MI);
|
PatchPointOpers Opers(&MI);
|
||||||
|
|
||||||
unsigned EncodedBytes = 0;
|
unsigned EncodedBytes = 0;
|
||||||
const MachineOperand &CalleeMO =
|
const MachineOperand &CalleeMO = Opers.getCallTarget();
|
||||||
Opers.getMetaOper(PatchPointOpers::TargetPos);
|
|
||||||
|
|
||||||
if (CalleeMO.isImm()) {
|
if (CalleeMO.isImm()) {
|
||||||
int64_t CallTarget = Opers.getMetaOper(PatchPointOpers::TargetPos).getImm();
|
int64_t CallTarget = CalleeMO.getImm();
|
||||||
if (CallTarget) {
|
if (CallTarget) {
|
||||||
assert((CallTarget & 0xFFFFFFFFFFFF) == CallTarget &&
|
assert((CallTarget & 0xFFFFFFFFFFFF) == CallTarget &&
|
||||||
"High 16 bits of call target should be zero.");
|
"High 16 bits of call target should be zero.");
|
||||||
@ -430,7 +429,7 @@ void PPCAsmPrinter::LowerPATCHPOINT(StackMaps &SM, const MachineInstr &MI) {
|
|||||||
EncodedBytes *= 4;
|
EncodedBytes *= 4;
|
||||||
|
|
||||||
// Emit padding.
|
// Emit padding.
|
||||||
unsigned NumBytes = Opers.getMetaOper(PatchPointOpers::NBytesPos).getImm();
|
unsigned NumBytes = Opers.getNumPatchBytes();
|
||||||
assert(NumBytes >= EncodedBytes &&
|
assert(NumBytes >= EncodedBytes &&
|
||||||
"Patchpoint can't request size less than the length of a call.");
|
"Patchpoint can't request size less than the length of a call.");
|
||||||
assert((NumBytes - EncodedBytes) % 4 == 0 &&
|
assert((NumBytes - EncodedBytes) % 4 == 0 &&
|
||||||
|
@ -1816,10 +1816,11 @@ unsigned PPCInstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
|
|||||||
const char *AsmStr = MI.getOperand(0).getSymbolName();
|
const char *AsmStr = MI.getOperand(0).getSymbolName();
|
||||||
return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo());
|
return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo());
|
||||||
} else if (Opcode == TargetOpcode::STACKMAP) {
|
} else if (Opcode == TargetOpcode::STACKMAP) {
|
||||||
return MI.getOperand(1).getImm();
|
StackMapOpers Opers(&MI);
|
||||||
|
return Opers.getNumPatchBytes();
|
||||||
} else if (Opcode == TargetOpcode::PATCHPOINT) {
|
} else if (Opcode == TargetOpcode::PATCHPOINT) {
|
||||||
PatchPointOpers Opers(&MI);
|
PatchPointOpers Opers(&MI);
|
||||||
return Opers.getMetaOper(PatchPointOpers::NBytesPos).getImm();
|
return Opers.getNumPatchBytes();
|
||||||
} else {
|
} else {
|
||||||
const MCInstrDesc &Desc = get(Opcode);
|
const MCInstrDesc &Desc = get(Opcode);
|
||||||
return Desc.getSize();
|
return Desc.getSize();
|
||||||
|
@ -979,8 +979,7 @@ void X86AsmPrinter::LowerPATCHPOINT(const MachineInstr &MI,
|
|||||||
PatchPointOpers opers(&MI);
|
PatchPointOpers opers(&MI);
|
||||||
unsigned ScratchIdx = opers.getNextScratchIdx();
|
unsigned ScratchIdx = opers.getNextScratchIdx();
|
||||||
unsigned EncodedBytes = 0;
|
unsigned EncodedBytes = 0;
|
||||||
const MachineOperand &CalleeMO =
|
const MachineOperand &CalleeMO = opers.getCallTarget();
|
||||||
opers.getMetaOper(PatchPointOpers::TargetPos);
|
|
||||||
|
|
||||||
// Check for null target. If target is non-null (i.e. is non-zero or is
|
// Check for null target. If target is non-null (i.e. is non-zero or is
|
||||||
// symbolic) then emit a call.
|
// symbolic) then emit a call.
|
||||||
@ -1016,7 +1015,7 @@ void X86AsmPrinter::LowerPATCHPOINT(const MachineInstr &MI,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Emit padding.
|
// Emit padding.
|
||||||
unsigned NumBytes = opers.getMetaOper(PatchPointOpers::NBytesPos).getImm();
|
unsigned NumBytes = opers.getNumPatchBytes();
|
||||||
assert(NumBytes >= EncodedBytes &&
|
assert(NumBytes >= EncodedBytes &&
|
||||||
"Patchpoint can't request size less than the length of a call.");
|
"Patchpoint can't request size less than the length of a call.");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user