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