Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions llvm/utils/TableGen/Common/GlobalISel/CXXPredicates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include "CXXPredicates.h"
#include "llvm/ADT/STLExtras.h"

namespace llvm {
namespace gi {
using namespace llvm;
using namespace gi;

std::vector<const CXXPredicateCode *>
CXXPredicateCode::getSorted(const CXXPredicateCodePool &Pool) {
Expand Down Expand Up @@ -46,6 +46,3 @@ CXXPredicateCode::CXXPredicateCode(std::string Code, unsigned ID)

CXXPredicateCode::CXXPredicateCodePool CXXPredicateCode::AllCXXMatchCode;
CXXPredicateCode::CXXPredicateCodePool CXXPredicateCode::AllCXXCustomActionCode;

} // namespace gi
} // namespace llvm
6 changes: 2 additions & 4 deletions llvm/utils/TableGen/Common/GlobalISel/CXXPredicates.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
#include <string>
#include <vector>

namespace llvm {
namespace gi {
namespace llvm::gi {

/// Entry into the static pool of all CXX Predicate code. This contains
/// fully expanded C++ code.
Expand Down Expand Up @@ -80,7 +79,6 @@ class CXXPredicateCode {
}
};

} // namespace gi
} // end namespace llvm
} // namespace llvm::gi

#endif // LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_CXXPREDICATES_H
6 changes: 2 additions & 4 deletions llvm/utils/TableGen/Common/GlobalISel/CombinerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
#include "CombinerUtils.h"
#include "llvm/ADT/StringSet.h"

namespace llvm {
using namespace llvm;

StringRef insertStrRef(StringRef S) {
StringRef llvm::insertStrRef(StringRef S) {
if (S.empty())
return {};

static StringSet<> Pool;
auto [It, Inserted] = Pool.insert(S);
return It->getKey();
}

} // namespace llvm
1 change: 1 addition & 0 deletions llvm/utils/TableGen/Common/GlobalISel/CombinerUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ inline const DagInit *getDagWithOperatorOfSubClass(const Init &N,
}

/// Copies a StringRef into a static pool to preserve it.
// FIXME: Use UniqueStringSaver instead.
StringRef insertStrRef(StringRef S);

} // namespace llvm
Expand Down
40 changes: 18 additions & 22 deletions llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@

STATISTIC(NumPatternEmitted, "Number of patterns emitted");

