Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/IceInstMIPS32.cpp

Issue 1993773004: [Subzero][MIPS32] Addition of bool folding machinery and implementation of conditional branches (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Added tests for eq and ne branches and corrected branch target label emission Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 /// \brief Implements the InstMips32 and OperandMips32 classes, primarily the 11 /// \brief 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 #include "IceAssemblerMIPS32.h" 15 #include "IceAssemblerMIPS32.h"
16 #include "IceCfg.h" 16 #include "IceCfg.h"
17 #include "IceCfgNode.h" 17 #include "IceCfgNode.h"
18 #include "IceInst.h" 18 #include "IceInst.h"
19 #include "IceInstMIPS32.h" 19 #include "IceInstMIPS32.h"
20 #include "IceOperand.h" 20 #include "IceOperand.h"
21 #include "IceRegistersMIPS32.h" 21 #include "IceRegistersMIPS32.h"
22 #include "IceTargetLoweringMIPS32.h" 22 #include "IceTargetLoweringMIPS32.h"
23 #include <limits> 23 #include <limits>
24 24
25 namespace Ice { 25 namespace Ice {
26 namespace MIPS32 { 26 namespace MIPS32 {
27 27
28 const struct InstMIPS32CondAttributes_ {
29 CondMIPS32::Cond Opposite;
30 const char *EmitString;
31 } InstMIPS32CondAttributes[] = {
32 #define X(tag, encode, opp, emit) \
33 { CondMIPS32::opp, emit } \
34 ,
35 ICEINSTMIPS32COND_TABLE
36 #undef X
37 };
38
28 bool OperandMIPS32Mem::canHoldOffset(Type Ty, bool SignExt, int32_t Offset) { 39 bool OperandMIPS32Mem::canHoldOffset(Type Ty, bool SignExt, int32_t Offset) {
29 (void)SignExt; 40 (void)SignExt;
30 (void)Ty; 41 (void)Ty;
31 if ((std::numeric_limits<int16_t>::min() <= Offset) && 42 if ((std::numeric_limits<int16_t>::min() <= Offset) &&
32 (Offset <= std::numeric_limits<int16_t>::max())) 43 (Offset <= std::numeric_limits<int16_t>::max()))
33 return true; 44 return true;
34 return false; 45 return false;
35 } 46 }
36 47
37 OperandMIPS32Mem::OperandMIPS32Mem(Cfg *Func, Type Ty, Variable *Base, 48 OperandMIPS32Mem::OperandMIPS32Mem(Cfg *Func, Type Ty, Variable *Base,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 emitThreeAddrLoHi(Opcode, this, Func); 115 emitThreeAddrLoHi(Opcode, this, Func);
105 } 116 }
106 117
107 template <> void InstMIPS32Multu::emit(const Cfg *Func) const { 118 template <> void InstMIPS32Multu::emit(const Cfg *Func) const {
108 if (!BuildDefs::dump()) 119 if (!BuildDefs::dump())
109 return; 120 return;
110 emitThreeAddrLoHi(Opcode, this, Func); 121 emitThreeAddrLoHi(Opcode, this, Func);
111 } 122 }
112 123
113 InstMIPS32Br::InstMIPS32Br(Cfg *Func, const CfgNode *TargetTrue, 124 InstMIPS32Br::InstMIPS32Br(Cfg *Func, const CfgNode *TargetTrue,
125 const CfgNode *TargetFalse, Operand *Src0,
126 Operand *Src1, const InstMIPS32Label *Label,
Jim Stichnoth 2016/05/19 15:03:40 In ICE there's a pretty strong assumption/pattern
sagar.thakur 2016/05/23 18:30:25 Done.
127 CondMIPS32::Cond Cond)
128 : InstMIPS32(Func, InstMIPS32::Br, 2, nullptr), TargetTrue(TargetTrue),
129 TargetFalse(TargetFalse), Label(Label), Predicate(Cond) {
130 addSource(Src0);
131 if (Src1 != NULL)
Jim Stichnoth 2016/05/19 15:03:40 nullptr
sagar.thakur 2016/05/23 18:30:25 Done.
132 addSource(Src1);
133 }
134
135 InstMIPS32Br::InstMIPS32Br(Cfg *Func, const CfgNode *TargetTrue,
114 const CfgNode *TargetFalse, 136 const CfgNode *TargetFalse,
115 const InstMIPS32Label *Label) 137 const InstMIPS32Label *Label, CondMIPS32::Cond Cond)
116 : InstMIPS32(Func, InstMIPS32::Br, 0, nullptr), TargetTrue(TargetTrue), 138 : InstMIPS32(Func, InstMIPS32::Br, 0, nullptr), TargetTrue(TargetTrue),
117 TargetFalse(TargetFalse), Label(Label) {} 139 TargetFalse(TargetFalse), Label(Label), Predicate(Cond) {}
118 140
119 InstMIPS32Label::InstMIPS32Label(Cfg *Func, TargetMIPS32 *Target) 141 InstMIPS32Label::InstMIPS32Label(Cfg *Func, TargetMIPS32 *Target)
120 : InstMIPS32(Func, InstMIPS32::Label, 0, nullptr), 142 : InstMIPS32(Func, InstMIPS32::Label, 0, nullptr),
121 Number(Target->makeNextLabelNumber()) { 143 Number(Target->makeNextLabelNumber()) {
122 if (BuildDefs::dump()) { 144 if (BuildDefs::dump()) {
123 Name = GlobalString::createWithString( 145 Name = GlobalString::createWithString(
124 Func->getContext(), 146 Func->getContext(),
125 ".L" + Func->getFunctionName() + "$local$__" + std::to_string(Number)); 147 ".L" + Func->getFunctionName() + "$local$__" + std::to_string(Number));
126 } else { 148 } else {
127 Name = GlobalString::createWithoutString(Func->getContext()); 149 Name = GlobalString::createWithoutString(Func->getContext());
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 "jr" 286 "jr"
265 "\t"; 287 "\t";
266 RA->emit(Func); 288 RA->emit(Func);
267 } 289 }
268 290
269 void InstMIPS32Br::emit(const Cfg *Func) const { 291 void InstMIPS32Br::emit(const Cfg *Func) const {
270 if (!BuildDefs::dump()) 292 if (!BuildDefs::dump())
271 return; 293 return;
272 Ostream &Str = Func->getContext()->getStrEmit(); 294 Ostream &Str = Func->getContext()->getStrEmit();
273 Str << "\t" 295 Str << "\t"
274 "b" 296 "b" << InstMIPS32CondAttributes[Predicate].EmitString << "\t";
275 << "\t";
276 if (Label) { 297 if (Label) {
277 Str << Label->getLabelName(); 298 Str << Label->getLabelName();
278 } else { 299 } else {
279 if (isUnconditionalBranch()) { 300 if (isUnconditionalBranch()) {
280 Str << getTargetFalse()->getAsmName(); 301 Str << getTargetFalse()->getAsmName();
281 } else { 302 } else {
282 // TODO(reed kotler): Finish implementing conditional branch. 303 switch (Predicate) {
304 default:
305 break;
306 case CondMIPS32::EQ:
307 case CondMIPS32::NE: {
308 getSrc(0)->emit(Func);
309 Str << ", ";
310 getSrc(1)->emit(Func);
311 Str << ", ";
312 break;
313 }
314 case CondMIPS32::EQZ:
315 case CondMIPS32::NEZ:
316 case CondMIPS32::LEZ:
317 case CondMIPS32::LTZ:
318 case CondMIPS32::GEZ:
319 case CondMIPS32::GTZ: {
320 getSrc(0)->emit(Func);
321 Str << ", ";
322 break;
323 }
324 }
325 Str << getTargetFalse()->getAsmName();
283 } 326 }
284 } 327 }
328 return;
Jim Stichnoth 2016/05/19 15:03:40 this "return" is unnecessary, remove
sagar.thakur 2016/05/23 18:30:25 Done.
285 } 329 }
286 330
287 void InstMIPS32Call::emit(const Cfg *Func) const { 331 void InstMIPS32Call::emit(const Cfg *Func) const {
288 if (!BuildDefs::dump()) 332 if (!BuildDefs::dump())
289 return; 333 return;
290 Ostream &Str = Func->getContext()->getStrEmit(); 334 Ostream &Str = Func->getContext()->getStrEmit();
291 assert(getSrcSize() == 1); 335 assert(getSrcSize() == 1);
292 if (llvm::isa<ConstantInteger32>(getCallTarget())) { 336 if (llvm::isa<ConstantInteger32>(getCallTarget())) {
293 // This shouldn't happen (typically have to copy the full 32-bits to a 337 // This shouldn't happen (typically have to copy the full 32-bits to a
294 // register and do an indirect jump). 338 // register and do an indirect jump).
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 } 495 }
452 496
453 Str << "\t"; 497 Str << "\t";
454 getDest()->emit(Func); 498 getDest()->emit(Func);
455 Str << ", "; 499 Str << ", ";
456 getSrc(0)->emit(Func); 500 getSrc(0)->emit(Func);
457 } 501 }
458 502
459 } // end of namespace MIPS32 503 } // end of namespace MIPS32
460 } // end of namespace Ice 504 } // end of namespace Ice
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698