OLD | NEW |
---|---|
1 //===- subzero/src/IceInstMips32.cpp - Mips32 instruction implementation --===// | 1 //===- subzero/src/IceInstMips32.cpp - Mips32 instruction implementation --===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
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 /// \file | 10 /// \file |
11 /// This file implements the InstMips32 and OperandMips32 classes, primarily the | 11 /// This file implements the InstMips32 and OperandMips32 classes, primarily the |
12 /// constructors and the dump()/emit() methods. | 12 /// constructors and the dump()/emit() methods. |
13 /// | 13 /// |
14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
15 | 15 #include <limits> |
Jim Stichnoth
2015/10/18 11:48:38
Generally our include order is:
#include "Ice*.h"
rkotlerimgtec
2015/10/19 00:11:59
Done.
| |
16 #include "IceAssemblerMIPS32.h" | 16 #include "IceAssemblerMIPS32.h" |
17 #include "IceCfg.h" | 17 #include "IceCfg.h" |
18 #include "IceCfgNode.h" | 18 #include "IceCfgNode.h" |
19 #include "IceInst.h" | 19 #include "IceInst.h" |
20 #include "IceInstMIPS32.h" | 20 #include "IceInstMIPS32.h" |
21 #include "IceOperand.h" | 21 #include "IceOperand.h" |
22 #include "IceRegistersMIPS32.h" | 22 #include "IceRegistersMIPS32.h" |
23 #include "IceTargetLoweringMIPS32.h" | 23 #include "IceTargetLoweringMIPS32.h" |
24 | 24 |
25 namespace Ice { | 25 namespace Ice { |
26 | 26 |
27 bool OperandMIPS32Mem::canHoldOffset(Type Ty, bool SignExt, int32_t Offset) { | |
28 (void)SignExt; | |
29 (void)Ty; | |
30 if ((std::numeric_limits<int16_t>::min() <= Offset) && | |
31 (Offset <= std::numeric_limits<int16_t>::max())) | |
32 return true; | |
33 return false; | |
34 } | |
35 | |
36 OperandMIPS32Mem::OperandMIPS32Mem(Cfg *Func, Type Ty, Variable *Base, | |
37 ConstantInteger32 *ImmOffset, AddrMode Mode) | |
38 : OperandMIPS32(kMem, Ty), Base(Base), ImmOffset(ImmOffset), Mode(Mode) { | |
39 // The Neg modes are only needed for Reg +/- Reg. | |
40 (void)Func; | |
41 // assert(!isNegAddrMode()); | |
42 NumVars = 1; | |
43 Vars = &this->Base; | |
44 } | |
45 | |
27 const char *InstMIPS32::getWidthString(Type Ty) { | 46 const char *InstMIPS32::getWidthString(Type Ty) { |
28 (void)Ty; | 47 (void)Ty; |
29 return "TBD"; | 48 return "TBD"; |
30 } | 49 } |
31 | 50 |
51 void InstMIPS32::emitUnaryopGPR(const char *Opcode, const InstMIPS32 *Inst, | |
Jim Stichnoth
2015/10/18 11:48:37
Dump and textual emit routines usually go at the e
rkotlerimgtec
2015/10/19 00:11:59
Done.
| |
52 const Cfg *Func) { | |
53 Ostream &Str = Func->getContext()->getStrEmit(); | |
Jim Stichnoth
2015/10/18 11:48:37
Add the following to the beginning of all dump() a
rkotlerimgtec
2015/10/19 00:11:59
Done.
| |
54 // assert(Inst->getSrcSize() == 1); | |
Jim Stichnoth
2015/10/18 11:48:37
Don't leave commented-out code in the code base.
rkotlerimgtec
2015/10/19 00:11:59
Done.
| |
55 // Type SrcTy = Inst->getSrc(0)->getType(); | |
56 Str << "\t" << Opcode << "\t"; | |
57 Inst->getDest()->emit(Func); | |
58 Str << ", "; | |
59 Inst->getSrc(0)->emit(Func); | |
60 } | |
61 | |
62 template <> const char *InstMIPS32Addiu::Opcode = "addiu"; | |
63 template <> const char *InstMIPS32Lui::Opcode = "lui"; | |
64 template <> const char *InstMIPS32La::Opcode = "la"; | |
65 | |
66 template <> const char *InstMIPS32Ori::Opcode = "ori"; | |
67 | |
68 InstMIPS32Mov::InstMIPS32Mov(Cfg *Func, Variable *Dest, Operand *Src) | |
69 : InstMIPS32(Func, InstMIPS32::Mov, 2, Dest) { | |
70 auto *Dest64 = llvm::dyn_cast<Variable64On32>(Dest); | |
71 auto *Src64 = llvm::dyn_cast<Variable64On32>(Src); | |
72 | |
73 assert(Dest64 == nullptr || Src64 == nullptr); | |
74 | |
75 if (Dest64 != nullptr) { | |
76 // this-> is needed below because there is a parameter named Dest. | |
77 this->Dest = Dest64->getLo(); | |
78 DestHi = Dest64->getHi(); | |
79 } | |
80 | |
81 if (Src64 == nullptr) { | |
82 addSource(Src); | |
83 } else { | |
84 addSource(Src64->getLo()); | |
85 addSource(Src64->getHi()); | |
86 } | |
87 } | |
88 | |
32 InstMIPS32Ret::InstMIPS32Ret(Cfg *Func, Variable *RA, Variable *Source) | 89 InstMIPS32Ret::InstMIPS32Ret(Cfg *Func, Variable *RA, Variable *Source) |
33 : InstMIPS32(Func, InstMIPS32::Ret, Source ? 2 : 1, nullptr) { | 90 : InstMIPS32(Func, InstMIPS32::Ret, Source ? 2 : 1, nullptr) { |
34 addSource(RA); | 91 addSource(RA); |
35 if (Source) | 92 if (Source) |
36 addSource(Source); | 93 addSource(Source); |
37 } | 94 } |
38 | 95 |
39 // ======================== Dump routines ======================== // | 96 // ======================== Dump routines ======================== // |
40 | 97 |
41 void InstMIPS32::dump(const Cfg *Func) const { | 98 void InstMIPS32::dump(const Cfg *Func) const { |
42 if (!BuildDefs::dump()) | 99 if (!BuildDefs::dump()) |
43 return; | 100 return; |
44 Ostream &Str = Func->getContext()->getStrDump(); | 101 Ostream &Str = Func->getContext()->getStrDump(); |
45 Str << "[MIPS32] "; | 102 Str << "[MIPS32] "; |
46 Inst::dump(Func); | 103 Inst::dump(Func); |
47 } | 104 } |
48 | 105 |
106 void OperandMIPS32Mem::emit(const Cfg *Func) const { | |
107 if (!BuildDefs::dump()) | |
108 return; | |
109 llvm_unreachable("Not yet implemented"); | |
110 (void)Func; | |
111 } | |
112 | |
49 void InstMIPS32Ret::emit(const Cfg *Func) const { | 113 void InstMIPS32Ret::emit(const Cfg *Func) const { |
50 if (!BuildDefs::dump()) | 114 if (!BuildDefs::dump()) |
51 return; | 115 return; |
52 assert(getSrcSize() > 0); | 116 assert(getSrcSize() > 0); |
53 Variable *RA = llvm::cast<Variable>(getSrc(0)); | 117 Variable *RA = llvm::cast<Variable>(getSrc(0)); |
54 assert(RA->hasReg()); | 118 assert(RA->hasReg()); |
55 assert(RA->getRegNum() == RegMIPS32::Reg_RA); | 119 assert(RA->getRegNum() == RegMIPS32::Reg_RA); |
56 Ostream &Str = Func->getContext()->getStrEmit(); | 120 Ostream &Str = Func->getContext()->getStrEmit(); |
57 Str << "\t" | 121 Str << "\t" |
58 << "jr $ra" | 122 << "jr" |
59 << "\t"; | 123 << "\t"; |
60 RA->emit(Func); | 124 RA->emit(Func); |
125 Str << "\n"; | |
Jim Stichnoth
2015/10/18 11:48:38
Usually the emit() routine doesn't print the endin
rkotlerimgtec
2015/10/19 00:11:59
Done.
| |
61 } | 126 } |
62 | 127 |
63 void InstMIPS32Ret::emitIAS(const Cfg *Func) const { | 128 void InstMIPS32Ret::emitIAS(const Cfg *Func) const { |
64 (void)Func; | 129 (void)Func; |
65 llvm_unreachable("Not yet implemented"); | 130 llvm_unreachable("Not yet implemented"); |
66 } | 131 } |
67 | 132 |
68 void InstMIPS32Ret::dump(const Cfg *Func) const { | 133 void InstMIPS32Ret::dump(const Cfg *Func) const { |
69 if (!BuildDefs::dump()) | 134 if (!BuildDefs::dump()) |
70 return; | 135 return; |
71 Ostream &Str = Func->getContext()->getStrDump(); | 136 Ostream &Str = Func->getContext()->getStrDump(); |
72 Type Ty = (getSrcSize() == 1 ? IceType_void : getSrc(0)->getType()); | 137 Type Ty = (getSrcSize() == 1 ? IceType_void : getSrc(0)->getType()); |
73 Str << "ret." << Ty << " "; | 138 Str << "ret." << Ty << " "; |
74 dumpSources(Func); | 139 dumpSources(Func); |
75 } | 140 } |
141 | |
142 void InstMIPS32Mov::emit(const Cfg *Func) const { | |
143 if (!BuildDefs::dump()) | |
144 return; | |
145 assert(!(isMultiDest() && isMultiSource()) && "Invalid vmov type."); | |
146 if (isMultiDest()) { | |
147 emitMultiDestSingleSource(Func); | |
148 return; | |
149 } | |
150 | |
151 if (isMultiSource()) { | |
152 emitSingleDestMultiSource(Func); | |
153 return; | |
154 } | |
155 | |
156 emitSingleDestSingleSource(Func); | |
76 } | 157 } |
158 | |
159 void InstMIPS32Mov::emitIAS(const Cfg *Func) const { | |
160 assert(getSrcSize() == 1); | |
161 (void)Func; | |
162 llvm_unreachable("Not yet implemented"); | |
163 } | |
164 | |
165 void InstMIPS32Mov::dump(const Cfg *Func) const { | |
166 if (!BuildDefs::dump()) | |
167 return; | |
168 assert(getSrcSize() == 1 || getSrcSize() == 2); | |
169 Ostream &Str = Func->getContext()->getStrDump(); | |
170 Variable *Dest = getDest(); | |
171 Variable *DestHi = getDestHi(); | |
172 Dest->dump(Func); | |
173 if (DestHi) { | |
174 Str << ", "; | |
175 DestHi->dump(Func); | |
176 } | |
177 | |
178 dumpOpcode(Str, " = mov", getDest()->getType()); | |
179 Str << " "; | |
180 | |
181 dumpSources(Func); | |
182 } | |
183 | |
184 void InstMIPS32Mov::emitMultiDestSingleSource(const Cfg *Func) const { | |
185 if (!BuildDefs::dump()) | |
186 return; | |
187 Ostream &Str = Func->getContext()->getStrEmit(); | |
188 Variable *DestLo = getDest(); | |
189 Variable *DestHi = getDestHi(); | |
190 auto *Src = llvm::cast<Variable>(getSrc(0)); | |
191 | |
192 assert(DestHi->hasReg()); | |
193 assert(DestLo->hasReg()); | |
194 assert(llvm::isa<Variable>(Src) && Src->hasReg()); | |
195 | |
196 // Str << "\t" | |
197 // << "vmov" << getPredicate() << "\t"; | |
198 DestLo->emit(Func); | |
199 Str << ", "; | |
200 DestHi->emit(Func); | |
201 Str << ", "; | |
202 Src->emit(Func); | |
203 } | |
204 | |
205 void InstMIPS32Mov::emitSingleDestMultiSource(const Cfg *Func) const { | |
206 if (!BuildDefs::dump()) | |
207 return; | |
208 Ostream &Str = Func->getContext()->getStrEmit(); | |
209 Variable *Dest = getDest(); | |
210 Variable *SrcLo = llvm::cast<Variable>(getSrc(0)); | |
211 Variable *SrcHi = llvm::cast<Variable>(getSrc(1)); | |
212 | |
213 assert(SrcHi->hasReg()); | |
214 assert(SrcLo->hasReg()); | |
215 assert(Dest->hasReg()); | |
216 assert(getSrcSize() == 2); | |
217 | |
218 // Str << "\t" | |
219 // << "vmov" << getPredicate() << "\t"; | |
220 Dest->emit(Func); | |
221 Str << ", "; | |
222 SrcLo->emit(Func); | |
223 Str << ", "; | |
224 SrcHi->emit(Func); | |
225 } | |
226 | |
227 void InstMIPS32Mov::emitSingleDestSingleSource(const Cfg *Func) const { | |
228 Ostream &Str = Func->getContext()->getStrEmit(); | |
229 // assert(Inst->getSrcSize() == 1); | |
230 // Type SrcTy = Inst->getSrc(0)->getType(); | |
231 Str << "\t" | |
232 << "move" | |
233 << "\t"; | |
234 getDest()->emit(Func); | |
235 Str << ", "; | |
236 getSrc(0)->emit(Func); | |
237 } | |
238 } | |
OLD | NEW |