blob: c7b3149054c3efabe7e268ecf13846ea50c670dd [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
Chris Lattner00950542001-06-06 20:29:01 +000012#include "llvm/SymTabValue.h"
13#include <vector>
14#include <map>
Chris Lattner644dc172001-07-14 06:08:51 +000015class Value;
Chris Lattner4c4007b2001-09-07 16:27:05 +000016class Module;
17class Method;
18class MethodArgument;
19class BasicBlock;
20class Instruction;
Chris Lattner00950542001-06-06 20:29:01 +000021
Chris Lattner4c4007b2001-09-07 16:27:05 +000022class SlotCalculator {
Chris Lattner00950542001-06-06 20:29:01 +000023 const Module *TheModule;
24 bool IgnoreNamedNodes; // Shall we not count named nodes?
25
26 typedef vector<const Value*> TypePlane;
Chris Lattner4c4007b2001-09-07 16:27:05 +000027 vector<TypePlane> Table;
Chris Lattner00950542001-06-06 20:29:01 +000028 map<const Value *, unsigned> NodeMap;
29
30 // ModuleLevel - Used to keep track of which values belong to the module,
31 // and which values belong to the currently incorporated method.
32 //
Chris Lattner4c4007b2001-09-07 16:27:05 +000033 vector<unsigned> ModuleLevel;
Chris Lattner00950542001-06-06 20:29:01 +000034
35public:
36 SlotCalculator(const Module *M, bool IgnoreNamed);
37 SlotCalculator(const Method *M, bool IgnoreNamed);// Start out in incorp state
38 inline ~SlotCalculator() {}
39
40 // getValSlot returns < 0 on error!
41 int getValSlot(const Value *D) const;
42
43 inline unsigned getNumPlanes() const { return Table.size(); }
44 inline unsigned getModuleLevel(unsigned Plane) const {
45 return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0;
46 }
47
48 inline const TypePlane &getPlane(unsigned Plane) const {
49 return Table[Plane];
50 }
51
52 // If you'd like to deal with a method, use these two methods to get its data
53 // into the SlotCalculator!
54 //
55 void incorporateMethod(const Method *M);
56 void purgeMethod();
57
58protected:
Chris Lattner4c4007b2001-09-07 16:27:05 +000059 // insertVal - Insert a value into the value table... Return the slot that it
60 // occupies, or -1 if the declaration is to be ignored because of the
61 // IgnoreNamedNodes flag.
Chris Lattner00950542001-06-06 20:29:01 +000062 //
Chris Lattner4c4007b2001-09-07 16:27:05 +000063 int insertVal(const Value *D, bool dontIgnore = false);
Chris Lattner00950542001-06-06 20:29:01 +000064
Chris Lattner4c4007b2001-09-07 16:27:05 +000065 // insertValue - Values can be crammed into here at will... if they haven't
66 // been inserted already, they get inserted, otherwise they are ignored.
Chris Lattner00950542001-06-06 20:29:01 +000067 //
Chris Lattner4c4007b2001-09-07 16:27:05 +000068 int insertValue(const Value *D);
Chris Lattner00950542001-06-06 20:29:01 +000069
Chris Lattner4c4007b2001-09-07 16:27:05 +000070 // doInsertVal - Small helper function to be called only be insertVal.
71 int doInsertVal(const Value *D);
Chris Lattner00950542001-06-06 20:29:01 +000072
Chris Lattner4c4007b2001-09-07 16:27:05 +000073 // processModule - Process all of the module level method declarations and
74 // types that are available.
Chris Lattner00950542001-06-06 20:29:01 +000075 //
Chris Lattner4c4007b2001-09-07 16:27:05 +000076 void processModule();
Chris Lattner00950542001-06-06 20:29:01 +000077
Chris Lattner4c4007b2001-09-07 16:27:05 +000078 // processSymbolTable - Insert all of the values in the specified symbol table
79 // into the values table...
Chris Lattner00950542001-06-06 20:29:01 +000080 //
Chris Lattner4c4007b2001-09-07 16:27:05 +000081 void processSymbolTable(const SymbolTable *ST);
82 void processSymbolTableConstants(const SymbolTable *ST);
Chris Lattner00950542001-06-06 20:29:01 +000083};
84
85#endif