[llvm-commits] [gcc-plugin] r81674 - in /gcc-plugin/trunk: llvm-convert.cpp llvm-internal.h

Duncan Sands baldrick at free.fr
Sun Sep 13 08:51:33 PDT 2009


Author: baldrick
Date: Sun Sep 13 10:51:32 2009
New Revision: 81674

URL: http://llvm.org/viewvc/llvm-project?rev=81674&view=rev
Log:
Output gimple gotos directly, rather than going via
a tree.

Modified:
    gcc-plugin/trunk/llvm-convert.cpp
    gcc-plugin/trunk/llvm-internal.h

Modified: gcc-plugin/trunk/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/llvm-convert.cpp?rev=81674&r1=81673&r2=81674&view=diff

==============================================================================
--- gcc-plugin/trunk/llvm-convert.cpp (original)
+++ gcc-plugin/trunk/llvm-convert.cpp Sun Sep 13 10:51:32 2009
@@ -949,7 +949,6 @@
 
     switch (gimple_code(gimple_stmt)) {
     case GIMPLE_ASSIGN:
-    case GIMPLE_GOTO:
     case GIMPLE_RETURN:
     case GIMPLE_ASM:
     case GIMPLE_CALL:
@@ -976,6 +975,10 @@
       RenderGIMPLE_COND(gimple_stmt);
       break;
 
+    case GIMPLE_GOTO:
+      RenderGIMPLE_GOTO(gimple_stmt);
+      break;
+
     case GIMPLE_LABEL:
     case GIMPLE_NOP:
     case GIMPLE_PREDICT:
@@ -1046,7 +1049,6 @@
 
   // Control flow
   case LABEL_EXPR:     break;
-  case GOTO_EXPR:      Result = EmitGOTO_EXPR(exp); break;
   case RETURN_EXPR:    Result = EmitRETURN_EXPR(exp, DestLoc); break;
   case SWITCH_EXPR:    Result = EmitSWITCH_EXPR(exp); break;
 
@@ -1908,31 +1910,6 @@
 //                           ... Control Flow ...
 //===----------------------------------------------------------------------===//
 
-Value *TreeToLLVM::EmitGOTO_EXPR(tree exp) {
-  if (TREE_CODE(TREE_OPERAND(exp, 0)) == LABEL_DECL) {
-    // Direct branch.
-    Builder.CreateBr(getLabelDeclBlock(TREE_OPERAND(exp, 0)));
-  } else {
-
-    // Otherwise we have an indirect goto.
-    BasicBlock *DestBB = getIndirectGotoBlock();
-
-    // Store the destination block to the GotoValue alloca.
-    Value *V = Emit(TREE_OPERAND(exp, 0), 0);
-    V = CastToType(Instruction::PtrToInt, V, TD.getIntPtrType(Context));
-    Builder.CreateStore(V, IndirectGotoValue);
-
-    // NOTE: This is HORRIBLY INCORRECT in the presence of exception handlers.
-    // There should be one collector block per cleanup level!  Note that
-    // standard GCC gets this wrong as well.
-    //
-    Builder.CreateBr(DestBB);
-  }
-  EmitBlock(BasicBlock::Create(Context));
-  return 0;
-}
-
-
 Value *TreeToLLVM::EmitRETURN_EXPR(tree exp, const MemRef *DestLoc) {
   assert(DestLoc == 0 && "Does not return a value!");
   tree retval = TREE_OPERAND(exp, 0);
@@ -8153,3 +8130,24 @@
   // Branch based on the condition.
   Builder.CreateCondBr(Cond, IfTrue, IfFalse);
 }
+
+void TreeToLLVM::RenderGIMPLE_GOTO(gimple stmt) {
+  tree dest = gimple_goto_dest(stmt);
+
+  if (TREE_CODE(dest) == LABEL_DECL) {
+    // Direct branch.
+    Builder.CreateBr(getLabelDeclBlock(dest));
+    return;
+  }
+
+  // Otherwise we have an indirect goto.
+  BasicBlock *DestBB = getIndirectGotoBlock();
+
+  // Store the destination block to the GotoValue alloca.
+  Value *V = Builder.CreatePtrToInt(Emit(dest, 0), TD.getIntPtrType(Context));
+  Builder.CreateStore(V, IndirectGotoValue);
+
+  // NOTE: This is HORRIBLY INCORRECT in the presence of exception handlers.
+  // There should be one collector block per cleanup level!
+  Builder.CreateBr(DestBB);
+}

Modified: gcc-plugin/trunk/llvm-internal.h
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/llvm-internal.h?rev=81674&r1=81673&r2=81674&view=diff

==============================================================================
--- gcc-plugin/trunk/llvm-internal.h (original)
+++ gcc-plugin/trunk/llvm-internal.h Sun Sep 13 10:51:32 2009
@@ -518,8 +518,8 @@
 private:
 
   // Render* - Convert GIMPLE to LLVM.
-
   void RenderGIMPLE_COND(gimple_statement_d *);
+  void RenderGIMPLE_GOTO(gimple_statement_d *);
 
 private:
   void EmitAutomaticVariableDecl(tree_node *decl);
@@ -541,7 +541,6 @@
   // characteristics.
 
   // Control flow.
-  Value *EmitGOTO_EXPR(tree_node *exp);
   Value *EmitRETURN_EXPR(tree_node *exp, const MemRef *DestLoc);
   Value *EmitSWITCH_EXPR(tree_node *exp);
 





More information about the llvm-commits mailing list