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 | // |
Matt Arsenault | c4c9226 | 2013-07-20 17:46:00 +0000 | [diff] [blame] | 10 | // This file implements the auto-upgrade helper functions |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chandler Carruth | 9106521 | 2014-03-05 10:34:14 +0000 | [diff] [blame] | 14 | #include "llvm/IR/AutoUpgrade.h" |
Chandler Carruth | 1305dc3 | 2014-03-04 11:45:46 +0000 | [diff] [blame] | 15 | #include "llvm/IR/CFG.h" |
Chandler Carruth | 219b89b | 2014-03-04 11:01:28 +0000 | [diff] [blame] | 16 | #include "llvm/IR/CallSite.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 17 | #include "llvm/IR/Constants.h" |
Chandler Carruth | 9a4c9e5 | 2014-03-06 00:46:21 +0000 | [diff] [blame] | 18 | #include "llvm/IR/DebugInfo.h" |
Manman Ren | 2ebfb42 | 2014-01-16 01:51:12 +0000 | [diff] [blame] | 19 | #include "llvm/IR/DiagnosticInfo.h" |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 20 | #include "llvm/IR/DIBuilder.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 21 | #include "llvm/IR/Function.h" |
| 22 | #include "llvm/IR/IRBuilder.h" |
| 23 | #include "llvm/IR/Instruction.h" |
| 24 | #include "llvm/IR/IntrinsicInst.h" |
| 25 | #include "llvm/IR/LLVMContext.h" |
| 26 | #include "llvm/IR/Module.h" |
Torok Edwin | 56d0659 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 27 | #include "llvm/Support/ErrorHandling.h" |
Anton Korobeynikov | 579f071 | 2008-02-20 11:08:44 +0000 | [diff] [blame] | 28 | #include <cstring> |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 29 | using namespace llvm; |
| 30 | |
Nadav Rotem | 17ee58a | 2012-06-10 18:42:51 +0000 | [diff] [blame] | 31 | // Upgrade the declarations of the SSE4.1 functions whose arguments have |
| 32 | // changed their type from v4f32 to v2i64. |
| 33 | static bool UpgradeSSE41Function(Function* F, Intrinsic::ID IID, |
| 34 | Function *&NewFn) { |
| 35 | // Check whether this is an old version of the function, which received |
| 36 | // v4f32 arguments. |
| 37 | Type *Arg0Type = F->getFunctionType()->getParamType(0); |
| 38 | if (Arg0Type != VectorType::get(Type::getFloatTy(F->getContext()), 4)) |
| 39 | return false; |
| 40 | |
| 41 | // Yes, it's old, replace it with new version. |
| 42 | F->setName(F->getName() + ".old"); |
| 43 | NewFn = Intrinsic::getDeclaration(F->getParent(), IID); |
| 44 | return true; |
| 45 | } |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 46 | |
Chandler Carruth | 373b2b1 | 2014-09-06 10:00:01 +0000 | [diff] [blame] | 47 | // Upgrade the declarations of intrinsic functions whose 8-bit immediate mask |
| 48 | // arguments have changed their type from i32 to i8. |
| 49 | static bool UpgradeX86IntrinsicsWith8BitMask(Function *F, Intrinsic::ID IID, |
| 50 | Function *&NewFn) { |
| 51 | // Check that the last argument is an i32. |
| 52 | Type *LastArgType = F->getFunctionType()->getParamType( |
| 53 | F->getFunctionType()->getNumParams() - 1); |
| 54 | if (!LastArgType->isIntegerTy(32)) |
| 55 | return false; |
| 56 | |
| 57 | // Move this function aside and map down. |
| 58 | F->setName(F->getName() + ".old"); |
| 59 | NewFn = Intrinsic::getDeclaration(F->getParent(), IID); |
| 60 | return true; |
| 61 | } |
| 62 | |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 63 | static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) { |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 64 | assert(F && "Illegal to upgrade a non-existent Function."); |
| 65 | |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 66 | // Quickly eliminate it, if it's not a candidate. |
Chris Lattner | b372f66 | 2011-06-18 18:56:39 +0000 | [diff] [blame] | 67 | StringRef Name = F->getName(); |
| 68 | if (Name.size() <= 8 || !Name.startswith("llvm.")) |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 69 | return false; |
Chris Lattner | b372f66 | 2011-06-18 18:56:39 +0000 | [diff] [blame] | 70 | Name = Name.substr(5); // Strip off "llvm." |
Chris Lattner | 0bcbde4 | 2011-11-27 08:42:07 +0000 | [diff] [blame] | 71 | |
Chris Lattner | b372f66 | 2011-06-18 18:56:39 +0000 | [diff] [blame] | 72 | switch (Name[0]) { |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 73 | default: break; |
Joel Jones | 43cb878 | 2012-07-13 23:25:25 +0000 | [diff] [blame] | 74 | case 'a': { |
| 75 | if (Name.startswith("arm.neon.vclz")) { |
| 76 | Type* args[2] = { |
Matt Arsenault | c4c9226 | 2013-07-20 17:46:00 +0000 | [diff] [blame] | 77 | F->arg_begin()->getType(), |
Joel Jones | 43cb878 | 2012-07-13 23:25:25 +0000 | [diff] [blame] | 78 | Type::getInt1Ty(F->getContext()) |
| 79 | }; |
| 80 | // Can't use Intrinsic::getDeclaration here as it adds a ".i1" to |
| 81 | // the end of the name. Change name from llvm.arm.neon.vclz.* to |
| 82 | // llvm.ctlz.* |
| 83 | FunctionType* fType = FunctionType::get(F->getReturnType(), args, false); |
Matt Arsenault | c4c9226 | 2013-07-20 17:46:00 +0000 | [diff] [blame] | 84 | NewFn = Function::Create(fType, F->getLinkage(), |
Joel Jones | 43cb878 | 2012-07-13 23:25:25 +0000 | [diff] [blame] | 85 | "llvm.ctlz." + Name.substr(14), F->getParent()); |
| 86 | return true; |
| 87 | } |
Joel Jones | b84f7be | 2012-07-18 00:02:16 +0000 | [diff] [blame] | 88 | if (Name.startswith("arm.neon.vcnt")) { |
| 89 | NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::ctpop, |
| 90 | F->arg_begin()->getType()); |
| 91 | return true; |
| 92 | } |
Joel Jones | 43cb878 | 2012-07-13 23:25:25 +0000 | [diff] [blame] | 93 | break; |
| 94 | } |
Chandler Carruth | 58a71ed | 2011-12-12 04:26:04 +0000 | [diff] [blame] | 95 | case 'c': { |
Chandler Carruth | 58a71ed | 2011-12-12 04:26:04 +0000 | [diff] [blame] | 96 | if (Name.startswith("ctlz.") && F->arg_size() == 1) { |
| 97 | F->setName(Name + ".old"); |
Chandler Carruth | d4a0240 | 2011-12-12 10:57:20 +0000 | [diff] [blame] | 98 | NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::ctlz, |
| 99 | F->arg_begin()->getType()); |
Chandler Carruth | 58a71ed | 2011-12-12 04:26:04 +0000 | [diff] [blame] | 100 | return true; |
| 101 | } |
| 102 | if (Name.startswith("cttz.") && F->arg_size() == 1) { |
| 103 | F->setName(Name + ".old"); |
Chandler Carruth | d4a0240 | 2011-12-12 10:57:20 +0000 | [diff] [blame] | 104 | NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::cttz, |
| 105 | F->arg_begin()->getType()); |
Chandler Carruth | 58a71ed | 2011-12-12 04:26:04 +0000 | [diff] [blame] | 106 | return true; |
| 107 | } |
| 108 | break; |
| 109 | } |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 110 | case 'd': { |
| 111 | if (Name.startswith("dbg.declare") && F->arg_size() == 2) { |
| 112 | F->setName(Name + ".old"); |
| 113 | NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::dbg_declare); |
| 114 | return true; |
| 115 | } |
| 116 | if (Name.startswith("dbg.value") && F->arg_size() == 3) { |
| 117 | F->setName(Name + ".old"); |
| 118 | NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::dbg_value); |
| 119 | return true; |
| 120 | } |
| 121 | break; |
| 122 | } |
| 123 | |
Matt Arsenault | fbcbce4 | 2013-10-07 18:06:48 +0000 | [diff] [blame] | 124 | case 'o': |
| 125 | // We only need to change the name to match the mangling including the |
| 126 | // address space. |
| 127 | if (F->arg_size() == 2 && Name.startswith("objectsize.")) { |
| 128 | Type *Tys[2] = { F->getReturnType(), F->arg_begin()->getType() }; |
| 129 | if (F->getName() != Intrinsic::getName(Intrinsic::objectsize, Tys)) { |
| 130 | F->setName(Name + ".old"); |
| 131 | NewFn = Intrinsic::getDeclaration(F->getParent(), |
| 132 | Intrinsic::objectsize, Tys); |
| 133 | return true; |
| 134 | } |
| 135 | } |
| 136 | break; |
| 137 | |
Craig Topper | 3b1817d | 2012-02-03 06:10:55 +0000 | [diff] [blame] | 138 | case 'x': { |
| 139 | if (Name.startswith("x86.sse2.pcmpeq.") || |
| 140 | Name.startswith("x86.sse2.pcmpgt.") || |
| 141 | Name.startswith("x86.avx2.pcmpeq.") || |
Craig Topper | d3c9e40 | 2012-04-18 05:24:00 +0000 | [diff] [blame] | 142 | Name.startswith("x86.avx2.pcmpgt.") || |
Craig Topper | 7daf897 | 2012-05-08 06:58:15 +0000 | [diff] [blame] | 143 | Name.startswith("x86.avx.vpermil.") || |
| 144 | Name == "x86.avx.movnt.dq.256" || |
| 145 | Name == "x86.avx.movnt.pd.256" || |
Craig Topper | 3352ba5 | 2012-06-09 16:46:13 +0000 | [diff] [blame] | 146 | Name == "x86.avx.movnt.ps.256" || |
Craig Topper | ef9e993 | 2013-10-15 05:20:47 +0000 | [diff] [blame] | 147 | Name == "x86.sse42.crc32.64.8" || |
Adam Nemet | 3906680 | 2014-05-29 23:35:33 +0000 | [diff] [blame] | 148 | Name == "x86.avx.vbroadcast.ss" || |
| 149 | Name == "x86.avx.vbroadcast.ss.256" || |
| 150 | Name == "x86.avx.vbroadcast.sd.256" || |
Craig Topper | 3352ba5 | 2012-06-09 16:46:13 +0000 | [diff] [blame] | 151 | (Name.startswith("x86.xop.vpcom") && F->arg_size() == 2)) { |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 152 | NewFn = nullptr; |
Craig Topper | 3b1817d | 2012-02-03 06:10:55 +0000 | [diff] [blame] | 153 | return true; |
| 154 | } |
Nadav Rotem | 17ee58a | 2012-06-10 18:42:51 +0000 | [diff] [blame] | 155 | // SSE4.1 ptest functions may have an old signature. |
| 156 | if (Name.startswith("x86.sse41.ptest")) { |
| 157 | if (Name == "x86.sse41.ptestc") |
| 158 | return UpgradeSSE41Function(F, Intrinsic::x86_sse41_ptestc, NewFn); |
| 159 | if (Name == "x86.sse41.ptestz") |
| 160 | return UpgradeSSE41Function(F, Intrinsic::x86_sse41_ptestz, NewFn); |
| 161 | if (Name == "x86.sse41.ptestnzc") |
| 162 | return UpgradeSSE41Function(F, Intrinsic::x86_sse41_ptestnzc, NewFn); |
| 163 | } |
Chandler Carruth | 373b2b1 | 2014-09-06 10:00:01 +0000 | [diff] [blame] | 164 | // Several blend and other instructions with maskes used the wrong number of |
| 165 | // bits. |
| 166 | if (Name == "x86.sse41.pblendw") |
| 167 | return UpgradeX86IntrinsicsWith8BitMask(F, Intrinsic::x86_sse41_pblendw, |
| 168 | NewFn); |
| 169 | if (Name == "x86.sse41.blendpd") |
| 170 | return UpgradeX86IntrinsicsWith8BitMask(F, Intrinsic::x86_sse41_blendpd, |
| 171 | NewFn); |
| 172 | if (Name == "x86.sse41.blendps") |
| 173 | return UpgradeX86IntrinsicsWith8BitMask(F, Intrinsic::x86_sse41_blendps, |
| 174 | NewFn); |
| 175 | if (Name == "x86.sse41.insertps") |
| 176 | return UpgradeX86IntrinsicsWith8BitMask(F, Intrinsic::x86_sse41_insertps, |
| 177 | NewFn); |
| 178 | if (Name == "x86.sse41.dppd") |
| 179 | return UpgradeX86IntrinsicsWith8BitMask(F, Intrinsic::x86_sse41_dppd, |
| 180 | NewFn); |
| 181 | if (Name == "x86.sse41.dpps") |
| 182 | return UpgradeX86IntrinsicsWith8BitMask(F, Intrinsic::x86_sse41_dpps, |
| 183 | NewFn); |
| 184 | if (Name == "x86.sse41.mpsadbw") |
| 185 | return UpgradeX86IntrinsicsWith8BitMask(F, Intrinsic::x86_sse41_mpsadbw, |
| 186 | NewFn); |
| 187 | if (Name == "x86.avx.blend.pd.256") |
| 188 | return UpgradeX86IntrinsicsWith8BitMask( |
| 189 | F, Intrinsic::x86_avx_blend_pd_256, NewFn); |
| 190 | if (Name == "x86.avx.blend.ps.256") |
| 191 | return UpgradeX86IntrinsicsWith8BitMask( |
| 192 | F, Intrinsic::x86_avx_blend_ps_256, NewFn); |
| 193 | if (Name == "x86.avx.dp.ps.256") |
| 194 | return UpgradeX86IntrinsicsWith8BitMask(F, Intrinsic::x86_avx_dp_ps_256, |
| 195 | NewFn); |
| 196 | if (Name == "x86.avx2.pblendw") |
| 197 | return UpgradeX86IntrinsicsWith8BitMask(F, Intrinsic::x86_avx2_pblendw, |
| 198 | NewFn); |
| 199 | if (Name == "x86.avx2.pblendd.128") |
| 200 | return UpgradeX86IntrinsicsWith8BitMask( |
| 201 | F, Intrinsic::x86_avx2_pblendd_128, NewFn); |
| 202 | if (Name == "x86.avx2.pblendd.256") |
| 203 | return UpgradeX86IntrinsicsWith8BitMask( |
| 204 | F, Intrinsic::x86_avx2_pblendd_256, NewFn); |
| 205 | if (Name == "x86.avx2.mpsadbw") |
| 206 | return UpgradeX86IntrinsicsWith8BitMask(F, Intrinsic::x86_avx2_mpsadbw, |
| 207 | NewFn); |
| 208 | |
Craig Topper | 71dc02d | 2012-06-13 07:18:53 +0000 | [diff] [blame] | 209 | // frcz.ss/sd may need to have an argument dropped |
| 210 | if (Name.startswith("x86.xop.vfrcz.ss") && F->arg_size() == 2) { |
| 211 | F->setName(Name + ".old"); |
| 212 | NewFn = Intrinsic::getDeclaration(F->getParent(), |
| 213 | Intrinsic::x86_xop_vfrcz_ss); |
| 214 | return true; |
| 215 | } |
| 216 | if (Name.startswith("x86.xop.vfrcz.sd") && F->arg_size() == 2) { |
| 217 | F->setName(Name + ".old"); |
| 218 | NewFn = Intrinsic::getDeclaration(F->getParent(), |
| 219 | Intrinsic::x86_xop_vfrcz_sd); |
| 220 | return true; |
| 221 | } |
Craig Topper | 720c7bd | 2012-06-03 08:07:25 +0000 | [diff] [blame] | 222 | // Fix the FMA4 intrinsics to remove the 4 |
| 223 | if (Name.startswith("x86.fma4.")) { |
Craig Topper | 2c5ccd8 | 2012-06-03 16:48:52 +0000 | [diff] [blame] | 224 | F->setName("llvm.x86.fma" + Name.substr(8)); |
| 225 | NewFn = F; |
| 226 | return true; |
Craig Topper | 720c7bd | 2012-06-03 08:07:25 +0000 | [diff] [blame] | 227 | } |
Craig Topper | 3b1817d | 2012-02-03 06:10:55 +0000 | [diff] [blame] | 228 | break; |
| 229 | } |
Chris Lattner | b372f66 | 2011-06-18 18:56:39 +0000 | [diff] [blame] | 230 | } |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 231 | |
Nadav Rotem | 17ee58a | 2012-06-10 18:42:51 +0000 | [diff] [blame] | 232 | // This may not belong here. This function is effectively being overloaded |
| 233 | // to both detect an intrinsic which needs upgrading, and to provide the |
| 234 | // upgraded form of the intrinsic. We should perhaps have two separate |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 235 | // functions for this. |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 236 | return false; |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 239 | bool llvm::UpgradeIntrinsicFunction(Function *F, Function *&NewFn) { |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 240 | NewFn = nullptr; |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 241 | bool Upgraded = UpgradeIntrinsicFunction1(F, NewFn); |
Duncan Sands | 38ef3a8 | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 242 | |
| 243 | // Upgrade intrinsic attributes. This does not change the function. |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 244 | if (NewFn) |
| 245 | F = NewFn; |
Dale Johannesen | b842d52 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 246 | if (unsigned id = F->getIntrinsicID()) |
Bill Wendling | d079a44 | 2012-10-15 04:46:55 +0000 | [diff] [blame] | 247 | F->setAttributes(Intrinsic::getAttributes(F->getContext(), |
| 248 | (Intrinsic::ID)id)); |
Duncan Sands | 38ef3a8 | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 249 | return Upgraded; |
| 250 | } |
| 251 | |
Bill Wendling | e26fffc | 2010-09-10 18:51:56 +0000 | [diff] [blame] | 252 | bool llvm::UpgradeGlobalVariable(GlobalVariable *GV) { |
Chris Lattner | 80ed9dc | 2011-06-18 06:05:24 +0000 | [diff] [blame] | 253 | // Nothing to do yet. |
Bill Wendling | e26fffc | 2010-09-10 18:51:56 +0000 | [diff] [blame] | 254 | return false; |
| 255 | } |
| 256 | |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 257 | static MDNode *getNodeField(const MDNode *DbgNode, unsigned Elt) { |
| 258 | if (!DbgNode || Elt >= DbgNode->getNumOperands()) |
| 259 | return nullptr; |
| 260 | return dyn_cast_or_null<MDNode>(DbgNode->getOperand(Elt)); |
| 261 | } |
| 262 | |
| 263 | static DIExpression getExpression(Value *VarOperand, Function *F) { |
| 264 | // Old-style DIVariables have an optional expression as the 8th element. |
| 265 | DIExpression Expr(getNodeField(cast<MDNode>(VarOperand), 8)); |
| 266 | if (!Expr) { |
| 267 | DIBuilder DIB(*F->getParent()); |
| 268 | Expr = DIB.createExpression(); |
| 269 | } |
| 270 | return Expr; |
| 271 | } |
| 272 | |
Nadav Rotem | 17ee58a | 2012-06-10 18:42:51 +0000 | [diff] [blame] | 273 | // UpgradeIntrinsicCall - Upgrade a call to an old intrinsic to be a call the |
| 274 | // upgraded intrinsic. All argument and return casting must be provided in |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 275 | // order to seamlessly integrate with existing context. |
| 276 | void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) { |
Craig Topper | 3b1817d | 2012-02-03 06:10:55 +0000 | [diff] [blame] | 277 | Function *F = CI->getCalledFunction(); |
Nick Lewycky | 2eb3ade | 2011-12-12 22:59:34 +0000 | [diff] [blame] | 278 | LLVMContext &C = CI->getContext(); |
Chandler Carruth | 58a71ed | 2011-12-12 04:26:04 +0000 | [diff] [blame] | 279 | IRBuilder<> Builder(C); |
| 280 | Builder.SetInsertPoint(CI->getParent(), CI); |
| 281 | |
Craig Topper | 3b1817d | 2012-02-03 06:10:55 +0000 | [diff] [blame] | 282 | assert(F && "Intrinsic call is not direct?"); |
| 283 | |
| 284 | if (!NewFn) { |
| 285 | // Get the Function's name. |
| 286 | StringRef Name = F->getName(); |
| 287 | |
| 288 | Value *Rep; |
| 289 | // Upgrade packed integer vector compares intrinsics to compare instructions |
| 290 | if (Name.startswith("llvm.x86.sse2.pcmpeq.") || |
| 291 | Name.startswith("llvm.x86.avx2.pcmpeq.")) { |
| 292 | Rep = Builder.CreateICmpEQ(CI->getArgOperand(0), CI->getArgOperand(1), |
| 293 | "pcmpeq"); |
| 294 | // need to sign extend since icmp returns vector of i1 |
| 295 | Rep = Builder.CreateSExt(Rep, CI->getType(), ""); |
| 296 | } else if (Name.startswith("llvm.x86.sse2.pcmpgt.") || |
| 297 | Name.startswith("llvm.x86.avx2.pcmpgt.")) { |
| 298 | Rep = Builder.CreateICmpSGT(CI->getArgOperand(0), CI->getArgOperand(1), |
| 299 | "pcmpgt"); |
| 300 | // need to sign extend since icmp returns vector of i1 |
| 301 | Rep = Builder.CreateSExt(Rep, CI->getType(), ""); |
Craig Topper | 7daf897 | 2012-05-08 06:58:15 +0000 | [diff] [blame] | 302 | } else if (Name == "llvm.x86.avx.movnt.dq.256" || |
| 303 | Name == "llvm.x86.avx.movnt.ps.256" || |
| 304 | Name == "llvm.x86.avx.movnt.pd.256") { |
| 305 | IRBuilder<> Builder(C); |
| 306 | Builder.SetInsertPoint(CI->getParent(), CI); |
| 307 | |
| 308 | Module *M = F->getParent(); |
| 309 | SmallVector<Value *, 1> Elts; |
| 310 | Elts.push_back(ConstantInt::get(Type::getInt32Ty(C), 1)); |
| 311 | MDNode *Node = MDNode::get(C, Elts); |
| 312 | |
| 313 | Value *Arg0 = CI->getArgOperand(0); |
| 314 | Value *Arg1 = CI->getArgOperand(1); |
| 315 | |
| 316 | // Convert the type of the pointer to a pointer to the stored type. |
| 317 | Value *BC = Builder.CreateBitCast(Arg0, |
| 318 | PointerType::getUnqual(Arg1->getType()), |
| 319 | "cast"); |
| 320 | StoreInst *SI = Builder.CreateStore(Arg1, BC); |
| 321 | SI->setMetadata(M->getMDKindID("nontemporal"), Node); |
| 322 | SI->setAlignment(16); |
| 323 | |
| 324 | // Remove intrinsic. |
| 325 | CI->eraseFromParent(); |
| 326 | return; |
Craig Topper | 3352ba5 | 2012-06-09 16:46:13 +0000 | [diff] [blame] | 327 | } else if (Name.startswith("llvm.x86.xop.vpcom")) { |
| 328 | Intrinsic::ID intID; |
| 329 | if (Name.endswith("ub")) |
| 330 | intID = Intrinsic::x86_xop_vpcomub; |
| 331 | else if (Name.endswith("uw")) |
| 332 | intID = Intrinsic::x86_xop_vpcomuw; |
| 333 | else if (Name.endswith("ud")) |
| 334 | intID = Intrinsic::x86_xop_vpcomud; |
| 335 | else if (Name.endswith("uq")) |
| 336 | intID = Intrinsic::x86_xop_vpcomuq; |
| 337 | else if (Name.endswith("b")) |
| 338 | intID = Intrinsic::x86_xop_vpcomb; |
| 339 | else if (Name.endswith("w")) |
| 340 | intID = Intrinsic::x86_xop_vpcomw; |
| 341 | else if (Name.endswith("d")) |
| 342 | intID = Intrinsic::x86_xop_vpcomd; |
| 343 | else if (Name.endswith("q")) |
| 344 | intID = Intrinsic::x86_xop_vpcomq; |
| 345 | else |
| 346 | llvm_unreachable("Unknown suffix"); |
| 347 | |
| 348 | Name = Name.substr(18); // strip off "llvm.x86.xop.vpcom" |
| 349 | unsigned Imm; |
| 350 | if (Name.startswith("lt")) |
| 351 | Imm = 0; |
| 352 | else if (Name.startswith("le")) |
| 353 | Imm = 1; |
| 354 | else if (Name.startswith("gt")) |
| 355 | Imm = 2; |
| 356 | else if (Name.startswith("ge")) |
| 357 | Imm = 3; |
| 358 | else if (Name.startswith("eq")) |
| 359 | Imm = 4; |
| 360 | else if (Name.startswith("ne")) |
| 361 | Imm = 5; |
| 362 | else if (Name.startswith("true")) |
| 363 | Imm = 6; |
| 364 | else if (Name.startswith("false")) |
| 365 | Imm = 7; |
| 366 | else |
| 367 | llvm_unreachable("Unknown condition"); |
| 368 | |
| 369 | Function *VPCOM = Intrinsic::getDeclaration(F->getParent(), intID); |
| 370 | Rep = Builder.CreateCall3(VPCOM, CI->getArgOperand(0), |
| 371 | CI->getArgOperand(1), Builder.getInt8(Imm)); |
Craig Topper | ef9e993 | 2013-10-15 05:20:47 +0000 | [diff] [blame] | 372 | } else if (Name == "llvm.x86.sse42.crc32.64.8") { |
| 373 | Function *CRC32 = Intrinsic::getDeclaration(F->getParent(), |
| 374 | Intrinsic::x86_sse42_crc32_32_8); |
| 375 | Value *Trunc0 = Builder.CreateTrunc(CI->getArgOperand(0), Type::getInt32Ty(C)); |
| 376 | Rep = Builder.CreateCall2(CRC32, Trunc0, CI->getArgOperand(1)); |
| 377 | Rep = Builder.CreateZExt(Rep, CI->getType(), ""); |
Adam Nemet | 3906680 | 2014-05-29 23:35:33 +0000 | [diff] [blame] | 378 | } else if (Name.startswith("llvm.x86.avx.vbroadcast")) { |
| 379 | // Replace broadcasts with a series of insertelements. |
| 380 | Type *VecTy = CI->getType(); |
| 381 | Type *EltTy = VecTy->getVectorElementType(); |
| 382 | unsigned EltNum = VecTy->getVectorNumElements(); |
| 383 | Value *Cast = Builder.CreateBitCast(CI->getArgOperand(0), |
| 384 | EltTy->getPointerTo()); |
| 385 | Value *Load = Builder.CreateLoad(Cast); |
| 386 | Type *I32Ty = Type::getInt32Ty(C); |
| 387 | Rep = UndefValue::get(VecTy); |
| 388 | for (unsigned I = 0; I < EltNum; ++I) |
| 389 | Rep = Builder.CreateInsertElement(Rep, Load, |
| 390 | ConstantInt::get(I32Ty, I)); |
Craig Topper | 3b1817d | 2012-02-03 06:10:55 +0000 | [diff] [blame] | 391 | } else { |
Craig Topper | d3c9e40 | 2012-04-18 05:24:00 +0000 | [diff] [blame] | 392 | bool PD128 = false, PD256 = false, PS128 = false, PS256 = false; |
Craig Topper | 7daf897 | 2012-05-08 06:58:15 +0000 | [diff] [blame] | 393 | if (Name == "llvm.x86.avx.vpermil.pd.256") |
Craig Topper | d3c9e40 | 2012-04-18 05:24:00 +0000 | [diff] [blame] | 394 | PD256 = true; |
Craig Topper | 7daf897 | 2012-05-08 06:58:15 +0000 | [diff] [blame] | 395 | else if (Name == "llvm.x86.avx.vpermil.pd") |
Craig Topper | d3c9e40 | 2012-04-18 05:24:00 +0000 | [diff] [blame] | 396 | PD128 = true; |
Craig Topper | 7daf897 | 2012-05-08 06:58:15 +0000 | [diff] [blame] | 397 | else if (Name == "llvm.x86.avx.vpermil.ps.256") |
Craig Topper | d3c9e40 | 2012-04-18 05:24:00 +0000 | [diff] [blame] | 398 | PS256 = true; |
Craig Topper | 7daf897 | 2012-05-08 06:58:15 +0000 | [diff] [blame] | 399 | else if (Name == "llvm.x86.avx.vpermil.ps") |
Craig Topper | d3c9e40 | 2012-04-18 05:24:00 +0000 | [diff] [blame] | 400 | PS128 = true; |
| 401 | |
| 402 | if (PD256 || PD128 || PS256 || PS128) { |
| 403 | Value *Op0 = CI->getArgOperand(0); |
| 404 | unsigned Imm = cast<ConstantInt>(CI->getArgOperand(1))->getZExtValue(); |
| 405 | SmallVector<Constant*, 8> Idxs; |
| 406 | |
| 407 | if (PD128) |
| 408 | for (unsigned i = 0; i != 2; ++i) |
| 409 | Idxs.push_back(Builder.getInt32((Imm >> i) & 0x1)); |
| 410 | else if (PD256) |
| 411 | for (unsigned l = 0; l != 4; l+=2) |
| 412 | for (unsigned i = 0; i != 2; ++i) |
| 413 | Idxs.push_back(Builder.getInt32(((Imm >> (l+i)) & 0x1) + l)); |
| 414 | else if (PS128) |
| 415 | for (unsigned i = 0; i != 4; ++i) |
| 416 | Idxs.push_back(Builder.getInt32((Imm >> (2 * i)) & 0x3)); |
| 417 | else if (PS256) |
| 418 | for (unsigned l = 0; l != 8; l+=4) |
| 419 | for (unsigned i = 0; i != 4; ++i) |
| 420 | Idxs.push_back(Builder.getInt32(((Imm >> (2 * i)) & 0x3) + l)); |
| 421 | else |
| 422 | llvm_unreachable("Unexpected function"); |
| 423 | |
| 424 | Rep = Builder.CreateShuffleVector(Op0, Op0, ConstantVector::get(Idxs)); |
| 425 | } else { |
| 426 | llvm_unreachable("Unknown function for CallInst upgrade."); |
| 427 | } |
Craig Topper | 3b1817d | 2012-02-03 06:10:55 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | CI->replaceAllUsesWith(Rep); |
| 431 | CI->eraseFromParent(); |
| 432 | return; |
| 433 | } |
| 434 | |
Chandler Carruth | 1f41bf0 | 2012-07-20 21:09:18 +0000 | [diff] [blame] | 435 | std::string Name = CI->getName().str(); |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 436 | if (!Name.empty()) |
| 437 | CI->setName(Name + ".old"); |
Nadav Rotem | 17ee58a | 2012-06-10 18:42:51 +0000 | [diff] [blame] | 438 | |
Chandler Carruth | 58a71ed | 2011-12-12 04:26:04 +0000 | [diff] [blame] | 439 | switch (NewFn->getIntrinsicID()) { |
| 440 | default: |
Chris Lattner | 0bcbde4 | 2011-11-27 08:42:07 +0000 | [diff] [blame] | 441 | llvm_unreachable("Unknown function for CallInst upgrade."); |
Chandler Carruth | 58a71ed | 2011-12-12 04:26:04 +0000 | [diff] [blame] | 442 | |
Adrian Prantl | 87b7eb9 | 2014-10-01 18:55:02 +0000 | [diff] [blame] | 443 | // Upgrade debug intrinsics to use an additional DIExpression argument. |
| 444 | case Intrinsic::dbg_declare: { |
| 445 | auto NewCI = |
| 446 | Builder.CreateCall3(NewFn, CI->getArgOperand(0), CI->getArgOperand(1), |
| 447 | getExpression(CI->getArgOperand(1), F), Name); |
| 448 | NewCI->setDebugLoc(CI->getDebugLoc()); |
| 449 | CI->replaceAllUsesWith(NewCI); |
| 450 | CI->eraseFromParent(); |
| 451 | return; |
| 452 | } |
| 453 | case Intrinsic::dbg_value: { |
| 454 | auto NewCI = Builder.CreateCall4( |
| 455 | NewFn, CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2), |
| 456 | getExpression(CI->getArgOperand(2), F), Name); |
| 457 | NewCI->setDebugLoc(CI->getDebugLoc()); |
| 458 | CI->replaceAllUsesWith(NewCI); |
| 459 | CI->eraseFromParent(); |
| 460 | return; |
| 461 | } |
Chandler Carruth | 58a71ed | 2011-12-12 04:26:04 +0000 | [diff] [blame] | 462 | case Intrinsic::ctlz: |
Nuno Lopes | ad40c0a | 2012-05-22 15:25:31 +0000 | [diff] [blame] | 463 | case Intrinsic::cttz: |
Chandler Carruth | 58a71ed | 2011-12-12 04:26:04 +0000 | [diff] [blame] | 464 | assert(CI->getNumArgOperands() == 1 && |
| 465 | "Mismatch between function args and call args"); |
Chandler Carruth | 58a71ed | 2011-12-12 04:26:04 +0000 | [diff] [blame] | 466 | CI->replaceAllUsesWith(Builder.CreateCall2(NewFn, CI->getArgOperand(0), |
| 467 | Builder.getFalse(), Name)); |
| 468 | CI->eraseFromParent(); |
| 469 | return; |
Nadav Rotem | 17ee58a | 2012-06-10 18:42:51 +0000 | [diff] [blame] | 470 | |
Matt Arsenault | fbcbce4 | 2013-10-07 18:06:48 +0000 | [diff] [blame] | 471 | case Intrinsic::objectsize: |
| 472 | CI->replaceAllUsesWith(Builder.CreateCall2(NewFn, |
| 473 | CI->getArgOperand(0), |
| 474 | CI->getArgOperand(1), |
| 475 | Name)); |
| 476 | CI->eraseFromParent(); |
| 477 | return; |
| 478 | |
Joel Jones | b84f7be | 2012-07-18 00:02:16 +0000 | [diff] [blame] | 479 | case Intrinsic::ctpop: { |
| 480 | CI->replaceAllUsesWith(Builder.CreateCall(NewFn, CI->getArgOperand(0))); |
| 481 | CI->eraseFromParent(); |
| 482 | return; |
| 483 | } |
Joel Jones | 43cb878 | 2012-07-13 23:25:25 +0000 | [diff] [blame] | 484 | |
Craig Topper | 71dc02d | 2012-06-13 07:18:53 +0000 | [diff] [blame] | 485 | case Intrinsic::x86_xop_vfrcz_ss: |
| 486 | case Intrinsic::x86_xop_vfrcz_sd: |
| 487 | CI->replaceAllUsesWith(Builder.CreateCall(NewFn, CI->getArgOperand(1), |
| 488 | Name)); |
| 489 | CI->eraseFromParent(); |
| 490 | return; |
| 491 | |
Nadav Rotem | 17ee58a | 2012-06-10 18:42:51 +0000 | [diff] [blame] | 492 | case Intrinsic::x86_sse41_ptestc: |
| 493 | case Intrinsic::x86_sse41_ptestz: |
Craig Topper | 71dc02d | 2012-06-13 07:18:53 +0000 | [diff] [blame] | 494 | case Intrinsic::x86_sse41_ptestnzc: { |
Nadav Rotem | 17ee58a | 2012-06-10 18:42:51 +0000 | [diff] [blame] | 495 | // The arguments for these intrinsics used to be v4f32, and changed |
| 496 | // to v2i64. This is purely a nop, since those are bitwise intrinsics. |
| 497 | // So, the only thing required is a bitcast for both arguments. |
| 498 | // First, check the arguments have the old type. |
| 499 | Value *Arg0 = CI->getArgOperand(0); |
| 500 | if (Arg0->getType() != VectorType::get(Type::getFloatTy(C), 4)) |
| 501 | return; |
| 502 | |
| 503 | // Old intrinsic, add bitcasts |
| 504 | Value *Arg1 = CI->getArgOperand(1); |
| 505 | |
| 506 | Value *BC0 = |
| 507 | Builder.CreateBitCast(Arg0, |
| 508 | VectorType::get(Type::getInt64Ty(C), 2), |
| 509 | "cast"); |
| 510 | Value *BC1 = |
| 511 | Builder.CreateBitCast(Arg1, |
| 512 | VectorType::get(Type::getInt64Ty(C), 2), |
| 513 | "cast"); |
| 514 | |
| 515 | CallInst* NewCall = Builder.CreateCall2(NewFn, BC0, BC1, Name); |
| 516 | CI->replaceAllUsesWith(NewCall); |
| 517 | CI->eraseFromParent(); |
| 518 | return; |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 519 | } |
Chandler Carruth | 373b2b1 | 2014-09-06 10:00:01 +0000 | [diff] [blame] | 520 | |
| 521 | case Intrinsic::x86_sse41_pblendw: |
| 522 | case Intrinsic::x86_sse41_blendpd: |
| 523 | case Intrinsic::x86_sse41_blendps: |
| 524 | case Intrinsic::x86_sse41_insertps: |
| 525 | case Intrinsic::x86_sse41_dppd: |
| 526 | case Intrinsic::x86_sse41_dpps: |
| 527 | case Intrinsic::x86_sse41_mpsadbw: |
| 528 | case Intrinsic::x86_avx_blend_pd_256: |
| 529 | case Intrinsic::x86_avx_blend_ps_256: |
| 530 | case Intrinsic::x86_avx_dp_ps_256: |
| 531 | case Intrinsic::x86_avx2_pblendw: |
| 532 | case Intrinsic::x86_avx2_pblendd_128: |
| 533 | case Intrinsic::x86_avx2_pblendd_256: |
| 534 | case Intrinsic::x86_avx2_mpsadbw: { |
| 535 | // Need to truncate the last argument from i32 to i8 -- this argument models |
| 536 | // an inherently 8-bit immediate operand to these x86 instructions. |
| 537 | SmallVector<Value *, 4> Args(CI->arg_operands().begin(), |
| 538 | CI->arg_operands().end()); |
| 539 | |
| 540 | // Replace the last argument with a trunc. |
| 541 | Args.back() = Builder.CreateTrunc(Args.back(), Type::getInt8Ty(C), "trunc"); |
| 542 | |
| 543 | CallInst *NewCall = Builder.CreateCall(NewFn, Args); |
| 544 | CI->replaceAllUsesWith(NewCall); |
| 545 | CI->eraseFromParent(); |
| 546 | return; |
| 547 | } |
Craig Topper | 71dc02d | 2012-06-13 07:18:53 +0000 | [diff] [blame] | 548 | } |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 549 | } |
| 550 | |
Matt Arsenault | c4c9226 | 2013-07-20 17:46:00 +0000 | [diff] [blame] | 551 | // This tests each Function to determine if it needs upgrading. When we find |
| 552 | // one we are interested in, we then upgrade all calls to reflect the new |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 553 | // function. |
| 554 | void llvm::UpgradeCallsToIntrinsic(Function* F) { |
| 555 | assert(F && "Illegal attempt to upgrade a non-existent intrinsic."); |
| 556 | |
| 557 | // Upgrade the function and check if it is a totaly new function. |
Chris Lattner | 80ed9dc | 2011-06-18 06:05:24 +0000 | [diff] [blame] | 558 | Function *NewFn; |
Evan Cheng | 0e179d0 | 2007-12-17 22:33:23 +0000 | [diff] [blame] | 559 | if (UpgradeIntrinsicFunction(F, NewFn)) { |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 560 | if (NewFn != F) { |
| 561 | // Replace all uses to the old function with the new one if necessary. |
Chandler Carruth | cdf4788 | 2014-03-09 03:16:01 +0000 | [diff] [blame] | 562 | for (Value::user_iterator UI = F->user_begin(), UE = F->user_end(); |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 563 | UI != UE; ) { |
Chris Lattner | 80ed9dc | 2011-06-18 06:05:24 +0000 | [diff] [blame] | 564 | if (CallInst *CI = dyn_cast<CallInst>(*UI++)) |
Chandler Carruth | 7132e00 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 565 | UpgradeIntrinsicCall(CI, NewFn); |
| 566 | } |
| 567 | // Remove old function, no longer used, from the module. |
| 568 | F->eraseFromParent(); |
| 569 | } |
| 570 | } |
| 571 | } |
Devang Patel | 80ae349 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 572 | |
Manman Ren | 209b17c | 2013-09-28 00:22:27 +0000 | [diff] [blame] | 573 | void llvm::UpgradeInstWithTBAATag(Instruction *I) { |
Duncan P. N. Exon Smith | de36e80 | 2014-11-11 21:30:22 +0000 | [diff] [blame] | 574 | MDNode *MD = I->getMetadata(LLVMContext::MD_tbaa); |
Manman Ren | 209b17c | 2013-09-28 00:22:27 +0000 | [diff] [blame] | 575 | assert(MD && "UpgradeInstWithTBAATag should have a TBAA tag"); |
| 576 | // Check if the tag uses struct-path aware TBAA format. |
| 577 | if (isa<MDNode>(MD->getOperand(0)) && MD->getNumOperands() >= 3) |
| 578 | return; |
| 579 | |
| 580 | if (MD->getNumOperands() == 3) { |
| 581 | Value *Elts[] = { |
| 582 | MD->getOperand(0), |
| 583 | MD->getOperand(1) |
| 584 | }; |
| 585 | MDNode *ScalarType = MDNode::get(I->getContext(), Elts); |
| 586 | // Create a MDNode <ScalarType, ScalarType, offset 0, const> |
| 587 | Value *Elts2[] = { |
| 588 | ScalarType, ScalarType, |
| 589 | Constant::getNullValue(Type::getInt64Ty(I->getContext())), |
| 590 | MD->getOperand(2) |
| 591 | }; |
| 592 | I->setMetadata(LLVMContext::MD_tbaa, MDNode::get(I->getContext(), Elts2)); |
| 593 | } else { |
| 594 | // Create a MDNode <MD, MD, offset 0> |
| 595 | Value *Elts[] = {MD, MD, |
| 596 | Constant::getNullValue(Type::getInt64Ty(I->getContext()))}; |
| 597 | I->setMetadata(LLVMContext::MD_tbaa, MDNode::get(I->getContext(), Elts)); |
| 598 | } |
| 599 | } |
Matt Arsenault | b03bd4d | 2013-11-15 01:34:59 +0000 | [diff] [blame] | 600 | |
| 601 | Instruction *llvm::UpgradeBitCastInst(unsigned Opc, Value *V, Type *DestTy, |
| 602 | Instruction *&Temp) { |
| 603 | if (Opc != Instruction::BitCast) |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 604 | return nullptr; |
Matt Arsenault | b03bd4d | 2013-11-15 01:34:59 +0000 | [diff] [blame] | 605 | |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 606 | Temp = nullptr; |
Matt Arsenault | b03bd4d | 2013-11-15 01:34:59 +0000 | [diff] [blame] | 607 | Type *SrcTy = V->getType(); |
| 608 | if (SrcTy->isPtrOrPtrVectorTy() && DestTy->isPtrOrPtrVectorTy() && |
| 609 | SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace()) { |
| 610 | LLVMContext &Context = V->getContext(); |
| 611 | |
| 612 | // We have no information about target data layout, so we assume that |
| 613 | // the maximum pointer size is 64bit. |
| 614 | Type *MidTy = Type::getInt64Ty(Context); |
| 615 | Temp = CastInst::Create(Instruction::PtrToInt, V, MidTy); |
| 616 | |
| 617 | return CastInst::Create(Instruction::IntToPtr, Temp, DestTy); |
| 618 | } |
| 619 | |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 620 | return nullptr; |
Matt Arsenault | b03bd4d | 2013-11-15 01:34:59 +0000 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | Value *llvm::UpgradeBitCastExpr(unsigned Opc, Constant *C, Type *DestTy) { |
| 624 | if (Opc != Instruction::BitCast) |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 625 | return nullptr; |
Matt Arsenault | b03bd4d | 2013-11-15 01:34:59 +0000 | [diff] [blame] | 626 | |
| 627 | Type *SrcTy = C->getType(); |
| 628 | if (SrcTy->isPtrOrPtrVectorTy() && DestTy->isPtrOrPtrVectorTy() && |
| 629 | SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace()) { |
| 630 | LLVMContext &Context = C->getContext(); |
| 631 | |
| 632 | // We have no information about target data layout, so we assume that |
| 633 | // the maximum pointer size is 64bit. |
| 634 | Type *MidTy = Type::getInt64Ty(Context); |
| 635 | |
| 636 | return ConstantExpr::getIntToPtr(ConstantExpr::getPtrToInt(C, MidTy), |
| 637 | DestTy); |
| 638 | } |
| 639 | |
Craig Topper | c620761 | 2014-04-09 06:08:46 +0000 | [diff] [blame] | 640 | return nullptr; |
Matt Arsenault | b03bd4d | 2013-11-15 01:34:59 +0000 | [diff] [blame] | 641 | } |
Manman Ren | 8b4306c | 2013-12-02 21:29:56 +0000 | [diff] [blame] | 642 | |
| 643 | /// Check the debug info version number, if it is out-dated, drop the debug |
| 644 | /// info. Return true if module is modified. |
| 645 | bool llvm::UpgradeDebugInfo(Module &M) { |
Manman Ren | 2ebfb42 | 2014-01-16 01:51:12 +0000 | [diff] [blame] | 646 | unsigned Version = getDebugMetadataVersionFromModule(M); |
| 647 | if (Version == DEBUG_METADATA_VERSION) |
Manman Ren | 8b4306c | 2013-12-02 21:29:56 +0000 | [diff] [blame] | 648 | return false; |
| 649 | |
Manman Ren | 2ebfb42 | 2014-01-16 01:51:12 +0000 | [diff] [blame] | 650 | bool RetCode = StripDebugInfo(M); |
| 651 | if (RetCode) { |
| 652 | DiagnosticInfoDebugMetadataVersion DiagVersion(M, Version); |
| 653 | M.getContext().diagnose(DiagVersion); |
| 654 | } |
| 655 | return RetCode; |
Manman Ren | 8b4306c | 2013-12-02 21:29:56 +0000 | [diff] [blame] | 656 | } |
Eli Bendersky | 5d5e18d | 2014-06-25 15:41:00 +0000 | [diff] [blame] | 657 | |
| 658 | void llvm::UpgradeMDStringConstant(std::string &String) { |
| 659 | const std::string OldPrefix = "llvm.vectorizer."; |
Mark Heffernan | 9d20e42 | 2014-07-21 23:11:03 +0000 | [diff] [blame] | 660 | if (String == "llvm.vectorizer.unroll") { |
| 661 | String = "llvm.loop.interleave.count"; |
| 662 | } else if (String.find(OldPrefix) == 0) { |
| 663 | String.replace(0, OldPrefix.size(), "llvm.loop.vectorize."); |
Eli Bendersky | 5d5e18d | 2014-06-25 15:41:00 +0000 | [diff] [blame] | 664 | } |
| 665 | } |