Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 1 | //===-- MachineCodeForInstruction.cpp -------------------------------------===// |
| 2 | // |
| 3 | // Representation of the sequence of machine instructions created |
| 4 | // for a single VM instruction. Additionally records information |
| 5 | // about hidden and implicit values used by the machine instructions: |
| 6 | // about hidden values used by the machine instructions: |
| 7 | // |
| 8 | // "Temporary values" are intermediate values used in the machine |
| 9 | // instruction sequence, but not in the VM instruction |
| 10 | // Note that such values should be treated as pure SSA values with |
| 11 | // no interpretation of their operands (i.e., as a TmpInstruction |
| 12 | // object which actually represents such a value). |
| 13 | // |
| 14 | // (2) "Implicit uses" are values used in the VM instruction but not in |
| 15 | // the machine instruction sequence |
| 16 | // |
| 17 | //===----------------------------------------------------------------------===// |
| 18 | |
| 19 | #include "llvm/CodeGen/MachineCodeForInstruction.h" |
| 20 | #include "llvm/CodeGen/MachineInstr.h" |
Vikram S. Adve | ded1bf8 | 2002-03-24 03:40:11 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/InstrSelection.h" |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 22 | |
| 23 | static AnnotationID MCFI_AID( |
| 24 | AnnotationManager::getID("CodeGen::MachineCodeForInstruction")); |
| 25 | |
| 26 | static Annotation *CreateMCFI(AnnotationID AID, const Annotable *, void *) { |
| 27 | assert(AID == MCFI_AID); |
| 28 | return new MachineCodeForInstruction(); // Invoke constructor! |
| 29 | } |
| 30 | |
| 31 | // Register the annotation with the annotation factory |
| 32 | static struct Initializer { |
| 33 | Initializer() { |
| 34 | AnnotationManager::registerAnnotationFactory(MCFI_AID, &CreateMCFI); |
| 35 | } |
| 36 | } RegisterAID; |
| 37 | |
Vikram S. Adve | ded1bf8 | 2002-03-24 03:40:11 +0000 | [diff] [blame] | 38 | |
| 39 | MachineCodeForInstruction& |
| 40 | MachineCodeForInstruction::get(const Instruction *I){ |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 41 | return *(MachineCodeForInstruction*)I->getOrCreateAnnotation(MCFI_AID); |
| 42 | } |
| 43 | |
Vikram S. Adve | ded1bf8 | 2002-03-24 03:40:11 +0000 | [diff] [blame] | 44 | |
| 45 | void |
| 46 | MachineCodeForInstruction::destroy(const Instruction *I) { |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 47 | I->deleteAnnotation(MCFI_AID); |
| 48 | } |
| 49 | |
| 50 | |
Vikram S. Adve | ded1bf8 | 2002-03-24 03:40:11 +0000 | [diff] [blame] | 51 | void |
| 52 | MachineCodeForInstruction::dropAllReferences() |
| 53 | { |
| 54 | for (unsigned i=0, N=tempVec.size(); i < N; i++) |
| 55 | cast<TmpInstruction>(tempVec[i])->dropAllReferences(); |
| 56 | } |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 57 | |
Vikram S. Adve | ded1bf8 | 2002-03-24 03:40:11 +0000 | [diff] [blame] | 58 | |
| 59 | MachineCodeForInstruction::MachineCodeForInstruction() |
| 60 | : Annotation(MCFI_AID) |
| 61 | {} |
| 62 | |
| 63 | |
| 64 | MachineCodeForInstruction::~MachineCodeForInstruction() |
| 65 | { |
| 66 | // Let go of all uses in temp. instructions |
| 67 | dropAllReferences(); |
| 68 | |
Chris Lattner | f2868ce | 2002-02-03 07:54:50 +0000 | [diff] [blame] | 69 | // Free the Value objects created to hold intermediate values |
| 70 | for (unsigned i=0, N=tempVec.size(); i < N; i++) |
| 71 | delete tempVec[i]; |
| 72 | |
| 73 | // Free the MachineInstr objects allocated, if any. |
| 74 | for (unsigned i=0, N = size(); i < N; i++) |
| 75 | delete (*this)[i]; |
| 76 | } |