blob: 9d5d2240afbfe99ccb2c5d145e2376006496f1bb [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;
Chris Lattnere7506a32002-03-23 22:51:58 +000017class Function;
Chris Lattner00950542001-06-06 20:29:01 +000018
Chris Lattner4c4007b2001-09-07 16:27:05 +000019class SlotCalculator {
Chris Lattner00950542001-06-06 20:29:01 +000020 const Module *TheModule;
21 bool IgnoreNamedNodes; // Shall we not count named nodes?
22
Chris Lattner697954c2002-01-20 22:54:45 +000023 typedef std::vector<const Value*> TypePlane;
24 std::vector<TypePlane> Table;
25 std::map<const Value *, unsigned> NodeMap;
Chris Lattner00950542001-06-06 20:29:01 +000026
27 // ModuleLevel - Used to keep track of which values belong to the module,
28 // and which values belong to the currently incorporated method.
29 //
Chris Lattner697954c2002-01-20 22:54:45 +000030 std::vector<unsigned> ModuleLevel;
Chris Lattner00950542001-06-06 20:29:01 +000031
32public:
33 SlotCalculator(const Module *M, bool IgnoreNamed);
Chris Lattnere7506a32002-03-23 22:51:58 +000034 // Start out in incorp state
35 SlotCalculator(const Function *M, bool IgnoreNamed);
Chris Lattner00950542001-06-06 20:29:01 +000036 inline ~SlotCalculator() {}
37
38 // getValSlot returns < 0 on error!
39 int getValSlot(const Value *D) const;
40
41 inline unsigned getNumPlanes() const { return Table.size(); }
42 inline unsigned getModuleLevel(unsigned Plane) const {
43 return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0;
44 }
45
46 inline const TypePlane &getPlane(unsigned Plane) const {
47 return Table[Plane];
48 }
49
50 // If you'd like to deal with a method, use these two methods to get its data
51 // into the SlotCalculator!
52 //
Chris Lattnere7506a32002-03-23 22:51:58 +000053 void incorporateMethod(const Function *F);
Chris Lattner00950542001-06-06 20:29:01 +000054 void purgeMethod();
55
56protected:
Chris Lattner4c4007b2001-09-07 16:27:05 +000057 // insertVal - Insert a value into the value table... Return the slot that it
58 // occupies, or -1 if the declaration is to be ignored because of the
59 // IgnoreNamedNodes flag.
Chris Lattner00950542001-06-06 20:29:01 +000060 //
Chris Lattner4c4007b2001-09-07 16:27:05 +000061 int insertVal(const Value *D, bool dontIgnore = false);
Chris Lattner00950542001-06-06 20:29:01 +000062
Chris Lattner4c4007b2001-09-07 16:27:05 +000063 // insertValue - Values can be crammed into here at will... if they haven't
64 // been inserted already, they get inserted, otherwise they are ignored.
Chris Lattner00950542001-06-06 20:29:01 +000065 //
Chris Lattner4c4007b2001-09-07 16:27:05 +000066 int insertValue(const Value *D);
Chris Lattner00950542001-06-06 20:29:01 +000067
Chris Lattner4c4007b2001-09-07 16:27:05 +000068 // doInsertVal - Small helper function to be called only be insertVal.
69 int doInsertVal(const Value *D);
Chris Lattner00950542001-06-06 20:29:01 +000070
Chris Lattner4c4007b2001-09-07 16:27:05 +000071 // processModule - Process all of the module level method declarations and
72 // types that are available.
Chris Lattner00950542001-06-06 20:29:01 +000073 //
Chris Lattner4c4007b2001-09-07 16:27:05 +000074 void processModule();
Chris Lattner00950542001-06-06 20:29:01 +000075
Chris Lattner4c4007b2001-09-07 16:27:05 +000076 // processSymbolTable - Insert all of the values in the specified symbol table
77 // into the values table...
Chris Lattner00950542001-06-06 20:29:01 +000078 //
Chris Lattner4c4007b2001-09-07 16:27:05 +000079 void processSymbolTable(const SymbolTable *ST);
80 void processSymbolTableConstants(const SymbolTable *ST);
Chris Lattner00950542001-06-06 20:29:01 +000081};
82
83#endif