Skip to content

Commit f2baeeb

Browse files
committed
X86: Switch to RegClassByHwMode
Replace the target uses of PointerLikeRegClass with RegClassByHwMode
1 parent bdfdc33 commit f2baeeb

File tree

8 files changed

+57
-43
lines changed

8 files changed

+57
-43
lines changed

llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ std::string X86_MC::ParseX86Triple(const Triple &TT) {
5555
else
5656
FS = "-64bit-mode,-32bit-mode,+16bit-mode";
5757

58+
if (TT.isX32())
59+
FS += ",+x32";
60+
5861
return FS;
5962
}
6063

llvm/lib/Target/X86/X86.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def Is32Bit : SubtargetFeature<"32bit-mode", "Is32Bit", "true",
2525
"32-bit mode (80386)">;
2626
def Is16Bit : SubtargetFeature<"16bit-mode", "Is16Bit", "true",
2727
"16-bit mode (i8086)">;
28+
def IsX32 : SubtargetFeature<"x32", "IsX32", "true",
29+
"64-bit with ILP32 programming model (e.g. x32 ABI)">;
2830

2931
//===----------------------------------------------------------------------===//
3032
// X86 Subtarget ISA features

llvm/lib/Target/X86/X86InstrInfo.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ include "X86InstrFragments.td"
1818
include "X86InstrFragmentsSIMD.td"
1919

2020
//===----------------------------------------------------------------------===//
21-
// X86 Operand Definitions.
21+
// X86 Predicate Definitions.
2222
//
23-
include "X86InstrOperands.td"
23+
include "X86InstrPredicates.td"
2424

2525
//===----------------------------------------------------------------------===//
26-
// X86 Predicate Definitions.
26+
// X86 Operand Definitions.
2727
//
28-
include "X86InstrPredicates.td"
28+
include "X86InstrOperands.td"
2929

3030
//===----------------------------------------------------------------------===//
3131
// X86 Instruction Format Definitions.

llvm/lib/Target/X86/X86InstrOperands.td

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
def x86_ptr_rc : RegClassByHwMode<
10+
[X86_32, X86_64, X86_64_X32],
11+
[GR32, GR64, LOW32_ADDR_ACCESS]>;
12+
913
// A version of ptr_rc which excludes SP, ESP, and RSP. This is used for
1014
// the index operand of an address, to conform to x86 encoding restrictions.
11-
def ptr_rc_nosp : PointerLikeRegClass<1>;
15+
def ptr_rc_nosp : RegClassByHwMode<
16+
[X86_32, X86_64, X86_64_X32],
17+
[GR32_NOSP, GR64_NOSP, GR32_NOSP]>;
1218

