Skip to content

Commit 62f2641

Browse files
authored
X86: Stop using MachineFunction in getPointerRegClass (#156880)
This should be a low level function used to interpret an MCInstrDesc that only depends on the hwmode. It should not depend on other dynamic context like the parent function. In general more ABI properties like this should be expressed directly in the instruction definitions, so introduce new TCRETURN pseudos to use with the special case register classes (e.g. in a better future the callee saved registers would always be encoded directly in a mask on the return instruction). This will help unify X86 onto a pending replacement mechanism for getPointerRegClass.
1 parent 312b561 commit 62f2641

File tree

8 files changed

+36
-26
lines changed

8 files changed

+36
-26
lines changed

llvm/lib/Target/X86/X86AsmPrinter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,8 @@ static bool isIndirectBranchOrTailCall(const MachineInstr &MI) {
476476
return MI.getDesc().isIndirectBranch() /*Make below code in a good shape*/ ||
477477
Opc == X86::TAILJMPr || Opc == X86::TAILJMPm ||
478478
Opc == X86::TAILJMPr64 || Opc == X86::TAILJMPm64 ||
479-
Opc == X86::TCRETURNri || Opc == X86::TCRETURNmi ||
479+
Opc == X86::TCRETURNri || Opc == X86::TCRETURN_WIN64ri ||
480+
Opc == X86::TCRETURN_HIPE32ri || Opc == X86::TCRETURNmi ||
480481
Opc == X86::TCRETURNri64 || Opc == X86::TCRETURNmi64 ||
481482
Opc == X86::TCRETURNri64_ImpCall || Opc == X86::TAILJMPr64_REX ||
482483
Opc == X86::TAILJMPm64_REX;

llvm/lib/Target/X86/X86ExpandPseudo.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ bool X86ExpandPseudo::expandMI(MachineBasicBlock &MBB,
269269
case X86::TCRETURNdi:
270270
case X86::TCRETURNdicc:
271271
case X86::TCRETURNri:
272+
case X86::TCRETURN_WIN64ri:
273+
case X86::TCRETURN_HIPE32ri:
272274
case X86::TCRETURNmi:
273275
case X86::TCRETURNdi64:
274276
case X86::TCRETURNdi64cc:
@@ -346,8 +348,9 @@ bool X86ExpandPseudo::expandMI(MachineBasicBlock &MBB,
346348
MachineInstrBuilder MIB = BuildMI(MBB, MBBI, DL, TII->get(Op));
347349
for (unsigned i = 0; i != X86::AddrNumOperands; ++i)
348350
MIB.add(MBBI->getOperand(i));
349-
} else if ((Opcode == X86::TCRETURNri64) ||
350-
(Opcode == X86::TCRETURNri64_ImpCall)) {
351+
} else if (Opcode == X86::TCRETURNri64 ||
352+
Opcode == X86::TCRETURNri64_ImpCall ||
353+
Opcode == X86::TCRETURN_WIN64ri) {
351354
JumpTarget.setIsKill();
352355
BuildMI(MBB, MBBI, DL,
353356
TII->get(IsX64 ? X86::TAILJMPr64_REX : X86::TAILJMPr64))

llvm/lib/Target/X86/X86FrameLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2398,7 +2398,8 @@ X86FrameLowering::getWinEHFuncletFrameSize(const MachineFunction &MF) const {
23982398
}
23992399

24002400
static bool isTailCallOpcode(unsigned Opc) {
2401-
return Opc == X86::TCRETURNri || Opc == X86::TCRETURNdi ||
2401+
return Opc == X86::TCRETURNri || Opc == X86::TCRETURN_WIN64ri ||
2402+
Opc == X86::TCRETURN_HIPE32ri || Opc == X86::TCRETURNdi ||
24022403
Opc == X86::TCRETURNmi || Opc == X86::TCRETURNri64 ||
24032404
Opc == X86::TCRETURNri64_ImpCall || Opc == X86::TCRETURNdi64 ||
24042405
Opc == X86::TCRETURNmi64;

llvm/lib/Target/X86/X86InstrCompiler.td

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,11 @@ def : Pat<(X86imp_call (i64 tglobaladdr:$dst)),
13261326
// Match an X86tcret that uses less than 7 volatile registers.
13271327
def : Pat<(X86tcret ptr_rc_tailcall:$dst, timm:$off),
13281328
(TCRETURNri ptr_rc_tailcall:$dst, timm:$off)>,
1329-
Requires<[Not64BitMode, NotUseIndirectThunkCalls]>;
1329+
Requires<[Not64BitMode, IsNotHiPECCFunc, NotUseIndirectThunkCalls]>;
1330+
1331+
def : Pat<(X86tcret GR32:$dst, timm:$off),
1332+
(TCRETURN_HIPE32ri GR32:$dst, timm:$off)>,
1333+
Requires<[Not64BitMode, IsHiPECCFunc, NotUseIndirectThunkCalls]>;
13301334

13311335
// FIXME: This is disabled for 32-bit PIC mode because the global base
13321336
// register which is part of the address mode may be assigned a
@@ -1346,7 +1350,11 @@ def : Pat<(X86tcret (i32 texternalsym:$dst), timm:$off),
13461350

13471351
def : Pat<(X86tcret ptr_rc_tailcall:$dst, timm:$off),
13481352
(TCRETURNri64 ptr_rc_tailcall:$dst, timm:$off)>,
1349-
Requires<[In64BitMode, NotUseIndirectThunkCalls, ImportCallOptimizationDisabled]>;
1353+
Requires<[In64BitMode, IsNotWin64CCFunc, NotUseIndirectThunkCalls, ImportCallOptimizationDisabled]>;
1354+
1355+
def : Pat<(X86tcret GR64_TCW64:$dst, timm:$off),
1356+
(TCRETURN_WIN64ri GR64_TCW64:$dst, timm:$off)>,
1357+
Requires<[IsWin64CCFunc, NotUseIndirectThunkCalls, ImportCallOptimizationDisabled]>;
13501358

13511359
def : Pat<(X86tcret ptr_rc_tailcall:$dst, timm:$off),
13521360
(TCRETURNri64_ImpCall ptr_rc_tailcall:$dst, timm:$off)>,

llvm/lib/Target/X86/X86InstrControl.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
282282
[]>, Sched<[WriteJump]>;
283283
def TCRETURNri : PseudoI<(outs), (ins ptr_rc_tailcall:$dst, i32imm:$offset),
284284
[]>, Sched<[WriteJump]>;
285+
286+
def TCRETURN_HIPE32ri : PseudoI<(outs), (ins GR32:$dst, i32imm:$offset),
287+
[]>, Sched<[WriteJump]>;
288+
285289
let mayLoad = 1 in
286290
def TCRETURNmi : PseudoI<(outs), (ins i32mem_TC:$dst, i32imm:$offset),
287291
[]>, Sched<[WriteJumpLd]>;
@@ -357,6 +361,9 @@ let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
357361
def TCRETURNri64 : PseudoI<(outs),
358362
(ins ptr_rc_tailcall:$dst, i32imm:$offset),
359363
[]>, Sched<[WriteJump]>;
364+
def TCRETURN_WIN64ri : PseudoI<(outs), (ins GR64_TCW64:$dst, i32imm:$offset),
365+
[]>, Sched<[WriteJump]>;
366+
360367
def TCRETURNri64_ImpCall : PseudoI<(outs),
361368
(ins GR64_A:$dst, i32imm:$offset),
362369
[]>, Sched<[WriteJump]>;

llvm/lib/Target/X86/X86InstrPredicates.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,13 @@ let RecomputePerFunction = 1 in {
230230
"!Subtarget->hasSSE41()">;
231231
def ImportCallOptimizationEnabled : Predicate<"MF->getFunction().getParent()->getModuleFlag(\"import-call-optimization\")">;
232232
def ImportCallOptimizationDisabled : Predicate<"!MF->getFunction().getParent()->getModuleFlag(\"import-call-optimization\")">;
233+
234+
def IsWin64CCFunc : Predicate<"Subtarget->isCallingConvWin64(MF->getFunction().getCallingConv())">;
235+
def IsNotWin64CCFunc : Predicate<"!Subtarget->isCallingConvWin64(MF->getFunction().getCallingConv())">;
236+
def IsHiPECCFunc : Predicate<"MF->getFunction().getCallingConv() == CallingConv::HiPE">;
237+
238+
def IsNotHiPECCFunc : Predicate<
239+
"MF->getFunction().getCallingConv() != CallingConv::HiPE">;
233240
}
234241

235242
def CallImmAddr : Predicate<"Subtarget->isLegalToCallImmediateAddr()">;

llvm/lib/Target/X86/X86RegisterInfo.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -220,24 +220,10 @@ X86RegisterInfo::getPointerRegClass(const MachineFunction &MF,
220220
// NOSP does not contain RIP, so no special case here.
221221
return &X86::GR32_NOREX_NOSPRegClass;
222222
case 4: // Available for tailcall (not callee-saved GPRs).
223-
return getGPRsForTailCall(MF);
223+
return Is64Bit ? &X86::GR64_TCRegClass : &X86::GR32_TCRegClass;
224224
}
225225
}
226226

227-
const TargetRegisterClass *
228-
X86RegisterInfo::getGPRsForTailCall(const MachineFunction &MF) const {
229-
const Function &F = MF.getFunction();
230-
if (IsWin64 || IsUEFI64 || (F.getCallingConv() == CallingConv::Win64))
231-
return &X86::GR64_TCW64RegClass;
232-
else if (Is64Bit)
233-
return &X86::GR64_TCRegClass;
234-
235-
bool hasHipeCC = (F.getCallingConv() == CallingConv::HiPE);
236-
if (hasHipeCC)
237-
return &X86::GR32RegClass;
238-
return &X86::GR32_TCRegClass;
239-
}
240-
241227
const TargetRegisterClass *
242228
X86RegisterInfo::getCrossCopyRegClass(const TargetRegisterClass *RC) const {
243229
if (RC == &X86::CCRRegClass) {
@@ -1017,6 +1003,8 @@ unsigned X86RegisterInfo::findDeadCallerSavedReg(
10171003
case X86::RETI64:
10181004
case X86::TCRETURNdi:
10191005
case X86::TCRETURNri:
1006+
case X86::TCRETURN_WIN64ri:
1007+
case X86::TCRETURN_HIPE32ri:
10201008
case X86::TCRETURNmi:
10211009
case X86::TCRETURNdi64:
10221010
case X86::TCRETURNri64:

llvm/lib/Target/X86/X86RegisterInfo.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@ class X86RegisterInfo final : public X86GenRegisterInfo {
8787
const TargetRegisterClass *
8888
getCrossCopyRegClass(const TargetRegisterClass *RC) const override;
8989

90-
/// getGPRsForTailCall - Returns a register class with registers that can be
91-
/// used in forming tail calls.
92-
const TargetRegisterClass *
93-
getGPRsForTailCall(const MachineFunction &MF) const;
94-
9590
unsigned getRegPressureLimit(const TargetRegisterClass *RC,
9691
MachineFunction &MF) const override;
9792

0 commit comments

Comments
 (0)