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" |
Bill Wendling | 45449b1 | 2011-08-25 23:22:40 +0000 | [diff] [blame] | 17 | #include "llvm/Instruction.h" |
Owen Anderson | 155dccd8 | 2009-07-07 23:43:39 +0000 | [diff] [blame] | 18 | #include "llvm/LLVMContext.h" |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 19 | #include "llvm/Module.h" |
Devang Patel | 80ae349 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 20 | #include "llvm/IntrinsicInst.h" |
Gabor Greif | e540653 | 2010-06-23 08:45:32 +0000 | [diff] [blame] | 21 | #include "llvm/Support/CallSite.h" |
Bill Wendling | 45449b1 | 2011-08-25 23:22:40 +0000 | [diff] [blame] | 22 | #include "llvm/Support/CFG.h" |
Torok Edwin | 56d0659 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 23 | #include "llvm/Support/ErrorHandling.h" |
Eric Christopher | 64831c6 | 2010-04-20 00:59:54 +0000 | [diff] [blame] | 24 | #include "llvm/Support/IRBuilder.h" |
Anton Korobeynikov | 579f071 | 2008-02-20 11:08:44 +0000 | [diff] [blame] | 25 | #include <cstring> |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 26 | using namespace llvm; |
| 27 | |
Nadav Rotem | 17ee58a | 2012-06-10 18:42:51 +0000 | [diff] [blame^] | 28 | // Upgrade the declarations of the SSE4.1 functions whose arguments have |
| 29 | // changed their type from v4f32 to v2i64. |
| 30 | static bool UpgradeSSE41Function(Function* F, Intrinsic::ID IID, |
| 31 | Function *&NewFn) { |
| 32 | // Check whether this is an old version of the function, which received |
| 33 | // v4f32 arguments. |
| 34 | Type *Arg0Type = F->getFunctionType()->getParamType(0); |
| 35 | if (Arg0Type != VectorType::get(Type::getFloatTy(F->getContext()), 4)) |
| 36 | return false; |
| 37 | |
| 38 | // Yes, it's old, replace it with new version. |
| 39 | F->setName(F->getName() + ".old"); |
| 40 | NewFn = Intrinsic::getDeclaration(F->getParent(), IID); |
| 41 | return true; |
| 42 | } |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 43 | |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 44 | static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) { |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 45 | assert(F && "Illegal to upgrade a non-existent Function."); |
| 46 | |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 47 | // Quickly eliminate it, if it's not a candidate. |
Chris Lattner | b372f66 | 2011-06-18 18:56:39 +0000 | [diff] [blame] | 48 | StringRef Name = F->getName(); |
| 49 | if (Name.size() <= 8 || !Name.startswith("llvm.")) |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 50 | return false; |
Chris Lattner | b372f66 | 2011-06-18 18:56:39 +0000 | [diff] [blame] | 51 | Name = Name.substr(5); // Strip off "llvm." |
Chris Lattner | 0bcbde4 | 2011-11-27 08:42:07 +0000 | [diff] [blame] | 52 | |
Chris Lattner | b372f66 | 2011-06-18 18:56:39 +0000 | [diff] [blame] | 53 | switch (Name[0]) { |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 54 | default: break; |
Chandler Carruth | 58a71ed | 2011-12-12 04:26:04 +0000 | [diff] [blame] | 55 | case 'c': { |
Chandler Carruth | 58a71ed | 2011-12-12 04:26:04 +0000 | [diff] [blame] | 56 | if (Name.startswith("ctlz.") && F->arg_size() == 1) { |
| 57 | F->setName(Name + ".old"); |
Chandler Carruth | d4a0240 | 2011-12-12 10:57:20 +0000 | [diff] [blame] | 58 | NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::ctlz, |
| 59 | F->arg_begin()->getType()); |
Chandler Carruth | 58a71ed | 2011-12-12 04:26:04 +0000 | [diff] [blame] | 60 | return true; |
| 61 | } |
| 62 | if (Name.startswith("cttz.") && F->arg_size() == 1) { |
| 63 | F->setName(Name + ".old"); |
Chandler Carruth | d4a0240 | 2011-12-12 10:57:20 +0000 | [diff] [blame] | 64 | NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::cttz, |
| 65 | F->arg_begin()->getType()); |
Chandler Carruth | 58a71ed | 2011-12-12 04:26:04 +0000 | [diff] [blame] | 66 | return true; |
| 67 | } |
| 68 | break; |
| 69 | } |
Craig Topper | 3b1817d | 2012-02-03 06:10:55 +0000 | [diff] [blame] | 70 | case 'x': { |
| 71 | if (Name.startswith("x86.sse2.pcmpeq.") || |
| 72 | Name.startswith("x86.sse2.pcmpgt.") || |
| 73 | Name.startswith("x86.avx2.pcmpeq.") || |
Craig Topper | d3c9e40 | 2012-04-18 05:24:00 +0000 | [diff] [blame] | 74 | Name.startswith("x86.avx2.pcmpgt.") || |
Craig Topper | 7daf897 | 2012-05-08 06:58:15 +0000 | [diff] [blame] | 75 | Name.startswith("x86.avx.vpermil.") || |
| 76 | Name == "x86.avx.movnt.dq.256" || |
| 77 | Name == "x86.avx.movnt.pd.256" || |
Craig Topper | 3352ba5 | 2012-06-09 16:46:13 +0000 | [diff] [blame] | 78 | Name == "x86.avx.movnt.ps.256" || |
| 79 | (Name.startswith("x86.xop.vpcom") && F->arg_size() == 2)) { |
Craig Topper | 3b1817d | 2012-02-03 06:10:55 +0000 | [diff] [blame] | 80 | NewFn = 0; |
| 81 | return true; |
| 82 | } |
Nadav Rotem | 17ee58a | 2012-06-10 18:42:51 +0000 | [diff] [blame^] | 83 | // SSE4.1 ptest functions may have an old signature. |
| 84 | if (Name.startswith("x86.sse41.ptest")) { |
| 85 | if (Name == "x86.sse41.ptestc") |
| 86 | return UpgradeSSE41Function(F, Intrinsic::x86_sse41_ptestc, NewFn); |
| 87 | if (Name == "x86.sse41.ptestz") |
| 88 | return UpgradeSSE41Function(F, Intrinsic::x86_sse41_ptestz, NewFn); |
| 89 | if (Name == "x86.sse41.ptestnzc") |
| 90 | return UpgradeSSE41Function(F, Intrinsic::x86_sse41_ptestnzc, NewFn); |
| 91 | } |
Craig Topper | 720c7bd | 2012-06-03 08:07:25 +0000 | [diff] [blame] | 92 | // Fix the FMA4 intrinsics to remove the 4 |
| 93 | if (Name.startswith("x86.fma4.")) { |
Craig Topper | 2c5ccd8 | 2012-06-03 16:48:52 +0000 | [diff] [blame] | 94 | F->setName("llvm.x86.fma" + Name.substr(8)); |
| 95 | NewFn = F; |
| 96 | return true; |
Craig Topper | 720c7bd | 2012-06-03 08:07:25 +0000 | [diff] [blame] | 97 | } |
Craig Topper | 3b1817d | 2012-02-03 06:10:55 +0000 | [diff] [blame] | 98 | break; |
| 99 | } |
Chris Lattner | b372f66 | 2011-06-18 18:56:39 +0000 | [diff] [blame] | 100 | } |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 101 | |
Nadav Rotem | 17ee58a | 2012-06-10 18:42:51 +0000 | [diff] [blame^] | 102 | // This may not belong here. This function is effectively being overloaded |
| 103 | // to both detect an intrinsic which needs upgrading, and to provide the |
| 104 | // upgraded form of the intrinsic. We should perhaps have two separate |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 105 | // functions for this. |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 106 | return false; |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 109 | bool llvm::UpgradeIntrinsicFunction(Function *F, Function *&NewFn) { |
| 110 | NewFn = 0; |
| 111 | bool Upgraded = UpgradeIntrinsicFunction1(F, NewFn); |
Duncan Sands | 38ef3a8 | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 112 | |
| 113 | // Upgrade intrinsic attributes. This does not change the function. |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 114 | if (NewFn) |
| 115 | F = NewFn; |
Dale Johannesen | b842d52 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 116 | if (unsigned id = F->getIntrinsicID()) |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 117 | F->setAttributes(Intrinsic::getAttributes((Intrinsic::ID)id)); |
Duncan Sands | 38ef3a8 | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 118 | return Upgraded; |
| 119 | } |
| 120 | |
Bill Wendling | e26fffc | 2010-09-10 18:51:56 +0000 | [diff] [blame] | 121 | bool llvm::UpgradeGlobalVariable(GlobalVariable *GV) { |
Chris Lattner | 80ed9dc | 2011-06-18 06:05:24 +0000 | [diff] [blame] | 122 | // Nothing to do yet. |
Bill Wendling | e26fffc | 2010-09-10 18:51:56 +0000 | [diff] [blame] | 123 | return false; |
| 124 | } |
| 125 | |
Nadav Rotem | 17ee58a | 2012-06-10 18:42:51 +0000 | [diff] [blame^] | 126 | // UpgradeIntrinsicCall - Upgrade a call to an old intrinsic to be a call the |
| 127 | // upgraded intrinsic. All argument and return casting must be provided in |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 128 | // order to seamlessly integrate with existing context. |
| 129 | void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) { |
Craig Topper | 3b1817d | 2012-02-03 06:10:55 +0000 | [diff] [blame] | 130 | Function *F = CI->getCalledFunction(); |
Nick Lewycky | 2eb3ade | 2011-12-12 22:59:34 +0000 | [diff] [blame] | 131 | LLVMContext &C = CI->getContext(); |
Chandler Carruth | 58a71ed | 2011-12-12 04:26:04 +0000 | [diff] [blame] | 132 | IRBuilder<> Builder(C); |
| 133 | Builder.SetInsertPoint(CI->getParent(), CI); |
| 134 | |
Craig Topper | 3b1817d | 2012-02-03 06:10:55 +0000 | [diff] [blame] | 135 | assert(F && "Intrinsic call is not direct?"); |
| 136 | |
| 137 | if (!NewFn) { |
| 138 | // Get the Function's name. |
| 139 | StringRef Name = F->getName(); |
| 140 | |
| 141 | Value *Rep; |
| 142 | // Upgrade packed integer vector compares intrinsics to compare instructions |
| 143 | if (Name.startswith("llvm.x86.sse2.pcmpeq.") || |
| 144 | Name.startswith("llvm.x86.avx2.pcmpeq.")) { |
| 145 | Rep = Builder.CreateICmpEQ(CI->getArgOperand(0), CI->getArgOperand(1), |
| 146 | "pcmpeq"); |
| 147 | // need to sign extend since icmp returns vector of i1 |
| 148 | Rep = Builder.CreateSExt(Rep, CI->getType(), ""); |
| 149 | } else if (Name.startswith("llvm.x86.sse2.pcmpgt.") || |
| 150 | Name.startswith("llvm.x86.avx2.pcmpgt.")) { |
| 151 | Rep = Builder.CreateICmpSGT(CI->getArgOperand(0), CI->getArgOperand(1), |
| 152 | "pcmpgt"); |
| 153 | // need to sign extend since icmp returns vector of i1 |
| 154 | Rep = Builder.CreateSExt(Rep, CI->getType(), ""); |
Craig Topper | 7daf897 | 2012-05-08 06:58:15 +0000 | [diff] [blame] | 155 | } else if (Name == "llvm.x86.avx.movnt.dq.256" || |
| 156 | Name == "llvm.x86.avx.movnt.ps.256" || |
| 157 | Name == "llvm.x86.avx.movnt.pd.256") { |
| 158 | IRBuilder<> Builder(C); |
| 159 | Builder.SetInsertPoint(CI->getParent(), CI); |
| 160 | |
| 161 | Module *M = F->getParent(); |
| 162 | SmallVector<Value *, 1> Elts; |
| 163 | Elts.push_back(ConstantInt::get(Type::getInt32Ty(C), 1)); |
| 164 | MDNode *Node = MDNode::get(C, Elts); |
| 165 | |
| 166 | Value *Arg0 = CI->getArgOperand(0); |
| 167 | Value *Arg1 = CI->getArgOperand(1); |
| 168 | |
| 169 | // Convert the type of the pointer to a pointer to the stored type. |
| 170 | Value *BC = Builder.CreateBitCast(Arg0, |
| 171 | PointerType::getUnqual(Arg1->getType()), |
| 172 | "cast"); |
| 173 | StoreInst *SI = Builder.CreateStore(Arg1, BC); |
| 174 | SI->setMetadata(M->getMDKindID("nontemporal"), Node); |
| 175 | SI->setAlignment(16); |
| 176 | |
| 177 | // Remove intrinsic. |
| 178 | CI->eraseFromParent(); |
| 179 | return; |
Craig Topper | 3352ba5 | 2012-06-09 16:46:13 +0000 | [diff] [blame] | 180 | } else if (Name.startswith("llvm.x86.xop.vpcom")) { |
| 181 | Intrinsic::ID intID; |
| 182 | if (Name.endswith("ub")) |
| 183 | intID = Intrinsic::x86_xop_vpcomub; |
| 184 | else if (Name.endswith("uw")) |
| 185 | intID = Intrinsic::x86_xop_vpcomuw; |
| 186 | else if (Name.endswith("ud")) |
| 187 | intID = Intrinsic::x86_xop_vpcomud; |
| 188 | else if (Name.endswith("uq")) |
| 189 | intID = Intrinsic::x86_xop_vpcomuq; |
| 190 | else if (Name.endswith("b")) |
| 191 | intID = Intrinsic::x86_xop_vpcomb; |
| 192 | else if (Name.endswith("w")) |
| 193 | intID = Intrinsic::x86_xop_vpcomw; |
| 194 | else if (Name.endswith("d")) |
| 195 | intID = Intrinsic::x86_xop_vpcomd; |
| 196 | else if (Name.endswith("q")) |
| 197 | intID = Intrinsic::x86_xop_vpcomq; |
| 198 | else |
| 199 | llvm_unreachable("Unknown suffix"); |
| 200 | |
| 201 | Name = Name.substr(18); // strip off "llvm.x86.xop.vpcom" |
| 202 | unsigned Imm; |
| 203 | if (Name.startswith("lt")) |
| 204 | Imm = 0; |
| 205 | else if (Name.startswith("le")) |
| 206 | Imm = 1; |
| 207 | else if (Name.startswith("gt")) |
| 208 | Imm = 2; |
| 209 | else if (Name.startswith("ge")) |
| 210 | Imm = 3; |
| 211 | else if (Name.startswith("eq")) |
| 212 | Imm = 4; |
| 213 | else if (Name.startswith("ne")) |
| 214 | Imm = 5; |
| 215 | else if (Name.startswith("true")) |
| 216 | Imm = 6; |
| 217 | else if (Name.startswith("false")) |
| 218 | Imm = 7; |
| 219 | else |
| 220 | llvm_unreachable("Unknown condition"); |
| 221 | |
| 222 | Function *VPCOM = Intrinsic::getDeclaration(F->getParent(), intID); |
| 223 | Rep = Builder.CreateCall3(VPCOM, CI->getArgOperand(0), |
| 224 | CI->getArgOperand(1), Builder.getInt8(Imm)); |
Craig Topper | 3b1817d | 2012-02-03 06:10:55 +0000 | [diff] [blame] | 225 | } else { |
Craig Topper | d3c9e40 | 2012-04-18 05:24:00 +0000 | [diff] [blame] | 226 | bool PD128 = false, PD256 = false, PS128 = false, PS256 = false; |
Craig Topper | 7daf897 | 2012-05-08 06:58:15 +0000 | [diff] [blame] | 227 | if (Name == "llvm.x86.avx.vpermil.pd.256") |
Craig Topper | d3c9e40 | 2012-04-18 05:24:00 +0000 | [diff] [blame] | 228 | PD256 = true; |
Craig Topper | 7daf897 | 2012-05-08 06:58:15 +0000 | [diff] [blame] | 229 | else if (Name == "llvm.x86.avx.vpermil.pd") |
Craig Topper | d3c9e40 | 2012-04-18 05:24:00 +0000 | [diff] [blame] | 230 | PD128 = true; |
Craig Topper | 7daf897 | 2012-05-08 06:58:15 +0000 | [diff] [blame] | 231 | else if (Name == "llvm.x86.avx.vpermil.ps.256") |
Craig Topper | d3c9e40 | 2012-04-18 05:24:00 +0000 | [diff] [blame] | 232 | PS256 = true; |
Craig Topper | 7daf897 | 2012-05-08 06:58:15 +0000 | [diff] [blame] | 233 | else if (Name == "llvm.x86.avx.vpermil.ps") |
Craig Topper | d3c9e40 | 2012-04-18 05:24:00 +0000 | [diff] [blame] | 234 | PS128 = true; |
| 235 | |
| 236 | if (PD256 || PD128 || PS256 || PS128) { |
| 237 | Value *Op0 = CI->getArgOperand(0); |
| 238 | unsigned Imm = cast<ConstantInt>(CI->getArgOperand(1))->getZExtValue(); |
| 239 | SmallVector<Constant*, 8> Idxs; |
| 240 | |
| 241 | if (PD128) |
| 242 | for (unsigned i = 0; i != 2; ++i) |
| 243 | Idxs.push_back(Builder.getInt32((Imm >> i) & 0x1)); |
| 244 | else if (PD256) |
| 245 | for (unsigned l = 0; l != 4; l+=2) |
| 246 | for (unsigned i = 0; i != 2; ++i) |
| 247 | Idxs.push_back(Builder.getInt32(((Imm >> (l+i)) & 0x1) + l)); |
| 248 | else if (PS128) |
| 249 | for (unsigned i = 0; i != 4; ++i) |
| 250 | Idxs.push_back(Builder.getInt32((Imm >> (2 * i)) & 0x3)); |
| 251 | else if (PS256) |
| 252 | for (unsigned l = 0; l != 8; l+=4) |
| 253 | for (unsigned i = 0; i != 4; ++i) |
| 254 | Idxs.push_back(Builder.getInt32(((Imm >> (2 * i)) & 0x3) + l)); |
| 255 | else |
| 256 | llvm_unreachable("Unexpected function"); |
| 257 | |
| 258 | Rep = Builder.CreateShuffleVector(Op0, Op0, ConstantVector::get(Idxs)); |
| 259 | } else { |
| 260 | llvm_unreachable("Unknown function for CallInst upgrade."); |
| 261 | } |
Craig Topper | 3b1817d | 2012-02-03 06:10:55 +0000 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | CI->replaceAllUsesWith(Rep); |
| 265 | CI->eraseFromParent(); |
| 266 | return; |
| 267 | } |
| 268 | |
Nadav Rotem | 17ee58a | 2012-06-10 18:42:51 +0000 | [diff] [blame^] | 269 | StringRef Name = CI->getName(); |
| 270 | |
Chandler Carruth | 58a71ed | 2011-12-12 04:26:04 +0000 | [diff] [blame] | 271 | switch (NewFn->getIntrinsicID()) { |
| 272 | default: |
Chris Lattner | 0bcbde4 | 2011-11-27 08:42:07 +0000 | [diff] [blame] | 273 | llvm_unreachable("Unknown function for CallInst upgrade."); |
Chandler Carruth | 58a71ed | 2011-12-12 04:26:04 +0000 | [diff] [blame] | 274 | |
| 275 | case Intrinsic::ctlz: |
Nuno Lopes | ad40c0a | 2012-05-22 15:25:31 +0000 | [diff] [blame] | 276 | case Intrinsic::cttz: |
Chandler Carruth | 58a71ed | 2011-12-12 04:26:04 +0000 | [diff] [blame] | 277 | assert(CI->getNumArgOperands() == 1 && |
| 278 | "Mismatch between function args and call args"); |
Chandler Carruth | 58a71ed | 2011-12-12 04:26:04 +0000 | [diff] [blame] | 279 | CI->setName(Name + ".old"); |
| 280 | CI->replaceAllUsesWith(Builder.CreateCall2(NewFn, CI->getArgOperand(0), |
| 281 | Builder.getFalse(), Name)); |
| 282 | CI->eraseFromParent(); |
| 283 | return; |
Nadav Rotem | 17ee58a | 2012-06-10 18:42:51 +0000 | [diff] [blame^] | 284 | |
| 285 | case Intrinsic::x86_sse41_ptestc: |
| 286 | case Intrinsic::x86_sse41_ptestz: |
| 287 | case Intrinsic::x86_sse41_ptestnzc: |
| 288 | // The arguments for these intrinsics used to be v4f32, and changed |
| 289 | // to v2i64. This is purely a nop, since those are bitwise intrinsics. |
| 290 | // So, the only thing required is a bitcast for both arguments. |
| 291 | // First, check the arguments have the old type. |
| 292 | Value *Arg0 = CI->getArgOperand(0); |
| 293 | if (Arg0->getType() != VectorType::get(Type::getFloatTy(C), 4)) |
| 294 | return; |
| 295 | |
| 296 | // Old intrinsic, add bitcasts |
| 297 | Value *Arg1 = CI->getArgOperand(1); |
| 298 | |
| 299 | Value *BC0 = |
| 300 | Builder.CreateBitCast(Arg0, |
| 301 | VectorType::get(Type::getInt64Ty(C), 2), |
| 302 | "cast"); |
| 303 | Value *BC1 = |
| 304 | Builder.CreateBitCast(Arg1, |
| 305 | VectorType::get(Type::getInt64Ty(C), 2), |
| 306 | "cast"); |
| 307 | |
| 308 | CallInst* NewCall = Builder.CreateCall2(NewFn, BC0, BC1, Name); |
| 309 | CI->replaceAllUsesWith(NewCall); |
| 310 | CI->eraseFromParent(); |
| 311 | return; |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 312 | } |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | // This tests each Function to determine if it needs upgrading. When we find |
| 316 | // one we are interested in, we then upgrade all calls to reflect the new |
| 317 | // function. |
| 318 | void llvm::UpgradeCallsToIntrinsic(Function* F) { |
| 319 | assert(F && "Illegal attempt to upgrade a non-existent intrinsic."); |
| 320 | |
| 321 | // Upgrade the function and check if it is a totaly new function. |
Chris Lattner | 80ed9dc | 2011-06-18 06:05:24 +0000 | [diff] [blame] | 322 | Function *NewFn; |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 323 | if (UpgradeIntrinsicFunction(F, NewFn)) { |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 324 | if (NewFn != F) { |
| 325 | // Replace all uses to the old function with the new one if necessary. |
| 326 | for (Value::use_iterator UI = F->use_begin(), UE = F->use_end(); |
| 327 | UI != UE; ) { |
Chris Lattner | 80ed9dc | 2011-06-18 06:05:24 +0000 | [diff] [blame] | 328 | if (CallInst *CI = dyn_cast<CallInst>(*UI++)) |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 329 | UpgradeIntrinsicCall(CI, NewFn); |
| 330 | } |
| 331 | // Remove old function, no longer used, from the module. |
| 332 | F->eraseFromParent(); |
| 333 | } |
| 334 | } |
| 335 | } |
Devang Patel | 80ae349 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 336 | |