Chris Lattner | 919c4f8 | 2002-08-09 20:04:28 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/MachineCodeForInstruction.h ----------------*- C++ -*-===// |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | 919c4f8 | 2002-08-09 20:04:28 +0000 | [diff] [blame] | 3 | // Representation of the sequence of machine instructions created for a single |
| 4 | // VM instruction. Additionally records information about hidden and implicit |
| 5 | // values used by the machine instructions: about hidden values used by the |
| 6 | // machine instructions: |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 7 | // |
Chris Lattner | 919c4f8 | 2002-08-09 20:04:28 +0000 | [diff] [blame] | 8 | // "Temporary values" are intermediate values used in the machine instruction |
| 9 | // sequence, but not in the VM instruction Note that such values should be |
| 10 | // treated as pure SSA values with no interpretation of their operands (i.e., as |
| 11 | // a TmpInstruction object which actually represents such a value). |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 12 | // |
Chris Lattner | 919c4f8 | 2002-08-09 20:04:28 +0000 | [diff] [blame] | 13 | // (2) "Implicit uses" are values used in the VM instruction but not in |
| 14 | // the machine instruction sequence |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 15 | // |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | |
| 18 | #ifndef LLVM_CODEGEN_MACHINECODE_FOR_INSTRUCTION_H |
| 19 | #define LLVM_CODEGEN_MACHINECODE_FOR_INSTRUCTION_H |
| 20 | |
| 21 | #include "llvm/Annotation.h" |
| 22 | #include <vector> |
| 23 | class MachineInstr; |
| 24 | class Instruction; |
| 25 | class Value; |
Vikram S. Adve | e68a343 | 2002-10-29 19:38:46 +0000 | [diff] [blame] | 26 | class CallArgsDescriptor; |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 27 | |
Chris Lattner | 51a8d85 | 2002-10-28 01:21:55 +0000 | [diff] [blame] | 28 | extern AnnotationID MCFI_AID; |
| 29 | |
Chris Lattner | 919c4f8 | 2002-08-09 20:04:28 +0000 | [diff] [blame] | 30 | class MachineCodeForInstruction : public Annotation { |
Vikram S. Adve | e68a343 | 2002-10-29 19:38:46 +0000 | [diff] [blame] | 31 | std::vector<Value*> tempVec; // used by m/c instr but not VM instr |
| 32 | std::vector<MachineInstr*> Contents; // the machine instr for this VM instr |
| 33 | CallArgsDescriptor* callArgsDesc; // only used for CALL instructions |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 34 | public: |
Vikram S. Adve | 601899d | 2002-10-30 20:38:49 +0000 | [diff] [blame^] | 35 | MachineCodeForInstruction() : Annotation(MCFI_AID), callArgsDesc(NULL) {} |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 36 | ~MachineCodeForInstruction(); |
| 37 | |
Chris Lattner | 51a8d85 | 2002-10-28 01:21:55 +0000 | [diff] [blame] | 38 | static MachineCodeForInstruction &get(const Instruction *I) { |
| 39 | assert(I != NULL); |
Chris Lattner | a4f808b | 2002-10-28 01:27:30 +0000 | [diff] [blame] | 40 | return *(MachineCodeForInstruction*) |
| 41 | ((Annotable*)I)->getOrCreateAnnotation(MCFI_AID); |
Chris Lattner | 51a8d85 | 2002-10-28 01:21:55 +0000 | [diff] [blame] | 42 | } |
| 43 | static void destroy(const Instruction *I) { |
Chris Lattner | a4f808b | 2002-10-28 01:27:30 +0000 | [diff] [blame] | 44 | ((Annotable*)I)->deleteAnnotation(MCFI_AID); |
Chris Lattner | 51a8d85 | 2002-10-28 01:21:55 +0000 | [diff] [blame] | 45 | } |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 46 | |
Chris Lattner | 919c4f8 | 2002-08-09 20:04:28 +0000 | [diff] [blame] | 47 | // Access to underlying machine instructions... |
| 48 | typedef std::vector<MachineInstr*>::iterator iterator; |
| 49 | typedef std::vector<MachineInstr*>::const_iterator const_iterator; |
| 50 | |
| 51 | unsigned size() const { return Contents.size(); } |
| 52 | bool empty() const { return Contents.empty(); } |
| 53 | MachineInstr *front() const { return Contents.front(); } |
| 54 | MachineInstr *back() const { return Contents.back(); } |
| 55 | MachineInstr *&operator[](unsigned i) { return Contents[i]; } |
| 56 | MachineInstr *operator[](unsigned i) const { return Contents[i]; } |
| 57 | void pop_back() { Contents.pop_back(); } |
| 58 | |
| 59 | iterator begin() { return Contents.begin(); } |
| 60 | iterator end() { return Contents.end(); } |
| 61 | const_iterator begin() const { return Contents.begin(); } |
| 62 | const_iterator end() const { return Contents.end(); } |
| 63 | |
| 64 | template<class InIt> |
| 65 | void insert(iterator where, InIt first, InIt last) { |
| 66 | Contents.insert(where, first, last); |
| 67 | } |
| 68 | iterator erase(iterator where) { return Contents.erase(where); } |
| 69 | iterator erase(iterator s, iterator e) { return Contents.erase(s, e); } |
| 70 | |
| 71 | |
Vikram S. Adve | dfe412d | 2002-03-24 03:58:02 +0000 | [diff] [blame] | 72 | // dropAllReferences() - This function drops all references within |
| 73 | // temporary (hidden) instructions created in implementing the original |
| 74 | // VM intruction. This ensures there are no remaining "uses" within |
| 75 | // these hidden instructions, before the values of a method are freed. |
| 76 | // |
| 77 | void dropAllReferences(); |
| 78 | |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 79 | const std::vector<Value*> &getTempValues() const { return tempVec; } |
| 80 | std::vector<Value*> &getTempValues() { return tempVec; } |
| 81 | |
Chris Lattner | 919c4f8 | 2002-08-09 20:04:28 +0000 | [diff] [blame] | 82 | MachineCodeForInstruction &addTemp(Value *tmp) { |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 83 | tempVec.push_back(tmp); |
| 84 | return *this; |
| 85 | } |
Vikram S. Adve | e68a343 | 2002-10-29 19:38:46 +0000 | [diff] [blame] | 86 | |
| 87 | void setCallArgsDescriptor(CallArgsDescriptor* desc) { callArgsDesc = desc; } |
| 88 | CallArgsDescriptor* getCallArgsDescriptor() const { return callArgsDesc; } |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | #endif |