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"
18 class SlotCalculator : public ModuleAnalyzer {
19 const Module *TheModule;
20 bool IgnoreNamedNodes; // Shall we not count named nodes?
22 typedef vector<const Value*> TypePlane;
23 vector <TypePlane> Table;
24 map<const Value *, unsigned> NodeMap;
26 // ModuleLevel - Used to keep track of which values belong to the module,
27 // and which values belong to the currently incorporated method.
29 vector <unsigned> ModuleLevel;
32 SlotCalculator(const Module *M, bool IgnoreNamed);
33 SlotCalculator(const Method *M, bool IgnoreNamed);// Start out in incorp state
34 inline ~SlotCalculator() {}
36 // getValSlot returns < 0 on error!
37 int getValSlot(const Value *D) const;
39 inline unsigned getNumPlanes() const { return Table.size(); }
40 inline unsigned getModuleLevel(unsigned Plane) const {
41 return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0;
44 inline const TypePlane &getPlane(unsigned Plane) const {
48 // If you'd like to deal with a method, use these two methods to get its data
49 // into the SlotCalculator!
51 void incorporateMethod(const Method *M);
55 // insertVal - Insert a value into the value table...
57 void insertVal(const Value *D);
59 // visitMethod - This member is called after the constant pool has been
60 // processed. The default implementation of this is a noop.
62 virtual bool visitMethod(const Method *M);
64 // processConstant is called once per each constant in the constant pool. It
65 // traverses the constant pool such that it visits each constant in the
66 // order of its type. Thus, all 'int' typed constants shall be visited
67 // sequentially, etc...
69 virtual bool processConstant(const ConstPoolVal *CPV);
71 // processType - This callback occurs when an derived type is discovered
72 // at the class level. This activity occurs when processing a constant pool.
74 virtual bool processType(const Type *Ty);
76 // processMethods - The default implementation of this method loops through
77 // all of the methods in the module and processModule's them. We don't want
78 // this (we want to explicitly visit them with incorporateMethod), so we
81 virtual bool processMethods(const Module *M) { return false; }
83 // processMethodArgument - This member is called for every argument that
84 // is passed into the method.
86 virtual bool processMethodArgument(const MethodArgument *MA);
88 // processBasicBlock - This member is called for each basic block in a methd.
90 virtual bool processBasicBlock(const BasicBlock *BB);
92 // processInstruction - This member is called for each Instruction in a methd.
94 virtual bool processInstruction(const Instruction *I);