From cf5cd875b51255602afaed29deb636b66b295671 Mon Sep 17 00:00:00 2001
From: ed <ed@FreeBSD.org>
Date: Sat, 27 Jun 2009 10:44:33 +0000
Subject: Import LLVM r74383.

---
 lib/Transforms/Utils/CMakeLists.txt |  2 ++
 lib/Transforms/Utils/LCSSA.cpp      | 13 ++++++++++--
 lib/Transforms/Utils/Local.cpp      | 41 -------------------------------------
 3 files changed, 13 insertions(+), 43 deletions(-)

(limited to 'lib/Transforms/Utils')

diff --git a/lib/Transforms/Utils/CMakeLists.txt b/lib/Transforms/Utils/CMakeLists.txt
index 6628b4b..d68bf02 100644
--- a/lib/Transforms/Utils/CMakeLists.txt
+++ b/lib/Transforms/Utils/CMakeLists.txt
@@ -25,3 +25,5 @@ add_llvm_library(LLVMTransformUtils
   ValueMapper.cpp
   InstructionNamer.cpp
   )
+
+target_link_libraries (LLVMTransformUtils LLVMSupport)
diff --git a/lib/Transforms/Utils/LCSSA.cpp b/lib/Transforms/Utils/LCSSA.cpp
index 7d4f3a3..d5e7303 100644
--- a/lib/Transforms/Utils/LCSSA.cpp
+++ b/lib/Transforms/Utils/LCSSA.cpp
@@ -149,7 +149,16 @@ void LCSSA::ProcessInstruction(Instruction *Instr,
   // Keep track of the blocks that have the value available already.
   DenseMap<DomTreeNode*, Value*> Phis;
 
-  DomTreeNode *InstrNode = DT->getNode(Instr->getParent());
+  BasicBlock *DomBB = Instr->getParent();
+
+  // Invoke instructions are special in that their result value is not available
+  // along their unwind edge. The code below tests to see whether DomBB dominates
+  // the value, so adjust DomBB to the normal destination block, which is
+  // effectively where the value is first usable.
+  if (InvokeInst *Inv = dyn_cast<InvokeInst>(Instr))
+    DomBB = Inv->getNormalDest();
+
+  DomTreeNode *DomNode = DT->getNode(DomBB);
 
   // Insert the LCSSA phi's into the exit blocks (dominated by the value), and
   // add them to the Phi's map.
@@ -158,7 +167,7 @@ void LCSSA::ProcessInstruction(Instruction *Instr,
     BasicBlock *BB = *BBI;
     DomTreeNode *ExitBBNode = DT->getNode(BB);
     Value *&Phi = Phis[ExitBBNode];
-    if (!Phi && DT->dominates(InstrNode, ExitBBNode)) {
+    if (!Phi && DT->dominates(DomNode, ExitBBNode)) {
       PHINode *PN = PHINode::Create(Instr->getType(), Instr->getName()+".lcssa",
                                     BB->begin());
       PN->reserveOperandSpace(PredCache.GetNumPreds(BB));
diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp
index c7fff54..8c08638 100644
--- a/lib/Transforms/Utils/Local.cpp
+++ b/lib/Transforms/Utils/Local.cpp
@@ -340,44 +340,3 @@ bool llvm::OnlyUsedByDbgInfoIntrinsics(Instruction *I,
   return true;
 }
 
-/// UserIsDebugInfo - Return true if U is a constant expr used by 
-/// llvm.dbg.variable or llvm.dbg.global_variable
-bool llvm::UserIsDebugInfo(User *U) {
-  ConstantExpr *CE = dyn_cast<ConstantExpr>(U);
-
-  if (!CE || CE->getNumUses() != 1)
-    return false;
-
-  Constant *Init = dyn_cast<Constant>(CE->use_back());
-  if (!Init || Init->getNumUses() != 1)
-    return false;
-
-  GlobalVariable *GV = dyn_cast<GlobalVariable>(Init->use_back());
-  if (!GV || !GV->hasInitializer() || GV->getInitializer() != Init)
-    return false;
-
-  DIVariable DV(GV);
-  if (!DV.isNull()) 
-    return true; // User is llvm.dbg.variable
-
-  DIGlobalVariable DGV(GV);
-  if (!DGV.isNull())
-    return true; // User is llvm.dbg.global_variable
-
-  return false;
-}
-
-/// RemoveDbgInfoUser - Remove an User which is representing debug info.
-void llvm::RemoveDbgInfoUser(User *U) {
-  assert (UserIsDebugInfo(U) && "Unexpected User!");
-  ConstantExpr *CE = cast<ConstantExpr>(U);
-  while (!CE->use_empty()) {
-    Constant *C = cast<Constant>(CE->use_back());
-    while (!C->use_empty()) {
-      GlobalVariable *GV = cast<GlobalVariable>(C->use_back());
-      GV->eraseFromParent();
-    }
-    C->destroyConstant();
-  }
-  CE->destroyConstant();
-}
-- 
cgit v1.1