Skip to content

Commit e5e5736

Browse files
authored
[NFC][TableGen] Fix GlobalISel TableGen backend namespace usage (#156986)
1 parent 7f6098e commit e5e5736

File tree

9 files changed

+57
-73
lines changed

9 files changed

+57
-73
lines changed

llvm/utils/TableGen/Common/GlobalISel/CXXPredicates.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include "CXXPredicates.h"
1313
#include "llvm/ADT/STLExtras.h"
1414

15-
namespace llvm {
16-
namespace gi {
15+
using namespace llvm;
16+
using namespace gi;
1717

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

4747
CXXPredicateCode::CXXPredicateCodePool CXXPredicateCode::AllCXXMatchCode;
4848
CXXPredicateCode::CXXPredicateCodePool CXXPredicateCode::AllCXXCustomActionCode;
49-
50-
} // namespace gi
51-
} // namespace llvm

llvm/utils/TableGen/Common/GlobalISel/CXXPredicates.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
#include <string>
2323
#include <vector>
2424

25-
namespace llvm {
26-
namespace gi {
25+
namespace llvm::gi {
2726

2827
/// Entry into the static pool of all CXX Predicate code. This contains
2928
/// fully expanded C++ code.
@@ -80,7 +79,6 @@ class CXXPredicateCode {
8079
}
8180
};
8281

83-
} // namespace gi
84-
} // end namespace llvm
82+
} // namespace llvm::gi
8583

8684
#endif // LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_CXXPREDICATES_H

llvm/utils/TableGen/Common/GlobalISel/CombinerUtils.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99
#include "CombinerUtils.h"
1010
#include "llvm/ADT/StringSet.h"
1111

12-
namespace llvm {
12+
using namespace llvm;
1313

14-
StringRef insertStrRef(StringRef S) {
14+
StringRef llvm::insertStrRef(StringRef S) {
1515
if (S.empty())
1616
return {};
1717

1818
static StringSet<> Pool;
1919
auto [It, Inserted] = Pool.insert(S);
2020
return It->getKey();
2121
}
22-
23-
} // namespace llvm

llvm/utils/TableGen/Common/GlobalISel/CombinerUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ inline const DagInit *getDagWithOperatorOfSubClass(const Init &N,
6767
}
6868

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

7273
} // namespace llvm

llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@
2020

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

