* Use the MachineConstantPool for storing constants instead of a hash_set;
[oota-llvm.git] / lib / Target / SparcV9 / MachineCodeForInstruction.h
1 //===-- llvm/CodeGen/MachineCodeForInstruction.h ----------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
9 //
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:
14 // 
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).
19 // 
20 // (2) "Implicit uses" are values used in the VM instruction but not in
21 //     the machine instruction sequence
22 // 
23 //===----------------------------------------------------------------------===//
24
25 #ifndef LLVM_CODEGEN_MACHINECODE_FOR_INSTRUCTION_H
26 #define LLVM_CODEGEN_MACHINECODE_FOR_INSTRUCTION_H
27
28 #include "Support/Annotation.h"
29 #include <vector>
30
31 class MachineInstr;
32 class Instruction;
33 class Value;
34 class CallArgsDescriptor;
35
36 extern AnnotationID MCFI_AID;
37
38 class MachineCodeForInstruction : public Annotation {
39   std::vector<Value*> tempVec;          // used by m/c instr but not VM instr
40   std::vector<MachineInstr*> Contents;  // the machine instr for this VM instr
41   CallArgsDescriptor* callArgsDesc;     // only used for CALL instructions
42 public:
43   MachineCodeForInstruction() : Annotation(MCFI_AID), callArgsDesc(NULL) {}
44   ~MachineCodeForInstruction();
45   
46   static MachineCodeForInstruction &get(const Instruction *I) {
47     assert(I != NULL);
48     return *(MachineCodeForInstruction*)
49       ((Annotable*)I)->getOrCreateAnnotation(MCFI_AID);
50   }
51   static void destroy(const Instruction *I) {
52     ((Annotable*)I)->deleteAnnotation(MCFI_AID);
53   }
54
55   // Access to underlying machine instructions...
56   typedef std::vector<MachineInstr*>::iterator iterator;
57   typedef std::vector<MachineInstr*>::const_iterator const_iterator;
58
59   unsigned size() const { return Contents.size(); }
60   bool empty() const { return Contents.empty(); }
61   MachineInstr *front() const { return Contents.front(); }
62   MachineInstr *back() const { return Contents.back(); }
63   MachineInstr *&operator[](unsigned i) { return Contents[i]; }
64   MachineInstr *operator[](unsigned i) const { return Contents[i]; }
65   void pop_back() { Contents.pop_back(); }
66
67   iterator begin() { return Contents.begin(); }
68   iterator end()   { return Contents.end(); }
69   const_iterator begin() const { return Contents.begin(); }
70   const_iterator end()   const { return Contents.end(); }
71
72   template<class InIt>
73   void insert(iterator where, InIt first, InIt last) {
74     Contents.insert(where, first, last);
75   }
76   iterator erase(iterator where) { return Contents.erase(where); }
77   iterator erase(iterator s, iterator e) { return Contents.erase(s, e); }
78   
79
80   // dropAllReferences() - This function drops all references within
81   // temporary (hidden) instructions created in implementing the original
82   // VM intruction.  This ensures there are no remaining "uses" within
83   // these hidden instructions, before the values of a method are freed.
84   //
85   void dropAllReferences();
86
87   const std::vector<Value*> &getTempValues() const { return tempVec; }
88         std::vector<Value*> &getTempValues()       { return tempVec; }
89   
90   MachineCodeForInstruction &addTemp(Value *tmp) {
91     tempVec.push_back(tmp);
92     return *this;
93   }
94
95   void setCallArgsDescriptor(CallArgsDescriptor* desc) { callArgsDesc = desc; }
96   CallArgsDescriptor* getCallArgsDescriptor() const    { return callArgsDesc; }
97 };
98
99 #endif