[polly] 91ca9ad - [Polly] Avoid "using namespace llvm" in public headers. NFC.

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 10 19:00:34 PST 2021


Author: Michael Kruse
Date: 2021-02-10T20:58:33-06:00
New Revision: 91ca9adc9edfba164b579d02c5fe0a7a24cfdd4e

URL: https://github.com/llvm/llvm-project/commit/91ca9adc9edfba164b579d02c5fe0a7a24cfdd4e
DIFF: https://github.com/llvm/llvm-project/commit/91ca9adc9edfba164b579d02c5fe0a7a24cfdd4e.diff

LOG: [Polly] Avoid "using namespace llvm" in public headers. NFC.

"using namespace" pollutes the namespace of every file that includes
such a header and universally considered a bad thing. Even the variant

    namespace polly {
      using namespace llvm;
    }

(previously used by LoopGenerators.h) imports more symbols than the file
is in control of. The header may include a fixed set of files from LLVM,
but the header itself may by be included together with other headers
from LLVM. For instance, LLVM's MemorySSA.h and Polly's ScopInfo.h both
declare a class 'MemoryAccess' which may conflict.

Instead of prefixing everything in Polly's header files, this patch adds
'using' statements to import only the symbols that are actually
referenced in Polly. This approach is also used by MLIR to import
commonly used symbols into the mlir namespace.

This patch also puts the symbols declared in IslNodeBuilder.h into the
Polly namespace to also be able to use the imported symbols.

Added: 
    

Modified: 
    polly/include/polly/CodeGen/BlockGenerators.h
    polly/include/polly/CodeGen/IslAst.h
    polly/include/polly/CodeGen/IslNodeBuilder.h
    polly/include/polly/CodeGen/LoopGenerators.h
    polly/include/polly/CodeGen/LoopGeneratorsGOMP.h
    polly/include/polly/CodeGen/LoopGeneratorsKMP.h
    polly/include/polly/DependenceInfo.h
    polly/include/polly/ForwardOpTree.h
    polly/include/polly/ScopBuilder.h
    polly/include/polly/ScopDetection.h
    polly/include/polly/ScopDetectionDiagnostic.h
    polly/include/polly/ScopInfo.h
    polly/include/polly/ScopPass.h
    polly/include/polly/Support/VirtualInstruction.h
    polly/lib/CodeGen/IslNodeBuilder.cpp
    polly/lib/CodeGen/ManagedMemoryRewrite.cpp
    polly/lib/Transform/ScopInliner.cpp

Removed: 
    


