-// [<def>], <id>, <numBytes>, <target>, <numArgs>
-static void LowerPATCHPOINT(MCStreamer &OutStreamer,
- X86MCInstLower &MCInstLowering,
- StackMaps &SM,
- const MachineInstr &MI) {
- bool hasDef = MI.getOperand(0).isReg() && MI.getOperand(0).isDef() &&
- !MI.getOperand(0).isImplicit();
- unsigned StartIdx = hasDef ? 1 : 0;
-#ifndef NDEBUG
- {
- unsigned StartIdx2 = 0, e = MI.getNumOperands();
- while (StartIdx2 < e && MI.getOperand(StartIdx2).isReg() &&
- MI.getOperand(StartIdx2).isDef() &&
- !MI.getOperand(StartIdx2).isImplicit())
- ++StartIdx2;
-
- assert(StartIdx == StartIdx2 &&
- "Unexpected additonal definition in Patchpoint intrinsic.");
- }
-#endif
-
- // Find the first scratch register (implicit def and early clobber)
- unsigned ScratchIdx = StartIdx, e = MI.getNumOperands();
- while (ScratchIdx < e &&
- !(MI.getOperand(ScratchIdx).isReg() &&
- MI.getOperand(ScratchIdx).isDef() &&
- MI.getOperand(ScratchIdx).isImplicit() &&
- MI.getOperand(ScratchIdx).isEarlyClobber()))
- ++ScratchIdx;
-
- assert(ScratchIdx != e && "No scratch register available");
-
- int64_t ID = MI.getOperand(StartIdx).getImm();
- assert((int32_t)ID == ID && "Stack maps hold 32-bit IDs");
-
- // Get the number of arguments participating in the call. This number was
- // adjusted during call lowering by subtracting stack args.
- bool isAnyRegCC = MI.getOperand(StartIdx + 4).getImm() == CallingConv::AnyReg;
- assert(((hasDef && isAnyRegCC) || !hasDef) &&
- "Only Patchpoints with AnyReg calling convention may have a result");
- int64_t StackMapIdx = isAnyRegCC ? StartIdx + 5 :
- StartIdx + 5 + MI.getOperand(StartIdx + 3).getImm();
- assert(StackMapIdx <= MI.getNumOperands() &&
- "Patchpoint intrinsic dropped arguments.");
-
- SM.recordStackMap(MI, ID, llvm::next(MI.operands_begin(), StackMapIdx),
- getStackMapEndMOP(MI.operands_begin(), MI.operands_end()),
- isAnyRegCC && hasDef);
-
+// [<def>], <id>, <numBytes>, <target>, <numArgs>, <cc>, ...
+static void LowerPATCHPOINT(MCStreamer &OS, StackMaps &SM,
+ const MachineInstr &MI, bool Is64Bit, const MCSubtargetInfo& STI) {
+ assert(Is64Bit && "Patchpoint currently only supports X86-64");
+ SM.recordPatchPoint(MI);
+
+ PatchPointOpers opers(&MI);
+ unsigned ScratchIdx = opers.getNextScratchIdx();