Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- subzero/src/IceInstMIPS32.h - MIPS32 machine instrs --*- C++ -*-----===// | 1 //===- subzero/src/IceInstMIPS32.h - MIPS32 machine instrs --*- C++ -*-----===// |
| 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 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 return Operand->getKind() == static_cast<OperandKind>(kMem); | 103 return Operand->getKind() == static_cast<OperandKind>(kMem); |
| 104 } | 104 } |
| 105 | 105 |
| 106 /// Return true if a load/store instruction for an element of type Ty | 106 /// Return true if a load/store instruction for an element of type Ty |
| 107 /// can encode the Offset directly in the immediate field of the 32-bit | 107 /// can encode the Offset directly in the immediate field of the 32-bit |
| 108 /// MIPS instruction. For some types, if the load is Sign extending, then | 108 /// MIPS instruction. For some types, if the load is Sign extending, then |
| 109 /// the range is reduced. | 109 /// the range is reduced. |
| 110 static bool canHoldOffset(Type Ty, bool SignExt, int32_t Offset); | 110 static bool canHoldOffset(Type Ty, bool SignExt, int32_t Offset); |
| 111 | 111 |
| 112 void dump(const Cfg *Func, Ostream &Str) const override { | 112 void dump(const Cfg *Func, Ostream &Str) const override { |
| 113 (void)Func; | 113 if (!BuildDefs::dump()) |
| 114 (void)Str; | 114 return; |
| 115 Str << "["; | |
| 116 if (Func) | |
| 117 getBase()->dump(Func); | |
| 118 else | |
| 119 getBase()->dump(Str); | |
| 120 Str << ", "; | |
| 121 getOffset()->dump(Func, Str); | |
| 122 Str << "] AddrMode=="; | |
| 123 if (getAddrMode() == Offset) { | |
| 124 Str << "Offset"; | |
| 125 } else { | |
| 126 Str << "Unknown"; | |
| 127 } | |
| 115 } | 128 } |
| 116 | 129 |
| 117 private: | 130 private: |
| 118 OperandMIPS32Mem(Cfg *Func, Type Ty, Variable *Base, Operand *ImmOffset, | 131 OperandMIPS32Mem(Cfg *Func, Type Ty, Variable *Base, Operand *ImmOffset, |
| 119 AddrMode Mode); | 132 AddrMode Mode); |
| 120 | 133 |
| 121 Variable *Base; | 134 Variable *Base; |
| 122 Operand *const ImmOffset; | 135 Operand *const ImmOffset; |
| 123 const AddrMode Mode; | 136 const AddrMode Mode; |
| 124 }; | 137 }; |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 static InstMIPS32Load *create(Cfg *Func, Variable *Value, | 521 static InstMIPS32Load *create(Cfg *Func, Variable *Value, |
| 509 OperandMIPS32Mem *Mem, RelocOp Reloc = RO_No) { | 522 OperandMIPS32Mem *Mem, RelocOp Reloc = RO_No) { |
| 510 return new (Func->allocate<InstMIPS32Load>()) | 523 return new (Func->allocate<InstMIPS32Load>()) |
| 511 InstMIPS32Load(Func, Value, Mem, Reloc); | 524 InstMIPS32Load(Func, Value, Mem, Reloc); |
| 512 } | 525 } |
| 513 | 526 |
| 514 void emit(const Cfg *Func) const override { | 527 void emit(const Cfg *Func) const override { |
| 515 if (!BuildDefs::dump()) | 528 if (!BuildDefs::dump()) |
| 516 return; | 529 return; |
| 517 Ostream &Str = Func->getContext()->getStrEmit(); | 530 Ostream &Str = Func->getContext()->getStrEmit(); |
| 518 assert(getSrcSize() == 1); | 531 const Type Ty = getDest()->getType(); |
| 519 Str << "\t" << Opcode << "\t"; | 532 if (Ty == IceType_i8 || Ty == IceType_i1) { |
|
Jim Stichnoth
2016/09/03 13:47:13
Maybe use a switch statement instead? (here and b
jaydeep.patil
2016/09/04 06:24:30
Done.
| |
| 533 Str << "\t" << "lb" << "\t"; | |
| 534 } else if (Ty == IceType_i16) { | |
| 535 Str << "\t" << "lh" << "\t"; | |
| 536 } else if (Ty == IceType_i32) { | |
| 537 Str << "\t" << "lw" << "\t"; | |
| 538 } else if (Ty == IceType_f32) { | |
| 539 Str << "\t" << "lwc1" << "\t"; | |
| 540 } else if (Ty == IceType_f64) { | |
| 541 Str << "\t" << "ldc1" << "\t"; | |
| 542 } else { | |
| 543 llvm_unreachable("InstMIPS32Load unknown type"); | |
| 544 } | |
| 520 getDest()->emit(Func); | 545 getDest()->emit(Func); |
| 521 Str << ", "; | 546 Str << ", "; |
| 522 emitRelocOp(Str, Reloc); | 547 emitRelocOp(Str, Reloc); |
| 523 getSrc(0)->emit(Func); | 548 getSrc(0)->emit(Func); |
| 524 } | 549 } |
| 525 | 550 |
| 526 void emitIAS(const Cfg *Func) const override { | 551 void emitIAS(const Cfg *Func) const override { |
| 527 (void)Func; | 552 (void)Func; |
| 528 llvm_unreachable("Not yet implemented"); | 553 llvm_unreachable("Not yet implemented"); |
| 529 } | 554 } |
| 530 | 555 |
| 531 void dump(const Cfg *Func) const override { | 556 void dump(const Cfg *Func) const override { |
| 532 if (!BuildDefs::dump()) | 557 if (!BuildDefs::dump()) |
| 533 return; | 558 return; |
| 534 Ostream &Str = Func->getContext()->getStrDump(); | 559 Ostream &Str = Func->getContext()->getStrDump(); |
| 535 Str << "\t" << Opcode << "\t"; | 560 dumpOpcode(Str, Opcode, getDest()->getType()); |
| 561 Str << " "; | |
| 536 getDest()->dump(Func); | 562 getDest()->dump(Func); |
| 537 Str << ", "; | 563 Str << ", "; |
| 538 emitRelocOp(Str, Reloc); | 564 emitRelocOp(Str, Reloc); |
| 539 Str << (Reloc ? "(" : ""); | |
| 540 getSrc(0)->dump(Func); | 565 getSrc(0)->dump(Func); |
| 541 Str << (Reloc ? ")" : ""); | |
| 542 } | 566 } |
| 543 static bool classof(const Inst *Inst) { return isClassof(Inst, K); } | 567 static bool classof(const Inst *Inst) { return isClassof(Inst, K); } |
| 544 | 568 |
| 545 private: | 569 private: |
| 546 InstMIPS32Load(Cfg *Func, Variable *Value, OperandMIPS32Mem *Mem, | 570 InstMIPS32Load(Cfg *Func, Variable *Value, OperandMIPS32Mem *Mem, |
| 547 RelocOp Reloc = RO_No) | 571 RelocOp Reloc = RO_No) |
| 548 : InstMIPS32(Func, K, 2, Value), Reloc(Reloc) { | 572 : InstMIPS32(Func, K, 2, Value), Reloc(Reloc) { |
| 549 addSource(Mem); | 573 addSource(Mem); |
| 550 } | 574 } |
| 551 static const char *Opcode; | 575 static const char *Opcode; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 565 OperandMIPS32Mem *Mem, RelocOp Reloc = RO_No) { | 589 OperandMIPS32Mem *Mem, RelocOp Reloc = RO_No) { |
| 566 return new (Func->allocate<InstMIPS32Store>()) | 590 return new (Func->allocate<InstMIPS32Store>()) |
| 567 InstMIPS32Store(Func, Value, Mem, Reloc); | 591 InstMIPS32Store(Func, Value, Mem, Reloc); |
| 568 } | 592 } |
| 569 | 593 |
| 570 void emit(const Cfg *Func) const override { | 594 void emit(const Cfg *Func) const override { |
| 571 if (!BuildDefs::dump()) | 595 if (!BuildDefs::dump()) |
| 572 return; | 596 return; |
| 573 Ostream &Str = Func->getContext()->getStrEmit(); | 597 Ostream &Str = Func->getContext()->getStrEmit(); |
| 574 assert(getSrcSize() == 2); | 598 assert(getSrcSize() == 2); |
| 575 Str << "\t" << Opcode << "\t"; | 599 const Type Ty = getSrc(0)->getType(); |
| 600 if (Ty == IceType_i8 || Ty == IceType_i1) { | |
| 601 Str << "\t" << "sb" << "\t"; | |
| 602 } else if (Ty == IceType_i16) { | |
| 603 Str << "\t" << "sh" << "\t"; | |
| 604 } else if (Ty == IceType_i32) { | |
| 605 Str << "\t" << "sw" << "\t"; | |
| 606 } else if (Ty == IceType_f32) { | |
| 607 Str << "\t" << "swc1" << "\t"; | |
| 608 } else if (Ty == IceType_f64) { | |
| 609 Str << "\t" << "sdc1" << "\t"; | |
| 610 } else { | |
| 611 llvm_unreachable("InstMIPS32Store unknown type"); | |
| 612 } | |
| 576 getSrc(0)->emit(Func); | 613 getSrc(0)->emit(Func); |
| 577 Str << ", "; | 614 Str << ", "; |
| 578 emitRelocOp(Str, Reloc); | 615 emitRelocOp(Str, Reloc); |
| 579 getSrc(1)->emit(Func); | 616 getSrc(1)->emit(Func); |
| 580 } | 617 } |
| 581 | 618 |
| 582 void emitIAS(const Cfg *Func) const override { | 619 void emitIAS(const Cfg *Func) const override { |
| 583 (void)Func; | 620 (void)Func; |
| 584 llvm_unreachable("Not yet implemented"); | 621 llvm_unreachable("InstMIPS32Store: Not yet implemented"); |
| 585 } | 622 } |
| 586 | 623 |
| 587 void dump(const Cfg *Func) const override { | 624 void dump(const Cfg *Func) const override { |
| 588 if (!BuildDefs::dump()) | 625 if (!BuildDefs::dump()) |
| 589 return; | 626 return; |
| 590 Ostream &Str = Func->getContext()->getStrDump(); | 627 Ostream &Str = Func->getContext()->getStrDump(); |
| 591 Str << "\t" << Opcode << "\t"; | 628 dumpOpcode(Str, Opcode, getSrc(0)->getType()); |
| 629 Str << " "; | |
| 592 getSrc(0)->dump(Func); | 630 getSrc(0)->dump(Func); |
| 593 Str << ", "; | 631 Str << ", "; |
| 594 emitRelocOp(Str, Reloc); | 632 emitRelocOp(Str, Reloc); |
| 595 Str << (Reloc ? "(" : ""); | |
| 596 getSrc(1)->dump(Func); | 633 getSrc(1)->dump(Func); |
| 597 Str << (Reloc ? ")" : ""); | |
| 598 } | 634 } |
| 599 static bool classof(const Inst *Inst) { return isClassof(Inst, K); } | 635 static bool classof(const Inst *Inst) { return isClassof(Inst, K); } |
| 600 | 636 |
| 601 private: | 637 private: |
| 602 InstMIPS32Store(Cfg *Func, Variable *Value, OperandMIPS32Mem *Mem, | 638 InstMIPS32Store(Cfg *Func, Variable *Value, OperandMIPS32Mem *Mem, |
| 603 RelocOp Reloc = RO_No) | 639 RelocOp Reloc = RO_No) |
| 604 : InstMIPS32(Func, K, 2, nullptr), Reloc(Reloc) { | 640 : InstMIPS32(Func, K, 2, nullptr), Reloc(Reloc) { |
| 605 addSource(Value); | 641 addSource(Value); |
| 606 addSource(Mem); | 642 addSource(Mem); |
| 607 } | 643 } |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 768 } | 804 } |
| 769 | 805 |
| 770 void emitIAS(const Cfg *Func) const override { | 806 void emitIAS(const Cfg *Func) const override { |
| 771 (void)Func; | 807 (void)Func; |
| 772 llvm_unreachable("Not yet implemented"); | 808 llvm_unreachable("Not yet implemented"); |
| 773 } | 809 } |
| 774 void dump(const Cfg *Func) const override { | 810 void dump(const Cfg *Func) const override { |
| 775 if (!BuildDefs::dump()) | 811 if (!BuildDefs::dump()) |
| 776 return; | 812 return; |
| 777 Ostream &Str = Func->getContext()->getStrDump(); | 813 Ostream &Str = Func->getContext()->getStrDump(); |
| 814 dumpOpcode(Str, Opcode, getDest()->getType()); | |
| 778 Str << " "; | 815 Str << " "; |
| 779 Str << "\t" << Opcode << "\t"; | |
| 780 dumpDest(Func); | 816 dumpDest(Func); |
| 781 Str << ", "; | 817 Str << ", "; |
| 782 dumpSources(Func); | 818 dumpSources(Func); |
| 819 Str << ", "; | |
| 783 if (Signed) | 820 if (Signed) |
| 784 Str << (int32_t)Imm; | 821 Str << (int32_t)Imm; |
| 785 else | 822 else |
| 786 Str << Imm; | 823 Str << Imm; |
| 787 } | 824 } |
| 788 | 825 |
| 789 static bool classof(const Inst *Inst) { return isClassof(Inst, K); } | 826 static bool classof(const Inst *Inst) { return isClassof(Inst, K); } |
| 790 | 827 |
| 791 private: | 828 private: |
| 792 InstMIPS32Imm16(Cfg *Func, Variable *Dest, Operand *Source, uint32_t Imm) | 829 InstMIPS32Imm16(Cfg *Func, Variable *Dest, Operand *Source, uint32_t Imm) |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 912 template <> void InstMIPS32Mtlo::emit(const Cfg *Func) const; | 949 template <> void InstMIPS32Mtlo::emit(const Cfg *Func) const; |
| 913 template <> void InstMIPS32Mthi::emit(const Cfg *Func) const; | 950 template <> void InstMIPS32Mthi::emit(const Cfg *Func) const; |
| 914 template <> void InstMIPS32Mult::emit(const Cfg *Func) const; | 951 template <> void InstMIPS32Mult::emit(const Cfg *Func) const; |
| 915 template <> void InstMIPS32Multu::emit(const Cfg *Func) const; | 952 template <> void InstMIPS32Multu::emit(const Cfg *Func) const; |
| 916 template <> void InstMIPS32Lui::emit(const Cfg *Func) const; | 953 template <> void InstMIPS32Lui::emit(const Cfg *Func) const; |
| 917 | 954 |
| 918 } // end of namespace MIPS32 | 955 } // end of namespace MIPS32 |
| 919 } // end of namespace Ice | 956 } // end of namespace Ice |
| 920 | 957 |
| 921 #endif // SUBZERO_SRC_ICEINSTMIPS32_H | 958 #endif // SUBZERO_SRC_ICEINSTMIPS32_H |
| OLD | NEW |