Mostly cosmetic improvements. Do fix the bug where a global value was considered an input.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12406 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2004-03-15 01:26:44 +00:00
parent 0de632bfae
commit 15d443b566

View File

@ -78,8 +78,7 @@ namespace {
void CodeExtractor::processPhiNodeInputs(PHINode *Phi, void CodeExtractor::processPhiNodeInputs(PHINode *Phi,
Values &inputs, Values &inputs,
BasicBlock *codeReplacer, BasicBlock *codeReplacer,
BasicBlock *newFuncRoot) BasicBlock *newFuncRoot) {
{
// Separate incoming values and BasicBlocks as internal/external. We ignore // Separate incoming values and BasicBlocks as internal/external. We ignore
// the case where both the value and BasicBlock are internal, because we don't // the case where both the value and BasicBlock are internal, because we don't
// need to do a thing. // need to do a thing.
@ -99,11 +98,6 @@ void CodeExtractor::processPhiNodeInputs(PHINode *Phi,
else else
EValEBB.push_back(i); EValEBB.push_back(i);
} }
} else if (Constant *Const = dyn_cast<Constant>(phiVal)) {
// Constants are internal, but considered `external' if they are coming
// from an external block.
if (!BlocksToExtract.count(Phi->getIncomingBlock(i)))
EValEBB.push_back(i);
} else if (Argument *Arg = dyn_cast<Argument>(phiVal)) { } else if (Argument *Arg = dyn_cast<Argument>(phiVal)) {
// arguments are external // arguments are external
if (BlocksToExtract.count(Phi->getIncomingBlock(i))) if (BlocksToExtract.count(Phi->getIncomingBlock(i)))
@ -111,20 +105,21 @@ void CodeExtractor::processPhiNodeInputs(PHINode *Phi,
else else
EValEBB.push_back(i); EValEBB.push_back(i);
} else { } else {
phiVal->dump(); // Globals/Constants are internal, but considered `external' if they are
assert(0 && "Unhandled input in a Phi node"); // coming from an external block.
if (!BlocksToExtract.count(Phi->getIncomingBlock(i)))
EValEBB.push_back(i);
} }
} }
// Both value and block are external. Need to group all of // Both value and block are external. Need to group all of these, have an
// these, have an external phi, pass the result as an // external phi, pass the result as an argument, and have THIS phi use that
// argument, and have THIS phi use that result. // result.
if (EValEBB.size() > 0) { if (EValEBB.size() > 0) {
if (EValEBB.size() == 1) { if (EValEBB.size() == 1) {
// Now if it's coming from the newFuncRoot, it's that funky input // Now if it's coming from the newFuncRoot, it's that funky input
unsigned phiIdx = EValEBB[0]; unsigned phiIdx = EValEBB[0];
if (!dyn_cast<Constant>(Phi->getIncomingValue(phiIdx))) if (!isa<Constant>(Phi->getIncomingValue(phiIdx))) {
{
PhiVal2Arg[Phi].push_back(std::make_pair(phiIdx, inputs.size())); PhiVal2Arg[Phi].push_back(std::make_pair(phiIdx, inputs.size()));
// We can just pass this value in as argument // We can just pass this value in as argument
inputs.push_back(Phi->getIncomingValue(phiIdx)); inputs.push_back(Phi->getIncomingValue(phiIdx));
@ -134,8 +129,7 @@ void CodeExtractor::processPhiNodeInputs(PHINode *Phi,
PHINode *externalPhi = new PHINode(Phi->getType(), "extPhi"); PHINode *externalPhi = new PHINode(Phi->getType(), "extPhi");
codeReplacer->getInstList().insert(codeReplacer->begin(), externalPhi); codeReplacer->getInstList().insert(codeReplacer->begin(), externalPhi);
for (std::vector<unsigned>::iterator i = EValEBB.begin(), for (std::vector<unsigned>::iterator i = EValEBB.begin(),
e = EValEBB.end(); i != e; ++i) e = EValEBB.end(); i != e; ++i) {
{
externalPhi->addIncoming(Phi->getIncomingValue(*i), externalPhi->addIncoming(Phi->getIncomingValue(*i),
Phi->getIncomingBlock(*i)); Phi->getIncomingBlock(*i));
@ -152,21 +146,19 @@ void CodeExtractor::processPhiNodeInputs(PHINode *Phi,
} }
} }
// When the value is external, but block internal... // When the value is external, but block internal... just pass it in as
// just pass it in as argument, no change to phi node // argument, no change to phi node
for (std::vector<unsigned>::iterator i = EValIBB.begin(), for (std::vector<unsigned>::iterator i = EValIBB.begin(),
e = EValIBB.end(); i != e; ++i) e = EValIBB.end(); i != e; ++i) {
{
// rewrite the phi input node to be an argument // rewrite the phi input node to be an argument
PhiVal2Arg[Phi].push_back(std::make_pair(*i, inputs.size())); PhiVal2Arg[Phi].push_back(std::make_pair(*i, inputs.size()));
inputs.push_back(Phi->getIncomingValue(*i)); inputs.push_back(Phi->getIncomingValue(*i));
} }
// Value internal, block external // Value internal, block external this can happen if we are extracting a part
// this can happen if we are extracting a part of a loop // of a loop.
for (std::vector<unsigned>::iterator i = IValEBB.begin(), for (std::vector<unsigned>::iterator i = IValEBB.begin(),
e = IValEBB.end(); i != e; ++i) e = IValEBB.end(); i != e; ++i) {
{
assert(0 && "Cannot (YET) handle internal values via external blocks"); assert(0 && "Cannot (YET) handle internal values via external blocks");
} }
} }
@ -190,10 +182,8 @@ void CodeExtractor::findInputsOutputs(Values &inputs, Values &outputs,
op != opE; ++op) op != opE; ++op)
if (Instruction *opI = dyn_cast<Instruction>(*op)) { if (Instruction *opI = dyn_cast<Instruction>(*op)) {
// Check if definition of this operand is within the loop // Check if definition of this operand is within the loop
if (!BlocksToExtract.count(opI->getParent())) { if (!BlocksToExtract.count(opI->getParent()))
// add this operand to the inputs
inputs.push_back(opI); inputs.push_back(opI);
}
} else if (isa<Argument>(*op)) { } else if (isa<Argument>(*op)) {
inputs.push_back(*op); inputs.push_back(*op);
} }
@ -212,10 +202,9 @@ void CodeExtractor::rewritePhiNodes(Function *F,
BasicBlock *newFuncRoot) { BasicBlock *newFuncRoot) {
// Write any changes that were saved before: use function arguments as inputs // Write any changes that were saved before: use function arguments as inputs
for (PhiVal2ArgTy::iterator i = PhiVal2Arg.begin(), e = PhiVal2Arg.end(); for (PhiVal2ArgTy::iterator i = PhiVal2Arg.begin(), e = PhiVal2Arg.end();
i != e; ++i) i != e; ++i) {
{ PHINode *phi = i->first;
PHINode *phi = (*i).first; PhiValChangesTy &values = i->second;
PhiValChangesTy &values = (*i).second;
for (unsigned cIdx = 0, ce = values.size(); cIdx != ce; ++cIdx) for (unsigned cIdx = 0, ce = values.size(); cIdx != ce; ++cIdx)
{ {
unsigned phiValueIdx = values[cIdx].first, argNum = values[cIdx].second; unsigned phiValueIdx = values[cIdx].first, argNum = values[cIdx].second;
@ -228,9 +217,8 @@ void CodeExtractor::rewritePhiNodes(Function *F,
// Delete any invalid Phi node inputs that were marked as NULL previously // Delete any invalid Phi node inputs that were marked as NULL previously
for (PhiVal2ArgTy::iterator i = PhiVal2Arg.begin(), e = PhiVal2Arg.end(); for (PhiVal2ArgTy::iterator i = PhiVal2Arg.begin(), e = PhiVal2Arg.end();
i != e; ++i) i != e; ++i) {
{ PHINode *phi = i->first;
PHINode *phi = (*i).first;
for (unsigned idx = 0, end = phi->getNumIncomingValues(); idx != end; ++idx) for (unsigned idx = 0, end = phi->getNumIncomingValues(); idx != end; ++idx)
{ {
if (phi->getIncomingValue(idx) == 0 && phi->getIncomingBlock(idx) == 0) { if (phi->getIncomingValue(idx) == 0 && phi->getIncomingBlock(idx) == 0) {
@ -287,7 +275,7 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
DEBUG(std::cerr << "Function type: " << retTy << " f("); DEBUG(std::cerr << "Function type: " << retTy << " f(");
for (std::vector<const Type*>::iterator i = paramTy.begin(), for (std::vector<const Type*>::iterator i = paramTy.begin(),
e = paramTy.end(); i != e; ++i) e = paramTy.end(); i != e; ++i)
DEBUG(std::cerr << (*i) << ", "); DEBUG(std::cerr << *i << ", ");
DEBUG(std::cerr << ")\n"); DEBUG(std::cerr << ")\n");
const FunctionType *funcType = FunctionType::get(retTy, paramTy, false); const FunctionType *funcType = FunctionType::get(retTy, paramTy, false);