#include "Basic/CodeGenIntrinsics.h"
#include "Common/CodeGenDAGPatterns.h"
#include "Common/CodeGenInstruction.h"
#include "Common/CodeGenRegisters.h"
#include "Common/CodeGenTarget.h"
#include "Common/GlobalISel/GlobalISelMatchTable.h"
#include "Common/GlobalISel/GlobalISelMatchTableExecutorEmitter.h"
#include "Common/InfoByHwMode.h"
#include "Common/SubtargetFeatureInfo.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/CodeGenTypes/LowLevelType.h"
#include "llvm/CodeGenTypes/MachineValueType.h"
#include "llvm/Support/CodeGenCoverage.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ScopedPrinter.h"
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/TableGenBackend.h"
#include <string>
usingnamespacellvm;
usingnamespacellvm::gi;
action_iterator;
#define DEBUG_TYPE …
STATISTIC(NumPatternTotal, "Total number of patterns");
STATISTIC(NumPatternImported, "Number of patterns imported from SelectionDAG");
STATISTIC(NumPatternImportsSkipped, "Number of SelectionDAG imports skipped");
STATISTIC(NumPatternsTested,
"Number of patterns executed according to coverage information");
cl::OptionCategory GlobalISelEmitterCat("Options for -gen-global-isel");
static cl::opt<bool> WarnOnSkippedPatterns(
"warn-on-skipped-patterns",
cl::desc("Explain why a pattern was skipped for inclusion "
"in the GlobalISel selector"),
cl::init(false), cl::cat(GlobalISelEmitterCat));
static cl::opt<bool> GenerateCoverage(
"instrument-gisel-coverage",
cl::desc("Generate coverage instrumentation for GlobalISel"),
cl::init(false), cl::cat(GlobalISelEmitterCat));
static cl::opt<std::string> UseCoverageFile(
"gisel-coverage-file", cl::init(""),
cl::desc("Specify file to retrieve coverage information from"),
cl::cat(GlobalISelEmitterCat));
static cl::opt<bool> OptimizeMatchTable(
"optimize-match-table",
cl::desc("Generate an optimized version of the match table"),
cl::init(true), cl::cat(GlobalISelEmitterCat));
namespace {
static std::string explainPredicates(const TreePatternNode &N) { … }
std::string explainOperator(const Record *Operator) { … }
static Error failedImport(const Twine &Reason) { … }
static Error isTrivialOperatorNode(const TreePatternNode &N) { … }
static const Record *getInitValueAsRegClass(const Init *V) { … }
static std::string getScopedName(unsigned Scope, const std::string &Name) { … }
static std::string getMangledRootDefName(StringRef DefOperandName) { … }
static Expected<LLTCodeGen> getInstResultType(const TreePatternNode &Dst,
const CodeGenTarget &Target) { … }
class GlobalISelEmitter final : public GlobalISelMatchTableExecutorEmitter { … };
StringRef getPatFragPredicateEnumName(const Record *R) { … }
void GlobalISelEmitter::gatherOpcodeValues() { … }
void GlobalISelEmitter::gatherTypeIDValues() { … }
void GlobalISelEmitter::gatherNodeEquivs() { … }
const Record *GlobalISelEmitter::findNodeEquiv(const Record *N) const { … }
const CodeGenInstruction *
GlobalISelEmitter::getEquivNode(const Record &Equiv,
const TreePatternNode &N) const { … }
GlobalISelEmitter::GlobalISelEmitter(const RecordKeeper &RK)
: … { … }
Error GlobalISelEmitter::importRulePredicates(
RuleMatcher &M, ArrayRef<const Record *> Predicates) { … }
std::optional<unsigned> GlobalISelEmitter::getMemSizeBitsFromPredicate(
const TreePredicateFn &Predicate) { … }
Expected<InstructionMatcher &> GlobalISelEmitter::addBuiltinPredicates(
const Record *SrcGIEquivOrNull, const TreePredicateFn &Predicate,
InstructionMatcher &InsnMatcher, bool &HasAddedMatcher) { … }
Expected<InstructionMatcher &> GlobalISelEmitter::createAndImportSelDAGMatcher(
RuleMatcher &Rule, InstructionMatcher &InsnMatcher,
const TreePatternNode &Src, unsigned &TempOpIdx) { … }
Error GlobalISelEmitter::importComplexPatternOperandMatcher(
OperandMatcher &OM, const Record *R, unsigned &TempOpIdx) const { … }
static StringRef getSrcChildName(const TreePatternNode &SrcChild,
const Record *&PhysReg) { … }
Error GlobalISelEmitter::importChildMatcher(
RuleMatcher &Rule, InstructionMatcher &InsnMatcher,
const TreePatternNode &SrcChild, bool OperandIsAPointer,
bool OperandIsImmArg, unsigned OpIdx, unsigned &TempOpIdx) { … }
Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderer(
action_iterator InsertPt, RuleMatcher &Rule, BuildMIAction &DstMIBuilder,
const TreePatternNode &DstChild, const TreePatternNode &Src) { … }
Expected<BuildMIAction &> GlobalISelEmitter::createAndImportInstructionRenderer(
RuleMatcher &M, InstructionMatcher &InsnMatcher, const TreePatternNode &Src,
const TreePatternNode &Dst) { … }
Expected<action_iterator>
GlobalISelEmitter::createAndImportSubInstructionRenderer(
const action_iterator InsertPt, RuleMatcher &M, const TreePatternNode &Dst,
const TreePatternNode &Src, unsigned TempRegID) { … }
Expected<action_iterator> GlobalISelEmitter::createInstructionRenderer(
action_iterator InsertPt, RuleMatcher &M, const TreePatternNode &Dst) { … }
Expected<action_iterator> GlobalISelEmitter::importExplicitDefRenderers(
action_iterator InsertPt, RuleMatcher &M, BuildMIAction &DstMIBuilder,
const TreePatternNode &Src, const TreePatternNode &Dst, unsigned Start) { … }
Expected<action_iterator> GlobalISelEmitter::importExplicitUseRenderers(
action_iterator InsertPt, RuleMatcher &M, BuildMIAction &DstMIBuilder,
const llvm::TreePatternNode &Dst, const llvm::TreePatternNode &Src) { … }
Error GlobalISelEmitter::importDefaultOperandRenderers(
action_iterator InsertPt, RuleMatcher &M, BuildMIAction &DstMIBuilder,
const DAGDefaultOperand &DefaultOp) const { … }
Error GlobalISelEmitter::importImplicitDefRenderers(
BuildMIAction &DstMIBuilder, ArrayRef<const Record *> ImplicitDefs) const { … }
std::optional<const CodeGenRegisterClass *>
GlobalISelEmitter::getRegClassFromLeaf(const TreePatternNode &Leaf) { … }
std::optional<const CodeGenRegisterClass *>
GlobalISelEmitter::inferRegClassFromPattern(const TreePatternNode &N) { … }
std::optional<const CodeGenRegisterClass *>
GlobalISelEmitter::inferSuperRegisterClass(
const TypeSetByHwMode &Ty, const TreePatternNode &SubRegIdxNode) { … }
std::optional<const CodeGenRegisterClass *>
GlobalISelEmitter::inferSuperRegisterClassForNode(
const TypeSetByHwMode &Ty, const TreePatternNode &SuperRegNode,
const TreePatternNode &SubRegIdxNode) { … }
std::optional<CodeGenSubRegIndex *> GlobalISelEmitter::inferSubRegIndexForNode(
const TreePatternNode &SubRegIdxNode) { … }
Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) { … }
MatchTable
GlobalISelEmitter::buildMatchTable(MutableArrayRef<RuleMatcher> Rules,
bool Optimize, bool WithCoverage) { … }
void GlobalISelEmitter::emitAdditionalImpl(raw_ostream &OS) { … }
void GlobalISelEmitter::emitMIPredicateFns(raw_ostream &OS) { … }
void GlobalISelEmitter::emitI64ImmPredicateFns(raw_ostream &OS) { … }
void GlobalISelEmitter::emitAPFloatImmPredicateFns(raw_ostream &OS) { … }
void GlobalISelEmitter::emitAPIntImmPredicateFns(raw_ostream &OS) { … }
void GlobalISelEmitter::emitTestSimplePredicate(raw_ostream &OS) { … }
void GlobalISelEmitter::emitRunCustomAction(raw_ostream &OS) { … }
void GlobalISelEmitter::postProcessRule(RuleMatcher &M) { … }
void GlobalISelEmitter::run(raw_ostream &OS) { … }
void GlobalISelEmitter::declareSubtargetFeature(const Record *Predicate) { … }
unsigned GlobalISelEmitter::declareHwModeCheck(StringRef HwModeFeatures) { … }
}
static TableGen::Emitter::OptClass<GlobalISelEmitter>
X("gen-global-isel", "Generate GlobalISel selector");