Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/CodeGen/IntrinsicLowering.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- IntrinsicLowering.cpp - Intrinsic Lowering default implementation -===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file implements the IntrinsicLowering class.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "llvm/CodeGen/IntrinsicLowering.h"
14
#include "llvm/ADT/SmallVector.h"
15
#include "llvm/IR/CallSite.h"
16
#include "llvm/IR/Constants.h"
17
#include "llvm/IR/DataLayout.h"
18
#include "llvm/IR/DerivedTypes.h"
19
#include "llvm/IR/IRBuilder.h"
20
#include "llvm/IR/Module.h"
21
#include "llvm/IR/Type.h"
22
#include "llvm/Support/ErrorHandling.h"
23
#include "llvm/Support/raw_ostream.h"
24
using namespace llvm;
25
26
/// This function is used when we want to lower an intrinsic call to a call of
27
/// an external function. This handles hard cases such as when there was already
28
/// a prototype for the external function, but that prototype doesn't match the
29
/// arguments we expect to pass in.
30
template <class ArgIt>
31
static CallInst *ReplaceCallWith(const char *NewFn, CallInst *CI,
32
                                 ArgIt ArgBegin, ArgIt ArgEnd,
33
0
                                 Type *RetTy) {
34
0
  // If we haven't already looked up this function, check to see if the
35
0
  // program already contains a function with this name.
36
0
  Module *M = CI->getModule();
37
0
  // Get or insert the definition now.
38
0
  std::vector<Type *> ParamTys;
39
0
  for (ArgIt I = ArgBegin; I != ArgEnd; ++I)
40
0
    ParamTys.push_back((*I)->getType());
41
0
  FunctionCallee FCache =
42
0
      M->getOrInsertFunction(NewFn, FunctionType::get(RetTy, ParamTys, false));
43
0
44
0
  IRBuilder<> Builder(CI->getParent(), CI->getIterator());
45
0
  SmallVector<Value *, 8> Args(ArgBegin, ArgEnd);
46
0
  CallInst *NewCI = Builder.CreateCall(FCache, Args);
47
0
  NewCI->setName(CI->getName());
48
0
  if (!CI->use_empty())
49
0
    CI->replaceAllUsesWith(NewCI);
50
0
  return NewCI;
51
0
}
Unexecuted instantiation: IntrinsicLowering.cpp:llvm::CallInst* ReplaceCallWith<llvm::Use*>(char const*, llvm::CallInst*, llvm::Use*, llvm::Use*, llvm::Type*)
Unexecuted instantiation: IntrinsicLowering.cpp:llvm::CallInst* ReplaceCallWith<llvm::Value**>(char const*, llvm::CallInst*, llvm::Value**, llvm::Value**, llvm::Type*)
52
53
// VisualStudio defines setjmp as _setjmp
54
#if defined(_MSC_VER) && defined(setjmp) && \
55
                         !defined(setjmp_undefined_for_msvc)
56
#  pragma push_macro("setjmp")
57
#  undef setjmp
58
#  define setjmp_undefined_for_msvc
59
#endif
60
61
/// Emit the code to lower bswap of V before the specified instruction IP.
62
6
static Value *LowerBSWAP(LLVMContext &Context, Value *V, Instruction *IP) {
63
6
  assert(V->getType()->isIntOrIntVectorTy() && "Can't bswap a non-integer type!");
64
6
65
6
  unsigned BitSize = V->getType()->getScalarSizeInBits();
66
6
67
6
  IRBuilder<> Builder(IP);
68
6
69
6
  switch(BitSize) {
70
6
  
default: 0
llvm_unreachable0
("Unhandled type size of value to byteswap!");
71
6
  case 16: {
72
2
    Value *Tmp1 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8),
73
2
                                    "bswap.2");
74
2
    Value *Tmp2 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8),
75
2
                                     "bswap.1");
76
2
    V = Builder.CreateOr(Tmp1, Tmp2, "bswap.i16");
77
2
    break;
78
6
  }
79
6
  case 32: {
80
2
    Value *Tmp4 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 24),
81
2
                                    "bswap.4");
82
2
    Value *Tmp3 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8),
83
2
                                    "bswap.3");
84
2
    Value *Tmp2 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8),
85
2
                                     "bswap.2");
