Remove VISIBILITY_HIDDEN from class/struct found inside anonymous namespaces.
[oota-llvm.git] / lib / Transforms / IPO / ExtractGV.cpp
index 03a8e5cebca9173d1833e3b67b35dd7e5f208415..8f5dc0c9b127e22282675233218540865b1051ec 100644 (file)
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Instructions.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Pass.h"
 #include "llvm/Constants.h"
@@ -22,7 +23,7 @@ using namespace llvm;
 
 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;
@@ -35,7 +36,7 @@ namespace {
     ///
     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) {
@@ -43,6 +44,7 @@ namespace {
         return false;  // Nothing to extract
       }
       
+      
       if (deleteStuff)
         return deleteGV();
       M.setModuleInlineAsm("");
@@ -52,7 +54,7 @@ namespace {
     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
@@ -63,7 +65,7 @@ namespace {
                   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);
                }
              }
@@ -85,6 +87,7 @@ namespace {
 
     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);
@@ -98,7 +101,8 @@ namespace {
       // 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);
@@ -106,9 +110,9 @@ namespace {
         }
         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");
       }