@@ -16,6 +16,8 @@ limitations under the License.
1616#ifndef XLA_SERVICE_CALL_INLINER_H_
1717#define XLA_SERVICE_CALL_INLINER_H_
1818
19+ #include < functional>
20+ #include < optional>
1921#include < string>
2022#include < utility>
2123
@@ -48,14 +50,19 @@ class CallInliner : public HloModulePass {
4850 // are being inlined if necessary.
4951 // If `uniquify_channel_ids` is true, the channel ids of the resulting
5052 // computation will be uniquified.
53+ // If the callback `should_inline` is provided, only functions callsite for
54+ // which it retuns true will be inlined.
5155 explicit CallInliner (
5256 bool single_call_site = false , bool update_domain = false ,
5357 absl::flat_hash_set<std::string> composites_to_preserve = {},
54- bool uniquify_channel_ids = false )
58+ bool uniquify_channel_ids = false ,
59+ std::optional<std::function<bool (const CallGraph&, HloInstruction*)>>
60+ should_inline = std::nullopt)
5561 : single_call_site_(single_call_site),
5662 update_domain_(update_domain),
5763 uniquify_channel_ids_(uniquify_channel_ids),
58- composites_to_preserve_(std::move(composites_to_preserve)) {}
64+ composites_to_preserve_(std::move(composites_to_preserve)),
65+ should_inline_(std::move(should_inline)) {}
5966 ~CallInliner () override = default ;
6067 absl::string_view name () const override { return " call-inliner" ; }
6168
@@ -73,10 +80,16 @@ class CallInliner : public HloModulePass {
7380 const CallGraph& call_graph, HloComputation* computation,
7481 absl::Span<HloInstruction* const > instruction_sequence) const ;
7582
83+ bool ShouldInline (const CallGraph& call_graph,
84+ HloInstruction* instruction) const ;
85+
7686 bool single_call_site_;
7787 bool update_domain_;
7888 bool uniquify_channel_ids_;
7989 absl::flat_hash_set<std::string> composites_to_preserve_;
90+ std::optional<
91+ std::function<bool (const CallGraph& call_graph, HloInstruction*)>>
92+ should_inline_;
8093};
8194
8295} // namespace xla
0 commit comments