################################################################################
diff  --git a/polly/include/polly/CodeGen/BlockGenerators.h b/polly/include/polly/CodeGen/BlockGenerators.h
index f2c52c8fedcf..f02524a34254 100644
--- a/polly/include/polly/CodeGen/BlockGenerators.h
+++ b/polly/include/polly/CodeGen/BlockGenerators.h
@@ -21,7 +21,32 @@
 #include "isl/isl-noexceptions.h"
 
 namespace polly {
-using namespace llvm;
+using llvm::AllocaInst;
+using llvm::ArrayRef;
+using llvm::AssertingVH;
+using llvm::BasicBlock;
+using llvm::BinaryOperator;
+using llvm::CmpInst;
+using llvm::DataLayout;
+using llvm::DenseMap;
+using llvm::DominatorTree;
+using llvm::Function;
+using llvm::Instruction;
+using llvm::LoadInst;
+using llvm::Loop;
+using llvm::LoopInfo;
+using llvm::LoopToScevMapT;
+using llvm::MapVector;
+using llvm::PHINode;
+using llvm::ScalarEvolution;
+using llvm::SetVector;
+using llvm::SmallVector;
+using llvm::StoreInst;
+using llvm::StringRef;
+using llvm::Type;
+using llvm::UnaryInstruction;
+using llvm::Value;
+
 class MemoryAccess;
 class ScopArrayInfo;
 class IslExprBuilder;

diff  --git a/polly/include/polly/CodeGen/IslAst.h b/polly/include/polly/CodeGen/IslAst.h
index 1a842b87d6d5..fc2a5e461fa1 100644
--- a/polly/include/polly/CodeGen/IslAst.h
+++ b/polly/include/polly/CodeGen/IslAst.h
@@ -27,6 +27,7 @@
 #include "isl/ctx.h"
 
 namespace polly {
+using llvm::SmallPtrSet;
 
 struct Dependences;
 

diff  --git a/polly/include/polly/CodeGen/IslNodeBuilder.h b/polly/include/polly/CodeGen/IslNodeBuilder.h
index ac28af20a3d4..3177762c8802 100644
--- a/polly/include/polly/CodeGen/IslNodeBuilder.h
+++ b/polly/include/polly/CodeGen/IslNodeBuilder.h
@@ -23,13 +23,11 @@
 #include "isl/ctx.h"
 #include "isl/isl-noexceptions.h"
 
-using namespace llvm;
-using namespace polly;
-
 namespace polly {
+using llvm::LoopInfo;
+using llvm::SmallSet;
 
 struct InvariantEquivClassTy;
-} // namespace polly
 
 struct SubtreeReferences {
   LoopInfo &LI;
@@ -429,4 +427,6 @@ class IslNodeBuilder {
   Value *materializeNonScopLoopInductionVariable(const Loop *L);
 };
 
+} // namespace polly
+
 #endif // POLLY_ISLNODEBUILDER_H

diff  --git a/polly/include/polly/CodeGen/LoopGenerators.h b/polly/include/polly/CodeGen/LoopGenerators.h
index 09a0424525c9..bb73f229d87c 100644
--- a/polly/include/polly/CodeGen/LoopGenerators.h
+++ b/polly/include/polly/CodeGen/LoopGenerators.h
@@ -18,7 +18,17 @@
 #include "llvm/ADT/SetVector.h"
 
 namespace polly {
-using namespace llvm;
+using llvm::AllocaInst;
+using llvm::BasicBlock;
+using llvm::DataLayout;
+using llvm::DominatorTree;
+using llvm::Function;
+using llvm::ICmpInst;
+using llvm::LoopInfo;
+using llvm::Module;
+using llvm::SetVector;
+using llvm::Type;
+using llvm::Value;
 
 /// General scheduling types of parallel OpenMP for loops.
 /// Initialization values taken from OpenMP's enum in kmp.h: sched_type.

diff  --git a/polly/include/polly/CodeGen/LoopGeneratorsGOMP.h b/polly/include/polly/CodeGen/LoopGeneratorsGOMP.h
index b3ff9825ff3b..1f47d38f0162 100644
--- a/polly/include/polly/CodeGen/LoopGeneratorsGOMP.h
+++ b/polly/include/polly/CodeGen/LoopGeneratorsGOMP.h
@@ -19,7 +19,6 @@
 #include "llvm/ADT/SetVector.h"
 
 namespace polly {
-using namespace llvm;
 
 /// This ParallelLoopGenerator subclass handles the generation of parallelized
 /// code, utilizing the GNU OpenMP library.

diff  --git a/polly/include/polly/CodeGen/LoopGeneratorsKMP.h b/polly/include/polly/CodeGen/LoopGeneratorsKMP.h
index 470df6002bee..c4921aced766 100644
--- a/polly/include/polly/CodeGen/LoopGeneratorsKMP.h
+++ b/polly/include/polly/CodeGen/LoopGeneratorsKMP.h
@@ -19,7 +19,8 @@
 #include "llvm/ADT/SetVector.h"
 
 namespace polly {
-using namespace llvm;
+using llvm::GlobalValue;
+using llvm::GlobalVariable;
 
 /// This ParallelLoopGenerator subclass handles the generation of parallelized
 /// code, utilizing the LLVM OpenMP library.

diff  --git a/polly/include/polly/DependenceInfo.h b/polly/include/polly/DependenceInfo.h
index d66be816349b..a8b11191d619 100644
--- a/polly/include/polly/DependenceInfo.h
+++ b/polly/include/polly/DependenceInfo.h
@@ -26,8 +26,6 @@
 #include "isl/ctx.h"
 #include "isl/isl-noexceptions.h"
 
-using namespace llvm;
-
 namespace polly {
 
 /// The accumulated dependence information for a SCoP.

diff  --git a/polly/include/polly/ForwardOpTree.h b/polly/include/polly/ForwardOpTree.h
index dfa11bea9414..72c77c398ad5 100644
--- a/polly/include/polly/ForwardOpTree.h
+++ b/polly/include/polly/ForwardOpTree.h
@@ -22,7 +22,7 @@ void initializeForwardOpTreeWrapperPassPass(PassRegistry &);
 } // namespace llvm
 
 namespace polly {
-Pass *createForwardOpTreeWrapperPass();
+llvm::Pass *createForwardOpTreeWrapperPass();
 
 struct ForwardOpTreePass : llvm::PassInfoMixin<ForwardOpTreePass> {
   ForwardOpTreePass() {}

diff  --git a/polly/include/polly/ScopBuilder.h b/polly/include/polly/ScopBuilder.h
index 7bed07c36c52..7c3a944dd5c9 100644
--- a/polly/include/polly/ScopBuilder.h
+++ b/polly/include/polly/ScopBuilder.h
@@ -22,6 +22,7 @@
 #include "llvm/ADT/SetVector.h"
 
 namespace polly {
+using llvm::SmallSetVector;
 
 class ScopDetection;
 

diff  --git a/polly/include/polly/ScopDetection.h b/polly/include/polly/ScopDetection.h
index f28ab498c83f..835dd135d8c6 100644
--- a/polly/include/polly/ScopDetection.h
+++ b/polly/include/polly/ScopDetection.h
@@ -54,8 +54,6 @@
 #include "llvm/Pass.h"
 #include <set>
 
-using namespace llvm;
-
 namespace llvm {
 class AAResults;
 
@@ -63,6 +61,32 @@ void initializeScopDetectionWrapperPassPass(PassRegistry &);
 } // namespace llvm
 
 namespace polly {
+using llvm::AAResults;
+using llvm::AliasSetTracker;
+using llvm::AnalysisInfoMixin;
+using llvm::AnalysisKey;
+using llvm::AnalysisUsage;
+using llvm::BranchInst;
+using llvm::CallInst;
+using llvm::DenseMap;
+using llvm::DominatorTree;
+using llvm::Function;
+using llvm::FunctionAnalysisManager;
+using llvm::FunctionPass;
+using llvm::IntrinsicInst;
+using llvm::LoopInfo;
+using llvm::Module;
+using llvm::OptimizationRemarkEmitter;
+using llvm::PassInfoMixin;
+using llvm::PreservedAnalyses;
+using llvm::RegionInfo;
+using llvm::ScalarEvolution;
+using llvm::SCEVUnknown;
+using llvm::SetVector;
+using llvm::SmallSetVector;
+using llvm::SmallVectorImpl;
+using llvm::StringRef;
+using llvm::SwitchInst;
 
 using ParamSetType = std::set<const SCEV *>;
 
@@ -136,7 +160,7 @@ class ScopDetection {
     ///
     /// This set contains all base pointers and the locations where they are
     /// used for memory accesses that can not be detected as affine accesses.
-    SetVector<std::pair<const SCEVUnknown *, Loop *>> NonAffineAccesses;
+    llvm::SetVector<std::pair<const SCEVUnknown *, Loop *>> NonAffineAccesses;
     BaseToElSize ElementSize;
 
     /// The region has at least one load instruction.

diff  --git a/polly/include/polly/ScopDetectionDiagnostic.h b/polly/include/polly/ScopDetectionDiagnostic.h
index 682461584617..200fb8f47d37 100644
--- a/polly/include/polly/ScopDetectionDiagnostic.h
+++ b/polly/include/polly/ScopDetectionDiagnostic.h
@@ -25,10 +25,7 @@
 #include "llvm/IR/Instruction.h"
 #include <cstddef>
 
-using namespace llvm;
-
 namespace llvm {
-
 class AliasSet;
 class BasicBlock;
 class OptimizationRemarkEmitter;
@@ -37,6 +34,17 @@ class SCEV;
 } // namespace llvm
 
 namespace polly {
+using llvm::AliasSet;
+using llvm::BasicBlock;
+using llvm::DebugLoc;
+using llvm::Instruction;
+using llvm::Loop;
+using llvm::OptimizationRemarkEmitter;
+using llvm::raw_ostream;
+using llvm::Region;
+using llvm::SCEV;
+using llvm::SmallVector;
+using llvm::Value;
 
 /// Type to hold region delimiters (entry & exit block).
 using BBPair = std::pair<BasicBlock *, BasicBlock *>;

diff  --git a/polly/include/polly/ScopInfo.h b/polly/include/polly/ScopInfo.h
index dbebfb2aa40e..6ac029c32102 100644
--- a/polly/include/polly/ScopInfo.h
+++ b/polly/include/polly/ScopInfo.h
@@ -35,14 +35,42 @@
 #include <cstddef>
 #include <forward_list>
 
-using namespace llvm;
-
 namespace llvm {
 void initializeScopInfoRegionPassPass(PassRegistry &);
 void initializeScopInfoWrapperPassPass(PassRegistry &);
 } // end namespace llvm
 
 namespace polly {
+using llvm::AnalysisInfoMixin;
+using llvm::ArrayRef;
+using llvm::AssertingVH;
+using llvm::AssumptionCache;
+using llvm::cast;
+using llvm::DataLayout;
+using llvm::DenseMap;
+using llvm::DenseSet;
+using llvm::function_ref;
+using llvm::isa;
+using llvm::iterator_range;
+using llvm::LoadInst;
+using llvm::make_range;
+using llvm::MapVector;
+using llvm::MemIntrinsic;
+using llvm::Optional;
+using llvm::PassInfoMixin;
+using llvm::PHINode;
+using llvm::RegionNode;
+using llvm::RegionPass;
+using llvm::RGPassManager;
+using llvm::SetVector;
+using llvm::SmallPtrSetImpl;
+using llvm::SmallVector;
+using llvm::SmallVectorImpl;
+using llvm::StringMap;
+using llvm::Type;
+using llvm::Use;
+using llvm::Value;
+using llvm::ValueToValueMap;
 
 class MemoryAccess;
 
@@ -1212,7 +1240,7 @@ class ScopStmt {
   /// The memory accesses of this statement.
   ///
   /// The only side effects of a statement are its memory accesses.
-  using MemoryAccessVec = SmallVector<MemoryAccess *, 8>;
+  using MemoryAccessVec = llvm::SmallVector<MemoryAccess *, 8>;
   MemoryAccessVec MemAccs;
 
   /// Mapping from instructions to (scalar) memory accesses.

diff  --git a/polly/include/polly/ScopPass.h b/polly/include/polly/ScopPass.h
index e091a39c8190..ccd6da143843 100644
--- a/polly/include/polly/ScopPass.h
+++ b/polly/include/polly/ScopPass.h
@@ -24,9 +24,20 @@
 #include "llvm/IR/PassManager.h"
 #include "llvm/IR/PassManagerImpl.h"
 
-using namespace llvm;
-
 namespace polly {
+using llvm::AllAnalysesOn;
+using llvm::AnalysisManager;
+using llvm::DominatorTreeAnalysis;
+using llvm::InnerAnalysisManagerProxy;
+using llvm::LoopAnalysis;
+using llvm::OuterAnalysisManagerProxy;
+using llvm::PassManager;
+using llvm::RegionInfoAnalysis;
+using llvm::ScalarEvolutionAnalysis;
+using llvm::SmallPriorityWorklist;
+using llvm::TargetIRAnalysis;
+using llvm::TargetTransformInfo;
+
 class Scop;
 class SPMUpdater;
 struct ScopStandardAnalysisResults;

diff  --git a/polly/include/polly/Support/VirtualInstruction.h b/polly/include/polly/Support/VirtualInstruction.h
index 90bf04f5bf46..4faf66e6caf9 100644
--- a/polly/include/polly/Support/VirtualInstruction.h
+++ b/polly/include/polly/Support/VirtualInstruction.h
@@ -17,6 +17,7 @@
 #include "polly/ScopInfo.h"
 
 namespace polly {
+using llvm::User;
 
 /// Determine the nature of a value's use within a statement.
 ///

diff  --git a/polly/lib/CodeGen/IslNodeBuilder.cpp b/polly/lib/CodeGen/IslNodeBuilder.cpp
index a329661feddf..688618e23be0 100644
--- a/polly/lib/CodeGen/IslNodeBuilder.cpp
+++ b/polly/lib/CodeGen/IslNodeBuilder.cpp
@@ -225,8 +225,8 @@ static int findReferencesInBlock(struct SubtreeReferences &References,
   return 0;
 }
 
-void addReferencesFromStmt(const ScopStmt *Stmt, void *UserPtr,
-                           bool CreateScalarRefs) {
+void polly::addReferencesFromStmt(const ScopStmt *Stmt, void *UserPtr,
+                                  bool CreateScalarRefs) {
   auto &References = *static_cast<struct SubtreeReferences *>(UserPtr);
 
   if (Stmt->isBlockStmt())

diff  --git a/polly/lib/CodeGen/ManagedMemoryRewrite.cpp b/polly/lib/CodeGen/ManagedMemoryRewrite.cpp
index 72ad0264b5bd..64bfa8dd8b1b 100644
--- a/polly/lib/CodeGen/ManagedMemoryRewrite.cpp
+++ b/polly/lib/CodeGen/ManagedMemoryRewrite.cpp
@@ -26,6 +26,7 @@
 #include "llvm/InitializePasses.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
 
+using namespace llvm;
 using namespace polly;
 
 static cl::opt<bool> RewriteAllocas(

diff  --git a/polly/lib/Transform/ScopInliner.cpp b/polly/lib/Transform/ScopInliner.cpp
index 3d0737f13cde..83c3b8d350ba 100644
--- a/polly/lib/Transform/ScopInliner.cpp
+++ b/polly/lib/Transform/ScopInliner.cpp
@@ -23,7 +23,9 @@
 
 #define DEBUG_TYPE "polly-scop-inliner"
 
+using namespace llvm;
 using namespace polly;
+
 extern bool polly::PollyAllowFullFunction;
 
 namespace {


        


More information about the llvm-commits mailing list