r226766 - SEH: Emit the constant filter 1 as a catch-all

Reid Kleckner reid at kleckner.net
Wed Jan 21 18:25:56 PST 2015


Author: rnk
Date: Wed Jan 21 20:25:56 2015
New Revision: 226766

URL: http://llvm.org/viewvc/llvm-project?rev=226766&view=rev
Log:
SEH: Emit the constant filter 1 as a catch-all

Minor optimization of code like __try { ... } __except(1) { ... }.

Modified:
    cfe/trunk/lib/CodeGen/CGException.cpp
    cfe/trunk/test/CodeGen/exceptions-seh.c

Modified: cfe/trunk/lib/CodeGen/CGException.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=226766&r1=226765&r2=226766&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGException.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGException.cpp Wed Jan 21 20:25:56 2015
@@ -1839,6 +1839,18 @@ void CodeGenFunction::EnterSEHTryStmt(co
   SEHExceptStmt *Except = S.getExceptHandler();
   assert(Except);
   EHCatchScope *CatchScope = EHStack.pushCatch(1);
+
+  // If the filter is known to evaluate to 1, then we can use the clause "catch
+  // i8* null".
+  llvm::Constant *C =
+      CGM.EmitConstantExpr(Except->getFilterExpr(), getContext().IntTy, this);
+  if (C && C->isOneValue()) {
+    CatchScope->setCatchAllHandler(0, createBasicBlock("__except"));
+    return;
+  }
+
+  // In general, we have to emit an outlined filter function. Use the function
+  // in place of the RTTI typeinfo global that C++ EH uses.
   CodeGenFunction FilterCGF(CGM, /*suppressNewContext=*/true);
   llvm::Function *FilterFunc =
       FilterCGF.GenerateSEHFilterFunction(*this, *Except);

Modified: cfe/trunk/test/CodeGen/exceptions-seh.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/exceptions-seh.c?rev=226766&r1=226765&r2=226766&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/exceptions-seh.c (original)
+++ cfe/trunk/test/CodeGen/exceptions-seh.c Wed Jan 21 20:25:56 2015
@@ -26,13 +26,11 @@ int safe_div(int numerator, int denomina
 //
 // CHECK: [[lpad]]
 // CHECK: landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*)
-// CHECK: %[[sel:[^ ]*]] = load i32*
-// CHECK: %[[filt_id:[^ ]*]] = call i32 @llvm.eh.typeid.for(i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0 at 0@safe_div@@" to i8*))
-// CHECK: %[[matches:[^ ]*]] = icmp eq i32 %[[sel]], %[[filt_id]]
-// CHECK: br i1 %[[matches]], label %[[except_bb:[^ ]*]], label %{{.*}}
-//
-// CHECK: [[except_bb]]
-// CHECK: store i32 -42, i32* %[[success:[^ ]*]]
+// CHECK-NEXT: catch i8* null
+// CHECK-NOT: br i1
+// CHECK: br label %[[except:[^ ]*]]
+// CHECK: [[except]]
+// CHECK-NEXT: store i32 -42, i32* %[[success:[^ ]*]]
 //
 // CHECK: %[[res:[^ ]*]] = load i32* %[[success]]
 // CHECK: ret i32 %[[res]]





More information about the cfe-commits mailing list