LLVM  6.0.0svn
IntrinsicLowering.cpp
Go to the documentation of this file.
1 //===-- IntrinsicLowering.cpp - Intrinsic Lowering default implementation -===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the IntrinsicLowering class.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/ADT/SmallVector.h"
16 #include "llvm/IR/CallSite.h"
17 #include "llvm/IR/Constants.h"
18 #include "llvm/IR/DataLayout.h"
19 #include "llvm/IR/DerivedTypes.h"
20 #include "llvm/IR/IRBuilder.h"
21 #include "llvm/IR/Module.h"
22 #include "llvm/IR/Type.h"
25 using namespace llvm;
26 
27 template <class ArgIt>
28 static void EnsureFunctionExists(Module &M, const char *Name,
29  ArgIt ArgBegin, ArgIt ArgEnd,
30  Type *RetTy) {
31  // Insert a correctly-typed definition now.
32  std::vector<Type *> ParamTys;
33  for (ArgIt I = ArgBegin; I != ArgEnd; ++I)
34  ParamTys.push_back(I->getType());
35  M.getOrInsertFunction(Name, FunctionType::get(RetTy, ParamTys, false));
36 }
37 
39  const char *FName,
40  const char *DName, const char *LDName) {
41  // Insert definitions for all the floating point types.
42  switch((int)Fn.arg_begin()->getType()->getTypeID()) {
43  case Type::FloatTyID:
44  EnsureFunctionExists(M, FName, Fn.arg_begin(), Fn.arg_end(),
46  break;
47  case Type::DoubleTyID:
48  EnsureFunctionExists(M, DName, Fn.arg_begin(), Fn.arg_end(),
50  break;
51  case Type::X86_FP80TyID:
52  case Type::FP128TyID:
54  EnsureFunctionExists(M, LDName, Fn.arg_begin(), Fn.arg_end(),
55  Fn.arg_begin()->getType());
56  break;
57  }
58 }
59 
60 /// ReplaceCallWith - This function is used when we want to lower an intrinsic
61 /// call to a call of an external function. This handles hard cases such as
62 /// when there was already a prototype for the external function, and if that
63 /// prototype doesn't match the arguments we expect to pass in.
64 template <class ArgIt>
65 static CallInst *ReplaceCallWith(const char *NewFn, CallInst *CI,
66  ArgIt ArgBegin, ArgIt ArgEnd,
67  Type *RetTy) {
68  // If we haven't already looked up this function, check to see if the
69  // program already contains a function with this name.
70  Module *M = CI->getModule();
71  // Get or insert the definition now.
72  std::vector<Type *> ParamTys;
73  for (ArgIt I = ArgBegin; I != ArgEnd; ++I)
74  ParamTys.push_back((*I)->getType());
75  Constant* FCache = M->getOrInsertFunction(NewFn,
76  FunctionType::get(RetTy, ParamTys, false));
77 
78  IRBuilder<> Builder(CI->getParent(), CI->getIterator());
79  SmallVector<Value *, 8> Args(ArgBegin, ArgEnd);
80  CallInst *NewCI = Builder.CreateCall(FCache, Args);
81  NewCI->setName(CI->getName());
82  if (!CI->use_empty())
83  CI->replaceAllUsesWith(NewCI);
84  return NewCI;
85 }
86 
87 // VisualStudio defines setjmp as _setjmp
88 #if defined(_MSC_VER) && defined(setjmp) && \
89  !defined(setjmp_undefined_for_msvc)
90 # pragma push_macro("setjmp")
91 # undef setjmp
92 # define setjmp_undefined_for_msvc
93 #endif
94 
97  for (auto &F : M)
98  if (F.isDeclaration() && !F.use_empty())
99  switch (F.getIntrinsicID()) {
100  default: break;
101  case Intrinsic::setjmp:
102  EnsureFunctionExists(M, "setjmp", F.arg_begin(), F.arg_end(),
103  Type::getInt32Ty(M.getContext()));
104  break;
105  case Intrinsic::longjmp:
106  EnsureFunctionExists(M, "longjmp", F.arg_begin(), F.arg_end(),
107  Type::getVoidTy(M.getContext()));
108  break;
109  case Intrinsic::siglongjmp:
110  EnsureFunctionExists(M, "abort", F.arg_end(), F.arg_end(),
111  Type::getVoidTy(M.getContext()));
112  break;
113  case Intrinsic::memcpy:
114  M.getOrInsertFunction("memcpy",
115  Type::getInt8PtrTy(Context),
116  Type::getInt8PtrTy(Context),
117  Type::getInt8PtrTy(Context),
118  DL.getIntPtrType(Context));
119  break;
120  case Intrinsic::memmove:
121  M.getOrInsertFunction("memmove",
122  Type::getInt8PtrTy(Context),
123  Type::getInt8PtrTy(Context),
124  Type::getInt8PtrTy(Context),
125  DL.getIntPtrType(Context));
126  break;
127  case Intrinsic::memset:
128  M.getOrInsertFunction("memset",
129  Type::getInt8PtrTy(Context),
130  Type::getInt8PtrTy(Context),
131  Type::getInt32Ty(M.getContext()),
132  DL.getIntPtrType(Context));
133  break;
134  case Intrinsic::sqrt:
135  EnsureFPIntrinsicsExist(M, F, "sqrtf", "sqrt", "sqrtl");
136  break;
137  case Intrinsic::sin:
138  EnsureFPIntrinsicsExist(M, F, "sinf", "sin", "sinl");
139  break;
140  case Intrinsic::cos:
141  EnsureFPIntrinsicsExist(M, F, "cosf", "cos", "cosl");
142  break;
143  case Intrinsic::pow:
144  EnsureFPIntrinsicsExist(M, F, "powf", "pow", "powl");
145  break;
146  case Intrinsic::log:
147  EnsureFPIntrinsicsExist(M, F, "logf", "log", "logl");
148  break;
149  case Intrinsic::log2:
150  EnsureFPIntrinsicsExist(M, F, "log2f", "log2", "log2l");
151  break;
152  case Intrinsic::log10:
153  EnsureFPIntrinsicsExist(M, F, "log10f", "log10", "log10l");
154  break;
155  case Intrinsic::exp:
156  EnsureFPIntrinsicsExist(M, F, "expf", "exp", "expl");
157  break;
158  case Intrinsic::exp2:
159  EnsureFPIntrinsicsExist(M, F, "exp2f", "exp2", "exp2l");
160  break;
161  }
162 }
163 
164 /// LowerBSWAP - Emit the code to lower bswap of V before the specified
165 /// instruction IP.
167  assert(V->getType()->isIntegerTy() && "Can't bswap a non-integer type!");
168 
169  unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
170 
171  IRBuilder<> Builder(IP);
172 
173  switch(BitSize) {
174  default: llvm_unreachable("Unhandled type size of value to byteswap!");
175  case 16: {
176  Value *Tmp1 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8),
177  "bswap.2");
178  Value *Tmp2 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8),
179  "bswap.1");
180  V = Builder.CreateOr(Tmp1, Tmp2, "bswap.i16");
181  break;
182  }
183  case 32: {
184  Value *Tmp4 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 24),
185  "bswap.4");
186  Value *Tmp3 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8),
187  "bswap.3");
188  Value *Tmp2 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8),
189  "bswap.2");
190  Value *Tmp1 = Builder.CreateLShr(V,ConstantInt::get(V->getType(), 24),
191  "bswap.1");
192  Tmp3 = Builder.CreateAnd(Tmp3,
193  ConstantInt::get(Type::getInt32Ty(Context), 0xFF0000),
194  "bswap.and3");
195  Tmp2 = Builder.CreateAnd(Tmp2,
196  ConstantInt::get(Type::getInt32Ty(Context), 0xFF00),
197  "bswap.and2");
198  Tmp4 = Builder.CreateOr(Tmp4, Tmp3, "bswap.or1");
199  Tmp2 = Builder.CreateOr(Tmp2, Tmp1, "bswap.or2");
200  V = Builder.CreateOr(Tmp4, Tmp2, "bswap.i32");
201  break;
202  }
203  case 64: {
204  Value *Tmp8 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 56),
205  "bswap.8");
206  Value *Tmp7 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 40),
207  "bswap.7");
208  Value *Tmp6 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 24),
209  "bswap.6");
210  Value *Tmp5 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8),
211  "bswap.5");
212  Value* Tmp4 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8),
213  "bswap.4");
214  Value* Tmp3 = Builder.CreateLShr(V,
215  ConstantInt::get(V->getType(), 24),
216  "bswap.3");
217  Value* Tmp2 = Builder.CreateLShr(V,
218  ConstantInt::get(V->getType(), 40),
219  "bswap.2");
220  Value* Tmp1 = Builder.CreateLShr(V,
221  ConstantInt::get(V->getType(), 56),
222  "bswap.1");
223  Tmp7 = Builder.CreateAnd(Tmp7,
225  0xFF000000000000ULL),
226  "bswap.and7");
227  Tmp6 = Builder.CreateAnd(Tmp6,
229  0xFF0000000000ULL),
230  "bswap.and6");
231  Tmp5 = Builder.CreateAnd(Tmp5,
233  0xFF00000000ULL),
234  "bswap.and5");
235  Tmp4 = Builder.CreateAnd(Tmp4,
237  0xFF000000ULL),
238  "bswap.and4");
239  Tmp3 = Builder.CreateAnd(Tmp3,
241  0xFF0000ULL),
242  "bswap.and3");
243  Tmp2 = Builder.CreateAnd(Tmp2,
245  0xFF00ULL),
246  "bswap.and2");
247  Tmp8 = Builder.CreateOr(Tmp8, Tmp7, "bswap.or1");
248  Tmp6 = Builder.CreateOr(Tmp6, Tmp5, "bswap.or2");
249  Tmp4 = Builder.CreateOr(Tmp4, Tmp3, "bswap.or3");
250  Tmp2 = Builder.CreateOr(Tmp2, Tmp1, "bswap.or4");
251  Tmp8 = Builder.CreateOr(Tmp8, Tmp6, "bswap.or5");
252  Tmp4 = Builder.CreateOr(Tmp4, Tmp2, "bswap.or6");
253  V = Builder.CreateOr(Tmp8, Tmp4, "bswap.i64");
254  break;
255  }
256  }
257  return V;
258 }
259 
260 /// LowerCTPOP - Emit the code to lower ctpop of V before the specified
261 /// instruction IP.
263  assert(V->getType()->isIntegerTy() && "Can't ctpop a non-integer type!");
264 
265  static const uint64_t MaskValues[6] = {
266  0x5555555555555555ULL, 0x3333333333333333ULL,
267  0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL,
268  0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL
269  };
270 
271  IRBuilder<> Builder(IP);
272 
273  unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
274  unsigned WordSize = (BitSize + 63) / 64;
275  Value *Count = ConstantInt::get(V->getType(), 0);
276 
277  for (unsigned n = 0; n < WordSize; ++n) {
278  Value *PartValue = V;
279  for (unsigned i = 1, ct = 0; i < (BitSize>64 ? 64 : BitSize);
280  i <<= 1, ++ct) {
281  Value *MaskCst = ConstantInt::get(V->getType(), MaskValues[ct]);
282  Value *LHS = Builder.CreateAnd(PartValue, MaskCst, "cppop.and1");
283  Value *VShift = Builder.CreateLShr(PartValue,
284  ConstantInt::get(V->getType(), i),
285  "ctpop.sh");
286  Value *RHS = Builder.CreateAnd(VShift, MaskCst, "cppop.and2");
287  PartValue = Builder.CreateAdd(LHS, RHS, "ctpop.step");
288  }
289  Count = Builder.CreateAdd(PartValue, Count, "ctpop.part");
290  if (BitSize > 64) {
291  V = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 64),
292  "ctpop.part.sh");
293  BitSize -= 64;
294  }
295  }
296 
297  return Count;
298 }
299 
300 /// LowerCTLZ - Emit the code to lower ctlz of V before the specified
301 /// instruction IP.
303 
304  IRBuilder<> Builder(IP);
305 
306  unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
307  for (unsigned i = 1; i < BitSize; i <<= 1) {
308  Value *ShVal = ConstantInt::get(V->getType(), i);
309  ShVal = Builder.CreateLShr(V, ShVal, "ctlz.sh");
310  V = Builder.CreateOr(V, ShVal, "ctlz.step");
311  }
312 
313  V = Builder.CreateNot(V);
314  return LowerCTPOP(Context, V, IP);
315 }
316 
317 static void ReplaceFPIntrinsicWithCall(CallInst *CI, const char *Fname,
318  const char *Dname,
319  const char *LDname) {
320  CallSite CS(CI);
321  switch (CI->getArgOperand(0)->getType()->getTypeID()) {
322  default: llvm_unreachable("Invalid type in intrinsic");
323  case Type::FloatTyID:
324  ReplaceCallWith(Fname, CI, CS.arg_begin(), CS.arg_end(),
326  break;
327  case Type::DoubleTyID:
328  ReplaceCallWith(Dname, CI, CS.arg_begin(), CS.arg_end(),
330  break;
331  case Type::X86_FP80TyID:
332  case Type::FP128TyID:
333  case Type::PPC_FP128TyID:
334  ReplaceCallWith(LDname, CI, CS.arg_begin(), CS.arg_end(),
335  CI->getArgOperand(0)->getType());
336  break;
337  }
338 }
339 
341  IRBuilder<> Builder(CI);
342  LLVMContext &Context = CI->getContext();
343 
344  const Function *Callee = CI->getCalledFunction();
345  assert(Callee && "Cannot lower an indirect call!");
346 
347  CallSite CS(CI);
348  switch (Callee->getIntrinsicID()) {
350  report_fatal_error("Cannot lower a call to a non-intrinsic function '"+
351  Callee->getName() + "'!");
352  default:
353  report_fatal_error("Code generator does not support intrinsic function '"+
354  Callee->getName()+"'!");
355 
356  case Intrinsic::expect: {
357  // Just replace __builtin_expect(exp, c) with EXP.
358  Value *V = CI->getArgOperand(0);
359  CI->replaceAllUsesWith(V);
360  break;
361  }
362 
363  // The setjmp/longjmp intrinsics should only exist in the code if it was
364  // never optimized (ie, right out of the CFE), or if it has been hacked on
365  // by the lowerinvoke pass. In both cases, the right thing to do is to
366  // convert the call to an explicit setjmp or longjmp call.
367  case Intrinsic::setjmp: {
368  Value *V = ReplaceCallWith("setjmp", CI, CS.arg_begin(), CS.arg_end(),
369  Type::getInt32Ty(Context));
370  if (!CI->getType()->isVoidTy())
371  CI->replaceAllUsesWith(V);
372  break;
373  }
374  case Intrinsic::sigsetjmp:
375  if (!CI->getType()->isVoidTy())
377  break;
378 
379  case Intrinsic::longjmp: {
380  ReplaceCallWith("longjmp", CI, CS.arg_begin(), CS.arg_end(),
381  Type::getVoidTy(Context));
382  break;
383  }
384 
385  case Intrinsic::siglongjmp: {
386  // Insert the call to abort
387  ReplaceCallWith("abort", CI, CS.arg_end(), CS.arg_end(),
388  Type::getVoidTy(Context));
389  break;
390  }
391  case Intrinsic::ctpop:
392  CI->replaceAllUsesWith(LowerCTPOP(Context, CI->getArgOperand(0), CI));
393  break;
394 
395  case Intrinsic::bswap:
396  CI->replaceAllUsesWith(LowerBSWAP(Context, CI->getArgOperand(0), CI));
397  break;
398 
399  case Intrinsic::ctlz:
400  CI->replaceAllUsesWith(LowerCTLZ(Context, CI->getArgOperand(0), CI));
401  break;
402 
403  case Intrinsic::cttz: {
404  // cttz(x) -> ctpop(~X & (X-1))
405  Value *Src = CI->getArgOperand(0);
406  Value *NotSrc = Builder.CreateNot(Src);
407  NotSrc->setName(Src->getName() + ".not");
408  Value *SrcM1 = ConstantInt::get(Src->getType(), 1);
409  SrcM1 = Builder.CreateSub(Src, SrcM1);
410  Src = LowerCTPOP(Context, Builder.CreateAnd(NotSrc, SrcM1), CI);
411  CI->replaceAllUsesWith(Src);
412  break;
413  }
414 
415  case Intrinsic::stacksave:
416  case Intrinsic::stackrestore: {
417  if (!Warned)
418  errs() << "WARNING: this target does not support the llvm.stack"
419  << (Callee->getIntrinsicID() == Intrinsic::stacksave ?
420  "save" : "restore") << " intrinsic.\n";
421  Warned = true;
422  if (Callee->getIntrinsicID() == Intrinsic::stacksave)
424  break;
425  }
426 
427  case Intrinsic::get_dynamic_area_offset:
428  errs() << "WARNING: this target does not support the custom llvm.get."
429  "dynamic.area.offset. It is being lowered to a constant 0\n";
430  // Just lower it to a constant 0 because for most targets
431  // @llvm.get.dynamic.area.offset is lowered to zero.
433  break;
434  case Intrinsic::returnaddress:
435  case Intrinsic::frameaddress:
436  errs() << "WARNING: this target does not support the llvm."
437  << (Callee->getIntrinsicID() == Intrinsic::returnaddress ?
438  "return" : "frame") << "address intrinsic.\n";
439  CI->replaceAllUsesWith(
440  ConstantPointerNull::get(cast<PointerType>(CI->getType())));
441  break;
442  case Intrinsic::addressofreturnaddress:
443  errs() << "WARNING: this target does not support the "
444  "llvm.addressofreturnaddress intrinsic.\n";
445  CI->replaceAllUsesWith(
446  ConstantPointerNull::get(cast<PointerType>(CI->getType())));
447  break;
448 
449  case Intrinsic::prefetch:
450  break; // Simply strip out prefetches on unsupported architectures
451 
452  case Intrinsic::pcmarker:
453  break; // Simply strip out pcmarker on unsupported architectures
454  case Intrinsic::readcyclecounter: {
455  errs() << "WARNING: this target does not support the llvm.readcyclecoun"
456  << "ter intrinsic. It is being lowered to a constant 0\n";
458  break;
459  }
460 
461  case Intrinsic::dbg_declare:
462  break; // Simply strip out debugging intrinsics
463 
464  case Intrinsic::eh_typeid_for:
465  // Return something different to eh_selector.
467  break;
468 
469  case Intrinsic::annotation:
470  case Intrinsic::ptr_annotation:
471  // Just drop the annotation, but forward the value
472  CI->replaceAllUsesWith(CI->getOperand(0));
473  break;
474 
475  case Intrinsic::assume:
476  case Intrinsic::var_annotation:
477  break; // Strip out these intrinsics
478 
479  case Intrinsic::memcpy: {
480  Type *IntPtr = DL.getIntPtrType(Context);
481  Value *Size = Builder.CreateIntCast(CI->getArgOperand(2), IntPtr,
482  /* isSigned */ false);
483  Value *Ops[3];
484  Ops[0] = CI->getArgOperand(0);
485  Ops[1] = CI->getArgOperand(1);
486  Ops[2] = Size;
487  ReplaceCallWith("memcpy", CI, Ops, Ops+3, CI->getArgOperand(0)->getType());
488  break;
489  }
490  case Intrinsic::memmove: {
491  Type *IntPtr = DL.getIntPtrType(Context);
492  Value *Size = Builder.CreateIntCast(CI->getArgOperand(2), IntPtr,
493  /* isSigned */ false);
494  Value *Ops[3];
495  Ops[0] = CI->getArgOperand(0);
496  Ops[1] = CI->getArgOperand(1);
497  Ops[2] = Size;
498  ReplaceCallWith("memmove", CI, Ops, Ops+3, CI->getArgOperand(0)->getType());
499  break;
500  }
501  case Intrinsic::memset: {
502  Value *Op0 = CI->getArgOperand(0);
503  Type *IntPtr = DL.getIntPtrType(Op0->getType());
504  Value *Size = Builder.CreateIntCast(CI->getArgOperand(2), IntPtr,
505  /* isSigned */ false);
506  Value *Ops[3];
507  Ops[0] = Op0;
508  // Extend the amount to i32.
509  Ops[1] = Builder.CreateIntCast(CI->getArgOperand(1),
510  Type::getInt32Ty(Context),
511  /* isSigned */ false);
512  Ops[2] = Size;
513  ReplaceCallWith("memset", CI, Ops, Ops+3, CI->getArgOperand(0)->getType());
514  break;
515  }
516  case Intrinsic::sqrt: {
517  ReplaceFPIntrinsicWithCall(CI, "sqrtf", "sqrt", "sqrtl");
518  break;
519  }
520  case Intrinsic::log: {
521  ReplaceFPIntrinsicWithCall(CI, "logf", "log", "logl");
522  break;
523  }
524  case Intrinsic::log2: {
525  ReplaceFPIntrinsicWithCall(CI, "log2f", "log2", "log2l");
526  break;
527  }
528  case Intrinsic::log10: {
529  ReplaceFPIntrinsicWithCall(CI, "log10f", "log10", "log10l");
530  break;
531  }
532  case Intrinsic::exp: {
533  ReplaceFPIntrinsicWithCall(CI, "expf", "exp", "expl");
534  break;
535  }
536  case Intrinsic::exp2: {
537  ReplaceFPIntrinsicWithCall(CI, "exp2f", "exp2", "exp2l");
538  break;
539  }
540  case Intrinsic::pow: {
541  ReplaceFPIntrinsicWithCall(CI, "powf", "pow", "powl");
542  break;
543  }
544  case Intrinsic::sin: {
545  ReplaceFPIntrinsicWithCall(CI, "sinf", "sin", "sinl");
546  break;
547  }
548  case Intrinsic::cos: {
549  ReplaceFPIntrinsicWithCall(CI, "cosf", "cos", "cosl");
550  break;
551  }
552  case Intrinsic::floor: {
553  ReplaceFPIntrinsicWithCall(CI, "floorf", "floor", "floorl");
554  break;
555  }
556  case Intrinsic::ceil: {
557  ReplaceFPIntrinsicWithCall(CI, "ceilf", "ceil", "ceill");
558  break;
559  }
560  case Intrinsic::trunc: {
561  ReplaceFPIntrinsicWithCall(CI, "truncf", "trunc", "truncl");
562  break;
563  }
564  case Intrinsic::round: {
565  ReplaceFPIntrinsicWithCall(CI, "roundf", "round", "roundl");
566  break;
567  }
568  case Intrinsic::copysign: {
569  ReplaceFPIntrinsicWithCall(CI, "copysignf", "copysign", "copysignl");
570  break;
571  }
572  case Intrinsic::flt_rounds:
573  // Lower to "round to the nearest"
574  if (!CI->getType()->isVoidTy())
576  break;
577  case Intrinsic::invariant_start:
578  case Intrinsic::lifetime_start:
579  // Discard region information.
581  break;
582  case Intrinsic::invariant_end:
583  case Intrinsic::lifetime_end:
584  // Discard region information.
585  break;
586  }
587 
588  assert(CI->use_empty() &&
589  "Lowering should have eliminated any uses of the intrinsic call!");
590  CI->eraseFromParent();
591 }
592 
594  // Verify this is a simple bswap.
595  if (CI->getNumArgOperands() != 1 ||
596  CI->getType() != CI->getArgOperand(0)->getType() ||
597  !CI->getType()->isIntegerTy())
598  return false;
599 
600  IntegerType *Ty = dyn_cast<IntegerType>(CI->getType());
601  if (!Ty)
602  return false;
603 
604  // Okay, we can do this xform, do so now.
605  Module *M = CI->getModule();
606  Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Ty);
607 
608  Value *Op = CI->getArgOperand(0);
609  Op = CallInst::Create(Int, Op, CI->getName(), CI);
610 
611  CI->replaceAllUsesWith(Op);
612  CI->eraseFromParent();
613  return true;
614 }
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks &#39;this&#39; from the containing basic block and deletes it.
Definition: Instruction.cpp:69
static Type * getDoubleTy(LLVMContext &C)
Definition: Type.cpp:165
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVMContext & Context
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:103
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
Definition: Module.cpp:142
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
static CallInst * ReplaceCallWith(const char *NewFn, CallInst *CI, ArgIt ArgBegin, ArgIt ArgEnd, Type *RetTy)
ReplaceCallWith - This function is used when we want to lower an intrinsic call to a call of an exter...
2: 32-bit floating point type
Definition: Type.h:59
This class represents a function call, abstracting a target machine&#39;s calling convention.
static uint64_t round(uint64_t Acc, uint64_t Input)
Definition: xxhash.cpp:57
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:697
arg_iterator arg_end()
Definition: Function.h:604
4: 80-bit floating point type (X87)
Definition: Type.h:61
static CallInst * Create(Value *Func, ArrayRef< Value *> Args, ArrayRef< OperandBundleDef > Bundles=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:177
loop data prefetch
static Constant * getNullValue(Type *Ty)
Constructor to create a &#39;0&#39; constant of arbitrary type.
Definition: Constants.cpp:207
Value * CreateNot(Value *V, const Twine &Name="")
Definition: IRBuilder.h:1142
unsigned getNumArgOperands() const
Return the number of call arguments.
static Type * getFloatTy(LLVMContext &C)
Definition: Type.cpp:164
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:138
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:237
IterTy arg_end() const
Definition: CallSite.h:549
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:197
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:664
static void EnsureFunctionExists(Module &M, const char *Name, ArgIt ArgBegin, ArgIt ArgEnd, Type *RetTy)
static void ReplaceFPIntrinsicWithCall(CallInst *CI, const char *Fname, const char *Dname, const char *LDname)
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:889
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:284
#define F(x, y, z)
Definition: MD5.cpp:55
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:911
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:428
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Definition: Function.cpp:975
const char * Name
Value * getOperand(unsigned i) const
Definition: User.h:154
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1079
bool isVoidTy() const
Return true if this is &#39;void&#39;.
Definition: Type.h:141
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
Definition: DataLayout.cpp:702
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
Definition: Constants.cpp:1306
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
static Value * LowerBSWAP(LLVMContext &Context, Value *V, Instruction *IP)
LowerBSWAP - Emit the code to lower bswap of V before the specified instruction IP.
This is an important base class in LLVM.
Definition: Constant.h:42
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:161
static void EnsureFPIntrinsicsExist(Module &M, Function &Fn, const char *FName, const char *DName, const char *LDName)
6: 128-bit floating point type (two 64-bits, PowerPC)
Definition: Type.h:63
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:297
arg_iterator arg_begin()
Definition: Function.h:595
self_iterator getIterator()
Definition: ilist_node.h:82
Class to represent integer types.
Definition: DerivedTypes.h:40
static UndefValue * get(Type *T)
Static factory methods - Return an &#39;undef&#39; object of the specified type.
Definition: Constants.cpp:1320
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Definition: Type.cpp:220
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static Value * LowerCTPOP(LLVMContext &Context, Value *V, Instruction *IP)
LowerCTPOP - Emit the code to lower ctpop of V before the specified instruction IP.
IterTy arg_begin() const
Definition: CallSite.h:545
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
Definition: IRBuilder.h:1507
Module.h This file contains the declarations for the Module class.
void AddPrototypes(Module &M)
AddPrototypes - This method, if called, causes all of the prototypes that might be needed by an intri...
static Value * LowerCTLZ(LLVMContext &Context, Value *V, Instruction *IP)
LowerCTLZ - Emit the code to lower ctlz of V before the specified instruction IP. ...
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:560
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Definition: Function.h:167
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Definition: Instruction.cpp:57
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition: IRBuilder.h:1008
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
static bool LowerToByteSwap(CallInst *CI)
LowerToByteSwap - Replace a call instruction into a call to bswap intrinsic.
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:176
void LowerIntrinsicCall(CallInst *CI)
LowerIntrinsicCall - This method replaces a call with the LLVM function which should be used to imple...
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:218
#define I(x, y, z)
Definition: MD5.cpp:58
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1063
3: 64-bit floating point type
Definition: Type.h:60
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition: Type.cpp:115
LLVM Value Representation.
Definition: Value.h:73
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Definition: IRBuilder.h:1027
bool use_empty() const
Definition: Value.h:322
const BasicBlock * getParent() const
Definition: Instruction.h:66
5: 128-bit floating point type (112-bit mantissa)
Definition: Type.h:62