Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceOperand.cpp - High-level operand implementation -----===// |
| 2 | // |
| 3 | // The Subzero Code Generator |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
Jim Stichnoth | 92a6e5b | 2015-12-02 16:52:44 -0800 | [diff] [blame] | 11 | /// \brief Implements the Operand class and its target-independent subclasses, |
| 12 | /// primarily for the methods of the Variable class. |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 13 | /// |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 14 | //===----------------------------------------------------------------------===// |
| 15 | |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 16 | #include "IceOperand.h" |
| 17 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 18 | #include "IceCfg.h" |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 19 | #include "IceCfgNode.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 20 | #include "IceInst.h" |
John Porto | ec3f565 | 2015-08-31 15:07:09 -0700 | [diff] [blame] | 21 | #include "IceInstVarIter.h" |
John Porto | e82b560 | 2016-02-24 15:58:55 -0800 | [diff] [blame] | 22 | #include "IceMemory.h" |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 23 | #include "IceTargetLowering.h" // dumping stack/frame pointer register |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 24 | |
| 25 | namespace Ice { |
| 26 | |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame^] | 27 | void Constant::initShouldBePooled() { |
| 28 | ShouldBePooled = TargetLowering::shouldBePooled(this); |
| 29 | } |
| 30 | |
Jim Stichnoth | d2cb436 | 2014-11-20 11:24:42 -0800 | [diff] [blame] | 31 | bool operator==(const RelocatableTuple &A, const RelocatableTuple &B) { |
John Porto | 27fddcc | 2016-02-02 15:06:09 -0800 | [diff] [blame] | 32 | // A and B are the same if: |
| 33 | // (1) they have the same name; and |
| 34 | // (2) they have the same offset. |
| 35 | // |
| 36 | // (1) is trivial to check, but (2) requires some care. |
| 37 | // |
| 38 | // For (2): |
| 39 | // if A and B have known offsets (i.e., no symbolic references), then |
| 40 | // A == B -> A.Offset == B.Offset. |
| 41 | // else each element i in A.OffsetExpr[i] must be the same (or have the same |
| 42 | // value) as B.OffsetExpr[i]. |
| 43 | if (A.Name != B.Name) { |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | bool BothHaveKnownOffsets = true; |
John Porto | e82b560 | 2016-02-24 15:58:55 -0800 | [diff] [blame] | 48 | RelocOffsetT OffsetA = A.Offset; |
| 49 | RelocOffsetT OffsetB = B.Offset; |
John Porto | 27fddcc | 2016-02-02 15:06:09 -0800 | [diff] [blame] | 50 | for (SizeT i = 0; i < A.OffsetExpr.size() && BothHaveKnownOffsets; ++i) { |
| 51 | BothHaveKnownOffsets = A.OffsetExpr[i]->hasOffset(); |
| 52 | if (BothHaveKnownOffsets) { |
| 53 | OffsetA += A.OffsetExpr[i]->getOffset(); |
| 54 | } |
| 55 | } |
| 56 | for (SizeT i = 0; i < B.OffsetExpr.size() && BothHaveKnownOffsets; ++i) { |
| 57 | BothHaveKnownOffsets = B.OffsetExpr[i]->hasOffset(); |
| 58 | if (BothHaveKnownOffsets) { |
| 59 | OffsetB += B.OffsetExpr[i]->getOffset(); |
| 60 | } |
| 61 | } |
| 62 | if (BothHaveKnownOffsets) { |
| 63 | // Both have known offsets (i.e., no unresolved symbolic references), so |
| 64 | // A == B -> A.Offset == B.Offset. |
| 65 | return OffsetA == OffsetB; |
| 66 | } |
| 67 | |
| 68 | // Otherwise, A and B are not the same if their OffsetExpr's have different |
| 69 | // sizes. |
| 70 | if (A.OffsetExpr.size() != B.OffsetExpr.size()) { |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | // If the OffsetExprs' sizes are the same, then |
| 75 | // for each i in OffsetExprSize: |
| 76 | for (SizeT i = 0; i < A.OffsetExpr.size(); ++i) { |
| 77 | const auto *const RelocOffsetA = A.OffsetExpr[i]; |
| 78 | const auto *const RelocOffsetB = B.OffsetExpr[i]; |
| 79 | if (RelocOffsetA->hasOffset() && RelocOffsetB->hasOffset()) { |
| 80 | // A.OffsetExpr[i].Offset == B.OffsetExpr[i].Offset iff they are both |
| 81 | // defined; |
| 82 | if (RelocOffsetA->getOffset() != RelocOffsetB->getOffset()) { |
| 83 | return false; |
| 84 | } |
| 85 | } else if (RelocOffsetA != RelocOffsetB) { |
| 86 | // or, if they are undefined, then the RelocOffsets must be the same. |
| 87 | return false; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | return true; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Jim Stichnoth | 8aa3966 | 2016-02-10 11:20:30 -0800 | [diff] [blame] | 94 | RegNumT::BaseType RegNumT::Limit = 0; |
| 95 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 96 | bool operator<(const RegWeight &A, const RegWeight &B) { |
| 97 | return A.getWeight() < B.getWeight(); |
| 98 | } |
| 99 | bool operator<=(const RegWeight &A, const RegWeight &B) { return !(B < A); } |
| 100 | bool operator==(const RegWeight &A, const RegWeight &B) { |
| 101 | return !(B < A) && !(A < B); |
| 102 | } |
| 103 | |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 104 | void LiveRange::addSegment(InstNumberT Start, InstNumberT End) { |
Jim Stichnoth | e5b73e6 | 2014-12-15 09:58:51 -0800 | [diff] [blame] | 105 | if (!Range.empty()) { |
| 106 | // Check for merge opportunity. |
| 107 | InstNumberT CurrentEnd = Range.back().second; |
| 108 | assert(Start >= CurrentEnd); |
| 109 | if (Start == CurrentEnd) { |
| 110 | Range.back().second = End; |
| 111 | return; |
| 112 | } |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 113 | } |
| 114 | Range.push_back(RangeElementType(Start, End)); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 117 | // Returns true if this live range ends before Other's live range starts. This |
| 118 | // means that the highest instruction number in this live range is less than or |
| 119 | // equal to the lowest instruction number of the Other live range. |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 120 | bool LiveRange::endsBefore(const LiveRange &Other) const { |
| 121 | // Neither range should be empty, but let's be graceful. |
| 122 | if (Range.empty() || Other.Range.empty()) |
| 123 | return true; |
| 124 | InstNumberT MyEnd = (*Range.rbegin()).second; |
| 125 | InstNumberT OtherStart = (*Other.Range.begin()).first; |
| 126 | return MyEnd <= OtherStart; |
| 127 | } |
| 128 | |
| 129 | // Returns true if there is any overlap between the two live ranges. |
Jim Stichnoth | 037fa1d | 2014-10-07 11:09:33 -0700 | [diff] [blame] | 130 | bool LiveRange::overlaps(const LiveRange &Other, bool UseTrimmed) const { |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 131 | // Do a two-finger walk through the two sorted lists of segments. |
Jim Stichnoth | 037fa1d | 2014-10-07 11:09:33 -0700 | [diff] [blame] | 132 | auto I1 = (UseTrimmed ? TrimmedBegin : Range.begin()), |
| 133 | I2 = (UseTrimmed ? Other.TrimmedBegin : Other.Range.begin()); |
| 134 | auto E1 = Range.end(), E2 = Other.Range.end(); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 135 | while (I1 != E1 && I2 != E2) { |
| 136 | if (I1->second <= I2->first) { |
| 137 | ++I1; |
| 138 | continue; |
| 139 | } |
| 140 | if (I2->second <= I1->first) { |
| 141 | ++I2; |
| 142 | continue; |
| 143 | } |
| 144 | return true; |
| 145 | } |
| 146 | return false; |
| 147 | } |
| 148 | |
Jim Stichnoth | 037fa1d | 2014-10-07 11:09:33 -0700 | [diff] [blame] | 149 | bool LiveRange::overlapsInst(InstNumberT OtherBegin, bool UseTrimmed) const { |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 150 | bool Result = false; |
Jim Stichnoth | 037fa1d | 2014-10-07 11:09:33 -0700 | [diff] [blame] | 151 | for (auto I = (UseTrimmed ? TrimmedBegin : Range.begin()), E = Range.end(); |
| 152 | I != E; ++I) { |
| 153 | if (OtherBegin < I->first) { |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 154 | Result = false; |
| 155 | break; |
| 156 | } |
Jim Stichnoth | 037fa1d | 2014-10-07 11:09:33 -0700 | [diff] [blame] | 157 | if (OtherBegin < I->second) { |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 158 | Result = true; |
| 159 | break; |
| 160 | } |
| 161 | } |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 162 | // This is an equivalent but less inefficient implementation. It's expensive |
| 163 | // enough that we wouldn't want to run it under any build, but it could be |
| 164 | // enabled if e.g. the LiveRange implementation changes and extra testing is |
| 165 | // needed. |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 166 | if (BuildDefs::extraValidation()) { |
| 167 | LiveRange Temp; |
| 168 | Temp.addSegment(OtherBegin, OtherBegin + 1); |
| 169 | bool Validation = overlaps(Temp); |
| 170 | (void)Validation; |
| 171 | assert(Result == Validation); |
| 172 | } |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 173 | return Result; |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 176 | // Returns true if the live range contains the given instruction number. This |
| 177 | // is only used for validating the live range calculation. The IsDest argument |
| 178 | // indicates whether the Variable being tested is used in the Dest position (as |
| 179 | // opposed to a Src position). |
Jim Stichnoth | 4775255 | 2014-10-13 17:15:08 -0700 | [diff] [blame] | 180 | bool LiveRange::containsValue(InstNumberT Value, bool IsDest) const { |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 181 | for (const RangeElementType &I : Range) { |
Jim Stichnoth | 4775255 | 2014-10-13 17:15:08 -0700 | [diff] [blame] | 182 | if (I.first <= Value && |
| 183 | (Value < I.second || (!IsDest && Value == I.second))) |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 184 | return true; |
| 185 | } |
| 186 | return false; |
| 187 | } |
| 188 | |
Jim Stichnoth | 037fa1d | 2014-10-07 11:09:33 -0700 | [diff] [blame] | 189 | void LiveRange::trim(InstNumberT Lower) { |
| 190 | while (TrimmedBegin != Range.end() && TrimmedBegin->second <= Lower) |
| 191 | ++TrimmedBegin; |
| 192 | } |
| 193 | |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame^] | 194 | std::string Variable::getName(const Cfg *Func) const { |
| 195 | if (Func == nullptr) |
| 196 | return "__" + std::to_string(getIndex()); |
| 197 | return Name.toString(); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame^] | 200 | const Variable *Variable::asType(const Cfg *Func, Type Ty, |
| 201 | RegNumT NewRegNum) const { |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 202 | // Note: This returns a Variable, even if the "this" object is a subclass of |
| 203 | // Variable. |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 204 | if (!BuildDefs::dump() || getType() == Ty) |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 205 | return this; |
John Porto | e82b560 | 2016-02-24 15:58:55 -0800 | [diff] [blame] | 206 | static constexpr SizeT One = 1; |
| 207 | Variable *V = new (CfgLocalAllocator<Variable>().allocate(One)) |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame^] | 208 | Variable(Func, kVariable, Ty, Number); |
| 209 | V->Name = Name; |
Reed Kotler | 5fa0a5f | 2016-02-15 20:01:24 -0800 | [diff] [blame] | 210 | V->RegNum = NewRegNum.hasValue() ? NewRegNum : RegNum; |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 211 | V->StackOffset = StackOffset; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 212 | return V; |
| 213 | } |
| 214 | |
Andrew Scull | 11c9a32 | 2015-08-28 14:24:14 -0700 | [diff] [blame] | 215 | RegWeight Variable::getWeight(const Cfg *Func) const { |
| 216 | VariablesMetadata *VMetadata = Func->getVMetadata(); |
Andrew Scull | aa6c109 | 2015-09-03 17:50:30 -0700 | [diff] [blame] | 217 | return mustHaveReg() ? RegWeight(RegWeight::Inf) |
| 218 | : mustNotHaveReg() ? RegWeight(RegWeight::Zero) |
| 219 | : VMetadata->getUseWeight(this); |
Andrew Scull | 11c9a32 | 2015-08-28 14:24:14 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Jim Stichnoth | 877b04e | 2014-10-15 15:13:06 -0700 | [diff] [blame] | 222 | void VariableTracking::markUse(MetadataKind TrackingKind, const Inst *Instr, |
Jim Stichnoth | a3f57b9 | 2015-07-30 12:46:04 -0700 | [diff] [blame] | 223 | CfgNode *Node, bool IsImplicit) { |
Jim Stichnoth | 877b04e | 2014-10-15 15:13:06 -0700 | [diff] [blame] | 224 | (void)TrackingKind; |
Andrew Scull | 11c9a32 | 2015-08-28 14:24:14 -0700 | [diff] [blame] | 225 | |
Andrew Scull | aa6c109 | 2015-09-03 17:50:30 -0700 | [diff] [blame] | 226 | // Increment the use weight depending on the loop nest depth. The weight is |
| 227 | // exponential in the nest depth as inner loops are expected to be executed |
| 228 | // an exponentially greater number of times. |
| 229 | constexpr uint32_t LogLoopTripCountEstimate = 2; // 2^2 = 4 |
| 230 | constexpr SizeT MaxShift = sizeof(uint32_t) * CHAR_BIT - 1; |
| 231 | constexpr SizeT MaxLoopNestDepth = MaxShift / LogLoopTripCountEstimate; |
| 232 | const uint32_t LoopNestDepth = |
| 233 | std::min(Node->getLoopNestDepth(), MaxLoopNestDepth); |
| 234 | const uint32_t ThisUseWeight = uint32_t(1) |
| 235 | << LoopNestDepth * LogLoopTripCountEstimate; |
| 236 | UseWeight.addWeight(ThisUseWeight); |
Andrew Scull | 11c9a32 | 2015-08-28 14:24:14 -0700 | [diff] [blame] | 237 | |
Jim Stichnoth | 4775255 | 2014-10-13 17:15:08 -0700 | [diff] [blame] | 238 | if (MultiBlock == MBS_MultiBlock) |
| 239 | return; |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 240 | // TODO(stichnot): If the use occurs as a source operand in the first |
| 241 | // instruction of the block, and its definition is in this block's only |
| 242 | // predecessor, we might consider not marking this as a separate use. This |
| 243 | // may also apply if it's the first instruction of the block that actually |
| 244 | // uses a Variable. |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 245 | assert(Node); |
| 246 | bool MakeMulti = false; |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 247 | if (IsImplicit) |
| 248 | MakeMulti = true; |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 249 | // A phi source variable conservatively needs to be marked as multi-block, |
| 250 | // even if its definition is in the same block. This is because there can be |
| 251 | // additional control flow before branching back to this node, and the |
| 252 | // variable is live throughout those nodes. |
Jim Stichnoth | a3f57b9 | 2015-07-30 12:46:04 -0700 | [diff] [blame] | 253 | if (Instr && llvm::isa<InstPhi>(Instr)) |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 254 | MakeMulti = true; |
| 255 | |
| 256 | if (!MakeMulti) { |
| 257 | switch (MultiBlock) { |
| 258 | case MBS_Unknown: |
| 259 | MultiBlock = MBS_SingleBlock; |
| 260 | SingleUseNode = Node; |
| 261 | break; |
| 262 | case MBS_SingleBlock: |
| 263 | if (SingleUseNode != Node) |
| 264 | MakeMulti = true; |
| 265 | break; |
| 266 | case MBS_MultiBlock: |
| 267 | break; |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | if (MakeMulti) { |
| 272 | MultiBlock = MBS_MultiBlock; |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 273 | SingleUseNode = nullptr; |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 274 | } |
| 275 | } |
| 276 | |
Jim Stichnoth | 877b04e | 2014-10-15 15:13:06 -0700 | [diff] [blame] | 277 | void VariableTracking::markDef(MetadataKind TrackingKind, const Inst *Instr, |
Jim Stichnoth | a3f57b9 | 2015-07-30 12:46:04 -0700 | [diff] [blame] | 278 | CfgNode *Node) { |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 279 | // TODO(stichnot): If the definition occurs in the last instruction of the |
| 280 | // block, consider not marking this as a separate use. But be careful not to |
| 281 | // omit all uses of the variable if markDef() and markUse() both use this |
| 282 | // optimization. |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 283 | assert(Node); |
Jim Stichnoth | 48e3ae5 | 2015-10-01 13:33:35 -0700 | [diff] [blame] | 284 | // Verify that instructions are added in increasing order. |
| 285 | if (BuildDefs::asserts()) { |
| 286 | if (TrackingKind == VMK_All) { |
| 287 | const Inst *LastInstruction = |
| 288 | Definitions.empty() ? FirstOrSingleDefinition : Definitions.back(); |
| 289 | (void)LastInstruction; |
| 290 | assert(LastInstruction == nullptr || |
| 291 | Instr->getNumber() >= LastInstruction->getNumber()); |
| 292 | } |
Jim Stichnoth | 877b04e | 2014-10-15 15:13:06 -0700 | [diff] [blame] | 293 | } |
Jim Stichnoth | a3f57b9 | 2015-07-30 12:46:04 -0700 | [diff] [blame] | 294 | constexpr bool IsImplicit = false; |
| 295 | markUse(TrackingKind, Instr, Node, IsImplicit); |
Jim Stichnoth | 877b04e | 2014-10-15 15:13:06 -0700 | [diff] [blame] | 296 | if (TrackingKind == VMK_Uses) |
| 297 | return; |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 298 | if (FirstOrSingleDefinition == nullptr) |
Jim Stichnoth | 877b04e | 2014-10-15 15:13:06 -0700 | [diff] [blame] | 299 | FirstOrSingleDefinition = Instr; |
| 300 | else if (TrackingKind == VMK_All) |
| 301 | Definitions.push_back(Instr); |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 302 | switch (MultiDef) { |
| 303 | case MDS_Unknown: |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 304 | assert(SingleDefNode == nullptr); |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 305 | MultiDef = MDS_SingleDef; |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 306 | SingleDefNode = Node; |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 307 | break; |
| 308 | case MDS_SingleDef: |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 309 | assert(SingleDefNode); |
| 310 | if (Node == SingleDefNode) { |
| 311 | MultiDef = MDS_MultiDefSingleBlock; |
| 312 | } else { |
| 313 | MultiDef = MDS_MultiDefMultiBlock; |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 314 | SingleDefNode = nullptr; |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 315 | } |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 316 | break; |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 317 | case MDS_MultiDefSingleBlock: |
| 318 | assert(SingleDefNode); |
| 319 | if (Node != SingleDefNode) { |
| 320 | MultiDef = MDS_MultiDefMultiBlock; |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 321 | SingleDefNode = nullptr; |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 322 | } |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 323 | break; |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 324 | case MDS_MultiDefMultiBlock: |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 325 | assert(SingleDefNode == nullptr); |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 326 | break; |
| 327 | } |
| 328 | } |
| 329 | |
Jim Stichnoth | 48e3ae5 | 2015-10-01 13:33:35 -0700 | [diff] [blame] | 330 | const Inst *VariableTracking::getFirstDefinitionSingleBlock() const { |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 331 | switch (MultiDef) { |
| 332 | case MDS_Unknown: |
| 333 | case MDS_MultiDefMultiBlock: |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 334 | return nullptr; |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 335 | case MDS_SingleDef: |
| 336 | case MDS_MultiDefSingleBlock: |
Jim Stichnoth | 877b04e | 2014-10-15 15:13:06 -0700 | [diff] [blame] | 337 | assert(FirstOrSingleDefinition); |
| 338 | return FirstOrSingleDefinition; |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 339 | } |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 340 | return nullptr; |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | const Inst *VariableTracking::getSingleDefinition() const { |
| 344 | switch (MultiDef) { |
| 345 | case MDS_Unknown: |
| 346 | case MDS_MultiDefMultiBlock: |
| 347 | case MDS_MultiDefSingleBlock: |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 348 | return nullptr; |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 349 | case MDS_SingleDef: |
Jim Stichnoth | 877b04e | 2014-10-15 15:13:06 -0700 | [diff] [blame] | 350 | assert(FirstOrSingleDefinition); |
| 351 | return FirstOrSingleDefinition; |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 352 | } |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 353 | return nullptr; |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Jim Stichnoth | 48e3ae5 | 2015-10-01 13:33:35 -0700 | [diff] [blame] | 356 | const Inst *VariableTracking::getFirstDefinition() const { |
| 357 | switch (MultiDef) { |
| 358 | case MDS_Unknown: |
| 359 | return nullptr; |
| 360 | case MDS_MultiDefMultiBlock: |
| 361 | case MDS_SingleDef: |
| 362 | case MDS_MultiDefSingleBlock: |
| 363 | assert(FirstOrSingleDefinition); |
| 364 | return FirstOrSingleDefinition; |
| 365 | } |
| 366 | return nullptr; |
| 367 | } |
| 368 | |
Jim Stichnoth | 877b04e | 2014-10-15 15:13:06 -0700 | [diff] [blame] | 369 | void VariablesMetadata::init(MetadataKind TrackingKind) { |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 370 | TimerMarker T(TimerStack::TT_vmetadata, Func); |
Jim Stichnoth | 877b04e | 2014-10-15 15:13:06 -0700 | [diff] [blame] | 371 | Kind = TrackingKind; |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 372 | Metadata.clear(); |
| 373 | Metadata.resize(Func->getNumVariables()); |
| 374 | |
| 375 | // Mark implicit args as being used in the entry node. |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 376 | for (Variable *Var : Func->getImplicitArgs()) { |
Jim Stichnoth | a3f57b9 | 2015-07-30 12:46:04 -0700 | [diff] [blame] | 377 | constexpr Inst *NoInst = nullptr; |
| 378 | CfgNode *EntryNode = Func->getEntryNode(); |
| 379 | constexpr bool IsImplicit = true; |
| 380 | Metadata[Var->getIndex()].markUse(Kind, NoInst, EntryNode, IsImplicit); |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 383 | for (CfgNode *Node : Func->getNodes()) |
| 384 | addNode(Node); |
| 385 | } |
| 386 | |
| 387 | void VariablesMetadata::addNode(CfgNode *Node) { |
Jim Stichnoth | 48e3ae5 | 2015-10-01 13:33:35 -0700 | [diff] [blame] | 388 | if (Func->getNumVariables() > Metadata.size()) |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 389 | Metadata.resize(Func->getNumVariables()); |
| 390 | |
Jim Stichnoth | 29841e8 | 2014-12-23 12:26:24 -0800 | [diff] [blame] | 391 | for (Inst &I : Node->getPhis()) { |
| 392 | if (I.isDeleted()) |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 393 | continue; |
Jim Stichnoth | 29841e8 | 2014-12-23 12:26:24 -0800 | [diff] [blame] | 394 | if (Variable *Dest = I.getDest()) { |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 395 | SizeT DestNum = Dest->getIndex(); |
| 396 | assert(DestNum < Metadata.size()); |
Jim Stichnoth | 29841e8 | 2014-12-23 12:26:24 -0800 | [diff] [blame] | 397 | Metadata[DestNum].markDef(Kind, &I, Node); |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 398 | } |
Jim Stichnoth | 29841e8 | 2014-12-23 12:26:24 -0800 | [diff] [blame] | 399 | for (SizeT SrcNum = 0; SrcNum < I.getSrcSize(); ++SrcNum) { |
Jim Stichnoth | 54f3d51 | 2015-12-11 09:53:00 -0800 | [diff] [blame] | 400 | if (auto *Var = llvm::dyn_cast<Variable>(I.getSrc(SrcNum))) { |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 401 | SizeT VarNum = Var->getIndex(); |
| 402 | assert(VarNum < Metadata.size()); |
Jim Stichnoth | a3f57b9 | 2015-07-30 12:46:04 -0700 | [diff] [blame] | 403 | constexpr bool IsImplicit = false; |
| 404 | Metadata[VarNum].markUse(Kind, &I, Node, IsImplicit); |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 405 | } |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 406 | } |
| 407 | } |
| 408 | |
Jim Stichnoth | 29841e8 | 2014-12-23 12:26:24 -0800 | [diff] [blame] | 409 | for (Inst &I : Node->getInsts()) { |
| 410 | if (I.isDeleted()) |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 411 | continue; |
Jim Stichnoth | bb8b624 | 2014-11-04 09:10:01 -0800 | [diff] [blame] | 412 | // Note: The implicit definitions (and uses) from InstFakeKill are |
| 413 | // deliberately ignored. |
Jim Stichnoth | 29841e8 | 2014-12-23 12:26:24 -0800 | [diff] [blame] | 414 | if (Variable *Dest = I.getDest()) { |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 415 | SizeT DestNum = Dest->getIndex(); |
| 416 | assert(DestNum < Metadata.size()); |
Jim Stichnoth | 29841e8 | 2014-12-23 12:26:24 -0800 | [diff] [blame] | 417 | Metadata[DestNum].markDef(Kind, &I, Node); |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 418 | } |
John Porto | ec3f565 | 2015-08-31 15:07:09 -0700 | [diff] [blame] | 419 | FOREACH_VAR_IN_INST(Var, I) { |
| 420 | SizeT VarNum = Var->getIndex(); |
| 421 | assert(VarNum < Metadata.size()); |
| 422 | constexpr bool IsImplicit = false; |
| 423 | Metadata[VarNum].markUse(Kind, &I, Node, IsImplicit); |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | bool VariablesMetadata::isMultiDef(const Variable *Var) const { |
Jim Stichnoth | 877b04e | 2014-10-15 15:13:06 -0700 | [diff] [blame] | 429 | assert(Kind != VMK_Uses); |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 430 | if (Var->getIsArg()) |
| 431 | return false; |
| 432 | if (!isTracked(Var)) |
| 433 | return true; // conservative answer |
| 434 | SizeT VarNum = Var->getIndex(); |
| 435 | // Conservatively return true if the state is unknown. |
| 436 | return Metadata[VarNum].getMultiDef() != VariableTracking::MDS_SingleDef; |
| 437 | } |
| 438 | |
| 439 | bool VariablesMetadata::isMultiBlock(const Variable *Var) const { |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 440 | if (Var->getIsArg()) |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 441 | return true; |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 442 | if (!isTracked(Var)) |
| 443 | return true; // conservative answer |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 444 | SizeT VarNum = Var->getIndex(); |
| 445 | // Conservatively return true if the state is unknown. |
| 446 | return Metadata[VarNum].getMultiBlock() != VariableTracking::MBS_SingleBlock; |
| 447 | } |
| 448 | |
Jim Stichnoth | 48e3ae5 | 2015-10-01 13:33:35 -0700 | [diff] [blame] | 449 | const Inst * |
| 450 | VariablesMetadata::getFirstDefinitionSingleBlock(const Variable *Var) const { |
Jim Stichnoth | 877b04e | 2014-10-15 15:13:06 -0700 | [diff] [blame] | 451 | assert(Kind != VMK_Uses); |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 452 | if (!isTracked(Var)) |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 453 | return nullptr; // conservative answer |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 454 | SizeT VarNum = Var->getIndex(); |
Jim Stichnoth | 48e3ae5 | 2015-10-01 13:33:35 -0700 | [diff] [blame] | 455 | return Metadata[VarNum].getFirstDefinitionSingleBlock(); |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | const Inst *VariablesMetadata::getSingleDefinition(const Variable *Var) const { |
Jim Stichnoth | 877b04e | 2014-10-15 15:13:06 -0700 | [diff] [blame] | 459 | assert(Kind != VMK_Uses); |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 460 | if (!isTracked(Var)) |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 461 | return nullptr; // conservative answer |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 462 | SizeT VarNum = Var->getIndex(); |
| 463 | return Metadata[VarNum].getSingleDefinition(); |
| 464 | } |
| 465 | |
Jim Stichnoth | 48e3ae5 | 2015-10-01 13:33:35 -0700 | [diff] [blame] | 466 | const Inst *VariablesMetadata::getFirstDefinition(const Variable *Var) const { |
| 467 | assert(Kind != VMK_Uses); |
| 468 | if (!isTracked(Var)) |
| 469 | return nullptr; // conservative answer |
| 470 | SizeT VarNum = Var->getIndex(); |
| 471 | return Metadata[VarNum].getFirstDefinition(); |
| 472 | } |
| 473 | |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 474 | const InstDefList & |
Jim Stichnoth | 877b04e | 2014-10-15 15:13:06 -0700 | [diff] [blame] | 475 | VariablesMetadata::getLatterDefinitions(const Variable *Var) const { |
| 476 | assert(Kind == VMK_All); |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 477 | if (!isTracked(Var)) |
| 478 | return NoDefinitions; |
| 479 | SizeT VarNum = Var->getIndex(); |
Jim Stichnoth | 877b04e | 2014-10-15 15:13:06 -0700 | [diff] [blame] | 480 | return Metadata[VarNum].getLatterDefinitions(); |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Jim Stichnoth | a3f57b9 | 2015-07-30 12:46:04 -0700 | [diff] [blame] | 483 | CfgNode *VariablesMetadata::getLocalUseNode(const Variable *Var) const { |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 484 | if (!isTracked(Var)) |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 485 | return nullptr; // conservative answer |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 486 | SizeT VarNum = Var->getIndex(); |
| 487 | return Metadata[VarNum].getNode(); |
| 488 | } |
| 489 | |
Andrew Scull | aa6c109 | 2015-09-03 17:50:30 -0700 | [diff] [blame] | 490 | RegWeight VariablesMetadata::getUseWeight(const Variable *Var) const { |
Andrew Scull | 11c9a32 | 2015-08-28 14:24:14 -0700 | [diff] [blame] | 491 | if (!isTracked(Var)) |
Andrew Scull | aa6c109 | 2015-09-03 17:50:30 -0700 | [diff] [blame] | 492 | return RegWeight(1); // conservative answer |
Andrew Scull | 11c9a32 | 2015-08-28 14:24:14 -0700 | [diff] [blame] | 493 | SizeT VarNum = Var->getIndex(); |
| 494 | return Metadata[VarNum].getUseWeight(); |
| 495 | } |
| 496 | |
Jim Stichnoth | ad40353 | 2014-09-25 12:44:17 -0700 | [diff] [blame] | 497 | const InstDefList VariablesMetadata::NoDefinitions; |
| 498 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 499 | // ======================== dump routines ======================== // |
| 500 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 501 | void Variable::emit(const Cfg *Func) const { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 502 | if (BuildDefs::dump()) |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 503 | Func->getTarget()->emitVariable(this); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 504 | } |
| 505 | |
Jim Stichnoth | 2e8bfbb | 2014-09-16 10:16:00 -0700 | [diff] [blame] | 506 | void Variable::dump(const Cfg *Func, Ostream &Str) const { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 507 | if (!BuildDefs::dump()) |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 508 | return; |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 509 | if (Func == nullptr) { |
Jim Stichnoth | 9a04c07 | 2014-12-11 15:51:42 -0800 | [diff] [blame] | 510 | Str << "%" << getName(Func); |
Jim Stichnoth | 2e8bfbb | 2014-09-16 10:16:00 -0700 | [diff] [blame] | 511 | return; |
| 512 | } |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 513 | if (Func->isVerbose(IceV_RegOrigins) || |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 514 | (!hasReg() && !Func->getTarget()->hasComputedFrame())) |
Jim Stichnoth | 9a04c07 | 2014-12-11 15:51:42 -0800 | [diff] [blame] | 515 | Str << "%" << getName(Func); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 516 | if (hasReg()) { |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 517 | if (Func->isVerbose(IceV_RegOrigins)) |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 518 | Str << ":"; |
| 519 | Str << Func->getTarget()->getRegName(RegNum, getType()); |
| 520 | } else if (Func->getTarget()->hasComputedFrame()) { |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 521 | if (Func->isVerbose(IceV_RegOrigins)) |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 522 | Str << ":"; |
Jim Stichnoth | 8aa3966 | 2016-02-10 11:20:30 -0800 | [diff] [blame] | 523 | const auto BaseRegisterNumber = |
| 524 | hasReg() ? getBaseRegNum() : Func->getTarget()->getFrameOrStackReg(); |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame] | 525 | Str << "[" |
Jan Voung | 28068ad | 2015-07-31 12:58:46 -0700 | [diff] [blame] | 526 | << Func->getTarget()->getRegName(BaseRegisterNumber, IceType_i32); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 527 | int32_t Offset = getStackOffset(); |
| 528 | if (Offset) { |
| 529 | if (Offset > 0) |
| 530 | Str << "+"; |
| 531 | Str << Offset; |
| 532 | } |
| 533 | Str << "]"; |
| 534 | } |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Jan Voung | 76bb0be | 2015-05-14 09:26:19 -0700 | [diff] [blame] | 537 | template <> void ConstantInteger32::emit(TargetLowering *Target) const { |
| 538 | Target->emit(this); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 539 | } |
| 540 | |
Jan Voung | 76bb0be | 2015-05-14 09:26:19 -0700 | [diff] [blame] | 541 | template <> void ConstantInteger64::emit(TargetLowering *Target) const { |
| 542 | Target->emit(this); |
| 543 | } |
| 544 | |
| 545 | template <> void ConstantFloat::emit(TargetLowering *Target) const { |
| 546 | Target->emit(this); |
| 547 | } |
| 548 | |
| 549 | template <> void ConstantDouble::emit(TargetLowering *Target) const { |
| 550 | Target->emit(this); |
| 551 | } |
| 552 | |
| 553 | void ConstantRelocatable::emit(TargetLowering *Target) const { |
| 554 | Target->emit(this); |
| 555 | } |
| 556 | |
Jim Stichnoth | 8ff4b28 | 2016-01-04 15:39:06 -0800 | [diff] [blame] | 557 | void ConstantRelocatable::emitWithoutPrefix(const TargetLowering *Target, |
| 558 | const char *Suffix) const { |
| 559 | Target->emitWithoutPrefix(this, Suffix); |
Jim Stichnoth | bca2f65 | 2014-11-01 10:13:54 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Jim Stichnoth | 98ba006 | 2016-03-07 09:26:22 -0800 | [diff] [blame] | 562 | void ConstantRelocatable::dump(const Cfg *, Ostream &Str) const { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 563 | if (!BuildDefs::dump()) |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 564 | return; |
John Porto | dc61925 | 2016-02-10 15:57:16 -0800 | [diff] [blame] | 565 | if (!EmitString.empty()) { |
| 566 | Str << EmitString; |
| 567 | return; |
| 568 | } |
Jim Stichnoth | 98ba006 | 2016-03-07 09:26:22 -0800 | [diff] [blame] | 569 | Str << "@" << Name; |
John Porto | 27fddcc | 2016-02-02 15:06:09 -0800 | [diff] [blame] | 570 | const RelocOffsetT Offset = getOffset(); |
| 571 | if (Offset) { |
| 572 | if (Offset >= 0) { |
| 573 | Str << "+"; |
| 574 | } |
| 575 | Str << Offset; |
| 576 | } |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 577 | } |
| 578 | |
Jan Voung | 76bb0be | 2015-05-14 09:26:19 -0700 | [diff] [blame] | 579 | void ConstantUndef::emit(TargetLowering *Target) const { Target->emit(this); } |
| 580 | |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 581 | void LiveRange::dump(Ostream &Str) const { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 582 | if (!BuildDefs::dump()) |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 583 | return; |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 584 | bool First = true; |
| 585 | for (const RangeElementType &I : Range) { |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 586 | if (!First) |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 587 | Str << ", "; |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 588 | First = false; |
| 589 | Str << "[" << I.first << ":" << I.second << ")"; |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 590 | } |
| 591 | } |
| 592 | |
| 593 | Ostream &operator<<(Ostream &Str, const LiveRange &L) { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 594 | if (!BuildDefs::dump()) |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 595 | return Str; |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 596 | L.dump(Str); |
| 597 | return Str; |
| 598 | } |
| 599 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 600 | Ostream &operator<<(Ostream &Str, const RegWeight &W) { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 601 | if (!BuildDefs::dump()) |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 602 | return Str; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 603 | if (W.getWeight() == RegWeight::Inf) |
| 604 | Str << "Inf"; |
| 605 | else |
| 606 | Str << W.getWeight(); |
| 607 | return Str; |
| 608 | } |
| 609 | |
Qining Lu | 253dc8a | 2015-06-22 10:10:23 -0700 | [diff] [blame] | 610 | // =========== Immediate Randomization and Pooling routines ============== |
| 611 | // Specialization of the template member function for ConstantInteger32 |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 612 | // TODO(stichnot): try to move this specialization into a target-specific file. |
Jim Stichnoth | 467ffe5 | 2016-03-29 15:01:06 -0700 | [diff] [blame^] | 613 | template <> bool ConstantInteger32::shouldBeRandomizedOrPooled() const { |
| 614 | uint32_t Threshold = |
| 615 | GlobalContext::getFlags().getRandomizeAndPoolImmediatesThreshold(); |
| 616 | if (GlobalContext::getFlags().getRandomizeAndPoolImmediatesOption() == |
| 617 | RPI_None) |
Qining Lu | 253dc8a | 2015-06-22 10:10:23 -0700 | [diff] [blame] | 618 | return false; |
| 619 | if (getType() != IceType_i32 && getType() != IceType_i16 && |
| 620 | getType() != IceType_i8) |
| 621 | return false; |
| 622 | // The Following checks if the signed representation of Value is between |
| 623 | // -Threshold/2 and +Threshold/2 |
| 624 | bool largerThanThreshold = Threshold / 2 + Value >= Threshold; |
| 625 | return largerThanThreshold; |
| 626 | } |
| 627 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 628 | } // end of namespace Ice |