Skip to content

Commit 3693909

Browse files
committed
[LoongArch] Reorder LoongArchTargetLowering(). NFC
1 parent 1654634 commit 3693909

File tree

1 file changed

+82
-70
lines changed

1 file changed

+82
-70
lines changed

llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp

Lines changed: 82 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,14 @@ LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM,
4747
: TargetLowering(TM), Subtarget(STI) {
4848

4949
MVT GRLenVT = Subtarget.getGRLenVT();
50+
5051
// Set up the register classes.
52+
5153
addRegisterClass(GRLenVT, &LoongArch::GPRRegClass);
5254
if (Subtarget.hasBasicF())
5355
addRegisterClass(MVT::f32, &LoongArch::FPR32RegClass);
5456
if (Subtarget.hasBasicD())
5557
addRegisterClass(MVT::f64, &LoongArch::FPR64RegClass);
56-
if (Subtarget.hasExtLSX())
57-
for (auto VT : {MVT::v4f32, MVT::v2f64, MVT::v16i8, MVT::v8i16, MVT::v4i32,
58-
MVT::v2i64})
59-
addRegisterClass(VT, &LoongArch::LSX128RegClass);
60-
if (Subtarget.hasExtLASX())
61-
for (auto VT : {MVT::v8f32, MVT::v4f64, MVT::v32i8, MVT::v16i16, MVT::v8i32,
62-
MVT::v4i64})
63-
addRegisterClass(VT, &LoongArch::LASX256RegClass);
6458

6559
static const MVT::SimpleValueType LSXVTs[] = {
6660
MVT::v16i8, MVT::v8i16, MVT::v4i32, MVT::v2i64, MVT::v4f32, MVT::v2f64};
@@ -75,38 +69,57 @@ LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM,
7569
for (MVT VT : LASXVTs)
7670
addRegisterClass(VT, &LoongArch::LASX256RegClass);
7771

72+
// Set operations for LA32 and LA64.
73+
7874
setLoadExtAction({ISD::EXTLOAD, ISD::SEXTLOAD, ISD::ZEXTLOAD}, GRLenVT,
7975
MVT::i1, Promote);
8076

81-
// TODO: add necessary setOperationAction calls later.
8277
setOperationAction(ISD::SHL_PARTS, GRLenVT, Custom);
8378
setOperationAction(ISD::SRA_PARTS, GRLenVT, Custom);
8479
setOperationAction(ISD::SRL_PARTS, GRLenVT, Custom);
8580
setOperationAction(ISD::FP_TO_SINT, GRLenVT, Custom);
8681
setOperationAction(ISD::ROTL, GRLenVT, Expand);
8782
setOperationAction(ISD::CTPOP, GRLenVT, Expand);
88-
setOperationAction(ISD::DEBUGTRAP, MVT::Other, Legal);
89-
setOperationAction(ISD::TRAP, MVT::Other, Legal);
90-
setOperationAction(ISD::INTRINSIC_VOID, MVT::Other, Custom);
91-
setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::Other, Custom);
9283

9384
setOperationAction({ISD::GlobalAddress, ISD::BlockAddress, ISD::ConstantPool,
94-
ISD::JumpTable},
85+
ISD::JumpTable, ISD::GlobalTLSAddress},
9586
GRLenVT, Custom);
9687

97-
setOperationAction(ISD::GlobalTLSAddress, GRLenVT, Custom);
98-
99-
setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
100-
101-
setOperationAction(ISD::EH_DWARF_CFA, MVT::i32, Custom);
102-
if (Subtarget.is64Bit())
103-
setOperationAction(ISD::EH_DWARF_CFA, MVT::i64, Custom);
88+
setOperationAction(ISD::EH_DWARF_CFA, GRLenVT, Custom);
10489

10590
setOperationAction(ISD::DYNAMIC_STACKALLOC, GRLenVT, Expand);
10691
setOperationAction({ISD::STACKSAVE, ISD::STACKRESTORE}, MVT::Other, Expand);
10792
setOperationAction(ISD::VASTART, MVT::Other, Custom);
10893
setOperationAction({ISD::VAARG, ISD::VACOPY, ISD::VAEND}, MVT::Other, Expand);
10994

