blob: f407a267931f4520117523f7fbad51c2c20a68bf [file] [log] [blame]
Chris Lattnerc1d10d62007-04-22 06:24:45 +00001//===-- Bitcode/Writer/ValueEnumerator.h - Number values --------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This class gives values and types Unique ID's.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef VALUE_ENUMERATOR_H
15#define VALUE_ENUMERATOR_H
16
17#include "llvm/ADT/DenseMap.h"
18#include <vector>
19
20namespace llvm {
21
22class Value;
23class Type;
24class Module;
25class Function;
26class TypeSymbolTable;
27class ValueSymbolTable;
28class ConstantArray;
29
30class ValueEnumerator {
31public:
32 // For each type, we remember its Type* and occurrence frequency.
33 typedef std::vector<std::pair<const Type*, unsigned> > TypeList;
34
35 // For each value, we remember its Value* and occurrence frequency.
36 typedef std::vector<std::pair<const Value*, unsigned> > ValueList;
37private:
38 TypeList Types;
39
40 typedef DenseMap<const Type*, unsigned> TypeMapType;
41 TypeMapType TypeMap;
42
43 ValueList Values;
44
45 typedef DenseMap<const Value*, unsigned> ValueMapType;
46 ValueMapType ValueMap;
47
48
49 ValueEnumerator(const ValueEnumerator &); // DO NOT IMPLEMENT
50 void operator=(const ValueEnumerator &); // DO NOT IMPLEMENT
51public:
52 ValueEnumerator(const Module *M);
53
54 unsigned getValueID(const Value *V) const {
55 ValueMapType::const_iterator I = ValueMap.find(V);
56 assert(I != ValueMap.end() && "Value not in slotcalculator!");
57 return I->second;
58 }
59
60 unsigned getTypeID(const Type *T) const {
61 TypeMapType::const_iterator I = TypeMap.find(T);
62 assert(I != TypeMap.end() && "Type not in ValueEnumerator!");
63 return I->second-1;
64 }
65
66
67 const TypeList &getTypes() const { return Types; }
68
69 /// incorporateFunction/purgeFunction - If you'd like to deal with a function,
70 /// use these two methods to get its data into the ValueEnumerator!
71 ///
72 void incorporateFunction(const Function *F);
73 void purgeFunction();
74
75private:
76 void EnumerateValue(const Value *V);
77 void EnumerateType(const Type *T);
78
79 void EnumerateTypeSymbolTable(const TypeSymbolTable &ST);
80 void EnumerateValueSymbolTable(const ValueSymbolTable &ST);
81};
82
83} // End llvm namespace
84
85#endif