//===----------------------------------------------------------------------===//
#include "llvm/Instructions.h"
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Pass.h"
#include "llvm/Constants.h"
namespace {
/// @brief A pass to extract specific functions and their dependencies.
- class VISIBILITY_HIDDEN GVExtractorPass : public ModulePass {
+ class GVExtractorPass : public ModulePass {
std::vector<GlobalValue*> Named;
bool deleteStuff;
bool reLink;
///
explicit GVExtractorPass(std::vector<GlobalValue*>& GVs, bool deleteS = true,
bool relinkCallees = false)
- : ModulePass((intptr_t)&ID), Named(GVs), deleteStuff(deleteS),
+ : ModulePass(&ID), Named(GVs), deleteStuff(deleteS),
reLink(relinkCallees) {}
bool runOnModule(Module &M) {
return false; // Nothing to extract
}
+
if (deleteStuff)
return deleteGV();
M.setModuleInlineAsm("");
bool deleteGV() {
for (std::vector<GlobalValue*>::iterator GI = Named.begin(),
GE = Named.end(); GI != GE; ++GI) {
- if (Function* NamedFunc = dyn_cast<Function>(&*GI)) {
+ if (Function* NamedFunc = dyn_cast<Function>(*GI)) {
// If we're in relinking mode, set linkage of all internal callees to
// external. This will allow us extract function, and then - link
// everything together
I != E; ++I) {
if (CallInst* callInst = dyn_cast<CallInst>(&*I)) {
Function* Callee = callInst->getCalledFunction();
- if (Callee && Callee->hasInternalLinkage())
+ if (Callee && Callee->hasLocalLinkage())
Callee->setLinkage(GlobalValue::ExternalLinkage);
}
}
bool isolateGV(Module &M) {
// Mark all globals internal
+ // FIXME: what should we do with private linkage?
for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
if (!I->isDeclaration()) {
I->setLinkage(GlobalValue::InternalLinkage);
// by putting them in the used array
{
std::vector<Constant *> AUGs;
- const Type *SBP= PointerType::getUnqual(Type::Int8Ty);
+ const Type *SBP=
+ Type::getInt8PtrTy(M.getContext());
for (std::vector<GlobalValue*>::iterator GI = Named.begin(),
GE = Named.end(); GI != GE; ++GI) {
(*GI)->setLinkage(GlobalValue::ExternalLinkage);
}
ArrayType *AT = ArrayType::get(SBP, AUGs.size());
Constant *Init = ConstantArray::get(AT, AUGs);
- GlobalValue *gv = new GlobalVariable(AT, false,
+ GlobalValue *gv = new GlobalVariable(M, AT, false,
GlobalValue::AppendingLinkage,
- Init, "llvm.used", &M);
+ Init, "llvm.used");
gv->setSection("llvm.metadata");
}