1 //===-- Bitcode/Writer/ValueEnumerator.h - Number values --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This class gives values and types Unique ID's.
12 //===----------------------------------------------------------------------===//
14 #ifndef VALUE_ENUMERATOR_H
15 #define VALUE_ENUMERATOR_H
17 #include "llvm/ADT/DenseMap.h"
27 class TypeSymbolTable;
28 class ValueSymbolTable;
30 class ValueEnumerator {
32 // For each type, we remember its Type* and occurrence frequency.
33 typedef std::vector<std::pair<const Type*, unsigned> > TypeList;
35 // For each value, we remember its Value* and occurrence frequency.
36 typedef std::vector<std::pair<const Value*, unsigned> > ValueList;
38 typedef DenseMap<const Type*, unsigned> TypeMapType;
42 typedef DenseMap<const Value*, unsigned> ValueMapType;
43 ValueMapType ValueMap;
46 /// BasicBlocks - This contains all the basic blocks for the currently
47 /// incorporated function. Their reverse mapping is stored in ValueMap.
48 std::vector<const BasicBlock*> BasicBlocks;
50 /// When a function is incorporated, this is the size of the Values list
51 /// before incorporation.
52 unsigned NumModuleValues;
53 unsigned FirstFuncConstantID;
56 ValueEnumerator(const ValueEnumerator &); // DO NOT IMPLEMENT
57 void operator=(const ValueEnumerator &); // DO NOT IMPLEMENT
59 ValueEnumerator(const Module *M);
61 unsigned getValueID(const Value *V) const {
62 ValueMapType::const_iterator I = ValueMap.find(V);
63 assert(I != ValueMap.end() && "Value not in slotcalculator!");
67 unsigned getTypeID(const Type *T) const {
68 TypeMapType::const_iterator I = TypeMap.find(T);
69 assert(I != TypeMap.end() && "Type not in ValueEnumerator!");
73 /// getFunctionConstantRange - Return the range of values that corresponds to
74 /// function-local constants.
75 void getFunctionConstantRange(unsigned &Start, unsigned &End) const {
76 Start = FirstFuncConstantID;
80 const ValueList &getValues() const { return Values; }
81 const TypeList &getTypes() const { return Types; }
82 const std::vector<const BasicBlock*> &getBasicBlocks() const {
86 /// PurgeAggregateValues - If there are any aggregate values at the end of the
87 /// value list, remove them and return the count of the remaining values. If
88 /// there are none, return -1.
89 int PurgeAggregateValues();
91 /// incorporateFunction/purgeFunction - If you'd like to deal with a function,
92 /// use these two methods to get its data into the ValueEnumerator!
94 void incorporateFunction(const Function &F);
98 void EnumerateValue(const Value *V);
99 void EnumerateType(const Type *T);
101 void EnumerateTypeSymbolTable(const TypeSymbolTable &ST);
102 void EnumerateValueSymbolTable(const ValueSymbolTable &ST);
105 } // End llvm namespace