86
2
    Value *Tmp1 = Builder.CreateLShr(V,ConstantInt::get(V->getType(), 24),
87
2
                                     "bswap.1");
88
2
    Tmp3 = Builder.CreateAnd(Tmp3,
89
2
                         ConstantInt::get(V->getType(), 0xFF0000),
90
2
                             "bswap.and3");
91
2
    Tmp2 = Builder.CreateAnd(Tmp2,
92
2
                           ConstantInt::get(V->getType(), 0xFF00),
93
2
                             "bswap.and2");
94
2
    Tmp4 = Builder.CreateOr(Tmp4, Tmp3, "bswap.or1");
95
2
    Tmp2 = Builder.CreateOr(Tmp2, Tmp1, "bswap.or2");
96
2
    V = Builder.CreateOr(Tmp4, Tmp2, "bswap.i32");
97
2
    break;
98
6
  }
99
6
  case 64: {
100
2
    Value *Tmp8 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 56),
101
2
                                    "bswap.8");
102
2
    Value *Tmp7 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 40),
103
2
                                    "bswap.7");
104
2
    Value *Tmp6 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 24),
105
2
                                    "bswap.6");
106
2
    Value *Tmp5 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8),
107
2
                                    "bswap.5");
108
2
    Value* Tmp4 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8),
109
2
                                     "bswap.4");
110
2
    Value* Tmp3 = Builder.CreateLShr(V,
111
2
                                     ConstantInt::get(V->getType(), 24),
112
2
                                     "bswap.3");
113
2
    Value* Tmp2 = Builder.CreateLShr(V,
114
2
                                     ConstantInt::get(V->getType(), 40),
115
2
                                     "bswap.2");
116
2
    Value* Tmp1 = Builder.CreateLShr(V,
117
2
                                     ConstantInt::get(V->getType(), 56),
118
2
                                     "bswap.1");
119
2
    Tmp7 = Builder.CreateAnd(Tmp7,
120
2
                             ConstantInt::get(V->getType(),
121
2
                                              0xFF000000000000ULL),
122
2
                             "bswap.and7");
123
2
    Tmp6 = Builder.CreateAnd(Tmp6,
124
2
                             ConstantInt::get(V->getType(),
125
2
                                              0xFF0000000000ULL),
126
2
                             "bswap.and6");
127
2
    Tmp5 = Builder.CreateAnd(Tmp5,
128
2
                        ConstantInt::get(V->getType(),
129
2
                             0xFF00000000ULL),
130
2
                             "bswap.and5");
131
2
    Tmp4 = Builder.CreateAnd(Tmp4,
132
2
                        ConstantInt::get(V->getType(),
133
2
                             0xFF000000ULL),
134
2
                             "bswap.and4");
135
2
    Tmp3 = Builder.CreateAnd(Tmp3,
136
2
                             ConstantInt::get(V->getType(),
137
2
                             0xFF0000ULL),
138
2
                             "bswap.and3");
139
2
    Tmp2 = Builder.CreateAnd(Tmp2,
140
2
                             ConstantInt::get(V->getType(),
141
2
                             0xFF00ULL),
142
2
                             "bswap.and2");
143
2
    Tmp8 = Builder.CreateOr(Tmp8, Tmp7, "bswap.or1");
144
2
    Tmp6 = Builder.CreateOr(Tmp6, Tmp5, "bswap.or2");
145
2
    Tmp4 = Builder.CreateOr(Tmp4, Tmp3, "bswap.or3");
146
2
    Tmp2 = Builder.CreateOr(Tmp2, Tmp1, "bswap.or4");
147
2
    Tmp8 = Builder.CreateOr(Tmp8, Tmp6, "bswap.or5");
148
2
    Tmp4 = Builder.CreateOr(Tmp4, Tmp2, "bswap.or6");
149
2
    V = Builder.CreateOr(Tmp8, Tmp4, "bswap.i64");
150
2
    break;
151
6
  }
152
6
  }
153
6
  return V;
