| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } else if (const auto CI = llvm::dyn_cast<ConstantInteger32>(Offset)) { | 113 } else if (const auto CI = llvm::dyn_cast<ConstantInteger32>(Offset)) { |
| 114 if (Base == nullptr || CI->getValue()) | 114 if (Base == nullptr || CI->getValue()) |
| 115 // Emit a non-zero offset without a leading '$'. | 115 // Emit a non-zero offset without a leading '$'. |
| 116 Str << CI->getValue(); | 116 Str << CI->getValue(); |
| 117 } else if (const auto CR = llvm::dyn_cast<ConstantRelocatable>(Offset)) { | 117 } else if (const auto CR = llvm::dyn_cast<ConstantRelocatable>(Offset)) { |
| 118 CR->emitWithoutPrefix(Func->getTarget()); | 118 CR->emitWithoutPrefix(Func->getTarget()); |
| 119 } else { | 119 } else { |
| 120 llvm_unreachable("Invalid offset type for x86 mem operand"); | 120 llvm_unreachable("Invalid offset type for x86 mem operand"); |
| 121 } | 121 } |
| 122 | 122 |
| 123 if (Base) { | 123 if (Base || Index) { |
| 124 Str << "("; | 124 Str << "("; |
| 125 Base->emit(Func); | 125 if (Base) |
| 126 Base->emit(Func); |
| 126 if (Index) { | 127 if (Index) { |
| 127 Str << ","; | 128 Str << ","; |
| 128 Index->emit(Func); | 129 Index->emit(Func); |
| 129 if (Shift) | 130 if (Shift) |
| 130 Str << "," << (1u << Shift); | 131 Str << "," << (1u << Shift); |
| 131 } | 132 } |
| 132 Str << ")"; | 133 Str << ")"; |
| 133 } | 134 } |
| 134 } | 135 } |
| 135 | 136 |
| 136 void MachineTraits<TargetX8632>::X86OperandMem::dump(const Cfg *Func, | 137 void MachineTraits<TargetX8632>::X86OperandMem::dump(const Cfg *Func, |
| 137 Ostream &Str) const { | 138 Ostream &Str) const { |
| 138 if (!BuildDefs::dump()) | 139 if (!BuildDefs::dump()) |
| 139 return; | 140 return; |
| 140 if (SegmentReg != DefaultSegment) { | 141 if (SegmentReg != DefaultSegment) { |
| 141 assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM); | 142 assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM); |
| 142 Str << X8632::Traits::InstSegmentRegNames[SegmentReg] << ":"; | 143 Str << X8632::Traits::InstSegmentRegNames[SegmentReg] << ":"; |
| 143 } | 144 } |
| 144 bool Dumped = false; | 145 bool Dumped = false; |
| 145 Str << "["; | 146 Str << "["; |
| 146 if (Base) { | 147 if (Base) { |
| 147 if (Func) | 148 if (Func) |
| 148 Base->dump(Func); | 149 Base->dump(Func); |
| 149 else | 150 else |
| 150 Base->dump(Str); | 151 Base->dump(Str); |
| 151 Dumped = true; | 152 Dumped = true; |
| 152 } | 153 } |
| 153 if (Index) { | 154 if (Index) { |
| 154 assert(Base); | 155 if (Base) |
| 155 Str << "+"; | 156 Str << "+"; |
| 156 if (Shift > 0) | 157 if (Shift > 0) |
| 157 Str << (1u << Shift) << "*"; | 158 Str << (1u << Shift) << "*"; |
| 158 if (Func) | 159 if (Func) |
| 159 Index->dump(Func); | 160 Index->dump(Func); |
| 160 else | 161 else |
| 161 Index->dump(Str); | 162 Index->dump(Str); |
| 162 Dumped = true; | 163 Dumped = true; |
| 163 } | 164 } |
| 164 // Pretty-print the Offset. | 165 // Pretty-print the Offset. |
| 165 bool OffsetIsZero = false; | 166 bool OffsetIsZero = false; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } else { | 210 } else { |
| 210 llvm_unreachable("Unexpected offset type"); | 211 llvm_unreachable("Unexpected offset type"); |
| 211 } | 212 } |
| 212 } | 213 } |
| 213 | 214 |
| 214 // Now convert to the various possible forms. | 215 // Now convert to the various possible forms. |
| 215 if (getBase() && getIndex()) { | 216 if (getBase() && getIndex()) { |
| 216 return X8632::Traits::Address( | 217 return X8632::Traits::Address( |
| 217 RegX8632::getEncodedGPR(getBase()->getRegNum()), | 218 RegX8632::getEncodedGPR(getBase()->getRegNum()), |
| 218 RegX8632::getEncodedGPR(getIndex()->getRegNum()), | 219 RegX8632::getEncodedGPR(getIndex()->getRegNum()), |
| 219 X8632::Traits::ScaleFactor(getShift()), Disp); | 220 X8632::Traits::ScaleFactor(getShift()), Disp, Fixup); |
| 220 } else if (getBase()) { | 221 } else if (getBase()) { |
| 221 return X8632::Traits::Address( | 222 return X8632::Traits::Address( |
| 222 RegX8632::getEncodedGPR(getBase()->getRegNum()), Disp); | 223 RegX8632::getEncodedGPR(getBase()->getRegNum()), Disp, Fixup); |
| 223 } else if (getIndex()) { | 224 } else if (getIndex()) { |
| 224 return X8632::Traits::Address( | 225 return X8632::Traits::Address( |
| 225 RegX8632::getEncodedGPR(getIndex()->getRegNum()), | 226 RegX8632::getEncodedGPR(getIndex()->getRegNum()), |
| 226 X8632::Traits::ScaleFactor(getShift()), Disp); | 227 X8632::Traits::ScaleFactor(getShift()), Disp, Fixup); |
| 227 } else if (Fixup) { | |
| 228 return X8632::Traits::Address::Absolute(Disp, Fixup); | |
| 229 } else { | 228 } else { |
| 230 return X8632::Traits::Address::Absolute(Disp); | 229 return X8632::Traits::Address(Disp, Fixup); |
| 231 } | 230 } |
| 232 } | 231 } |
| 233 | 232 |
| 234 MachineTraits<TargetX8632>::Address | 233 MachineTraits<TargetX8632>::Address |
| 235 MachineTraits<TargetX8632>::VariableSplit::toAsmAddress(const Cfg *Func) const { | 234 MachineTraits<TargetX8632>::VariableSplit::toAsmAddress(const Cfg *Func) const { |
| 236 assert(!Var->hasReg()); | 235 assert(!Var->hasReg()); |
| 237 const ::Ice::TargetLowering *Target = Func->getTarget(); | 236 const ::Ice::TargetLowering *Target = Func->getTarget(); |
| 238 int32_t Offset = | 237 int32_t Offset = |
| 239 Var->getStackOffset() + Target->getStackAdjustment() + getOffset(); | 238 Var->getStackOffset() + Target->getStackAdjustment() + getOffset(); |
| 239 static constexpr AssemblerFixup *Fixup = nullptr; |
| 240 return X8632::Traits::Address( | 240 return X8632::Traits::Address( |
| 241 RegX8632::getEncodedGPR(Target->getFrameOrStackReg()), Offset); | 241 RegX8632::getEncodedGPR(Target->getFrameOrStackReg()), Offset, Fixup); |
| 242 } | 242 } |
| 243 | 243 |
| 244 void MachineTraits<TargetX8632>::VariableSplit::emit(const Cfg *Func) const { | 244 void MachineTraits<TargetX8632>::VariableSplit::emit(const Cfg *Func) const { |
| 245 if (!BuildDefs::dump()) | 245 if (!BuildDefs::dump()) |
| 246 return; | 246 return; |
| 247 Ostream &Str = Func->getContext()->getStrEmit(); | 247 Ostream &Str = Func->getContext()->getStrEmit(); |
| 248 assert(!Var->hasReg()); | 248 assert(!Var->hasReg()); |
| 249 // The following is copied/adapted from TargetX8632::emitVariable(). | 249 // The following is copied/adapted from TargetX8632::emitVariable(). |
| 250 const ::Ice::TargetLowering *Target = Func->getTarget(); | 250 const ::Ice::TargetLowering *Target = Func->getTarget(); |
| 251 const Type Ty = IceType_i32; | 251 const Type Ty = IceType_i32; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 273 Var->dump(Func); | 273 Var->dump(Func); |
| 274 else | 274 else |
| 275 Var->dump(Str); | 275 Var->dump(Str); |
| 276 Str << ")"; | 276 Str << ")"; |
| 277 } | 277 } |
| 278 | 278 |
| 279 } // namespace X86Internal | 279 } // namespace X86Internal |
| 280 } // end of namespace Ice | 280 } // end of namespace Ice |
| 281 | 281 |
| 282 X86INSTS_DEFINE_STATIC_DATA(TargetX8632) | 282 X86INSTS_DEFINE_STATIC_DATA(TargetX8632) |
| OLD | NEW |