Chromium Code Reviews| 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 /// \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, 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 Loading... | |
| 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 const InstMIPS32Label *Label, CondMIPS32::Cond Cond) | |
| 127 : InstMIPS32(Func, InstMIPS32::Br, 2, nullptr), TargetTrue(TargetTrue), | |
|
Jim Stichnoth
2016/05/23 19:53:05
s/2/1/
sagar.thakur
2016/05/24 05:44:36
Done.
| |
| 128 TargetFalse(TargetFalse), Label(Label), Predicate(Cond) { | |
| 129 addSource(Src0); | |
| 130 } | |
| 131 | |
| 132 InstMIPS32Br::InstMIPS32Br(Cfg *Func, const CfgNode *TargetTrue, | |
| 133 const CfgNode *TargetFalse, Operand *Src0, | |
| 134 Operand *Src1, const InstMIPS32Label *Label, | |
| 135 CondMIPS32::Cond Cond) | |
| 136 : InstMIPS32(Func, InstMIPS32::Br, 2, nullptr), TargetTrue(TargetTrue), | |
| 137 TargetFalse(TargetFalse), Label(Label), Predicate(Cond) { | |
| 138 addSource(Src0); | |
| 139 addSource(Src1); | |
| 140 } | |
| 141 | |
| 142 InstMIPS32Br::InstMIPS32Br(Cfg *Func, const CfgNode *TargetTrue, | |
| 114 const CfgNode *TargetFalse, | 143 const CfgNode *TargetFalse, |
| 115 const InstMIPS32Label *Label) | 144 const InstMIPS32Label *Label, CondMIPS32::Cond Cond) |
| 116 : InstMIPS32(Func, InstMIPS32::Br, 0, nullptr), TargetTrue(TargetTrue), | 145 : InstMIPS32(Func, InstMIPS32::Br, 0, nullptr), TargetTrue(TargetTrue), |
| 117 TargetFalse(TargetFalse), Label(Label) {} | 146 TargetFalse(TargetFalse), Label(Label), Predicate(Cond) {} |
| 118 | 147 |
| 119 InstMIPS32Label::InstMIPS32Label(Cfg *Func, TargetMIPS32 *Target) | 148 InstMIPS32Label::InstMIPS32Label(Cfg *Func, TargetMIPS32 *Target) |
| 120 : InstMIPS32(Func, InstMIPS32::Label, 0, nullptr), | 149 : InstMIPS32(Func, InstMIPS32::Label, 0, nullptr), |
| 121 Number(Target->makeNextLabelNumber()) { | 150 Number(Target->makeNextLabelNumber()) { |
| 122 if (BuildDefs::dump()) { | 151 if (BuildDefs::dump()) { |
| 123 Name = GlobalString::createWithString( | 152 Name = GlobalString::createWithString( |
| 124 Func->getContext(), | 153 Func->getContext(), |
| 125 ".L" + Func->getFunctionName() + "$local$__" + std::to_string(Number)); | 154 ".L" + Func->getFunctionName() + "$local$__" + std::to_string(Number)); |
| 126 } else { | 155 } else { |
| 127 Name = GlobalString::createWithoutString(Func->getContext()); | 156 Name = GlobalString::createWithoutString(Func->getContext()); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 "jr" | 293 "jr" |
| 265 "\t"; | 294 "\t"; |
| 266 RA->emit(Func); | 295 RA->emit(Func); |
| 267 } | 296 } |
| 268 | 297 |
| 269 void InstMIPS32Br::emit(const Cfg *Func) const { | 298 void InstMIPS32Br::emit(const Cfg *Func) const { |
| 270 if (!BuildDefs::dump()) | 299 if (!BuildDefs::dump()) |
| 271 return; | 300 return; |
| 272 Ostream &Str = Func->getContext()->getStrEmit(); | 301 Ostream &Str = Func->getContext()->getStrEmit(); |
| 273 Str << "\t" | 302 Str << "\t" |
| 274 "b" | 303 "b" << InstMIPS32CondAttributes[Predicate].EmitString << "\t"; |
| 275 << "\t"; | |
| 276 if (Label) { | 304 if (Label) { |
| 277 Str << Label->getLabelName(); | 305 Str << Label->getLabelName(); |
| 278 } else { | 306 } else { |
| 279 if (isUnconditionalBranch()) { | 307 if (isUnconditionalBranch()) { |
| 280 Str << getTargetFalse()->getAsmName(); | 308 Str << getTargetFalse()->getAsmName(); |
| 281 } else { | 309 } else { |
| 282 // TODO(reed kotler): Finish implementing conditional branch. | 310 switch (Predicate) { |
| 311 default: | |
| 312 break; | |
| 313 case CondMIPS32::EQ: | |
| 314 case CondMIPS32::NE: { | |
| 315 getSrc(0)->emit(Func); | |
| 316 Str << ", "; | |
| 317 getSrc(1)->emit(Func); | |
| 318 Str << ", "; | |
| 319 break; | |
| 320 } | |
| 321 case CondMIPS32::EQZ: | |
| 322 case CondMIPS32::NEZ: | |
| 323 case CondMIPS32::LEZ: | |
| 324 case CondMIPS32::LTZ: | |
| 325 case CondMIPS32::GEZ: | |
| 326 case CondMIPS32::GTZ: { | |
| 327 getSrc(0)->emit(Func); | |
| 328 Str << ", "; | |
| 329 break; | |
| 330 } | |
| 331 } | |
| 332 Str << getTargetFalse()->getAsmName(); | |
| 283 } | 333 } |
| 284 } | 334 } |
| 285 } | 335 } |
| 336 | |
| 337 void InstMIPS32Br::dump(const Cfg *Func) const { | |
| 338 if (!BuildDefs::dump()) | |
| 339 return; | |
| 340 Ostream &Str = Func->getContext()->getStrDump(); | |
| 341 Str << "\t" | |
| 342 "b" << InstMIPS32CondAttributes[Predicate].EmitString << "\t"; | |
| 343 | |
| 344 if (Label) { | |
| 345 Str << Label->getLabelName(); | |
| 346 } else { | |
| 347 if (isUnconditionalBranch()) { | |
| 348 Str << getTargetFalse()->getAsmName(); | |
| 349 } else { | |
| 350 dumpSources(Func); | |
| 351 Str << ", "; | |
| 352 Str << getTargetFalse()->getAsmName(); | |
| 353 } | |
| 354 } | |
| 355 } | |
| 286 | 356 |
| 287 void InstMIPS32Call::emit(const Cfg *Func) const { | 357 void InstMIPS32Call::emit(const Cfg *Func) const { |
| 288 if (!BuildDefs::dump()) | 358 if (!BuildDefs::dump()) |
| 289 return; | 359 return; |
| 290 Ostream &Str = Func->getContext()->getStrEmit(); | 360 Ostream &Str = Func->getContext()->getStrEmit(); |
| 291 assert(getSrcSize() == 1); | 361 assert(getSrcSize() == 1); |
| 292 if (llvm::isa<ConstantInteger32>(getCallTarget())) { | 362 if (llvm::isa<ConstantInteger32>(getCallTarget())) { |
| 293 // This shouldn't happen (typically have to copy the full 32-bits to a | 363 // This shouldn't happen (typically have to copy the full 32-bits to a |
| 294 // register and do an indirect jump). | 364 // register and do an indirect jump). |
| 295 llvm::report_fatal_error("MIPS2Call to ConstantInteger32"); | 365 llvm::report_fatal_error("MIPS2Call to ConstantInteger32"); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 } | 521 } |
| 452 | 522 |
| 453 Str << "\t"; | 523 Str << "\t"; |
| 454 getDest()->emit(Func); | 524 getDest()->emit(Func); |
| 455 Str << ", "; | 525 Str << ", "; |
| 456 getSrc(0)->emit(Func); | 526 getSrc(0)->emit(Func); |
| 457 } | 527 } |
| 458 | 528 |
| 459 } // end of namespace MIPS32 | 529 } // end of namespace MIPS32 |
| 460 } // end of namespace Ice | 530 } // end of namespace Ice |
| OLD | NEW |