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