For PR780:

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.

llvm-svn: 28715
This commit is contained in:
Reid Spencer 2006-06-07 22:00:26 +00:00
parent d4b795902c
commit be535661cc
19 changed files with 57 additions and 78 deletions

View File

@ -318,14 +318,13 @@ public:
} }
}; };
} // End llvm namespace
// Because of the way .a files work, we must force the BasicAA implementation to // 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 // be pulled in if the AliasAnalysis header is included. Otherwise we run
// the risk of AliasAnalysis being used, but the default implementation not // the risk of AliasAnalysis being used, but the default implementation not
// being linked into the tool that uses it. // being linked into the tool that uses it.
// FORCE_DEFINING_FILE_TO_BE_LINKED(AliasAnalysis)
extern int BasicAAStub; FORCE_DEFINING_FILE_TO_BE_LINKED(BasicAliasAnalysis)
static IncludeFile HDR_INCLUDE_BASICAA_CPP(&BasicAAStub);
} // End llvm namespace
#endif #endif

View File

@ -287,13 +287,9 @@ template<> struct GraphTraits<const CallGraph*> :
static nodes_iterator nodes_end (const CallGraph *CG) { return CG->end(); } 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 } // End llvm namespace
// Make sure that any clients of this file link in CallGraph.cpp
FORCE_DEFINING_FILE_TO_BE_LINKED(CallGraph)
#endif #endif

View 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 } // End llvm namespace
// Make sure that any clients of this file link in Dominators.cpp
FORCE_DEFINING_FILE_TO_BE_LINKED(DominatorSet)
#endif #endif

View File

@ -53,15 +53,11 @@ public:
virtual void getAnalysisUsage(AnalysisUsage &AU) const { virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll(); 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 } // End llvm namespace
// Make sure that any clients of this file link in PostDominators.cpp
FORCE_DEFINING_FILE_TO_BE_LINKED(FindUsedTypes)
#endif #endif

View File

@ -295,7 +295,6 @@ public:
/// BasicBlocks to loops. /// BasicBlocks to loops.
void removeBlock(BasicBlock *BB); void removeBlock(BasicBlock *BB);
static int stub; // Noop
private: private:
void Calculate(ETForest &EF); void Calculate(ETForest &EF);
Loop *ConsiderForLoop(BasicBlock *BB, 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... // Allow clients to walk the list of nested loops...
template <> struct GraphTraits<const Loop*> { template <> struct GraphTraits<const Loop*> {
typedef const Loop NodeType; typedef const Loop NodeType;
@ -337,4 +332,7 @@ template <> struct GraphTraits<Loop*> {
} // End llvm namespace } // End llvm namespace
// Make sure that any clients of this file link in LoopInfo.cpp
FORCE_DEFINING_FILE_TO_BE_LINKED(LoopInfo)
#endif #endif

View File

@ -128,18 +128,14 @@ struct PostDominanceFrontier : public DominanceFrontierBase {
AU.addRequired<PostDominatorTree>(); AU.addRequired<PostDominatorTree>();
} }
// stub - dummy function, just ignore it
static int stub;
private: private:
const DomSetType &calculate(const PostDominatorTree &DT, const DomSetType &calculate(const PostDominatorTree &DT,
const DominatorTree::Node *Node); 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 } // End llvm namespace
// Make sure that any clients of this file link in PostDominators.cpp
FORCE_DEFINING_FILE_TO_BE_LINKED(PostDominanceFrontier)
#endif #endif

View File

@ -65,10 +65,9 @@ struct ValueNumbering {
} }
}; };
extern int BasicValueNumberingStub;
static IncludeFile
HDR_INCLUDE_VALUENUMBERING_CPP(&BasicValueNumberingStub);
} // End llvm namespace } // End llvm namespace
// Force any file including this header to get the implementation as well
FORCE_DEFINING_FILE_TO_BE_LINKED(BasicValueNumbering)
#endif #endif

View 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 #endif

View File

@ -27,13 +27,15 @@
/// And, foo.cp would use:<br/> /// And, foo.cp would use:<br/>
/// <tt>DEFINING_FILE_FOR(foo)</tt><br/> /// <tt>DEFINING_FILE_FOR(foo)</tt><br/>
#define FORCE_DEFINING_FILE_TO_BE_LINKED(name) \ #define FORCE_DEFINING_FILE_TO_BE_LINKED(name) \
extern char name ## LinkVar; \ namespace llvm { \
static IncludeFile name ## LinkObj ( &name ## LinkVar ) extern char name ## LinkVar; \
static IncludeFile name ## LinkObj ( &name ## LinkVar ); \
}
/// This macro is the counterpart to FORCE_DEFINING_FILE_TO_BE_LINKED. It should /// 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 /// 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. /// 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 { namespace llvm {

View File

@ -27,13 +27,15 @@
/// And, foo.cp would use:<br/> /// And, foo.cp would use:<br/>
/// <tt>DEFINING_FILE_FOR(foo)</tt><br/> /// <tt>DEFINING_FILE_FOR(foo)</tt><br/>
#define FORCE_DEFINING_FILE_TO_BE_LINKED(name) \ #define FORCE_DEFINING_FILE_TO_BE_LINKED(name) \
extern char name ## LinkVar; \ namespace llvm { \
static IncludeFile name ## LinkObj ( &name ## LinkVar ) extern char name ## LinkVar; \
static IncludeFile name ## LinkObj ( &name ## LinkVar ); \
}
/// This macro is the counterpart to FORCE_DEFINING_FILE_TO_BE_LINKED. It should /// 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 /// 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. /// 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 { namespace llvm {

View File

