[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.
This commit is contained in:
Michael Kruse 2021-02-10 20:07:58 -06:00
parent 5ad416ca78
commit 91ca9adc9e
17 changed files with 134 additions and 24 deletions

View File

@ -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;

View File

@ -27,6 +27,7 @@
#include "isl/ctx.h"
namespace polly {
using llvm::SmallPtrSet;
struct Dependences;

View File

@ -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 @@ private:
Value *materializeNonScopLoopInductionVariable(const Loop *L);
};
} // namespace polly
#endif // POLLY_ISLNODEBUILDER_H

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -22,7 +22,7 @@ void initializeForwardOpTreeWrapperPassPass(PassRegistry &);
} // namespace llvm
namespace polly {
Pass *createForwardOpTreeWrapperPass();
llvm::Pass *createForwardOpTreeWrapperPass();
struct ForwardOpTreePass : llvm::PassInfoMixin<ForwardOpTreePass> {
ForwardOpTreePass() {}

View File

@ -22,6 +22,7 @@
#include "llvm/ADT/SetVector.h"
namespace polly {
using llvm::SmallSetVector;
class ScopDetection;

View File

@ -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 @@ public:
///
/// 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.

View File

@ -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 *>;

View File

@ -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 @@ private:
/// 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.

View File

@ -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;

View File

@ -17,6 +17,7 @@
#include "polly/ScopInfo.h"
namespace polly {
using llvm::User;
/// Determine the nature of a value's use within a statement.
///

View File

@ -225,7 +225,7 @@ static int findReferencesInBlock(struct SubtreeReferences &References,
return 0;
}
void addReferencesFromStmt(const ScopStmt *Stmt, void *UserPtr,
void polly::addReferencesFromStmt(const ScopStmt *Stmt, void *UserPtr,
bool CreateScalarRefs) {
auto &References = *static_cast<struct SubtreeReferences *>(UserPtr);

View File

@ -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(

View File

@ -23,7 +23,9 @@
#define DEBUG_TYPE "polly-scop-inliner"
using namespace llvm;
using namespace polly;
extern bool polly::PollyAllowFullFunction;
namespace {