154
6
}
155
156
/// Emit the code to lower ctpop of V before the specified instruction IP.
157
0
static Value *LowerCTPOP(LLVMContext &Context, Value *V, Instruction *IP) {
158
0
  assert(V->getType()->isIntegerTy() && "Can't ctpop a non-integer type!");
159
0
160
0
  static const uint64_t MaskValues[6] = {
161
0
    0x5555555555555555ULL, 0x3333333333333333ULL,
162
0
    0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL,
163
0
    0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL
164
0
  };
165
0
166
0
  IRBuilder<> Builder(IP);
167
0
168
0
  unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
169
0
  unsigned WordSize = (BitSize + 63) / 64;
170
0
  Value *Count = ConstantInt::get(V->getType(), 0);
171
0
172
0
  for (unsigned n = 0; n < WordSize; ++n) {
173
0
    Value *PartValue = V;
174
0
    for (unsigned i = 1, ct = 0; i < (BitSize>64 ? 64 : BitSize);
175
0
         i <<= 1, ++ct) {
176
0
      Value *MaskCst = ConstantInt::get(V->getType(), MaskValues[ct]);
177
0
      Value *LHS = Builder.CreateAnd(PartValue, MaskCst, "cppop.and1");
178
0
      Value *VShift = Builder.CreateLShr(PartValue,
179
0
                                        ConstantInt::get(V->getType(), i),
180
0
                                         "ctpop.sh");
181
0
      Value *RHS = Builder.CreateAnd(VShift, MaskCst, "cppop.and2");
182
0
      PartValue = Builder.CreateAdd(LHS, RHS, "ctpop.step");
183
0
    }
184
0
    Count = Builder.CreateAdd(PartValue, Count, "ctpop.part");
185
0
    if (BitSize > 64) {
186
0
      V = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 64),
187
0
                             "ctpop.part.sh");
188
0
      BitSize -= 64;
189
0
    }
190
0
  }
191
0
192
0
  return Count;
193
0
}
194
195
/// Emit the code to lower ctlz of V before the specified instruction IP.
196
0
static Value *LowerCTLZ(LLVMContext &Context, Value *V, Instruction *IP) {
197
0
198
0
  IRBuilder<> Builder(IP);
199
0
200
0
  unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
201
0
  for (unsigned i = 1; i < BitSize; i <<= 1) {
202
0
    Value *ShVal = ConstantInt::get(V->getType(), i);
203
0
    ShVal = Builder.CreateLShr(V, ShVal, "ctlz.sh");
204
0
    V = Builder.CreateOr(V, ShVal, "ctlz.step");
205
0
  }
206
0
207
0
  V = Builder.CreateNot(V);
208
0
  return LowerCTPOP(Context, V, IP);
209
0
}
210
211
static void ReplaceFPIntrinsicWithCall(CallInst *CI, const char *Fname,
212
                                       const char *Dname,
213
0
                                       const char *LDname) {
214
0
  CallSite CS(CI);
215
0
  switch (CI->getArgOperand(0)->getType()->getTypeID()) {
216
0
  default: llvm_unreachable("Invalid type in intrinsic");
217
0
  case Type::FloatTyID:
218
0
    ReplaceCallWith(Fname, CI, CS.arg_begin(), CS.arg_end(),
219
0
                  Type::getFloatTy(CI->getContext()));
220
0
    break;
221
0
  case Type::DoubleTyID:
222
0
    ReplaceCallWith(Dname, CI, CS.arg_begin(), CS.arg_end(),
223
0
                  Type::getDoubleTy(CI->getContext()));
224
0
    break;
225
0
  case Type::X86_FP80TyID:
226
0
  case Type::FP128TyID:
227
0
  case Type::PPC_FP128TyID:
228
0
    ReplaceCallWith(LDname, CI, CS.arg_begin(), CS.arg_end(),
229
0
                  CI->getArgOperand(0)->getType());
230
0
    break;
231
0
  }
232
0
}
233
234
6
void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
235
6
  IRBuilder<> Builder(CI);
236
6
  LLVMContext &Context = CI->getContext();
237
6
238
6
  const Function *Callee = CI->getCalledFunction();
239
6
  assert(Callee && "Cannot lower an indirect call!");
240
6
241
6
  CallSite CS(CI);
