[llvm] r279586 - [stackmaps] More extraction of common code [NFCI]
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 23 16:33:30 PDT 2016
Author: reames
Date: Tue Aug 23 18:33:29 2016
New Revision: 279586
URL: http://llvm.org/viewvc/llvm-project?rev=279586&view=rev
Log:
[stackmaps] More extraction of common code [NFCI]
General cleanup before starting to work on the part I want to actually change.
Modified:
llvm/trunk/include/llvm/CodeGen/StackMaps.h
llvm/trunk/lib/CodeGen/StackMaps.cpp
llvm/trunk/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp
llvm/trunk/lib/Target/PowerPC/PPCInstrInfo.cpp
llvm/trunk/lib/Target/X86/X86MCInstLower.cpp
Modified: llvm/trunk/include/llvm/CodeGen/StackMaps.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/StackMaps.h?rev=279586&r1=279585&r2=279586&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/StackMaps.h (original)
+++ llvm/trunk/include/llvm/CodeGen/StackMaps.h Tue Aug 23 18:33:29 2016
@@ -31,9 +31,20 @@ public:
/// Enumerate the meta operands.
enum { IDPos, NBytesPos };
+private:
+ const MachineInstr* MI;
+
public:
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.
/// These hold the "live state".
unsigned getVarIdx() const {
@@ -66,28 +77,50 @@ private:
bool HasDef;
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:
explicit PatchPointOpers(const MachineInstr *MI);
bool isAnyReg() const { return IsAnyReg; }
bool hasDef() const { return HasDef; }
- unsigned getMetaIdx(unsigned Pos = 0) const {
- assert(Pos < MetaEnd && "Meta operand index out of range.");
- return (HasDef ? 1 : 0) + Pos;
+ /// Return the ID for the given patchpoint.
+ uint64_t getID() const { return getMetaOper(IDPos).getImm(); }
+
+ /// Return the number of patchable bytes the given patchpoint should emit.
+ uint32_t getNumPatchBytes() const {
+ return getMetaOper(NBytesPos).getImm();
}
- const MachineOperand &getMetaOper(unsigned Pos) {
- return MI->getOperand(getMetaIdx(Pos));
+ /// Returns the target of the underlying call.
+ 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; }
+ /// 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.
/// These hold the "live state".
unsigned getVarIdx() const {
- return getMetaIdx() + MetaEnd +
- MI->getOperand(getMetaIdx(NArgPos)).getImm();
+ return getMetaIdx() + MetaEnd + getNumCallArgs();
}
/// Get the index at which stack map locations will be recorded.
Modified: llvm/trunk/lib/CodeGen/StackMaps.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/StackMaps.cpp?rev=279586&r1=279585&r2=279586&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/StackMaps.cpp (original)
+++ llvm/trunk/lib/CodeGen/StackMaps.cpp Tue Aug 23 18:33:29 2016
@@ -35,7 +35,8 @@ static cl::opt<int> StackMapVersion(
const char *StackMaps::WSMP = "Stack Maps: ";
-StackMapOpers::StackMapOpers(const MachineInstr *MI) {
+StackMapOpers::StackMapOpers(const MachineInstr *MI)
+ : MI(MI) {
assert(getVarIdx() <= MI->getNumOperands() &&
"invalid stackmap definition");
}
@@ -43,8 +44,7 @@ StackMapOpers::StackMapOpers(const Machi
PatchPointOpers::PatchPointOpers(const MachineInstr *MI)
: MI(MI), HasDef(MI->getOperand(0).isReg() && MI->getOperand(0).isDef() &&
!MI->getOperand(0).isImplicit()),
- IsAnyReg(MI->getOperand(getMetaIdx(CCPos)).getImm() ==
- CallingConv::AnyReg) {
+ IsAnyReg(getCallingConv() == CallingConv::AnyReg) {
#ifndef NDEBUG
unsigned CheckStartIdx = 0, e = MI->getNumOperands();
while (CheckStartIdx < e && MI->getOperand(CheckStartIdx).isReg() &&
@@ -358,8 +358,7 @@ void StackMaps::recordPatchPoint(const M
assert(MI.getOpcode() == TargetOpcode::PATCHPOINT && "expected patchpoint");
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());
recordStackMapOpers(MI, ID, MOI, MI.operands_end(),
opers.isAnyReg() && opers.hasDef());
@@ -368,7 +367,7 @@ void StackMaps::recordPatchPoint(const M
// verify anyregcc
auto &Locations = CSInfos.back().Locations;
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)
assert(Locations[i].Type == Location::Register &&
"anyreg arg must be in reg.");
Modified: llvm/trunk/lib/Target/AArch64/AArch64AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64AsmPrinter.cpp?rev=279586&r1=279585&r2=279586&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64AsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64AsmPrinter.cpp Tue Aug 23 18:33:29 2016
@@ -386,7 +386,7 @@ void AArch64AsmPrinter::LowerPATCHPOINT(
PatchPointOpers Opers(&MI);
- int64_t CallTarget = Opers.getMetaOper(PatchPointOpers::TargetPos).getImm();
+ int64_t CallTarget = Opers.getCallTarget().getImm();
unsigned EncodedBytes = 0;
if (CallTarget) {
assert((CallTarget & 0xFFFFFFFFFFFF) == CallTarget &&
@@ -411,7 +411,7 @@ void AArch64AsmPrinter::LowerPATCHPOINT(
EmitToStreamer(OutStreamer, MCInstBuilder(AArch64::BLR).addReg(ScratchReg));
}
// Emit padding.
- unsigned NumBytes = Opers.getMetaOper(PatchPointOpers::NBytesPos).getImm();
+ unsigned NumBytes = Opers.getNumPatchBytes();
assert(NumBytes >= EncodedBytes &&
"Patchpoint can't request size less than the length of a call.");
assert((NumBytes - EncodedBytes) % 4 == 0 &&
Modified: llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp?rev=279586&r1=279585&r2=279586&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp Tue Aug 23 18:33:29 2016
@@ -347,11 +347,10 @@ void PPCAsmPrinter::LowerPATCHPOINT(Stac
PatchPointOpers Opers(&MI);
unsigned EncodedBytes = 0;
- const MachineOperand &CalleeMO =
- Opers.getMetaOper(PatchPointOpers::TargetPos);
+ const MachineOperand &CalleeMO = Opers.getCallTarget();
if (CalleeMO.isImm()) {
- int64_t CallTarget = Opers.getMetaOper(PatchPointOpers::TargetPos).getImm();
+ int64_t CallTarget = CalleeMO.getImm();
if (CallTarget) {
assert((CallTarget & 0xFFFFFFFFFFFF) == CallTarget &&
"High 16 bits of call target should be zero.");
@@ -430,7 +429,7 @@ void PPCAsmPrinter::LowerPATCHPOINT(Stac
EncodedBytes *= 4;
// Emit padding.
- unsigned NumBytes = Opers.getMetaOper(PatchPointOpers::NBytesPos).getImm();
+ unsigned NumBytes = Opers.getNumPatchBytes();
assert(NumBytes >= EncodedBytes &&
"Patchpoint can't request size less than the length of a call.");
assert((NumBytes - EncodedBytes) % 4 == 0 &&
Modified: llvm/trunk/lib/Target/PowerPC/PPCInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCInstrInfo.cpp?rev=279586&r1=279585&r2=279586&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCInstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCInstrInfo.cpp Tue Aug 23 18:33:29 2016
@@ -1816,10 +1816,11 @@ unsigned PPCInstrInfo::getInstSizeInByte
const char *AsmStr = MI.getOperand(0).getSymbolName();
return getInlineAsmLength(AsmStr, *MF->getTarget().getMCAsmInfo());
} else if (Opcode == TargetOpcode::STACKMAP) {
- return MI.getOperand(1).getImm();
+ StackMapOpers Opers(&MI);
+ return Opers.getNumPatchBytes();
} else if (Opcode == TargetOpcode::PATCHPOINT) {
PatchPointOpers Opers(&MI);
- return Opers.getMetaOper(PatchPointOpers::NBytesPos).getImm();
+ return Opers.getNumPatchBytes();
} else {
const MCInstrDesc &Desc = get(Opcode);
return Desc.getSize();
Modified: llvm/trunk/lib/Target/X86/X86MCInstLower.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86MCInstLower.cpp?rev=279586&r1=279585&r2=279586&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86MCInstLower.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86MCInstLower.cpp Tue Aug 23 18:33:29 2016
@@ -979,8 +979,7 @@ void X86AsmPrinter::LowerPATCHPOINT(cons
PatchPointOpers opers(&MI);
unsigned ScratchIdx = opers.getNextScratchIdx();
unsigned EncodedBytes = 0;
- const MachineOperand &CalleeMO =
- opers.getMetaOper(PatchPointOpers::TargetPos);
+ const MachineOperand &CalleeMO = opers.getCallTarget();
// Check for null target. If target is non-null (i.e. is non-zero or is
// symbolic) then emit a call.
@@ -1016,7 +1015,7 @@ void X86AsmPrinter::LowerPATCHPOINT(cons
}
// Emit padding.
- unsigned NumBytes = opers.getMetaOper(PatchPointOpers::NBytesPos).getImm();
+ unsigned NumBytes = opers.getNumPatchBytes();
assert(NumBytes >= EncodedBytes &&
"Patchpoint can't request size less than the length of a call.");
More information about the llvm-commits
mailing list