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