1 /* Copyright 2018 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_ANALYSIS_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_WHILE_LOOP_ANALYSIS_H_ 18 19 #include <optional> 20 21 #include "tensorflow/compiler/xla/service/hlo_instruction.h" 22 23 namespace xla { 24 25 // Returns the precise trip count of the loop if it's statically known, 26 // nullopt otherwise. 27 // 28 // max_brute_force_iters limits the number of steps that are evaluated while 29 // trying to brute force a loop trip count. trip counts larger than 30 // max_brute_force_iters may be returned if we can pattern-match the loop 31 // condition. 32 std::optional<int64_t> ComputeWhileLoopTripCount( 33 HloInstruction *while_op, int64_t max_brute_force_iters = 128); 34 35 // Returns an upper bound on the trip count of the loop if it's statically 36 // known, nullopt otherwise. 37 std::optional<int64_t> ComputeWhileLoopTripCountUpperBound( 38 HloInstruction *while_op); 39 40 // The below function identifies a subset of all possible auxiliary 41 // induction variables (AIV). Specifically, candidates are gtes, e.g., 42 // gte(param0, N) 43 std::vector<const HloInstruction *> GetAuxiliaryLoopInductionVars( 44 const HloInstruction *while_op); 45 // Returns the tuple index of the loop induction variable if there is such an 46 // induction variable detected. Otherwise returns nullopt. 47 std::optional<int64_t> GetLoopInductionVarTupleIdx( 48 const HloInstruction *while_op); 49 } // namespace xla 50 51 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_WHILE_LOOP_ANALYSIS_H_ 52