2018-09-13 15:40:53 +08:00
|
|
|
//===-- SnippetGenerator.h --------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-09-13 15:40:53 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// Defines the abstract SnippetGenerator class for generating code that allows
|
|
|
|
/// measuring a certain property of instructions (e.g. latency).
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_TOOLS_LLVM_EXEGESIS_SNIPPETGENERATOR_H
|
|
|
|
#define LLVM_TOOLS_LLVM_EXEGESIS_SNIPPETGENERATOR_H
|
|
|
|
|
|
|
|
#include "Assembler.h"
|
|
|
|
#include "BenchmarkCode.h"
|
2018-09-26 19:57:24 +08:00
|
|
|
#include "CodeTemplate.h"
|
2018-09-13 15:40:53 +08:00
|
|
|
#include "LlvmState.h"
|
|
|
|
#include "MCInstrDescView.h"
|
|
|
|
#include "RegisterAliasing.h"
|
2021-11-05 21:50:23 +08:00
|
|
|
#include "llvm/ADT/CombinationGenerator.h"
|
2018-09-13 15:40:53 +08:00
|
|
|
#include "llvm/MC/MCInst.h"
|
|
|
|
#include "llvm/Support/Error.h"
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
2018-10-23 01:10:47 +08:00
|
|
|
namespace llvm {
|
2018-09-13 15:40:53 +08:00
|
|
|
namespace exegesis {
|
|
|
|
|
2018-10-17 19:37:28 +08:00
|
|
|
std::vector<CodeTemplate> getSingleton(CodeTemplate &&CT);
|
2018-10-15 17:09:19 +08:00
|
|
|
|
|
|
|
// Generates code templates that has a self-dependency.
|
2019-10-09 19:58:42 +08:00
|
|
|
Expected<std::vector<CodeTemplate>>
|
[llvm-exegesis] Exploring X86::OperandType::OPERAND_COND_CODE
Summary:
Currently, we only have nice exploration for LEA instruction,
while for the rest, we rely on `randomizeUnsetVariables()`
to sometimes generate something interesting.
While that works, it isn't very reliable in coverage :)
Here, i'm making an assumption that while we may want to explore
multi-instruction configs, we are most interested in the
characteristics of the main instruction we were asked about.
Which we can do, by taking the existing `randomizeMCOperand()`,
and turning it on it's head - instead of relying on it to randomly fill
one of the interesting values, let's pregenerate all the possible interesting
values for the variable, and then generate as much `InstructionTemplate`
combinations of these possible values for variables as needed/possible.
Of course, that requires invasive changes to no longer pass just the
naked `Instruction`, but sometimes partially filled `InstructionTemplate`.
As it can be seen from the test, this allows us to explore
`X86::OperandType::OPERAND_COND_CODE` for instructions
that take such an operand.
I'm hoping this will greatly simplify exploration.
Reviewers: courbet, gchatelet
Reviewed By: gchatelet
Subscribers: orodley, mgorny, sdardis, tschuett, jrtc27, atanasyan, mstojanovic, andreadb, RKSimon, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74156
2020-02-13 01:54:39 +08:00
|
|
|
generateSelfAliasingCodeTemplates(InstructionTemplate Variant);
|
2018-10-15 17:09:19 +08:00
|
|
|
|
|
|
|
// Generates code templates without assignment constraints.
|
2019-10-09 19:58:42 +08:00
|
|
|
Expected<std::vector<CodeTemplate>>
|
[llvm-exegesis] Exploring X86::OperandType::OPERAND_COND_CODE
Summary:
Currently, we only have nice exploration for LEA instruction,
while for the rest, we rely on `randomizeUnsetVariables()`
to sometimes generate something interesting.
While that works, it isn't very reliable in coverage :)
Here, i'm making an assumption that while we may want to explore
multi-instruction configs, we are most interested in the
characteristics of the main instruction we were asked about.
Which we can do, by taking the existing `randomizeMCOperand()`,
and turning it on it's head - instead of relying on it to randomly fill
one of the interesting values, let's pregenerate all the possible interesting
values for the variable, and then generate as much `InstructionTemplate`
combinations of these possible values for variables as needed/possible.
Of course, that requires invasive changes to no longer pass just the
naked `Instruction`, but sometimes partially filled `InstructionTemplate`.
As it can be seen from the test, this allows us to explore
`X86::OperandType::OPERAND_COND_CODE` for instructions
that take such an operand.
I'm hoping this will greatly simplify exploration.
Reviewers: courbet, gchatelet
Reviewed By: gchatelet
Subscribers: orodley, mgorny, sdardis, tschuett, jrtc27, atanasyan, mstojanovic, andreadb, RKSimon, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74156
2020-02-13 01:54:39 +08:00
|
|
|
generateUnconstrainedCodeTemplates(const InstructionTemplate &Variant,
|
|
|
|
StringRef Msg);
|
2018-10-15 17:09:19 +08:00
|
|
|
|
2018-09-13 15:40:53 +08:00
|
|
|
// A class representing failures that happened during Benchmark, they are used
|
|
|
|
// to report informations to the user.
|
2019-10-09 19:58:42 +08:00
|
|
|
class SnippetGeneratorFailure : public StringError {
|
2018-09-13 15:40:53 +08:00
|
|
|
public:
|
2019-10-09 19:58:42 +08:00
|
|
|
SnippetGeneratorFailure(const Twine &S);
|
2018-09-13 15:40:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Common code for all benchmark modes.
|
|
|
|
class SnippetGenerator {
|
|
|
|
public:
|
2019-10-08 22:30:24 +08:00
|
|
|
struct Options {
|
|
|
|
unsigned MaxConfigsPerOpcode = 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
explicit SnippetGenerator(const LLVMState &State, const Options &Opts);
|
2018-09-13 15:40:53 +08:00
|
|
|
|
|
|
|
virtual ~SnippetGenerator();
|
|
|
|
|
|
|
|
// Calls generateCodeTemplate and expands it into one or more BenchmarkCode.
|
[llvm-exegesis] Exploring X86::OperandType::OPERAND_COND_CODE
Summary:
Currently, we only have nice exploration for LEA instruction,
while for the rest, we rely on `randomizeUnsetVariables()`
to sometimes generate something interesting.
While that works, it isn't very reliable in coverage :)
Here, i'm making an assumption that while we may want to explore
multi-instruction configs, we are most interested in the
characteristics of the main instruction we were asked about.
Which we can do, by taking the existing `randomizeMCOperand()`,
and turning it on it's head - instead of relying on it to randomly fill
one of the interesting values, let's pregenerate all the possible interesting
values for the variable, and then generate as much `InstructionTemplate`
combinations of these possible values for variables as needed/possible.
Of course, that requires invasive changes to no longer pass just the
naked `Instruction`, but sometimes partially filled `InstructionTemplate`.
As it can be seen from the test, this allows us to explore
`X86::OperandType::OPERAND_COND_CODE` for instructions
that take such an operand.
I'm hoping this will greatly simplify exploration.
Reviewers: courbet, gchatelet
Reviewed By: gchatelet
Subscribers: orodley, mgorny, sdardis, tschuett, jrtc27, atanasyan, mstojanovic, andreadb, RKSimon, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74156
2020-02-13 01:54:39 +08:00
|
|
|
Error generateConfigurations(const InstructionTemplate &Variant,
|
|
|
|
std::vector<BenchmarkCode> &Benchmarks,
|
|
|
|
const BitVector &ExtraForbiddenRegs) const;
|
2018-09-13 15:40:53 +08:00
|
|
|
|
|
|
|
// Given a snippet, computes which registers the setup code needs to define.
|
2018-09-20 20:22:18 +08:00
|
|
|
std::vector<RegisterValue> computeRegisterInitialValues(
|
2018-09-27 17:23:04 +08:00
|
|
|
const std::vector<InstructionTemplate> &Snippet) const;
|
2018-09-13 15:40:53 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
const LLVMState &State;
|
2019-10-08 22:30:24 +08:00
|
|
|
const Options Opts;
|
2018-09-13 15:40:53 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
// API to be implemented by subclasses.
|
2019-10-09 19:58:42 +08:00
|
|
|
virtual Expected<std::vector<CodeTemplate>>
|
[llvm-exegesis] Exploring X86::OperandType::OPERAND_COND_CODE
Summary:
Currently, we only have nice exploration for LEA instruction,
while for the rest, we rely on `randomizeUnsetVariables()`
to sometimes generate something interesting.
While that works, it isn't very reliable in coverage :)
Here, i'm making an assumption that while we may want to explore
multi-instruction configs, we are most interested in the
characteristics of the main instruction we were asked about.
Which we can do, by taking the existing `randomizeMCOperand()`,
and turning it on it's head - instead of relying on it to randomly fill
one of the interesting values, let's pregenerate all the possible interesting
values for the variable, and then generate as much `InstructionTemplate`
combinations of these possible values for variables as needed/possible.
Of course, that requires invasive changes to no longer pass just the
naked `Instruction`, but sometimes partially filled `InstructionTemplate`.
As it can be seen from the test, this allows us to explore
`X86::OperandType::OPERAND_COND_CODE` for instructions
that take such an operand.
I'm hoping this will greatly simplify exploration.
Reviewers: courbet, gchatelet
Reviewed By: gchatelet
Subscribers: orodley, mgorny, sdardis, tschuett, jrtc27, atanasyan, mstojanovic, andreadb, RKSimon, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74156
2020-02-13 01:54:39 +08:00
|
|
|
generateCodeTemplates(InstructionTemplate Variant,
|
2019-09-27 16:04:10 +08:00
|
|
|
const BitVector &ForbiddenRegisters) const = 0;
|
2018-09-13 15:40:53 +08:00
|
|
|
};
|
|
|
|
|
2018-10-01 20:19:10 +08:00
|
|
|
// A global Random Number Generator to randomize configurations.
|
|
|
|
// FIXME: Move random number generation into an object and make it seedable for
|
|
|
|
// unit tests.
|
|
|
|
std::mt19937 &randomGenerator();
|
|
|
|
|
2019-04-08 18:11:00 +08:00
|
|
|
// Picks a random unsigned integer from 0 to Max (inclusive).
|
|
|
|
size_t randomIndex(size_t Max);
|
|
|
|
|
2018-10-01 20:19:10 +08:00
|
|
|
// Picks a random bit among the bits set in Vector and returns its index.
|
|
|
|
// Precondition: Vector must have at least one bit set.
|
2019-10-09 19:58:42 +08:00
|
|
|
size_t randomBit(const BitVector &Vector);
|
2018-10-01 20:19:10 +08:00
|
|
|
|
|
|
|
// Picks a random configuration, then selects a random def and a random use from
|
|
|
|
// it and finally set the selected values in the provided InstructionInstances.
|
|
|
|
void setRandomAliasing(const AliasingConfigurations &AliasingConfigurations,
|
|
|
|
InstructionTemplate &DefIB, InstructionTemplate &UseIB);
|
|
|
|
|
|
|
|
// Assigns a Random Value to all Variables in IT that are still Invalid.
|
|
|
|
// Do not use any of the registers in `ForbiddenRegs`.
|
2020-01-22 22:49:10 +08:00
|
|
|
Error randomizeUnsetVariables(const LLVMState &State,
|
|
|
|
const BitVector &ForbiddenRegs,
|
|
|
|
InstructionTemplate &IT);
|
2018-10-01 20:19:10 +08:00
|
|
|
|
2018-09-13 15:40:53 +08:00
|
|
|
} // namespace exegesis
|
2018-10-23 01:10:47 +08:00
|
|
|
} // namespace llvm
|
2018-09-13 15:40:53 +08:00
|
|
|
|
|
|
|
#endif // LLVM_TOOLS_LLVM_EXEGESIS_SNIPPETGENERATOR_H
|