242
6
  switch (Callee->getIntrinsicID()) {
243
6
  case Intrinsic::not_intrinsic:
244
0
    report_fatal_error("Cannot lower a call to a non-intrinsic function '"+
245
0
                      Callee->getName() + "'!");
246
6
  default:
247
0
    report_fatal_error("Code generator does not support intrinsic function '"+
248
0
                      Callee->getName()+"'!");
249
6
250
6
  case Intrinsic::expect: {
251
0
    // Just replace __builtin_expect(exp, c) with EXP.
252
0
    Value *V = CI->getArgOperand(0);
253
0
    CI->replaceAllUsesWith(V);
254
0
    break;
255
6
  }
256
6
257
6
    // The setjmp/longjmp intrinsics should only exist in the code if it was
258
6
    // never optimized (ie, right out of the CFE), or if it has been hacked on
259
6
    // by the lowerinvoke pass.  In both cases, the right thing to do is to
260
6
    // convert the call to an explicit setjmp or longjmp call.
261
6
  case Intrinsic::setjmp: {
262
0
    Value *V = ReplaceCallWith("setjmp", CI, CS.arg_begin(), CS.arg_end(),
263
0
                               Type::getInt32Ty(Context));
264
0
    if (!CI->getType()->isVoidTy())
265
0
      CI->replaceAllUsesWith(V);
266
0
    break;
267
6
  }
268
6
  case Intrinsic::sigsetjmp:
269
0
     if (!CI->getType()->isVoidTy())
270
0
       CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
271
0
     break;
272
6
273
6
  case Intrinsic::longjmp: {
274
0
    ReplaceCallWith("longjmp", CI, CS.arg_begin(), CS.arg_end(),
275
0
                    Type::getVoidTy(Context));
276
0
    break;
277
6
  }
278
6
279
6
  case Intrinsic::siglongjmp: {
280
0
    // Insert the call to abort
281
0
    ReplaceCallWith("abort", CI, CS.arg_end(), CS.arg_end(),
282
0
                    Type::getVoidTy(Context));
283
0
    break;
284
6
  }
285
6
  case Intrinsic::ctpop:
286
0
    CI->replaceAllUsesWith(LowerCTPOP(Context, CI->getArgOperand(0), CI));
287
0
    break;
288
6
289
6
  case Intrinsic::bswap:
290
6
    CI->replaceAllUsesWith(LowerBSWAP(Context, CI->getArgOperand(0), CI));
291
6
    break;
292
6
293
6
  case Intrinsic::ctlz:
294
0
    CI->replaceAllUsesWith(LowerCTLZ(Context, CI->getArgOperand(0), CI));
295
0
    break;
296
6
297
6
  case Intrinsic::cttz: {
298
0
    // cttz(x) -> ctpop(~X & (X-1))
299
0
    Value *Src = CI->getArgOperand(0);
300
0
    Value *NotSrc = Builder.CreateNot(Src);
301
0
    NotSrc->setName(Src->getName() + ".not");
302
0
    Value *SrcM1 = ConstantInt::get(Src->getType(), 1);
303
0
    SrcM1 = Builder.CreateSub(Src, SrcM1);
304
0
    Src = LowerCTPOP(Context, Builder.CreateAnd(NotSrc, SrcM1), CI);
305
0
    CI->replaceAllUsesWith(Src);
306
0
    break;
307
6
  }
308
6
309
6
  case Intrinsic::stacksave:
310
0
  case Intrinsic::stackrestore: {
311
0
    if (!Warned)
312
0
      errs() << "WARNING: this target does not support the llvm.stack"
313
0
             << (Callee->getIntrinsicID() == Intrinsic::stacksave ?
314
0
               "save" : "restore") << " intrinsic.\n";
315
0
    Warned = true;
316
0
    if (Callee->getIntrinsicID() == Intrinsic::stacksave)
317
0
      CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
318
0
    break;
319
0
  }
320
0
321
0
  case Intrinsic::get_dynamic_area_offset:
322
0
    errs() << "WARNING: this target does not support the custom llvm.get."
323
0
              "dynamic.area.offset.  It is being lowered to a constant 0\n";
324
0
    // Just lower it to a constant 0 because for most targets
325
0
    // @llvm.get.dynamic.area.offset is lowered to zero.
326
0
    CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 0));
327
0
    break;
328
0
  case Intrinsic::returnaddress:
329
0
  case Intrinsic::frameaddress:
330
0
    errs() << "WARNING: this target does not support the llvm."
331
0
           << (Callee->getIntrinsicID() == Intrinsic::returnaddress ?
332
0
             "return" : "frame") << "address intrinsic.\n";
