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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 Str << Disp; | 129 Str << Disp; |
130 } else if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(Offset)) { | 130 } else if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(Offset)) { |
131 if (Base == nullptr || CI->getValue() || Disp != 0) | 131 if (Base == nullptr || CI->getValue() || Disp != 0) |
132 // Emit a non-zero offset without a leading '$'. | 132 // Emit a non-zero offset without a leading '$'. |
133 Str << CI->getValue() + Disp; | 133 Str << CI->getValue() + Disp; |
134 } else if (const auto *CR = llvm::dyn_cast<ConstantRelocatable>(Offset)) { | 134 } else if (const auto *CR = llvm::dyn_cast<ConstantRelocatable>(Offset)) { |
135 // TODO(sehr): ConstantRelocatable still needs updating for | 135 // TODO(sehr): ConstantRelocatable still needs updating for |
136 // rematerializable base/index and Disp. | 136 // rematerializable base/index and Disp. |
137 assert(Disp == 0); | 137 assert(Disp == 0); |
138 const bool UseNonsfi = Func->getContext()->getFlags().getUseNonsfi(); | 138 const bool UseNonsfi = Func->getContext()->getFlags().getUseNonsfi(); |
139 CR->emitWithoutPrefix(Func->getTarget(), UseNonsfi ? "@GOTOFF" : ""); | 139 CR->emitWithoutPrefix(Target, UseNonsfi ? "@GOTOFF" : ""); |
| 140 assert(!UseNonsfi); |
| 141 if (Base == nullptr && Index == nullptr) { |
| 142 if (CR->getName() != "") { // rip-relative addressing. |
| 143 if (NeedSandboxing) { |
| 144 Str << "(%rip)"; |
| 145 } else { |
| 146 Str << "(%eip)"; |
| 147 } |
| 148 } |
| 149 } |
140 } else { | 150 } else { |
141 llvm_unreachable("Invalid offset type for x86 mem operand"); | 151 llvm_unreachable("Invalid offset type for x86 mem operand"); |
142 } | 152 } |
143 | 153 |
144 if (Base == nullptr && Index == nullptr) { | 154 if (Base == nullptr && Index == nullptr) { |
145 return; | 155 return; |
146 } | 156 } |
147 | 157 |
148 Str << "("; | 158 Str << "("; |
149 if (Base != nullptr) { | 159 if (Base != nullptr) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 } | 259 } |
250 if (getIndex() != nullptr) { | 260 if (getIndex() != nullptr) { |
251 assert(!getIndex()->isRematerializable()); | 261 assert(!getIndex()->isRematerializable()); |
252 } | 262 } |
253 | 263 |
254 AssemblerFixup *Fixup = nullptr; | 264 AssemblerFixup *Fixup = nullptr; |
255 // Determine the offset (is it relocatable?) | 265 // Determine the offset (is it relocatable?) |
256 if (getOffset() != nullptr) { | 266 if (getOffset() != nullptr) { |
257 if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(getOffset())) { | 267 if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(getOffset())) { |
258 Disp += static_cast<int32_t>(CI->getValue()); | 268 Disp += static_cast<int32_t>(CI->getValue()); |
259 } else if (const auto CR = | 269 } else if (const auto *CR = |
260 llvm::dyn_cast<ConstantRelocatable>(getOffset())) { | 270 llvm::dyn_cast<ConstantRelocatable>(getOffset())) { |
261 Disp = CR->getOffset(); | 271 RelocOffsetT DispAdjustment = 0; |
262 Fixup = Asm->createFixup(FK_Abs, CR); | 272 if (CR->getName() != "") { |
| 273 const auto FixupKind = |
| 274 (getBase() != nullptr || getIndex() != nullptr) ? FK_Abs : FK_PcRel; |
| 275 DispAdjustment = FixupKind == FK_PcRel ? 4 : 0; |
| 276 Fixup = Asm->createFixup(FixupKind, CR); |
| 277 } |
| 278 Disp = CR->getOffset() - DispAdjustment; |
263 } else { | 279 } else { |
264 llvm_unreachable("Unexpected offset type"); | 280 llvm_unreachable("Unexpected offset type"); |
265 } | 281 } |
266 } | 282 } |
267 | 283 |
268 // Now convert to the various possible forms. | 284 // Now convert to the various possible forms. |
269 if (getBase() && getIndex()) { | 285 if (getBase() && getIndex()) { |
270 const bool NeedSandboxing = Target->needSandboxing(); | 286 const bool NeedSandboxing = Target->needSandboxing(); |
271 (void)NeedSandboxing; | 287 (void)NeedSandboxing; |
272 assert(!NeedSandboxing || IsLeaAddr || | 288 assert(!NeedSandboxing || IsLeaAddr || |
(...skipping 10 matching lines...) Expand all Loading... |
283 return X8664::Traits::Address(getEncodedGPR(getBase()->getRegNum()), Disp, | 299 return X8664::Traits::Address(getEncodedGPR(getBase()->getRegNum()), Disp, |
284 Fixup); | 300 Fixup); |
285 } | 301 } |
286 | 302 |
287 if (getIndex()) { | 303 if (getIndex()) { |
288 return X8664::Traits::Address(getEncodedGPR(getIndex()->getRegNum()), | 304 return X8664::Traits::Address(getEncodedGPR(getIndex()->getRegNum()), |
289 X8664::Traits::ScaleFactor(getShift()), Disp, | 305 X8664::Traits::ScaleFactor(getShift()), Disp, |
290 Fixup); | 306 Fixup); |
291 } | 307 } |
292 | 308 |
293 return X8664::Traits::Address(Disp, Fixup); | 309 if (Fixup == nullptr) { |
| 310 // Absolute addresses are not allowed in Nexes -- they must be rebased |
| 311 // w.r.t. %r15. |
| 312 // Exception: LEAs are fine because they do not touch memory. |
| 313 assert(!Target->needSandboxing() || IsLeaAddr); |
| 314 return X8664::Traits::Address::Absolute(Disp); |
| 315 } |
| 316 |
| 317 return X8664::Traits::Address::RipRelative(Disp, Fixup); |
294 } | 318 } |
295 | 319 |
296 TargetX8664Traits::Address | 320 TargetX8664Traits::Address |
297 TargetX8664Traits::VariableSplit::toAsmAddress(const Cfg *Func) const { | 321 TargetX8664Traits::VariableSplit::toAsmAddress(const Cfg *Func) const { |
298 assert(!Var->hasReg()); | 322 assert(!Var->hasReg()); |
299 const ::Ice::TargetLowering *Target = Func->getTarget(); | 323 const ::Ice::TargetLowering *Target = Func->getTarget(); |
300 int32_t Offset = Var->getStackOffset() + getOffset(); | 324 int32_t Offset = Var->getStackOffset() + getOffset(); |
301 return X8664::Traits::Address(getEncodedGPR(Target->getFrameOrStackReg()), | 325 return X8664::Traits::Address(getEncodedGPR(Target->getFrameOrStackReg()), |
302 Offset, AssemblerFixup::NoFixup); | 326 Offset, AssemblerFixup::NoFixup); |
303 } | 327 } |
(...skipping 29 matching lines...) Expand all Loading... |
333 Var->dump(Func); | 357 Var->dump(Func); |
334 else | 358 else |
335 Var->dump(Str); | 359 Var->dump(Str); |
336 Str << ")"; | 360 Str << ")"; |
337 } | 361 } |
338 | 362 |
339 } // namespace X8664 | 363 } // namespace X8664 |
340 } // end of namespace Ice | 364 } // end of namespace Ice |
341 | 365 |
342 X86INSTS_DEFINE_STATIC_DATA(X8664, X8664::Traits) | 366 X86INSTS_DEFINE_STATIC_DATA(X8664, X8664::Traits) |
OLD | NEW |