C++ LoopPass可加载模块的未定义符号

C++ LoopPass可加载模块的未定义符号,c++,llvm,llvm-c++-api,C++,Llvm,Llvm C++ Api,我正在按照以下说明构建循环过程: 一切正常,我对函数传递做了很多次,但是在runonlop方法中,每当我调用作为参数传递的循环的方法,例如L->begin(),我都会得到以下错误: 选项:符号查找错误: /home/giacomo/llvmcsfv/Debug+Asserts/lib/Acsl.so:未定义符号: _ZNK4llvm8LoopBaseINS\u 10BasicBlockENS\u 4LoopEE5beginEv 其中Acsl是可加载模块的名称。如果我删除了runOnPass中的所

我正在按照以下说明构建循环过程: 一切正常,我对函数传递做了很多次,但是在
runonlop
方法中,每当我调用作为参数传递的循环的方法,例如
L->begin()
,我都会得到以下错误:

选项:符号查找错误: /home/giacomo/llvmcsfv/Debug+Asserts/lib/Acsl.so:未定义符号: _ZNK4llvm8LoopBaseINS\u 10BasicBlockENS\u 4LoopEE5beginEv

其中Acsl是可加载模块的名称。如果我删除了
runOnPass
中的所有指令,但删除了调试打印,那么它工作正常(打印),因此问题不在于模块。 有人知道吗

这是转换传递代码:

//===- AcslDCEE.cpp - Acsl Dead Code Elimination -----------------*- C++ -*-===//
//
//         The LLVM Compiler Infrastructure - CSFV Annotation Framework
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements a Dead Code Elimination that uses ACSL annotations
//
//===----------------------------------------------------------------------===//    

#define DEBUG_TYPE "licm"
#include "llvm/Transforms/Scalar.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/AliasSetTracker.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
#include "llvm/Support/CFG.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetLibraryInfo.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/SSAUpdater.h"
#include <algorithm>
using namespace llvm;    

// STATISTIC(AcslNumSunk      , "Number of instructions sunk out of loop");
// STATISTIC(AcslNumHoisted   , "Number of instructions hoisted out of loop");
// STATISTIC(AcslNumMovedLoads, "Number of load insts hoisted or sunk");
// STATISTIC(AcslNumMovedCalls, "Number of call insts hoisted or sunk");
// STATISTIC(AcslNumPromoted  , "Number of memory locations promoted to registers");    

namespace {
struct AcslDCEE: public LoopPass {
  static char ID; // Pass identification, replacement for typeid
  AcslDCEE() :
      LoopPass(ID) {}    

  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
    AU.setPreservesCFG();
    AU.addRequired<DominatorTree>();
    AU.addRequired<LoopInfo>();
    AU.addRequiredID(LoopSimplifyID);
    AU.addRequired<AliasAnalysis>();
    AU.addPreserved<AliasAnalysis>();
    AU.addPreserved("scalar-evolution");
    AU.addPreservedID(LoopSimplifyID);
    AU.addRequired<TargetLibraryInfo>();
  }    

  /**
   * The runOnFunction method must be implemented by your subclass to do the
   * transformation or analysis work of your pass. As usual, a true value
   * should be returned if the function is modified.
   */
  virtual bool runOnLoop(Loop *L, LPPassManager &LPM){
    bool Changed = false;
    LI = &getAnalysis<LoopInfo>();
    AA = &getAnalysis<AliasAnalysis>();
    DT = &getAnalysis<DominatorTree>();    

    TD = getAnalysisIfAvailable<DataLayout>();
    TLI = &getAnalysis<TargetLibraryInfo>();    

    errs() << "before!\n";
    L->begin();
    errs() << "after!\n";
    return Changed;
  }    

  /**
   * The doInitialization method is designed to do simple initialization type
   * of stuff that does not depend on the functions being processed.
   * The doInitialization method call is not scheduled to overlap with any
   * other pass executions.
   */
  // virtual bool doInitialization(Loop *L, LPPassManager &LPM){
  //   errs() << "###Acsl DCEeeeea###\n";
  //   L->dump();
  //   errs() << "uhm...\n";
  //   return LoopPass::doInitialization(L,LPM);
  //   // return true;
  // }    

  // /**
  //  * The doFinalization method is an infrequently used method that is called
  //  * when the pass framework has finished calling runOnFunction for every
  //  * function in the program being compiled.
  //  */
  // virtual bool doFinalization(Module &M) {
  //   DEBUG(errs() << "\n");
  //   return LoopPass::doFinalization(M);
  // }    

  // bool doFinalization() {
  //     DEBUG(errs() << "\n");
  //     return LoopPass::doFinalization();
  //   }    

private:    

  AliasAnalysis *AA;       // Current AliasAnalysis information
  LoopInfo      *LI;       // Current LoopInfo
  DominatorTree *DT;       // Dominator Tree for the current Loop.    

  DataLayout *TD;          // DataLayout for constant folding.
  TargetLibraryInfo *TLI;  // TargetLibraryInfo for constant folding.    

