| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } else if (getOffset() == nullptr && Disp != 0) { | 128 } else if (getOffset() == nullptr && Disp != 0) { |
| 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 if (Base == nullptr && Index == nullptr && NeedSandboxing) { |
| 139 llvm::report_fatal_error( |
| 140 "llvm-mc encodes rip-relative instructions incorrectly. Why?"); |
| 141 // Native code should be fine. The relocatable will be emitted with a |
| 142 // regular, absolute relocation. |
| 143 } |
| 138 const bool UseNonsfi = Func->getContext()->getFlags().getUseNonsfi(); | 144 const bool UseNonsfi = Func->getContext()->getFlags().getUseNonsfi(); |
| 145 assert(!UseNonsfi); |
| 139 CR->emitWithoutPrefix(Func->getTarget(), UseNonsfi ? "@GOTOFF" : ""); | 146 CR->emitWithoutPrefix(Func->getTarget(), UseNonsfi ? "@GOTOFF" : ""); |
| 140 } else { | 147 } else { |
| 141 llvm_unreachable("Invalid offset type for x86 mem operand"); | 148 llvm_unreachable("Invalid offset type for x86 mem operand"); |
| 142 } | 149 } |
| 143 | 150 |
| 144 if (Base == nullptr && Index == nullptr) { | 151 if (Base == nullptr && Index == nullptr) { |
| 145 return; | 152 return; |
| 146 } | 153 } |
| 147 | 154 |
| 148 Str << "("; | 155 Str << "("; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 } | 256 } |
| 250 if (getIndex() != nullptr) { | 257 if (getIndex() != nullptr) { |
| 251 assert(!getIndex()->isRematerializable()); | 258 assert(!getIndex()->isRematerializable()); |
| 252 } | 259 } |
| 253 | 260 |
| 254 AssemblerFixup *Fixup = nullptr; | 261 AssemblerFixup *Fixup = nullptr; |
| 255 // Determine the offset (is it relocatable?) | 262 // Determine the offset (is it relocatable?) |
| 256 if (getOffset() != nullptr) { | 263 if (getOffset() != nullptr) { |
| 257 if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(getOffset())) { | 264 if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(getOffset())) { |
| 258 Disp += static_cast<int32_t>(CI->getValue()); | 265 Disp += static_cast<int32_t>(CI->getValue()); |
| 259 } else if (const auto CR = | 266 } else if (const auto *CR = |
| 260 llvm::dyn_cast<ConstantRelocatable>(getOffset())) { | 267 llvm::dyn_cast<ConstantRelocatable>(getOffset())) { |
| 261 Disp = CR->getOffset(); | 268 const auto FixupKind = |
| 262 Fixup = Asm->createFixup(FK_Abs, CR); | 269 (getBase() != nullptr || getIndex() != nullptr) ? FK_Abs : FK_PcRel; |
| 270 Disp = CR->getOffset() - (FixupKind == FK_PcRel ? 4 : 0); |
| 271 Fixup = Asm->createFixup(FixupKind, CR); |
| 263 } else { | 272 } else { |
| 264 llvm_unreachable("Unexpected offset type"); | 273 llvm_unreachable("Unexpected offset type"); |
| 265 } | 274 } |
| 266 } | 275 } |
| 267 | 276 |
| 268 // Now convert to the various possible forms. | 277 // Now convert to the various possible forms. |
| 269 if (getBase() && getIndex()) { | 278 if (getBase() && getIndex()) { |
| 270 const bool NeedSandboxing = Target->needSandboxing(); | 279 const bool NeedSandboxing = Target->needSandboxing(); |
| 271 (void)NeedSandboxing; | 280 (void)NeedSandboxing; |
| 272 assert(!NeedSandboxing || IsLeaAddr || | 281 assert(!NeedSandboxing || IsLeaAddr || |
| (...skipping 10 matching lines...) Expand all Loading... |
| 283 return X8664::Traits::Address(getEncodedGPR(getBase()->getRegNum()), Disp, | 292 return X8664::Traits::Address(getEncodedGPR(getBase()->getRegNum()), Disp, |
| 284 Fixup); | 293 Fixup); |
| 285 } | 294 } |
| 286 | 295 |
| 287 if (getIndex()) { | 296 if (getIndex()) { |
| 288 return X8664::Traits::Address(getEncodedGPR(getIndex()->getRegNum()), | 297 return X8664::Traits::Address(getEncodedGPR(getIndex()->getRegNum()), |
| 289 X8664::Traits::ScaleFactor(getShift()), Disp, | 298 X8664::Traits::ScaleFactor(getShift()), Disp, |
| 290 Fixup); | 299 Fixup); |
| 291 } | 300 } |
| 292 | 301 |
| 293 return X8664::Traits::Address(Disp, Fixup); | 302 return X8664::Traits::Address::RipRelative(Disp, Fixup); |
| 294 } | 303 } |
| 295 | 304 |
| 296 TargetX8664Traits::Address | 305 TargetX8664Traits::Address |
| 297 TargetX8664Traits::VariableSplit::toAsmAddress(const Cfg *Func) const { | 306 TargetX8664Traits::VariableSplit::toAsmAddress(const Cfg *Func) const { |
| 298 assert(!Var->hasReg()); | 307 assert(!Var->hasReg()); |
| 299 const ::Ice::TargetLowering *Target = Func->getTarget(); | 308 const ::Ice::TargetLowering *Target = Func->getTarget(); |
| 300 int32_t Offset = Var->getStackOffset() + getOffset(); | 309 int32_t Offset = Var->getStackOffset() + getOffset(); |
| 301 return X8664::Traits::Address(getEncodedGPR(Target->getFrameOrStackReg()), | 310 return X8664::Traits::Address(getEncodedGPR(Target->getFrameOrStackReg()), |
| 302 Offset, AssemblerFixup::NoFixup); | 311 Offset, AssemblerFixup::NoFixup); |
| 303 } | 312 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 333 Var->dump(Func); | 342 Var->dump(Func); |
| 334 else | 343 else |
| 335 Var->dump(Str); | 344 Var->dump(Str); |
| 336 Str << ")"; | 345 Str << ")"; |
| 337 } | 346 } |
| 338 | 347 |
| 339 } // namespace X8664 | 348 } // namespace X8664 |
| 340 } // end of namespace Ice | 349 } // end of namespace Ice |
| 341 | 350 |
| 342 X86INSTS_DEFINE_STATIC_DATA(X8664, X8664::Traits) | 351 X86INSTS_DEFINE_STATIC_DATA(X8664, X8664::Traits) |
| OLD | NEW |