blob: 99e40cbeb5fe6ec19b09852fc670bdb707acadef [file] [log] [blame]
Chris Lattner00950542001-06-06 20:29:01 +00001//===-- llvm/Analysis/SlotCalculator.h - Calculate value slots ---*- C++ -*-==//
2//
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.
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_ANALYSIS_SLOTCALCULATOR_H
10#define LLVM_ANALYSIS_SLOTCALCULATOR_H
11
12#include "llvm/Analysis/ModuleAnalyzer.h"
13#include "llvm/SymTabValue.h"
14#include <vector>
15#include <map>
16
17class SlotCalculator : public ModuleAnalyzer {
18 const Module *TheModule;
19 bool IgnoreNamedNodes; // Shall we not count named nodes?
20
21 typedef vector<const Value*> TypePlane;
22 vector <TypePlane> Table;
23 map<const Value *, unsigned> NodeMap;
24
25 // ModuleLevel - Used to keep track of which values belong to the module,
26 // and which values belong to the currently incorporated method.
27 //
28 vector <unsigned> ModuleLevel;
29
30public:
31 SlotCalculator(const Module *M, bool IgnoreNamed);
32 SlotCalculator(const Method *M, bool IgnoreNamed);// Start out in incorp state
33 inline ~SlotCalculator() {}
34
35 // getValSlot returns < 0 on error!
36 int getValSlot(const Value *D) const;
37
38 inline unsigned getNumPlanes() const { return Table.size(); }
39 inline unsigned getModuleLevel(unsigned Plane) const {
40 return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0;
41 }
42
43 inline const TypePlane &getPlane(unsigned Plane) const {
44 return Table[Plane];
45 }
46
47 // If you'd like to deal with a method, use these two methods to get its data
48 // into the SlotCalculator!
49 //
50 void incorporateMethod(const Method *M);
51 void purgeMethod();
52
53protected:
54 // insertVal - Insert a value into the value table...
55 //
56 void insertVal(const Value *D);
57
58 // visitMethod - This member is called after the constant pool has been
59 // processed. The default implementation of this is a noop.
60 //
61 virtual bool visitMethod(const Method *M);
62
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...
67 //
68 virtual bool processConstant(const ConstPoolVal *CPV);
69
70 // processType - This callback occurs when an derived type is discovered
71 // at the class level. This activity occurs when processing a constant pool.
72 //
73 virtual bool processType(const Type *Ty);
74
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
78 // disable it.
79 //
80 virtual bool processMethods(const Module *M) { return false; }
81
82 // processMethodArgument - This member is called for every argument that
83 // is passed into the method.
84 //
85 virtual bool processMethodArgument(const MethodArgument *MA);
86
87 // processBasicBlock - This member is called for each basic block in a methd.
88 //
89 virtual bool processBasicBlock(const BasicBlock *BB);
90
91 // processInstruction - This member is called for each Instruction in a methd.
92 //
93 virtual bool processInstruction(const Instruction *I);
94};
95
96#endif