Skip to content

Commit dd01791

Browse files
kddnewtonmeta-codesync[bot]
authored andcommitted
Share AArch64 stack input legalization helper
Summary: Extract a shared helper for AArch64 target-selection legalizations that load a stack input through a virtual register. Just a refactor for later diffs. Reviewed By: alexmalyshev Differential Revision: D109608871 fbshipit-source-id: 5e04e07b134723988fa19560e92a7082816653d1
1 parent dc42069 commit dd01791

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

cinderx/Jit/lir/target_select.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,22 @@ void legalizeA64GuardFPInput(BasicBlock* block, instr_iter_t instr_iter) {
200200
kGuardVarIndex, std::make_unique<Operand>(move, Operand::kLinked));
201201
}
202202

203+
Instruction* moveA64StackInputToVreg(
204+
BasicBlock* block,
205+
instr_iter_t instr_iter,
206+
size_t idx) {
207+
Instruction* instr = instr_iter->get();
208+
Operand* input = instr->getInput(idx);
209+
JIT_DCHECK(input->isStack(), "Expected stack input");
210+
211+
PhyLocation loc = input->getStackSlot();
212+
DataType dt = input->dataType();
213+
Instruction* move = block->allocateInstrBefore(
214+
instr_iter, Instruction::kMove, OutVReg{dt}, Stk{loc, dt});
215+
instr->setInput(idx, std::make_unique<Operand>(move, Operand::kLinked));
216+
return move;
217+
}
218+
203219
/* AArch64 unary arithmetic instructions only operate on registers. */
204220
void legalizeA64UnaryStackInput(BasicBlock* block, instr_iter_t instr_iter) {
205221
Instruction* instr = instr_iter->get();
@@ -208,16 +224,11 @@ void legalizeA64UnaryStackInput(BasicBlock* block, instr_iter_t instr_iter) {
208224
"Expected Negate or Invert, got {}",
209225
instr->opname());
210226

211-
Operand* input = instr->getInput(0);
212-
if (!input->isStack()) {
227+
if (!instr->getInput(0)->isStack()) {
213228
return;
214229
}
215230

216-
PhyLocation loc = input->getStackSlot();
217-
DataType dt = input->dataType();
218-
Instruction* move = block->allocateInstrBefore(
219-
instr_iter, Instruction::kMove, OutVReg{dt}, Stk{loc, dt});
220-
instr->setInput(0, std::make_unique<Operand>(move, Operand::kLinked));
231+
moveA64StackInputToVreg(block, instr_iter, 0);
221232
}
222233

223234
/* AArch64 Inc/Dec only operate on registers. Rewrite stack updates through a
@@ -239,9 +250,7 @@ void legalizeA64StackInputForIncDec(
239250

240251
PhyLocation loc = input->getStackSlot();
241252
DataType dt = input->dataType();
242-
Instruction* move = block->allocateInstrBefore(
243-
instr_iter, Instruction::kMove, OutVReg{dt}, Stk{loc, dt});
244-
instr->setInput(0, std::make_unique<Operand>(move, Operand::kLinked));
253+
Instruction* move = moveA64StackInputToVreg(block, instr_iter, 0);
245254

246255
block->allocateInstrBefore(
247256
std::next(instr_iter), Instruction::kMove, OutStk{loc, dt}, VReg{move});

0 commit comments

Comments
 (0)