@@ -397,9 +397,8 @@ Value *LibCallSimplifier::emitStrLenMemCpy(Value *Src, Value *Dst, uint64_t Len,
397
397
398
398
// We have enough information to now generate the memcpy call to do the
399
399
// concatenation for us. Make a memcpy to copy the nul byte with align = 1.
400
- B.CreateMemCpy (
401
- CpyDst, Align (1 ), Src, Align (1 ),
402
- ConstantInt::get (DL.getIntPtrType (Src->getContext ()), Len + 1 ));
400
+ B.CreateMemCpy (CpyDst, Align (1 ), Src, Align (1 ),
401
+ TLI->getAsSizeT (Len + 1 , *B.GetInsertBlock ()->getModule ()));
403
402
return Dst;
404
403
}
405
404
@@ -590,26 +589,21 @@ Value *LibCallSimplifier::optimizeStrCmp(CallInst *CI, IRBuilderBase &B) {
590
589
if (Len1 && Len2) {
591
590
return copyFlags (
592
591
*CI, emitMemCmp (Str1P, Str2P,
593
- ConstantInt::get (DL.getIntPtrType (CI->getContext ()),
594
- std::min (Len1, Len2)),
592
+ TLI->getAsSizeT (std::min (Len1, Len2), *CI->getModule ()),
595
593
B, DL, TLI));
596
594
}
597
595
598
596
// strcmp to memcmp
599
597
if (!HasStr1 && HasStr2) {
600
598
if (canTransformToMemCmp (CI, Str1P, Len2, DL))
601
- return copyFlags (
602
- *CI,
603
- emitMemCmp (Str1P, Str2P,
604
- ConstantInt::get (DL.getIntPtrType (CI->getContext ()), Len2),
605
- B, DL, TLI));
599
+ return copyFlags (*CI, emitMemCmp (Str1P, Str2P,
600
+ TLI->getAsSizeT (Len2, *CI->getModule ()),
601
+ B, DL, TLI));
606
602
} else if (HasStr1 && !HasStr2) {
607
603
if (canTransformToMemCmp (CI, Str2P, Len1, DL))
608
- return copyFlags (
609
- *CI,
610
- emitMemCmp (Str1P, Str2P,
611
- ConstantInt::get (DL.getIntPtrType (CI->getContext ()), Len1),
612
- B, DL, TLI));
604
+ return copyFlags (*CI, emitMemCmp (Str1P, Str2P,
605
+ TLI->getAsSizeT (Len1, *CI->getModule ()),
606
+ B, DL, TLI));
613
607
}
614
608
615
609
annotateNonNullNoUndefBasedOnAccess (CI, {0 , 1 });
@@ -676,19 +670,15 @@ Value *LibCallSimplifier::optimizeStrNCmp(CallInst *CI, IRBuilderBase &B) {
676
670
if (!HasStr1 && HasStr2) {
677
671
Len2 = std::min (Len2, Length);
678
672
if (canTransformToMemCmp (CI, Str1P, Len2, DL))
679
- return copyFlags (
680
- *CI,
681
- emitMemCmp (Str1P, Str2P,
682
- ConstantInt::get (DL.getIntPtrType (CI->getContext ()), Len2),
683
- B, DL, TLI));
673
+ return copyFlags (*CI, emitMemCmp (Str1P, Str2P,
674
+ TLI->getAsSizeT (Len2, *CI->getModule ()),
675
+ B, DL, TLI));
684
676
} else if (HasStr1 && !HasStr2) {
685
677
Len1 = std::min (Len1, Length);
686
678
if (canTransformToMemCmp (CI, Str2P, Len1, DL))
687
- return copyFlags (
688
- *CI,
689
- emitMemCmp (Str1P, Str2P,
690
- ConstantInt::get (DL.getIntPtrType (CI->getContext ()), Len1),
691
- B, DL, TLI));
679
+ return copyFlags (*CI, emitMemCmp (Str1P, Str2P,
680
+ TLI->getAsSizeT (Len1, *CI->getModule ()),
681
+ B, DL, TLI));
692
682
}
693
683
694
684
return nullptr ;
@@ -722,15 +712,13 @@ Value *LibCallSimplifier::optimizeStrCpy(CallInst *CI, IRBuilderBase &B) {
722
712
723
713
// We have enough information to now generate the memcpy call to do the
724
714
// copy for us. Make a memcpy to copy the nul byte with align = 1.
725
- CallInst *NewCI =
726
- B.CreateMemCpy (Dst, Align (1 ), Src, Align (1 ),
727
- ConstantInt::get (DL.getIntPtrType (CI->getContext ()), Len));
715
+ CallInst *NewCI = B.CreateMemCpy (Dst, Align (1 ), Src, Align (1 ),
716
+ TLI->getAsSizeT (Len, *CI->getModule ()));
728
717
mergeAttributesAndFlags (NewCI, *CI);
729
718
return Dst;
730
719
}
731
720
732
721
Value *LibCallSimplifier::optimizeStpCpy (CallInst *CI, IRBuilderBase &B) {
733
- Function *Callee = CI->getCalledFunction ();
734
722
Value *Dst = CI->getArgOperand (0 ), *Src = CI->getArgOperand (1 );
735
723
736
724
// stpcpy(d,s) -> strcpy(d,s) if the result is not used.
@@ -749,10 +737,9 @@ Value *LibCallSimplifier::optimizeStpCpy(CallInst *CI, IRBuilderBase &B) {
749
737
else
750
738
return nullptr ;
751
739
752
- Type *PT = Callee->getFunctionType ()->getParamType (0 );
753
- Value *LenV = ConstantInt::get (DL.getIntPtrType (PT), Len);
740
+ Value *LenV = TLI->getAsSizeT (Len, *CI->getModule ());
754
741
Value *DstEnd = B.CreateInBoundsGEP (
755
- B.getInt8Ty (), Dst, ConstantInt::get (DL. getIntPtrType (PT), Len - 1 ));
742
+ B.getInt8Ty (), Dst, TLI-> getAsSizeT ( Len - 1 , *CI-> getModule () ));
756
743
757
744
// We have enough information to now generate the memcpy call to do the
758
745
// copy for us. Make a memcpy to copy the nul byte with align = 1.
@@ -819,13 +806,11 @@ Value *LibCallSimplifier::optimizeStrLCpy(CallInst *CI, IRBuilderBase &B) {
819
806
return ConstantInt::get (CI->getType (), 0 );
820
807
}
821
808
822
- Function *Callee = CI->getCalledFunction ();
823
- Type *PT = Callee->getFunctionType ()->getParamType (0 );
824
809
// Transform strlcpy(D, S, N) to memcpy(D, S, N') where N' is the lower
825
810
// bound on strlen(S) + 1 and N, optionally followed by a nul store to
826
811
// D[N' - 1] if necessary.
827
812
CallInst *NewCI = B.CreateMemCpy (Dst, Align (1 ), Src, Align (1 ),
828
- ConstantInt::get (DL. getIntPtrType (PT), NBytes ));
813
+ TLI-> getAsSizeT (NBytes, *CI-> getModule () ));
829
814
mergeAttributesAndFlags (NewCI, *CI);
830
815
831
816
if (!NulTerm) {
@@ -844,7 +829,6 @@ Value *LibCallSimplifier::optimizeStrLCpy(CallInst *CI, IRBuilderBase &B) {
844
829
// otherwise.
845
830
Value *LibCallSimplifier::optimizeStringNCpy (CallInst *CI, bool RetEnd,
846
831
IRBuilderBase &B) {
847
- Function *Callee = CI->getCalledFunction ();
848
832
Value *Dst = CI->getArgOperand (0 );
849
833
Value *Src = CI->getArgOperand (1 );
850
834
Value *Size = CI->getArgOperand (2 );
@@ -922,11 +906,10 @@ Value *LibCallSimplifier::optimizeStringNCpy(CallInst *CI, bool RetEnd,
922
906
/* M=*/ nullptr , /* AddNull=*/ false );
923
907
}
924
908
925
- Type *PT = Callee->getFunctionType ()->getParamType (0 );
926
909
// st{p,r}ncpy(D, S, N) -> memcpy(align 1 D, align 1 S, N) when both
927
910
// S and N are constant.
928
911
CallInst *NewCI = B.CreateMemCpy (Dst, Align (1 ), Src, Align (1 ),
929
- ConstantInt::get (DL. getIntPtrType (PT), N ));
912
+ TLI-> getAsSizeT (N, *CI-> getModule () ));
930
913
mergeAttributesAndFlags (NewCI, *CI);
931
914
if (!RetEnd)
932
915
return Dst;
@@ -3438,10 +3421,9 @@ Value *LibCallSimplifier::optimizeSPrintFString(CallInst *CI,
3438
3421
return nullptr ; // we found a format specifier, bail out.
3439
3422
3440
3423
// sprintf(str, fmt) -> llvm.memcpy(align 1 str, align 1 fmt, strlen(fmt)+1)
3441
- B.CreateMemCpy (
3442
- Dest, Align (1 ), CI->getArgOperand (1 ), Align (1 ),
3443
- ConstantInt::get (DL.getIntPtrType (CI->getContext ()),
3444
- FormatStr.size () + 1 )); // Copy the null byte.
3424
+ B.CreateMemCpy (Dest, Align (1 ), CI->getArgOperand (1 ), Align (1 ),
3425
+ // Copy the null byte.
3426
+ TLI->getAsSizeT (FormatStr.size () + 1 , *CI->getModule ()));
3445
3427
return ConstantInt::get (CI->getType (), FormatStr.size ());
3446
3428
}
3447
3429
@@ -3476,9 +3458,8 @@ Value *LibCallSimplifier::optimizeSPrintFString(CallInst *CI,
3476
3458
3477
3459
uint64_t SrcLen = GetStringLength (CI->getArgOperand (2 ));
3478
3460
if (SrcLen) {
3479
- B.CreateMemCpy (
3480
- Dest, Align (1 ), CI->getArgOperand (2 ), Align (1 ),
3481
- ConstantInt::get (DL.getIntPtrType (CI->getContext ()), SrcLen));
3461
+ B.CreateMemCpy (Dest, Align (1 ), CI->getArgOperand (2 ), Align (1 ),
3462
+ TLI->getAsSizeT (SrcLen, *CI->getModule ()));
3482
3463
// Returns total number of characters written without null-character.
3483
3464
return ConstantInt::get (CI->getType (), SrcLen - 1 );
3484
3465
} else if (Value *V = emitStpCpy (Dest, CI->getArgOperand (2 ), B, TLI)) {
@@ -3576,11 +3557,8 @@ Value *LibCallSimplifier::emitSnPrintfMemCpy(CallInst *CI, Value *StrArg,
3576
3557
Value *DstArg = CI->getArgOperand (0 );
3577
3558
if (NCopy && StrArg)
3578
3559
// Transform the call to lvm.memcpy(dst, fmt, N).
3579
- copyFlags (
3580
- *CI,
3581
- B.CreateMemCpy (
3582
- DstArg, Align (1 ), StrArg, Align (1 ),
3583
- ConstantInt::get (DL.getIntPtrType (CI->getContext ()), NCopy)));
3560
+ copyFlags (*CI, B.CreateMemCpy (DstArg, Align (1 ), StrArg, Align (1 ),
3561
+ TLI->getAsSizeT (NCopy, *CI->getModule ())));
3584
3562
3585
3563
if (N > Str.size ())
3586
3564
// Return early when the whole format string, including the final nul,
@@ -3696,11 +3674,9 @@ Value *LibCallSimplifier::optimizeFPrintFString(CallInst *CI,
3696
3674
if (FormatStr.contains (' %' ))
3697
3675
return nullptr ; // We found a format specifier.
3698
3676
3699
- unsigned SizeTBits = TLI->getSizeTSize (*CI->getModule ());
3700
- Type *SizeTTy = IntegerType::get (CI->getContext (), SizeTBits);
3701
3677
return copyFlags (
3702
3678
*CI, emitFWrite (CI->getArgOperand (1 ),
3703
- ConstantInt::get (SizeTTy, FormatStr.size ()),
3679
+ TLI-> getAsSizeT ( FormatStr.size (), *CI-> getModule ()),
3704
3680
CI->getArgOperand (0 ), B, DL, TLI));
3705
3681
}
3706
3682
0 commit comments