//
//===----------------------------------------------------------------------===//
+#define DEBUG_TYPE "internalize"
#include "llvm/Transforms/IPO.h"
#include "llvm/Pass.h"
#include "llvm/Module.h"
#include "llvm/Support/Debug.h"
#include "llvm/ADT/Statistic.h"
#include <fstream>
-#include <iostream>
#include <set>
using namespace llvm;
+STATISTIC(NumFunctions, "Number of functions internalized");
+STATISTIC(NumGlobals , "Number of global vars internalized");
+
namespace {
- Statistic<> NumFunctions("internalize", "Number of functions internalized");
- Statistic<> NumGlobals ("internalize", "Number of global vars internalized");
// APIFile - A file which contains a list of symbols that should not be marked
// external.
bool DontInternalize;
public:
InternalizePass(bool InternalizeEverything = true);
+ InternalizePass(const std::vector <const char *>& exportList);
void LoadFile(const char *Filename);
virtual bool runOnModule(Module &M);
};
- RegisterOpt<InternalizePass> X("internalize", "Internalize Global Symbols");
+ RegisterPass<InternalizePass> X("internalize", "Internalize Global Symbols");
} // end anonymous namespace
InternalizePass::InternalizePass(bool InternalizeEverything)
DontInternalize = true;
}
+InternalizePass::InternalizePass(const std::vector<const char *>&exportList)
+ : DontInternalize(false){
+ for(std::vector<const char *>::const_iterator itr = exportList.begin();
+ itr != exportList.end(); itr++) {
+ ExternalNames.insert(*itr);
+ }
+}
+
void InternalizePass::LoadFile(const char *Filename) {
// Load the APIFile...
std::ifstream In(Filename);
if (!In.good()) {
- std::cerr << "WARNING: Internalize couldn't load file '" << Filename
- << "'!\n";
+ cerr << "WARNING: Internalize couldn't load file '" << Filename << "'!\n";
return; // Do not internalize anything...
}
while (In) {
I->setLinkage(GlobalValue::InternalLinkage);
Changed = true;
++NumFunctions;
- DEBUG(std::cerr << "Internalizing func " << I->getName() << "\n");
+ DOUT << "Internalizing func " << I->getName() << "\n";
}
// Never internalize the llvm.used symbol. It is used to implement
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");
+ // find them. (see MachineDebugInfo.)
+ ExternalNames.insert("llvm.dbg.compile_units");
+ ExternalNames.insert("llvm.dbg.global_variables");
+ ExternalNames.insert("llvm.dbg.subprograms");
// Mark all global variables with initializers as internal as well.
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
I->setLinkage(GlobalValue::InternalLinkage);
Changed = true;
++NumGlobals;
- DEBUG(std::cerr << "Internalized gvar " << I->getName() << "\n");
+ DOUT << "Internalized gvar " << I->getName() << "\n";
}
return Changed;
ModulePass *llvm::createInternalizePass(bool InternalizeEverything) {
return new InternalizePass(InternalizeEverything);
}
+
+ModulePass *llvm::createInternalizePass(const std::vector <const char *> &el) {
+ return new InternalizePass(el);
+}