tf_1.8_xla_doc
compiler_functor.h
Go to the documentation of this file.
1 
3 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
4 
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8 
9  http://www.apache.org/licenses/LICENSE-2.0
10 
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 ==============================================================================*/
17 
18 #ifndef TENSORFLOW_COMPILER_XLA_SERVICE_CPU_COMPILER_FUNCTOR_H_
19 #define TENSORFLOW_COMPILER_XLA_SERVICE_CPU_COMPILER_FUNCTOR_H_
20 
21 #include "llvm/IR/LegacyPassManager.h"
22 #include "llvm/IR/Module.h"
23 #include "llvm/Object/ObjectFile.h"
24 #include "llvm/Target/TargetMachine.h"
27 #include "tensorflow/core/platform/logging.h"
28 
29 namespace xla {
30 namespace cpu {
31 
38  public:
39  explicit CompilerFunctor(
40  llvm::TargetMachine* target_machine, const Disassembler* disassembler,
41  int opt_level, bool optimize_for_size, bool enable_fast_math,
42  bool disable_expensive_passes,
43  LLVMCompiler::ModuleHook pre_optimization_hook = nullptr,
44  LLVMCompiler::ModuleHook post_optimization_hook = nullptr)
45  : target_machine_(target_machine),
46  disassembler_(CHECK_NOTNULL(disassembler)),
47  opt_level_(opt_level),
48  optimize_for_size_(optimize_for_size),
49  enable_fast_math_(enable_fast_math),
50  disable_expensive_passes_(disable_expensive_passes),
51  pre_optimization_hook_(pre_optimization_hook),
52  post_optimization_hook_(post_optimization_hook) {}
53 
55  std::unique_ptr<llvm::MemoryBuffer> operator()(
56  llvm::Module& module) const; // NOLINT
57 
58  private:
59  // Populates the given pass manager with TargetLibraryInfo and
60  // TargetTransformInfo passes.
61  void AddTargetInfoPasses(llvm::legacy::PassManagerBase* passes) const;
62 
63  // Populates the given pass managers based on the optimization level.
64  void AddOptimizationPasses(llvm::legacy::PassManagerBase* module_passes,
65  llvm::legacy::FunctionPassManager* function_passes,
66  unsigned opt_level, unsigned size_level) const;
67 
68  llvm::TargetMachine* target_machine_;
69  const Disassembler* disassembler_;
70  const unsigned opt_level_;
71  const bool optimize_for_size_;
72  const bool enable_fast_math_;
73  const bool disable_expensive_passes_;
74  LLVMCompiler::ModuleHook pre_optimization_hook_;
75  LLVMCompiler::ModuleHook post_optimization_hook_;
76 };
77 
78 } // namespace cpu
79 } // namespace xla
80 
81 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_CPU_COMPILER_FUNCTOR_H_
Definition: disassembler.h:55
std::unique_ptr< llvm::MemoryBuffer > operator()(llvm::Module &module) const
Definition: compiler_functor.cc:98
namespace for xla
Definition: client_library.cc:26
Definition: compiler_functor.h:37