333
0
    CI->replaceAllUsesWith(
334
0
        ConstantPointerNull::get(cast<PointerType>(CI->getType())));
335
0
    break;
336
0
  case Intrinsic::addressofreturnaddress:
337
0
    errs() << "WARNING: this target does not support the "
338
0
              "llvm.addressofreturnaddress intrinsic.\n";
339
0
    CI->replaceAllUsesWith(
340
0
        ConstantPointerNull::get(cast<PointerType>(CI->getType())));
341
0
    break;
342
0
343
0
  case Intrinsic::prefetch:
344
0
    break;    // Simply strip out prefetches on unsupported architectures
345
0
346
0
  case Intrinsic::pcmarker:
347
0
    break;    // Simply strip out pcmarker on unsupported architectures
348
0
  case Intrinsic::readcyclecounter: {
349
0
    errs() << "WARNING: this target does not support the llvm.readcyclecoun"
350
0
           << "ter intrinsic.  It is being lowered to a constant 0\n";
351
0
    CI->replaceAllUsesWith(ConstantInt::get(Type::getInt64Ty(Context), 0));
352
0
    break;
353
0
  }
354
0
355
0
  case Intrinsic::dbg_declare:
356
0
  case Intrinsic::dbg_label:
357
0
    break;    // Simply strip out debugging intrinsics
358
0
359
0
  case Intrinsic::eh_typeid_for:
360
0
    // Return something different to eh_selector.
361
0
    CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1));
362
0
    break;
363
0
364
0
  case Intrinsic::annotation:
365
0
  case Intrinsic::ptr_annotation:
366
0
    // Just drop the annotation, but forward the value
367
0
    CI->replaceAllUsesWith(CI->getOperand(0));
368
0
    break;
369
0
370
0
  case Intrinsic::assume:
371
0
  case Intrinsic::var_annotation:
372
0
    break;   // Strip out these intrinsics
373
0
374
0
  case Intrinsic::memcpy: {
375
0
    Type *IntPtr = DL.getIntPtrType(Context);
376
0
    Value *Size = Builder.CreateIntCast(CI->getArgOperand(2), IntPtr,
377
0
                                        /* isSigned */ false);
378
0
    Value *Ops[3];
379
0
    Ops[0] = CI->getArgOperand(0);
380
0
    Ops[1] = CI->getArgOperand(1);
381
0
    Ops[2] = Size;
382
0
    ReplaceCallWith("memcpy", CI, Ops, Ops+3, CI->getArgOperand(0)->getType());
383
0
    break;
384
0
  }
385
0
  case Intrinsic::memmove: {
386
0
    Type *IntPtr = DL.getIntPtrType(Context);
387
0
    Value *Size = Builder.CreateIntCast(CI->getArgOperand(2), IntPtr,
388
0
                                        /* isSigned */ false);
389
0
    Value *Ops[3];
390
0
    Ops[0] = CI->getArgOperand(0);
391
0
    Ops[1] = CI->getArgOperand(1);
392
0
    Ops[2] = Size;
393
0
    ReplaceCallWith("memmove", CI, Ops, Ops+3, CI->getArgOperand(0)->getType());
394
0
    break;
395
0
  }
396
0
  case Intrinsic::memset: {
397
0
    Value *Op0 = CI->getArgOperand(0);
398
0
    Type *IntPtr = DL.getIntPtrType(Op0->getType());
399
0
    Value *Size = Builder.CreateIntCast(CI->getArgOperand(2), IntPtr,
400
0
                                        /* isSigned */ false);
401
0
    Value *Ops[3];
402
0
    Ops[0] = Op0;
403
0
    // Extend the amount to i32.
404
0
    Ops[1] = Builder.CreateIntCast(CI->getArgOperand(1),
405
0
                                   Type::getInt32Ty(Context),
406
0
                                   /* isSigned */ false);
407
0
    Ops[2] = Size;
408
0
    ReplaceCallWith("memset", CI, Ops, Ops+3, CI->getArgOperand(0)->getType());
409
0
    break;
410
0
  }
411
0
  case Intrinsic::sqrt: {
412
0
    ReplaceFPIntrinsicWithCall(CI, "sqrtf", "sqrt", "sqrtl");
413
0
    break;
414
0
  }
