From 31f8499e83dc4dccbb57ea7e76d1fd49b7010d0c Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 21 Nov 2003 20:23:48 +0000 Subject: [PATCH] Finegrainify namespacification git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10131 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bytecode/Writer/SlotCalculator.cpp | 5 +- lib/VMCore/AsmWriter.cpp | 16 +- lib/VMCore/Constants.cpp | 228 +++++++++++++------------ lib/VMCore/Dominators.cpp | 7 +- lib/VMCore/Function.cpp | 5 +- lib/VMCore/Module.cpp | 16 +- lib/VMCore/ModuleProvider.cpp | 5 +- lib/VMCore/Pass.cpp | 5 +- lib/VMCore/SlotCalculator.cpp | 5 +- lib/VMCore/SymbolTable.cpp | 5 +- lib/VMCore/Value.cpp | 5 +- lib/VMCore/Verifier.cpp | 20 +-- lib/VMCore/iMemory.cpp | 1 - 13 files changed, 152 insertions(+), 171 deletions(-) diff --git a/lib/Bytecode/Writer/SlotCalculator.cpp b/lib/Bytecode/Writer/SlotCalculator.cpp index c6e44e8266f..f4414a5921d 100644 --- a/lib/Bytecode/Writer/SlotCalculator.cpp +++ b/lib/Bytecode/Writer/SlotCalculator.cpp @@ -26,8 +26,7 @@ #include "Support/PostOrderIterator.h" #include "Support/STLExtras.h" #include - -namespace llvm { +using namespace llvm; #if 0 #define SC_DEBUG(X) std::cerr << X @@ -363,5 +362,3 @@ int SlotCalculator::doInsertValue(const Value *D) { SC_DEBUG("]\n"); return (int)DestSlot; } - -} // End llvm namespace diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index 1823412755b..671864972ba 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -32,8 +32,7 @@ #include "Support/StringExtras.h" #include "Support/STLExtras.h" #include - -namespace llvm { +using namespace llvm; static RegisterPass X("printm", "Print module to stderr",PassInfo::Analysis|PassInfo::Optimization); @@ -233,8 +232,8 @@ static std::ostream &printTypeInt(std::ostream &Out, const Type *Ty, // type, iff there is an entry in the modules symbol table for the specified // type or one of it's component types. This is slower than a simple x << Type; // -std::ostream &WriteTypeSymbolic(std::ostream &Out, const Type *Ty, - const Module *M) { +std::ostream &llvm::WriteTypeSymbolic(std::ostream &Out, const Type *Ty, + const Module *M) { Out << " "; // If they want us to print out a type, attempt to make it symbolic if there @@ -447,7 +446,8 @@ static void WriteAsOperandInternal(std::ostream &Out, const Value *V, // ostream. This can be useful when you just want to print int %reg126, not the // whole instruction that generated it. // -std::ostream &WriteAsOperand(std::ostream &Out, const Value *V, bool PrintType, +std::ostream &llvm::WriteAsOperand(std::ostream &Out, const Value *V, + bool PrintType, bool PrintName, const Module *Context) { std::map TypeNames; if (Context == 0) Context = getModuleFromVal(V); @@ -465,7 +465,7 @@ std::ostream &WriteAsOperand(std::ostream &Out, const Value *V, bool PrintType, return Out; } - +namespace llvm { class AssemblyWriter { std::ostream &Out; @@ -520,7 +520,7 @@ private : // which slot it occupies. void printInfoComment(const Value &V); }; - +} // end of anonymous namespace // printTypeAtLeastOneLevel - Print out one level of the possibly complex type // without considering any symbolic types that we may have equal to it. @@ -1063,5 +1063,3 @@ CachedWriter &CachedWriter::operator<<(const Value *V) { } return *this; } - -} // End llvm namespace diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 05bbef16b3f..2a9af77ef6a 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -19,8 +19,7 @@ #include "llvm/Module.h" #include "Support/StringExtras.h" #include - -namespace llvm { +using namespace llvm; ConstantBool *ConstantBool::True = new ConstantBool(true); ConstantBool *ConstantBool::False = new ConstantBool(false); @@ -540,20 +539,22 @@ void ConstantExpr::replaceUsesOfWithOnConstant(Value *From, Value *ToV, // something strange that needs to be done to interface to the ctor for the // constant. // -template -struct ConstantCreator { - static ConstantClass *create(const TypeClass *Ty, const ValType &V) { - return new ConstantClass(Ty, V); - } -}; - -template -struct ConvertConstantType { - static void convert(ConstantClass *OldC, const TypeClass *NewTy) { - assert(0 && "This type cannot be converted!\n"); - abort(); - } -}; +namespace llvm { + template + struct ConstantCreator { + static ConstantClass *create(const TypeClass *Ty, const ValType &V) { + return new ConstantClass(Ty, V); + } + }; + + template + struct ConvertConstantType { + static void convert(ConstantClass *OldC, const TypeClass *NewTy) { + assert(0 && "This type cannot be converted!\n"); + abort(); + } + }; +} namespace { template @@ -712,21 +713,21 @@ ConstantFP *ConstantFP::get(const Type *Ty, double V) { //---- ConstantArray::get() implementation... // - -template<> -struct ConvertConstantType { - static void convert(ConstantArray *OldC, const ArrayType *NewTy) { - // Make everyone now use a constant of the new type... - std::vector C; - for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i) - C.push_back(cast(OldC->getOperand(i))); - Constant *New = ConstantArray::get(NewTy, C); - assert(New != OldC && "Didn't replace constant??"); - OldC->uncheckedReplaceAllUsesWith(New); - OldC->destroyConstant(); // This constant is now dead, destroy it. - } -}; - +namespace llvm { + template<> + struct ConvertConstantType { + static void convert(ConstantArray *OldC, const ArrayType *NewTy) { + // Make everyone now use a constant of the new type... + std::vector C; + for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i) + C.push_back(cast(OldC->getOperand(i))); + Constant *New = ConstantArray::get(NewTy, C); + assert(New != OldC && "Didn't replace constant??"); + OldC->uncheckedReplaceAllUsesWith(New); + OldC->destroyConstant(); // This constant is now dead, destroy it. + } + }; +} static ValueMap, ArrayType, ConstantArray> ArrayConstants; @@ -778,20 +779,22 @@ std::string ConstantArray::getAsString() const { //---- ConstantStruct::get() implementation... // -template<> -struct ConvertConstantType { - static void convert(ConstantStruct *OldC, const StructType *NewTy) { - // Make everyone now use a constant of the new type... - std::vector C; - for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i) - C.push_back(cast(OldC->getOperand(i))); - Constant *New = ConstantStruct::get(NewTy, C); - assert(New != OldC && "Didn't replace constant??"); - - OldC->uncheckedReplaceAllUsesWith(New); - OldC->destroyConstant(); // This constant is now dead, destroy it. - } -}; +namespace llvm { + template<> + struct ConvertConstantType { + static void convert(ConstantStruct *OldC, const StructType *NewTy) { + // Make everyone now use a constant of the new type... + std::vector C; + for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i) + C.push_back(cast(OldC->getOperand(i))); + Constant *New = ConstantStruct::get(NewTy, C); + assert(New != OldC && "Didn't replace constant??"); + + OldC->uncheckedReplaceAllUsesWith(New); + OldC->destroyConstant(); // This constant is now dead, destroy it. + } + }; +} static ValueMap, StructType, ConstantStruct> StructConstants; @@ -811,24 +814,26 @@ void ConstantStruct::destroyConstant() { //---- ConstantPointerNull::get() implementation... // -// ConstantPointerNull does not take extra "value" argument... -template -struct ConstantCreator { - static ConstantPointerNull *create(const PointerType *Ty, const ValType &V){ - return new ConstantPointerNull(Ty); - } -}; +namespace llvm { + // ConstantPointerNull does not take extra "value" argument... + template + struct ConstantCreator { + static ConstantPointerNull *create(const PointerType *Ty, const ValType &V){ + return new ConstantPointerNull(Ty); + } + }; -template<> -struct ConvertConstantType { - static void convert(ConstantPointerNull *OldC, const PointerType *NewTy) { - // Make everyone now use a constant of the new type... - Constant *New = ConstantPointerNull::get(NewTy); - assert(New != OldC && "Didn't replace constant??"); - OldC->uncheckedReplaceAllUsesWith(New); - OldC->destroyConstant(); // This constant is now dead, destroy it. - } -}; + template<> + struct ConvertConstantType { + static void convert(ConstantPointerNull *OldC, const PointerType *NewTy) { + // Make everyone now use a constant of the new type... + Constant *New = ConstantPointerNull::get(NewTy); + assert(New != OldC && "Didn't replace constant??"); + OldC->uncheckedReplaceAllUsesWith(New); + OldC->destroyConstant(); // This constant is now dead, destroy it. + } + }; +} static ValueMap NullPtrConstants; @@ -865,56 +870,58 @@ void ConstantPointerRef::destroyConstant() { // typedef std::pair > ExprMapKeyType; -template<> -struct ConstantCreator { - static ConstantExpr *create(const Type *Ty, const ExprMapKeyType &V) { - if (V.first == Instruction::Cast) - return new ConstantExpr(Instruction::Cast, V.second[0], Ty); - if ((V.first >= Instruction::BinaryOpsBegin && - V.first < Instruction::BinaryOpsEnd) || - V.first == Instruction::Shl || V.first == Instruction::Shr) - return new ConstantExpr(V.first, V.second[0], V.second[1]); - - assert(V.first == Instruction::GetElementPtr && "Invalid ConstantExpr!"); - - std::vector IdxList(V.second.begin()+1, V.second.end()); - return new ConstantExpr(V.second[0], IdxList, Ty); - } -}; - -template<> -struct ConvertConstantType { - static void convert(ConstantExpr *OldC, const Type *NewTy) { - Constant *New; - switch (OldC->getOpcode()) { - case Instruction::Cast: - New = ConstantExpr::getCast(OldC->getOperand(0), NewTy); - break; - case Instruction::Shl: - case Instruction::Shr: - New = ConstantExpr::getShiftTy(NewTy, OldC->getOpcode(), - OldC->getOperand(0), OldC->getOperand(1)); - break; - default: - assert(OldC->getOpcode() >= Instruction::BinaryOpsBegin && - OldC->getOpcode() < Instruction::BinaryOpsEnd); - New = ConstantExpr::getTy(NewTy, OldC->getOpcode(), OldC->getOperand(0), - OldC->getOperand(1)); - break; - case Instruction::GetElementPtr: - // Make everyone now use a constant of the new type... - std::vector C; - for (unsigned i = 1, e = OldC->getNumOperands(); i != e; ++i) - C.push_back(cast(OldC->getOperand(i))); - New = ConstantExpr::getGetElementPtrTy(NewTy, OldC->getOperand(0), C); - break; +namespace llvm { + template<> + struct ConstantCreator { + static ConstantExpr *create(const Type *Ty, const ExprMapKeyType &V) { + if (V.first == Instruction::Cast) + return new ConstantExpr(Instruction::Cast, V.second[0], Ty); + if ((V.first >= Instruction::BinaryOpsBegin && + V.first < Instruction::BinaryOpsEnd) || + V.first == Instruction::Shl || V.first == Instruction::Shr) + return new ConstantExpr(V.first, V.second[0], V.second[1]); + + assert(V.first == Instruction::GetElementPtr && "Invalid ConstantExpr!"); + + std::vector IdxList(V.second.begin()+1, V.second.end()); + return new ConstantExpr(V.second[0], IdxList, Ty); } + }; - assert(New != OldC && "Didn't replace constant??"); - OldC->uncheckedReplaceAllUsesWith(New); - OldC->destroyConstant(); // This constant is now dead, destroy it. - } -}; + template<> + struct ConvertConstantType { + static void convert(ConstantExpr *OldC, const Type *NewTy) { + Constant *New; + switch (OldC->getOpcode()) { + case Instruction::Cast: + New = ConstantExpr::getCast(OldC->getOperand(0), NewTy); + break; + case Instruction::Shl: + case Instruction::Shr: + New = ConstantExpr::getShiftTy(NewTy, OldC->getOpcode(), + OldC->getOperand(0), OldC->getOperand(1)); + break; + default: + assert(OldC->getOpcode() >= Instruction::BinaryOpsBegin && + OldC->getOpcode() < Instruction::BinaryOpsEnd); + New = ConstantExpr::getTy(NewTy, OldC->getOpcode(), OldC->getOperand(0), + OldC->getOperand(1)); + break; + case Instruction::GetElementPtr: + // Make everyone now use a constant of the new type... + std::vector C; + for (unsigned i = 1, e = OldC->getNumOperands(); i != e; ++i) + C.push_back(cast(OldC->getOperand(i))); + New = ConstantExpr::getGetElementPtrTy(NewTy, OldC->getOperand(0), C); + break; + } + + assert(New != OldC && "Didn't replace constant??"); + OldC->uncheckedReplaceAllUsesWith(New); + OldC->destroyConstant(); // This constant is now dead, destroy it. + } + }; +} // end namespace llvm static ValueMap ExprConstants; @@ -1039,4 +1046,3 @@ unsigned Constant::mutateReferences(Value *OldV, Value *NewV) { } } -} // End llvm namespace diff --git a/lib/VMCore/Dominators.cpp b/lib/VMCore/Dominators.cpp index cad66853c9c..dbdb4097305 100644 --- a/lib/VMCore/Dominators.cpp +++ b/lib/VMCore/Dominators.cpp @@ -19,8 +19,7 @@ #include "llvm/Assembly/Writer.h" #include "Support/DepthFirstIterator.h" #include "Support/SetOperations.h" - -namespace llvm { +using namespace llvm; //===----------------------------------------------------------------------===// // DominatorSet Implementation @@ -120,7 +119,7 @@ void DominatorSet::recalculate() { for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) Doms[I]; } - +namespace llvm { static std::ostream &operator<<(std::ostream &o, const std::set &BBs) { for (std::set::const_iterator I = BBs.begin(), E = BBs.end(); @@ -131,6 +130,7 @@ static std::ostream &operator<<(std::ostream &o, o << " <>"; return o; } +} void DominatorSetBase::print(std::ostream &o) const { for (const_iterator I = begin(), E = end(); I != E; ++I) { @@ -361,4 +361,3 @@ void DominanceFrontierBase::print(std::ostream &o) const { } } -} // End llvm namespace diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index 364cc6f733e..9a4ac6711cc 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -18,8 +18,7 @@ #include "llvm/Intrinsics.h" #include "Support/LeakDetector.h" #include "SymbolTableListTraitsImpl.h" - -namespace llvm { +using namespace llvm; BasicBlock *ilist_traits::createNode() { BasicBlock *Ret = new BasicBlock(); @@ -259,5 +258,3 @@ void GlobalVariable::setName(const std::string &name, SymbolTable *ST) { Value::setName(name); if (P && getName() != "") P->getSymbolTable().insert(this); } - -} // End llvm namespace diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index 6b15929506e..b4b0925926f 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -21,8 +21,7 @@ #include #include #include - -namespace llvm { +using namespace llvm; Function *ilist_traits::createNode() { FunctionType *FTy = @@ -55,11 +54,13 @@ template class SymbolTableListTraits; // Define the GlobalValueRefMap as a struct that wraps a map so that we don't // have Module.h depend on // -struct GlobalValueRefMap { - typedef std::map MapTy; - typedef MapTy::iterator iterator; - std::map Map; -}; +namespace llvm { + struct GlobalValueRefMap { + typedef std::map MapTy; + typedef MapTy::iterator iterator; + std::map Map; + }; +} Module::Module(const std::string &MID) @@ -310,4 +311,3 @@ void Module::mutateConstantPointerRef(GlobalValue *OldGV, GlobalValue *NewGV) { } } -} // End llvm namespace diff --git a/lib/VMCore/ModuleProvider.cpp b/lib/VMCore/ModuleProvider.cpp index 8be033622df..12a4fe6f25d 100644 --- a/lib/VMCore/ModuleProvider.cpp +++ b/lib/VMCore/ModuleProvider.cpp @@ -13,8 +13,7 @@ #include "llvm/ModuleProvider.h" #include "llvm/Module.h" - -namespace llvm { +using namespace llvm; /// ctor - always have a valid Module /// @@ -37,5 +36,3 @@ Module* ModuleProvider::materializeModule() { return TheModule; } - -} // End llvm namespace diff --git a/lib/VMCore/Pass.cpp b/lib/VMCore/Pass.cpp index b387fc35240..40a3b7d17fe 100644 --- a/lib/VMCore/Pass.cpp +++ b/lib/VMCore/Pass.cpp @@ -20,8 +20,7 @@ #include "Support/STLExtras.h" #include "Support/TypeInfo.h" #include - -namespace llvm { +using namespace llvm; // IncludeFile - Stub function used to help linking out. IncludeFile::IncludeFile(void*) {} @@ -469,5 +468,3 @@ void PassRegistrationListener::enumeratePasses() { E = PassInfoMap->end(); I != E; ++I) passEnumerate(I->second); } - -} // End llvm namespace diff --git a/lib/VMCore/SlotCalculator.cpp b/lib/VMCore/SlotCalculator.cpp index c6e44e8266f..f4414a5921d 100644 --- a/lib/VMCore/SlotCalculator.cpp +++ b/lib/VMCore/SlotCalculator.cpp @@ -26,8 +26,7 @@ #include "Support/PostOrderIterator.h" #include "Support/STLExtras.h" #include - -namespace llvm { +using namespace llvm; #if 0 #define SC_DEBUG(X) std::cerr << X @@ -363,5 +362,3 @@ int SlotCalculator::doInsertValue(const Value *D) { SC_DEBUG("]\n"); return (int)DestSlot; } - -} // End llvm namespace diff --git a/lib/VMCore/SymbolTable.cpp b/lib/VMCore/SymbolTable.cpp index f2e5398d411..8c9e86c0030 100644 --- a/lib/VMCore/SymbolTable.cpp +++ b/lib/VMCore/SymbolTable.cpp @@ -16,8 +16,7 @@ #include "llvm/Module.h" #include "Support/StringExtras.h" #include - -namespace llvm { +using namespace llvm; #define DEBUG_SYMBOL_TABLE 0 #define DEBUG_ABSTYPE 0 @@ -363,5 +362,3 @@ void SymbolTable::dump() const { std::cout << "Symbol table dump:\n"; for_each(begin(), end(), DumpPlane); } - -} // End llvm namespace diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp index f389eb0132f..fcf0b7a4c4a 100644 --- a/lib/VMCore/Value.cpp +++ b/lib/VMCore/Value.cpp @@ -17,8 +17,7 @@ #include "llvm/Constant.h" #include "Support/LeakDetector.h" #include - -namespace llvm { +using namespace llvm; //===----------------------------------------------------------------------===// // Value Class @@ -109,5 +108,3 @@ void User::replaceUsesOfWith(Value *From, Value *To) { setOperand(i, To); // Fix it now... } } - -} // End llvm namespace diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index b517dacb440..48384e882c9 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -57,8 +57,7 @@ #include "llvm/Support/InstVisitor.h" #include "Support/STLExtras.h" #include - -namespace llvm { +using namespace llvm; namespace { // Anonymous namespace for class @@ -158,9 +157,11 @@ namespace { // Anonymous namespace for class void WriteValue(const Value *V) { if (!V) return; - if (isa(V)) + if (isa(V)) { std::cerr << *V; - else { + } else if (const Type *Ty = dyn_cast(V)) { + WriteTypeSymbolic(std::cerr, Ty, Mod); + } else { WriteAsOperand (std::cerr, V, true, true, Mod); std::cerr << "\n"; } @@ -184,6 +185,8 @@ namespace { // Anonymous namespace for class }; RegisterOpt X("verify", "Module Verifier"); +} // End anonymous namespace + // Assert - We know that cond should be true, if not print an error message. #define Assert(C, M) \ @@ -569,19 +572,18 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) { "Illegal # arguments for intrinsic function!", IF); } -} // End anonymous namespace //===----------------------------------------------------------------------===// // Implement the public interfaces to this file... //===----------------------------------------------------------------------===// -FunctionPass *createVerifierPass() { +FunctionPass *llvm::createVerifierPass() { return new Verifier(); } // verifyFunction - Create -bool verifyFunction(const Function &f) { +bool llvm::verifyFunction(const Function &f) { Function &F = (Function&)f; assert(!F.isExternal() && "Cannot verify external functions"); @@ -600,12 +602,10 @@ bool verifyFunction(const Function &f) { // verifyModule - Check a module for errors, printing messages on stderr. // Return true if the module is corrupt. // -bool verifyModule(const Module &M) { +bool llvm::verifyModule(const Module &M) { PassManager PM; Verifier *V = new Verifier(); PM.add(V); PM.run((Module&)M); return V->Broken; } - -} // End llvm namespace diff --git a/lib/VMCore/iMemory.cpp b/lib/VMCore/iMemory.cpp index c1a06576cd4..917692e8963 100644 --- a/lib/VMCore/iMemory.cpp +++ b/lib/VMCore/iMemory.cpp @@ -14,7 +14,6 @@ #include "llvm/iMemory.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" - using namespace llvm; AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,