~ubuntu-branches/ubuntu/feisty/clamav/feisty

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/include/llvm/Support/StableBasicBlockNumbering.h

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-02-20 10:33:44 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20070220103344-zgcu2psnx9d98fpa
Tags: upstream-0.90
ImportĀ upstreamĀ versionĀ 0.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//===- StableBasicBlockNumbering.h - Provide BB identifiers -----*- C++ -*-===//
2
 
//
3
 
//                     The LLVM Compiler Infrastructure
4
 
//
5
 
// This file is distributed under the University of Illinois Open Source
6
 
// License. See LICENSE.TXT for details.
7
 
//
8
 
//===----------------------------------------------------------------------===//
9
 
//
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.
14
 
//
15
 
//===----------------------------------------------------------------------===//
16
 
 
17
 
#ifndef LLVM_SUPPORT_STABLEBASICBLOCKNUMBERING_H
18
 
#define LLVM_SUPPORT_STABLEBASICBLOCKNUMBERING_H
19
 
 
20
 
#include "llvm/Function.h"
21
 
#include "llvm/ADT/UniqueVector.h"
22
 
 
23
 
namespace llvm {
24
 
  class StableBasicBlockNumbering {
25
 
    // BBNumbering - Holds the numbering.
26
 
    UniqueVector<BasicBlock*> BBNumbering;
27
 
  public:
28
 
    StableBasicBlockNumbering(Function *F = 0) {
29
 
      if (F) compute(*F);
30
 
    }
31
 
 
32
 
    /// compute - If we have not computed a numbering for the function yet, do
33
 
    /// so.
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);
38
 
      }
39
 
    }
40
 
 
41
 
    /// getNumber - Return the ID number for the specified BasicBlock.
42
 
    ///
43
 
    unsigned getNumber(BasicBlock *BB) const {
44
 
      unsigned Idx = BBNumbering.idFor(BB);
45
 
      assert(Idx && "Invalid basic block or numbering not computed!");
46
 
      return Idx-1;
47
 
    }
48
 
 
49
 
    /// getBlock - Return the BasicBlock corresponding to a particular ID.
50
 
    ///
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];
55
 
    }
56
 
  };
57
 
}
58
 
 
59
 
#endif