| OLD | NEW |
| 1 //===- subzero/src/IceInstX8632.cpp - X86-32 instruction implementation ---===// | 1 //===- subzero/src/IceInstX8632.cpp - X86-32 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 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "IceCfg.h" | 21 #include "IceCfg.h" |
| 22 #include "IceCfgNode.h" | 22 #include "IceCfgNode.h" |
| 23 #include "IceConditionCodesX8632.h" | 23 #include "IceConditionCodesX8632.h" |
| 24 #include "IceInst.h" | 24 #include "IceInst.h" |
| 25 #include "IceRegistersX8632.h" | 25 #include "IceRegistersX8632.h" |
| 26 #include "IceTargetLoweringX8632.h" | 26 #include "IceTargetLoweringX8632.h" |
| 27 #include "IceOperand.h" | 27 #include "IceOperand.h" |
| 28 | 28 |
| 29 namespace Ice { | 29 namespace Ice { |
| 30 | 30 |
| 31 namespace X86Internal { | 31 namespace X8632 { |
| 32 | 32 |
| 33 const MachineTraits<TargetX8632>::InstBrAttributesType | 33 const TargetX8632Traits::InstBrAttributesType |
| 34 MachineTraits<TargetX8632>::InstBrAttributes[] = { | 34 TargetX8632Traits::InstBrAttributes[] = { |
| 35 #define X(val, encode, opp, dump, emit) \ | 35 #define X(val, encode, opp, dump, emit) \ |
| 36 { X8632::Traits::Cond::opp, dump, emit } \ | 36 { X8632::Traits::Cond::opp, dump, emit } \ |
| 37 , | 37 , |
| 38 ICEINSTX8632BR_TABLE | 38 ICEINSTX8632BR_TABLE |
| 39 #undef X | 39 #undef X |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 const MachineTraits<TargetX8632>::InstCmppsAttributesType | 42 const TargetX8632Traits::InstCmppsAttributesType |
| 43 MachineTraits<TargetX8632>::InstCmppsAttributes[] = { | 43 TargetX8632Traits::InstCmppsAttributes[] = { |
| 44 #define X(val, emit) \ | 44 #define X(val, emit) \ |
| 45 { emit } \ | 45 { emit } \ |
| 46 , | 46 , |
| 47 ICEINSTX8632CMPPS_TABLE | 47 ICEINSTX8632CMPPS_TABLE |
| 48 #undef X | 48 #undef X |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 const MachineTraits<TargetX8632>::TypeAttributesType | 51 const TargetX8632Traits::TypeAttributesType |
| 52 MachineTraits<TargetX8632>::TypeAttributes[] = { | 52 TargetX8632Traits::TypeAttributes[] = { |
| 53 #define X(tag, elementty, cvt, sdss, pdps, spsd, pack, width, fld) \ | 53 #define X(tag, elementty, cvt, sdss, pdps, spsd, pack, width, fld) \ |
| 54 { cvt, sdss, pdps, spsd, pack, width, fld } \ | 54 { cvt, sdss, pdps, spsd, pack, width, fld } \ |
| 55 , | 55 , |
| 56 ICETYPEX8632_TABLE | 56 ICETYPEX8632_TABLE |
| 57 #undef X | 57 #undef X |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 const char *MachineTraits<TargetX8632>::InstSegmentRegNames[] = { | 60 const char *TargetX8632Traits::InstSegmentRegNames[] = { |
| 61 #define X(val, name, prefix) name, | 61 #define X(val, name, prefix) name, |
| 62 SEG_REGX8632_TABLE | 62 SEG_REGX8632_TABLE |
| 63 #undef X | 63 #undef X |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 uint8_t MachineTraits<TargetX8632>::InstSegmentPrefixes[] = { | 66 uint8_t TargetX8632Traits::InstSegmentPrefixes[] = { |
| 67 #define X(val, name, prefix) prefix, | 67 #define X(val, name, prefix) prefix, |
| 68 SEG_REGX8632_TABLE | 68 SEG_REGX8632_TABLE |
| 69 #undef X | 69 #undef X |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 void MachineTraits<TargetX8632>::X86Operand::dump(const Cfg *, | 72 void TargetX8632Traits::X86Operand::dump(const Cfg *, Ostream &Str) const { |
| 73 Ostream &Str) const { | |
| 74 if (BuildDefs::dump()) | 73 if (BuildDefs::dump()) |
| 75 Str << "<OperandX8632>"; | 74 Str << "<OperandX8632>"; |
| 76 } | 75 } |
| 77 | 76 |
| 78 MachineTraits<TargetX8632>::X86OperandMem::X86OperandMem( | 77 TargetX8632Traits::X86OperandMem::X86OperandMem(Cfg *Func, Type Ty, |
| 79 Cfg *Func, Type Ty, Variable *Base, Constant *Offset, Variable *Index, | 78 Variable *Base, |
| 80 uint16_t Shift, SegmentRegisters SegmentReg) | 79 Constant *Offset, |
| 80 Variable *Index, uint16_t Shift, |
| 81 SegmentRegisters SegmentReg) |
| 81 : X86Operand(kMem, Ty), Base(Base), Offset(Offset), Index(Index), | 82 : X86Operand(kMem, Ty), Base(Base), Offset(Offset), Index(Index), |
| 82 Shift(Shift), SegmentReg(SegmentReg), Randomized(false) { | 83 Shift(Shift), SegmentReg(SegmentReg), Randomized(false) { |
| 83 assert(Shift <= 3); | 84 assert(Shift <= 3); |
| 84 Vars = nullptr; | 85 Vars = nullptr; |
| 85 NumVars = 0; | 86 NumVars = 0; |
| 86 if (Base) | 87 if (Base) |
| 87 ++NumVars; | 88 ++NumVars; |
| 88 if (Index) | 89 if (Index) |
| 89 ++NumVars; | 90 ++NumVars; |
| 90 if (NumVars) { | 91 if (NumVars) { |
| 91 Vars = Func->allocateArrayOf<Variable *>(NumVars); | 92 Vars = Func->allocateArrayOf<Variable *>(NumVars); |
| 92 SizeT I = 0; | 93 SizeT I = 0; |
| 93 if (Base) | 94 if (Base) |
| 94 Vars[I++] = Base; | 95 Vars[I++] = Base; |
| 95 if (Index) | 96 if (Index) |
| 96 Vars[I++] = Index; | 97 Vars[I++] = Index; |
| 97 assert(I == NumVars); | 98 assert(I == NumVars); |
| 98 } | 99 } |
| 99 } | 100 } |
| 100 | 101 |
| 101 namespace { | 102 namespace { |
| 102 static int32_t GetRematerializableOffset(Variable *Var, | 103 static int32_t |
| 103 const Ice::TargetX8632 *Target) { | 104 GetRematerializableOffset(Variable *Var, |
| 105 const Ice::X8632::TargetX8632 *Target) { |
| 104 int32_t Disp = Var->getStackOffset(); | 106 int32_t Disp = Var->getStackOffset(); |
| 105 SizeT RegNum = static_cast<SizeT>(Var->getRegNum()); | 107 SizeT RegNum = static_cast<SizeT>(Var->getRegNum()); |
| 106 if (RegNum == Target->getFrameReg()) { | 108 if (RegNum == Target->getFrameReg()) { |
| 107 Disp += Target->getFrameFixedAllocaOffset(); | 109 Disp += Target->getFrameFixedAllocaOffset(); |
| 108 } else if (RegNum != Target->getStackReg()) { | 110 } else if (RegNum != Target->getStackReg()) { |
| 109 llvm::report_fatal_error("Unexpected rematerializable register type"); | 111 llvm::report_fatal_error("Unexpected rematerializable register type"); |
| 110 } | 112 } |
| 111 return Disp; | 113 return Disp; |
| 112 } | 114 } |
| 113 } // end of anonymous namespace | 115 } // end of anonymous namespace |
| 114 | 116 |
| 115 void MachineTraits<TargetX8632>::X86OperandMem::emit(const Cfg *Func) const { | 117 void TargetX8632Traits::X86OperandMem::emit(const Cfg *Func) const { |
| 116 if (!BuildDefs::dump()) | 118 if (!BuildDefs::dump()) |
| 117 return; | 119 return; |
| 118 const auto *Target = static_cast<const Ice::TargetX8632 *>(Func->getTarget()); | 120 const auto *Target = |
| 121 static_cast<const ::Ice::X8632::TargetX8632 *>(Func->getTarget()); |
| 119 // If the base is rematerializable, we need to replace it with the correct | 122 // If the base is rematerializable, we need to replace it with the correct |
| 120 // physical register (esp or ebp), and update the Offset. | 123 // physical register (esp or ebp), and update the Offset. |
| 121 int32_t Disp = 0; | 124 int32_t Disp = 0; |
| 122 if (getBase() && getBase()->isRematerializable()) { | 125 if (getBase() && getBase()->isRematerializable()) { |
| 123 Disp += GetRematerializableOffset(getBase(), Target); | 126 Disp += GetRematerializableOffset(getBase(), Target); |
| 124 } | 127 } |
| 125 // The index should never be rematerializable. But if we ever allow it, then | 128 // The index should never be rematerializable. But if we ever allow it, then |
| 126 // we should make sure the rematerialization offset is shifted by the Shift | 129 // we should make sure the rematerialization offset is shifted by the Shift |
| 127 // value. | 130 // value. |
| 128 if (getIndex()) | 131 if (getIndex()) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 159 if (getIndex()) { | 162 if (getIndex()) { |
| 160 Str << ","; | 163 Str << ","; |
| 161 getIndex()->emit(Func); | 164 getIndex()->emit(Func); |
| 162 if (getShift()) | 165 if (getShift()) |
| 163 Str << "," << (1u << getShift()); | 166 Str << "," << (1u << getShift()); |
| 164 } | 167 } |
| 165 Str << ")"; | 168 Str << ")"; |
| 166 } | 169 } |
| 167 } | 170 } |
| 168 | 171 |
| 169 void MachineTraits<TargetX8632>::X86OperandMem::dump(const Cfg *Func, | 172 void TargetX8632Traits::X86OperandMem::dump(const Cfg *Func, |
| 170 Ostream &Str) const { | 173 Ostream &Str) const { |
| 171 if (!BuildDefs::dump()) | 174 if (!BuildDefs::dump()) |
| 172 return; | 175 return; |
| 173 if (SegmentReg != DefaultSegment) { | 176 if (SegmentReg != DefaultSegment) { |
| 174 assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM); | 177 assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM); |
| 175 Str << X8632::Traits::InstSegmentRegNames[SegmentReg] << ":"; | 178 Str << X8632::Traits::InstSegmentRegNames[SegmentReg] << ":"; |
| 176 } | 179 } |
| 177 bool Dumped = false; | 180 bool Dumped = false; |
| 178 Str << "["; | 181 Str << "["; |
| 179 int32_t Disp = 0; | 182 int32_t Disp = 0; |
| 180 const auto *Target = static_cast<const Ice::TargetX8632 *>(Func->getTarget()); | 183 const auto *Target = |
| 184 static_cast<const ::Ice::X8632::TargetX8632 *>(Func->getTarget()); |
| 181 if (getBase() && getBase()->isRematerializable()) { | 185 if (getBase() && getBase()->isRematerializable()) { |
| 182 Disp += GetRematerializableOffset(getBase(), Target); | 186 Disp += GetRematerializableOffset(getBase(), Target); |
| 183 } | 187 } |
| 184 if (getBase()) { | 188 if (getBase()) { |
| 185 if (Func) | 189 if (Func) |
| 186 getBase()->dump(Func); | 190 getBase()->dump(Func); |
| 187 else | 191 else |
| 188 getBase()->dump(Str); | 192 getBase()->dump(Str); |
| 189 Dumped = true; | 193 Dumped = true; |
| 190 } | 194 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 Str << "+"; | 227 Str << "+"; |
| 224 getOffset()->dump(Func, Str); | 228 getOffset()->dump(Func, Str); |
| 225 } | 229 } |
| 226 } else { | 230 } else { |
| 227 // There is only the offset. | 231 // There is only the offset. |
| 228 getOffset()->dump(Func, Str); | 232 getOffset()->dump(Func, Str); |
| 229 } | 233 } |
| 230 Str << "]"; | 234 Str << "]"; |
| 231 } | 235 } |
| 232 | 236 |
| 233 void MachineTraits<TargetX8632>::X86OperandMem::emitSegmentOverride( | 237 void TargetX8632Traits::X86OperandMem::emitSegmentOverride( |
| 234 MachineTraits<TargetX8632>::Assembler *Asm) const { | 238 TargetX8632Traits::Assembler *Asm) const { |
| 235 if (SegmentReg != DefaultSegment) { | 239 if (SegmentReg != DefaultSegment) { |
| 236 assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM); | 240 assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM); |
| 237 Asm->emitSegmentOverride(X8632::Traits::InstSegmentPrefixes[SegmentReg]); | 241 Asm->emitSegmentOverride(X8632::Traits::InstSegmentPrefixes[SegmentReg]); |
| 238 } | 242 } |
| 239 } | 243 } |
| 240 | 244 |
| 241 MachineTraits<TargetX8632>::Address | 245 TargetX8632Traits::Address TargetX8632Traits::X86OperandMem::toAsmAddress( |
| 242 MachineTraits<TargetX8632>::X86OperandMem::toAsmAddress( | 246 TargetX8632Traits::Assembler *Asm, |
| 243 MachineTraits<TargetX8632>::Assembler *Asm, | |
| 244 const Ice::TargetLowering *TargetLowering) const { | 247 const Ice::TargetLowering *TargetLowering) const { |
| 245 int32_t Disp = 0; | 248 int32_t Disp = 0; |
| 246 const auto *Target = static_cast<const Ice::TargetX8632 *>(TargetLowering); | 249 const auto *Target = |
| 250 static_cast<const ::Ice::X8632::TargetX8632 *>(TargetLowering); |
| 247 if (getBase() && getBase()->isRematerializable()) { | 251 if (getBase() && getBase()->isRematerializable()) { |
| 248 Disp += GetRematerializableOffset(getBase(), Target); | 252 Disp += GetRematerializableOffset(getBase(), Target); |
| 249 } | 253 } |
| 250 // The index should never be rematerializable. But if we ever allow it, then | 254 // The index should never be rematerializable. But if we ever allow it, then |
| 251 // we should make sure the rematerialization offset is shifted by the Shift | 255 // we should make sure the rematerialization offset is shifted by the Shift |
| 252 // value. | 256 // value. |
| 253 if (getIndex()) | 257 if (getIndex()) |
| 254 assert(!getIndex()->isRematerializable()); | 258 assert(!getIndex()->isRematerializable()); |
| 255 AssemblerFixup *Fixup = nullptr; | 259 AssemblerFixup *Fixup = nullptr; |
| 256 // Determine the offset (is it relocatable?) | 260 // Determine the offset (is it relocatable?) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 277 Fixup); | 281 Fixup); |
| 278 } else if (getIndex()) { | 282 } else if (getIndex()) { |
| 279 return X8632::Traits::Address(getEncodedGPR(getIndex()->getRegNum()), | 283 return X8632::Traits::Address(getEncodedGPR(getIndex()->getRegNum()), |
| 280 X8632::Traits::ScaleFactor(getShift()), Disp, | 284 X8632::Traits::ScaleFactor(getShift()), Disp, |
| 281 Fixup); | 285 Fixup); |
| 282 } else { | 286 } else { |
| 283 return X8632::Traits::Address(Disp, Fixup); | 287 return X8632::Traits::Address(Disp, Fixup); |
| 284 } | 288 } |
| 285 } | 289 } |
| 286 | 290 |
| 287 MachineTraits<TargetX8632>::Address | 291 TargetX8632Traits::Address |
| 288 MachineTraits<TargetX8632>::VariableSplit::toAsmAddress(const Cfg *Func) const { | 292 TargetX8632Traits::VariableSplit::toAsmAddress(const Cfg *Func) const { |
| 289 assert(!Var->hasReg()); | 293 assert(!Var->hasReg()); |
| 290 const ::Ice::TargetLowering *Target = Func->getTarget(); | 294 const ::Ice::TargetLowering *Target = Func->getTarget(); |
| 291 int32_t Offset = Var->getStackOffset() + getOffset(); | 295 int32_t Offset = Var->getStackOffset() + getOffset(); |
| 292 return X8632::Traits::Address(getEncodedGPR(Target->getFrameOrStackReg()), | 296 return X8632::Traits::Address(getEncodedGPR(Target->getFrameOrStackReg()), |
| 293 Offset, AssemblerFixup::NoFixup); | 297 Offset, AssemblerFixup::NoFixup); |
| 294 } | 298 } |
| 295 | 299 |
| 296 void MachineTraits<TargetX8632>::VariableSplit::emit(const Cfg *Func) const { | 300 void TargetX8632Traits::VariableSplit::emit(const Cfg *Func) const { |
| 297 if (!BuildDefs::dump()) | 301 if (!BuildDefs::dump()) |
| 298 return; | 302 return; |
| 299 Ostream &Str = Func->getContext()->getStrEmit(); | 303 Ostream &Str = Func->getContext()->getStrEmit(); |
| 300 assert(!Var->hasReg()); | 304 assert(!Var->hasReg()); |
| 301 // The following is copied/adapted from TargetX8632::emitVariable(). | 305 // The following is copied/adapted from TargetX8632::emitVariable(). |
| 302 const ::Ice::TargetLowering *Target = Func->getTarget(); | 306 const ::Ice::TargetLowering *Target = Func->getTarget(); |
| 303 constexpr Type Ty = IceType_i32; | 307 constexpr Type Ty = IceType_i32; |
| 304 int32_t Offset = Var->getStackOffset() + getOffset(); | 308 int32_t Offset = Var->getStackOffset() + getOffset(); |
| 305 if (Offset) | 309 if (Offset) |
| 306 Str << Offset; | 310 Str << Offset; |
| 307 Str << "(%" << Target->getRegName(Target->getFrameOrStackReg(), Ty) << ")"; | 311 Str << "(%" << Target->getRegName(Target->getFrameOrStackReg(), Ty) << ")"; |
| 308 } | 312 } |
| 309 | 313 |
| 310 void MachineTraits<TargetX8632>::VariableSplit::dump(const Cfg *Func, | 314 void TargetX8632Traits::VariableSplit::dump(const Cfg *Func, |
| 311 Ostream &Str) const { | 315 Ostream &Str) const { |
| 312 if (!BuildDefs::dump()) | 316 if (!BuildDefs::dump()) |
| 313 return; | 317 return; |
| 314 switch (Part) { | 318 switch (Part) { |
| 315 case Low: | 319 case Low: |
| 316 Str << "low"; | 320 Str << "low"; |
| 317 break; | 321 break; |
| 318 case High: | 322 case High: |
| 319 Str << "high"; | 323 Str << "high"; |
| 320 break; | 324 break; |
| 321 } | 325 } |
| 322 Str << "("; | 326 Str << "("; |
| 323 if (Func) | 327 if (Func) |
| 324 Var->dump(Func); | 328 Var->dump(Func); |
| 325 else | 329 else |
| 326 Var->dump(Str); | 330 Var->dump(Str); |
| 327 Str << ")"; | 331 Str << ")"; |
| 328 } | 332 } |
| 329 | 333 |
| 330 } // namespace X86Internal | 334 } // namespace X8632 |
| 331 } // end of namespace Ice | 335 } // end of namespace Ice |
| 332 | 336 |
| 333 X86INSTS_DEFINE_STATIC_DATA(TargetX8632) | 337 X86INSTS_DEFINE_STATIC_DATA(X8632, X8632::Traits) |
| OLD | NEW |