Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1 | //===-- SelectionDAG.cpp - Implement the SelectionDAG data structures -----===// |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 7 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 78ec311 | 2003-08-11 14:57:33 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 10 | // This implements the SelectionDAG class. |
Chris Lattner | 78ec311 | 2003-08-11 14:57:33 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Bill Wendling | e36025e | 2009-12-21 19:34:59 +0000 | [diff] [blame] | 13 | |
Chris Lattner | 78ec311 | 2003-08-11 14:57:33 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/SelectionDAG.h" |
Evan Cheng | a8efe28 | 2010-03-14 19:56:39 +0000 | [diff] [blame] | 15 | #include "SDNodeDbgValue.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/SetVector.h" |
| 17 | #include "llvm/ADT/SmallPtrSet.h" |
| 18 | #include "llvm/ADT/SmallSet.h" |
| 19 | #include "llvm/ADT/SmallVector.h" |
| 20 | #include "llvm/ADT/StringExtras.h" |
Chandler Carruth | be04929 | 2013-01-07 03:08:10 +0000 | [diff] [blame] | 21 | #include "llvm/Analysis/TargetTransformInfo.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 22 | #include "llvm/Analysis/ValueTracking.h" |
| 23 | #include "llvm/Assembly/Writer.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 25 | #include "llvm/CodeGen/MachineConstantPool.h" |
| 26 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 27 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Bill Wendling | 0bcbd1d | 2012-06-28 00:05:13 +0000 | [diff] [blame] | 28 | #include "llvm/DebugInfo.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 29 | #include "llvm/IR/CallingConv.h" |
| 30 | #include "llvm/IR/Constants.h" |
| 31 | #include "llvm/IR/DataLayout.h" |
| 32 | #include "llvm/IR/DerivedTypes.h" |
| 33 | #include "llvm/IR/Function.h" |
| 34 | #include "llvm/IR/GlobalAlias.h" |
| 35 | #include "llvm/IR/GlobalVariable.h" |
| 36 | #include "llvm/IR/Intrinsics.h" |
Bill Wendling | 6f287b2 | 2008-09-30 21:22:07 +0000 | [diff] [blame] | 37 | #include "llvm/Support/CommandLine.h" |
David Greene | 55d146e | 2010-01-05 01:24:36 +0000 | [diff] [blame] | 38 | #include "llvm/Support/Debug.h" |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 39 | #include "llvm/Support/ErrorHandling.h" |
Owen Anderson | b445908 | 2009-06-25 17:09:00 +0000 | [diff] [blame] | 40 | #include "llvm/Support/ManagedStatic.h" |
Chris Lattner | 944fac7 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 41 | #include "llvm/Support/MathExtras.h" |
Michael J. Spencer | 1f6efa3 | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 42 | #include "llvm/Support/Mutex.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 43 | #include "llvm/Support/raw_ostream.h" |
| 44 | #include "llvm/Target/TargetInstrInfo.h" |
| 45 | #include "llvm/Target/TargetIntrinsicInfo.h" |
| 46 | #include "llvm/Target/TargetLowering.h" |
| 47 | #include "llvm/Target/TargetMachine.h" |
| 48 | #include "llvm/Target/TargetOptions.h" |
| 49 | #include "llvm/Target/TargetRegisterInfo.h" |
| 50 | #include "llvm/Target/TargetSelectionDAGInfo.h" |
Jeff Cohen | fd161e9 | 2005-01-09 20:41:56 +0000 | [diff] [blame] | 51 | #include <algorithm> |
Jeff Cohen | 97af751 | 2006-12-02 02:22:01 +0000 | [diff] [blame] | 52 | #include <cmath> |
Chris Lattner | e25738c | 2004-06-02 04:28:06 +0000 | [diff] [blame] | 53 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 54 | |
Chris Lattner | 0b3e525 | 2006-08-15 19:11:05 +0000 | [diff] [blame] | 55 | /// makeVTList - Return an instance of the SDVTList struct initialized with the |
| 56 | /// specified members. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 57 | static SDVTList makeVTList(const EVT *VTs, unsigned NumVTs) { |
Chris Lattner | 0b3e525 | 2006-08-15 19:11:05 +0000 | [diff] [blame] | 58 | SDVTList Res = {VTs, NumVTs}; |
| 59 | return Res; |
| 60 | } |
| 61 | |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 62 | // Default null implementations of the callbacks. |
| 63 | void SelectionDAG::DAGUpdateListener::NodeDeleted(SDNode*, SDNode*) {} |
| 64 | void SelectionDAG::DAGUpdateListener::NodeUpdated(SDNode*) {} |
Chris Lattner | f8dc061 | 2008-02-03 06:49:24 +0000 | [diff] [blame] | 65 | |
Jim Laskey | 58b968b | 2005-08-17 20:08:02 +0000 | [diff] [blame] | 66 | //===----------------------------------------------------------------------===// |
| 67 | // ConstantFPSDNode Class |
| 68 | //===----------------------------------------------------------------------===// |
| 69 | |
| 70 | /// isExactlyValue - We don't rely on operator== working on double values, as |
| 71 | /// it returns true for things that are clearly not equal, like -0.0 and 0.0. |
| 72 | /// As such, this method can be used to do an exact bit-for-bit comparison of |
| 73 | /// two floating point values. |
Dale Johannesen | e6c1742 | 2007-08-26 01:18:27 +0000 | [diff] [blame] | 74 | bool ConstantFPSDNode::isExactlyValue(const APFloat& V) const { |
Dan Gohman | 4fbd796 | 2008-09-12 18:08:03 +0000 | [diff] [blame] | 75 | return getValueAPF().bitwiseIsEqual(V); |
Jim Laskey | 58b968b | 2005-08-17 20:08:02 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 78 | bool ConstantFPSDNode::isValueValidForType(EVT VT, |
Dale Johannesen | f04afdb | 2007-08-30 00:23:21 +0000 | [diff] [blame] | 79 | const APFloat& Val) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 80 | assert(VT.isFloatingPoint() && "Can only convert between FP types"); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 81 | |
Dale Johannesen | f04afdb | 2007-08-30 00:23:21 +0000 | [diff] [blame] | 82 | // convert modifies in place, so make a copy. |
| 83 | APFloat Val2 = APFloat(Val); |
Dale Johannesen | 23a9855 | 2008-10-09 23:00:39 +0000 | [diff] [blame] | 84 | bool losesInfo; |
Tim Northover | 0a29cb0 | 2013-01-22 09:46:31 +0000 | [diff] [blame] | 85 | (void) Val2.convert(SelectionDAG::EVTToAPFloatSemantics(VT), |
| 86 | APFloat::rmNearestTiesToEven, |
Dale Johannesen | 23a9855 | 2008-10-09 23:00:39 +0000 | [diff] [blame] | 87 | &losesInfo); |
| 88 | return !losesInfo; |
Dale Johannesen | f04afdb | 2007-08-30 00:23:21 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Jim Laskey | 58b968b | 2005-08-17 20:08:02 +0000 | [diff] [blame] | 91 | //===----------------------------------------------------------------------===// |
Chris Lattner | 61d4399 | 2006-03-25 22:57:01 +0000 | [diff] [blame] | 92 | // ISD Namespace |
Jim Laskey | 58b968b | 2005-08-17 20:08:02 +0000 | [diff] [blame] | 93 | //===----------------------------------------------------------------------===// |
Chris Lattner | 5cdcc58 | 2005-01-09 20:52:51 +0000 | [diff] [blame] | 94 | |
Evan Cheng | a8df166 | 2006-03-27 06:58:47 +0000 | [diff] [blame] | 95 | /// isBuildVectorAllOnes - Return true if the specified node is a |
Chris Lattner | 61d4399 | 2006-03-25 22:57:01 +0000 | [diff] [blame] | 96 | /// BUILD_VECTOR where all of the elements are ~0 or undef. |
Evan Cheng | a8df166 | 2006-03-27 06:58:47 +0000 | [diff] [blame] | 97 | bool ISD::isBuildVectorAllOnes(const SDNode *N) { |
Chris Lattner | 547a16f | 2006-04-15 23:38:00 +0000 | [diff] [blame] | 98 | // Look through a bit convert. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 99 | if (N->getOpcode() == ISD::BITCAST) |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 100 | N = N->getOperand(0).getNode(); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 101 | |
Evan Cheng | a8df166 | 2006-03-27 06:58:47 +0000 | [diff] [blame] | 102 | if (N->getOpcode() != ISD::BUILD_VECTOR) return false; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 103 | |
Chris Lattner | 61d4399 | 2006-03-25 22:57:01 +0000 | [diff] [blame] | 104 | unsigned i = 0, e = N->getNumOperands(); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 105 | |
Chris Lattner | 61d4399 | 2006-03-25 22:57:01 +0000 | [diff] [blame] | 106 | // Skip over all of the undef values. |
| 107 | while (i != e && N->getOperand(i).getOpcode() == ISD::UNDEF) |
| 108 | ++i; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 109 | |
Chris Lattner | 61d4399 | 2006-03-25 22:57:01 +0000 | [diff] [blame] | 110 | // Do not accept an all-undef vector. |
| 111 | if (i == e) return false; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 112 | |
Chris Lattner | 61d4399 | 2006-03-25 22:57:01 +0000 | [diff] [blame] | 113 | // Do not accept build_vectors that aren't all constants or which have non-~0 |
Jim Grosbach | 331ff3b | 2012-03-21 17:48:04 +0000 | [diff] [blame] | 114 | // elements. We have to be a bit careful here, as the type of the constant |
| 115 | // may not be the same as the type of the vector elements due to type |
| 116 | // legalization (the elements are promoted to a legal type for the target and |
| 117 | // a vector of a type may be legal when the base element type is not). |
| 118 | // We only want to check enough bits to cover the vector elements, because |
| 119 | // we care if the resultant vector is all ones, not whether the individual |
| 120 | // constants are. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 121 | SDValue NotZero = N->getOperand(i); |
Jim Grosbach | 331ff3b | 2012-03-21 17:48:04 +0000 | [diff] [blame] | 122 | unsigned EltSize = N->getValueType(0).getVectorElementType().getSizeInBits(); |
Jakub Staszak | 554c676 | 2012-09-30 21:24:57 +0000 | [diff] [blame] | 123 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(NotZero)) { |
| 124 | if (CN->getAPIntValue().countTrailingOnes() < EltSize) |
Evan Cheng | a8df166 | 2006-03-27 06:58:47 +0000 | [diff] [blame] | 125 | return false; |
Jakub Staszak | 554c676 | 2012-09-30 21:24:57 +0000 | [diff] [blame] | 126 | } else if (ConstantFPSDNode *CFPN = dyn_cast<ConstantFPSDNode>(NotZero)) { |
| 127 | if (CFPN->getValueAPF().bitcastToAPInt().countTrailingOnes() < EltSize) |
Dan Gohman | 6c23150 | 2008-02-29 01:47:35 +0000 | [diff] [blame] | 128 | return false; |
Evan Cheng | a8df166 | 2006-03-27 06:58:47 +0000 | [diff] [blame] | 129 | } else |
Chris Lattner | 61d4399 | 2006-03-25 22:57:01 +0000 | [diff] [blame] | 130 | return false; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 131 | |
Chris Lattner | 61d4399 | 2006-03-25 22:57:01 +0000 | [diff] [blame] | 132 | // Okay, we have at least one ~0 value, check to see if the rest match or are |
Jim Grosbach | 331ff3b | 2012-03-21 17:48:04 +0000 | [diff] [blame] | 133 | // undefs. Even with the above element type twiddling, this should be OK, as |
| 134 | // the same type legalization should have applied to all the elements. |
Chris Lattner | 61d4399 | 2006-03-25 22:57:01 +0000 | [diff] [blame] | 135 | for (++i; i != e; ++i) |
| 136 | if (N->getOperand(i) != NotZero && |
| 137 | N->getOperand(i).getOpcode() != ISD::UNDEF) |
| 138 | return false; |
| 139 | return true; |
| 140 | } |
| 141 | |
| 142 | |
Evan Cheng | 4a14784 | 2006-03-26 09:50:58 +0000 | [diff] [blame] | 143 | /// isBuildVectorAllZeros - Return true if the specified node is a |
| 144 | /// BUILD_VECTOR where all of the elements are 0 or undef. |
| 145 | bool ISD::isBuildVectorAllZeros(const SDNode *N) { |
Chris Lattner | 547a16f | 2006-04-15 23:38:00 +0000 | [diff] [blame] | 146 | // Look through a bit convert. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 147 | if (N->getOpcode() == ISD::BITCAST) |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 148 | N = N->getOperand(0).getNode(); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 149 | |
Evan Cheng | 4a14784 | 2006-03-26 09:50:58 +0000 | [diff] [blame] | 150 | if (N->getOpcode() != ISD::BUILD_VECTOR) return false; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 151 | |
Evan Cheng | a8df166 | 2006-03-27 06:58:47 +0000 | [diff] [blame] | 152 | unsigned i = 0, e = N->getNumOperands(); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 153 | |
Evan Cheng | a8df166 | 2006-03-27 06:58:47 +0000 | [diff] [blame] | 154 | // Skip over all of the undef values. |
| 155 | while (i != e && N->getOperand(i).getOpcode() == ISD::UNDEF) |
| 156 | ++i; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 157 | |
Evan Cheng | a8df166 | 2006-03-27 06:58:47 +0000 | [diff] [blame] | 158 | // Do not accept an all-undef vector. |
| 159 | if (i == e) return false; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 160 | |
Dan Gohman | 68f32cb | 2009-06-04 16:49:15 +0000 | [diff] [blame] | 161 | // Do not accept build_vectors that aren't all constants or which have non-0 |
Evan Cheng | a8df166 | 2006-03-27 06:58:47 +0000 | [diff] [blame] | 162 | // elements. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 163 | SDValue Zero = N->getOperand(i); |
Jakub Staszak | 554c676 | 2012-09-30 21:24:57 +0000 | [diff] [blame] | 164 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Zero)) { |
| 165 | if (!CN->isNullValue()) |
Evan Cheng | a8df166 | 2006-03-27 06:58:47 +0000 | [diff] [blame] | 166 | return false; |
Jakub Staszak | 554c676 | 2012-09-30 21:24:57 +0000 | [diff] [blame] | 167 | } else if (ConstantFPSDNode *CFPN = dyn_cast<ConstantFPSDNode>(Zero)) { |
| 168 | if (!CFPN->getValueAPF().isPosZero()) |
Evan Cheng | a8df166 | 2006-03-27 06:58:47 +0000 | [diff] [blame] | 169 | return false; |
| 170 | } else |
| 171 | return false; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 172 | |
Dan Gohman | 68f32cb | 2009-06-04 16:49:15 +0000 | [diff] [blame] | 173 | // Okay, we have at least one 0 value, check to see if the rest match or are |
Evan Cheng | a8df166 | 2006-03-27 06:58:47 +0000 | [diff] [blame] | 174 | // undefs. |
| 175 | for (++i; i != e; ++i) |
| 176 | if (N->getOperand(i) != Zero && |
| 177 | N->getOperand(i).getOpcode() != ISD::UNDEF) |
| 178 | return false; |
| 179 | return true; |
Evan Cheng | 4a14784 | 2006-03-26 09:50:58 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Evan Cheng | efec751 | 2008-02-18 23:04:32 +0000 | [diff] [blame] | 182 | /// isScalarToVector - Return true if the specified node is a |
| 183 | /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low |
| 184 | /// element is not an undef. |
| 185 | bool ISD::isScalarToVector(const SDNode *N) { |
| 186 | if (N->getOpcode() == ISD::SCALAR_TO_VECTOR) |
| 187 | return true; |
| 188 | |
| 189 | if (N->getOpcode() != ISD::BUILD_VECTOR) |
| 190 | return false; |
| 191 | if (N->getOperand(0).getOpcode() == ISD::UNDEF) |
| 192 | return false; |
| 193 | unsigned NumElems = N->getNumOperands(); |
Mon P Wang | cab98e3 | 2010-11-19 19:08:12 +0000 | [diff] [blame] | 194 | if (NumElems == 1) |
| 195 | return false; |
Evan Cheng | efec751 | 2008-02-18 23:04:32 +0000 | [diff] [blame] | 196 | for (unsigned i = 1; i < NumElems; ++i) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 197 | SDValue V = N->getOperand(i); |
Evan Cheng | efec751 | 2008-02-18 23:04:32 +0000 | [diff] [blame] | 198 | if (V.getOpcode() != ISD::UNDEF) |
| 199 | return false; |
| 200 | } |
| 201 | return true; |
| 202 | } |
| 203 | |
Nadav Rotem | b87bdac | 2012-07-15 08:38:23 +0000 | [diff] [blame] | 204 | /// allOperandsUndef - Return true if the node has at least one operand |
| 205 | /// and all operands of the specified node are ISD::UNDEF. |
| 206 | bool ISD::allOperandsUndef(const SDNode *N) { |
| 207 | // Return false if the node has no operands. |
| 208 | // This is "logically inconsistent" with the definition of "all" but |
| 209 | // is probably the desired behavior. |
| 210 | if (N->getNumOperands() == 0) |
| 211 | return false; |
| 212 | |
| 213 | for (unsigned i = 0, e = N->getNumOperands(); i != e ; ++i) |
| 214 | if (N->getOperand(i).getOpcode() != ISD::UNDEF) |
| 215 | return false; |
| 216 | |
| 217 | return true; |
| 218 | } |
| 219 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 220 | /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X) |
| 221 | /// when given the operation for (X op Y). |
| 222 | ISD::CondCode ISD::getSetCCSwappedOperands(ISD::CondCode Operation) { |
| 223 | // To perform this operation, we just need to swap the L and G bits of the |
| 224 | // operation. |
| 225 | unsigned OldL = (Operation >> 2) & 1; |
| 226 | unsigned OldG = (Operation >> 1) & 1; |
| 227 | return ISD::CondCode((Operation & ~6) | // Keep the N, U, E bits |
| 228 | (OldL << 1) | // New G bit |
Bill Wendling | a1dc602 | 2008-10-19 20:51:12 +0000 | [diff] [blame] | 229 | (OldG << 2)); // New L bit. |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | /// getSetCCInverse - Return the operation corresponding to !(X op Y), where |
| 233 | /// 'op' is a valid SetCC operation. |
| 234 | ISD::CondCode ISD::getSetCCInverse(ISD::CondCode Op, bool isInteger) { |
| 235 | unsigned Operation = Op; |
| 236 | if (isInteger) |
| 237 | Operation ^= 7; // Flip L, G, E bits, but not U. |
| 238 | else |
| 239 | Operation ^= 15; // Flip all of the condition bits. |
Bill Wendling | a1dc602 | 2008-10-19 20:51:12 +0000 | [diff] [blame] | 240 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 241 | if (Operation > ISD::SETTRUE2) |
Bill Wendling | a1dc602 | 2008-10-19 20:51:12 +0000 | [diff] [blame] | 242 | Operation &= ~8; // Don't let N and U bits get set. |
| 243 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 244 | return ISD::CondCode(Operation); |
| 245 | } |
| 246 | |
| 247 | |
| 248 | /// isSignedOp - For an integer comparison, return 1 if the comparison is a |
| 249 | /// signed operation and 2 if the result is an unsigned comparison. Return zero |
| 250 | /// if the operation does not depend on the sign of the input (setne and seteq). |
| 251 | static int isSignedOp(ISD::CondCode Opcode) { |
| 252 | switch (Opcode) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 253 | default: llvm_unreachable("Illegal integer setcc operation!"); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 254 | case ISD::SETEQ: |
| 255 | case ISD::SETNE: return 0; |
| 256 | case ISD::SETLT: |
| 257 | case ISD::SETLE: |
| 258 | case ISD::SETGT: |
| 259 | case ISD::SETGE: return 1; |
| 260 | case ISD::SETULT: |
| 261 | case ISD::SETULE: |
| 262 | case ISD::SETUGT: |
| 263 | case ISD::SETUGE: return 2; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | /// getSetCCOrOperation - Return the result of a logical OR between different |
| 268 | /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This function |
| 269 | /// returns SETCC_INVALID if it is not possible to represent the resultant |
| 270 | /// comparison. |
| 271 | ISD::CondCode ISD::getSetCCOrOperation(ISD::CondCode Op1, ISD::CondCode Op2, |
| 272 | bool isInteger) { |
| 273 | if (isInteger && (isSignedOp(Op1) | isSignedOp(Op2)) == 3) |
| 274 | // Cannot fold a signed integer setcc with an unsigned integer setcc. |
| 275 | return ISD::SETCC_INVALID; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 276 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 277 | unsigned Op = Op1 | Op2; // Combine all of the condition bits. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 278 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 279 | // If the N and U bits get set then the resultant comparison DOES suddenly |
| 280 | // care about orderedness, and is true when ordered. |
| 281 | if (Op > ISD::SETTRUE2) |
Chris Lattner | e41102b | 2006-05-12 17:03:46 +0000 | [diff] [blame] | 282 | Op &= ~16; // Clear the U bit if the N bit is set. |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 283 | |
Chris Lattner | e41102b | 2006-05-12 17:03:46 +0000 | [diff] [blame] | 284 | // Canonicalize illegal integer setcc's. |
| 285 | if (isInteger && Op == ISD::SETUNE) // e.g. SETUGT | SETULT |
| 286 | Op = ISD::SETNE; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 287 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 288 | return ISD::CondCode(Op); |
| 289 | } |
| 290 | |
| 291 | /// getSetCCAndOperation - Return the result of a logical AND between different |
| 292 | /// comparisons of identical values: ((X op1 Y) & (X op2 Y)). This |
| 293 | /// function returns zero if it is not possible to represent the resultant |
| 294 | /// comparison. |
| 295 | ISD::CondCode ISD::getSetCCAndOperation(ISD::CondCode Op1, ISD::CondCode Op2, |
| 296 | bool isInteger) { |
| 297 | if (isInteger && (isSignedOp(Op1) | isSignedOp(Op2)) == 3) |
| 298 | // Cannot fold a signed setcc with an unsigned setcc. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 299 | return ISD::SETCC_INVALID; |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 300 | |
| 301 | // Combine all of the condition bits. |
Chris Lattner | a83385f | 2006-04-27 05:01:07 +0000 | [diff] [blame] | 302 | ISD::CondCode Result = ISD::CondCode(Op1 & Op2); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 303 | |
Chris Lattner | a83385f | 2006-04-27 05:01:07 +0000 | [diff] [blame] | 304 | // Canonicalize illegal integer setcc's. |
| 305 | if (isInteger) { |
| 306 | switch (Result) { |
| 307 | default: break; |
Chris Lattner | 883a52d | 2006-06-28 18:29:47 +0000 | [diff] [blame] | 308 | case ISD::SETUO : Result = ISD::SETFALSE; break; // SETUGT & SETULT |
Dan Gohman | d64a78c | 2008-05-14 18:17:09 +0000 | [diff] [blame] | 309 | case ISD::SETOEQ: // SETEQ & SETU[LG]E |
Chris Lattner | 883a52d | 2006-06-28 18:29:47 +0000 | [diff] [blame] | 310 | case ISD::SETUEQ: Result = ISD::SETEQ ; break; // SETUGE & SETULE |
| 311 | case ISD::SETOLT: Result = ISD::SETULT ; break; // SETULT & SETNE |
| 312 | case ISD::SETOGT: Result = ISD::SETUGT ; break; // SETUGT & SETNE |
Chris Lattner | a83385f | 2006-04-27 05:01:07 +0000 | [diff] [blame] | 313 | } |
| 314 | } |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 315 | |
Chris Lattner | a83385f | 2006-04-27 05:01:07 +0000 | [diff] [blame] | 316 | return Result; |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 317 | } |
| 318 | |
Jim Laskey | 58b968b | 2005-08-17 20:08:02 +0000 | [diff] [blame] | 319 | //===----------------------------------------------------------------------===// |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 320 | // SDNode Profile Support |
| 321 | //===----------------------------------------------------------------------===// |
| 322 | |
Jim Laskey | def69b9 | 2006-10-27 23:52:51 +0000 | [diff] [blame] | 323 | /// AddNodeIDOpcode - Add the node opcode to the NodeID data. |
| 324 | /// |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 325 | static void AddNodeIDOpcode(FoldingSetNodeID &ID, unsigned OpC) { |
| 326 | ID.AddInteger(OpC); |
| 327 | } |
| 328 | |
| 329 | /// AddNodeIDValueTypes - Value type lists are intern'd so we can represent them |
| 330 | /// solely with their pointer. |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 331 | static void AddNodeIDValueTypes(FoldingSetNodeID &ID, SDVTList VTList) { |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 332 | ID.AddPointer(VTList.VTs); |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Jim Laskey | def69b9 | 2006-10-27 23:52:51 +0000 | [diff] [blame] | 335 | /// AddNodeIDOperands - Various routines for adding operands to the NodeID data. |
| 336 | /// |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 337 | static void AddNodeIDOperands(FoldingSetNodeID &ID, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 338 | const SDValue *Ops, unsigned NumOps) { |
Chris Lattner | 63e3f14 | 2007-02-04 07:28:00 +0000 | [diff] [blame] | 339 | for (; NumOps; --NumOps, ++Ops) { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 340 | ID.AddPointer(Ops->getNode()); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 341 | ID.AddInteger(Ops->getResNo()); |
Chris Lattner | 63e3f14 | 2007-02-04 07:28:00 +0000 | [diff] [blame] | 342 | } |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Dan Gohman | 6d9cdd5 | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 345 | /// AddNodeIDOperands - Various routines for adding operands to the NodeID data. |
| 346 | /// |
| 347 | static void AddNodeIDOperands(FoldingSetNodeID &ID, |
| 348 | const SDUse *Ops, unsigned NumOps) { |
| 349 | for (; NumOps; --NumOps, ++Ops) { |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 350 | ID.AddPointer(Ops->getNode()); |
| 351 | ID.AddInteger(Ops->getResNo()); |
Dan Gohman | 6d9cdd5 | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 352 | } |
| 353 | } |
| 354 | |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 355 | static void AddNodeIDNode(FoldingSetNodeID &ID, |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 356 | unsigned short OpC, SDVTList VTList, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 357 | const SDValue *OpList, unsigned N) { |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 358 | AddNodeIDOpcode(ID, OpC); |
| 359 | AddNodeIDValueTypes(ID, VTList); |
| 360 | AddNodeIDOperands(ID, OpList, N); |
| 361 | } |
| 362 | |
Duncan Sands | 0dc4045 | 2008-10-27 15:30:53 +0000 | [diff] [blame] | 363 | /// AddNodeIDCustom - If this is an SDNode with special info, add this info to |
| 364 | /// the NodeID data. |
| 365 | static void AddNodeIDCustom(FoldingSetNodeID &ID, const SDNode *N) { |
Dale Johannesen | 2041a0e | 2007-03-30 21:38:07 +0000 | [diff] [blame] | 366 | switch (N->getOpcode()) { |
Chris Lattner | 2a4ed82 | 2009-06-25 21:21:14 +0000 | [diff] [blame] | 367 | case ISD::TargetExternalSymbol: |
| 368 | case ISD::ExternalSymbol: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 369 | llvm_unreachable("Should only be used on nodes with operands"); |
Dale Johannesen | 2041a0e | 2007-03-30 21:38:07 +0000 | [diff] [blame] | 370 | default: break; // Normal nodes don't need extra info. |
| 371 | case ISD::TargetConstant: |
| 372 | case ISD::Constant: |
Dan Gohman | 4fbd796 | 2008-09-12 18:08:03 +0000 | [diff] [blame] | 373 | ID.AddPointer(cast<ConstantSDNode>(N)->getConstantIntValue()); |
Dale Johannesen | 2041a0e | 2007-03-30 21:38:07 +0000 | [diff] [blame] | 374 | break; |
| 375 | case ISD::TargetConstantFP: |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 376 | case ISD::ConstantFP: { |
Dan Gohman | 4fbd796 | 2008-09-12 18:08:03 +0000 | [diff] [blame] | 377 | ID.AddPointer(cast<ConstantFPSDNode>(N)->getConstantFPValue()); |
Dale Johannesen | 2041a0e | 2007-03-30 21:38:07 +0000 | [diff] [blame] | 378 | break; |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 379 | } |
Dale Johannesen | 2041a0e | 2007-03-30 21:38:07 +0000 | [diff] [blame] | 380 | case ISD::TargetGlobalAddress: |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 381 | case ISD::GlobalAddress: |
| 382 | case ISD::TargetGlobalTLSAddress: |
| 383 | case ISD::GlobalTLSAddress: { |
Dan Gohman | b8d2f55 | 2008-08-20 15:58:01 +0000 | [diff] [blame] | 384 | const GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(N); |
Dale Johannesen | 2041a0e | 2007-03-30 21:38:07 +0000 | [diff] [blame] | 385 | ID.AddPointer(GA->getGlobal()); |
| 386 | ID.AddInteger(GA->getOffset()); |
Chris Lattner | 2a4ed82 | 2009-06-25 21:21:14 +0000 | [diff] [blame] | 387 | ID.AddInteger(GA->getTargetFlags()); |
Pete Cooper | 32ecfb4 | 2012-07-30 20:23:19 +0000 | [diff] [blame] | 388 | ID.AddInteger(GA->getAddressSpace()); |
Dale Johannesen | 2041a0e | 2007-03-30 21:38:07 +0000 | [diff] [blame] | 389 | break; |
| 390 | } |
| 391 | case ISD::BasicBlock: |
| 392 | ID.AddPointer(cast<BasicBlockSDNode>(N)->getBasicBlock()); |
| 393 | break; |
| 394 | case ISD::Register: |
| 395 | ID.AddInteger(cast<RegisterSDNode>(N)->getReg()); |
| 396 | break; |
Jakob Stoklund Olesen | 9cf37e8 | 2012-01-18 23:52:12 +0000 | [diff] [blame] | 397 | case ISD::RegisterMask: |
| 398 | ID.AddPointer(cast<RegisterMaskSDNode>(N)->getRegMask()); |
| 399 | break; |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 400 | case ISD::SRCVALUE: |
| 401 | ID.AddPointer(cast<SrcValueSDNode>(N)->getValue()); |
| 402 | break; |
Dale Johannesen | 2041a0e | 2007-03-30 21:38:07 +0000 | [diff] [blame] | 403 | case ISD::FrameIndex: |
| 404 | case ISD::TargetFrameIndex: |
| 405 | ID.AddInteger(cast<FrameIndexSDNode>(N)->getIndex()); |
| 406 | break; |
| 407 | case ISD::JumpTable: |
| 408 | case ISD::TargetJumpTable: |
| 409 | ID.AddInteger(cast<JumpTableSDNode>(N)->getIndex()); |
Chris Lattner | f5a5546 | 2009-06-25 21:35:31 +0000 | [diff] [blame] | 410 | ID.AddInteger(cast<JumpTableSDNode>(N)->getTargetFlags()); |
Dale Johannesen | 2041a0e | 2007-03-30 21:38:07 +0000 | [diff] [blame] | 411 | break; |
| 412 | case ISD::ConstantPool: |
| 413 | case ISD::TargetConstantPool: { |
Dan Gohman | b8d2f55 | 2008-08-20 15:58:01 +0000 | [diff] [blame] | 414 | const ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(N); |
Dale Johannesen | 2041a0e | 2007-03-30 21:38:07 +0000 | [diff] [blame] | 415 | ID.AddInteger(CP->getAlignment()); |
| 416 | ID.AddInteger(CP->getOffset()); |
| 417 | if (CP->isMachineConstantPoolEntry()) |
Jim Grosbach | 5405d58 | 2011-09-27 20:59:33 +0000 | [diff] [blame] | 418 | CP->getMachineCPVal()->addSelectionDAGCSEId(ID); |
Dale Johannesen | 2041a0e | 2007-03-30 21:38:07 +0000 | [diff] [blame] | 419 | else |
| 420 | ID.AddPointer(CP->getConstVal()); |
Chris Lattner | f5a5546 | 2009-06-25 21:35:31 +0000 | [diff] [blame] | 421 | ID.AddInteger(CP->getTargetFlags()); |
Dale Johannesen | 2041a0e | 2007-03-30 21:38:07 +0000 | [diff] [blame] | 422 | break; |
| 423 | } |
Jakob Stoklund Olesen | 74500bd | 2012-08-07 22:37:05 +0000 | [diff] [blame] | 424 | case ISD::TargetIndex: { |
| 425 | const TargetIndexSDNode *TI = cast<TargetIndexSDNode>(N); |
| 426 | ID.AddInteger(TI->getIndex()); |
| 427 | ID.AddInteger(TI->getOffset()); |
| 428 | ID.AddInteger(TI->getTargetFlags()); |
| 429 | break; |
| 430 | } |
Dale Johannesen | 2041a0e | 2007-03-30 21:38:07 +0000 | [diff] [blame] | 431 | case ISD::LOAD: { |
Dan Gohman | b8d2f55 | 2008-08-20 15:58:01 +0000 | [diff] [blame] | 432 | const LoadSDNode *LD = cast<LoadSDNode>(N); |
Duncan Sands | 3b3adbb | 2008-06-06 12:49:32 +0000 | [diff] [blame] | 433 | ID.AddInteger(LD->getMemoryVT().getRawBits()); |
Dan Gohman | a7ce741 | 2009-02-03 00:08:45 +0000 | [diff] [blame] | 434 | ID.AddInteger(LD->getRawSubclassData()); |
Pete Cooper | 32ecfb4 | 2012-07-30 20:23:19 +0000 | [diff] [blame] | 435 | ID.AddInteger(LD->getPointerInfo().getAddrSpace()); |
Dale Johannesen | 2041a0e | 2007-03-30 21:38:07 +0000 | [diff] [blame] | 436 | break; |
| 437 | } |
| 438 | case ISD::STORE: { |
Dan Gohman | b8d2f55 | 2008-08-20 15:58:01 +0000 | [diff] [blame] | 439 | const StoreSDNode *ST = cast<StoreSDNode>(N); |
Duncan Sands | 3b3adbb | 2008-06-06 12:49:32 +0000 | [diff] [blame] | 440 | ID.AddInteger(ST->getMemoryVT().getRawBits()); |
Dan Gohman | a7ce741 | 2009-02-03 00:08:45 +0000 | [diff] [blame] | 441 | ID.AddInteger(ST->getRawSubclassData()); |
Pete Cooper | 32ecfb4 | 2012-07-30 20:23:19 +0000 | [diff] [blame] | 442 | ID.AddInteger(ST->getPointerInfo().getAddrSpace()); |
Dale Johannesen | 2041a0e | 2007-03-30 21:38:07 +0000 | [diff] [blame] | 443 | break; |
| 444 | } |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 445 | case ISD::ATOMIC_CMP_SWAP: |
| 446 | case ISD::ATOMIC_SWAP: |
| 447 | case ISD::ATOMIC_LOAD_ADD: |
| 448 | case ISD::ATOMIC_LOAD_SUB: |
| 449 | case ISD::ATOMIC_LOAD_AND: |
| 450 | case ISD::ATOMIC_LOAD_OR: |
| 451 | case ISD::ATOMIC_LOAD_XOR: |
| 452 | case ISD::ATOMIC_LOAD_NAND: |
| 453 | case ISD::ATOMIC_LOAD_MIN: |
| 454 | case ISD::ATOMIC_LOAD_MAX: |
| 455 | case ISD::ATOMIC_LOAD_UMIN: |
Eli Friedman | 327236c | 2011-08-24 20:50:09 +0000 | [diff] [blame] | 456 | case ISD::ATOMIC_LOAD_UMAX: |
| 457 | case ISD::ATOMIC_LOAD: |
| 458 | case ISD::ATOMIC_STORE: { |
Dan Gohman | b8d2f55 | 2008-08-20 15:58:01 +0000 | [diff] [blame] | 459 | const AtomicSDNode *AT = cast<AtomicSDNode>(N); |
Dan Gohman | a7ce741 | 2009-02-03 00:08:45 +0000 | [diff] [blame] | 460 | ID.AddInteger(AT->getMemoryVT().getRawBits()); |
| 461 | ID.AddInteger(AT->getRawSubclassData()); |
Pete Cooper | 32ecfb4 | 2012-07-30 20:23:19 +0000 | [diff] [blame] | 462 | ID.AddInteger(AT->getPointerInfo().getAddrSpace()); |
| 463 | break; |
| 464 | } |
| 465 | case ISD::PREFETCH: { |
| 466 | const MemSDNode *PF = cast<MemSDNode>(N); |
| 467 | ID.AddInteger(PF->getPointerInfo().getAddrSpace()); |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 468 | break; |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 469 | } |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 470 | case ISD::VECTOR_SHUFFLE: { |
| 471 | const ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(N); |
Eric Christopher | 4d7c18c | 2009-08-22 00:40:45 +0000 | [diff] [blame] | 472 | for (unsigned i = 0, e = N->getValueType(0).getVectorNumElements(); |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 473 | i != e; ++i) |
| 474 | ID.AddInteger(SVN->getMaskElt(i)); |
| 475 | break; |
| 476 | } |
Dan Gohman | 8c2b525 | 2009-10-30 01:27:03 +0000 | [diff] [blame] | 477 | case ISD::TargetBlockAddress: |
| 478 | case ISD::BlockAddress: { |
Michael Liao | 6c7ccaa | 2012-09-12 21:43:09 +0000 | [diff] [blame] | 479 | const BlockAddressSDNode *BA = cast<BlockAddressSDNode>(N); |
| 480 | ID.AddPointer(BA->getBlockAddress()); |
| 481 | ID.AddInteger(BA->getOffset()); |
| 482 | ID.AddInteger(BA->getTargetFlags()); |
Dan Gohman | 8c2b525 | 2009-10-30 01:27:03 +0000 | [diff] [blame] | 483 | break; |
| 484 | } |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 485 | } // end switch (N->getOpcode()) |
Pete Cooper | 32ecfb4 | 2012-07-30 20:23:19 +0000 | [diff] [blame] | 486 | |
| 487 | // Target specific memory nodes could also have address spaces to check. |
| 488 | if (N->isTargetMemoryOpcode()) |
| 489 | ID.AddInteger(cast<MemSDNode>(N)->getPointerInfo().getAddrSpace()); |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 490 | } |
| 491 | |
Duncan Sands | 0dc4045 | 2008-10-27 15:30:53 +0000 | [diff] [blame] | 492 | /// AddNodeIDNode - Generic routine for adding a nodes info to the NodeID |
| 493 | /// data. |
| 494 | static void AddNodeIDNode(FoldingSetNodeID &ID, const SDNode *N) { |
| 495 | AddNodeIDOpcode(ID, N->getOpcode()); |
| 496 | // Add the return value info. |
| 497 | AddNodeIDValueTypes(ID, N->getVTList()); |
| 498 | // Add the operand info. |
| 499 | AddNodeIDOperands(ID, N->op_begin(), N->getNumOperands()); |
| 500 | |
| 501 | // Handle SDNode leafs with special info. |
| 502 | AddNodeIDCustom(ID, N); |
| 503 | } |
| 504 | |
Dan Gohman | b8d2f55 | 2008-08-20 15:58:01 +0000 | [diff] [blame] | 505 | /// encodeMemSDNodeFlags - Generic routine for computing a value for use in |
David Greene | 1157f79 | 2010-02-17 20:21:42 +0000 | [diff] [blame] | 506 | /// the CSE map that carries volatility, temporalness, indexing mode, and |
Dan Gohman | a7ce741 | 2009-02-03 00:08:45 +0000 | [diff] [blame] | 507 | /// extension/truncation information. |
Dan Gohman | b8d2f55 | 2008-08-20 15:58:01 +0000 | [diff] [blame] | 508 | /// |
Bill Wendling | a1dc602 | 2008-10-19 20:51:12 +0000 | [diff] [blame] | 509 | static inline unsigned |
David Greene | 1157f79 | 2010-02-17 20:21:42 +0000 | [diff] [blame] | 510 | encodeMemSDNodeFlags(int ConvType, ISD::MemIndexedMode AM, bool isVolatile, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 511 | bool isNonTemporal, bool isInvariant) { |
Dan Gohman | a7ce741 | 2009-02-03 00:08:45 +0000 | [diff] [blame] | 512 | assert((ConvType & 3) == ConvType && |
| 513 | "ConvType may not require more than 2 bits!"); |
| 514 | assert((AM & 7) == AM && |
| 515 | "AM may not require more than 3 bits!"); |
| 516 | return ConvType | |
| 517 | (AM << 2) | |
David Greene | 1157f79 | 2010-02-17 20:21:42 +0000 | [diff] [blame] | 518 | (isVolatile << 5) | |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 519 | (isNonTemporal << 6) | |
| 520 | (isInvariant << 7); |
Dan Gohman | b8d2f55 | 2008-08-20 15:58:01 +0000 | [diff] [blame] | 521 | } |
| 522 | |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 523 | //===----------------------------------------------------------------------===// |
Jim Laskey | 58b968b | 2005-08-17 20:08:02 +0000 | [diff] [blame] | 524 | // SelectionDAG Class |
| 525 | //===----------------------------------------------------------------------===// |
Chris Lattner | b48da39 | 2005-01-23 04:39:44 +0000 | [diff] [blame] | 526 | |
Duncan Sands | 0dc4045 | 2008-10-27 15:30:53 +0000 | [diff] [blame] | 527 | /// doNotCSE - Return true if CSE should not be performed for this node. |
| 528 | static bool doNotCSE(SDNode *N) { |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 529 | if (N->getValueType(0) == MVT::Glue) |
Duncan Sands | 0dc4045 | 2008-10-27 15:30:53 +0000 | [diff] [blame] | 530 | return true; // Never CSE anything that produces a flag. |
| 531 | |
| 532 | switch (N->getOpcode()) { |
| 533 | default: break; |
| 534 | case ISD::HANDLENODE: |
Duncan Sands | 0dc4045 | 2008-10-27 15:30:53 +0000 | [diff] [blame] | 535 | case ISD::EH_LABEL: |
Duncan Sands | 0dc4045 | 2008-10-27 15:30:53 +0000 | [diff] [blame] | 536 | return true; // Never CSE these nodes. |
| 537 | } |
| 538 | |
| 539 | // Check that remaining values produced are not flags. |
| 540 | for (unsigned i = 1, e = N->getNumValues(); i != e; ++i) |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 541 | if (N->getValueType(i) == MVT::Glue) |
Duncan Sands | 0dc4045 | 2008-10-27 15:30:53 +0000 | [diff] [blame] | 542 | return true; // Never CSE anything that produces a flag. |
| 543 | |
| 544 | return false; |
| 545 | } |
| 546 | |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 547 | /// RemoveDeadNodes - This method deletes all unreachable nodes in the |
Chris Lattner | 190a418 | 2006-08-04 17:45:20 +0000 | [diff] [blame] | 548 | /// SelectionDAG. |
| 549 | void SelectionDAG::RemoveDeadNodes() { |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 550 | // Create a dummy node (which is not added to allnodes), that adds a reference |
| 551 | // to the root node, preventing it from being deleted. |
Chris Lattner | 9503859 | 2005-10-05 06:35:28 +0000 | [diff] [blame] | 552 | HandleSDNode Dummy(getRoot()); |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 553 | |
Chris Lattner | 190a418 | 2006-08-04 17:45:20 +0000 | [diff] [blame] | 554 | SmallVector<SDNode*, 128> DeadNodes; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 555 | |
Chris Lattner | 190a418 | 2006-08-04 17:45:20 +0000 | [diff] [blame] | 556 | // Add all obviously-dead nodes to the DeadNodes worklist. |
Chris Lattner | de202b3 | 2005-11-09 23:47:37 +0000 | [diff] [blame] | 557 | for (allnodes_iterator I = allnodes_begin(), E = allnodes_end(); I != E; ++I) |
Chris Lattner | 190a418 | 2006-08-04 17:45:20 +0000 | [diff] [blame] | 558 | if (I->use_empty()) |
| 559 | DeadNodes.push_back(I); |
| 560 | |
Dan Gohman | 0fe9c6e | 2008-07-07 20:57:48 +0000 | [diff] [blame] | 561 | RemoveDeadNodes(DeadNodes); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 562 | |
Dan Gohman | 0fe9c6e | 2008-07-07 20:57:48 +0000 | [diff] [blame] | 563 | // If the root changed (e.g. it was a dead load, update the root). |
| 564 | setRoot(Dummy.getValue()); |
| 565 | } |
| 566 | |
| 567 | /// RemoveDeadNodes - This method deletes the unreachable nodes in the |
| 568 | /// given list, and any nodes that become unreachable as a result. |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 569 | void SelectionDAG::RemoveDeadNodes(SmallVectorImpl<SDNode *> &DeadNodes) { |
Dan Gohman | 0fe9c6e | 2008-07-07 20:57:48 +0000 | [diff] [blame] | 570 | |
Chris Lattner | 190a418 | 2006-08-04 17:45:20 +0000 | [diff] [blame] | 571 | // Process the worklist, deleting the nodes and adding their uses to the |
| 572 | // worklist. |
| 573 | while (!DeadNodes.empty()) { |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 574 | SDNode *N = DeadNodes.pop_back_val(); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 575 | |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 576 | for (DAGUpdateListener *DUL = UpdateListeners; DUL; DUL = DUL->Next) |
| 577 | DUL->NodeDeleted(N, 0); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 578 | |
Chris Lattner | 190a418 | 2006-08-04 17:45:20 +0000 | [diff] [blame] | 579 | // Take the node out of the appropriate CSE map. |
| 580 | RemoveNodeFromCSEMaps(N); |
| 581 | |
| 582 | // Next, brutally remove the operand list. This is safe to do, as there are |
| 583 | // no cycles in the graph. |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 584 | for (SDNode::op_iterator I = N->op_begin(), E = N->op_end(); I != E; ) { |
| 585 | SDUse &Use = *I++; |
| 586 | SDNode *Operand = Use.getNode(); |
| 587 | Use.set(SDValue()); |
| 588 | |
Chris Lattner | 190a418 | 2006-08-04 17:45:20 +0000 | [diff] [blame] | 589 | // Now that we removed this operand, see if there are no uses of it left. |
| 590 | if (Operand->use_empty()) |
| 591 | DeadNodes.push_back(Operand); |
Chris Lattner | f469cb6 | 2005-11-08 18:52:27 +0000 | [diff] [blame] | 592 | } |
Bill Wendling | a1dc602 | 2008-10-19 20:51:12 +0000 | [diff] [blame] | 593 | |
Dan Gohman | c533612 | 2009-01-19 22:39:36 +0000 | [diff] [blame] | 594 | DeallocateNode(N); |
Chris Lattner | f469cb6 | 2005-11-08 18:52:27 +0000 | [diff] [blame] | 595 | } |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 596 | } |
| 597 | |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 598 | void SelectionDAG::RemoveDeadNode(SDNode *N){ |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 599 | SmallVector<SDNode*, 16> DeadNodes(1, N); |
Eli Friedman | 2efa35f | 2011-11-08 01:25:24 +0000 | [diff] [blame] | 600 | |
| 601 | // Create a dummy node that adds a reference to the root node, preventing |
| 602 | // it from being deleted. (This matters if the root is an operand of the |
| 603 | // dead node.) |
| 604 | HandleSDNode Dummy(getRoot()); |
| 605 | |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 606 | RemoveDeadNodes(DeadNodes); |
Evan Cheng | 130a647 | 2006-10-12 20:34:05 +0000 | [diff] [blame] | 607 | } |
| 608 | |
Chris Lattner | c26aefa | 2005-08-29 21:59:31 +0000 | [diff] [blame] | 609 | void SelectionDAG::DeleteNode(SDNode *N) { |
Chris Lattner | c26aefa | 2005-08-29 21:59:31 +0000 | [diff] [blame] | 610 | // First take this out of the appropriate CSE map. |
| 611 | RemoveNodeFromCSEMaps(N); |
| 612 | |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 613 | // Finally, remove uses due to operands of this node, remove from the |
Chris Lattner | 1e111c7 | 2005-09-07 05:37:01 +0000 | [diff] [blame] | 614 | // AllNodes list, and delete the node. |
| 615 | DeleteNodeNotInCSEMaps(N); |
| 616 | } |
| 617 | |
| 618 | void SelectionDAG::DeleteNodeNotInCSEMaps(SDNode *N) { |
Dan Gohman | e77f89d | 2009-01-25 16:20:37 +0000 | [diff] [blame] | 619 | assert(N != AllNodes.begin() && "Cannot delete the entry node!"); |
| 620 | assert(N->use_empty() && "Cannot delete a node that is not dead!"); |
Dan Gohman | c533612 | 2009-01-19 22:39:36 +0000 | [diff] [blame] | 621 | |
Dan Gohman | f06c835 | 2008-09-30 18:30:35 +0000 | [diff] [blame] | 622 | // Drop all of the operands and decrement used node's use counts. |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 623 | N->DropOperands(); |
Bill Wendling | a1dc602 | 2008-10-19 20:51:12 +0000 | [diff] [blame] | 624 | |
Dan Gohman | c533612 | 2009-01-19 22:39:36 +0000 | [diff] [blame] | 625 | DeallocateNode(N); |
| 626 | } |
| 627 | |
| 628 | void SelectionDAG::DeallocateNode(SDNode *N) { |
| 629 | if (N->OperandsNeedDelete) |
Chris Lattner | 63e3f14 | 2007-02-04 07:28:00 +0000 | [diff] [blame] | 630 | delete[] N->OperandList; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 631 | |
Dan Gohman | c533612 | 2009-01-19 22:39:36 +0000 | [diff] [blame] | 632 | // Set the opcode to DELETED_NODE to help catch bugs when node |
| 633 | // memory is reallocated. |
| 634 | N->NodeType = ISD::DELETED_NODE; |
| 635 | |
Dan Gohman | 1146728 | 2008-08-26 01:44:34 +0000 | [diff] [blame] | 636 | NodeAllocator.Deallocate(AllNodes.remove(N)); |
Daniel Dunbar | 819309e | 2009-12-16 20:10:05 +0000 | [diff] [blame] | 637 | |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 638 | // If any of the SDDbgValue nodes refer to this SDNode, invalidate them. |
Benjamin Kramer | 22a54c1 | 2011-06-18 13:13:44 +0000 | [diff] [blame] | 639 | ArrayRef<SDDbgValue*> DbgVals = DbgInfo->getSDDbgValues(N); |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 640 | for (unsigned i = 0, e = DbgVals.size(); i != e; ++i) |
| 641 | DbgVals[i]->setIsInvalidated(); |
Chris Lattner | c26aefa | 2005-08-29 21:59:31 +0000 | [diff] [blame] | 642 | } |
| 643 | |
Chris Lattner | 149c58c | 2005-08-16 18:17:10 +0000 | [diff] [blame] | 644 | /// RemoveNodeFromCSEMaps - Take the specified node out of the CSE map that |
| 645 | /// correspond to it. This is useful when we're about to delete or repurpose |
| 646 | /// the node. We don't want future request for structurally identical nodes |
| 647 | /// to return N anymore. |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 648 | bool SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) { |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 649 | bool Erased = false; |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 650 | switch (N->getOpcode()) { |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 651 | case ISD::HANDLENODE: return false; // noop. |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 652 | case ISD::CONDCODE: |
| 653 | assert(CondCodeNodes[cast<CondCodeSDNode>(N)->get()] && |
| 654 | "Cond code doesn't exist!"); |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 655 | Erased = CondCodeNodes[cast<CondCodeSDNode>(N)->get()] != 0; |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 656 | CondCodeNodes[cast<CondCodeSDNode>(N)->get()] = 0; |
| 657 | break; |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 658 | case ISD::ExternalSymbol: |
| 659 | Erased = ExternalSymbols.erase(cast<ExternalSymbolSDNode>(N)->getSymbol()); |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 660 | break; |
Chris Lattner | 1af2231 | 2009-06-25 18:45:50 +0000 | [diff] [blame] | 661 | case ISD::TargetExternalSymbol: { |
| 662 | ExternalSymbolSDNode *ESN = cast<ExternalSymbolSDNode>(N); |
| 663 | Erased = TargetExternalSymbols.erase( |
| 664 | std::pair<std::string,unsigned char>(ESN->getSymbol(), |
| 665 | ESN->getTargetFlags())); |
Andrew Lenharth | 2a2de66 | 2005-10-23 03:40:17 +0000 | [diff] [blame] | 666 | break; |
Chris Lattner | 1af2231 | 2009-06-25 18:45:50 +0000 | [diff] [blame] | 667 | } |
Duncan Sands | f411b83 | 2007-10-17 13:49:58 +0000 | [diff] [blame] | 668 | case ISD::VALUETYPE: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 669 | EVT VT = cast<VTSDNode>(N)->getVT(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 670 | if (VT.isExtended()) { |
Duncan Sands | f411b83 | 2007-10-17 13:49:58 +0000 | [diff] [blame] | 671 | Erased = ExtendedValueTypeNodes.erase(VT); |
| 672 | } else { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 673 | Erased = ValueTypeNodes[VT.getSimpleVT().SimpleTy] != 0; |
| 674 | ValueTypeNodes[VT.getSimpleVT().SimpleTy] = 0; |
Duncan Sands | f411b83 | 2007-10-17 13:49:58 +0000 | [diff] [blame] | 675 | } |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 676 | break; |
Duncan Sands | f411b83 | 2007-10-17 13:49:58 +0000 | [diff] [blame] | 677 | } |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 678 | default: |
Chris Lattner | 4a283e9 | 2006-08-11 18:38:11 +0000 | [diff] [blame] | 679 | // Remove it from the CSE Map. |
Duncan Sands | a30b7d2 | 2010-12-12 13:22:50 +0000 | [diff] [blame] | 680 | assert(N->getOpcode() != ISD::DELETED_NODE && "DELETED_NODE in CSEMap!"); |
| 681 | assert(N->getOpcode() != ISD::EntryToken && "EntryToken in CSEMap!"); |
Chris Lattner | 4a283e9 | 2006-08-11 18:38:11 +0000 | [diff] [blame] | 682 | Erased = CSEMap.RemoveNode(N); |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 683 | break; |
| 684 | } |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 685 | #ifndef NDEBUG |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 686 | // Verify that the node was actually in one of the CSE maps, unless it has a |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 687 | // flag result (which cannot be CSE'd) or is one of the special cases that are |
| 688 | // not subject to CSE. |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 689 | if (!Erased && N->getValueType(N->getNumValues()-1) != MVT::Glue && |
Duncan Sands | 0dc4045 | 2008-10-27 15:30:53 +0000 | [diff] [blame] | 690 | !N->isMachineOpcode() && !doNotCSE(N)) { |
Dan Gohman | b5bec2b | 2007-06-19 14:13:56 +0000 | [diff] [blame] | 691 | N->dump(this); |
David Greene | 55d146e | 2010-01-05 01:24:36 +0000 | [diff] [blame] | 692 | dbgs() << "\n"; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 693 | llvm_unreachable("Node is not in map!"); |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 694 | } |
| 695 | #endif |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 696 | return Erased; |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 697 | } |
| 698 | |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 699 | /// AddModifiedNodeToCSEMaps - The specified node has been removed from the CSE |
| 700 | /// maps and modified in place. Add it back to the CSE maps, unless an identical |
| 701 | /// node already exists, in which case transfer all its users to the existing |
| 702 | /// node. This transfer can potentially trigger recursive merging. |
Chris Lattner | 8b8749f | 2005-08-17 19:00:20 +0000 | [diff] [blame] | 703 | /// |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 704 | void |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 705 | SelectionDAG::AddModifiedNodeToCSEMaps(SDNode *N) { |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 706 | // For node types that aren't CSE'd, just act as if no identical node |
| 707 | // already exists. |
| 708 | if (!doNotCSE(N)) { |
| 709 | SDNode *Existing = CSEMap.GetOrInsertNode(N); |
| 710 | if (Existing != N) { |
| 711 | // If there was already an existing matching node, use ReplaceAllUsesWith |
| 712 | // to replace the dead one with the existing one. This can cause |
| 713 | // recursive merging of other unrelated nodes down the line. |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 714 | ReplaceAllUsesWith(N, Existing); |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 715 | |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 716 | // N is now dead. Inform the listeners and delete it. |
| 717 | for (DAGUpdateListener *DUL = UpdateListeners; DUL; DUL = DUL->Next) |
| 718 | DUL->NodeDeleted(N, Existing); |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 719 | DeleteNodeNotInCSEMaps(N); |
| 720 | return; |
| 721 | } |
| 722 | } |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 723 | |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 724 | // If the node doesn't already exist, we updated it. Inform listeners. |
| 725 | for (DAGUpdateListener *DUL = UpdateListeners; DUL; DUL = DUL->Next) |
| 726 | DUL->NodeUpdated(N); |
Chris Lattner | 8b8749f | 2005-08-17 19:00:20 +0000 | [diff] [blame] | 727 | } |
| 728 | |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 729 | /// FindModifiedNodeSlot - Find a slot for the specified node if its operands |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 730 | /// were replaced with those specified. If this node is never memoized, |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 731 | /// return null, otherwise return a pointer to the slot it would take. If a |
| 732 | /// node already exists with these operands, the slot will be non-null. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 733 | SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N, SDValue Op, |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 734 | void *&InsertPos) { |
Duncan Sands | 0dc4045 | 2008-10-27 15:30:53 +0000 | [diff] [blame] | 735 | if (doNotCSE(N)) |
| 736 | return 0; |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 737 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 738 | SDValue Ops[] = { Op }; |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 739 | FoldingSetNodeID ID; |
Chris Lattner | 63e3f14 | 2007-02-04 07:28:00 +0000 | [diff] [blame] | 740 | AddNodeIDNode(ID, N->getOpcode(), N->getVTList(), Ops, 1); |
Duncan Sands | 0dc4045 | 2008-10-27 15:30:53 +0000 | [diff] [blame] | 741 | AddNodeIDCustom(ID, N); |
Daniel Dunbar | 819309e | 2009-12-16 20:10:05 +0000 | [diff] [blame] | 742 | SDNode *Node = CSEMap.FindNodeOrInsertPos(ID, InsertPos); |
Daniel Dunbar | 819309e | 2009-12-16 20:10:05 +0000 | [diff] [blame] | 743 | return Node; |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | /// FindModifiedNodeSlot - Find a slot for the specified node if its operands |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 747 | /// were replaced with those specified. If this node is never memoized, |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 748 | /// return null, otherwise return a pointer to the slot it would take. If a |
| 749 | /// node already exists with these operands, the slot will be non-null. |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 750 | SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 751 | SDValue Op1, SDValue Op2, |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 752 | void *&InsertPos) { |
Duncan Sands | 0dc4045 | 2008-10-27 15:30:53 +0000 | [diff] [blame] | 753 | if (doNotCSE(N)) |
| 754 | return 0; |
| 755 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 756 | SDValue Ops[] = { Op1, Op2 }; |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 757 | FoldingSetNodeID ID; |
Chris Lattner | 63e3f14 | 2007-02-04 07:28:00 +0000 | [diff] [blame] | 758 | AddNodeIDNode(ID, N->getOpcode(), N->getVTList(), Ops, 2); |
Duncan Sands | 0dc4045 | 2008-10-27 15:30:53 +0000 | [diff] [blame] | 759 | AddNodeIDCustom(ID, N); |
Daniel Dunbar | 819309e | 2009-12-16 20:10:05 +0000 | [diff] [blame] | 760 | SDNode *Node = CSEMap.FindNodeOrInsertPos(ID, InsertPos); |
Daniel Dunbar | 819309e | 2009-12-16 20:10:05 +0000 | [diff] [blame] | 761 | return Node; |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | |
| 765 | /// FindModifiedNodeSlot - Find a slot for the specified node if its operands |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 766 | /// were replaced with those specified. If this node is never memoized, |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 767 | /// return null, otherwise return a pointer to the slot it would take. If a |
| 768 | /// node already exists with these operands, the slot will be non-null. |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 769 | SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 770 | const SDValue *Ops,unsigned NumOps, |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 771 | void *&InsertPos) { |
Duncan Sands | 0dc4045 | 2008-10-27 15:30:53 +0000 | [diff] [blame] | 772 | if (doNotCSE(N)) |
| 773 | return 0; |
Evan Cheng | 71e8685 | 2008-07-08 20:06:39 +0000 | [diff] [blame] | 774 | |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 775 | FoldingSetNodeID ID; |
Dan Gohman | 575e2f4 | 2007-06-04 15:49:41 +0000 | [diff] [blame] | 776 | AddNodeIDNode(ID, N->getOpcode(), N->getVTList(), Ops, NumOps); |
Duncan Sands | 0dc4045 | 2008-10-27 15:30:53 +0000 | [diff] [blame] | 777 | AddNodeIDCustom(ID, N); |
Daniel Dunbar | 819309e | 2009-12-16 20:10:05 +0000 | [diff] [blame] | 778 | SDNode *Node = CSEMap.FindNodeOrInsertPos(ID, InsertPos); |
Daniel Dunbar | 819309e | 2009-12-16 20:10:05 +0000 | [diff] [blame] | 779 | return Node; |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 780 | } |
Chris Lattner | 8b8749f | 2005-08-17 19:00:20 +0000 | [diff] [blame] | 781 | |
Benjamin Kramer | 3ca1363 | 2010-11-20 15:53:24 +0000 | [diff] [blame] | 782 | #ifndef NDEBUG |
Duncan Sands | 59d2dad | 2010-11-20 11:25:00 +0000 | [diff] [blame] | 783 | /// VerifyNodeCommon - Sanity check the given node. Aborts if it is invalid. |
| 784 | static void VerifyNodeCommon(SDNode *N) { |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 785 | switch (N->getOpcode()) { |
| 786 | default: |
| 787 | break; |
Duncan Sands | d22ec5f | 2008-10-29 14:22:20 +0000 | [diff] [blame] | 788 | case ISD::BUILD_PAIR: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 789 | EVT VT = N->getValueType(0); |
Duncan Sands | d22ec5f | 2008-10-29 14:22:20 +0000 | [diff] [blame] | 790 | assert(N->getNumValues() == 1 && "Too many results!"); |
| 791 | assert(!VT.isVector() && (VT.isInteger() || VT.isFloatingPoint()) && |
| 792 | "Wrong return type!"); |
| 793 | assert(N->getNumOperands() == 2 && "Wrong number of operands!"); |
| 794 | assert(N->getOperand(0).getValueType() == N->getOperand(1).getValueType() && |
| 795 | "Mismatched operand types!"); |
| 796 | assert(N->getOperand(0).getValueType().isInteger() == VT.isInteger() && |
| 797 | "Wrong operand type!"); |
| 798 | assert(VT.getSizeInBits() == 2 * N->getOperand(0).getValueSizeInBits() && |
| 799 | "Wrong return type size"); |
| 800 | break; |
| 801 | } |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 802 | case ISD::BUILD_VECTOR: { |
Duncan Sands | d22ec5f | 2008-10-29 14:22:20 +0000 | [diff] [blame] | 803 | assert(N->getNumValues() == 1 && "Too many results!"); |
| 804 | assert(N->getValueType(0).isVector() && "Wrong return type!"); |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 805 | assert(N->getNumOperands() == N->getValueType(0).getVectorNumElements() && |
Duncan Sands | d22ec5f | 2008-10-29 14:22:20 +0000 | [diff] [blame] | 806 | "Wrong number of operands!"); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 807 | EVT EltVT = N->getValueType(0).getVectorElementType(); |
Eli Friedman | 9db817f | 2011-09-09 21:04:06 +0000 | [diff] [blame] | 808 | for (SDNode::op_iterator I = N->op_begin(), E = N->op_end(); I != E; ++I) { |
Rafael Espindola | 15684b2 | 2009-04-24 12:40:33 +0000 | [diff] [blame] | 809 | assert((I->getValueType() == EltVT || |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 810 | (EltVT.isInteger() && I->getValueType().isInteger() && |
| 811 | EltVT.bitsLE(I->getValueType()))) && |
| 812 | "Wrong operand type!"); |
Eli Friedman | 9db817f | 2011-09-09 21:04:06 +0000 | [diff] [blame] | 813 | assert(I->getValueType() == N->getOperand(0).getValueType() && |
| 814 | "Operands must all have the same type"); |
| 815 | } |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 816 | break; |
| 817 | } |
| 818 | } |
| 819 | } |
| 820 | |
Duncan Sands | 59d2dad | 2010-11-20 11:25:00 +0000 | [diff] [blame] | 821 | /// VerifySDNode - Sanity check the given SDNode. Aborts if it is invalid. |
| 822 | static void VerifySDNode(SDNode *N) { |
| 823 | // The SDNode allocators cannot be used to allocate nodes with fields that are |
| 824 | // not present in an SDNode! |
| 825 | assert(!isa<MemSDNode>(N) && "Bad MemSDNode!"); |
| 826 | assert(!isa<ShuffleVectorSDNode>(N) && "Bad ShuffleVectorSDNode!"); |
| 827 | assert(!isa<ConstantSDNode>(N) && "Bad ConstantSDNode!"); |
| 828 | assert(!isa<ConstantFPSDNode>(N) && "Bad ConstantFPSDNode!"); |
| 829 | assert(!isa<GlobalAddressSDNode>(N) && "Bad GlobalAddressSDNode!"); |
| 830 | assert(!isa<FrameIndexSDNode>(N) && "Bad FrameIndexSDNode!"); |
| 831 | assert(!isa<JumpTableSDNode>(N) && "Bad JumpTableSDNode!"); |
| 832 | assert(!isa<ConstantPoolSDNode>(N) && "Bad ConstantPoolSDNode!"); |
| 833 | assert(!isa<BasicBlockSDNode>(N) && "Bad BasicBlockSDNode!"); |
| 834 | assert(!isa<SrcValueSDNode>(N) && "Bad SrcValueSDNode!"); |
| 835 | assert(!isa<MDNodeSDNode>(N) && "Bad MDNodeSDNode!"); |
| 836 | assert(!isa<RegisterSDNode>(N) && "Bad RegisterSDNode!"); |
| 837 | assert(!isa<BlockAddressSDNode>(N) && "Bad BlockAddressSDNode!"); |
| 838 | assert(!isa<EHLabelSDNode>(N) && "Bad EHLabelSDNode!"); |
| 839 | assert(!isa<ExternalSymbolSDNode>(N) && "Bad ExternalSymbolSDNode!"); |
| 840 | assert(!isa<CondCodeSDNode>(N) && "Bad CondCodeSDNode!"); |
| 841 | assert(!isa<CvtRndSatSDNode>(N) && "Bad CvtRndSatSDNode!"); |
| 842 | assert(!isa<VTSDNode>(N) && "Bad VTSDNode!"); |
| 843 | assert(!isa<MachineSDNode>(N) && "Bad MachineSDNode!"); |
| 844 | |
| 845 | VerifyNodeCommon(N); |
| 846 | } |
| 847 | |
| 848 | /// VerifyMachineNode - Sanity check the given MachineNode. Aborts if it is |
| 849 | /// invalid. |
| 850 | static void VerifyMachineNode(SDNode *N) { |
| 851 | // The MachineNode allocators cannot be used to allocate nodes with fields |
| 852 | // that are not present in a MachineNode! |
| 853 | // Currently there are no such nodes. |
| 854 | |
| 855 | VerifyNodeCommon(N); |
| 856 | } |
Benjamin Kramer | 3ca1363 | 2010-11-20 15:53:24 +0000 | [diff] [blame] | 857 | #endif // NDEBUG |
Duncan Sands | 59d2dad | 2010-11-20 11:25:00 +0000 | [diff] [blame] | 858 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 859 | /// getEVTAlignment - Compute the default alignment value for the |
Dan Gohman | 9c6e70e | 2008-07-08 23:46:32 +0000 | [diff] [blame] | 860 | /// given type. |
| 861 | /// |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 862 | unsigned SelectionDAG::getEVTAlignment(EVT VT) const { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 863 | Type *Ty = VT == MVT::iPTR ? |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 864 | PointerType::get(Type::getInt8Ty(*getContext()), 0) : |
Owen Anderson | 23b9b19 | 2009-08-12 00:36:31 +0000 | [diff] [blame] | 865 | VT.getTypeForEVT(*getContext()); |
Dan Gohman | 9c6e70e | 2008-07-08 23:46:32 +0000 | [diff] [blame] | 866 | |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 867 | return TM.getTargetLowering()->getDataLayout()->getABITypeAlignment(Ty); |
Dan Gohman | 9c6e70e | 2008-07-08 23:46:32 +0000 | [diff] [blame] | 868 | } |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 869 | |
Dale Johannesen | 92570c4 | 2009-02-07 02:15:05 +0000 | [diff] [blame] | 870 | // EntryNode could meaningfully have debug info if we can find it... |
Devang Patel | 0508d04 | 2011-12-15 18:21:18 +0000 | [diff] [blame] | 871 | SelectionDAG::SelectionDAG(const TargetMachine &tm, CodeGenOpt::Level OL) |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 872 | : TM(tm), TSI(*tm.getSelectionDAGInfo()), TTI(0), OptLevel(OL), |
| 873 | EntryNode(ISD::EntryToken, 0, DebugLoc(), getVTList(MVT::Other)), |
Andrew Trick | dd0fb01 | 2013-05-25 03:08:10 +0000 | [diff] [blame] | 874 | Root(getEntryNode()), UpdateListeners(0) { |
Dan Gohman | f350b27 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 875 | AllNodes.push_back(&EntryNode); |
Dale Johannesen | bfdf7f3 | 2010-03-10 22:13:47 +0000 | [diff] [blame] | 876 | DbgInfo = new SDDbgInfo(); |
Dan Gohman | 6f17966 | 2008-08-23 00:50:30 +0000 | [diff] [blame] | 877 | } |
| 878 | |
Chandler Carruth | e4b4edd | 2013-01-05 12:32:17 +0000 | [diff] [blame] | 879 | void SelectionDAG::init(MachineFunction &mf, const TargetTransformInfo *tti) { |
Dan Gohman | 7c3234c | 2008-08-27 23:52:12 +0000 | [diff] [blame] | 880 | MF = &mf; |
Chandler Carruth | e4b4edd | 2013-01-05 12:32:17 +0000 | [diff] [blame] | 881 | TTI = tti; |
Eric Christopher | 4d7c18c | 2009-08-22 00:40:45 +0000 | [diff] [blame] | 882 | Context = &mf.getFunction()->getContext(); |
Dan Gohman | 7c3234c | 2008-08-27 23:52:12 +0000 | [diff] [blame] | 883 | } |
| 884 | |
Chris Lattner | 78ec311 | 2003-08-11 14:57:33 +0000 | [diff] [blame] | 885 | SelectionDAG::~SelectionDAG() { |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 886 | assert(!UpdateListeners && "Dangling registered DAGUpdateListeners"); |
Dan Gohman | f350b27 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 887 | allnodes_clear(); |
Dale Johannesen | bfdf7f3 | 2010-03-10 22:13:47 +0000 | [diff] [blame] | 888 | delete DbgInfo; |
Dan Gohman | f350b27 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | void SelectionDAG::allnodes_clear() { |
Dan Gohman | 1146728 | 2008-08-26 01:44:34 +0000 | [diff] [blame] | 892 | assert(&*AllNodes.begin() == &EntryNode); |
| 893 | AllNodes.remove(AllNodes.begin()); |
Dan Gohman | c533612 | 2009-01-19 22:39:36 +0000 | [diff] [blame] | 894 | while (!AllNodes.empty()) |
| 895 | DeallocateNode(AllNodes.begin()); |
Chris Lattner | 78ec311 | 2003-08-11 14:57:33 +0000 | [diff] [blame] | 896 | } |
| 897 | |
Dan Gohman | 7c3234c | 2008-08-27 23:52:12 +0000 | [diff] [blame] | 898 | void SelectionDAG::clear() { |
Dan Gohman | f350b27 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 899 | allnodes_clear(); |
| 900 | OperandAllocator.Reset(); |
| 901 | CSEMap.clear(); |
| 902 | |
| 903 | ExtendedValueTypeNodes.clear(); |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 904 | ExternalSymbols.clear(); |
| 905 | TargetExternalSymbols.clear(); |
Dan Gohman | f350b27 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 906 | std::fill(CondCodeNodes.begin(), CondCodeNodes.end(), |
| 907 | static_cast<CondCodeSDNode*>(0)); |
| 908 | std::fill(ValueTypeNodes.begin(), ValueTypeNodes.end(), |
| 909 | static_cast<SDNode*>(0)); |
| 910 | |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 911 | EntryNode.UseList = 0; |
Dan Gohman | f350b27 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 912 | AllNodes.push_back(&EntryNode); |
| 913 | Root = getEntryNode(); |
Evan Cheng | 31441b7 | 2010-03-29 20:48:30 +0000 | [diff] [blame] | 914 | DbgInfo->clear(); |
Dan Gohman | f350b27 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 915 | } |
| 916 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 917 | SDValue SelectionDAG::getAnyExtOrTrunc(SDValue Op, SDLoc DL, EVT VT) { |
Nadav Rotem | a3c42f3 | 2011-09-27 11:16:47 +0000 | [diff] [blame] | 918 | return VT.bitsGT(Op.getValueType()) ? |
| 919 | getNode(ISD::ANY_EXTEND, DL, VT, Op) : |
| 920 | getNode(ISD::TRUNCATE, DL, VT, Op); |
| 921 | } |
| 922 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 923 | SDValue SelectionDAG::getSExtOrTrunc(SDValue Op, SDLoc DL, EVT VT) { |
Duncan Sands | 3a66a68 | 2009-10-13 21:04:12 +0000 | [diff] [blame] | 924 | return VT.bitsGT(Op.getValueType()) ? |
| 925 | getNode(ISD::SIGN_EXTEND, DL, VT, Op) : |
| 926 | getNode(ISD::TRUNCATE, DL, VT, Op); |
| 927 | } |
| 928 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 929 | SDValue SelectionDAG::getZExtOrTrunc(SDValue Op, SDLoc DL, EVT VT) { |
Duncan Sands | 3a66a68 | 2009-10-13 21:04:12 +0000 | [diff] [blame] | 930 | return VT.bitsGT(Op.getValueType()) ? |
| 931 | getNode(ISD::ZERO_EXTEND, DL, VT, Op) : |
| 932 | getNode(ISD::TRUNCATE, DL, VT, Op); |
| 933 | } |
| 934 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 935 | SDValue SelectionDAG::getZeroExtendInReg(SDValue Op, SDLoc DL, EVT VT) { |
Dan Gohman | 87862e7 | 2009-12-11 21:31:27 +0000 | [diff] [blame] | 936 | assert(!VT.isVector() && |
| 937 | "getZeroExtendInReg should use the vector element type instead of " |
| 938 | "the vector type!"); |
Bill Wendling | 6ce610f | 2009-01-30 22:23:15 +0000 | [diff] [blame] | 939 | if (Op.getValueType() == VT) return Op; |
Dan Gohman | 87862e7 | 2009-12-11 21:31:27 +0000 | [diff] [blame] | 940 | unsigned BitWidth = Op.getValueType().getScalarType().getSizeInBits(); |
| 941 | APInt Imm = APInt::getLowBitsSet(BitWidth, |
Bill Wendling | 6ce610f | 2009-01-30 22:23:15 +0000 | [diff] [blame] | 942 | VT.getSizeInBits()); |
| 943 | return getNode(ISD::AND, DL, Op.getValueType(), Op, |
| 944 | getConstant(Imm, Op.getValueType())); |
| 945 | } |
| 946 | |
Bob Wilson | 4c24546 | 2009-01-22 17:39:32 +0000 | [diff] [blame] | 947 | /// getNOT - Create a bitwise NOT operation as (XOR Val, -1). |
| 948 | /// |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 949 | SDValue SelectionDAG::getNOT(SDLoc DL, SDValue Val, EVT VT) { |
Chris Lattner | 5cf0b6e | 2010-02-24 22:44:06 +0000 | [diff] [blame] | 950 | EVT EltVT = VT.getScalarType(); |
Dan Gohman | bd209ab | 2009-04-20 22:51:43 +0000 | [diff] [blame] | 951 | SDValue NegOne = |
| 952 | getConstant(APInt::getAllOnesValue(EltVT.getSizeInBits()), VT); |
Bill Wendling | 41b9d27 | 2009-01-30 22:11:22 +0000 | [diff] [blame] | 953 | return getNode(ISD::XOR, DL, VT, Val, NegOne); |
| 954 | } |
| 955 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 956 | SDValue SelectionDAG::getConstant(uint64_t Val, EVT VT, bool isT) { |
Chris Lattner | 5cf0b6e | 2010-02-24 22:44:06 +0000 | [diff] [blame] | 957 | EVT EltVT = VT.getScalarType(); |
Dan Gohman | ce9bc12 | 2009-01-27 20:39:34 +0000 | [diff] [blame] | 958 | assert((EltVT.getSizeInBits() >= 64 || |
| 959 | (uint64_t)((int64_t)Val >> EltVT.getSizeInBits()) + 1 < 2) && |
| 960 | "getConstant with a uint64_t value that doesn't fit in the type!"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 961 | return getConstant(APInt(EltVT.getSizeInBits(), Val), VT, isT); |
Dan Gohman | 6394b09 | 2008-02-08 22:59:30 +0000 | [diff] [blame] | 962 | } |
| 963 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 964 | SDValue SelectionDAG::getConstant(const APInt &Val, EVT VT, bool isT) { |
Owen Anderson | eed707b | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 965 | return getConstant(*ConstantInt::get(*Context, Val), VT, isT); |
Dan Gohman | 4fbd796 | 2008-09-12 18:08:03 +0000 | [diff] [blame] | 966 | } |
| 967 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 968 | SDValue SelectionDAG::getConstant(const ConstantInt &Val, EVT VT, bool isT) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 969 | assert(VT.isInteger() && "Cannot create FP integer constant!"); |
Dan Gohman | 8908132 | 2007-12-12 22:21:26 +0000 | [diff] [blame] | 970 | |
Chris Lattner | 5cf0b6e | 2010-02-24 22:44:06 +0000 | [diff] [blame] | 971 | EVT EltVT = VT.getScalarType(); |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 972 | const ConstantInt *Elt = &Val; |
Chris Lattner | 61b0941 | 2006-08-11 21:01:22 +0000 | [diff] [blame] | 973 | |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 974 | const TargetLowering *TLI = TM.getTargetLowering(); |
| 975 | |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 976 | // In some cases the vector type is legal but the element type is illegal and |
| 977 | // needs to be promoted, for example v8i8 on ARM. In this case, promote the |
| 978 | // inserted value (the type does not need to match the vector element type). |
| 979 | // Any extra bits introduced will be truncated away. |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 980 | if (VT.isVector() && TLI->getTypeAction(*getContext(), EltVT) == |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 981 | TargetLowering::TypePromoteInteger) { |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 982 | EltVT = TLI->getTypeToTransformTo(*getContext(), EltVT); |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 983 | APInt NewVal = Elt->getValue().zext(EltVT.getSizeInBits()); |
| 984 | Elt = ConstantInt::get(*getContext(), NewVal); |
| 985 | } |
| 986 | |
| 987 | assert(Elt->getBitWidth() == EltVT.getSizeInBits() && |
| 988 | "APInt size does not match type size!"); |
Chris Lattner | 61b0941 | 2006-08-11 21:01:22 +0000 | [diff] [blame] | 989 | unsigned Opc = isT ? ISD::TargetConstant : ISD::Constant; |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 990 | FoldingSetNodeID ID; |
Dan Gohman | 6d9cdd5 | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 991 | AddNodeIDNode(ID, Opc, getVTList(EltVT), 0, 0); |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 992 | ID.AddPointer(Elt); |
Chris Lattner | 61b0941 | 2006-08-11 21:01:22 +0000 | [diff] [blame] | 993 | void *IP = 0; |
Dan Gohman | 8908132 | 2007-12-12 22:21:26 +0000 | [diff] [blame] | 994 | SDNode *N = NULL; |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 995 | if ((N = CSEMap.FindNodeOrInsertPos(ID, IP))) |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 996 | if (!VT.isVector()) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 997 | return SDValue(N, 0); |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 998 | |
Dan Gohman | 8908132 | 2007-12-12 22:21:26 +0000 | [diff] [blame] | 999 | if (!N) { |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 1000 | N = new (NodeAllocator) ConstantSDNode(isT, Elt, EltVT); |
Dan Gohman | 8908132 | 2007-12-12 22:21:26 +0000 | [diff] [blame] | 1001 | CSEMap.InsertNode(N, IP); |
| 1002 | AllNodes.push_back(N); |
| 1003 | } |
| 1004 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1005 | SDValue Result(N, 0); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1006 | if (VT.isVector()) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1007 | SmallVector<SDValue, 8> Ops; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1008 | Ops.assign(VT.getVectorNumElements(), Result); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1009 | Result = getNode(ISD::BUILD_VECTOR, SDLoc(), VT, &Ops[0], Ops.size()); |
Dan Gohman | 8908132 | 2007-12-12 22:21:26 +0000 | [diff] [blame] | 1010 | } |
| 1011 | return Result; |
Chris Lattner | 78ec311 | 2003-08-11 14:57:33 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1014 | SDValue SelectionDAG::getIntPtrConstant(uint64_t Val, bool isTarget) { |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 1015 | return getConstant(Val, TM.getTargetLowering()->getPointerTy(), isTarget); |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1019 | SDValue SelectionDAG::getConstantFP(const APFloat& V, EVT VT, bool isTarget) { |
Owen Anderson | 6f83c9c | 2009-07-27 20:59:43 +0000 | [diff] [blame] | 1020 | return getConstantFP(*ConstantFP::get(*getContext(), V), VT, isTarget); |
Dan Gohman | 4fbd796 | 2008-09-12 18:08:03 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1023 | SDValue SelectionDAG::getConstantFP(const ConstantFP& V, EVT VT, bool isTarget){ |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1024 | assert(VT.isFloatingPoint() && "Cannot create integer FP constant!"); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1025 | |
Chris Lattner | 5cf0b6e | 2010-02-24 22:44:06 +0000 | [diff] [blame] | 1026 | EVT EltVT = VT.getScalarType(); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1027 | |
Chris Lattner | d865861 | 2005-02-17 20:17:32 +0000 | [diff] [blame] | 1028 | // Do the map lookup using the actual bit pattern for the floating point |
| 1029 | // value, so that we don't have problems with 0.0 comparing equal to -0.0, and |
| 1030 | // we don't have issues with SNANs. |
Chris Lattner | c9f8f41 | 2006-08-11 21:55:30 +0000 | [diff] [blame] | 1031 | unsigned Opc = isTarget ? ISD::TargetConstantFP : ISD::ConstantFP; |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 1032 | FoldingSetNodeID ID; |
Dan Gohman | 6d9cdd5 | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 1033 | AddNodeIDNode(ID, Opc, getVTList(EltVT), 0, 0); |
Dan Gohman | 4fbd796 | 2008-09-12 18:08:03 +0000 | [diff] [blame] | 1034 | ID.AddPointer(&V); |
Chris Lattner | c9f8f41 | 2006-08-11 21:55:30 +0000 | [diff] [blame] | 1035 | void *IP = 0; |
Evan Cheng | c908dcd | 2007-06-29 21:36:04 +0000 | [diff] [blame] | 1036 | SDNode *N = NULL; |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1037 | if ((N = CSEMap.FindNodeOrInsertPos(ID, IP))) |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1038 | if (!VT.isVector()) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1039 | return SDValue(N, 0); |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1040 | |
Evan Cheng | c908dcd | 2007-06-29 21:36:04 +0000 | [diff] [blame] | 1041 | if (!N) { |
Dan Gohman | 9553188 | 2010-03-18 18:49:47 +0000 | [diff] [blame] | 1042 | N = new (NodeAllocator) ConstantFPSDNode(isTarget, &V, EltVT); |
Evan Cheng | c908dcd | 2007-06-29 21:36:04 +0000 | [diff] [blame] | 1043 | CSEMap.InsertNode(N, IP); |
| 1044 | AllNodes.push_back(N); |
| 1045 | } |
| 1046 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1047 | SDValue Result(N, 0); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1048 | if (VT.isVector()) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1049 | SmallVector<SDValue, 8> Ops; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1050 | Ops.assign(VT.getVectorNumElements(), Result); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1051 | // FIXME SDLoc info might be appropriate here |
| 1052 | Result = getNode(ISD::BUILD_VECTOR, SDLoc(), VT, &Ops[0], Ops.size()); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 1053 | } |
| 1054 | return Result; |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1057 | SDValue SelectionDAG::getConstantFP(double Val, EVT VT, bool isTarget) { |
Chris Lattner | 5cf0b6e | 2010-02-24 22:44:06 +0000 | [diff] [blame] | 1058 | EVT EltVT = VT.getScalarType(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1059 | if (EltVT==MVT::f32) |
Dale Johannesen | f04afdb | 2007-08-30 00:23:21 +0000 | [diff] [blame] | 1060 | return getConstantFP(APFloat((float)Val), VT, isTarget); |
Dale Johannesen | 0a406ae | 2010-05-07 21:35:53 +0000 | [diff] [blame] | 1061 | else if (EltVT==MVT::f64) |
Dale Johannesen | f04afdb | 2007-08-30 00:23:21 +0000 | [diff] [blame] | 1062 | return getConstantFP(APFloat(Val), VT, isTarget); |
Hal Finkel | 6eb7a42 | 2012-12-30 19:03:32 +0000 | [diff] [blame] | 1063 | else if (EltVT==MVT::f80 || EltVT==MVT::f128 || EltVT==MVT::ppcf128 || |
| 1064 | EltVT==MVT::f16) { |
Dale Johannesen | 0a406ae | 2010-05-07 21:35:53 +0000 | [diff] [blame] | 1065 | bool ignored; |
| 1066 | APFloat apf = APFloat(Val); |
Tim Northover | 0a29cb0 | 2013-01-22 09:46:31 +0000 | [diff] [blame] | 1067 | apf.convert(EVTToAPFloatSemantics(EltVT), APFloat::rmNearestTiesToEven, |
Dale Johannesen | 0a406ae | 2010-05-07 21:35:53 +0000 | [diff] [blame] | 1068 | &ignored); |
| 1069 | return getConstantFP(apf, VT, isTarget); |
Craig Topper | 5e25ee8 | 2012-02-05 08:31:47 +0000 | [diff] [blame] | 1070 | } else |
| 1071 | llvm_unreachable("Unsupported type in getConstantFP"); |
Dale Johannesen | f04afdb | 2007-08-30 00:23:21 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1074 | SDValue SelectionDAG::getGlobalAddress(const GlobalValue *GV, SDLoc DL, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1075 | EVT VT, int64_t Offset, |
Chris Lattner | 2a4ed82 | 2009-06-25 21:21:14 +0000 | [diff] [blame] | 1076 | bool isTargetGA, |
| 1077 | unsigned char TargetFlags) { |
| 1078 | assert((TargetFlags == 0 || isTargetGA) && |
| 1079 | "Cannot set target flags on target-independent globals"); |
Eric Christopher | 4d7c18c | 2009-08-22 00:40:45 +0000 | [diff] [blame] | 1080 | |
Dan Gohman | 6520e20 | 2008-10-18 02:06:02 +0000 | [diff] [blame] | 1081 | // Truncate (with sign-extension) the offset value to the pointer size. |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 1082 | unsigned BitWidth = TM.getTargetLowering()->getPointerTy().getSizeInBits(); |
Dan Gohman | 6520e20 | 2008-10-18 02:06:02 +0000 | [diff] [blame] | 1083 | if (BitWidth < 64) |
Richard Smith | 1144af3 | 2012-08-24 23:29:28 +0000 | [diff] [blame] | 1084 | Offset = SignExtend64(Offset, BitWidth); |
Dan Gohman | 6520e20 | 2008-10-18 02:06:02 +0000 | [diff] [blame] | 1085 | |
Anton Korobeynikov | 4d86e2a | 2008-03-11 22:38:53 +0000 | [diff] [blame] | 1086 | const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV); |
| 1087 | if (!GVar) { |
Anton Korobeynikov | c73ede0 | 2008-03-22 07:53:40 +0000 | [diff] [blame] | 1088 | // If GV is an alias then use the aliasee for determining thread-localness. |
Anton Korobeynikov | 4d86e2a | 2008-03-11 22:38:53 +0000 | [diff] [blame] | 1089 | if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV)) |
Anton Korobeynikov | 19e861a | 2008-09-09 20:05:04 +0000 | [diff] [blame] | 1090 | GVar = dyn_cast_or_null<GlobalVariable>(GA->resolveAliasedGlobal(false)); |
Anton Korobeynikov | 4d86e2a | 2008-03-11 22:38:53 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
Chris Lattner | 2a4ed82 | 2009-06-25 21:21:14 +0000 | [diff] [blame] | 1093 | unsigned Opc; |
Lauro Ramos Venancio | b3a0417 | 2007-04-20 21:38:10 +0000 | [diff] [blame] | 1094 | if (GVar && GVar->isThreadLocal()) |
| 1095 | Opc = isTargetGA ? ISD::TargetGlobalTLSAddress : ISD::GlobalTLSAddress; |
| 1096 | else |
| 1097 | Opc = isTargetGA ? ISD::TargetGlobalAddress : ISD::GlobalAddress; |
Anton Korobeynikov | 4d86e2a | 2008-03-11 22:38:53 +0000 | [diff] [blame] | 1098 | |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 1099 | FoldingSetNodeID ID; |
Dan Gohman | 6d9cdd5 | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 1100 | AddNodeIDNode(ID, Opc, getVTList(VT), 0, 0); |
Chris Lattner | 61b0941 | 2006-08-11 21:01:22 +0000 | [diff] [blame] | 1101 | ID.AddPointer(GV); |
| 1102 | ID.AddInteger(Offset); |
Chris Lattner | 2a4ed82 | 2009-06-25 21:21:14 +0000 | [diff] [blame] | 1103 | ID.AddInteger(TargetFlags); |
Pete Cooper | 32ecfb4 | 2012-07-30 20:23:19 +0000 | [diff] [blame] | 1104 | ID.AddInteger(GV->getType()->getAddressSpace()); |
Chris Lattner | 61b0941 | 2006-08-11 21:01:22 +0000 | [diff] [blame] | 1105 | void *IP = 0; |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1106 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
Dan Gohman | 74692c0 | 2009-01-25 16:21:38 +0000 | [diff] [blame] | 1107 | return SDValue(E, 0); |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1108 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1109 | SDNode *N = new (NodeAllocator) GlobalAddressSDNode(Opc, DL.getIROrder(), |
| 1110 | DL.getDebugLoc(), GV, VT, |
Dan Gohman | 9553188 | 2010-03-18 18:49:47 +0000 | [diff] [blame] | 1111 | Offset, TargetFlags); |
Chris Lattner | 61b0941 | 2006-08-11 21:01:22 +0000 | [diff] [blame] | 1112 | CSEMap.InsertNode(N, IP); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1113 | AllNodes.push_back(N); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1114 | return SDValue(N, 0); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1115 | } |
| 1116 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1117 | SDValue SelectionDAG::getFrameIndex(int FI, EVT VT, bool isTarget) { |
Chris Lattner | c9f8f41 | 2006-08-11 21:55:30 +0000 | [diff] [blame] | 1118 | unsigned Opc = isTarget ? ISD::TargetFrameIndex : ISD::FrameIndex; |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 1119 | FoldingSetNodeID ID; |
Dan Gohman | 6d9cdd5 | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 1120 | AddNodeIDNode(ID, Opc, getVTList(VT), 0, 0); |
Chris Lattner | c9f8f41 | 2006-08-11 21:55:30 +0000 | [diff] [blame] | 1121 | ID.AddInteger(FI); |
| 1122 | void *IP = 0; |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1123 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1124 | return SDValue(E, 0); |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1125 | |
Dan Gohman | 9553188 | 2010-03-18 18:49:47 +0000 | [diff] [blame] | 1126 | SDNode *N = new (NodeAllocator) FrameIndexSDNode(FI, VT, isTarget); |
Chris Lattner | c9f8f41 | 2006-08-11 21:55:30 +0000 | [diff] [blame] | 1127 | CSEMap.InsertNode(N, IP); |
Chris Lattner | afb2dd4 | 2005-08-25 00:43:01 +0000 | [diff] [blame] | 1128 | AllNodes.push_back(N); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1129 | return SDValue(N, 0); |
Chris Lattner | afb2dd4 | 2005-08-25 00:43:01 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1132 | SDValue SelectionDAG::getJumpTable(int JTI, EVT VT, bool isTarget, |
Chris Lattner | f5a5546 | 2009-06-25 21:35:31 +0000 | [diff] [blame] | 1133 | unsigned char TargetFlags) { |
| 1134 | assert((TargetFlags == 0 || isTarget) && |
| 1135 | "Cannot set target flags on target-independent jump tables"); |
Chris Lattner | c9f8f41 | 2006-08-11 21:55:30 +0000 | [diff] [blame] | 1136 | unsigned Opc = isTarget ? ISD::TargetJumpTable : ISD::JumpTable; |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 1137 | FoldingSetNodeID ID; |
Dan Gohman | 6d9cdd5 | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 1138 | AddNodeIDNode(ID, Opc, getVTList(VT), 0, 0); |
Chris Lattner | c9f8f41 | 2006-08-11 21:55:30 +0000 | [diff] [blame] | 1139 | ID.AddInteger(JTI); |
Chris Lattner | f5a5546 | 2009-06-25 21:35:31 +0000 | [diff] [blame] | 1140 | ID.AddInteger(TargetFlags); |
Chris Lattner | c9f8f41 | 2006-08-11 21:55:30 +0000 | [diff] [blame] | 1141 | void *IP = 0; |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1142 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1143 | return SDValue(E, 0); |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1144 | |
Dan Gohman | 9553188 | 2010-03-18 18:49:47 +0000 | [diff] [blame] | 1145 | SDNode *N = new (NodeAllocator) JumpTableSDNode(JTI, VT, isTarget, |
| 1146 | TargetFlags); |
Chris Lattner | c9f8f41 | 2006-08-11 21:55:30 +0000 | [diff] [blame] | 1147 | CSEMap.InsertNode(N, IP); |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1148 | AllNodes.push_back(N); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1149 | return SDValue(N, 0); |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 1150 | } |
| 1151 | |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1152 | SDValue SelectionDAG::getConstantPool(const Constant *C, EVT VT, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1153 | unsigned Alignment, int Offset, |
Eric Christopher | 4d7c18c | 2009-08-22 00:40:45 +0000 | [diff] [blame] | 1154 | bool isTarget, |
Chris Lattner | f5a5546 | 2009-06-25 21:35:31 +0000 | [diff] [blame] | 1155 | unsigned char TargetFlags) { |
| 1156 | assert((TargetFlags == 0 || isTarget) && |
| 1157 | "Cannot set target flags on target-independent globals"); |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 1158 | if (Alignment == 0) |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 1159 | Alignment = |
| 1160 | TM.getTargetLowering()->getDataLayout()->getPrefTypeAlignment(C->getType()); |
Chris Lattner | c9f8f41 | 2006-08-11 21:55:30 +0000 | [diff] [blame] | 1161 | unsigned Opc = isTarget ? ISD::TargetConstantPool : ISD::ConstantPool; |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 1162 | FoldingSetNodeID ID; |
Dan Gohman | 6d9cdd5 | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 1163 | AddNodeIDNode(ID, Opc, getVTList(VT), 0, 0); |
Chris Lattner | c9f8f41 | 2006-08-11 21:55:30 +0000 | [diff] [blame] | 1164 | ID.AddInteger(Alignment); |
| 1165 | ID.AddInteger(Offset); |
Chris Lattner | 130fc13 | 2006-08-14 20:12:44 +0000 | [diff] [blame] | 1166 | ID.AddPointer(C); |
Chris Lattner | f5a5546 | 2009-06-25 21:35:31 +0000 | [diff] [blame] | 1167 | ID.AddInteger(TargetFlags); |
Chris Lattner | c9f8f41 | 2006-08-11 21:55:30 +0000 | [diff] [blame] | 1168 | void *IP = 0; |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1169 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1170 | return SDValue(E, 0); |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1171 | |
Dan Gohman | 9553188 | 2010-03-18 18:49:47 +0000 | [diff] [blame] | 1172 | SDNode *N = new (NodeAllocator) ConstantPoolSDNode(isTarget, C, VT, Offset, |
| 1173 | Alignment, TargetFlags); |
Chris Lattner | c9f8f41 | 2006-08-11 21:55:30 +0000 | [diff] [blame] | 1174 | CSEMap.InsertNode(N, IP); |
Chris Lattner | 4025a9c | 2005-08-25 05:03:06 +0000 | [diff] [blame] | 1175 | AllNodes.push_back(N); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1176 | return SDValue(N, 0); |
Chris Lattner | 4025a9c | 2005-08-25 05:03:06 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1179 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1180 | SDValue SelectionDAG::getConstantPool(MachineConstantPoolValue *C, EVT VT, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1181 | unsigned Alignment, int Offset, |
Chris Lattner | f5a5546 | 2009-06-25 21:35:31 +0000 | [diff] [blame] | 1182 | bool isTarget, |
| 1183 | unsigned char TargetFlags) { |
| 1184 | assert((TargetFlags == 0 || isTarget) && |
| 1185 | "Cannot set target flags on target-independent globals"); |
Dan Gohman | 50284d8 | 2008-09-16 22:05:41 +0000 | [diff] [blame] | 1186 | if (Alignment == 0) |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 1187 | Alignment = |
| 1188 | TM.getTargetLowering()->getDataLayout()->getPrefTypeAlignment(C->getType()); |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1189 | unsigned Opc = isTarget ? ISD::TargetConstantPool : ISD::ConstantPool; |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 1190 | FoldingSetNodeID ID; |
Dan Gohman | 6d9cdd5 | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 1191 | AddNodeIDNode(ID, Opc, getVTList(VT), 0, 0); |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1192 | ID.AddInteger(Alignment); |
| 1193 | ID.AddInteger(Offset); |
Jim Grosbach | 5405d58 | 2011-09-27 20:59:33 +0000 | [diff] [blame] | 1194 | C->addSelectionDAGCSEId(ID); |
Chris Lattner | f5a5546 | 2009-06-25 21:35:31 +0000 | [diff] [blame] | 1195 | ID.AddInteger(TargetFlags); |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1196 | void *IP = 0; |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1197 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1198 | return SDValue(E, 0); |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1199 | |
Dan Gohman | 9553188 | 2010-03-18 18:49:47 +0000 | [diff] [blame] | 1200 | SDNode *N = new (NodeAllocator) ConstantPoolSDNode(isTarget, C, VT, Offset, |
| 1201 | Alignment, TargetFlags); |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1202 | CSEMap.InsertNode(N, IP); |
| 1203 | AllNodes.push_back(N); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1204 | return SDValue(N, 0); |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
Jakob Stoklund Olesen | 74500bd | 2012-08-07 22:37:05 +0000 | [diff] [blame] | 1207 | SDValue SelectionDAG::getTargetIndex(int Index, EVT VT, int64_t Offset, |
| 1208 | unsigned char TargetFlags) { |
| 1209 | FoldingSetNodeID ID; |
| 1210 | AddNodeIDNode(ID, ISD::TargetIndex, getVTList(VT), 0, 0); |
| 1211 | ID.AddInteger(Index); |
| 1212 | ID.AddInteger(Offset); |
| 1213 | ID.AddInteger(TargetFlags); |
| 1214 | void *IP = 0; |
| 1215 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
| 1216 | return SDValue(E, 0); |
| 1217 | |
| 1218 | SDNode *N = new (NodeAllocator) TargetIndexSDNode(Index, VT, Offset, |
| 1219 | TargetFlags); |
| 1220 | CSEMap.InsertNode(N, IP); |
| 1221 | AllNodes.push_back(N); |
| 1222 | return SDValue(N, 0); |
| 1223 | } |
| 1224 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1225 | SDValue SelectionDAG::getBasicBlock(MachineBasicBlock *MBB) { |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 1226 | FoldingSetNodeID ID; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1227 | AddNodeIDNode(ID, ISD::BasicBlock, getVTList(MVT::Other), 0, 0); |
Chris Lattner | 61b0941 | 2006-08-11 21:01:22 +0000 | [diff] [blame] | 1228 | ID.AddPointer(MBB); |
| 1229 | void *IP = 0; |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1230 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1231 | return SDValue(E, 0); |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1232 | |
Dan Gohman | 9553188 | 2010-03-18 18:49:47 +0000 | [diff] [blame] | 1233 | SDNode *N = new (NodeAllocator) BasicBlockSDNode(MBB); |
Chris Lattner | 61b0941 | 2006-08-11 21:01:22 +0000 | [diff] [blame] | 1234 | CSEMap.InsertNode(N, IP); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1235 | AllNodes.push_back(N); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1236 | return SDValue(N, 0); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1237 | } |
| 1238 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1239 | SDValue SelectionDAG::getValueType(EVT VT) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1240 | if (VT.isSimple() && (unsigned)VT.getSimpleVT().SimpleTy >= |
| 1241 | ValueTypeNodes.size()) |
| 1242 | ValueTypeNodes.resize(VT.getSimpleVT().SimpleTy+1); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 1243 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1244 | SDNode *&N = VT.isExtended() ? |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1245 | ExtendedValueTypeNodes[VT] : ValueTypeNodes[VT.getSimpleVT().SimpleTy]; |
Duncan Sands | f411b83 | 2007-10-17 13:49:58 +0000 | [diff] [blame] | 1246 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1247 | if (N) return SDValue(N, 0); |
Dan Gohman | 9553188 | 2010-03-18 18:49:47 +0000 | [diff] [blame] | 1248 | N = new (NodeAllocator) VTSDNode(VT); |
Duncan Sands | f411b83 | 2007-10-17 13:49:58 +0000 | [diff] [blame] | 1249 | AllNodes.push_back(N); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1250 | return SDValue(N, 0); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1253 | SDValue SelectionDAG::getExternalSymbol(const char *Sym, EVT VT) { |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1254 | SDNode *&N = ExternalSymbols[Sym]; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1255 | if (N) return SDValue(N, 0); |
Dan Gohman | 9553188 | 2010-03-18 18:49:47 +0000 | [diff] [blame] | 1256 | N = new (NodeAllocator) ExternalSymbolSDNode(false, Sym, 0, VT); |
Andrew Lenharth | 2a2de66 | 2005-10-23 03:40:17 +0000 | [diff] [blame] | 1257 | AllNodes.push_back(N); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1258 | return SDValue(N, 0); |
Andrew Lenharth | 2a2de66 | 2005-10-23 03:40:17 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1261 | SDValue SelectionDAG::getTargetExternalSymbol(const char *Sym, EVT VT, |
Chris Lattner | 1af2231 | 2009-06-25 18:45:50 +0000 | [diff] [blame] | 1262 | unsigned char TargetFlags) { |
| 1263 | SDNode *&N = |
| 1264 | TargetExternalSymbols[std::pair<std::string,unsigned char>(Sym, |
| 1265 | TargetFlags)]; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1266 | if (N) return SDValue(N, 0); |
Dan Gohman | 9553188 | 2010-03-18 18:49:47 +0000 | [diff] [blame] | 1267 | N = new (NodeAllocator) ExternalSymbolSDNode(true, Sym, TargetFlags, VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1268 | AllNodes.push_back(N); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1269 | return SDValue(N, 0); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1272 | SDValue SelectionDAG::getCondCode(ISD::CondCode Cond) { |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 1273 | if ((unsigned)Cond >= CondCodeNodes.size()) |
| 1274 | CondCodeNodes.resize(Cond+1); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1275 | |
Chris Lattner | 079a27a | 2005-08-09 20:40:02 +0000 | [diff] [blame] | 1276 | if (CondCodeNodes[Cond] == 0) { |
Dan Gohman | 9553188 | 2010-03-18 18:49:47 +0000 | [diff] [blame] | 1277 | CondCodeSDNode *N = new (NodeAllocator) CondCodeSDNode(Cond); |
Dan Gohman | 0e5f130 | 2008-07-07 23:02:41 +0000 | [diff] [blame] | 1278 | CondCodeNodes[Cond] = N; |
| 1279 | AllNodes.push_back(N); |
Chris Lattner | 079a27a | 2005-08-09 20:40:02 +0000 | [diff] [blame] | 1280 | } |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1281 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1282 | return SDValue(CondCodeNodes[Cond], 0); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
Nate Begeman | 5a5ca15 | 2009-04-29 05:20:52 +0000 | [diff] [blame] | 1285 | // commuteShuffle - swaps the values of N1 and N2, and swaps all indices in |
| 1286 | // the shuffle mask M that point at N1 to point at N2, and indices that point |
| 1287 | // N2 to point at N1. |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1288 | static void commuteShuffle(SDValue &N1, SDValue &N2, SmallVectorImpl<int> &M) { |
| 1289 | std::swap(N1, N2); |
| 1290 | int NElts = M.size(); |
| 1291 | for (int i = 0; i != NElts; ++i) { |
| 1292 | if (M[i] >= NElts) |
| 1293 | M[i] -= NElts; |
| 1294 | else if (M[i] >= 0) |
| 1295 | M[i] += NElts; |
| 1296 | } |
| 1297 | } |
| 1298 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1299 | SDValue SelectionDAG::getVectorShuffle(EVT VT, SDLoc dl, SDValue N1, |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1300 | SDValue N2, const int *Mask) { |
Craig Topper | ad445a6 | 2013-08-09 04:37:24 +0000 | [diff] [blame] | 1301 | assert(VT == N1.getValueType() && VT == N2.getValueType() && |
| 1302 | "Invalid VECTOR_SHUFFLE"); |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1303 | |
| 1304 | // Canonicalize shuffle undef, undef -> undef |
| 1305 | if (N1.getOpcode() == ISD::UNDEF && N2.getOpcode() == ISD::UNDEF) |
Dan Gohman | 2e4284d | 2009-07-09 00:46:33 +0000 | [diff] [blame] | 1306 | return getUNDEF(VT); |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1307 | |
Eric Christopher | 4d7c18c | 2009-08-22 00:40:45 +0000 | [diff] [blame] | 1308 | // Validate that all indices in Mask are within the range of the elements |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1309 | // input to the shuffle. |
Nate Begeman | 5a5ca15 | 2009-04-29 05:20:52 +0000 | [diff] [blame] | 1310 | unsigned NElts = VT.getVectorNumElements(); |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1311 | SmallVector<int, 8> MaskVec; |
Nate Begeman | 5a5ca15 | 2009-04-29 05:20:52 +0000 | [diff] [blame] | 1312 | for (unsigned i = 0; i != NElts; ++i) { |
| 1313 | assert(Mask[i] < (int)(NElts * 2) && "Index out of range"); |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1314 | MaskVec.push_back(Mask[i]); |
| 1315 | } |
Eric Christopher | 4d7c18c | 2009-08-22 00:40:45 +0000 | [diff] [blame] | 1316 | |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1317 | // Canonicalize shuffle v, v -> v, undef |
| 1318 | if (N1 == N2) { |
| 1319 | N2 = getUNDEF(VT); |
Nate Begeman | 5a5ca15 | 2009-04-29 05:20:52 +0000 | [diff] [blame] | 1320 | for (unsigned i = 0; i != NElts; ++i) |
| 1321 | if (MaskVec[i] >= (int)NElts) MaskVec[i] -= NElts; |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1322 | } |
Eric Christopher | 4d7c18c | 2009-08-22 00:40:45 +0000 | [diff] [blame] | 1323 | |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1324 | // Canonicalize shuffle undef, v -> v, undef. Commute the shuffle mask. |
| 1325 | if (N1.getOpcode() == ISD::UNDEF) |
| 1326 | commuteShuffle(N1, N2, MaskVec); |
Eric Christopher | 4d7c18c | 2009-08-22 00:40:45 +0000 | [diff] [blame] | 1327 | |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1328 | // Canonicalize all index into lhs, -> shuffle lhs, undef |
| 1329 | // Canonicalize all index into rhs, -> shuffle rhs, undef |
| 1330 | bool AllLHS = true, AllRHS = true; |
| 1331 | bool N2Undef = N2.getOpcode() == ISD::UNDEF; |
Nate Begeman | 5a5ca15 | 2009-04-29 05:20:52 +0000 | [diff] [blame] | 1332 | for (unsigned i = 0; i != NElts; ++i) { |
| 1333 | if (MaskVec[i] >= (int)NElts) { |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1334 | if (N2Undef) |
| 1335 | MaskVec[i] = -1; |
| 1336 | else |
| 1337 | AllLHS = false; |
| 1338 | } else if (MaskVec[i] >= 0) { |
| 1339 | AllRHS = false; |
| 1340 | } |
| 1341 | } |
| 1342 | if (AllLHS && AllRHS) |
| 1343 | return getUNDEF(VT); |
Nate Begeman | 5a5ca15 | 2009-04-29 05:20:52 +0000 | [diff] [blame] | 1344 | if (AllLHS && !N2Undef) |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1345 | N2 = getUNDEF(VT); |
| 1346 | if (AllRHS) { |
| 1347 | N1 = getUNDEF(VT); |
| 1348 | commuteShuffle(N1, N2, MaskVec); |
| 1349 | } |
Eric Christopher | 4d7c18c | 2009-08-22 00:40:45 +0000 | [diff] [blame] | 1350 | |
Craig Topper | eee2a11 | 2013-08-08 08:03:12 +0000 | [diff] [blame] | 1351 | // If Identity shuffle return that node. |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1352 | bool Identity = true; |
Nate Begeman | 5a5ca15 | 2009-04-29 05:20:52 +0000 | [diff] [blame] | 1353 | for (unsigned i = 0; i != NElts; ++i) { |
| 1354 | if (MaskVec[i] >= 0 && MaskVec[i] != (int)i) Identity = false; |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1355 | } |
Craig Topper | ad445a6 | 2013-08-09 04:37:24 +0000 | [diff] [blame] | 1356 | if (Identity && NElts) |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1357 | return N1; |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1358 | |
| 1359 | FoldingSetNodeID ID; |
| 1360 | SDValue Ops[2] = { N1, N2 }; |
| 1361 | AddNodeIDNode(ID, ISD::VECTOR_SHUFFLE, getVTList(VT), Ops, 2); |
Nate Begeman | 5a5ca15 | 2009-04-29 05:20:52 +0000 | [diff] [blame] | 1362 | for (unsigned i = 0; i != NElts; ++i) |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1363 | ID.AddInteger(MaskVec[i]); |
Eric Christopher | 4d7c18c | 2009-08-22 00:40:45 +0000 | [diff] [blame] | 1364 | |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1365 | void* IP = 0; |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1366 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1367 | return SDValue(E, 0); |
Eric Christopher | 4d7c18c | 2009-08-22 00:40:45 +0000 | [diff] [blame] | 1368 | |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1369 | // Allocate the mask array for the node out of the BumpPtrAllocator, since |
| 1370 | // SDNode doesn't have access to it. This memory will be "leaked" when |
| 1371 | // the node is deallocated, but recovered when the NodeAllocator is released. |
| 1372 | int *MaskAlloc = OperandAllocator.Allocate<int>(NElts); |
| 1373 | memcpy(MaskAlloc, &MaskVec[0], NElts * sizeof(int)); |
Eric Christopher | 4d7c18c | 2009-08-22 00:40:45 +0000 | [diff] [blame] | 1374 | |
Dan Gohman | 9553188 | 2010-03-18 18:49:47 +0000 | [diff] [blame] | 1375 | ShuffleVectorSDNode *N = |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 1376 | new (NodeAllocator) ShuffleVectorSDNode(VT, dl.getIROrder(), |
| 1377 | dl.getDebugLoc(), N1, N2, |
| 1378 | MaskAlloc); |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1379 | CSEMap.InsertNode(N, IP); |
| 1380 | AllNodes.push_back(N); |
| 1381 | return SDValue(N, 0); |
| 1382 | } |
| 1383 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1384 | SDValue SelectionDAG::getConvertRndSat(EVT VT, SDLoc dl, |
Dale Johannesen | a04b757 | 2009-02-03 23:04:43 +0000 | [diff] [blame] | 1385 | SDValue Val, SDValue DTy, |
| 1386 | SDValue STy, SDValue Rnd, SDValue Sat, |
| 1387 | ISD::CvtCode Code) { |
Mon P Wang | b0e341b | 2009-02-05 04:47:42 +0000 | [diff] [blame] | 1388 | // If the src and dest types are the same and the conversion is between |
| 1389 | // integer types of the same sign or two floats, no conversion is necessary. |
| 1390 | if (DTy == STy && |
| 1391 | (Code == ISD::CVT_UU || Code == ISD::CVT_SS || Code == ISD::CVT_FF)) |
Dale Johannesen | a04b757 | 2009-02-03 23:04:43 +0000 | [diff] [blame] | 1392 | return Val; |
| 1393 | |
| 1394 | FoldingSetNodeID ID; |
Mon P Wang | bdea348 | 2009-11-07 04:46:25 +0000 | [diff] [blame] | 1395 | SDValue Ops[] = { Val, DTy, STy, Rnd, Sat }; |
| 1396 | AddNodeIDNode(ID, ISD::CONVERT_RNDSAT, getVTList(VT), &Ops[0], 5); |
Dale Johannesen | a04b757 | 2009-02-03 23:04:43 +0000 | [diff] [blame] | 1397 | void* IP = 0; |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1398 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
Dale Johannesen | a04b757 | 2009-02-03 23:04:43 +0000 | [diff] [blame] | 1399 | return SDValue(E, 0); |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1400 | |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 1401 | CvtRndSatSDNode *N = new (NodeAllocator) CvtRndSatSDNode(VT, dl.getIROrder(), |
| 1402 | dl.getDebugLoc(), |
| 1403 | Ops, 5, Code); |
Dale Johannesen | a04b757 | 2009-02-03 23:04:43 +0000 | [diff] [blame] | 1404 | CSEMap.InsertNode(N, IP); |
| 1405 | AllNodes.push_back(N); |
| 1406 | return SDValue(N, 0); |
| 1407 | } |
| 1408 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1409 | SDValue SelectionDAG::getRegister(unsigned RegNo, EVT VT) { |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 1410 | FoldingSetNodeID ID; |
Dan Gohman | 6d9cdd5 | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 1411 | AddNodeIDNode(ID, ISD::Register, getVTList(VT), 0, 0); |
Chris Lattner | 61b0941 | 2006-08-11 21:01:22 +0000 | [diff] [blame] | 1412 | ID.AddInteger(RegNo); |
| 1413 | void *IP = 0; |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1414 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1415 | return SDValue(E, 0); |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1416 | |
Dan Gohman | 9553188 | 2010-03-18 18:49:47 +0000 | [diff] [blame] | 1417 | SDNode *N = new (NodeAllocator) RegisterSDNode(RegNo, VT); |
Chris Lattner | 61b0941 | 2006-08-11 21:01:22 +0000 | [diff] [blame] | 1418 | CSEMap.InsertNode(N, IP); |
| 1419 | AllNodes.push_back(N); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1420 | return SDValue(N, 0); |
Chris Lattner | 61b0941 | 2006-08-11 21:01:22 +0000 | [diff] [blame] | 1421 | } |
| 1422 | |
Jakob Stoklund Olesen | 9cf37e8 | 2012-01-18 23:52:12 +0000 | [diff] [blame] | 1423 | SDValue SelectionDAG::getRegisterMask(const uint32_t *RegMask) { |
| 1424 | FoldingSetNodeID ID; |
| 1425 | AddNodeIDNode(ID, ISD::RegisterMask, getVTList(MVT::Untyped), 0, 0); |
| 1426 | ID.AddPointer(RegMask); |
| 1427 | void *IP = 0; |
| 1428 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
| 1429 | return SDValue(E, 0); |
| 1430 | |
| 1431 | SDNode *N = new (NodeAllocator) RegisterMaskSDNode(RegMask); |
| 1432 | CSEMap.InsertNode(N, IP); |
| 1433 | AllNodes.push_back(N); |
| 1434 | return SDValue(N, 0); |
| 1435 | } |
| 1436 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1437 | SDValue SelectionDAG::getEHLabel(SDLoc dl, SDValue Root, MCSymbol *Label) { |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 1438 | FoldingSetNodeID ID; |
| 1439 | SDValue Ops[] = { Root }; |
Chris Lattner | 7561d48 | 2010-03-14 02:33:54 +0000 | [diff] [blame] | 1440 | AddNodeIDNode(ID, ISD::EH_LABEL, getVTList(MVT::Other), &Ops[0], 1); |
| 1441 | ID.AddPointer(Label); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 1442 | void *IP = 0; |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1443 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 1444 | return SDValue(E, 0); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1445 | |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 1446 | SDNode *N = new (NodeAllocator) EHLabelSDNode(dl.getIROrder(), |
| 1447 | dl.getDebugLoc(), Root, Label); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 1448 | CSEMap.InsertNode(N, IP); |
| 1449 | AllNodes.push_back(N); |
| 1450 | return SDValue(N, 0); |
| 1451 | } |
| 1452 | |
Chris Lattner | 7561d48 | 2010-03-14 02:33:54 +0000 | [diff] [blame] | 1453 | |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1454 | SDValue SelectionDAG::getBlockAddress(const BlockAddress *BA, EVT VT, |
Michael Liao | 6c7ccaa | 2012-09-12 21:43:09 +0000 | [diff] [blame] | 1455 | int64_t Offset, |
Dan Gohman | 29cbade | 2009-11-20 23:18:13 +0000 | [diff] [blame] | 1456 | bool isTarget, |
| 1457 | unsigned char TargetFlags) { |
Dan Gohman | 8c2b525 | 2009-10-30 01:27:03 +0000 | [diff] [blame] | 1458 | unsigned Opc = isTarget ? ISD::TargetBlockAddress : ISD::BlockAddress; |
| 1459 | |
| 1460 | FoldingSetNodeID ID; |
Dan Gohman | 29cbade | 2009-11-20 23:18:13 +0000 | [diff] [blame] | 1461 | AddNodeIDNode(ID, Opc, getVTList(VT), 0, 0); |
Dan Gohman | 8c2b525 | 2009-10-30 01:27:03 +0000 | [diff] [blame] | 1462 | ID.AddPointer(BA); |
Michael Liao | 6c7ccaa | 2012-09-12 21:43:09 +0000 | [diff] [blame] | 1463 | ID.AddInteger(Offset); |
Dan Gohman | 29cbade | 2009-11-20 23:18:13 +0000 | [diff] [blame] | 1464 | ID.AddInteger(TargetFlags); |
Dan Gohman | 8c2b525 | 2009-10-30 01:27:03 +0000 | [diff] [blame] | 1465 | void *IP = 0; |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1466 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
Dan Gohman | 8c2b525 | 2009-10-30 01:27:03 +0000 | [diff] [blame] | 1467 | return SDValue(E, 0); |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1468 | |
Michael Liao | 6c7ccaa | 2012-09-12 21:43:09 +0000 | [diff] [blame] | 1469 | SDNode *N = new (NodeAllocator) BlockAddressSDNode(Opc, VT, BA, Offset, |
| 1470 | TargetFlags); |
Dan Gohman | 8c2b525 | 2009-10-30 01:27:03 +0000 | [diff] [blame] | 1471 | CSEMap.InsertNode(N, IP); |
| 1472 | AllNodes.push_back(N); |
| 1473 | return SDValue(N, 0); |
| 1474 | } |
| 1475 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1476 | SDValue SelectionDAG::getSrcValue(const Value *V) { |
Duncan Sands | 1df9859 | 2010-02-16 11:11:14 +0000 | [diff] [blame] | 1477 | assert((!V || V->getType()->isPointerTy()) && |
Chris Lattner | 61b0941 | 2006-08-11 21:01:22 +0000 | [diff] [blame] | 1478 | "SrcValue is not a pointer?"); |
| 1479 | |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 1480 | FoldingSetNodeID ID; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1481 | AddNodeIDNode(ID, ISD::SRCVALUE, getVTList(MVT::Other), 0, 0); |
Chris Lattner | 61b0941 | 2006-08-11 21:01:22 +0000 | [diff] [blame] | 1482 | ID.AddPointer(V); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1483 | |
Chris Lattner | 61b0941 | 2006-08-11 21:01:22 +0000 | [diff] [blame] | 1484 | void *IP = 0; |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 1485 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1486 | return SDValue(E, 0); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1487 | |
Dan Gohman | 9553188 | 2010-03-18 18:49:47 +0000 | [diff] [blame] | 1488 | SDNode *N = new (NodeAllocator) SrcValueSDNode(V); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1489 | CSEMap.InsertNode(N, IP); |
| 1490 | AllNodes.push_back(N); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1491 | return SDValue(N, 0); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
Chris Lattner | decc267 | 2010-04-07 05:20:54 +0000 | [diff] [blame] | 1494 | /// getMDNode - Return an MDNodeSDNode which holds an MDNode. |
| 1495 | SDValue SelectionDAG::getMDNode(const MDNode *MD) { |
| 1496 | FoldingSetNodeID ID; |
| 1497 | AddNodeIDNode(ID, ISD::MDNODE_SDNODE, getVTList(MVT::Other), 0, 0); |
| 1498 | ID.AddPointer(MD); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1499 | |
Chris Lattner | decc267 | 2010-04-07 05:20:54 +0000 | [diff] [blame] | 1500 | void *IP = 0; |
| 1501 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
| 1502 | return SDValue(E, 0); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1503 | |
Chris Lattner | decc267 | 2010-04-07 05:20:54 +0000 | [diff] [blame] | 1504 | SDNode *N = new (NodeAllocator) MDNodeSDNode(MD); |
| 1505 | CSEMap.InsertNode(N, IP); |
| 1506 | AllNodes.push_back(N); |
| 1507 | return SDValue(N, 0); |
| 1508 | } |
| 1509 | |
Matt Arsenault | 59d3ae6 | 2013-11-15 01:34:59 +0000 | [diff] [blame^] | 1510 | /// getAddrSpaceCast - Return an AddrSpaceCastSDNode. |
| 1511 | SDValue SelectionDAG::getAddrSpaceCast(SDLoc dl, EVT VT, SDValue Ptr, |
| 1512 | unsigned SrcAS, unsigned DestAS) { |
| 1513 | SDValue Ops[] = {Ptr}; |
| 1514 | FoldingSetNodeID ID; |
| 1515 | AddNodeIDNode(ID, ISD::ADDRSPACECAST, getVTList(VT), &Ops[0], 1); |
| 1516 | ID.AddInteger(SrcAS); |
| 1517 | ID.AddInteger(DestAS); |
| 1518 | |
| 1519 | void *IP = 0; |
| 1520 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
| 1521 | return SDValue(E, 0); |
| 1522 | |
| 1523 | SDNode *N = new (NodeAllocator) AddrSpaceCastSDNode(dl.getIROrder(), |
| 1524 | dl.getDebugLoc(), |
| 1525 | VT, Ptr, SrcAS, DestAS); |
| 1526 | CSEMap.InsertNode(N, IP); |
| 1527 | AllNodes.push_back(N); |
| 1528 | return SDValue(N, 0); |
| 1529 | } |
Chris Lattner | decc267 | 2010-04-07 05:20:54 +0000 | [diff] [blame] | 1530 | |
Duncan Sands | 92abc62 | 2009-01-31 15:50:11 +0000 | [diff] [blame] | 1531 | /// getShiftAmountOperand - Return the specified value casted to |
| 1532 | /// the target's desired shift amount type. |
Owen Anderson | 6154f6c | 2011-03-07 18:29:47 +0000 | [diff] [blame] | 1533 | SDValue SelectionDAG::getShiftAmountOperand(EVT LHSTy, SDValue Op) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1534 | EVT OpTy = Op.getValueType(); |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 1535 | EVT ShTy = TM.getTargetLowering()->getShiftAmountTy(LHSTy); |
Duncan Sands | 92abc62 | 2009-01-31 15:50:11 +0000 | [diff] [blame] | 1536 | if (OpTy == ShTy || OpTy.isVector()) return Op; |
| 1537 | |
| 1538 | ISD::NodeType Opcode = OpTy.bitsGT(ShTy) ? ISD::TRUNCATE : ISD::ZERO_EXTEND; |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1539 | return getNode(Opcode, SDLoc(Op), ShTy, Op); |
Duncan Sands | 92abc62 | 2009-01-31 15:50:11 +0000 | [diff] [blame] | 1540 | } |
| 1541 | |
Chris Lattner | 37ce9df | 2007-10-15 17:47:20 +0000 | [diff] [blame] | 1542 | /// CreateStackTemporary - Create a stack temporary, suitable for holding the |
| 1543 | /// specified value type. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1544 | SDValue SelectionDAG::CreateStackTemporary(EVT VT, unsigned minAlign) { |
Chris Lattner | 37ce9df | 2007-10-15 17:47:20 +0000 | [diff] [blame] | 1545 | MachineFrameInfo *FrameInfo = getMachineFunction().getFrameInfo(); |
Dan Gohman | 4e918b2 | 2009-09-23 21:07:02 +0000 | [diff] [blame] | 1546 | unsigned ByteSize = VT.getStoreSize(); |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1547 | Type *Ty = VT.getTypeForEVT(*getContext()); |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 1548 | const TargetLowering *TLI = TM.getTargetLowering(); |
Mon P Wang | 364d73d | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 1549 | unsigned StackAlign = |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 1550 | std::max((unsigned)TLI->getDataLayout()->getPrefTypeAlignment(Ty), minAlign); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1551 | |
David Greene | 3f2bf85 | 2009-11-12 20:49:22 +0000 | [diff] [blame] | 1552 | int FrameIdx = FrameInfo->CreateStackObject(ByteSize, StackAlign, false); |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 1553 | return getFrameIndex(FrameIdx, TLI->getPointerTy()); |
Chris Lattner | 37ce9df | 2007-10-15 17:47:20 +0000 | [diff] [blame] | 1554 | } |
| 1555 | |
Duncan Sands | 47d9dcc | 2008-12-09 21:33:20 +0000 | [diff] [blame] | 1556 | /// CreateStackTemporary - Create a stack temporary suitable for holding |
| 1557 | /// either of the specified value types. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1558 | SDValue SelectionDAG::CreateStackTemporary(EVT VT1, EVT VT2) { |
Duncan Sands | 47d9dcc | 2008-12-09 21:33:20 +0000 | [diff] [blame] | 1559 | unsigned Bytes = std::max(VT1.getStoreSizeInBits(), |
| 1560 | VT2.getStoreSizeInBits())/8; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1561 | Type *Ty1 = VT1.getTypeForEVT(*getContext()); |
| 1562 | Type *Ty2 = VT2.getTypeForEVT(*getContext()); |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 1563 | const TargetLowering *TLI = TM.getTargetLowering(); |
| 1564 | const DataLayout *TD = TLI->getDataLayout(); |
Duncan Sands | 47d9dcc | 2008-12-09 21:33:20 +0000 | [diff] [blame] | 1565 | unsigned Align = std::max(TD->getPrefTypeAlignment(Ty1), |
| 1566 | TD->getPrefTypeAlignment(Ty2)); |
| 1567 | |
| 1568 | MachineFrameInfo *FrameInfo = getMachineFunction().getFrameInfo(); |
David Greene | 3f2bf85 | 2009-11-12 20:49:22 +0000 | [diff] [blame] | 1569 | int FrameIdx = FrameInfo->CreateStackObject(Bytes, Align, false); |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 1570 | return getFrameIndex(FrameIdx, TLI->getPointerTy()); |
Duncan Sands | 47d9dcc | 2008-12-09 21:33:20 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1573 | SDValue SelectionDAG::FoldSetCC(EVT VT, SDValue N1, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1574 | SDValue N2, ISD::CondCode Cond, SDLoc dl) { |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1575 | // These setcc operations always fold. |
| 1576 | switch (Cond) { |
| 1577 | default: break; |
| 1578 | case ISD::SETFALSE: |
Chris Lattner | f30b73b | 2005-01-18 02:52:03 +0000 | [diff] [blame] | 1579 | case ISD::SETFALSE2: return getConstant(0, VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1580 | case ISD::SETTRUE: |
Tim Northover | a5eeb9d | 2013-09-06 12:38:12 +0000 | [diff] [blame] | 1581 | case ISD::SETTRUE2: { |
| 1582 | const TargetLowering *TLI = TM.getTargetLowering(); |
| 1583 | TargetLowering::BooleanContent Cnt = TLI->getBooleanContents(VT.isVector()); |
| 1584 | return getConstant( |
| 1585 | Cnt == TargetLowering::ZeroOrNegativeOneBooleanContent ? -1ULL : 1, VT); |
| 1586 | } |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1587 | |
Chris Lattner | a83385f | 2006-04-27 05:01:07 +0000 | [diff] [blame] | 1588 | case ISD::SETOEQ: |
| 1589 | case ISD::SETOGT: |
| 1590 | case ISD::SETOGE: |
| 1591 | case ISD::SETOLT: |
| 1592 | case ISD::SETOLE: |
| 1593 | case ISD::SETONE: |
| 1594 | case ISD::SETO: |
| 1595 | case ISD::SETUO: |
| 1596 | case ISD::SETUEQ: |
| 1597 | case ISD::SETUNE: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1598 | assert(!N1.getValueType().isInteger() && "Illegal setcc for integer!"); |
Chris Lattner | a83385f | 2006-04-27 05:01:07 +0000 | [diff] [blame] | 1599 | break; |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1600 | } |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1601 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1602 | if (ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2.getNode())) { |
Dan Gohman | 6c23150 | 2008-02-29 01:47:35 +0000 | [diff] [blame] | 1603 | const APInt &C2 = N2C->getAPIntValue(); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1604 | if (ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1.getNode())) { |
Dan Gohman | 6c23150 | 2008-02-29 01:47:35 +0000 | [diff] [blame] | 1605 | const APInt &C1 = N1C->getAPIntValue(); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1606 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1607 | switch (Cond) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1608 | default: llvm_unreachable("Unknown integer setcc!"); |
Chris Lattner | f30b73b | 2005-01-18 02:52:03 +0000 | [diff] [blame] | 1609 | case ISD::SETEQ: return getConstant(C1 == C2, VT); |
| 1610 | case ISD::SETNE: return getConstant(C1 != C2, VT); |
Dan Gohman | 6c23150 | 2008-02-29 01:47:35 +0000 | [diff] [blame] | 1611 | case ISD::SETULT: return getConstant(C1.ult(C2), VT); |
| 1612 | case ISD::SETUGT: return getConstant(C1.ugt(C2), VT); |
| 1613 | case ISD::SETULE: return getConstant(C1.ule(C2), VT); |
| 1614 | case ISD::SETUGE: return getConstant(C1.uge(C2), VT); |
| 1615 | case ISD::SETLT: return getConstant(C1.slt(C2), VT); |
| 1616 | case ISD::SETGT: return getConstant(C1.sgt(C2), VT); |
| 1617 | case ISD::SETLE: return getConstant(C1.sle(C2), VT); |
| 1618 | case ISD::SETGE: return getConstant(C1.sge(C2), VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1619 | } |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1620 | } |
Chris Lattner | 67255a1 | 2005-04-07 18:14:58 +0000 | [diff] [blame] | 1621 | } |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1622 | if (ConstantFPSDNode *N1C = dyn_cast<ConstantFPSDNode>(N1.getNode())) { |
| 1623 | if (ConstantFPSDNode *N2C = dyn_cast<ConstantFPSDNode>(N2.getNode())) { |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 1624 | APFloat::cmpResult R = N1C->getValueAPF().compare(N2C->getValueAPF()); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1625 | switch (Cond) { |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 1626 | default: break; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1627 | case ISD::SETEQ: if (R==APFloat::cmpUnordered) |
Dale Johannesen | e8d7230 | 2009-02-06 23:05:02 +0000 | [diff] [blame] | 1628 | return getUNDEF(VT); |
Dale Johannesen | ee84768 | 2007-08-31 17:03:33 +0000 | [diff] [blame] | 1629 | // fall through |
| 1630 | case ISD::SETOEQ: return getConstant(R==APFloat::cmpEqual, VT); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1631 | case ISD::SETNE: if (R==APFloat::cmpUnordered) |
Dale Johannesen | e8d7230 | 2009-02-06 23:05:02 +0000 | [diff] [blame] | 1632 | return getUNDEF(VT); |
Dale Johannesen | ee84768 | 2007-08-31 17:03:33 +0000 | [diff] [blame] | 1633 | // fall through |
| 1634 | case ISD::SETONE: return getConstant(R==APFloat::cmpGreaterThan || |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 1635 | R==APFloat::cmpLessThan, VT); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1636 | case ISD::SETLT: if (R==APFloat::cmpUnordered) |
Dale Johannesen | e8d7230 | 2009-02-06 23:05:02 +0000 | [diff] [blame] | 1637 | return getUNDEF(VT); |
Dale Johannesen | ee84768 | 2007-08-31 17:03:33 +0000 | [diff] [blame] | 1638 | // fall through |
| 1639 | case ISD::SETOLT: return getConstant(R==APFloat::cmpLessThan, VT); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1640 | case ISD::SETGT: if (R==APFloat::cmpUnordered) |
Dale Johannesen | e8d7230 | 2009-02-06 23:05:02 +0000 | [diff] [blame] | 1641 | return getUNDEF(VT); |
Dale Johannesen | ee84768 | 2007-08-31 17:03:33 +0000 | [diff] [blame] | 1642 | // fall through |
| 1643 | case ISD::SETOGT: return getConstant(R==APFloat::cmpGreaterThan, VT); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1644 | case ISD::SETLE: if (R==APFloat::cmpUnordered) |
Dale Johannesen | e8d7230 | 2009-02-06 23:05:02 +0000 | [diff] [blame] | 1645 | return getUNDEF(VT); |
Dale Johannesen | ee84768 | 2007-08-31 17:03:33 +0000 | [diff] [blame] | 1646 | // fall through |
| 1647 | case ISD::SETOLE: return getConstant(R==APFloat::cmpLessThan || |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 1648 | R==APFloat::cmpEqual, VT); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1649 | case ISD::SETGE: if (R==APFloat::cmpUnordered) |
Dale Johannesen | e8d7230 | 2009-02-06 23:05:02 +0000 | [diff] [blame] | 1650 | return getUNDEF(VT); |
Dale Johannesen | ee84768 | 2007-08-31 17:03:33 +0000 | [diff] [blame] | 1651 | // fall through |
| 1652 | case ISD::SETOGE: return getConstant(R==APFloat::cmpGreaterThan || |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 1653 | R==APFloat::cmpEqual, VT); |
| 1654 | case ISD::SETO: return getConstant(R!=APFloat::cmpUnordered, VT); |
| 1655 | case ISD::SETUO: return getConstant(R==APFloat::cmpUnordered, VT); |
| 1656 | case ISD::SETUEQ: return getConstant(R==APFloat::cmpUnordered || |
| 1657 | R==APFloat::cmpEqual, VT); |
| 1658 | case ISD::SETUNE: return getConstant(R!=APFloat::cmpEqual, VT); |
| 1659 | case ISD::SETULT: return getConstant(R==APFloat::cmpUnordered || |
| 1660 | R==APFloat::cmpLessThan, VT); |
| 1661 | case ISD::SETUGT: return getConstant(R==APFloat::cmpGreaterThan || |
| 1662 | R==APFloat::cmpUnordered, VT); |
| 1663 | case ISD::SETULE: return getConstant(R!=APFloat::cmpGreaterThan, VT); |
| 1664 | case ISD::SETUGE: return getConstant(R!=APFloat::cmpLessThan, VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1665 | } |
| 1666 | } else { |
| 1667 | // Ensure that the constant occurs on the RHS. |
Tom Stellard | 12d43f9 | 2013-09-28 02:50:38 +0000 | [diff] [blame] | 1668 | ISD::CondCode SwappedCond = ISD::getSetCCSwappedOperands(Cond); |
| 1669 | MVT CompVT = N1.getValueType().getSimpleVT(); |
| 1670 | if (!TM.getTargetLowering()->isCondCodeLegal(SwappedCond, CompVT)) |
| 1671 | return SDValue(); |
| 1672 | |
| 1673 | return getSetCC(dl, VT, N2, N1, SwappedCond); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1674 | } |
Anton Korobeynikov | 4c71dfe | 2008-02-20 11:10:28 +0000 | [diff] [blame] | 1675 | } |
| 1676 | |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 1677 | // Could not fold it. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1678 | return SDValue(); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1679 | } |
| 1680 | |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1681 | /// SignBitIsZero - Return true if the sign bit of Op is known to be zero. We |
| 1682 | /// use this predicate to simplify operations downstream. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1683 | bool SelectionDAG::SignBitIsZero(SDValue Op, unsigned Depth) const { |
Chris Lattner | a4f7318 | 2009-07-07 23:28:46 +0000 | [diff] [blame] | 1684 | // This predicate is not safe for vector operations. |
| 1685 | if (Op.getValueType().isVector()) |
| 1686 | return false; |
Eric Christopher | 4d7c18c | 2009-08-22 00:40:45 +0000 | [diff] [blame] | 1687 | |
Dan Gohman | 87862e7 | 2009-12-11 21:31:27 +0000 | [diff] [blame] | 1688 | unsigned BitWidth = Op.getValueType().getScalarType().getSizeInBits(); |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1689 | return MaskedValueIsZero(Op, APInt::getSignBit(BitWidth), Depth); |
| 1690 | } |
| 1691 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1692 | /// MaskedValueIsZero - Return true if 'V & Mask' is known to be zero. We use |
| 1693 | /// this predicate to simplify operations downstream. Mask is known to be zero |
| 1694 | /// for bits that V cannot have. |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1695 | bool SelectionDAG::MaskedValueIsZero(SDValue Op, const APInt &Mask, |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1696 | unsigned Depth) const { |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1697 | APInt KnownZero, KnownOne; |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1698 | ComputeMaskedBits(Op, KnownZero, KnownOne, Depth); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1699 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1700 | return (KnownZero & Mask) == Mask; |
| 1701 | } |
| 1702 | |
| 1703 | /// ComputeMaskedBits - Determine which of the bits specified in Mask are |
| 1704 | /// known to be either zero or one and return them in the KnownZero/KnownOne |
| 1705 | /// bitsets. This code only analyzes bits in Mask, in order to short-circuit |
| 1706 | /// processing. |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1707 | void SelectionDAG::ComputeMaskedBits(SDValue Op, APInt &KnownZero, |
| 1708 | APInt &KnownOne, unsigned Depth) const { |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 1709 | const TargetLowering *TLI = TM.getTargetLowering(); |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1710 | unsigned BitWidth = Op.getValueType().getScalarType().getSizeInBits(); |
Dan Gohman | d9fe41c | 2008-02-13 23:13:32 +0000 | [diff] [blame] | 1711 | |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 1712 | KnownZero = KnownOne = APInt(BitWidth, 0); // Don't know anything. |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1713 | if (Depth == 6) |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1714 | return; // Limit search depth. |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1715 | |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 1716 | APInt KnownZero2, KnownOne2; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1717 | |
| 1718 | switch (Op.getOpcode()) { |
| 1719 | case ISD::Constant: |
| 1720 | // We know all of the bits for a constant! |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1721 | KnownOne = cast<ConstantSDNode>(Op)->getAPIntValue(); |
| 1722 | KnownZero = ~KnownOne; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1723 | return; |
| 1724 | case ISD::AND: |
| 1725 | // If either the LHS or the RHS are Zero, the result is zero. |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1726 | ComputeMaskedBits(Op.getOperand(1), KnownZero, KnownOne, Depth+1); |
| 1727 | ComputeMaskedBits(Op.getOperand(0), KnownZero2, KnownOne2, Depth+1); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1728 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
| 1729 | assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1730 | |
| 1731 | // Output known-1 bits are only known if set in both the LHS & RHS. |
| 1732 | KnownOne &= KnownOne2; |
| 1733 | // Output known-0 are known to be clear if zero in either the LHS | RHS. |
| 1734 | KnownZero |= KnownZero2; |
| 1735 | return; |
| 1736 | case ISD::OR: |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1737 | ComputeMaskedBits(Op.getOperand(1), KnownZero, KnownOne, Depth+1); |
| 1738 | ComputeMaskedBits(Op.getOperand(0), KnownZero2, KnownOne2, Depth+1); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1739 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
| 1740 | assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); |
| 1741 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1742 | // Output known-0 bits are only known if clear in both the LHS & RHS. |
| 1743 | KnownZero &= KnownZero2; |
| 1744 | // Output known-1 are known to be set if set in either the LHS | RHS. |
| 1745 | KnownOne |= KnownOne2; |
| 1746 | return; |
| 1747 | case ISD::XOR: { |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1748 | ComputeMaskedBits(Op.getOperand(1), KnownZero, KnownOne, Depth+1); |
| 1749 | ComputeMaskedBits(Op.getOperand(0), KnownZero2, KnownOne2, Depth+1); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1750 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
| 1751 | assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); |
| 1752 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1753 | // Output known-0 bits are known if clear or set in both the LHS & RHS. |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 1754 | APInt KnownZeroOut = (KnownZero & KnownZero2) | (KnownOne & KnownOne2); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1755 | // Output known-1 are known to be set if set in only one of the LHS, RHS. |
| 1756 | KnownOne = (KnownZero & KnownOne2) | (KnownOne & KnownZero2); |
| 1757 | KnownZero = KnownZeroOut; |
| 1758 | return; |
| 1759 | } |
Dan Gohman | 23e8b71 | 2008-04-28 17:02:21 +0000 | [diff] [blame] | 1760 | case ISD::MUL: { |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1761 | ComputeMaskedBits(Op.getOperand(1), KnownZero, KnownOne, Depth+1); |
| 1762 | ComputeMaskedBits(Op.getOperand(0), KnownZero2, KnownOne2, Depth+1); |
Dan Gohman | 23e8b71 | 2008-04-28 17:02:21 +0000 | [diff] [blame] | 1763 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
| 1764 | assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); |
| 1765 | |
| 1766 | // If low bits are zero in either operand, output low known-0 bits. |
| 1767 | // Also compute a conserative estimate for high known-0 bits. |
| 1768 | // More trickiness is possible, but this is sufficient for the |
| 1769 | // interesting case of alignment computation. |
Jay Foad | 7a874dd | 2010-12-01 08:53:58 +0000 | [diff] [blame] | 1770 | KnownOne.clearAllBits(); |
Dan Gohman | 23e8b71 | 2008-04-28 17:02:21 +0000 | [diff] [blame] | 1771 | unsigned TrailZ = KnownZero.countTrailingOnes() + |
| 1772 | KnownZero2.countTrailingOnes(); |
| 1773 | unsigned LeadZ = std::max(KnownZero.countLeadingOnes() + |
Dan Gohman | 42ac929 | 2008-05-07 00:35:55 +0000 | [diff] [blame] | 1774 | KnownZero2.countLeadingOnes(), |
| 1775 | BitWidth) - BitWidth; |
Dan Gohman | 23e8b71 | 2008-04-28 17:02:21 +0000 | [diff] [blame] | 1776 | |
| 1777 | TrailZ = std::min(TrailZ, BitWidth); |
| 1778 | LeadZ = std::min(LeadZ, BitWidth); |
| 1779 | KnownZero = APInt::getLowBitsSet(BitWidth, TrailZ) | |
| 1780 | APInt::getHighBitsSet(BitWidth, LeadZ); |
Dan Gohman | 23e8b71 | 2008-04-28 17:02:21 +0000 | [diff] [blame] | 1781 | return; |
| 1782 | } |
| 1783 | case ISD::UDIV: { |
| 1784 | // For the purposes of computing leading zeros we can conservatively |
| 1785 | // treat a udiv as a logical right shift by the power of 2 known to |
Dan Gohman | 1d9cd50 | 2008-05-02 21:30:02 +0000 | [diff] [blame] | 1786 | // be less than the denominator. |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1787 | ComputeMaskedBits(Op.getOperand(0), KnownZero2, KnownOne2, Depth+1); |
Dan Gohman | 23e8b71 | 2008-04-28 17:02:21 +0000 | [diff] [blame] | 1788 | unsigned LeadZ = KnownZero2.countLeadingOnes(); |
| 1789 | |
Jay Foad | 7a874dd | 2010-12-01 08:53:58 +0000 | [diff] [blame] | 1790 | KnownOne2.clearAllBits(); |
| 1791 | KnownZero2.clearAllBits(); |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1792 | ComputeMaskedBits(Op.getOperand(1), KnownZero2, KnownOne2, Depth+1); |
Dan Gohman | 1d9cd50 | 2008-05-02 21:30:02 +0000 | [diff] [blame] | 1793 | unsigned RHSUnknownLeadingOnes = KnownOne2.countLeadingZeros(); |
| 1794 | if (RHSUnknownLeadingOnes != BitWidth) |
| 1795 | LeadZ = std::min(BitWidth, |
| 1796 | LeadZ + BitWidth - RHSUnknownLeadingOnes - 1); |
Dan Gohman | 23e8b71 | 2008-04-28 17:02:21 +0000 | [diff] [blame] | 1797 | |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1798 | KnownZero = APInt::getHighBitsSet(BitWidth, LeadZ); |
Dan Gohman | 23e8b71 | 2008-04-28 17:02:21 +0000 | [diff] [blame] | 1799 | return; |
| 1800 | } |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1801 | case ISD::SELECT: |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1802 | ComputeMaskedBits(Op.getOperand(2), KnownZero, KnownOne, Depth+1); |
| 1803 | ComputeMaskedBits(Op.getOperand(1), KnownZero2, KnownOne2, Depth+1); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1804 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
| 1805 | assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); |
| 1806 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1807 | // Only known if known in both the LHS and RHS. |
| 1808 | KnownOne &= KnownOne2; |
| 1809 | KnownZero &= KnownZero2; |
| 1810 | return; |
| 1811 | case ISD::SELECT_CC: |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1812 | ComputeMaskedBits(Op.getOperand(3), KnownZero, KnownOne, Depth+1); |
| 1813 | ComputeMaskedBits(Op.getOperand(2), KnownZero2, KnownOne2, Depth+1); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1814 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
| 1815 | assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); |
| 1816 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1817 | // Only known if known in both the LHS and RHS. |
| 1818 | KnownOne &= KnownOne2; |
| 1819 | KnownZero &= KnownZero2; |
| 1820 | return; |
Bill Wendling | 253174b | 2008-11-22 07:24:01 +0000 | [diff] [blame] | 1821 | case ISD::SADDO: |
| 1822 | case ISD::UADDO: |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 1823 | case ISD::SSUBO: |
| 1824 | case ISD::USUBO: |
| 1825 | case ISD::SMULO: |
| 1826 | case ISD::UMULO: |
Bill Wendling | 253174b | 2008-11-22 07:24:01 +0000 | [diff] [blame] | 1827 | if (Op.getResNo() != 1) |
| 1828 | return; |
Duncan Sands | 0322808 | 2008-11-23 15:47:28 +0000 | [diff] [blame] | 1829 | // The boolean result conforms to getBooleanContents. Fall through. |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1830 | case ISD::SETCC: |
| 1831 | // If we know the result of a setcc has the top bits zero, use this info. |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 1832 | if (TLI->getBooleanContents(Op.getValueType().isVector()) == |
Duncan Sands | 28b77e9 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 1833 | TargetLowering::ZeroOrOneBooleanContent && BitWidth > 1) |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 1834 | KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - 1); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1835 | return; |
| 1836 | case ISD::SHL: |
Sylvestre Ledru | 94c2271 | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 1837 | // (shl X, C1) & C2 == 0 iff (X & C2 >>u C1) == 0 |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1838 | if (ConstantSDNode *SA = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1839 | unsigned ShAmt = SA->getZExtValue(); |
Dan Gohman | d4cf992 | 2008-02-26 18:50:50 +0000 | [diff] [blame] | 1840 | |
| 1841 | // If the shift count is an invalid immediate, don't do anything. |
| 1842 | if (ShAmt >= BitWidth) |
| 1843 | return; |
| 1844 | |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1845 | ComputeMaskedBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1846 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
Dan Gohman | d4cf992 | 2008-02-26 18:50:50 +0000 | [diff] [blame] | 1847 | KnownZero <<= ShAmt; |
| 1848 | KnownOne <<= ShAmt; |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 1849 | // low bits known zero. |
Dan Gohman | d4cf992 | 2008-02-26 18:50:50 +0000 | [diff] [blame] | 1850 | KnownZero |= APInt::getLowBitsSet(BitWidth, ShAmt); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1851 | } |
| 1852 | return; |
| 1853 | case ISD::SRL: |
Sylvestre Ledru | 94c2271 | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 1854 | // (ushr X, C1) & C2 == 0 iff (-1 >> C1) & C2 == 0 |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1855 | if (ConstantSDNode *SA = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1856 | unsigned ShAmt = SA->getZExtValue(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1857 | |
Dan Gohman | d4cf992 | 2008-02-26 18:50:50 +0000 | [diff] [blame] | 1858 | // If the shift count is an invalid immediate, don't do anything. |
| 1859 | if (ShAmt >= BitWidth) |
| 1860 | return; |
| 1861 | |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1862 | ComputeMaskedBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1863 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 1864 | KnownZero = KnownZero.lshr(ShAmt); |
| 1865 | KnownOne = KnownOne.lshr(ShAmt); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1866 | |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1867 | APInt HighBits = APInt::getHighBitsSet(BitWidth, ShAmt); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1868 | KnownZero |= HighBits; // High bits known zero. |
| 1869 | } |
| 1870 | return; |
| 1871 | case ISD::SRA: |
| 1872 | if (ConstantSDNode *SA = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1873 | unsigned ShAmt = SA->getZExtValue(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1874 | |
Dan Gohman | d4cf992 | 2008-02-26 18:50:50 +0000 | [diff] [blame] | 1875 | // If the shift count is an invalid immediate, don't do anything. |
| 1876 | if (ShAmt >= BitWidth) |
| 1877 | return; |
| 1878 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1879 | // If any of the demanded bits are produced by the sign extension, we also |
| 1880 | // demand the input sign bit. |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1881 | APInt HighBits = APInt::getHighBitsSet(BitWidth, ShAmt); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1882 | |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1883 | ComputeMaskedBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1884 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 1885 | KnownZero = KnownZero.lshr(ShAmt); |
| 1886 | KnownOne = KnownOne.lshr(ShAmt); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1887 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1888 | // Handle the sign bits. |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 1889 | APInt SignBit = APInt::getSignBit(BitWidth); |
| 1890 | SignBit = SignBit.lshr(ShAmt); // Adjust to where it is now in the mask. |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1891 | |
Dan Gohman | ca93a43 | 2008-02-20 16:30:17 +0000 | [diff] [blame] | 1892 | if (KnownZero.intersects(SignBit)) { |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1893 | KnownZero |= HighBits; // New bits are known zero. |
Dan Gohman | ca93a43 | 2008-02-20 16:30:17 +0000 | [diff] [blame] | 1894 | } else if (KnownOne.intersects(SignBit)) { |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1895 | KnownOne |= HighBits; // New bits are known one. |
| 1896 | } |
| 1897 | } |
| 1898 | return; |
| 1899 | case ISD::SIGN_EXTEND_INREG: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1900 | EVT EVT = cast<VTSDNode>(Op.getOperand(1))->getVT(); |
Dan Gohman | d199636 | 2010-01-09 02:13:55 +0000 | [diff] [blame] | 1901 | unsigned EBits = EVT.getScalarType().getSizeInBits(); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1902 | |
| 1903 | // Sign extension. Compute the demanded bits in the result that are not |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1904 | // present in the input. |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1905 | APInt NewBits = APInt::getHighBitsSet(BitWidth, BitWidth - EBits); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1906 | |
Dan Gohman | 977a76f | 2008-02-13 22:28:48 +0000 | [diff] [blame] | 1907 | APInt InSignBit = APInt::getSignBit(EBits); |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1908 | APInt InputDemandedBits = APInt::getLowBitsSet(BitWidth, EBits); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1909 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1910 | // If the sign extended bits are demanded, we know that the sign |
| 1911 | // bit is demanded. |
Jay Foad | 40f8f62 | 2010-12-07 08:25:19 +0000 | [diff] [blame] | 1912 | InSignBit = InSignBit.zext(BitWidth); |
Dan Gohman | 977a76f | 2008-02-13 22:28:48 +0000 | [diff] [blame] | 1913 | if (NewBits.getBoolValue()) |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1914 | InputDemandedBits |= InSignBit; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1915 | |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1916 | ComputeMaskedBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1); |
| 1917 | KnownOne &= InputDemandedBits; |
| 1918 | KnownZero &= InputDemandedBits; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1919 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
| 1920 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1921 | // If the sign bit of the input is known set or clear, then we know the |
| 1922 | // top bits of the result. |
Dan Gohman | ca93a43 | 2008-02-20 16:30:17 +0000 | [diff] [blame] | 1923 | if (KnownZero.intersects(InSignBit)) { // Input sign bit known clear |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1924 | KnownZero |= NewBits; |
| 1925 | KnownOne &= ~NewBits; |
Dan Gohman | ca93a43 | 2008-02-20 16:30:17 +0000 | [diff] [blame] | 1926 | } else if (KnownOne.intersects(InSignBit)) { // Input sign bit known set |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1927 | KnownOne |= NewBits; |
| 1928 | KnownZero &= ~NewBits; |
| 1929 | } else { // Input sign bit unknown |
| 1930 | KnownZero &= ~NewBits; |
| 1931 | KnownOne &= ~NewBits; |
| 1932 | } |
| 1933 | return; |
| 1934 | } |
| 1935 | case ISD::CTTZ: |
Chandler Carruth | 63974b2 | 2011-12-13 01:56:10 +0000 | [diff] [blame] | 1936 | case ISD::CTTZ_ZERO_UNDEF: |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1937 | case ISD::CTLZ: |
Chandler Carruth | 63974b2 | 2011-12-13 01:56:10 +0000 | [diff] [blame] | 1938 | case ISD::CTLZ_ZERO_UNDEF: |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1939 | case ISD::CTPOP: { |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 1940 | unsigned LowBits = Log2_32(BitWidth)+1; |
| 1941 | KnownZero = APInt::getHighBitsSet(BitWidth, BitWidth - LowBits); |
Jay Foad | 7a874dd | 2010-12-01 08:53:58 +0000 | [diff] [blame] | 1942 | KnownOne.clearAllBits(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1943 | return; |
| 1944 | } |
| 1945 | case ISD::LOAD: { |
Rafael Espindola | 95d594c | 2012-03-31 18:14:00 +0000 | [diff] [blame] | 1946 | LoadSDNode *LD = cast<LoadSDNode>(Op); |
Nadav Rotem | 7745175 | 2013-03-20 22:53:44 +0000 | [diff] [blame] | 1947 | // If this is a ZEXTLoad and we are looking at the loaded value. |
| 1948 | if (ISD::isZEXTLoad(Op.getNode()) && Op.getResNo() == 0) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1949 | EVT VT = LD->getMemoryVT(); |
Dan Gohman | d199636 | 2010-01-09 02:13:55 +0000 | [diff] [blame] | 1950 | unsigned MemBits = VT.getScalarType().getSizeInBits(); |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1951 | KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - MemBits); |
Rafael Espindola | 95d594c | 2012-03-31 18:14:00 +0000 | [diff] [blame] | 1952 | } else if (const MDNode *Ranges = LD->getRanges()) { |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1953 | computeMaskedBitsLoad(*Ranges, KnownZero); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1954 | } |
| 1955 | return; |
| 1956 | } |
| 1957 | case ISD::ZERO_EXTEND: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1958 | EVT InVT = Op.getOperand(0).getValueType(); |
Dan Gohman | 87862e7 | 2009-12-11 21:31:27 +0000 | [diff] [blame] | 1959 | unsigned InBits = InVT.getScalarType().getSizeInBits(); |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1960 | APInt NewBits = APInt::getHighBitsSet(BitWidth, BitWidth - InBits); |
Jay Foad | 40f8f62 | 2010-12-07 08:25:19 +0000 | [diff] [blame] | 1961 | KnownZero = KnownZero.trunc(InBits); |
| 1962 | KnownOne = KnownOne.trunc(InBits); |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1963 | ComputeMaskedBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1); |
Jay Foad | 40f8f62 | 2010-12-07 08:25:19 +0000 | [diff] [blame] | 1964 | KnownZero = KnownZero.zext(BitWidth); |
| 1965 | KnownOne = KnownOne.zext(BitWidth); |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 1966 | KnownZero |= NewBits; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1967 | return; |
| 1968 | } |
| 1969 | case ISD::SIGN_EXTEND: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1970 | EVT InVT = Op.getOperand(0).getValueType(); |
Dan Gohman | 87862e7 | 2009-12-11 21:31:27 +0000 | [diff] [blame] | 1971 | unsigned InBits = InVT.getScalarType().getSizeInBits(); |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1972 | APInt NewBits = APInt::getHighBitsSet(BitWidth, BitWidth - InBits); |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 1973 | |
Jay Foad | 40f8f62 | 2010-12-07 08:25:19 +0000 | [diff] [blame] | 1974 | KnownZero = KnownZero.trunc(InBits); |
| 1975 | KnownOne = KnownOne.trunc(InBits); |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 1976 | ComputeMaskedBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1); |
Dan Gohman | 977a76f | 2008-02-13 22:28:48 +0000 | [diff] [blame] | 1977 | |
| 1978 | // Note if the sign bit is known to be zero or one. |
| 1979 | bool SignBitKnownZero = KnownZero.isNegative(); |
| 1980 | bool SignBitKnownOne = KnownOne.isNegative(); |
| 1981 | assert(!(SignBitKnownZero && SignBitKnownOne) && |
| 1982 | "Sign bit can't be known to be both zero and one!"); |
| 1983 | |
Jay Foad | 40f8f62 | 2010-12-07 08:25:19 +0000 | [diff] [blame] | 1984 | KnownZero = KnownZero.zext(BitWidth); |
| 1985 | KnownOne = KnownOne.zext(BitWidth); |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 1986 | |
Dan Gohman | 977a76f | 2008-02-13 22:28:48 +0000 | [diff] [blame] | 1987 | // If the sign bit is known zero or one, the top bits match. |
| 1988 | if (SignBitKnownZero) |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1989 | KnownZero |= NewBits; |
Dan Gohman | 977a76f | 2008-02-13 22:28:48 +0000 | [diff] [blame] | 1990 | else if (SignBitKnownOne) |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1991 | KnownOne |= NewBits; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1992 | return; |
| 1993 | } |
| 1994 | case ISD::ANY_EXTEND: { |
Evan Cheng | 2766a47 | 2012-12-06 19:13:27 +0000 | [diff] [blame] | 1995 | EVT InVT = Op.getOperand(0).getValueType(); |
| 1996 | unsigned InBits = InVT.getScalarType().getSizeInBits(); |
| 1997 | KnownZero = KnownZero.trunc(InBits); |
| 1998 | KnownOne = KnownOne.trunc(InBits); |
| 1999 | ComputeMaskedBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1); |
| 2000 | KnownZero = KnownZero.zext(BitWidth); |
| 2001 | KnownOne = KnownOne.zext(BitWidth); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2002 | return; |
| 2003 | } |
| 2004 | case ISD::TRUNCATE: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2005 | EVT InVT = Op.getOperand(0).getValueType(); |
Dan Gohman | 87862e7 | 2009-12-11 21:31:27 +0000 | [diff] [blame] | 2006 | unsigned InBits = InVT.getScalarType().getSizeInBits(); |
Jay Foad | 40f8f62 | 2010-12-07 08:25:19 +0000 | [diff] [blame] | 2007 | KnownZero = KnownZero.zext(InBits); |
| 2008 | KnownOne = KnownOne.zext(InBits); |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 2009 | ComputeMaskedBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2010 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
Jay Foad | 40f8f62 | 2010-12-07 08:25:19 +0000 | [diff] [blame] | 2011 | KnownZero = KnownZero.trunc(BitWidth); |
| 2012 | KnownOne = KnownOne.trunc(BitWidth); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2013 | break; |
| 2014 | } |
| 2015 | case ISD::AssertZext: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2016 | EVT VT = cast<VTSDNode>(Op.getOperand(1))->getVT(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2017 | APInt InMask = APInt::getLowBitsSet(BitWidth, VT.getSizeInBits()); |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 2018 | ComputeMaskedBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1); |
| 2019 | KnownZero |= (~InMask); |
Nadav Rotem | 7ee0e5a | 2012-07-16 18:34:53 +0000 | [diff] [blame] | 2020 | KnownOne &= (~KnownZero); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2021 | return; |
| 2022 | } |
Chris Lattner | d268a49 | 2007-12-22 21:26:52 +0000 | [diff] [blame] | 2023 | case ISD::FGETSIGN: |
| 2024 | // All bits are zero except the low bit. |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 2025 | KnownZero = APInt::getHighBitsSet(BitWidth, BitWidth - 1); |
Chris Lattner | d268a49 | 2007-12-22 21:26:52 +0000 | [diff] [blame] | 2026 | return; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2027 | |
Dan Gohman | 23e8b71 | 2008-04-28 17:02:21 +0000 | [diff] [blame] | 2028 | case ISD::SUB: { |
| 2029 | if (ConstantSDNode *CLHS = dyn_cast<ConstantSDNode>(Op.getOperand(0))) { |
| 2030 | // We know that the top bits of C-X are clear if X contains less bits |
| 2031 | // than C (i.e. no wrap-around can happen). For example, 20-X is |
| 2032 | // positive if we can prove that X is >= 0 and < 16. |
| 2033 | if (CLHS->getAPIntValue().isNonNegative()) { |
| 2034 | unsigned NLZ = (CLHS->getAPIntValue()+1).countLeadingZeros(); |
| 2035 | // NLZ can't be BitWidth with no sign bit |
| 2036 | APInt MaskV = APInt::getHighBitsSet(BitWidth, NLZ+1); |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 2037 | ComputeMaskedBits(Op.getOperand(1), KnownZero2, KnownOne2, Depth+1); |
Dan Gohman | 23e8b71 | 2008-04-28 17:02:21 +0000 | [diff] [blame] | 2038 | |
| 2039 | // If all of the MaskV bits are known to be zero, then we know the |
| 2040 | // output top bits are zero, because we now know that the output is |
| 2041 | // from [0-C]. |
| 2042 | if ((KnownZero2 & MaskV) == MaskV) { |
| 2043 | unsigned NLZ2 = CLHS->getAPIntValue().countLeadingZeros(); |
| 2044 | // Top bits known zero. |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 2045 | KnownZero = APInt::getHighBitsSet(BitWidth, NLZ2); |
Dan Gohman | 23e8b71 | 2008-04-28 17:02:21 +0000 | [diff] [blame] | 2046 | } |
| 2047 | } |
| 2048 | } |
| 2049 | } |
| 2050 | // fall through |
Chris Lattner | da60588 | 2010-12-19 20:38:28 +0000 | [diff] [blame] | 2051 | case ISD::ADD: |
| 2052 | case ISD::ADDE: { |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2053 | // Output known-0 bits are known if clear or set in both the low clear bits |
| 2054 | // common to both LHS & RHS. For example, 8+(X<<3) is known to have the |
| 2055 | // low 3 bits clear. |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 2056 | ComputeMaskedBits(Op.getOperand(0), KnownZero2, KnownOne2, Depth+1); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2057 | assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); |
Dan Gohman | 23e8b71 | 2008-04-28 17:02:21 +0000 | [diff] [blame] | 2058 | unsigned KnownZeroOut = KnownZero2.countTrailingOnes(); |
| 2059 | |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 2060 | ComputeMaskedBits(Op.getOperand(1), KnownZero2, KnownOne2, Depth+1); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2061 | assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); |
Dan Gohman | 23e8b71 | 2008-04-28 17:02:21 +0000 | [diff] [blame] | 2062 | KnownZeroOut = std::min(KnownZeroOut, |
| 2063 | KnownZero2.countTrailingOnes()); |
| 2064 | |
Chris Lattner | da60588 | 2010-12-19 20:38:28 +0000 | [diff] [blame] | 2065 | if (Op.getOpcode() == ISD::ADD) { |
| 2066 | KnownZero |= APInt::getLowBitsSet(BitWidth, KnownZeroOut); |
| 2067 | return; |
| 2068 | } |
| 2069 | |
| 2070 | // With ADDE, a carry bit may be added in, so we can only use this |
| 2071 | // information if we know (at least) that the low two bits are clear. We |
| 2072 | // then return to the caller that the low bit is unknown but that other bits |
| 2073 | // are known zero. |
| 2074 | if (KnownZeroOut >= 2) // ADDE |
| 2075 | KnownZero |= APInt::getBitsSet(BitWidth, 1, KnownZeroOut); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2076 | return; |
| 2077 | } |
Dan Gohman | 23e8b71 | 2008-04-28 17:02:21 +0000 | [diff] [blame] | 2078 | case ISD::SREM: |
| 2079 | if (ConstantSDNode *Rem = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { |
Duncan Sands | 5c2873a | 2010-01-29 09:45:26 +0000 | [diff] [blame] | 2080 | const APInt &RA = Rem->getAPIntValue().abs(); |
| 2081 | if (RA.isPowerOf2()) { |
| 2082 | APInt LowBits = RA - 1; |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 2083 | ComputeMaskedBits(Op.getOperand(0), KnownZero2,KnownOne2,Depth+1); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2084 | |
Duncan Sands | 5c2873a | 2010-01-29 09:45:26 +0000 | [diff] [blame] | 2085 | // The low bits of the first operand are unchanged by the srem. |
| 2086 | KnownZero = KnownZero2 & LowBits; |
| 2087 | KnownOne = KnownOne2 & LowBits; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2088 | |
Duncan Sands | 5c2873a | 2010-01-29 09:45:26 +0000 | [diff] [blame] | 2089 | // If the first operand is non-negative or has all low bits zero, then |
| 2090 | // the upper bits are all zero. |
| 2091 | if (KnownZero2[BitWidth-1] || ((KnownZero2 & LowBits) == LowBits)) |
| 2092 | KnownZero |= ~LowBits; |
| 2093 | |
| 2094 | // If the first operand is negative and not all low bits are zero, then |
| 2095 | // the upper bits are all one. |
| 2096 | if (KnownOne2[BitWidth-1] && ((KnownOne2 & LowBits) != 0)) |
| 2097 | KnownOne |= ~LowBits; |
Dan Gohman | 23e8b71 | 2008-04-28 17:02:21 +0000 | [diff] [blame] | 2098 | assert((KnownZero & KnownOne) == 0&&"Bits known to be one AND zero?"); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2099 | } |
| 2100 | } |
| 2101 | return; |
Dan Gohman | 23e8b71 | 2008-04-28 17:02:21 +0000 | [diff] [blame] | 2102 | case ISD::UREM: { |
| 2103 | if (ConstantSDNode *Rem = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { |
Dan Gohman | 9b44c1f | 2008-07-03 00:52:03 +0000 | [diff] [blame] | 2104 | const APInt &RA = Rem->getAPIntValue(); |
Dan Gohman | 23e1df8 | 2008-05-06 00:51:48 +0000 | [diff] [blame] | 2105 | if (RA.isPowerOf2()) { |
| 2106 | APInt LowBits = (RA - 1); |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 2107 | KnownZero |= ~LowBits; |
| 2108 | ComputeMaskedBits(Op.getOperand(0), KnownZero, KnownOne,Depth+1); |
Dan Gohman | 23e8b71 | 2008-04-28 17:02:21 +0000 | [diff] [blame] | 2109 | assert((KnownZero & KnownOne) == 0&&"Bits known to be one AND zero?"); |
| 2110 | break; |
| 2111 | } |
| 2112 | } |
| 2113 | |
| 2114 | // Since the result is less than or equal to either operand, any leading |
| 2115 | // zero bits in either operand must also exist in the result. |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 2116 | ComputeMaskedBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1); |
| 2117 | ComputeMaskedBits(Op.getOperand(1), KnownZero2, KnownOne2, Depth+1); |
Dan Gohman | 23e8b71 | 2008-04-28 17:02:21 +0000 | [diff] [blame] | 2118 | |
| 2119 | uint32_t Leaders = std::max(KnownZero.countLeadingOnes(), |
| 2120 | KnownZero2.countLeadingOnes()); |
Jay Foad | 7a874dd | 2010-12-01 08:53:58 +0000 | [diff] [blame] | 2121 | KnownOne.clearAllBits(); |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 2122 | KnownZero = APInt::getHighBitsSet(BitWidth, Leaders); |
Dan Gohman | 23e8b71 | 2008-04-28 17:02:21 +0000 | [diff] [blame] | 2123 | return; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2124 | } |
Chris Lattner | 0a9481f | 2011-02-13 22:25:43 +0000 | [diff] [blame] | 2125 | case ISD::FrameIndex: |
| 2126 | case ISD::TargetFrameIndex: |
| 2127 | if (unsigned Align = InferPtrAlignment(Op)) { |
| 2128 | // The low bits are known zero if the pointer is aligned. |
| 2129 | KnownZero = APInt::getLowBitsSet(BitWidth, Log2_32(Align)); |
| 2130 | return; |
| 2131 | } |
| 2132 | break; |
Owen Anderson | 95771af | 2011-02-25 21:41:48 +0000 | [diff] [blame] | 2133 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2134 | default: |
Evan Cheng | b5a55d9 | 2011-05-24 01:48:22 +0000 | [diff] [blame] | 2135 | if (Op.getOpcode() < ISD::BUILTIN_OP_END) |
| 2136 | break; |
| 2137 | // Fallthrough |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2138 | case ISD::INTRINSIC_WO_CHAIN: |
| 2139 | case ISD::INTRINSIC_W_CHAIN: |
| 2140 | case ISD::INTRINSIC_VOID: |
Evan Cheng | b5a55d9 | 2011-05-24 01:48:22 +0000 | [diff] [blame] | 2141 | // Allow the target to implement this method for its nodes. |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 2142 | TLI->computeMaskedBitsForTargetNode(Op, KnownZero, KnownOne, *this, Depth); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2143 | return; |
| 2144 | } |
| 2145 | } |
| 2146 | |
| 2147 | /// ComputeNumSignBits - Return the number of times the sign bit of the |
| 2148 | /// register is replicated into the other bits. We know that at least 1 bit |
| 2149 | /// is always equal to the sign bit (itself), but other cases can give us |
| 2150 | /// information. For example, immediately after an "SRA X, 2", we know that |
| 2151 | /// the top 3 bits are all equal to each other, so we return 3. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2152 | unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, unsigned Depth) const{ |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 2153 | const TargetLowering *TLI = TM.getTargetLowering(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2154 | EVT VT = Op.getValueType(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2155 | assert(VT.isInteger() && "Invalid VT!"); |
Dan Gohman | 87862e7 | 2009-12-11 21:31:27 +0000 | [diff] [blame] | 2156 | unsigned VTBits = VT.getScalarType().getSizeInBits(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2157 | unsigned Tmp, Tmp2; |
Dan Gohman | a332f17 | 2008-05-23 02:28:01 +0000 | [diff] [blame] | 2158 | unsigned FirstAnswer = 1; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2159 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2160 | if (Depth == 6) |
| 2161 | return 1; // Limit search depth. |
| 2162 | |
| 2163 | switch (Op.getOpcode()) { |
| 2164 | default: break; |
| 2165 | case ISD::AssertSext: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2166 | Tmp = cast<VTSDNode>(Op.getOperand(1))->getVT().getSizeInBits(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2167 | return VTBits-Tmp+1; |
| 2168 | case ISD::AssertZext: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2169 | Tmp = cast<VTSDNode>(Op.getOperand(1))->getVT().getSizeInBits(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2170 | return VTBits-Tmp; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2171 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2172 | case ISD::Constant: { |
Dan Gohman | bb271ff | 2008-03-03 23:35:36 +0000 | [diff] [blame] | 2173 | const APInt &Val = cast<ConstantSDNode>(Op)->getAPIntValue(); |
Cameron Zwarich | 9b6af8d | 2011-02-24 10:00:20 +0000 | [diff] [blame] | 2174 | return Val.getNumSignBits(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2175 | } |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2176 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2177 | case ISD::SIGN_EXTEND: |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 2178 | Tmp = |
| 2179 | VTBits-Op.getOperand(0).getValueType().getScalarType().getSizeInBits(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2180 | return ComputeNumSignBits(Op.getOperand(0), Depth+1) + Tmp; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2181 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2182 | case ISD::SIGN_EXTEND_INREG: |
| 2183 | // Max of the input and what this extends. |
Dan Gohman | d199636 | 2010-01-09 02:13:55 +0000 | [diff] [blame] | 2184 | Tmp = |
| 2185 | cast<VTSDNode>(Op.getOperand(1))->getVT().getScalarType().getSizeInBits(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2186 | Tmp = VTBits-Tmp+1; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2187 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2188 | Tmp2 = ComputeNumSignBits(Op.getOperand(0), Depth+1); |
| 2189 | return std::max(Tmp, Tmp2); |
| 2190 | |
| 2191 | case ISD::SRA: |
| 2192 | Tmp = ComputeNumSignBits(Op.getOperand(0), Depth+1); |
| 2193 | // SRA X, C -> adds C sign bits. |
| 2194 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2195 | Tmp += C->getZExtValue(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2196 | if (Tmp > VTBits) Tmp = VTBits; |
| 2197 | } |
| 2198 | return Tmp; |
| 2199 | case ISD::SHL: |
| 2200 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { |
| 2201 | // shl destroys sign bits. |
| 2202 | Tmp = ComputeNumSignBits(Op.getOperand(0), Depth+1); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2203 | if (C->getZExtValue() >= VTBits || // Bad shift. |
| 2204 | C->getZExtValue() >= Tmp) break; // Shifted all sign bits out. |
| 2205 | return Tmp - C->getZExtValue(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2206 | } |
| 2207 | break; |
| 2208 | case ISD::AND: |
| 2209 | case ISD::OR: |
| 2210 | case ISD::XOR: // NOT is handled here. |
Dan Gohman | a332f17 | 2008-05-23 02:28:01 +0000 | [diff] [blame] | 2211 | // Logical binary ops preserve the number of sign bits at the worst. |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2212 | Tmp = ComputeNumSignBits(Op.getOperand(0), Depth+1); |
Dan Gohman | a332f17 | 2008-05-23 02:28:01 +0000 | [diff] [blame] | 2213 | if (Tmp != 1) { |
| 2214 | Tmp2 = ComputeNumSignBits(Op.getOperand(1), Depth+1); |
| 2215 | FirstAnswer = std::min(Tmp, Tmp2); |
| 2216 | // We computed what we know about the sign bits as our first |
| 2217 | // answer. Now proceed to the generic code that uses |
| 2218 | // ComputeMaskedBits, and pick whichever answer is better. |
| 2219 | } |
| 2220 | break; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2221 | |
| 2222 | case ISD::SELECT: |
Dan Gohman | c84941b | 2008-05-20 20:59:51 +0000 | [diff] [blame] | 2223 | Tmp = ComputeNumSignBits(Op.getOperand(1), Depth+1); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2224 | if (Tmp == 1) return 1; // Early out. |
Dan Gohman | c84941b | 2008-05-20 20:59:51 +0000 | [diff] [blame] | 2225 | Tmp2 = ComputeNumSignBits(Op.getOperand(2), Depth+1); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2226 | return std::min(Tmp, Tmp2); |
Bill Wendling | 253174b | 2008-11-22 07:24:01 +0000 | [diff] [blame] | 2227 | |
| 2228 | case ISD::SADDO: |
| 2229 | case ISD::UADDO: |
Bill Wendling | 74c3765 | 2008-12-09 22:08:41 +0000 | [diff] [blame] | 2230 | case ISD::SSUBO: |
| 2231 | case ISD::USUBO: |
| 2232 | case ISD::SMULO: |
| 2233 | case ISD::UMULO: |
Bill Wendling | 253174b | 2008-11-22 07:24:01 +0000 | [diff] [blame] | 2234 | if (Op.getResNo() != 1) |
| 2235 | break; |
Duncan Sands | 0322808 | 2008-11-23 15:47:28 +0000 | [diff] [blame] | 2236 | // The boolean result conforms to getBooleanContents. Fall through. |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2237 | case ISD::SETCC: |
| 2238 | // If setcc returns 0/-1, all bits are sign bits. |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 2239 | if (TLI->getBooleanContents(Op.getValueType().isVector()) == |
Duncan Sands | 0322808 | 2008-11-23 15:47:28 +0000 | [diff] [blame] | 2240 | TargetLowering::ZeroOrNegativeOneBooleanContent) |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2241 | return VTBits; |
| 2242 | break; |
| 2243 | case ISD::ROTL: |
| 2244 | case ISD::ROTR: |
| 2245 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2246 | unsigned RotAmt = C->getZExtValue() & (VTBits-1); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2247 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2248 | // Handle rotate right by N like a rotate left by 32-N. |
| 2249 | if (Op.getOpcode() == ISD::ROTR) |
| 2250 | RotAmt = (VTBits-RotAmt) & (VTBits-1); |
| 2251 | |
| 2252 | // If we aren't rotating out all of the known-in sign bits, return the |
| 2253 | // number that are left. This handles rotl(sext(x), 1) for example. |
| 2254 | Tmp = ComputeNumSignBits(Op.getOperand(0), Depth+1); |
| 2255 | if (Tmp > RotAmt+1) return Tmp-RotAmt; |
| 2256 | } |
| 2257 | break; |
| 2258 | case ISD::ADD: |
| 2259 | // Add can have at most one carry bit. Thus we know that the output |
| 2260 | // is, at worst, one more bit than the inputs. |
| 2261 | Tmp = ComputeNumSignBits(Op.getOperand(0), Depth+1); |
| 2262 | if (Tmp == 1) return 1; // Early out. |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2263 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2264 | // Special case decrementing a value (ADD X, -1): |
Dan Gohman | 0001e56 | 2009-02-24 02:00:40 +0000 | [diff] [blame] | 2265 | if (ConstantSDNode *CRHS = dyn_cast<ConstantSDNode>(Op.getOperand(1))) |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2266 | if (CRHS->isAllOnesValue()) { |
Dan Gohman | b3564aa | 2008-02-27 01:23:58 +0000 | [diff] [blame] | 2267 | APInt KnownZero, KnownOne; |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 2268 | ComputeMaskedBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2269 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2270 | // If the input is known to be 0 or 1, the output is 0/-1, which is all |
| 2271 | // sign bits set. |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 2272 | if ((KnownZero | APInt(VTBits, 1)).isAllOnesValue()) |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2273 | return VTBits; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2274 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2275 | // If we are subtracting one from a positive number, there is no carry |
| 2276 | // out of the result. |
Dan Gohman | b3564aa | 2008-02-27 01:23:58 +0000 | [diff] [blame] | 2277 | if (KnownZero.isNegative()) |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2278 | return Tmp; |
| 2279 | } |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2280 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2281 | Tmp2 = ComputeNumSignBits(Op.getOperand(1), Depth+1); |
| 2282 | if (Tmp2 == 1) return 1; |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 2283 | return std::min(Tmp, Tmp2)-1; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2284 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2285 | case ISD::SUB: |
| 2286 | Tmp2 = ComputeNumSignBits(Op.getOperand(1), Depth+1); |
| 2287 | if (Tmp2 == 1) return 1; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2288 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2289 | // Handle NEG. |
| 2290 | if (ConstantSDNode *CLHS = dyn_cast<ConstantSDNode>(Op.getOperand(0))) |
Dan Gohman | 002e5d0 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 2291 | if (CLHS->isNullValue()) { |
Dan Gohman | b3564aa | 2008-02-27 01:23:58 +0000 | [diff] [blame] | 2292 | APInt KnownZero, KnownOne; |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 2293 | ComputeMaskedBits(Op.getOperand(1), KnownZero, KnownOne, Depth+1); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2294 | // If the input is known to be 0 or 1, the output is 0/-1, which is all |
| 2295 | // sign bits set. |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 2296 | if ((KnownZero | APInt(VTBits, 1)).isAllOnesValue()) |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2297 | return VTBits; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2298 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2299 | // If the input is known to be positive (the sign bit is known clear), |
| 2300 | // the output of the NEG has the same number of sign bits as the input. |
Dan Gohman | b3564aa | 2008-02-27 01:23:58 +0000 | [diff] [blame] | 2301 | if (KnownZero.isNegative()) |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2302 | return Tmp2; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2303 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2304 | // Otherwise, we treat this like a SUB. |
| 2305 | } |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2306 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2307 | // Sub can have at most one carry bit. Thus we know that the output |
| 2308 | // is, at worst, one more bit than the inputs. |
| 2309 | Tmp = ComputeNumSignBits(Op.getOperand(0), Depth+1); |
| 2310 | if (Tmp == 1) return 1; // Early out. |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 2311 | return std::min(Tmp, Tmp2)-1; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2312 | case ISD::TRUNCATE: |
| 2313 | // FIXME: it's tricky to do anything useful for this, but it is an important |
| 2314 | // case for targets like X86. |
| 2315 | break; |
| 2316 | } |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2317 | |
Nadav Rotem | 7745175 | 2013-03-20 22:53:44 +0000 | [diff] [blame] | 2318 | // If we are looking at the loaded value of the SDNode. |
| 2319 | if (Op.getResNo() == 0) { |
| 2320 | // Handle LOADX separately here. EXTLOAD case will fallthrough. |
| 2321 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(Op)) { |
| 2322 | unsigned ExtType = LD->getExtensionType(); |
| 2323 | switch (ExtType) { |
| 2324 | default: break; |
| 2325 | case ISD::SEXTLOAD: // '17' bits known |
| 2326 | Tmp = LD->getMemoryVT().getScalarType().getSizeInBits(); |
| 2327 | return VTBits-Tmp+1; |
| 2328 | case ISD::ZEXTLOAD: // '16' bits known |
| 2329 | Tmp = LD->getMemoryVT().getScalarType().getSizeInBits(); |
| 2330 | return VTBits-Tmp; |
| 2331 | } |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2332 | } |
| 2333 | } |
| 2334 | |
| 2335 | // Allow the target to implement this method for its nodes. |
| 2336 | if (Op.getOpcode() >= ISD::BUILTIN_OP_END || |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2337 | Op.getOpcode() == ISD::INTRINSIC_WO_CHAIN || |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2338 | Op.getOpcode() == ISD::INTRINSIC_W_CHAIN || |
| 2339 | Op.getOpcode() == ISD::INTRINSIC_VOID) { |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 2340 | unsigned NumBits = TLI->ComputeNumSignBitsForTargetNode(Op, Depth); |
Dan Gohman | a332f17 | 2008-05-23 02:28:01 +0000 | [diff] [blame] | 2341 | if (NumBits > 1) FirstAnswer = std::max(FirstAnswer, NumBits); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2342 | } |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2343 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2344 | // Finally, if we can prove that the top bits of the result are 0's or 1's, |
| 2345 | // use this information. |
Dan Gohman | b3564aa | 2008-02-27 01:23:58 +0000 | [diff] [blame] | 2346 | APInt KnownZero, KnownOne; |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 2347 | ComputeMaskedBits(Op, KnownZero, KnownOne, Depth); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2348 | |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 2349 | APInt Mask; |
Dan Gohman | b3564aa | 2008-02-27 01:23:58 +0000 | [diff] [blame] | 2350 | if (KnownZero.isNegative()) { // sign bit is 0 |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2351 | Mask = KnownZero; |
Dan Gohman | b3564aa | 2008-02-27 01:23:58 +0000 | [diff] [blame] | 2352 | } else if (KnownOne.isNegative()) { // sign bit is 1; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2353 | Mask = KnownOne; |
| 2354 | } else { |
| 2355 | // Nothing known. |
Dan Gohman | a332f17 | 2008-05-23 02:28:01 +0000 | [diff] [blame] | 2356 | return FirstAnswer; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2357 | } |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2358 | |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2359 | // Okay, we know that the sign bit in Mask is set. Use CLZ to determine |
| 2360 | // the number of identical bits in the top of the input value. |
Dan Gohman | b3564aa | 2008-02-27 01:23:58 +0000 | [diff] [blame] | 2361 | Mask = ~Mask; |
| 2362 | Mask <<= Mask.getBitWidth()-VTBits; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2363 | // Return # leading zeros. We use 'min' here in case Val was zero before |
| 2364 | // shifting. We don't want to return '64' as for an i32 "0". |
Dan Gohman | a332f17 | 2008-05-23 02:28:01 +0000 | [diff] [blame] | 2365 | return std::max(FirstAnswer, std::min(VTBits, Mask.countLeadingZeros())); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 2366 | } |
| 2367 | |
Chris Lattner | 0a9481f | 2011-02-13 22:25:43 +0000 | [diff] [blame] | 2368 | /// isBaseWithConstantOffset - Return true if the specified operand is an |
| 2369 | /// ISD::ADD with a ConstantSDNode on the right-hand side, or if it is an |
| 2370 | /// ISD::OR with a ConstantSDNode that is guaranteed to have the same |
| 2371 | /// semantics as an ADD. This handles the equivalence: |
Sylvestre Ledru | 94c2271 | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 2372 | /// X|Cst == X+Cst iff X&Cst = 0. |
Chris Lattner | 0a9481f | 2011-02-13 22:25:43 +0000 | [diff] [blame] | 2373 | bool SelectionDAG::isBaseWithConstantOffset(SDValue Op) const { |
| 2374 | if ((Op.getOpcode() != ISD::ADD && Op.getOpcode() != ISD::OR) || |
| 2375 | !isa<ConstantSDNode>(Op.getOperand(1))) |
| 2376 | return false; |
Owen Anderson | 95771af | 2011-02-25 21:41:48 +0000 | [diff] [blame] | 2377 | |
| 2378 | if (Op.getOpcode() == ISD::OR && |
Chris Lattner | 0a9481f | 2011-02-13 22:25:43 +0000 | [diff] [blame] | 2379 | !MaskedValueIsZero(Op.getOperand(0), |
| 2380 | cast<ConstantSDNode>(Op.getOperand(1))->getAPIntValue())) |
| 2381 | return false; |
Owen Anderson | 95771af | 2011-02-25 21:41:48 +0000 | [diff] [blame] | 2382 | |
Chris Lattner | 0a9481f | 2011-02-13 22:25:43 +0000 | [diff] [blame] | 2383 | return true; |
| 2384 | } |
| 2385 | |
| 2386 | |
Dan Gohman | 8d44b28 | 2009-09-03 20:34:31 +0000 | [diff] [blame] | 2387 | bool SelectionDAG::isKnownNeverNaN(SDValue Op) const { |
| 2388 | // If we're told that NaNs won't happen, assume they won't. |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 2389 | if (getTarget().Options.NoNaNsFPMath) |
Dan Gohman | 8d44b28 | 2009-09-03 20:34:31 +0000 | [diff] [blame] | 2390 | return true; |
| 2391 | |
| 2392 | // If the value is a constant, we can obviously see if it is a NaN or not. |
| 2393 | if (const ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(Op)) |
| 2394 | return !C->getValueAPF().isNaN(); |
| 2395 | |
| 2396 | // TODO: Recognize more cases here. |
| 2397 | |
| 2398 | return false; |
| 2399 | } |
Chris Lattner | 51dabfb | 2006-10-14 00:41:01 +0000 | [diff] [blame] | 2400 | |
Dan Gohman | e832693 | 2010-02-24 06:52:40 +0000 | [diff] [blame] | 2401 | bool SelectionDAG::isKnownNeverZero(SDValue Op) const { |
| 2402 | // If the value is a constant, we can obviously see if it is a zero or not. |
| 2403 | if (const ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(Op)) |
| 2404 | return !C->isZero(); |
| 2405 | |
| 2406 | // TODO: Recognize more cases here. |
Evan Cheng | b5a55d9 | 2011-05-24 01:48:22 +0000 | [diff] [blame] | 2407 | switch (Op.getOpcode()) { |
| 2408 | default: break; |
| 2409 | case ISD::OR: |
| 2410 | if (const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op.getOperand(1))) |
| 2411 | return !C->isNullValue(); |
| 2412 | break; |
| 2413 | } |
Dan Gohman | e832693 | 2010-02-24 06:52:40 +0000 | [diff] [blame] | 2414 | |
| 2415 | return false; |
| 2416 | } |
| 2417 | |
| 2418 | bool SelectionDAG::isEqualTo(SDValue A, SDValue B) const { |
| 2419 | // Check the obvious case. |
| 2420 | if (A == B) return true; |
| 2421 | |
| 2422 | // For for negative and positive zero. |
| 2423 | if (const ConstantFPSDNode *CA = dyn_cast<ConstantFPSDNode>(A)) |
| 2424 | if (const ConstantFPSDNode *CB = dyn_cast<ConstantFPSDNode>(B)) |
| 2425 | if (CA->isZero() && CB->isZero()) return true; |
| 2426 | |
| 2427 | // Otherwise they may not be equal. |
| 2428 | return false; |
| 2429 | } |
| 2430 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2431 | /// getNode - Gets or creates the specified node. |
Chris Lattner | 78ec311 | 2003-08-11 14:57:33 +0000 | [diff] [blame] | 2432 | /// |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2433 | SDValue SelectionDAG::getNode(unsigned Opcode, SDLoc DL, EVT VT) { |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 2434 | FoldingSetNodeID ID; |
Dan Gohman | 6d9cdd5 | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 2435 | AddNodeIDNode(ID, Opcode, getVTList(VT), 0, 0); |
Chris Lattner | 4a283e9 | 2006-08-11 18:38:11 +0000 | [diff] [blame] | 2436 | void *IP = 0; |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 2437 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2438 | return SDValue(E, 0); |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 2439 | |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 2440 | SDNode *N = new (NodeAllocator) SDNode(Opcode, DL.getIROrder(), |
| 2441 | DL.getDebugLoc(), getVTList(VT)); |
Chris Lattner | 4a283e9 | 2006-08-11 18:38:11 +0000 | [diff] [blame] | 2442 | CSEMap.InsertNode(N, IP); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2443 | |
Chris Lattner | 4a283e9 | 2006-08-11 18:38:11 +0000 | [diff] [blame] | 2444 | AllNodes.push_back(N); |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 2445 | #ifndef NDEBUG |
Duncan Sands | 59d2dad | 2010-11-20 11:25:00 +0000 | [diff] [blame] | 2446 | VerifySDNode(N); |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 2447 | #endif |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2448 | return SDValue(N, 0); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2449 | } |
| 2450 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2451 | SDValue SelectionDAG::getNode(unsigned Opcode, SDLoc DL, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2452 | EVT VT, SDValue Operand) { |
Chris Lattner | 9468377 | 2005-12-23 05:30:37 +0000 | [diff] [blame] | 2453 | // Constant fold unary operations with an integer constant operand. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2454 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Operand.getNode())) { |
Dan Gohman | 6c23150 | 2008-02-29 01:47:35 +0000 | [diff] [blame] | 2455 | const APInt &Val = C->getAPIntValue(); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2456 | switch (Opcode) { |
| 2457 | default: break; |
Evan Cheng | eb49c4e | 2008-03-06 17:42:34 +0000 | [diff] [blame] | 2458 | case ISD::SIGN_EXTEND: |
Jay Foad | 40f8f62 | 2010-12-07 08:25:19 +0000 | [diff] [blame] | 2459 | return getConstant(Val.sextOrTrunc(VT.getSizeInBits()), VT); |
Chris Lattner | 4ed11b4 | 2005-09-02 00:17:32 +0000 | [diff] [blame] | 2460 | case ISD::ANY_EXTEND: |
Dan Gohman | 6c23150 | 2008-02-29 01:47:35 +0000 | [diff] [blame] | 2461 | case ISD::ZERO_EXTEND: |
Evan Cheng | eb49c4e | 2008-03-06 17:42:34 +0000 | [diff] [blame] | 2462 | case ISD::TRUNCATE: |
Jay Foad | 40f8f62 | 2010-12-07 08:25:19 +0000 | [diff] [blame] | 2463 | return getConstant(Val.zextOrTrunc(VT.getSizeInBits()), VT); |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 2464 | case ISD::UINT_TO_FP: |
| 2465 | case ISD::SINT_TO_FP: { |
Tim Northover | 0a29cb0 | 2013-01-22 09:46:31 +0000 | [diff] [blame] | 2466 | APFloat apf(EVTToAPFloatSemantics(VT), |
| 2467 | APInt::getNullValue(VT.getSizeInBits())); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2468 | (void)apf.convertFromAPInt(Val, |
Dan Gohman | 6c23150 | 2008-02-29 01:47:35 +0000 | [diff] [blame] | 2469 | Opcode==ISD::SINT_TO_FP, |
| 2470 | APFloat::rmNearestTiesToEven); |
Dale Johannesen | 73328d1 | 2007-09-19 23:55:34 +0000 | [diff] [blame] | 2471 | return getConstantFP(apf, VT); |
| 2472 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2473 | case ISD::BITCAST: |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2474 | if (VT == MVT::f32 && C->getValueType(0) == MVT::i32) |
Tim Northover | 0a29cb0 | 2013-01-22 09:46:31 +0000 | [diff] [blame] | 2475 | return getConstantFP(APFloat(APFloat::IEEEsingle, Val), VT); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2476 | else if (VT == MVT::f64 && C->getValueType(0) == MVT::i64) |
Tim Northover | 0a29cb0 | 2013-01-22 09:46:31 +0000 | [diff] [blame] | 2477 | return getConstantFP(APFloat(APFloat::IEEEdouble, Val), VT); |
Chris Lattner | 9468377 | 2005-12-23 05:30:37 +0000 | [diff] [blame] | 2478 | break; |
Nate Begeman | 1b5db7a | 2006-01-16 08:07:10 +0000 | [diff] [blame] | 2479 | case ISD::BSWAP: |
Dan Gohman | 6c23150 | 2008-02-29 01:47:35 +0000 | [diff] [blame] | 2480 | return getConstant(Val.byteSwap(), VT); |
Nate Begeman | 1b5db7a | 2006-01-16 08:07:10 +0000 | [diff] [blame] | 2481 | case ISD::CTPOP: |
Dan Gohman | 6c23150 | 2008-02-29 01:47:35 +0000 | [diff] [blame] | 2482 | return getConstant(Val.countPopulation(), VT); |
Nate Begeman | 1b5db7a | 2006-01-16 08:07:10 +0000 | [diff] [blame] | 2483 | case ISD::CTLZ: |
Chandler Carruth | 63974b2 | 2011-12-13 01:56:10 +0000 | [diff] [blame] | 2484 | case ISD::CTLZ_ZERO_UNDEF: |
Dan Gohman | 6c23150 | 2008-02-29 01:47:35 +0000 | [diff] [blame] | 2485 | return getConstant(Val.countLeadingZeros(), VT); |
Nate Begeman | 1b5db7a | 2006-01-16 08:07:10 +0000 | [diff] [blame] | 2486 | case ISD::CTTZ: |
Chandler Carruth | 63974b2 | 2011-12-13 01:56:10 +0000 | [diff] [blame] | 2487 | case ISD::CTTZ_ZERO_UNDEF: |
Dan Gohman | 6c23150 | 2008-02-29 01:47:35 +0000 | [diff] [blame] | 2488 | return getConstant(Val.countTrailingZeros(), VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2489 | } |
| 2490 | } |
| 2491 | |
Dale Johannesen | c4dd3c3 | 2007-08-31 23:34:27 +0000 | [diff] [blame] | 2492 | // Constant fold unary operations with a floating point constant operand. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2493 | if (ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(Operand.getNode())) { |
Dale Johannesen | c4dd3c3 | 2007-08-31 23:34:27 +0000 | [diff] [blame] | 2494 | APFloat V = C->getValueAPF(); // make copy |
Ulrich Weigand | e669c93 | 2012-10-29 18:35:49 +0000 | [diff] [blame] | 2495 | switch (Opcode) { |
| 2496 | case ISD::FNEG: |
| 2497 | V.changeSign(); |
| 2498 | return getConstantFP(V, VT); |
| 2499 | case ISD::FABS: |
| 2500 | V.clearSign(); |
| 2501 | return getConstantFP(V, VT); |
| 2502 | case ISD::FCEIL: { |
| 2503 | APFloat::opStatus fs = V.roundToIntegral(APFloat::rmTowardPositive); |
| 2504 | if (fs == APFloat::opOK || fs == APFloat::opInexact) |
Dale Johannesen | db44bf8 | 2007-10-16 23:38:29 +0000 | [diff] [blame] | 2505 | return getConstantFP(V, VT); |
Ulrich Weigand | e669c93 | 2012-10-29 18:35:49 +0000 | [diff] [blame] | 2506 | break; |
| 2507 | } |
| 2508 | case ISD::FTRUNC: { |
| 2509 | APFloat::opStatus fs = V.roundToIntegral(APFloat::rmTowardZero); |
| 2510 | if (fs == APFloat::opOK || fs == APFloat::opInexact) |
Dale Johannesen | db44bf8 | 2007-10-16 23:38:29 +0000 | [diff] [blame] | 2511 | return getConstantFP(V, VT); |
Ulrich Weigand | e669c93 | 2012-10-29 18:35:49 +0000 | [diff] [blame] | 2512 | break; |
| 2513 | } |
| 2514 | case ISD::FFLOOR: { |
| 2515 | APFloat::opStatus fs = V.roundToIntegral(APFloat::rmTowardNegative); |
| 2516 | if (fs == APFloat::opOK || fs == APFloat::opInexact) |
Dale Johannesen | db44bf8 | 2007-10-16 23:38:29 +0000 | [diff] [blame] | 2517 | return getConstantFP(V, VT); |
Ulrich Weigand | e669c93 | 2012-10-29 18:35:49 +0000 | [diff] [blame] | 2518 | break; |
| 2519 | } |
| 2520 | case ISD::FP_EXTEND: { |
| 2521 | bool ignored; |
| 2522 | // This can return overflow, underflow, or inexact; we don't care. |
| 2523 | // FIXME need to be more flexible about rounding mode. |
Tim Northover | 0a29cb0 | 2013-01-22 09:46:31 +0000 | [diff] [blame] | 2524 | (void)V.convert(EVTToAPFloatSemantics(VT), |
Ulrich Weigand | e669c93 | 2012-10-29 18:35:49 +0000 | [diff] [blame] | 2525 | APFloat::rmNearestTiesToEven, &ignored); |
| 2526 | return getConstantFP(V, VT); |
| 2527 | } |
| 2528 | case ISD::FP_TO_SINT: |
| 2529 | case ISD::FP_TO_UINT: { |
| 2530 | integerPart x[2]; |
| 2531 | bool ignored; |
| 2532 | assert(integerPartWidth >= 64); |
| 2533 | // FIXME need to be more flexible about rounding mode. |
| 2534 | APFloat::opStatus s = V.convertToInteger(x, VT.getSizeInBits(), |
| 2535 | Opcode==ISD::FP_TO_SINT, |
| 2536 | APFloat::rmTowardZero, &ignored); |
| 2537 | if (s==APFloat::opInvalidOp) // inexact is OK, in fact usual |
Dale Johannesen | c4dd3c3 | 2007-08-31 23:34:27 +0000 | [diff] [blame] | 2538 | break; |
Ulrich Weigand | e669c93 | 2012-10-29 18:35:49 +0000 | [diff] [blame] | 2539 | APInt api(VT.getSizeInBits(), x); |
| 2540 | return getConstant(api, VT); |
| 2541 | } |
| 2542 | case ISD::BITCAST: |
| 2543 | if (VT == MVT::i32 && C->getValueType(0) == MVT::f32) |
| 2544 | return getConstant((uint32_t)V.bitcastToAPInt().getZExtValue(), VT); |
| 2545 | else if (VT == MVT::i64 && C->getValueType(0) == MVT::f64) |
| 2546 | return getConstant(V.bitcastToAPInt().getZExtValue(), VT); |
| 2547 | break; |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2548 | } |
Dale Johannesen | c4dd3c3 | 2007-08-31 23:34:27 +0000 | [diff] [blame] | 2549 | } |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2550 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2551 | unsigned OpOpcode = Operand.getNode()->getOpcode(); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2552 | switch (Opcode) { |
Chris Lattner | a93ec3e | 2005-01-21 18:01:22 +0000 | [diff] [blame] | 2553 | case ISD::TokenFactor: |
Duncan Sands | aaffa05 | 2008-12-01 11:41:29 +0000 | [diff] [blame] | 2554 | case ISD::MERGE_VALUES: |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 2555 | case ISD::CONCAT_VECTORS: |
Duncan Sands | aaffa05 | 2008-12-01 11:41:29 +0000 | [diff] [blame] | 2556 | return Operand; // Factor, merge or concat of one node? No need. |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2557 | case ISD::FP_ROUND: llvm_unreachable("Invalid method to make FP_ROUND node"); |
Chris Lattner | ff33cc4 | 2007-04-09 05:23:13 +0000 | [diff] [blame] | 2558 | case ISD::FP_EXTEND: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2559 | assert(VT.isFloatingPoint() && |
| 2560 | Operand.getValueType().isFloatingPoint() && "Invalid FP cast!"); |
Chris Lattner | 7e2e033 | 2008-01-16 17:59:31 +0000 | [diff] [blame] | 2561 | if (Operand.getValueType() == VT) return Operand; // noop conversion. |
Dan Gohman | 2e141d7 | 2009-12-14 23:40:38 +0000 | [diff] [blame] | 2562 | assert((!VT.isVector() || |
| 2563 | VT.getVectorNumElements() == |
| 2564 | Operand.getValueType().getVectorNumElements()) && |
| 2565 | "Vector element count mismatch!"); |
Chris Lattner | 5d03f21 | 2008-03-11 06:21:08 +0000 | [diff] [blame] | 2566 | if (Operand.getOpcode() == ISD::UNDEF) |
Dale Johannesen | e8d7230 | 2009-02-06 23:05:02 +0000 | [diff] [blame] | 2567 | return getUNDEF(VT); |
Chris Lattner | ff33cc4 | 2007-04-09 05:23:13 +0000 | [diff] [blame] | 2568 | break; |
Chris Lattner | 5d03f21 | 2008-03-11 06:21:08 +0000 | [diff] [blame] | 2569 | case ISD::SIGN_EXTEND: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2570 | assert(VT.isInteger() && Operand.getValueType().isInteger() && |
Chris Lattner | ff33cc4 | 2007-04-09 05:23:13 +0000 | [diff] [blame] | 2571 | "Invalid SIGN_EXTEND!"); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2572 | if (Operand.getValueType() == VT) return Operand; // noop extension |
Dan Gohman | 2e141d7 | 2009-12-14 23:40:38 +0000 | [diff] [blame] | 2573 | assert(Operand.getValueType().getScalarType().bitsLT(VT.getScalarType()) && |
| 2574 | "Invalid sext node, dst < src!"); |
| 2575 | assert((!VT.isVector() || |
| 2576 | VT.getVectorNumElements() == |
| 2577 | Operand.getValueType().getVectorNumElements()) && |
| 2578 | "Vector element count mismatch!"); |
Nadav Rotem | 0c8607b | 2013-01-20 08:35:56 +0000 | [diff] [blame] | 2579 | if (OpOpcode == ISD::SIGN_EXTEND || OpOpcode == ISD::ZERO_EXTEND) |
| 2580 | return getNode(OpOpcode, DL, VT, Operand.getNode()->getOperand(0)); |
| 2581 | else if (OpOpcode == ISD::UNDEF) |
Evan Cheng | bf34a5e | 2011-03-15 02:22:10 +0000 | [diff] [blame] | 2582 | // sext(undef) = 0, because the top bits will all be the same. |
| 2583 | return getConstant(0, VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2584 | break; |
| 2585 | case ISD::ZERO_EXTEND: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2586 | assert(VT.isInteger() && Operand.getValueType().isInteger() && |
Chris Lattner | ff33cc4 | 2007-04-09 05:23:13 +0000 | [diff] [blame] | 2587 | "Invalid ZERO_EXTEND!"); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2588 | if (Operand.getValueType() == VT) return Operand; // noop extension |
Dan Gohman | 2e141d7 | 2009-12-14 23:40:38 +0000 | [diff] [blame] | 2589 | assert(Operand.getValueType().getScalarType().bitsLT(VT.getScalarType()) && |
| 2590 | "Invalid zext node, dst < src!"); |
| 2591 | assert((!VT.isVector() || |
| 2592 | VT.getVectorNumElements() == |
| 2593 | Operand.getValueType().getVectorNumElements()) && |
| 2594 | "Vector element count mismatch!"); |
Chris Lattner | 5a6bace | 2005-04-07 19:43:53 +0000 | [diff] [blame] | 2595 | if (OpOpcode == ISD::ZERO_EXTEND) // (zext (zext x)) -> (zext x) |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2596 | return getNode(ISD::ZERO_EXTEND, DL, VT, |
Dale Johannesen | dbfd8db | 2009-02-03 01:55:44 +0000 | [diff] [blame] | 2597 | Operand.getNode()->getOperand(0)); |
Evan Cheng | bf34a5e | 2011-03-15 02:22:10 +0000 | [diff] [blame] | 2598 | else if (OpOpcode == ISD::UNDEF) |
| 2599 | // zext(undef) = 0, because the top bits will be zero. |
| 2600 | return getConstant(0, VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2601 | break; |
Chris Lattner | 4ed11b4 | 2005-09-02 00:17:32 +0000 | [diff] [blame] | 2602 | case ISD::ANY_EXTEND: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2603 | assert(VT.isInteger() && Operand.getValueType().isInteger() && |
Chris Lattner | ff33cc4 | 2007-04-09 05:23:13 +0000 | [diff] [blame] | 2604 | "Invalid ANY_EXTEND!"); |
Chris Lattner | 4ed11b4 | 2005-09-02 00:17:32 +0000 | [diff] [blame] | 2605 | if (Operand.getValueType() == VT) return Operand; // noop extension |
Dan Gohman | 2e141d7 | 2009-12-14 23:40:38 +0000 | [diff] [blame] | 2606 | assert(Operand.getValueType().getScalarType().bitsLT(VT.getScalarType()) && |
| 2607 | "Invalid anyext node, dst < src!"); |
| 2608 | assert((!VT.isVector() || |
| 2609 | VT.getVectorNumElements() == |
| 2610 | Operand.getValueType().getVectorNumElements()) && |
| 2611 | "Vector element count mismatch!"); |
Dan Gohman | 4e39e9d | 2010-06-24 14:30:44 +0000 | [diff] [blame] | 2612 | |
Dan Gohman | 9e86a73 | 2010-06-18 00:08:30 +0000 | [diff] [blame] | 2613 | if (OpOpcode == ISD::ZERO_EXTEND || OpOpcode == ISD::SIGN_EXTEND || |
| 2614 | OpOpcode == ISD::ANY_EXTEND) |
Chris Lattner | 4ed11b4 | 2005-09-02 00:17:32 +0000 | [diff] [blame] | 2615 | // (ext (zext x)) -> (zext x) and (ext (sext x)) -> (sext x) |
Dale Johannesen | dbfd8db | 2009-02-03 01:55:44 +0000 | [diff] [blame] | 2616 | return getNode(OpOpcode, DL, VT, Operand.getNode()->getOperand(0)); |
Evan Cheng | 5ae1da9 | 2011-03-14 18:15:55 +0000 | [diff] [blame] | 2617 | else if (OpOpcode == ISD::UNDEF) |
| 2618 | return getUNDEF(VT); |
Dan Gohman | 4e39e9d | 2010-06-24 14:30:44 +0000 | [diff] [blame] | 2619 | |
| 2620 | // (ext (trunx x)) -> x |
| 2621 | if (OpOpcode == ISD::TRUNCATE) { |
| 2622 | SDValue OpOp = Operand.getNode()->getOperand(0); |
| 2623 | if (OpOp.getValueType() == VT) |
| 2624 | return OpOp; |
| 2625 | } |
Chris Lattner | 4ed11b4 | 2005-09-02 00:17:32 +0000 | [diff] [blame] | 2626 | break; |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2627 | case ISD::TRUNCATE: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2628 | assert(VT.isInteger() && Operand.getValueType().isInteger() && |
Chris Lattner | ff33cc4 | 2007-04-09 05:23:13 +0000 | [diff] [blame] | 2629 | "Invalid TRUNCATE!"); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2630 | if (Operand.getValueType() == VT) return Operand; // noop truncate |
Dan Gohman | 2e141d7 | 2009-12-14 23:40:38 +0000 | [diff] [blame] | 2631 | assert(Operand.getValueType().getScalarType().bitsGT(VT.getScalarType()) && |
| 2632 | "Invalid truncate node, src < dst!"); |
| 2633 | assert((!VT.isVector() || |
| 2634 | VT.getVectorNumElements() == |
| 2635 | Operand.getValueType().getVectorNumElements()) && |
| 2636 | "Vector element count mismatch!"); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2637 | if (OpOpcode == ISD::TRUNCATE) |
Dale Johannesen | dbfd8db | 2009-02-03 01:55:44 +0000 | [diff] [blame] | 2638 | return getNode(ISD::TRUNCATE, DL, VT, Operand.getNode()->getOperand(0)); |
Craig Topper | 799ea5c | 2012-01-15 01:05:11 +0000 | [diff] [blame] | 2639 | if (OpOpcode == ISD::ZERO_EXTEND || OpOpcode == ISD::SIGN_EXTEND || |
| 2640 | OpOpcode == ISD::ANY_EXTEND) { |
Chris Lattner | fd8c39b | 2005-01-07 21:56:24 +0000 | [diff] [blame] | 2641 | // If the source is smaller than the dest, we still need an extend. |
Dan Gohman | 2e141d7 | 2009-12-14 23:40:38 +0000 | [diff] [blame] | 2642 | if (Operand.getNode()->getOperand(0).getValueType().getScalarType() |
| 2643 | .bitsLT(VT.getScalarType())) |
Dale Johannesen | dbfd8db | 2009-02-03 01:55:44 +0000 | [diff] [blame] | 2644 | return getNode(OpOpcode, DL, VT, Operand.getNode()->getOperand(0)); |
Craig Topper | 799ea5c | 2012-01-15 01:05:11 +0000 | [diff] [blame] | 2645 | if (Operand.getNode()->getOperand(0).getValueType().bitsGT(VT)) |
Dale Johannesen | dbfd8db | 2009-02-03 01:55:44 +0000 | [diff] [blame] | 2646 | return getNode(ISD::TRUNCATE, DL, VT, Operand.getNode()->getOperand(0)); |
Craig Topper | 799ea5c | 2012-01-15 01:05:11 +0000 | [diff] [blame] | 2647 | return Operand.getNode()->getOperand(0); |
Chris Lattner | fd8c39b | 2005-01-07 21:56:24 +0000 | [diff] [blame] | 2648 | } |
Craig Topper | 799ea5c | 2012-01-15 01:05:11 +0000 | [diff] [blame] | 2649 | if (OpOpcode == ISD::UNDEF) |
| 2650 | return getUNDEF(VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2651 | break; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2652 | case ISD::BITCAST: |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 2653 | // Basic sanity checking. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2654 | assert(VT.getSizeInBits() == Operand.getValueType().getSizeInBits() |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2655 | && "Cannot BITCAST between types of different sizes!"); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 2656 | if (VT == Operand.getValueType()) return Operand; // noop conversion. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2657 | if (OpOpcode == ISD::BITCAST) // bitconv(bitconv(x)) -> bitconv(x) |
| 2658 | return getNode(ISD::BITCAST, DL, VT, Operand.getOperand(0)); |
Chris Lattner | 08da55e | 2006-04-04 01:02:22 +0000 | [diff] [blame] | 2659 | if (OpOpcode == ISD::UNDEF) |
Dale Johannesen | e8d7230 | 2009-02-06 23:05:02 +0000 | [diff] [blame] | 2660 | return getUNDEF(VT); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 2661 | break; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 2662 | case ISD::SCALAR_TO_VECTOR: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2663 | assert(VT.isVector() && !Operand.getValueType().isVector() && |
Duncan Sands | b10b5ac | 2009-04-18 20:16:54 +0000 | [diff] [blame] | 2664 | (VT.getVectorElementType() == Operand.getValueType() || |
| 2665 | (VT.getVectorElementType().isInteger() && |
| 2666 | Operand.getValueType().isInteger() && |
| 2667 | VT.getVectorElementType().bitsLE(Operand.getValueType()))) && |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 2668 | "Illegal SCALAR_TO_VECTOR node!"); |
Chris Lattner | f3ba434 | 2008-03-08 23:43:36 +0000 | [diff] [blame] | 2669 | if (OpOpcode == ISD::UNDEF) |
Dale Johannesen | e8d7230 | 2009-02-06 23:05:02 +0000 | [diff] [blame] | 2670 | return getUNDEF(VT); |
Chris Lattner | f3ba434 | 2008-03-08 23:43:36 +0000 | [diff] [blame] | 2671 | // scalar_to_vector(extract_vector_elt V, 0) -> V, top bits are undefined. |
| 2672 | if (OpOpcode == ISD::EXTRACT_VECTOR_ELT && |
| 2673 | isa<ConstantSDNode>(Operand.getOperand(1)) && |
| 2674 | Operand.getConstantOperandVal(1) == 0 && |
| 2675 | Operand.getOperand(0).getValueType() == VT) |
| 2676 | return Operand.getOperand(0); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 2677 | break; |
Chris Lattner | 485df9b | 2005-04-09 03:02:46 +0000 | [diff] [blame] | 2678 | case ISD::FNEG: |
Mon P Wang | a7b6cff | 2009-01-31 06:07:45 +0000 | [diff] [blame] | 2679 | // -(X-Y) -> (Y-X) is unsafe because when X==Y, -0.0 != +0.0 |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 2680 | if (getTarget().Options.UnsafeFPMath && OpOpcode == ISD::FSUB) |
Dale Johannesen | dbfd8db | 2009-02-03 01:55:44 +0000 | [diff] [blame] | 2681 | return getNode(ISD::FSUB, DL, VT, Operand.getNode()->getOperand(1), |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2682 | Operand.getNode()->getOperand(0)); |
Chris Lattner | 485df9b | 2005-04-09 03:02:46 +0000 | [diff] [blame] | 2683 | if (OpOpcode == ISD::FNEG) // --X -> X |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2684 | return Operand.getNode()->getOperand(0); |
Chris Lattner | 485df9b | 2005-04-09 03:02:46 +0000 | [diff] [blame] | 2685 | break; |
| 2686 | case ISD::FABS: |
| 2687 | if (OpOpcode == ISD::FNEG) // abs(-X) -> abs(X) |
Dale Johannesen | dbfd8db | 2009-02-03 01:55:44 +0000 | [diff] [blame] | 2688 | return getNode(ISD::FABS, DL, VT, Operand.getNode()->getOperand(0)); |
Chris Lattner | 485df9b | 2005-04-09 03:02:46 +0000 | [diff] [blame] | 2689 | break; |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2690 | } |
| 2691 | |
Chris Lattner | 43247a1 | 2005-08-25 19:12:10 +0000 | [diff] [blame] | 2692 | SDNode *N; |
Chris Lattner | 0b3e525 | 2006-08-15 19:11:05 +0000 | [diff] [blame] | 2693 | SDVTList VTs = getVTList(VT); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2694 | if (VT != MVT::Glue) { // Don't CSE flag producing nodes |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 2695 | FoldingSetNodeID ID; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2696 | SDValue Ops[1] = { Operand }; |
Chris Lattner | 63e3f14 | 2007-02-04 07:28:00 +0000 | [diff] [blame] | 2697 | AddNodeIDNode(ID, Opcode, VTs, Ops, 1); |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 2698 | void *IP = 0; |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 2699 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2700 | return SDValue(E, 0); |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 2701 | |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 2702 | N = new (NodeAllocator) UnarySDNode(Opcode, DL.getIROrder(), |
| 2703 | DL.getDebugLoc(), VTs, Operand); |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 2704 | CSEMap.InsertNode(N, IP); |
Chris Lattner | 43247a1 | 2005-08-25 19:12:10 +0000 | [diff] [blame] | 2705 | } else { |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 2706 | N = new (NodeAllocator) UnarySDNode(Opcode, DL.getIROrder(), |
| 2707 | DL.getDebugLoc(), VTs, Operand); |
Chris Lattner | 43247a1 | 2005-08-25 19:12:10 +0000 | [diff] [blame] | 2708 | } |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 2709 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2710 | AllNodes.push_back(N); |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 2711 | #ifndef NDEBUG |
Duncan Sands | 59d2dad | 2010-11-20 11:25:00 +0000 | [diff] [blame] | 2712 | VerifySDNode(N); |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 2713 | #endif |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2714 | return SDValue(N, 0); |
Chris Lattner | 78ec311 | 2003-08-11 14:57:33 +0000 | [diff] [blame] | 2715 | } |
| 2716 | |
Benjamin Kramer | 4969310 | 2013-02-04 15:19:18 +0000 | [diff] [blame] | 2717 | SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, EVT VT, |
| 2718 | SDNode *Cst1, SDNode *Cst2) { |
| 2719 | SmallVector<std::pair<ConstantSDNode *, ConstantSDNode *>, 4> Inputs; |
| 2720 | SmallVector<SDValue, 4> Outputs; |
| 2721 | EVT SVT = VT.getScalarType(); |
Bill Wendling | 688d1c4 | 2008-09-24 10:16:24 +0000 | [diff] [blame] | 2722 | |
Benjamin Kramer | 4969310 | 2013-02-04 15:19:18 +0000 | [diff] [blame] | 2723 | ConstantSDNode *Scalar1 = dyn_cast<ConstantSDNode>(Cst1); |
| 2724 | ConstantSDNode *Scalar2 = dyn_cast<ConstantSDNode>(Cst2); |
| 2725 | if (Scalar1 && Scalar2) { |
| 2726 | // Scalar instruction. |
| 2727 | Inputs.push_back(std::make_pair(Scalar1, Scalar2)); |
| 2728 | } else { |
| 2729 | // For vectors extract each constant element into Inputs so we can constant |
| 2730 | // fold them individually. |
| 2731 | BuildVectorSDNode *BV1 = dyn_cast<BuildVectorSDNode>(Cst1); |
| 2732 | BuildVectorSDNode *BV2 = dyn_cast<BuildVectorSDNode>(Cst2); |
| 2733 | if (!BV1 || !BV2) |
| 2734 | return SDValue(); |
| 2735 | |
| 2736 | assert(BV1->getNumOperands() == BV2->getNumOperands() && "Out of sync!"); |
| 2737 | |
| 2738 | for (unsigned I = 0, E = BV1->getNumOperands(); I != E; ++I) { |
| 2739 | ConstantSDNode *V1 = dyn_cast<ConstantSDNode>(BV1->getOperand(I)); |
| 2740 | ConstantSDNode *V2 = dyn_cast<ConstantSDNode>(BV2->getOperand(I)); |
| 2741 | if (!V1 || !V2) // Not a constant, bail. |
| 2742 | return SDValue(); |
| 2743 | |
| 2744 | // Avoid BUILD_VECTOR nodes that perform implicit truncation. |
| 2745 | // FIXME: This is valid and could be handled by truncating the APInts. |
| 2746 | if (V1->getValueType(0) != SVT || V2->getValueType(0) != SVT) |
| 2747 | return SDValue(); |
| 2748 | |
| 2749 | Inputs.push_back(std::make_pair(V1, V2)); |
| 2750 | } |
Bill Wendling | 688d1c4 | 2008-09-24 10:16:24 +0000 | [diff] [blame] | 2751 | } |
| 2752 | |
Benjamin Kramer | 4969310 | 2013-02-04 15:19:18 +0000 | [diff] [blame] | 2753 | // We have a number of constant values, constant fold them element by element. |
| 2754 | for (unsigned I = 0, E = Inputs.size(); I != E; ++I) { |
| 2755 | const APInt &C1 = Inputs[I].first->getAPIntValue(); |
| 2756 | const APInt &C2 = Inputs[I].second->getAPIntValue(); |
| 2757 | |
| 2758 | switch (Opcode) { |
| 2759 | case ISD::ADD: |
| 2760 | Outputs.push_back(getConstant(C1 + C2, SVT)); |
| 2761 | break; |
| 2762 | case ISD::SUB: |
| 2763 | Outputs.push_back(getConstant(C1 - C2, SVT)); |
| 2764 | break; |
| 2765 | case ISD::MUL: |
| 2766 | Outputs.push_back(getConstant(C1 * C2, SVT)); |
| 2767 | break; |
| 2768 | case ISD::UDIV: |
| 2769 | if (!C2.getBoolValue()) |
| 2770 | return SDValue(); |
| 2771 | Outputs.push_back(getConstant(C1.udiv(C2), SVT)); |
| 2772 | break; |
| 2773 | case ISD::UREM: |
| 2774 | if (!C2.getBoolValue()) |
| 2775 | return SDValue(); |
| 2776 | Outputs.push_back(getConstant(C1.urem(C2), SVT)); |
| 2777 | break; |
| 2778 | case ISD::SDIV: |
| 2779 | if (!C2.getBoolValue()) |
| 2780 | return SDValue(); |
| 2781 | Outputs.push_back(getConstant(C1.sdiv(C2), SVT)); |
| 2782 | break; |
| 2783 | case ISD::SREM: |
| 2784 | if (!C2.getBoolValue()) |
| 2785 | return SDValue(); |
| 2786 | Outputs.push_back(getConstant(C1.srem(C2), SVT)); |
| 2787 | break; |
| 2788 | case ISD::AND: |
| 2789 | Outputs.push_back(getConstant(C1 & C2, SVT)); |
| 2790 | break; |
| 2791 | case ISD::OR: |
| 2792 | Outputs.push_back(getConstant(C1 | C2, SVT)); |
| 2793 | break; |
| 2794 | case ISD::XOR: |
| 2795 | Outputs.push_back(getConstant(C1 ^ C2, SVT)); |
| 2796 | break; |
| 2797 | case ISD::SHL: |
| 2798 | Outputs.push_back(getConstant(C1 << C2, SVT)); |
| 2799 | break; |
| 2800 | case ISD::SRL: |
| 2801 | Outputs.push_back(getConstant(C1.lshr(C2), SVT)); |
| 2802 | break; |
| 2803 | case ISD::SRA: |
| 2804 | Outputs.push_back(getConstant(C1.ashr(C2), SVT)); |
| 2805 | break; |
| 2806 | case ISD::ROTL: |
| 2807 | Outputs.push_back(getConstant(C1.rotl(C2), SVT)); |
| 2808 | break; |
| 2809 | case ISD::ROTR: |
| 2810 | Outputs.push_back(getConstant(C1.rotr(C2), SVT)); |
| 2811 | break; |
| 2812 | default: |
| 2813 | return SDValue(); |
| 2814 | } |
| 2815 | } |
| 2816 | |
| 2817 | // Handle the scalar case first. |
Silviu Baranga | 0206683 | 2013-04-25 09:32:33 +0000 | [diff] [blame] | 2818 | if (Scalar1 && Scalar2) |
Benjamin Kramer | 4969310 | 2013-02-04 15:19:18 +0000 | [diff] [blame] | 2819 | return Outputs.back(); |
| 2820 | |
| 2821 | // Otherwise build a big vector out of the scalar elements we generated. |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2822 | return getNode(ISD::BUILD_VECTOR, SDLoc(), VT, Outputs.data(), |
Benjamin Kramer | 4969310 | 2013-02-04 15:19:18 +0000 | [diff] [blame] | 2823 | Outputs.size()); |
Bill Wendling | 688d1c4 | 2008-09-24 10:16:24 +0000 | [diff] [blame] | 2824 | } |
| 2825 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2826 | SDValue SelectionDAG::getNode(unsigned Opcode, SDLoc DL, EVT VT, SDValue N1, |
Benjamin Kramer | 4969310 | 2013-02-04 15:19:18 +0000 | [diff] [blame] | 2827 | SDValue N2) { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2828 | ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1.getNode()); |
| 2829 | ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2.getNode()); |
Chris Lattner | 7636512 | 2005-01-16 02:23:22 +0000 | [diff] [blame] | 2830 | switch (Opcode) { |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 2831 | default: break; |
Chris Lattner | 39908e0 | 2005-01-19 18:01:40 +0000 | [diff] [blame] | 2832 | case ISD::TokenFactor: |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2833 | assert(VT == MVT::Other && N1.getValueType() == MVT::Other && |
| 2834 | N2.getValueType() == MVT::Other && "Invalid token factor!"); |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 2835 | // Fold trivial token factors. |
| 2836 | if (N1.getOpcode() == ISD::EntryToken) return N2; |
| 2837 | if (N2.getOpcode() == ISD::EntryToken) return N1; |
Dan Gohman | 38ac062 | 2008-10-01 15:11:19 +0000 | [diff] [blame] | 2838 | if (N1 == N2) return N1; |
Chris Lattner | 39908e0 | 2005-01-19 18:01:40 +0000 | [diff] [blame] | 2839 | break; |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 2840 | case ISD::CONCAT_VECTORS: |
Nadav Rotem | b87bdac | 2012-07-15 08:38:23 +0000 | [diff] [blame] | 2841 | // Concat of UNDEFs is UNDEF. |
| 2842 | if (N1.getOpcode() == ISD::UNDEF && |
| 2843 | N2.getOpcode() == ISD::UNDEF) |
| 2844 | return getUNDEF(VT); |
| 2845 | |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 2846 | // A CONCAT_VECTOR with all operands BUILD_VECTOR can be simplified to |
| 2847 | // one big BUILD_VECTOR. |
| 2848 | if (N1.getOpcode() == ISD::BUILD_VECTOR && |
| 2849 | N2.getOpcode() == ISD::BUILD_VECTOR) { |
Gabor Greif | 481c4c0 | 2010-07-22 17:18:03 +0000 | [diff] [blame] | 2850 | SmallVector<SDValue, 16> Elts(N1.getNode()->op_begin(), |
| 2851 | N1.getNode()->op_end()); |
Dan Gohman | 403a8cd | 2010-06-21 19:47:52 +0000 | [diff] [blame] | 2852 | Elts.append(N2.getNode()->op_begin(), N2.getNode()->op_end()); |
Evan Cheng | a87008d | 2009-02-25 22:49:59 +0000 | [diff] [blame] | 2853 | return getNode(ISD::BUILD_VECTOR, DL, VT, &Elts[0], Elts.size()); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 2854 | } |
| 2855 | break; |
Chris Lattner | 7636512 | 2005-01-16 02:23:22 +0000 | [diff] [blame] | 2856 | case ISD::AND: |
Dale Johannesen | 7899551 | 2010-05-15 18:38:02 +0000 | [diff] [blame] | 2857 | assert(VT.isInteger() && "This operator does not apply to FP types!"); |
| 2858 | assert(N1.getValueType() == N2.getValueType() && |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 2859 | N1.getValueType() == VT && "Binary operator types must match!"); |
| 2860 | // (X & 0) -> 0. This commonly occurs when legalizing i64 values, so it's |
| 2861 | // worth handling here. |
Dan Gohman | 002e5d0 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 2862 | if (N2C && N2C->isNullValue()) |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 2863 | return N2; |
Chris Lattner | 9967c15 | 2008-01-26 01:05:42 +0000 | [diff] [blame] | 2864 | if (N2C && N2C->isAllOnesValue()) // X & -1 -> X |
| 2865 | return N1; |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 2866 | break; |
Chris Lattner | 7636512 | 2005-01-16 02:23:22 +0000 | [diff] [blame] | 2867 | case ISD::OR: |
| 2868 | case ISD::XOR: |
Dan Gohman | 33b625b | 2008-06-02 22:27:05 +0000 | [diff] [blame] | 2869 | case ISD::ADD: |
| 2870 | case ISD::SUB: |
Dale Johannesen | 7899551 | 2010-05-15 18:38:02 +0000 | [diff] [blame] | 2871 | assert(VT.isInteger() && "This operator does not apply to FP types!"); |
| 2872 | assert(N1.getValueType() == N2.getValueType() && |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 2873 | N1.getValueType() == VT && "Binary operator types must match!"); |
Dan Gohman | 33b625b | 2008-06-02 22:27:05 +0000 | [diff] [blame] | 2874 | // (X ^|+- 0) -> X. This commonly occurs when legalizing i64 values, so |
| 2875 | // it's worth handling here. |
Dan Gohman | 002e5d0 | 2008-03-13 22:13:53 +0000 | [diff] [blame] | 2876 | if (N2C && N2C->isNullValue()) |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 2877 | return N1; |
| 2878 | break; |
Chris Lattner | 7636512 | 2005-01-16 02:23:22 +0000 | [diff] [blame] | 2879 | case ISD::UDIV: |
| 2880 | case ISD::UREM: |
Chris Lattner | e5eb6f8 | 2005-05-15 05:39:08 +0000 | [diff] [blame] | 2881 | case ISD::MULHU: |
| 2882 | case ISD::MULHS: |
Chris Lattner | 7636512 | 2005-01-16 02:23:22 +0000 | [diff] [blame] | 2883 | case ISD::MUL: |
| 2884 | case ISD::SDIV: |
| 2885 | case ISD::SREM: |
Dan Gohman | 760f86f | 2009-01-22 21:58:43 +0000 | [diff] [blame] | 2886 | assert(VT.isInteger() && "This operator does not apply to FP types!"); |
Dale Johannesen | 7899551 | 2010-05-15 18:38:02 +0000 | [diff] [blame] | 2887 | assert(N1.getValueType() == N2.getValueType() && |
| 2888 | N1.getValueType() == VT && "Binary operator types must match!"); |
| 2889 | break; |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 2890 | case ISD::FADD: |
| 2891 | case ISD::FSUB: |
| 2892 | case ISD::FMUL: |
| 2893 | case ISD::FDIV: |
| 2894 | case ISD::FREM: |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 2895 | if (getTarget().Options.UnsafeFPMath) { |
Dan Gohman | a90c8e6 | 2009-01-23 19:10:37 +0000 | [diff] [blame] | 2896 | if (Opcode == ISD::FADD) { |
| 2897 | // 0+x --> x |
| 2898 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(N1)) |
| 2899 | if (CFP->getValueAPF().isZero()) |
| 2900 | return N2; |
| 2901 | // x+0 --> x |
| 2902 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(N2)) |
| 2903 | if (CFP->getValueAPF().isZero()) |
| 2904 | return N1; |
| 2905 | } else if (Opcode == ISD::FSUB) { |
| 2906 | // x-0 --> x |
| 2907 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(N2)) |
| 2908 | if (CFP->getValueAPF().isZero()) |
| 2909 | return N1; |
Michael Ilseman | 10def39 | 2012-09-10 17:00:37 +0000 | [diff] [blame] | 2910 | } else if (Opcode == ISD::FMUL) { |
| 2911 | ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(N1); |
| 2912 | SDValue V = N2; |
| 2913 | |
| 2914 | // If the first operand isn't the constant, try the second |
| 2915 | if (!CFP) { |
| 2916 | CFP = dyn_cast<ConstantFPSDNode>(N2); |
| 2917 | V = N1; |
| 2918 | } |
| 2919 | |
| 2920 | if (CFP) { |
| 2921 | // 0*x --> 0 |
| 2922 | if (CFP->isZero()) |
| 2923 | return SDValue(CFP,0); |
| 2924 | // 1*x --> x |
| 2925 | if (CFP->isExactlyValue(1.0)) |
| 2926 | return V; |
| 2927 | } |
Dan Gohman | a90c8e6 | 2009-01-23 19:10:37 +0000 | [diff] [blame] | 2928 | } |
Dan Gohman | 760f86f | 2009-01-22 21:58:43 +0000 | [diff] [blame] | 2929 | } |
Dale Johannesen | 7899551 | 2010-05-15 18:38:02 +0000 | [diff] [blame] | 2930 | assert(VT.isFloatingPoint() && "This operator only applies to FP types!"); |
Chris Lattner | 7636512 | 2005-01-16 02:23:22 +0000 | [diff] [blame] | 2931 | assert(N1.getValueType() == N2.getValueType() && |
| 2932 | N1.getValueType() == VT && "Binary operator types must match!"); |
| 2933 | break; |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 2934 | case ISD::FCOPYSIGN: // N1 and result must match. N1/N2 need not match. |
| 2935 | assert(N1.getValueType() == VT && |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2936 | N1.getValueType().isFloatingPoint() && |
| 2937 | N2.getValueType().isFloatingPoint() && |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 2938 | "Invalid FCOPYSIGN!"); |
| 2939 | break; |
Chris Lattner | 7636512 | 2005-01-16 02:23:22 +0000 | [diff] [blame] | 2940 | case ISD::SHL: |
| 2941 | case ISD::SRA: |
| 2942 | case ISD::SRL: |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 2943 | case ISD::ROTL: |
| 2944 | case ISD::ROTR: |
Chris Lattner | 7636512 | 2005-01-16 02:23:22 +0000 | [diff] [blame] | 2945 | assert(VT == N1.getValueType() && |
| 2946 | "Shift operators return type must be the same as their first arg"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2947 | assert(VT.isInteger() && N2.getValueType().isInteger() && |
Chris Lattner | 349db17 | 2008-07-02 17:01:57 +0000 | [diff] [blame] | 2948 | "Shifts only work on integers"); |
Michael Liao | a6b20ce | 2013-03-01 18:40:30 +0000 | [diff] [blame] | 2949 | assert((!VT.isVector() || VT == N2.getValueType()) && |
| 2950 | "Vector shift amounts must be in the same as their first arg"); |
Chris Lattner | e075118 | 2011-02-13 19:09:16 +0000 | [diff] [blame] | 2951 | // Verify that the shift amount VT is bit enough to hold valid shift |
| 2952 | // amounts. This catches things like trying to shift an i1024 value by an |
| 2953 | // i8, which is easy to fall into in generic code that uses |
| 2954 | // TLI.getShiftAmount(). |
| 2955 | assert(N2.getValueType().getSizeInBits() >= |
Owen Anderson | 95771af | 2011-02-25 21:41:48 +0000 | [diff] [blame] | 2956 | Log2_32_Ceil(N1.getValueType().getSizeInBits()) && |
Chris Lattner | e075118 | 2011-02-13 19:09:16 +0000 | [diff] [blame] | 2957 | "Invalid use of small shift amount with oversized value!"); |
Chris Lattner | 349db17 | 2008-07-02 17:01:57 +0000 | [diff] [blame] | 2958 | |
| 2959 | // Always fold shifts of i1 values so the code generator doesn't need to |
| 2960 | // handle them. Since we know the size of the shift has to be less than the |
| 2961 | // size of the value, the shift/rotate count is guaranteed to be zero. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2962 | if (VT == MVT::i1) |
Chris Lattner | 349db17 | 2008-07-02 17:01:57 +0000 | [diff] [blame] | 2963 | return N1; |
Evan Cheng | d40d03e | 2010-01-06 19:38:29 +0000 | [diff] [blame] | 2964 | if (N2C && N2C->isNullValue()) |
| 2965 | return N1; |
Chris Lattner | 7636512 | 2005-01-16 02:23:22 +0000 | [diff] [blame] | 2966 | break; |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 2967 | case ISD::FP_ROUND_INREG: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2968 | EVT EVT = cast<VTSDNode>(N2)->getVT(); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 2969 | assert(VT == N1.getValueType() && "Not an inreg round!"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2970 | assert(VT.isFloatingPoint() && EVT.isFloatingPoint() && |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 2971 | "Cannot FP_ROUND_INREG integer types"); |
Dan Gohman | d199636 | 2010-01-09 02:13:55 +0000 | [diff] [blame] | 2972 | assert(EVT.isVector() == VT.isVector() && |
Sylvestre Ledru | 94c2271 | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 2973 | "FP_ROUND_INREG type should be vector iff the operand " |
Dan Gohman | d199636 | 2010-01-09 02:13:55 +0000 | [diff] [blame] | 2974 | "type is vector!"); |
| 2975 | assert((!EVT.isVector() || |
| 2976 | EVT.getVectorNumElements() == VT.getVectorNumElements()) && |
| 2977 | "Vector element counts must match in FP_ROUND_INREG"); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 2978 | assert(EVT.bitsLE(VT) && "Not rounding down!"); |
Duncan Sands | 17001ce | 2011-10-18 12:44:00 +0000 | [diff] [blame] | 2979 | (void)EVT; |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 2980 | if (cast<VTSDNode>(N2)->getVT() == VT) return N1; // Not actually rounding. |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 2981 | break; |
| 2982 | } |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2983 | case ISD::FP_ROUND: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2984 | assert(VT.isFloatingPoint() && |
| 2985 | N1.getValueType().isFloatingPoint() && |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 2986 | VT.bitsLE(N1.getValueType()) && |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2987 | isa<ConstantSDNode>(N2) && "Invalid FP_ROUND!"); |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 2988 | if (N1.getValueType() == VT) return N1; // noop conversion. |
Chris Lattner | 0bd4893 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 2989 | break; |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 2990 | case ISD::AssertSext: |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 2991 | case ISD::AssertZext: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2992 | EVT EVT = cast<VTSDNode>(N2)->getVT(); |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 2993 | assert(VT == N1.getValueType() && "Not an inreg extend!"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2994 | assert(VT.isInteger() && EVT.isInteger() && |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 2995 | "Cannot *_EXTEND_INREG FP types"); |
Dan Gohman | 87862e7 | 2009-12-11 21:31:27 +0000 | [diff] [blame] | 2996 | assert(!EVT.isVector() && |
| 2997 | "AssertSExt/AssertZExt type should be the vector element type " |
| 2998 | "rather than the vector type!"); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 2999 | assert(EVT.bitsLE(VT) && "Not extending!"); |
Duncan Sands | d885dbd | 2008-02-10 10:08:52 +0000 | [diff] [blame] | 3000 | if (VT == EVT) return N1; // noop assertion. |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 3001 | break; |
| 3002 | } |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3003 | case ISD::SIGN_EXTEND_INREG: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3004 | EVT EVT = cast<VTSDNode>(N2)->getVT(); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3005 | assert(VT == N1.getValueType() && "Not an inreg extend!"); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3006 | assert(VT.isInteger() && EVT.isInteger() && |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3007 | "Cannot *_EXTEND_INREG FP types"); |
Dan Gohman | d199636 | 2010-01-09 02:13:55 +0000 | [diff] [blame] | 3008 | assert(EVT.isVector() == VT.isVector() && |
Sylvestre Ledru | 94c2271 | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 3009 | "SIGN_EXTEND_INREG type should be vector iff the operand " |
Dan Gohman | d199636 | 2010-01-09 02:13:55 +0000 | [diff] [blame] | 3010 | "type is vector!"); |
| 3011 | assert((!EVT.isVector() || |
| 3012 | EVT.getVectorNumElements() == VT.getVectorNumElements()) && |
| 3013 | "Vector element counts must match in SIGN_EXTEND_INREG"); |
| 3014 | assert(EVT.bitsLE(VT) && "Not extending!"); |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 3015 | if (EVT == VT) return N1; // Not actually extending |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3016 | |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 3017 | if (N1C) { |
Dan Gohman | 6c23150 | 2008-02-29 01:47:35 +0000 | [diff] [blame] | 3018 | APInt Val = N1C->getAPIntValue(); |
Dan Gohman | d199636 | 2010-01-09 02:13:55 +0000 | [diff] [blame] | 3019 | unsigned FromBits = EVT.getScalarType().getSizeInBits(); |
Dan Gohman | 6c23150 | 2008-02-29 01:47:35 +0000 | [diff] [blame] | 3020 | Val <<= Val.getBitWidth()-FromBits; |
Evan Cheng | 433f6f6 | 2008-03-06 08:20:51 +0000 | [diff] [blame] | 3021 | Val = Val.ashr(Val.getBitWidth()-FromBits); |
Chris Lattner | b9ebacd | 2006-05-06 23:05:41 +0000 | [diff] [blame] | 3022 | return getConstant(Val, VT); |
| 3023 | } |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 3024 | break; |
| 3025 | } |
| 3026 | case ISD::EXTRACT_VECTOR_ELT: |
Chris Lattner | f3ba434 | 2008-03-08 23:43:36 +0000 | [diff] [blame] | 3027 | // EXTRACT_VECTOR_ELT of an UNDEF is an UNDEF. |
| 3028 | if (N1.getOpcode() == ISD::UNDEF) |
Dale Johannesen | e8d7230 | 2009-02-06 23:05:02 +0000 | [diff] [blame] | 3029 | return getUNDEF(VT); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 3030 | |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 3031 | // EXTRACT_VECTOR_ELT of CONCAT_VECTORS is often formed while lowering is |
| 3032 | // expanding copies of large vectors from registers. |
Dan Gohman | 6ab6422 | 2008-08-13 21:51:37 +0000 | [diff] [blame] | 3033 | if (N2C && |
| 3034 | N1.getOpcode() == ISD::CONCAT_VECTORS && |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 3035 | N1.getNumOperands() > 0) { |
| 3036 | unsigned Factor = |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3037 | N1.getOperand(0).getValueType().getVectorNumElements(); |
Dale Johannesen | dbfd8db | 2009-02-03 01:55:44 +0000 | [diff] [blame] | 3038 | return getNode(ISD::EXTRACT_VECTOR_ELT, DL, VT, |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 3039 | N1.getOperand(N2C->getZExtValue() / Factor), |
| 3040 | getConstant(N2C->getZExtValue() % Factor, |
| 3041 | N2.getValueType())); |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 3042 | } |
| 3043 | |
| 3044 | // EXTRACT_VECTOR_ELT of BUILD_VECTOR is often formed while lowering is |
| 3045 | // expanding large vector constants. |
Bob Wilson | b1303d0 | 2009-04-13 22:05:19 +0000 | [diff] [blame] | 3046 | if (N2C && N1.getOpcode() == ISD::BUILD_VECTOR) { |
| 3047 | SDValue Elt = N1.getOperand(N2C->getZExtValue()); |
James Molloy | 8cd08bf | 2012-09-10 14:01:21 +0000 | [diff] [blame] | 3048 | |
| 3049 | if (VT != Elt.getValueType()) |
Bob Wilson | b1303d0 | 2009-04-13 22:05:19 +0000 | [diff] [blame] | 3050 | // If the vector element type is not legal, the BUILD_VECTOR operands |
James Molloy | 8cd08bf | 2012-09-10 14:01:21 +0000 | [diff] [blame] | 3051 | // are promoted and implicitly truncated, and the result implicitly |
| 3052 | // extended. Make that explicit here. |
| 3053 | Elt = getAnyExtOrTrunc(Elt, DL, VT); |
Michael Ilseman | 06b9690 | 2012-09-10 16:56:31 +0000 | [diff] [blame] | 3054 | |
Bob Wilson | b1303d0 | 2009-04-13 22:05:19 +0000 | [diff] [blame] | 3055 | return Elt; |
| 3056 | } |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 3057 | |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 3058 | // EXTRACT_VECTOR_ELT of INSERT_VECTOR_ELT is often formed when vector |
| 3059 | // operations are lowered to scalars. |
Dan Gohman | 6ab6422 | 2008-08-13 21:51:37 +0000 | [diff] [blame] | 3060 | if (N1.getOpcode() == ISD::INSERT_VECTOR_ELT) { |
Mon P Wang | 87c46d8 | 2010-02-01 22:15:09 +0000 | [diff] [blame] | 3061 | // If the indices are the same, return the inserted element else |
| 3062 | // if the indices are known different, extract the element from |
Dan Gohman | 197e88f | 2009-01-29 16:10:46 +0000 | [diff] [blame] | 3063 | // the original vector. |
Bill Wendling | d71bb56 | 2010-04-30 22:19:17 +0000 | [diff] [blame] | 3064 | SDValue N1Op2 = N1.getOperand(2); |
| 3065 | ConstantSDNode *N1Op2C = dyn_cast<ConstantSDNode>(N1Op2.getNode()); |
| 3066 | |
| 3067 | if (N1Op2C && N2C) { |
| 3068 | if (N1Op2C->getZExtValue() == N2C->getZExtValue()) { |
| 3069 | if (VT == N1.getOperand(1).getValueType()) |
| 3070 | return N1.getOperand(1); |
| 3071 | else |
| 3072 | return getSExtOrTrunc(N1.getOperand(1), DL, VT); |
| 3073 | } |
| 3074 | |
Dale Johannesen | dbfd8db | 2009-02-03 01:55:44 +0000 | [diff] [blame] | 3075 | return getNode(ISD::EXTRACT_VECTOR_ELT, DL, VT, N1.getOperand(0), N2); |
Bill Wendling | d71bb56 | 2010-04-30 22:19:17 +0000 | [diff] [blame] | 3076 | } |
Dan Gohman | 6ab6422 | 2008-08-13 21:51:37 +0000 | [diff] [blame] | 3077 | } |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 3078 | break; |
| 3079 | case ISD::EXTRACT_ELEMENT: |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 3080 | assert(N2C && (unsigned)N2C->getZExtValue() < 2 && "Bad EXTRACT_ELEMENT!"); |
Duncan Sands | 041cde2 | 2008-06-25 20:24:48 +0000 | [diff] [blame] | 3081 | assert(!N1.getValueType().isVector() && !VT.isVector() && |
| 3082 | (N1.getValueType().isInteger() == VT.isInteger()) && |
Eli Friedman | 6cdc1f4 | 2011-08-02 18:38:35 +0000 | [diff] [blame] | 3083 | N1.getValueType() != VT && |
Duncan Sands | 041cde2 | 2008-06-25 20:24:48 +0000 | [diff] [blame] | 3084 | "Wrong types for EXTRACT_ELEMENT!"); |
Duncan Sands | 25eb043 | 2008-03-12 20:30:08 +0000 | [diff] [blame] | 3085 | |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 3086 | // EXTRACT_ELEMENT of BUILD_PAIR is often formed while legalize is expanding |
| 3087 | // 64-bit integers into 32-bit parts. Instead of building the extract of |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 3088 | // the BUILD_PAIR, only to have legalize rip it apart, just do it now. |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 3089 | if (N1.getOpcode() == ISD::BUILD_PAIR) |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 3090 | return N1.getOperand(N2C->getZExtValue()); |
Duncan Sands | 25eb043 | 2008-03-12 20:30:08 +0000 | [diff] [blame] | 3091 | |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 3092 | // EXTRACT_ELEMENT of a constant int is also very common. |
| 3093 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N1)) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3094 | unsigned ElementSize = VT.getSizeInBits(); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 3095 | unsigned Shift = ElementSize * N2C->getZExtValue(); |
Dan Gohman | 4c931fc | 2008-03-24 16:38:05 +0000 | [diff] [blame] | 3096 | APInt ShiftedVal = C->getAPIntValue().lshr(Shift); |
| 3097 | return getConstant(ShiftedVal.trunc(ElementSize), VT); |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 3098 | } |
| 3099 | break; |
David Greene | 9158509 | 2011-01-26 15:38:49 +0000 | [diff] [blame] | 3100 | case ISD::EXTRACT_SUBVECTOR: { |
| 3101 | SDValue Index = N2; |
| 3102 | if (VT.isSimple() && N1.getValueType().isSimple()) { |
| 3103 | assert(VT.isVector() && N1.getValueType().isVector() && |
| 3104 | "Extract subvector VTs must be a vectors!"); |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 3105 | assert(VT.getVectorElementType() == |
| 3106 | N1.getValueType().getVectorElementType() && |
David Greene | 9158509 | 2011-01-26 15:38:49 +0000 | [diff] [blame] | 3107 | "Extract subvector VTs must have the same element type!"); |
Craig Topper | 0ff1190 | 2013-08-15 02:44:19 +0000 | [diff] [blame] | 3108 | assert(VT.getSimpleVT() <= N1.getSimpleValueType() && |
David Greene | 9158509 | 2011-01-26 15:38:49 +0000 | [diff] [blame] | 3109 | "Extract subvector must be from larger vector to smaller vector!"); |
| 3110 | |
Matt Beaumont-Gay | 9a14a36 | 2011-02-01 22:12:50 +0000 | [diff] [blame] | 3111 | if (isa<ConstantSDNode>(Index.getNode())) { |
| 3112 | assert((VT.getVectorNumElements() + |
| 3113 | cast<ConstantSDNode>(Index.getNode())->getZExtValue() |
David Greene | 9158509 | 2011-01-26 15:38:49 +0000 | [diff] [blame] | 3114 | <= N1.getValueType().getVectorNumElements()) |
| 3115 | && "Extract subvector overflow!"); |
| 3116 | } |
| 3117 | |
| 3118 | // Trivial extraction. |
Craig Topper | 0ff1190 | 2013-08-15 02:44:19 +0000 | [diff] [blame] | 3119 | if (VT.getSimpleVT() == N1.getSimpleValueType()) |
David Greene | 9158509 | 2011-01-26 15:38:49 +0000 | [diff] [blame] | 3120 | return N1; |
| 3121 | } |
Duncan Sands | f83b1f6 | 2008-02-20 17:38:09 +0000 | [diff] [blame] | 3122 | break; |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 3123 | } |
David Greene | 9158509 | 2011-01-26 15:38:49 +0000 | [diff] [blame] | 3124 | } |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 3125 | |
Benjamin Kramer | 4969310 | 2013-02-04 15:19:18 +0000 | [diff] [blame] | 3126 | // Perform trivial constant folding. |
| 3127 | SDValue SV = FoldConstantArithmetic(Opcode, VT, N1.getNode(), N2.getNode()); |
| 3128 | if (SV.getNode()) return SV; |
| 3129 | |
| 3130 | // Canonicalize constant to RHS if commutative. |
| 3131 | if (N1C && !N2C && isCommutativeBinOp(Opcode)) { |
| 3132 | std::swap(N1C, N2C); |
| 3133 | std::swap(N1, N2); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 3134 | } |
| 3135 | |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 3136 | // Constant fold FP operations. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3137 | ConstantFPSDNode *N1CFP = dyn_cast<ConstantFPSDNode>(N1.getNode()); |
| 3138 | ConstantFPSDNode *N2CFP = dyn_cast<ConstantFPSDNode>(N2.getNode()); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3139 | if (N1CFP) { |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 3140 | if (!N2CFP && isCommutativeBinOp(Opcode)) { |
Benjamin Kramer | 4969310 | 2013-02-04 15:19:18 +0000 | [diff] [blame] | 3141 | // Canonicalize constant to RHS if commutative. |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 3142 | std::swap(N1CFP, N2CFP); |
| 3143 | std::swap(N1, N2); |
Ulrich Weigand | e669c93 | 2012-10-29 18:35:49 +0000 | [diff] [blame] | 3144 | } else if (N2CFP) { |
Dale Johannesen | c4dd3c3 | 2007-08-31 23:34:27 +0000 | [diff] [blame] | 3145 | APFloat V1 = N1CFP->getValueAPF(), V2 = N2CFP->getValueAPF(); |
| 3146 | APFloat::opStatus s; |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 3147 | switch (Opcode) { |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 3148 | case ISD::FADD: |
Dale Johannesen | c4dd3c3 | 2007-08-31 23:34:27 +0000 | [diff] [blame] | 3149 | s = V1.add(V2, APFloat::rmNearestTiesToEven); |
Chris Lattner | 8e1f7ac | 2008-01-22 19:09:33 +0000 | [diff] [blame] | 3150 | if (s != APFloat::opInvalidOp) |
Dale Johannesen | c4dd3c3 | 2007-08-31 23:34:27 +0000 | [diff] [blame] | 3151 | return getConstantFP(V1, VT); |
| 3152 | break; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 3153 | case ISD::FSUB: |
Dale Johannesen | c4dd3c3 | 2007-08-31 23:34:27 +0000 | [diff] [blame] | 3154 | s = V1.subtract(V2, APFloat::rmNearestTiesToEven); |
| 3155 | if (s!=APFloat::opInvalidOp) |
| 3156 | return getConstantFP(V1, VT); |
| 3157 | break; |
| 3158 | case ISD::FMUL: |
| 3159 | s = V1.multiply(V2, APFloat::rmNearestTiesToEven); |
| 3160 | if (s!=APFloat::opInvalidOp) |
| 3161 | return getConstantFP(V1, VT); |
| 3162 | break; |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3163 | case ISD::FDIV: |
Dale Johannesen | c4dd3c3 | 2007-08-31 23:34:27 +0000 | [diff] [blame] | 3164 | s = V1.divide(V2, APFloat::rmNearestTiesToEven); |
| 3165 | if (s!=APFloat::opInvalidOp && s!=APFloat::opDivByZero) |
| 3166 | return getConstantFP(V1, VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 3167 | break; |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 3168 | case ISD::FREM : |
Dale Johannesen | c4dd3c3 | 2007-08-31 23:34:27 +0000 | [diff] [blame] | 3169 | s = V1.mod(V2, APFloat::rmNearestTiesToEven); |
| 3170 | if (s!=APFloat::opInvalidOp && s!=APFloat::opDivByZero) |
| 3171 | return getConstantFP(V1, VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 3172 | break; |
Dale Johannesen | c4dd3c3 | 2007-08-31 23:34:27 +0000 | [diff] [blame] | 3173 | case ISD::FCOPYSIGN: |
| 3174 | V1.copySign(V2); |
| 3175 | return getConstantFP(V1, VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 3176 | default: break; |
| 3177 | } |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 3178 | } |
Owen Anderson | 06886aa | 2012-04-10 22:46:53 +0000 | [diff] [blame] | 3179 | |
| 3180 | if (Opcode == ISD::FP_ROUND) { |
| 3181 | APFloat V = N1CFP->getValueAPF(); // make copy |
| 3182 | bool ignored; |
| 3183 | // This can return overflow, underflow, or inexact; we don't care. |
| 3184 | // FIXME need to be more flexible about rounding mode. |
Tim Northover | 0a29cb0 | 2013-01-22 09:46:31 +0000 | [diff] [blame] | 3185 | (void)V.convert(EVTToAPFloatSemantics(VT), |
Owen Anderson | 06886aa | 2012-04-10 22:46:53 +0000 | [diff] [blame] | 3186 | APFloat::rmNearestTiesToEven, &ignored); |
| 3187 | return getConstantFP(V, VT); |
| 3188 | } |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3189 | } |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 3190 | |
Chris Lattner | 62b5772 | 2006-04-20 05:39:12 +0000 | [diff] [blame] | 3191 | // Canonicalize an UNDEF to the RHS, even over a constant. |
| 3192 | if (N1.getOpcode() == ISD::UNDEF) { |
| 3193 | if (isCommutativeBinOp(Opcode)) { |
| 3194 | std::swap(N1, N2); |
| 3195 | } else { |
| 3196 | switch (Opcode) { |
| 3197 | case ISD::FP_ROUND_INREG: |
| 3198 | case ISD::SIGN_EXTEND_INREG: |
| 3199 | case ISD::SUB: |
| 3200 | case ISD::FSUB: |
| 3201 | case ISD::FDIV: |
| 3202 | case ISD::FREM: |
Chris Lattner | 2cfd674 | 2006-05-08 17:29:49 +0000 | [diff] [blame] | 3203 | case ISD::SRA: |
Chris Lattner | 62b5772 | 2006-04-20 05:39:12 +0000 | [diff] [blame] | 3204 | return N1; // fold op(undef, arg2) -> undef |
| 3205 | case ISD::UDIV: |
| 3206 | case ISD::SDIV: |
| 3207 | case ISD::UREM: |
| 3208 | case ISD::SREM: |
Chris Lattner | 2cfd674 | 2006-05-08 17:29:49 +0000 | [diff] [blame] | 3209 | case ISD::SRL: |
| 3210 | case ISD::SHL: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3211 | if (!VT.isVector()) |
Chris Lattner | 964dd86 | 2007-04-25 00:00:45 +0000 | [diff] [blame] | 3212 | return getConstant(0, VT); // fold op(undef, arg2) -> 0 |
| 3213 | // For vectors, we can't easily build an all zero vector, just return |
| 3214 | // the LHS. |
| 3215 | return N2; |
Chris Lattner | 62b5772 | 2006-04-20 05:39:12 +0000 | [diff] [blame] | 3216 | } |
| 3217 | } |
| 3218 | } |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 3219 | |
| 3220 | // Fold a bunch of operators when the RHS is undef. |
Chris Lattner | 62b5772 | 2006-04-20 05:39:12 +0000 | [diff] [blame] | 3221 | if (N2.getOpcode() == ISD::UNDEF) { |
| 3222 | switch (Opcode) { |
Evan Cheng | 26471c4 | 2008-03-25 20:08:07 +0000 | [diff] [blame] | 3223 | case ISD::XOR: |
| 3224 | if (N1.getOpcode() == ISD::UNDEF) |
| 3225 | // Handle undef ^ undef -> 0 special case. This is a common |
| 3226 | // idiom (misuse). |
| 3227 | return getConstant(0, VT); |
| 3228 | // fallthrough |
Chris Lattner | 62b5772 | 2006-04-20 05:39:12 +0000 | [diff] [blame] | 3229 | case ISD::ADD: |
Chris Lattner | 175415e | 2007-03-04 20:01:46 +0000 | [diff] [blame] | 3230 | case ISD::ADDC: |
| 3231 | case ISD::ADDE: |
Chris Lattner | 62b5772 | 2006-04-20 05:39:12 +0000 | [diff] [blame] | 3232 | case ISD::SUB: |
Chris Lattner | 62b5772 | 2006-04-20 05:39:12 +0000 | [diff] [blame] | 3233 | case ISD::UDIV: |
| 3234 | case ISD::SDIV: |
| 3235 | case ISD::UREM: |
| 3236 | case ISD::SREM: |
Chris Lattner | 62b5772 | 2006-04-20 05:39:12 +0000 | [diff] [blame] | 3237 | return N2; // fold op(arg1, undef) -> undef |
Dan Gohman | 77b81fe | 2009-06-04 17:12:12 +0000 | [diff] [blame] | 3238 | case ISD::FADD: |
| 3239 | case ISD::FSUB: |
| 3240 | case ISD::FMUL: |
| 3241 | case ISD::FDIV: |
| 3242 | case ISD::FREM: |
Nick Lewycky | 8a8d479 | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 3243 | if (getTarget().Options.UnsafeFPMath) |
Dan Gohman | 77b81fe | 2009-06-04 17:12:12 +0000 | [diff] [blame] | 3244 | return N2; |
| 3245 | break; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 3246 | case ISD::MUL: |
Chris Lattner | 62b5772 | 2006-04-20 05:39:12 +0000 | [diff] [blame] | 3247 | case ISD::AND: |
Chris Lattner | 2cfd674 | 2006-05-08 17:29:49 +0000 | [diff] [blame] | 3248 | case ISD::SRL: |
| 3249 | case ISD::SHL: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3250 | if (!VT.isVector()) |
Chris Lattner | 964dd86 | 2007-04-25 00:00:45 +0000 | [diff] [blame] | 3251 | return getConstant(0, VT); // fold op(arg1, undef) -> 0 |
| 3252 | // For vectors, we can't easily build an all zero vector, just return |
| 3253 | // the LHS. |
| 3254 | return N1; |
Chris Lattner | 62b5772 | 2006-04-20 05:39:12 +0000 | [diff] [blame] | 3255 | case ISD::OR: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3256 | if (!VT.isVector()) |
Duncan Sands | b0d5cdd | 2009-02-01 18:06:53 +0000 | [diff] [blame] | 3257 | return getConstant(APInt::getAllOnesValue(VT.getSizeInBits()), VT); |
Chris Lattner | 964dd86 | 2007-04-25 00:00:45 +0000 | [diff] [blame] | 3258 | // For vectors, we can't easily build an all one vector, just return |
| 3259 | // the LHS. |
| 3260 | return N1; |
Chris Lattner | 2cfd674 | 2006-05-08 17:29:49 +0000 | [diff] [blame] | 3261 | case ISD::SRA: |
| 3262 | return N1; |
Chris Lattner | 62b5772 | 2006-04-20 05:39:12 +0000 | [diff] [blame] | 3263 | } |
| 3264 | } |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 3265 | |
Chris Lattner | 27e9b41 | 2005-05-11 18:57:39 +0000 | [diff] [blame] | 3266 | // Memoize this node if possible. |
| 3267 | SDNode *N; |
Chris Lattner | 0b3e525 | 2006-08-15 19:11:05 +0000 | [diff] [blame] | 3268 | SDVTList VTs = getVTList(VT); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3269 | if (VT != MVT::Glue) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3270 | SDValue Ops[] = { N1, N2 }; |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 3271 | FoldingSetNodeID ID; |
Chris Lattner | 63e3f14 | 2007-02-04 07:28:00 +0000 | [diff] [blame] | 3272 | AddNodeIDNode(ID, Opcode, VTs, Ops, 2); |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 3273 | void *IP = 0; |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 3274 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3275 | return SDValue(E, 0); |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 3276 | |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 3277 | N = new (NodeAllocator) BinarySDNode(Opcode, DL.getIROrder(), |
| 3278 | DL.getDebugLoc(), VTs, N1, N2); |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 3279 | CSEMap.InsertNode(N, IP); |
Chris Lattner | 27e9b41 | 2005-05-11 18:57:39 +0000 | [diff] [blame] | 3280 | } else { |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 3281 | N = new (NodeAllocator) BinarySDNode(Opcode, DL.getIROrder(), |
| 3282 | DL.getDebugLoc(), VTs, N1, N2); |
Chris Lattner | 27e9b41 | 2005-05-11 18:57:39 +0000 | [diff] [blame] | 3283 | } |
| 3284 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 3285 | AllNodes.push_back(N); |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 3286 | #ifndef NDEBUG |
Duncan Sands | 59d2dad | 2010-11-20 11:25:00 +0000 | [diff] [blame] | 3287 | VerifySDNode(N); |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 3288 | #endif |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3289 | return SDValue(N, 0); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 3290 | } |
| 3291 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3292 | SDValue SelectionDAG::getNode(unsigned Opcode, SDLoc DL, EVT VT, |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 3293 | SDValue N1, SDValue N2, SDValue N3) { |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 3294 | // Perform various simplifications. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3295 | ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1.getNode()); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 3296 | switch (Opcode) { |
Owen Anderson | 58dcd20 | 2013-05-09 22:27:13 +0000 | [diff] [blame] | 3297 | case ISD::FMA: { |
| 3298 | ConstantFPSDNode *N1CFP = dyn_cast<ConstantFPSDNode>(N1); |
| 3299 | ConstantFPSDNode *N2CFP = dyn_cast<ConstantFPSDNode>(N2); |
| 3300 | ConstantFPSDNode *N3CFP = dyn_cast<ConstantFPSDNode>(N3); |
| 3301 | if (N1CFP && N2CFP && N3CFP) { |
| 3302 | APFloat V1 = N1CFP->getValueAPF(); |
| 3303 | const APFloat &V2 = N2CFP->getValueAPF(); |
| 3304 | const APFloat &V3 = N3CFP->getValueAPF(); |
| 3305 | APFloat::opStatus s = |
| 3306 | V1.fusedMultiplyAdd(V2, V3, APFloat::rmNearestTiesToEven); |
| 3307 | if (s != APFloat::opInvalidOp) |
| 3308 | return getConstantFP(V1, VT); |
| 3309 | } |
| 3310 | break; |
| 3311 | } |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 3312 | case ISD::CONCAT_VECTORS: |
| 3313 | // A CONCAT_VECTOR with all operands BUILD_VECTOR can be simplified to |
| 3314 | // one big BUILD_VECTOR. |
| 3315 | if (N1.getOpcode() == ISD::BUILD_VECTOR && |
| 3316 | N2.getOpcode() == ISD::BUILD_VECTOR && |
| 3317 | N3.getOpcode() == ISD::BUILD_VECTOR) { |
Gabor Greif | 481c4c0 | 2010-07-22 17:18:03 +0000 | [diff] [blame] | 3318 | SmallVector<SDValue, 16> Elts(N1.getNode()->op_begin(), |
| 3319 | N1.getNode()->op_end()); |
Dan Gohman | 403a8cd | 2010-06-21 19:47:52 +0000 | [diff] [blame] | 3320 | Elts.append(N2.getNode()->op_begin(), N2.getNode()->op_end()); |
| 3321 | Elts.append(N3.getNode()->op_begin(), N3.getNode()->op_end()); |
Evan Cheng | a87008d | 2009-02-25 22:49:59 +0000 | [diff] [blame] | 3322 | return getNode(ISD::BUILD_VECTOR, DL, VT, &Elts[0], Elts.size()); |
Dan Gohman | 7f8613e | 2008-08-14 20:04:46 +0000 | [diff] [blame] | 3323 | } |
| 3324 | break; |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 3325 | case ISD::SETCC: { |
Chris Lattner | 51dabfb | 2006-10-14 00:41:01 +0000 | [diff] [blame] | 3326 | // Use FoldSetCC to simplify SETCC's. |
Dale Johannesen | ff97d4f | 2009-02-03 00:47:48 +0000 | [diff] [blame] | 3327 | SDValue Simp = FoldSetCC(VT, N1, N2, cast<CondCodeSDNode>(N3)->get(), DL); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3328 | if (Simp.getNode()) return Simp; |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 3329 | break; |
| 3330 | } |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 3331 | case ISD::SELECT: |
Anton Korobeynikov | 4c71dfe | 2008-02-20 11:10:28 +0000 | [diff] [blame] | 3332 | if (N1C) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 3333 | if (N1C->getZExtValue()) |
David Blaikie | 4d6ccb5 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 3334 | return N2; // select true, X, Y -> X |
| 3335 | return N3; // select false, X, Y -> Y |
Anton Korobeynikov | 4c71dfe | 2008-02-20 11:10:28 +0000 | [diff] [blame] | 3336 | } |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 3337 | |
| 3338 | if (N2 == N3) return N2; // select C, X, X -> X |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 3339 | break; |
Chris Lattner | fb194b9 | 2006-03-19 23:56:04 +0000 | [diff] [blame] | 3340 | case ISD::VECTOR_SHUFFLE: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3341 | llvm_unreachable("should use getVectorShuffle constructor!"); |
David Greene | cfe33c4 | 2011-01-26 19:13:22 +0000 | [diff] [blame] | 3342 | case ISD::INSERT_SUBVECTOR: { |
| 3343 | SDValue Index = N3; |
| 3344 | if (VT.isSimple() && N1.getValueType().isSimple() |
| 3345 | && N2.getValueType().isSimple()) { |
| 3346 | assert(VT.isVector() && N1.getValueType().isVector() && |
| 3347 | N2.getValueType().isVector() && |
| 3348 | "Insert subvector VTs must be a vectors"); |
| 3349 | assert(VT == N1.getValueType() && |
| 3350 | "Dest and insert subvector source types must match!"); |
Craig Topper | 0ff1190 | 2013-08-15 02:44:19 +0000 | [diff] [blame] | 3351 | assert(N2.getSimpleValueType() <= N1.getSimpleValueType() && |
David Greene | cfe33c4 | 2011-01-26 19:13:22 +0000 | [diff] [blame] | 3352 | "Insert subvector must be from smaller vector to larger vector!"); |
Matt Beaumont-Gay | 9a14a36 | 2011-02-01 22:12:50 +0000 | [diff] [blame] | 3353 | if (isa<ConstantSDNode>(Index.getNode())) { |
| 3354 | assert((N2.getValueType().getVectorNumElements() + |
| 3355 | cast<ConstantSDNode>(Index.getNode())->getZExtValue() |
David Greene | cfe33c4 | 2011-01-26 19:13:22 +0000 | [diff] [blame] | 3356 | <= VT.getVectorNumElements()) |
| 3357 | && "Insert subvector overflow!"); |
| 3358 | } |
| 3359 | |
| 3360 | // Trivial insertion. |
Craig Topper | 0ff1190 | 2013-08-15 02:44:19 +0000 | [diff] [blame] | 3361 | if (VT.getSimpleVT() == N2.getSimpleValueType()) |
David Greene | cfe33c4 | 2011-01-26 19:13:22 +0000 | [diff] [blame] | 3362 | return N2; |
| 3363 | } |
| 3364 | break; |
| 3365 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3366 | case ISD::BITCAST: |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 3367 | // Fold bit_convert nodes from a type to themselves. |
| 3368 | if (N1.getValueType() == VT) |
| 3369 | return N1; |
Chris Lattner | 4829b1c | 2007-04-12 05:58:43 +0000 | [diff] [blame] | 3370 | break; |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 3371 | } |
| 3372 | |
Chris Lattner | 43247a1 | 2005-08-25 19:12:10 +0000 | [diff] [blame] | 3373 | // Memoize node if it doesn't produce a flag. |
| 3374 | SDNode *N; |
Chris Lattner | 0b3e525 | 2006-08-15 19:11:05 +0000 | [diff] [blame] | 3375 | SDVTList VTs = getVTList(VT); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3376 | if (VT != MVT::Glue) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3377 | SDValue Ops[] = { N1, N2, N3 }; |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 3378 | FoldingSetNodeID ID; |
Chris Lattner | 63e3f14 | 2007-02-04 07:28:00 +0000 | [diff] [blame] | 3379 | AddNodeIDNode(ID, Opcode, VTs, Ops, 3); |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 3380 | void *IP = 0; |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 3381 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3382 | return SDValue(E, 0); |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 3383 | |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 3384 | N = new (NodeAllocator) TernarySDNode(Opcode, DL.getIROrder(), |
| 3385 | DL.getDebugLoc(), VTs, N1, N2, N3); |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 3386 | CSEMap.InsertNode(N, IP); |
Chris Lattner | 43247a1 | 2005-08-25 19:12:10 +0000 | [diff] [blame] | 3387 | } else { |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 3388 | N = new (NodeAllocator) TernarySDNode(Opcode, DL.getIROrder(), |
| 3389 | DL.getDebugLoc(), VTs, N1, N2, N3); |
Chris Lattner | 43247a1 | 2005-08-25 19:12:10 +0000 | [diff] [blame] | 3390 | } |
Daniel Dunbar | 819309e | 2009-12-16 20:10:05 +0000 | [diff] [blame] | 3391 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 3392 | AllNodes.push_back(N); |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 3393 | #ifndef NDEBUG |
Duncan Sands | 59d2dad | 2010-11-20 11:25:00 +0000 | [diff] [blame] | 3394 | VerifySDNode(N); |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 3395 | #endif |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3396 | return SDValue(N, 0); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 3397 | } |
| 3398 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3399 | SDValue SelectionDAG::getNode(unsigned Opcode, SDLoc DL, EVT VT, |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 3400 | SDValue N1, SDValue N2, SDValue N3, |
| 3401 | SDValue N4) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3402 | SDValue Ops[] = { N1, N2, N3, N4 }; |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 3403 | return getNode(Opcode, DL, VT, Ops, 4); |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 3404 | } |
| 3405 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3406 | SDValue SelectionDAG::getNode(unsigned Opcode, SDLoc DL, EVT VT, |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 3407 | SDValue N1, SDValue N2, SDValue N3, |
| 3408 | SDValue N4, SDValue N5) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3409 | SDValue Ops[] = { N1, N2, N3, N4, N5 }; |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 3410 | return getNode(Opcode, DL, VT, Ops, 5); |
Chris Lattner | 9fadb4c | 2005-07-10 00:29:18 +0000 | [diff] [blame] | 3411 | } |
| 3412 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3413 | /// getStackArgumentTokenFactor - Compute a TokenFactor to force all |
| 3414 | /// the incoming stack arguments to be loaded from the stack. |
| 3415 | SDValue SelectionDAG::getStackArgumentTokenFactor(SDValue Chain) { |
| 3416 | SmallVector<SDValue, 8> ArgChains; |
| 3417 | |
| 3418 | // Include the original chain at the beginning of the list. When this is |
| 3419 | // used by target LowerCall hooks, this helps legalize find the |
| 3420 | // CALLSEQ_BEGIN node. |
| 3421 | ArgChains.push_back(Chain); |
| 3422 | |
| 3423 | // Add a chain value for each stack argument. |
| 3424 | for (SDNode::use_iterator U = getEntryNode().getNode()->use_begin(), |
| 3425 | UE = getEntryNode().getNode()->use_end(); U != UE; ++U) |
| 3426 | if (LoadSDNode *L = dyn_cast<LoadSDNode>(*U)) |
| 3427 | if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(L->getBasePtr())) |
| 3428 | if (FI->getIndex() < 0) |
| 3429 | ArgChains.push_back(SDValue(L, 1)); |
| 3430 | |
| 3431 | // Build a tokenfactor for all the chains. |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3432 | return getNode(ISD::TokenFactor, SDLoc(Chain), MVT::Other, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3433 | &ArgChains[0], ArgChains.size()); |
| 3434 | } |
| 3435 | |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3436 | /// getMemsetValue - Vectorized representation of the memset value |
| 3437 | /// operand. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3438 | static SDValue getMemsetValue(SDValue Value, EVT VT, SelectionDAG &DAG, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3439 | SDLoc dl) { |
Evan Cheng | f28f8bc | 2010-04-02 19:36:14 +0000 | [diff] [blame] | 3440 | assert(Value.getOpcode() != ISD::UNDEF); |
| 3441 | |
Chris Lattner | 5cf0b6e | 2010-02-24 22:44:06 +0000 | [diff] [blame] | 3442 | unsigned NumBits = VT.getScalarType().getSizeInBits(); |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3443 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Value)) { |
Benjamin Kramer | ad4da0f | 2013-02-20 13:00:06 +0000 | [diff] [blame] | 3444 | assert(C->getAPIntValue().getBitWidth() == 8); |
| 3445 | APInt Val = APInt::getSplat(NumBits, C->getAPIntValue()); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3446 | if (VT.isInteger()) |
Evan Cheng | f0df031 | 2008-05-15 08:39:06 +0000 | [diff] [blame] | 3447 | return DAG.getConstant(Val, VT); |
Tim Northover | 0a29cb0 | 2013-01-22 09:46:31 +0000 | [diff] [blame] | 3448 | return DAG.getConstantFP(APFloat(DAG.EVTToAPFloatSemantics(VT), Val), VT); |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3449 | } |
Evan Cheng | f0df031 | 2008-05-15 08:39:06 +0000 | [diff] [blame] | 3450 | |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 3451 | Value = DAG.getNode(ISD::ZERO_EXTEND, dl, VT, Value); |
Benjamin Kramer | 8c06aa1 | 2011-01-02 19:44:58 +0000 | [diff] [blame] | 3452 | if (NumBits > 8) { |
| 3453 | // Use a multiplication with 0x010101... to extend the input to the |
| 3454 | // required length. |
Benjamin Kramer | ad4da0f | 2013-02-20 13:00:06 +0000 | [diff] [blame] | 3455 | APInt Magic = APInt::getSplat(NumBits, APInt(8, 0x01)); |
Benjamin Kramer | 8c06aa1 | 2011-01-02 19:44:58 +0000 | [diff] [blame] | 3456 | Value = DAG.getNode(ISD::MUL, dl, VT, Value, DAG.getConstant(Magic, VT)); |
Evan Cheng | f0df031 | 2008-05-15 08:39:06 +0000 | [diff] [blame] | 3457 | } |
| 3458 | |
| 3459 | return Value; |
Rafael Espindola | 5c0d6ed | 2007-10-19 10:41:11 +0000 | [diff] [blame] | 3460 | } |
| 3461 | |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3462 | /// getMemsetStringVal - Similar to getMemsetValue. Except this is only |
| 3463 | /// used when a memcpy is turned into a memset when the source is a constant |
| 3464 | /// string ptr. |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3465 | static SDValue getMemsetStringVal(EVT VT, SDLoc dl, SelectionDAG &DAG, |
Chris Lattner | 18c7f80 | 2012-02-05 02:29:43 +0000 | [diff] [blame] | 3466 | const TargetLowering &TLI, StringRef Str) { |
Evan Cheng | 0ff39b3 | 2008-06-30 07:31:25 +0000 | [diff] [blame] | 3467 | // Handle vector with all elements zero. |
| 3468 | if (Str.empty()) { |
| 3469 | if (VT.isInteger()) |
| 3470 | return DAG.getConstant(0, VT); |
Duncan Sands | cdfad36 | 2010-11-03 12:17:33 +0000 | [diff] [blame] | 3471 | else if (VT == MVT::f32 || VT == MVT::f64) |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3472 | return DAG.getConstantFP(0.0, VT); |
| 3473 | else if (VT.isVector()) { |
| 3474 | unsigned NumElts = VT.getVectorNumElements(); |
| 3475 | MVT EltVT = (VT.getVectorElementType() == MVT::f32) ? MVT::i32 : MVT::i64; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3476 | return DAG.getNode(ISD::BITCAST, dl, VT, |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3477 | DAG.getConstant(0, EVT::getVectorVT(*DAG.getContext(), |
| 3478 | EltVT, NumElts))); |
| 3479 | } else |
| 3480 | llvm_unreachable("Expected type!"); |
Evan Cheng | 0ff39b3 | 2008-06-30 07:31:25 +0000 | [diff] [blame] | 3481 | } |
| 3482 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3483 | assert(!VT.isVector() && "Can't handle vector type here!"); |
Evan Cheng | 4ff23d0 | 2013-01-10 22:13:27 +0000 | [diff] [blame] | 3484 | unsigned NumVTBits = VT.getSizeInBits(); |
| 3485 | unsigned NumVTBytes = NumVTBits / 8; |
Chris Lattner | 18c7f80 | 2012-02-05 02:29:43 +0000 | [diff] [blame] | 3486 | unsigned NumBytes = std::min(NumVTBytes, unsigned(Str.size())); |
| 3487 | |
Evan Cheng | 4ff23d0 | 2013-01-10 22:13:27 +0000 | [diff] [blame] | 3488 | APInt Val(NumVTBits, 0); |
Chris Lattner | 18c7f80 | 2012-02-05 02:29:43 +0000 | [diff] [blame] | 3489 | if (TLI.isLittleEndian()) { |
| 3490 | for (unsigned i = 0; i != NumBytes; ++i) |
| 3491 | Val |= (uint64_t)(unsigned char)Str[i] << i*8; |
| 3492 | } else { |
| 3493 | for (unsigned i = 0; i != NumBytes; ++i) |
| 3494 | Val |= (uint64_t)(unsigned char)Str[i] << (NumVTBytes-i-1)*8; |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3495 | } |
Chris Lattner | 18c7f80 | 2012-02-05 02:29:43 +0000 | [diff] [blame] | 3496 | |
Evan Cheng | e07f85e | 2012-12-11 23:26:14 +0000 | [diff] [blame] | 3497 | // If the "cost" of materializing the integer immediate is 1 or free, then |
| 3498 | // it is cost effective to turn the load into the immediate. |
Chandler Carruth | e4b4edd | 2013-01-05 12:32:17 +0000 | [diff] [blame] | 3499 | const TargetTransformInfo *TTI = DAG.getTargetTransformInfo(); |
| 3500 | if (TTI->getIntImmCost(Val, VT.getTypeForEVT(*DAG.getContext())) < 2) |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 3501 | return DAG.getConstant(Val, VT); |
| 3502 | return SDValue(0, 0); |
Rafael Espindola | 5c0d6ed | 2007-10-19 10:41:11 +0000 | [diff] [blame] | 3503 | } |
| 3504 | |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 3505 | /// getMemBasePlusOffset - Returns base and offset node for the |
Evan Cheng | f0df031 | 2008-05-15 08:39:06 +0000 | [diff] [blame] | 3506 | /// |
Andrew Trick | dd0fb01 | 2013-05-25 03:08:10 +0000 | [diff] [blame] | 3507 | static SDValue getMemBasePlusOffset(SDValue Base, unsigned Offset, SDLoc dl, |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3508 | SelectionDAG &DAG) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3509 | EVT VT = Base.getValueType(); |
Andrew Trick | dd0fb01 | 2013-05-25 03:08:10 +0000 | [diff] [blame] | 3510 | return DAG.getNode(ISD::ADD, dl, |
Dale Johannesen | dbfd8db | 2009-02-03 01:55:44 +0000 | [diff] [blame] | 3511 | VT, Base, DAG.getConstant(Offset, VT)); |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3512 | } |
| 3513 | |
Evan Cheng | f0df031 | 2008-05-15 08:39:06 +0000 | [diff] [blame] | 3514 | /// isMemSrcFromString - Returns true if memcpy source is a string constant. |
| 3515 | /// |
Chris Lattner | 18c7f80 | 2012-02-05 02:29:43 +0000 | [diff] [blame] | 3516 | static bool isMemSrcFromString(SDValue Src, StringRef &Str) { |
Evan Cheng | f0df031 | 2008-05-15 08:39:06 +0000 | [diff] [blame] | 3517 | unsigned SrcDelta = 0; |
| 3518 | GlobalAddressSDNode *G = NULL; |
| 3519 | if (Src.getOpcode() == ISD::GlobalAddress) |
| 3520 | G = cast<GlobalAddressSDNode>(Src); |
| 3521 | else if (Src.getOpcode() == ISD::ADD && |
| 3522 | Src.getOperand(0).getOpcode() == ISD::GlobalAddress && |
| 3523 | Src.getOperand(1).getOpcode() == ISD::Constant) { |
| 3524 | G = cast<GlobalAddressSDNode>(Src.getOperand(0)); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 3525 | SrcDelta = cast<ConstantSDNode>(Src.getOperand(1))->getZExtValue(); |
Evan Cheng | f0df031 | 2008-05-15 08:39:06 +0000 | [diff] [blame] | 3526 | } |
| 3527 | if (!G) |
| 3528 | return false; |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3529 | |
Chris Lattner | 18c7f80 | 2012-02-05 02:29:43 +0000 | [diff] [blame] | 3530 | return getConstantStringInfo(G->getGlobal(), Str, SrcDelta, false); |
Evan Cheng | f0df031 | 2008-05-15 08:39:06 +0000 | [diff] [blame] | 3531 | } |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3532 | |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3533 | /// FindOptimalMemOpLowering - Determines the optimial series memory ops |
| 3534 | /// to replace the memset / memcpy. Return true if the number of memory ops |
| 3535 | /// is below the threshold. It returns the types of the sequence of |
| 3536 | /// memory ops to perform memset / memcpy by reference. |
| 3537 | static bool FindOptimalMemOpLowering(std::vector<EVT> &MemOps, |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3538 | unsigned Limit, uint64_t Size, |
| 3539 | unsigned DstAlign, unsigned SrcAlign, |
Evan Cheng | 946a3a9 | 2012-12-12 02:34:41 +0000 | [diff] [blame] | 3540 | bool IsMemset, |
| 3541 | bool ZeroMemset, |
Evan Cheng | c3b0c34 | 2010-04-08 07:37:57 +0000 | [diff] [blame] | 3542 | bool MemcpyStrSrc, |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 3543 | bool AllowOverlap, |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3544 | SelectionDAG &DAG, |
| 3545 | const TargetLowering &TLI) { |
| 3546 | assert((SrcAlign == 0 || SrcAlign >= DstAlign) && |
| 3547 | "Expecting memcpy / memset source to meet alignment requirement!"); |
Eric Christopher | 882e1e1 | 2011-07-06 22:41:18 +0000 | [diff] [blame] | 3548 | // If 'SrcAlign' is zero, that means the memory operation does not need to |
| 3549 | // load the value, i.e. memset or memcpy from constant string. Otherwise, |
| 3550 | // it's the inferred alignment of the source. 'DstAlign', on the other hand, |
| 3551 | // is the specified alignment of the memory operation. If it is zero, that |
| 3552 | // means it's possible to change the alignment of the destination. |
| 3553 | // 'MemcpyStrSrc' indicates whether the memcpy source is constant so it does |
| 3554 | // not need to be loaded. |
Evan Cheng | f28f8bc | 2010-04-02 19:36:14 +0000 | [diff] [blame] | 3555 | EVT VT = TLI.getOptimalMemOpType(Size, DstAlign, SrcAlign, |
Evan Cheng | 946a3a9 | 2012-12-12 02:34:41 +0000 | [diff] [blame] | 3556 | IsMemset, ZeroMemset, MemcpyStrSrc, |
Dan Gohman | 4bcf0a9 | 2010-04-16 20:22:43 +0000 | [diff] [blame] | 3557 | DAG.getMachineFunction()); |
Evan Cheng | f0df031 | 2008-05-15 08:39:06 +0000 | [diff] [blame] | 3558 | |
Chris Lattner | acee647 | 2010-03-07 07:45:08 +0000 | [diff] [blame] | 3559 | if (VT == MVT::Other) { |
Chandler Carruth | 426c2bf | 2012-11-01 09:14:31 +0000 | [diff] [blame] | 3560 | if (DstAlign >= TLI.getDataLayout()->getPointerPrefAlignment() || |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3561 | TLI.allowsUnalignedMemoryAccesses(VT)) { |
Evan Cheng | 18141ee | 2010-04-05 23:33:29 +0000 | [diff] [blame] | 3562 | VT = TLI.getPointerTy(); |
Evan Cheng | f0df031 | 2008-05-15 08:39:06 +0000 | [diff] [blame] | 3563 | } else { |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3564 | switch (DstAlign & 7) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3565 | case 0: VT = MVT::i64; break; |
| 3566 | case 4: VT = MVT::i32; break; |
| 3567 | case 2: VT = MVT::i16; break; |
| 3568 | default: VT = MVT::i8; break; |
Evan Cheng | f0df031 | 2008-05-15 08:39:06 +0000 | [diff] [blame] | 3569 | } |
| 3570 | } |
| 3571 | |
Owen Anderson | 766b5ef | 2009-08-11 21:59:30 +0000 | [diff] [blame] | 3572 | MVT LVT = MVT::i64; |
Evan Cheng | f0df031 | 2008-05-15 08:39:06 +0000 | [diff] [blame] | 3573 | while (!TLI.isTypeLegal(LVT)) |
Owen Anderson | 766b5ef | 2009-08-11 21:59:30 +0000 | [diff] [blame] | 3574 | LVT = (MVT::SimpleValueType)(LVT.SimpleTy - 1); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3575 | assert(LVT.isInteger()); |
Evan Cheng | f0df031 | 2008-05-15 08:39:06 +0000 | [diff] [blame] | 3576 | |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 3577 | if (VT.bitsGT(LVT)) |
Evan Cheng | f0df031 | 2008-05-15 08:39:06 +0000 | [diff] [blame] | 3578 | VT = LVT; |
| 3579 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3580 | |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3581 | unsigned NumMemOps = 0; |
| 3582 | while (Size != 0) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3583 | unsigned VTSize = VT.getSizeInBits() / 8; |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3584 | while (VTSize > Size) { |
Evan Cheng | f0df031 | 2008-05-15 08:39:06 +0000 | [diff] [blame] | 3585 | // For now, only use non-vector load / store's for the left-over pieces. |
Evan Cheng | 61f4dfe | 2012-12-12 00:42:09 +0000 | [diff] [blame] | 3586 | EVT NewVT = VT; |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 3587 | unsigned NewVTSize; |
Evan Cheng | 61f4dfe | 2012-12-12 00:42:09 +0000 | [diff] [blame] | 3588 | |
| 3589 | bool Found = false; |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3590 | if (VT.isVector() || VT.isFloatingPoint()) { |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 3591 | NewVT = (VT.getSizeInBits() > 64) ? MVT::i64 : MVT::i32; |
Evan Cheng | 61f4dfe | 2012-12-12 00:42:09 +0000 | [diff] [blame] | 3592 | if (TLI.isOperationLegalOrCustom(ISD::STORE, NewVT) && |
Evan Cheng | 7d34267 | 2012-12-12 01:32:07 +0000 | [diff] [blame] | 3593 | TLI.isSafeMemOpType(NewVT.getSimpleVT())) |
Evan Cheng | 61f4dfe | 2012-12-12 00:42:09 +0000 | [diff] [blame] | 3594 | Found = true; |
| 3595 | else if (NewVT == MVT::i64 && |
| 3596 | TLI.isOperationLegalOrCustom(ISD::STORE, MVT::f64) && |
Evan Cheng | 7d34267 | 2012-12-12 01:32:07 +0000 | [diff] [blame] | 3597 | TLI.isSafeMemOpType(MVT::f64)) { |
Evan Cheng | 61f4dfe | 2012-12-12 00:42:09 +0000 | [diff] [blame] | 3598 | // i64 is usually not legal on 32-bit targets, but f64 may be. |
| 3599 | NewVT = MVT::f64; |
| 3600 | Found = true; |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 3601 | } |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 3602 | } |
| 3603 | |
Evan Cheng | 61f4dfe | 2012-12-12 00:42:09 +0000 | [diff] [blame] | 3604 | if (!Found) { |
| 3605 | do { |
| 3606 | NewVT = (MVT::SimpleValueType)(NewVT.getSimpleVT().SimpleTy - 1); |
| 3607 | if (NewVT == MVT::i8) |
| 3608 | break; |
Evan Cheng | 7d34267 | 2012-12-12 01:32:07 +0000 | [diff] [blame] | 3609 | } while (!TLI.isSafeMemOpType(NewVT.getSimpleVT())); |
Evan Cheng | 61f4dfe | 2012-12-12 00:42:09 +0000 | [diff] [blame] | 3610 | } |
| 3611 | NewVTSize = NewVT.getSizeInBits() / 8; |
| 3612 | |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 3613 | // If the new VT cannot cover all of the remaining bits, then consider |
| 3614 | // issuing a (or a pair of) unaligned and overlapping load / store. |
| 3615 | // FIXME: Only does this for 64-bit or more since we don't have proper |
| 3616 | // cost model for unaligned load / store. |
| 3617 | bool Fast; |
Evan Cheng | a16e49d | 2012-12-12 20:43:23 +0000 | [diff] [blame] | 3618 | if (NumMemOps && AllowOverlap && |
| 3619 | VTSize >= 8 && NewVTSize < Size && |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 3620 | TLI.allowsUnalignedMemoryAccesses(VT, &Fast) && Fast) |
| 3621 | VTSize = Size; |
| 3622 | else { |
| 3623 | VT = NewVT; |
| 3624 | VTSize = NewVTSize; |
Evan Cheng | f0df031 | 2008-05-15 08:39:06 +0000 | [diff] [blame] | 3625 | } |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3626 | } |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3627 | |
Evan Cheng | a16e49d | 2012-12-12 20:43:23 +0000 | [diff] [blame] | 3628 | if (++NumMemOps > Limit) |
| 3629 | return false; |
| 3630 | |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3631 | MemOps.push_back(VT); |
| 3632 | Size -= VTSize; |
| 3633 | } |
| 3634 | |
| 3635 | return true; |
| 3636 | } |
| 3637 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3638 | static SDValue getMemcpyLoadsAndStores(SelectionDAG &DAG, SDLoc dl, |
Evan Cheng | 87bd191 | 2010-03-30 18:08:53 +0000 | [diff] [blame] | 3639 | SDValue Chain, SDValue Dst, |
| 3640 | SDValue Src, uint64_t Size, |
Mon P Wang | 20adc9d | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 3641 | unsigned Align, bool isVol, |
| 3642 | bool AlwaysInline, |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 3643 | MachinePointerInfo DstPtrInfo, |
| 3644 | MachinePointerInfo SrcPtrInfo) { |
Evan Cheng | f28f8bc | 2010-04-02 19:36:14 +0000 | [diff] [blame] | 3645 | // Turn a memcpy of undef to nop. |
| 3646 | if (Src.getOpcode() == ISD::UNDEF) |
| 3647 | return Chain; |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3648 | |
Dan Gohman | 21323f3 | 2008-05-29 19:42:22 +0000 | [diff] [blame] | 3649 | // Expand memcpy to a series of load and store ops if the size operand falls |
| 3650 | // below a certain threshold. |
Duncan Sands | 69300a2 | 2010-11-05 15:20:29 +0000 | [diff] [blame] | 3651 | // TODO: In the AlwaysInline case, if the size is big then generate a loop |
| 3652 | // rather than maybe a humongous number of loads and stores. |
Evan Cheng | f28f8bc | 2010-04-02 19:36:14 +0000 | [diff] [blame] | 3653 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3654 | std::vector<EVT> MemOps; |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3655 | bool DstAlignCanChange = false; |
Evan Cheng | 0521928 | 2011-01-06 06:52:41 +0000 | [diff] [blame] | 3656 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3657 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Bill Wendling | 6765834 | 2012-10-09 07:45:08 +0000 | [diff] [blame] | 3658 | bool OptSize = |
Bill Wendling | 831737d | 2012-12-30 10:32:01 +0000 | [diff] [blame] | 3659 | MF.getFunction()->getAttributes(). |
| 3660 | hasAttribute(AttributeSet::FunctionIndex, Attribute::OptimizeForSize); |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3661 | FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Dst); |
| 3662 | if (FI && !MFI->isFixedObjectIndex(FI->getIndex())) |
| 3663 | DstAlignCanChange = true; |
| 3664 | unsigned SrcAlign = DAG.InferPtrAlignment(Src); |
| 3665 | if (Align > SrcAlign) |
| 3666 | SrcAlign = Align; |
Chris Lattner | 18c7f80 | 2012-02-05 02:29:43 +0000 | [diff] [blame] | 3667 | StringRef Str; |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3668 | bool CopyFromStr = isMemSrcFromString(Src, Str); |
| 3669 | bool isZeroStr = CopyFromStr && Str.empty(); |
Evan Cheng | 0521928 | 2011-01-06 06:52:41 +0000 | [diff] [blame] | 3670 | unsigned Limit = AlwaysInline ? ~0U : TLI.getMaxStoresPerMemcpy(OptSize); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3671 | |
Evan Cheng | 94107ba | 2010-04-01 18:19:11 +0000 | [diff] [blame] | 3672 | if (!FindOptimalMemOpLowering(MemOps, Limit, Size, |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3673 | (DstAlignCanChange ? 0 : Align), |
Evan Cheng | c3b0c34 | 2010-04-08 07:37:57 +0000 | [diff] [blame] | 3674 | (isZeroStr ? 0 : SrcAlign), |
Evan Cheng | 946a3a9 | 2012-12-12 02:34:41 +0000 | [diff] [blame] | 3675 | false, false, CopyFromStr, true, DAG, TLI)) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3676 | return SDValue(); |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3677 | |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3678 | if (DstAlignCanChange) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 3679 | Type *Ty = MemOps[0].getTypeForEVT(*DAG.getContext()); |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 3680 | unsigned NewAlign = (unsigned) TLI.getDataLayout()->getABITypeAlignment(Ty); |
Lang Hames | 2d95e43 | 2013-01-31 20:23:43 +0000 | [diff] [blame] | 3681 | |
| 3682 | // Don't promote to an alignment that would require dynamic stack |
Stephen Lin | 155615d | 2013-07-08 00:37:03 +0000 | [diff] [blame] | 3683 | // realignment. |
Lang Hames | 2d95e43 | 2013-01-31 20:23:43 +0000 | [diff] [blame] | 3684 | const TargetRegisterInfo *TRI = MF.getTarget().getRegisterInfo(); |
| 3685 | if (!TRI->needsStackRealignment(MF)) |
| 3686 | while (NewAlign > Align && |
| 3687 | TLI.getDataLayout()->exceedsNaturalStackAlignment(NewAlign)) |
| 3688 | NewAlign /= 2; |
| 3689 | |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3690 | if (NewAlign > Align) { |
| 3691 | // Give the stack frame object a larger alignment if needed. |
| 3692 | if (MFI->getObjectAlignment(FI->getIndex()) < NewAlign) |
| 3693 | MFI->setObjectAlignment(FI->getIndex(), NewAlign); |
| 3694 | Align = NewAlign; |
| 3695 | } |
| 3696 | } |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3697 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3698 | SmallVector<SDValue, 8> OutChains; |
Evan Cheng | f0df031 | 2008-05-15 08:39:06 +0000 | [diff] [blame] | 3699 | unsigned NumMemOps = MemOps.size(); |
Evan Cheng | 0ff39b3 | 2008-06-30 07:31:25 +0000 | [diff] [blame] | 3700 | uint64_t SrcOff = 0, DstOff = 0; |
Chris Lattner | 7453f8a | 2009-09-20 17:32:21 +0000 | [diff] [blame] | 3701 | for (unsigned i = 0; i != NumMemOps; ++i) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3702 | EVT VT = MemOps[i]; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3703 | unsigned VTSize = VT.getSizeInBits() / 8; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3704 | SDValue Value, Store; |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3705 | |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 3706 | if (VTSize > Size) { |
| 3707 | // Issuing an unaligned load / store pair that overlaps with the previous |
| 3708 | // pair. Adjust the offset accordingly. |
| 3709 | assert(i == NumMemOps-1 && i != 0); |
| 3710 | SrcOff -= VTSize - Size; |
| 3711 | DstOff -= VTSize - Size; |
| 3712 | } |
| 3713 | |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3714 | if (CopyFromStr && |
| 3715 | (isZeroStr || (VT.isInteger() && !VT.isVector()))) { |
Evan Cheng | f0df031 | 2008-05-15 08:39:06 +0000 | [diff] [blame] | 3716 | // It's unlikely a store of a vector immediate can be done in a single |
| 3717 | // instruction. It would require a load from a constantpool first. |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3718 | // We only handle zero vectors here. |
Evan Cheng | 0ff39b3 | 2008-06-30 07:31:25 +0000 | [diff] [blame] | 3719 | // FIXME: Handle other cases where store of vector immediate is done in |
| 3720 | // a single instruction. |
Chris Lattner | 18c7f80 | 2012-02-05 02:29:43 +0000 | [diff] [blame] | 3721 | Value = getMemsetStringVal(VT, dl, DAG, TLI, Str.substr(SrcOff)); |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 3722 | if (Value.getNode()) |
| 3723 | Store = DAG.getStore(Chain, dl, Value, |
Andrew Trick | dd0fb01 | 2013-05-25 03:08:10 +0000 | [diff] [blame] | 3724 | getMemBasePlusOffset(Dst, DstOff, dl, DAG), |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 3725 | DstPtrInfo.getWithOffset(DstOff), isVol, |
| 3726 | false, Align); |
| 3727 | } |
| 3728 | |
| 3729 | if (!Store.getNode()) { |
Dale Johannesen | 08bc98e | 2009-06-22 20:59:07 +0000 | [diff] [blame] | 3730 | // The type might not be legal for the target. This should only happen |
| 3731 | // if the type is smaller than a legal type, as on PPC, so the right |
Dale Johannesen | 8539cfd | 2009-06-24 17:11:31 +0000 | [diff] [blame] | 3732 | // thing to do is generate a LoadExt/StoreTrunc pair. These simplify |
| 3733 | // to Load/Store if NVT==VT. |
Dale Johannesen | 08bc98e | 2009-06-22 20:59:07 +0000 | [diff] [blame] | 3734 | // FIXME does the case above also need this? |
Owen Anderson | 23b9b19 | 2009-08-12 00:36:31 +0000 | [diff] [blame] | 3735 | EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT); |
Dale Johannesen | 8539cfd | 2009-06-24 17:11:31 +0000 | [diff] [blame] | 3736 | assert(NVT.bitsGE(VT)); |
Stuart Hastings | a901129 | 2011-02-16 16:23:55 +0000 | [diff] [blame] | 3737 | Value = DAG.getExtLoad(ISD::EXTLOAD, dl, NVT, Chain, |
Andrew Trick | dd0fb01 | 2013-05-25 03:08:10 +0000 | [diff] [blame] | 3738 | getMemBasePlusOffset(Src, SrcOff, dl, DAG), |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 3739 | SrcPtrInfo.getWithOffset(SrcOff), VT, isVol, false, |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3740 | MinAlign(SrcAlign, SrcOff)); |
Dale Johannesen | 8539cfd | 2009-06-24 17:11:31 +0000 | [diff] [blame] | 3741 | Store = DAG.getTruncStore(Chain, dl, Value, |
Andrew Trick | dd0fb01 | 2013-05-25 03:08:10 +0000 | [diff] [blame] | 3742 | getMemBasePlusOffset(Dst, DstOff, dl, DAG), |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 3743 | DstPtrInfo.getWithOffset(DstOff), VT, isVol, |
| 3744 | false, Align); |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3745 | } |
| 3746 | OutChains.push_back(Store); |
| 3747 | SrcOff += VTSize; |
| 3748 | DstOff += VTSize; |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 3749 | Size -= VTSize; |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3750 | } |
| 3751 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3752 | return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3753 | &OutChains[0], OutChains.size()); |
| 3754 | } |
| 3755 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3756 | static SDValue getMemmoveLoadsAndStores(SelectionDAG &DAG, SDLoc dl, |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3757 | SDValue Chain, SDValue Dst, |
| 3758 | SDValue Src, uint64_t Size, |
Mon P Wang | 20adc9d | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 3759 | unsigned Align, bool isVol, |
| 3760 | bool AlwaysInline, |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 3761 | MachinePointerInfo DstPtrInfo, |
| 3762 | MachinePointerInfo SrcPtrInfo) { |
Evan Cheng | f28f8bc | 2010-04-02 19:36:14 +0000 | [diff] [blame] | 3763 | // Turn a memmove of undef to nop. |
| 3764 | if (Src.getOpcode() == ISD::UNDEF) |
| 3765 | return Chain; |
Dan Gohman | 21323f3 | 2008-05-29 19:42:22 +0000 | [diff] [blame] | 3766 | |
| 3767 | // Expand memmove to a series of load and store ops if the size operand falls |
| 3768 | // below a certain threshold. |
Evan Cheng | f28f8bc | 2010-04-02 19:36:14 +0000 | [diff] [blame] | 3769 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3770 | std::vector<EVT> MemOps; |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3771 | bool DstAlignCanChange = false; |
Evan Cheng | 0521928 | 2011-01-06 06:52:41 +0000 | [diff] [blame] | 3772 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3773 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Bill Wendling | 831737d | 2012-12-30 10:32:01 +0000 | [diff] [blame] | 3774 | bool OptSize = MF.getFunction()->getAttributes(). |
| 3775 | hasAttribute(AttributeSet::FunctionIndex, Attribute::OptimizeForSize); |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3776 | FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Dst); |
| 3777 | if (FI && !MFI->isFixedObjectIndex(FI->getIndex())) |
| 3778 | DstAlignCanChange = true; |
| 3779 | unsigned SrcAlign = DAG.InferPtrAlignment(Src); |
| 3780 | if (Align > SrcAlign) |
| 3781 | SrcAlign = Align; |
Evan Cheng | 0521928 | 2011-01-06 06:52:41 +0000 | [diff] [blame] | 3782 | unsigned Limit = AlwaysInline ? ~0U : TLI.getMaxStoresPerMemmove(OptSize); |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3783 | |
Evan Cheng | 94107ba | 2010-04-01 18:19:11 +0000 | [diff] [blame] | 3784 | if (!FindOptimalMemOpLowering(MemOps, Limit, Size, |
Evan Cheng | 946a3a9 | 2012-12-12 02:34:41 +0000 | [diff] [blame] | 3785 | (DstAlignCanChange ? 0 : Align), SrcAlign, |
| 3786 | false, false, false, false, DAG, TLI)) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3787 | return SDValue(); |
Dan Gohman | 21323f3 | 2008-05-29 19:42:22 +0000 | [diff] [blame] | 3788 | |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3789 | if (DstAlignCanChange) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 3790 | Type *Ty = MemOps[0].getTypeForEVT(*DAG.getContext()); |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 3791 | unsigned NewAlign = (unsigned) TLI.getDataLayout()->getABITypeAlignment(Ty); |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3792 | if (NewAlign > Align) { |
| 3793 | // Give the stack frame object a larger alignment if needed. |
| 3794 | if (MFI->getObjectAlignment(FI->getIndex()) < NewAlign) |
| 3795 | MFI->setObjectAlignment(FI->getIndex(), NewAlign); |
| 3796 | Align = NewAlign; |
| 3797 | } |
| 3798 | } |
Dan Gohman | 21323f3 | 2008-05-29 19:42:22 +0000 | [diff] [blame] | 3799 | |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3800 | uint64_t SrcOff = 0, DstOff = 0; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3801 | SmallVector<SDValue, 8> LoadValues; |
| 3802 | SmallVector<SDValue, 8> LoadChains; |
| 3803 | SmallVector<SDValue, 8> OutChains; |
Dan Gohman | 21323f3 | 2008-05-29 19:42:22 +0000 | [diff] [blame] | 3804 | unsigned NumMemOps = MemOps.size(); |
| 3805 | for (unsigned i = 0; i < NumMemOps; i++) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3806 | EVT VT = MemOps[i]; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3807 | unsigned VTSize = VT.getSizeInBits() / 8; |
Rafael Espindola | 8819c84 | 2013-10-01 13:32:03 +0000 | [diff] [blame] | 3808 | SDValue Value; |
Dan Gohman | 21323f3 | 2008-05-29 19:42:22 +0000 | [diff] [blame] | 3809 | |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 3810 | Value = DAG.getLoad(VT, dl, Chain, |
Andrew Trick | dd0fb01 | 2013-05-25 03:08:10 +0000 | [diff] [blame] | 3811 | getMemBasePlusOffset(Src, SrcOff, dl, DAG), |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 3812 | SrcPtrInfo.getWithOffset(SrcOff), isVol, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3813 | false, false, SrcAlign); |
Dan Gohman | 21323f3 | 2008-05-29 19:42:22 +0000 | [diff] [blame] | 3814 | LoadValues.push_back(Value); |
| 3815 | LoadChains.push_back(Value.getValue(1)); |
| 3816 | SrcOff += VTSize; |
| 3817 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3818 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Dan Gohman | 21323f3 | 2008-05-29 19:42:22 +0000 | [diff] [blame] | 3819 | &LoadChains[0], LoadChains.size()); |
| 3820 | OutChains.clear(); |
| 3821 | for (unsigned i = 0; i < NumMemOps; i++) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3822 | EVT VT = MemOps[i]; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3823 | unsigned VTSize = VT.getSizeInBits() / 8; |
Rafael Espindola | 8819c84 | 2013-10-01 13:32:03 +0000 | [diff] [blame] | 3824 | SDValue Store; |
Dan Gohman | 21323f3 | 2008-05-29 19:42:22 +0000 | [diff] [blame] | 3825 | |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 3826 | Store = DAG.getStore(Chain, dl, LoadValues[i], |
Andrew Trick | dd0fb01 | 2013-05-25 03:08:10 +0000 | [diff] [blame] | 3827 | getMemBasePlusOffset(Dst, DstOff, dl, DAG), |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 3828 | DstPtrInfo.getWithOffset(DstOff), isVol, false, Align); |
Dan Gohman | 21323f3 | 2008-05-29 19:42:22 +0000 | [diff] [blame] | 3829 | OutChains.push_back(Store); |
| 3830 | DstOff += VTSize; |
| 3831 | } |
| 3832 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3833 | return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Dan Gohman | 21323f3 | 2008-05-29 19:42:22 +0000 | [diff] [blame] | 3834 | &OutChains[0], OutChains.size()); |
| 3835 | } |
| 3836 | |
Serge Pavlov | 496f024 | 2013-09-17 16:24:42 +0000 | [diff] [blame] | 3837 | /// \brief Lower the call to 'memset' intrinsic function into a series of store |
| 3838 | /// operations. |
| 3839 | /// |
| 3840 | /// \param DAG Selection DAG where lowered code is placed. |
| 3841 | /// \param dl Link to corresponding IR location. |
| 3842 | /// \param Chain Control flow dependency. |
| 3843 | /// \param Dst Pointer to destination memory location. |
| 3844 | /// \param Src Value of byte to write into the memory. |
| 3845 | /// \param Size Number of bytes to write. |
| 3846 | /// \param Align Alignment of the destination in bytes. |
| 3847 | /// \param isVol True if destination is volatile. |
| 3848 | /// \param DstPtrInfo IR information on the memory pointer. |
| 3849 | /// \returns New head in the control flow, if lowering was successful, empty |
| 3850 | /// SDValue otherwise. |
| 3851 | /// |
| 3852 | /// The function tries to replace 'llvm.memset' intrinsic with several store |
| 3853 | /// operations and value calculation code. This is usually profitable for small |
| 3854 | /// memory size. |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3855 | static SDValue getMemsetStores(SelectionDAG &DAG, SDLoc dl, |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3856 | SDValue Chain, SDValue Dst, |
| 3857 | SDValue Src, uint64_t Size, |
Mon P Wang | 20adc9d | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 3858 | unsigned Align, bool isVol, |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 3859 | MachinePointerInfo DstPtrInfo) { |
Evan Cheng | f28f8bc | 2010-04-02 19:36:14 +0000 | [diff] [blame] | 3860 | // Turn a memset of undef to nop. |
| 3861 | if (Src.getOpcode() == ISD::UNDEF) |
| 3862 | return Chain; |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3863 | |
| 3864 | // Expand memset to a series of load/store ops if the size operand |
| 3865 | // falls below a certain threshold. |
Evan Cheng | f28f8bc | 2010-04-02 19:36:14 +0000 | [diff] [blame] | 3866 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3867 | std::vector<EVT> MemOps; |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3868 | bool DstAlignCanChange = false; |
Evan Cheng | 0521928 | 2011-01-06 06:52:41 +0000 | [diff] [blame] | 3869 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3870 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Bill Wendling | 831737d | 2012-12-30 10:32:01 +0000 | [diff] [blame] | 3871 | bool OptSize = MF.getFunction()->getAttributes(). |
| 3872 | hasAttribute(AttributeSet::FunctionIndex, Attribute::OptimizeForSize); |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3873 | FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Dst); |
| 3874 | if (FI && !MFI->isFixedObjectIndex(FI->getIndex())) |
| 3875 | DstAlignCanChange = true; |
Lang Hames | 15701f8 | 2011-10-26 23:50:43 +0000 | [diff] [blame] | 3876 | bool IsZeroVal = |
Evan Cheng | f28f8bc | 2010-04-02 19:36:14 +0000 | [diff] [blame] | 3877 | isa<ConstantSDNode>(Src) && cast<ConstantSDNode>(Src)->isNullValue(); |
Evan Cheng | 0521928 | 2011-01-06 06:52:41 +0000 | [diff] [blame] | 3878 | if (!FindOptimalMemOpLowering(MemOps, TLI.getMaxStoresPerMemset(OptSize), |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3879 | Size, (DstAlignCanChange ? 0 : Align), 0, |
Evan Cheng | 946a3a9 | 2012-12-12 02:34:41 +0000 | [diff] [blame] | 3880 | true, IsZeroVal, false, true, DAG, TLI)) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3881 | return SDValue(); |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3882 | |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3883 | if (DstAlignCanChange) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 3884 | Type *Ty = MemOps[0].getTypeForEVT(*DAG.getContext()); |
Micah Villmow | 3574eca | 2012-10-08 16:38:25 +0000 | [diff] [blame] | 3885 | unsigned NewAlign = (unsigned) TLI.getDataLayout()->getABITypeAlignment(Ty); |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3886 | if (NewAlign > Align) { |
| 3887 | // Give the stack frame object a larger alignment if needed. |
| 3888 | if (MFI->getObjectAlignment(FI->getIndex()) < NewAlign) |
| 3889 | MFI->setObjectAlignment(FI->getIndex(), NewAlign); |
| 3890 | Align = NewAlign; |
| 3891 | } |
| 3892 | } |
| 3893 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3894 | SmallVector<SDValue, 8> OutChains; |
Dan Gohman | 1f13c68 | 2008-04-28 17:15:20 +0000 | [diff] [blame] | 3895 | uint64_t DstOff = 0; |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3896 | unsigned NumMemOps = MemOps.size(); |
Benjamin Kramer | 8022036 | 2011-01-02 19:57:05 +0000 | [diff] [blame] | 3897 | |
| 3898 | // Find the largest store and generate the bit pattern for it. |
| 3899 | EVT LargestVT = MemOps[0]; |
| 3900 | for (unsigned i = 1; i < NumMemOps; i++) |
| 3901 | if (MemOps[i].bitsGT(LargestVT)) |
| 3902 | LargestVT = MemOps[i]; |
| 3903 | SDValue MemSetValue = getMemsetValue(Src, LargestVT, DAG, dl); |
| 3904 | |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3905 | for (unsigned i = 0; i < NumMemOps; i++) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3906 | EVT VT = MemOps[i]; |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 3907 | unsigned VTSize = VT.getSizeInBits() / 8; |
| 3908 | if (VTSize > Size) { |
| 3909 | // Issuing an unaligned load / store pair that overlaps with the previous |
| 3910 | // pair. Adjust the offset accordingly. |
| 3911 | assert(i == NumMemOps-1 && i != 0); |
| 3912 | DstOff -= VTSize - Size; |
| 3913 | } |
Benjamin Kramer | 8022036 | 2011-01-02 19:57:05 +0000 | [diff] [blame] | 3914 | |
| 3915 | // If this store is smaller than the largest store see whether we can get |
| 3916 | // the smaller value for free with a truncate. |
| 3917 | SDValue Value = MemSetValue; |
| 3918 | if (VT.bitsLT(LargestVT)) { |
| 3919 | if (!LargestVT.isVector() && !VT.isVector() && |
| 3920 | TLI.isTruncateFree(LargestVT, VT)) |
| 3921 | Value = DAG.getNode(ISD::TRUNCATE, dl, VT, MemSetValue); |
| 3922 | else |
| 3923 | Value = getMemsetValue(Src, VT, DAG, dl); |
| 3924 | } |
| 3925 | assert(Value.getValueType() == VT && "Value with wrong type."); |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 3926 | SDValue Store = DAG.getStore(Chain, dl, Value, |
Andrew Trick | dd0fb01 | 2013-05-25 03:08:10 +0000 | [diff] [blame] | 3927 | getMemBasePlusOffset(Dst, DstOff, dl, DAG), |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 3928 | DstPtrInfo.getWithOffset(DstOff), |
Dale Johannesen | b4ac285 | 2010-11-18 01:35:23 +0000 | [diff] [blame] | 3929 | isVol, false, Align); |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3930 | OutChains.push_back(Store); |
Benjamin Kramer | 8022036 | 2011-01-02 19:57:05 +0000 | [diff] [blame] | 3931 | DstOff += VT.getSizeInBits() / 8; |
Evan Cheng | 376642e | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 3932 | Size -= VTSize; |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3933 | } |
| 3934 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3935 | return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3936 | &OutChains[0], OutChains.size()); |
| 3937 | } |
| 3938 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3939 | SDValue SelectionDAG::getMemcpy(SDValue Chain, SDLoc dl, SDValue Dst, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3940 | SDValue Src, SDValue Size, |
Mon P Wang | 20adc9d | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 3941 | unsigned Align, bool isVol, bool AlwaysInline, |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 3942 | MachinePointerInfo DstPtrInfo, |
| 3943 | MachinePointerInfo SrcPtrInfo) { |
Chandler Carruth | 7e6ffac | 2013-02-25 14:29:38 +0000 | [diff] [blame] | 3944 | assert(Align && "The SDAG layer expects explicit alignment and reserves 0"); |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3945 | |
| 3946 | // Check to see if we should lower the memcpy to loads and stores first. |
| 3947 | // For cases within the target-specified limits, this is the best choice. |
| 3948 | ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size); |
| 3949 | if (ConstantSize) { |
| 3950 | // Memcpy with size zero? Just return the original chain. |
| 3951 | if (ConstantSize->isNullValue()) |
| 3952 | return Chain; |
| 3953 | |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 3954 | SDValue Result = getMemcpyLoadsAndStores(*this, dl, Chain, Dst, Src, |
| 3955 | ConstantSize->getZExtValue(),Align, |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 3956 | isVol, false, DstPtrInfo, SrcPtrInfo); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3957 | if (Result.getNode()) |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3958 | return Result; |
| 3959 | } |
| 3960 | |
| 3961 | // Then check to see if we should lower the memcpy with target-specific |
| 3962 | // code. If the target chooses to do this, this is the next best. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3963 | SDValue Result = |
Dan Gohman | ff7a562 | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 3964 | TSI.EmitTargetCodeForMemcpy(*this, dl, Chain, Dst, Src, Size, Align, |
Mon P Wang | 20adc9d | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 3965 | isVol, AlwaysInline, |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 3966 | DstPtrInfo, SrcPtrInfo); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3967 | if (Result.getNode()) |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3968 | return Result; |
| 3969 | |
| 3970 | // If we really need inline code and the target declined to provide it, |
| 3971 | // use a (potentially long) sequence of loads and stores. |
| 3972 | if (AlwaysInline) { |
| 3973 | assert(ConstantSize && "AlwaysInline requires a constant size!"); |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 3974 | return getMemcpyLoadsAndStores(*this, dl, Chain, Dst, Src, |
Mon P Wang | 20adc9d | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 3975 | ConstantSize->getZExtValue(), Align, isVol, |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 3976 | true, DstPtrInfo, SrcPtrInfo); |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3977 | } |
| 3978 | |
Dan Gohman | 7b55d36 | 2010-04-05 20:24:08 +0000 | [diff] [blame] | 3979 | // FIXME: If the memcpy is volatile (isVol), lowering it to a plain libc |
| 3980 | // memcpy is not guaranteed to be safe. libc memcpys aren't required to |
| 3981 | // respect volatile, so they may do things like read or write memory |
| 3982 | // beyond the given memory regions. But fixing this isn't easy, and most |
| 3983 | // people don't care. |
| 3984 | |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 3985 | const TargetLowering *TLI = TM.getTargetLowering(); |
| 3986 | |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3987 | // Emit a library call. |
| 3988 | TargetLowering::ArgListTy Args; |
| 3989 | TargetLowering::ArgListEntry Entry; |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 3990 | Entry.Ty = TLI->getDataLayout()->getIntPtrType(*getContext()); |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 3991 | Entry.Node = Dst; Args.push_back(Entry); |
| 3992 | Entry.Node = Src; Args.push_back(Entry); |
| 3993 | Entry.Node = Size; Args.push_back(Entry); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3994 | // FIXME: pass in SDLoc |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 3995 | TargetLowering:: |
| 3996 | CallLoweringInfo CLI(Chain, Type::getVoidTy(*getContext()), |
Anton Korobeynikov | 72977a4 | 2009-08-14 20:10:52 +0000 | [diff] [blame] | 3997 | false, false, false, false, 0, |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 3998 | TLI->getLibcallCallingConv(RTLIB::MEMCPY), |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 3999 | /*isTailCall=*/false, |
| 4000 | /*doesNotReturn=*/false, /*isReturnValueUsed=*/false, |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 4001 | getExternalSymbol(TLI->getLibcallName(RTLIB::MEMCPY), |
| 4002 | TLI->getPointerTy()), |
Bill Wendling | 46ada19 | 2010-03-02 01:55:18 +0000 | [diff] [blame] | 4003 | Args, *this, dl); |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 4004 | std::pair<SDValue,SDValue> CallResult = TLI->LowerCallTo(CLI); |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 4005 | |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 4006 | return CallResult.second; |
| 4007 | } |
| 4008 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4009 | SDValue SelectionDAG::getMemmove(SDValue Chain, SDLoc dl, SDValue Dst, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4010 | SDValue Src, SDValue Size, |
Mon P Wang | 20adc9d | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 4011 | unsigned Align, bool isVol, |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 4012 | MachinePointerInfo DstPtrInfo, |
| 4013 | MachinePointerInfo SrcPtrInfo) { |
Chandler Carruth | 7e6ffac | 2013-02-25 14:29:38 +0000 | [diff] [blame] | 4014 | assert(Align && "The SDAG layer expects explicit alignment and reserves 0"); |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 4015 | |
Dan Gohman | 21323f3 | 2008-05-29 19:42:22 +0000 | [diff] [blame] | 4016 | // Check to see if we should lower the memmove to loads and stores first. |
| 4017 | // For cases within the target-specified limits, this is the best choice. |
| 4018 | ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size); |
| 4019 | if (ConstantSize) { |
| 4020 | // Memmove with size zero? Just return the original chain. |
| 4021 | if (ConstantSize->isNullValue()) |
| 4022 | return Chain; |
| 4023 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4024 | SDValue Result = |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 4025 | getMemmoveLoadsAndStores(*this, dl, Chain, Dst, Src, |
Mon P Wang | 20adc9d | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 4026 | ConstantSize->getZExtValue(), Align, isVol, |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 4027 | false, DstPtrInfo, SrcPtrInfo); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4028 | if (Result.getNode()) |
Dan Gohman | 21323f3 | 2008-05-29 19:42:22 +0000 | [diff] [blame] | 4029 | return Result; |
| 4030 | } |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 4031 | |
| 4032 | // Then check to see if we should lower the memmove with target-specific |
| 4033 | // code. If the target chooses to do this, this is the next best. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4034 | SDValue Result = |
Dan Gohman | ff7a562 | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 4035 | TSI.EmitTargetCodeForMemmove(*this, dl, Chain, Dst, Src, Size, Align, isVol, |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 4036 | DstPtrInfo, SrcPtrInfo); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4037 | if (Result.getNode()) |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 4038 | return Result; |
| 4039 | |
Mon P Wang | 01f0e85 | 2010-04-06 08:27:51 +0000 | [diff] [blame] | 4040 | // FIXME: If the memmove is volatile, lowering it to plain libc memmove may |
| 4041 | // not be safe. See memcpy above for more details. |
| 4042 | |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 4043 | const TargetLowering *TLI = TM.getTargetLowering(); |
| 4044 | |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 4045 | // Emit a library call. |
| 4046 | TargetLowering::ArgListTy Args; |
| 4047 | TargetLowering::ArgListEntry Entry; |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 4048 | Entry.Ty = TLI->getDataLayout()->getIntPtrType(*getContext()); |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 4049 | Entry.Node = Dst; Args.push_back(Entry); |
| 4050 | Entry.Node = Src; Args.push_back(Entry); |
| 4051 | Entry.Node = Size; Args.push_back(Entry); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4052 | // FIXME: pass in SDLoc |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 4053 | TargetLowering:: |
| 4054 | CallLoweringInfo CLI(Chain, Type::getVoidTy(*getContext()), |
Anton Korobeynikov | 72977a4 | 2009-08-14 20:10:52 +0000 | [diff] [blame] | 4055 | false, false, false, false, 0, |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 4056 | TLI->getLibcallCallingConv(RTLIB::MEMMOVE), |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 4057 | /*isTailCall=*/false, |
| 4058 | /*doesNotReturn=*/false, /*isReturnValueUsed=*/false, |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 4059 | getExternalSymbol(TLI->getLibcallName(RTLIB::MEMMOVE), |
| 4060 | TLI->getPointerTy()), |
Bill Wendling | 46ada19 | 2010-03-02 01:55:18 +0000 | [diff] [blame] | 4061 | Args, *this, dl); |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 4062 | std::pair<SDValue,SDValue> CallResult = TLI->LowerCallTo(CLI); |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 4063 | |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 4064 | return CallResult.second; |
| 4065 | } |
| 4066 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4067 | SDValue SelectionDAG::getMemset(SDValue Chain, SDLoc dl, SDValue Dst, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4068 | SDValue Src, SDValue Size, |
Mon P Wang | 20adc9d | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 4069 | unsigned Align, bool isVol, |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 4070 | MachinePointerInfo DstPtrInfo) { |
Chandler Carruth | 7e6ffac | 2013-02-25 14:29:38 +0000 | [diff] [blame] | 4071 | assert(Align && "The SDAG layer expects explicit alignment and reserves 0"); |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 4072 | |
| 4073 | // Check to see if we should lower the memset to stores first. |
| 4074 | // For cases within the target-specified limits, this is the best choice. |
| 4075 | ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size); |
| 4076 | if (ConstantSize) { |
| 4077 | // Memset with size zero? Just return the original chain. |
| 4078 | if (ConstantSize->isNullValue()) |
| 4079 | return Chain; |
| 4080 | |
Mon P Wang | 20adc9d | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 4081 | SDValue Result = |
| 4082 | getMemsetStores(*this, dl, Chain, Dst, Src, ConstantSize->getZExtValue(), |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 4083 | Align, isVol, DstPtrInfo); |
Mon P Wang | 20adc9d | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 4084 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4085 | if (Result.getNode()) |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 4086 | return Result; |
| 4087 | } |
| 4088 | |
| 4089 | // Then check to see if we should lower the memset with target-specific |
| 4090 | // code. If the target chooses to do this, this is the next best. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4091 | SDValue Result = |
Dan Gohman | ff7a562 | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 4092 | TSI.EmitTargetCodeForMemset(*this, dl, Chain, Dst, Src, Size, Align, isVol, |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 4093 | DstPtrInfo); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4094 | if (Result.getNode()) |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 4095 | return Result; |
| 4096 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4097 | // Emit a library call. |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 4098 | const TargetLowering *TLI = TM.getTargetLowering(); |
| 4099 | Type *IntPtrTy = TLI->getDataLayout()->getIntPtrType(*getContext()); |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 4100 | TargetLowering::ArgListTy Args; |
| 4101 | TargetLowering::ArgListEntry Entry; |
| 4102 | Entry.Node = Dst; Entry.Ty = IntPtrTy; |
| 4103 | Args.push_back(Entry); |
| 4104 | // Extend or truncate the argument to be an i32 value for the call. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4105 | if (Src.getValueType().bitsGT(MVT::i32)) |
| 4106 | Src = getNode(ISD::TRUNCATE, dl, MVT::i32, Src); |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 4107 | else |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4108 | Src = getNode(ISD::ZERO_EXTEND, dl, MVT::i32, Src); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 4109 | Entry.Node = Src; |
| 4110 | Entry.Ty = Type::getInt32Ty(*getContext()); |
| 4111 | Entry.isSExt = true; |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 4112 | Args.push_back(Entry); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 4113 | Entry.Node = Size; |
| 4114 | Entry.Ty = IntPtrTy; |
| 4115 | Entry.isSExt = false; |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 4116 | Args.push_back(Entry); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4117 | // FIXME: pass in SDLoc |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 4118 | TargetLowering:: |
| 4119 | CallLoweringInfo CLI(Chain, Type::getVoidTy(*getContext()), |
Anton Korobeynikov | 72977a4 | 2009-08-14 20:10:52 +0000 | [diff] [blame] | 4120 | false, false, false, false, 0, |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 4121 | TLI->getLibcallCallingConv(RTLIB::MEMSET), |
Evan Cheng | 4bfcd4a | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 4122 | /*isTailCall=*/false, |
| 4123 | /*doesNotReturn*/false, /*isReturnValueUsed=*/false, |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 4124 | getExternalSymbol(TLI->getLibcallName(RTLIB::MEMSET), |
| 4125 | TLI->getPointerTy()), |
Bill Wendling | 46ada19 | 2010-03-02 01:55:18 +0000 | [diff] [blame] | 4126 | Args, *this, dl); |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 4127 | std::pair<SDValue,SDValue> CallResult = TLI->LowerCallTo(CLI); |
Justin Holewinski | d2ea0e1 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 4128 | |
Dan Gohman | 707e018 | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 4129 | return CallResult.second; |
Rafael Espindola | 5c0d6ed | 2007-10-19 10:41:11 +0000 | [diff] [blame] | 4130 | } |
| 4131 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4132 | SDValue SelectionDAG::getAtomic(unsigned Opcode, SDLoc dl, EVT MemVT, |
Amara Emerson | 268c743 | 2013-09-26 12:22:36 +0000 | [diff] [blame] | 4133 | SDVTList VTList, SDValue* Ops, unsigned NumOps, |
| 4134 | MachineMemOperand *MMO, |
| 4135 | AtomicOrdering Ordering, |
| 4136 | SynchronizationScope SynchScope) { |
| 4137 | FoldingSetNodeID ID; |
| 4138 | ID.AddInteger(MemVT.getRawBits()); |
| 4139 | AddNodeIDNode(ID, Opcode, VTList, Ops, NumOps); |
| 4140 | ID.AddInteger(MMO->getPointerInfo().getAddrSpace()); |
| 4141 | void* IP = 0; |
| 4142 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) { |
| 4143 | cast<AtomicSDNode>(E)->refineAlignment(MMO); |
| 4144 | return SDValue(E, 0); |
| 4145 | } |
Benjamin Kramer | fd40d51 | 2013-09-29 11:18:56 +0000 | [diff] [blame] | 4146 | |
| 4147 | // Allocate the operands array for the node out of the BumpPtrAllocator, since |
| 4148 | // SDNode doesn't have access to it. This memory will be "leaked" when |
| 4149 | // the node is deallocated, but recovered when the allocator is released. |
| 4150 | // If the number of operands is less than 5 we use AtomicSDNode's internal |
| 4151 | // storage. |
| 4152 | SDUse *DynOps = NumOps > 4 ? OperandAllocator.Allocate<SDUse>(NumOps) : 0; |
| 4153 | |
Amara Emerson | 268c743 | 2013-09-26 12:22:36 +0000 | [diff] [blame] | 4154 | SDNode *N = new (NodeAllocator) AtomicSDNode(Opcode, dl.getIROrder(), |
| 4155 | dl.getDebugLoc(), VTList, MemVT, |
Benjamin Kramer | fd40d51 | 2013-09-29 11:18:56 +0000 | [diff] [blame] | 4156 | Ops, DynOps, NumOps, MMO, |
| 4157 | Ordering, SynchScope); |
Amara Emerson | 268c743 | 2013-09-26 12:22:36 +0000 | [diff] [blame] | 4158 | CSEMap.InsertNode(N, IP); |
| 4159 | AllNodes.push_back(N); |
| 4160 | return SDValue(N, 0); |
| 4161 | } |
| 4162 | |
| 4163 | SDValue SelectionDAG::getAtomic(unsigned Opcode, SDLoc dl, EVT MemVT, |
Chris Lattner | 60bddc8 | 2010-09-21 04:53:42 +0000 | [diff] [blame] | 4164 | SDValue Chain, SDValue Ptr, SDValue Cmp, |
| 4165 | SDValue Swp, MachinePointerInfo PtrInfo, |
Eli Friedman | 55ba816 | 2011-07-29 03:05:32 +0000 | [diff] [blame] | 4166 | unsigned Alignment, |
| 4167 | AtomicOrdering Ordering, |
Michael Ilseman | 06b9690 | 2012-09-10 16:56:31 +0000 | [diff] [blame] | 4168 | SynchronizationScope SynchScope) { |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4169 | if (Alignment == 0) // Ensure that codegen never sees alignment 0 |
| 4170 | Alignment = getEVTAlignment(MemVT); |
| 4171 | |
Evan Cheng | ff89dcb | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 4172 | MachineFunction &MF = getMachineFunction(); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4173 | |
Jakob Stoklund Olesen | 36d29bc | 2012-08-28 03:11:32 +0000 | [diff] [blame] | 4174 | // All atomics are load and store, except for ATMOIC_LOAD and ATOMIC_STORE. |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4175 | // For now, atomics are considered to be volatile always. |
Eli Friedman | 981a010 | 2011-09-07 02:23:42 +0000 | [diff] [blame] | 4176 | // FIXME: Volatile isn't really correct; we should keep track of atomic |
| 4177 | // orderings in the memoperand. |
Jakob Stoklund Olesen | 36d29bc | 2012-08-28 03:11:32 +0000 | [diff] [blame] | 4178 | unsigned Flags = MachineMemOperand::MOVolatile; |
| 4179 | if (Opcode != ISD::ATOMIC_STORE) |
| 4180 | Flags |= MachineMemOperand::MOLoad; |
| 4181 | if (Opcode != ISD::ATOMIC_LOAD) |
| 4182 | Flags |= MachineMemOperand::MOStore; |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4183 | |
| 4184 | MachineMemOperand *MMO = |
Chris Lattner | 60bddc8 | 2010-09-21 04:53:42 +0000 | [diff] [blame] | 4185 | MF.getMachineMemOperand(PtrInfo, Flags, MemVT.getStoreSize(), Alignment); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4186 | |
Eli Friedman | 55ba816 | 2011-07-29 03:05:32 +0000 | [diff] [blame] | 4187 | return getAtomic(Opcode, dl, MemVT, Chain, Ptr, Cmp, Swp, MMO, |
| 4188 | Ordering, SynchScope); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4189 | } |
| 4190 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4191 | SDValue SelectionDAG::getAtomic(unsigned Opcode, SDLoc dl, EVT MemVT, |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4192 | SDValue Chain, |
| 4193 | SDValue Ptr, SDValue Cmp, |
Eli Friedman | 55ba816 | 2011-07-29 03:05:32 +0000 | [diff] [blame] | 4194 | SDValue Swp, MachineMemOperand *MMO, |
| 4195 | AtomicOrdering Ordering, |
| 4196 | SynchronizationScope SynchScope) { |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4197 | assert(Opcode == ISD::ATOMIC_CMP_SWAP && "Invalid Atomic Op"); |
| 4198 | assert(Cmp.getValueType() == Swp.getValueType() && "Invalid Atomic Op Types"); |
| 4199 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4200 | EVT VT = Cmp.getValueType(); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4201 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4202 | SDVTList VTs = getVTList(VT, MVT::Other); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4203 | SDValue Ops[] = {Chain, Ptr, Cmp, Swp}; |
Amara Emerson | 268c743 | 2013-09-26 12:22:36 +0000 | [diff] [blame] | 4204 | return getAtomic(Opcode, dl, MemVT, VTs, Ops, 4, MMO, Ordering, SynchScope); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4205 | } |
| 4206 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4207 | SDValue SelectionDAG::getAtomic(unsigned Opcode, SDLoc dl, EVT MemVT, |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4208 | SDValue Chain, |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 4209 | SDValue Ptr, SDValue Val, |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4210 | const Value* PtrVal, |
Eli Friedman | 55ba816 | 2011-07-29 03:05:32 +0000 | [diff] [blame] | 4211 | unsigned Alignment, |
| 4212 | AtomicOrdering Ordering, |
| 4213 | SynchronizationScope SynchScope) { |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4214 | if (Alignment == 0) // Ensure that codegen never sees alignment 0 |
| 4215 | Alignment = getEVTAlignment(MemVT); |
| 4216 | |
Evan Cheng | ff89dcb | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 4217 | MachineFunction &MF = getMachineFunction(); |
Jakob Stoklund Olesen | 36d29bc | 2012-08-28 03:11:32 +0000 | [diff] [blame] | 4218 | // An atomic store does not load. An atomic load does not store. |
Eli Friedman | 981a010 | 2011-09-07 02:23:42 +0000 | [diff] [blame] | 4219 | // (An atomicrmw obviously both loads and stores.) |
Jakob Stoklund Olesen | 36d29bc | 2012-08-28 03:11:32 +0000 | [diff] [blame] | 4220 | // For now, atomics are considered to be volatile always, and they are |
| 4221 | // chained as such. |
Eli Friedman | 981a010 | 2011-09-07 02:23:42 +0000 | [diff] [blame] | 4222 | // FIXME: Volatile isn't really correct; we should keep track of atomic |
| 4223 | // orderings in the memoperand. |
Jakob Stoklund Olesen | 36d29bc | 2012-08-28 03:11:32 +0000 | [diff] [blame] | 4224 | unsigned Flags = MachineMemOperand::MOVolatile; |
| 4225 | if (Opcode != ISD::ATOMIC_STORE) |
| 4226 | Flags |= MachineMemOperand::MOLoad; |
| 4227 | if (Opcode != ISD::ATOMIC_LOAD) |
| 4228 | Flags |= MachineMemOperand::MOStore; |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4229 | |
| 4230 | MachineMemOperand *MMO = |
Chris Lattner | 93a95ae | 2010-09-21 04:46:39 +0000 | [diff] [blame] | 4231 | MF.getMachineMemOperand(MachinePointerInfo(PtrVal), Flags, |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4232 | MemVT.getStoreSize(), Alignment); |
| 4233 | |
Eli Friedman | 55ba816 | 2011-07-29 03:05:32 +0000 | [diff] [blame] | 4234 | return getAtomic(Opcode, dl, MemVT, Chain, Ptr, Val, MMO, |
| 4235 | Ordering, SynchScope); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4236 | } |
| 4237 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4238 | SDValue SelectionDAG::getAtomic(unsigned Opcode, SDLoc dl, EVT MemVT, |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4239 | SDValue Chain, |
| 4240 | SDValue Ptr, SDValue Val, |
Eli Friedman | 55ba816 | 2011-07-29 03:05:32 +0000 | [diff] [blame] | 4241 | MachineMemOperand *MMO, |
| 4242 | AtomicOrdering Ordering, |
| 4243 | SynchronizationScope SynchScope) { |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4244 | assert((Opcode == ISD::ATOMIC_LOAD_ADD || |
| 4245 | Opcode == ISD::ATOMIC_LOAD_SUB || |
| 4246 | Opcode == ISD::ATOMIC_LOAD_AND || |
| 4247 | Opcode == ISD::ATOMIC_LOAD_OR || |
| 4248 | Opcode == ISD::ATOMIC_LOAD_XOR || |
| 4249 | Opcode == ISD::ATOMIC_LOAD_NAND || |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 4250 | Opcode == ISD::ATOMIC_LOAD_MIN || |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4251 | Opcode == ISD::ATOMIC_LOAD_MAX || |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 4252 | Opcode == ISD::ATOMIC_LOAD_UMIN || |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4253 | Opcode == ISD::ATOMIC_LOAD_UMAX || |
Eli Friedman | 327236c | 2011-08-24 20:50:09 +0000 | [diff] [blame] | 4254 | Opcode == ISD::ATOMIC_SWAP || |
| 4255 | Opcode == ISD::ATOMIC_STORE) && |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4256 | "Invalid Atomic Op"); |
| 4257 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4258 | EVT VT = Val.getValueType(); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4259 | |
Eli Friedman | 327236c | 2011-08-24 20:50:09 +0000 | [diff] [blame] | 4260 | SDVTList VTs = Opcode == ISD::ATOMIC_STORE ? getVTList(MVT::Other) : |
| 4261 | getVTList(VT, MVT::Other); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4262 | SDValue Ops[] = {Chain, Ptr, Val}; |
Amara Emerson | 268c743 | 2013-09-26 12:22:36 +0000 | [diff] [blame] | 4263 | return getAtomic(Opcode, dl, MemVT, VTs, Ops, 3, MMO, Ordering, SynchScope); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4264 | } |
| 4265 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4266 | SDValue SelectionDAG::getAtomic(unsigned Opcode, SDLoc dl, EVT MemVT, |
Eli Friedman | 327236c | 2011-08-24 20:50:09 +0000 | [diff] [blame] | 4267 | EVT VT, SDValue Chain, |
| 4268 | SDValue Ptr, |
| 4269 | const Value* PtrVal, |
| 4270 | unsigned Alignment, |
| 4271 | AtomicOrdering Ordering, |
| 4272 | SynchronizationScope SynchScope) { |
| 4273 | if (Alignment == 0) // Ensure that codegen never sees alignment 0 |
| 4274 | Alignment = getEVTAlignment(MemVT); |
| 4275 | |
| 4276 | MachineFunction &MF = getMachineFunction(); |
Jakob Stoklund Olesen | 36d29bc | 2012-08-28 03:11:32 +0000 | [diff] [blame] | 4277 | // An atomic store does not load. An atomic load does not store. |
| 4278 | // (An atomicrmw obviously both loads and stores.) |
| 4279 | // For now, atomics are considered to be volatile always, and they are |
| 4280 | // chained as such. |
Eli Friedman | 981a010 | 2011-09-07 02:23:42 +0000 | [diff] [blame] | 4281 | // FIXME: Volatile isn't really correct; we should keep track of atomic |
| 4282 | // orderings in the memoperand. |
Jakob Stoklund Olesen | 36d29bc | 2012-08-28 03:11:32 +0000 | [diff] [blame] | 4283 | unsigned Flags = MachineMemOperand::MOVolatile; |
| 4284 | if (Opcode != ISD::ATOMIC_STORE) |
| 4285 | Flags |= MachineMemOperand::MOLoad; |
| 4286 | if (Opcode != ISD::ATOMIC_LOAD) |
| 4287 | Flags |= MachineMemOperand::MOStore; |
Eli Friedman | 327236c | 2011-08-24 20:50:09 +0000 | [diff] [blame] | 4288 | |
| 4289 | MachineMemOperand *MMO = |
| 4290 | MF.getMachineMemOperand(MachinePointerInfo(PtrVal), Flags, |
| 4291 | MemVT.getStoreSize(), Alignment); |
| 4292 | |
| 4293 | return getAtomic(Opcode, dl, MemVT, VT, Chain, Ptr, MMO, |
| 4294 | Ordering, SynchScope); |
| 4295 | } |
| 4296 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4297 | SDValue SelectionDAG::getAtomic(unsigned Opcode, SDLoc dl, EVT MemVT, |
Eli Friedman | 327236c | 2011-08-24 20:50:09 +0000 | [diff] [blame] | 4298 | EVT VT, SDValue Chain, |
| 4299 | SDValue Ptr, |
| 4300 | MachineMemOperand *MMO, |
| 4301 | AtomicOrdering Ordering, |
| 4302 | SynchronizationScope SynchScope) { |
| 4303 | assert(Opcode == ISD::ATOMIC_LOAD && "Invalid Atomic Op"); |
| 4304 | |
| 4305 | SDVTList VTs = getVTList(VT, MVT::Other); |
Eli Friedman | 327236c | 2011-08-24 20:50:09 +0000 | [diff] [blame] | 4306 | SDValue Ops[] = {Chain, Ptr}; |
Amara Emerson | 268c743 | 2013-09-26 12:22:36 +0000 | [diff] [blame] | 4307 | return getAtomic(Opcode, dl, MemVT, VTs, Ops, 2, MMO, Ordering, SynchScope); |
Eli Friedman | 327236c | 2011-08-24 20:50:09 +0000 | [diff] [blame] | 4308 | } |
| 4309 | |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 4310 | /// getMergeValues - Create a MERGE_VALUES node from the given operands. |
Dale Johannesen | 54c9452 | 2009-02-02 20:47:48 +0000 | [diff] [blame] | 4311 | SDValue SelectionDAG::getMergeValues(const SDValue *Ops, unsigned NumOps, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4312 | SDLoc dl) { |
Dale Johannesen | 54c9452 | 2009-02-02 20:47:48 +0000 | [diff] [blame] | 4313 | if (NumOps == 1) |
| 4314 | return Ops[0]; |
| 4315 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4316 | SmallVector<EVT, 4> VTs; |
Dale Johannesen | 54c9452 | 2009-02-02 20:47:48 +0000 | [diff] [blame] | 4317 | VTs.reserve(NumOps); |
| 4318 | for (unsigned i = 0; i < NumOps; ++i) |
| 4319 | VTs.push_back(Ops[i].getValueType()); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 4320 | return getNode(ISD::MERGE_VALUES, dl, getVTList(&VTs[0], NumOps), |
Dale Johannesen | 54c9452 | 2009-02-02 20:47:48 +0000 | [diff] [blame] | 4321 | Ops, NumOps); |
| 4322 | } |
| 4323 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4324 | SDValue |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4325 | SelectionDAG::getMemIntrinsicNode(unsigned Opcode, SDLoc dl, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4326 | const EVT *VTs, unsigned NumVTs, |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4327 | const SDValue *Ops, unsigned NumOps, |
Chris Lattner | e9ba5dd | 2010-09-21 04:57:15 +0000 | [diff] [blame] | 4328 | EVT MemVT, MachinePointerInfo PtrInfo, |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4329 | unsigned Align, bool Vol, |
| 4330 | bool ReadMem, bool WriteMem) { |
| 4331 | return getMemIntrinsicNode(Opcode, dl, makeVTList(VTs, NumVTs), Ops, NumOps, |
Chris Lattner | e9ba5dd | 2010-09-21 04:57:15 +0000 | [diff] [blame] | 4332 | MemVT, PtrInfo, Align, Vol, |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4333 | ReadMem, WriteMem); |
| 4334 | } |
| 4335 | |
| 4336 | SDValue |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4337 | SelectionDAG::getMemIntrinsicNode(unsigned Opcode, SDLoc dl, SDVTList VTList, |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4338 | const SDValue *Ops, unsigned NumOps, |
Chris Lattner | e9ba5dd | 2010-09-21 04:57:15 +0000 | [diff] [blame] | 4339 | EVT MemVT, MachinePointerInfo PtrInfo, |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4340 | unsigned Align, bool Vol, |
| 4341 | bool ReadMem, bool WriteMem) { |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4342 | if (Align == 0) // Ensure that codegen never sees alignment 0 |
| 4343 | Align = getEVTAlignment(MemVT); |
| 4344 | |
| 4345 | MachineFunction &MF = getMachineFunction(); |
| 4346 | unsigned Flags = 0; |
| 4347 | if (WriteMem) |
| 4348 | Flags |= MachineMemOperand::MOStore; |
| 4349 | if (ReadMem) |
| 4350 | Flags |= MachineMemOperand::MOLoad; |
| 4351 | if (Vol) |
| 4352 | Flags |= MachineMemOperand::MOVolatile; |
| 4353 | MachineMemOperand *MMO = |
Chris Lattner | e9ba5dd | 2010-09-21 04:57:15 +0000 | [diff] [blame] | 4354 | MF.getMachineMemOperand(PtrInfo, Flags, MemVT.getStoreSize(), Align); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4355 | |
| 4356 | return getMemIntrinsicNode(Opcode, dl, VTList, Ops, NumOps, MemVT, MMO); |
| 4357 | } |
| 4358 | |
| 4359 | SDValue |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4360 | SelectionDAG::getMemIntrinsicNode(unsigned Opcode, SDLoc dl, SDVTList VTList, |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4361 | const SDValue *Ops, unsigned NumOps, |
| 4362 | EVT MemVT, MachineMemOperand *MMO) { |
| 4363 | assert((Opcode == ISD::INTRINSIC_VOID || |
| 4364 | Opcode == ISD::INTRINSIC_W_CHAIN || |
Dale Johannesen | 1de4aa9 | 2010-10-26 23:11:10 +0000 | [diff] [blame] | 4365 | Opcode == ISD::PREFETCH || |
Nadav Rotem | c05d306 | 2012-09-06 09:17:37 +0000 | [diff] [blame] | 4366 | Opcode == ISD::LIFETIME_START || |
| 4367 | Opcode == ISD::LIFETIME_END || |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4368 | (Opcode <= INT_MAX && |
| 4369 | (int)Opcode >= ISD::FIRST_TARGET_MEMORY_OPCODE)) && |
| 4370 | "Opcode is not a memory-accessing opcode!"); |
| 4371 | |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4372 | // Memoize the node unless it returns a flag. |
| 4373 | MemIntrinsicSDNode *N; |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 4374 | if (VTList.VTs[VTList.NumVTs-1] != MVT::Glue) { |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4375 | FoldingSetNodeID ID; |
| 4376 | AddNodeIDNode(ID, Opcode, VTList, Ops, NumOps); |
Pete Cooper | 32ecfb4 | 2012-07-30 20:23:19 +0000 | [diff] [blame] | 4377 | ID.AddInteger(MMO->getPointerInfo().getAddrSpace()); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4378 | void *IP = 0; |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4379 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) { |
| 4380 | cast<MemIntrinsicSDNode>(E)->refineAlignment(MMO); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4381 | return SDValue(E, 0); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4382 | } |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 4383 | |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 4384 | N = new (NodeAllocator) MemIntrinsicSDNode(Opcode, dl.getIROrder(), |
| 4385 | dl.getDebugLoc(), VTList, Ops, |
| 4386 | NumOps, MemVT, MMO); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4387 | CSEMap.InsertNode(N, IP); |
| 4388 | } else { |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 4389 | N = new (NodeAllocator) MemIntrinsicSDNode(Opcode, dl.getIROrder(), |
| 4390 | dl.getDebugLoc(), VTList, Ops, |
| 4391 | NumOps, MemVT, MMO); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4392 | } |
| 4393 | AllNodes.push_back(N); |
| 4394 | return SDValue(N, 0); |
| 4395 | } |
| 4396 | |
Chris Lattner | d0e139f | 2010-09-21 17:24:05 +0000 | [diff] [blame] | 4397 | /// InferPointerInfo - If the specified ptr/offset is a frame index, infer a |
| 4398 | /// MachinePointerInfo record from it. This is particularly useful because the |
| 4399 | /// code generator has many cases where it doesn't bother passing in a |
| 4400 | /// MachinePointerInfo to getLoad or getStore when it has "FI+Cst". |
| 4401 | static MachinePointerInfo InferPointerInfo(SDValue Ptr, int64_t Offset = 0) { |
| 4402 | // If this is FI+Offset, we can model it. |
| 4403 | if (const FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Ptr)) |
| 4404 | return MachinePointerInfo::getFixedStack(FI->getIndex(), Offset); |
| 4405 | |
| 4406 | // If this is (FI+Offset1)+Offset2, we can model it. |
| 4407 | if (Ptr.getOpcode() != ISD::ADD || |
| 4408 | !isa<ConstantSDNode>(Ptr.getOperand(1)) || |
| 4409 | !isa<FrameIndexSDNode>(Ptr.getOperand(0))) |
| 4410 | return MachinePointerInfo(); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4411 | |
Chris Lattner | d0e139f | 2010-09-21 17:24:05 +0000 | [diff] [blame] | 4412 | int FI = cast<FrameIndexSDNode>(Ptr.getOperand(0))->getIndex(); |
| 4413 | return MachinePointerInfo::getFixedStack(FI, Offset+ |
| 4414 | cast<ConstantSDNode>(Ptr.getOperand(1))->getSExtValue()); |
| 4415 | } |
| 4416 | |
| 4417 | /// InferPointerInfo - If the specified ptr/offset is a frame index, infer a |
| 4418 | /// MachinePointerInfo record from it. This is particularly useful because the |
| 4419 | /// code generator has many cases where it doesn't bother passing in a |
| 4420 | /// MachinePointerInfo to getLoad or getStore when it has "FI+Cst". |
| 4421 | static MachinePointerInfo InferPointerInfo(SDValue Ptr, SDValue OffsetOp) { |
| 4422 | // If the 'Offset' value isn't a constant, we can't handle this. |
| 4423 | if (ConstantSDNode *OffsetNode = dyn_cast<ConstantSDNode>(OffsetOp)) |
| 4424 | return InferPointerInfo(Ptr, OffsetNode->getSExtValue()); |
| 4425 | if (OffsetOp.getOpcode() == ISD::UNDEF) |
| 4426 | return InferPointerInfo(Ptr); |
| 4427 | return MachinePointerInfo(); |
| 4428 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4429 | |
Chris Lattner | d0e139f | 2010-09-21 17:24:05 +0000 | [diff] [blame] | 4430 | |
Chris Lattner | 5c5cb2a | 2010-09-21 05:10:45 +0000 | [diff] [blame] | 4431 | SDValue |
| 4432 | SelectionDAG::getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4433 | EVT VT, SDLoc dl, SDValue Chain, |
Chris Lattner | 5c5cb2a | 2010-09-21 05:10:45 +0000 | [diff] [blame] | 4434 | SDValue Ptr, SDValue Offset, |
| 4435 | MachinePointerInfo PtrInfo, EVT MemVT, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 4436 | bool isVolatile, bool isNonTemporal, bool isInvariant, |
Rafael Espindola | 95d594c | 2012-03-31 18:14:00 +0000 | [diff] [blame] | 4437 | unsigned Alignment, const MDNode *TBAAInfo, |
| 4438 | const MDNode *Ranges) { |
Michael Ilseman | 06b9690 | 2012-09-10 16:56:31 +0000 | [diff] [blame] | 4439 | assert(Chain.getValueType() == MVT::Other && |
Nadav Rotem | aeb86fa | 2011-07-14 10:37:54 +0000 | [diff] [blame] | 4440 | "Invalid chain type"); |
Chris Lattner | 5c5cb2a | 2010-09-21 05:10:45 +0000 | [diff] [blame] | 4441 | if (Alignment == 0) // Ensure that codegen never sees alignment 0 |
| 4442 | Alignment = getEVTAlignment(VT); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4443 | |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4444 | unsigned Flags = MachineMemOperand::MOLoad; |
| 4445 | if (isVolatile) |
| 4446 | Flags |= MachineMemOperand::MOVolatile; |
David Greene | 1e55944 | 2010-02-15 17:00:31 +0000 | [diff] [blame] | 4447 | if (isNonTemporal) |
| 4448 | Flags |= MachineMemOperand::MONonTemporal; |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 4449 | if (isInvariant) |
| 4450 | Flags |= MachineMemOperand::MOInvariant; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4451 | |
Chris Lattner | d0e139f | 2010-09-21 17:24:05 +0000 | [diff] [blame] | 4452 | // If we don't have a PtrInfo, infer the trivial frame index case to simplify |
| 4453 | // clients. |
| 4454 | if (PtrInfo.V == 0) |
| 4455 | PtrInfo = InferPointerInfo(Ptr, Offset); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4456 | |
Chris Lattner | d0e139f | 2010-09-21 17:24:05 +0000 | [diff] [blame] | 4457 | MachineFunction &MF = getMachineFunction(); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4458 | MachineMemOperand *MMO = |
Dan Gohman | f96e4bd | 2010-10-20 00:31:05 +0000 | [diff] [blame] | 4459 | MF.getMachineMemOperand(PtrInfo, Flags, MemVT.getStoreSize(), Alignment, |
Rafael Espindola | 95d594c | 2012-03-31 18:14:00 +0000 | [diff] [blame] | 4460 | TBAAInfo, Ranges); |
Evan Cheng | bcc8017 | 2010-07-07 22:15:37 +0000 | [diff] [blame] | 4461 | return getLoad(AM, ExtType, VT, dl, Chain, Ptr, Offset, MemVT, MMO); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4462 | } |
| 4463 | |
| 4464 | SDValue |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4465 | SelectionDAG::getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4466 | EVT VT, SDLoc dl, SDValue Chain, |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4467 | SDValue Ptr, SDValue Offset, EVT MemVT, |
| 4468 | MachineMemOperand *MMO) { |
Dan Gohman | 8a55ce4 | 2009-09-23 21:02:20 +0000 | [diff] [blame] | 4469 | if (VT == MemVT) { |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4470 | ExtType = ISD::NON_EXTLOAD; |
| 4471 | } else if (ExtType == ISD::NON_EXTLOAD) { |
Dan Gohman | 8a55ce4 | 2009-09-23 21:02:20 +0000 | [diff] [blame] | 4472 | assert(VT == MemVT && "Non-extending load from different memory type!"); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4473 | } else { |
| 4474 | // Extending load. |
Dan Gohman | 2e141d7 | 2009-12-14 23:40:38 +0000 | [diff] [blame] | 4475 | assert(MemVT.getScalarType().bitsLT(VT.getScalarType()) && |
| 4476 | "Should only be an extending load, not truncating!"); |
Dan Gohman | 8a55ce4 | 2009-09-23 21:02:20 +0000 | [diff] [blame] | 4477 | assert(VT.isInteger() == MemVT.isInteger() && |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4478 | "Cannot convert from FP to Int or Int -> FP!"); |
Dan Gohman | 2e141d7 | 2009-12-14 23:40:38 +0000 | [diff] [blame] | 4479 | assert(VT.isVector() == MemVT.isVector() && |
| 4480 | "Cannot use trunc store to convert to or from a vector!"); |
| 4481 | assert((!VT.isVector() || |
| 4482 | VT.getVectorNumElements() == MemVT.getVectorNumElements()) && |
| 4483 | "Cannot use trunc store to change the number of vector elements!"); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4484 | } |
| 4485 | |
| 4486 | bool Indexed = AM != ISD::UNINDEXED; |
| 4487 | assert((Indexed || Offset.getOpcode() == ISD::UNDEF) && |
| 4488 | "Unindexed load with an offset!"); |
| 4489 | |
| 4490 | SDVTList VTs = Indexed ? |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4491 | getVTList(VT, Ptr.getValueType(), MVT::Other) : getVTList(VT, MVT::Other); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4492 | SDValue Ops[] = { Chain, Ptr, Offset }; |
| 4493 | FoldingSetNodeID ID; |
| 4494 | AddNodeIDNode(ID, ISD::LOAD, VTs, Ops, 3); |
Dan Gohman | 8a55ce4 | 2009-09-23 21:02:20 +0000 | [diff] [blame] | 4495 | ID.AddInteger(MemVT.getRawBits()); |
David Greene | 1157f79 | 2010-02-17 20:21:42 +0000 | [diff] [blame] | 4496 | ID.AddInteger(encodeMemSDNodeFlags(ExtType, AM, MMO->isVolatile(), |
Michael Ilseman | 06b9690 | 2012-09-10 16:56:31 +0000 | [diff] [blame] | 4497 | MMO->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 4498 | MMO->isInvariant())); |
Pete Cooper | 32ecfb4 | 2012-07-30 20:23:19 +0000 | [diff] [blame] | 4499 | ID.AddInteger(MMO->getPointerInfo().getAddrSpace()); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4500 | void *IP = 0; |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4501 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) { |
| 4502 | cast<LoadSDNode>(E)->refineAlignment(MMO); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4503 | return SDValue(E, 0); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4504 | } |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 4505 | SDNode *N = new (NodeAllocator) LoadSDNode(Ops, dl.getIROrder(), |
| 4506 | dl.getDebugLoc(), VTs, AM, ExtType, |
Dan Gohman | 9553188 | 2010-03-18 18:49:47 +0000 | [diff] [blame] | 4507 | MemVT, MMO); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4508 | CSEMap.InsertNode(N, IP); |
| 4509 | AllNodes.push_back(N); |
| 4510 | return SDValue(N, 0); |
| 4511 | } |
| 4512 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4513 | SDValue SelectionDAG::getLoad(EVT VT, SDLoc dl, |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4514 | SDValue Chain, SDValue Ptr, |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 4515 | MachinePointerInfo PtrInfo, |
| 4516 | bool isVolatile, bool isNonTemporal, |
Michael Ilseman | 06b9690 | 2012-09-10 16:56:31 +0000 | [diff] [blame] | 4517 | bool isInvariant, unsigned Alignment, |
Rafael Espindola | 95d594c | 2012-03-31 18:14:00 +0000 | [diff] [blame] | 4518 | const MDNode *TBAAInfo, |
| 4519 | const MDNode *Ranges) { |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 4520 | SDValue Undef = getUNDEF(Ptr.getValueType()); |
| 4521 | return getLoad(ISD::UNINDEXED, ISD::NON_EXTLOAD, VT, dl, Chain, Ptr, Undef, |
Rafael Espindola | 95d594c | 2012-03-31 18:14:00 +0000 | [diff] [blame] | 4522 | PtrInfo, VT, isVolatile, isNonTemporal, isInvariant, Alignment, |
| 4523 | TBAAInfo, Ranges); |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 4524 | } |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4525 | |
Richard Sandiford | 66589dc | 2013-10-28 11:17:59 +0000 | [diff] [blame] | 4526 | SDValue SelectionDAG::getLoad(EVT VT, SDLoc dl, |
| 4527 | SDValue Chain, SDValue Ptr, |
| 4528 | MachineMemOperand *MMO) { |
| 4529 | SDValue Undef = getUNDEF(Ptr.getValueType()); |
| 4530 | return getLoad(ISD::UNINDEXED, ISD::NON_EXTLOAD, VT, dl, Chain, Ptr, Undef, |
| 4531 | VT, MMO); |
| 4532 | } |
| 4533 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4534 | SDValue SelectionDAG::getExtLoad(ISD::LoadExtType ExtType, SDLoc dl, EVT VT, |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 4535 | SDValue Chain, SDValue Ptr, |
| 4536 | MachinePointerInfo PtrInfo, EVT MemVT, |
| 4537 | bool isVolatile, bool isNonTemporal, |
Dan Gohman | f96e4bd | 2010-10-20 00:31:05 +0000 | [diff] [blame] | 4538 | unsigned Alignment, const MDNode *TBAAInfo) { |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 4539 | SDValue Undef = getUNDEF(Ptr.getValueType()); |
| 4540 | return getLoad(ISD::UNINDEXED, ExtType, VT, dl, Chain, Ptr, Undef, |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 4541 | PtrInfo, MemVT, isVolatile, isNonTemporal, false, Alignment, |
Dan Gohman | f96e4bd | 2010-10-20 00:31:05 +0000 | [diff] [blame] | 4542 | TBAAInfo); |
Chris Lattner | e72f202 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 4543 | } |
| 4544 | |
| 4545 | |
Richard Sandiford | 66589dc | 2013-10-28 11:17:59 +0000 | [diff] [blame] | 4546 | SDValue SelectionDAG::getExtLoad(ISD::LoadExtType ExtType, SDLoc dl, EVT VT, |
| 4547 | SDValue Chain, SDValue Ptr, EVT MemVT, |
| 4548 | MachineMemOperand *MMO) { |
| 4549 | SDValue Undef = getUNDEF(Ptr.getValueType()); |
| 4550 | return getLoad(ISD::UNINDEXED, ExtType, VT, dl, Chain, Ptr, Undef, |
| 4551 | MemVT, MMO); |
| 4552 | } |
| 4553 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4554 | SDValue |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4555 | SelectionDAG::getIndexedLoad(SDValue OrigLoad, SDLoc dl, SDValue Base, |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4556 | SDValue Offset, ISD::MemIndexedMode AM) { |
| 4557 | LoadSDNode *LD = cast<LoadSDNode>(OrigLoad); |
| 4558 | assert(LD->getOffset().getOpcode() == ISD::UNDEF && |
| 4559 | "Load is already a indexed load!"); |
Evan Cheng | bcc8017 | 2010-07-07 22:15:37 +0000 | [diff] [blame] | 4560 | return getLoad(AM, LD->getExtensionType(), OrigLoad.getValueType(), dl, |
Chris Lattner | d0e139f | 2010-09-21 17:24:05 +0000 | [diff] [blame] | 4561 | LD->getChain(), Base, Offset, LD->getPointerInfo(), |
Michael Ilseman | 06b9690 | 2012-09-10 16:56:31 +0000 | [diff] [blame] | 4562 | LD->getMemoryVT(), LD->isVolatile(), LD->isNonTemporal(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 4563 | false, LD->getAlignment()); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4564 | } |
| 4565 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4566 | SDValue SelectionDAG::getStore(SDValue Chain, SDLoc dl, SDValue Val, |
Chris Lattner | 5c5cb2a | 2010-09-21 05:10:45 +0000 | [diff] [blame] | 4567 | SDValue Ptr, MachinePointerInfo PtrInfo, |
David Greene | 1e55944 | 2010-02-15 17:00:31 +0000 | [diff] [blame] | 4568 | bool isVolatile, bool isNonTemporal, |
Dan Gohman | f96e4bd | 2010-10-20 00:31:05 +0000 | [diff] [blame] | 4569 | unsigned Alignment, const MDNode *TBAAInfo) { |
Michael Ilseman | 06b9690 | 2012-09-10 16:56:31 +0000 | [diff] [blame] | 4570 | assert(Chain.getValueType() == MVT::Other && |
Nadav Rotem | aeb86fa | 2011-07-14 10:37:54 +0000 | [diff] [blame] | 4571 | "Invalid chain type"); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4572 | if (Alignment == 0) // Ensure that codegen never sees alignment 0 |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4573 | Alignment = getEVTAlignment(Val.getValueType()); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4574 | |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4575 | unsigned Flags = MachineMemOperand::MOStore; |
| 4576 | if (isVolatile) |
| 4577 | Flags |= MachineMemOperand::MOVolatile; |
David Greene | 1e55944 | 2010-02-15 17:00:31 +0000 | [diff] [blame] | 4578 | if (isNonTemporal) |
| 4579 | Flags |= MachineMemOperand::MONonTemporal; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4580 | |
Chris Lattner | d0e139f | 2010-09-21 17:24:05 +0000 | [diff] [blame] | 4581 | if (PtrInfo.V == 0) |
| 4582 | PtrInfo = InferPointerInfo(Ptr); |
| 4583 | |
| 4584 | MachineFunction &MF = getMachineFunction(); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4585 | MachineMemOperand *MMO = |
Chris Lattner | 5c5cb2a | 2010-09-21 05:10:45 +0000 | [diff] [blame] | 4586 | MF.getMachineMemOperand(PtrInfo, Flags, |
Dan Gohman | f96e4bd | 2010-10-20 00:31:05 +0000 | [diff] [blame] | 4587 | Val.getValueType().getStoreSize(), Alignment, |
| 4588 | TBAAInfo); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4589 | |
| 4590 | return getStore(Chain, dl, Val, Ptr, MMO); |
| 4591 | } |
| 4592 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4593 | SDValue SelectionDAG::getStore(SDValue Chain, SDLoc dl, SDValue Val, |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4594 | SDValue Ptr, MachineMemOperand *MMO) { |
Michael Ilseman | 06b9690 | 2012-09-10 16:56:31 +0000 | [diff] [blame] | 4595 | assert(Chain.getValueType() == MVT::Other && |
Nadav Rotem | aeb86fa | 2011-07-14 10:37:54 +0000 | [diff] [blame] | 4596 | "Invalid chain type"); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4597 | EVT VT = Val.getValueType(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4598 | SDVTList VTs = getVTList(MVT::Other); |
Dale Johannesen | e8d7230 | 2009-02-06 23:05:02 +0000 | [diff] [blame] | 4599 | SDValue Undef = getUNDEF(Ptr.getValueType()); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4600 | SDValue Ops[] = { Chain, Val, Ptr, Undef }; |
| 4601 | FoldingSetNodeID ID; |
| 4602 | AddNodeIDNode(ID, ISD::STORE, VTs, Ops, 4); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4603 | ID.AddInteger(VT.getRawBits()); |
David Greene | 1157f79 | 2010-02-17 20:21:42 +0000 | [diff] [blame] | 4604 | ID.AddInteger(encodeMemSDNodeFlags(false, ISD::UNINDEXED, MMO->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 4605 | MMO->isNonTemporal(), MMO->isInvariant())); |
Pete Cooper | 32ecfb4 | 2012-07-30 20:23:19 +0000 | [diff] [blame] | 4606 | ID.AddInteger(MMO->getPointerInfo().getAddrSpace()); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4607 | void *IP = 0; |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4608 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) { |
| 4609 | cast<StoreSDNode>(E)->refineAlignment(MMO); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4610 | return SDValue(E, 0); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4611 | } |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 4612 | SDNode *N = new (NodeAllocator) StoreSDNode(Ops, dl.getIROrder(), |
| 4613 | dl.getDebugLoc(), VTs, |
| 4614 | ISD::UNINDEXED, false, VT, MMO); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4615 | CSEMap.InsertNode(N, IP); |
| 4616 | AllNodes.push_back(N); |
| 4617 | return SDValue(N, 0); |
| 4618 | } |
| 4619 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4620 | SDValue SelectionDAG::getTruncStore(SDValue Chain, SDLoc dl, SDValue Val, |
Chris Lattner | 5c5cb2a | 2010-09-21 05:10:45 +0000 | [diff] [blame] | 4621 | SDValue Ptr, MachinePointerInfo PtrInfo, |
| 4622 | EVT SVT,bool isVolatile, bool isNonTemporal, |
Dan Gohman | f96e4bd | 2010-10-20 00:31:05 +0000 | [diff] [blame] | 4623 | unsigned Alignment, |
| 4624 | const MDNode *TBAAInfo) { |
Michael Ilseman | 06b9690 | 2012-09-10 16:56:31 +0000 | [diff] [blame] | 4625 | assert(Chain.getValueType() == MVT::Other && |
Nadav Rotem | aeb86fa | 2011-07-14 10:37:54 +0000 | [diff] [blame] | 4626 | "Invalid chain type"); |
Chris Lattner | 5c5cb2a | 2010-09-21 05:10:45 +0000 | [diff] [blame] | 4627 | if (Alignment == 0) // Ensure that codegen never sees alignment 0 |
| 4628 | Alignment = getEVTAlignment(SVT); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4629 | |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4630 | unsigned Flags = MachineMemOperand::MOStore; |
| 4631 | if (isVolatile) |
| 4632 | Flags |= MachineMemOperand::MOVolatile; |
David Greene | 1e55944 | 2010-02-15 17:00:31 +0000 | [diff] [blame] | 4633 | if (isNonTemporal) |
| 4634 | Flags |= MachineMemOperand::MONonTemporal; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4635 | |
Chris Lattner | d0e139f | 2010-09-21 17:24:05 +0000 | [diff] [blame] | 4636 | if (PtrInfo.V == 0) |
| 4637 | PtrInfo = InferPointerInfo(Ptr); |
| 4638 | |
| 4639 | MachineFunction &MF = getMachineFunction(); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4640 | MachineMemOperand *MMO = |
Dan Gohman | f96e4bd | 2010-10-20 00:31:05 +0000 | [diff] [blame] | 4641 | MF.getMachineMemOperand(PtrInfo, Flags, SVT.getStoreSize(), Alignment, |
| 4642 | TBAAInfo); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4643 | |
| 4644 | return getTruncStore(Chain, dl, Val, Ptr, SVT, MMO); |
| 4645 | } |
| 4646 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4647 | SDValue SelectionDAG::getTruncStore(SDValue Chain, SDLoc dl, SDValue Val, |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4648 | SDValue Ptr, EVT SVT, |
| 4649 | MachineMemOperand *MMO) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4650 | EVT VT = Val.getValueType(); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4651 | |
Michael Ilseman | 06b9690 | 2012-09-10 16:56:31 +0000 | [diff] [blame] | 4652 | assert(Chain.getValueType() == MVT::Other && |
Nadav Rotem | aeb86fa | 2011-07-14 10:37:54 +0000 | [diff] [blame] | 4653 | "Invalid chain type"); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4654 | if (VT == SVT) |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4655 | return getStore(Chain, dl, Val, Ptr, MMO); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4656 | |
Dan Gohman | 2e141d7 | 2009-12-14 23:40:38 +0000 | [diff] [blame] | 4657 | assert(SVT.getScalarType().bitsLT(VT.getScalarType()) && |
| 4658 | "Should only be a truncating store, not extending!"); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4659 | assert(VT.isInteger() == SVT.isInteger() && |
| 4660 | "Can't do FP-INT conversion!"); |
Dan Gohman | 2e141d7 | 2009-12-14 23:40:38 +0000 | [diff] [blame] | 4661 | assert(VT.isVector() == SVT.isVector() && |
| 4662 | "Cannot use trunc store to convert to or from a vector!"); |
| 4663 | assert((!VT.isVector() || |
| 4664 | VT.getVectorNumElements() == SVT.getVectorNumElements()) && |
| 4665 | "Cannot use trunc store to change the number of vector elements!"); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4666 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4667 | SDVTList VTs = getVTList(MVT::Other); |
Dale Johannesen | e8d7230 | 2009-02-06 23:05:02 +0000 | [diff] [blame] | 4668 | SDValue Undef = getUNDEF(Ptr.getValueType()); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4669 | SDValue Ops[] = { Chain, Val, Ptr, Undef }; |
| 4670 | FoldingSetNodeID ID; |
| 4671 | AddNodeIDNode(ID, ISD::STORE, VTs, Ops, 4); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4672 | ID.AddInteger(SVT.getRawBits()); |
David Greene | 1157f79 | 2010-02-17 20:21:42 +0000 | [diff] [blame] | 4673 | ID.AddInteger(encodeMemSDNodeFlags(true, ISD::UNINDEXED, MMO->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 4674 | MMO->isNonTemporal(), MMO->isInvariant())); |
Pete Cooper | 32ecfb4 | 2012-07-30 20:23:19 +0000 | [diff] [blame] | 4675 | ID.AddInteger(MMO->getPointerInfo().getAddrSpace()); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4676 | void *IP = 0; |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4677 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) { |
| 4678 | cast<StoreSDNode>(E)->refineAlignment(MMO); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4679 | return SDValue(E, 0); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 4680 | } |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 4681 | SDNode *N = new (NodeAllocator) StoreSDNode(Ops, dl.getIROrder(), |
| 4682 | dl.getDebugLoc(), VTs, |
| 4683 | ISD::UNINDEXED, true, SVT, MMO); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4684 | CSEMap.InsertNode(N, IP); |
| 4685 | AllNodes.push_back(N); |
| 4686 | return SDValue(N, 0); |
| 4687 | } |
| 4688 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4689 | SDValue |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4690 | SelectionDAG::getIndexedStore(SDValue OrigStore, SDLoc dl, SDValue Base, |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4691 | SDValue Offset, ISD::MemIndexedMode AM) { |
| 4692 | StoreSDNode *ST = cast<StoreSDNode>(OrigStore); |
| 4693 | assert(ST->getOffset().getOpcode() == ISD::UNDEF && |
| 4694 | "Store is already a indexed store!"); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4695 | SDVTList VTs = getVTList(Base.getValueType(), MVT::Other); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4696 | SDValue Ops[] = { ST->getChain(), ST->getValue(), Base, Offset }; |
| 4697 | FoldingSetNodeID ID; |
| 4698 | AddNodeIDNode(ID, ISD::STORE, VTs, Ops, 4); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4699 | ID.AddInteger(ST->getMemoryVT().getRawBits()); |
Dan Gohman | a7ce741 | 2009-02-03 00:08:45 +0000 | [diff] [blame] | 4700 | ID.AddInteger(ST->getRawSubclassData()); |
Pete Cooper | 32ecfb4 | 2012-07-30 20:23:19 +0000 | [diff] [blame] | 4701 | ID.AddInteger(ST->getPointerInfo().getAddrSpace()); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4702 | void *IP = 0; |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 4703 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4704 | return SDValue(E, 0); |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 4705 | |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 4706 | SDNode *N = new (NodeAllocator) StoreSDNode(Ops, dl.getIROrder(), |
| 4707 | dl.getDebugLoc(), VTs, AM, |
Dan Gohman | 9553188 | 2010-03-18 18:49:47 +0000 | [diff] [blame] | 4708 | ST->isTruncatingStore(), |
| 4709 | ST->getMemoryVT(), |
| 4710 | ST->getMemOperand()); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 4711 | CSEMap.InsertNode(N, IP); |
| 4712 | AllNodes.push_back(N); |
| 4713 | return SDValue(N, 0); |
| 4714 | } |
| 4715 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4716 | SDValue SelectionDAG::getVAArg(EVT VT, SDLoc dl, |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 4717 | SDValue Chain, SDValue Ptr, |
Rafael Espindola | 72d13ff | 2010-06-26 18:22:20 +0000 | [diff] [blame] | 4718 | SDValue SV, |
| 4719 | unsigned Align) { |
| 4720 | SDValue Ops[] = { Chain, Ptr, SV, getTargetConstant(Align, MVT::i32) }; |
| 4721 | return getNode(ISD::VAARG, dl, getVTList(VT, MVT::Other), Ops, 4); |
Dale Johannesen | 0f502f6 | 2009-02-03 22:26:09 +0000 | [diff] [blame] | 4722 | } |
| 4723 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4724 | SDValue SelectionDAG::getNode(unsigned Opcode, SDLoc DL, EVT VT, |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4725 | const SDUse *Ops, unsigned NumOps) { |
Dan Gohman | 6d9cdd5 | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 4726 | switch (NumOps) { |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4727 | case 0: return getNode(Opcode, DL, VT); |
| 4728 | case 1: return getNode(Opcode, DL, VT, Ops[0]); |
| 4729 | case 2: return getNode(Opcode, DL, VT, Ops[0], Ops[1]); |
| 4730 | case 3: return getNode(Opcode, DL, VT, Ops[0], Ops[1], Ops[2]); |
Dan Gohman | 6d9cdd5 | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 4731 | default: break; |
| 4732 | } |
| 4733 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4734 | // Copy from an SDUse array into an SDValue array for use with |
Dan Gohman | 6d9cdd5 | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 4735 | // the regular getNode logic. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4736 | SmallVector<SDValue, 8> NewOps(Ops, Ops + NumOps); |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4737 | return getNode(Opcode, DL, VT, &NewOps[0], NumOps); |
Dan Gohman | 6d9cdd5 | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 4738 | } |
| 4739 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4740 | SDValue SelectionDAG::getNode(unsigned Opcode, SDLoc DL, EVT VT, |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4741 | const SDValue *Ops, unsigned NumOps) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 4742 | switch (NumOps) { |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4743 | case 0: return getNode(Opcode, DL, VT); |
| 4744 | case 1: return getNode(Opcode, DL, VT, Ops[0]); |
| 4745 | case 2: return getNode(Opcode, DL, VT, Ops[0], Ops[1]); |
| 4746 | case 3: return getNode(Opcode, DL, VT, Ops[0], Ops[1], Ops[2]); |
Chris Lattner | ef847df | 2005-04-09 03:27:28 +0000 | [diff] [blame] | 4747 | default: break; |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 4748 | } |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 4749 | |
Chris Lattner | ef847df | 2005-04-09 03:27:28 +0000 | [diff] [blame] | 4750 | switch (Opcode) { |
| 4751 | default: break; |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 4752 | case ISD::SELECT_CC: { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 4753 | assert(NumOps == 5 && "SELECT_CC takes 5 operands!"); |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 4754 | assert(Ops[0].getValueType() == Ops[1].getValueType() && |
| 4755 | "LHS and RHS of condition must have same type!"); |
| 4756 | assert(Ops[2].getValueType() == Ops[3].getValueType() && |
| 4757 | "True and False arms of SelectCC must have same type!"); |
| 4758 | assert(Ops[2].getValueType() == VT && |
| 4759 | "select_cc node must be of same type as true and false value!"); |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 4760 | break; |
| 4761 | } |
| 4762 | case ISD::BR_CC: { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 4763 | assert(NumOps == 5 && "BR_CC takes 5 operands!"); |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 4764 | assert(Ops[2].getValueType() == Ops[3].getValueType() && |
| 4765 | "LHS/RHS of comparison should match types!"); |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 4766 | break; |
| 4767 | } |
Chris Lattner | ef847df | 2005-04-09 03:27:28 +0000 | [diff] [blame] | 4768 | } |
| 4769 | |
Chris Lattner | 385328c | 2005-05-14 07:42:29 +0000 | [diff] [blame] | 4770 | // Memoize nodes. |
Chris Lattner | 43247a1 | 2005-08-25 19:12:10 +0000 | [diff] [blame] | 4771 | SDNode *N; |
Chris Lattner | 0b3e525 | 2006-08-15 19:11:05 +0000 | [diff] [blame] | 4772 | SDVTList VTs = getVTList(VT); |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4773 | |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 4774 | if (VT != MVT::Glue) { |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 4775 | FoldingSetNodeID ID; |
| 4776 | AddNodeIDNode(ID, Opcode, VTs, Ops, NumOps); |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 4777 | void *IP = 0; |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4778 | |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 4779 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4780 | return SDValue(E, 0); |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4781 | |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 4782 | N = new (NodeAllocator) SDNode(Opcode, DL.getIROrder(), DL.getDebugLoc(), |
| 4783 | VTs, Ops, NumOps); |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 4784 | CSEMap.InsertNode(N, IP); |
Chris Lattner | 43247a1 | 2005-08-25 19:12:10 +0000 | [diff] [blame] | 4785 | } else { |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 4786 | N = new (NodeAllocator) SDNode(Opcode, DL.getIROrder(), DL.getDebugLoc(), |
| 4787 | VTs, Ops, NumOps); |
Chris Lattner | 43247a1 | 2005-08-25 19:12:10 +0000 | [diff] [blame] | 4788 | } |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4789 | |
Chris Lattner | ef847df | 2005-04-09 03:27:28 +0000 | [diff] [blame] | 4790 | AllNodes.push_back(N); |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 4791 | #ifndef NDEBUG |
Duncan Sands | 59d2dad | 2010-11-20 11:25:00 +0000 | [diff] [blame] | 4792 | VerifySDNode(N); |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 4793 | #endif |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4794 | return SDValue(N, 0); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 4795 | } |
| 4796 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4797 | SDValue SelectionDAG::getNode(unsigned Opcode, SDLoc DL, |
Benjamin Kramer | 3853f74 | 2013-03-07 20:33:29 +0000 | [diff] [blame] | 4798 | ArrayRef<EVT> ResultTys, |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4799 | const SDValue *Ops, unsigned NumOps) { |
Dan Gohman | fc16657 | 2009-04-09 23:54:40 +0000 | [diff] [blame] | 4800 | return getNode(Opcode, DL, getVTList(&ResultTys[0], ResultTys.size()), |
Chris Lattner | 2fa6d3b | 2006-08-14 23:31:51 +0000 | [diff] [blame] | 4801 | Ops, NumOps); |
| 4802 | } |
| 4803 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4804 | SDValue SelectionDAG::getNode(unsigned Opcode, SDLoc DL, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4805 | const EVT *VTs, unsigned NumVTs, |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4806 | const SDValue *Ops, unsigned NumOps) { |
Chris Lattner | 2fa6d3b | 2006-08-14 23:31:51 +0000 | [diff] [blame] | 4807 | if (NumVTs == 1) |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4808 | return getNode(Opcode, DL, VTs[0], Ops, NumOps); |
| 4809 | return getNode(Opcode, DL, makeVTList(VTs, NumVTs), Ops, NumOps); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 4810 | } |
| 4811 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4812 | SDValue SelectionDAG::getNode(unsigned Opcode, SDLoc DL, SDVTList VTList, |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4813 | const SDValue *Ops, unsigned NumOps) { |
Chris Lattner | be38416 | 2006-08-16 22:57:46 +0000 | [diff] [blame] | 4814 | if (VTList.NumVTs == 1) |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4815 | return getNode(Opcode, DL, VTList.VTs[0], Ops, NumOps); |
Chris Lattner | 89c3463 | 2005-05-14 06:20:26 +0000 | [diff] [blame] | 4816 | |
Daniel Dunbar | cfb8a1b | 2009-07-19 01:38:38 +0000 | [diff] [blame] | 4817 | #if 0 |
Chris Lattner | 5f056bf | 2005-07-10 01:55:33 +0000 | [diff] [blame] | 4818 | switch (Opcode) { |
Chris Lattner | e89083a | 2005-05-14 07:25:05 +0000 | [diff] [blame] | 4819 | // FIXME: figure out how to safely handle things like |
| 4820 | // int foo(int x) { return 1 << (x & 255); } |
| 4821 | // int bar() { return foo(256); } |
Chris Lattner | e89083a | 2005-05-14 07:25:05 +0000 | [diff] [blame] | 4822 | case ISD::SRA_PARTS: |
| 4823 | case ISD::SRL_PARTS: |
| 4824 | case ISD::SHL_PARTS: |
| 4825 | if (N3.getOpcode() == ISD::SIGN_EXTEND_INREG && |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4826 | cast<VTSDNode>(N3.getOperand(1))->getVT() != MVT::i1) |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4827 | return getNode(Opcode, DL, VT, N1, N2, N3.getOperand(0)); |
Chris Lattner | e89083a | 2005-05-14 07:25:05 +0000 | [diff] [blame] | 4828 | else if (N3.getOpcode() == ISD::AND) |
| 4829 | if (ConstantSDNode *AndRHS = dyn_cast<ConstantSDNode>(N3.getOperand(1))) { |
| 4830 | // If the and is only masking out bits that cannot effect the shift, |
| 4831 | // eliminate the and. |
Dan Gohman | d199636 | 2010-01-09 02:13:55 +0000 | [diff] [blame] | 4832 | unsigned NumBits = VT.getScalarType().getSizeInBits()*2; |
Chris Lattner | e89083a | 2005-05-14 07:25:05 +0000 | [diff] [blame] | 4833 | if ((AndRHS->getValue() & (NumBits-1)) == NumBits-1) |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4834 | return getNode(Opcode, DL, VT, N1, N2, N3.getOperand(0)); |
Chris Lattner | e89083a | 2005-05-14 07:25:05 +0000 | [diff] [blame] | 4835 | } |
| 4836 | break; |
Chris Lattner | 5f056bf | 2005-07-10 01:55:33 +0000 | [diff] [blame] | 4837 | } |
Daniel Dunbar | cfb8a1b | 2009-07-19 01:38:38 +0000 | [diff] [blame] | 4838 | #endif |
Chris Lattner | 89c3463 | 2005-05-14 06:20:26 +0000 | [diff] [blame] | 4839 | |
Chris Lattner | 43247a1 | 2005-08-25 19:12:10 +0000 | [diff] [blame] | 4840 | // Memoize the node unless it returns a flag. |
| 4841 | SDNode *N; |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 4842 | if (VTList.VTs[VTList.NumVTs-1] != MVT::Glue) { |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 4843 | FoldingSetNodeID ID; |
| 4844 | AddNodeIDNode(ID, Opcode, VTList, Ops, NumOps); |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 4845 | void *IP = 0; |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 4846 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4847 | return SDValue(E, 0); |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 4848 | |
Dan Gohman | 0e5f130 | 2008-07-07 23:02:41 +0000 | [diff] [blame] | 4849 | if (NumOps == 1) { |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 4850 | N = new (NodeAllocator) UnarySDNode(Opcode, DL.getIROrder(), |
| 4851 | DL.getDebugLoc(), VTList, Ops[0]); |
Dan Gohman | 0e5f130 | 2008-07-07 23:02:41 +0000 | [diff] [blame] | 4852 | } else if (NumOps == 2) { |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 4853 | N = new (NodeAllocator) BinarySDNode(Opcode, DL.getIROrder(), |
| 4854 | DL.getDebugLoc(), VTList, Ops[0], |
| 4855 | Ops[1]); |
Dan Gohman | 0e5f130 | 2008-07-07 23:02:41 +0000 | [diff] [blame] | 4856 | } else if (NumOps == 3) { |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 4857 | N = new (NodeAllocator) TernarySDNode(Opcode, DL.getIROrder(), |
| 4858 | DL.getDebugLoc(), VTList, Ops[0], |
| 4859 | Ops[1], Ops[2]); |
Dan Gohman | 0e5f130 | 2008-07-07 23:02:41 +0000 | [diff] [blame] | 4860 | } else { |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 4861 | N = new (NodeAllocator) SDNode(Opcode, DL.getIROrder(), DL.getDebugLoc(), |
| 4862 | VTList, Ops, NumOps); |
Dan Gohman | 0e5f130 | 2008-07-07 23:02:41 +0000 | [diff] [blame] | 4863 | } |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 4864 | CSEMap.InsertNode(N, IP); |
Chris Lattner | 43247a1 | 2005-08-25 19:12:10 +0000 | [diff] [blame] | 4865 | } else { |
Dan Gohman | 0e5f130 | 2008-07-07 23:02:41 +0000 | [diff] [blame] | 4866 | if (NumOps == 1) { |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 4867 | N = new (NodeAllocator) UnarySDNode(Opcode, DL.getIROrder(), |
| 4868 | DL.getDebugLoc(), VTList, Ops[0]); |
Dan Gohman | 0e5f130 | 2008-07-07 23:02:41 +0000 | [diff] [blame] | 4869 | } else if (NumOps == 2) { |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 4870 | N = new (NodeAllocator) BinarySDNode(Opcode, DL.getIROrder(), |
| 4871 | DL.getDebugLoc(), VTList, Ops[0], |
| 4872 | Ops[1]); |
Dan Gohman | 0e5f130 | 2008-07-07 23:02:41 +0000 | [diff] [blame] | 4873 | } else if (NumOps == 3) { |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 4874 | N = new (NodeAllocator) TernarySDNode(Opcode, DL.getIROrder(), |
| 4875 | DL.getDebugLoc(), VTList, Ops[0], |
| 4876 | Ops[1], Ops[2]); |
Dan Gohman | 0e5f130 | 2008-07-07 23:02:41 +0000 | [diff] [blame] | 4877 | } else { |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 4878 | N = new (NodeAllocator) SDNode(Opcode, DL.getIROrder(), DL.getDebugLoc(), |
| 4879 | VTList, Ops, NumOps); |
Dan Gohman | 0e5f130 | 2008-07-07 23:02:41 +0000 | [diff] [blame] | 4880 | } |
Chris Lattner | 43247a1 | 2005-08-25 19:12:10 +0000 | [diff] [blame] | 4881 | } |
Chris Lattner | 5fa4fa4 | 2005-05-14 06:42:57 +0000 | [diff] [blame] | 4882 | AllNodes.push_back(N); |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 4883 | #ifndef NDEBUG |
Duncan Sands | 59d2dad | 2010-11-20 11:25:00 +0000 | [diff] [blame] | 4884 | VerifySDNode(N); |
Duncan Sands | d038e04 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 4885 | #endif |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4886 | return SDValue(N, 0); |
Chris Lattner | 89c3463 | 2005-05-14 06:20:26 +0000 | [diff] [blame] | 4887 | } |
| 4888 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4889 | SDValue SelectionDAG::getNode(unsigned Opcode, SDLoc DL, SDVTList VTList) { |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4890 | return getNode(Opcode, DL, VTList, 0, 0); |
Dan Gohman | 08ce976 | 2007-10-08 15:49:58 +0000 | [diff] [blame] | 4891 | } |
| 4892 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4893 | SDValue SelectionDAG::getNode(unsigned Opcode, SDLoc DL, SDVTList VTList, |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4894 | SDValue N1) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4895 | SDValue Ops[] = { N1 }; |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4896 | return getNode(Opcode, DL, VTList, Ops, 1); |
Dan Gohman | 08ce976 | 2007-10-08 15:49:58 +0000 | [diff] [blame] | 4897 | } |
| 4898 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4899 | SDValue SelectionDAG::getNode(unsigned Opcode, SDLoc DL, SDVTList VTList, |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4900 | SDValue N1, SDValue N2) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4901 | SDValue Ops[] = { N1, N2 }; |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4902 | return getNode(Opcode, DL, VTList, Ops, 2); |
Dan Gohman | 08ce976 | 2007-10-08 15:49:58 +0000 | [diff] [blame] | 4903 | } |
| 4904 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4905 | SDValue SelectionDAG::getNode(unsigned Opcode, SDLoc DL, SDVTList VTList, |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4906 | SDValue N1, SDValue N2, SDValue N3) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4907 | SDValue Ops[] = { N1, N2, N3 }; |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4908 | return getNode(Opcode, DL, VTList, Ops, 3); |
Dan Gohman | 08ce976 | 2007-10-08 15:49:58 +0000 | [diff] [blame] | 4909 | } |
| 4910 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4911 | SDValue SelectionDAG::getNode(unsigned Opcode, SDLoc DL, SDVTList VTList, |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4912 | SDValue N1, SDValue N2, SDValue N3, |
| 4913 | SDValue N4) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4914 | SDValue Ops[] = { N1, N2, N3, N4 }; |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4915 | return getNode(Opcode, DL, VTList, Ops, 4); |
Dan Gohman | 08ce976 | 2007-10-08 15:49:58 +0000 | [diff] [blame] | 4916 | } |
| 4917 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4918 | SDValue SelectionDAG::getNode(unsigned Opcode, SDLoc DL, SDVTList VTList, |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4919 | SDValue N1, SDValue N2, SDValue N3, |
| 4920 | SDValue N4, SDValue N5) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4921 | SDValue Ops[] = { N1, N2, N3, N4, N5 }; |
Bill Wendling | 7ade28c | 2009-01-28 22:17:52 +0000 | [diff] [blame] | 4922 | return getNode(Opcode, DL, VTList, Ops, 5); |
Dan Gohman | 08ce976 | 2007-10-08 15:49:58 +0000 | [diff] [blame] | 4923 | } |
| 4924 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4925 | SDVTList SelectionDAG::getVTList(EVT VT) { |
Duncan Sands | af47b11 | 2007-10-16 09:56:48 +0000 | [diff] [blame] | 4926 | return makeVTList(SDNode::getValueTypeList(VT), 1); |
Chris Lattner | a325511 | 2005-11-08 23:30:28 +0000 | [diff] [blame] | 4927 | } |
| 4928 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4929 | SDVTList SelectionDAG::getVTList(EVT VT1, EVT VT2) { |
Wan Xiaofei | 8c955ea | 2013-10-22 08:02:02 +0000 | [diff] [blame] | 4930 | FoldingSetNodeID ID; |
| 4931 | ID.AddInteger(2U); |
| 4932 | ID.AddInteger(VT1.getRawBits()); |
| 4933 | ID.AddInteger(VT2.getRawBits()); |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 4934 | |
Wan Xiaofei | 8c955ea | 2013-10-22 08:02:02 +0000 | [diff] [blame] | 4935 | void *IP = 0; |
| 4936 | SDVTListNode *Result = VTListMap.FindNodeOrInsertPos(ID, IP); |
| 4937 | if (Result == NULL) { |
| 4938 | EVT *Array = Allocator.Allocate<EVT>(2); |
| 4939 | Array[0] = VT1; |
| 4940 | Array[1] = VT2; |
| 4941 | Result = new (Allocator) SDVTListNode(ID.Intern(Allocator), Array, 2); |
| 4942 | VTListMap.InsertNode(Result, IP); |
| 4943 | } |
| 4944 | return Result->getSDVTList(); |
Chris Lattner | a325511 | 2005-11-08 23:30:28 +0000 | [diff] [blame] | 4945 | } |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 4946 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4947 | SDVTList SelectionDAG::getVTList(EVT VT1, EVT VT2, EVT VT3) { |
Wan Xiaofei | 8c955ea | 2013-10-22 08:02:02 +0000 | [diff] [blame] | 4948 | FoldingSetNodeID ID; |
| 4949 | ID.AddInteger(3U); |
| 4950 | ID.AddInteger(VT1.getRawBits()); |
| 4951 | ID.AddInteger(VT2.getRawBits()); |
| 4952 | ID.AddInteger(VT3.getRawBits()); |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 4953 | |
Wan Xiaofei | 8c955ea | 2013-10-22 08:02:02 +0000 | [diff] [blame] | 4954 | void *IP = 0; |
| 4955 | SDVTListNode *Result = VTListMap.FindNodeOrInsertPos(ID, IP); |
| 4956 | if (Result == NULL) { |
| 4957 | EVT *Array = Allocator.Allocate<EVT>(3); |
| 4958 | Array[0] = VT1; |
| 4959 | Array[1] = VT2; |
| 4960 | Array[2] = VT3; |
| 4961 | Result = new (Allocator) SDVTListNode(ID.Intern(Allocator), Array, 3); |
| 4962 | VTListMap.InsertNode(Result, IP); |
| 4963 | } |
| 4964 | return Result->getSDVTList(); |
Chris Lattner | 70046e9 | 2006-08-15 17:46:01 +0000 | [diff] [blame] | 4965 | } |
| 4966 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4967 | SDVTList SelectionDAG::getVTList(EVT VT1, EVT VT2, EVT VT3, EVT VT4) { |
Wan Xiaofei | 8c955ea | 2013-10-22 08:02:02 +0000 | [diff] [blame] | 4968 | FoldingSetNodeID ID; |
| 4969 | ID.AddInteger(4U); |
| 4970 | ID.AddInteger(VT1.getRawBits()); |
| 4971 | ID.AddInteger(VT2.getRawBits()); |
| 4972 | ID.AddInteger(VT3.getRawBits()); |
| 4973 | ID.AddInteger(VT4.getRawBits()); |
Bill Wendling | 13d6d44 | 2008-12-01 23:28:22 +0000 | [diff] [blame] | 4974 | |
Wan Xiaofei | 8c955ea | 2013-10-22 08:02:02 +0000 | [diff] [blame] | 4975 | void *IP = 0; |
| 4976 | SDVTListNode *Result = VTListMap.FindNodeOrInsertPos(ID, IP); |
| 4977 | if (Result == NULL) { |
| 4978 | EVT *Array = Allocator.Allocate<EVT>(4); |
| 4979 | Array[0] = VT1; |
| 4980 | Array[1] = VT2; |
| 4981 | Array[2] = VT3; |
| 4982 | Array[3] = VT4; |
| 4983 | Result = new (Allocator) SDVTListNode(ID.Intern(Allocator), Array, 4); |
| 4984 | VTListMap.InsertNode(Result, IP); |
| 4985 | } |
| 4986 | return Result->getSDVTList(); |
Bill Wendling | 13d6d44 | 2008-12-01 23:28:22 +0000 | [diff] [blame] | 4987 | } |
| 4988 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4989 | SDVTList SelectionDAG::getVTList(const EVT *VTs, unsigned NumVTs) { |
Wan Xiaofei | 8c955ea | 2013-10-22 08:02:02 +0000 | [diff] [blame] | 4990 | FoldingSetNodeID ID; |
| 4991 | ID.AddInteger(NumVTs); |
| 4992 | for (unsigned index = 0; index < NumVTs; index++) { |
| 4993 | ID.AddInteger(VTs[index].getRawBits()); |
Chris Lattner | 70046e9 | 2006-08-15 17:46:01 +0000 | [diff] [blame] | 4994 | } |
| 4995 | |
Wan Xiaofei | 8c955ea | 2013-10-22 08:02:02 +0000 | [diff] [blame] | 4996 | void *IP = 0; |
| 4997 | SDVTListNode *Result = VTListMap.FindNodeOrInsertPos(ID, IP); |
| 4998 | if (Result == NULL) { |
| 4999 | EVT *Array = Allocator.Allocate<EVT>(NumVTs); |
| 5000 | std::copy(VTs, VTs + NumVTs, Array); |
| 5001 | Result = new (Allocator) SDVTListNode(ID.Intern(Allocator), Array, NumVTs); |
| 5002 | VTListMap.InsertNode(Result, IP); |
Chris Lattner | 70046e9 | 2006-08-15 17:46:01 +0000 | [diff] [blame] | 5003 | } |
Wan Xiaofei | 8c955ea | 2013-10-22 08:02:02 +0000 | [diff] [blame] | 5004 | return Result->getSDVTList(); |
Chris Lattner | 2fa6d3b | 2006-08-14 23:31:51 +0000 | [diff] [blame] | 5005 | } |
| 5006 | |
| 5007 | |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5008 | /// UpdateNodeOperands - *Mutate* the specified node in-place to have the |
| 5009 | /// specified operands. If the resultant node already exists in the DAG, |
| 5010 | /// this does not modify the specified node, instead it returns the node that |
| 5011 | /// already exists. If the resultant node does not exist in the DAG, the |
| 5012 | /// input node is returned. As a degenerate case, if you specify the same |
| 5013 | /// input operands as the node already has, the input node is returned. |
Dan Gohman | 027657d | 2010-06-18 15:30:29 +0000 | [diff] [blame] | 5014 | SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, SDValue Op) { |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5015 | assert(N->getNumOperands() == 1 && "Update with wrong number of operands"); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5016 | |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5017 | // Check to see if there is no change. |
Dan Gohman | 027657d | 2010-06-18 15:30:29 +0000 | [diff] [blame] | 5018 | if (Op == N->getOperand(0)) return N; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5019 | |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5020 | // See if the modified node already exists. |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 5021 | void *InsertPos = 0; |
| 5022 | if (SDNode *Existing = FindModifiedNodeSlot(N, Op, InsertPos)) |
Dan Gohman | 027657d | 2010-06-18 15:30:29 +0000 | [diff] [blame] | 5023 | return Existing; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5024 | |
Dan Gohman | 79acd2b | 2008-07-21 22:38:59 +0000 | [diff] [blame] | 5025 | // Nope it doesn't. Remove the node from its current place in the maps. |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 5026 | if (InsertPos) |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 5027 | if (!RemoveNodeFromCSEMaps(N)) |
| 5028 | InsertPos = 0; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5029 | |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5030 | // Now we update the operands. |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5031 | N->OperandList[0].set(Op); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5032 | |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5033 | // If this gets put into a CSE map, add it. |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 5034 | if (InsertPos) CSEMap.InsertNode(N, InsertPos); |
Dan Gohman | 027657d | 2010-06-18 15:30:29 +0000 | [diff] [blame] | 5035 | return N; |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5036 | } |
| 5037 | |
Dan Gohman | 027657d | 2010-06-18 15:30:29 +0000 | [diff] [blame] | 5038 | SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2) { |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5039 | assert(N->getNumOperands() == 2 && "Update with wrong number of operands"); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5040 | |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5041 | // Check to see if there is no change. |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5042 | if (Op1 == N->getOperand(0) && Op2 == N->getOperand(1)) |
Dan Gohman | 027657d | 2010-06-18 15:30:29 +0000 | [diff] [blame] | 5043 | return N; // No operands changed, just return the input node. |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5044 | |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5045 | // See if the modified node already exists. |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 5046 | void *InsertPos = 0; |
| 5047 | if (SDNode *Existing = FindModifiedNodeSlot(N, Op1, Op2, InsertPos)) |
Dan Gohman | 027657d | 2010-06-18 15:30:29 +0000 | [diff] [blame] | 5048 | return Existing; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5049 | |
Dan Gohman | 79acd2b | 2008-07-21 22:38:59 +0000 | [diff] [blame] | 5050 | // Nope it doesn't. Remove the node from its current place in the maps. |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 5051 | if (InsertPos) |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 5052 | if (!RemoveNodeFromCSEMaps(N)) |
| 5053 | InsertPos = 0; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5054 | |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5055 | // Now we update the operands. |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5056 | if (N->OperandList[0] != Op1) |
| 5057 | N->OperandList[0].set(Op1); |
| 5058 | if (N->OperandList[1] != Op2) |
| 5059 | N->OperandList[1].set(Op2); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5060 | |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5061 | // If this gets put into a CSE map, add it. |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 5062 | if (InsertPos) CSEMap.InsertNode(N, InsertPos); |
Dan Gohman | 027657d | 2010-06-18 15:30:29 +0000 | [diff] [blame] | 5063 | return N; |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5064 | } |
| 5065 | |
Dan Gohman | 027657d | 2010-06-18 15:30:29 +0000 | [diff] [blame] | 5066 | SDNode *SelectionDAG:: |
| 5067 | UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2, SDValue Op3) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5068 | SDValue Ops[] = { Op1, Op2, Op3 }; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 5069 | return UpdateNodeOperands(N, Ops, 3); |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5070 | } |
| 5071 | |
Dan Gohman | 027657d | 2010-06-18 15:30:29 +0000 | [diff] [blame] | 5072 | SDNode *SelectionDAG:: |
| 5073 | UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5074 | SDValue Op3, SDValue Op4) { |
| 5075 | SDValue Ops[] = { Op1, Op2, Op3, Op4 }; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 5076 | return UpdateNodeOperands(N, Ops, 4); |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5077 | } |
| 5078 | |
Dan Gohman | 027657d | 2010-06-18 15:30:29 +0000 | [diff] [blame] | 5079 | SDNode *SelectionDAG:: |
| 5080 | UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5081 | SDValue Op3, SDValue Op4, SDValue Op5) { |
| 5082 | SDValue Ops[] = { Op1, Op2, Op3, Op4, Op5 }; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 5083 | return UpdateNodeOperands(N, Ops, 5); |
Chris Lattner | 809ec11 | 2006-01-28 10:09:25 +0000 | [diff] [blame] | 5084 | } |
| 5085 | |
Dan Gohman | 027657d | 2010-06-18 15:30:29 +0000 | [diff] [blame] | 5086 | SDNode *SelectionDAG:: |
| 5087 | UpdateNodeOperands(SDNode *N, const SDValue *Ops, unsigned NumOps) { |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 5088 | assert(N->getNumOperands() == NumOps && |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5089 | "Update with wrong number of operands"); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5090 | |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5091 | // Check to see if there is no change. |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5092 | bool AnyChange = false; |
| 5093 | for (unsigned i = 0; i != NumOps; ++i) { |
| 5094 | if (Ops[i] != N->getOperand(i)) { |
| 5095 | AnyChange = true; |
| 5096 | break; |
| 5097 | } |
| 5098 | } |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5099 | |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5100 | // No operands changed, just return the input node. |
Dan Gohman | 027657d | 2010-06-18 15:30:29 +0000 | [diff] [blame] | 5101 | if (!AnyChange) return N; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5102 | |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5103 | // See if the modified node already exists. |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 5104 | void *InsertPos = 0; |
Chris Lattner | f06f35e | 2006-08-08 01:09:31 +0000 | [diff] [blame] | 5105 | if (SDNode *Existing = FindModifiedNodeSlot(N, Ops, NumOps, InsertPos)) |
Dan Gohman | 027657d | 2010-06-18 15:30:29 +0000 | [diff] [blame] | 5106 | return Existing; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5107 | |
Dan Gohman | 7ceda16 | 2008-05-02 00:05:03 +0000 | [diff] [blame] | 5108 | // Nope it doesn't. Remove the node from its current place in the maps. |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 5109 | if (InsertPos) |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 5110 | if (!RemoveNodeFromCSEMaps(N)) |
| 5111 | InsertPos = 0; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5112 | |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5113 | // Now we update the operands. |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5114 | for (unsigned i = 0; i != NumOps; ++i) |
| 5115 | if (N->OperandList[i] != Ops[i]) |
| 5116 | N->OperandList[i].set(Ops[i]); |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5117 | |
| 5118 | // If this gets put into a CSE map, add it. |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 5119 | if (InsertPos) CSEMap.InsertNode(N, InsertPos); |
Dan Gohman | 027657d | 2010-06-18 15:30:29 +0000 | [diff] [blame] | 5120 | return N; |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 5121 | } |
| 5122 | |
Dan Gohman | 0fe9c6e | 2008-07-07 20:57:48 +0000 | [diff] [blame] | 5123 | /// DropOperands - Release the operands and set this node to have |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5124 | /// zero operands. |
Dan Gohman | 0fe9c6e | 2008-07-07 20:57:48 +0000 | [diff] [blame] | 5125 | void SDNode::DropOperands() { |
Dan Gohman | 0fe9c6e | 2008-07-07 20:57:48 +0000 | [diff] [blame] | 5126 | // Unlike the code in MorphNodeTo that does this, we don't need to |
| 5127 | // watch for dead nodes here. |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5128 | for (op_iterator I = op_begin(), E = op_end(); I != E; ) { |
| 5129 | SDUse &Use = *I++; |
| 5130 | Use.set(SDValue()); |
| 5131 | } |
Chris Lattner | d429bcd | 2007-02-04 02:49:29 +0000 | [diff] [blame] | 5132 | } |
Chris Lattner | 149c58c | 2005-08-16 18:17:10 +0000 | [diff] [blame] | 5133 | |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5134 | /// SelectNodeTo - These are wrappers around MorphNodeTo that accept a |
| 5135 | /// machine opcode. |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 5136 | /// |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5137 | SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5138 | EVT VT) { |
Chris Lattner | 0b3e525 | 2006-08-15 19:11:05 +0000 | [diff] [blame] | 5139 | SDVTList VTs = getVTList(VT); |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5140 | return SelectNodeTo(N, MachineOpc, VTs, 0, 0); |
Chris Lattner | 7651fa4 | 2005-08-24 23:00:29 +0000 | [diff] [blame] | 5141 | } |
Chris Lattner | 0fb094f | 2005-11-19 01:44:53 +0000 | [diff] [blame] | 5142 | |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5143 | SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5144 | EVT VT, SDValue Op1) { |
Chris Lattner | 0b3e525 | 2006-08-15 19:11:05 +0000 | [diff] [blame] | 5145 | SDVTList VTs = getVTList(VT); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5146 | SDValue Ops[] = { Op1 }; |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5147 | return SelectNodeTo(N, MachineOpc, VTs, Ops, 1); |
Chris Lattner | 149c58c | 2005-08-16 18:17:10 +0000 | [diff] [blame] | 5148 | } |
Chris Lattner | 0fb094f | 2005-11-19 01:44:53 +0000 | [diff] [blame] | 5149 | |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5150 | SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5151 | EVT VT, SDValue Op1, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5152 | SDValue Op2) { |
Chris Lattner | 0b3e525 | 2006-08-15 19:11:05 +0000 | [diff] [blame] | 5153 | SDVTList VTs = getVTList(VT); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5154 | SDValue Ops[] = { Op1, Op2 }; |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5155 | return SelectNodeTo(N, MachineOpc, VTs, Ops, 2); |
Chris Lattner | 149c58c | 2005-08-16 18:17:10 +0000 | [diff] [blame] | 5156 | } |
Chris Lattner | 0fb094f | 2005-11-19 01:44:53 +0000 | [diff] [blame] | 5157 | |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5158 | SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5159 | EVT VT, SDValue Op1, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5160 | SDValue Op2, SDValue Op3) { |
Chris Lattner | 0b3e525 | 2006-08-15 19:11:05 +0000 | [diff] [blame] | 5161 | SDVTList VTs = getVTList(VT); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5162 | SDValue Ops[] = { Op1, Op2, Op3 }; |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5163 | return SelectNodeTo(N, MachineOpc, VTs, Ops, 3); |
Chris Lattner | 149c58c | 2005-08-16 18:17:10 +0000 | [diff] [blame] | 5164 | } |
Chris Lattner | c975e1d | 2005-08-21 22:30:30 +0000 | [diff] [blame] | 5165 | |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5166 | SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5167 | EVT VT, const SDValue *Ops, |
Evan Cheng | 694481e | 2006-08-27 08:08:54 +0000 | [diff] [blame] | 5168 | unsigned NumOps) { |
Chris Lattner | 0b3e525 | 2006-08-15 19:11:05 +0000 | [diff] [blame] | 5169 | SDVTList VTs = getVTList(VT); |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5170 | return SelectNodeTo(N, MachineOpc, VTs, Ops, NumOps); |
Dan Gohman | cd920d9 | 2008-07-02 23:23:19 +0000 | [diff] [blame] | 5171 | } |
| 5172 | |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5173 | SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5174 | EVT VT1, EVT VT2, const SDValue *Ops, |
Dan Gohman | cd920d9 | 2008-07-02 23:23:19 +0000 | [diff] [blame] | 5175 | unsigned NumOps) { |
| 5176 | SDVTList VTs = getVTList(VT1, VT2); |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5177 | return SelectNodeTo(N, MachineOpc, VTs, Ops, NumOps); |
Dan Gohman | cd920d9 | 2008-07-02 23:23:19 +0000 | [diff] [blame] | 5178 | } |
| 5179 | |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5180 | SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5181 | EVT VT1, EVT VT2) { |
Dan Gohman | cd920d9 | 2008-07-02 23:23:19 +0000 | [diff] [blame] | 5182 | SDVTList VTs = getVTList(VT1, VT2); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5183 | return SelectNodeTo(N, MachineOpc, VTs, (SDValue *)0, 0); |
Dan Gohman | cd920d9 | 2008-07-02 23:23:19 +0000 | [diff] [blame] | 5184 | } |
| 5185 | |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5186 | SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5187 | EVT VT1, EVT VT2, EVT VT3, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5188 | const SDValue *Ops, unsigned NumOps) { |
Dan Gohman | cd920d9 | 2008-07-02 23:23:19 +0000 | [diff] [blame] | 5189 | SDVTList VTs = getVTList(VT1, VT2, VT3); |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5190 | return SelectNodeTo(N, MachineOpc, VTs, Ops, NumOps); |
Dan Gohman | cd920d9 | 2008-07-02 23:23:19 +0000 | [diff] [blame] | 5191 | } |
| 5192 | |
Bill Wendling | 13d6d44 | 2008-12-01 23:28:22 +0000 | [diff] [blame] | 5193 | SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5194 | EVT VT1, EVT VT2, EVT VT3, EVT VT4, |
Bill Wendling | 13d6d44 | 2008-12-01 23:28:22 +0000 | [diff] [blame] | 5195 | const SDValue *Ops, unsigned NumOps) { |
| 5196 | SDVTList VTs = getVTList(VT1, VT2, VT3, VT4); |
| 5197 | return SelectNodeTo(N, MachineOpc, VTs, Ops, NumOps); |
| 5198 | } |
| 5199 | |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5200 | SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5201 | EVT VT1, EVT VT2, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5202 | SDValue Op1) { |
Dan Gohman | cd920d9 | 2008-07-02 23:23:19 +0000 | [diff] [blame] | 5203 | SDVTList VTs = getVTList(VT1, VT2); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5204 | SDValue Ops[] = { Op1 }; |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5205 | return SelectNodeTo(N, MachineOpc, VTs, Ops, 1); |
Andrew Lenharth | 7cf11b4 | 2006-01-23 21:51:14 +0000 | [diff] [blame] | 5206 | } |
Andrew Lenharth | 8c6f1ee | 2006-01-23 20:59:12 +0000 | [diff] [blame] | 5207 | |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5208 | SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5209 | EVT VT1, EVT VT2, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5210 | SDValue Op1, SDValue Op2) { |
Chris Lattner | 0b3e525 | 2006-08-15 19:11:05 +0000 | [diff] [blame] | 5211 | SDVTList VTs = getVTList(VT1, VT2); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5212 | SDValue Ops[] = { Op1, Op2 }; |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5213 | return SelectNodeTo(N, MachineOpc, VTs, Ops, 2); |
Chris Lattner | 0fb094f | 2005-11-19 01:44:53 +0000 | [diff] [blame] | 5214 | } |
| 5215 | |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5216 | SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5217 | EVT VT1, EVT VT2, |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5218 | SDValue Op1, SDValue Op2, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5219 | SDValue Op3) { |
Chris Lattner | 0b3e525 | 2006-08-15 19:11:05 +0000 | [diff] [blame] | 5220 | SDVTList VTs = getVTList(VT1, VT2); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5221 | SDValue Ops[] = { Op1, Op2, Op3 }; |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5222 | return SelectNodeTo(N, MachineOpc, VTs, Ops, 3); |
Dan Gohman | cd920d9 | 2008-07-02 23:23:19 +0000 | [diff] [blame] | 5223 | } |
| 5224 | |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5225 | SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5226 | EVT VT1, EVT VT2, EVT VT3, |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5227 | SDValue Op1, SDValue Op2, |
Bill Wendling | 13d6d44 | 2008-12-01 23:28:22 +0000 | [diff] [blame] | 5228 | SDValue Op3) { |
| 5229 | SDVTList VTs = getVTList(VT1, VT2, VT3); |
| 5230 | SDValue Ops[] = { Op1, Op2, Op3 }; |
| 5231 | return SelectNodeTo(N, MachineOpc, VTs, Ops, 3); |
| 5232 | } |
| 5233 | |
| 5234 | SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5235 | SDVTList VTs, const SDValue *Ops, |
Dan Gohman | cd920d9 | 2008-07-02 23:23:19 +0000 | [diff] [blame] | 5236 | unsigned NumOps) { |
Chris Lattner | 5857e0a | 2010-02-23 23:01:35 +0000 | [diff] [blame] | 5237 | N = MorphNodeTo(N, ~MachineOpc, VTs, Ops, NumOps); |
| 5238 | // Reset the NodeID to -1. |
| 5239 | N->setNodeId(-1); |
| 5240 | return N; |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5241 | } |
| 5242 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5243 | /// UpdadeSDLocOnMergedSDNode - If the opt level is -O0 then it throws away |
Devang Patel | 0508d04 | 2011-12-15 18:21:18 +0000 | [diff] [blame] | 5244 | /// the line number information on the merged node since it is not possible to |
| 5245 | /// preserve the information that operation is associated with multiple lines. |
| 5246 | /// This will make the debugger working better at -O0, were there is a higher |
| 5247 | /// probability having other instructions associated with that line. |
| 5248 | /// |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5249 | /// For IROrder, we keep the smaller of the two |
| 5250 | SDNode *SelectionDAG::UpdadeSDLocOnMergedSDNode(SDNode *N, SDLoc OLoc) { |
Devang Patel | 0508d04 | 2011-12-15 18:21:18 +0000 | [diff] [blame] | 5251 | DebugLoc NLoc = N->getDebugLoc(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5252 | if (!(NLoc.isUnknown()) && (OptLevel == CodeGenOpt::None) && |
| 5253 | (OLoc.getDebugLoc() != NLoc)) { |
Devang Patel | 0508d04 | 2011-12-15 18:21:18 +0000 | [diff] [blame] | 5254 | N->setDebugLoc(DebugLoc()); |
| 5255 | } |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5256 | unsigned Order = std::min(N->getIROrder(), OLoc.getIROrder()); |
| 5257 | N->setIROrder(Order); |
Devang Patel | 0508d04 | 2011-12-15 18:21:18 +0000 | [diff] [blame] | 5258 | return N; |
| 5259 | } |
| 5260 | |
Chris Lattner | 21221e3 | 2010-02-28 21:36:14 +0000 | [diff] [blame] | 5261 | /// MorphNodeTo - This *mutates* the specified node to have the specified |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5262 | /// return type, opcode, and operands. |
| 5263 | /// |
| 5264 | /// Note that MorphNodeTo returns the resultant node. If there is already a |
| 5265 | /// node of the specified opcode and operands, it returns that node instead of |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5266 | /// the current one. Note that the SDLoc need not be the same. |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5267 | /// |
| 5268 | /// Using MorphNodeTo is faster than creating a new node and swapping it in |
| 5269 | /// with ReplaceAllUsesWith both because it often avoids allocating a new |
Gabor Greif | dc71563 | 2008-08-30 22:16:05 +0000 | [diff] [blame] | 5270 | /// node, and because it doesn't require CSE recalculation for any of |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5271 | /// the node's users. |
| 5272 | /// |
| 5273 | SDNode *SelectionDAG::MorphNodeTo(SDNode *N, unsigned Opc, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5274 | SDVTList VTs, const SDValue *Ops, |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5275 | unsigned NumOps) { |
Dan Gohman | cd920d9 | 2008-07-02 23:23:19 +0000 | [diff] [blame] | 5276 | // If an identical node already exists, use it. |
Chris Lattner | a568285 | 2006-08-07 23:03:03 +0000 | [diff] [blame] | 5277 | void *IP = 0; |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 5278 | if (VTs.VTs[VTs.NumVTs-1] != MVT::Glue) { |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5279 | FoldingSetNodeID ID; |
| 5280 | AddNodeIDNode(ID, Opc, VTs, Ops, NumOps); |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 5281 | if (SDNode *ON = CSEMap.FindNodeOrInsertPos(ID, IP)) |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5282 | return UpdadeSDLocOnMergedSDNode(ON, SDLoc(N)); |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5283 | } |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 5284 | |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 5285 | if (!RemoveNodeFromCSEMaps(N)) |
| 5286 | IP = 0; |
Chris Lattner | 67612a1 | 2007-02-04 02:32:44 +0000 | [diff] [blame] | 5287 | |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5288 | // Start the morphing. |
| 5289 | N->NodeType = Opc; |
| 5290 | N->ValueList = VTs.VTs; |
| 5291 | N->NumValues = VTs.NumVTs; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5292 | |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5293 | // Clear the operands list, updating used nodes to remove this from their |
| 5294 | // use list. Keep track of any operands that become dead as a result. |
| 5295 | SmallPtrSet<SDNode*, 16> DeadNodeSet; |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5296 | for (SDNode::op_iterator I = N->op_begin(), E = N->op_end(); I != E; ) { |
| 5297 | SDUse &Use = *I++; |
| 5298 | SDNode *Used = Use.getNode(); |
| 5299 | Use.set(SDValue()); |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5300 | if (Used->use_empty()) |
| 5301 | DeadNodeSet.insert(Used); |
| 5302 | } |
| 5303 | |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 5304 | if (MachineSDNode *MN = dyn_cast<MachineSDNode>(N)) { |
| 5305 | // Initialize the memory references information. |
| 5306 | MN->setMemRefs(0, 0); |
| 5307 | // If NumOps is larger than the # of operands we can have in a |
| 5308 | // MachineSDNode, reallocate the operand list. |
| 5309 | if (NumOps > MN->NumOperands || !MN->OperandsNeedDelete) { |
| 5310 | if (MN->OperandsNeedDelete) |
| 5311 | delete[] MN->OperandList; |
| 5312 | if (NumOps > array_lengthof(MN->LocalOperands)) |
| 5313 | // We're creating a final node that will live unmorphed for the |
| 5314 | // remainder of the current SelectionDAG iteration, so we can allocate |
| 5315 | // the operands directly out of a pool with no recycling metadata. |
| 5316 | MN->InitOperands(OperandAllocator.Allocate<SDUse>(NumOps), |
Dan Gohman | 9553188 | 2010-03-18 18:49:47 +0000 | [diff] [blame] | 5317 | Ops, NumOps); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 5318 | else |
| 5319 | MN->InitOperands(MN->LocalOperands, Ops, NumOps); |
| 5320 | MN->OperandsNeedDelete = false; |
| 5321 | } else |
| 5322 | MN->InitOperands(MN->OperandList, Ops, NumOps); |
| 5323 | } else { |
| 5324 | // If NumOps is larger than the # of operands we currently have, reallocate |
| 5325 | // the operand list. |
| 5326 | if (NumOps > N->NumOperands) { |
| 5327 | if (N->OperandsNeedDelete) |
| 5328 | delete[] N->OperandList; |
| 5329 | N->InitOperands(new SDUse[NumOps], Ops, NumOps); |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5330 | N->OperandsNeedDelete = true; |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 5331 | } else |
Anton Korobeynikov | 443b215 | 2009-10-22 00:15:17 +0000 | [diff] [blame] | 5332 | N->InitOperands(N->OperandList, Ops, NumOps); |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5333 | } |
| 5334 | |
| 5335 | // Delete any nodes that are still dead after adding the uses for the |
| 5336 | // new operands. |
Chris Lattner | 7d892d6 | 2010-03-01 07:43:08 +0000 | [diff] [blame] | 5337 | if (!DeadNodeSet.empty()) { |
| 5338 | SmallVector<SDNode *, 16> DeadNodes; |
| 5339 | for (SmallPtrSet<SDNode *, 16>::iterator I = DeadNodeSet.begin(), |
| 5340 | E = DeadNodeSet.end(); I != E; ++I) |
| 5341 | if ((*I)->use_empty()) |
| 5342 | DeadNodes.push_back(*I); |
| 5343 | RemoveDeadNodes(DeadNodes); |
| 5344 | } |
Dan Gohman | 0fe9c6e | 2008-07-07 20:57:48 +0000 | [diff] [blame] | 5345 | |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5346 | if (IP) |
| 5347 | CSEMap.InsertNode(N, IP); // Memoize the new node. |
Evan Cheng | 95514ba | 2006-08-26 08:00:10 +0000 | [diff] [blame] | 5348 | return N; |
Chris Lattner | 0fb094f | 2005-11-19 01:44:53 +0000 | [diff] [blame] | 5349 | } |
| 5350 | |
Chris Lattner | 0fb094f | 2005-11-19 01:44:53 +0000 | [diff] [blame] | 5351 | |
Dan Gohman | 602b0c8 | 2009-09-25 18:54:59 +0000 | [diff] [blame] | 5352 | /// getMachineNode - These are used for target selectors to create a new node |
| 5353 | /// with specified return type(s), MachineInstr opcode, and operands. |
Evan Cheng | 6ae46c4 | 2006-02-09 07:15:23 +0000 | [diff] [blame] | 5354 | /// |
Dan Gohman | 602b0c8 | 2009-09-25 18:54:59 +0000 | [diff] [blame] | 5355 | /// Note that getMachineNode returns the resultant node. If there is already a |
Evan Cheng | 6ae46c4 | 2006-02-09 07:15:23 +0000 | [diff] [blame] | 5356 | /// node of the specified opcode and operands, it returns that node instead of |
| 5357 | /// the current one. |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5358 | MachineSDNode * |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5359 | SelectionDAG::getMachineNode(unsigned Opcode, SDLoc dl, EVT VT) { |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 5360 | SDVTList VTs = getVTList(VT); |
Dmitri Gribenko | 5c332db | 2013-05-05 00:40:33 +0000 | [diff] [blame] | 5361 | return getMachineNode(Opcode, dl, VTs, None); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 5362 | } |
Bill Wendling | 56ab1a2 | 2009-01-29 09:01:55 +0000 | [diff] [blame] | 5363 | |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5364 | MachineSDNode * |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5365 | SelectionDAG::getMachineNode(unsigned Opcode, SDLoc dl, EVT VT, SDValue Op1) { |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 5366 | SDVTList VTs = getVTList(VT); |
| 5367 | SDValue Ops[] = { Op1 }; |
Michael Liao | 2a8bea7 | 2013-04-19 22:22:57 +0000 | [diff] [blame] | 5368 | return getMachineNode(Opcode, dl, VTs, Ops); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 5369 | } |
Bill Wendling | 56ab1a2 | 2009-01-29 09:01:55 +0000 | [diff] [blame] | 5370 | |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5371 | MachineSDNode * |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5372 | SelectionDAG::getMachineNode(unsigned Opcode, SDLoc dl, EVT VT, |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5373 | SDValue Op1, SDValue Op2) { |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 5374 | SDVTList VTs = getVTList(VT); |
| 5375 | SDValue Ops[] = { Op1, Op2 }; |
Michael Liao | 2a8bea7 | 2013-04-19 22:22:57 +0000 | [diff] [blame] | 5376 | return getMachineNode(Opcode, dl, VTs, Ops); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 5377 | } |
Bill Wendling | 56ab1a2 | 2009-01-29 09:01:55 +0000 | [diff] [blame] | 5378 | |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5379 | MachineSDNode * |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5380 | SelectionDAG::getMachineNode(unsigned Opcode, SDLoc dl, EVT VT, |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5381 | SDValue Op1, SDValue Op2, SDValue Op3) { |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 5382 | SDVTList VTs = getVTList(VT); |
| 5383 | SDValue Ops[] = { Op1, Op2, Op3 }; |
Michael Liao | 2a8bea7 | 2013-04-19 22:22:57 +0000 | [diff] [blame] | 5384 | return getMachineNode(Opcode, dl, VTs, Ops); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 5385 | } |
Bill Wendling | 56ab1a2 | 2009-01-29 09:01:55 +0000 | [diff] [blame] | 5386 | |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5387 | MachineSDNode * |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5388 | SelectionDAG::getMachineNode(unsigned Opcode, SDLoc dl, EVT VT, |
Michael Liao | 2a8bea7 | 2013-04-19 22:22:57 +0000 | [diff] [blame] | 5389 | ArrayRef<SDValue> Ops) { |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 5390 | SDVTList VTs = getVTList(VT); |
Michael Liao | 2a8bea7 | 2013-04-19 22:22:57 +0000 | [diff] [blame] | 5391 | return getMachineNode(Opcode, dl, VTs, Ops); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 5392 | } |
Bill Wendling | 56ab1a2 | 2009-01-29 09:01:55 +0000 | [diff] [blame] | 5393 | |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5394 | MachineSDNode * |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5395 | SelectionDAG::getMachineNode(unsigned Opcode, SDLoc dl, EVT VT1, EVT VT2) { |
Dan Gohman | fc16657 | 2009-04-09 23:54:40 +0000 | [diff] [blame] | 5396 | SDVTList VTs = getVTList(VT1, VT2); |
Dmitri Gribenko | 5c332db | 2013-05-05 00:40:33 +0000 | [diff] [blame] | 5397 | return getMachineNode(Opcode, dl, VTs, None); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 5398 | } |
Bill Wendling | 56ab1a2 | 2009-01-29 09:01:55 +0000 | [diff] [blame] | 5399 | |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5400 | MachineSDNode * |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5401 | SelectionDAG::getMachineNode(unsigned Opcode, SDLoc dl, |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5402 | EVT VT1, EVT VT2, SDValue Op1) { |
Dan Gohman | fc16657 | 2009-04-09 23:54:40 +0000 | [diff] [blame] | 5403 | SDVTList VTs = getVTList(VT1, VT2); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 5404 | SDValue Ops[] = { Op1 }; |
Michael Liao | 2a8bea7 | 2013-04-19 22:22:57 +0000 | [diff] [blame] | 5405 | return getMachineNode(Opcode, dl, VTs, Ops); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 5406 | } |
Bill Wendling | 56ab1a2 | 2009-01-29 09:01:55 +0000 | [diff] [blame] | 5407 | |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5408 | MachineSDNode * |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5409 | SelectionDAG::getMachineNode(unsigned Opcode, SDLoc dl, |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5410 | EVT VT1, EVT VT2, SDValue Op1, SDValue Op2) { |
Dan Gohman | fc16657 | 2009-04-09 23:54:40 +0000 | [diff] [blame] | 5411 | SDVTList VTs = getVTList(VT1, VT2); |
Bill Wendling | 56ab1a2 | 2009-01-29 09:01:55 +0000 | [diff] [blame] | 5412 | SDValue Ops[] = { Op1, Op2 }; |
Michael Liao | 2a8bea7 | 2013-04-19 22:22:57 +0000 | [diff] [blame] | 5413 | return getMachineNode(Opcode, dl, VTs, Ops); |
Bill Wendling | 56ab1a2 | 2009-01-29 09:01:55 +0000 | [diff] [blame] | 5414 | } |
| 5415 | |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5416 | MachineSDNode * |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5417 | SelectionDAG::getMachineNode(unsigned Opcode, SDLoc dl, |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5418 | EVT VT1, EVT VT2, SDValue Op1, |
| 5419 | SDValue Op2, SDValue Op3) { |
Dan Gohman | fc16657 | 2009-04-09 23:54:40 +0000 | [diff] [blame] | 5420 | SDVTList VTs = getVTList(VT1, VT2); |
Bill Wendling | 56ab1a2 | 2009-01-29 09:01:55 +0000 | [diff] [blame] | 5421 | SDValue Ops[] = { Op1, Op2, Op3 }; |
Michael Liao | 2a8bea7 | 2013-04-19 22:22:57 +0000 | [diff] [blame] | 5422 | return getMachineNode(Opcode, dl, VTs, Ops); |
Bill Wendling | 56ab1a2 | 2009-01-29 09:01:55 +0000 | [diff] [blame] | 5423 | } |
| 5424 | |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5425 | MachineSDNode * |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5426 | SelectionDAG::getMachineNode(unsigned Opcode, SDLoc dl, |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5427 | EVT VT1, EVT VT2, |
Michael Liao | 2a8bea7 | 2013-04-19 22:22:57 +0000 | [diff] [blame] | 5428 | ArrayRef<SDValue> Ops) { |
Dan Gohman | fc16657 | 2009-04-09 23:54:40 +0000 | [diff] [blame] | 5429 | SDVTList VTs = getVTList(VT1, VT2); |
Michael Liao | 2a8bea7 | 2013-04-19 22:22:57 +0000 | [diff] [blame] | 5430 | return getMachineNode(Opcode, dl, VTs, Ops); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 5431 | } |
Bill Wendling | 56ab1a2 | 2009-01-29 09:01:55 +0000 | [diff] [blame] | 5432 | |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5433 | MachineSDNode * |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5434 | SelectionDAG::getMachineNode(unsigned Opcode, SDLoc dl, |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5435 | EVT VT1, EVT VT2, EVT VT3, |
| 5436 | SDValue Op1, SDValue Op2) { |
Dan Gohman | fc16657 | 2009-04-09 23:54:40 +0000 | [diff] [blame] | 5437 | SDVTList VTs = getVTList(VT1, VT2, VT3); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 5438 | SDValue Ops[] = { Op1, Op2 }; |
Michael Liao | 2a8bea7 | 2013-04-19 22:22:57 +0000 | [diff] [blame] | 5439 | return getMachineNode(Opcode, dl, VTs, Ops); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 5440 | } |
Bill Wendling | 56ab1a2 | 2009-01-29 09:01:55 +0000 | [diff] [blame] | 5441 | |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5442 | MachineSDNode * |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5443 | SelectionDAG::getMachineNode(unsigned Opcode, SDLoc dl, |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5444 | EVT VT1, EVT VT2, EVT VT3, |
| 5445 | SDValue Op1, SDValue Op2, SDValue Op3) { |
Dan Gohman | fc16657 | 2009-04-09 23:54:40 +0000 | [diff] [blame] | 5446 | SDVTList VTs = getVTList(VT1, VT2, VT3); |
Bill Wendling | 56ab1a2 | 2009-01-29 09:01:55 +0000 | [diff] [blame] | 5447 | SDValue Ops[] = { Op1, Op2, Op3 }; |
Michael Liao | 2a8bea7 | 2013-04-19 22:22:57 +0000 | [diff] [blame] | 5448 | return getMachineNode(Opcode, dl, VTs, Ops); |
Evan Cheng | 6ae46c4 | 2006-02-09 07:15:23 +0000 | [diff] [blame] | 5449 | } |
Bill Wendling | 56ab1a2 | 2009-01-29 09:01:55 +0000 | [diff] [blame] | 5450 | |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5451 | MachineSDNode * |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5452 | SelectionDAG::getMachineNode(unsigned Opcode, SDLoc dl, |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5453 | EVT VT1, EVT VT2, EVT VT3, |
Michael Liao | 2a8bea7 | 2013-04-19 22:22:57 +0000 | [diff] [blame] | 5454 | ArrayRef<SDValue> Ops) { |
Dan Gohman | fc16657 | 2009-04-09 23:54:40 +0000 | [diff] [blame] | 5455 | SDVTList VTs = getVTList(VT1, VT2, VT3); |
Michael Liao | 2a8bea7 | 2013-04-19 22:22:57 +0000 | [diff] [blame] | 5456 | return getMachineNode(Opcode, dl, VTs, Ops); |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 5457 | } |
Bill Wendling | 56ab1a2 | 2009-01-29 09:01:55 +0000 | [diff] [blame] | 5458 | |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5459 | MachineSDNode * |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5460 | SelectionDAG::getMachineNode(unsigned Opcode, SDLoc dl, EVT VT1, |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5461 | EVT VT2, EVT VT3, EVT VT4, |
Michael Liao | 2a8bea7 | 2013-04-19 22:22:57 +0000 | [diff] [blame] | 5462 | ArrayRef<SDValue> Ops) { |
Dan Gohman | fc16657 | 2009-04-09 23:54:40 +0000 | [diff] [blame] | 5463 | SDVTList VTs = getVTList(VT1, VT2, VT3, VT4); |
Michael Liao | 2a8bea7 | 2013-04-19 22:22:57 +0000 | [diff] [blame] | 5464 | return getMachineNode(Opcode, dl, VTs, Ops); |
Bill Wendling | 56ab1a2 | 2009-01-29 09:01:55 +0000 | [diff] [blame] | 5465 | } |
| 5466 | |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5467 | MachineSDNode * |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5468 | SelectionDAG::getMachineNode(unsigned Opcode, SDLoc dl, |
Benjamin Kramer | 3853f74 | 2013-03-07 20:33:29 +0000 | [diff] [blame] | 5469 | ArrayRef<EVT> ResultTys, |
Michael Liao | 2a8bea7 | 2013-04-19 22:22:57 +0000 | [diff] [blame] | 5470 | ArrayRef<SDValue> Ops) { |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 5471 | SDVTList VTs = getVTList(&ResultTys[0], ResultTys.size()); |
Michael Liao | 2a8bea7 | 2013-04-19 22:22:57 +0000 | [diff] [blame] | 5472 | return getMachineNode(Opcode, dl, VTs, Ops); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 5473 | } |
| 5474 | |
Dan Gohman | c81b783 | 2009-10-10 01:29:16 +0000 | [diff] [blame] | 5475 | MachineSDNode * |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5476 | SelectionDAG::getMachineNode(unsigned Opcode, SDLoc DL, SDVTList VTs, |
Michael Liao | 2a8bea7 | 2013-04-19 22:22:57 +0000 | [diff] [blame] | 5477 | ArrayRef<SDValue> OpsArray) { |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 5478 | bool DoCSE = VTs.VTs[VTs.NumVTs-1] != MVT::Glue; |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 5479 | MachineSDNode *N; |
Ted Kremenek | 584520e | 2011-01-23 17:05:06 +0000 | [diff] [blame] | 5480 | void *IP = 0; |
Michael Liao | 2a8bea7 | 2013-04-19 22:22:57 +0000 | [diff] [blame] | 5481 | const SDValue *Ops = OpsArray.data(); |
| 5482 | unsigned NumOps = OpsArray.size(); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 5483 | |
| 5484 | if (DoCSE) { |
| 5485 | FoldingSetNodeID ID; |
| 5486 | AddNodeIDNode(ID, ~Opcode, VTs, Ops, NumOps); |
| 5487 | IP = 0; |
Devang Patel | 0508d04 | 2011-12-15 18:21:18 +0000 | [diff] [blame] | 5488 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) { |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5489 | return cast<MachineSDNode>(UpdadeSDLocOnMergedSDNode(E, DL)); |
Devang Patel | 0508d04 | 2011-12-15 18:21:18 +0000 | [diff] [blame] | 5490 | } |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 5491 | } |
| 5492 | |
| 5493 | // Allocate a new MachineSDNode. |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 5494 | N = new (NodeAllocator) MachineSDNode(~Opcode, DL.getIROrder(), |
| 5495 | DL.getDebugLoc(), VTs); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 5496 | |
| 5497 | // Initialize the operands list. |
| 5498 | if (NumOps > array_lengthof(N->LocalOperands)) |
| 5499 | // We're creating a final node that will live unmorphed for the |
| 5500 | // remainder of the current SelectionDAG iteration, so we can allocate |
| 5501 | // the operands directly out of a pool with no recycling metadata. |
| 5502 | N->InitOperands(OperandAllocator.Allocate<SDUse>(NumOps), |
| 5503 | Ops, NumOps); |
| 5504 | else |
| 5505 | N->InitOperands(N->LocalOperands, Ops, NumOps); |
| 5506 | N->OperandsNeedDelete = false; |
| 5507 | |
| 5508 | if (DoCSE) |
| 5509 | CSEMap.InsertNode(N, IP); |
| 5510 | |
| 5511 | AllNodes.push_back(N); |
| 5512 | #ifndef NDEBUG |
Duncan Sands | 59d2dad | 2010-11-20 11:25:00 +0000 | [diff] [blame] | 5513 | VerifyMachineNode(N); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 5514 | #endif |
| 5515 | return N; |
Dale Johannesen | e8c1733 | 2009-01-29 00:47:48 +0000 | [diff] [blame] | 5516 | } |
Evan Cheng | 6ae46c4 | 2006-02-09 07:15:23 +0000 | [diff] [blame] | 5517 | |
Dan Gohman | 6a402dc | 2009-08-19 18:16:17 +0000 | [diff] [blame] | 5518 | /// getTargetExtractSubreg - A convenience function for creating |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 5519 | /// TargetOpcode::EXTRACT_SUBREG nodes. |
Dan Gohman | 6a402dc | 2009-08-19 18:16:17 +0000 | [diff] [blame] | 5520 | SDValue |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5521 | SelectionDAG::getTargetExtractSubreg(int SRIdx, SDLoc DL, EVT VT, |
Dan Gohman | 6a402dc | 2009-08-19 18:16:17 +0000 | [diff] [blame] | 5522 | SDValue Operand) { |
| 5523 | SDValue SRIdxVal = getTargetConstant(SRIdx, MVT::i32); |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 5524 | SDNode *Subreg = getMachineNode(TargetOpcode::EXTRACT_SUBREG, DL, |
Dan Gohman | 602b0c8 | 2009-09-25 18:54:59 +0000 | [diff] [blame] | 5525 | VT, Operand, SRIdxVal); |
Dan Gohman | 6a402dc | 2009-08-19 18:16:17 +0000 | [diff] [blame] | 5526 | return SDValue(Subreg, 0); |
| 5527 | } |
| 5528 | |
Bob Wilson | 5fcbf0d | 2009-10-08 18:49:46 +0000 | [diff] [blame] | 5529 | /// getTargetInsertSubreg - A convenience function for creating |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 5530 | /// TargetOpcode::INSERT_SUBREG nodes. |
Bob Wilson | 5fcbf0d | 2009-10-08 18:49:46 +0000 | [diff] [blame] | 5531 | SDValue |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5532 | SelectionDAG::getTargetInsertSubreg(int SRIdx, SDLoc DL, EVT VT, |
Bob Wilson | 5fcbf0d | 2009-10-08 18:49:46 +0000 | [diff] [blame] | 5533 | SDValue Operand, SDValue Subreg) { |
| 5534 | SDValue SRIdxVal = getTargetConstant(SRIdx, MVT::i32); |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 5535 | SDNode *Result = getMachineNode(TargetOpcode::INSERT_SUBREG, DL, |
Bob Wilson | 5fcbf0d | 2009-10-08 18:49:46 +0000 | [diff] [blame] | 5536 | VT, Operand, Subreg, SRIdxVal); |
| 5537 | return SDValue(Result, 0); |
| 5538 | } |
| 5539 | |
Evan Cheng | 08b1173 | 2008-03-22 01:55:50 +0000 | [diff] [blame] | 5540 | /// getNodeIfExists - Get the specified node if it's already available, or |
| 5541 | /// else return NULL. |
| 5542 | SDNode *SelectionDAG::getNodeIfExists(unsigned Opcode, SDVTList VTList, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5543 | const SDValue *Ops, unsigned NumOps) { |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 5544 | if (VTList.VTs[VTList.NumVTs-1] != MVT::Glue) { |
Evan Cheng | 08b1173 | 2008-03-22 01:55:50 +0000 | [diff] [blame] | 5545 | FoldingSetNodeID ID; |
| 5546 | AddNodeIDNode(ID, Opcode, VTList, Ops, NumOps); |
| 5547 | void *IP = 0; |
Bill Wendling | b4e6a5d | 2009-12-18 23:32:53 +0000 | [diff] [blame] | 5548 | if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP)) |
Evan Cheng | 08b1173 | 2008-03-22 01:55:50 +0000 | [diff] [blame] | 5549 | return E; |
| 5550 | } |
| 5551 | return NULL; |
| 5552 | } |
| 5553 | |
Evan Cheng | 31441b7 | 2010-03-29 20:48:30 +0000 | [diff] [blame] | 5554 | /// getDbgValue - Creates a SDDbgValue node. |
| 5555 | /// |
| 5556 | SDDbgValue * |
| 5557 | SelectionDAG::getDbgValue(MDNode *MDPtr, SDNode *N, unsigned R, uint64_t Off, |
| 5558 | DebugLoc DL, unsigned O) { |
| 5559 | return new (Allocator) SDDbgValue(MDPtr, N, R, Off, DL, O); |
| 5560 | } |
| 5561 | |
| 5562 | SDDbgValue * |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 5563 | SelectionDAG::getDbgValue(MDNode *MDPtr, const Value *C, uint64_t Off, |
Evan Cheng | 31441b7 | 2010-03-29 20:48:30 +0000 | [diff] [blame] | 5564 | DebugLoc DL, unsigned O) { |
| 5565 | return new (Allocator) SDDbgValue(MDPtr, C, Off, DL, O); |
| 5566 | } |
| 5567 | |
| 5568 | SDDbgValue * |
| 5569 | SelectionDAG::getDbgValue(MDNode *MDPtr, unsigned FI, uint64_t Off, |
| 5570 | DebugLoc DL, unsigned O) { |
| 5571 | return new (Allocator) SDDbgValue(MDPtr, FI, Off, DL, O); |
| 5572 | } |
| 5573 | |
Dan Gohman | a72d2a2 | 2010-03-03 21:33:37 +0000 | [diff] [blame] | 5574 | namespace { |
| 5575 | |
Dan Gohman | ba72b0c | 2010-03-04 19:11:28 +0000 | [diff] [blame] | 5576 | /// RAUWUpdateListener - Helper for ReplaceAllUsesWith - When the node |
Dan Gohman | a72d2a2 | 2010-03-03 21:33:37 +0000 | [diff] [blame] | 5577 | /// pointed to by a use iterator is deleted, increment the use iterator |
| 5578 | /// so that it doesn't dangle. |
| 5579 | /// |
Dan Gohman | a72d2a2 | 2010-03-03 21:33:37 +0000 | [diff] [blame] | 5580 | class RAUWUpdateListener : public SelectionDAG::DAGUpdateListener { |
Dan Gohman | a72d2a2 | 2010-03-03 21:33:37 +0000 | [diff] [blame] | 5581 | SDNode::use_iterator &UI; |
| 5582 | SDNode::use_iterator &UE; |
| 5583 | |
| 5584 | virtual void NodeDeleted(SDNode *N, SDNode *E) { |
| 5585 | // Increment the iterator as needed. |
| 5586 | while (UI != UE && N == *UI) |
| 5587 | ++UI; |
Dan Gohman | a72d2a2 | 2010-03-03 21:33:37 +0000 | [diff] [blame] | 5588 | } |
| 5589 | |
| 5590 | public: |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 5591 | RAUWUpdateListener(SelectionDAG &d, |
Dan Gohman | a72d2a2 | 2010-03-03 21:33:37 +0000 | [diff] [blame] | 5592 | SDNode::use_iterator &ui, |
| 5593 | SDNode::use_iterator &ue) |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 5594 | : SelectionDAG::DAGUpdateListener(d), UI(ui), UE(ue) {} |
Dan Gohman | a72d2a2 | 2010-03-03 21:33:37 +0000 | [diff] [blame] | 5595 | }; |
| 5596 | |
| 5597 | } |
| 5598 | |
Evan Cheng | 99157a0 | 2006-08-07 22:13:29 +0000 | [diff] [blame] | 5599 | /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead. |
Chris Lattner | 8b8749f | 2005-08-17 19:00:20 +0000 | [diff] [blame] | 5600 | /// This can cause recursive merging of nodes in the DAG. |
| 5601 | /// |
Chris Lattner | 11d049c | 2008-02-03 03:35:22 +0000 | [diff] [blame] | 5602 | /// This version assumes From has a single result value. |
Chris Lattner | 8b52f21 | 2005-08-26 18:36:28 +0000 | [diff] [blame] | 5603 | /// |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 5604 | void SelectionDAG::ReplaceAllUsesWith(SDValue FromN, SDValue To) { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5605 | SDNode *From = FromN.getNode(); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5606 | assert(From->getNumValues() == 1 && FromN.getResNo() == 0 && |
Chris Lattner | 8b52f21 | 2005-08-26 18:36:28 +0000 | [diff] [blame] | 5607 | "Cannot replace with this method!"); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5608 | assert(From != To.getNode() && "Cannot replace uses of with self"); |
Roman Levenstein | dc1adac | 2008-04-07 10:06:32 +0000 | [diff] [blame] | 5609 | |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5610 | // Iterate over all the existing uses of From. New uses will be added |
| 5611 | // to the beginning of the use list, which we avoid visiting. |
| 5612 | // This specifically avoids visiting uses of From that arise while the |
| 5613 | // replacement is happening, because any such uses would be the result |
| 5614 | // of CSE: If an existing node looks like From after one of its operands |
| 5615 | // is replaced by To, we don't want to replace of all its users with To |
| 5616 | // too. See PR3018 for more info. |
Dan Gohman | dbe664a | 2009-01-19 21:44:21 +0000 | [diff] [blame] | 5617 | SDNode::use_iterator UI = From->use_begin(), UE = From->use_end(); |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 5618 | RAUWUpdateListener Listener(*this, UI, UE); |
Dan Gohman | dbe664a | 2009-01-19 21:44:21 +0000 | [diff] [blame] | 5619 | while (UI != UE) { |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5620 | SDNode *User = *UI; |
Roman Levenstein | dc1adac | 2008-04-07 10:06:32 +0000 | [diff] [blame] | 5621 | |
Chris Lattner | 8b8749f | 2005-08-17 19:00:20 +0000 | [diff] [blame] | 5622 | // This node is about to morph, remove its old self from the CSE maps. |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5623 | RemoveNodeFromCSEMaps(User); |
Chris Lattner | 8b52f21 | 2005-08-26 18:36:28 +0000 | [diff] [blame] | 5624 | |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5625 | // A user can appear in a use list multiple times, and when this |
| 5626 | // happens the uses are usually next to each other in the list. |
| 5627 | // To help reduce the number of CSE recomputations, process all |
| 5628 | // the uses of this user that we can find this way. |
| 5629 | do { |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5630 | SDUse &Use = UI.getUse(); |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5631 | ++UI; |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5632 | Use.set(To); |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5633 | } while (UI != UE && *UI == User); |
| 5634 | |
| 5635 | // Now that we have modified User, add it back to the CSE maps. If it |
| 5636 | // already exists there, recursively merge the results together. |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 5637 | AddModifiedNodeToCSEMaps(User); |
Chris Lattner | 8b52f21 | 2005-08-26 18:36:28 +0000 | [diff] [blame] | 5638 | } |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 5639 | |
| 5640 | // If we just RAUW'd the root, take note. |
| 5641 | if (FromN == getRoot()) |
| 5642 | setRoot(To); |
Chris Lattner | 8b52f21 | 2005-08-26 18:36:28 +0000 | [diff] [blame] | 5643 | } |
| 5644 | |
| 5645 | /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead. |
| 5646 | /// This can cause recursive merging of nodes in the DAG. |
| 5647 | /// |
Dan Gohman | c23e496 | 2009-04-15 20:06:30 +0000 | [diff] [blame] | 5648 | /// This version assumes that for each value of From, there is a |
| 5649 | /// corresponding value in To in the same position with the same type. |
Chris Lattner | 8b52f21 | 2005-08-26 18:36:28 +0000 | [diff] [blame] | 5650 | /// |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 5651 | void SelectionDAG::ReplaceAllUsesWith(SDNode *From, SDNode *To) { |
Dan Gohman | c23e496 | 2009-04-15 20:06:30 +0000 | [diff] [blame] | 5652 | #ifndef NDEBUG |
| 5653 | for (unsigned i = 0, e = From->getNumValues(); i != e; ++i) |
| 5654 | assert((!From->hasAnyUseOfValue(i) || |
| 5655 | From->getValueType(i) == To->getValueType(i)) && |
| 5656 | "Cannot use this version of ReplaceAllUsesWith!"); |
| 5657 | #endif |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5658 | |
| 5659 | // Handle the trivial case. |
| 5660 | if (From == To) |
| 5661 | return; |
| 5662 | |
Dan Gohman | dbe664a | 2009-01-19 21:44:21 +0000 | [diff] [blame] | 5663 | // Iterate over just the existing users of From. See the comments in |
| 5664 | // the ReplaceAllUsesWith above. |
| 5665 | SDNode::use_iterator UI = From->use_begin(), UE = From->use_end(); |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 5666 | RAUWUpdateListener Listener(*this, UI, UE); |
Dan Gohman | dbe664a | 2009-01-19 21:44:21 +0000 | [diff] [blame] | 5667 | while (UI != UE) { |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5668 | SDNode *User = *UI; |
Roman Levenstein | dc1adac | 2008-04-07 10:06:32 +0000 | [diff] [blame] | 5669 | |
Chris Lattner | 8b52f21 | 2005-08-26 18:36:28 +0000 | [diff] [blame] | 5670 | // This node is about to morph, remove its old self from the CSE maps. |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5671 | RemoveNodeFromCSEMaps(User); |
Roman Levenstein | dc1adac | 2008-04-07 10:06:32 +0000 | [diff] [blame] | 5672 | |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5673 | // A user can appear in a use list multiple times, and when this |
| 5674 | // happens the uses are usually next to each other in the list. |
| 5675 | // To help reduce the number of CSE recomputations, process all |
| 5676 | // the uses of this user that we can find this way. |
| 5677 | do { |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5678 | SDUse &Use = UI.getUse(); |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5679 | ++UI; |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5680 | Use.setNode(To); |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5681 | } while (UI != UE && *UI == User); |
| 5682 | |
| 5683 | // Now that we have modified User, add it back to the CSE maps. If it |
| 5684 | // already exists there, recursively merge the results together. |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 5685 | AddModifiedNodeToCSEMaps(User); |
Chris Lattner | 8b8749f | 2005-08-17 19:00:20 +0000 | [diff] [blame] | 5686 | } |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 5687 | |
| 5688 | // If we just RAUW'd the root, take note. |
| 5689 | if (From == getRoot().getNode()) |
| 5690 | setRoot(SDValue(To, getRoot().getResNo())); |
Chris Lattner | 8b8749f | 2005-08-17 19:00:20 +0000 | [diff] [blame] | 5691 | } |
| 5692 | |
Chris Lattner | 8b52f21 | 2005-08-26 18:36:28 +0000 | [diff] [blame] | 5693 | /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead. |
| 5694 | /// This can cause recursive merging of nodes in the DAG. |
| 5695 | /// |
| 5696 | /// This version can replace From with any result values. To must match the |
| 5697 | /// number and types of values returned by From. |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 5698 | void SelectionDAG::ReplaceAllUsesWith(SDNode *From, const SDValue *To) { |
Chris Lattner | 11d049c | 2008-02-03 03:35:22 +0000 | [diff] [blame] | 5699 | if (From->getNumValues() == 1) // Handle the simple case efficiently. |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 5700 | return ReplaceAllUsesWith(SDValue(From, 0), To[0]); |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 5701 | |
Dan Gohman | dbe664a | 2009-01-19 21:44:21 +0000 | [diff] [blame] | 5702 | // Iterate over just the existing users of From. See the comments in |
| 5703 | // the ReplaceAllUsesWith above. |
| 5704 | SDNode::use_iterator UI = From->use_begin(), UE = From->use_end(); |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 5705 | RAUWUpdateListener Listener(*this, UI, UE); |
Dan Gohman | dbe664a | 2009-01-19 21:44:21 +0000 | [diff] [blame] | 5706 | while (UI != UE) { |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5707 | SDNode *User = *UI; |
Roman Levenstein | dc1adac | 2008-04-07 10:06:32 +0000 | [diff] [blame] | 5708 | |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 5709 | // This node is about to morph, remove its old self from the CSE maps. |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5710 | RemoveNodeFromCSEMaps(User); |
Roman Levenstein | dc1adac | 2008-04-07 10:06:32 +0000 | [diff] [blame] | 5711 | |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5712 | // A user can appear in a use list multiple times, and when this |
| 5713 | // happens the uses are usually next to each other in the list. |
| 5714 | // To help reduce the number of CSE recomputations, process all |
| 5715 | // the uses of this user that we can find this way. |
| 5716 | do { |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5717 | SDUse &Use = UI.getUse(); |
| 5718 | const SDValue &ToOp = To[Use.getResNo()]; |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5719 | ++UI; |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5720 | Use.set(ToOp); |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5721 | } while (UI != UE && *UI == User); |
| 5722 | |
| 5723 | // Now that we have modified User, add it back to the CSE maps. If it |
| 5724 | // already exists there, recursively merge the results together. |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 5725 | AddModifiedNodeToCSEMaps(User); |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 5726 | } |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 5727 | |
| 5728 | // If we just RAUW'd the root, take note. |
| 5729 | if (From == getRoot().getNode()) |
| 5730 | setRoot(SDValue(To[getRoot().getResNo()])); |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 5731 | } |
| 5732 | |
Chris Lattner | 012f241 | 2006-02-17 21:58:01 +0000 | [diff] [blame] | 5733 | /// ReplaceAllUsesOfValueWith - Replace any uses of From with To, leaving |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5734 | /// uses of other values produced by From.getNode() alone. The Deleted |
| 5735 | /// vector is handled the same way as for ReplaceAllUsesWith. |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 5736 | void SelectionDAG::ReplaceAllUsesOfValueWith(SDValue From, SDValue To){ |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5737 | // Handle the really simple, really trivial case efficiently. |
| 5738 | if (From == To) return; |
| 5739 | |
Chris Lattner | 012f241 | 2006-02-17 21:58:01 +0000 | [diff] [blame] | 5740 | // Handle the simple, trivial, case efficiently. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 5741 | if (From.getNode()->getNumValues() == 1) { |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 5742 | ReplaceAllUsesWith(From, To); |
Chris Lattner | 012f241 | 2006-02-17 21:58:01 +0000 | [diff] [blame] | 5743 | return; |
| 5744 | } |
Chris Lattner | f8dc061 | 2008-02-03 06:49:24 +0000 | [diff] [blame] | 5745 | |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5746 | // Iterate over just the existing users of From. See the comments in |
| 5747 | // the ReplaceAllUsesWith above. |
| 5748 | SDNode::use_iterator UI = From.getNode()->use_begin(), |
| 5749 | UE = From.getNode()->use_end(); |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 5750 | RAUWUpdateListener Listener(*this, UI, UE); |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5751 | while (UI != UE) { |
| 5752 | SDNode *User = *UI; |
| 5753 | bool UserRemovedFromCSEMaps = false; |
Chris Lattner | 012f241 | 2006-02-17 21:58:01 +0000 | [diff] [blame] | 5754 | |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5755 | // A user can appear in a use list multiple times, and when this |
| 5756 | // happens the uses are usually next to each other in the list. |
| 5757 | // To help reduce the number of CSE recomputations, process all |
| 5758 | // the uses of this user that we can find this way. |
| 5759 | do { |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5760 | SDUse &Use = UI.getUse(); |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5761 | |
| 5762 | // Skip uses of different values from the same node. |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5763 | if (Use.getResNo() != From.getResNo()) { |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5764 | ++UI; |
| 5765 | continue; |
Chris Lattner | 012f241 | 2006-02-17 21:58:01 +0000 | [diff] [blame] | 5766 | } |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5767 | |
| 5768 | // If this node hasn't been modified yet, it's still in the CSE maps, |
| 5769 | // so remove its old self from the CSE maps. |
| 5770 | if (!UserRemovedFromCSEMaps) { |
| 5771 | RemoveNodeFromCSEMaps(User); |
| 5772 | UserRemovedFromCSEMaps = true; |
| 5773 | } |
| 5774 | |
| 5775 | ++UI; |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5776 | Use.set(To); |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5777 | } while (UI != UE && *UI == User); |
| 5778 | |
| 5779 | // We are iterating over all uses of the From node, so if a use |
| 5780 | // doesn't use the specific value, no changes are made. |
| 5781 | if (!UserRemovedFromCSEMaps) |
| 5782 | continue; |
| 5783 | |
Chris Lattner | 01d029b | 2007-10-15 06:10:22 +0000 | [diff] [blame] | 5784 | // Now that we have modified User, add it back to the CSE maps. If it |
| 5785 | // already exists there, recursively merge the results together. |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 5786 | AddModifiedNodeToCSEMaps(User); |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5787 | } |
Dan Gohman | 65fd656 | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 5788 | |
| 5789 | // If we just RAUW'd the root, take note. |
| 5790 | if (From == getRoot()) |
| 5791 | setRoot(To); |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5792 | } |
| 5793 | |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5794 | namespace { |
| 5795 | /// UseMemo - This class is used by SelectionDAG::ReplaceAllUsesOfValuesWith |
| 5796 | /// to record information about a use. |
| 5797 | struct UseMemo { |
| 5798 | SDNode *User; |
| 5799 | unsigned Index; |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5800 | SDUse *Use; |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5801 | }; |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5802 | |
| 5803 | /// operator< - Sort Memos by User. |
| 5804 | bool operator<(const UseMemo &L, const UseMemo &R) { |
| 5805 | return (intptr_t)L.User < (intptr_t)R.User; |
| 5806 | } |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5807 | } |
| 5808 | |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5809 | /// ReplaceAllUsesOfValuesWith - Replace any uses of From with To, leaving |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5810 | /// uses of other values produced by From.getNode() alone. The same value |
| 5811 | /// may appear in both the From and To list. The Deleted vector is |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5812 | /// handled the same way as for ReplaceAllUsesWith. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5813 | void SelectionDAG::ReplaceAllUsesOfValuesWith(const SDValue *From, |
| 5814 | const SDValue *To, |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 5815 | unsigned Num){ |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5816 | // Handle the simple, trivial case efficiently. |
| 5817 | if (Num == 1) |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 5818 | return ReplaceAllUsesOfValueWith(*From, *To); |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5819 | |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5820 | // Read up all the uses and make records of them. This helps |
| 5821 | // processing new uses that are introduced during the |
| 5822 | // replacement process. |
| 5823 | SmallVector<UseMemo, 4> Uses; |
| 5824 | for (unsigned i = 0; i != Num; ++i) { |
| 5825 | unsigned FromResNo = From[i].getResNo(); |
| 5826 | SDNode *FromNode = From[i].getNode(); |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5827 | for (SDNode::use_iterator UI = FromNode->use_begin(), |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5828 | E = FromNode->use_end(); UI != E; ++UI) { |
| 5829 | SDUse &Use = UI.getUse(); |
| 5830 | if (Use.getResNo() == FromResNo) { |
| 5831 | UseMemo Memo = { *UI, i, &Use }; |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5832 | Uses.push_back(Memo); |
| 5833 | } |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5834 | } |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5835 | } |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5836 | |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5837 | // Sort the uses, so that all the uses from a given User are together. |
| 5838 | std::sort(Uses.begin(), Uses.end()); |
| 5839 | |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5840 | for (unsigned UseIndex = 0, UseIndexEnd = Uses.size(); |
| 5841 | UseIndex != UseIndexEnd; ) { |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5842 | // We know that this user uses some value of From. If it is the right |
| 5843 | // value, update it. |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5844 | SDNode *User = Uses[UseIndex].User; |
| 5845 | |
| 5846 | // This node is about to morph, remove its old self from the CSE maps. |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5847 | RemoveNodeFromCSEMaps(User); |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5848 | |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5849 | // The Uses array is sorted, so all the uses for a given User |
| 5850 | // are next to each other in the list. |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5851 | // To help reduce the number of CSE recomputations, process all |
| 5852 | // the uses of this user that we can find this way. |
| 5853 | do { |
| 5854 | unsigned i = Uses[UseIndex].Index; |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5855 | SDUse &Use = *Uses[UseIndex].Use; |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5856 | ++UseIndex; |
| 5857 | |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 5858 | Use.set(To[i]); |
Dan Gohman | 3994610 | 2009-01-25 16:29:12 +0000 | [diff] [blame] | 5859 | } while (UseIndex != UseIndexEnd && Uses[UseIndex].User == User); |
| 5860 | |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 5861 | // Now that we have modified User, add it back to the CSE maps. If it |
| 5862 | // already exists there, recursively merge the results together. |
Jakob Stoklund Olesen | bc7d448 | 2012-04-20 22:08:46 +0000 | [diff] [blame] | 5863 | AddModifiedNodeToCSEMaps(User); |
Chris Lattner | 012f241 | 2006-02-17 21:58:01 +0000 | [diff] [blame] | 5864 | } |
| 5865 | } |
| 5866 | |
Evan Cheng | e6f35d8 | 2006-08-01 08:20:41 +0000 | [diff] [blame] | 5867 | /// AssignTopologicalOrder - Assign a unique node id for each node in the DAG |
Evan Cheng | c384d6c | 2006-08-02 22:00:34 +0000 | [diff] [blame] | 5868 | /// based on their topological order. It returns the maximum id and a vector |
| 5869 | /// of the SDNodes* in assigned order by reference. |
Dan Gohman | f06c835 | 2008-09-30 18:30:35 +0000 | [diff] [blame] | 5870 | unsigned SelectionDAG::AssignTopologicalOrder() { |
Evan Cheng | c384d6c | 2006-08-02 22:00:34 +0000 | [diff] [blame] | 5871 | |
Dan Gohman | f06c835 | 2008-09-30 18:30:35 +0000 | [diff] [blame] | 5872 | unsigned DAGSize = 0; |
Evan Cheng | e6f35d8 | 2006-08-01 08:20:41 +0000 | [diff] [blame] | 5873 | |
Dan Gohman | f06c835 | 2008-09-30 18:30:35 +0000 | [diff] [blame] | 5874 | // SortedPos tracks the progress of the algorithm. Nodes before it are |
| 5875 | // sorted, nodes after it are unsorted. When the algorithm completes |
| 5876 | // it is at the end of the list. |
| 5877 | allnodes_iterator SortedPos = allnodes_begin(); |
| 5878 | |
Dan Gohman | 3ebd0ee | 2008-11-21 19:10:41 +0000 | [diff] [blame] | 5879 | // Visit all the nodes. Move nodes with no operands to the front of |
| 5880 | // the list immediately. Annotate nodes that do have operands with their |
Dan Gohman | f06c835 | 2008-09-30 18:30:35 +0000 | [diff] [blame] | 5881 | // operand count. Before we do this, the Node Id fields of the nodes |
| 5882 | // may contain arbitrary values. After, the Node Id fields for nodes |
| 5883 | // before SortedPos will contain the topological sort index, and the |
| 5884 | // Node Id fields for nodes At SortedPos and after will contain the |
| 5885 | // count of outstanding operands. |
| 5886 | for (allnodes_iterator I = allnodes_begin(),E = allnodes_end(); I != E; ) { |
| 5887 | SDNode *N = I++; |
David Greene | cf495bc | 2010-01-20 20:13:31 +0000 | [diff] [blame] | 5888 | checkForCycles(N); |
Dan Gohman | f06c835 | 2008-09-30 18:30:35 +0000 | [diff] [blame] | 5889 | unsigned Degree = N->getNumOperands(); |
| 5890 | if (Degree == 0) { |
| 5891 | // A node with no uses, add it to the result array immediately. |
| 5892 | N->setNodeId(DAGSize++); |
| 5893 | allnodes_iterator Q = N; |
| 5894 | if (Q != SortedPos) |
| 5895 | SortedPos = AllNodes.insert(SortedPos, AllNodes.remove(Q)); |
David Greene | 221925e | 2010-01-20 00:59:23 +0000 | [diff] [blame] | 5896 | assert(SortedPos != AllNodes.end() && "Overran node list"); |
Dan Gohman | f06c835 | 2008-09-30 18:30:35 +0000 | [diff] [blame] | 5897 | ++SortedPos; |
| 5898 | } else { |
| 5899 | // Temporarily use the Node Id as scratch space for the degree count. |
| 5900 | N->setNodeId(Degree); |
Evan Cheng | e6f35d8 | 2006-08-01 08:20:41 +0000 | [diff] [blame] | 5901 | } |
| 5902 | } |
| 5903 | |
Chad Rosier | f496dea | 2012-05-21 17:13:41 +0000 | [diff] [blame] | 5904 | // Visit all the nodes. As we iterate, move nodes into sorted order, |
Dan Gohman | f06c835 | 2008-09-30 18:30:35 +0000 | [diff] [blame] | 5905 | // such that by the time the end is reached all nodes will be sorted. |
| 5906 | for (allnodes_iterator I = allnodes_begin(),E = allnodes_end(); I != E; ++I) { |
| 5907 | SDNode *N = I; |
David Greene | cf495bc | 2010-01-20 20:13:31 +0000 | [diff] [blame] | 5908 | checkForCycles(N); |
David Greene | 221925e | 2010-01-20 00:59:23 +0000 | [diff] [blame] | 5909 | // N is in sorted position, so all its uses have one less operand |
| 5910 | // that needs to be sorted. |
Dan Gohman | f06c835 | 2008-09-30 18:30:35 +0000 | [diff] [blame] | 5911 | for (SDNode::use_iterator UI = N->use_begin(), UE = N->use_end(); |
| 5912 | UI != UE; ++UI) { |
| 5913 | SDNode *P = *UI; |
| 5914 | unsigned Degree = P->getNodeId(); |
David Greene | 221925e | 2010-01-20 00:59:23 +0000 | [diff] [blame] | 5915 | assert(Degree != 0 && "Invalid node degree"); |
Dan Gohman | f06c835 | 2008-09-30 18:30:35 +0000 | [diff] [blame] | 5916 | --Degree; |
| 5917 | if (Degree == 0) { |
| 5918 | // All of P's operands are sorted, so P may sorted now. |
| 5919 | P->setNodeId(DAGSize++); |
| 5920 | if (P != SortedPos) |
| 5921 | SortedPos = AllNodes.insert(SortedPos, AllNodes.remove(P)); |
David Greene | 221925e | 2010-01-20 00:59:23 +0000 | [diff] [blame] | 5922 | assert(SortedPos != AllNodes.end() && "Overran node list"); |
Dan Gohman | f06c835 | 2008-09-30 18:30:35 +0000 | [diff] [blame] | 5923 | ++SortedPos; |
| 5924 | } else { |
| 5925 | // Update P's outstanding operand count. |
| 5926 | P->setNodeId(Degree); |
| 5927 | } |
| 5928 | } |
David Greene | 221925e | 2010-01-20 00:59:23 +0000 | [diff] [blame] | 5929 | if (I == SortedPos) { |
David Greene | 3914370 | 2010-02-09 23:03:05 +0000 | [diff] [blame] | 5930 | #ifndef NDEBUG |
| 5931 | SDNode *S = ++I; |
| 5932 | dbgs() << "Overran sorted position:\n"; |
David Greene | 221925e | 2010-01-20 00:59:23 +0000 | [diff] [blame] | 5933 | S->dumprFull(); |
David Greene | 3914370 | 2010-02-09 23:03:05 +0000 | [diff] [blame] | 5934 | #endif |
| 5935 | llvm_unreachable(0); |
David Greene | 221925e | 2010-01-20 00:59:23 +0000 | [diff] [blame] | 5936 | } |
Dan Gohman | f06c835 | 2008-09-30 18:30:35 +0000 | [diff] [blame] | 5937 | } |
| 5938 | |
| 5939 | assert(SortedPos == AllNodes.end() && |
| 5940 | "Topological sort incomplete!"); |
| 5941 | assert(AllNodes.front().getOpcode() == ISD::EntryToken && |
| 5942 | "First node in topological sort is not the entry token!"); |
| 5943 | assert(AllNodes.front().getNodeId() == 0 && |
| 5944 | "First node in topological sort has non-zero id!"); |
| 5945 | assert(AllNodes.front().getNumOperands() == 0 && |
| 5946 | "First node in topological sort has operands!"); |
| 5947 | assert(AllNodes.back().getNodeId() == (int)DAGSize-1 && |
| 5948 | "Last node in topologic sort has unexpected id!"); |
| 5949 | assert(AllNodes.back().use_empty() && |
| 5950 | "Last node in topologic sort has users!"); |
Dan Gohman | 3ebd0ee | 2008-11-21 19:10:41 +0000 | [diff] [blame] | 5951 | assert(DAGSize == allnodes_size() && "Node count mismatch!"); |
Dan Gohman | f06c835 | 2008-09-30 18:30:35 +0000 | [diff] [blame] | 5952 | return DAGSize; |
Evan Cheng | e6f35d8 | 2006-08-01 08:20:41 +0000 | [diff] [blame] | 5953 | } |
| 5954 | |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 5955 | /// AddDbgValue - Add a dbg_value SDNode. If SD is non-null that means the |
| 5956 | /// value is produced by SD. |
Dale Johannesen | fdb42fa | 2010-04-26 20:06:49 +0000 | [diff] [blame] | 5957 | void SelectionDAG::AddDbgValue(SDDbgValue *DB, SDNode *SD, bool isParameter) { |
| 5958 | DbgInfo->add(DB, SD, isParameter); |
Evan Cheng | bfcb305 | 2010-03-25 01:38:16 +0000 | [diff] [blame] | 5959 | if (SD) |
| 5960 | SD->setHasDebugValue(true); |
Dale Johannesen | bfdf7f3 | 2010-03-10 22:13:47 +0000 | [diff] [blame] | 5961 | } |
Evan Cheng | 091cba1 | 2006-07-27 06:39:06 +0000 | [diff] [blame] | 5962 | |
Devang Patel | a2e868d | 2011-01-25 23:27:42 +0000 | [diff] [blame] | 5963 | /// TransferDbgValues - Transfer SDDbgValues. |
| 5964 | void SelectionDAG::TransferDbgValues(SDValue From, SDValue To) { |
| 5965 | if (From == To || !From.getNode()->getHasDebugValue()) |
| 5966 | return; |
| 5967 | SDNode *FromNode = From.getNode(); |
| 5968 | SDNode *ToNode = To.getNode(); |
Benjamin Kramer | 22a54c1 | 2011-06-18 13:13:44 +0000 | [diff] [blame] | 5969 | ArrayRef<SDDbgValue *> DVs = GetDbgValues(FromNode); |
Devang Patel | a778f5c | 2011-02-18 22:43:42 +0000 | [diff] [blame] | 5970 | SmallVector<SDDbgValue *, 2> ClonedDVs; |
Benjamin Kramer | 22a54c1 | 2011-06-18 13:13:44 +0000 | [diff] [blame] | 5971 | for (ArrayRef<SDDbgValue *>::iterator I = DVs.begin(), E = DVs.end(); |
Devang Patel | a2e868d | 2011-01-25 23:27:42 +0000 | [diff] [blame] | 5972 | I != E; ++I) { |
Devang Patel | a778f5c | 2011-02-18 22:43:42 +0000 | [diff] [blame] | 5973 | SDDbgValue *Dbg = *I; |
| 5974 | if (Dbg->getKind() == SDDbgValue::SDNODE) { |
| 5975 | SDDbgValue *Clone = getDbgValue(Dbg->getMDPtr(), ToNode, To.getResNo(), |
| 5976 | Dbg->getOffset(), Dbg->getDebugLoc(), |
| 5977 | Dbg->getOrder()); |
| 5978 | ClonedDVs.push_back(Clone); |
Devang Patel | a2e868d | 2011-01-25 23:27:42 +0000 | [diff] [blame] | 5979 | } |
| 5980 | } |
Craig Topper | f22fd3f | 2013-07-03 05:11:49 +0000 | [diff] [blame] | 5981 | for (SmallVectorImpl<SDDbgValue *>::iterator I = ClonedDVs.begin(), |
Devang Patel | a778f5c | 2011-02-18 22:43:42 +0000 | [diff] [blame] | 5982 | E = ClonedDVs.end(); I != E; ++I) |
| 5983 | AddDbgValue(*I, ToNode, false); |
Devang Patel | a2e868d | 2011-01-25 23:27:42 +0000 | [diff] [blame] | 5984 | } |
| 5985 | |
Jim Laskey | 58b968b | 2005-08-17 20:08:02 +0000 | [diff] [blame] | 5986 | //===----------------------------------------------------------------------===// |
| 5987 | // SDNode Class |
| 5988 | //===----------------------------------------------------------------------===// |
Chris Lattner | 149c58c | 2005-08-16 18:17:10 +0000 | [diff] [blame] | 5989 | |
Chris Lattner | 48b8592 | 2007-02-04 02:41:42 +0000 | [diff] [blame] | 5990 | HandleSDNode::~HandleSDNode() { |
Dan Gohman | 0fe9c6e | 2008-07-07 20:57:48 +0000 | [diff] [blame] | 5991 | DropOperands(); |
Chris Lattner | 48b8592 | 2007-02-04 02:41:42 +0000 | [diff] [blame] | 5992 | } |
| 5993 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5994 | GlobalAddressSDNode::GlobalAddressSDNode(unsigned Opc, unsigned Order, |
| 5995 | DebugLoc DL, const GlobalValue *GA, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5996 | EVT VT, int64_t o, unsigned char TF) |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5997 | : SDNode(Opc, Order, DL, getSDVTList(VT)), Offset(o), TargetFlags(TF) { |
Dan Gohman | 383b5f6 | 2010-04-17 15:32:28 +0000 | [diff] [blame] | 5998 | TheGlobal = GA; |
Lauro Ramos Venancio | 2c5c111 | 2007-04-21 20:56:26 +0000 | [diff] [blame] | 5999 | } |
Chris Lattner | 48b8592 | 2007-02-04 02:41:42 +0000 | [diff] [blame] | 6000 | |
Matt Arsenault | 59d3ae6 | 2013-11-15 01:34:59 +0000 | [diff] [blame^] | 6001 | AddrSpaceCastSDNode::AddrSpaceCastSDNode(unsigned Order, DebugLoc dl, EVT VT, |
| 6002 | SDValue X, unsigned SrcAS, |
| 6003 | unsigned DestAS) |
| 6004 | : UnarySDNode(ISD::ADDRSPACECAST, Order, dl, getSDVTList(VT), X), |
| 6005 | SrcAddrSpace(SrcAS), DestAddrSpace(DestAS) {} |
| 6006 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6007 | MemSDNode::MemSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs, |
| 6008 | EVT memvt, MachineMemOperand *mmo) |
| 6009 | : SDNode(Opc, Order, dl, VTs), MemoryVT(memvt), MMO(mmo) { |
David Greene | 1157f79 | 2010-02-17 20:21:42 +0000 | [diff] [blame] | 6010 | SubclassData = encodeMemSDNodeFlags(0, ISD::UNINDEXED, MMO->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 6011 | MMO->isNonTemporal(), MMO->isInvariant()); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 6012 | assert(isVolatile() == MMO->isVolatile() && "Volatile encoding error!"); |
David Greene | 1157f79 | 2010-02-17 20:21:42 +0000 | [diff] [blame] | 6013 | assert(isNonTemporal() == MMO->isNonTemporal() && |
| 6014 | "Non-temporal encoding error!"); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 6015 | assert(memvt.getStoreSize() == MMO->getSize() && "Size mismatch!"); |
Dale Johannesen | 3edb43e | 2009-01-28 21:18:29 +0000 | [diff] [blame] | 6016 | } |
| 6017 | |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6018 | MemSDNode::MemSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6019 | const SDValue *Ops, unsigned NumOps, EVT memvt, |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 6020 | MachineMemOperand *mmo) |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6021 | : SDNode(Opc, Order, dl, VTs, Ops, NumOps), |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 6022 | MemoryVT(memvt), MMO(mmo) { |
David Greene | 1157f79 | 2010-02-17 20:21:42 +0000 | [diff] [blame] | 6023 | SubclassData = encodeMemSDNodeFlags(0, ISD::UNINDEXED, MMO->isVolatile(), |
Pete Cooper | d752e0f | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 6024 | MMO->isNonTemporal(), MMO->isInvariant()); |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 6025 | assert(isVolatile() == MMO->isVolatile() && "Volatile encoding error!"); |
| 6026 | assert(memvt.getStoreSize() == MMO->getSize() && "Size mismatch!"); |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6027 | } |
| 6028 | |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 6029 | /// Profile - Gather unique data for the node. |
| 6030 | /// |
Dan Gohman | b8d2f55 | 2008-08-20 15:58:01 +0000 | [diff] [blame] | 6031 | void SDNode::Profile(FoldingSetNodeID &ID) const { |
Jim Laskey | 583bd47 | 2006-10-27 23:46:08 +0000 | [diff] [blame] | 6032 | AddNodeIDNode(ID, this); |
| 6033 | } |
| 6034 | |
Owen Anderson | d8110fb | 2009-08-25 22:27:22 +0000 | [diff] [blame] | 6035 | namespace { |
| 6036 | struct EVTArray { |
| 6037 | std::vector<EVT> VTs; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6038 | |
Owen Anderson | d8110fb | 2009-08-25 22:27:22 +0000 | [diff] [blame] | 6039 | EVTArray() { |
| 6040 | VTs.reserve(MVT::LAST_VALUETYPE); |
| 6041 | for (unsigned i = 0; i < MVT::LAST_VALUETYPE; ++i) |
| 6042 | VTs.push_back(MVT((MVT::SimpleValueType)i)); |
| 6043 | } |
| 6044 | }; |
| 6045 | } |
| 6046 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6047 | static ManagedStatic<std::set<EVT, EVT::compareRawBits> > EVTs; |
Owen Anderson | d8110fb | 2009-08-25 22:27:22 +0000 | [diff] [blame] | 6048 | static ManagedStatic<EVTArray> SimpleVTArray; |
Chris Lattner | 895a55e | 2009-08-22 04:07:34 +0000 | [diff] [blame] | 6049 | static ManagedStatic<sys::SmartMutex<true> > VTMutex; |
Owen Anderson | b445908 | 2009-06-25 17:09:00 +0000 | [diff] [blame] | 6050 | |
Chris Lattner | a325511 | 2005-11-08 23:30:28 +0000 | [diff] [blame] | 6051 | /// getValueTypeList - Return a pointer to the specified value type. |
| 6052 | /// |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6053 | const EVT *SDNode::getValueTypeList(EVT VT) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6054 | if (VT.isExtended()) { |
Owen Anderson | 02b1034 | 2009-08-22 06:32:36 +0000 | [diff] [blame] | 6055 | sys::SmartScopedLock<true> Lock(*VTMutex); |
Owen Anderson | b445908 | 2009-06-25 17:09:00 +0000 | [diff] [blame] | 6056 | return &(*EVTs->insert(VT).first); |
Duncan Sands | af47b11 | 2007-10-16 09:56:48 +0000 | [diff] [blame] | 6057 | } else { |
Duncan Sands | cdfad36 | 2010-11-03 12:17:33 +0000 | [diff] [blame] | 6058 | assert(VT.getSimpleVT() < MVT::LAST_VALUETYPE && |
Duncan Sands | ad017dc | 2010-05-10 04:54:28 +0000 | [diff] [blame] | 6059 | "Value type out of range!"); |
Owen Anderson | d8110fb | 2009-08-25 22:27:22 +0000 | [diff] [blame] | 6060 | return &SimpleVTArray->VTs[VT.getSimpleVT().SimpleTy]; |
Duncan Sands | af47b11 | 2007-10-16 09:56:48 +0000 | [diff] [blame] | 6061 | } |
Chris Lattner | a325511 | 2005-11-08 23:30:28 +0000 | [diff] [blame] | 6062 | } |
Duncan Sands | af47b11 | 2007-10-16 09:56:48 +0000 | [diff] [blame] | 6063 | |
Chris Lattner | 5c88456 | 2005-01-12 18:37:47 +0000 | [diff] [blame] | 6064 | /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the |
| 6065 | /// indicated value. This method ignores uses of other values defined by this |
| 6066 | /// operation. |
Evan Cheng | 4ee6211 | 2006-02-05 06:29:23 +0000 | [diff] [blame] | 6067 | bool SDNode::hasNUsesOfValue(unsigned NUses, unsigned Value) const { |
Chris Lattner | 5c88456 | 2005-01-12 18:37:47 +0000 | [diff] [blame] | 6068 | assert(Value < getNumValues() && "Bad value!"); |
| 6069 | |
Roman Levenstein | dc1adac | 2008-04-07 10:06:32 +0000 | [diff] [blame] | 6070 | // TODO: Only iterate over uses of a given value of the node |
| 6071 | for (SDNode::use_iterator UI = use_begin(), E = use_end(); UI != E; ++UI) { |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 6072 | if (UI.getUse().getResNo() == Value) { |
Roman Levenstein | dc1adac | 2008-04-07 10:06:32 +0000 | [diff] [blame] | 6073 | if (NUses == 0) |
| 6074 | return false; |
| 6075 | --NUses; |
| 6076 | } |
Chris Lattner | 5c88456 | 2005-01-12 18:37:47 +0000 | [diff] [blame] | 6077 | } |
| 6078 | |
| 6079 | // Found exactly the right number of uses? |
| 6080 | return NUses == 0; |
| 6081 | } |
| 6082 | |
| 6083 | |
Evan Cheng | 33d5595 | 2007-08-02 05:29:38 +0000 | [diff] [blame] | 6084 | /// hasAnyUseOfValue - Return true if there are any use of the indicated |
| 6085 | /// value. This method ignores uses of other values defined by this operation. |
| 6086 | bool SDNode::hasAnyUseOfValue(unsigned Value) const { |
| 6087 | assert(Value < getNumValues() && "Bad value!"); |
| 6088 | |
Dan Gohman | 1373c1c | 2008-07-09 22:39:01 +0000 | [diff] [blame] | 6089 | for (SDNode::use_iterator UI = use_begin(), E = use_end(); UI != E; ++UI) |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 6090 | if (UI.getUse().getResNo() == Value) |
Dan Gohman | 1373c1c | 2008-07-09 22:39:01 +0000 | [diff] [blame] | 6091 | return true; |
Evan Cheng | 33d5595 | 2007-08-02 05:29:38 +0000 | [diff] [blame] | 6092 | |
| 6093 | return false; |
| 6094 | } |
| 6095 | |
| 6096 | |
Dan Gohman | 2a62995 | 2008-07-27 18:06:42 +0000 | [diff] [blame] | 6097 | /// isOnlyUserOf - Return true if this node is the only use of N. |
Evan Cheng | e6e97e6 | 2006-11-03 07:31:32 +0000 | [diff] [blame] | 6098 | /// |
Dan Gohman | 2a62995 | 2008-07-27 18:06:42 +0000 | [diff] [blame] | 6099 | bool SDNode::isOnlyUserOf(SDNode *N) const { |
Evan Cheng | 4ee6211 | 2006-02-05 06:29:23 +0000 | [diff] [blame] | 6100 | bool Seen = false; |
| 6101 | for (SDNode::use_iterator I = N->use_begin(), E = N->use_end(); I != E; ++I) { |
Dan Gohman | 8968450 | 2008-07-27 20:43:25 +0000 | [diff] [blame] | 6102 | SDNode *User = *I; |
Evan Cheng | 4ee6211 | 2006-02-05 06:29:23 +0000 | [diff] [blame] | 6103 | if (User == this) |
| 6104 | Seen = true; |
| 6105 | else |
| 6106 | return false; |
| 6107 | } |
| 6108 | |
| 6109 | return Seen; |
| 6110 | } |
| 6111 | |
Evan Cheng | e6e97e6 | 2006-11-03 07:31:32 +0000 | [diff] [blame] | 6112 | /// isOperand - Return true if this node is an operand of N. |
| 6113 | /// |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6114 | bool SDValue::isOperandOf(SDNode *N) const { |
Evan Cheng | bfa284f | 2006-03-03 06:42:32 +0000 | [diff] [blame] | 6115 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) |
| 6116 | if (*this == N->getOperand(i)) |
| 6117 | return true; |
| 6118 | return false; |
| 6119 | } |
| 6120 | |
Evan Cheng | 917be68 | 2008-03-04 00:41:45 +0000 | [diff] [blame] | 6121 | bool SDNode::isOperandOf(SDNode *N) const { |
Evan Cheng | 80d8eaa | 2006-03-03 06:24:54 +0000 | [diff] [blame] | 6122 | for (unsigned i = 0, e = N->NumOperands; i != e; ++i) |
Dan Gohman | e7852d0 | 2009-01-26 04:35:06 +0000 | [diff] [blame] | 6123 | if (this == N->OperandList[i].getNode()) |
Evan Cheng | 80d8eaa | 2006-03-03 06:24:54 +0000 | [diff] [blame] | 6124 | return true; |
| 6125 | return false; |
| 6126 | } |
Evan Cheng | 4ee6211 | 2006-02-05 06:29:23 +0000 | [diff] [blame] | 6127 | |
Chris Lattner | 572dee7 | 2008-01-16 05:49:24 +0000 | [diff] [blame] | 6128 | /// reachesChainWithoutSideEffects - Return true if this operand (which must |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6129 | /// be a chain) reaches the specified operand without crossing any |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6130 | /// side-effecting instructions on any chain path. In practice, this looks |
| 6131 | /// through token factors and non-volatile loads. In order to remain efficient, |
Owen Anderson | 14ac1dd | 2010-09-18 04:45:14 +0000 | [diff] [blame] | 6132 | /// this only looks a couple of nodes in, it does not do an exhaustive search. |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6133 | bool SDValue::reachesChainWithoutSideEffects(SDValue Dest, |
Chris Lattner | 572dee7 | 2008-01-16 05:49:24 +0000 | [diff] [blame] | 6134 | unsigned Depth) const { |
| 6135 | if (*this == Dest) return true; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6136 | |
Chris Lattner | 572dee7 | 2008-01-16 05:49:24 +0000 | [diff] [blame] | 6137 | // Don't search too deeply, we just want to be able to see through |
| 6138 | // TokenFactor's etc. |
| 6139 | if (Depth == 0) return false; |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6140 | |
Chris Lattner | 572dee7 | 2008-01-16 05:49:24 +0000 | [diff] [blame] | 6141 | // If this is a token factor, all inputs to the TF happen in parallel. If any |
Owen Anderson | 14ac1dd | 2010-09-18 04:45:14 +0000 | [diff] [blame] | 6142 | // of the operands of the TF does not reach dest, then we cannot do the xform. |
Chris Lattner | 572dee7 | 2008-01-16 05:49:24 +0000 | [diff] [blame] | 6143 | if (getOpcode() == ISD::TokenFactor) { |
| 6144 | for (unsigned i = 0, e = getNumOperands(); i != e; ++i) |
Owen Anderson | 14ac1dd | 2010-09-18 04:45:14 +0000 | [diff] [blame] | 6145 | if (!getOperand(i).reachesChainWithoutSideEffects(Dest, Depth-1)) |
| 6146 | return false; |
| 6147 | return true; |
Chris Lattner | 572dee7 | 2008-01-16 05:49:24 +0000 | [diff] [blame] | 6148 | } |
Scott Michel | fdc40a0 | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6149 | |
Chris Lattner | 572dee7 | 2008-01-16 05:49:24 +0000 | [diff] [blame] | 6150 | // Loads don't have side effects, look through them. |
| 6151 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(*this)) { |
| 6152 | if (!Ld->isVolatile()) |
| 6153 | return Ld->getChain().reachesChainWithoutSideEffects(Dest, Depth-1); |
| 6154 | } |
| 6155 | return false; |
| 6156 | } |
| 6157 | |
Lang Hames | 944520f | 2011-07-07 04:31:51 +0000 | [diff] [blame] | 6158 | /// hasPredecessor - Return true if N is a predecessor of this node. |
| 6159 | /// N is either an operand of this node, or can be reached by recursively |
| 6160 | /// traversing up the operands. |
| 6161 | /// NOTE: This is an expensive method. Use it carefully. |
| 6162 | bool SDNode::hasPredecessor(const SDNode *N) const { |
| 6163 | SmallPtrSet<const SDNode *, 32> Visited; |
| 6164 | SmallVector<const SDNode *, 16> Worklist; |
| 6165 | return hasPredecessorHelper(N, Visited, Worklist); |
| 6166 | } |
Dan Gohman | 6688d61 | 2009-10-28 03:44:30 +0000 | [diff] [blame] | 6167 | |
Craig Topper | a0ec3f9 | 2013-07-14 04:42:23 +0000 | [diff] [blame] | 6168 | bool |
| 6169 | SDNode::hasPredecessorHelper(const SDNode *N, |
| 6170 | SmallPtrSet<const SDNode *, 32> &Visited, |
| 6171 | SmallVectorImpl<const SDNode *> &Worklist) const { |
Lang Hames | 944520f | 2011-07-07 04:31:51 +0000 | [diff] [blame] | 6172 | if (Visited.empty()) { |
| 6173 | Worklist.push_back(this); |
| 6174 | } else { |
| 6175 | // Take a look in the visited set. If we've already encountered this node |
| 6176 | // we needn't search further. |
| 6177 | if (Visited.count(N)) |
| 6178 | return true; |
| 6179 | } |
| 6180 | |
| 6181 | // Haven't visited N yet. Continue the search. |
| 6182 | while (!Worklist.empty()) { |
| 6183 | const SDNode *M = Worklist.pop_back_val(); |
| 6184 | for (unsigned i = 0, e = M->getNumOperands(); i != e; ++i) { |
| 6185 | SDNode *Op = M->getOperand(i).getNode(); |
Dan Gohman | 6688d61 | 2009-10-28 03:44:30 +0000 | [diff] [blame] | 6186 | if (Visited.insert(Op)) |
| 6187 | Worklist.push_back(Op); |
Lang Hames | 944520f | 2011-07-07 04:31:51 +0000 | [diff] [blame] | 6188 | if (Op == N) |
| 6189 | return true; |
Dan Gohman | 6688d61 | 2009-10-28 03:44:30 +0000 | [diff] [blame] | 6190 | } |
Lang Hames | 944520f | 2011-07-07 04:31:51 +0000 | [diff] [blame] | 6191 | } |
Dan Gohman | 6688d61 | 2009-10-28 03:44:30 +0000 | [diff] [blame] | 6192 | |
| 6193 | return false; |
Evan Cheng | c5fc57d | 2006-11-03 03:05:24 +0000 | [diff] [blame] | 6194 | } |
| 6195 | |
Evan Cheng | c548428 | 2006-10-04 00:56:09 +0000 | [diff] [blame] | 6196 | uint64_t SDNode::getConstantOperandVal(unsigned Num) const { |
| 6197 | assert(Num < NumOperands && "Invalid child # of SDNode!"); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 6198 | return cast<ConstantSDNode>(OperandList[Num])->getZExtValue(); |
Evan Cheng | c548428 | 2006-10-04 00:56:09 +0000 | [diff] [blame] | 6199 | } |
| 6200 | |
Mon P Wang | cd6e725 | 2009-11-30 02:42:02 +0000 | [diff] [blame] | 6201 | SDValue SelectionDAG::UnrollVectorOp(SDNode *N, unsigned ResNE) { |
| 6202 | assert(N->getNumValues() == 1 && |
| 6203 | "Can't unroll a vector with multiple results!"); |
| 6204 | |
| 6205 | EVT VT = N->getValueType(0); |
| 6206 | unsigned NE = VT.getVectorNumElements(); |
| 6207 | EVT EltVT = VT.getVectorElementType(); |
Andrew Trick | ac6d9be | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6208 | SDLoc dl(N); |
Mon P Wang | cd6e725 | 2009-11-30 02:42:02 +0000 | [diff] [blame] | 6209 | |
| 6210 | SmallVector<SDValue, 8> Scalars; |
| 6211 | SmallVector<SDValue, 4> Operands(N->getNumOperands()); |
| 6212 | |
| 6213 | // If ResNE is 0, fully unroll the vector op. |
| 6214 | if (ResNE == 0) |
| 6215 | ResNE = NE; |
| 6216 | else if (NE > ResNE) |
| 6217 | NE = ResNE; |
| 6218 | |
| 6219 | unsigned i; |
| 6220 | for (i= 0; i != NE; ++i) { |
Bill Wendling | d71bb56 | 2010-04-30 22:19:17 +0000 | [diff] [blame] | 6221 | for (unsigned j = 0, e = N->getNumOperands(); j != e; ++j) { |
Mon P Wang | cd6e725 | 2009-11-30 02:42:02 +0000 | [diff] [blame] | 6222 | SDValue Operand = N->getOperand(j); |
| 6223 | EVT OperandVT = Operand.getValueType(); |
| 6224 | if (OperandVT.isVector()) { |
| 6225 | // A vector operand; extract a single element. |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 6226 | const TargetLowering *TLI = TM.getTargetLowering(); |
Mon P Wang | cd6e725 | 2009-11-30 02:42:02 +0000 | [diff] [blame] | 6227 | EVT OperandEltVT = OperandVT.getVectorElementType(); |
| 6228 | Operands[j] = getNode(ISD::EXTRACT_VECTOR_ELT, dl, |
| 6229 | OperandEltVT, |
| 6230 | Operand, |
Tom Stellard | 425b76c | 2013-08-05 22:22:01 +0000 | [diff] [blame] | 6231 | getConstant(i, TLI->getVectorIdxTy())); |
Mon P Wang | cd6e725 | 2009-11-30 02:42:02 +0000 | [diff] [blame] | 6232 | } else { |
| 6233 | // A scalar operand; just use it as is. |
| 6234 | Operands[j] = Operand; |
| 6235 | } |
| 6236 | } |
| 6237 | |
| 6238 | switch (N->getOpcode()) { |
| 6239 | default: |
| 6240 | Scalars.push_back(getNode(N->getOpcode(), dl, EltVT, |
| 6241 | &Operands[0], Operands.size())); |
| 6242 | break; |
Nadav Rotem | aec5861 | 2011-09-13 19:17:42 +0000 | [diff] [blame] | 6243 | case ISD::VSELECT: |
| 6244 | Scalars.push_back(getNode(ISD::SELECT, dl, EltVT, |
| 6245 | &Operands[0], Operands.size())); |
| 6246 | break; |
Mon P Wang | cd6e725 | 2009-11-30 02:42:02 +0000 | [diff] [blame] | 6247 | case ISD::SHL: |
| 6248 | case ISD::SRA: |
| 6249 | case ISD::SRL: |
| 6250 | case ISD::ROTL: |
| 6251 | case ISD::ROTR: |
| 6252 | Scalars.push_back(getNode(N->getOpcode(), dl, EltVT, Operands[0], |
Jack Carter | 3af4d25 | 2013-09-09 22:02:08 +0000 | [diff] [blame] | 6253 | getShiftAmountOperand(Operands[0].getValueType(), |
| 6254 | Operands[1]))); |
Mon P Wang | cd6e725 | 2009-11-30 02:42:02 +0000 | [diff] [blame] | 6255 | break; |
Dan Gohman | d199636 | 2010-01-09 02:13:55 +0000 | [diff] [blame] | 6256 | case ISD::SIGN_EXTEND_INREG: |
| 6257 | case ISD::FP_ROUND_INREG: { |
| 6258 | EVT ExtVT = cast<VTSDNode>(Operands[1])->getVT().getVectorElementType(); |
| 6259 | Scalars.push_back(getNode(N->getOpcode(), dl, EltVT, |
| 6260 | Operands[0], |
| 6261 | getValueType(ExtVT))); |
| 6262 | } |
Mon P Wang | cd6e725 | 2009-11-30 02:42:02 +0000 | [diff] [blame] | 6263 | } |
| 6264 | } |
| 6265 | |
| 6266 | for (; i < ResNE; ++i) |
| 6267 | Scalars.push_back(getUNDEF(EltVT)); |
| 6268 | |
| 6269 | return getNode(ISD::BUILD_VECTOR, dl, |
| 6270 | EVT::getVectorVT(*getContext(), EltVT, ResNE), |
| 6271 | &Scalars[0], Scalars.size()); |
| 6272 | } |
| 6273 | |
Evan Cheng | 64fa4a9 | 2009-12-09 01:36:00 +0000 | [diff] [blame] | 6274 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6275 | /// isConsecutiveLoad - Return true if LD is loading 'Bytes' bytes from a |
| 6276 | /// location that is 'Dist' units away from the location that the 'Base' load |
Evan Cheng | 64fa4a9 | 2009-12-09 01:36:00 +0000 | [diff] [blame] | 6277 | /// is loading from. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6278 | bool SelectionDAG::isConsecutiveLoad(LoadSDNode *LD, LoadSDNode *Base, |
Evan Cheng | 64fa4a9 | 2009-12-09 01:36:00 +0000 | [diff] [blame] | 6279 | unsigned Bytes, int Dist) const { |
| 6280 | if (LD->getChain() != Base->getChain()) |
| 6281 | return false; |
| 6282 | EVT VT = LD->getValueType(0); |
| 6283 | if (VT.getSizeInBits() / 8 != Bytes) |
| 6284 | return false; |
| 6285 | |
| 6286 | SDValue Loc = LD->getOperand(1); |
| 6287 | SDValue BaseLoc = Base->getOperand(1); |
| 6288 | if (Loc.getOpcode() == ISD::FrameIndex) { |
| 6289 | if (BaseLoc.getOpcode() != ISD::FrameIndex) |
| 6290 | return false; |
| 6291 | const MachineFrameInfo *MFI = getMachineFunction().getFrameInfo(); |
| 6292 | int FI = cast<FrameIndexSDNode>(Loc)->getIndex(); |
| 6293 | int BFI = cast<FrameIndexSDNode>(BaseLoc)->getIndex(); |
| 6294 | int FS = MFI->getObjectSize(FI); |
| 6295 | int BFS = MFI->getObjectSize(BFI); |
| 6296 | if (FS != BFS || FS != (int)Bytes) return false; |
| 6297 | return MFI->getObjectOffset(FI) == (MFI->getObjectOffset(BFI) + Dist*Bytes); |
| 6298 | } |
Chris Lattner | 0a9481f | 2011-02-13 22:25:43 +0000 | [diff] [blame] | 6299 | |
| 6300 | // Handle X+C |
| 6301 | if (isBaseWithConstantOffset(Loc) && Loc.getOperand(0) == BaseLoc && |
| 6302 | cast<ConstantSDNode>(Loc.getOperand(1))->getSExtValue() == Dist*Bytes) |
| 6303 | return true; |
Evan Cheng | 64fa4a9 | 2009-12-09 01:36:00 +0000 | [diff] [blame] | 6304 | |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 6305 | const GlobalValue *GV1 = NULL; |
| 6306 | const GlobalValue *GV2 = NULL; |
Evan Cheng | 64fa4a9 | 2009-12-09 01:36:00 +0000 | [diff] [blame] | 6307 | int64_t Offset1 = 0; |
| 6308 | int64_t Offset2 = 0; |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 6309 | const TargetLowering *TLI = TM.getTargetLowering(); |
| 6310 | bool isGA1 = TLI->isGAPlusOffset(Loc.getNode(), GV1, Offset1); |
| 6311 | bool isGA2 = TLI->isGAPlusOffset(BaseLoc.getNode(), GV2, Offset2); |
Evan Cheng | 64fa4a9 | 2009-12-09 01:36:00 +0000 | [diff] [blame] | 6312 | if (isGA1 && isGA2 && GV1 == GV2) |
| 6313 | return Offset1 == (Offset2 + Dist*Bytes); |
| 6314 | return false; |
| 6315 | } |
| 6316 | |
| 6317 | |
Evan Cheng | f2dc5c7 | 2009-12-09 01:04:59 +0000 | [diff] [blame] | 6318 | /// InferPtrAlignment - Infer alignment of a load / store address. Return 0 if |
| 6319 | /// it cannot be inferred. |
Evan Cheng | 7ced2e0 | 2009-12-09 01:10:37 +0000 | [diff] [blame] | 6320 | unsigned SelectionDAG::InferPtrAlignment(SDValue Ptr) const { |
Evan Cheng | 7bd6478 | 2009-12-09 01:53:58 +0000 | [diff] [blame] | 6321 | // If this is a GlobalAddress + cst, return the alignment. |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 6322 | const GlobalValue *GV; |
Evan Cheng | 7bd6478 | 2009-12-09 01:53:58 +0000 | [diff] [blame] | 6323 | int64_t GVOffset = 0; |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 6324 | const TargetLowering *TLI = TM.getTargetLowering(); |
| 6325 | if (TLI->isGAPlusOffset(Ptr.getNode(), GV, GVOffset)) { |
| 6326 | unsigned PtrWidth = TLI->getPointerTy().getSizeInBits(); |
Eli Friedman | c4c2a02 | 2011-11-28 22:48:22 +0000 | [diff] [blame] | 6327 | APInt KnownZero(PtrWidth, 0), KnownOne(PtrWidth, 0); |
Rafael Espindola | 26c8dcc | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 6328 | llvm::ComputeMaskedBits(const_cast<GlobalValue*>(GV), KnownZero, KnownOne, |
Bill Wendling | ba54bca | 2013-06-19 21:36:55 +0000 | [diff] [blame] | 6329 | TLI->getDataLayout()); |
Eli Friedman | c4c2a02 | 2011-11-28 22:48:22 +0000 | [diff] [blame] | 6330 | unsigned AlignBits = KnownZero.countTrailingOnes(); |
| 6331 | unsigned Align = AlignBits ? 1 << std::min(31U, AlignBits) : 0; |
| 6332 | if (Align) |
| 6333 | return MinAlign(Align, GVOffset); |
Evan Cheng | 255f20f | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 6334 | } |
Evan Cheng | 7bd6478 | 2009-12-09 01:53:58 +0000 | [diff] [blame] | 6335 | |
Evan Cheng | f2dc5c7 | 2009-12-09 01:04:59 +0000 | [diff] [blame] | 6336 | // If this is a direct reference to a stack slot, use information about the |
| 6337 | // stack slot's alignment. |
| 6338 | int FrameIdx = 1 << 31; |
| 6339 | int64_t FrameOffset = 0; |
| 6340 | if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Ptr)) { |
| 6341 | FrameIdx = FI->getIndex(); |
Chris Lattner | 0a9481f | 2011-02-13 22:25:43 +0000 | [diff] [blame] | 6342 | } else if (isBaseWithConstantOffset(Ptr) && |
Evan Cheng | f2dc5c7 | 2009-12-09 01:04:59 +0000 | [diff] [blame] | 6343 | isa<FrameIndexSDNode>(Ptr.getOperand(0))) { |
Chris Lattner | 0a9481f | 2011-02-13 22:25:43 +0000 | [diff] [blame] | 6344 | // Handle FI+Cst |
Evan Cheng | f2dc5c7 | 2009-12-09 01:04:59 +0000 | [diff] [blame] | 6345 | FrameIdx = cast<FrameIndexSDNode>(Ptr.getOperand(0))->getIndex(); |
| 6346 | FrameOffset = Ptr.getConstantOperandVal(1); |
| 6347 | } |
| 6348 | |
| 6349 | if (FrameIdx != (1 << 31)) { |
Evan Cheng | f2dc5c7 | 2009-12-09 01:04:59 +0000 | [diff] [blame] | 6350 | const MachineFrameInfo &MFI = *getMachineFunction().getFrameInfo(); |
Evan Cheng | de2ace1 | 2009-12-09 01:17:24 +0000 | [diff] [blame] | 6351 | unsigned FIInfoAlign = MinAlign(MFI.getObjectAlignment(FrameIdx), |
| 6352 | FrameOffset); |
Evan Cheng | de2ace1 | 2009-12-09 01:17:24 +0000 | [diff] [blame] | 6353 | return FIInfoAlign; |
Evan Cheng | f2dc5c7 | 2009-12-09 01:04:59 +0000 | [diff] [blame] | 6354 | } |
| 6355 | |
| 6356 | return 0; |
| 6357 | } |
| 6358 | |
Sanjiv Gupta | a3518a1 | 2009-04-29 04:43:24 +0000 | [diff] [blame] | 6359 | // getAddressSpace - Return the address space this GlobalAddress belongs to. |
| 6360 | unsigned GlobalAddressSDNode::getAddressSpace() const { |
| 6361 | return getGlobal()->getType()->getAddressSpace(); |
| 6362 | } |
| 6363 | |
| 6364 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 6365 | Type *ConstantPoolSDNode::getType() const { |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 6366 | if (isMachineConstantPoolEntry()) |
| 6367 | return Val.MachineCPVal->getType(); |
| 6368 | return Val.ConstVal->getType(); |
| 6369 | } |
Bob Wilson | a27ea9e | 2009-03-01 01:13:55 +0000 | [diff] [blame] | 6370 | |
Bob Wilson | 24e338e | 2009-03-02 23:24:16 +0000 | [diff] [blame] | 6371 | bool BuildVectorSDNode::isConstantSplat(APInt &SplatValue, |
| 6372 | APInt &SplatUndef, |
| 6373 | unsigned &SplatBitSize, |
| 6374 | bool &HasAnyUndefs, |
Dale Johannesen | 1e60881 | 2009-11-13 01:45:18 +0000 | [diff] [blame] | 6375 | unsigned MinSplatBits, |
| 6376 | bool isBigEndian) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6377 | EVT VT = getValueType(0); |
Bob Wilson | 24e338e | 2009-03-02 23:24:16 +0000 | [diff] [blame] | 6378 | assert(VT.isVector() && "Expected a vector type"); |
| 6379 | unsigned sz = VT.getSizeInBits(); |
| 6380 | if (MinSplatBits > sz) |
| 6381 | return false; |
Bob Wilson | a27ea9e | 2009-03-01 01:13:55 +0000 | [diff] [blame] | 6382 | |
Bob Wilson | 24e338e | 2009-03-02 23:24:16 +0000 | [diff] [blame] | 6383 | SplatValue = APInt(sz, 0); |
| 6384 | SplatUndef = APInt(sz, 0); |
Bob Wilson | a27ea9e | 2009-03-01 01:13:55 +0000 | [diff] [blame] | 6385 | |
Bob Wilson | 24e338e | 2009-03-02 23:24:16 +0000 | [diff] [blame] | 6386 | // Get the bits. Bits with undefined values (when the corresponding element |
| 6387 | // of the vector is an ISD::UNDEF value) are set in SplatUndef and cleared |
| 6388 | // in SplatValue. If any of the values are not constant, give up and return |
| 6389 | // false. |
| 6390 | unsigned int nOps = getNumOperands(); |
| 6391 | assert(nOps > 0 && "isConstantSplat has 0-size build vector"); |
| 6392 | unsigned EltBitSize = VT.getVectorElementType().getSizeInBits(); |
Dale Johannesen | 1e60881 | 2009-11-13 01:45:18 +0000 | [diff] [blame] | 6393 | |
| 6394 | for (unsigned j = 0; j < nOps; ++j) { |
| 6395 | unsigned i = isBigEndian ? nOps-1-j : j; |
Bob Wilson | a27ea9e | 2009-03-01 01:13:55 +0000 | [diff] [blame] | 6396 | SDValue OpVal = getOperand(i); |
Dale Johannesen | 1e60881 | 2009-11-13 01:45:18 +0000 | [diff] [blame] | 6397 | unsigned BitPos = j * EltBitSize; |
Bob Wilson | a27ea9e | 2009-03-01 01:13:55 +0000 | [diff] [blame] | 6398 | |
Bob Wilson | 24e338e | 2009-03-02 23:24:16 +0000 | [diff] [blame] | 6399 | if (OpVal.getOpcode() == ISD::UNDEF) |
Dale Johannesen | 1e60881 | 2009-11-13 01:45:18 +0000 | [diff] [blame] | 6400 | SplatUndef |= APInt::getBitsSet(sz, BitPos, BitPos + EltBitSize); |
Bob Wilson | 24e338e | 2009-03-02 23:24:16 +0000 | [diff] [blame] | 6401 | else if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(OpVal)) |
Jay Foad | 40f8f62 | 2010-12-07 08:25:19 +0000 | [diff] [blame] | 6402 | SplatValue |= CN->getAPIntValue().zextOrTrunc(EltBitSize). |
Dan Gohman | 58c2587 | 2010-04-12 02:24:01 +0000 | [diff] [blame] | 6403 | zextOrTrunc(sz) << BitPos; |
Bob Wilson | 24e338e | 2009-03-02 23:24:16 +0000 | [diff] [blame] | 6404 | else if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(OpVal)) |
Bob Wilson | d344b88 | 2009-03-04 17:47:01 +0000 | [diff] [blame] | 6405 | SplatValue |= CN->getValueAPF().bitcastToAPInt().zextOrTrunc(sz) <<BitPos; |
Bob Wilson | 24e338e | 2009-03-02 23:24:16 +0000 | [diff] [blame] | 6406 | else |
Bob Wilson | a27ea9e | 2009-03-01 01:13:55 +0000 | [diff] [blame] | 6407 | return false; |
Bob Wilson | a27ea9e | 2009-03-01 01:13:55 +0000 | [diff] [blame] | 6408 | } |
| 6409 | |
Bob Wilson | 24e338e | 2009-03-02 23:24:16 +0000 | [diff] [blame] | 6410 | // The build_vector is all constants or undefs. Find the smallest element |
| 6411 | // size that splats the vector. |
Bob Wilson | a27ea9e | 2009-03-01 01:13:55 +0000 | [diff] [blame] | 6412 | |
Bob Wilson | 24e338e | 2009-03-02 23:24:16 +0000 | [diff] [blame] | 6413 | HasAnyUndefs = (SplatUndef != 0); |
| 6414 | while (sz > 8) { |
Bob Wilson | a27ea9e | 2009-03-01 01:13:55 +0000 | [diff] [blame] | 6415 | |
Bob Wilson | 24e338e | 2009-03-02 23:24:16 +0000 | [diff] [blame] | 6416 | unsigned HalfSize = sz / 2; |
Jay Foad | 40f8f62 | 2010-12-07 08:25:19 +0000 | [diff] [blame] | 6417 | APInt HighValue = SplatValue.lshr(HalfSize).trunc(HalfSize); |
| 6418 | APInt LowValue = SplatValue.trunc(HalfSize); |
| 6419 | APInt HighUndef = SplatUndef.lshr(HalfSize).trunc(HalfSize); |
| 6420 | APInt LowUndef = SplatUndef.trunc(HalfSize); |
Bob Wilson | a27ea9e | 2009-03-01 01:13:55 +0000 | [diff] [blame] | 6421 | |
Bob Wilson | 24e338e | 2009-03-02 23:24:16 +0000 | [diff] [blame] | 6422 | // If the two halves do not match (ignoring undef bits), stop here. |
| 6423 | if ((HighValue & ~LowUndef) != (LowValue & ~HighUndef) || |
| 6424 | MinSplatBits > HalfSize) |
| 6425 | break; |
Bob Wilson | a27ea9e | 2009-03-01 01:13:55 +0000 | [diff] [blame] | 6426 | |
Bob Wilson | 24e338e | 2009-03-02 23:24:16 +0000 | [diff] [blame] | 6427 | SplatValue = HighValue | LowValue; |
| 6428 | SplatUndef = HighUndef & LowUndef; |
Eric Christopher | 4d7c18c | 2009-08-22 00:40:45 +0000 | [diff] [blame] | 6429 | |
Bob Wilson | 24e338e | 2009-03-02 23:24:16 +0000 | [diff] [blame] | 6430 | sz = HalfSize; |
Bob Wilson | a27ea9e | 2009-03-01 01:13:55 +0000 | [diff] [blame] | 6431 | } |
| 6432 | |
Bob Wilson | 24e338e | 2009-03-02 23:24:16 +0000 | [diff] [blame] | 6433 | SplatBitSize = sz; |
Bob Wilson | a27ea9e | 2009-03-01 01:13:55 +0000 | [diff] [blame] | 6434 | return true; |
| 6435 | } |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 6436 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6437 | bool ShuffleVectorSDNode::isSplatMask(const int *Mask, EVT VT) { |
Nate Begeman | 5a5ca15 | 2009-04-29 05:20:52 +0000 | [diff] [blame] | 6438 | // Find the first non-undef value in the shuffle mask. |
| 6439 | unsigned i, e; |
| 6440 | for (i = 0, e = VT.getVectorNumElements(); i != e && Mask[i] < 0; ++i) |
| 6441 | /* search */; |
| 6442 | |
Nate Begeman | a641575 | 2009-04-29 18:13:31 +0000 | [diff] [blame] | 6443 | assert(i != e && "VECTOR_SHUFFLE node with all undef indices!"); |
Eric Christopher | 4d7c18c | 2009-08-22 00:40:45 +0000 | [diff] [blame] | 6444 | |
Nate Begeman | 5a5ca15 | 2009-04-29 05:20:52 +0000 | [diff] [blame] | 6445 | // Make sure all remaining elements are either undef or the same as the first |
| 6446 | // non-undef value. |
| 6447 | for (int Idx = Mask[i]; i != e; ++i) |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 6448 | if (Mask[i] >= 0 && Mask[i] != Idx) |
| 6449 | return false; |
Nate Begeman | 9008ca6 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 6450 | return true; |
| 6451 | } |
David Greene | cf495bc | 2010-01-20 20:13:31 +0000 | [diff] [blame] | 6452 | |
Chris Lattner | 46ca5ef | 2010-02-24 21:34:04 +0000 | [diff] [blame] | 6453 | #ifdef XDEBUG |
David Greene | cf495bc | 2010-01-20 20:13:31 +0000 | [diff] [blame] | 6454 | static void checkForCyclesHelper(const SDNode *N, |
Chris Lattner | 46ca5ef | 2010-02-24 21:34:04 +0000 | [diff] [blame] | 6455 | SmallPtrSet<const SDNode*, 32> &Visited, |
| 6456 | SmallPtrSet<const SDNode*, 32> &Checked) { |
| 6457 | // If this node has already been checked, don't check it again. |
| 6458 | if (Checked.count(N)) |
David Greene | e3d97c7 | 2010-02-23 17:37:50 +0000 | [diff] [blame] | 6459 | return; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6460 | |
Chris Lattner | 46ca5ef | 2010-02-24 21:34:04 +0000 | [diff] [blame] | 6461 | // If a node has already been visited on this depth-first walk, reject it as |
| 6462 | // a cycle. |
| 6463 | if (!Visited.insert(N)) { |
David Greene | cf495bc | 2010-01-20 20:13:31 +0000 | [diff] [blame] | 6464 | dbgs() << "Offending node:\n"; |
| 6465 | N->dumprFull(); |
Chris Lattner | 46ca5ef | 2010-02-24 21:34:04 +0000 | [diff] [blame] | 6466 | errs() << "Detected cycle in SelectionDAG\n"; |
| 6467 | abort(); |
David Greene | cf495bc | 2010-01-20 20:13:31 +0000 | [diff] [blame] | 6468 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6469 | |
Chris Lattner | 46ca5ef | 2010-02-24 21:34:04 +0000 | [diff] [blame] | 6470 | for(unsigned i = 0, e = N->getNumOperands(); i != e; ++i) |
| 6471 | checkForCyclesHelper(N->getOperand(i).getNode(), Visited, Checked); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6472 | |
Chris Lattner | 46ca5ef | 2010-02-24 21:34:04 +0000 | [diff] [blame] | 6473 | Checked.insert(N); |
| 6474 | Visited.erase(N); |
David Greene | cf495bc | 2010-01-20 20:13:31 +0000 | [diff] [blame] | 6475 | } |
Chris Lattner | 46ca5ef | 2010-02-24 21:34:04 +0000 | [diff] [blame] | 6476 | #endif |
David Greene | cf495bc | 2010-01-20 20:13:31 +0000 | [diff] [blame] | 6477 | |
| 6478 | void llvm::checkForCycles(const llvm::SDNode *N) { |
| 6479 | #ifdef XDEBUG |
Alp Toker | 18a988e | 2013-10-29 02:35:28 +0000 | [diff] [blame] | 6480 | assert(N && "Checking nonexistent SDNode"); |
Chris Lattner | 46ca5ef | 2010-02-24 21:34:04 +0000 | [diff] [blame] | 6481 | SmallPtrSet<const SDNode*, 32> visited; |
| 6482 | SmallPtrSet<const SDNode*, 32> checked; |
David Greene | e3d97c7 | 2010-02-23 17:37:50 +0000 | [diff] [blame] | 6483 | checkForCyclesHelper(N, visited, checked); |
David Greene | cf495bc | 2010-01-20 20:13:31 +0000 | [diff] [blame] | 6484 | #endif |
| 6485 | } |
| 6486 | |
| 6487 | void llvm::checkForCycles(const llvm::SelectionDAG *DAG) { |
| 6488 | checkForCycles(DAG->getRoot().getNode()); |
| 6489 | } |