]> granicus.if.org Git - clang/commitdiff
Refactor the load of the exception pointer and the exception selector from their
authorBill Wendling <isanbard@gmail.com>
Thu, 15 Sep 2011 18:57:19 +0000 (18:57 +0000)
committerBill Wendling <isanbard@gmail.com>
Thu, 15 Sep 2011 18:57:19 +0000 (18:57 +0000)
storage slot into helper functions.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139826 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGException.cpp
lib/CodeGen/CGObjCRuntime.cpp
lib/CodeGen/CodeGenFunction.h

index 6d8e38e6afa9e964aed0b5fec90e12ba2334ed3d..e7119149557b1413ff7994da3cb26845ec016960 100644 (file)
@@ -367,6 +367,14 @@ llvm::Value *CodeGenFunction::getEHSelectorSlot() {
   return EHSelectorSlot;
 }
 
+llvm::Value *CodeGenFunction::getExceptionFromSlot() {
+  return Builder.CreateLoad(getExceptionSlot(), "exn");
+}
+
+llvm::Value *CodeGenFunction::getSelectorFromSlot() {
+  return Builder.CreateLoad(getEHSelectorSlot(), "sel");
+}
+
 void CodeGenFunction::EmitCXXThrowExpr(const CXXThrowExpr *E) {
   if (!E->getSubExpr()) {
     if (getInvokeDest()) {
@@ -483,9 +491,7 @@ static void emitFilterDispatchBlock(CodeGenFunction &CGF,
   // here because the filter triggered.
   if (filterScope.getNumFilters()) {
     // Load the selector value.
-    llvm::Value *selector =
-      CGF.Builder.CreateLoad(CGF.getEHSelectorSlot(), "selector");
-
+    llvm::Value *selector = CGF.getSelectorFromSlot();
     llvm::BasicBlock *unexpectedBB = CGF.createBasicBlock("ehspec.unexpected");
 
     llvm::Value *zero = CGF.Builder.getInt32(0);
@@ -500,7 +506,7 @@ static void emitFilterDispatchBlock(CodeGenFunction &CGF,
   // because __cxa_call_unexpected magically filters exceptions
   // according to the last landing pad the exception was thrown
   // into.  Seriously.
-  llvm::Value *exn = CGF.Builder.CreateLoad(CGF.getExceptionSlot());
+  llvm::Value *exn = CGF.getExceptionFromSlot();
   CGF.Builder.CreateCall(getUnexpectedFn(CGF), exn)
     ->setDoesNotReturn();
   CGF.Builder.CreateUnreachable();
@@ -899,7 +905,7 @@ static void InitCatchParam(CodeGenFunction &CGF,
                            const VarDecl &CatchParam,
                            llvm::Value *ParamAddr) {
   // Load the exception from where the landing pad saved it.
-  llvm::Value *Exn = CGF.Builder.CreateLoad(CGF.getExceptionSlot(), "exn");
+  llvm::Value *Exn = CGF.getExceptionFromSlot();
 
   CanQualType CatchType =
     CGF.CGM.getContext().getCanonicalType(CatchParam.getType());
@@ -1074,7 +1080,7 @@ static void BeginCatch(CodeGenFunction &CGF, const CXXCatchStmt *S) {
 
   VarDecl *CatchParam = S->getExceptionDecl();
   if (!CatchParam) {
-    llvm::Value *Exn = CGF.Builder.CreateLoad(CGF.getExceptionSlot(), "exn");
+    llvm::Value *Exn = CGF.getExceptionFromSlot();
     CallBeginCatch(CGF, Exn, true);
     return;
   }
@@ -1116,8 +1122,7 @@ static void emitCatchDispatchBlock(CodeGenFunction &CGF,
     CGF.CGM.getIntrinsic(llvm::Intrinsic::eh_typeid_for);
 
   // Load the selector value.
-  llvm::Value *selector =
-    CGF.Builder.CreateLoad(CGF.getEHSelectorSlot(), "selector");
+  llvm::Value *selector = CGF.getSelectorFromSlot();
 
   // Test against each of the exception types we claim to catch.
   for (unsigned i = 0, e = catchScope.getNumHandlers(); ; ++i) {
@@ -1423,13 +1428,13 @@ void CodeGenFunction::FinallyInfo::exit(CodeGenFunction &CGF) {
 
     // If there's a begin-catch function, call it.
     if (BeginCatchFn) {
-      exn = CGF.Builder.CreateLoad(CGF.getExceptionSlot());
+      exn = CGF.getExceptionFromSlot();
       CGF.Builder.CreateCall(BeginCatchFn, exn)->setDoesNotThrow();
     }
 
     // If we need to remember the exception pointer to rethrow later, do so.
     if (SavedExnVar) {
-      if (!exn) exn = CGF.Builder.CreateLoad(CGF.getExceptionSlot());
+      if (!exn) exn = CGF.getExceptionFromSlot();
       CGF.Builder.CreateStore(exn, SavedExnVar);
     }
 
@@ -1519,10 +1524,10 @@ llvm::BasicBlock *CodeGenFunction::getEHResumeBlock() {
   StringRef RethrowName = Personality.getCatchallRethrowFnName();
   if (!RethrowName.empty()) {
     Builder.CreateCall(getCatchallRethrowFn(*this, RethrowName),
-                       Builder.CreateLoad(getExceptionSlot()))
+                       getExceptionFromSlot())
       ->setDoesNotReturn();
   } else {
-    llvm::Value *Exn = Builder.CreateLoad(getExceptionSlot());
+    llvm::Value *Exn = getExceptionFromSlot();
 
     switch (CleanupHackLevel) {
     case CHL_MandatoryCatchall:
@@ -1534,7 +1539,7 @@ llvm::BasicBlock *CodeGenFunction::getEHResumeBlock() {
       break;
     case CHL_MandatoryCleanup: {
       // In mandatory-cleanup mode, we should use llvm.eh.resume.
-      llvm::Value *Selector = Builder.CreateLoad(getEHSelectorSlot());
+      llvm::Value *Selector = getSelectorFromSlot();
       Builder.CreateCall2(CGM.getIntrinsic(llvm::Intrinsic::eh_resume),
                           Exn, Selector)
         ->setDoesNotReturn();
index ce261142987d345b5371ea7b0da829900d3dda97..f1e49ac81efdc73b85ef06d7882c5e06e4b7fe74 100644 (file)
@@ -221,7 +221,7 @@ void CGObjCRuntime::EmitTryCatchStmt(CodeGenFunction &CGF,
     CatchHandler &Handler = Handlers[I];
 
     CGF.EmitBlock(Handler.Block);
-    llvm::Value *RawExn = CGF.Builder.CreateLoad(CGF.getExceptionSlot());
+    llvm::Value *RawExn = CGF.getExceptionFromSlot();
 
     // Enter the catch.
     llvm::Value *Exn = RawExn;
index 89f0a7e94bb69e9130eaaaba17ebe7587d25c05f..177e647b4d123a993fd9a34553b471e8177cb586 100644 (file)
@@ -1121,6 +1121,11 @@ public:
   llvm::Value *getExceptionSlot();
   llvm::Value *getEHSelectorSlot();
 
+  /// Returns the contents of the function's exception object and selector
+  /// slots.
+  llvm::Value *getExceptionFromSlot();
+  llvm::Value *getSelectorFromSlot();
+
   llvm::Value *getNormalCleanupDestSlot();
 
   llvm::BasicBlock *getUnreachableBlock() {