  // State that is updated as we process loops.
  bool Changed;            // Set to true when we change anything.
  BasicBlock *Preheader;   // The preheader block of the current loop...
  Loop *CurLoop;           // The current loop we are working on...
  AliasSetTracker *CurAST; // AliasSet information for the current loop...
  bool MayThrow;           // The current loop contains an instruction which
                           // may throw, thus preventing code motion of
                           // instructions with side effects.
  DenseMap<Loop*, AliasSetTracker*> LoopToAliasSetMap;    

};
} //end of anonymous namespace    

char AcslDCEE::ID = 0;
static RegisterPass<AcslDCEE> X("acsldcee", "acsl dead code elimination");
// INITIALIZE_PASS_BEGIN(AcslDCEE, "acsldcee", "Loop Invariant Code Motion", false, false)
// // INITIALIZE_PASS_DEPENDENCY(DominatorTree)
// INITIALIZE_PASS_DEPENDENCY(LoopInfo)
// // INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
// // INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfo)
// // INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
// INITIALIZE_PASS_END(AcslDCEE, "acsldcee", "Loop Invariant Code Motion", false, false)
<代码> //==-ACSLDCECE.CPP-ACSL死代码消除---------*-*-C++ +*==// // //LLVM编译器基础结构-CSFV注释框架 // //此文件是在伊利诺伊大学开源下分发的。 //执照。有关详细信息,请参阅LICENSE.TXT。 // //===----------------------------------------------------------------------===// // //此文件实现了使用ACSL注释的死代码消除 // //===----------------------------------------------------------------------===// #定义调试类型“licm” #包括“llvm/Transforms/Scalar.h” #包括“llvm/ADT/Statistic.h” #包括“llvm/Analysis/AliasAnalysis.h” #包括“llvm/Analysis/AliasSetTracker.h” #包括“llvm/Analysis/ConstantFolding.h” #包括“llvm/Analysis/Dominators.h” #包括“llvm/Pass.h” #包括“llvm/IR/Function.h” #包括“llvm/Analysis/LoopInfo.h” #包括“llvm/Analysis/LoopPass.h” #包括“llvm/Analysis/ValueTracking.h” #包括“llvm/IR/Constants.h” #包括“llvm/IR/DataLayout.h” #包括“llvm/IR/DerivedTypes.h” #包括“llvm/IR/Instructions.h” #包括“llvm/IR/IntrinsicInst.h” #包括“llvm/IR/LLVMContext.h” #包括“llvm/IR/Metadata.h” #包括“llvm/Support/CFG.h” #包括“llvm/Support/CommandLine.h” #包括“llvm/Support/Debug.h” #包括“llvm/Support/raw_ostream.h” #包括“llvm/Target/TargetLibraryInfo.h” #包括“llvm/Transforms/Utils/Local.h” #包括“llvm/Transforms/Utils/SSAUpdater.h” #包括 使用名称空间llvm; //统计(AcslNumSunk,“从循环中沉没的指令数”); //统计(ACSLNUMHOITED,“从循环中提升的指令数”); //统计数据(AcslNumMovedLoads,“起吊或下沉的负载数量”); //统计(AcslNumMovedCalls,“挂起或沉没的呼叫装置数量”); //统计(ACSLNUMPROMBROMBOTED,“提升到寄存器的内存位置数”); 名称空间{ 结构AcslDCEE:公共循环通行证{ 静态字符ID;//传递标识,替换typeid AcslDCEE(): LoopPass(ID){} 虚空getAnalysisUsage(AnalysisUsage&AU)常量{ AU.setscfg(); AU.addRequired(); AU.addRequired(); AU.addRequiredID(ID); AU.addRequired(); AU.addPreserved(); AU.addPreserved(“标量进化”); AU.adddid(id); AU.addRequired(); } /** *runOnFunction方法必须由子类实现才能执行 *转换或分析你的通行证工作。像往常一样,一个真正的价值 *如果修改函数,则应返回。 */ 虚拟bool runonlop(循环*L、LPPassManager和LPM){ bool-Changed=false; LI=&getAnalysis(); AA=&getAnalysis(); DT=&getAnalysis(); TD=getAnalysisIfAvailable(); TLI=&getAnalysis(); 错误()开始(); errs()错误地使用了begin()函数。错误表明编译器找不到这样的函数。快速查看循环类引用可以发现没有名为begin的成员函数


begin是在第一个基本块返回迭代器的函数。当然,我没有定义它,正如我所说,我可以将它替换为Loop定义的其他方法。顺便说一句,你的不是答案,你应该在我的问题中添加注释,而不是答案。那么我认为begin()的用法是错误的函数,因为错误似乎表明编译器找不到这样的函数。快速查看循环类引用告诉我,没有名为begin的成员函数。我知道这不是一个答案,但我目前没有足够的声誉来评论某人的问题。如果它行得通,我将进行编辑以使其成为答案。ThATS是您的问题的答案。请考虑接受它。当然,因为是由类环基继承的……正如您在这里看到的:在这个循环中,在第218行,L调用方法开始。如果它可以帮助,我添加它。