tf_1.8_xla_doc
disassembler.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_DISASSEMBLER_H_
19 #define TENSORFLOW_COMPILER_XLA_SERVICE_CPU_DISASSEMBLER_H_
20 
21 #include <memory>
22 #include <string>
23 
24 #include "llvm/MC/MCContext.h"
25 #include "llvm/MC/MCDisassembler/MCDisassembler.h"
26 #include "llvm/MC/MCInstPrinter.h"
27 #include "llvm/MC/MCInstrAnalysis.h"
28 #include "llvm/MC/MCObjectFileInfo.h"
29 #include "llvm/MC/MCSubtargetInfo.h"
30 #include "llvm/Object/ObjectFile.h"
31 #include "llvm/Target/TargetMachine.h"
32 #include "tensorflow/compiler/xla/statusor.h"
33 #include "tensorflow/compiler/xla/types.h"
34 
35 namespace xla {
36 namespace cpu {
37 
38 struct DisassemblerResult {
39  DisassemblerResult(const string& text, size_t code_size_bytes)
40  : text(text), code_size_bytes(code_size_bytes) {}
41 
42  // The disassembled text sections of the object file.
43  string text;
44  // The total number of bytes of executable code in the object file.
45  uint64_t code_size_bytes;
46 };
55 class Disassembler {
56  public:
57  explicit Disassembler(const llvm::TargetMachine& target_machine);
58 
59  // Returns a DisassemblerResult for the given object file, containing the
60  // disassembled code.
61  //
62  // If we couldn't retrieve a disassembler for this platform, an error status
63  // is returned.
64  StatusOr<DisassemblerResult> DisassembleObjectFile(
65  const llvm::object::ObjectFile& object_file) const;
66 
67  private:
68  const llvm::MCSubtargetInfo& subtarget_info_;
69  std::unique_ptr<llvm::MCObjectFileInfo> objfile_info_;
70  std::unique_ptr<llvm::MCContext> mc_context_;
71  std::unique_ptr<llvm::MCDisassembler> disassembler_;
72  std::unique_ptr<llvm::MCInstPrinter> inst_printer_;
73  std::unique_ptr<llvm::MCInstrAnalysis> inst_analysis_;
74 };
75 
76 } // namespace cpu
77 } // namespace xla
78 
79 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_CPU_DISASSEMBLER_H_
Definition: disassembler.h:55
namespace for xla
Definition: client_library.cc:26