1 //===-- Target.h ------------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 /// Classes that handle the creation of target-specific objects. This is
13 /// similar to llvm::Target/TargetRegistry.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_TOOLS_LLVM_EXEGESIS_TARGET_H
18 #define LLVM_TOOLS_LLVM_EXEGESIS_TARGET_H
20 #include "BenchmarkResult.h"
21 #include "BenchmarkRunner.h"
22 #include "LlvmState.h"
23 #include "SnippetGenerator.h"
24 #include "llvm/ADT/Triple.h"
25 #include "llvm/CodeGen/TargetPassConfig.h"
26 #include "llvm/IR/CallingConv.h"
27 #include "llvm/IR/LegacyPassManager.h"
28 #include "llvm/MC/MCInst.h"
29 #include "llvm/MC/MCRegisterInfo.h"
33 class ExegesisTarget
{
35 // Targets can use this to add target-specific passes in assembleToStream();
36 virtual void addTargetSpecificPasses(llvm::PassManagerBase
&PM
) const {}
38 // Generates code to move a constant into a the given register.
39 virtual std::vector
<llvm::MCInst
> setRegTo(const llvm::MCSubtargetInfo
&STI
,
40 const llvm::APInt
&Value
,
41 unsigned Reg
) const = 0;
43 // Returns the register pointing to scratch memory, or 0 if this target
44 // does not support memory operands. The benchmark function uses the
45 // default calling convention.
46 virtual unsigned getScratchMemoryRegister(const llvm::Triple
&) const = 0;
48 // Fills memory operands with references to the address at [Reg] + Offset.
49 virtual void fillMemoryOperands(InstructionBuilder
&IB
, unsigned Reg
,
50 unsigned Offset
) const = 0;
52 // Returns the maximum number of bytes a load/store instruction can access at
53 // once. This is typically the size of the largest register available on the
54 // processor. Note that this only used as a hint to generate independant
55 // load/stores to/from memory, so the exact returned value does not really
56 // matter as long as it's large enough.
57 virtual unsigned getMaxMemoryAccessSize() const = 0;
59 // Creates a snippet generator for the given mode.
60 std::unique_ptr
<SnippetGenerator
>
61 createSnippetGenerator(InstructionBenchmark::ModeE Mode
,
62 const LLVMState
&State
) const;
63 // Creates a benchmark runner for the given mode.
64 std::unique_ptr
<BenchmarkRunner
>
65 createBenchmarkRunner(InstructionBenchmark::ModeE Mode
,
66 const LLVMState
&State
) const;
68 // Returns the ExegesisTarget for the given triple or nullptr if the target
70 static const ExegesisTarget
*lookup(llvm::Triple TT
);
71 // Returns the default (unspecialized) ExegesisTarget.
72 static const ExegesisTarget
&getDefault();
73 // Registers a target. Not thread safe.
74 static void registerTarget(ExegesisTarget
*T
);
76 virtual ~ExegesisTarget();
79 virtual bool matchesArch(llvm::Triple::ArchType Arch
) const = 0;
81 // Targets can implement their own snippet generators/benchmarks runners by
82 // implementing these.
83 std::unique_ptr
<SnippetGenerator
> virtual createLatencySnippetGenerator(
84 const LLVMState
&State
) const;
85 std::unique_ptr
<SnippetGenerator
> virtual createUopsSnippetGenerator(
86 const LLVMState
&State
) const;
87 std::unique_ptr
<BenchmarkRunner
> virtual createLatencyBenchmarkRunner(
88 const LLVMState
&State
) const;
89 std::unique_ptr
<BenchmarkRunner
> virtual createUopsBenchmarkRunner(
90 const LLVMState
&State
) const;
92 const ExegesisTarget
*Next
= nullptr;
95 } // namespace exegesis
97 #endif // LLVM_TOOLS_LLVM_EXEGESIS_TARGET_H