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

Duncan Sands baldrick at free.fr
Tue Sep 8 02:02:13 PDT 2009


Author: baldrick
Date: Tue Sep  8 04:02:13 2009
New Revision: 81209

URL: http://llvm.org/viewvc/llvm-project?rev=81209&view=rev
Log:
When no label is available, work directly with basic
blocks rather than constructing a label.  Name basic
blocks using the same scheme as GCC.

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=81209&r1=81208&r2=81209&view=diff

==============================================================================
--- gcc-plugin/trunk/llvm-convert.cpp (original)
+++ gcc-plugin/trunk/llvm-convert.cpp Tue Sep  8 04:02:13 2009
@@ -198,24 +198,6 @@
   TheTreeToLLVM = 0;
 }
 
-/// getLabelDeclBlock - Lazily get and create a basic block for the specified
-/// label.
-/// TODO: remove uses of gimple_block_label, keep a map of GCC basic blocks to
-/// LLVM basic blocks rather than going via labels and DECL_LLVM.
-static BasicBlock *getLabelDeclBlock(tree LabelDecl) {
-  assert(TREE_CODE(LabelDecl) == LABEL_DECL && "Isn't a label!?");
-  if (DECL_LLVM_SET_P(LabelDecl))
-    return cast<BasicBlock>(DECL_LLVM(LabelDecl));
-
-  const char *Name = "bb";
-  if (DECL_NAME(LabelDecl))
-    Name = IDENTIFIER_POINTER(DECL_NAME(LabelDecl));
-
-  BasicBlock *NewBB = BasicBlock::Create(Context, Name);
-  SET_DECL_LLVM(LabelDecl, NewBB);
-  return NewBB;
-}
-
 /// llvm_store_scalar_argument - Store scalar argument ARGVAL of type
 /// LLVMTY at location LOC.
 static void llvm_store_scalar_argument(Value *Loc, Value *ArgVal,
@@ -742,6 +724,27 @@
   return Fn;
 }
 
+/// getBasicBlock - Find or create the LLVM basic block corresponding to BB.
+BasicBlock *TreeToLLVM::getBasicBlock(basic_block bb) {
+  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);
+}
+
+/// getLabelDeclBlock - Lazily get and create a basic block for the specified
+/// label.
+BasicBlock *TreeToLLVM::getLabelDeclBlock(tree LabelDecl) {
+  assert(TREE_CODE(LabelDecl) == LABEL_DECL && "Isn't a label!?");
+  if (DECL_LLVM_SET_P(LabelDecl))
+    return cast<BasicBlock>(DECL_LLVM(LabelDecl));
+
+  BasicBlock *BB = getBasicBlock(label_to_block(LabelDecl));
+  SET_DECL_LLVM(LabelDecl, BB);
+  return BB;
+}
+
 extern "C" tree gimple_to_tree(gimple);
 extern "C" void release_stmt_tree (gimple, tree);
 
@@ -794,7 +797,7 @@
     if (e->flags & EDGE_FALLTHRU)
       break;
   if (e && e->dest != bb->next_bb) {
-    Builder.CreateBr(getLabelDeclBlock(gimple_block_label (e->dest)));
+    Builder.CreateBr(getBasicBlock(e->dest));
     EmitBlock(BasicBlock::Create(Context, ""));
   }
 }
@@ -7866,7 +7869,7 @@
            "Taking the address of a label that isn't in the current fn!?");
   }
 
-  BasicBlock *BB = getLabelDeclBlock(exp);
+  BasicBlock *BB = TheTreeToLLVM->getLabelDeclBlock(exp);
   Constant *C = TheTreeToLLVM->getIndirectGotoBlockNumber(BB);
   return
        TheFolder->CreateIntToPtr(C, PointerType::getUnqual(Type::getInt8Ty(Context)));
@@ -8069,8 +8072,8 @@
   // Extract the target basic blocks.
   edge true_edge, false_edge;
   extract_true_false_edges_from_block(gimple_bb(stmt), &true_edge, &false_edge);
-  BasicBlock *IfTrue = getLabelDeclBlock(gimple_block_label(true_edge->dest));
-  BasicBlock *IfFalse = getLabelDeclBlock(gimple_block_label(false_edge->dest));
+  BasicBlock *IfTrue = getBasicBlock(true_edge->dest);
+  BasicBlock *IfFalse = getBasicBlock(false_edge->dest);
 
   // Branch based on the condition.
   Builder.CreateCondBr(Cond, IfTrue, IfFalse);

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

==============================================================================
--- gcc-plugin/trunk/llvm-internal.h (original)
+++ gcc-plugin/trunk/llvm-internal.h Tue Sep  8 04:02:13 2009
@@ -320,6 +320,9 @@
   /// same as &Fn->back().
   LLVMBuilder Builder;
 
+  /// BasicBlocks - Map from GCC to LLVM basic blocks.
+  DenseMap<basic_block, BasicBlock*> BasicBlocks;
+
   // AllocaInsertionPoint - Place to insert alloca instructions.  Lazily created
   // and managed by CreateTemporary.
   Instruction *AllocaInsertionPoint;
@@ -450,7 +453,16 @@
   /// FinishFunctionBody - Once the body of the function has been emitted, this
   /// cleans up and returns the result function.
   Function *FinishFunctionBody();
-  
+
+  /// getBasicBlock - Find or create the LLVM basic block corresponding to BB.
+  BasicBlock *getBasicBlock(basic_block bb);
+
+public:
+  /// getLabelDeclBlock - Lazily get and create a basic block for the specified
+  /// label.
+  BasicBlock *getLabelDeclBlock(tree_node *LabelDecl);
+
+private:
   /// Emit - Convert the specified tree node to LLVM code.  If the node is an
   /// expression that fits into an LLVM scalar value, the result is returned. If
   /// the result is an aggregate, it is stored into the location specified by





More information about the llvm-commits mailing list