Added LLVM copyright header (for lack of a better term).
[oota-llvm.git] / include / llvm / 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 class Value;
26 class Module;
27 class Function;
28 class SymbolTable;
29
30 class SlotCalculator {
31   const Module *TheModule;
32   bool IgnoreNamedNodes;     // Shall we not count named nodes?
33
34   typedef std::vector<const Value*> TypePlane;
35   std::vector<TypePlane> Table;
36   std::map<const Value *, unsigned> NodeMap;
37
38   // ModuleLevel - Used to keep track of which values belong to the module,
39   // and which values belong to the currently incorporated function.
40   //
41   std::vector<unsigned> ModuleLevel;
42
43 public:
44   SlotCalculator(const Module *M, bool IgnoreNamed);
45   // Start out in incorp state
46   SlotCalculator(const Function *M, bool IgnoreNamed);
47   inline ~SlotCalculator() {}
48   
49   // getSlot returns < 0 on error!
50   int getSlot(const Value *D) const;
51
52   inline unsigned getNumPlanes() const { return Table.size(); }
53   inline unsigned getModuleLevel(unsigned Plane) const { 
54     return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0; 
55   }
56
57   inline const TypePlane &getPlane(unsigned Plane) const { 
58     return Table[Plane]; 
59   }
60
61   // If you'd like to deal with a function, use these two methods to get its
62   // data into the SlotCalculator!
63   //
64   void incorporateFunction(const Function *F);
65   void purgeFunction();
66
67 protected:
68   // getOrCreateSlot - Values can be crammed into here at will... if
69   // they haven't been inserted already, they get inserted, otherwise
70   // they are ignored.
71   //
72   int getOrCreateSlot(const Value *D);
73
74   // insertValue - Insert a value into the value table... Return the
75   // slot that it occupies, or -1 if the declaration is to be ignored
76   // because of the IgnoreNamedNodes flag.
77   //
78   int insertValue(const Value *D, bool dontIgnore = false);
79
80   // doInsertValue - Small helper function to be called only be insertVal.
81   int doInsertValue(const Value *D);
82
83   // processModule - Process all of the module level function declarations and
84   // types that are available.
85   //
86   void processModule();
87
88   // processSymbolTable - Insert all of the values in the specified symbol table
89   // into the values table...
90   //
91   void processSymbolTable(const SymbolTable *ST);
92   void processSymbolTableConstants(const SymbolTable *ST);
93 };
94
95 #endif