Pull inline methods out of the pass class definition to make it easier to

read the code.

Do not internalize debugger anchors.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25067 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2006-01-03 19:13:17 +00:00
parent 361dfa62be
commit 4eb40df1a8

View File

@ -43,7 +43,15 @@ namespace {
std::set<std::string> ExternalNames; std::set<std::string> ExternalNames;
bool DontInternalize; bool DontInternalize;
public: public:
InternalizePass(bool InternalizeEverything = true) : DontInternalize(false){ InternalizePass(bool InternalizeEverything = true);
void LoadFile(const char *Filename);
virtual bool runOnModule(Module &M);
};
RegisterOpt<InternalizePass> X("internalize", "Internalize Global Symbols");
} // end anonymous namespace
InternalizePass::InternalizePass(bool InternalizeEverything)
: DontInternalize(false){
if (!APIFile.empty()) // If a filename is specified, use it if (!APIFile.empty()) // If a filename is specified, use it
LoadFile(APIFile.c_str()); LoadFile(APIFile.c_str());
else if (!APIList.empty()) // Else, if a list is specified, use it. else if (!APIList.empty()) // Else, if a list is specified, use it.
@ -51,9 +59,9 @@ namespace {
else if (!InternalizeEverything) else if (!InternalizeEverything)
// Finally, if we're allowed to, internalize all but main. // Finally, if we're allowed to, internalize all but main.
DontInternalize = true; DontInternalize = true;
} }
void LoadFile(const char *Filename) { void InternalizePass::LoadFile(const char *Filename) {
// Load the APIFile... // Load the APIFile...
std::ifstream In(Filename); std::ifstream In(Filename);
if (!In.good()) { if (!In.good()) {
@ -67,9 +75,9 @@ namespace {
if (!Symbol.empty()) if (!Symbol.empty())
ExternalNames.insert(Symbol); ExternalNames.insert(Symbol);
} }
} }
virtual bool runOnModule(Module &M) { bool InternalizePass::runOnModule(Module &M) {
if (DontInternalize) return false; if (DontInternalize) return false;
// If no list or file of symbols was specified, check to see if there is a // If no list or file of symbols was specified, check to see if there is a
@ -98,19 +106,25 @@ namespace {
DEBUG(std::cerr << "Internalizing func " << I->getName() << "\n"); DEBUG(std::cerr << "Internalizing func " << I->getName() << "\n");
} }
// Mark all global variables with initializers as internal as well... // Never internalize the llvm.used symbol. It is used to implement
// attribute((used)).
ExternalNames.insert("llvm.used");
// Never internalize anchors used by the debugger, else the debugger won't
// find them.
ExternalNames.insert("llvm.dbg.translation_units");
ExternalNames.insert("llvm.dbg.globals");
// Mark all global variables with initializers as internal as well.
for (Module::global_iterator I = M.global_begin(), E = M.global_end(); for (Module::global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I) I != E; ++I)
if (!I->isExternal() && !I->hasInternalLinkage() && if (!I->isExternal() && !I->hasInternalLinkage() &&
!ExternalNames.count(I->getName()) && !ExternalNames.count(I->getName())) {
// *never* internalize the llvm.used symbol, used to implement
// attribute((used)).
I->getName() != "llvm.used") {
// Special case handling of the global ctor and dtor list. When we // Special case handling of the global ctor and dtor list. When we
// internalize it, we mark it constant, which allows elimination of // internalize it, we mark it constant, which allows elimination of
// the list if it's empty. // the list if it's empty.
// //
if (I->hasAppendingLinkage() && (I->getName() == "llvm.global_ctors"|| if (I->hasAppendingLinkage() && (I->getName() == "llvm.global_ctors" ||
I->getName() == "llvm.global_dtors")) I->getName() == "llvm.global_dtors"))
I->setConstant(true); I->setConstant(true);
@ -121,11 +135,7 @@ namespace {
} }
return Changed; return Changed;
} }
};
RegisterOpt<InternalizePass> X("internalize", "Internalize Global Symbols");
} // end anonymous namespace
ModulePass *llvm::createInternalizePass(bool InternalizeEverything) { ModulePass *llvm::createInternalizePass(bool InternalizeEverything) {
return new InternalizePass(InternalizeEverything); return new InternalizePass(InternalizeEverything);