415
0
  case Intrinsic::log: {
416
0
    ReplaceFPIntrinsicWithCall(CI, "logf", "log", "logl");
417
0
    break;
418
0
  }
419
0
  case Intrinsic::log2: {
420
0
    ReplaceFPIntrinsicWithCall(CI, "log2f", "log2", "log2l");
421
0
    break;
422
0
  }
423
0
  case Intrinsic::log10: {
424
0
    ReplaceFPIntrinsicWithCall(CI, "log10f", "log10", "log10l");
425
0
    break;
426
0
  }
427
0
  case Intrinsic::exp: {
428
0
    ReplaceFPIntrinsicWithCall(CI, "expf", "exp", "expl");
429
0
    break;
430
0
  }
431
0
  case Intrinsic::exp2: {
432
0
    ReplaceFPIntrinsicWithCall(CI, "exp2f", "exp2", "exp2l");
433
0
    break;
434
0
  }
435
0
  case Intrinsic::pow: {
436
0
    ReplaceFPIntrinsicWithCall(CI, "powf", "pow", "powl");
437
0
    break;
438
0
  }
439
0
  case Intrinsic::sin: {
440
0
    ReplaceFPIntrinsicWithCall(CI, "sinf", "sin", "sinl");
441
0
    break;
442
0
  }
443
0
  case Intrinsic::cos: {
444
0
    ReplaceFPIntrinsicWithCall(CI, "cosf", "cos", "cosl");
445
0
    break;
446
0
  }
447
0
  case Intrinsic::floor: {
448
0
    ReplaceFPIntrinsicWithCall(CI, "floorf", "floor", "floorl");
449
0
    break;
450
0
  }
451
0
  case Intrinsic::ceil: {
452
0
    ReplaceFPIntrinsicWithCall(CI, "ceilf", "ceil", "ceill");
453
0
    break;
454
0
  }
455
0
  case Intrinsic::trunc: {
456
0
    ReplaceFPIntrinsicWithCall(CI, "truncf", "trunc", "truncl");
457
0
    break;
458
0
  }
459
0
  case Intrinsic::round: {
460
0
    ReplaceFPIntrinsicWithCall(CI, "roundf", "round", "roundl");
461
0
    break;
462
0
  }
463
0
  case Intrinsic::copysign: {
464
0
    ReplaceFPIntrinsicWithCall(CI, "copysignf", "copysign", "copysignl");
465
0
    break;
466
0
  }
467
0
  case Intrinsic::flt_rounds:
468
0
     // Lower to "round to the nearest"
469
0
     if (!CI->getType()->isVoidTy())
470
0
       CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1));
471
0
     break;
472
0
  case Intrinsic::invariant_start:
473
0
  case Intrinsic::lifetime_start:
474
0
    // Discard region information.
475
0
    CI->replaceAllUsesWith(UndefValue::get(CI->getType()));
476
0
    break;
477
0
  case Intrinsic::invariant_end:
478
0
  case Intrinsic::lifetime_end:
479
0
    // Discard region information.
480
0
    break;
481
6
  }
482
6
483
6
  assert(CI->use_empty() &&
484
6
         "Lowering should have eliminated any uses of the intrinsic call!");
485
6
  CI->eraseFromParent();
486
6
}
487
488
27
bool IntrinsicLowering::LowerToByteSwap(CallInst *CI) {
489
27
  // Verify this is a simple bswap.
490
27
  if (CI->getNumArgOperands() != 1 ||
491
27
      CI->getType() != CI->getArgOperand(0)->getType() ||
492
27
      !CI->getType()->isIntegerTy())
493
0
    return false;
494
27
495
27
  IntegerType *Ty = dyn_cast<IntegerType>(CI->getType());
496
27
  if (!Ty)
497
0
    return false;
498
27
499
27
  // Okay, we can do this xform, do so now.
500
27
  Module *M = CI->getModule();
501
27
  Function *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Ty);
502
27
503
27
  Value *Op = CI->getArgOperand(0);
504
27
  Op = CallInst::Create(Int, Op, CI->getName(), CI);
505
27
506
27
  CI->replaceAllUsesWith(Op);
507
27
  CI->eraseFromParent();
508
27
  return true;
509
27
}