Fix bug: UnitTests/2003-05-02-DependantPHI.c

Fix testcase MultiSource/Ptrdist-ks

llvm-svn: 6000
This commit is contained in:
Chris Lattner 2003-05-03 07:11:00 +00:00
parent 0ec2b1188a
commit 5636fe923e

View File

@ -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.