mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-19 19:29:31 +00:00
Print all PHI copies for successor blocks before the terminator, whether it be a conditional branch or switch.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13430 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
be97b4e9ab
commit
a05e0ec419
@ -27,6 +27,7 @@
|
|||||||
#include "llvm/Analysis/ConstantsScanner.h"
|
#include "llvm/Analysis/ConstantsScanner.h"
|
||||||
#include "llvm/Transforms/Scalar.h"
|
#include "llvm/Transforms/Scalar.h"
|
||||||
#include "llvm/Support/CallSite.h"
|
#include "llvm/Support/CallSite.h"
|
||||||
|
#include "llvm/Support/CFG.h"
|
||||||
#include "llvm/Support/GetElementPtrTypeIterator.h"
|
#include "llvm/Support/GetElementPtrTypeIterator.h"
|
||||||
#include "llvm/Support/InstVisitor.h"
|
#include "llvm/Support/InstVisitor.h"
|
||||||
#include "llvm/Support/Mangler.h"
|
#include "llvm/Support/Mangler.h"
|
||||||
@ -162,6 +163,8 @@ namespace {
|
|||||||
void outputLValue(Instruction *I) {
|
void outputLValue(Instruction *I) {
|
||||||
Out << " " << Mang->getValueName(I) << " = ";
|
Out << " " << Mang->getValueName(I) << " = ";
|
||||||
}
|
}
|
||||||
|
void printPHICopiesForSuccessors(BasicBlock *CurBlock,
|
||||||
|
unsigned Indent);
|
||||||
void printBranchToBlock(BasicBlock *CurBlock, BasicBlock *SuccBlock,
|
void printBranchToBlock(BasicBlock *CurBlock, BasicBlock *SuccBlock,
|
||||||
unsigned Indent);
|
unsigned Indent);
|
||||||
void printIndexingExpression(Value *Ptr, gep_type_iterator I,
|
void printIndexingExpression(Value *Ptr, gep_type_iterator I,
|
||||||
@ -1035,6 +1038,8 @@ void CWriter::visitReturnInst(ReturnInst &I) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CWriter::visitSwitchInst(SwitchInst &SI) {
|
void CWriter::visitSwitchInst(SwitchInst &SI) {
|
||||||
|
printPHICopiesForSuccessors(SI.getParent(), 0);
|
||||||
|
|
||||||
Out << " switch (";
|
Out << " switch (";
|
||||||
writeOperand(SI.getOperand(0));
|
writeOperand(SI.getOperand(0));
|
||||||
Out << ") {\n default:\n";
|
Out << ") {\n default:\n";
|
||||||
@ -1061,7 +1066,7 @@ void CWriter::visitUnwindInst(UnwindInst &I) {
|
|||||||
assert(0 && "Lowerinvoke pass didn't work!");
|
assert(0 && "Lowerinvoke pass didn't work!");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isGotoCodeNecessary(BasicBlock *From, BasicBlock *To) {
|
static bool isGotoCodeNecessary(BasicBlock *From, BasicBlock *To) {
|
||||||
// If PHI nodes need copies, we need the copy code...
|
// If PHI nodes need copies, we need the copy code...
|
||||||
if (isa<PHINode>(To->front()) ||
|
if (isa<PHINode>(To->front()) ||
|
||||||
From->getNext() != To) // Not directly successor, need goto
|
From->getNext() != To) // Not directly successor, need goto
|
||||||
@ -1071,17 +1076,23 @@ bool isGotoCodeNecessary(BasicBlock *From, BasicBlock *To) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWriter::printBranchToBlock(BasicBlock *CurBB, BasicBlock *Succ,
|
void CWriter::printPHICopiesForSuccessors(BasicBlock *CurBlock,
|
||||||
unsigned Indent) {
|
unsigned Indent) {
|
||||||
for (BasicBlock::iterator I = Succ->begin();
|
for (succ_iterator SI = succ_begin(CurBlock), E = succ_end(CurBlock);
|
||||||
|
SI != E; ++SI)
|
||||||
|
for (BasicBlock::iterator I = SI->begin();
|
||||||
PHINode *PN = dyn_cast<PHINode>(I); ++I) {
|
PHINode *PN = dyn_cast<PHINode>(I); ++I) {
|
||||||
// now we have to do the printing
|
// now we have to do the printing
|
||||||
Out << std::string(Indent, ' ');
|
Out << std::string(Indent, ' ');
|
||||||
Out << " " << Mang->getValueName(I) << "__PHI_TEMPORARY = ";
|
Out << " " << Mang->getValueName(I) << "__PHI_TEMPORARY = ";
|
||||||
writeOperand(PN->getIncomingValue(PN->getBasicBlockIndex(CurBB)));
|
writeOperand(PN->getIncomingValue(PN->getBasicBlockIndex(CurBlock)));
|
||||||
Out << "; /* for PHI node */\n";
|
Out << "; /* for PHI node */\n";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CWriter::printBranchToBlock(BasicBlock *CurBB, BasicBlock *Succ,
|
||||||
|
unsigned Indent) {
|
||||||
if (CurBB->getNext() != Succ ||
|
if (CurBB->getNext() != Succ ||
|
||||||
isa<InvokeInst>(CurBB->getTerminator()) ||
|
isa<InvokeInst>(CurBB->getTerminator()) ||
|
||||||
isa<SwitchInst>(CurBB->getTerminator())) {
|
isa<SwitchInst>(CurBB->getTerminator())) {
|
||||||
@ -1095,6 +1106,8 @@ void CWriter::printBranchToBlock(BasicBlock *CurBB, BasicBlock *Succ,
|
|||||||
// that immediately succeeds the current one.
|
// that immediately succeeds the current one.
|
||||||
//
|
//
|
||||||
void CWriter::visitBranchInst(BranchInst &I) {
|
void CWriter::visitBranchInst(BranchInst &I) {
|
||||||
|
printPHICopiesForSuccessors(I.getParent(), 0);
|
||||||
|
|
||||||
if (I.isConditional()) {
|
if (I.isConditional()) {
|
||||||
if (isGotoCodeNecessary(I.getParent(), I.getSuccessor(0))) {
|
if (isGotoCodeNecessary(I.getParent(), I.getSuccessor(0))) {
|
||||||
Out << " if (";
|
Out << " if (";
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "llvm/Analysis/ConstantsScanner.h"
|
#include "llvm/Analysis/ConstantsScanner.h"
|
||||||
#include "llvm/Transforms/Scalar.h"
|
#include "llvm/Transforms/Scalar.h"
|
||||||
#include "llvm/Support/CallSite.h"
|
#include "llvm/Support/CallSite.h"
|
||||||
|
#include "llvm/Support/CFG.h"
|
||||||
#include "llvm/Support/GetElementPtrTypeIterator.h"
|
#include "llvm/Support/GetElementPtrTypeIterator.h"
|
||||||
#include "llvm/Support/InstVisitor.h"
|
#include "llvm/Support/InstVisitor.h"
|
||||||
#include "llvm/Support/Mangler.h"
|
#include "llvm/Support/Mangler.h"
|
||||||
@ -162,6 +163,8 @@ namespace {
|
|||||||
void outputLValue(Instruction *I) {
|
void outputLValue(Instruction *I) {
|
||||||
Out << " " << Mang->getValueName(I) << " = ";
|
Out << " " << Mang->getValueName(I) << " = ";
|
||||||
}
|
}
|
||||||
|
void printPHICopiesForSuccessors(BasicBlock *CurBlock,
|
||||||
|
unsigned Indent);
|
||||||
void printBranchToBlock(BasicBlock *CurBlock, BasicBlock *SuccBlock,
|
void printBranchToBlock(BasicBlock *CurBlock, BasicBlock *SuccBlock,
|
||||||
unsigned Indent);
|
unsigned Indent);
|
||||||
void printIndexingExpression(Value *Ptr, gep_type_iterator I,
|
void printIndexingExpression(Value *Ptr, gep_type_iterator I,
|
||||||
@ -1035,6 +1038,8 @@ void CWriter::visitReturnInst(ReturnInst &I) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CWriter::visitSwitchInst(SwitchInst &SI) {
|
void CWriter::visitSwitchInst(SwitchInst &SI) {
|
||||||
|
printPHICopiesForSuccessors(SI.getParent(), 0);
|
||||||
|
|
||||||
Out << " switch (";
|
Out << " switch (";
|
||||||
writeOperand(SI.getOperand(0));
|
writeOperand(SI.getOperand(0));
|
||||||
Out << ") {\n default:\n";
|
Out << ") {\n default:\n";
|
||||||
@ -1061,7 +1066,7 @@ void CWriter::visitUnwindInst(UnwindInst &I) {
|
|||||||
assert(0 && "Lowerinvoke pass didn't work!");
|
assert(0 && "Lowerinvoke pass didn't work!");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isGotoCodeNecessary(BasicBlock *From, BasicBlock *To) {
|
static bool isGotoCodeNecessary(BasicBlock *From, BasicBlock *To) {
|
||||||
// If PHI nodes need copies, we need the copy code...
|
// If PHI nodes need copies, we need the copy code...
|
||||||
if (isa<PHINode>(To->front()) ||
|
if (isa<PHINode>(To->front()) ||
|
||||||
From->getNext() != To) // Not directly successor, need goto
|
From->getNext() != To) // Not directly successor, need goto
|
||||||
@ -1071,17 +1076,23 @@ bool isGotoCodeNecessary(BasicBlock *From, BasicBlock *To) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWriter::printBranchToBlock(BasicBlock *CurBB, BasicBlock *Succ,
|
void CWriter::printPHICopiesForSuccessors(BasicBlock *CurBlock,
|
||||||
unsigned Indent) {
|
unsigned Indent) {
|
||||||
for (BasicBlock::iterator I = Succ->begin();
|
for (succ_iterator SI = succ_begin(CurBlock), E = succ_end(CurBlock);
|
||||||
|
SI != E; ++SI)
|
||||||
|
for (BasicBlock::iterator I = SI->begin();
|
||||||
PHINode *PN = dyn_cast<PHINode>(I); ++I) {
|
PHINode *PN = dyn_cast<PHINode>(I); ++I) {
|
||||||
// now we have to do the printing
|
// now we have to do the printing
|
||||||
Out << std::string(Indent, ' ');
|
Out << std::string(Indent, ' ');
|
||||||
Out << " " << Mang->getValueName(I) << "__PHI_TEMPORARY = ";
|
Out << " " << Mang->getValueName(I) << "__PHI_TEMPORARY = ";
|
||||||
writeOperand(PN->getIncomingValue(PN->getBasicBlockIndex(CurBB)));
|
writeOperand(PN->getIncomingValue(PN->getBasicBlockIndex(CurBlock)));
|
||||||
Out << "; /* for PHI node */\n";
|
Out << "; /* for PHI node */\n";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CWriter::printBranchToBlock(BasicBlock *CurBB, BasicBlock *Succ,
|
||||||
|
unsigned Indent) {
|
||||||
if (CurBB->getNext() != Succ ||
|
if (CurBB->getNext() != Succ ||
|
||||||
isa<InvokeInst>(CurBB->getTerminator()) ||
|
isa<InvokeInst>(CurBB->getTerminator()) ||
|
||||||
isa<SwitchInst>(CurBB->getTerminator())) {
|
isa<SwitchInst>(CurBB->getTerminator())) {
|
||||||
@ -1095,6 +1106,8 @@ void CWriter::printBranchToBlock(BasicBlock *CurBB, BasicBlock *Succ,
|
|||||||
// that immediately succeeds the current one.
|
// that immediately succeeds the current one.
|
||||||
//
|
//
|
||||||
void CWriter::visitBranchInst(BranchInst &I) {
|
void CWriter::visitBranchInst(BranchInst &I) {
|
||||||
|
printPHICopiesForSuccessors(I.getParent(), 0);
|
||||||
|
|
||||||
if (I.isConditional()) {
|
if (I.isConditional()) {
|
||||||
if (isGotoCodeNecessary(I.getParent(), I.getSuccessor(0))) {
|
if (isGotoCodeNecessary(I.getParent(), I.getSuccessor(0))) {
|
||||||
Out << " if (";
|
Out << " if (";
|
||||||
|
Loading…
Reference in New Issue
Block a user