[llvm] [RegAllocFast] fold foldable inline asm (PR #74344)
Nick Desaulniers via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 4 09:42:58 PST 2023
================
@@ -1626,6 +1637,69 @@ void RegAllocFast::allocateBasicBlock(MachineBasicBlock &MBB) {
LLVM_DEBUG(MBB.dump());
}
+void RegAllocFast::preemptivelySpillInlineAsmOperands(MachineInstr *MI) {
+ assert(MI->isInlineAsm() && "should only be used by inline asm");
+ // BOTH MI and its number of operands may change in this loop; cache neither.
+ for (unsigned I = InlineAsm::MIOp_FirstOperand; I < MI->getNumOperands();
+ ++I) {
+ MachineOperand &MO = MI->getOperand(I);
+ if (!(MO.isReg() && MI->mayFoldInlineAsmRegOp(I)))
+ continue;
+
+ const bool IsDef = MO.isDef();
+ const bool IsUse = MO.isUse();
+ const bool IsKill = MO.isKill();
+ const MachineOperand *TiedOp = nullptr;
+
+ if (MO.isTied())
+ if (MachineOperand *T = &MI->getOperand(MI->findTiedOperandIdx(I)))
+ if (T->isUse())
+ TiedOp = T;
+
+ Register Reg = MO.getReg();
+ const bool IsVirt = Reg.isVirtual();
+ const TargetRegisterClass *RC =
+ IsVirt ? MRI->getRegClass(Reg) : TRI->getMinimalPhysRegClass(Reg);
+ int FrameIndex = IsVirt
+ ? getStackSpaceFor(Reg)
+ : MFI->CreateSpillStackObject(TRI->getSpillSize(*RC),
+ TRI->getSpillAlign(*RC));
+
+ MachineInstr *NewMI = TII->foldMemoryOperand(*MI, {I}, FrameIndex);
+ // foldMemoryOperand always puts the new instruction before its first param.
+ // Here, we want the newly created replacement to go after the old one, so
+ // that we don't attempt to regalloc it again.
----------------
nickdesaulniers wrote:
This comment is stale, but I'll remove it once I get additional feedback from reviewers.
https://github.com/llvm/llvm-project/pull/74344
More information about the llvm-commits
mailing list