Tuesday, June 06, 2006

Getting loop information

The register allocation algorithm must provide heuristics to select good registers to spill, when spilling is unavoidable. Normally, the usage frequency of instructions is used as a utility function. The best candidate for eviction is a temporary that minimizes the frequency of execution of load and store instruction. Such frequency can be approximated by taking into consideration the loop depth of each basic block. In order to obtain this information in LLVM, one can use the following code:

#include "llvm/Analysis/LoopInfo.h"
AU.addRequired<LoopInfo>(); // in getAnalysisUsage
const LoopInfo *loopInfo;
loopInfo = &getAnalysis<LoopInfo>();
// MBB is MachineBasicBlock
const BasicBlock *BB = MBB.getBasicBlock();
unsigned loopDepth = loopInfo->getLoopDepth(BB);

0 Comments:

Post a Comment

<< Home