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


C++ global_iterator::use_empty方法代码示例

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


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

示例1: OptimizeGlobals

/// OptimizeGlobals - This method uses information taken from DSA to optimize
/// global variables.
///
bool DSOpt::OptimizeGlobals(Module &M) {
  DSGraph* GG = TD->getGlobalsGraph();
  const DSGraph::ScalarMapTy &SM = GG->getScalarMap();
  bool Changed = false;

  for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
    if (!I->isDeclaration()) { // Loop over all of the non-external globals...
      // Look up the node corresponding to this global, if it exists.
      DSNode *GNode = 0;
      DSGraph::ScalarMapTy::const_iterator SMI = SM.find(I);
      if (SMI != SM.end()) GNode = SMI->second.getNode();

      if (GNode == 0 && I->hasInternalLinkage()) {
        // If there is no entry in the scalar map for this global, it was never
        // referenced in the program.  If it has internal linkage, that means we
        // can delete it.  We don't ACTUALLY want to delete the global, just
        // remove anything that references the global: later passes will take
        // care of nuking it.
        if (!I->use_empty()) {
          I->replaceAllUsesWith(ConstantPointerNull::get(I->getType()));
          ++NumGlobalsIsolated;
        }
      } else if (GNode && GNode->NodeType.isCompleteNode()) {

        // If the node has not been read or written, and it is not externally
        // visible, kill any references to it so it can be DCE'd.
        if (!GNode->NodeType.isModifiedNode() && !GNode->NodeType.isReadNode() &&I->hasInternalLinkage()){
          if (!I->use_empty()) {
            I->replaceAllUsesWith(ConstantPointerNull::get(I->getType()));
            ++NumGlobalsIsolated;
          }
        }

        // We expect that there will almost always be a node for this global.
        // If there is, and the node doesn't have the M bit set, we can set the
        // 'constant' bit on the global.
        if (!GNode->NodeType.isModifiedNode() && !I->isConstant()) {
          I->setConstant(true);
          ++NumGlobalsConstanted;
          Changed = true;
        }
      }
    }
  return Changed;
}
开发者ID:C0deZLee,项目名称:IntFlow,代码行数:48,代码来源:DataStructureOpt.cpp

示例2: runOnModule

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

  for (Module::iterator I = M.begin(); I != M.end(); ) {
    if (I->hasAvailableExternallyLinkage()) {
      assert(!I->isDeclaration()&&"Declarations can't be available_externally");
      Changed = true;
      ++NumFunctions;
      if (I->use_empty()) {
        DEBUG(errs() << "Deleting function: " << *I);
        Module::iterator todelete = I;
        ++I;
        todelete->eraseFromParent();
        continue;
      } else {
        I->deleteBody();
        DEBUG(errs() << "Deleted function body: " << *I);
      }
    }
    ++I;
  }

  for (Module::global_iterator I = M.global_begin();
       I != M.global_end(); ) {
    if (I->hasAvailableExternallyLinkage()) {
      assert(!I->isDeclaration()&&"Declarations can't be available_externally");
      Changed = true;
      ++NumVariables;
      if (I->use_empty()) {
        DEBUG(errs() << "Deleting global: " << *I);
        Module::global_iterator todelete = I;
        ++I;
        todelete->eraseFromParent();
        continue;
      } else {
        I->setInitializer(0);
        I->setLinkage(GlobalValue::ExternalLinkage);
        DEBUG(errs() << "Deleted initializer: " << *I);
      }
    }
    ++I;
  }

  return Changed;
}
开发者ID:NilsBossung,项目名称:ldc,代码行数:45,代码来源:StripExternals.cpp


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