//
//===----------------------------------------------------------------------===//
+#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.
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) {
+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);
// 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
I->setLinkage(GlobalValue::InternalLinkage);
Changed = true;
++NumGlobals;
- DEBUG(std::cerr << "Internalized gvar " << I->getName() << "\n");
+ DOUT << "Internalized gvar " << I->getName() << "\n";
}
return Changed;