blob: ff171e9621d4e02fd64cb5eeb12c737d13695901 [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>
23class MachineInstr;
24class Instruction;
25class Value;
Vikram S. Advee68a3432002-10-29 19:38:46 +000026class CallArgsDescriptor;
Chris Lattnerf2868ce2002-02-03 07:54:50 +000027
Chris Lattner51a8d852002-10-28 01:21:55 +000028extern AnnotationID MCFI_AID;
29
Chris Lattner919c4f82002-08-09 20:04:28 +000030class MachineCodeForInstruction : public Annotation {
Vikram S. Advee68a3432002-10-29 19:38:46 +000031 std::vector<Value*> tempVec; // used by m/c instr but not VM instr
32 std::vector<MachineInstr*> Contents; // the machine instr for this VM instr
33 CallArgsDescriptor* callArgsDesc; // only used for CALL instructions
Chris Lattnerf2868ce2002-02-03 07:54:50 +000034public:
Vikram S. Adve601899d2002-10-30 20:38:49 +000035 MachineCodeForInstruction() : Annotation(MCFI_AID), callArgsDesc(NULL) {}
Chris Lattnerf2868ce2002-02-03 07:54:50 +000036 ~MachineCodeForInstruction();
37
Chris Lattner51a8d852002-10-28 01:21:55 +000038 static MachineCodeForInstruction &get(const Instruction *I) {
39 assert(I != NULL);
Chris Lattnera4f808b2002-10-28 01:27:30 +000040 return *(MachineCodeForInstruction*)
41 ((Annotable*)I)->getOrCreateAnnotation(MCFI_AID);
Chris Lattner51a8d852002-10-28 01:21:55 +000042 }
43 static void destroy(const Instruction *I) {
Chris Lattnera4f808b2002-10-28 01:27:30 +000044 ((Annotable*)I)->deleteAnnotation(MCFI_AID);
Chris Lattner51a8d852002-10-28 01:21:55 +000045 }
Chris Lattnerf2868ce2002-02-03 07:54:50 +000046
Chris Lattner919c4f82002-08-09 20:04:28 +000047 // Access to underlying machine instructions...
48 typedef std::vector<MachineInstr*>::iterator iterator;
49 typedef std::vector<MachineInstr*>::const_iterator const_iterator;
50
51 unsigned size() const { return Contents.size(); }
52 bool empty() const { return Contents.empty(); }
53 MachineInstr *front() const { return Contents.front(); }
54 MachineInstr *back() const { return Contents.back(); }
55 MachineInstr *&operator[](unsigned i) { return Contents[i]; }
56 MachineInstr *operator[](unsigned i) const { return Contents[i]; }
57 void pop_back() { Contents.pop_back(); }
58
59 iterator begin() { return Contents.begin(); }
60 iterator end() { return Contents.end(); }
61 const_iterator begin() const { return Contents.begin(); }
62 const_iterator end() const { return Contents.end(); }
63
64 template<class InIt>
65 void insert(iterator where, InIt first, InIt last) {
66 Contents.insert(where, first, last);
67 }
68 iterator erase(iterator where) { return Contents.erase(where); }
69 iterator erase(iterator s, iterator e) { return Contents.erase(s, e); }
70
71
Vikram S. Advedfe412d2002-03-24 03:58:02 +000072 // dropAllReferences() - This function drops all references within
73 // temporary (hidden) instructions created in implementing the original
74 // VM intruction. This ensures there are no remaining "uses" within
75 // these hidden instructions, before the values of a method are freed.
76 //
77 void dropAllReferences();
78
Chris Lattnerf2868ce2002-02-03 07:54:50 +000079 const std::vector<Value*> &getTempValues() const { return tempVec; }
80 std::vector<Value*> &getTempValues() { return tempVec; }
81
Chris Lattner919c4f82002-08-09 20:04:28 +000082 MachineCodeForInstruction &addTemp(Value *tmp) {
Chris Lattnerf2868ce2002-02-03 07:54:50 +000083 tempVec.push_back(tmp);
84 return *this;
85 }
Vikram S. Advee68a3432002-10-29 19:38:46 +000086
87 void setCallArgsDescriptor(CallArgsDescriptor* desc) { callArgsDesc = desc; }
88 CallArgsDescriptor* getCallArgsDescriptor() const { return callArgsDesc; }
Chris Lattnerf2868ce2002-02-03 07:54:50 +000089};
90
91#endif