• 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_ORC_JIT_MEMORY_MAPPER_H_
17 #define TENSORFLOW_COMPILER_XLA_SERVICE_CPU_ORC_JIT_MEMORY_MAPPER_H_
18 
19 #include <memory>
20 
21 #include "llvm/ExecutionEngine/SectionMemoryManager.h"
22 
23 namespace xla {
24 namespace cpu {
25 
26 namespace orc_jit_memory_mapper {
27 // Returns the registered memory mapper if there is one.  Returns nullptr if no
28 // memory mapper is registered.
29 llvm::SectionMemoryManager::MemoryMapper* GetInstance();
30 
31 class Registrar {
32  public:
33   // Registers the `mapper` as a memory mapper.  This is a no-op if `mapper` is
34   // null.  Precondition:  no other memory mapper has been registered yet.
35   explicit Registrar(
36       std::unique_ptr<llvm::SectionMemoryManager::MemoryMapper> mapper);
37 };
38 }  // namespace orc_jit_memory_mapper
39 
40 #define XLA_INTERNAL_REGISTER_ORC_JIT_MEMORY_MAPPER(mapper_instance, ctr) \
41   static ::xla::cpu::orc_jit_memory_mapper::Registrar                     \
42       XLA_INTERNAL_REGISTER_ORC_JIT_MEMORY_MAPPER_NAME(ctr)(mapper_instance)
43 
44 // __COUNTER__ must go through another macro to be properly expanded
45 #define XLA_INTERNAL_REGISTER_ORC_JIT_MEMORY_MAPPER_NAME(ctr) \
46   __orc_jit_memory_mapper_registrar_##ctr
47 
48 // Registers the std::unique_ptr<llvm::SectionMemoryManager::MemoryMapper>
49 // returned by the `factory` expression.  `factory` is allowed to evaluate to
50 // a null unique_ptr in which case this macro does nothing.
51 #define XLA_REGISTER_ORC_JIT_MEMORY_MAPPER(factory) \
52   XLA_INTERNAL_REGISTER_ORC_JIT_MEMORY_MAPPER(factory, __COUNTER__)
53 }  // namespace cpu
54 }  // namespace xla
55 
56 #endif  // TENSORFLOW_COMPILER_XLA_SERVICE_CPU_ORC_JIT_MEMORY_MAPPER_H_
57