更新时间:2023-12-03 22:52:52
AllocaInst
的公共方法 isArrayAllocation()
。你可以用它来计算对应只有阵列的alloca指令数。
的(功能:迭代BB = F.begin(),BE = F.end(); BB = BE;!++ BB)
对于(BasicBlock:迭代II = BB->开始(),IE = BB->结束(!); II = IE ++ II)
如果(AllocaInst * AI = dyn_cast&所述; AllocaInst&GT(II))
如果(AI-> isArrayAllocation())
犯错()&所述;&下; !数组的ALLOCA发现\\ N的;
How can the total number of arrays be counted in a C program ?
The array declarations in LLVM IR correspond to alloca type of operation. So
int a[10];
corresponds to
%a = alloca [10 x i32], align 4
in LLVM IR.
But I also noticed that
int j = 0;
also corresponds to an alloca instruction
%j = alloca i32, align 4
So how to count the number of alloca instructions that correspond only to arrays ?
EDIT:
for (Function::iterator i = F.begin(), e = F.end(); i != e; ++i)
{
for (BasicBlock::iterator ii =(*i).begin(), ii_e = (*i).end(); ii != ii_e; ++ii)
{
Instruction *n = dyn_cast<Instruction>(&*ii);
for( int num = 0; num < n->getNumOperands(); ++num)
if(isa<ArrayType>(n->getOperand(num)->getType()))
{
// doesn't work
errs()<<"yayayayay Array\n";
}
}
}
AllocaInst
has public method isArrayAllocation()
. You can use it to count the number of alloca instructions that correspond only to arrays.
for (Function::iterator BB = F.begin(), BE = F.end(); BB != BE; ++BB)
for (BasicBlock::iterator II = BB->begin(), IE = BB->end(); II != IE; ++II)
if (AllocaInst *AI = dyn_cast<AllocaInst>(II))
if (AI->isArrayAllocation())
errs() << "Alloca of array is found!\n";