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