1818#include " llvm/CodeGen/TargetFrameLowering.h"
1919#include " llvm/CodeGen/TargetOpcodes.h"
2020#include " llvm/CodeGen/TargetRegisterInfo.h"
21+ #include " llvm/CodeGen/TargetInstrInfo.h"
2122#include " llvm/CodeGen/TargetSubtargetInfo.h"
2223#include " llvm/IR/DataLayout.h"
2324#include " llvm/MC/MCContext.h"
@@ -219,7 +220,8 @@ static unsigned getDwarfRegNum(unsigned Reg, const TargetRegisterInfo *TRI) {
219220MachineInstr::const_mop_iterator
220221StackMaps::parseOperand (MachineInstr::const_mop_iterator MOI,
221222 MachineInstr::const_mop_iterator MOE,
222- LiveVarsVec &LiveVars, LiveOutVec &LiveOuts) const {
223+ LiveVarsVec &LiveVars, LiveOutVec &LiveOuts,
224+ std::map<Register, int64_t > SpillOffsets) const {
223225 LocationVec &Locs = LiveVars.back ();
224226 const TargetRegisterInfo *TRI = AP.MF ->getSubtarget ().getRegisterInfo ();
225227 if (MOI->isImm ()) {
@@ -282,7 +284,27 @@ StackMaps::parseOperand(MachineInstr::const_mop_iterator MOI,
282284 const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass (MOI->getReg ());
283285 assert (!MOI->getSubReg () && " Physical subreg still around." );
284286
285- unsigned Offset = 0 ;
287+
288+ signed Offset = 0 ;
289+ // Check if there are any mappings for this register in the spillmap. If so,
290+ // encode the additional location in the offset field of the stackmap record
291+ // (which is unused for register locations). Note that this assumes that
292+ // there can only be one additional location for each value, which may turn
293+ // out to be false.
294+ if (MOI->isReg ()) {
295+ Register R = MOI->getReg ();
296+ if (SpillOffsets.count (R) > 0 ) {
297+ Offset = SpillOffsets[R];
298+ assert (SpillOffsets[R] != 0 );
299+ if (Offset > 0 ) {
300+ // If the additional location is another register encode its DWARF id.
301+ // Also temporarily add 1 since 0 is used to mean there is no
302+ // additional location.
303+ Offset = getDwarfRegNum (Offset, TRI) + 1 ;
304+ }
305+ }
306+ }
307+
286308 unsigned DwarfRegNum = getDwarfRegNum (MOI->getReg (), TRI);
287309 unsigned LLVMRegNum = *TRI->getLLVMRegNum (DwarfRegNum, false );
288310 unsigned SubRegIdx = TRI->getSubRegIndex (LLVMRegNum, MOI->getReg ());
@@ -520,6 +542,7 @@ void StackMaps::recordStackMapOpers(const MCSymbol &MILabel,
520542 const MachineInstr &MI, uint64_t ID,
521543 MachineInstr::const_mop_iterator MOI,
522544 MachineInstr::const_mop_iterator MOE,
545+ std::map<Register, int64_t > SpillOffsets,
523546 bool recordResult) {
524547 MCContext &OutContext = AP.OutStreamer ->getContext ();
525548
@@ -529,7 +552,7 @@ void StackMaps::recordStackMapOpers(const MCSymbol &MILabel,
529552 if (recordResult) {
530553 assert (PatchPointOpers (&MI).hasDef () && " Stackmap has no return value." );
531554 parseOperand (MI.operands_begin (), std::next (MI.operands_begin ()), LiveVars,
532- LiveOuts);
555+ LiveOuts, SpillOffsets );
533556 LiveVars.push_back (LocationVec ());
534557 }
535558
@@ -538,7 +561,7 @@ void StackMaps::recordStackMapOpers(const MCSymbol &MILabel,
538561 parseStatepointOpers (MI, MOI, MOE, LiveVars, LiveOuts);
539562 else
540563 while (MOI != MOE)
541- MOI = parseOperand (MOI, MOE, LiveVars, LiveOuts);
564+ MOI = parseOperand (MOI, MOE, LiveVars, LiveOuts, SpillOffsets );
542565
543566 // Move large constants into the constant pool.
544567 for (auto &Locations : LiveVars) {
@@ -611,14 +634,14 @@ void StackMaps::recordStackMapOpers(const MCSymbol &MILabel,
611634 }
612635}
613636
614- void StackMaps::recordStackMap (const MCSymbol &L, const MachineInstr &MI) {
637+ void StackMaps::recordStackMap (const MCSymbol &L, const MachineInstr &MI, std::map<Register, int64_t > SpillOffsets ) {
615638 assert (MI.getOpcode () == TargetOpcode::STACKMAP && " expected stackmap" );
616639
617640 StackMapOpers opers (&MI);
618641 const int64_t ID = MI.getOperand (PatchPointOpers::IDPos).getImm ();
619642 recordStackMapOpers (L, MI, ID,
620643 std::next (MI.operands_begin (), opers.getVarIdx ()),
621- MI.operands_end ());
644+ MI.operands_end (), SpillOffsets );
622645}
623646
624647void StackMaps::recordPatchPoint (const MCSymbol &L, const MachineInstr &MI) {
@@ -627,7 +650,7 @@ void StackMaps::recordPatchPoint(const MCSymbol &L, const MachineInstr &MI) {
627650 PatchPointOpers opers (&MI);
628651 const int64_t ID = opers.getID ();
629652 auto MOI = std::next (MI.operands_begin (), opers.getStackMapStartIdx ());
630- recordStackMapOpers (L, MI, ID, MOI, MI.operands_end (),
653+ recordStackMapOpers (L, MI, ID, MOI, MI.operands_end (), {},
631654 opers.isAnyReg () && opers.hasDef ());
632655
633656#ifndef NDEBUG
@@ -648,7 +671,7 @@ void StackMaps::recordStatepoint(const MCSymbol &L, const MachineInstr &MI) {
648671 StatepointOpers opers (&MI);
649672 const unsigned StartIdx = opers.getVarIdx ();
650673 recordStackMapOpers (L, MI, opers.getID (), MI.operands_begin () + StartIdx,
651- MI.operands_end (), false );
674+ MI.operands_end (), {}, false );
652675}
653676
654677// / Emit the stackmap header.
0 commit comments