Skip to content

Commit bd7e228

Browse files
authored
[NFC][TableGen] Fix namespace usage in various files (#161839)
- Move standalone functions and variables out of anonymous namespace and make them static. - Eliminate `namespace llvm {}` wrapping all code in .cpp files, and instead use namespace qualifier to define such functions (https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions) - Add namespace for X86DisassemblerShared.h.
1 parent 2a73a79 commit bd7e228

19 files changed

+86
-118
lines changed

llvm/include/llvm/Support/X86DisassemblerDecoderCommon.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818

1919
#include "llvm/Support/DataTypes.h"
2020

21-
namespace llvm {
22-
namespace X86Disassembler {
21+
namespace llvm::X86Disassembler {
2322

2423
#define INSTRUCTIONS_SYM x86DisassemblerInstrSpecifiers
2524
#define CONTEXTS_SYM x86DisassemblerContexts
@@ -541,7 +540,6 @@ static const unsigned X86_MAX_OPERANDS = 6;
541540
/// respectively.
542541
enum DisassemblerMode { MODE_16BIT, MODE_32BIT, MODE_64BIT };
543542

544-
} // namespace X86Disassembler
545-
} // namespace llvm
543+
} // namespace llvm::X86Disassembler
546544

547545
#endif

llvm/lib/TableGen/Error.cpp

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
#include "llvm/TableGen/Record.h"
2020
#include <cstdlib>
2121

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

24-
SourceMgr SrcMgr;
25-
unsigned ErrorsPrinted = 0;
24+
SourceMgr llvm::SrcMgr;
25+
unsigned llvm::ErrorsPrinted = 0;
2626

2727
static void PrintMessage(ArrayRef<SMLoc> Locs, SourceMgr::DiagKind Kind,
2828
const Twine &Msg) {
@@ -49,118 +49,118 @@ static void PrintMessage(ArrayRef<SMLoc> Locs, SourceMgr::DiagKind Kind,
4949

5050
// Functions to print notes.
5151

52-
void PrintNote(const Twine &Msg) {
53-
WithColor::note() << Msg << "\n";
54-
}
52+
void llvm::PrintNote(const Twine &Msg) { WithColor::note() << Msg << "\n"; }
5553

56-
void PrintNote(function_ref<void(raw_ostream &OS)> PrintMsg) {
54+
void llvm::PrintNote(function_ref<void(raw_ostream &OS)> PrintMsg) {
5755
PrintMsg(WithColor::note());
5856
}
5957

60-
void PrintNote(ArrayRef<SMLoc> NoteLoc, const Twine &Msg) {
58+
void llvm::PrintNote(ArrayRef<SMLoc> NoteLoc, const Twine &Msg) {
6159
PrintMessage(NoteLoc, SourceMgr::DK_Note, Msg);
6260
}
6361

6462
// Functions to print fatal notes.
6563

66-
void PrintFatalNote(const Twine &Msg) {
64+
void llvm::PrintFatalNote(const Twine &Msg) {
6765
PrintNote(Msg);
6866
fatal_exit();
6967
}
7068

71-
void PrintFatalNote(ArrayRef<SMLoc> NoteLoc, const Twine &Msg) {
69+
void llvm::PrintFatalNote(ArrayRef<SMLoc> NoteLoc, const Twine &Msg) {
7270
PrintNote(NoteLoc, Msg);
7371
fatal_exit();
7472
}
7573

7674
// This method takes a Record and uses the source location
7775
// stored in it.
78-
void PrintFatalNote(const Record *Rec, const Twine &Msg) {
76+
void llvm::PrintFatalNote(const Record *Rec, const Twine &Msg) {
7977
PrintNote(Rec->getLoc(), Msg);
8078
fatal_exit();
8179
}
8280

8381
// This method takes a RecordVal and uses the source location
8482
// stored in it.
85-
void PrintFatalNote(const RecordVal *RecVal, const Twine &Msg) {
83+
void llvm::PrintFatalNote(const RecordVal *RecVal, const Twine &Msg) {
8684
PrintNote(RecVal->getLoc(), Msg);
8785
fatal_exit();
8886
}
8987

9088
// Functions to print warnings.
9189

92-
void PrintWarning(const Twine &Msg) { WithColor::warning() << Msg << "\n"; }
90+
void llvm::PrintWarning(const Twine &Msg) {
91+
WithColor::warning() << Msg << "\n";
92+
}
9393

94-
void PrintWarning(ArrayRef<SMLoc> WarningLoc, const Twine &Msg) {
94+
void llvm::PrintWarning(ArrayRef<SMLoc> WarningLoc, const Twine &Msg) {
9595
PrintMessage(WarningLoc, SourceMgr::DK_Warning, Msg);
9696
}
9797

98-
void PrintWarning(const char *Loc, const Twine &Msg) {
98+
void llvm::PrintWarning(const char *Loc, const Twine &Msg) {
9999
SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), SourceMgr::DK_Warning, Msg);
100100
}
101101

102102
// Functions to print errors.
103103

104-
void PrintError(const Twine &Msg) { WithColor::error() << Msg << "\n"; }
104+
void llvm::PrintError(const Twine &Msg) { WithColor::error() << Msg << "\n"; }
105105

106-
void PrintError(function_ref<void(raw_ostream &OS)> PrintMsg) {
106+
void llvm::PrintError(function_ref<void(raw_ostream &OS)> PrintMsg) {
107107
PrintMsg(WithColor::error());
108108
}
109109

110-
void PrintError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
110+
void llvm::PrintError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
111111
PrintMessage(ErrorLoc, SourceMgr::DK_Error, Msg);
112112
}
113113

114-
void PrintError(const char *Loc, const Twine &Msg) {
114+
void llvm::PrintError(const char *Loc, const Twine &Msg) {
115115
SrcMgr.PrintMessage(SMLoc::getFromPointer(Loc), SourceMgr::DK_Error, Msg);
116116
}
117117

118118
// This method takes a Record and uses the source location
119119
// stored in it.
120-
void PrintError(const Record *Rec, const Twine &Msg) {
120+
void llvm::PrintError(const Record *Rec, const Twine &Msg) {
121121
PrintMessage(Rec->getLoc(), SourceMgr::DK_Error, Msg);
122122
}
123123

124124
// This method takes a RecordVal and uses the source location
125125
// stored in it.
126-
void PrintError(const RecordVal *RecVal, const Twine &Msg) {
126+
void llvm::PrintError(const RecordVal *RecVal, const Twine &Msg) {
127127
PrintMessage(RecVal->getLoc(), SourceMgr::DK_Error, Msg);
128128
}
129129

130130
// Functions to print fatal errors.
131131

132-
void PrintFatalError(const Twine &Msg) {
132+
void llvm::PrintFatalError(const Twine &Msg) {
133133
PrintError(Msg);
134134
fatal_exit();
135135
}
136136

137-
void PrintFatalError(function_ref<void(raw_ostream &OS)> PrintMsg) {
137+
void llvm::PrintFatalError(function_ref<void(raw_ostream &OS)> PrintMsg) {
138138
PrintError(PrintMsg);
139139
fatal_exit();
140140
}
141141

142-
void PrintFatalError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
142+
void llvm::PrintFatalError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) {
143143
PrintError(ErrorLoc, Msg);
144144
fatal_exit();
145145
}
146146

147147
// This method takes a Record and uses the source location
148148
// stored in it.
149-
void PrintFatalError(const Record *Rec, const Twine &Msg) {
149+
void llvm::PrintFatalError(const Record *Rec, const Twine &Msg) {
150150
PrintError(Rec->getLoc(), Msg);
151151
fatal_exit();
152152
}
153153

154154
// This method takes a RecordVal and uses the source location
155155
// stored in it.
156-
void PrintFatalError(const RecordVal *RecVal, const Twine &Msg) {
156+
void llvm::PrintFatalError(const RecordVal *RecVal, const Twine &Msg) {
157157
PrintError(RecVal->getLoc(), Msg);
158158
fatal_exit();
159159
}
160160

161161
// Check an assertion: Obtain the condition value and be sure it is true.
162162
// If not, print a nonfatal error along with the message.
163-
bool CheckAssert(SMLoc Loc, const Init *Condition, const Init *Message) {
163+
bool llvm::CheckAssert(SMLoc Loc, const Init *Condition, const Init *Message) {
164164
auto *CondValue = dyn_cast_or_null<IntInit>(Condition->convertInitializerTo(
165165
IntRecTy::get(Condition->getRecordKeeper())));
166166
if (!CondValue) {
@@ -178,11 +178,9 @@ bool CheckAssert(SMLoc Loc, const Init *Condition, const Init *Message) {
178178
}
179179

180180
// Dump a message to stderr.
181-
void dumpMessage(SMLoc Loc, const Init *Message) {
181+
void llvm::dumpMessage(SMLoc Loc, const Init *Message) {
182182
if (auto *MessageInit = dyn_cast<StringInit>(Message))
183183
PrintNote(Loc, MessageInit->getValue());
184184
else
185185
PrintError(Loc, "dump value is not of type string");
186186
}
187-
188-
} // end namespace llvm

llvm/lib/TableGen/Main.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,12 @@ WriteIfChanged("write-if-changed", cl::desc("Only write output if it changed"));
6464
static cl::opt<bool>
6565
TimePhases("time-phases", cl::desc("Time phases of parser and backend"));
6666

67-
namespace llvm {
68-
cl::opt<bool> EmitLongStrLiterals(
67+
cl::opt<bool> llvm::EmitLongStrLiterals(
6968
"long-string-literals",
7069
cl::desc("when emitting large string tables, prefer string literals over "
7170
"comma-separated char literals. This can be a readability and "
7271
"compile-time performance win, but upsets some compilers"),
7372
cl::Hidden, cl::init(true));
74-
} // end namespace llvm
7573

7674
static cl::opt<bool> NoWarnOnUnusedTemplateArgs(
7775
"no-warn-on-unused-template-args",

llvm/lib/TableGen/Record.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ using namespace llvm;
4646
// Context
4747
//===----------------------------------------------------------------------===//
4848

49-
namespace llvm {
50-
namespace detail {
49+
namespace llvm::detail {
5150
/// This class represents the internal implementation of the RecordKeeper.
5251
/// It contains all of the contextual static state of the Record classes. It is
5352
/// kept out-of-line to simplify dependencies, and also make it easier for
@@ -100,8 +99,7 @@ struct RecordKeeperImpl {
10099

101100
void dumpAllocationStats(raw_ostream &OS) const;
102101
};
103-
} // namespace detail
104-
} // namespace llvm
102+
} // namespace llvm::detail
105103

106104
void detail::RecordKeeperImpl::dumpAllocationStats(raw_ostream &OS) const {
107105
// Dump memory allocation related stats.

llvm/lib/TableGen/TGParser.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ using namespace llvm;
3131
// Support Code for the Semantic Actions.
3232
//===----------------------------------------------------------------------===//
3333

34-
namespace llvm {
35-
3634
RecordsEntry::RecordsEntry(std::unique_ptr<Record> Rec) : Rec(std::move(Rec)) {}
3735
RecordsEntry::RecordsEntry(std::unique_ptr<ForeachLoop> Loop)
3836
: Loop(std::move(Loop)) {}
@@ -41,6 +39,7 @@ RecordsEntry::RecordsEntry(std::unique_ptr<Record::AssertionInfo> Assertion)
4139
RecordsEntry::RecordsEntry(std::unique_ptr<Record::DumpInfo> Dump)
4240
: Dump(std::move(Dump)) {}
4341

42+
namespace llvm {
4443
struct SubClassReference {
4544
SMRange RefRange;
4645
const Record *Rec = nullptr;
@@ -61,6 +60,7 @@ struct SubMultiClassReference {
6160
bool isInvalid() const { return MC == nullptr; }
6261
void dump() const;
6362
};
63+
} // end namespace llvm
6464

6565
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
6666
LLVM_DUMP_METHOD void SubMultiClassReference::dump() const {
@@ -74,8 +74,6 @@ LLVM_DUMP_METHOD void SubMultiClassReference::dump() const {
7474
}
7575
#endif
7676

77-
} // end namespace llvm
78-
7977
static bool checkBitsConcrete(Record &R, const RecordVal &RV) {
8078
const auto *BV = cast<BitsInit>(RV.getValue());
8179
for (unsigned i = 0, e = BV->getNumBits(); i != e; ++i) {

llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,16 +246,14 @@ bool TypeSetByHwMode::operator==(const TypeSetByHwMode &VTS) const {
246246
return true;
247247
}
248248

249-
namespace llvm {
250-
raw_ostream &operator<<(raw_ostream &OS, const MachineValueTypeSet &T) {
249+
raw_ostream &llvm::operator<<(raw_ostream &OS, const MachineValueTypeSet &T) {
251250
T.writeToStream(OS);
252251
return OS;
253252
}
254-
raw_ostream &operator<<(raw_ostream &OS, const TypeSetByHwMode &T) {
253+
raw_ostream &llvm::operator<<(raw_ostream &OS, const TypeSetByHwMode &T) {
255254
T.writeToStream(OS);
256255
return OS;
257256
}
258-
} // namespace llvm
259257

260258
LLVM_DUMP_METHOD
261259
void TypeSetByHwMode::dump() const { dbgs() << *this << '\n'; }

llvm/utils/TableGen/Common/CodeGenRegisters.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -857,17 +857,6 @@ unsigned CodeGenRegisterClass::getWeight(const CodeGenRegBank &RegBank) const {
857857
return (*Members.begin())->getWeight(RegBank);
858858
}
859859

860-
namespace llvm {
861-
862-
raw_ostream &operator<<(raw_ostream &OS, const CodeGenRegisterClass::Key &K) {
863-
OS << "{ " << K.RSI;
864-
for (const auto R : *K.Members)
865-
OS << ", " << R->getName();
866-
return OS << " }";
867-
}
868-
869-
} // end namespace llvm
870-
871860
// This is a simple lexicographical order that can be used to search for sets.
872861
// It is not the same as the topological order provided by TopoOrderRC.
873862
bool CodeGenRegisterClass::Key::operator<(

llvm/utils/TableGen/Common/InfoByHwMode.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,19 +227,17 @@ EncodingInfoByHwMode::EncodingInfoByHwMode(const Record *R,
227227
}
228228
}
229229

230-
namespace llvm {
231-
raw_ostream &operator<<(raw_ostream &OS, const ValueTypeByHwMode &T) {
230+
raw_ostream &llvm::operator<<(raw_ostream &OS, const ValueTypeByHwMode &T) {
232231
T.writeToStream(OS);
233232
return OS;
234233
}
235234

236-
raw_ostream &operator<<(raw_ostream &OS, const RegSizeInfo &T) {
235+
raw_ostream &llvm::operator<<(raw_ostream &OS, const RegSizeInfo &T) {
237236
T.writeToStream(OS);
238237
return OS;
239238
}
240239

241-
raw_ostream &operator<<(raw_ostream &OS, const RegSizeInfoByHwMode &T) {
240+
raw_ostream &llvm::operator<<(raw_ostream &OS, const RegSizeInfoByHwMode &T) {
242241
T.writeToStream(OS);
243242
return OS;
244243
}
245-
} // namespace llvm

llvm/utils/TableGen/Common/PredicateExpander.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "CodeGenSchedule.h" // Definition of STIPredicateFunction.
1515
#include "llvm/TableGen/Record.h"
1616

17-
namespace llvm {
17+
using namespace llvm;
1818

1919
void PredicateExpander::expandTrue(raw_ostream &OS) { OS << "true"; }
2020
void PredicateExpander::expandFalse(raw_ostream &OS) { OS << "false"; }
@@ -553,5 +553,3 @@ void STIPredicateExpander::expandSTIPredicate(raw_ostream &OS,
553553
expandEpilogue(OS, Fn);
554554
}
555555
}
556-
557-
} // namespace llvm

llvm/utils/TableGen/DXILEmitter.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,6 @@ struct DXILIntrinsicSelect {
3737
SmallVector<const Record *> ArgSelectRecords;
3838
};
3939

40-
static StringRef StripIntrinArgSelectTypePrefix(StringRef Type) {
41-
StringRef Prefix = "IntrinArgSelect_";
42-
if (!Type.starts_with(Prefix)) {
43-
PrintFatalError("IntrinArgSelectType definintion must be prefixed with "
44-
"'IntrinArgSelect_'");
45-
}
46-
return Type.substr(Prefix.size());
47-
}
48-
4940
struct DXILOperationDesc {
5041
std::string OpName; // name of DXIL operation
5142
int OpCode; // ID of DXIL operation
@@ -66,6 +57,15 @@ struct DXILOperationDesc {
6657
};
6758
} // end anonymous namespace
6859

60+
static StringRef stripIntrinArgSelectTypePrefix(StringRef Type) {
61+
StringRef Prefix = "IntrinArgSelect_";
62+
if (!Type.starts_with(Prefix)) {
63+
PrintFatalError("IntrinArgSelectType definintion must be prefixed with "
64+
"'IntrinArgSelect_'");
65+
}
66+
return Type.substr(Prefix.size());
67+
}
68+
6969
/// In-place sort TableGen records of class with a field
7070
/// Version dxil_version
7171
/// in the ascending version order.
@@ -449,7 +449,7 @@ static void emitDXILIntrinsicMap(ArrayRef<DXILOperationDesc> Ops,
449449
ArgSelect->getValueAsDef("type")->getNameInitAsString();
450450
int Value = ArgSelect->getValueAsInt("value");
451451
OS << "(IntrinArgSelect{"
452-
<< "IntrinArgSelect::Type::" << StripIntrinArgSelectTypePrefix(Type)
452+
<< "IntrinArgSelect::Type::" << stripIntrinArgSelectTypePrefix(Type)
453453
<< "," << Value << "}), ";
454454
}
455455
OS << ")\n";
@@ -466,7 +466,7 @@ static void emitDXILIntrinsicArgSelectTypes(const RecordKeeper &Records,
466466
OS << "#ifdef DXIL_OP_INTRINSIC_ARG_SELECT_TYPE\n";
467467
for (const Record *Records :
468468
Records.getAllDerivedDefinitions("IntrinArgSelectType")) {
469-
StringRef StrippedName = StripIntrinArgSelectTypePrefix(Records->getName());
469+
StringRef StrippedName = stripIntrinArgSelectTypePrefix(Records->getName());
470470
OS << "DXIL_OP_INTRINSIC_ARG_SELECT_TYPE(" << StrippedName << ")\n";
471471
}
472472
OS << "#undef DXIL_OP_INTRINSIC_ARG_SELECT_TYPE\n";

0 commit comments

Comments
 (0)