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


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

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


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

示例1: ReduceGlobalInitializers

static Error ReduceGlobalInitializers(BugDriver &BD,
                                      bool (*TestFn)(const BugDriver &,
                                                     Module *)) {
  if (BD.getProgram()->global_begin() != BD.getProgram()->global_end()) {
    // Now try to reduce the number of global variable initializers in the
    // module to something small.
    Module *M = CloneModule(BD.getProgram()).release();
    bool DeletedInit = false;

    for (Module::global_iterator I = M->global_begin(), E = M->global_end();
         I != E; ++I)
      if (I->hasInitializer()) {
        DeleteGlobalInitializer(&*I);
        I->setLinkage(GlobalValue::ExternalLinkage);
        I->setComdat(nullptr);
        DeletedInit = true;
      }

    if (!DeletedInit) {
      delete M; // No change made...
    } else {
      // See if the program still causes a crash...
      outs() << "\nChecking to see if we can delete global inits: ";

      if (TestFn(BD, M)) { // Still crashes?
        BD.setNewProgram(M);
        outs() << "\n*** Able to remove all global initializers!\n";
      } else { // No longer crashes?
        outs() << "  - Removing all global inits hides problem!\n";
        delete M;

        std::vector<GlobalVariable *> GVs;

        for (Module::global_iterator I = BD.getProgram()->global_begin(),
                                     E = BD.getProgram()->global_end();
             I != E; ++I)
          if (I->hasInitializer())
            GVs.push_back(&*I);

        if (GVs.size() > 1 && !BugpointIsInterrupted) {
          outs() << "\n*** Attempting to reduce the number of global "
                 << "variables in the testcase\n";

          unsigned OldSize = GVs.size();
          Expected<bool> Result =
              ReduceCrashingGlobalVariables(BD, TestFn).reduceList(GVs);
          if (Error E = Result.takeError())
            return E;

          if (GVs.size() < OldSize)
            BD.EmitProgressBitcode(BD.getProgram(), "reduced-global-variables");
        }
      }
    }
  }
  return Error::success();
}
开发者ID:AstroVPK,项目名称:LLVM-4.0.0,代码行数:57,代码来源:CrashDebugger.cpp

示例2: DebugACrash

/// DebugACrash - Given a predicate that determines whether a component crashes
/// on a program, try to destructively reduce the program while still keeping
/// the predicate true.
static bool DebugACrash(BugDriver &BD,
                        bool (*TestFn)(const BugDriver &, Module *),
                        std::string &Error) {
    // See if we can get away with nuking some of the global variable initializers
    // in the program...
    if (!NoGlobalRM &&
            BD.getProgram()->global_begin() != BD.getProgram()->global_end()) {
        // Now try to reduce the number of global variable initializers in the
        // module to something small.
        Module *M = CloneModule(BD.getProgram()).release();
        bool DeletedInit = false;

        for (Module::global_iterator I = M->global_begin(), E = M->global_end();
                I != E; ++I)
            if (I->hasInitializer()) {
                DeleteGlobalInitializer(&*I);
                I->setLinkage(GlobalValue::ExternalLinkage);
                I->setComdat(nullptr);
                DeletedInit = true;
            }

        if (!DeletedInit) {
            delete M;  // No change made...
        } else {
            // See if the program still causes a crash...
            outs() << "\nChecking to see if we can delete global inits: ";

            if (TestFn(BD, M)) {      // Still crashes?
                BD.setNewProgram(M);
                outs() << "\n*** Able to remove all global initializers!\n";
            } else {                  // No longer crashes?
                outs() << "  - Removing all global inits hides problem!\n";
                delete M;

                std::vector<GlobalVariable*> GVs;

                for (Module::global_iterator I = BD.getProgram()->global_begin(),
                        E = BD.getProgram()->global_end(); I != E; ++I)
                    if (I->hasInitializer())
                        GVs.push_back(&*I);

                if (GVs.size() > 1 && !BugpointIsInterrupted) {
                    outs() << "\n*** Attempting to reduce the number of global "
                           << "variables in the testcase\n";

                    unsigned OldSize = GVs.size();
                    ReduceCrashingGlobalVariables(BD, TestFn).reduceList(GVs, Error);
                    if (!Error.empty())
                        return true;

                    if (GVs.size() < OldSize)
                        BD.EmitProgressBitcode(BD.getProgram(), "reduced-global-variables");
                }
            }
        }
    }

    // Now try to reduce the number of functions in the module to something small.
    std::vector<Function*> Functions;
    for (Function &F : *BD.getProgram())
        if (!F.isDeclaration())
            Functions.push_back(&F);

    if (Functions.size() > 1 && !BugpointIsInterrupted) {
        outs() << "\n*** Attempting to reduce the number of functions "
               "in the testcase\n";

        unsigned OldSize = Functions.size();
        ReduceCrashingFunctions(BD, TestFn).reduceList(Functions, Error);

        if (Functions.size() < OldSize)
            BD.EmitProgressBitcode(BD.getProgram(), "reduced-function");
    }

    // Attempt to delete entire basic blocks at a time to speed up
    // convergence... this actually works by setting the terminator of the blocks
    // to a return instruction then running simplifycfg, which can potentially
    // shrinks the code dramatically quickly
    //
    if (!DisableSimplifyCFG && !BugpointIsInterrupted) {
        std::vector<const BasicBlock*> Blocks;
        for (Function &F : *BD.getProgram())
            for (BasicBlock &BB : F)
                Blocks.push_back(&BB);
        unsigned OldSize = Blocks.size();
        ReduceCrashingBlocks(BD, TestFn).reduceList(Blocks, Error);
        if (Blocks.size() < OldSize)
            BD.EmitProgressBitcode(BD.getProgram(), "reduced-blocks");
    }

    // Attempt to delete instructions using bisection. This should help out nasty
    // cases with large basic blocks where the problem is at one end.
    if (!BugpointIsInterrupted) {
        std::vector<const Instruction*> Insts;
        for (const Function &F : *BD.getProgram())
            for (const BasicBlock &BB : F)
                for (const Instruction &I : BB)
//.........这里部分代码省略.........
开发者ID:autodesk-forks,项目名称:llvm,代码行数:101,代码来源:CrashDebugger.cpp


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