95+
setOperationAction(ISD::DEBUGTRAP, MVT::Other, Legal);
96+
setOperationAction(ISD::TRAP, MVT::Other, Legal);
97+
98+
setOperationAction(ISD::INTRINSIC_VOID, MVT::Other, Custom);
99+
setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::Other, Custom);
100+
setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
101+
102+
// Expand bitreverse.i16 with native-width bitrev and shift for now, before
103+
// we get to know which of sll and revb.2h is faster.
104+
setOperationAction(ISD::BITREVERSE, MVT::i8, Custom);
105+
setOperationAction(ISD::BITREVERSE, GRLenVT, Legal);
106+
107+
// LA32 does not have REVB.2W and REVB.D due to the 64-bit operands, and
108+
// the narrower REVB.W does not exist. But LA32 does have REVB.2H, so i16
109+
// and i32 could still be byte-swapped relatively cheaply.
110+
setOperationAction(ISD::BSWAP, MVT::i16, Custom);
111+
112+
setOperationAction(ISD::BR_JT, MVT::Other, Expand);
113+
setOperationAction(ISD::BR_CC, GRLenVT, Expand);
114+
setOperationAction(ISD::SELECT_CC, GRLenVT, Expand);
115+
setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
116+
setOperationAction({ISD::SMUL_LOHI, ISD::UMUL_LOHI}, GRLenVT, Expand);
117+
118+
setOperationAction(ISD::FP_TO_UINT, GRLenVT, Custom);
119+
setOperationAction(ISD::UINT_TO_FP, GRLenVT, Expand);
120+
121+
// Set operations for LA64 only.
122+
110123
if (Subtarget.is64Bit()) {
111124
setOperationAction(ISD::SHL, MVT::i32, Custom);
112125
setOperationAction(ISD::SRA, MVT::i32, Custom);
@@ -117,50 +130,39 @@ LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM,
117130
setOperationAction(ISD::ROTL, MVT::i32, Custom);
118131
setOperationAction(ISD::CTTZ, MVT::i32, Custom);
119132
setOperationAction(ISD::CTLZ, MVT::i32, Custom);
120-
setOperationAction(ISD::INTRINSIC_VOID, MVT::i32, Custom);
121-
setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::i32, Custom);
122-
setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::Other, Custom);
133+
setOperationAction(ISD::EH_DWARF_CFA, MVT::i32, Custom);
123134
setOperationAction(ISD::READ_REGISTER, MVT::i32, Custom);
124135
setOperationAction(ISD::WRITE_REGISTER, MVT::i32, Custom);
136+
setOperationAction(ISD::INTRINSIC_VOID, MVT::i32, Custom);
125137
setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::i32, Custom);
126-
if (Subtarget.hasBasicF() && !Subtarget.hasBasicD())
127-
setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom);
128-
if (Subtarget.hasBasicF())
129-
setOperationAction(ISD::FRINT, MVT::f32, Legal);
130-
if (Subtarget.hasBasicD())
131-
setOperationAction(ISD::FRINT, MVT::f64, Legal);
132-
}
138+
setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::i32, Custom);
133139

134-
// LA32 does not have REVB.2W and REVB.D due to the 64-bit operands, and
135-
// the narrower REVB.W does not exist. But LA32 does have REVB.2H, so i16
136-
// and i32 could still be byte-swapped relatively cheaply.
137-
setOperationAction(ISD::BSWAP, MVT::i16, Custom);
138-
if (Subtarget.is64Bit()) {
140+
setOperationAction(ISD::BITREVERSE, MVT::i32, Custom);
139141
setOperationAction(ISD::BSWAP, MVT::i32, Custom);
140142
}
141143

142-
// Expand bitreverse.i16 with native-width bitrev and shift for now, before
143-
// we get to know which of sll and revb.2h is faster.
144-
setOperationAction(ISD::BITREVERSE, MVT::i8, Custom);
145-
if (Subtarget.is64Bit()) {
146-
setOperationAction(ISD::BITREVERSE, MVT::i32, Custom);
147-
setOperationAction(ISD::BITREVERSE, MVT::i64, Legal);
148-
} else {
149-
setOperationAction(ISD::BITREVERSE, MVT::i32, Legal);
150-
setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::i64, Custom);
144+
// Set operations for LA32 only.
145+
146+
if (!Subtarget.is64Bit) {
151147
setOperationAction(ISD::READ_REGISTER, MVT::i64, Custom);
152148
setOperationAction(ISD::WRITE_REGISTER, MVT::i64, Custom);
153-
setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::Other, Custom);
154149
setOperationAction(ISD::INTRINSIC_VOID, MVT::i64, Custom);
155150
setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::i64, Custom);
151+
setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::i64, Custom);
152+
153+
// Set libcalls.
154+
setLibcallName(RTLIB::MUL_I128, nullptr);
156155
}
157156

158157
static const ISD::CondCode FPCCToExpand[] = {
159158
ISD::SETOGT, ISD::SETOGE, ISD::SETUGT, ISD::SETUGE,
160159
ISD::SETGE, ISD::SETNE, ISD::SETGT};
161160

