For PR780:
authorReid Spencer <rspencer@reidspencer.com>
Wed, 7 Jun 2006 22:00:26 +0000 (22:00 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Wed, 7 Jun 2006 22:00:26 +0000 (22:00 +0000)
1. Fix the macros in IncludeFile.h to put everything in the llvm namespace
2. Replace the previous explicit mechanism in all the .h and .cpp files
   with the macros in IncludeFile.h
This gets us a consistent mechanism throughout LLVM for ensuring linkage.
Next step is to make sure its used in enough places.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28715 91177308-0d34-0410-b5e6-96231b3b80d8

19 files changed:
include/llvm/Analysis/AliasAnalysis.h
include/llvm/Analysis/CallGraph.h
include/llvm/Analysis/Dominators.h
include/llvm/Analysis/FindUsedTypes.h
include/llvm/Analysis/LoopInfo.h
include/llvm/Analysis/PostDominators.h
include/llvm/Analysis/ValueNumbering.h
include/llvm/IntrinsicInst.h
include/llvm/Support/IncludeFile.h
include/llvm/System/IncludeFile.h
lib/Analysis/AliasAnalysis.cpp
lib/Analysis/BasicAliasAnalysis.cpp
lib/Analysis/IPA/CallGraph.cpp
lib/Analysis/IPA/FindUsedTypes.cpp
lib/Analysis/LoopInfo.cpp
lib/Analysis/PostDominators.cpp
lib/Analysis/ValueNumbering.cpp
lib/VMCore/Dominators.cpp
lib/VMCore/IntrinsicInst.cpp

index d715e0880b65415b0d9b7a9eb6026503cb4cd624..2fff77420aeb5b29f7521ea0ef1b198cc4ff6521 100644 (file)
@@ -318,14 +318,13 @@ public:
   }
 };
 
+} // End llvm namespace
+
 // Because of the way .a files work, we must force the BasicAA implementation to
 // be pulled in if the AliasAnalysis header is included.  Otherwise we run
 // the risk of AliasAnalysis being used, but the default implementation not
 // being linked into the tool that uses it.
-//
-extern int BasicAAStub;
-static IncludeFile HDR_INCLUDE_BASICAA_CPP(&BasicAAStub);
-
-} // End llvm namespace
+FORCE_DEFINING_FILE_TO_BE_LINKED(AliasAnalysis)
+FORCE_DEFINING_FILE_TO_BE_LINKED(BasicAliasAnalysis)
 
 #endif
index e51a3c7fb1811d2c338a4d43816f2ae5decf924f..94cea100485b622dec65602386754a9c38efd51c 100644 (file)
@@ -287,13 +287,9 @@ template<> struct GraphTraits<const CallGraph*> :
   static nodes_iterator nodes_end  (const CallGraph *CG) { return CG->end(); }
 };
 
-// Make sure that any clients of this file link in CallGraph.cpp
-static IncludeFile
-CALLGRAPH_INCLUDE_FILE(&CallGraph::stub);
-
-extern int BasicCallGraphStub;
-static IncludeFile HDR_INCLUDE_CALLGRAPH_CPP(&BasicCallGraphStub);
-
 } // End llvm namespace
 
+// Make sure that any clients of this file link in CallGraph.cpp
+FORCE_DEFINING_FILE_TO_BE_LINKED(CallGraph)
+
 #endif
index 224e529915fa51dded46fd3af3a0334907e23c88..31b8562f2c3bee11a91560e20cab9cdbd05a2574 100644 (file)
@@ -652,9 +652,9 @@ private:
 };
 
 
-// Make sure that any clients of this file link in Dominators.cpp
-static IncludeFile
-DOMINATORS_INCLUDE_FILE(&DominatorSet::stub);
 } // End llvm namespace
 
+// Make sure that any clients of this file link in Dominators.cpp
+FORCE_DEFINING_FILE_TO_BE_LINKED(DominatorSet)
+
 #endif
index e16fe9d7c30199b567c31a5874dc7c35bae26e03..fbf41de7cb6e2e843c6b8c00408d70519e7a8ffb 100644 (file)
@@ -53,15 +53,11 @@ public:
   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
     AU.setPreservesAll();
   }
-
-  // stub - dummy function, just ignore it
-  static int stub;
 };
 
