blob: a4ebbec187f563017592a7da4bd61990d2183ab0 [file] [log] [blame]
Chris Lattnerf2868ce2002-02-03 07:54:50 +00001//===-- 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. Adveded1bf82002-03-24 03:40:11 +000021#include "llvm/CodeGen/InstrSelection.h"
Chris Lattnerf2868ce2002-02-03 07:54:50 +000022#include "llvm/Instruction.h"
23
24static AnnotationID MCFI_AID(
25 AnnotationManager::getID("CodeGen::MachineCodeForInstruction"));
26
27static Annotation *CreateMCFI(AnnotationID AID, const Annotable *, void *) {
28 assert(AID == MCFI_AID);
29 return new MachineCodeForInstruction(); // Invoke constructor!
30}
31
32// Register the annotation with the annotation factory
33static struct Initializer {
34 Initializer() {
35 AnnotationManager::registerAnnotationFactory(MCFI_AID, &CreateMCFI);
36 }
37} RegisterAID;
38
Vikram S. Adveded1bf82002-03-24 03:40:11 +000039
40MachineCodeForInstruction&
41MachineCodeForInstruction::get(const Instruction *I){
Chris Lattnerf2868ce2002-02-03 07:54:50 +000042 return *(MachineCodeForInstruction*)I->getOrCreateAnnotation(MCFI_AID);
43}
44
Vikram S. Adveded1bf82002-03-24 03:40:11 +000045
46void
47MachineCodeForInstruction::destroy(const Instruction *I) {
Chris Lattnerf2868ce2002-02-03 07:54:50 +000048 I->deleteAnnotation(MCFI_AID);
49}
50
51
Vikram S. Adveded1bf82002-03-24 03:40:11 +000052void
53MachineCodeForInstruction::dropAllReferences()
54{
55 for (unsigned i=0, N=tempVec.size(); i < N; i++)
56 cast<TmpInstruction>(tempVec[i])->dropAllReferences();
57}
Chris Lattnerf2868ce2002-02-03 07:54:50 +000058
Vikram S. Adveded1bf82002-03-24 03:40:11 +000059
60MachineCodeForInstruction::MachineCodeForInstruction()
61 : Annotation(MCFI_AID)
62{}
63
64
65MachineCodeForInstruction::~MachineCodeForInstruction()
66{
67 // Let go of all uses in temp. instructions
68 dropAllReferences();
69
Chris Lattnerf2868ce2002-02-03 07:54:50 +000070 // Free the Value objects created to hold intermediate values
71 for (unsigned i=0, N=tempVec.size(); i < N; i++)
72 delete tempVec[i];
73
74 // Free the MachineInstr objects allocated, if any.
75 for (unsigned i=0, N = size(); i < N; i++)
76 delete (*this)[i];
77}