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"
28 class TypeSymbolTable;
29 class ValueSymbolTable;
31 class ValueEnumerator {
33 // For each type, we remember its Type* and occurrence frequency.
34 typedef std::vector<std::pair<const Type*, unsigned> > TypeList;
36 // For each value, we remember its Value* and occurrence frequency.
37 typedef std::vector<std::pair<const Value*, unsigned> > ValueList;
39 typedef DenseMap<const Type*, unsigned> TypeMapType;
43 typedef DenseMap<const Value*, unsigned> ValueMapType;
44 ValueMapType ValueMap;
47 typedef DenseMap<const ParamAttrsList*, unsigned> ParamAttrMapType;
48 ParamAttrMapType ParamAttrMap;
49 std::vector<const ParamAttrsList*> ParamAttrs;
51 /// BasicBlocks - This contains all the basic blocks for the currently
52 /// incorporated function. Their reverse mapping is stored in ValueMap.
53 std::vector<const BasicBlock*> BasicBlocks;
55 /// When a function is incorporated, this is the size of the Values list
56 /// before incorporation.
57 unsigned NumModuleValues;
58 unsigned FirstFuncConstantID;
61 ValueEnumerator(const ValueEnumerator &); // DO NOT IMPLEMENT
62 void operator=(const ValueEnumerator &); // DO NOT IMPLEMENT
64 ValueEnumerator(const Module *M);
66 unsigned getValueID(const Value *V) const {
67 ValueMapType::const_iterator I = ValueMap.find(V);
68 assert(I != ValueMap.end() && "Value not in slotcalculator!");
72 unsigned getTypeID(const Type *T) const {
73 TypeMapType::const_iterator I = TypeMap.find(T);
74 assert(I != TypeMap.end() && "Type not in ValueEnumerator!");
78 unsigned getParamAttrID(const ParamAttrsList *PAL) const {
79 if (PAL == 0) return 0; // Null maps to zero.
80 ParamAttrMapType::const_iterator I = ParamAttrMap.find(PAL);
81 assert(I != ParamAttrMap.end() && "ParamAttr not in ValueEnumerator!");
85 /// getFunctionConstantRange - Return the range of values that corresponds to
86 /// function-local constants.
87 void getFunctionConstantRange(unsigned &Start, unsigned &End) const {
88 Start = FirstFuncConstantID;
92 const ValueList &getValues() const { return Values; }
93 const TypeList &getTypes() const { return Types; }
94 const std::vector<const BasicBlock*> &getBasicBlocks() const {
97 const std::vector<const ParamAttrsList*> &getParamAttrs() const {
101 /// PurgeAggregateValues - If there are any aggregate values at the end of the
102 /// value list, remove them and return the count of the remaining values. If
103 /// there are none, return -1.
104 int PurgeAggregateValues();
106 /// incorporateFunction/purgeFunction - If you'd like to deal with a function,
107 /// use these two methods to get its data into the ValueEnumerator!
109 void incorporateFunction(const Function &F);
110 void purgeFunction();
113 void OptimizeConstants(unsigned CstStart, unsigned CstEnd);
115 void EnumerateValue(const Value *V);
116 void EnumerateType(const Type *T);
117 void EnumerateParamAttrs(const ParamAttrsList *PAL);
119 void EnumerateTypeSymbolTable(const TypeSymbolTable &ST);
120 void EnumerateValueSymbolTable(const ValueSymbolTable &ST);
123 } // End llvm namespace