#ifdef GET_GICOMBINER_DEPS
#include "llvm/ADT/SparseBitVector.h"
namespace llvm {
extern cl::OptionCategory GICombinerOptionCategory;
}
#endif
#ifdef GET_GICOMBINER_TYPES
struct MipsPostLegalizerCombinerImplRuleConfig {
SparseBitVector<> DisabledRules;
bool isRuleEnabled(unsigned RuleID) const;
bool parseCommandLineOption();
bool setRuleEnabled(StringRef RuleIdentifier);
bool setRuleDisabled(StringRef RuleIdentifier);
};
static std::optional<uint64_t> getRuleIdxForIdentifier(StringRef RuleIdentifier) {
uint64_t I;
bool Parsed = !RuleIdentifier.getAsInteger(0, I);
if (Parsed)
return I;
#ifndef NDEBUG
#endif
return std::nullopt;
}
static std::optional<std::pair<uint64_t, uint64_t>> getRuleRangeForIdentifier(StringRef RuleIdentifier) {
std::pair<StringRef, StringRef> RangePair = RuleIdentifier.split('-');
if (!RangePair.second.empty()) {
const auto First = getRuleIdxForIdentifier(RangePair.first);
const auto Last = getRuleIdxForIdentifier(RangePair.second);
if (!First || !Last)
return std::nullopt;
if (First >= Last)
report_fatal_error("Beginning of range should be before end of range");
return {{*First, *Last + 1}};
}
if (RangePair.first == "*") {
return {{0, 0}};
}
const auto I = getRuleIdxForIdentifier(RangePair.first);
if (!I)
return std::nullopt;
return {{*I, *I + 1}};
}
bool MipsPostLegalizerCombinerImplRuleConfig::setRuleEnabled(StringRef RuleIdentifier) {
auto MaybeRange = getRuleRangeForIdentifier(RuleIdentifier);
if (!MaybeRange)
return false;
for (auto I = MaybeRange->first; I < MaybeRange->second; ++I)
DisabledRules.reset(I);
return true;
}
bool MipsPostLegalizerCombinerImplRuleConfig::setRuleDisabled(StringRef RuleIdentifier) {
auto MaybeRange = getRuleRangeForIdentifier(RuleIdentifier);
if (!MaybeRange)
return false;
for (auto I = MaybeRange->first; I < MaybeRange->second; ++I)
DisabledRules.set(I);
return true;
}
static std::vector<std::string> MipsPostLegalizerCombinerOption;
static cl::list<std::string> MipsPostLegalizerCombinerDisableOption(
"mipspostlegalizercombiner-disable-rule",
cl::desc("Disable one or more combiner rules temporarily in the MipsPostLegalizerCombiner pass"),
cl::CommaSeparated,
cl::Hidden,
cl::cat(GICombinerOptionCategory),
cl::callback([](const std::string &Str) {
MipsPostLegalizerCombinerOption.push_back(Str);
}));
static cl::list<std::string> MipsPostLegalizerCombinerOnlyEnableOption(
"mipspostlegalizercombiner-only-enable-rule",
cl::desc("Disable all rules in the MipsPostLegalizerCombiner pass then re-enable the specified ones"),
cl::Hidden,
cl::cat(GICombinerOptionCategory),
cl::callback([](const std::string &CommaSeparatedArg) {
StringRef Str = CommaSeparatedArg;
MipsPostLegalizerCombinerOption.push_back("*");
do {
auto X = Str.split(",");
MipsPostLegalizerCombinerOption.push_back(("!" + X.first).str());
Str = X.second;
} while (!Str.empty());
}));
bool MipsPostLegalizerCombinerImplRuleConfig::isRuleEnabled(unsigned RuleID) const {
return !DisabledRules.test(RuleID);
}
bool MipsPostLegalizerCombinerImplRuleConfig::parseCommandLineOption() {
for (StringRef Identifier : MipsPostLegalizerCombinerOption) {
bool Enabled = Identifier.consume_front("!");
if (Enabled && !setRuleEnabled(Identifier))
return false;
if (!Enabled && !setRuleDisabled(Identifier))
return false;
}
return true;
}
#endif
#ifdef GET_GICOMBINER_TYPES
const unsigned MAX_SUBTARGET_PREDICATES = 0;
using PredicateBitset = llvm::Bitset<MAX_SUBTARGET_PREDICATES>;
#endif
#ifdef GET_GICOMBINER_CLASS_MEMBERS
PredicateBitset AvailableModuleFeatures;
mutable PredicateBitset AvailableFunctionFeatures;
PredicateBitset getAvailableFeatures() const {
return AvailableModuleFeatures | AvailableFunctionFeatures;
}
PredicateBitset
computeAvailableModuleFeatures(const MipsSubtarget *Subtarget) const;
PredicateBitset
computeAvailableFunctionFeatures(const MipsSubtarget *Subtarget,
const MachineFunction *MF) const;
void setupGeneratedPerFunctionState(MachineFunction &MF) override;
#endif
#ifdef GET_GICOMBINER_CLASS_MEMBERS
mutable MatcherState State;
typedef ComplexRendererFns(MipsPostLegalizerCombinerImpl::*ComplexMatcherMemFn)(MachineOperand &) const;
typedef void(MipsPostLegalizerCombinerImpl::*CustomRendererFn)(MachineInstrBuilder &, const MachineInstr &, int) const;
const ExecInfoTy<PredicateBitset, ComplexMatcherMemFn, CustomRendererFn> ExecInfo;
static MipsPostLegalizerCombinerImpl::ComplexMatcherMemFn ComplexPredicateFns[];
static MipsPostLegalizerCombinerImpl::CustomRendererFn CustomRenderers[];
bool testImmPredicate_I64(unsigned PredicateID, int64_t Imm) const override;
bool testImmPredicate_APInt(unsigned PredicateID, const APInt &Imm) const override;
bool testImmPredicate_APFloat(unsigned PredicateID, const APFloat &Imm) const override;
const uint8_t *getMatchTable() const override;
bool testMIPredicate_MI(unsigned PredicateID, const MachineInstr &MI, const MatcherState &State) const override;
bool testSimplePredicate(unsigned PredicateID) const override;
bool runCustomAction(unsigned FnID, const MatcherState &State, NewMIVector &OutMIs) const override;
#endif
#ifdef GET_GICOMBINER_IMPL
enum {
GILLT_s1,
};
const static size_t NumTypeObjects = 1;
const static LLT TypeObjects[] = {
LLT::scalar(1),
};
enum SubtargetFeatureBits : uint8_t {
};
PredicateBitset MipsPostLegalizerCombinerImpl::
computeAvailableModuleFeatures(const MipsSubtarget *Subtarget) const {
PredicateBitset Features{};
return Features;
}
void MipsPostLegalizerCombinerImpl::setupGeneratedPerFunctionState(MachineFunction &MF) {
AvailableFunctionFeatures = computeAvailableFunctionFeatures((const MipsSubtarget *)&MF.getSubtarget(), &MF);
}
PredicateBitset MipsPostLegalizerCombinerImpl::
computeAvailableFunctionFeatures(const MipsSubtarget *Subtarget, const MachineFunction *MF) const {
PredicateBitset Features{};
return Features;
}
enum {
GIFBS_Invalid,
};
constexpr static PredicateBitset FeatureBitsets[] {
{},
};
enum {
GICP_Invalid,
};
MipsPostLegalizerCombinerImpl::ComplexMatcherMemFn
MipsPostLegalizerCombinerImpl::ComplexPredicateFns[] = {
nullptr,
};
bool MipsPostLegalizerCombinerImpl::testMIPredicate_MI(unsigned PredicateID, const MachineInstr & MI, const MatcherState &State) const {
llvm_unreachable("Unknown predicate");
return false;
}
bool MipsPostLegalizerCombinerImpl::testImmPredicate_I64(unsigned PredicateID, int64_t Imm) const {
llvm_unreachable("Unknown predicate");
return false;
}
bool MipsPostLegalizerCombinerImpl::testImmPredicate_APFloat(unsigned PredicateID, const APFloat & Imm) const {
llvm_unreachable("Unknown predicate");
return false;
}
bool MipsPostLegalizerCombinerImpl::testImmPredicate_APInt(unsigned PredicateID, const APInt & Imm) const {
llvm_unreachable("Unknown predicate");
return false;
}
bool MipsPostLegalizerCombinerImpl::testSimplePredicate(unsigned Predicate) const {
return RuleConfig.isRuleEnabled(Predicate - GICXXPred_Invalid - 1);
}
enum {
GICR_Invalid,
};
MipsPostLegalizerCombinerImpl::CustomRendererFn
MipsPostLegalizerCombinerImpl::CustomRenderers[] = {
nullptr,
};
bool MipsPostLegalizerCombinerImpl::tryCombineAll(MachineInstr &I) const {
const TargetSubtargetInfo &ST = MF.getSubtarget();
const PredicateBitset AvailableFeatures = getAvailableFeatures();
B.setInstrAndDebugLoc(I);
State.MIs.clear();
State.MIs.push_back(&I);
if (executeMatchTable(*this, State, ExecInfo, B, getMatchTable(), *ST.getInstrInfo(), MRI, *MRI.getTargetRegisterInfo(), *ST.getRegBankInfo(), AvailableFeatures, nullptr)) {
return true;
}
return false;
}
bool MipsPostLegalizerCombinerImpl::runCustomAction(unsigned ApplyID, const MatcherState &State, NewMIVector &OutMIs) const {
Helper.getBuilder().setInstrAndDebugLoc(*State.MIs[0]);
llvm_unreachable("Unknown Apply Action");
}
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define GIMT_Encode2 …
#define GIMT_Encode4 …
#define GIMT_Encode8 …
#else
#define GIMT_Encode2 …
#define GIMT_Encode4 …
#define GIMT_Encode8 …
#endif
const uint8_t *MipsPostLegalizerCombinerImpl::getMatchTable() const {
constexpr static uint8_t MatchTable0[] = {
GIM_Reject,
};
return MatchTable0;
}
#undef GIMT_Encode2
#undef GIMT_Encode4
#undef GIMT_Encode8
#endif
#ifdef GET_GICOMBINER_CONSTRUCTOR_INITS
AvailableModuleFeatures(computeAvailableModuleFeatures(&STI)),
AvailableFunctionFeatures()
#endif
#ifdef GET_GICOMBINER_CONSTRUCTOR_INITS
, State(0),
ExecInfo(TypeObjects, NumTypeObjects, FeatureBitsets, ComplexPredicateFns, CustomRenderers)
#endif