[llvm-commits] [dragonegg] r99430 - in /dragonegg/trunk: llvm-convert.cpp llvm-internal.h

Duncan Sands baldrick at free.fr
Wed Mar 24 14:33:18 PDT 2010


Author: baldrick
Date: Wed Mar 24 16:33:18 2010
New Revision: 99430

URL: http://llvm.org/viewvc/llvm-project?rev=99430&view=rev
Log:
Start implementing exception handling: implement BUILT_IN_EH_POINTER.

Modified:
    dragonegg/trunk/llvm-convert.cpp
    dragonegg/trunk/llvm-internal.h

Modified: dragonegg/trunk/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-convert.cpp?rev=99430&r1=99429&r2=99430&view=diff
==============================================================================
--- dragonegg/trunk/llvm-convert.cpp (original)
+++ dragonegg/trunk/llvm-convert.cpp Wed Mar 24 16:33:18 2010
@@ -256,8 +256,6 @@
 
   AllocaInsertionPoint = 0;
 
-  ExceptionValue = 0;
-  ExceptionSelectorValue = 0;
   FuncEHException = 0;
   FuncEHSelector = 0;
   FuncEHGetTypeID = 0;
@@ -1292,14 +1290,6 @@
     LV = EmitLV_VIEW_CONVERT_EXPR(exp);
     break;
 
-  // Exception Handling.
-//FIXME  case EXC_PTR_EXPR:
-//FIXME    LV = EmitLV_EXC_PTR_EXPR(exp);
-//FIXME    break;
-//FIXME  case FILTER_EXPR:
-//FIXME    LV = EmitLV_FILTER_EXPR(exp);
-//FIXME    break;
-
   // Trivial Cases.
   case WITH_SIZE_EXPR:
     LV = EmitLV_WITH_SIZE_EXPR(exp);
@@ -1849,15 +1839,7 @@
 /// CreateExceptionValues - Create values used internally by exception handling.
 void TreeToLLVM::CreateExceptionValues() {
   // Check to see if the exception values have been constructed.
-  if (ExceptionValue) return;
-
-  const Type *IntTy = ConvertType(integer_type_node);
-
-  ExceptionValue = CreateTemporary(Type::getInt8PtrTy(Context));
-  ExceptionValue->setName("eh_exception");
-
-  ExceptionSelectorValue = CreateTemporary(IntTy);
-  ExceptionSelectorValue->setName("eh_selector");
+  if (FuncEHException) return;
 
   FuncEHException = Intrinsic::getDeclaration(TheModule,
                                               Intrinsic::eh_exception);
@@ -1867,6 +1849,19 @@
                                               Intrinsic::eh_typeid_for);
 }
 
+/// getLandingPad - Return the landing pad for the given exception handling
+/// region, creating it if necessary.
+BasicBlock *TreeToLLVM::getLandingPad(unsigned RegionNo) {
+  LandingPads.grow(RegionNo);
+  BasicBlock *&LandingPad = LandingPads[RegionNo];
+
+  if (!LandingPad)
+    LandingPad = BasicBlock::Create(Context, "lpad");
+
+  return LandingPad;
+}
+
+
 /// getPostPad - Return the post landing pad for the given exception handling
 /// region, creating it if necessary.
 BasicBlock *TreeToLLVM::getPostPad(unsigned RegionNo) {
@@ -1879,6 +1874,20 @@
   return PostPad;
 }
 
+/// getExceptionPtr - Return the local holding the exception pointer for the
+/// given exception handling region, creating it if necessary.
+AllocaInst *TreeToLLVM::getExceptionPtr(unsigned RegionNo) {
+  ExceptionPtrs.grow(RegionNo);
+  AllocaInst *&ExceptionPtr = ExceptionPtrs[RegionNo];
+
+  if (!ExceptionPtr) {
+    ExceptionPtr = CreateTemporary(Type::getInt8PtrTy(Context));
+    ExceptionPtr->setName("exc_ptr");
+  }
+
+  return ExceptionPtr;
+}
+
 /// AddHandler - Append the given region to a vector of exception handlers.
 /// A callback passed to foreach_reachable_handler.
 //FIXMEstatic void AddHandler (eh_region region, void *data) {
@@ -1901,13 +1910,13 @@
     BeginBlock(LandingPad);
 
     // Fetch and store the exception.
