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 /// 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 | |
| 16 #include "IceAssemblerMIPS32.h" | 15 #include "IceAssemblerMIPS32.h" |
| 17 #include "IceCfg.h" | 16 #include "IceCfg.h" |
| 18 #include "IceCfgNode.h" | 17 #include "IceCfgNode.h" |
| 19 #include "IceInst.h" | 18 #include "IceInst.h" |
| 20 #include "IceInstMIPS32.h" | 19 #include "IceInstMIPS32.h" |
| 21 #include "IceOperand.h" | 20 #include "IceOperand.h" |
| 22 #include "IceRegistersMIPS32.h" | 21 #include "IceRegistersMIPS32.h" |
| 23 #include "IceTargetLoweringMIPS32.h" | 22 #include "IceTargetLoweringMIPS32.h" |
| 23 #include <limits> | |
| 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 | |
| 52 template <> const char *InstMIPS32Addiu::Opcode = "addiu"; | |
| 53 template <> const char *InstMIPS32Lui::Opcode = "lui"; | |
| 54 template <> const char *InstMIPS32La::Opcode = "la"; | |
| 55 | |
| 56 template <> const char *InstMIPS32Ori::Opcode = "ori"; | |
| 57 | |
| 58 InstMIPS32Mov::InstMIPS32Mov(Cfg *Func, Variable *Dest, Operand *Src) | |
| 59 : InstMIPS32(Func, InstMIPS32::Mov, 2, Dest) { | |
| 60 auto *Dest64 = llvm::dyn_cast<Variable64On32>(Dest); | |
| 61 auto *Src64 = llvm::dyn_cast<Variable64On32>(Src); | |
| 62 | |
| 63 assert(Dest64 == nullptr || Src64 == nullptr); | |
| 64 | |
| 65 if (Dest64 != nullptr) { | |
| 66 // this-> is needed below because there is a parameter named Dest. | |
| 67 this->Dest = Dest64->getLo(); | |
| 68 DestHi = Dest64->getHi(); | |
| 69 } | |
| 70 | |
| 71 if (Src64 == nullptr) { | |
| 72 addSource(Src); | |
| 73 } else { | |
| 74 addSource(Src64->getLo()); | |
| 75 addSource(Src64->getHi()); | |
| 76 } | |
| 77 } | |
| 78 | |
| 32 InstMIPS32Ret::InstMIPS32Ret(Cfg *Func, Variable *RA, Variable *Source) | 79 InstMIPS32Ret::InstMIPS32Ret(Cfg *Func, Variable *RA, Variable *Source) |
| 33 : InstMIPS32(Func, InstMIPS32::Ret, Source ? 2 : 1, nullptr) { | 80 : InstMIPS32(Func, InstMIPS32::Ret, Source ? 2 : 1, nullptr) { |
| 34 addSource(RA); | 81 addSource(RA); |
| 35 if (Source) | 82 if (Source) |
| 36 addSource(Source); | 83 addSource(Source); |
| 37 } | 84 } |
| 38 | 85 |
| 39 // ======================== Dump routines ======================== // | 86 // ======================== Dump routines ======================== // |
| 40 | 87 |
| 41 void InstMIPS32::dump(const Cfg *Func) const { | 88 void InstMIPS32::dump(const Cfg *Func) const { |
| 42 if (!BuildDefs::dump()) | 89 if (!BuildDefs::dump()) |
| 43 return; | 90 return; |
| 44 Ostream &Str = Func->getContext()->getStrDump(); | 91 Ostream &Str = Func->getContext()->getStrDump(); |
| 45 Str << "[MIPS32] "; | 92 Str << "[MIPS32] "; |
| 46 Inst::dump(Func); | 93 Inst::dump(Func); |
| 47 } | 94 } |
| 48 | 95 |
| 96 void OperandMIPS32Mem::emit(const Cfg *Func) const { | |
| 97 if (!BuildDefs::dump()) | |
| 98 return; | |
| 99 llvm_unreachable("Not yet implemented"); | |
| 100 (void)Func; | |
| 101 } | |
| 102 | |
| 103 void InstMIPS32::emitUnaryopGPR(const char *Opcode, const InstMIPS32 *Inst, | |
| 104 const Cfg *Func) { | |
| 105 if (!BuildDefs::dump()) | |
| 106 return; | |
| 107 Ostream &Str = Func->getContext()->getStrEmit(); | |
| 108 // Type SrcTy = Inst->getSrc(0)->getType(); | |
| 109 Str << "\t" << Opcode << "\t"; | |
| 110 Inst->getDest()->emit(Func); | |
| 111 Str << ", "; | |
| 112 Inst->getSrc(0)->emit(Func); | |
| 113 } | |
| 114 | |
| 49 void InstMIPS32Ret::emit(const Cfg *Func) const { | 115 void InstMIPS32Ret::emit(const Cfg *Func) const { |
| 50 if (!BuildDefs::dump()) | 116 if (!BuildDefs::dump()) |
| 51 return; | 117 return; |
| 52 assert(getSrcSize() > 0); | 118 assert(getSrcSize() > 0); |
| 53 Variable *RA = llvm::cast<Variable>(getSrc(0)); | 119 Variable *RA = llvm::cast<Variable>(getSrc(0)); |
| 54 assert(RA->hasReg()); | 120 assert(RA->hasReg()); |
| 55 assert(RA->getRegNum() == RegMIPS32::Reg_RA); | 121 assert(RA->getRegNum() == RegMIPS32::Reg_RA); |
| 56 Ostream &Str = Func->getContext()->getStrEmit(); | 122 Ostream &Str = Func->getContext()->getStrEmit(); |
| 57 Str << "\t" | 123 Str << "\t" |
| 58 << "jr $ra" | 124 << "jr" |
| 59 << "\t"; | 125 << "\t"; |
| 60 RA->emit(Func); | 126 RA->emit(Func); |
| 61 } | 127 } |
| 62 | 128 |
| 63 void InstMIPS32Ret::emitIAS(const Cfg *Func) const { | 129 void InstMIPS32Ret::emitIAS(const Cfg *Func) const { |
| 64 (void)Func; | 130 (void)Func; |
| 65 llvm_unreachable("Not yet implemented"); | 131 llvm_unreachable("Not yet implemented"); |
| 66 } | 132 } |
| 67 | 133 |
| 68 void InstMIPS32Ret::dump(const Cfg *Func) const { | 134 void InstMIPS32Ret::dump(const Cfg *Func) const { |
| 69 if (!BuildDefs::dump()) | 135 if (!BuildDefs::dump()) |
| 70 return; | 136 return; |
| 71 Ostream &Str = Func->getContext()->getStrDump(); | 137 Ostream &Str = Func->getContext()->getStrDump(); |
| 72 Type Ty = (getSrcSize() == 1 ? IceType_void : getSrc(0)->getType()); | 138 Type Ty = (getSrcSize() == 1 ? IceType_void : getSrc(0)->getType()); |
| 73 Str << "ret." << Ty << " "; | 139 Str << "ret." << Ty << " "; |
| 74 dumpSources(Func); | 140 dumpSources(Func); |
| 75 } | 141 } |
| 142 | |
| 143 void InstMIPS32Mov::emit(const Cfg *Func) const { | |
| 144 if (!BuildDefs::dump()) | |
| 145 return; | |
| 146 assert(!(isMultiDest() && isMultiSource()) && "Invalid vmov type."); | |
| 147 if (isMultiDest()) { | |
| 148 emitMultiDestSingleSource(Func); | |
| 149 return; | |
| 150 } | |
| 151 | |
| 152 if (isMultiSource()) { | |
| 153 emitSingleDestMultiSource(Func); | |
| 154 return; | |
| 155 } | |
| 156 | |
| 157 emitSingleDestSingleSource(Func); | |
| 76 } | 158 } |
| 159 | |
| 160 void InstMIPS32Mov::emitIAS(const Cfg *Func) const { | |
| 161 assert(getSrcSize() == 1); | |
| 162 (void)Func; | |
| 163 llvm_unreachable("Not yet implemented"); | |
| 164 } | |
| 165 | |
| 166 void InstMIPS32Mov::dump(const Cfg *Func) const { | |
| 167 if (!BuildDefs::dump()) | |
| 168 return; | |
| 169 assert(getSrcSize() == 1 || getSrcSize() == 2); | |
| 170 Ostream &Str = Func->getContext()->getStrDump(); | |
| 171 Variable *Dest = getDest(); | |
| 172 Variable *DestHi = getDestHi(); | |
| 173 Dest->dump(Func); | |
| 174 if (DestHi) { | |
| 175 Str << ", "; | |
| 176 DestHi->dump(Func); | |
| 177 } | |
| 178 | |
| 179 dumpOpcode(Str, " = mov", getDest()->getType()); | |
| 180 Str << " "; | |
| 181 | |
| 182 dumpSources(Func); | |
| 183 } | |
| 184 | |
| 185 void InstMIPS32Mov::emitMultiDestSingleSource(const Cfg *Func) const { | |
| 186 if (!BuildDefs::dump()) | |
| 187 return; | |
| 188 Ostream &Str = Func->getContext()->getStrEmit(); | |
| 189 Variable *DestLo = getDest(); | |
| 190 Variable *DestHi = getDestHi(); | |
| 191 auto *Src = llvm::cast<Variable>(getSrc(0)); | |
| 192 | |
| 193 assert(DestHi->hasReg()); | |
| 194 assert(DestLo->hasReg()); | |
| 195 assert(llvm::isa<Variable>(Src) && Src->hasReg()); | |
| 196 | |
| 197 // Str << "\t" | |
| 198 // << "vmov" << getPredicate() << "\t"; | |
| 199 DestLo->emit(Func); | |
| 200 Str << ", "; | |
| 201 DestHi->emit(Func); | |
| 202 Str << ", "; | |
| 203 Src->emit(Func); | |
| 204 } | |
| 205 | |
| 206 void InstMIPS32Mov::emitSingleDestMultiSource(const Cfg *Func) const { | |
| 207 if (!BuildDefs::dump()) | |
| 208 return; | |
| 209 Ostream &Str = Func->getContext()->getStrEmit(); | |
| 210 Variable *Dest = getDest(); | |
| 211 Variable *SrcLo = llvm::cast<Variable>(getSrc(0)); | |
| 212 Variable *SrcHi = llvm::cast<Variable>(getSrc(1)); | |
| 213 | |
| 214 assert(SrcHi->hasReg()); | |
| 215 assert(SrcLo->hasReg()); | |
| 216 assert(Dest->hasReg()); | |
| 217 assert(getSrcSize() == 2); | |
| 218 | |
| 219 // Str << "\t" | |
| 220 // << "vmov" << getPredicate() << "\t"; | |
| 221 Dest->emit(Func); | |
| 222 Str << ", "; | |
| 223 SrcLo->emit(Func); | |
| 224 Str << ", "; | |
| 225 SrcHi->emit(Func); | |
| 226 } | |
| 227 | |
| 228 void InstMIPS32Mov::emitSingleDestSingleSource(const Cfg *Func) const { | |
| 229 Ostream &Str = Func->getContext()->getStrEmit(); | |
| 230 // assert(Inst->getSrcSize() == 1); | |
| 231 // Type SrcTy = Inst->getSrc(0)->getType(); | |
| 232 Str << "\t" | |
| 233 << "move" | |
| 234 << "\t"; | |
| 235 getDest()->emit(Func); | |
| 236 Str << ", "; | |
| 237 getSrc(0)->emit(Func); | |
| 238 } | |
| 239 } | |
|
Jim Stichnoth
2015/10/20 04:40:59
add the "end of namespace Ice" comment
rkotlerimgtec
2015/10/21 00:30:53
Done.
| |
| OLD | NEW |