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"
31 class TypeSymbolTable;
32 class ValueSymbolTable;
34 class ValueEnumerator {
36 // For each type, we remember its Type* and occurrence frequency.
37 typedef std::vector<std::pair<const Type*, unsigned> > TypeList;
39 // For each value, we remember its Value* and occurrence frequency.
40 typedef std::vector<std::pair<const Value*, unsigned> > ValueList;
42 typedef DenseMap<const Type*, unsigned> TypeMapType;
46 typedef DenseMap<const Value*, unsigned> ValueMapType;
47 ValueMapType ValueMap;
50 ValueMapType MDValueMap;
52 typedef DenseMap<void*, unsigned> AttributeMapType;
53 AttributeMapType AttributeMap;
54 std::vector<AttrListPtr> Attributes;
56 typedef DenseMap<const Instruction*, unsigned> InstructionMapType;
57 InstructionMapType InstructionMap;
58 unsigned InstructionCount;
60 /// BasicBlocks - This contains all the basic blocks for the currently
61 /// incorporated function. Their reverse mapping is stored in ValueMap.
62 std::vector<const BasicBlock*> BasicBlocks;
64 /// When a function is incorporated, this is the size of the Values list
65 /// before incorporation.
66 unsigned NumModuleValues;
67 unsigned FirstFuncConstantID;
70 ValueEnumerator(const ValueEnumerator &); // DO NOT IMPLEMENT
71 void operator=(const ValueEnumerator &); // DO NOT IMPLEMENT
73 ValueEnumerator(const Module *M);
75 unsigned getValueID(const Value *V) const;
77 unsigned getTypeID(const Type *T) const {
78 TypeMapType::const_iterator I = TypeMap.find(T);
79 assert(I != TypeMap.end() && "Type not in ValueEnumerator!");
83 unsigned getInstructionID(const Instruction *I) const;
84 void setInstructionID(const Instruction *I);
86 unsigned getAttributeID(const AttrListPtr &PAL) const {
87 if (PAL.isEmpty()) return 0; // Null maps to zero.
88 AttributeMapType::const_iterator I = AttributeMap.find(PAL.getRawPointer());
89 assert(I != AttributeMap.end() && "Attribute not in ValueEnumerator!");
93 /// getFunctionConstantRange - Return the range of values that corresponds to
94 /// function-local constants.
95 void getFunctionConstantRange(unsigned &Start, unsigned &End) const {
96 Start = FirstFuncConstantID;
100 const ValueList &getValues() const { return Values; }
101 const ValueList &getMDValues() const { return MDValues; }
102 const TypeList &getTypes() const { return Types; }
103 const std::vector<const BasicBlock*> &getBasicBlocks() const {
106 const std::vector<AttrListPtr> &getAttributes() const {
110 /// incorporateFunction/purgeFunction - If you'd like to deal with a function,
111 /// use these two methods to get its data into the ValueEnumerator!
113 void incorporateFunction(const Function &F);
114 void purgeFunction();
117 void OptimizeConstants(unsigned CstStart, unsigned CstEnd);
119 void EnumerateMetadata(const MetadataBase *MD);
120 void EnumerateValue(const Value *V);
121 void EnumerateType(const Type *T);
122 void EnumerateOperandType(const Value *V);
123 void EnumerateAttributes(const AttrListPtr &PAL);
125 void EnumerateTypeSymbolTable(const TypeSymbolTable &ST);
126 void EnumerateValueSymbolTable(const ValueSymbolTable &ST);
129 } // End llvm namespace