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; |
Chris Lattner | e7506a3 | 2002-03-23 22:51:58 +0000 | [diff] [blame] | 17 | class Function; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 18 | |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 19 | class SlotCalculator { |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 20 | const Module *TheModule; |
| 21 | bool IgnoreNamedNodes; // Shall we not count named nodes? |
| 22 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 23 | typedef std::vector<const Value*> TypePlane; |
| 24 | std::vector<TypePlane> Table; |
| 25 | std::map<const Value *, unsigned> NodeMap; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 26 | |
| 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 Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 30 | std::vector<unsigned> ModuleLevel; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 31 | |
| 32 | public: |
| 33 | SlotCalculator(const Module *M, bool IgnoreNamed); |
Chris Lattner | e7506a3 | 2002-03-23 22:51:58 +0000 | [diff] [blame] | 34 | // Start out in incorp state |
| 35 | SlotCalculator(const Function *M, bool IgnoreNamed); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 36 | 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 Lattner | e7506a3 | 2002-03-23 22:51:58 +0000 | [diff] [blame] | 53 | void incorporateMethod(const Function *F); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 54 | void purgeMethod(); |
| 55 | |
| 56 | protected: |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 57 | // 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 Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 60 | // |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 61 | int insertVal(const Value *D, bool dontIgnore = false); |
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 | // 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 Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 65 | // |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 66 | int insertValue(const Value *D); |
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 | // doInsertVal - Small helper function to be called only be insertVal. |
| 69 | int doInsertVal(const Value *D); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 70 | |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 71 | // processModule - Process all of the module level method declarations and |
| 72 | // types that are available. |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 73 | // |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 74 | void processModule(); |
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 | // processSymbolTable - Insert all of the values in the specified symbol table |
| 77 | // into the values table... |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 78 | // |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 79 | void processSymbolTable(const SymbolTable *ST); |
| 80 | void processSymbolTableConstants(const SymbolTable *ST); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | #endif |