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

Duncan Sands baldrick at free.fr
Wed Sep 9 05:16:29 PDT 2009


Author: baldrick
Date: Wed Sep  9 07:16:04 2009
New Revision: 81334

URL: http://llvm.org/viewvc/llvm-project?rev=81334&view=rev
Log:
Due to recent changes in basic block handling, there
is no longer any need to do anything special for
LABEL_DECL, and in fact the old code causes trouble.
Also, if a basic block contains a label, name the LLVM
basic block after the label.

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=81334&r1=81333&r2=81334&view=diff

==============================================================================
--- gcc-plugin/trunk/llvm-convert.cpp (original)
+++ gcc-plugin/trunk/llvm-convert.cpp Wed Sep  9 07:16:04 2009
@@ -761,11 +761,25 @@
 
 /// getBasicBlock - Find or create the LLVM basic block corresponding to BB.
 BasicBlock *TreeToLLVM::getBasicBlock(basic_block bb) {
+  // If we already associated an LLVM basic block with BB, then return it.
   DenseMap<basic_block, BasicBlock*>::iterator I = BasicBlocks.find(bb);
   if (I != BasicBlocks.end())
     return I->second;
-  Twine Name(bb->index);
-  return BasicBlocks[bb] = BasicBlock::Create(Context, "bb " + Name);
+
+  // Otherwise, create a new LLVM basic block.
+  BasicBlock *BB = BasicBlock::Create(Context);
+
+  // If BB contains labels, name the LLVM basic block after the first one.
+  gimple stmt = first_stmt (bb);
+  if (stmt && gimple_code (stmt) == GIMPLE_LABEL) {
+    BB->setName(IDENTIFIER_POINTER(DECL_NAME(gimple_label_label(stmt))));
+  } else {
+    // Use the same basic block naming scheme as the GCC tree dumps.
+    Twine Name(bb->index);
+    BB->setName("<bb " + Name + ">");
+  }
+
+  return BasicBlocks[bb] = BB;
 }
 
 /// getLabelDeclBlock - Lazily get and create a basic block for the specified
@@ -914,7 +928,7 @@
     llvm_unreachable("Unhandled expression!");
 
   // Control flow
-  case LABEL_EXPR:     Result = EmitLABEL_EXPR(exp); break;
+  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;
@@ -1777,13 +1791,6 @@
 //                           ... Control Flow ...
 //===----------------------------------------------------------------------===//
 
-/// EmitLABEL_EXPR - Emit the basic block corresponding to the specified label.
-///
-Value *TreeToLLVM::EmitLABEL_EXPR(tree exp) {
-  EmitBlock(getLabelDeclBlock(TREE_OPERAND(exp, 0)));
-  return 0;
-}
-
 Value *TreeToLLVM::EmitGOTO_EXPR(tree exp) {
   if (TREE_CODE(TREE_OPERAND(exp, 0)) == LABEL_DECL) {
     // Direct branch.

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

==============================================================================
--- gcc-plugin/trunk/llvm-internal.h (original)
+++ gcc-plugin/trunk/llvm-internal.h Wed Sep  9 07:16:04 2009
@@ -538,7 +538,6 @@
   // characteristics.
 
   // Control flow.
-  Value *EmitLABEL_EXPR(tree_node *exp);
   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