@@ -463,7 +463,7 @@ Function *AArch64Arm64ECCallLowering::buildExitThunk(FunctionType *FT,
463
463
IRB.CreateStore (&Arg, Mem);
464
464
if (ArgTranslation == ThunkArgTranslation::Bitcast) {
465
465
Type *IntTy = IRB.getIntNTy (DL.getTypeStoreSizeInBits (Arg.getType ()));
466
- Args.push_back (IRB.CreateLoad (IntTy, IRB. CreateBitCast ( Mem, PtrTy) ));
466
+ Args.push_back (IRB.CreateLoad (IntTy, Mem));
467
467
} else {
468
468
assert (ArgTranslation == ThunkArgTranslation::PointerIndirection);
469
469
Args.push_back (Mem);
@@ -475,7 +475,6 @@ Function *AArch64Arm64ECCallLowering::buildExitThunk(FunctionType *FT,
475
475
}
476
476
// FIXME: Transfer necessary attributes? sret? anything else?
477
477
478
- Callee = IRB.CreateBitCast (Callee, PtrTy);
479
478
CallInst *Call = IRB.CreateCall (X64Ty, Callee, Args);
480
479
Call->setCallingConv (CallingConv::ARM64EC_Thunk_X64);
481
480
@@ -487,7 +486,7 @@ Function *AArch64Arm64ECCallLowering::buildExitThunk(FunctionType *FT,
487
486
RetVal = IRB.CreateLoad (RetTy, Args[1 ]);
488
487
} else {
489
488
Value *CastAlloca = IRB.CreateAlloca (RetTy);
490
- IRB.CreateStore (Call, IRB. CreateBitCast ( CastAlloca, PtrTy) );
489
+ IRB.CreateStore (Call, CastAlloca);
491
490
RetVal = IRB.CreateLoad (RetTy, CastAlloca);
492
491
}
493
492
}
@@ -542,11 +541,11 @@ Function *AArch64Arm64ECCallLowering::buildEntryThunk(Function *F) {
542
541
// Translate array/struct arguments to the expected type.
543
542
if (ArgTranslation == ThunkArgTranslation::Bitcast) {
544
543
Value *CastAlloca = IRB.CreateAlloca (ArgTy);
545
- IRB.CreateStore (Arg, IRB. CreateBitCast ( CastAlloca, PtrTy) );
544
+ IRB.CreateStore (Arg, CastAlloca);
546
545
Arg = IRB.CreateLoad (ArgTy, CastAlloca);
547
546
} else {
548
547
assert (ArgTranslation == ThunkArgTranslation::PointerIndirection);
549
- Arg = IRB.CreateLoad (ArgTy, IRB. CreateBitCast ( Arg, PtrTy) );
548
+ Arg = IRB.CreateLoad (ArgTy, Arg);
550
549
}
551
550
}
552
551
assert (Arg->getType () == ArgTy);
@@ -571,7 +570,6 @@ Function *AArch64Arm64ECCallLowering::buildEntryThunk(Function *F) {
571
570
572
571
// Call the function passed to the thunk.
573
572
Value *Callee = Thunk->getArg (0 );
574
- Callee = IRB.CreateBitCast (Callee, PtrTy);
575
573
CallInst *Call = IRB.CreateCall (Arm64Ty, Callee, Args);
576
574
577
575
auto SRetAttr = F->getAttributes ().getParamAttr (0 , Attribute::StructRet);
@@ -583,10 +581,10 @@ Function *AArch64Arm64ECCallLowering::buildEntryThunk(Function *F) {
583
581
584
582
Value *RetVal = Call;
585
583
if (TransformDirectToSRet) {
586
- IRB.CreateStore (RetVal, IRB. CreateBitCast ( Thunk->getArg (1 ), PtrTy ));
584
+ IRB.CreateStore (RetVal, Thunk->getArg (1 ));
587
585
} else if (X64RetType != RetTy) {
588
586
Value *CastAlloca = IRB.CreateAlloca (X64RetType);
589
- IRB.CreateStore (Call, IRB. CreateBitCast ( CastAlloca, PtrTy) );
587
+ IRB.CreateStore (Call, CastAlloca);
590
588
RetVal = IRB.CreateLoad (X64RetType, CastAlloca);
591
589
}
592
590
@@ -649,15 +647,13 @@ Function *AArch64Arm64ECCallLowering::buildGuestExitThunk(Function *F) {
649
647
// even if the original CallBase is an Invoke or CallBr instruction.
650
648
Function *Thunk = buildExitThunk (F->getFunctionType (), F->getAttributes ());
651
649
CallInst *GuardCheck = B.CreateCall (
652
- GuardFnType, GuardCheckLoad,
653
- {B.CreateBitCast (F, B.getPtrTy ()), B.CreateBitCast (Thunk, B.getPtrTy ())});
650
+ GuardFnType, GuardCheckLoad, {F, Thunk});
654
651
655
652
// Ensure that the first argument is passed in the correct register.
656
653
GuardCheck->setCallingConv (CallingConv::CFGuard_Check);
657
654
658
- Value *GuardRetVal = B.CreateBitCast (GuardCheck, PtrTy);
659
655
SmallVector<Value *> Args (llvm::make_pointer_range (GuestExit->args ()));
660
- CallInst *Call = B.CreateCall (Arm64Ty, GuardRetVal , Args);
656
+ CallInst *Call = B.CreateCall (Arm64Ty, GuardCheck , Args);
661
657
Call->setTailCallKind (llvm::CallInst::TCK_MustTail);
662
658
663
659
if (Call->getType ()->isVoidTy ())
@@ -712,9 +708,8 @@ AArch64Arm64ECCallLowering::buildPatchableThunk(GlobalAlias *UnmangledAlias,
712
708
// Ensure that the first arguments are passed in the correct registers.
713
709
Dispatch->setCallingConv (CallingConv::CFGuard_Check);
714
710
715
- Value *DispatchRetVal = B.CreateBitCast (Dispatch, PtrTy);
716
711
SmallVector<Value *> Args (llvm::make_pointer_range (GuestExit->args ()));
717
- CallInst *Call = B.CreateCall (Arm64Ty, DispatchRetVal , Args);
712
+ CallInst *Call = B.CreateCall (Arm64Ty, Dispatch , Args);
718
713
Call->setTailCallKind (llvm::CallInst::TCK_MustTail);
719
714
720
715
if (Call->getType ()->isVoidTy ())
@@ -759,16 +754,13 @@ void AArch64Arm64ECCallLowering::lowerCall(CallBase *CB) {
759
754
// even if the original CallBase is an Invoke or CallBr instruction.
760
755
Function *Thunk = buildExitThunk (CB->getFunctionType (), CB->getAttributes ());
761
756
CallInst *GuardCheck =
762
- B.CreateCall (GuardFnType, GuardCheckLoad,
763
- {B.CreateBitCast (CalledOperand, B.getPtrTy ()),
764
- B.CreateBitCast (Thunk, B.getPtrTy ())},
757
+ B.CreateCall (GuardFnType, GuardCheckLoad, {CalledOperand, Thunk},
765
758
Bundles);
766
759
767
760
// Ensure that the first argument is passed in the correct register.
768
761
GuardCheck->setCallingConv (CallingConv::CFGuard_Check);
769
762
770
- Value *GuardRetVal = B.CreateBitCast (GuardCheck, CalledOperand->getType ());
771
- CB->setCalledOperand (GuardRetVal);
763
+ CB->setCalledOperand (GuardCheck);
772
764
}
773
765
774
766
bool AArch64Arm64ECCallLowering::runOnModule (Module &Mod) {
@@ -912,8 +904,7 @@ bool AArch64Arm64ECCallLowering::runOnModule(Module &Mod) {
912
904
SmallVector<Constant *> ThunkMappingArrayElems;
913
905
for (ThunkInfo &Thunk : ThunkMapping) {
914
906
ThunkMappingArrayElems.push_back (ConstantStruct::getAnon (
915
- {ConstantExpr::getBitCast (Thunk.Src , PtrTy),
916
- ConstantExpr::getBitCast (Thunk.Dst , PtrTy),
907
+ {Thunk.Src , Thunk.Dst ,
917
908
ConstantInt::get (M->getContext (), APInt (32 , uint8_t (Thunk.Kind )))}));
918
909
}
919
910
Constant *ThunkMappingArray = ConstantArray::get (
0 commit comments