namespace llvm {
namespace gi {
using namespace llvm;
using namespace gi;

namespace {

Error failUnsupported(const Twine &Reason) {
// FIXME: Use createStringError instead.
static Error failUnsupported(const Twine &Reason) {
return make_error<StringError>(Reason, inconvertibleErrorCode());
}

/// Get the name of the enum value used to number the predicate function.
std::string getEnumNameForPredicate(const TreePredicateFn &Predicate) {
static std::string getEnumNameForPredicate(const TreePredicateFn &Predicate) {
if (Predicate.hasGISelPredicateCode())
return "GICXXPred_MI_" + Predicate.getFnName();
if (Predicate.hasGISelLeafPredicateCode())
Expand All @@ -39,18 +38,17 @@ std::string getEnumNameForPredicate(const TreePredicateFn &Predicate) {
Predicate.getFnName();
}

std::string getMatchOpcodeForImmPredicate(const TreePredicateFn &Predicate) {
static std::string
getMatchOpcodeForImmPredicate(const TreePredicateFn &Predicate) {
return "GIM_Check" + Predicate.getImmTypeIdentifier().str() + "ImmPredicate";
}

// GIMT_Encode2/4/8
constexpr StringLiteral EncodeMacroName = "GIMT_Encode";

} // namespace

//===- Helpers ------------------------------------------------------------===//

void emitEncodingMacrosDef(raw_ostream &OS) {
void llvm::gi::emitEncodingMacrosDef(raw_ostream &OS) {
OS << "#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__\n"
<< "#define " << EncodeMacroName << "2(Val)"
<< " uint8_t(Val), uint8_t((Val) >> 8)\n"
Expand All @@ -76,14 +74,15 @@ void emitEncodingMacrosDef(raw_ostream &OS) {
<< "#endif\n";
}

void emitEncodingMacrosUndef(raw_ostream &OS) {
void llvm::gi::emitEncodingMacrosUndef(raw_ostream &OS) {
OS << "#undef " << EncodeMacroName << "2\n"
<< "#undef " << EncodeMacroName << "4\n"
<< "#undef " << EncodeMacroName << "8\n";
}

std::string getNameForFeatureBitset(ArrayRef<const Record *> FeatureBitset,
int HwModeIdx) {
std::string
llvm::gi::getNameForFeatureBitset(ArrayRef<const Record *> FeatureBitset,
int HwModeIdx) {
std::string Name = "GIFBS";
for (const Record *Feature : FeatureBitset)
Name += ("_" + Feature->getName()).str();
Expand All @@ -94,8 +93,8 @@ std::string getNameForFeatureBitset(ArrayRef<const Record *> FeatureBitset,

template <class GroupT>
std::vector<Matcher *>
optimizeRules(ArrayRef<Matcher *> Rules,
std::vector<std::unique_ptr<Matcher>> &MatcherStorage) {
llvm::gi::optimizeRules(ArrayRef<Matcher *> Rules,
std::vector<std::unique_ptr<Matcher>> &MatcherStorage) {

std::vector<Matcher *> OptRules;
std::unique_ptr<GroupT> CurrentGroup = std::make_unique<GroupT>();
Expand Down Expand Up @@ -142,11 +141,11 @@ optimizeRules(ArrayRef<Matcher *> Rules,
return OptRules;
}

template std::vector<Matcher *> optimizeRules<GroupMatcher>(
template std::vector<Matcher *> llvm::gi::optimizeRules<GroupMatcher>(
ArrayRef<Matcher *> Rules,
std::vector<std::unique_ptr<Matcher>> &MatcherStorage);

template std::vector<Matcher *> optimizeRules<SwitchMatcher>(
template std::vector<Matcher *> llvm::gi::optimizeRules<SwitchMatcher>(
ArrayRef<Matcher *> Rules,
std::vector<std::unique_ptr<Matcher>> &MatcherStorage);

Expand All @@ -158,7 +157,7 @@ static std::string getEncodedEmitStr(StringRef NamedValue, unsigned NumBytes) {

//===- Global Data --------------------------------------------------------===//

std::set<LLTCodeGen> KnownTypes;
std::set<LLTCodeGen> llvm::gi::KnownTypes;

//===- MatchTableRecord ---------------------------------------------------===//

Expand Down Expand Up @@ -437,7 +436,7 @@ bool LLTCodeGen::operator<(const LLTCodeGen &Other) const {

//===- LLTCodeGen Helpers -------------------------------------------------===//

std::optional<LLTCodeGen> MVTToLLT(MVT::SimpleValueType SVT) {
std::optional<LLTCodeGen> llvm::gi::MVTToLLT(MVT::SimpleValueType SVT) {
MVT VT(SVT);

if (VT.isVector() && !VT.getVectorElementCount().isScalar())
Expand Down Expand Up @@ -2434,6 +2433,3 @@ void MakeTempRegisterAction::emitActionOpcodes(MatchTable &Table,
<< MatchTable::ULEB128Value(TempRegID) << MatchTable::Comment("TypeID")
<< Ty << MatchTable::LineBreak;
}

} // namespace gi
} // namespace llvm
8 changes: 3 additions & 5 deletions llvm/utils/TableGen/Common/GlobalISel/PatternParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"

namespace llvm {
namespace gi {
using namespace llvm;
using namespace gi;

static constexpr StringLiteral MIFlagsEnumClassName = "MIFlagEnum";

namespace {
Expand Down Expand Up @@ -445,6 +446,3 @@ const PatFrag *PatternParser::parsePatFrag(const Record *Def) {
SeenPatFrags.insert(Res);
return Res;
}

} // namespace gi
} // namespace llvm
7 changes: 2 additions & 5 deletions llvm/utils/TableGen/Common/GlobalISel/Patterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"

namespace llvm {
namespace gi {
using namespace llvm;
using namespace gi;

//===- PatternType --------------------------------------------------------===//

Expand Down Expand Up @@ -884,6 +884,3 @@ bool BuiltinPattern::checkSemantics(ArrayRef<SMLoc> Loc) {

return true;
}

} // namespace gi
} // namespace llvm
43 changes: 21 additions & 22 deletions llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,44 +60,43 @@ using namespace llvm::gi;

#define DEBUG_TYPE "gicombiner-emitter"

namespace {
cl::OptionCategory
static cl::OptionCategory
GICombinerEmitterCat("Options for -gen-global-isel-combiner");
cl::opt<bool> StopAfterParse(
static cl::opt<bool> StopAfterParse(
"gicombiner-stop-after-parse",
cl::desc("Stop processing after parsing rules and dump state"),
cl::cat(GICombinerEmitterCat));
cl::list<std::string>
static cl::list<std::string>
SelectedCombiners("combiners", cl::desc("Emit the specified combiners"),
cl::cat(GICombinerEmitterCat), cl::CommaSeparated);
cl::opt<bool> DebugCXXPreds(
static cl::opt<bool> DebugCXXPreds(
"gicombiner-debug-cxxpreds",
cl::desc("Add Contextual/Debug comments to all C++ predicates"),
cl::cat(GICombinerEmitterCat));
cl::opt<bool> DebugTypeInfer("gicombiner-debug-typeinfer",
cl::desc("Print type inference debug logs"),
cl::cat(GICombinerEmitterCat));
static cl::opt<bool> DebugTypeInfer("gicombiner-debug-typeinfer",
cl::desc("Print type inference debug logs"),
cl::cat(GICombinerEmitterCat));

constexpr StringLiteral CXXCustomActionPrefix = "GICXXCustomAction_";
constexpr StringLiteral CXXPredPrefix = "GICXXPred_MI_Predicate_";
constexpr StringLiteral MatchDataClassName = "GIDefMatchData";

//===- CodeExpansions Helpers --------------------------------------------===//

void declareInstExpansion(CodeExpansions &CE, const InstructionMatcher &IM,
StringRef Name) {
static void declareInstExpansion(CodeExpansions &CE,
const InstructionMatcher &IM, StringRef Name) {
CE.declare(Name, "State.MIs[" + to_string(IM.getInsnVarID()) + "]");
}

void declareInstExpansion(CodeExpansions &CE, const BuildMIAction &A,
StringRef Name) {
static void declareInstExpansion(CodeExpansions &CE, const BuildMIAction &A,
StringRef Name) {
// Note: we use redeclare here because this may overwrite a matcher inst
// expansion.
CE.redeclare(Name, "OutMIs[" + to_string(A.getInsnID()) + "]");
}

void declareOperandExpansion(CodeExpansions &CE, const OperandMatcher &OM,
StringRef Name) {
static void declareOperandExpansion(CodeExpansions &CE,
const OperandMatcher &OM, StringRef Name) {
if (OM.isVariadic()) {
CE.declare(Name, "getRemainingOperands(*State.MIs[" +
to_string(OM.getInsnVarID()) + "], " +
Expand All @@ -108,33 +107,34 @@ void declareOperandExpansion(CodeExpansions &CE, const OperandMatcher &OM,
}
}

void declareTempRegExpansion(CodeExpansions &CE, unsigned TempRegID,
StringRef Name) {
static void declareTempRegExpansion(CodeExpansions &CE, unsigned TempRegID,
StringRef Name) {
CE.declare(Name, "State.TempRegisters[" + to_string(TempRegID) + "]");
}

//===- Misc. Helpers -----------------------------------------------------===//

template <typename Container> auto keys(Container &&C) {
template <typename Container> static auto keys(Container &&C) {
return map_range(C, [](auto &Entry) -> auto & { return Entry.first; });
}

template <typename Container> auto values(Container &&C) {
template <typename Container> static auto values(Container &&C) {
return map_range(C, [](auto &Entry) -> auto & { return Entry.second; });
}

std::string getIsEnabledPredicateEnumName(unsigned CombinerRuleID) {
static std::string getIsEnabledPredicateEnumName(unsigned CombinerRuleID) {
return "GICXXPred_Simple_IsRule" + to_string(CombinerRuleID) + "Enabled";
}

//===- MatchTable Helpers ------------------------------------------------===//

LLTCodeGen getLLTCodeGen(const PatternType &PT) {
static LLTCodeGen getLLTCodeGen(const PatternType &PT) {
return *MVTToLLT(getValueType(PT.getLLTRecord()));
}

//===- PrettyStackTrace Helpers ------------------------------------------===//

namespace {
class PrettyStackTraceParse : public PrettyStackTraceEntry {
const Record &Def;

Expand Down Expand Up @@ -277,6 +277,7 @@ class CombineRuleOperandTypeChecker : private OperandTypeChecker {

const OperandTable &MatchOpTable;
};
} // namespace

bool CombineRuleOperandTypeChecker::processMatchPattern(InstructionPattern &P) {
MatchPats.push_back(&P);
Expand Down Expand Up @@ -2822,8 +2823,6 @@ void GICombinerEmitter::run(raw_ostream &OS) {
emitTemporariesInit(OS, MaxTemporaries, "GET_GICOMBINER_CONSTRUCTOR_INITS");
}

} // end anonymous namespace

//===----------------------------------------------------------------------===//

static void EmitGICombiner(const RecordKeeper &RK, raw_ostream &OS) {
Expand Down
12 changes: 6 additions & 6 deletions llvm/utils/TableGen/GlobalISelEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ static cl::opt<bool> OptimizeMatchTable(
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 Explanation;
StringRef Separator = "";
Expand Down Expand Up @@ -167,7 +165,7 @@ static std::string explainPredicates(const TreePatternNode &N) {
return Explanation;
}

std::string explainOperator(const Record *Operator) {
static std::string explainOperator(const Record *Operator) {
if (Operator->isSubClassOf("SDNode"))
return (" (" + Operator->getValueAsString("Opcode") + ")").str();

Expand Down Expand Up @@ -314,6 +312,7 @@ static Expected<LLTCodeGen> getInstResultType(const TreePatternNode &Dst,
return *MaybeOpTy;
}

namespace {
class GlobalISelEmitter final : public GlobalISelMatchTableExecutorEmitter {
public:
explicit GlobalISelEmitter(const RecordKeeper &RK);
Expand Down Expand Up @@ -493,8 +492,11 @@ class GlobalISelEmitter final : public GlobalISelMatchTableExecutorEmitter {
const TreePredicateFn &Predicate,
InstructionMatcher &InsnMatcher, bool &HasAddedMatcher);
};
} // namespace

StringRef getPatFragPredicateEnumName(const Record *R) { return R->getName(); }
static StringRef getPatFragPredicateEnumName(const Record *R) {
return R->getName();
}

void GlobalISelEmitter::gatherOpcodeValues() {
InstructionOpcodeMatcher::initOpcodeValuesMap(Target);
Expand Down Expand Up @@ -2534,8 +2536,6 @@ unsigned GlobalISelEmitter::declareHwModeCheck(StringRef HwModeFeatures) {
return HwModes.emplace(HwModeFeatures.str(), HwModes.size()).first->second;
}

} // end anonymous namespace

//===----------------------------------------------------------------------===//

static TableGen::Emitter::OptClass<GlobalISelEmitter>
Expand Down