llvm中的立即数测试

时间:2011-04-27 14:18:07

标签: optimization compiler-construction llvm

在LLVM中,我想测试LoopInfo传递获得的行程数是否是立即数 数。例如,以下循环

for(i=0; i<10; i++) { ... }

的旅行次数为10,这是一个立即数。可以调用Loop的成员函数getTripCount()来获取表示行程计数的值。如何确定此值是否为立即数?

1 个答案:

答案 0 :(得分:0)

使用Scalar Evolution分析提供的以下getter:

unsigned ScalarEvolution::getSmallConstantTripCount(Loop *L, BasicBlock *ExitingBlock)

/// getSmallConstantTripCount - Returns the maximum trip count of this loop as a
/// normal unsigned value. Returns 0 if the trip count is unknown or not
/// constant. Will also return 0 if the maximum trip count is very large (>=
/// 2^32).
///
/// This "trip count" assumes that control exits via ExitingBlock. More
/// precisely, it is the number of times that control may reach ExitingBlock
/// before taking the branch. For loops with multiple exits, it may not be the
/// number times that the loop header executes because the loop may exit
/// prematurely via another branch.