OLD | NEW |
1 //===- subzero/src/IceOperand.cpp - High-level operand implementation -----===// | 1 //===- subzero/src/IceOperand.cpp - High-level operand 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 Operand class and its | 10 // This file implements the Operand class and its |
11 // target-independent subclasses, primarily for the methods of the | 11 // target-independent subclasses, primarily for the methods of the |
12 // Variable class. | 12 // Variable class. |
13 // | 13 // |
14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
15 | 15 |
16 #include "IceCfg.h" | 16 #include "IceCfg.h" |
17 #include "IceInst.h" | 17 #include "IceInst.h" |
18 #include "IceOperand.h" | 18 #include "IceOperand.h" |
| 19 #include "IceTargetLowering.h" // dumping stack/frame pointer register |
19 | 20 |
20 namespace Ice { | 21 namespace Ice { |
21 | 22 |
22 bool operator<(const RelocatableTuple &A, const RelocatableTuple &B) { | 23 bool operator<(const RelocatableTuple &A, const RelocatableTuple &B) { |
23 if (A.Offset != B.Offset) | 24 if (A.Offset != B.Offset) |
24 return A.Offset < B.Offset; | 25 return A.Offset < B.Offset; |
25 if (A.SuppressMangling != B.SuppressMangling) | 26 if (A.SuppressMangling != B.SuppressMangling) |
26 return A.SuppressMangling < B.SuppressMangling; | 27 return A.SuppressMangling < B.SuppressMangling; |
27 return A.Name < B.Name; | 28 return A.Name < B.Name; |
28 } | 29 } |
29 | 30 |
| 31 bool operator<(const RegWeight &A, const RegWeight &B) { |
| 32 return A.getWeight() < B.getWeight(); |
| 33 } |
| 34 bool operator<=(const RegWeight &A, const RegWeight &B) { return !(B < A); } |
| 35 bool operator==(const RegWeight &A, const RegWeight &B) { |
| 36 return !(B < A) && !(A < B); |
| 37 } |
| 38 |
30 void Variable::setUse(const Inst *Inst, const CfgNode *Node) { | 39 void Variable::setUse(const Inst *Inst, const CfgNode *Node) { |
31 if (DefNode == NULL) | 40 if (DefNode == NULL) |
32 return; | 41 return; |
33 if (llvm::isa<InstPhi>(Inst) || Node != DefNode) | 42 if (llvm::isa<InstPhi>(Inst) || Node != DefNode) |
34 DefNode = NULL; | 43 DefNode = NULL; |
35 } | 44 } |
36 | 45 |
37 void Variable::setDefinition(Inst *Inst, const CfgNode *Node) { | 46 void Variable::setDefinition(Inst *Inst, const CfgNode *Node) { |
38 if (DefNode == NULL) | 47 if (DefNode == NULL) |
39 return; | 48 return; |
(...skipping 19 matching lines...) Expand all Loading... |
59 } | 68 } |
60 | 69 |
61 IceString Variable::getName() const { | 70 IceString Variable::getName() const { |
62 if (!Name.empty()) | 71 if (!Name.empty()) |
63 return Name; | 72 return Name; |
64 char buf[30]; | 73 char buf[30]; |
65 snprintf(buf, llvm::array_lengthof(buf), "__%u", getIndex()); | 74 snprintf(buf, llvm::array_lengthof(buf), "__%u", getIndex()); |
66 return buf; | 75 return buf; |
67 } | 76 } |
68 | 77 |
| 78 Variable Variable::asType(Type Ty) { |
| 79 Variable V(Ty, DefNode, Number, Name); |
| 80 V.RegNum = RegNum; |
| 81 V.StackOffset = StackOffset; |
| 82 return V; |
| 83 } |
| 84 |
69 // ======================== dump routines ======================== // | 85 // ======================== dump routines ======================== // |
70 | 86 |
| 87 void Variable::emit(const Cfg *Func) const { |
| 88 Func->getTarget()->emitVariable(this, Func); |
| 89 } |
| 90 |
71 void Variable::dump(const Cfg *Func) const { | 91 void Variable::dump(const Cfg *Func) const { |
72 Ostream &Str = Func->getContext()->getStrDump(); | 92 Ostream &Str = Func->getContext()->getStrDump(); |
73 const CfgNode *CurrentNode = Func->getCurrentNode(); | 93 const CfgNode *CurrentNode = Func->getCurrentNode(); |
74 (void)CurrentNode; // used only in assert() | 94 (void)CurrentNode; // used only in assert() |
75 assert(CurrentNode == NULL || DefNode == NULL || DefNode == CurrentNode); | 95 assert(CurrentNode == NULL || DefNode == NULL || DefNode == CurrentNode); |
76 Str << "%" << getName(); | 96 if (Func->getContext()->isVerbose(IceV_RegOrigins) || |
| 97 (!hasReg() && !Func->getTarget()->hasComputedFrame())) |
| 98 Str << "%" << getName(); |
| 99 if (hasReg()) { |
| 100 if (Func->getContext()->isVerbose(IceV_RegOrigins)) |
| 101 Str << ":"; |
| 102 Str << Func->getTarget()->getRegName(RegNum, getType()); |
| 103 } else if (Func->getTarget()->hasComputedFrame()) { |
| 104 if (Func->getContext()->isVerbose(IceV_RegOrigins)) |
| 105 Str << ":"; |
| 106 Str << "[" << Func->getTarget()->getRegName( |
| 107 Func->getTarget()->getFrameOrStackReg(), IceType_i32); |
| 108 int32_t Offset = getStackOffset(); |
| 109 if (Offset) { |
| 110 if (Offset > 0) |
| 111 Str << "+"; |
| 112 Str << Offset; |
| 113 } |
| 114 Str << "]"; |
| 115 } |
77 } | 116 } |
78 | 117 |
79 void Operand::dump(const Cfg *Func) const { | 118 void ConstantRelocatable::emit(const Cfg *Func) const { |
80 Ostream &Str = Func->getContext()->getStrDump(); | 119 Ostream &Str = Func->getContext()->getStrEmit(); |
81 Str << "Operand<?>"; | 120 if (SuppressMangling) |
| 121 Str << Name; |
| 122 else |
| 123 Str << Func->getContext()->mangleName(Name); |
| 124 if (Offset) { |
| 125 if (Offset > 0) |
| 126 Str << "+"; |
| 127 Str << Offset; |
| 128 } |
82 } | 129 } |
83 | 130 |
84 void ConstantRelocatable::dump(const Cfg *Func) const { | 131 void ConstantRelocatable::dump(const Cfg *Func) const { |
85 Ostream &Str = Func->getContext()->getStrDump(); | 132 Ostream &Str = Func->getContext()->getStrDump(); |
86 Str << "@" << Name; | 133 Str << "@" << Name; |
87 if (Offset) | 134 if (Offset) |
88 Str << "+" << Offset; | 135 Str << "+" << Offset; |
89 } | 136 } |
90 | 137 |
| 138 Ostream &operator<<(Ostream &Str, const RegWeight &W) { |
| 139 if (W.getWeight() == RegWeight::Inf) |
| 140 Str << "Inf"; |
| 141 else |
| 142 Str << W.getWeight(); |
| 143 return Str; |
| 144 } |
| 145 |
91 } // end of namespace Ice | 146 } // end of namespace Ice |
OLD | NEW |