我正按照以下说明构建循环传递:http://llvm.org/docs/WritingAnLLVMPass.html
一切正常,我为Function Passes做了很多次,但是在runOnLoop
方法中,每当我调用作为参数传递的循环L的方法时,例如L->begin()
,我得到以下错误:
opt:符号查找错误: /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)
答案 0 :(得分:-1)
使用begin()函数错误。该错误表明编译器找不到这样的函数。快速查看Loop类引用告诉我没有名为begin的成员函数。