Skip to content

Commit afc9748

Browse files
dantrushinmemfrob
authored andcommitted
[Statepoint] Add getters to StatepointOpers.
To simplify future work on statepoint representation, hide direct access to statepoint field indices and provide getters for them. Add getters for couple more statepoint fields. This also fixes two bugs in MachineVerifier for statepoint: First, the `break` statement was falling out of `if` statement scope, thus disabling following checks. Second, it was incorrectly accessing some fields like CallingConv - StatepointOpers gives index to their value directly, not to preceeding field type encoding. Reviewed By: skatkov Differential Revision: https://reviews.llvm.org/D78119
1 parent d0d37ca commit afc9748

File tree

3 files changed

+50
-22
lines changed

3 files changed

+50
-22
lines changed

llvm/include/llvm/CodeGen/StackMaps.h

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,23 +156,44 @@ class StatepointOpers {
156156
// Flags should be part of meta operands, with args and deopt operands, and
157157
// gc operands all prefixed by their length and a type code. This would be
158158
// much more consistent.
159-
public:
160-
// These values are aboolute offsets into the operands of the statepoint
159+
160+
// These values are absolute offsets into the operands of the statepoint
161161
// instruction.
162162
enum { IDPos, NBytesPos, NCallArgsPos, CallTargetPos, MetaEnd };
163163

164-
// These values are relative offests from the start of the statepoint meta
164+
// These values are relative offsets from the start of the statepoint meta
165165
// arguments (i.e. the end of the call arguments).
166166
enum { CCOffset = 1, FlagsOffset = 3, NumDeoptOperandsOffset = 5 };
167167

168+
public:
168169
explicit StatepointOpers(const MachineInstr *MI) : MI(MI) {}
169170

171+
/// Get index of statepoint ID operand.
172+
unsigned getIDPos() const { return IDPos; }
173+
174+
/// Get index of Num Patch Bytes operand.
175+
unsigned getNBytesPos() const { return NBytesPos; }
176+
177+
/// Get index of Num Call Arguments operand.
178+
unsigned getNCallArgsPos() const { return NCallArgsPos; }
179+
170180
/// Get starting index of non call related arguments
171181
/// (calling convention, statepoint flags, vm state and gc state).
172182
unsigned getVarIdx() const {
173183
return MI->getOperand(NCallArgsPos).getImm() + MetaEnd;
174184
}
175185

186+
/// Get index of Calling Convention operand.
187+
unsigned getCCIdx() const { return getVarIdx() + CCOffset; }
188+
189+
/// Get index of Flags operand.
190+
unsigned getFlagsIdx() const { return getVarIdx() + FlagsOffset; }
191+
192+
/// Get index of Number Deopt Arguments operand.
193+
unsigned getNumDeoptArgsIdx() const {
194+
return getVarIdx() + NumDeoptOperandsOffset;
195+
}
196+
176197
/// Return the ID for the given statepoint.
177198
uint64_t getID() const { return MI->getOperand(IDPos).getImm(); }
178199

@@ -181,11 +202,19 @@ class StatepointOpers {
181202
return MI->getOperand(NBytesPos).getImm();
182203
}
183204

184-
/// Returns the target of the underlying call.
205+
/// Return the target of the underlying call.
185206
const MachineOperand &getCallTarget() const {
186207
return MI->getOperand(CallTargetPos);
187208
}
188209

210+
/// Return the calling convention.
211+
CallingConv::ID getCallingConv() const {
212+
return MI->getOperand(getCCIdx()).getImm();
213+
}
214+
215+
/// Return the statepoint flags.
216+
uint64_t getFlags() const { return MI->getOperand(getFlagsIdx()).getImm(); }
217+
189218
private:
190219
const MachineInstr *MI;
191220
};

llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,12 @@ class StatepointProcessor {
264264
CacheFI(MF.getFrameInfo(), TRI) {}
265265

266266
bool process(MachineInstr &MI) {
267-
unsigned VarIdx = StatepointOpers(&MI).getVarIdx();
268-
uint64_t Flags =
269-
MI.getOperand(VarIdx + StatepointOpers::FlagsOffset).getImm();
267+
StatepointOpers SO(&MI);
268+
uint64_t Flags = SO.getFlags();
270269
// Do nothing for LiveIn, it supports all registers.
271270
if (Flags & (uint64_t)StatepointFlags::DeoptLiveIn)
272271
return false;
273-
CallingConv::ID CC =
274-
MI.getOperand(VarIdx + StatepointOpers::CCOffset).getImm();
272+
CallingConv::ID CC = SO.getCallingConv();
275273
const uint32_t *Mask = TRI.getCallPreservedMask(MF, CC);
276274
CacheFI.reset();
277275
StatepointState SS(MI, Mask, CacheFI);

llvm/lib/CodeGen/MachineVerifier.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,26 +1551,27 @@ void MachineVerifier::visitMachineInstrBefore(const MachineInstr *MI) {
15511551
}
15521552
break;
15531553
}
1554-
case TargetOpcode::STATEPOINT:
1555-
if (!MI->getOperand(StatepointOpers::IDPos).isImm() ||
1556-
!MI->getOperand(StatepointOpers::NBytesPos).isImm() ||
1557-
!MI->getOperand(StatepointOpers::NCallArgsPos).isImm())
1554+
case TargetOpcode::STATEPOINT: {
1555+
StatepointOpers SO(MI);
1556+
if (!MI->getOperand(SO.getIDPos()).isImm() ||
1557+
!MI->getOperand(SO.getNBytesPos()).isImm() ||
1558+
!MI->getOperand(SO.getNCallArgsPos()).isImm()) {
15581559
report("meta operands to STATEPOINT not constant!", MI);
1559-
break;
1560+
break;
1561+
}
15601562

15611563
auto VerifyStackMapConstant = [&](unsigned Offset) {
1562-
if (!MI->getOperand(Offset).isImm() ||
1563-
MI->getOperand(Offset).getImm() != StackMaps::ConstantOp ||
1564-
!MI->getOperand(Offset + 1).isImm())
1564+
if (!MI->getOperand(Offset - 1).isImm() ||
1565+
MI->getOperand(Offset - 1).getImm() != StackMaps::ConstantOp ||
1566+
!MI->getOperand(Offset).isImm())
15651567
report("stack map constant to STATEPOINT not well formed!", MI);
15661568
};
1567-
const unsigned VarStart = StatepointOpers(MI).getVarIdx();
1568-
VerifyStackMapConstant(VarStart + StatepointOpers::CCOffset);
1569-
VerifyStackMapConstant(VarStart + StatepointOpers::FlagsOffset);
1570-
VerifyStackMapConstant(VarStart + StatepointOpers::NumDeoptOperandsOffset);
1569+
VerifyStackMapConstant(SO.getCCIdx());
1570+
VerifyStackMapConstant(SO.getFlagsIdx());
1571+
VerifyStackMapConstant(SO.getNumDeoptArgsIdx());
15711572

15721573
// TODO: verify we have properly encoded deopt arguments
1573-
break;
1574+
} break;
15741575
}
15751576
}
15761577

0 commit comments

Comments
 (0)