1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 04:02:41 +01:00

SimplifyCFG: Clean up optforfuzzing implementation

This should function as any other SimplifyCFGOption rather than having
the transform check and specially consider the attribute itself.
This commit is contained in:
Matt Arsenault 2020-05-20 20:05:07 -04:00
parent 10f1beb37b
commit 198b0994f4
3 changed files with 33 additions and 11 deletions

View File

@ -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;
}
};
//===----------------------------------------------------------------------===//

View File

@ -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);
}

View File

@ -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);