[ARM GlobalISel] Modernize LegalizerInfo. NFCI

Start using the new LegalizerInfo API introduced in r323681.

Keep the old API for opcodes that need Lowering in some circumstances
(G_FNEG and G_UREM/G_SREM).

llvm-svn: 323876
This commit is contained in:
Diana Picus 2018-01-31 14:55:07 +00:00
parent 3f34f33148
commit 1d4421f6a6
2 changed files with 71 additions and 126 deletions

View File

@ -313,6 +313,9 @@ public:
LegalizeRuleSet &customIf(LegalityPredicate Predicate) {
return actionIf(LegalizeAction::Custom, Predicate);
}
LegalizeRuleSet &customFor(std::initializer_list<LLT> Types) {
return actionFor(LegalizeAction::Custom, Types);
}
LegalizeRuleSet &customForCartesianProduct(std::initializer_list<LLT> Types) {
return actionForCartesianProduct(LegalizeAction::Custom, Types);
}

View File

@ -60,20 +60,6 @@ widen_8_16(const LegalizerInfo::SizeAndActionsVec &v) {
return result;
}
static LegalizerInfo::SizeAndActionsVec
widen_1_8_16_narrowToLargest(const LegalizerInfo::SizeAndActionsVec &v) {
assert(v.size() >= 1);
assert(v[0].first > 17);
LegalizerInfo::SizeAndActionsVec result = {
{1, WidenScalar}, {2, Unsupported},
{8, WidenScalar}, {9, Unsupported},
{16, WidenScalar}, {17, Unsupported}};
addAndInterleaveWithUnsupported(result, v);
auto Largest = result.back().first;
result.push_back({Largest + 1, NarrowScalar});
return result;
}
static bool AEABI(const ARMSubtarget &ST) {
return ST.isTargetAEABI() || ST.isTargetGNUAEABI() || ST.isTargetMuslAEABI();
}
@ -89,30 +75,21 @@ ARMLegalizerInfo::ARMLegalizerInfo(const ARMSubtarget &ST) {
const LLT s32 = LLT::scalar(32);
const LLT s64 = LLT::scalar(64);
setAction({G_GLOBAL_VALUE, p0}, Legal);
setAction({G_FRAME_INDEX, p0}, Legal);
getActionDefinitionsBuilder(G_GLOBAL_VALUE).legalFor({p0});
getActionDefinitionsBuilder(G_FRAME_INDEX).legalFor({p0});
for (unsigned Op : {G_LOAD, G_STORE}) {
for (auto Ty : {s1, s8, s16, s32, p0})
setAction({Op, Ty}, Legal);
setAction({Op, 1, p0}, Legal);
}
getActionDefinitionsBuilder({G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR})
.legalFor({s32})
.minScalar(0, s32);
for (unsigned Op : {G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR}) {
if (Op != G_ADD)
setLegalizeScalarToDifferentSizeStrategy(
Op, 0, widenToLargerTypesUnsupportedOtherwise);
setAction({Op, s32}, Legal);
}
for (unsigned Op : {G_SDIV, G_UDIV}) {
setLegalizeScalarToDifferentSizeStrategy(Op, 0,
widenToLargerTypesUnsupportedOtherwise);
if (ST.hasDivideInARMMode())
setAction({Op, s32}, Legal);
else
setAction({Op, s32}, Libcall);
}
if (ST.hasDivideInARMMode())
getActionDefinitionsBuilder({G_SDIV, G_UDIV})
.legalFor({s32})
.clampScalar(0, s32, s32);
else
getActionDefinitionsBuilder({G_SDIV, G_UDIV})
.libcallFor({s32})
.clampScalar(0, s32, s32);
for (unsigned Op : {G_SREM, G_UREM}) {
setLegalizeScalarToDifferentSizeStrategy(Op, 0, widen_8_16);
@ -124,127 +101,92 @@ ARMLegalizerInfo::ARMLegalizerInfo(const ARMSubtarget &ST) {
setAction({Op, s32}, Libcall);
}
for (unsigned Op : {G_SEXT, G_ZEXT, G_ANYEXT}) {
setAction({Op, s32}, Legal);
}
getActionDefinitionsBuilder({G_SEXT, G_ZEXT, G_ANYEXT}).legalFor({s32});
setAction({G_INTTOPTR, p0}, Legal);
setAction({G_INTTOPTR, 1, s32}, Legal);
getActionDefinitionsBuilder(G_INTTOPTR).legalFor({{p0, s32}});
getActionDefinitionsBuilder(G_PTRTOINT).legalFor({{s32, p0}});
setAction({G_PTRTOINT, s32}, Legal);
setAction({G_PTRTOINT, 1, p0}, Legal);
getActionDefinitionsBuilder({G_ASHR, G_LSHR, G_SHL}).legalFor({s32});
for (unsigned Op : {G_ASHR, G_LSHR, G_SHL})
setAction({Op, s32}, Legal);
getActionDefinitionsBuilder(G_GEP).legalFor({{p0, s32}});
setAction({G_GEP, p0}, Legal);
setAction({G_GEP, 1, s32}, Legal);
getActionDefinitionsBuilder(G_SELECT).legalForCartesianProduct({s32, p0},
{s1});
setAction({G_SELECT, s32}, Legal);
setAction({G_SELECT, p0}, Legal);
setAction({G_SELECT, 1, s1}, Legal);
getActionDefinitionsBuilder(G_BRCOND).legalFor({s1});
setAction({G_BRCOND, s1}, Legal);
getActionDefinitionsBuilder(G_CONSTANT)
.legalFor({s32, p0})
.clampScalar(0, s32, s32);
for (auto Ty : {s32, p0})
setAction({G_PHI, Ty}, Legal);
setLegalizeScalarToDifferentSizeStrategy(
G_PHI, 0, widenToLargerTypesUnsupportedOtherwise);
getActionDefinitionsBuilder(G_ICMP)
.legalForCartesianProduct({s1}, {s32, p0})
.minScalar(1, s32);
setAction({G_CONSTANT, s32}, Legal);
setAction({G_CONSTANT, p0}, Legal);
setLegalizeScalarToDifferentSizeStrategy(G_CONSTANT, 0,
widen_1_8_16_narrowToLargest);
// We're keeping these builders around because we'll want to add support for
// floating point to them.
auto &LoadStoreBuilder = getActionDefinitionsBuilder({G_LOAD, G_STORE}).legalForCartesianProduct(
{s1, s8, s16, s32, p0}, {p0});
setAction({G_ICMP, s1}, Legal);
setLegalizeScalarToDifferentSizeStrategy(G_ICMP, 1,
widenToLargerTypesUnsupportedOtherwise);
for (auto Ty : {s32, p0})
setAction({G_ICMP, 1, Ty}, Legal);
auto &PhiBuilder = getActionDefinitionsBuilder(G_PHI)
.legalFor({s32, p0})
.minScalar(0, s32);
if (!ST.useSoftFloat() && ST.hasVFP2()) {
for (unsigned Op : {G_FADD, G_FSUB, G_FMUL, G_FDIV, G_FCONSTANT, G_FNEG})
for (auto Ty : {s32, s64})
setAction({Op, Ty}, Legal);
getActionDefinitionsBuilder(
{G_FADD, G_FSUB, G_FMUL, G_FDIV, G_FCONSTANT, G_FNEG})
.legalFor({s32, s64});
setAction({G_LOAD, s64}, Legal);
setAction({G_STORE, s64}, Legal);
LoadStoreBuilder.legalFor({{s64, p0}});
PhiBuilder.legalFor({s64});
setAction({G_PHI, s64}, Legal);
getActionDefinitionsBuilder(G_FCMP).legalForCartesianProduct({s1},
{s32, s64});
setAction({G_FCMP, s1}, Legal);
setAction({G_FCMP, 1, s32}, Legal);
setAction({G_FCMP, 1, s64}, Legal);
getActionDefinitionsBuilder(G_MERGE_VALUES).legalFor({{s64, s32}});
getActionDefinitionsBuilder(G_UNMERGE_VALUES).legalFor({{s32, s64}});
setAction({G_MERGE_VALUES, s64}, Legal);
setAction({G_MERGE_VALUES, 1, s32}, Legal);
setAction({G_UNMERGE_VALUES, s32}, Legal);
setAction({G_UNMERGE_VALUES, 1, s64}, Legal);
getActionDefinitionsBuilder(G_FPEXT).legalFor({{s64, s32}});
getActionDefinitionsBuilder(G_FPTRUNC).legalFor({{s32, s64}});
setAction({G_FPEXT, s64}, Legal);
setAction({G_FPEXT, 1, s32}, Legal);
setAction({G_FPTRUNC, s32}, Legal);
setAction({G_FPTRUNC, 1, s64}, Legal);
for (unsigned Op : {G_FPTOSI, G_FPTOUI}) {
setAction({Op, s32}, Legal);
for (auto Ty : {s32, s64})
setAction({Op, 1, Ty}, Legal);
}
for (unsigned Op : {G_SITOFP, G_UITOFP}) {
setAction({Op, 1, s32}, Legal);
for (auto Ty : {s32, s64})
setAction({Op, Ty}, Legal);
}
getActionDefinitionsBuilder({G_FPTOSI, G_FPTOUI})
.legalForCartesianProduct({s32}, {s32, s64});
getActionDefinitionsBuilder({G_SITOFP, G_UITOFP})
.legalForCartesianProduct({s32, s64}, {s32});
} else {
for (unsigned BinOp : {G_FADD, G_FSUB, G_FMUL, G_FDIV})
for (auto Ty : {s32, s64})
setAction({BinOp, Ty}, Libcall);
getActionDefinitionsBuilder({G_FADD, G_FSUB, G_FMUL, G_FDIV})
.libcallFor({s32, s64});
for (auto Ty : {s32, s64}) {
LoadStoreBuilder.maxScalar(0, s32);
for (auto Ty : {s32, s64})
setAction({G_FNEG, Ty}, Lower);
setAction({G_FCONSTANT, Ty}, Custom);
}
setAction({G_FCMP, s1}, Legal);
setAction({G_FCMP, 1, s32}, Custom);
setAction({G_FCMP, 1, s64}, Custom);
getActionDefinitionsBuilder(G_FCONSTANT).customFor({s32, s64});
setAction({G_FPEXT, s64}, Legal);
setAction({G_FPEXT, 1, s32}, Libcall);
setAction({G_FPTRUNC, s32}, Legal);
setAction({G_FPTRUNC, 1, s64}, Libcall);
for (unsigned Op : {G_FPTOSI, G_FPTOUI}) {
setAction({Op, s32}, Legal);
setAction({Op, 1, s32}, Libcall);
setAction({Op, 1, s64}, Libcall);
}
for (unsigned Op : {G_SITOFP, G_UITOFP}) {
for (auto Ty : {s32, s64})
setAction({Op, Ty}, Libcall);
}
getActionDefinitionsBuilder(G_FCMP).customForCartesianProduct({s1},
{s32, s64});
if (AEABI(ST))
setFCmpLibcallsAEABI();
else
setFCmpLibcallsGNU();
getActionDefinitionsBuilder(G_FPEXT).libcallFor({s64, s32});
getActionDefinitionsBuilder(G_FPTRUNC).libcallFor({s32, s64});
getActionDefinitionsBuilder({G_FPTOSI, G_FPTOUI})
.libcallForCartesianProduct({s32}, {s32, s64});
getActionDefinitionsBuilder({G_SITOFP, G_UITOFP})
.libcallForCartesianProduct({s32, s64}, {s32});
}
if (!ST.useSoftFloat() && ST.hasVFP4())
for (auto Ty : {s32, s64})
setAction({G_FMA, Ty}, Legal);
getActionDefinitionsBuilder(G_FMA).legalFor({s32, s64});
else
for (auto Ty : {s32, s64})
setAction({G_FMA, Ty}, Libcall);
getActionDefinitionsBuilder(G_FMA).libcallFor({s32, s64});
for (unsigned Op : {G_FREM, G_FPOW})
for (auto Ty : {s32, s64})
setAction({Op, Ty}, Libcall);
getActionDefinitionsBuilder({G_FREM, G_FPOW}).libcallFor({s32, s64});
computeTables();
}