18
18
#include " llvm/CodeGen/TargetFrameLowering.h"
19
19
#include " llvm/CodeGen/TargetOpcodes.h"
20
20
#include " llvm/CodeGen/TargetRegisterInfo.h"
21
+ #include " llvm/CodeGen/TargetInstrInfo.h"
21
22
#include " llvm/CodeGen/TargetSubtargetInfo.h"
22
23
#include " llvm/IR/DataLayout.h"
23
24
#include " llvm/MC/MCContext.h"
@@ -219,7 +220,8 @@ static unsigned getDwarfRegNum(unsigned Reg, const TargetRegisterInfo *TRI) {
219
220
MachineInstr::const_mop_iterator
220
221
StackMaps::parseOperand (MachineInstr::const_mop_iterator MOI,
221
222
MachineInstr::const_mop_iterator MOE,
222
- LiveVarsVec &LiveVars, LiveOutVec &LiveOuts) const {
223
+ LiveVarsVec &LiveVars, LiveOutVec &LiveOuts,
224
+ std::map<Register, int64_t > SpillOffsets) const {
223
225
LocationVec &Locs = LiveVars.back ();
224
226
const TargetRegisterInfo *TRI = AP.MF ->getSubtarget ().getRegisterInfo ();
225
227
if (MOI->isImm ()) {
@@ -282,7 +284,27 @@ StackMaps::parseOperand(MachineInstr::const_mop_iterator MOI,
282
284
const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass (MOI->getReg ());
283
285
assert (!MOI->getSubReg () && " Physical subreg still around." );
284
286
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
+
286
308
unsigned DwarfRegNum = getDwarfRegNum (MOI->getReg (), TRI);
287
309
unsigned LLVMRegNum = *TRI->getLLVMRegNum (DwarfRegNum, false );
288
310
unsigned SubRegIdx = TRI->getSubRegIndex (LLVMRegNum, MOI->getReg ());
@@ -520,6 +542,7 @@ void StackMaps::recordStackMapOpers(const MCSymbol &MILabel,
520
542
const MachineInstr &MI, uint64_t ID,
521
543
MachineInstr::const_mop_iterator MOI,
522
544
MachineInstr::const_mop_iterator MOE,
545
+ std::map<Register, int64_t > SpillOffsets,
523
546
bool recordResult) {
524
547
MCContext &OutContext = AP.OutStreamer ->getContext ();
525
548
@@ -529,7 +552,7 @@ void StackMaps::recordStackMapOpers(const MCSymbol &MILabel,
529
552
if (recordResult) {
530
553
assert (PatchPointOpers (&MI).hasDef () && " Stackmap has no return value." );
531
554
parseOperand (MI.operands_begin (), std::next (MI.operands_begin ()), LiveVars,
532
- LiveOuts);
555
+ LiveOuts, SpillOffsets );
533
556
LiveVars.push_back (LocationVec ());
534
557
}
535
558
@@ -538,7 +561,7 @@ void StackMaps::recordStackMapOpers(const MCSymbol &MILabel,
538
561
parseStatepointOpers (MI, MOI, MOE, LiveVars, LiveOuts);
539
562
else
540
563
while (MOI != MOE)
541
- MOI = parseOperand (MOI, MOE, LiveVars, LiveOuts);
564
+ MOI = parseOperand (MOI, MOE, LiveVars, LiveOuts, SpillOffsets );
542
565
543
566
// Move large constants into the constant pool.
544
567
for (auto &Locations : LiveVars) {
@@ -611,14 +634,14 @@ void StackMaps::recordStackMapOpers(const MCSymbol &MILabel,
611
634
}
612
635
}
613
636
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 ) {
615
638
assert (MI.getOpcode () == TargetOpcode::STACKMAP && " expected stackmap" );
616
639
617
640
StackMapOpers opers (&MI);
618
641
const int64_t ID = MI.getOperand (PatchPointOpers::IDPos).getImm ();
619
642
recordStackMapOpers (L, MI, ID,
620
643
std::next (MI.operands_begin (), opers.getVarIdx ()),
621
- MI.operands_end ());
644
+ MI.operands_end (), SpillOffsets );
622
645
}
623
646
624
647
void StackMaps::recordPatchPoint (const MCSymbol &L, const MachineInstr &MI) {
@@ -627,7 +650,7 @@ void StackMaps::recordPatchPoint(const MCSymbol &L, const MachineInstr &MI) {
627
650
PatchPointOpers opers (&MI);
628
651
const int64_t ID = opers.getID ();
629
652
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 (), {},
631
654
opers.isAnyReg () && opers.hasDef ());
632
655
633
656
#ifndef NDEBUG
@@ -648,7 +671,7 @@ void StackMaps::recordStatepoint(const MCSymbol &L, const MachineInstr &MI) {
648
671
StatepointOpers opers (&MI);
649
672
const unsigned StartIdx = opers.getVarIdx ();
650
673
recordStackMapOpers (L, MI, opers.getID (), MI.operands_begin () + StartIdx,
651
- MI.operands_end (), false );
674
+ MI.operands_end (), {}, false );
652
675
}
653
676
654
677
// / Emit the stackmap header.
0 commit comments