diff options
Diffstat (limited to 'llvm/lib/Transforms/Scalar')
-rw-r--r-- | llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp | 66 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/GVN.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/NewGVN.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp | 2 |
4 files changed, 35 insertions, 35 deletions
diff --git a/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp b/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp index ae34b4e..3f7003d 100644 --- a/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp @@ -61,6 +61,7 @@ #include "llvm/ADT/APInt.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/Statistic.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Analysis/AssumptionCache.h" #include "llvm/Analysis/CodeMetrics.h" #include "llvm/Analysis/DomTreeUpdater.h" @@ -120,6 +121,9 @@ static cl::opt<unsigned> CostThreshold("dfa-cost-threshold", cl::desc("Maximum cost accepted for the transformation"), cl::Hidden, cl::init(50)); + +extern cl::opt<bool> ProfcheckDisableMetadataFixes; + } // namespace llvm static cl::opt<double> MaxClonedRate( @@ -260,7 +264,11 @@ void DFAJumpThreading::unfold(DomTreeUpdater *DTU, LoopInfo *LI, // Insert the real conditional branch based on the original condition. StartBlockTerm->eraseFromParent(); - BranchInst::Create(EndBlock, NewBlock, SI->getCondition(), StartBlock); + auto *BI = + BranchInst::Create(EndBlock, NewBlock, SI->getCondition(), StartBlock); + if (!ProfcheckDisableMetadataFixes) + BI->setMetadata(LLVMContext::MD_prof, + SI->getMetadata(LLVMContext::MD_prof)); DTU->applyUpdates({{DominatorTree::Insert, StartBlock, EndBlock}, {DominatorTree::Insert, StartBlock, NewBlock}}); } else { @@ -295,7 +303,11 @@ void DFAJumpThreading::unfold(DomTreeUpdater *DTU, LoopInfo *LI, // (Use) BranchInst::Create(EndBlock, NewBlockF); // Insert the real conditional branch based on the original condition. - BranchInst::Create(EndBlock, NewBlockF, SI->getCondition(), NewBlockT); + auto *BI = + BranchInst::Create(EndBlock, NewBlockF, SI->getCondition(), NewBlockT); + if (!ProfcheckDisableMetadataFixes) + BI->setMetadata(LLVMContext::MD_prof, + SI->getMetadata(LLVMContext::MD_prof)); DTU->applyUpdates({{DominatorTree::Insert, NewBlockT, NewBlockF}, {DominatorTree::Insert, NewBlockT, EndBlock}, {DominatorTree::Insert, NewBlockF, EndBlock}}); @@ -371,16 +383,9 @@ typedef DenseMap<BasicBlock *, CloneList> DuplicateBlockMap; typedef MapVector<Instruction *, std::vector<Instruction *>> DefMap; inline raw_ostream &operator<<(raw_ostream &OS, const PathType &Path) { - OS << "< "; - for (const BasicBlock *BB : Path) { - std::string BBName; - if (BB->hasName()) - raw_string_ostream(BBName) << BB->getName(); - else - raw_string_ostream(BBName) << BB; - OS << BBName << " "; - } - OS << ">"; + auto BBNames = llvm::map_range( + Path, [](const BasicBlock *BB) { return BB->getNameOrAsOperand(); }); + OS << "< " << llvm::join(BBNames, ", ") << " >"; return OS; } @@ -412,7 +417,7 @@ struct ThreadingPath { } void print(raw_ostream &OS) const { - OS << Path << " [ " << ExitVal << ", " << DBB->getName() << " ]"; + OS << Path << " [ " << ExitVal << ", " << DBB->getNameOrAsOperand() << " ]"; } private: @@ -1195,19 +1200,18 @@ private: // value for the new predecessor ClonedBB. The value will either be the same // value from BB or a cloned value. for (BasicBlock *Succ : BlocksToUpdate) { - for (auto II = Succ->begin(); PHINode *Phi = dyn_cast<PHINode>(II); - ++II) { - Value *Incoming = Phi->getIncomingValueForBlock(BB); + for (PHINode &Phi : Succ->phis()) { + Value *Incoming = Phi.getIncomingValueForBlock(BB); if (Incoming) { if (isa<Constant>(Incoming)) { - Phi->addIncoming(Incoming, ClonedBB); + Phi.addIncoming(Incoming, ClonedBB); continue; } Value *ClonedVal = VMap[Incoming]; if (ClonedVal) - Phi->addIncoming(ClonedVal, ClonedBB); + Phi.addIncoming(ClonedVal, ClonedBB); else - Phi->addIncoming(Incoming, ClonedBB); + Phi.addIncoming(Incoming, ClonedBB); } } } @@ -1302,27 +1306,19 @@ private: void cleanPhiNodes(BasicBlock *BB) { // If BB is no longer reachable, remove any remaining phi nodes if (pred_empty(BB)) { - std::vector<PHINode *> PhiToRemove; - for (auto II = BB->begin(); PHINode *Phi = dyn_cast<PHINode>(II); ++II) { - PhiToRemove.push_back(Phi); - } - for (PHINode *PN : PhiToRemove) { - PN->replaceAllUsesWith(PoisonValue::get(PN->getType())); - PN->eraseFromParent(); + for (PHINode &PN : make_early_inc_range(BB->phis())) { + PN.replaceAllUsesWith(PoisonValue::get(PN.getType())); + PN.eraseFromParent(); } return; } // Remove any incoming values that come from an invalid predecessor - for (auto II = BB->begin(); PHINode *Phi = dyn_cast<PHINode>(II); ++II) { - std::vector<BasicBlock *> BlocksToRemove; - for (BasicBlock *IncomingBB : Phi->blocks()) { - if (!isPredecessor(BB, IncomingBB)) - BlocksToRemove.push_back(IncomingBB); - } - for (BasicBlock *BB : BlocksToRemove) - Phi->removeIncomingValue(BB); - } + for (PHINode &Phi : BB->phis()) + Phi.removeIncomingValueIf([&](unsigned Index) { + BasicBlock *IncomingBB = Phi.getIncomingBlock(Index); + return !isPredecessor(BB, IncomingBB); + }); } /// Checks if BB was already cloned for a particular next state value. If it diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp index b9b5b58..638952a 100644 --- a/llvm/lib/Transforms/Scalar/GVN.cpp +++ b/llvm/lib/Transforms/Scalar/GVN.cpp @@ -699,6 +699,7 @@ uint32_t GVNPass::ValueTable::lookupOrAdd(Value *V) { case Instruction::FPTrunc: case Instruction::FPExt: case Instruction::PtrToInt: + case Instruction::PtrToAddr: case Instruction::IntToPtr: case Instruction::AddrSpaceCast: case Instruction::BitCast: diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp index d6b7633..3c1a8ba 100644 --- a/llvm/lib/Transforms/Scalar/NewGVN.cpp +++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp @@ -2066,6 +2066,7 @@ NewGVN::performSymbolicEvaluation(Instruction *I, case Instruction::FPTrunc: case Instruction::FPExt: case Instruction::PtrToInt: + case Instruction::PtrToAddr: case Instruction::IntToPtr: case Instruction::Select: case Instruction::ExtractElement: diff --git a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp index 60e5df0..7ffccf7 100644 --- a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp +++ b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp @@ -355,6 +355,8 @@ void SimplifyCFGPass::printPipeline( OS << (Options.ForwardSwitchCondToPhi ? "" : "no-") << "forward-switch-cond;"; OS << (Options.ConvertSwitchRangeToICmp ? "" : "no-") << "switch-range-to-icmp;"; + OS << (Options.ConvertSwitchToArithmetic ? "" : "no-") + << "switch-to-arithmetic;"; OS << (Options.ConvertSwitchToLookupTable ? "" : "no-") << "switch-to-lookup;"; OS << (Options.NeedCanonicalLoop ? "" : "no-") << "keep-loops;"; |