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 // Precondition: Value must fit into Reg.
40 virtual std::vector
<llvm::MCInst
>
41 setRegTo(const llvm::MCSubtargetInfo
&STI
, unsigned Reg
,
42 const llvm::APInt
&Value
) const = 0;
44 // Returns the register pointing to scratch memory, or 0 if this target
45 // does not support memory operands. The benchmark function uses the
46 // default calling convention.
47 virtual unsigned getScratchMemoryRegister(const llvm::Triple
&) const {
51 // Fills memory operands with references to the address at [Reg] + Offset.
52 virtual void fillMemoryOperands(InstructionTemplate
&IT
, unsigned Reg
,
53 unsigned Offset
) const {
56 "fillMemoryOperands() requires getScratchMemoryRegister() > 0");
59 // Returns the maximum number of bytes a load/store instruction can access at
60 // once. This is typically the size of the largest register available on the
61 // processor. Note that this only used as a hint to generate independant
62 // load/stores to/from memory, so the exact returned value does not really
63 // matter as long as it's large enough.
64 virtual unsigned getMaxMemoryAccessSize() const { return 0; }
66 // Creates a snippet generator for the given mode.
67 std::unique_ptr
<SnippetGenerator
>
68 createSnippetGenerator(InstructionBenchmark::ModeE Mode
,
69 const LLVMState
&State
) const;
70 // Creates a benchmark runner for the given mode.
71 std::unique_ptr
<BenchmarkRunner
>
72 createBenchmarkRunner(InstructionBenchmark::ModeE Mode
,
73 const LLVMState
&State
) const;
75 // Returns the ExegesisTarget for the given triple or nullptr if the target
77 static const ExegesisTarget
*lookup(llvm::Triple TT
);
78 // Returns the default (unspecialized) ExegesisTarget.
79 static const ExegesisTarget
&getDefault();
80 // Registers a target. Not thread safe.
81 static void registerTarget(ExegesisTarget
*T
);
83 virtual ~ExegesisTarget();
86 virtual bool matchesArch(llvm::Triple::ArchType Arch
) const = 0;
88 // Targets can implement their own snippet generators/benchmarks runners by
89 // implementing these.
90 std::unique_ptr
<SnippetGenerator
> virtual createLatencySnippetGenerator(
91 const LLVMState
&State
) const;
92 std::unique_ptr
<SnippetGenerator
> virtual createUopsSnippetGenerator(
93 const LLVMState
&State
) const;
94 std::unique_ptr
<BenchmarkRunner
> virtual createLatencyBenchmarkRunner(
95 const LLVMState
&State
) const;
96 std::unique_ptr
<BenchmarkRunner
> virtual createUopsBenchmarkRunner(
97 const LLVMState
&State
) const;
99 const ExegesisTarget
*Next
= nullptr;
102 } // namespace exegesis
104 #endif // LLVM_TOOLS_LLVM_EXEGESIS_TARGET_H