[UpdateCCTestChecks] Detect function mangled name on separate line
[llvm-core.git] / tools / llvm-exegesis / lib / CodeTemplate.h
blobd782296ed33d66cf3aeeaebe55eec7b76f078f71
1 //===-- CodeTemplate.h ------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// A set of structures and functions to craft instructions for the
11 /// SnippetGenerator.
12 ///
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TOOLS_LLVM_EXEGESIS_CODETEMPLATE_H
16 #define LLVM_TOOLS_LLVM_EXEGESIS_CODETEMPLATE_H
18 #include "MCInstrDescView.h"
19 #include "llvm/ADT/BitmaskEnum.h"
21 namespace llvm {
22 namespace exegesis {
24 // A template for an Instruction holding values for each of its Variables.
25 struct InstructionTemplate {
26 InstructionTemplate(const Instruction &Instr);
28 InstructionTemplate(const InstructionTemplate &); // default
29 InstructionTemplate &operator=(const InstructionTemplate &); // default
30 InstructionTemplate(InstructionTemplate &&); // default
31 InstructionTemplate &operator=(InstructionTemplate &&); // default
33 unsigned getOpcode() const;
34 llvm::MCOperand &getValueFor(const Variable &Var);
35 const llvm::MCOperand &getValueFor(const Variable &Var) const;
36 llvm::MCOperand &getValueFor(const Operand &Op);
37 const llvm::MCOperand &getValueFor(const Operand &Op) const;
38 bool hasImmediateVariables() const;
40 // Builds an llvm::MCInst from this InstructionTemplate setting its operands
41 // to the corresponding variable values. Precondition: All VariableValues must
42 // be set.
43 llvm::MCInst build() const;
45 Instruction Instr;
46 llvm::SmallVector<llvm::MCOperand, 4> VariableValues;
49 enum class ExecutionMode : uint8_t {
50 UNKNOWN = 0U,
51 // The instruction is always serial because implicit Use and Def alias.
52 // e.g. AAA (alias via EFLAGS)
53 ALWAYS_SERIAL_IMPLICIT_REGS_ALIAS = 1u << 0,
55 // The instruction is always serial because one Def is tied to a Use.
56 // e.g. AND32ri (alias via tied GR32)
57 ALWAYS_SERIAL_TIED_REGS_ALIAS = 1u << 1,
59 // The execution can be made serial by inserting a second instruction that
60 // clobbers/reads memory.
61 // e.g. MOV8rm
62 SERIAL_VIA_MEMORY_INSTR = 1u << 2,
64 // The execution can be made serial by picking one Def that aliases with one
65 // Use.
66 // e.g. VXORPSrr XMM1, XMM1, XMM2
67 SERIAL_VIA_EXPLICIT_REGS = 1u << 3,
69 // The execution can be made serial by inserting a second instruction that
70 // uses one of the Defs and defs one of the Uses.
71 // e.g.
72 // 1st instruction: MMX_PMOVMSKBrr ECX, MM7
73 // 2nd instruction: MMX_MOVD64rr MM7, ECX
74 // or instruction: MMX_MOVD64to64rr MM7, ECX
75 // or instruction: MMX_PINSRWrr MM7, MM7, ECX, 1
76 SERIAL_VIA_NON_MEMORY_INSTR = 1u << 4,
78 // The execution is always parallel because the instruction is missing Use or
79 // Def operands.
80 ALWAYS_PARALLEL_MISSING_USE_OR_DEF = 1u << 5,
82 // The execution can be made parallel by repeating the same instruction but
83 // making sure that Defs of one instruction do not alias with Uses of the
84 // second one.
85 PARALLEL_VIA_EXPLICIT_REGS = 1u << 6,
87 LLVM_MARK_AS_BITMASK_ENUM(/*Largest*/ PARALLEL_VIA_EXPLICIT_REGS)
90 // Returns whether Execution is one of the values defined in the enum above.
91 bool isEnumValue(ExecutionMode Execution);
93 // Returns a human readable string for the enum.
94 llvm::StringRef getName(ExecutionMode Execution);
96 // Returns a sequence of increasing powers of two corresponding to all the
97 // Execution flags.
98 llvm::ArrayRef<ExecutionMode> getAllExecutionBits();
100 // Decomposes Execution into individual set bits.
101 llvm::SmallVector<ExecutionMode, 4> getExecutionModeBits(ExecutionMode);
103 LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
105 // A CodeTemplate is a set of InstructionTemplates that may not be fully
106 // specified (i.e. some variables are not yet set). This allows the
107 // SnippetGenerator to instantiate it many times with specific values to study
108 // their impact on instruction's performance.
109 struct CodeTemplate {
110 CodeTemplate() = default;
112 CodeTemplate(CodeTemplate &&); // default
113 CodeTemplate &operator=(CodeTemplate &&); // default
114 CodeTemplate(const CodeTemplate &) = delete;
115 CodeTemplate &operator=(const CodeTemplate &) = delete;
117 ExecutionMode Execution = ExecutionMode::UNKNOWN;
118 // See InstructionBenchmarkKey.::Config.
119 std::string Config;
120 // Some information about how this template has been created.
121 std::string Info;
122 // The list of the instructions for this template.
123 std::vector<InstructionTemplate> Instructions;
124 // If the template uses the provided scratch memory, the register in which
125 // the pointer to this memory is passed in to the function.
126 unsigned ScratchSpacePointerInReg = 0;
129 } // namespace exegesis
130 } // namespace llvm
132 #endif // LLVM_TOOLS_LLVM_EXEGESIS_CODETEMPLATE_H