1 //===-- CodeTemplate.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 //===----------------------------------------------------------------------===//
11 /// A set of structures and functions to craft instructions for the
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_TOOLS_LLVM_EXEGESIS_CODETEMPLATE_H
17 #define LLVM_TOOLS_LLVM_EXEGESIS_CODETEMPLATE_H
19 #include "MCInstrDescView.h"
23 // A template for an Instruction holding values for each of its Variables.
24 struct InstructionTemplate
{
25 InstructionTemplate(const Instruction
&Instr
);
27 InstructionTemplate(const InstructionTemplate
&); // default
28 InstructionTemplate
&operator=(const InstructionTemplate
&); // default
29 InstructionTemplate(InstructionTemplate
&&); // default
30 InstructionTemplate
&operator=(InstructionTemplate
&&); // default
32 unsigned getOpcode() const;
33 llvm::MCOperand
&getValueFor(const Variable
&Var
);
34 const llvm::MCOperand
&getValueFor(const Variable
&Var
) const;
35 llvm::MCOperand
&getValueFor(const Operand
&Op
);
36 const llvm::MCOperand
&getValueFor(const Operand
&Op
) const;
37 bool hasImmediateVariables() const;
39 // Builds an llvm::MCInst from this InstructionTemplate setting its operands
40 // to the corresponding variable values. Precondition: All VariableValues must
42 llvm::MCInst
build() const;
45 llvm::SmallVector
<llvm::MCOperand
, 4> VariableValues
;
48 // A CodeTemplate is a set of InstructionTemplates that may not be fully
49 // specified (i.e. some variables are not yet set). This allows the
50 // BenchmarkRunner to instantiate it many times with specific values to study
51 // their impact on instruction's performance.
53 CodeTemplate() = default;
55 CodeTemplate(CodeTemplate
&&); // default
56 CodeTemplate
&operator=(CodeTemplate
&&); // default
57 CodeTemplate(const CodeTemplate
&) = delete;
58 CodeTemplate
&operator=(const CodeTemplate
&) = delete;
60 // Some information about how this template has been created.
62 // The list of the instructions for this template.
63 std::vector
<InstructionTemplate
> Instructions
;
64 // If the template uses the provided scratch memory, the register in which
65 // the pointer to this memory is passed in to the function.
66 unsigned ScratchSpacePointerInReg
= 0;
69 } // namespace exegesis
71 #endif // LLVM_TOOLS_LLVM_EXEGESIS_CODETEMPLATE_H