1 //===-- Analysis/SlotCalculator.h - Calculate value slots -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
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.
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.
18 //===----------------------------------------------------------------------===//
20 #ifndef LLVM_ANALYSIS_SLOTCALCULATOR_H
21 #define LLVM_ANALYSIS_SLOTCALCULATOR_H
33 class TypeSymbolTable;
36 class SlotCalculator {
37 const Module *TheModule;
39 typedef std::vector<const Type*> TypeList;
40 typedef std::vector<const Value*> TypePlane;
41 std::vector<TypePlane> Table;
43 typedef std::map<const Value*, unsigned> NodeMapType;
46 typedef std::map<const Type*, unsigned> TypeMapType;
49 /// ConstantStrings - If we are indexing for a bytecode file, this keeps track
50 /// of all of the constants strings that need to be emitted.
51 std::vector<const ConstantArray*> ConstantStrings;
53 /// ModuleLevel - Used to keep track of which values belong to the module,
54 /// and which values belong to the currently incorporated function.
56 std::vector<unsigned> ModuleLevel;
57 unsigned ModuleTypeLevel;
59 /// ModuleContainsAllFunctionConstants - This flag is set to true if all
60 /// function constants are incorporated into the module constant table. This
61 /// is only possible if building information for a bytecode file.
62 bool ModuleContainsAllFunctionConstants;
64 SlotCalculator(const SlotCalculator &); // DO NOT IMPLEMENT
65 void operator=(const SlotCalculator &); // DO NOT IMPLEMENT
67 SlotCalculator(const Module *M);
68 // Start out in incorp state
69 SlotCalculator(const Function *F);
71 /// getSlot - Return the slot number of the specified value in it's type
72 /// plane. This returns < 0 on error!
74 int getSlot(const Value *V) const;
75 int getSlot(const Type* T) const;
77 inline unsigned getNumPlanes() const { return Table.size(); }
78 inline unsigned getNumTypes() const { return Types.size(); }
80 inline unsigned getModuleLevel(unsigned Plane) const {
81 return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0;
84 /// Returns the number of types in the type list that are at module level
85 inline unsigned getModuleTypeLevel() const {
86 return ModuleTypeLevel;
89 TypePlane &getPlane(unsigned Plane);
90 TypeList& getTypes() { return Types; }
92 /// incorporateFunction/purgeFunction - If you'd like to deal with a function,
93 /// use these two methods to get its data into the SlotCalculator!
95 void incorporateFunction(const Function *F);
98 /// string_iterator/string_begin/end - Access the list of module-level
99 /// constant strings that have been incorporated. This is only applicable to
101 typedef std::vector<const ConstantArray*>::const_iterator string_iterator;
102 string_iterator string_begin() const { return ConstantStrings.begin(); }
103 string_iterator string_end() const { return ConstantStrings.end(); }
106 // getOrCreateSlot - Values can be crammed into here at will... if
107 // they haven't been inserted already, they get inserted, otherwise
110 int getOrCreateSlot(const Value *V);
111 int getOrCreateSlot(const Type *T);
113 // insertValue - Insert a value into the value table... Return the
114 // slot that it occupies, or -1 if the declaration is to be ignored
115 // because of the IgnoreNamedNodes flag.
117 int insertValue(const Value *D, bool dontIgnore = false);
118 int insertType(const Type *T, bool dontIgnore = false);
120 // doInsertValue - Small helper function to be called only be insertVal.
121 int doInsertValue(const Value *V);
122 int doInsertType(const Type *T);
124 // processModule - Process all of the module level function declarations and
125 // types that are available.
127 void processModule();
129 // processSymbolTable - Insert all of the values in the specified symbol table
130 // into the values table...
132 void processTypeSymbolTable(const TypeSymbolTable *ST);
133 void processValueSymbolTable(const SymbolTable *ST);
134 void processSymbolTableConstants(const SymbolTable *ST);
136 // insertPrimitives - helper for constructors to insert primitive types.
137 void insertPrimitives();
140 } // End llvm namespace