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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // Emit a non-zero offset without a leading '$'. | 131 // Emit a non-zero offset without a leading '$'. |
132 Str << CI->getValue() + Disp; | 132 Str << CI->getValue() + Disp; |
133 } else if (const auto *CR = llvm::dyn_cast<ConstantRelocatable>(Offset)) { | 133 } else if (const auto *CR = llvm::dyn_cast<ConstantRelocatable>(Offset)) { |
134 // TODO(sehr): ConstantRelocatable still needs updating for | 134 // TODO(sehr): ConstantRelocatable still needs updating for |
135 // rematerializable base/index and Disp. | 135 // rematerializable base/index and Disp. |
136 assert(Disp == 0); | 136 assert(Disp == 0); |
137 const bool UseNonsfi = Func->getContext()->getFlags().getUseNonsfi(); | 137 const bool UseNonsfi = Func->getContext()->getFlags().getUseNonsfi(); |
138 CR->emitWithoutPrefix(Target, UseNonsfi ? "@GOTOFF" : ""); | 138 CR->emitWithoutPrefix(Target, UseNonsfi ? "@GOTOFF" : ""); |
139 assert(!UseNonsfi); | 139 assert(!UseNonsfi); |
140 if (Base == nullptr && Index == nullptr) { | 140 if (Base == nullptr && Index == nullptr) { |
141 if (CR->getName() != "") { // rip-relative addressing. | 141 // rip-relative addressing. |
142 if (NeedSandboxing) { | 142 if (NeedSandboxing) { |
143 Str << "(%rip)"; | 143 Str << "(%rip)"; |
144 } else { | 144 } else { |
145 Str << "(%eip)"; | 145 Str << "(%eip)"; |
146 } | |
147 } | 146 } |
148 } | 147 } |
149 } else { | 148 } else { |
150 llvm_unreachable("Invalid offset type for x86 mem operand"); | 149 llvm_unreachable("Invalid offset type for x86 mem operand"); |
151 } | 150 } |
152 | 151 |
153 if (Base == nullptr && Index == nullptr) { | 152 if (Base == nullptr && Index == nullptr) { |
154 return; | 153 return; |
155 } | 154 } |
156 | 155 |
157 Str << "("; | 156 Str << "("; |
158 if (Base != nullptr) { | 157 if (Base != nullptr) { |
159 const Variable *B = Base; | 158 const Variable *B = Base; |
160 if (!NeedSandboxing) { | 159 if (!NeedSandboxing) { |
161 // TODO(jpp): stop abusing the operand's type to identify LEAs. | 160 // TODO(jpp): stop abusing the operand's type to identify LEAs. |
162 const Type MemType = getType(); | 161 const Type MemType = getType(); |
163 if (Base->getType() != IceType_i32 && MemType != IceType_void) { | 162 if (Base->getType() != IceType_i32 && MemType != IceType_void) { |
164 // X86-64 is ILP32, but %rsp and %rbp are accessed as 64-bit registers. | 163 // X86-64 is ILP32, but %rsp and %rbp are accessed as 64-bit registers. |
165 // For filetype=asm, they need to be emitted as their 32-bit sibilings. | 164 // For filetype=asm, they need to be emitted as their 32-bit sibilings. |
166 assert(Base->getType() == IceType_i64); | 165 assert(Base->getType() == IceType_i64); |
167 assert(Base->getRegNum() == RegX8664::Encoded_Reg_rsp || | 166 assert(Base->getRegNum() == RegX8664::Encoded_Reg_rsp || |
168 Base->getRegNum() == RegX8664::Encoded_Reg_rbp || | 167 Base->getRegNum() == RegX8664::Encoded_Reg_rbp || |
169 getType() == IceType_void); | 168 getType() == IceType_void); |
170 B = B->asType(IceType_i32, X8664::Traits::getGprForType( | 169 B = B->asType(Func, IceType_i32, X8664::Traits::getGprForType( |
171 IceType_i32, Base->getRegNum())); | 170 IceType_i32, Base->getRegNum())); |
172 } | 171 } |
173 } | 172 } |
174 | 173 |
175 B->emit(Func); | 174 B->emit(Func); |
176 } | 175 } |
177 | 176 |
178 if (Index != nullptr) { | 177 if (Index != nullptr) { |
179 Variable *I = Index; | 178 Variable *I = Index; |
180 Str << ","; | 179 Str << ","; |
181 I->emit(Func); | 180 I->emit(Func); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 assert(!getIndex()->isRematerializable()); | 259 assert(!getIndex()->isRematerializable()); |
261 } | 260 } |
262 | 261 |
263 AssemblerFixup *Fixup = nullptr; | 262 AssemblerFixup *Fixup = nullptr; |
264 // Determine the offset (is it relocatable?) | 263 // Determine the offset (is it relocatable?) |
265 if (getOffset() != nullptr) { | 264 if (getOffset() != nullptr) { |
266 if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(getOffset())) { | 265 if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(getOffset())) { |
267 Disp += static_cast<int32_t>(CI->getValue()); | 266 Disp += static_cast<int32_t>(CI->getValue()); |
268 } else if (const auto *CR = | 267 } else if (const auto *CR = |
269 llvm::dyn_cast<ConstantRelocatable>(getOffset())) { | 268 llvm::dyn_cast<ConstantRelocatable>(getOffset())) { |
270 if (CR->getName() != "") { | 269 const auto FixupKind = |
271 const auto FixupKind = | 270 (getBase() != nullptr || getIndex() != nullptr) ? FK_Abs : FK_PcRel; |
272 (getBase() != nullptr || getIndex() != nullptr) ? FK_Abs : FK_PcRel; | 271 const RelocOffsetT DispAdjustment = FixupKind == FK_PcRel ? 4 : 0; |
273 const RelocOffsetT DispAdjustment = FixupKind == FK_PcRel ? 4 : 0; | 272 Fixup = Asm->createFixup(FixupKind, CR); |
274 Fixup = Asm->createFixup(FixupKind, CR); | 273 Fixup->set_addend(-DispAdjustment); |
275 Fixup->set_addend(-DispAdjustment); | |
276 } | |
277 Disp = CR->getOffset(); | 274 Disp = CR->getOffset(); |
278 } else { | 275 } else { |
279 llvm_unreachable("Unexpected offset type"); | 276 llvm_unreachable("Unexpected offset type"); |
280 } | 277 } |
281 } | 278 } |
282 | 279 |
283 // Now convert to the various possible forms. | 280 // Now convert to the various possible forms. |
284 if (getBase() && getIndex()) { | 281 if (getBase() && getIndex()) { |
285 const bool NeedSandboxing = Target->needSandboxing(); | 282 const bool NeedSandboxing = Target->needSandboxing(); |
286 (void)NeedSandboxing; | 283 (void)NeedSandboxing; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 Var->dump(Func); | 353 Var->dump(Func); |
357 else | 354 else |
358 Var->dump(Str); | 355 Var->dump(Str); |
359 Str << ")"; | 356 Str << ")"; |
360 } | 357 } |
361 | 358 |
362 } // namespace X8664 | 359 } // namespace X8664 |
363 } // end of namespace Ice | 360 } // end of namespace Ice |
364 | 361 |
365 X86INSTS_DEFINE_STATIC_DATA(X8664, X8664::Traits) | 362 X86INSTS_DEFINE_STATIC_DATA(X8664, X8664::Traits) |
OLD | NEW |