@ -188,8 +188,4 @@ bool AliasAnalysis::canInstructionRangeModify(const Instruction &I1,
// be pulled in if the AliasAnalysis classes are pulled in. Otherwise we run // be pulled in if the AliasAnalysis classes are pulled in. Otherwise we run
// the risk of AliasAnalysis being used, but the default implementation not // the risk of AliasAnalysis being used, but the default implementation not
// being linked into the tool that uses it. // being linked into the tool that uses it.
// DEFINING_FILE_FOR(AliasAnalysis)
namespace llvm {
extern int BasicAAStub;
}
static IncludeFile INCLUDE_BASICAA_CPP((void*)&BasicAAStub);

View File

@ -26,9 +26,6 @@
#include <algorithm> #include <algorithm>
using namespace llvm; using namespace llvm;
// Make sure that anything that uses AliasAnalysis pulls in this file...
int llvm::BasicAAStub;
namespace { namespace {
/// NoAA - This class implements the -no-aa pass, which always returns "I /// NoAA - This class implements the -no-aa pass, which always returns "I
/// don't know" for alias queries. NoAA is unlike other alias analysis /// don't know" for alias queries. NoAA is unlike other alias analysis
@ -846,3 +843,6 @@ BasicAliasAnalysis::getModRefBehavior(Function *F, CallSite CS,
return UnknownModRefBehavior; return UnknownModRefBehavior;
} }
// Make sure that anything that uses AliasAnalysis pulls in this file...
DEFINING_FILE_FOR(BasicAliasAnalysis)

View File

@ -19,8 +19,6 @@
#include <iostream> #include <iostream>
using namespace llvm; using namespace llvm;
int llvm::BasicCallGraphStub;
static bool isOnlyADirectCall(Function *F, CallSite CS) { static bool isOnlyADirectCall(Function *F, CallSite CS) {
if (!CS.getInstruction()) return false; if (!CS.getInstruction()) return false;
for (CallSite::arg_iterator I = CS.arg_begin(), E = CS.arg_end(); I != E; ++I) 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)); return CGN = new CallGraphNode(const_cast<Function*>(F));
} }
int CallGraph::stub; // to ensure linkage of this file.
void CallGraphNode::print(std::ostream &OS) const { void CallGraphNode::print(std::ostream &OS) const {
if (Function *F = getFunction()) if (Function *F = getFunction())
OS << "Call graph node for function: '" << F->getName() <<"'\n"; OS << "Call graph node for function: '" << F->getName() <<"'\n";
@ -297,3 +291,6 @@ void CallGraphNode::removeAnyCallEdgeTo(CallGraphNode *Callee) {
--i; --e; --i; --e;
} }
} }
// Enuse that users of CallGraph.h also link with this file
DEFINING_FILE_FOR(CallGraph)

View File

@ -24,9 +24,6 @@ using namespace llvm;
static RegisterAnalysis<FindUsedTypes> static RegisterAnalysis<FindUsedTypes>
X("printusedtypes", "Find Used Types"); 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 // IncorporateType - Incorporate one type and all of its subtypes into the
// collection of used types. // collection of used types.
// //
@ -104,3 +101,6 @@ void FindUsedTypes::print(std::ostream &o, const Module *M) const {
E = UsedTypes.end(); I != E; ++I) E = UsedTypes.end(); I != E; ++I)
o << " " << **I << "\n"; o << " " << **I << "\n";
} }
// Ensure that this file gets linked in when FindUsedTypes.h is used.
DEFINING_FILE_FOR(FindUsedTypes)

View File

@ -86,8 +86,6 @@ void Loop::dump() const {
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// LoopInfo implementation // LoopInfo implementation
// //
int LoopInfo::stub;
bool LoopInfo::runOnFunction(Function &) { bool LoopInfo::runOnFunction(Function &) {
releaseMemory(); releaseMemory();
Calculate(getAnalysis<ETForest>()); // Update Calculate(getAnalysis<ETForest>()); // Update
@ -557,3 +555,6 @@ Loop *Loop::removeChildLoop(iterator I) {
void Loop::removeBlockFromLoop(BasicBlock *BB) { void Loop::removeBlockFromLoop(BasicBlock *BB) {
RemoveFromVector(Blocks, BB); RemoveFromVector(Blocks, BB);
} }
// Ensure this file gets linked when LoopInfo.h is used.
DEFINING_FILE_FOR(LoopInfo)

View File

@ -359,6 +359,5 @@ PostDominanceFrontier::calculate(const PostDominatorTree &DT,
return S; return S;
} }
// stub - a dummy function to make linking work ok. // Ensure that this .cpp file gets linked when PostDominators.h is used.
int PostDominanceFrontier::stub; DEFINING_FILE_FOR(PostDominanceFrontier)

View 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)

View File

@ -304,8 +304,6 @@ bool DominatorSet::runOnFunction(Function &F) {
return false; return false;
} }
int DominatorSet::stub;
namespace llvm { namespace llvm {
static std::ostream &operator<<(std::ostream &o, static std::ostream &operator<<(std::ostream &o,
const std::set<BasicBlock*> &BBs) { const std::set<BasicBlock*> &BBs) {
@ -933,3 +931,5 @@ void ETForestBase::print(std::ostream &o, const Module *) const {
} }
o << "\n"; o << "\n";
} }
DEFINING_FILE_FOR(DominatorSet)

View File

@ -71,7 +71,5 @@ std::string DbgStopPointInst::getDirectory() const {
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// LinkIntrinsicInstStub -- This is a hack to make sure that programs that /// Ensure that users of IntrinsicInst.h will link with this module.
/// #include IntrinsicInst.h also link this file. See Support/IncludeFile.h DEFINING_FILE_FOR(IntrinsicInst)
/// for further details.
char llvm::LinkIntrinsicInstStub;