1
//===- StableBasicBlockNumbering.h - Provide BB identifiers -----*- C++ -*-===//
3
// The LLVM Compiler Infrastructure
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
8
//===----------------------------------------------------------------------===//
10
// This class provides a *stable* numbering of basic blocks that does not depend
11
// on their address in memory (which is nondeterministic). When requested, this
12
// class simply provides a unique ID for each basic block in the function
13
// specified and the inverse mapping.
15
//===----------------------------------------------------------------------===//
17
#ifndef LLVM_SUPPORT_STABLEBASICBLOCKNUMBERING_H
18
#define LLVM_SUPPORT_STABLEBASICBLOCKNUMBERING_H
20
#include "llvm/Function.h"
21
#include "llvm/ADT/UniqueVector.h"
24
class StableBasicBlockNumbering {
25
// BBNumbering - Holds the numbering.
26
UniqueVector<BasicBlock*> BBNumbering;
28
StableBasicBlockNumbering(Function *F = 0) {
32
/// compute - If we have not computed a numbering for the function yet, do
34
void compute(Function &F) {
35
if (BBNumbering.empty()) {
36
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
37
BBNumbering.insert(I);
41
/// getNumber - Return the ID number for the specified BasicBlock.
43
unsigned getNumber(BasicBlock *BB) const {
44
unsigned Idx = BBNumbering.idFor(BB);
45
assert(Idx && "Invalid basic block or numbering not computed!");
49
/// getBlock - Return the BasicBlock corresponding to a particular ID.
51
BasicBlock *getBlock(unsigned N) const {
52
assert(N < BBNumbering.size() &&
53
"Block ID out of range or numbering not computed!");
54
return BBNumbering[N+1];