OLD | NEW |
1 //===-- CodeGen/MachineInstBuilder.h - Simplify creation of MIs -*- C++ -*-===// | 1 //===-- CodeGen/MachineInstBuilder.h - Simplify creation of MIs -*- C++ -*-===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file exposes a function named BuildMI, which is useful for dramatically | 10 // This file exposes a function named BuildMI, which is useful for dramatically |
11 // simplifying how MachineInstr's are created. It allows use of code like this: | 11 // simplifying how MachineInstr's are created. It allows use of code like this: |
12 // | 12 // |
13 // M = BuildMI(X86::ADDrr8, 2).addReg(argVal1).addReg(argVal2); | 13 // M = BuildMI(X86::ADDrr8, 2).addReg(argVal1).addReg(argVal2); |
14 // | 14 // |
15 //===----------------------------------------------------------------------===// | 15 //===----------------------------------------------------------------------===// |
16 | 16 |
17 #ifndef LLVM_CODEGEN_MACHINEINSTRBUILDER_H | 17 #ifndef LLVM_CODEGEN_MACHINEINSTRBUILDER_H |
18 #define LLVM_CODEGEN_MACHINEINSTRBUILDER_H | 18 #define LLVM_CODEGEN_MACHINEINSTRBUILDER_H |
19 | 19 |
20 #include "llvm/CodeGen/MachineFunction.h" | 20 #include "llvm/CodeGen/MachineFunction.h" |
| 21 #include "llvm/Support/ErrorHandling.h" |
21 | 22 |
22 namespace llvm { | 23 namespace llvm { |
23 | 24 |
24 class TargetInstrDesc; | 25 class TargetInstrDesc; |
25 class MDNode; | 26 class MDNode; |
26 | 27 |
27 namespace RegState { | 28 namespace RegState { |
28 enum { | 29 enum { |
29 Define = 0x2, | 30 Define = 0x2, |
30 Implicit = 0x4, | 31 Implicit = 0x4, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 unsigned char TargetFlags = 0) const { | 116 unsigned char TargetFlags = 0) const { |
116 MI->addOperand(MachineOperand::CreateES(FnName, TargetFlags)); | 117 MI->addOperand(MachineOperand::CreateES(FnName, TargetFlags)); |
117 return *this; | 118 return *this; |
118 } | 119 } |
119 | 120 |
120 const MachineInstrBuilder &addMemOperand(MachineMemOperand *MMO) const { | 121 const MachineInstrBuilder &addMemOperand(MachineMemOperand *MMO) const { |
121 MI->addMemOperand(*MI->getParent()->getParent(), MMO); | 122 MI->addMemOperand(*MI->getParent()->getParent(), MMO); |
122 return *this; | 123 return *this; |
123 } | 124 } |
124 | 125 |
| 126 const MachineInstrBuilder &setMemRefs(MachineInstr::mmo_iterator b, |
| 127 MachineInstr::mmo_iterator e) const { |
| 128 MI->setMemRefs(b, e); |
| 129 return *this; |
| 130 } |
| 131 |
| 132 |
125 const MachineInstrBuilder &addOperand(const MachineOperand &MO) const { | 133 const MachineInstrBuilder &addOperand(const MachineOperand &MO) const { |
126 MI->addOperand(MO); | 134 MI->addOperand(MO); |
127 return *this; | 135 return *this; |
128 } | 136 } |
129 | 137 |
130 const MachineInstrBuilder &addMetadata(const MDNode *MD) const { | 138 const MachineInstrBuilder &addMetadata(const MDNode *MD) const { |
131 MI->addOperand(MachineOperand::CreateMetadata(MD)); | 139 MI->addOperand(MachineOperand::CreateMetadata(MD)); |
132 return *this; | 140 return *this; |
133 } | 141 } |
134 | 142 |
135 const MachineInstrBuilder &addSym(MCSymbol *Sym) const { | 143 const MachineInstrBuilder &addSym(MCSymbol *Sym) const { |
136 MI->addOperand(MachineOperand::CreateMCSymbol(Sym)); | 144 MI->addOperand(MachineOperand::CreateMCSymbol(Sym)); |
137 return *this; | 145 return *this; |
138 } | 146 } |
| 147 |
| 148 // Add a displacement from an existing MachineOperand with an added offset. |
| 149 const MachineInstrBuilder &addDisp(const MachineOperand &Disp, |
| 150 int64_t off) const { |
| 151 switch (Disp.getType()) { |
| 152 default: |
| 153 llvm_unreachable("Unhandled operand type in addDisp()"); |
| 154 case MachineOperand::MO_Immediate: |
| 155 return addImm(Disp.getImm() + off); |
| 156 case MachineOperand::MO_GlobalAddress: |
| 157 return addGlobalAddress(Disp.getGlobal(), Disp.getOffset() + off); |
| 158 } |
| 159 } |
139 }; | 160 }; |
140 | 161 |
141 /// BuildMI - Builder interface. Specify how to create the initial instruction | 162 /// BuildMI - Builder interface. Specify how to create the initial instruction |
142 /// itself. | 163 /// itself. |
143 /// | 164 /// |
144 inline MachineInstrBuilder BuildMI(MachineFunction &MF, | 165 inline MachineInstrBuilder BuildMI(MachineFunction &MF, |
145 DebugLoc DL, | 166 DebugLoc DL, |
146 const TargetInstrDesc &TID) { | 167 const TargetInstrDesc &TID) { |
147 return MachineInstrBuilder(MF.CreateMachineInstr(TID, DL)); | 168 return MachineInstrBuilder(MF.CreateMachineInstr(TID, DL)); |
148 } | 169 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 inline unsigned getDeadRegState(bool B) { | 239 inline unsigned getDeadRegState(bool B) { |
219 return B ? RegState::Dead : 0; | 240 return B ? RegState::Dead : 0; |
220 } | 241 } |
221 inline unsigned getUndefRegState(bool B) { | 242 inline unsigned getUndefRegState(bool B) { |
222 return B ? RegState::Undef : 0; | 243 return B ? RegState::Undef : 0; |
223 } | 244 } |
224 | 245 |
225 } // End llvm namespace | 246 } // End llvm namespace |
226 | 247 |
227 #endif | 248 #endif |
OLD | NEW |