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_GPU_IR_EMITTER_CONTEXT_H_
17 #define TENSORFLOW_COMPILER_XLA_SERVICE_GPU_IR_EMITTER_CONTEXT_H_
18 
19 #include "llvm/IR/Module.h"
20 #include "tensorflow/compiler/xla/service/buffer_assignment.h"
21 #include "tensorflow/compiler/xla/service/gpu/partition_assignment.h"
22 #include "tensorflow/compiler/xla/service/name_uniquer.h"
23 #include "tensorflow/core/platform/stream_executor_no_cuda.h"
24 
25 namespace xla {
26 namespace gpu {
27 
28 // IrEmitterContext encapsulates common (mutable and immutable) data structures
29 // used by both IrEmitterNested and IrEmitterUnnested, such as the buffer
30 // assignment and the name uniquer.
31 class IrEmitterContext {
32  public:
IrEmitterContext(const HloModule * hlo_module,const BufferAssignment * buffer_assignment,const se::DeviceDescription * device_desc,llvm::Module * llvm_module)33   IrEmitterContext(const HloModule* hlo_module,
34                    const BufferAssignment* buffer_assignment,
35                    const se::DeviceDescription* device_desc,
36                    llvm::Module* llvm_module)
37       : hlo_module_(hlo_module),
38         buffer_assignment_(buffer_assignment),
39         device_desc_(device_desc),
40         llvm_module_(llvm_module) {}
41   // Disallow copy and assign.
42   IrEmitterContext(const IrEmitterContext&) = delete;
43   IrEmitterContext& operator=(const IrEmitterContext&) = delete;
44 
45   // Simple accessors.
hlo_module()46   const HloModule& hlo_module() const { return *hlo_module_; }
buffer_assignment()47   const BufferAssignment& buffer_assignment() const {
48     return *buffer_assignment_;
49   }
device_description()50   const se::DeviceDescription& device_description() const {
51     return *device_desc_;
52   }
llvm_module()53   llvm::Module* llvm_module() { return llvm_module_; }
name_uniquer()54   NameUniquer* name_uniquer() { return &name_uniquer_; }
55 
56  private:
57   const HloModule* hlo_module_;
58   const BufferAssignment* buffer_assignment_;
59   const se::DeviceDescription* device_desc_;
60   llvm::Module* llvm_module_;
61   NameUniquer name_uniquer_;
62 };
63 
64 }  // namespace gpu
65 }  // namespace xla
66 
67 #endif  // TENSORFLOW_COMPILER_XLA_SERVICE_GPU_IR_EMITTER_CONTEXT_H_
68