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 std::vector<const Value*> TypePlane;
27 std::vector<TypePlane> Table;
28 std::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 std::vector<unsigned> ModuleLevel;
36 SlotCalculator(const Module *M, bool IgnoreNamed);
37 // Start out in incorp state
38 SlotCalculator(const Function *M, bool IgnoreNamed);
39 inline ~SlotCalculator() {}
41 // getValSlot returns < 0 on error!
42 int getValSlot(const Value *D) const;
44 inline unsigned getNumPlanes() const { return Table.size(); }
45 inline unsigned getModuleLevel(unsigned Plane) const {
46 return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0;
49 inline const TypePlane &getPlane(unsigned Plane) const {
53 // If you'd like to deal with a method, use these two methods to get its data
54 // into the SlotCalculator!
56 void incorporateMethod(const Function *F);
60 // insertVal - Insert a value into the value table... Return the slot that it
61 // occupies, or -1 if the declaration is to be ignored because of the
62 // IgnoreNamedNodes flag.
64 int insertVal(const Value *D, bool dontIgnore = false);
66 // insertValue - Values can be crammed into here at will... if they haven't
67 // been inserted already, they get inserted, otherwise they are ignored.
69 int insertValue(const Value *D);
71 // doInsertVal - Small helper function to be called only be insertVal.
72 int doInsertVal(const Value *D);
74 // processModule - Process all of the module level method declarations and
75 // types that are available.
79 // processSymbolTable - Insert all of the values in the specified symbol table
80 // into the values table...
82 void processSymbolTable(const SymbolTable *ST);
83 void processSymbolTableConstants(const SymbolTable *ST);