diff options
author | Chris Lattner <sabre@nondot.org> | 2002-06-25 16:13:21 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-06-25 16:13:21 +0000 |
commit | 0b12b5f50ec77a8bd01b92d287c52d748619bb4b (patch) | |
tree | 5764db59facb124b023f1de96f0e45d37657c82e /lib/CodeGen | |
parent | 18961504fc2b299578dba817900a0696cf3ccc4d (diff) |
MEGAPATCH checkin.
For details, See: docs/2002-06-25-MegaPatchInfo.txt
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2778 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/InstrSelection/InstrForest.cpp | 8 | ||||
-rw-r--r-- | lib/CodeGen/InstrSelection/InstrSelection.cpp | 79 | ||||
-rw-r--r-- | lib/CodeGen/MachineFunction.cpp | 76 |
3 files changed, 71 insertions, 92 deletions
diff --git a/lib/CodeGen/InstrSelection/InstrForest.cpp b/lib/CodeGen/InstrSelection/InstrForest.cpp index 4a08c24704..a95f1e377a 100644 --- a/lib/CodeGen/InstrSelection/InstrForest.cpp +++ b/lib/CodeGen/InstrSelection/InstrForest.cpp @@ -25,7 +25,6 @@ #include "llvm/iTerminators.h" #include "llvm/iMemory.h" #include "llvm/Constant.h" -#include "llvm/BasicBlock.h" #include "llvm/Type.h" #include "llvm/CodeGen/MachineInstr.h" #include "Support/STLExtras.h" @@ -188,10 +187,9 @@ LabelNode::dumpNode(int indent) const InstrForest::InstrForest(Function *F) { - for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI) { - BasicBlock *BB = *FI; - for_each(BB->begin(), BB->end(), - bind_obj(this, &InstrForest::buildTreeForInstruction)); + for (Function::iterator BB = F->begin(), FE = F->end(); BB != FE; ++BB) { + for(BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) + buildTreeForInstruction(I); } } diff --git a/lib/CodeGen/InstrSelection/InstrSelection.cpp b/lib/CodeGen/InstrSelection/InstrSelection.cpp index 614c5f6773..b27f9022bb 100644 --- a/lib/CodeGen/InstrSelection/InstrSelection.cpp +++ b/lib/CodeGen/InstrSelection/InstrSelection.cpp @@ -123,14 +123,10 @@ SelectInstructionsForMethod(Function *F, TargetMachine &target) // Record instructions in the vector for each basic block // for (Function::iterator BI = F->begin(), BE = F->end(); BI != BE; ++BI) - { - MachineCodeForBasicBlock& bbMvec = (*BI)->getMachineInstrVec(); - for (BasicBlock::iterator II = (*BI)->begin(); II != (*BI)->end(); ++II) - { - MachineCodeForInstruction &mvec =MachineCodeForInstruction::get(*II); - for (unsigned i=0; i < mvec.size(); i++) - bbMvec.push_back(mvec[i]); - } + for (BasicBlock::iterator II = BI->begin(); II != BI->end(); ++II) { + MachineCodeForInstruction &mvec =MachineCodeForInstruction::get(II); + for (unsigned i=0; i < mvec.size(); i++) + BI->getMachineInstrVec().push_back(mvec[i]); } // Insert phi elimination code -- added by Ruchira @@ -191,49 +187,38 @@ InsertCode4AllPhisInMeth(Function *F, TargetMachine &target) { // for all basic blocks in function // - for (Function::iterator BI = F->begin(); BI != F->end(); ++BI) { - - BasicBlock *BB = *BI; - const BasicBlock::InstListType &InstList = BB->getInstList(); - BasicBlock::InstListType::const_iterator IIt = InstList.begin(); - - // for all instructions in the basic block - // - for( ; IIt != InstList.end(); ++IIt ) { - - if (PHINode *PN = dyn_cast<PHINode>(*IIt)) { - // FIXME: This is probably wrong... - Value *PhiCpRes = new PHINode(PN->getType(), "PhiCp:"); - - // for each incoming value of the phi, insert phi elimination - // - for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i) - { // insert the copy instruction to the predecessor BB - vector<MachineInstr*> mvec, CpVec; - target.getRegInfo().cpValue2Value(PN->getIncomingValue(i), PhiCpRes, - mvec); - for (vector<MachineInstr*>::iterator MI=mvec.begin(); - MI != mvec.end(); ++MI) - { - vector<MachineInstr*> CpVec2 = - FixConstantOperandsForInstr(PN, *MI, target); - CpVec2.push_back(*MI); - CpVec.insert(CpVec.end(), CpVec2.begin(), CpVec2.end()); - } - - InsertPhiElimInstructions(PN->getIncomingBlock(i), CpVec); - } + for (Function::iterator BB = F->begin(); BB != F->end(); ++BB) { + BasicBlock::InstListType &InstList = BB->getInstList(); + for (BasicBlock::iterator IIt = InstList.begin(); + PHINode *PN = dyn_cast<PHINode>(&*IIt); ++IIt) { + // FIXME: This is probably wrong... + Value *PhiCpRes = new PHINode(PN->getType(), "PhiCp:"); - vector<MachineInstr*> mvec; - target.getRegInfo().cpValue2Value(PhiCpRes, PN, mvec); + // for each incoming value of the phi, insert phi elimination + // + for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i) { + // insert the copy instruction to the predecessor BB + vector<MachineInstr*> mvec, CpVec; + target.getRegInfo().cpValue2Value(PN->getIncomingValue(i), PhiCpRes, + mvec); + for (vector<MachineInstr*>::iterator MI=mvec.begin(); + MI != mvec.end(); ++MI) { + vector<MachineInstr*> CpVec2 = + FixConstantOperandsForInstr(PN, *MI, target); + CpVec2.push_back(*MI); + CpVec.insert(CpVec.end(), CpVec2.begin(), CpVec2.end()); + } - // get an iterator to machine instructions in the BB - MachineCodeForBasicBlock& bbMvec = BB->getMachineInstrVec(); - - bbMvec.insert( bbMvec.begin(), mvec.begin(), mvec.end()); + InsertPhiElimInstructions(PN->getIncomingBlock(i), CpVec); } - else break; // since PHI nodes can only be at the top + vector<MachineInstr*> mvec; + target.getRegInfo().cpValue2Value(PhiCpRes, PN, mvec); + + // get an iterator to machine instructions in the BB + MachineCodeForBasicBlock& bbMvec = BB->getMachineInstrVec(); + + bbMvec.insert(bbMvec.begin(), mvec.begin(), mvec.end()); } // for each Phi Instr in BB } // for all BBs in function } diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index 06e0666ec8..4d50f89729 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -60,43 +60,40 @@ ComputeMaxOptionalArgsSize(const TargetMachine& target, const Function *F, { const MachineFrameInfo& frameInfo = target.getFrameInfo(); - unsigned int maxSize = 0; + unsigned maxSize = 0; - for (Function::const_iterator MI = F->begin(), ME = F->end(); MI != ME; ++MI) - { - const BasicBlock *BB = *MI; - for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) - if (CallInst *callInst = dyn_cast<CallInst>(*I)) - { - unsigned int numOperands = callInst->getNumOperands() - 1; - int numExtra =(int)numOperands-frameInfo.getNumFixedOutgoingArgs(); - if (numExtra <= 0) - continue; - - unsigned int sizeForThisCall; - if (frameInfo.argsOnStackHaveFixedSize()) - { - int argSize = frameInfo.getSizeOfEachArgOnStack(); - sizeForThisCall = numExtra * (unsigned) argSize; - } - else - { - assert(0 && "UNTESTED CODE: Size per stack argument is not " - "fixed on this architecture: use actual arg sizes to " - "compute MaxOptionalArgsSize"); - sizeForThisCall = 0; - for (unsigned i=0; i < numOperands; ++i) - sizeForThisCall += target.findOptimalStorageSize(callInst-> - getOperand(i)->getType()); - } - - if (maxSize < sizeForThisCall) - maxSize = sizeForThisCall; - - if (((int) maxOptionalNumArgs) < numExtra) - maxOptionalNumArgs = (unsigned) numExtra; - } - } + for (Function::const_iterator BB = F->begin(), BBE = F->end(); BB !=BBE; ++BB) + for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) + if (const CallInst *callInst = dyn_cast<CallInst>(&*I)) + { + unsigned numOperands = callInst->getNumOperands() - 1; + int numExtra = (int)numOperands-frameInfo.getNumFixedOutgoingArgs(); + if (numExtra <= 0) + continue; + + unsigned int sizeForThisCall; + if (frameInfo.argsOnStackHaveFixedSize()) + { + int argSize = frameInfo.getSizeOfEachArgOnStack(); + sizeForThisCall = numExtra * (unsigned) argSize; + } + else + { + assert(0 && "UNTESTED CODE: Size per stack argument is not " + "fixed on this architecture: use actual arg sizes to " + "compute MaxOptionalArgsSize"); + sizeForThisCall = 0; + for (unsigned i = 0; i < numOperands; ++i) + sizeForThisCall += target.findOptimalStorageSize(callInst-> + getOperand(i)->getType()); + } + + if (maxSize < sizeForThisCall) + maxSize = sizeForThisCall; + + if ((int)maxOptionalNumArgs < numExtra) + maxOptionalNumArgs = (unsigned) numExtra; + } return maxSize; } @@ -278,12 +275,11 @@ MachineCodeForMethod::dump() const std::cerr << "\n" << method->getReturnType() << " \"" << method->getName() << "\"\n"; - for (Function::const_iterator BI = method->begin(); BI != method->end(); ++BI) + for (Function::const_iterator BB = method->begin(); BB != method->end(); ++BB) { - BasicBlock* bb = *BI; - std::cerr << "\n" << bb->getName() << " (" << bb << ")" << ":\n"; + std::cerr << "\n" << BB->getName() << " (" << *BB << ")" << ":\n"; - MachineCodeForBasicBlock& mvec = bb->getMachineInstrVec(); + MachineCodeForBasicBlock& mvec = BB->getMachineInstrVec(); for (unsigned i=0; i < mvec.size(); i++) std::cerr << "\t" << *mvec[i]; } |