From 87aa10ba09392efab57554bb0af1dc1c3b700eba Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Tue, 23 Aug 2016 21:21:43 +0000 Subject: [PATCH] [stackmaps] Extract out magic constants [NFCI] This is a first step towards clarifying the exact MI semantics of stackmap's "live values". git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279574 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/StackMaps.h | 23 +++++++++++++++++++++++ lib/CodeGen/StackMaps.cpp | 13 ++++++++++--- lib/CodeGen/TargetInstrInfo.cpp | 10 +++++++--- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/include/llvm/CodeGen/StackMaps.h b/include/llvm/CodeGen/StackMaps.h index 918848f6b2a..b3fd1d6b735 100644 --- a/include/llvm/CodeGen/StackMaps.h +++ b/include/llvm/CodeGen/StackMaps.h @@ -22,6 +22,29 @@ class AsmPrinter; class MCExpr; class MCStreamer; +/// \brief MI-level stackmap operands. +/// +/// MI slackmap operations take the form: +/// , , live args... +class StackMapOpers { +public: + /// Enumerate the meta operands. + enum { IDPos, NBytesPos }; + +private: + const MachineInstr *MI; + +public: + explicit StackMapOpers(const MachineInstr *MI); + + /// Get the operand index of the variable list of non-argument operands. + /// These hold the "live state". + unsigned getVarIdx() const { + // Skip ID, nShadowBytes. + return 2; + } +}; + /// \brief MI-level patchpoint operands. /// /// MI patchpoint operations take the form: diff --git a/lib/CodeGen/StackMaps.cpp b/lib/CodeGen/StackMaps.cpp index 01ce527e9ae..7d5e20c281f 100644 --- a/lib/CodeGen/StackMaps.cpp +++ b/lib/CodeGen/StackMaps.cpp @@ -35,6 +35,12 @@ static cl::opt StackMapVersion( const char *StackMaps::WSMP = "Stack Maps: "; +StackMapOpers::StackMapOpers(const MachineInstr *MI) + : MI(MI) { + assert(getVarIdx() <= MI->getNumOperands() && + "invalid stackmap definition"); +} + PatchPointOpers::PatchPointOpers(const MachineInstr *MI) : MI(MI), HasDef(MI->getOperand(0).isReg() && MI->getOperand(0).isDef() && !MI->getOperand(0).isImplicit()), @@ -343,8 +349,9 @@ void StackMaps::recordStackMapOpers(const MachineInstr &MI, uint64_t ID, void StackMaps::recordStackMap(const MachineInstr &MI) { assert(MI.getOpcode() == TargetOpcode::STACKMAP && "expected stackmap"); - int64_t ID = MI.getOperand(0).getImm(); - recordStackMapOpers(MI, ID, std::next(MI.operands_begin(), 2), + StackMapOpers opers(&MI); + const int64_t ID = MI.getOperand(PatchPointOpers::IDPos).getImm(); + recordStackMapOpers(MI, ID, std::next(MI.operands_begin(), opers.getVarIdx()), MI.operands_end()); } @@ -352,7 +359,7 @@ void StackMaps::recordPatchPoint(const MachineInstr &MI) { assert(MI.getOpcode() == TargetOpcode::PATCHPOINT && "expected patchpoint"); PatchPointOpers opers(&MI); - int64_t ID = opers.getMetaOper(PatchPointOpers::IDPos).getImm(); + const int64_t ID = opers.getMetaOper(PatchPointOpers::IDPos).getImm(); auto MOI = std::next(MI.operands_begin(), opers.getStackMapStartIdx()); recordStackMapOpers(MI, ID, MOI, MI.operands_end(), diff --git a/lib/CodeGen/TargetInstrInfo.cpp b/lib/CodeGen/TargetInstrInfo.cpp index 78eb567daf8..3982e1e71d1 100644 --- a/lib/CodeGen/TargetInstrInfo.cpp +++ b/lib/CodeGen/TargetInstrInfo.cpp @@ -437,11 +437,15 @@ static MachineInstr *foldPatchpoint(MachineFunction &MF, MachineInstr &MI, const TargetInstrInfo &TII) { unsigned StartIdx = 0; switch (MI.getOpcode()) { - case TargetOpcode::STACKMAP: - StartIdx = 2; // Skip ID, nShadowBytes. + case TargetOpcode::STACKMAP: { + // StackMapLiveValues are foldable + StackMapOpers opers(&MI); + StartIdx = opers.getVarIdx(); break; + } case TargetOpcode::PATCHPOINT: { - // For PatchPoint, the call args are not foldable. + // For PatchPoint, the call args are not foldable (even if reported in the + // stackmap e.g. via anyregcc). PatchPointOpers opers(&MI); StartIdx = opers.getVarIdx(); break; -- 2.11.0