OLD | NEW |
---|---|
1 //===- subzero/src/IceInstX8632.h - Low-level x86 instructions --*- C++ -*-===// | 1 //===- subzero/src/IceInstX8632.h - Low-level x86 instructions --*- C++ -*-===// |
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 declares the InstX8632 and OperandX8632 classes and | 10 // This file declares the InstX8632 and OperandX8632 classes and |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 class InstX8632 : public InstTarget { | 132 class InstX8632 : public InstTarget { |
133 public: | 133 public: |
134 enum InstKindX8632 { | 134 enum InstKindX8632 { |
135 k__Start = Inst::Target, | 135 k__Start = Inst::Target, |
136 Adc, | 136 Adc, |
137 Add, | 137 Add, |
138 Addps, | 138 Addps, |
139 Addss, | 139 Addss, |
140 And, | 140 And, |
141 Br, | 141 Br, |
142 Bsf, | |
143 Bsr, | |
142 Call, | 144 Call, |
143 Cdq, | 145 Cdq, |
146 Cmov, | |
144 Cmpxchg, | 147 Cmpxchg, |
145 Cmpxchg8b, | 148 Cmpxchg8b, |
146 Cvt, | 149 Cvt, |
147 Div, | 150 Div, |
148 Divps, | 151 Divps, |
149 Divss, | 152 Divss, |
150 Fld, | 153 Fld, |
151 Fstp, | 154 Fstp, |
152 Icmp, | 155 Icmp, |
153 Idiv, | 156 Idiv, |
(...skipping 27 matching lines...) Expand all Loading... | |
181 Sub, | 184 Sub, |
182 Subps, | 185 Subps, |
183 Subss, | 186 Subss, |
184 Test, | 187 Test, |
185 Ucomiss, | 188 Ucomiss, |
186 UD2, | 189 UD2, |
187 Xadd, | 190 Xadd, |
188 Xchg, | 191 Xchg, |
189 Xor | 192 Xor |
190 }; | 193 }; |
194 | |
195 enum BrCond { | |
196 #define X(tag, dump, emit) tag, | |
197 ICEINSTX8632BR_TABLE | |
198 #undef X | |
199 Br_None | |
200 }; | |
201 | |
191 static const char *getWidthString(Type Ty); | 202 static const char *getWidthString(Type Ty); |
192 virtual void emit(const Cfg *Func) const = 0; | 203 virtual void emit(const Cfg *Func) const = 0; |
193 virtual void dump(const Cfg *Func) const; | 204 virtual void dump(const Cfg *Func) const; |
194 | 205 |
195 protected: | 206 protected: |
196 InstX8632(Cfg *Func, InstKindX8632 Kind, SizeT Maxsrcs, Variable *Dest) | 207 InstX8632(Cfg *Func, InstKindX8632 Kind, SizeT Maxsrcs, Variable *Dest) |
197 : InstTarget(Func, static_cast<InstKind>(Kind), Maxsrcs, Dest) {} | 208 : InstTarget(Func, static_cast<InstKind>(Kind), Maxsrcs, Dest) {} |
198 virtual ~InstX8632() {} | 209 virtual ~InstX8632() {} |
199 static bool isClassof(const Inst *Inst, InstKindX8632 MyKind) { | 210 static bool isClassof(const Inst *Inst, InstKindX8632 MyKind) { |
200 return Inst->getKind() == static_cast<InstKind>(MyKind); | 211 return Inst->getKind() == static_cast<InstKind>(MyKind); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 InstX8632Label(Cfg *Func, TargetX8632 *Target); | 266 InstX8632Label(Cfg *Func, TargetX8632 *Target); |
256 InstX8632Label(const InstX8632Label &) LLVM_DELETED_FUNCTION; | 267 InstX8632Label(const InstX8632Label &) LLVM_DELETED_FUNCTION; |
257 InstX8632Label &operator=(const InstX8632Label &) LLVM_DELETED_FUNCTION; | 268 InstX8632Label &operator=(const InstX8632Label &) LLVM_DELETED_FUNCTION; |
258 virtual ~InstX8632Label() {} | 269 virtual ~InstX8632Label() {} |
259 SizeT Number; // used only for unique label string generation | 270 SizeT Number; // used only for unique label string generation |
260 }; | 271 }; |
261 | 272 |
262 // Conditional and unconditional branch instruction. | 273 // Conditional and unconditional branch instruction. |
263 class InstX8632Br : public InstX8632 { | 274 class InstX8632Br : public InstX8632 { |
264 public: | 275 public: |
265 enum BrCond { | |
266 #define X(tag, dump, emit) tag, | |
267 ICEINSTX8632BR_TABLE | |
268 #undef X | |
269 Br_None | |
270 }; | |
271 | |
272 // Create a conditional branch to a node. | 276 // Create a conditional branch to a node. |
273 static InstX8632Br *create(Cfg *Func, CfgNode *TargetTrue, | 277 static InstX8632Br *create(Cfg *Func, CfgNode *TargetTrue, |
274 CfgNode *TargetFalse, BrCond Condition) { | 278 CfgNode *TargetFalse, BrCond Condition) { |
275 return new (Func->allocate<InstX8632Br>()) | 279 return new (Func->allocate<InstX8632Br>()) |
276 InstX8632Br(Func, TargetTrue, TargetFalse, NULL, Condition); | 280 InstX8632Br(Func, TargetTrue, TargetFalse, NULL, Condition); |
277 } | 281 } |
278 // Create an unconditional branch to a node. | 282 // Create an unconditional branch to a node. |
279 static InstX8632Br *create(Cfg *Func, CfgNode *Target) { | 283 static InstX8632Br *create(Cfg *Func, CfgNode *Target) { |
280 return new (Func->allocate<InstX8632Br>()) | 284 return new (Func->allocate<InstX8632Br>()) |
281 InstX8632Br(Func, NULL, Target, NULL, Br_None); | 285 InstX8632Br(Func, NULL, Target, NULL, Br_None); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
538 static bool classof(const Inst *Inst) { return isClassof(Inst, Shrd); } | 542 static bool classof(const Inst *Inst) { return isClassof(Inst, Shrd); } |
539 | 543 |
540 private: | 544 private: |
541 InstX8632Shrd(Cfg *Func, Variable *Dest, Variable *Source1, | 545 InstX8632Shrd(Cfg *Func, Variable *Dest, Variable *Source1, |
542 Variable *Source2); | 546 Variable *Source2); |
543 InstX8632Shrd(const InstX8632Shrd &) LLVM_DELETED_FUNCTION; | 547 InstX8632Shrd(const InstX8632Shrd &) LLVM_DELETED_FUNCTION; |
544 InstX8632Shrd &operator=(const InstX8632Shrd &) LLVM_DELETED_FUNCTION; | 548 InstX8632Shrd &operator=(const InstX8632Shrd &) LLVM_DELETED_FUNCTION; |
545 virtual ~InstX8632Shrd() {} | 549 virtual ~InstX8632Shrd() {} |
546 }; | 550 }; |
547 | 551 |
552 // Bit-scan-{forward,reverse} instructions. Finds the {least,most} significant | |
553 // '1' bit, and stores the 0-based position in the Dest register. | |
554 // If the Source is all zeroes, then the Dest is undefined and the ZF flag | |
555 // is set. Otherwise, the ZF flag is cleared. | |
556 template <InstX8632::InstKindX8632 K> | |
557 class InstX8632BitScan : public InstX8632 { | |
wala
2014/07/15 00:16:31
The other instruction classes in the file are defi
Jim Stichnoth
2014/07/15 17:15:02
You're right that this is a unary op, but not the
jvoung (off chromium)
2014/07/15 21:30:23
That sounds reasonable. I'll refactor.
I think mo
| |
558 public: | |
559 static InstX8632BitScan *create(Cfg *Func, Variable *Dest, Operand *Source) { | |
560 return new (Func->allocate<InstX8632BitScan>()) | |
561 InstX8632BitScan(Func, Dest, Source); | |
562 } | |
563 virtual void emit(const Cfg *Func) const { | |
564 Ostream &Str = Func->getContext()->getStrEmit(); | |
565 assert(getSrcSize() == 1); | |
566 Str << "\t" << Opcode << "\t"; | |
567 getDest()->emit(Func); | |
568 Str << ", "; | |
569 getSrc(0)->emit(Func); | |
570 Str << "\n"; | |
571 } | |
572 virtual void dump(const Cfg *Func) const { | |
573 Ostream &Str = Func->getContext()->getStrDump(); | |
574 dumpDest(Func); | |
575 Str << " = " << Opcode << "." << getDest()->getType() << " "; | |
576 dumpSources(Func); | |
577 } | |
578 static bool classof(const Inst *Inst) { return isClassof(Inst, K); } | |
579 | |
580 private: | |
581 InstX8632BitScan(Cfg *Func, Variable *Dest, Operand *Source) | |
582 : InstX8632(Func, K, 1, Dest) { | |
583 addSource(Source); | |
584 } | |
585 InstX8632BitScan(const InstX8632BitScan &) LLVM_DELETED_FUNCTION; | |
586 InstX8632BitScan &operator=(const InstX8632BitScan &) LLVM_DELETED_FUNCTION; | |
587 virtual ~InstX8632BitScan() {} | |
588 | |
589 static const char *Opcode; | |
590 }; | |
591 | |
592 typedef InstX8632BitScan<InstX8632::Bsf> InstX8632Bsf; | |
593 typedef InstX8632BitScan<InstX8632::Bsr> InstX8632Bsr; | |
594 | |
548 // Cdq instruction - sign-extend eax into edx | 595 // Cdq instruction - sign-extend eax into edx |
549 class InstX8632Cdq : public InstX8632 { | 596 class InstX8632Cdq : public InstX8632 { |
550 public: | 597 public: |
551 static InstX8632Cdq *create(Cfg *Func, Variable *Dest, Operand *Source) { | 598 static InstX8632Cdq *create(Cfg *Func, Variable *Dest, Operand *Source) { |
552 return new (Func->allocate<InstX8632Cdq>()) | 599 return new (Func->allocate<InstX8632Cdq>()) |
553 InstX8632Cdq(Func, Dest, Source); | 600 InstX8632Cdq(Func, Dest, Source); |
554 } | 601 } |
555 virtual void emit(const Cfg *Func) const; | 602 virtual void emit(const Cfg *Func) const; |
556 virtual void dump(const Cfg *Func) const; | 603 virtual void dump(const Cfg *Func) const; |
557 static bool classof(const Inst *Inst) { return isClassof(Inst, Cdq); } | 604 static bool classof(const Inst *Inst) { return isClassof(Inst, Cdq); } |
558 | 605 |
559 private: | 606 private: |
560 InstX8632Cdq(Cfg *Func, Variable *Dest, Operand *Source); | 607 InstX8632Cdq(Cfg *Func, Variable *Dest, Operand *Source); |
561 InstX8632Cdq(const InstX8632Cdq &) LLVM_DELETED_FUNCTION; | 608 InstX8632Cdq(const InstX8632Cdq &) LLVM_DELETED_FUNCTION; |
562 InstX8632Cdq &operator=(const InstX8632Cdq &) LLVM_DELETED_FUNCTION; | 609 InstX8632Cdq &operator=(const InstX8632Cdq &) LLVM_DELETED_FUNCTION; |
563 virtual ~InstX8632Cdq() {} | 610 virtual ~InstX8632Cdq() {} |
564 }; | 611 }; |
565 | 612 |
613 // Conditional move instruction. | |
614 class InstX8632Cmov : public InstX8632 { | |
615 public: | |
616 static InstX8632Cmov *create(Cfg *Func, Variable *Dest, Operand *Source, | |
617 BrCond Cond) { | |
618 return new (Func->allocate<InstX8632Cmov>()) | |
619 InstX8632Cmov(Func, Dest, Source, Cond); | |
620 } | |
621 virtual void emit(const Cfg *Func) const; | |
622 virtual void dump(const Cfg *Func) const; | |
623 static bool classof(const Inst *Inst) { return isClassof(Inst, Cmov); } | |
624 | |
625 private: | |
626 InstX8632Cmov(Cfg *Func, Variable *Dest, Operand *Source, BrCond Cond); | |
627 InstX8632Cmov(const InstX8632Cmov &) LLVM_DELETED_FUNCTION; | |
628 InstX8632Cmov &operator=(const InstX8632Cmov &) LLVM_DELETED_FUNCTION; | |
629 virtual ~InstX8632Cmov() {} | |
630 | |
631 BrCond Condition; | |
632 }; | |
633 | |
566 // Cmpxchg instruction - cmpxchg <dest>, <desired> will compare if <dest> | 634 // Cmpxchg instruction - cmpxchg <dest>, <desired> will compare if <dest> |
567 // equals eax. If so, the ZF is set and <desired> is stored in <dest>. | 635 // equals eax. If so, the ZF is set and <desired> is stored in <dest>. |
568 // If not, ZF is cleared and <dest> is copied to eax (or subregister). | 636 // If not, ZF is cleared and <dest> is copied to eax (or subregister). |
569 // <dest> can be a register or memory, while <desired> must be a register. | 637 // <dest> can be a register or memory, while <desired> must be a register. |
570 // It is the user's responsiblity to mark eax with a FakeDef. | 638 // It is the user's responsiblity to mark eax with a FakeDef. |
571 class InstX8632Cmpxchg : public InstX8632Lockable { | 639 class InstX8632Cmpxchg : public InstX8632Lockable { |
572 public: | 640 public: |
573 static InstX8632Cmpxchg *create(Cfg *Func, Operand *DestOrAddr, Variable *Eax, | 641 static InstX8632Cmpxchg *create(Cfg *Func, Operand *DestOrAddr, Variable *Eax, |
574 Variable *Desired, bool Locked) { | 642 Variable *Desired, bool Locked) { |
575 return new (Func->allocate<InstX8632Cmpxchg>()) | 643 return new (Func->allocate<InstX8632Cmpxchg>()) |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1010 private: | 1078 private: |
1011 InstX8632Xchg(Cfg *Func, Operand *Dest, Variable *Source); | 1079 InstX8632Xchg(Cfg *Func, Operand *Dest, Variable *Source); |
1012 InstX8632Xchg(const InstX8632Xchg &) LLVM_DELETED_FUNCTION; | 1080 InstX8632Xchg(const InstX8632Xchg &) LLVM_DELETED_FUNCTION; |
1013 InstX8632Xchg &operator=(const InstX8632Xchg &) LLVM_DELETED_FUNCTION; | 1081 InstX8632Xchg &operator=(const InstX8632Xchg &) LLVM_DELETED_FUNCTION; |
1014 virtual ~InstX8632Xchg() {} | 1082 virtual ~InstX8632Xchg() {} |
1015 }; | 1083 }; |
1016 | 1084 |
1017 } // end of namespace Ice | 1085 } // end of namespace Ice |
1018 | 1086 |
1019 #endif // SUBZERO_SRC_ICEINSTX8632_H | 1087 #endif // SUBZERO_SRC_ICEINSTX8632_H |
OLD | NEW |