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