1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_COMPILER_XLA_SERVICE_CALL_INLINER_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_CALL_INLINER_H_ 18 19 #include <deque> 20 21 #include "absl/container/flat_hash_map.h" 22 #include "tensorflow/compiler/xla/service/hlo_pass_interface.h" 23 #include "tensorflow/compiler/xla/statusor.h" 24 25 namespace xla { 26 27 // For every kCall operation in the main computation, we inline the body of the 28 // called function, and proceed recursively. 29 class CallInliner : public HloModulePass { 30 public: 31 using InlinedInstructionMap = 32 absl::flat_hash_map<HloInstruction*, HloInstruction*>; 33 34 // Inlines one call instruction. Returns a mapping from the original 35 // instructions to their inlined versions. 36 static StatusOr<InlinedInstructionMap> Inline(HloInstruction* call); 37 38 // If single_call_site is true, only functions with a single call site will be 39 // inlined. 40 // If update_domain is true, the exit domains could be updated for calls which 41 // are being inlined if necessary. 42 explicit CallInliner(bool single_call_site = false, 43 bool update_domain = false) single_call_site_(single_call_site)44 : single_call_site_(single_call_site), update_domain_(update_domain) {} 45 ~CallInliner() override = default; name()46 absl::string_view name() const override { return "CallInliner"; } 47 48 using HloPassInterface::Run; 49 StatusOr<bool> Run( 50 HloModule* module, 51 const absl::flat_hash_set<absl::string_view>& execution_threads) override; 52 53 private: 54 bool single_call_site_; 55 bool update_domain_; 56 }; 57 58 } // namespace xla 59 60 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_CALL_INLINER_H_ 61