23-
namespace llvm {
24-
namespace gi {
23+
using namespace llvm;
24+
using namespace gi;
2525

26-
namespace {
27-
28-
Error failUnsupported(const Twine &Reason) {
26+
// FIXME: Use createStringError instead.
27+
static Error failUnsupported(const Twine &Reason) {
2928
return make_error<StringError>(Reason, inconvertibleErrorCode());
3029
}
3130

3231
/// Get the name of the enum value used to number the predicate function.
33-
std::string getEnumNameForPredicate(const TreePredicateFn &Predicate) {
32+
static std::string getEnumNameForPredicate(const TreePredicateFn &Predicate) {
3433
if (Predicate.hasGISelPredicateCode())
3534
return "GICXXPred_MI_" + Predicate.getFnName();
3635
if (Predicate.hasGISelLeafPredicateCode())
@@ -39,18 +38,17 @@ std::string getEnumNameForPredicate(const TreePredicateFn &Predicate) {
3938
Predicate.getFnName();
4039
}
4140

42-
std::string getMatchOpcodeForImmPredicate(const TreePredicateFn &Predicate) {
41+
static std::string
42+
getMatchOpcodeForImmPredicate(const TreePredicateFn &Predicate) {
4343
return "GIM_Check" + Predicate.getImmTypeIdentifier().str() + "ImmPredicate";
4444
}
4545

4646
// GIMT_Encode2/4/8
4747
constexpr StringLiteral EncodeMacroName = "GIMT_Encode";
4848

49-
} // namespace
50-
5149
//===- Helpers ------------------------------------------------------------===//
5250

53-
void emitEncodingMacrosDef(raw_ostream &OS) {
51+
void llvm::gi::emitEncodingMacrosDef(raw_ostream &OS) {
5452
OS << "#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__\n"
5553
<< "#define " << EncodeMacroName << "2(Val)"
5654
<< " uint8_t(Val), uint8_t((Val) >> 8)\n"
@@ -76,14 +74,15 @@ void emitEncodingMacrosDef(raw_ostream &OS) {
7674
<< "#endif\n";
7775
}
7876

79-
void emitEncodingMacrosUndef(raw_ostream &OS) {
77+
void llvm::gi::emitEncodingMacrosUndef(raw_ostream &OS) {
8078
OS << "#undef " << EncodeMacroName << "2\n"
8179
<< "#undef " << EncodeMacroName << "4\n"
8280
<< "#undef " << EncodeMacroName << "8\n";
8381
}
8482

85-
std::string getNameForFeatureBitset(ArrayRef<const Record *> FeatureBitset,
86-
int HwModeIdx) {
83+
std::string
84+
llvm::gi::getNameForFeatureBitset(ArrayRef<const Record *> FeatureBitset,
85+
int HwModeIdx) {
8786
std::string Name = "GIFBS";
8887
for (const Record *Feature : FeatureBitset)
8988
Name += ("_" + Feature->getName()).str();
@@ -94,8 +93,8 @@ std::string getNameForFeatureBitset(ArrayRef<const Record *> FeatureBitset,
9493

9594
template <class GroupT>
9695
std::vector<Matcher *>
97-
optimizeRules(ArrayRef<Matcher *> Rules,
98-
std::vector<std::unique_ptr<Matcher>> &MatcherStorage) {
96+
llvm::gi::optimizeRules(ArrayRef<Matcher *> Rules,
97+
std::vector<std::unique_ptr<Matcher>> &MatcherStorage) {
9998

10099
std::vector<Matcher *> OptRules;
101100
std::unique_ptr<GroupT> CurrentGroup = std::make_unique<GroupT>();
@@ -142,11 +141,11 @@ optimizeRules(ArrayRef<Matcher *> Rules,
142141
return OptRules;
143142
}
144143

145-
template std::vector<Matcher *> optimizeRules<GroupMatcher>(
144+
template std::vector<Matcher *> llvm::gi::optimizeRules<GroupMatcher>(
146145
ArrayRef<Matcher *> Rules,
147146
std::vector<std::unique_ptr<Matcher>> &MatcherStorage);
148147

149-
template std::vector<Matcher *> optimizeRules<SwitchMatcher>(
148+
template std::vector<Matcher *> llvm::gi::optimizeRules<SwitchMatcher>(
150149
ArrayRef<Matcher *> Rules,
151150
std::vector<std::unique_ptr<Matcher>> &MatcherStorage);
152151

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

159158
//===- Global Data --------------------------------------------------------===//
160159

161-
std::set<LLTCodeGen> KnownTypes;
160+
std::set<LLTCodeGen> llvm::gi::KnownTypes;
162161

163162
//===- MatchTableRecord ---------------------------------------------------===//
164163

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

438437
//===- LLTCodeGen Helpers -------------------------------------------------===//
439438

440-
std::optional<LLTCodeGen> MVTToLLT(MVT::SimpleValueType SVT) {
439+
std::optional<LLTCodeGen> llvm::gi::MVTToLLT(MVT::SimpleValueType SVT) {
441440
MVT VT(SVT);
442441

443442
if (VT.isVector() && !VT.getVectorElementCount().isScalar())
@@ -2434,6 +2433,3 @@ void MakeTempRegisterAction::emitActionOpcodes(MatchTable &Table,
24342433
<< MatchTable::ULEB128Value(TempRegID) << MatchTable::Comment("TypeID")
24352434
<< Ty << MatchTable::LineBreak;
24362435
}
2437-
2438-
} // namespace gi
2439-
} // namespace llvm

llvm/utils/TableGen/Common/GlobalISel/PatternParser.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
#include "llvm/TableGen/Error.h"
1818
#include "llvm/TableGen/Record.h"
1919

20-
namespace llvm {
21-
namespace gi {
20+
using namespace llvm;
21+
using namespace gi;
22+
2223
static constexpr StringLiteral MIFlagsEnumClassName = "MIFlagEnum";
2324

2425
namespace {
@@ -445,6 +446,3 @@ const PatFrag *PatternParser::parsePatFrag(const Record *Def) {
445446
SeenPatFrags.insert(Res);
446447
return Res;
447448
}
448-
449-
} // namespace gi
450-
} // namespace llvm

llvm/utils/TableGen/Common/GlobalISel/Patterns.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#include "llvm/TableGen/Error.h"
1919
#include "llvm/TableGen/Record.h"
2020

21-
namespace llvm {
22-
namespace gi {
21+
using namespace llvm;
22+
using namespace gi;
2323

2424
//===- PatternType --------------------------------------------------------===//
2525

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

885885
return true;
886886
}
887-
888-
} // namespace gi
889-
} // namespace llvm

llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,44 +60,43 @@ using namespace llvm::gi;
6060

6161
#define DEBUG_TYPE "gicombiner-emitter"
6262

63-
namespace {
64-
cl::OptionCategory
63+
static cl::OptionCategory
6564
GICombinerEmitterCat("Options for -gen-global-isel-combiner");
66-
cl::opt<bool> StopAfterParse(
65+
static cl::opt<bool> StopAfterParse(
6766
"gicombiner-stop-after-parse",
6867
cl::desc("Stop processing after parsing rules and dump state"),
6968
cl::cat(GICombinerEmitterCat));
70-
cl::list<std::string>
69+
static cl::list<std::string>
7170
SelectedCombiners("combiners", cl::desc("Emit the specified combiners"),
7271
cl::cat(GICombinerEmitterCat), cl::CommaSeparated);
73-
cl::opt<bool> DebugCXXPreds(
72+
static cl::opt<bool> DebugCXXPreds(
7473
"gicombiner-debug-cxxpreds",
7574
cl::desc("Add Contextual/Debug comments to all C++ predicates"),
7675
cl::cat(GICombinerEmitterCat));
77-
cl::opt<bool> DebugTypeInfer("gicombiner-debug-typeinfer",
78-
cl::desc("Print type inference debug logs"),
79-
cl::cat(GICombinerEmitterCat));
76+
static cl::opt<bool> DebugTypeInfer("gicombiner-debug-typeinfer",
77+
cl::desc("Print type inference debug logs"),
78+
cl::cat(GICombinerEmitterCat));
8079

8180
constexpr StringLiteral CXXCustomActionPrefix = "GICXXCustomAction_";
8281
constexpr StringLiteral CXXPredPrefix = "GICXXPred_MI_Predicate_";
8382
constexpr StringLiteral MatchDataClassName = "GIDefMatchData";
8483

8584
//===- CodeExpansions Helpers --------------------------------------------===//
8685

87-
void declareInstExpansion(CodeExpansions &CE, const InstructionMatcher &IM,
88-
StringRef Name) {
86+
static void declareInstExpansion(CodeExpansions &CE,
87+
const InstructionMatcher &IM, StringRef Name) {
8988
CE.declare(Name, "State.MIs[" + to_string(IM.getInsnVarID()) + "]");
9089
}
9190

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

99-
void declareOperandExpansion(CodeExpansions &CE, const OperandMatcher &OM,
100-
StringRef Name) {
98+
static void declareOperandExpansion(CodeExpansions &CE,
99+
const OperandMatcher &OM, StringRef Name) {
101100
if (OM.isVariadic()) {
102101
CE.declare(Name, "getRemainingOperands(*State.MIs[" +
103102
to_string(OM.getInsnVarID()) + "], " +
@@ -108,33 +107,34 @@ void declareOperandExpansion(CodeExpansions &CE, const OperandMatcher &OM,
108107
}
109108
}
110109

111-
void declareTempRegExpansion(CodeExpansions &CE, unsigned TempRegID,
112-
StringRef Name) {
110+
static void declareTempRegExpansion(CodeExpansions &CE, unsigned TempRegID,
111+
StringRef Name) {
113112
CE.declare(Name, "State.TempRegisters[" + to_string(TempRegID) + "]");
114113
}
115114

116115
//===- Misc. Helpers -----------------------------------------------------===//
117116

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

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

126-
std::string getIsEnabledPredicateEnumName(unsigned CombinerRuleID) {
125+
static std::string getIsEnabledPredicateEnumName(unsigned CombinerRuleID) {
127126
return "GICXXPred_Simple_IsRule" + to_string(CombinerRuleID) + "Enabled";
128127
}
129128

130129
//===- MatchTable Helpers ------------------------------------------------===//
131130

132-
LLTCodeGen getLLTCodeGen(const PatternType &PT) {
131+
static LLTCodeGen getLLTCodeGen(const PatternType &PT) {
133132
return *MVTToLLT(getValueType(PT.getLLTRecord()));
134133
}
135134

136135
//===- PrettyStackTrace Helpers ------------------------------------------===//
137136

137+
namespace {
138138
class PrettyStackTraceParse : public PrettyStackTraceEntry {
139139
const Record &Def;
140140

@@ -277,6 +277,7 @@ class CombineRuleOperandTypeChecker : private OperandTypeChecker {
277277

278278
const OperandTable &MatchOpTable;
279279
};
280+
} // namespace
280281

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

2825-
} // end anonymous namespace
2826-
28272826
//===----------------------------------------------------------------------===//
28282827

28292828
static void EmitGICombiner(const RecordKeeper &RK, raw_ostream &OS) {

llvm/utils/TableGen/GlobalISelEmitter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ static cl::opt<bool> OptimizeMatchTable(
8686
cl::desc("Generate an optimized version of the match table"),
8787
cl::init(true), cl::cat(GlobalISelEmitterCat));
8888

89-
namespace {
90-
9189
static std::string explainPredicates(const TreePatternNode &N) {
9290
std::string Explanation;
9391
StringRef Separator = "";
@@ -167,7 +165,7 @@ static std::string explainPredicates(const TreePatternNode &N) {
167165
return Explanation;
168166
}
169167

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

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

315+
namespace {
317316
class GlobalISelEmitter final : public GlobalISelMatchTableExecutorEmitter {
318317
public:
319318
explicit GlobalISelEmitter(const RecordKeeper &RK);
@@ -493,8 +492,11 @@ class GlobalISelEmitter final : public GlobalISelMatchTableExecutorEmitter {
493492
const TreePredicateFn &Predicate,
494493
InstructionMatcher &InsnMatcher, bool &HasAddedMatcher);
495494
};
495+
} // namespace
496496

497-
StringRef getPatFragPredicateEnumName(const Record *R) { return R->getName(); }
497+
static StringRef getPatFragPredicateEnumName(const Record *R) {
498+
return R->getName();
499+
}
498500

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

2537-
} // end anonymous namespace
2538-
25392539
//===----------------------------------------------------------------------===//
25402540

25412541
static TableGen::Emitter::OptClass<GlobalISelEmitter>

0 commit comments

Comments
 (0)