blob: 8bf1c4129a49863a2bd0e09fc99ef6d0eb81ef0d [file] [log] [blame]
Chris Lattnerf2868ce2002-02-03 07:54:50 +00001//===-- MachineCodeForInstruction.cpp -------------------------------------===//
John Criswellb576c942003-10-20 19:43:21 +00002//
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 Lattnerf2868ce2002-02-03 07:54:50 +00009//
Chris Lattner51a8d852002-10-28 01:21:55 +000010// 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 Lattnerf2868ce2002-02-03 07:54:50 +000014//
Chris Lattner51a8d852002-10-28 01:21:55 +000015// "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 Lattnerf2868ce2002-02-03 07:54:50 +000019//
Chris Lattner51a8d852002-10-28 01:21:55 +000020// (2) "Implicit uses" are values used in the VM instruction but not in the
21// machine instruction sequence
Chris Lattnerf2868ce2002-02-03 07:54:50 +000022//
23//===----------------------------------------------------------------------===//
24
25#include "llvm/CodeGen/MachineCodeForInstruction.h"
26#include "llvm/CodeGen/MachineInstr.h"
Chris Lattnerc81295a2004-02-29 21:40:53 +000027#include "../Target/SparcV9/MachineInstrAnnot.h"
Chris Lattnerae7fc3a2004-01-10 19:16:26 +000028#include "llvm/Instruction.h"
Chris Lattnerd5da1972004-01-09 06:30:18 +000029using namespace llvm;
Chris Lattnerf2868ce2002-02-03 07:54:50 +000030
Chris Lattner585911e2004-02-29 19:02:39 +000031MachineCodeForInstruction &MachineCodeForInstruction::get(const Instruction *I){
32 return *(MachineCodeForInstruction*)I->getOrCreateAnnotation(MCFI_AID);
33}
34void MachineCodeForInstruction::destroy(const Instruction *I) {
35 I->deleteAnnotation(MCFI_AID);
36}
37
38
39
Chris Lattnerd5da1972004-01-09 06:30:18 +000040AnnotationID llvm::MCFI_AID(
Chris Lattnerf2868ce2002-02-03 07:54:50 +000041 AnnotationManager::getID("CodeGen::MachineCodeForInstruction"));
42
43static 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. Adve45c38772002-07-08 23:04:31 +000049static struct MCFIInitializer {
50 MCFIInitializer() {
Chris Lattnerf2868ce2002-02-03 07:54:50 +000051 AnnotationManager::registerAnnotationFactory(MCFI_AID, &CreateMCFI);
52 }
Vikram S. Adve45c38772002-07-08 23:04:31 +000053} RegisterCreateMCFI;
Chris Lattnerf2868ce2002-02-03 07:54:50 +000054
Vikram S. Adveded1bf82002-03-24 03:40:11 +000055
Vikram S. Adveded1bf82002-03-24 03:40:11 +000056void
57MachineCodeForInstruction::dropAllReferences()
58{
59 for (unsigned i=0, N=tempVec.size(); i < N; i++)
Chris Lattnerae7fc3a2004-01-10 19:16:26 +000060 cast<Instruction>(tempVec[i])->dropAllReferences();
Vikram S. Adveded1bf82002-03-24 03:40:11 +000061}
Chris Lattnerf2868ce2002-02-03 07:54:50 +000062
Vikram S. Adveded1bf82002-03-24 03:40:11 +000063
Chris Lattnerd5da1972004-01-09 06:30:18 +000064MachineCodeForInstruction::~MachineCodeForInstruction() {
Vikram S. Adveded1bf82002-03-24 03:40:11 +000065 // Let go of all uses in temp. instructions
66 dropAllReferences();
67
Chris Lattnerf2868ce2002-02-03 07:54:50 +000068 // 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 Evlogimenosc0b9dc52004-02-12 02:27:10 +000072 // do not free the MachineInstr objects allocated. they are managed
73 // by the ilist in MachineBasicBlock
Vikram S. Advee68a3432002-10-29 19:38:46 +000074
75 // Free the CallArgsDescriptor if it exists.
Chris Lattnerd5da1972004-01-09 06:30:18 +000076 delete callArgsDesc;
Chris Lattnerf2868ce2002-02-03 07:54:50 +000077}