OLD | NEW |
1 //===- subzero/src/IceInstX8664.cpp - X86-64 instruction implementation ---===// | 1 //===- subzero/src/IceInstX8664.cpp - X86-64 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 } else if (const auto CI = llvm::dyn_cast<ConstantInteger32>(Offset)) { | 99 } else if (const auto CI = llvm::dyn_cast<ConstantInteger32>(Offset)) { |
100 if (Base == nullptr || CI->getValue()) | 100 if (Base == nullptr || CI->getValue()) |
101 // Emit a non-zero offset without a leading '$'. | 101 // Emit a non-zero offset without a leading '$'. |
102 Str << CI->getValue(); | 102 Str << CI->getValue(); |
103 } else if (const auto CR = llvm::dyn_cast<ConstantRelocatable>(Offset)) { | 103 } else if (const auto CR = llvm::dyn_cast<ConstantRelocatable>(Offset)) { |
104 CR->emitWithoutPrefix(Func->getTarget()); | 104 CR->emitWithoutPrefix(Func->getTarget()); |
105 } else { | 105 } else { |
106 llvm_unreachable("Invalid offset type for x86 mem operand"); | 106 llvm_unreachable("Invalid offset type for x86 mem operand"); |
107 } | 107 } |
108 | 108 |
109 if (Base) { | 109 if (Base || Index) { |
110 Str << "("; | 110 Str << "("; |
111 Base->emit(Func); | 111 if (Base) |
| 112 Base->emit(Func); |
112 if (Index) { | 113 if (Index) { |
113 Str << ","; | 114 Str << ","; |
114 Index->emit(Func); | 115 Index->emit(Func); |
115 if (Shift) | 116 if (Shift) |
116 Str << "," << (1u << Shift); | 117 Str << "," << (1u << Shift); |
117 } | 118 } |
118 Str << ")"; | 119 Str << ")"; |
119 } | 120 } |
120 } | 121 } |
121 | 122 |
122 void MachineTraits<TargetX8664>::X86OperandMem::dump(const Cfg *Func, | 123 void MachineTraits<TargetX8664>::X86OperandMem::dump(const Cfg *Func, |
123 Ostream &Str) const { | 124 Ostream &Str) const { |
124 if (!BuildDefs::dump()) | 125 if (!BuildDefs::dump()) |
125 return; | 126 return; |
126 bool Dumped = false; | 127 bool Dumped = false; |
127 Str << "["; | 128 Str << "["; |
128 if (Base) { | 129 if (Base) { |
129 if (Func) | 130 if (Func) |
130 Base->dump(Func); | 131 Base->dump(Func); |
131 else | 132 else |
132 Base->dump(Str); | 133 Base->dump(Str); |
133 Dumped = true; | 134 Dumped = true; |
134 } | 135 } |
135 if (Index) { | 136 if (Index) { |
136 assert(Base); | 137 if (Base) |
137 Str << "+"; | 138 Str << "+"; |
138 if (Shift > 0) | 139 if (Shift > 0) |
139 Str << (1u << Shift) << "*"; | 140 Str << (1u << Shift) << "*"; |
140 if (Func) | 141 if (Func) |
141 Index->dump(Func); | 142 Index->dump(Func); |
142 else | 143 else |
143 Index->dump(Str); | 144 Index->dump(Str); |
144 Dumped = true; | 145 Dumped = true; |
145 } | 146 } |
146 // Pretty-print the Offset. | 147 // Pretty-print the Offset. |
147 bool OffsetIsZero = false; | 148 bool OffsetIsZero = false; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } else { | 184 } else { |
184 llvm_unreachable("Unexpected offset type"); | 185 llvm_unreachable("Unexpected offset type"); |
185 } | 186 } |
186 } | 187 } |
187 | 188 |
188 // Now convert to the various possible forms. | 189 // Now convert to the various possible forms. |
189 if (getBase() && getIndex()) { | 190 if (getBase() && getIndex()) { |
190 return X8664::Traits::Address( | 191 return X8664::Traits::Address( |
191 RegX8664::getEncodedGPR(getBase()->getRegNum()), | 192 RegX8664::getEncodedGPR(getBase()->getRegNum()), |
192 RegX8664::getEncodedGPR(getIndex()->getRegNum()), | 193 RegX8664::getEncodedGPR(getIndex()->getRegNum()), |
193 X8664::Traits::ScaleFactor(getShift()), Disp); | 194 X8664::Traits::ScaleFactor(getShift()), Disp, Fixup); |
194 } else if (getBase()) { | 195 } else if (getBase()) { |
195 return X8664::Traits::Address( | 196 return X8664::Traits::Address( |
196 RegX8664::getEncodedGPR(getBase()->getRegNum()), Disp); | 197 RegX8664::getEncodedGPR(getBase()->getRegNum()), Disp, Fixup); |
197 } else if (getIndex()) { | 198 } else if (getIndex()) { |
198 return X8664::Traits::Address( | 199 return X8664::Traits::Address( |
199 RegX8664::getEncodedGPR(getIndex()->getRegNum()), | 200 RegX8664::getEncodedGPR(getIndex()->getRegNum()), |
200 X8664::Traits::ScaleFactor(getShift()), Disp); | 201 X8664::Traits::ScaleFactor(getShift()), Disp, Fixup); |
201 } else if (Fixup) { | |
202 return X8664::Traits::Address::Absolute(Disp, Fixup); | |
203 } else { | 202 } else { |
204 return X8664::Traits::Address::Absolute(Disp); | 203 return X8664::Traits::Address(Disp, Fixup); |
205 } | 204 } |
206 } | 205 } |
207 | 206 |
208 MachineTraits<TargetX8664>::Address | 207 MachineTraits<TargetX8664>::Address |
209 MachineTraits<TargetX8664>::VariableSplit::toAsmAddress(const Cfg *Func) const { | 208 MachineTraits<TargetX8664>::VariableSplit::toAsmAddress(const Cfg *Func) const { |
210 assert(!Var->hasReg()); | 209 assert(!Var->hasReg()); |
211 const ::Ice::TargetLowering *Target = Func->getTarget(); | 210 const ::Ice::TargetLowering *Target = Func->getTarget(); |
212 int32_t Offset = | 211 int32_t Offset = |
213 Var->getStackOffset() + Target->getStackAdjustment() + getOffset(); | 212 Var->getStackOffset() + Target->getStackAdjustment() + getOffset(); |
| 213 static constexpr AssemblerFixup *Fixup = nullptr; |
214 return X8664::Traits::Address( | 214 return X8664::Traits::Address( |
215 RegX8664::getEncodedGPR(Target->getFrameOrStackReg()), Offset); | 215 RegX8664::getEncodedGPR(Target->getFrameOrStackReg()), Offset, Fixup); |
216 } | 216 } |
217 | 217 |
218 void MachineTraits<TargetX8664>::VariableSplit::emit(const Cfg *Func) const { | 218 void MachineTraits<TargetX8664>::VariableSplit::emit(const Cfg *Func) const { |
219 if (!BuildDefs::dump()) | 219 if (!BuildDefs::dump()) |
220 return; | 220 return; |
221 Ostream &Str = Func->getContext()->getStrEmit(); | 221 Ostream &Str = Func->getContext()->getStrEmit(); |
222 assert(!Var->hasReg()); | 222 assert(!Var->hasReg()); |
223 // The following is copied/adapted from TargetX8664::emitVariable(). | 223 // The following is copied/adapted from TargetX8664::emitVariable(). |
224 const ::Ice::TargetLowering *Target = Func->getTarget(); | 224 const ::Ice::TargetLowering *Target = Func->getTarget(); |
225 const Type Ty = IceType_i32; | 225 const Type Ty = IceType_i32; |
(...skipping 21 matching lines...) Expand all Loading... |
247 Var->dump(Func); | 247 Var->dump(Func); |
248 else | 248 else |
249 Var->dump(Str); | 249 Var->dump(Str); |
250 Str << ")"; | 250 Str << ")"; |
251 } | 251 } |
252 | 252 |
253 } // namespace X86Internal | 253 } // namespace X86Internal |
254 } // end of namespace Ice | 254 } // end of namespace Ice |
255 | 255 |
256 X86INSTS_DEFINE_STATIC_DATA(TargetX8664) | 256 X86INSTS_DEFINE_STATIC_DATA(TargetX8664) |
OLD | NEW |