161+
// Set operations for 'F' feature.
162+
162163
if (Subtarget.hasBasicF()) {
163164
setCondCodeAction(FPCCToExpand, MVT::f32, Expand);
165+
164166
setOperationAction(ISD::SELECT_CC, MVT::f32, Expand);
165167
setOperationAction(ISD::BR_CC, MVT::f32, Expand);
166168
setOperationAction(ISD::FMA, MVT::f32, Legal);
@@ -173,14 +175,30 @@ LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM,
173175
setOperationAction(ISD::FSINCOS, MVT::f32, Expand);
174176
setOperationAction(ISD::FPOW, MVT::f32, Expand);
175177
setOperationAction(ISD::FREM, MVT::f32, Expand);
178+
179+
if (Subtarget.is64Bit())
180+
setOperationAction(ISD::FRINT, MVT::f32, Legal);
181+
182+
if (!Subtarget.hasBasicD()) {
183+
setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom);
184+
if (Subtarget.is64Bit()) {
185+
setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom);
186+
setOperationAction(ISD::UINT_TO_FP, MVT::i64, Custom);
187+
}
188+
}
176189
}
190+
191+
// Set operations for 'D' feature.
192+
177193
if (Subtarget.hasBasicD()) {
194+
setLoadExtAction(ISD::EXTLOAD, MVT::f64, MVT::f32, Expand);
195+
setTruncStoreAction(MVT::f64, MVT::f32, Expand);
178196
setCondCodeAction(FPCCToExpand, MVT::f64, Expand);
197+
179198
setOperationAction(ISD::SELECT_CC, MVT::f64, Expand);
180199
setOperationAction(ISD::BR_CC, MVT::f64, Expand);
181200
setOperationAction(ISD::STRICT_FSETCCS, MVT::f64, Legal);
182201
setOperationAction(ISD::STRICT_FSETCC, MVT::f64, Legal);
183-
setLoadExtAction(ISD::EXTLOAD, MVT::f64, MVT::f32, Expand);
184202
setOperationAction(ISD::FMA, MVT::f64, Legal);
185203
setOperationAction(ISD::FMINNUM_IEEE, MVT::f64, Legal);
186204
setOperationAction(ISD::FMAXNUM_IEEE, MVT::f64, Legal);
@@ -189,35 +207,35 @@ LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM,
189207
setOperationAction(ISD::FSINCOS, MVT::f64, Expand);
190208
setOperationAction(ISD::FPOW, MVT::f64, Expand);
191209
setOperationAction(ISD::FREM, MVT::f64, Expand);
192-
setTruncStoreAction(MVT::f64, MVT::f32, Expand);
193-
}
194-
195-
setOperationAction(ISD::BR_JT, MVT::Other, Expand);
196210

197-
setOperationAction(ISD::BR_CC, GRLenVT, Expand);
198-
setOperationAction(ISD::SELECT_CC, GRLenVT, Expand);
199-
setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
200-
setOperationAction({ISD::SMUL_LOHI, ISD::UMUL_LOHI}, GRLenVT, Expand);
201-
if (!Subtarget.is64Bit())
202-
setLibcallName(RTLIB::MUL_I128, nullptr);
203-
204-
setOperationAction(ISD::FP_TO_UINT, GRLenVT, Custom);
205-
setOperationAction(ISD::UINT_TO_FP, GRLenVT, Expand);
206-
if ((Subtarget.is64Bit() && Subtarget.hasBasicF() &&
207-
!Subtarget.hasBasicD())) {
208-
setOperationAction(ISD::SINT_TO_FP, GRLenVT, Custom);
209-
setOperationAction(ISD::UINT_TO_FP, GRLenVT, Custom);
211+
if (Subtarget.is64Bit())
212+
setOperationAction(ISD::FRINT, MVT::f64, Legal);
210213
}
211214

215+
// Set operations for 'LSX' feature.
216+
212217
if (Subtarget.hasExtLSX())
213218
setOperationAction({ISD::UMAX, ISD::UMIN, ISD::SMAX, ISD::SMIN},
214219
{MVT::v2i64, MVT::v4i32, MVT::v8i16, MVT::v16i8}, Legal);
215220

221+
// Set operations for 'LASX' feature.
222+
216223
if (Subtarget.hasExtLASX())
217224
setOperationAction({ISD::UMAX, ISD::UMIN, ISD::SMAX, ISD::SMIN},
218225
{MVT::v4i64, MVT::v8i32, MVT::v16i16, MVT::v32i8},
219226
Legal);
220227

228+
// Set DAG combine for LA32 and LA64.
229+
230+
setTargetDAGCombine(ISD::AND);
231+
setTargetDAGCombine(ISD::OR);
232+
setTargetDAGCombine(ISD::SRL);
233+
234+
// Set DAG combine for 'LSX' feature.
235+
236+
if (Subtarget.hasExtLSX())
237+
setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN);
238+
221239
// Compute derived properties from the register classes.
222240
computeRegisterProperties(Subtarget.getRegisterInfo());
223241

@@ -235,12 +253,6 @@ LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM,
235253
setPrefFunctionAlignment(Subtarget.getPrefFunctionAlignment());
236254
setPrefLoopAlignment(Subtarget.getPrefLoopAlignment());
237255
setMaxBytesForAlignment(Subtarget.getMaxBytesForAlignment());
238-
239-
setTargetDAGCombine(ISD::AND);
240-
setTargetDAGCombine(ISD::OR);
241-
setTargetDAGCombine(ISD::SRL);
242-
if (Subtarget.hasExtLSX())
243-
setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN);
244256
}
245257

246258
bool LoongArchTargetLowering::isOffsetFoldingLegal(

0 commit comments

Comments
 (0)