diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2020-05-20 20:05:07 -0400 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2020-05-23 13:49:50 -0400 |
commit | cdd006eec9409923f9a56b9026ce2cb72e7b71dc (patch) | |
tree | 98205d8adba2d46c0e4b36ad4440b5dd5e4f20e6 | |
parent | 27fe841aa650a24fd98da2fb6c6eb2fca806a63f (diff) | |
download | llvm-cdd006eec9409923f9a56b9026ce2cb72e7b71dc.zip llvm-cdd006eec9409923f9a56b9026ce2cb72e7b71dc.tar.gz llvm-cdd006eec9409923f9a56b9026ce2cb72e7b71dc.tar.bz2 |
SimplifyCFG: Clean up optforfuzzing implementation
This should function as any other SimplifyCFGOption rather than having
the transform check and specially consider the attribute itself.
-rw-r--r-- | llvm/include/llvm/Transforms/Utils/Local.h | 18 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp | 8 | ||||
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 18 |
3 files changed, 33 insertions, 11 deletions
diff --git a/llvm/include/llvm/Transforms/Utils/Local.h b/llvm/include/llvm/Transforms/Utils/Local.h index 615f1c7..5c24870 100644 --- a/llvm/include/llvm/Transforms/Utils/Local.h +++ b/llvm/include/llvm/Transforms/Utils/Local.h @@ -66,18 +66,25 @@ struct SimplifyCFGOptions { bool ConvertSwitchToLookupTable; bool NeedCanonicalLoop; bool SinkCommonInsts; + bool SimplifyCondBranch; + bool FoldTwoEntryPHINode; + AssumptionCache *AC; SimplifyCFGOptions(unsigned BonusThreshold = 1, bool ForwardSwitchCond = false, bool SwitchToLookup = false, bool CanonicalLoops = true, bool SinkCommon = false, - AssumptionCache *AssumpCache = nullptr) + AssumptionCache *AssumpCache = nullptr, + bool SimplifyCondBranch = true, + bool FoldTwoEntryPHINode = true) : BonusInstThreshold(BonusThreshold), ForwardSwitchCondToPhi(ForwardSwitchCond), ConvertSwitchToLookupTable(SwitchToLookup), NeedCanonicalLoop(CanonicalLoops), SinkCommonInsts(SinkCommon), + SimplifyCondBranch(SimplifyCondBranch), + FoldTwoEntryPHINode(FoldTwoEntryPHINode), AC(AssumpCache) {} // Support 'builder' pattern to set members by name at construction time. @@ -105,6 +112,15 @@ struct SimplifyCFGOptions { AC = Cache; return *this; } + SimplifyCFGOptions &setSimplifyCondBranch(bool B) { + SimplifyCondBranch = B; + return *this; + } + + SimplifyCFGOptions &setFoldTwoEntryPHINode(bool B) { + FoldTwoEntryPHINode = B; + return *this; + } }; //===----------------------------------------------------------------------===// diff --git a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp index ac53ff3..2e459c9 100644 --- a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp +++ b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp @@ -281,6 +281,14 @@ struct CFGSimplifyPass : public FunctionPass { return false; Options.AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F); + if (F.hasFnAttribute(Attribute::OptForFuzzing)) { + Options.setSimplifyCondBranch(false) + .setFoldTwoEntryPHINode(false); + } else { + Options.setSimplifyCondBranch(true) + .setFoldTwoEntryPHINode(true); + } + auto &TTI = getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F); return simplifyFunctionCFG(F, TTI, Options); } diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 5bccb7d..9afc18e 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -2336,9 +2336,6 @@ static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI, // dependence information for this check, but simplifycfg can't keep it up // to date, and this catches most of the cases we care about anyway. BasicBlock *BB = PN->getParent(); - const Function *Fn = BB->getParent(); - if (Fn && Fn->hasFnAttribute(Attribute::OptForFuzzing)) - return false; BasicBlock *IfTrue, *IfFalse; Value *IfCond = GetIfCondition(BB, IfTrue, IfFalse); @@ -5969,8 +5966,7 @@ static BasicBlock *allPredecessorsComeFromSameSource(BasicBlock *BB) { bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) { BasicBlock *BB = BI->getParent(); - const Function *Fn = BB->getParent(); - if (Fn && Fn->hasFnAttribute(Attribute::OptForFuzzing)) + if (!Options.SimplifyCondBranch) return false; // Conditional branch @@ -6184,11 +6180,13 @@ bool SimplifyCFGOpt::simplifyOnce(BasicBlock *BB) { IRBuilder<> Builder(BB); - // If there is a trivial two-entry PHI node in this basic block, and we can - // eliminate it, do so now. - if (auto *PN = dyn_cast<PHINode>(BB->begin())) - if (PN->getNumIncomingValues() == 2) - Changed |= FoldTwoEntryPHINode(PN, TTI, DL); + if (Options.FoldTwoEntryPHINode) { + // If there is a trivial two-entry PHI node in this basic block, and we can + // eliminate it, do so now. + if (auto *PN = dyn_cast<PHINode>(BB->begin())) + if (PN->getNumIncomingValues() == 2) + Changed |= FoldTwoEntryPHINode(PN, TTI, DL); + } Instruction *Terminator = BB->getTerminator(); Builder.SetInsertPoint(Terminator); |