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 #include "tensorflow/compiler/mlir/init_mlir.h"
17 
18 #include "tensorflow/core/platform/init_main.h"
19 
20 static llvm::cl::extrahelp FlagSplittingHelp(R"(
21 The command line parsing is split between the two flag parsing libraries used by
22 TensorFlow and LLVM:
23   * Flags before the first '--' are parsed by tensorflow::InitMain while those
24     post are parsed by LLVM's command line parser.
25   * If there is no separator, then no flags are parsed by InitMain and only
26     LLVM command line parser used.
27 The above help options reported are for LLVM's parser, run with `--help --` for
28 TensorFlow's help.
29 )");
30 
31 namespace tensorflow {
32 
InitMlir(int * argc,char *** argv)33 InitMlir::InitMlir(int *argc, char ***argv) : init_llvm_(*argc, *argv) {
34   llvm::setBugReportMsg(
35       "TensorFlow crashed, please file a bug on "
36       "https://github.com/tensorflow/tensorflow/issues with the trace "
37       "below.\n");
38 
39   constexpr char kSeparator[] = "--";
40 
41   // Find index of separator between two sets of flags.
42   int pass_remainder = 1;
43   bool split = false;
44   for (int i = 0; i < *argc; ++i) {
45     if (llvm::StringRef((*argv)[i]) == kSeparator) {
46       pass_remainder = i;
47       *argc -= (i + 1);
48       split = true;
49       break;
50     }
51   }
52 
53   tensorflow::port::InitMain((*argv)[0], &pass_remainder, argv);
54   if (split) {
55     *argc += pass_remainder;
56     (*argv)[1] = (*argv)[0];
57     ++*argv;
58   }
59 }
60 
61 }  // namespace tensorflow
62