Skip to content

Commit 37fff6e

Browse files
authored
[NFC][LLVM][IR] Cleanup namespace usage in LLVM IR cpp files (#166477)
1 parent e7f7973 commit 37fff6e

File tree

11 files changed

+35
-54
lines changed

11 files changed

+35
-54
lines changed

llvm/lib/IR/AsmWriter.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -758,14 +758,12 @@ void TypePrinting::printStructBody(StructType *STy, raw_ostream &OS) {
758758

759759
AbstractSlotTrackerStorage::~AbstractSlotTrackerStorage() = default;
760760

761-
namespace llvm {
762-
763761
//===----------------------------------------------------------------------===//
764762
// SlotTracker Class: Enumerate slot numbers for unnamed values
765763
//===----------------------------------------------------------------------===//
766764
/// This class provides computation of slot numbers for LLVM Assembly writing.
767765
///
768-
class SlotTracker : public AbstractSlotTrackerStorage {
766+
class llvm::SlotTracker : public AbstractSlotTrackerStorage {
769767
public:
770768
/// ValueMap - A mapping of Values to slot numbers.
771769
using ValueMap = DenseMap<const Value *, unsigned>;
@@ -943,8 +941,6 @@ class SlotTracker : public AbstractSlotTrackerStorage {
943941
void processDbgRecordMetadata(const DbgRecord &DVR);
944942
};
945943

946-
} // end namespace llvm
947-
948944
ModuleSlotTracker::ModuleSlotTracker(SlotTracker &Machine, const Module *M,
949945
const Function *F)
950946
: M(M), F(F), Machine(&Machine) {}

llvm/lib/IR/DebugLoc.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
#include "llvm/Config/llvm-config.h"
1111
#include "llvm/IR/DebugInfo.h"
1212

13+
using namespace llvm;
14+
1315
#if LLVM_ENABLE_DEBUGLOC_TRACKING_ORIGIN
1416
#include "llvm/Support/Signals.h"
1517

16-
namespace llvm {
1718
DbgLocOrigin::DbgLocOrigin(bool ShouldCollectTrace) {
1819
if (!ShouldCollectTrace)
1920
return;
@@ -30,11 +31,8 @@ void DbgLocOrigin::addTrace() {
3031
auto &[Depth, StackTrace] = StackTraces.emplace_back();
3132
Depth = sys::getStackTrace(StackTrace);
3233
}
33-
} // namespace llvm
3434
#endif
3535

36-
using namespace llvm;
37-
3836
#if LLVM_ENABLE_DEBUGLOC_TRACKING_COVERAGE
3937
DILocAndCoverageTracking::DILocAndCoverageTracking(const DILocation *L)
4038
: TrackingMDNodeRef(const_cast<DILocation *>(L)), DbgLocOrigin(!L),

llvm/lib/IR/DebugProgramInstruction.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
#include "llvm/IR/IntrinsicInst.h"
1313
#include "llvm/Support/Compiler.h"
1414

15-
namespace llvm {
15+
using namespace llvm;
1616

17+
namespace llvm {
1718
template <typename T>
1819
DbgRecordParamRef<T>::DbgRecordParamRef(const T *Param)
1920
: Ref(const_cast<T *>(Param)) {}
@@ -28,6 +29,7 @@ template <typename T> T *DbgRecordParamRef<T>::get() const {
2829
template class LLVM_EXPORT_TEMPLATE DbgRecordParamRef<DIExpression>;
2930
template class LLVM_EXPORT_TEMPLATE DbgRecordParamRef<DILabel>;
3031
template class LLVM_EXPORT_TEMPLATE DbgRecordParamRef<DILocalVariable>;
32+
} // namespace llvm
3133

3234
DbgVariableRecord::DbgVariableRecord(const DbgVariableIntrinsic *DVI)
3335
: DbgRecord(ValueKind, DVI->getDebugLoc()),
@@ -755,5 +757,3 @@ iterator_range<simple_ilist<DbgRecord>::iterator> DbgMarker::cloneDebugInfoFrom(
755757
// We inserted a block at the end, return that range.
756758
return {First->getIterator(), StoredDbgRecords.end()};
757759
}
758-
759-
} // end namespace llvm

llvm/lib/IR/FPEnv.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
#include "llvm/IR/Intrinsics.h"
2020
#include <optional>
2121

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

24-
std::optional<RoundingMode> convertStrToRoundingMode(StringRef RoundingArg) {
24+
std::optional<RoundingMode>
25+
llvm::convertStrToRoundingMode(StringRef RoundingArg) {
2526
// For dynamic rounding mode, we use round to nearest but we will set the
2627
// 'exact' SDNodeFlag so that the value will not be rounded.
2728
return StringSwitch<std::optional<RoundingMode>>(RoundingArg)
@@ -34,7 +35,8 @@ std::optional<RoundingMode> convertStrToRoundingMode(StringRef RoundingArg) {
3435
.Default(std::nullopt);
3536
}
3637

37-
std::optional<StringRef> convertRoundingModeToStr(RoundingMode UseRounding) {
38+
std::optional<StringRef>
39+
llvm::convertRoundingModeToStr(RoundingMode UseRounding) {
3840
std::optional<StringRef> RoundingStr;
3941
switch (UseRounding) {
4042
case RoundingMode::Dynamic:
@@ -62,7 +64,7 @@ std::optional<StringRef> convertRoundingModeToStr(RoundingMode UseRounding) {
6264
}
6365

6466
std::optional<fp::ExceptionBehavior>
65-
convertStrToExceptionBehavior(StringRef ExceptionArg) {
67+
llvm::convertStrToExceptionBehavior(StringRef ExceptionArg) {
6668
return StringSwitch<std::optional<fp::ExceptionBehavior>>(ExceptionArg)
6769
.Case("fpexcept.ignore", fp::ebIgnore)
6870
.Case("fpexcept.maytrap", fp::ebMayTrap)
@@ -71,7 +73,7 @@ convertStrToExceptionBehavior(StringRef ExceptionArg) {
7173
}
7274

7375
std::optional<StringRef>
74-
convertExceptionBehaviorToStr(fp::ExceptionBehavior UseExcept) {
76+
llvm::convertExceptionBehaviorToStr(fp::ExceptionBehavior UseExcept) {
7577
std::optional<StringRef> ExceptStr;
7678
switch (UseExcept) {
7779
case fp::ebStrict:
@@ -87,7 +89,7 @@ convertExceptionBehaviorToStr(fp::ExceptionBehavior UseExcept) {
8789
return ExceptStr;
8890
}
8991

90-
Intrinsic::ID getConstrainedIntrinsicID(const Instruction &Instr) {
92+
Intrinsic::ID llvm::getConstrainedIntrinsicID(const Instruction &Instr) {
9193
Intrinsic::ID IID = Intrinsic::not_intrinsic;
9294
switch (Instr.getOpcode()) {
9395
case Instruction::FCmp:
@@ -127,5 +129,3 @@ Intrinsic::ID getConstrainedIntrinsicID(const Instruction &Instr) {
127129

128130
return IID;
129131
}
130-
131-
} // namespace llvm

llvm/lib/IR/Operator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
#include "ConstantsContext.h"
1919

20-
namespace llvm {
20+
using namespace llvm;
21+
2122
bool Operator::hasPoisonGeneratingFlags() const {
2223
switch (getOpcode()) {
2324
case Instruction::Add:
@@ -288,4 +289,3 @@ void FastMathFlags::print(raw_ostream &O) const {
288289
O << " afn";
289290
}
290291
}
291-
} // namespace llvm

llvm/lib/IR/PassTimingInfo.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ using namespace llvm;
3232

3333
#define DEBUG_TYPE "time-passes"
3434

35-
namespace llvm {
35+
using namespace llvm;
3636

37-
bool TimePassesIsEnabled = false;
38-
bool TimePassesPerRun = false;
37+
bool llvm::TimePassesIsEnabled = false;
38+
bool llvm::TimePassesPerRun = false;
3939

4040
static cl::opt<bool, true> EnableTiming(
4141
"time-passes", cl::location(TimePassesIsEnabled), cl::Hidden,
@@ -139,7 +139,7 @@ PassTimingInfo *PassTimingInfo::TheTimeInfo;
139139
} // namespace legacy
140140
} // namespace
141141

142-
Timer *getPassTimer(Pass *P) {
142+
Timer *llvm::getPassTimer(Pass *P) {
143143
legacy::PassTimingInfo::init();
144144
if (legacy::PassTimingInfo::TheTimeInfo)
145145
return legacy::PassTimingInfo::TheTimeInfo->getPassTimer(P, P);
@@ -148,7 +148,7 @@ Timer *getPassTimer(Pass *P) {
148148

149149
/// If timing is enabled, report the times collected up to now and then reset
150150
/// them.
151-
void reportAndResetTimings(raw_ostream *OutStream) {
151+
void llvm::reportAndResetTimings(raw_ostream *OutStream) {
152152
if (legacy::PassTimingInfo::TheTimeInfo)
153153
legacy::PassTimingInfo::TheTimeInfo->print(OutStream);
154154
}
@@ -315,5 +315,3 @@ void TimePassesHandler::registerCallbacks(PassInstrumentationCallbacks &PIC) {
315315
PIC.registerAfterAnalysisCallback(
316316
[this](StringRef P, Any) { this->stopAnalysisTimer(P); });
317317
}
318-
319-
} // namespace llvm

llvm/lib/IR/PseudoProbe.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919

2020
using namespace llvm;
2121

22-
namespace llvm {
23-
24-
std::optional<PseudoProbe>
22+
static std::optional<PseudoProbe>
2523
extractProbeFromDiscriminator(const DILocation *DIL) {
2624
if (DIL) {
2725
auto Discriminator = DIL->getDiscriminator();
@@ -43,7 +41,7 @@ extractProbeFromDiscriminator(const DILocation *DIL) {
4341
return std::nullopt;
4442
}
4543

46-
std::optional<PseudoProbe>
44+
static std::optional<PseudoProbe>
4745
extractProbeFromDiscriminator(const Instruction &Inst) {
4846
assert(isa<CallBase>(&Inst) && !isa<IntrinsicInst>(&Inst) &&
4947
"Only call instructions should have pseudo probe encodes as their "
@@ -53,7 +51,7 @@ extractProbeFromDiscriminator(const Instruction &Inst) {
5351
return std::nullopt;
5452
}
5553

56-
std::optional<PseudoProbe> extractProbe(const Instruction &Inst) {
54+
std::optional<PseudoProbe> llvm::extractProbe(const Instruction &Inst) {
5755
if (const auto *II = dyn_cast<PseudoProbeInst>(&Inst)) {
5856
PseudoProbe Probe;
5957
Probe.Id = II->getIndex()->getZExtValue();
@@ -73,7 +71,7 @@ std::optional<PseudoProbe> extractProbe(const Instruction &Inst) {
7371
return std::nullopt;
7472
}
7573

76-
void setProbeDistributionFactor(Instruction &Inst, float Factor) {
74+
void llvm::setProbeDistributionFactor(Instruction &Inst, float Factor) {
7775
assert(Factor >= 0 && Factor <= 1 &&
7876
"Distribution factor must be in [0, 1.0]");
7977
if (auto *II = dyn_cast<PseudoProbeInst>(&Inst)) {
@@ -111,5 +109,3 @@ void setProbeDistributionFactor(Instruction &Inst, float Factor) {
111109
}
112110
}
113111
}
114-
115-
} // namespace llvm

llvm/lib/IR/ReplaceConstant.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "llvm/IR/Constants.h"
1717
#include "llvm/IR/Instructions.h"
1818

19-
namespace llvm {
19+
using namespace llvm;
2020

2121
static bool isExpandableUser(User *U) {
2222
return isa<ConstantExpr>(U) || isa<ConstantAggregate>(U);
@@ -49,10 +49,10 @@ static SmallVector<Instruction *, 4> expandUser(BasicBlock::iterator InsertPt,
4949
return NewInsts;
5050
}
5151

52-
bool convertUsersOfConstantsToInstructions(ArrayRef<Constant *> Consts,
53-
Function *RestrictToFunc,
54-
bool RemoveDeadConstants,
55-
bool IncludeSelf) {
52+
bool llvm::convertUsersOfConstantsToInstructions(ArrayRef<Constant *> Consts,
53+
Function *RestrictToFunc,
54+
bool RemoveDeadConstants,
55+
bool IncludeSelf) {
5656
// Find all expandable direct users of Consts.
5757
SmallVector<Constant *> Stack;
5858
for (Constant *C : Consts) {
@@ -121,5 +121,3 @@ bool convertUsersOfConstantsToInstructions(ArrayRef<Constant *> Consts,
121121

122122
return Changed;
123123
}
124-
125-
} // namespace llvm

llvm/lib/IR/Use.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "llvm/IR/Use.h"
1010
#include "llvm/IR/User.h"
1111

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

1414
void Use::swap(Use &RHS) {
1515
if (Val == RHS.Val)
@@ -42,5 +42,3 @@ void Use::zap(Use *Start, const Use *Stop, bool del) {
4242
if (del)
4343
::operator delete(Start);
4444
}
45-
46-
} // namespace llvm

llvm/lib/IR/User.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
#include "llvm/IR/GlobalValue.h"
1212
#include "llvm/IR/IntrinsicInst.h"
1313

14+
using namespace llvm;
15+
1416
namespace llvm {
1517
class BasicBlock;
18+
}
1619

1720
//===----------------------------------------------------------------------===//
1821
// User Class
@@ -214,5 +217,3 @@ LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE void User::operator delete(void *Usr) {
214217
::operator delete(Storage);
215218
}
216219
}
217-
218-
} // namespace llvm

0 commit comments

Comments
 (0)