OLD | NEW |
---|---|
1 //===- subzero/src/IceInst.cpp - High-level instruction implementation ----===// | 1 //===- subzero/src/IceInst.cpp - High-level 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 ICEINSTICMP_TABLE | 70 ICEINSTICMP_TABLE |
71 #undef X | 71 #undef X |
72 }; | 72 }; |
73 | 73 |
74 } // end of anonymous namespace | 74 } // end of anonymous namespace |
75 | 75 |
76 Inst::Inst(Cfg *Func, InstKind Kind, SizeT MaxSrcs, Variable *Dest) | 76 Inst::Inst(Cfg *Func, InstKind Kind, SizeT MaxSrcs, Variable *Dest) |
77 : Kind(Kind), Number(Func->newInstNumber()), Dest(Dest), MaxSrcs(MaxSrcs), | 77 : Kind(Kind), Number(Func->newInstNumber()), Dest(Dest), MaxSrcs(MaxSrcs), |
78 Srcs(Func->allocateArrayOf<Operand *>(MaxSrcs)), LiveRangesEnded(0) {} | 78 Srcs(Func->allocateArrayOf<Operand *>(MaxSrcs)), LiveRangesEnded(0) {} |
79 | 79 |
80 IceString Inst::getInstName() const { | |
81 if (!BuildDefs::dump()) | |
82 return "???"; | |
83 | |
84 switch (Kind) { | |
85 #define X(InstrKind, name) \ | |
Jim Stichnoth
2016/01/27 22:31:51
If you want to take the X() approach, I would add
| |
86 case InstrKind: \ | |
87 return name | |
John
2016/01/27 21:14:46
You could have just returned a capitalized version
Eric Holk
2016/01/27 21:28:10
Jim wanted them to be lowercase for use in dump(),
| |
88 X(Unreachable, "unreachable"); | |
89 X(Alloca, "alloca"); | |
90 X(Arithmetic, "arithmetic"); | |
91 X(Br, "br"); | |
92 X(Call, "call"); | |
93 X(Cast, "cast"); | |
94 X(ExtractElement, "extractelement"); | |
95 X(Fcmp, "fcmp"); | |
96 X(Icmp, "icmp"); | |
97 X(IntrinsicCall, "intrinsiccall"); | |
98 X(InsertElement, "insertelement"); | |
99 X(Load, "load"); | |
100 X(Phi, "phi"); | |
101 X(Ret, "ret"); | |
102 X(Select, "select"); | |
103 X(Store, "store"); | |
104 X(Switch, "switch"); | |
105 X(Assign, "assign"); | |
106 X(BundleLock, "bundlelock"); | |
107 X(BundleUnlock, "bundleunlock"); | |
108 X(FakeDef, "fakedef"); | |
109 X(FakeUse, "fakeuse"); | |
110 X(FakeKill, "fakekill"); | |
111 X(JumpTable, "jumptable"); | |
112 #undef X | |
113 default: | |
114 assert(Kind >= Target); | |
115 return "target"; | |
116 } | |
117 } | |
118 | |
80 // Assign the instruction a new number. | 119 // Assign the instruction a new number. |
81 void Inst::renumber(Cfg *Func) { | 120 void Inst::renumber(Cfg *Func) { |
82 Number = isDeleted() ? NumberDeleted : Func->newInstNumber(); | 121 Number = isDeleted() ? NumberDeleted : Func->newInstNumber(); |
83 } | 122 } |
84 | 123 |
85 // Delete the instruction if its tentative Dead flag is still set after | 124 // Delete the instruction if its tentative Dead flag is still set after |
86 // liveness analysis. | 125 // liveness analysis. |
87 void Inst::deleteIfDead() { | 126 void Inst::deleteIfDead() { |
88 if (Dead) | 127 if (Dead) |
89 setDeleted(); | 128 setDeleted(); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 addSource(ByteCount); | 265 addSource(ByteCount); |
227 } | 266 } |
228 | 267 |
229 InstArithmetic::InstArithmetic(Cfg *Func, OpKind Op, Variable *Dest, | 268 InstArithmetic::InstArithmetic(Cfg *Func, OpKind Op, Variable *Dest, |
230 Operand *Source1, Operand *Source2) | 269 Operand *Source1, Operand *Source2) |
231 : InstHighLevel(Func, Inst::Arithmetic, 2, Dest), Op(Op) { | 270 : InstHighLevel(Func, Inst::Arithmetic, 2, Dest), Op(Op) { |
232 addSource(Source1); | 271 addSource(Source1); |
233 addSource(Source2); | 272 addSource(Source2); |
234 } | 273 } |
235 | 274 |
275 IceString InstArithmetic::getInstName() const { | |
276 if (!BuildDefs::dump()) | |
277 return "???"; | |
278 | |
279 return InstArithmeticAttributes[getOp()].DisplayString; | |
280 } | |
281 | |
236 const char *InstArithmetic::getOpName(OpKind Op) { | 282 const char *InstArithmetic::getOpName(OpKind Op) { |
237 size_t OpIndex = static_cast<size_t>(Op); | 283 size_t OpIndex = static_cast<size_t>(Op); |
238 return OpIndex < InstArithmetic::_num | 284 return OpIndex < InstArithmetic::_num |
239 ? InstArithmeticAttributes[OpIndex].DisplayString | 285 ? InstArithmeticAttributes[OpIndex].DisplayString |
240 : "???"; | 286 : "???"; |
241 } | 287 } |
242 | 288 |
243 bool InstArithmetic::isCommutative() const { | 289 bool InstArithmetic::isCommutative() const { |
244 return InstArithmeticAttributes[getOp()].IsCommutative; | 290 return InstArithmeticAttributes[getOp()].IsCommutative; |
245 } | 291 } |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
551 dump(Func); | 597 dump(Func); |
552 dumpExtras(Func); | 598 dumpExtras(Func); |
553 Str << "\n"; | 599 Str << "\n"; |
554 } | 600 } |
555 | 601 |
556 void Inst::dump(const Cfg *Func) const { | 602 void Inst::dump(const Cfg *Func) const { |
557 if (!BuildDefs::dump()) | 603 if (!BuildDefs::dump()) |
558 return; | 604 return; |
559 Ostream &Str = Func->getContext()->getStrDump(); | 605 Ostream &Str = Func->getContext()->getStrDump(); |
560 dumpDest(Func); | 606 dumpDest(Func); |
561 Str << " =~ "; | 607 Str << " =~ " << getInstName() << " "; |
562 dumpSources(Func); | 608 dumpSources(Func); |
563 } | 609 } |
564 | 610 |
565 void Inst::dumpExtras(const Cfg *Func) const { | 611 void Inst::dumpExtras(const Cfg *Func) const { |
566 if (!BuildDefs::dump()) | 612 if (!BuildDefs::dump()) |
567 return; | 613 return; |
568 Ostream &Str = Func->getContext()->getStrDump(); | 614 Ostream &Str = Func->getContext()->getStrDump(); |
569 bool First = true; | 615 bool First = true; |
570 // Print "LIVEEND={a,b,c}" for all source operands whose live ranges are | 616 // Print "LIVEEND={a,b,c}" for all source operands whose live ranges are |
571 // known to end at this instruction. | 617 // known to end at this instruction. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
612 return; | 658 return; |
613 if (getDest()) | 659 if (getDest()) |
614 getDest()->dump(Func); | 660 getDest()->dump(Func); |
615 } | 661 } |
616 | 662 |
617 void InstAlloca::dump(const Cfg *Func) const { | 663 void InstAlloca::dump(const Cfg *Func) const { |
618 if (!BuildDefs::dump()) | 664 if (!BuildDefs::dump()) |
619 return; | 665 return; |
620 Ostream &Str = Func->getContext()->getStrDump(); | 666 Ostream &Str = Func->getContext()->getStrDump(); |
621 dumpDest(Func); | 667 dumpDest(Func); |
622 Str << " = alloca i8, i32 "; | 668 Str << " = alloca i8, i32 "; |
Jim Stichnoth
2016/01/27 22:31:51
I was actually thinking this should be changed to:
| |
623 getSizeInBytes()->dump(Func); | 669 getSizeInBytes()->dump(Func); |
624 if (getAlignInBytes()) | 670 if (getAlignInBytes()) |
625 Str << ", align " << getAlignInBytes(); | 671 Str << ", align " << getAlignInBytes(); |
626 } | 672 } |
627 | 673 |
628 void InstArithmetic::dump(const Cfg *Func) const { | 674 void InstArithmetic::dump(const Cfg *Func) const { |
629 if (!BuildDefs::dump()) | 675 if (!BuildDefs::dump()) |
630 return; | 676 return; |
631 Ostream &Str = Func->getContext()->getStrDump(); | 677 Ostream &Str = Func->getContext()->getStrDump(); |
632 dumpDest(Func); | 678 dumpDest(Func); |
633 Str << " = " << InstArithmeticAttributes[getOp()].DisplayString << " " | 679 Str << " = " << getInstName() << " " << getDest()->getType() << " "; |
634 << getDest()->getType() << " "; | |
635 dumpSources(Func); | 680 dumpSources(Func); |
636 } | 681 } |
637 | 682 |
638 void InstAssign::dump(const Cfg *Func) const { | 683 void InstAssign::dump(const Cfg *Func) const { |
639 if (!BuildDefs::dump()) | 684 if (!BuildDefs::dump()) |
640 return; | 685 return; |
641 Ostream &Str = Func->getContext()->getStrDump(); | 686 Ostream &Str = Func->getContext()->getStrDump(); |
642 dumpDest(Func); | 687 dumpDest(Func); |
643 Str << " = " << getDest()->getType() << " "; | 688 Str << " = " << getDest()->getType() << " "; |
644 dumpSources(Func); | 689 dumpSources(Func); |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
967 // upper 32 bits of rax. We need to recognize and preserve these. | 1012 // upper 32 bits of rax. We need to recognize and preserve these. |
968 return true; | 1013 return true; |
969 } | 1014 } |
970 if (!Dest->hasReg() && !SrcVar->hasReg() && | 1015 if (!Dest->hasReg() && !SrcVar->hasReg() && |
971 Dest->getStackOffset() == SrcVar->getStackOffset()) | 1016 Dest->getStackOffset() == SrcVar->getStackOffset()) |
972 return true; | 1017 return true; |
973 return false; | 1018 return false; |
974 } | 1019 } |
975 | 1020 |
976 } // end of namespace Ice | 1021 } // end of namespace Ice |
OLD | NEW |