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

Side by Side Diff: src/IceInstX8632.cpp

Issue 1419903002: Subzero: Refactor x86 register definitions to use the alias mechanism. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Add some comments Created 5 years, 1 month 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/IceInstX8632.cpp - X86-32 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 14 matching lines...) Expand all
25 #include "IceRegistersX8632.h" 25 #include "IceRegistersX8632.h"
26 #include "IceTargetLoweringX8632.h" 26 #include "IceTargetLoweringX8632.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<TargetX8632>::InstBrAttributesType
34 MachineTraits<TargetX8632>::InstBrAttributes[] = { 34 MachineTraits<TargetX8632>::InstBrAttributes[] = {
35 #define X(tag, encode, opp, dump, emit) \ 35 #define X(val, encode, opp, dump, emit) \
36 { X8632::Traits::Cond::opp, dump, emit } \ 36 { X8632::Traits::Cond::opp, dump, emit } \
37 , 37 ,
38 ICEINSTX8632BR_TABLE 38 ICEINSTX8632BR_TABLE
39 #undef X 39 #undef X
40 }; 40 };
41 41
42 const MachineTraits<TargetX8632>::InstCmppsAttributesType 42 const MachineTraits<TargetX8632>::InstCmppsAttributesType
43 MachineTraits<TargetX8632>::InstCmppsAttributes[] = { 43 MachineTraits<TargetX8632>::InstCmppsAttributes[] = {
44 #define X(tag, emit) \ 44 #define X(val, emit) \
45 { emit } \ 45 { emit } \
46 , 46 ,
47 ICEINSTX8632CMPPS_TABLE 47 ICEINSTX8632CMPPS_TABLE
48 #undef X 48 #undef X
49 }; 49 };
50 50
51 const MachineTraits<TargetX8632>::TypeAttributesType 51 const MachineTraits<TargetX8632>::TypeAttributesType
52 MachineTraits<TargetX8632>::TypeAttributes[] = { 52 MachineTraits<TargetX8632>::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 } \
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 return; 103 return;
104 Ostream &Str = Func->getContext()->getStrEmit(); 104 Ostream &Str = Func->getContext()->getStrEmit();
105 if (SegmentReg != DefaultSegment) { 105 if (SegmentReg != DefaultSegment) {
106 assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM); 106 assert(SegmentReg >= 0 && SegmentReg < SegReg_NUM);
107 Str << "%" << X8632::Traits::InstSegmentRegNames[SegmentReg] << ":"; 107 Str << "%" << X8632::Traits::InstSegmentRegNames[SegmentReg] << ":";
108 } 108 }
109 // Emit as Offset(Base,Index,1<<Shift). Offset is emitted without the leading 109 // Emit as Offset(Base,Index,1<<Shift). Offset is emitted without the leading
110 // '$'. Omit the (Base,Index,1<<Shift) part if Base==nullptr. 110 // '$'. Omit the (Base,Index,1<<Shift) part if Base==nullptr.
111 if (!Offset) { 111 if (!Offset) {
112 // No offset, emit nothing. 112 // No offset, emit nothing.
113 } else if (const auto CI = llvm::dyn_cast<ConstantInteger32>(Offset)) { 113 } else if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(Offset)) {
114 if (Base == nullptr || CI->getValue()) 114 if (Base == nullptr || CI->getValue())
115 // Emit a non-zero offset without a leading '$'. 115 // Emit a non-zero offset without a leading '$'.
116 Str << CI->getValue(); 116 Str << CI->getValue();
117 } else if (const auto CR = llvm::dyn_cast<ConstantRelocatable>(Offset)) { 117 } else if (const auto *CR = llvm::dyn_cast<ConstantRelocatable>(Offset)) {
118 CR->emitWithoutPrefix(Func->getTarget()); 118 CR->emitWithoutPrefix(Func->getTarget());
119 } else { 119 } else {
120 llvm_unreachable("Invalid offset type for x86 mem operand"); 120 llvm_unreachable("Invalid offset type for x86 mem operand");
121 } 121 }
122 122
123 if (Base) { 123 if (Base) {
124 Str << "("; 124 Str << "(";
125 Base->emit(Func); 125 Base->emit(Func);
126 if (Index) { 126 if (Index) {
127 Str << ","; 127 Str << ",";
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 Index->dump(Func); 159 Index->dump(Func);
160 else 160 else
161 Index->dump(Str); 161 Index->dump(Str);
162 Dumped = true; 162 Dumped = true;
163 } 163 }
164 // Pretty-print the Offset. 164 // Pretty-print the Offset.
165 bool OffsetIsZero = false; 165 bool OffsetIsZero = false;
166 bool OffsetIsNegative = false; 166 bool OffsetIsNegative = false;
167 if (!Offset) { 167 if (!Offset) {
168 OffsetIsZero = true; 168 OffsetIsZero = true;
169 } else if (const auto CI = llvm::dyn_cast<ConstantInteger32>(Offset)) { 169 } else if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(Offset)) {
170 OffsetIsZero = (CI->getValue() == 0); 170 OffsetIsZero = (CI->getValue() == 0);
171 OffsetIsNegative = (static_cast<int32_t>(CI->getValue()) < 0); 171 OffsetIsNegative = (static_cast<int32_t>(CI->getValue()) < 0);
172 } else { 172 } else {
173 assert(llvm::isa<ConstantRelocatable>(Offset)); 173 assert(llvm::isa<ConstantRelocatable>(Offset));
174 } 174 }
175 if (Dumped) { 175 if (Dumped) {
176 if (!OffsetIsZero) { // Suppress if Offset is known to be 0 176 if (!OffsetIsZero) { // Suppress if Offset is known to be 0
177 if (!OffsetIsNegative) // Suppress if Offset is known to be negative 177 if (!OffsetIsNegative) // Suppress if Offset is known to be negative
178 Str << "+"; 178 Str << "+";
179 Offset->dump(Func, Str); 179 Offset->dump(Func, Str);
(...skipping 13 matching lines...) Expand all
193 } 193 }
194 } 194 }
195 195
196 MachineTraits<TargetX8632>::Address 196 MachineTraits<TargetX8632>::Address
197 MachineTraits<TargetX8632>::X86OperandMem::toAsmAddress( 197 MachineTraits<TargetX8632>::X86OperandMem::toAsmAddress(
198 MachineTraits<TargetX8632>::Assembler *Asm) const { 198 MachineTraits<TargetX8632>::Assembler *Asm) const {
199 int32_t Disp = 0; 199 int32_t Disp = 0;
200 AssemblerFixup *Fixup = nullptr; 200 AssemblerFixup *Fixup = nullptr;
201 // Determine the offset (is it relocatable?) 201 // Determine the offset (is it relocatable?)
202 if (getOffset()) { 202 if (getOffset()) {
203 if (const auto CI = llvm::dyn_cast<ConstantInteger32>(getOffset())) { 203 if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(getOffset())) {
204 Disp = static_cast<int32_t>(CI->getValue()); 204 Disp = static_cast<int32_t>(CI->getValue());
205 } else if (const auto CR = 205 } else if (const auto CR =
206 llvm::dyn_cast<ConstantRelocatable>(getOffset())) { 206 llvm::dyn_cast<ConstantRelocatable>(getOffset())) {
207 Disp = CR->getOffset(); 207 Disp = CR->getOffset();
208 Fixup = Asm->createFixup(RelFixup, CR); 208 Fixup = Asm->createFixup(RelFixup, CR);
209 } else { 209 } else {
210 llvm_unreachable("Unexpected offset type"); 210 llvm_unreachable("Unexpected offset type");
211 } 211 }
212 } 212 }
213 213
214 // Now convert to the various possible forms. 214 // Now convert to the various possible forms.
215 if (getBase() && getIndex()) { 215 if (getBase() && getIndex()) {
216 return X8632::Traits::Address( 216 return X8632::Traits::Address(getEncodedGPR(getBase()->getRegNum()),
217 RegX8632::getEncodedGPR(getBase()->getRegNum()), 217 getEncodedGPR(getIndex()->getRegNum()),
218 RegX8632::getEncodedGPR(getIndex()->getRegNum()), 218 X8632::Traits::ScaleFactor(getShift()), Disp);
219 X8632::Traits::ScaleFactor(getShift()), Disp);
220 } else if (getBase()) { 219 } else if (getBase()) {
221 return X8632::Traits::Address( 220 return X8632::Traits::Address(getEncodedGPR(getBase()->getRegNum()), Disp);
222 RegX8632::getEncodedGPR(getBase()->getRegNum()), Disp);
223 } else if (getIndex()) { 221 } else if (getIndex()) {
224 return X8632::Traits::Address( 222 return X8632::Traits::Address(getEncodedGPR(getIndex()->getRegNum()),
225 RegX8632::getEncodedGPR(getIndex()->getRegNum()), 223 X8632::Traits::ScaleFactor(getShift()), Disp);
226 X8632::Traits::ScaleFactor(getShift()), Disp);
227 } else if (Fixup) { 224 } else if (Fixup) {
228 return X8632::Traits::Address::Absolute(Disp, Fixup); 225 return X8632::Traits::Address::Absolute(Disp, Fixup);
229 } else { 226 } else {
230 return X8632::Traits::Address::Absolute(Disp); 227 return X8632::Traits::Address::Absolute(Disp);
231 } 228 }
232 } 229 }
233 230
234 MachineTraits<TargetX8632>::Address 231 MachineTraits<TargetX8632>::Address
235 MachineTraits<TargetX8632>::VariableSplit::toAsmAddress(const Cfg *Func) const { 232 MachineTraits<TargetX8632>::VariableSplit::toAsmAddress(const Cfg *Func) const {
236 assert(!Var->hasReg()); 233 assert(!Var->hasReg());
237 const ::Ice::TargetLowering *Target = Func->getTarget(); 234 const ::Ice::TargetLowering *Target = Func->getTarget();
238 int32_t Offset = 235 int32_t Offset =
239 Var->getStackOffset() + Target->getStackAdjustment() + getOffset(); 236 Var->getStackOffset() + Target->getStackAdjustment() + getOffset();
240 return X8632::Traits::Address( 237 return X8632::Traits::Address(getEncodedGPR(Target->getFrameOrStackReg()),
241 RegX8632::getEncodedGPR(Target->getFrameOrStackReg()), Offset); 238 Offset);
242 } 239 }
243 240
244 void MachineTraits<TargetX8632>::VariableSplit::emit(const Cfg *Func) const { 241 void MachineTraits<TargetX8632>::VariableSplit::emit(const Cfg *Func) const {
245 if (!BuildDefs::dump()) 242 if (!BuildDefs::dump())
246 return; 243 return;
247 Ostream &Str = Func->getContext()->getStrEmit(); 244 Ostream &Str = Func->getContext()->getStrEmit();
248 assert(!Var->hasReg()); 245 assert(!Var->hasReg());
249 // The following is copied/adapted from TargetX8632::emitVariable(). 246 // The following is copied/adapted from TargetX8632::emitVariable().
250 const ::Ice::TargetLowering *Target = Func->getTarget(); 247 const ::Ice::TargetLowering *Target = Func->getTarget();
251 const Type Ty = IceType_i32; 248 constexpr Type Ty = IceType_i32;
252 int32_t Offset = 249 int32_t Offset =
253 Var->getStackOffset() + Target->getStackAdjustment() + getOffset(); 250 Var->getStackOffset() + Target->getStackAdjustment() + getOffset();
254 if (Offset) 251 if (Offset)
255 Str << Offset; 252 Str << Offset;
256 Str << "(%" << Target->getRegName(Target->getFrameOrStackReg(), Ty) << ")"; 253 Str << "(%" << Target->getRegName(Target->getFrameOrStackReg(), Ty) << ")";
257 } 254 }
258 255
259 void MachineTraits<TargetX8632>::VariableSplit::dump(const Cfg *Func, 256 void MachineTraits<TargetX8632>::VariableSplit::dump(const Cfg *Func,
260 Ostream &Str) const { 257 Ostream &Str) const {
261 if (!BuildDefs::dump()) 258 if (!BuildDefs::dump())
(...skipping 11 matching lines...) Expand all
273 Var->dump(Func); 270 Var->dump(Func);
274 else 271 else
275 Var->dump(Str); 272 Var->dump(Str);
276 Str << ")"; 273 Str << ")";
277 } 274 }
278 275
279 } // namespace X86Internal 276 } // namespace X86Internal
280 } // end of namespace Ice 277 } // end of namespace Ice
281 278
282 X86INSTS_DEFINE_STATIC_DATA(TargetX8632) 279 X86INSTS_DEFINE_STATIC_DATA(TargetX8632)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698