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"
30 class TypeSymbolTable
;
31 class ValueSymbolTable
;
33 class ValueEnumerator
{
35 // For each type, we remember its Type* and occurrence frequency.
36 typedef std::vector
<std::pair
<const Type
*, unsigned> > TypeList
;
38 // For each value, we remember its Value* and occurrence frequency.
39 typedef std::vector
<std::pair
<const Value
*, unsigned> > ValueList
;
41 typedef DenseMap
<const Type
*, unsigned> TypeMapType
;
45 typedef DenseMap
<const Value
*, unsigned> ValueMapType
;
46 ValueMapType ValueMap
;
49 ValueMapType MDValueMap
;
51 typedef DenseMap
<void*, unsigned> AttributeMapType
;
52 AttributeMapType AttributeMap
;
53 std::vector
<AttrListPtr
> Attributes
;
55 /// BasicBlocks - This contains all the basic blocks for the currently
56 /// incorporated function. Their reverse mapping is stored in ValueMap.
57 std::vector
<const BasicBlock
*> BasicBlocks
;
59 /// When a function is incorporated, this is the size of the Values list
60 /// before incorporation.
61 unsigned NumModuleValues
;
62 unsigned FirstFuncConstantID
;
65 ValueEnumerator(const ValueEnumerator
&); // DO NOT IMPLEMENT
66 void operator=(const ValueEnumerator
&); // DO NOT IMPLEMENT
68 ValueEnumerator(const Module
*M
);
70 unsigned getValueID(const Value
*V
) const;
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 getAttributeID(const AttrListPtr
&PAL
) const {
79 if (PAL
.isEmpty()) return 0; // Null maps to zero.
80 AttributeMapType::const_iterator I
= AttributeMap
.find(PAL
.getRawPointer());
81 assert(I
!= AttributeMap
.end() && "Attribute 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 ValueList
&getMDValues() const { return MDValues
; }
94 const TypeList
&getTypes() const { return Types
; }
95 const std::vector
<const BasicBlock
*> &getBasicBlocks() const {
98 const std::vector
<AttrListPtr
> &getAttributes() const {
102 /// incorporateFunction/purgeFunction - If you'd like to deal with a function,
103 /// use these two methods to get its data into the ValueEnumerator!
105 void incorporateFunction(const Function
&F
);
106 void purgeFunction();
109 void OptimizeConstants(unsigned CstStart
, unsigned CstEnd
);
111 void EnumerateMetadata(const MetadataBase
*MD
);
112 void EnumerateValue(const Value
*V
);
113 void EnumerateType(const Type
*T
);
114 void EnumerateOperandType(const Value
*V
);
115 void EnumerateAttributes(const AttrListPtr
&PAL
);
117 void EnumerateTypeSymbolTable(const TypeSymbolTable
&ST
);
118 void EnumerateValueSymbolTable(const ValueSymbolTable
&ST
);
121 } // End llvm namespace