Lines Matching +full:lower +full:- +full:case

1 //===-- IntrinsicLowering.cpp - Intrinsic Lowering default implementation -===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
25 /// This function is used when we want to lower an intrinsic call to a call of
35 Module *M = CI->getModule(); in ReplaceCallWith()
39 ParamTys.push_back((*I)->getType()); in ReplaceCallWith()
41 M->getOrInsertFunction(NewFn, FunctionType::get(RetTy, ParamTys, false)); in ReplaceCallWith()
43 IRBuilder<> Builder(CI->getParent(), CI->getIterator()); in ReplaceCallWith()
46 NewCI->setName(CI->getName()); in ReplaceCallWith()
47 if (!CI->use_empty()) in ReplaceCallWith()
48 CI->replaceAllUsesWith(NewCI); in ReplaceCallWith()
52 /// Emit the code to lower bswap of V before the specified instruction IP.
54 assert(V->getType()->isIntOrIntVectorTy() && "Can't bswap a non-integer type!"); in LowerBSWAP()
56 unsigned BitSize = V->getType()->getScalarSizeInBits(); in LowerBSWAP()
62 case 16: { in LowerBSWAP()
63 Value *Tmp1 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8), in LowerBSWAP()
65 Value *Tmp2 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8), in LowerBSWAP()
70 case 32: { in LowerBSWAP()
71 Value *Tmp4 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 24), in LowerBSWAP()
73 Value *Tmp3 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8), in LowerBSWAP()
75 Value *Tmp2 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8), in LowerBSWAP()
77 Value *Tmp1 = Builder.CreateLShr(V,ConstantInt::get(V->getType(), 24), in LowerBSWAP()
80 ConstantInt::get(V->getType(), 0xFF0000), in LowerBSWAP()
83 ConstantInt::get(V->getType(), 0xFF00), in LowerBSWAP()
90 case 64: { in LowerBSWAP()
91 Value *Tmp8 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 56), in LowerBSWAP()
93 Value *Tmp7 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 40), in LowerBSWAP()
95 Value *Tmp6 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 24), in LowerBSWAP()
97 Value *Tmp5 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8), in LowerBSWAP()
99 Value* Tmp4 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8), in LowerBSWAP()
102 ConstantInt::get(V->getType(), 24), in LowerBSWAP()
105 ConstantInt::get(V->getType(), 40), in LowerBSWAP()
108 ConstantInt::get(V->getType(), 56), in LowerBSWAP()
111 ConstantInt::get(V->getType(), in LowerBSWAP()
115 ConstantInt::get(V->getType(), in LowerBSWAP()
119 ConstantInt::get(V->getType(), in LowerBSWAP()
123 ConstantInt::get(V->getType(), in LowerBSWAP()
127 ConstantInt::get(V->getType(), in LowerBSWAP()
131 ConstantInt::get(V->getType(), in LowerBSWAP()
147 /// Emit the code to lower ctpop of V before the specified instruction IP.
149 assert(V->getType()->isIntegerTy() && "Can't ctpop a non-integer type!"); in LowerCTPOP()
159 unsigned BitSize = V->getType()->getPrimitiveSizeInBits(); in LowerCTPOP()
161 Value *Count = ConstantInt::get(V->getType(), 0); in LowerCTPOP()
167 Value *MaskCst = ConstantInt::get(V->getType(), MaskValues[ct]); in LowerCTPOP()
170 ConstantInt::get(V->getType(), i), in LowerCTPOP()
177 V = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 64), in LowerCTPOP()
179 BitSize -= 64; in LowerCTPOP()
186 /// Emit the code to lower ctlz of V before the specified instruction IP.
191 unsigned BitSize = V->getType()->getPrimitiveSizeInBits(); in LowerCTLZ()
193 Value *ShVal = ConstantInt::get(V->getType(), i); in LowerCTLZ()
205 switch (CI->getArgOperand(0)->getType()->getTypeID()) { in ReplaceFPIntrinsicWithCall()
207 case Type::FloatTyID: in ReplaceFPIntrinsicWithCall()
208 ReplaceCallWith(Fname, CI, CI->arg_begin(), CI->arg_end(), in ReplaceFPIntrinsicWithCall()
209 Type::getFloatTy(CI->getContext())); in ReplaceFPIntrinsicWithCall()
211 case Type::DoubleTyID: in ReplaceFPIntrinsicWithCall()
212 ReplaceCallWith(Dname, CI, CI->arg_begin(), CI->arg_end(), in ReplaceFPIntrinsicWithCall()
213 Type::getDoubleTy(CI->getContext())); in ReplaceFPIntrinsicWithCall()
215 case Type::X86_FP80TyID: in ReplaceFPIntrinsicWithCall()
216 case Type::FP128TyID: in ReplaceFPIntrinsicWithCall()
217 case Type::PPC_FP128TyID: in ReplaceFPIntrinsicWithCall()
218 ReplaceCallWith(LDname, CI, CI->arg_begin(), CI->arg_end(), in ReplaceFPIntrinsicWithCall()
219 CI->getArgOperand(0)->getType()); in ReplaceFPIntrinsicWithCall()
226 LLVMContext &Context = CI->getContext(); in LowerIntrinsicCall()
228 const Function *Callee = CI->getCalledFunction(); in LowerIntrinsicCall()
229 assert(Callee && "Cannot lower an indirect call!"); in LowerIntrinsicCall()
231 switch (Callee->getIntrinsicID()) { in LowerIntrinsicCall()
232 case Intrinsic::not_intrinsic: in LowerIntrinsicCall()
233 report_fatal_error("Cannot lower a call to a non-intrinsic function '"+ in LowerIntrinsicCall()
234 Callee->getName() + "'!"); in LowerIntrinsicCall()
237 Callee->getName()+"'!"); in LowerIntrinsicCall()
239 case Intrinsic::expect: { in LowerIntrinsicCall()
241 Value *V = CI->getArgOperand(0); in LowerIntrinsicCall()
242 CI->replaceAllUsesWith(V); in LowerIntrinsicCall()
246 case Intrinsic::allow_runtime_check: in LowerIntrinsicCall()
247 case Intrinsic::allow_ubsan_check: in LowerIntrinsicCall()
248 CI->replaceAllUsesWith(ConstantInt::getTrue(CI->getType())); in LowerIntrinsicCall()
251 case Intrinsic::ctpop: in LowerIntrinsicCall()
252 CI->replaceAllUsesWith(LowerCTPOP(Context, CI->getArgOperand(0), CI)); in LowerIntrinsicCall()
255 case Intrinsic::bswap: in LowerIntrinsicCall()
256 CI->replaceAllUsesWith(LowerBSWAP(Context, CI->getArgOperand(0), CI)); in LowerIntrinsicCall()
259 case Intrinsic::ctlz: in LowerIntrinsicCall()
260 CI->replaceAllUsesWith(LowerCTLZ(Context, CI->getArgOperand(0), CI)); in LowerIntrinsicCall()
263 case Intrinsic::cttz: { in LowerIntrinsicCall()
264 // cttz(x) -> ctpop(~X & (X-1)) in LowerIntrinsicCall()
265 Value *Src = CI->getArgOperand(0); in LowerIntrinsicCall()
267 NotSrc->setName(Src->getName() + ".not"); in LowerIntrinsicCall()
268 Value *SrcM1 = ConstantInt::get(Src->getType(), 1); in LowerIntrinsicCall()
271 CI->replaceAllUsesWith(Src); in LowerIntrinsicCall()
275 case Intrinsic::stacksave: in LowerIntrinsicCall()
276 case Intrinsic::stackrestore: { in LowerIntrinsicCall()
279 << (Callee->getIntrinsicID() == Intrinsic::stacksave ? in LowerIntrinsicCall()
282 if (Callee->getIntrinsicID() == Intrinsic::stacksave) in LowerIntrinsicCall()
283 CI->replaceAllUsesWith(Constant::getNullValue(CI->getType())); in LowerIntrinsicCall()
287 case Intrinsic::get_dynamic_area_offset: in LowerIntrinsicCall()
290 // Just lower it to a constant 0 because for most targets in LowerIntrinsicCall()
292 CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 0)); in LowerIntrinsicCall()
294 case Intrinsic::returnaddress: in LowerIntrinsicCall()
295 case Intrinsic::frameaddress: in LowerIntrinsicCall()
297 << (Callee->getIntrinsicID() == Intrinsic::returnaddress ? in LowerIntrinsicCall()
299 CI->replaceAllUsesWith( in LowerIntrinsicCall()
300 ConstantPointerNull::get(cast<PointerType>(CI->getType()))); in LowerIntrinsicCall()
302 case Intrinsic::addressofreturnaddress: in LowerIntrinsicCall()
305 CI->replaceAllUsesWith( in LowerIntrinsicCall()
306 ConstantPointerNull::get(cast<PointerType>(CI->getType()))); in LowerIntrinsicCall()
309 case Intrinsic::prefetch: in LowerIntrinsicCall()
312 case Intrinsic::pcmarker: in LowerIntrinsicCall()
314 case Intrinsic::readcyclecounter: { in LowerIntrinsicCall()
317 CI->replaceAllUsesWith(ConstantInt::get(Type::getInt64Ty(Context), 0)); in LowerIntrinsicCall()
320 case Intrinsic::readsteadycounter: { in LowerIntrinsicCall()
323 CI->replaceAllUsesWith(ConstantInt::get(Type::getInt64Ty(Context), 0)); in LowerIntrinsicCall()
327 case Intrinsic::dbg_declare: in LowerIntrinsicCall()
328 case Intrinsic::dbg_label: in LowerIntrinsicCall()
331 case Intrinsic::eh_typeid_for: in LowerIntrinsicCall()
333 CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1)); in LowerIntrinsicCall()
336 case Intrinsic::annotation: in LowerIntrinsicCall()
337 case Intrinsic::ptr_annotation: in LowerIntrinsicCall()
339 CI->replaceAllUsesWith(CI->getOperand(0)); in LowerIntrinsicCall()
342 case Intrinsic::assume: in LowerIntrinsicCall()
343 case Intrinsic::experimental_noalias_scope_decl: in LowerIntrinsicCall()
344 case Intrinsic::var_annotation: in LowerIntrinsicCall()
347 case Intrinsic::memcpy: { in LowerIntrinsicCall()
349 Value *Size = Builder.CreateIntCast(CI->getArgOperand(2), IntPtr, in LowerIntrinsicCall()
352 Ops[0] = CI->getArgOperand(0); in LowerIntrinsicCall()
353 Ops[1] = CI->getArgOperand(1); in LowerIntrinsicCall()
355 ReplaceCallWith("memcpy", CI, Ops, Ops+3, CI->getArgOperand(0)->getType()); in LowerIntrinsicCall()
358 case Intrinsic::memmove: { in LowerIntrinsicCall()
360 Value *Size = Builder.CreateIntCast(CI->getArgOperand(2), IntPtr, in LowerIntrinsicCall()
363 Ops[0] = CI->getArgOperand(0); in LowerIntrinsicCall()
364 Ops[1] = CI->getArgOperand(1); in LowerIntrinsicCall()
366 ReplaceCallWith("memmove", CI, Ops, Ops+3, CI->getArgOperand(0)->getType()); in LowerIntrinsicCall()
369 case Intrinsic::memset: { in LowerIntrinsicCall()
370 Value *Op0 = CI->getArgOperand(0); in LowerIntrinsicCall()
371 Type *IntPtr = DL.getIntPtrType(Op0->getType()); in LowerIntrinsicCall()
372 Value *Size = Builder.CreateIntCast(CI->getArgOperand(2), IntPtr, in LowerIntrinsicCall()
377 Ops[1] = Builder.CreateIntCast(CI->getArgOperand(1), in LowerIntrinsicCall()
381 ReplaceCallWith("memset", CI, Ops, Ops+3, CI->getArgOperand(0)->getType()); in LowerIntrinsicCall()
384 case Intrinsic::sqrt: { in LowerIntrinsicCall()
388 case Intrinsic::log: { in LowerIntrinsicCall()
392 case Intrinsic::log2: { in LowerIntrinsicCall()
396 case Intrinsic::log10: { in LowerIntrinsicCall()
400 case Intrinsic::exp: { in LowerIntrinsicCall()
404 case Intrinsic::exp2: { in LowerIntrinsicCall()
408 case Intrinsic::pow: { in LowerIntrinsicCall()
412 case Intrinsic::sin: { in LowerIntrinsicCall()
416 case Intrinsic::cos: { in LowerIntrinsicCall()
420 case Intrinsic::floor: { in LowerIntrinsicCall()
424 case Intrinsic::ceil: { in LowerIntrinsicCall()
428 case Intrinsic::trunc: { in LowerIntrinsicCall()
432 case Intrinsic::round: { in LowerIntrinsicCall()
436 case Intrinsic::roundeven: { in LowerIntrinsicCall()
440 case Intrinsic::copysign: { in LowerIntrinsicCall()
444 case Intrinsic::get_rounding: in LowerIntrinsicCall()
445 // Lower to "round to the nearest" in LowerIntrinsicCall()
446 if (!CI->getType()->isVoidTy()) in LowerIntrinsicCall()
447 CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1)); in LowerIntrinsicCall()
449 case Intrinsic::invariant_start: in LowerIntrinsicCall()
450 case Intrinsic::lifetime_start: in LowerIntrinsicCall()
452 CI->replaceAllUsesWith(UndefValue::get(CI->getType())); in LowerIntrinsicCall()
454 case Intrinsic::invariant_end: in LowerIntrinsicCall()
455 case Intrinsic::lifetime_end: in LowerIntrinsicCall()
460 assert(CI->use_empty() && in LowerIntrinsicCall()
462 CI->eraseFromParent(); in LowerIntrinsicCall()
467 if (CI->arg_size() != 1 || CI->getType() != CI->getArgOperand(0)->getType() || in LowerToByteSwap()
468 !CI->getType()->isIntegerTy()) in LowerToByteSwap()
471 IntegerType *Ty = dyn_cast<IntegerType>(CI->getType()); in LowerToByteSwap()
476 Module *M = CI->getModule(); in LowerToByteSwap()
479 Value *Op = CI->getArgOperand(0); in LowerToByteSwap()
480 Op = CallInst::Create(Int, Op, CI->getName(), CI->getIterator()); in LowerToByteSwap()
482 CI->replaceAllUsesWith(Op); in LowerToByteSwap()
483 CI->eraseFromParent(); in LowerToByteSwap()