| 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 14 matching lines...) Expand all Loading... |
| 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 X86Internal { |
| 32 | 32 |
| 33 const MachineTraits<TargetX8632>::InstBrAttributesType | 33 const MachineTraits<TargetX8632>::InstBrAttributesType |
| 34 MachineTraits<TargetX8632>::InstBrAttributes[] = { | 34 MachineTraits<TargetX8632>::InstBrAttributes[] = { |
| 35 #define X(tag, 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 MachineTraits<TargetX8632>::InstCmppsAttributesType |
| 43 MachineTraits<TargetX8632>::InstCmppsAttributes[] = { | 43 MachineTraits<TargetX8632>::InstCmppsAttributes[] = { |
| 44 #define X(tag, 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 MachineTraits<TargetX8632>::TypeAttributesType |
| 52 MachineTraits<TargetX8632>::TypeAttributes[] = { | 52 MachineTraits<TargetX8632>::TypeAttributes[] = { |
| 53 #define X(tag, elementty, cvt, sdss, pack, width, fld) \ | 53 #define X(tag, elementty, cvt, sdss, pack, width, fld) \ |
| 54 { cvt, sdss, pack, width, fld } \ | 54 { cvt, sdss, pack, width, fld } \ |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 return; | 103 return; |
| 104 Ostream &Str = Func->getContext()->getStrEmit(); | 104 Ostream &Str = Func->getContext()->getStrEmit(); |
| 105 if (SegmentReg != DefaultSegment) { | 105 if (SegmentReg != DefaultSegment) { |
| 106 assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM); | 106 assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM); |
| 107 Str << "%" << X8632::Traits::InstSegmentRegNames[SegmentReg] << ":"; | 107 Str << "%" << X8632::Traits::InstSegmentRegNames[SegmentReg] << ":"; |
| 108 } | 108 } |
| 109 // Emit as Offset(Base,Index,1<<Shift). Offset is emitted without the leading | 109 // Emit as Offset(Base,Index,1<<Shift). Offset is emitted without the leading |
| 110 // '$'. Omit the (Base,Index,1<<Shift) part if Base==nullptr. | 110 // '$'. Omit the (Base,Index,1<<Shift) part if Base==nullptr. |
| 111 if (!Offset) { | 111 if (!Offset) { |
| 112 // No offset, emit nothing. | 112 // No offset, emit nothing. |
| 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 || Index) { | 123 if (Base || Index) { |
| 124 Str << "("; | 124 Str << "("; |
| 125 if (Base) | 125 if (Base) |
| 126 Base->emit(Func); | 126 Base->emit(Func); |
| 127 if (Index) { | 127 if (Index) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 Index->dump(Func); | 160 Index->dump(Func); |
| 161 else | 161 else |
| 162 Index->dump(Str); | 162 Index->dump(Str); |
| 163 Dumped = true; | 163 Dumped = true; |
| 164 } | 164 } |
| 165 // Pretty-print the Offset. | 165 // Pretty-print the Offset. |
| 166 bool OffsetIsZero = false; | 166 bool OffsetIsZero = false; |
| 167 bool OffsetIsNegative = false; | 167 bool OffsetIsNegative = false; |
| 168 if (!Offset) { | 168 if (!Offset) { |
| 169 OffsetIsZero = true; | 169 OffsetIsZero = true; |
| 170 } else if (const auto CI = llvm::dyn_cast<ConstantInteger32>(Offset)) { | 170 } else if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(Offset)) { |
| 171 OffsetIsZero = (CI->getValue() == 0); | 171 OffsetIsZero = (CI->getValue() == 0); |
| 172 OffsetIsNegative = (static_cast<int32_t>(CI->getValue()) < 0); | 172 OffsetIsNegative = (static_cast<int32_t>(CI->getValue()) < 0); |
| 173 } else { | 173 } else { |
| 174 assert(llvm::isa<ConstantRelocatable>(Offset)); | 174 assert(llvm::isa<ConstantRelocatable>(Offset)); |
| 175 } | 175 } |
| 176 if (Dumped) { | 176 if (Dumped) { |
| 177 if (!OffsetIsZero) { // Suppress if Offset is known to be 0 | 177 if (!OffsetIsZero) { // Suppress if Offset is known to be 0 |
| 178 if (!OffsetIsNegative) // Suppress if Offset is known to be negative | 178 if (!OffsetIsNegative) // Suppress if Offset is known to be negative |
| 179 Str << "+"; | 179 Str << "+"; |
| 180 Offset->dump(Func, Str); | 180 Offset->dump(Func, Str); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 194 } | 194 } |
| 195 } | 195 } |
| 196 | 196 |
| 197 MachineTraits<TargetX8632>::Address | 197 MachineTraits<TargetX8632>::Address |
| 198 MachineTraits<TargetX8632>::X86OperandMem::toAsmAddress( | 198 MachineTraits<TargetX8632>::X86OperandMem::toAsmAddress( |
| 199 MachineTraits<TargetX8632>::Assembler *Asm) const { | 199 MachineTraits<TargetX8632>::Assembler *Asm) const { |
| 200 int32_t Disp = 0; | 200 int32_t Disp = 0; |
| 201 AssemblerFixup *Fixup = nullptr; | 201 AssemblerFixup *Fixup = nullptr; |
| 202 // Determine the offset (is it relocatable?) | 202 // Determine the offset (is it relocatable?) |
| 203 if (getOffset()) { | 203 if (getOffset()) { |
| 204 if (const auto CI = llvm::dyn_cast<ConstantInteger32>(getOffset())) { | 204 if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(getOffset())) { |
| 205 Disp = static_cast<int32_t>(CI->getValue()); | 205 Disp = static_cast<int32_t>(CI->getValue()); |
| 206 } else if (const auto CR = | 206 } else if (const auto CR = |
| 207 llvm::dyn_cast<ConstantRelocatable>(getOffset())) { | 207 llvm::dyn_cast<ConstantRelocatable>(getOffset())) { |
| 208 Disp = CR->getOffset(); | 208 Disp = CR->getOffset(); |
| 209 Fixup = Asm->createFixup(RelFixup, CR); | 209 Fixup = Asm->createFixup(RelFixup, CR); |
| 210 } else { | 210 } else { |
| 211 llvm_unreachable("Unexpected offset type"); | 211 llvm_unreachable("Unexpected offset type"); |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 | 214 |
| 215 // Now convert to the various possible forms. | 215 // Now convert to the various possible forms. |
| 216 if (getBase() && getIndex()) { | 216 if (getBase() && getIndex()) { |
| 217 return X8632::Traits::Address( | 217 return X8632::Traits::Address(getEncodedGPR(getBase()->getRegNum()), |
| 218 RegX8632::getEncodedGPR(getBase()->getRegNum()), | 218 getEncodedGPR(getIndex()->getRegNum()), |
| 219 RegX8632::getEncodedGPR(getIndex()->getRegNum()), | 219 X8632::Traits::ScaleFactor(getShift()), Disp, |
| 220 X8632::Traits::ScaleFactor(getShift()), Disp, Fixup); | 220 Fixup); |
| 221 } else if (getBase()) { | 221 } else if (getBase()) { |
| 222 return X8632::Traits::Address( | 222 return X8632::Traits::Address(getEncodedGPR(getBase()->getRegNum()), Disp, |
| 223 RegX8632::getEncodedGPR(getBase()->getRegNum()), Disp, Fixup); | 223 Fixup); |
| 224 } else if (getIndex()) { | 224 } else if (getIndex()) { |
| 225 return X8632::Traits::Address( | 225 return X8632::Traits::Address(getEncodedGPR(getIndex()->getRegNum()), |
| 226 RegX8632::getEncodedGPR(getIndex()->getRegNum()), | 226 X8632::Traits::ScaleFactor(getShift()), Disp, |
| 227 X8632::Traits::ScaleFactor(getShift()), Disp, Fixup); | 227 Fixup); |
| 228 } else { | 228 } else { |
| 229 return X8632::Traits::Address(Disp, Fixup); | 229 return X8632::Traits::Address(Disp, Fixup); |
| 230 } | 230 } |
| 231 } | 231 } |
| 232 | 232 |
| 233 MachineTraits<TargetX8632>::Address | 233 MachineTraits<TargetX8632>::Address |
| 234 MachineTraits<TargetX8632>::VariableSplit::toAsmAddress(const Cfg *Func) const { | 234 MachineTraits<TargetX8632>::VariableSplit::toAsmAddress(const Cfg *Func) const { |
| 235 assert(!Var->hasReg()); | 235 assert(!Var->hasReg()); |
| 236 const ::Ice::TargetLowering *Target = Func->getTarget(); | 236 const ::Ice::TargetLowering *Target = Func->getTarget(); |
| 237 int32_t Offset = | 237 int32_t Offset = |
| 238 Var->getStackOffset() + Target->getStackAdjustment() + getOffset(); | 238 Var->getStackOffset() + Target->getStackAdjustment() + getOffset(); |
| 239 return X8632::Traits::Address( | 239 return X8632::Traits::Address(getEncodedGPR(Target->getFrameOrStackReg()), |
| 240 RegX8632::getEncodedGPR(Target->getFrameOrStackReg()), Offset, | 240 Offset, AssemblerFixup::NoFixup); |
| 241 AssemblerFixup::NoFixup); | |
| 242 } | 241 } |
| 243 | 242 |
| 244 void MachineTraits<TargetX8632>::VariableSplit::emit(const Cfg *Func) const { | 243 void MachineTraits<TargetX8632>::VariableSplit::emit(const Cfg *Func) const { |
| 245 if (!BuildDefs::dump()) | 244 if (!BuildDefs::dump()) |
| 246 return; | 245 return; |
| 247 Ostream &Str = Func->getContext()->getStrEmit(); | 246 Ostream &Str = Func->getContext()->getStrEmit(); |
| 248 assert(!Var->hasReg()); | 247 assert(!Var->hasReg()); |
| 249 // The following is copied/adapted from TargetX8632::emitVariable(). | 248 // The following is copied/adapted from TargetX8632::emitVariable(). |
| 250 const ::Ice::TargetLowering *Target = Func->getTarget(); | 249 const ::Ice::TargetLowering *Target = Func->getTarget(); |
| 251 const Type Ty = IceType_i32; | 250 constexpr Type Ty = IceType_i32; |
| 252 int32_t Offset = | 251 int32_t Offset = |
| 253 Var->getStackOffset() + Target->getStackAdjustment() + getOffset(); | 252 Var->getStackOffset() + Target->getStackAdjustment() + getOffset(); |
| 254 if (Offset) | 253 if (Offset) |
| 255 Str << Offset; | 254 Str << Offset; |
| 256 Str << "(%" << Target->getRegName(Target->getFrameOrStackReg(), Ty) << ")"; | 255 Str << "(%" << Target->getRegName(Target->getFrameOrStackReg(), Ty) << ")"; |
| 257 } | 256 } |
| 258 | 257 |
| 259 void MachineTraits<TargetX8632>::VariableSplit::dump(const Cfg *Func, | 258 void MachineTraits<TargetX8632>::VariableSplit::dump(const Cfg *Func, |
| 260 Ostream &Str) const { | 259 Ostream &Str) const { |
| 261 if (!BuildDefs::dump()) | 260 if (!BuildDefs::dump()) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 273 Var->dump(Func); | 272 Var->dump(Func); |
| 274 else | 273 else |
| 275 Var->dump(Str); | 274 Var->dump(Str); |
| 276 Str << ")"; | 275 Str << ")"; |
| 277 } | 276 } |
| 278 | 277 |
| 279 } // namespace X86Internal | 278 } // namespace X86Internal |
| 280 } // end of namespace Ice | 279 } // end of namespace Ice |
| 281 | 280 |
| 282 X86INSTS_DEFINE_STATIC_DATA(TargetX8632) | 281 X86INSTS_DEFINE_STATIC_DATA(TargetX8632) |
| OLD | NEW |