gpt4 book ai didi

c++ - LoopPass 可加载模块的 undefined symbol

转载 作者:太空狗 更新时间:2023-10-29 23:20:42 25 4
gpt4 key购买 nike

我正在按照以下说明构建循环传递:http://llvm.org/docs/WritingAnLLVMPass.html一切正常,我为函数传递做了很多次,但是在 runOnLoop 方法中,每当我调用作为参数传递的循环 L 的方法时,例如 L->begin() ,我收到以下错误:

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)

最佳答案

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

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

关于c++ - LoopPass 可加载模块的 undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16311431/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com