The only clients of the slot calculator are now the asmwriter and bcwriter.
[oota-llvm.git] / include / llvm / Analysis / SlotCalculator.h
1 //===-- llvm/SlotCalculator.h - Calculate value slots -----------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This class calculates the slots that values will land in.  This is useful for
11 // when writing bytecode or assembly out, because you have to know these things.
12 //
13 // Specifically, this class calculates the "type plane numbering" that you see
14 // for a function if you strip out all of the symbols in it.  For assembly
15 // writing, this is used when a symbol does not have a name.  For bytecode
16 // writing, this is always used, and the symbol table is added on later.
17 //
18 //===----------------------------------------------------------------------===//
19
20 #ifndef LLVM_SLOTCALCULATOR_H
21 #define LLVM_SLOTCALCULATOR_H
22
23 #include <vector>
24 #include <map>
25
26 namespace llvm {
27
28 class Value;
29 class Module;
30 class Function;
31 class SymbolTable;
32
33 class SlotCalculator {
34   const Module *TheModule;
35
36   // BuildBytecodeInfo - If true, this is the creating information for the
37   // bytecode writer, if false, we are building information for the assembly
38   // emitter.  The assembly emitter doesn't need named objects numbered, among
39   // other differences.
40   bool BuildBytecodeInfo;
41
42   typedef std::vector<const Value*> TypePlane;
43   std::vector<TypePlane> Table;
44   std::map<const Value *, unsigned> NodeMap;
45
46   // ModuleLevel - Used to keep track of which values belong to the module,
47   // and which values belong to the currently incorporated function.
48   //
49   std::vector<unsigned> ModuleLevel;
50
51 public:
52   SlotCalculator(const Module *M, bool BuildBytecodeInfo);
53   // Start out in incorp state
54   SlotCalculator(const Function *M, bool BuildBytecodeInfo);
55   inline ~SlotCalculator() {}
56   
57   // getSlot returns < 0 on error!
58   int getSlot(const Value *D) const;
59
60   inline unsigned getNumPlanes() const { return Table.size(); }
61   inline unsigned getModuleLevel(unsigned Plane) const { 
62     return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0; 
63   }
64
65   inline const TypePlane &getPlane(unsigned Plane) const { 
66     return Table[Plane]; 
67   }
68
69   // If you'd like to deal with a function, use these two methods to get its
70   // data into the SlotCalculator!
71   //
72   void incorporateFunction(const Function *F);
73   void purgeFunction();
74
75 protected:
76   // getOrCreateSlot - Values can be crammed into here at will... if
77   // they haven't been inserted already, they get inserted, otherwise
78   // they are ignored.
79   //
80   int getOrCreateSlot(const Value *D);
81
82   // insertValue - Insert a value into the value table... Return the
83   // slot that it occupies, or -1 if the declaration is to be ignored
84   // because of the IgnoreNamedNodes flag.
85   //
86   int insertValue(const Value *D, bool dontIgnore = false);
87
88   // doInsertValue - Small helper function to be called only be insertVal.
89   int doInsertValue(const Value *D);
90
91   // processModule - Process all of the module level function declarations and
92   // types that are available.
93   //
94   void processModule();
95
96   // processSymbolTable - Insert all of the values in the specified symbol table
97   // into the values table...
98   //
99   void processSymbolTable(const SymbolTable *ST);
100   void processSymbolTableConstants(const SymbolTable *ST);
101 };
102
103 } // End llvm namespace
104
105 #endif