| Nate Begeman | 0b71e00 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 1 | //===-- PPCISelLowering.cpp - PPC DAG Lowering Implementation -------------===// | 
| Chris Lattner | f22556d | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 2 | // | 
|  | 3 | //                     The LLVM Compiler Infrastructure | 
|  | 4 | // | 
| Chris Lattner | f3ebc3f | 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. | 
| Chris Lattner | f22556d | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 7 | // | 
|  | 8 | //===----------------------------------------------------------------------===// | 
|  | 9 | // | 
| Nate Begeman | 6cca84e | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 10 | // This file implements the PPCISelLowering class. | 
| Chris Lattner | f22556d | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 11 | // | 
|  | 12 | //===----------------------------------------------------------------------===// | 
|  | 13 |  | 
| Chris Lattner | 6f3b954 | 2005-10-14 23:59:06 +0000 | [diff] [blame] | 14 | #include "PPCISelLowering.h" | 
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "MCTargetDesc/PPCPredicates.h" | 
| Hal Finkel | 934361a | 2015-01-14 01:07:51 +0000 | [diff] [blame] | 16 | #include "PPCCallingConv.h" | 
| Strahinja Petrovic | e682b80 | 2016-05-09 12:27:39 +0000 | [diff] [blame] | 17 | #include "PPCCCState.h" | 
| Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 18 | #include "PPCMachineFunctionInfo.h" | 
| Bill Wendling | dd3fe94 | 2010-03-12 02:00:43 +0000 | [diff] [blame] | 19 | #include "PPCPerfectShuffle.h" | 
| Chris Lattner | 6f3b954 | 2005-10-14 23:59:06 +0000 | [diff] [blame] | 20 | #include "PPCTargetMachine.h" | 
| Bill Schmidt | 22d40dc | 2013-05-13 19:34:37 +0000 | [diff] [blame] | 21 | #include "PPCTargetObjectFile.h" | 
| Owen Anderson | e2f23a3 | 2007-09-07 04:06:50 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/STLExtras.h" | 
| Chuang-Yu Cheng | 2e5973e | 2016-04-06 02:04:38 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/Statistic.h" | 
| Hal Finkel | 0d8db46 | 2014-05-11 19:29:11 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/StringSwitch.h" | 
| Eric Christopher | 8995833 | 2014-05-31 00:07:32 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/Triple.h" | 
| Chris Lattner | 4f2e4e0 | 2007-03-06 00:59:59 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/CallingConvLower.h" | 
| Chris Lattner | f22556d | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/MachineFrameInfo.h" | 
|  | 28 | #include "llvm/CodeGen/MachineFunction.h" | 
| Chris Lattner | 9b577f1 | 2005-08-26 21:23:58 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/MachineInstrBuilder.h" | 
| Hal Finkel | 5772566 | 2015-01-03 17:58:24 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineLoopInfo.h" | 
| Chris Lattner | a10fff5 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/MachineRegisterInfo.h" | 
| Chris Lattner | f22556d | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/SelectionDAG.h" | 
| Anton Korobeynikov | ab663a0 | 2010-02-15 22:37:53 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" | 
| Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 34 | #include "llvm/IR/CallingConv.h" | 
|  | 35 | #include "llvm/IR/Constants.h" | 
|  | 36 | #include "llvm/IR/DerivedTypes.h" | 
|  | 37 | #include "llvm/IR/Function.h" | 
|  | 38 | #include "llvm/IR/Intrinsics.h" | 
| Chris Lattner | ce64554 | 2006-11-10 02:08:47 +0000 | [diff] [blame] | 39 | #include "llvm/Support/CommandLine.h" | 
| Torok Edwin | fb8d6d5 | 2009-07-08 20:53:28 +0000 | [diff] [blame] | 40 | #include "llvm/Support/ErrorHandling.h" | 
| Chuang-Yu Cheng | 2e5973e | 2016-04-06 02:04:38 +0000 | [diff] [blame] | 41 | #include "llvm/Support/Format.h" | 
| Craig Topper | b25fda9 | 2012-03-17 18:46:09 +0000 | [diff] [blame] | 42 | #include "llvm/Support/MathExtras.h" | 
| Torok Edwin | fb8d6d5 | 2009-07-08 20:53:28 +0000 | [diff] [blame] | 43 | #include "llvm/Support/raw_ostream.h" | 
| Craig Topper | b25fda9 | 2012-03-17 18:46:09 +0000 | [diff] [blame] | 44 | #include "llvm/Target/TargetOptions.h" | 
| Hal Finkel | 1fb10e8 | 2016-05-12 04:00:56 +0000 | [diff] [blame] | 45 | #include <list> | 
| Kit Barton | d4eb73c | 2015-05-05 16:10:44 +0000 | [diff] [blame] | 46 |  | 
| Chris Lattner | f22556d | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 47 | using namespace llvm; | 
|  | 48 |  | 
| Chuang-Yu Cheng | 2e5973e | 2016-04-06 02:04:38 +0000 | [diff] [blame] | 49 | #define DEBUG_TYPE "ppc-lowering" | 
|  | 50 |  | 
| Hal Finkel | 595817e | 2012-06-04 02:21:00 +0000 | [diff] [blame] | 51 | static cl::opt<bool> DisablePPCPreinc("disable-ppc-preinc", | 
|  | 52 | cl::desc("disable preincrement load/store generation on PPC"), cl::Hidden); | 
| Chris Lattner | ce64554 | 2006-11-10 02:08:47 +0000 | [diff] [blame] | 53 |  | 
| Hal Finkel | 4e9f1a8 | 2012-06-10 19:32:29 +0000 | [diff] [blame] | 54 | static cl::opt<bool> DisableILPPref("disable-ppc-ilp-pref", | 
|  | 55 | cl::desc("disable setting the node scheduling preference to ILP on PPC"), cl::Hidden); | 
|  | 56 |  | 
| Hal Finkel | 8d7fbc9 | 2013-03-15 15:27:13 +0000 | [diff] [blame] | 57 | static cl::opt<bool> DisablePPCUnaligned("disable-ppc-unaligned", | 
|  | 58 | cl::desc("disable unaligned load/store generation on PPC"), cl::Hidden); | 
|  | 59 |  | 
| Chuang-Yu Cheng | 0600e8d | 2016-04-26 07:38:24 +0000 | [diff] [blame] | 60 | static cl::opt<bool> DisableSCO("disable-ppc-sco", | 
| Chuang-Yu Cheng | 2e5973e | 2016-04-06 02:04:38 +0000 | [diff] [blame] | 61 | cl::desc("disable sibling call optimization on ppc"), cl::Hidden); | 
|  | 62 |  | 
|  | 63 | STATISTIC(NumTailCalls, "Number of tail calls"); | 
|  | 64 | STATISTIC(NumSiblingCalls, "Number of sibling calls"); | 
|  | 65 |  | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 66 | // FIXME: Remove this once the bug has been fixed! | 
|  | 67 | extern cl::opt<bool> ANDIGlueBug; | 
|  | 68 |  | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 69 | PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine &TM, | 
|  | 70 | const PPCSubtarget &STI) | 
|  | 71 | : TargetLowering(TM), Subtarget(STI) { | 
| Chris Lattner | a028e7a | 2005-09-27 22:18:25 +0000 | [diff] [blame] | 72 | // Use _setjmp/_longjmp instead of setjmp/longjmp. | 
| Anton Korobeynikov | 3b7c257 | 2006-12-10 23:12:42 +0000 | [diff] [blame] | 73 | setUseUnderscoreSetJmp(true); | 
|  | 74 | setUseUnderscoreLongJmp(true); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 75 |  | 
| Chris Lattner | d10babf | 2010-10-10 18:34:00 +0000 | [diff] [blame] | 76 | // On PPC32/64, arguments smaller than 4/8 bytes are extended, so all | 
|  | 77 | // arguments are at least 4/8 bytes aligned. | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 78 | bool isPPC64 = Subtarget.isPPC64(); | 
| Evan Cheng | 39e9002 | 2012-07-02 22:39:56 +0000 | [diff] [blame] | 79 | setMinStackArgumentAlignment(isPPC64 ? 8:4); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 80 |  | 
| Chris Lattner | f22556d | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 81 | // Set up the register classes. | 
| Craig Topper | abadc66 | 2012-04-20 06:31:50 +0000 | [diff] [blame] | 82 | addRegisterClass(MVT::i32, &PPC::GPRCRegClass); | 
| Eric Christopher | 317df66 | 2016-07-07 01:49:57 +0000 | [diff] [blame] | 83 | if (!useSoftFloat()) { | 
| Petar Jovanovic | 280f710 | 2015-12-14 17:57:33 +0000 | [diff] [blame] | 84 | addRegisterClass(MVT::f32, &PPC::F4RCRegClass); | 
|  | 85 | addRegisterClass(MVT::f64, &PPC::F8RCRegClass); | 
|  | 86 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 87 |  | 
| Evan Cheng | 5d9fd97 | 2006-10-04 00:56:09 +0000 | [diff] [blame] | 88 | // PowerPC has an i16 but no i8 (or i1) SEXTLOAD | 
| Ahmed Bougacha | 2b6917b | 2015-01-08 00:51:32 +0000 | [diff] [blame] | 89 | for (MVT VT : MVT::integer_valuetypes()) { | 
|  | 90 | setLoadExtAction(ISD::SEXTLOAD, VT, MVT::i1, Promote); | 
|  | 91 | setLoadExtAction(ISD::SEXTLOAD, VT, MVT::i8, Expand); | 
|  | 92 | } | 
| Duncan Sands | 95d46ef | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 93 |  | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 94 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 95 |  | 
| Chris Lattner | c9fa36d | 2006-11-10 23:58:45 +0000 | [diff] [blame] | 96 | // PowerPC has pre-inc load and store's. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 97 | setIndexedLoadAction(ISD::PRE_INC, MVT::i1, Legal); | 
|  | 98 | setIndexedLoadAction(ISD::PRE_INC, MVT::i8, Legal); | 
|  | 99 | setIndexedLoadAction(ISD::PRE_INC, MVT::i16, Legal); | 
|  | 100 | setIndexedLoadAction(ISD::PRE_INC, MVT::i32, Legal); | 
|  | 101 | setIndexedLoadAction(ISD::PRE_INC, MVT::i64, Legal); | 
| Hal Finkel | 65d1cbf | 2015-02-05 18:42:53 +0000 | [diff] [blame] | 102 | setIndexedLoadAction(ISD::PRE_INC, MVT::f32, Legal); | 
|  | 103 | setIndexedLoadAction(ISD::PRE_INC, MVT::f64, Legal); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 104 | setIndexedStoreAction(ISD::PRE_INC, MVT::i1, Legal); | 
|  | 105 | setIndexedStoreAction(ISD::PRE_INC, MVT::i8, Legal); | 
|  | 106 | setIndexedStoreAction(ISD::PRE_INC, MVT::i16, Legal); | 
|  | 107 | setIndexedStoreAction(ISD::PRE_INC, MVT::i32, Legal); | 
|  | 108 | setIndexedStoreAction(ISD::PRE_INC, MVT::i64, Legal); | 
| Hal Finkel | 65d1cbf | 2015-02-05 18:42:53 +0000 | [diff] [blame] | 109 | setIndexedStoreAction(ISD::PRE_INC, MVT::f32, Legal); | 
|  | 110 | setIndexedStoreAction(ISD::PRE_INC, MVT::f64, Legal); | 
| Evan Cheng | 36a8fbf | 2006-11-09 19:11:50 +0000 | [diff] [blame] | 111 |  | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 112 | if (Subtarget.useCRBits()) { | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 113 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); | 
|  | 114 |  | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 115 | if (isPPC64 || Subtarget.hasFPCVT()) { | 
| Hal Finkel | 6a56b21 | 2014-03-05 22:14:00 +0000 | [diff] [blame] | 116 | setOperationAction(ISD::SINT_TO_FP, MVT::i1, Promote); | 
|  | 117 | AddPromotedToType (ISD::SINT_TO_FP, MVT::i1, | 
|  | 118 | isPPC64 ? MVT::i64 : MVT::i32); | 
|  | 119 | setOperationAction(ISD::UINT_TO_FP, MVT::i1, Promote); | 
| NAKAMURA Takumi | 70ad98a | 2015-09-22 11:13:55 +0000 | [diff] [blame] | 120 | AddPromotedToType(ISD::UINT_TO_FP, MVT::i1, | 
|  | 121 | isPPC64 ? MVT::i64 : MVT::i32); | 
| Hal Finkel | 6a56b21 | 2014-03-05 22:14:00 +0000 | [diff] [blame] | 122 | } else { | 
|  | 123 | setOperationAction(ISD::SINT_TO_FP, MVT::i1, Custom); | 
|  | 124 | setOperationAction(ISD::UINT_TO_FP, MVT::i1, Custom); | 
|  | 125 | } | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 126 |  | 
|  | 127 | // PowerPC does not support direct load / store of condition registers | 
|  | 128 | setOperationAction(ISD::LOAD, MVT::i1, Custom); | 
|  | 129 | setOperationAction(ISD::STORE, MVT::i1, Custom); | 
|  | 130 |  | 
|  | 131 | // FIXME: Remove this once the ANDI glue bug is fixed: | 
|  | 132 | if (ANDIGlueBug) | 
|  | 133 | setOperationAction(ISD::TRUNCATE, MVT::i1, Custom); | 
|  | 134 |  | 
| Ahmed Bougacha | 2b6917b | 2015-01-08 00:51:32 +0000 | [diff] [blame] | 135 | for (MVT VT : MVT::integer_valuetypes()) { | 
|  | 136 | setLoadExtAction(ISD::SEXTLOAD, VT, MVT::i1, Promote); | 
|  | 137 | setLoadExtAction(ISD::ZEXTLOAD, VT, MVT::i1, Promote); | 
|  | 138 | setTruncStoreAction(VT, MVT::i1, Expand); | 
|  | 139 | } | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 140 |  | 
|  | 141 | addRegisterClass(MVT::i1, &PPC::CRBITRCRegClass); | 
|  | 142 | } | 
|  | 143 |  | 
| Dale Johannesen | 666323e | 2007-10-10 01:01:31 +0000 | [diff] [blame] | 144 | // This is used in the ppcf128->int sequence.  Note it has different semantics | 
|  | 145 | // from FP_ROUND:  that rounds to nearest, this rounds to zero. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 146 | setOperationAction(ISD::FP_ROUND_INREG, MVT::ppcf128, Custom); | 
| Dale Johannesen | f864ac9 | 2007-10-06 01:24:11 +0000 | [diff] [blame] | 147 |  | 
| Roman Divacky | 1faf5b0 | 2012-08-16 18:19:29 +0000 | [diff] [blame] | 148 | // We do not currently implement these libm ops for PowerPC. | 
| Owen Anderson | 0b9b9da | 2011-12-08 19:32:14 +0000 | [diff] [blame] | 149 | setOperationAction(ISD::FFLOOR, MVT::ppcf128, Expand); | 
|  | 150 | setOperationAction(ISD::FCEIL,  MVT::ppcf128, Expand); | 
|  | 151 | setOperationAction(ISD::FTRUNC, MVT::ppcf128, Expand); | 
|  | 152 | setOperationAction(ISD::FRINT,  MVT::ppcf128, Expand); | 
|  | 153 | setOperationAction(ISD::FNEARBYINT, MVT::ppcf128, Expand); | 
| Bill Schmidt | 92e2664 | 2013-04-03 13:05:44 +0000 | [diff] [blame] | 154 | setOperationAction(ISD::FREM, MVT::ppcf128, Expand); | 
| Owen Anderson | 0b9b9da | 2011-12-08 19:32:14 +0000 | [diff] [blame] | 155 |  | 
| Chris Lattner | f22556d | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 156 | // PowerPC has no SREM/UREM instructions | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 157 | setOperationAction(ISD::SREM, MVT::i32, Expand); | 
|  | 158 | setOperationAction(ISD::UREM, MVT::i32, Expand); | 
|  | 159 | setOperationAction(ISD::SREM, MVT::i64, Expand); | 
|  | 160 | setOperationAction(ISD::UREM, MVT::i64, Expand); | 
| Dan Gohman | 71f0d7d | 2007-10-08 17:28:24 +0000 | [diff] [blame] | 161 |  | 
|  | 162 | // Don't use SMUL_LOHI/UMUL_LOHI or SDIVREM/UDIVREM to lower SREM/UREM. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 163 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand); | 
|  | 164 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand); | 
|  | 165 | setOperationAction(ISD::UMUL_LOHI, MVT::i64, Expand); | 
|  | 166 | setOperationAction(ISD::SMUL_LOHI, MVT::i64, Expand); | 
|  | 167 | setOperationAction(ISD::UDIVREM, MVT::i32, Expand); | 
|  | 168 | setOperationAction(ISD::SDIVREM, MVT::i32, Expand); | 
|  | 169 | setOperationAction(ISD::UDIVREM, MVT::i64, Expand); | 
|  | 170 | setOperationAction(ISD::SDIVREM, MVT::i64, Expand); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 171 |  | 
| Dan Gohman | 482732a | 2007-10-11 23:21:31 +0000 | [diff] [blame] | 172 | // We don't support sin/cos/sqrt/fmod/pow | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 173 | setOperationAction(ISD::FSIN , MVT::f64, Expand); | 
|  | 174 | setOperationAction(ISD::FCOS , MVT::f64, Expand); | 
| Evan Cheng | 0e88c7d | 2013-01-29 02:32:37 +0000 | [diff] [blame] | 175 | setOperationAction(ISD::FSINCOS, MVT::f64, Expand); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 176 | setOperationAction(ISD::FREM , MVT::f64, Expand); | 
|  | 177 | setOperationAction(ISD::FPOW , MVT::f64, Expand); | 
| Hal Finkel | 0a479ae | 2012-06-22 00:49:52 +0000 | [diff] [blame] | 178 | setOperationAction(ISD::FMA  , MVT::f64, Legal); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 179 | setOperationAction(ISD::FSIN , MVT::f32, Expand); | 
|  | 180 | setOperationAction(ISD::FCOS , MVT::f32, Expand); | 
| Evan Cheng | 0e88c7d | 2013-01-29 02:32:37 +0000 | [diff] [blame] | 181 | setOperationAction(ISD::FSINCOS, MVT::f32, Expand); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 182 | setOperationAction(ISD::FREM , MVT::f32, Expand); | 
|  | 183 | setOperationAction(ISD::FPOW , MVT::f32, Expand); | 
| Hal Finkel | 0a479ae | 2012-06-22 00:49:52 +0000 | [diff] [blame] | 184 | setOperationAction(ISD::FMA  , MVT::f32, Legal); | 
| Dale Johannesen | 5c94cb3 | 2008-01-18 19:55:37 +0000 | [diff] [blame] | 185 |  | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 186 | setOperationAction(ISD::FLT_ROUNDS_, MVT::i32, Custom); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 187 |  | 
| Chris Lattner | f22556d | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 188 | // If we're enabling GP optimizations, use hardware square root | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 189 | if (!Subtarget.hasFSQRT() && | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 190 | !(TM.Options.UnsafeFPMath && Subtarget.hasFRSQRTE() && | 
|  | 191 | Subtarget.hasFRE())) | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 192 | setOperationAction(ISD::FSQRT, MVT::f64, Expand); | 
| Hal Finkel | 2e10331 | 2013-04-03 04:01:11 +0000 | [diff] [blame] | 193 |  | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 194 | if (!Subtarget.hasFSQRT() && | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 195 | !(TM.Options.UnsafeFPMath && Subtarget.hasFRSQRTES() && | 
|  | 196 | Subtarget.hasFRES())) | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 197 | setOperationAction(ISD::FSQRT, MVT::f32, Expand); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 198 |  | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 199 | if (Subtarget.hasFCPSGN()) { | 
| Hal Finkel | dbc78e1 | 2013-08-19 05:01:02 +0000 | [diff] [blame] | 200 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Legal); | 
|  | 201 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Legal); | 
|  | 202 | } else { | 
|  | 203 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Expand); | 
|  | 204 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Expand); | 
|  | 205 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 206 |  | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 207 | if (Subtarget.hasFPRND()) { | 
| Hal Finkel | c20a08d | 2013-03-29 08:57:48 +0000 | [diff] [blame] | 208 | setOperationAction(ISD::FFLOOR, MVT::f64, Legal); | 
|  | 209 | setOperationAction(ISD::FCEIL,  MVT::f64, Legal); | 
|  | 210 | setOperationAction(ISD::FTRUNC, MVT::f64, Legal); | 
| Hal Finkel | 2b7b2f3 | 2013-08-08 04:31:34 +0000 | [diff] [blame] | 211 | setOperationAction(ISD::FROUND, MVT::f64, Legal); | 
| Hal Finkel | c20a08d | 2013-03-29 08:57:48 +0000 | [diff] [blame] | 212 |  | 
|  | 213 | setOperationAction(ISD::FFLOOR, MVT::f32, Legal); | 
|  | 214 | setOperationAction(ISD::FCEIL,  MVT::f32, Legal); | 
|  | 215 | setOperationAction(ISD::FTRUNC, MVT::f32, Legal); | 
| Hal Finkel | 2b7b2f3 | 2013-08-08 04:31:34 +0000 | [diff] [blame] | 216 | setOperationAction(ISD::FROUND, MVT::f32, Legal); | 
| Hal Finkel | c20a08d | 2013-03-29 08:57:48 +0000 | [diff] [blame] | 217 | } | 
|  | 218 |  | 
| Nate Begeman | 2fba8a3 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 219 | // PowerPC does not have BSWAP, CTPOP or CTTZ | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 220 | setOperationAction(ISD::BSWAP, MVT::i32  , Expand); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 221 | setOperationAction(ISD::CTTZ , MVT::i32  , Expand); | 
|  | 222 | setOperationAction(ISD::BSWAP, MVT::i64  , Expand); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 223 | setOperationAction(ISD::CTTZ , MVT::i64  , Expand); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 224 |  | 
| Hal Finkel | fa7057a | 2016-03-29 01:36:01 +0000 | [diff] [blame] | 225 | if (Subtarget.hasPOPCNTD() == PPCSubtarget::POPCNTD_Fast) { | 
| Hal Finkel | 290376d | 2013-04-01 15:58:15 +0000 | [diff] [blame] | 226 | setOperationAction(ISD::CTPOP, MVT::i32  , Legal); | 
| Hal Finkel | a4d0748 | 2013-03-28 13:29:47 +0000 | [diff] [blame] | 227 | setOperationAction(ISD::CTPOP, MVT::i64  , Legal); | 
|  | 228 | } else { | 
|  | 229 | setOperationAction(ISD::CTPOP, MVT::i32  , Expand); | 
|  | 230 | setOperationAction(ISD::CTPOP, MVT::i64  , Expand); | 
|  | 231 | } | 
|  | 232 |  | 
| Nate Begeman | 1b8121b | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 233 | // PowerPC does not have ROTR | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 234 | setOperationAction(ISD::ROTR, MVT::i32   , Expand); | 
|  | 235 | setOperationAction(ISD::ROTR, MVT::i64   , Expand); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 236 |  | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 237 | if (!Subtarget.useCRBits()) { | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 238 | // PowerPC does not have Select | 
|  | 239 | setOperationAction(ISD::SELECT, MVT::i32, Expand); | 
|  | 240 | setOperationAction(ISD::SELECT, MVT::i64, Expand); | 
|  | 241 | setOperationAction(ISD::SELECT, MVT::f32, Expand); | 
|  | 242 | setOperationAction(ISD::SELECT, MVT::f64, Expand); | 
|  | 243 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 244 |  | 
| Chris Lattner | 7f1fa8e | 2005-08-26 17:36:52 +0000 | [diff] [blame] | 245 | // PowerPC wants to turn select_cc of FP into fsel when possible. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 246 | setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); | 
|  | 247 | setOperationAction(ISD::SELECT_CC, MVT::f64, Custom); | 
| Nate Begeman | a162f20 | 2006-01-31 08:17:29 +0000 | [diff] [blame] | 248 |  | 
| Nate Begeman | 7e7f439 | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 249 | // PowerPC wants to optimize integer setcc a bit | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 250 | if (!Subtarget.useCRBits()) | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 251 | setOperationAction(ISD::SETCC, MVT::i32, Custom); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 252 |  | 
| Nate Begeman | bb01d4f | 2006-03-17 01:40:33 +0000 | [diff] [blame] | 253 | // PowerPC does not have BRCOND which requires SetCC | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 254 | if (!Subtarget.useCRBits()) | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 255 | setOperationAction(ISD::BRCOND, MVT::Other, Expand); | 
| Evan Cheng | 0d41d19 | 2006-10-30 08:02:39 +0000 | [diff] [blame] | 256 |  | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 257 | setOperationAction(ISD::BR_JT,  MVT::Other, Expand); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 258 |  | 
| Chris Lattner | da2e04c | 2005-08-31 21:09:52 +0000 | [diff] [blame] | 259 | // PowerPC turns FP_TO_SINT into FCTIWZ and some load/stores. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 260 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); | 
| Nate Begeman | 6095214 | 2005-09-06 22:03:27 +0000 | [diff] [blame] | 261 |  | 
| Jim Laskey | 6267b2c | 2005-08-17 00:40:22 +0000 | [diff] [blame] | 262 | // PowerPC does not have [U|S]INT_TO_FP | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 263 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Expand); | 
|  | 264 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Expand); | 
| Jim Laskey | 6267b2c | 2005-08-17 00:40:22 +0000 | [diff] [blame] | 265 |  | 
| Nemanja Ivanovic | 5ebc92d | 2016-03-24 13:40:33 +0000 | [diff] [blame] | 266 | if (Subtarget.hasDirectMove() && isPPC64) { | 
| Nemanja Ivanovic | 8922476 | 2015-12-15 14:50:34 +0000 | [diff] [blame] | 267 | setOperationAction(ISD::BITCAST, MVT::f32, Legal); | 
|  | 268 | setOperationAction(ISD::BITCAST, MVT::i32, Legal); | 
|  | 269 | setOperationAction(ISD::BITCAST, MVT::i64, Legal); | 
|  | 270 | setOperationAction(ISD::BITCAST, MVT::f64, Legal); | 
|  | 271 | } else { | 
|  | 272 | setOperationAction(ISD::BITCAST, MVT::f32, Expand); | 
|  | 273 | setOperationAction(ISD::BITCAST, MVT::i32, Expand); | 
|  | 274 | setOperationAction(ISD::BITCAST, MVT::i64, Expand); | 
|  | 275 | setOperationAction(ISD::BITCAST, MVT::f64, Expand); | 
|  | 276 | } | 
| Chris Lattner | c46fc24 | 2005-12-23 05:13:35 +0000 | [diff] [blame] | 277 |  | 
| Chris Lattner | 84b49d5 | 2006-04-28 21:56:10 +0000 | [diff] [blame] | 278 | // We cannot sextinreg(i1).  Expand to shifts. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 279 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); | 
| Jim Laskey | e0008e2 | 2007-02-22 14:56:36 +0000 | [diff] [blame] | 280 |  | 
| Hal Finkel | 1996f3d | 2013-03-27 19:10:42 +0000 | [diff] [blame] | 281 | // NOTE: EH_SJLJ_SETJMP/_LONGJMP supported here is NOT intended to support | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 282 | // SjLj exception handling but a light-weight setjmp/longjmp replacement to | 
|  | 283 | // support continuation, user-level threading, and etc.. As a result, no | 
|  | 284 | // other SjLj exception interfaces are implemented and please don't build | 
|  | 285 | // your own exception handling based on them. | 
|  | 286 | // LLVM/Clang supports zero-cost DWARF exception handling. | 
|  | 287 | setOperationAction(ISD::EH_SJLJ_SETJMP, MVT::i32, Custom); | 
|  | 288 | setOperationAction(ISD::EH_SJLJ_LONGJMP, MVT::Other, Custom); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 289 |  | 
|  | 290 | // We want to legalize GlobalAddress and ConstantPool nodes into the | 
| Nate Begeman | 4e56db6 | 2005-12-10 02:36:00 +0000 | [diff] [blame] | 291 | // appropriate instructions to materialize the address. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 292 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); | 
|  | 293 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); | 
| Bob Wilson | f84f710 | 2009-11-04 21:31:18 +0000 | [diff] [blame] | 294 | setOperationAction(ISD::BlockAddress,  MVT::i32, Custom); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 295 | setOperationAction(ISD::ConstantPool,  MVT::i32, Custom); | 
|  | 296 | setOperationAction(ISD::JumpTable,     MVT::i32, Custom); | 
|  | 297 | setOperationAction(ISD::GlobalAddress, MVT::i64, Custom); | 
|  | 298 | setOperationAction(ISD::GlobalTLSAddress, MVT::i64, Custom); | 
| Bob Wilson | f84f710 | 2009-11-04 21:31:18 +0000 | [diff] [blame] | 299 | setOperationAction(ISD::BlockAddress,  MVT::i64, Custom); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 300 | setOperationAction(ISD::ConstantPool,  MVT::i64, Custom); | 
|  | 301 | setOperationAction(ISD::JumpTable,     MVT::i64, Custom); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 302 |  | 
| Nate Begeman | f69d13b | 2008-08-11 17:36:31 +0000 | [diff] [blame] | 303 | // TRAP is legal. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 304 | setOperationAction(ISD::TRAP, MVT::Other, Legal); | 
| Bill Wendling | 95e1af2 | 2008-09-17 00:30:57 +0000 | [diff] [blame] | 305 |  | 
|  | 306 | // TRAMPOLINE is custom lowered. | 
| Duncan Sands | a098436 | 2011-09-06 13:37:06 +0000 | [diff] [blame] | 307 | setOperationAction(ISD::INIT_TRAMPOLINE, MVT::Other, Custom); | 
|  | 308 | setOperationAction(ISD::ADJUST_TRAMPOLINE, MVT::Other, Custom); | 
| Bill Wendling | 95e1af2 | 2008-09-17 00:30:57 +0000 | [diff] [blame] | 309 |  | 
| Nate Begeman | e74795c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 310 | // VASTART needs to be custom lowered to use the VarArgsFrameIndex | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 311 | setOperationAction(ISD::VASTART           , MVT::Other, Custom); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 312 |  | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 313 | if (Subtarget.isSVR4ABI()) { | 
| Evan Cheng | 39e9002 | 2012-07-02 22:39:56 +0000 | [diff] [blame] | 314 | if (isPPC64) { | 
| Hal Finkel | e44eb28 | 2012-03-24 03:53:55 +0000 | [diff] [blame] | 315 | // VAARG always uses double-word chunks, so promote anything smaller. | 
|  | 316 | setOperationAction(ISD::VAARG, MVT::i1, Promote); | 
|  | 317 | AddPromotedToType (ISD::VAARG, MVT::i1, MVT::i64); | 
|  | 318 | setOperationAction(ISD::VAARG, MVT::i8, Promote); | 
|  | 319 | AddPromotedToType (ISD::VAARG, MVT::i8, MVT::i64); | 
|  | 320 | setOperationAction(ISD::VAARG, MVT::i16, Promote); | 
|  | 321 | AddPromotedToType (ISD::VAARG, MVT::i16, MVT::i64); | 
|  | 322 | setOperationAction(ISD::VAARG, MVT::i32, Promote); | 
|  | 323 | AddPromotedToType (ISD::VAARG, MVT::i32, MVT::i64); | 
|  | 324 | setOperationAction(ISD::VAARG, MVT::Other, Expand); | 
|  | 325 | } else { | 
|  | 326 | // VAARG is custom lowered with the 32-bit SVR4 ABI. | 
|  | 327 | setOperationAction(ISD::VAARG, MVT::Other, Custom); | 
|  | 328 | setOperationAction(ISD::VAARG, MVT::i64, Custom); | 
|  | 329 | } | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 330 | } else | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 331 | setOperationAction(ISD::VAARG, MVT::Other, Expand); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 332 |  | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 333 | if (Subtarget.isSVR4ABI() && !isPPC64) | 
| Roman Divacky | c3825df | 2013-07-25 21:36:47 +0000 | [diff] [blame] | 334 | // VACOPY is custom lowered with the 32-bit SVR4 ABI. | 
|  | 335 | setOperationAction(ISD::VACOPY            , MVT::Other, Custom); | 
|  | 336 | else | 
|  | 337 | setOperationAction(ISD::VACOPY            , MVT::Other, Expand); | 
|  | 338 |  | 
| Chris Lattner | 5bd514d | 2006-01-15 09:02:48 +0000 | [diff] [blame] | 339 | // Use the default implementation. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 340 | setOperationAction(ISD::VAEND             , MVT::Other, Expand); | 
|  | 341 | setOperationAction(ISD::STACKSAVE         , MVT::Other, Expand); | 
|  | 342 | setOperationAction(ISD::STACKRESTORE      , MVT::Other, Custom); | 
|  | 343 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32  , Custom); | 
|  | 344 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i64  , Custom); | 
| Yury Gribov | d7dbb66 | 2015-12-01 11:40:55 +0000 | [diff] [blame] | 345 | setOperationAction(ISD::GET_DYNAMIC_AREA_OFFSET, MVT::i32, Custom); | 
|  | 346 | setOperationAction(ISD::GET_DYNAMIC_AREA_OFFSET, MVT::i64, Custom); | 
| Chris Lattner | ab4df834 | 2006-10-18 01:18:48 +0000 | [diff] [blame] | 347 |  | 
| Chris Lattner | 6961fc7 | 2006-03-26 10:06:40 +0000 | [diff] [blame] | 348 | // We want to custom lower some of our intrinsics. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 349 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 350 |  | 
| Hal Finkel | 25c1992 | 2013-05-15 21:37:41 +0000 | [diff] [blame] | 351 | // To handle counter-based loop conditions. | 
|  | 352 | setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::i1, Custom); | 
|  | 353 |  | 
| Dale Johannesen | 160be0f | 2008-11-07 22:54:33 +0000 | [diff] [blame] | 354 | // Comparisons that require checking two conditions. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 355 | setCondCodeAction(ISD::SETULT, MVT::f32, Expand); | 
|  | 356 | setCondCodeAction(ISD::SETULT, MVT::f64, Expand); | 
|  | 357 | setCondCodeAction(ISD::SETUGT, MVT::f32, Expand); | 
|  | 358 | setCondCodeAction(ISD::SETUGT, MVT::f64, Expand); | 
|  | 359 | setCondCodeAction(ISD::SETUEQ, MVT::f32, Expand); | 
|  | 360 | setCondCodeAction(ISD::SETUEQ, MVT::f64, Expand); | 
|  | 361 | setCondCodeAction(ISD::SETOGE, MVT::f32, Expand); | 
|  | 362 | setCondCodeAction(ISD::SETOGE, MVT::f64, Expand); | 
|  | 363 | setCondCodeAction(ISD::SETOLE, MVT::f32, Expand); | 
|  | 364 | setCondCodeAction(ISD::SETOLE, MVT::f64, Expand); | 
|  | 365 | setCondCodeAction(ISD::SETONE, MVT::f32, Expand); | 
|  | 366 | setCondCodeAction(ISD::SETONE, MVT::f64, Expand); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 367 |  | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 368 | if (Subtarget.has64BitSupport()) { | 
| Nate Begeman | 0b71e00 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 369 | // They also have instructions for converting between i64 and fp. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 370 | setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom); | 
|  | 371 | setOperationAction(ISD::FP_TO_UINT, MVT::i64, Expand); | 
|  | 372 | setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom); | 
|  | 373 | setOperationAction(ISD::UINT_TO_FP, MVT::i64, Expand); | 
| Dale Johannesen | 37bc85f | 2009-06-04 20:53:52 +0000 | [diff] [blame] | 374 | // This is just the low 32 bits of a (signed) fp->i64 conversion. | 
|  | 375 | // We cannot do this with Promote because i64 is not a legal type. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 376 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 377 |  | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 378 | if (Subtarget.hasLFIWAX() || Subtarget.isPPC64()) | 
| Hal Finkel | e53429a | 2013-03-31 01:58:02 +0000 | [diff] [blame] | 379 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); | 
| Nate Begeman | 762bf80 | 2005-10-25 23:48:36 +0000 | [diff] [blame] | 380 | } else { | 
| Chris Lattner | 595088a | 2005-11-17 07:30:41 +0000 | [diff] [blame] | 381 | // PowerPC does not have FP_TO_UINT on 32-bit implementations. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 382 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Expand); | 
| Nate Begeman | e74dfbb | 2005-10-18 00:56:42 +0000 | [diff] [blame] | 383 | } | 
|  | 384 |  | 
| Hal Finkel | f6d45f2 | 2013-04-01 17:52:07 +0000 | [diff] [blame] | 385 | // With the instructions enabled under FPCVT, we can do everything. | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 386 | if (Subtarget.hasFPCVT()) { | 
|  | 387 | if (Subtarget.has64BitSupport()) { | 
| Hal Finkel | f6d45f2 | 2013-04-01 17:52:07 +0000 | [diff] [blame] | 388 | setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom); | 
|  | 389 | setOperationAction(ISD::FP_TO_UINT, MVT::i64, Custom); | 
|  | 390 | setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom); | 
|  | 391 | setOperationAction(ISD::UINT_TO_FP, MVT::i64, Custom); | 
|  | 392 | } | 
|  | 393 |  | 
|  | 394 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); | 
|  | 395 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom); | 
|  | 396 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); | 
|  | 397 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom); | 
|  | 398 | } | 
|  | 399 |  | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 400 | if (Subtarget.use64BitRegs()) { | 
| Chris Lattner | b193576 | 2007-10-19 04:08:28 +0000 | [diff] [blame] | 401 | // 64-bit PowerPC implementations can support i64 types directly | 
| Craig Topper | abadc66 | 2012-04-20 06:31:50 +0000 | [diff] [blame] | 402 | addRegisterClass(MVT::i64, &PPC::G8RCRegClass); | 
| Nate Begeman | 0b71e00 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 403 | // BUILD_PAIR can't be handled natively, and should be expanded to shl/or | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 404 | setOperationAction(ISD::BUILD_PAIR, MVT::i64, Expand); | 
| Dan Gohman | 8d2ead2 | 2008-03-07 20:36:53 +0000 | [diff] [blame] | 405 | // 64-bit PowerPC wants to expand i128 shifts itself. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 406 | setOperationAction(ISD::SHL_PARTS, MVT::i64, Custom); | 
|  | 407 | setOperationAction(ISD::SRA_PARTS, MVT::i64, Custom); | 
|  | 408 | setOperationAction(ISD::SRL_PARTS, MVT::i64, Custom); | 
| Nate Begeman | 0b71e00 | 2005-10-18 00:28:58 +0000 | [diff] [blame] | 409 | } else { | 
| Chris Lattner | b193576 | 2007-10-19 04:08:28 +0000 | [diff] [blame] | 410 | // 32-bit PowerPC wants to expand i64 shifts itself. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 411 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Custom); | 
|  | 412 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom); | 
|  | 413 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom); | 
| Nate Begeman | 6095214 | 2005-09-06 22:03:27 +0000 | [diff] [blame] | 414 | } | 
| Evan Cheng | 1926427 | 2006-03-01 01:11:20 +0000 | [diff] [blame] | 415 |  | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 416 | if (Subtarget.hasAltivec()) { | 
| Chris Lattner | baa73e0 | 2006-03-31 19:52:36 +0000 | [diff] [blame] | 417 | // First set operation action for all vector types to expand. Then we | 
|  | 418 | // will selectively turn on ones that can be effectively codegen'd. | 
| Ahmed Bougacha | 67dd2d2 | 2015-01-07 21:27:10 +0000 | [diff] [blame] | 419 | for (MVT VT : MVT::vector_valuetypes()) { | 
| Chris Lattner | 06a21ba | 2006-04-16 01:37:57 +0000 | [diff] [blame] | 420 | // add/sub are legal for all supported vector VT's. | 
| NAKAMURA Takumi | 70ad98a | 2015-09-22 11:13:55 +0000 | [diff] [blame] | 421 | setOperationAction(ISD::ADD, VT, Legal); | 
|  | 422 | setOperationAction(ISD::SUB, VT, Legal); | 
|  | 423 |  | 
| Bill Schmidt | 433b1c3 | 2015-02-05 15:24:47 +0000 | [diff] [blame] | 424 | // Vector instructions introduced in P8 | 
| Kit Barton | d4eb73c | 2015-05-05 16:10:44 +0000 | [diff] [blame] | 425 | if (Subtarget.hasP8Altivec() && (VT.SimpleTy != MVT::v1i128)) { | 
| Bill Schmidt | fe88b18 | 2015-02-03 21:58:23 +0000 | [diff] [blame] | 426 | setOperationAction(ISD::CTPOP, VT, Legal); | 
| Bill Schmidt | 433b1c3 | 2015-02-05 15:24:47 +0000 | [diff] [blame] | 427 | setOperationAction(ISD::CTLZ, VT, Legal); | 
|  | 428 | } | 
|  | 429 | else { | 
| Bill Schmidt | fe88b18 | 2015-02-03 21:58:23 +0000 | [diff] [blame] | 430 | setOperationAction(ISD::CTPOP, VT, Expand); | 
| Bill Schmidt | 433b1c3 | 2015-02-05 15:24:47 +0000 | [diff] [blame] | 431 | setOperationAction(ISD::CTLZ, VT, Expand); | 
|  | 432 | } | 
| Bill Schmidt | fe88b18 | 2015-02-03 21:58:23 +0000 | [diff] [blame] | 433 |  | 
| Chris Lattner | 95c7adc | 2006-04-04 17:25:31 +0000 | [diff] [blame] | 434 | // We promote all shuffles to v16i8. | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 435 | setOperationAction(ISD::VECTOR_SHUFFLE, VT, Promote); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 436 | AddPromotedToType (ISD::VECTOR_SHUFFLE, VT, MVT::v16i8); | 
| Chris Lattner | 06a21ba | 2006-04-16 01:37:57 +0000 | [diff] [blame] | 437 |  | 
|  | 438 | // We promote all non-typed operations to v4i32. | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 439 | setOperationAction(ISD::AND   , VT, Promote); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 440 | AddPromotedToType (ISD::AND   , VT, MVT::v4i32); | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 441 | setOperationAction(ISD::OR    , VT, Promote); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 442 | AddPromotedToType (ISD::OR    , VT, MVT::v4i32); | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 443 | setOperationAction(ISD::XOR   , VT, Promote); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 444 | AddPromotedToType (ISD::XOR   , VT, MVT::v4i32); | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 445 | setOperationAction(ISD::LOAD  , VT, Promote); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 446 | AddPromotedToType (ISD::LOAD  , VT, MVT::v4i32); | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 447 | setOperationAction(ISD::SELECT, VT, Promote); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 448 | AddPromotedToType (ISD::SELECT, VT, MVT::v4i32); | 
| Hal Finkel | a2cdbce | 2015-08-30 22:12:50 +0000 | [diff] [blame] | 449 | setOperationAction(ISD::SELECT_CC, VT, Promote); | 
|  | 450 | AddPromotedToType (ISD::SELECT_CC, VT, MVT::v4i32); | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 451 | setOperationAction(ISD::STORE, VT, Promote); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 452 | AddPromotedToType (ISD::STORE, VT, MVT::v4i32); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 453 |  | 
| Chris Lattner | 06a21ba | 2006-04-16 01:37:57 +0000 | [diff] [blame] | 454 | // No other operations are legal. | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 455 | setOperationAction(ISD::MUL , VT, Expand); | 
|  | 456 | setOperationAction(ISD::SDIV, VT, Expand); | 
|  | 457 | setOperationAction(ISD::SREM, VT, Expand); | 
|  | 458 | setOperationAction(ISD::UDIV, VT, Expand); | 
|  | 459 | setOperationAction(ISD::UREM, VT, Expand); | 
|  | 460 | setOperationAction(ISD::FDIV, VT, Expand); | 
| Hal Finkel | e393022 | 2013-07-08 17:30:25 +0000 | [diff] [blame] | 461 | setOperationAction(ISD::FREM, VT, Expand); | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 462 | setOperationAction(ISD::FNEG, VT, Expand); | 
| Craig Topper | c8a2adf | 2012-11-15 08:02:19 +0000 | [diff] [blame] | 463 | setOperationAction(ISD::FSQRT, VT, Expand); | 
|  | 464 | setOperationAction(ISD::FLOG, VT, Expand); | 
|  | 465 | setOperationAction(ISD::FLOG10, VT, Expand); | 
|  | 466 | setOperationAction(ISD::FLOG2, VT, Expand); | 
|  | 467 | setOperationAction(ISD::FEXP, VT, Expand); | 
|  | 468 | setOperationAction(ISD::FEXP2, VT, Expand); | 
|  | 469 | setOperationAction(ISD::FSIN, VT, Expand); | 
|  | 470 | setOperationAction(ISD::FCOS, VT, Expand); | 
|  | 471 | setOperationAction(ISD::FABS, VT, Expand); | 
|  | 472 | setOperationAction(ISD::FPOWI, VT, Expand); | 
| Craig Topper | c4343f2 | 2012-11-14 08:11:25 +0000 | [diff] [blame] | 473 | setOperationAction(ISD::FFLOOR, VT, Expand); | 
| Craig Topper | 61d0457 | 2012-11-15 06:51:10 +0000 | [diff] [blame] | 474 | setOperationAction(ISD::FCEIL,  VT, Expand); | 
|  | 475 | setOperationAction(ISD::FTRUNC, VT, Expand); | 
|  | 476 | setOperationAction(ISD::FRINT,  VT, Expand); | 
|  | 477 | setOperationAction(ISD::FNEARBYINT, VT, Expand); | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 478 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, VT, Expand); | 
|  | 479 | setOperationAction(ISD::INSERT_VECTOR_ELT, VT, Expand); | 
|  | 480 | setOperationAction(ISD::BUILD_VECTOR, VT, Expand); | 
| Ulrich Weigand | 51eccec | 2014-08-04 13:27:12 +0000 | [diff] [blame] | 481 | setOperationAction(ISD::MULHU, VT, Expand); | 
|  | 482 | setOperationAction(ISD::MULHS, VT, Expand); | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 483 | setOperationAction(ISD::UMUL_LOHI, VT, Expand); | 
|  | 484 | setOperationAction(ISD::SMUL_LOHI, VT, Expand); | 
|  | 485 | setOperationAction(ISD::UDIVREM, VT, Expand); | 
|  | 486 | setOperationAction(ISD::SDIVREM, VT, Expand); | 
|  | 487 | setOperationAction(ISD::SCALAR_TO_VECTOR, VT, Expand); | 
|  | 488 | setOperationAction(ISD::FPOW, VT, Expand); | 
| Benjamin Kramer | f3ad235 | 2014-05-19 13:12:38 +0000 | [diff] [blame] | 489 | setOperationAction(ISD::BSWAP, VT, Expand); | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 490 | setOperationAction(ISD::CTTZ, VT, Expand); | 
| Benjamin Kramer | c507146 | 2012-12-19 15:49:14 +0000 | [diff] [blame] | 491 | setOperationAction(ISD::VSELECT, VT, Expand); | 
| Adhemerval Zanella | c4182d1 | 2012-11-05 17:15:56 +0000 | [diff] [blame] | 492 | setOperationAction(ISD::SIGN_EXTEND_INREG, VT, Expand); | 
| Nemanja Ivanovic | 74e31bc | 2015-12-02 10:36:24 +0000 | [diff] [blame] | 493 | setOperationAction(ISD::ROTL, VT, Expand); | 
|  | 494 | setOperationAction(ISD::ROTR, VT, Expand); | 
| Adhemerval Zanella | c4182d1 | 2012-11-05 17:15:56 +0000 | [diff] [blame] | 495 |  | 
| Ahmed Bougacha | 2b6917b | 2015-01-08 00:51:32 +0000 | [diff] [blame] | 496 | for (MVT InnerVT : MVT::vector_valuetypes()) { | 
| Adhemerval Zanella | c4182d1 | 2012-11-05 17:15:56 +0000 | [diff] [blame] | 497 | setTruncStoreAction(VT, InnerVT, Expand); | 
| Ahmed Bougacha | 2b6917b | 2015-01-08 00:51:32 +0000 | [diff] [blame] | 498 | setLoadExtAction(ISD::SEXTLOAD, VT, InnerVT, Expand); | 
|  | 499 | setLoadExtAction(ISD::ZEXTLOAD, VT, InnerVT, Expand); | 
|  | 500 | setLoadExtAction(ISD::EXTLOAD, VT, InnerVT, Expand); | 
|  | 501 | } | 
| Chris Lattner | baa73e0 | 2006-03-31 19:52:36 +0000 | [diff] [blame] | 502 | } | 
|  | 503 |  | 
| Chris Lattner | 95c7adc | 2006-04-04 17:25:31 +0000 | [diff] [blame] | 504 | // We can custom expand all VECTOR_SHUFFLEs to VPERM, others we can handle | 
|  | 505 | // with merges, splats, etc. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 506 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v16i8, Custom); | 
| Chris Lattner | 95c7adc | 2006-04-04 17:25:31 +0000 | [diff] [blame] | 507 |  | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 508 | setOperationAction(ISD::AND   , MVT::v4i32, Legal); | 
|  | 509 | setOperationAction(ISD::OR    , MVT::v4i32, Legal); | 
|  | 510 | setOperationAction(ISD::XOR   , MVT::v4i32, Legal); | 
|  | 511 | setOperationAction(ISD::LOAD  , MVT::v4i32, Legal); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 512 | setOperationAction(ISD::SELECT, MVT::v4i32, | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 513 | Subtarget.useCRBits() ? Legal : Expand); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 514 | setOperationAction(ISD::STORE , MVT::v4i32, Legal); | 
| Adhemerval Zanella | 5c6e084 | 2012-10-08 17:27:24 +0000 | [diff] [blame] | 515 | setOperationAction(ISD::FP_TO_SINT, MVT::v4i32, Legal); | 
|  | 516 | setOperationAction(ISD::FP_TO_UINT, MVT::v4i32, Legal); | 
|  | 517 | setOperationAction(ISD::SINT_TO_FP, MVT::v4i32, Legal); | 
|  | 518 | setOperationAction(ISD::UINT_TO_FP, MVT::v4i32, Legal); | 
| Adhemerval Zanella | bdface5 | 2012-11-15 20:56:03 +0000 | [diff] [blame] | 519 | setOperationAction(ISD::FFLOOR, MVT::v4f32, Legal); | 
|  | 520 | setOperationAction(ISD::FCEIL, MVT::v4f32, Legal); | 
|  | 521 | setOperationAction(ISD::FTRUNC, MVT::v4f32, Legal); | 
|  | 522 | setOperationAction(ISD::FNEARBYINT, MVT::v4f32, Legal); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 523 |  | 
| Craig Topper | abadc66 | 2012-04-20 06:31:50 +0000 | [diff] [blame] | 524 | addRegisterClass(MVT::v4f32, &PPC::VRRCRegClass); | 
|  | 525 | addRegisterClass(MVT::v4i32, &PPC::VRRCRegClass); | 
|  | 526 | addRegisterClass(MVT::v8i16, &PPC::VRRCRegClass); | 
|  | 527 | addRegisterClass(MVT::v16i8, &PPC::VRRCRegClass); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 528 |  | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 529 | setOperationAction(ISD::MUL, MVT::v4f32, Legal); | 
| Hal Finkel | 0a479ae | 2012-06-22 00:49:52 +0000 | [diff] [blame] | 530 | setOperationAction(ISD::FMA, MVT::v4f32, Legal); | 
| Hal Finkel | 2e10331 | 2013-04-03 04:01:11 +0000 | [diff] [blame] | 531 |  | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 532 | if (TM.Options.UnsafeFPMath || Subtarget.hasVSX()) { | 
| Hal Finkel | 2e10331 | 2013-04-03 04:01:11 +0000 | [diff] [blame] | 533 | setOperationAction(ISD::FDIV, MVT::v4f32, Legal); | 
|  | 534 | setOperationAction(ISD::FSQRT, MVT::v4f32, Legal); | 
|  | 535 | } | 
|  | 536 |  | 
| NAKAMURA Takumi | 70ad98a | 2015-09-22 11:13:55 +0000 | [diff] [blame] | 537 | if (Subtarget.hasP8Altivec()) | 
| Kit Barton | 20d3981 | 2015-03-10 19:49:38 +0000 | [diff] [blame] | 538 | setOperationAction(ISD::MUL, MVT::v4i32, Legal); | 
|  | 539 | else | 
|  | 540 | setOperationAction(ISD::MUL, MVT::v4i32, Custom); | 
| NAKAMURA Takumi | a9cb538 | 2015-09-22 11:14:39 +0000 | [diff] [blame] | 541 |  | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 542 | setOperationAction(ISD::MUL, MVT::v8i16, Custom); | 
|  | 543 | setOperationAction(ISD::MUL, MVT::v16i8, Custom); | 
| Chris Lattner | a8713b1 | 2006-03-20 01:53:53 +0000 | [diff] [blame] | 544 |  | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 545 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v4f32, Custom); | 
|  | 546 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v4i32, Custom); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 547 |  | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 548 | setOperationAction(ISD::BUILD_VECTOR, MVT::v16i8, Custom); | 
|  | 549 | setOperationAction(ISD::BUILD_VECTOR, MVT::v8i16, Custom); | 
|  | 550 | setOperationAction(ISD::BUILD_VECTOR, MVT::v4i32, Custom); | 
|  | 551 | setOperationAction(ISD::BUILD_VECTOR, MVT::v4f32, Custom); | 
| Adhemerval Zanella | 56775e0 | 2012-10-30 13:50:19 +0000 | [diff] [blame] | 552 |  | 
|  | 553 | // Altivec does not contain unordered floating-point compare instructions | 
|  | 554 | setCondCodeAction(ISD::SETUO, MVT::v4f32, Expand); | 
|  | 555 | setCondCodeAction(ISD::SETUEQ, MVT::v4f32, Expand); | 
| Hal Finkel | 21ada79 | 2013-07-08 20:00:03 +0000 | [diff] [blame] | 556 | setCondCodeAction(ISD::SETO,   MVT::v4f32, Expand); | 
|  | 557 | setCondCodeAction(ISD::SETONE, MVT::v4f32, Expand); | 
| Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 558 |  | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 559 | if (Subtarget.hasVSX()) { | 
| Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 560 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v2f64, Legal); | 
| Nemanja Ivanovic | d389657 | 2015-10-09 11:12:18 +0000 | [diff] [blame] | 561 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v2f64, Legal); | 
|  | 562 | if (Subtarget.hasP8Vector()) { | 
| Nemanja Ivanovic | 1c39ca6 | 2015-08-13 17:40:44 +0000 | [diff] [blame] | 563 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v4f32, Legal); | 
| Nemanja Ivanovic | d389657 | 2015-10-09 11:12:18 +0000 | [diff] [blame] | 564 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v4f32, Legal); | 
|  | 565 | } | 
| Nemanja Ivanovic | 5ebc92d | 2016-03-24 13:40:33 +0000 | [diff] [blame] | 566 | if (Subtarget.hasDirectMove() && isPPC64) { | 
| Nemanja Ivanovic | 1c39ca6 | 2015-08-13 17:40:44 +0000 | [diff] [blame] | 567 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v16i8, Legal); | 
|  | 568 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v8i16, Legal); | 
|  | 569 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v4i32, Legal); | 
| Nemanja Ivanovic | be5f0c0 | 2015-11-02 14:01:11 +0000 | [diff] [blame] | 570 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v2i64, Legal); | 
| Nemanja Ivanovic | d389657 | 2015-10-09 11:12:18 +0000 | [diff] [blame] | 571 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v16i8, Legal); | 
|  | 572 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v8i16, Legal); | 
|  | 573 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v4i32, Legal); | 
|  | 574 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v2i64, Legal); | 
| Nemanja Ivanovic | 1c39ca6 | 2015-08-13 17:40:44 +0000 | [diff] [blame] | 575 | } | 
| Hal Finkel | 82569b6 | 2014-03-27 22:22:48 +0000 | [diff] [blame] | 576 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v2f64, Legal); | 
| Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 577 |  | 
|  | 578 | setOperationAction(ISD::FFLOOR, MVT::v2f64, Legal); | 
|  | 579 | setOperationAction(ISD::FCEIL, MVT::v2f64, Legal); | 
|  | 580 | setOperationAction(ISD::FTRUNC, MVT::v2f64, Legal); | 
|  | 581 | setOperationAction(ISD::FNEARBYINT, MVT::v2f64, Legal); | 
|  | 582 | setOperationAction(ISD::FROUND, MVT::v2f64, Legal); | 
|  | 583 |  | 
|  | 584 | setOperationAction(ISD::FROUND, MVT::v4f32, Legal); | 
|  | 585 |  | 
|  | 586 | setOperationAction(ISD::MUL, MVT::v2f64, Legal); | 
|  | 587 | setOperationAction(ISD::FMA, MVT::v2f64, Legal); | 
|  | 588 |  | 
|  | 589 | setOperationAction(ISD::FDIV, MVT::v2f64, Legal); | 
|  | 590 | setOperationAction(ISD::FSQRT, MVT::v2f64, Legal); | 
|  | 591 |  | 
| Hal Finkel | 732f0f7 | 2014-03-26 12:49:28 +0000 | [diff] [blame] | 592 | setOperationAction(ISD::VSELECT, MVT::v16i8, Legal); | 
|  | 593 | setOperationAction(ISD::VSELECT, MVT::v8i16, Legal); | 
|  | 594 | setOperationAction(ISD::VSELECT, MVT::v4i32, Legal); | 
|  | 595 | setOperationAction(ISD::VSELECT, MVT::v4f32, Legal); | 
|  | 596 | setOperationAction(ISD::VSELECT, MVT::v2f64, Legal); | 
|  | 597 |  | 
| Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 598 | // Share the Altivec comparison restrictions. | 
|  | 599 | setCondCodeAction(ISD::SETUO, MVT::v2f64, Expand); | 
|  | 600 | setCondCodeAction(ISD::SETUEQ, MVT::v2f64, Expand); | 
| Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 601 | setCondCodeAction(ISD::SETO,   MVT::v2f64, Expand); | 
|  | 602 | setCondCodeAction(ISD::SETONE, MVT::v2f64, Expand); | 
|  | 603 |  | 
| Hal Finkel | 9281c9a | 2014-03-26 18:26:30 +0000 | [diff] [blame] | 604 | setOperationAction(ISD::LOAD, MVT::v2f64, Legal); | 
|  | 605 | setOperationAction(ISD::STORE, MVT::v2f64, Legal); | 
|  | 606 |  | 
| Hal Finkel | df3e34d | 2014-03-26 22:58:37 +0000 | [diff] [blame] | 607 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v2f64, Legal); | 
|  | 608 |  | 
| Nemanja Ivanovic | f3c94b1 | 2015-05-07 18:24:05 +0000 | [diff] [blame] | 609 | if (Subtarget.hasP8Vector()) | 
|  | 610 | addRegisterClass(MVT::f32, &PPC::VSSRCRegClass); | 
|  | 611 |  | 
| Hal Finkel | 19be506 | 2014-03-29 05:29:01 +0000 | [diff] [blame] | 612 | addRegisterClass(MVT::f64, &PPC::VSFRCRegClass); | 
| Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 613 |  | 
| Bill Schmidt | 54cced5 | 2015-07-16 21:14:07 +0000 | [diff] [blame] | 614 | addRegisterClass(MVT::v4i32, &PPC::VSRCRegClass); | 
| Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 615 | addRegisterClass(MVT::v4f32, &PPC::VSRCRegClass); | 
|  | 616 | addRegisterClass(MVT::v2f64, &PPC::VSRCRegClass); | 
| Hal Finkel | a6c8b51 | 2014-03-26 16:12:58 +0000 | [diff] [blame] | 617 |  | 
| Kit Barton | 0cfa7b7 | 2015-03-03 19:55:45 +0000 | [diff] [blame] | 618 | if (Subtarget.hasP8Altivec()) { | 
| Kit Barton | e48b1e1 | 2015-03-05 16:24:38 +0000 | [diff] [blame] | 619 | setOperationAction(ISD::SHL, MVT::v2i64, Legal); | 
|  | 620 | setOperationAction(ISD::SRA, MVT::v2i64, Legal); | 
|  | 621 | setOperationAction(ISD::SRL, MVT::v2i64, Legal); | 
|  | 622 |  | 
| Kit Barton | 0cfa7b7 | 2015-03-03 19:55:45 +0000 | [diff] [blame] | 623 | setOperationAction(ISD::SETCC, MVT::v2i64, Legal); | 
|  | 624 | } | 
|  | 625 | else { | 
| Kit Barton | e48b1e1 | 2015-03-05 16:24:38 +0000 | [diff] [blame] | 626 | setOperationAction(ISD::SHL, MVT::v2i64, Expand); | 
|  | 627 | setOperationAction(ISD::SRA, MVT::v2i64, Expand); | 
|  | 628 | setOperationAction(ISD::SRL, MVT::v2i64, Expand); | 
|  | 629 |  | 
| Kit Barton | 0cfa7b7 | 2015-03-03 19:55:45 +0000 | [diff] [blame] | 630 | setOperationAction(ISD::SETCC, MVT::v2i64, Custom); | 
|  | 631 |  | 
|  | 632 | // VSX v2i64 only supports non-arithmetic operations. | 
|  | 633 | setOperationAction(ISD::ADD, MVT::v2i64, Expand); | 
|  | 634 | setOperationAction(ISD::SUB, MVT::v2i64, Expand); | 
|  | 635 | } | 
| Hal Finkel | 777c9dd | 2014-03-29 16:04:40 +0000 | [diff] [blame] | 636 |  | 
| Hal Finkel | 9281c9a | 2014-03-26 18:26:30 +0000 | [diff] [blame] | 637 | setOperationAction(ISD::LOAD, MVT::v2i64, Promote); | 
|  | 638 | AddPromotedToType (ISD::LOAD, MVT::v2i64, MVT::v2f64); | 
|  | 639 | setOperationAction(ISD::STORE, MVT::v2i64, Promote); | 
|  | 640 | AddPromotedToType (ISD::STORE, MVT::v2i64, MVT::v2f64); | 
|  | 641 |  | 
| Hal Finkel | df3e34d | 2014-03-26 22:58:37 +0000 | [diff] [blame] | 642 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v2i64, Legal); | 
|  | 643 |  | 
| Hal Finkel | 7279f4b | 2014-03-26 19:13:54 +0000 | [diff] [blame] | 644 | setOperationAction(ISD::SINT_TO_FP, MVT::v2i64, Legal); | 
|  | 645 | setOperationAction(ISD::UINT_TO_FP, MVT::v2i64, Legal); | 
|  | 646 | setOperationAction(ISD::FP_TO_SINT, MVT::v2i64, Legal); | 
|  | 647 | setOperationAction(ISD::FP_TO_UINT, MVT::v2i64, Legal); | 
|  | 648 |  | 
| Hal Finkel | 5c0d145 | 2014-03-30 13:22:59 +0000 | [diff] [blame] | 649 | // Vector operation legalization checks the result type of | 
|  | 650 | // SIGN_EXTEND_INREG, overall legalization checks the inner type. | 
|  | 651 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::v2i64, Legal); | 
|  | 652 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::v2i32, Legal); | 
|  | 653 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::v2i16, Custom); | 
|  | 654 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::v2i8, Custom); | 
|  | 655 |  | 
| Kit Barton | 915c5ec | 2016-02-26 21:59:44 +0000 | [diff] [blame] | 656 | setOperationAction(ISD::FNEG, MVT::v4f32, Legal); | 
|  | 657 | setOperationAction(ISD::FNEG, MVT::v2f64, Legal); | 
| Kit Barton | a1d6a6f | 2016-03-09 17:48:01 +0000 | [diff] [blame] | 658 | setOperationAction(ISD::FABS, MVT::v4f32, Legal); | 
|  | 659 | setOperationAction(ISD::FABS, MVT::v2f64, Legal); | 
| Kit Barton | 915c5ec | 2016-02-26 21:59:44 +0000 | [diff] [blame] | 660 |  | 
| Hal Finkel | a6c8b51 | 2014-03-26 16:12:58 +0000 | [diff] [blame] | 661 | addRegisterClass(MVT::v2i64, &PPC::VSRCRegClass); | 
| Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 662 | } | 
| Bill Schmidt | fe88b18 | 2015-02-03 21:58:23 +0000 | [diff] [blame] | 663 |  | 
| Kit Barton | d4eb73c | 2015-05-05 16:10:44 +0000 | [diff] [blame] | 664 | if (Subtarget.hasP8Altivec()) { | 
| Bill Schmidt | fe88b18 | 2015-02-03 21:58:23 +0000 | [diff] [blame] | 665 | addRegisterClass(MVT::v2i64, &PPC::VRRCRegClass); | 
| Kit Barton | d4eb73c | 2015-05-05 16:10:44 +0000 | [diff] [blame] | 666 | addRegisterClass(MVT::v1i128, &PPC::VRRCRegClass); | 
|  | 667 | } | 
| Nemanja Ivanovic | b43bb61 | 2016-07-12 21:00:10 +0000 | [diff] [blame] | 668 | if (Subtarget.hasP9Vector()) { | 
|  | 669 | setOperationAction(ISD::INSERT_VECTOR_ELT, MVT::v4i32, Legal); | 
|  | 670 | setOperationAction(ISD::INSERT_VECTOR_ELT, MVT::v4f32, Legal); | 
|  | 671 | } | 
| Nate Begeman | 3e7db9c | 2005-11-29 08:17:20 +0000 | [diff] [blame] | 672 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 673 |  | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 674 | if (Subtarget.hasQPX()) { | 
|  | 675 | setOperationAction(ISD::FADD, MVT::v4f64, Legal); | 
|  | 676 | setOperationAction(ISD::FSUB, MVT::v4f64, Legal); | 
|  | 677 | setOperationAction(ISD::FMUL, MVT::v4f64, Legal); | 
|  | 678 | setOperationAction(ISD::FREM, MVT::v4f64, Expand); | 
|  | 679 |  | 
|  | 680 | setOperationAction(ISD::FCOPYSIGN, MVT::v4f64, Legal); | 
|  | 681 | setOperationAction(ISD::FGETSIGN, MVT::v4f64, Expand); | 
|  | 682 |  | 
|  | 683 | setOperationAction(ISD::LOAD  , MVT::v4f64, Custom); | 
|  | 684 | setOperationAction(ISD::STORE , MVT::v4f64, Custom); | 
|  | 685 |  | 
|  | 686 | setTruncStoreAction(MVT::v4f64, MVT::v4f32, Custom); | 
|  | 687 | setLoadExtAction(ISD::EXTLOAD, MVT::v4f64, MVT::v4f32, Custom); | 
|  | 688 |  | 
|  | 689 | if (!Subtarget.useCRBits()) | 
|  | 690 | setOperationAction(ISD::SELECT, MVT::v4f64, Expand); | 
|  | 691 | setOperationAction(ISD::VSELECT, MVT::v4f64, Legal); | 
|  | 692 |  | 
|  | 693 | setOperationAction(ISD::EXTRACT_VECTOR_ELT , MVT::v4f64, Legal); | 
|  | 694 | setOperationAction(ISD::INSERT_VECTOR_ELT , MVT::v4f64, Expand); | 
|  | 695 | setOperationAction(ISD::CONCAT_VECTORS , MVT::v4f64, Expand); | 
|  | 696 | setOperationAction(ISD::EXTRACT_SUBVECTOR , MVT::v4f64, Expand); | 
|  | 697 | setOperationAction(ISD::VECTOR_SHUFFLE , MVT::v4f64, Custom); | 
|  | 698 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v4f64, Legal); | 
|  | 699 | setOperationAction(ISD::BUILD_VECTOR, MVT::v4f64, Custom); | 
|  | 700 |  | 
|  | 701 | setOperationAction(ISD::FP_TO_SINT , MVT::v4f64, Legal); | 
|  | 702 | setOperationAction(ISD::FP_TO_UINT , MVT::v4f64, Expand); | 
|  | 703 |  | 
|  | 704 | setOperationAction(ISD::FP_ROUND , MVT::v4f32, Legal); | 
|  | 705 | setOperationAction(ISD::FP_ROUND_INREG , MVT::v4f32, Expand); | 
|  | 706 | setOperationAction(ISD::FP_EXTEND, MVT::v4f64, Legal); | 
|  | 707 |  | 
|  | 708 | setOperationAction(ISD::FNEG , MVT::v4f64, Legal); | 
|  | 709 | setOperationAction(ISD::FABS , MVT::v4f64, Legal); | 
|  | 710 | setOperationAction(ISD::FSIN , MVT::v4f64, Expand); | 
|  | 711 | setOperationAction(ISD::FCOS , MVT::v4f64, Expand); | 
|  | 712 | setOperationAction(ISD::FPOWI , MVT::v4f64, Expand); | 
|  | 713 | setOperationAction(ISD::FPOW , MVT::v4f64, Expand); | 
|  | 714 | setOperationAction(ISD::FLOG , MVT::v4f64, Expand); | 
|  | 715 | setOperationAction(ISD::FLOG2 , MVT::v4f64, Expand); | 
|  | 716 | setOperationAction(ISD::FLOG10 , MVT::v4f64, Expand); | 
|  | 717 | setOperationAction(ISD::FEXP , MVT::v4f64, Expand); | 
|  | 718 | setOperationAction(ISD::FEXP2 , MVT::v4f64, Expand); | 
|  | 719 |  | 
|  | 720 | setOperationAction(ISD::FMINNUM, MVT::v4f64, Legal); | 
|  | 721 | setOperationAction(ISD::FMAXNUM, MVT::v4f64, Legal); | 
|  | 722 |  | 
|  | 723 | setIndexedLoadAction(ISD::PRE_INC, MVT::v4f64, Legal); | 
|  | 724 | setIndexedStoreAction(ISD::PRE_INC, MVT::v4f64, Legal); | 
|  | 725 |  | 
|  | 726 | addRegisterClass(MVT::v4f64, &PPC::QFRCRegClass); | 
|  | 727 |  | 
|  | 728 | setOperationAction(ISD::FADD, MVT::v4f32, Legal); | 
|  | 729 | setOperationAction(ISD::FSUB, MVT::v4f32, Legal); | 
|  | 730 | setOperationAction(ISD::FMUL, MVT::v4f32, Legal); | 
|  | 731 | setOperationAction(ISD::FREM, MVT::v4f32, Expand); | 
|  | 732 |  | 
|  | 733 | setOperationAction(ISD::FCOPYSIGN, MVT::v4f32, Legal); | 
|  | 734 | setOperationAction(ISD::FGETSIGN, MVT::v4f32, Expand); | 
|  | 735 |  | 
|  | 736 | setOperationAction(ISD::LOAD  , MVT::v4f32, Custom); | 
|  | 737 | setOperationAction(ISD::STORE , MVT::v4f32, Custom); | 
|  | 738 |  | 
|  | 739 | if (!Subtarget.useCRBits()) | 
|  | 740 | setOperationAction(ISD::SELECT, MVT::v4f32, Expand); | 
|  | 741 | setOperationAction(ISD::VSELECT, MVT::v4f32, Legal); | 
|  | 742 |  | 
|  | 743 | setOperationAction(ISD::EXTRACT_VECTOR_ELT , MVT::v4f32, Legal); | 
|  | 744 | setOperationAction(ISD::INSERT_VECTOR_ELT , MVT::v4f32, Expand); | 
|  | 745 | setOperationAction(ISD::CONCAT_VECTORS , MVT::v4f32, Expand); | 
|  | 746 | setOperationAction(ISD::EXTRACT_SUBVECTOR , MVT::v4f32, Expand); | 
|  | 747 | setOperationAction(ISD::VECTOR_SHUFFLE , MVT::v4f32, Custom); | 
|  | 748 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v4f32, Legal); | 
|  | 749 | setOperationAction(ISD::BUILD_VECTOR, MVT::v4f32, Custom); | 
|  | 750 |  | 
|  | 751 | setOperationAction(ISD::FP_TO_SINT , MVT::v4f32, Legal); | 
|  | 752 | setOperationAction(ISD::FP_TO_UINT , MVT::v4f32, Expand); | 
|  | 753 |  | 
|  | 754 | setOperationAction(ISD::FNEG , MVT::v4f32, Legal); | 
|  | 755 | setOperationAction(ISD::FABS , MVT::v4f32, Legal); | 
|  | 756 | setOperationAction(ISD::FSIN , MVT::v4f32, Expand); | 
|  | 757 | setOperationAction(ISD::FCOS , MVT::v4f32, Expand); | 
|  | 758 | setOperationAction(ISD::FPOWI , MVT::v4f32, Expand); | 
|  | 759 | setOperationAction(ISD::FPOW , MVT::v4f32, Expand); | 
|  | 760 | setOperationAction(ISD::FLOG , MVT::v4f32, Expand); | 
|  | 761 | setOperationAction(ISD::FLOG2 , MVT::v4f32, Expand); | 
|  | 762 | setOperationAction(ISD::FLOG10 , MVT::v4f32, Expand); | 
|  | 763 | setOperationAction(ISD::FEXP , MVT::v4f32, Expand); | 
|  | 764 | setOperationAction(ISD::FEXP2 , MVT::v4f32, Expand); | 
|  | 765 |  | 
|  | 766 | setOperationAction(ISD::FMINNUM, MVT::v4f32, Legal); | 
|  | 767 | setOperationAction(ISD::FMAXNUM, MVT::v4f32, Legal); | 
|  | 768 |  | 
|  | 769 | setIndexedLoadAction(ISD::PRE_INC, MVT::v4f32, Legal); | 
|  | 770 | setIndexedStoreAction(ISD::PRE_INC, MVT::v4f32, Legal); | 
|  | 771 |  | 
|  | 772 | addRegisterClass(MVT::v4f32, &PPC::QSRCRegClass); | 
|  | 773 |  | 
|  | 774 | setOperationAction(ISD::AND , MVT::v4i1, Legal); | 
|  | 775 | setOperationAction(ISD::OR , MVT::v4i1, Legal); | 
|  | 776 | setOperationAction(ISD::XOR , MVT::v4i1, Legal); | 
|  | 777 |  | 
|  | 778 | if (!Subtarget.useCRBits()) | 
|  | 779 | setOperationAction(ISD::SELECT, MVT::v4i1, Expand); | 
|  | 780 | setOperationAction(ISD::VSELECT, MVT::v4i1, Legal); | 
|  | 781 |  | 
|  | 782 | setOperationAction(ISD::LOAD  , MVT::v4i1, Custom); | 
|  | 783 | setOperationAction(ISD::STORE , MVT::v4i1, Custom); | 
|  | 784 |  | 
|  | 785 | setOperationAction(ISD::EXTRACT_VECTOR_ELT , MVT::v4i1, Custom); | 
|  | 786 | setOperationAction(ISD::INSERT_VECTOR_ELT , MVT::v4i1, Expand); | 
|  | 787 | setOperationAction(ISD::CONCAT_VECTORS , MVT::v4i1, Expand); | 
|  | 788 | setOperationAction(ISD::EXTRACT_SUBVECTOR , MVT::v4i1, Expand); | 
|  | 789 | setOperationAction(ISD::VECTOR_SHUFFLE , MVT::v4i1, Custom); | 
|  | 790 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v4i1, Expand); | 
|  | 791 | setOperationAction(ISD::BUILD_VECTOR, MVT::v4i1, Custom); | 
|  | 792 |  | 
|  | 793 | setOperationAction(ISD::SINT_TO_FP, MVT::v4i1, Custom); | 
|  | 794 | setOperationAction(ISD::UINT_TO_FP, MVT::v4i1, Custom); | 
|  | 795 |  | 
|  | 796 | addRegisterClass(MVT::v4i1, &PPC::QBRCRegClass); | 
|  | 797 |  | 
|  | 798 | setOperationAction(ISD::FFLOOR, MVT::v4f64, Legal); | 
|  | 799 | setOperationAction(ISD::FCEIL,  MVT::v4f64, Legal); | 
|  | 800 | setOperationAction(ISD::FTRUNC, MVT::v4f64, Legal); | 
|  | 801 | setOperationAction(ISD::FROUND, MVT::v4f64, Legal); | 
|  | 802 |  | 
|  | 803 | setOperationAction(ISD::FFLOOR, MVT::v4f32, Legal); | 
|  | 804 | setOperationAction(ISD::FCEIL,  MVT::v4f32, Legal); | 
|  | 805 | setOperationAction(ISD::FTRUNC, MVT::v4f32, Legal); | 
|  | 806 | setOperationAction(ISD::FROUND, MVT::v4f32, Legal); | 
|  | 807 |  | 
|  | 808 | setOperationAction(ISD::FNEARBYINT, MVT::v4f64, Expand); | 
|  | 809 | setOperationAction(ISD::FNEARBYINT, MVT::v4f32, Expand); | 
|  | 810 |  | 
|  | 811 | // These need to set FE_INEXACT, and so cannot be vectorized here. | 
|  | 812 | setOperationAction(ISD::FRINT, MVT::v4f64, Expand); | 
|  | 813 | setOperationAction(ISD::FRINT, MVT::v4f32, Expand); | 
|  | 814 |  | 
|  | 815 | if (TM.Options.UnsafeFPMath) { | 
|  | 816 | setOperationAction(ISD::FDIV, MVT::v4f64, Legal); | 
|  | 817 | setOperationAction(ISD::FSQRT, MVT::v4f64, Legal); | 
|  | 818 |  | 
|  | 819 | setOperationAction(ISD::FDIV, MVT::v4f32, Legal); | 
|  | 820 | setOperationAction(ISD::FSQRT, MVT::v4f32, Legal); | 
|  | 821 | } else { | 
|  | 822 | setOperationAction(ISD::FDIV, MVT::v4f64, Expand); | 
|  | 823 | setOperationAction(ISD::FSQRT, MVT::v4f64, Expand); | 
|  | 824 |  | 
|  | 825 | setOperationAction(ISD::FDIV, MVT::v4f32, Expand); | 
|  | 826 | setOperationAction(ISD::FSQRT, MVT::v4f32, Expand); | 
|  | 827 | } | 
|  | 828 | } | 
|  | 829 |  | 
| Hal Finkel | 01fa770 | 2014-12-03 00:19:17 +0000 | [diff] [blame] | 830 | if (Subtarget.has64BitSupport()) | 
| Hal Finkel | 322e41a | 2012-04-01 20:08:17 +0000 | [diff] [blame] | 831 | setOperationAction(ISD::PREFETCH, MVT::Other, Legal); | 
| Hal Finkel | 01fa770 | 2014-12-03 00:19:17 +0000 | [diff] [blame] | 832 |  | 
|  | 833 | setOperationAction(ISD::READCYCLECOUNTER, MVT::i64, isPPC64 ? Legal : Custom); | 
| Hal Finkel | 322e41a | 2012-04-01 20:08:17 +0000 | [diff] [blame] | 834 |  | 
| Robin Morisset | e1ca44b | 2014-10-02 22:27:07 +0000 | [diff] [blame] | 835 | if (!isPPC64) { | 
|  | 836 | setOperationAction(ISD::ATOMIC_LOAD,  MVT::i64, Expand); | 
|  | 837 | setOperationAction(ISD::ATOMIC_STORE, MVT::i64, Expand); | 
|  | 838 | } | 
| Eli Friedman | 7dfa791 | 2011-08-29 18:23:02 +0000 | [diff] [blame] | 839 |  | 
| Duncan Sands | 8d6e2e1 | 2008-11-23 15:47:28 +0000 | [diff] [blame] | 840 | setBooleanContents(ZeroOrOneBooleanContent); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 841 |  | 
|  | 842 | if (Subtarget.hasAltivec()) { | 
|  | 843 | // Altivec instructions set fields to all zeros or all ones. | 
|  | 844 | setBooleanVectorContents(ZeroOrNegativeOneBooleanContent); | 
|  | 845 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 846 |  | 
| Joerg Sonnenberger | b5459e6 | 2014-07-24 22:20:10 +0000 | [diff] [blame] | 847 | if (!isPPC64) { | 
|  | 848 | // These libcalls are not available in 32-bit. | 
|  | 849 | setLibcallName(RTLIB::SHL_I128, nullptr); | 
|  | 850 | setLibcallName(RTLIB::SRL_I128, nullptr); | 
|  | 851 | setLibcallName(RTLIB::SRA_I128, nullptr); | 
|  | 852 | } | 
|  | 853 |  | 
| Joseph Tremoulet | f748c89 | 2015-11-07 01:11:31 +0000 | [diff] [blame] | 854 | setStackPointerRegisterToSaveRestore(isPPC64 ? PPC::X1 : PPC::R1); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 855 |  | 
| Chris Lattner | f418435 | 2006-03-01 04:57:39 +0000 | [diff] [blame] | 856 | // We have target-specific dag combine patterns for the following nodes: | 
|  | 857 | setTargetDAGCombine(ISD::SINT_TO_FP); | 
| Nemanja Ivanovic | 44513e5 | 2016-07-05 09:22:29 +0000 | [diff] [blame] | 858 | setTargetDAGCombine(ISD::BUILD_VECTOR); | 
| Hal Finkel | 5efb918 | 2015-01-06 06:01:57 +0000 | [diff] [blame] | 859 | if (Subtarget.hasFPCVT()) | 
|  | 860 | setTargetDAGCombine(ISD::UINT_TO_FP); | 
| Hal Finkel | cf2e908 | 2013-05-24 23:00:14 +0000 | [diff] [blame] | 861 | setTargetDAGCombine(ISD::LOAD); | 
| Chris Lattner | 27f5345 | 2006-03-01 05:50:56 +0000 | [diff] [blame] | 862 | setTargetDAGCombine(ISD::STORE); | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 863 | setTargetDAGCombine(ISD::BR_CC); | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 864 | if (Subtarget.useCRBits()) | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 865 | setTargetDAGCombine(ISD::BRCOND); | 
| Chris Lattner | a7976d3 | 2006-07-10 20:56:58 +0000 | [diff] [blame] | 866 | setTargetDAGCombine(ISD::BSWAP); | 
| Hal Finkel | bc2ee4c | 2013-05-25 04:05:05 +0000 | [diff] [blame] | 867 | setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN); | 
| Bill Schmidt | fae5d71 | 2014-12-09 16:35:51 +0000 | [diff] [blame] | 868 | setTargetDAGCombine(ISD::INTRINSIC_W_CHAIN); | 
|  | 869 | setTargetDAGCombine(ISD::INTRINSIC_VOID); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 870 |  | 
| Hal Finkel | 46043ed | 2014-03-01 21:36:57 +0000 | [diff] [blame] | 871 | setTargetDAGCombine(ISD::SIGN_EXTEND); | 
|  | 872 | setTargetDAGCombine(ISD::ZERO_EXTEND); | 
|  | 873 | setTargetDAGCombine(ISD::ANY_EXTEND); | 
|  | 874 |  | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 875 | if (Subtarget.useCRBits()) { | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 876 | setTargetDAGCombine(ISD::TRUNCATE); | 
|  | 877 | setTargetDAGCombine(ISD::SETCC); | 
|  | 878 | setTargetDAGCombine(ISD::SELECT_CC); | 
|  | 879 | } | 
|  | 880 |  | 
| Hal Finkel | 2e10331 | 2013-04-03 04:01:11 +0000 | [diff] [blame] | 881 | // Use reciprocal estimates. | 
|  | 882 | if (TM.Options.UnsafeFPMath) { | 
|  | 883 | setTargetDAGCombine(ISD::FDIV); | 
|  | 884 | setTargetDAGCombine(ISD::FSQRT); | 
|  | 885 | } | 
|  | 886 |  | 
| Dale Johannesen | 10432e5 | 2007-10-19 00:59:18 +0000 | [diff] [blame] | 887 | // Darwin long double math library functions have $LDBL128 appended. | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 888 | if (Subtarget.isDarwin()) { | 
| Duncan Sands | 53c954f | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 889 | setLibcallName(RTLIB::COS_PPCF128, "cosl$LDBL128"); | 
| Dale Johannesen | 10432e5 | 2007-10-19 00:59:18 +0000 | [diff] [blame] | 890 | setLibcallName(RTLIB::POW_PPCF128, "powl$LDBL128"); | 
|  | 891 | setLibcallName(RTLIB::REM_PPCF128, "fmodl$LDBL128"); | 
| Duncan Sands | 53c954f | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 892 | setLibcallName(RTLIB::SIN_PPCF128, "sinl$LDBL128"); | 
|  | 893 | setLibcallName(RTLIB::SQRT_PPCF128, "sqrtl$LDBL128"); | 
| Dale Johannesen | da2d806 | 2008-09-04 00:47:13 +0000 | [diff] [blame] | 894 | setLibcallName(RTLIB::LOG_PPCF128, "logl$LDBL128"); | 
|  | 895 | setLibcallName(RTLIB::LOG2_PPCF128, "log2l$LDBL128"); | 
|  | 896 | setLibcallName(RTLIB::LOG10_PPCF128, "log10l$LDBL128"); | 
|  | 897 | setLibcallName(RTLIB::EXP_PPCF128, "expl$LDBL128"); | 
|  | 898 | setLibcallName(RTLIB::EXP2_PPCF128, "exp2l$LDBL128"); | 
| Dale Johannesen | 10432e5 | 2007-10-19 00:59:18 +0000 | [diff] [blame] | 899 | } | 
|  | 900 |  | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 901 | // With 32 condition bits, we don't need to sink (and duplicate) compares | 
|  | 902 | // aggressively in CodeGenPrep. | 
| Hal Finkel | 7a0516e | 2015-02-12 01:02:52 +0000 | [diff] [blame] | 903 | if (Subtarget.useCRBits()) { | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 904 | setHasMultipleConditionRegisters(); | 
| Hal Finkel | 7a0516e | 2015-02-12 01:02:52 +0000 | [diff] [blame] | 905 | setJumpIsExpensive(); | 
|  | 906 | } | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 907 |  | 
| Hal Finkel | 6529857 | 2011-10-17 18:53:03 +0000 | [diff] [blame] | 908 | setMinFunctionAlignment(2); | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 909 | if (Subtarget.isDarwin()) | 
| Hal Finkel | 6529857 | 2011-10-17 18:53:03 +0000 | [diff] [blame] | 910 | setPrefFunctionAlignment(4); | 
| Eli Friedman | 2518f83 | 2011-05-06 20:34:06 +0000 | [diff] [blame] | 911 |  | 
| Hal Finkel | d73bfba | 2015-01-03 14:58:25 +0000 | [diff] [blame] | 912 | switch (Subtarget.getDarwinDirective()) { | 
|  | 913 | default: break; | 
|  | 914 | case PPC::DIR_970: | 
|  | 915 | case PPC::DIR_A2: | 
|  | 916 | case PPC::DIR_E500mc: | 
|  | 917 | case PPC::DIR_E5500: | 
|  | 918 | case PPC::DIR_PWR4: | 
|  | 919 | case PPC::DIR_PWR5: | 
|  | 920 | case PPC::DIR_PWR5X: | 
|  | 921 | case PPC::DIR_PWR6: | 
|  | 922 | case PPC::DIR_PWR6X: | 
|  | 923 | case PPC::DIR_PWR7: | 
|  | 924 | case PPC::DIR_PWR8: | 
| Nemanja Ivanovic | 6e29baf | 2016-05-09 18:54:58 +0000 | [diff] [blame] | 925 | case PPC::DIR_PWR9: | 
| Hal Finkel | d73bfba | 2015-01-03 14:58:25 +0000 | [diff] [blame] | 926 | setPrefFunctionAlignment(4); | 
|  | 927 | setPrefLoopAlignment(4); | 
|  | 928 | break; | 
|  | 929 | } | 
|  | 930 |  | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 931 | if (Subtarget.enableMachineScheduler()) | 
| Hal Finkel | 21442b2 | 2013-09-11 23:05:25 +0000 | [diff] [blame] | 932 | setSchedulingPreference(Sched::Source); | 
|  | 933 | else | 
|  | 934 | setSchedulingPreference(Sched::Hybrid); | 
| Hal Finkel | 6f0ae78 | 2011-11-22 16:21:04 +0000 | [diff] [blame] | 935 |  | 
| Eric Christopher | 23a3a7c | 2015-02-26 00:00:24 +0000 | [diff] [blame] | 936 | computeRegisterProperties(STI.getRegisterInfo()); | 
| Hal Finkel | 742b535 | 2012-08-28 16:12:39 +0000 | [diff] [blame] | 937 |  | 
| Hal Finkel | d73bfba | 2015-01-03 14:58:25 +0000 | [diff] [blame] | 938 | // The Freescale cores do better with aggressive inlining of memcpy and | 
|  | 939 | // friends. GCC uses same threshold of 128 bytes (= 32 word stores). | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 940 | if (Subtarget.getDarwinDirective() == PPC::DIR_E500mc || | 
|  | 941 | Subtarget.getDarwinDirective() == PPC::DIR_E5500) { | 
| Jim Grosbach | 341ad3e | 2013-02-20 21:13:59 +0000 | [diff] [blame] | 942 | MaxStoresPerMemset = 32; | 
|  | 943 | MaxStoresPerMemsetOptSize = 16; | 
|  | 944 | MaxStoresPerMemcpy = 32; | 
|  | 945 | MaxStoresPerMemcpyOptSize = 8; | 
|  | 946 | MaxStoresPerMemmove = 32; | 
|  | 947 | MaxStoresPerMemmoveOptSize = 8; | 
| Hal Finkel | 5c3cacf | 2015-02-27 19:58:28 +0000 | [diff] [blame] | 948 | } else if (Subtarget.getDarwinDirective() == PPC::DIR_A2) { | 
|  | 949 | // The A2 also benefits from (very) aggressive inlining of memcpy and | 
|  | 950 | // friends. The overhead of a the function call, even when warm, can be | 
|  | 951 | // over one hundred cycles. | 
|  | 952 | MaxStoresPerMemset = 128; | 
|  | 953 | MaxStoresPerMemcpy = 128; | 
|  | 954 | MaxStoresPerMemmove = 128; | 
| Hal Finkel | 742b535 | 2012-08-28 16:12:39 +0000 | [diff] [blame] | 955 | } | 
| Chris Lattner | f22556d | 2005-08-16 17:14:42 +0000 | [diff] [blame] | 956 | } | 
|  | 957 |  | 
| Hal Finkel | 262a224 | 2013-09-12 23:20:06 +0000 | [diff] [blame] | 958 | /// getMaxByValAlign - Helper for getByValTypeAlignment to determine | 
|  | 959 | /// the desired ByVal argument alignment. | 
| Pete Cooper | 2e20147 | 2015-07-27 17:15:24 +0000 | [diff] [blame] | 960 | static void getMaxByValAlign(Type *Ty, unsigned &MaxAlign, | 
| Hal Finkel | 262a224 | 2013-09-12 23:20:06 +0000 | [diff] [blame] | 961 | unsigned MaxMaxAlign) { | 
|  | 962 | if (MaxAlign == MaxMaxAlign) | 
|  | 963 | return; | 
| Pete Cooper | 2e20147 | 2015-07-27 17:15:24 +0000 | [diff] [blame] | 964 | if (VectorType *VTy = dyn_cast<VectorType>(Ty)) { | 
| Hal Finkel | 262a224 | 2013-09-12 23:20:06 +0000 | [diff] [blame] | 965 | if (MaxMaxAlign >= 32 && VTy->getBitWidth() >= 256) | 
|  | 966 | MaxAlign = 32; | 
|  | 967 | else if (VTy->getBitWidth() >= 128 && MaxAlign < 16) | 
|  | 968 | MaxAlign = 16; | 
| Pete Cooper | 2e20147 | 2015-07-27 17:15:24 +0000 | [diff] [blame] | 969 | } else if (ArrayType *ATy = dyn_cast<ArrayType>(Ty)) { | 
| Hal Finkel | 262a224 | 2013-09-12 23:20:06 +0000 | [diff] [blame] | 970 | unsigned EltAlign = 0; | 
|  | 971 | getMaxByValAlign(ATy->getElementType(), EltAlign, MaxMaxAlign); | 
|  | 972 | if (EltAlign > MaxAlign) | 
|  | 973 | MaxAlign = EltAlign; | 
| Pete Cooper | 2e20147 | 2015-07-27 17:15:24 +0000 | [diff] [blame] | 974 | } else if (StructType *STy = dyn_cast<StructType>(Ty)) { | 
|  | 975 | for (auto *EltTy : STy->elements()) { | 
| Hal Finkel | 262a224 | 2013-09-12 23:20:06 +0000 | [diff] [blame] | 976 | unsigned EltAlign = 0; | 
| Pete Cooper | 0debbdc | 2015-07-24 18:55:49 +0000 | [diff] [blame] | 977 | getMaxByValAlign(EltTy, EltAlign, MaxMaxAlign); | 
| Hal Finkel | 262a224 | 2013-09-12 23:20:06 +0000 | [diff] [blame] | 978 | if (EltAlign > MaxAlign) | 
|  | 979 | MaxAlign = EltAlign; | 
|  | 980 | if (MaxAlign == MaxMaxAlign) | 
|  | 981 | break; | 
|  | 982 | } | 
|  | 983 | } | 
|  | 984 | } | 
|  | 985 |  | 
| Dale Johannesen | cbde4c2 | 2008-02-28 22:31:51 +0000 | [diff] [blame] | 986 | /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate | 
|  | 987 | /// function arguments in the caller parameter area. | 
| Mehdi Amini | 5c183d5 | 2015-07-09 02:09:28 +0000 | [diff] [blame] | 988 | unsigned PPCTargetLowering::getByValTypeAlignment(Type *Ty, | 
|  | 989 | const DataLayout &DL) const { | 
| Dale Johannesen | cbde4c2 | 2008-02-28 22:31:51 +0000 | [diff] [blame] | 990 | // Darwin passes everything on 4 byte boundary. | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 991 | if (Subtarget.isDarwin()) | 
| Dale Johannesen | cbde4c2 | 2008-02-28 22:31:51 +0000 | [diff] [blame] | 992 | return 4; | 
| Roman Divacky | b9663cc | 2012-04-02 15:49:30 +0000 | [diff] [blame] | 993 |  | 
|  | 994 | // 16byte and wider vectors are passed on 16byte boundary. | 
| Roman Divacky | b9663cc | 2012-04-02 15:49:30 +0000 | [diff] [blame] | 995 | // The rest is 8 on PPC64 and 4 on PPC32 boundary. | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 996 | unsigned Align = Subtarget.isPPC64() ? 8 : 4; | 
|  | 997 | if (Subtarget.hasAltivec() || Subtarget.hasQPX()) | 
|  | 998 | getMaxByValAlign(Ty, Align, Subtarget.hasQPX() ? 32 : 16); | 
| Hal Finkel | 262a224 | 2013-09-12 23:20:06 +0000 | [diff] [blame] | 999 | return Align; | 
| Dale Johannesen | cbde4c2 | 2008-02-28 22:31:51 +0000 | [diff] [blame] | 1000 | } | 
|  | 1001 |  | 
| Petar Jovanovic | 280f710 | 2015-12-14 17:57:33 +0000 | [diff] [blame] | 1002 | bool PPCTargetLowering::useSoftFloat() const { | 
|  | 1003 | return Subtarget.useSoftFloat(); | 
|  | 1004 | } | 
|  | 1005 |  | 
| Chris Lattner | 347ed8a | 2006-01-09 23:52:17 +0000 | [diff] [blame] | 1006 | const char *PPCTargetLowering::getTargetNodeName(unsigned Opcode) const { | 
| Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1007 | switch ((PPCISD::NodeType)Opcode) { | 
|  | 1008 | case PPCISD::FIRST_NUMBER:    break; | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 1009 | case PPCISD::FSEL:            return "PPCISD::FSEL"; | 
|  | 1010 | case PPCISD::FCFID:           return "PPCISD::FCFID"; | 
| Hal Finkel | 3fe09ea | 2015-01-06 07:02:15 +0000 | [diff] [blame] | 1011 | case PPCISD::FCFIDU:          return "PPCISD::FCFIDU"; | 
|  | 1012 | case PPCISD::FCFIDS:          return "PPCISD::FCFIDS"; | 
|  | 1013 | case PPCISD::FCFIDUS:         return "PPCISD::FCFIDUS"; | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 1014 | case PPCISD::FCTIDZ:          return "PPCISD::FCTIDZ"; | 
|  | 1015 | case PPCISD::FCTIWZ:          return "PPCISD::FCTIWZ"; | 
| Hal Finkel | 3fe09ea | 2015-01-06 07:02:15 +0000 | [diff] [blame] | 1016 | case PPCISD::FCTIDUZ:         return "PPCISD::FCTIDUZ"; | 
|  | 1017 | case PPCISD::FCTIWUZ:         return "PPCISD::FCTIWUZ"; | 
| Hal Finkel | 2e10331 | 2013-04-03 04:01:11 +0000 | [diff] [blame] | 1018 | case PPCISD::FRE:             return "PPCISD::FRE"; | 
|  | 1019 | case PPCISD::FRSQRTE:         return "PPCISD::FRSQRTE"; | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 1020 | case PPCISD::STFIWX:          return "PPCISD::STFIWX"; | 
|  | 1021 | case PPCISD::VMADDFP:         return "PPCISD::VMADDFP"; | 
|  | 1022 | case PPCISD::VNMSUBFP:        return "PPCISD::VNMSUBFP"; | 
|  | 1023 | case PPCISD::VPERM:           return "PPCISD::VPERM"; | 
| Nemanja Ivanovic | 1a2b2f0 | 2016-05-04 16:04:02 +0000 | [diff] [blame] | 1024 | case PPCISD::XXSPLT:          return "PPCISD::XXSPLT"; | 
| Nemanja Ivanovic | b43bb61 | 2016-07-12 21:00:10 +0000 | [diff] [blame] | 1025 | case PPCISD::XXINSERT:        return "PPCISD::XXINSERT"; | 
|  | 1026 | case PPCISD::VECSHL:          return "PPCISD::VECSHL"; | 
| Hal Finkel | 4edc66b | 2015-01-03 01:16:37 +0000 | [diff] [blame] | 1027 | case PPCISD::CMPB:            return "PPCISD::CMPB"; | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 1028 | case PPCISD::Hi:              return "PPCISD::Hi"; | 
|  | 1029 | case PPCISD::Lo:              return "PPCISD::Lo"; | 
| Tilmann Scheller | d1aaa32 | 2009-08-15 11:54:46 +0000 | [diff] [blame] | 1030 | case PPCISD::TOC_ENTRY:       return "PPCISD::TOC_ENTRY"; | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 1031 | case PPCISD::DYNALLOC:        return "PPCISD::DYNALLOC"; | 
| Yury Gribov | d7dbb66 | 2015-12-01 11:40:55 +0000 | [diff] [blame] | 1032 | case PPCISD::DYNAREAOFFSET:   return "PPCISD::DYNAREAOFFSET"; | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 1033 | case PPCISD::GlobalBaseReg:   return "PPCISD::GlobalBaseReg"; | 
|  | 1034 | case PPCISD::SRL:             return "PPCISD::SRL"; | 
|  | 1035 | case PPCISD::SRA:             return "PPCISD::SRA"; | 
|  | 1036 | case PPCISD::SHL:             return "PPCISD::SHL"; | 
| Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1037 | case PPCISD::SRA_ADDZE:       return "PPCISD::SRA_ADDZE"; | 
| Ulrich Weigand | f62e83f | 2013-03-22 15:24:13 +0000 | [diff] [blame] | 1038 | case PPCISD::CALL:            return "PPCISD::CALL"; | 
|  | 1039 | case PPCISD::CALL_NOP:        return "PPCISD::CALL_NOP"; | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 1040 | case PPCISD::MTCTR:           return "PPCISD::MTCTR"; | 
| Ulrich Weigand | f62e83f | 2013-03-22 15:24:13 +0000 | [diff] [blame] | 1041 | case PPCISD::BCTRL:           return "PPCISD::BCTRL"; | 
| Hal Finkel | fc096c9 | 2014-12-23 22:29:40 +0000 | [diff] [blame] | 1042 | case PPCISD::BCTRL_LOAD_TOC:  return "PPCISD::BCTRL_LOAD_TOC"; | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 1043 | case PPCISD::RET_FLAG:        return "PPCISD::RET_FLAG"; | 
| Hal Finkel | bbdee93 | 2014-12-02 22:01:00 +0000 | [diff] [blame] | 1044 | case PPCISD::READ_TIME_BASE:  return "PPCISD::READ_TIME_BASE"; | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 1045 | case PPCISD::EH_SJLJ_SETJMP:  return "PPCISD::EH_SJLJ_SETJMP"; | 
|  | 1046 | case PPCISD::EH_SJLJ_LONGJMP: return "PPCISD::EH_SJLJ_LONGJMP"; | 
| Ulrich Weigand | d5ebc62 | 2013-07-03 17:05:42 +0000 | [diff] [blame] | 1047 | case PPCISD::MFOCRF:          return "PPCISD::MFOCRF"; | 
| Nemanja Ivanovic | c38b531 | 2015-04-11 10:40:42 +0000 | [diff] [blame] | 1048 | case PPCISD::MFVSR:           return "PPCISD::MFVSR"; | 
|  | 1049 | case PPCISD::MTVSRA:          return "PPCISD::MTVSRA"; | 
|  | 1050 | case PPCISD::MTVSRZ:          return "PPCISD::MTVSRZ"; | 
| Nemanja Ivanovic | 44513e5 | 2016-07-05 09:22:29 +0000 | [diff] [blame] | 1051 | case PPCISD::SINT_VEC_TO_FP:  return "PPCISD::SINT_VEC_TO_FP"; | 
|  | 1052 | case PPCISD::UINT_VEC_TO_FP:  return "PPCISD::UINT_VEC_TO_FP"; | 
| Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1053 | case PPCISD::ANDIo_1_EQ_BIT:  return "PPCISD::ANDIo_1_EQ_BIT"; | 
|  | 1054 | case PPCISD::ANDIo_1_GT_BIT:  return "PPCISD::ANDIo_1_GT_BIT"; | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 1055 | case PPCISD::VCMP:            return "PPCISD::VCMP"; | 
|  | 1056 | case PPCISD::VCMPo:           return "PPCISD::VCMPo"; | 
|  | 1057 | case PPCISD::LBRX:            return "PPCISD::LBRX"; | 
|  | 1058 | case PPCISD::STBRX:           return "PPCISD::STBRX"; | 
| Hal Finkel | 3fe09ea | 2015-01-06 07:02:15 +0000 | [diff] [blame] | 1059 | case PPCISD::LFIWAX:          return "PPCISD::LFIWAX"; | 
|  | 1060 | case PPCISD::LFIWZX:          return "PPCISD::LFIWZX"; | 
| Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1061 | case PPCISD::LXVD2X:          return "PPCISD::LXVD2X"; | 
|  | 1062 | case PPCISD::STXVD2X:         return "PPCISD::STXVD2X"; | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 1063 | case PPCISD::COND_BRANCH:     return "PPCISD::COND_BRANCH"; | 
| Hal Finkel | 25c1992 | 2013-05-15 21:37:41 +0000 | [diff] [blame] | 1064 | case PPCISD::BDNZ:            return "PPCISD::BDNZ"; | 
|  | 1065 | case PPCISD::BDZ:             return "PPCISD::BDZ"; | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 1066 | case PPCISD::MFFS:            return "PPCISD::MFFS"; | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 1067 | case PPCISD::FADDRTZ:         return "PPCISD::FADDRTZ"; | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 1068 | case PPCISD::TC_RETURN:       return "PPCISD::TC_RETURN"; | 
| Hal Finkel | 5ab3780 | 2012-08-28 02:10:27 +0000 | [diff] [blame] | 1069 | case PPCISD::CR6SET:          return "PPCISD::CR6SET"; | 
|  | 1070 | case PPCISD::CR6UNSET:        return "PPCISD::CR6UNSET"; | 
| Roman Divacky | 32143e2 | 2013-12-20 18:08:54 +0000 | [diff] [blame] | 1071 | case PPCISD::PPC32_GOT:       return "PPCISD::PPC32_GOT"; | 
| Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1072 | case PPCISD::PPC32_PICGOT:    return "PPCISD::PPC32_PICGOT"; | 
| Bill Schmidt | 9f0b4ec | 2012-12-14 17:02:38 +0000 | [diff] [blame] | 1073 | case PPCISD::ADDIS_GOT_TPREL_HA: return "PPCISD::ADDIS_GOT_TPREL_HA"; | 
|  | 1074 | case PPCISD::LD_GOT_TPREL_L:  return "PPCISD::LD_GOT_TPREL_L"; | 
| Bill Schmidt | ca4a0c9 | 2012-12-04 16:18:08 +0000 | [diff] [blame] | 1075 | case PPCISD::ADD_TLS:         return "PPCISD::ADD_TLS"; | 
| Bill Schmidt | c56f1d3 | 2012-12-11 20:30:11 +0000 | [diff] [blame] | 1076 | case PPCISD::ADDIS_TLSGD_HA:  return "PPCISD::ADDIS_TLSGD_HA"; | 
|  | 1077 | case PPCISD::ADDI_TLSGD_L:    return "PPCISD::ADDI_TLSGD_L"; | 
| Bill Schmidt | 82f1c77 | 2015-02-10 19:09:05 +0000 | [diff] [blame] | 1078 | case PPCISD::GET_TLS_ADDR:    return "PPCISD::GET_TLS_ADDR"; | 
|  | 1079 | case PPCISD::ADDI_TLSGD_L_ADDR: return "PPCISD::ADDI_TLSGD_L_ADDR"; | 
| Bill Schmidt | 24b8dd6 | 2012-12-12 19:29:35 +0000 | [diff] [blame] | 1080 | case PPCISD::ADDIS_TLSLD_HA:  return "PPCISD::ADDIS_TLSLD_HA"; | 
|  | 1081 | case PPCISD::ADDI_TLSLD_L:    return "PPCISD::ADDI_TLSLD_L"; | 
| Bill Schmidt | 82f1c77 | 2015-02-10 19:09:05 +0000 | [diff] [blame] | 1082 | case PPCISD::GET_TLSLD_ADDR:  return "PPCISD::GET_TLSLD_ADDR"; | 
|  | 1083 | case PPCISD::ADDI_TLSLD_L_ADDR: return "PPCISD::ADDI_TLSLD_L_ADDR"; | 
| Bill Schmidt | 24b8dd6 | 2012-12-12 19:29:35 +0000 | [diff] [blame] | 1084 | case PPCISD::ADDIS_DTPREL_HA: return "PPCISD::ADDIS_DTPREL_HA"; | 
|  | 1085 | case PPCISD::ADDI_DTPREL_L:   return "PPCISD::ADDI_DTPREL_L"; | 
| Bill Schmidt | 51e7951 | 2013-02-20 15:50:31 +0000 | [diff] [blame] | 1086 | case PPCISD::VADD_SPLAT:      return "PPCISD::VADD_SPLAT"; | 
| Bill Schmidt | a87a7e2 | 2013-05-14 19:35:45 +0000 | [diff] [blame] | 1087 | case PPCISD::SC:              return "PPCISD::SC"; | 
| Bill Schmidt | e26236e | 2015-05-22 16:44:10 +0000 | [diff] [blame] | 1088 | case PPCISD::CLRBHRB:         return "PPCISD::CLRBHRB"; | 
|  | 1089 | case PPCISD::MFBHRBE:         return "PPCISD::MFBHRBE"; | 
|  | 1090 | case PPCISD::RFEBB:           return "PPCISD::RFEBB"; | 
| Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1091 | case PPCISD::XXSWAPD:         return "PPCISD::XXSWAPD"; | 
| Nemanja Ivanovic | eebbcb6 | 2016-07-12 12:16:27 +0000 | [diff] [blame] | 1092 | case PPCISD::SWAP_NO_CHAIN:   return "PPCISD::SWAP_NO_CHAIN"; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 1093 | case PPCISD::QVFPERM:         return "PPCISD::QVFPERM"; | 
|  | 1094 | case PPCISD::QVGPCI:          return "PPCISD::QVGPCI"; | 
|  | 1095 | case PPCISD::QVALIGNI:        return "PPCISD::QVALIGNI"; | 
|  | 1096 | case PPCISD::QVESPLATI:       return "PPCISD::QVESPLATI"; | 
|  | 1097 | case PPCISD::QBFLT:           return "PPCISD::QBFLT"; | 
|  | 1098 | case PPCISD::QVLFSb:          return "PPCISD::QVLFSb"; | 
| Chris Lattner | 347ed8a | 2006-01-09 23:52:17 +0000 | [diff] [blame] | 1099 | } | 
| Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1100 | return nullptr; | 
| Chris Lattner | 347ed8a | 2006-01-09 23:52:17 +0000 | [diff] [blame] | 1101 | } | 
|  | 1102 |  | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1103 | EVT PPCTargetLowering::getSetCCResultType(const DataLayout &DL, LLVMContext &C, | 
|  | 1104 | EVT VT) const { | 
| Adhemerval Zanella | fe3f793 | 2012-10-08 18:59:53 +0000 | [diff] [blame] | 1105 | if (!VT.isVector()) | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 1106 | return Subtarget.useCRBits() ? MVT::i1 : MVT::i32; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 1107 |  | 
|  | 1108 | if (Subtarget.hasQPX()) | 
|  | 1109 | return EVT::getVectorVT(C, MVT::i1, VT.getVectorNumElements()); | 
|  | 1110 |  | 
| Adhemerval Zanella | fe3f793 | 2012-10-08 18:59:53 +0000 | [diff] [blame] | 1111 | return VT.changeVectorElementTypeToInteger(); | 
| Scott Michel | a6729e8 | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 1112 | } | 
|  | 1113 |  | 
| Hal Finkel | 62ac736 | 2014-09-19 11:42:56 +0000 | [diff] [blame] | 1114 | bool PPCTargetLowering::enableAggressiveFMAFusion(EVT VT) const { | 
|  | 1115 | assert(VT.isFloatingPoint() && "Non-floating-point FMA?"); | 
|  | 1116 | return true; | 
|  | 1117 | } | 
|  | 1118 |  | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 1119 | //===----------------------------------------------------------------------===// | 
|  | 1120 | // Node matching predicates, for use by the tblgen matching code. | 
|  | 1121 | //===----------------------------------------------------------------------===// | 
|  | 1122 |  | 
| Chris Lattner | 7f1fa8e | 2005-08-26 17:36:52 +0000 | [diff] [blame] | 1123 | /// isFloatingPointZero - Return true if this is 0.0 or -0.0. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1124 | static bool isFloatingPointZero(SDValue Op) { | 
| Chris Lattner | 7f1fa8e | 2005-08-26 17:36:52 +0000 | [diff] [blame] | 1125 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op)) | 
| Dale Johannesen | 3cf889f | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 1126 | return CFP->getValueAPF().isZero(); | 
| Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1127 | else if (ISD::isEXTLoad(Op.getNode()) || ISD::isNON_EXTLoad(Op.getNode())) { | 
| Chris Lattner | 7f1fa8e | 2005-08-26 17:36:52 +0000 | [diff] [blame] | 1128 | // Maybe this has already been legalized into the constant pool? | 
|  | 1129 | if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Op.getOperand(1))) | 
| Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1130 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal())) | 
| Dale Johannesen | 3cf889f | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 1131 | return CFP->getValueAPF().isZero(); | 
| Chris Lattner | 7f1fa8e | 2005-08-26 17:36:52 +0000 | [diff] [blame] | 1132 | } | 
|  | 1133 | return false; | 
|  | 1134 | } | 
|  | 1135 |  | 
| Chris Lattner | e8b83b4 | 2006-04-06 17:23:16 +0000 | [diff] [blame] | 1136 | /// isConstantOrUndef - Op is either an undef node or a ConstantSDNode.  Return | 
|  | 1137 | /// true if Op is undef or if it matches the specified value. | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1138 | static bool isConstantOrUndef(int Op, int Val) { | 
|  | 1139 | return Op < 0 || Op == Val; | 
| Chris Lattner | e8b83b4 | 2006-04-06 17:23:16 +0000 | [diff] [blame] | 1140 | } | 
|  | 1141 |  | 
|  | 1142 | /// isVPKUHUMShuffleMask - Return true if this is the shuffle mask for a | 
|  | 1143 | /// VPKUHUM instruction. | 
| Ulrich Weigand | cc9909b | 2014-08-04 13:53:40 +0000 | [diff] [blame] | 1144 | /// The ShuffleKind distinguishes between big-endian operations with | 
|  | 1145 | /// two different inputs (0), either-endian operations with two identical | 
| Bill Schmidt | 5ed84cd | 2015-05-16 01:02:12 +0000 | [diff] [blame] | 1146 | /// inputs (1), and little-endian operations with two different inputs (2). | 
| Ulrich Weigand | cc9909b | 2014-08-04 13:53:40 +0000 | [diff] [blame] | 1147 | /// For the latter, the input operands are swapped (see PPCInstrAltivec.td). | 
|  | 1148 | bool PPC::isVPKUHUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind, | 
| Bill Schmidt | f910a06 | 2014-06-10 14:35:01 +0000 | [diff] [blame] | 1149 | SelectionDAG &DAG) { | 
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 1150 | bool IsLE = DAG.getDataLayout().isLittleEndian(); | 
| Ulrich Weigand | cc9909b | 2014-08-04 13:53:40 +0000 | [diff] [blame] | 1151 | if (ShuffleKind == 0) { | 
| Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 1152 | if (IsLE) | 
| Ulrich Weigand | cc9909b | 2014-08-04 13:53:40 +0000 | [diff] [blame] | 1153 | return false; | 
| Chris Lattner | a4bbfae | 2006-04-06 22:28:36 +0000 | [diff] [blame] | 1154 | for (unsigned i = 0; i != 16; ++i) | 
| Ulrich Weigand | cc9909b | 2014-08-04 13:53:40 +0000 | [diff] [blame] | 1155 | if (!isConstantOrUndef(N->getMaskElt(i), i*2+1)) | 
| Chris Lattner | a4bbfae | 2006-04-06 22:28:36 +0000 | [diff] [blame] | 1156 | return false; | 
| Ulrich Weigand | cc9909b | 2014-08-04 13:53:40 +0000 | [diff] [blame] | 1157 | } else if (ShuffleKind == 2) { | 
| Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 1158 | if (!IsLE) | 
| Ulrich Weigand | cc9909b | 2014-08-04 13:53:40 +0000 | [diff] [blame] | 1159 | return false; | 
|  | 1160 | for (unsigned i = 0; i != 16; ++i) | 
|  | 1161 | if (!isConstantOrUndef(N->getMaskElt(i), i*2)) | 
|  | 1162 | return false; | 
|  | 1163 | } else if (ShuffleKind == 1) { | 
| Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 1164 | unsigned j = IsLE ? 0 : 1; | 
| Chris Lattner | a4bbfae | 2006-04-06 22:28:36 +0000 | [diff] [blame] | 1165 | for (unsigned i = 0; i != 8; ++i) | 
| Bill Schmidt | f910a06 | 2014-06-10 14:35:01 +0000 | [diff] [blame] | 1166 | if (!isConstantOrUndef(N->getMaskElt(i),    i*2+j) || | 
|  | 1167 | !isConstantOrUndef(N->getMaskElt(i+8),  i*2+j)) | 
| Chris Lattner | a4bbfae | 2006-04-06 22:28:36 +0000 | [diff] [blame] | 1168 | return false; | 
|  | 1169 | } | 
| Chris Lattner | 1d33819 | 2006-04-06 18:26:28 +0000 | [diff] [blame] | 1170 | return true; | 
| Chris Lattner | e8b83b4 | 2006-04-06 17:23:16 +0000 | [diff] [blame] | 1171 | } | 
|  | 1172 |  | 
|  | 1173 | /// isVPKUWUMShuffleMask - Return true if this is the shuffle mask for a | 
|  | 1174 | /// VPKUWUM instruction. | 
| Ulrich Weigand | cc9909b | 2014-08-04 13:53:40 +0000 | [diff] [blame] | 1175 | /// The ShuffleKind distinguishes between big-endian operations with | 
|  | 1176 | /// two different inputs (0), either-endian operations with two identical | 
| Bill Schmidt | 5ed84cd | 2015-05-16 01:02:12 +0000 | [diff] [blame] | 1177 | /// inputs (1), and little-endian operations with two different inputs (2). | 
| Ulrich Weigand | cc9909b | 2014-08-04 13:53:40 +0000 | [diff] [blame] | 1178 | /// For the latter, the input operands are swapped (see PPCInstrAltivec.td). | 
|  | 1179 | bool PPC::isVPKUWUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind, | 
| Bill Schmidt | f910a06 | 2014-06-10 14:35:01 +0000 | [diff] [blame] | 1180 | SelectionDAG &DAG) { | 
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 1181 | bool IsLE = DAG.getDataLayout().isLittleEndian(); | 
| Ulrich Weigand | cc9909b | 2014-08-04 13:53:40 +0000 | [diff] [blame] | 1182 | if (ShuffleKind == 0) { | 
| Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 1183 | if (IsLE) | 
| Ulrich Weigand | cc9909b | 2014-08-04 13:53:40 +0000 | [diff] [blame] | 1184 | return false; | 
| Chris Lattner | a4bbfae | 2006-04-06 22:28:36 +0000 | [diff] [blame] | 1185 | for (unsigned i = 0; i != 16; i += 2) | 
| Ulrich Weigand | cc9909b | 2014-08-04 13:53:40 +0000 | [diff] [blame] | 1186 | if (!isConstantOrUndef(N->getMaskElt(i  ),  i*2+2) || | 
|  | 1187 | !isConstantOrUndef(N->getMaskElt(i+1),  i*2+3)) | 
| Chris Lattner | a4bbfae | 2006-04-06 22:28:36 +0000 | [diff] [blame] | 1188 | return false; | 
| Ulrich Weigand | cc9909b | 2014-08-04 13:53:40 +0000 | [diff] [blame] | 1189 | } else if (ShuffleKind == 2) { | 
| Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 1190 | if (!IsLE) | 
| Ulrich Weigand | cc9909b | 2014-08-04 13:53:40 +0000 | [diff] [blame] | 1191 | return false; | 
|  | 1192 | for (unsigned i = 0; i != 16; i += 2) | 
|  | 1193 | if (!isConstantOrUndef(N->getMaskElt(i  ),  i*2) || | 
|  | 1194 | !isConstantOrUndef(N->getMaskElt(i+1),  i*2+1)) | 
|  | 1195 | return false; | 
|  | 1196 | } else if (ShuffleKind == 1) { | 
| Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 1197 | unsigned j = IsLE ? 0 : 2; | 
| Chris Lattner | a4bbfae | 2006-04-06 22:28:36 +0000 | [diff] [blame] | 1198 | for (unsigned i = 0; i != 8; i += 2) | 
| Ulrich Weigand | cc9909b | 2014-08-04 13:53:40 +0000 | [diff] [blame] | 1199 | if (!isConstantOrUndef(N->getMaskElt(i  ),  i*2+j)   || | 
|  | 1200 | !isConstantOrUndef(N->getMaskElt(i+1),  i*2+j+1) || | 
|  | 1201 | !isConstantOrUndef(N->getMaskElt(i+8),  i*2+j)   || | 
|  | 1202 | !isConstantOrUndef(N->getMaskElt(i+9),  i*2+j+1)) | 
| Chris Lattner | a4bbfae | 2006-04-06 22:28:36 +0000 | [diff] [blame] | 1203 | return false; | 
|  | 1204 | } | 
| Chris Lattner | 1d33819 | 2006-04-06 18:26:28 +0000 | [diff] [blame] | 1205 | return true; | 
| Chris Lattner | e8b83b4 | 2006-04-06 17:23:16 +0000 | [diff] [blame] | 1206 | } | 
|  | 1207 |  | 
| Bill Schmidt | 5ed84cd | 2015-05-16 01:02:12 +0000 | [diff] [blame] | 1208 | /// isVPKUDUMShuffleMask - Return true if this is the shuffle mask for a | 
| Bill Schmidt | e13ac91 | 2015-05-21 20:48:49 +0000 | [diff] [blame] | 1209 | /// VPKUDUM instruction, AND the VPKUDUM instruction exists for the | 
|  | 1210 | /// current subtarget. | 
|  | 1211 | /// | 
| Bill Schmidt | 5ed84cd | 2015-05-16 01:02:12 +0000 | [diff] [blame] | 1212 | /// The ShuffleKind distinguishes between big-endian operations with | 
|  | 1213 | /// two different inputs (0), either-endian operations with two identical | 
|  | 1214 | /// inputs (1), and little-endian operations with two different inputs (2). | 
|  | 1215 | /// For the latter, the input operands are swapped (see PPCInstrAltivec.td). | 
|  | 1216 | bool PPC::isVPKUDUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind, | 
|  | 1217 | SelectionDAG &DAG) { | 
| Bill Schmidt | e13ac91 | 2015-05-21 20:48:49 +0000 | [diff] [blame] | 1218 | const PPCSubtarget& Subtarget = | 
|  | 1219 | static_cast<const PPCSubtarget&>(DAG.getSubtarget()); | 
|  | 1220 | if (!Subtarget.hasP8Vector()) | 
|  | 1221 | return false; | 
|  | 1222 |  | 
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 1223 | bool IsLE = DAG.getDataLayout().isLittleEndian(); | 
| Bill Schmidt | 5ed84cd | 2015-05-16 01:02:12 +0000 | [diff] [blame] | 1224 | if (ShuffleKind == 0) { | 
|  | 1225 | if (IsLE) | 
|  | 1226 | return false; | 
|  | 1227 | for (unsigned i = 0; i != 16; i += 4) | 
|  | 1228 | if (!isConstantOrUndef(N->getMaskElt(i  ),  i*2+4) || | 
|  | 1229 | !isConstantOrUndef(N->getMaskElt(i+1),  i*2+5) || | 
|  | 1230 | !isConstantOrUndef(N->getMaskElt(i+2),  i*2+6) || | 
|  | 1231 | !isConstantOrUndef(N->getMaskElt(i+3),  i*2+7)) | 
|  | 1232 | return false; | 
|  | 1233 | } else if (ShuffleKind == 2) { | 
|  | 1234 | if (!IsLE) | 
|  | 1235 | return false; | 
|  | 1236 | for (unsigned i = 0; i != 16; i += 4) | 
|  | 1237 | if (!isConstantOrUndef(N->getMaskElt(i  ),  i*2) || | 
|  | 1238 | !isConstantOrUndef(N->getMaskElt(i+1),  i*2+1) || | 
|  | 1239 | !isConstantOrUndef(N->getMaskElt(i+2),  i*2+2) || | 
|  | 1240 | !isConstantOrUndef(N->getMaskElt(i+3),  i*2+3)) | 
|  | 1241 | return false; | 
|  | 1242 | } else if (ShuffleKind == 1) { | 
|  | 1243 | unsigned j = IsLE ? 0 : 4; | 
|  | 1244 | for (unsigned i = 0; i != 8; i += 4) | 
|  | 1245 | if (!isConstantOrUndef(N->getMaskElt(i  ),  i*2+j)   || | 
|  | 1246 | !isConstantOrUndef(N->getMaskElt(i+1),  i*2+j+1) || | 
|  | 1247 | !isConstantOrUndef(N->getMaskElt(i+2),  i*2+j+2) || | 
|  | 1248 | !isConstantOrUndef(N->getMaskElt(i+3),  i*2+j+3) || | 
|  | 1249 | !isConstantOrUndef(N->getMaskElt(i+8),  i*2+j)   || | 
|  | 1250 | !isConstantOrUndef(N->getMaskElt(i+9),  i*2+j+1) || | 
|  | 1251 | !isConstantOrUndef(N->getMaskElt(i+10), i*2+j+2) || | 
|  | 1252 | !isConstantOrUndef(N->getMaskElt(i+11), i*2+j+3)) | 
|  | 1253 | return false; | 
|  | 1254 | } | 
|  | 1255 | return true; | 
|  | 1256 | } | 
|  | 1257 |  | 
| Chris Lattner | f38e033 | 2006-04-06 22:02:42 +0000 | [diff] [blame] | 1258 | /// isVMerge - Common function, used to match vmrg* shuffles. | 
|  | 1259 | /// | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1260 | static bool isVMerge(ShuffleVectorSDNode *N, unsigned UnitSize, | 
| Chris Lattner | f38e033 | 2006-04-06 22:02:42 +0000 | [diff] [blame] | 1261 | unsigned LHSStart, unsigned RHSStart) { | 
| Hal Finkel | df3e34d | 2014-03-26 22:58:37 +0000 | [diff] [blame] | 1262 | if (N->getValueType(0) != MVT::v16i8) | 
|  | 1263 | return false; | 
| Chris Lattner | d1dcb52 | 2006-04-06 21:11:54 +0000 | [diff] [blame] | 1264 | assert((UnitSize == 1 || UnitSize == 2 || UnitSize == 4) && | 
|  | 1265 | "Unsupported merge size!"); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1266 |  | 
| Chris Lattner | d1dcb52 | 2006-04-06 21:11:54 +0000 | [diff] [blame] | 1267 | for (unsigned i = 0; i != 8/UnitSize; ++i)     // Step over units | 
|  | 1268 | for (unsigned j = 0; j != UnitSize; ++j) {   // Step over bytes within unit | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1269 | if (!isConstantOrUndef(N->getMaskElt(i*UnitSize*2+j), | 
| Chris Lattner | f38e033 | 2006-04-06 22:02:42 +0000 | [diff] [blame] | 1270 | LHSStart+j+i*UnitSize) || | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1271 | !isConstantOrUndef(N->getMaskElt(i*UnitSize*2+UnitSize+j), | 
| Chris Lattner | f38e033 | 2006-04-06 22:02:42 +0000 | [diff] [blame] | 1272 | RHSStart+j+i*UnitSize)) | 
| Chris Lattner | d1dcb52 | 2006-04-06 21:11:54 +0000 | [diff] [blame] | 1273 | return false; | 
|  | 1274 | } | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1275 | return true; | 
| Chris Lattner | f38e033 | 2006-04-06 22:02:42 +0000 | [diff] [blame] | 1276 | } | 
|  | 1277 |  | 
|  | 1278 | /// isVMRGLShuffleMask - Return true if this is a shuffle mask suitable for | 
| Bill Schmidt | f910a06 | 2014-06-10 14:35:01 +0000 | [diff] [blame] | 1279 | /// a VMRGL* instruction with the specified unit size (1,2 or 4 bytes). | 
| NAKAMURA Takumi | 8496503 | 2015-09-22 11:14:12 +0000 | [diff] [blame] | 1280 | /// The ShuffleKind distinguishes between big-endian merges with two | 
| Bill Schmidt | c9fa5dd | 2014-07-25 01:55:55 +0000 | [diff] [blame] | 1281 | /// different inputs (0), either-endian merges with two identical inputs (1), | 
|  | 1282 | /// and little-endian merges with two different inputs (2).  For the latter, | 
|  | 1283 | /// the input operands are swapped (see PPCInstrAltivec.td). | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1284 | bool PPC::isVMRGLShuffleMask(ShuffleVectorSDNode *N, unsigned UnitSize, | 
| Bill Schmidt | c9fa5dd | 2014-07-25 01:55:55 +0000 | [diff] [blame] | 1285 | unsigned ShuffleKind, SelectionDAG &DAG) { | 
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 1286 | if (DAG.getDataLayout().isLittleEndian()) { | 
| Bill Schmidt | c9fa5dd | 2014-07-25 01:55:55 +0000 | [diff] [blame] | 1287 | if (ShuffleKind == 1) // unary | 
|  | 1288 | return isVMerge(N, UnitSize, 0, 0); | 
|  | 1289 | else if (ShuffleKind == 2) // swapped | 
| Bill Schmidt | f910a06 | 2014-06-10 14:35:01 +0000 | [diff] [blame] | 1290 | return isVMerge(N, UnitSize, 0, 16); | 
| Bill Schmidt | c9fa5dd | 2014-07-25 01:55:55 +0000 | [diff] [blame] | 1291 | else | 
|  | 1292 | return false; | 
| Bill Schmidt | f910a06 | 2014-06-10 14:35:01 +0000 | [diff] [blame] | 1293 | } else { | 
| Bill Schmidt | c9fa5dd | 2014-07-25 01:55:55 +0000 | [diff] [blame] | 1294 | if (ShuffleKind == 1) // unary | 
|  | 1295 | return isVMerge(N, UnitSize, 8, 8); | 
|  | 1296 | else if (ShuffleKind == 0) // normal | 
| Bill Schmidt | f910a06 | 2014-06-10 14:35:01 +0000 | [diff] [blame] | 1297 | return isVMerge(N, UnitSize, 8, 24); | 
| Bill Schmidt | c9fa5dd | 2014-07-25 01:55:55 +0000 | [diff] [blame] | 1298 | else | 
|  | 1299 | return false; | 
| Bill Schmidt | f910a06 | 2014-06-10 14:35:01 +0000 | [diff] [blame] | 1300 | } | 
| Chris Lattner | d1dcb52 | 2006-04-06 21:11:54 +0000 | [diff] [blame] | 1301 | } | 
|  | 1302 |  | 
|  | 1303 | /// isVMRGHShuffleMask - Return true if this is a shuffle mask suitable for | 
| Bill Schmidt | f910a06 | 2014-06-10 14:35:01 +0000 | [diff] [blame] | 1304 | /// a VMRGH* instruction with the specified unit size (1,2 or 4 bytes). | 
| NAKAMURA Takumi | 8496503 | 2015-09-22 11:14:12 +0000 | [diff] [blame] | 1305 | /// The ShuffleKind distinguishes between big-endian merges with two | 
| Bill Schmidt | c9fa5dd | 2014-07-25 01:55:55 +0000 | [diff] [blame] | 1306 | /// different inputs (0), either-endian merges with two identical inputs (1), | 
|  | 1307 | /// and little-endian merges with two different inputs (2).  For the latter, | 
|  | 1308 | /// the input operands are swapped (see PPCInstrAltivec.td). | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1309 | bool PPC::isVMRGHShuffleMask(ShuffleVectorSDNode *N, unsigned UnitSize, | 
| Bill Schmidt | c9fa5dd | 2014-07-25 01:55:55 +0000 | [diff] [blame] | 1310 | unsigned ShuffleKind, SelectionDAG &DAG) { | 
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 1311 | if (DAG.getDataLayout().isLittleEndian()) { | 
| Bill Schmidt | c9fa5dd | 2014-07-25 01:55:55 +0000 | [diff] [blame] | 1312 | if (ShuffleKind == 1) // unary | 
|  | 1313 | return isVMerge(N, UnitSize, 8, 8); | 
|  | 1314 | else if (ShuffleKind == 2) // swapped | 
| Bill Schmidt | f910a06 | 2014-06-10 14:35:01 +0000 | [diff] [blame] | 1315 | return isVMerge(N, UnitSize, 8, 24); | 
| Bill Schmidt | c9fa5dd | 2014-07-25 01:55:55 +0000 | [diff] [blame] | 1316 | else | 
|  | 1317 | return false; | 
| Bill Schmidt | f910a06 | 2014-06-10 14:35:01 +0000 | [diff] [blame] | 1318 | } else { | 
| Bill Schmidt | c9fa5dd | 2014-07-25 01:55:55 +0000 | [diff] [blame] | 1319 | if (ShuffleKind == 1) // unary | 
|  | 1320 | return isVMerge(N, UnitSize, 0, 0); | 
|  | 1321 | else if (ShuffleKind == 0) // normal | 
| Bill Schmidt | f910a06 | 2014-06-10 14:35:01 +0000 | [diff] [blame] | 1322 | return isVMerge(N, UnitSize, 0, 16); | 
| Bill Schmidt | c9fa5dd | 2014-07-25 01:55:55 +0000 | [diff] [blame] | 1323 | else | 
|  | 1324 | return false; | 
| Bill Schmidt | f910a06 | 2014-06-10 14:35:01 +0000 | [diff] [blame] | 1325 | } | 
| Chris Lattner | d1dcb52 | 2006-04-06 21:11:54 +0000 | [diff] [blame] | 1326 | } | 
|  | 1327 |  | 
| Kit Barton | 13894c7 | 2015-06-25 15:17:40 +0000 | [diff] [blame] | 1328 | /** | 
|  | 1329 | * \brief Common function used to match vmrgew and vmrgow shuffles | 
|  | 1330 | * | 
|  | 1331 | * The indexOffset determines whether to look for even or odd words in | 
|  | 1332 | * the shuffle mask. This is based on the of the endianness of the target | 
|  | 1333 | * machine. | 
|  | 1334 | *   - Little Endian: | 
|  | 1335 | *     - Use offset of 0 to check for odd elements | 
|  | 1336 | *     - Use offset of 4 to check for even elements | 
|  | 1337 | *   - Big Endian: | 
|  | 1338 | *     - Use offset of 0 to check for even elements | 
|  | 1339 | *     - Use offset of 4 to check for odd elements | 
|  | 1340 | * A detailed description of the vector element ordering for little endian and | 
| NAKAMURA Takumi | 520b45d | 2015-06-25 23:38:44 +0000 | [diff] [blame] | 1341 | * big endian can be found at | 
|  | 1342 | * http://www.ibm.com/developerworks/library/l-ibm-xl-c-cpp-compiler/index.html | 
| Kit Barton | 13894c7 | 2015-06-25 15:17:40 +0000 | [diff] [blame] | 1343 | * Targeting your applications - what little endian and big endian IBM XL C/C++ | 
| NAKAMURA Takumi | 520b45d | 2015-06-25 23:38:44 +0000 | [diff] [blame] | 1344 | * compiler differences mean to you | 
| Kit Barton | 13894c7 | 2015-06-25 15:17:40 +0000 | [diff] [blame] | 1345 | * | 
|  | 1346 | * The mask to the shuffle vector instruction specifies the indices of the | 
|  | 1347 | * elements from the two input vectors to place in the result. The elements are | 
|  | 1348 | * numbered in array-access order, starting with the first vector. These vectors | 
|  | 1349 | * are always of type v16i8, thus each vector will contain 16 elements of size | 
| NAKAMURA Takumi | 520b45d | 2015-06-25 23:38:44 +0000 | [diff] [blame] | 1350 | * 8. More info on the shuffle vector can be found in the | 
|  | 1351 | * http://llvm.org/docs/LangRef.html#shufflevector-instruction | 
|  | 1352 | * Language Reference. | 
| Kit Barton | 13894c7 | 2015-06-25 15:17:40 +0000 | [diff] [blame] | 1353 | * | 
|  | 1354 | * The RHSStartValue indicates whether the same input vectors are used (unary) | 
|  | 1355 | * or two different input vectors are used, based on the following: | 
|  | 1356 | *   - If the instruction uses the same vector for both inputs, the range of the | 
|  | 1357 | *     indices will be 0 to 15. In this case, the RHSStart value passed should | 
|  | 1358 | *     be 0. | 
|  | 1359 | *   - If the instruction has two different vectors then the range of the | 
|  | 1360 | *     indices will be 0 to 31. In this case, the RHSStart value passed should | 
|  | 1361 | *     be 16 (indices 0-15 specify elements in the first vector while indices 16 | 
|  | 1362 | *     to 31 specify elements in the second vector). | 
|  | 1363 | * | 
|  | 1364 | * \param[in] N The shuffle vector SD Node to analyze | 
|  | 1365 | * \param[in] IndexOffset Specifies whether to look for even or odd elements | 
|  | 1366 | * \param[in] RHSStartValue Specifies the starting index for the righthand input | 
|  | 1367 | * vector to the shuffle_vector instruction | 
|  | 1368 | * \return true iff this shuffle vector represents an even or odd word merge | 
|  | 1369 | */ | 
|  | 1370 | static bool isVMerge(ShuffleVectorSDNode *N, unsigned IndexOffset, | 
|  | 1371 | unsigned RHSStartValue) { | 
|  | 1372 | if (N->getValueType(0) != MVT::v16i8) | 
|  | 1373 | return false; | 
|  | 1374 |  | 
|  | 1375 | for (unsigned i = 0; i < 2; ++i) | 
|  | 1376 | for (unsigned j = 0; j < 4; ++j) | 
|  | 1377 | if (!isConstantOrUndef(N->getMaskElt(i*4+j), | 
|  | 1378 | i*RHSStartValue+j+IndexOffset) || | 
|  | 1379 | !isConstantOrUndef(N->getMaskElt(i*4+j+8), | 
|  | 1380 | i*RHSStartValue+j+IndexOffset+8)) | 
|  | 1381 | return false; | 
|  | 1382 | return true; | 
|  | 1383 | } | 
|  | 1384 |  | 
|  | 1385 | /** | 
|  | 1386 | * \brief Determine if the specified shuffle mask is suitable for the vmrgew or | 
|  | 1387 | * vmrgow instructions. | 
|  | 1388 | * | 
|  | 1389 | * \param[in] N The shuffle vector SD Node to analyze | 
|  | 1390 | * \param[in] CheckEven Check for an even merge (true) or an odd merge (false) | 
|  | 1391 | * \param[in] ShuffleKind Identify the type of merge: | 
|  | 1392 | *   - 0 = big-endian merge with two different inputs; | 
|  | 1393 | *   - 1 = either-endian merge with two identical inputs; | 
|  | 1394 | *   - 2 = little-endian merge with two different inputs (inputs are swapped for | 
|  | 1395 | *     little-endian merges). | 
|  | 1396 | * \param[in] DAG The current SelectionDAG | 
| NAKAMURA Takumi | 8496503 | 2015-09-22 11:14:12 +0000 | [diff] [blame] | 1397 | * \return true iff this shuffle mask | 
| Kit Barton | 13894c7 | 2015-06-25 15:17:40 +0000 | [diff] [blame] | 1398 | */ | 
|  | 1399 | bool PPC::isVMRGEOShuffleMask(ShuffleVectorSDNode *N, bool CheckEven, | 
|  | 1400 | unsigned ShuffleKind, SelectionDAG &DAG) { | 
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 1401 | if (DAG.getDataLayout().isLittleEndian()) { | 
| Kit Barton | 13894c7 | 2015-06-25 15:17:40 +0000 | [diff] [blame] | 1402 | unsigned indexOffset = CheckEven ? 4 : 0; | 
|  | 1403 | if (ShuffleKind == 1) // Unary | 
|  | 1404 | return isVMerge(N, indexOffset, 0); | 
|  | 1405 | else if (ShuffleKind == 2) // swapped | 
|  | 1406 | return isVMerge(N, indexOffset, 16); | 
|  | 1407 | else | 
|  | 1408 | return false; | 
|  | 1409 | } | 
|  | 1410 | else { | 
|  | 1411 | unsigned indexOffset = CheckEven ? 0 : 4; | 
|  | 1412 | if (ShuffleKind == 1) // Unary | 
|  | 1413 | return isVMerge(N, indexOffset, 0); | 
|  | 1414 | else if (ShuffleKind == 0) // Normal | 
|  | 1415 | return isVMerge(N, indexOffset, 16); | 
|  | 1416 | else | 
|  | 1417 | return false; | 
|  | 1418 | } | 
|  | 1419 | return false; | 
|  | 1420 | } | 
| Chris Lattner | d1dcb52 | 2006-04-06 21:11:54 +0000 | [diff] [blame] | 1421 |  | 
| Chris Lattner | 1d33819 | 2006-04-06 18:26:28 +0000 | [diff] [blame] | 1422 | /// isVSLDOIShuffleMask - If this is a vsldoi shuffle mask, return the shift | 
|  | 1423 | /// amount, otherwise return -1. | 
| NAKAMURA Takumi | 8496503 | 2015-09-22 11:14:12 +0000 | [diff] [blame] | 1424 | /// The ShuffleKind distinguishes between big-endian operations with two | 
| Bill Schmidt | 42a6936 | 2014-08-05 20:47:25 +0000 | [diff] [blame] | 1425 | /// different inputs (0), either-endian operations with two identical inputs | 
|  | 1426 | /// (1), and little-endian operations with two different inputs (2).  For the | 
|  | 1427 | /// latter, the input operands are swapped (see PPCInstrAltivec.td). | 
|  | 1428 | int PPC::isVSLDOIShuffleMask(SDNode *N, unsigned ShuffleKind, | 
|  | 1429 | SelectionDAG &DAG) { | 
| Hal Finkel | df3e34d | 2014-03-26 22:58:37 +0000 | [diff] [blame] | 1430 | if (N->getValueType(0) != MVT::v16i8) | 
| Hal Finkel | a775e51 | 2014-04-08 19:00:27 +0000 | [diff] [blame] | 1431 | return -1; | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1432 |  | 
|  | 1433 | ShuffleVectorSDNode *SVOp = cast<ShuffleVectorSDNode>(N); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1434 |  | 
| Chris Lattner | 1d33819 | 2006-04-06 18:26:28 +0000 | [diff] [blame] | 1435 | // Find the first non-undef value in the shuffle mask. | 
|  | 1436 | unsigned i; | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1437 | for (i = 0; i != 16 && SVOp->getMaskElt(i) < 0; ++i) | 
| Chris Lattner | 1d33819 | 2006-04-06 18:26:28 +0000 | [diff] [blame] | 1438 | /*search*/; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1439 |  | 
| Chris Lattner | 1d33819 | 2006-04-06 18:26:28 +0000 | [diff] [blame] | 1440 | if (i == 16) return -1;  // all undef. | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1441 |  | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1442 | // Otherwise, check to see if the rest of the elements are consecutively | 
| Chris Lattner | 1d33819 | 2006-04-06 18:26:28 +0000 | [diff] [blame] | 1443 | // numbered from this value. | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1444 | unsigned ShiftAmt = SVOp->getMaskElt(i); | 
| Chris Lattner | 1d33819 | 2006-04-06 18:26:28 +0000 | [diff] [blame] | 1445 | if (ShiftAmt < i) return -1; | 
| Chris Lattner | e8b83b4 | 2006-04-06 17:23:16 +0000 | [diff] [blame] | 1446 |  | 
| Bill Schmidt | f04e998 | 2014-08-04 23:21:01 +0000 | [diff] [blame] | 1447 | ShiftAmt -= i; | 
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 1448 | bool isLE = DAG.getDataLayout().isLittleEndian(); | 
| Bill Schmidt | f910a06 | 2014-06-10 14:35:01 +0000 | [diff] [blame] | 1449 |  | 
| Bill Schmidt | 42a6936 | 2014-08-05 20:47:25 +0000 | [diff] [blame] | 1450 | if ((ShuffleKind == 0 && !isLE) || (ShuffleKind == 2 && isLE)) { | 
| Bill Schmidt | f04e998 | 2014-08-04 23:21:01 +0000 | [diff] [blame] | 1451 | // Check the rest of the elements to see if they are consecutive. | 
|  | 1452 | for (++i; i != 16; ++i) | 
|  | 1453 | if (!isConstantOrUndef(SVOp->getMaskElt(i), ShiftAmt+i)) | 
|  | 1454 | return -1; | 
| Bill Schmidt | 42a6936 | 2014-08-05 20:47:25 +0000 | [diff] [blame] | 1455 | } else if (ShuffleKind == 1) { | 
| Bill Schmidt | f04e998 | 2014-08-04 23:21:01 +0000 | [diff] [blame] | 1456 | // Check the rest of the elements to see if they are consecutive. | 
|  | 1457 | for (++i; i != 16; ++i) | 
|  | 1458 | if (!isConstantOrUndef(SVOp->getMaskElt(i), (ShiftAmt+i) & 15)) | 
|  | 1459 | return -1; | 
| Bill Schmidt | 42a6936 | 2014-08-05 20:47:25 +0000 | [diff] [blame] | 1460 | } else | 
|  | 1461 | return -1; | 
|  | 1462 |  | 
| Bill Schmidt | 1e77bb1 | 2015-07-15 15:45:30 +0000 | [diff] [blame] | 1463 | if (isLE) | 
| Bill Schmidt | 42a6936 | 2014-08-05 20:47:25 +0000 | [diff] [blame] | 1464 | ShiftAmt = 16 - ShiftAmt; | 
| Bill Schmidt | f04e998 | 2014-08-04 23:21:01 +0000 | [diff] [blame] | 1465 |  | 
| Chris Lattner | 1d33819 | 2006-04-06 18:26:28 +0000 | [diff] [blame] | 1466 | return ShiftAmt; | 
|  | 1467 | } | 
| Chris Lattner | ffc4756 | 2006-03-20 06:33:01 +0000 | [diff] [blame] | 1468 |  | 
|  | 1469 | /// isSplatShuffleMask - Return true if the specified VECTOR_SHUFFLE operand | 
|  | 1470 | /// specifies a splat of a single element that is suitable for input to | 
|  | 1471 | /// VSPLTB/VSPLTH/VSPLTW. | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1472 | bool PPC::isSplatShuffleMask(ShuffleVectorSDNode *N, unsigned EltSize) { | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1473 | assert(N->getValueType(0) == MVT::v16i8 && | 
| Chris Lattner | 95c7adc | 2006-04-04 17:25:31 +0000 | [diff] [blame] | 1474 | (EltSize == 1 || EltSize == 2 || EltSize == 4)); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1475 |  | 
| Bill Schmidt | 42ddd71 | 2015-07-29 14:31:57 +0000 | [diff] [blame] | 1476 | // The consecutive indices need to specify an element, not part of two | 
|  | 1477 | // different elements.  So abandon ship early if this isn't the case. | 
|  | 1478 | if (N->getMaskElt(0) % EltSize != 0) | 
|  | 1479 | return false; | 
|  | 1480 |  | 
| Chris Lattner | a8fbb6d | 2006-03-20 06:37:44 +0000 | [diff] [blame] | 1481 | // This is a splat operation if each element of the permute is the same, and | 
|  | 1482 | // if the value doesn't reference the second vector. | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1483 | unsigned ElementBase = N->getMaskElt(0); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1484 |  | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1485 | // FIXME: Handle UNDEF elements too! | 
|  | 1486 | if (ElementBase >= 16) | 
| Chris Lattner | 95c7adc | 2006-04-04 17:25:31 +0000 | [diff] [blame] | 1487 | return false; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1488 |  | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1489 | // Check that the indices are consecutive, in the case of a multi-byte element | 
|  | 1490 | // splatted with a v16i8 mask. | 
|  | 1491 | for (unsigned i = 1; i != EltSize; ++i) | 
|  | 1492 | if (N->getMaskElt(i) < 0 || N->getMaskElt(i) != (int)(i+ElementBase)) | 
| Chris Lattner | 95c7adc | 2006-04-04 17:25:31 +0000 | [diff] [blame] | 1493 | return false; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1494 |  | 
| Chris Lattner | 95c7adc | 2006-04-04 17:25:31 +0000 | [diff] [blame] | 1495 | for (unsigned i = EltSize, e = 16; i != e; i += EltSize) { | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1496 | if (N->getMaskElt(i) < 0) continue; | 
| Chris Lattner | 95c7adc | 2006-04-04 17:25:31 +0000 | [diff] [blame] | 1497 | for (unsigned j = 0; j != EltSize; ++j) | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1498 | if (N->getMaskElt(i+j) != N->getMaskElt(j)) | 
| Chris Lattner | 95c7adc | 2006-04-04 17:25:31 +0000 | [diff] [blame] | 1499 | return false; | 
| Chris Lattner | a8fbb6d | 2006-03-20 06:37:44 +0000 | [diff] [blame] | 1500 | } | 
| Chris Lattner | 95c7adc | 2006-04-04 17:25:31 +0000 | [diff] [blame] | 1501 | return true; | 
| Chris Lattner | ffc4756 | 2006-03-20 06:33:01 +0000 | [diff] [blame] | 1502 | } | 
|  | 1503 |  | 
| Nemanja Ivanovic | b43bb61 | 2016-07-12 21:00:10 +0000 | [diff] [blame] | 1504 | bool PPC::isXXINSERTWMask(ShuffleVectorSDNode *N, unsigned &ShiftElts, | 
|  | 1505 | unsigned &InsertAtByte, bool &Swap, bool IsLE) { | 
|  | 1506 |  | 
|  | 1507 | // Check that the mask is shuffling words | 
|  | 1508 | for (unsigned i = 0; i < 4; ++i) { | 
|  | 1509 | unsigned B0 = N->getMaskElt(i*4); | 
|  | 1510 | unsigned B1 = N->getMaskElt(i*4+1); | 
|  | 1511 | unsigned B2 = N->getMaskElt(i*4+2); | 
|  | 1512 | unsigned B3 = N->getMaskElt(i*4+3); | 
|  | 1513 | if (B0 % 4) | 
|  | 1514 | return false; | 
|  | 1515 | if (B1 != B0+1 || B2 != B1+1 || B3 != B2+1) | 
|  | 1516 | return false; | 
|  | 1517 | } | 
|  | 1518 |  | 
|  | 1519 | // Now we look at mask elements 0,4,8,12 | 
|  | 1520 | unsigned M0 = N->getMaskElt(0) / 4; | 
|  | 1521 | unsigned M1 = N->getMaskElt(4) / 4; | 
|  | 1522 | unsigned M2 = N->getMaskElt(8) / 4; | 
|  | 1523 | unsigned M3 = N->getMaskElt(12) / 4; | 
|  | 1524 | unsigned LittleEndianShifts[] = { 2, 1, 0, 3 }; | 
|  | 1525 | unsigned BigEndianShifts[] = { 3, 0, 1, 2 }; | 
|  | 1526 |  | 
|  | 1527 | // Below, let H and L be arbitrary elements of the shuffle mask | 
|  | 1528 | // where H is in the range [4,7] and L is in the range [0,3]. | 
|  | 1529 | // H, 1, 2, 3 or L, 5, 6, 7 | 
|  | 1530 | if ((M0 > 3 && M1 == 1 && M2 == 2 && M3 == 3) || | 
|  | 1531 | (M0 < 4 && M1 == 5 && M2 == 6 && M3 == 7)) { | 
|  | 1532 | ShiftElts = IsLE ? LittleEndianShifts[M0 & 0x3] : BigEndianShifts[M0 & 0x3]; | 
|  | 1533 | InsertAtByte = IsLE ? 12 : 0; | 
|  | 1534 | Swap = M0 < 4; | 
|  | 1535 | return true; | 
|  | 1536 | } | 
|  | 1537 | // 0, H, 2, 3 or 4, L, 6, 7 | 
|  | 1538 | if ((M1 > 3 && M0 == 0 && M2 == 2 && M3 == 3) || | 
|  | 1539 | (M1 < 4 && M0 == 4 && M2 == 6 && M3 == 7)) { | 
|  | 1540 | ShiftElts = IsLE ? LittleEndianShifts[M1 & 0x3] : BigEndianShifts[M1 & 0x3]; | 
|  | 1541 | InsertAtByte = IsLE ? 8 : 4; | 
|  | 1542 | Swap = M1 < 4; | 
|  | 1543 | return true; | 
|  | 1544 | } | 
|  | 1545 | // 0, 1, H, 3 or 4, 5, L, 7 | 
|  | 1546 | if ((M2 > 3 && M0 == 0 && M1 == 1 && M3 == 3) || | 
|  | 1547 | (M2 < 4 && M0 == 4 && M1 == 5 && M3 == 7)) { | 
|  | 1548 | ShiftElts = IsLE ? LittleEndianShifts[M2 & 0x3] : BigEndianShifts[M2 & 0x3]; | 
|  | 1549 | InsertAtByte = IsLE ? 4 : 8; | 
|  | 1550 | Swap = M2 < 4; | 
|  | 1551 | return true; | 
|  | 1552 | } | 
|  | 1553 | // 0, 1, 2, H or 4, 5, 6, L | 
|  | 1554 | if ((M3 > 3 && M0 == 0 && M1 == 1 && M2 == 2) || | 
|  | 1555 | (M3 < 4 && M0 == 4 && M1 == 5 && M2 == 6)) { | 
|  | 1556 | ShiftElts = IsLE ? LittleEndianShifts[M3 & 0x3] : BigEndianShifts[M3 & 0x3]; | 
|  | 1557 | InsertAtByte = IsLE ? 0 : 12; | 
|  | 1558 | Swap = M3 < 4; | 
|  | 1559 | return true; | 
|  | 1560 | } | 
|  | 1561 |  | 
|  | 1562 | // If both vector operands for the shuffle are the same vector, the mask will | 
|  | 1563 | // contain only elements from the first one and the second one will be undef. | 
|  | 1564 | if (N->getOperand(1).isUndef()) { | 
|  | 1565 | ShiftElts = 0; | 
|  | 1566 | Swap = true; | 
|  | 1567 | unsigned XXINSERTWSrcElem = IsLE ? 2 : 1; | 
|  | 1568 | if (M0 == XXINSERTWSrcElem && M1 == 1 && M2 == 2 && M3 == 3) { | 
|  | 1569 | InsertAtByte = IsLE ? 12 : 0; | 
|  | 1570 | return true; | 
|  | 1571 | } | 
|  | 1572 | if (M0 == 0 && M1 == XXINSERTWSrcElem && M2 == 2 && M3 == 3) { | 
|  | 1573 | InsertAtByte = IsLE ? 8 : 4; | 
|  | 1574 | return true; | 
|  | 1575 | } | 
|  | 1576 | if (M0 == 0 && M1 == 1 && M2 == XXINSERTWSrcElem && M3 == 3) { | 
|  | 1577 | InsertAtByte = IsLE ? 4 : 8; | 
|  | 1578 | return true; | 
|  | 1579 | } | 
|  | 1580 | if (M0 == 0 && M1 == 1 && M2 == 2 && M3 == XXINSERTWSrcElem) { | 
|  | 1581 | InsertAtByte = IsLE ? 0 : 12; | 
|  | 1582 | return true; | 
|  | 1583 | } | 
|  | 1584 | } | 
|  | 1585 |  | 
|  | 1586 | return false; | 
|  | 1587 | } | 
|  | 1588 |  | 
| Chris Lattner | ffc4756 | 2006-03-20 06:33:01 +0000 | [diff] [blame] | 1589 | /// getVSPLTImmediate - Return the appropriate VSPLT* immediate to splat the | 
|  | 1590 | /// specified isSplatShuffleMask VECTOR_SHUFFLE mask. | 
| Bill Schmidt | f910a06 | 2014-06-10 14:35:01 +0000 | [diff] [blame] | 1591 | unsigned PPC::getVSPLTImmediate(SDNode *N, unsigned EltSize, | 
|  | 1592 | SelectionDAG &DAG) { | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 1593 | ShuffleVectorSDNode *SVOp = cast<ShuffleVectorSDNode>(N); | 
|  | 1594 | assert(isSplatShuffleMask(SVOp, EltSize)); | 
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 1595 | if (DAG.getDataLayout().isLittleEndian()) | 
| Bill Schmidt | f910a06 | 2014-06-10 14:35:01 +0000 | [diff] [blame] | 1596 | return (16 / EltSize) - 1 - (SVOp->getMaskElt(0) / EltSize); | 
|  | 1597 | else | 
|  | 1598 | return SVOp->getMaskElt(0) / EltSize; | 
| Chris Lattner | ffc4756 | 2006-03-20 06:33:01 +0000 | [diff] [blame] | 1599 | } | 
|  | 1600 |  | 
| Chris Lattner | 74cf9ff | 2006-04-12 17:37:20 +0000 | [diff] [blame] | 1601 | /// get_VSPLTI_elt - If this is a build_vector of constants which can be formed | 
| Chris Lattner | d71a1f9 | 2006-04-08 06:46:53 +0000 | [diff] [blame] | 1602 | /// by using a vspltis[bhw] instruction of the specified element size, return | 
|  | 1603 | /// the constant being splatted.  The ByteSize field indicates the number of | 
|  | 1604 | /// bytes of each element [124] -> [bhw]. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1605 | SDValue PPC::get_VSPLTI_elt(SDNode *N, unsigned ByteSize, SelectionDAG &DAG) { | 
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1606 | SDValue OpVal(nullptr, 0); | 
| Chris Lattner | d9e80f4 | 2006-04-08 07:14:26 +0000 | [diff] [blame] | 1607 |  | 
|  | 1608 | // If ByteSize of the splat is bigger than the element size of the | 
|  | 1609 | // build_vector, then we have a case where we are checking for a splat where | 
|  | 1610 | // multiple elements of the buildvector are folded together into a single | 
|  | 1611 | // logical element of the splat (e.g. "vsplish 1" to splat {0,1}*8). | 
|  | 1612 | unsigned EltSize = 16/N->getNumOperands(); | 
|  | 1613 | if (EltSize < ByteSize) { | 
|  | 1614 | unsigned Multiple = ByteSize/EltSize;   // Number of BV entries per spltval. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1615 | SDValue UniquedVals[4]; | 
| Chris Lattner | d9e80f4 | 2006-04-08 07:14:26 +0000 | [diff] [blame] | 1616 | assert(Multiple > 1 && Multiple <= 4 && "How can this happen?"); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1617 |  | 
| Chris Lattner | d9e80f4 | 2006-04-08 07:14:26 +0000 | [diff] [blame] | 1618 | // See if all of the elements in the buildvector agree across. | 
|  | 1619 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { | 
| Sanjay Patel | 5719584 | 2016-03-14 17:28:46 +0000 | [diff] [blame] | 1620 | if (N->getOperand(i).isUndef()) continue; | 
| Chris Lattner | d9e80f4 | 2006-04-08 07:14:26 +0000 | [diff] [blame] | 1621 | // If the element isn't a constant, bail fully out. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1622 | if (!isa<ConstantSDNode>(N->getOperand(i))) return SDValue(); | 
| Chris Lattner | d9e80f4 | 2006-04-08 07:14:26 +0000 | [diff] [blame] | 1623 |  | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1624 |  | 
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1625 | if (!UniquedVals[i&(Multiple-1)].getNode()) | 
| Chris Lattner | d9e80f4 | 2006-04-08 07:14:26 +0000 | [diff] [blame] | 1626 | UniquedVals[i&(Multiple-1)] = N->getOperand(i); | 
|  | 1627 | else if (UniquedVals[i&(Multiple-1)] != N->getOperand(i)) | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1628 | return SDValue();  // no match. | 
| Chris Lattner | d9e80f4 | 2006-04-08 07:14:26 +0000 | [diff] [blame] | 1629 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1630 |  | 
| Chris Lattner | d9e80f4 | 2006-04-08 07:14:26 +0000 | [diff] [blame] | 1631 | // Okay, if we reached this point, UniquedVals[0..Multiple-1] contains | 
|  | 1632 | // either constant or undef values that are identical for each chunk.  See | 
|  | 1633 | // if these chunks can form into a larger vspltis*. | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1634 |  | 
| Chris Lattner | d9e80f4 | 2006-04-08 07:14:26 +0000 | [diff] [blame] | 1635 | // Check to see if all of the leading entries are either 0 or -1.  If | 
|  | 1636 | // neither, then this won't fit into the immediate field. | 
|  | 1637 | bool LeadingZero = true; | 
|  | 1638 | bool LeadingOnes = true; | 
|  | 1639 | for (unsigned i = 0; i != Multiple-1; ++i) { | 
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1640 | if (!UniquedVals[i].getNode()) continue;  // Must have been undefs. | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1641 |  | 
| Artyom Skrobov | 314ee04 | 2015-11-25 19:41:11 +0000 | [diff] [blame] | 1642 | LeadingZero &= isNullConstant(UniquedVals[i]); | 
|  | 1643 | LeadingOnes &= isAllOnesConstant(UniquedVals[i]); | 
| Chris Lattner | d9e80f4 | 2006-04-08 07:14:26 +0000 | [diff] [blame] | 1644 | } | 
|  | 1645 | // Finally, check the least significant entry. | 
|  | 1646 | if (LeadingZero) { | 
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1647 | if (!UniquedVals[Multiple-1].getNode()) | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1648 | return DAG.getTargetConstant(0, SDLoc(N), MVT::i32);  // 0,0,0,undef | 
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1649 | int Val = cast<ConstantSDNode>(UniquedVals[Multiple-1])->getZExtValue(); | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1650 | if (Val < 16)                                   // 0,0,0,4 -> vspltisw(4) | 
|  | 1651 | return DAG.getTargetConstant(Val, SDLoc(N), MVT::i32); | 
| Chris Lattner | d9e80f4 | 2006-04-08 07:14:26 +0000 | [diff] [blame] | 1652 | } | 
|  | 1653 | if (LeadingOnes) { | 
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1654 | if (!UniquedVals[Multiple-1].getNode()) | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1655 | return DAG.getTargetConstant(~0U, SDLoc(N), MVT::i32); // -1,-1,-1,undef | 
| Dan Gohman | 6e05483 | 2008-09-26 21:54:37 +0000 | [diff] [blame] | 1656 | int Val =cast<ConstantSDNode>(UniquedVals[Multiple-1])->getSExtValue(); | 
| Chris Lattner | d9e80f4 | 2006-04-08 07:14:26 +0000 | [diff] [blame] | 1657 | if (Val >= -16)                            // -1,-1,-1,-2 -> vspltisw(-2) | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1658 | return DAG.getTargetConstant(Val, SDLoc(N), MVT::i32); | 
| Chris Lattner | d9e80f4 | 2006-04-08 07:14:26 +0000 | [diff] [blame] | 1659 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1660 |  | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1661 | return SDValue(); | 
| Chris Lattner | d9e80f4 | 2006-04-08 07:14:26 +0000 | [diff] [blame] | 1662 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1663 |  | 
| Chris Lattner | 2771e2c | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 1664 | // Check to see if this buildvec has a single non-undef value in its elements. | 
|  | 1665 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { | 
| Sanjay Patel | 5719584 | 2016-03-14 17:28:46 +0000 | [diff] [blame] | 1666 | if (N->getOperand(i).isUndef()) continue; | 
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1667 | if (!OpVal.getNode()) | 
| Chris Lattner | 2771e2c | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 1668 | OpVal = N->getOperand(i); | 
|  | 1669 | else if (OpVal != N->getOperand(i)) | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1670 | return SDValue(); | 
| Chris Lattner | 2771e2c | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 1671 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1672 |  | 
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1673 | if (!OpVal.getNode()) return SDValue();  // All UNDEF: use implicit def. | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1674 |  | 
| Eli Friedman | 9c6ab1a | 2009-05-24 02:03:36 +0000 | [diff] [blame] | 1675 | unsigned ValSizeInBytes = EltSize; | 
| Nate Begeman | 1b39287 | 2006-03-28 04:15:58 +0000 | [diff] [blame] | 1676 | uint64_t Value = 0; | 
| Chris Lattner | 2771e2c | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 1677 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(OpVal)) { | 
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1678 | Value = CN->getZExtValue(); | 
| Chris Lattner | 2771e2c | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 1679 | } else if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(OpVal)) { | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1680 | assert(CN->getValueType(0) == MVT::f32 && "Only one legal FP vector type!"); | 
| Dale Johannesen | 3cf889f | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 1681 | Value = FloatToBits(CN->getValueAPF().convertToFloat()); | 
| Chris Lattner | 2771e2c | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 1682 | } | 
|  | 1683 |  | 
|  | 1684 | // If the splat value is larger than the element value, then we can never do | 
|  | 1685 | // this splat.  The only case that we could fit the replicated bits into our | 
|  | 1686 | // immediate field for would be zero, and we prefer to use vxor for it. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1687 | if (ValSizeInBytes < ByteSize) return SDValue(); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1688 |  | 
| Benjamin Kramer | b4b5150 | 2015-03-25 16:49:59 +0000 | [diff] [blame] | 1689 | // If the element value is larger than the splat value, check if it consists | 
|  | 1690 | // of a repeated bit pattern of size ByteSize. | 
|  | 1691 | if (!APInt(ValSizeInBytes * 8, Value).isSplat(ByteSize * 8)) | 
|  | 1692 | return SDValue(); | 
| Chris Lattner | 2771e2c | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 1693 |  | 
|  | 1694 | // Properly sign extend the value. | 
| Richard Smith | 228e6d4 | 2012-08-24 23:29:28 +0000 | [diff] [blame] | 1695 | int MaskVal = SignExtend32(Value, ByteSize * 8); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1696 |  | 
| Evan Cheng | b1ddc98 | 2006-03-26 09:52:32 +0000 | [diff] [blame] | 1697 | // If this is zero, don't match, zero matches ISD::isBuildVectorAllZeros. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1698 | if (MaskVal == 0) return SDValue(); | 
| Chris Lattner | 2771e2c | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 1699 |  | 
| Chris Lattner | d71a1f9 | 2006-04-08 06:46:53 +0000 | [diff] [blame] | 1700 | // Finally, if this value fits in a 5 bit sext field, return it | 
| Richard Smith | 228e6d4 | 2012-08-24 23:29:28 +0000 | [diff] [blame] | 1701 | if (SignExtend32<5>(MaskVal) == MaskVal) | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1702 | return DAG.getTargetConstant(MaskVal, SDLoc(N), MVT::i32); | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1703 | return SDValue(); | 
| Chris Lattner | 2771e2c | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 1704 | } | 
|  | 1705 |  | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 1706 | /// isQVALIGNIShuffleMask - If this is a qvaligni shuffle mask, return the shift | 
|  | 1707 | /// amount, otherwise return -1. | 
|  | 1708 | int PPC::isQVALIGNIShuffleMask(SDNode *N) { | 
|  | 1709 | EVT VT = N->getValueType(0); | 
|  | 1710 | if (VT != MVT::v4f64 && VT != MVT::v4f32 && VT != MVT::v4i1) | 
|  | 1711 | return -1; | 
|  | 1712 |  | 
|  | 1713 | ShuffleVectorSDNode *SVOp = cast<ShuffleVectorSDNode>(N); | 
|  | 1714 |  | 
|  | 1715 | // Find the first non-undef value in the shuffle mask. | 
|  | 1716 | unsigned i; | 
|  | 1717 | for (i = 0; i != 4 && SVOp->getMaskElt(i) < 0; ++i) | 
|  | 1718 | /*search*/; | 
|  | 1719 |  | 
|  | 1720 | if (i == 4) return -1;  // all undef. | 
|  | 1721 |  | 
|  | 1722 | // Otherwise, check to see if the rest of the elements are consecutively | 
|  | 1723 | // numbered from this value. | 
|  | 1724 | unsigned ShiftAmt = SVOp->getMaskElt(i); | 
|  | 1725 | if (ShiftAmt < i) return -1; | 
|  | 1726 | ShiftAmt -= i; | 
|  | 1727 |  | 
|  | 1728 | // Check the rest of the elements to see if they are consecutive. | 
|  | 1729 | for (++i; i != 4; ++i) | 
|  | 1730 | if (!isConstantOrUndef(SVOp->getMaskElt(i), ShiftAmt+i)) | 
|  | 1731 | return -1; | 
|  | 1732 |  | 
|  | 1733 | return ShiftAmt; | 
|  | 1734 | } | 
|  | 1735 |  | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 1736 | //===----------------------------------------------------------------------===// | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1737 | //  Addressing Mode Selection | 
|  | 1738 | //===----------------------------------------------------------------------===// | 
|  | 1739 |  | 
|  | 1740 | /// isIntS16Immediate - This method tests to see if the node is either a 32-bit | 
|  | 1741 | /// or 64-bit immediate, and if the value can be accurately represented as a | 
|  | 1742 | /// sign extension from a 16-bit value.  If so, this returns true and the | 
|  | 1743 | /// immediate. | 
|  | 1744 | static bool isIntS16Immediate(SDNode *N, short &Imm) { | 
| Adam Nemet | 571eb5f | 2014-05-20 17:20:34 +0000 | [diff] [blame] | 1745 | if (!isa<ConstantSDNode>(N)) | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1746 | return false; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1747 |  | 
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1748 | Imm = (short)cast<ConstantSDNode>(N)->getZExtValue(); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1749 | if (N->getValueType(0) == MVT::i32) | 
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1750 | return Imm == (int32_t)cast<ConstantSDNode>(N)->getZExtValue(); | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1751 | else | 
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1752 | return Imm == (int64_t)cast<ConstantSDNode>(N)->getZExtValue(); | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1753 | } | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1754 | static bool isIntS16Immediate(SDValue Op, short &Imm) { | 
| Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1755 | return isIntS16Immediate(Op.getNode(), Imm); | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1756 | } | 
|  | 1757 |  | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1758 | /// SelectAddressRegReg - Given the specified addressed, check to see if it | 
|  | 1759 | /// can be represented as an indexed [r+r] operation.  Returns false if it | 
|  | 1760 | /// can be more efficiently represented with [r+imm]. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1761 | bool PPCTargetLowering::SelectAddressRegReg(SDValue N, SDValue &Base, | 
|  | 1762 | SDValue &Index, | 
| Dan Gohman | 02b9313 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 1763 | SelectionDAG &DAG) const { | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1764 | short imm = 0; | 
|  | 1765 | if (N.getOpcode() == ISD::ADD) { | 
|  | 1766 | if (isIntS16Immediate(N.getOperand(1), imm)) | 
|  | 1767 | return false;    // r+i | 
|  | 1768 | if (N.getOperand(1).getOpcode() == PPCISD::Lo) | 
|  | 1769 | return false;    // r+i | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1770 |  | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1771 | Base = N.getOperand(0); | 
|  | 1772 | Index = N.getOperand(1); | 
|  | 1773 | return true; | 
|  | 1774 | } else if (N.getOpcode() == ISD::OR) { | 
|  | 1775 | if (isIntS16Immediate(N.getOperand(1), imm)) | 
|  | 1776 | return false;    // r+i can fold it if we can. | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1777 |  | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1778 | // If this is an or of disjoint bitfields, we can codegen this as an add | 
|  | 1779 | // (for better address arithmetic) if the LHS and RHS of the OR are provably | 
|  | 1780 | // disjoint. | 
| Dan Gohman | f19609a | 2008-02-27 01:23:58 +0000 | [diff] [blame] | 1781 | APInt LHSKnownZero, LHSKnownOne; | 
|  | 1782 | APInt RHSKnownZero, RHSKnownOne; | 
| Jay Foad | a0653a3 | 2014-05-14 21:14:37 +0000 | [diff] [blame] | 1783 | DAG.computeKnownBits(N.getOperand(0), | 
|  | 1784 | LHSKnownZero, LHSKnownOne); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1785 |  | 
| Dan Gohman | f19609a | 2008-02-27 01:23:58 +0000 | [diff] [blame] | 1786 | if (LHSKnownZero.getBoolValue()) { | 
| Jay Foad | a0653a3 | 2014-05-14 21:14:37 +0000 | [diff] [blame] | 1787 | DAG.computeKnownBits(N.getOperand(1), | 
|  | 1788 | RHSKnownZero, RHSKnownOne); | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1789 | // If all of the bits are known zero on the LHS or RHS, the add won't | 
|  | 1790 | // carry. | 
| Dan Gohman | 26854f2 | 2008-02-27 21:12:32 +0000 | [diff] [blame] | 1791 | if (~(LHSKnownZero | RHSKnownZero) == 0) { | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1792 | Base = N.getOperand(0); | 
|  | 1793 | Index = N.getOperand(1); | 
|  | 1794 | return true; | 
|  | 1795 | } | 
|  | 1796 | } | 
|  | 1797 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1798 |  | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1799 | return false; | 
|  | 1800 | } | 
|  | 1801 |  | 
| Hal Finkel | dbbf09b | 2013-07-09 06:34:51 +0000 | [diff] [blame] | 1802 | // If we happen to be doing an i64 load or store into a stack slot that has | 
|  | 1803 | // less than a 4-byte alignment, then the frame-index elimination may need to | 
|  | 1804 | // use an indexed load or store instruction (because the offset may not be a | 
|  | 1805 | // multiple of 4). The extra register needed to hold the offset comes from the | 
|  | 1806 | // register scavenger, and it is possible that the scavenger will need to use | 
|  | 1807 | // an emergency spill slot. As a result, we need to make sure that a spill slot | 
|  | 1808 | // is allocated when doing an i64 load/store into a less-than-4-byte-aligned | 
|  | 1809 | // stack slot. | 
|  | 1810 | static void fixupFuncForFI(SelectionDAG &DAG, int FrameIdx, EVT VT) { | 
|  | 1811 | // FIXME: This does not handle the LWA case. | 
|  | 1812 | if (VT != MVT::i64) | 
|  | 1813 | return; | 
|  | 1814 |  | 
| Hal Finkel | 7ab3db5 | 2013-07-10 15:29:01 +0000 | [diff] [blame] | 1815 | // NOTE: We'll exclude negative FIs here, which come from argument | 
|  | 1816 | // lowering, because there are no known test cases triggering this problem | 
|  | 1817 | // using packed structures (or similar). We can remove this exclusion if | 
|  | 1818 | // we find such a test case. The reason why this is so test-case driven is | 
|  | 1819 | // because this entire 'fixup' is only to prevent crashes (from the | 
|  | 1820 | // register scavenger) on not-really-valid inputs. For example, if we have: | 
|  | 1821 | //   %a = alloca i1 | 
|  | 1822 | //   %b = bitcast i1* %a to i64* | 
|  | 1823 | //   store i64* a, i64 b | 
|  | 1824 | // then the store should really be marked as 'align 1', but is not. If it | 
|  | 1825 | // were marked as 'align 1' then the indexed form would have been | 
|  | 1826 | // instruction-selected initially, and the problem this 'fixup' is preventing | 
|  | 1827 | // won't happen regardless. | 
| Hal Finkel | dbbf09b | 2013-07-09 06:34:51 +0000 | [diff] [blame] | 1828 | if (FrameIdx < 0) | 
|  | 1829 | return; | 
|  | 1830 |  | 
|  | 1831 | MachineFunction &MF = DAG.getMachineFunction(); | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 1832 | MachineFrameInfo &MFI = MF.getFrameInfo(); | 
| Hal Finkel | dbbf09b | 2013-07-09 06:34:51 +0000 | [diff] [blame] | 1833 |  | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 1834 | unsigned Align = MFI.getObjectAlignment(FrameIdx); | 
| Hal Finkel | dbbf09b | 2013-07-09 06:34:51 +0000 | [diff] [blame] | 1835 | if (Align >= 4) | 
|  | 1836 | return; | 
|  | 1837 |  | 
|  | 1838 | PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>(); | 
|  | 1839 | FuncInfo->setHasNonRISpills(); | 
|  | 1840 | } | 
|  | 1841 |  | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1842 | /// Returns true if the address N can be represented by a base register plus | 
|  | 1843 | /// a signed 16-bit displacement [r+imm], and if it is not better | 
| Ulrich Weigand | 9d980cb | 2013-05-16 17:58:02 +0000 | [diff] [blame] | 1844 | /// represented as reg+reg.  If Aligned is true, only accept displacements | 
|  | 1845 | /// suitable for STD and friends, i.e. multiples of 4. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1846 | bool PPCTargetLowering::SelectAddressRegImm(SDValue N, SDValue &Disp, | 
| Dan Gohman | 02b9313 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 1847 | SDValue &Base, | 
| Ulrich Weigand | 9d980cb | 2013-05-16 17:58:02 +0000 | [diff] [blame] | 1848 | SelectionDAG &DAG, | 
|  | 1849 | bool Aligned) const { | 
| Dale Johannesen | ab8e442 | 2009-02-06 19:16:40 +0000 | [diff] [blame] | 1850 | // FIXME dl should come from parent load or store, not from address | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1851 | SDLoc dl(N); | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1852 | // If this can be more profitably realized as r+r, fail. | 
|  | 1853 | if (SelectAddressRegReg(N, Disp, Base, DAG)) | 
|  | 1854 | return false; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1855 |  | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1856 | if (N.getOpcode() == ISD::ADD) { | 
|  | 1857 | short imm = 0; | 
| Ulrich Weigand | 9d980cb | 2013-05-16 17:58:02 +0000 | [diff] [blame] | 1858 | if (isIntS16Immediate(N.getOperand(1), imm) && | 
|  | 1859 | (!Aligned || (imm & 3) == 0)) { | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1860 | Disp = DAG.getTargetConstant(imm, dl, N.getValueType()); | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1861 | if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(N.getOperand(0))) { | 
|  | 1862 | Base = DAG.getTargetFrameIndex(FI->getIndex(), N.getValueType()); | 
| Hal Finkel | dbbf09b | 2013-07-09 06:34:51 +0000 | [diff] [blame] | 1863 | fixupFuncForFI(DAG, FI->getIndex(), N.getValueType()); | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1864 | } else { | 
|  | 1865 | Base = N.getOperand(0); | 
|  | 1866 | } | 
|  | 1867 | return true; // [r+i] | 
|  | 1868 | } else if (N.getOperand(1).getOpcode() == PPCISD::Lo) { | 
|  | 1869 | // Match LOAD (ADD (X, Lo(G))). | 
| Gabor Greif | c8a9abe | 2012-04-20 11:41:38 +0000 | [diff] [blame] | 1870 | assert(!cast<ConstantSDNode>(N.getOperand(1).getOperand(1))->getZExtValue() | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1871 | && "Cannot handle constant offsets yet!"); | 
|  | 1872 | Disp = N.getOperand(1).getOperand(0);  // The global address. | 
|  | 1873 | assert(Disp.getOpcode() == ISD::TargetGlobalAddress || | 
| Roman Divacky | e3f15c98 | 2012-06-04 17:36:38 +0000 | [diff] [blame] | 1874 | Disp.getOpcode() == ISD::TargetGlobalTLSAddress || | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1875 | Disp.getOpcode() == ISD::TargetConstantPool || | 
|  | 1876 | Disp.getOpcode() == ISD::TargetJumpTable); | 
|  | 1877 | Base = N.getOperand(0); | 
|  | 1878 | return true;  // [&g+r] | 
|  | 1879 | } | 
|  | 1880 | } else if (N.getOpcode() == ISD::OR) { | 
|  | 1881 | short imm = 0; | 
| Ulrich Weigand | 9d980cb | 2013-05-16 17:58:02 +0000 | [diff] [blame] | 1882 | if (isIntS16Immediate(N.getOperand(1), imm) && | 
|  | 1883 | (!Aligned || (imm & 3) == 0)) { | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1884 | // If this is an or of disjoint bitfields, we can codegen this as an add | 
|  | 1885 | // (for better address arithmetic) if the LHS and RHS of the OR are | 
|  | 1886 | // provably disjoint. | 
| Dan Gohman | f19609a | 2008-02-27 01:23:58 +0000 | [diff] [blame] | 1887 | APInt LHSKnownZero, LHSKnownOne; | 
| Jay Foad | a0653a3 | 2014-05-14 21:14:37 +0000 | [diff] [blame] | 1888 | DAG.computeKnownBits(N.getOperand(0), LHSKnownZero, LHSKnownOne); | 
| Bill Wendling | 6306183 | 2008-03-24 23:16:37 +0000 | [diff] [blame] | 1889 |  | 
| Dan Gohman | f19609a | 2008-02-27 01:23:58 +0000 | [diff] [blame] | 1890 | if ((LHSKnownZero.getZExtValue()|~(uint64_t)imm) == ~0ULL) { | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1891 | // If all of the bits are known zero on the LHS or RHS, the add won't | 
|  | 1892 | // carry. | 
| Ulrich Weigand | 55a9665 | 2014-07-20 22:26:40 +0000 | [diff] [blame] | 1893 | if (FrameIndexSDNode *FI = | 
|  | 1894 | dyn_cast<FrameIndexSDNode>(N.getOperand(0))) { | 
|  | 1895 | Base = DAG.getTargetFrameIndex(FI->getIndex(), N.getValueType()); | 
|  | 1896 | fixupFuncForFI(DAG, FI->getIndex(), N.getValueType()); | 
|  | 1897 | } else { | 
|  | 1898 | Base = N.getOperand(0); | 
|  | 1899 | } | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1900 | Disp = DAG.getTargetConstant(imm, dl, N.getValueType()); | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1901 | return true; | 
|  | 1902 | } | 
|  | 1903 | } | 
|  | 1904 | } else if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N)) { | 
|  | 1905 | // Loading from a constant address. | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1906 |  | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1907 | // If this address fits entirely in a 16-bit sext immediate field, codegen | 
|  | 1908 | // this as "d, 0" | 
|  | 1909 | short Imm; | 
| Ulrich Weigand | 9d980cb | 2013-05-16 17:58:02 +0000 | [diff] [blame] | 1910 | if (isIntS16Immediate(CN, Imm) && (!Aligned || (Imm & 3) == 0)) { | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1911 | Disp = DAG.getTargetConstant(Imm, dl, CN->getValueType(0)); | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 1912 | Base = DAG.getRegister(Subtarget.isPPC64() ? PPC::ZERO8 : PPC::ZERO, | 
| Hal Finkel | f70c41e | 2013-03-21 23:45:03 +0000 | [diff] [blame] | 1913 | CN->getValueType(0)); | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1914 | return true; | 
|  | 1915 | } | 
| Chris Lattner | 4a9c0bb | 2007-02-17 06:44:03 +0000 | [diff] [blame] | 1916 |  | 
|  | 1917 | // Handle 32-bit sext immediates with LIS + addr mode. | 
| Ulrich Weigand | 9d980cb | 2013-05-16 17:58:02 +0000 | [diff] [blame] | 1918 | if ((CN->getValueType(0) == MVT::i32 || | 
|  | 1919 | (int64_t)CN->getZExtValue() == (int)CN->getZExtValue()) && | 
|  | 1920 | (!Aligned || (CN->getZExtValue() & 3) == 0)) { | 
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1921 | int Addr = (int)CN->getZExtValue(); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1922 |  | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1923 | // Otherwise, break this down into an LIS + disp. | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1924 | Disp = DAG.getTargetConstant((short)Addr, dl, MVT::i32); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1925 |  | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1926 | Base = DAG.getTargetConstant((Addr - (signed short)Addr) >> 16, dl, | 
|  | 1927 | MVT::i32); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1928 | unsigned Opc = CN->getValueType(0) == MVT::i32 ? PPC::LIS : PPC::LIS8; | 
| Dan Gohman | 32f71d7 | 2009-09-25 18:54:59 +0000 | [diff] [blame] | 1929 | Base = SDValue(DAG.getMachineNode(Opc, dl, CN->getValueType(0), Base), 0); | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1930 | return true; | 
|  | 1931 | } | 
|  | 1932 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1933 |  | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1934 | Disp = DAG.getTargetConstant(0, dl, getPointerTy(DAG.getDataLayout())); | 
| Hal Finkel | dbbf09b | 2013-07-09 06:34:51 +0000 | [diff] [blame] | 1935 | if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(N)) { | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1936 | Base = DAG.getTargetFrameIndex(FI->getIndex(), N.getValueType()); | 
| Hal Finkel | dbbf09b | 2013-07-09 06:34:51 +0000 | [diff] [blame] | 1937 | fixupFuncForFI(DAG, FI->getIndex(), N.getValueType()); | 
|  | 1938 | } else | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1939 | Base = N; | 
|  | 1940 | return true;      // [r+0] | 
|  | 1941 | } | 
|  | 1942 |  | 
|  | 1943 | /// SelectAddressRegRegOnly - Given the specified addressed, force it to be | 
|  | 1944 | /// represented as an indexed [r+r] operation. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1945 | bool PPCTargetLowering::SelectAddressRegRegOnly(SDValue N, SDValue &Base, | 
|  | 1946 | SDValue &Index, | 
| Dan Gohman | 02b9313 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 1947 | SelectionDAG &DAG) const { | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1948 | // Check to see if we can easily represent this as an [r+r] address.  This | 
|  | 1949 | // will fail if it thinks that the address is more profitably represented as | 
|  | 1950 | // reg+imm, e.g. where imm = 0. | 
|  | 1951 | if (SelectAddressRegReg(N, Base, Index, DAG)) | 
|  | 1952 | return true; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1953 |  | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1954 | // If the operand is an addition, always emit this as [r+r], since this is | 
|  | 1955 | // better (for code size, and execution, as the memop does the add for free) | 
|  | 1956 | // than emitting an explicit add. | 
|  | 1957 | if (N.getOpcode() == ISD::ADD) { | 
|  | 1958 | Base = N.getOperand(0); | 
|  | 1959 | Index = N.getOperand(1); | 
|  | 1960 | return true; | 
|  | 1961 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1962 |  | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1963 | // Otherwise, do it the hard way, using R0 as the base register. | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 1964 | Base = DAG.getRegister(Subtarget.isPPC64() ? PPC::ZERO8 : PPC::ZERO, | 
| Hal Finkel | f70c41e | 2013-03-21 23:45:03 +0000 | [diff] [blame] | 1965 | N.getValueType()); | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1966 | Index = N; | 
|  | 1967 | return true; | 
|  | 1968 | } | 
|  | 1969 |  | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1970 | /// getPreIndexedAddressParts - returns true by value, base pointer and | 
|  | 1971 | /// offset pointer and addressing mode by reference if the node's address | 
|  | 1972 | /// can be legally represented as pre-indexed load / store address. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1973 | bool PPCTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base, | 
|  | 1974 | SDValue &Offset, | 
| Evan Cheng | b150007 | 2006-11-09 17:55:04 +0000 | [diff] [blame] | 1975 | ISD::MemIndexedMode &AM, | 
| Dan Gohman | 02b9313 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 1976 | SelectionDAG &DAG) const { | 
| Hal Finkel | 595817e | 2012-06-04 02:21:00 +0000 | [diff] [blame] | 1977 | if (DisablePPCPreinc) return false; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 1978 |  | 
| Ulrich Weigand | e90b022 | 2013-03-22 14:58:48 +0000 | [diff] [blame] | 1979 | bool isLoad = true; | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1980 | SDValue Ptr; | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1981 | EVT VT; | 
| Hal Finkel | b09680b | 2013-03-18 23:00:58 +0000 | [diff] [blame] | 1982 | unsigned Alignment; | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1983 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { | 
|  | 1984 | Ptr = LD->getBasePtr(); | 
| Dan Gohman | 47a7d6f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 1985 | VT = LD->getMemoryVT(); | 
| Hal Finkel | b09680b | 2013-03-18 23:00:58 +0000 | [diff] [blame] | 1986 | Alignment = LD->getAlignment(); | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1987 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { | 
| Chris Lattner | 6837125 | 2006-11-14 01:38:31 +0000 | [diff] [blame] | 1988 | Ptr = ST->getBasePtr(); | 
| Dan Gohman | 47a7d6f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 1989 | VT  = ST->getMemoryVT(); | 
| Hal Finkel | b09680b | 2013-03-18 23:00:58 +0000 | [diff] [blame] | 1990 | Alignment = ST->getAlignment(); | 
| Ulrich Weigand | e90b022 | 2013-03-22 14:58:48 +0000 | [diff] [blame] | 1991 | isLoad = false; | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 1992 | } else | 
|  | 1993 | return false; | 
|  | 1994 |  | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 1995 | // PowerPC doesn't have preinc load/store instructions for vectors (except | 
|  | 1996 | // for QPX, which does have preinc r+r forms). | 
|  | 1997 | if (VT.isVector()) { | 
|  | 1998 | if (!Subtarget.hasQPX() || (VT != MVT::v4f64 && VT != MVT::v4f32)) { | 
|  | 1999 | return false; | 
|  | 2000 | } else if (SelectAddressRegRegOnly(Ptr, Offset, Base, DAG)) { | 
|  | 2001 | AM = ISD::PRE_INC; | 
|  | 2002 | return true; | 
|  | 2003 | } | 
|  | 2004 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2005 |  | 
| Ulrich Weigand | e90b022 | 2013-03-22 14:58:48 +0000 | [diff] [blame] | 2006 | if (SelectAddressRegReg(Ptr, Base, Offset, DAG)) { | 
|  | 2007 |  | 
|  | 2008 | // Common code will reject creating a pre-inc form if the base pointer | 
|  | 2009 | // is a frame index, or if N is a store and the base pointer is either | 
|  | 2010 | // the same as or a predecessor of the value being stored.  Check for | 
|  | 2011 | // those situations here, and try with swapped Base/Offset instead. | 
|  | 2012 | bool Swap = false; | 
|  | 2013 |  | 
|  | 2014 | if (isa<FrameIndexSDNode>(Base) || isa<RegisterSDNode>(Base)) | 
|  | 2015 | Swap = true; | 
|  | 2016 | else if (!isLoad) { | 
|  | 2017 | SDValue Val = cast<StoreSDNode>(N)->getValue(); | 
|  | 2018 | if (Val == Base || Base.getNode()->isPredecessorOf(Val.getNode())) | 
|  | 2019 | Swap = true; | 
|  | 2020 | } | 
|  | 2021 |  | 
|  | 2022 | if (Swap) | 
|  | 2023 | std::swap(Base, Offset); | 
|  | 2024 |  | 
| Hal Finkel | ca542be | 2012-06-20 15:43:03 +0000 | [diff] [blame] | 2025 | AM = ISD::PRE_INC; | 
|  | 2026 | return true; | 
| Hal Finkel | 1cc27e4 | 2012-06-19 02:34:32 +0000 | [diff] [blame] | 2027 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2028 |  | 
| Ulrich Weigand | 9d980cb | 2013-05-16 17:58:02 +0000 | [diff] [blame] | 2029 | // LDU/STU can only handle immediates that are a multiple of 4. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2030 | if (VT != MVT::i64) { | 
| Ulrich Weigand | 9d980cb | 2013-05-16 17:58:02 +0000 | [diff] [blame] | 2031 | if (!SelectAddressRegImm(Ptr, Offset, Base, DAG, false)) | 
| Chris Lattner | 474b5b7 | 2006-11-15 19:55:13 +0000 | [diff] [blame] | 2032 | return false; | 
|  | 2033 | } else { | 
| Hal Finkel | b09680b | 2013-03-18 23:00:58 +0000 | [diff] [blame] | 2034 | // LDU/STU need an address with at least 4-byte alignment. | 
|  | 2035 | if (Alignment < 4) | 
|  | 2036 | return false; | 
|  | 2037 |  | 
| Ulrich Weigand | 9d980cb | 2013-05-16 17:58:02 +0000 | [diff] [blame] | 2038 | if (!SelectAddressRegImm(Ptr, Offset, Base, DAG, true)) | 
| Chris Lattner | 474b5b7 | 2006-11-15 19:55:13 +0000 | [diff] [blame] | 2039 | return false; | 
|  | 2040 | } | 
| Chris Lattner | b314b15 | 2006-11-11 00:08:42 +0000 | [diff] [blame] | 2041 |  | 
| Chris Lattner | b314b15 | 2006-11-11 00:08:42 +0000 | [diff] [blame] | 2042 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { | 
| Chris Lattner | 474b5b7 | 2006-11-15 19:55:13 +0000 | [diff] [blame] | 2043 | // PPC64 doesn't have lwau, but it does have lwaux.  Reject preinc load of | 
|  | 2044 | // sext i32 to i64 when addr mode is r+i. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2045 | if (LD->getValueType(0) == MVT::i64 && LD->getMemoryVT() == MVT::i32 && | 
| Chris Lattner | b314b15 | 2006-11-11 00:08:42 +0000 | [diff] [blame] | 2046 | LD->getExtensionType() == ISD::SEXTLOAD && | 
|  | 2047 | isa<ConstantSDNode>(Offset)) | 
|  | 2048 | return false; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2049 | } | 
|  | 2050 |  | 
| Chris Lattner | ce64554 | 2006-11-10 02:08:47 +0000 | [diff] [blame] | 2051 | AM = ISD::PRE_INC; | 
|  | 2052 | return true; | 
| Chris Lattner | a801fced | 2006-11-08 02:15:41 +0000 | [diff] [blame] | 2053 | } | 
|  | 2054 |  | 
|  | 2055 | //===----------------------------------------------------------------------===// | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 2056 | //  LowerOperation implementation | 
|  | 2057 | //===----------------------------------------------------------------------===// | 
|  | 2058 |  | 
| Rafael Espindola | e1d255f | 2016-06-27 12:56:02 +0000 | [diff] [blame] | 2059 | /// Return true if we should reference labels using a PICBase, set the HiOpFlags | 
|  | 2060 | /// and LoOpFlags to the target MO flags. | 
|  | 2061 | static void getLabelAccessInfo(bool IsPIC, const PPCSubtarget &Subtarget, | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 2062 | unsigned &HiOpFlags, unsigned &LoOpFlags, | 
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 2063 | const GlobalValue *GV = nullptr) { | 
| Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 2064 | HiOpFlags = PPCII::MO_HA; | 
|  | 2065 | LoOpFlags = PPCII::MO_LO; | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2066 |  | 
| Hal Finkel | 3ee2af7 | 2014-07-18 23:29:49 +0000 | [diff] [blame] | 2067 | // Don't use the pic base if not in PIC relocation model. | 
| Rafael Espindola | e1d255f | 2016-06-27 12:56:02 +0000 | [diff] [blame] | 2068 | if (IsPIC) { | 
| Chris Lattner | dd6df84 | 2010-11-15 03:13:19 +0000 | [diff] [blame] | 2069 | HiOpFlags |= PPCII::MO_PIC_FLAG; | 
|  | 2070 | LoOpFlags |= PPCII::MO_PIC_FLAG; | 
|  | 2071 | } | 
|  | 2072 |  | 
|  | 2073 | // If this is a reference to a global value that requires a non-lazy-ptr, make | 
|  | 2074 | // sure that instruction lowering adds it. | 
| Eric Christopher | e8dbfe1 | 2015-02-13 22:23:04 +0000 | [diff] [blame] | 2075 | if (GV && Subtarget.hasLazyResolverStub(GV)) { | 
| Chris Lattner | dd6df84 | 2010-11-15 03:13:19 +0000 | [diff] [blame] | 2076 | HiOpFlags |= PPCII::MO_NLP_FLAG; | 
|  | 2077 | LoOpFlags |= PPCII::MO_NLP_FLAG; | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2078 |  | 
| Chris Lattner | dd6df84 | 2010-11-15 03:13:19 +0000 | [diff] [blame] | 2079 | if (GV->hasHiddenVisibility()) { | 
|  | 2080 | HiOpFlags |= PPCII::MO_NLP_HIDDEN_FLAG; | 
|  | 2081 | LoOpFlags |= PPCII::MO_NLP_HIDDEN_FLAG; | 
|  | 2082 | } | 
|  | 2083 | } | 
| Chris Lattner | edb9d84 | 2010-11-15 02:46:57 +0000 | [diff] [blame] | 2084 | } | 
|  | 2085 |  | 
|  | 2086 | static SDValue LowerLabelRef(SDValue HiPart, SDValue LoPart, bool isPIC, | 
|  | 2087 | SelectionDAG &DAG) { | 
| Daniel Jasper | 48e93f7 | 2015-04-28 13:38:35 +0000 | [diff] [blame] | 2088 | SDLoc DL(HiPart); | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2089 | EVT PtrVT = HiPart.getValueType(); | 
|  | 2090 | SDValue Zero = DAG.getConstant(0, DL, PtrVT); | 
| Chris Lattner | edb9d84 | 2010-11-15 02:46:57 +0000 | [diff] [blame] | 2091 |  | 
|  | 2092 | SDValue Hi = DAG.getNode(PPCISD::Hi, DL, PtrVT, HiPart, Zero); | 
|  | 2093 | SDValue Lo = DAG.getNode(PPCISD::Lo, DL, PtrVT, LoPart, Zero); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2094 |  | 
| Chris Lattner | edb9d84 | 2010-11-15 02:46:57 +0000 | [diff] [blame] | 2095 | // With PIC, the first instruction is actually "GR+hi(&G)". | 
|  | 2096 | if (isPIC) | 
|  | 2097 | Hi = DAG.getNode(ISD::ADD, DL, PtrVT, | 
|  | 2098 | DAG.getNode(PPCISD::GlobalBaseReg, DL, PtrVT), Hi); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2099 |  | 
| Chris Lattner | edb9d84 | 2010-11-15 02:46:57 +0000 | [diff] [blame] | 2100 | // Generate non-pic code that has direct accesses to the constant pool. | 
|  | 2101 | // The address of the global is just (hi(&g)+lo(&g)). | 
|  | 2102 | return DAG.getNode(ISD::ADD, DL, PtrVT, Hi, Lo); | 
|  | 2103 | } | 
|  | 2104 |  | 
| Hal Finkel | e6698d5 | 2015-02-01 15:03:28 +0000 | [diff] [blame] | 2105 | static void setUsesTOCBasePtr(MachineFunction &MF) { | 
|  | 2106 | PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>(); | 
|  | 2107 | FuncInfo->setUsesTOCBasePtr(); | 
|  | 2108 | } | 
|  | 2109 |  | 
|  | 2110 | static void setUsesTOCBasePtr(SelectionDAG &DAG) { | 
|  | 2111 | setUsesTOCBasePtr(DAG.getMachineFunction()); | 
|  | 2112 | } | 
|  | 2113 |  | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 2114 | static SDValue getTOCEntry(SelectionDAG &DAG, const SDLoc &dl, bool Is64Bit, | 
| Hal Finkel | cf59921 | 2015-02-25 21:36:59 +0000 | [diff] [blame] | 2115 | SDValue GA) { | 
|  | 2116 | EVT VT = Is64Bit ? MVT::i64 : MVT::i32; | 
|  | 2117 | SDValue Reg = Is64Bit ? DAG.getRegister(PPC::X2, VT) : | 
|  | 2118 | DAG.getNode(PPCISD::GlobalBaseReg, dl, VT); | 
|  | 2119 |  | 
|  | 2120 | SDValue Ops[] = { GA, Reg }; | 
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2121 | return DAG.getMemIntrinsicNode( | 
|  | 2122 | PPCISD::TOC_ENTRY, dl, DAG.getVTList(VT, MVT::Other), Ops, VT, | 
|  | 2123 | MachinePointerInfo::getGOT(DAG.getMachineFunction()), 0, false, true, | 
|  | 2124 | false, 0); | 
| Hal Finkel | cf59921 | 2015-02-25 21:36:59 +0000 | [diff] [blame] | 2125 | } | 
|  | 2126 |  | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2127 | SDValue PPCTargetLowering::LowerConstantPool(SDValue Op, | 
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2128 | SelectionDAG &DAG) const { | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2129 | EVT PtrVT = Op.getValueType(); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 2130 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); | 
| Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2131 | const Constant *C = CP->getConstVal(); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 2132 |  | 
| Roman Divacky | ace4707 | 2012-08-24 16:26:02 +0000 | [diff] [blame] | 2133 | // 64-bit SVR4 ABI code is always position-independent. | 
|  | 2134 | // The actual address of the GlobalValue is stored in the TOC. | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 2135 | if (Subtarget.isSVR4ABI() && Subtarget.isPPC64()) { | 
| Hal Finkel | e6698d5 | 2015-02-01 15:03:28 +0000 | [diff] [blame] | 2136 | setUsesTOCBasePtr(DAG); | 
| Roman Divacky | ace4707 | 2012-08-24 16:26:02 +0000 | [diff] [blame] | 2137 | SDValue GA = DAG.getTargetConstantPool(C, PtrVT, CP->getAlignment(), 0); | 
| Hal Finkel | cf59921 | 2015-02-25 21:36:59 +0000 | [diff] [blame] | 2138 | return getTOCEntry(DAG, SDLoc(CP), true, GA); | 
| Roman Divacky | ace4707 | 2012-08-24 16:26:02 +0000 | [diff] [blame] | 2139 | } | 
|  | 2140 |  | 
| Chris Lattner | edb9d84 | 2010-11-15 02:46:57 +0000 | [diff] [blame] | 2141 | unsigned MOHiFlag, MOLoFlag; | 
| Rafael Espindola | e1d255f | 2016-06-27 12:56:02 +0000 | [diff] [blame] | 2142 | bool IsPIC = isPositionIndependent(); | 
|  | 2143 | getLabelAccessInfo(IsPIC, Subtarget, MOHiFlag, MOLoFlag); | 
| Hal Finkel | 3ee2af7 | 2014-07-18 23:29:49 +0000 | [diff] [blame] | 2144 |  | 
| Rafael Espindola | e1d255f | 2016-06-27 12:56:02 +0000 | [diff] [blame] | 2145 | if (IsPIC && Subtarget.isSVR4ABI()) { | 
| Hal Finkel | 3ee2af7 | 2014-07-18 23:29:49 +0000 | [diff] [blame] | 2146 | SDValue GA = DAG.getTargetConstantPool(C, PtrVT, CP->getAlignment(), | 
|  | 2147 | PPCII::MO_PIC_FLAG); | 
| Hal Finkel | cf59921 | 2015-02-25 21:36:59 +0000 | [diff] [blame] | 2148 | return getTOCEntry(DAG, SDLoc(CP), false, GA); | 
| Hal Finkel | 3ee2af7 | 2014-07-18 23:29:49 +0000 | [diff] [blame] | 2149 | } | 
|  | 2150 |  | 
| Chris Lattner | edb9d84 | 2010-11-15 02:46:57 +0000 | [diff] [blame] | 2151 | SDValue CPIHi = | 
|  | 2152 | DAG.getTargetConstantPool(C, PtrVT, CP->getAlignment(), 0, MOHiFlag); | 
|  | 2153 | SDValue CPILo = | 
|  | 2154 | DAG.getTargetConstantPool(C, PtrVT, CP->getAlignment(), 0, MOLoFlag); | 
| Rafael Espindola | e1d255f | 2016-06-27 12:56:02 +0000 | [diff] [blame] | 2155 | return LowerLabelRef(CPIHi, CPILo, IsPIC, DAG); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 2156 | } | 
|  | 2157 |  | 
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2158 | SDValue PPCTargetLowering::LowerJumpTable(SDValue Op, SelectionDAG &DAG) const { | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2159 | EVT PtrVT = Op.getValueType(); | 
| Nate Begeman | 4ca2ea5 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 2160 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Op); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2161 |  | 
| Roman Divacky | ace4707 | 2012-08-24 16:26:02 +0000 | [diff] [blame] | 2162 | // 64-bit SVR4 ABI code is always position-independent. | 
|  | 2163 | // The actual address of the GlobalValue is stored in the TOC. | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 2164 | if (Subtarget.isSVR4ABI() && Subtarget.isPPC64()) { | 
| Hal Finkel | e6698d5 | 2015-02-01 15:03:28 +0000 | [diff] [blame] | 2165 | setUsesTOCBasePtr(DAG); | 
| Roman Divacky | ace4707 | 2012-08-24 16:26:02 +0000 | [diff] [blame] | 2166 | SDValue GA = DAG.getTargetJumpTable(JT->getIndex(), PtrVT); | 
| Hal Finkel | cf59921 | 2015-02-25 21:36:59 +0000 | [diff] [blame] | 2167 | return getTOCEntry(DAG, SDLoc(JT), true, GA); | 
| Roman Divacky | ace4707 | 2012-08-24 16:26:02 +0000 | [diff] [blame] | 2168 | } | 
|  | 2169 |  | 
| Chris Lattner | edb9d84 | 2010-11-15 02:46:57 +0000 | [diff] [blame] | 2170 | unsigned MOHiFlag, MOLoFlag; | 
| Rafael Espindola | e1d255f | 2016-06-27 12:56:02 +0000 | [diff] [blame] | 2171 | bool IsPIC = isPositionIndependent(); | 
|  | 2172 | getLabelAccessInfo(IsPIC, Subtarget, MOHiFlag, MOLoFlag); | 
| Hal Finkel | 3ee2af7 | 2014-07-18 23:29:49 +0000 | [diff] [blame] | 2173 |  | 
| Rafael Espindola | e1d255f | 2016-06-27 12:56:02 +0000 | [diff] [blame] | 2174 | if (IsPIC && Subtarget.isSVR4ABI()) { | 
| Hal Finkel | 3ee2af7 | 2014-07-18 23:29:49 +0000 | [diff] [blame] | 2175 | SDValue GA = DAG.getTargetJumpTable(JT->getIndex(), PtrVT, | 
|  | 2176 | PPCII::MO_PIC_FLAG); | 
| Hal Finkel | cf59921 | 2015-02-25 21:36:59 +0000 | [diff] [blame] | 2177 | return getTOCEntry(DAG, SDLoc(GA), false, GA); | 
| Hal Finkel | 3ee2af7 | 2014-07-18 23:29:49 +0000 | [diff] [blame] | 2178 | } | 
|  | 2179 |  | 
| Chris Lattner | edb9d84 | 2010-11-15 02:46:57 +0000 | [diff] [blame] | 2180 | SDValue JTIHi = DAG.getTargetJumpTable(JT->getIndex(), PtrVT, MOHiFlag); | 
|  | 2181 | SDValue JTILo = DAG.getTargetJumpTable(JT->getIndex(), PtrVT, MOLoFlag); | 
| Rafael Espindola | e1d255f | 2016-06-27 12:56:02 +0000 | [diff] [blame] | 2182 | return LowerLabelRef(JTIHi, JTILo, IsPIC, DAG); | 
| Lauro Ramos Venancio | 09d73c0 | 2007-07-11 17:19:51 +0000 | [diff] [blame] | 2183 | } | 
|  | 2184 |  | 
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2185 | SDValue PPCTargetLowering::LowerBlockAddress(SDValue Op, | 
|  | 2186 | SelectionDAG &DAG) const { | 
| Bob Wilson | f84f710 | 2009-11-04 21:31:18 +0000 | [diff] [blame] | 2187 | EVT PtrVT = Op.getValueType(); | 
| Ulrich Weigand | c8c2ea2 | 2014-10-31 10:33:14 +0000 | [diff] [blame] | 2188 | BlockAddressSDNode *BASDN = cast<BlockAddressSDNode>(Op); | 
|  | 2189 | const BlockAddress *BA = BASDN->getBlockAddress(); | 
| Bob Wilson | f84f710 | 2009-11-04 21:31:18 +0000 | [diff] [blame] | 2190 |  | 
| Ulrich Weigand | c8c2ea2 | 2014-10-31 10:33:14 +0000 | [diff] [blame] | 2191 | // 64-bit SVR4 ABI code is always position-independent. | 
|  | 2192 | // The actual BlockAddress is stored in the TOC. | 
|  | 2193 | if (Subtarget.isSVR4ABI() && Subtarget.isPPC64()) { | 
| Hal Finkel | e6698d5 | 2015-02-01 15:03:28 +0000 | [diff] [blame] | 2194 | setUsesTOCBasePtr(DAG); | 
| Ulrich Weigand | c8c2ea2 | 2014-10-31 10:33:14 +0000 | [diff] [blame] | 2195 | SDValue GA = DAG.getTargetBlockAddress(BA, PtrVT, BASDN->getOffset()); | 
| Hal Finkel | cf59921 | 2015-02-25 21:36:59 +0000 | [diff] [blame] | 2196 | return getTOCEntry(DAG, SDLoc(BASDN), true, GA); | 
| Ulrich Weigand | c8c2ea2 | 2014-10-31 10:33:14 +0000 | [diff] [blame] | 2197 | } | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2198 |  | 
| Chris Lattner | edb9d84 | 2010-11-15 02:46:57 +0000 | [diff] [blame] | 2199 | unsigned MOHiFlag, MOLoFlag; | 
| Rafael Espindola | e1d255f | 2016-06-27 12:56:02 +0000 | [diff] [blame] | 2200 | bool IsPIC = isPositionIndependent(); | 
|  | 2201 | getLabelAccessInfo(IsPIC, Subtarget, MOHiFlag, MOLoFlag); | 
| Michael Liao | abb87d4 | 2012-09-12 21:43:09 +0000 | [diff] [blame] | 2202 | SDValue TgtBAHi = DAG.getTargetBlockAddress(BA, PtrVT, 0, MOHiFlag); | 
|  | 2203 | SDValue TgtBALo = DAG.getTargetBlockAddress(BA, PtrVT, 0, MOLoFlag); | 
| Rafael Espindola | e1d255f | 2016-06-27 12:56:02 +0000 | [diff] [blame] | 2204 | return LowerLabelRef(TgtBAHi, TgtBALo, IsPIC, DAG); | 
| Chris Lattner | edb9d84 | 2010-11-15 02:46:57 +0000 | [diff] [blame] | 2205 | } | 
|  | 2206 |  | 
| Roman Divacky | e3f15c98 | 2012-06-04 17:36:38 +0000 | [diff] [blame] | 2207 | SDValue PPCTargetLowering::LowerGlobalTLSAddress(SDValue Op, | 
|  | 2208 | SelectionDAG &DAG) const { | 
|  | 2209 |  | 
| Bill Schmidt | bdae03f | 2013-09-17 20:22:05 +0000 | [diff] [blame] | 2210 | // FIXME: TLS addresses currently use medium model code sequences, | 
|  | 2211 | // which is the most useful form.  Eventually support for small and | 
|  | 2212 | // large models could be added if users need it, at the cost of | 
|  | 2213 | // additional complexity. | 
| Roman Divacky | e3f15c98 | 2012-06-04 17:36:38 +0000 | [diff] [blame] | 2214 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); | 
| Chih-Hung Hsieh | 1e85958 | 2015-07-28 16:24:05 +0000 | [diff] [blame] | 2215 | if (DAG.getTarget().Options.EmulatedTLS) | 
|  | 2216 | return LowerToTLSEmulatedModel(GA, DAG); | 
|  | 2217 |  | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2218 | SDLoc dl(GA); | 
| Roman Divacky | e3f15c98 | 2012-06-04 17:36:38 +0000 | [diff] [blame] | 2219 | const GlobalValue *GV = GA->getGlobal(); | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2220 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 2221 | bool is64bit = Subtarget.isPPC64(); | 
| Justin Hibbits | a88b605 | 2014-11-12 15:16:30 +0000 | [diff] [blame] | 2222 | const Module *M = DAG.getMachineFunction().getFunction()->getParent(); | 
|  | 2223 | PICLevel::Level picLevel = M->getPICLevel(); | 
| Roman Divacky | e3f15c98 | 2012-06-04 17:36:38 +0000 | [diff] [blame] | 2224 |  | 
| Bill Schmidt | ca4a0c9 | 2012-12-04 16:18:08 +0000 | [diff] [blame] | 2225 | TLSModel::Model Model = getTargetMachine().getTLSModel(GV); | 
| Roman Divacky | e3f15c98 | 2012-06-04 17:36:38 +0000 | [diff] [blame] | 2226 |  | 
| Bill Schmidt | ca4a0c9 | 2012-12-04 16:18:08 +0000 | [diff] [blame] | 2227 | if (Model == TLSModel::LocalExec) { | 
|  | 2228 | SDValue TGAHi = DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, | 
| Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 2229 | PPCII::MO_TPREL_HA); | 
| Bill Schmidt | ca4a0c9 | 2012-12-04 16:18:08 +0000 | [diff] [blame] | 2230 | SDValue TGALo = DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, | 
| Ulrich Weigand | d51c09f | 2013-06-21 14:42:20 +0000 | [diff] [blame] | 2231 | PPCII::MO_TPREL_LO); | 
| Bill Schmidt | ca4a0c9 | 2012-12-04 16:18:08 +0000 | [diff] [blame] | 2232 | SDValue TLSReg = DAG.getRegister(is64bit ? PPC::X13 : PPC::R2, | 
|  | 2233 | is64bit ? MVT::i64 : MVT::i32); | 
|  | 2234 | SDValue Hi = DAG.getNode(PPCISD::Hi, dl, PtrVT, TGAHi, TLSReg); | 
|  | 2235 | return DAG.getNode(PPCISD::Lo, dl, PtrVT, TGALo, Hi); | 
|  | 2236 | } | 
| Roman Divacky | e3f15c98 | 2012-06-04 17:36:38 +0000 | [diff] [blame] | 2237 |  | 
| Bill Schmidt | c56f1d3 | 2012-12-11 20:30:11 +0000 | [diff] [blame] | 2238 | if (Model == TLSModel::InitialExec) { | 
| Bill Schmidt | 732eb91 | 2012-12-13 18:45:54 +0000 | [diff] [blame] | 2239 | SDValue TGA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, 0); | 
| Ulrich Weigand | 5b42759 | 2013-07-05 12:22:36 +0000 | [diff] [blame] | 2240 | SDValue TGATLS = DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, | 
|  | 2241 | PPCII::MO_TLS); | 
| Roman Divacky | 32143e2 | 2013-12-20 18:08:54 +0000 | [diff] [blame] | 2242 | SDValue GOTPtr; | 
|  | 2243 | if (is64bit) { | 
| Hal Finkel | e6698d5 | 2015-02-01 15:03:28 +0000 | [diff] [blame] | 2244 | setUsesTOCBasePtr(DAG); | 
| Roman Divacky | 32143e2 | 2013-12-20 18:08:54 +0000 | [diff] [blame] | 2245 | SDValue GOTReg = DAG.getRegister(PPC::X2, MVT::i64); | 
|  | 2246 | GOTPtr = DAG.getNode(PPCISD::ADDIS_GOT_TPREL_HA, dl, | 
|  | 2247 | PtrVT, GOTReg, TGA); | 
|  | 2248 | } else | 
|  | 2249 | GOTPtr = DAG.getNode(PPCISD::PPC32_GOT, dl, PtrVT); | 
| Bill Schmidt | 9f0b4ec | 2012-12-14 17:02:38 +0000 | [diff] [blame] | 2250 | SDValue TPOffset = DAG.getNode(PPCISD::LD_GOT_TPREL_L, dl, | 
| Roman Divacky | 32143e2 | 2013-12-20 18:08:54 +0000 | [diff] [blame] | 2251 | PtrVT, TGA, GOTPtr); | 
| Ulrich Weigand | 5b42759 | 2013-07-05 12:22:36 +0000 | [diff] [blame] | 2252 | return DAG.getNode(PPCISD::ADD_TLS, dl, PtrVT, TPOffset, TGATLS); | 
| Bill Schmidt | c56f1d3 | 2012-12-11 20:30:11 +0000 | [diff] [blame] | 2253 | } | 
| Bill Schmidt | ca4a0c9 | 2012-12-04 16:18:08 +0000 | [diff] [blame] | 2254 |  | 
| Bill Schmidt | c56f1d3 | 2012-12-11 20:30:11 +0000 | [diff] [blame] | 2255 | if (Model == TLSModel::GeneralDynamic) { | 
| Bill Schmidt | 82f1c77 | 2015-02-10 19:09:05 +0000 | [diff] [blame] | 2256 | SDValue TGA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, 0); | 
| Hal Finkel | 7c8ae53 | 2014-07-25 17:47:22 +0000 | [diff] [blame] | 2257 | SDValue GOTPtr; | 
|  | 2258 | if (is64bit) { | 
| Hal Finkel | e6698d5 | 2015-02-01 15:03:28 +0000 | [diff] [blame] | 2259 | setUsesTOCBasePtr(DAG); | 
| Hal Finkel | 7c8ae53 | 2014-07-25 17:47:22 +0000 | [diff] [blame] | 2260 | SDValue GOTReg = DAG.getRegister(PPC::X2, MVT::i64); | 
|  | 2261 | GOTPtr = DAG.getNode(PPCISD::ADDIS_TLSGD_HA, dl, PtrVT, | 
|  | 2262 | GOTReg, TGA); | 
|  | 2263 | } else { | 
| Davide Italiano | 4cccc48 | 2016-06-17 18:07:14 +0000 | [diff] [blame] | 2264 | if (picLevel == PICLevel::SmallPIC) | 
| Justin Hibbits | a88b605 | 2014-11-12 15:16:30 +0000 | [diff] [blame] | 2265 | GOTPtr = DAG.getNode(PPCISD::GlobalBaseReg, dl, PtrVT); | 
|  | 2266 | else | 
|  | 2267 | GOTPtr = DAG.getNode(PPCISD::PPC32_PICGOT, dl, PtrVT); | 
| Hal Finkel | 7c8ae53 | 2014-07-25 17:47:22 +0000 | [diff] [blame] | 2268 | } | 
| Bill Schmidt | 82f1c77 | 2015-02-10 19:09:05 +0000 | [diff] [blame] | 2269 | return DAG.getNode(PPCISD::ADDI_TLSGD_L_ADDR, dl, PtrVT, | 
|  | 2270 | GOTPtr, TGA, TGA); | 
| Bill Schmidt | c56f1d3 | 2012-12-11 20:30:11 +0000 | [diff] [blame] | 2271 | } | 
|  | 2272 |  | 
| Bill Schmidt | 24b8dd6 | 2012-12-12 19:29:35 +0000 | [diff] [blame] | 2273 | if (Model == TLSModel::LocalDynamic) { | 
| Bill Schmidt | 82f1c77 | 2015-02-10 19:09:05 +0000 | [diff] [blame] | 2274 | SDValue TGA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, 0); | 
| Hal Finkel | 7c8ae53 | 2014-07-25 17:47:22 +0000 | [diff] [blame] | 2275 | SDValue GOTPtr; | 
|  | 2276 | if (is64bit) { | 
| Hal Finkel | e6698d5 | 2015-02-01 15:03:28 +0000 | [diff] [blame] | 2277 | setUsesTOCBasePtr(DAG); | 
| Hal Finkel | 7c8ae53 | 2014-07-25 17:47:22 +0000 | [diff] [blame] | 2278 | SDValue GOTReg = DAG.getRegister(PPC::X2, MVT::i64); | 
|  | 2279 | GOTPtr = DAG.getNode(PPCISD::ADDIS_TLSLD_HA, dl, PtrVT, | 
|  | 2280 | GOTReg, TGA); | 
|  | 2281 | } else { | 
| Davide Italiano | 4cccc48 | 2016-06-17 18:07:14 +0000 | [diff] [blame] | 2282 | if (picLevel == PICLevel::SmallPIC) | 
| Justin Hibbits | a88b605 | 2014-11-12 15:16:30 +0000 | [diff] [blame] | 2283 | GOTPtr = DAG.getNode(PPCISD::GlobalBaseReg, dl, PtrVT); | 
|  | 2284 | else | 
|  | 2285 | GOTPtr = DAG.getNode(PPCISD::PPC32_PICGOT, dl, PtrVT); | 
| Hal Finkel | 7c8ae53 | 2014-07-25 17:47:22 +0000 | [diff] [blame] | 2286 | } | 
| Bill Schmidt | 82f1c77 | 2015-02-10 19:09:05 +0000 | [diff] [blame] | 2287 | SDValue TLSAddr = DAG.getNode(PPCISD::ADDI_TLSLD_L_ADDR, dl, | 
|  | 2288 | PtrVT, GOTPtr, TGA, TGA); | 
|  | 2289 | SDValue DtvOffsetHi = DAG.getNode(PPCISD::ADDIS_DTPREL_HA, dl, | 
|  | 2290 | PtrVT, TLSAddr, TGA); | 
| Bill Schmidt | 24b8dd6 | 2012-12-12 19:29:35 +0000 | [diff] [blame] | 2291 | return DAG.getNode(PPCISD::ADDI_DTPREL_L, dl, PtrVT, DtvOffsetHi, TGA); | 
|  | 2292 | } | 
|  | 2293 |  | 
|  | 2294 | llvm_unreachable("Unknown TLS model!"); | 
| Roman Divacky | e3f15c98 | 2012-06-04 17:36:38 +0000 | [diff] [blame] | 2295 | } | 
|  | 2296 |  | 
| Chris Lattner | edb9d84 | 2010-11-15 02:46:57 +0000 | [diff] [blame] | 2297 | SDValue PPCTargetLowering::LowerGlobalAddress(SDValue Op, | 
|  | 2298 | SelectionDAG &DAG) const { | 
|  | 2299 | EVT PtrVT = Op.getValueType(); | 
|  | 2300 | GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op); | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2301 | SDLoc DL(GSDN); | 
| Chris Lattner | edb9d84 | 2010-11-15 02:46:57 +0000 | [diff] [blame] | 2302 | const GlobalValue *GV = GSDN->getGlobal(); | 
|  | 2303 |  | 
| Chris Lattner | edb9d84 | 2010-11-15 02:46:57 +0000 | [diff] [blame] | 2304 | // 64-bit SVR4 ABI code is always position-independent. | 
|  | 2305 | // The actual address of the GlobalValue is stored in the TOC. | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 2306 | if (Subtarget.isSVR4ABI() && Subtarget.isPPC64()) { | 
| Hal Finkel | e6698d5 | 2015-02-01 15:03:28 +0000 | [diff] [blame] | 2307 | setUsesTOCBasePtr(DAG); | 
| Chris Lattner | edb9d84 | 2010-11-15 02:46:57 +0000 | [diff] [blame] | 2308 | SDValue GA = DAG.getTargetGlobalAddress(GV, DL, PtrVT, GSDN->getOffset()); | 
| Hal Finkel | cf59921 | 2015-02-25 21:36:59 +0000 | [diff] [blame] | 2309 | return getTOCEntry(DAG, DL, true, GA); | 
| Chris Lattner | edb9d84 | 2010-11-15 02:46:57 +0000 | [diff] [blame] | 2310 | } | 
|  | 2311 |  | 
| Chris Lattner | dd6df84 | 2010-11-15 03:13:19 +0000 | [diff] [blame] | 2312 | unsigned MOHiFlag, MOLoFlag; | 
| Rafael Espindola | e1d255f | 2016-06-27 12:56:02 +0000 | [diff] [blame] | 2313 | bool IsPIC = isPositionIndependent(); | 
|  | 2314 | getLabelAccessInfo(IsPIC, Subtarget, MOHiFlag, MOLoFlag, GV); | 
| Chris Lattner | edb9d84 | 2010-11-15 02:46:57 +0000 | [diff] [blame] | 2315 |  | 
| Rafael Espindola | e1d255f | 2016-06-27 12:56:02 +0000 | [diff] [blame] | 2316 | if (IsPIC && Subtarget.isSVR4ABI()) { | 
| Hal Finkel | 3ee2af7 | 2014-07-18 23:29:49 +0000 | [diff] [blame] | 2317 | SDValue GA = DAG.getTargetGlobalAddress(GV, DL, PtrVT, | 
|  | 2318 | GSDN->getOffset(), | 
|  | 2319 | PPCII::MO_PIC_FLAG); | 
| Hal Finkel | cf59921 | 2015-02-25 21:36:59 +0000 | [diff] [blame] | 2320 | return getTOCEntry(DAG, DL, false, GA); | 
| Hal Finkel | 3ee2af7 | 2014-07-18 23:29:49 +0000 | [diff] [blame] | 2321 | } | 
|  | 2322 |  | 
| Chris Lattner | dd6df84 | 2010-11-15 03:13:19 +0000 | [diff] [blame] | 2323 | SDValue GAHi = | 
|  | 2324 | DAG.getTargetGlobalAddress(GV, DL, PtrVT, GSDN->getOffset(), MOHiFlag); | 
|  | 2325 | SDValue GALo = | 
|  | 2326 | DAG.getTargetGlobalAddress(GV, DL, PtrVT, GSDN->getOffset(), MOLoFlag); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2327 |  | 
| Rafael Espindola | e1d255f | 2016-06-27 12:56:02 +0000 | [diff] [blame] | 2328 | SDValue Ptr = LowerLabelRef(GAHi, GALo, IsPIC, DAG); | 
| Bob Wilson | f84f710 | 2009-11-04 21:31:18 +0000 | [diff] [blame] | 2329 |  | 
| Chris Lattner | dd6df84 | 2010-11-15 03:13:19 +0000 | [diff] [blame] | 2330 | // If the global reference is actually to a non-lazy-pointer, we have to do an | 
|  | 2331 | // extra load to get the address of the global. | 
|  | 2332 | if (MOHiFlag & PPCII::MO_NLP_FLAG) | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 2333 | Ptr = DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), Ptr, MachinePointerInfo()); | 
| Chris Lattner | dd6df84 | 2010-11-15 03:13:19 +0000 | [diff] [blame] | 2334 | return Ptr; | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 2335 | } | 
|  | 2336 |  | 
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2337 | SDValue PPCTargetLowering::LowerSETCC(SDValue Op, SelectionDAG &DAG) const { | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 2338 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get(); | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2339 | SDLoc dl(Op); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2340 |  | 
| Hal Finkel | 777c9dd | 2014-03-29 16:04:40 +0000 | [diff] [blame] | 2341 | if (Op.getValueType() == MVT::v2i64) { | 
|  | 2342 | // When the operands themselves are v2i64 values, we need to do something | 
|  | 2343 | // special because VSX has no underlying comparison operations for these. | 
|  | 2344 | if (Op.getOperand(0).getValueType() == MVT::v2i64) { | 
|  | 2345 | // Equality can be handled by casting to the legal type for Altivec | 
|  | 2346 | // comparisons, everything else needs to be expanded. | 
|  | 2347 | if (CC == ISD::SETEQ || CC == ISD::SETNE) { | 
|  | 2348 | return DAG.getNode(ISD::BITCAST, dl, MVT::v2i64, | 
|  | 2349 | DAG.getSetCC(dl, MVT::v4i32, | 
|  | 2350 | DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, Op.getOperand(0)), | 
|  | 2351 | DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, Op.getOperand(1)), | 
|  | 2352 | CC)); | 
|  | 2353 | } | 
|  | 2354 |  | 
|  | 2355 | return SDValue(); | 
|  | 2356 | } | 
|  | 2357 |  | 
|  | 2358 | // We handle most of these in the usual way. | 
|  | 2359 | return Op; | 
|  | 2360 | } | 
|  | 2361 |  | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 2362 | // If we're comparing for equality to zero, expose the fact that this is | 
| Sanjay Patel | 9cc21ac | 2016-07-06 16:42:46 +0000 | [diff] [blame] | 2363 | // implemented as a ctlz/srl pair on ppc, so that the dag combiner can | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 2364 | // fold the new nodes. | 
| Pierre Gousseau | 051db7d | 2016-08-16 13:53:53 +0000 | [diff] [blame] | 2365 | if (SDValue V = lowerCmpEqZeroToCtlzSrl(Op, DAG)) | 
|  | 2366 | return V; | 
|  | 2367 |  | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 2368 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2369 | // Leave comparisons against 0 and -1 alone for now, since they're usually | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 2370 | // optimized.  FIXME: revisit this when we can custom lower all setcc | 
|  | 2371 | // optimizations. | 
|  | 2372 | if (C->isAllOnesValue() || C->isNullValue()) | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2373 | return SDValue(); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 2374 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2375 |  | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 2376 | // If we have an integer seteq/setne, turn it into a compare against zero | 
| Chris Lattner | 97ff46b | 2006-11-14 05:28:08 +0000 | [diff] [blame] | 2377 | // by xor'ing the rhs with the lhs, which is faster than setting a | 
|  | 2378 | // condition register, reading it back out, and masking the correct bit.  The | 
|  | 2379 | // normal approach here uses sub to do this instead of xor.  Using xor exposes | 
|  | 2380 | // the result to other bit-twiddling opportunities. | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2381 | EVT LHSVT = Op.getOperand(0).getValueType(); | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2382 | if (LHSVT.isInteger() && (CC == ISD::SETEQ || CC == ISD::SETNE)) { | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2383 | EVT VT = Op.getValueType(); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2384 | SDValue Sub = DAG.getNode(ISD::XOR, dl, LHSVT, Op.getOperand(0), | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 2385 | Op.getOperand(1)); | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2386 | return DAG.getSetCC(dl, VT, Sub, DAG.getConstant(0, dl, LHSVT), CC); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 2387 | } | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2388 | return SDValue(); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 2389 | } | 
|  | 2390 |  | 
| Eric Christopher | b976a39 | 2016-07-07 00:39:27 +0000 | [diff] [blame] | 2391 | SDValue PPCTargetLowering::LowerVAARG(SDValue Op, SelectionDAG &DAG) const { | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 2392 | SDNode *Node = Op.getNode(); | 
|  | 2393 | EVT VT = Node->getValueType(0); | 
| Eric Christopher | cd71946 | 2016-07-07 01:49:59 +0000 | [diff] [blame] | 2394 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 2395 | SDValue InChain = Node->getOperand(0); | 
|  | 2396 | SDValue VAListPtr = Node->getOperand(1); | 
|  | 2397 | const Value *SV = cast<SrcValueSDNode>(Node->getOperand(2))->getValue(); | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2398 | SDLoc dl(Node); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2399 |  | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 2400 | assert(!Subtarget.isPPC64() && "LowerVAARG is PPC32 only"); | 
|  | 2401 |  | 
|  | 2402 | // gpr_index | 
|  | 2403 | SDValue GprIndex = DAG.getExtLoad(ISD::ZEXTLOAD, dl, MVT::i32, InChain, | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 2404 | VAListPtr, MachinePointerInfo(SV), MVT::i8); | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 2405 | InChain = GprIndex.getValue(1); | 
|  | 2406 |  | 
|  | 2407 | if (VT == MVT::i64) { | 
|  | 2408 | // Check if GprIndex is even | 
|  | 2409 | SDValue GprAnd = DAG.getNode(ISD::AND, dl, MVT::i32, GprIndex, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2410 | DAG.getConstant(1, dl, MVT::i32)); | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 2411 | SDValue CC64 = DAG.getSetCC(dl, MVT::i32, GprAnd, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2412 | DAG.getConstant(0, dl, MVT::i32), ISD::SETNE); | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 2413 | SDValue GprIndexPlusOne = DAG.getNode(ISD::ADD, dl, MVT::i32, GprIndex, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2414 | DAG.getConstant(1, dl, MVT::i32)); | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 2415 | // Align GprIndex to be even if it isn't | 
|  | 2416 | GprIndex = DAG.getNode(ISD::SELECT, dl, MVT::i32, CC64, GprIndexPlusOne, | 
|  | 2417 | GprIndex); | 
|  | 2418 | } | 
|  | 2419 |  | 
|  | 2420 | // fpr index is 1 byte after gpr | 
|  | 2421 | SDValue FprPtr = DAG.getNode(ISD::ADD, dl, PtrVT, VAListPtr, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2422 | DAG.getConstant(1, dl, MVT::i32)); | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 2423 |  | 
|  | 2424 | // fpr | 
|  | 2425 | SDValue FprIndex = DAG.getExtLoad(ISD::ZEXTLOAD, dl, MVT::i32, InChain, | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 2426 | FprPtr, MachinePointerInfo(SV), MVT::i8); | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 2427 | InChain = FprIndex.getValue(1); | 
|  | 2428 |  | 
|  | 2429 | SDValue RegSaveAreaPtr = DAG.getNode(ISD::ADD, dl, PtrVT, VAListPtr, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2430 | DAG.getConstant(8, dl, MVT::i32)); | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 2431 |  | 
|  | 2432 | SDValue OverflowAreaPtr = DAG.getNode(ISD::ADD, dl, PtrVT, VAListPtr, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2433 | DAG.getConstant(4, dl, MVT::i32)); | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 2434 |  | 
|  | 2435 | // areas | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 2436 | SDValue OverflowArea = | 
|  | 2437 | DAG.getLoad(MVT::i32, dl, InChain, OverflowAreaPtr, MachinePointerInfo()); | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 2438 | InChain = OverflowArea.getValue(1); | 
|  | 2439 |  | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 2440 | SDValue RegSaveArea = | 
|  | 2441 | DAG.getLoad(MVT::i32, dl, InChain, RegSaveAreaPtr, MachinePointerInfo()); | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 2442 | InChain = RegSaveArea.getValue(1); | 
|  | 2443 |  | 
|  | 2444 | // select overflow_area if index > 8 | 
|  | 2445 | SDValue CC = DAG.getSetCC(dl, MVT::i32, VT.isInteger() ? GprIndex : FprIndex, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2446 | DAG.getConstant(8, dl, MVT::i32), ISD::SETLT); | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 2447 |  | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 2448 | // adjustment constant gpr_index * 4/8 | 
|  | 2449 | SDValue RegConstant = DAG.getNode(ISD::MUL, dl, MVT::i32, | 
|  | 2450 | VT.isInteger() ? GprIndex : FprIndex, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2451 | DAG.getConstant(VT.isInteger() ? 4 : 8, dl, | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 2452 | MVT::i32)); | 
|  | 2453 |  | 
|  | 2454 | // OurReg = RegSaveArea + RegConstant | 
|  | 2455 | SDValue OurReg = DAG.getNode(ISD::ADD, dl, PtrVT, RegSaveArea, | 
|  | 2456 | RegConstant); | 
|  | 2457 |  | 
|  | 2458 | // Floating types are 32 bytes into RegSaveArea | 
|  | 2459 | if (VT.isFloatingPoint()) | 
|  | 2460 | OurReg = DAG.getNode(ISD::ADD, dl, PtrVT, OurReg, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2461 | DAG.getConstant(32, dl, MVT::i32)); | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 2462 |  | 
|  | 2463 | // increase {f,g}pr_index by 1 (or 2 if VT is i64) | 
|  | 2464 | SDValue IndexPlus1 = DAG.getNode(ISD::ADD, dl, MVT::i32, | 
|  | 2465 | VT.isInteger() ? GprIndex : FprIndex, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2466 | DAG.getConstant(VT == MVT::i64 ? 2 : 1, dl, | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 2467 | MVT::i32)); | 
|  | 2468 |  | 
|  | 2469 | InChain = DAG.getTruncStore(InChain, dl, IndexPlus1, | 
|  | 2470 | VT.isInteger() ? VAListPtr : FprPtr, | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 2471 | MachinePointerInfo(SV), MVT::i8); | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 2472 |  | 
|  | 2473 | // determine if we should load from reg_save_area or overflow_area | 
|  | 2474 | SDValue Result = DAG.getNode(ISD::SELECT, dl, PtrVT, CC, OurReg, OverflowArea); | 
|  | 2475 |  | 
|  | 2476 | // increase overflow_area by 4/8 if gpr/fpr > 8 | 
|  | 2477 | SDValue OverflowAreaPlusN = DAG.getNode(ISD::ADD, dl, PtrVT, OverflowArea, | 
|  | 2478 | DAG.getConstant(VT.isInteger() ? 4 : 8, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2479 | dl, MVT::i32)); | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 2480 |  | 
|  | 2481 | OverflowArea = DAG.getNode(ISD::SELECT, dl, MVT::i32, CC, OverflowArea, | 
|  | 2482 | OverflowAreaPlusN); | 
|  | 2483 |  | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 2484 | InChain = DAG.getTruncStore(InChain, dl, OverflowArea, OverflowAreaPtr, | 
|  | 2485 | MachinePointerInfo(), MVT::i32); | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 2486 |  | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 2487 | return DAG.getLoad(VT, dl, InChain, Result, MachinePointerInfo()); | 
| Nicolas Geoffray | 23710a7 | 2007-04-03 13:59:52 +0000 | [diff] [blame] | 2488 | } | 
|  | 2489 |  | 
| Eric Christopher | b976a39 | 2016-07-07 00:39:27 +0000 | [diff] [blame] | 2490 | SDValue PPCTargetLowering::LowerVACOPY(SDValue Op, SelectionDAG &DAG) const { | 
| Roman Divacky | c3825df | 2013-07-25 21:36:47 +0000 | [diff] [blame] | 2491 | assert(!Subtarget.isPPC64() && "LowerVACOPY is PPC32 only"); | 
|  | 2492 |  | 
|  | 2493 | // We have to copy the entire va_list struct: | 
|  | 2494 | // 2*sizeof(char) + 2 Byte alignment + 2*sizeof(char*) = 12 Byte | 
|  | 2495 | return DAG.getMemcpy(Op.getOperand(0), Op, | 
|  | 2496 | Op.getOperand(1), Op.getOperand(2), | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2497 | DAG.getConstant(12, SDLoc(Op), MVT::i32), 8, false, true, | 
|  | 2498 | false, MachinePointerInfo(), MachinePointerInfo()); | 
| Roman Divacky | c3825df | 2013-07-25 21:36:47 +0000 | [diff] [blame] | 2499 | } | 
|  | 2500 |  | 
| Duncan Sands | a098436 | 2011-09-06 13:37:06 +0000 | [diff] [blame] | 2501 | SDValue PPCTargetLowering::LowerADJUST_TRAMPOLINE(SDValue Op, | 
|  | 2502 | SelectionDAG &DAG) const { | 
|  | 2503 | return Op.getOperand(0); | 
|  | 2504 | } | 
|  | 2505 |  | 
|  | 2506 | SDValue PPCTargetLowering::LowerINIT_TRAMPOLINE(SDValue Op, | 
|  | 2507 | SelectionDAG &DAG) const { | 
| Bill Wendling | 95e1af2 | 2008-09-17 00:30:57 +0000 | [diff] [blame] | 2508 | SDValue Chain = Op.getOperand(0); | 
|  | 2509 | SDValue Trmp = Op.getOperand(1); // trampoline | 
|  | 2510 | SDValue FPtr = Op.getOperand(2); // nested function | 
|  | 2511 | SDValue Nest = Op.getOperand(3); // 'nest' parameter value | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2512 | SDLoc dl(Op); | 
| Bill Wendling | 95e1af2 | 2008-09-17 00:30:57 +0000 | [diff] [blame] | 2513 |  | 
| Eric Christopher | cd71946 | 2016-07-07 01:49:59 +0000 | [diff] [blame] | 2514 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2515 | bool isPPC64 = (PtrVT == MVT::i64); | 
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 2516 | Type *IntPtrTy = DAG.getDataLayout().getIntPtrType(*DAG.getContext()); | 
| Bill Wendling | 95e1af2 | 2008-09-17 00:30:57 +0000 | [diff] [blame] | 2517 |  | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2518 | TargetLowering::ArgListTy Args; | 
| Bill Wendling | 95e1af2 | 2008-09-17 00:30:57 +0000 | [diff] [blame] | 2519 | TargetLowering::ArgListEntry Entry; | 
|  | 2520 |  | 
|  | 2521 | Entry.Ty = IntPtrTy; | 
|  | 2522 | Entry.Node = Trmp; Args.push_back(Entry); | 
|  | 2523 |  | 
|  | 2524 | // TrampSize == (isPPC64 ? 48 : 40); | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2525 | Entry.Node = DAG.getConstant(isPPC64 ? 48 : 40, dl, | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2526 | isPPC64 ? MVT::i64 : MVT::i32); | 
| Bill Wendling | 95e1af2 | 2008-09-17 00:30:57 +0000 | [diff] [blame] | 2527 | Args.push_back(Entry); | 
|  | 2528 |  | 
|  | 2529 | Entry.Node = FPtr; Args.push_back(Entry); | 
|  | 2530 | Entry.Node = Nest; Args.push_back(Entry); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2531 |  | 
| Bill Wendling | 95e1af2 | 2008-09-17 00:30:57 +0000 | [diff] [blame] | 2532 | // Lower to a call to __trampoline_setup(Trmp, TrampSize, FPtr, ctx_reg) | 
| Saleem Abdulrasool | f3a5a5c | 2014-05-17 21:50:17 +0000 | [diff] [blame] | 2533 | TargetLowering::CallLoweringInfo CLI(DAG); | 
|  | 2534 | CLI.setDebugLoc(dl).setChain(Chain) | 
|  | 2535 | .setCallee(CallingConv::C, Type::getVoidTy(*DAG.getContext()), | 
| Juergen Ributzka | 3bd03c7 | 2014-07-01 22:01:54 +0000 | [diff] [blame] | 2536 | DAG.getExternalSymbol("__trampoline_setup", PtrVT), | 
| Krzysztof Parzyszek | e116d500 | 2016-06-22 12:54:25 +0000 | [diff] [blame] | 2537 | std::move(Args)); | 
| Bill Wendling | 95e1af2 | 2008-09-17 00:30:57 +0000 | [diff] [blame] | 2538 |  | 
| Saleem Abdulrasool | f3a5a5c | 2014-05-17 21:50:17 +0000 | [diff] [blame] | 2539 | std::pair<SDValue, SDValue> CallResult = LowerCallTo(CLI); | 
| Duncan Sands | a098436 | 2011-09-06 13:37:06 +0000 | [diff] [blame] | 2540 | return CallResult.second; | 
| Bill Wendling | 95e1af2 | 2008-09-17 00:30:57 +0000 | [diff] [blame] | 2541 | } | 
|  | 2542 |  | 
| Eric Christopher | b976a39 | 2016-07-07 00:39:27 +0000 | [diff] [blame] | 2543 | SDValue PPCTargetLowering::LowerVASTART(SDValue Op, SelectionDAG &DAG) const { | 
| Dan Gohman | 31ae586 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2544 | MachineFunction &MF = DAG.getMachineFunction(); | 
|  | 2545 | PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>(); | 
| Eric Christopher | cd71946 | 2016-07-07 01:49:59 +0000 | [diff] [blame] | 2546 | EVT PtrVT = getPointerTy(MF.getDataLayout()); | 
| Dan Gohman | 31ae586 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2547 |  | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2548 | SDLoc dl(Op); | 
| Nicolas Geoffray | 23710a7 | 2007-04-03 13:59:52 +0000 | [diff] [blame] | 2549 |  | 
| Tilmann Scheller | d1aaa32 | 2009-08-15 11:54:46 +0000 | [diff] [blame] | 2550 | if (Subtarget.isDarwinABI() || Subtarget.isPPC64()) { | 
| Nicolas Geoffray | 23710a7 | 2007-04-03 13:59:52 +0000 | [diff] [blame] | 2551 | // vastart just stores the address of the VarArgsFrameIndex slot into the | 
|  | 2552 | // memory location argument. | 
| Dan Gohman | 31ae586 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2553 | SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT); | 
| Dan Gohman | 2d489b5 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 2554 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); | 
| Chris Lattner | 676c61d | 2010-09-21 18:41:36 +0000 | [diff] [blame] | 2555 | return DAG.getStore(Op.getOperand(0), dl, FR, Op.getOperand(1), | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 2556 | MachinePointerInfo(SV)); | 
| Nicolas Geoffray | 23710a7 | 2007-04-03 13:59:52 +0000 | [diff] [blame] | 2557 | } | 
|  | 2558 |  | 
| Tilmann Scheller | d1aaa32 | 2009-08-15 11:54:46 +0000 | [diff] [blame] | 2559 | // For the 32-bit SVR4 ABI we follow the layout of the va_list struct. | 
| Nicolas Geoffray | 23710a7 | 2007-04-03 13:59:52 +0000 | [diff] [blame] | 2560 | // We suppose the given va_list is already allocated. | 
|  | 2561 | // | 
|  | 2562 | // typedef struct { | 
|  | 2563 | //  char gpr;     /* index into the array of 8 GPRs | 
|  | 2564 | //                 * stored in the register save area | 
|  | 2565 | //                 * gpr=0 corresponds to r3, | 
|  | 2566 | //                 * gpr=1 to r4, etc. | 
|  | 2567 | //                 */ | 
|  | 2568 | //  char fpr;     /* index into the array of 8 FPRs | 
|  | 2569 | //                 * stored in the register save area | 
|  | 2570 | //                 * fpr=0 corresponds to f1, | 
|  | 2571 | //                 * fpr=1 to f2, etc. | 
|  | 2572 | //                 */ | 
|  | 2573 | //  char *overflow_arg_area; | 
|  | 2574 | //                /* location on stack that holds | 
|  | 2575 | //                 * the next overflow argument | 
|  | 2576 | //                 */ | 
|  | 2577 | //  char *reg_save_area; | 
|  | 2578 | //               /* where r3:r10 and f1:f8 (if saved) | 
|  | 2579 | //                * are stored | 
|  | 2580 | //                */ | 
|  | 2581 | // } va_list[1]; | 
|  | 2582 |  | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2583 | SDValue ArgGPR = DAG.getConstant(FuncInfo->getVarArgsNumGPR(), dl, MVT::i32); | 
|  | 2584 | SDValue ArgFPR = DAG.getConstant(FuncInfo->getVarArgsNumFPR(), dl, MVT::i32); | 
| Dan Gohman | 31ae586 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2585 | SDValue StackOffsetFI = DAG.getFrameIndex(FuncInfo->getVarArgsStackOffset(), | 
|  | 2586 | PtrVT); | 
|  | 2587 | SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), | 
|  | 2588 | PtrVT); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2589 |  | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2590 | uint64_t FrameOffset = PtrVT.getSizeInBits()/8; | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2591 | SDValue ConstFrameOffset = DAG.getConstant(FrameOffset, dl, PtrVT); | 
| Dan Gohman | 2d489b5 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 2592 |  | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2593 | uint64_t StackOffset = PtrVT.getSizeInBits()/8 - 1; | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2594 | SDValue ConstStackOffset = DAG.getConstant(StackOffset, dl, PtrVT); | 
| Dan Gohman | 2d489b5 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 2595 |  | 
|  | 2596 | uint64_t FPROffset = 1; | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2597 | SDValue ConstFPROffset = DAG.getConstant(FPROffset, dl, PtrVT); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2598 |  | 
| Dan Gohman | 2d489b5 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 2599 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2600 |  | 
| Nicolas Geoffray | 23710a7 | 2007-04-03 13:59:52 +0000 | [diff] [blame] | 2601 | // Store first byte : number of int regs | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 2602 | SDValue firstStore = | 
|  | 2603 | DAG.getTruncStore(Op.getOperand(0), dl, ArgGPR, Op.getOperand(1), | 
|  | 2604 | MachinePointerInfo(SV), MVT::i8); | 
| Dan Gohman | 2d489b5 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 2605 | uint64_t nextOffset = FPROffset; | 
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2606 | SDValue nextPtr = DAG.getNode(ISD::ADD, dl, PtrVT, Op.getOperand(1), | 
| Nicolas Geoffray | 23710a7 | 2007-04-03 13:59:52 +0000 | [diff] [blame] | 2607 | ConstFPROffset); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2608 |  | 
| Nicolas Geoffray | 23710a7 | 2007-04-03 13:59:52 +0000 | [diff] [blame] | 2609 | // Store second byte : number of float regs | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2610 | SDValue secondStore = | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 2611 | DAG.getTruncStore(firstStore, dl, ArgFPR, nextPtr, | 
|  | 2612 | MachinePointerInfo(SV, nextOffset), MVT::i8); | 
| Dan Gohman | 2d489b5 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 2613 | nextOffset += StackOffset; | 
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2614 | nextPtr = DAG.getNode(ISD::ADD, dl, PtrVT, nextPtr, ConstStackOffset); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 2615 |  | 
| Nicolas Geoffray | 23710a7 | 2007-04-03 13:59:52 +0000 | [diff] [blame] | 2616 | // Store second word : arguments given on stack | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 2617 | SDValue thirdStore = DAG.getStore(secondStore, dl, StackOffsetFI, nextPtr, | 
|  | 2618 | MachinePointerInfo(SV, nextOffset)); | 
| Dan Gohman | 2d489b5 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 2619 | nextOffset += FrameOffset; | 
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2620 | nextPtr = DAG.getNode(ISD::ADD, dl, PtrVT, nextPtr, ConstFrameOffset); | 
| Nicolas Geoffray | 23710a7 | 2007-04-03 13:59:52 +0000 | [diff] [blame] | 2621 |  | 
|  | 2622 | // Store third word : arguments given in registers | 
| Chris Lattner | 676c61d | 2010-09-21 18:41:36 +0000 | [diff] [blame] | 2623 | return DAG.getStore(thirdStore, dl, FR, nextPtr, | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 2624 | MachinePointerInfo(SV, nextOffset)); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 2625 | } | 
|  | 2626 |  | 
| Chris Lattner | 4f2e4e0 | 2007-03-06 00:59:59 +0000 | [diff] [blame] | 2627 | #include "PPCGenCallingConv.inc" | 
|  | 2628 |  | 
| NAKAMURA Takumi | 8496503 | 2015-09-22 11:14:12 +0000 | [diff] [blame] | 2629 | // Function whose sole purpose is to kill compiler warnings | 
| Bill Schmidt | 8c3976e | 2013-08-26 20:11:46 +0000 | [diff] [blame] | 2630 | // stemming from unused functions included from PPCGenCallingConv.inc. | 
|  | 2631 | CCAssignFn *PPCTargetLowering::useFastISelCCs(unsigned Flag) const { | 
| Bill Schmidt | 8470b0f | 2013-08-30 22:18:55 +0000 | [diff] [blame] | 2632 | return Flag ? CC_PPC64_ELF_FIS : RetCC_PPC64_ELF_FIS; | 
| Bill Schmidt | 8c3976e | 2013-08-26 20:11:46 +0000 | [diff] [blame] | 2633 | } | 
|  | 2634 |  | 
| Bill Schmidt | 230b451 | 2013-06-12 16:39:22 +0000 | [diff] [blame] | 2635 | bool llvm::CC_PPC32_SVR4_Custom_Dummy(unsigned &ValNo, MVT &ValVT, MVT &LocVT, | 
|  | 2636 | CCValAssign::LocInfo &LocInfo, | 
|  | 2637 | ISD::ArgFlagsTy &ArgFlags, | 
|  | 2638 | CCState &State) { | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2639 | return true; | 
|  | 2640 | } | 
|  | 2641 |  | 
| Bill Schmidt | 230b451 | 2013-06-12 16:39:22 +0000 | [diff] [blame] | 2642 | bool llvm::CC_PPC32_SVR4_Custom_AlignArgRegs(unsigned &ValNo, MVT &ValVT, | 
|  | 2643 | MVT &LocVT, | 
|  | 2644 | CCValAssign::LocInfo &LocInfo, | 
|  | 2645 | ISD::ArgFlagsTy &ArgFlags, | 
|  | 2646 | CCState &State) { | 
| Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 2647 | static const MCPhysReg ArgRegs[] = { | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2648 | PPC::R3, PPC::R4, PPC::R5, PPC::R6, | 
|  | 2649 | PPC::R7, PPC::R8, PPC::R9, PPC::R10, | 
|  | 2650 | }; | 
|  | 2651 | const unsigned NumArgRegs = array_lengthof(ArgRegs); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2652 |  | 
| Tim Northover | 3b6b7ca | 2015-02-21 02:11:17 +0000 | [diff] [blame] | 2653 | unsigned RegNum = State.getFirstUnallocated(ArgRegs); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2654 |  | 
|  | 2655 | // Skip one register if the first unallocated register has an even register | 
|  | 2656 | // number and there are still argument registers available which have not been | 
|  | 2657 | // allocated yet. RegNum is actually an index into ArgRegs, which means we | 
|  | 2658 | // need to skip a register if RegNum is odd. | 
|  | 2659 | if (RegNum != NumArgRegs && RegNum % 2 == 1) { | 
|  | 2660 | State.AllocateReg(ArgRegs[RegNum]); | 
|  | 2661 | } | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2662 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2663 | // Always return false here, as this function only makes sure that the first | 
|  | 2664 | // unallocated register has an odd register number and does not actually | 
|  | 2665 | // allocate a register for the current argument. | 
|  | 2666 | return false; | 
|  | 2667 | } | 
|  | 2668 |  | 
| Strahinja Petrovic | 30e0ce8 | 2016-08-05 08:47:26 +0000 | [diff] [blame] | 2669 | bool | 
|  | 2670 | llvm::CC_PPC32_SVR4_Custom_SkipLastArgRegsPPCF128(unsigned &ValNo, MVT &ValVT, | 
|  | 2671 | MVT &LocVT, | 
|  | 2672 | CCValAssign::LocInfo &LocInfo, | 
|  | 2673 | ISD::ArgFlagsTy &ArgFlags, | 
|  | 2674 | CCState &State) { | 
|  | 2675 | static const MCPhysReg ArgRegs[] = { | 
|  | 2676 | PPC::R3, PPC::R4, PPC::R5, PPC::R6, | 
|  | 2677 | PPC::R7, PPC::R8, PPC::R9, PPC::R10, | 
|  | 2678 | }; | 
|  | 2679 | const unsigned NumArgRegs = array_lengthof(ArgRegs); | 
|  | 2680 |  | 
|  | 2681 | unsigned RegNum = State.getFirstUnallocated(ArgRegs); | 
|  | 2682 | int RegsLeft = NumArgRegs - RegNum; | 
|  | 2683 |  | 
|  | 2684 | // Skip if there is not enough registers left for long double type (4 gpr regs | 
|  | 2685 | // in soft float mode) and put long double argument on the stack. | 
|  | 2686 | if (RegNum != NumArgRegs && RegsLeft < 4) { | 
|  | 2687 | for (int i = 0; i < RegsLeft; i++) { | 
|  | 2688 | State.AllocateReg(ArgRegs[RegNum + i]); | 
|  | 2689 | } | 
|  | 2690 | } | 
|  | 2691 |  | 
|  | 2692 | return false; | 
|  | 2693 | } | 
|  | 2694 |  | 
| Bill Schmidt | 230b451 | 2013-06-12 16:39:22 +0000 | [diff] [blame] | 2695 | bool llvm::CC_PPC32_SVR4_Custom_AlignFPArgRegs(unsigned &ValNo, MVT &ValVT, | 
|  | 2696 | MVT &LocVT, | 
|  | 2697 | CCValAssign::LocInfo &LocInfo, | 
|  | 2698 | ISD::ArgFlagsTy &ArgFlags, | 
|  | 2699 | CCState &State) { | 
| Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 2700 | static const MCPhysReg ArgRegs[] = { | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2701 | PPC::F1, PPC::F2, PPC::F3, PPC::F4, PPC::F5, PPC::F6, PPC::F7, | 
|  | 2702 | PPC::F8 | 
|  | 2703 | }; | 
|  | 2704 |  | 
|  | 2705 | const unsigned NumArgRegs = array_lengthof(ArgRegs); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2706 |  | 
| Tim Northover | 3b6b7ca | 2015-02-21 02:11:17 +0000 | [diff] [blame] | 2707 | unsigned RegNum = State.getFirstUnallocated(ArgRegs); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2708 |  | 
|  | 2709 | // If there is only one Floating-point register left we need to put both f64 | 
|  | 2710 | // values of a split ppc_fp128 value on the stack. | 
|  | 2711 | if (RegNum != NumArgRegs && ArgRegs[RegNum] == PPC::F8) { | 
|  | 2712 | State.AllocateReg(ArgRegs[RegNum]); | 
|  | 2713 | } | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2714 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2715 | // Always return false here, as this function only makes sure that the two f64 | 
|  | 2716 | // values a ppc_fp128 value is split into are both passed in registers or both | 
|  | 2717 | // passed on the stack and does not actually allocate a register for the | 
|  | 2718 | // current argument. | 
|  | 2719 | return false; | 
|  | 2720 | } | 
|  | 2721 |  | 
| Benjamin Kramer | 7149aab | 2015-03-01 18:09:56 +0000 | [diff] [blame] | 2722 | /// FPR - The set of FP registers that should be allocated for arguments, | 
| Tilmann Scheller | d1aaa32 | 2009-08-15 11:54:46 +0000 | [diff] [blame] | 2723 | /// on Darwin. | 
| Benjamin Kramer | 7149aab | 2015-03-01 18:09:56 +0000 | [diff] [blame] | 2724 | static const MCPhysReg FPR[] = {PPC::F1,  PPC::F2,  PPC::F3, PPC::F4, PPC::F5, | 
|  | 2725 | PPC::F6,  PPC::F7,  PPC::F8, PPC::F9, PPC::F10, | 
|  | 2726 | PPC::F11, PPC::F12, PPC::F13}; | 
| Tilmann Scheller | d1aaa32 | 2009-08-15 11:54:46 +0000 | [diff] [blame] | 2727 |  | 
| Benjamin Kramer | 7149aab | 2015-03-01 18:09:56 +0000 | [diff] [blame] | 2728 | /// QFPR - The set of QPX registers that should be allocated for arguments. | 
|  | 2729 | static const MCPhysReg QFPR[] = { | 
|  | 2730 | PPC::QF1, PPC::QF2, PPC::QF3,  PPC::QF4,  PPC::QF5,  PPC::QF6, PPC::QF7, | 
|  | 2731 | PPC::QF8, PPC::QF9, PPC::QF10, PPC::QF11, PPC::QF12, PPC::QF13}; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 2732 |  | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 2733 | /// CalculateStackSlotSize - Calculates the size reserved for this argument on | 
|  | 2734 | /// the stack. | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2735 | static unsigned CalculateStackSlotSize(EVT ArgVT, ISD::ArgFlagsTy Flags, | 
| Tilmann Scheller | 98bdaaa | 2009-07-03 06:43:35 +0000 | [diff] [blame] | 2736 | unsigned PtrByteSize) { | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 2737 | unsigned ArgSize = ArgVT.getStoreSize(); | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 2738 | if (Flags.isByVal()) | 
|  | 2739 | ArgSize = Flags.getByValSize(); | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 2740 |  | 
|  | 2741 | // Round up to multiples of the pointer size, except for array members, | 
|  | 2742 | // which are always packed. | 
|  | 2743 | if (!Flags.isInConsecutiveRegs()) | 
|  | 2744 | ArgSize = ((ArgSize + PtrByteSize - 1)/PtrByteSize) * PtrByteSize; | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 2745 |  | 
|  | 2746 | return ArgSize; | 
|  | 2747 | } | 
| Ulrich Weigand | ec2bf93 | 2014-07-07 19:26:41 +0000 | [diff] [blame] | 2748 |  | 
|  | 2749 | /// CalculateStackSlotAlignment - Calculates the alignment of this argument | 
|  | 2750 | /// on the stack. | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 2751 | static unsigned CalculateStackSlotAlignment(EVT ArgVT, EVT OrigVT, | 
|  | 2752 | ISD::ArgFlagsTy Flags, | 
| Ulrich Weigand | ec2bf93 | 2014-07-07 19:26:41 +0000 | [diff] [blame] | 2753 | unsigned PtrByteSize) { | 
|  | 2754 | unsigned Align = PtrByteSize; | 
|  | 2755 |  | 
|  | 2756 | // Altivec parameters are padded to a 16 byte boundary. | 
|  | 2757 | if (ArgVT == MVT::v4f32 || ArgVT == MVT::v4i32 || | 
|  | 2758 | ArgVT == MVT::v8i16 || ArgVT == MVT::v16i8 || | 
| Kit Barton | d4eb73c | 2015-05-05 16:10:44 +0000 | [diff] [blame] | 2759 | ArgVT == MVT::v2f64 || ArgVT == MVT::v2i64 || | 
|  | 2760 | ArgVT == MVT::v1i128) | 
| Ulrich Weigand | ec2bf93 | 2014-07-07 19:26:41 +0000 | [diff] [blame] | 2761 | Align = 16; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 2762 | // QPX vector types stored in double-precision are padded to a 32 byte | 
|  | 2763 | // boundary. | 
|  | 2764 | else if (ArgVT == MVT::v4f64 || ArgVT == MVT::v4i1) | 
|  | 2765 | Align = 32; | 
| Ulrich Weigand | ec2bf93 | 2014-07-07 19:26:41 +0000 | [diff] [blame] | 2766 |  | 
|  | 2767 | // ByVal parameters are aligned as requested. | 
|  | 2768 | if (Flags.isByVal()) { | 
|  | 2769 | unsigned BVAlign = Flags.getByValAlign(); | 
|  | 2770 | if (BVAlign > PtrByteSize) { | 
|  | 2771 | if (BVAlign % PtrByteSize != 0) | 
|  | 2772 | llvm_unreachable( | 
|  | 2773 | "ByVal alignment is not a multiple of the pointer size"); | 
|  | 2774 |  | 
|  | 2775 | Align = BVAlign; | 
|  | 2776 | } | 
|  | 2777 | } | 
|  | 2778 |  | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 2779 | // Array members are always packed to their original alignment. | 
|  | 2780 | if (Flags.isInConsecutiveRegs()) { | 
|  | 2781 | // If the array member was split into multiple registers, the first | 
|  | 2782 | // needs to be aligned to the size of the full type.  (Except for | 
|  | 2783 | // ppcf128, which is only aligned as its f64 components.) | 
|  | 2784 | if (Flags.isSplit() && OrigVT != MVT::ppcf128) | 
|  | 2785 | Align = OrigVT.getStoreSize(); | 
|  | 2786 | else | 
|  | 2787 | Align = ArgVT.getStoreSize(); | 
|  | 2788 | } | 
|  | 2789 |  | 
| Ulrich Weigand | ec2bf93 | 2014-07-07 19:26:41 +0000 | [diff] [blame] | 2790 | return Align; | 
|  | 2791 | } | 
|  | 2792 |  | 
| Ulrich Weigand | 8658f17 | 2014-07-20 23:43:15 +0000 | [diff] [blame] | 2793 | /// CalculateStackSlotUsed - Return whether this argument will use its | 
|  | 2794 | /// stack slot (instead of being passed in registers).  ArgOffset, | 
|  | 2795 | /// AvailableFPRs, and AvailableVRs must hold the current argument | 
|  | 2796 | /// position, and will be updated to account for this argument. | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 2797 | static bool CalculateStackSlotUsed(EVT ArgVT, EVT OrigVT, | 
|  | 2798 | ISD::ArgFlagsTy Flags, | 
| Ulrich Weigand | 8658f17 | 2014-07-20 23:43:15 +0000 | [diff] [blame] | 2799 | unsigned PtrByteSize, | 
|  | 2800 | unsigned LinkageSize, | 
|  | 2801 | unsigned ParamAreaSize, | 
|  | 2802 | unsigned &ArgOffset, | 
|  | 2803 | unsigned &AvailableFPRs, | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 2804 | unsigned &AvailableVRs, bool HasQPX) { | 
| Ulrich Weigand | 8658f17 | 2014-07-20 23:43:15 +0000 | [diff] [blame] | 2805 | bool UseMemory = false; | 
|  | 2806 |  | 
|  | 2807 | // Respect alignment of argument on the stack. | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 2808 | unsigned Align = | 
|  | 2809 | CalculateStackSlotAlignment(ArgVT, OrigVT, Flags, PtrByteSize); | 
| Ulrich Weigand | 8658f17 | 2014-07-20 23:43:15 +0000 | [diff] [blame] | 2810 | ArgOffset = ((ArgOffset + Align - 1) / Align) * Align; | 
|  | 2811 | // If there's no space left in the argument save area, we must | 
|  | 2812 | // use memory (this check also catches zero-sized arguments). | 
|  | 2813 | if (ArgOffset >= LinkageSize + ParamAreaSize) | 
|  | 2814 | UseMemory = true; | 
|  | 2815 |  | 
|  | 2816 | // Allocate argument on the stack. | 
|  | 2817 | ArgOffset += CalculateStackSlotSize(ArgVT, Flags, PtrByteSize); | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 2818 | if (Flags.isInConsecutiveRegsLast()) | 
|  | 2819 | ArgOffset = ((ArgOffset + PtrByteSize - 1)/PtrByteSize) * PtrByteSize; | 
| Ulrich Weigand | 8658f17 | 2014-07-20 23:43:15 +0000 | [diff] [blame] | 2820 | // If we overran the argument save area, we must use memory | 
|  | 2821 | // (this check catches arguments passed partially in memory) | 
|  | 2822 | if (ArgOffset > LinkageSize + ParamAreaSize) | 
|  | 2823 | UseMemory = true; | 
|  | 2824 |  | 
|  | 2825 | // However, if the argument is actually passed in an FPR or a VR, | 
|  | 2826 | // we don't use memory after all. | 
|  | 2827 | if (!Flags.isByVal()) { | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 2828 | if (ArgVT == MVT::f32 || ArgVT == MVT::f64 || | 
|  | 2829 | // QPX registers overlap with the scalar FP registers. | 
|  | 2830 | (HasQPX && (ArgVT == MVT::v4f32 || | 
|  | 2831 | ArgVT == MVT::v4f64 || | 
|  | 2832 | ArgVT == MVT::v4i1))) | 
| Ulrich Weigand | 8658f17 | 2014-07-20 23:43:15 +0000 | [diff] [blame] | 2833 | if (AvailableFPRs > 0) { | 
|  | 2834 | --AvailableFPRs; | 
|  | 2835 | return false; | 
|  | 2836 | } | 
|  | 2837 | if (ArgVT == MVT::v4f32 || ArgVT == MVT::v4i32 || | 
|  | 2838 | ArgVT == MVT::v8i16 || ArgVT == MVT::v16i8 || | 
| Kit Barton | d4eb73c | 2015-05-05 16:10:44 +0000 | [diff] [blame] | 2839 | ArgVT == MVT::v2f64 || ArgVT == MVT::v2i64 || | 
|  | 2840 | ArgVT == MVT::v1i128) | 
| Ulrich Weigand | 8658f17 | 2014-07-20 23:43:15 +0000 | [diff] [blame] | 2841 | if (AvailableVRs > 0) { | 
|  | 2842 | --AvailableVRs; | 
|  | 2843 | return false; | 
|  | 2844 | } | 
|  | 2845 | } | 
|  | 2846 |  | 
|  | 2847 | return UseMemory; | 
|  | 2848 | } | 
|  | 2849 |  | 
| Ulrich Weigand | 2bffb95 | 2014-06-23 13:08:27 +0000 | [diff] [blame] | 2850 | /// EnsureStackAlignment - Round stack frame size up from NumBytes to | 
|  | 2851 | /// ensure minimum alignment required for target. | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 2852 | static unsigned EnsureStackAlignment(const PPCFrameLowering *Lowering, | 
| Ulrich Weigand | 2bffb95 | 2014-06-23 13:08:27 +0000 | [diff] [blame] | 2853 | unsigned NumBytes) { | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 2854 | unsigned TargetAlign = Lowering->getStackAlignment(); | 
| Ulrich Weigand | 2bffb95 | 2014-06-23 13:08:27 +0000 | [diff] [blame] | 2855 | unsigned AlignMask = TargetAlign - 1; | 
|  | 2856 | NumBytes = (NumBytes + AlignMask) & ~AlignMask; | 
|  | 2857 | return NumBytes; | 
|  | 2858 | } | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 2859 |  | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 2860 | SDValue PPCTargetLowering::LowerFormalArguments( | 
|  | 2861 | SDValue Chain, CallingConv::ID CallConv, bool isVarArg, | 
|  | 2862 | const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl, | 
|  | 2863 | SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const { | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 2864 | if (Subtarget.isSVR4ABI()) { | 
|  | 2865 | if (Subtarget.isPPC64()) | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 2866 | return LowerFormalArguments_64SVR4(Chain, CallConv, isVarArg, Ins, | 
|  | 2867 | dl, DAG, InVals); | 
|  | 2868 | else | 
|  | 2869 | return LowerFormalArguments_32SVR4(Chain, CallConv, isVarArg, Ins, | 
|  | 2870 | dl, DAG, InVals); | 
| Bill Schmidt | 019cc6f | 2012-09-19 15:42:13 +0000 | [diff] [blame] | 2871 | } else { | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 2872 | return LowerFormalArguments_Darwin(Chain, CallConv, isVarArg, Ins, | 
|  | 2873 | dl, DAG, InVals); | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2874 | } | 
|  | 2875 | } | 
|  | 2876 |  | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 2877 | SDValue PPCTargetLowering::LowerFormalArguments_32SVR4( | 
|  | 2878 | SDValue Chain, CallingConv::ID CallConv, bool isVarArg, | 
|  | 2879 | const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl, | 
|  | 2880 | SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const { | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2881 |  | 
| Tilmann Scheller | d1aaa32 | 2009-08-15 11:54:46 +0000 | [diff] [blame] | 2882 | // 32-bit SVR4 ABI Stack Frame Layout: | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2883 | //              +-----------------------------------+ | 
|  | 2884 | //        +-->  |            Back chain             | | 
|  | 2885 | //        |     +-----------------------------------+ | 
|  | 2886 | //        |     | Floating-point register save area | | 
|  | 2887 | //        |     +-----------------------------------+ | 
|  | 2888 | //        |     |    General register save area     | | 
|  | 2889 | //        |     +-----------------------------------+ | 
|  | 2890 | //        |     |          CR save word             | | 
|  | 2891 | //        |     +-----------------------------------+ | 
|  | 2892 | //        |     |         VRSAVE save word          | | 
|  | 2893 | //        |     +-----------------------------------+ | 
|  | 2894 | //        |     |         Alignment padding         | | 
|  | 2895 | //        |     +-----------------------------------+ | 
|  | 2896 | //        |     |     Vector register save area     | | 
|  | 2897 | //        |     +-----------------------------------+ | 
|  | 2898 | //        |     |       Local variable space        | | 
|  | 2899 | //        |     +-----------------------------------+ | 
|  | 2900 | //        |     |        Parameter list area        | | 
|  | 2901 | //        |     +-----------------------------------+ | 
|  | 2902 | //        |     |           LR save word            | | 
|  | 2903 | //        |     +-----------------------------------+ | 
|  | 2904 | // SP-->  +---  |            Back chain             | | 
|  | 2905 | //              +-----------------------------------+ | 
|  | 2906 | // | 
|  | 2907 | // Specifications: | 
|  | 2908 | //   System V Application Binary Interface PowerPC Processor Supplement | 
|  | 2909 | //   AltiVec Technology Programming Interface Manual | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2910 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2911 | MachineFunction &MF = DAG.getMachineFunction(); | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 2912 | MachineFrameInfo &MFI = MF.getFrameInfo(); | 
| Dan Gohman | 31ae586 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2913 | PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>(); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2914 |  | 
| Eric Christopher | cd71946 | 2016-07-07 01:49:59 +0000 | [diff] [blame] | 2915 | EVT PtrVT = getPointerTy(MF.getDataLayout()); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2916 | // Potential tail calls could cause overwriting of argument stack slots. | 
| Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 2917 | bool isImmutable = !(getTargetMachine().Options.GuaranteedTailCallOpt && | 
|  | 2918 | (CallConv == CallingConv::Fast)); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2919 | unsigned PtrByteSize = 4; | 
|  | 2920 |  | 
|  | 2921 | // Assign locations to all of the incoming arguments. | 
|  | 2922 | SmallVector<CCValAssign, 16> ArgLocs; | 
| Strahinja Petrovic | e682b80 | 2016-05-09 12:27:39 +0000 | [diff] [blame] | 2923 | PPCCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs, | 
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 2924 | *DAG.getContext()); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2925 |  | 
|  | 2926 | // Reserve space for the linkage area on the stack. | 
| Eric Christopher | a4ae213 | 2015-02-13 22:22:57 +0000 | [diff] [blame] | 2927 | unsigned LinkageSize = Subtarget.getFrameLowering()->getLinkageSize(); | 
| Ulrich Weigand | 8ca988f | 2014-06-23 14:15:53 +0000 | [diff] [blame] | 2928 | CCInfo.AllocateStack(LinkageSize, PtrByteSize); | 
| Eric Christopher | 317df66 | 2016-07-07 01:49:57 +0000 | [diff] [blame] | 2929 | if (useSoftFloat()) | 
| Strahinja Petrovic | e682b80 | 2016-05-09 12:27:39 +0000 | [diff] [blame] | 2930 | CCInfo.PreAnalyzeFormalArguments(Ins); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2931 |  | 
| Bill Schmidt | ef17c14 | 2013-02-06 17:33:58 +0000 | [diff] [blame] | 2932 | CCInfo.AnalyzeFormalArguments(Ins, CC_PPC32_SVR4); | 
| Strahinja Petrovic | e682b80 | 2016-05-09 12:27:39 +0000 | [diff] [blame] | 2933 | CCInfo.clearWasPPCF128(); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2934 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2935 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { | 
|  | 2936 | CCValAssign &VA = ArgLocs[i]; | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2937 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2938 | // Arguments stored in registers. | 
|  | 2939 | if (VA.isRegLoc()) { | 
| Craig Topper | 760b134 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2940 | const TargetRegisterClass *RC; | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2941 | EVT ValVT = VA.getValVT(); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2942 |  | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2943 | switch (ValVT.getSimpleVT().SimpleTy) { | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2944 | default: | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2945 | llvm_unreachable("ValVT not supported by formal arguments Lowering"); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 2946 | case MVT::i1: | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2947 | case MVT::i32: | 
| Craig Topper | abadc66 | 2012-04-20 06:31:50 +0000 | [diff] [blame] | 2948 | RC = &PPC::GPRCRegClass; | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2949 | break; | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2950 | case MVT::f32: | 
| Nemanja Ivanovic | f3c94b1 | 2015-05-07 18:24:05 +0000 | [diff] [blame] | 2951 | if (Subtarget.hasP8Vector()) | 
|  | 2952 | RC = &PPC::VSSRCRegClass; | 
|  | 2953 | else | 
|  | 2954 | RC = &PPC::F4RCRegClass; | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2955 | break; | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2956 | case MVT::f64: | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 2957 | if (Subtarget.hasVSX()) | 
| Hal Finkel | 19be506 | 2014-03-29 05:29:01 +0000 | [diff] [blame] | 2958 | RC = &PPC::VSFRCRegClass; | 
|  | 2959 | else | 
|  | 2960 | RC = &PPC::F8RCRegClass; | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2961 | break; | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2962 | case MVT::v16i8: | 
|  | 2963 | case MVT::v8i16: | 
|  | 2964 | case MVT::v4i32: | 
| Hal Finkel | 7811c61 | 2014-03-28 19:58:11 +0000 | [diff] [blame] | 2965 | RC = &PPC::VRRCRegClass; | 
|  | 2966 | break; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 2967 | case MVT::v4f32: | 
|  | 2968 | RC = Subtarget.hasQPX() ? &PPC::QSRCRegClass : &PPC::VRRCRegClass; | 
|  | 2969 | break; | 
| Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 2970 | case MVT::v2f64: | 
| Hal Finkel | a6c8b51 | 2014-03-26 16:12:58 +0000 | [diff] [blame] | 2971 | case MVT::v2i64: | 
| Hal Finkel | 7811c61 | 2014-03-28 19:58:11 +0000 | [diff] [blame] | 2972 | RC = &PPC::VSHRCRegClass; | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2973 | break; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 2974 | case MVT::v4f64: | 
|  | 2975 | RC = &PPC::QFRCRegClass; | 
|  | 2976 | break; | 
|  | 2977 | case MVT::v4i1: | 
|  | 2978 | RC = &PPC::QBRCRegClass; | 
|  | 2979 | break; | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2980 | } | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2981 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2982 | // Transform the arguments stored in physical registers into virtual ones. | 
| Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2983 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 2984 | SDValue ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, | 
|  | 2985 | ValVT == MVT::i1 ? MVT::i32 : ValVT); | 
|  | 2986 |  | 
|  | 2987 | if (ValVT == MVT::i1) | 
|  | 2988 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, MVT::i1, ArgValue); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2989 |  | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2990 | InVals.push_back(ArgValue); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2991 | } else { | 
|  | 2992 | // Argument stored in memory. | 
|  | 2993 | assert(VA.isMemLoc()); | 
|  | 2994 |  | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 2995 | unsigned ArgSize = VA.getLocVT().getStoreSize(); | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 2996 | int FI = MFI.CreateFixedObject(ArgSize, VA.getLocMemOffset(), | 
|  | 2997 | isImmutable); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 2998 |  | 
|  | 2999 | // Create load nodes to retrieve arguments from the stack. | 
|  | 3000 | SDValue FIN = DAG.getFrameIndex(FI, PtrVT); | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 3001 | InVals.push_back( | 
|  | 3002 | DAG.getLoad(VA.getValVT(), dl, Chain, FIN, MachinePointerInfo())); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3003 | } | 
|  | 3004 | } | 
|  | 3005 |  | 
|  | 3006 | // Assign locations to all of the incoming aggregate by value arguments. | 
|  | 3007 | // Aggregates passed by value are stored in the local variable space of the | 
|  | 3008 | // caller's stack frame, right above the parameter list area. | 
|  | 3009 | SmallVector<CCValAssign, 16> ByValArgLocs; | 
| Eric Christopher | 0713a9d | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 3010 | CCState CCByValInfo(CallConv, isVarArg, DAG.getMachineFunction(), | 
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 3011 | ByValArgLocs, *DAG.getContext()); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3012 |  | 
|  | 3013 | // Reserve stack space for the allocations in CCInfo. | 
|  | 3014 | CCByValInfo.AllocateStack(CCInfo.getNextStackOffset(), PtrByteSize); | 
|  | 3015 |  | 
| Bill Schmidt | ef17c14 | 2013-02-06 17:33:58 +0000 | [diff] [blame] | 3016 | CCByValInfo.AnalyzeFormalArguments(Ins, CC_PPC32_SVR4_ByVal); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3017 |  | 
|  | 3018 | // Area that is at least reserved in the caller of this function. | 
|  | 3019 | unsigned MinReservedArea = CCByValInfo.getNextStackOffset(); | 
| Ulrich Weigand | 8ca988f | 2014-06-23 14:15:53 +0000 | [diff] [blame] | 3020 | MinReservedArea = std::max(MinReservedArea, LinkageSize); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3021 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3022 | // Set the size that is at least reserved in caller of this function.  Tail | 
|  | 3023 | // call optimized function's reserved stack space needs to be aligned so that | 
|  | 3024 | // taking the difference between two stack areas will result in an aligned | 
|  | 3025 | // stack. | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 3026 | MinReservedArea = | 
|  | 3027 | EnsureStackAlignment(Subtarget.getFrameLowering(), MinReservedArea); | 
| Ulrich Weigand | 2bffb95 | 2014-06-23 13:08:27 +0000 | [diff] [blame] | 3028 | FuncInfo->setMinReservedArea(MinReservedArea); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3029 |  | 
|  | 3030 | SmallVector<SDValue, 8> MemOps; | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3031 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3032 | // If the function takes variable number of arguments, make a frame index for | 
|  | 3033 | // the start of the first vararg value... for expansion of llvm.va_start. | 
|  | 3034 | if (isVarArg) { | 
| Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 3035 | static const MCPhysReg GPArgRegs[] = { | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3036 | PPC::R3, PPC::R4, PPC::R5, PPC::R6, | 
|  | 3037 | PPC::R7, PPC::R8, PPC::R9, PPC::R10, | 
|  | 3038 | }; | 
|  | 3039 | const unsigned NumGPArgRegs = array_lengthof(GPArgRegs); | 
|  | 3040 |  | 
| Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 3041 | static const MCPhysReg FPArgRegs[] = { | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3042 | PPC::F1, PPC::F2, PPC::F3, PPC::F4, PPC::F5, PPC::F6, PPC::F7, | 
|  | 3043 | PPC::F8 | 
|  | 3044 | }; | 
| Joerg Sonnenberger | eb8655a | 2014-08-08 16:46:10 +0000 | [diff] [blame] | 3045 | unsigned NumFPArgRegs = array_lengthof(FPArgRegs); | 
| Petar Jovanovic | 280f710 | 2015-12-14 17:57:33 +0000 | [diff] [blame] | 3046 |  | 
| Eric Christopher | 317df66 | 2016-07-07 01:49:57 +0000 | [diff] [blame] | 3047 | if (useSoftFloat()) | 
| Petar Jovanovic | 280f710 | 2015-12-14 17:57:33 +0000 | [diff] [blame] | 3048 | NumFPArgRegs = 0; | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3049 |  | 
| Tim Northover | 3b6b7ca | 2015-02-21 02:11:17 +0000 | [diff] [blame] | 3050 | FuncInfo->setVarArgsNumGPR(CCInfo.getFirstUnallocated(GPArgRegs)); | 
|  | 3051 | FuncInfo->setVarArgsNumFPR(CCInfo.getFirstUnallocated(FPArgRegs)); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3052 |  | 
|  | 3053 | // Make room for NumGPArgRegs and NumFPArgRegs. | 
|  | 3054 | int Depth = NumGPArgRegs * PtrVT.getSizeInBits()/8 + | 
| Craig Topper | 7ff1592 | 2014-09-10 04:51:36 +0000 | [diff] [blame] | 3055 | NumFPArgRegs * MVT(MVT::f64).getSizeInBits()/8; | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3056 |  | 
| Dan Gohman | 31ae586 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 3057 | FuncInfo->setVarArgsStackOffset( | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 3058 | MFI.CreateFixedObject(PtrVT.getSizeInBits()/8, | 
|  | 3059 | CCInfo.getNextStackOffset(), true)); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3060 |  | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 3061 | FuncInfo->setVarArgsFrameIndex(MFI.CreateStackObject(Depth, 8, false)); | 
| Dan Gohman | 31ae586 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 3062 | SDValue FIN = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3063 |  | 
| Jakob Stoklund Olesen | 6c4353e | 2010-10-11 20:43:09 +0000 | [diff] [blame] | 3064 | // The fixed integer arguments of a variadic function are stored to the | 
| Nick Lewycky | 9980075 | 2016-06-28 01:45:05 +0000 | [diff] [blame] | 3065 | // VarArgsFrameIndex on the stack so that they may be loaded by | 
|  | 3066 | // dereferencing the result of va_next. | 
| Jakob Stoklund Olesen | 6c4353e | 2010-10-11 20:43:09 +0000 | [diff] [blame] | 3067 | for (unsigned GPRIndex = 0; GPRIndex != NumGPArgRegs; ++GPRIndex) { | 
|  | 3068 | // Get an existing live-in vreg, or add a new one. | 
|  | 3069 | unsigned VReg = MF.getRegInfo().getLiveInVirtReg(GPArgRegs[GPRIndex]); | 
|  | 3070 | if (!VReg) | 
| Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 3071 | VReg = MF.addLiveIn(GPArgRegs[GPRIndex], &PPC::GPRCRegClass); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3072 |  | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3073 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, PtrVT); | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 3074 | SDValue Store = | 
|  | 3075 | DAG.getStore(Val.getValue(1), dl, Val, FIN, MachinePointerInfo()); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3076 | MemOps.push_back(Store); | 
|  | 3077 | // Increment the address by four for the next argument to store | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3078 | SDValue PtrOff = DAG.getConstant(PtrVT.getSizeInBits()/8, dl, PtrVT); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3079 | FIN = DAG.getNode(ISD::ADD, dl, PtrOff.getValueType(), FIN, PtrOff); | 
|  | 3080 | } | 
|  | 3081 |  | 
| Tilmann Scheller | d1aaa32 | 2009-08-15 11:54:46 +0000 | [diff] [blame] | 3082 | // FIXME 32-bit SVR4: We only need to save FP argument registers if CR bit 6 | 
|  | 3083 | // is set. | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3084 | // The double arguments are stored to the VarArgsFrameIndex | 
|  | 3085 | // on the stack. | 
| Jakob Stoklund Olesen | 6c4353e | 2010-10-11 20:43:09 +0000 | [diff] [blame] | 3086 | for (unsigned FPRIndex = 0; FPRIndex != NumFPArgRegs; ++FPRIndex) { | 
|  | 3087 | // Get an existing live-in vreg, or add a new one. | 
|  | 3088 | unsigned VReg = MF.getRegInfo().getLiveInVirtReg(FPArgRegs[FPRIndex]); | 
|  | 3089 | if (!VReg) | 
| Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 3090 | VReg = MF.addLiveIn(FPArgRegs[FPRIndex], &PPC::F8RCRegClass); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3091 |  | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3092 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, MVT::f64); | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 3093 | SDValue Store = | 
|  | 3094 | DAG.getStore(Val.getValue(1), dl, Val, FIN, MachinePointerInfo()); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3095 | MemOps.push_back(Store); | 
|  | 3096 | // Increment the address by eight for the next argument to store | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3097 | SDValue PtrOff = DAG.getConstant(MVT(MVT::f64).getSizeInBits()/8, dl, | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3098 | PtrVT); | 
|  | 3099 | FIN = DAG.getNode(ISD::ADD, dl, PtrOff.getValueType(), FIN, PtrOff); | 
|  | 3100 | } | 
|  | 3101 | } | 
|  | 3102 |  | 
|  | 3103 | if (!MemOps.empty()) | 
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 3104 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOps); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3105 |  | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3106 | return Chain; | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 3107 | } | 
|  | 3108 |  | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 3109 | // PPC64 passes i8, i16, and i32 values in i64 registers. Promote | 
|  | 3110 | // value to MVT::i64 and then truncate to the correct register size. | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 3111 | SDValue PPCTargetLowering::extendArgForPPC64(ISD::ArgFlagsTy Flags, | 
|  | 3112 | EVT ObjectVT, SelectionDAG &DAG, | 
|  | 3113 | SDValue ArgVal, | 
|  | 3114 | const SDLoc &dl) const { | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 3115 | if (Flags.isSExt()) | 
|  | 3116 | ArgVal = DAG.getNode(ISD::AssertSext, dl, MVT::i64, ArgVal, | 
|  | 3117 | DAG.getValueType(ObjectVT)); | 
|  | 3118 | else if (Flags.isZExt()) | 
|  | 3119 | ArgVal = DAG.getNode(ISD::AssertZext, dl, MVT::i64, ArgVal, | 
|  | 3120 | DAG.getValueType(ObjectVT)); | 
| Matt Arsenault | 75865923 | 2013-05-18 00:21:46 +0000 | [diff] [blame] | 3121 |  | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 3122 | return DAG.getNode(ISD::TRUNCATE, dl, ObjectVT, ArgVal); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 3123 | } | 
|  | 3124 |  | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 3125 | SDValue PPCTargetLowering::LowerFormalArguments_64SVR4( | 
|  | 3126 | SDValue Chain, CallingConv::ID CallConv, bool isVarArg, | 
|  | 3127 | const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl, | 
|  | 3128 | SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const { | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3129 | // TODO: add description of PPC stack frame format, or at least some docs. | 
|  | 3130 | // | 
| Ulrich Weigand | 8658f17 | 2014-07-20 23:43:15 +0000 | [diff] [blame] | 3131 | bool isELFv2ABI = Subtarget.isELFv2ABI(); | 
| Ulrich Weigand | 59c6ab2 | 2014-06-20 16:34:05 +0000 | [diff] [blame] | 3132 | bool isLittleEndian = Subtarget.isLittleEndian(); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3133 | MachineFunction &MF = DAG.getMachineFunction(); | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 3134 | MachineFrameInfo &MFI = MF.getFrameInfo(); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3135 | PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>(); | 
|  | 3136 |  | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 3137 | assert(!(CallConv == CallingConv::Fast && isVarArg) && | 
|  | 3138 | "fastcc not supported on varargs functions"); | 
|  | 3139 |  | 
| Eric Christopher | cd71946 | 2016-07-07 01:49:59 +0000 | [diff] [blame] | 3140 | EVT PtrVT = getPointerTy(MF.getDataLayout()); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3141 | // Potential tail calls could cause overwriting of argument stack slots. | 
|  | 3142 | bool isImmutable = !(getTargetMachine().Options.GuaranteedTailCallOpt && | 
|  | 3143 | (CallConv == CallingConv::Fast)); | 
|  | 3144 | unsigned PtrByteSize = 8; | 
| Eric Christopher | a4ae213 | 2015-02-13 22:22:57 +0000 | [diff] [blame] | 3145 | unsigned LinkageSize = Subtarget.getFrameLowering()->getLinkageSize(); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3146 |  | 
| Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 3147 | static const MCPhysReg GPR[] = { | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3148 | PPC::X3, PPC::X4, PPC::X5, PPC::X6, | 
|  | 3149 | PPC::X7, PPC::X8, PPC::X9, PPC::X10, | 
|  | 3150 | }; | 
| Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 3151 | static const MCPhysReg VR[] = { | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3152 | PPC::V2, PPC::V3, PPC::V4, PPC::V5, PPC::V6, PPC::V7, PPC::V8, | 
|  | 3153 | PPC::V9, PPC::V10, PPC::V11, PPC::V12, PPC::V13 | 
|  | 3154 | }; | 
| Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 3155 | static const MCPhysReg VSRH[] = { | 
| Hal Finkel | 7811c61 | 2014-03-28 19:58:11 +0000 | [diff] [blame] | 3156 | PPC::VSH2, PPC::VSH3, PPC::VSH4, PPC::VSH5, PPC::VSH6, PPC::VSH7, PPC::VSH8, | 
|  | 3157 | PPC::VSH9, PPC::VSH10, PPC::VSH11, PPC::VSH12, PPC::VSH13 | 
|  | 3158 | }; | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3159 |  | 
|  | 3160 | const unsigned Num_GPR_Regs = array_lengthof(GPR); | 
|  | 3161 | const unsigned Num_FPR_Regs = 13; | 
|  | 3162 | const unsigned Num_VR_Regs  = array_lengthof(VR); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 3163 | const unsigned Num_QFPR_Regs = Num_FPR_Regs; | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3164 |  | 
| Ulrich Weigand | 8658f17 | 2014-07-20 23:43:15 +0000 | [diff] [blame] | 3165 | // Do a first pass over the arguments to determine whether the ABI | 
|  | 3166 | // guarantees that our caller has allocated the parameter save area | 
|  | 3167 | // on its stack frame.  In the ELFv1 ABI, this is always the case; | 
|  | 3168 | // in the ELFv2 ABI, it is true if this is a vararg function or if | 
|  | 3169 | // any parameter is located in a stack slot. | 
|  | 3170 |  | 
|  | 3171 | bool HasParameterArea = !isELFv2ABI || isVarArg; | 
|  | 3172 | unsigned ParamAreaSize = Num_GPR_Regs * PtrByteSize; | 
|  | 3173 | unsigned NumBytes = LinkageSize; | 
|  | 3174 | unsigned AvailableFPRs = Num_FPR_Regs; | 
|  | 3175 | unsigned AvailableVRs = Num_VR_Regs; | 
| Hal Finkel | 965cea5 | 2015-07-12 00:37:44 +0000 | [diff] [blame] | 3176 | for (unsigned i = 0, e = Ins.size(); i != e; ++i) { | 
|  | 3177 | if (Ins[i].Flags.isNest()) | 
|  | 3178 | continue; | 
|  | 3179 |  | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 3180 | if (CalculateStackSlotUsed(Ins[i].VT, Ins[i].ArgVT, Ins[i].Flags, | 
| Ulrich Weigand | 8658f17 | 2014-07-20 23:43:15 +0000 | [diff] [blame] | 3181 | PtrByteSize, LinkageSize, ParamAreaSize, | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 3182 | NumBytes, AvailableFPRs, AvailableVRs, | 
|  | 3183 | Subtarget.hasQPX())) | 
| Ulrich Weigand | 8658f17 | 2014-07-20 23:43:15 +0000 | [diff] [blame] | 3184 | HasParameterArea = true; | 
| Hal Finkel | 965cea5 | 2015-07-12 00:37:44 +0000 | [diff] [blame] | 3185 | } | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3186 |  | 
|  | 3187 | // Add DAG nodes to load the arguments or copy them out of registers.  On | 
|  | 3188 | // entry to a function on PPC, the arguments start after the linkage area, | 
|  | 3189 | // although the first ones are often in registers. | 
|  | 3190 |  | 
| Ulrich Weigand | 8658f17 | 2014-07-20 23:43:15 +0000 | [diff] [blame] | 3191 | unsigned ArgOffset = LinkageSize; | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 3192 | unsigned GPR_idx = 0, FPR_idx = 0, VR_idx = 0; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 3193 | unsigned &QFPR_idx = FPR_idx; | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3194 | SmallVector<SDValue, 8> MemOps; | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3195 | Function::const_arg_iterator FuncArg = MF.getFunction()->arg_begin(); | 
| Bill Schmidt | 6631e94 | 2013-02-20 17:31:41 +0000 | [diff] [blame] | 3196 | unsigned CurArgIdx = 0; | 
|  | 3197 | for (unsigned ArgNo = 0, e = Ins.size(); ArgNo != e; ++ArgNo) { | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3198 | SDValue ArgVal; | 
|  | 3199 | bool needsLoad = false; | 
|  | 3200 | EVT ObjectVT = Ins[ArgNo].VT; | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 3201 | EVT OrigVT = Ins[ArgNo].ArgVT; | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 3202 | unsigned ObjSize = ObjectVT.getStoreSize(); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3203 | unsigned ArgSize = ObjSize; | 
|  | 3204 | ISD::ArgFlagsTy Flags = Ins[ArgNo].Flags; | 
| Andrew Trick | 05938a5 | 2015-02-16 18:10:47 +0000 | [diff] [blame] | 3205 | if (Ins[ArgNo].isOrigArg()) { | 
|  | 3206 | std::advance(FuncArg, Ins[ArgNo].getOrigArgIndex() - CurArgIdx); | 
|  | 3207 | CurArgIdx = Ins[ArgNo].getOrigArgIndex(); | 
|  | 3208 | } | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 3209 | // We re-align the argument offset for each argument, except when using the | 
|  | 3210 | // fast calling convention, when we need to make sure we do that only when | 
|  | 3211 | // we'll actually use a stack slot. | 
|  | 3212 | unsigned CurArgOffset, Align; | 
|  | 3213 | auto ComputeArgOffset = [&]() { | 
|  | 3214 | /* Respect alignment of argument on the stack.  */ | 
|  | 3215 | Align = CalculateStackSlotAlignment(ObjectVT, OrigVT, Flags, PtrByteSize); | 
|  | 3216 | ArgOffset = ((ArgOffset + Align - 1) / Align) * Align; | 
|  | 3217 | CurArgOffset = ArgOffset; | 
|  | 3218 | }; | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3219 |  | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 3220 | if (CallConv != CallingConv::Fast) { | 
|  | 3221 | ComputeArgOffset(); | 
|  | 3222 |  | 
|  | 3223 | /* Compute GPR index associated with argument offset.  */ | 
|  | 3224 | GPR_idx = (ArgOffset - LinkageSize) / PtrByteSize; | 
|  | 3225 | GPR_idx = std::min(GPR_idx, Num_GPR_Regs); | 
|  | 3226 | } | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3227 |  | 
|  | 3228 | // FIXME the codegen can be much improved in some cases. | 
|  | 3229 | // We do not have to keep everything in memory. | 
|  | 3230 | if (Flags.isByVal()) { | 
| Andrew Trick | 05938a5 | 2015-02-16 18:10:47 +0000 | [diff] [blame] | 3231 | assert(Ins[ArgNo].isOrigArg() && "Byval arguments cannot be implicit"); | 
|  | 3232 |  | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 3233 | if (CallConv == CallingConv::Fast) | 
|  | 3234 | ComputeArgOffset(); | 
|  | 3235 |  | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3236 | // ObjSize is the true size, ArgSize rounded up to multiple of registers. | 
|  | 3237 | ObjSize = Flags.getByValSize(); | 
|  | 3238 | ArgSize = ((ObjSize + PtrByteSize - 1)/PtrByteSize) * PtrByteSize; | 
| Bill Schmidt | 9953cf2 | 2012-10-31 01:15:05 +0000 | [diff] [blame] | 3239 | // Empty aggregate parameters do not take up registers.  Examples: | 
|  | 3240 | //   struct { } a; | 
|  | 3241 | //   union  { } b; | 
|  | 3242 | //   int c[0]; | 
|  | 3243 | // etc.  However, we have to provide a place-holder in InVals, so | 
|  | 3244 | // pretend we have an 8-byte item at the current address for that | 
|  | 3245 | // purpose. | 
|  | 3246 | if (!ObjSize) { | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 3247 | int FI = MFI.CreateFixedObject(PtrByteSize, ArgOffset, true); | 
| Bill Schmidt | 9953cf2 | 2012-10-31 01:15:05 +0000 | [diff] [blame] | 3248 | SDValue FIN = DAG.getFrameIndex(FI, PtrVT); | 
|  | 3249 | InVals.push_back(FIN); | 
|  | 3250 | continue; | 
|  | 3251 | } | 
| Hal Finkel | 262a224 | 2013-09-12 23:20:06 +0000 | [diff] [blame] | 3252 |  | 
| Ulrich Weigand | 2419597 | 2014-07-20 22:36:52 +0000 | [diff] [blame] | 3253 | // Create a stack object covering all stack doublewords occupied | 
| Ulrich Weigand | 8658f17 | 2014-07-20 23:43:15 +0000 | [diff] [blame] | 3254 | // by the argument.  If the argument is (fully or partially) on | 
|  | 3255 | // the stack, or if the argument is fully in registers but the | 
|  | 3256 | // caller has allocated the parameter save anyway, we can refer | 
|  | 3257 | // directly to the caller's stack frame.  Otherwise, create a | 
|  | 3258 | // local copy in our own frame. | 
|  | 3259 | int FI; | 
|  | 3260 | if (HasParameterArea || | 
|  | 3261 | ArgSize + ArgOffset > LinkageSize + Num_GPR_Regs * PtrByteSize) | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 3262 | FI = MFI.CreateFixedObject(ArgSize, ArgOffset, false, true); | 
| Ulrich Weigand | 8658f17 | 2014-07-20 23:43:15 +0000 | [diff] [blame] | 3263 | else | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 3264 | FI = MFI.CreateStackObject(ArgSize, Align, false); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3265 | SDValue FIN = DAG.getFrameIndex(FI, PtrVT); | 
| Bill Schmidt | 6ed3b99 | 2012-10-25 13:38:09 +0000 | [diff] [blame] | 3266 |  | 
| Ulrich Weigand | 2419597 | 2014-07-20 22:36:52 +0000 | [diff] [blame] | 3267 | // Handle aggregates smaller than 8 bytes. | 
|  | 3268 | if (ObjSize < PtrByteSize) { | 
|  | 3269 | // The value of the object is its address, which differs from the | 
|  | 3270 | // address of the enclosing doubleword on big-endian systems. | 
|  | 3271 | SDValue Arg = FIN; | 
|  | 3272 | if (!isLittleEndian) { | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3273 | SDValue ArgOff = DAG.getConstant(PtrByteSize - ObjSize, dl, PtrVT); | 
| Ulrich Weigand | 2419597 | 2014-07-20 22:36:52 +0000 | [diff] [blame] | 3274 | Arg = DAG.getNode(ISD::ADD, dl, ArgOff.getValueType(), Arg, ArgOff); | 
|  | 3275 | } | 
|  | 3276 | InVals.push_back(Arg); | 
|  | 3277 |  | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3278 | if (GPR_idx != Num_GPR_Regs) { | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 3279 | unsigned VReg = MF.addLiveIn(GPR[GPR_idx++], &PPC::G8RCRegClass); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3280 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, PtrVT); | 
| Bill Schmidt | 6ed3b99 | 2012-10-25 13:38:09 +0000 | [diff] [blame] | 3281 | SDValue Store; | 
|  | 3282 |  | 
|  | 3283 | if (ObjSize==1 || ObjSize==2 || ObjSize==4) { | 
|  | 3284 | EVT ObjType = (ObjSize == 1 ? MVT::i8 : | 
|  | 3285 | (ObjSize == 2 ? MVT::i16 : MVT::i32)); | 
| Ulrich Weigand | 2419597 | 2014-07-20 22:36:52 +0000 | [diff] [blame] | 3286 | Store = DAG.getTruncStore(Val.getValue(1), dl, Val, Arg, | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 3287 | MachinePointerInfo(&*FuncArg), ObjType); | 
| Bill Schmidt | 6ed3b99 | 2012-10-25 13:38:09 +0000 | [diff] [blame] | 3288 | } else { | 
|  | 3289 | // For sizes that don't fit a truncating store (3, 5, 6, 7), | 
|  | 3290 | // store the whole register as-is to the parameter save area | 
| Ulrich Weigand | 2419597 | 2014-07-20 22:36:52 +0000 | [diff] [blame] | 3291 | // slot. | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 3292 | Store = DAG.getStore(Val.getValue(1), dl, Val, FIN, | 
|  | 3293 | MachinePointerInfo(&*FuncArg)); | 
| Bill Schmidt | 6ed3b99 | 2012-10-25 13:38:09 +0000 | [diff] [blame] | 3294 | } | 
|  | 3295 |  | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3296 | MemOps.push_back(Store); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3297 | } | 
| Bill Schmidt | 6ed3b99 | 2012-10-25 13:38:09 +0000 | [diff] [blame] | 3298 | // Whether we copied from a register or not, advance the offset | 
|  | 3299 | // into the parameter save area by a full doubleword. | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3300 | ArgOffset += PtrByteSize; | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3301 | continue; | 
|  | 3302 | } | 
| Bill Schmidt | 6ed3b99 | 2012-10-25 13:38:09 +0000 | [diff] [blame] | 3303 |  | 
| Ulrich Weigand | 2419597 | 2014-07-20 22:36:52 +0000 | [diff] [blame] | 3304 | // The value of the object is its address, which is the address of | 
|  | 3305 | // its first stack doubleword. | 
|  | 3306 | InVals.push_back(FIN); | 
|  | 3307 |  | 
|  | 3308 | // Store whatever pieces of the object are in registers to memory. | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3309 | for (unsigned j = 0; j < ArgSize; j += PtrByteSize) { | 
| Ulrich Weigand | 2419597 | 2014-07-20 22:36:52 +0000 | [diff] [blame] | 3310 | if (GPR_idx == Num_GPR_Regs) | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3311 | break; | 
| Ulrich Weigand | 2419597 | 2014-07-20 22:36:52 +0000 | [diff] [blame] | 3312 |  | 
|  | 3313 | unsigned VReg = MF.addLiveIn(GPR[GPR_idx], &PPC::G8RCRegClass); | 
|  | 3314 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, PtrVT); | 
|  | 3315 | SDValue Addr = FIN; | 
|  | 3316 | if (j) { | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3317 | SDValue Off = DAG.getConstant(j, dl, PtrVT); | 
| Ulrich Weigand | 2419597 | 2014-07-20 22:36:52 +0000 | [diff] [blame] | 3318 | Addr = DAG.getNode(ISD::ADD, dl, Off.getValueType(), Addr, Off); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3319 | } | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 3320 | SDValue Store = DAG.getStore(Val.getValue(1), dl, Val, Addr, | 
|  | 3321 | MachinePointerInfo(&*FuncArg, j)); | 
| Ulrich Weigand | 2419597 | 2014-07-20 22:36:52 +0000 | [diff] [blame] | 3322 | MemOps.push_back(Store); | 
|  | 3323 | ++GPR_idx; | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3324 | } | 
| Ulrich Weigand | 2419597 | 2014-07-20 22:36:52 +0000 | [diff] [blame] | 3325 | ArgOffset += ArgSize; | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3326 | continue; | 
|  | 3327 | } | 
|  | 3328 |  | 
|  | 3329 | switch (ObjectVT.getSimpleVT().SimpleTy) { | 
|  | 3330 | default: llvm_unreachable("Unhandled argument type!"); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 3331 | case MVT::i1: | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3332 | case MVT::i32: | 
|  | 3333 | case MVT::i64: | 
| Hal Finkel | 965cea5 | 2015-07-12 00:37:44 +0000 | [diff] [blame] | 3334 | if (Flags.isNest()) { | 
|  | 3335 | // The 'nest' parameter, if any, is passed in R11. | 
|  | 3336 | unsigned VReg = MF.addLiveIn(PPC::X11, &PPC::G8RCRegClass); | 
|  | 3337 | ArgVal = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i64); | 
|  | 3338 |  | 
|  | 3339 | if (ObjectVT == MVT::i32 || ObjectVT == MVT::i1) | 
|  | 3340 | ArgVal = extendArgForPPC64(Flags, ObjectVT, DAG, ArgVal, dl); | 
|  | 3341 |  | 
|  | 3342 | break; | 
|  | 3343 | } | 
|  | 3344 |  | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 3345 | // These can be scalar arguments or elements of an integer array type | 
|  | 3346 | // passed directly.  Clang may use those instead of "byval" aggregate | 
|  | 3347 | // types to avoid forcing arguments to memory unnecessarily. | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3348 | if (GPR_idx != Num_GPR_Regs) { | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 3349 | unsigned VReg = MF.addLiveIn(GPR[GPR_idx++], &PPC::G8RCRegClass); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3350 | ArgVal = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i64); | 
|  | 3351 |  | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 3352 | if (ObjectVT == MVT::i32 || ObjectVT == MVT::i1) | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3353 | // PPC64 passes i8, i16, and i32 values in i64 registers. Promote | 
|  | 3354 | // value to MVT::i64 and then truncate to the correct register size. | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 3355 | ArgVal = extendArgForPPC64(Flags, ObjectVT, DAG, ArgVal, dl); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3356 | } else { | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 3357 | if (CallConv == CallingConv::Fast) | 
|  | 3358 | ComputeArgOffset(); | 
|  | 3359 |  | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3360 | needsLoad = true; | 
|  | 3361 | ArgSize = PtrByteSize; | 
|  | 3362 | } | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 3363 | if (CallConv != CallingConv::Fast || needsLoad) | 
|  | 3364 | ArgOffset += 8; | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3365 | break; | 
|  | 3366 |  | 
|  | 3367 | case MVT::f32: | 
|  | 3368 | case MVT::f64: | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 3369 | // These can be scalar arguments or elements of a float array type | 
|  | 3370 | // passed directly.  The latter are used to implement ELFv2 homogenous | 
|  | 3371 | // float aggregates. | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3372 | if (FPR_idx != Num_FPR_Regs) { | 
|  | 3373 | unsigned VReg; | 
|  | 3374 |  | 
|  | 3375 | if (ObjectVT == MVT::f32) | 
| Nemanja Ivanovic | f3c94b1 | 2015-05-07 18:24:05 +0000 | [diff] [blame] | 3376 | VReg = MF.addLiveIn(FPR[FPR_idx], | 
|  | 3377 | Subtarget.hasP8Vector() | 
|  | 3378 | ? &PPC::VSSRCRegClass | 
|  | 3379 | : &PPC::F4RCRegClass); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3380 | else | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 3381 | VReg = MF.addLiveIn(FPR[FPR_idx], Subtarget.hasVSX() | 
|  | 3382 | ? &PPC::VSFRCRegClass | 
|  | 3383 | : &PPC::F8RCRegClass); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3384 |  | 
|  | 3385 | ArgVal = DAG.getCopyFromReg(Chain, dl, VReg, ObjectVT); | 
|  | 3386 | ++FPR_idx; | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 3387 | } else if (GPR_idx != Num_GPR_Regs && CallConv != CallingConv::Fast) { | 
| Hal Finkel | 8ea446b | 2015-01-18 14:31:10 +0000 | [diff] [blame] | 3388 | // FIXME: We may want to re-enable this for CallingConv::Fast on the P8 | 
|  | 3389 | // once we support fp <-> gpr moves. | 
|  | 3390 |  | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 3391 | // This can only ever happen in the presence of f32 array types, | 
|  | 3392 | // since otherwise we never run out of FPRs before running out | 
|  | 3393 | // of GPRs. | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 3394 | unsigned VReg = MF.addLiveIn(GPR[GPR_idx++], &PPC::G8RCRegClass); | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 3395 | ArgVal = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i64); | 
|  | 3396 |  | 
|  | 3397 | if (ObjectVT == MVT::f32) { | 
|  | 3398 | if ((ArgOffset % PtrByteSize) == (isLittleEndian ? 4 : 0)) | 
|  | 3399 | ArgVal = DAG.getNode(ISD::SRL, dl, MVT::i64, ArgVal, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3400 | DAG.getConstant(32, dl, MVT::i32)); | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 3401 | ArgVal = DAG.getNode(ISD::TRUNCATE, dl, MVT::i32, ArgVal); | 
|  | 3402 | } | 
|  | 3403 |  | 
|  | 3404 | ArgVal = DAG.getNode(ISD::BITCAST, dl, ObjectVT, ArgVal); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3405 | } else { | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 3406 | if (CallConv == CallingConv::Fast) | 
|  | 3407 | ComputeArgOffset(); | 
|  | 3408 |  | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3409 | needsLoad = true; | 
|  | 3410 | } | 
|  | 3411 |  | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 3412 | // When passing an array of floats, the array occupies consecutive | 
|  | 3413 | // space in the argument area; only round up to the next doubleword | 
|  | 3414 | // at the end of the array.  Otherwise, each float takes 8 bytes. | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 3415 | if (CallConv != CallingConv::Fast || needsLoad) { | 
|  | 3416 | ArgSize = Flags.isInConsecutiveRegs() ? ObjSize : PtrByteSize; | 
|  | 3417 | ArgOffset += ArgSize; | 
|  | 3418 | if (Flags.isInConsecutiveRegsLast()) | 
|  | 3419 | ArgOffset = ((ArgOffset + PtrByteSize - 1)/PtrByteSize) * PtrByteSize; | 
|  | 3420 | } | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3421 | break; | 
|  | 3422 | case MVT::v4f32: | 
|  | 3423 | case MVT::v4i32: | 
|  | 3424 | case MVT::v8i16: | 
|  | 3425 | case MVT::v16i8: | 
| Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 3426 | case MVT::v2f64: | 
| Hal Finkel | a6c8b51 | 2014-03-26 16:12:58 +0000 | [diff] [blame] | 3427 | case MVT::v2i64: | 
| Kit Barton | d4eb73c | 2015-05-05 16:10:44 +0000 | [diff] [blame] | 3428 | case MVT::v1i128: | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 3429 | if (!Subtarget.hasQPX()) { | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 3430 | // These can be scalar arguments or elements of a vector array type | 
|  | 3431 | // passed directly.  The latter are used to implement ELFv2 homogenous | 
|  | 3432 | // vector aggregates. | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3433 | if (VR_idx != Num_VR_Regs) { | 
| Hal Finkel | 7811c61 | 2014-03-28 19:58:11 +0000 | [diff] [blame] | 3434 | unsigned VReg = (ObjectVT == MVT::v2f64 || ObjectVT == MVT::v2i64) ? | 
|  | 3435 | MF.addLiveIn(VSRH[VR_idx], &PPC::VSHRCRegClass) : | 
|  | 3436 | MF.addLiveIn(VR[VR_idx], &PPC::VRRCRegClass); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3437 | ArgVal = DAG.getCopyFromReg(Chain, dl, VReg, ObjectVT); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3438 | ++VR_idx; | 
|  | 3439 | } else { | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 3440 | if (CallConv == CallingConv::Fast) | 
|  | 3441 | ComputeArgOffset(); | 
|  | 3442 |  | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3443 | needsLoad = true; | 
|  | 3444 | } | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 3445 | if (CallConv != CallingConv::Fast || needsLoad) | 
|  | 3446 | ArgOffset += 16; | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3447 | break; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 3448 | } // not QPX | 
|  | 3449 |  | 
|  | 3450 | assert(ObjectVT.getSimpleVT().SimpleTy == MVT::v4f32 && | 
|  | 3451 | "Invalid QPX parameter type"); | 
|  | 3452 | /* fall through */ | 
|  | 3453 |  | 
|  | 3454 | case MVT::v4f64: | 
|  | 3455 | case MVT::v4i1: | 
|  | 3456 | // QPX vectors are treated like their scalar floating-point subregisters | 
|  | 3457 | // (except that they're larger). | 
|  | 3458 | unsigned Sz = ObjectVT.getSimpleVT().SimpleTy == MVT::v4f32 ? 16 : 32; | 
|  | 3459 | if (QFPR_idx != Num_QFPR_Regs) { | 
|  | 3460 | const TargetRegisterClass *RC; | 
|  | 3461 | switch (ObjectVT.getSimpleVT().SimpleTy) { | 
|  | 3462 | case MVT::v4f64: RC = &PPC::QFRCRegClass; break; | 
|  | 3463 | case MVT::v4f32: RC = &PPC::QSRCRegClass; break; | 
|  | 3464 | default:         RC = &PPC::QBRCRegClass; break; | 
|  | 3465 | } | 
|  | 3466 |  | 
|  | 3467 | unsigned VReg = MF.addLiveIn(QFPR[QFPR_idx], RC); | 
|  | 3468 | ArgVal = DAG.getCopyFromReg(Chain, dl, VReg, ObjectVT); | 
|  | 3469 | ++QFPR_idx; | 
|  | 3470 | } else { | 
|  | 3471 | if (CallConv == CallingConv::Fast) | 
|  | 3472 | ComputeArgOffset(); | 
|  | 3473 | needsLoad = true; | 
|  | 3474 | } | 
|  | 3475 | if (CallConv != CallingConv::Fast || needsLoad) | 
|  | 3476 | ArgOffset += Sz; | 
|  | 3477 | break; | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3478 | } | 
|  | 3479 |  | 
|  | 3480 | // We need to load the argument to a virtual register if we determined | 
|  | 3481 | // above that we ran out of physical registers of the appropriate type. | 
|  | 3482 | if (needsLoad) { | 
| Ulrich Weigand | 59c6ab2 | 2014-06-20 16:34:05 +0000 | [diff] [blame] | 3483 | if (ObjSize < ArgSize && !isLittleEndian) | 
|  | 3484 | CurArgOffset += ArgSize - ObjSize; | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 3485 | int FI = MFI.CreateFixedObject(ObjSize, CurArgOffset, isImmutable); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3486 | SDValue FIN = DAG.getFrameIndex(FI, PtrVT); | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 3487 | ArgVal = DAG.getLoad(ObjectVT, dl, Chain, FIN, MachinePointerInfo()); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3488 | } | 
|  | 3489 |  | 
|  | 3490 | InVals.push_back(ArgVal); | 
|  | 3491 | } | 
|  | 3492 |  | 
| Ulrich Weigand | 2bffb95 | 2014-06-23 13:08:27 +0000 | [diff] [blame] | 3493 | // Area that is at least reserved in the caller of this function. | 
| Ulrich Weigand | ec2bf93 | 2014-07-07 19:26:41 +0000 | [diff] [blame] | 3494 | unsigned MinReservedArea; | 
| Ulrich Weigand | 8658f17 | 2014-07-20 23:43:15 +0000 | [diff] [blame] | 3495 | if (HasParameterArea) | 
|  | 3496 | MinReservedArea = std::max(ArgOffset, LinkageSize + 8 * PtrByteSize); | 
|  | 3497 | else | 
|  | 3498 | MinReservedArea = LinkageSize; | 
| Ulrich Weigand | 2bffb95 | 2014-06-23 13:08:27 +0000 | [diff] [blame] | 3499 |  | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3500 | // Set the size that is at least reserved in caller of this function.  Tail | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 3501 | // call optimized functions' reserved stack space needs to be aligned so that | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3502 | // taking the difference between two stack areas will result in an aligned | 
|  | 3503 | // stack. | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 3504 | MinReservedArea = | 
|  | 3505 | EnsureStackAlignment(Subtarget.getFrameLowering(), MinReservedArea); | 
| Ulrich Weigand | 2bffb95 | 2014-06-23 13:08:27 +0000 | [diff] [blame] | 3506 | FuncInfo->setMinReservedArea(MinReservedArea); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3507 |  | 
|  | 3508 | // If the function takes variable number of arguments, make a frame index for | 
|  | 3509 | // the start of the first vararg value... for expansion of llvm.va_start. | 
|  | 3510 | if (isVarArg) { | 
|  | 3511 | int Depth = ArgOffset; | 
|  | 3512 |  | 
|  | 3513 | FuncInfo->setVarArgsFrameIndex( | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 3514 | MFI.CreateFixedObject(PtrByteSize, Depth, true)); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3515 | SDValue FIN = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT); | 
|  | 3516 |  | 
|  | 3517 | // If this function is vararg, store any remaining integer argument regs | 
| Nick Lewycky | 9980075 | 2016-06-28 01:45:05 +0000 | [diff] [blame] | 3518 | // to their spots on the stack so that they may be loaded by dereferencing | 
|  | 3519 | // the result of va_next. | 
| Ulrich Weigand | ec2bf93 | 2014-07-07 19:26:41 +0000 | [diff] [blame] | 3520 | for (GPR_idx = (ArgOffset - LinkageSize) / PtrByteSize; | 
|  | 3521 | GPR_idx < Num_GPR_Regs; ++GPR_idx) { | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3522 | unsigned VReg = MF.addLiveIn(GPR[GPR_idx], &PPC::G8RCRegClass); | 
|  | 3523 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, PtrVT); | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 3524 | SDValue Store = | 
|  | 3525 | DAG.getStore(Val.getValue(1), dl, Val, FIN, MachinePointerInfo()); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3526 | MemOps.push_back(Store); | 
|  | 3527 | // Increment the address by four for the next argument to store | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3528 | SDValue PtrOff = DAG.getConstant(PtrByteSize, dl, PtrVT); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3529 | FIN = DAG.getNode(ISD::ADD, dl, PtrOff.getValueType(), FIN, PtrOff); | 
|  | 3530 | } | 
|  | 3531 | } | 
|  | 3532 |  | 
|  | 3533 | if (!MemOps.empty()) | 
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 3534 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOps); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3535 |  | 
|  | 3536 | return Chain; | 
|  | 3537 | } | 
|  | 3538 |  | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 3539 | SDValue PPCTargetLowering::LowerFormalArguments_Darwin( | 
|  | 3540 | SDValue Chain, CallingConv::ID CallConv, bool isVarArg, | 
|  | 3541 | const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl, | 
|  | 3542 | SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const { | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3543 | // TODO: add description of PPC stack frame format, or at least some docs. | 
|  | 3544 | // | 
|  | 3545 | MachineFunction &MF = DAG.getMachineFunction(); | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 3546 | MachineFrameInfo &MFI = MF.getFrameInfo(); | 
| Dan Gohman | 31ae586 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 3547 | PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>(); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 3548 |  | 
| Eric Christopher | cd71946 | 2016-07-07 01:49:59 +0000 | [diff] [blame] | 3549 | EVT PtrVT = getPointerTy(MF.getDataLayout()); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3550 | bool isPPC64 = PtrVT == MVT::i64; | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 3551 | // Potential tail calls could cause overwriting of argument stack slots. | 
| Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 3552 | bool isImmutable = !(getTargetMachine().Options.GuaranteedTailCallOpt && | 
|  | 3553 | (CallConv == CallingConv::Fast)); | 
| Jim Laskey | f4e2e00 | 2006-11-28 14:53:52 +0000 | [diff] [blame] | 3554 | unsigned PtrByteSize = isPPC64 ? 8 : 4; | 
| Eric Christopher | a4ae213 | 2015-02-13 22:22:57 +0000 | [diff] [blame] | 3555 | unsigned LinkageSize = Subtarget.getFrameLowering()->getLinkageSize(); | 
| Ulrich Weigand | 8ca988f | 2014-06-23 14:15:53 +0000 | [diff] [blame] | 3556 | unsigned ArgOffset = LinkageSize; | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 3557 | // Area that is at least reserved in caller of this function. | 
|  | 3558 | unsigned MinReservedArea = ArgOffset; | 
|  | 3559 |  | 
| Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 3560 | static const MCPhysReg GPR_32[] = {           // 32-bit registers. | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3561 | PPC::R3, PPC::R4, PPC::R5, PPC::R6, | 
|  | 3562 | PPC::R7, PPC::R8, PPC::R9, PPC::R10, | 
|  | 3563 | }; | 
| Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 3564 | static const MCPhysReg GPR_64[] = {           // 64-bit registers. | 
| Chris Lattner | ec78cad | 2006-06-26 22:48:35 +0000 | [diff] [blame] | 3565 | PPC::X3, PPC::X4, PPC::X5, PPC::X6, | 
|  | 3566 | PPC::X7, PPC::X8, PPC::X9, PPC::X10, | 
|  | 3567 | }; | 
| Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 3568 | static const MCPhysReg VR[] = { | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3569 | PPC::V2, PPC::V3, PPC::V4, PPC::V5, PPC::V6, PPC::V7, PPC::V8, | 
|  | 3570 | PPC::V9, PPC::V10, PPC::V11, PPC::V12, PPC::V13 | 
|  | 3571 | }; | 
| Chris Lattner | ec78cad | 2006-06-26 22:48:35 +0000 | [diff] [blame] | 3572 |  | 
| Owen Anderson | e2f23a3 | 2007-09-07 04:06:50 +0000 | [diff] [blame] | 3573 | const unsigned Num_GPR_Regs = array_lengthof(GPR_32); | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 3574 | const unsigned Num_FPR_Regs = 13; | 
| Owen Anderson | e2f23a3 | 2007-09-07 04:06:50 +0000 | [diff] [blame] | 3575 | const unsigned Num_VR_Regs  = array_lengthof( VR); | 
| Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 3576 |  | 
|  | 3577 | unsigned GPR_idx = 0, FPR_idx = 0, VR_idx = 0; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 3578 |  | 
| Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 3579 | const MCPhysReg *GPR = isPPC64 ? GPR_64 : GPR_32; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 3580 |  | 
| Dale Johannesen | 0dfd3f3 | 2008-03-14 17:41:26 +0000 | [diff] [blame] | 3581 | // In 32-bit non-varargs functions, the stack space for vectors is after the | 
|  | 3582 | // stack space for non-vectors.  We do not use this space unless we have | 
|  | 3583 | // too many vectors to fit in registers, something that only occurs in | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 3584 | // constructed examples:), but we have to walk the arglist to figure | 
| Dale Johannesen | 0dfd3f3 | 2008-03-14 17:41:26 +0000 | [diff] [blame] | 3585 | // that out...for the pathological case, compute VecArgOffset as the | 
|  | 3586 | // start of the vector parameter area.  Computing VecArgOffset is the | 
|  | 3587 | // entire point of the following loop. | 
| Dale Johannesen | 0dfd3f3 | 2008-03-14 17:41:26 +0000 | [diff] [blame] | 3588 | unsigned VecArgOffset = ArgOffset; | 
|  | 3589 | if (!isVarArg && !isPPC64) { | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3590 | for (unsigned ArgNo = 0, e = Ins.size(); ArgNo != e; | 
| Dale Johannesen | 0dfd3f3 | 2008-03-14 17:41:26 +0000 | [diff] [blame] | 3591 | ++ArgNo) { | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3592 | EVT ObjectVT = Ins[ArgNo].VT; | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3593 | ISD::ArgFlagsTy Flags = Ins[ArgNo].Flags; | 
| Dale Johannesen | 0dfd3f3 | 2008-03-14 17:41:26 +0000 | [diff] [blame] | 3594 |  | 
| Duncan Sands | d97eea3 | 2008-03-21 09:14:45 +0000 | [diff] [blame] | 3595 | if (Flags.isByVal()) { | 
| Dale Johannesen | 0dfd3f3 | 2008-03-14 17:41:26 +0000 | [diff] [blame] | 3596 | // ObjSize is the true size, ArgSize rounded up to multiple of regs. | 
| Benjamin Kramer | 084b9f4 | 2012-01-20 14:42:32 +0000 | [diff] [blame] | 3597 | unsigned ObjSize = Flags.getByValSize(); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 3598 | unsigned ArgSize = | 
| Dale Johannesen | 0dfd3f3 | 2008-03-14 17:41:26 +0000 | [diff] [blame] | 3599 | ((ObjSize + PtrByteSize - 1)/PtrByteSize) * PtrByteSize; | 
|  | 3600 | VecArgOffset += ArgSize; | 
|  | 3601 | continue; | 
|  | 3602 | } | 
|  | 3603 |  | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3604 | switch(ObjectVT.getSimpleVT().SimpleTy) { | 
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3605 | default: llvm_unreachable("Unhandled argument type!"); | 
| Hal Finkel | 5cae216 | 2014-02-28 01:17:25 +0000 | [diff] [blame] | 3606 | case MVT::i1: | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3607 | case MVT::i32: | 
|  | 3608 | case MVT::f32: | 
| Bill Schmidt | 019cc6f | 2012-09-19 15:42:13 +0000 | [diff] [blame] | 3609 | VecArgOffset += 4; | 
| Dale Johannesen | 0dfd3f3 | 2008-03-14 17:41:26 +0000 | [diff] [blame] | 3610 | break; | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3611 | case MVT::i64:  // PPC64 | 
|  | 3612 | case MVT::f64: | 
| Bill Schmidt | 019cc6f | 2012-09-19 15:42:13 +0000 | [diff] [blame] | 3613 | // FIXME: We are guaranteed to be !isPPC64 at this point. | 
|  | 3614 | // Does MVT::i64 apply? | 
| Dale Johannesen | 0dfd3f3 | 2008-03-14 17:41:26 +0000 | [diff] [blame] | 3615 | VecArgOffset += 8; | 
|  | 3616 | break; | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3617 | case MVT::v4f32: | 
|  | 3618 | case MVT::v4i32: | 
|  | 3619 | case MVT::v8i16: | 
|  | 3620 | case MVT::v16i8: | 
| Dale Johannesen | 0dfd3f3 | 2008-03-14 17:41:26 +0000 | [diff] [blame] | 3621 | // Nothing to do, we're only looking at Nonvector args here. | 
|  | 3622 | break; | 
|  | 3623 | } | 
|  | 3624 | } | 
|  | 3625 | } | 
|  | 3626 | // We've found where the vector parameter area in memory is.  Skip the | 
|  | 3627 | // first 12 parameters; these don't use that memory. | 
|  | 3628 | VecArgOffset = ((VecArgOffset+15)/16)*16; | 
|  | 3629 | VecArgOffset += 12*16; | 
|  | 3630 |  | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3631 | // Add DAG nodes to load the arguments or copy them out of registers.  On | 
| Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 3632 | // entry to a function on PPC, the arguments start after the linkage area, | 
|  | 3633 | // although the first ones are often in registers. | 
| Nicolas Geoffray | 7aad928 | 2007-03-13 15:02:46 +0000 | [diff] [blame] | 3634 |  | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3635 | SmallVector<SDValue, 8> MemOps; | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 3636 | unsigned nAltivecParamsAtEnd = 0; | 
| Roman Divacky | ca10389 | 2012-09-24 20:47:19 +0000 | [diff] [blame] | 3637 | Function::const_arg_iterator FuncArg = MF.getFunction()->arg_begin(); | 
| Bill Schmidt | 38b6cb5 | 2013-05-08 17:22:33 +0000 | [diff] [blame] | 3638 | unsigned CurArgIdx = 0; | 
|  | 3639 | for (unsigned ArgNo = 0, e = Ins.size(); ArgNo != e; ++ArgNo) { | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3640 | SDValue ArgVal; | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3641 | bool needsLoad = false; | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3642 | EVT ObjectVT = Ins[ArgNo].VT; | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 3643 | unsigned ObjSize = ObjectVT.getSizeInBits()/8; | 
| Jim Laskey | 152671f | 2006-11-29 13:37:09 +0000 | [diff] [blame] | 3644 | unsigned ArgSize = ObjSize; | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3645 | ISD::ArgFlagsTy Flags = Ins[ArgNo].Flags; | 
| Andrew Trick | 05938a5 | 2015-02-16 18:10:47 +0000 | [diff] [blame] | 3646 | if (Ins[ArgNo].isOrigArg()) { | 
|  | 3647 | std::advance(FuncArg, Ins[ArgNo].getOrigArgIndex() - CurArgIdx); | 
|  | 3648 | CurArgIdx = Ins[ArgNo].getOrigArgIndex(); | 
|  | 3649 | } | 
| Chris Lattner | 318f0d2 | 2006-05-16 18:51:52 +0000 | [diff] [blame] | 3650 | unsigned CurArgOffset = ArgOffset; | 
| Dale Johannesen | bfa252d | 2008-03-07 20:27:40 +0000 | [diff] [blame] | 3651 |  | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 3652 | // Varargs or 64 bit Altivec parameters are padded to a 16 byte boundary. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3653 | if (ObjectVT==MVT::v4f32 || ObjectVT==MVT::v4i32 || | 
|  | 3654 | ObjectVT==MVT::v8i16 || ObjectVT==MVT::v16i8) { | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 3655 | if (isVarArg || isPPC64) { | 
|  | 3656 | MinReservedArea = ((MinReservedArea+15)/16)*16; | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3657 | MinReservedArea += CalculateStackSlotSize(ObjectVT, | 
| Dan Gohman | d3fe174 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 3658 | Flags, | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 3659 | PtrByteSize); | 
|  | 3660 | } else  nAltivecParamsAtEnd++; | 
|  | 3661 | } else | 
|  | 3662 | // Calculate min reserved area. | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3663 | MinReservedArea += CalculateStackSlotSize(Ins[ArgNo].VT, | 
| Dan Gohman | d3fe174 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 3664 | Flags, | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 3665 | PtrByteSize); | 
|  | 3666 |  | 
| Dale Johannesen | bfa252d | 2008-03-07 20:27:40 +0000 | [diff] [blame] | 3667 | // FIXME the codegen can be much improved in some cases. | 
|  | 3668 | // We do not have to keep everything in memory. | 
| Duncan Sands | d97eea3 | 2008-03-21 09:14:45 +0000 | [diff] [blame] | 3669 | if (Flags.isByVal()) { | 
| Andrew Trick | 05938a5 | 2015-02-16 18:10:47 +0000 | [diff] [blame] | 3670 | assert(Ins[ArgNo].isOrigArg() && "Byval arguments cannot be implicit"); | 
|  | 3671 |  | 
| Dale Johannesen | bfa252d | 2008-03-07 20:27:40 +0000 | [diff] [blame] | 3672 | // ObjSize is the true size, ArgSize rounded up to multiple of registers. | 
| Duncan Sands | d97eea3 | 2008-03-21 09:14:45 +0000 | [diff] [blame] | 3673 | ObjSize = Flags.getByValSize(); | 
| Dale Johannesen | bfa252d | 2008-03-07 20:27:40 +0000 | [diff] [blame] | 3674 | ArgSize = ((ObjSize + PtrByteSize - 1)/PtrByteSize) * PtrByteSize; | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3675 | // Objects of size 1 and 2 are right justified, everything else is | 
|  | 3676 | // left justified.  This means the memory address is adjusted forwards. | 
| Dale Johannesen | 21a8f14 | 2008-03-08 01:41:42 +0000 | [diff] [blame] | 3677 | if (ObjSize==1 || ObjSize==2) { | 
|  | 3678 | CurArgOffset = CurArgOffset + (4 - ObjSize); | 
|  | 3679 | } | 
| Dale Johannesen | bfa252d | 2008-03-07 20:27:40 +0000 | [diff] [blame] | 3680 | // The value of the object is its address. | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 3681 | int FI = MFI.CreateFixedObject(ObjSize, CurArgOffset, false, true); | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3682 | SDValue FIN = DAG.getFrameIndex(FI, PtrVT); | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3683 | InVals.push_back(FIN); | 
| Bill Schmidt | d1fa36f | 2012-10-05 21:27:08 +0000 | [diff] [blame] | 3684 | if (ObjSize==1 || ObjSize==2) { | 
| Dale Johannesen | 21a8f14 | 2008-03-08 01:41:42 +0000 | [diff] [blame] | 3685 | if (GPR_idx != Num_GPR_Regs) { | 
| Roman Divacky | d041962 | 2011-06-17 15:21:10 +0000 | [diff] [blame] | 3686 | unsigned VReg; | 
|  | 3687 | if (isPPC64) | 
|  | 3688 | VReg = MF.addLiveIn(GPR[GPR_idx], &PPC::G8RCRegClass); | 
|  | 3689 | else | 
|  | 3690 | VReg = MF.addLiveIn(GPR[GPR_idx], &PPC::GPRCRegClass); | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3691 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, PtrVT); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 3692 | EVT ObjType = ObjSize == 1 ? MVT::i8 : MVT::i16; | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 3693 | SDValue Store = | 
|  | 3694 | DAG.getTruncStore(Val.getValue(1), dl, Val, FIN, | 
|  | 3695 | MachinePointerInfo(&*FuncArg), ObjType); | 
| Dale Johannesen | 21a8f14 | 2008-03-08 01:41:42 +0000 | [diff] [blame] | 3696 | MemOps.push_back(Store); | 
|  | 3697 | ++GPR_idx; | 
| Dale Johannesen | 21a8f14 | 2008-03-08 01:41:42 +0000 | [diff] [blame] | 3698 | } | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3699 |  | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 3700 | ArgOffset += PtrByteSize; | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3701 |  | 
| Dale Johannesen | 21a8f14 | 2008-03-08 01:41:42 +0000 | [diff] [blame] | 3702 | continue; | 
|  | 3703 | } | 
| Dale Johannesen | bfa252d | 2008-03-07 20:27:40 +0000 | [diff] [blame] | 3704 | for (unsigned j = 0; j < ArgSize; j += PtrByteSize) { | 
|  | 3705 | // Store whatever pieces of the object are in registers | 
| Bill Schmidt | 019cc6f | 2012-09-19 15:42:13 +0000 | [diff] [blame] | 3706 | // to memory.  ArgOffset will be the address of the beginning | 
|  | 3707 | // of the object. | 
| Dale Johannesen | bfa252d | 2008-03-07 20:27:40 +0000 | [diff] [blame] | 3708 | if (GPR_idx != Num_GPR_Regs) { | 
| Roman Divacky | d041962 | 2011-06-17 15:21:10 +0000 | [diff] [blame] | 3709 | unsigned VReg; | 
|  | 3710 | if (isPPC64) | 
|  | 3711 | VReg = MF.addLiveIn(GPR[GPR_idx], &PPC::G8RCRegClass); | 
|  | 3712 | else | 
|  | 3713 | VReg = MF.addLiveIn(GPR[GPR_idx], &PPC::GPRCRegClass); | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 3714 | int FI = MFI.CreateFixedObject(PtrByteSize, ArgOffset, true); | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3715 | SDValue FIN = DAG.getFrameIndex(FI, PtrVT); | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3716 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, PtrVT); | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 3717 | SDValue Store = DAG.getStore(Val.getValue(1), dl, Val, FIN, | 
|  | 3718 | MachinePointerInfo(&*FuncArg, j)); | 
| Dale Johannesen | bfa252d | 2008-03-07 20:27:40 +0000 | [diff] [blame] | 3719 | MemOps.push_back(Store); | 
|  | 3720 | ++GPR_idx; | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 3721 | ArgOffset += PtrByteSize; | 
| Dale Johannesen | bfa252d | 2008-03-07 20:27:40 +0000 | [diff] [blame] | 3722 | } else { | 
|  | 3723 | ArgOffset += ArgSize - (ArgOffset-CurArgOffset); | 
|  | 3724 | break; | 
|  | 3725 | } | 
|  | 3726 | } | 
|  | 3727 | continue; | 
|  | 3728 | } | 
|  | 3729 |  | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3730 | switch (ObjectVT.getSimpleVT().SimpleTy) { | 
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3731 | default: llvm_unreachable("Unhandled argument type!"); | 
| Hal Finkel | 5cae216 | 2014-02-28 01:17:25 +0000 | [diff] [blame] | 3732 | case MVT::i1: | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3733 | case MVT::i32: | 
| Bill Wendling | 968f32c | 2008-03-07 20:49:02 +0000 | [diff] [blame] | 3734 | if (!isPPC64) { | 
| Bill Wendling | 968f32c | 2008-03-07 20:49:02 +0000 | [diff] [blame] | 3735 | if (GPR_idx != Num_GPR_Regs) { | 
| Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 3736 | unsigned VReg = MF.addLiveIn(GPR[GPR_idx], &PPC::GPRCRegClass); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3737 | ArgVal = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32); | 
| Hal Finkel | 7f908e8 | 2014-03-06 00:45:19 +0000 | [diff] [blame] | 3738 |  | 
|  | 3739 | if (ObjectVT == MVT::i1) | 
|  | 3740 | ArgVal = DAG.getNode(ISD::TRUNCATE, dl, MVT::i1, ArgVal); | 
|  | 3741 |  | 
| Bill Wendling | 968f32c | 2008-03-07 20:49:02 +0000 | [diff] [blame] | 3742 | ++GPR_idx; | 
|  | 3743 | } else { | 
|  | 3744 | needsLoad = true; | 
|  | 3745 | ArgSize = PtrByteSize; | 
|  | 3746 | } | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 3747 | // All int arguments reserve stack space in the Darwin ABI. | 
|  | 3748 | ArgOffset += PtrByteSize; | 
| Bill Wendling | 968f32c | 2008-03-07 20:49:02 +0000 | [diff] [blame] | 3749 | break; | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3750 | } | 
| Justin Bogner | b03fd12 | 2016-08-17 05:10:15 +0000 | [diff] [blame] | 3751 | LLVM_FALLTHROUGH; | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3752 | case MVT::i64:  // PPC64 | 
| Chris Lattner | ec78cad | 2006-06-26 22:48:35 +0000 | [diff] [blame] | 3753 | if (GPR_idx != Num_GPR_Regs) { | 
| Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 3754 | unsigned VReg = MF.addLiveIn(GPR[GPR_idx], &PPC::G8RCRegClass); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3755 | ArgVal = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i64); | 
| Bill Wendling | 968f32c | 2008-03-07 20:49:02 +0000 | [diff] [blame] | 3756 |  | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 3757 | if (ObjectVT == MVT::i32 || ObjectVT == MVT::i1) | 
| Bill Wendling | 968f32c | 2008-03-07 20:49:02 +0000 | [diff] [blame] | 3758 | // PPC64 passes i8, i16, and i32 values in i64 registers. Promote | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3759 | // value to MVT::i64 and then truncate to the correct register size. | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 3760 | ArgVal = extendArgForPPC64(Flags, ObjectVT, DAG, ArgVal, dl); | 
| Bill Wendling | 968f32c | 2008-03-07 20:49:02 +0000 | [diff] [blame] | 3761 |  | 
| Chris Lattner | ec78cad | 2006-06-26 22:48:35 +0000 | [diff] [blame] | 3762 | ++GPR_idx; | 
|  | 3763 | } else { | 
|  | 3764 | needsLoad = true; | 
| Evan Cheng | 0f0aee2 | 2008-07-24 08:17:07 +0000 | [diff] [blame] | 3765 | ArgSize = PtrByteSize; | 
| Chris Lattner | ec78cad | 2006-06-26 22:48:35 +0000 | [diff] [blame] | 3766 | } | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 3767 | // All int arguments reserve stack space in the Darwin ABI. | 
|  | 3768 | ArgOffset += 8; | 
| Chris Lattner | ec78cad | 2006-06-26 22:48:35 +0000 | [diff] [blame] | 3769 | break; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 3770 |  | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3771 | case MVT::f32: | 
|  | 3772 | case MVT::f64: | 
| Chris Lattner | 318f0d2 | 2006-05-16 18:51:52 +0000 | [diff] [blame] | 3773 | // Every 4 bytes of argument space consumes one of the GPRs available for | 
|  | 3774 | // argument passing. | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 3775 | if (GPR_idx != Num_GPR_Regs) { | 
| Chris Lattner | 26e2fcd | 2006-05-16 18:58:15 +0000 | [diff] [blame] | 3776 | ++GPR_idx; | 
| Chris Lattner | 2cca385 | 2006-11-18 01:57:19 +0000 | [diff] [blame] | 3777 | if (ObjSize == 8 && GPR_idx != Num_GPR_Regs && !isPPC64) | 
| Chris Lattner | 26e2fcd | 2006-05-16 18:58:15 +0000 | [diff] [blame] | 3778 | ++GPR_idx; | 
| Chris Lattner | 318f0d2 | 2006-05-16 18:51:52 +0000 | [diff] [blame] | 3779 | } | 
| Chris Lattner | 26e2fcd | 2006-05-16 18:58:15 +0000 | [diff] [blame] | 3780 | if (FPR_idx != Num_FPR_Regs) { | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3781 | unsigned VReg; | 
| Tilmann Scheller | 98bdaaa | 2009-07-03 06:43:35 +0000 | [diff] [blame] | 3782 |  | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3783 | if (ObjectVT == MVT::f32) | 
| Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 3784 | VReg = MF.addLiveIn(FPR[FPR_idx], &PPC::F4RCRegClass); | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3785 | else | 
| Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 3786 | VReg = MF.addLiveIn(FPR[FPR_idx], &PPC::F8RCRegClass); | 
| Tilmann Scheller | 98bdaaa | 2009-07-03 06:43:35 +0000 | [diff] [blame] | 3787 |  | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3788 | ArgVal = DAG.getCopyFromReg(Chain, dl, VReg, ObjectVT); | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3789 | ++FPR_idx; | 
|  | 3790 | } else { | 
|  | 3791 | needsLoad = true; | 
|  | 3792 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 3793 |  | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 3794 | // All FP arguments reserve stack space in the Darwin ABI. | 
|  | 3795 | ArgOffset += isPPC64 ? 8 : ObjSize; | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3796 | break; | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3797 | case MVT::v4f32: | 
|  | 3798 | case MVT::v4i32: | 
|  | 3799 | case MVT::v8i16: | 
|  | 3800 | case MVT::v16i8: | 
| Dale Johannesen | b28456e | 2008-03-12 00:22:17 +0000 | [diff] [blame] | 3801 | // Note that vector arguments in registers don't reserve stack space, | 
|  | 3802 | // except in varargs functions. | 
| Chris Lattner | 26e2fcd | 2006-05-16 18:58:15 +0000 | [diff] [blame] | 3803 | if (VR_idx != Num_VR_Regs) { | 
| Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 3804 | unsigned VReg = MF.addLiveIn(VR[VR_idx], &PPC::VRRCRegClass); | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3805 | ArgVal = DAG.getCopyFromReg(Chain, dl, VReg, ObjectVT); | 
| Dale Johannesen | b28456e | 2008-03-12 00:22:17 +0000 | [diff] [blame] | 3806 | if (isVarArg) { | 
|  | 3807 | while ((ArgOffset % 16) != 0) { | 
|  | 3808 | ArgOffset += PtrByteSize; | 
|  | 3809 | if (GPR_idx != Num_GPR_Regs) | 
|  | 3810 | GPR_idx++; | 
|  | 3811 | } | 
|  | 3812 | ArgOffset += 16; | 
| Tilmann Scheller | d1aaa32 | 2009-08-15 11:54:46 +0000 | [diff] [blame] | 3813 | GPR_idx = std::min(GPR_idx+4, Num_GPR_Regs); // FIXME correct for ppc64? | 
| Dale Johannesen | b28456e | 2008-03-12 00:22:17 +0000 | [diff] [blame] | 3814 | } | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3815 | ++VR_idx; | 
|  | 3816 | } else { | 
| Dale Johannesen | 0dfd3f3 | 2008-03-14 17:41:26 +0000 | [diff] [blame] | 3817 | if (!isVarArg && !isPPC64) { | 
|  | 3818 | // Vectors go after all the nonvectors. | 
|  | 3819 | CurArgOffset = VecArgOffset; | 
|  | 3820 | VecArgOffset += 16; | 
|  | 3821 | } else { | 
|  | 3822 | // Vectors are aligned. | 
|  | 3823 | ArgOffset = ((ArgOffset+15)/16)*16; | 
|  | 3824 | CurArgOffset = ArgOffset; | 
|  | 3825 | ArgOffset += 16; | 
| Dale Johannesen | 0d98256 | 2008-03-12 00:49:20 +0000 | [diff] [blame] | 3826 | } | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3827 | needsLoad = true; | 
|  | 3828 | } | 
|  | 3829 | break; | 
|  | 3830 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 3831 |  | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3832 | // We need to load the argument to a virtual register if we determined above | 
| Chris Lattner | f6518cf | 2008-02-13 07:35:30 +0000 | [diff] [blame] | 3833 | // that we ran out of physical registers of the appropriate type. | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3834 | if (needsLoad) { | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 3835 | int FI = MFI.CreateFixedObject(ObjSize, | 
|  | 3836 | CurArgOffset + (ArgSize - ObjSize), | 
|  | 3837 | isImmutable); | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3838 | SDValue FIN = DAG.getFrameIndex(FI, PtrVT); | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 3839 | ArgVal = DAG.getLoad(ObjectVT, dl, Chain, FIN, MachinePointerInfo()); | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3840 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 3841 |  | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3842 | InVals.push_back(ArgVal); | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3843 | } | 
| Dale Johannesen | bfa252d | 2008-03-07 20:27:40 +0000 | [diff] [blame] | 3844 |  | 
| Ulrich Weigand | 2bffb95 | 2014-06-23 13:08:27 +0000 | [diff] [blame] | 3845 | // Allow for Altivec parameters at the end, if needed. | 
|  | 3846 | if (nAltivecParamsAtEnd) { | 
|  | 3847 | MinReservedArea = ((MinReservedArea+15)/16)*16; | 
|  | 3848 | MinReservedArea += 16*nAltivecParamsAtEnd; | 
|  | 3849 | } | 
|  | 3850 |  | 
|  | 3851 | // Area that is at least reserved in the caller of this function. | 
| Ulrich Weigand | 8ca988f | 2014-06-23 14:15:53 +0000 | [diff] [blame] | 3852 | MinReservedArea = std::max(MinReservedArea, LinkageSize + 8 * PtrByteSize); | 
| Ulrich Weigand | 2bffb95 | 2014-06-23 13:08:27 +0000 | [diff] [blame] | 3853 |  | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 3854 | // Set the size that is at least reserved in caller of this function.  Tail | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 3855 | // call optimized functions' reserved stack space needs to be aligned so that | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 3856 | // taking the difference between two stack areas will result in an aligned | 
|  | 3857 | // stack. | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 3858 | MinReservedArea = | 
|  | 3859 | EnsureStackAlignment(Subtarget.getFrameLowering(), MinReservedArea); | 
| Ulrich Weigand | 2bffb95 | 2014-06-23 13:08:27 +0000 | [diff] [blame] | 3860 | FuncInfo->setMinReservedArea(MinReservedArea); | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 3861 |  | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3862 | // If the function takes variable number of arguments, make a frame index for | 
|  | 3863 | // the start of the first vararg value... for expansion of llvm.va_start. | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3864 | if (isVarArg) { | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 3865 | int Depth = ArgOffset; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 3866 |  | 
| Dan Gohman | 31ae586 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 3867 | FuncInfo->setVarArgsFrameIndex( | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 3868 | MFI.CreateFixedObject(PtrVT.getSizeInBits()/8, | 
|  | 3869 | Depth, true)); | 
| Dan Gohman | 31ae586 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 3870 | SDValue FIN = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 3871 |  | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3872 | // If this function is vararg, store any remaining integer argument regs | 
| Nick Lewycky | 9980075 | 2016-06-28 01:45:05 +0000 | [diff] [blame] | 3873 | // to their spots on the stack so that they may be loaded by dereferencing | 
|  | 3874 | // the result of va_next. | 
| Chris Lattner | 26e2fcd | 2006-05-16 18:58:15 +0000 | [diff] [blame] | 3875 | for (; GPR_idx != Num_GPR_Regs; ++GPR_idx) { | 
| Chris Lattner | 2cca385 | 2006-11-18 01:57:19 +0000 | [diff] [blame] | 3876 | unsigned VReg; | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3877 |  | 
| Chris Lattner | 2cca385 | 2006-11-18 01:57:19 +0000 | [diff] [blame] | 3878 | if (isPPC64) | 
| Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 3879 | VReg = MF.addLiveIn(GPR[GPR_idx], &PPC::G8RCRegClass); | 
| Chris Lattner | 2cca385 | 2006-11-18 01:57:19 +0000 | [diff] [blame] | 3880 | else | 
| Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 3881 | VReg = MF.addLiveIn(GPR[GPR_idx], &PPC::GPRCRegClass); | 
| Chris Lattner | 2cca385 | 2006-11-18 01:57:19 +0000 | [diff] [blame] | 3882 |  | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3883 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, PtrVT); | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 3884 | SDValue Store = | 
|  | 3885 | DAG.getStore(Val.getValue(1), dl, Val, FIN, MachinePointerInfo()); | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3886 | MemOps.push_back(Store); | 
|  | 3887 | // Increment the address by four for the next argument to store | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3888 | SDValue PtrOff = DAG.getConstant(PtrVT.getSizeInBits()/8, dl, PtrVT); | 
| Dale Johannesen | 679073b | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 3889 | FIN = DAG.getNode(ISD::ADD, dl, PtrOff.getValueType(), FIN, PtrOff); | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3890 | } | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3891 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 3892 |  | 
| Dale Johannesen | bfa252d | 2008-03-07 20:27:40 +0000 | [diff] [blame] | 3893 | if (!MemOps.empty()) | 
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 3894 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOps); | 
| Dale Johannesen | bfa252d | 2008-03-07 20:27:40 +0000 | [diff] [blame] | 3895 |  | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3896 | return Chain; | 
| Chris Lattner | 4302e8f | 2006-05-16 18:18:50 +0000 | [diff] [blame] | 3897 | } | 
|  | 3898 |  | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 3899 | /// CalculateTailCallSPDiff - Get the amount the stack pointer has to be | 
| Chris Lattner | 0ab5e2c | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 3900 | /// adjusted to accommodate the arguments for the tailcall. | 
| Dale Johannesen | 86dcae1 | 2009-11-24 01:09:07 +0000 | [diff] [blame] | 3901 | static int CalculateTailCallSPDiff(SelectionDAG& DAG, bool isTailCall, | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 3902 | unsigned ParamSize) { | 
|  | 3903 |  | 
| Dale Johannesen | 86dcae1 | 2009-11-24 01:09:07 +0000 | [diff] [blame] | 3904 | if (!isTailCall) return 0; | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 3905 |  | 
|  | 3906 | PPCFunctionInfo *FI = DAG.getMachineFunction().getInfo<PPCFunctionInfo>(); | 
|  | 3907 | unsigned CallerMinReservedArea = FI->getMinReservedArea(); | 
|  | 3908 | int SPDiff = (int)CallerMinReservedArea - (int)ParamSize; | 
|  | 3909 | // Remember only if the new adjustement is bigger. | 
|  | 3910 | if (SPDiff < FI->getTailCallSPDelta()) | 
|  | 3911 | FI->setTailCallSPDelta(SPDiff); | 
|  | 3912 |  | 
|  | 3913 | return SPDiff; | 
|  | 3914 | } | 
|  | 3915 |  | 
| Chuang-Yu Cheng | 2e5973e | 2016-04-06 02:04:38 +0000 | [diff] [blame] | 3916 | static bool isFunctionGlobalAddress(SDValue Callee); | 
|  | 3917 |  | 
|  | 3918 | static bool | 
|  | 3919 | resideInSameModule(SDValue Callee, Reloc::Model RelMod) { | 
|  | 3920 | // If !G, Callee can be an external symbol. | 
|  | 3921 | GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee); | 
|  | 3922 | if (!G) return false; | 
|  | 3923 |  | 
|  | 3924 | const GlobalValue *GV = G->getGlobal(); | 
|  | 3925 |  | 
|  | 3926 | if (GV->isDeclaration()) return false; | 
|  | 3927 |  | 
|  | 3928 | switch(GV->getLinkage()) { | 
|  | 3929 | default: llvm_unreachable("unknow linkage type"); | 
|  | 3930 | case GlobalValue::AvailableExternallyLinkage: | 
|  | 3931 | case GlobalValue::ExternalWeakLinkage: | 
|  | 3932 | return false; | 
|  | 3933 |  | 
|  | 3934 | // Callee with weak linkage is allowed if it has hidden or protected | 
|  | 3935 | // visibility | 
|  | 3936 | case GlobalValue::LinkOnceAnyLinkage: | 
|  | 3937 | case GlobalValue::LinkOnceODRLinkage: // e.g. c++ inline functions | 
|  | 3938 | case GlobalValue::WeakAnyLinkage: | 
|  | 3939 | case GlobalValue::WeakODRLinkage:     // e.g. c++ template instantiation | 
|  | 3940 | if (GV->hasDefaultVisibility()) | 
|  | 3941 | return false; | 
|  | 3942 |  | 
|  | 3943 | case GlobalValue::ExternalLinkage: | 
|  | 3944 | case GlobalValue::InternalLinkage: | 
|  | 3945 | case GlobalValue::PrivateLinkage: | 
|  | 3946 | break; | 
|  | 3947 | } | 
|  | 3948 |  | 
|  | 3949 | // With '-fPIC', calling default visiblity function need insert 'nop' after | 
|  | 3950 | // function call, no matter that function resides in same module or not, so | 
|  | 3951 | // we treat it as in different module. | 
|  | 3952 | if (RelMod == Reloc::PIC_ && GV->hasDefaultVisibility()) | 
|  | 3953 | return false; | 
|  | 3954 |  | 
|  | 3955 | return true; | 
|  | 3956 | } | 
|  | 3957 |  | 
|  | 3958 | static bool | 
|  | 3959 | needStackSlotPassParameters(const PPCSubtarget &Subtarget, | 
|  | 3960 | const SmallVectorImpl<ISD::OutputArg> &Outs) { | 
|  | 3961 | assert(Subtarget.isSVR4ABI() && Subtarget.isPPC64()); | 
|  | 3962 |  | 
|  | 3963 | const unsigned PtrByteSize = 8; | 
|  | 3964 | const unsigned LinkageSize = Subtarget.getFrameLowering()->getLinkageSize(); | 
|  | 3965 |  | 
|  | 3966 | static const MCPhysReg GPR[] = { | 
|  | 3967 | PPC::X3, PPC::X4, PPC::X5, PPC::X6, | 
|  | 3968 | PPC::X7, PPC::X8, PPC::X9, PPC::X10, | 
|  | 3969 | }; | 
|  | 3970 | static const MCPhysReg VR[] = { | 
|  | 3971 | PPC::V2, PPC::V3, PPC::V4, PPC::V5, PPC::V6, PPC::V7, PPC::V8, | 
|  | 3972 | PPC::V9, PPC::V10, PPC::V11, PPC::V12, PPC::V13 | 
|  | 3973 | }; | 
|  | 3974 |  | 
|  | 3975 | const unsigned NumGPRs = array_lengthof(GPR); | 
|  | 3976 | const unsigned NumFPRs = 13; | 
|  | 3977 | const unsigned NumVRs = array_lengthof(VR); | 
|  | 3978 | const unsigned ParamAreaSize = NumGPRs * PtrByteSize; | 
|  | 3979 |  | 
|  | 3980 | unsigned NumBytes = LinkageSize; | 
|  | 3981 | unsigned AvailableFPRs = NumFPRs; | 
|  | 3982 | unsigned AvailableVRs = NumVRs; | 
|  | 3983 |  | 
|  | 3984 | for (const ISD::OutputArg& Param : Outs) { | 
|  | 3985 | if (Param.Flags.isNest()) continue; | 
|  | 3986 |  | 
|  | 3987 | if (CalculateStackSlotUsed(Param.VT, Param.ArgVT, Param.Flags, | 
|  | 3988 | PtrByteSize, LinkageSize, ParamAreaSize, | 
|  | 3989 | NumBytes, AvailableFPRs, AvailableVRs, | 
|  | 3990 | Subtarget.hasQPX())) | 
|  | 3991 | return true; | 
|  | 3992 | } | 
|  | 3993 | return false; | 
|  | 3994 | } | 
|  | 3995 |  | 
|  | 3996 | static bool | 
|  | 3997 | hasSameArgumentList(const Function *CallerFn, ImmutableCallSite *CS) { | 
|  | 3998 | if (CS->arg_size() != CallerFn->getArgumentList().size()) | 
|  | 3999 | return false; | 
|  | 4000 |  | 
|  | 4001 | ImmutableCallSite::arg_iterator CalleeArgIter = CS->arg_begin(); | 
|  | 4002 | ImmutableCallSite::arg_iterator CalleeArgEnd = CS->arg_end(); | 
|  | 4003 | Function::const_arg_iterator CallerArgIter = CallerFn->arg_begin(); | 
|  | 4004 |  | 
|  | 4005 | for (; CalleeArgIter != CalleeArgEnd; ++CalleeArgIter, ++CallerArgIter) { | 
|  | 4006 | const Value* CalleeArg = *CalleeArgIter; | 
|  | 4007 | const Value* CallerArg = &(*CallerArgIter); | 
|  | 4008 | if (CalleeArg == CallerArg) | 
|  | 4009 | continue; | 
|  | 4010 |  | 
|  | 4011 | // e.g. @caller([4 x i64] %a, [4 x i64] %b) { | 
|  | 4012 | //        tail call @callee([4 x i64] undef, [4 x i64] %b) | 
|  | 4013 | //      } | 
|  | 4014 | // 1st argument of callee is undef and has the same type as caller. | 
|  | 4015 | if (CalleeArg->getType() == CallerArg->getType() && | 
|  | 4016 | isa<UndefValue>(CalleeArg)) | 
|  | 4017 | continue; | 
|  | 4018 |  | 
|  | 4019 | return false; | 
|  | 4020 | } | 
|  | 4021 |  | 
|  | 4022 | return true; | 
|  | 4023 | } | 
|  | 4024 |  | 
|  | 4025 | bool | 
|  | 4026 | PPCTargetLowering::IsEligibleForTailCallOptimization_64SVR4( | 
|  | 4027 | SDValue Callee, | 
|  | 4028 | CallingConv::ID CalleeCC, | 
|  | 4029 | ImmutableCallSite *CS, | 
|  | 4030 | bool isVarArg, | 
|  | 4031 | const SmallVectorImpl<ISD::OutputArg> &Outs, | 
|  | 4032 | const SmallVectorImpl<ISD::InputArg> &Ins, | 
|  | 4033 | SelectionDAG& DAG) const { | 
|  | 4034 | bool TailCallOpt = getTargetMachine().Options.GuaranteedTailCallOpt; | 
|  | 4035 |  | 
|  | 4036 | if (DisableSCO && !TailCallOpt) return false; | 
|  | 4037 |  | 
|  | 4038 | // Variadic argument functions are not supported. | 
|  | 4039 | if (isVarArg) return false; | 
|  | 4040 |  | 
|  | 4041 | MachineFunction &MF = DAG.getMachineFunction(); | 
|  | 4042 | CallingConv::ID CallerCC = MF.getFunction()->getCallingConv(); | 
|  | 4043 |  | 
|  | 4044 | // Tail or Sibling call optimization (TCO/SCO) needs callee and caller has | 
|  | 4045 | // the same calling convention | 
|  | 4046 | if (CallerCC != CalleeCC) return false; | 
|  | 4047 |  | 
|  | 4048 | // SCO support C calling convention | 
|  | 4049 | if (CalleeCC != CallingConv::Fast && CalleeCC != CallingConv::C) | 
|  | 4050 | return false; | 
|  | 4051 |  | 
| Chuang-Yu Cheng | f7ba716 | 2016-08-17 03:17:44 +0000 | [diff] [blame] | 4052 | // Caller contains any byval parameter is not supported. | 
| David Majnemer | 0a16c22 | 2016-08-11 21:15:00 +0000 | [diff] [blame] | 4053 | if (any_of(Ins, [](const ISD::InputArg &IA) { return IA.Flags.isByVal(); })) | 
| Chuang-Yu Cheng | 2e5973e | 2016-04-06 02:04:38 +0000 | [diff] [blame] | 4054 | return false; | 
|  | 4055 |  | 
| Chuang-Yu Cheng | f7ba716 | 2016-08-17 03:17:44 +0000 | [diff] [blame] | 4056 | // Callee contains any byval parameter is not supported, too. | 
|  | 4057 | // Note: This is a quick work around, because in some cases, e.g. | 
|  | 4058 | // caller's stack size > callee's stack size, we are still able to apply | 
|  | 4059 | // sibling call optimization. See: https://reviews.llvm.org/D23441#513574 | 
|  | 4060 | if (any_of(Outs, [](const ISD::OutputArg& OA) { return OA.Flags.isByVal(); })) | 
|  | 4061 | return false; | 
|  | 4062 |  | 
| Chuang-Yu Cheng | 2e5973e | 2016-04-06 02:04:38 +0000 | [diff] [blame] | 4063 | // No TCO/SCO on indirect call because Caller have to restore its TOC | 
|  | 4064 | if (!isFunctionGlobalAddress(Callee) && | 
|  | 4065 | !isa<ExternalSymbolSDNode>(Callee)) | 
|  | 4066 | return false; | 
|  | 4067 |  | 
|  | 4068 | // Check if Callee resides in the same module, because for now, PPC64 SVR4 ABI | 
|  | 4069 | // (ELFv1/ELFv2) doesn't allow tail calls to a symbol resides in another | 
|  | 4070 | // module. | 
|  | 4071 | // ref: https://bugzilla.mozilla.org/show_bug.cgi?id=973977 | 
|  | 4072 | if (!resideInSameModule(Callee, getTargetMachine().getRelocationModel())) | 
|  | 4073 | return false; | 
|  | 4074 |  | 
|  | 4075 | // TCO allows altering callee ABI, so we don't have to check further. | 
|  | 4076 | if (CalleeCC == CallingConv::Fast && TailCallOpt) | 
|  | 4077 | return true; | 
|  | 4078 |  | 
|  | 4079 | if (DisableSCO) return false; | 
|  | 4080 |  | 
|  | 4081 | // If callee use the same argument list that caller is using, then we can | 
|  | 4082 | // apply SCO on this case. If it is not, then we need to check if callee needs | 
|  | 4083 | // stack for passing arguments. | 
|  | 4084 | if (!hasSameArgumentList(MF.getFunction(), CS) && | 
|  | 4085 | needStackSlotPassParameters(Subtarget, Outs)) { | 
|  | 4086 | return false; | 
|  | 4087 | } | 
|  | 4088 |  | 
|  | 4089 | return true; | 
|  | 4090 | } | 
|  | 4091 |  | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4092 | /// IsEligibleForTailCallOptimization - Check whether the call is eligible | 
|  | 4093 | /// for tail call optimization. Targets which want to do tail call | 
|  | 4094 | /// optimization should implement this function. | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4095 | bool | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4096 | PPCTargetLowering::IsEligibleForTailCallOptimization(SDValue Callee, | 
| Sandeep Patel | 68c5f47 | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 4097 | CallingConv::ID CalleeCC, | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4098 | bool isVarArg, | 
|  | 4099 | const SmallVectorImpl<ISD::InputArg> &Ins, | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4100 | SelectionDAG& DAG) const { | 
| Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 4101 | if (!getTargetMachine().Options.GuaranteedTailCallOpt) | 
| Evan Cheng | 25217ff | 2010-01-29 23:05:56 +0000 | [diff] [blame] | 4102 | return false; | 
|  | 4103 |  | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4104 | // Variable argument functions are not supported. | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4105 | if (isVarArg) | 
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 4106 | return false; | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4107 |  | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4108 | MachineFunction &MF = DAG.getMachineFunction(); | 
| Sandeep Patel | 68c5f47 | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 4109 | CallingConv::ID CallerCC = MF.getFunction()->getCallingConv(); | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4110 | if (CalleeCC == CallingConv::Fast && CallerCC == CalleeCC) { | 
|  | 4111 | // Functions containing by val parameters are not supported. | 
|  | 4112 | for (unsigned i = 0; i != Ins.size(); i++) { | 
|  | 4113 | ISD::ArgFlagsTy Flags = Ins[i].Flags; | 
|  | 4114 | if (Flags.isByVal()) return false; | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4115 | } | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4116 |  | 
| Alp Toker | f907b89 | 2013-12-05 05:44:44 +0000 | [diff] [blame] | 4117 | // Non-PIC/GOT tail calls are supported. | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4118 | if (getTargetMachine().getRelocationModel() != Reloc::PIC_) | 
|  | 4119 | return true; | 
|  | 4120 |  | 
|  | 4121 | // At the moment we can only do local tail calls (in same module, hidden | 
|  | 4122 | // or protected) if we are generating PIC. | 
|  | 4123 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) | 
|  | 4124 | return G->getGlobal()->hasHiddenVisibility() | 
|  | 4125 | || G->getGlobal()->hasProtectedVisibility(); | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4126 | } | 
|  | 4127 |  | 
|  | 4128 | return false; | 
|  | 4129 | } | 
|  | 4130 |  | 
| Chris Lattner | eb755fc | 2006-05-17 19:00:46 +0000 | [diff] [blame] | 4131 | /// isCallCompatibleAddress - Return the immediate to use if the specified | 
|  | 4132 | /// 32-bit value is representable in the immediate field of a BxA instruction. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4133 | static SDNode *isBLACompatibleAddress(SDValue Op, SelectionDAG &DAG) { | 
| Chris Lattner | eb755fc | 2006-05-17 19:00:46 +0000 | [diff] [blame] | 4134 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op); | 
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 4135 | if (!C) return nullptr; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 4136 |  | 
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 4137 | int Addr = C->getZExtValue(); | 
| Chris Lattner | eb755fc | 2006-05-17 19:00:46 +0000 | [diff] [blame] | 4138 | if ((Addr & 3) != 0 ||  // Low 2 bits are implicitly zero. | 
| Richard Smith | 228e6d4 | 2012-08-24 23:29:28 +0000 | [diff] [blame] | 4139 | SignExtend32<26>(Addr) != Addr) | 
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 4140 | return nullptr;  // Top 6 bits have to be sext of immediate. | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 4141 |  | 
| Eric Christopher | cd71946 | 2016-07-07 01:49:59 +0000 | [diff] [blame] | 4142 | return DAG | 
|  | 4143 | .getConstant( | 
|  | 4144 | (int)C->getZExtValue() >> 2, SDLoc(Op), | 
|  | 4145 | DAG.getTargetLoweringInfo().getPointerTy(DAG.getDataLayout())) | 
|  | 4146 | .getNode(); | 
| Chris Lattner | eb755fc | 2006-05-17 19:00:46 +0000 | [diff] [blame] | 4147 | } | 
|  | 4148 |  | 
| Dan Gohman | d78c400 | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 4149 | namespace { | 
|  | 4150 |  | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4151 | struct TailCallArgumentInfo { | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4152 | SDValue Arg; | 
|  | 4153 | SDValue FrameIdxOp; | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4154 | int       FrameIdx; | 
|  | 4155 |  | 
|  | 4156 | TailCallArgumentInfo() : FrameIdx(0) {} | 
|  | 4157 | }; | 
| Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 4158 | } | 
| Dan Gohman | d78c400 | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 4159 |  | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4160 | /// StoreTailCallArgumentsToStackSlot - Stores arguments to their stack slot. | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 4161 | static void StoreTailCallArgumentsToStackSlot( | 
|  | 4162 | SelectionDAG &DAG, SDValue Chain, | 
|  | 4163 | const SmallVectorImpl<TailCallArgumentInfo> &TailCallArgs, | 
|  | 4164 | SmallVectorImpl<SDValue> &MemOpChains, const SDLoc &dl) { | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4165 | for (unsigned i = 0, e = TailCallArgs.size(); i != e; ++i) { | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4166 | SDValue Arg = TailCallArgs[i].Arg; | 
|  | 4167 | SDValue FIN = TailCallArgs[i].FrameIdxOp; | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4168 | int FI = TailCallArgs[i].FrameIdx; | 
|  | 4169 | // Store relative to framepointer. | 
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 4170 | MemOpChains.push_back(DAG.getStore( | 
|  | 4171 | Chain, dl, Arg, FIN, | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 4172 | MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FI))); | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4173 | } | 
|  | 4174 | } | 
|  | 4175 |  | 
|  | 4176 | /// EmitTailCallStoreFPAndRetAddr - Move the frame pointer and return address to | 
|  | 4177 | /// the appropriate stack slot for the tail call optimized function call. | 
| Eric Christopher | c16ccbe | 2016-07-07 00:39:30 +0000 | [diff] [blame] | 4178 | static SDValue EmitTailCallStoreFPAndRetAddr(SelectionDAG &DAG, SDValue Chain, | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 4179 | SDValue OldRetAddr, SDValue OldFP, | 
| Eric Christopher | 327e440 | 2016-07-07 01:08:17 +0000 | [diff] [blame] | 4180 | int SPDiff, const SDLoc &dl) { | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4181 | if (SPDiff) { | 
|  | 4182 | // Calculate the new stack slot for the return address. | 
| Eric Christopher | c16ccbe | 2016-07-07 00:39:30 +0000 | [diff] [blame] | 4183 | MachineFunction &MF = DAG.getMachineFunction(); | 
| Eric Christopher | ade4eed | 2016-07-07 00:39:32 +0000 | [diff] [blame] | 4184 | const PPCSubtarget &Subtarget = MF.getSubtarget<PPCSubtarget>(); | 
|  | 4185 | const PPCFrameLowering *FL = Subtarget.getFrameLowering(); | 
|  | 4186 | bool isPPC64 = Subtarget.isPPC64(); | 
|  | 4187 | int SlotSize = isPPC64 ? 8 : 4; | 
| Eric Christopher | dc3a8a4 | 2015-02-13 00:39:38 +0000 | [diff] [blame] | 4188 | int NewRetAddrLoc = SPDiff + FL->getReturnSaveOffset(); | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 4189 | int NewRetAddr = MF.getFrameInfo().CreateFixedObject(SlotSize, | 
|  | 4190 | NewRetAddrLoc, true); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4191 | EVT VT = isPPC64 ? MVT::i64 : MVT::i32; | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4192 | SDValue NewRetAddrFrIdx = DAG.getFrameIndex(NewRetAddr, VT); | 
| Eric Christopher | c16ccbe | 2016-07-07 00:39:30 +0000 | [diff] [blame] | 4193 | Chain = DAG.getStore(Chain, dl, OldRetAddr, NewRetAddrFrIdx, | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 4194 | MachinePointerInfo::getFixedStack(MF, NewRetAddr)); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4195 |  | 
| Tilmann Scheller | d1aaa32 | 2009-08-15 11:54:46 +0000 | [diff] [blame] | 4196 | // When using the 32/64-bit SVR4 ABI there is no need to move the FP stack | 
|  | 4197 | // slot as the FP is never overwritten. | 
| Eric Christopher | 327e440 | 2016-07-07 01:08:17 +0000 | [diff] [blame] | 4198 | if (Subtarget.isDarwinABI()) { | 
| Eric Christopher | dc3a8a4 | 2015-02-13 00:39:38 +0000 | [diff] [blame] | 4199 | int NewFPLoc = SPDiff + FL->getFramePointerSaveOffset(); | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 4200 | int NewFPIdx = MF.getFrameInfo().CreateFixedObject(SlotSize, NewFPLoc, | 
|  | 4201 | true); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4202 | SDValue NewFramePtrIdx = DAG.getFrameIndex(NewFPIdx, VT); | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 4203 | Chain = DAG.getStore(Chain, dl, OldFP, NewFramePtrIdx, | 
|  | 4204 | MachinePointerInfo::getFixedStack( | 
|  | 4205 | DAG.getMachineFunction(), NewFPIdx)); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4206 | } | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4207 | } | 
|  | 4208 | return Chain; | 
|  | 4209 | } | 
|  | 4210 |  | 
|  | 4211 | /// CalculateTailCallArgDest - Remember Argument for later processing. Calculate | 
|  | 4212 | /// the position of the argument. | 
|  | 4213 | static void | 
|  | 4214 | CalculateTailCallArgDest(SelectionDAG &DAG, MachineFunction &MF, bool isPPC64, | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4215 | SDValue Arg, int SPDiff, unsigned ArgOffset, | 
| Craig Topper | b94011f | 2013-07-14 04:42:23 +0000 | [diff] [blame] | 4216 | SmallVectorImpl<TailCallArgumentInfo>& TailCallArguments) { | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4217 | int Offset = ArgOffset + SPDiff; | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 4218 | uint32_t OpSize = (Arg.getValueType().getSizeInBits()+7)/8; | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 4219 | int FI = MF.getFrameInfo().CreateFixedObject(OpSize, Offset, true); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4220 | EVT VT = isPPC64 ? MVT::i64 : MVT::i32; | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4221 | SDValue FIN = DAG.getFrameIndex(FI, VT); | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4222 | TailCallArgumentInfo Info; | 
|  | 4223 | Info.Arg = Arg; | 
|  | 4224 | Info.FrameIdxOp = FIN; | 
|  | 4225 | Info.FrameIdx = FI; | 
|  | 4226 | TailCallArguments.push_back(Info); | 
|  | 4227 | } | 
|  | 4228 |  | 
|  | 4229 | /// EmitTCFPAndRetAddrLoad - Emit load from frame pointer and return address | 
|  | 4230 | /// stack slot. Returns the chain as result and the loaded frame pointers in | 
|  | 4231 | /// LROpOut/FPOpout. Used when tail calling. | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 4232 | SDValue PPCTargetLowering::EmitTailCallLoadFPAndRetAddr( | 
|  | 4233 | SelectionDAG &DAG, int SPDiff, SDValue Chain, SDValue &LROpOut, | 
| Eric Christopher | e0d09ba | 2016-07-07 01:08:21 +0000 | [diff] [blame] | 4234 | SDValue &FPOpOut, const SDLoc &dl) const { | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4235 | if (SPDiff) { | 
|  | 4236 | // Load the LR and FP stack slot for later adjusting. | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 4237 | EVT VT = Subtarget.isPPC64() ? MVT::i64 : MVT::i32; | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4238 | LROpOut = getReturnAddrFrameIndex(DAG); | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 4239 | LROpOut = DAG.getLoad(VT, dl, Chain, LROpOut, MachinePointerInfo()); | 
| Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 4240 | Chain = SDValue(LROpOut.getNode(), 1); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4241 |  | 
| Tilmann Scheller | d1aaa32 | 2009-08-15 11:54:46 +0000 | [diff] [blame] | 4242 | // When using the 32/64-bit SVR4 ABI there is no need to load the FP stack | 
|  | 4243 | // slot as the FP is never overwritten. | 
| Eric Christopher | e0d09ba | 2016-07-07 01:08:21 +0000 | [diff] [blame] | 4244 | if (Subtarget.isDarwinABI()) { | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4245 | FPOpOut = getFramePointerFrameIndex(DAG); | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 4246 | FPOpOut = DAG.getLoad(VT, dl, Chain, FPOpOut, MachinePointerInfo()); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4247 | Chain = SDValue(FPOpOut.getNode(), 1); | 
|  | 4248 | } | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4249 | } | 
|  | 4250 | return Chain; | 
|  | 4251 | } | 
|  | 4252 |  | 
| Dale Johannesen | 85d41a1 | 2008-03-04 23:17:14 +0000 | [diff] [blame] | 4253 | /// CreateCopyOfByValArgument - Make a copy of an aggregate at address specified | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 4254 | /// by "Src" to address "Dst" of size "Size".  Alignment information is | 
| Dale Johannesen | 85d41a1 | 2008-03-04 23:17:14 +0000 | [diff] [blame] | 4255 | /// specified by the specific parameter attribute. The copy will be passed as | 
|  | 4256 | /// a byval function parameter. | 
|  | 4257 | /// Sometimes what we are copying is the end of a larger object, the part that | 
|  | 4258 | /// does not fit in registers. | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 4259 | static SDValue CreateCopyOfByValArgument(SDValue Src, SDValue Dst, | 
|  | 4260 | SDValue Chain, ISD::ArgFlagsTy Flags, | 
|  | 4261 | SelectionDAG &DAG, const SDLoc &dl) { | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4262 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), dl, MVT::i32); | 
| Dale Johannesen | 8526388 | 2009-02-04 01:17:06 +0000 | [diff] [blame] | 4263 | return DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, Flags.getByValAlign(), | 
| Krzysztof Parzyszek | a46c36b | 2015-04-13 17:16:45 +0000 | [diff] [blame] | 4264 | false, false, false, MachinePointerInfo(), | 
| Nick Lewycky | aad475b | 2014-04-15 07:22:52 +0000 | [diff] [blame] | 4265 | MachinePointerInfo()); | 
| Dale Johannesen | 85d41a1 | 2008-03-04 23:17:14 +0000 | [diff] [blame] | 4266 | } | 
| Chris Lattner | 43df5b3 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 4267 |  | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4268 | /// LowerMemOpCallTo - Store the argument to the stack or remember it in case of | 
|  | 4269 | /// tail calls. | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 4270 | static void LowerMemOpCallTo( | 
|  | 4271 | SelectionDAG &DAG, MachineFunction &MF, SDValue Chain, SDValue Arg, | 
|  | 4272 | SDValue PtrOff, int SPDiff, unsigned ArgOffset, bool isPPC64, | 
|  | 4273 | bool isTailCall, bool isVector, SmallVectorImpl<SDValue> &MemOpChains, | 
|  | 4274 | SmallVectorImpl<TailCallArgumentInfo> &TailCallArguments, const SDLoc &dl) { | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 4275 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(DAG.getDataLayout()); | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4276 | if (!isTailCall) { | 
|  | 4277 | if (isVector) { | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4278 | SDValue StackPtr; | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4279 | if (isPPC64) | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4280 | StackPtr = DAG.getRegister(PPC::X1, MVT::i64); | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4281 | else | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4282 | StackPtr = DAG.getRegister(PPC::R1, MVT::i32); | 
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 4283 | PtrOff = DAG.getNode(ISD::ADD, dl, PtrVT, StackPtr, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4284 | DAG.getConstant(ArgOffset, dl, PtrVT)); | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4285 | } | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 4286 | MemOpChains.push_back( | 
|  | 4287 | DAG.getStore(Chain, dl, Arg, PtrOff, MachinePointerInfo())); | 
|  | 4288 | // Calculate and remember argument location. | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 4289 | } else CalculateTailCallArgDest(DAG, MF, isPPC64, Arg, SPDiff, ArgOffset, | 
|  | 4290 | TailCallArguments); | 
|  | 4291 | } | 
|  | 4292 |  | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 4293 | static void | 
|  | 4294 | PrepareTailCall(SelectionDAG &DAG, SDValue &InFlag, SDValue &Chain, | 
| Eric Christopher | 327e440 | 2016-07-07 01:08:17 +0000 | [diff] [blame] | 4295 | const SDLoc &dl, int SPDiff, unsigned NumBytes, SDValue LROp, | 
|  | 4296 | SDValue FPOp, | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 4297 | SmallVectorImpl<TailCallArgumentInfo> &TailCallArguments) { | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4298 | // Emit a sequence of copyto/copyfrom virtual registers for arguments that | 
|  | 4299 | // might overwrite each other in case of tail call optimization. | 
|  | 4300 | SmallVector<SDValue, 8> MemOpChains2; | 
| Chris Lattner | 0ab5e2c | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 4301 | // Do not flag preceding copytoreg stuff together with the following stuff. | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4302 | InFlag = SDValue(); | 
|  | 4303 | StoreTailCallArgumentsToStackSlot(DAG, Chain, TailCallArguments, | 
|  | 4304 | MemOpChains2, dl); | 
|  | 4305 | if (!MemOpChains2.empty()) | 
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 4306 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains2); | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4307 |  | 
|  | 4308 | // Store the return address to the appropriate stack slot. | 
| Eric Christopher | 327e440 | 2016-07-07 01:08:17 +0000 | [diff] [blame] | 4309 | Chain = EmitTailCallStoreFPAndRetAddr(DAG, Chain, LROp, FPOp, SPDiff, dl); | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4310 |  | 
|  | 4311 | // Emit callseq_end just before tailcall node. | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4312 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, dl, true), | 
|  | 4313 | DAG.getIntPtrConstant(0, dl, true), InFlag, dl); | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4314 | InFlag = Chain.getValue(1); | 
|  | 4315 | } | 
|  | 4316 |  | 
| Hal Finkel | 87deb0b | 2015-01-12 04:34:47 +0000 | [diff] [blame] | 4317 | // Is this global address that of a function that can be called by name? (as | 
|  | 4318 | // opposed to something that must hold a descriptor for an indirect call). | 
|  | 4319 | static bool isFunctionGlobalAddress(SDValue Callee) { | 
|  | 4320 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { | 
|  | 4321 | if (Callee.getOpcode() == ISD::GlobalTLSAddress || | 
|  | 4322 | Callee.getOpcode() == ISD::TargetGlobalTLSAddress) | 
|  | 4323 | return false; | 
|  | 4324 |  | 
| Manuel Jacob | 5f6eaac | 2016-01-16 20:30:46 +0000 | [diff] [blame] | 4325 | return G->getGlobal()->getValueType()->isFunctionTy(); | 
| Hal Finkel | 87deb0b | 2015-01-12 04:34:47 +0000 | [diff] [blame] | 4326 | } | 
|  | 4327 |  | 
|  | 4328 | return false; | 
|  | 4329 | } | 
|  | 4330 |  | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 4331 | static unsigned | 
|  | 4332 | PrepareCall(SelectionDAG &DAG, SDValue &Callee, SDValue &InFlag, SDValue &Chain, | 
|  | 4333 | SDValue CallSeqStart, const SDLoc &dl, int SPDiff, bool isTailCall, | 
| Eric Christopher | 2454a3b | 2016-07-07 01:08:23 +0000 | [diff] [blame] | 4334 | bool isPatchPoint, bool hasNest, | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 4335 | SmallVectorImpl<std::pair<unsigned, SDValue>> &RegsToPass, | 
|  | 4336 | SmallVectorImpl<SDValue> &Ops, std::vector<EVT> &NodeTys, | 
|  | 4337 | ImmutableCallSite *CS, const PPCSubtarget &Subtarget) { | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4338 |  | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 4339 | bool isPPC64 = Subtarget.isPPC64(); | 
|  | 4340 | bool isSVR4ABI = Subtarget.isSVR4ABI(); | 
| Ulrich Weigand | aa0ac4f | 2014-07-20 23:31:44 +0000 | [diff] [blame] | 4341 | bool isELFv2ABI = Subtarget.isELFv2ABI(); | 
| Chris Lattner | df8e17d | 2010-11-14 23:42:06 +0000 | [diff] [blame] | 4342 |  | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 4343 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(DAG.getDataLayout()); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4344 | NodeTys.push_back(MVT::Other);   // Returns a chain | 
| Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 4345 | NodeTys.push_back(MVT::Glue);    // Returns a flag for retval copy to use. | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4346 |  | 
| Ulrich Weigand | f62e83f | 2013-03-22 15:24:13 +0000 | [diff] [blame] | 4347 | unsigned CallOpc = PPCISD::CALL; | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4348 |  | 
| Torok Edwin | 31e90d2 | 2010-08-04 20:47:44 +0000 | [diff] [blame] | 4349 | bool needIndirectCall = true; | 
| Ulrich Weigand | 9aa09ef | 2014-06-18 16:14:04 +0000 | [diff] [blame] | 4350 | if (!isSVR4ABI || !isPPC64) | 
|  | 4351 | if (SDNode *Dest = isBLACompatibleAddress(Callee, DAG)) { | 
|  | 4352 | // If this is an absolute destination address, use the munged value. | 
|  | 4353 | Callee = SDValue(Dest, 0); | 
|  | 4354 | needIndirectCall = false; | 
|  | 4355 | } | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4356 |  | 
| Rafael Espindola | 53fd425 | 2016-06-23 18:43:06 +0000 | [diff] [blame] | 4357 | // PC-relative references to external symbols should go through $stub, unless | 
|  | 4358 | // we're building with the leopard linker or later, which automatically | 
|  | 4359 | // synthesizes these stubs. | 
| Rafael Espindola | 3beef8d | 2016-06-27 23:15:57 +0000 | [diff] [blame] | 4360 | const TargetMachine &TM = DAG.getTarget(); | 
| Rafael Espindola | 53fd425 | 2016-06-23 18:43:06 +0000 | [diff] [blame] | 4361 | const Module *Mod = DAG.getMachineFunction().getFunction()->getParent(); | 
|  | 4362 | const GlobalValue *GV = nullptr; | 
|  | 4363 | if (auto *G = dyn_cast<GlobalAddressSDNode>(Callee)) | 
|  | 4364 | GV = G->getGlobal(); | 
| Rafael Espindola | 3beef8d | 2016-06-27 23:15:57 +0000 | [diff] [blame] | 4365 | bool Local = TM.shouldAssumeDSOLocal(*Mod, GV); | 
| Rafael Espindola | a99ccfc | 2016-06-29 14:59:50 +0000 | [diff] [blame] | 4366 | bool UsePlt = !Local && Subtarget.isTargetELF() && !isPPC64; | 
| Rafael Espindola | 53fd425 | 2016-06-23 18:43:06 +0000 | [diff] [blame] | 4367 |  | 
| Hal Finkel | 87deb0b | 2015-01-12 04:34:47 +0000 | [diff] [blame] | 4368 | if (isFunctionGlobalAddress(Callee)) { | 
|  | 4369 | GlobalAddressSDNode *G = cast<GlobalAddressSDNode>(Callee); | 
|  | 4370 | // A call to a TLS address is actually an indirect call to a | 
|  | 4371 | // thread-specific pointer. | 
| Eric Christopher | 79cc1e3 | 2014-09-02 22:28:02 +0000 | [diff] [blame] | 4372 | unsigned OpFlags = 0; | 
| Rafael Espindola | 53fd425 | 2016-06-23 18:43:06 +0000 | [diff] [blame] | 4373 | if (UsePlt) | 
| Rafael Espindola | a99ccfc | 2016-06-29 14:59:50 +0000 | [diff] [blame] | 4374 | OpFlags = PPCII::MO_PLT; | 
| Eric Christopher | 79cc1e3 | 2014-09-02 22:28:02 +0000 | [diff] [blame] | 4375 |  | 
|  | 4376 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, | 
|  | 4377 | // every direct call is) turn it into a TargetGlobalAddress / | 
|  | 4378 | // TargetExternalSymbol node so that legalize doesn't hack it. | 
|  | 4379 | Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl, | 
|  | 4380 | Callee.getValueType(), 0, OpFlags); | 
|  | 4381 | needIndirectCall = false; | 
| Torok Edwin | 31e90d2 | 2010-08-04 20:47:44 +0000 | [diff] [blame] | 4382 | } | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4383 |  | 
| Torok Edwin | 31e90d2 | 2010-08-04 20:47:44 +0000 | [diff] [blame] | 4384 | if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) { | 
| Chris Lattner | df8e17d | 2010-11-14 23:42:06 +0000 | [diff] [blame] | 4385 | unsigned char OpFlags = 0; | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4386 |  | 
| Rafael Espindola | 53fd425 | 2016-06-23 18:43:06 +0000 | [diff] [blame] | 4387 | if (UsePlt) | 
| Rafael Espindola | a99ccfc | 2016-06-29 14:59:50 +0000 | [diff] [blame] | 4388 | OpFlags = PPCII::MO_PLT; | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4389 |  | 
| Chris Lattner | df8e17d | 2010-11-14 23:42:06 +0000 | [diff] [blame] | 4390 | Callee = DAG.getTargetExternalSymbol(S->getSymbol(), Callee.getValueType(), | 
|  | 4391 | OpFlags); | 
|  | 4392 | needIndirectCall = false; | 
| Torok Edwin | 31e90d2 | 2010-08-04 20:47:44 +0000 | [diff] [blame] | 4393 | } | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4394 |  | 
| Eric Christopher | 2454a3b | 2016-07-07 01:08:23 +0000 | [diff] [blame] | 4395 | if (isPatchPoint) { | 
| Hal Finkel | 934361a | 2015-01-14 01:07:51 +0000 | [diff] [blame] | 4396 | // We'll form an invalid direct call when lowering a patchpoint; the full | 
|  | 4397 | // sequence for an indirect call is complicated, and many of the | 
|  | 4398 | // instructions introduced might have side effects (and, thus, can't be | 
|  | 4399 | // removed later). The call itself will be removed as soon as the | 
|  | 4400 | // argument/return lowering is complete, so the fact that it has the wrong | 
|  | 4401 | // kind of operands should not really matter. | 
|  | 4402 | needIndirectCall = false; | 
|  | 4403 | } | 
|  | 4404 |  | 
| Torok Edwin | 31e90d2 | 2010-08-04 20:47:44 +0000 | [diff] [blame] | 4405 | if (needIndirectCall) { | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4406 | // Otherwise, this is an indirect call.  We have to use a MTCTR/BCTRL pair | 
|  | 4407 | // to do the call, we can't use PPCISD::CALL. | 
|  | 4408 | SDValue MTCTROps[] = {Chain, Callee, InFlag}; | 
| Tilmann Scheller | 79fef93 | 2009-12-18 13:00:15 +0000 | [diff] [blame] | 4409 |  | 
| Hal Finkel | 63fb928 | 2015-01-13 18:25:05 +0000 | [diff] [blame] | 4410 | if (isSVR4ABI && isPPC64 && !isELFv2ABI) { | 
| Tilmann Scheller | 79fef93 | 2009-12-18 13:00:15 +0000 | [diff] [blame] | 4411 | // Function pointers in the 64-bit SVR4 ABI do not point to the function | 
|  | 4412 | // entry point, but to the function descriptor (the function entry point | 
|  | 4413 | // address is part of the function descriptor though). | 
|  | 4414 | // The function descriptor is a three doubleword structure with the | 
|  | 4415 | // following fields: function entry point, TOC base address and | 
|  | 4416 | // environment pointer. | 
|  | 4417 | // Thus for a call through a function pointer, the following actions need | 
|  | 4418 | // to be performed: | 
|  | 4419 | //   1. Save the TOC of the caller in the TOC save area of its stack | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 4420 | //      frame (this is done in LowerCall_Darwin() or LowerCall_64SVR4()). | 
| Tilmann Scheller | 79fef93 | 2009-12-18 13:00:15 +0000 | [diff] [blame] | 4421 | //   2. Load the address of the function entry point from the function | 
|  | 4422 | //      descriptor. | 
|  | 4423 | //   3. Load the TOC of the callee from the function descriptor into r2. | 
|  | 4424 | //   4. Load the environment pointer from the function descriptor into | 
|  | 4425 | //      r11. | 
|  | 4426 | //   5. Branch to the function entry point address. | 
|  | 4427 | //   6. On return of the callee, the TOC of the caller needs to be | 
|  | 4428 | //      restored (this is done in FinishCall()). | 
|  | 4429 | // | 
| Hal Finkel | e2ab0f1 | 2015-01-15 21:17:34 +0000 | [diff] [blame] | 4430 | // The loads are scheduled at the beginning of the call sequence, and the | 
|  | 4431 | // register copies are flagged together to ensure that no other | 
| Tilmann Scheller | 79fef93 | 2009-12-18 13:00:15 +0000 | [diff] [blame] | 4432 | // operations can be scheduled in between. E.g. without flagging the | 
| Hal Finkel | e2ab0f1 | 2015-01-15 21:17:34 +0000 | [diff] [blame] | 4433 | // copies together, a TOC access in the caller could be scheduled between | 
|  | 4434 | // the assignment of the callee TOC and the branch to the callee, which | 
| Tilmann Scheller | 79fef93 | 2009-12-18 13:00:15 +0000 | [diff] [blame] | 4435 | // results in the TOC access going through the TOC of the callee instead | 
|  | 4436 | // of going through the TOC of the caller, which leads to incorrect code. | 
|  | 4437 |  | 
|  | 4438 | // Load the address of the function entry point from the function | 
|  | 4439 | // descriptor. | 
| Hal Finkel | e2ab0f1 | 2015-01-15 21:17:34 +0000 | [diff] [blame] | 4440 | SDValue LDChain = CallSeqStart.getValue(CallSeqStart->getNumValues()-1); | 
|  | 4441 | if (LDChain.getValueType() == MVT::Glue) | 
|  | 4442 | LDChain = CallSeqStart.getValue(CallSeqStart->getNumValues()-2); | 
|  | 4443 |  | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 4444 | auto MMOFlags = Subtarget.hasInvariantFunctionDescriptors() | 
|  | 4445 | ? MachineMemOperand::MOInvariant | 
|  | 4446 | : MachineMemOperand::MONone; | 
| Hal Finkel | e2ab0f1 | 2015-01-15 21:17:34 +0000 | [diff] [blame] | 4447 |  | 
|  | 4448 | MachinePointerInfo MPI(CS ? CS->getCalledValue() : nullptr); | 
|  | 4449 | SDValue LoadFuncPtr = DAG.getLoad(MVT::i64, dl, LDChain, Callee, MPI, | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 4450 | /* Alignment = */ 8, MMOFlags); | 
| Tilmann Scheller | 79fef93 | 2009-12-18 13:00:15 +0000 | [diff] [blame] | 4451 |  | 
|  | 4452 | // Load environment pointer into r11. | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4453 | SDValue PtrOff = DAG.getIntPtrConstant(16, dl); | 
| Tilmann Scheller | 79fef93 | 2009-12-18 13:00:15 +0000 | [diff] [blame] | 4454 | SDValue AddPtr = DAG.getNode(ISD::ADD, dl, MVT::i64, Callee, PtrOff); | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 4455 | SDValue LoadEnvPtr = | 
|  | 4456 | DAG.getLoad(MVT::i64, dl, LDChain, AddPtr, MPI.getWithOffset(16), | 
|  | 4457 | /* Alignment = */ 8, MMOFlags); | 
| Hal Finkel | e2ab0f1 | 2015-01-15 21:17:34 +0000 | [diff] [blame] | 4458 |  | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4459 | SDValue TOCOff = DAG.getIntPtrConstant(8, dl); | 
| Hal Finkel | e2ab0f1 | 2015-01-15 21:17:34 +0000 | [diff] [blame] | 4460 | SDValue AddTOC = DAG.getNode(ISD::ADD, dl, MVT::i64, Callee, TOCOff); | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 4461 | SDValue TOCPtr = | 
|  | 4462 | DAG.getLoad(MVT::i64, dl, LDChain, AddTOC, MPI.getWithOffset(8), | 
|  | 4463 | /* Alignment = */ 8, MMOFlags); | 
| Hal Finkel | e2ab0f1 | 2015-01-15 21:17:34 +0000 | [diff] [blame] | 4464 |  | 
| Hal Finkel | e6698d5 | 2015-02-01 15:03:28 +0000 | [diff] [blame] | 4465 | setUsesTOCBasePtr(DAG); | 
| Hal Finkel | e2ab0f1 | 2015-01-15 21:17:34 +0000 | [diff] [blame] | 4466 | SDValue TOCVal = DAG.getCopyToReg(Chain, dl, PPC::X2, TOCPtr, | 
|  | 4467 | InFlag); | 
|  | 4468 | Chain = TOCVal.getValue(0); | 
|  | 4469 | InFlag = TOCVal.getValue(1); | 
| Tilmann Scheller | 79fef93 | 2009-12-18 13:00:15 +0000 | [diff] [blame] | 4470 |  | 
| Hal Finkel | 965cea5 | 2015-07-12 00:37:44 +0000 | [diff] [blame] | 4471 | // If the function call has an explicit 'nest' parameter, it takes the | 
|  | 4472 | // place of the environment pointer. | 
|  | 4473 | if (!hasNest) { | 
|  | 4474 | SDValue EnvVal = DAG.getCopyToReg(Chain, dl, PPC::X11, LoadEnvPtr, | 
|  | 4475 | InFlag); | 
| Hal Finkel | e2ab0f1 | 2015-01-15 21:17:34 +0000 | [diff] [blame] | 4476 |  | 
| Hal Finkel | 965cea5 | 2015-07-12 00:37:44 +0000 | [diff] [blame] | 4477 | Chain = EnvVal.getValue(0); | 
|  | 4478 | InFlag = EnvVal.getValue(1); | 
|  | 4479 | } | 
| Tilmann Scheller | 79fef93 | 2009-12-18 13:00:15 +0000 | [diff] [blame] | 4480 |  | 
| Tilmann Scheller | 79fef93 | 2009-12-18 13:00:15 +0000 | [diff] [blame] | 4481 | MTCTROps[0] = Chain; | 
|  | 4482 | MTCTROps[1] = LoadFuncPtr; | 
|  | 4483 | MTCTROps[2] = InFlag; | 
|  | 4484 | } | 
|  | 4485 |  | 
| Hal Finkel | 63fb928 | 2015-01-13 18:25:05 +0000 | [diff] [blame] | 4486 | Chain = DAG.getNode(PPCISD::MTCTR, dl, NodeTys, | 
|  | 4487 | makeArrayRef(MTCTROps, InFlag.getNode() ? 3 : 2)); | 
|  | 4488 | InFlag = Chain.getValue(1); | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4489 |  | 
|  | 4490 | NodeTys.clear(); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4491 | NodeTys.push_back(MVT::Other); | 
| Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 4492 | NodeTys.push_back(MVT::Glue); | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4493 | Ops.push_back(Chain); | 
| Ulrich Weigand | f62e83f | 2013-03-22 15:24:13 +0000 | [diff] [blame] | 4494 | CallOpc = PPCISD::BCTRL; | 
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 4495 | Callee.setNode(nullptr); | 
| Ulrich Weigand | f62e83f | 2013-03-22 15:24:13 +0000 | [diff] [blame] | 4496 | // Add use of X11 (holding environment pointer) | 
| Hal Finkel | 965cea5 | 2015-07-12 00:37:44 +0000 | [diff] [blame] | 4497 | if (isSVR4ABI && isPPC64 && !isELFv2ABI && !hasNest) | 
| Ulrich Weigand | f62e83f | 2013-03-22 15:24:13 +0000 | [diff] [blame] | 4498 | Ops.push_back(DAG.getRegister(PPC::X11, PtrVT)); | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4499 | // Add CTR register as callee so a bctr can be emitted later. | 
|  | 4500 | if (isTailCall) | 
| Roman Divacky | a4a59ae | 2011-06-03 15:47:49 +0000 | [diff] [blame] | 4501 | Ops.push_back(DAG.getRegister(isPPC64 ? PPC::CTR8 : PPC::CTR, PtrVT)); | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4502 | } | 
|  | 4503 |  | 
|  | 4504 | // If this is a direct call, pass the chain and the callee. | 
|  | 4505 | if (Callee.getNode()) { | 
|  | 4506 | Ops.push_back(Chain); | 
|  | 4507 | Ops.push_back(Callee); | 
|  | 4508 | } | 
|  | 4509 | // If this is a tail call add stack pointer delta. | 
|  | 4510 | if (isTailCall) | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4511 | Ops.push_back(DAG.getConstant(SPDiff, dl, MVT::i32)); | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4512 |  | 
|  | 4513 | // Add argument registers to the end of the list so that they are known live | 
|  | 4514 | // into the call. | 
|  | 4515 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) | 
|  | 4516 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, | 
|  | 4517 | RegsToPass[i].second.getValueType())); | 
|  | 4518 |  | 
| Hal Finkel | af51993 | 2015-01-19 07:20:27 +0000 | [diff] [blame] | 4519 | // All calls, in both the ELF V1 and V2 ABIs, need the TOC register live | 
|  | 4520 | // into the call. | 
| Eric Christopher | 2454a3b | 2016-07-07 01:08:23 +0000 | [diff] [blame] | 4521 | if (isSVR4ABI && isPPC64 && !isPatchPoint) { | 
| Hal Finkel | e6698d5 | 2015-02-01 15:03:28 +0000 | [diff] [blame] | 4522 | setUsesTOCBasePtr(DAG); | 
| Ulrich Weigand | aa0ac4f | 2014-07-20 23:31:44 +0000 | [diff] [blame] | 4523 | Ops.push_back(DAG.getRegister(PPC::X2, PtrVT)); | 
| Hal Finkel | e6698d5 | 2015-02-01 15:03:28 +0000 | [diff] [blame] | 4524 | } | 
| Ulrich Weigand | aa0ac4f | 2014-07-20 23:31:44 +0000 | [diff] [blame] | 4525 |  | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4526 | return CallOpc; | 
|  | 4527 | } | 
|  | 4528 |  | 
| Roman Divacky | 7629306 | 2012-09-18 16:47:58 +0000 | [diff] [blame] | 4529 | static | 
|  | 4530 | bool isLocalCall(const SDValue &Callee) | 
|  | 4531 | { | 
|  | 4532 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) | 
| Peter Collingbourne | 6a9d177 | 2015-07-05 20:52:35 +0000 | [diff] [blame] | 4533 | return G->getGlobal()->isStrongDefinitionForLinker(); | 
| Roman Divacky | 7629306 | 2012-09-18 16:47:58 +0000 | [diff] [blame] | 4534 | return false; | 
|  | 4535 | } | 
|  | 4536 |  | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 4537 | SDValue PPCTargetLowering::LowerCallResult( | 
|  | 4538 | SDValue Chain, SDValue InFlag, CallingConv::ID CallConv, bool isVarArg, | 
|  | 4539 | const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl, | 
|  | 4540 | SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const { | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4541 |  | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4542 | SmallVector<CCValAssign, 16> RVLocs; | 
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 4543 | CCState CCRetInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs, | 
|  | 4544 | *DAG.getContext()); | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4545 | CCRetInfo.AnalyzeCallResult(Ins, RetCC_PPC); | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4546 |  | 
|  | 4547 | // Copy all of the result registers out of their specified physreg. | 
|  | 4548 | for (unsigned i = 0, e = RVLocs.size(); i != e; ++i) { | 
|  | 4549 | CCValAssign &VA = RVLocs[i]; | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4550 | assert(VA.isRegLoc() && "Can only return in registers!"); | 
| Ulrich Weigand | 339d059 | 2012-11-05 19:39:45 +0000 | [diff] [blame] | 4551 |  | 
|  | 4552 | SDValue Val = DAG.getCopyFromReg(Chain, dl, | 
|  | 4553 | VA.getLocReg(), VA.getLocVT(), InFlag); | 
|  | 4554 | Chain = Val.getValue(1); | 
|  | 4555 | InFlag = Val.getValue(2); | 
|  | 4556 |  | 
|  | 4557 | switch (VA.getLocInfo()) { | 
|  | 4558 | default: llvm_unreachable("Unknown loc info!"); | 
|  | 4559 | case CCValAssign::Full: break; | 
|  | 4560 | case CCValAssign::AExt: | 
|  | 4561 | Val = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), Val); | 
|  | 4562 | break; | 
|  | 4563 | case CCValAssign::ZExt: | 
|  | 4564 | Val = DAG.getNode(ISD::AssertZext, dl, VA.getLocVT(), Val, | 
|  | 4565 | DAG.getValueType(VA.getValVT())); | 
|  | 4566 | Val = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), Val); | 
|  | 4567 | break; | 
|  | 4568 | case CCValAssign::SExt: | 
|  | 4569 | Val = DAG.getNode(ISD::AssertSext, dl, VA.getLocVT(), Val, | 
|  | 4570 | DAG.getValueType(VA.getValVT())); | 
|  | 4571 | Val = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), Val); | 
|  | 4572 | break; | 
|  | 4573 | } | 
|  | 4574 |  | 
|  | 4575 | InVals.push_back(Val); | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4576 | } | 
|  | 4577 |  | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4578 | return Chain; | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4579 | } | 
|  | 4580 |  | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 4581 | SDValue PPCTargetLowering::FinishCall( | 
|  | 4582 | CallingConv::ID CallConv, const SDLoc &dl, bool isTailCall, bool isVarArg, | 
| Eric Christopher | 2454a3b | 2016-07-07 01:08:23 +0000 | [diff] [blame] | 4583 | bool isPatchPoint, bool hasNest, SelectionDAG &DAG, | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 4584 | SmallVector<std::pair<unsigned, SDValue>, 8> &RegsToPass, SDValue InFlag, | 
|  | 4585 | SDValue Chain, SDValue CallSeqStart, SDValue &Callee, int SPDiff, | 
|  | 4586 | unsigned NumBytes, const SmallVectorImpl<ISD::InputArg> &Ins, | 
|  | 4587 | SmallVectorImpl<SDValue> &InVals, ImmutableCallSite *CS) const { | 
| Ulrich Weigand | 8658f17 | 2014-07-20 23:43:15 +0000 | [diff] [blame] | 4588 |  | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4589 | std::vector<EVT> NodeTys; | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4590 | SmallVector<SDValue, 8> Ops; | 
| Hal Finkel | e2ab0f1 | 2015-01-15 21:17:34 +0000 | [diff] [blame] | 4591 | unsigned CallOpc = PrepareCall(DAG, Callee, InFlag, Chain, CallSeqStart, dl, | 
| Eric Christopher | 2454a3b | 2016-07-07 01:08:23 +0000 | [diff] [blame] | 4592 | SPDiff, isTailCall, isPatchPoint, hasNest, | 
| Hal Finkel | 965cea5 | 2015-07-12 00:37:44 +0000 | [diff] [blame] | 4593 | RegsToPass, Ops, NodeTys, CS, Subtarget); | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4594 |  | 
| Hal Finkel | 5ab3780 | 2012-08-28 02:10:27 +0000 | [diff] [blame] | 4595 | // Add implicit use of CR bit 6 for 32-bit SVR4 vararg calls | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 4596 | if (isVarArg && Subtarget.isSVR4ABI() && !Subtarget.isPPC64()) | 
| Hal Finkel | 5ab3780 | 2012-08-28 02:10:27 +0000 | [diff] [blame] | 4597 | Ops.push_back(DAG.getRegister(PPC::CR1EQ, MVT::i32)); | 
|  | 4598 |  | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4599 | // When performing tail call optimization the callee pops its arguments off | 
|  | 4600 | // the stack. Account for this here so these bytes can be pushed back on in | 
| Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 4601 | // PPCFrameLowering::eliminateCallFramePseudoInstr. | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4602 | int BytesCalleePops = | 
| Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 4603 | (CallConv == CallingConv::Fast && | 
|  | 4604 | getTargetMachine().Options.GuaranteedTailCallOpt) ? NumBytes : 0; | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4605 |  | 
| Roman Divacky | ef21be2 | 2012-03-06 16:41:49 +0000 | [diff] [blame] | 4606 | // Add a register mask operand representing the call-preserved registers. | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 4607 | const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo(); | 
| Eric Christopher | 9deb75d | 2015-03-11 22:42:13 +0000 | [diff] [blame] | 4608 | const uint32_t *Mask = | 
|  | 4609 | TRI->getCallPreservedMask(DAG.getMachineFunction(), CallConv); | 
| Roman Divacky | ef21be2 | 2012-03-06 16:41:49 +0000 | [diff] [blame] | 4610 | assert(Mask && "Missing call preserved mask for calling convention"); | 
|  | 4611 | Ops.push_back(DAG.getRegisterMask(Mask)); | 
|  | 4612 |  | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4613 | if (InFlag.getNode()) | 
|  | 4614 | Ops.push_back(InFlag); | 
|  | 4615 |  | 
|  | 4616 | // Emit tail call. | 
|  | 4617 | if (isTailCall) { | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4618 | assert(((Callee.getOpcode() == ISD::Register && | 
|  | 4619 | cast<RegisterSDNode>(Callee)->getReg() == PPC::CTR) || | 
|  | 4620 | Callee.getOpcode() == ISD::TargetExternalSymbol || | 
|  | 4621 | Callee.getOpcode() == ISD::TargetGlobalAddress || | 
|  | 4622 | isa<ConstantSDNode>(Callee)) && | 
|  | 4623 | "Expecting an global address, external symbol, absolute value or register"); | 
|  | 4624 |  | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 4625 | DAG.getMachineFunction().getFrameInfo().setHasTailCall(); | 
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 4626 | return DAG.getNode(PPCISD::TC_RETURN, dl, MVT::Other, Ops); | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4627 | } | 
|  | 4628 |  | 
| Tilmann Scheller | d1aaa32 | 2009-08-15 11:54:46 +0000 | [diff] [blame] | 4629 | // Add a NOP immediately after the branch instruction when using the 64-bit | 
|  | 4630 | // SVR4 ABI. At link time, if caller and callee are in a different module and | 
|  | 4631 | // thus have a different TOC, the call will be replaced with a call to a stub | 
|  | 4632 | // function which saves the current TOC, loads the TOC of the callee and | 
|  | 4633 | // branches to the callee. The NOP will be replaced with a load instruction | 
|  | 4634 | // which restores the TOC of the caller from the TOC save slot of the current | 
|  | 4635 | // stack frame. If caller and callee belong to the same module (and have the | 
|  | 4636 | // same TOC), the NOP will remain unchanged. | 
| Hal Finkel | 51861b4 | 2012-03-31 14:45:15 +0000 | [diff] [blame] | 4637 |  | 
| Hal Finkel | 934361a | 2015-01-14 01:07:51 +0000 | [diff] [blame] | 4638 | if (!isTailCall && Subtarget.isSVR4ABI()&& Subtarget.isPPC64() && | 
| Eric Christopher | 2454a3b | 2016-07-07 01:08:23 +0000 | [diff] [blame] | 4639 | !isPatchPoint) { | 
| Ulrich Weigand | f62e83f | 2013-03-22 15:24:13 +0000 | [diff] [blame] | 4640 | if (CallOpc == PPCISD::BCTRL) { | 
| Tilmann Scheller | 79fef93 | 2009-12-18 13:00:15 +0000 | [diff] [blame] | 4641 | // This is a call through a function pointer. | 
|  | 4642 | // Restore the caller TOC from the save area into R2. | 
|  | 4643 | // See PrepareCall() for more information about calls through function | 
|  | 4644 | // pointers in the 64-bit SVR4 ABI. | 
|  | 4645 | // We are using a target-specific load with r2 hard coded, because the | 
|  | 4646 | // result of a target-independent load would never go directly into r2, | 
|  | 4647 | // since r2 is a reserved register (which prevents the register allocator | 
|  | 4648 | // from allocating it), resulting in an additional register being | 
|  | 4649 | // allocated and an unnecessary move instruction being generated. | 
| Hal Finkel | fc096c9 | 2014-12-23 22:29:40 +0000 | [diff] [blame] | 4650 | CallOpc = PPCISD::BCTRL_LOAD_TOC; | 
|  | 4651 |  | 
| Eric Christopher | cd71946 | 2016-07-07 01:49:59 +0000 | [diff] [blame] | 4652 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); | 
| Hal Finkel | fc096c9 | 2014-12-23 22:29:40 +0000 | [diff] [blame] | 4653 | SDValue StackPtr = DAG.getRegister(PPC::X1, PtrVT); | 
| Eric Christopher | 736d39e | 2015-02-13 00:39:36 +0000 | [diff] [blame] | 4654 | unsigned TOCSaveOffset = Subtarget.getFrameLowering()->getTOCSaveOffset(); | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4655 | SDValue TOCOff = DAG.getIntPtrConstant(TOCSaveOffset, dl); | 
| Hal Finkel | fc096c9 | 2014-12-23 22:29:40 +0000 | [diff] [blame] | 4656 | SDValue AddTOC = DAG.getNode(ISD::ADD, dl, MVT::i64, StackPtr, TOCOff); | 
|  | 4657 |  | 
|  | 4658 | // The address needs to go after the chain input but before the flag (or | 
|  | 4659 | // any other variadic arguments). | 
|  | 4660 | Ops.insert(std::next(Ops.begin()), AddTOC); | 
| Bill Schmidt | cea1596 | 2013-09-26 17:09:28 +0000 | [diff] [blame] | 4661 | } else if ((CallOpc == PPCISD::CALL) && | 
|  | 4662 | (!isLocalCall(Callee) || | 
| Bill Schmidt | 82f1c77 | 2015-02-10 19:09:05 +0000 | [diff] [blame] | 4663 | DAG.getTarget().getRelocationModel() == Reloc::PIC_)) | 
| Roman Divacky | 7629306 | 2012-09-18 16:47:58 +0000 | [diff] [blame] | 4664 | // Otherwise insert NOP for non-local calls. | 
| Ulrich Weigand | f62e83f | 2013-03-22 15:24:13 +0000 | [diff] [blame] | 4665 | CallOpc = PPCISD::CALL_NOP; | 
| Tilmann Scheller | d1aaa32 | 2009-08-15 11:54:46 +0000 | [diff] [blame] | 4666 | } | 
|  | 4667 |  | 
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 4668 | Chain = DAG.getNode(CallOpc, dl, NodeTys, Ops); | 
| Hal Finkel | 51861b4 | 2012-03-31 14:45:15 +0000 | [diff] [blame] | 4669 | InFlag = Chain.getValue(1); | 
|  | 4670 |  | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4671 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, dl, true), | 
|  | 4672 | DAG.getIntPtrConstant(BytesCalleePops, dl, true), | 
| Andrew Trick | ad6d08a | 2013-05-29 22:03:55 +0000 | [diff] [blame] | 4673 | InFlag, dl); | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4674 | if (!Ins.empty()) | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4675 | InFlag = Chain.getValue(1); | 
|  | 4676 |  | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4677 | return LowerCallResult(Chain, InFlag, CallConv, isVarArg, | 
|  | 4678 | Ins, dl, DAG, InVals); | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 4679 | } | 
|  | 4680 |  | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4681 | SDValue | 
| Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 4682 | PPCTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, | 
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 4683 | SmallVectorImpl<SDValue> &InVals) const { | 
| Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 4684 | SelectionDAG &DAG                     = CLI.DAG; | 
| Craig Topper | b94011f | 2013-07-14 04:42:23 +0000 | [diff] [blame] | 4685 | SDLoc &dl                             = CLI.DL; | 
|  | 4686 | SmallVectorImpl<ISD::OutputArg> &Outs = CLI.Outs; | 
|  | 4687 | SmallVectorImpl<SDValue> &OutVals     = CLI.OutVals; | 
|  | 4688 | SmallVectorImpl<ISD::InputArg> &Ins   = CLI.Ins; | 
| Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 4689 | SDValue Chain                         = CLI.Chain; | 
|  | 4690 | SDValue Callee                        = CLI.Callee; | 
|  | 4691 | bool &isTailCall                      = CLI.IsTailCall; | 
|  | 4692 | CallingConv::ID CallConv              = CLI.CallConv; | 
|  | 4693 | bool isVarArg                         = CLI.IsVarArg; | 
| Eric Christopher | 2454a3b | 2016-07-07 01:08:23 +0000 | [diff] [blame] | 4694 | bool isPatchPoint                     = CLI.IsPatchPoint; | 
| Hal Finkel | e2ab0f1 | 2015-01-15 21:17:34 +0000 | [diff] [blame] | 4695 | ImmutableCallSite *CS                 = CLI.CS; | 
| Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 4696 |  | 
| Chuang-Yu Cheng | 2e5973e | 2016-04-06 02:04:38 +0000 | [diff] [blame] | 4697 | if (isTailCall) { | 
| Hal Finkel | b074a60 | 2016-08-30 00:59:23 +0000 | [diff] [blame] | 4698 | if (Subtarget.useLongCalls() && !(CS && CS->isMustTailCall())) | 
|  | 4699 | isTailCall = false; | 
|  | 4700 | else if (Subtarget.isSVR4ABI() && Subtarget.isPPC64()) | 
| Chuang-Yu Cheng | 2e5973e | 2016-04-06 02:04:38 +0000 | [diff] [blame] | 4701 | isTailCall = | 
|  | 4702 | IsEligibleForTailCallOptimization_64SVR4(Callee, CallConv, CS, | 
|  | 4703 | isVarArg, Outs, Ins, DAG); | 
|  | 4704 | else | 
|  | 4705 | isTailCall = IsEligibleForTailCallOptimization(Callee, CallConv, isVarArg, | 
|  | 4706 | Ins, DAG); | 
|  | 4707 | if (isTailCall) { | 
|  | 4708 | ++NumTailCalls; | 
|  | 4709 | if (!getTargetMachine().Options.GuaranteedTailCallOpt) | 
|  | 4710 | ++NumSiblingCalls; | 
|  | 4711 |  | 
|  | 4712 | assert(isa<GlobalAddressSDNode>(Callee) && | 
|  | 4713 | "Callee should be an llvm::Function object."); | 
|  | 4714 | DEBUG( | 
|  | 4715 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Callee)->getGlobal(); | 
|  | 4716 | const unsigned Width = 80 - strlen("TCO caller: ") | 
|  | 4717 | - strlen(", callee linkage: 0, 0"); | 
|  | 4718 | dbgs() << "TCO caller: " | 
|  | 4719 | << left_justify(DAG.getMachineFunction().getName(), Width) | 
|  | 4720 | << ", callee linkage: " | 
|  | 4721 | << GV->getVisibility() << ", " << GV->getLinkage() << "\n" | 
|  | 4722 | ); | 
|  | 4723 | } | 
|  | 4724 | } | 
| Evan Cheng | 67a69dd | 2010-01-27 00:07:07 +0000 | [diff] [blame] | 4725 |  | 
| Hal Finkel | e2ab0f1 | 2015-01-15 21:17:34 +0000 | [diff] [blame] | 4726 | if (!isTailCall && CS && CS->isMustTailCall()) | 
| Reid Kleckner | 5772b77 | 2014-04-24 20:14:34 +0000 | [diff] [blame] | 4727 | report_fatal_error("failed to perform tail call elimination on a call " | 
|  | 4728 | "site marked musttail"); | 
|  | 4729 |  | 
| Hal Finkel | b074a60 | 2016-08-30 00:59:23 +0000 | [diff] [blame] | 4730 | // When long calls (i.e. indirect calls) are always used, calls are always | 
|  | 4731 | // made via function pointer. If we have a function name, first translate it | 
|  | 4732 | // into a pointer. | 
|  | 4733 | if (Subtarget.useLongCalls() && isa<GlobalAddressSDNode>(Callee) && | 
|  | 4734 | !isTailCall) | 
|  | 4735 | Callee = LowerGlobalAddress(Callee, DAG); | 
|  | 4736 |  | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 4737 | if (Subtarget.isSVR4ABI()) { | 
|  | 4738 | if (Subtarget.isPPC64()) | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 4739 | return LowerCall_64SVR4(Chain, Callee, CallConv, isVarArg, | 
| Eric Christopher | 2454a3b | 2016-07-07 01:08:23 +0000 | [diff] [blame] | 4740 | isTailCall, isPatchPoint, Outs, OutVals, Ins, | 
| Hal Finkel | e2ab0f1 | 2015-01-15 21:17:34 +0000 | [diff] [blame] | 4741 | dl, DAG, InVals, CS); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 4742 | else | 
|  | 4743 | return LowerCall_32SVR4(Chain, Callee, CallConv, isVarArg, | 
| Eric Christopher | 2454a3b | 2016-07-07 01:08:23 +0000 | [diff] [blame] | 4744 | isTailCall, isPatchPoint, Outs, OutVals, Ins, | 
| Hal Finkel | e2ab0f1 | 2015-01-15 21:17:34 +0000 | [diff] [blame] | 4745 | dl, DAG, InVals, CS); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 4746 | } | 
| Chris Lattner | df8e17d | 2010-11-14 23:42:06 +0000 | [diff] [blame] | 4747 |  | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 4748 | return LowerCall_Darwin(Chain, Callee, CallConv, isVarArg, | 
| Eric Christopher | 2454a3b | 2016-07-07 01:08:23 +0000 | [diff] [blame] | 4749 | isTailCall, isPatchPoint, Outs, OutVals, Ins, | 
| Hal Finkel | e2ab0f1 | 2015-01-15 21:17:34 +0000 | [diff] [blame] | 4750 | dl, DAG, InVals, CS); | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4751 | } | 
|  | 4752 |  | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 4753 | SDValue PPCTargetLowering::LowerCall_32SVR4( | 
|  | 4754 | SDValue Chain, SDValue Callee, CallingConv::ID CallConv, bool isVarArg, | 
| Eric Christopher | 2454a3b | 2016-07-07 01:08:23 +0000 | [diff] [blame] | 4755 | bool isTailCall, bool isPatchPoint, | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 4756 | const SmallVectorImpl<ISD::OutputArg> &Outs, | 
|  | 4757 | const SmallVectorImpl<SDValue> &OutVals, | 
|  | 4758 | const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl, | 
|  | 4759 | SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals, | 
|  | 4760 | ImmutableCallSite *CS) const { | 
| Bill Schmidt | 019cc6f | 2012-09-19 15:42:13 +0000 | [diff] [blame] | 4761 | // See PPCTargetLowering::LowerFormalArguments_32SVR4() for a description | 
| Tilmann Scheller | d1aaa32 | 2009-08-15 11:54:46 +0000 | [diff] [blame] | 4762 | // of the 32-bit SVR4 ABI stack frame layout. | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4763 |  | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4764 | assert((CallConv == CallingConv::C || | 
|  | 4765 | CallConv == CallingConv::Fast) && "Unknown calling convention!"); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4766 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4767 | unsigned PtrByteSize = 4; | 
|  | 4768 |  | 
|  | 4769 | MachineFunction &MF = DAG.getMachineFunction(); | 
|  | 4770 |  | 
|  | 4771 | // Mark this function as potentially containing a function that contains a | 
|  | 4772 | // tail call. As a consequence the frame pointer will be used for dynamicalloc | 
|  | 4773 | // and restoring the callers stack pointer in this functions epilog. This is | 
|  | 4774 | // done because by tail calling the called function might overwrite the value | 
|  | 4775 | // in this function's (MF) stack pointer stack slot 0(SP). | 
| Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 4776 | if (getTargetMachine().Options.GuaranteedTailCallOpt && | 
|  | 4777 | CallConv == CallingConv::Fast) | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4778 | MF.getInfo<PPCFunctionInfo>()->setHasFastCall(); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4779 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4780 | // Count how many bytes are to be pushed on the stack, including the linkage | 
|  | 4781 | // area, parameter list area and the part of the local variable space which | 
|  | 4782 | // contains copies of aggregates which are passed by value. | 
|  | 4783 |  | 
|  | 4784 | // Assign locations to all of the outgoing arguments. | 
|  | 4785 | SmallVector<CCValAssign, 16> ArgLocs; | 
| Eric Christopher | 606a268 | 2016-07-07 01:08:19 +0000 | [diff] [blame] | 4786 | PPCCCState CCInfo(CallConv, isVarArg, MF, ArgLocs, *DAG.getContext()); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4787 |  | 
|  | 4788 | // Reserve space for the linkage area on the stack. | 
| Eric Christopher | a4ae213 | 2015-02-13 22:22:57 +0000 | [diff] [blame] | 4789 | CCInfo.AllocateStack(Subtarget.getFrameLowering()->getLinkageSize(), | 
| Ulrich Weigand | 8658f17 | 2014-07-20 23:43:15 +0000 | [diff] [blame] | 4790 | PtrByteSize); | 
| Eric Christopher | 317df66 | 2016-07-07 01:49:57 +0000 | [diff] [blame] | 4791 | if (useSoftFloat()) | 
| Strahinja Petrovic | e682b80 | 2016-05-09 12:27:39 +0000 | [diff] [blame] | 4792 | CCInfo.PreAnalyzeCallOperands(Outs); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4793 |  | 
|  | 4794 | if (isVarArg) { | 
|  | 4795 | // Handle fixed and variable vector arguments differently. | 
|  | 4796 | // Fixed vector arguments go into registers as long as registers are | 
|  | 4797 | // available. Variable vector arguments always go into memory. | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4798 | unsigned NumArgs = Outs.size(); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4799 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4800 | for (unsigned i = 0; i != NumArgs; ++i) { | 
| Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 4801 | MVT ArgVT = Outs[i].VT; | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4802 | ISD::ArgFlagsTy ArgFlags = Outs[i].Flags; | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4803 | bool Result; | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4804 |  | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4805 | if (Outs[i].IsFixed) { | 
| Bill Schmidt | ef17c14 | 2013-02-06 17:33:58 +0000 | [diff] [blame] | 4806 | Result = CC_PPC32_SVR4(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, | 
|  | 4807 | CCInfo); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4808 | } else { | 
| Bill Schmidt | ef17c14 | 2013-02-06 17:33:58 +0000 | [diff] [blame] | 4809 | Result = CC_PPC32_SVR4_VarArg(i, ArgVT, ArgVT, CCValAssign::Full, | 
|  | 4810 | ArgFlags, CCInfo); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4811 | } | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4812 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4813 | if (Result) { | 
| Torok Edwin | fb8d6d5 | 2009-07-08 20:53:28 +0000 | [diff] [blame] | 4814 | #ifndef NDEBUG | 
| Chris Lattner | 1362602 | 2009-08-23 06:03:38 +0000 | [diff] [blame] | 4815 | errs() << "Call operand #" << i << " has unhandled type " | 
| Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 4816 | << EVT(ArgVT).getEVTString() << "\n"; | 
| Torok Edwin | fb8d6d5 | 2009-07-08 20:53:28 +0000 | [diff] [blame] | 4817 | #endif | 
| Craig Topper | e73658d | 2014-04-28 04:05:08 +0000 | [diff] [blame] | 4818 | llvm_unreachable(nullptr); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4819 | } | 
|  | 4820 | } | 
|  | 4821 | } else { | 
|  | 4822 | // All arguments are treated the same. | 
| Bill Schmidt | ef17c14 | 2013-02-06 17:33:58 +0000 | [diff] [blame] | 4823 | CCInfo.AnalyzeCallOperands(Outs, CC_PPC32_SVR4); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4824 | } | 
| Strahinja Petrovic | e682b80 | 2016-05-09 12:27:39 +0000 | [diff] [blame] | 4825 | CCInfo.clearWasPPCF128(); | 
| NAKAMURA Takumi | fd92154 | 2016-06-20 01:05:15 +0000 | [diff] [blame] | 4826 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4827 | // Assign locations to all of the outgoing aggregate by value arguments. | 
|  | 4828 | SmallVector<CCValAssign, 16> ByValArgLocs; | 
| Eric Christopher | 606a268 | 2016-07-07 01:08:19 +0000 | [diff] [blame] | 4829 | CCState CCByValInfo(CallConv, isVarArg, MF, ByValArgLocs, *DAG.getContext()); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4830 |  | 
|  | 4831 | // Reserve stack space for the allocations in CCInfo. | 
|  | 4832 | CCByValInfo.AllocateStack(CCInfo.getNextStackOffset(), PtrByteSize); | 
|  | 4833 |  | 
| Bill Schmidt | ef17c14 | 2013-02-06 17:33:58 +0000 | [diff] [blame] | 4834 | CCByValInfo.AnalyzeCallOperands(Outs, CC_PPC32_SVR4_ByVal); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4835 |  | 
|  | 4836 | // Size of the linkage area, parameter list area and the part of the local | 
|  | 4837 | // space variable where copies of aggregates which are passed by value are | 
|  | 4838 | // stored. | 
|  | 4839 | unsigned NumBytes = CCByValInfo.getNextStackOffset(); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4840 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4841 | // Calculate by how many bytes the stack has to be adjusted in case of tail | 
|  | 4842 | // call optimization. | 
|  | 4843 | int SPDiff = CalculateTailCallSPDiff(DAG, isTailCall, NumBytes); | 
|  | 4844 |  | 
|  | 4845 | // Adjust the stack pointer for the new arguments... | 
|  | 4846 | // These operations are automatically eliminated by the prolog/epilog pass | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4847 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, dl, true), | 
| Andrew Trick | ad6d08a | 2013-05-29 22:03:55 +0000 | [diff] [blame] | 4848 | dl); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4849 | SDValue CallSeqStart = Chain; | 
|  | 4850 |  | 
|  | 4851 | // Load the return address and frame pointer so it can be moved somewhere else | 
|  | 4852 | // later. | 
|  | 4853 | SDValue LROp, FPOp; | 
| Eric Christopher | e0d09ba | 2016-07-07 01:08:21 +0000 | [diff] [blame] | 4854 | Chain = EmitTailCallLoadFPAndRetAddr(DAG, SPDiff, Chain, LROp, FPOp, dl); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4855 |  | 
|  | 4856 | // Set up a copy of the stack pointer for use loading and storing any | 
|  | 4857 | // arguments that may not fit in the registers available for argument | 
|  | 4858 | // passing. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4859 | SDValue StackPtr = DAG.getRegister(PPC::R1, MVT::i32); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4860 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4861 | SmallVector<std::pair<unsigned, SDValue>, 8> RegsToPass; | 
|  | 4862 | SmallVector<TailCallArgumentInfo, 8> TailCallArguments; | 
|  | 4863 | SmallVector<SDValue, 8> MemOpChains; | 
|  | 4864 |  | 
| Roman Divacky | 71038e7 | 2011-08-30 17:04:16 +0000 | [diff] [blame] | 4865 | bool seenFloatArg = false; | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4866 | // Walk the register/memloc assignments, inserting copies/loads. | 
|  | 4867 | for (unsigned i = 0, j = 0, e = ArgLocs.size(); | 
|  | 4868 | i != e; | 
|  | 4869 | ++i) { | 
|  | 4870 | CCValAssign &VA = ArgLocs[i]; | 
| Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 4871 | SDValue Arg = OutVals[i]; | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4872 | ISD::ArgFlagsTy Flags = Outs[i].Flags; | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4873 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4874 | if (Flags.isByVal()) { | 
|  | 4875 | // Argument is an aggregate which is passed by value, thus we need to | 
|  | 4876 | // create a copy of it in the local variable space of the current stack | 
|  | 4877 | // frame (which is the stack frame of the caller) and pass the address of | 
|  | 4878 | // this copy to the callee. | 
|  | 4879 | assert((j < ByValArgLocs.size()) && "Index out of bounds!"); | 
|  | 4880 | CCValAssign &ByValVA = ByValArgLocs[j++]; | 
|  | 4881 | assert((VA.getValNo() == ByValVA.getValNo()) && "ValNo mismatch!"); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4882 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4883 | // Memory reserved in the local variable space of the callers stack frame. | 
|  | 4884 | unsigned LocMemOffset = ByValVA.getLocMemOffset(); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4885 |  | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4886 | SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset, dl); | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 4887 | PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(MF.getDataLayout()), | 
|  | 4888 | StackPtr, PtrOff); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4889 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4890 | // Create a copy of the argument in the local area of the current | 
|  | 4891 | // stack frame. | 
|  | 4892 | SDValue MemcpyCall = | 
|  | 4893 | CreateCopyOfByValArgument(Arg, PtrOff, | 
|  | 4894 | CallSeqStart.getNode()->getOperand(0), | 
|  | 4895 | Flags, DAG, dl); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4896 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4897 | // This must go outside the CALLSEQ_START..END. | 
|  | 4898 | SDValue NewCallSeqStart = DAG.getCALLSEQ_START(MemcpyCall, | 
| Andrew Trick | ad6d08a | 2013-05-29 22:03:55 +0000 | [diff] [blame] | 4899 | CallSeqStart.getNode()->getOperand(1), | 
|  | 4900 | SDLoc(MemcpyCall)); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4901 | DAG.ReplaceAllUsesWith(CallSeqStart.getNode(), | 
|  | 4902 | NewCallSeqStart.getNode()); | 
|  | 4903 | Chain = CallSeqStart = NewCallSeqStart; | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4904 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4905 | // Pass the address of the aggregate copy on the stack either in a | 
|  | 4906 | // physical register or in the parameter list area of the current stack | 
|  | 4907 | // frame to the callee. | 
|  | 4908 | Arg = PtrOff; | 
|  | 4909 | } | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4910 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4911 | if (VA.isRegLoc()) { | 
| Hal Finkel | 2a9d318 | 2014-03-06 00:23:33 +0000 | [diff] [blame] | 4912 | if (Arg.getValueType() == MVT::i1) | 
|  | 4913 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i32, Arg); | 
|  | 4914 |  | 
| Roman Divacky | 71038e7 | 2011-08-30 17:04:16 +0000 | [diff] [blame] | 4915 | seenFloatArg |= VA.getLocVT().isFloatingPoint(); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4916 | // Put argument in a physical register. | 
|  | 4917 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); | 
|  | 4918 | } else { | 
|  | 4919 | // Put argument in the parameter list area of the current stack frame. | 
|  | 4920 | assert(VA.isMemLoc()); | 
|  | 4921 | unsigned LocMemOffset = VA.getLocMemOffset(); | 
|  | 4922 |  | 
|  | 4923 | if (!isTailCall) { | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4924 | SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset, dl); | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 4925 | PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(MF.getDataLayout()), | 
|  | 4926 | StackPtr, PtrOff); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4927 |  | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 4928 | MemOpChains.push_back( | 
|  | 4929 | DAG.getStore(Chain, dl, Arg, PtrOff, MachinePointerInfo())); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4930 | } else { | 
|  | 4931 | // Calculate and remember argument location. | 
|  | 4932 | CalculateTailCallArgDest(DAG, MF, false, Arg, SPDiff, LocMemOffset, | 
|  | 4933 | TailCallArguments); | 
|  | 4934 | } | 
|  | 4935 | } | 
|  | 4936 | } | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4937 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4938 | if (!MemOpChains.empty()) | 
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 4939 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4940 |  | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4941 | // Build a sequence of copy-to-reg nodes chained together with token chain | 
|  | 4942 | // and flag operands which copy the outgoing args into the appropriate regs. | 
|  | 4943 | SDValue InFlag; | 
|  | 4944 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { | 
|  | 4945 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, | 
|  | 4946 | RegsToPass[i].second, InFlag); | 
|  | 4947 | InFlag = Chain.getValue(1); | 
|  | 4948 | } | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4949 |  | 
| Hal Finkel | 5ab3780 | 2012-08-28 02:10:27 +0000 | [diff] [blame] | 4950 | // Set CR bit 6 to true if this is a vararg call with floating args passed in | 
|  | 4951 | // registers. | 
|  | 4952 | if (isVarArg) { | 
| NAKAMURA Takumi | ac49029 | 2012-08-30 15:52:29 +0000 | [diff] [blame] | 4953 | SDVTList VTs = DAG.getVTList(MVT::Other, MVT::Glue); | 
|  | 4954 | SDValue Ops[] = { Chain, InFlag }; | 
|  | 4955 |  | 
| Hal Finkel | 5ab3780 | 2012-08-28 02:10:27 +0000 | [diff] [blame] | 4956 | Chain = DAG.getNode(seenFloatArg ? PPCISD::CR6SET : PPCISD::CR6UNSET, | 
| Craig Topper | 2d2aa0c | 2014-04-30 07:17:30 +0000 | [diff] [blame] | 4957 | dl, VTs, makeArrayRef(Ops, InFlag.getNode() ? 2 : 1)); | 
| NAKAMURA Takumi | ac49029 | 2012-08-30 15:52:29 +0000 | [diff] [blame] | 4958 |  | 
| Hal Finkel | 5ab3780 | 2012-08-28 02:10:27 +0000 | [diff] [blame] | 4959 | InFlag = Chain.getValue(1); | 
|  | 4960 | } | 
|  | 4961 |  | 
| Chris Lattner | df8e17d | 2010-11-14 23:42:06 +0000 | [diff] [blame] | 4962 | if (isTailCall) | 
| Eric Christopher | 327e440 | 2016-07-07 01:08:17 +0000 | [diff] [blame] | 4963 | PrepareTailCall(DAG, InFlag, Chain, dl, SPDiff, NumBytes, LROp, FPOp, | 
| Eric Christopher | ade4eed | 2016-07-07 00:39:32 +0000 | [diff] [blame] | 4964 | TailCallArguments); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4965 |  | 
| Eric Christopher | 2454a3b | 2016-07-07 01:08:23 +0000 | [diff] [blame] | 4966 | return FinishCall(CallConv, dl, isTailCall, isVarArg, isPatchPoint, | 
| Hal Finkel | 965cea5 | 2015-07-12 00:37:44 +0000 | [diff] [blame] | 4967 | /* unused except on PPC64 ELFv1 */ false, DAG, | 
| Hal Finkel | e2ab0f1 | 2015-01-15 21:17:34 +0000 | [diff] [blame] | 4968 | RegsToPass, InFlag, Chain, CallSeqStart, Callee, SPDiff, | 
|  | 4969 | NumBytes, Ins, InVals, CS); | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 4970 | } | 
|  | 4971 |  | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 4972 | // Copy an argument into memory, being careful to do this outside the | 
|  | 4973 | // call sequence for the call to which the argument belongs. | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 4974 | SDValue PPCTargetLowering::createMemcpyOutsideCallSeq( | 
|  | 4975 | SDValue Arg, SDValue PtrOff, SDValue CallSeqStart, ISD::ArgFlagsTy Flags, | 
|  | 4976 | SelectionDAG &DAG, const SDLoc &dl) const { | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 4977 | SDValue MemcpyCall = CreateCopyOfByValArgument(Arg, PtrOff, | 
|  | 4978 | CallSeqStart.getNode()->getOperand(0), | 
|  | 4979 | Flags, DAG, dl); | 
|  | 4980 | // The MEMCPY must go outside the CALLSEQ_START..END. | 
|  | 4981 | SDValue NewCallSeqStart = DAG.getCALLSEQ_START(MemcpyCall, | 
| Andrew Trick | ad6d08a | 2013-05-29 22:03:55 +0000 | [diff] [blame] | 4982 | CallSeqStart.getNode()->getOperand(1), | 
|  | 4983 | SDLoc(MemcpyCall)); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 4984 | DAG.ReplaceAllUsesWith(CallSeqStart.getNode(), | 
|  | 4985 | NewCallSeqStart.getNode()); | 
|  | 4986 | return NewCallSeqStart; | 
|  | 4987 | } | 
|  | 4988 |  | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 4989 | SDValue PPCTargetLowering::LowerCall_64SVR4( | 
|  | 4990 | SDValue Chain, SDValue Callee, CallingConv::ID CallConv, bool isVarArg, | 
| Eric Christopher | 2454a3b | 2016-07-07 01:08:23 +0000 | [diff] [blame] | 4991 | bool isTailCall, bool isPatchPoint, | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 4992 | const SmallVectorImpl<ISD::OutputArg> &Outs, | 
|  | 4993 | const SmallVectorImpl<SDValue> &OutVals, | 
|  | 4994 | const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl, | 
|  | 4995 | SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals, | 
|  | 4996 | ImmutableCallSite *CS) const { | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 4997 |  | 
| Ulrich Weigand | aa0ac4f | 2014-07-20 23:31:44 +0000 | [diff] [blame] | 4998 | bool isELFv2ABI = Subtarget.isELFv2ABI(); | 
| Ulrich Weigand | 59c6ab2 | 2014-06-20 16:34:05 +0000 | [diff] [blame] | 4999 | bool isLittleEndian = Subtarget.isLittleEndian(); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5000 | unsigned NumOps = Outs.size(); | 
| Hal Finkel | 965cea5 | 2015-07-12 00:37:44 +0000 | [diff] [blame] | 5001 | bool hasNest = false; | 
| Chuang-Yu Cheng | 2e5973e | 2016-04-06 02:04:38 +0000 | [diff] [blame] | 5002 | bool IsSibCall = false; | 
| Bill Schmidt | 019cc6f | 2012-09-19 15:42:13 +0000 | [diff] [blame] | 5003 |  | 
| Eric Christopher | cd71946 | 2016-07-07 01:49:59 +0000 | [diff] [blame] | 5004 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5005 | unsigned PtrByteSize = 8; | 
|  | 5006 |  | 
|  | 5007 | MachineFunction &MF = DAG.getMachineFunction(); | 
|  | 5008 |  | 
| Chuang-Yu Cheng | 2e5973e | 2016-04-06 02:04:38 +0000 | [diff] [blame] | 5009 | if (isTailCall && !getTargetMachine().Options.GuaranteedTailCallOpt) | 
|  | 5010 | IsSibCall = true; | 
|  | 5011 |  | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5012 | // Mark this function as potentially containing a function that contains a | 
|  | 5013 | // tail call. As a consequence the frame pointer will be used for dynamicalloc | 
|  | 5014 | // and restoring the callers stack pointer in this functions epilog. This is | 
|  | 5015 | // done because by tail calling the called function might overwrite the value | 
|  | 5016 | // in this function's (MF) stack pointer stack slot 0(SP). | 
|  | 5017 | if (getTargetMachine().Options.GuaranteedTailCallOpt && | 
|  | 5018 | CallConv == CallingConv::Fast) | 
|  | 5019 | MF.getInfo<PPCFunctionInfo>()->setHasFastCall(); | 
|  | 5020 |  | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5021 | assert(!(CallConv == CallingConv::Fast && isVarArg) && | 
|  | 5022 | "fastcc not supported on varargs functions"); | 
|  | 5023 |  | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5024 | // Count how many bytes are to be pushed on the stack, including the linkage | 
| Ulrich Weigand | 8658f17 | 2014-07-20 23:43:15 +0000 | [diff] [blame] | 5025 | // area, and parameter passing area.  On ELFv1, the linkage area is 48 bytes | 
|  | 5026 | // reserved space for [SP][CR][LR][2 x unused][TOC]; on ELFv2, the linkage | 
|  | 5027 | // area is 32 bytes reserved space for [SP][CR][LR][TOC]. | 
| Eric Christopher | a4ae213 | 2015-02-13 22:22:57 +0000 | [diff] [blame] | 5028 | unsigned LinkageSize = Subtarget.getFrameLowering()->getLinkageSize(); | 
| Ulrich Weigand | 8ca988f | 2014-06-23 14:15:53 +0000 | [diff] [blame] | 5029 | unsigned NumBytes = LinkageSize; | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5030 | unsigned GPR_idx = 0, FPR_idx = 0, VR_idx = 0; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 5031 | unsigned &QFPR_idx = FPR_idx; | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5032 |  | 
|  | 5033 | static const MCPhysReg GPR[] = { | 
|  | 5034 | PPC::X3, PPC::X4, PPC::X5, PPC::X6, | 
|  | 5035 | PPC::X7, PPC::X8, PPC::X9, PPC::X10, | 
|  | 5036 | }; | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5037 | static const MCPhysReg VR[] = { | 
|  | 5038 | PPC::V2, PPC::V3, PPC::V4, PPC::V5, PPC::V6, PPC::V7, PPC::V8, | 
|  | 5039 | PPC::V9, PPC::V10, PPC::V11, PPC::V12, PPC::V13 | 
|  | 5040 | }; | 
|  | 5041 | static const MCPhysReg VSRH[] = { | 
|  | 5042 | PPC::VSH2, PPC::VSH3, PPC::VSH4, PPC::VSH5, PPC::VSH6, PPC::VSH7, PPC::VSH8, | 
|  | 5043 | PPC::VSH9, PPC::VSH10, PPC::VSH11, PPC::VSH12, PPC::VSH13 | 
|  | 5044 | }; | 
|  | 5045 |  | 
|  | 5046 | const unsigned NumGPRs = array_lengthof(GPR); | 
|  | 5047 | const unsigned NumFPRs = 13; | 
|  | 5048 | const unsigned NumVRs  = array_lengthof(VR); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 5049 | const unsigned NumQFPRs = NumFPRs; | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5050 |  | 
|  | 5051 | // When using the fast calling convention, we don't provide backing for | 
|  | 5052 | // arguments that will be in registers. | 
|  | 5053 | unsigned NumGPRsUsed = 0, NumFPRsUsed = 0, NumVRsUsed = 0; | 
| Ulrich Weigand | 2bffb95 | 2014-06-23 13:08:27 +0000 | [diff] [blame] | 5054 |  | 
|  | 5055 | // Add up all the space actually used. | 
|  | 5056 | for (unsigned i = 0; i != NumOps; ++i) { | 
|  | 5057 | ISD::ArgFlagsTy Flags = Outs[i].Flags; | 
|  | 5058 | EVT ArgVT = Outs[i].VT; | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 5059 | EVT OrigVT = Outs[i].ArgVT; | 
| Ulrich Weigand | 2bffb95 | 2014-06-23 13:08:27 +0000 | [diff] [blame] | 5060 |  | 
| Hal Finkel | 965cea5 | 2015-07-12 00:37:44 +0000 | [diff] [blame] | 5061 | if (Flags.isNest()) | 
|  | 5062 | continue; | 
|  | 5063 |  | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5064 | if (CallConv == CallingConv::Fast) { | 
|  | 5065 | if (Flags.isByVal()) | 
|  | 5066 | NumGPRsUsed += (Flags.getByValSize()+7)/8; | 
|  | 5067 | else | 
|  | 5068 | switch (ArgVT.getSimpleVT().SimpleTy) { | 
|  | 5069 | default: llvm_unreachable("Unexpected ValueType for argument!"); | 
|  | 5070 | case MVT::i1: | 
|  | 5071 | case MVT::i32: | 
|  | 5072 | case MVT::i64: | 
|  | 5073 | if (++NumGPRsUsed <= NumGPRs) | 
|  | 5074 | continue; | 
|  | 5075 | break; | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5076 | case MVT::v4i32: | 
|  | 5077 | case MVT::v8i16: | 
|  | 5078 | case MVT::v16i8: | 
|  | 5079 | case MVT::v2f64: | 
|  | 5080 | case MVT::v2i64: | 
| Kit Barton | d4eb73c | 2015-05-05 16:10:44 +0000 | [diff] [blame] | 5081 | case MVT::v1i128: | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5082 | if (++NumVRsUsed <= NumVRs) | 
|  | 5083 | continue; | 
|  | 5084 | break; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 5085 | case MVT::v4f32: | 
| NAKAMURA Takumi | 8496503 | 2015-09-22 11:14:12 +0000 | [diff] [blame] | 5086 | // When using QPX, this is handled like a FP register, otherwise, it | 
|  | 5087 | // is an Altivec register. | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 5088 | if (Subtarget.hasQPX()) { | 
|  | 5089 | if (++NumFPRsUsed <= NumFPRs) | 
|  | 5090 | continue; | 
|  | 5091 | } else { | 
|  | 5092 | if (++NumVRsUsed <= NumVRs) | 
|  | 5093 | continue; | 
|  | 5094 | } | 
|  | 5095 | break; | 
|  | 5096 | case MVT::f32: | 
|  | 5097 | case MVT::f64: | 
|  | 5098 | case MVT::v4f64: // QPX | 
|  | 5099 | case MVT::v4i1:  // QPX | 
|  | 5100 | if (++NumFPRsUsed <= NumFPRs) | 
|  | 5101 | continue; | 
|  | 5102 | break; | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5103 | } | 
|  | 5104 | } | 
|  | 5105 |  | 
| Ulrich Weigand | ec2bf93 | 2014-07-07 19:26:41 +0000 | [diff] [blame] | 5106 | /* Respect alignment of argument on the stack.  */ | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 5107 | unsigned Align = | 
|  | 5108 | CalculateStackSlotAlignment(ArgVT, OrigVT, Flags, PtrByteSize); | 
| Ulrich Weigand | ec2bf93 | 2014-07-07 19:26:41 +0000 | [diff] [blame] | 5109 | NumBytes = ((NumBytes + Align - 1) / Align) * Align; | 
| Ulrich Weigand | 2bffb95 | 2014-06-23 13:08:27 +0000 | [diff] [blame] | 5110 |  | 
|  | 5111 | NumBytes += CalculateStackSlotSize(ArgVT, Flags, PtrByteSize); | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 5112 | if (Flags.isInConsecutiveRegsLast()) | 
|  | 5113 | NumBytes = ((NumBytes + PtrByteSize - 1)/PtrByteSize) * PtrByteSize; | 
| Ulrich Weigand | 2bffb95 | 2014-06-23 13:08:27 +0000 | [diff] [blame] | 5114 | } | 
|  | 5115 |  | 
| Ulrich Weigand | ec2bf93 | 2014-07-07 19:26:41 +0000 | [diff] [blame] | 5116 | unsigned NumBytesActuallyUsed = NumBytes; | 
|  | 5117 |  | 
| Ulrich Weigand | 2bffb95 | 2014-06-23 13:08:27 +0000 | [diff] [blame] | 5118 | // The prolog code of the callee may store up to 8 GPR argument registers to | 
|  | 5119 | // the stack, allowing va_start to index over them in memory if its varargs. | 
|  | 5120 | // Because we cannot tell if this is needed on the caller side, we have to | 
|  | 5121 | // conservatively assume that it is needed.  As such, make sure we have at | 
|  | 5122 | // least enough stack space for the caller to store the 8 GPRs. | 
| Ulrich Weigand | 8658f17 | 2014-07-20 23:43:15 +0000 | [diff] [blame] | 5123 | // FIXME: On ELFv2, it may be unnecessary to allocate the parameter area. | 
| Ulrich Weigand | 8ca988f | 2014-06-23 14:15:53 +0000 | [diff] [blame] | 5124 | NumBytes = std::max(NumBytes, LinkageSize + 8 * PtrByteSize); | 
| Ulrich Weigand | 2bffb95 | 2014-06-23 13:08:27 +0000 | [diff] [blame] | 5125 |  | 
|  | 5126 | // Tail call needs the stack to be aligned. | 
|  | 5127 | if (getTargetMachine().Options.GuaranteedTailCallOpt && | 
|  | 5128 | CallConv == CallingConv::Fast) | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 5129 | NumBytes = EnsureStackAlignment(Subtarget.getFrameLowering(), NumBytes); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5130 |  | 
| Chuang-Yu Cheng | 2e5973e | 2016-04-06 02:04:38 +0000 | [diff] [blame] | 5131 | int SPDiff = 0; | 
|  | 5132 |  | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5133 | // Calculate by how many bytes the stack has to be adjusted in case of tail | 
|  | 5134 | // call optimization. | 
| Chuang-Yu Cheng | 2e5973e | 2016-04-06 02:04:38 +0000 | [diff] [blame] | 5135 | if (!IsSibCall) | 
|  | 5136 | SPDiff = CalculateTailCallSPDiff(DAG, isTailCall, NumBytes); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5137 |  | 
|  | 5138 | // To protect arguments on the stack from being clobbered in a tail call, | 
|  | 5139 | // force all the loads to happen before doing any other lowering. | 
|  | 5140 | if (isTailCall) | 
|  | 5141 | Chain = DAG.getStackArgumentTokenFactor(Chain); | 
|  | 5142 |  | 
|  | 5143 | // Adjust the stack pointer for the new arguments... | 
|  | 5144 | // These operations are automatically eliminated by the prolog/epilog pass | 
| Chuang-Yu Cheng | 2e5973e | 2016-04-06 02:04:38 +0000 | [diff] [blame] | 5145 | if (!IsSibCall) | 
|  | 5146 | Chain = DAG.getCALLSEQ_START(Chain, | 
|  | 5147 | DAG.getIntPtrConstant(NumBytes, dl, true), dl); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5148 | SDValue CallSeqStart = Chain; | 
|  | 5149 |  | 
|  | 5150 | // Load the return address and frame pointer so it can be move somewhere else | 
|  | 5151 | // later. | 
|  | 5152 | SDValue LROp, FPOp; | 
| Eric Christopher | e0d09ba | 2016-07-07 01:08:21 +0000 | [diff] [blame] | 5153 | Chain = EmitTailCallLoadFPAndRetAddr(DAG, SPDiff, Chain, LROp, FPOp, dl); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5154 |  | 
|  | 5155 | // Set up a copy of the stack pointer for use loading and storing any | 
|  | 5156 | // arguments that may not fit in the registers available for argument | 
|  | 5157 | // passing. | 
|  | 5158 | SDValue StackPtr = DAG.getRegister(PPC::X1, MVT::i64); | 
|  | 5159 |  | 
|  | 5160 | // Figure out which arguments are going to go in registers, and which in | 
|  | 5161 | // memory.  Also, if this is a vararg function, floating point operations | 
|  | 5162 | // must be stored to our stack, and loaded into integer regs as well, if | 
|  | 5163 | // any integer regs are available for argument passing. | 
| Ulrich Weigand | 8ca988f | 2014-06-23 14:15:53 +0000 | [diff] [blame] | 5164 | unsigned ArgOffset = LinkageSize; | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5165 |  | 
|  | 5166 | SmallVector<std::pair<unsigned, SDValue>, 8> RegsToPass; | 
|  | 5167 | SmallVector<TailCallArgumentInfo, 8> TailCallArguments; | 
|  | 5168 |  | 
|  | 5169 | SmallVector<SDValue, 8> MemOpChains; | 
|  | 5170 | for (unsigned i = 0; i != NumOps; ++i) { | 
|  | 5171 | SDValue Arg = OutVals[i]; | 
|  | 5172 | ISD::ArgFlagsTy Flags = Outs[i].Flags; | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 5173 | EVT ArgVT = Outs[i].VT; | 
|  | 5174 | EVT OrigVT = Outs[i].ArgVT; | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5175 |  | 
|  | 5176 | // PtrOff will be used to store the current argument to the stack if a | 
|  | 5177 | // register cannot be found for it. | 
|  | 5178 | SDValue PtrOff; | 
|  | 5179 |  | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5180 | // We re-align the argument offset for each argument, except when using the | 
|  | 5181 | // fast calling convention, when we need to make sure we do that only when | 
|  | 5182 | // we'll actually use a stack slot. | 
|  | 5183 | auto ComputePtrOff = [&]() { | 
|  | 5184 | /* Respect alignment of argument on the stack.  */ | 
|  | 5185 | unsigned Align = | 
|  | 5186 | CalculateStackSlotAlignment(ArgVT, OrigVT, Flags, PtrByteSize); | 
|  | 5187 | ArgOffset = ((ArgOffset + Align - 1) / Align) * Align; | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5188 |  | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5189 | PtrOff = DAG.getConstant(ArgOffset, dl, StackPtr.getValueType()); | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5190 |  | 
|  | 5191 | PtrOff = DAG.getNode(ISD::ADD, dl, PtrVT, StackPtr, PtrOff); | 
|  | 5192 | }; | 
|  | 5193 |  | 
|  | 5194 | if (CallConv != CallingConv::Fast) { | 
|  | 5195 | ComputePtrOff(); | 
|  | 5196 |  | 
|  | 5197 | /* Compute GPR index associated with argument offset.  */ | 
|  | 5198 | GPR_idx = (ArgOffset - LinkageSize) / PtrByteSize; | 
|  | 5199 | GPR_idx = std::min(GPR_idx, NumGPRs); | 
|  | 5200 | } | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5201 |  | 
|  | 5202 | // Promote integers to 64-bit values. | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 5203 | if (Arg.getValueType() == MVT::i32 || Arg.getValueType() == MVT::i1) { | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5204 | // FIXME: Should this use ANY_EXTEND if neither sext nor zext? | 
|  | 5205 | unsigned ExtOp = Flags.isSExt() ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND; | 
|  | 5206 | Arg = DAG.getNode(ExtOp, dl, MVT::i64, Arg); | 
|  | 5207 | } | 
|  | 5208 |  | 
|  | 5209 | // FIXME memcpy is used way more than necessary.  Correctness first. | 
|  | 5210 | // Note: "by value" is code for passing a structure by value, not | 
|  | 5211 | // basic types. | 
|  | 5212 | if (Flags.isByVal()) { | 
|  | 5213 | // Note: Size includes alignment padding, so | 
|  | 5214 | //   struct x { short a; char b; } | 
|  | 5215 | // will have Size = 4.  With #pragma pack(1), it will have Size = 3. | 
|  | 5216 | // These are the proper values we need for right-justifying the | 
|  | 5217 | // aggregate in a parameter register. | 
|  | 5218 | unsigned Size = Flags.getByValSize(); | 
| Bill Schmidt | 9953cf2 | 2012-10-31 01:15:05 +0000 | [diff] [blame] | 5219 |  | 
|  | 5220 | // An empty aggregate parameter takes up no storage and no | 
|  | 5221 | // registers. | 
|  | 5222 | if (Size == 0) | 
|  | 5223 | continue; | 
|  | 5224 |  | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5225 | if (CallConv == CallingConv::Fast) | 
|  | 5226 | ComputePtrOff(); | 
|  | 5227 |  | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5228 | // All aggregates smaller than 8 bytes must be passed right-justified. | 
|  | 5229 | if (Size==1 || Size==2 || Size==4) { | 
|  | 5230 | EVT VT = (Size==1) ? MVT::i8 : ((Size==2) ? MVT::i16 : MVT::i32); | 
|  | 5231 | if (GPR_idx != NumGPRs) { | 
|  | 5232 | SDValue Load = DAG.getExtLoad(ISD::EXTLOAD, dl, PtrVT, Chain, Arg, | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 5233 | MachinePointerInfo(), VT); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5234 | MemOpChains.push_back(Load.getValue(1)); | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5235 | RegsToPass.push_back(std::make_pair(GPR[GPR_idx++], Load)); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5236 |  | 
|  | 5237 | ArgOffset += PtrByteSize; | 
|  | 5238 | continue; | 
|  | 5239 | } | 
|  | 5240 | } | 
|  | 5241 |  | 
|  | 5242 | if (GPR_idx == NumGPRs && Size < 8) { | 
| Ulrich Weigand | 59c6ab2 | 2014-06-20 16:34:05 +0000 | [diff] [blame] | 5243 | SDValue AddPtr = PtrOff; | 
|  | 5244 | if (!isLittleEndian) { | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5245 | SDValue Const = DAG.getConstant(PtrByteSize - Size, dl, | 
| Ulrich Weigand | 59c6ab2 | 2014-06-20 16:34:05 +0000 | [diff] [blame] | 5246 | PtrOff.getValueType()); | 
|  | 5247 | AddPtr = DAG.getNode(ISD::ADD, dl, PtrVT, PtrOff, Const); | 
|  | 5248 | } | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5249 | Chain = CallSeqStart = createMemcpyOutsideCallSeq(Arg, AddPtr, | 
|  | 5250 | CallSeqStart, | 
|  | 5251 | Flags, DAG, dl); | 
|  | 5252 | ArgOffset += PtrByteSize; | 
|  | 5253 | continue; | 
|  | 5254 | } | 
|  | 5255 | // Copy entire object into memory.  There are cases where gcc-generated | 
|  | 5256 | // code assumes it is there, even if it could be put entirely into | 
|  | 5257 | // registers.  (This is not what the doc says.) | 
|  | 5258 |  | 
|  | 5259 | // FIXME: The above statement is likely due to a misunderstanding of the | 
|  | 5260 | // documents.  All arguments must be copied into the parameter area BY | 
|  | 5261 | // THE CALLEE in the event that the callee takes the address of any | 
|  | 5262 | // formal argument.  That has not yet been implemented.  However, it is | 
|  | 5263 | // reasonable to use the stack area as a staging area for the register | 
|  | 5264 | // load. | 
|  | 5265 |  | 
|  | 5266 | // Skip this for small aggregates, as we will use the same slot for a | 
|  | 5267 | // right-justified copy, below. | 
|  | 5268 | if (Size >= 8) | 
|  | 5269 | Chain = CallSeqStart = createMemcpyOutsideCallSeq(Arg, PtrOff, | 
|  | 5270 | CallSeqStart, | 
|  | 5271 | Flags, DAG, dl); | 
|  | 5272 |  | 
|  | 5273 | // When a register is available, pass a small aggregate right-justified. | 
|  | 5274 | if (Size < 8 && GPR_idx != NumGPRs) { | 
|  | 5275 | // The easiest way to get this right-justified in a register | 
|  | 5276 | // is to copy the structure into the rightmost portion of a | 
|  | 5277 | // local variable slot, then load the whole slot into the | 
|  | 5278 | // register. | 
|  | 5279 | // FIXME: The memcpy seems to produce pretty awful code for | 
|  | 5280 | // small aggregates, particularly for packed ones. | 
| Matt Arsenault | 75865923 | 2013-05-18 00:21:46 +0000 | [diff] [blame] | 5281 | // FIXME: It would be preferable to use the slot in the | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5282 | // parameter save area instead of a new local variable. | 
| Ulrich Weigand | 59c6ab2 | 2014-06-20 16:34:05 +0000 | [diff] [blame] | 5283 | SDValue AddPtr = PtrOff; | 
|  | 5284 | if (!isLittleEndian) { | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5285 | SDValue Const = DAG.getConstant(8 - Size, dl, PtrOff.getValueType()); | 
| Ulrich Weigand | 59c6ab2 | 2014-06-20 16:34:05 +0000 | [diff] [blame] | 5286 | AddPtr = DAG.getNode(ISD::ADD, dl, PtrVT, PtrOff, Const); | 
|  | 5287 | } | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5288 | Chain = CallSeqStart = createMemcpyOutsideCallSeq(Arg, AddPtr, | 
|  | 5289 | CallSeqStart, | 
|  | 5290 | Flags, DAG, dl); | 
|  | 5291 |  | 
|  | 5292 | // Load the slot into the register. | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 5293 | SDValue Load = | 
|  | 5294 | DAG.getLoad(PtrVT, dl, Chain, PtrOff, MachinePointerInfo()); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5295 | MemOpChains.push_back(Load.getValue(1)); | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5296 | RegsToPass.push_back(std::make_pair(GPR[GPR_idx++], Load)); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5297 |  | 
|  | 5298 | // Done with this argument. | 
|  | 5299 | ArgOffset += PtrByteSize; | 
|  | 5300 | continue; | 
|  | 5301 | } | 
|  | 5302 |  | 
|  | 5303 | // For aggregates larger than PtrByteSize, copy the pieces of the | 
|  | 5304 | // object that fit into registers from the parameter save area. | 
|  | 5305 | for (unsigned j=0; j<Size; j+=PtrByteSize) { | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5306 | SDValue Const = DAG.getConstant(j, dl, PtrOff.getValueType()); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5307 | SDValue AddArg = DAG.getNode(ISD::ADD, dl, PtrVT, Arg, Const); | 
|  | 5308 | if (GPR_idx != NumGPRs) { | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 5309 | SDValue Load = | 
|  | 5310 | DAG.getLoad(PtrVT, dl, Chain, AddArg, MachinePointerInfo()); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5311 | MemOpChains.push_back(Load.getValue(1)); | 
|  | 5312 | RegsToPass.push_back(std::make_pair(GPR[GPR_idx++], Load)); | 
|  | 5313 | ArgOffset += PtrByteSize; | 
|  | 5314 | } else { | 
|  | 5315 | ArgOffset += ((Size - j + PtrByteSize-1)/PtrByteSize)*PtrByteSize; | 
|  | 5316 | break; | 
|  | 5317 | } | 
|  | 5318 | } | 
|  | 5319 | continue; | 
|  | 5320 | } | 
|  | 5321 |  | 
| Craig Topper | 5671010 | 2013-08-15 02:33:50 +0000 | [diff] [blame] | 5322 | switch (Arg.getSimpleValueType().SimpleTy) { | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5323 | default: llvm_unreachable("Unexpected ValueType for argument!"); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 5324 | case MVT::i1: | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5325 | case MVT::i32: | 
|  | 5326 | case MVT::i64: | 
| Hal Finkel | 965cea5 | 2015-07-12 00:37:44 +0000 | [diff] [blame] | 5327 | if (Flags.isNest()) { | 
|  | 5328 | // The 'nest' parameter, if any, is passed in R11. | 
|  | 5329 | RegsToPass.push_back(std::make_pair(PPC::X11, Arg)); | 
|  | 5330 | hasNest = true; | 
|  | 5331 | break; | 
|  | 5332 | } | 
|  | 5333 |  | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 5334 | // These can be scalar arguments or elements of an integer array type | 
|  | 5335 | // passed directly.  Clang may use those instead of "byval" aggregate | 
|  | 5336 | // types to avoid forcing arguments to memory unnecessarily. | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5337 | if (GPR_idx != NumGPRs) { | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5338 | RegsToPass.push_back(std::make_pair(GPR[GPR_idx++], Arg)); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5339 | } else { | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5340 | if (CallConv == CallingConv::Fast) | 
|  | 5341 | ComputePtrOff(); | 
|  | 5342 |  | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5343 | LowerMemOpCallTo(DAG, MF, Chain, Arg, PtrOff, SPDiff, ArgOffset, | 
|  | 5344 | true, isTailCall, false, MemOpChains, | 
|  | 5345 | TailCallArguments, dl); | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5346 | if (CallConv == CallingConv::Fast) | 
|  | 5347 | ArgOffset += PtrByteSize; | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5348 | } | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5349 | if (CallConv != CallingConv::Fast) | 
|  | 5350 | ArgOffset += PtrByteSize; | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5351 | break; | 
|  | 5352 | case MVT::f32: | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 5353 | case MVT::f64: { | 
|  | 5354 | // These can be scalar arguments or elements of a float array type | 
|  | 5355 | // passed directly.  The latter are used to implement ELFv2 homogenous | 
|  | 5356 | // float aggregates. | 
|  | 5357 |  | 
|  | 5358 | // Named arguments go into FPRs first, and once they overflow, the | 
|  | 5359 | // remaining arguments go into GPRs and then the parameter save area. | 
|  | 5360 | // Unnamed arguments for vararg functions always go to GPRs and | 
|  | 5361 | // then the parameter save area.  For now, put all arguments to vararg | 
|  | 5362 | // routines always in both locations (FPR *and* GPR or stack slot). | 
|  | 5363 | bool NeedGPROrStack = isVarArg || FPR_idx == NumFPRs; | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5364 | bool NeededLoad = false; | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 5365 |  | 
|  | 5366 | // First load the argument into the next available FPR. | 
|  | 5367 | if (FPR_idx != NumFPRs) | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5368 | RegsToPass.push_back(std::make_pair(FPR[FPR_idx++], Arg)); | 
|  | 5369 |  | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 5370 | // Next, load the argument into GPR or stack slot if needed. | 
|  | 5371 | if (!NeedGPROrStack) | 
|  | 5372 | ; | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5373 | else if (GPR_idx != NumGPRs && CallConv != CallingConv::Fast) { | 
| Hal Finkel | 8ea446b | 2015-01-18 14:31:10 +0000 | [diff] [blame] | 5374 | // FIXME: We may want to re-enable this for CallingConv::Fast on the P8 | 
|  | 5375 | // once we support fp <-> gpr moves. | 
|  | 5376 |  | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 5377 | // In the non-vararg case, this can only ever happen in the | 
|  | 5378 | // presence of f32 array types, since otherwise we never run | 
|  | 5379 | // out of FPRs before running out of GPRs. | 
|  | 5380 | SDValue ArgVal; | 
| Bill Schmidt | bd4ac26 | 2012-10-29 21:18:16 +0000 | [diff] [blame] | 5381 |  | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 5382 | // Double values are always passed in a single GPR. | 
|  | 5383 | if (Arg.getValueType() != MVT::f32) { | 
|  | 5384 | ArgVal = DAG.getNode(ISD::BITCAST, dl, MVT::i64, Arg); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5385 |  | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 5386 | // Non-array float values are extended and passed in a GPR. | 
|  | 5387 | } else if (!Flags.isInConsecutiveRegs()) { | 
|  | 5388 | ArgVal = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Arg); | 
|  | 5389 | ArgVal = DAG.getNode(ISD::ANY_EXTEND, dl, MVT::i64, ArgVal); | 
|  | 5390 |  | 
|  | 5391 | // If we have an array of floats, we collect every odd element | 
|  | 5392 | // together with its predecessor into one GPR. | 
|  | 5393 | } else if (ArgOffset % PtrByteSize != 0) { | 
|  | 5394 | SDValue Lo, Hi; | 
|  | 5395 | Lo = DAG.getNode(ISD::BITCAST, dl, MVT::i32, OutVals[i - 1]); | 
|  | 5396 | Hi = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Arg); | 
|  | 5397 | if (!isLittleEndian) | 
|  | 5398 | std::swap(Lo, Hi); | 
|  | 5399 | ArgVal = DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi); | 
|  | 5400 |  | 
|  | 5401 | // The final element, if even, goes into the first half of a GPR. | 
|  | 5402 | } else if (Flags.isInConsecutiveRegsLast()) { | 
|  | 5403 | ArgVal = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Arg); | 
|  | 5404 | ArgVal = DAG.getNode(ISD::ANY_EXTEND, dl, MVT::i64, ArgVal); | 
|  | 5405 | if (!isLittleEndian) | 
|  | 5406 | ArgVal = DAG.getNode(ISD::SHL, dl, MVT::i64, ArgVal, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5407 | DAG.getConstant(32, dl, MVT::i32)); | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 5408 |  | 
|  | 5409 | // Non-final even elements are skipped; they will be handled | 
|  | 5410 | // together the with subsequent argument on the next go-around. | 
|  | 5411 | } else | 
|  | 5412 | ArgVal = SDValue(); | 
|  | 5413 |  | 
|  | 5414 | if (ArgVal.getNode()) | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5415 | RegsToPass.push_back(std::make_pair(GPR[GPR_idx++], ArgVal)); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5416 | } else { | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5417 | if (CallConv == CallingConv::Fast) | 
|  | 5418 | ComputePtrOff(); | 
|  | 5419 |  | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5420 | // Single-precision floating-point values are mapped to the | 
|  | 5421 | // second (rightmost) word of the stack doubleword. | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 5422 | if (Arg.getValueType() == MVT::f32 && | 
|  | 5423 | !isLittleEndian && !Flags.isInConsecutiveRegs()) { | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5424 | SDValue ConstFour = DAG.getConstant(4, dl, PtrOff.getValueType()); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5425 | PtrOff = DAG.getNode(ISD::ADD, dl, PtrVT, PtrOff, ConstFour); | 
|  | 5426 | } | 
|  | 5427 |  | 
|  | 5428 | LowerMemOpCallTo(DAG, MF, Chain, Arg, PtrOff, SPDiff, ArgOffset, | 
|  | 5429 | true, isTailCall, false, MemOpChains, | 
|  | 5430 | TailCallArguments, dl); | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5431 |  | 
|  | 5432 | NeededLoad = true; | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5433 | } | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 5434 | // When passing an array of floats, the array occupies consecutive | 
|  | 5435 | // space in the argument area; only round up to the next doubleword | 
|  | 5436 | // at the end of the array.  Otherwise, each float takes 8 bytes. | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5437 | if (CallConv != CallingConv::Fast || NeededLoad) { | 
|  | 5438 | ArgOffset += (Arg.getValueType() == MVT::f32 && | 
|  | 5439 | Flags.isInConsecutiveRegs()) ? 4 : 8; | 
|  | 5440 | if (Flags.isInConsecutiveRegsLast()) | 
|  | 5441 | ArgOffset = ((ArgOffset + PtrByteSize - 1)/PtrByteSize) * PtrByteSize; | 
|  | 5442 | } | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5443 | break; | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 5444 | } | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5445 | case MVT::v4f32: | 
|  | 5446 | case MVT::v4i32: | 
|  | 5447 | case MVT::v8i16: | 
|  | 5448 | case MVT::v16i8: | 
| Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 5449 | case MVT::v2f64: | 
| Hal Finkel | a6c8b51 | 2014-03-26 16:12:58 +0000 | [diff] [blame] | 5450 | case MVT::v2i64: | 
| Kit Barton | d4eb73c | 2015-05-05 16:10:44 +0000 | [diff] [blame] | 5451 | case MVT::v1i128: | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 5452 | if (!Subtarget.hasQPX()) { | 
| Ulrich Weigand | 85d5df2 | 2014-07-21 00:13:26 +0000 | [diff] [blame] | 5453 | // These can be scalar arguments or elements of a vector array type | 
|  | 5454 | // passed directly.  The latter are used to implement ELFv2 homogenous | 
|  | 5455 | // vector aggregates. | 
|  | 5456 |  | 
| Ulrich Weigand | 9ba552d | 2014-06-23 12:36:34 +0000 | [diff] [blame] | 5457 | // For a varargs call, named arguments go into VRs or on the stack as | 
|  | 5458 | // usual; unnamed arguments always go to the stack or the corresponding | 
|  | 5459 | // GPRs when within range.  For now, we always put the value in both | 
|  | 5460 | // locations (or even all three). | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5461 | if (isVarArg) { | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5462 | // We could elide this store in the case where the object fits | 
|  | 5463 | // entirely in R registers.  Maybe later. | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 5464 | SDValue Store = | 
|  | 5465 | DAG.getStore(Chain, dl, Arg, PtrOff, MachinePointerInfo()); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5466 | MemOpChains.push_back(Store); | 
|  | 5467 | if (VR_idx != NumVRs) { | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 5468 | SDValue Load = | 
|  | 5469 | DAG.getLoad(MVT::v4f32, dl, Store, PtrOff, MachinePointerInfo()); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5470 | MemOpChains.push_back(Load.getValue(1)); | 
| Hal Finkel | 7811c61 | 2014-03-28 19:58:11 +0000 | [diff] [blame] | 5471 |  | 
|  | 5472 | unsigned VReg = (Arg.getSimpleValueType() == MVT::v2f64 || | 
|  | 5473 | Arg.getSimpleValueType() == MVT::v2i64) ? | 
|  | 5474 | VSRH[VR_idx] : VR[VR_idx]; | 
|  | 5475 | ++VR_idx; | 
|  | 5476 |  | 
|  | 5477 | RegsToPass.push_back(std::make_pair(VReg, Load)); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5478 | } | 
|  | 5479 | ArgOffset += 16; | 
|  | 5480 | for (unsigned i=0; i<16; i+=PtrByteSize) { | 
|  | 5481 | if (GPR_idx == NumGPRs) | 
|  | 5482 | break; | 
|  | 5483 | SDValue Ix = DAG.getNode(ISD::ADD, dl, PtrVT, PtrOff, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5484 | DAG.getConstant(i, dl, PtrVT)); | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 5485 | SDValue Load = | 
|  | 5486 | DAG.getLoad(PtrVT, dl, Store, Ix, MachinePointerInfo()); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5487 | MemOpChains.push_back(Load.getValue(1)); | 
|  | 5488 | RegsToPass.push_back(std::make_pair(GPR[GPR_idx++], Load)); | 
|  | 5489 | } | 
|  | 5490 | break; | 
|  | 5491 | } | 
|  | 5492 |  | 
| Ulrich Weigand | 9ba552d | 2014-06-23 12:36:34 +0000 | [diff] [blame] | 5493 | // Non-varargs Altivec params go into VRs or on the stack. | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5494 | if (VR_idx != NumVRs) { | 
| Hal Finkel | 7811c61 | 2014-03-28 19:58:11 +0000 | [diff] [blame] | 5495 | unsigned VReg = (Arg.getSimpleValueType() == MVT::v2f64 || | 
|  | 5496 | Arg.getSimpleValueType() == MVT::v2i64) ? | 
|  | 5497 | VSRH[VR_idx] : VR[VR_idx]; | 
|  | 5498 | ++VR_idx; | 
|  | 5499 |  | 
|  | 5500 | RegsToPass.push_back(std::make_pair(VReg, Arg)); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5501 | } else { | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5502 | if (CallConv == CallingConv::Fast) | 
|  | 5503 | ComputePtrOff(); | 
|  | 5504 |  | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5505 | LowerMemOpCallTo(DAG, MF, Chain, Arg, PtrOff, SPDiff, ArgOffset, | 
|  | 5506 | true, isTailCall, true, MemOpChains, | 
|  | 5507 | TailCallArguments, dl); | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5508 | if (CallConv == CallingConv::Fast) | 
|  | 5509 | ArgOffset += 16; | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5510 | } | 
| Hal Finkel | f81b6dd | 2015-01-18 12:08:47 +0000 | [diff] [blame] | 5511 |  | 
|  | 5512 | if (CallConv != CallingConv::Fast) | 
|  | 5513 | ArgOffset += 16; | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5514 | break; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 5515 | } // not QPX | 
|  | 5516 |  | 
|  | 5517 | assert(Arg.getValueType().getSimpleVT().SimpleTy == MVT::v4f32 && | 
|  | 5518 | "Invalid QPX parameter type"); | 
|  | 5519 |  | 
|  | 5520 | /* fall through */ | 
|  | 5521 | case MVT::v4f64: | 
|  | 5522 | case MVT::v4i1: { | 
|  | 5523 | bool IsF32 = Arg.getValueType().getSimpleVT().SimpleTy == MVT::v4f32; | 
|  | 5524 | if (isVarArg) { | 
|  | 5525 | // We could elide this store in the case where the object fits | 
|  | 5526 | // entirely in R registers.  Maybe later. | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 5527 | SDValue Store = | 
|  | 5528 | DAG.getStore(Chain, dl, Arg, PtrOff, MachinePointerInfo()); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 5529 | MemOpChains.push_back(Store); | 
|  | 5530 | if (QFPR_idx != NumQFPRs) { | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 5531 | SDValue Load = DAG.getLoad(IsF32 ? MVT::v4f32 : MVT::v4f64, dl, Store, | 
|  | 5532 | PtrOff, MachinePointerInfo()); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 5533 | MemOpChains.push_back(Load.getValue(1)); | 
|  | 5534 | RegsToPass.push_back(std::make_pair(QFPR[QFPR_idx++], Load)); | 
|  | 5535 | } | 
|  | 5536 | ArgOffset += (IsF32 ? 16 : 32); | 
| Aaron Ballman | 70c27de | 2015-02-25 13:02:23 +0000 | [diff] [blame] | 5537 | for (unsigned i = 0; i < (IsF32 ? 16U : 32U); i += PtrByteSize) { | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 5538 | if (GPR_idx == NumGPRs) | 
|  | 5539 | break; | 
|  | 5540 | SDValue Ix = DAG.getNode(ISD::ADD, dl, PtrVT, PtrOff, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5541 | DAG.getConstant(i, dl, PtrVT)); | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 5542 | SDValue Load = | 
|  | 5543 | DAG.getLoad(PtrVT, dl, Store, Ix, MachinePointerInfo()); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 5544 | MemOpChains.push_back(Load.getValue(1)); | 
|  | 5545 | RegsToPass.push_back(std::make_pair(GPR[GPR_idx++], Load)); | 
|  | 5546 | } | 
|  | 5547 | break; | 
|  | 5548 | } | 
|  | 5549 |  | 
|  | 5550 | // Non-varargs QPX params go into registers or on the stack. | 
|  | 5551 | if (QFPR_idx != NumQFPRs) { | 
|  | 5552 | RegsToPass.push_back(std::make_pair(QFPR[QFPR_idx++], Arg)); | 
|  | 5553 | } else { | 
|  | 5554 | if (CallConv == CallingConv::Fast) | 
|  | 5555 | ComputePtrOff(); | 
|  | 5556 |  | 
|  | 5557 | LowerMemOpCallTo(DAG, MF, Chain, Arg, PtrOff, SPDiff, ArgOffset, | 
|  | 5558 | true, isTailCall, true, MemOpChains, | 
|  | 5559 | TailCallArguments, dl); | 
|  | 5560 | if (CallConv == CallingConv::Fast) | 
|  | 5561 | ArgOffset += (IsF32 ? 16 : 32); | 
|  | 5562 | } | 
|  | 5563 |  | 
|  | 5564 | if (CallConv != CallingConv::Fast) | 
|  | 5565 | ArgOffset += (IsF32 ? 16 : 32); | 
|  | 5566 | break; | 
|  | 5567 | } | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5568 | } | 
|  | 5569 | } | 
|  | 5570 |  | 
| Ulrich Weigand | ec2bf93 | 2014-07-07 19:26:41 +0000 | [diff] [blame] | 5571 | assert(NumBytesActuallyUsed == ArgOffset); | 
| Ulrich Weigand | de8641b | 2014-07-07 19:39:44 +0000 | [diff] [blame] | 5572 | (void)NumBytesActuallyUsed; | 
| Ulrich Weigand | ec2bf93 | 2014-07-07 19:26:41 +0000 | [diff] [blame] | 5573 |  | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5574 | if (!MemOpChains.empty()) | 
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 5575 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5576 |  | 
|  | 5577 | // Check if this is an indirect call (MTCTR/BCTRL). | 
|  | 5578 | // See PrepareCall() for more information about calls through function | 
|  | 5579 | // pointers in the 64-bit SVR4 ABI. | 
| Eric Christopher | 2454a3b | 2016-07-07 01:08:23 +0000 | [diff] [blame] | 5580 | if (!isTailCall && !isPatchPoint && | 
| Hal Finkel | 87deb0b | 2015-01-12 04:34:47 +0000 | [diff] [blame] | 5581 | !isFunctionGlobalAddress(Callee) && | 
|  | 5582 | !isa<ExternalSymbolSDNode>(Callee)) { | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5583 | // Load r2 into a virtual register and store it to the TOC save area. | 
| Hal Finkel | e6698d5 | 2015-02-01 15:03:28 +0000 | [diff] [blame] | 5584 | setUsesTOCBasePtr(DAG); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5585 | SDValue Val = DAG.getCopyFromReg(Chain, dl, PPC::X2, MVT::i64); | 
|  | 5586 | // TOC save area offset. | 
| Eric Christopher | 736d39e | 2015-02-13 00:39:36 +0000 | [diff] [blame] | 5587 | unsigned TOCSaveOffset = Subtarget.getFrameLowering()->getTOCSaveOffset(); | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5588 | SDValue PtrOff = DAG.getIntPtrConstant(TOCSaveOffset, dl); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5589 | SDValue AddPtr = DAG.getNode(ISD::ADD, dl, PtrVT, StackPtr, PtrOff); | 
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 5590 | Chain = DAG.getStore( | 
|  | 5591 | Val.getValue(1), dl, Val, AddPtr, | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 5592 | MachinePointerInfo::getStack(DAG.getMachineFunction(), TOCSaveOffset)); | 
| Ulrich Weigand | aa0ac4f | 2014-07-20 23:31:44 +0000 | [diff] [blame] | 5593 | // In the ELFv2 ABI, R12 must contain the address of an indirect callee. | 
|  | 5594 | // This does not mean the MTCTR instruction must use R12; it's easier | 
|  | 5595 | // to model this as an extra parameter, so do that. | 
| Eric Christopher | 2454a3b | 2016-07-07 01:08:23 +0000 | [diff] [blame] | 5596 | if (isELFv2ABI && !isPatchPoint) | 
| Ulrich Weigand | aa0ac4f | 2014-07-20 23:31:44 +0000 | [diff] [blame] | 5597 | RegsToPass.push_back(std::make_pair((unsigned)PPC::X12, Callee)); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5598 | } | 
|  | 5599 |  | 
|  | 5600 | // Build a sequence of copy-to-reg nodes chained together with token chain | 
|  | 5601 | // and flag operands which copy the outgoing args into the appropriate regs. | 
|  | 5602 | SDValue InFlag; | 
|  | 5603 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { | 
|  | 5604 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, | 
|  | 5605 | RegsToPass[i].second, InFlag); | 
|  | 5606 | InFlag = Chain.getValue(1); | 
|  | 5607 | } | 
|  | 5608 |  | 
| Chuang-Yu Cheng | 2e5973e | 2016-04-06 02:04:38 +0000 | [diff] [blame] | 5609 | if (isTailCall && !IsSibCall) | 
| Eric Christopher | 327e440 | 2016-07-07 01:08:17 +0000 | [diff] [blame] | 5610 | PrepareTailCall(DAG, InFlag, Chain, dl, SPDiff, NumBytes, LROp, FPOp, | 
| Eric Christopher | ade4eed | 2016-07-07 00:39:32 +0000 | [diff] [blame] | 5611 | TailCallArguments); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5612 |  | 
| Eric Christopher | 2454a3b | 2016-07-07 01:08:23 +0000 | [diff] [blame] | 5613 | return FinishCall(CallConv, dl, isTailCall, isVarArg, isPatchPoint, hasNest, | 
| NAKAMURA Takumi | 0a7d0ad | 2015-09-22 11:15:07 +0000 | [diff] [blame] | 5614 | DAG, RegsToPass, InFlag, Chain, CallSeqStart, Callee, | 
|  | 5615 | SPDiff, NumBytes, Ins, InVals, CS); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5616 | } | 
|  | 5617 |  | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 5618 | SDValue PPCTargetLowering::LowerCall_Darwin( | 
|  | 5619 | SDValue Chain, SDValue Callee, CallingConv::ID CallConv, bool isVarArg, | 
| Eric Christopher | 2454a3b | 2016-07-07 01:08:23 +0000 | [diff] [blame] | 5620 | bool isTailCall, bool isPatchPoint, | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 5621 | const SmallVectorImpl<ISD::OutputArg> &Outs, | 
|  | 5622 | const SmallVectorImpl<SDValue> &OutVals, | 
|  | 5623 | const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl, | 
|  | 5624 | SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals, | 
|  | 5625 | ImmutableCallSite *CS) const { | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5626 |  | 
|  | 5627 | unsigned NumOps = Outs.size(); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5628 |  | 
| Eric Christopher | cd71946 | 2016-07-07 01:49:59 +0000 | [diff] [blame] | 5629 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5630 | bool isPPC64 = PtrVT == MVT::i64; | 
| Chris Lattner | ec78cad | 2006-06-26 22:48:35 +0000 | [diff] [blame] | 5631 | unsigned PtrByteSize = isPPC64 ? 8 : 4; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5632 |  | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 5633 | MachineFunction &MF = DAG.getMachineFunction(); | 
|  | 5634 |  | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 5635 | // Mark this function as potentially containing a function that contains a | 
|  | 5636 | // tail call. As a consequence the frame pointer will be used for dynamicalloc | 
|  | 5637 | // and restoring the callers stack pointer in this functions epilog. This is | 
|  | 5638 | // done because by tail calling the called function might overwrite the value | 
|  | 5639 | // in this function's (MF) stack pointer stack slot 0(SP). | 
| Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 5640 | if (getTargetMachine().Options.GuaranteedTailCallOpt && | 
|  | 5641 | CallConv == CallingConv::Fast) | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 5642 | MF.getInfo<PPCFunctionInfo>()->setHasFastCall(); | 
|  | 5643 |  | 
| Chris Lattner | aa40ec1 | 2006-05-16 22:56:08 +0000 | [diff] [blame] | 5644 | // Count how many bytes are to be pushed on the stack, including the linkage | 
| Chris Lattner | ec78cad | 2006-06-26 22:48:35 +0000 | [diff] [blame] | 5645 | // area, and parameter passing area.  We start with 24/48 bytes, which is | 
| Chris Lattner | b7552a8 | 2006-05-17 00:15:40 +0000 | [diff] [blame] | 5646 | // prereserved space for [SP][CR][LR][3 x unused]. | 
| Eric Christopher | a4ae213 | 2015-02-13 22:22:57 +0000 | [diff] [blame] | 5647 | unsigned LinkageSize = Subtarget.getFrameLowering()->getLinkageSize(); | 
| Ulrich Weigand | 8ca988f | 2014-06-23 14:15:53 +0000 | [diff] [blame] | 5648 | unsigned NumBytes = LinkageSize; | 
| Ulrich Weigand | 2bffb95 | 2014-06-23 13:08:27 +0000 | [diff] [blame] | 5649 |  | 
|  | 5650 | // Add up all the space actually used. | 
|  | 5651 | // In 32-bit non-varargs calls, Altivec parameters all go at the end; usually | 
|  | 5652 | // they all go in registers, but we must reserve stack space for them for | 
|  | 5653 | // possible use by the caller.  In varargs or 64-bit calls, parameters are | 
|  | 5654 | // assigned stack space in order, with padding so Altivec parameters are | 
|  | 5655 | // 16-byte aligned. | 
|  | 5656 | unsigned nAltivecParamsAtEnd = 0; | 
|  | 5657 | for (unsigned i = 0; i != NumOps; ++i) { | 
|  | 5658 | ISD::ArgFlagsTy Flags = Outs[i].Flags; | 
|  | 5659 | EVT ArgVT = Outs[i].VT; | 
|  | 5660 | // Varargs Altivec parameters are padded to a 16 byte boundary. | 
|  | 5661 | if (ArgVT == MVT::v4f32 || ArgVT == MVT::v4i32 || | 
|  | 5662 | ArgVT == MVT::v8i16 || ArgVT == MVT::v16i8 || | 
|  | 5663 | ArgVT == MVT::v2f64 || ArgVT == MVT::v2i64) { | 
|  | 5664 | if (!isVarArg && !isPPC64) { | 
|  | 5665 | // Non-varargs Altivec parameters go after all the non-Altivec | 
|  | 5666 | // parameters; handle those later so we know how much padding we need. | 
|  | 5667 | nAltivecParamsAtEnd++; | 
|  | 5668 | continue; | 
|  | 5669 | } | 
|  | 5670 | // Varargs and 64-bit Altivec parameters are padded to 16 byte boundary. | 
|  | 5671 | NumBytes = ((NumBytes+15)/16)*16; | 
|  | 5672 | } | 
|  | 5673 | NumBytes += CalculateStackSlotSize(ArgVT, Flags, PtrByteSize); | 
|  | 5674 | } | 
|  | 5675 |  | 
|  | 5676 | // Allow for Altivec parameters at the end, if needed. | 
|  | 5677 | if (nAltivecParamsAtEnd) { | 
|  | 5678 | NumBytes = ((NumBytes+15)/16)*16; | 
|  | 5679 | NumBytes += 16*nAltivecParamsAtEnd; | 
|  | 5680 | } | 
|  | 5681 |  | 
|  | 5682 | // The prolog code of the callee may store up to 8 GPR argument registers to | 
|  | 5683 | // the stack, allowing va_start to index over them in memory if its varargs. | 
|  | 5684 | // Because we cannot tell if this is needed on the caller side, we have to | 
|  | 5685 | // conservatively assume that it is needed.  As such, make sure we have at | 
|  | 5686 | // least enough stack space for the caller to store the 8 GPRs. | 
| Ulrich Weigand | 8ca988f | 2014-06-23 14:15:53 +0000 | [diff] [blame] | 5687 | NumBytes = std::max(NumBytes, LinkageSize + 8 * PtrByteSize); | 
| Ulrich Weigand | 2bffb95 | 2014-06-23 13:08:27 +0000 | [diff] [blame] | 5688 |  | 
|  | 5689 | // Tail call needs the stack to be aligned. | 
|  | 5690 | if (getTargetMachine().Options.GuaranteedTailCallOpt && | 
|  | 5691 | CallConv == CallingConv::Fast) | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 5692 | NumBytes = EnsureStackAlignment(Subtarget.getFrameLowering(), NumBytes); | 
| Dale Johannesen | b28456e | 2008-03-12 00:22:17 +0000 | [diff] [blame] | 5693 |  | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 5694 | // Calculate by how many bytes the stack has to be adjusted in case of tail | 
|  | 5695 | // call optimization. | 
|  | 5696 | int SPDiff = CalculateTailCallSPDiff(DAG, isTailCall, NumBytes); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5697 |  | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 5698 | // To protect arguments on the stack from being clobbered in a tail call, | 
|  | 5699 | // force all the loads to happen before doing any other lowering. | 
|  | 5700 | if (isTailCall) | 
|  | 5701 | Chain = DAG.getStackArgumentTokenFactor(Chain); | 
|  | 5702 |  | 
| Chris Lattner | b7552a8 | 2006-05-17 00:15:40 +0000 | [diff] [blame] | 5703 | // Adjust the stack pointer for the new arguments... | 
|  | 5704 | // These operations are automatically eliminated by the prolog/epilog pass | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5705 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, dl, true), | 
| Andrew Trick | ad6d08a | 2013-05-29 22:03:55 +0000 | [diff] [blame] | 5706 | dl); | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5707 | SDValue CallSeqStart = Chain; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5708 |  | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 5709 | // Load the return address and frame pointer so it can be move somewhere else | 
|  | 5710 | // later. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5711 | SDValue LROp, FPOp; | 
| Eric Christopher | e0d09ba | 2016-07-07 01:08:21 +0000 | [diff] [blame] | 5712 | Chain = EmitTailCallLoadFPAndRetAddr(DAG, SPDiff, Chain, LROp, FPOp, dl); | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 5713 |  | 
| Chris Lattner | b7552a8 | 2006-05-17 00:15:40 +0000 | [diff] [blame] | 5714 | // Set up a copy of the stack pointer for use loading and storing any | 
|  | 5715 | // arguments that may not fit in the registers available for argument | 
|  | 5716 | // passing. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5717 | SDValue StackPtr; | 
| Chris Lattner | ec78cad | 2006-06-26 22:48:35 +0000 | [diff] [blame] | 5718 | if (isPPC64) | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5719 | StackPtr = DAG.getRegister(PPC::X1, MVT::i64); | 
| Chris Lattner | ec78cad | 2006-06-26 22:48:35 +0000 | [diff] [blame] | 5720 | else | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5721 | StackPtr = DAG.getRegister(PPC::R1, MVT::i32); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5722 |  | 
| Chris Lattner | b7552a8 | 2006-05-17 00:15:40 +0000 | [diff] [blame] | 5723 | // Figure out which arguments are going to go in registers, and which in | 
|  | 5724 | // memory.  Also, if this is a vararg function, floating point operations | 
|  | 5725 | // must be stored to our stack, and loaded into integer regs as well, if | 
|  | 5726 | // any integer regs are available for argument passing. | 
| Ulrich Weigand | 8ca988f | 2014-06-23 14:15:53 +0000 | [diff] [blame] | 5727 | unsigned ArgOffset = LinkageSize; | 
| Chris Lattner | b1e9e37 | 2006-05-17 06:01:33 +0000 | [diff] [blame] | 5728 | unsigned GPR_idx = 0, FPR_idx = 0, VR_idx = 0; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5729 |  | 
| Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 5730 | static const MCPhysReg GPR_32[] = {           // 32-bit registers. | 
| Chris Lattner | b1e9e37 | 2006-05-17 06:01:33 +0000 | [diff] [blame] | 5731 | PPC::R3, PPC::R4, PPC::R5, PPC::R6, | 
|  | 5732 | PPC::R7, PPC::R8, PPC::R9, PPC::R10, | 
|  | 5733 | }; | 
| Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 5734 | static const MCPhysReg GPR_64[] = {           // 64-bit registers. | 
| Chris Lattner | ec78cad | 2006-06-26 22:48:35 +0000 | [diff] [blame] | 5735 | PPC::X3, PPC::X4, PPC::X5, PPC::X6, | 
|  | 5736 | PPC::X7, PPC::X8, PPC::X9, PPC::X10, | 
|  | 5737 | }; | 
| Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 5738 | static const MCPhysReg VR[] = { | 
| Chris Lattner | b1e9e37 | 2006-05-17 06:01:33 +0000 | [diff] [blame] | 5739 | PPC::V2, PPC::V3, PPC::V4, PPC::V5, PPC::V6, PPC::V7, PPC::V8, | 
|  | 5740 | PPC::V9, PPC::V10, PPC::V11, PPC::V12, PPC::V13 | 
|  | 5741 | }; | 
| Owen Anderson | e2f23a3 | 2007-09-07 04:06:50 +0000 | [diff] [blame] | 5742 | const unsigned NumGPRs = array_lengthof(GPR_32); | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 5743 | const unsigned NumFPRs = 13; | 
| Tilmann Scheller | 98bdaaa | 2009-07-03 06:43:35 +0000 | [diff] [blame] | 5744 | const unsigned NumVRs  = array_lengthof(VR); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5745 |  | 
| Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 5746 | const MCPhysReg *GPR = isPPC64 ? GPR_64 : GPR_32; | 
| Chris Lattner | ec78cad | 2006-06-26 22:48:35 +0000 | [diff] [blame] | 5747 |  | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 5748 | SmallVector<std::pair<unsigned, SDValue>, 8> RegsToPass; | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 5749 | SmallVector<TailCallArgumentInfo, 8> TailCallArguments; | 
|  | 5750 |  | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5751 | SmallVector<SDValue, 8> MemOpChains; | 
| Evan Cheng | c2cd473 | 2006-05-25 00:57:32 +0000 | [diff] [blame] | 5752 | for (unsigned i = 0; i != NumOps; ++i) { | 
| Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 5753 | SDValue Arg = OutVals[i]; | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 5754 | ISD::ArgFlagsTy Flags = Outs[i].Flags; | 
| Nicolas Geoffray | 7aad928 | 2007-03-13 15:02:46 +0000 | [diff] [blame] | 5755 |  | 
| Chris Lattner | b7552a8 | 2006-05-17 00:15:40 +0000 | [diff] [blame] | 5756 | // PtrOff will be used to store the current argument to the stack if a | 
|  | 5757 | // register cannot be found for it. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5758 | SDValue PtrOff; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5759 |  | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5760 | PtrOff = DAG.getConstant(ArgOffset, dl, StackPtr.getValueType()); | 
| Nicolas Geoffray | 7aad928 | 2007-03-13 15:02:46 +0000 | [diff] [blame] | 5761 |  | 
| Dale Johannesen | 679073b | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 5762 | PtrOff = DAG.getNode(ISD::ADD, dl, PtrVT, StackPtr, PtrOff); | 
| Chris Lattner | ec78cad | 2006-06-26 22:48:35 +0000 | [diff] [blame] | 5763 |  | 
|  | 5764 | // On PPC64, promote integers to 64-bit values. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5765 | if (isPPC64 && Arg.getValueType() == MVT::i32) { | 
| Duncan Sands | d97eea3 | 2008-03-21 09:14:45 +0000 | [diff] [blame] | 5766 | // FIXME: Should this use ANY_EXTEND if neither sext nor zext? | 
|  | 5767 | unsigned ExtOp = Flags.isSExt() ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND; | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5768 | Arg = DAG.getNode(ExtOp, dl, MVT::i64, Arg); | 
| Chris Lattner | ec78cad | 2006-06-26 22:48:35 +0000 | [diff] [blame] | 5769 | } | 
| Dale Johannesen | 85d41a1 | 2008-03-04 23:17:14 +0000 | [diff] [blame] | 5770 |  | 
| Dale Johannesen | bfa252d | 2008-03-07 20:27:40 +0000 | [diff] [blame] | 5771 | // FIXME memcpy is used way more than necessary.  Correctness first. | 
| Bill Schmidt | 019cc6f | 2012-09-19 15:42:13 +0000 | [diff] [blame] | 5772 | // Note: "by value" is code for passing a structure by value, not | 
|  | 5773 | // basic types. | 
| Duncan Sands | d97eea3 | 2008-03-21 09:14:45 +0000 | [diff] [blame] | 5774 | if (Flags.isByVal()) { | 
|  | 5775 | unsigned Size = Flags.getByValSize(); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5776 | // Very small objects are passed right-justified.  Everything else is | 
|  | 5777 | // passed left-justified. | 
|  | 5778 | if (Size==1 || Size==2) { | 
|  | 5779 | EVT VT = (Size==1) ? MVT::i8 : MVT::i16; | 
| Dale Johannesen | bfa252d | 2008-03-07 20:27:40 +0000 | [diff] [blame] | 5780 | if (GPR_idx != NumGPRs) { | 
| Stuart Hastings | 81c4306 | 2011-02-16 16:23:55 +0000 | [diff] [blame] | 5781 | SDValue Load = DAG.getExtLoad(ISD::EXTLOAD, dl, PtrVT, Chain, Arg, | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 5782 | MachinePointerInfo(), VT); | 
| Dale Johannesen | bfa252d | 2008-03-07 20:27:40 +0000 | [diff] [blame] | 5783 | MemOpChains.push_back(Load.getValue(1)); | 
|  | 5784 | RegsToPass.push_back(std::make_pair(GPR[GPR_idx++], Load)); | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 5785 |  | 
|  | 5786 | ArgOffset += PtrByteSize; | 
| Dale Johannesen | bfa252d | 2008-03-07 20:27:40 +0000 | [diff] [blame] | 5787 | } else { | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5788 | SDValue Const = DAG.getConstant(PtrByteSize - Size, dl, | 
| Bill Schmidt | 48081ca | 2012-10-16 13:30:53 +0000 | [diff] [blame] | 5789 | PtrOff.getValueType()); | 
| Dale Johannesen | 679073b | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 5790 | SDValue AddPtr = DAG.getNode(ISD::ADD, dl, PtrVT, PtrOff, Const); | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5791 | Chain = CallSeqStart = createMemcpyOutsideCallSeq(Arg, AddPtr, | 
|  | 5792 | CallSeqStart, | 
|  | 5793 | Flags, DAG, dl); | 
| Dale Johannesen | bfa252d | 2008-03-07 20:27:40 +0000 | [diff] [blame] | 5794 | ArgOffset += PtrByteSize; | 
|  | 5795 | } | 
|  | 5796 | continue; | 
|  | 5797 | } | 
| Dale Johannesen | 92dcf1e | 2008-03-17 02:13:43 +0000 | [diff] [blame] | 5798 | // Copy entire object into memory.  There are cases where gcc-generated | 
|  | 5799 | // code assumes it is there, even if it could be put entirely into | 
|  | 5800 | // registers.  (This is not what the doc says.) | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5801 | Chain = CallSeqStart = createMemcpyOutsideCallSeq(Arg, PtrOff, | 
|  | 5802 | CallSeqStart, | 
|  | 5803 | Flags, DAG, dl); | 
| Bill Schmidt | 019cc6f | 2012-09-19 15:42:13 +0000 | [diff] [blame] | 5804 |  | 
|  | 5805 | // For small aggregates (Darwin only) and aggregates >= PtrByteSize, | 
|  | 5806 | // copy the pieces of the object that fit into registers from the | 
|  | 5807 | // parameter save area. | 
| Dale Johannesen | 85d41a1 | 2008-03-04 23:17:14 +0000 | [diff] [blame] | 5808 | for (unsigned j=0; j<Size; j+=PtrByteSize) { | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5809 | SDValue Const = DAG.getConstant(j, dl, PtrOff.getValueType()); | 
| Dale Johannesen | 679073b | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 5810 | SDValue AddArg = DAG.getNode(ISD::ADD, dl, PtrVT, Arg, Const); | 
| Dale Johannesen | 85d41a1 | 2008-03-04 23:17:14 +0000 | [diff] [blame] | 5811 | if (GPR_idx != NumGPRs) { | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 5812 | SDValue Load = | 
|  | 5813 | DAG.getLoad(PtrVT, dl, Chain, AddArg, MachinePointerInfo()); | 
| Dale Johannesen | 0d23505 | 2008-03-05 23:31:27 +0000 | [diff] [blame] | 5814 | MemOpChains.push_back(Load.getValue(1)); | 
| Dale Johannesen | 85d41a1 | 2008-03-04 23:17:14 +0000 | [diff] [blame] | 5815 | RegsToPass.push_back(std::make_pair(GPR[GPR_idx++], Load)); | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 5816 | ArgOffset += PtrByteSize; | 
| Dale Johannesen | 85d41a1 | 2008-03-04 23:17:14 +0000 | [diff] [blame] | 5817 | } else { | 
| Dale Johannesen | 92dcf1e | 2008-03-17 02:13:43 +0000 | [diff] [blame] | 5818 | ArgOffset += ((Size - j + PtrByteSize-1)/PtrByteSize)*PtrByteSize; | 
| Dale Johannesen | bfa252d | 2008-03-07 20:27:40 +0000 | [diff] [blame] | 5819 | break; | 
| Dale Johannesen | 85d41a1 | 2008-03-04 23:17:14 +0000 | [diff] [blame] | 5820 | } | 
|  | 5821 | } | 
|  | 5822 | continue; | 
|  | 5823 | } | 
|  | 5824 |  | 
| Craig Topper | 5671010 | 2013-08-15 02:33:50 +0000 | [diff] [blame] | 5825 | switch (Arg.getSimpleValueType().SimpleTy) { | 
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 5826 | default: llvm_unreachable("Unexpected ValueType for argument!"); | 
| Hal Finkel | 5cae216 | 2014-02-28 01:17:25 +0000 | [diff] [blame] | 5827 | case MVT::i1: | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5828 | case MVT::i32: | 
|  | 5829 | case MVT::i64: | 
| Chris Lattner | b1e9e37 | 2006-05-17 06:01:33 +0000 | [diff] [blame] | 5830 | if (GPR_idx != NumGPRs) { | 
| Hal Finkel | 7f908e8 | 2014-03-06 00:45:19 +0000 | [diff] [blame] | 5831 | if (Arg.getValueType() == MVT::i1) | 
|  | 5832 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, PtrVT, Arg); | 
|  | 5833 |  | 
| Chris Lattner | b1e9e37 | 2006-05-17 06:01:33 +0000 | [diff] [blame] | 5834 | RegsToPass.push_back(std::make_pair(GPR[GPR_idx++], Arg)); | 
| Chris Lattner | b7552a8 | 2006-05-17 00:15:40 +0000 | [diff] [blame] | 5835 | } else { | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 5836 | LowerMemOpCallTo(DAG, MF, Chain, Arg, PtrOff, SPDiff, ArgOffset, | 
|  | 5837 | isPPC64, isTailCall, false, MemOpChains, | 
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 5838 | TailCallArguments, dl); | 
| Chris Lattner | b7552a8 | 2006-05-17 00:15:40 +0000 | [diff] [blame] | 5839 | } | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 5840 | ArgOffset += PtrByteSize; | 
| Chris Lattner | b7552a8 | 2006-05-17 00:15:40 +0000 | [diff] [blame] | 5841 | break; | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5842 | case MVT::f32: | 
|  | 5843 | case MVT::f64: | 
| Chris Lattner | b1e9e37 | 2006-05-17 06:01:33 +0000 | [diff] [blame] | 5844 | if (FPR_idx != NumFPRs) { | 
|  | 5845 | RegsToPass.push_back(std::make_pair(FPR[FPR_idx++], Arg)); | 
|  | 5846 |  | 
| Chris Lattner | b7552a8 | 2006-05-17 00:15:40 +0000 | [diff] [blame] | 5847 | if (isVarArg) { | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 5848 | SDValue Store = | 
|  | 5849 | DAG.getStore(Chain, dl, Arg, PtrOff, MachinePointerInfo()); | 
| Chris Lattner | b1e9e37 | 2006-05-17 06:01:33 +0000 | [diff] [blame] | 5850 | MemOpChains.push_back(Store); | 
|  | 5851 |  | 
| Chris Lattner | b7552a8 | 2006-05-17 00:15:40 +0000 | [diff] [blame] | 5852 | // Float varargs are always shadowed in available integer registers | 
| Chris Lattner | b1e9e37 | 2006-05-17 06:01:33 +0000 | [diff] [blame] | 5853 | if (GPR_idx != NumGPRs) { | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 5854 | SDValue Load = | 
|  | 5855 | DAG.getLoad(PtrVT, dl, Store, PtrOff, MachinePointerInfo()); | 
| Chris Lattner | b1e9e37 | 2006-05-17 06:01:33 +0000 | [diff] [blame] | 5856 | MemOpChains.push_back(Load.getValue(1)); | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 5857 | RegsToPass.push_back(std::make_pair(GPR[GPR_idx++], Load)); | 
| Chris Lattner | b7552a8 | 2006-05-17 00:15:40 +0000 | [diff] [blame] | 5858 | } | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5859 | if (GPR_idx != NumGPRs && Arg.getValueType() == MVT::f64 && !isPPC64){ | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5860 | SDValue ConstFour = DAG.getConstant(4, dl, PtrOff.getValueType()); | 
| Dale Johannesen | 679073b | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 5861 | PtrOff = DAG.getNode(ISD::ADD, dl, PtrVT, PtrOff, ConstFour); | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 5862 | SDValue Load = | 
|  | 5863 | DAG.getLoad(PtrVT, dl, Store, PtrOff, MachinePointerInfo()); | 
| Chris Lattner | b1e9e37 | 2006-05-17 06:01:33 +0000 | [diff] [blame] | 5864 | MemOpChains.push_back(Load.getValue(1)); | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 5865 | RegsToPass.push_back(std::make_pair(GPR[GPR_idx++], Load)); | 
| Chris Lattner | aa40ec1 | 2006-05-16 22:56:08 +0000 | [diff] [blame] | 5866 | } | 
|  | 5867 | } else { | 
| Chris Lattner | b7552a8 | 2006-05-17 00:15:40 +0000 | [diff] [blame] | 5868 | // If we have any FPRs remaining, we may also have GPRs remaining. | 
|  | 5869 | // Args passed in FPRs consume either 1 (f32) or 2 (f64) available | 
|  | 5870 | // GPRs. | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 5871 | if (GPR_idx != NumGPRs) | 
|  | 5872 | ++GPR_idx; | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5873 | if (GPR_idx != NumGPRs && Arg.getValueType() == MVT::f64 && | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 5874 | !isPPC64)  // PPC64 has 64-bit GPR's obviously :) | 
|  | 5875 | ++GPR_idx; | 
| Chris Lattner | aa40ec1 | 2006-05-16 22:56:08 +0000 | [diff] [blame] | 5876 | } | 
| Bill Schmidt | 57d6de5 | 2012-10-23 15:51:16 +0000 | [diff] [blame] | 5877 | } else | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 5878 | LowerMemOpCallTo(DAG, MF, Chain, Arg, PtrOff, SPDiff, ArgOffset, | 
|  | 5879 | isPPC64, isTailCall, false, MemOpChains, | 
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 5880 | TailCallArguments, dl); | 
| Tilmann Scheller | 773f14c | 2009-07-03 06:47:08 +0000 | [diff] [blame] | 5881 | if (isPPC64) | 
|  | 5882 | ArgOffset += 8; | 
|  | 5883 | else | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5884 | ArgOffset += Arg.getValueType() == MVT::f32 ? 4 : 8; | 
| Chris Lattner | b7552a8 | 2006-05-17 00:15:40 +0000 | [diff] [blame] | 5885 | break; | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5886 | case MVT::v4f32: | 
|  | 5887 | case MVT::v4i32: | 
|  | 5888 | case MVT::v8i16: | 
|  | 5889 | case MVT::v16i8: | 
| Dale Johannesen | b28456e | 2008-03-12 00:22:17 +0000 | [diff] [blame] | 5890 | if (isVarArg) { | 
|  | 5891 | // These go aligned on the stack, or in the corresponding R registers | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5892 | // when within range.  The Darwin PPC ABI doc claims they also go in | 
| Dale Johannesen | b28456e | 2008-03-12 00:22:17 +0000 | [diff] [blame] | 5893 | // V registers; in fact gcc does this only for arguments that are | 
|  | 5894 | // prototyped, not for those that match the ...  We do it for all | 
|  | 5895 | // arguments, seems to work. | 
|  | 5896 | while (ArgOffset % 16 !=0) { | 
|  | 5897 | ArgOffset += PtrByteSize; | 
|  | 5898 | if (GPR_idx != NumGPRs) | 
|  | 5899 | GPR_idx++; | 
|  | 5900 | } | 
|  | 5901 | // We could elide this store in the case where the object fits | 
|  | 5902 | // entirely in R registers.  Maybe later. | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5903 | PtrOff = DAG.getNode(ISD::ADD, dl, PtrVT, StackPtr, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5904 | DAG.getConstant(ArgOffset, dl, PtrVT)); | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 5905 | SDValue Store = | 
|  | 5906 | DAG.getStore(Chain, dl, Arg, PtrOff, MachinePointerInfo()); | 
| Dale Johannesen | b28456e | 2008-03-12 00:22:17 +0000 | [diff] [blame] | 5907 | MemOpChains.push_back(Store); | 
|  | 5908 | if (VR_idx != NumVRs) { | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 5909 | SDValue Load = | 
|  | 5910 | DAG.getLoad(MVT::v4f32, dl, Store, PtrOff, MachinePointerInfo()); | 
| Dale Johannesen | b28456e | 2008-03-12 00:22:17 +0000 | [diff] [blame] | 5911 | MemOpChains.push_back(Load.getValue(1)); | 
|  | 5912 | RegsToPass.push_back(std::make_pair(VR[VR_idx++], Load)); | 
|  | 5913 | } | 
|  | 5914 | ArgOffset += 16; | 
|  | 5915 | for (unsigned i=0; i<16; i+=PtrByteSize) { | 
|  | 5916 | if (GPR_idx == NumGPRs) | 
|  | 5917 | break; | 
| Dale Johannesen | 679073b | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 5918 | SDValue Ix = DAG.getNode(ISD::ADD, dl, PtrVT, PtrOff, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5919 | DAG.getConstant(i, dl, PtrVT)); | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 5920 | SDValue Load = | 
|  | 5921 | DAG.getLoad(PtrVT, dl, Store, Ix, MachinePointerInfo()); | 
| Dale Johannesen | b28456e | 2008-03-12 00:22:17 +0000 | [diff] [blame] | 5922 | MemOpChains.push_back(Load.getValue(1)); | 
|  | 5923 | RegsToPass.push_back(std::make_pair(GPR[GPR_idx++], Load)); | 
|  | 5924 | } | 
|  | 5925 | break; | 
|  | 5926 | } | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 5927 |  | 
| Dale Johannesen | 0dfd3f3 | 2008-03-14 17:41:26 +0000 | [diff] [blame] | 5928 | // Non-varargs Altivec params generally go in registers, but have | 
|  | 5929 | // stack space allocated at the end. | 
|  | 5930 | if (VR_idx != NumVRs) { | 
|  | 5931 | // Doesn't have GPR space allocated. | 
|  | 5932 | RegsToPass.push_back(std::make_pair(VR[VR_idx++], Arg)); | 
|  | 5933 | } else if (nAltivecParamsAtEnd==0) { | 
|  | 5934 | // We are emitting Altivec params in order. | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 5935 | LowerMemOpCallTo(DAG, MF, Chain, Arg, PtrOff, SPDiff, ArgOffset, | 
|  | 5936 | isPPC64, isTailCall, true, MemOpChains, | 
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 5937 | TailCallArguments, dl); | 
| Dale Johannesen | b28456e | 2008-03-12 00:22:17 +0000 | [diff] [blame] | 5938 | ArgOffset += 16; | 
| Dale Johannesen | b28456e | 2008-03-12 00:22:17 +0000 | [diff] [blame] | 5939 | } | 
| Chris Lattner | b7552a8 | 2006-05-17 00:15:40 +0000 | [diff] [blame] | 5940 | break; | 
| Chris Lattner | aa40ec1 | 2006-05-16 22:56:08 +0000 | [diff] [blame] | 5941 | } | 
| Chris Lattner | aa40ec1 | 2006-05-16 22:56:08 +0000 | [diff] [blame] | 5942 | } | 
| Dale Johannesen | 0dfd3f3 | 2008-03-14 17:41:26 +0000 | [diff] [blame] | 5943 | // If all Altivec parameters fit in registers, as they usually do, | 
|  | 5944 | // they get stack space following the non-Altivec parameters.  We | 
|  | 5945 | // don't track this here because nobody below needs it. | 
|  | 5946 | // If there are more Altivec parameters than fit in registers emit | 
|  | 5947 | // the stores here. | 
|  | 5948 | if (!isVarArg && nAltivecParamsAtEnd > NumVRs) { | 
|  | 5949 | unsigned j = 0; | 
|  | 5950 | // Offset is aligned; skip 1st 12 params which go in V registers. | 
|  | 5951 | ArgOffset = ((ArgOffset+15)/16)*16; | 
|  | 5952 | ArgOffset += 12*16; | 
|  | 5953 | for (unsigned i = 0; i != NumOps; ++i) { | 
| Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 5954 | SDValue Arg = OutVals[i]; | 
|  | 5955 | EVT ArgType = Outs[i].VT; | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 5956 | if (ArgType==MVT::v4f32 || ArgType==MVT::v4i32 || | 
|  | 5957 | ArgType==MVT::v8i16 || ArgType==MVT::v16i8) { | 
| Dale Johannesen | 0dfd3f3 | 2008-03-14 17:41:26 +0000 | [diff] [blame] | 5958 | if (++j > NumVRs) { | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5959 | SDValue PtrOff; | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 5960 | // We are emitting Altivec params in order. | 
|  | 5961 | LowerMemOpCallTo(DAG, MF, Chain, Arg, PtrOff, SPDiff, ArgOffset, | 
|  | 5962 | isPPC64, isTailCall, true, MemOpChains, | 
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 5963 | TailCallArguments, dl); | 
| Dale Johannesen | 0dfd3f3 | 2008-03-14 17:41:26 +0000 | [diff] [blame] | 5964 | ArgOffset += 16; | 
|  | 5965 | } | 
|  | 5966 | } | 
|  | 5967 | } | 
|  | 5968 | } | 
|  | 5969 |  | 
| Chris Lattner | b1e9e37 | 2006-05-17 06:01:33 +0000 | [diff] [blame] | 5970 | if (!MemOpChains.empty()) | 
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 5971 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5972 |  | 
| Dale Johannesen | 90eab67 | 2010-03-09 20:15:42 +0000 | [diff] [blame] | 5973 | // On Darwin, R12 must contain the address of an indirect callee.  This does | 
|  | 5974 | // not mean the MTCTR instruction must use R12; it's easier to model this as | 
|  | 5975 | // an extra parameter, so do that. | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5976 | if (!isTailCall && | 
| Hal Finkel | 87deb0b | 2015-01-12 04:34:47 +0000 | [diff] [blame] | 5977 | !isFunctionGlobalAddress(Callee) && | 
|  | 5978 | !isa<ExternalSymbolSDNode>(Callee) && | 
| Dale Johannesen | 90eab67 | 2010-03-09 20:15:42 +0000 | [diff] [blame] | 5979 | !isBLACompatibleAddress(Callee, DAG)) | 
|  | 5980 | RegsToPass.push_back(std::make_pair((unsigned)(isPPC64 ? PPC::X12 : | 
|  | 5981 | PPC::R12), Callee)); | 
|  | 5982 |  | 
| Chris Lattner | b1e9e37 | 2006-05-17 06:01:33 +0000 | [diff] [blame] | 5983 | // Build a sequence of copy-to-reg nodes chained together with token chain | 
|  | 5984 | // and flag operands which copy the outgoing args into the appropriate regs. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 5985 | SDValue InFlag; | 
| Chris Lattner | b1e9e37 | 2006-05-17 06:01:33 +0000 | [diff] [blame] | 5986 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5987 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, | 
| Dale Johannesen | 679073b | 2009-02-04 02:34:38 +0000 | [diff] [blame] | 5988 | RegsToPass[i].second, InFlag); | 
| Chris Lattner | b1e9e37 | 2006-05-17 06:01:33 +0000 | [diff] [blame] | 5989 | InFlag = Chain.getValue(1); | 
|  | 5990 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 5991 |  | 
| Chris Lattner | df8e17d | 2010-11-14 23:42:06 +0000 | [diff] [blame] | 5992 | if (isTailCall) | 
| Eric Christopher | 327e440 | 2016-07-07 01:08:17 +0000 | [diff] [blame] | 5993 | PrepareTailCall(DAG, InFlag, Chain, dl, SPDiff, NumBytes, LROp, FPOp, | 
| Eric Christopher | ade4eed | 2016-07-07 00:39:32 +0000 | [diff] [blame] | 5994 | TailCallArguments); | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 5995 |  | 
| Eric Christopher | 2454a3b | 2016-07-07 01:08:23 +0000 | [diff] [blame] | 5996 | return FinishCall(CallConv, dl, isTailCall, isVarArg, isPatchPoint, | 
| Hal Finkel | 965cea5 | 2015-07-12 00:37:44 +0000 | [diff] [blame] | 5997 | /* unused except on PPC64 ELFv1 */ false, DAG, | 
| Hal Finkel | e2ab0f1 | 2015-01-15 21:17:34 +0000 | [diff] [blame] | 5998 | RegsToPass, InFlag, Chain, CallSeqStart, Callee, SPDiff, | 
|  | 5999 | NumBytes, Ins, InVals, CS); | 
| Chris Lattner | aa40ec1 | 2006-05-16 22:56:08 +0000 | [diff] [blame] | 6000 | } | 
|  | 6001 |  | 
| Hal Finkel | 450128a | 2011-10-14 19:51:36 +0000 | [diff] [blame] | 6002 | bool | 
|  | 6003 | PPCTargetLowering::CanLowerReturn(CallingConv::ID CallConv, | 
|  | 6004 | MachineFunction &MF, bool isVarArg, | 
|  | 6005 | const SmallVectorImpl<ISD::OutputArg> &Outs, | 
|  | 6006 | LLVMContext &Context) const { | 
|  | 6007 | SmallVector<CCValAssign, 16> RVLocs; | 
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 6008 | CCState CCInfo(CallConv, isVarArg, MF, RVLocs, Context); | 
| Hal Finkel | 450128a | 2011-10-14 19:51:36 +0000 | [diff] [blame] | 6009 | return CCInfo.CheckReturn(Outs, RetCC_PPC); | 
|  | 6010 | } | 
|  | 6011 |  | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 6012 | SDValue | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 6013 | PPCTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv, | 
|  | 6014 | bool isVarArg, | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 6015 | const SmallVectorImpl<ISD::OutputArg> &Outs, | 
| Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 6016 | const SmallVectorImpl<SDValue> &OutVals, | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 6017 | const SDLoc &dl, SelectionDAG &DAG) const { | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 6018 |  | 
| Chris Lattner | 4f2e4e0 | 2007-03-06 00:59:59 +0000 | [diff] [blame] | 6019 | SmallVector<CCValAssign, 16> RVLocs; | 
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 6020 | CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs, | 
|  | 6021 | *DAG.getContext()); | 
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 6022 | CCInfo.AnalyzeReturn(Outs, RetCC_PPC); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6023 |  | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6024 | SDValue Flag; | 
| Jakob Stoklund Olesen | 8660a8c | 2013-02-05 18:12:00 +0000 | [diff] [blame] | 6025 | SmallVector<SDValue, 4> RetOps(1, Chain); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6026 |  | 
| Chris Lattner | 4f2e4e0 | 2007-03-06 00:59:59 +0000 | [diff] [blame] | 6027 | // Copy the result values into the output registers. | 
|  | 6028 | for (unsigned i = 0; i != RVLocs.size(); ++i) { | 
|  | 6029 | CCValAssign &VA = RVLocs[i]; | 
|  | 6030 | assert(VA.isRegLoc() && "Can only return in registers!"); | 
| Ulrich Weigand | 339d059 | 2012-11-05 19:39:45 +0000 | [diff] [blame] | 6031 |  | 
|  | 6032 | SDValue Arg = OutVals[i]; | 
|  | 6033 |  | 
|  | 6034 | switch (VA.getLocInfo()) { | 
|  | 6035 | default: llvm_unreachable("Unknown loc info!"); | 
|  | 6036 | case CCValAssign::Full: break; | 
|  | 6037 | case CCValAssign::AExt: | 
|  | 6038 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); | 
|  | 6039 | break; | 
|  | 6040 | case CCValAssign::ZExt: | 
|  | 6041 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); | 
|  | 6042 | break; | 
|  | 6043 | case CCValAssign::SExt: | 
|  | 6044 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); | 
|  | 6045 | break; | 
|  | 6046 | } | 
|  | 6047 |  | 
|  | 6048 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), Arg, Flag); | 
| Chris Lattner | 4f2e4e0 | 2007-03-06 00:59:59 +0000 | [diff] [blame] | 6049 | Flag = Chain.getValue(1); | 
| Jakob Stoklund Olesen | 8660a8c | 2013-02-05 18:12:00 +0000 | [diff] [blame] | 6050 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); | 
| Chris Lattner | 4f2e4e0 | 2007-03-06 00:59:59 +0000 | [diff] [blame] | 6051 | } | 
|  | 6052 |  | 
| Chuang-Yu Cheng | 98c1894 | 2016-04-08 12:04:32 +0000 | [diff] [blame] | 6053 | const PPCRegisterInfo *TRI = Subtarget.getRegisterInfo(); | 
|  | 6054 | const MCPhysReg *I = | 
|  | 6055 | TRI->getCalleeSavedRegsViaCopy(&DAG.getMachineFunction()); | 
|  | 6056 | if (I) { | 
|  | 6057 | for (; *I; ++I) { | 
|  | 6058 |  | 
|  | 6059 | if (PPC::G8RCRegClass.contains(*I)) | 
|  | 6060 | RetOps.push_back(DAG.getRegister(*I, MVT::i64)); | 
|  | 6061 | else if (PPC::F8RCRegClass.contains(*I)) | 
|  | 6062 | RetOps.push_back(DAG.getRegister(*I, MVT::getFloatingPointVT(64))); | 
|  | 6063 | else if (PPC::CRRCRegClass.contains(*I)) | 
|  | 6064 | RetOps.push_back(DAG.getRegister(*I, MVT::i1)); | 
|  | 6065 | else if (PPC::VRRCRegClass.contains(*I)) | 
|  | 6066 | RetOps.push_back(DAG.getRegister(*I, MVT::Other)); | 
|  | 6067 | else | 
|  | 6068 | llvm_unreachable("Unexpected register class in CSRsViaCopy!"); | 
|  | 6069 | } | 
|  | 6070 | } | 
|  | 6071 |  | 
| Jakob Stoklund Olesen | 8660a8c | 2013-02-05 18:12:00 +0000 | [diff] [blame] | 6072 | RetOps[0] = Chain;  // Update chain. | 
|  | 6073 |  | 
|  | 6074 | // Add the flag if we have it. | 
| Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 6075 | if (Flag.getNode()) | 
| Jakob Stoklund Olesen | 8660a8c | 2013-02-05 18:12:00 +0000 | [diff] [blame] | 6076 | RetOps.push_back(Flag); | 
|  | 6077 |  | 
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 6078 | return DAG.getNode(PPCISD::RET_FLAG, dl, MVT::Other, RetOps); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6079 | } | 
|  | 6080 |  | 
| Eric Christopher | b976a39 | 2016-07-07 00:39:27 +0000 | [diff] [blame] | 6081 | SDValue | 
|  | 6082 | PPCTargetLowering::LowerGET_DYNAMIC_AREA_OFFSET(SDValue Op, | 
|  | 6083 | SelectionDAG &DAG) const { | 
| Yury Gribov | d7dbb66 | 2015-12-01 11:40:55 +0000 | [diff] [blame] | 6084 | SDLoc dl(Op); | 
|  | 6085 |  | 
|  | 6086 | // Get the corect type for integers. | 
|  | 6087 | EVT IntVT = Op.getValueType(); | 
|  | 6088 |  | 
|  | 6089 | // Get the inputs. | 
|  | 6090 | SDValue Chain = Op.getOperand(0); | 
|  | 6091 | SDValue FPSIdx = getFramePointerFrameIndex(DAG); | 
|  | 6092 | // Build a DYNAREAOFFSET node. | 
|  | 6093 | SDValue Ops[2] = {Chain, FPSIdx}; | 
|  | 6094 | SDVTList VTs = DAG.getVTList(IntVT); | 
|  | 6095 | return DAG.getNode(PPCISD::DYNAREAOFFSET, dl, VTs, Ops); | 
|  | 6096 | } | 
|  | 6097 |  | 
| Eric Christopher | b976a39 | 2016-07-07 00:39:27 +0000 | [diff] [blame] | 6098 | SDValue PPCTargetLowering::LowerSTACKRESTORE(SDValue Op, | 
|  | 6099 | SelectionDAG &DAG) const { | 
| Jim Laskey | e4f4d04 | 2006-12-04 22:04:42 +0000 | [diff] [blame] | 6100 | // When we pop the dynamic allocation we need to restore the SP link. | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6101 | SDLoc dl(Op); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6102 |  | 
| Jim Laskey | e4f4d04 | 2006-12-04 22:04:42 +0000 | [diff] [blame] | 6103 | // Get the corect type for pointers. | 
| Eric Christopher | cd71946 | 2016-07-07 01:49:59 +0000 | [diff] [blame] | 6104 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); | 
| Jim Laskey | e4f4d04 | 2006-12-04 22:04:42 +0000 | [diff] [blame] | 6105 |  | 
|  | 6106 | // Construct the stack pointer operand. | 
| Dale Johannesen | 86dcae1 | 2009-11-24 01:09:07 +0000 | [diff] [blame] | 6107 | bool isPPC64 = Subtarget.isPPC64(); | 
|  | 6108 | unsigned SP = isPPC64 ? PPC::X1 : PPC::R1; | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6109 | SDValue StackPtr = DAG.getRegister(SP, PtrVT); | 
| Jim Laskey | e4f4d04 | 2006-12-04 22:04:42 +0000 | [diff] [blame] | 6110 |  | 
|  | 6111 | // Get the operands for the STACKRESTORE. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6112 | SDValue Chain = Op.getOperand(0); | 
|  | 6113 | SDValue SaveSP = Op.getOperand(1); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6114 |  | 
| Jim Laskey | e4f4d04 | 2006-12-04 22:04:42 +0000 | [diff] [blame] | 6115 | // Load the old link SP. | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 6116 | SDValue LoadLinkSP = | 
|  | 6117 | DAG.getLoad(PtrVT, dl, Chain, StackPtr, MachinePointerInfo()); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6118 |  | 
| Jim Laskey | e4f4d04 | 2006-12-04 22:04:42 +0000 | [diff] [blame] | 6119 | // Restore the stack pointer. | 
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 6120 | Chain = DAG.getCopyToReg(LoadLinkSP.getValue(1), dl, SP, SaveSP); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6121 |  | 
| Jim Laskey | e4f4d04 | 2006-12-04 22:04:42 +0000 | [diff] [blame] | 6122 | // Store the old link SP. | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 6123 | return DAG.getStore(Chain, dl, LoadLinkSP, StackPtr, MachinePointerInfo()); | 
| Jim Laskey | e4f4d04 | 2006-12-04 22:04:42 +0000 | [diff] [blame] | 6124 | } | 
|  | 6125 |  | 
| NAKAMURA Takumi | 70ad98a | 2015-09-22 11:13:55 +0000 | [diff] [blame] | 6126 | SDValue PPCTargetLowering::getReturnAddrFrameIndex(SelectionDAG &DAG) const { | 
| Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 6127 | MachineFunction &MF = DAG.getMachineFunction(); | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 6128 | bool isPPC64 = Subtarget.isPPC64(); | 
| Eric Christopher | cd71946 | 2016-07-07 01:49:59 +0000 | [diff] [blame] | 6129 | EVT PtrVT = getPointerTy(MF.getDataLayout()); | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 6130 |  | 
|  | 6131 | // Get current frame pointer save index.  The users of this index will be | 
|  | 6132 | // primarily DYNALLOC instructions. | 
|  | 6133 | PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>(); | 
|  | 6134 | int RASI = FI->getReturnAddrSaveIndex(); | 
|  | 6135 |  | 
|  | 6136 | // If the frame pointer save index hasn't been defined yet. | 
|  | 6137 | if (!RASI) { | 
|  | 6138 | // Find out what the fix offset of the frame pointer save area. | 
| Eric Christopher | f71609b | 2015-02-13 00:39:27 +0000 | [diff] [blame] | 6139 | int LROffset = Subtarget.getFrameLowering()->getReturnSaveOffset(); | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 6140 | // Allocate the frame index for frame pointer save area. | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 6141 | RASI = MF.getFrameInfo().CreateFixedObject(isPPC64? 8 : 4, LROffset, false); | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 6142 | // Save the result. | 
|  | 6143 | FI->setReturnAddrSaveIndex(RASI); | 
|  | 6144 | } | 
|  | 6145 | return DAG.getFrameIndex(RASI, PtrVT); | 
|  | 6146 | } | 
|  | 6147 |  | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6148 | SDValue | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 6149 | PPCTargetLowering::getFramePointerFrameIndex(SelectionDAG & DAG) const { | 
|  | 6150 | MachineFunction &MF = DAG.getMachineFunction(); | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 6151 | bool isPPC64 = Subtarget.isPPC64(); | 
| Eric Christopher | cd71946 | 2016-07-07 01:49:59 +0000 | [diff] [blame] | 6152 | EVT PtrVT = getPointerTy(MF.getDataLayout()); | 
| Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 6153 |  | 
|  | 6154 | // Get current frame pointer save index.  The users of this index will be | 
|  | 6155 | // primarily DYNALLOC instructions. | 
|  | 6156 | PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>(); | 
|  | 6157 | int FPSI = FI->getFramePointerSaveIndex(); | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 6158 |  | 
| Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 6159 | // If the frame pointer save index hasn't been defined yet. | 
|  | 6160 | if (!FPSI) { | 
|  | 6161 | // Find out what the fix offset of the frame pointer save area. | 
| Eric Christopher | dc3a8a4 | 2015-02-13 00:39:38 +0000 | [diff] [blame] | 6162 | int FPOffset = Subtarget.getFrameLowering()->getFramePointerSaveOffset(); | 
| Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 6163 | // Allocate the frame index for frame pointer save area. | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 6164 | FPSI = MF.getFrameInfo().CreateFixedObject(isPPC64? 8 : 4, FPOffset, true); | 
| Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 6165 | // Save the result. | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6166 | FI->setFramePointerSaveIndex(FPSI); | 
| Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 6167 | } | 
| Arnold Schwaighofer | be0de34 | 2008-04-30 09:16:33 +0000 | [diff] [blame] | 6168 | return DAG.getFrameIndex(FPSI, PtrVT); | 
|  | 6169 | } | 
| Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 6170 |  | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6171 | SDValue PPCTargetLowering::LowerDYNAMIC_STACKALLOC(SDValue Op, | 
| Eric Christopher | b976a39 | 2016-07-07 00:39:27 +0000 | [diff] [blame] | 6172 | SelectionDAG &DAG) const { | 
| Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 6173 | // Get the inputs. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6174 | SDValue Chain = Op.getOperand(0); | 
|  | 6175 | SDValue Size  = Op.getOperand(1); | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6176 | SDLoc dl(Op); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6177 |  | 
| Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 6178 | // Get the corect type for pointers. | 
| Eric Christopher | cd71946 | 2016-07-07 01:49:59 +0000 | [diff] [blame] | 6179 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); | 
| Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 6180 | // Negate the size. | 
| Dale Johannesen | 400dc2e | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 6181 | SDValue NegSize = DAG.getNode(ISD::SUB, dl, PtrVT, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6182 | DAG.getConstant(0, dl, PtrVT), Size); | 
| Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 6183 | // Construct a node for the frame pointer save index. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6184 | SDValue FPSIdx = getFramePointerFrameIndex(DAG); | 
| Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 6185 | // Build a DYNALLOC node. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6186 | SDValue Ops[3] = { Chain, NegSize, FPSIdx }; | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6187 | SDVTList VTs = DAG.getVTList(PtrVT, MVT::Other); | 
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 6188 | return DAG.getNode(PPCISD::DYNALLOC, dl, VTs, Ops); | 
| Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 6189 | } | 
|  | 6190 |  | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 6191 | SDValue PPCTargetLowering::lowerEH_SJLJ_SETJMP(SDValue Op, | 
|  | 6192 | SelectionDAG &DAG) const { | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6193 | SDLoc DL(Op); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 6194 | return DAG.getNode(PPCISD::EH_SJLJ_SETJMP, DL, | 
|  | 6195 | DAG.getVTList(MVT::i32, MVT::Other), | 
|  | 6196 | Op.getOperand(0), Op.getOperand(1)); | 
|  | 6197 | } | 
|  | 6198 |  | 
|  | 6199 | SDValue PPCTargetLowering::lowerEH_SJLJ_LONGJMP(SDValue Op, | 
|  | 6200 | SelectionDAG &DAG) const { | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6201 | SDLoc DL(Op); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 6202 | return DAG.getNode(PPCISD::EH_SJLJ_LONGJMP, DL, MVT::Other, | 
|  | 6203 | Op.getOperand(0), Op.getOperand(1)); | 
|  | 6204 | } | 
|  | 6205 |  | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 6206 | SDValue PPCTargetLowering::LowerLOAD(SDValue Op, SelectionDAG &DAG) const { | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 6207 | if (Op.getValueType().isVector()) | 
|  | 6208 | return LowerVectorLoad(Op, DAG); | 
|  | 6209 |  | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 6210 | assert(Op.getValueType() == MVT::i1 && | 
|  | 6211 | "Custom lowering only for i1 loads"); | 
|  | 6212 |  | 
|  | 6213 | // First, load 8 bits into 32 bits, then truncate to 1 bit. | 
|  | 6214 |  | 
|  | 6215 | SDLoc dl(Op); | 
|  | 6216 | LoadSDNode *LD = cast<LoadSDNode>(Op); | 
|  | 6217 |  | 
|  | 6218 | SDValue Chain = LD->getChain(); | 
|  | 6219 | SDValue BasePtr = LD->getBasePtr(); | 
|  | 6220 | MachineMemOperand *MMO = LD->getMemOperand(); | 
|  | 6221 |  | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 6222 | SDValue NewLD = | 
|  | 6223 | DAG.getExtLoad(ISD::EXTLOAD, dl, getPointerTy(DAG.getDataLayout()), Chain, | 
|  | 6224 | BasePtr, MVT::i8, MMO); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 6225 | SDValue Result = DAG.getNode(ISD::TRUNCATE, dl, MVT::i1, NewLD); | 
|  | 6226 |  | 
|  | 6227 | SDValue Ops[] = { Result, SDValue(NewLD.getNode(), 1) }; | 
| Craig Topper | 64941d9 | 2014-04-27 19:20:57 +0000 | [diff] [blame] | 6228 | return DAG.getMergeValues(Ops, dl); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 6229 | } | 
|  | 6230 |  | 
|  | 6231 | SDValue PPCTargetLowering::LowerSTORE(SDValue Op, SelectionDAG &DAG) const { | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 6232 | if (Op.getOperand(1).getValueType().isVector()) | 
|  | 6233 | return LowerVectorStore(Op, DAG); | 
|  | 6234 |  | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 6235 | assert(Op.getOperand(1).getValueType() == MVT::i1 && | 
|  | 6236 | "Custom lowering only for i1 stores"); | 
|  | 6237 |  | 
|  | 6238 | // First, zero extend to 32 bits, then use a truncating store to 8 bits. | 
|  | 6239 |  | 
|  | 6240 | SDLoc dl(Op); | 
|  | 6241 | StoreSDNode *ST = cast<StoreSDNode>(Op); | 
|  | 6242 |  | 
|  | 6243 | SDValue Chain = ST->getChain(); | 
|  | 6244 | SDValue BasePtr = ST->getBasePtr(); | 
|  | 6245 | SDValue Value = ST->getValue(); | 
|  | 6246 | MachineMemOperand *MMO = ST->getMemOperand(); | 
|  | 6247 |  | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 6248 | Value = DAG.getNode(ISD::ZERO_EXTEND, dl, getPointerTy(DAG.getDataLayout()), | 
|  | 6249 | Value); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 6250 | return DAG.getTruncStore(Chain, dl, Value, BasePtr, MVT::i8, MMO); | 
|  | 6251 | } | 
|  | 6252 |  | 
|  | 6253 | // FIXME: Remove this once the ANDI glue bug is fixed: | 
|  | 6254 | SDValue PPCTargetLowering::LowerTRUNCATE(SDValue Op, SelectionDAG &DAG) const { | 
|  | 6255 | assert(Op.getValueType() == MVT::i1 && | 
|  | 6256 | "Custom lowering only for i1 results"); | 
|  | 6257 |  | 
|  | 6258 | SDLoc DL(Op); | 
|  | 6259 | return DAG.getNode(PPCISD::ANDIo_1_GT_BIT, DL, MVT::i1, | 
|  | 6260 | Op.getOperand(0)); | 
|  | 6261 | } | 
|  | 6262 |  | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6263 | /// LowerSELECT_CC - Lower floating point select_cc's into fsel instruction when | 
|  | 6264 | /// possible. | 
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 6265 | SDValue PPCTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const { | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6266 | // Not FP? Not a fsel. | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6267 | if (!Op.getOperand(0).getValueType().isFloatingPoint() || | 
|  | 6268 | !Op.getOperand(2).getValueType().isFloatingPoint()) | 
| Eli Friedman | 5806e18 | 2009-05-28 04:31:08 +0000 | [diff] [blame] | 6269 | return Op; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6270 |  | 
| Hal Finkel | 81f8799 | 2013-04-07 22:11:09 +0000 | [diff] [blame] | 6271 | // We might be able to do better than this under some circumstances, but in | 
|  | 6272 | // general, fsel-based lowering of select is a finite-math-only optimization. | 
|  | 6273 | // For more information, see section F.3 of the 2.06 ISA specification. | 
|  | 6274 | if (!DAG.getTarget().Options.NoInfsFPMath || | 
|  | 6275 | !DAG.getTarget().Options.NoNaNsFPMath) | 
|  | 6276 | return Op; | 
| Sanjay Patel | a260701 | 2015-09-16 16:31:21 +0000 | [diff] [blame] | 6277 | // TODO: Propagate flags from the select rather than global settings. | 
|  | 6278 | SDNodeFlags Flags; | 
|  | 6279 | Flags.setNoInfs(true); | 
|  | 6280 | Flags.setNoNaNs(true); | 
| NAKAMURA Takumi | a9cb538 | 2015-09-22 11:14:39 +0000 | [diff] [blame] | 6281 |  | 
| Hal Finkel | 81f8799 | 2013-04-07 22:11:09 +0000 | [diff] [blame] | 6282 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get(); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6283 |  | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6284 | EVT ResVT = Op.getValueType(); | 
|  | 6285 | EVT CmpVT = Op.getOperand(0).getValueType(); | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6286 | SDValue LHS = Op.getOperand(0), RHS = Op.getOperand(1); | 
|  | 6287 | SDValue TV  = Op.getOperand(2), FV  = Op.getOperand(3); | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6288 | SDLoc dl(Op); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6289 |  | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6290 | // If the RHS of the comparison is a 0.0, we don't need to do the | 
|  | 6291 | // subtraction at all. | 
| Hal Finkel | 81f8799 | 2013-04-07 22:11:09 +0000 | [diff] [blame] | 6292 | SDValue Sel1; | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6293 | if (isFloatingPointZero(RHS)) | 
|  | 6294 | switch (CC) { | 
|  | 6295 | default: break;       // SETUO etc aren't handled by fsel. | 
| Hal Finkel | 81f8799 | 2013-04-07 22:11:09 +0000 | [diff] [blame] | 6296 | case ISD::SETNE: | 
|  | 6297 | std::swap(TV, FV); | 
|  | 6298 | case ISD::SETEQ: | 
|  | 6299 | if (LHS.getValueType() == MVT::f32)   // Comparison is always 64-bits | 
|  | 6300 | LHS = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, LHS); | 
|  | 6301 | Sel1 = DAG.getNode(PPCISD::FSEL, dl, ResVT, LHS, TV, FV); | 
|  | 6302 | if (Sel1.getValueType() == MVT::f32)   // Comparison is always 64-bits | 
|  | 6303 | Sel1 = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, Sel1); | 
|  | 6304 | return DAG.getNode(PPCISD::FSEL, dl, ResVT, | 
|  | 6305 | DAG.getNode(ISD::FNEG, dl, MVT::f64, LHS), Sel1, FV); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6306 | case ISD::SETULT: | 
|  | 6307 | case ISD::SETLT: | 
|  | 6308 | std::swap(TV, FV);  // fsel is natively setge, swap operands for setlt | 
| Chris Lattner | b56d22c | 2006-05-24 00:06:44 +0000 | [diff] [blame] | 6309 | case ISD::SETOGE: | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6310 | case ISD::SETGE: | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6311 | if (LHS.getValueType() == MVT::f32)   // Comparison is always 64-bits | 
|  | 6312 | LHS = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, LHS); | 
| Dale Johannesen | 400dc2e | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 6313 | return DAG.getNode(PPCISD::FSEL, dl, ResVT, LHS, TV, FV); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6314 | case ISD::SETUGT: | 
|  | 6315 | case ISD::SETGT: | 
|  | 6316 | std::swap(TV, FV);  // fsel is natively setge, swap operands for setlt | 
| Chris Lattner | b56d22c | 2006-05-24 00:06:44 +0000 | [diff] [blame] | 6317 | case ISD::SETOLE: | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6318 | case ISD::SETLE: | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6319 | if (LHS.getValueType() == MVT::f32)   // Comparison is always 64-bits | 
|  | 6320 | LHS = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, LHS); | 
| Dale Johannesen | 400dc2e | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 6321 | return DAG.getNode(PPCISD::FSEL, dl, ResVT, | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6322 | DAG.getNode(ISD::FNEG, dl, MVT::f64, LHS), TV, FV); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6323 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6324 |  | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6325 | SDValue Cmp; | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6326 | switch (CC) { | 
|  | 6327 | default: break;       // SETUO etc aren't handled by fsel. | 
| Hal Finkel | 81f8799 | 2013-04-07 22:11:09 +0000 | [diff] [blame] | 6328 | case ISD::SETNE: | 
|  | 6329 | std::swap(TV, FV); | 
|  | 6330 | case ISD::SETEQ: | 
| Sanjay Patel | a260701 | 2015-09-16 16:31:21 +0000 | [diff] [blame] | 6331 | Cmp = DAG.getNode(ISD::FSUB, dl, CmpVT, LHS, RHS, &Flags); | 
| Hal Finkel | 81f8799 | 2013-04-07 22:11:09 +0000 | [diff] [blame] | 6332 | if (Cmp.getValueType() == MVT::f32)   // Comparison is always 64-bits | 
|  | 6333 | Cmp = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, Cmp); | 
|  | 6334 | Sel1 = DAG.getNode(PPCISD::FSEL, dl, ResVT, Cmp, TV, FV); | 
|  | 6335 | if (Sel1.getValueType() == MVT::f32)   // Comparison is always 64-bits | 
|  | 6336 | Sel1 = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, Sel1); | 
|  | 6337 | return DAG.getNode(PPCISD::FSEL, dl, ResVT, | 
|  | 6338 | DAG.getNode(ISD::FNEG, dl, MVT::f64, Cmp), Sel1, FV); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6339 | case ISD::SETULT: | 
|  | 6340 | case ISD::SETLT: | 
| Sanjay Patel | a260701 | 2015-09-16 16:31:21 +0000 | [diff] [blame] | 6341 | Cmp = DAG.getNode(ISD::FSUB, dl, CmpVT, LHS, RHS, &Flags); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6342 | if (Cmp.getValueType() == MVT::f32)   // Comparison is always 64-bits | 
|  | 6343 | Cmp = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, Cmp); | 
| Hal Finkel | 81f8799 | 2013-04-07 22:11:09 +0000 | [diff] [blame] | 6344 | return DAG.getNode(PPCISD::FSEL, dl, ResVT, Cmp, FV, TV); | 
| Chris Lattner | b56d22c | 2006-05-24 00:06:44 +0000 | [diff] [blame] | 6345 | case ISD::SETOGE: | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6346 | case ISD::SETGE: | 
| Sanjay Patel | a260701 | 2015-09-16 16:31:21 +0000 | [diff] [blame] | 6347 | Cmp = DAG.getNode(ISD::FSUB, dl, CmpVT, LHS, RHS, &Flags); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6348 | if (Cmp.getValueType() == MVT::f32)   // Comparison is always 64-bits | 
|  | 6349 | Cmp = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, Cmp); | 
| Hal Finkel | 81f8799 | 2013-04-07 22:11:09 +0000 | [diff] [blame] | 6350 | return DAG.getNode(PPCISD::FSEL, dl, ResVT, Cmp, TV, FV); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6351 | case ISD::SETUGT: | 
|  | 6352 | case ISD::SETGT: | 
| Sanjay Patel | a260701 | 2015-09-16 16:31:21 +0000 | [diff] [blame] | 6353 | Cmp = DAG.getNode(ISD::FSUB, dl, CmpVT, RHS, LHS, &Flags); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6354 | if (Cmp.getValueType() == MVT::f32)   // Comparison is always 64-bits | 
|  | 6355 | Cmp = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, Cmp); | 
| Hal Finkel | 81f8799 | 2013-04-07 22:11:09 +0000 | [diff] [blame] | 6356 | return DAG.getNode(PPCISD::FSEL, dl, ResVT, Cmp, FV, TV); | 
| Chris Lattner | b56d22c | 2006-05-24 00:06:44 +0000 | [diff] [blame] | 6357 | case ISD::SETOLE: | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6358 | case ISD::SETLE: | 
| Sanjay Patel | a260701 | 2015-09-16 16:31:21 +0000 | [diff] [blame] | 6359 | Cmp = DAG.getNode(ISD::FSUB, dl, CmpVT, RHS, LHS, &Flags); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6360 | if (Cmp.getValueType() == MVT::f32)   // Comparison is always 64-bits | 
|  | 6361 | Cmp = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, Cmp); | 
| Hal Finkel | 81f8799 | 2013-04-07 22:11:09 +0000 | [diff] [blame] | 6362 | return DAG.getNode(PPCISD::FSEL, dl, ResVT, Cmp, TV, FV); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6363 | } | 
| Eli Friedman | 5806e18 | 2009-05-28 04:31:08 +0000 | [diff] [blame] | 6364 | return Op; | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6365 | } | 
|  | 6366 |  | 
| Hal Finkel | ed844c4 | 2015-01-06 22:31:02 +0000 | [diff] [blame] | 6367 | void PPCTargetLowering::LowerFP_TO_INTForReuse(SDValue Op, ReuseLoadInfo &RLI, | 
|  | 6368 | SelectionDAG &DAG, | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 6369 | const SDLoc &dl) const { | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6370 | assert(Op.getOperand(0).getValueType().isFloatingPoint()); | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6371 | SDValue Src = Op.getOperand(0); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6372 | if (Src.getValueType() == MVT::f32) | 
|  | 6373 | Src = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, Src); | 
| Duncan Sands | 2a28791 | 2008-07-19 16:26:02 +0000 | [diff] [blame] | 6374 |  | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6375 | SDValue Tmp; | 
| Craig Topper | 5671010 | 2013-08-15 02:33:50 +0000 | [diff] [blame] | 6376 | switch (Op.getSimpleValueType().SimpleTy) { | 
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6377 | default: llvm_unreachable("Unhandled FP_TO_INT type in custom expander!"); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6378 | case MVT::i32: | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 6379 | Tmp = DAG.getNode( | 
|  | 6380 | Op.getOpcode() == ISD::FP_TO_SINT | 
|  | 6381 | ? PPCISD::FCTIWZ | 
|  | 6382 | : (Subtarget.hasFPCVT() ? PPCISD::FCTIWUZ : PPCISD::FCTIDZ), | 
|  | 6383 | dl, MVT::f64, Src); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6384 | break; | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6385 | case MVT::i64: | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 6386 | assert((Op.getOpcode() == ISD::FP_TO_SINT || Subtarget.hasFPCVT()) && | 
| Hal Finkel | 3f88d08 | 2013-04-01 18:42:58 +0000 | [diff] [blame] | 6387 | "i64 FP_TO_UINT is supported only with FPCVT"); | 
| Hal Finkel | f6d45f2 | 2013-04-01 17:52:07 +0000 | [diff] [blame] | 6388 | Tmp = DAG.getNode(Op.getOpcode()==ISD::FP_TO_SINT ? PPCISD::FCTIDZ : | 
|  | 6389 | PPCISD::FCTIDUZ, | 
|  | 6390 | dl, MVT::f64, Src); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6391 | break; | 
|  | 6392 | } | 
| Duncan Sands | 2a28791 | 2008-07-19 16:26:02 +0000 | [diff] [blame] | 6393 |  | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6394 | // Convert the FP value to an int value through memory. | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 6395 | bool i32Stack = Op.getValueType() == MVT::i32 && Subtarget.hasSTFIWX() && | 
|  | 6396 | (Op.getOpcode() == ISD::FP_TO_SINT || Subtarget.hasFPCVT()); | 
| Hal Finkel | f6d45f2 | 2013-04-01 17:52:07 +0000 | [diff] [blame] | 6397 | SDValue FIPtr = DAG.CreateStackTemporary(i32Stack ? MVT::i32 : MVT::f64); | 
|  | 6398 | int FI = cast<FrameIndexSDNode>(FIPtr)->getIndex(); | 
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 6399 | MachinePointerInfo MPI = | 
|  | 6400 | MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FI); | 
| Duncan Sands | 2a28791 | 2008-07-19 16:26:02 +0000 | [diff] [blame] | 6401 |  | 
| Chris Lattner | 06a4954 | 2007-10-15 20:14:52 +0000 | [diff] [blame] | 6402 | // Emit a store to the stack slot. | 
| Hal Finkel | f6d45f2 | 2013-04-01 17:52:07 +0000 | [diff] [blame] | 6403 | SDValue Chain; | 
|  | 6404 | if (i32Stack) { | 
|  | 6405 | MachineFunction &MF = DAG.getMachineFunction(); | 
|  | 6406 | MachineMemOperand *MMO = | 
|  | 6407 | MF.getMachineMemOperand(MPI, MachineMemOperand::MOStore, 4, 4); | 
|  | 6408 | SDValue Ops[] = { DAG.getEntryNode(), Tmp, FIPtr }; | 
|  | 6409 | Chain = DAG.getMemIntrinsicNode(PPCISD::STFIWX, dl, | 
| Craig Topper | 206fcd4 | 2014-04-26 19:29:41 +0000 | [diff] [blame] | 6410 | DAG.getVTList(MVT::Other), Ops, MVT::i32, MMO); | 
| Hal Finkel | f6d45f2 | 2013-04-01 17:52:07 +0000 | [diff] [blame] | 6411 | } else | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 6412 | Chain = DAG.getStore(DAG.getEntryNode(), dl, Tmp, FIPtr, MPI); | 
| Chris Lattner | 06a4954 | 2007-10-15 20:14:52 +0000 | [diff] [blame] | 6413 |  | 
|  | 6414 | // Result is a load from the stack slot.  If loading 4 bytes, make sure to | 
| Nemanja Ivanovic | 1a5706c | 2016-02-29 16:42:27 +0000 | [diff] [blame] | 6415 | // add in a bias on big endian. | 
| Hal Finkel | f6d45f2 | 2013-04-01 17:52:07 +0000 | [diff] [blame] | 6416 | if (Op.getValueType() == MVT::i32 && !i32Stack) { | 
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 6417 | FIPtr = DAG.getNode(ISD::ADD, dl, FIPtr.getValueType(), FIPtr, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6418 | DAG.getConstant(4, dl, FIPtr.getValueType())); | 
| Nemanja Ivanovic | 1a5706c | 2016-02-29 16:42:27 +0000 | [diff] [blame] | 6419 | MPI = MPI.getWithOffset(Subtarget.isLittleEndian() ? 0 : 4); | 
| Hal Finkel | f6d45f2 | 2013-04-01 17:52:07 +0000 | [diff] [blame] | 6420 | } | 
|  | 6421 |  | 
| Hal Finkel | ed844c4 | 2015-01-06 22:31:02 +0000 | [diff] [blame] | 6422 | RLI.Chain = Chain; | 
|  | 6423 | RLI.Ptr = FIPtr; | 
|  | 6424 | RLI.MPI = MPI; | 
|  | 6425 | } | 
|  | 6426 |  | 
| Nemanja Ivanovic | c38b531 | 2015-04-11 10:40:42 +0000 | [diff] [blame] | 6427 | /// \brief Custom lowers floating point to integer conversions to use | 
|  | 6428 | /// the direct move instructions available in ISA 2.07 to avoid the | 
|  | 6429 | /// need for load/store combinations. | 
|  | 6430 | SDValue PPCTargetLowering::LowerFP_TO_INTDirectMove(SDValue Op, | 
|  | 6431 | SelectionDAG &DAG, | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 6432 | const SDLoc &dl) const { | 
| Nemanja Ivanovic | c38b531 | 2015-04-11 10:40:42 +0000 | [diff] [blame] | 6433 | assert(Op.getOperand(0).getValueType().isFloatingPoint()); | 
|  | 6434 | SDValue Src = Op.getOperand(0); | 
|  | 6435 |  | 
|  | 6436 | if (Src.getValueType() == MVT::f32) | 
|  | 6437 | Src = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, Src); | 
|  | 6438 |  | 
|  | 6439 | SDValue Tmp; | 
|  | 6440 | switch (Op.getSimpleValueType().SimpleTy) { | 
|  | 6441 | default: llvm_unreachable("Unhandled FP_TO_INT type in custom expander!"); | 
|  | 6442 | case MVT::i32: | 
|  | 6443 | Tmp = DAG.getNode( | 
|  | 6444 | Op.getOpcode() == ISD::FP_TO_SINT | 
|  | 6445 | ? PPCISD::FCTIWZ | 
|  | 6446 | : (Subtarget.hasFPCVT() ? PPCISD::FCTIWUZ : PPCISD::FCTIDZ), | 
|  | 6447 | dl, MVT::f64, Src); | 
|  | 6448 | Tmp = DAG.getNode(PPCISD::MFVSR, dl, MVT::i32, Tmp); | 
|  | 6449 | break; | 
|  | 6450 | case MVT::i64: | 
|  | 6451 | assert((Op.getOpcode() == ISD::FP_TO_SINT || Subtarget.hasFPCVT()) && | 
|  | 6452 | "i64 FP_TO_UINT is supported only with FPCVT"); | 
|  | 6453 | Tmp = DAG.getNode(Op.getOpcode()==ISD::FP_TO_SINT ? PPCISD::FCTIDZ : | 
|  | 6454 | PPCISD::FCTIDUZ, | 
|  | 6455 | dl, MVT::f64, Src); | 
|  | 6456 | Tmp = DAG.getNode(PPCISD::MFVSR, dl, MVT::i64, Tmp); | 
|  | 6457 | break; | 
|  | 6458 | } | 
|  | 6459 | return Tmp; | 
|  | 6460 | } | 
|  | 6461 |  | 
| Hal Finkel | ed844c4 | 2015-01-06 22:31:02 +0000 | [diff] [blame] | 6462 | SDValue PPCTargetLowering::LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG, | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 6463 | const SDLoc &dl) const { | 
| Nemanja Ivanovic | c38b531 | 2015-04-11 10:40:42 +0000 | [diff] [blame] | 6464 | if (Subtarget.hasDirectMove() && Subtarget.isPPC64()) | 
|  | 6465 | return LowerFP_TO_INTDirectMove(Op, DAG, dl); | 
|  | 6466 |  | 
| Hal Finkel | ed844c4 | 2015-01-06 22:31:02 +0000 | [diff] [blame] | 6467 | ReuseLoadInfo RLI; | 
|  | 6468 | LowerFP_TO_INTForReuse(Op, RLI, DAG, dl); | 
|  | 6469 |  | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 6470 | return DAG.getLoad(Op.getValueType(), dl, RLI.Chain, RLI.Ptr, RLI.MPI, | 
|  | 6471 | RLI.Alignment, | 
|  | 6472 | RLI.IsInvariant ? MachineMemOperand::MOInvariant | 
|  | 6473 | : MachineMemOperand::MONone, | 
|  | 6474 | RLI.AAInfo, RLI.Ranges); | 
| Hal Finkel | ed844c4 | 2015-01-06 22:31:02 +0000 | [diff] [blame] | 6475 | } | 
|  | 6476 |  | 
|  | 6477 | // We're trying to insert a regular store, S, and then a load, L. If the | 
|  | 6478 | // incoming value, O, is a load, we might just be able to have our load use the | 
|  | 6479 | // address used by O. However, we don't know if anything else will store to | 
|  | 6480 | // that address before we can load from it. To prevent this situation, we need | 
|  | 6481 | // to insert our load, L, into the chain as a peer of O. To do this, we give L | 
|  | 6482 | // the same chain operand as O, we create a token factor from the chain results | 
|  | 6483 | // of O and L, and we replace all uses of O's chain result with that token | 
|  | 6484 | // factor (see spliceIntoChain below for this last part). | 
|  | 6485 | bool PPCTargetLowering::canReuseLoadAddress(SDValue Op, EVT MemVT, | 
|  | 6486 | ReuseLoadInfo &RLI, | 
| Hal Finkel | 6c39269 | 2015-01-09 01:34:30 +0000 | [diff] [blame] | 6487 | SelectionDAG &DAG, | 
|  | 6488 | ISD::LoadExtType ET) const { | 
| Hal Finkel | ed844c4 | 2015-01-06 22:31:02 +0000 | [diff] [blame] | 6489 | SDLoc dl(Op); | 
| Hal Finkel | 6c39269 | 2015-01-09 01:34:30 +0000 | [diff] [blame] | 6490 | if (ET == ISD::NON_EXTLOAD && | 
|  | 6491 | (Op.getOpcode() == ISD::FP_TO_UINT || | 
| Hal Finkel | ed844c4 | 2015-01-06 22:31:02 +0000 | [diff] [blame] | 6492 | Op.getOpcode() == ISD::FP_TO_SINT) && | 
|  | 6493 | isOperationLegalOrCustom(Op.getOpcode(), | 
|  | 6494 | Op.getOperand(0).getValueType())) { | 
|  | 6495 |  | 
|  | 6496 | LowerFP_TO_INTForReuse(Op, RLI, DAG, dl); | 
|  | 6497 | return true; | 
|  | 6498 | } | 
|  | 6499 |  | 
|  | 6500 | LoadSDNode *LD = dyn_cast<LoadSDNode>(Op); | 
| Hal Finkel | 6c39269 | 2015-01-09 01:34:30 +0000 | [diff] [blame] | 6501 | if (!LD || LD->getExtensionType() != ET || LD->isVolatile() || | 
|  | 6502 | LD->isNonTemporal()) | 
| Hal Finkel | ed844c4 | 2015-01-06 22:31:02 +0000 | [diff] [blame] | 6503 | return false; | 
|  | 6504 | if (LD->getMemoryVT() != MemVT) | 
|  | 6505 | return false; | 
|  | 6506 |  | 
|  | 6507 | RLI.Ptr = LD->getBasePtr(); | 
| Sanjay Patel | 7506852 | 2016-03-14 18:09:43 +0000 | [diff] [blame] | 6508 | if (LD->isIndexed() && !LD->getOffset().isUndef()) { | 
| Hal Finkel | ed844c4 | 2015-01-06 22:31:02 +0000 | [diff] [blame] | 6509 | assert(LD->getAddressingMode() == ISD::PRE_INC && | 
|  | 6510 | "Non-pre-inc AM on PPC?"); | 
|  | 6511 | RLI.Ptr = DAG.getNode(ISD::ADD, dl, RLI.Ptr.getValueType(), RLI.Ptr, | 
|  | 6512 | LD->getOffset()); | 
|  | 6513 | } | 
|  | 6514 |  | 
|  | 6515 | RLI.Chain = LD->getChain(); | 
|  | 6516 | RLI.MPI = LD->getPointerInfo(); | 
|  | 6517 | RLI.IsInvariant = LD->isInvariant(); | 
|  | 6518 | RLI.Alignment = LD->getAlignment(); | 
|  | 6519 | RLI.AAInfo = LD->getAAInfo(); | 
|  | 6520 | RLI.Ranges = LD->getRanges(); | 
|  | 6521 |  | 
|  | 6522 | RLI.ResChain = SDValue(LD, LD->isIndexed() ? 2 : 1); | 
|  | 6523 | return true; | 
|  | 6524 | } | 
|  | 6525 |  | 
|  | 6526 | // Given the head of the old chain, ResChain, insert a token factor containing | 
|  | 6527 | // it and NewResChain, and make users of ResChain now be users of that token | 
|  | 6528 | // factor. | 
|  | 6529 | void PPCTargetLowering::spliceIntoChain(SDValue ResChain, | 
|  | 6530 | SDValue NewResChain, | 
|  | 6531 | SelectionDAG &DAG) const { | 
|  | 6532 | if (!ResChain) | 
|  | 6533 | return; | 
|  | 6534 |  | 
|  | 6535 | SDLoc dl(NewResChain); | 
|  | 6536 |  | 
|  | 6537 | SDValue TF = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, | 
|  | 6538 | NewResChain, DAG.getUNDEF(MVT::Other)); | 
|  | 6539 | assert(TF.getNode() != NewResChain.getNode() && | 
|  | 6540 | "A new TF really is required here"); | 
|  | 6541 |  | 
|  | 6542 | DAG.ReplaceAllUsesOfValueWith(ResChain, TF); | 
|  | 6543 | DAG.UpdateNodeOperands(TF.getNode(), ResChain, NewResChain); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6544 | } | 
|  | 6545 |  | 
| Ehsan Amiri | 322eca3 | 2016-04-06 20:12:29 +0000 | [diff] [blame] | 6546 | /// \brief Analyze profitability of direct move | 
|  | 6547 | /// prefer float load to int load plus direct move | 
|  | 6548 | /// when there is no integer use of int load | 
|  | 6549 | static bool directMoveIsProfitable(const SDValue &Op) { | 
|  | 6550 | SDNode *Origin = Op.getOperand(0).getNode(); | 
|  | 6551 | if (Origin->getOpcode() != ISD::LOAD) | 
|  | 6552 | return true; | 
|  | 6553 |  | 
|  | 6554 | for (SDNode::use_iterator UI = Origin->use_begin(), | 
|  | 6555 | UE = Origin->use_end(); | 
|  | 6556 | UI != UE; ++UI) { | 
|  | 6557 |  | 
|  | 6558 | // Only look at the users of the loaded value. | 
|  | 6559 | if (UI.getUse().get().getResNo() != 0) | 
|  | 6560 | continue; | 
|  | 6561 |  | 
|  | 6562 | if (UI->getOpcode() != ISD::SINT_TO_FP && | 
|  | 6563 | UI->getOpcode() != ISD::UINT_TO_FP) | 
|  | 6564 | return true; | 
|  | 6565 | } | 
|  | 6566 |  | 
|  | 6567 | return false; | 
|  | 6568 | } | 
|  | 6569 |  | 
| Nemanja Ivanovic | c38b531 | 2015-04-11 10:40:42 +0000 | [diff] [blame] | 6570 | /// \brief Custom lowers integer to floating point conversions to use | 
|  | 6571 | /// the direct move instructions available in ISA 2.07 to avoid the | 
|  | 6572 | /// need for load/store combinations. | 
|  | 6573 | SDValue PPCTargetLowering::LowerINT_TO_FPDirectMove(SDValue Op, | 
|  | 6574 | SelectionDAG &DAG, | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 6575 | const SDLoc &dl) const { | 
| Nemanja Ivanovic | c38b531 | 2015-04-11 10:40:42 +0000 | [diff] [blame] | 6576 | assert((Op.getValueType() == MVT::f32 || | 
|  | 6577 | Op.getValueType() == MVT::f64) && | 
|  | 6578 | "Invalid floating point type as target of conversion"); | 
|  | 6579 | assert(Subtarget.hasFPCVT() && | 
|  | 6580 | "Int to FP conversions with direct moves require FPCVT"); | 
|  | 6581 | SDValue FP; | 
|  | 6582 | SDValue Src = Op.getOperand(0); | 
|  | 6583 | bool SinglePrec = Op.getValueType() == MVT::f32; | 
|  | 6584 | bool WordInt = Src.getSimpleValueType().SimpleTy == MVT::i32; | 
|  | 6585 | bool Signed = Op.getOpcode() == ISD::SINT_TO_FP; | 
|  | 6586 | unsigned ConvOp = Signed ? (SinglePrec ? PPCISD::FCFIDS : PPCISD::FCFID) : | 
|  | 6587 | (SinglePrec ? PPCISD::FCFIDUS : PPCISD::FCFIDU); | 
|  | 6588 |  | 
|  | 6589 | if (WordInt) { | 
|  | 6590 | FP = DAG.getNode(Signed ? PPCISD::MTVSRA : PPCISD::MTVSRZ, | 
|  | 6591 | dl, MVT::f64, Src); | 
|  | 6592 | FP = DAG.getNode(ConvOp, dl, SinglePrec ? MVT::f32 : MVT::f64, FP); | 
|  | 6593 | } | 
|  | 6594 | else { | 
|  | 6595 | FP = DAG.getNode(PPCISD::MTVSRA, dl, MVT::f64, Src); | 
|  | 6596 | FP = DAG.getNode(ConvOp, dl, SinglePrec ? MVT::f32 : MVT::f64, FP); | 
|  | 6597 | } | 
|  | 6598 |  | 
|  | 6599 | return FP; | 
|  | 6600 | } | 
|  | 6601 |  | 
| Hal Finkel | f6d45f2 | 2013-04-01 17:52:07 +0000 | [diff] [blame] | 6602 | SDValue PPCTargetLowering::LowerINT_TO_FP(SDValue Op, | 
| Hal Finkel | ed844c4 | 2015-01-06 22:31:02 +0000 | [diff] [blame] | 6603 | SelectionDAG &DAG) const { | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6604 | SDLoc dl(Op); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 6605 |  | 
|  | 6606 | if (Subtarget.hasQPX() && Op.getOperand(0).getValueType() == MVT::v4i1) { | 
|  | 6607 | if (Op.getValueType() != MVT::v4f32 && Op.getValueType() != MVT::v4f64) | 
|  | 6608 | return SDValue(); | 
|  | 6609 |  | 
|  | 6610 | SDValue Value = Op.getOperand(0); | 
|  | 6611 | // The values are now known to be -1 (false) or 1 (true). To convert this | 
|  | 6612 | // into 0 (false) and 1 (true), add 1 and then divide by 2 (multiply by 0.5). | 
|  | 6613 | // This can be done with an fma and the 0.5 constant: (V+1.0)*0.5 = 0.5*V+0.5 | 
|  | 6614 | Value = DAG.getNode(PPCISD::QBFLT, dl, MVT::v4f64, Value); | 
| NAKAMURA Takumi | a9cb538 | 2015-09-22 11:14:39 +0000 | [diff] [blame] | 6615 |  | 
| Ahmed Bougacha | 93cff7f | 2016-02-15 18:07:29 +0000 | [diff] [blame] | 6616 | SDValue FPHalfs = DAG.getConstantFP(0.5, dl, MVT::v4f64); | 
| NAKAMURA Takumi | 70ad98a | 2015-09-22 11:13:55 +0000 | [diff] [blame] | 6617 |  | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 6618 | Value = DAG.getNode(ISD::FMA, dl, MVT::v4f64, Value, FPHalfs, FPHalfs); | 
|  | 6619 |  | 
|  | 6620 | if (Op.getValueType() != MVT::v4f64) | 
|  | 6621 | Value = DAG.getNode(ISD::FP_ROUND, dl, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6622 | Op.getValueType(), Value, | 
|  | 6623 | DAG.getIntPtrConstant(1, dl)); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 6624 | return Value; | 
|  | 6625 | } | 
|  | 6626 |  | 
| Dan Gohman | d6819da | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 6627 | // Don't handle ppc_fp128 here; let it be lowered to a libcall. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6628 | if (Op.getValueType() != MVT::f32 && Op.getValueType() != MVT::f64) | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6629 | return SDValue(); | 
| Dan Gohman | d6819da | 2008-03-11 01:59:03 +0000 | [diff] [blame] | 6630 |  | 
| Hal Finkel | 6a56b21 | 2014-03-05 22:14:00 +0000 | [diff] [blame] | 6631 | if (Op.getOperand(0).getValueType() == MVT::i1) | 
|  | 6632 | return DAG.getNode(ISD::SELECT, dl, Op.getValueType(), Op.getOperand(0), | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6633 | DAG.getConstantFP(1.0, dl, Op.getValueType()), | 
|  | 6634 | DAG.getConstantFP(0.0, dl, Op.getValueType())); | 
| Hal Finkel | 6a56b21 | 2014-03-05 22:14:00 +0000 | [diff] [blame] | 6635 |  | 
| Nemanja Ivanovic | c38b531 | 2015-04-11 10:40:42 +0000 | [diff] [blame] | 6636 | // If we have direct moves, we can do all the conversion, skip the store/load | 
|  | 6637 | // however, without FPCVT we can't do most conversions. | 
| Ehsan Amiri | 322eca3 | 2016-04-06 20:12:29 +0000 | [diff] [blame] | 6638 | if (Subtarget.hasDirectMove() && directMoveIsProfitable(Op) && | 
|  | 6639 | Subtarget.isPPC64() && Subtarget.hasFPCVT()) | 
| Nemanja Ivanovic | c38b531 | 2015-04-11 10:40:42 +0000 | [diff] [blame] | 6640 | return LowerINT_TO_FPDirectMove(Op, DAG, dl); | 
|  | 6641 |  | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 6642 | assert((Op.getOpcode() == ISD::SINT_TO_FP || Subtarget.hasFPCVT()) && | 
| Hal Finkel | f6d45f2 | 2013-04-01 17:52:07 +0000 | [diff] [blame] | 6643 | "UINT_TO_FP is supported only with FPCVT"); | 
|  | 6644 |  | 
|  | 6645 | // If we have FCFIDS, then use it when converting to single-precision. | 
| Hal Finkel | 93d75ea | 2013-04-02 03:29:51 +0000 | [diff] [blame] | 6646 | // Otherwise, convert to double-precision and then round. | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 6647 | unsigned FCFOp = (Subtarget.hasFPCVT() && Op.getValueType() == MVT::f32) | 
|  | 6648 | ? (Op.getOpcode() == ISD::UINT_TO_FP ? PPCISD::FCFIDUS | 
|  | 6649 | : PPCISD::FCFIDS) | 
|  | 6650 | : (Op.getOpcode() == ISD::UINT_TO_FP ? PPCISD::FCFIDU | 
|  | 6651 | : PPCISD::FCFID); | 
|  | 6652 | MVT FCFTy = (Subtarget.hasFPCVT() && Op.getValueType() == MVT::f32) | 
|  | 6653 | ? MVT::f32 | 
|  | 6654 | : MVT::f64; | 
| Hal Finkel | f6d45f2 | 2013-04-01 17:52:07 +0000 | [diff] [blame] | 6655 |  | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6656 | if (Op.getOperand(0).getValueType() == MVT::i64) { | 
| Ulrich Weigand | d34b5bd | 2012-10-18 13:16:11 +0000 | [diff] [blame] | 6657 | SDValue SINT = Op.getOperand(0); | 
|  | 6658 | // When converting to single-precision, we actually need to convert | 
|  | 6659 | // to double-precision first and then round to single-precision. | 
|  | 6660 | // To avoid double-rounding effects during that operation, we have | 
|  | 6661 | // to prepare the input operand.  Bits that might be truncated when | 
|  | 6662 | // converting to double-precision are replaced by a bit that won't | 
|  | 6663 | // be lost at this stage, but is below the single-precision rounding | 
|  | 6664 | // position. | 
|  | 6665 | // | 
|  | 6666 | // However, if -enable-unsafe-fp-math is in effect, accept double | 
|  | 6667 | // rounding to avoid the extra overhead. | 
|  | 6668 | if (Op.getValueType() == MVT::f32 && | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 6669 | !Subtarget.hasFPCVT() && | 
| Ulrich Weigand | d34b5bd | 2012-10-18 13:16:11 +0000 | [diff] [blame] | 6670 | !DAG.getTarget().Options.UnsafeFPMath) { | 
|  | 6671 |  | 
|  | 6672 | // Twiddle input to make sure the low 11 bits are zero.  (If this | 
|  | 6673 | // is the case, we are guaranteed the value will fit into the 53 bit | 
|  | 6674 | // mantissa of an IEEE double-precision value without rounding.) | 
|  | 6675 | // If any of those low 11 bits were not zero originally, make sure | 
|  | 6676 | // bit 12 (value 2048) is set instead, so that the final rounding | 
|  | 6677 | // to single-precision gets the correct result. | 
|  | 6678 | SDValue Round = DAG.getNode(ISD::AND, dl, MVT::i64, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6679 | SINT, DAG.getConstant(2047, dl, MVT::i64)); | 
| Ulrich Weigand | d34b5bd | 2012-10-18 13:16:11 +0000 | [diff] [blame] | 6680 | Round = DAG.getNode(ISD::ADD, dl, MVT::i64, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6681 | Round, DAG.getConstant(2047, dl, MVT::i64)); | 
| Ulrich Weigand | d34b5bd | 2012-10-18 13:16:11 +0000 | [diff] [blame] | 6682 | Round = DAG.getNode(ISD::OR, dl, MVT::i64, Round, SINT); | 
|  | 6683 | Round = DAG.getNode(ISD::AND, dl, MVT::i64, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6684 | Round, DAG.getConstant(-2048, dl, MVT::i64)); | 
| Ulrich Weigand | d34b5bd | 2012-10-18 13:16:11 +0000 | [diff] [blame] | 6685 |  | 
|  | 6686 | // However, we cannot use that value unconditionally: if the magnitude | 
|  | 6687 | // of the input value is small, the bit-twiddling we did above might | 
|  | 6688 | // end up visibly changing the output.  Fortunately, in that case, we | 
|  | 6689 | // don't need to twiddle bits since the original input will convert | 
|  | 6690 | // exactly to double-precision floating-point already.  Therefore, | 
|  | 6691 | // construct a conditional to use the original value if the top 11 | 
|  | 6692 | // bits are all sign-bit copies, and use the rounded value computed | 
|  | 6693 | // above otherwise. | 
|  | 6694 | SDValue Cond = DAG.getNode(ISD::SRA, dl, MVT::i64, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6695 | SINT, DAG.getConstant(53, dl, MVT::i32)); | 
| Ulrich Weigand | d34b5bd | 2012-10-18 13:16:11 +0000 | [diff] [blame] | 6696 | Cond = DAG.getNode(ISD::ADD, dl, MVT::i64, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6697 | Cond, DAG.getConstant(1, dl, MVT::i64)); | 
| Ulrich Weigand | d34b5bd | 2012-10-18 13:16:11 +0000 | [diff] [blame] | 6698 | Cond = DAG.getSetCC(dl, MVT::i32, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6699 | Cond, DAG.getConstant(1, dl, MVT::i64), ISD::SETUGT); | 
| Ulrich Weigand | d34b5bd | 2012-10-18 13:16:11 +0000 | [diff] [blame] | 6700 |  | 
|  | 6701 | SINT = DAG.getNode(ISD::SELECT, dl, MVT::i64, Cond, Round, SINT); | 
|  | 6702 | } | 
| Hal Finkel | f6d45f2 | 2013-04-01 17:52:07 +0000 | [diff] [blame] | 6703 |  | 
| Hal Finkel | ed844c4 | 2015-01-06 22:31:02 +0000 | [diff] [blame] | 6704 | ReuseLoadInfo RLI; | 
|  | 6705 | SDValue Bits; | 
|  | 6706 |  | 
| Hal Finkel | 6c39269 | 2015-01-09 01:34:30 +0000 | [diff] [blame] | 6707 | MachineFunction &MF = DAG.getMachineFunction(); | 
| Hal Finkel | ed844c4 | 2015-01-06 22:31:02 +0000 | [diff] [blame] | 6708 | if (canReuseLoadAddress(SINT, MVT::i64, RLI, DAG)) { | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 6709 | Bits = | 
|  | 6710 | DAG.getLoad(MVT::f64, dl, RLI.Chain, RLI.Ptr, RLI.MPI, RLI.Alignment, | 
|  | 6711 | RLI.IsInvariant ? MachineMemOperand::MOInvariant | 
|  | 6712 | : MachineMemOperand::MONone, | 
|  | 6713 | RLI.AAInfo, RLI.Ranges); | 
| Hal Finkel | ed844c4 | 2015-01-06 22:31:02 +0000 | [diff] [blame] | 6714 | spliceIntoChain(RLI.ResChain, Bits.getValue(1), DAG); | 
| Hal Finkel | 6c39269 | 2015-01-09 01:34:30 +0000 | [diff] [blame] | 6715 | } else if (Subtarget.hasLFIWAX() && | 
|  | 6716 | canReuseLoadAddress(SINT, MVT::i32, RLI, DAG, ISD::SEXTLOAD)) { | 
|  | 6717 | MachineMemOperand *MMO = | 
|  | 6718 | MF.getMachineMemOperand(RLI.MPI, MachineMemOperand::MOLoad, 4, | 
|  | 6719 | RLI.Alignment, RLI.AAInfo, RLI.Ranges); | 
|  | 6720 | SDValue Ops[] = { RLI.Chain, RLI.Ptr }; | 
|  | 6721 | Bits = DAG.getMemIntrinsicNode(PPCISD::LFIWAX, dl, | 
|  | 6722 | DAG.getVTList(MVT::f64, MVT::Other), | 
|  | 6723 | Ops, MVT::i32, MMO); | 
|  | 6724 | spliceIntoChain(RLI.ResChain, Bits.getValue(1), DAG); | 
|  | 6725 | } else if (Subtarget.hasFPCVT() && | 
|  | 6726 | canReuseLoadAddress(SINT, MVT::i32, RLI, DAG, ISD::ZEXTLOAD)) { | 
|  | 6727 | MachineMemOperand *MMO = | 
|  | 6728 | MF.getMachineMemOperand(RLI.MPI, MachineMemOperand::MOLoad, 4, | 
|  | 6729 | RLI.Alignment, RLI.AAInfo, RLI.Ranges); | 
|  | 6730 | SDValue Ops[] = { RLI.Chain, RLI.Ptr }; | 
|  | 6731 | Bits = DAG.getMemIntrinsicNode(PPCISD::LFIWZX, dl, | 
|  | 6732 | DAG.getVTList(MVT::f64, MVT::Other), | 
|  | 6733 | Ops, MVT::i32, MMO); | 
|  | 6734 | spliceIntoChain(RLI.ResChain, Bits.getValue(1), DAG); | 
|  | 6735 | } else if (((Subtarget.hasLFIWAX() && | 
|  | 6736 | SINT.getOpcode() == ISD::SIGN_EXTEND) || | 
|  | 6737 | (Subtarget.hasFPCVT() && | 
|  | 6738 | SINT.getOpcode() == ISD::ZERO_EXTEND)) && | 
|  | 6739 | SINT.getOperand(0).getValueType() == MVT::i32) { | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 6740 | MachineFrameInfo &MFI = MF.getFrameInfo(); | 
| Eric Christopher | cd71946 | 2016-07-07 01:49:59 +0000 | [diff] [blame] | 6741 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); | 
| Hal Finkel | 6c39269 | 2015-01-09 01:34:30 +0000 | [diff] [blame] | 6742 |  | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 6743 | int FrameIdx = MFI.CreateStackObject(4, 4, false); | 
| Hal Finkel | 6c39269 | 2015-01-09 01:34:30 +0000 | [diff] [blame] | 6744 | SDValue FIdx = DAG.getFrameIndex(FrameIdx, PtrVT); | 
|  | 6745 |  | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 6746 | SDValue Store = | 
|  | 6747 | DAG.getStore(DAG.getEntryNode(), dl, SINT.getOperand(0), FIdx, | 
|  | 6748 | MachinePointerInfo::getFixedStack( | 
|  | 6749 | DAG.getMachineFunction(), FrameIdx)); | 
| Hal Finkel | 6c39269 | 2015-01-09 01:34:30 +0000 | [diff] [blame] | 6750 |  | 
|  | 6751 | assert(cast<StoreSDNode>(Store)->getMemoryVT() == MVT::i32 && | 
|  | 6752 | "Expected an i32 store"); | 
|  | 6753 |  | 
|  | 6754 | RLI.Ptr = FIdx; | 
|  | 6755 | RLI.Chain = Store; | 
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 6756 | RLI.MPI = | 
|  | 6757 | MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FrameIdx); | 
| Hal Finkel | 6c39269 | 2015-01-09 01:34:30 +0000 | [diff] [blame] | 6758 | RLI.Alignment = 4; | 
|  | 6759 |  | 
|  | 6760 | MachineMemOperand *MMO = | 
|  | 6761 | MF.getMachineMemOperand(RLI.MPI, MachineMemOperand::MOLoad, 4, | 
|  | 6762 | RLI.Alignment, RLI.AAInfo, RLI.Ranges); | 
|  | 6763 | SDValue Ops[] = { RLI.Chain, RLI.Ptr }; | 
|  | 6764 | Bits = DAG.getMemIntrinsicNode(SINT.getOpcode() == ISD::ZERO_EXTEND ? | 
|  | 6765 | PPCISD::LFIWZX : PPCISD::LFIWAX, | 
|  | 6766 | dl, DAG.getVTList(MVT::f64, MVT::Other), | 
|  | 6767 | Ops, MVT::i32, MMO); | 
| Hal Finkel | ed844c4 | 2015-01-06 22:31:02 +0000 | [diff] [blame] | 6768 | } else | 
|  | 6769 | Bits = DAG.getNode(ISD::BITCAST, dl, MVT::f64, SINT); | 
|  | 6770 |  | 
| Hal Finkel | f6d45f2 | 2013-04-01 17:52:07 +0000 | [diff] [blame] | 6771 | SDValue FP = DAG.getNode(FCFOp, dl, FCFTy, Bits); | 
|  | 6772 |  | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 6773 | if (Op.getValueType() == MVT::f32 && !Subtarget.hasFPCVT()) | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6774 | FP = DAG.getNode(ISD::FP_ROUND, dl, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6775 | MVT::f32, FP, DAG.getIntPtrConstant(0, dl)); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6776 | return FP; | 
|  | 6777 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6778 |  | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6779 | assert(Op.getOperand(0).getValueType() == MVT::i32 && | 
| Hal Finkel | f6d45f2 | 2013-04-01 17:52:07 +0000 | [diff] [blame] | 6780 | "Unhandled INT_TO_FP type in custom expander!"); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6781 | // Since we only generate this in 64-bit mode, we can take advantage of | 
|  | 6782 | // 64-bit registers.  In particular, sign extend the input value into the | 
|  | 6783 | // 64-bit register with extsw, store the WHOLE 64-bit value into the stack | 
|  | 6784 | // then lfd it and fcfid it. | 
| Dan Gohman | 48b185d | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 6785 | MachineFunction &MF = DAG.getMachineFunction(); | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 6786 | MachineFrameInfo &MFI = MF.getFrameInfo(); | 
| Eric Christopher | cd71946 | 2016-07-07 01:49:59 +0000 | [diff] [blame] | 6787 | EVT PtrVT = getPointerTy(MF.getDataLayout()); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6788 |  | 
| Hal Finkel | beb296b | 2013-03-31 10:12:51 +0000 | [diff] [blame] | 6789 | SDValue Ld; | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 6790 | if (Subtarget.hasLFIWAX() || Subtarget.hasFPCVT()) { | 
| Hal Finkel | ed844c4 | 2015-01-06 22:31:02 +0000 | [diff] [blame] | 6791 | ReuseLoadInfo RLI; | 
|  | 6792 | bool ReusingLoad; | 
|  | 6793 | if (!(ReusingLoad = canReuseLoadAddress(Op.getOperand(0), MVT::i32, RLI, | 
|  | 6794 | DAG))) { | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 6795 | int FrameIdx = MFI.CreateStackObject(4, 4, false); | 
| Hal Finkel | ed844c4 | 2015-01-06 22:31:02 +0000 | [diff] [blame] | 6796 | SDValue FIdx = DAG.getFrameIndex(FrameIdx, PtrVT); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6797 |  | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 6798 | SDValue Store = | 
|  | 6799 | DAG.getStore(DAG.getEntryNode(), dl, Op.getOperand(0), FIdx, | 
|  | 6800 | MachinePointerInfo::getFixedStack( | 
|  | 6801 | DAG.getMachineFunction(), FrameIdx)); | 
| Hal Finkel | e53429a | 2013-03-31 01:58:02 +0000 | [diff] [blame] | 6802 |  | 
| Hal Finkel | ed844c4 | 2015-01-06 22:31:02 +0000 | [diff] [blame] | 6803 | assert(cast<StoreSDNode>(Store)->getMemoryVT() == MVT::i32 && | 
|  | 6804 | "Expected an i32 store"); | 
|  | 6805 |  | 
|  | 6806 | RLI.Ptr = FIdx; | 
|  | 6807 | RLI.Chain = Store; | 
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 6808 | RLI.MPI = | 
|  | 6809 | MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FrameIdx); | 
| Hal Finkel | ed844c4 | 2015-01-06 22:31:02 +0000 | [diff] [blame] | 6810 | RLI.Alignment = 4; | 
|  | 6811 | } | 
|  | 6812 |  | 
| Hal Finkel | beb296b | 2013-03-31 10:12:51 +0000 | [diff] [blame] | 6813 | MachineMemOperand *MMO = | 
| Hal Finkel | ed844c4 | 2015-01-06 22:31:02 +0000 | [diff] [blame] | 6814 | MF.getMachineMemOperand(RLI.MPI, MachineMemOperand::MOLoad, 4, | 
|  | 6815 | RLI.Alignment, RLI.AAInfo, RLI.Ranges); | 
|  | 6816 | SDValue Ops[] = { RLI.Chain, RLI.Ptr }; | 
| Hal Finkel | f6d45f2 | 2013-04-01 17:52:07 +0000 | [diff] [blame] | 6817 | Ld = DAG.getMemIntrinsicNode(Op.getOpcode() == ISD::UINT_TO_FP ? | 
|  | 6818 | PPCISD::LFIWZX : PPCISD::LFIWAX, | 
|  | 6819 | dl, DAG.getVTList(MVT::f64, MVT::Other), | 
| Craig Topper | 206fcd4 | 2014-04-26 19:29:41 +0000 | [diff] [blame] | 6820 | Ops, MVT::i32, MMO); | 
| Hal Finkel | ed844c4 | 2015-01-06 22:31:02 +0000 | [diff] [blame] | 6821 | if (ReusingLoad) | 
|  | 6822 | spliceIntoChain(RLI.ResChain, Ld.getValue(1), DAG); | 
| Hal Finkel | beb296b | 2013-03-31 10:12:51 +0000 | [diff] [blame] | 6823 | } else { | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 6824 | assert(Subtarget.isPPC64() && | 
| Hal Finkel | f6d45f2 | 2013-04-01 17:52:07 +0000 | [diff] [blame] | 6825 | "i32->FP without LFIWAX supported only on PPC64"); | 
|  | 6826 |  | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 6827 | int FrameIdx = MFI.CreateStackObject(8, 8, false); | 
| Hal Finkel | beb296b | 2013-03-31 10:12:51 +0000 | [diff] [blame] | 6828 | SDValue FIdx = DAG.getFrameIndex(FrameIdx, PtrVT); | 
|  | 6829 |  | 
|  | 6830 | SDValue Ext64 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i64, | 
|  | 6831 | Op.getOperand(0)); | 
|  | 6832 |  | 
|  | 6833 | // STD the extended value into the stack slot. | 
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 6834 | SDValue Store = DAG.getStore( | 
|  | 6835 | DAG.getEntryNode(), dl, Ext64, FIdx, | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 6836 | MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FrameIdx)); | 
| Hal Finkel | beb296b | 2013-03-31 10:12:51 +0000 | [diff] [blame] | 6837 |  | 
|  | 6838 | // Load the value as a double. | 
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 6839 | Ld = DAG.getLoad( | 
|  | 6840 | MVT::f64, dl, Store, FIdx, | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 6841 | MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FrameIdx)); | 
| Hal Finkel | beb296b | 2013-03-31 10:12:51 +0000 | [diff] [blame] | 6842 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6843 |  | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6844 | // FCFID it and return it. | 
| Hal Finkel | f6d45f2 | 2013-04-01 17:52:07 +0000 | [diff] [blame] | 6845 | SDValue FP = DAG.getNode(FCFOp, dl, FCFTy, Ld); | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 6846 | if (Op.getValueType() == MVT::f32 && !Subtarget.hasFPCVT()) | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6847 | FP = DAG.getNode(ISD::FP_ROUND, dl, MVT::f32, FP, | 
|  | 6848 | DAG.getIntPtrConstant(0, dl)); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6849 | return FP; | 
|  | 6850 | } | 
|  | 6851 |  | 
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 6852 | SDValue PPCTargetLowering::LowerFLT_ROUNDS_(SDValue Op, | 
|  | 6853 | SelectionDAG &DAG) const { | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6854 | SDLoc dl(Op); | 
| Dale Johannesen | 5c94cb3 | 2008-01-18 19:55:37 +0000 | [diff] [blame] | 6855 | /* | 
|  | 6856 | The rounding mode is in bits 30:31 of FPSR, and has the following | 
|  | 6857 | settings: | 
|  | 6858 | 00 Round to nearest | 
|  | 6859 | 01 Round to 0 | 
|  | 6860 | 10 Round to +inf | 
|  | 6861 | 11 Round to -inf | 
|  | 6862 |  | 
|  | 6863 | FLT_ROUNDS, on the other hand, expects the following: | 
|  | 6864 | -1 Undefined | 
|  | 6865 | 0 Round to 0 | 
|  | 6866 | 1 Round to nearest | 
|  | 6867 | 2 Round to +inf | 
|  | 6868 | 3 Round to -inf | 
|  | 6869 |  | 
|  | 6870 | To perform the conversion, we do: | 
|  | 6871 | ((FPSCR & 0x3) ^ ((~FPSCR & 0x3) >> 1)) | 
|  | 6872 | */ | 
|  | 6873 |  | 
|  | 6874 | MachineFunction &MF = DAG.getMachineFunction(); | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6875 | EVT VT = Op.getValueType(); | 
| Eric Christopher | cd71946 | 2016-07-07 01:49:59 +0000 | [diff] [blame] | 6876 | EVT PtrVT = getPointerTy(MF.getDataLayout()); | 
| Dale Johannesen | 5c94cb3 | 2008-01-18 19:55:37 +0000 | [diff] [blame] | 6877 |  | 
|  | 6878 | // Save FP Control Word to register | 
| Benjamin Kramer | fdf362b | 2013-03-07 20:33:29 +0000 | [diff] [blame] | 6879 | EVT NodeTys[] = { | 
|  | 6880 | MVT::f64,    // return register | 
|  | 6881 | MVT::Glue    // unused in this context | 
|  | 6882 | }; | 
| Craig Topper | 2d2aa0c | 2014-04-30 07:17:30 +0000 | [diff] [blame] | 6883 | SDValue Chain = DAG.getNode(PPCISD::MFFS, dl, NodeTys, None); | 
| Dale Johannesen | 5c94cb3 | 2008-01-18 19:55:37 +0000 | [diff] [blame] | 6884 |  | 
|  | 6885 | // Save FP register to stack slot | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 6886 | int SSFI = MF.getFrameInfo().CreateStackObject(8, 8, false); | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6887 | SDValue StackSlot = DAG.getFrameIndex(SSFI, PtrVT); | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 6888 | SDValue Store = DAG.getStore(DAG.getEntryNode(), dl, Chain, StackSlot, | 
|  | 6889 | MachinePointerInfo()); | 
| Dale Johannesen | 5c94cb3 | 2008-01-18 19:55:37 +0000 | [diff] [blame] | 6890 |  | 
|  | 6891 | // Load FP Control Word from low 32 bits of stack slot. | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6892 | SDValue Four = DAG.getConstant(4, dl, PtrVT); | 
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 6893 | SDValue Addr = DAG.getNode(ISD::ADD, dl, PtrVT, StackSlot, Four); | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 6894 | SDValue CWD = DAG.getLoad(MVT::i32, dl, Store, Addr, MachinePointerInfo()); | 
| Dale Johannesen | 5c94cb3 | 2008-01-18 19:55:37 +0000 | [diff] [blame] | 6895 |  | 
|  | 6896 | // Transform as necessary | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6897 | SDValue CWD1 = | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6898 | DAG.getNode(ISD::AND, dl, MVT::i32, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6899 | CWD, DAG.getConstant(3, dl, MVT::i32)); | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6900 | SDValue CWD2 = | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6901 | DAG.getNode(ISD::SRL, dl, MVT::i32, | 
|  | 6902 | DAG.getNode(ISD::AND, dl, MVT::i32, | 
|  | 6903 | DAG.getNode(ISD::XOR, dl, MVT::i32, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6904 | CWD, DAG.getConstant(3, dl, MVT::i32)), | 
|  | 6905 | DAG.getConstant(3, dl, MVT::i32)), | 
|  | 6906 | DAG.getConstant(1, dl, MVT::i32)); | 
| Dale Johannesen | 5c94cb3 | 2008-01-18 19:55:37 +0000 | [diff] [blame] | 6907 |  | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6908 | SDValue RetVal = | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6909 | DAG.getNode(ISD::XOR, dl, MVT::i32, CWD1, CWD2); | 
| Dale Johannesen | 5c94cb3 | 2008-01-18 19:55:37 +0000 | [diff] [blame] | 6910 |  | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6911 | return DAG.getNode((VT.getSizeInBits() < 16 ? | 
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 6912 | ISD::TRUNCATE : ISD::ZERO_EXTEND), dl, VT, RetVal); | 
| Dale Johannesen | 5c94cb3 | 2008-01-18 19:55:37 +0000 | [diff] [blame] | 6913 | } | 
|  | 6914 |  | 
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 6915 | SDValue PPCTargetLowering::LowerSHL_PARTS(SDValue Op, SelectionDAG &DAG) const { | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6916 | EVT VT = Op.getValueType(); | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6917 | unsigned BitWidth = VT.getSizeInBits(); | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6918 | SDLoc dl(Op); | 
| Dan Gohman | 8d2ead2 | 2008-03-07 20:36:53 +0000 | [diff] [blame] | 6919 | assert(Op.getNumOperands() == 3 && | 
|  | 6920 | VT == Op.getOperand(1).getValueType() && | 
|  | 6921 | "Unexpected SHL!"); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6922 |  | 
| Chris Lattner | 601b865 | 2006-09-20 03:47:40 +0000 | [diff] [blame] | 6923 | // Expand into a bunch of logical ops.  Note that these ops | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6924 | // depend on the PPC behavior for oversized shift amounts. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6925 | SDValue Lo = Op.getOperand(0); | 
|  | 6926 | SDValue Hi = Op.getOperand(1); | 
|  | 6927 | SDValue Amt = Op.getOperand(2); | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6928 | EVT AmtVT = Amt.getValueType(); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6929 |  | 
| Dale Johannesen | 7ae8c8b | 2009-02-05 00:20:09 +0000 | [diff] [blame] | 6930 | SDValue Tmp1 = DAG.getNode(ISD::SUB, dl, AmtVT, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6931 | DAG.getConstant(BitWidth, dl, AmtVT), Amt); | 
| Dale Johannesen | 7ae8c8b | 2009-02-05 00:20:09 +0000 | [diff] [blame] | 6932 | SDValue Tmp2 = DAG.getNode(PPCISD::SHL, dl, VT, Hi, Amt); | 
|  | 6933 | SDValue Tmp3 = DAG.getNode(PPCISD::SRL, dl, VT, Lo, Tmp1); | 
|  | 6934 | SDValue Tmp4 = DAG.getNode(ISD::OR , dl, VT, Tmp2, Tmp3); | 
|  | 6935 | SDValue Tmp5 = DAG.getNode(ISD::ADD, dl, AmtVT, Amt, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6936 | DAG.getConstant(-BitWidth, dl, AmtVT)); | 
| Dale Johannesen | 7ae8c8b | 2009-02-05 00:20:09 +0000 | [diff] [blame] | 6937 | SDValue Tmp6 = DAG.getNode(PPCISD::SHL, dl, VT, Lo, Tmp5); | 
|  | 6938 | SDValue OutHi = DAG.getNode(ISD::OR, dl, VT, Tmp4, Tmp6); | 
|  | 6939 | SDValue OutLo = DAG.getNode(PPCISD::SHL, dl, VT, Lo, Amt); | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6940 | SDValue OutOps[] = { OutLo, OutHi }; | 
| Craig Topper | 64941d9 | 2014-04-27 19:20:57 +0000 | [diff] [blame] | 6941 | return DAG.getMergeValues(OutOps, dl); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6942 | } | 
|  | 6943 |  | 
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 6944 | SDValue PPCTargetLowering::LowerSRL_PARTS(SDValue Op, SelectionDAG &DAG) const { | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6945 | EVT VT = Op.getValueType(); | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6946 | SDLoc dl(Op); | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6947 | unsigned BitWidth = VT.getSizeInBits(); | 
| Dan Gohman | 8d2ead2 | 2008-03-07 20:36:53 +0000 | [diff] [blame] | 6948 | assert(Op.getNumOperands() == 3 && | 
|  | 6949 | VT == Op.getOperand(1).getValueType() && | 
|  | 6950 | "Unexpected SRL!"); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6951 |  | 
| Dan Gohman | 8d2ead2 | 2008-03-07 20:36:53 +0000 | [diff] [blame] | 6952 | // Expand into a bunch of logical ops.  Note that these ops | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6953 | // depend on the PPC behavior for oversized shift amounts. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6954 | SDValue Lo = Op.getOperand(0); | 
|  | 6955 | SDValue Hi = Op.getOperand(1); | 
|  | 6956 | SDValue Amt = Op.getOperand(2); | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6957 | EVT AmtVT = Amt.getValueType(); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6958 |  | 
| Dale Johannesen | 7ae8c8b | 2009-02-05 00:20:09 +0000 | [diff] [blame] | 6959 | SDValue Tmp1 = DAG.getNode(ISD::SUB, dl, AmtVT, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6960 | DAG.getConstant(BitWidth, dl, AmtVT), Amt); | 
| Dale Johannesen | 7ae8c8b | 2009-02-05 00:20:09 +0000 | [diff] [blame] | 6961 | SDValue Tmp2 = DAG.getNode(PPCISD::SRL, dl, VT, Lo, Amt); | 
|  | 6962 | SDValue Tmp3 = DAG.getNode(PPCISD::SHL, dl, VT, Hi, Tmp1); | 
|  | 6963 | SDValue Tmp4 = DAG.getNode(ISD::OR, dl, VT, Tmp2, Tmp3); | 
|  | 6964 | SDValue Tmp5 = DAG.getNode(ISD::ADD, dl, AmtVT, Amt, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6965 | DAG.getConstant(-BitWidth, dl, AmtVT)); | 
| Dale Johannesen | 7ae8c8b | 2009-02-05 00:20:09 +0000 | [diff] [blame] | 6966 | SDValue Tmp6 = DAG.getNode(PPCISD::SRL, dl, VT, Hi, Tmp5); | 
|  | 6967 | SDValue OutLo = DAG.getNode(ISD::OR, dl, VT, Tmp4, Tmp6); | 
|  | 6968 | SDValue OutHi = DAG.getNode(PPCISD::SRL, dl, VT, Hi, Amt); | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6969 | SDValue OutOps[] = { OutLo, OutHi }; | 
| Craig Topper | 64941d9 | 2014-04-27 19:20:57 +0000 | [diff] [blame] | 6970 | return DAG.getMergeValues(OutOps, dl); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 6971 | } | 
|  | 6972 |  | 
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 6973 | SDValue PPCTargetLowering::LowerSRA_PARTS(SDValue Op, SelectionDAG &DAG) const { | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6974 | SDLoc dl(Op); | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6975 | EVT VT = Op.getValueType(); | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 6976 | unsigned BitWidth = VT.getSizeInBits(); | 
| Dan Gohman | 8d2ead2 | 2008-03-07 20:36:53 +0000 | [diff] [blame] | 6977 | assert(Op.getNumOperands() == 3 && | 
|  | 6978 | VT == Op.getOperand(1).getValueType() && | 
|  | 6979 | "Unexpected SRA!"); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6980 |  | 
| Dan Gohman | 8d2ead2 | 2008-03-07 20:36:53 +0000 | [diff] [blame] | 6981 | // Expand into a bunch of logical ops, followed by a select_cc. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6982 | SDValue Lo = Op.getOperand(0); | 
|  | 6983 | SDValue Hi = Op.getOperand(1); | 
|  | 6984 | SDValue Amt = Op.getOperand(2); | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6985 | EVT AmtVT = Amt.getValueType(); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 6986 |  | 
| Dale Johannesen | f2bb6f0 | 2009-02-04 01:48:28 +0000 | [diff] [blame] | 6987 | SDValue Tmp1 = DAG.getNode(ISD::SUB, dl, AmtVT, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6988 | DAG.getConstant(BitWidth, dl, AmtVT), Amt); | 
| Dale Johannesen | f2bb6f0 | 2009-02-04 01:48:28 +0000 | [diff] [blame] | 6989 | SDValue Tmp2 = DAG.getNode(PPCISD::SRL, dl, VT, Lo, Amt); | 
|  | 6990 | SDValue Tmp3 = DAG.getNode(PPCISD::SHL, dl, VT, Hi, Tmp1); | 
|  | 6991 | SDValue Tmp4 = DAG.getNode(ISD::OR, dl, VT, Tmp2, Tmp3); | 
|  | 6992 | SDValue Tmp5 = DAG.getNode(ISD::ADD, dl, AmtVT, Amt, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6993 | DAG.getConstant(-BitWidth, dl, AmtVT)); | 
| Dale Johannesen | f2bb6f0 | 2009-02-04 01:48:28 +0000 | [diff] [blame] | 6994 | SDValue Tmp6 = DAG.getNode(PPCISD::SRA, dl, VT, Hi, Tmp5); | 
|  | 6995 | SDValue OutHi = DAG.getNode(PPCISD::SRA, dl, VT, Hi, Amt); | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6996 | SDValue OutLo = DAG.getSelectCC(dl, Tmp5, DAG.getConstant(0, dl, AmtVT), | 
| Duncan Sands | 1310574 | 2008-10-30 19:28:32 +0000 | [diff] [blame] | 6997 | Tmp4, Tmp6, ISD::SETLE); | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 6998 | SDValue OutOps[] = { OutLo, OutHi }; | 
| Craig Topper | 64941d9 | 2014-04-27 19:20:57 +0000 | [diff] [blame] | 6999 | return DAG.getMergeValues(OutOps, dl); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7000 | } | 
|  | 7001 |  | 
|  | 7002 | //===----------------------------------------------------------------------===// | 
|  | 7003 | // Vector related lowering. | 
|  | 7004 | // | 
|  | 7005 |  | 
| Chris Lattner | 2a099c0 | 2006-04-17 06:00:21 +0000 | [diff] [blame] | 7006 | /// BuildSplatI - Build a canonical splati of Val with an element size of | 
|  | 7007 | /// SplatSize.  Cast the result to VT. | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7008 | static SDValue BuildSplatI(int Val, unsigned SplatSize, EVT VT, | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 7009 | SelectionDAG &DAG, const SDLoc &dl) { | 
| Chris Lattner | 2a099c0 | 2006-04-17 06:00:21 +0000 | [diff] [blame] | 7010 | assert(Val >= -16 && Val <= 15 && "vsplti is out of range!"); | 
| Chris Lattner | 09ed0ff | 2006-12-01 01:45:39 +0000 | [diff] [blame] | 7011 |  | 
| Benjamin Kramer | 7149aab | 2015-03-01 18:09:56 +0000 | [diff] [blame] | 7012 | static const MVT VTys[] = { // canonical VT to use for each size. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7013 | MVT::v16i8, MVT::v8i16, MVT::Other, MVT::v4i32 | 
| Chris Lattner | 2a099c0 | 2006-04-17 06:00:21 +0000 | [diff] [blame] | 7014 | }; | 
| Chris Lattner | 09ed0ff | 2006-12-01 01:45:39 +0000 | [diff] [blame] | 7015 |  | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7016 | EVT ReqVT = VT != MVT::Other ? VT : VTys[SplatSize-1]; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7017 |  | 
| Chris Lattner | 09ed0ff | 2006-12-01 01:45:39 +0000 | [diff] [blame] | 7018 | // Force vspltis[hw] -1 to vspltisb -1 to canonicalize. | 
|  | 7019 | if (Val == -1) | 
|  | 7020 | SplatSize = 1; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7021 |  | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7022 | EVT CanonicalVT = VTys[SplatSize-1]; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7023 |  | 
| Chris Lattner | 2a099c0 | 2006-04-17 06:00:21 +0000 | [diff] [blame] | 7024 | // Build a canonical splat for this value. | 
| Ahmed Bougacha | 93cff7f | 2016-02-15 18:07:29 +0000 | [diff] [blame] | 7025 | return DAG.getBitcast(ReqVT, DAG.getConstant(Val, dl, CanonicalVT)); | 
| Chris Lattner | 2a099c0 | 2006-04-17 06:00:21 +0000 | [diff] [blame] | 7026 | } | 
|  | 7027 |  | 
| Hal Finkel | cf2e908 | 2013-05-24 23:00:14 +0000 | [diff] [blame] | 7028 | /// BuildIntrinsicOp - Return a unary operator intrinsic node with the | 
|  | 7029 | /// specified intrinsic ID. | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 7030 | static SDValue BuildIntrinsicOp(unsigned IID, SDValue Op, SelectionDAG &DAG, | 
|  | 7031 | const SDLoc &dl, EVT DestVT = MVT::Other) { | 
| Hal Finkel | cf2e908 | 2013-05-24 23:00:14 +0000 | [diff] [blame] | 7032 | if (DestVT == MVT::Other) DestVT = Op.getValueType(); | 
|  | 7033 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, DestVT, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 7034 | DAG.getConstant(IID, dl, MVT::i32), Op); | 
| Hal Finkel | cf2e908 | 2013-05-24 23:00:14 +0000 | [diff] [blame] | 7035 | } | 
|  | 7036 |  | 
| Chris Lattner | a2cae1b | 2006-04-18 03:24:30 +0000 | [diff] [blame] | 7037 | /// BuildIntrinsicOp - Return a binary operator intrinsic node with the | 
| Chris Lattner | 1b3806a | 2006-04-17 06:58:41 +0000 | [diff] [blame] | 7038 | /// specified intrinsic ID. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7039 | static SDValue BuildIntrinsicOp(unsigned IID, SDValue LHS, SDValue RHS, | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 7040 | SelectionDAG &DAG, const SDLoc &dl, | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7041 | EVT DestVT = MVT::Other) { | 
|  | 7042 | if (DestVT == MVT::Other) DestVT = LHS.getValueType(); | 
| Dale Johannesen | 9f3f72f | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 7043 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, DestVT, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 7044 | DAG.getConstant(IID, dl, MVT::i32), LHS, RHS); | 
| Chris Lattner | 1b3806a | 2006-04-17 06:58:41 +0000 | [diff] [blame] | 7045 | } | 
|  | 7046 |  | 
| Chris Lattner | a2cae1b | 2006-04-18 03:24:30 +0000 | [diff] [blame] | 7047 | /// BuildIntrinsicOp - Return a ternary operator intrinsic node with the | 
|  | 7048 | /// specified intrinsic ID. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7049 | static SDValue BuildIntrinsicOp(unsigned IID, SDValue Op0, SDValue Op1, | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 7050 | SDValue Op2, SelectionDAG &DAG, const SDLoc &dl, | 
|  | 7051 | EVT DestVT = MVT::Other) { | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7052 | if (DestVT == MVT::Other) DestVT = Op0.getValueType(); | 
| Dale Johannesen | 9f3f72f | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 7053 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, DestVT, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 7054 | DAG.getConstant(IID, dl, MVT::i32), Op0, Op1, Op2); | 
| Chris Lattner | a2cae1b | 2006-04-18 03:24:30 +0000 | [diff] [blame] | 7055 | } | 
|  | 7056 |  | 
| Chris Lattner | 264c908 | 2006-04-17 17:55:10 +0000 | [diff] [blame] | 7057 | /// BuildVSLDOI - Return a VECTOR_SHUFFLE that is a vsldoi of the specified | 
|  | 7058 | /// amount.  The result has the specified value type. | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 7059 | static SDValue BuildVSLDOI(SDValue LHS, SDValue RHS, unsigned Amt, EVT VT, | 
|  | 7060 | SelectionDAG &DAG, const SDLoc &dl) { | 
| Chris Lattner | 264c908 | 2006-04-17 17:55:10 +0000 | [diff] [blame] | 7061 | // Force LHS/RHS to be the right type. | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7062 | LHS = DAG.getNode(ISD::BITCAST, dl, MVT::v16i8, LHS); | 
|  | 7063 | RHS = DAG.getNode(ISD::BITCAST, dl, MVT::v16i8, RHS); | 
| Duncan Sands | b0e3938 | 2008-07-21 10:20:31 +0000 | [diff] [blame] | 7064 |  | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 7065 | int Ops[16]; | 
| Chris Lattner | 264c908 | 2006-04-17 17:55:10 +0000 | [diff] [blame] | 7066 | for (unsigned i = 0; i != 16; ++i) | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 7067 | Ops[i] = i + Amt; | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7068 | SDValue T = DAG.getVectorShuffle(MVT::v16i8, dl, LHS, RHS, Ops); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7069 | return DAG.getNode(ISD::BITCAST, dl, VT, T); | 
| Chris Lattner | 264c908 | 2006-04-17 17:55:10 +0000 | [diff] [blame] | 7070 | } | 
|  | 7071 |  | 
| Chris Lattner | 19e9055 | 2006-04-14 05:19:18 +0000 | [diff] [blame] | 7072 | // If this is a case we can't handle, return null and let the default | 
|  | 7073 | // expansion code take care of it.  If we CAN select this case, and if it | 
|  | 7074 | // selects to a single instruction, return Op.  Otherwise, if we can codegen | 
|  | 7075 | // this case more efficiently than a constant pool load, lower it to the | 
|  | 7076 | // sequence of ops that should be used. | 
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 7077 | SDValue PPCTargetLowering::LowerBUILD_VECTOR(SDValue Op, | 
|  | 7078 | SelectionDAG &DAG) const { | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 7079 | SDLoc dl(Op); | 
| Bob Wilson | d8ea0e1 | 2009-03-01 01:13:55 +0000 | [diff] [blame] | 7080 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode()); | 
| Craig Topper | e73658d | 2014-04-28 04:05:08 +0000 | [diff] [blame] | 7081 | assert(BVN && "Expected a BuildVectorSDNode in LowerBUILD_VECTOR"); | 
| Scott Michel | bb87828 | 2009-02-25 03:12:50 +0000 | [diff] [blame] | 7082 |  | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7083 | if (Subtarget.hasQPX() && Op.getValueType() == MVT::v4i1) { | 
|  | 7084 | // We first build an i32 vector, load it into a QPX register, | 
|  | 7085 | // then convert it to a floating-point vector and compare it | 
|  | 7086 | // to a zero vector to get the boolean result. | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 7087 | MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo(); | 
|  | 7088 | int FrameIdx = MFI.CreateStackObject(16, 16, false); | 
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 7089 | MachinePointerInfo PtrInfo = | 
|  | 7090 | MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FrameIdx); | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 7091 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7092 | SDValue FIdx = DAG.getFrameIndex(FrameIdx, PtrVT); | 
|  | 7093 |  | 
|  | 7094 | assert(BVN->getNumOperands() == 4 && | 
|  | 7095 | "BUILD_VECTOR for v4i1 does not have 4 operands"); | 
|  | 7096 |  | 
|  | 7097 | bool IsConst = true; | 
|  | 7098 | for (unsigned i = 0; i < 4; ++i) { | 
| Sanjay Patel | 5719584 | 2016-03-14 17:28:46 +0000 | [diff] [blame] | 7099 | if (BVN->getOperand(i).isUndef()) continue; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7100 | if (!isa<ConstantSDNode>(BVN->getOperand(i))) { | 
|  | 7101 | IsConst = false; | 
|  | 7102 | break; | 
|  | 7103 | } | 
|  | 7104 | } | 
|  | 7105 |  | 
|  | 7106 | if (IsConst) { | 
|  | 7107 | Constant *One = | 
|  | 7108 | ConstantFP::get(Type::getFloatTy(*DAG.getContext()), 1.0); | 
|  | 7109 | Constant *NegOne = | 
|  | 7110 | ConstantFP::get(Type::getFloatTy(*DAG.getContext()), -1.0); | 
|  | 7111 |  | 
| Benjamin Kramer | 1d67ac5 | 2016-06-17 13:15:10 +0000 | [diff] [blame] | 7112 | Constant *CV[4]; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7113 | for (unsigned i = 0; i < 4; ++i) { | 
| Sanjay Patel | 5719584 | 2016-03-14 17:28:46 +0000 | [diff] [blame] | 7114 | if (BVN->getOperand(i).isUndef()) | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7115 | CV[i] = UndefValue::get(Type::getFloatTy(*DAG.getContext())); | 
| Artyom Skrobov | 314ee04 | 2015-11-25 19:41:11 +0000 | [diff] [blame] | 7116 | else if (isNullConstant(BVN->getOperand(i))) | 
| Benjamin Kramer | 1d67ac5 | 2016-06-17 13:15:10 +0000 | [diff] [blame] | 7117 | CV[i] = NegOne; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7118 | else | 
|  | 7119 | CV[i] = One; | 
|  | 7120 | } | 
|  | 7121 |  | 
|  | 7122 | Constant *CP = ConstantVector::get(CV); | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 7123 | SDValue CPIdx = DAG.getConstantPool(CP, getPointerTy(DAG.getDataLayout()), | 
|  | 7124 | 16 /* alignment */); | 
|  | 7125 |  | 
| Benjamin Kramer | 1d67ac5 | 2016-06-17 13:15:10 +0000 | [diff] [blame] | 7126 | SDValue Ops[] = {DAG.getEntryNode(), CPIdx}; | 
|  | 7127 | SDVTList VTs = DAG.getVTList({MVT::v4i1, /*chain*/ MVT::Other}); | 
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 7128 | return DAG.getMemIntrinsicNode( | 
|  | 7129 | PPCISD::QVLFSb, dl, VTs, Ops, MVT::v4f32, | 
|  | 7130 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction())); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7131 | } | 
|  | 7132 |  | 
|  | 7133 | SmallVector<SDValue, 4> Stores; | 
|  | 7134 | for (unsigned i = 0; i < 4; ++i) { | 
| Sanjay Patel | 5719584 | 2016-03-14 17:28:46 +0000 | [diff] [blame] | 7135 | if (BVN->getOperand(i).isUndef()) continue; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7136 |  | 
|  | 7137 | unsigned Offset = 4*i; | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 7138 | SDValue Idx = DAG.getConstant(Offset, dl, FIdx.getValueType()); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7139 | Idx = DAG.getNode(ISD::ADD, dl, FIdx.getValueType(), FIdx, Idx); | 
|  | 7140 |  | 
|  | 7141 | unsigned StoreSize = BVN->getOperand(i).getValueType().getStoreSize(); | 
|  | 7142 | if (StoreSize > 4) { | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 7143 | Stores.push_back( | 
|  | 7144 | DAG.getTruncStore(DAG.getEntryNode(), dl, BVN->getOperand(i), Idx, | 
|  | 7145 | PtrInfo.getWithOffset(Offset), MVT::i32)); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7146 | } else { | 
|  | 7147 | SDValue StoreValue = BVN->getOperand(i); | 
|  | 7148 | if (StoreSize < 4) | 
|  | 7149 | StoreValue = DAG.getNode(ISD::ANY_EXTEND, dl, MVT::i32, StoreValue); | 
|  | 7150 |  | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 7151 | Stores.push_back(DAG.getStore(DAG.getEntryNode(), dl, StoreValue, Idx, | 
|  | 7152 | PtrInfo.getWithOffset(Offset))); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7153 | } | 
|  | 7154 | } | 
|  | 7155 |  | 
|  | 7156 | SDValue StoreChain; | 
|  | 7157 | if (!Stores.empty()) | 
|  | 7158 | StoreChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Stores); | 
|  | 7159 | else | 
|  | 7160 | StoreChain = DAG.getEntryNode(); | 
|  | 7161 |  | 
|  | 7162 | // Now load from v4i32 into the QPX register; this will extend it to | 
|  | 7163 | // v4i64 but not yet convert it to a floating point. Nevertheless, this | 
|  | 7164 | // is typed as v4f64 because the QPX register integer states are not | 
|  | 7165 | // explicitly represented. | 
|  | 7166 |  | 
| Benjamin Kramer | 1d67ac5 | 2016-06-17 13:15:10 +0000 | [diff] [blame] | 7167 | SDValue Ops[] = {StoreChain, | 
|  | 7168 | DAG.getConstant(Intrinsic::ppc_qpx_qvlfiwz, dl, MVT::i32), | 
|  | 7169 | FIdx}; | 
|  | 7170 | SDVTList VTs = DAG.getVTList({MVT::v4f64, /*chain*/ MVT::Other}); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7171 |  | 
|  | 7172 | SDValue LoadedVect = DAG.getMemIntrinsicNode(ISD::INTRINSIC_W_CHAIN, | 
|  | 7173 | dl, VTs, Ops, MVT::v4i32, PtrInfo); | 
|  | 7174 | LoadedVect = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f64, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 7175 | DAG.getConstant(Intrinsic::ppc_qpx_qvfcfidu, dl, MVT::i32), | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7176 | LoadedVect); | 
|  | 7177 |  | 
| Ahmed Bougacha | 93cff7f | 2016-02-15 18:07:29 +0000 | [diff] [blame] | 7178 | SDValue FPZeros = DAG.getConstantFP(0.0, dl, MVT::v4f64); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7179 |  | 
|  | 7180 | return DAG.getSetCC(dl, MVT::v4i1, LoadedVect, FPZeros, ISD::SETEQ); | 
|  | 7181 | } | 
|  | 7182 |  | 
|  | 7183 | // All other QPX vectors are handled by generic code. | 
|  | 7184 | if (Subtarget.hasQPX()) | 
|  | 7185 | return SDValue(); | 
|  | 7186 |  | 
| Bob Wilson | 85cefe8 | 2009-03-02 23:24:16 +0000 | [diff] [blame] | 7187 | // Check if this is a splat of a constant value. | 
|  | 7188 | APInt APSplatBits, APSplatUndef; | 
|  | 7189 | unsigned SplatBitSize; | 
| Bob Wilson | d8ea0e1 | 2009-03-01 01:13:55 +0000 | [diff] [blame] | 7190 | bool HasAnyUndefs; | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7191 | if (! BVN->isConstantSplat(APSplatBits, APSplatUndef, SplatBitSize, | 
| Bill Schmidt | 91dd765 | 2015-04-03 13:48:24 +0000 | [diff] [blame] | 7192 | HasAnyUndefs, 0, !Subtarget.isLittleEndian()) || | 
|  | 7193 | SplatBitSize > 32) | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7194 | return SDValue(); | 
| Evan Cheng | a49de9d | 2009-02-25 22:49:59 +0000 | [diff] [blame] | 7195 |  | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7196 | unsigned SplatBits = APSplatBits.getZExtValue(); | 
|  | 7197 | unsigned SplatUndef = APSplatUndef.getZExtValue(); | 
|  | 7198 | unsigned SplatSize = SplatBitSize / 8; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7199 |  | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7200 | // First, handle single instruction cases. | 
|  | 7201 |  | 
|  | 7202 | // All zeros? | 
|  | 7203 | if (SplatBits == 0) { | 
|  | 7204 | // Canonicalize all zero vectors to be v4i32. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7205 | if (Op.getValueType() != MVT::v4i32 || HasAnyUndefs) { | 
| Ahmed Bougacha | 93cff7f | 2016-02-15 18:07:29 +0000 | [diff] [blame] | 7206 | SDValue Z = DAG.getConstant(0, dl, MVT::v4i32); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7207 | Op = DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Z); | 
| Chris Lattner | 19e9055 | 2006-04-14 05:19:18 +0000 | [diff] [blame] | 7208 | } | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7209 | return Op; | 
|  | 7210 | } | 
| Chris Lattner | fa5aa39 | 2006-04-16 01:01:29 +0000 | [diff] [blame] | 7211 |  | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7212 | // If the sign extended value is in the range [-16,15], use VSPLTI[bhw]. | 
|  | 7213 | int32_t SextVal= (int32_t(SplatBits << (32-SplatBitSize)) >> | 
|  | 7214 | (32-SplatBitSize)); | 
|  | 7215 | if (SextVal >= -16 && SextVal <= 15) | 
|  | 7216 | return BuildSplatI(SextVal, SplatSize, Op.getValueType(), DAG, dl); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7217 |  | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7218 | // Two instruction sequences. | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7219 |  | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7220 | // If this value is in the range [-32,30] and is even, use: | 
| Bill Schmidt | c6cbecc | 2013-02-20 20:41:42 +0000 | [diff] [blame] | 7221 | //     VSPLTI[bhw](val/2) + VSPLTI[bhw](val/2) | 
|  | 7222 | // If this value is in the range [17,31] and is odd, use: | 
|  | 7223 | //     VSPLTI[bhw](val-16) - VSPLTI[bhw](-16) | 
|  | 7224 | // If this value is in the range [-31,-17] and is odd, use: | 
|  | 7225 | //     VSPLTI[bhw](val+16) + VSPLTI[bhw](-16) | 
|  | 7226 | // Note the last two are three-instruction sequences. | 
|  | 7227 | if (SextVal >= -32 && SextVal <= 31) { | 
|  | 7228 | // To avoid having these optimizations undone by constant folding, | 
|  | 7229 | // we convert to a pseudo that will be expanded later into one of | 
|  | 7230 | // the above forms. | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 7231 | SDValue Elt = DAG.getConstant(SextVal, dl, MVT::i32); | 
| Bill Schmidt | 71dddd5 | 2014-05-27 15:57:51 +0000 | [diff] [blame] | 7232 | EVT VT = (SplatSize == 1 ? MVT::v16i8 : | 
|  | 7233 | (SplatSize == 2 ? MVT::v8i16 : MVT::v4i32)); | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 7234 | SDValue EltSize = DAG.getConstant(SplatSize, dl, MVT::i32); | 
| Bill Schmidt | 71dddd5 | 2014-05-27 15:57:51 +0000 | [diff] [blame] | 7235 | SDValue RetVal = DAG.getNode(PPCISD::VADD_SPLAT, dl, VT, Elt, EltSize); | 
|  | 7236 | if (VT == Op.getValueType()) | 
|  | 7237 | return RetVal; | 
|  | 7238 | else | 
|  | 7239 | return DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), RetVal); | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7240 | } | 
|  | 7241 |  | 
|  | 7242 | // If this is 0x8000_0000 x 4, turn into vspltisw + vslw.  If it is | 
|  | 7243 | // 0x7FFF_FFFF x 4, turn it into not(0x8000_0000).  This is important | 
|  | 7244 | // for fneg/fabs. | 
|  | 7245 | if (SplatSize == 4 && SplatBits == (0x7FFFFFFF&~SplatUndef)) { | 
|  | 7246 | // Make -1 and vspltisw -1: | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7247 | SDValue OnesV = BuildSplatI(-1, 4, MVT::v4i32, DAG, dl); | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7248 |  | 
|  | 7249 | // Make the VSLW intrinsic, computing 0x8000_0000. | 
|  | 7250 | SDValue Res = BuildIntrinsicOp(Intrinsic::ppc_altivec_vslw, OnesV, | 
|  | 7251 | OnesV, DAG, dl); | 
|  | 7252 |  | 
|  | 7253 | // xor by OnesV to invert it. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7254 | Res = DAG.getNode(ISD::XOR, dl, MVT::v4i32, Res, OnesV); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7255 | return DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Res); | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7256 | } | 
|  | 7257 |  | 
|  | 7258 | // Check to see if this is a wide variety of vsplti*, binop self cases. | 
|  | 7259 | static const signed char SplatCsts[] = { | 
|  | 7260 | -1, 1, -2, 2, -3, 3, -4, 4, -5, 5, -6, 6, -7, 7, | 
|  | 7261 | -8, 8, -9, 9, -10, 10, -11, 11, -12, 12, -13, 13, 14, -14, 15, -15, -16 | 
|  | 7262 | }; | 
|  | 7263 |  | 
|  | 7264 | for (unsigned idx = 0; idx < array_lengthof(SplatCsts); ++idx) { | 
|  | 7265 | // Indirect through the SplatCsts array so that we favor 'vsplti -1' for | 
|  | 7266 | // cases which are ambiguous (e.g. formation of 0x8000_0000).  'vsplti -1' | 
|  | 7267 | int i = SplatCsts[idx]; | 
|  | 7268 |  | 
|  | 7269 | // Figure out what shift amount will be used by altivec if shifted by i in | 
|  | 7270 | // this splat size. | 
|  | 7271 | unsigned TypeShiftAmt = i & (SplatBitSize-1); | 
|  | 7272 |  | 
|  | 7273 | // vsplti + shl self. | 
| Richard Smith | 228e6d4 | 2012-08-24 23:29:28 +0000 | [diff] [blame] | 7274 | if (SextVal == (int)((unsigned)i << TypeShiftAmt)) { | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7275 | SDValue Res = BuildSplatI(i, SplatSize, MVT::Other, DAG, dl); | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7276 | static const unsigned IIDs[] = { // Intrinsic to use for each size. | 
|  | 7277 | Intrinsic::ppc_altivec_vslb, Intrinsic::ppc_altivec_vslh, 0, | 
|  | 7278 | Intrinsic::ppc_altivec_vslw | 
|  | 7279 | }; | 
|  | 7280 | Res = BuildIntrinsicOp(IIDs[SplatSize-1], Res, Res, DAG, dl); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7281 | return DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Res); | 
| Chris Lattner | 2a099c0 | 2006-04-17 06:00:21 +0000 | [diff] [blame] | 7282 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7283 |  | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7284 | // vsplti + srl self. | 
|  | 7285 | if (SextVal == (int)((unsigned)i >> TypeShiftAmt)) { | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7286 | SDValue Res = BuildSplatI(i, SplatSize, MVT::Other, DAG, dl); | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7287 | static const unsigned IIDs[] = { // Intrinsic to use for each size. | 
|  | 7288 | Intrinsic::ppc_altivec_vsrb, Intrinsic::ppc_altivec_vsrh, 0, | 
|  | 7289 | Intrinsic::ppc_altivec_vsrw | 
|  | 7290 | }; | 
|  | 7291 | Res = BuildIntrinsicOp(IIDs[SplatSize-1], Res, Res, DAG, dl); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7292 | return DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Res); | 
| Chris Lattner | 1b3806a | 2006-04-17 06:58:41 +0000 | [diff] [blame] | 7293 | } | 
|  | 7294 |  | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7295 | // vsplti + sra self. | 
|  | 7296 | if (SextVal == (int)((unsigned)i >> TypeShiftAmt)) { | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7297 | SDValue Res = BuildSplatI(i, SplatSize, MVT::Other, DAG, dl); | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7298 | static const unsigned IIDs[] = { // Intrinsic to use for each size. | 
|  | 7299 | Intrinsic::ppc_altivec_vsrab, Intrinsic::ppc_altivec_vsrah, 0, | 
|  | 7300 | Intrinsic::ppc_altivec_vsraw | 
|  | 7301 | }; | 
|  | 7302 | Res = BuildIntrinsicOp(IIDs[SplatSize-1], Res, Res, DAG, dl); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7303 | return DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Res); | 
| Chris Lattner | 1b3806a | 2006-04-17 06:58:41 +0000 | [diff] [blame] | 7304 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7305 |  | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7306 | // vsplti + rol self. | 
|  | 7307 | if (SextVal == (int)(((unsigned)i << TypeShiftAmt) | | 
|  | 7308 | ((unsigned)i >> (SplatBitSize-TypeShiftAmt)))) { | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7309 | SDValue Res = BuildSplatI(i, SplatSize, MVT::Other, DAG, dl); | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7310 | static const unsigned IIDs[] = { // Intrinsic to use for each size. | 
|  | 7311 | Intrinsic::ppc_altivec_vrlb, Intrinsic::ppc_altivec_vrlh, 0, | 
|  | 7312 | Intrinsic::ppc_altivec_vrlw | 
|  | 7313 | }; | 
|  | 7314 | Res = BuildIntrinsicOp(IIDs[SplatSize-1], Res, Res, DAG, dl); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7315 | return DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Res); | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7316 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7317 |  | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7318 | // t = vsplti c, result = vsldoi t, t, 1 | 
| Richard Smith | 228e6d4 | 2012-08-24 23:29:28 +0000 | [diff] [blame] | 7319 | if (SextVal == (int)(((unsigned)i << 8) | (i < 0 ? 0xFF : 0))) { | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7320 | SDValue T = BuildSplatI(i, SplatSize, MVT::v16i8, DAG, dl); | 
| Bill Schmidt | 1e77bb1 | 2015-07-15 15:45:30 +0000 | [diff] [blame] | 7321 | unsigned Amt = Subtarget.isLittleEndian() ? 15 : 1; | 
|  | 7322 | return BuildVSLDOI(T, T, Amt, Op.getValueType(), DAG, dl); | 
| Chris Lattner | e54133c | 2006-04-17 18:09:22 +0000 | [diff] [blame] | 7323 | } | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7324 | // t = vsplti c, result = vsldoi t, t, 2 | 
| Richard Smith | 228e6d4 | 2012-08-24 23:29:28 +0000 | [diff] [blame] | 7325 | if (SextVal == (int)(((unsigned)i << 16) | (i < 0 ? 0xFFFF : 0))) { | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7326 | SDValue T = BuildSplatI(i, SplatSize, MVT::v16i8, DAG, dl); | 
| Bill Schmidt | 1e77bb1 | 2015-07-15 15:45:30 +0000 | [diff] [blame] | 7327 | unsigned Amt = Subtarget.isLittleEndian() ? 14 : 2; | 
|  | 7328 | return BuildVSLDOI(T, T, Amt, Op.getValueType(), DAG, dl); | 
| Chris Lattner | 19e9055 | 2006-04-14 05:19:18 +0000 | [diff] [blame] | 7329 | } | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7330 | // t = vsplti c, result = vsldoi t, t, 3 | 
| Richard Smith | 228e6d4 | 2012-08-24 23:29:28 +0000 | [diff] [blame] | 7331 | if (SextVal == (int)(((unsigned)i << 24) | (i < 0 ? 0xFFFFFF : 0))) { | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7332 | SDValue T = BuildSplatI(i, SplatSize, MVT::v16i8, DAG, dl); | 
| Bill Schmidt | 1e77bb1 | 2015-07-15 15:45:30 +0000 | [diff] [blame] | 7333 | unsigned Amt = Subtarget.isLittleEndian() ? 13 : 3; | 
|  | 7334 | return BuildVSLDOI(T, T, Amt, Op.getValueType(), DAG, dl); | 
| Bob Wilson | 530e038 | 2009-03-03 19:26:27 +0000 | [diff] [blame] | 7335 | } | 
|  | 7336 | } | 
|  | 7337 |  | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7338 | return SDValue(); | 
| Chris Lattner | 19e9055 | 2006-04-14 05:19:18 +0000 | [diff] [blame] | 7339 | } | 
|  | 7340 |  | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7341 | /// GeneratePerfectShuffle - Given an entry in the perfect-shuffle table, emit | 
|  | 7342 | /// the specified operations to build the shuffle. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7343 | static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS, | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7344 | SDValue RHS, SelectionDAG &DAG, | 
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 7345 | const SDLoc &dl) { | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7346 | unsigned OpNum = (PFEntry >> 26) & 0x0F; | 
| Bill Wendling | 95e1af2 | 2008-09-17 00:30:57 +0000 | [diff] [blame] | 7347 | unsigned LHSID = (PFEntry >> 13) & ((1 << 13)-1); | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7348 | unsigned RHSID = (PFEntry >>  0) & ((1 << 13)-1); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7349 |  | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7350 | enum { | 
| Chris Lattner | d2ca9ab | 2006-05-16 04:20:24 +0000 | [diff] [blame] | 7351 | OP_COPY = 0,  // Copy, used for things like <u,u,u,3> to say it is <0,1,2,3> | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7352 | OP_VMRGHW, | 
|  | 7353 | OP_VMRGLW, | 
|  | 7354 | OP_VSPLTISW0, | 
|  | 7355 | OP_VSPLTISW1, | 
|  | 7356 | OP_VSPLTISW2, | 
|  | 7357 | OP_VSPLTISW3, | 
|  | 7358 | OP_VSLDOI4, | 
|  | 7359 | OP_VSLDOI8, | 
| Chris Lattner | aa237256 | 2006-05-24 17:04:05 +0000 | [diff] [blame] | 7360 | OP_VSLDOI12 | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7361 | }; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7362 |  | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7363 | if (OpNum == OP_COPY) { | 
|  | 7364 | if (LHSID == (1*9+2)*9+3) return LHS; | 
|  | 7365 | assert(LHSID == ((4*9+5)*9+6)*9+7 && "Illegal OP_COPY!"); | 
|  | 7366 | return RHS; | 
|  | 7367 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7368 |  | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7369 | SDValue OpLHS, OpRHS; | 
| Dale Johannesen | 9f3f72f | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 7370 | OpLHS = GeneratePerfectShuffle(PerfectShuffleTable[LHSID], LHS, RHS, DAG, dl); | 
|  | 7371 | OpRHS = GeneratePerfectShuffle(PerfectShuffleTable[RHSID], LHS, RHS, DAG, dl); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7372 |  | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 7373 | int ShufIdxs[16]; | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7374 | switch (OpNum) { | 
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 7375 | default: llvm_unreachable("Unknown i32 permute!"); | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7376 | case OP_VMRGHW: | 
|  | 7377 | ShufIdxs[ 0] =  0; ShufIdxs[ 1] =  1; ShufIdxs[ 2] =  2; ShufIdxs[ 3] =  3; | 
|  | 7378 | ShufIdxs[ 4] = 16; ShufIdxs[ 5] = 17; ShufIdxs[ 6] = 18; ShufIdxs[ 7] = 19; | 
|  | 7379 | ShufIdxs[ 8] =  4; ShufIdxs[ 9] =  5; ShufIdxs[10] =  6; ShufIdxs[11] =  7; | 
|  | 7380 | ShufIdxs[12] = 20; ShufIdxs[13] = 21; ShufIdxs[14] = 22; ShufIdxs[15] = 23; | 
|  | 7381 | break; | 
|  | 7382 | case OP_VMRGLW: | 
|  | 7383 | ShufIdxs[ 0] =  8; ShufIdxs[ 1] =  9; ShufIdxs[ 2] = 10; ShufIdxs[ 3] = 11; | 
|  | 7384 | ShufIdxs[ 4] = 24; ShufIdxs[ 5] = 25; ShufIdxs[ 6] = 26; ShufIdxs[ 7] = 27; | 
|  | 7385 | ShufIdxs[ 8] = 12; ShufIdxs[ 9] = 13; ShufIdxs[10] = 14; ShufIdxs[11] = 15; | 
|  | 7386 | ShufIdxs[12] = 28; ShufIdxs[13] = 29; ShufIdxs[14] = 30; ShufIdxs[15] = 31; | 
|  | 7387 | break; | 
|  | 7388 | case OP_VSPLTISW0: | 
|  | 7389 | for (unsigned i = 0; i != 16; ++i) | 
|  | 7390 | ShufIdxs[i] = (i&3)+0; | 
|  | 7391 | break; | 
|  | 7392 | case OP_VSPLTISW1: | 
|  | 7393 | for (unsigned i = 0; i != 16; ++i) | 
|  | 7394 | ShufIdxs[i] = (i&3)+4; | 
|  | 7395 | break; | 
|  | 7396 | case OP_VSPLTISW2: | 
|  | 7397 | for (unsigned i = 0; i != 16; ++i) | 
|  | 7398 | ShufIdxs[i] = (i&3)+8; | 
|  | 7399 | break; | 
|  | 7400 | case OP_VSPLTISW3: | 
|  | 7401 | for (unsigned i = 0; i != 16; ++i) | 
|  | 7402 | ShufIdxs[i] = (i&3)+12; | 
|  | 7403 | break; | 
|  | 7404 | case OP_VSLDOI4: | 
| Dale Johannesen | 9f3f72f | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 7405 | return BuildVSLDOI(OpLHS, OpRHS, 4, OpLHS.getValueType(), DAG, dl); | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7406 | case OP_VSLDOI8: | 
| Dale Johannesen | 9f3f72f | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 7407 | return BuildVSLDOI(OpLHS, OpRHS, 8, OpLHS.getValueType(), DAG, dl); | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7408 | case OP_VSLDOI12: | 
| Dale Johannesen | 9f3f72f | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 7409 | return BuildVSLDOI(OpLHS, OpRHS, 12, OpLHS.getValueType(), DAG, dl); | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7410 | } | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7411 | EVT VT = OpLHS.getValueType(); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7412 | OpLHS = DAG.getNode(ISD::BITCAST, dl, MVT::v16i8, OpLHS); | 
|  | 7413 | OpRHS = DAG.getNode(ISD::BITCAST, dl, MVT::v16i8, OpRHS); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7414 | SDValue T = DAG.getVectorShuffle(MVT::v16i8, dl, OpLHS, OpRHS, ShufIdxs); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7415 | return DAG.getNode(ISD::BITCAST, dl, VT, T); | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7416 | } | 
|  | 7417 |  | 
| Chris Lattner | 19e9055 | 2006-04-14 05:19:18 +0000 | [diff] [blame] | 7418 | /// LowerVECTOR_SHUFFLE - Return the code we lower for VECTOR_SHUFFLE.  If this | 
|  | 7419 | /// is a shuffle we can handle in a single instruction, return it.  Otherwise, | 
|  | 7420 | /// return the code it can be lowered into.  Worst case, it can always be | 
|  | 7421 | /// lowered into a vperm. | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7422 | SDValue PPCTargetLowering::LowerVECTOR_SHUFFLE(SDValue Op, | 
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 7423 | SelectionDAG &DAG) const { | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 7424 | SDLoc dl(Op); | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7425 | SDValue V1 = Op.getOperand(0); | 
|  | 7426 | SDValue V2 = Op.getOperand(1); | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 7427 | ShuffleVectorSDNode *SVOp = cast<ShuffleVectorSDNode>(Op); | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7428 | EVT VT = Op.getValueType(); | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 7429 | bool isLittleEndian = Subtarget.isLittleEndian(); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7430 |  | 
| Nemanja Ivanovic | b43bb61 | 2016-07-12 21:00:10 +0000 | [diff] [blame] | 7431 | unsigned ShiftElts, InsertAtByte; | 
|  | 7432 | bool Swap; | 
|  | 7433 | if (Subtarget.hasP9Vector() && | 
|  | 7434 | PPC::isXXINSERTWMask(SVOp, ShiftElts, InsertAtByte, Swap, | 
|  | 7435 | isLittleEndian)) { | 
|  | 7436 | if (Swap) | 
|  | 7437 | std::swap(V1, V2); | 
|  | 7438 | SDValue Conv1 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, V1); | 
|  | 7439 | SDValue Conv2 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, V2); | 
|  | 7440 | if (ShiftElts) { | 
|  | 7441 | SDValue Shl = DAG.getNode(PPCISD::VECSHL, dl, MVT::v4i32, Conv2, Conv2, | 
|  | 7442 | DAG.getConstant(ShiftElts, dl, MVT::i32)); | 
|  | 7443 | SDValue Ins = DAG.getNode(PPCISD::XXINSERT, dl, MVT::v4i32, Conv1, Shl, | 
|  | 7444 | DAG.getConstant(InsertAtByte, dl, MVT::i32)); | 
|  | 7445 | return DAG.getNode(ISD::BITCAST, dl, MVT::v16i8, Ins); | 
|  | 7446 | } | 
|  | 7447 | SDValue Ins = DAG.getNode(PPCISD::XXINSERT, dl, MVT::v4i32, Conv1, Conv2, | 
|  | 7448 | DAG.getConstant(InsertAtByte, dl, MVT::i32)); | 
|  | 7449 | return DAG.getNode(ISD::BITCAST, dl, MVT::v16i8, Ins); | 
|  | 7450 | } | 
|  | 7451 |  | 
| Nemanja Ivanovic | 1a2b2f0 | 2016-05-04 16:04:02 +0000 | [diff] [blame] | 7452 | if (Subtarget.hasVSX()) { | 
|  | 7453 | if (V2.isUndef() && PPC::isSplatShuffleMask(SVOp, 4)) { | 
|  | 7454 | int SplatIdx = PPC::getVSPLTImmediate(SVOp, 4, DAG); | 
|  | 7455 | SDValue Conv = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, V1); | 
|  | 7456 | SDValue Splat = DAG.getNode(PPCISD::XXSPLT, dl, MVT::v4i32, Conv, | 
|  | 7457 | DAG.getConstant(SplatIdx, dl, MVT::i32)); | 
|  | 7458 | return DAG.getNode(ISD::BITCAST, dl, MVT::v16i8, Splat); | 
|  | 7459 | } | 
| Nemanja Ivanovic | eebbcb6 | 2016-07-12 12:16:27 +0000 | [diff] [blame] | 7460 |  | 
|  | 7461 | // Left shifts of 8 bytes are actually swaps. Convert accordingly. | 
|  | 7462 | if (V2.isUndef() && PPC::isVSLDOIShuffleMask(SVOp, 1, DAG) == 8) { | 
|  | 7463 | SDValue Conv = DAG.getNode(ISD::BITCAST, dl, MVT::v2f64, V1); | 
|  | 7464 | SDValue Swap = DAG.getNode(PPCISD::SWAP_NO_CHAIN, dl, MVT::v2f64, Conv); | 
|  | 7465 | return DAG.getNode(ISD::BITCAST, dl, MVT::v16i8, Swap); | 
|  | 7466 | } | 
|  | 7467 |  | 
| Nemanja Ivanovic | 1a2b2f0 | 2016-05-04 16:04:02 +0000 | [diff] [blame] | 7468 | } | 
|  | 7469 |  | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7470 | if (Subtarget.hasQPX()) { | 
|  | 7471 | if (VT.getVectorNumElements() != 4) | 
|  | 7472 | return SDValue(); | 
|  | 7473 |  | 
| Sanjay Patel | 5719584 | 2016-03-14 17:28:46 +0000 | [diff] [blame] | 7474 | if (V2.isUndef()) V2 = V1; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7475 |  | 
|  | 7476 | int AlignIdx = PPC::isQVALIGNIShuffleMask(SVOp); | 
|  | 7477 | if (AlignIdx != -1) { | 
|  | 7478 | return DAG.getNode(PPCISD::QVALIGNI, dl, VT, V1, V2, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 7479 | DAG.getConstant(AlignIdx, dl, MVT::i32)); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7480 | } else if (SVOp->isSplat()) { | 
|  | 7481 | int SplatIdx = SVOp->getSplatIndex(); | 
|  | 7482 | if (SplatIdx >= 4) { | 
|  | 7483 | std::swap(V1, V2); | 
|  | 7484 | SplatIdx -= 4; | 
|  | 7485 | } | 
|  | 7486 |  | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7487 | return DAG.getNode(PPCISD::QVESPLATI, dl, VT, V1, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 7488 | DAG.getConstant(SplatIdx, dl, MVT::i32)); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7489 | } | 
|  | 7490 |  | 
|  | 7491 | // Lower this into a qvgpci/qvfperm pair. | 
|  | 7492 |  | 
|  | 7493 | // Compute the qvgpci literal | 
|  | 7494 | unsigned idx = 0; | 
|  | 7495 | for (unsigned i = 0; i < 4; ++i) { | 
|  | 7496 | int m = SVOp->getMaskElt(i); | 
|  | 7497 | unsigned mm = m >= 0 ? (unsigned) m : i; | 
|  | 7498 | idx |= mm << (3-i)*3; | 
|  | 7499 | } | 
|  | 7500 |  | 
|  | 7501 | SDValue V3 = DAG.getNode(PPCISD::QVGPCI, dl, MVT::v4f64, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 7502 | DAG.getConstant(idx, dl, MVT::i32)); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7503 | return DAG.getNode(PPCISD::QVFPERM, dl, VT, V1, V2, V3); | 
|  | 7504 | } | 
|  | 7505 |  | 
| Chris Lattner | 19e9055 | 2006-04-14 05:19:18 +0000 | [diff] [blame] | 7506 | // Cases that are handled by instructions that take permute immediates | 
|  | 7507 | // (such as vsplt*) should be left as VECTOR_SHUFFLE nodes so they can be | 
|  | 7508 | // selected by the instruction selector. | 
| Sanjay Patel | 5719584 | 2016-03-14 17:28:46 +0000 | [diff] [blame] | 7509 | if (V2.isUndef()) { | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 7510 | if (PPC::isSplatShuffleMask(SVOp, 1) || | 
|  | 7511 | PPC::isSplatShuffleMask(SVOp, 2) || | 
|  | 7512 | PPC::isSplatShuffleMask(SVOp, 4) || | 
| Ulrich Weigand | cc9909b | 2014-08-04 13:53:40 +0000 | [diff] [blame] | 7513 | PPC::isVPKUWUMShuffleMask(SVOp, 1, DAG) || | 
|  | 7514 | PPC::isVPKUHUMShuffleMask(SVOp, 1, DAG) || | 
| Bill Schmidt | 42a6936 | 2014-08-05 20:47:25 +0000 | [diff] [blame] | 7515 | PPC::isVSLDOIShuffleMask(SVOp, 1, DAG) != -1 || | 
| Bill Schmidt | c9fa5dd | 2014-07-25 01:55:55 +0000 | [diff] [blame] | 7516 | PPC::isVMRGLShuffleMask(SVOp, 1, 1, DAG) || | 
|  | 7517 | PPC::isVMRGLShuffleMask(SVOp, 2, 1, DAG) || | 
|  | 7518 | PPC::isVMRGLShuffleMask(SVOp, 4, 1, DAG) || | 
|  | 7519 | PPC::isVMRGHShuffleMask(SVOp, 1, 1, DAG) || | 
|  | 7520 | PPC::isVMRGHShuffleMask(SVOp, 2, 1, DAG) || | 
| Kit Barton | 13894c7 | 2015-06-25 15:17:40 +0000 | [diff] [blame] | 7521 | PPC::isVMRGHShuffleMask(SVOp, 4, 1, DAG) || | 
| Hal Finkel | 77c8b7f | 2015-09-02 16:52:37 +0000 | [diff] [blame] | 7522 | (Subtarget.hasP8Altivec() && ( | 
|  | 7523 | PPC::isVPKUDUMShuffleMask(SVOp, 1, DAG) || | 
|  | 7524 | PPC::isVMRGEOShuffleMask(SVOp, true, 1, DAG) || | 
|  | 7525 | PPC::isVMRGEOShuffleMask(SVOp, false, 1, DAG)))) { | 
| Chris Lattner | 19e9055 | 2006-04-14 05:19:18 +0000 | [diff] [blame] | 7526 | return Op; | 
|  | 7527 | } | 
|  | 7528 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7529 |  | 
| Chris Lattner | 19e9055 | 2006-04-14 05:19:18 +0000 | [diff] [blame] | 7530 | // Altivec has a variety of "shuffle immediates" that take two vector inputs | 
|  | 7531 | // and produce a fixed permutation.  If any of these match, do not lower to | 
|  | 7532 | // VPERM. | 
| Bill Schmidt | c9fa5dd | 2014-07-25 01:55:55 +0000 | [diff] [blame] | 7533 | unsigned int ShuffleKind = isLittleEndian ? 2 : 0; | 
| Ulrich Weigand | cc9909b | 2014-08-04 13:53:40 +0000 | [diff] [blame] | 7534 | if (PPC::isVPKUWUMShuffleMask(SVOp, ShuffleKind, DAG) || | 
|  | 7535 | PPC::isVPKUHUMShuffleMask(SVOp, ShuffleKind, DAG) || | 
| Bill Schmidt | 42a6936 | 2014-08-05 20:47:25 +0000 | [diff] [blame] | 7536 | PPC::isVSLDOIShuffleMask(SVOp, ShuffleKind, DAG) != -1 || | 
| Bill Schmidt | c9fa5dd | 2014-07-25 01:55:55 +0000 | [diff] [blame] | 7537 | PPC::isVMRGLShuffleMask(SVOp, 1, ShuffleKind, DAG) || | 
|  | 7538 | PPC::isVMRGLShuffleMask(SVOp, 2, ShuffleKind, DAG) || | 
|  | 7539 | PPC::isVMRGLShuffleMask(SVOp, 4, ShuffleKind, DAG) || | 
|  | 7540 | PPC::isVMRGHShuffleMask(SVOp, 1, ShuffleKind, DAG) || | 
|  | 7541 | PPC::isVMRGHShuffleMask(SVOp, 2, ShuffleKind, DAG) || | 
| Kit Barton | 13894c7 | 2015-06-25 15:17:40 +0000 | [diff] [blame] | 7542 | PPC::isVMRGHShuffleMask(SVOp, 4, ShuffleKind, DAG) || | 
| Hal Finkel | 77c8b7f | 2015-09-02 16:52:37 +0000 | [diff] [blame] | 7543 | (Subtarget.hasP8Altivec() && ( | 
|  | 7544 | PPC::isVPKUDUMShuffleMask(SVOp, ShuffleKind, DAG) || | 
|  | 7545 | PPC::isVMRGEOShuffleMask(SVOp, true, ShuffleKind, DAG) || | 
|  | 7546 | PPC::isVMRGEOShuffleMask(SVOp, false, ShuffleKind, DAG)))) | 
| Chris Lattner | 19e9055 | 2006-04-14 05:19:18 +0000 | [diff] [blame] | 7547 | return Op; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7548 |  | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7549 | // Check to see if this is a shuffle of 4-byte values.  If so, we can use our | 
|  | 7550 | // perfect shuffle table to emit an optimal matching sequence. | 
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 7551 | ArrayRef<int> PermMask = SVOp->getMask(); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7552 |  | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7553 | unsigned PFIndexes[4]; | 
|  | 7554 | bool isFourElementShuffle = true; | 
|  | 7555 | for (unsigned i = 0; i != 4 && isFourElementShuffle; ++i) { // Element number | 
|  | 7556 | unsigned EltNo = 8;   // Start out undef. | 
|  | 7557 | for (unsigned j = 0; j != 4; ++j) {  // Intra-element byte. | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 7558 | if (PermMask[i*4+j] < 0) | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7559 | continue;   // Undef, ignore it. | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7560 |  | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 7561 | unsigned ByteSource = PermMask[i*4+j]; | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7562 | if ((ByteSource & 3) != j) { | 
|  | 7563 | isFourElementShuffle = false; | 
|  | 7564 | break; | 
|  | 7565 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7566 |  | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7567 | if (EltNo == 8) { | 
|  | 7568 | EltNo = ByteSource/4; | 
|  | 7569 | } else if (EltNo != ByteSource/4) { | 
|  | 7570 | isFourElementShuffle = false; | 
|  | 7571 | break; | 
|  | 7572 | } | 
|  | 7573 | } | 
|  | 7574 | PFIndexes[i] = EltNo; | 
|  | 7575 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7576 |  | 
|  | 7577 | // If this shuffle can be expressed as a shuffle of 4-byte elements, use the | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7578 | // perfect shuffle vector to determine if it is cost effective to do this as | 
|  | 7579 | // discrete instructions, or whether we should use a vperm. | 
| Bill Schmidt | f910a06 | 2014-06-10 14:35:01 +0000 | [diff] [blame] | 7580 | // For now, we skip this for little endian until such time as we have a | 
|  | 7581 | // little-endian perfect shuffle table. | 
|  | 7582 | if (isFourElementShuffle && !isLittleEndian) { | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7583 | // Compute the index in the perfect shuffle table. | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7584 | unsigned PFTableIndex = | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7585 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7586 |  | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7587 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; | 
|  | 7588 | unsigned Cost  = (PFEntry >> 30); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7589 |  | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7590 | // Determining when to avoid vperm is tricky.  Many things affect the cost | 
|  | 7591 | // of vperm, particularly how many times the perm mask needs to be computed. | 
|  | 7592 | // For example, if the perm mask can be hoisted out of a loop or is already | 
|  | 7593 | // used (perhaps because there are multiple permutes with the same shuffle | 
|  | 7594 | // mask?) the vperm has a cost of 1.  OTOH, hoisting the permute mask out of | 
|  | 7595 | // the loop requires an extra register. | 
|  | 7596 | // | 
|  | 7597 | // As a compromise, we only emit discrete instructions if the shuffle can be | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7598 | // generated in 3 or fewer operations.  When we have loop information | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7599 | // available, if this block is within a loop, we should avoid using vperm | 
|  | 7600 | // for 3-operation perms and use a constant pool load instead. | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7601 | if (Cost < 3) | 
| Dale Johannesen | 9f3f72f | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 7602 | return GeneratePerfectShuffle(PFEntry, V1, V2, DAG, dl); | 
| Chris Lattner | 071ad01 | 2006-04-17 05:28:54 +0000 | [diff] [blame] | 7603 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7604 |  | 
| Chris Lattner | 19e9055 | 2006-04-14 05:19:18 +0000 | [diff] [blame] | 7605 | // Lower this to a VPERM(V1, V2, V3) expression, where V3 is a constant | 
|  | 7606 | // vector that will get spilled to the constant pool. | 
| Sanjay Patel | 5719584 | 2016-03-14 17:28:46 +0000 | [diff] [blame] | 7607 | if (V2.isUndef()) V2 = V1; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7608 |  | 
| Chris Lattner | 19e9055 | 2006-04-14 05:19:18 +0000 | [diff] [blame] | 7609 | // The SHUFFLE_VECTOR mask is almost exactly what we want for vperm, except | 
|  | 7610 | // that it is in input element units, not in bytes.  Convert now. | 
| Bill Schmidt | 4aedff8 | 2014-06-06 14:06:26 +0000 | [diff] [blame] | 7611 |  | 
|  | 7612 | // For little endian, the order of the input vectors is reversed, and | 
|  | 7613 | // the permutation mask is complemented with respect to 31.  This is | 
|  | 7614 | // necessary to produce proper semantics with the big-endian-biased vperm | 
|  | 7615 | // instruction. | 
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7616 | EVT EltVT = V1.getValueType().getVectorElementType(); | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 7617 | unsigned BytesPerElement = EltVT.getSizeInBits()/8; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7618 |  | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7619 | SmallVector<SDValue, 16> ResultMask; | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 7620 | for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i) { | 
|  | 7621 | unsigned SrcElt = PermMask[i] < 0 ? 0 : PermMask[i]; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7622 |  | 
| Chris Lattner | 19e9055 | 2006-04-14 05:19:18 +0000 | [diff] [blame] | 7623 | for (unsigned j = 0; j != BytesPerElement; ++j) | 
| Bill Schmidt | 4aedff8 | 2014-06-06 14:06:26 +0000 | [diff] [blame] | 7624 | if (isLittleEndian) | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 7625 | ResultMask.push_back(DAG.getConstant(31 - (SrcElt*BytesPerElement + j), | 
|  | 7626 | dl, MVT::i32)); | 
| Bill Schmidt | 4aedff8 | 2014-06-06 14:06:26 +0000 | [diff] [blame] | 7627 | else | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 7628 | ResultMask.push_back(DAG.getConstant(SrcElt*BytesPerElement + j, dl, | 
| Bill Schmidt | 4aedff8 | 2014-06-06 14:06:26 +0000 | [diff] [blame] | 7629 | MVT::i32)); | 
| Chris Lattner | 19e9055 | 2006-04-14 05:19:18 +0000 | [diff] [blame] | 7630 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7631 |  | 
| Ahmed Bougacha | 128f873 | 2016-04-26 21:15:30 +0000 | [diff] [blame] | 7632 | SDValue VPermMask = DAG.getBuildVector(MVT::v16i8, dl, ResultMask); | 
| Bill Schmidt | 4aedff8 | 2014-06-06 14:06:26 +0000 | [diff] [blame] | 7633 | if (isLittleEndian) | 
|  | 7634 | return DAG.getNode(PPCISD::VPERM, dl, V1.getValueType(), | 
|  | 7635 | V2, V1, VPermMask); | 
|  | 7636 | else | 
|  | 7637 | return DAG.getNode(PPCISD::VPERM, dl, V1.getValueType(), | 
|  | 7638 | V1, V2, VPermMask); | 
| Chris Lattner | 19e9055 | 2006-04-14 05:19:18 +0000 | [diff] [blame] | 7639 | } | 
|  | 7640 |  | 
| Nemanja Ivanovic | 2c84b29 | 2015-09-29 17:41:53 +0000 | [diff] [blame] | 7641 | /// getVectorCompareInfo - Given an intrinsic, return false if it is not a | 
|  | 7642 | /// vector comparison.  If it is, return true and fill in Opc/isDot with | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 7643 | /// information about the intrinsic. | 
| Nemanja Ivanovic | 2c84b29 | 2015-09-29 17:41:53 +0000 | [diff] [blame] | 7644 | static bool getVectorCompareInfo(SDValue Intrin, int &CompareOpc, | 
|  | 7645 | bool &isDot, const PPCSubtarget &Subtarget) { | 
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7646 | unsigned IntrinsicID = | 
|  | 7647 | cast<ConstantSDNode>(Intrin.getOperand(0))->getZExtValue(); | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 7648 | CompareOpc = -1; | 
|  | 7649 | isDot = false; | 
|  | 7650 | switch (IntrinsicID) { | 
|  | 7651 | default: return false; | 
|  | 7652 | // Comparison predicates. | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7653 | case Intrinsic::ppc_altivec_vcmpbfp_p:  CompareOpc = 966; isDot = 1; break; | 
|  | 7654 | case Intrinsic::ppc_altivec_vcmpeqfp_p: CompareOpc = 198; isDot = 1; break; | 
|  | 7655 | case Intrinsic::ppc_altivec_vcmpequb_p: CompareOpc =   6; isDot = 1; break; | 
|  | 7656 | case Intrinsic::ppc_altivec_vcmpequh_p: CompareOpc =  70; isDot = 1; break; | 
|  | 7657 | case Intrinsic::ppc_altivec_vcmpequw_p: CompareOpc = 134; isDot = 1; break; | 
| NAKAMURA Takumi | 10c80e7 | 2015-09-22 11:19:03 +0000 | [diff] [blame] | 7658 | case Intrinsic::ppc_altivec_vcmpequd_p: | 
| Kit Barton | 0cfa7b7 | 2015-03-03 19:55:45 +0000 | [diff] [blame] | 7659 | if (Subtarget.hasP8Altivec()) { | 
| NAKAMURA Takumi | 70ad98a | 2015-09-22 11:13:55 +0000 | [diff] [blame] | 7660 | CompareOpc = 199; | 
|  | 7661 | isDot = 1; | 
|  | 7662 | } else | 
| Kit Barton | 0cfa7b7 | 2015-03-03 19:55:45 +0000 | [diff] [blame] | 7663 | return false; | 
|  | 7664 |  | 
|  | 7665 | break; | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7666 | case Intrinsic::ppc_altivec_vcmpgefp_p: CompareOpc = 454; isDot = 1; break; | 
|  | 7667 | case Intrinsic::ppc_altivec_vcmpgtfp_p: CompareOpc = 710; isDot = 1; break; | 
|  | 7668 | case Intrinsic::ppc_altivec_vcmpgtsb_p: CompareOpc = 774; isDot = 1; break; | 
|  | 7669 | case Intrinsic::ppc_altivec_vcmpgtsh_p: CompareOpc = 838; isDot = 1; break; | 
|  | 7670 | case Intrinsic::ppc_altivec_vcmpgtsw_p: CompareOpc = 902; isDot = 1; break; | 
| NAKAMURA Takumi | 10c80e7 | 2015-09-22 11:19:03 +0000 | [diff] [blame] | 7671 | case Intrinsic::ppc_altivec_vcmpgtsd_p: | 
| Kit Barton | 0cfa7b7 | 2015-03-03 19:55:45 +0000 | [diff] [blame] | 7672 | if (Subtarget.hasP8Altivec()) { | 
| NAKAMURA Takumi | 70ad98a | 2015-09-22 11:13:55 +0000 | [diff] [blame] | 7673 | CompareOpc = 967; | 
|  | 7674 | isDot = 1; | 
|  | 7675 | } else | 
| Kit Barton | 0cfa7b7 | 2015-03-03 19:55:45 +0000 | [diff] [blame] | 7676 | return false; | 
|  | 7677 |  | 
|  | 7678 | break; | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7679 | case Intrinsic::ppc_altivec_vcmpgtub_p: CompareOpc = 518; isDot = 1; break; | 
|  | 7680 | case Intrinsic::ppc_altivec_vcmpgtuh_p: CompareOpc = 582; isDot = 1; break; | 
|  | 7681 | case Intrinsic::ppc_altivec_vcmpgtuw_p: CompareOpc = 646; isDot = 1; break; | 
| NAKAMURA Takumi | 10c80e7 | 2015-09-22 11:19:03 +0000 | [diff] [blame] | 7682 | case Intrinsic::ppc_altivec_vcmpgtud_p: | 
| Kit Barton | 0cfa7b7 | 2015-03-03 19:55:45 +0000 | [diff] [blame] | 7683 | if (Subtarget.hasP8Altivec()) { | 
| NAKAMURA Takumi | 70ad98a | 2015-09-22 11:13:55 +0000 | [diff] [blame] | 7684 | CompareOpc = 711; | 
|  | 7685 | isDot = 1; | 
|  | 7686 | } else | 
| Kit Barton | 0cfa7b7 | 2015-03-03 19:55:45 +0000 | [diff] [blame] | 7687 | return false; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7688 |  | 
| Kit Barton | 0cfa7b7 | 2015-03-03 19:55:45 +0000 | [diff] [blame] | 7689 | break; | 
| Nemanja Ivanovic | 2c84b29 | 2015-09-29 17:41:53 +0000 | [diff] [blame] | 7690 | // VSX predicate comparisons use the same infrastructure | 
|  | 7691 | case Intrinsic::ppc_vsx_xvcmpeqdp_p: | 
|  | 7692 | case Intrinsic::ppc_vsx_xvcmpgedp_p: | 
|  | 7693 | case Intrinsic::ppc_vsx_xvcmpgtdp_p: | 
|  | 7694 | case Intrinsic::ppc_vsx_xvcmpeqsp_p: | 
|  | 7695 | case Intrinsic::ppc_vsx_xvcmpgesp_p: | 
|  | 7696 | case Intrinsic::ppc_vsx_xvcmpgtsp_p: | 
|  | 7697 | if (Subtarget.hasVSX()) { | 
|  | 7698 | switch (IntrinsicID) { | 
|  | 7699 | case Intrinsic::ppc_vsx_xvcmpeqdp_p: CompareOpc = 99; break; | 
|  | 7700 | case Intrinsic::ppc_vsx_xvcmpgedp_p: CompareOpc = 115; break; | 
|  | 7701 | case Intrinsic::ppc_vsx_xvcmpgtdp_p: CompareOpc = 107; break; | 
|  | 7702 | case Intrinsic::ppc_vsx_xvcmpeqsp_p: CompareOpc = 67; break; | 
|  | 7703 | case Intrinsic::ppc_vsx_xvcmpgesp_p: CompareOpc = 83; break; | 
|  | 7704 | case Intrinsic::ppc_vsx_xvcmpgtsp_p: CompareOpc = 75; break; | 
|  | 7705 | } | 
|  | 7706 | isDot = 1; | 
|  | 7707 | } | 
|  | 7708 | else | 
|  | 7709 | return false; | 
|  | 7710 |  | 
|  | 7711 | break; | 
| NAKAMURA Takumi | 10c80e7 | 2015-09-22 11:19:03 +0000 | [diff] [blame] | 7712 |  | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7713 | // Normal Comparisons. | 
|  | 7714 | case Intrinsic::ppc_altivec_vcmpbfp:    CompareOpc = 966; isDot = 0; break; | 
|  | 7715 | case Intrinsic::ppc_altivec_vcmpeqfp:   CompareOpc = 198; isDot = 0; break; | 
|  | 7716 | case Intrinsic::ppc_altivec_vcmpequb:   CompareOpc =   6; isDot = 0; break; | 
|  | 7717 | case Intrinsic::ppc_altivec_vcmpequh:   CompareOpc =  70; isDot = 0; break; | 
|  | 7718 | case Intrinsic::ppc_altivec_vcmpequw:   CompareOpc = 134; isDot = 0; break; | 
| Kit Barton | 0cfa7b7 | 2015-03-03 19:55:45 +0000 | [diff] [blame] | 7719 | case Intrinsic::ppc_altivec_vcmpequd: | 
|  | 7720 | if (Subtarget.hasP8Altivec()) { | 
| NAKAMURA Takumi | 70ad98a | 2015-09-22 11:13:55 +0000 | [diff] [blame] | 7721 | CompareOpc = 199; | 
|  | 7722 | isDot = 0; | 
|  | 7723 | } else | 
| Kit Barton | 0cfa7b7 | 2015-03-03 19:55:45 +0000 | [diff] [blame] | 7724 | return false; | 
|  | 7725 |  | 
|  | 7726 | break; | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7727 | case Intrinsic::ppc_altivec_vcmpgefp:   CompareOpc = 454; isDot = 0; break; | 
|  | 7728 | case Intrinsic::ppc_altivec_vcmpgtfp:   CompareOpc = 710; isDot = 0; break; | 
|  | 7729 | case Intrinsic::ppc_altivec_vcmpgtsb:   CompareOpc = 774; isDot = 0; break; | 
|  | 7730 | case Intrinsic::ppc_altivec_vcmpgtsh:   CompareOpc = 838; isDot = 0; break; | 
|  | 7731 | case Intrinsic::ppc_altivec_vcmpgtsw:   CompareOpc = 902; isDot = 0; break; | 
| NAKAMURA Takumi | 10c80e7 | 2015-09-22 11:19:03 +0000 | [diff] [blame] | 7732 | case Intrinsic::ppc_altivec_vcmpgtsd: | 
| Kit Barton | 0cfa7b7 | 2015-03-03 19:55:45 +0000 | [diff] [blame] | 7733 | if (Subtarget.hasP8Altivec()) { | 
| NAKAMURA Takumi | 70ad98a | 2015-09-22 11:13:55 +0000 | [diff] [blame] | 7734 | CompareOpc = 967; | 
|  | 7735 | isDot = 0; | 
|  | 7736 | } else | 
| Kit Barton | 0cfa7b7 | 2015-03-03 19:55:45 +0000 | [diff] [blame] | 7737 | return false; | 
|  | 7738 |  | 
|  | 7739 | break; | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7740 | case Intrinsic::ppc_altivec_vcmpgtub:   CompareOpc = 518; isDot = 0; break; | 
|  | 7741 | case Intrinsic::ppc_altivec_vcmpgtuh:   CompareOpc = 582; isDot = 0; break; | 
|  | 7742 | case Intrinsic::ppc_altivec_vcmpgtuw:   CompareOpc = 646; isDot = 0; break; | 
| NAKAMURA Takumi | 10c80e7 | 2015-09-22 11:19:03 +0000 | [diff] [blame] | 7743 | case Intrinsic::ppc_altivec_vcmpgtud: | 
| Kit Barton | 0cfa7b7 | 2015-03-03 19:55:45 +0000 | [diff] [blame] | 7744 | if (Subtarget.hasP8Altivec()) { | 
| NAKAMURA Takumi | 70ad98a | 2015-09-22 11:13:55 +0000 | [diff] [blame] | 7745 | CompareOpc = 711; | 
|  | 7746 | isDot = 0; | 
|  | 7747 | } else | 
| Kit Barton | 0cfa7b7 | 2015-03-03 19:55:45 +0000 | [diff] [blame] | 7748 | return false; | 
|  | 7749 |  | 
|  | 7750 | break; | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7751 | } | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 7752 | return true; | 
|  | 7753 | } | 
|  | 7754 |  | 
|  | 7755 | /// LowerINTRINSIC_WO_CHAIN - If this is an intrinsic that we want to custom | 
|  | 7756 | /// lower, do it, otherwise return null. | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7757 | SDValue PPCTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, | 
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 7758 | SelectionDAG &DAG) const { | 
| Marcin Koscielnicki | 0cfb612 | 2016-04-26 10:37:22 +0000 | [diff] [blame] | 7759 | unsigned IntrinsicID = | 
|  | 7760 | cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); | 
|  | 7761 |  | 
|  | 7762 | if (IntrinsicID == Intrinsic::thread_pointer) { | 
|  | 7763 | // Reads the thread pointer register, used for __builtin_thread_pointer. | 
|  | 7764 | bool is64bit = Subtarget.isPPC64(); | 
|  | 7765 | return DAG.getRegister(is64bit ? PPC::X13 : PPC::R2, | 
|  | 7766 | is64bit ? MVT::i64 : MVT::i32); | 
|  | 7767 | } | 
|  | 7768 |  | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 7769 | // If this is a lowered altivec predicate compare, CompareOpc is set to the | 
|  | 7770 | // opcode number of the comparison. | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 7771 | SDLoc dl(Op); | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 7772 | int CompareOpc; | 
|  | 7773 | bool isDot; | 
| Nemanja Ivanovic | 2c84b29 | 2015-09-29 17:41:53 +0000 | [diff] [blame] | 7774 | if (!getVectorCompareInfo(Op, CompareOpc, isDot, Subtarget)) | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7775 | return SDValue();    // Don't custom lower most intrinsics. | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7776 |  | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 7777 | // If this is a non-dot comparison, make the VCMP node and we are done. | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7778 | if (!isDot) { | 
| Dale Johannesen | f80493b | 2009-02-05 22:07:54 +0000 | [diff] [blame] | 7779 | SDValue Tmp = DAG.getNode(PPCISD::VCMP, dl, Op.getOperand(2).getValueType(), | 
| Chris Lattner | 9fa851b | 2010-03-14 22:44:11 +0000 | [diff] [blame] | 7780 | Op.getOperand(1), Op.getOperand(2), | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 7781 | DAG.getConstant(CompareOpc, dl, MVT::i32)); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7782 | return DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Tmp); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7783 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7784 |  | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7785 | // Create the PPCISD altivec 'dot' comparison node. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7786 | SDValue Ops[] = { | 
| Chris Lattner | d66f14e | 2006-08-11 17:18:05 +0000 | [diff] [blame] | 7787 | Op.getOperand(2),  // LHS | 
|  | 7788 | Op.getOperand(3),  // RHS | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 7789 | DAG.getConstant(CompareOpc, dl, MVT::i32) | 
| Chris Lattner | d66f14e | 2006-08-11 17:18:05 +0000 | [diff] [blame] | 7790 | }; | 
| Benjamin Kramer | fdf362b | 2013-03-07 20:33:29 +0000 | [diff] [blame] | 7791 | EVT VTs[] = { Op.getOperand(2).getValueType(), MVT::Glue }; | 
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 7792 | SDValue CompNode = DAG.getNode(PPCISD::VCMPo, dl, VTs, Ops); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7793 |  | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7794 | // Now that we have the comparison, emit a copy from the CR to a GPR. | 
|  | 7795 | // This is flagged to the above dot comparison. | 
| Ulrich Weigand | d5ebc62 | 2013-07-03 17:05:42 +0000 | [diff] [blame] | 7796 | SDValue Flags = DAG.getNode(PPCISD::MFOCRF, dl, MVT::i32, | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7797 | DAG.getRegister(PPC::CR6, MVT::i32), | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7798 | CompNode.getValue(1)); | 
|  | 7799 |  | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7800 | // Unpack the result based on how the target uses it. | 
|  | 7801 | unsigned BitNo;   // Bit # of CR6. | 
|  | 7802 | bool InvertBit;   // Invert result? | 
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7803 | switch (cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue()) { | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7804 | default:  // Can't happen, don't crash on invalid number though. | 
|  | 7805 | case 0:   // Return the value of the EQ bit of CR6. | 
|  | 7806 | BitNo = 0; InvertBit = false; | 
|  | 7807 | break; | 
|  | 7808 | case 1:   // Return the inverted value of the EQ bit of CR6. | 
|  | 7809 | BitNo = 0; InvertBit = true; | 
|  | 7810 | break; | 
|  | 7811 | case 2:   // Return the value of the LT bit of CR6. | 
|  | 7812 | BitNo = 2; InvertBit = false; | 
|  | 7813 | break; | 
|  | 7814 | case 3:   // Return the inverted value of the LT bit of CR6. | 
|  | 7815 | BitNo = 2; InvertBit = true; | 
|  | 7816 | break; | 
|  | 7817 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7818 |  | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7819 | // Shift the bit into the low position. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7820 | Flags = DAG.getNode(ISD::SRL, dl, MVT::i32, Flags, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 7821 | DAG.getConstant(8 - (3 - BitNo), dl, MVT::i32)); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7822 | // Isolate the bit. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7823 | Flags = DAG.getNode(ISD::AND, dl, MVT::i32, Flags, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 7824 | DAG.getConstant(1, dl, MVT::i32)); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7825 |  | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7826 | // If we are supposed to, toggle the bit. | 
|  | 7827 | if (InvertBit) | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7828 | Flags = DAG.getNode(ISD::XOR, dl, MVT::i32, Flags, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 7829 | DAG.getConstant(1, dl, MVT::i32)); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7830 | return Flags; | 
|  | 7831 | } | 
|  | 7832 |  | 
| Hal Finkel | 5c0d145 | 2014-03-30 13:22:59 +0000 | [diff] [blame] | 7833 | SDValue PPCTargetLowering::LowerSIGN_EXTEND_INREG(SDValue Op, | 
|  | 7834 | SelectionDAG &DAG) const { | 
|  | 7835 | SDLoc dl(Op); | 
|  | 7836 | // For v2i64 (VSX), we can pattern patch the v2i32 case (using fp <-> int | 
|  | 7837 | // instructions), but for smaller types, we need to first extend up to v2i32 | 
|  | 7838 | // before doing going farther. | 
|  | 7839 | if (Op.getValueType() == MVT::v2i64) { | 
|  | 7840 | EVT ExtVT = cast<VTSDNode>(Op.getOperand(1))->getVT(); | 
|  | 7841 | if (ExtVT != MVT::v2i32) { | 
|  | 7842 | Op = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, Op.getOperand(0)); | 
|  | 7843 | Op = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, MVT::v4i32, Op, | 
|  | 7844 | DAG.getValueType(EVT::getVectorVT(*DAG.getContext(), | 
|  | 7845 | ExtVT.getVectorElementType(), 4))); | 
|  | 7846 | Op = DAG.getNode(ISD::BITCAST, dl, MVT::v2i64, Op); | 
|  | 7847 | Op = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, MVT::v2i64, Op, | 
|  | 7848 | DAG.getValueType(MVT::v2i32)); | 
|  | 7849 | } | 
|  | 7850 |  | 
|  | 7851 | return Op; | 
|  | 7852 | } | 
|  | 7853 |  | 
|  | 7854 | return SDValue(); | 
|  | 7855 | } | 
|  | 7856 |  | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7857 | SDValue PPCTargetLowering::LowerSCALAR_TO_VECTOR(SDValue Op, | 
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 7858 | SelectionDAG &DAG) const { | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 7859 | SDLoc dl(Op); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7860 | // Create a stack slot that is 16-byte aligned. | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 7861 | MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo(); | 
|  | 7862 | int FrameIdx = MFI.CreateStackObject(16, 16, false); | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 7863 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7864 | SDValue FIdx = DAG.getFrameIndex(FrameIdx, PtrVT); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 7865 |  | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7866 | // Store the input value into Value#0 of the stack slot. | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 7867 | SDValue Store = DAG.getStore(DAG.getEntryNode(), dl, Op.getOperand(0), FIdx, | 
|  | 7868 | MachinePointerInfo()); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7869 | // Load it out. | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 7870 | return DAG.getLoad(Op.getValueType(), dl, Store, FIdx, MachinePointerInfo()); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 7871 | } | 
|  | 7872 |  | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7873 | SDValue PPCTargetLowering::LowerEXTRACT_VECTOR_ELT(SDValue Op, | 
|  | 7874 | SelectionDAG &DAG) const { | 
|  | 7875 | SDLoc dl(Op); | 
|  | 7876 | SDNode *N = Op.getNode(); | 
|  | 7877 |  | 
|  | 7878 | assert(N->getOperand(0).getValueType() == MVT::v4i1 && | 
|  | 7879 | "Unknown extract_vector_elt type"); | 
|  | 7880 |  | 
|  | 7881 | SDValue Value = N->getOperand(0); | 
|  | 7882 |  | 
|  | 7883 | // The first part of this is like the store lowering except that we don't | 
|  | 7884 | // need to track the chain. | 
|  | 7885 |  | 
|  | 7886 | // The values are now known to be -1 (false) or 1 (true). To convert this | 
|  | 7887 | // into 0 (false) and 1 (true), add 1 and then divide by 2 (multiply by 0.5). | 
|  | 7888 | // This can be done with an fma and the 0.5 constant: (V+1.0)*0.5 = 0.5*V+0.5 | 
|  | 7889 | Value = DAG.getNode(PPCISD::QBFLT, dl, MVT::v4f64, Value); | 
|  | 7890 |  | 
|  | 7891 | // FIXME: We can make this an f32 vector, but the BUILD_VECTOR code needs to | 
|  | 7892 | // understand how to form the extending load. | 
| Ahmed Bougacha | 93cff7f | 2016-02-15 18:07:29 +0000 | [diff] [blame] | 7893 | SDValue FPHalfs = DAG.getConstantFP(0.5, dl, MVT::v4f64); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7894 |  | 
| NAKAMURA Takumi | 10c80e7 | 2015-09-22 11:19:03 +0000 | [diff] [blame] | 7895 | Value = DAG.getNode(ISD::FMA, dl, MVT::v4f64, Value, FPHalfs, FPHalfs); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7896 |  | 
|  | 7897 | // Now convert to an integer and store. | 
|  | 7898 | Value = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f64, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 7899 | DAG.getConstant(Intrinsic::ppc_qpx_qvfctiwu, dl, MVT::i32), | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7900 | Value); | 
|  | 7901 |  | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 7902 | MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo(); | 
|  | 7903 | int FrameIdx = MFI.CreateStackObject(16, 16, false); | 
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 7904 | MachinePointerInfo PtrInfo = | 
|  | 7905 | MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FrameIdx); | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 7906 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7907 | SDValue FIdx = DAG.getFrameIndex(FrameIdx, PtrVT); | 
|  | 7908 |  | 
|  | 7909 | SDValue StoreChain = DAG.getEntryNode(); | 
| Benjamin Kramer | 1d67ac5 | 2016-06-17 13:15:10 +0000 | [diff] [blame] | 7910 | SDValue Ops[] = {StoreChain, | 
|  | 7911 | DAG.getConstant(Intrinsic::ppc_qpx_qvstfiw, dl, MVT::i32), | 
|  | 7912 | Value, FIdx}; | 
|  | 7913 | SDVTList VTs = DAG.getVTList(/*chain*/ MVT::Other); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7914 |  | 
|  | 7915 | StoreChain = DAG.getMemIntrinsicNode(ISD::INTRINSIC_VOID, | 
|  | 7916 | dl, VTs, Ops, MVT::v4i32, PtrInfo); | 
|  | 7917 |  | 
|  | 7918 | // Extract the value requested. | 
|  | 7919 | unsigned Offset = 4*cast<ConstantSDNode>(N->getOperand(1))->getZExtValue(); | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 7920 | SDValue Idx = DAG.getConstant(Offset, dl, FIdx.getValueType()); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7921 | Idx = DAG.getNode(ISD::ADD, dl, FIdx.getValueType(), FIdx, Idx); | 
|  | 7922 |  | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 7923 | SDValue IntVal = | 
|  | 7924 | DAG.getLoad(MVT::i32, dl, StoreChain, Idx, PtrInfo.getWithOffset(Offset)); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7925 |  | 
|  | 7926 | if (!Subtarget.useCRBits()) | 
|  | 7927 | return IntVal; | 
|  | 7928 |  | 
|  | 7929 | return DAG.getNode(ISD::TRUNCATE, dl, MVT::i1, IntVal); | 
|  | 7930 | } | 
|  | 7931 |  | 
|  | 7932 | /// Lowering for QPX v4i1 loads | 
|  | 7933 | SDValue PPCTargetLowering::LowerVectorLoad(SDValue Op, | 
|  | 7934 | SelectionDAG &DAG) const { | 
|  | 7935 | SDLoc dl(Op); | 
|  | 7936 | LoadSDNode *LN = cast<LoadSDNode>(Op.getNode()); | 
|  | 7937 | SDValue LoadChain = LN->getChain(); | 
|  | 7938 | SDValue BasePtr = LN->getBasePtr(); | 
|  | 7939 |  | 
|  | 7940 | if (Op.getValueType() == MVT::v4f64 || | 
|  | 7941 | Op.getValueType() == MVT::v4f32) { | 
|  | 7942 | EVT MemVT = LN->getMemoryVT(); | 
|  | 7943 | unsigned Alignment = LN->getAlignment(); | 
|  | 7944 |  | 
|  | 7945 | // If this load is properly aligned, then it is legal. | 
|  | 7946 | if (Alignment >= MemVT.getStoreSize()) | 
|  | 7947 | return Op; | 
|  | 7948 |  | 
|  | 7949 | EVT ScalarVT = Op.getValueType().getScalarType(), | 
|  | 7950 | ScalarMemVT = MemVT.getScalarType(); | 
|  | 7951 | unsigned Stride = ScalarMemVT.getStoreSize(); | 
|  | 7952 |  | 
| Benjamin Kramer | 1d67ac5 | 2016-06-17 13:15:10 +0000 | [diff] [blame] | 7953 | SDValue Vals[4], LoadChains[4]; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7954 | for (unsigned Idx = 0; Idx < 4; ++Idx) { | 
|  | 7955 | SDValue Load; | 
|  | 7956 | if (ScalarVT != ScalarMemVT) | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 7957 | Load = DAG.getExtLoad(LN->getExtensionType(), dl, ScalarVT, LoadChain, | 
|  | 7958 | BasePtr, | 
|  | 7959 | LN->getPointerInfo().getWithOffset(Idx * Stride), | 
|  | 7960 | ScalarMemVT, MinAlign(Alignment, Idx * Stride), | 
|  | 7961 | LN->getMemOperand()->getFlags(), LN->getAAInfo()); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7962 | else | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 7963 | Load = DAG.getLoad(ScalarVT, dl, LoadChain, BasePtr, | 
|  | 7964 | LN->getPointerInfo().getWithOffset(Idx * Stride), | 
|  | 7965 | MinAlign(Alignment, Idx * Stride), | 
|  | 7966 | LN->getMemOperand()->getFlags(), LN->getAAInfo()); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7967 |  | 
|  | 7968 | if (Idx == 0 && LN->isIndexed()) { | 
|  | 7969 | assert(LN->getAddressingMode() == ISD::PRE_INC && | 
|  | 7970 | "Unknown addressing mode on vector load"); | 
|  | 7971 | Load = DAG.getIndexedLoad(Load, dl, BasePtr, LN->getOffset(), | 
|  | 7972 | LN->getAddressingMode()); | 
|  | 7973 | } | 
|  | 7974 |  | 
| Benjamin Kramer | 1d67ac5 | 2016-06-17 13:15:10 +0000 | [diff] [blame] | 7975 | Vals[Idx] = Load; | 
|  | 7976 | LoadChains[Idx] = Load.getValue(1); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7977 |  | 
|  | 7978 | BasePtr = DAG.getNode(ISD::ADD, dl, BasePtr.getValueType(), BasePtr, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 7979 | DAG.getConstant(Stride, dl, | 
|  | 7980 | BasePtr.getValueType())); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7981 | } | 
|  | 7982 |  | 
|  | 7983 | SDValue TF =  DAG.getNode(ISD::TokenFactor, dl, MVT::Other, LoadChains); | 
| Ahmed Bougacha | 128f873 | 2016-04-26 21:15:30 +0000 | [diff] [blame] | 7984 | SDValue Value = DAG.getBuildVector(Op.getValueType(), dl, Vals); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 7985 |  | 
|  | 7986 | if (LN->isIndexed()) { | 
|  | 7987 | SDValue RetOps[] = { Value, Vals[0].getValue(1), TF }; | 
|  | 7988 | return DAG.getMergeValues(RetOps, dl); | 
|  | 7989 | } | 
|  | 7990 |  | 
|  | 7991 | SDValue RetOps[] = { Value, TF }; | 
|  | 7992 | return DAG.getMergeValues(RetOps, dl); | 
|  | 7993 | } | 
|  | 7994 |  | 
|  | 7995 | assert(Op.getValueType() == MVT::v4i1 && "Unknown load to lower"); | 
|  | 7996 | assert(LN->isUnindexed() && "Indexed v4i1 loads are not supported"); | 
|  | 7997 |  | 
|  | 7998 | // To lower v4i1 from a byte array, we load the byte elements of the | 
|  | 7999 | // vector and then reuse the BUILD_VECTOR logic. | 
|  | 8000 |  | 
| Benjamin Kramer | 1d67ac5 | 2016-06-17 13:15:10 +0000 | [diff] [blame] | 8001 | SDValue VectElmts[4], VectElmtChains[4]; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 8002 | for (unsigned i = 0; i < 4; ++i) { | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8003 | SDValue Idx = DAG.getConstant(i, dl, BasePtr.getValueType()); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 8004 | Idx = DAG.getNode(ISD::ADD, dl, BasePtr.getValueType(), BasePtr, Idx); | 
|  | 8005 |  | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 8006 | VectElmts[i] = DAG.getExtLoad( | 
|  | 8007 | ISD::EXTLOAD, dl, MVT::i32, LoadChain, Idx, | 
|  | 8008 | LN->getPointerInfo().getWithOffset(i), MVT::i8, | 
|  | 8009 | /* Alignment = */ 1, LN->getMemOperand()->getFlags(), LN->getAAInfo()); | 
| Benjamin Kramer | 1d67ac5 | 2016-06-17 13:15:10 +0000 | [diff] [blame] | 8010 | VectElmtChains[i] = VectElmts[i].getValue(1); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 8011 | } | 
|  | 8012 |  | 
|  | 8013 | LoadChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, VectElmtChains); | 
| Ahmed Bougacha | 128f873 | 2016-04-26 21:15:30 +0000 | [diff] [blame] | 8014 | SDValue Value = DAG.getBuildVector(MVT::v4i1, dl, VectElmts); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 8015 |  | 
|  | 8016 | SDValue RVals[] = { Value, LoadChain }; | 
|  | 8017 | return DAG.getMergeValues(RVals, dl); | 
|  | 8018 | } | 
|  | 8019 |  | 
|  | 8020 | /// Lowering for QPX v4i1 stores | 
|  | 8021 | SDValue PPCTargetLowering::LowerVectorStore(SDValue Op, | 
|  | 8022 | SelectionDAG &DAG) const { | 
|  | 8023 | SDLoc dl(Op); | 
|  | 8024 | StoreSDNode *SN = cast<StoreSDNode>(Op.getNode()); | 
|  | 8025 | SDValue StoreChain = SN->getChain(); | 
|  | 8026 | SDValue BasePtr = SN->getBasePtr(); | 
|  | 8027 | SDValue Value = SN->getValue(); | 
|  | 8028 |  | 
|  | 8029 | if (Value.getValueType() == MVT::v4f64 || | 
|  | 8030 | Value.getValueType() == MVT::v4f32) { | 
|  | 8031 | EVT MemVT = SN->getMemoryVT(); | 
|  | 8032 | unsigned Alignment = SN->getAlignment(); | 
|  | 8033 |  | 
|  | 8034 | // If this store is properly aligned, then it is legal. | 
|  | 8035 | if (Alignment >= MemVT.getStoreSize()) | 
|  | 8036 | return Op; | 
|  | 8037 |  | 
|  | 8038 | EVT ScalarVT = Value.getValueType().getScalarType(), | 
|  | 8039 | ScalarMemVT = MemVT.getScalarType(); | 
|  | 8040 | unsigned Stride = ScalarMemVT.getStoreSize(); | 
|  | 8041 |  | 
| Benjamin Kramer | 1d67ac5 | 2016-06-17 13:15:10 +0000 | [diff] [blame] | 8042 | SDValue Stores[4]; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 8043 | for (unsigned Idx = 0; Idx < 4; ++Idx) { | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 8044 | SDValue Ex = DAG.getNode( | 
|  | 8045 | ISD::EXTRACT_VECTOR_ELT, dl, ScalarVT, Value, | 
|  | 8046 | DAG.getConstant(Idx, dl, getVectorIdxTy(DAG.getDataLayout()))); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 8047 | SDValue Store; | 
|  | 8048 | if (ScalarVT != ScalarMemVT) | 
|  | 8049 | Store = | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 8050 | DAG.getTruncStore(StoreChain, dl, Ex, BasePtr, | 
|  | 8051 | SN->getPointerInfo().getWithOffset(Idx * Stride), | 
|  | 8052 | ScalarMemVT, MinAlign(Alignment, Idx * Stride), | 
|  | 8053 | SN->getMemOperand()->getFlags(), SN->getAAInfo()); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 8054 | else | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 8055 | Store = DAG.getStore(StoreChain, dl, Ex, BasePtr, | 
|  | 8056 | SN->getPointerInfo().getWithOffset(Idx * Stride), | 
|  | 8057 | MinAlign(Alignment, Idx * Stride), | 
|  | 8058 | SN->getMemOperand()->getFlags(), SN->getAAInfo()); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 8059 |  | 
|  | 8060 | if (Idx == 0 && SN->isIndexed()) { | 
|  | 8061 | assert(SN->getAddressingMode() == ISD::PRE_INC && | 
|  | 8062 | "Unknown addressing mode on vector store"); | 
|  | 8063 | Store = DAG.getIndexedStore(Store, dl, BasePtr, SN->getOffset(), | 
|  | 8064 | SN->getAddressingMode()); | 
|  | 8065 | } | 
|  | 8066 |  | 
|  | 8067 | BasePtr = DAG.getNode(ISD::ADD, dl, BasePtr.getValueType(), BasePtr, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8068 | DAG.getConstant(Stride, dl, | 
|  | 8069 | BasePtr.getValueType())); | 
| Benjamin Kramer | 1d67ac5 | 2016-06-17 13:15:10 +0000 | [diff] [blame] | 8070 | Stores[Idx] = Store; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 8071 | } | 
|  | 8072 |  | 
|  | 8073 | SDValue TF =  DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Stores); | 
|  | 8074 |  | 
|  | 8075 | if (SN->isIndexed()) { | 
|  | 8076 | SDValue RetOps[] = { TF, Stores[0].getValue(1) }; | 
|  | 8077 | return DAG.getMergeValues(RetOps, dl); | 
|  | 8078 | } | 
|  | 8079 |  | 
|  | 8080 | return TF; | 
|  | 8081 | } | 
|  | 8082 |  | 
|  | 8083 | assert(SN->isUnindexed() && "Indexed v4i1 stores are not supported"); | 
|  | 8084 | assert(Value.getValueType() == MVT::v4i1 && "Unknown store to lower"); | 
|  | 8085 |  | 
|  | 8086 | // The values are now known to be -1 (false) or 1 (true). To convert this | 
|  | 8087 | // into 0 (false) and 1 (true), add 1 and then divide by 2 (multiply by 0.5). | 
|  | 8088 | // This can be done with an fma and the 0.5 constant: (V+1.0)*0.5 = 0.5*V+0.5 | 
|  | 8089 | Value = DAG.getNode(PPCISD::QBFLT, dl, MVT::v4f64, Value); | 
|  | 8090 |  | 
|  | 8091 | // FIXME: We can make this an f32 vector, but the BUILD_VECTOR code needs to | 
|  | 8092 | // understand how to form the extending load. | 
| Ahmed Bougacha | 93cff7f | 2016-02-15 18:07:29 +0000 | [diff] [blame] | 8093 | SDValue FPHalfs = DAG.getConstantFP(0.5, dl, MVT::v4f64); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 8094 |  | 
| NAKAMURA Takumi | 10c80e7 | 2015-09-22 11:19:03 +0000 | [diff] [blame] | 8095 | Value = DAG.getNode(ISD::FMA, dl, MVT::v4f64, Value, FPHalfs, FPHalfs); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 8096 |  | 
|  | 8097 | // Now convert to an integer and store. | 
|  | 8098 | Value = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f64, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8099 | DAG.getConstant(Intrinsic::ppc_qpx_qvfctiwu, dl, MVT::i32), | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 8100 | Value); | 
|  | 8101 |  | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 8102 | MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo(); | 
|  | 8103 | int FrameIdx = MFI.CreateStackObject(16, 16, false); | 
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 8104 | MachinePointerInfo PtrInfo = | 
|  | 8105 | MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FrameIdx); | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 8106 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 8107 | SDValue FIdx = DAG.getFrameIndex(FrameIdx, PtrVT); | 
|  | 8108 |  | 
| Benjamin Kramer | 1d67ac5 | 2016-06-17 13:15:10 +0000 | [diff] [blame] | 8109 | SDValue Ops[] = {StoreChain, | 
|  | 8110 | DAG.getConstant(Intrinsic::ppc_qpx_qvstfiw, dl, MVT::i32), | 
|  | 8111 | Value, FIdx}; | 
|  | 8112 | SDVTList VTs = DAG.getVTList(/*chain*/ MVT::Other); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 8113 |  | 
|  | 8114 | StoreChain = DAG.getMemIntrinsicNode(ISD::INTRINSIC_VOID, | 
|  | 8115 | dl, VTs, Ops, MVT::v4i32, PtrInfo); | 
|  | 8116 |  | 
|  | 8117 | // Move data into the byte array. | 
| Benjamin Kramer | 1d67ac5 | 2016-06-17 13:15:10 +0000 | [diff] [blame] | 8118 | SDValue Loads[4], LoadChains[4]; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 8119 | for (unsigned i = 0; i < 4; ++i) { | 
|  | 8120 | unsigned Offset = 4*i; | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8121 | SDValue Idx = DAG.getConstant(Offset, dl, FIdx.getValueType()); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 8122 | Idx = DAG.getNode(ISD::ADD, dl, FIdx.getValueType(), FIdx, Idx); | 
|  | 8123 |  | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 8124 | Loads[i] = DAG.getLoad(MVT::i32, dl, StoreChain, Idx, | 
|  | 8125 | PtrInfo.getWithOffset(Offset)); | 
| Benjamin Kramer | 1d67ac5 | 2016-06-17 13:15:10 +0000 | [diff] [blame] | 8126 | LoadChains[i] = Loads[i].getValue(1); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 8127 | } | 
|  | 8128 |  | 
|  | 8129 | StoreChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, LoadChains); | 
|  | 8130 |  | 
| Benjamin Kramer | 1d67ac5 | 2016-06-17 13:15:10 +0000 | [diff] [blame] | 8131 | SDValue Stores[4]; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 8132 | for (unsigned i = 0; i < 4; ++i) { | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8133 | SDValue Idx = DAG.getConstant(i, dl, BasePtr.getValueType()); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 8134 | Idx = DAG.getNode(ISD::ADD, dl, BasePtr.getValueType(), BasePtr, Idx); | 
|  | 8135 |  | 
| Benjamin Kramer | 1d67ac5 | 2016-06-17 13:15:10 +0000 | [diff] [blame] | 8136 | Stores[i] = DAG.getTruncStore( | 
| NAKAMURA Takumi | 70ad98a | 2015-09-22 11:13:55 +0000 | [diff] [blame] | 8137 | StoreChain, dl, Loads[i], Idx, SN->getPointerInfo().getWithOffset(i), | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 8138 | MVT::i8, /* Alignment = */ 1, SN->getMemOperand()->getFlags(), | 
|  | 8139 | SN->getAAInfo()); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 8140 | } | 
|  | 8141 |  | 
|  | 8142 | StoreChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Stores); | 
|  | 8143 |  | 
|  | 8144 | return StoreChain; | 
|  | 8145 | } | 
|  | 8146 |  | 
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 8147 | SDValue PPCTargetLowering::LowerMUL(SDValue Op, SelectionDAG &DAG) const { | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8148 | SDLoc dl(Op); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8149 | if (Op.getValueType() == MVT::v4i32) { | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8150 | SDValue LHS = Op.getOperand(0), RHS = Op.getOperand(1); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 8151 |  | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8152 | SDValue Zero  = BuildSplatI(  0, 1, MVT::v4i32, DAG, dl); | 
|  | 8153 | SDValue Neg16 = BuildSplatI(-16, 4, MVT::v4i32, DAG, dl);//+16 as shift amt. | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 8154 |  | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8155 | SDValue RHSSwap =   // = vrlw RHS, 16 | 
| Dale Johannesen | 9f3f72f | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 8156 | BuildIntrinsicOp(Intrinsic::ppc_altivec_vrlw, RHS, Neg16, DAG, dl); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 8157 |  | 
| Chris Lattner | 7e439874 | 2006-04-18 03:43:48 +0000 | [diff] [blame] | 8158 | // Shrinkify inputs to v8i16. | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8159 | LHS = DAG.getNode(ISD::BITCAST, dl, MVT::v8i16, LHS); | 
|  | 8160 | RHS = DAG.getNode(ISD::BITCAST, dl, MVT::v8i16, RHS); | 
|  | 8161 | RHSSwap = DAG.getNode(ISD::BITCAST, dl, MVT::v8i16, RHSSwap); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 8162 |  | 
| Chris Lattner | 7e439874 | 2006-04-18 03:43:48 +0000 | [diff] [blame] | 8163 | // Low parts multiplied together, generating 32-bit results (we ignore the | 
|  | 8164 | // top parts). | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8165 | SDValue LoProd = BuildIntrinsicOp(Intrinsic::ppc_altivec_vmulouh, | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8166 | LHS, RHS, DAG, dl, MVT::v4i32); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 8167 |  | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8168 | SDValue HiProd = BuildIntrinsicOp(Intrinsic::ppc_altivec_vmsumuhm, | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8169 | LHS, RHSSwap, Zero, DAG, dl, MVT::v4i32); | 
| Chris Lattner | 7e439874 | 2006-04-18 03:43:48 +0000 | [diff] [blame] | 8170 | // Shift the high parts up 16 bits. | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 8171 | HiProd = BuildIntrinsicOp(Intrinsic::ppc_altivec_vslw, HiProd, | 
| Dale Johannesen | 9f3f72f | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 8172 | Neg16, DAG, dl); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8173 | return DAG.getNode(ISD::ADD, dl, MVT::v4i32, LoProd, HiProd); | 
|  | 8174 | } else if (Op.getValueType() == MVT::v8i16) { | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8175 | SDValue LHS = Op.getOperand(0), RHS = Op.getOperand(1); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 8176 |  | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8177 | SDValue Zero = BuildSplatI(0, 1, MVT::v8i16, DAG, dl); | 
| Chris Lattner | 7e439874 | 2006-04-18 03:43:48 +0000 | [diff] [blame] | 8178 |  | 
| Chris Lattner | 96d5048 | 2006-04-18 04:28:57 +0000 | [diff] [blame] | 8179 | return BuildIntrinsicOp(Intrinsic::ppc_altivec_vmladduhm, | 
| Dale Johannesen | 9f3f72f | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 8180 | LHS, RHS, Zero, DAG, dl); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8181 | } else if (Op.getValueType() == MVT::v16i8) { | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8182 | SDValue LHS = Op.getOperand(0), RHS = Op.getOperand(1); | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 8183 | bool isLittleEndian = Subtarget.isLittleEndian(); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 8184 |  | 
| Chris Lattner | d6d82aa | 2006-04-18 03:57:35 +0000 | [diff] [blame] | 8185 | // Multiply the even 8-bit parts, producing 16-bit sums. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8186 | SDValue EvenParts = BuildIntrinsicOp(Intrinsic::ppc_altivec_vmuleub, | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8187 | LHS, RHS, DAG, dl, MVT::v8i16); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8188 | EvenParts = DAG.getNode(ISD::BITCAST, dl, MVT::v16i8, EvenParts); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 8189 |  | 
| Chris Lattner | d6d82aa | 2006-04-18 03:57:35 +0000 | [diff] [blame] | 8190 | // Multiply the odd 8-bit parts, producing 16-bit sums. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 8191 | SDValue OddParts = BuildIntrinsicOp(Intrinsic::ppc_altivec_vmuloub, | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8192 | LHS, RHS, DAG, dl, MVT::v8i16); | 
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8193 | OddParts = DAG.getNode(ISD::BITCAST, dl, MVT::v16i8, OddParts); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 8194 |  | 
| Bill Schmidt | 42995e8 | 2014-06-09 16:06:29 +0000 | [diff] [blame] | 8195 | // Merge the results together.  Because vmuleub and vmuloub are | 
|  | 8196 | // instructions with a big-endian bias, we must reverse the | 
|  | 8197 | // element numbering and reverse the meaning of "odd" and "even" | 
|  | 8198 | // when generating little endian code. | 
| Nate Begeman | 8d6d4b9 | 2009-04-27 18:41:29 +0000 | [diff] [blame] | 8199 | int Ops[16]; | 
| Chris Lattner | d6d82aa | 2006-04-18 03:57:35 +0000 | [diff] [blame] | 8200 | for (unsigned i = 0; i != 8; ++i) { | 
| Bill Schmidt | 42995e8 | 2014-06-09 16:06:29 +0000 | [diff] [blame] | 8201 | if (isLittleEndian) { | 
|  | 8202 | Ops[i*2  ] = 2*i; | 
|  | 8203 | Ops[i*2+1] = 2*i+16; | 
|  | 8204 | } else { | 
|  | 8205 | Ops[i*2  ] = 2*i+1; | 
|  | 8206 | Ops[i*2+1] = 2*i+1+16; | 
|  | 8207 | } | 
| Chris Lattner | d6d82aa | 2006-04-18 03:57:35 +0000 | [diff] [blame] | 8208 | } | 
| Bill Schmidt | 42995e8 | 2014-06-09 16:06:29 +0000 | [diff] [blame] | 8209 | if (isLittleEndian) | 
|  | 8210 | return DAG.getVectorShuffle(MVT::v16i8, dl, OddParts, EvenParts, Ops); | 
|  | 8211 | else | 
|  | 8212 | return DAG.getVectorShuffle(MVT::v16i8, dl, EvenParts, OddParts, Ops); | 
| Chris Lattner | 7e439874 | 2006-04-18 03:43:48 +0000 | [diff] [blame] | 8213 | } else { | 
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 8214 | llvm_unreachable("Unknown mul to lower!"); | 
| Chris Lattner | 7e439874 | 2006-04-18 03:43:48 +0000 | [diff] [blame] | 8215 | } | 
| Chris Lattner | a2cae1b | 2006-04-18 03:24:30 +0000 | [diff] [blame] | 8216 | } | 
|  | 8217 |  | 
| Chris Lattner | f3d06c6 | 2005-08-26 00:52:45 +0000 | [diff] [blame] | 8218 | /// LowerOperation - Provide custom lowering hooks for some operations. | 
|  | 8219 | /// | 
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 8220 | SDValue PPCTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { | 
| Chris Lattner | f3d06c6 | 2005-08-26 00:52:45 +0000 | [diff] [blame] | 8221 | switch (Op.getOpcode()) { | 
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 8222 | default: llvm_unreachable("Wasn't expecting to be able to lower this!"); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 8223 | case ISD::ConstantPool:       return LowerConstantPool(Op, DAG); | 
| Bob Wilson | f84f710 | 2009-11-04 21:31:18 +0000 | [diff] [blame] | 8224 | case ISD::BlockAddress:       return LowerBlockAddress(Op, DAG); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 8225 | case ISD::GlobalAddress:      return LowerGlobalAddress(Op, DAG); | 
| Roman Divacky | e3f15c98 | 2012-06-04 17:36:38 +0000 | [diff] [blame] | 8226 | case ISD::GlobalTLSAddress:   return LowerGlobalTLSAddress(Op, DAG); | 
| Nate Begeman | 4ca2ea5 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 8227 | case ISD::JumpTable:          return LowerJumpTable(Op, DAG); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 8228 | case ISD::SETCC:              return LowerSETCC(Op, DAG); | 
| Duncan Sands | a098436 | 2011-09-06 13:37:06 +0000 | [diff] [blame] | 8229 | case ISD::INIT_TRAMPOLINE:    return LowerINIT_TRAMPOLINE(Op, DAG); | 
|  | 8230 | case ISD::ADJUST_TRAMPOLINE:  return LowerADJUST_TRAMPOLINE(Op, DAG); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 8231 | case ISD::VASTART: | 
| Eric Christopher | b976a39 | 2016-07-07 00:39:27 +0000 | [diff] [blame] | 8232 | return LowerVASTART(Op, DAG); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 8233 |  | 
|  | 8234 | case ISD::VAARG: | 
| Eric Christopher | b976a39 | 2016-07-07 00:39:27 +0000 | [diff] [blame] | 8235 | return LowerVAARG(Op, DAG); | 
| Nicolas Geoffray | 23710a7 | 2007-04-03 13:59:52 +0000 | [diff] [blame] | 8236 |  | 
| Roman Divacky | c3825df | 2013-07-25 21:36:47 +0000 | [diff] [blame] | 8237 | case ISD::VACOPY: | 
| Eric Christopher | b976a39 | 2016-07-07 00:39:27 +0000 | [diff] [blame] | 8238 | return LowerVACOPY(Op, DAG); | 
| Roman Divacky | c3825df | 2013-07-25 21:36:47 +0000 | [diff] [blame] | 8239 |  | 
| Eric Christopher | b976a39 | 2016-07-07 00:39:27 +0000 | [diff] [blame] | 8240 | case ISD::STACKRESTORE: | 
|  | 8241 | return LowerSTACKRESTORE(Op, DAG); | 
|  | 8242 |  | 
| Chris Lattner | 43df5b3 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 8243 | case ISD::DYNAMIC_STACKALLOC: | 
| Eric Christopher | b976a39 | 2016-07-07 00:39:27 +0000 | [diff] [blame] | 8244 | return LowerDYNAMIC_STACKALLOC(Op, DAG); | 
|  | 8245 |  | 
|  | 8246 | case ISD::GET_DYNAMIC_AREA_OFFSET: | 
|  | 8247 | return LowerGET_DYNAMIC_AREA_OFFSET(Op, DAG); | 
| Evan Cheng | 51096af | 2008-04-19 01:30:48 +0000 | [diff] [blame] | 8248 |  | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8249 | case ISD::EH_SJLJ_SETJMP:     return lowerEH_SJLJ_SETJMP(Op, DAG); | 
|  | 8250 | case ISD::EH_SJLJ_LONGJMP:    return lowerEH_SJLJ_LONGJMP(Op, DAG); | 
|  | 8251 |  | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 8252 | case ISD::LOAD:               return LowerLOAD(Op, DAG); | 
|  | 8253 | case ISD::STORE:              return LowerSTORE(Op, DAG); | 
|  | 8254 | case ISD::TRUNCATE:           return LowerTRUNCATE(Op, DAG); | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 8255 | case ISD::SELECT_CC:          return LowerSELECT_CC(Op, DAG); | 
| Dale Johannesen | 37bc85f | 2009-06-04 20:53:52 +0000 | [diff] [blame] | 8256 | case ISD::FP_TO_UINT: | 
|  | 8257 | case ISD::FP_TO_SINT:         return LowerFP_TO_INT(Op, DAG, | 
| Hal Finkel | ed844c4 | 2015-01-06 22:31:02 +0000 | [diff] [blame] | 8258 | SDLoc(Op)); | 
| Hal Finkel | f6d45f2 | 2013-04-01 17:52:07 +0000 | [diff] [blame] | 8259 | case ISD::UINT_TO_FP: | 
|  | 8260 | case ISD::SINT_TO_FP:         return LowerINT_TO_FP(Op, DAG); | 
| Dan Gohman | 9ba4d76 | 2008-01-31 00:41:03 +0000 | [diff] [blame] | 8261 | case ISD::FLT_ROUNDS_:        return LowerFLT_ROUNDS_(Op, DAG); | 
| Chris Lattner | 4a66d69 | 2006-03-22 05:30:33 +0000 | [diff] [blame] | 8262 |  | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 8263 | // Lower 64-bit shifts. | 
| Chris Lattner | 601b865 | 2006-09-20 03:47:40 +0000 | [diff] [blame] | 8264 | case ISD::SHL_PARTS:          return LowerSHL_PARTS(Op, DAG); | 
|  | 8265 | case ISD::SRL_PARTS:          return LowerSRL_PARTS(Op, DAG); | 
|  | 8266 | case ISD::SRA_PARTS:          return LowerSRA_PARTS(Op, DAG); | 
| Chris Lattner | 4a66d69 | 2006-03-22 05:30:33 +0000 | [diff] [blame] | 8267 |  | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 8268 | // Vector-related lowering. | 
|  | 8269 | case ISD::BUILD_VECTOR:       return LowerBUILD_VECTOR(Op, DAG); | 
|  | 8270 | case ISD::VECTOR_SHUFFLE:     return LowerVECTOR_SHUFFLE(Op, DAG); | 
|  | 8271 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG); | 
|  | 8272 | case ISD::SCALAR_TO_VECTOR:   return LowerSCALAR_TO_VECTOR(Op, DAG); | 
| Hal Finkel | 5c0d145 | 2014-03-30 13:22:59 +0000 | [diff] [blame] | 8273 | case ISD::SIGN_EXTEND_INREG:  return LowerSIGN_EXTEND_INREG(Op, DAG); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 8274 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); | 
| Chris Lattner | a2cae1b | 2006-04-18 03:24:30 +0000 | [diff] [blame] | 8275 | case ISD::MUL:                return LowerMUL(Op, DAG); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 8276 |  | 
| Hal Finkel | 25c1992 | 2013-05-15 21:37:41 +0000 | [diff] [blame] | 8277 | // For counter-based loop handling. | 
|  | 8278 | case ISD::INTRINSIC_W_CHAIN:  return SDValue(); | 
|  | 8279 |  | 
| Chris Lattner | f6a8156 | 2007-12-08 06:59:59 +0000 | [diff] [blame] | 8280 | // Frame & Return address. | 
|  | 8281 | case ISD::RETURNADDR:         return LowerRETURNADDR(Op, DAG); | 
| Nicolas Geoffray | 75ab979 | 2007-03-01 13:11:38 +0000 | [diff] [blame] | 8282 | case ISD::FRAMEADDR:          return LowerFRAMEADDR(Op, DAG); | 
| Chris Lattner | e675a08 | 2005-08-31 20:23:54 +0000 | [diff] [blame] | 8283 | } | 
| Chris Lattner | f3d06c6 | 2005-08-26 00:52:45 +0000 | [diff] [blame] | 8284 | } | 
|  | 8285 |  | 
| Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 8286 | void PPCTargetLowering::ReplaceNodeResults(SDNode *N, | 
|  | 8287 | SmallVectorImpl<SDValue>&Results, | 
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 8288 | SelectionDAG &DAG) const { | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8289 | SDLoc dl(N); | 
| Chris Lattner | 57ee7c6 | 2007-11-28 18:44:47 +0000 | [diff] [blame] | 8290 | switch (N->getOpcode()) { | 
| Duncan Sands | 4068a7f | 2008-10-28 15:00:32 +0000 | [diff] [blame] | 8291 | default: | 
| Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 8292 | llvm_unreachable("Do not know how to custom type legalize this operation!"); | 
| Hal Finkel | bbdee93 | 2014-12-02 22:01:00 +0000 | [diff] [blame] | 8293 | case ISD::READCYCLECOUNTER: { | 
|  | 8294 | SDVTList VTs = DAG.getVTList(MVT::i32, MVT::i32, MVT::Other); | 
|  | 8295 | SDValue RTB = DAG.getNode(PPCISD::READ_TIME_BASE, dl, VTs, N->getOperand(0)); | 
|  | 8296 |  | 
|  | 8297 | Results.push_back(RTB); | 
|  | 8298 | Results.push_back(RTB.getValue(1)); | 
|  | 8299 | Results.push_back(RTB.getValue(2)); | 
|  | 8300 | break; | 
|  | 8301 | } | 
| Hal Finkel | 25c1992 | 2013-05-15 21:37:41 +0000 | [diff] [blame] | 8302 | case ISD::INTRINSIC_W_CHAIN: { | 
|  | 8303 | if (cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() != | 
|  | 8304 | Intrinsic::ppc_is_decremented_ctr_nonzero) | 
|  | 8305 | break; | 
|  | 8306 |  | 
|  | 8307 | assert(N->getValueType(0) == MVT::i1 && | 
|  | 8308 | "Unexpected result type for CTR decrement intrinsic"); | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 8309 | EVT SVT = getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), | 
|  | 8310 | N->getValueType(0)); | 
| Hal Finkel | 25c1992 | 2013-05-15 21:37:41 +0000 | [diff] [blame] | 8311 | SDVTList VTs = DAG.getVTList(SVT, MVT::Other); | 
|  | 8312 | SDValue NewInt = DAG.getNode(N->getOpcode(), dl, VTs, N->getOperand(0), | 
| NAKAMURA Takumi | 10c80e7 | 2015-09-22 11:19:03 +0000 | [diff] [blame] | 8313 | N->getOperand(1)); | 
| Hal Finkel | 25c1992 | 2013-05-15 21:37:41 +0000 | [diff] [blame] | 8314 |  | 
|  | 8315 | Results.push_back(NewInt); | 
|  | 8316 | Results.push_back(NewInt.getValue(1)); | 
|  | 8317 | break; | 
|  | 8318 | } | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 8319 | case ISD::VAARG: { | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 8320 | if (!Subtarget.isSVR4ABI() || Subtarget.isPPC64()) | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 8321 | return; | 
|  | 8322 |  | 
|  | 8323 | EVT VT = N->getValueType(0); | 
|  | 8324 |  | 
|  | 8325 | if (VT == MVT::i64) { | 
| Eric Christopher | b976a39 | 2016-07-07 00:39:27 +0000 | [diff] [blame] | 8326 | SDValue NewNode = LowerVAARG(SDValue(N, 1), DAG); | 
| Roman Divacky | 4394e68 | 2011-06-28 15:30:42 +0000 | [diff] [blame] | 8327 |  | 
|  | 8328 | Results.push_back(NewNode); | 
|  | 8329 | Results.push_back(NewNode.getValue(1)); | 
|  | 8330 | } | 
|  | 8331 | return; | 
|  | 8332 | } | 
| Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 8333 | case ISD::FP_ROUND_INREG: { | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8334 | assert(N->getValueType(0) == MVT::ppcf128); | 
|  | 8335 | assert(N->getOperand(0).getValueType() == MVT::ppcf128); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 8336 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8337 | MVT::f64, N->getOperand(0), | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8338 | DAG.getIntPtrConstant(0, dl)); | 
| Dale Johannesen | f80493b | 2009-02-05 22:07:54 +0000 | [diff] [blame] | 8339 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8340 | MVT::f64, N->getOperand(0), | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8341 | DAG.getIntPtrConstant(1, dl)); | 
| Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 8342 |  | 
| Ulrich Weigand | 874fc62 | 2013-03-26 10:56:22 +0000 | [diff] [blame] | 8343 | // Add the two halves of the long double in round-to-zero mode. | 
|  | 8344 | SDValue FPreg = DAG.getNode(PPCISD::FADDRTZ, dl, MVT::f64, Lo, Hi); | 
| Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 8345 |  | 
|  | 8346 | // We know the low half is about to be thrown away, so just use something | 
|  | 8347 | // convenient. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 8348 | Results.push_back(DAG.getNode(ISD::BUILD_PAIR, dl, MVT::ppcf128, | 
| Dale Johannesen | f80493b | 2009-02-05 22:07:54 +0000 | [diff] [blame] | 8349 | FPreg, FPreg)); | 
| Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 8350 | return; | 
| Duncan Sands | 2a28791 | 2008-07-19 16:26:02 +0000 | [diff] [blame] | 8351 | } | 
| Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 8352 | case ISD::FP_TO_SINT: | 
| Hal Finkel | 9313850 | 2015-04-10 03:39:00 +0000 | [diff] [blame] | 8353 | case ISD::FP_TO_UINT: | 
| Bill Schmidt | 4122169 | 2013-07-09 18:50:20 +0000 | [diff] [blame] | 8354 | // LowerFP_TO_INT() can only handle f32 and f64. | 
|  | 8355 | if (N->getOperand(0).getValueType() == MVT::ppcf128) | 
|  | 8356 | return; | 
| Dale Johannesen | 37bc85f | 2009-06-04 20:53:52 +0000 | [diff] [blame] | 8357 | Results.push_back(LowerFP_TO_INT(SDValue(N, 0), DAG, dl)); | 
| Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 8358 | return; | 
| Chris Lattner | 57ee7c6 | 2007-11-28 18:44:47 +0000 | [diff] [blame] | 8359 | } | 
|  | 8360 | } | 
|  | 8361 |  | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 8362 | //===----------------------------------------------------------------------===// | 
|  | 8363 | //  Other Lowering Code | 
|  | 8364 | //===----------------------------------------------------------------------===// | 
|  | 8365 |  | 
| Robin Morisset | 2212996 | 2014-09-23 20:46:49 +0000 | [diff] [blame] | 8366 | static Instruction* callIntrinsic(IRBuilder<> &Builder, Intrinsic::ID Id) { | 
|  | 8367 | Module *M = Builder.GetInsertBlock()->getParent()->getParent(); | 
|  | 8368 | Function *Func = Intrinsic::getDeclaration(M, Id); | 
| David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 8369 | return Builder.CreateCall(Func, {}); | 
| Robin Morisset | 2212996 | 2014-09-23 20:46:49 +0000 | [diff] [blame] | 8370 | } | 
|  | 8371 |  | 
|  | 8372 | // The mappings for emitLeading/TrailingFence is taken from | 
|  | 8373 | // http://www.cl.cam.ac.uk/~pes20/cpp/cpp0xmappings.html | 
|  | 8374 | Instruction* PPCTargetLowering::emitLeadingFence(IRBuilder<> &Builder, | 
|  | 8375 | AtomicOrdering Ord, bool IsStore, | 
|  | 8376 | bool IsLoad) const { | 
| JF Bastien | 800f87a | 2016-04-06 21:19:33 +0000 | [diff] [blame] | 8377 | if (Ord == AtomicOrdering::SequentiallyConsistent) | 
| Robin Morisset | 2212996 | 2014-09-23 20:46:49 +0000 | [diff] [blame] | 8378 | return callIntrinsic(Builder, Intrinsic::ppc_sync); | 
| JF Bastien | 800f87a | 2016-04-06 21:19:33 +0000 | [diff] [blame] | 8379 | if (isReleaseOrStronger(Ord)) | 
| Robin Morisset | 2212996 | 2014-09-23 20:46:49 +0000 | [diff] [blame] | 8380 | return callIntrinsic(Builder, Intrinsic::ppc_lwsync); | 
| David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 8381 | return nullptr; | 
| Robin Morisset | 2212996 | 2014-09-23 20:46:49 +0000 | [diff] [blame] | 8382 | } | 
|  | 8383 |  | 
|  | 8384 | Instruction* PPCTargetLowering::emitTrailingFence(IRBuilder<> &Builder, | 
|  | 8385 | AtomicOrdering Ord, bool IsStore, | 
|  | 8386 | bool IsLoad) const { | 
| JF Bastien | 800f87a | 2016-04-06 21:19:33 +0000 | [diff] [blame] | 8387 | if (IsLoad && isAcquireOrStronger(Ord)) | 
| Robin Morisset | 2212996 | 2014-09-23 20:46:49 +0000 | [diff] [blame] | 8388 | return callIntrinsic(Builder, Intrinsic::ppc_lwsync); | 
|  | 8389 | // FIXME: this is too conservative, a dependent branch + isync is enough. | 
|  | 8390 | // See http://www.cl.cam.ac.uk/~pes20/cpp/cpp0xmappings.html and | 
|  | 8391 | // http://www.rdrop.com/users/paulmck/scalability/paper/N2745r.2011.03.04a.html | 
|  | 8392 | // and http://www.cl.cam.ac.uk/~pes20/cppppc/ for justification. | 
| David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 8393 | return nullptr; | 
| Robin Morisset | 2212996 | 2014-09-23 20:46:49 +0000 | [diff] [blame] | 8394 | } | 
|  | 8395 |  | 
| Chris Lattner | 9b577f1 | 2005-08-26 21:23:58 +0000 | [diff] [blame] | 8396 | MachineBasicBlock * | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8397 | PPCTargetLowering::EmitAtomicBinary(MachineInstr &MI, MachineBasicBlock *BB, | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 8398 | unsigned AtomicSize, | 
| Hal Finkel | 5728200 | 2016-08-28 16:17:58 +0000 | [diff] [blame] | 8399 | unsigned BinOpcode, | 
|  | 8400 | unsigned CmpOpcode, | 
|  | 8401 | unsigned CmpPred) const { | 
| Dale Johannesen | f0a88d6 | 2008-08-29 18:29:46 +0000 | [diff] [blame] | 8402 | // This also handles ATOMIC_SWAP, indicated by BinOpcode==0. | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 8403 | const TargetInstrInfo *TII = Subtarget.getInstrInfo(); | 
| Dale Johannesen | d4eb052 | 2008-08-25 22:34:37 +0000 | [diff] [blame] | 8404 |  | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 8405 | auto LoadMnemonic = PPC::LDARX; | 
|  | 8406 | auto StoreMnemonic = PPC::STDCX; | 
|  | 8407 | switch (AtomicSize) { | 
|  | 8408 | default: | 
|  | 8409 | llvm_unreachable("Unexpected size of atomic entity"); | 
|  | 8410 | case 1: | 
|  | 8411 | LoadMnemonic = PPC::LBARX; | 
|  | 8412 | StoreMnemonic = PPC::STBCX; | 
|  | 8413 | assert(Subtarget.hasPartwordAtomics() && "Call this only with size >=4"); | 
|  | 8414 | break; | 
|  | 8415 | case 2: | 
|  | 8416 | LoadMnemonic = PPC::LHARX; | 
|  | 8417 | StoreMnemonic = PPC::STHCX; | 
|  | 8418 | assert(Subtarget.hasPartwordAtomics() && "Call this only with size >=4"); | 
|  | 8419 | break; | 
|  | 8420 | case 4: | 
|  | 8421 | LoadMnemonic = PPC::LWARX; | 
|  | 8422 | StoreMnemonic = PPC::STWCX; | 
|  | 8423 | break; | 
|  | 8424 | case 8: | 
|  | 8425 | LoadMnemonic = PPC::LDARX; | 
|  | 8426 | StoreMnemonic = PPC::STDCX; | 
|  | 8427 | break; | 
|  | 8428 | } | 
|  | 8429 |  | 
| Dale Johannesen | d4eb052 | 2008-08-25 22:34:37 +0000 | [diff] [blame] | 8430 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); | 
|  | 8431 | MachineFunction *F = BB->getParent(); | 
| Duncan P. N. Exon Smith | ac65b4c | 2015-10-20 01:07:37 +0000 | [diff] [blame] | 8432 | MachineFunction::iterator It = ++BB->getIterator(); | 
| Dale Johannesen | d4eb052 | 2008-08-25 22:34:37 +0000 | [diff] [blame] | 8433 |  | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8434 | unsigned dest = MI.getOperand(0).getReg(); | 
|  | 8435 | unsigned ptrA = MI.getOperand(1).getReg(); | 
|  | 8436 | unsigned ptrB = MI.getOperand(2).getReg(); | 
|  | 8437 | unsigned incr = MI.getOperand(3).getReg(); | 
|  | 8438 | DebugLoc dl = MI.getDebugLoc(); | 
| Dale Johannesen | d4eb052 | 2008-08-25 22:34:37 +0000 | [diff] [blame] | 8439 |  | 
|  | 8440 | MachineBasicBlock *loopMBB = F->CreateMachineBasicBlock(LLVM_BB); | 
| Hal Finkel | 5728200 | 2016-08-28 16:17:58 +0000 | [diff] [blame] | 8441 | MachineBasicBlock *loop2MBB = | 
|  | 8442 | CmpOpcode ? F->CreateMachineBasicBlock(LLVM_BB) : nullptr; | 
| Dale Johannesen | d4eb052 | 2008-08-25 22:34:37 +0000 | [diff] [blame] | 8443 | MachineBasicBlock *exitMBB = F->CreateMachineBasicBlock(LLVM_BB); | 
|  | 8444 | F->insert(It, loopMBB); | 
| Hal Finkel | 5728200 | 2016-08-28 16:17:58 +0000 | [diff] [blame] | 8445 | if (CmpOpcode) | 
|  | 8446 | F->insert(It, loop2MBB); | 
| Dale Johannesen | d4eb052 | 2008-08-25 22:34:37 +0000 | [diff] [blame] | 8447 | F->insert(It, exitMBB); | 
| Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 8448 | exitMBB->splice(exitMBB->begin(), BB, | 
| Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 8449 | std::next(MachineBasicBlock::iterator(MI)), BB->end()); | 
| Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 8450 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); | 
| Dale Johannesen | d4eb052 | 2008-08-25 22:34:37 +0000 | [diff] [blame] | 8451 |  | 
|  | 8452 | MachineRegisterInfo &RegInfo = F->getRegInfo(); | 
| Dale Johannesen | f0a88d6 | 2008-08-29 18:29:46 +0000 | [diff] [blame] | 8453 | unsigned TmpReg = (!BinOpcode) ? incr : | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 8454 | RegInfo.createVirtualRegister( AtomicSize == 8 ? &PPC::G8RCRegClass | 
| Craig Topper | 61e88f4 | 2014-11-21 05:58:21 +0000 | [diff] [blame] | 8455 | : &PPC::GPRCRegClass); | 
| Dale Johannesen | d4eb052 | 2008-08-25 22:34:37 +0000 | [diff] [blame] | 8456 |  | 
|  | 8457 | //  thisMBB: | 
|  | 8458 | //   ... | 
|  | 8459 | //   fallthrough --> loopMBB | 
|  | 8460 | BB->addSuccessor(loopMBB); | 
|  | 8461 |  | 
|  | 8462 | //  loopMBB: | 
|  | 8463 | //   l[wd]arx dest, ptr | 
|  | 8464 | //   add r0, dest, incr | 
|  | 8465 | //   st[wd]cx. r0, ptr | 
|  | 8466 | //   bne- loopMBB | 
|  | 8467 | //   fallthrough --> exitMBB | 
| Hal Finkel | 5728200 | 2016-08-28 16:17:58 +0000 | [diff] [blame] | 8468 |  | 
|  | 8469 | // For max/min... | 
|  | 8470 | //  loopMBB: | 
|  | 8471 | //   l[wd]arx dest, ptr | 
|  | 8472 | //   cmpl?[wd] incr, dest | 
|  | 8473 | //   bgt exitMBB | 
|  | 8474 | //  loop2MBB: | 
|  | 8475 | //   st[wd]cx. dest, ptr | 
|  | 8476 | //   bne- loopMBB | 
|  | 8477 | //   fallthrough --> exitMBB | 
|  | 8478 |  | 
| Dale Johannesen | d4eb052 | 2008-08-25 22:34:37 +0000 | [diff] [blame] | 8479 | BB = loopMBB; | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 8480 | BuildMI(BB, dl, TII->get(LoadMnemonic), dest) | 
| Dale Johannesen | d4eb052 | 2008-08-25 22:34:37 +0000 | [diff] [blame] | 8481 | .addReg(ptrA).addReg(ptrB); | 
| Dale Johannesen | f0a88d6 | 2008-08-29 18:29:46 +0000 | [diff] [blame] | 8482 | if (BinOpcode) | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 8483 | BuildMI(BB, dl, TII->get(BinOpcode), TmpReg).addReg(incr).addReg(dest); | 
| Hal Finkel | 5728200 | 2016-08-28 16:17:58 +0000 | [diff] [blame] | 8484 | if (CmpOpcode) { | 
|  | 8485 | BuildMI(BB, dl, TII->get(CmpOpcode), PPC::CR0) | 
|  | 8486 | .addReg(incr).addReg(dest); | 
|  | 8487 | BuildMI(BB, dl, TII->get(PPC::BCC)) | 
|  | 8488 | .addImm(CmpPred).addReg(PPC::CR0).addMBB(exitMBB); | 
|  | 8489 | BB->addSuccessor(loop2MBB); | 
|  | 8490 | BB->addSuccessor(exitMBB); | 
|  | 8491 | BB = loop2MBB; | 
|  | 8492 | } | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 8493 | BuildMI(BB, dl, TII->get(StoreMnemonic)) | 
| Dale Johannesen | d4eb052 | 2008-08-25 22:34:37 +0000 | [diff] [blame] | 8494 | .addReg(TmpReg).addReg(ptrA).addReg(ptrB); | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 8495 | BuildMI(BB, dl, TII->get(PPC::BCC)) | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 8496 | .addImm(PPC::PRED_NE).addReg(PPC::CR0).addMBB(loopMBB); | 
| Dale Johannesen | d4eb052 | 2008-08-25 22:34:37 +0000 | [diff] [blame] | 8497 | BB->addSuccessor(loopMBB); | 
|  | 8498 | BB->addSuccessor(exitMBB); | 
|  | 8499 |  | 
|  | 8500 | //  exitMBB: | 
|  | 8501 | //   ... | 
|  | 8502 | BB = exitMBB; | 
|  | 8503 | return BB; | 
|  | 8504 | } | 
|  | 8505 |  | 
|  | 8506 | MachineBasicBlock * | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8507 | PPCTargetLowering::EmitPartwordAtomicBinary(MachineInstr &MI, | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8508 | MachineBasicBlock *BB, | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8509 | bool is8bit, // operation | 
| Hal Finkel | 5728200 | 2016-08-28 16:17:58 +0000 | [diff] [blame] | 8510 | unsigned BinOpcode, | 
|  | 8511 | unsigned CmpOpcode, | 
|  | 8512 | unsigned CmpPred) const { | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 8513 | // If we support part-word atomic mnemonics, just use them | 
|  | 8514 | if (Subtarget.hasPartwordAtomics()) | 
| Hal Finkel | 5728200 | 2016-08-28 16:17:58 +0000 | [diff] [blame] | 8515 | return EmitAtomicBinary(MI, BB, is8bit ? 1 : 2, BinOpcode, | 
|  | 8516 | CmpOpcode, CmpPred); | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 8517 |  | 
| Dale Johannesen | f0a88d6 | 2008-08-29 18:29:46 +0000 | [diff] [blame] | 8518 | // This also handles ATOMIC_SWAP, indicated by BinOpcode==0. | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 8519 | const TargetInstrInfo *TII = Subtarget.getInstrInfo(); | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8520 | // In 64 bit mode we have to use 64 bits for addresses, even though the | 
|  | 8521 | // lwarx/stwcx are 32 bits.  With the 32-bit atomics we can use address | 
|  | 8522 | // registers without caring whether they're 32 or 64, but here we're | 
|  | 8523 | // doing actual arithmetic on the addresses. | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 8524 | bool is64bit = Subtarget.isPPC64(); | 
| Hal Finkel | 3d70a9d | 2016-08-29 22:25:36 +0000 | [diff] [blame] | 8525 | bool isLittleEndian = Subtarget.isLittleEndian(); | 
| Hal Finkel | f70c41e | 2013-03-21 23:45:03 +0000 | [diff] [blame] | 8526 | unsigned ZeroReg = is64bit ? PPC::ZERO8 : PPC::ZERO; | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8527 |  | 
|  | 8528 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); | 
|  | 8529 | MachineFunction *F = BB->getParent(); | 
| Duncan P. N. Exon Smith | ac65b4c | 2015-10-20 01:07:37 +0000 | [diff] [blame] | 8530 | MachineFunction::iterator It = ++BB->getIterator(); | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8531 |  | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8532 | unsigned dest = MI.getOperand(0).getReg(); | 
|  | 8533 | unsigned ptrA = MI.getOperand(1).getReg(); | 
|  | 8534 | unsigned ptrB = MI.getOperand(2).getReg(); | 
|  | 8535 | unsigned incr = MI.getOperand(3).getReg(); | 
|  | 8536 | DebugLoc dl = MI.getDebugLoc(); | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8537 |  | 
|  | 8538 | MachineBasicBlock *loopMBB = F->CreateMachineBasicBlock(LLVM_BB); | 
| Hal Finkel | 5728200 | 2016-08-28 16:17:58 +0000 | [diff] [blame] | 8539 | MachineBasicBlock *loop2MBB = | 
|  | 8540 | CmpOpcode ? F->CreateMachineBasicBlock(LLVM_BB) : nullptr; | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8541 | MachineBasicBlock *exitMBB = F->CreateMachineBasicBlock(LLVM_BB); | 
|  | 8542 | F->insert(It, loopMBB); | 
| Hal Finkel | 5728200 | 2016-08-28 16:17:58 +0000 | [diff] [blame] | 8543 | if (CmpOpcode) | 
|  | 8544 | F->insert(It, loop2MBB); | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8545 | F->insert(It, exitMBB); | 
| Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 8546 | exitMBB->splice(exitMBB->begin(), BB, | 
| Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 8547 | std::next(MachineBasicBlock::iterator(MI)), BB->end()); | 
| Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 8548 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8549 |  | 
|  | 8550 | MachineRegisterInfo &RegInfo = F->getRegInfo(); | 
| Craig Topper | 61e88f4 | 2014-11-21 05:58:21 +0000 | [diff] [blame] | 8551 | const TargetRegisterClass *RC = is64bit ? &PPC::G8RCRegClass | 
|  | 8552 | : &PPC::GPRCRegClass; | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8553 | unsigned PtrReg = RegInfo.createVirtualRegister(RC); | 
|  | 8554 | unsigned Shift1Reg = RegInfo.createVirtualRegister(RC); | 
| Hal Finkel | 3d70a9d | 2016-08-29 22:25:36 +0000 | [diff] [blame] | 8555 | unsigned ShiftReg = | 
|  | 8556 | isLittleEndian ? Shift1Reg : RegInfo.createVirtualRegister(RC); | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8557 | unsigned Incr2Reg = RegInfo.createVirtualRegister(RC); | 
|  | 8558 | unsigned MaskReg = RegInfo.createVirtualRegister(RC); | 
|  | 8559 | unsigned Mask2Reg = RegInfo.createVirtualRegister(RC); | 
|  | 8560 | unsigned Mask3Reg = RegInfo.createVirtualRegister(RC); | 
|  | 8561 | unsigned Tmp2Reg = RegInfo.createVirtualRegister(RC); | 
|  | 8562 | unsigned Tmp3Reg = RegInfo.createVirtualRegister(RC); | 
|  | 8563 | unsigned Tmp4Reg = RegInfo.createVirtualRegister(RC); | 
| Dale Johannesen | f0a88d6 | 2008-08-29 18:29:46 +0000 | [diff] [blame] | 8564 | unsigned TmpDestReg = RegInfo.createVirtualRegister(RC); | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8565 | unsigned Ptr1Reg; | 
| Dale Johannesen | f0a88d6 | 2008-08-29 18:29:46 +0000 | [diff] [blame] | 8566 | unsigned TmpReg = (!BinOpcode) ? Incr2Reg : RegInfo.createVirtualRegister(RC); | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8567 |  | 
|  | 8568 | //  thisMBB: | 
|  | 8569 | //   ... | 
|  | 8570 | //   fallthrough --> loopMBB | 
|  | 8571 | BB->addSuccessor(loopMBB); | 
|  | 8572 |  | 
|  | 8573 | // The 4-byte load must be aligned, while a char or short may be | 
|  | 8574 | // anywhere in the word.  Hence all this nasty bookkeeping code. | 
|  | 8575 | //   add ptr1, ptrA, ptrB [copy if ptrA==0] | 
|  | 8576 | //   rlwinm shift1, ptr1, 3, 27, 28 [3, 27, 27] | 
| Dale Johannesen | bc69829 | 2008-09-02 20:30:23 +0000 | [diff] [blame] | 8577 | //   xori shift, shift1, 24 [16] | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8578 | //   rlwinm ptr, ptr1, 0, 0, 29 | 
|  | 8579 | //   slw incr2, incr, shift | 
|  | 8580 | //   li mask2, 255 [li mask3, 0; ori mask2, mask3, 65535] | 
|  | 8581 | //   slw mask, mask2, shift | 
|  | 8582 | //  loopMBB: | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 8583 | //   lwarx tmpDest, ptr | 
| Dale Johannesen | f0a88d6 | 2008-08-29 18:29:46 +0000 | [diff] [blame] | 8584 | //   add tmp, tmpDest, incr2 | 
|  | 8585 | //   andc tmp2, tmpDest, mask | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8586 | //   and tmp3, tmp, mask | 
|  | 8587 | //   or tmp4, tmp3, tmp2 | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 8588 | //   stwcx. tmp4, ptr | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8589 | //   bne- loopMBB | 
|  | 8590 | //   fallthrough --> exitMBB | 
| Dale Johannesen | f0a88d6 | 2008-08-29 18:29:46 +0000 | [diff] [blame] | 8591 | //   srw dest, tmpDest, shift | 
| Jakob Stoklund Olesen | 7067bff | 2011-04-04 17:07:06 +0000 | [diff] [blame] | 8592 | if (ptrA != ZeroReg) { | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8593 | Ptr1Reg = RegInfo.createVirtualRegister(RC); | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 8594 | BuildMI(BB, dl, TII->get(is64bit ? PPC::ADD8 : PPC::ADD4), Ptr1Reg) | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8595 | .addReg(ptrA).addReg(ptrB); | 
|  | 8596 | } else { | 
|  | 8597 | Ptr1Reg = ptrB; | 
|  | 8598 | } | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 8599 | BuildMI(BB, dl, TII->get(PPC::RLWINM), Shift1Reg).addReg(Ptr1Reg) | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8600 | .addImm(3).addImm(27).addImm(is8bit ? 28 : 27); | 
| Hal Finkel | 3d70a9d | 2016-08-29 22:25:36 +0000 | [diff] [blame] | 8601 | if (!isLittleEndian) | 
|  | 8602 | BuildMI(BB, dl, TII->get(is64bit ? PPC::XORI8 : PPC::XORI), ShiftReg) | 
|  | 8603 | .addReg(Shift1Reg).addImm(is8bit ? 24 : 16); | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8604 | if (is64bit) | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 8605 | BuildMI(BB, dl, TII->get(PPC::RLDICR), PtrReg) | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8606 | .addReg(Ptr1Reg).addImm(0).addImm(61); | 
|  | 8607 | else | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 8608 | BuildMI(BB, dl, TII->get(PPC::RLWINM), PtrReg) | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8609 | .addReg(Ptr1Reg).addImm(0).addImm(0).addImm(29); | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 8610 | BuildMI(BB, dl, TII->get(PPC::SLW), Incr2Reg) | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8611 | .addReg(incr).addReg(ShiftReg); | 
|  | 8612 | if (is8bit) | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 8613 | BuildMI(BB, dl, TII->get(PPC::LI), Mask2Reg).addImm(255); | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8614 | else { | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 8615 | BuildMI(BB, dl, TII->get(PPC::LI), Mask3Reg).addImm(0); | 
|  | 8616 | BuildMI(BB, dl, TII->get(PPC::ORI),Mask2Reg).addReg(Mask3Reg).addImm(65535); | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8617 | } | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 8618 | BuildMI(BB, dl, TII->get(PPC::SLW), MaskReg) | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8619 | .addReg(Mask2Reg).addReg(ShiftReg); | 
|  | 8620 |  | 
|  | 8621 | BB = loopMBB; | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 8622 | BuildMI(BB, dl, TII->get(PPC::LWARX), TmpDestReg) | 
| Jakob Stoklund Olesen | 7067bff | 2011-04-04 17:07:06 +0000 | [diff] [blame] | 8623 | .addReg(ZeroReg).addReg(PtrReg); | 
| Dale Johannesen | f0a88d6 | 2008-08-29 18:29:46 +0000 | [diff] [blame] | 8624 | if (BinOpcode) | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 8625 | BuildMI(BB, dl, TII->get(BinOpcode), TmpReg) | 
| Dale Johannesen | f0a88d6 | 2008-08-29 18:29:46 +0000 | [diff] [blame] | 8626 | .addReg(Incr2Reg).addReg(TmpDestReg); | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 8627 | BuildMI(BB, dl, TII->get(is64bit ? PPC::ANDC8 : PPC::ANDC), Tmp2Reg) | 
| Dale Johannesen | f0a88d6 | 2008-08-29 18:29:46 +0000 | [diff] [blame] | 8628 | .addReg(TmpDestReg).addReg(MaskReg); | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 8629 | BuildMI(BB, dl, TII->get(is64bit ? PPC::AND8 : PPC::AND), Tmp3Reg) | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8630 | .addReg(TmpReg).addReg(MaskReg); | 
| Hal Finkel | 5728200 | 2016-08-28 16:17:58 +0000 | [diff] [blame] | 8631 | if (CmpOpcode) { | 
|  | 8632 | // For unsigned comparisons, we can directly compare the shifted values. | 
|  | 8633 | // For signed comparisons we shift and sign extend. | 
|  | 8634 | unsigned SReg = RegInfo.createVirtualRegister(RC); | 
|  | 8635 | BuildMI(BB, dl, TII->get(is64bit ? PPC::AND8 : PPC::AND), SReg) | 
|  | 8636 | .addReg(TmpDestReg).addReg(MaskReg); | 
|  | 8637 | unsigned ValueReg = SReg; | 
|  | 8638 | unsigned CmpReg = Incr2Reg; | 
|  | 8639 | if (CmpOpcode == PPC::CMPW) { | 
|  | 8640 | ValueReg = RegInfo.createVirtualRegister(RC); | 
|  | 8641 | BuildMI(BB, dl, TII->get(PPC::SRW), ValueReg) | 
|  | 8642 | .addReg(SReg).addReg(ShiftReg); | 
|  | 8643 | unsigned ValueSReg = RegInfo.createVirtualRegister(RC); | 
|  | 8644 | BuildMI(BB, dl, TII->get(is8bit ? PPC::EXTSB : PPC::EXTSH), ValueSReg) | 
|  | 8645 | .addReg(ValueReg); | 
|  | 8646 | ValueReg = ValueSReg; | 
|  | 8647 | CmpReg = incr; | 
|  | 8648 | } | 
|  | 8649 | BuildMI(BB, dl, TII->get(CmpOpcode), PPC::CR0) | 
|  | 8650 | .addReg(CmpReg).addReg(ValueReg); | 
|  | 8651 | BuildMI(BB, dl, TII->get(PPC::BCC)) | 
|  | 8652 | .addImm(CmpPred).addReg(PPC::CR0).addMBB(exitMBB); | 
|  | 8653 | BB->addSuccessor(loop2MBB); | 
|  | 8654 | BB->addSuccessor(exitMBB); | 
|  | 8655 | BB = loop2MBB; | 
|  | 8656 | } | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 8657 | BuildMI(BB, dl, TII->get(is64bit ? PPC::OR8 : PPC::OR), Tmp4Reg) | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8658 | .addReg(Tmp3Reg).addReg(Tmp2Reg); | 
| Bill Schmidt | 3581cd4 | 2013-04-02 18:37:08 +0000 | [diff] [blame] | 8659 | BuildMI(BB, dl, TII->get(PPC::STWCX)) | 
| Jakob Stoklund Olesen | 7067bff | 2011-04-04 17:07:06 +0000 | [diff] [blame] | 8660 | .addReg(Tmp4Reg).addReg(ZeroReg).addReg(PtrReg); | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 8661 | BuildMI(BB, dl, TII->get(PPC::BCC)) | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 8662 | .addImm(PPC::PRED_NE).addReg(PPC::CR0).addMBB(loopMBB); | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8663 | BB->addSuccessor(loopMBB); | 
|  | 8664 | BB->addSuccessor(exitMBB); | 
|  | 8665 |  | 
|  | 8666 | //  exitMBB: | 
|  | 8667 | //   ... | 
|  | 8668 | BB = exitMBB; | 
| Jakob Stoklund Olesen | 13ce236 | 2011-04-04 17:57:29 +0000 | [diff] [blame] | 8669 | BuildMI(*BB, BB->begin(), dl, TII->get(PPC::SRW), dest).addReg(TmpDestReg) | 
|  | 8670 | .addReg(ShiftReg); | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8671 | return BB; | 
|  | 8672 | } | 
|  | 8673 |  | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8674 | llvm::MachineBasicBlock * | 
|  | 8675 | PPCTargetLowering::emitEHSjLjSetJmp(MachineInstr &MI, | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8676 | MachineBasicBlock *MBB) const { | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8677 | DebugLoc DL = MI.getDebugLoc(); | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 8678 | const TargetInstrInfo *TII = Subtarget.getInstrInfo(); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8679 |  | 
|  | 8680 | MachineFunction *MF = MBB->getParent(); | 
|  | 8681 | MachineRegisterInfo &MRI = MF->getRegInfo(); | 
|  | 8682 |  | 
|  | 8683 | const BasicBlock *BB = MBB->getBasicBlock(); | 
| Duncan P. N. Exon Smith | ac65b4c | 2015-10-20 01:07:37 +0000 | [diff] [blame] | 8684 | MachineFunction::iterator I = ++MBB->getIterator(); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8685 |  | 
|  | 8686 | // Memory Reference | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8687 | MachineInstr::mmo_iterator MMOBegin = MI.memoperands_begin(); | 
|  | 8688 | MachineInstr::mmo_iterator MMOEnd = MI.memoperands_end(); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8689 |  | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8690 | unsigned DstReg = MI.getOperand(0).getReg(); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8691 | const TargetRegisterClass *RC = MRI.getRegClass(DstReg); | 
|  | 8692 | assert(RC->hasType(MVT::i32) && "Invalid destination!"); | 
|  | 8693 | unsigned mainDstReg = MRI.createVirtualRegister(RC); | 
|  | 8694 | unsigned restoreDstReg = MRI.createVirtualRegister(RC); | 
|  | 8695 |  | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 8696 | MVT PVT = getPointerTy(MF->getDataLayout()); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8697 | assert((PVT == MVT::i64 || PVT == MVT::i32) && | 
|  | 8698 | "Invalid Pointer Size!"); | 
|  | 8699 | // For v = setjmp(buf), we generate | 
|  | 8700 | // | 
|  | 8701 | // thisMBB: | 
|  | 8702 | //  SjLjSetup mainMBB | 
|  | 8703 | //  bl mainMBB | 
|  | 8704 | //  v_restore = 1 | 
|  | 8705 | //  b sinkMBB | 
|  | 8706 | // | 
|  | 8707 | // mainMBB: | 
|  | 8708 | //  buf[LabelOffset] = LR | 
|  | 8709 | //  v_main = 0 | 
|  | 8710 | // | 
|  | 8711 | // sinkMBB: | 
|  | 8712 | //  v = phi(main, restore) | 
|  | 8713 | // | 
|  | 8714 |  | 
|  | 8715 | MachineBasicBlock *thisMBB = MBB; | 
|  | 8716 | MachineBasicBlock *mainMBB = MF->CreateMachineBasicBlock(BB); | 
|  | 8717 | MachineBasicBlock *sinkMBB = MF->CreateMachineBasicBlock(BB); | 
|  | 8718 | MF->insert(I, mainMBB); | 
|  | 8719 | MF->insert(I, sinkMBB); | 
|  | 8720 |  | 
|  | 8721 | MachineInstrBuilder MIB; | 
|  | 8722 |  | 
|  | 8723 | // Transfer the remainder of BB and its successor edges to sinkMBB. | 
|  | 8724 | sinkMBB->splice(sinkMBB->begin(), MBB, | 
| Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 8725 | std::next(MachineBasicBlock::iterator(MI)), MBB->end()); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8726 | sinkMBB->transferSuccessorsAndUpdatePHIs(MBB); | 
|  | 8727 |  | 
|  | 8728 | // Note that the structure of the jmp_buf used here is not compatible | 
|  | 8729 | // with that used by libc, and is not designed to be. Specifically, it | 
|  | 8730 | // stores only those 'reserved' registers that LLVM does not otherwise | 
|  | 8731 | // understand how to spill. Also, by convention, by the time this | 
|  | 8732 | // intrinsic is called, Clang has already stored the frame address in the | 
|  | 8733 | // first slot of the buffer and stack address in the third. Following the | 
|  | 8734 | // X86 target code, we'll store the jump address in the second slot. We also | 
|  | 8735 | // need to save the TOC pointer (R2) to handle jumps between shared | 
|  | 8736 | // libraries, and that will be stored in the fourth slot. The thread | 
|  | 8737 | // identifier (R13) is not affected. | 
|  | 8738 |  | 
|  | 8739 | // thisMBB: | 
|  | 8740 | const int64_t LabelOffset = 1 * PVT.getStoreSize(); | 
|  | 8741 | const int64_t TOCOffset   = 3 * PVT.getStoreSize(); | 
| Hal Finkel | f05d6c7 | 2013-07-17 23:50:51 +0000 | [diff] [blame] | 8742 | const int64_t BPOffset    = 4 * PVT.getStoreSize(); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8743 |  | 
|  | 8744 | // Prepare IP either in reg. | 
|  | 8745 | const TargetRegisterClass *PtrRC = getRegClassFor(PVT); | 
|  | 8746 | unsigned LabelReg = MRI.createVirtualRegister(PtrRC); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8747 | unsigned BufReg = MI.getOperand(1).getReg(); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8748 |  | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 8749 | if (Subtarget.isPPC64() && Subtarget.isSVR4ABI()) { | 
| Hal Finkel | e6698d5 | 2015-02-01 15:03:28 +0000 | [diff] [blame] | 8750 | setUsesTOCBasePtr(*MBB->getParent()); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8751 | MIB = BuildMI(*thisMBB, MI, DL, TII->get(PPC::STD)) | 
|  | 8752 | .addReg(PPC::X2) | 
| Ulrich Weigand | 9d980cb | 2013-05-16 17:58:02 +0000 | [diff] [blame] | 8753 | .addImm(TOCOffset) | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8754 | .addReg(BufReg); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8755 | MIB.setMemRefs(MMOBegin, MMOEnd); | 
|  | 8756 | } | 
|  | 8757 |  | 
| Hal Finkel | f05d6c7 | 2013-07-17 23:50:51 +0000 | [diff] [blame] | 8758 | // Naked functions never have a base pointer, and so we use r1. For all | 
|  | 8759 | // other functions, this decision must be delayed until during PEI. | 
|  | 8760 | unsigned BaseReg; | 
| Duncan P. N. Exon Smith | 5bedaf93 | 2015-02-14 02:54:07 +0000 | [diff] [blame] | 8761 | if (MF->getFunction()->hasFnAttribute(Attribute::Naked)) | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 8762 | BaseReg = Subtarget.isPPC64() ? PPC::X1 : PPC::R1; | 
| Hal Finkel | f05d6c7 | 2013-07-17 23:50:51 +0000 | [diff] [blame] | 8763 | else | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 8764 | BaseReg = Subtarget.isPPC64() ? PPC::BP8 : PPC::BP; | 
| Hal Finkel | f05d6c7 | 2013-07-17 23:50:51 +0000 | [diff] [blame] | 8765 |  | 
|  | 8766 | MIB = BuildMI(*thisMBB, MI, DL, | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 8767 | TII->get(Subtarget.isPPC64() ? PPC::STD : PPC::STW)) | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 8768 | .addReg(BaseReg) | 
|  | 8769 | .addImm(BPOffset) | 
|  | 8770 | .addReg(BufReg); | 
| Hal Finkel | f05d6c7 | 2013-07-17 23:50:51 +0000 | [diff] [blame] | 8771 | MIB.setMemRefs(MMOBegin, MMOEnd); | 
|  | 8772 |  | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8773 | // Setup | 
| Hal Finkel | e5680b3 | 2013-04-04 22:55:54 +0000 | [diff] [blame] | 8774 | MIB = BuildMI(*thisMBB, MI, DL, TII->get(PPC::BCLalways)).addMBB(mainMBB); | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 8775 | const PPCRegisterInfo *TRI = Subtarget.getRegisterInfo(); | 
| Bill Wendling | 5e7656b | 2013-06-07 07:55:53 +0000 | [diff] [blame] | 8776 | MIB.addRegMask(TRI->getNoPreservedMask()); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8777 |  | 
|  | 8778 | BuildMI(*thisMBB, MI, DL, TII->get(PPC::LI), restoreDstReg).addImm(1); | 
|  | 8779 |  | 
|  | 8780 | MIB = BuildMI(*thisMBB, MI, DL, TII->get(PPC::EH_SjLj_Setup)) | 
|  | 8781 | .addMBB(mainMBB); | 
|  | 8782 | MIB = BuildMI(*thisMBB, MI, DL, TII->get(PPC::B)).addMBB(sinkMBB); | 
|  | 8783 |  | 
| Cong Hou | 1938f2e | 2015-11-24 08:51:23 +0000 | [diff] [blame] | 8784 | thisMBB->addSuccessor(mainMBB, BranchProbability::getZero()); | 
|  | 8785 | thisMBB->addSuccessor(sinkMBB, BranchProbability::getOne()); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8786 |  | 
|  | 8787 | // mainMBB: | 
|  | 8788 | //  mainDstReg = 0 | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 8789 | MIB = | 
|  | 8790 | BuildMI(mainMBB, DL, | 
|  | 8791 | TII->get(Subtarget.isPPC64() ? PPC::MFLR8 : PPC::MFLR), LabelReg); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8792 |  | 
|  | 8793 | // Store IP | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 8794 | if (Subtarget.isPPC64()) { | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8795 | MIB = BuildMI(mainMBB, DL, TII->get(PPC::STD)) | 
|  | 8796 | .addReg(LabelReg) | 
| Ulrich Weigand | 9d980cb | 2013-05-16 17:58:02 +0000 | [diff] [blame] | 8797 | .addImm(LabelOffset) | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8798 | .addReg(BufReg); | 
|  | 8799 | } else { | 
|  | 8800 | MIB = BuildMI(mainMBB, DL, TII->get(PPC::STW)) | 
|  | 8801 | .addReg(LabelReg) | 
|  | 8802 | .addImm(LabelOffset) | 
|  | 8803 | .addReg(BufReg); | 
|  | 8804 | } | 
|  | 8805 |  | 
|  | 8806 | MIB.setMemRefs(MMOBegin, MMOEnd); | 
|  | 8807 |  | 
|  | 8808 | BuildMI(mainMBB, DL, TII->get(PPC::LI), mainDstReg).addImm(0); | 
|  | 8809 | mainMBB->addSuccessor(sinkMBB); | 
|  | 8810 |  | 
|  | 8811 | // sinkMBB: | 
|  | 8812 | BuildMI(*sinkMBB, sinkMBB->begin(), DL, | 
|  | 8813 | TII->get(PPC::PHI), DstReg) | 
|  | 8814 | .addReg(mainDstReg).addMBB(mainMBB) | 
|  | 8815 | .addReg(restoreDstReg).addMBB(thisMBB); | 
|  | 8816 |  | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8817 | MI.eraseFromParent(); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8818 | return sinkMBB; | 
|  | 8819 | } | 
|  | 8820 |  | 
|  | 8821 | MachineBasicBlock * | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8822 | PPCTargetLowering::emitEHSjLjLongJmp(MachineInstr &MI, | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8823 | MachineBasicBlock *MBB) const { | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8824 | DebugLoc DL = MI.getDebugLoc(); | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 8825 | const TargetInstrInfo *TII = Subtarget.getInstrInfo(); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8826 |  | 
|  | 8827 | MachineFunction *MF = MBB->getParent(); | 
|  | 8828 | MachineRegisterInfo &MRI = MF->getRegInfo(); | 
|  | 8829 |  | 
|  | 8830 | // Memory Reference | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8831 | MachineInstr::mmo_iterator MMOBegin = MI.memoperands_begin(); | 
|  | 8832 | MachineInstr::mmo_iterator MMOEnd = MI.memoperands_end(); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8833 |  | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 8834 | MVT PVT = getPointerTy(MF->getDataLayout()); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8835 | assert((PVT == MVT::i64 || PVT == MVT::i32) && | 
|  | 8836 | "Invalid Pointer Size!"); | 
|  | 8837 |  | 
|  | 8838 | const TargetRegisterClass *RC = | 
|  | 8839 | (PVT == MVT::i64) ? &PPC::G8RCRegClass : &PPC::GPRCRegClass; | 
|  | 8840 | unsigned Tmp = MRI.createVirtualRegister(RC); | 
|  | 8841 | // Since FP is only updated here but NOT referenced, it's treated as GPR. | 
|  | 8842 | unsigned FP  = (PVT == MVT::i64) ? PPC::X31 : PPC::R31; | 
|  | 8843 | unsigned SP  = (PVT == MVT::i64) ? PPC::X1 : PPC::R1; | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 8844 | unsigned BP = | 
|  | 8845 | (PVT == MVT::i64) | 
|  | 8846 | ? PPC::X30 | 
| Rafael Espindola | 21d22a0 | 2016-06-27 14:05:43 +0000 | [diff] [blame] | 8847 | : (Subtarget.isSVR4ABI() && isPositionIndependent() ? PPC::R29 | 
|  | 8848 | : PPC::R30); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8849 |  | 
|  | 8850 | MachineInstrBuilder MIB; | 
|  | 8851 |  | 
|  | 8852 | const int64_t LabelOffset = 1 * PVT.getStoreSize(); | 
|  | 8853 | const int64_t SPOffset    = 2 * PVT.getStoreSize(); | 
|  | 8854 | const int64_t TOCOffset   = 3 * PVT.getStoreSize(); | 
| Hal Finkel | f05d6c7 | 2013-07-17 23:50:51 +0000 | [diff] [blame] | 8855 | const int64_t BPOffset    = 4 * PVT.getStoreSize(); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8856 |  | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8857 | unsigned BufReg = MI.getOperand(0).getReg(); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8858 |  | 
|  | 8859 | // Reload FP (the jumped-to function may not have had a | 
|  | 8860 | // frame pointer, and if so, then its r31 will be restored | 
|  | 8861 | // as necessary). | 
|  | 8862 | if (PVT == MVT::i64) { | 
|  | 8863 | MIB = BuildMI(*MBB, MI, DL, TII->get(PPC::LD), FP) | 
|  | 8864 | .addImm(0) | 
|  | 8865 | .addReg(BufReg); | 
|  | 8866 | } else { | 
|  | 8867 | MIB = BuildMI(*MBB, MI, DL, TII->get(PPC::LWZ), FP) | 
|  | 8868 | .addImm(0) | 
|  | 8869 | .addReg(BufReg); | 
|  | 8870 | } | 
|  | 8871 | MIB.setMemRefs(MMOBegin, MMOEnd); | 
|  | 8872 |  | 
|  | 8873 | // Reload IP | 
|  | 8874 | if (PVT == MVT::i64) { | 
|  | 8875 | MIB = BuildMI(*MBB, MI, DL, TII->get(PPC::LD), Tmp) | 
| Ulrich Weigand | 9d980cb | 2013-05-16 17:58:02 +0000 | [diff] [blame] | 8876 | .addImm(LabelOffset) | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8877 | .addReg(BufReg); | 
|  | 8878 | } else { | 
|  | 8879 | MIB = BuildMI(*MBB, MI, DL, TII->get(PPC::LWZ), Tmp) | 
|  | 8880 | .addImm(LabelOffset) | 
|  | 8881 | .addReg(BufReg); | 
|  | 8882 | } | 
|  | 8883 | MIB.setMemRefs(MMOBegin, MMOEnd); | 
|  | 8884 |  | 
|  | 8885 | // Reload SP | 
|  | 8886 | if (PVT == MVT::i64) { | 
|  | 8887 | MIB = BuildMI(*MBB, MI, DL, TII->get(PPC::LD), SP) | 
| Ulrich Weigand | 9d980cb | 2013-05-16 17:58:02 +0000 | [diff] [blame] | 8888 | .addImm(SPOffset) | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8889 | .addReg(BufReg); | 
|  | 8890 | } else { | 
|  | 8891 | MIB = BuildMI(*MBB, MI, DL, TII->get(PPC::LWZ), SP) | 
|  | 8892 | .addImm(SPOffset) | 
|  | 8893 | .addReg(BufReg); | 
|  | 8894 | } | 
|  | 8895 | MIB.setMemRefs(MMOBegin, MMOEnd); | 
|  | 8896 |  | 
| Hal Finkel | f05d6c7 | 2013-07-17 23:50:51 +0000 | [diff] [blame] | 8897 | // Reload BP | 
|  | 8898 | if (PVT == MVT::i64) { | 
|  | 8899 | MIB = BuildMI(*MBB, MI, DL, TII->get(PPC::LD), BP) | 
|  | 8900 | .addImm(BPOffset) | 
|  | 8901 | .addReg(BufReg); | 
|  | 8902 | } else { | 
|  | 8903 | MIB = BuildMI(*MBB, MI, DL, TII->get(PPC::LWZ), BP) | 
|  | 8904 | .addImm(BPOffset) | 
|  | 8905 | .addReg(BufReg); | 
|  | 8906 | } | 
|  | 8907 | MIB.setMemRefs(MMOBegin, MMOEnd); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8908 |  | 
|  | 8909 | // Reload TOC | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 8910 | if (PVT == MVT::i64 && Subtarget.isSVR4ABI()) { | 
| Hal Finkel | e6698d5 | 2015-02-01 15:03:28 +0000 | [diff] [blame] | 8911 | setUsesTOCBasePtr(*MBB->getParent()); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8912 | MIB = BuildMI(*MBB, MI, DL, TII->get(PPC::LD), PPC::X2) | 
| Ulrich Weigand | 9d980cb | 2013-05-16 17:58:02 +0000 | [diff] [blame] | 8913 | .addImm(TOCOffset) | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8914 | .addReg(BufReg); | 
|  | 8915 |  | 
|  | 8916 | MIB.setMemRefs(MMOBegin, MMOEnd); | 
|  | 8917 | } | 
|  | 8918 |  | 
|  | 8919 | // Jump | 
|  | 8920 | BuildMI(*MBB, MI, DL, | 
|  | 8921 | TII->get(PVT == MVT::i64 ? PPC::MTCTR8 : PPC::MTCTR)).addReg(Tmp); | 
|  | 8922 | BuildMI(*MBB, MI, DL, TII->get(PVT == MVT::i64 ? PPC::BCTR8 : PPC::BCTR)); | 
|  | 8923 |  | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8924 | MI.eraseFromParent(); | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8925 | return MBB; | 
|  | 8926 | } | 
|  | 8927 |  | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 8928 | MachineBasicBlock * | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8929 | PPCTargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI, | 
| Dan Gohman | 25c1653 | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 8930 | MachineBasicBlock *BB) const { | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8931 | if (MI.getOpcode() == TargetOpcode::STACKMAP || | 
|  | 8932 | MI.getOpcode() == TargetOpcode::PATCHPOINT) { | 
| Hal Finkel | af51993 | 2015-01-19 07:20:27 +0000 | [diff] [blame] | 8933 | if (Subtarget.isPPC64() && Subtarget.isSVR4ABI() && | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8934 | MI.getOpcode() == TargetOpcode::PATCHPOINT) { | 
| Hal Finkel | af51993 | 2015-01-19 07:20:27 +0000 | [diff] [blame] | 8935 | // Call lowering should have added an r2 operand to indicate a dependence | 
|  | 8936 | // on the TOC base pointer value. It can't however, because there is no | 
|  | 8937 | // way to mark the dependence as implicit there, and so the stackmap code | 
|  | 8938 | // will confuse it with a regular operand. Instead, add the dependence | 
|  | 8939 | // here. | 
| Hal Finkel | e6698d5 | 2015-02-01 15:03:28 +0000 | [diff] [blame] | 8940 | setUsesTOCBasePtr(*BB->getParent()); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8941 | MI.addOperand(MachineOperand::CreateReg(PPC::X2, false, true)); | 
| Hal Finkel | af51993 | 2015-01-19 07:20:27 +0000 | [diff] [blame] | 8942 | } | 
|  | 8943 |  | 
| Hal Finkel | 934361a | 2015-01-14 01:07:51 +0000 | [diff] [blame] | 8944 | return emitPatchPoint(MI, BB); | 
| Hal Finkel | af51993 | 2015-01-19 07:20:27 +0000 | [diff] [blame] | 8945 | } | 
| Hal Finkel | 934361a | 2015-01-14 01:07:51 +0000 | [diff] [blame] | 8946 |  | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8947 | if (MI.getOpcode() == PPC::EH_SjLj_SetJmp32 || | 
|  | 8948 | MI.getOpcode() == PPC::EH_SjLj_SetJmp64) { | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8949 | return emitEHSjLjSetJmp(MI, BB); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8950 | } else if (MI.getOpcode() == PPC::EH_SjLj_LongJmp32 || | 
|  | 8951 | MI.getOpcode() == PPC::EH_SjLj_LongJmp64) { | 
| Hal Finkel | 756810f | 2013-03-21 21:37:52 +0000 | [diff] [blame] | 8952 | return emitEHSjLjLongJmp(MI, BB); | 
|  | 8953 | } | 
|  | 8954 |  | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 8955 | const TargetInstrInfo *TII = Subtarget.getInstrInfo(); | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 8956 |  | 
|  | 8957 | // To "insert" these instructions we actually have to insert their | 
|  | 8958 | // control-flow patterns. | 
| Chris Lattner | 9b577f1 | 2005-08-26 21:23:58 +0000 | [diff] [blame] | 8959 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); | 
| Duncan P. N. Exon Smith | ac65b4c | 2015-10-20 01:07:37 +0000 | [diff] [blame] | 8960 | MachineFunction::iterator It = ++BB->getIterator(); | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 8961 |  | 
| Dan Gohman | 3b46030 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 8962 | MachineFunction *F = BB->getParent(); | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 8963 |  | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8964 | if (Subtarget.hasISEL() && | 
|  | 8965 | (MI.getOpcode() == PPC::SELECT_CC_I4 || | 
|  | 8966 | MI.getOpcode() == PPC::SELECT_CC_I8 || | 
|  | 8967 | MI.getOpcode() == PPC::SELECT_I4 || MI.getOpcode() == PPC::SELECT_I8)) { | 
| Hal Finkel | ed6a285 | 2013-04-05 23:29:01 +0000 | [diff] [blame] | 8968 | SmallVector<MachineOperand, 2> Cond; | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8969 | if (MI.getOpcode() == PPC::SELECT_CC_I4 || | 
|  | 8970 | MI.getOpcode() == PPC::SELECT_CC_I8) | 
|  | 8971 | Cond.push_back(MI.getOperand(4)); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 8972 | else | 
|  | 8973 | Cond.push_back(MachineOperand::CreateImm(PPC::PRED_BIT_SET)); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8974 | Cond.push_back(MI.getOperand(1)); | 
| Hal Finkel | ed6a285 | 2013-04-05 23:29:01 +0000 | [diff] [blame] | 8975 |  | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 8976 | DebugLoc dl = MI.getDebugLoc(); | 
|  | 8977 | TII->insertSelect(*BB, MI, dl, MI.getOperand(0).getReg(), Cond, | 
|  | 8978 | MI.getOperand(2).getReg(), MI.getOperand(3).getReg()); | 
|  | 8979 | } else if (MI.getOpcode() == PPC::SELECT_CC_I4 || | 
|  | 8980 | MI.getOpcode() == PPC::SELECT_CC_I8 || | 
|  | 8981 | MI.getOpcode() == PPC::SELECT_CC_F4 || | 
|  | 8982 | MI.getOpcode() == PPC::SELECT_CC_F8 || | 
|  | 8983 | MI.getOpcode() == PPC::SELECT_CC_QFRC || | 
|  | 8984 | MI.getOpcode() == PPC::SELECT_CC_QSRC || | 
|  | 8985 | MI.getOpcode() == PPC::SELECT_CC_QBRC || | 
|  | 8986 | MI.getOpcode() == PPC::SELECT_CC_VRRC || | 
|  | 8987 | MI.getOpcode() == PPC::SELECT_CC_VSFRC || | 
|  | 8988 | MI.getOpcode() == PPC::SELECT_CC_VSSRC || | 
|  | 8989 | MI.getOpcode() == PPC::SELECT_CC_VSRC || | 
|  | 8990 | MI.getOpcode() == PPC::SELECT_I4 || | 
|  | 8991 | MI.getOpcode() == PPC::SELECT_I8 || | 
|  | 8992 | MI.getOpcode() == PPC::SELECT_F4 || | 
|  | 8993 | MI.getOpcode() == PPC::SELECT_F8 || | 
|  | 8994 | MI.getOpcode() == PPC::SELECT_QFRC || | 
|  | 8995 | MI.getOpcode() == PPC::SELECT_QSRC || | 
|  | 8996 | MI.getOpcode() == PPC::SELECT_QBRC || | 
|  | 8997 | MI.getOpcode() == PPC::SELECT_VRRC || | 
|  | 8998 | MI.getOpcode() == PPC::SELECT_VSFRC || | 
|  | 8999 | MI.getOpcode() == PPC::SELECT_VSSRC || | 
|  | 9000 | MI.getOpcode() == PPC::SELECT_VSRC) { | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 9001 | // The incoming instruction knows the destination vreg to set, the | 
|  | 9002 | // condition code register to branch on, the true/false values to | 
|  | 9003 | // select between, and a branch opcode to use. | 
|  | 9004 |  | 
|  | 9005 | //  thisMBB: | 
|  | 9006 | //  ... | 
|  | 9007 | //   TrueVal = ... | 
|  | 9008 | //   cmpTY ccX, r1, r2 | 
|  | 9009 | //   bCC copy1MBB | 
|  | 9010 | //   fallthrough --> copy0MBB | 
|  | 9011 | MachineBasicBlock *thisMBB = BB; | 
|  | 9012 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); | 
|  | 9013 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9014 | DebugLoc dl = MI.getDebugLoc(); | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 9015 | F->insert(It, copy0MBB); | 
|  | 9016 | F->insert(It, sinkMBB); | 
| Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 9017 |  | 
|  | 9018 | // Transfer the remainder of BB and its successor edges to sinkMBB. | 
|  | 9019 | sinkMBB->splice(sinkMBB->begin(), BB, | 
| Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 9020 | std::next(MachineBasicBlock::iterator(MI)), BB->end()); | 
| Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 9021 | sinkMBB->transferSuccessorsAndUpdatePHIs(BB); | 
|  | 9022 |  | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 9023 | // Next, add the true and fallthrough blocks as its successors. | 
|  | 9024 | BB->addSuccessor(copy0MBB); | 
|  | 9025 | BB->addSuccessor(sinkMBB); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 9026 |  | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9027 | if (MI.getOpcode() == PPC::SELECT_I4 || MI.getOpcode() == PPC::SELECT_I8 || | 
|  | 9028 | MI.getOpcode() == PPC::SELECT_F4 || MI.getOpcode() == PPC::SELECT_F8 || | 
|  | 9029 | MI.getOpcode() == PPC::SELECT_QFRC || | 
|  | 9030 | MI.getOpcode() == PPC::SELECT_QSRC || | 
|  | 9031 | MI.getOpcode() == PPC::SELECT_QBRC || | 
|  | 9032 | MI.getOpcode() == PPC::SELECT_VRRC || | 
|  | 9033 | MI.getOpcode() == PPC::SELECT_VSFRC || | 
|  | 9034 | MI.getOpcode() == PPC::SELECT_VSSRC || | 
|  | 9035 | MI.getOpcode() == PPC::SELECT_VSRC) { | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 9036 | BuildMI(BB, dl, TII->get(PPC::BC)) | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9037 | .addReg(MI.getOperand(1).getReg()) | 
|  | 9038 | .addMBB(sinkMBB); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 9039 | } else { | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9040 | unsigned SelectPred = MI.getOperand(4).getImm(); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 9041 | BuildMI(BB, dl, TII->get(PPC::BCC)) | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9042 | .addImm(SelectPred) | 
|  | 9043 | .addReg(MI.getOperand(1).getReg()) | 
|  | 9044 | .addMBB(sinkMBB); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 9045 | } | 
| Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 9046 |  | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 9047 | //  copy0MBB: | 
|  | 9048 | //   %FalseValue = ... | 
|  | 9049 | //   # fallthrough to sinkMBB | 
|  | 9050 | BB = copy0MBB; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 9051 |  | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 9052 | // Update machine-CFG edges | 
|  | 9053 | BB->addSuccessor(sinkMBB); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 9054 |  | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 9055 | //  sinkMBB: | 
|  | 9056 | //   %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] | 
|  | 9057 | //  ... | 
|  | 9058 | BB = sinkMBB; | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9059 | BuildMI(*BB, BB->begin(), dl, TII->get(PPC::PHI), MI.getOperand(0).getReg()) | 
|  | 9060 | .addReg(MI.getOperand(3).getReg()) | 
|  | 9061 | .addMBB(copy0MBB) | 
|  | 9062 | .addReg(MI.getOperand(2).getReg()) | 
|  | 9063 | .addMBB(thisMBB); | 
|  | 9064 | } else if (MI.getOpcode() == PPC::ReadTB) { | 
| Hal Finkel | bbdee93 | 2014-12-02 22:01:00 +0000 | [diff] [blame] | 9065 | // To read the 64-bit time-base register on a 32-bit target, we read the | 
|  | 9066 | // two halves. Should the counter have wrapped while it was being read, we | 
|  | 9067 | // need to try again. | 
|  | 9068 | // ... | 
|  | 9069 | // readLoop: | 
|  | 9070 | // mfspr Rx,TBU # load from TBU | 
|  | 9071 | // mfspr Ry,TB  # load from TB | 
|  | 9072 | // mfspr Rz,TBU # load from TBU | 
| NAKAMURA Takumi | bf9cc7f | 2015-09-22 11:10:08 +0000 | [diff] [blame] | 9073 | // cmpw crX,Rx,Rz # check if 'old'='new' | 
| Hal Finkel | bbdee93 | 2014-12-02 22:01:00 +0000 | [diff] [blame] | 9074 | // bne readLoop   # branch if they're not equal | 
|  | 9075 | // ... | 
|  | 9076 |  | 
|  | 9077 | MachineBasicBlock *readMBB = F->CreateMachineBasicBlock(LLVM_BB); | 
|  | 9078 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9079 | DebugLoc dl = MI.getDebugLoc(); | 
| Hal Finkel | bbdee93 | 2014-12-02 22:01:00 +0000 | [diff] [blame] | 9080 | F->insert(It, readMBB); | 
|  | 9081 | F->insert(It, sinkMBB); | 
|  | 9082 |  | 
|  | 9083 | // Transfer the remainder of BB and its successor edges to sinkMBB. | 
|  | 9084 | sinkMBB->splice(sinkMBB->begin(), BB, | 
|  | 9085 | std::next(MachineBasicBlock::iterator(MI)), BB->end()); | 
|  | 9086 | sinkMBB->transferSuccessorsAndUpdatePHIs(BB); | 
|  | 9087 |  | 
|  | 9088 | BB->addSuccessor(readMBB); | 
|  | 9089 | BB = readMBB; | 
|  | 9090 |  | 
|  | 9091 | MachineRegisterInfo &RegInfo = F->getRegInfo(); | 
|  | 9092 | unsigned ReadAgainReg = RegInfo.createVirtualRegister(&PPC::GPRCRegClass); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9093 | unsigned LoReg = MI.getOperand(0).getReg(); | 
|  | 9094 | unsigned HiReg = MI.getOperand(1).getReg(); | 
| Hal Finkel | bbdee93 | 2014-12-02 22:01:00 +0000 | [diff] [blame] | 9095 |  | 
|  | 9096 | BuildMI(BB, dl, TII->get(PPC::MFSPR), HiReg).addImm(269); | 
|  | 9097 | BuildMI(BB, dl, TII->get(PPC::MFSPR), LoReg).addImm(268); | 
|  | 9098 | BuildMI(BB, dl, TII->get(PPC::MFSPR), ReadAgainReg).addImm(269); | 
|  | 9099 |  | 
|  | 9100 | unsigned CmpReg = RegInfo.createVirtualRegister(&PPC::CRRCRegClass); | 
|  | 9101 |  | 
|  | 9102 | BuildMI(BB, dl, TII->get(PPC::CMPW), CmpReg) | 
|  | 9103 | .addReg(HiReg).addReg(ReadAgainReg); | 
|  | 9104 | BuildMI(BB, dl, TII->get(PPC::BCC)) | 
|  | 9105 | .addImm(PPC::PRED_NE).addReg(CmpReg).addMBB(readMBB); | 
|  | 9106 |  | 
|  | 9107 | BB->addSuccessor(readMBB); | 
|  | 9108 | BB->addSuccessor(sinkMBB); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9109 | } else if (MI.getOpcode() == PPC::ATOMIC_LOAD_ADD_I8) | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 9110 | BB = EmitPartwordAtomicBinary(MI, BB, true, PPC::ADD4); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9111 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_ADD_I16) | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 9112 | BB = EmitPartwordAtomicBinary(MI, BB, false, PPC::ADD4); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9113 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_ADD_I32) | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9114 | BB = EmitAtomicBinary(MI, BB, 4, PPC::ADD4); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9115 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_ADD_I64) | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9116 | BB = EmitAtomicBinary(MI, BB, 8, PPC::ADD8); | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 9117 |  | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9118 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_AND_I8) | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 9119 | BB = EmitPartwordAtomicBinary(MI, BB, true, PPC::AND); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9120 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_AND_I16) | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 9121 | BB = EmitPartwordAtomicBinary(MI, BB, false, PPC::AND); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9122 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_AND_I32) | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9123 | BB = EmitAtomicBinary(MI, BB, 4, PPC::AND); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9124 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_AND_I64) | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9125 | BB = EmitAtomicBinary(MI, BB, 8, PPC::AND8); | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 9126 |  | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9127 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_OR_I8) | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 9128 | BB = EmitPartwordAtomicBinary(MI, BB, true, PPC::OR); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9129 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_OR_I16) | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 9130 | BB = EmitPartwordAtomicBinary(MI, BB, false, PPC::OR); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9131 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_OR_I32) | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9132 | BB = EmitAtomicBinary(MI, BB, 4, PPC::OR); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9133 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_OR_I64) | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9134 | BB = EmitAtomicBinary(MI, BB, 8, PPC::OR8); | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 9135 |  | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9136 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_XOR_I8) | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 9137 | BB = EmitPartwordAtomicBinary(MI, BB, true, PPC::XOR); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9138 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_XOR_I16) | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 9139 | BB = EmitPartwordAtomicBinary(MI, BB, false, PPC::XOR); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9140 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_XOR_I32) | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9141 | BB = EmitAtomicBinary(MI, BB, 4, PPC::XOR); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9142 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_XOR_I64) | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9143 | BB = EmitAtomicBinary(MI, BB, 8, PPC::XOR8); | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 9144 |  | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9145 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_NAND_I8) | 
| Ulrich Weigand | 862d8b8 | 2014-07-08 16:16:02 +0000 | [diff] [blame] | 9146 | BB = EmitPartwordAtomicBinary(MI, BB, true, PPC::NAND); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9147 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_NAND_I16) | 
| Ulrich Weigand | 862d8b8 | 2014-07-08 16:16:02 +0000 | [diff] [blame] | 9148 | BB = EmitPartwordAtomicBinary(MI, BB, false, PPC::NAND); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9149 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_NAND_I32) | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9150 | BB = EmitAtomicBinary(MI, BB, 4, PPC::NAND); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9151 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_NAND_I64) | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9152 | BB = EmitAtomicBinary(MI, BB, 8, PPC::NAND8); | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 9153 |  | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9154 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_SUB_I8) | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 9155 | BB = EmitPartwordAtomicBinary(MI, BB, true, PPC::SUBF); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9156 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_SUB_I16) | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 9157 | BB = EmitPartwordAtomicBinary(MI, BB, false, PPC::SUBF); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9158 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_SUB_I32) | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9159 | BB = EmitAtomicBinary(MI, BB, 4, PPC::SUBF); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9160 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_SUB_I64) | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9161 | BB = EmitAtomicBinary(MI, BB, 8, PPC::SUBF8); | 
| Dale Johannesen | a32affb | 2008-08-28 17:53:09 +0000 | [diff] [blame] | 9162 |  | 
| Hal Finkel | 5728200 | 2016-08-28 16:17:58 +0000 | [diff] [blame] | 9163 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_MIN_I8) | 
|  | 9164 | BB = EmitPartwordAtomicBinary(MI, BB, true, 0, PPC::CMPW, PPC::PRED_GE); | 
|  | 9165 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_MIN_I16) | 
|  | 9166 | BB = EmitPartwordAtomicBinary(MI, BB, false, 0, PPC::CMPW, PPC::PRED_GE); | 
|  | 9167 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_MIN_I32) | 
|  | 9168 | BB = EmitAtomicBinary(MI, BB, 4, 0, PPC::CMPW, PPC::PRED_GE); | 
|  | 9169 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_MIN_I64) | 
|  | 9170 | BB = EmitAtomicBinary(MI, BB, 8, 0, PPC::CMPD, PPC::PRED_GE); | 
|  | 9171 |  | 
|  | 9172 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_MAX_I8) | 
|  | 9173 | BB = EmitPartwordAtomicBinary(MI, BB, true, 0, PPC::CMPW, PPC::PRED_LE); | 
|  | 9174 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_MAX_I16) | 
|  | 9175 | BB = EmitPartwordAtomicBinary(MI, BB, false, 0, PPC::CMPW, PPC::PRED_LE); | 
|  | 9176 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_MAX_I32) | 
|  | 9177 | BB = EmitAtomicBinary(MI, BB, 4, 0, PPC::CMPW, PPC::PRED_LE); | 
|  | 9178 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_MAX_I64) | 
|  | 9179 | BB = EmitAtomicBinary(MI, BB, 8, 0, PPC::CMPD, PPC::PRED_LE); | 
|  | 9180 |  | 
|  | 9181 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_UMIN_I8) | 
|  | 9182 | BB = EmitPartwordAtomicBinary(MI, BB, true, 0, PPC::CMPLW, PPC::PRED_GE); | 
|  | 9183 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_UMIN_I16) | 
|  | 9184 | BB = EmitPartwordAtomicBinary(MI, BB, false, 0, PPC::CMPLW, PPC::PRED_GE); | 
|  | 9185 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_UMIN_I32) | 
|  | 9186 | BB = EmitAtomicBinary(MI, BB, 4, 0, PPC::CMPLW, PPC::PRED_GE); | 
|  | 9187 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_UMIN_I64) | 
|  | 9188 | BB = EmitAtomicBinary(MI, BB, 8, 0, PPC::CMPLD, PPC::PRED_GE); | 
|  | 9189 |  | 
|  | 9190 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_UMAX_I8) | 
|  | 9191 | BB = EmitPartwordAtomicBinary(MI, BB, true, 0, PPC::CMPLW, PPC::PRED_LE); | 
|  | 9192 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_UMAX_I16) | 
|  | 9193 | BB = EmitPartwordAtomicBinary(MI, BB, false, 0, PPC::CMPLW, PPC::PRED_LE); | 
|  | 9194 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_UMAX_I32) | 
|  | 9195 | BB = EmitAtomicBinary(MI, BB, 4, 0, PPC::CMPLW, PPC::PRED_LE); | 
|  | 9196 | else if (MI.getOpcode() == PPC::ATOMIC_LOAD_UMAX_I64) | 
|  | 9197 | BB = EmitAtomicBinary(MI, BB, 8, 0, PPC::CMPLD, PPC::PRED_LE); | 
|  | 9198 |  | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9199 | else if (MI.getOpcode() == PPC::ATOMIC_SWAP_I8) | 
| Dale Johannesen | f0a88d6 | 2008-08-29 18:29:46 +0000 | [diff] [blame] | 9200 | BB = EmitPartwordAtomicBinary(MI, BB, true, 0); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9201 | else if (MI.getOpcode() == PPC::ATOMIC_SWAP_I16) | 
| Dale Johannesen | f0a88d6 | 2008-08-29 18:29:46 +0000 | [diff] [blame] | 9202 | BB = EmitPartwordAtomicBinary(MI, BB, false, 0); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9203 | else if (MI.getOpcode() == PPC::ATOMIC_SWAP_I32) | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9204 | BB = EmitAtomicBinary(MI, BB, 4, 0); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9205 | else if (MI.getOpcode() == PPC::ATOMIC_SWAP_I64) | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9206 | BB = EmitAtomicBinary(MI, BB, 8, 0); | 
| Dale Johannesen | f0a88d6 | 2008-08-29 18:29:46 +0000 | [diff] [blame] | 9207 |  | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9208 | else if (MI.getOpcode() == PPC::ATOMIC_CMP_SWAP_I32 || | 
|  | 9209 | MI.getOpcode() == PPC::ATOMIC_CMP_SWAP_I64 || | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9210 | (Subtarget.hasPartwordAtomics() && | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9211 | MI.getOpcode() == PPC::ATOMIC_CMP_SWAP_I8) || | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9212 | (Subtarget.hasPartwordAtomics() && | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9213 | MI.getOpcode() == PPC::ATOMIC_CMP_SWAP_I16)) { | 
|  | 9214 | bool is64bit = MI.getOpcode() == PPC::ATOMIC_CMP_SWAP_I64; | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 9215 |  | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9216 | auto LoadMnemonic = PPC::LDARX; | 
|  | 9217 | auto StoreMnemonic = PPC::STDCX; | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9218 | switch (MI.getOpcode()) { | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9219 | default: | 
|  | 9220 | llvm_unreachable("Compare and swap of unknown size"); | 
|  | 9221 | case PPC::ATOMIC_CMP_SWAP_I8: | 
|  | 9222 | LoadMnemonic = PPC::LBARX; | 
|  | 9223 | StoreMnemonic = PPC::STBCX; | 
|  | 9224 | assert(Subtarget.hasPartwordAtomics() && "No support partword atomics."); | 
|  | 9225 | break; | 
|  | 9226 | case PPC::ATOMIC_CMP_SWAP_I16: | 
|  | 9227 | LoadMnemonic = PPC::LHARX; | 
|  | 9228 | StoreMnemonic = PPC::STHCX; | 
|  | 9229 | assert(Subtarget.hasPartwordAtomics() && "No support partword atomics."); | 
|  | 9230 | break; | 
|  | 9231 | case PPC::ATOMIC_CMP_SWAP_I32: | 
|  | 9232 | LoadMnemonic = PPC::LWARX; | 
|  | 9233 | StoreMnemonic = PPC::STWCX; | 
|  | 9234 | break; | 
|  | 9235 | case PPC::ATOMIC_CMP_SWAP_I64: | 
|  | 9236 | LoadMnemonic = PPC::LDARX; | 
|  | 9237 | StoreMnemonic = PPC::STDCX; | 
|  | 9238 | break; | 
|  | 9239 | } | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9240 | unsigned dest = MI.getOperand(0).getReg(); | 
|  | 9241 | unsigned ptrA = MI.getOperand(1).getReg(); | 
|  | 9242 | unsigned ptrB = MI.getOperand(2).getReg(); | 
|  | 9243 | unsigned oldval = MI.getOperand(3).getReg(); | 
|  | 9244 | unsigned newval = MI.getOperand(4).getReg(); | 
|  | 9245 | DebugLoc dl = MI.getDebugLoc(); | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 9246 |  | 
| Dale Johannesen | 166d6cb | 2008-08-25 18:53:26 +0000 | [diff] [blame] | 9247 | MachineBasicBlock *loop1MBB = F->CreateMachineBasicBlock(LLVM_BB); | 
|  | 9248 | MachineBasicBlock *loop2MBB = F->CreateMachineBasicBlock(LLVM_BB); | 
|  | 9249 | MachineBasicBlock *midMBB = F->CreateMachineBasicBlock(LLVM_BB); | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 9250 | MachineBasicBlock *exitMBB = F->CreateMachineBasicBlock(LLVM_BB); | 
| Dale Johannesen | 166d6cb | 2008-08-25 18:53:26 +0000 | [diff] [blame] | 9251 | F->insert(It, loop1MBB); | 
|  | 9252 | F->insert(It, loop2MBB); | 
|  | 9253 | F->insert(It, midMBB); | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 9254 | F->insert(It, exitMBB); | 
| Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 9255 | exitMBB->splice(exitMBB->begin(), BB, | 
| Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 9256 | std::next(MachineBasicBlock::iterator(MI)), BB->end()); | 
| Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 9257 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 9258 |  | 
|  | 9259 | //  thisMBB: | 
|  | 9260 | //   ... | 
|  | 9261 | //   fallthrough --> loopMBB | 
| Dale Johannesen | 166d6cb | 2008-08-25 18:53:26 +0000 | [diff] [blame] | 9262 | BB->addSuccessor(loop1MBB); | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 9263 |  | 
| Dale Johannesen | 166d6cb | 2008-08-25 18:53:26 +0000 | [diff] [blame] | 9264 | // loop1MBB: | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9265 | //   l[bhwd]arx dest, ptr | 
| Dale Johannesen | 166d6cb | 2008-08-25 18:53:26 +0000 | [diff] [blame] | 9266 | //   cmp[wd] dest, oldval | 
|  | 9267 | //   bne- midMBB | 
|  | 9268 | // loop2MBB: | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9269 | //   st[bhwd]cx. newval, ptr | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 9270 | //   bne- loopMBB | 
| Dale Johannesen | 166d6cb | 2008-08-25 18:53:26 +0000 | [diff] [blame] | 9271 | //   b exitBB | 
|  | 9272 | // midMBB: | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9273 | //   st[bhwd]cx. dest, ptr | 
| Dale Johannesen | 166d6cb | 2008-08-25 18:53:26 +0000 | [diff] [blame] | 9274 | // exitBB: | 
|  | 9275 | BB = loop1MBB; | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9276 | BuildMI(BB, dl, TII->get(LoadMnemonic), dest) | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 9277 | .addReg(ptrA).addReg(ptrB); | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9278 | BuildMI(BB, dl, TII->get(is64bit ? PPC::CMPD : PPC::CMPW), PPC::CR0) | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 9279 | .addReg(oldval).addReg(dest); | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9280 | BuildMI(BB, dl, TII->get(PPC::BCC)) | 
| Dale Johannesen | 166d6cb | 2008-08-25 18:53:26 +0000 | [diff] [blame] | 9281 | .addImm(PPC::PRED_NE).addReg(PPC::CR0).addMBB(midMBB); | 
|  | 9282 | BB->addSuccessor(loop2MBB); | 
|  | 9283 | BB->addSuccessor(midMBB); | 
|  | 9284 |  | 
|  | 9285 | BB = loop2MBB; | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9286 | BuildMI(BB, dl, TII->get(StoreMnemonic)) | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 9287 | .addReg(newval).addReg(ptrA).addReg(ptrB); | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9288 | BuildMI(BB, dl, TII->get(PPC::BCC)) | 
| Dale Johannesen | 166d6cb | 2008-08-25 18:53:26 +0000 | [diff] [blame] | 9289 | .addImm(PPC::PRED_NE).addReg(PPC::CR0).addMBB(loop1MBB); | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9290 | BuildMI(BB, dl, TII->get(PPC::B)).addMBB(exitMBB); | 
| Dale Johannesen | 166d6cb | 2008-08-25 18:53:26 +0000 | [diff] [blame] | 9291 | BB->addSuccessor(loop1MBB); | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 9292 | BB->addSuccessor(exitMBB); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 9293 |  | 
| Dale Johannesen | 166d6cb | 2008-08-25 18:53:26 +0000 | [diff] [blame] | 9294 | BB = midMBB; | 
| Nemanja Ivanovic | 0adf26b | 2015-03-10 20:51:07 +0000 | [diff] [blame] | 9295 | BuildMI(BB, dl, TII->get(StoreMnemonic)) | 
| Dale Johannesen | 166d6cb | 2008-08-25 18:53:26 +0000 | [diff] [blame] | 9296 | .addReg(dest).addReg(ptrA).addReg(ptrB); | 
|  | 9297 | BB->addSuccessor(exitMBB); | 
|  | 9298 |  | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 9299 | //  exitMBB: | 
|  | 9300 | //   ... | 
|  | 9301 | BB = exitMBB; | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9302 | } else if (MI.getOpcode() == PPC::ATOMIC_CMP_SWAP_I8 || | 
|  | 9303 | MI.getOpcode() == PPC::ATOMIC_CMP_SWAP_I16) { | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9304 | // We must use 64-bit registers for addresses when targeting 64-bit, | 
|  | 9305 | // since we're actually doing arithmetic on them.  Other registers | 
|  | 9306 | // can be 32-bit. | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 9307 | bool is64bit = Subtarget.isPPC64(); | 
| Hal Finkel | 3d70a9d | 2016-08-29 22:25:36 +0000 | [diff] [blame] | 9308 | bool isLittleEndian = Subtarget.isLittleEndian(); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9309 | bool is8bit = MI.getOpcode() == PPC::ATOMIC_CMP_SWAP_I8; | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9310 |  | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9311 | unsigned dest = MI.getOperand(0).getReg(); | 
|  | 9312 | unsigned ptrA = MI.getOperand(1).getReg(); | 
|  | 9313 | unsigned ptrB = MI.getOperand(2).getReg(); | 
|  | 9314 | unsigned oldval = MI.getOperand(3).getReg(); | 
|  | 9315 | unsigned newval = MI.getOperand(4).getReg(); | 
|  | 9316 | DebugLoc dl = MI.getDebugLoc(); | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9317 |  | 
|  | 9318 | MachineBasicBlock *loop1MBB = F->CreateMachineBasicBlock(LLVM_BB); | 
|  | 9319 | MachineBasicBlock *loop2MBB = F->CreateMachineBasicBlock(LLVM_BB); | 
|  | 9320 | MachineBasicBlock *midMBB = F->CreateMachineBasicBlock(LLVM_BB); | 
|  | 9321 | MachineBasicBlock *exitMBB = F->CreateMachineBasicBlock(LLVM_BB); | 
|  | 9322 | F->insert(It, loop1MBB); | 
|  | 9323 | F->insert(It, loop2MBB); | 
|  | 9324 | F->insert(It, midMBB); | 
|  | 9325 | F->insert(It, exitMBB); | 
| Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 9326 | exitMBB->splice(exitMBB->begin(), BB, | 
| Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 9327 | std::next(MachineBasicBlock::iterator(MI)), BB->end()); | 
| Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 9328 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9329 |  | 
|  | 9330 | MachineRegisterInfo &RegInfo = F->getRegInfo(); | 
| Craig Topper | 61e88f4 | 2014-11-21 05:58:21 +0000 | [diff] [blame] | 9331 | const TargetRegisterClass *RC = is64bit ? &PPC::G8RCRegClass | 
|  | 9332 | : &PPC::GPRCRegClass; | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9333 | unsigned PtrReg = RegInfo.createVirtualRegister(RC); | 
|  | 9334 | unsigned Shift1Reg = RegInfo.createVirtualRegister(RC); | 
| Hal Finkel | 3d70a9d | 2016-08-29 22:25:36 +0000 | [diff] [blame] | 9335 | unsigned ShiftReg = | 
|  | 9336 | isLittleEndian ? Shift1Reg : RegInfo.createVirtualRegister(RC); | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9337 | unsigned NewVal2Reg = RegInfo.createVirtualRegister(RC); | 
|  | 9338 | unsigned NewVal3Reg = RegInfo.createVirtualRegister(RC); | 
|  | 9339 | unsigned OldVal2Reg = RegInfo.createVirtualRegister(RC); | 
|  | 9340 | unsigned OldVal3Reg = RegInfo.createVirtualRegister(RC); | 
|  | 9341 | unsigned MaskReg = RegInfo.createVirtualRegister(RC); | 
|  | 9342 | unsigned Mask2Reg = RegInfo.createVirtualRegister(RC); | 
|  | 9343 | unsigned Mask3Reg = RegInfo.createVirtualRegister(RC); | 
|  | 9344 | unsigned Tmp2Reg = RegInfo.createVirtualRegister(RC); | 
|  | 9345 | unsigned Tmp4Reg = RegInfo.createVirtualRegister(RC); | 
|  | 9346 | unsigned TmpDestReg = RegInfo.createVirtualRegister(RC); | 
|  | 9347 | unsigned Ptr1Reg; | 
|  | 9348 | unsigned TmpReg = RegInfo.createVirtualRegister(RC); | 
| Hal Finkel | f70c41e | 2013-03-21 23:45:03 +0000 | [diff] [blame] | 9349 | unsigned ZeroReg = is64bit ? PPC::ZERO8 : PPC::ZERO; | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9350 | //  thisMBB: | 
|  | 9351 | //   ... | 
|  | 9352 | //   fallthrough --> loopMBB | 
|  | 9353 | BB->addSuccessor(loop1MBB); | 
|  | 9354 |  | 
|  | 9355 | // The 4-byte load must be aligned, while a char or short may be | 
|  | 9356 | // anywhere in the word.  Hence all this nasty bookkeeping code. | 
|  | 9357 | //   add ptr1, ptrA, ptrB [copy if ptrA==0] | 
|  | 9358 | //   rlwinm shift1, ptr1, 3, 27, 28 [3, 27, 27] | 
| Dale Johannesen | bc69829 | 2008-09-02 20:30:23 +0000 | [diff] [blame] | 9359 | //   xori shift, shift1, 24 [16] | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9360 | //   rlwinm ptr, ptr1, 0, 0, 29 | 
|  | 9361 | //   slw newval2, newval, shift | 
|  | 9362 | //   slw oldval2, oldval,shift | 
|  | 9363 | //   li mask2, 255 [li mask3, 0; ori mask2, mask3, 65535] | 
|  | 9364 | //   slw mask, mask2, shift | 
|  | 9365 | //   and newval3, newval2, mask | 
|  | 9366 | //   and oldval3, oldval2, mask | 
|  | 9367 | // loop1MBB: | 
|  | 9368 | //   lwarx tmpDest, ptr | 
|  | 9369 | //   and tmp, tmpDest, mask | 
|  | 9370 | //   cmpw tmp, oldval3 | 
|  | 9371 | //   bne- midMBB | 
|  | 9372 | // loop2MBB: | 
|  | 9373 | //   andc tmp2, tmpDest, mask | 
|  | 9374 | //   or tmp4, tmp2, newval3 | 
|  | 9375 | //   stwcx. tmp4, ptr | 
|  | 9376 | //   bne- loop1MBB | 
|  | 9377 | //   b exitBB | 
|  | 9378 | // midMBB: | 
|  | 9379 | //   stwcx. tmpDest, ptr | 
|  | 9380 | // exitBB: | 
|  | 9381 | //   srw dest, tmpDest, shift | 
| Jakob Stoklund Olesen | 7067bff | 2011-04-04 17:07:06 +0000 | [diff] [blame] | 9382 | if (ptrA != ZeroReg) { | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9383 | Ptr1Reg = RegInfo.createVirtualRegister(RC); | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9384 | BuildMI(BB, dl, TII->get(is64bit ? PPC::ADD8 : PPC::ADD4), Ptr1Reg) | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9385 | .addReg(ptrA).addReg(ptrB); | 
|  | 9386 | } else { | 
|  | 9387 | Ptr1Reg = ptrB; | 
|  | 9388 | } | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9389 | BuildMI(BB, dl, TII->get(PPC::RLWINM), Shift1Reg).addReg(Ptr1Reg) | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9390 | .addImm(3).addImm(27).addImm(is8bit ? 28 : 27); | 
| Hal Finkel | 3d70a9d | 2016-08-29 22:25:36 +0000 | [diff] [blame] | 9391 | if (!isLittleEndian) | 
|  | 9392 | BuildMI(BB, dl, TII->get(is64bit ? PPC::XORI8 : PPC::XORI), ShiftReg) | 
|  | 9393 | .addReg(Shift1Reg).addImm(is8bit ? 24 : 16); | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9394 | if (is64bit) | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9395 | BuildMI(BB, dl, TII->get(PPC::RLDICR), PtrReg) | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9396 | .addReg(Ptr1Reg).addImm(0).addImm(61); | 
|  | 9397 | else | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9398 | BuildMI(BB, dl, TII->get(PPC::RLWINM), PtrReg) | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9399 | .addReg(Ptr1Reg).addImm(0).addImm(0).addImm(29); | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9400 | BuildMI(BB, dl, TII->get(PPC::SLW), NewVal2Reg) | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9401 | .addReg(newval).addReg(ShiftReg); | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9402 | BuildMI(BB, dl, TII->get(PPC::SLW), OldVal2Reg) | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9403 | .addReg(oldval).addReg(ShiftReg); | 
|  | 9404 | if (is8bit) | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9405 | BuildMI(BB, dl, TII->get(PPC::LI), Mask2Reg).addImm(255); | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9406 | else { | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9407 | BuildMI(BB, dl, TII->get(PPC::LI), Mask3Reg).addImm(0); | 
|  | 9408 | BuildMI(BB, dl, TII->get(PPC::ORI), Mask2Reg) | 
|  | 9409 | .addReg(Mask3Reg).addImm(65535); | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9410 | } | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9411 | BuildMI(BB, dl, TII->get(PPC::SLW), MaskReg) | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9412 | .addReg(Mask2Reg).addReg(ShiftReg); | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9413 | BuildMI(BB, dl, TII->get(PPC::AND), NewVal3Reg) | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9414 | .addReg(NewVal2Reg).addReg(MaskReg); | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9415 | BuildMI(BB, dl, TII->get(PPC::AND), OldVal3Reg) | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9416 | .addReg(OldVal2Reg).addReg(MaskReg); | 
|  | 9417 |  | 
|  | 9418 | BB = loop1MBB; | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9419 | BuildMI(BB, dl, TII->get(PPC::LWARX), TmpDestReg) | 
| Jakob Stoklund Olesen | 7067bff | 2011-04-04 17:07:06 +0000 | [diff] [blame] | 9420 | .addReg(ZeroReg).addReg(PtrReg); | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9421 | BuildMI(BB, dl, TII->get(PPC::AND),TmpReg) | 
|  | 9422 | .addReg(TmpDestReg).addReg(MaskReg); | 
|  | 9423 | BuildMI(BB, dl, TII->get(PPC::CMPW), PPC::CR0) | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9424 | .addReg(TmpReg).addReg(OldVal3Reg); | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9425 | BuildMI(BB, dl, TII->get(PPC::BCC)) | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9426 | .addImm(PPC::PRED_NE).addReg(PPC::CR0).addMBB(midMBB); | 
|  | 9427 | BB->addSuccessor(loop2MBB); | 
|  | 9428 | BB->addSuccessor(midMBB); | 
|  | 9429 |  | 
|  | 9430 | BB = loop2MBB; | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9431 | BuildMI(BB, dl, TII->get(PPC::ANDC),Tmp2Reg) | 
|  | 9432 | .addReg(TmpDestReg).addReg(MaskReg); | 
|  | 9433 | BuildMI(BB, dl, TII->get(PPC::OR),Tmp4Reg) | 
|  | 9434 | .addReg(Tmp2Reg).addReg(NewVal3Reg); | 
|  | 9435 | BuildMI(BB, dl, TII->get(PPC::STWCX)).addReg(Tmp4Reg) | 
| Jakob Stoklund Olesen | 7067bff | 2011-04-04 17:07:06 +0000 | [diff] [blame] | 9436 | .addReg(ZeroReg).addReg(PtrReg); | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9437 | BuildMI(BB, dl, TII->get(PPC::BCC)) | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9438 | .addImm(PPC::PRED_NE).addReg(PPC::CR0).addMBB(loop1MBB); | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9439 | BuildMI(BB, dl, TII->get(PPC::B)).addMBB(exitMBB); | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9440 | BB->addSuccessor(loop1MBB); | 
|  | 9441 | BB->addSuccessor(exitMBB); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 9442 |  | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9443 | BB = midMBB; | 
| Dale Johannesen | e9f623e | 2009-02-13 02:27:39 +0000 | [diff] [blame] | 9444 | BuildMI(BB, dl, TII->get(PPC::STWCX)).addReg(TmpDestReg) | 
| Jakob Stoklund Olesen | 7067bff | 2011-04-04 17:07:06 +0000 | [diff] [blame] | 9445 | .addReg(ZeroReg).addReg(PtrReg); | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9446 | BB->addSuccessor(exitMBB); | 
|  | 9447 |  | 
|  | 9448 | //  exitMBB: | 
|  | 9449 | //   ... | 
|  | 9450 | BB = exitMBB; | 
| Jakob Stoklund Olesen | 13ce236 | 2011-04-04 17:57:29 +0000 | [diff] [blame] | 9451 | BuildMI(*BB, BB->begin(), dl, TII->get(PPC::SRW),dest).addReg(TmpReg) | 
|  | 9452 | .addReg(ShiftReg); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9453 | } else if (MI.getOpcode() == PPC::FADDrtz) { | 
| Ulrich Weigand | 874fc62 | 2013-03-26 10:56:22 +0000 | [diff] [blame] | 9454 | // This pseudo performs an FADD with rounding mode temporarily forced | 
|  | 9455 | // to round-to-zero.  We emit this via custom inserter since the FPSCR | 
|  | 9456 | // is not modeled at the SelectionDAG level. | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9457 | unsigned Dest = MI.getOperand(0).getReg(); | 
|  | 9458 | unsigned Src1 = MI.getOperand(1).getReg(); | 
|  | 9459 | unsigned Src2 = MI.getOperand(2).getReg(); | 
|  | 9460 | DebugLoc dl = MI.getDebugLoc(); | 
| Ulrich Weigand | 874fc62 | 2013-03-26 10:56:22 +0000 | [diff] [blame] | 9461 |  | 
|  | 9462 | MachineRegisterInfo &RegInfo = F->getRegInfo(); | 
|  | 9463 | unsigned MFFSReg = RegInfo.createVirtualRegister(&PPC::F8RCRegClass); | 
|  | 9464 |  | 
|  | 9465 | // Save FPSCR value. | 
|  | 9466 | BuildMI(*BB, MI, dl, TII->get(PPC::MFFS), MFFSReg); | 
|  | 9467 |  | 
|  | 9468 | // Set rounding mode to round-to-zero. | 
|  | 9469 | BuildMI(*BB, MI, dl, TII->get(PPC::MTFSB1)).addImm(31); | 
|  | 9470 | BuildMI(*BB, MI, dl, TII->get(PPC::MTFSB0)).addImm(30); | 
|  | 9471 |  | 
|  | 9472 | // Perform addition. | 
|  | 9473 | BuildMI(*BB, MI, dl, TII->get(PPC::FADD), Dest).addReg(Src1).addReg(Src2); | 
|  | 9474 |  | 
|  | 9475 | // Restore FPSCR value. | 
| Hal Finkel | 6420216 | 2015-01-15 01:00:53 +0000 | [diff] [blame] | 9476 | BuildMI(*BB, MI, dl, TII->get(PPC::MTFSFb)).addImm(1).addReg(MFFSReg); | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9477 | } else if (MI.getOpcode() == PPC::ANDIo_1_EQ_BIT || | 
|  | 9478 | MI.getOpcode() == PPC::ANDIo_1_GT_BIT || | 
|  | 9479 | MI.getOpcode() == PPC::ANDIo_1_EQ_BIT8 || | 
|  | 9480 | MI.getOpcode() == PPC::ANDIo_1_GT_BIT8) { | 
|  | 9481 | unsigned Opcode = (MI.getOpcode() == PPC::ANDIo_1_EQ_BIT8 || | 
|  | 9482 | MI.getOpcode() == PPC::ANDIo_1_GT_BIT8) | 
|  | 9483 | ? PPC::ANDIo8 | 
|  | 9484 | : PPC::ANDIo; | 
|  | 9485 | bool isEQ = (MI.getOpcode() == PPC::ANDIo_1_EQ_BIT || | 
|  | 9486 | MI.getOpcode() == PPC::ANDIo_1_EQ_BIT8); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 9487 |  | 
|  | 9488 | MachineRegisterInfo &RegInfo = F->getRegInfo(); | 
|  | 9489 | unsigned Dest = RegInfo.createVirtualRegister(Opcode == PPC::ANDIo ? | 
|  | 9490 | &PPC::GPRCRegClass : | 
|  | 9491 | &PPC::G8RCRegClass); | 
|  | 9492 |  | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9493 | DebugLoc dl = MI.getDebugLoc(); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 9494 | BuildMI(*BB, MI, dl, TII->get(Opcode), Dest) | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9495 | .addReg(MI.getOperand(1).getReg()) | 
|  | 9496 | .addImm(1); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 9497 | BuildMI(*BB, MI, dl, TII->get(TargetOpcode::COPY), | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9498 | MI.getOperand(0).getReg()) | 
|  | 9499 | .addReg(isEQ ? PPC::CR0EQ : PPC::CR0GT); | 
|  | 9500 | } else if (MI.getOpcode() == PPC::TCHECK_RET) { | 
|  | 9501 | DebugLoc Dl = MI.getDebugLoc(); | 
| Kit Barton | 535e69d | 2015-03-25 19:36:23 +0000 | [diff] [blame] | 9502 | MachineRegisterInfo &RegInfo = F->getRegInfo(); | 
|  | 9503 | unsigned CRReg = RegInfo.createVirtualRegister(&PPC::CRRCRegClass); | 
|  | 9504 | BuildMI(*BB, MI, Dl, TII->get(PPC::TCHECK), CRReg); | 
|  | 9505 | return BB; | 
| Dale Johannesen | 340d264 | 2008-08-30 00:08:53 +0000 | [diff] [blame] | 9506 | } else { | 
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 9507 | llvm_unreachable("Unexpected instr type to insert"); | 
| Evan Cheng | 32e376f | 2008-07-12 02:23:19 +0000 | [diff] [blame] | 9508 | } | 
| Chris Lattner | 9b577f1 | 2005-08-26 21:23:58 +0000 | [diff] [blame] | 9509 |  | 
| Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 9510 | MI.eraseFromParent(); // The pseudo instruction is gone now. | 
| Chris Lattner | 9b577f1 | 2005-08-26 21:23:58 +0000 | [diff] [blame] | 9511 | return BB; | 
|  | 9512 | } | 
|  | 9513 |  | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 9514 | //===----------------------------------------------------------------------===// | 
|  | 9515 | // Target Optimization Hooks | 
|  | 9516 | //===----------------------------------------------------------------------===// | 
|  | 9517 |  | 
| Hal Finkel | cbf0892 | 2015-07-12 02:33:57 +0000 | [diff] [blame] | 9518 | static std::string getRecipOp(const char *Base, EVT VT) { | 
|  | 9519 | std::string RecipOp(Base); | 
|  | 9520 | if (VT.getScalarType() == MVT::f64) | 
|  | 9521 | RecipOp += "d"; | 
|  | 9522 | else | 
|  | 9523 | RecipOp += "f"; | 
|  | 9524 |  | 
|  | 9525 | if (VT.isVector()) | 
|  | 9526 | RecipOp = "vec-" + RecipOp; | 
|  | 9527 |  | 
|  | 9528 | return RecipOp; | 
|  | 9529 | } | 
|  | 9530 |  | 
| Sanjay Patel | 8fde95c | 2014-09-30 20:28:48 +0000 | [diff] [blame] | 9531 | SDValue PPCTargetLowering::getRsqrtEstimate(SDValue Operand, | 
|  | 9532 | DAGCombinerInfo &DCI, | 
| Sanjay Patel | 957efc23 | 2014-10-24 17:02:16 +0000 | [diff] [blame] | 9533 | unsigned &RefinementSteps, | 
|  | 9534 | bool &UseOneConstNR) const { | 
| Sanjay Patel | bdf1e38 | 2014-09-26 23:01:47 +0000 | [diff] [blame] | 9535 | EVT VT = Operand.getValueType(); | 
| Sanjay Patel | 8fde95c | 2014-09-30 20:28:48 +0000 | [diff] [blame] | 9536 | if ((VT == MVT::f32 && Subtarget.hasFRSQRTES()) || | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 9537 | (VT == MVT::f64 && Subtarget.hasFRSQRTE()) || | 
| Sanjay Patel | 8fde95c | 2014-09-30 20:28:48 +0000 | [diff] [blame] | 9538 | (VT == MVT::v4f32 && Subtarget.hasAltivec()) || | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 9539 | (VT == MVT::v2f64 && Subtarget.hasVSX()) || | 
|  | 9540 | (VT == MVT::v4f32 && Subtarget.hasQPX()) || | 
|  | 9541 | (VT == MVT::v4f64 && Subtarget.hasQPX())) { | 
| Hal Finkel | cbf0892 | 2015-07-12 02:33:57 +0000 | [diff] [blame] | 9542 | TargetRecip Recips = DCI.DAG.getTarget().Options.Reciprocals; | 
|  | 9543 | std::string RecipOp = getRecipOp("sqrt", VT); | 
|  | 9544 | if (!Recips.isEnabled(RecipOp)) | 
|  | 9545 | return SDValue(); | 
|  | 9546 |  | 
|  | 9547 | RefinementSteps = Recips.getRefinementSteps(RecipOp); | 
| Sanjay Patel | 957efc23 | 2014-10-24 17:02:16 +0000 | [diff] [blame] | 9548 | UseOneConstNR = true; | 
| Sanjay Patel | 8fde95c | 2014-09-30 20:28:48 +0000 | [diff] [blame] | 9549 | return DCI.DAG.getNode(PPCISD::FRSQRTE, SDLoc(Operand), VT, Operand); | 
| Hal Finkel | 2e10331 | 2013-04-03 04:01:11 +0000 | [diff] [blame] | 9550 | } | 
| Sanjay Patel | 8fde95c | 2014-09-30 20:28:48 +0000 | [diff] [blame] | 9551 | return SDValue(); | 
|  | 9552 | } | 
|  | 9553 |  | 
|  | 9554 | SDValue PPCTargetLowering::getRecipEstimate(SDValue Operand, | 
|  | 9555 | DAGCombinerInfo &DCI, | 
|  | 9556 | unsigned &RefinementSteps) const { | 
|  | 9557 | EVT VT = Operand.getValueType(); | 
|  | 9558 | if ((VT == MVT::f32 && Subtarget.hasFRES()) || | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 9559 | (VT == MVT::f64 && Subtarget.hasFRE()) || | 
| Sanjay Patel | 8fde95c | 2014-09-30 20:28:48 +0000 | [diff] [blame] | 9560 | (VT == MVT::v4f32 && Subtarget.hasAltivec()) || | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 9561 | (VT == MVT::v2f64 && Subtarget.hasVSX()) || | 
|  | 9562 | (VT == MVT::v4f32 && Subtarget.hasQPX()) || | 
|  | 9563 | (VT == MVT::v4f64 && Subtarget.hasQPX())) { | 
| Hal Finkel | cbf0892 | 2015-07-12 02:33:57 +0000 | [diff] [blame] | 9564 | TargetRecip Recips = DCI.DAG.getTarget().Options.Reciprocals; | 
|  | 9565 | std::string RecipOp = getRecipOp("div", VT); | 
|  | 9566 | if (!Recips.isEnabled(RecipOp)) | 
|  | 9567 | return SDValue(); | 
|  | 9568 |  | 
|  | 9569 | RefinementSteps = Recips.getRefinementSteps(RecipOp); | 
| Sanjay Patel | 8fde95c | 2014-09-30 20:28:48 +0000 | [diff] [blame] | 9570 | return DCI.DAG.getNode(PPCISD::FRE, SDLoc(Operand), VT, Operand); | 
|  | 9571 | } | 
|  | 9572 | return SDValue(); | 
| Hal Finkel | 2e10331 | 2013-04-03 04:01:11 +0000 | [diff] [blame] | 9573 | } | 
|  | 9574 |  | 
| Sanjay Patel | 1dd1559 | 2015-07-28 23:05:48 +0000 | [diff] [blame] | 9575 | unsigned PPCTargetLowering::combineRepeatedFPDivisors() const { | 
| Hal Finkel | 360f213 | 2014-11-24 23:45:21 +0000 | [diff] [blame] | 9576 | // Note: This functionality is used only when unsafe-fp-math is enabled, and | 
|  | 9577 | // on cores with reciprocal estimates (which are used when unsafe-fp-math is | 
|  | 9578 | // enabled for division), this functionality is redundant with the default | 
|  | 9579 | // combiner logic (once the division -> reciprocal/multiply transformation | 
|  | 9580 | // has taken place). As a result, this matters more for older cores than for | 
|  | 9581 | // newer ones. | 
|  | 9582 |  | 
|  | 9583 | // Combine multiple FDIVs with the same divisor into multiple FMULs by the | 
|  | 9584 | // reciprocal if there are two or more FDIVs (for embedded cores with only | 
|  | 9585 | // one FP pipeline) for three or more FDIVs (for generic OOO cores). | 
|  | 9586 | switch (Subtarget.getDarwinDirective()) { | 
|  | 9587 | default: | 
| Sanjay Patel | 1dd1559 | 2015-07-28 23:05:48 +0000 | [diff] [blame] | 9588 | return 3; | 
| Hal Finkel | 360f213 | 2014-11-24 23:45:21 +0000 | [diff] [blame] | 9589 | case PPC::DIR_440: | 
|  | 9590 | case PPC::DIR_A2: | 
|  | 9591 | case PPC::DIR_E500mc: | 
|  | 9592 | case PPC::DIR_E5500: | 
| Sanjay Patel | 1dd1559 | 2015-07-28 23:05:48 +0000 | [diff] [blame] | 9593 | return 2; | 
| Hal Finkel | 360f213 | 2014-11-24 23:45:21 +0000 | [diff] [blame] | 9594 | } | 
|  | 9595 | } | 
|  | 9596 |  | 
| Hal Finkel | e6702ca | 2015-09-03 22:37:44 +0000 | [diff] [blame] | 9597 | // isConsecutiveLSLoc needs to work even if all adds have not yet been | 
|  | 9598 | // collapsed, and so we need to look through chains of them. | 
|  | 9599 | static void getBaseWithConstantOffset(SDValue Loc, SDValue &Base, | 
|  | 9600 | int64_t& Offset, SelectionDAG &DAG) { | 
|  | 9601 | if (DAG.isBaseWithConstantOffset(Loc)) { | 
|  | 9602 | Base = Loc.getOperand(0); | 
|  | 9603 | Offset += cast<ConstantSDNode>(Loc.getOperand(1))->getSExtValue(); | 
|  | 9604 |  | 
|  | 9605 | // The base might itself be a base plus an offset, and if so, accumulate | 
|  | 9606 | // that as well. | 
|  | 9607 | getBaseWithConstantOffset(Loc.getOperand(0), Base, Offset, DAG); | 
|  | 9608 | } | 
|  | 9609 | } | 
|  | 9610 |  | 
| Hal Finkel | 3604bf7 | 2014-08-01 01:02:01 +0000 | [diff] [blame] | 9611 | static bool isConsecutiveLSLoc(SDValue Loc, EVT VT, LSBaseSDNode *Base, | 
| Hal Finkel | 8ebfe6c | 2013-05-27 02:06:39 +0000 | [diff] [blame] | 9612 | unsigned Bytes, int Dist, | 
|  | 9613 | SelectionDAG &DAG) { | 
| Hal Finkel | 8ebfe6c | 2013-05-27 02:06:39 +0000 | [diff] [blame] | 9614 | if (VT.getSizeInBits() / 8 != Bytes) | 
|  | 9615 | return false; | 
|  | 9616 |  | 
| Hal Finkel | 8ebfe6c | 2013-05-27 02:06:39 +0000 | [diff] [blame] | 9617 | SDValue BaseLoc = Base->getBasePtr(); | 
|  | 9618 | if (Loc.getOpcode() == ISD::FrameIndex) { | 
|  | 9619 | if (BaseLoc.getOpcode() != ISD::FrameIndex) | 
|  | 9620 | return false; | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 9621 | const MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo(); | 
| Hal Finkel | 8ebfe6c | 2013-05-27 02:06:39 +0000 | [diff] [blame] | 9622 | int FI  = cast<FrameIndexSDNode>(Loc)->getIndex(); | 
|  | 9623 | int BFI = cast<FrameIndexSDNode>(BaseLoc)->getIndex(); | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 9624 | int FS  = MFI.getObjectSize(FI); | 
|  | 9625 | int BFS = MFI.getObjectSize(BFI); | 
| Hal Finkel | 8ebfe6c | 2013-05-27 02:06:39 +0000 | [diff] [blame] | 9626 | if (FS != BFS || FS != (int)Bytes) return false; | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 9627 | return MFI.getObjectOffset(FI) == (MFI.getObjectOffset(BFI) + Dist*Bytes); | 
| Hal Finkel | 8ebfe6c | 2013-05-27 02:06:39 +0000 | [diff] [blame] | 9628 | } | 
|  | 9629 |  | 
| Hal Finkel | e6702ca | 2015-09-03 22:37:44 +0000 | [diff] [blame] | 9630 | SDValue Base1 = Loc, Base2 = BaseLoc; | 
|  | 9631 | int64_t Offset1 = 0, Offset2 = 0; | 
|  | 9632 | getBaseWithConstantOffset(Loc, Base1, Offset1, DAG); | 
|  | 9633 | getBaseWithConstantOffset(BaseLoc, Base2, Offset2, DAG); | 
| NAKAMURA Takumi | 70ad98a | 2015-09-22 11:13:55 +0000 | [diff] [blame] | 9634 | if (Base1 == Base2 && Offset1 == (Offset2 + Dist * Bytes)) | 
|  | 9635 | return true; | 
|  | 9636 |  | 
| Hal Finkel | 8ebfe6c | 2013-05-27 02:06:39 +0000 | [diff] [blame] | 9637 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); | 
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 9638 | const GlobalValue *GV1 = nullptr; | 
|  | 9639 | const GlobalValue *GV2 = nullptr; | 
| Hal Finkel | e6702ca | 2015-09-03 22:37:44 +0000 | [diff] [blame] | 9640 | Offset1 = 0; | 
|  | 9641 | Offset2 = 0; | 
| Hal Finkel | 8ebfe6c | 2013-05-27 02:06:39 +0000 | [diff] [blame] | 9642 | bool isGA1 = TLI.isGAPlusOffset(Loc.getNode(), GV1, Offset1); | 
|  | 9643 | bool isGA2 = TLI.isGAPlusOffset(BaseLoc.getNode(), GV2, Offset2); | 
|  | 9644 | if (isGA1 && isGA2 && GV1 == GV2) | 
|  | 9645 | return Offset1 == (Offset2 + Dist*Bytes); | 
|  | 9646 | return false; | 
|  | 9647 | } | 
|  | 9648 |  | 
| Hal Finkel | 3604bf7 | 2014-08-01 01:02:01 +0000 | [diff] [blame] | 9649 | // Like SelectionDAG::isConsecutiveLoad, but also works for stores, and does | 
|  | 9650 | // not enforce equality of the chain operands. | 
|  | 9651 | static bool isConsecutiveLS(SDNode *N, LSBaseSDNode *Base, | 
|  | 9652 | unsigned Bytes, int Dist, | 
|  | 9653 | SelectionDAG &DAG) { | 
|  | 9654 | if (LSBaseSDNode *LS = dyn_cast<LSBaseSDNode>(N)) { | 
|  | 9655 | EVT VT = LS->getMemoryVT(); | 
|  | 9656 | SDValue Loc = LS->getBasePtr(); | 
|  | 9657 | return isConsecutiveLSLoc(Loc, VT, Base, Bytes, Dist, DAG); | 
|  | 9658 | } | 
|  | 9659 |  | 
|  | 9660 | if (N->getOpcode() == ISD::INTRINSIC_W_CHAIN) { | 
|  | 9661 | EVT VT; | 
|  | 9662 | switch (cast<ConstantSDNode>(N->getOperand(1))->getZExtValue()) { | 
|  | 9663 | default: return false; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 9664 | case Intrinsic::ppc_qpx_qvlfd: | 
|  | 9665 | case Intrinsic::ppc_qpx_qvlfda: | 
|  | 9666 | VT = MVT::v4f64; | 
|  | 9667 | break; | 
|  | 9668 | case Intrinsic::ppc_qpx_qvlfs: | 
|  | 9669 | case Intrinsic::ppc_qpx_qvlfsa: | 
|  | 9670 | VT = MVT::v4f32; | 
|  | 9671 | break; | 
|  | 9672 | case Intrinsic::ppc_qpx_qvlfcd: | 
|  | 9673 | case Intrinsic::ppc_qpx_qvlfcda: | 
|  | 9674 | VT = MVT::v2f64; | 
|  | 9675 | break; | 
|  | 9676 | case Intrinsic::ppc_qpx_qvlfcs: | 
|  | 9677 | case Intrinsic::ppc_qpx_qvlfcsa: | 
|  | 9678 | VT = MVT::v2f32; | 
|  | 9679 | break; | 
|  | 9680 | case Intrinsic::ppc_qpx_qvlfiwa: | 
|  | 9681 | case Intrinsic::ppc_qpx_qvlfiwz: | 
| Hal Finkel | 3604bf7 | 2014-08-01 01:02:01 +0000 | [diff] [blame] | 9682 | case Intrinsic::ppc_altivec_lvx: | 
|  | 9683 | case Intrinsic::ppc_altivec_lvxl: | 
| Bill Schmidt | 7295478 | 2014-11-12 04:19:40 +0000 | [diff] [blame] | 9684 | case Intrinsic::ppc_vsx_lxvw4x: | 
| Hal Finkel | 3604bf7 | 2014-08-01 01:02:01 +0000 | [diff] [blame] | 9685 | VT = MVT::v4i32; | 
|  | 9686 | break; | 
| Bill Schmidt | 7295478 | 2014-11-12 04:19:40 +0000 | [diff] [blame] | 9687 | case Intrinsic::ppc_vsx_lxvd2x: | 
|  | 9688 | VT = MVT::v2f64; | 
|  | 9689 | break; | 
| Hal Finkel | 3604bf7 | 2014-08-01 01:02:01 +0000 | [diff] [blame] | 9690 | case Intrinsic::ppc_altivec_lvebx: | 
|  | 9691 | VT = MVT::i8; | 
|  | 9692 | break; | 
|  | 9693 | case Intrinsic::ppc_altivec_lvehx: | 
|  | 9694 | VT = MVT::i16; | 
|  | 9695 | break; | 
|  | 9696 | case Intrinsic::ppc_altivec_lvewx: | 
|  | 9697 | VT = MVT::i32; | 
|  | 9698 | break; | 
|  | 9699 | } | 
|  | 9700 |  | 
|  | 9701 | return isConsecutiveLSLoc(N->getOperand(2), VT, Base, Bytes, Dist, DAG); | 
|  | 9702 | } | 
|  | 9703 |  | 
|  | 9704 | if (N->getOpcode() == ISD::INTRINSIC_VOID) { | 
|  | 9705 | EVT VT; | 
|  | 9706 | switch (cast<ConstantSDNode>(N->getOperand(1))->getZExtValue()) { | 
|  | 9707 | default: return false; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 9708 | case Intrinsic::ppc_qpx_qvstfd: | 
|  | 9709 | case Intrinsic::ppc_qpx_qvstfda: | 
|  | 9710 | VT = MVT::v4f64; | 
|  | 9711 | break; | 
|  | 9712 | case Intrinsic::ppc_qpx_qvstfs: | 
|  | 9713 | case Intrinsic::ppc_qpx_qvstfsa: | 
|  | 9714 | VT = MVT::v4f32; | 
|  | 9715 | break; | 
|  | 9716 | case Intrinsic::ppc_qpx_qvstfcd: | 
|  | 9717 | case Intrinsic::ppc_qpx_qvstfcda: | 
|  | 9718 | VT = MVT::v2f64; | 
|  | 9719 | break; | 
|  | 9720 | case Intrinsic::ppc_qpx_qvstfcs: | 
|  | 9721 | case Intrinsic::ppc_qpx_qvstfcsa: | 
|  | 9722 | VT = MVT::v2f32; | 
|  | 9723 | break; | 
|  | 9724 | case Intrinsic::ppc_qpx_qvstfiw: | 
|  | 9725 | case Intrinsic::ppc_qpx_qvstfiwa: | 
| Hal Finkel | 3604bf7 | 2014-08-01 01:02:01 +0000 | [diff] [blame] | 9726 | case Intrinsic::ppc_altivec_stvx: | 
|  | 9727 | case Intrinsic::ppc_altivec_stvxl: | 
| Bill Schmidt | 7295478 | 2014-11-12 04:19:40 +0000 | [diff] [blame] | 9728 | case Intrinsic::ppc_vsx_stxvw4x: | 
| Hal Finkel | 3604bf7 | 2014-08-01 01:02:01 +0000 | [diff] [blame] | 9729 | VT = MVT::v4i32; | 
|  | 9730 | break; | 
| Bill Schmidt | 7295478 | 2014-11-12 04:19:40 +0000 | [diff] [blame] | 9731 | case Intrinsic::ppc_vsx_stxvd2x: | 
|  | 9732 | VT = MVT::v2f64; | 
|  | 9733 | break; | 
| Hal Finkel | 3604bf7 | 2014-08-01 01:02:01 +0000 | [diff] [blame] | 9734 | case Intrinsic::ppc_altivec_stvebx: | 
|  | 9735 | VT = MVT::i8; | 
|  | 9736 | break; | 
|  | 9737 | case Intrinsic::ppc_altivec_stvehx: | 
|  | 9738 | VT = MVT::i16; | 
|  | 9739 | break; | 
|  | 9740 | case Intrinsic::ppc_altivec_stvewx: | 
|  | 9741 | VT = MVT::i32; | 
|  | 9742 | break; | 
|  | 9743 | } | 
|  | 9744 |  | 
|  | 9745 | return isConsecutiveLSLoc(N->getOperand(3), VT, Base, Bytes, Dist, DAG); | 
|  | 9746 | } | 
|  | 9747 |  | 
|  | 9748 | return false; | 
|  | 9749 | } | 
|  | 9750 |  | 
| Hal Finkel | 7d8a691 | 2013-05-26 18:08:30 +0000 | [diff] [blame] | 9751 | // Return true is there is a nearyby consecutive load to the one provided | 
|  | 9752 | // (regardless of alignment). We search up and down the chain, looking though | 
| Matt Arsenault | 57e74d2 | 2014-07-29 00:02:40 +0000 | [diff] [blame] | 9753 | // token factors and other loads (but nothing else). As a result, a true result | 
|  | 9754 | // indicates that it is safe to create a new consecutive load adjacent to the | 
|  | 9755 | // load provided. | 
| Hal Finkel | 7d8a691 | 2013-05-26 18:08:30 +0000 | [diff] [blame] | 9756 | static bool findConsecutiveLoad(LoadSDNode *LD, SelectionDAG &DAG) { | 
|  | 9757 | SDValue Chain = LD->getChain(); | 
|  | 9758 | EVT VT = LD->getMemoryVT(); | 
|  | 9759 |  | 
|  | 9760 | SmallSet<SDNode *, 16> LoadRoots; | 
|  | 9761 | SmallVector<SDNode *, 8> Queue(1, Chain.getNode()); | 
|  | 9762 | SmallSet<SDNode *, 16> Visited; | 
|  | 9763 |  | 
|  | 9764 | // First, search up the chain, branching to follow all token-factor operands. | 
|  | 9765 | // If we find a consecutive load, then we're done, otherwise, record all | 
|  | 9766 | // nodes just above the top-level loads and token factors. | 
|  | 9767 | while (!Queue.empty()) { | 
|  | 9768 | SDNode *ChainNext = Queue.pop_back_val(); | 
| David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 9769 | if (!Visited.insert(ChainNext).second) | 
| Hal Finkel | 7d8a691 | 2013-05-26 18:08:30 +0000 | [diff] [blame] | 9770 | continue; | 
|  | 9771 |  | 
| Hal Finkel | 3604bf7 | 2014-08-01 01:02:01 +0000 | [diff] [blame] | 9772 | if (MemSDNode *ChainLD = dyn_cast<MemSDNode>(ChainNext)) { | 
| Hal Finkel | 8ebfe6c | 2013-05-27 02:06:39 +0000 | [diff] [blame] | 9773 | if (isConsecutiveLS(ChainLD, LD, VT.getStoreSize(), 1, DAG)) | 
| Hal Finkel | 7d8a691 | 2013-05-26 18:08:30 +0000 | [diff] [blame] | 9774 | return true; | 
|  | 9775 |  | 
|  | 9776 | if (!Visited.count(ChainLD->getChain().getNode())) | 
|  | 9777 | Queue.push_back(ChainLD->getChain().getNode()); | 
|  | 9778 | } else if (ChainNext->getOpcode() == ISD::TokenFactor) { | 
| Craig Topper | 66e588b | 2014-06-29 00:40:57 +0000 | [diff] [blame] | 9779 | for (const SDUse &O : ChainNext->ops()) | 
|  | 9780 | if (!Visited.count(O.getNode())) | 
|  | 9781 | Queue.push_back(O.getNode()); | 
| Hal Finkel | 7d8a691 | 2013-05-26 18:08:30 +0000 | [diff] [blame] | 9782 | } else | 
|  | 9783 | LoadRoots.insert(ChainNext); | 
|  | 9784 | } | 
|  | 9785 |  | 
|  | 9786 | // Second, search down the chain, starting from the top-level nodes recorded | 
|  | 9787 | // in the first phase. These top-level nodes are the nodes just above all | 
|  | 9788 | // loads and token factors. Starting with their uses, recursively look though | 
|  | 9789 | // all loads (just the chain uses) and token factors to find a consecutive | 
|  | 9790 | // load. | 
|  | 9791 | Visited.clear(); | 
|  | 9792 | Queue.clear(); | 
|  | 9793 |  | 
|  | 9794 | for (SmallSet<SDNode *, 16>::iterator I = LoadRoots.begin(), | 
|  | 9795 | IE = LoadRoots.end(); I != IE; ++I) { | 
|  | 9796 | Queue.push_back(*I); | 
| NAKAMURA Takumi | a9cb538 | 2015-09-22 11:14:39 +0000 | [diff] [blame] | 9797 |  | 
| Hal Finkel | 7d8a691 | 2013-05-26 18:08:30 +0000 | [diff] [blame] | 9798 | while (!Queue.empty()) { | 
|  | 9799 | SDNode *LoadRoot = Queue.pop_back_val(); | 
| David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 9800 | if (!Visited.insert(LoadRoot).second) | 
| Hal Finkel | 7d8a691 | 2013-05-26 18:08:30 +0000 | [diff] [blame] | 9801 | continue; | 
|  | 9802 |  | 
| Hal Finkel | 3604bf7 | 2014-08-01 01:02:01 +0000 | [diff] [blame] | 9803 | if (MemSDNode *ChainLD = dyn_cast<MemSDNode>(LoadRoot)) | 
| Hal Finkel | 8ebfe6c | 2013-05-27 02:06:39 +0000 | [diff] [blame] | 9804 | if (isConsecutiveLS(ChainLD, LD, VT.getStoreSize(), 1, DAG)) | 
| Hal Finkel | 7d8a691 | 2013-05-26 18:08:30 +0000 | [diff] [blame] | 9805 | return true; | 
|  | 9806 |  | 
|  | 9807 | for (SDNode::use_iterator UI = LoadRoot->use_begin(), | 
|  | 9808 | UE = LoadRoot->use_end(); UI != UE; ++UI) | 
| Hal Finkel | 3604bf7 | 2014-08-01 01:02:01 +0000 | [diff] [blame] | 9809 | if (((isa<MemSDNode>(*UI) && | 
|  | 9810 | cast<MemSDNode>(*UI)->getChain().getNode() == LoadRoot) || | 
| Hal Finkel | 7d8a691 | 2013-05-26 18:08:30 +0000 | [diff] [blame] | 9811 | UI->getOpcode() == ISD::TokenFactor) && !Visited.count(*UI)) | 
|  | 9812 | Queue.push_back(*UI); | 
|  | 9813 | } | 
|  | 9814 | } | 
|  | 9815 |  | 
|  | 9816 | return false; | 
|  | 9817 | } | 
|  | 9818 |  | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 9819 | SDValue PPCTargetLowering::DAGCombineTruncBoolExt(SDNode *N, | 
|  | 9820 | DAGCombinerInfo &DCI) const { | 
|  | 9821 | SelectionDAG &DAG = DCI.DAG; | 
|  | 9822 | SDLoc dl(N); | 
|  | 9823 |  | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 9824 | assert(Subtarget.useCRBits() && "Expecting to be tracking CR bits"); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 9825 | // If we're tracking CR bits, we need to be careful that we don't have: | 
|  | 9826 | //   trunc(binary-ops(zext(x), zext(y))) | 
|  | 9827 | // or | 
|  | 9828 | //   trunc(binary-ops(binary-ops(zext(x), zext(y)), ...) | 
|  | 9829 | // such that we're unnecessarily moving things into GPRs when it would be | 
|  | 9830 | // better to keep them in CR bits. | 
|  | 9831 |  | 
|  | 9832 | // Note that trunc here can be an actual i1 trunc, or can be the effective | 
|  | 9833 | // truncation that comes from a setcc or select_cc. | 
|  | 9834 | if (N->getOpcode() == ISD::TRUNCATE && | 
|  | 9835 | N->getValueType(0) != MVT::i1) | 
|  | 9836 | return SDValue(); | 
|  | 9837 |  | 
|  | 9838 | if (N->getOperand(0).getValueType() != MVT::i32 && | 
|  | 9839 | N->getOperand(0).getValueType() != MVT::i64) | 
|  | 9840 | return SDValue(); | 
|  | 9841 |  | 
|  | 9842 | if (N->getOpcode() == ISD::SETCC || | 
|  | 9843 | N->getOpcode() == ISD::SELECT_CC) { | 
|  | 9844 | // If we're looking at a comparison, then we need to make sure that the | 
|  | 9845 | // high bits (all except for the first) don't matter the result. | 
|  | 9846 | ISD::CondCode CC = | 
|  | 9847 | cast<CondCodeSDNode>(N->getOperand( | 
|  | 9848 | N->getOpcode() == ISD::SETCC ? 2 : 4))->get(); | 
|  | 9849 | unsigned OpBits = N->getOperand(0).getValueSizeInBits(); | 
|  | 9850 |  | 
|  | 9851 | if (ISD::isSignedIntSetCC(CC)) { | 
|  | 9852 | if (DAG.ComputeNumSignBits(N->getOperand(0)) != OpBits || | 
|  | 9853 | DAG.ComputeNumSignBits(N->getOperand(1)) != OpBits) | 
|  | 9854 | return SDValue(); | 
|  | 9855 | } else if (ISD::isUnsignedIntSetCC(CC)) { | 
|  | 9856 | if (!DAG.MaskedValueIsZero(N->getOperand(0), | 
|  | 9857 | APInt::getHighBitsSet(OpBits, OpBits-1)) || | 
|  | 9858 | !DAG.MaskedValueIsZero(N->getOperand(1), | 
|  | 9859 | APInt::getHighBitsSet(OpBits, OpBits-1))) | 
|  | 9860 | return SDValue(); | 
|  | 9861 | } else { | 
|  | 9862 | // This is neither a signed nor an unsigned comparison, just make sure | 
|  | 9863 | // that the high bits are equal. | 
|  | 9864 | APInt Op1Zero, Op1One; | 
|  | 9865 | APInt Op2Zero, Op2One; | 
| Jay Foad | a0653a3 | 2014-05-14 21:14:37 +0000 | [diff] [blame] | 9866 | DAG.computeKnownBits(N->getOperand(0), Op1Zero, Op1One); | 
|  | 9867 | DAG.computeKnownBits(N->getOperand(1), Op2Zero, Op2One); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 9868 |  | 
|  | 9869 | // We don't really care about what is known about the first bit (if | 
|  | 9870 | // anything), so clear it in all masks prior to comparing them. | 
|  | 9871 | Op1Zero.clearBit(0); Op1One.clearBit(0); | 
|  | 9872 | Op2Zero.clearBit(0); Op2One.clearBit(0); | 
|  | 9873 |  | 
|  | 9874 | if (Op1Zero != Op2Zero || Op1One != Op2One) | 
|  | 9875 | return SDValue(); | 
|  | 9876 | } | 
|  | 9877 | } | 
|  | 9878 |  | 
|  | 9879 | // We now know that the higher-order bits are irrelevant, we just need to | 
|  | 9880 | // make sure that all of the intermediate operations are bit operations, and | 
|  | 9881 | // all inputs are extensions. | 
|  | 9882 | if (N->getOperand(0).getOpcode() != ISD::AND && | 
|  | 9883 | N->getOperand(0).getOpcode() != ISD::OR  && | 
|  | 9884 | N->getOperand(0).getOpcode() != ISD::XOR && | 
|  | 9885 | N->getOperand(0).getOpcode() != ISD::SELECT && | 
|  | 9886 | N->getOperand(0).getOpcode() != ISD::SELECT_CC && | 
|  | 9887 | N->getOperand(0).getOpcode() != ISD::TRUNCATE && | 
|  | 9888 | N->getOperand(0).getOpcode() != ISD::SIGN_EXTEND && | 
|  | 9889 | N->getOperand(0).getOpcode() != ISD::ZERO_EXTEND && | 
|  | 9890 | N->getOperand(0).getOpcode() != ISD::ANY_EXTEND) | 
|  | 9891 | return SDValue(); | 
|  | 9892 |  | 
|  | 9893 | if ((N->getOpcode() == ISD::SETCC || N->getOpcode() == ISD::SELECT_CC) && | 
|  | 9894 | N->getOperand(1).getOpcode() != ISD::AND && | 
|  | 9895 | N->getOperand(1).getOpcode() != ISD::OR  && | 
|  | 9896 | N->getOperand(1).getOpcode() != ISD::XOR && | 
|  | 9897 | N->getOperand(1).getOpcode() != ISD::SELECT && | 
|  | 9898 | N->getOperand(1).getOpcode() != ISD::SELECT_CC && | 
|  | 9899 | N->getOperand(1).getOpcode() != ISD::TRUNCATE && | 
|  | 9900 | N->getOperand(1).getOpcode() != ISD::SIGN_EXTEND && | 
|  | 9901 | N->getOperand(1).getOpcode() != ISD::ZERO_EXTEND && | 
|  | 9902 | N->getOperand(1).getOpcode() != ISD::ANY_EXTEND) | 
|  | 9903 | return SDValue(); | 
|  | 9904 |  | 
|  | 9905 | SmallVector<SDValue, 4> Inputs; | 
|  | 9906 | SmallVector<SDValue, 8> BinOps, PromOps; | 
|  | 9907 | SmallPtrSet<SDNode *, 16> Visited; | 
|  | 9908 |  | 
|  | 9909 | for (unsigned i = 0; i < 2; ++i) { | 
|  | 9910 | if (((N->getOperand(i).getOpcode() == ISD::SIGN_EXTEND || | 
|  | 9911 | N->getOperand(i).getOpcode() == ISD::ZERO_EXTEND || | 
|  | 9912 | N->getOperand(i).getOpcode() == ISD::ANY_EXTEND) && | 
|  | 9913 | N->getOperand(i).getOperand(0).getValueType() == MVT::i1) || | 
|  | 9914 | isa<ConstantSDNode>(N->getOperand(i))) | 
|  | 9915 | Inputs.push_back(N->getOperand(i)); | 
|  | 9916 | else | 
|  | 9917 | BinOps.push_back(N->getOperand(i)); | 
|  | 9918 |  | 
|  | 9919 | if (N->getOpcode() == ISD::TRUNCATE) | 
|  | 9920 | break; | 
|  | 9921 | } | 
|  | 9922 |  | 
|  | 9923 | // Visit all inputs, collect all binary operations (and, or, xor and | 
| NAKAMURA Takumi | 8496503 | 2015-09-22 11:14:12 +0000 | [diff] [blame] | 9924 | // select) that are all fed by extensions. | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 9925 | while (!BinOps.empty()) { | 
|  | 9926 | SDValue BinOp = BinOps.back(); | 
|  | 9927 | BinOps.pop_back(); | 
|  | 9928 |  | 
| David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 9929 | if (!Visited.insert(BinOp.getNode()).second) | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 9930 | continue; | 
|  | 9931 |  | 
|  | 9932 | PromOps.push_back(BinOp); | 
|  | 9933 |  | 
|  | 9934 | for (unsigned i = 0, ie = BinOp.getNumOperands(); i != ie; ++i) { | 
|  | 9935 | // The condition of the select is not promoted. | 
|  | 9936 | if (BinOp.getOpcode() == ISD::SELECT && i == 0) | 
|  | 9937 | continue; | 
|  | 9938 | if (BinOp.getOpcode() == ISD::SELECT_CC && i != 2 && i != 3) | 
|  | 9939 | continue; | 
|  | 9940 |  | 
|  | 9941 | if (((BinOp.getOperand(i).getOpcode() == ISD::SIGN_EXTEND || | 
|  | 9942 | BinOp.getOperand(i).getOpcode() == ISD::ZERO_EXTEND || | 
|  | 9943 | BinOp.getOperand(i).getOpcode() == ISD::ANY_EXTEND) && | 
|  | 9944 | BinOp.getOperand(i).getOperand(0).getValueType() == MVT::i1) || | 
|  | 9945 | isa<ConstantSDNode>(BinOp.getOperand(i))) { | 
| NAKAMURA Takumi | 10c80e7 | 2015-09-22 11:19:03 +0000 | [diff] [blame] | 9946 | Inputs.push_back(BinOp.getOperand(i)); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 9947 | } else if (BinOp.getOperand(i).getOpcode() == ISD::AND || | 
|  | 9948 | BinOp.getOperand(i).getOpcode() == ISD::OR  || | 
|  | 9949 | BinOp.getOperand(i).getOpcode() == ISD::XOR || | 
|  | 9950 | BinOp.getOperand(i).getOpcode() == ISD::SELECT || | 
|  | 9951 | BinOp.getOperand(i).getOpcode() == ISD::SELECT_CC || | 
|  | 9952 | BinOp.getOperand(i).getOpcode() == ISD::TRUNCATE || | 
|  | 9953 | BinOp.getOperand(i).getOpcode() == ISD::SIGN_EXTEND || | 
|  | 9954 | BinOp.getOperand(i).getOpcode() == ISD::ZERO_EXTEND || | 
|  | 9955 | BinOp.getOperand(i).getOpcode() == ISD::ANY_EXTEND) { | 
|  | 9956 | BinOps.push_back(BinOp.getOperand(i)); | 
|  | 9957 | } else { | 
|  | 9958 | // We have an input that is not an extension or another binary | 
|  | 9959 | // operation; we'll abort this transformation. | 
|  | 9960 | return SDValue(); | 
|  | 9961 | } | 
|  | 9962 | } | 
|  | 9963 | } | 
|  | 9964 |  | 
|  | 9965 | // Make sure that this is a self-contained cluster of operations (which | 
|  | 9966 | // is not quite the same thing as saying that everything has only one | 
|  | 9967 | // use). | 
|  | 9968 | for (unsigned i = 0, ie = Inputs.size(); i != ie; ++i) { | 
|  | 9969 | if (isa<ConstantSDNode>(Inputs[i])) | 
|  | 9970 | continue; | 
|  | 9971 |  | 
|  | 9972 | for (SDNode::use_iterator UI = Inputs[i].getNode()->use_begin(), | 
|  | 9973 | UE = Inputs[i].getNode()->use_end(); | 
|  | 9974 | UI != UE; ++UI) { | 
|  | 9975 | SDNode *User = *UI; | 
|  | 9976 | if (User != N && !Visited.count(User)) | 
|  | 9977 | return SDValue(); | 
| Hal Finkel | 46043ed | 2014-03-01 21:36:57 +0000 | [diff] [blame] | 9978 |  | 
|  | 9979 | // Make sure that we're not going to promote the non-output-value | 
|  | 9980 | // operand(s) or SELECT or SELECT_CC. | 
|  | 9981 | // FIXME: Although we could sometimes handle this, and it does occur in | 
|  | 9982 | // practice that one of the condition inputs to the select is also one of | 
|  | 9983 | // the outputs, we currently can't deal with this. | 
|  | 9984 | if (User->getOpcode() == ISD::SELECT) { | 
|  | 9985 | if (User->getOperand(0) == Inputs[i]) | 
|  | 9986 | return SDValue(); | 
|  | 9987 | } else if (User->getOpcode() == ISD::SELECT_CC) { | 
|  | 9988 | if (User->getOperand(0) == Inputs[i] || | 
|  | 9989 | User->getOperand(1) == Inputs[i]) | 
|  | 9990 | return SDValue(); | 
|  | 9991 | } | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 9992 | } | 
|  | 9993 | } | 
|  | 9994 |  | 
|  | 9995 | for (unsigned i = 0, ie = PromOps.size(); i != ie; ++i) { | 
|  | 9996 | for (SDNode::use_iterator UI = PromOps[i].getNode()->use_begin(), | 
|  | 9997 | UE = PromOps[i].getNode()->use_end(); | 
|  | 9998 | UI != UE; ++UI) { | 
|  | 9999 | SDNode *User = *UI; | 
|  | 10000 | if (User != N && !Visited.count(User)) | 
|  | 10001 | return SDValue(); | 
| Hal Finkel | 46043ed | 2014-03-01 21:36:57 +0000 | [diff] [blame] | 10002 |  | 
|  | 10003 | // Make sure that we're not going to promote the non-output-value | 
|  | 10004 | // operand(s) or SELECT or SELECT_CC. | 
|  | 10005 | // FIXME: Although we could sometimes handle this, and it does occur in | 
|  | 10006 | // practice that one of the condition inputs to the select is also one of | 
|  | 10007 | // the outputs, we currently can't deal with this. | 
|  | 10008 | if (User->getOpcode() == ISD::SELECT) { | 
|  | 10009 | if (User->getOperand(0) == PromOps[i]) | 
|  | 10010 | return SDValue(); | 
|  | 10011 | } else if (User->getOpcode() == ISD::SELECT_CC) { | 
|  | 10012 | if (User->getOperand(0) == PromOps[i] || | 
|  | 10013 | User->getOperand(1) == PromOps[i]) | 
|  | 10014 | return SDValue(); | 
|  | 10015 | } | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10016 | } | 
|  | 10017 | } | 
|  | 10018 |  | 
|  | 10019 | // Replace all inputs with the extension operand. | 
|  | 10020 | for (unsigned i = 0, ie = Inputs.size(); i != ie; ++i) { | 
|  | 10021 | // Constants may have users outside the cluster of to-be-promoted nodes, | 
|  | 10022 | // and so we need to replace those as we do the promotions. | 
|  | 10023 | if (isa<ConstantSDNode>(Inputs[i])) | 
|  | 10024 | continue; | 
|  | 10025 | else | 
| NAKAMURA Takumi | 10c80e7 | 2015-09-22 11:19:03 +0000 | [diff] [blame] | 10026 | DAG.ReplaceAllUsesOfValueWith(Inputs[i], Inputs[i].getOperand(0)); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10027 | } | 
|  | 10028 |  | 
| Hal Finkel | 1fb10e8 | 2016-05-12 04:00:56 +0000 | [diff] [blame] | 10029 | std::list<HandleSDNode> PromOpHandles; | 
|  | 10030 | for (auto &PromOp : PromOps) | 
| NAKAMURA Takumi | ae7c97d | 2016-06-20 00:49:20 +0000 | [diff] [blame] | 10031 | PromOpHandles.emplace_back(PromOp); | 
| Hal Finkel | 1fb10e8 | 2016-05-12 04:00:56 +0000 | [diff] [blame] | 10032 |  | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10033 | // Replace all operations (these are all the same, but have a different | 
|  | 10034 | // (i1) return type). DAG.getNode will validate that the types of | 
|  | 10035 | // a binary operator match, so go through the list in reverse so that | 
|  | 10036 | // we've likely promoted both operands first. Any intermediate truncations or | 
|  | 10037 | // extensions disappear. | 
| Hal Finkel | 1fb10e8 | 2016-05-12 04:00:56 +0000 | [diff] [blame] | 10038 | while (!PromOpHandles.empty()) { | 
|  | 10039 | SDValue PromOp = PromOpHandles.back().getValue(); | 
|  | 10040 | PromOpHandles.pop_back(); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10041 |  | 
|  | 10042 | if (PromOp.getOpcode() == ISD::TRUNCATE || | 
|  | 10043 | PromOp.getOpcode() == ISD::SIGN_EXTEND || | 
|  | 10044 | PromOp.getOpcode() == ISD::ZERO_EXTEND || | 
|  | 10045 | PromOp.getOpcode() == ISD::ANY_EXTEND) { | 
|  | 10046 | if (!isa<ConstantSDNode>(PromOp.getOperand(0)) && | 
|  | 10047 | PromOp.getOperand(0).getValueType() != MVT::i1) { | 
|  | 10048 | // The operand is not yet ready (see comment below). | 
| Hal Finkel | 1fb10e8 | 2016-05-12 04:00:56 +0000 | [diff] [blame] | 10049 | PromOpHandles.emplace_front(PromOp); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10050 | continue; | 
|  | 10051 | } | 
|  | 10052 |  | 
|  | 10053 | SDValue RepValue = PromOp.getOperand(0); | 
|  | 10054 | if (isa<ConstantSDNode>(RepValue)) | 
|  | 10055 | RepValue = DAG.getNode(ISD::TRUNCATE, dl, MVT::i1, RepValue); | 
|  | 10056 |  | 
|  | 10057 | DAG.ReplaceAllUsesOfValueWith(PromOp, RepValue); | 
|  | 10058 | continue; | 
|  | 10059 | } | 
|  | 10060 |  | 
|  | 10061 | unsigned C; | 
|  | 10062 | switch (PromOp.getOpcode()) { | 
|  | 10063 | default:             C = 0; break; | 
|  | 10064 | case ISD::SELECT:    C = 1; break; | 
|  | 10065 | case ISD::SELECT_CC: C = 2; break; | 
|  | 10066 | } | 
|  | 10067 |  | 
|  | 10068 | if ((!isa<ConstantSDNode>(PromOp.getOperand(C)) && | 
|  | 10069 | PromOp.getOperand(C).getValueType() != MVT::i1) || | 
|  | 10070 | (!isa<ConstantSDNode>(PromOp.getOperand(C+1)) && | 
|  | 10071 | PromOp.getOperand(C+1).getValueType() != MVT::i1)) { | 
|  | 10072 | // The to-be-promoted operands of this node have not yet been | 
|  | 10073 | // promoted (this should be rare because we're going through the | 
|  | 10074 | // list backward, but if one of the operands has several users in | 
|  | 10075 | // this cluster of to-be-promoted nodes, it is possible). | 
| Hal Finkel | 1fb10e8 | 2016-05-12 04:00:56 +0000 | [diff] [blame] | 10076 | PromOpHandles.emplace_front(PromOp); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10077 | continue; | 
|  | 10078 | } | 
|  | 10079 |  | 
|  | 10080 | SmallVector<SDValue, 3> Ops(PromOp.getNode()->op_begin(), | 
|  | 10081 | PromOp.getNode()->op_end()); | 
|  | 10082 |  | 
|  | 10083 | // If there are any constant inputs, make sure they're replaced now. | 
|  | 10084 | for (unsigned i = 0; i < 2; ++i) | 
|  | 10085 | if (isa<ConstantSDNode>(Ops[C+i])) | 
|  | 10086 | Ops[C+i] = DAG.getNode(ISD::TRUNCATE, dl, MVT::i1, Ops[C+i]); | 
|  | 10087 |  | 
|  | 10088 | DAG.ReplaceAllUsesOfValueWith(PromOp, | 
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 10089 | DAG.getNode(PromOp.getOpcode(), dl, MVT::i1, Ops)); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10090 | } | 
|  | 10091 |  | 
|  | 10092 | // Now we're left with the initial truncation itself. | 
|  | 10093 | if (N->getOpcode() == ISD::TRUNCATE) | 
|  | 10094 | return N->getOperand(0); | 
|  | 10095 |  | 
|  | 10096 | // Otherwise, this is a comparison. The operands to be compared have just | 
|  | 10097 | // changed type (to i1), but everything else is the same. | 
|  | 10098 | return SDValue(N, 0); | 
|  | 10099 | } | 
|  | 10100 |  | 
|  | 10101 | SDValue PPCTargetLowering::DAGCombineExtBoolTrunc(SDNode *N, | 
|  | 10102 | DAGCombinerInfo &DCI) const { | 
|  | 10103 | SelectionDAG &DAG = DCI.DAG; | 
|  | 10104 | SDLoc dl(N); | 
|  | 10105 |  | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10106 | // If we're tracking CR bits, we need to be careful that we don't have: | 
|  | 10107 | //   zext(binary-ops(trunc(x), trunc(y))) | 
|  | 10108 | // or | 
|  | 10109 | //   zext(binary-ops(binary-ops(trunc(x), trunc(y)), ...) | 
|  | 10110 | // such that we're unnecessarily moving things into CR bits that can more | 
|  | 10111 | // efficiently stay in GPRs. Note that if we're not certain that the high | 
|  | 10112 | // bits are set as required by the final extension, we still may need to do | 
|  | 10113 | // some masking to get the proper behavior. | 
|  | 10114 |  | 
| Hal Finkel | 46043ed | 2014-03-01 21:36:57 +0000 | [diff] [blame] | 10115 | // This same functionality is important on PPC64 when dealing with | 
|  | 10116 | // 32-to-64-bit extensions; these occur often when 32-bit values are used as | 
|  | 10117 | // the return values of functions. Because it is so similar, it is handled | 
|  | 10118 | // here as well. | 
|  | 10119 |  | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10120 | if (N->getValueType(0) != MVT::i32 && | 
|  | 10121 | N->getValueType(0) != MVT::i64) | 
|  | 10122 | return SDValue(); | 
|  | 10123 |  | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 10124 | if (!((N->getOperand(0).getValueType() == MVT::i1 && Subtarget.useCRBits()) || | 
|  | 10125 | (N->getOperand(0).getValueType() == MVT::i32 && Subtarget.isPPC64()))) | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10126 | return SDValue(); | 
|  | 10127 |  | 
|  | 10128 | if (N->getOperand(0).getOpcode() != ISD::AND && | 
|  | 10129 | N->getOperand(0).getOpcode() != ISD::OR  && | 
|  | 10130 | N->getOperand(0).getOpcode() != ISD::XOR && | 
|  | 10131 | N->getOperand(0).getOpcode() != ISD::SELECT && | 
|  | 10132 | N->getOperand(0).getOpcode() != ISD::SELECT_CC) | 
|  | 10133 | return SDValue(); | 
|  | 10134 |  | 
|  | 10135 | SmallVector<SDValue, 4> Inputs; | 
|  | 10136 | SmallVector<SDValue, 8> BinOps(1, N->getOperand(0)), PromOps; | 
|  | 10137 | SmallPtrSet<SDNode *, 16> Visited; | 
|  | 10138 |  | 
|  | 10139 | // Visit all inputs, collect all binary operations (and, or, xor and | 
| NAKAMURA Takumi | 8496503 | 2015-09-22 11:14:12 +0000 | [diff] [blame] | 10140 | // select) that are all fed by truncations. | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10141 | while (!BinOps.empty()) { | 
|  | 10142 | SDValue BinOp = BinOps.back(); | 
|  | 10143 | BinOps.pop_back(); | 
|  | 10144 |  | 
| David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 10145 | if (!Visited.insert(BinOp.getNode()).second) | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10146 | continue; | 
|  | 10147 |  | 
|  | 10148 | PromOps.push_back(BinOp); | 
|  | 10149 |  | 
|  | 10150 | for (unsigned i = 0, ie = BinOp.getNumOperands(); i != ie; ++i) { | 
|  | 10151 | // The condition of the select is not promoted. | 
|  | 10152 | if (BinOp.getOpcode() == ISD::SELECT && i == 0) | 
|  | 10153 | continue; | 
|  | 10154 | if (BinOp.getOpcode() == ISD::SELECT_CC && i != 2 && i != 3) | 
|  | 10155 | continue; | 
|  | 10156 |  | 
|  | 10157 | if (BinOp.getOperand(i).getOpcode() == ISD::TRUNCATE || | 
|  | 10158 | isa<ConstantSDNode>(BinOp.getOperand(i))) { | 
| NAKAMURA Takumi | 10c80e7 | 2015-09-22 11:19:03 +0000 | [diff] [blame] | 10159 | Inputs.push_back(BinOp.getOperand(i)); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10160 | } else if (BinOp.getOperand(i).getOpcode() == ISD::AND || | 
|  | 10161 | BinOp.getOperand(i).getOpcode() == ISD::OR  || | 
|  | 10162 | BinOp.getOperand(i).getOpcode() == ISD::XOR || | 
|  | 10163 | BinOp.getOperand(i).getOpcode() == ISD::SELECT || | 
|  | 10164 | BinOp.getOperand(i).getOpcode() == ISD::SELECT_CC) { | 
|  | 10165 | BinOps.push_back(BinOp.getOperand(i)); | 
|  | 10166 | } else { | 
|  | 10167 | // We have an input that is not a truncation or another binary | 
|  | 10168 | // operation; we'll abort this transformation. | 
|  | 10169 | return SDValue(); | 
|  | 10170 | } | 
|  | 10171 | } | 
|  | 10172 | } | 
|  | 10173 |  | 
| Hal Finkel | 4104a1a | 2014-12-14 05:53:19 +0000 | [diff] [blame] | 10174 | // The operands of a select that must be truncated when the select is | 
|  | 10175 | // promoted because the operand is actually part of the to-be-promoted set. | 
|  | 10176 | DenseMap<SDNode *, EVT> SelectTruncOp[2]; | 
|  | 10177 |  | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10178 | // Make sure that this is a self-contained cluster of operations (which | 
|  | 10179 | // is not quite the same thing as saying that everything has only one | 
|  | 10180 | // use). | 
|  | 10181 | for (unsigned i = 0, ie = Inputs.size(); i != ie; ++i) { | 
|  | 10182 | if (isa<ConstantSDNode>(Inputs[i])) | 
|  | 10183 | continue; | 
|  | 10184 |  | 
|  | 10185 | for (SDNode::use_iterator UI = Inputs[i].getNode()->use_begin(), | 
|  | 10186 | UE = Inputs[i].getNode()->use_end(); | 
|  | 10187 | UI != UE; ++UI) { | 
|  | 10188 | SDNode *User = *UI; | 
|  | 10189 | if (User != N && !Visited.count(User)) | 
|  | 10190 | return SDValue(); | 
| Hal Finkel | 46043ed | 2014-03-01 21:36:57 +0000 | [diff] [blame] | 10191 |  | 
| Hal Finkel | 4104a1a | 2014-12-14 05:53:19 +0000 | [diff] [blame] | 10192 | // If we're going to promote the non-output-value operand(s) or SELECT or | 
|  | 10193 | // SELECT_CC, record them for truncation. | 
| Hal Finkel | 46043ed | 2014-03-01 21:36:57 +0000 | [diff] [blame] | 10194 | if (User->getOpcode() == ISD::SELECT) { | 
|  | 10195 | if (User->getOperand(0) == Inputs[i]) | 
| Hal Finkel | 4104a1a | 2014-12-14 05:53:19 +0000 | [diff] [blame] | 10196 | SelectTruncOp[0].insert(std::make_pair(User, | 
|  | 10197 | User->getOperand(0).getValueType())); | 
| Hal Finkel | 46043ed | 2014-03-01 21:36:57 +0000 | [diff] [blame] | 10198 | } else if (User->getOpcode() == ISD::SELECT_CC) { | 
| Hal Finkel | 4104a1a | 2014-12-14 05:53:19 +0000 | [diff] [blame] | 10199 | if (User->getOperand(0) == Inputs[i]) | 
|  | 10200 | SelectTruncOp[0].insert(std::make_pair(User, | 
|  | 10201 | User->getOperand(0).getValueType())); | 
|  | 10202 | if (User->getOperand(1) == Inputs[i]) | 
|  | 10203 | SelectTruncOp[1].insert(std::make_pair(User, | 
|  | 10204 | User->getOperand(1).getValueType())); | 
| Hal Finkel | 46043ed | 2014-03-01 21:36:57 +0000 | [diff] [blame] | 10205 | } | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10206 | } | 
|  | 10207 | } | 
|  | 10208 |  | 
|  | 10209 | for (unsigned i = 0, ie = PromOps.size(); i != ie; ++i) { | 
|  | 10210 | for (SDNode::use_iterator UI = PromOps[i].getNode()->use_begin(), | 
|  | 10211 | UE = PromOps[i].getNode()->use_end(); | 
|  | 10212 | UI != UE; ++UI) { | 
|  | 10213 | SDNode *User = *UI; | 
|  | 10214 | if (User != N && !Visited.count(User)) | 
|  | 10215 | return SDValue(); | 
| Hal Finkel | 46043ed | 2014-03-01 21:36:57 +0000 | [diff] [blame] | 10216 |  | 
| Hal Finkel | 4104a1a | 2014-12-14 05:53:19 +0000 | [diff] [blame] | 10217 | // If we're going to promote the non-output-value operand(s) or SELECT or | 
|  | 10218 | // SELECT_CC, record them for truncation. | 
| Hal Finkel | 46043ed | 2014-03-01 21:36:57 +0000 | [diff] [blame] | 10219 | if (User->getOpcode() == ISD::SELECT) { | 
|  | 10220 | if (User->getOperand(0) == PromOps[i]) | 
| Hal Finkel | 4104a1a | 2014-12-14 05:53:19 +0000 | [diff] [blame] | 10221 | SelectTruncOp[0].insert(std::make_pair(User, | 
|  | 10222 | User->getOperand(0).getValueType())); | 
| Hal Finkel | 46043ed | 2014-03-01 21:36:57 +0000 | [diff] [blame] | 10223 | } else if (User->getOpcode() == ISD::SELECT_CC) { | 
| Hal Finkel | 4104a1a | 2014-12-14 05:53:19 +0000 | [diff] [blame] | 10224 | if (User->getOperand(0) == PromOps[i]) | 
|  | 10225 | SelectTruncOp[0].insert(std::make_pair(User, | 
|  | 10226 | User->getOperand(0).getValueType())); | 
|  | 10227 | if (User->getOperand(1) == PromOps[i]) | 
|  | 10228 | SelectTruncOp[1].insert(std::make_pair(User, | 
|  | 10229 | User->getOperand(1).getValueType())); | 
| Hal Finkel | 46043ed | 2014-03-01 21:36:57 +0000 | [diff] [blame] | 10230 | } | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10231 | } | 
|  | 10232 | } | 
|  | 10233 |  | 
| Hal Finkel | 46043ed | 2014-03-01 21:36:57 +0000 | [diff] [blame] | 10234 | unsigned PromBits = N->getOperand(0).getValueSizeInBits(); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10235 | bool ReallyNeedsExt = false; | 
|  | 10236 | if (N->getOpcode() != ISD::ANY_EXTEND) { | 
|  | 10237 | // If all of the inputs are not already sign/zero extended, then | 
|  | 10238 | // we'll still need to do that at the end. | 
|  | 10239 | for (unsigned i = 0, ie = Inputs.size(); i != ie; ++i) { | 
|  | 10240 | if (isa<ConstantSDNode>(Inputs[i])) | 
|  | 10241 | continue; | 
|  | 10242 |  | 
|  | 10243 | unsigned OpBits = | 
|  | 10244 | Inputs[i].getOperand(0).getValueSizeInBits(); | 
| Hal Finkel | 46043ed | 2014-03-01 21:36:57 +0000 | [diff] [blame] | 10245 | assert(PromBits < OpBits && "Truncation not to a smaller bit count?"); | 
|  | 10246 |  | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10247 | if ((N->getOpcode() == ISD::ZERO_EXTEND && | 
|  | 10248 | !DAG.MaskedValueIsZero(Inputs[i].getOperand(0), | 
| Hal Finkel | 46043ed | 2014-03-01 21:36:57 +0000 | [diff] [blame] | 10249 | APInt::getHighBitsSet(OpBits, | 
|  | 10250 | OpBits-PromBits))) || | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10251 | (N->getOpcode() == ISD::SIGN_EXTEND && | 
| Hal Finkel | 46043ed | 2014-03-01 21:36:57 +0000 | [diff] [blame] | 10252 | DAG.ComputeNumSignBits(Inputs[i].getOperand(0)) < | 
|  | 10253 | (OpBits-(PromBits-1)))) { | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10254 | ReallyNeedsExt = true; | 
|  | 10255 | break; | 
|  | 10256 | } | 
|  | 10257 | } | 
|  | 10258 | } | 
|  | 10259 |  | 
|  | 10260 | // Replace all inputs, either with the truncation operand, or a | 
|  | 10261 | // truncation or extension to the final output type. | 
|  | 10262 | for (unsigned i = 0, ie = Inputs.size(); i != ie; ++i) { | 
|  | 10263 | // Constant inputs need to be replaced with the to-be-promoted nodes that | 
|  | 10264 | // use them because they might have users outside of the cluster of | 
|  | 10265 | // promoted nodes. | 
|  | 10266 | if (isa<ConstantSDNode>(Inputs[i])) | 
|  | 10267 | continue; | 
|  | 10268 |  | 
|  | 10269 | SDValue InSrc = Inputs[i].getOperand(0); | 
|  | 10270 | if (Inputs[i].getValueType() == N->getValueType(0)) | 
|  | 10271 | DAG.ReplaceAllUsesOfValueWith(Inputs[i], InSrc); | 
|  | 10272 | else if (N->getOpcode() == ISD::SIGN_EXTEND) | 
|  | 10273 | DAG.ReplaceAllUsesOfValueWith(Inputs[i], | 
|  | 10274 | DAG.getSExtOrTrunc(InSrc, dl, N->getValueType(0))); | 
|  | 10275 | else if (N->getOpcode() == ISD::ZERO_EXTEND) | 
|  | 10276 | DAG.ReplaceAllUsesOfValueWith(Inputs[i], | 
|  | 10277 | DAG.getZExtOrTrunc(InSrc, dl, N->getValueType(0))); | 
|  | 10278 | else | 
|  | 10279 | DAG.ReplaceAllUsesOfValueWith(Inputs[i], | 
|  | 10280 | DAG.getAnyExtOrTrunc(InSrc, dl, N->getValueType(0))); | 
|  | 10281 | } | 
|  | 10282 |  | 
| Hal Finkel | 1fb10e8 | 2016-05-12 04:00:56 +0000 | [diff] [blame] | 10283 | std::list<HandleSDNode> PromOpHandles; | 
|  | 10284 | for (auto &PromOp : PromOps) | 
| NAKAMURA Takumi | ae7c97d | 2016-06-20 00:49:20 +0000 | [diff] [blame] | 10285 | PromOpHandles.emplace_back(PromOp); | 
| Hal Finkel | 1fb10e8 | 2016-05-12 04:00:56 +0000 | [diff] [blame] | 10286 |  | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10287 | // Replace all operations (these are all the same, but have a different | 
|  | 10288 | // (promoted) return type). DAG.getNode will validate that the types of | 
|  | 10289 | // a binary operator match, so go through the list in reverse so that | 
|  | 10290 | // we've likely promoted both operands first. | 
| Hal Finkel | 1fb10e8 | 2016-05-12 04:00:56 +0000 | [diff] [blame] | 10291 | while (!PromOpHandles.empty()) { | 
|  | 10292 | SDValue PromOp = PromOpHandles.back().getValue(); | 
|  | 10293 | PromOpHandles.pop_back(); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10294 |  | 
|  | 10295 | unsigned C; | 
|  | 10296 | switch (PromOp.getOpcode()) { | 
|  | 10297 | default:             C = 0; break; | 
|  | 10298 | case ISD::SELECT:    C = 1; break; | 
|  | 10299 | case ISD::SELECT_CC: C = 2; break; | 
|  | 10300 | } | 
|  | 10301 |  | 
|  | 10302 | if ((!isa<ConstantSDNode>(PromOp.getOperand(C)) && | 
|  | 10303 | PromOp.getOperand(C).getValueType() != N->getValueType(0)) || | 
|  | 10304 | (!isa<ConstantSDNode>(PromOp.getOperand(C+1)) && | 
|  | 10305 | PromOp.getOperand(C+1).getValueType() != N->getValueType(0))) { | 
|  | 10306 | // The to-be-promoted operands of this node have not yet been | 
|  | 10307 | // promoted (this should be rare because we're going through the | 
|  | 10308 | // list backward, but if one of the operands has several users in | 
|  | 10309 | // this cluster of to-be-promoted nodes, it is possible). | 
| Hal Finkel | 1fb10e8 | 2016-05-12 04:00:56 +0000 | [diff] [blame] | 10310 | PromOpHandles.emplace_front(PromOp); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10311 | continue; | 
|  | 10312 | } | 
|  | 10313 |  | 
| Hal Finkel | 4104a1a | 2014-12-14 05:53:19 +0000 | [diff] [blame] | 10314 | // For SELECT and SELECT_CC nodes, we do a similar check for any | 
|  | 10315 | // to-be-promoted comparison inputs. | 
|  | 10316 | if (PromOp.getOpcode() == ISD::SELECT || | 
|  | 10317 | PromOp.getOpcode() == ISD::SELECT_CC) { | 
|  | 10318 | if ((SelectTruncOp[0].count(PromOp.getNode()) && | 
|  | 10319 | PromOp.getOperand(0).getValueType() != N->getValueType(0)) || | 
|  | 10320 | (SelectTruncOp[1].count(PromOp.getNode()) && | 
|  | 10321 | PromOp.getOperand(1).getValueType() != N->getValueType(0))) { | 
| Hal Finkel | 1fb10e8 | 2016-05-12 04:00:56 +0000 | [diff] [blame] | 10322 | PromOpHandles.emplace_front(PromOp); | 
| Hal Finkel | 4104a1a | 2014-12-14 05:53:19 +0000 | [diff] [blame] | 10323 | continue; | 
|  | 10324 | } | 
|  | 10325 | } | 
|  | 10326 |  | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10327 | SmallVector<SDValue, 3> Ops(PromOp.getNode()->op_begin(), | 
|  | 10328 | PromOp.getNode()->op_end()); | 
|  | 10329 |  | 
|  | 10330 | // If this node has constant inputs, then they'll need to be promoted here. | 
|  | 10331 | for (unsigned i = 0; i < 2; ++i) { | 
|  | 10332 | if (!isa<ConstantSDNode>(Ops[C+i])) | 
|  | 10333 | continue; | 
|  | 10334 | if (Ops[C+i].getValueType() == N->getValueType(0)) | 
|  | 10335 | continue; | 
|  | 10336 |  | 
|  | 10337 | if (N->getOpcode() == ISD::SIGN_EXTEND) | 
|  | 10338 | Ops[C+i] = DAG.getSExtOrTrunc(Ops[C+i], dl, N->getValueType(0)); | 
|  | 10339 | else if (N->getOpcode() == ISD::ZERO_EXTEND) | 
|  | 10340 | Ops[C+i] = DAG.getZExtOrTrunc(Ops[C+i], dl, N->getValueType(0)); | 
|  | 10341 | else | 
|  | 10342 | Ops[C+i] = DAG.getAnyExtOrTrunc(Ops[C+i], dl, N->getValueType(0)); | 
|  | 10343 | } | 
|  | 10344 |  | 
| Hal Finkel | 4104a1a | 2014-12-14 05:53:19 +0000 | [diff] [blame] | 10345 | // If we've promoted the comparison inputs of a SELECT or SELECT_CC, | 
|  | 10346 | // truncate them again to the original value type. | 
|  | 10347 | if (PromOp.getOpcode() == ISD::SELECT || | 
|  | 10348 | PromOp.getOpcode() == ISD::SELECT_CC) { | 
|  | 10349 | auto SI0 = SelectTruncOp[0].find(PromOp.getNode()); | 
|  | 10350 | if (SI0 != SelectTruncOp[0].end()) | 
|  | 10351 | Ops[0] = DAG.getNode(ISD::TRUNCATE, dl, SI0->second, Ops[0]); | 
|  | 10352 | auto SI1 = SelectTruncOp[1].find(PromOp.getNode()); | 
|  | 10353 | if (SI1 != SelectTruncOp[1].end()) | 
|  | 10354 | Ops[1] = DAG.getNode(ISD::TRUNCATE, dl, SI1->second, Ops[1]); | 
|  | 10355 | } | 
|  | 10356 |  | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10357 | DAG.ReplaceAllUsesOfValueWith(PromOp, | 
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 10358 | DAG.getNode(PromOp.getOpcode(), dl, N->getValueType(0), Ops)); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10359 | } | 
|  | 10360 |  | 
|  | 10361 | // Now we're left with the initial extension itself. | 
|  | 10362 | if (!ReallyNeedsExt) | 
|  | 10363 | return N->getOperand(0); | 
|  | 10364 |  | 
| Hal Finkel | 46043ed | 2014-03-01 21:36:57 +0000 | [diff] [blame] | 10365 | // To zero extend, just mask off everything except for the first bit (in the | 
|  | 10366 | // i1 case). | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10367 | if (N->getOpcode() == ISD::ZERO_EXTEND) | 
|  | 10368 | return DAG.getNode(ISD::AND, dl, N->getValueType(0), N->getOperand(0), | 
| Hal Finkel | 46043ed | 2014-03-01 21:36:57 +0000 | [diff] [blame] | 10369 | DAG.getConstant(APInt::getLowBitsSet( | 
|  | 10370 | N->getValueSizeInBits(0), PromBits), | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10371 | dl, N->getValueType(0))); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10372 |  | 
|  | 10373 | assert(N->getOpcode() == ISD::SIGN_EXTEND && | 
|  | 10374 | "Invalid extension type"); | 
| Mehdi Amini | 9639d65 | 2015-07-09 02:09:20 +0000 | [diff] [blame] | 10375 | EVT ShiftAmountTy = getShiftAmountTy(N->getValueType(0), DAG.getDataLayout()); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10376 | SDValue ShiftCst = | 
| NAKAMURA Takumi | 70ad98a | 2015-09-22 11:13:55 +0000 | [diff] [blame] | 10377 | DAG.getConstant(N->getValueSizeInBits(0) - PromBits, dl, ShiftAmountTy); | 
|  | 10378 | return DAG.getNode( | 
|  | 10379 | ISD::SRA, dl, N->getValueType(0), | 
|  | 10380 | DAG.getNode(ISD::SHL, dl, N->getValueType(0), N->getOperand(0), ShiftCst), | 
|  | 10381 | ShiftCst); | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10382 | } | 
|  | 10383 |  | 
| Nemanja Ivanovic | 44513e5 | 2016-07-05 09:22:29 +0000 | [diff] [blame] | 10384 | SDValue PPCTargetLowering::DAGCombineBuildVector(SDNode *N, | 
|  | 10385 | DAGCombinerInfo &DCI) const { | 
|  | 10386 | assert(N->getOpcode() == ISD::BUILD_VECTOR && | 
|  | 10387 | "Should be called with a BUILD_VECTOR node"); | 
|  | 10388 |  | 
|  | 10389 | SelectionDAG &DAG = DCI.DAG; | 
|  | 10390 | SDLoc dl(N); | 
|  | 10391 | if (N->getValueType(0) != MVT::v2f64 || !Subtarget.hasVSX()) | 
|  | 10392 | return SDValue(); | 
|  | 10393 |  | 
|  | 10394 | // Looking for: | 
|  | 10395 | // (build_vector ([su]int_to_fp (extractelt 0)), [su]int_to_fp (extractelt 1)) | 
|  | 10396 | if (N->getOperand(0).getOpcode() != ISD::SINT_TO_FP && | 
|  | 10397 | N->getOperand(0).getOpcode() != ISD::UINT_TO_FP) | 
|  | 10398 | return SDValue(); | 
|  | 10399 | if (N->getOperand(1).getOpcode() != ISD::SINT_TO_FP && | 
|  | 10400 | N->getOperand(1).getOpcode() != ISD::UINT_TO_FP) | 
|  | 10401 | return SDValue(); | 
|  | 10402 | if (N->getOperand(0).getOpcode() != N->getOperand(1).getOpcode()) | 
|  | 10403 | return SDValue(); | 
|  | 10404 |  | 
|  | 10405 | SDValue Ext1 = N->getOperand(0).getOperand(0); | 
|  | 10406 | SDValue Ext2 = N->getOperand(1).getOperand(0); | 
|  | 10407 | if(Ext1.getOpcode() != ISD::EXTRACT_VECTOR_ELT || | 
|  | 10408 | Ext2.getOpcode() != ISD::EXTRACT_VECTOR_ELT) | 
|  | 10409 | return SDValue(); | 
|  | 10410 |  | 
|  | 10411 | ConstantSDNode *Ext1Op = dyn_cast<ConstantSDNode>(Ext1.getOperand(1)); | 
|  | 10412 | ConstantSDNode *Ext2Op = dyn_cast<ConstantSDNode>(Ext2.getOperand(1)); | 
|  | 10413 | if (!Ext1Op || !Ext2Op) | 
|  | 10414 | return SDValue(); | 
|  | 10415 | if (Ext1.getValueType() != MVT::i32 || | 
|  | 10416 | Ext2.getValueType() != MVT::i32) | 
|  | 10417 | if (Ext1.getOperand(0) != Ext2.getOperand(0)) | 
|  | 10418 | return SDValue(); | 
|  | 10419 |  | 
|  | 10420 | int FirstElem = Ext1Op->getZExtValue(); | 
|  | 10421 | int SecondElem = Ext2Op->getZExtValue(); | 
|  | 10422 | int SubvecIdx; | 
|  | 10423 | if (FirstElem == 0 && SecondElem == 1) | 
|  | 10424 | SubvecIdx = Subtarget.isLittleEndian() ? 1 : 0; | 
|  | 10425 | else if (FirstElem == 2 && SecondElem == 3) | 
|  | 10426 | SubvecIdx = Subtarget.isLittleEndian() ? 0 : 1; | 
|  | 10427 | else | 
|  | 10428 | return SDValue(); | 
|  | 10429 |  | 
|  | 10430 | SDValue SrcVec = Ext1.getOperand(0); | 
|  | 10431 | auto NodeType = (N->getOperand(1).getOpcode() == ISD::SINT_TO_FP) ? | 
|  | 10432 | PPCISD::SINT_VEC_TO_FP : PPCISD::UINT_VEC_TO_FP; | 
|  | 10433 | return DAG.getNode(NodeType, dl, MVT::v2f64, | 
|  | 10434 | SrcVec, DAG.getIntPtrConstant(SubvecIdx, dl)); | 
|  | 10435 | } | 
|  | 10436 |  | 
| Hal Finkel | 5efb918 | 2015-01-06 06:01:57 +0000 | [diff] [blame] | 10437 | SDValue PPCTargetLowering::combineFPToIntToFP(SDNode *N, | 
|  | 10438 | DAGCombinerInfo &DCI) const { | 
|  | 10439 | assert((N->getOpcode() == ISD::SINT_TO_FP || | 
|  | 10440 | N->getOpcode() == ISD::UINT_TO_FP) && | 
|  | 10441 | "Need an int -> FP conversion node here"); | 
|  | 10442 |  | 
|  | 10443 | if (!Subtarget.has64BitSupport()) | 
|  | 10444 | return SDValue(); | 
|  | 10445 |  | 
|  | 10446 | SelectionDAG &DAG = DCI.DAG; | 
|  | 10447 | SDLoc dl(N); | 
|  | 10448 | SDValue Op(N, 0); | 
|  | 10449 |  | 
|  | 10450 | // Don't handle ppc_fp128 here or i1 conversions. | 
|  | 10451 | if (Op.getValueType() != MVT::f32 && Op.getValueType() != MVT::f64) | 
|  | 10452 | return SDValue(); | 
|  | 10453 | if (Op.getOperand(0).getValueType() == MVT::i1) | 
|  | 10454 | return SDValue(); | 
|  | 10455 |  | 
|  | 10456 | // For i32 intermediate values, unfortunately, the conversion functions | 
|  | 10457 | // leave the upper 32 bits of the value are undefined. Within the set of | 
|  | 10458 | // scalar instructions, we have no method for zero- or sign-extending the | 
|  | 10459 | // value. Thus, we cannot handle i32 intermediate values here. | 
|  | 10460 | if (Op.getOperand(0).getValueType() == MVT::i32) | 
|  | 10461 | return SDValue(); | 
|  | 10462 |  | 
|  | 10463 | assert((Op.getOpcode() == ISD::SINT_TO_FP || Subtarget.hasFPCVT()) && | 
|  | 10464 | "UINT_TO_FP is supported only with FPCVT"); | 
|  | 10465 |  | 
|  | 10466 | // If we have FCFIDS, then use it when converting to single-precision. | 
|  | 10467 | // Otherwise, convert to double-precision and then round. | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 10468 | unsigned FCFOp = (Subtarget.hasFPCVT() && Op.getValueType() == MVT::f32) | 
|  | 10469 | ? (Op.getOpcode() == ISD::UINT_TO_FP ? PPCISD::FCFIDUS | 
|  | 10470 | : PPCISD::FCFIDS) | 
|  | 10471 | : (Op.getOpcode() == ISD::UINT_TO_FP ? PPCISD::FCFIDU | 
|  | 10472 | : PPCISD::FCFID); | 
|  | 10473 | MVT FCFTy = (Subtarget.hasFPCVT() && Op.getValueType() == MVT::f32) | 
|  | 10474 | ? MVT::f32 | 
|  | 10475 | : MVT::f64; | 
| Hal Finkel | 5efb918 | 2015-01-06 06:01:57 +0000 | [diff] [blame] | 10476 |  | 
|  | 10477 | // If we're converting from a float, to an int, and back to a float again, | 
|  | 10478 | // then we don't need the store/load pair at all. | 
|  | 10479 | if ((Op.getOperand(0).getOpcode() == ISD::FP_TO_UINT && | 
|  | 10480 | Subtarget.hasFPCVT()) || | 
|  | 10481 | (Op.getOperand(0).getOpcode() == ISD::FP_TO_SINT)) { | 
|  | 10482 | SDValue Src = Op.getOperand(0).getOperand(0); | 
|  | 10483 | if (Src.getValueType() == MVT::f32) { | 
|  | 10484 | Src = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, Src); | 
|  | 10485 | DCI.AddToWorklist(Src.getNode()); | 
| Hal Finkel | be78c25 | 2015-08-20 01:18:20 +0000 | [diff] [blame] | 10486 | } else if (Src.getValueType() != MVT::f64) { | 
|  | 10487 | // Make sure that we don't pick up a ppc_fp128 source value. | 
|  | 10488 | return SDValue(); | 
| Hal Finkel | 5efb918 | 2015-01-06 06:01:57 +0000 | [diff] [blame] | 10489 | } | 
|  | 10490 |  | 
|  | 10491 | unsigned FCTOp = | 
|  | 10492 | Op.getOperand(0).getOpcode() == ISD::FP_TO_SINT ? PPCISD::FCTIDZ : | 
|  | 10493 | PPCISD::FCTIDUZ; | 
|  | 10494 |  | 
|  | 10495 | SDValue Tmp = DAG.getNode(FCTOp, dl, MVT::f64, Src); | 
|  | 10496 | SDValue FP = DAG.getNode(FCFOp, dl, FCFTy, Tmp); | 
|  | 10497 |  | 
|  | 10498 | if (Op.getValueType() == MVT::f32 && !Subtarget.hasFPCVT()) { | 
|  | 10499 | FP = DAG.getNode(ISD::FP_ROUND, dl, | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10500 | MVT::f32, FP, DAG.getIntPtrConstant(0, dl)); | 
| Hal Finkel | 5efb918 | 2015-01-06 06:01:57 +0000 | [diff] [blame] | 10501 | DCI.AddToWorklist(FP.getNode()); | 
|  | 10502 | } | 
|  | 10503 |  | 
|  | 10504 | return FP; | 
|  | 10505 | } | 
|  | 10506 |  | 
|  | 10507 | return SDValue(); | 
|  | 10508 | } | 
|  | 10509 |  | 
| Bill Schmidt | fae5d71 | 2014-12-09 16:35:51 +0000 | [diff] [blame] | 10510 | // expandVSXLoadForLE - Convert VSX loads (which may be intrinsics for | 
|  | 10511 | // builtins) into loads with swaps. | 
|  | 10512 | SDValue PPCTargetLowering::expandVSXLoadForLE(SDNode *N, | 
|  | 10513 | DAGCombinerInfo &DCI) const { | 
|  | 10514 | SelectionDAG &DAG = DCI.DAG; | 
|  | 10515 | SDLoc dl(N); | 
|  | 10516 | SDValue Chain; | 
|  | 10517 | SDValue Base; | 
|  | 10518 | MachineMemOperand *MMO; | 
|  | 10519 |  | 
|  | 10520 | switch (N->getOpcode()) { | 
|  | 10521 | default: | 
|  | 10522 | llvm_unreachable("Unexpected opcode for little endian VSX load"); | 
|  | 10523 | case ISD::LOAD: { | 
|  | 10524 | LoadSDNode *LD = cast<LoadSDNode>(N); | 
|  | 10525 | Chain = LD->getChain(); | 
|  | 10526 | Base = LD->getBasePtr(); | 
|  | 10527 | MMO = LD->getMemOperand(); | 
|  | 10528 | // If the MMO suggests this isn't a load of a full vector, leave | 
|  | 10529 | // things alone.  For a built-in, we have to make the change for | 
|  | 10530 | // correctness, so if there is a size problem that will be a bug. | 
|  | 10531 | if (MMO->getSize() < 16) | 
|  | 10532 | return SDValue(); | 
|  | 10533 | break; | 
|  | 10534 | } | 
|  | 10535 | case ISD::INTRINSIC_W_CHAIN: { | 
|  | 10536 | MemIntrinsicSDNode *Intrin = cast<MemIntrinsicSDNode>(N); | 
|  | 10537 | Chain = Intrin->getChain(); | 
| Nemanja Ivanovic | 7df26c9 | 2015-06-30 20:01:16 +0000 | [diff] [blame] | 10538 | // Similarly to the store case below, Intrin->getBasePtr() doesn't get | 
| Nemanja Ivanovic | 9c8d4cf | 2015-06-30 19:45:45 +0000 | [diff] [blame] | 10539 | // us what we want. Get operand 2 instead. | 
| Nemanja Ivanovic | 9c8d4cf | 2015-06-30 19:45:45 +0000 | [diff] [blame] | 10540 | Base = Intrin->getOperand(2); | 
| Bill Schmidt | fae5d71 | 2014-12-09 16:35:51 +0000 | [diff] [blame] | 10541 | MMO = Intrin->getMemOperand(); | 
|  | 10542 | break; | 
|  | 10543 | } | 
|  | 10544 | } | 
|  | 10545 |  | 
|  | 10546 | MVT VecTy = N->getValueType(0).getSimpleVT(); | 
|  | 10547 | SDValue LoadOps[] = { Chain, Base }; | 
|  | 10548 | SDValue Load = DAG.getMemIntrinsicNode(PPCISD::LXVD2X, dl, | 
| Nirav Dave | 1f51c33 | 2016-04-15 15:01:38 +0000 | [diff] [blame] | 10549 | DAG.getVTList(MVT::v2f64, MVT::Other), | 
|  | 10550 | LoadOps, MVT::v2f64, MMO); | 
|  | 10551 |  | 
| Bill Schmidt | fae5d71 | 2014-12-09 16:35:51 +0000 | [diff] [blame] | 10552 | DCI.AddToWorklist(Load.getNode()); | 
|  | 10553 | Chain = Load.getValue(1); | 
| Nirav Dave | 1f51c33 | 2016-04-15 15:01:38 +0000 | [diff] [blame] | 10554 | SDValue Swap = DAG.getNode( | 
|  | 10555 | PPCISD::XXSWAPD, dl, DAG.getVTList(MVT::v2f64, MVT::Other), Chain, Load); | 
| Bill Schmidt | fae5d71 | 2014-12-09 16:35:51 +0000 | [diff] [blame] | 10556 | DCI.AddToWorklist(Swap.getNode()); | 
| Nirav Dave | 1f51c33 | 2016-04-15 15:01:38 +0000 | [diff] [blame] | 10557 |  | 
|  | 10558 | // Add a bitcast if the resulting load type doesn't match v2f64. | 
|  | 10559 | if (VecTy != MVT::v2f64) { | 
|  | 10560 | SDValue N = DAG.getNode(ISD::BITCAST, dl, VecTy, Swap); | 
|  | 10561 | DCI.AddToWorklist(N.getNode()); | 
|  | 10562 | // Package {bitcast value, swap's chain} to match Load's shape. | 
|  | 10563 | return DAG.getNode(ISD::MERGE_VALUES, dl, DAG.getVTList(VecTy, MVT::Other), | 
|  | 10564 | N, Swap.getValue(1)); | 
|  | 10565 | } | 
|  | 10566 |  | 
| Bill Schmidt | fae5d71 | 2014-12-09 16:35:51 +0000 | [diff] [blame] | 10567 | return Swap; | 
|  | 10568 | } | 
|  | 10569 |  | 
|  | 10570 | // expandVSXStoreForLE - Convert VSX stores (which may be intrinsics for | 
|  | 10571 | // builtins) into stores with swaps. | 
|  | 10572 | SDValue PPCTargetLowering::expandVSXStoreForLE(SDNode *N, | 
|  | 10573 | DAGCombinerInfo &DCI) const { | 
|  | 10574 | SelectionDAG &DAG = DCI.DAG; | 
|  | 10575 | SDLoc dl(N); | 
|  | 10576 | SDValue Chain; | 
|  | 10577 | SDValue Base; | 
|  | 10578 | unsigned SrcOpnd; | 
|  | 10579 | MachineMemOperand *MMO; | 
|  | 10580 |  | 
|  | 10581 | switch (N->getOpcode()) { | 
|  | 10582 | default: | 
|  | 10583 | llvm_unreachable("Unexpected opcode for little endian VSX store"); | 
|  | 10584 | case ISD::STORE: { | 
|  | 10585 | StoreSDNode *ST = cast<StoreSDNode>(N); | 
|  | 10586 | Chain = ST->getChain(); | 
|  | 10587 | Base = ST->getBasePtr(); | 
|  | 10588 | MMO = ST->getMemOperand(); | 
|  | 10589 | SrcOpnd = 1; | 
|  | 10590 | // If the MMO suggests this isn't a store of a full vector, leave | 
|  | 10591 | // things alone.  For a built-in, we have to make the change for | 
|  | 10592 | // correctness, so if there is a size problem that will be a bug. | 
|  | 10593 | if (MMO->getSize() < 16) | 
|  | 10594 | return SDValue(); | 
|  | 10595 | break; | 
|  | 10596 | } | 
|  | 10597 | case ISD::INTRINSIC_VOID: { | 
|  | 10598 | MemIntrinsicSDNode *Intrin = cast<MemIntrinsicSDNode>(N); | 
|  | 10599 | Chain = Intrin->getChain(); | 
|  | 10600 | // Intrin->getBasePtr() oddly does not get what we want. | 
|  | 10601 | Base = Intrin->getOperand(3); | 
|  | 10602 | MMO = Intrin->getMemOperand(); | 
|  | 10603 | SrcOpnd = 2; | 
|  | 10604 | break; | 
|  | 10605 | } | 
|  | 10606 | } | 
|  | 10607 |  | 
|  | 10608 | SDValue Src = N->getOperand(SrcOpnd); | 
|  | 10609 | MVT VecTy = Src.getValueType().getSimpleVT(); | 
| Nirav Dave | 1f51c33 | 2016-04-15 15:01:38 +0000 | [diff] [blame] | 10610 |  | 
|  | 10611 | // All stores are done as v2f64 and possible bit cast. | 
|  | 10612 | if (VecTy != MVT::v2f64) { | 
|  | 10613 | Src = DAG.getNode(ISD::BITCAST, dl, MVT::v2f64, Src); | 
|  | 10614 | DCI.AddToWorklist(Src.getNode()); | 
|  | 10615 | } | 
|  | 10616 |  | 
| Bill Schmidt | fae5d71 | 2014-12-09 16:35:51 +0000 | [diff] [blame] | 10617 | SDValue Swap = DAG.getNode(PPCISD::XXSWAPD, dl, | 
| Nirav Dave | 1f51c33 | 2016-04-15 15:01:38 +0000 | [diff] [blame] | 10618 | DAG.getVTList(MVT::v2f64, MVT::Other), Chain, Src); | 
| Bill Schmidt | fae5d71 | 2014-12-09 16:35:51 +0000 | [diff] [blame] | 10619 | DCI.AddToWorklist(Swap.getNode()); | 
|  | 10620 | Chain = Swap.getValue(1); | 
|  | 10621 | SDValue StoreOps[] = { Chain, Swap, Base }; | 
|  | 10622 | SDValue Store = DAG.getMemIntrinsicNode(PPCISD::STXVD2X, dl, | 
|  | 10623 | DAG.getVTList(MVT::Other), | 
|  | 10624 | StoreOps, VecTy, MMO); | 
|  | 10625 | DCI.AddToWorklist(Store.getNode()); | 
|  | 10626 | return Store; | 
|  | 10627 | } | 
|  | 10628 |  | 
| Duncan Sands | dc2dac1 | 2008-11-24 14:53:14 +0000 | [diff] [blame] | 10629 | SDValue PPCTargetLowering::PerformDAGCombine(SDNode *N, | 
|  | 10630 | DAGCombinerInfo &DCI) const { | 
| Chris Lattner | f418435 | 2006-03-01 04:57:39 +0000 | [diff] [blame] | 10631 | SelectionDAG &DAG = DCI.DAG; | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 10632 | SDLoc dl(N); | 
| Chris Lattner | f418435 | 2006-03-01 04:57:39 +0000 | [diff] [blame] | 10633 | switch (N->getOpcode()) { | 
|  | 10634 | default: break; | 
| Chris Lattner | 3c48ea5 | 2006-09-19 05:22:59 +0000 | [diff] [blame] | 10635 | case PPCISD::SHL: | 
| Artyom Skrobov | 314ee04 | 2015-11-25 19:41:11 +0000 | [diff] [blame] | 10636 | if (isNullConstant(N->getOperand(0))) // 0 << V -> 0. | 
| Chris Lattner | 3c48ea5 | 2006-09-19 05:22:59 +0000 | [diff] [blame] | 10637 | return N->getOperand(0); | 
| Chris Lattner | 3c48ea5 | 2006-09-19 05:22:59 +0000 | [diff] [blame] | 10638 | break; | 
|  | 10639 | case PPCISD::SRL: | 
| Artyom Skrobov | 314ee04 | 2015-11-25 19:41:11 +0000 | [diff] [blame] | 10640 | if (isNullConstant(N->getOperand(0))) // 0 >>u V -> 0. | 
| Chris Lattner | 3c48ea5 | 2006-09-19 05:22:59 +0000 | [diff] [blame] | 10641 | return N->getOperand(0); | 
| Chris Lattner | 3c48ea5 | 2006-09-19 05:22:59 +0000 | [diff] [blame] | 10642 | break; | 
|  | 10643 | case PPCISD::SRA: | 
|  | 10644 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(0))) { | 
| Dan Gohman | f1d8304 | 2010-06-18 14:22:04 +0000 | [diff] [blame] | 10645 | if (C->isNullValue() ||   //  0 >>s V -> 0. | 
| Chris Lattner | 3c48ea5 | 2006-09-19 05:22:59 +0000 | [diff] [blame] | 10646 | C->isAllOnesValue())    // -1 >>s V -> -1. | 
|  | 10647 | return N->getOperand(0); | 
|  | 10648 | } | 
|  | 10649 | break; | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10650 | case ISD::SIGN_EXTEND: | 
|  | 10651 | case ISD::ZERO_EXTEND: | 
| NAKAMURA Takumi | 10c80e7 | 2015-09-22 11:19:03 +0000 | [diff] [blame] | 10652 | case ISD::ANY_EXTEND: | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 10653 | return DAGCombineExtBoolTrunc(N, DCI); | 
|  | 10654 | case ISD::TRUNCATE: | 
|  | 10655 | case ISD::SETCC: | 
|  | 10656 | case ISD::SELECT_CC: | 
|  | 10657 | return DAGCombineTruncBoolExt(N, DCI); | 
| Chris Lattner | f418435 | 2006-03-01 04:57:39 +0000 | [diff] [blame] | 10658 | case ISD::SINT_TO_FP: | 
| Hal Finkel | 5efb918 | 2015-01-06 06:01:57 +0000 | [diff] [blame] | 10659 | case ISD::UINT_TO_FP: | 
|  | 10660 | return combineFPToIntToFP(N, DCI); | 
| Bill Schmidt | fae5d71 | 2014-12-09 16:35:51 +0000 | [diff] [blame] | 10661 | case ISD::STORE: { | 
| Chris Lattner | 27f5345 | 2006-03-01 05:50:56 +0000 | [diff] [blame] | 10662 | // Turn STORE (FP_TO_SINT F) -> STFIWX(FCTIWZ(F)). | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 10663 | if (Subtarget.hasSTFIWX() && !cast<StoreSDNode>(N)->isTruncatingStore() && | 
| Chris Lattner | 27f5345 | 2006-03-01 05:50:56 +0000 | [diff] [blame] | 10664 | N->getOperand(1).getOpcode() == ISD::FP_TO_SINT && | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10665 | N->getOperand(1).getValueType() == MVT::i32 && | 
|  | 10666 | N->getOperand(1).getOperand(0).getValueType() != MVT::ppcf128) { | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 10667 | SDValue Val = N->getOperand(1).getOperand(0); | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10668 | if (Val.getValueType() == MVT::f32) { | 
|  | 10669 | Val = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f64, Val); | 
| Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 10670 | DCI.AddToWorklist(Val.getNode()); | 
| Chris Lattner | 27f5345 | 2006-03-01 05:50:56 +0000 | [diff] [blame] | 10671 | } | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10672 | Val = DAG.getNode(PPCISD::FCTIWZ, dl, MVT::f64, Val); | 
| Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 10673 | DCI.AddToWorklist(Val.getNode()); | 
| Chris Lattner | 27f5345 | 2006-03-01 05:50:56 +0000 | [diff] [blame] | 10674 |  | 
| Hal Finkel | 60c7510 | 2013-04-01 15:37:53 +0000 | [diff] [blame] | 10675 | SDValue Ops[] = { | 
|  | 10676 | N->getOperand(0), Val, N->getOperand(2), | 
|  | 10677 | DAG.getValueType(N->getOperand(1).getValueType()) | 
|  | 10678 | }; | 
|  | 10679 |  | 
|  | 10680 | Val = DAG.getMemIntrinsicNode(PPCISD::STFIWX, dl, | 
| Craig Topper | 206fcd4 | 2014-04-26 19:29:41 +0000 | [diff] [blame] | 10681 | DAG.getVTList(MVT::Other), Ops, | 
| Hal Finkel | 60c7510 | 2013-04-01 15:37:53 +0000 | [diff] [blame] | 10682 | cast<StoreSDNode>(N)->getMemoryVT(), | 
|  | 10683 | cast<StoreSDNode>(N)->getMemOperand()); | 
| Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 10684 | DCI.AddToWorklist(Val.getNode()); | 
| Chris Lattner | 27f5345 | 2006-03-01 05:50:56 +0000 | [diff] [blame] | 10685 | return Val; | 
|  | 10686 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 10687 |  | 
| Chris Lattner | a7976d3 | 2006-07-10 20:56:58 +0000 | [diff] [blame] | 10688 | // Turn STORE (BSWAP) -> sthbrx/stwbrx. | 
| Dan Gohman | 28328db | 2009-09-25 00:57:30 +0000 | [diff] [blame] | 10689 | if (cast<StoreSDNode>(N)->isUnindexed() && | 
|  | 10690 | N->getOperand(1).getOpcode() == ISD::BSWAP && | 
| Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 10691 | N->getOperand(1).getNode()->hasOneUse() && | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10692 | (N->getOperand(1).getValueType() == MVT::i32 || | 
| Hal Finkel | 31d2956 | 2013-03-28 19:25:55 +0000 | [diff] [blame] | 10693 | N->getOperand(1).getValueType() == MVT::i16 || | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 10694 | (Subtarget.hasLDBRX() && Subtarget.isPPC64() && | 
| Hal Finkel | 31d2956 | 2013-03-28 19:25:55 +0000 | [diff] [blame] | 10695 | N->getOperand(1).getValueType() == MVT::i64))) { | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 10696 | SDValue BSwapOp = N->getOperand(1).getOperand(0); | 
| Chris Lattner | a7976d3 | 2006-07-10 20:56:58 +0000 | [diff] [blame] | 10697 | // Do an any-extend to 32-bits if this is a half-word input. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10698 | if (BSwapOp.getValueType() == MVT::i16) | 
|  | 10699 | BSwapOp = DAG.getNode(ISD::ANY_EXTEND, dl, MVT::i32, BSwapOp); | 
| Chris Lattner | a7976d3 | 2006-07-10 20:56:58 +0000 | [diff] [blame] | 10700 |  | 
| Dan Gohman | 48b185d | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 10701 | SDValue Ops[] = { | 
|  | 10702 | N->getOperand(0), BSwapOp, N->getOperand(2), | 
|  | 10703 | DAG.getValueType(N->getOperand(1).getValueType()) | 
|  | 10704 | }; | 
|  | 10705 | return | 
|  | 10706 | DAG.getMemIntrinsicNode(PPCISD::STBRX, dl, DAG.getVTList(MVT::Other), | 
| Craig Topper | 206fcd4 | 2014-04-26 19:29:41 +0000 | [diff] [blame] | 10707 | Ops, cast<StoreSDNode>(N)->getMemoryVT(), | 
| Dan Gohman | 48b185d | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 10708 | cast<StoreSDNode>(N)->getMemOperand()); | 
| Chris Lattner | a7976d3 | 2006-07-10 20:56:58 +0000 | [diff] [blame] | 10709 | } | 
| Bill Schmidt | fae5d71 | 2014-12-09 16:35:51 +0000 | [diff] [blame] | 10710 |  | 
|  | 10711 | // For little endian, VSX stores require generating xxswapd/lxvd2x. | 
|  | 10712 | EVT VT = N->getOperand(1).getValueType(); | 
|  | 10713 | if (VT.isSimple()) { | 
|  | 10714 | MVT StoreVT = VT.getSimpleVT(); | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 10715 | if (Subtarget.hasVSX() && Subtarget.isLittleEndian() && | 
| Bill Schmidt | fae5d71 | 2014-12-09 16:35:51 +0000 | [diff] [blame] | 10716 | (StoreVT == MVT::v2f64 || StoreVT == MVT::v2i64 || | 
|  | 10717 | StoreVT == MVT::v4f32 || StoreVT == MVT::v4i32)) | 
|  | 10718 | return expandVSXStoreForLE(N, DCI); | 
|  | 10719 | } | 
| Chris Lattner | a7976d3 | 2006-07-10 20:56:58 +0000 | [diff] [blame] | 10720 | break; | 
| Bill Schmidt | fae5d71 | 2014-12-09 16:35:51 +0000 | [diff] [blame] | 10721 | } | 
| Hal Finkel | cf2e908 | 2013-05-24 23:00:14 +0000 | [diff] [blame] | 10722 | case ISD::LOAD: { | 
|  | 10723 | LoadSDNode *LD = cast<LoadSDNode>(N); | 
|  | 10724 | EVT VT = LD->getValueType(0); | 
| Bill Schmidt | fae5d71 | 2014-12-09 16:35:51 +0000 | [diff] [blame] | 10725 |  | 
|  | 10726 | // For little endian, VSX loads require generating lxvd2x/xxswapd. | 
|  | 10727 | if (VT.isSimple()) { | 
|  | 10728 | MVT LoadVT = VT.getSimpleVT(); | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 10729 | if (Subtarget.hasVSX() && Subtarget.isLittleEndian() && | 
| Bill Schmidt | fae5d71 | 2014-12-09 16:35:51 +0000 | [diff] [blame] | 10730 | (LoadVT == MVT::v2f64 || LoadVT == MVT::v2i64 || | 
|  | 10731 | LoadVT == MVT::v4f32 || LoadVT == MVT::v4i32)) | 
|  | 10732 | return expandVSXLoadForLE(N, DCI); | 
|  | 10733 | } | 
|  | 10734 |  | 
| Hal Finkel | 851b33a | 2016-03-31 02:56:05 +0000 | [diff] [blame] | 10735 | // We sometimes end up with a 64-bit integer load, from which we extract | 
|  | 10736 | // two single-precision floating-point numbers. This happens with | 
|  | 10737 | // std::complex<float>, and other similar structures, because of the way we | 
|  | 10738 | // canonicalize structure copies. However, if we lack direct moves, | 
|  | 10739 | // then the final bitcasts from the extracted integer values to the | 
|  | 10740 | // floating-point numbers turn into store/load pairs. Even with direct moves, | 
|  | 10741 | // just loading the two floating-point numbers is likely better. | 
|  | 10742 | auto ReplaceTwoFloatLoad = [&]() { | 
|  | 10743 | if (VT != MVT::i64) | 
|  | 10744 | return false; | 
|  | 10745 |  | 
|  | 10746 | if (LD->getExtensionType() != ISD::NON_EXTLOAD || | 
|  | 10747 | LD->isVolatile()) | 
|  | 10748 | return false; | 
|  | 10749 |  | 
|  | 10750 | //  We're looking for a sequence like this: | 
|  | 10751 | //  t13: i64,ch = load<LD8[%ref.tmp]> t0, t6, undef:i64 | 
|  | 10752 | //      t16: i64 = srl t13, Constant:i32<32> | 
|  | 10753 | //    t17: i32 = truncate t16 | 
|  | 10754 | //  t18: f32 = bitcast t17 | 
|  | 10755 | //    t19: i32 = truncate t13 | 
|  | 10756 | //  t20: f32 = bitcast t19 | 
|  | 10757 |  | 
|  | 10758 | if (!LD->hasNUsesOfValue(2, 0)) | 
|  | 10759 | return false; | 
|  | 10760 |  | 
|  | 10761 | auto UI = LD->use_begin(); | 
|  | 10762 | while (UI.getUse().getResNo() != 0) ++UI; | 
|  | 10763 | SDNode *Trunc = *UI++; | 
|  | 10764 | while (UI.getUse().getResNo() != 0) ++UI; | 
|  | 10765 | SDNode *RightShift = *UI; | 
|  | 10766 | if (Trunc->getOpcode() != ISD::TRUNCATE) | 
|  | 10767 | std::swap(Trunc, RightShift); | 
|  | 10768 |  | 
|  | 10769 | if (Trunc->getOpcode() != ISD::TRUNCATE || | 
|  | 10770 | Trunc->getValueType(0) != MVT::i32 || | 
|  | 10771 | !Trunc->hasOneUse()) | 
|  | 10772 | return false; | 
|  | 10773 | if (RightShift->getOpcode() != ISD::SRL || | 
|  | 10774 | !isa<ConstantSDNode>(RightShift->getOperand(1)) || | 
|  | 10775 | RightShift->getConstantOperandVal(1) != 32 || | 
|  | 10776 | !RightShift->hasOneUse()) | 
|  | 10777 | return false; | 
|  | 10778 |  | 
|  | 10779 | SDNode *Trunc2 = *RightShift->use_begin(); | 
|  | 10780 | if (Trunc2->getOpcode() != ISD::TRUNCATE || | 
|  | 10781 | Trunc2->getValueType(0) != MVT::i32 || | 
|  | 10782 | !Trunc2->hasOneUse()) | 
|  | 10783 | return false; | 
|  | 10784 |  | 
|  | 10785 | SDNode *Bitcast = *Trunc->use_begin(); | 
|  | 10786 | SDNode *Bitcast2 = *Trunc2->use_begin(); | 
|  | 10787 |  | 
|  | 10788 | if (Bitcast->getOpcode() != ISD::BITCAST || | 
|  | 10789 | Bitcast->getValueType(0) != MVT::f32) | 
|  | 10790 | return false; | 
| NAKAMURA Takumi | ae7c97d | 2016-06-20 00:49:20 +0000 | [diff] [blame] | 10791 | if (Bitcast2->getOpcode() != ISD::BITCAST || | 
| Hal Finkel | 851b33a | 2016-03-31 02:56:05 +0000 | [diff] [blame] | 10792 | Bitcast2->getValueType(0) != MVT::f32) | 
|  | 10793 | return false; | 
|  | 10794 |  | 
|  | 10795 | if (Subtarget.isLittleEndian()) | 
|  | 10796 | std::swap(Bitcast, Bitcast2); | 
|  | 10797 |  | 
|  | 10798 | // Bitcast has the second float (in memory-layout order) and Bitcast2 | 
|  | 10799 | // has the first one. | 
|  | 10800 |  | 
|  | 10801 | SDValue BasePtr = LD->getBasePtr(); | 
|  | 10802 | if (LD->isIndexed()) { | 
|  | 10803 | assert(LD->getAddressingMode() == ISD::PRE_INC && | 
|  | 10804 | "Non-pre-inc AM on PPC?"); | 
|  | 10805 | BasePtr = | 
|  | 10806 | DAG.getNode(ISD::ADD, dl, BasePtr.getValueType(), BasePtr, | 
|  | 10807 | LD->getOffset()); | 
|  | 10808 | } | 
|  | 10809 |  | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 10810 | auto MMOFlags = | 
|  | 10811 | LD->getMemOperand()->getFlags() & ~MachineMemOperand::MOVolatile; | 
|  | 10812 | SDValue FloatLoad = DAG.getLoad(MVT::f32, dl, LD->getChain(), BasePtr, | 
|  | 10813 | LD->getPointerInfo(), LD->getAlignment(), | 
|  | 10814 | MMOFlags, LD->getAAInfo()); | 
| Hal Finkel | 851b33a | 2016-03-31 02:56:05 +0000 | [diff] [blame] | 10815 | SDValue AddPtr = | 
|  | 10816 | DAG.getNode(ISD::ADD, dl, BasePtr.getValueType(), | 
|  | 10817 | BasePtr, DAG.getIntPtrConstant(4, dl)); | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 10818 | SDValue FloatLoad2 = DAG.getLoad( | 
|  | 10819 | MVT::f32, dl, SDValue(FloatLoad.getNode(), 1), AddPtr, | 
|  | 10820 | LD->getPointerInfo().getWithOffset(4), | 
|  | 10821 | MinAlign(LD->getAlignment(), 4), MMOFlags, LD->getAAInfo()); | 
| Hal Finkel | 851b33a | 2016-03-31 02:56:05 +0000 | [diff] [blame] | 10822 |  | 
|  | 10823 | if (LD->isIndexed()) { | 
| NAKAMURA Takumi | fe1202c | 2016-06-20 00:37:41 +0000 | [diff] [blame] | 10824 | // Note that DAGCombine should re-form any pre-increment load(s) from | 
|  | 10825 | // what is produced here if that makes sense. | 
| Hal Finkel | 851b33a | 2016-03-31 02:56:05 +0000 | [diff] [blame] | 10826 | DAG.ReplaceAllUsesOfValueWith(SDValue(LD, 1), BasePtr); | 
|  | 10827 | } | 
|  | 10828 |  | 
|  | 10829 | DCI.CombineTo(Bitcast2, FloatLoad); | 
|  | 10830 | DCI.CombineTo(Bitcast, FloatLoad2); | 
|  | 10831 |  | 
|  | 10832 | DAG.ReplaceAllUsesOfValueWith(SDValue(LD, LD->isIndexed() ? 2 : 1), | 
|  | 10833 | SDValue(FloatLoad2.getNode(), 1)); | 
|  | 10834 | return true; | 
|  | 10835 | }; | 
|  | 10836 |  | 
|  | 10837 | if (ReplaceTwoFloatLoad()) | 
|  | 10838 | return SDValue(N, 0); | 
|  | 10839 |  | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 10840 | EVT MemVT = LD->getMemoryVT(); | 
|  | 10841 | Type *Ty = MemVT.getTypeForEVT(*DAG.getContext()); | 
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 10842 | unsigned ABIAlignment = DAG.getDataLayout().getABITypeAlignment(Ty); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 10843 | Type *STy = MemVT.getScalarType().getTypeForEVT(*DAG.getContext()); | 
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 10844 | unsigned ScalarABIAlignment = DAG.getDataLayout().getABITypeAlignment(STy); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 10845 | if (LD->isUnindexed() && VT.isVector() && | 
|  | 10846 | ((Subtarget.hasAltivec() && ISD::isNON_EXTLoad(N) && | 
|  | 10847 | // P8 and later hardware should just use LOAD. | 
|  | 10848 | !Subtarget.hasP8Vector() && (VT == MVT::v16i8 || VT == MVT::v8i16 || | 
|  | 10849 | VT == MVT::v4i32 || VT == MVT::v4f32)) || | 
|  | 10850 | (Subtarget.hasQPX() && (VT == MVT::v4f64 || VT == MVT::v4f32) && | 
|  | 10851 | LD->getAlignment() >= ScalarABIAlignment)) && | 
| Hal Finkel | cf2e908 | 2013-05-24 23:00:14 +0000 | [diff] [blame] | 10852 | LD->getAlignment() < ABIAlignment) { | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 10853 | // This is a type-legal unaligned Altivec or QPX load. | 
| Hal Finkel | cf2e908 | 2013-05-24 23:00:14 +0000 | [diff] [blame] | 10854 | SDValue Chain = LD->getChain(); | 
|  | 10855 | SDValue Ptr = LD->getBasePtr(); | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 10856 | bool isLittleEndian = Subtarget.isLittleEndian(); | 
| Hal Finkel | cf2e908 | 2013-05-24 23:00:14 +0000 | [diff] [blame] | 10857 |  | 
|  | 10858 | // This implements the loading of unaligned vectors as described in | 
|  | 10859 | // the venerable Apple Velocity Engine overview. Specifically: | 
|  | 10860 | // https://developer.apple.com/hardwaredrivers/ve/alignment.html | 
|  | 10861 | // https://developer.apple.com/hardwaredrivers/ve/code_optimization.html | 
|  | 10862 | // | 
|  | 10863 | // The general idea is to expand a sequence of one or more unaligned | 
| Bill Schmidt | 6b5a7df | 2014-06-09 22:00:52 +0000 | [diff] [blame] | 10864 | // loads into an alignment-based permutation-control instruction (lvsl | 
|  | 10865 | // or lvsr), a series of regular vector loads (which always truncate | 
|  | 10866 | // their input address to an aligned address), and a series of | 
|  | 10867 | // permutations.  The results of these permutations are the requested | 
|  | 10868 | // loaded values.  The trick is that the last "extra" load is not taken | 
|  | 10869 | // from the address you might suspect (sizeof(vector) bytes after the | 
|  | 10870 | // last requested load), but rather sizeof(vector) - 1 bytes after the | 
|  | 10871 | // last requested vector. The point of this is to avoid a page fault if | 
|  | 10872 | // the base address happened to be aligned. This works because if the | 
|  | 10873 | // base address is aligned, then adding less than a full vector length | 
|  | 10874 | // will cause the last vector in the sequence to be (re)loaded. | 
|  | 10875 | // Otherwise, the next vector will be fetched as you might suspect was | 
|  | 10876 | // necessary. | 
| Hal Finkel | cf2e908 | 2013-05-24 23:00:14 +0000 | [diff] [blame] | 10877 |  | 
| Hal Finkel | bc2ee4c | 2013-05-25 04:05:05 +0000 | [diff] [blame] | 10878 | // We might be able to reuse the permutation generation from | 
| Hal Finkel | cf2e908 | 2013-05-24 23:00:14 +0000 | [diff] [blame] | 10879 | // a different base address offset from this one by an aligned amount. | 
| Hal Finkel | bc2ee4c | 2013-05-25 04:05:05 +0000 | [diff] [blame] | 10880 | // The INTRINSIC_WO_CHAIN DAG combine will attempt to perform this | 
|  | 10881 | // optimization later. | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 10882 | Intrinsic::ID Intr, IntrLD, IntrPerm; | 
|  | 10883 | MVT PermCntlTy, PermTy, LDTy; | 
|  | 10884 | if (Subtarget.hasAltivec()) { | 
|  | 10885 | Intr = isLittleEndian ?  Intrinsic::ppc_altivec_lvsr : | 
|  | 10886 | Intrinsic::ppc_altivec_lvsl; | 
|  | 10887 | IntrLD = Intrinsic::ppc_altivec_lvx; | 
|  | 10888 | IntrPerm = Intrinsic::ppc_altivec_vperm; | 
|  | 10889 | PermCntlTy = MVT::v16i8; | 
|  | 10890 | PermTy = MVT::v4i32; | 
|  | 10891 | LDTy = MVT::v4i32; | 
|  | 10892 | } else { | 
|  | 10893 | Intr =   MemVT == MVT::v4f64 ? Intrinsic::ppc_qpx_qvlpcld : | 
|  | 10894 | Intrinsic::ppc_qpx_qvlpcls; | 
|  | 10895 | IntrLD = MemVT == MVT::v4f64 ? Intrinsic::ppc_qpx_qvlfd : | 
|  | 10896 | Intrinsic::ppc_qpx_qvlfs; | 
|  | 10897 | IntrPerm = Intrinsic::ppc_qpx_qvfperm; | 
|  | 10898 | PermCntlTy = MVT::v4f64; | 
|  | 10899 | PermTy = MVT::v4f64; | 
|  | 10900 | LDTy = MemVT.getSimpleVT(); | 
|  | 10901 | } | 
|  | 10902 |  | 
|  | 10903 | SDValue PermCntl = BuildIntrinsicOp(Intr, Ptr, DAG, dl, PermCntlTy); | 
| Hal Finkel | cf2e908 | 2013-05-24 23:00:14 +0000 | [diff] [blame] | 10904 |  | 
| Hal Finkel | b6d0d6b | 2014-08-01 05:20:41 +0000 | [diff] [blame] | 10905 | // Create the new MMO for the new base load. It is like the original MMO, | 
|  | 10906 | // but represents an area in memory almost twice the vector size centered | 
|  | 10907 | // on the original address. If the address is unaligned, we might start | 
|  | 10908 | // reading up to (sizeof(vector)-1) bytes below the address of the | 
|  | 10909 | // original unaligned load. | 
| Hal Finkel | cf2e908 | 2013-05-24 23:00:14 +0000 | [diff] [blame] | 10910 | MachineFunction &MF = DAG.getMachineFunction(); | 
| Hal Finkel | b6d0d6b | 2014-08-01 05:20:41 +0000 | [diff] [blame] | 10911 | MachineMemOperand *BaseMMO = | 
| Hal Finkel | 99d9532 | 2015-09-03 21:12:15 +0000 | [diff] [blame] | 10912 | MF.getMachineMemOperand(LD->getMemOperand(), | 
|  | 10913 | -(long)MemVT.getStoreSize()+1, | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 10914 | 2*MemVT.getStoreSize()-1); | 
| Hal Finkel | b6d0d6b | 2014-08-01 05:20:41 +0000 | [diff] [blame] | 10915 |  | 
|  | 10916 | // Create the new base load. | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 10917 | SDValue LDXIntID = | 
|  | 10918 | DAG.getTargetConstant(IntrLD, dl, getPointerTy(MF.getDataLayout())); | 
| Hal Finkel | b6d0d6b | 2014-08-01 05:20:41 +0000 | [diff] [blame] | 10919 | SDValue BaseLoadOps[] = { Chain, LDXIntID, Ptr }; | 
|  | 10920 | SDValue BaseLoad = | 
|  | 10921 | DAG.getMemIntrinsicNode(ISD::INTRINSIC_W_CHAIN, dl, | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 10922 | DAG.getVTList(PermTy, MVT::Other), | 
|  | 10923 | BaseLoadOps, LDTy, BaseMMO); | 
| Hal Finkel | cf2e908 | 2013-05-24 23:00:14 +0000 | [diff] [blame] | 10924 |  | 
|  | 10925 | // Note that the value of IncOffset (which is provided to the next | 
|  | 10926 | // load's pointer info offset value, and thus used to calculate the | 
|  | 10927 | // alignment), and the value of IncValue (which is actually used to | 
|  | 10928 | // increment the pointer value) are different! This is because we | 
|  | 10929 | // require the next load to appear to be aligned, even though it | 
|  | 10930 | // is actually offset from the base pointer by a lesser amount. | 
|  | 10931 | int IncOffset = VT.getSizeInBits() / 8; | 
| Hal Finkel | 7d8a691 | 2013-05-26 18:08:30 +0000 | [diff] [blame] | 10932 | int IncValue = IncOffset; | 
|  | 10933 |  | 
|  | 10934 | // Walk (both up and down) the chain looking for another load at the real | 
|  | 10935 | // (aligned) offset (the alignment of the other load does not matter in | 
|  | 10936 | // this case). If found, then do not use the offset reduction trick, as | 
|  | 10937 | // that will prevent the loads from being later combined (as they would | 
|  | 10938 | // otherwise be duplicates). | 
|  | 10939 | if (!findConsecutiveLoad(LD, DAG)) | 
|  | 10940 | --IncValue; | 
|  | 10941 |  | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 10942 | SDValue Increment = | 
|  | 10943 | DAG.getConstant(IncValue, dl, getPointerTy(MF.getDataLayout())); | 
| Hal Finkel | cf2e908 | 2013-05-24 23:00:14 +0000 | [diff] [blame] | 10944 | Ptr = DAG.getNode(ISD::ADD, dl, Ptr.getValueType(), Ptr, Increment); | 
|  | 10945 |  | 
| Hal Finkel | b6d0d6b | 2014-08-01 05:20:41 +0000 | [diff] [blame] | 10946 | MachineMemOperand *ExtraMMO = | 
|  | 10947 | MF.getMachineMemOperand(LD->getMemOperand(), | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 10948 | 1, 2*MemVT.getStoreSize()-1); | 
| Hal Finkel | b6d0d6b | 2014-08-01 05:20:41 +0000 | [diff] [blame] | 10949 | SDValue ExtraLoadOps[] = { Chain, LDXIntID, Ptr }; | 
| Hal Finkel | cf2e908 | 2013-05-24 23:00:14 +0000 | [diff] [blame] | 10950 | SDValue ExtraLoad = | 
| Hal Finkel | b6d0d6b | 2014-08-01 05:20:41 +0000 | [diff] [blame] | 10951 | DAG.getMemIntrinsicNode(ISD::INTRINSIC_W_CHAIN, dl, | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 10952 | DAG.getVTList(PermTy, MVT::Other), | 
|  | 10953 | ExtraLoadOps, LDTy, ExtraMMO); | 
| Hal Finkel | cf2e908 | 2013-05-24 23:00:14 +0000 | [diff] [blame] | 10954 |  | 
|  | 10955 | SDValue TF = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, | 
|  | 10956 | BaseLoad.getValue(1), ExtraLoad.getValue(1)); | 
|  | 10957 |  | 
| Bill Schmidt | 6b5a7df | 2014-06-09 22:00:52 +0000 | [diff] [blame] | 10958 | // Because vperm has a big-endian bias, we must reverse the order | 
|  | 10959 | // of the input vectors and complement the permute control vector | 
|  | 10960 | // when generating little endian code.  We have already handled the | 
|  | 10961 | // latter by using lvsr instead of lvsl, so just reverse BaseLoad | 
|  | 10962 | // and ExtraLoad here. | 
|  | 10963 | SDValue Perm; | 
|  | 10964 | if (isLittleEndian) | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 10965 | Perm = BuildIntrinsicOp(IntrPerm, | 
| Bill Schmidt | 6b5a7df | 2014-06-09 22:00:52 +0000 | [diff] [blame] | 10966 | ExtraLoad, BaseLoad, PermCntl, DAG, dl); | 
|  | 10967 | else | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 10968 | Perm = BuildIntrinsicOp(IntrPerm, | 
| Bill Schmidt | 6b5a7df | 2014-06-09 22:00:52 +0000 | [diff] [blame] | 10969 | BaseLoad, ExtraLoad, PermCntl, DAG, dl); | 
| Hal Finkel | cf2e908 | 2013-05-24 23:00:14 +0000 | [diff] [blame] | 10970 |  | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 10971 | if (VT != PermTy) | 
|  | 10972 | Perm = Subtarget.hasAltivec() ? | 
|  | 10973 | DAG.getNode(ISD::BITCAST, dl, VT, Perm) : | 
|  | 10974 | DAG.getNode(ISD::FP_ROUND, dl, VT, Perm, // QPX | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10975 | DAG.getTargetConstant(1, dl, MVT::i64)); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 10976 | // second argument is 1 because this rounding | 
|  | 10977 | // is always exact. | 
| Hal Finkel | cf2e908 | 2013-05-24 23:00:14 +0000 | [diff] [blame] | 10978 |  | 
| Hal Finkel | b6d0d6b | 2014-08-01 05:20:41 +0000 | [diff] [blame] | 10979 | // The output of the permutation is our loaded result, the TokenFactor is | 
|  | 10980 | // our new chain. | 
|  | 10981 | DCI.CombineTo(N, Perm, TF); | 
| Hal Finkel | cf2e908 | 2013-05-24 23:00:14 +0000 | [diff] [blame] | 10982 | return SDValue(N, 0); | 
|  | 10983 | } | 
|  | 10984 | } | 
|  | 10985 | break; | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 10986 | case ISD::INTRINSIC_WO_CHAIN: { | 
|  | 10987 | bool isLittleEndian = Subtarget.isLittleEndian(); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 10988 | unsigned IID = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue(); | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 10989 | Intrinsic::ID Intr = (isLittleEndian ? Intrinsic::ppc_altivec_lvsr | 
|  | 10990 | : Intrinsic::ppc_altivec_lvsl); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 10991 | if ((IID == Intr || | 
|  | 10992 | IID == Intrinsic::ppc_qpx_qvlpcld  || | 
|  | 10993 | IID == Intrinsic::ppc_qpx_qvlpcls) && | 
|  | 10994 | N->getOperand(1)->getOpcode() == ISD::ADD) { | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 10995 | SDValue Add = N->getOperand(1); | 
| Hal Finkel | bc2ee4c | 2013-05-25 04:05:05 +0000 | [diff] [blame] | 10996 |  | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 10997 | int Bits = IID == Intrinsic::ppc_qpx_qvlpcld ? | 
|  | 10998 | 5 /* 32 byte alignment */ : 4 /* 16 byte alignment */; | 
|  | 10999 |  | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 11000 | if (DAG.MaskedValueIsZero( | 
|  | 11001 | Add->getOperand(1), | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 11002 | APInt::getAllOnesValue(Bits /* alignment */) | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 11003 | .zext( | 
|  | 11004 | Add.getValueType().getScalarType().getSizeInBits()))) { | 
|  | 11005 | SDNode *BasePtr = Add->getOperand(0).getNode(); | 
|  | 11006 | for (SDNode::use_iterator UI = BasePtr->use_begin(), | 
|  | 11007 | UE = BasePtr->use_end(); | 
|  | 11008 | UI != UE; ++UI) { | 
|  | 11009 | if (UI->getOpcode() == ISD::INTRINSIC_WO_CHAIN && | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 11010 | cast<ConstantSDNode>(UI->getOperand(0))->getZExtValue() == IID) { | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 11011 | // We've found another LVSL/LVSR, and this address is an aligned | 
|  | 11012 | // multiple of that one. The results will be the same, so use the | 
|  | 11013 | // one we've just found instead. | 
| Hal Finkel | bc2ee4c | 2013-05-25 04:05:05 +0000 | [diff] [blame] | 11014 |  | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 11015 | return SDValue(*UI, 0); | 
|  | 11016 | } | 
| Hal Finkel | bc2ee4c | 2013-05-25 04:05:05 +0000 | [diff] [blame] | 11017 | } | 
|  | 11018 | } | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 11019 |  | 
|  | 11020 | if (isa<ConstantSDNode>(Add->getOperand(1))) { | 
|  | 11021 | SDNode *BasePtr = Add->getOperand(0).getNode(); | 
|  | 11022 | for (SDNode::use_iterator UI = BasePtr->use_begin(), | 
|  | 11023 | UE = BasePtr->use_end(); UI != UE; ++UI) { | 
|  | 11024 | if (UI->getOpcode() == ISD::ADD && | 
|  | 11025 | isa<ConstantSDNode>(UI->getOperand(1)) && | 
|  | 11026 | (cast<ConstantSDNode>(Add->getOperand(1))->getZExtValue() - | 
|  | 11027 | cast<ConstantSDNode>(UI->getOperand(1))->getZExtValue()) % | 
| Aaron Ballman | 5561ed4 | 2015-02-25 13:05:24 +0000 | [diff] [blame] | 11028 | (1ULL << Bits) == 0) { | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 11029 | SDNode *OtherAdd = *UI; | 
|  | 11030 | for (SDNode::use_iterator VI = OtherAdd->use_begin(), | 
|  | 11031 | VE = OtherAdd->use_end(); VI != VE; ++VI) { | 
|  | 11032 | if (VI->getOpcode() == ISD::INTRINSIC_WO_CHAIN && | 
|  | 11033 | cast<ConstantSDNode>(VI->getOperand(0))->getZExtValue() == IID) { | 
|  | 11034 | return SDValue(*VI, 0); | 
|  | 11035 | } | 
|  | 11036 | } | 
|  | 11037 | } | 
|  | 11038 | } | 
|  | 11039 | } | 
| Hal Finkel | bc2ee4c | 2013-05-25 04:05:05 +0000 | [diff] [blame] | 11040 | } | 
|  | 11041 | } | 
| Hal Finkel | c3cfbf8 | 2013-09-13 20:09:02 +0000 | [diff] [blame] | 11042 |  | 
|  | 11043 | break; | 
| Bill Schmidt | fae5d71 | 2014-12-09 16:35:51 +0000 | [diff] [blame] | 11044 | case ISD::INTRINSIC_W_CHAIN: { | 
|  | 11045 | // For little endian, VSX loads require generating lxvd2x/xxswapd. | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 11046 | if (Subtarget.hasVSX() && Subtarget.isLittleEndian()) { | 
| Bill Schmidt | fae5d71 | 2014-12-09 16:35:51 +0000 | [diff] [blame] | 11047 | switch (cast<ConstantSDNode>(N->getOperand(1))->getZExtValue()) { | 
|  | 11048 | default: | 
|  | 11049 | break; | 
|  | 11050 | case Intrinsic::ppc_vsx_lxvw4x: | 
|  | 11051 | case Intrinsic::ppc_vsx_lxvd2x: | 
|  | 11052 | return expandVSXLoadForLE(N, DCI); | 
|  | 11053 | } | 
|  | 11054 | } | 
|  | 11055 | break; | 
|  | 11056 | } | 
|  | 11057 | case ISD::INTRINSIC_VOID: { | 
|  | 11058 | // For little endian, VSX stores require generating xxswapd/stxvd2x. | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 11059 | if (Subtarget.hasVSX() && Subtarget.isLittleEndian()) { | 
| Bill Schmidt | fae5d71 | 2014-12-09 16:35:51 +0000 | [diff] [blame] | 11060 | switch (cast<ConstantSDNode>(N->getOperand(1))->getZExtValue()) { | 
|  | 11061 | default: | 
|  | 11062 | break; | 
|  | 11063 | case Intrinsic::ppc_vsx_stxvw4x: | 
|  | 11064 | case Intrinsic::ppc_vsx_stxvd2x: | 
|  | 11065 | return expandVSXStoreForLE(N, DCI); | 
|  | 11066 | } | 
|  | 11067 | } | 
|  | 11068 | break; | 
|  | 11069 | } | 
| Chris Lattner | a7976d3 | 2006-07-10 20:56:58 +0000 | [diff] [blame] | 11070 | case ISD::BSWAP: | 
|  | 11071 | // Turn BSWAP (LOAD) -> lhbrx/lwbrx. | 
| Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 11072 | if (ISD::isNON_EXTLoad(N->getOperand(0).getNode()) && | 
| Chris Lattner | a7976d3 | 2006-07-10 20:56:58 +0000 | [diff] [blame] | 11073 | N->getOperand(0).hasOneUse() && | 
| Hal Finkel | 31d2956 | 2013-03-28 19:25:55 +0000 | [diff] [blame] | 11074 | (N->getValueType(0) == MVT::i32 || N->getValueType(0) == MVT::i16 || | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 11075 | (Subtarget.hasLDBRX() && Subtarget.isPPC64() && | 
| Hal Finkel | 31d2956 | 2013-03-28 19:25:55 +0000 | [diff] [blame] | 11076 | N->getValueType(0) == MVT::i64))) { | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 11077 | SDValue Load = N->getOperand(0); | 
| Evan Cheng | e71fe34d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 11078 | LoadSDNode *LD = cast<LoadSDNode>(Load); | 
| Chris Lattner | a7976d3 | 2006-07-10 20:56:58 +0000 | [diff] [blame] | 11079 | // Create the byte-swapping load. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 11080 | SDValue Ops[] = { | 
| Evan Cheng | e71fe34d | 2006-10-09 20:57:25 +0000 | [diff] [blame] | 11081 | LD->getChain(),    // Chain | 
|  | 11082 | LD->getBasePtr(),  // Ptr | 
| Chris Lattner | d66f14e | 2006-08-11 17:18:05 +0000 | [diff] [blame] | 11083 | DAG.getValueType(N->getValueType(0)) // VT | 
|  | 11084 | }; | 
| Dan Gohman | 48b185d | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 11085 | SDValue BSLoad = | 
|  | 11086 | DAG.getMemIntrinsicNode(PPCISD::LBRX, dl, | 
| Hal Finkel | 31d2956 | 2013-03-28 19:25:55 +0000 | [diff] [blame] | 11087 | DAG.getVTList(N->getValueType(0) == MVT::i64 ? | 
|  | 11088 | MVT::i64 : MVT::i32, MVT::Other), | 
| Craig Topper | 206fcd4 | 2014-04-26 19:29:41 +0000 | [diff] [blame] | 11089 | Ops, LD->getMemoryVT(), LD->getMemOperand()); | 
| Chris Lattner | a7976d3 | 2006-07-10 20:56:58 +0000 | [diff] [blame] | 11090 |  | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11091 | // If this is an i16 load, insert the truncate. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 11092 | SDValue ResVal = BSLoad; | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 11093 | if (N->getValueType(0) == MVT::i16) | 
|  | 11094 | ResVal = DAG.getNode(ISD::TRUNCATE, dl, MVT::i16, BSLoad); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11095 |  | 
| Chris Lattner | a7976d3 | 2006-07-10 20:56:58 +0000 | [diff] [blame] | 11096 | // First, combine the bswap away.  This makes the value produced by the | 
|  | 11097 | // load dead. | 
|  | 11098 | DCI.CombineTo(N, ResVal); | 
|  | 11099 |  | 
|  | 11100 | // Next, combine the load away, we give it a bogus result value but a real | 
|  | 11101 | // chain result.  The result value is dead because the bswap is dead. | 
| Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 11102 | DCI.CombineTo(Load.getNode(), ResVal, BSLoad.getValue(1)); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11103 |  | 
| Chris Lattner | a7976d3 | 2006-07-10 20:56:58 +0000 | [diff] [blame] | 11104 | // Return N so it doesn't get rechecked! | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 11105 | return SDValue(N, 0); | 
| Chris Lattner | a7976d3 | 2006-07-10 20:56:58 +0000 | [diff] [blame] | 11106 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11107 |  | 
| Chris Lattner | 27f5345 | 2006-03-01 05:50:56 +0000 | [diff] [blame] | 11108 | break; | 
| Chris Lattner | d4058a5 | 2006-03-31 06:02:07 +0000 | [diff] [blame] | 11109 | case PPCISD::VCMP: { | 
|  | 11110 | // If a VCMPo node already exists with exactly the same operands as this | 
|  | 11111 | // node, use its result instead of this node (VCMPo computes both a CR6 and | 
|  | 11112 | // a normal output). | 
|  | 11113 | // | 
|  | 11114 | if (!N->getOperand(0).hasOneUse() && | 
|  | 11115 | !N->getOperand(1).hasOneUse() && | 
|  | 11116 | !N->getOperand(2).hasOneUse()) { | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11117 |  | 
| Chris Lattner | d4058a5 | 2006-03-31 06:02:07 +0000 | [diff] [blame] | 11118 | // Scan all of the users of the LHS, looking for VCMPo's that match. | 
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 11119 | SDNode *VCMPoNode = nullptr; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11120 |  | 
| Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 11121 | SDNode *LHSN = N->getOperand(0).getNode(); | 
| Chris Lattner | d4058a5 | 2006-03-31 06:02:07 +0000 | [diff] [blame] | 11122 | for (SDNode::use_iterator UI = LHSN->use_begin(), E = LHSN->use_end(); | 
|  | 11123 | UI != E; ++UI) | 
| Dan Gohman | 91e5dcb | 2008-07-27 20:43:25 +0000 | [diff] [blame] | 11124 | if (UI->getOpcode() == PPCISD::VCMPo && | 
|  | 11125 | UI->getOperand(1) == N->getOperand(1) && | 
|  | 11126 | UI->getOperand(2) == N->getOperand(2) && | 
|  | 11127 | UI->getOperand(0) == N->getOperand(0)) { | 
|  | 11128 | VCMPoNode = *UI; | 
| Chris Lattner | d4058a5 | 2006-03-31 06:02:07 +0000 | [diff] [blame] | 11129 | break; | 
|  | 11130 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11131 |  | 
| Chris Lattner | 518834c | 2006-04-18 18:28:22 +0000 | [diff] [blame] | 11132 | // If there is no VCMPo node, or if the flag value has a single use, don't | 
|  | 11133 | // transform this. | 
|  | 11134 | if (!VCMPoNode || VCMPoNode->hasNUsesOfValue(0, 1)) | 
|  | 11135 | break; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11136 |  | 
|  | 11137 | // Look at the (necessarily single) use of the flag value.  If it has a | 
| Chris Lattner | 518834c | 2006-04-18 18:28:22 +0000 | [diff] [blame] | 11138 | // chain, this transformation is more complex.  Note that multiple things | 
|  | 11139 | // could use the value result, which we should ignore. | 
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 11140 | SDNode *FlagUser = nullptr; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11141 | for (SDNode::use_iterator UI = VCMPoNode->use_begin(); | 
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 11142 | FlagUser == nullptr; ++UI) { | 
| Chris Lattner | 518834c | 2006-04-18 18:28:22 +0000 | [diff] [blame] | 11143 | assert(UI != VCMPoNode->use_end() && "Didn't find user!"); | 
| Dan Gohman | 91e5dcb | 2008-07-27 20:43:25 +0000 | [diff] [blame] | 11144 | SDNode *User = *UI; | 
| Chris Lattner | 518834c | 2006-04-18 18:28:22 +0000 | [diff] [blame] | 11145 | for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i) { | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 11146 | if (User->getOperand(i) == SDValue(VCMPoNode, 1)) { | 
| Chris Lattner | 518834c | 2006-04-18 18:28:22 +0000 | [diff] [blame] | 11147 | FlagUser = User; | 
|  | 11148 | break; | 
|  | 11149 | } | 
|  | 11150 | } | 
|  | 11151 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11152 |  | 
| Ulrich Weigand | d5ebc62 | 2013-07-03 17:05:42 +0000 | [diff] [blame] | 11153 | // If the user is a MFOCRF instruction, we know this is safe. | 
|  | 11154 | // Otherwise we give up for right now. | 
|  | 11155 | if (FlagUser->getOpcode() == PPCISD::MFOCRF) | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 11156 | return SDValue(VCMPoNode, 0); | 
| Chris Lattner | d4058a5 | 2006-03-31 06:02:07 +0000 | [diff] [blame] | 11157 | } | 
|  | 11158 | break; | 
|  | 11159 | } | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 11160 | case ISD::BRCOND: { | 
|  | 11161 | SDValue Cond = N->getOperand(1); | 
|  | 11162 | SDValue Target = N->getOperand(2); | 
| NAKAMURA Takumi | a9cb538 | 2015-09-22 11:14:39 +0000 | [diff] [blame] | 11163 |  | 
| Hal Finkel | 940ab93 | 2014-02-28 00:27:01 +0000 | [diff] [blame] | 11164 | if (Cond.getOpcode() == ISD::INTRINSIC_W_CHAIN && | 
|  | 11165 | cast<ConstantSDNode>(Cond.getOperand(1))->getZExtValue() == | 
|  | 11166 | Intrinsic::ppc_is_decremented_ctr_nonzero) { | 
|  | 11167 |  | 
|  | 11168 | // We now need to make the intrinsic dead (it cannot be instruction | 
|  | 11169 | // selected). | 
|  | 11170 | DAG.ReplaceAllUsesOfValueWith(Cond.getValue(1), Cond.getOperand(0)); | 
|  | 11171 | assert(Cond.getNode()->hasOneUse() && | 
|  | 11172 | "Counter decrement has more than one use"); | 
|  | 11173 |  | 
|  | 11174 | return DAG.getNode(PPCISD::BDNZ, dl, MVT::Other, | 
|  | 11175 | N->getOperand(0), Target); | 
|  | 11176 | } | 
|  | 11177 | } | 
|  | 11178 | break; | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 11179 | case ISD::BR_CC: { | 
|  | 11180 | // If this is a branch on an altivec predicate comparison, lower this so | 
| Ulrich Weigand | d5ebc62 | 2013-07-03 17:05:42 +0000 | [diff] [blame] | 11181 | // that we don't have to do a MFOCRF: instead, branch directly on CR6.  This | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 11182 | // lowering is done pre-legalize, because the legalizer lowers the predicate | 
|  | 11183 | // compare down to code that is difficult to reassemble. | 
|  | 11184 | ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(1))->get(); | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 11185 | SDValue LHS = N->getOperand(2), RHS = N->getOperand(3); | 
| Hal Finkel | 25c1992 | 2013-05-15 21:37:41 +0000 | [diff] [blame] | 11186 |  | 
|  | 11187 | // Sometimes the promoted value of the intrinsic is ANDed by some non-zero | 
|  | 11188 | // value. If so, pass-through the AND to get to the intrinsic. | 
|  | 11189 | if (LHS.getOpcode() == ISD::AND && | 
|  | 11190 | LHS.getOperand(0).getOpcode() == ISD::INTRINSIC_W_CHAIN && | 
|  | 11191 | cast<ConstantSDNode>(LHS.getOperand(0).getOperand(1))->getZExtValue() == | 
|  | 11192 | Intrinsic::ppc_is_decremented_ctr_nonzero && | 
|  | 11193 | isa<ConstantSDNode>(LHS.getOperand(1)) && | 
| Artyom Skrobov | 314ee04 | 2015-11-25 19:41:11 +0000 | [diff] [blame] | 11194 | !isNullConstant(LHS.getOperand(1))) | 
| Hal Finkel | 25c1992 | 2013-05-15 21:37:41 +0000 | [diff] [blame] | 11195 | LHS = LHS.getOperand(0); | 
|  | 11196 |  | 
|  | 11197 | if (LHS.getOpcode() == ISD::INTRINSIC_W_CHAIN && | 
|  | 11198 | cast<ConstantSDNode>(LHS.getOperand(1))->getZExtValue() == | 
|  | 11199 | Intrinsic::ppc_is_decremented_ctr_nonzero && | 
|  | 11200 | isa<ConstantSDNode>(RHS)) { | 
|  | 11201 | assert((CC == ISD::SETEQ || CC == ISD::SETNE) && | 
|  | 11202 | "Counter decrement comparison is not EQ or NE"); | 
|  | 11203 |  | 
|  | 11204 | unsigned Val = cast<ConstantSDNode>(RHS)->getZExtValue(); | 
|  | 11205 | bool isBDNZ = (CC == ISD::SETEQ && Val) || | 
|  | 11206 | (CC == ISD::SETNE && !Val); | 
|  | 11207 |  | 
|  | 11208 | // We now need to make the intrinsic dead (it cannot be instruction | 
|  | 11209 | // selected). | 
|  | 11210 | DAG.ReplaceAllUsesOfValueWith(LHS.getValue(1), LHS.getOperand(0)); | 
|  | 11211 | assert(LHS.getNode()->hasOneUse() && | 
|  | 11212 | "Counter decrement has more than one use"); | 
|  | 11213 |  | 
|  | 11214 | return DAG.getNode(isBDNZ ? PPCISD::BDNZ : PPCISD::BDZ, dl, MVT::Other, | 
|  | 11215 | N->getOperand(0), N->getOperand(4)); | 
|  | 11216 | } | 
|  | 11217 |  | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 11218 | int CompareOpc; | 
|  | 11219 | bool isDot; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11220 |  | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 11221 | if (LHS.getOpcode() == ISD::INTRINSIC_WO_CHAIN && | 
|  | 11222 | isa<ConstantSDNode>(RHS) && (CC == ISD::SETEQ || CC == ISD::SETNE) && | 
| Nemanja Ivanovic | 2c84b29 | 2015-09-29 17:41:53 +0000 | [diff] [blame] | 11223 | getVectorCompareInfo(LHS, CompareOpc, isDot, Subtarget)) { | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 11224 | assert(isDot && "Can't compare against a vector result!"); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11225 |  | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 11226 | // If this is a comparison against something other than 0/1, then we know | 
|  | 11227 | // that the condition is never/always true. | 
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 11228 | unsigned Val = cast<ConstantSDNode>(RHS)->getZExtValue(); | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 11229 | if (Val != 0 && Val != 1) { | 
|  | 11230 | if (CC == ISD::SETEQ)      // Cond never true, remove branch. | 
|  | 11231 | return N->getOperand(0); | 
|  | 11232 | // Always !=, turn it into an unconditional branch. | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 11233 | return DAG.getNode(ISD::BR, dl, MVT::Other, | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 11234 | N->getOperand(0), N->getOperand(4)); | 
|  | 11235 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11236 |  | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 11237 | bool BranchOnWhenPredTrue = (CC == ISD::SETEQ) ^ (Val == 0); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11238 |  | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 11239 | // Create the PPCISD altivec 'dot' comparison node. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 11240 | SDValue Ops[] = { | 
| Chris Lattner | d66f14e | 2006-08-11 17:18:05 +0000 | [diff] [blame] | 11241 | LHS.getOperand(2),  // LHS of compare | 
|  | 11242 | LHS.getOperand(3),  // RHS of compare | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11243 | DAG.getConstant(CompareOpc, dl, MVT::i32) | 
| Chris Lattner | d66f14e | 2006-08-11 17:18:05 +0000 | [diff] [blame] | 11244 | }; | 
| Benjamin Kramer | fdf362b | 2013-03-07 20:33:29 +0000 | [diff] [blame] | 11245 | EVT VTs[] = { LHS.getOperand(2).getValueType(), MVT::Glue }; | 
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 11246 | SDValue CompNode = DAG.getNode(PPCISD::VCMPo, dl, VTs, Ops); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11247 |  | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 11248 | // Unpack the result based on how the target uses it. | 
| Chris Lattner | 8c6a41e | 2006-11-17 22:10:59 +0000 | [diff] [blame] | 11249 | PPC::Predicate CompOpc; | 
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 11250 | switch (cast<ConstantSDNode>(LHS.getOperand(1))->getZExtValue()) { | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 11251 | default:  // Can't happen, don't crash on invalid number though. | 
|  | 11252 | case 0:   // Branch on the value of the EQ bit of CR6. | 
| Chris Lattner | 8c6a41e | 2006-11-17 22:10:59 +0000 | [diff] [blame] | 11253 | CompOpc = BranchOnWhenPredTrue ? PPC::PRED_EQ : PPC::PRED_NE; | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 11254 | break; | 
|  | 11255 | case 1:   // Branch on the inverted value of the EQ bit of CR6. | 
| Chris Lattner | 8c6a41e | 2006-11-17 22:10:59 +0000 | [diff] [blame] | 11256 | CompOpc = BranchOnWhenPredTrue ? PPC::PRED_NE : PPC::PRED_EQ; | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 11257 | break; | 
|  | 11258 | case 2:   // Branch on the value of the LT bit of CR6. | 
| Chris Lattner | 8c6a41e | 2006-11-17 22:10:59 +0000 | [diff] [blame] | 11259 | CompOpc = BranchOnWhenPredTrue ? PPC::PRED_LT : PPC::PRED_GE; | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 11260 | break; | 
|  | 11261 | case 3:   // Branch on the inverted value of the LT bit of CR6. | 
| Chris Lattner | 8c6a41e | 2006-11-17 22:10:59 +0000 | [diff] [blame] | 11262 | CompOpc = BranchOnWhenPredTrue ? PPC::PRED_GE : PPC::PRED_LT; | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 11263 | break; | 
|  | 11264 | } | 
|  | 11265 |  | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 11266 | return DAG.getNode(PPCISD::COND_BRANCH, dl, MVT::Other, N->getOperand(0), | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11267 | DAG.getConstant(CompOpc, dl, MVT::i32), | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 11268 | DAG.getRegister(PPC::CR6, MVT::i32), | 
| Chris Lattner | 9754d14 | 2006-04-18 17:59:36 +0000 | [diff] [blame] | 11269 | N->getOperand(4), CompNode.getValue(1)); | 
|  | 11270 | } | 
|  | 11271 | break; | 
|  | 11272 | } | 
| Nemanja Ivanovic | 44513e5 | 2016-07-05 09:22:29 +0000 | [diff] [blame] | 11273 | case ISD::BUILD_VECTOR: | 
|  | 11274 | return DAGCombineBuildVector(N, DCI); | 
| Chris Lattner | f418435 | 2006-03-01 04:57:39 +0000 | [diff] [blame] | 11275 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11276 |  | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 11277 | return SDValue(); | 
| Chris Lattner | f418435 | 2006-03-01 04:57:39 +0000 | [diff] [blame] | 11278 | } | 
|  | 11279 |  | 
| Hal Finkel | 13d104b | 2014-12-11 18:37:52 +0000 | [diff] [blame] | 11280 | SDValue | 
|  | 11281 | PPCTargetLowering::BuildSDIVPow2(SDNode *N, const APInt &Divisor, | 
|  | 11282 | SelectionDAG &DAG, | 
|  | 11283 | std::vector<SDNode *> *Created) const { | 
|  | 11284 | // fold (sdiv X, pow2) | 
|  | 11285 | EVT VT = N->getValueType(0); | 
| Hal Finkel | 04b16b5 | 2014-12-23 08:38:50 +0000 | [diff] [blame] | 11286 | if (VT == MVT::i64 && !Subtarget.isPPC64()) | 
|  | 11287 | return SDValue(); | 
| Hal Finkel | 13d104b | 2014-12-11 18:37:52 +0000 | [diff] [blame] | 11288 | if ((VT != MVT::i32 && VT != MVT::i64) || | 
|  | 11289 | !(Divisor.isPowerOf2() || (-Divisor).isPowerOf2())) | 
|  | 11290 | return SDValue(); | 
|  | 11291 |  | 
|  | 11292 | SDLoc DL(N); | 
|  | 11293 | SDValue N0 = N->getOperand(0); | 
|  | 11294 |  | 
|  | 11295 | bool IsNegPow2 = (-Divisor).isPowerOf2(); | 
|  | 11296 | unsigned Lg2 = (IsNegPow2 ? -Divisor : Divisor).countTrailingZeros(); | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11297 | SDValue ShiftAmt = DAG.getConstant(Lg2, DL, VT); | 
| Hal Finkel | 13d104b | 2014-12-11 18:37:52 +0000 | [diff] [blame] | 11298 |  | 
|  | 11299 | SDValue Op = DAG.getNode(PPCISD::SRA_ADDZE, DL, VT, N0, ShiftAmt); | 
|  | 11300 | if (Created) | 
|  | 11301 | Created->push_back(Op.getNode()); | 
|  | 11302 |  | 
|  | 11303 | if (IsNegPow2) { | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11304 | Op = DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, DL, VT), Op); | 
| Hal Finkel | 13d104b | 2014-12-11 18:37:52 +0000 | [diff] [blame] | 11305 | if (Created) | 
|  | 11306 | Created->push_back(Op.getNode()); | 
|  | 11307 | } | 
|  | 11308 |  | 
|  | 11309 | return Op; | 
|  | 11310 | } | 
|  | 11311 |  | 
| Chris Lattner | 4211ca9 | 2006-04-14 06:01:58 +0000 | [diff] [blame] | 11312 | //===----------------------------------------------------------------------===// | 
|  | 11313 | // Inline Assembly Support | 
|  | 11314 | //===----------------------------------------------------------------------===// | 
|  | 11315 |  | 
| Jay Foad | a0653a3 | 2014-05-14 21:14:37 +0000 | [diff] [blame] | 11316 | void PPCTargetLowering::computeKnownBitsForTargetNode(const SDValue Op, | 
|  | 11317 | APInt &KnownZero, | 
|  | 11318 | APInt &KnownOne, | 
|  | 11319 | const SelectionDAG &DAG, | 
|  | 11320 | unsigned Depth) const { | 
| Rafael Espindola | ba0a6ca | 2012-04-04 12:51:34 +0000 | [diff] [blame] | 11321 | KnownZero = KnownOne = APInt(KnownZero.getBitWidth(), 0); | 
| Chris Lattner | c5287c0 | 2006-04-02 06:26:07 +0000 | [diff] [blame] | 11322 | switch (Op.getOpcode()) { | 
|  | 11323 | default: break; | 
| Chris Lattner | a7976d3 | 2006-07-10 20:56:58 +0000 | [diff] [blame] | 11324 | case PPCISD::LBRX: { | 
|  | 11325 | // lhbrx is known to have the top bits cleared out. | 
| Dan Gohman | a5fc035 | 2009-09-27 23:17:47 +0000 | [diff] [blame] | 11326 | if (cast<VTSDNode>(Op.getOperand(2))->getVT() == MVT::i16) | 
| Chris Lattner | a7976d3 | 2006-07-10 20:56:58 +0000 | [diff] [blame] | 11327 | KnownZero = 0xFFFF0000; | 
|  | 11328 | break; | 
|  | 11329 | } | 
| Chris Lattner | c5287c0 | 2006-04-02 06:26:07 +0000 | [diff] [blame] | 11330 | case ISD::INTRINSIC_WO_CHAIN: { | 
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 11331 | switch (cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue()) { | 
| Chris Lattner | c5287c0 | 2006-04-02 06:26:07 +0000 | [diff] [blame] | 11332 | default: break; | 
|  | 11333 | case Intrinsic::ppc_altivec_vcmpbfp_p: | 
|  | 11334 | case Intrinsic::ppc_altivec_vcmpeqfp_p: | 
|  | 11335 | case Intrinsic::ppc_altivec_vcmpequb_p: | 
|  | 11336 | case Intrinsic::ppc_altivec_vcmpequh_p: | 
|  | 11337 | case Intrinsic::ppc_altivec_vcmpequw_p: | 
| Kit Barton | 0cfa7b7 | 2015-03-03 19:55:45 +0000 | [diff] [blame] | 11338 | case Intrinsic::ppc_altivec_vcmpequd_p: | 
| Chris Lattner | c5287c0 | 2006-04-02 06:26:07 +0000 | [diff] [blame] | 11339 | case Intrinsic::ppc_altivec_vcmpgefp_p: | 
|  | 11340 | case Intrinsic::ppc_altivec_vcmpgtfp_p: | 
|  | 11341 | case Intrinsic::ppc_altivec_vcmpgtsb_p: | 
|  | 11342 | case Intrinsic::ppc_altivec_vcmpgtsh_p: | 
|  | 11343 | case Intrinsic::ppc_altivec_vcmpgtsw_p: | 
| Kit Barton | 0cfa7b7 | 2015-03-03 19:55:45 +0000 | [diff] [blame] | 11344 | case Intrinsic::ppc_altivec_vcmpgtsd_p: | 
| Chris Lattner | c5287c0 | 2006-04-02 06:26:07 +0000 | [diff] [blame] | 11345 | case Intrinsic::ppc_altivec_vcmpgtub_p: | 
|  | 11346 | case Intrinsic::ppc_altivec_vcmpgtuh_p: | 
|  | 11347 | case Intrinsic::ppc_altivec_vcmpgtuw_p: | 
| Kit Barton | 0cfa7b7 | 2015-03-03 19:55:45 +0000 | [diff] [blame] | 11348 | case Intrinsic::ppc_altivec_vcmpgtud_p: | 
| Chris Lattner | c5287c0 | 2006-04-02 06:26:07 +0000 | [diff] [blame] | 11349 | KnownZero = ~1U;  // All bits but the low one are known to be zero. | 
|  | 11350 | break; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11351 | } | 
| Chris Lattner | c5287c0 | 2006-04-02 06:26:07 +0000 | [diff] [blame] | 11352 | } | 
|  | 11353 | } | 
|  | 11354 | } | 
|  | 11355 |  | 
| Hal Finkel | 5772566 | 2015-01-03 17:58:24 +0000 | [diff] [blame] | 11356 | unsigned PPCTargetLowering::getPrefLoopAlignment(MachineLoop *ML) const { | 
|  | 11357 | switch (Subtarget.getDarwinDirective()) { | 
|  | 11358 | default: break; | 
|  | 11359 | case PPC::DIR_970: | 
|  | 11360 | case PPC::DIR_PWR4: | 
|  | 11361 | case PPC::DIR_PWR5: | 
|  | 11362 | case PPC::DIR_PWR5X: | 
|  | 11363 | case PPC::DIR_PWR6: | 
|  | 11364 | case PPC::DIR_PWR6X: | 
|  | 11365 | case PPC::DIR_PWR7: | 
| Nemanja Ivanovic | 6e29baf | 2016-05-09 18:54:58 +0000 | [diff] [blame] | 11366 | case PPC::DIR_PWR8: | 
|  | 11367 | case PPC::DIR_PWR9: { | 
| Hal Finkel | 5772566 | 2015-01-03 17:58:24 +0000 | [diff] [blame] | 11368 | if (!ML) | 
|  | 11369 | break; | 
|  | 11370 |  | 
| Eric Christopher | cccae79 | 2015-01-30 22:02:31 +0000 | [diff] [blame] | 11371 | const PPCInstrInfo *TII = Subtarget.getInstrInfo(); | 
| Hal Finkel | 5772566 | 2015-01-03 17:58:24 +0000 | [diff] [blame] | 11372 |  | 
|  | 11373 | // For small loops (between 5 and 8 instructions), align to a 32-byte | 
|  | 11374 | // boundary so that the entire loop fits in one instruction-cache line. | 
|  | 11375 | uint64_t LoopSize = 0; | 
|  | 11376 | for (auto I = ML->block_begin(), IE = ML->block_end(); I != IE; ++I) | 
| Chad Rosier | bc9d4f9 | 2015-12-14 14:44:06 +0000 | [diff] [blame] | 11377 | for (auto J = (*I)->begin(), JE = (*I)->end(); J != JE; ++J) { | 
| Sjoerd Meijer | 89217f8 | 2016-07-28 16:32:22 +0000 | [diff] [blame] | 11378 | LoopSize += TII->getInstSizeInBytes(*J); | 
| Chad Rosier | bc9d4f9 | 2015-12-14 14:44:06 +0000 | [diff] [blame] | 11379 | if (LoopSize > 32) | 
|  | 11380 | break; | 
|  | 11381 | } | 
| Hal Finkel | 5772566 | 2015-01-03 17:58:24 +0000 | [diff] [blame] | 11382 |  | 
|  | 11383 | if (LoopSize > 16 && LoopSize <= 32) | 
|  | 11384 | return 5; | 
|  | 11385 |  | 
|  | 11386 | break; | 
|  | 11387 | } | 
|  | 11388 | } | 
|  | 11389 |  | 
|  | 11390 | return TargetLowering::getPrefLoopAlignment(ML); | 
|  | 11391 | } | 
| Chris Lattner | c5287c0 | 2006-04-02 06:26:07 +0000 | [diff] [blame] | 11392 |  | 
| Chris Lattner | d685514 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 11393 | /// getConstraintType - Given a constraint, return the type of | 
| Chris Lattner | 203b2f1 | 2006-02-07 20:16:30 +0000 | [diff] [blame] | 11394 | /// constraint it is for this target. | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11395 | PPCTargetLowering::ConstraintType | 
| Benjamin Kramer | 9bfb627 | 2015-07-05 19:29:18 +0000 | [diff] [blame] | 11396 | PPCTargetLowering::getConstraintType(StringRef Constraint) const { | 
| Chris Lattner | d685514 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 11397 | if (Constraint.size() == 1) { | 
|  | 11398 | switch (Constraint[0]) { | 
|  | 11399 | default: break; | 
|  | 11400 | case 'b': | 
|  | 11401 | case 'r': | 
|  | 11402 | case 'f': | 
| Eric Christopher | b979d51 | 2016-03-24 21:04:52 +0000 | [diff] [blame] | 11403 | case 'd': | 
| Chris Lattner | d685514 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 11404 | case 'v': | 
|  | 11405 | case 'y': | 
|  | 11406 | return C_RegisterClass; | 
| Hal Finkel | 4f24c62 | 2012-11-05 18:18:42 +0000 | [diff] [blame] | 11407 | case 'Z': | 
|  | 11408 | // FIXME: While Z does indicate a memory constraint, it specifically | 
|  | 11409 | // indicates an r+r address (used in conjunction with the 'y' modifier | 
|  | 11410 | // in the replacement string). Currently, we're forcing the base | 
|  | 11411 | // register to be r0 in the asm printer (which is interpreted as zero) | 
|  | 11412 | // and forming the complete address in the second register. This is | 
|  | 11413 | // suboptimal. | 
|  | 11414 | return C_Memory; | 
| Chris Lattner | d685514 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 11415 | } | 
| Hal Finkel | 6aca237 | 2014-03-02 18:23:39 +0000 | [diff] [blame] | 11416 | } else if (Constraint == "wc") { // individual CR bits. | 
|  | 11417 | return C_RegisterClass; | 
| Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 11418 | } else if (Constraint == "wa" || Constraint == "wd" || | 
|  | 11419 | Constraint == "wf" || Constraint == "ws") { | 
|  | 11420 | return C_RegisterClass; // VSX registers. | 
| Chris Lattner | d685514 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 11421 | } | 
|  | 11422 | return TargetLowering::getConstraintType(Constraint); | 
| Chris Lattner | 203b2f1 | 2006-02-07 20:16:30 +0000 | [diff] [blame] | 11423 | } | 
|  | 11424 |  | 
| John Thompson | e8360b7 | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 11425 | /// Examine constraint type and operand type and determine a weight value. | 
|  | 11426 | /// This object must already have been set up with the operand type | 
|  | 11427 | /// and the current alternative constraint selected. | 
|  | 11428 | TargetLowering::ConstraintWeight | 
|  | 11429 | PPCTargetLowering::getSingleConstraintMatchWeight( | 
|  | 11430 | AsmOperandInfo &info, const char *constraint) const { | 
|  | 11431 | ConstraintWeight weight = CW_Invalid; | 
|  | 11432 | Value *CallOperandVal = info.CallOperandVal; | 
|  | 11433 | // If we don't have a value, we can't do a match, | 
|  | 11434 | // but allow it at the lowest weight. | 
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 11435 | if (!CallOperandVal) | 
| John Thompson | e8360b7 | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 11436 | return CW_Default; | 
| Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 11437 | Type *type = CallOperandVal->getType(); | 
| Hal Finkel | 6aca237 | 2014-03-02 18:23:39 +0000 | [diff] [blame] | 11438 |  | 
| John Thompson | e8360b7 | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 11439 | // Look at the constraint type. | 
| Hal Finkel | 6aca237 | 2014-03-02 18:23:39 +0000 | [diff] [blame] | 11440 | if (StringRef(constraint) == "wc" && type->isIntegerTy(1)) | 
|  | 11441 | return CW_Register; // an individual CR bit. | 
| Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 11442 | else if ((StringRef(constraint) == "wa" || | 
|  | 11443 | StringRef(constraint) == "wd" || | 
|  | 11444 | StringRef(constraint) == "wf") && | 
|  | 11445 | type->isVectorTy()) | 
|  | 11446 | return CW_Register; | 
|  | 11447 | else if (StringRef(constraint) == "ws" && type->isDoubleTy()) | 
|  | 11448 | return CW_Register; | 
| Hal Finkel | 6aca237 | 2014-03-02 18:23:39 +0000 | [diff] [blame] | 11449 |  | 
| John Thompson | e8360b7 | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 11450 | switch (*constraint) { | 
|  | 11451 | default: | 
|  | 11452 | weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint); | 
|  | 11453 | break; | 
|  | 11454 | case 'b': | 
|  | 11455 | if (type->isIntegerTy()) | 
|  | 11456 | weight = CW_Register; | 
|  | 11457 | break; | 
|  | 11458 | case 'f': | 
|  | 11459 | if (type->isFloatTy()) | 
|  | 11460 | weight = CW_Register; | 
|  | 11461 | break; | 
|  | 11462 | case 'd': | 
|  | 11463 | if (type->isDoubleTy()) | 
|  | 11464 | weight = CW_Register; | 
|  | 11465 | break; | 
|  | 11466 | case 'v': | 
|  | 11467 | if (type->isVectorTy()) | 
|  | 11468 | weight = CW_Register; | 
|  | 11469 | break; | 
|  | 11470 | case 'y': | 
|  | 11471 | weight = CW_Register; | 
|  | 11472 | break; | 
| Hal Finkel | 4f24c62 | 2012-11-05 18:18:42 +0000 | [diff] [blame] | 11473 | case 'Z': | 
|  | 11474 | weight = CW_Memory; | 
|  | 11475 | break; | 
| John Thompson | e8360b7 | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 11476 | } | 
|  | 11477 | return weight; | 
|  | 11478 | } | 
|  | 11479 |  | 
| Eric Christopher | 11e4df7 | 2015-02-26 22:38:43 +0000 | [diff] [blame] | 11480 | std::pair<unsigned, const TargetRegisterClass *> | 
|  | 11481 | PPCTargetLowering::getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, | 
| Benjamin Kramer | 9bfb627 | 2015-07-05 19:29:18 +0000 | [diff] [blame] | 11482 | StringRef Constraint, | 
| Chad Rosier | 295bd43 | 2013-06-22 18:37:38 +0000 | [diff] [blame] | 11483 | MVT VT) const { | 
| Chris Lattner | 0151361 | 2006-01-31 19:20:21 +0000 | [diff] [blame] | 11484 | if (Constraint.size() == 1) { | 
| Chris Lattner | 584a11a | 2006-11-02 01:44:04 +0000 | [diff] [blame] | 11485 | // GCC RS6000 Constraint Letters | 
|  | 11486 | switch (Constraint[0]) { | 
|  | 11487 | case 'b':   // R1-R31 | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 11488 | if (VT == MVT::i64 && Subtarget.isPPC64()) | 
| Hal Finkel | 638a9fa | 2013-03-19 18:51:05 +0000 | [diff] [blame] | 11489 | return std::make_pair(0U, &PPC::G8RC_NOX0RegClass); | 
|  | 11490 | return std::make_pair(0U, &PPC::GPRC_NOR0RegClass); | 
| Chris Lattner | 584a11a | 2006-11-02 01:44:04 +0000 | [diff] [blame] | 11491 | case 'r':   // R0-R31 | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 11492 | if (VT == MVT::i64 && Subtarget.isPPC64()) | 
| Craig Topper | abadc66 | 2012-04-20 06:31:50 +0000 | [diff] [blame] | 11493 | return std::make_pair(0U, &PPC::G8RCRegClass); | 
|  | 11494 | return std::make_pair(0U, &PPC::GPRCRegClass); | 
| Eric Christopher | b979d51 | 2016-03-24 21:04:52 +0000 | [diff] [blame] | 11495 | // 'd' and 'f' constraints are both defined to be "the floating point | 
|  | 11496 | // registers", where one is for 32-bit and the other for 64-bit. We don't | 
|  | 11497 | // really care overly much here so just give them all the same reg classes. | 
|  | 11498 | case 'd': | 
| Chris Lattner | 584a11a | 2006-11-02 01:44:04 +0000 | [diff] [blame] | 11499 | case 'f': | 
| Ulrich Weigand | 0de4a1e | 2012-10-29 17:49:34 +0000 | [diff] [blame] | 11500 | if (VT == MVT::f32 || VT == MVT::i32) | 
| Craig Topper | abadc66 | 2012-04-20 06:31:50 +0000 | [diff] [blame] | 11501 | return std::make_pair(0U, &PPC::F4RCRegClass); | 
| Ulrich Weigand | 0de4a1e | 2012-10-29 17:49:34 +0000 | [diff] [blame] | 11502 | if (VT == MVT::f64 || VT == MVT::i64) | 
| Craig Topper | abadc66 | 2012-04-20 06:31:50 +0000 | [diff] [blame] | 11503 | return std::make_pair(0U, &PPC::F8RCRegClass); | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 11504 | if (VT == MVT::v4f64 && Subtarget.hasQPX()) | 
|  | 11505 | return std::make_pair(0U, &PPC::QFRCRegClass); | 
|  | 11506 | if (VT == MVT::v4f32 && Subtarget.hasQPX()) | 
|  | 11507 | return std::make_pair(0U, &PPC::QSRCRegClass); | 
| Chris Lattner | 584a11a | 2006-11-02 01:44:04 +0000 | [diff] [blame] | 11508 | break; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11509 | case 'v': | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 11510 | if (VT == MVT::v4f64 && Subtarget.hasQPX()) | 
|  | 11511 | return std::make_pair(0U, &PPC::QFRCRegClass); | 
|  | 11512 | if (VT == MVT::v4f32 && Subtarget.hasQPX()) | 
|  | 11513 | return std::make_pair(0U, &PPC::QSRCRegClass); | 
| Hal Finkel | bdd292a | 2015-10-28 23:03:45 +0000 | [diff] [blame] | 11514 | if (Subtarget.hasAltivec()) | 
|  | 11515 | return std::make_pair(0U, &PPC::VRRCRegClass); | 
| Chris Lattner | 584a11a | 2006-11-02 01:44:04 +0000 | [diff] [blame] | 11516 | case 'y':   // crrc | 
| Craig Topper | abadc66 | 2012-04-20 06:31:50 +0000 | [diff] [blame] | 11517 | return std::make_pair(0U, &PPC::CRRCRegClass); | 
| Chris Lattner | 0151361 | 2006-01-31 19:20:21 +0000 | [diff] [blame] | 11518 | } | 
| Hal Finkel | 34d4149 | 2015-10-28 22:25:52 +0000 | [diff] [blame] | 11519 | } else if (Constraint == "wc" && Subtarget.useCRBits()) { | 
|  | 11520 | // An individual CR bit. | 
| Hal Finkel | 6aca237 | 2014-03-02 18:23:39 +0000 | [diff] [blame] | 11521 | return std::make_pair(0U, &PPC::CRBITRCRegClass); | 
| Hal Finkel | bdd292a | 2015-10-28 23:03:45 +0000 | [diff] [blame] | 11522 | } else if ((Constraint == "wa" || Constraint == "wd" || | 
|  | 11523 | Constraint == "wf") && Subtarget.hasVSX()) { | 
| Hal Finkel | 27774d9 | 2014-03-13 07:58:58 +0000 | [diff] [blame] | 11524 | return std::make_pair(0U, &PPC::VSRCRegClass); | 
| Hal Finkel | bdd292a | 2015-10-28 23:03:45 +0000 | [diff] [blame] | 11525 | } else if (Constraint == "ws" && Subtarget.hasVSX()) { | 
|  | 11526 | if (VT == MVT::f32 && Subtarget.hasP8Vector()) | 
| Nemanja Ivanovic | f3c94b1 | 2015-05-07 18:24:05 +0000 | [diff] [blame] | 11527 | return std::make_pair(0U, &PPC::VSSRCRegClass); | 
|  | 11528 | else | 
|  | 11529 | return std::make_pair(0U, &PPC::VSFRCRegClass); | 
| Chris Lattner | 0151361 | 2006-01-31 19:20:21 +0000 | [diff] [blame] | 11530 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11531 |  | 
| Eric Christopher | 11e4df7 | 2015-02-26 22:38:43 +0000 | [diff] [blame] | 11532 | std::pair<unsigned, const TargetRegisterClass *> R = | 
|  | 11533 | TargetLowering::getRegForInlineAsmConstraint(TRI, Constraint, VT); | 
| Hal Finkel | b176acb | 2013-08-03 12:25:10 +0000 | [diff] [blame] | 11534 |  | 
|  | 11535 | // r[0-9]+ are used, on PPC64, to refer to the corresponding 64-bit registers | 
|  | 11536 | // (which we call X[0-9]+). If a 64-bit value has been requested, and a | 
|  | 11537 | // 32-bit GPR has been selected, then 'upgrade' it to the 64-bit parent | 
|  | 11538 | // register. | 
|  | 11539 | // FIXME: If TargetLowering::getRegForInlineAsmConstraint could somehow use | 
|  | 11540 | // the AsmName field from *RegisterInfo.td, then this would not be necessary. | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 11541 | if (R.first && VT == MVT::i64 && Subtarget.isPPC64() && | 
| Eric Christopher | 11e4df7 | 2015-02-26 22:38:43 +0000 | [diff] [blame] | 11542 | PPC::GPRCRegClass.contains(R.first)) | 
| Hal Finkel | b176acb | 2013-08-03 12:25:10 +0000 | [diff] [blame] | 11543 | return std::make_pair(TRI->getMatchingSuperReg(R.first, | 
| Hal Finkel | b3ca00d | 2013-08-14 20:05:04 +0000 | [diff] [blame] | 11544 | PPC::sub_32, &PPC::G8RCRegClass), | 
| Hal Finkel | b176acb | 2013-08-03 12:25:10 +0000 | [diff] [blame] | 11545 | &PPC::G8RCRegClass); | 
| Hal Finkel | b176acb | 2013-08-03 12:25:10 +0000 | [diff] [blame] | 11546 |  | 
| Hal Finkel | aa10b3c | 2014-12-08 22:54:22 +0000 | [diff] [blame] | 11547 | // GCC accepts 'cc' as an alias for 'cr0', and we need to do the same. | 
|  | 11548 | if (!R.second && StringRef("{cc}").equals_lower(Constraint)) { | 
|  | 11549 | R.first = PPC::CR0; | 
|  | 11550 | R.second = &PPC::CRRCRegClass; | 
|  | 11551 | } | 
|  | 11552 |  | 
| Hal Finkel | b176acb | 2013-08-03 12:25:10 +0000 | [diff] [blame] | 11553 | return R; | 
| Chris Lattner | 0151361 | 2006-01-31 19:20:21 +0000 | [diff] [blame] | 11554 | } | 
| Chris Lattner | 15a6c4c | 2006-02-07 00:47:13 +0000 | [diff] [blame] | 11555 |  | 
| Chris Lattner | d8c9cb9 | 2007-08-25 00:47:38 +0000 | [diff] [blame] | 11556 | /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops | 
| Dale Johannesen | ce97d55 | 2010-06-25 21:55:36 +0000 | [diff] [blame] | 11557 | /// vector.  If it is invalid, don't add anything to Ops. | 
| Eric Christopher | 0713a9d | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 11558 | void PPCTargetLowering::LowerAsmOperandForConstraint(SDValue Op, | 
| Eric Christopher | de9399b | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 11559 | std::string &Constraint, | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 11560 | std::vector<SDValue>&Ops, | 
| Chris Lattner | 724539c | 2008-04-26 23:02:14 +0000 | [diff] [blame] | 11561 | SelectionDAG &DAG) const { | 
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 11562 | SDValue Result; | 
| Eric Christopher | 0713a9d | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 11563 |  | 
| Eric Christopher | de9399b | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 11564 | // Only support length 1 constraints. | 
|  | 11565 | if (Constraint.length() > 1) return; | 
| Eric Christopher | 0713a9d | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 11566 |  | 
| Eric Christopher | de9399b | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 11567 | char Letter = Constraint[0]; | 
| Chris Lattner | 15a6c4c | 2006-02-07 00:47:13 +0000 | [diff] [blame] | 11568 | switch (Letter) { | 
|  | 11569 | default: break; | 
|  | 11570 | case 'I': | 
|  | 11571 | case 'J': | 
|  | 11572 | case 'K': | 
|  | 11573 | case 'L': | 
|  | 11574 | case 'M': | 
|  | 11575 | case 'N': | 
|  | 11576 | case 'O': | 
|  | 11577 | case 'P': { | 
| Chris Lattner | 0b7472d | 2007-05-15 01:31:05 +0000 | [diff] [blame] | 11578 | ConstantSDNode *CST = dyn_cast<ConstantSDNode>(Op); | 
| Chris Lattner | d8c9cb9 | 2007-08-25 00:47:38 +0000 | [diff] [blame] | 11579 | if (!CST) return; // Must be an immediate to match. | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11580 | SDLoc dl(Op); | 
| Hal Finkel | c91fc11 | 2014-12-03 09:37:50 +0000 | [diff] [blame] | 11581 | int64_t Value = CST->getSExtValue(); | 
|  | 11582 | EVT TCVT = MVT::i64; // All constants taken to be 64 bits so that negative | 
|  | 11583 | // numbers are printed as such. | 
| Chris Lattner | 15a6c4c | 2006-02-07 00:47:13 +0000 | [diff] [blame] | 11584 | switch (Letter) { | 
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 11585 | default: llvm_unreachable("Unknown constraint letter!"); | 
| Chris Lattner | 15a6c4c | 2006-02-07 00:47:13 +0000 | [diff] [blame] | 11586 | case 'I':  // "I" is a signed 16-bit constant. | 
| Hal Finkel | c91fc11 | 2014-12-03 09:37:50 +0000 | [diff] [blame] | 11587 | if (isInt<16>(Value)) | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11588 | Result = DAG.getTargetConstant(Value, dl, TCVT); | 
| Chris Lattner | 8c6949e | 2006-10-31 19:40:43 +0000 | [diff] [blame] | 11589 | break; | 
| Chris Lattner | 15a6c4c | 2006-02-07 00:47:13 +0000 | [diff] [blame] | 11590 | case 'J':  // "J" is a constant with only the high-order 16 bits nonzero. | 
| Hal Finkel | c91fc11 | 2014-12-03 09:37:50 +0000 | [diff] [blame] | 11591 | if (isShiftedUInt<16, 16>(Value)) | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11592 | Result = DAG.getTargetConstant(Value, dl, TCVT); | 
| Hal Finkel | c91fc11 | 2014-12-03 09:37:50 +0000 | [diff] [blame] | 11593 | break; | 
| Chris Lattner | 15a6c4c | 2006-02-07 00:47:13 +0000 | [diff] [blame] | 11594 | case 'L':  // "L" is a signed 16-bit constant shifted left 16 bits. | 
| Hal Finkel | c91fc11 | 2014-12-03 09:37:50 +0000 | [diff] [blame] | 11595 | if (isShiftedInt<16, 16>(Value)) | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11596 | Result = DAG.getTargetConstant(Value, dl, TCVT); | 
| Chris Lattner | 8c6949e | 2006-10-31 19:40:43 +0000 | [diff] [blame] | 11597 | break; | 
| Chris Lattner | 15a6c4c | 2006-02-07 00:47:13 +0000 | [diff] [blame] | 11598 | case 'K':  // "K" is a constant with only the low-order 16 bits nonzero. | 
| Hal Finkel | c91fc11 | 2014-12-03 09:37:50 +0000 | [diff] [blame] | 11599 | if (isUInt<16>(Value)) | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11600 | Result = DAG.getTargetConstant(Value, dl, TCVT); | 
| Chris Lattner | 8c6949e | 2006-10-31 19:40:43 +0000 | [diff] [blame] | 11601 | break; | 
| Chris Lattner | 15a6c4c | 2006-02-07 00:47:13 +0000 | [diff] [blame] | 11602 | case 'M':  // "M" is a constant that is greater than 31. | 
| Chris Lattner | 0b7472d | 2007-05-15 01:31:05 +0000 | [diff] [blame] | 11603 | if (Value > 31) | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11604 | Result = DAG.getTargetConstant(Value, dl, TCVT); | 
| Chris Lattner | 8c6949e | 2006-10-31 19:40:43 +0000 | [diff] [blame] | 11605 | break; | 
| Chris Lattner | 15a6c4c | 2006-02-07 00:47:13 +0000 | [diff] [blame] | 11606 | case 'N':  // "N" is a positive constant that is an exact power of two. | 
| Hal Finkel | c91fc11 | 2014-12-03 09:37:50 +0000 | [diff] [blame] | 11607 | if (Value > 0 && isPowerOf2_64(Value)) | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11608 | Result = DAG.getTargetConstant(Value, dl, TCVT); | 
| Chris Lattner | 8c6949e | 2006-10-31 19:40:43 +0000 | [diff] [blame] | 11609 | break; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11610 | case 'O':  // "O" is the constant zero. | 
| Chris Lattner | 0b7472d | 2007-05-15 01:31:05 +0000 | [diff] [blame] | 11611 | if (Value == 0) | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11612 | Result = DAG.getTargetConstant(Value, dl, TCVT); | 
| Chris Lattner | 8c6949e | 2006-10-31 19:40:43 +0000 | [diff] [blame] | 11613 | break; | 
| Chris Lattner | 15a6c4c | 2006-02-07 00:47:13 +0000 | [diff] [blame] | 11614 | case 'P':  // "P" is a constant whose negation is a signed 16-bit constant. | 
| Hal Finkel | c91fc11 | 2014-12-03 09:37:50 +0000 | [diff] [blame] | 11615 | if (isInt<16>(-Value)) | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11616 | Result = DAG.getTargetConstant(Value, dl, TCVT); | 
| Chris Lattner | 8c6949e | 2006-10-31 19:40:43 +0000 | [diff] [blame] | 11617 | break; | 
| Chris Lattner | 15a6c4c | 2006-02-07 00:47:13 +0000 | [diff] [blame] | 11618 | } | 
|  | 11619 | break; | 
|  | 11620 | } | 
|  | 11621 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11622 |  | 
| Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 11623 | if (Result.getNode()) { | 
| Chris Lattner | d8c9cb9 | 2007-08-25 00:47:38 +0000 | [diff] [blame] | 11624 | Ops.push_back(Result); | 
|  | 11625 | return; | 
|  | 11626 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11627 |  | 
| Chris Lattner | 15a6c4c | 2006-02-07 00:47:13 +0000 | [diff] [blame] | 11628 | // Handle standard constraint letters. | 
| Eric Christopher | de9399b | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 11629 | TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG); | 
| Chris Lattner | 15a6c4c | 2006-02-07 00:47:13 +0000 | [diff] [blame] | 11630 | } | 
| Evan Cheng | 2dd2c65 | 2006-03-13 23:20:37 +0000 | [diff] [blame] | 11631 |  | 
| Chris Lattner | 1eb94d9 | 2007-03-30 23:15:24 +0000 | [diff] [blame] | 11632 | // isLegalAddressingMode - Return true if the addressing mode represented | 
|  | 11633 | // by AM is legal for this target, for a load/store of the specified type. | 
| Mehdi Amini | 0cdec1e | 2015-07-09 02:09:40 +0000 | [diff] [blame] | 11634 | bool PPCTargetLowering::isLegalAddressingMode(const DataLayout &DL, | 
|  | 11635 | const AddrMode &AM, Type *Ty, | 
| Matt Arsenault | bd7d80a | 2015-06-01 05:31:59 +0000 | [diff] [blame] | 11636 | unsigned AS) const { | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 11637 | // PPC does not allow r+i addressing modes for vectors! | 
|  | 11638 | if (Ty->isVectorTy() && AM.BaseOffs != 0) | 
|  | 11639 | return false; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11640 |  | 
| Chris Lattner | 1eb94d9 | 2007-03-30 23:15:24 +0000 | [diff] [blame] | 11641 | // PPC allows a sign-extended 16-bit immediate field. | 
|  | 11642 | if (AM.BaseOffs <= -(1LL << 16) || AM.BaseOffs >= (1LL << 16)-1) | 
|  | 11643 | return false; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11644 |  | 
| Chris Lattner | 1eb94d9 | 2007-03-30 23:15:24 +0000 | [diff] [blame] | 11645 | // No global is ever allowed as a base. | 
|  | 11646 | if (AM.BaseGV) | 
|  | 11647 | return false; | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11648 |  | 
|  | 11649 | // PPC only support r+r, | 
| Chris Lattner | 1eb94d9 | 2007-03-30 23:15:24 +0000 | [diff] [blame] | 11650 | switch (AM.Scale) { | 
|  | 11651 | case 0:  // "r+i" or just "i", depending on HasBaseReg. | 
|  | 11652 | break; | 
|  | 11653 | case 1: | 
|  | 11654 | if (AM.HasBaseReg && AM.BaseOffs)  // "r+r+i" is not allowed. | 
|  | 11655 | return false; | 
|  | 11656 | // Otherwise we have r+r or r+i. | 
|  | 11657 | break; | 
|  | 11658 | case 2: | 
|  | 11659 | if (AM.HasBaseReg || AM.BaseOffs)  // 2*r+r  or  2*r+i is not allowed. | 
|  | 11660 | return false; | 
|  | 11661 | // Allow 2*r as r+r. | 
|  | 11662 | break; | 
| Chris Lattner | 19ccd62 | 2007-04-09 22:10:05 +0000 | [diff] [blame] | 11663 | default: | 
|  | 11664 | // No other scales are supported. | 
|  | 11665 | return false; | 
| Chris Lattner | 1eb94d9 | 2007-03-30 23:15:24 +0000 | [diff] [blame] | 11666 | } | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11667 |  | 
| Chris Lattner | 1eb94d9 | 2007-03-30 23:15:24 +0000 | [diff] [blame] | 11668 | return true; | 
|  | 11669 | } | 
|  | 11670 |  | 
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 11671 | SDValue PPCTargetLowering::LowerRETURNADDR(SDValue Op, | 
|  | 11672 | SelectionDAG &DAG) const { | 
| Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 11673 | MachineFunction &MF = DAG.getMachineFunction(); | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 11674 | MachineFrameInfo &MFI = MF.getFrameInfo(); | 
|  | 11675 | MFI.setReturnAddressIsTaken(true); | 
| Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 11676 |  | 
| Bill Wendling | 908bf81 | 2014-01-06 00:43:20 +0000 | [diff] [blame] | 11677 | if (verifyReturnAddressArgumentIsConstant(Op, DAG)) | 
| Bill Wendling | df7dd28 | 2014-01-05 01:47:20 +0000 | [diff] [blame] | 11678 | return SDValue(); | 
| Bill Wendling | df7dd28 | 2014-01-05 01:47:20 +0000 | [diff] [blame] | 11679 |  | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 11680 | SDLoc dl(Op); | 
| Dale Johannesen | 81bfca7 | 2010-05-03 22:59:34 +0000 | [diff] [blame] | 11681 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); | 
| Chris Lattner | f6a8156 | 2007-12-08 06:59:59 +0000 | [diff] [blame] | 11682 |  | 
| Dale Johannesen | 81bfca7 | 2010-05-03 22:59:34 +0000 | [diff] [blame] | 11683 | // Make sure the function does not optimize away the store of the RA to | 
|  | 11684 | // the stack. | 
| Chris Lattner | f6a8156 | 2007-12-08 06:59:59 +0000 | [diff] [blame] | 11685 | PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>(); | 
| Dale Johannesen | 81bfca7 | 2010-05-03 22:59:34 +0000 | [diff] [blame] | 11686 | FuncInfo->setLRStoreRequired(); | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 11687 | bool isPPC64 = Subtarget.isPPC64(); | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 11688 | auto PtrVT = getPointerTy(MF.getDataLayout()); | 
| Dale Johannesen | 81bfca7 | 2010-05-03 22:59:34 +0000 | [diff] [blame] | 11689 |  | 
|  | 11690 | if (Depth > 0) { | 
|  | 11691 | SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); | 
|  | 11692 | SDValue Offset = | 
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11693 | DAG.getConstant(Subtarget.getFrameLowering()->getReturnSaveOffset(), dl, | 
| Eric Christopher | f71609b | 2015-02-13 00:39:27 +0000 | [diff] [blame] | 11694 | isPPC64 ? MVT::i64 : MVT::i32); | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 11695 | return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), | 
|  | 11696 | DAG.getNode(ISD::ADD, dl, PtrVT, FrameAddr, Offset), | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 11697 | MachinePointerInfo()); | 
| Dale Johannesen | 81bfca7 | 2010-05-03 22:59:34 +0000 | [diff] [blame] | 11698 | } | 
| Chris Lattner | f6a8156 | 2007-12-08 06:59:59 +0000 | [diff] [blame] | 11699 |  | 
| Chris Lattner | f6a8156 | 2007-12-08 06:59:59 +0000 | [diff] [blame] | 11700 | // Just load the return address off the stack. | 
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 11701 | SDValue RetAddrFI = getReturnAddrFrameIndex(DAG); | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 11702 | return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), RetAddrFI, | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 11703 | MachinePointerInfo()); | 
| Chris Lattner | f6a8156 | 2007-12-08 06:59:59 +0000 | [diff] [blame] | 11704 | } | 
|  | 11705 |  | 
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 11706 | SDValue PPCTargetLowering::LowerFRAMEADDR(SDValue Op, | 
|  | 11707 | SelectionDAG &DAG) const { | 
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 11708 | SDLoc dl(Op); | 
| Dale Johannesen | 81bfca7 | 2010-05-03 22:59:34 +0000 | [diff] [blame] | 11709 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); | 
| Scott Michel | cf0da6c | 2009-02-17 22:15:04 +0000 | [diff] [blame] | 11710 |  | 
| Nicolas Geoffray | 75ab979 | 2007-03-01 13:11:38 +0000 | [diff] [blame] | 11711 | MachineFunction &MF = DAG.getMachineFunction(); | 
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 11712 | MachineFrameInfo &MFI = MF.getFrameInfo(); | 
|  | 11713 | MFI.setFrameAddressIsTaken(true); | 
| Hal Finkel | aa03c03 | 2013-03-21 19:03:19 +0000 | [diff] [blame] | 11714 |  | 
| Eric Christopher | cd71946 | 2016-07-07 01:49:59 +0000 | [diff] [blame] | 11715 | EVT PtrVT = getPointerTy(MF.getDataLayout()); | 
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 11716 | bool isPPC64 = PtrVT == MVT::i64; | 
|  | 11717 |  | 
| Hal Finkel | aa03c03 | 2013-03-21 19:03:19 +0000 | [diff] [blame] | 11718 | // Naked functions never have a frame pointer, and so we use r1. For all | 
|  | 11719 | // other functions, this decision must be delayed until during PEI. | 
|  | 11720 | unsigned FrameReg; | 
| Duncan P. N. Exon Smith | 5bedaf93 | 2015-02-14 02:54:07 +0000 | [diff] [blame] | 11721 | if (MF.getFunction()->hasFnAttribute(Attribute::Naked)) | 
| Hal Finkel | aa03c03 | 2013-03-21 19:03:19 +0000 | [diff] [blame] | 11722 | FrameReg = isPPC64 ? PPC::X1 : PPC::R1; | 
|  | 11723 | else | 
|  | 11724 | FrameReg = isPPC64 ? PPC::FP8 : PPC::FP; | 
|  | 11725 |  | 
| Dale Johannesen | 81bfca7 | 2010-05-03 22:59:34 +0000 | [diff] [blame] | 11726 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, FrameReg, | 
|  | 11727 | PtrVT); | 
|  | 11728 | while (Depth--) | 
|  | 11729 | FrameAddr = DAG.getLoad(Op.getValueType(), dl, DAG.getEntryNode(), | 
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 11730 | FrameAddr, MachinePointerInfo()); | 
| Dale Johannesen | 81bfca7 | 2010-05-03 22:59:34 +0000 | [diff] [blame] | 11731 | return FrameAddr; | 
| Nicolas Geoffray | 75ab979 | 2007-03-01 13:11:38 +0000 | [diff] [blame] | 11732 | } | 
| Dan Gohman | c14e522 | 2008-10-21 03:41:46 +0000 | [diff] [blame] | 11733 |  | 
| Hal Finkel | 0d8db46 | 2014-05-11 19:29:11 +0000 | [diff] [blame] | 11734 | // FIXME? Maybe this could be a TableGen attribute on some registers and | 
|  | 11735 | // this table could be generated automatically from RegInfo. | 
| Pat Gavlin | a717f25 | 2015-07-09 17:40:29 +0000 | [diff] [blame] | 11736 | unsigned PPCTargetLowering::getRegisterByName(const char* RegName, EVT VT, | 
|  | 11737 | SelectionDAG &DAG) const { | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 11738 | bool isPPC64 = Subtarget.isPPC64(); | 
|  | 11739 | bool isDarwinABI = Subtarget.isDarwinABI(); | 
| Hal Finkel | 0d8db46 | 2014-05-11 19:29:11 +0000 | [diff] [blame] | 11740 |  | 
|  | 11741 | if ((isPPC64 && VT != MVT::i64 && VT != MVT::i32) || | 
|  | 11742 | (!isPPC64 && VT != MVT::i32)) | 
|  | 11743 | report_fatal_error("Invalid register global variable type"); | 
|  | 11744 |  | 
|  | 11745 | bool is64Bit = isPPC64 && VT == MVT::i64; | 
|  | 11746 | unsigned Reg = StringSwitch<unsigned>(RegName) | 
|  | 11747 | .Case("r1", is64Bit ? PPC::X1 : PPC::R1) | 
| Hal Finkel | e6698d5 | 2015-02-01 15:03:28 +0000 | [diff] [blame] | 11748 | .Case("r2", (isDarwinABI || isPPC64) ? 0 : PPC::R2) | 
| Hal Finkel | 0d8db46 | 2014-05-11 19:29:11 +0000 | [diff] [blame] | 11749 | .Case("r13", (!isPPC64 && isDarwinABI) ? 0 : | 
|  | 11750 | (is64Bit ? PPC::X13 : PPC::R13)) | 
|  | 11751 | .Default(0); | 
|  | 11752 |  | 
|  | 11753 | if (Reg) | 
|  | 11754 | return Reg; | 
|  | 11755 | report_fatal_error("Invalid register name global variable"); | 
|  | 11756 | } | 
|  | 11757 |  | 
| Dan Gohman | c14e522 | 2008-10-21 03:41:46 +0000 | [diff] [blame] | 11758 | bool | 
|  | 11759 | PPCTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { | 
|  | 11760 | // The PowerPC target isn't yet aware of offsets. | 
|  | 11761 | return false; | 
|  | 11762 | } | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 11763 |  | 
| Hal Finkel | 46ef7ce | 2014-08-13 01:15:40 +0000 | [diff] [blame] | 11764 | bool PPCTargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info, | 
|  | 11765 | const CallInst &I, | 
|  | 11766 | unsigned Intrinsic) const { | 
|  | 11767 |  | 
|  | 11768 | switch (Intrinsic) { | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 11769 | case Intrinsic::ppc_qpx_qvlfd: | 
|  | 11770 | case Intrinsic::ppc_qpx_qvlfs: | 
|  | 11771 | case Intrinsic::ppc_qpx_qvlfcd: | 
|  | 11772 | case Intrinsic::ppc_qpx_qvlfcs: | 
|  | 11773 | case Intrinsic::ppc_qpx_qvlfiwa: | 
|  | 11774 | case Intrinsic::ppc_qpx_qvlfiwz: | 
| Hal Finkel | 46ef7ce | 2014-08-13 01:15:40 +0000 | [diff] [blame] | 11775 | case Intrinsic::ppc_altivec_lvx: | 
|  | 11776 | case Intrinsic::ppc_altivec_lvxl: | 
|  | 11777 | case Intrinsic::ppc_altivec_lvebx: | 
|  | 11778 | case Intrinsic::ppc_altivec_lvehx: | 
| Bill Schmidt | 7295478 | 2014-11-12 04:19:40 +0000 | [diff] [blame] | 11779 | case Intrinsic::ppc_altivec_lvewx: | 
|  | 11780 | case Intrinsic::ppc_vsx_lxvd2x: | 
|  | 11781 | case Intrinsic::ppc_vsx_lxvw4x: { | 
| Hal Finkel | 46ef7ce | 2014-08-13 01:15:40 +0000 | [diff] [blame] | 11782 | EVT VT; | 
|  | 11783 | switch (Intrinsic) { | 
|  | 11784 | case Intrinsic::ppc_altivec_lvebx: | 
|  | 11785 | VT = MVT::i8; | 
|  | 11786 | break; | 
|  | 11787 | case Intrinsic::ppc_altivec_lvehx: | 
|  | 11788 | VT = MVT::i16; | 
|  | 11789 | break; | 
|  | 11790 | case Intrinsic::ppc_altivec_lvewx: | 
|  | 11791 | VT = MVT::i32; | 
|  | 11792 | break; | 
| Bill Schmidt | 7295478 | 2014-11-12 04:19:40 +0000 | [diff] [blame] | 11793 | case Intrinsic::ppc_vsx_lxvd2x: | 
|  | 11794 | VT = MVT::v2f64; | 
|  | 11795 | break; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 11796 | case Intrinsic::ppc_qpx_qvlfd: | 
|  | 11797 | VT = MVT::v4f64; | 
|  | 11798 | break; | 
|  | 11799 | case Intrinsic::ppc_qpx_qvlfs: | 
|  | 11800 | VT = MVT::v4f32; | 
|  | 11801 | break; | 
|  | 11802 | case Intrinsic::ppc_qpx_qvlfcd: | 
|  | 11803 | VT = MVT::v2f64; | 
|  | 11804 | break; | 
|  | 11805 | case Intrinsic::ppc_qpx_qvlfcs: | 
|  | 11806 | VT = MVT::v2f32; | 
|  | 11807 | break; | 
| Hal Finkel | 46ef7ce | 2014-08-13 01:15:40 +0000 | [diff] [blame] | 11808 | default: | 
|  | 11809 | VT = MVT::v4i32; | 
|  | 11810 | break; | 
|  | 11811 | } | 
|  | 11812 |  | 
|  | 11813 | Info.opc = ISD::INTRINSIC_W_CHAIN; | 
|  | 11814 | Info.memVT = VT; | 
|  | 11815 | Info.ptrVal = I.getArgOperand(0); | 
|  | 11816 | Info.offset = -VT.getStoreSize()+1; | 
|  | 11817 | Info.size = 2*VT.getStoreSize()-1; | 
|  | 11818 | Info.align = 1; | 
|  | 11819 | Info.vol = false; | 
|  | 11820 | Info.readMem = true; | 
|  | 11821 | Info.writeMem = false; | 
|  | 11822 | return true; | 
|  | 11823 | } | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 11824 | case Intrinsic::ppc_qpx_qvlfda: | 
|  | 11825 | case Intrinsic::ppc_qpx_qvlfsa: | 
|  | 11826 | case Intrinsic::ppc_qpx_qvlfcda: | 
|  | 11827 | case Intrinsic::ppc_qpx_qvlfcsa: | 
|  | 11828 | case Intrinsic::ppc_qpx_qvlfiwaa: | 
|  | 11829 | case Intrinsic::ppc_qpx_qvlfiwza: { | 
|  | 11830 | EVT VT; | 
|  | 11831 | switch (Intrinsic) { | 
|  | 11832 | case Intrinsic::ppc_qpx_qvlfda: | 
|  | 11833 | VT = MVT::v4f64; | 
|  | 11834 | break; | 
|  | 11835 | case Intrinsic::ppc_qpx_qvlfsa: | 
|  | 11836 | VT = MVT::v4f32; | 
|  | 11837 | break; | 
|  | 11838 | case Intrinsic::ppc_qpx_qvlfcda: | 
|  | 11839 | VT = MVT::v2f64; | 
|  | 11840 | break; | 
|  | 11841 | case Intrinsic::ppc_qpx_qvlfcsa: | 
|  | 11842 | VT = MVT::v2f32; | 
|  | 11843 | break; | 
|  | 11844 | default: | 
|  | 11845 | VT = MVT::v4i32; | 
|  | 11846 | break; | 
|  | 11847 | } | 
|  | 11848 |  | 
|  | 11849 | Info.opc = ISD::INTRINSIC_W_CHAIN; | 
|  | 11850 | Info.memVT = VT; | 
|  | 11851 | Info.ptrVal = I.getArgOperand(0); | 
|  | 11852 | Info.offset = 0; | 
|  | 11853 | Info.size = VT.getStoreSize(); | 
|  | 11854 | Info.align = 1; | 
|  | 11855 | Info.vol = false; | 
|  | 11856 | Info.readMem = true; | 
|  | 11857 | Info.writeMem = false; | 
|  | 11858 | return true; | 
|  | 11859 | } | 
|  | 11860 | case Intrinsic::ppc_qpx_qvstfd: | 
|  | 11861 | case Intrinsic::ppc_qpx_qvstfs: | 
|  | 11862 | case Intrinsic::ppc_qpx_qvstfcd: | 
|  | 11863 | case Intrinsic::ppc_qpx_qvstfcs: | 
|  | 11864 | case Intrinsic::ppc_qpx_qvstfiw: | 
| Hal Finkel | 46ef7ce | 2014-08-13 01:15:40 +0000 | [diff] [blame] | 11865 | case Intrinsic::ppc_altivec_stvx: | 
|  | 11866 | case Intrinsic::ppc_altivec_stvxl: | 
|  | 11867 | case Intrinsic::ppc_altivec_stvebx: | 
|  | 11868 | case Intrinsic::ppc_altivec_stvehx: | 
| Bill Schmidt | 7295478 | 2014-11-12 04:19:40 +0000 | [diff] [blame] | 11869 | case Intrinsic::ppc_altivec_stvewx: | 
|  | 11870 | case Intrinsic::ppc_vsx_stxvd2x: | 
|  | 11871 | case Intrinsic::ppc_vsx_stxvw4x: { | 
| Hal Finkel | 46ef7ce | 2014-08-13 01:15:40 +0000 | [diff] [blame] | 11872 | EVT VT; | 
|  | 11873 | switch (Intrinsic) { | 
|  | 11874 | case Intrinsic::ppc_altivec_stvebx: | 
|  | 11875 | VT = MVT::i8; | 
|  | 11876 | break; | 
|  | 11877 | case Intrinsic::ppc_altivec_stvehx: | 
|  | 11878 | VT = MVT::i16; | 
|  | 11879 | break; | 
|  | 11880 | case Intrinsic::ppc_altivec_stvewx: | 
|  | 11881 | VT = MVT::i32; | 
|  | 11882 | break; | 
| Bill Schmidt | 7295478 | 2014-11-12 04:19:40 +0000 | [diff] [blame] | 11883 | case Intrinsic::ppc_vsx_stxvd2x: | 
|  | 11884 | VT = MVT::v2f64; | 
|  | 11885 | break; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 11886 | case Intrinsic::ppc_qpx_qvstfd: | 
|  | 11887 | VT = MVT::v4f64; | 
|  | 11888 | break; | 
|  | 11889 | case Intrinsic::ppc_qpx_qvstfs: | 
|  | 11890 | VT = MVT::v4f32; | 
|  | 11891 | break; | 
|  | 11892 | case Intrinsic::ppc_qpx_qvstfcd: | 
|  | 11893 | VT = MVT::v2f64; | 
|  | 11894 | break; | 
|  | 11895 | case Intrinsic::ppc_qpx_qvstfcs: | 
|  | 11896 | VT = MVT::v2f32; | 
|  | 11897 | break; | 
| Hal Finkel | 46ef7ce | 2014-08-13 01:15:40 +0000 | [diff] [blame] | 11898 | default: | 
|  | 11899 | VT = MVT::v4i32; | 
|  | 11900 | break; | 
|  | 11901 | } | 
|  | 11902 |  | 
|  | 11903 | Info.opc = ISD::INTRINSIC_VOID; | 
|  | 11904 | Info.memVT = VT; | 
|  | 11905 | Info.ptrVal = I.getArgOperand(1); | 
|  | 11906 | Info.offset = -VT.getStoreSize()+1; | 
|  | 11907 | Info.size = 2*VT.getStoreSize()-1; | 
|  | 11908 | Info.align = 1; | 
|  | 11909 | Info.vol = false; | 
|  | 11910 | Info.readMem = false; | 
|  | 11911 | Info.writeMem = true; | 
|  | 11912 | return true; | 
|  | 11913 | } | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 11914 | case Intrinsic::ppc_qpx_qvstfda: | 
|  | 11915 | case Intrinsic::ppc_qpx_qvstfsa: | 
|  | 11916 | case Intrinsic::ppc_qpx_qvstfcda: | 
|  | 11917 | case Intrinsic::ppc_qpx_qvstfcsa: | 
|  | 11918 | case Intrinsic::ppc_qpx_qvstfiwa: { | 
|  | 11919 | EVT VT; | 
|  | 11920 | switch (Intrinsic) { | 
|  | 11921 | case Intrinsic::ppc_qpx_qvstfda: | 
|  | 11922 | VT = MVT::v4f64; | 
|  | 11923 | break; | 
|  | 11924 | case Intrinsic::ppc_qpx_qvstfsa: | 
|  | 11925 | VT = MVT::v4f32; | 
|  | 11926 | break; | 
|  | 11927 | case Intrinsic::ppc_qpx_qvstfcda: | 
|  | 11928 | VT = MVT::v2f64; | 
|  | 11929 | break; | 
|  | 11930 | case Intrinsic::ppc_qpx_qvstfcsa: | 
|  | 11931 | VT = MVT::v2f32; | 
|  | 11932 | break; | 
|  | 11933 | default: | 
|  | 11934 | VT = MVT::v4i32; | 
|  | 11935 | break; | 
|  | 11936 | } | 
|  | 11937 |  | 
|  | 11938 | Info.opc = ISD::INTRINSIC_VOID; | 
|  | 11939 | Info.memVT = VT; | 
|  | 11940 | Info.ptrVal = I.getArgOperand(1); | 
|  | 11941 | Info.offset = 0; | 
|  | 11942 | Info.size = VT.getStoreSize(); | 
|  | 11943 | Info.align = 1; | 
|  | 11944 | Info.vol = false; | 
|  | 11945 | Info.readMem = false; | 
|  | 11946 | Info.writeMem = true; | 
|  | 11947 | return true; | 
|  | 11948 | } | 
| Hal Finkel | 46ef7ce | 2014-08-13 01:15:40 +0000 | [diff] [blame] | 11949 | default: | 
|  | 11950 | break; | 
|  | 11951 | } | 
|  | 11952 |  | 
|  | 11953 | return false; | 
|  | 11954 | } | 
|  | 11955 |  | 
| Evan Cheng | d9929f0 | 2010-04-01 20:10:42 +0000 | [diff] [blame] | 11956 | /// getOptimalMemOpType - Returns the target specific optimal type for load | 
| Evan Cheng | 6139937 | 2010-04-02 19:36:14 +0000 | [diff] [blame] | 11957 | /// and store operations as a result of memset, memcpy, and memmove | 
|  | 11958 | /// lowering. If DstAlign is zero that means it's safe to destination | 
|  | 11959 | /// alignment can satisfy any constraint. Similarly if SrcAlign is zero it | 
|  | 11960 | /// means there isn't a need to check it against alignment requirement, | 
| Evan Cheng | 962711e | 2012-12-12 02:34:41 +0000 | [diff] [blame] | 11961 | /// probably because the source does not need to be loaded. If 'IsMemset' is | 
|  | 11962 | /// true, that means it's expanding a memset. If 'ZeroMemset' is true, that | 
|  | 11963 | /// means it's a memset of zero. 'MemcpyStrSrc' indicates whether the memcpy | 
|  | 11964 | /// source is constant so it does not need to be loaded. | 
| Dan Gohman | 148c69a | 2010-04-16 20:11:05 +0000 | [diff] [blame] | 11965 | /// It returns EVT::Other if the type should be determined using generic | 
|  | 11966 | /// target-independent logic. | 
| Evan Cheng | 43cd9e3 | 2010-04-01 06:04:33 +0000 | [diff] [blame] | 11967 | EVT PPCTargetLowering::getOptimalMemOpType(uint64_t Size, | 
|  | 11968 | unsigned DstAlign, unsigned SrcAlign, | 
| Evan Cheng | 962711e | 2012-12-12 02:34:41 +0000 | [diff] [blame] | 11969 | bool IsMemset, bool ZeroMemset, | 
| Evan Cheng | ebe47c8 | 2010-04-08 07:37:57 +0000 | [diff] [blame] | 11970 | bool MemcpyStrSrc, | 
| Dan Gohman | 148c69a | 2010-04-16 20:11:05 +0000 | [diff] [blame] | 11971 | MachineFunction &MF) const { | 
| Hal Finkel | 52368d4 | 2015-03-31 20:56:09 +0000 | [diff] [blame] | 11972 | if (getTargetMachine().getOptLevel() != CodeGenOpt::None) { | 
|  | 11973 | const Function *F = MF.getFunction(); | 
|  | 11974 | // When expanding a memset, require at least two QPX instructions to cover | 
|  | 11975 | // the cost of loading the value to be stored from the constant pool. | 
|  | 11976 | if (Subtarget.hasQPX() && Size >= 32 && (!IsMemset || Size >= 64) && | 
|  | 11977 | (!SrcAlign || SrcAlign >= 32) && (!DstAlign || DstAlign >= 32) && | 
|  | 11978 | !F->hasFnAttribute(Attribute::NoImplicitFloat)) { | 
|  | 11979 | return MVT::v4f64; | 
|  | 11980 | } | 
| Hal Finkel | 5c3cacf | 2015-02-27 19:58:28 +0000 | [diff] [blame] | 11981 |  | 
| Hal Finkel | 52368d4 | 2015-03-31 20:56:09 +0000 | [diff] [blame] | 11982 | // We should use Altivec/VSX loads and stores when available. For unaligned | 
|  | 11983 | // addresses, unaligned VSX loads are only fast starting with the P8. | 
|  | 11984 | if (Subtarget.hasAltivec() && Size >= 16 && | 
|  | 11985 | (((!SrcAlign || SrcAlign >= 16) && (!DstAlign || DstAlign >= 16)) || | 
|  | 11986 | ((IsMemset && Subtarget.hasVSX()) || Subtarget.hasP8Vector()))) | 
|  | 11987 | return MVT::v4i32; | 
|  | 11988 | } | 
| Hal Finkel | 5c3cacf | 2015-02-27 19:58:28 +0000 | [diff] [blame] | 11989 |  | 
| Eric Christopher | d90a874 | 2014-06-12 22:38:20 +0000 | [diff] [blame] | 11990 | if (Subtarget.isPPC64()) { | 
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 11991 | return MVT::i64; | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 11992 | } | 
| Hal Finkel | 5c3cacf | 2015-02-27 19:58:28 +0000 | [diff] [blame] | 11993 |  | 
|  | 11994 | return MVT::i32; | 
| Tilmann Scheller | b93960d | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 11995 | } | 
| Hal Finkel | 88ed4e3 | 2012-04-01 19:23:08 +0000 | [diff] [blame] | 11996 |  | 
| Hal Finkel | 34974ed | 2014-04-12 21:52:38 +0000 | [diff] [blame] | 11997 | /// \brief Returns true if it is beneficial to convert a load of a constant | 
|  | 11998 | /// to just the constant itself. | 
|  | 11999 | bool PPCTargetLowering::shouldConvertConstantLoadToIntImm(const APInt &Imm, | 
|  | 12000 | Type *Ty) const { | 
|  | 12001 | assert(Ty->isIntegerTy()); | 
|  | 12002 |  | 
|  | 12003 | unsigned BitSize = Ty->getPrimitiveSizeInBits(); | 
| Alexander Kornienko | 175a7cb | 2015-12-28 13:38:42 +0000 | [diff] [blame] | 12004 | return !(BitSize == 0 || BitSize > 64); | 
| Hal Finkel | 34974ed | 2014-04-12 21:52:38 +0000 | [diff] [blame] | 12005 | } | 
|  | 12006 |  | 
|  | 12007 | bool PPCTargetLowering::isTruncateFree(Type *Ty1, Type *Ty2) const { | 
|  | 12008 | if (!Ty1->isIntegerTy() || !Ty2->isIntegerTy()) | 
|  | 12009 | return false; | 
|  | 12010 | unsigned NumBits1 = Ty1->getPrimitiveSizeInBits(); | 
|  | 12011 | unsigned NumBits2 = Ty2->getPrimitiveSizeInBits(); | 
|  | 12012 | return NumBits1 == 64 && NumBits2 == 32; | 
|  | 12013 | } | 
|  | 12014 |  | 
|  | 12015 | bool PPCTargetLowering::isTruncateFree(EVT VT1, EVT VT2) const { | 
|  | 12016 | if (!VT1.isInteger() || !VT2.isInteger()) | 
|  | 12017 | return false; | 
|  | 12018 | unsigned NumBits1 = VT1.getSizeInBits(); | 
|  | 12019 | unsigned NumBits2 = VT2.getSizeInBits(); | 
|  | 12020 | return NumBits1 == 64 && NumBits2 == 32; | 
|  | 12021 | } | 
|  | 12022 |  | 
| Hal Finkel | 5d5d153 | 2015-01-10 08:21:59 +0000 | [diff] [blame] | 12023 | bool PPCTargetLowering::isZExtFree(SDValue Val, EVT VT2) const { | 
|  | 12024 | // Generally speaking, zexts are not free, but they are free when they can be | 
|  | 12025 | // folded with other operations. | 
|  | 12026 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(Val)) { | 
|  | 12027 | EVT MemVT = LD->getMemoryVT(); | 
|  | 12028 | if ((MemVT == MVT::i1 || MemVT == MVT::i8 || MemVT == MVT::i16 || | 
|  | 12029 | (Subtarget.isPPC64() && MemVT == MVT::i32)) && | 
|  | 12030 | (LD->getExtensionType() == ISD::NON_EXTLOAD || | 
|  | 12031 | LD->getExtensionType() == ISD::ZEXTLOAD)) | 
|  | 12032 | return true; | 
|  | 12033 | } | 
|  | 12034 |  | 
|  | 12035 | // FIXME: Add other cases... | 
|  | 12036 | //  - 32-bit shifts with a zext to i64 | 
|  | 12037 | //  - zext after ctlz, bswap, etc. | 
|  | 12038 | //  - zext after and by a constant mask | 
|  | 12039 |  | 
|  | 12040 | return TargetLowering::isZExtFree(Val, VT2); | 
|  | 12041 | } | 
|  | 12042 |  | 
| Olivier Sallenave | 3250969 | 2015-01-13 15:06:36 +0000 | [diff] [blame] | 12043 | bool PPCTargetLowering::isFPExtFree(EVT VT) const { | 
|  | 12044 | assert(VT.isFloatingPoint()); | 
|  | 12045 | return true; | 
|  | 12046 | } | 
|  | 12047 |  | 
| Hal Finkel | 34974ed | 2014-04-12 21:52:38 +0000 | [diff] [blame] | 12048 | bool PPCTargetLowering::isLegalICmpImmediate(int64_t Imm) const { | 
|  | 12049 | return isInt<16>(Imm) || isUInt<16>(Imm); | 
|  | 12050 | } | 
|  | 12051 |  | 
|  | 12052 | bool PPCTargetLowering::isLegalAddImmediate(int64_t Imm) const { | 
|  | 12053 | return isInt<16>(Imm) || isUInt<16>(Imm); | 
|  | 12054 | } | 
|  | 12055 |  | 
| Matt Arsenault | 6f2a526 | 2014-07-27 17:46:40 +0000 | [diff] [blame] | 12056 | bool PPCTargetLowering::allowsMisalignedMemoryAccesses(EVT VT, | 
|  | 12057 | unsigned, | 
|  | 12058 | unsigned, | 
|  | 12059 | bool *Fast) const { | 
| Hal Finkel | 8d7fbc9 | 2013-03-15 15:27:13 +0000 | [diff] [blame] | 12060 | if (DisablePPCUnaligned) | 
|  | 12061 | return false; | 
|  | 12062 |  | 
|  | 12063 | // PowerPC supports unaligned memory access for simple non-vector types. | 
|  | 12064 | // Although accessing unaligned addresses is not as efficient as accessing | 
|  | 12065 | // aligned addresses, it is generally more efficient than manual expansion, | 
|  | 12066 | // and generally only traps for software emulation when crossing page | 
|  | 12067 | // boundaries. | 
|  | 12068 |  | 
|  | 12069 | if (!VT.isSimple()) | 
|  | 12070 | return false; | 
|  | 12071 |  | 
| Hal Finkel | 6e28e6a | 2014-03-26 19:39:09 +0000 | [diff] [blame] | 12072 | if (VT.getSimpleVT().isVector()) { | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 12073 | if (Subtarget.hasVSX()) { | 
| Bill Schmidt | 2d1128a | 2014-10-17 15:13:38 +0000 | [diff] [blame] | 12074 | if (VT != MVT::v2f64 && VT != MVT::v2i64 && | 
|  | 12075 | VT != MVT::v4f32 && VT != MVT::v4i32) | 
| Hal Finkel | 6e28e6a | 2014-03-26 19:39:09 +0000 | [diff] [blame] | 12076 | return false; | 
|  | 12077 | } else { | 
|  | 12078 | return false; | 
|  | 12079 | } | 
|  | 12080 | } | 
| Hal Finkel | 8d7fbc9 | 2013-03-15 15:27:13 +0000 | [diff] [blame] | 12081 |  | 
|  | 12082 | if (VT == MVT::ppcf128) | 
|  | 12083 | return false; | 
|  | 12084 |  | 
|  | 12085 | if (Fast) | 
|  | 12086 | *Fast = true; | 
|  | 12087 |  | 
|  | 12088 | return true; | 
|  | 12089 | } | 
|  | 12090 |  | 
| Stephen Lin | 73de7bf | 2013-07-09 18:16:56 +0000 | [diff] [blame] | 12091 | bool PPCTargetLowering::isFMAFasterThanFMulAndFAdd(EVT VT) const { | 
|  | 12092 | VT = VT.getScalarType(); | 
|  | 12093 |  | 
| Hal Finkel | 0a479ae | 2012-06-22 00:49:52 +0000 | [diff] [blame] | 12094 | if (!VT.isSimple()) | 
|  | 12095 | return false; | 
|  | 12096 |  | 
|  | 12097 | switch (VT.getSimpleVT().SimpleTy) { | 
|  | 12098 | case MVT::f32: | 
|  | 12099 | case MVT::f64: | 
| Hal Finkel | 0a479ae | 2012-06-22 00:49:52 +0000 | [diff] [blame] | 12100 | return true; | 
|  | 12101 | default: | 
|  | 12102 | break; | 
|  | 12103 | } | 
|  | 12104 |  | 
|  | 12105 | return false; | 
|  | 12106 | } | 
|  | 12107 |  | 
| Hal Finkel | 934361a | 2015-01-14 01:07:51 +0000 | [diff] [blame] | 12108 | const MCPhysReg * | 
|  | 12109 | PPCTargetLowering::getScratchRegisters(CallingConv::ID) const { | 
|  | 12110 | // LR is a callee-save register, but we must treat it as clobbered by any call | 
|  | 12111 | // site. Hence we include LR in the scratch registers, which are in turn added | 
|  | 12112 | // as implicit-defs for stackmaps and patchpoints. The same reasoning applies | 
|  | 12113 | // to CTR, which is used by any indirect call. | 
|  | 12114 | static const MCPhysReg ScratchRegs[] = { | 
| Hal Finkel | c19805a | 2015-01-17 03:57:34 +0000 | [diff] [blame] | 12115 | PPC::X12, PPC::LR8, PPC::CTR8, 0 | 
| Hal Finkel | 934361a | 2015-01-14 01:07:51 +0000 | [diff] [blame] | 12116 | }; | 
|  | 12117 |  | 
|  | 12118 | return ScratchRegs; | 
|  | 12119 | } | 
|  | 12120 |  | 
| Joseph Tremoulet | f748c89 | 2015-11-07 01:11:31 +0000 | [diff] [blame] | 12121 | unsigned PPCTargetLowering::getExceptionPointerRegister( | 
|  | 12122 | const Constant *PersonalityFn) const { | 
|  | 12123 | return Subtarget.isPPC64() ? PPC::X3 : PPC::R3; | 
|  | 12124 | } | 
|  | 12125 |  | 
|  | 12126 | unsigned PPCTargetLowering::getExceptionSelectorRegister( | 
|  | 12127 | const Constant *PersonalityFn) const { | 
|  | 12128 | return Subtarget.isPPC64() ? PPC::X4 : PPC::R4; | 
|  | 12129 | } | 
|  | 12130 |  | 
| Hal Finkel | b4240ca | 2014-03-31 17:48:16 +0000 | [diff] [blame] | 12131 | bool | 
|  | 12132 | PPCTargetLowering::shouldExpandBuildVectorWithShuffles( | 
|  | 12133 | EVT VT , unsigned DefinedValues) const { | 
|  | 12134 | if (VT == MVT::v2i64) | 
| Nemanja Ivanovic | 1c39ca6 | 2015-08-13 17:40:44 +0000 | [diff] [blame] | 12135 | return Subtarget.hasDirectMove(); // Don't need stack ops with direct moves | 
| Hal Finkel | b4240ca | 2014-03-31 17:48:16 +0000 | [diff] [blame] | 12136 |  | 
| Guozhi Wei | fa3e042 | 2016-04-29 17:00:54 +0000 | [diff] [blame] | 12137 | if (Subtarget.hasVSX() || Subtarget.hasQPX()) | 
|  | 12138 | return true; | 
| Hal Finkel | c93a9a2 | 2015-02-25 01:06:45 +0000 | [diff] [blame] | 12139 |  | 
| Hal Finkel | b4240ca | 2014-03-31 17:48:16 +0000 | [diff] [blame] | 12140 | return TargetLowering::shouldExpandBuildVectorWithShuffles(VT, DefinedValues); | 
|  | 12141 | } | 
|  | 12142 |  | 
| Hal Finkel | 88ed4e3 | 2012-04-01 19:23:08 +0000 | [diff] [blame] | 12143 | Sched::Preference PPCTargetLowering::getSchedulingPreference(SDNode *N) const { | 
| Eric Christopher | b1aaebe | 2014-06-12 22:38:18 +0000 | [diff] [blame] | 12144 | if (DisableILPPref || Subtarget.enableMachineScheduler()) | 
| Hal Finkel | 4e9f1a8 | 2012-06-10 19:32:29 +0000 | [diff] [blame] | 12145 | return TargetLowering::getSchedulingPreference(N); | 
| Hal Finkel | 88ed4e3 | 2012-04-01 19:23:08 +0000 | [diff] [blame] | 12146 |  | 
| Hal Finkel | 4e9f1a8 | 2012-06-10 19:32:29 +0000 | [diff] [blame] | 12147 | return Sched::ILP; | 
| Hal Finkel | 88ed4e3 | 2012-04-01 19:23:08 +0000 | [diff] [blame] | 12148 | } | 
|  | 12149 |  | 
| Bill Schmidt | 0cf702f | 2013-07-30 00:50:39 +0000 | [diff] [blame] | 12150 | // Create a fast isel object. | 
|  | 12151 | FastISel * | 
|  | 12152 | PPCTargetLowering::createFastISel(FunctionLoweringInfo &FuncInfo, | 
|  | 12153 | const TargetLibraryInfo *LibInfo) const { | 
|  | 12154 | return PPC::createFastISel(FuncInfo, LibInfo); | 
|  | 12155 | } | 
| Chuang-Yu Cheng | 98c1894 | 2016-04-08 12:04:32 +0000 | [diff] [blame] | 12156 |  | 
|  | 12157 | void PPCTargetLowering::initializeSplitCSR(MachineBasicBlock *Entry) const { | 
|  | 12158 | if (Subtarget.isDarwinABI()) return; | 
|  | 12159 | if (!Subtarget.isPPC64()) return; | 
|  | 12160 |  | 
|  | 12161 | // Update IsSplitCSR in PPCFunctionInfo | 
|  | 12162 | PPCFunctionInfo *PFI = Entry->getParent()->getInfo<PPCFunctionInfo>(); | 
|  | 12163 | PFI->setIsSplitCSR(true); | 
|  | 12164 | } | 
|  | 12165 |  | 
|  | 12166 | void PPCTargetLowering::insertCopiesSplitCSR( | 
|  | 12167 | MachineBasicBlock *Entry, | 
|  | 12168 | const SmallVectorImpl<MachineBasicBlock *> &Exits) const { | 
|  | 12169 | const PPCRegisterInfo *TRI = Subtarget.getRegisterInfo(); | 
|  | 12170 | const MCPhysReg *IStart = TRI->getCalleeSavedRegsViaCopy(Entry->getParent()); | 
|  | 12171 | if (!IStart) | 
|  | 12172 | return; | 
|  | 12173 |  | 
|  | 12174 | const TargetInstrInfo *TII = Subtarget.getInstrInfo(); | 
|  | 12175 | MachineRegisterInfo *MRI = &Entry->getParent()->getRegInfo(); | 
|  | 12176 | MachineBasicBlock::iterator MBBI = Entry->begin(); | 
|  | 12177 | for (const MCPhysReg *I = IStart; *I; ++I) { | 
|  | 12178 | const TargetRegisterClass *RC = nullptr; | 
|  | 12179 | if (PPC::G8RCRegClass.contains(*I)) | 
|  | 12180 | RC = &PPC::G8RCRegClass; | 
|  | 12181 | else if (PPC::F8RCRegClass.contains(*I)) | 
|  | 12182 | RC = &PPC::F8RCRegClass; | 
|  | 12183 | else if (PPC::CRRCRegClass.contains(*I)) | 
|  | 12184 | RC = &PPC::CRRCRegClass; | 
|  | 12185 | else if (PPC::VRRCRegClass.contains(*I)) | 
|  | 12186 | RC = &PPC::VRRCRegClass; | 
|  | 12187 | else | 
|  | 12188 | llvm_unreachable("Unexpected register class in CSRsViaCopy!"); | 
|  | 12189 |  | 
|  | 12190 | unsigned NewVR = MRI->createVirtualRegister(RC); | 
|  | 12191 | // Create copy from CSR to a virtual register. | 
|  | 12192 | // FIXME: this currently does not emit CFI pseudo-instructions, it works | 
|  | 12193 | // fine for CXX_FAST_TLS since the C++-style TLS access functions should be | 
|  | 12194 | // nounwind. If we want to generalize this later, we may need to emit | 
|  | 12195 | // CFI pseudo-instructions. | 
|  | 12196 | assert(Entry->getParent()->getFunction()->hasFnAttribute( | 
|  | 12197 | Attribute::NoUnwind) && | 
|  | 12198 | "Function should be nounwind in insertCopiesSplitCSR!"); | 
|  | 12199 | Entry->addLiveIn(*I); | 
|  | 12200 | BuildMI(*Entry, MBBI, DebugLoc(), TII->get(TargetOpcode::COPY), NewVR) | 
|  | 12201 | .addReg(*I); | 
|  | 12202 |  | 
|  | 12203 | // Insert the copy-back instructions right before the terminator | 
|  | 12204 | for (auto *Exit : Exits) | 
|  | 12205 | BuildMI(*Exit, Exit->getFirstTerminator(), DebugLoc(), | 
|  | 12206 | TII->get(TargetOpcode::COPY), *I) | 
|  | 12207 | .addReg(NewVR); | 
|  | 12208 | } | 
|  | 12209 | } | 
| Tim Shen | a1d8bc5 | 2016-04-19 20:14:52 +0000 | [diff] [blame] | 12210 |  | 
|  | 12211 | // Override to enable LOAD_STACK_GUARD lowering on Linux. | 
|  | 12212 | bool PPCTargetLowering::useLoadStackGuardNode() const { | 
|  | 12213 | if (!Subtarget.isTargetLinux()) | 
|  | 12214 | return TargetLowering::useLoadStackGuardNode(); | 
|  | 12215 | return true; | 
|  | 12216 | } | 
|  | 12217 |  | 
|  | 12218 | // Override to disable global variable loading on Linux. | 
|  | 12219 | void PPCTargetLowering::insertSSPDeclarations(Module &M) const { | 
|  | 12220 | if (!Subtarget.isTargetLinux()) | 
|  | 12221 | return TargetLowering::insertSSPDeclarations(M); | 
|  | 12222 | } |