Chris Lattner | 4848689 | 2003-09-30 18:37:50 +0000 | [diff] [blame] | 1 | //===-- llvm/SlotCalculator.h - Calculate value slots -----------*- C++ -*-===// |
John Criswell | 6fbcc26 | 2003-10-20 20:19:47 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | b579400 | 2002-04-07 22:49:37 +0000 | [diff] [blame] | 10 | // This class calculates the slots that values will land in. This is useful for |
| 11 | // when writing bytecode or assembly out, because you have to know these things. |
| 12 | // |
| 13 | // Specifically, this class calculates the "type plane numbering" that you see |
| 14 | // for a function if you strip out all of the symbols in it. For assembly |
| 15 | // writing, this is used when a symbol does not have a name. For bytecode |
| 16 | // 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] | 17 | // |
| 18 | //===----------------------------------------------------------------------===// |
| 19 | |
Chris Lattner | b579400 | 2002-04-07 22:49:37 +0000 | [diff] [blame] | 20 | #ifndef LLVM_SLOTCALCULATOR_H |
| 21 | #define LLVM_SLOTCALCULATOR_H |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 22 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 23 | #include <vector> |
| 24 | #include <map> |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 25 | |
| 26 | namespace llvm { |
| 27 | |
Chris Lattner | 644dc17 | 2001-07-14 06:08:51 +0000 | [diff] [blame] | 28 | class Value; |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 29 | class Module; |
Chris Lattner | e7506a3 | 2002-03-23 22:51:58 +0000 | [diff] [blame] | 30 | class Function; |
Chris Lattner | 184b2fa | 2002-04-09 18:35:38 +0000 | [diff] [blame] | 31 | class SymbolTable; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 32 | |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 33 | class SlotCalculator { |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 34 | const Module *TheModule; |
Chris Lattner | 8ce7501 | 2004-01-14 02:49:34 +0000 | [diff] [blame^] | 35 | |
| 36 | // BuildBytecodeInfo - If true, this is the creating information for the |
| 37 | // bytecode writer, if false, we are building information for the assembly |
| 38 | // emitter. The assembly emitter doesn't need named objects numbered, among |
| 39 | // other differences. |
| 40 | bool BuildBytecodeInfo; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 41 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 42 | typedef std::vector<const Value*> TypePlane; |
| 43 | std::vector<TypePlane> Table; |
| 44 | std::map<const Value *, unsigned> NodeMap; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 45 | |
| 46 | // ModuleLevel - Used to keep track of which values belong to the module, |
Chris Lattner | b579400 | 2002-04-07 22:49:37 +0000 | [diff] [blame] | 47 | // and which values belong to the currently incorporated function. |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 48 | // |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 49 | std::vector<unsigned> ModuleLevel; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 50 | |
| 51 | public: |
Chris Lattner | 8ce7501 | 2004-01-14 02:49:34 +0000 | [diff] [blame^] | 52 | SlotCalculator(const Module *M, bool BuildBytecodeInfo); |
Chris Lattner | e7506a3 | 2002-03-23 22:51:58 +0000 | [diff] [blame] | 53 | // Start out in incorp state |
Chris Lattner | 8ce7501 | 2004-01-14 02:49:34 +0000 | [diff] [blame^] | 54 | SlotCalculator(const Function *M, bool BuildBytecodeInfo); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 55 | inline ~SlotCalculator() {} |
| 56 | |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame] | 57 | // getSlot returns < 0 on error! |
| 58 | int getSlot(const Value *D) const; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 59 | |
| 60 | inline unsigned getNumPlanes() const { return Table.size(); } |
| 61 | inline unsigned getModuleLevel(unsigned Plane) const { |
| 62 | return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0; |
| 63 | } |
| 64 | |
| 65 | inline const TypePlane &getPlane(unsigned Plane) const { |
| 66 | return Table[Plane]; |
| 67 | } |
| 68 | |
Chris Lattner | b579400 | 2002-04-07 22:49:37 +0000 | [diff] [blame] | 69 | // If you'd like to deal with a function, use these two methods to get its |
| 70 | // data into the SlotCalculator! |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 71 | // |
Chris Lattner | b579400 | 2002-04-07 22:49:37 +0000 | [diff] [blame] | 72 | void incorporateFunction(const Function *F); |
| 73 | void purgeFunction(); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 74 | |
| 75 | protected: |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame] | 76 | // getOrCreateSlot - Values can be crammed into here at will... if |
| 77 | // they haven't been inserted already, they get inserted, otherwise |
| 78 | // they are ignored. |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 79 | // |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame] | 80 | int getOrCreateSlot(const Value *D); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 81 | |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame] | 82 | // insertValue - Insert a value into the value table... Return the |
| 83 | // slot that it occupies, or -1 if the declaration is to be ignored |
| 84 | // because of the IgnoreNamedNodes flag. |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 85 | // |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame] | 86 | int insertValue(const Value *D, bool dontIgnore = false); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 87 | |
Alkis Evlogimenos | 6059638 | 2003-10-17 02:02:40 +0000 | [diff] [blame] | 88 | // doInsertValue - Small helper function to be called only be insertVal. |
| 89 | int doInsertValue(const Value *D); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 90 | |
Chris Lattner | b579400 | 2002-04-07 22:49:37 +0000 | [diff] [blame] | 91 | // processModule - Process all of the module level function declarations and |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 92 | // types that are available. |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 93 | // |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 94 | void processModule(); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 95 | |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 96 | // processSymbolTable - Insert all of the values in the specified symbol table |
| 97 | // into the values table... |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 98 | // |
Chris Lattner | 4c4007b | 2001-09-07 16:27:05 +0000 | [diff] [blame] | 99 | void processSymbolTable(const SymbolTable *ST); |
| 100 | void processSymbolTableConstants(const SymbolTable *ST); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 101 | }; |
| 102 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 103 | } // End llvm namespace |
| 104 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 105 | #endif |