1
我需要使用LLVM函數傳遞找出函數調用站點(或任何指令)的嵌套級別。我已經編寫了下面的代碼,但它總是返回0作爲嵌套級別。如何使用LLVM函數傳遞找出呼叫站點的環路深度?
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";
}
}