1319
// *mem - Operand definitions for the funky X86 addressing mode operands.
1420
//
@@ -53,7 +59,7 @@ class X86MemOperand<string printMethod,
5359
AsmOperandClass parserMatchClass = X86MemAsmOperand,
5460
int size = 0> : Operand<iPTR> {
5561
let PrintMethod = printMethod;
56-
let MIOperandInfo = (ops ptr_rc, i8imm, ptr_rc_nosp, i32imm, SEGMENT_REG);
62+
let MIOperandInfo = (ops x86_ptr_rc, i8imm, ptr_rc_nosp, i32imm, SEGMENT_REG);
5763
let ParserMatchClass = parserMatchClass;
5864
let OperandType = "OPERAND_MEMORY";
5965
int Size = size;
@@ -63,7 +69,7 @@ class X86MemOperand<string printMethod,
6369
class X86VMemOperand<RegisterClass RC, string printMethod,
6470
AsmOperandClass parserMatchClass, int size = 0>
6571
: X86MemOperand<printMethod, parserMatchClass, size> {
66-
let MIOperandInfo = (ops ptr_rc, i8imm, RC, i32imm, SEGMENT_REG);
72+
let MIOperandInfo = (ops x86_ptr_rc, i8imm, RC, i32imm, SEGMENT_REG);
6773
}
6874

6975
def anymem : X86MemOperand<"printMemReference">;
@@ -113,8 +119,14 @@ def sdmem : X86MemOperand<"printqwordmem", X86Mem64AsmOperand>;
113119

114120
// A version of i8mem for use on x86-64 and x32 that uses a NOREX GPR instead
115121
// of a plain GPR, so that it doesn't potentially require a REX prefix.
116-
def ptr_rc_norex : PointerLikeRegClass<2>;
117-
def ptr_rc_norex_nosp : PointerLikeRegClass<3>;
122+
def ptr_rc_norex : RegClassByHwMode<
123+
[X86_32, X86_64, X86_64_X32],
124+
[GR32_NOREX, GR64_NOREX, GR32_NOREX]>;
125+
126+
def ptr_rc_norex_nosp : RegClassByHwMode<
127+
[X86_32, X86_64, X86_64_X32],
128+
[GR32_NOREX_NOSP, GR64_NOREX_NOSP, GR32_NOREX_NOSP]>;
129+
118130

119131
def i8mem_NOREX : X86MemOperand<"printbytemem", X86Mem8AsmOperand, 8> {
120132
let MIOperandInfo = (ops ptr_rc_norex, i8imm, ptr_rc_norex_nosp, i32imm,
@@ -123,7 +135,9 @@ def i8mem_NOREX : X86MemOperand<"printbytemem", X86Mem8AsmOperand, 8> {
123135

124136
// GPRs available for tailcall.
125137
// It represents GR32_TC, GR64_TC or GR64_TCW64.
126-
def ptr_rc_tailcall : PointerLikeRegClass<4>;
138+
def ptr_rc_tailcall : RegClassByHwMode<
139+
[X86_32, X86_64, X86_64_X32],
140+
[GR32_TC, GR64_TC, GR64_TC]>;
127141

128142
// Special i32mem for addresses of load folding tail calls. These are not
129143
// allowed to use callee-saved registers since they must be scheduled
@@ -270,12 +284,12 @@ let RenderMethod = "addMemOffsOperands" in {
270284

271285
class X86SrcIdxOperand<string printMethod, AsmOperandClass parserMatchClass>
272286
: X86MemOperand<printMethod, parserMatchClass> {
273-
let MIOperandInfo = (ops ptr_rc, SEGMENT_REG);
287+
let MIOperandInfo = (ops x86_ptr_rc, SEGMENT_REG);
274288
}
275289

276290
class X86DstIdxOperand<string printMethod, AsmOperandClass parserMatchClass>
277291
: X86MemOperand<printMethod, parserMatchClass> {
278-
let MIOperandInfo = (ops ptr_rc);
292+
let MIOperandInfo = (ops x86_ptr_rc);
279293
}
280294

281295
def srcidx8 : X86SrcIdxOperand<"printSrcIdx8", X86SrcIdx8Operand>;

llvm/lib/Target/X86/X86InstrPredicates.td

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ def Not64BitMode : Predicate<"!Subtarget->is64Bit()">,
195195
AssemblerPredicate<(all_of (not Is64Bit)), "Not 64-bit mode">;
196196
def In64BitMode : Predicate<"Subtarget->is64Bit()">,
197197
AssemblerPredicate<(all_of Is64Bit), "64-bit mode">;
198+
199+
def IsX32Mode : Predicate<"Subtarget->getTargetTriple().isX32()">,
200+
AssemblerPredicate<(all_of IsX32), "x32 ABI">;
201+
def NotX32Mode : Predicate<"!Subtarget->getTargetTriple().isX32()">,
202+
AssemblerPredicate<(all_of (not IsX32)), "not x32 ABI">;
203+
198204
def IsLP64 : Predicate<"Subtarget->isTarget64BitLP64()">;
199205
def NotLP64 : Predicate<"!Subtarget->isTarget64BitLP64()">;
200206
def In16BitMode : Predicate<"Subtarget->is16Bit()">,
@@ -250,3 +256,11 @@ def HasMFence : Predicate<"Subtarget->hasMFence()">;
250256
def HasFastDPWSSD: Predicate<"Subtarget->hasFastDPWSSD()">;
251257
def UseIndirectThunkCalls : Predicate<"Subtarget->useIndirectThunkCalls()">;
252258
def NotUseIndirectThunkCalls : Predicate<"!Subtarget->useIndirectThunkCalls()">;
259+
260+
//===----------------------------------------------------------------------===//
261+
// HwModes
262+
//===----------------------------------------------------------------------===//
263+
264+
defvar X86_32 = DefaultMode;
265+
def X86_64 : HwMode<[In64BitMode, NotX32Mode]>;
266+
def X86_64_X32 : HwMode<[IsX32Mode]>;

llvm/lib/Target/X86/X86RegisterInfo.cpp

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -194,33 +194,14 @@ X86RegisterInfo::getLargestLegalSuperClass(const TargetRegisterClass *RC,
194194

195195
const TargetRegisterClass *
196196
X86RegisterInfo::getPointerRegClass(unsigned Kind) const {
197-
switch (Kind) {
198-
default: llvm_unreachable("Unexpected Kind in getPointerRegClass!");
199-
case 0: // Normal GPRs.
200-
if (IsTarget64BitLP64)
201-
return &X86::GR64RegClass;
202-
// If the target is 64bit but we have been told to use 32bit addresses,
203-
// we can still use 64-bit register as long as we know the high bits
204-
// are zeros.
205-
// Reflect that in the returned register class.
206-
return Is64Bit ? &X86::LOW32_ADDR_ACCESSRegClass : &X86::GR32RegClass;
207-
case 1: // Normal GPRs except the stack pointer (for encoding reasons).
208-
if (IsTarget64BitLP64)
209-
return &X86::GR64_NOSPRegClass;
210-
// NOSP does not contain RIP, so no special case here.
211-
return &X86::GR32_NOSPRegClass;
212-
case 2: // NOREX GPRs.
213-
if (IsTarget64BitLP64)
214-
return &X86::GR64_NOREXRegClass;
215-
return &X86::GR32_NOREXRegClass;
216-
case 3: // NOREX GPRs except the stack pointer (for encoding reasons).
217-
if (IsTarget64BitLP64)
218-
return &X86::GR64_NOREX_NOSPRegClass;
219-
// NOSP does not contain RIP, so no special case here.
220-
return &X86::GR32_NOREX_NOSPRegClass;
221-
case 4: // Available for tailcall (not callee-saved GPRs).
222-
return Is64Bit ? &X86::GR64_TCRegClass : &X86::GR32_TCRegClass;
223-
}
197+
assert(Kind == 0 && "this should only be used for default cases");
198+
if (IsTarget64BitLP64)
199+
return &X86::GR64RegClass;
200+
// If the target is 64bit but we have been told to use 32bit addresses,
201+
// we can still use 64-bit register as long as we know the high bits
202+
// are zeros.
203+
// Reflect that in the returned register class.
204+
return Is64Bit ? &X86::LOW32_ADDR_ACCESSRegClass : &X86::GR32RegClass;
224205
}
225206

226207
const TargetRegisterClass *

llvm/lib/Target/X86/X86Subtarget.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ class X86Subtarget final : public X86GenSubtargetInfo {
170170
#include "X86GenSubtargetInfo.inc"
171171

172172
/// Is this x86_64 with the ILP32 programming model (x32 ABI)?
173-
bool isTarget64BitILP32() const { return Is64Bit && (TargetTriple.isX32()); }
173+
bool isTarget64BitILP32() const { return Is64Bit && IsX32; }
174174

175175
/// Is this x86_64 with the LP64 programming model (standard AMD64, no x32)?
176-
bool isTarget64BitLP64() const { return Is64Bit && (!TargetTriple.isX32()); }
176+
bool isTarget64BitLP64() const { return Is64Bit && !IsX32; }
177177

178178
PICStyles::Style getPICStyle() const { return PICStyle; }
179179
void setPICStyle(PICStyles::Style Style) { PICStyle = Style; }

llvm/utils/TableGen/X86FoldTablesEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,10 @@ void X86FoldTablesEmitter::updateTables(const CodeGenInstruction *RegInst,
553553
for (unsigned I = RegOutSize, E = RegInst->Operands.size(); I < E; I++) {
554554
const Record *RegOpRec = RegInst->Operands[I].Rec;
555555
const Record *MemOpRec = MemInst->Operands[I].Rec;
556-
// PointerLikeRegClass: For instructions like TAILJMPr, TAILJMPr64,
556+
// RegClassByHwMode: For instructions like TAILJMPr, TAILJMPr64,
557557
// TAILJMPr64_REX
558558
if ((isRegisterOperand(RegOpRec) ||
559-
RegOpRec->isSubClassOf("PointerLikeRegClass")) &&
559+
(RegOpRec->isSubClassOf("RegClassByHwMode"))) &&
560560
isMemoryOperand(MemOpRec)) {
561561
switch (I) {
562562
case 0:

0 commit comments

Comments
 (0)