Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(805)

Side by Side Diff: src/IceInstX8664.cpp

Issue 1257643004: Subzero. Buildable, non-functional TargetLoweringX8664. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 //===- subzero/src/IceInstX8632.cpp - X86-32 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
11 /// This file defines X8632 specific data related to X8632 Instructions and 11 /// This file defines X8664 specific data related to X8664 Instructions and
12 /// Instruction traits. These are declared in the IceTargetLoweringX8632Traits.h 12 /// Instruction traits. These are declared in the IceTargetLoweringX8664Traits.h
13 /// header file. 13 /// header file.
14 /// 14 ///
15 /// This file also defines X8632 operand specific methods (dump and emit.) 15 /// This file also defines X8664 operand specific methods (dump and emit.)
16 /// 16 ///
17 //===----------------------------------------------------------------------===// 17 //===----------------------------------------------------------------------===//
18 #include "IceInstX8632.h" 18 #include "IceInstX8664.h"
19 19
20 #include "IceAssemblerX8632.h" 20 #include "IceAssemblerX8664.h"
21 #include "IceCfg.h" 21 #include "IceCfg.h"
22 #include "IceCfgNode.h" 22 #include "IceCfgNode.h"
23 #include "IceConditionCodesX8632.h" 23 #include "IceConditionCodesX8664.h"
24 #include "IceInst.h" 24 #include "IceInst.h"
25 #include "IceRegistersX8632.h" 25 #include "IceRegistersX8664.h"
26 #include "IceTargetLoweringX8632.h" 26 #include "IceTargetLoweringX8664.h"
27 #include "IceOperand.h" 27 #include "IceOperand.h"
28 28
29 namespace Ice { 29 namespace Ice {
30 30
31 namespace X86Internal { 31 namespace X86Internal {
32 32
33 const MachineTraits<TargetX8632>::InstBrAttributesType 33 const MachineTraits<TargetX8664>::InstBrAttributesType
34 MachineTraits<TargetX8632>::InstBrAttributes[] = { 34 MachineTraits<TargetX8664>::InstBrAttributes[] = {
35 #define X(tag, encode, opp, dump, emit) \ 35 #define X(tag, encode, opp, dump, emit) \
36 { X8632::Traits::Cond::opp, dump, emit } \ 36 { X8664::Traits::Cond::opp, dump, emit } \
37 , 37 ,
38 ICEINSTX8632BR_TABLE 38 ICEINSTX8664BR_TABLE
39 #undef X 39 #undef X
40 }; 40 };
41 41
42 const MachineTraits<TargetX8632>::InstCmppsAttributesType 42 const MachineTraits<TargetX8664>::InstCmppsAttributesType
43 MachineTraits<TargetX8632>::InstCmppsAttributes[] = { 43 MachineTraits<TargetX8664>::InstCmppsAttributes[] = {
44 #define X(tag, emit) \ 44 #define X(tag, emit) \
45 { emit } \ 45 { emit } \
46 , 46 ,
47 ICEINSTX8632CMPPS_TABLE 47 ICEINSTX8664CMPPS_TABLE
48 #undef X 48 #undef X
49 }; 49 };
50 50
51 const MachineTraits<TargetX8632>::TypeAttributesType 51 const MachineTraits<TargetX8664>::TypeAttributesType
52 MachineTraits<TargetX8632>::TypeAttributes[] = { 52 MachineTraits<TargetX8664>::TypeAttributes[] = {
53 #define X(tag, elementty, cvt, sdss, pack, width, fld) \ 53 #define X(tag, elementty, cvt, sdss, pack, width, fld) \
54 { cvt, sdss, pack, width, fld } \ 54 { cvt, sdss, pack, width, fld } \
55 , 55 ,
56 ICETYPEX8632_TABLE 56 ICETYPEX8664_TABLE
57 #undef X 57 #undef X
58 }; 58 };
59 59
60 const char *MachineTraits<TargetX8632>::InstSegmentRegNames[] = { 60 void MachineTraits<TargetX8664>::X86Operand::dump(const Cfg *,
61 #define X(val, name, prefix) name,
62 SEG_REGX8632_TABLE
63 #undef X
64 };
65
66 uint8_t MachineTraits<TargetX8632>::InstSegmentPrefixes[] = {
67 #define X(val, name, prefix) prefix,
68 SEG_REGX8632_TABLE
69 #undef X
70 };
71
72 void MachineTraits<TargetX8632>::X86Operand::dump(const Cfg *,
73 Ostream &Str) const { 61 Ostream &Str) const {
74 if (BuildDefs::dump()) 62 if (BuildDefs::dump())
75 Str << "<OperandX8632>"; 63 Str << "<OperandX8664>";
76 } 64 }
77 65
78 MachineTraits<TargetX8632>::X86OperandMem::X86OperandMem( 66 MachineTraits<TargetX8664>::X86OperandMem::X86OperandMem(
79 Cfg *Func, Type Ty, Variable *Base, Constant *Offset, Variable *Index, 67 Cfg *Func, Type Ty, Variable *Base, Constant *Offset, Variable *Index,
80 uint16_t Shift, SegmentRegisters SegmentReg) 68 uint16_t Shift, SegmentRegisters SegmentReg)
81 : X86Operand(kMem, Ty), Base(Base), Offset(Offset), Index(Index), 69 : X86Operand(kMem, Ty), Base(Base), Offset(Offset), Index(Index),
82 Shift(Shift), SegmentReg(SegmentReg), Randomized(false) { 70 Shift(Shift), SegmentReg(SegmentReg), Randomized(false) {
83 assert(Shift <= 3); 71 assert(Shift <= 3);
84 Vars = nullptr; 72 Vars = nullptr;
85 NumVars = 0; 73 NumVars = 0;
86 if (Base) 74 if (Base)
87 ++NumVars; 75 ++NumVars;
88 if (Index) 76 if (Index)
89 ++NumVars; 77 ++NumVars;
90 if (NumVars) { 78 if (NumVars) {
91 Vars = Func->allocateArrayOf<Variable *>(NumVars); 79 Vars = Func->allocateArrayOf<Variable *>(NumVars);
92 SizeT I = 0; 80 SizeT I = 0;
93 if (Base) 81 if (Base)
94 Vars[I++] = Base; 82 Vars[I++] = Base;
95 if (Index) 83 if (Index)
96 Vars[I++] = Index; 84 Vars[I++] = Index;
97 assert(I == NumVars); 85 assert(I == NumVars);
98 } 86 }
99 } 87 }
100 88
101 void MachineTraits<TargetX8632>::X86OperandMem::emit(const Cfg *Func) const { 89 void MachineTraits<TargetX8664>::X86OperandMem::emit(const Cfg *Func) const {
102 if (!BuildDefs::dump()) 90 if (!BuildDefs::dump())
103 return; 91 return;
104 Ostream &Str = Func->getContext()->getStrEmit(); 92 Ostream &Str = Func->getContext()->getStrEmit();
105 if (SegmentReg != DefaultSegment) { 93 assert(SegmentReg == DefaultSegment);
106 assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM);
107 Str << "%" << X8632::Traits::InstSegmentRegNames[SegmentReg] << ":";
108 }
109 // Emit as Offset(Base,Index,1<<Shift). 94 // Emit as Offset(Base,Index,1<<Shift).
110 // Offset is emitted without the leading '$'. 95 // Offset is emitted without the leading '$'.
111 // Omit the (Base,Index,1<<Shift) part if Base==nullptr. 96 // Omit the (Base,Index,1<<Shift) part if Base==nullptr.
112 if (!Offset) { 97 if (!Offset) {
113 // No offset, emit nothing. 98 // No offset, emit nothing.
114 } else if (const auto CI = llvm::dyn_cast<ConstantInteger32>(Offset)) { 99 } else if (const auto CI = llvm::dyn_cast<ConstantInteger32>(Offset)) {
115 if (Base == nullptr || CI->getValue()) 100 if (Base == nullptr || CI->getValue())
116 // Emit a non-zero offset without a leading '$'. 101 // Emit a non-zero offset without a leading '$'.
117 Str << CI->getValue(); 102 Str << CI->getValue();
118 } else if (const auto CR = llvm::dyn_cast<ConstantRelocatable>(Offset)) { 103 } else if (const auto CR = llvm::dyn_cast<ConstantRelocatable>(Offset)) {
119 CR->emitWithoutPrefix(Func->getTarget()); 104 CR->emitWithoutPrefix(Func->getTarget());
120 } else { 105 } else {
121 llvm_unreachable("Invalid offset type for x86 mem operand"); 106 llvm_unreachable("Invalid offset type for x86 mem operand");
122 } 107 }
123 108
124 if (Base) { 109 if (Base) {
125 Str << "("; 110 Str << "(";
126 Base->emit(Func); 111 Base->emit(Func);
127 if (Index) { 112 if (Index) {
128 Str << ","; 113 Str << ",";
129 Index->emit(Func); 114 Index->emit(Func);
130 if (Shift) 115 if (Shift)
131 Str << "," << (1u << Shift); 116 Str << "," << (1u << Shift);
132 } 117 }
133 Str << ")"; 118 Str << ")";
134 } 119 }
135 } 120 }
136 121
137 void MachineTraits<TargetX8632>::X86OperandMem::dump(const Cfg *Func, 122 void MachineTraits<TargetX8664>::X86OperandMem::dump(const Cfg *Func,
138 Ostream &Str) const { 123 Ostream &Str) const {
139 if (!BuildDefs::dump()) 124 if (!BuildDefs::dump())
140 return; 125 return;
141 if (SegmentReg != DefaultSegment) { 126 assert(SegmentReg == DefaultSegment);
142 assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM);
143 Str << X8632::Traits::InstSegmentRegNames[SegmentReg] << ":";
144 }
145 bool Dumped = false; 127 bool Dumped = false;
146 Str << "["; 128 Str << "[";
147 if (Base) { 129 if (Base) {
148 if (Func) 130 if (Func)
149 Base->dump(Func); 131 Base->dump(Func);
150 else 132 else
151 Base->dump(Str); 133 Base->dump(Str);
152 Dumped = true; 134 Dumped = true;
153 } 135 }
154 if (Index) { 136 if (Index) {
(...skipping 24 matching lines...) Expand all
179 Str << "+"; 161 Str << "+";
180 Offset->dump(Func, Str); 162 Offset->dump(Func, Str);
181 } 163 }
182 } else { 164 } else {
183 // There is only the offset. 165 // There is only the offset.
184 Offset->dump(Func, Str); 166 Offset->dump(Func, Str);
185 } 167 }
186 Str << "]"; 168 Str << "]";
187 } 169 }
188 170
189 void MachineTraits<TargetX8632>::X86OperandMem::emitSegmentOverride( 171 void MachineTraits<TargetX8664>::X86OperandMem::emitSegmentOverride(
190 MachineTraits<TargetX8632>::Assembler *Asm) const { 172 MachineTraits<TargetX8664>::Assembler *) const {
191 if (SegmentReg != DefaultSegment) { 173 assert(SegmentReg == DefaultSegment);
192 assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM);
193 Asm->emitSegmentOverride(X8632::Traits::InstSegmentPrefixes[SegmentReg]);
194 }
195 } 174 }
196 175
197 MachineTraits<TargetX8632>::Address 176 MachineTraits<TargetX8664>::Address
198 MachineTraits<TargetX8632>::X86OperandMem::toAsmAddress( 177 MachineTraits<TargetX8664>::X86OperandMem::toAsmAddress(
199 MachineTraits<TargetX8632>::Assembler *Asm) const { 178 MachineTraits<TargetX8664>::Assembler *Asm) const {
200 int32_t Disp = 0; 179 int32_t Disp = 0;
201 AssemblerFixup *Fixup = nullptr; 180 AssemblerFixup *Fixup = nullptr;
202 // Determine the offset (is it relocatable?) 181 // Determine the offset (is it relocatable?)
203 if (getOffset()) { 182 if (getOffset()) {
204 if (const auto CI = llvm::dyn_cast<ConstantInteger32>(getOffset())) { 183 if (const auto CI = llvm::dyn_cast<ConstantInteger32>(getOffset())) {
205 Disp = static_cast<int32_t>(CI->getValue()); 184 Disp = static_cast<int32_t>(CI->getValue());
206 } else if (const auto CR = 185 } else if (const auto CR =
207 llvm::dyn_cast<ConstantRelocatable>(getOffset())) { 186 llvm::dyn_cast<ConstantRelocatable>(getOffset())) {
208 Disp = CR->getOffset(); 187 Disp = CR->getOffset();
209 Fixup = Asm->createFixup(llvm::ELF::R_386_32, CR); 188 Fixup = Asm->createFixup(llvm::ELF::R_386_32, CR);
210 } else { 189 } else {
211 llvm_unreachable("Unexpected offset type"); 190 llvm_unreachable("Unexpected offset type");
212 } 191 }
213 } 192 }
214 193
215 // Now convert to the various possible forms. 194 // Now convert to the various possible forms.
216 if (getBase() && getIndex()) { 195 if (getBase() && getIndex()) {
217 return X8632::Traits::Address( 196 return X8664::Traits::Address(
218 RegX8632::getEncodedGPR(getBase()->getRegNum()), 197 RegX8664::getEncodedGPR(getBase()->getRegNum()),
219 RegX8632::getEncodedGPR(getIndex()->getRegNum()), 198 RegX8664::getEncodedGPR(getIndex()->getRegNum()),
220 X8632::Traits::ScaleFactor(getShift()), Disp); 199 X8664::Traits::ScaleFactor(getShift()), Disp);
221 } else if (getBase()) { 200 } else if (getBase()) {
222 return X8632::Traits::Address( 201 return X8664::Traits::Address(
223 RegX8632::getEncodedGPR(getBase()->getRegNum()), Disp); 202 RegX8664::getEncodedGPR(getBase()->getRegNum()), Disp);
224 } else if (getIndex()) { 203 } else if (getIndex()) {
225 return X8632::Traits::Address( 204 return X8664::Traits::Address(
226 RegX8632::getEncodedGPR(getIndex()->getRegNum()), 205 RegX8664::getEncodedGPR(getIndex()->getRegNum()),
227 X8632::Traits::ScaleFactor(getShift()), Disp); 206 X8664::Traits::ScaleFactor(getShift()), Disp);
228 } else if (Fixup) { 207 } else if (Fixup) {
229 return X8632::Traits::Address::Absolute(Disp, Fixup); 208 return X8664::Traits::Address::Absolute(Disp, Fixup);
230 } else { 209 } else {
231 return X8632::Traits::Address::Absolute(Disp); 210 return X8664::Traits::Address::Absolute(Disp);
232 } 211 }
233 } 212 }
234 213
235 MachineTraits<TargetX8632>::Address 214 MachineTraits<TargetX8664>::Address
236 MachineTraits<TargetX8632>::VariableSplit::toAsmAddress(const Cfg *Func) const { 215 MachineTraits<TargetX8664>::VariableSplit::toAsmAddress(const Cfg *Func) const {
237 assert(!Var->hasReg()); 216 assert(!Var->hasReg());
238 const ::Ice::TargetLowering *Target = Func->getTarget(); 217 const ::Ice::TargetLowering *Target = Func->getTarget();
239 int32_t Offset = 218 int32_t Offset =
240 Var->getStackOffset() + Target->getStackAdjustment() + getOffset(); 219 Var->getStackOffset() + Target->getStackAdjustment() + getOffset();
241 return X8632::Traits::Address( 220 return X8664::Traits::Address(
242 RegX8632::getEncodedGPR(Target->getFrameOrStackReg()), Offset); 221 RegX8664::getEncodedGPR(Target->getFrameOrStackReg()), Offset);
243 } 222 }
244 223
245 void MachineTraits<TargetX8632>::VariableSplit::emit(const Cfg *Func) const { 224 void MachineTraits<TargetX8664>::VariableSplit::emit(const Cfg *Func) const {
246 if (!BuildDefs::dump()) 225 if (!BuildDefs::dump())
247 return; 226 return;
248 Ostream &Str = Func->getContext()->getStrEmit(); 227 Ostream &Str = Func->getContext()->getStrEmit();
249 assert(!Var->hasReg()); 228 assert(!Var->hasReg());
250 // The following is copied/adapted from TargetX8632::emitVariable(). 229 // The following is copied/adapted from TargetX8664::emitVariable().
251 const ::Ice::TargetLowering *Target = Func->getTarget(); 230 const ::Ice::TargetLowering *Target = Func->getTarget();
252 const Type Ty = IceType_i32; 231 const Type Ty = IceType_i32;
253 int32_t Offset = 232 int32_t Offset =
254 Var->getStackOffset() + Target->getStackAdjustment() + getOffset(); 233 Var->getStackOffset() + Target->getStackAdjustment() + getOffset();
255 if (Offset) 234 if (Offset)
256 Str << Offset; 235 Str << Offset;
257 Str << "(%" << Target->getRegName(Target->getFrameOrStackReg(), Ty) << ")"; 236 Str << "(%" << Target->getRegName(Target->getFrameOrStackReg(), Ty) << ")";
258 } 237 }
259 238
260 void MachineTraits<TargetX8632>::VariableSplit::dump(const Cfg *Func, 239 void MachineTraits<TargetX8664>::VariableSplit::dump(const Cfg *Func,
261 Ostream &Str) const { 240 Ostream &Str) const {
262 if (!BuildDefs::dump()) 241 if (!BuildDefs::dump())
263 return; 242 return;
264 switch (Part) { 243 switch (Part) {
265 case Low: 244 case Low:
266 Str << "low"; 245 Str << "low";
267 break; 246 break;
268 case High: 247 case High:
269 Str << "high"; 248 Str << "high";
270 break; 249 break;
271 } 250 }
272 Str << "("; 251 Str << "(";
273 if (Func) 252 if (Func)
274 Var->dump(Func); 253 Var->dump(Func);
275 else 254 else
276 Var->dump(Str); 255 Var->dump(Str);
277 Str << ")"; 256 Str << ")";
278 } 257 }
279 258
280 } // namespace X86Internal 259 } // namespace X86Internal
281 } // end of namespace Ice 260 } // end of namespace Ice
282 261
283 X86INSTS_DEFINE_STATIC_DATA(TargetX8632); 262 X86INSTS_DEFINE_STATIC_DATA(TargetX8664);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698