[clang] 9e90027 - [CGException] Remove no-op ptr-to-ptr bitcasts (NFC)

Youngsuk Kim via cfe-commits cfe-commits at lists.llvm.org
Sat Nov 4 17:18:21 PDT 2023


Author: Youngsuk Kim
Date: 2023-11-04T19:17:21-05:00
New Revision: 9e90027d618687f3d744e21ad3eda5735a167503

URL: https://github.com/llvm/llvm-project/commit/9e90027d618687f3d744e21ad3eda5735a167503
DIFF: https://github.com/llvm/llvm-project/commit/9e90027d618687f3d744e21ad3eda5735a167503.diff

LOG: [CGException] Remove no-op ptr-to-ptr bitcasts (NFC)

Opaque ptr cleanup effort (NFC).

Added: 
    

Modified: 
    clang/lib/CodeGen/CGException.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp
index 87594f71b26ec53..4a54b2040154dad 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -263,12 +263,7 @@ static llvm::FunctionCallee getPersonalityFn(CodeGenModule &CGM,
 static llvm::Constant *getOpaquePersonalityFn(CodeGenModule &CGM,
                                         const EHPersonality &Personality) {
   llvm::FunctionCallee Fn = getPersonalityFn(CGM, Personality);
-  llvm::PointerType* Int8PtrTy = llvm::PointerType::get(
-      llvm::Type::getInt8Ty(CGM.getLLVMContext()),
-      CGM.getDataLayout().getProgramAddressSpace());
-
-  return llvm::ConstantExpr::getBitCast(cast<llvm::Constant>(Fn.getCallee()),
-                                        Int8PtrTy);
+  return cast<llvm::Constant>(Fn.getCallee());
 }
 
 /// Check whether a landingpad instruction only uses C++ features.
@@ -1838,13 +1833,11 @@ Address CodeGenFunction::recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF,
     auto InsertPair = ParentCGF.EscapedLocals.insert(
         std::make_pair(ParentAlloca, ParentCGF.EscapedLocals.size()));
     int FrameEscapeIdx = InsertPair.first->second;
-    // call i8* @llvm.localrecover(i8* bitcast(@parentFn), i8* %fp, i32 N)
+    // call ptr @llvm.localrecover(ptr @parentFn, ptr %fp, i32 N)
     llvm::Function *FrameRecoverFn = llvm::Intrinsic::getDeclaration(
         &CGM.getModule(), llvm::Intrinsic::localrecover);
-    llvm::Constant *ParentI8Fn =
-        llvm::ConstantExpr::getBitCast(ParentCGF.CurFn, Int8PtrTy);
     RecoverCall = Builder.CreateCall(
-        FrameRecoverFn, {ParentI8Fn, ParentFP,
+        FrameRecoverFn, {ParentCGF.CurFn, ParentFP,
                          llvm::ConstantInt::get(Int32Ty, FrameEscapeIdx)});
 
   } else {
@@ -1907,9 +1900,7 @@ void CodeGenFunction::EmitCapturedLocals(CodeGenFunction &ParentCGF,
     // since finally funclets recover the parent FP for us.
     llvm::Function *RecoverFPIntrin =
         CGM.getIntrinsic(llvm::Intrinsic::eh_recoverfp);
-    llvm::Constant *ParentI8Fn =
-        llvm::ConstantExpr::getBitCast(ParentCGF.CurFn, Int8PtrTy);
-    ParentFP = Builder.CreateCall(RecoverFPIntrin, {ParentI8Fn, EntryFP});
+    ParentFP = Builder.CreateCall(RecoverFPIntrin, {ParentCGF.CurFn, EntryFP});
 
     // if the parent is a _finally, the passed-in ParentFP is the FP
     // of parent _finally, not Establisher's FP (FP of outermost function).
@@ -1937,19 +1928,15 @@ void CodeGenFunction::EmitCapturedLocals(CodeGenFunction &ParentCGF,
       int FrameEscapeIdx = InsertPair.first->second;
 
       // an example of a filter's prolog::
-      // %0 = call i8* @llvm.eh.recoverfp(bitcast(@"?fin$0 at 0@main@@"),..)
-      // %1 = call i8* @llvm.localrecover(bitcast(@"?fin$0 at 0@main@@"),..)
-      // %2 = bitcast i8* %1 to i8**
-      // %3 = load i8*, i8* *%2, align 8
-      //   ==> %3 is the frame-pointer of outermost host function
+      // %0 = call ptr @llvm.eh.recoverfp(@"?fin$0 at 0@main@@",..)
+      // %1 = call ptr @llvm.localrecover(@"?fin$0 at 0@main@@",..)
+      // %2 = load ptr, ptr %1, align 8
+      //   ==> %2 is the frame-pointer of outermost host function
       llvm::Function *FrameRecoverFn = llvm::Intrinsic::getDeclaration(
           &CGM.getModule(), llvm::Intrinsic::localrecover);
-      llvm::Constant *ParentI8Fn =
-          llvm::ConstantExpr::getBitCast(ParentCGF.CurFn, Int8PtrTy);
       ParentFP = Builder.CreateCall(
-          FrameRecoverFn, {ParentI8Fn, ParentFP,
+          FrameRecoverFn, {ParentCGF.CurFn, ParentFP,
                            llvm::ConstantInt::get(Int32Ty, FrameEscapeIdx)});
-      ParentFP = Builder.CreateBitCast(ParentFP, CGM.VoidPtrPtrTy);
       ParentFP = Builder.CreateLoad(
           Address(ParentFP, CGM.VoidPtrTy, getPointerAlign()));
     }
@@ -2206,9 +2193,7 @@ void CodeGenFunction::EnterSEHTryStmt(const SEHTryStmt &S) {
   // in place of the RTTI typeinfo global that C++ EH uses.
   llvm::Function *FilterFunc =
       HelperCGF.GenerateSEHFilterFunction(*this, *Except);
-  llvm::Constant *OpaqueFunc =
-      llvm::ConstantExpr::getBitCast(FilterFunc, Int8PtrTy);
-  CatchScope->setHandler(0, OpaqueFunc, createBasicBlock("__except.ret"));
+  CatchScope->setHandler(0, FilterFunc, createBasicBlock("__except.ret"));
 }
 
 void CodeGenFunction::ExitSEHTryStmt(const SEHTryStmt &S) {


        


More information about the cfe-commits mailing list