Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 1 | //===-- AutoUpgrade.cpp - Implement auto-upgrade helper functions ---------===// |
| 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. |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the auto-upgrade helper functions |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/AutoUpgrade.h" |
Anders Carlsson | f924f34 | 2007-12-14 06:38:54 +0000 | [diff] [blame] | 15 | #include "llvm/Constants.h" |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 16 | #include "llvm/Function.h" |
Owen Anderson | 155dccd8 | 2009-07-07 23:43:39 +0000 | [diff] [blame] | 17 | #include "llvm/LLVMContext.h" |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 18 | #include "llvm/Module.h" |
Devang Patel | 80ae349 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 19 | #include "llvm/IntrinsicInst.h" |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/SmallVector.h" |
Gabor Greif | e540653 | 2010-06-23 08:45:32 +0000 | [diff] [blame] | 21 | #include "llvm/Support/CallSite.h" |
Torok Edwin | 56d0659 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 22 | #include "llvm/Support/ErrorHandling.h" |
Eric Christopher | 64831c6 | 2010-04-20 00:59:54 +0000 | [diff] [blame] | 23 | #include "llvm/Support/IRBuilder.h" |
Anton Korobeynikov | 579f071 | 2008-02-20 11:08:44 +0000 | [diff] [blame] | 24 | #include <cstring> |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 25 | using namespace llvm; |
| 26 | |
| 27 | |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 28 | static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) { |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 29 | assert(F && "Illegal to upgrade a non-existent Function."); |
| 30 | |
| 31 | // Get the Function's name. |
| 32 | const std::string& Name = F->getName(); |
| 33 | |
| 34 | // Convenience |
| 35 | const FunctionType *FTy = F->getFunctionType(); |
| 36 | |
| 37 | // Quickly eliminate it, if it's not a candidate. |
| 38 | if (Name.length() <= 8 || Name[0] != 'l' || Name[1] != 'l' || |
| 39 | Name[2] != 'v' || Name[3] != 'm' || Name[4] != '.') |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 40 | return false; |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 41 | |
| 42 | Module *M = F->getParent(); |
| 43 | switch (Name[5]) { |
| 44 | default: break; |
Mon P Wang | 6a49037 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 45 | case 'a': |
Mon P Wang | 2c839d4 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 46 | // This upgrades the llvm.atomic.lcs, llvm.atomic.las, llvm.atomic.lss, |
| 47 | // and atomics with default address spaces to their new names to their new |
| 48 | // function name (e.g. llvm.atomic.add.i32 => llvm.atomic.add.i32.p0i32) |
| 49 | if (Name.compare(5,7,"atomic.",7) == 0) { |
Mon P Wang | 6a49037 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 50 | if (Name.compare(12,3,"lcs",3) == 0) { |
| 51 | std::string::size_type delim = Name.find('.',12); |
Mon P Wang | 2c839d4 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 52 | F->setName("llvm.atomic.cmp.swap" + Name.substr(delim) + |
| 53 | ".p0" + Name.substr(delim+1)); |
Mon P Wang | 6a49037 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 54 | NewFn = F; |
| 55 | return true; |
| 56 | } |
| 57 | else if (Name.compare(12,3,"las",3) == 0) { |
| 58 | std::string::size_type delim = Name.find('.',12); |
Mon P Wang | 2c839d4 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 59 | F->setName("llvm.atomic.load.add"+Name.substr(delim) |
| 60 | + ".p0" + Name.substr(delim+1)); |
Mon P Wang | 6a49037 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 61 | NewFn = F; |
| 62 | return true; |
| 63 | } |
| 64 | else if (Name.compare(12,3,"lss",3) == 0) { |
| 65 | std::string::size_type delim = Name.find('.',12); |
Mon P Wang | 2c839d4 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 66 | F->setName("llvm.atomic.load.sub"+Name.substr(delim) |
| 67 | + ".p0" + Name.substr(delim+1)); |
| 68 | NewFn = F; |
| 69 | return true; |
| 70 | } |
| 71 | else if (Name.rfind(".p") == std::string::npos) { |
| 72 | // We don't have an address space qualifier so this has be upgraded |
| 73 | // to the new name. Copy the type name at the end of the intrinsic |
| 74 | // and add to it |
| 75 | std::string::size_type delim = Name.find_last_of('.'); |
| 76 | assert(delim != std::string::npos && "can not find type"); |
| 77 | F->setName(Name + ".p0" + Name.substr(delim+1)); |
Mon P Wang | 6a49037 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 78 | NewFn = F; |
| 79 | return true; |
| 80 | } |
Bob Wilson | 9a511c0 | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 81 | } else if (Name.compare(5, 9, "arm.neon.", 9) == 0) { |
Bob Wilson | d0c0548 | 2010-08-29 05:57:34 +0000 | [diff] [blame] | 82 | if (((Name.compare(14, 5, "vmovl", 5) == 0 || |
| 83 | Name.compare(14, 5, "vaddl", 5) == 0 || |
Bob Wilson | f65c9ef | 2010-09-03 01:35:08 +0000 | [diff] [blame] | 84 | Name.compare(14, 5, "vsubl", 5) == 0 || |
| 85 | Name.compare(14, 5, "vaddw", 5) == 0 || |
| 86 | Name.compare(14, 5, "vsubw", 5) == 0 || |
| 87 | Name.compare(14, 5, "vmull", 5) == 0 || |
Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 88 | Name.compare(14, 5, "vmlal", 5) == 0 || |
Bob Wilson | f65c9ef | 2010-09-03 01:35:08 +0000 | [diff] [blame] | 89 | Name.compare(14, 5, "vmlsl", 5) == 0 || |
| 90 | Name.compare(14, 5, "vabdl", 5) == 0 || |
| 91 | Name.compare(14, 5, "vabal", 5) == 0) && |
Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 92 | (Name.compare(19, 2, "s.", 2) == 0 || |
| 93 | Name.compare(19, 2, "u.", 2) == 0)) || |
| 94 | |
Bob Wilson | f65c9ef | 2010-09-03 01:35:08 +0000 | [diff] [blame] | 95 | (Name.compare(14, 4, "vaba", 4) == 0 && |
| 96 | (Name.compare(18, 2, "s.", 2) == 0 || |
| 97 | Name.compare(18, 2, "u.", 2) == 0)) || |
| 98 | |
Bob Wilson | 4cd8a12 | 2010-08-30 20:02:30 +0000 | [diff] [blame] | 99 | (Name.compare(14, 6, "vmovn.", 6) == 0)) { |
Bob Wilson | d0c0548 | 2010-08-29 05:57:34 +0000 | [diff] [blame] | 100 | |
Bob Wilson | 9a511c0 | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 101 | // Calls to these are transformed into IR without intrinsics. |
| 102 | NewFn = 0; |
| 103 | return true; |
| 104 | } |
Bob Wilson | edf722a | 2010-08-27 17:13:24 +0000 | [diff] [blame] | 105 | // Old versions of NEON ld/st intrinsics are missing alignment arguments. |
| 106 | bool isVLd = (Name.compare(14, 3, "vld", 3) == 0); |
| 107 | bool isVSt = (Name.compare(14, 3, "vst", 3) == 0); |
| 108 | if (isVLd || isVSt) { |
| 109 | unsigned NumVecs = Name.at(17) - '0'; |
| 110 | if (NumVecs == 0 || NumVecs > 4) |
| 111 | return false; |
| 112 | bool isLaneOp = (Name.compare(18, 5, "lane.", 5) == 0); |
| 113 | if (!isLaneOp && Name.at(18) != '.') |
| 114 | return false; |
| 115 | unsigned ExpectedArgs = 2; // for the address and alignment |
| 116 | if (isVSt || isLaneOp) |
| 117 | ExpectedArgs += NumVecs; |
| 118 | if (isLaneOp) |
| 119 | ExpectedArgs += 1; // for the lane number |
| 120 | unsigned NumP = FTy->getNumParams(); |
| 121 | if (NumP != ExpectedArgs - 1) |
| 122 | return false; |
| 123 | |
| 124 | // Change the name of the old (bad) intrinsic, because |
| 125 | // its type is incorrect, but we cannot overload that name. |
| 126 | F->setName(""); |
| 127 | |
| 128 | // One argument is missing: add the alignment argument. |
| 129 | std::vector<const Type*> NewParams; |
| 130 | for (unsigned p = 0; p < NumP; ++p) |
| 131 | NewParams.push_back(FTy->getParamType(p)); |
| 132 | NewParams.push_back(Type::getInt32Ty(F->getContext())); |
| 133 | FunctionType *NewFTy = FunctionType::get(FTy->getReturnType(), |
| 134 | NewParams, false); |
| 135 | NewFn = cast<Function>(M->getOrInsertFunction(Name, NewFTy)); |
| 136 | return true; |
| 137 | } |
Mon P Wang | 6a49037 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 138 | } |
| 139 | break; |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 140 | case 'b': |
| 141 | // This upgrades the name of the llvm.bswap intrinsic function to only use |
| 142 | // a single type name for overloading. We only care about the old format |
| 143 | // 'llvm.bswap.i*.i*', so check for 'bswap.' and then for there being |
| 144 | // a '.' after 'bswap.' |
| 145 | if (Name.compare(5,6,"bswap.",6) == 0) { |
| 146 | std::string::size_type delim = Name.find('.',11); |
| 147 | |
| 148 | if (delim != std::string::npos) { |
| 149 | // Construct the new name as 'llvm.bswap' + '.i*' |
| 150 | F->setName(Name.substr(0,10)+Name.substr(delim)); |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 151 | NewFn = F; |
| 152 | return true; |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | break; |
| 156 | |
| 157 | case 'c': |
| 158 | // We only want to fix the 'llvm.ct*' intrinsics which do not have the |
| 159 | // correct return type, so we check for the name, and then check if the |
| 160 | // return type does not match the parameter type. |
| 161 | if ( (Name.compare(5,5,"ctpop",5) == 0 || |
| 162 | Name.compare(5,4,"ctlz",4) == 0 || |
| 163 | Name.compare(5,4,"cttz",4) == 0) && |
| 164 | FTy->getReturnType() != FTy->getParamType(0)) { |
| 165 | // We first need to change the name of the old (bad) intrinsic, because |
| 166 | // its type is incorrect, but we cannot overload that name. We |
| 167 | // arbitrarily unique it here allowing us to construct a correctly named |
| 168 | // and typed function below. |
| 169 | F->setName(""); |
| 170 | |
| 171 | // Now construct the new intrinsic with the correct name and type. We |
| 172 | // leave the old function around in order to query its type, whatever it |
| 173 | // may be, and correctly convert up to the new type. |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 174 | NewFn = cast<Function>(M->getOrInsertFunction(Name, |
| 175 | FTy->getParamType(0), |
| 176 | FTy->getParamType(0), |
| 177 | (Type *)0)); |
| 178 | return true; |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 179 | } |
| 180 | break; |
| 181 | |
Duncan Sands | 8e6ccb6 | 2009-10-14 16:11:37 +0000 | [diff] [blame] | 182 | case 'e': |
| 183 | // The old llvm.eh.selector.i32 is equivalent to the new llvm.eh.selector. |
| 184 | if (Name.compare("llvm.eh.selector.i32") == 0) { |
| 185 | F->setName("llvm.eh.selector"); |
| 186 | NewFn = F; |
| 187 | return true; |
| 188 | } |
| 189 | // The old llvm.eh.typeid.for.i32 is equivalent to llvm.eh.typeid.for. |
| 190 | if (Name.compare("llvm.eh.typeid.for.i32") == 0) { |
| 191 | F->setName("llvm.eh.typeid.for"); |
| 192 | NewFn = F; |
| 193 | return true; |
| 194 | } |
| 195 | // Convert the old llvm.eh.selector.i64 to a call to llvm.eh.selector. |
| 196 | if (Name.compare("llvm.eh.selector.i64") == 0) { |
| 197 | NewFn = Intrinsic::getDeclaration(M, Intrinsic::eh_selector); |
| 198 | return true; |
| 199 | } |
| 200 | // Convert the old llvm.eh.typeid.for.i64 to a call to llvm.eh.typeid.for. |
| 201 | if (Name.compare("llvm.eh.typeid.for.i64") == 0) { |
| 202 | NewFn = Intrinsic::getDeclaration(M, Intrinsic::eh_typeid_for); |
| 203 | return true; |
| 204 | } |
| 205 | break; |
| 206 | |
Mon P Wang | c576ee9 | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 207 | case 'm': { |
| 208 | // This upgrades the llvm.memcpy, llvm.memmove, and llvm.memset to the |
| 209 | // new format that allows overloading the pointer for different address |
| 210 | // space (e.g., llvm.memcpy.i16 => llvm.memcpy.p0i8.p0i8.i16) |
| 211 | const char* NewFnName = NULL; |
| 212 | if (Name.compare(5,8,"memcpy.i",8) == 0) { |
| 213 | if (Name[13] == '8') |
| 214 | NewFnName = "llvm.memcpy.p0i8.p0i8.i8"; |
| 215 | else if (Name.compare(13,2,"16") == 0) |
| 216 | NewFnName = "llvm.memcpy.p0i8.p0i8.i16"; |
| 217 | else if (Name.compare(13,2,"32") == 0) |
| 218 | NewFnName = "llvm.memcpy.p0i8.p0i8.i32"; |
| 219 | else if (Name.compare(13,2,"64") == 0) |
| 220 | NewFnName = "llvm.memcpy.p0i8.p0i8.i64"; |
| 221 | } else if (Name.compare(5,9,"memmove.i",9) == 0) { |
| 222 | if (Name[14] == '8') |
| 223 | NewFnName = "llvm.memmove.p0i8.p0i8.i8"; |
| 224 | else if (Name.compare(14,2,"16") == 0) |
| 225 | NewFnName = "llvm.memmove.p0i8.p0i8.i16"; |
| 226 | else if (Name.compare(14,2,"32") == 0) |
| 227 | NewFnName = "llvm.memmove.p0i8.p0i8.i32"; |
| 228 | else if (Name.compare(14,2,"64") == 0) |
| 229 | NewFnName = "llvm.memmove.p0i8.p0i8.i64"; |
| 230 | } |
| 231 | else if (Name.compare(5,8,"memset.i",8) == 0) { |
| 232 | if (Name[13] == '8') |
| 233 | NewFnName = "llvm.memset.p0i8.i8"; |
| 234 | else if (Name.compare(13,2,"16") == 0) |
| 235 | NewFnName = "llvm.memset.p0i8.i16"; |
| 236 | else if (Name.compare(13,2,"32") == 0) |
| 237 | NewFnName = "llvm.memset.p0i8.i32"; |
| 238 | else if (Name.compare(13,2,"64") == 0) |
| 239 | NewFnName = "llvm.memset.p0i8.i64"; |
| 240 | } |
| 241 | if (NewFnName) { |
Mon P Wang | c576ee9 | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 242 | NewFn = cast<Function>(M->getOrInsertFunction(NewFnName, |
| 243 | FTy->getReturnType(), |
| 244 | FTy->getParamType(0), |
| 245 | FTy->getParamType(1), |
| 246 | FTy->getParamType(2), |
| 247 | FTy->getParamType(3), |
| 248 | Type::getInt1Ty(F->getContext()), |
| 249 | (Type *)0)); |
| 250 | return true; |
| 251 | } |
| 252 | break; |
| 253 | } |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 254 | case 'p': |
| 255 | // This upgrades the llvm.part.select overloaded intrinsic names to only |
| 256 | // use one type specifier in the name. We only care about the old format |
| 257 | // 'llvm.part.select.i*.i*', and solve as above with bswap. |
| 258 | if (Name.compare(5,12,"part.select.",12) == 0) { |
| 259 | std::string::size_type delim = Name.find('.',17); |
| 260 | |
| 261 | if (delim != std::string::npos) { |
| 262 | // Construct a new name as 'llvm.part.select' + '.i*' |
| 263 | F->setName(Name.substr(0,16)+Name.substr(delim)); |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 264 | NewFn = F; |
| 265 | return true; |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 266 | } |
| 267 | break; |
| 268 | } |
| 269 | |
| 270 | // This upgrades the llvm.part.set intrinsics similarly as above, however |
| 271 | // we care about 'llvm.part.set.i*.i*.i*', but only the first two types |
| 272 | // must match. There is an additional type specifier after these two |
| 273 | // matching types that we must retain when upgrading. Thus, we require |
| 274 | // finding 2 periods, not just one, after the intrinsic name. |
| 275 | if (Name.compare(5,9,"part.set.",9) == 0) { |
| 276 | std::string::size_type delim = Name.find('.',14); |
| 277 | |
| 278 | if (delim != std::string::npos && |
| 279 | Name.find('.',delim+1) != std::string::npos) { |
| 280 | // Construct a new name as 'llvm.part.select' + '.i*.i*' |
| 281 | F->setName(Name.substr(0,13)+Name.substr(delim)); |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 282 | NewFn = F; |
| 283 | return true; |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 284 | } |
| 285 | break; |
| 286 | } |
| 287 | |
| 288 | break; |
Anders Carlsson | f924f34 | 2007-12-14 06:38:54 +0000 | [diff] [blame] | 289 | case 'x': |
| 290 | // This fixes all MMX shift intrinsic instructions to take a |
| 291 | // v1i64 instead of a v2i32 as the second parameter. |
| 292 | if (Name.compare(5,10,"x86.mmx.ps",10) == 0 && |
| 293 | (Name.compare(13,4,"psll", 4) == 0 || |
| 294 | Name.compare(13,4,"psra", 4) == 0 || |
Evan Cheng | cdf22f2 | 2008-05-03 00:52:09 +0000 | [diff] [blame] | 295 | Name.compare(13,4,"psrl", 4) == 0) && Name[17] != 'i') { |
Anders Carlsson | f924f34 | 2007-12-14 06:38:54 +0000 | [diff] [blame] | 296 | |
Owen Anderson | 155dccd8 | 2009-07-07 23:43:39 +0000 | [diff] [blame] | 297 | const llvm::Type *VT = |
Owen Anderson | 55f1c09 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 298 | VectorType::get(IntegerType::get(FTy->getContext(), 64), 1); |
Anders Carlsson | f924f34 | 2007-12-14 06:38:54 +0000 | [diff] [blame] | 299 | |
| 300 | // We don't have to do anything if the parameter already has |
| 301 | // the correct type. |
| 302 | if (FTy->getParamType(1) == VT) |
| 303 | break; |
| 304 | |
| 305 | // We first need to change the name of the old (bad) intrinsic, because |
| 306 | // its type is incorrect, but we cannot overload that name. We |
| 307 | // arbitrarily unique it here allowing us to construct a correctly named |
| 308 | // and typed function below. |
| 309 | F->setName(""); |
| 310 | |
| 311 | assert(FTy->getNumParams() == 2 && "MMX shift intrinsics take 2 args!"); |
| 312 | |
| 313 | // Now construct the new intrinsic with the correct name and type. We |
| 314 | // leave the old function around in order to query its type, whatever it |
| 315 | // may be, and correctly convert up to the new type. |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 316 | NewFn = cast<Function>(M->getOrInsertFunction(Name, |
| 317 | FTy->getReturnType(), |
| 318 | FTy->getParamType(0), |
| 319 | VT, |
| 320 | (Type *)0)); |
| 321 | return true; |
Evan Cheng | 5065932 | 2008-05-24 00:08:39 +0000 | [diff] [blame] | 322 | } else if (Name.compare(5,17,"x86.sse2.loadh.pd",17) == 0 || |
| 323 | Name.compare(5,17,"x86.sse2.loadl.pd",17) == 0 || |
Evan Cheng | 2146270c | 2008-05-24 02:14:05 +0000 | [diff] [blame] | 324 | Name.compare(5,16,"x86.sse2.movl.dq",16) == 0 || |
| 325 | Name.compare(5,15,"x86.sse2.movs.d",15) == 0 || |
| 326 | Name.compare(5,16,"x86.sse2.shuf.pd",16) == 0 || |
| 327 | Name.compare(5,18,"x86.sse2.unpckh.pd",18) == 0 || |
Evan Cheng | 91a2e56 | 2008-05-24 02:56:30 +0000 | [diff] [blame] | 328 | Name.compare(5,18,"x86.sse2.unpckl.pd",18) == 0 || |
| 329 | Name.compare(5,20,"x86.sse2.punpckh.qdq",20) == 0 || |
| 330 | Name.compare(5,20,"x86.sse2.punpckl.qdq",20) == 0) { |
Evan Cheng | 5065932 | 2008-05-24 00:08:39 +0000 | [diff] [blame] | 331 | // Calls to these intrinsics are transformed into ShuffleVector's. |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 332 | NewFn = 0; |
| 333 | return true; |
Eric Christopher | 6ad8167 | 2010-03-30 18:49:01 +0000 | [diff] [blame] | 334 | } else if (Name.compare(5, 16, "x86.sse41.pmulld", 16) == 0) { |
| 335 | // Calls to these intrinsics are transformed into vector multiplies. |
| 336 | NewFn = 0; |
| 337 | return true; |
Eric Christopher | 64831c6 | 2010-04-20 00:59:54 +0000 | [diff] [blame] | 338 | } else if (Name.compare(5, 18, "x86.ssse3.palign.r", 18) == 0 || |
| 339 | Name.compare(5, 22, "x86.ssse3.palign.r.128", 22) == 0) { |
| 340 | // Calls to these intrinsics are transformed into vector shuffles, shifts, |
| 341 | // or 0. |
| 342 | NewFn = 0; |
| 343 | return true; |
Anders Carlsson | f924f34 | 2007-12-14 06:38:54 +0000 | [diff] [blame] | 344 | } |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 345 | |
Anders Carlsson | f924f34 | 2007-12-14 06:38:54 +0000 | [diff] [blame] | 346 | break; |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | // This may not belong here. This function is effectively being overloaded |
| 350 | // to both detect an intrinsic which needs upgrading, and to provide the |
| 351 | // upgraded form of the intrinsic. We should perhaps have two separate |
| 352 | // functions for this. |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 353 | return false; |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 356 | bool llvm::UpgradeIntrinsicFunction(Function *F, Function *&NewFn) { |
| 357 | NewFn = 0; |
| 358 | bool Upgraded = UpgradeIntrinsicFunction1(F, NewFn); |
Duncan Sands | 38ef3a8 | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 359 | |
| 360 | // Upgrade intrinsic attributes. This does not change the function. |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 361 | if (NewFn) |
| 362 | F = NewFn; |
Dale Johannesen | b842d52 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 363 | if (unsigned id = F->getIntrinsicID()) |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 364 | F->setAttributes(Intrinsic::getAttributes((Intrinsic::ID)id)); |
Duncan Sands | 38ef3a8 | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 365 | return Upgraded; |
| 366 | } |
| 367 | |
Bill Wendling | e26fffc | 2010-09-10 18:51:56 +0000 | [diff] [blame] | 368 | bool llvm::UpgradeGlobalVariable(GlobalVariable *GV) { |
| 369 | const std::string &Name = GV->getName(); |
| 370 | |
Bill Wendling | 6a57e24 | 2010-09-10 19:06:58 +0000 | [diff] [blame] | 371 | // Early exit with simple tests. |
| 372 | if (Name.length() != 24 || Name[0] != '.' || Name[1] != 'l' || |
| 373 | Name[3] != 'l' || Name[4] != 'v' || Name[5] != 'm' || Name[6] != '.') |
| 374 | return false; |
| 375 | |
| 376 | // We are only upgrading one symbol here. |
Bill Wendling | e26fffc | 2010-09-10 18:51:56 +0000 | [diff] [blame] | 377 | if (Name == ".llvm.eh.catch.all.value") { |
| 378 | GV->setName("llvm.eh.catch.all.value"); |
| 379 | return true; |
| 380 | } |
| 381 | |
| 382 | return false; |
| 383 | } |
| 384 | |
Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 385 | /// ExtendNEONArgs - For NEON "long" and "wide" operations, where the results |
| 386 | /// have vector elements twice as big as one or both source operands, do the |
| 387 | /// sign- or zero-extension that used to be handled by intrinsics. The |
| 388 | /// extended values are returned via V0 and V1. |
| 389 | static void ExtendNEONArgs(CallInst *CI, Value *Arg0, Value *Arg1, |
| 390 | Value *&V0, Value *&V1) { |
| 391 | Function *F = CI->getCalledFunction(); |
| 392 | const std::string& Name = F->getName(); |
| 393 | bool isLong = (Name.at(18) == 'l'); |
| 394 | bool isSigned = (Name.at(19) == 's'); |
| 395 | |
| 396 | if (isSigned) { |
| 397 | if (isLong) |
| 398 | V0 = new SExtInst(Arg0, CI->getType(), "", CI); |
| 399 | else |
| 400 | V0 = Arg0; |
| 401 | V1 = new SExtInst(Arg1, CI->getType(), "", CI); |
| 402 | } else { |
| 403 | if (isLong) |
| 404 | V0 = new ZExtInst(Arg0, CI->getType(), "", CI); |
| 405 | else |
| 406 | V0 = Arg0; |
| 407 | V1 = new ZExtInst(Arg1, CI->getType(), "", CI); |
| 408 | } |
| 409 | } |
| 410 | |
Bob Wilson | f65c9ef | 2010-09-03 01:35:08 +0000 | [diff] [blame] | 411 | /// CallVABD - As part of expanding a call to one of the old NEON vabdl, vaba, |
| 412 | /// or vabal intrinsics, construct a call to a vabd intrinsic. Examine the |
| 413 | /// name of the old intrinsic to determine whether to use a signed or unsigned |
| 414 | /// vabd intrinsic. Get the type from the old call instruction, adjusted for |
| 415 | /// half-size vector elements if the old intrinsic was vabdl or vabal. |
| 416 | static Instruction *CallVABD(CallInst *CI, Value *Arg0, Value *Arg1) { |
| 417 | Function *F = CI->getCalledFunction(); |
| 418 | const std::string& Name = F->getName(); |
| 419 | bool isLong = (Name.at(18) == 'l'); |
| 420 | bool isSigned = (Name.at(isLong ? 19 : 18) == 's'); |
| 421 | |
| 422 | Intrinsic::ID intID; |
| 423 | if (isSigned) |
| 424 | intID = Intrinsic::arm_neon_vabds; |
| 425 | else |
| 426 | intID = Intrinsic::arm_neon_vabdu; |
| 427 | |
| 428 | const Type *Ty = CI->getType(); |
| 429 | if (isLong) |
| 430 | Ty = VectorType::getTruncatedElementVectorType(cast<const VectorType>(Ty)); |
| 431 | |
| 432 | Function *VABD = Intrinsic::getDeclaration(F->getParent(), intID, &Ty, 1); |
| 433 | Value *Operands[2]; |
| 434 | Operands[0] = Arg0; |
| 435 | Operands[1] = Arg1; |
| 436 | return CallInst::Create(VABD, Operands, Operands+2, |
| 437 | "upgraded."+CI->getName(), CI); |
| 438 | } |
| 439 | |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 440 | // UpgradeIntrinsicCall - Upgrade a call to an old intrinsic to be a call the |
| 441 | // upgraded intrinsic. All argument and return casting must be provided in |
| 442 | // order to seamlessly integrate with existing context. |
| 443 | void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) { |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 444 | Function *F = CI->getCalledFunction(); |
Owen Anderson | 55f1c09 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 445 | LLVMContext &C = CI->getContext(); |
Gabor Greif | e540653 | 2010-06-23 08:45:32 +0000 | [diff] [blame] | 446 | ImmutableCallSite CS(CI); |
| 447 | |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 448 | assert(F && "CallInst has no function associated with it."); |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 449 | |
| 450 | if (!NewFn) { |
Bob Wilson | 9a511c0 | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 451 | // Get the Function's name. |
| 452 | const std::string& Name = F->getName(); |
| 453 | |
| 454 | // Upgrade ARM NEON intrinsics. |
| 455 | if (Name.compare(5, 9, "arm.neon.", 9) == 0) { |
| 456 | Instruction *NewI; |
Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 457 | Value *V0, *V1; |
Bob Wilson | 9a511c0 | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 458 | if (Name.compare(14, 7, "vmovls.", 7) == 0) { |
| 459 | NewI = new SExtInst(CI->getArgOperand(0), CI->getType(), |
| 460 | "upgraded." + CI->getName(), CI); |
| 461 | } else if (Name.compare(14, 7, "vmovlu.", 7) == 0) { |
| 462 | NewI = new ZExtInst(CI->getArgOperand(0), CI->getType(), |
| 463 | "upgraded." + CI->getName(), CI); |
Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 464 | } else if (Name.compare(14, 4, "vadd", 4) == 0) { |
| 465 | ExtendNEONArgs(CI, CI->getArgOperand(0), CI->getArgOperand(1), V0, V1); |
| 466 | NewI = BinaryOperator::CreateAdd(V0, V1, "upgraded."+CI->getName(), CI); |
| 467 | } else if (Name.compare(14, 4, "vsub", 4) == 0) { |
| 468 | ExtendNEONArgs(CI, CI->getArgOperand(0), CI->getArgOperand(1), V0, V1); |
| 469 | NewI = BinaryOperator::CreateSub(V0, V1,"upgraded."+CI->getName(),CI); |
| 470 | } else if (Name.compare(14, 4, "vmul", 4) == 0) { |
| 471 | ExtendNEONArgs(CI, CI->getArgOperand(0), CI->getArgOperand(1), V0, V1); |
| 472 | NewI = BinaryOperator::CreateMul(V0, V1,"upgraded."+CI->getName(),CI); |
| 473 | } else if (Name.compare(14, 4, "vmla", 4) == 0) { |
| 474 | ExtendNEONArgs(CI, CI->getArgOperand(1), CI->getArgOperand(2), V0, V1); |
| 475 | Instruction *MulI = BinaryOperator::CreateMul(V0, V1, "", CI); |
| 476 | NewI = BinaryOperator::CreateAdd(CI->getArgOperand(0), MulI, |
| 477 | "upgraded."+CI->getName(), CI); |
| 478 | } else if (Name.compare(14, 4, "vmls", 4) == 0) { |
| 479 | ExtendNEONArgs(CI, CI->getArgOperand(1), CI->getArgOperand(2), V0, V1); |
| 480 | Instruction *MulI = BinaryOperator::CreateMul(V0, V1, "", CI); |
| 481 | NewI = BinaryOperator::CreateSub(CI->getArgOperand(0), MulI, |
| 482 | "upgraded."+CI->getName(), CI); |
Bob Wilson | f65c9ef | 2010-09-03 01:35:08 +0000 | [diff] [blame] | 483 | } else if (Name.compare(14, 4, "vabd", 4) == 0) { |
| 484 | NewI = CallVABD(CI, CI->getArgOperand(0), CI->getArgOperand(1)); |
| 485 | NewI = new ZExtInst(NewI, CI->getType(), "upgraded."+CI->getName(), CI); |
| 486 | } else if (Name.compare(14, 4, "vaba", 4) == 0) { |
| 487 | NewI = CallVABD(CI, CI->getArgOperand(1), CI->getArgOperand(2)); |
| 488 | if (Name.at(18) == 'l') |
| 489 | NewI = new ZExtInst(NewI, CI->getType(), "", CI); |
| 490 | NewI = BinaryOperator::CreateAdd(CI->getArgOperand(0), NewI, |
| 491 | "upgraded."+CI->getName(), CI); |
Bob Wilson | 4cd8a12 | 2010-08-30 20:02:30 +0000 | [diff] [blame] | 492 | } else if (Name.compare(14, 6, "vmovn.", 6) == 0) { |
| 493 | NewI = new TruncInst(CI->getArgOperand(0), CI->getType(), |
| 494 | "upgraded." + CI->getName(), CI); |
Bob Wilson | 9a511c0 | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 495 | } else { |
| 496 | llvm_unreachable("Unknown arm.neon function for CallInst upgrade."); |
| 497 | } |
| 498 | // Replace any uses of the old CallInst. |
| 499 | if (!CI->use_empty()) |
| 500 | CI->replaceAllUsesWith(NewI); |
| 501 | CI->eraseFromParent(); |
| 502 | return; |
| 503 | } |
| 504 | |
Evan Cheng | 5065932 | 2008-05-24 00:08:39 +0000 | [diff] [blame] | 505 | bool isLoadH = false, isLoadL = false, isMovL = false; |
Evan Cheng | 2146270c | 2008-05-24 02:14:05 +0000 | [diff] [blame] | 506 | bool isMovSD = false, isShufPD = false; |
| 507 | bool isUnpckhPD = false, isUnpcklPD = false; |
Evan Cheng | 91a2e56 | 2008-05-24 02:56:30 +0000 | [diff] [blame] | 508 | bool isPunpckhQPD = false, isPunpcklQPD = false; |
Daniel Dunbar | e03eecb | 2009-07-25 23:55:21 +0000 | [diff] [blame] | 509 | if (F->getName() == "llvm.x86.sse2.loadh.pd") |
Evan Cheng | 5065932 | 2008-05-24 00:08:39 +0000 | [diff] [blame] | 510 | isLoadH = true; |
Daniel Dunbar | e03eecb | 2009-07-25 23:55:21 +0000 | [diff] [blame] | 511 | else if (F->getName() == "llvm.x86.sse2.loadl.pd") |
Evan Cheng | 5065932 | 2008-05-24 00:08:39 +0000 | [diff] [blame] | 512 | isLoadL = true; |
Daniel Dunbar | e03eecb | 2009-07-25 23:55:21 +0000 | [diff] [blame] | 513 | else if (F->getName() == "llvm.x86.sse2.movl.dq") |
Evan Cheng | 5065932 | 2008-05-24 00:08:39 +0000 | [diff] [blame] | 514 | isMovL = true; |
Daniel Dunbar | e03eecb | 2009-07-25 23:55:21 +0000 | [diff] [blame] | 515 | else if (F->getName() == "llvm.x86.sse2.movs.d") |
Evan Cheng | 2146270c | 2008-05-24 02:14:05 +0000 | [diff] [blame] | 516 | isMovSD = true; |
Daniel Dunbar | e03eecb | 2009-07-25 23:55:21 +0000 | [diff] [blame] | 517 | else if (F->getName() == "llvm.x86.sse2.shuf.pd") |
Evan Cheng | 2146270c | 2008-05-24 02:14:05 +0000 | [diff] [blame] | 518 | isShufPD = true; |
Daniel Dunbar | e03eecb | 2009-07-25 23:55:21 +0000 | [diff] [blame] | 519 | else if (F->getName() == "llvm.x86.sse2.unpckh.pd") |
Evan Cheng | 2146270c | 2008-05-24 02:14:05 +0000 | [diff] [blame] | 520 | isUnpckhPD = true; |
Daniel Dunbar | e03eecb | 2009-07-25 23:55:21 +0000 | [diff] [blame] | 521 | else if (F->getName() == "llvm.x86.sse2.unpckl.pd") |
Evan Cheng | 2146270c | 2008-05-24 02:14:05 +0000 | [diff] [blame] | 522 | isUnpcklPD = true; |
Daniel Dunbar | e03eecb | 2009-07-25 23:55:21 +0000 | [diff] [blame] | 523 | else if (F->getName() == "llvm.x86.sse2.punpckh.qdq") |
Evan Cheng | 91a2e56 | 2008-05-24 02:56:30 +0000 | [diff] [blame] | 524 | isPunpckhQPD = true; |
Daniel Dunbar | e03eecb | 2009-07-25 23:55:21 +0000 | [diff] [blame] | 525 | else if (F->getName() == "llvm.x86.sse2.punpckl.qdq") |
Evan Cheng | 91a2e56 | 2008-05-24 02:56:30 +0000 | [diff] [blame] | 526 | isPunpcklQPD = true; |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 527 | |
Evan Cheng | 2146270c | 2008-05-24 02:14:05 +0000 | [diff] [blame] | 528 | if (isLoadH || isLoadL || isMovL || isMovSD || isShufPD || |
Evan Cheng | 91a2e56 | 2008-05-24 02:56:30 +0000 | [diff] [blame] | 529 | isUnpckhPD || isUnpcklPD || isPunpckhQPD || isPunpcklQPD) { |
Evan Cheng | 5065932 | 2008-05-24 00:08:39 +0000 | [diff] [blame] | 530 | std::vector<Constant*> Idxs; |
Gabor Greif | c89d2aa | 2010-06-22 20:40:38 +0000 | [diff] [blame] | 531 | Value *Op0 = CI->getArgOperand(0); |
Evan Cheng | 2146270c | 2008-05-24 02:14:05 +0000 | [diff] [blame] | 532 | ShuffleVectorInst *SI = NULL; |
Evan Cheng | 5065932 | 2008-05-24 00:08:39 +0000 | [diff] [blame] | 533 | if (isLoadH || isLoadL) { |
Owen Anderson | b292b8c | 2009-07-30 23:03:37 +0000 | [diff] [blame] | 534 | Value *Op1 = UndefValue::get(Op0->getType()); |
Gabor Greif | c89d2aa | 2010-06-22 20:40:38 +0000 | [diff] [blame] | 535 | Value *Addr = new BitCastInst(CI->getArgOperand(1), |
Duncan Sands | 9ed7b16 | 2009-10-06 15:40:36 +0000 | [diff] [blame] | 536 | Type::getDoublePtrTy(C), |
Evan Cheng | 5065932 | 2008-05-24 00:08:39 +0000 | [diff] [blame] | 537 | "upgraded.", CI); |
| 538 | Value *Load = new LoadInst(Addr, "upgraded.", false, 8, CI); |
Owen Anderson | 55f1c09 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 539 | Value *Idx = ConstantInt::get(Type::getInt32Ty(C), 0); |
Evan Cheng | 5065932 | 2008-05-24 00:08:39 +0000 | [diff] [blame] | 540 | Op1 = InsertElementInst::Create(Op1, Load, Idx, "upgraded.", CI); |
| 541 | |
| 542 | if (isLoadH) { |
Owen Anderson | 55f1c09 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 543 | Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 0)); |
| 544 | Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 2)); |
Evan Cheng | 5065932 | 2008-05-24 00:08:39 +0000 | [diff] [blame] | 545 | } else { |
Owen Anderson | 55f1c09 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 546 | Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 2)); |
| 547 | Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 1)); |
Evan Cheng | 5065932 | 2008-05-24 00:08:39 +0000 | [diff] [blame] | 548 | } |
Owen Anderson | 4aa3295 | 2009-07-28 21:19:26 +0000 | [diff] [blame] | 549 | Value *Mask = ConstantVector::get(Idxs); |
Evan Cheng | 5065932 | 2008-05-24 00:08:39 +0000 | [diff] [blame] | 550 | SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI); |
Evan Cheng | 2146270c | 2008-05-24 02:14:05 +0000 | [diff] [blame] | 551 | } else if (isMovL) { |
Owen Anderson | 55f1c09 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 552 | Constant *Zero = ConstantInt::get(Type::getInt32Ty(C), 0); |
Evan Cheng | 5065932 | 2008-05-24 00:08:39 +0000 | [diff] [blame] | 553 | Idxs.push_back(Zero); |
| 554 | Idxs.push_back(Zero); |
| 555 | Idxs.push_back(Zero); |
| 556 | Idxs.push_back(Zero); |
Owen Anderson | 4aa3295 | 2009-07-28 21:19:26 +0000 | [diff] [blame] | 557 | Value *ZeroV = ConstantVector::get(Idxs); |
Evan Cheng | 5065932 | 2008-05-24 00:08:39 +0000 | [diff] [blame] | 558 | |
| 559 | Idxs.clear(); |
Owen Anderson | 55f1c09 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 560 | Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 4)); |
| 561 | Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 5)); |
| 562 | Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 2)); |
| 563 | Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 3)); |
Owen Anderson | 4aa3295 | 2009-07-28 21:19:26 +0000 | [diff] [blame] | 564 | Value *Mask = ConstantVector::get(Idxs); |
Evan Cheng | 5065932 | 2008-05-24 00:08:39 +0000 | [diff] [blame] | 565 | SI = new ShuffleVectorInst(ZeroV, Op0, Mask, "upgraded.", CI); |
Evan Cheng | 91a2e56 | 2008-05-24 02:56:30 +0000 | [diff] [blame] | 566 | } else if (isMovSD || |
| 567 | isUnpckhPD || isUnpcklPD || isPunpckhQPD || isPunpcklQPD) { |
Gabor Greif | c89d2aa | 2010-06-22 20:40:38 +0000 | [diff] [blame] | 568 | Value *Op1 = CI->getArgOperand(1); |
Evan Cheng | 2146270c | 2008-05-24 02:14:05 +0000 | [diff] [blame] | 569 | if (isMovSD) { |
Owen Anderson | 55f1c09 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 570 | Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 2)); |
| 571 | Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 1)); |
Evan Cheng | 91a2e56 | 2008-05-24 02:56:30 +0000 | [diff] [blame] | 572 | } else if (isUnpckhPD || isPunpckhQPD) { |
Owen Anderson | 55f1c09 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 573 | Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 1)); |
| 574 | Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 3)); |
Evan Cheng | 2146270c | 2008-05-24 02:14:05 +0000 | [diff] [blame] | 575 | } else { |
Owen Anderson | 55f1c09 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 576 | Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 0)); |
| 577 | Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 2)); |
Evan Cheng | 2146270c | 2008-05-24 02:14:05 +0000 | [diff] [blame] | 578 | } |
Owen Anderson | 4aa3295 | 2009-07-28 21:19:26 +0000 | [diff] [blame] | 579 | Value *Mask = ConstantVector::get(Idxs); |
Evan Cheng | 2146270c | 2008-05-24 02:14:05 +0000 | [diff] [blame] | 580 | SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI); |
| 581 | } else if (isShufPD) { |
Gabor Greif | c89d2aa | 2010-06-22 20:40:38 +0000 | [diff] [blame] | 582 | Value *Op1 = CI->getArgOperand(1); |
Gabor Greif | 3e44ea1 | 2010-07-22 10:37:47 +0000 | [diff] [blame] | 583 | unsigned MaskVal = |
| 584 | cast<ConstantInt>(CI->getArgOperand(2))->getZExtValue(); |
Owen Anderson | 55f1c09 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 585 | Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), MaskVal & 1)); |
| 586 | Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), |
Owen Anderson | 155dccd8 | 2009-07-07 23:43:39 +0000 | [diff] [blame] | 587 | ((MaskVal >> 1) & 1)+2)); |
Owen Anderson | 4aa3295 | 2009-07-28 21:19:26 +0000 | [diff] [blame] | 588 | Value *Mask = ConstantVector::get(Idxs); |
Evan Cheng | 2146270c | 2008-05-24 02:14:05 +0000 | [diff] [blame] | 589 | SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI); |
Evan Cheng | 5065932 | 2008-05-24 00:08:39 +0000 | [diff] [blame] | 590 | } |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 591 | |
Evan Cheng | 2146270c | 2008-05-24 02:14:05 +0000 | [diff] [blame] | 592 | assert(SI && "Unexpected!"); |
| 593 | |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 594 | // Handle any uses of the old CallInst. |
| 595 | if (!CI->use_empty()) |
| 596 | // Replace all uses of the old call with the new cast which has the |
| 597 | // correct type. |
| 598 | CI->replaceAllUsesWith(SI); |
| 599 | |
| 600 | // Clean up the old call now that it has been completely upgraded. |
| 601 | CI->eraseFromParent(); |
Eric Christopher | 6ad8167 | 2010-03-30 18:49:01 +0000 | [diff] [blame] | 602 | } else if (F->getName() == "llvm.x86.sse41.pmulld") { |
| 603 | // Upgrade this set of intrinsics into vector multiplies. |
Gabor Greif | c89d2aa | 2010-06-22 20:40:38 +0000 | [diff] [blame] | 604 | Instruction *Mul = BinaryOperator::CreateMul(CI->getArgOperand(0), |
| 605 | CI->getArgOperand(1), |
Eric Christopher | 6ad8167 | 2010-03-30 18:49:01 +0000 | [diff] [blame] | 606 | CI->getName(), |
| 607 | CI); |
| 608 | // Fix up all the uses with our new multiply. |
| 609 | if (!CI->use_empty()) |
| 610 | CI->replaceAllUsesWith(Mul); |
| 611 | |
| 612 | // Remove upgraded multiply. |
| 613 | CI->eraseFromParent(); |
Eric Christopher | 64831c6 | 2010-04-20 00:59:54 +0000 | [diff] [blame] | 614 | } else if (F->getName() == "llvm.x86.ssse3.palign.r") { |
Gabor Greif | eab748d | 2010-06-29 16:17:26 +0000 | [diff] [blame] | 615 | Value *Op1 = CI->getArgOperand(0); |
| 616 | Value *Op2 = CI->getArgOperand(1); |
| 617 | Value *Op3 = CI->getArgOperand(2); |
Eric Christopher | 64831c6 | 2010-04-20 00:59:54 +0000 | [diff] [blame] | 618 | unsigned shiftVal = cast<ConstantInt>(Op3)->getZExtValue(); |
| 619 | Value *Rep; |
| 620 | IRBuilder<> Builder(C); |
| 621 | Builder.SetInsertPoint(CI->getParent(), CI); |
| 622 | |
| 623 | // If palignr is shifting the pair of input vectors less than 9 bytes, |
| 624 | // emit a shuffle instruction. |
| 625 | if (shiftVal <= 8) { |
| 626 | const Type *IntTy = Type::getInt32Ty(C); |
| 627 | const Type *EltTy = Type::getInt8Ty(C); |
| 628 | const Type *VecTy = VectorType::get(EltTy, 8); |
| 629 | |
| 630 | Op2 = Builder.CreateBitCast(Op2, VecTy); |
| 631 | Op1 = Builder.CreateBitCast(Op1, VecTy); |
| 632 | |
| 633 | llvm::SmallVector<llvm::Constant*, 8> Indices; |
| 634 | for (unsigned i = 0; i != 8; ++i) |
| 635 | Indices.push_back(ConstantInt::get(IntTy, shiftVal + i)); |
| 636 | |
| 637 | Value *SV = ConstantVector::get(Indices.begin(), Indices.size()); |
| 638 | Rep = Builder.CreateShuffleVector(Op2, Op1, SV, "palignr"); |
| 639 | Rep = Builder.CreateBitCast(Rep, F->getReturnType()); |
| 640 | } |
| 641 | |
| 642 | // If palignr is shifting the pair of input vectors more than 8 but less |
| 643 | // than 16 bytes, emit a logical right shift of the destination. |
| 644 | else if (shiftVal < 16) { |
| 645 | // MMX has these as 1 x i64 vectors for some odd optimization reasons. |
| 646 | const Type *EltTy = Type::getInt64Ty(C); |
| 647 | const Type *VecTy = VectorType::get(EltTy, 1); |
| 648 | |
| 649 | Op1 = Builder.CreateBitCast(Op1, VecTy, "cast"); |
| 650 | Op2 = ConstantInt::get(VecTy, (shiftVal-8) * 8); |
| 651 | |
| 652 | // create i32 constant |
| 653 | Function *I = |
| 654 | Intrinsic::getDeclaration(F->getParent(), Intrinsic::x86_mmx_psrl_q); |
| 655 | Rep = Builder.CreateCall2(I, Op1, Op2, "palignr"); |
| 656 | } |
| 657 | |
| 658 | // If palignr is shifting the pair of vectors more than 32 bytes, emit zero. |
| 659 | else { |
| 660 | Rep = Constant::getNullValue(F->getReturnType()); |
| 661 | } |
| 662 | |
| 663 | // Replace any uses with our new instruction. |
| 664 | if (!CI->use_empty()) |
| 665 | CI->replaceAllUsesWith(Rep); |
| 666 | |
| 667 | // Remove upgraded instruction. |
| 668 | CI->eraseFromParent(); |
| 669 | |
| 670 | } else if (F->getName() == "llvm.x86.ssse3.palign.r.128") { |
Gabor Greif | eab748d | 2010-06-29 16:17:26 +0000 | [diff] [blame] | 671 | Value *Op1 = CI->getArgOperand(0); |
| 672 | Value *Op2 = CI->getArgOperand(1); |
| 673 | Value *Op3 = CI->getArgOperand(2); |
Eric Christopher | 64831c6 | 2010-04-20 00:59:54 +0000 | [diff] [blame] | 674 | unsigned shiftVal = cast<ConstantInt>(Op3)->getZExtValue(); |
| 675 | Value *Rep; |
| 676 | IRBuilder<> Builder(C); |
| 677 | Builder.SetInsertPoint(CI->getParent(), CI); |
| 678 | |
| 679 | // If palignr is shifting the pair of input vectors less than 17 bytes, |
| 680 | // emit a shuffle instruction. |
| 681 | if (shiftVal <= 16) { |
| 682 | const Type *IntTy = Type::getInt32Ty(C); |
| 683 | const Type *EltTy = Type::getInt8Ty(C); |
| 684 | const Type *VecTy = VectorType::get(EltTy, 16); |
| 685 | |
| 686 | Op2 = Builder.CreateBitCast(Op2, VecTy); |
| 687 | Op1 = Builder.CreateBitCast(Op1, VecTy); |
| 688 | |
| 689 | llvm::SmallVector<llvm::Constant*, 16> Indices; |
| 690 | for (unsigned i = 0; i != 16; ++i) |
| 691 | Indices.push_back(ConstantInt::get(IntTy, shiftVal + i)); |
| 692 | |
| 693 | Value *SV = ConstantVector::get(Indices.begin(), Indices.size()); |
| 694 | Rep = Builder.CreateShuffleVector(Op2, Op1, SV, "palignr"); |
| 695 | Rep = Builder.CreateBitCast(Rep, F->getReturnType()); |
| 696 | } |
| 697 | |
| 698 | // If palignr is shifting the pair of input vectors more than 16 but less |
| 699 | // than 32 bytes, emit a logical right shift of the destination. |
| 700 | else if (shiftVal < 32) { |
| 701 | const Type *EltTy = Type::getInt64Ty(C); |
| 702 | const Type *VecTy = VectorType::get(EltTy, 2); |
| 703 | const Type *IntTy = Type::getInt32Ty(C); |
| 704 | |
| 705 | Op1 = Builder.CreateBitCast(Op1, VecTy, "cast"); |
| 706 | Op2 = ConstantInt::get(IntTy, (shiftVal-16) * 8); |
| 707 | |
| 708 | // create i32 constant |
| 709 | Function *I = |
| 710 | Intrinsic::getDeclaration(F->getParent(), Intrinsic::x86_sse2_psrl_dq); |
| 711 | Rep = Builder.CreateCall2(I, Op1, Op2, "palignr"); |
| 712 | } |
| 713 | |
| 714 | // If palignr is shifting the pair of vectors more than 32 bytes, emit zero. |
| 715 | else { |
| 716 | Rep = Constant::getNullValue(F->getReturnType()); |
| 717 | } |
| 718 | |
| 719 | // Replace any uses with our new instruction. |
| 720 | if (!CI->use_empty()) |
| 721 | CI->replaceAllUsesWith(Rep); |
| 722 | |
| 723 | // Remove upgraded instruction. |
| 724 | CI->eraseFromParent(); |
| 725 | |
Evan Cheng | a8288f4 | 2007-12-18 01:04:25 +0000 | [diff] [blame] | 726 | } else { |
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 727 | llvm_unreachable("Unknown function for CallInst upgrade."); |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 728 | } |
| 729 | return; |
| 730 | } |
| 731 | |
Gabor Greif | e9ecc68 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 732 | switch (NewFn->getIntrinsicID()) { |
Bob Wilson | f65c9ef | 2010-09-03 01:35:08 +0000 | [diff] [blame] | 733 | default: llvm_unreachable("Unknown function for CallInst upgrade."); |
Bob Wilson | edf722a | 2010-08-27 17:13:24 +0000 | [diff] [blame] | 734 | case Intrinsic::arm_neon_vld1: |
| 735 | case Intrinsic::arm_neon_vld2: |
| 736 | case Intrinsic::arm_neon_vld3: |
| 737 | case Intrinsic::arm_neon_vld4: |
| 738 | case Intrinsic::arm_neon_vst1: |
| 739 | case Intrinsic::arm_neon_vst2: |
| 740 | case Intrinsic::arm_neon_vst3: |
| 741 | case Intrinsic::arm_neon_vst4: |
| 742 | case Intrinsic::arm_neon_vld2lane: |
| 743 | case Intrinsic::arm_neon_vld3lane: |
| 744 | case Intrinsic::arm_neon_vld4lane: |
| 745 | case Intrinsic::arm_neon_vst2lane: |
| 746 | case Intrinsic::arm_neon_vst3lane: |
| 747 | case Intrinsic::arm_neon_vst4lane: { |
| 748 | // Add a default alignment argument of 1. |
| 749 | SmallVector<Value*, 8> Operands(CS.arg_begin(), CS.arg_end()); |
| 750 | Operands.push_back(ConstantInt::get(Type::getInt32Ty(C), 1)); |
| 751 | CallInst *NewCI = CallInst::Create(NewFn, Operands.begin(), Operands.end(), |
| 752 | CI->getName(), CI); |
| 753 | NewCI->setTailCall(CI->isTailCall()); |
| 754 | NewCI->setCallingConv(CI->getCallingConv()); |
| 755 | |
| 756 | // Handle any uses of the old CallInst. |
| 757 | if (!CI->use_empty()) |
| 758 | // Replace all uses of the old call with the new cast which has the |
| 759 | // correct type. |
| 760 | CI->replaceAllUsesWith(NewCI); |
| 761 | |
| 762 | // Clean up the old call now that it has been completely upgraded. |
| 763 | CI->eraseFromParent(); |
| 764 | break; |
| 765 | } |
| 766 | |
Anders Carlsson | f924f34 | 2007-12-14 06:38:54 +0000 | [diff] [blame] | 767 | case Intrinsic::x86_mmx_psll_d: |
| 768 | case Intrinsic::x86_mmx_psll_q: |
| 769 | case Intrinsic::x86_mmx_psll_w: |
| 770 | case Intrinsic::x86_mmx_psra_d: |
| 771 | case Intrinsic::x86_mmx_psra_w: |
| 772 | case Intrinsic::x86_mmx_psrl_d: |
| 773 | case Intrinsic::x86_mmx_psrl_q: |
| 774 | case Intrinsic::x86_mmx_psrl_w: { |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 775 | Value *Operands[2]; |
Anders Carlsson | f924f34 | 2007-12-14 06:38:54 +0000 | [diff] [blame] | 776 | |
Gabor Greif | c89d2aa | 2010-06-22 20:40:38 +0000 | [diff] [blame] | 777 | Operands[0] = CI->getArgOperand(0); |
Anders Carlsson | f924f34 | 2007-12-14 06:38:54 +0000 | [diff] [blame] | 778 | |
| 779 | // Cast the second parameter to the correct type. |
Gabor Greif | c89d2aa | 2010-06-22 20:40:38 +0000 | [diff] [blame] | 780 | BitCastInst *BC = new BitCastInst(CI->getArgOperand(1), |
Anders Carlsson | f924f34 | 2007-12-14 06:38:54 +0000 | [diff] [blame] | 781 | NewFn->getFunctionType()->getParamType(1), |
Evan Cheng | 5065932 | 2008-05-24 00:08:39 +0000 | [diff] [blame] | 782 | "upgraded.", CI); |
Chris Lattner | 8a923e7 | 2008-03-12 17:45:29 +0000 | [diff] [blame] | 783 | Operands[1] = BC; |
Anders Carlsson | f924f34 | 2007-12-14 06:38:54 +0000 | [diff] [blame] | 784 | |
| 785 | // Construct a new CallInst |
Gabor Greif | e9ecc68 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 786 | CallInst *NewCI = CallInst::Create(NewFn, Operands, Operands+2, |
| 787 | "upgraded."+CI->getName(), CI); |
Anders Carlsson | f924f34 | 2007-12-14 06:38:54 +0000 | [diff] [blame] | 788 | NewCI->setTailCall(CI->isTailCall()); |
| 789 | NewCI->setCallingConv(CI->getCallingConv()); |
| 790 | |
| 791 | // Handle any uses of the old CallInst. |
| 792 | if (!CI->use_empty()) |
| 793 | // Replace all uses of the old call with the new cast which has the |
| 794 | // correct type. |
| 795 | CI->replaceAllUsesWith(NewCI); |
| 796 | |
| 797 | // Clean up the old call now that it has been completely upgraded. |
| 798 | CI->eraseFromParent(); |
| 799 | break; |
| 800 | } |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 801 | case Intrinsic::ctlz: |
| 802 | case Intrinsic::ctpop: |
Gabor Greif | e9ecc68 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 803 | case Intrinsic::cttz: { |
Gabor Greif | e540653 | 2010-06-23 08:45:32 +0000 | [diff] [blame] | 804 | // Build a small vector of the original arguments. |
| 805 | SmallVector<Value*, 8> Operands(CS.arg_begin(), CS.arg_end()); |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 806 | |
| 807 | // Construct a new CallInst |
Gabor Greif | e9ecc68 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 808 | CallInst *NewCI = CallInst::Create(NewFn, Operands.begin(), Operands.end(), |
| 809 | "upgraded."+CI->getName(), CI); |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 810 | NewCI->setTailCall(CI->isTailCall()); |
| 811 | NewCI->setCallingConv(CI->getCallingConv()); |
| 812 | |
| 813 | // Handle any uses of the old CallInst. |
| 814 | if (!CI->use_empty()) { |
| 815 | // Check for sign extend parameter attributes on the return values. |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 816 | bool SrcSExt = NewFn->getAttributes().paramHasAttr(0, Attribute::SExt); |
| 817 | bool DestSExt = F->getAttributes().paramHasAttr(0, Attribute::SExt); |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 818 | |
| 819 | // Construct an appropriate cast from the new return type to the old. |
Gabor Greif | e1f6e4b | 2008-05-16 19:29:10 +0000 | [diff] [blame] | 820 | CastInst *RetCast = CastInst::Create( |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 821 | CastInst::getCastOpcode(NewCI, SrcSExt, |
| 822 | F->getReturnType(), |
| 823 | DestSExt), |
| 824 | NewCI, F->getReturnType(), |
| 825 | NewCI->getName(), CI); |
| 826 | NewCI->moveBefore(RetCast); |
| 827 | |
| 828 | // Replace all uses of the old call with the new cast which has the |
| 829 | // correct type. |
| 830 | CI->replaceAllUsesWith(RetCast); |
| 831 | } |
| 832 | |
| 833 | // Clean up the old call now that it has been completely upgraded. |
| 834 | CI->eraseFromParent(); |
Gabor Greif | e9ecc68 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 835 | } |
| 836 | break; |
Duncan Sands | 8e6ccb6 | 2009-10-14 16:11:37 +0000 | [diff] [blame] | 837 | case Intrinsic::eh_selector: |
| 838 | case Intrinsic::eh_typeid_for: { |
| 839 | // Only the return type changed. |
Gabor Greif | e540653 | 2010-06-23 08:45:32 +0000 | [diff] [blame] | 840 | SmallVector<Value*, 8> Operands(CS.arg_begin(), CS.arg_end()); |
Duncan Sands | 8e6ccb6 | 2009-10-14 16:11:37 +0000 | [diff] [blame] | 841 | CallInst *NewCI = CallInst::Create(NewFn, Operands.begin(), Operands.end(), |
| 842 | "upgraded." + CI->getName(), CI); |
| 843 | NewCI->setTailCall(CI->isTailCall()); |
| 844 | NewCI->setCallingConv(CI->getCallingConv()); |
| 845 | |
| 846 | // Handle any uses of the old CallInst. |
| 847 | if (!CI->use_empty()) { |
| 848 | // Construct an appropriate cast from the new return type to the old. |
| 849 | CastInst *RetCast = |
| 850 | CastInst::Create(CastInst::getCastOpcode(NewCI, true, |
| 851 | F->getReturnType(), true), |
| 852 | NewCI, F->getReturnType(), NewCI->getName(), CI); |
| 853 | CI->replaceAllUsesWith(RetCast); |
| 854 | } |
| 855 | CI->eraseFromParent(); |
| 856 | } |
| 857 | break; |
Mon P Wang | c576ee9 | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 858 | case Intrinsic::memcpy: |
| 859 | case Intrinsic::memmove: |
| 860 | case Intrinsic::memset: { |
| 861 | // Add isVolatile |
| 862 | const llvm::Type *I1Ty = llvm::Type::getInt1Ty(CI->getContext()); |
Gabor Greif | c89d2aa | 2010-06-22 20:40:38 +0000 | [diff] [blame] | 863 | Value *Operands[5] = { CI->getArgOperand(0), CI->getArgOperand(1), |
| 864 | CI->getArgOperand(2), CI->getArgOperand(3), |
Mon P Wang | c576ee9 | 2010-04-04 03:10:48 +0000 | [diff] [blame] | 865 | llvm::ConstantInt::get(I1Ty, 0) }; |
| 866 | CallInst *NewCI = CallInst::Create(NewFn, Operands, Operands+5, |
| 867 | CI->getName(), CI); |
| 868 | NewCI->setTailCall(CI->isTailCall()); |
| 869 | NewCI->setCallingConv(CI->getCallingConv()); |
| 870 | // Handle any uses of the old CallInst. |
| 871 | if (!CI->use_empty()) |
| 872 | // Replace all uses of the old call with the new cast which has the |
| 873 | // correct type. |
| 874 | CI->replaceAllUsesWith(NewCI); |
| 875 | |
| 876 | // Clean up the old call now that it has been completely upgraded. |
| 877 | CI->eraseFromParent(); |
| 878 | break; |
| 879 | } |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 880 | } |
| 881 | } |
| 882 | |
| 883 | // This tests each Function to determine if it needs upgrading. When we find |
| 884 | // one we are interested in, we then upgrade all calls to reflect the new |
| 885 | // function. |
| 886 | void llvm::UpgradeCallsToIntrinsic(Function* F) { |
| 887 | assert(F && "Illegal attempt to upgrade a non-existent intrinsic."); |
| 888 | |
| 889 | // Upgrade the function and check if it is a totaly new function. |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 890 | Function* NewFn; |
| 891 | if (UpgradeIntrinsicFunction(F, NewFn)) { |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 892 | if (NewFn != F) { |
| 893 | // Replace all uses to the old function with the new one if necessary. |
| 894 | for (Value::use_iterator UI = F->use_begin(), UE = F->use_end(); |
| 895 | UI != UE; ) { |
| 896 | if (CallInst* CI = dyn_cast<CallInst>(*UI++)) |
| 897 | UpgradeIntrinsicCall(CI, NewFn); |
| 898 | } |
| 899 | // Remove old function, no longer used, from the module. |
| 900 | F->eraseFromParent(); |
| 901 | } |
| 902 | } |
| 903 | } |
Devang Patel | 80ae349 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 904 | |
Victor Hernandez | c2044a1 | 2010-01-05 21:13:46 +0000 | [diff] [blame] | 905 | /// This function strips all debug info intrinsics, except for llvm.dbg.declare. |
| 906 | /// If an llvm.dbg.declare intrinsic is invalid, then this function simply |
| 907 | /// strips that use. |
Devang Patel | 80ae349 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 908 | void llvm::CheckDebugInfoIntrinsics(Module *M) { |
| 909 | |
| 910 | |
| 911 | if (Function *FuncStart = M->getFunction("llvm.dbg.func.start")) { |
Devang Patel | be94f23 | 2010-01-05 01:10:40 +0000 | [diff] [blame] | 912 | while (!FuncStart->use_empty()) { |
| 913 | CallInst *CI = cast<CallInst>(FuncStart->use_back()); |
| 914 | CI->eraseFromParent(); |
Devang Patel | 80ae349 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 915 | } |
Devang Patel | be94f23 | 2010-01-05 01:10:40 +0000 | [diff] [blame] | 916 | FuncStart->eraseFromParent(); |
Devang Patel | 80ae349 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 917 | } |
Devang Patel | be94f23 | 2010-01-05 01:10:40 +0000 | [diff] [blame] | 918 | |
Devang Patel | 80ae349 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 919 | if (Function *StopPoint = M->getFunction("llvm.dbg.stoppoint")) { |
Devang Patel | be94f23 | 2010-01-05 01:10:40 +0000 | [diff] [blame] | 920 | while (!StopPoint->use_empty()) { |
| 921 | CallInst *CI = cast<CallInst>(StopPoint->use_back()); |
| 922 | CI->eraseFromParent(); |
Devang Patel | 80ae349 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 923 | } |
Devang Patel | be94f23 | 2010-01-05 01:10:40 +0000 | [diff] [blame] | 924 | StopPoint->eraseFromParent(); |
Devang Patel | 80ae349 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | if (Function *RegionStart = M->getFunction("llvm.dbg.region.start")) { |
Devang Patel | be94f23 | 2010-01-05 01:10:40 +0000 | [diff] [blame] | 928 | while (!RegionStart->use_empty()) { |
| 929 | CallInst *CI = cast<CallInst>(RegionStart->use_back()); |
| 930 | CI->eraseFromParent(); |
Devang Patel | 80ae349 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 931 | } |
Devang Patel | be94f23 | 2010-01-05 01:10:40 +0000 | [diff] [blame] | 932 | RegionStart->eraseFromParent(); |
Devang Patel | 80ae349 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | if (Function *RegionEnd = M->getFunction("llvm.dbg.region.end")) { |
Devang Patel | be94f23 | 2010-01-05 01:10:40 +0000 | [diff] [blame] | 936 | while (!RegionEnd->use_empty()) { |
| 937 | CallInst *CI = cast<CallInst>(RegionEnd->use_back()); |
| 938 | CI->eraseFromParent(); |
Devang Patel | 80ae349 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 939 | } |
Devang Patel | be94f23 | 2010-01-05 01:10:40 +0000 | [diff] [blame] | 940 | RegionEnd->eraseFromParent(); |
Devang Patel | 80ae349 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | if (Function *Declare = M->getFunction("llvm.dbg.declare")) { |
| 944 | if (!Declare->use_empty()) { |
| 945 | DbgDeclareInst *DDI = cast<DbgDeclareInst>(Declare->use_back()); |
Gabor Greif | c89d2aa | 2010-06-22 20:40:38 +0000 | [diff] [blame] | 946 | if (!isa<MDNode>(DDI->getArgOperand(0)) || |
| 947 | !isa<MDNode>(DDI->getArgOperand(1))) { |
Devang Patel | 80ae349 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 948 | while (!Declare->use_empty()) { |
| 949 | CallInst *CI = cast<CallInst>(Declare->use_back()); |
| 950 | CI->eraseFromParent(); |
| 951 | } |
| 952 | Declare->eraseFromParent(); |
| 953 | } |
| 954 | } |
| 955 | } |
| 956 | } |