Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用LLVM函数pass找出调用站点的循环深度?_Llvm_Llvm C++ Api - Fatal编程技术网

如何使用LLVM函数pass找出调用站点的循环深度?

如何使用LLVM函数pass找出调用站点的循环深度?,llvm,llvm-c++-api,Llvm,Llvm C++ Api,我需要使用LLVM函数传递找出函数调用站点(或任何指令)的嵌套级别。我已经编写了下面的代码,但它总是返回0作为嵌套级别 virtual bool runOnFunction(Function &F) { LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); errs() << "Function: " << F.getName() << "\n";

我需要使用LLVM函数传递找出函数调用站点(或任何指令)的嵌套级别。我已经编写了下面的代码,但它总是返回0作为嵌套级别

virtual bool runOnFunction(Function &F) {
  LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
  errs() << "Function: " << F.getName() << "\n";

  for (User *U : F.users()) {
    CallSite CS(dyn_cast<Instruction>(U));
    Function *callerFn = CS.getCaller();
    if (callerFn && !callerFn->isDeclaration()) {
      errs() <<callerFn->getName() << "--> " << F.getName()<<"\n";
      Instruction *callInstr = CS.getInstruction();
      BasicBlock *callerBB = callInstr->getParent();
      callerBB->dump();
      bool isLoop = LI.getLoopFor(callerBB);
      errs()<<"Is Loop: "<<isLoop<<"\n";
      int LoopDepth = LI.getLoopDepth(callerBB);
      errs()<<"Loop Depth: "<< LoopDepth <<"\n";

    }

  }
virtualbool runOnFunction(函数&F){
LoopInfo&LI=getAnalysis().getLoopInfo();
errs()
我需要找出函数调用站点(或任何
(关于这一点,请参见说明)

对于循环,可以通过以下方式编辑过程来执行此操作:

namespace {
  struct LoopDepthPass: public FunctionPass {
    static char ID;
    LoopDepthPass: () : FunctionPass(ID) {}

    void getAnalysisUsage(AnalysisUsage &AU) const override {
      AU.setPreservesCFG();
      AU.addRequired<LoopInfoWrapperPass>();
    }

    bool runOnFunction(Function& F) override {
      LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
      for (LoopInfo::iterator LIT = LI.begin(); LIT != LI.end(); ++LIT) {
        Loop* ll = *LIT;  
        ll->dump();
      }
      return false;
    }
};
产出将是:

Loop at depth 1 containing: %for.cond<header><exiting>,%for.body,%for.cond.1,%for.end,%for.inc.7<latch>,%for.body.4,%for.inc
    Loop at depth 2 containing: %for.cond.1<header><exiting>,%for.body.4,%for.inc<latch>
深度1处的循环包含以下内容:%for.cond、.body、.cond.1、.end、.inc.7、.body.4、.inc
深度2处的循环包含:%for.cond.1、%for.body.4、%for.inc
我已打印出
循环->转储()
,您也可以轻松地将其改编为其他属性

Loop at depth 1 containing: %for.cond<header><exiting>,%for.body,%for.cond.1,%for.end,%for.inc.7<latch>,%for.body.4,%for.inc
    Loop at depth 2 containing: %for.cond.1<header><exiting>,%for.body.4,%for.inc<latch>