-// Make sure that any clients of this file link in PostDominators.cpp
-static IncludeFile
-FIND_USED_TYPES_INCLUDE_FILE(&FindUsedTypes::stub);
-
 } // End llvm namespace
 
+// Make sure that any clients of this file link in PostDominators.cpp
+FORCE_DEFINING_FILE_TO_BE_LINKED(FindUsedTypes)
+
 #endif
index 065ce31d8bbd688a1324862ae686377754cb6ec4..06b007cf3fcce6fd54e3762f04004a58aee9b579 100644 (file)
@@ -295,7 +295,6 @@ public:
   /// BasicBlocks to loops.
   void removeBlock(BasicBlock *BB);
 
-  static int stub;  // Noop
 private:
   void Calculate(ETForest &EF);
   Loop *ConsiderForLoop(BasicBlock *BB, ETForest &EF);
@@ -304,10 +303,6 @@ private:
 };
 
 
-// Make sure that any clients of this file link in LoopInfo.cpp
-static IncludeFile
-LOOP_INFO_INCLUDE_FILE(&LoopInfo::stub);
-
 // Allow clients to walk the list of nested loops...
 template <> struct GraphTraits<const Loop*> {
   typedef const Loop NodeType;
@@ -337,4 +332,7 @@ template <> struct GraphTraits<Loop*> {
 
 } // End llvm namespace
 
+// Make sure that any clients of this file link in LoopInfo.cpp
+FORCE_DEFINING_FILE_TO_BE_LINKED(LoopInfo)
+
 #endif
index 1436be30375f57e95abcddb3c17d7159b793a109..4d8d140373eabd5790cb039ee0d67d3d66c2a899 100644 (file)
@@ -128,18 +128,14 @@ struct PostDominanceFrontier : public DominanceFrontierBase {
     AU.addRequired<PostDominatorTree>();
   }
 
-  // stub - dummy function, just ignore it
-  static int stub;
-
 private:
   const DomSetType &calculate(const PostDominatorTree &DT,
                               const DominatorTree::Node *Node);
 };
 
-// Make sure that any clients of this file link in PostDominators.cpp
-static IncludeFile
-POST_DOMINATOR_INCLUDE_FILE(&PostDominanceFrontier::stub);
-
 } // End llvm namespace
 
+// Make sure that any clients of this file link in PostDominators.cpp
+FORCE_DEFINING_FILE_TO_BE_LINKED(PostDominanceFrontier)
+
 #endif
index 2fc949766e7a9fbedd23d636ca466bec77417249..f708f48382b9c113db8e1d9b36fbdde4be3b0962 100644 (file)
@@ -65,10 +65,9 @@ struct ValueNumbering {
   }
 };
 
-extern int BasicValueNumberingStub;
-static IncludeFile
-HDR_INCLUDE_VALUENUMBERING_CPP(&BasicValueNumberingStub);
-
 } // End llvm namespace
 
+// Force any file including this header to get the implementation as well
+FORCE_DEFINING_FILE_TO_BE_LINKED(BasicValueNumbering)
+
 #endif
index fbc3968f26474d430f2957acabdb3e866d574107..5b784fc2b90fec7df943e60f71f5a30c3125b476 100644 (file)
@@ -314,11 +314,10 @@ namespace llvm {
     }
   };
 
-// A hack to ensure that the IntrinsicInst.cpp file gets added as a dependency
-// of any file that 
-extern char LinkIntrinsicInstStub;
-static IncludeFile LinkIntrinsicInst(&LinkIntrinsicInstStub);
-
 }
 
+// Ensure that the IntrinsicInst.cpp file gets added as a dependency of any 
+// file that includes this header
+FORCE_DEFINING_FILE_TO_BE_LINKED(IntrinsicInst)
+
 #endif
index 8e96f7571f630495e9fef3f5940875cf721115f0..798c6b454fc9dfe7a49ee5e37c8ebec985966ed8 100644 (file)
 /// And, foo.cp would use:<br/>
 /// <tt>DEFINING_FILE_FOR(foo)</tt><br/>
 #define FORCE_DEFINING_FILE_TO_BE_LINKED(name) \
