From: Craig Topper Date: Sat, 6 Jun 2015 01:33:55 +0000 (+0000) Subject: [TableGen] Remove unnecessary outer 'if' and merge it's conditions into the inner... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=c052f545590462f2992fd6f9b3002274397ef4e8 [TableGen] Remove unnecessary outer 'if' and merge it's conditions into the inner 'if's. NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239206 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp index bb9e95d68b8..d9405e18d5c 100644 --- a/lib/TableGen/Record.cpp +++ b/lib/TableGen/Record.cpp @@ -913,8 +913,6 @@ static Init *EvaluateOperation(OpInit *RHSo, Init *LHS, Init *Arg, static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type, Record *CurRec, MultiClass *CurMultiClass) { - DagInit *MHSd = dyn_cast(MHS); - ListInit *MHSl = dyn_cast(MHS); OpInit *RHSo = dyn_cast(RHS); @@ -926,53 +924,54 @@ static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type, if (!LHSt) PrintFatalError(CurRec->getLoc(), "!foreach requires typed variable\n"); - if ((MHSd && isa(Type)) || (MHSl && isa(Type))) { - if (MHSd) { - Init *Val = MHSd->getOperator(); - Init *Result = EvaluateOperation(RHSo, LHS, Val, - Type, CurRec, CurMultiClass); + DagInit *MHSd = dyn_cast(MHS); + if (MHSd && isa(Type)) { + Init *Val = MHSd->getOperator(); + Init *Result = EvaluateOperation(RHSo, LHS, Val, + Type, CurRec, CurMultiClass); + if (Result) + Val = Result; + + std::vector > args; + for (unsigned int i = 0; i < MHSd->getNumArgs(); ++i) { + Init *Arg = MHSd->getArg(i); + std::string ArgName = MHSd->getArgName(i); + + // Process args + Init *Result = EvaluateOperation(RHSo, LHS, Arg, Type, + CurRec, CurMultiClass); if (Result) - Val = Result; + Arg = Result; - std::vector > args; - for (unsigned int i = 0; i < MHSd->getNumArgs(); ++i) { - Init *Arg = MHSd->getArg(i); - std::string ArgName = MHSd->getArgName(i); + // TODO: Process arg names + args.push_back(std::make_pair(Arg, ArgName)); + } - // Process args - Init *Result = EvaluateOperation(RHSo, LHS, Arg, Type, - CurRec, CurMultiClass); - if (Result) - Arg = Result; + return DagInit::get(Val, "", args); + } - // TODO: Process arg names - args.push_back(std::make_pair(Arg, ArgName)); + ListInit *MHSl = dyn_cast(MHS); + if (MHSl && isa(Type)) { + std::vector NewOperands; + std::vector NewList(MHSl->begin(), MHSl->end()); + + for (Init *&Item : NewList) { + NewOperands.clear(); + for(int i = 0; i < RHSo->getNumOperands(); ++i) { + // First, replace the foreach variable with the list item + if (LHS->getAsString() == RHSo->getOperand(i)->getAsString()) + NewOperands.push_back(Item); + else + NewOperands.push_back(RHSo->getOperand(i)); } - return DagInit::get(Val, "", args); - } - if (MHSl) { - std::vector NewOperands; - std::vector NewList(MHSl->begin(), MHSl->end()); - - for (Init *&Item : NewList) { - NewOperands.clear(); - for(int i = 0; i < RHSo->getNumOperands(); ++i) { - // First, replace the foreach variable with the list item - if (LHS->getAsString() == RHSo->getOperand(i)->getAsString()) - NewOperands.push_back(Item); - else - NewOperands.push_back(RHSo->getOperand(i)); - } - - // Now run the operator and use its result as the new list item - const OpInit *NewOp = RHSo->clone(NewOperands); - Init *NewItem = NewOp->Fold(CurRec, CurMultiClass); - if (NewItem != NewOp) - Item = NewItem; - } - return ListInit::get(NewList, MHSl->getType()); + // Now run the operator and use its result as the new list item + const OpInit *NewOp = RHSo->clone(NewOperands); + Init *NewItem = NewOp->Fold(CurRec, CurMultiClass); + if (NewItem != NewOp) + Item = NewItem; } + return ListInit::get(NewList, MHSl->getType()); } return nullptr; }