diff options
author | Chris Lattner <sabre@nondot.org> | 2003-05-03 07:11:00 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-05-03 07:11:00 +0000 |
commit | 84e66655701008654105bf50801a794d02ef8094 (patch) | |
tree | 9e238025bc253524ad55a86db8ab6002ee4b6617 /lib/Target/CBackend/CBackend.cpp | |
parent | 577385edd80d4560347ead1174a44794124206fd (diff) |
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
Diffstat (limited to 'lib/Target/CBackend/CBackend.cpp')
-rw-r--r-- | lib/Target/CBackend/CBackend.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index 4c5fd07207..59a2fd9b96 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 @@ namespace { 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 @@ void CWriter::printFunction(Function *F) { 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 @@ void CWriter::printFunction(Function *F) { // 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 @@ void CWriter::printBranchToBlock(BasicBlock *CurBB, BasicBlock *Succ, 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 @@ void CWriter::visitBranchInst(BranchInst &I) { 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. |