Skip to content

Commit e90110e

Browse files
author
Shao-Ce SUN
committed
[NFC][CodeGen] Use ArrayRef in TargetLowering functions
This patch is similar to D122557, adding an `ArrayRef` version for `setOperationAction`, `setLoadExtAction`, `setCondCodeAction`, `setLibcallName`. Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D123467
1 parent 528aa09 commit e90110e

File tree

2 files changed

+100
-134
lines changed

2 files changed

+100
-134
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,21 +2249,33 @@ class TargetLoweringBase {
22492249
/// Indicate that the specified operation does not work with the specified
22502250
/// type and indicate what to do about it. Note that VT may refer to either
22512251
/// the type of a result or that of an operand of Op.
2252-
void setOperationAction(unsigned Op, MVT VT, LegalizeAction Action) {
2253-
assert(Op < array_lengthof(OpActions[0]) && "Table isn't big enough!");
2254-
OpActions[(unsigned)VT.SimpleTy][Op] = Action;
2252+
void setOperationAction(ArrayRef<unsigned> Ops, MVT VT,
2253+
LegalizeAction Action) {
2254+
for (auto Op : Ops) {
2255+
assert(Op < array_lengthof(OpActions[0]) && "Table isn't big enough!");
2256+
OpActions[(unsigned)VT.SimpleTy][Op] = Action;
2257+
}
2258+
}
2259+
void setOperationAction(ArrayRef<unsigned> Ops, ArrayRef<MVT> VTs,
2260+
LegalizeAction Action) {
2261+
for (auto VT : VTs)
2262+
setOperationAction(Ops, VT, Action);
22552263
}
22562264

22572265
/// Indicate that the specified load with extension does not work with the
22582266
/// specified type and indicate what to do about it.
2259-
void setLoadExtAction(unsigned ExtType, MVT ValVT, MVT MemVT,
2267+
void setLoadExtAction(ArrayRef<unsigned> ExtTypes, MVT ValVT, MVT MemVT,
22602268
LegalizeAction Action) {
2261-
assert(ExtType < ISD::LAST_LOADEXT_TYPE && ValVT.isValid() &&
2262-
MemVT.isValid() && "Table isn't big enough!");
2263-
assert((unsigned)Action < 0x10 && "too many bits for bitfield array");
2264-
unsigned Shift = 4 * ExtType;
2265-
LoadExtActions[ValVT.SimpleTy][MemVT.SimpleTy] &= ~((uint16_t)0xF << Shift);
2266-
LoadExtActions[ValVT.SimpleTy][MemVT.SimpleTy] |= (uint16_t)Action << Shift;
2269+
for (auto ExtType : ExtTypes) {
2270+
assert(ExtType < ISD::LAST_LOADEXT_TYPE && ValVT.isValid() &&
2271+
MemVT.isValid() && "Table isn't big enough!");
2272+
assert((unsigned)Action < 0x10 && "too many bits for bitfield array");
2273+
unsigned Shift = 4 * ExtType;
2274+
LoadExtActions[ValVT.SimpleTy][MemVT.SimpleTy] &=
2275+
~((uint16_t)0xF << Shift);
2276+
LoadExtActions[ValVT.SimpleTy][MemVT.SimpleTy] |= (uint16_t)Action
2277+
<< Shift;
2278+
}
22672279
}
22682280

22692281
/// Indicate that the specified truncating store does not work with the
@@ -2313,17 +2325,24 @@ class TargetLoweringBase {
23132325

23142326
/// Indicate that the specified condition code is or isn't supported on the
23152327
/// target and indicate what to do about it.
2316-
void setCondCodeAction(ISD::CondCode CC, MVT VT,
2328+
void setCondCodeAction(ArrayRef<ISD::CondCode> CCs, MVT VT,
23172329
LegalizeAction Action) {
2318-
assert(VT.isValid() && (unsigned)CC < array_lengthof(CondCodeActions) &&
2319-
"Table isn't big enough!");
2320-
assert((unsigned)Action < 0x10 && "too many bits for bitfield array");
2321-
/// The lower 3 bits of the SimpleTy index into Nth 4bit set from the 32-bit
2322-
/// value and the upper 29 bits index into the second dimension of the array
2323-
/// to select what 32-bit value to use.
2324-
uint32_t Shift = 4 * (VT.SimpleTy & 0x7);
2325-
CondCodeActions[CC][VT.SimpleTy >> 3] &= ~((uint32_t)0xF << Shift);
2326-
CondCodeActions[CC][VT.SimpleTy >> 3] |= (uint32_t)Action << Shift;
2330+
for (auto CC : CCs) {
2331+
assert(VT.isValid() && (unsigned)CC < array_lengthof(CondCodeActions) &&
2332+
"Table isn't big enough!");
2333+
assert((unsigned)Action < 0x10 && "too many bits for bitfield array");
2334+
/// The lower 3 bits of the SimpleTy index into Nth 4bit set from the
2335+
/// 32-bit value and the upper 29 bits index into the second dimension of
2336+
/// the array to select what 32-bit value to use.
2337+
uint32_t Shift = 4 * (VT.SimpleTy & 0x7);
2338+
CondCodeActions[CC][VT.SimpleTy >> 3] &= ~((uint32_t)0xF << Shift);
2339+
CondCodeActions[CC][VT.SimpleTy >> 3] |= (uint32_t)Action << Shift;
2340+
}
2341+
}
2342+
void setCondCodeAction(ArrayRef<ISD::CondCode> CCs, ArrayRef<MVT> VTs,
2343+
LegalizeAction Action) {
2344+
for (auto VT : VTs)
2345+
setCondCodeAction(CCs, VT, Action);
23272346
}
23282347

23292348
/// If Opc/OrigVT is specified as being promoted, the promotion code defaults
@@ -2344,14 +2363,11 @@ class TargetLoweringBase {
23442363
/// Targets should invoke this method for each target independent node that
23452364
/// they want to provide a custom DAG combiner for by implementing the
23462365
/// PerformDAGCombine virtual method.
2347-
void setTargetDAGCombine(ISD::NodeType NT) {
2348-
assert(unsigned(NT >> 3) < array_lengthof(TargetDAGCombineArray));
2349-
TargetDAGCombineArray[NT >> 3] |= 1 << (NT&7);
2350-
}
2351-
23522366
void setTargetDAGCombine(ArrayRef<ISD::NodeType> NTs) {
2353-
for (auto NT : NTs)
2354-
setTargetDAGCombine(NT);
2367+
for (auto NT : NTs) {
2368+
assert(unsigned(NT >> 3) < array_lengthof(TargetDAGCombineArray));
2369+
TargetDAGCombineArray[NT >> 3] |= 1 << (NT & 7);
2370+
}
23552371
}
23562372

23572373
/// Set the target's minimum function alignment.
@@ -2979,8 +2995,9 @@ class TargetLoweringBase {
29792995
//
29802996

29812997
/// Rename the default libcall routine name for the specified libcall.
2982-
void setLibcallName(RTLIB::Libcall Call, const char *Name) {
2983-
LibcallRoutineNames[Call] = Name;
2998+
void setLibcallName(ArrayRef<RTLIB::Libcall> Calls, const char *Name) {
2999+
for (auto Call : Calls)
3000+
LibcallRoutineNames[Call] = Name;
29843001
}
29853002

29863003
/// Get the libcall routine name for the specified libcall.

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 54 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -762,91 +762,62 @@ void TargetLoweringBase::initActions() {
762762
setOperationAction(ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS, VT, Expand);
763763

764764
// These operations default to expand.
765-
setOperationAction(ISD::FGETSIGN, VT, Expand);
766-
setOperationAction(ISD::CONCAT_VECTORS, VT, Expand);
767-
setOperationAction(ISD::FMINNUM, VT, Expand);
768-
setOperationAction(ISD::FMAXNUM, VT, Expand);
769-
setOperationAction(ISD::FMINNUM_IEEE, VT, Expand);
770-
setOperationAction(ISD::FMAXNUM_IEEE, VT, Expand);
771-
setOperationAction(ISD::FMINIMUM, VT, Expand);
772-
setOperationAction(ISD::FMAXIMUM, VT, Expand);
773-
setOperationAction(ISD::FMAD, VT, Expand);
774-
setOperationAction(ISD::SMIN, VT, Expand);
775-
setOperationAction(ISD::SMAX, VT, Expand);
776-
setOperationAction(ISD::UMIN, VT, Expand);
777-
setOperationAction(ISD::UMAX, VT, Expand);
778-
setOperationAction(ISD::ABS, VT, Expand);
779-
setOperationAction(ISD::FSHL, VT, Expand);
780-
setOperationAction(ISD::FSHR, VT, Expand);
781-
setOperationAction(ISD::SADDSAT, VT, Expand);
782-
setOperationAction(ISD::UADDSAT, VT, Expand);
783-
setOperationAction(ISD::SSUBSAT, VT, Expand);
784-
setOperationAction(ISD::USUBSAT, VT, Expand);
785-
setOperationAction(ISD::SSHLSAT, VT, Expand);
786-
setOperationAction(ISD::USHLSAT, VT, Expand);
787-
setOperationAction(ISD::SMULFIX, VT, Expand);
788-
setOperationAction(ISD::SMULFIXSAT, VT, Expand);
789-
setOperationAction(ISD::UMULFIX, VT, Expand);
790-
setOperationAction(ISD::UMULFIXSAT, VT, Expand);
791-
setOperationAction(ISD::SDIVFIX, VT, Expand);
792-
setOperationAction(ISD::SDIVFIXSAT, VT, Expand);
793-
setOperationAction(ISD::UDIVFIX, VT, Expand);
794-
setOperationAction(ISD::UDIVFIXSAT, VT, Expand);
795-
setOperationAction(ISD::FP_TO_SINT_SAT, VT, Expand);
796-
setOperationAction(ISD::FP_TO_UINT_SAT, VT, Expand);
765+
setOperationAction({ISD::FGETSIGN, ISD::CONCAT_VECTORS,
766+
ISD::FMINNUM, ISD::FMAXNUM,
767+
ISD::FMINNUM_IEEE, ISD::FMAXNUM_IEEE,
768+
ISD::FMINIMUM, ISD::FMAXIMUM,
769+
ISD::FMAD, ISD::SMIN,
770+
ISD::SMAX, ISD::UMIN,
771+
ISD::UMAX, ISD::ABS,
772+
ISD::FSHL, ISD::FSHR,
773+
ISD::SADDSAT, ISD::UADDSAT,
774+
ISD::SSUBSAT, ISD::USUBSAT,
775+
ISD::SSHLSAT, ISD::USHLSAT,
776+
ISD::SMULFIX, ISD::SMULFIXSAT,
777+
ISD::UMULFIX, ISD::UMULFIXSAT,
778+
ISD::SDIVFIX, ISD::SDIVFIXSAT,
779+
ISD::UDIVFIX, ISD::UDIVFIXSAT,
780+
ISD::FP_TO_SINT_SAT, ISD::FP_TO_UINT_SAT},
781+
VT, Expand);
797782

798783
// Overflow operations default to expand
799-
setOperationAction(ISD::SADDO, VT, Expand);
800-
setOperationAction(ISD::SSUBO, VT, Expand);
801-
setOperationAction(ISD::UADDO, VT, Expand);
802-
setOperationAction(ISD::USUBO, VT, Expand);
803-
setOperationAction(ISD::SMULO, VT, Expand);
804-
setOperationAction(ISD::UMULO, VT, Expand);
784+
setOperationAction({ISD::SADDO, ISD::SSUBO, ISD::UADDO, ISD::USUBO,
785+
ISD::SMULO, ISD::UMULO},
786+
VT, Expand);
805787

806788
// ADDCARRY operations default to expand
807-
setOperationAction(ISD::ADDCARRY, VT, Expand);
808-
setOperationAction(ISD::SUBCARRY, VT, Expand);
809-
setOperationAction(ISD::SETCCCARRY, VT, Expand);
810-
setOperationAction(ISD::SADDO_CARRY, VT, Expand);
811-
setOperationAction(ISD::SSUBO_CARRY, VT, Expand);
789+
setOperationAction({ISD::ADDCARRY, ISD::SUBCARRY, ISD::SETCCCARRY,
790+
ISD::SADDO_CARRY, ISD::SSUBO_CARRY},
791+
VT, Expand);
812792

813793
// ADDC/ADDE/SUBC/SUBE default to expand.
814-
setOperationAction(ISD::ADDC, VT, Expand);
815-
setOperationAction(ISD::ADDE, VT, Expand);
816-
setOperationAction(ISD::SUBC, VT, Expand);
817-
setOperationAction(ISD::SUBE, VT, Expand);
794+
setOperationAction({ISD::ADDC, ISD::ADDE, ISD::SUBC, ISD::SUBE}, VT,
795+
Expand);
818796

819797
// Halving adds
820-
setOperationAction(ISD::AVGFLOORS, VT, Expand);
821-
setOperationAction(ISD::AVGFLOORU, VT, Expand);
822-
setOperationAction(ISD::AVGCEILS, VT, Expand);
823-
setOperationAction(ISD::AVGCEILU, VT, Expand);
798+
setOperationAction(
799+
{ISD::AVGFLOORS, ISD::AVGFLOORU, ISD::AVGCEILS, ISD::AVGCEILU}, VT,
800+
Expand);
824801

825802
// Absolute difference
826-
setOperationAction(ISD::ABDS, VT, Expand);
827-
setOperationAction(ISD::ABDU, VT, Expand);
803+
setOperationAction({ISD::ABDS, ISD::ABDU}, VT, Expand);
828804

829805
// These default to Expand so they will be expanded to CTLZ/CTTZ by default.
830-
setOperationAction(ISD::CTLZ_ZERO_UNDEF, VT, Expand);
831-
setOperationAction(ISD::CTTZ_ZERO_UNDEF, VT, Expand);
806+
setOperationAction({ISD::CTLZ_ZERO_UNDEF, ISD::CTTZ_ZERO_UNDEF}, VT,
807+
Expand);
832808

833-
setOperationAction(ISD::BITREVERSE, VT, Expand);
834-
setOperationAction(ISD::PARITY, VT, Expand);
809+
setOperationAction({ISD::BITREVERSE, ISD::PARITY}, VT, Expand);
835810

836811
// These library functions default to expand.
837-
setOperationAction(ISD::FROUND, VT, Expand);
838-
setOperationAction(ISD::FROUNDEVEN, VT, Expand);
839-
setOperationAction(ISD::FPOWI, VT, Expand);
812+
setOperationAction({ISD::FROUND, ISD::FROUNDEVEN, ISD::FPOWI}, VT, Expand);
840813

841814
// These operations default to expand for vector types.
842-
if (VT.isVector()) {
843-
setOperationAction(ISD::FCOPYSIGN, VT, Expand);
844-
setOperationAction(ISD::SIGN_EXTEND_INREG, VT, Expand);
845-
setOperationAction(ISD::ANY_EXTEND_VECTOR_INREG, VT, Expand);
846-
setOperationAction(ISD::SIGN_EXTEND_VECTOR_INREG, VT, Expand);
847-
setOperationAction(ISD::ZERO_EXTEND_VECTOR_INREG, VT, Expand);
848-
setOperationAction(ISD::SPLAT_VECTOR, VT, Expand);
849-
}
815+
if (VT.isVector())
816+
setOperationAction({ISD::FCOPYSIGN, ISD::SIGN_EXTEND_INREG,
817+
ISD::ANY_EXTEND_VECTOR_INREG,
818+
ISD::SIGN_EXTEND_VECTOR_INREG,
819+
ISD::ZERO_EXTEND_VECTOR_INREG, ISD::SPLAT_VECTOR},
820+
VT, Expand);
850821

851822
// Constrained floating-point operations default to expand.
852823
#define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
@@ -857,21 +828,13 @@ void TargetLoweringBase::initActions() {
857828
setOperationAction(ISD::GET_DYNAMIC_AREA_OFFSET, VT, Expand);
858829

859830
// Vector reduction default to expand.
860-
setOperationAction(ISD::VECREDUCE_FADD, VT, Expand);
861-
setOperationAction(ISD::VECREDUCE_FMUL, VT, Expand);
862-
setOperationAction(ISD::VECREDUCE_ADD, VT, Expand);
863-
setOperationAction(ISD::VECREDUCE_MUL, VT, Expand);
864-
setOperationAction(ISD::VECREDUCE_AND, VT, Expand);
865-
setOperationAction(ISD::VECREDUCE_OR, VT, Expand);
866-
setOperationAction(ISD::VECREDUCE_XOR, VT, Expand);
867-
setOperationAction(ISD::VECREDUCE_SMAX, VT, Expand);
868-
setOperationAction(ISD::VECREDUCE_SMIN, VT, Expand);
869-
setOperationAction(ISD::VECREDUCE_UMAX, VT, Expand);
870-
setOperationAction(ISD::VECREDUCE_UMIN, VT, Expand);
871-
setOperationAction(ISD::VECREDUCE_FMAX, VT, Expand);
872-
setOperationAction(ISD::VECREDUCE_FMIN, VT, Expand);
873-
setOperationAction(ISD::VECREDUCE_SEQ_FADD, VT, Expand);
874-
setOperationAction(ISD::VECREDUCE_SEQ_FMUL, VT, Expand);
831+
setOperationAction(
832+
{ISD::VECREDUCE_FADD, ISD::VECREDUCE_FMUL, ISD::VECREDUCE_ADD,
833+
ISD::VECREDUCE_MUL, ISD::VECREDUCE_AND, ISD::VECREDUCE_OR,
834+
ISD::VECREDUCE_XOR, ISD::VECREDUCE_SMAX, ISD::VECREDUCE_SMIN,
835+
ISD::VECREDUCE_UMAX, ISD::VECREDUCE_UMIN, ISD::VECREDUCE_FMAX,
836+
ISD::VECREDUCE_FMIN, ISD::VECREDUCE_SEQ_FADD, ISD::VECREDUCE_SEQ_FMUL},
837+
VT, Expand);
875838

876839
// Named vector shuffles default to expand.
877840
setOperationAction(ISD::VECTOR_SPLICE, VT, Expand);
@@ -886,30 +849,16 @@ void TargetLoweringBase::initActions() {
886849
// ConstantFP nodes default to expand. Targets can either change this to
887850
// Legal, in which case all fp constants are legal, or use isFPImmLegal()
888851
// to optimize expansions for certain constants.
889-
setOperationAction(ISD::ConstantFP, MVT::f16, Expand);
890-
setOperationAction(ISD::ConstantFP, MVT::f32, Expand);
891-
setOperationAction(ISD::ConstantFP, MVT::f64, Expand);
892-
setOperationAction(ISD::ConstantFP, MVT::f80, Expand);
893-
setOperationAction(ISD::ConstantFP, MVT::f128, Expand);
852+
setOperationAction(ISD::ConstantFP,
853+
{MVT::f16, MVT::f32, MVT::f64, MVT::f80, MVT::f128},
854+
Expand);
894855

895856
// These library functions default to expand.
896-
for (MVT VT : {MVT::f32, MVT::f64, MVT::f128}) {
897-
setOperationAction(ISD::FCBRT, VT, Expand);
898-
setOperationAction(ISD::FLOG , VT, Expand);
899-
setOperationAction(ISD::FLOG2, VT, Expand);
900-
setOperationAction(ISD::FLOG10, VT, Expand);
901-
setOperationAction(ISD::FEXP , VT, Expand);
902-
setOperationAction(ISD::FEXP2, VT, Expand);
903-
setOperationAction(ISD::FFLOOR, VT, Expand);
904-
setOperationAction(ISD::FNEARBYINT, VT, Expand);
905-
setOperationAction(ISD::FCEIL, VT, Expand);
906-
setOperationAction(ISD::FRINT, VT, Expand);
907-
setOperationAction(ISD::FTRUNC, VT, Expand);
908-
setOperationAction(ISD::LROUND, VT, Expand);
909-
setOperationAction(ISD::LLROUND, VT, Expand);
910-
setOperationAction(ISD::LRINT, VT, Expand);
911-
setOperationAction(ISD::LLRINT, VT, Expand);
912-
}
857+
setOperationAction({ISD::FCBRT, ISD::FLOG, ISD::FLOG2, ISD::FLOG10, ISD::FEXP,
858+
ISD::FEXP2, ISD::FFLOOR, ISD::FNEARBYINT, ISD::FCEIL,
859+
ISD::FRINT, ISD::FTRUNC, ISD::LROUND, ISD::LLROUND,
860+
ISD::LRINT, ISD::LLRINT},
861+
{MVT::f32, MVT::f64, MVT::f128}, Expand);
913862

914863
// Default ISD::TRAP to expand (which turns it into abort).
915864
setOperationAction(ISD::TRAP, MVT::Other, Expand);

0 commit comments

Comments
 (0)