Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1 | //===-- 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 Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 12 | #include "llvm/SymTabValue.h" |
| 13 | #include <vector> |
| 14 | #include <map> |
Chris Lattner | 644dc17 | 2001-07-14 06:08:51 +0000 | [diff] [blame] | 15 | class Value; |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 16 | class Module; |
| 17 | class Method; |
| 18 | class MethodArgument; |
| 19 | class BasicBlock; |
| 20 | class Instruction; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 21 | |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 22 | class SlotCalculator { |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 23 | const Module *TheModule; |
| 24 | bool IgnoreNamedNodes; // Shall we not count named nodes? |
| 25 | |
| 26 | typedef vector<const Value*> TypePlane; |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 27 | vector<TypePlane> Table; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 28 | 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 Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 33 | vector<unsigned> ModuleLevel; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 34 | |
| 35 | public: |
| 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 | |
| 58 | protected: |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 59 | // 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 Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 62 | // |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 63 | int insertVal(const Value *D, bool dontIgnore = false); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 64 | |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 65 | // 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 Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 67 | // |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 68 | int insertValue(const Value *D); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 69 | |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 70 | // doInsertVal - Small helper function to be called only be insertVal. |
| 71 | int doInsertVal(const Value *D); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 72 | |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 73 | // processModule - Process all of the module level method declarations and |
| 74 | // types that are available. |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 75 | // |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 76 | void processModule(); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 77 | |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 78 | // processSymbolTable - Insert all of the values in the specified symbol table |
| 79 | // into the values table... |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 80 | // |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 81 | void processSymbolTable(const SymbolTable *ST); |
| 82 | void processSymbolTableConstants(const SymbolTable *ST); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | #endif |