Lines Matching +full:- +full:- +full:upgrade

1 //===-- AutoUpgrade.cpp - Implement auto-upgrade helper functions ---------===//
8 //===----------------------------------------------------------------------===//
10 // This file implements the auto-upgrade helper functions.
14 //===----------------------------------------------------------------------===//
34 // Upgrade the declarations of the SSE4.1 functions whose arguments have
40 Type *Arg0Type = F->getFunctionType()->getParamType(0); in UpgradeSSE41Function()
41 if (Arg0Type != VectorType::get(Type::getFloatTy(F->getContext()), 4)) in UpgradeSSE41Function()
45 F->setName(F->getName() + ".old"); in UpgradeSSE41Function()
46 NewFn = Intrinsic::getDeclaration(F->getParent(), IID); in UpgradeSSE41Function()
50 // Upgrade the declarations of intrinsic functions whose 8-bit immediate mask
55 Type *LastArgType = F->getFunctionType()->getParamType( in UpgradeX86IntrinsicsWith8BitMask()
56 F->getFunctionType()->getNumParams() - 1); in UpgradeX86IntrinsicsWith8BitMask()
57 if (!LastArgType->isIntegerTy(32)) in UpgradeX86IntrinsicsWith8BitMask()
61 F->setName(F->getName() + ".old"); in UpgradeX86IntrinsicsWith8BitMask()
62 NewFn = Intrinsic::getDeclaration(F->getParent(), IID); in UpgradeX86IntrinsicsWith8BitMask()
67 assert(F && "Illegal to upgrade a non-existent Function."); in UpgradeIntrinsicFunction1()
70 StringRef Name = F->getName(); in UpgradeIntrinsicFunction1()
80 F->arg_begin()->getType(), in UpgradeIntrinsicFunction1()
81 Type::getInt1Ty(F->getContext()) in UpgradeIntrinsicFunction1()
86 FunctionType* fType = FunctionType::get(F->getReturnType(), args, false); in UpgradeIntrinsicFunction1()
87 NewFn = Function::Create(fType, F->getLinkage(), in UpgradeIntrinsicFunction1()
88 "llvm.ctlz." + Name.substr(14), F->getParent()); in UpgradeIntrinsicFunction1()
92 NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::ctpop, in UpgradeIntrinsicFunction1()
93 F->arg_begin()->getType()); in UpgradeIntrinsicFunction1()
96 Regex vldRegex("^arm\\.neon\\.vld([1234]|[234]lane)\\.v[a-z0-9]*$"); in UpgradeIntrinsicFunction1()
98 auto fArgs = F->getFunctionType()->params(); in UpgradeIntrinsicFunction1()
102 FunctionType* fType = FunctionType::get(F->getReturnType(), Tys, false); in UpgradeIntrinsicFunction1()
103 NewFn = Function::Create(fType, F->getLinkage(), in UpgradeIntrinsicFunction1()
104 "llvm." + Name + ".p0i8", F->getParent()); in UpgradeIntrinsicFunction1()
107 Regex vstRegex("^arm\\.neon\\.vst([1234]|[234]lane)\\.v[a-z0-9]*$"); in UpgradeIntrinsicFunction1()
119 auto fArgs = F->getFunctionType()->params(); in UpgradeIntrinsicFunction1()
122 NewFn = Intrinsic::getDeclaration(F->getParent(), in UpgradeIntrinsicFunction1()
123 StoreInts[fArgs.size() - 3], Tys); in UpgradeIntrinsicFunction1()
125 NewFn = Intrinsic::getDeclaration(F->getParent(), in UpgradeIntrinsicFunction1()
126 StoreLaneInts[fArgs.size() - 5], Tys); in UpgradeIntrinsicFunction1()
133 if (Name.startswith("ctlz.") && F->arg_size() == 1) { in UpgradeIntrinsicFunction1()
134 F->setName(Name + ".old"); in UpgradeIntrinsicFunction1()
135 NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::ctlz, in UpgradeIntrinsicFunction1()
136 F->arg_begin()->getType()); in UpgradeIntrinsicFunction1()
139 if (Name.startswith("cttz.") && F->arg_size() == 1) { in UpgradeIntrinsicFunction1()
140 F->setName(Name + ".old"); in UpgradeIntrinsicFunction1()
141 NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::cttz, in UpgradeIntrinsicFunction1()
142 F->arg_begin()->getType()); in UpgradeIntrinsicFunction1()
151 if (F->arg_size() == 2 && Name.startswith("objectsize.")) { in UpgradeIntrinsicFunction1()
152 Type *Tys[2] = { F->getReturnType(), F->arg_begin()->getType() }; in UpgradeIntrinsicFunction1()
153 if (F->getName() != Intrinsic::getName(Intrinsic::objectsize, Tys)) { in UpgradeIntrinsicFunction1()
154 F->setName(Name + ".old"); in UpgradeIntrinsicFunction1()
155 NewFn = Intrinsic::getDeclaration(F->getParent(), in UpgradeIntrinsicFunction1()
204 (Name.startswith("x86.xop.vpcom") && F->arg_size() == 2)) { in UpgradeIntrinsicFunction1()
239 if (Name.startswith("x86.xop.vfrcz.ss") && F->arg_size() == 2) { in UpgradeIntrinsicFunction1()
240 F->setName(Name + ".old"); in UpgradeIntrinsicFunction1()
241 NewFn = Intrinsic::getDeclaration(F->getParent(), in UpgradeIntrinsicFunction1()
245 if (Name.startswith("x86.xop.vfrcz.sd") && F->arg_size() == 2) { in UpgradeIntrinsicFunction1()
246 F->setName(Name + ".old"); in UpgradeIntrinsicFunction1()
247 NewFn = Intrinsic::getDeclaration(F->getParent(), in UpgradeIntrinsicFunction1()
253 F->setName("llvm.x86.fma" + Name.substr(8)); in UpgradeIntrinsicFunction1()
273 // Upgrade intrinsic attributes. This does not change the function. in UpgradeIntrinsicFunction()
276 if (Intrinsic::ID id = F->getIntrinsicID()) in UpgradeIntrinsicFunction()
277 F->setAttributes(Intrinsic::getAttributes(F->getContext(), id)); in UpgradeIntrinsicFunction()
294 // Bitcast from a 64-bit element type to a byte element type. in UpgradeX86PSLLDQIntrinsics()
305 // 256-bit version is split into two 16-byte lanes. in UpgradeX86PSLLDQIntrinsics()
308 unsigned Idx = NumElts + i - Shift; in UpgradeX86PSLLDQIntrinsics()
310 Idx -= NumElts - 16; // end of lane, switch operand. in UpgradeX86PSLLDQIntrinsics()
317 // Bitcast back to a 64-bit element type. in UpgradeX86PSLLDQIntrinsics()
331 // Bitcast from a 64-bit element type to a byte element type. in UpgradeX86PSRLDQIntrinsics()
342 // 256-bit version is split into two 16-byte lanes. in UpgradeX86PSRLDQIntrinsics()
347 Idx += NumElts - 16; // end of lane, switch operand. in UpgradeX86PSRLDQIntrinsics()
354 // Bitcast back to a 64-bit element type. in UpgradeX86PSRLDQIntrinsics()
360 // UpgradeIntrinsicCall - Upgrade a call to an old intrinsic to be a call the
364 Function *F = CI->getCalledFunction(); in UpgradeIntrinsicCall()
365 LLVMContext &C = CI->getContext(); in UpgradeIntrinsicCall()
367 Builder.SetInsertPoint(CI->getParent(), CI->getIterator()); in UpgradeIntrinsicCall()
373 StringRef Name = F->getName(); in UpgradeIntrinsicCall()
376 // Upgrade packed integer vector compares intrinsics to compare instructions in UpgradeIntrinsicCall()
379 Rep = Builder.CreateICmpEQ(CI->getArgOperand(0), CI->getArgOperand(1), in UpgradeIntrinsicCall()
382 Rep = Builder.CreateSExt(Rep, CI->getType(), ""); in UpgradeIntrinsicCall()
385 Rep = Builder.CreateICmpSGT(CI->getArgOperand(0), CI->getArgOperand(1), in UpgradeIntrinsicCall()
388 Rep = Builder.CreateSExt(Rep, CI->getType(), ""); in UpgradeIntrinsicCall()
393 Builder.SetInsertPoint(CI->getParent(), CI->getIterator()); in UpgradeIntrinsicCall()
395 Module *M = F->getParent(); in UpgradeIntrinsicCall()
401 Value *Arg0 = CI->getArgOperand(0); in UpgradeIntrinsicCall()
402 Value *Arg1 = CI->getArgOperand(1); in UpgradeIntrinsicCall()
406 PointerType::getUnqual(Arg1->getType()), in UpgradeIntrinsicCall()
409 SI->setMetadata(M->getMDKindID("nontemporal"), Node); in UpgradeIntrinsicCall()
410 SI->setAlignment(32); in UpgradeIntrinsicCall()
413 CI->eraseFromParent(); in UpgradeIntrinsicCall()
457 Function *VPCOM = Intrinsic::getDeclaration(F->getParent(), intID); in UpgradeIntrinsicCall()
459 Builder.CreateCall(VPCOM, {CI->getArgOperand(0), CI->getArgOperand(1), in UpgradeIntrinsicCall()
462 Value *Arg0 = CI->getArgOperand(0); in UpgradeIntrinsicCall()
463 Value *Arg1 = CI->getArgOperand(1); in UpgradeIntrinsicCall()
464 Value *Sel = CI->getArgOperand(2); in UpgradeIntrinsicCall()
465 unsigned NumElts = CI->getType()->getVectorNumElements(); in UpgradeIntrinsicCall()
466 Constant *MinusOne = ConstantVector::getSplat(NumElts, Builder.getInt64(-1)); in UpgradeIntrinsicCall()
472 Function *CRC32 = Intrinsic::getDeclaration(F->getParent(), in UpgradeIntrinsicCall()
474 Value *Trunc0 = Builder.CreateTrunc(CI->getArgOperand(0), Type::getInt32Ty(C)); in UpgradeIntrinsicCall()
475 Rep = Builder.CreateCall(CRC32, {Trunc0, CI->getArgOperand(1)}); in UpgradeIntrinsicCall()
476 Rep = Builder.CreateZExt(Rep, CI->getType(), ""); in UpgradeIntrinsicCall()
479 Type *VecTy = CI->getType(); in UpgradeIntrinsicCall()
480 Type *EltTy = VecTy->getVectorElementType(); in UpgradeIntrinsicCall()
481 unsigned EltNum = VecTy->getVectorNumElements(); in UpgradeIntrinsicCall()
482 Value *Cast = Builder.CreateBitCast(CI->getArgOperand(0), in UpgradeIntrinsicCall()
483 EltTy->getPointerTo()); in UpgradeIntrinsicCall()
491 VectorType *SrcTy = cast<VectorType>(CI->getArgOperand(0)->getType()); in UpgradeIntrinsicCall()
492 VectorType *DstTy = cast<VectorType>(CI->getType()); in UpgradeIntrinsicCall()
493 unsigned NumDstElts = DstTy->getNumElements(); in UpgradeIntrinsicCall()
501 CI->getArgOperand(0), UndefValue::get(SrcTy), ShuffleMask); in UpgradeIntrinsicCall()
506 Value *Op = Builder.CreatePointerCast(CI->getArgOperand(0), in UpgradeIntrinsicCall()
510 Rep = Builder.CreateShuffleVector(Load, UndefValue::get(Load->getType()), in UpgradeIntrinsicCall()
515 Value *Op = CI->getArgOperand(0); in UpgradeIntrinsicCall()
516 unsigned NumElts = CI->getType()->getVectorNumElements(); in UpgradeIntrinsicCall()
518 Rep = Builder.CreateShuffleVector(Op, UndefValue::get(Op->getType()), in UpgradeIntrinsicCall()
521 // 128-bit shift left specified in bits. in UpgradeIntrinsicCall()
522 unsigned Shift = cast<ConstantInt>(CI->getArgOperand(1))->getZExtValue(); in UpgradeIntrinsicCall()
523 Rep = UpgradeX86PSLLDQIntrinsics(Builder, C, CI->getArgOperand(0), 1, in UpgradeIntrinsicCall()
526 // 128-bit shift right specified in bits. in UpgradeIntrinsicCall()
527 unsigned Shift = cast<ConstantInt>(CI->getArgOperand(1))->getZExtValue(); in UpgradeIntrinsicCall()
528 Rep = UpgradeX86PSRLDQIntrinsics(Builder, C, CI->getArgOperand(0), 1, in UpgradeIntrinsicCall()
531 // 256-bit shift left specified in bits. in UpgradeIntrinsicCall()
532 unsigned Shift = cast<ConstantInt>(CI->getArgOperand(1))->getZExtValue(); in UpgradeIntrinsicCall()
533 Rep = UpgradeX86PSLLDQIntrinsics(Builder, C, CI->getArgOperand(0), 2, in UpgradeIntrinsicCall()
536 // 256-bit shift right specified in bits. in UpgradeIntrinsicCall()
537 unsigned Shift = cast<ConstantInt>(CI->getArgOperand(1))->getZExtValue(); in UpgradeIntrinsicCall()
538 Rep = UpgradeX86PSRLDQIntrinsics(Builder, C, CI->getArgOperand(0), 2, in UpgradeIntrinsicCall()
541 // 128-bit shift left specified in bytes. in UpgradeIntrinsicCall()
542 unsigned Shift = cast<ConstantInt>(CI->getArgOperand(1))->getZExtValue(); in UpgradeIntrinsicCall()
543 Rep = UpgradeX86PSLLDQIntrinsics(Builder, C, CI->getArgOperand(0), 1, in UpgradeIntrinsicCall()
546 // 128-bit shift right specified in bytes. in UpgradeIntrinsicCall()
547 unsigned Shift = cast<ConstantInt>(CI->getArgOperand(1))->getZExtValue(); in UpgradeIntrinsicCall()
548 Rep = UpgradeX86PSRLDQIntrinsics(Builder, C, CI->getArgOperand(0), 1, in UpgradeIntrinsicCall()
551 // 256-bit shift left specified in bytes. in UpgradeIntrinsicCall()
552 unsigned Shift = cast<ConstantInt>(CI->getArgOperand(1))->getZExtValue(); in UpgradeIntrinsicCall()
553 Rep = UpgradeX86PSLLDQIntrinsics(Builder, C, CI->getArgOperand(0), 2, in UpgradeIntrinsicCall()
556 // 256-bit shift right specified in bytes. in UpgradeIntrinsicCall()
557 unsigned Shift = cast<ConstantInt>(CI->getArgOperand(1))->getZExtValue(); in UpgradeIntrinsicCall()
558 Rep = UpgradeX86PSRLDQIntrinsics(Builder, C, CI->getArgOperand(0), 2, in UpgradeIntrinsicCall()
568 Value *Op0 = CI->getArgOperand(0); in UpgradeIntrinsicCall()
569 Value *Op1 = CI->getArgOperand(1); in UpgradeIntrinsicCall()
570 unsigned Imm = cast <ConstantInt>(CI->getArgOperand(2))->getZExtValue(); in UpgradeIntrinsicCall()
571 VectorType *VecTy = cast<VectorType>(CI->getType()); in UpgradeIntrinsicCall()
572 unsigned NumElts = VecTy->getNumElements(); in UpgradeIntrinsicCall()
585 Value *Op0 = CI->getArgOperand(0); in UpgradeIntrinsicCall()
586 Value *Op1 = CI->getArgOperand(1); in UpgradeIntrinsicCall()
587 unsigned Imm = cast<ConstantInt>(CI->getArgOperand(2))->getZExtValue(); in UpgradeIntrinsicCall()
588 VectorType *VecTy = cast<VectorType>(CI->getType()); in UpgradeIntrinsicCall()
589 unsigned NumElts = VecTy->getNumElements(); in UpgradeIntrinsicCall()
595 Value *UndefV = UndefValue::get(Op1->getType()); in UpgradeIntrinsicCall()
609 // Example of shuffle mask for 32-bit elements: in UpgradeIntrinsicCall()
631 Value *Op0 = CI->getArgOperand(0); in UpgradeIntrinsicCall()
632 unsigned Imm = cast<ConstantInt>(CI->getArgOperand(1))->getZExtValue(); in UpgradeIntrinsicCall()
633 VectorType *VecTy = cast<VectorType>(CI->getType()); in UpgradeIntrinsicCall()
634 unsigned NumElts = VecTy->getNumElements(); in UpgradeIntrinsicCall()
646 Value *UndefV = UndefValue::get(Op0->getType()); in UpgradeIntrinsicCall()
660 Value *Op0 = CI->getArgOperand(0); in UpgradeIntrinsicCall()
661 unsigned Imm = cast<ConstantInt>(CI->getArgOperand(1))->getZExtValue(); in UpgradeIntrinsicCall()
683 llvm_unreachable("Unknown function for CallInst upgrade."); in UpgradeIntrinsicCall()
687 CI->replaceAllUsesWith(Rep); in UpgradeIntrinsicCall()
688 CI->eraseFromParent(); in UpgradeIntrinsicCall()
692 std::string Name = CI->getName(); in UpgradeIntrinsicCall()
694 CI->setName(Name + ".old"); in UpgradeIntrinsicCall()
696 switch (NewFn->getIntrinsicID()) { in UpgradeIntrinsicCall()
698 llvm_unreachable("Unknown function for CallInst upgrade."); in UpgradeIntrinsicCall()
714 SmallVector<Value *, 4> Args(CI->arg_operands().begin(), in UpgradeIntrinsicCall()
715 CI->arg_operands().end()); in UpgradeIntrinsicCall()
716 CI->replaceAllUsesWith(Builder.CreateCall(NewFn, Args)); in UpgradeIntrinsicCall()
717 CI->eraseFromParent(); in UpgradeIntrinsicCall()
723 assert(CI->getNumArgOperands() == 1 && in UpgradeIntrinsicCall()
725 CI->replaceAllUsesWith(Builder.CreateCall( in UpgradeIntrinsicCall()
726 NewFn, {CI->getArgOperand(0), Builder.getFalse()}, Name)); in UpgradeIntrinsicCall()
727 CI->eraseFromParent(); in UpgradeIntrinsicCall()
731 CI->replaceAllUsesWith(Builder.CreateCall( in UpgradeIntrinsicCall()
732 NewFn, {CI->getArgOperand(0), CI->getArgOperand(1)}, Name)); in UpgradeIntrinsicCall()
733 CI->eraseFromParent(); in UpgradeIntrinsicCall()
737 CI->replaceAllUsesWith(Builder.CreateCall(NewFn, {CI->getArgOperand(0)})); in UpgradeIntrinsicCall()
738 CI->eraseFromParent(); in UpgradeIntrinsicCall()
744 CI->replaceAllUsesWith( in UpgradeIntrinsicCall()
745 Builder.CreateCall(NewFn, {CI->getArgOperand(1)}, Name)); in UpgradeIntrinsicCall()
746 CI->eraseFromParent(); in UpgradeIntrinsicCall()
756 Value *Arg0 = CI->getArgOperand(0); in UpgradeIntrinsicCall()
757 if (Arg0->getType() != VectorType::get(Type::getFloatTy(C), 4)) in UpgradeIntrinsicCall()
761 Value *Arg1 = CI->getArgOperand(1); in UpgradeIntrinsicCall()
769 CI->replaceAllUsesWith(NewCall); in UpgradeIntrinsicCall()
770 CI->eraseFromParent(); in UpgradeIntrinsicCall()
780 // Need to truncate the last argument from i32 to i8 -- this argument models in UpgradeIntrinsicCall()
781 // an inherently 8-bit immediate operand to these x86 instructions. in UpgradeIntrinsicCall()
782 SmallVector<Value *, 4> Args(CI->arg_operands().begin(), in UpgradeIntrinsicCall()
783 CI->arg_operands().end()); in UpgradeIntrinsicCall()
789 CI->replaceAllUsesWith(NewCall); in UpgradeIntrinsicCall()
790 CI->eraseFromParent(); in UpgradeIntrinsicCall()
797 // one we are interested in, we then upgrade all calls to reflect the new
800 assert(F && "Illegal attempt to upgrade a non-existent intrinsic."); in UpgradeCallsToIntrinsic()
802 // Upgrade the function and check if it is a totaly new function. in UpgradeCallsToIntrinsic()
806 for (Value::user_iterator UI = F->user_begin(), UE = F->user_end(); in UpgradeCallsToIntrinsic()
812 F->eraseFromParent(); in UpgradeCallsToIntrinsic()
817 MDNode *MD = I->getMetadata(LLVMContext::MD_tbaa); in UpgradeInstWithTBAATag()
819 // Check if the tag uses struct-path aware TBAA format. in UpgradeInstWithTBAATag()
820 if (isa<MDNode>(MD->getOperand(0)) && MD->getNumOperands() >= 3) in UpgradeInstWithTBAATag()
823 if (MD->getNumOperands() == 3) { in UpgradeInstWithTBAATag()
824 Metadata *Elts[] = {MD->getOperand(0), MD->getOperand(1)}; in UpgradeInstWithTBAATag()
825 MDNode *ScalarType = MDNode::get(I->getContext(), Elts); in UpgradeInstWithTBAATag()
829 Type::getInt64Ty(I->getContext()))), in UpgradeInstWithTBAATag()
830 MD->getOperand(2)}; in UpgradeInstWithTBAATag()
831 I->setMetadata(LLVMContext::MD_tbaa, MDNode::get(I->getContext(), Elts2)); in UpgradeInstWithTBAATag()
835 Type::getInt64Ty(I->getContext())))}; in UpgradeInstWithTBAATag()
836 I->setMetadata(LLVMContext::MD_tbaa, MDNode::get(I->getContext(), Elts)); in UpgradeInstWithTBAATag()
846 Type *SrcTy = V->getType(); in UpgradeBitCastInst()
847 if (SrcTy->isPtrOrPtrVectorTy() && DestTy->isPtrOrPtrVectorTy() && in UpgradeBitCastInst()
848 SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace()) { in UpgradeBitCastInst()
849 LLVMContext &Context = V->getContext(); in UpgradeBitCastInst()
866 Type *SrcTy = C->getType(); in UpgradeBitCastExpr()
867 if (SrcTy->isPtrOrPtrVectorTy() && DestTy->isPtrOrPtrVectorTy() && in UpgradeBitCastExpr()
868 SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace()) { in UpgradeBitCastExpr()
869 LLVMContext &Context = C->getContext(); in UpgradeBitCastExpr()
882 /// Check the debug info version number, if it is out-dated, drop the debug