Regarding LLVM Compiler

Hi Kameshwar,

You’re best off sending emails such as this to the LLVM developers mailing list ( You’ll reach a much wider audience.

The PBQPRegAlloc::buildInterferenceMatrix method constructs a PBQP cost matrix representing a single interference constraint, which doesn’t sound like what you want. It is only used by the PBQP allocator (-regalloc=pbqp), whereas LLVM uses linear scan by default (-regalloc=linscan). That’s why you’re not seeing it called.

LLVM does not currently have an interference graph as such, because we do not have a graph coloring register allocator. You can get the same information from the LiveIntervals pass though. The LiveIntervals pass holds a set of LiveInterval objects, one for each register (both virtual and physical) that is live in the function. Each LiveInterval object describes the set of instructions for which its register is live. The LiveInterval::overlaps method will tell you whether or not two intervals overlap, which means the registers for those intervals interfere.
(One caution: LiveInterval::overlaps currently triggers an assertion if the interval passed as a parameter is empty. You’ll want to explicitly skip testing of empty intervals. They can just be treated as non-interfering.)

To sum up, you probably want something like this:

LiveIntervals *li_ = &getAnalysis();
for (LiveIntervals::iterator liItr = li_->begin(), liEnd = li_->end(); liItr != liEnd; ++liItr) {
LiveInterval *li = liItr->second;
if (li->empty())
for (LiveIntervals::iterator li2Itr = llvm::next(liItr); li2Itr != liEnd; ++liItr) {
LiveInterval *li2 = li2Itr->second;
if (li2->empty())

if (li->overlaps(*li2)) {
// li->reg interferes with li2->reg.
// Handle this however you need to.