blob: 25994a94a38f761b2423a98b52f41951ff4442ad [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
Chris Lattnercb09cc22003-01-14 21:29:58 +000021#include "Support/Annotation.h"
Chris Lattnerf2868ce2002-02-03 07:54:50 +000022#include <vector>
John Criswellbe583b92003-06-11 14:01:36 +000023
Chris Lattnerf2868ce2002-02-03 07:54:50 +000024class MachineInstr;
25class Instruction;
26class Value;
Vikram S. Advee68a3432002-10-29 19:38:46 +000027class CallArgsDescriptor;
Chris Lattnerf2868ce2002-02-03 07:54:50 +000028
Chris Lattner51a8d852002-10-28 01:21:55 +000029extern AnnotationID MCFI_AID;
30
Chris Lattner919c4f82002-08-09 20:04:28 +000031class MachineCodeForInstruction : public Annotation {
Vikram S. Advee68a3432002-10-29 19:38:46 +000032 std::vector<Value*> tempVec; // used by m/c instr but not VM instr
33 std::vector<MachineInstr*> Contents; // the machine instr for this VM instr
34 CallArgsDescriptor* callArgsDesc; // only used for CALL instructions
Chris Lattnerf2868ce2002-02-03 07:54:50 +000035public:
Vikram S. Adve601899d2002-10-30 20:38:49 +000036 MachineCodeForInstruction() : Annotation(MCFI_AID), callArgsDesc(NULL) {}
Chris Lattnerf2868ce2002-02-03 07:54:50 +000037 ~MachineCodeForInstruction();
38
Chris Lattner51a8d852002-10-28 01:21:55 +000039 static MachineCodeForInstruction &get(const Instruction *I) {
40 assert(I != NULL);
Chris Lattnera4f808b2002-10-28 01:27:30 +000041 return *(MachineCodeForInstruction*)
42 ((Annotable*)I)->getOrCreateAnnotation(MCFI_AID);
Chris Lattner51a8d852002-10-28 01:21:55 +000043 }
44 static void destroy(const Instruction *I) {
Chris Lattnera4f808b2002-10-28 01:27:30 +000045 ((Annotable*)I)->deleteAnnotation(MCFI_AID);
Chris Lattner51a8d852002-10-28 01:21:55 +000046 }
Chris Lattnerf2868ce2002-02-03 07:54:50 +000047
Chris Lattner919c4f82002-08-09 20:04:28 +000048 // Access to underlying machine instructions...
49 typedef std::vector<MachineInstr*>::iterator iterator;
50 typedef std::vector<MachineInstr*>::const_iterator const_iterator;
51
52 unsigned size() const { return Contents.size(); }
53 bool empty() const { return Contents.empty(); }
54 MachineInstr *front() const { return Contents.front(); }
55 MachineInstr *back() const { return Contents.back(); }
56 MachineInstr *&operator[](unsigned i) { return Contents[i]; }
57 MachineInstr *operator[](unsigned i) const { return Contents[i]; }
58 void pop_back() { Contents.pop_back(); }
59
60 iterator begin() { return Contents.begin(); }
61 iterator end() { return Contents.end(); }
62 const_iterator begin() const { return Contents.begin(); }
63 const_iterator end() const { return Contents.end(); }
64
65 template<class InIt>
66 void insert(iterator where, InIt first, InIt last) {
67 Contents.insert(where, first, last);
68 }
69 iterator erase(iterator where) { return Contents.erase(where); }
70 iterator erase(iterator s, iterator e) { return Contents.erase(s, e); }
71
72
Vikram S. Advedfe412d2002-03-24 03:58:02 +000073 // dropAllReferences() - This function drops all references within
74 // temporary (hidden) instructions created in implementing the original
75 // VM intruction. This ensures there are no remaining "uses" within
76 // these hidden instructions, before the values of a method are freed.
77 //
78 void dropAllReferences();
79
Chris Lattnerf2868ce2002-02-03 07:54:50 +000080 const std::vector<Value*> &getTempValues() const { return tempVec; }
81 std::vector<Value*> &getTempValues() { return tempVec; }
82
Chris Lattner919c4f82002-08-09 20:04:28 +000083 MachineCodeForInstruction &addTemp(Value *tmp) {
Chris Lattnerf2868ce2002-02-03 07:54:50 +000084 tempVec.push_back(tmp);
85 return *this;
86 }
Vikram S. Advee68a3432002-10-29 19:38:46 +000087
88 void setCallArgsDescriptor(CallArgsDescriptor* desc) { callArgsDesc = desc; }
89 CallArgsDescriptor* getCallArgsDescriptor() const { return callArgsDesc; }
Chris Lattnerf2868ce2002-02-03 07:54:50 +000090};
91
92#endif