Fix bug: UnitTests/2003-05-02-DependantPHI.c
Fix testcase MultiSource/Ptrdist-ks


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6000 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp
index 4c5fd07..59a2fd9 100644
--- a/lib/Target/CBackend/CBackend.cpp
+++ b/lib/Target/CBackend/CBackend.cpp
@@ -3,6 +3,7 @@
 // This library converts LLVM code to C code, compilable by GCC.
 //
 //===----------------------------------------------------------------------===//
+
 #include "llvm/Assembly/CWriter.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
@@ -103,7 +104,7 @@
     void visitBranchInst(BranchInst &I);
     void visitSwitchInst(SwitchInst &I);
 
-    void visitPHINode(PHINode &I) {}
+    void visitPHINode(PHINode &I);
     void visitBinaryOperator(Instruction &I);
 
     void visitCastInst (CastInst &I);
@@ -771,6 +772,12 @@
       Out << "  ";
       printType(Out, (*I)->getType(), getValueName(*I));
       Out << ";\n";
+
+      if (isa<PHINode>(*I)) {  // Print out PHI node temporaries as well...
+        Out << "  ";
+        printType(Out, (*I)->getType(), getValueName(*I)+"__PHI_TEMPORARY");
+        Out << ";\n";
+      }
     }
 
   Out << "\n";
@@ -825,7 +832,7 @@
 
     // Output all of the instructions in the basic block...
     for (BasicBlock::iterator II = BB->begin(), E = --BB->end(); II != E; ++II){
-      if (!isInlinableInst(*II) && !isa<PHINode>(*II)) {
+      if (!isInlinableInst(*II)) {
         if (II->getType() != Type::VoidTy)
           outputLValue(II);
         else
@@ -898,7 +905,7 @@
        PHINode *PN = dyn_cast<PHINode>(I); ++I) {
     //  now we have to do the printing
     Out << std::string(Indent, ' ');
-    outputLValue(PN);
+    Out << "  " << getValueName(I) << "__PHI_TEMPORARY = ";
     writeOperand(PN->getIncomingValue(PN->getBasicBlockIndex(CurBB)));
     Out << ";   /* for PHI node */\n";
   }
@@ -942,6 +949,14 @@
   Out << "\n";
 }
 
+// PHI nodes get copied into temporary values at the end of predecessor basic
+// blocks.  We now need to copy these temporary values into the REAL value for
+// the PHI.
+void CWriter::visitPHINode(PHINode &I) {
+  writeOperand(&I);
+  Out << "__PHI_TEMPORARY";
+}
+
 
 void CWriter::visitBinaryOperator(Instruction &I) {
   // binary instructions, shift instructions, setCond instructions.