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/Analysis/ModuleAnalyzer.h"
13 #include "llvm/SymTabValue.h"
17 class SlotCalculator : public ModuleAnalyzer {
18 const Module *TheModule;
19 bool IgnoreNamedNodes; // Shall we not count named nodes?
21 typedef vector<const Value*> TypePlane;
22 vector <TypePlane> Table;
23 map<const Value *, unsigned> NodeMap;
25 // ModuleLevel - Used to keep track of which values belong to the module,
26 // and which values belong to the currently incorporated method.
28 vector <unsigned> ModuleLevel;
31 SlotCalculator(const Module *M, bool IgnoreNamed);
32 SlotCalculator(const Method *M, bool IgnoreNamed);// Start out in incorp state
33 inline ~SlotCalculator() {}
35 // getValSlot returns < 0 on error!
36 int getValSlot(const Value *D) const;
38 inline unsigned getNumPlanes() const { return Table.size(); }
39 inline unsigned getModuleLevel(unsigned Plane) const {
40 return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0;
43 inline const TypePlane &getPlane(unsigned Plane) const {
47 // If you'd like to deal with a method, use these two methods to get its data
48 // into the SlotCalculator!
50 void incorporateMethod(const Method *M);
54 // insertVal - Insert a value into the value table...
56 void insertVal(const Value *D);
58 // visitMethod - This member is called after the constant pool has been
59 // processed. The default implementation of this is a noop.
61 virtual bool visitMethod(const Method *M);
63 // processConstant is called once per each constant in the constant pool. It
64 // traverses the constant pool such that it visits each constant in the
65 // order of its type. Thus, all 'int' typed constants shall be visited
66 // sequentially, etc...
68 virtual bool processConstant(const ConstPoolVal *CPV);
70 // processType - This callback occurs when an derived type is discovered
71 // at the class level. This activity occurs when processing a constant pool.
73 virtual bool processType(const Type *Ty);
75 // processMethods - The default implementation of this method loops through
76 // all of the methods in the module and processModule's them. We don't want
77 // this (we want to explicitly visit them with incorporateMethod), so we
80 virtual bool processMethods(const Module *M) { return false; }
82 // processMethodArgument - This member is called for every argument that
83 // is passed into the method.
85 virtual bool processMethodArgument(const MethodArgument *MA);
87 // processBasicBlock - This member is called for each basic block in a methd.
89 virtual bool processBasicBlock(const BasicBlock *BB);
91 // processInstruction - This member is called for each Instruction in a methd.
93 virtual bool processInstruction(const Instruction *I);