-    Value *Ex = Builder.CreateCall(FuncEHException, "eh_ptr");
-    Builder.CreateStore(Ex, ExceptionValue);
+    Value *ExcPtr = Builder.CreateCall(FuncEHException, "exc_ptr");
+    Builder.CreateStore(ExcPtr, getExceptionPtr(i));
 
     // Fetch and store the exception selector.
 
     // The exception and the personality function.
-    Args.push_back(Builder.CreateLoad(ExceptionValue, "eh_ptr"));
+    Args.push_back(ExcPtr);
 abort();//FIXME
 //FIXME    assert(llvm_eh_personality_libfunc
 //FIXME           && "no exception handling personality function!");
@@ -2637,20 +2646,12 @@
 //FIXME    // Is the call contained in an exception handling region?
 //FIXME    if (RegionNo > 0) {
 //FIXME      // Are there any exception handlers for this region?
-//FIXME      if (can_throw_internal_1(RegionNo, false, false)) {
+//FIXME      if (can_throw_internal_1(RegionNo, false, false))
 //FIXME        // There are - turn the call into an invoke.
-//FIXME        LandingPads.grow(RegionNo);
-//FIXME        BasicBlock *&ThisPad = LandingPads[RegionNo];
-//FIXME
-//FIXME        // Create a landing pad if one didn't exist already.
-//FIXME        if (!ThisPad)
-//FIXME          ThisPad = BasicBlock::Create(Context, "lpad");
-//FIXME
-//FIXME        LandingPad = ThisPad;
-//FIXME      } else {
+//FIXME        LandingPad = getLandingPad(RegionNo);
+//FIXME      else
 //FIXME        assert(can_throw_external_1(RegionNo, false, false) &&
 //FIXME               "Must-not-throw region handled by runtime?");
-//FIXME      }
 //FIXME    }
   }
 
@@ -2824,23 +2825,6 @@
   return 0;
 }
 
-/// EmitEXC_PTR_EXPR - Handle EXC_PTR_EXPR.
-Value *TreeToLLVM::EmitEXC_PTR_EXPR(tree exp) {
-abort();
-//TODO  CreateExceptionValues();
-//TODO  // Load exception address.
-//TODO  Value *V = Builder.CreateLoad(ExceptionValue, "eh_value");
-//TODO  // Cast the address to the right pointer type.
-//TODO  return Builder.CreateBitCast(V, ConvertType(TREE_TYPE(exp)));
-}
-
-/// EmitFILTER_EXPR - Handle FILTER_EXPR.
-Value *TreeToLLVM::EmitFILTER_EXPR(tree exp) {
-abort();
-//FIXME  CreateExceptionValues();
-//FIXME  // Load exception selector.
-//FIXME  return Builder.CreateLoad(ExceptionSelectorValue, "eh_select");
-}
 
 //===----------------------------------------------------------------------===//
 //               ... Inline Assembly and Register Variables ...
@@ -3576,6 +3560,10 @@
   case BUILT_IN_INIT_TRAMPOLINE:
     return EmitBuiltinInitTrampoline(stmt, Result);
 
+  // Exception handling builtins.
+  case BUILT_IN_EH_POINTER:
+    return EmitBuiltinEHPointer(stmt, Result);
+
   // Builtins used by the exception handling runtime.
   case BUILT_IN_DWARF_CFA:
     return EmitBuiltinDwarfCFA(stmt, Result);
@@ -4742,6 +4730,21 @@
 }
 
 
+// Exception handling builtins.
+
+bool TreeToLLVM::EmitBuiltinEHPointer(gimple stmt, Value *&Result) {
+  // Lookup the local that holds the exception pointer for this region.
+  unsigned RegionNo = tree_low_cst(gimple_call_arg(stmt, 0), 0);
+  AllocaInst *ExcPtr = getExceptionPtr(RegionNo);
+  // Load the exception pointer out.
+  Result = Builder.CreateLoad(ExcPtr);
+  // Ensure the returned value has the right pointer type.
+  tree type = gimple_call_return_type(stmt);
+  Result = Builder.CreateBitCast(Result, ConvertType(type));
+  return true;
+}
+
+
 // Builtins used by the exception handling runtime.
 
 // On most machines, the CFA coincides with the first incoming parm.
@@ -5505,24 +5508,6 @@
   return LValue(Builder.CreateBitCast(Decl, PTy), Alignment);
 }
 
