Chris Lattner | 4848689 | 2003-09-30 18:37:50 +0000 | [diff] [blame] | 1 | //===-- llvm/SlotCalculator.h - Calculate value slots -----------*- C++ -*-===// |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | b579400 | 2002-04-07 22:49:37 +0000 | [diff] [blame] | 3 | // 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 Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
Chris Lattner | b579400 | 2002-04-07 22:49:37 +0000 | [diff] [blame] | 13 | #ifndef LLVM_SLOTCALCULATOR_H |
| 14 | #define LLVM_SLOTCALCULATOR_H |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 15 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 16 | #include <vector> |
| 17 | #include <map> |
Chris Lattner | 644dc17 | 2001-07-14 06:08:51 +0000 | [diff] [blame] | 18 | class Value; |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 19 | class Module; |
Chris Lattner | e7506a3 | 2002-03-23 22:51:58 +0000 | [diff] [blame] | 20 | class Function; |
Chris Lattner | 184b2fa | 2002-04-09 18:35:38 +0000 | [diff] [blame] | 21 | class SymbolTable; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 22 | |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 23 | class SlotCalculator { |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 24 | const Module *TheModule; |
| 25 | bool IgnoreNamedNodes; // Shall we not count named nodes? |
| 26 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 27 | typedef std::vector<const Value*> TypePlane; |
| 28 | std::vector<TypePlane> Table; |
| 29 | std::map<const Value *, unsigned> NodeMap; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 30 | |
| 31 | // ModuleLevel - Used to keep track of which values belong to the module, |
Chris Lattner | b579400 | 2002-04-07 22:49:37 +0000 | [diff] [blame] | 32 | // and which values belong to the currently incorporated function. |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 33 | // |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 34 | std::vector<unsigned> ModuleLevel; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 35 | |
| 36 | public: |
| 37 | SlotCalculator(const Module *M, bool IgnoreNamed); |
Chris Lattner | e7506a3 | 2002-03-23 22:51:58 +0000 | [diff] [blame] | 38 | // Start out in incorp state |
| 39 | SlotCalculator(const Function *M, bool IgnoreNamed); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 40 | inline ~SlotCalculator() {} |
| 41 | |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame^] | 42 | // getSlot returns < 0 on error! |
| 43 | int getSlot(const Value *D) const; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 44 | |
| 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 Lattner | b579400 | 2002-04-07 22:49:37 +0000 | [diff] [blame] | 54 | // If you'd like to deal with a function, use these two methods to get its |
| 55 | // data into the SlotCalculator! |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 56 | // |
Chris Lattner | b579400 | 2002-04-07 22:49:37 +0000 | [diff] [blame] | 57 | void incorporateFunction(const Function *F); |
| 58 | void purgeFunction(); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 59 | |
| 60 | protected: |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame^] | 61 | // 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 Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 64 | // |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame^] | 65 | int getOrCreateSlot(const Value *D); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 66 | |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame^] | 67 | // 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 Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 70 | // |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame^] | 71 | int insertValue(const Value *D, bool dontIgnore = false); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 72 | |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame^] | 73 | // doInsertValue - Small helper function to be called only be insertVal. |
| 74 | int doInsertValue(const Value *D); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 75 | |
Chris Lattner | b579400 | 2002-04-07 22:49:37 +0000 | [diff] [blame] | 76 | // processModule - Process all of the module level function declarations and |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 77 | // types that are available. |
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 processModule(); |
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 | // processSymbolTable - Insert all of the values in the specified symbol table |
| 82 | // into the values table... |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 83 | // |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 84 | void processSymbolTable(const SymbolTable *ST); |
| 85 | void processSymbolTableConstants(const SymbolTable *ST); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | #endif |