• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2017 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_CPU_ELEMENTAL_IR_EMITTER_H_
17 #define TENSORFLOW_COMPILER_XLA_SERVICE_CPU_ELEMENTAL_IR_EMITTER_H_
18 
19 #include "llvm/IR/IRBuilder.h"
20 #include "llvm/IR/Module.h"
21 #include "llvm/IR/Value.h"
22 #include "tensorflow/compiler/xla/service/cpu/ir_emitter.h"
23 #include "tensorflow/compiler/xla/service/elemental_ir_emitter.h"
24 #include "tensorflow/compiler/xla/service/hlo_instruction.h"
25 #include "tensorflow/compiler/xla/statusor.h"
26 
27 namespace xla {
28 namespace cpu {
29 
30 class CpuElementalIrEmitter : public ElementalIrEmitter {
31  public:
CpuElementalIrEmitter(const HloModuleConfig & module_config,IrEmitter * ir_emitter,llvm::Module * module)32   CpuElementalIrEmitter(const HloModuleConfig& module_config,
33                         IrEmitter* ir_emitter, llvm::Module* module)
34       : ElementalIrEmitter(module, ir_emitter->b()),
35         hlo_module_config_(module_config),
36         ir_emitter_(ir_emitter) {}
37 
38  protected:
39   StatusOr<llvm::Value*> EmitAtan2(PrimitiveType prim_type, llvm::Value* lhs,
40                                    llvm::Value* rhs,
41                                    absl::string_view name) override;
42   StatusOr<llvm::Value*> EmitTanh(PrimitiveType prim_type,
43                                   llvm::Value* value) override;
44 
EmitThreadLocalCall(const HloComputation & callee,absl::Span<llvm::Value * const> parameters,absl::string_view name)45   StatusOr<std::vector<llvm::Value*>> EmitThreadLocalCall(
46       const HloComputation& callee, absl::Span<llvm::Value* const> parameters,
47       absl::string_view name) override {
48     return ir_emitter_->EmitThreadLocalCall(callee, parameters, name);
49   }
50 
fast_min_max()51   bool fast_min_max() override {
52     return hlo_module_config_.debug_options().xla_cpu_enable_fast_min_max();
53   }
54 
55   const HloModuleConfig& hlo_module_config_;
56   IrEmitter* ir_emitter_;
57 };
58 
59 }  // namespace cpu
60 }  // namespace xla
61 
62 #endif  // TENSORFLOW_COMPILER_XLA_SERVICE_CPU_ELEMENTAL_IR_EMITTER_H_
63