Don't analyze block if it's not considered for ifcvt anymore.
[llvm/stm8.git] / lib / Bitcode / Writer / ValueEnumerator.h
blob6617b60deb26168976d32d7199d40296e3fd421b
1 //===-- Bitcode/Writer/ValueEnumerator.h - Number values --------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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/ADT/SmallVector.h"
19 #include "llvm/Attributes.h"
20 #include <vector>
22 namespace llvm {
24 class Type;
25 class Value;
26 class Instruction;
27 class BasicBlock;
28 class Function;
29 class Module;
30 class MDNode;
31 class NamedMDNode;
32 class AttrListPtr;
33 class ValueSymbolTable;
34 class MDSymbolTable;
36 class ValueEnumerator {
37 public:
38 typedef std::vector<const Type*> TypeList;
40 // For each value, we remember its Value* and occurrence frequency.
41 typedef std::vector<std::pair<const Value*, unsigned> > ValueList;
42 private:
43 typedef DenseMap<const Type*, unsigned> TypeMapType;
44 TypeMapType TypeMap;
45 TypeList Types;
47 typedef DenseMap<const Value*, unsigned> ValueMapType;
48 ValueMapType ValueMap;
49 ValueList Values;
50 ValueList MDValues;
51 SmallVector<const MDNode *, 8> FunctionLocalMDs;
52 ValueMapType MDValueMap;
54 typedef DenseMap<void*, unsigned> AttributeMapType;
55 AttributeMapType AttributeMap;
56 std::vector<AttrListPtr> Attributes;
58 /// GlobalBasicBlockIDs - This map memoizes the basic block ID's referenced by
59 /// the "getGlobalBasicBlockID" method.
60 mutable DenseMap<const BasicBlock*, unsigned> GlobalBasicBlockIDs;
62 typedef DenseMap<const Instruction*, unsigned> InstructionMapType;
63 InstructionMapType InstructionMap;
64 unsigned InstructionCount;
66 /// BasicBlocks - This contains all the basic blocks for the currently
67 /// incorporated function. Their reverse mapping is stored in ValueMap.
68 std::vector<const BasicBlock*> BasicBlocks;
70 /// When a function is incorporated, this is the size of the Values list
71 /// before incorporation.
72 unsigned NumModuleValues;
74 /// When a function is incorporated, this is the size of the MDValues list
75 /// before incorporation.
76 unsigned NumModuleMDValues;
78 unsigned FirstFuncConstantID;
79 unsigned FirstInstID;
81 ValueEnumerator(const ValueEnumerator &); // DO NOT IMPLEMENT
82 void operator=(const ValueEnumerator &); // DO NOT IMPLEMENT
83 public:
84 ValueEnumerator(const Module *M);
86 unsigned getValueID(const Value *V) const;
88 unsigned getTypeID(const Type *T) const {
89 TypeMapType::const_iterator I = TypeMap.find(T);
90 assert(I != TypeMap.end() && "Type not in ValueEnumerator!");
91 return I->second-1;
94 unsigned getInstructionID(const Instruction *I) const;
95 void setInstructionID(const Instruction *I);
97 unsigned getAttributeID(const AttrListPtr &PAL) const {
98 if (PAL.isEmpty()) return 0; // Null maps to zero.
99 AttributeMapType::const_iterator I = AttributeMap.find(PAL.getRawPointer());
100 assert(I != AttributeMap.end() && "Attribute not in ValueEnumerator!");
101 return I->second;
104 /// getFunctionConstantRange - Return the range of values that corresponds to
105 /// function-local constants.
106 void getFunctionConstantRange(unsigned &Start, unsigned &End) const {
107 Start = FirstFuncConstantID;
108 End = FirstInstID;
111 const ValueList &getValues() const { return Values; }
112 const ValueList &getMDValues() const { return MDValues; }
113 const SmallVector<const MDNode *, 8> &getFunctionLocalMDValues() const {
114 return FunctionLocalMDs;
116 const TypeList &getTypes() const { return Types; }
117 const std::vector<const BasicBlock*> &getBasicBlocks() const {
118 return BasicBlocks;
120 const std::vector<AttrListPtr> &getAttributes() const {
121 return Attributes;
124 /// getGlobalBasicBlockID - This returns the function-specific ID for the
125 /// specified basic block. This is relatively expensive information, so it
126 /// should only be used by rare constructs such as address-of-label.
127 unsigned getGlobalBasicBlockID(const BasicBlock *BB) const;
129 /// incorporateFunction/purgeFunction - If you'd like to deal with a function,
130 /// use these two methods to get its data into the ValueEnumerator!
132 void incorporateFunction(const Function &F);
133 void purgeFunction();
135 private:
136 void OptimizeConstants(unsigned CstStart, unsigned CstEnd);
138 void EnumerateMDNodeOperands(const MDNode *N);
139 void EnumerateMetadata(const Value *MD);
140 void EnumerateFunctionLocalMetadata(const MDNode *N);
141 void EnumerateNamedMDNode(const NamedMDNode *NMD);
142 void EnumerateValue(const Value *V);
143 void EnumerateType(const Type *T);
144 void EnumerateOperandType(const Value *V);
145 void EnumerateAttributes(const AttrListPtr &PAL);
147 void EnumerateValueSymbolTable(const ValueSymbolTable &ST);
148 void EnumerateNamedMetadata(const Module *M);
151 } // End llvm namespace
153 #endif