blob: 3228ce260ff99c4894ccd52974920fb7d7d91618 [file] [log] [blame]
Chris Lattner48486892003-09-30 18:37:50 +00001//===-- llvm/SlotCalculator.h - Calculate value slots -----------*- C++ -*-===//
Chris Lattner00950542001-06-06 20:29:01 +00002//
Chris Lattnerb5794002002-04-07 22:49:37 +00003// This class calculates the slots that values will land in. This is useful for
4// when writing bytecode or assembly out, because you have to know these things.
5//
6// Specifically, this class calculates the "type plane numbering" that you see
7// for a function if you strip out all of the symbols in it. For assembly
8// writing, this is used when a symbol does not have a name. For bytecode
9// writing, this is always used, and the symbol table is added on later.
Chris Lattner00950542001-06-06 20:29:01 +000010//
11//===----------------------------------------------------------------------===//
12
Chris Lattnerb5794002002-04-07 22:49:37 +000013#ifndef LLVM_SLOTCALCULATOR_H
14#define LLVM_SLOTCALCULATOR_H
Chris Lattner00950542001-06-06 20:29:01 +000015
Chris Lattner00950542001-06-06 20:29:01 +000016#include <vector>
17#include <map>
Chris Lattner644dc172001-07-14 06:08:51 +000018class Value;
Chris Lattner4c4007b2001-09-07 16:27:05 +000019class Module;
Chris Lattnere7506a32002-03-23 22:51:58 +000020class Function;
Chris Lattner184b2fa2002-04-09 18:35:38 +000021class SymbolTable;
Chris Lattner00950542001-06-06 20:29:01 +000022
Chris Lattner4c4007b2001-09-07 16:27:05 +000023class SlotCalculator {
Chris Lattner00950542001-06-06 20:29:01 +000024 const Module *TheModule;
25 bool IgnoreNamedNodes; // Shall we not count named nodes?
26
Chris Lattner697954c2002-01-20 22:54:45 +000027 typedef std::vector<const Value*> TypePlane;
28 std::vector<TypePlane> Table;
29 std::map<const Value *, unsigned> NodeMap;
Chris Lattner00950542001-06-06 20:29:01 +000030
31 // ModuleLevel - Used to keep track of which values belong to the module,
Chris Lattnerb5794002002-04-07 22:49:37 +000032 // and which values belong to the currently incorporated function.
Chris Lattner00950542001-06-06 20:29:01 +000033 //
Chris Lattner697954c2002-01-20 22:54:45 +000034 std::vector<unsigned> ModuleLevel;
Chris Lattner00950542001-06-06 20:29:01 +000035
36public:
37 SlotCalculator(const Module *M, bool IgnoreNamed);
Chris Lattnere7506a32002-03-23 22:51:58 +000038 // Start out in incorp state
39 SlotCalculator(const Function *M, bool IgnoreNamed);
Chris Lattner00950542001-06-06 20:29:01 +000040 inline ~SlotCalculator() {}
41
Alkis Evlogimenos60596382003-10-17 02:02:40 +000042 // getSlot returns < 0 on error!
43 int getSlot(const Value *D) const;
Chris Lattner00950542001-06-06 20:29:01 +000044
45 inline unsigned getNumPlanes() const { return Table.size(); }
46 inline unsigned getModuleLevel(unsigned Plane) const {
47 return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0;
48 }
49
50 inline const TypePlane &getPlane(unsigned Plane) const {
51 return Table[Plane];
52 }
53
Chris Lattnerb5794002002-04-07 22:49:37 +000054 // If you'd like to deal with a function, use these two methods to get its
55 // data into the SlotCalculator!
Chris Lattner00950542001-06-06 20:29:01 +000056 //
Chris Lattnerb5794002002-04-07 22:49:37 +000057 void incorporateFunction(const Function *F);
58 void purgeFunction();
Chris Lattner00950542001-06-06 20:29:01 +000059
60protected:
Alkis Evlogimenos60596382003-10-17 02:02:40 +000061 // getOrCreateSlot - Values can be crammed into here at will... if
62 // they haven't been inserted already, they get inserted, otherwise
63 // they are ignored.
Chris Lattner00950542001-06-06 20:29:01 +000064 //
Alkis Evlogimenos60596382003-10-17 02:02:40 +000065 int getOrCreateSlot(const Value *D);
Chris Lattner00950542001-06-06 20:29:01 +000066
Alkis Evlogimenos60596382003-10-17 02:02:40 +000067 // insertValue - Insert a value into the value table... Return the
68 // slot that it occupies, or -1 if the declaration is to be ignored
69 // because of the IgnoreNamedNodes flag.
Chris Lattner00950542001-06-06 20:29:01 +000070 //
Alkis Evlogimenos60596382003-10-17 02:02:40 +000071 int insertValue(const Value *D, bool dontIgnore = false);
Chris Lattner00950542001-06-06 20:29:01 +000072
Alkis Evlogimenos60596382003-10-17 02:02:40 +000073 // doInsertValue - Small helper function to be called only be insertVal.
74 int doInsertValue(const Value *D);
Chris Lattner00950542001-06-06 20:29:01 +000075
Chris Lattnerb5794002002-04-07 22:49:37 +000076 // processModule - Process all of the module level function declarations and
Chris Lattner4c4007b2001-09-07 16:27:05 +000077 // types that are available.
Chris Lattner00950542001-06-06 20:29:01 +000078 //
Chris Lattner4c4007b2001-09-07 16:27:05 +000079 void processModule();
Chris Lattner00950542001-06-06 20:29:01 +000080
Chris Lattner4c4007b2001-09-07 16:27:05 +000081 // processSymbolTable - Insert all of the values in the specified symbol table
82 // into the values table...
Chris Lattner00950542001-06-06 20:29:01 +000083 //
Chris Lattner4c4007b2001-09-07 16:27:05 +000084 void processSymbolTable(const SymbolTable *ST);
85 void processSymbolTableConstants(const SymbolTable *ST);
Chris Lattner00950542001-06-06 20:29:01 +000086};
87
88#endif