1 //===-- llvm/SlotCalculator.h - Calculate value slots ------------*- C++ -*-==//
3 // This class calculates the slots that values will land in. This is useful for
4 // when writing bytecode or assembly out, because you have to know these things.
6 // Specifically, this class calculates the "type plane numbering" that you see
7 // for a function if you strip out all of the symbols in it. For assembly
8 // writing, this is used when a symbol does not have a name. For bytecode
9 // writing, this is always used, and the symbol table is added on later.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_SLOTCALCULATOR_H
14 #define LLVM_SLOTCALCULATOR_H
23 class SlotCalculator {
24 const Module *TheModule;
25 bool IgnoreNamedNodes; // Shall we not count named nodes?
27 typedef std::vector<const Value*> TypePlane;
28 std::vector<TypePlane> Table;
29 std::map<const Value *, unsigned> NodeMap;
31 // ModuleLevel - Used to keep track of which values belong to the module,
32 // and which values belong to the currently incorporated function.
34 std::vector<unsigned> ModuleLevel;
37 SlotCalculator(const Module *M, bool IgnoreNamed);
38 // Start out in incorp state
39 SlotCalculator(const Function *M, bool IgnoreNamed);
40 inline ~SlotCalculator() {}
42 // getValSlot returns < 0 on error!
43 int getValSlot(const Value *D) const;
45 inline unsigned getNumPlanes() const { return Table.size(); }
46 inline unsigned getModuleLevel(unsigned Plane) const {
47 return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0;
50 inline const TypePlane &getPlane(unsigned Plane) const {
54 // If you'd like to deal with a function, use these two methods to get its
55 // data into the SlotCalculator!
57 void incorporateFunction(const Function *F);
61 // insertVal - Insert a value into the value table... Return the slot that it
62 // occupies, or -1 if the declaration is to be ignored because of the
63 // IgnoreNamedNodes flag.
65 int insertVal(const Value *D, bool dontIgnore = false);
67 // insertValue - Values can be crammed into here at will... if they haven't
68 // been inserted already, they get inserted, otherwise they are ignored.
70 int insertValue(const Value *D);
72 // doInsertVal - Small helper function to be called only be insertVal.
73 int doInsertVal(const Value *D);
75 // processModule - Process all of the module level function declarations and
76 // types that are available.
80 // processSymbolTable - Insert all of the values in the specified symbol table
81 // into the values table...
83 void processSymbolTable(const SymbolTable *ST);
84 void processSymbolTableConstants(const SymbolTable *ST);