2013-05-01 82 views
3

我建立一个环通以下说明未定义的符号:http://llvm.org/docs/WritingAnLLVMPass.html 一切正常,我是做功能很多次传球,但在runOnLoop方法,每当我打电话通过环L的方法作为参数,例如L->begin(),我得到以下错误:为LoopPass可加载模块

opt: symbol lookup error: /home/giacomo/llvmcsfv/Debug+Asserts/lib/Acsl.so: undefined symbol: _ZNK4llvm8LoopBaseINS_10BasicBlockENS_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) 

回答

-1

开始()函数错误使用。错误表示编译器找不到这样的函数。快速查看Loop类引用告诉我,没有成员函数称为begin。

http://llvm.org/docs/doxygen/html/classllvm_1_1Loop.html

+0

begin是返回第一个基本块的迭代器的函数。当然我没有定义它,正如我所说的,我可以用Loop定义的其他方法替代它。 btw你的不是答案,你应该为我的问题添加评论,而不是回答。 – 2013-05-08 18:57:06

+0

然后我认为这是错误的begin()函数的用法,因为错误似乎说编译器找不到这样的函数。快速查看Loop类引用告诉我,没有成员函数称为begin。 http://llvm.org/docs/doxygen/html/classllvm_1_1Loop.html 我知道这不是一个答案,但我目前没有足够的声望评论某人的问题。如果解决了,我会编辑它以作为答案。 – shrm 2013-05-08 19:43:42

+0

这就是你的问题的答案。请考虑接受它。 – shrm 2013-05-08 19:59:34