1

In LLVM, I'd like to test whether the trip count obtained by LoopInfo pass is an immediate number. For example, the following loop

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

has a trip count of 10, and it's an immediate number. The member function getTripCount() of Loop can be called to get a Value representing the trip count. How can I decide this value is an immediate number or not?

osgx
  • 90,338
  • 53
  • 357
  • 513
dalibocai
  • 2,289
  • 5
  • 29
  • 45

1 Answers1

0

Use the following getter provided by the Scalar Evolution analysis:

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.
zr.
  • 7,528
  • 11
  • 50
  • 84