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

Side by Side Diff: src/IceInstX8632.cpp

Issue 362463002: Subzero: lower the rest of the atomic operations. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: comment cleanup Created 6 years, 5 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/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 // This file implements the InstX8632 and OperandX8632 classes, 10 // This file implements the InstX8632 and OperandX8632 classes,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #define X(tag, cvt, sdss, width) \ 44 #define X(tag, cvt, sdss, width) \
45 { cvt, "" sdss, width } \ 45 { cvt, "" sdss, width } \
46 , 46 ,
47 ICETYPEX8632_TABLE 47 ICETYPEX8632_TABLE
48 #undef X 48 #undef X
49 }; 49 };
50 const size_t TypeX8632AttributesSize = 50 const size_t TypeX8632AttributesSize =
51 llvm::array_lengthof(TypeX8632Attributes); 51 llvm::array_lengthof(TypeX8632Attributes);
52 52
53 const char *InstX8632SegmentRegNames[] = { 53 const char *InstX8632SegmentRegNames[] = {
54 #define X(val, name) \ 54 #define X(val, name) name,
55 name, 55 SEG_REGX8632_TABLE
56 SEG_REGX8632_TABLE
57 #undef X 56 #undef X
58 }; 57 };
59 const size_t InstX8632SegmentRegNamesSize = 58 const size_t InstX8632SegmentRegNamesSize =
60 llvm::array_lengthof(InstX8632SegmentRegNames); 59 llvm::array_lengthof(InstX8632SegmentRegNames);
61 60
62 } // end of anonymous namespace 61 } // end of anonymous namespace
63 62
64 const char *InstX8632::getWidthString(Type Ty) { 63 const char *InstX8632::getWidthString(Type Ty) {
65 return TypeX8632Attributes[Ty].WidthString; 64 return TypeX8632Attributes[Ty].WidthString;
66 } 65 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } 132 }
134 133
135 InstX8632Cdq::InstX8632Cdq(Cfg *Func, Variable *Dest, Operand *Source) 134 InstX8632Cdq::InstX8632Cdq(Cfg *Func, Variable *Dest, Operand *Source)
136 : InstX8632(Func, InstX8632::Cdq, 1, Dest) { 135 : InstX8632(Func, InstX8632::Cdq, 1, Dest) {
137 assert(Dest->getRegNum() == TargetX8632::Reg_edx); 136 assert(Dest->getRegNum() == TargetX8632::Reg_edx);
138 assert(llvm::isa<Variable>(Source)); 137 assert(llvm::isa<Variable>(Source));
139 assert(llvm::dyn_cast<Variable>(Source)->getRegNum() == TargetX8632::Reg_eax); 138 assert(llvm::dyn_cast<Variable>(Source)->getRegNum() == TargetX8632::Reg_eax);
140 addSource(Source); 139 addSource(Source);
141 } 140 }
142 141
142 InstX8632Cmpxchg::InstX8632Cmpxchg(Cfg *Func, Operand *DestOrAddr,
143 Variable *Eax, Variable *Desired,
144 bool Locked)
145 : InstX8632Lockable(Func, InstX8632::Cmpxchg, 3,
146 llvm::dyn_cast<Variable>(DestOrAddr), Locked) {
147 assert(Eax->getRegNum() == TargetX8632::Reg_eax);
148 addSource(DestOrAddr);
149 addSource(Eax);
150 addSource(Desired);
151 }
152
153 InstX8632Cmpxchg8b::InstX8632Cmpxchg8b(Cfg *Func, OperandX8632 *Addr,
154 Variable *Edx, Variable *Eax,
155 Variable *Ecx, Variable *Ebx,
156 bool Locked)
157 : InstX8632Lockable(Func, InstX8632::Cmpxchg, 5, NULL, Locked) {
158 assert(Edx->getRegNum() == TargetX8632::Reg_edx);
159 assert(Eax->getRegNum() == TargetX8632::Reg_eax);
160 assert(Ecx->getRegNum() == TargetX8632::Reg_ecx);
161 assert(Ebx->getRegNum() == TargetX8632::Reg_ebx);
162 addSource(Addr);
163 addSource(Edx);
164 addSource(Eax);
165 addSource(Ecx);
166 addSource(Ebx);
167 }
168
143 InstX8632Cvt::InstX8632Cvt(Cfg *Func, Variable *Dest, Operand *Source) 169 InstX8632Cvt::InstX8632Cvt(Cfg *Func, Variable *Dest, Operand *Source)
144 : InstX8632(Func, InstX8632::Cvt, 1, Dest) { 170 : InstX8632(Func, InstX8632::Cvt, 1, Dest) {
145 addSource(Source); 171 addSource(Source);
146 } 172 }
147 173
148 InstX8632Icmp::InstX8632Icmp(Cfg *Func, Operand *Src0, Operand *Src1) 174 InstX8632Icmp::InstX8632Icmp(Cfg *Func, Operand *Src0, Operand *Src1)
149 : InstX8632(Func, InstX8632::Icmp, 2, NULL) { 175 : InstX8632(Func, InstX8632::Icmp, 2, NULL) {
150 addSource(Src0); 176 addSource(Src0);
151 addSource(Src1); 177 addSource(Src1);
152 } 178 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 } 277 }
252 278
253 InstX8632Ret::InstX8632Ret(Cfg *Func, Variable *Source) 279 InstX8632Ret::InstX8632Ret(Cfg *Func, Variable *Source)
254 : InstX8632(Func, InstX8632::Ret, Source ? 1 : 0, NULL) { 280 : InstX8632(Func, InstX8632::Ret, Source ? 1 : 0, NULL) {
255 if (Source) 281 if (Source)
256 addSource(Source); 282 addSource(Source);
257 } 283 }
258 284
259 InstX8632Xadd::InstX8632Xadd(Cfg *Func, Operand *Dest, Variable *Source, 285 InstX8632Xadd::InstX8632Xadd(Cfg *Func, Operand *Dest, Variable *Source,
260 bool Locked) 286 bool Locked)
261 : InstX8632(Func, InstX8632::Xadd, 2, llvm::dyn_cast<Variable>(Dest)), 287 : InstX8632Lockable(Func, InstX8632::Xadd, 2,
262 Locked(Locked) { 288 llvm::dyn_cast<Variable>(Dest), Locked) {
263 HasSideEffects = Locked;
264 addSource(Dest); 289 addSource(Dest);
265 addSource(Source); 290 addSource(Source);
266 } 291 }
292
293 InstX8632Xchg::InstX8632Xchg(Cfg *Func, Operand *Dest, Variable *Source)
294 : InstX8632(Func, InstX8632::Xchg, 2, llvm::dyn_cast<Variable>(Dest)) {
295 addSource(Dest);
296 addSource(Source);
297 }
267 298
268 // ======================== Dump routines ======================== // 299 // ======================== Dump routines ======================== //
269 300
270 void InstX8632::dump(const Cfg *Func) const { 301 void InstX8632::dump(const Cfg *Func) const {
271 Ostream &Str = Func->getContext()->getStrDump(); 302 Ostream &Str = Func->getContext()->getStrDump();
272 Str << "[X8632] "; 303 Str << "[X8632] ";
273 Inst::dump(Func); 304 Inst::dump(Func);
274 } 305 }
275 306
276 void InstX8632Label::emit(const Cfg *Func) const { 307 void InstX8632Label::emit(const Cfg *Func) const {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 if (ShiftReg && ShiftReg->getRegNum() == TargetX8632::Reg_ecx) { 396 if (ShiftReg && ShiftReg->getRegNum() == TargetX8632::Reg_ecx) {
366 Str << "cl"; 397 Str << "cl";
367 EmittedSrc1 = true; 398 EmittedSrc1 = true;
368 } 399 }
369 } 400 }
370 if (!EmittedSrc1) 401 if (!EmittedSrc1)
371 Inst->getSrc(1)->emit(Func); 402 Inst->getSrc(1)->emit(Func);
372 Str << "\n"; 403 Str << "\n";
373 } 404 }
374 405
406 template <> const char *InstX8632Neg::Opcode = "neg";
375 template <> const char *InstX8632Add::Opcode = "add"; 407 template <> const char *InstX8632Add::Opcode = "add";
376 template <> const char *InstX8632Adc::Opcode = "adc"; 408 template <> const char *InstX8632Adc::Opcode = "adc";
377 template <> const char *InstX8632Addss::Opcode = "addss"; 409 template <> const char *InstX8632Addss::Opcode = "addss";
378 template <> const char *InstX8632Sub::Opcode = "sub"; 410 template <> const char *InstX8632Sub::Opcode = "sub";
379 template <> const char *InstX8632Subss::Opcode = "subss"; 411 template <> const char *InstX8632Subss::Opcode = "subss";
380 template <> const char *InstX8632Sbb::Opcode = "sbb"; 412 template <> const char *InstX8632Sbb::Opcode = "sbb";
381 template <> const char *InstX8632And::Opcode = "and"; 413 template <> const char *InstX8632And::Opcode = "and";
382 template <> const char *InstX8632Or::Opcode = "or"; 414 template <> const char *InstX8632Or::Opcode = "or";
383 template <> const char *InstX8632Xor::Opcode = "xor"; 415 template <> const char *InstX8632Xor::Opcode = "xor";
384 template <> const char *InstX8632Imul::Opcode = "imul"; 416 template <> const char *InstX8632Imul::Opcode = "imul";
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 Str << "\tcdq\n"; 548 Str << "\tcdq\n";
517 } 549 }
518 550
519 void InstX8632Cdq::dump(const Cfg *Func) const { 551 void InstX8632Cdq::dump(const Cfg *Func) const {
520 Ostream &Str = Func->getContext()->getStrDump(); 552 Ostream &Str = Func->getContext()->getStrDump();
521 dumpDest(Func); 553 dumpDest(Func);
522 Str << " = cdq." << getSrc(0)->getType() << " "; 554 Str << " = cdq." << getSrc(0)->getType() << " ";
523 dumpSources(Func); 555 dumpSources(Func);
524 } 556 }
525 557
558 void InstX8632Cmpxchg::emit(const Cfg *Func) const {
559 Ostream &Str = Func->getContext()->getStrEmit();
560 assert(getSrcSize() == 3);
561 if (Locked) {
562 Str << "\tlock";
563 }
564 Str << "\tcmpxchg\t";
565 getSrc(0)->emit(Func);
566 Str << ", ";
567 getSrc(2)->emit(Func);
568 Str << "\n";
569 }
570
571 void InstX8632Cmpxchg::dump(const Cfg *Func) const {
572 Ostream &Str = Func->getContext()->getStrDump();
573 if (Locked) {
574 Str << "lock ";
575 }
576 Str << "cmpxchg." << getSrc(0)->getType() << " ";
577 dumpSources(Func);
578 }
579
580 void InstX8632Cmpxchg8b::emit(const Cfg *Func) const {
581 Ostream &Str = Func->getContext()->getStrEmit();
582 assert(getSrcSize() == 5);
583 if (Locked) {
584 Str << "\tlock";
585 }
586 Str << "\tcmpxchg8b\t";
587 getSrc(0)->emit(Func);
588 Str << "\n";
589 }
590
591 void InstX8632Cmpxchg8b::dump(const Cfg *Func) const {
592 Ostream &Str = Func->getContext()->getStrDump();
593 if (Locked) {
594 Str << "lock ";
595 }
596 Str << "cmpxchg8b ";
597 dumpSources(Func);
598 }
599
526 void InstX8632Cvt::emit(const Cfg *Func) const { 600 void InstX8632Cvt::emit(const Cfg *Func) const {
527 Ostream &Str = Func->getContext()->getStrEmit(); 601 Ostream &Str = Func->getContext()->getStrEmit();
528 assert(getSrcSize() == 1); 602 assert(getSrcSize() == 1);
529 Str << "\tcvts" << TypeX8632Attributes[getSrc(0)->getType()].CvtString << "2s" 603 Str << "\tcvts" << TypeX8632Attributes[getSrc(0)->getType()].CvtString << "2s"
530 << TypeX8632Attributes[getDest()->getType()].CvtString << "\t"; 604 << TypeX8632Attributes[getDest()->getType()].CvtString << "\t";
531 getDest()->emit(Func); 605 getDest()->emit(Func);
532 Str << ", "; 606 Str << ", ";
533 getSrc(0)->emit(Func); 607 getSrc(0)->emit(Func);
534 Str << "\n"; 608 Str << "\n";
535 } 609 }
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 void InstX8632Ret::dump(const Cfg *Func) const { 945 void InstX8632Ret::dump(const Cfg *Func) const {
872 Ostream &Str = Func->getContext()->getStrDump(); 946 Ostream &Str = Func->getContext()->getStrDump();
873 Type Ty = (getSrcSize() == 0 ? IceType_void : getSrc(0)->getType()); 947 Type Ty = (getSrcSize() == 0 ? IceType_void : getSrc(0)->getType());
874 Str << "ret." << Ty << " "; 948 Str << "ret." << Ty << " ";
875 dumpSources(Func); 949 dumpSources(Func);
876 } 950 }
877 951
878 void InstX8632Xadd::emit(const Cfg *Func) const { 952 void InstX8632Xadd::emit(const Cfg *Func) const {
879 Ostream &Str = Func->getContext()->getStrEmit(); 953 Ostream &Str = Func->getContext()->getStrEmit();
880 if (Locked) { 954 if (Locked) {
881 Str << "\tlock xadd "; 955 Str << "\tlock";
882 } else {
883 Str << "\txadd\t";
884 } 956 }
957 Str << "\txadd\t";
885 getSrc(0)->emit(Func); 958 getSrc(0)->emit(Func);
886 Str << ", "; 959 Str << ", ";
887 getSrc(1)->emit(Func); 960 getSrc(1)->emit(Func);
888 Str << "\n"; 961 Str << "\n";
889 } 962 }
890 963
891 void InstX8632Xadd::dump(const Cfg *Func) const { 964 void InstX8632Xadd::dump(const Cfg *Func) const {
892 Ostream &Str = Func->getContext()->getStrDump(); 965 Ostream &Str = Func->getContext()->getStrDump();
893 if (Locked) { 966 if (Locked) {
894 Str << "lock "; 967 Str << "lock ";
895 } 968 }
896 Type Ty = getSrc(0)->getType(); 969 Type Ty = getSrc(0)->getType();
897 Str << "xadd." << Ty << " "; 970 Str << "xadd." << Ty << " ";
898 dumpSources(Func); 971 dumpSources(Func);
899 } 972 }
900 973
974 void InstX8632Xchg::emit(const Cfg *Func) const {
975 Ostream &Str = Func->getContext()->getStrEmit();
976 Str << "\txchg\t";
977 getSrc(0)->emit(Func);
978 Str << ", ";
979 getSrc(1)->emit(Func);
980 Str << "\n";
981 }
982
983 void InstX8632Xchg::dump(const Cfg *Func) const {
984 Ostream &Str = Func->getContext()->getStrDump();
985 Type Ty = getSrc(0)->getType();
986 Str << "xchg." << Ty << " ";
987 dumpSources(Func);
988 }
989
901 void OperandX8632::dump(const Cfg *Func) const { 990 void OperandX8632::dump(const Cfg *Func) const {
902 Ostream &Str = Func->getContext()->getStrDump(); 991 Ostream &Str = Func->getContext()->getStrDump();
903 Str << "<OperandX8632>"; 992 Str << "<OperandX8632>";
904 } 993 }
905 994
906 void OperandX8632Mem::emit(const Cfg *Func) const { 995 void OperandX8632Mem::emit(const Cfg *Func) const {
907 Ostream &Str = Func->getContext()->getStrEmit(); 996 Ostream &Str = Func->getContext()->getStrEmit();
908 Str << TypeX8632Attributes[getType()].WidthString << " "; 997 Str << TypeX8632Attributes[getType()].WidthString << " ";
909 if (SegmentReg != DefaultSegment) { 998 if (SegmentReg != DefaultSegment) {
910 assert(SegmentReg >= 0 && 999 assert(SegmentReg >= 0 &&
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 default: 1113 default:
1025 Str << "???"; 1114 Str << "???";
1026 break; 1115 break;
1027 } 1116 }
1028 Str << "("; 1117 Str << "(";
1029 Var->dump(Func); 1118 Var->dump(Func);
1030 Str << ")"; 1119 Str << ")";
1031 } 1120 }
1032 1121
1033 } // end of namespace Ice 1122 } // end of namespace Ice
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698