当前位置: 首页>>代码示例>>C++>>正文


C++ iterator::hasLocalLinkage方法代码示例

本文整理汇总了C++中module::iterator::hasLocalLinkage方法的典型用法代码示例。如果您正苦于以下问题:C++ iterator::hasLocalLinkage方法的具体用法?C++ iterator::hasLocalLinkage怎么用?C++ iterator::hasLocalLinkage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在module::iterator的用法示例。


在下文中一共展示了iterator::hasLocalLinkage方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: StripSymbolNames

/// StripSymbolNames - Strip symbol names.
static bool StripSymbolNames(Module &M, bool PreserveDbgInfo) {

  SmallPtrSet<const GlobalValue*, 8> llvmUsedValues;
  findUsedValues(M.getGlobalVariable("llvm.used"), llvmUsedValues);
  findUsedValues(M.getGlobalVariable("llvm.compiler.used"), llvmUsedValues);

  for (Module::global_iterator I = M.global_begin(), E = M.global_end();
       I != E; ++I) {
    if (I->hasLocalLinkage() && llvmUsedValues.count(I) == 0)
      if (!PreserveDbgInfo || !I->getName().startswith("llvm.dbg"))
        I->setName("");     // Internal symbols can't participate in linkage
  }
  
  for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
    if (I->hasLocalLinkage() && llvmUsedValues.count(I) == 0)
      if (!PreserveDbgInfo || !I->getName().startswith("llvm.dbg"))
        I->setName("");     // Internal symbols can't participate in linkage
    StripSymtab(I->getValueSymbolTable(), PreserveDbgInfo);
  }
  
  // Remove all names from types.
  StripTypeSymtab(M.getTypeSymbolTable(), PreserveDbgInfo);

  return true;
}
开发者ID:jyasskin,项目名称:llvm-mirror,代码行数:26,代码来源:StripSymbols.cpp

示例2: AnalyzeGlobals

/// AnalyzeGlobals - Scan through the users of all of the internal
/// GlobalValue's in the program.  If none of them have their "address taken"
/// (really, their address passed to something nontrivial), record this fact,
/// and record the functions that they are used directly in.
void GlobalsModRef::AnalyzeGlobals(Module &M) {
  std::vector<Function*> Readers, Writers;
  for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
    if (I->hasLocalLinkage()) {
      if (!AnalyzeUsesOfPointer(I, Readers, Writers)) {
        // Remember that we are tracking this global.
        NonAddressTakenGlobals.insert(I);
        ++NumNonAddrTakenFunctions;
      }
      Readers.clear(); Writers.clear();
    }

  for (Module::global_iterator I = M.global_begin(), E = M.global_end();
       I != E; ++I)
    if (I->hasLocalLinkage()) {
      if (!AnalyzeUsesOfPointer(I, Readers, Writers)) {
        // Remember that we are tracking this global, and the mod/ref fns
        NonAddressTakenGlobals.insert(I);

        for (unsigned i = 0, e = Readers.size(); i != e; ++i)
          FunctionInfo[Readers[i]].GlobalInfo[I] |= Ref;

        if (!I->isConstant())  // No need to keep track of writers to constants
          for (unsigned i = 0, e = Writers.size(); i != e; ++i)
            FunctionInfo[Writers[i]].GlobalInfo[I] |= Mod;
        ++NumNonAddrTakenGlobalVars;

        // If this global holds a pointer type, see if it is an indirect global.
        if (I->getType()->getElementType()->isPointerTy() &&
            AnalyzeIndirectGlobalMemory(I))
          ++NumIndirectGlobalVars;
      }
      Readers.clear(); Writers.clear();
    }
}
开发者ID:AHelper,项目名称:llvm-z80-target,代码行数:39,代码来源:GlobalsModRef.cpp

示例3: runOnModule

bool MergeFunctions::runOnModule(Module &M) {
  bool Changed = false;

  std::map<unsigned long, std::vector<Function *> > FnMap;

  for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
    if (F->isDeclaration() || F->isIntrinsic())
      continue;

    if (!F->hasLocalLinkage() && !F->hasExternalLinkage() &&
        !F->hasWeakLinkage())
      continue;

    if (hasAddressTaken(F))
      continue;

    FnMap[hash(F)].push_back(F);
  }

  // TODO: instead of running in a loop, we could also fold functions in callgraph
  // order. Constructing the CFG probably isn't cheaper than just running in a loop.

  bool LocalChanged;
  do {
    LocalChanged = false;
    for (std::map<unsigned long, std::vector<Function *> >::iterator
         I = FnMap.begin(), E = FnMap.end(); I != E; ++I) {
      DOUT << "size: " << FnMap.size() << "\n";
      std::vector<Function *> &FnVec = I->second;
      DOUT << "hash (" << I->first << "): " << FnVec.size() << "\n";

      for (int i = 0, e = FnVec.size(); i != e; ++i) {
        for (int j = i + 1; j != e; ++j) {
          bool isEqual = equals(FnVec[i], FnVec[j]);

          DOUT << "  " << FnVec[i]->getName()
               << (isEqual ? " == " : " != ")
               << FnVec[j]->getName() << "\n";

          if (isEqual) {
            if (fold(FnVec, i, j)) {
              LocalChanged = true;
              FnVec.erase(FnVec.begin() + j);
              --j, --e;
            }
          }
        }
      }

    }
    Changed |= LocalChanged;
  } while (LocalChanged);

  return Changed;
}
开发者ID:aosm,项目名称:clang,代码行数:55,代码来源:MergeFunctions.cpp

