Chris Lattner | c1d10d6 | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 1 | //===-- Bitcode/Writer/ValueEnumerator.h - Number values --------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 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. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This class gives values and types Unique ID's. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef VALUE_ENUMERATOR_H |
| 15 | #define VALUE_ENUMERATOR_H |
| 16 | |
| 17 | #include "llvm/ADT/DenseMap.h" |
| 18 | #include <vector> |
| 19 | |
| 20 | namespace llvm { |
| 21 | |
| 22 | class Value; |
| 23 | class Type; |
| 24 | class Module; |
| 25 | class Function; |
| 26 | class TypeSymbolTable; |
| 27 | class ValueSymbolTable; |
| 28 | class ConstantArray; |
| 29 | |
| 30 | class ValueEnumerator { |
| 31 | public: |
| 32 | // For each type, we remember its Type* and occurrence frequency. |
| 33 | typedef std::vector<std::pair<const Type*, unsigned> > TypeList; |
| 34 | |
| 35 | // For each value, we remember its Value* and occurrence frequency. |
| 36 | typedef std::vector<std::pair<const Value*, unsigned> > ValueList; |
| 37 | private: |
Chris Lattner | c1d10d6 | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 38 | typedef DenseMap<const Type*, unsigned> TypeMapType; |
| 39 | TypeMapType TypeMap; |
Chris Lattner | 5252356 | 2007-04-24 00:16:04 +0000 | [diff] [blame] | 40 | TypeList Types; |
Chris Lattner | c1d10d6 | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 41 | |
Chris Lattner | c1d10d6 | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 42 | typedef DenseMap<const Value*, unsigned> ValueMapType; |
| 43 | ValueMapType ValueMap; |
Chris Lattner | 5252356 | 2007-04-24 00:16:04 +0000 | [diff] [blame] | 44 | ValueList Values; |
Chris Lattner | c1d10d6 | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 45 | |
| 46 | |
| 47 | ValueEnumerator(const ValueEnumerator &); // DO NOT IMPLEMENT |
| 48 | void operator=(const ValueEnumerator &); // DO NOT IMPLEMENT |
| 49 | public: |
| 50 | ValueEnumerator(const Module *M); |
| 51 | |
| 52 | unsigned getValueID(const Value *V) const { |
| 53 | ValueMapType::const_iterator I = ValueMap.find(V); |
| 54 | assert(I != ValueMap.end() && "Value not in slotcalculator!"); |
Chris Lattner | 1e93f5b | 2007-04-23 21:23:41 +0000 | [diff] [blame] | 55 | return I->second-1; |
Chris Lattner | c1d10d6 | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | unsigned getTypeID(const Type *T) const { |
| 59 | TypeMapType::const_iterator I = TypeMap.find(T); |
| 60 | assert(I != TypeMap.end() && "Type not in ValueEnumerator!"); |
| 61 | return I->second-1; |
| 62 | } |
| 63 | |
Chris Lattner | 5252356 | 2007-04-24 00:16:04 +0000 | [diff] [blame] | 64 | const ValueList &getValues() const { return Values; } |
Chris Lattner | c1d10d6 | 2007-04-22 06:24:45 +0000 | [diff] [blame] | 65 | const TypeList &getTypes() const { return Types; } |
| 66 | |
| 67 | /// incorporateFunction/purgeFunction - If you'd like to deal with a function, |
| 68 | /// use these two methods to get its data into the ValueEnumerator! |
| 69 | /// |
| 70 | void incorporateFunction(const Function *F); |
| 71 | void purgeFunction(); |
| 72 | |
| 73 | private: |
| 74 | void EnumerateValue(const Value *V); |
| 75 | void EnumerateType(const Type *T); |
| 76 | |
| 77 | void EnumerateTypeSymbolTable(const TypeSymbolTable &ST); |
| 78 | void EnumerateValueSymbolTable(const ValueSymbolTable &ST); |
| 79 | }; |
| 80 | |
| 81 | } // End llvm namespace |
| 82 | |
| 83 | #endif |