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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 ICETYPEX8664_TABLE | 57 ICETYPEX8664_TABLE |
58 #undef X | 58 #undef X |
59 }; | 59 }; |
60 | 60 |
61 void MachineTraits<TargetX8664>::X86Operand::dump(const Cfg *, | 61 void MachineTraits<TargetX8664>::X86Operand::dump(const Cfg *, |
62 Ostream &Str) const { | 62 Ostream &Str) const { |
63 if (BuildDefs::dump()) | 63 if (BuildDefs::dump()) |
64 Str << "<OperandX8664>"; | 64 Str << "<OperandX8664>"; |
65 } | 65 } |
66 | 66 |
67 MachineTraits<TargetX8664>::X86OperandMem::X86OperandMem(Cfg *Func, Type Ty, | 67 MachineTraits<TargetX8664>::X86OperandMem::X86OperandMem( |
68 Variable *Base, | 68 Cfg *Func, Type Ty, Variable *Base, Constant *Offset, Variable *Index, |
69 Constant *Offset, | 69 uint16_t Shift, bool IsPIC) |
70 Variable *Index, | |
71 uint16_t Shift) | |
72 : X86Operand(kMem, Ty), Base(Base), Offset(Offset), Index(Index), | 70 : X86Operand(kMem, Ty), Base(Base), Offset(Offset), Index(Index), |
73 Shift(Shift) { | 71 Shift(Shift), IsPIC(IsPIC) { |
74 assert(Shift <= 3); | 72 assert(Shift <= 3); |
75 Vars = nullptr; | 73 Vars = nullptr; |
76 NumVars = 0; | 74 NumVars = 0; |
77 if (Base) | 75 if (Base) |
78 ++NumVars; | 76 ++NumVars; |
79 if (Index) | 77 if (Index) |
80 ++NumVars; | 78 ++NumVars; |
81 if (NumVars) { | 79 if (NumVars) { |
82 Vars = Func->allocateArrayOf<Variable *>(NumVars); | 80 Vars = Func->allocateArrayOf<Variable *>(NumVars); |
83 SizeT I = 0; | 81 SizeT I = 0; |
(...skipping 11 matching lines...) Expand all Loading... |
95 Ostream &Str = Func->getContext()->getStrEmit(); | 93 Ostream &Str = Func->getContext()->getStrEmit(); |
96 // Emit as Offset(Base,Index,1<<Shift). Offset is emitted without the leading | 94 // Emit as Offset(Base,Index,1<<Shift). Offset is emitted without the leading |
97 // '$'. Omit the (Base,Index,1<<Shift) part if Base==nullptr. | 95 // '$'. Omit the (Base,Index,1<<Shift) part if Base==nullptr. |
98 if (!Offset) { | 96 if (!Offset) { |
99 // No offset, emit nothing. | 97 // No offset, emit nothing. |
100 } else if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(Offset)) { | 98 } else if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(Offset)) { |
101 if (Base == nullptr || CI->getValue()) | 99 if (Base == nullptr || CI->getValue()) |
102 // Emit a non-zero offset without a leading '$'. | 100 // Emit a non-zero offset without a leading '$'. |
103 Str << CI->getValue(); | 101 Str << CI->getValue(); |
104 } else if (const auto *CR = llvm::dyn_cast<ConstantRelocatable>(Offset)) { | 102 } else if (const auto *CR = llvm::dyn_cast<ConstantRelocatable>(Offset)) { |
105 CR->emitWithoutPrefix(Func->getTarget()); | 103 const bool UseNonsfi = Func->getContext()->getFlags().getUseNonsfi(); |
| 104 CR->emitWithoutPrefix(Func->getTarget(), UseNonsfi ? "@GOTOFF" : ""); |
106 } else { | 105 } else { |
107 llvm_unreachable("Invalid offset type for x86 mem operand"); | 106 llvm_unreachable("Invalid offset type for x86 mem operand"); |
108 } | 107 } |
109 | 108 |
110 if (Base || Index) { | 109 if (Base || Index) { |
111 Str << "("; | 110 Str << "("; |
112 if (Base) | 111 if (Base) |
113 Base->emit(Func); | 112 Base->emit(Func); |
114 if (Index) { | 113 if (Index) { |
115 Str << ","; | 114 Str << ","; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 assert(!getIndex()->isRematerializable()); | 180 assert(!getIndex()->isRematerializable()); |
182 int32_t Disp = 0; | 181 int32_t Disp = 0; |
183 AssemblerFixup *Fixup = nullptr; | 182 AssemblerFixup *Fixup = nullptr; |
184 // Determine the offset (is it relocatable?) | 183 // Determine the offset (is it relocatable?) |
185 if (getOffset()) { | 184 if (getOffset()) { |
186 if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(getOffset())) { | 185 if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(getOffset())) { |
187 Disp = static_cast<int32_t>(CI->getValue()); | 186 Disp = static_cast<int32_t>(CI->getValue()); |
188 } else if (const auto CR = | 187 } else if (const auto CR = |
189 llvm::dyn_cast<ConstantRelocatable>(getOffset())) { | 188 llvm::dyn_cast<ConstantRelocatable>(getOffset())) { |
190 Disp = CR->getOffset() - 4; | 189 Disp = CR->getOffset() - 4; |
191 Fixup = Asm->createFixup(PcRelFixup, CR); | 190 Fixup = Asm->createFixup(FixupKindPcRel, CR); |
192 } else { | 191 } else { |
193 llvm_unreachable("Unexpected offset type"); | 192 llvm_unreachable("Unexpected offset type"); |
194 } | 193 } |
195 } | 194 } |
196 | 195 |
197 // Now convert to the various possible forms. | 196 // Now convert to the various possible forms. |
198 if (getBase() && getIndex()) { | 197 if (getBase() && getIndex()) { |
199 return X8664::Traits::Address(getEncodedGPR(getBase()->getRegNum()), | 198 return X8664::Traits::Address(getEncodedGPR(getBase()->getRegNum()), |
200 getEncodedGPR(getIndex()->getRegNum()), | 199 getEncodedGPR(getIndex()->getRegNum()), |
201 X8664::Traits::ScaleFactor(getShift()), Disp, | 200 X8664::Traits::ScaleFactor(getShift()), Disp, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 Var->dump(Func); | 251 Var->dump(Func); |
253 else | 252 else |
254 Var->dump(Str); | 253 Var->dump(Str); |
255 Str << ")"; | 254 Str << ")"; |
256 } | 255 } |
257 | 256 |
258 } // namespace X86Internal | 257 } // namespace X86Internal |
259 } // end of namespace Ice | 258 } // end of namespace Ice |
260 | 259 |
261 X86INSTS_DEFINE_STATIC_DATA(TargetX8664) | 260 X86INSTS_DEFINE_STATIC_DATA(TargetX8664) |
OLD | NEW |