1 //===-- llvm/Analysis/SlotCalculator.h - Calculate value slots ---*- C++ -*-==//
3 // This ModuleAnalyzer subclass calculates the slots that values will land in.
4 // This is useful for when writing bytecode or assembly out, because you have
5 // to know these things.
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_ANALYSIS_SLOTCALCULATOR_H
10 #define LLVM_ANALYSIS_SLOTCALCULATOR_H
12 #include "llvm/SymTabValue.h"
22 class SlotCalculator {
23 const Module *TheModule;
24 bool IgnoreNamedNodes; // Shall we not count named nodes?
26 typedef vector<const Value*> TypePlane;
27 vector<TypePlane> Table;
28 map<const Value *, unsigned> NodeMap;
30 // ModuleLevel - Used to keep track of which values belong to the module,
31 // and which values belong to the currently incorporated method.
33 vector<unsigned> ModuleLevel;
36 SlotCalculator(const Module *M, bool IgnoreNamed);
37 SlotCalculator(const Method *M, bool IgnoreNamed);// Start out in incorp state
38 inline ~SlotCalculator() {}
40 // getValSlot returns < 0 on error!
41 int getValSlot(const Value *D) const;
43 inline unsigned getNumPlanes() const { return Table.size(); }
44 inline unsigned getModuleLevel(unsigned Plane) const {
45 return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0;
48 inline const TypePlane &getPlane(unsigned Plane) const {
52 // If you'd like to deal with a method, use these two methods to get its data
53 // into the SlotCalculator!
55 void incorporateMethod(const Method *M);
59 // insertVal - Insert a value into the value table... Return the slot that it
60 // occupies, or -1 if the declaration is to be ignored because of the
61 // IgnoreNamedNodes flag.
63 int insertVal(const Value *D, bool dontIgnore = false);
65 // insertValue - Values can be crammed into here at will... if they haven't
66 // been inserted already, they get inserted, otherwise they are ignored.
68 int insertValue(const Value *D);
70 // doInsertVal - Small helper function to be called only be insertVal.
71 int doInsertVal(const Value *D);
73 // processModule - Process all of the module level method declarations and
74 // types that are available.
78 // processSymbolTable - Insert all of the values in the specified symbol table
79 // into the values table...
81 void processSymbolTable(const SymbolTable *ST);
82 void processSymbolTableConstants(const SymbolTable *ST);