-LValue TreeToLLVM::EmitLV_EXC_PTR_EXPR(tree exp) {
-  CreateExceptionValues();
-  // Cast the address pointer to the expected type.
-  unsigned Alignment = TD.getABITypeAlignment(cast<PointerType>(ExceptionValue->
-                                                  getType())->getElementType());
-  return LValue(Builder.CreateBitCast(ExceptionValue,
-                           PointerType::getUnqual(ConvertType(TREE_TYPE(exp)))),
-                Alignment);
-}
-
-LValue TreeToLLVM::EmitLV_FILTER_EXPR(tree exp) {
-  CreateExceptionValues();
-  unsigned Alignment =
-    TD.getABITypeAlignment(cast<PointerType>(ExceptionSelectorValue->
-                                             getType())->getElementType());
-  return LValue(ExceptionSelectorValue, Alignment);
-}
-
 LValue TreeToLLVM::EmitLV_INDIRECT_REF(tree exp) {
   // The lvalue is just the address.
   LValue LV = LValue(EmitRegister(TREE_OPERAND(exp, 0)), expr_align(exp) / 8);

Modified: dragonegg/trunk/llvm-internal.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-internal.h?rev=99430&r1=99429&r2=99430&view=diff
==============================================================================
--- dragonegg/trunk/llvm-internal.h (original)
+++ dragonegg/trunk/llvm-internal.h Wed Mar 24 16:33:18 2010
@@ -430,12 +430,8 @@
   /// PostPads - The post landing pad for a given EH region.
   IndexedMap<BasicBlock *> PostPads;
 
-  /// ExceptionValue - Is the local to receive the current exception.
-  Value *ExceptionValue;
-
-  /// ExceptionSelectorValue - Is the local to receive the current exception
-  /// selector.
-  Value *ExceptionSelectorValue;
+  /// ExceptionPtrs - The local holding the exception pointer for a EH region.
+  IndexedMap<AllocaInst *> ExceptionPtrs;
 
   /// FuncEHException - Function used to receive the exception.
   Function *FuncEHException;
@@ -574,10 +570,18 @@
   /// handling.
   void CreateExceptionValues();
 
+  /// getLandingPad - Return the landing pad for the given exception handling
+  /// region, creating it if necessary.
+  BasicBlock *getLandingPad(unsigned RegionNo);
+
   /// getPostPad - Return the post landing pad for the given exception handling
   /// region, creating it if necessary.
   BasicBlock *getPostPad(unsigned RegionNo);
 
+  /// getExceptionPtr - Return the local holding the exception pointer for the
+  /// given exception handling region, creating it if necessary.
+  AllocaInst *getExceptionPtr(unsigned RegionNo);
+
 private:
   void EmitAutomaticVariableDecl(tree_node *decl);
 
@@ -695,10 +699,6 @@
                     const AttrListPtr &PAL);
   Value *EmitFieldAnnotation(Value *FieldPtr, tree_node *FieldDecl);
 
-  // Exception Handling.
-  Value *EmitEXC_PTR_EXPR(tree_node *exp);
-  Value *EmitFILTER_EXPR(tree_node *exp);
-
   // Inline Assembly and Register Variables.
   Value *EmitReadOfRegisterVariable(tree_node *vardecl);
   void EmitModifyOfRegisterVariable(tree_node *vardecl, Value *RHS);
@@ -739,6 +739,7 @@
   bool EmitBuiltinFrobReturnAddr(gimple stmt, Value *&Result);
   bool EmitBuiltinStackSave(gimple stmt, Value *&Result);
   bool EmitBuiltinStackRestore(gimple stmt);
+  bool EmitBuiltinEHPointer(gimple stmt, Value *&Result);
   bool EmitBuiltinDwarfCFA(gimple stmt, Value *&Result);
   bool EmitBuiltinDwarfSPColumn(gimple stmt, Value *&Result);
   bool EmitBuiltinEHReturnDataRegno(gimple stmt, Value *&Result);
@@ -758,8 +759,6 @@
   LValue EmitLV_BIT_FIELD_REF(tree_node *exp);
   LValue EmitLV_COMPONENT_REF(tree_node *exp);
   LValue EmitLV_DECL(tree_node *exp);
-  LValue EmitLV_EXC_PTR_EXPR(tree_node *exp);
-  LValue EmitLV_FILTER_EXPR(tree_node *exp);
   LValue EmitLV_INDIRECT_REF(tree_node *exp);
   LValue EmitLV_VIEW_CONVERT_EXPR(tree_node *exp);
   LValue EmitLV_WITH_SIZE_EXPR(tree_node *exp);





More information about the llvm-commits mailing list