1 //===-- Bitcode/Writer/ValueEnumerator.h - Number values --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // 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"
18 #include "llvm/Attributes.h"
29 class TypeSymbolTable
;
30 class ValueSymbolTable
;
32 class ValueEnumerator
{
34 // For each type, we remember its Type* and occurrence frequency.
35 typedef std::vector
<std::pair
<const Type
*, unsigned> > TypeList
;
37 // For each value, we remember its Value* and occurrence frequency.
38 typedef std::vector
<std::pair
<const Value
*, unsigned> > ValueList
;
40 typedef DenseMap
<const Type
*, unsigned> TypeMapType
;
44 typedef DenseMap
<const Value
*, unsigned> ValueMapType
;
45 ValueMapType ValueMap
;
48 typedef DenseMap
<void*, unsigned> AttributeMapType
;
49 AttributeMapType AttributeMap
;
50 std::vector
<AttrListPtr
> Attributes
;
52 /// BasicBlocks - This contains all the basic blocks for the currently
53 /// incorporated function. Their reverse mapping is stored in ValueMap.
54 std::vector
<const BasicBlock
*> BasicBlocks
;
56 /// When a function is incorporated, this is the size of the Values list
57 /// before incorporation.
58 unsigned NumModuleValues
;
59 unsigned FirstFuncConstantID
;
62 ValueEnumerator(const ValueEnumerator
&); // DO NOT IMPLEMENT
63 void operator=(const ValueEnumerator
&); // DO NOT IMPLEMENT
65 ValueEnumerator(const Module
*M
);
67 unsigned getValueID(const Value
*V
) const {
68 ValueMapType::const_iterator I
= ValueMap
.find(V
);
69 assert(I
!= ValueMap
.end() && "Value not in slotcalculator!");
73 unsigned getTypeID(const Type
*T
) const {
74 TypeMapType::const_iterator I
= TypeMap
.find(T
);
75 assert(I
!= TypeMap
.end() && "Type not in ValueEnumerator!");
79 unsigned getAttributeID(const AttrListPtr
&PAL
) const {
80 if (PAL
.isEmpty()) return 0; // Null maps to zero.
81 AttributeMapType::const_iterator I
= AttributeMap
.find(PAL
.getRawPointer());
82 assert(I
!= AttributeMap
.end() && "Attribute not in ValueEnumerator!");
86 /// getFunctionConstantRange - Return the range of values that corresponds to
87 /// function-local constants.
88 void getFunctionConstantRange(unsigned &Start
, unsigned &End
) const {
89 Start
= FirstFuncConstantID
;
93 const ValueList
&getValues() const { return Values
; }
94 const TypeList
&getTypes() const { return Types
; }
95 const std::vector
<const BasicBlock
*> &getBasicBlocks() const {
98 const std::vector
<AttrListPtr
> &getAttributes() const {
102 /// PurgeAggregateValues - If there are any aggregate values at the end of the
103 /// value list, remove them and return the count of the remaining values. If
104 /// there are none, return -1.
105 int PurgeAggregateValues();
107 /// incorporateFunction/purgeFunction - If you'd like to deal with a function,
108 /// use these two methods to get its data into the ValueEnumerator!
110 void incorporateFunction(const Function
&F
);
111 void purgeFunction();
114 void OptimizeConstants(unsigned CstStart
, unsigned CstEnd
);
116 void EnumerateValue(const Value
*V
);
117 void EnumerateType(const Type
*T
);
118 void EnumerateOperandType(const Value
*V
);
119 void EnumerateAttributes(const AttrListPtr
&PAL
);
121 void EnumerateTypeSymbolTable(const TypeSymbolTable
&ST
);
122 void EnumerateValueSymbolTable(const ValueSymbolTable
&ST
);
125 } // End llvm namespace