示例4: if

/// GetAllUndefinedSymbols - calculates the set of undefined symbols that still
/// exist in an LLVM module. This is a bit tricky because there may be two
/// symbols with the same name but different LLVM types that will be resolved to
/// each other but aren't currently (thus we need to treat it as resolved).
///
/// Inputs:
///  M - The module in which to find undefined symbols.
///
/// Outputs:
///  UndefinedSymbols - A set of C++ strings containing the name of all
///                     undefined symbols.
///
static void
GetAllUndefinedSymbols(Module *M, std::set<std::string> &UndefinedSymbols) {
  std::set<std::string> DefinedSymbols;
  UndefinedSymbols.clear();

  // If the program doesn't define a main, try pulling one in from a .a file.
  // This is needed for programs where the main function is defined in an
  // archive, such f2c'd programs.
  Function *Main = M->getFunction("main");
  if (Main == 0 || Main->isDeclaration())
    UndefinedSymbols.insert("main");

  for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
    if (I->hasName()) {
      if (I->isDeclaration())
        UndefinedSymbols.insert(I->getName());
      else if (!I->hasLocalLinkage()) {
        assert(!I->hasDLLImportLinkage()
               && "Found dllimported non-external symbol!");
        DefinedSymbols.insert(I->getName());
      }      
    }

  for (Module::global_iterator I = M->global_begin(), E = M->global_end();
       I != E; ++I)
    if (I->hasName()) {
      if (I->isDeclaration())
        UndefinedSymbols.insert(I->getName());
      else if (!I->hasLocalLinkage()) {
        assert(!I->hasDLLImportLinkage()
               && "Found dllimported non-external symbol!");
        DefinedSymbols.insert(I->getName());
      }      
    }

  for (Module::alias_iterator I = M->alias_begin(), E = M->alias_end();
       I != E; ++I)
    if (I->hasName())
      DefinedSymbols.insert(I->getName());

  // Prune out any defined symbols from the undefined symbols set...
  for (std::set<std::string>::iterator I = UndefinedSymbols.begin();
       I != UndefinedSymbols.end(); )
    if (DefinedSymbols.count(*I))
      UndefinedSymbols.erase(I++);  // This symbol really is defined!
    else
      ++I; // Keep this symbol in the undefined symbols list
}
开发者ID:Killfrra,项目名称:llvm-kernel,代码行数:60,代码来源:LinkArchives.cpp

示例5: if

void
AndroidBitcodeLinker::GetAllSymbols(Module *M,
  std::set<std::string> &UndefinedSymbols,
  std::set<std::string> &DefinedSymbols) {

  UndefinedSymbols.clear();
  DefinedSymbols.clear();

  Function *Main = M->getFunction("main");
  if (Main == 0 || Main->isDeclaration())
    UndefinedSymbols.insert("main");

  for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
    if (I->hasName()) {
      if (I->isDeclaration())
        UndefinedSymbols.insert(I->getName());
      else if (!I->hasLocalLinkage()) {
        assert(!I->hasDLLImportStorageClass()
               && "Found dllimported non-external symbol!");
        DefinedSymbols.insert(I->getName());
      }
    }

  for (Module::global_iterator I = M->global_begin(), E = M->global_end();
       I != E; ++I)
    if (I->hasName()) {
      if (I->isDeclaration())
        UndefinedSymbols.insert(I->getName());
      else if (!I->hasLocalLinkage()) {
        assert(!I->hasDLLImportStorageClass()
               && "Found dllimported non-external symbol!");
        DefinedSymbols.insert(I->getName());
      }
    }

  for (Module::alias_iterator I = M->alias_begin(), E = M->alias_end();
       I != E; ++I)
    if (I->hasName())
      DefinedSymbols.insert(I->getName());

  for (std::set<std::string>::iterator I = UndefinedSymbols.begin();
       I != UndefinedSymbols.end(); )
    if (DefinedSymbols.count(*I))
      UndefinedSymbols.erase(I++);
    else
      ++I;
}
开发者ID:crystax,项目名称:android-toolchain-llvm-3-7,代码行数:47,代码来源:AndroidBitcodeLinker.cpp

