Skip to content

Commit e524446

Browse files
committed
[NFC][LLVM] Fix namespace usage in Transforms/Scalar
1 parent 178e2a7 commit e524446

23 files changed

+121
-143
lines changed

llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ static cl::opt<unsigned>
121121
cl::Hidden, cl::init(50));
122122

123123
namespace {
124-
125124
class SelectInstToUnfold {
126125
SelectInst *SI;
127126
PHINode *SIUse;
@@ -134,11 +133,14 @@ class SelectInstToUnfold {
134133

135134
explicit operator bool() const { return SI && SIUse; }
136135
};
136+
} // namespace
137137

138-
void unfold(DomTreeUpdater *DTU, LoopInfo *LI, SelectInstToUnfold SIToUnfold,
139-
std::vector<SelectInstToUnfold> *NewSIsToUnfold,
140-
std::vector<BasicBlock *> *NewBBs);
138+
static void unfold(DomTreeUpdater *DTU, LoopInfo *LI,
139+
SelectInstToUnfold SIToUnfold,
140+
std::vector<SelectInstToUnfold> *NewSIsToUnfold,
141+
std::vector<BasicBlock *> *NewBBs);
141142

143+
namespace {
142144
class DFAJumpThreading {
143145
public:
144146
DFAJumpThreading(AssumptionCache *AC, DominatorTree *DT, LoopInfo *LI,
@@ -176,18 +178,17 @@ class DFAJumpThreading {
176178

177179
} // end anonymous namespace
178180

179-
namespace {
180-
181181
/// Unfold the select instruction held in \p SIToUnfold by replacing it with
182182
/// control flow.
183183
///
184184
/// Put newly discovered select instructions into \p NewSIsToUnfold. Put newly
185185
/// created basic blocks into \p NewBBs.
186186
///
187187
/// TODO: merge it with CodeGenPrepare::optimizeSelectInst() if possible.
188-
void unfold(DomTreeUpdater *DTU, LoopInfo *LI, SelectInstToUnfold SIToUnfold,
189-
std::vector<SelectInstToUnfold> *NewSIsToUnfold,
190-
std::vector<BasicBlock *> *NewBBs) {
188+
static void unfold(DomTreeUpdater *DTU, LoopInfo *LI,
189+
SelectInstToUnfold SIToUnfold,
190+
std::vector<SelectInstToUnfold> *NewSIsToUnfold,
191+
std::vector<BasicBlock *> *NewBBs) {
191192
SelectInst *SI = SIToUnfold.getInst();
192193
PHINode *SIUse = SIToUnfold.getUse();
193194
assert(SI->hasOneUse());
@@ -342,10 +343,12 @@ void unfold(DomTreeUpdater *DTU, LoopInfo *LI, SelectInstToUnfold SIToUnfold,
342343
SI->eraseFromParent();
343344
}
344345

346+
namespace {
345347
struct ClonedBlock {
346348
BasicBlock *BB;
347349
APInt State; ///< \p State corresponds to the next value of a switch stmnt.
348350
};
351+
} // namespace
349352

350353
typedef std::deque<BasicBlock *> PathType;
351354
typedef std::vector<PathType> PathsType;
@@ -375,6 +378,7 @@ inline raw_ostream &operator<<(raw_ostream &OS, const PathType &Path) {
375378
return OS;
376379
}
377380

381+
namespace {
378382
/// ThreadingPath is a path in the control flow of a loop that can be threaded
379383
/// by cloning necessary basic blocks and replacing conditional branches with
380384
/// unconditional ones. A threading path includes a list of basic blocks, the
@@ -1336,6 +1340,7 @@ struct TransformDFA {
13361340
SmallPtrSet<const Value *, 32> EphValues;
13371341
std::vector<ThreadingPath> TPaths;
13381342
};
1343+
} // namespace
13391344

13401345
bool DFAJumpThreading::run(Function &F) {
13411346
LLVM_DEBUG(dbgs() << "\nDFA Jump threading: " << F.getName() << "\n");
@@ -1415,8 +1420,6 @@ bool DFAJumpThreading::run(Function &F) {
14151420
return MadeChanges;
14161421
}
14171422

1418-
} // end anonymous namespace
1419-
14201423
/// Integrate with the new Pass Manager
14211424
PreservedAnalyses DFAJumpThreadingPass::run(Function &F,
14221425
FunctionAnalysisManager &AM) {

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#include "llvm/Support/DebugCounter.h"
7878
#include "llvm/Support/ErrorHandling.h"
7979
#include "llvm/Support/raw_ostream.h"
80+
#include "llvm/Transforms/Scalar.h"
8081
#include "llvm/Transforms/Utils/AssumeBundleBuilder.h"
8182
#include "llvm/Transforms/Utils/BuildLibCalls.h"
8283
#include "llvm/Transforms/Utils/Local.h"
@@ -805,9 +806,8 @@ tryToMergePartialOverlappingStores(StoreInst *KillingI, StoreInst *DeadI,
805806
return nullptr;
806807
}
807808

808-
namespace {
809809
// Returns true if \p I is an intrinsic that does not read or write memory.
810-
bool isNoopIntrinsic(Instruction *I) {
810+
static bool isNoopIntrinsic(Instruction *I) {
811811
if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
812812
switch (II->getIntrinsicID()) {
813813
case Intrinsic::lifetime_start:
@@ -828,7 +828,7 @@ bool isNoopIntrinsic(Instruction *I) {
828828
}
829829

830830
// Check if we can ignore \p D for DSE.
831-
bool canSkipDef(MemoryDef *D, bool DefVisibleToCaller) {
831+
static bool canSkipDef(MemoryDef *D, bool DefVisibleToCaller) {
832832
Instruction *DI = D->getMemoryInst();
833833
// Calls that only access inaccessible memory cannot read or write any memory
834834
// locations we consider for elimination.
@@ -856,6 +856,7 @@ bool canSkipDef(MemoryDef *D, bool DefVisibleToCaller) {
856856
return false;
857857
}
858858

859+
namespace {
859860
// A memory location wrapper that represents a MemoryLocation, `MemLoc`,
860861
// defined by `MemDef`.
861862
struct MemoryLocationWrapper {
@@ -889,23 +890,25 @@ struct MemoryDefWrapper {
889890
SmallVector<MemoryLocationWrapper, 1> DefinedLocations;
890891
};
891892

892-
bool hasInitializesAttr(Instruction *I) {
893-
CallBase *CB = dyn_cast<CallBase>(I);
894-
return CB && CB->getArgOperandWithAttribute(Attribute::Initializes);
895-
}
896-
897893
struct ArgumentInitInfo {
898894
unsigned Idx;
899895
bool IsDeadOrInvisibleOnUnwind;
900896
ConstantRangeList Inits;
901897
};
898+
} // namespace
899+
900+
static bool hasInitializesAttr(Instruction *I) {
901+
CallBase *CB = dyn_cast<CallBase>(I);
902+
return CB && CB->getArgOperandWithAttribute(Attribute::Initializes);
903+
}
902904

903905
// Return the intersected range list of the initializes attributes of "Args".
904906
// "Args" are call arguments that alias to each other.
905907
// If any argument in "Args" doesn't have dead_on_unwind attr and
906908
// "CallHasNoUnwindAttr" is false, return empty.
907-
ConstantRangeList getIntersectedInitRangeList(ArrayRef<ArgumentInitInfo> Args,
908-
bool CallHasNoUnwindAttr) {
909+
static ConstantRangeList
910+
getIntersectedInitRangeList(ArrayRef<ArgumentInitInfo> Args,
911+
bool CallHasNoUnwindAttr) {
909912
if (Args.empty())
910913
return {};
911914

@@ -925,6 +928,7 @@ ConstantRangeList getIntersectedInitRangeList(ArrayRef<ArgumentInitInfo> Args,
925928
return IntersectedIntervals;
926929
}
927930

931+
namespace {
928932
struct DSEState {
929933
Function &F;
930934
AliasAnalysis &AA;
@@ -2328,10 +2332,11 @@ struct DSEState {
23282332
// change state: whether make any change.
23292333
bool eliminateDeadDefs(const MemoryDefWrapper &KillingDefWrapper);
23302334
};
2335+
} // namespace
23312336

23322337
// Return true if "Arg" is function local and isn't captured before "CB".
2333-
bool isFuncLocalAndNotCaptured(Value *Arg, const CallBase *CB,
2334-
EarliestEscapeAnalysis &EA) {
2338+
static bool isFuncLocalAndNotCaptured(Value *Arg, const CallBase *CB,
2339+
EarliestEscapeAnalysis &EA) {
23352340
const Value *UnderlyingObj = getUnderlyingObject(Arg);
23362341
return isIdentifiedFunctionLocal(UnderlyingObj) &&
23372342
capturesNothing(
@@ -2627,7 +2632,6 @@ static bool eliminateDeadStores(Function &F, AliasAnalysis &AA, MemorySSA &MSSA,
26272632

26282633
return MadeChange;
26292634
}
2630-
} // end anonymous namespace
26312635

26322636
//===----------------------------------------------------------------------===//
26332637
// DSE Pass
@@ -2728,8 +2732,6 @@ INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
27282732
INITIALIZE_PASS_END(DSELegacyPass, "dse", "Dead Store Elimination", false,
27292733
false)
27302734

2731-
namespace llvm {
2732-
LLVM_ABI FunctionPass *createDeadStoreEliminationPass() {
2735+
LLVM_ABI FunctionPass *llvm::createDeadStoreEliminationPass() {
27332736
return new DSELegacyPass();
27342737
}
2735-
} // namespace llvm

llvm/lib/Transforms/Scalar/FlattenCFGPass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ struct FlattenCFGLegacyPass : public FunctionPass {
3939
private:
4040
AliasAnalysis *AA;
4141
};
42+
} // namespace
4243

4344
/// iterativelyFlattenCFG - Call FlattenCFG on all the blocks in the function,
4445
/// iterating until no more changes are made.
45-
bool iterativelyFlattenCFG(Function &F, AliasAnalysis *AA) {
46+
static bool iterativelyFlattenCFG(Function &F, AliasAnalysis *AA) {
4647
bool Changed = false;
4748
bool LocalChange = true;
4849

@@ -67,7 +68,6 @@ bool iterativelyFlattenCFG(Function &F, AliasAnalysis *AA) {
6768
}
6869
return Changed;
6970
}
70-
} // namespace
7171

7272
char FlattenCFGLegacyPass::ID = 0;
7373

llvm/lib/Transforms/Scalar/GVNSink.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,14 @@ using namespace llvm;
7878

7979
STATISTIC(NumRemoved, "Number of instructions removed");
8080

81-
namespace llvm {
82-
namespace GVNExpression {
81+
namespace llvm::GVNExpression {
8382

8483
LLVM_DUMP_METHOD void Expression::dump() const {
8584
print(dbgs());
8685
dbgs() << "\n";
8786
}
8887

89-
} // end namespace GVNExpression
90-
} // end namespace llvm
91-
92-
namespace {
88+
} // end namespace llvm::GVNExpression
9389

9490
static bool isMemoryInst(const Instruction *I) {
9591
return isa<LoadInst>(I) || isa<StoreInst>(I) ||
@@ -103,6 +99,7 @@ static bool isMemoryInst(const Instruction *I) {
10399
/// sink instructions, differing in the number of instructions sunk,
104100
/// the number of predecessors sunk from and the number of PHIs
105101
/// required.
102+
namespace {
106103
struct SinkingInstructionCandidate {
107104
unsigned NumBlocks;
108105
unsigned NumInstructions;
@@ -594,6 +591,7 @@ class GVNSink {
594591
}
595592
}
596593
};
594+
} // namespace
597595

598596
std::optional<SinkingInstructionCandidate>
599597
GVNSink::analyzeInstructionForSinking(LockstepReverseIterator<false> &LRI,
@@ -851,8 +849,6 @@ void GVNSink::sinkLastInstruction(ArrayRef<BasicBlock *> Blocks,
851849
NumRemoved += Insts.size() - 1;
852850
}
853851

854-
} // end anonymous namespace
855-
856852
PreservedAnalyses GVNSinkPass::run(Function &F, FunctionAnalysisManager &AM) {
857853
GVNSink G;
858854
if (!G.run(F))

llvm/lib/Transforms/Scalar/GuardWidening.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ static cl::opt<bool>
7575
"expressed as branches by widenable conditions"),
7676
cl::init(true));
7777

78-
namespace {
79-
8078
// Get the condition of \p I. It can either be a guard or a conditional branch.
8179
static Value *getCondition(Instruction *I) {
8280
if (IntrinsicInst *GI = dyn_cast<IntrinsicInst>(I)) {
@@ -130,6 +128,7 @@ findInsertionPointForWideCondition(Instruction *WCOrGuard) {
130128
return std::nullopt;
131129
}
132130

131+
namespace {
133132
class GuardWideningImpl {
134133
DominatorTree &DT;
135134
PostDominatorTree *PDT;
@@ -328,7 +327,7 @@ class GuardWideningImpl {
328327
/// The entry point for this pass.
329328
bool run();
330329
};
331-
}
330+
} // namespace
332331

333332
static bool isSupportedGuardInstruction(const Instruction *Insn) {
334333
if (isGuard(Insn))

llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626

2727
using namespace llvm;
2828

29-
namespace llvm {
30-
3129
static cl::opt<unsigned>
3230
JumpTableSizeThreshold("jump-table-to-switch-size-threshold", cl::Hidden,
3331
cl::desc("Only split jump tables with size less or "
@@ -43,8 +41,8 @@ static cl::opt<unsigned> FunctionSizeThreshold(
4341
"or equal than this threshold."),
4442
cl::init(50));
4543

44+
namespace llvm {
4645
extern cl::opt<bool> ProfcheckDisableMetadataFixes;
47-
4846
} // end namespace llvm
4947

5048
#define DEBUG_TYPE "jump-table-to-switch"

llvm/lib/Transforms/Scalar/LICM.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ STATISTIC(NumIntAssociationsHoisted,
116116
STATISTIC(NumBOAssociationsHoisted, "Number of invariant BinaryOp expressions "
117117
"reassociated and hoisted out of the loop");
118118

119-
namespace llvm {
120-
121119
/// Memory promotion is enabled by default.
122120
static cl::opt<bool>
123121
DisablePromotion("disable-licm-promotion", cl::Hidden, cl::init(false),
@@ -156,23 +154,22 @@ static cl::opt<unsigned> IntAssociationUpperLimit(
156154
// which may not be precise, since optimizeUses is capped. The result is
157155
// correct, but we may not get as "far up" as possible to get which access is
158156
// clobbering the one queried.
159-
cl::opt<unsigned> SetLicmMssaOptCap(
157+
cl::opt<unsigned> llvm::SetLicmMssaOptCap(
160158
"licm-mssa-optimization-cap", cl::init(100), cl::Hidden,
161159
cl::desc("Enable imprecision in LICM in pathological cases, in exchange "
162160
"for faster compile. Caps the MemorySSA clobbering calls."));
163161

164162
// Experimentally, memory promotion carries less importance than sinking and
165163
// hoisting. Limit when we do promotion when using MemorySSA, in order to save
166164
// compile time.
167-
cl::opt<unsigned> SetLicmMssaNoAccForPromotionCap(
165+
cl::opt<unsigned> llvm::SetLicmMssaNoAccForPromotionCap(
168166
"licm-mssa-max-acc-promotion", cl::init(250), cl::Hidden,
169167
cl::desc("[LICM & MemorySSA] When MSSA in LICM is disabled, this has no "
170168
"effect. When MSSA in LICM is enabled, then this is the maximum "
171169
"number of accesses allowed to be present in a loop in order to "
172170
"enable memory promotion."));
173-
171+
namespace llvm {
174172
extern cl::opt<bool> ProfcheckDisableMetadataFixes;
175-
176173
} // end namespace llvm
177174

178175
static bool inSubLoop(BasicBlock *BB, Loop *CurLoop, LoopInfo *LI);
@@ -1120,11 +1117,10 @@ static bool isLoadInvariantInLoop(LoadInst *LI, DominatorTree *DT,
11201117
return false;
11211118
}
11221119

1123-
namespace {
11241120
/// Return true if-and-only-if we know how to (mechanically) both hoist and
11251121
/// sink a given instruction out of a loop. Does not address legality
11261122
/// concerns such as aliasing or speculation safety.
1127-
bool isHoistableAndSinkableInst(Instruction &I) {
1123+
static bool isHoistableAndSinkableInst(Instruction &I) {
11281124
// Only these instructions are hoistable/sinkable.
11291125
return (isa<LoadInst>(I) || isa<StoreInst>(I) || isa<CallInst>(I) ||
11301126
isa<FenceInst>(I) || isa<CastInst>(I) || isa<UnaryOperator>(I) ||
@@ -1136,8 +1132,8 @@ bool isHoistableAndSinkableInst(Instruction &I) {
11361132
}
11371133

11381134
/// Return true if I is the only Instruction with a MemoryAccess in L.
1139-
bool isOnlyMemoryAccess(const Instruction *I, const Loop *L,
1140-
const MemorySSAUpdater &MSSAU) {
1135+
static bool isOnlyMemoryAccess(const Instruction *I, const Loop *L,
1136+
const MemorySSAUpdater &MSSAU) {
11411137
for (auto *BB : L->getBlocks())
11421138
if (auto *Accs = MSSAU.getMemorySSA()->getBlockAccesses(BB)) {
11431139
int NotAPhi = 0;
@@ -1151,7 +1147,6 @@ bool isOnlyMemoryAccess(const Instruction *I, const Loop *L,
11511147
}
11521148
return true;
11531149
}
1154-
}
11551150

11561151
static MemoryAccess *getClobberingMemoryAccess(MemorySSA &MSSA,
11571152
BatchAAResults &BAA,

llvm/lib/Transforms/Scalar/LoopBoundSplit.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121

2222
#define DEBUG_TYPE "loop-bound-split"
2323

24-
namespace llvm {
25-
24+
using namespace llvm;
2625
using namespace PatternMatch;
2726

2827
namespace {
@@ -486,5 +485,3 @@ PreservedAnalyses LoopBoundSplitPass::run(Loop &L, LoopAnalysisManager &AM,
486485

487486
return getLoopPassPreservedAnalyses();
488487
}
489-
490-
} // end namespace llvm

0 commit comments

Comments
 (0)