2004-06-19 08:41:59 +00:00
|
|
|
//===- StableBasicBlockNumbering.h - Provide BB identifiers -----*- C++ -*-===//
|
2005-04-21 20:48:15 +00:00
|
|
|
//
|
2004-06-19 08:41:59 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:48:15 +00:00
|
|
|
//
|
2004-06-19 08:41:59 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This class provides a *stable* numbering of basic blocks that does not depend
|
|
|
|
// on their address in memory (which is nondeterministic). When requested, this
|
|
|
|
// class simply provides a unique ID for each basic block in the function
|
|
|
|
// specified and the inverse mapping.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_SUPPORT_STABLEBASICBLOCKNUMBERING_H
|
|
|
|
#define LLVM_SUPPORT_STABLEBASICBLOCKNUMBERING_H
|
|
|
|
|
|
|
|
#include "llvm/Function.h"
|
2007-02-05 23:19:24 +00:00
|
|
|
#include "llvm/ADT/UniqueVector.h"
|
2004-06-19 08:41:59 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class StableBasicBlockNumbering {
|
2007-02-05 23:19:24 +00:00
|
|
|
// BBNumbering - Holds the numbering.
|
|
|
|
UniqueVector<BasicBlock*> BBNumbering;
|
2004-06-19 08:41:59 +00:00
|
|
|
public:
|
|
|
|
StableBasicBlockNumbering(Function *F = 0) {
|
|
|
|
if (F) compute(*F);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// compute - If we have not computed a numbering for the function yet, do
|
|
|
|
/// so.
|
|
|
|
void compute(Function &F) {
|
2007-02-05 23:19:24 +00:00
|
|
|
if (BBNumbering.empty()) {
|
|
|
|
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
|
|
|
|
BBNumbering.insert(I);
|
2004-06-19 08:41:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getNumber - Return the ID number for the specified BasicBlock.
|
|
|
|
///
|
|
|
|
unsigned getNumber(BasicBlock *BB) const {
|
2007-02-05 23:19:24 +00:00
|
|
|
unsigned Idx = BBNumbering.idFor(BB);
|
|
|
|
assert(Idx && "Invalid basic block or numbering not computed!");
|
|
|
|
return Idx-1;
|
2004-06-19 08:41:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getBlock - Return the BasicBlock corresponding to a particular ID.
|
|
|
|
///
|
|
|
|
BasicBlock *getBlock(unsigned N) const {
|
2007-02-05 23:19:24 +00:00
|
|
|
assert(N < BBNumbering.size() &&
|
2004-06-19 08:41:59 +00:00
|
|
|
"Block ID out of range or numbering not computed!");
|
2007-02-05 23:19:24 +00:00
|
|
|
return BBNumbering[N+1];
|
2004-06-19 08:41:59 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|