示例6: getSymbols

static void getSymbols(Module*M, std::vector<std::string>& symbols) {
    // Loop over global variables
    for (Module::global_iterator GI = M->global_begin(), GE=M->global_end(); GI != GE; ++GI)
        if (!GI->isDeclaration() && !GI->hasLocalLinkage())
            if (!GI->getName().empty())
                symbols.push_back(GI->getName());

    // Loop over functions
    for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI)
        if (!FI->isDeclaration() && !FI->hasLocalLinkage())
            if (!FI->getName().empty())
                symbols.push_back(FI->getName());

    // Loop over aliases
    for (Module::alias_iterator AI = M->alias_begin(), AE = M->alias_end();
            AI != AE; ++AI) {
        if (AI->hasName())
            symbols.push_back(AI->getName());
    }
}
开发者ID:crystax,项目名称:android-toolchain-llvm-3-7,代码行数:20,代码来源:Archive.cpp

示例7: runOnModule

bool IPCP::runOnModule(Module &M) {
    bool Changed = false;
    bool LocalChange = true;

    // FIXME: instead of using smart algorithms, we just iterate until we stop
    // making changes.
    while (LocalChange) {
        LocalChange = false;
        for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
            if (!I->isDeclaration()) {
                // Delete any klingons.
                I->removeDeadConstantUsers();
                if (I->hasLocalLinkage())
                    LocalChange |= PropagateConstantsIntoArguments(*I);
                Changed |= PropagateConstantReturn(*I);
            }
        Changed |= LocalChange;
    }
    return Changed;
}
开发者ID:,项目名称:,代码行数:20,代码来源:

示例8: runOnModule

bool InternalizePass::runOnModule(Module &M) {
  CallGraph *CG = getAnalysisIfAvailable<CallGraph>();
  CallGraphNode *ExternalNode = CG ? CG->getExternalCallingNode() : 0;
  
  if (ExternalNames.empty()) {
    // Return if we're not in 'all but main' mode and have no external api
    if (!AllButMain)
      return false;
    // If no list or file of symbols was specified, check to see if there is a
    // "main" symbol defined in the module.  If so, use it, otherwise do not
    // internalize the module, it must be a library or something.
    //
    Function *MainFunc = M.getFunction("main");
    if (MainFunc == 0 || MainFunc->isDeclaration())
      return false;  // No main found, must be a library...

    // Preserve main, internalize all else.
    ExternalNames.insert(MainFunc->getName());
  }

  bool Changed = false;

  // Never internalize functions which code-gen might insert.
  ExternalNames.insert("__stack_chk_fail");

  // Mark all functions not in the api as internal.
  // FIXME: maybe use private linkage?
  for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
    if (!I->isDeclaration() &&         // Function must be defined here
        // Available externally is really just a "declaration with a body".
        !I->hasAvailableExternallyLinkage() &&
        !I->hasLocalLinkage() &&  // Can't already have internal linkage
        !ExternalNames.count(I->getName())) {// Not marked to keep external?
      I->setLinkage(GlobalValue::InternalLinkage);
      // Remove a callgraph edge from the external node to this function.
      if (ExternalNode) ExternalNode->removeOneAbstractEdgeTo((*CG)[I]);
      Changed = true;
      ++NumFunctions;
      DEBUG(dbgs() << "Internalizing func " << I->getName() << "\n");
    }

  // Never internalize the llvm.used symbol.  It is used to implement
  // attribute((used)).
  // FIXME: Shouldn't this just filter on llvm.metadata section??
  ExternalNames.insert("llvm.used");
  ExternalNames.insert("llvm.compiler.used");

  // Never internalize anchors used by the machine module info, else the info
  // won't find them.  (see MachineModuleInfo.)
  ExternalNames.insert("llvm.global_ctors");
  ExternalNames.insert("llvm.global_dtors");
  ExternalNames.insert("llvm.global.annotations");

  // Never internalize symbols code-gen inserts.
  ExternalNames.insert("__stack_chk_guard");

  // Mark all global variables with initializers that are not in the api as
  // internal as well.
  // FIXME: maybe use private linkage?
  for (Module::global_iterator I = M.global_begin(), E = M.global_end();
       I != E; ++I)
    if (!I->isDeclaration() && !I->hasLocalLinkage() &&
        // Available externally is really just a "declaration with a body".
        !I->hasAvailableExternallyLinkage() &&
        !ExternalNames.count(I->getName())) {
      I->setLinkage(GlobalValue::InternalLinkage);
      Changed = true;
      ++NumGlobals;
      DEBUG(dbgs() << "Internalized gvar " << I->getName() << "\n");
    }

  // Mark all aliases that are not in the api as internal as well.
  for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end();
       I != E; ++I)
    if (!I->isDeclaration() && !I->hasInternalLinkage() &&
        // Available externally is really just a "declaration with a body".
        !I->hasAvailableExternallyLinkage() &&
        !ExternalNames.count(I->getName())) {
      I->setLinkage(GlobalValue::InternalLinkage);
      Changed = true;
      ++NumAliases;
      DEBUG(dbgs() << "Internalized alias " << I->getName() << "\n");
    }

  return Changed;
}
开发者ID:bluemutedwisdom,项目名称:bhyve,代码行数:86,代码来源:Internalize.cpp

