1 /* Copyright 2019 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_WHILE_LOOP_TRIP_COUNT_ANNOTATOR_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_WHILE_LOOP_TRIP_COUNT_ANNOTATOR_H_ 18 19 #include "tensorflow/compiler/xla/service/hlo_module.h" 20 #include "tensorflow/compiler/xla/service/hlo_pass_interface.h" 21 #include "tensorflow/compiler/xla/statusor.h" 22 23 namespace xla { 24 25 // Pass that annotates `while` loops with known trip counts. 26 // 27 // The annotation is stored as a backend-config on the while loop node. 28 // 29 // This pass should run after all passes that might semantically modify a while 30 // loop, e.g. by unrolling it. Otherwise, a loop could end up with a 31 // backend-config that doesn't match its true trip-count. 32 // 33 // This pass does some pattern-matching on loop bodies and conditions, so it 34 // should run after most HLO simplifications and before fusion and layout 35 // assignment, which make pattern matching much more difficult by e.g. 36 // introducing `copy` nodes. 37 class WhileLoopTripCountAnnotator : public HloModulePass { 38 public: ~WhileLoopTripCountAnnotator()39 ~WhileLoopTripCountAnnotator() override {} name()40 absl::string_view name() const override { 41 return "while-loop-trip-count-annotator"; 42 } 43 StatusOr<bool> Run(HloModule* module) override; 44 }; 45 46 } // namespace xla 47 48 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_WHILE_LOOP_TRIP_COUNT_ANNOTATOR_H_ 49