diff options
author | Chris Lattner <sabre@nondot.org> | 2002-05-09 20:33:35 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-05-09 20:33:35 +0000 |
commit | 7683a12e2063c7226cc24a1f5cd6ce4ca99d140d (patch) | |
tree | b1ef1e8b663279338a7f282e4aa20474c66480bc /lib/Target/CBackend | |
parent | 1f02c8910a4d9388e69d909b203e537509bed7d2 (diff) | |
download | external_llvm-7683a12e2063c7226cc24a1f5cd6ce4ca99d140d.zip external_llvm-7683a12e2063c7226cc24a1f5cd6ce4ca99d140d.tar.gz external_llvm-7683a12e2063c7226cc24a1f5cd6ce4ca99d140d.tar.bz2 |
Simplify code by removing InstLocalVarsVisitor, replacing it with a simple
inst_iterator.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2584 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/CBackend')
-rw-r--r-- | lib/Target/CBackend/CBackend.cpp | 79 | ||||
-rw-r--r-- | lib/Target/CBackend/Writer.cpp | 79 |
2 files changed, 34 insertions, 124 deletions
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index 77aef46..a36f2ae 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -24,6 +24,7 @@ #include "llvm/iOperators.h" #include "llvm/SymbolTable.h" #include "llvm/Support/InstVisitor.h" +#include "llvm/Support/InstIterator.h" #include "Support/StringExtras.h" #include "Support/STLExtras.h" @@ -40,12 +41,10 @@ using std::ostream; // Appends a variable to the LocalVars map if it does not already exist // Also check that the type exists on the map. -void CLocalVars::addLocalVar(const Type *t, const string & var) { +void CLocalVars::addLocalVar(const Type *t, const string &V) { if (!LocalVars.count(t) || - find(LocalVars[t].begin(), LocalVars[t].end(), var) - == LocalVars[t].end()) { - LocalVars[t].push_back(var); - } + find(LocalVars[t].begin(), LocalVars[t].end(), V) == LocalVars[t].end()) + LocalVars[t].push_back(V); } static std::string getConstStrValue(const Constant* CPV); @@ -101,7 +100,6 @@ static std::string getConstArrayStrValue(const Constant* CPV) { } } Result += "\""; - } else { Result = "{"; if (CPV->getNumOperands()) { @@ -193,10 +191,9 @@ static string calcTypeNameVar(const Type *Ty, string Result; switch (Ty->getPrimitiveID()) { case Type::FunctionTyID: { - const FunctionType *MTy = cast<const FunctionType>(Ty); + const FunctionType *MTy = cast<FunctionType>(Ty); Result += calcTypeNameVar(MTy->getReturnType(), TypeNames, ""); - Result += " " + NameSoFar; - Result += " ("; + Result += " " + NameSoFar + " ("; for (FunctionType::ParamTypes::const_iterator I = MTy->getParamTypes().begin(), E = MTy->getParamTypes().end(); I != E; ++I) { @@ -282,45 +279,6 @@ namespace { void printFunction(Function *); }; /* END class CWriter */ - - - /* CLASS InstLocalVarsVisitor */ - class InstLocalVarsVisitor : public InstVisitor<InstLocalVarsVisitor> { - CWriter& CW; - void handleTerminator(TerminatorInst *tI, int indx); - public: - CLocalVars CLV; - - InstLocalVarsVisitor(CWriter &cw) : CW(cw) {} - - void visitInstruction(Instruction *I) { - if (I->getType() != Type::VoidTy) - CLV.addLocalVar(I->getType(), CW.getValueName(I)); - } - - void visitBranchInst(BranchInst *I) { - handleTerminator(I, 0); - if (I->isConditional()) - handleTerminator(I, 1); - } - }; -} - -void InstLocalVarsVisitor::handleTerminator(TerminatorInst *tI,int indx) { - BasicBlock *bb = tI->getSuccessor(indx); - - BasicBlock::const_iterator insIt = bb->begin(); - while (insIt != bb->end()) { - if (const PHINode *pI = dyn_cast<PHINode>(*insIt)) { - // Its a phinode! - // Calculate the incoming index for this - assert(pI->getBasicBlockIndex(tI->getParent()) != -1); - - CLV.addLocalVar(pI->getType(), CW.getValueName(pI)); - } else - break; - insIt++; - } } namespace { @@ -792,23 +750,20 @@ void CWriter::printFunction(Function *F) { // output methods on the CLocalVars and Function* objects. // gather local variable information for each basic block - InstLocalVarsVisitor ILV(*this); - ILV.visit(F); - - // print the local variables - // we assume that every local variable is alloca'ed in the C code. - std::map<const Type*, VarListType> &locals = ILV.CLV.LocalVars; - - map<const Type*, VarListType>::iterator iter; - for (iter = locals.begin(); iter != locals.end(); ++iter) { - VarListType::iterator listiter; - for (listiter = iter->second.begin(); listiter != iter->second.end(); - ++listiter) { + CLocalVars CLV; + for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) + if ((*I)->getType() != Type::VoidTy) + CLV.addLocalVar((*I)->getType(), getValueName(*I)); + + // print the local variables + for (map<const Type*, VarListType>::iterator I = CLV.LocalVars.begin(), + E = CLV.LocalVars.end(); I != E; ++I) + for (VarListType::iterator TI = I->second.begin(), E = I->second.end(); + TI != E; ++TI) { Out << " "; - printTypeVar(iter->first, *listiter); + printTypeVar(I->first, *TI); Out << ";\n"; } - } // print the basic blocks for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) { diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp index 77aef46..a36f2ae 100644 --- a/lib/Target/CBackend/Writer.cpp +++ b/lib/Target/CBackend/Writer.cpp @@ -24,6 +24,7 @@ #include "llvm/iOperators.h" #include "llvm/SymbolTable.h" #include "llvm/Support/InstVisitor.h" +#include "llvm/Support/InstIterator.h" #include "Support/StringExtras.h" #include "Support/STLExtras.h" @@ -40,12 +41,10 @@ using std::ostream; // Appends a variable to the LocalVars map if it does not already exist // Also check that the type exists on the map. -void CLocalVars::addLocalVar(const Type *t, const string & var) { +void CLocalVars::addLocalVar(const Type *t, const string &V) { if (!LocalVars.count(t) || - find(LocalVars[t].begin(), LocalVars[t].end(), var) - == LocalVars[t].end()) { - LocalVars[t].push_back(var); - } + find(LocalVars[t].begin(), LocalVars[t].end(), V) == LocalVars[t].end()) + LocalVars[t].push_back(V); } static std::string getConstStrValue(const Constant* CPV); @@ -101,7 +100,6 @@ static std::string getConstArrayStrValue(const Constant* CPV) { } } Result += "\""; - } else { Result = "{"; if (CPV->getNumOperands()) { @@ -193,10 +191,9 @@ static string calcTypeNameVar(const Type *Ty, string Result; switch (Ty->getPrimitiveID()) { case Type::FunctionTyID: { - const FunctionType *MTy = cast<const FunctionType>(Ty); + const FunctionType *MTy = cast<FunctionType>(Ty); Result += calcTypeNameVar(MTy->getReturnType(), TypeNames, ""); - Result += " " + NameSoFar; - Result += " ("; + Result += " " + NameSoFar + " ("; for (FunctionType::ParamTypes::const_iterator I = MTy->getParamTypes().begin(), E = MTy->getParamTypes().end(); I != E; ++I) { @@ -282,45 +279,6 @@ namespace { void printFunction(Function *); }; /* END class CWriter */ - - - /* CLASS InstLocalVarsVisitor */ - class InstLocalVarsVisitor : public InstVisitor<InstLocalVarsVisitor> { - CWriter& CW; - void handleTerminator(TerminatorInst *tI, int indx); - public: - CLocalVars CLV; - - InstLocalVarsVisitor(CWriter &cw) : CW(cw) {} - - void visitInstruction(Instruction *I) { - if (I->getType() != Type::VoidTy) - CLV.addLocalVar(I->getType(), CW.getValueName(I)); - } - - void visitBranchInst(BranchInst *I) { - handleTerminator(I, 0); - if (I->isConditional()) - handleTerminator(I, 1); - } - }; -} - -void InstLocalVarsVisitor::handleTerminator(TerminatorInst *tI,int indx) { - BasicBlock *bb = tI->getSuccessor(indx); - - BasicBlock::const_iterator insIt = bb->begin(); - while (insIt != bb->end()) { - if (const PHINode *pI = dyn_cast<PHINode>(*insIt)) { - // Its a phinode! - // Calculate the incoming index for this - assert(pI->getBasicBlockIndex(tI->getParent()) != -1); - - CLV.addLocalVar(pI->getType(), CW.getValueName(pI)); - } else - break; - insIt++; - } } namespace { @@ -792,23 +750,20 @@ void CWriter::printFunction(Function *F) { // output methods on the CLocalVars and Function* objects. // gather local variable information for each basic block - InstLocalVarsVisitor ILV(*this); - ILV.visit(F); - - // print the local variables - // we assume that every local variable is alloca'ed in the C code. - std::map<const Type*, VarListType> &locals = ILV.CLV.LocalVars; - - map<const Type*, VarListType>::iterator iter; - for (iter = locals.begin(); iter != locals.end(); ++iter) { - VarListType::iterator listiter; - for (listiter = iter->second.begin(); listiter != iter->second.end(); - ++listiter) { + CLocalVars CLV; + for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) + if ((*I)->getType() != Type::VoidTy) + CLV.addLocalVar((*I)->getType(), getValueName(*I)); + + // print the local variables + for (map<const Type*, VarListType>::iterator I = CLV.LocalVars.begin(), + E = CLV.LocalVars.end(); I != E; ++I) + for (VarListType::iterator TI = I->second.begin(), E = I->second.end(); + TI != E; ++TI) { Out << " "; - printTypeVar(iter->first, *listiter); + printTypeVar(I->first, *TI); Out << ";\n"; } - } // print the basic blocks for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) { |