blob: 2193a80e529bcc477e7654773b649e58e61124a1 [file] [log] [blame]
Chris Lattner919c4f82002-08-09 20:04:28 +00001//===-- llvm/CodeGen/MachineCodeForInstruction.h ----------------*- C++ -*-===//
Chris Lattnerf2868ce2002-02-03 07:54:50 +00002//
Chris Lattner919c4f82002-08-09 20:04:28 +00003// Representation of the sequence of machine instructions created for a single
4// VM instruction. Additionally records information about hidden and implicit
5// values used by the machine instructions: about hidden values used by the
6// machine instructions:
Chris Lattnerf2868ce2002-02-03 07:54:50 +00007//
Chris Lattner919c4f82002-08-09 20:04:28 +00008// "Temporary values" are intermediate values used in the machine instruction
9// sequence, but not in the VM instruction Note that such values should be
10// treated as pure SSA values with no interpretation of their operands (i.e., as
11// a TmpInstruction object which actually represents such a value).
Chris Lattnerf2868ce2002-02-03 07:54:50 +000012//
Chris Lattner919c4f82002-08-09 20:04:28 +000013// (2) "Implicit uses" are values used in the VM instruction but not in
14// the machine instruction sequence
Chris Lattnerf2868ce2002-02-03 07:54:50 +000015//
16//===----------------------------------------------------------------------===//
17
18#ifndef LLVM_CODEGEN_MACHINECODE_FOR_INSTRUCTION_H
19#define LLVM_CODEGEN_MACHINECODE_FOR_INSTRUCTION_H
20
21#include "llvm/Annotation.h"
22#include <vector>
23class MachineInstr;
24class Instruction;
25class Value;
26
Chris Lattner51a8d852002-10-28 01:21:55 +000027extern AnnotationID MCFI_AID;
28
Chris Lattner919c4f82002-08-09 20:04:28 +000029class MachineCodeForInstruction : public Annotation {
Chris Lattnerf2868ce2002-02-03 07:54:50 +000030 std::vector<Value*> tempVec; // used by m/c instr but not VM instr
Chris Lattner919c4f82002-08-09 20:04:28 +000031 std::vector<MachineInstr*> Contents;
Chris Lattnerf2868ce2002-02-03 07:54:50 +000032public:
Chris Lattner51a8d852002-10-28 01:21:55 +000033 MachineCodeForInstruction() : Annotation(MCFI_AID) {}
Chris Lattnerf2868ce2002-02-03 07:54:50 +000034 ~MachineCodeForInstruction();
35
Chris Lattner51a8d852002-10-28 01:21:55 +000036 static MachineCodeForInstruction &get(const Instruction *I) {
37 assert(I != NULL);
Chris Lattnera4f808b2002-10-28 01:27:30 +000038 return *(MachineCodeForInstruction*)
39 ((Annotable*)I)->getOrCreateAnnotation(MCFI_AID);
Chris Lattner51a8d852002-10-28 01:21:55 +000040 }
41 static void destroy(const Instruction *I) {
Chris Lattnera4f808b2002-10-28 01:27:30 +000042 ((Annotable*)I)->deleteAnnotation(MCFI_AID);
Chris Lattner51a8d852002-10-28 01:21:55 +000043 }
Chris Lattnerf2868ce2002-02-03 07:54:50 +000044
Chris Lattner919c4f82002-08-09 20:04:28 +000045 // Access to underlying machine instructions...
46 typedef std::vector<MachineInstr*>::iterator iterator;
47 typedef std::vector<MachineInstr*>::const_iterator const_iterator;
48
49 unsigned size() const { return Contents.size(); }
50 bool empty() const { return Contents.empty(); }
51 MachineInstr *front() const { return Contents.front(); }
52 MachineInstr *back() const { return Contents.back(); }
53 MachineInstr *&operator[](unsigned i) { return Contents[i]; }
54 MachineInstr *operator[](unsigned i) const { return Contents[i]; }
55 void pop_back() { Contents.pop_back(); }
56
57 iterator begin() { return Contents.begin(); }
58 iterator end() { return Contents.end(); }
59 const_iterator begin() const { return Contents.begin(); }
60 const_iterator end() const { return Contents.end(); }
61
62 template<class InIt>
63 void insert(iterator where, InIt first, InIt last) {
64 Contents.insert(where, first, last);
65 }
66 iterator erase(iterator where) { return Contents.erase(where); }
67 iterator erase(iterator s, iterator e) { return Contents.erase(s, e); }
68
69
Vikram S. Advedfe412d2002-03-24 03:58:02 +000070 // dropAllReferences() - This function drops all references within
71 // temporary (hidden) instructions created in implementing the original
72 // VM intruction. This ensures there are no remaining "uses" within
73 // these hidden instructions, before the values of a method are freed.
74 //
75 void dropAllReferences();
76
Chris Lattnerf2868ce2002-02-03 07:54:50 +000077 const std::vector<Value*> &getTempValues() const { return tempVec; }
78 std::vector<Value*> &getTempValues() { return tempVec; }
79
Chris Lattner919c4f82002-08-09 20:04:28 +000080 MachineCodeForInstruction &addTemp(Value *tmp) {
Chris Lattnerf2868ce2002-02-03 07:54:50 +000081 tempVec.push_back(tmp);
82 return *this;
83 }
84};
85
86#endif