diff options
author | Amir Ayupov <aaupov@fb.com> | 2022-09-09 01:50:25 +0300 |
---|---|---|
committer | Amir Ayupov <aaupov@fb.com> | 2022-09-09 01:50:40 +0300 |
commit | 31abde43d624aebaee90ac65ed7ca8cecf438e22 (patch) | |
tree | 7e53ececbde767db05d95b3601d17be7a3158b73 /bolt | |
parent | 873942e1783f09b407f8081264036458f7c17db3 (diff) |
[BOLT] Restrict ICP for functions with unknown control flow
ICP has two modes: jump table promotion and indirect call promotion.
The selection is based on whether an instruction has a jump table or not.
An instruction with unknown control flow doesn't have a jump table and will
fall under indirect call promotion policy which might be incorrect/unsafe
(if an instruction is not a tail call, i.e. has local jump targets).
Prevent ICP for functions containing instructions with unknown control flow.
Follow-up to https://reviews.llvm.org/D128870.
Reviewed By: maksfb
Differential Revision: https://reviews.llvm.org/D132882
Diffstat (limited to 'bolt')
-rw-r--r-- | bolt/include/bolt/Passes/IndirectCallPromotion.h | 4 | ||||
-rw-r--r-- | bolt/lib/Passes/IndirectCallPromotion.cpp | 5 |
2 files changed, 6 insertions, 3 deletions
diff --git a/bolt/include/bolt/Passes/IndirectCallPromotion.h b/bolt/include/bolt/Passes/IndirectCallPromotion.h index 9c1a41c1e609..397a38663948 100644 --- a/bolt/include/bolt/Passes/IndirectCallPromotion.h +++ b/bolt/include/bolt/Passes/IndirectCallPromotion.h @@ -217,6 +217,10 @@ public: bool shouldPrint(const BinaryFunction &BF) const override { return BinaryFunctionPass::shouldPrint(BF) && Modified.count(&BF) > 0; } + bool shouldOptimize(const BinaryFunction &BF) const override { + return BF.isSimple() && !BF.isIgnored() && BF.hasProfile() && + !BF.hasUnknownControlFlow(); + } void runOnFunctions(BinaryContext &BC) override; }; diff --git a/bolt/lib/Passes/IndirectCallPromotion.cpp b/bolt/lib/Passes/IndirectCallPromotion.cpp index b6b30e7a76d9..e4b577a147ac 100644 --- a/bolt/lib/Passes/IndirectCallPromotion.cpp +++ b/bolt/lib/Passes/IndirectCallPromotion.cpp @@ -1158,8 +1158,7 @@ void IndirectCallPromotion::runOnFunctions(BinaryContext &BC) { for (auto &BFIt : BFs) { BinaryFunction &Function = BFIt.second; - if (!Function.isSimple() || Function.isIgnored() || - !Function.hasProfile()) + if (!shouldOptimize(Function)) continue; const bool HasLayout = !Function.getLayout().block_empty(); @@ -1219,7 +1218,7 @@ void IndirectCallPromotion::runOnFunctions(BinaryContext &BC) { for (BinaryFunction *FuncPtr : Functions) { BinaryFunction &Function = *FuncPtr; - if (!Function.isSimple() || Function.isIgnored() || !Function.hasProfile()) + if (!shouldOptimize(Function)) continue; const bool HasLayout = !Function.getLayout().block_empty(); |