-  extern char name ## LinkVar; \
-  static IncludeFile name ## LinkObj ( &name ## LinkVar )
+  namespace llvm { \
+    extern char name ## LinkVar; \
+    static IncludeFile name ## LinkObj ( &name ## LinkVar ); \
+  } 
 
 /// This macro is the counterpart to FORCE_DEFINING_FILE_TO_BE_LINKED. It should
 /// be used in a .cpp file to define the name referenced in a header file that
 /// will cause linkage of the .cpp file. It should only be used at extern level.
-#define DEFINING_FILE_FOR(name) char name
+#define DEFINING_FILE_FOR(name) namespace llvm { char name ## LinkVar; }
 
 namespace llvm {
 
index 8e96f7571f630495e9fef3f5940875cf721115f0..798c6b454fc9dfe7a49ee5e37c8ebec985966ed8 100644 (file)
 /// And, foo.cp would use:<br/>
 /// <tt>DEFINING_FILE_FOR(foo)</tt><br/>
 #define FORCE_DEFINING_FILE_TO_BE_LINKED(name) \
-  extern char name ## LinkVar; \
-  static IncludeFile name ## LinkObj ( &name ## LinkVar )
+  namespace llvm { \
+    extern char name ## LinkVar; \
+    static IncludeFile name ## LinkObj ( &name ## LinkVar ); \
+  } 
 
 /// This macro is the counterpart to FORCE_DEFINING_FILE_TO_BE_LINKED. It should
 /// be used in a .cpp file to define the name referenced in a header file that
 /// will cause linkage of the .cpp file. It should only be used at extern level.
-#define DEFINING_FILE_FOR(name) char name
+#define DEFINING_FILE_FOR(name) namespace llvm { char name ## LinkVar; }
 
 namespace llvm {
 
index 2abcbde74e71c67db57b18acd1886bc59620e4bf..1843cd41d43a959b6bd3f856b692819519e95395 100644 (file)
@@ -188,8 +188,4 @@ bool AliasAnalysis::canInstructionRangeModify(const Instruction &I1,
 // be pulled in if the AliasAnalysis classes are pulled in.  Otherwise we run
 // the risk of AliasAnalysis being used, but the default implementation not
 // being linked into the tool that uses it.
-//
-namespace llvm {
-  extern int BasicAAStub;
-}
-static IncludeFile INCLUDE_BASICAA_CPP((void*)&BasicAAStub);
+DEFINING_FILE_FOR(AliasAnalysis)
index 3cda92e49f5755b80142dc8ceb6659ae627e15db..fa4a029648f84684d4a1d4404dd54308afb53feb 100644 (file)
@@ -26,9 +26,6 @@
 #include <algorithm>
 using namespace llvm;
 
-// Make sure that anything that uses AliasAnalysis pulls in this file...
-int llvm::BasicAAStub;
-
 namespace {
   /// NoAA - This class implements the -no-aa pass, which always returns "I
   /// don't know" for alias queries.  NoAA is unlike other alias analysis
@@ -846,3 +843,6 @@ BasicAliasAnalysis::getModRefBehavior(Function *F, CallSite CS,
 
   return UnknownModRefBehavior;
 }
+
+// Make sure that anything that uses AliasAnalysis pulls in this file...
+DEFINING_FILE_FOR(BasicAliasAnalysis)
index f8846d390a59d0749d04428907d32a48a7676413..78bb735ffa23aa84610125ac260ad575fa32803d 100644 (file)
@@ -19,8 +19,6 @@
 #include <iostream>
 using namespace llvm;
 
-int llvm::BasicCallGraphStub;
-
 static bool isOnlyADirectCall(Function *F, CallSite CS) {
   if (!CS.getInstruction()) return false;
   for (CallSite::arg_iterator I = CS.arg_begin(), E = CS.arg_end(); I != E; ++I)
@@ -256,10 +254,6 @@ CallGraphNode *CallGraph::getOrInsertFunction(const Function *F) {
   return CGN = new CallGraphNode(const_cast<Function*>(F));
 }
 
-
-
-int CallGraph::stub; // to ensure linkage of this file.
-
 void CallGraphNode::print(std::ostream &OS) const {
   if (Function *F = getFunction())
     OS << "Call graph node for function: '" << F->getName() <<"'\n";
@@ -297,3 +291,6 @@ void CallGraphNode::removeAnyCallEdgeTo(CallGraphNode *Callee) {
       --i; --e;
     }
 }
+
+// Enuse that users of CallGraph.h also link with this file
+DEFINING_FILE_FOR(CallGraph)
index f7efc7d3a4157efb9a876e6e8cd0b95701444a75..725cec4c01826d9ea26e93cc868d2004e8255497 100644 (file)
@@ -24,9 +24,6 @@ using namespace llvm;
 static RegisterAnalysis<FindUsedTypes>
 X("printusedtypes", "Find Used Types");
 
-// stub to help linkage
-int FindUsedTypes::stub; // to ensure linkage of this file
-
 // IncorporateType - Incorporate one type and all of its subtypes into the
 // collection of used types.
 //
@@ -104,3 +101,6 @@ void FindUsedTypes::print(std::ostream &o, const Module *M) const {
            E = UsedTypes.end(); I != E; ++I)
       o << "  " << **I << "\n";
 }
+
+// Ensure that this file gets linked in when FindUsedTypes.h is used.
+DEFINING_FILE_FOR(FindUsedTypes)
index f2ef17682fc8d0a2e75f96647fe4dbe60b98d638..c7ce58ef915a9634c13110b0f7ef15d4b1de7998 100644 (file)
@@ -86,8 +86,6 @@ void Loop::dump() const {
 //===----------------------------------------------------------------------===//
 // LoopInfo implementation
 //
-int LoopInfo::stub;
-
 bool LoopInfo::runOnFunction(Function &) {
   releaseMemory();
   Calculate(getAnalysis<ETForest>());    // Update
@@ -557,3 +555,6 @@ Loop *Loop::removeChildLoop(iterator I) {
 void Loop::removeBlockFromLoop(BasicBlock *BB) {
   RemoveFromVector(Blocks, BB);
 }
+
+// Ensure this file gets linked when LoopInfo.h is used.
+DEFINING_FILE_FOR(LoopInfo)
index 611ea60a672f943f16fca33a768a6568d340c38c..e195d7a4c77addd41b32ccfc20830332652c34af 100644 (file)
@@ -359,6 +359,5 @@ PostDominanceFrontier::calculate(const PostDominatorTree &DT,
   return S;
 }
 
-// stub - a dummy function to make linking work ok.
-int PostDominanceFrontier::stub;
-
+// Ensure that this .cpp file gets linked when PostDominators.h is used.
+DEFINING_FILE_FOR(PostDominanceFrontier)
index 06482224544c2be37953d02b57e330c894d3c601..c534bba4dcb14548e0ea4ec5dc3cf3a2ff82c8ba 100644 (file)
@@ -239,4 +239,5 @@ void BVNImpl::handleTernaryInst(Instruction &I) {
 }
 
 
-int llvm::BasicValueNumberingStub; // to ensure linkage of this file
+// Ensure that users of ValueNumbering.h will link with this file
+DEFINING_FILE_FOR(BasicValueNumbering)
index a0a6d253b2809e159d8d1e842512b15e74668dba..35c847f7d6df9b477216d7bf1ea082039e830dd2 100644 (file)
@@ -304,8 +304,6 @@ bool DominatorSet::runOnFunction(Function &F) {
   return false;
 }
 
-int DominatorSet::stub;
-
 namespace llvm {
 static std::ostream &operator<<(std::ostream &o,
                                 const std::set<BasicBlock*> &BBs) {
@@ -933,3 +931,5 @@ void ETForestBase::print(std::ostream &o, const Module *) const {
   }
   o << "\n";
 }
+
+DEFINING_FILE_FOR(DominatorSet)
index b4395e1cd32b7e31d986f0417d539f9c37f02ecf..598a99f18fdf708d97a8fece0dc7e184d3896487 100644 (file)
@@ -71,7 +71,5 @@ std::string DbgStopPointInst::getDirectory() const {
 }
 
 //===----------------------------------------------------------------------===//
-/// LinkIntrinsicInstStub -- This is a hack to make sure that programs that
-/// #include IntrinsicInst.h also link this file. See Support/IncludeFile.h
-/// for further details.
-char llvm::LinkIntrinsicInstStub;
+/// Ensure that users of IntrinsicInst.h will link with this module.
+DEFINING_FILE_FOR(IntrinsicInst)