示例9: if

/// Based on GetAllUndefinedSymbols() from LLVM3.2
///
/// GetAllUndefinedSymbols - calculates the set of undefined symbols that still
/// exist in an LLVM module. This is a bit tricky because there may be two
/// symbols with the same name but different LLVM types that will be resolved to
/// each other but aren't currently (thus we need to treat it as resolved).
///
/// Inputs:
///  M - The module in which to find undefined symbols.
///
/// Outputs:
///  UndefinedSymbols - A set of C++ strings containing the name of all
///                     undefined symbols.
///
static void
GetAllUndefinedSymbols(Module *M, std::set<std::string> &UndefinedSymbols) {
    static const std::string llvmIntrinsicPrefix="llvm.";
    std::set<std::string> DefinedSymbols;
    UndefinedSymbols.clear();
    KLEE_DEBUG_WITH_TYPE("klee_linker",
                         dbgs() << "*** Computing undefined symbols ***\n");

    for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
        if (I->hasName()) {
            if (I->isDeclaration())
                UndefinedSymbols.insert(I->getName());
            else if (!I->hasLocalLinkage()) {
#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5)
                assert(!I->hasDLLImportLinkage() && "Found dllimported non-external symbol!");
#else
                assert(!I->hasDLLImportStorageClass() && "Found dllimported non-external symbol!");
#endif
                DefinedSymbols.insert(I->getName());
            }
        }

    for (Module::global_iterator I = M->global_begin(), E = M->global_end();
            I != E; ++I)
        if (I->hasName()) {
            if (I->isDeclaration())
                UndefinedSymbols.insert(I->getName());
            else if (!I->hasLocalLinkage()) {
#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5)
                assert(!I->hasDLLImportLinkage() && "Found dllimported non-external symbol!");
#else
                assert(!I->hasDLLImportStorageClass() && "Found dllimported non-external symbol!");
#endif
                DefinedSymbols.insert(I->getName());
            }
        }

    for (Module::alias_iterator I = M->alias_begin(), E = M->alias_end();
            I != E; ++I)
        if (I->hasName())
            DefinedSymbols.insert(I->getName());


    // Prune out any defined symbols from the undefined symbols set
    // and other symbols we don't want to treat as an undefined symbol
    std::vector<std::string> SymbolsToRemove;
    for (std::set<std::string>::iterator I = UndefinedSymbols.begin();
            I != UndefinedSymbols.end(); ++I )
    {
        if (DefinedSymbols.count(*I))
        {
            SymbolsToRemove.push_back(*I);
            continue;
        }

        // Strip out llvm intrinsics
        if ( (I->size() >= llvmIntrinsicPrefix.size() ) &&
                (I->compare(0, llvmIntrinsicPrefix.size(), llvmIntrinsicPrefix) == 0) )
        {
            KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() << "LLVM intrinsic " << *I <<
                                 " has will be removed from undefined symbols"<< "\n");
            SymbolsToRemove.push_back(*I);
            continue;
        }

        // Symbol really is undefined
        KLEE_DEBUG_WITH_TYPE("klee_linker",
                             dbgs() << "Symbol " << *I << " is undefined.\n");
    }

    // Remove KLEE intrinsics from set of undefined symbols
    for (SpecialFunctionHandler::const_iterator sf = SpecialFunctionHandler::begin(),
            se = SpecialFunctionHandler::end(); sf != se; ++sf)
    {
        if (UndefinedSymbols.find(sf->name) == UndefinedSymbols.end())
            continue;

        SymbolsToRemove.push_back(sf->name);
        KLEE_DEBUG_WITH_TYPE("klee_linker",
                             dbgs() << "KLEE intrinsic " << sf->name <<
                             " has will be removed from undefined symbols"<< "\n");
    }

    // Now remove the symbols from undefined set.
    for (size_t i = 0, j = SymbolsToRemove.size(); i < j; ++i )
        UndefinedSymbols.erase(SymbolsToRemove[i]);
//.........这里部分代码省略.........
开发者ID:tracer-x,项目名称:klee,代码行数:101,代码来源:ModuleUtil.cpp


注:本文中的module::iterator::hasLocalLinkage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。