2018-05-25 17:55:37 +02:00
|
|
|
//===--------------------- PredicateExpander.h ----------------------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01: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-05-25 17:55:37 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \file
|
|
|
|
/// Functionalities used by the Tablegen backends to expand machine predicates.
|
|
|
|
///
|
|
|
|
/// See file llvm/Target/TargetInstrPredicate.td for a full list and description
|
|
|
|
/// of all the supported MCInstPredicate classes.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_UTILS_TABLEGEN_PREDICATEEXPANDER_H
|
|
|
|
#define LLVM_UTILS_TABLEGEN_PREDICATEEXPANDER_H
|
|
|
|
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2018-08-13 17:13:35 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2018-05-25 17:55:37 +02:00
|
|
|
#include "llvm/TableGen/Record.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2018-08-13 17:13:35 +02:00
|
|
|
class raw_ostream;
|
2018-05-25 17:55:37 +02:00
|
|
|
|
|
|
|
class PredicateExpander {
|
|
|
|
bool EmitCallsByRef;
|
|
|
|
bool NegatePredicate;
|
|
|
|
bool ExpandForMC;
|
|
|
|
unsigned IndentLevel;
|
2018-08-14 20:36:54 +02:00
|
|
|
StringRef TargetName;
|
2018-05-25 17:55:37 +02:00
|
|
|
|
|
|
|
PredicateExpander(const PredicateExpander &) = delete;
|
|
|
|
PredicateExpander &operator=(const PredicateExpander &) = delete;
|
|
|
|
|
|
|
|
public:
|
2018-08-14 20:36:54 +02:00
|
|
|
PredicateExpander(StringRef Target)
|
2018-05-25 17:55:37 +02:00
|
|
|
: EmitCallsByRef(true), NegatePredicate(false), ExpandForMC(false),
|
2018-08-14 20:36:54 +02:00
|
|
|
IndentLevel(1U), TargetName(Target) {}
|
2018-05-25 17:55:37 +02:00
|
|
|
bool isByRef() const { return EmitCallsByRef; }
|
|
|
|
bool shouldNegate() const { return NegatePredicate; }
|
|
|
|
bool shouldExpandForMC() const { return ExpandForMC; }
|
|
|
|
unsigned getIndentLevel() const { return IndentLevel; }
|
[TableGen][SubtargetEmitter] Add the ability for processor models to describe dependency breaking instructions.
This patch adds the ability for processor models to describe dependency breaking
instructions.
Different processors may specify a different set of dependency-breaking
instructions.
That means, we cannot assume that all processors of the same target would use
the same rules to classify dependency breaking instructions.
The main goal of this patch is to provide the means to describe dependency
breaking instructions directly via tablegen, and have the following
TargetSubtargetInfo hooks redefined in overrides by tabegen'd
XXXGenSubtargetInfo classes (here, XXX is a Target name).
```
virtual bool isZeroIdiom(const MachineInstr *MI, APInt &Mask) const {
return false;
}
virtual bool isDependencyBreaking(const MachineInstr *MI, APInt &Mask) const {
return isZeroIdiom(MI);
}
```
An instruction MI is a dependency-breaking instruction if a call to method
isDependencyBreaking(MI) on the STI (TargetSubtargetInfo object) evaluates to
true. Similarly, an instruction MI is a special case of zero-idiom dependency
breaking instruction if a call to STI.isZeroIdiom(MI) returns true.
The extra APInt is used for those targets that may want to select which machine
operands have their dependency broken (see comments in code).
Note that by default, subtargets don't know about the existence of
dependency-breaking. In the absence of external information, those method calls
would always return false.
A new tablegen class named STIPredicate has been added by this patch to let
processor models classify instructions that have properties in common. The idea
is that, a MCInstrPredicate definition can be used to "generate" an instruction
equivalence class, with the idea that instructions of a same class all have a
property in common.
STIPredicate definitions are essentially a collection of instruction equivalence
classes.
Also, different processor models can specify a different variant of the same
STIPredicate with different rules (i.e. predicates) to classify instructions.
Tablegen backends (in this particular case, the SubtargetEmitter) will be able
to process STIPredicate definitions, and automatically generate functions in
XXXGenSubtargetInfo.
This patch introduces two special kind of STIPredicate classes named
IsZeroIdiomFunction and IsDepBreakingFunction in tablegen. It also adds a
definition for those in the BtVer2 scheduling model only.
This patch supersedes the one committed at r338372 (phabricator review: D49310).
The main advantages are:
- We can describe subtarget predicates via tablegen using STIPredicates.
- We can describe zero-idioms / dep-breaking instructions directly via
tablegen in the scheduling models.
In future, the STIPredicates framework can be used for solving other problems.
Examples of future developments are:
- Teach how to identify optimizable register-register moves
- Teach how to identify slow LEA instructions (each subtarget defining its own
concept of "slow" LEA).
- Teach how to identify instructions that have undocumented false dependencies
on the output registers on some processors only.
It is also (in my opinion) an elegant way to expose knowledge to both external
tools like llvm-mca, and codegen passes.
For example, machine schedulers in LLVM could reuse that information when
internally constructing the data dependency graph for a code region.
This new design feature is also an "opt-in" feature. Processor models don't have
to use the new STIPredicates. It has all been designed to be as unintrusive as
possible.
Differential Revision: https://reviews.llvm.org/D52174
llvm-svn: 342555
2018-09-19 17:57:45 +02:00
|
|
|
StringRef getTargetName() const { return TargetName; }
|
2018-05-25 17:55:37 +02:00
|
|
|
|
|
|
|
void setByRef(bool Value) { EmitCallsByRef = Value; }
|
|
|
|
void flipNegatePredicate() { NegatePredicate = !NegatePredicate; }
|
|
|
|
void setNegatePredicate(bool Value) { NegatePredicate = Value; }
|
|
|
|
void setExpandForMC(bool Value) { ExpandForMC = Value; }
|
[TableGen][SubtargetEmitter] Add the ability for processor models to describe dependency breaking instructions.
This patch adds the ability for processor models to describe dependency breaking
instructions.
Different processors may specify a different set of dependency-breaking
instructions.
That means, we cannot assume that all processors of the same target would use
the same rules to classify dependency breaking instructions.
The main goal of this patch is to provide the means to describe dependency
breaking instructions directly via tablegen, and have the following
TargetSubtargetInfo hooks redefined in overrides by tabegen'd
XXXGenSubtargetInfo classes (here, XXX is a Target name).
```
virtual bool isZeroIdiom(const MachineInstr *MI, APInt &Mask) const {
return false;
}
virtual bool isDependencyBreaking(const MachineInstr *MI, APInt &Mask) const {
return isZeroIdiom(MI);
}
```
An instruction MI is a dependency-breaking instruction if a call to method
isDependencyBreaking(MI) on the STI (TargetSubtargetInfo object) evaluates to
true. Similarly, an instruction MI is a special case of zero-idiom dependency
breaking instruction if a call to STI.isZeroIdiom(MI) returns true.
The extra APInt is used for those targets that may want to select which machine
operands have their dependency broken (see comments in code).
Note that by default, subtargets don't know about the existence of
dependency-breaking. In the absence of external information, those method calls
would always return false.
A new tablegen class named STIPredicate has been added by this patch to let
processor models classify instructions that have properties in common. The idea
is that, a MCInstrPredicate definition can be used to "generate" an instruction
equivalence class, with the idea that instructions of a same class all have a
property in common.
STIPredicate definitions are essentially a collection of instruction equivalence
classes.
Also, different processor models can specify a different variant of the same
STIPredicate with different rules (i.e. predicates) to classify instructions.
Tablegen backends (in this particular case, the SubtargetEmitter) will be able
to process STIPredicate definitions, and automatically generate functions in
XXXGenSubtargetInfo.
This patch introduces two special kind of STIPredicate classes named
IsZeroIdiomFunction and IsDepBreakingFunction in tablegen. It also adds a
definition for those in the BtVer2 scheduling model only.
This patch supersedes the one committed at r338372 (phabricator review: D49310).
The main advantages are:
- We can describe subtarget predicates via tablegen using STIPredicates.
- We can describe zero-idioms / dep-breaking instructions directly via
tablegen in the scheduling models.
In future, the STIPredicates framework can be used for solving other problems.
Examples of future developments are:
- Teach how to identify optimizable register-register moves
- Teach how to identify slow LEA instructions (each subtarget defining its own
concept of "slow" LEA).
- Teach how to identify instructions that have undocumented false dependencies
on the output registers on some processors only.
It is also (in my opinion) an elegant way to expose knowledge to both external
tools like llvm-mca, and codegen passes.
For example, machine schedulers in LLVM could reuse that information when
internally constructing the data dependency graph for a code region.
This new design feature is also an "opt-in" feature. Processor models don't have
to use the new STIPredicates. It has all been designed to be as unintrusive as
possible.
Differential Revision: https://reviews.llvm.org/D52174
llvm-svn: 342555
2018-09-19 17:57:45 +02:00
|
|
|
void setIndentLevel(unsigned Level) { IndentLevel = Level; }
|
2018-05-25 17:55:37 +02:00
|
|
|
void increaseIndentLevel() { ++IndentLevel; }
|
|
|
|
void decreaseIndentLevel() { --IndentLevel; }
|
|
|
|
|
|
|
|
using RecVec = std::vector<Record *>;
|
2018-08-13 17:13:35 +02:00
|
|
|
void expandTrue(raw_ostream &OS);
|
|
|
|
void expandFalse(raw_ostream &OS);
|
[tblgen][PredicateExpander] Add the ability to describe more complex constraints on instruction operands.
Before this patch, class PredicateExpander only knew how to expand simple
predicates that performed checks on instruction operands.
In particular, the new scheduling predicate syntax was not rich enough to
express checks like this one:
Foo(MI->getOperand(0).getImm()) == ExpectedVal;
Here, the immediate operand value at index zero is passed in input to function
Foo, and ExpectedVal is compared against the value returned by function Foo.
While this predicate pattern doesn't show up in any X86 model, it shows up in
other upstream targets. So, being able to support those predicates is
fundamental if we want to be able to modernize all the scheduling models
upstream.
With this patch, we allow users to specify if a register/immediate operand value
needs to be passed in input to a function as part of the predicate check. Now,
register/immediate operand checks all derive from base class CheckOperandBase.
This patch also changes where TIIPredicate definitions are expanded by the
instructon info emitter. Before, definitions were expanded in class
XXXGenInstrInfo (where XXX is a target name).
With the introduction of this new syntax, we may want to have TIIPredicates
expanded directly in XXXInstrInfo. That is because functions used by the new
operand predicates may only exist in the derived class (i.e. XXXInstrInfo).
This patch is a non functional change for the existing scheduling models.
In future, we will be able to use this richer syntax to better describe complex
scheduling predicates, and expose them to llvm-mca.
Differential Revision: https://reviews.llvm.org/D53880
llvm-svn: 345714
2018-10-31 13:28:05 +01:00
|
|
|
void expandCheckImmOperand(raw_ostream &OS, int OpIndex, int ImmVal,
|
|
|
|
StringRef FunctionMapper);
|
|
|
|
void expandCheckImmOperand(raw_ostream &OS, int OpIndex, StringRef ImmVal,
|
|
|
|
StringRef FunctionMapperer);
|
|
|
|
void expandCheckImmOperandSimple(raw_ostream &OS, int OpIndex,
|
|
|
|
StringRef FunctionMapper);
|
|
|
|
void expandCheckRegOperand(raw_ostream &OS, int OpIndex, const Record *Reg,
|
|
|
|
StringRef FunctionMapper);
|
|
|
|
void expandCheckRegOperandSimple(raw_ostream &OS, int OpIndex,
|
|
|
|
StringRef FunctionMapper);
|
2018-08-13 17:13:35 +02:00
|
|
|
void expandCheckSameRegOperand(raw_ostream &OS, int First, int Second);
|
|
|
|
void expandCheckNumOperands(raw_ostream &OS, int NumOps);
|
|
|
|
void expandCheckOpcode(raw_ostream &OS, const Record *Inst);
|
2018-05-25 17:55:37 +02:00
|
|
|
|
2018-08-13 17:13:35 +02:00
|
|
|
void expandCheckPseudo(raw_ostream &OS, const RecVec &Opcodes);
|
|
|
|
void expandCheckOpcode(raw_ostream &OS, const RecVec &Opcodes);
|
|
|
|
void expandPredicateSequence(raw_ostream &OS, const RecVec &Sequence,
|
|
|
|
bool IsCheckAll);
|
2018-08-14 20:36:54 +02:00
|
|
|
void expandTIIFunctionCall(raw_ostream &OS, StringRef MethodName);
|
2018-08-13 17:13:35 +02:00
|
|
|
void expandCheckIsRegOperand(raw_ostream &OS, int OpIndex);
|
|
|
|
void expandCheckIsImmOperand(raw_ostream &OS, int OpIndex);
|
|
|
|
void expandCheckInvalidRegOperand(raw_ostream &OS, int OpIndex);
|
|
|
|
void expandCheckFunctionPredicate(raw_ostream &OS, StringRef MCInstFn,
|
2018-05-25 17:55:37 +02:00
|
|
|
StringRef MachineInstrFn);
|
2020-10-19 10:37:54 +02:00
|
|
|
void expandCheckFunctionPredicateWithTII(raw_ostream &OS, StringRef MCInstFn,
|
|
|
|
StringRef MachineInstrFn,
|
|
|
|
StringRef TIIPtr);
|
2018-08-13 17:13:35 +02:00
|
|
|
void expandCheckNonPortable(raw_ostream &OS, StringRef CodeBlock);
|
|
|
|
void expandPredicate(raw_ostream &OS, const Record *Rec);
|
|
|
|
void expandReturnStatement(raw_ostream &OS, const Record *Rec);
|
|
|
|
void expandOpcodeSwitchCase(raw_ostream &OS, const Record *Rec);
|
|
|
|
void expandOpcodeSwitchStatement(raw_ostream &OS, const RecVec &Cases,
|
|
|
|
const Record *Default);
|
|
|
|
void expandStatement(raw_ostream &OS, const Record *Rec);
|
2018-05-25 17:55:37 +02:00
|
|
|
};
|
|
|
|
|
[TableGen][SubtargetEmitter] Add the ability for processor models to describe dependency breaking instructions.
This patch adds the ability for processor models to describe dependency breaking
instructions.
Different processors may specify a different set of dependency-breaking
instructions.
That means, we cannot assume that all processors of the same target would use
the same rules to classify dependency breaking instructions.
The main goal of this patch is to provide the means to describe dependency
breaking instructions directly via tablegen, and have the following
TargetSubtargetInfo hooks redefined in overrides by tabegen'd
XXXGenSubtargetInfo classes (here, XXX is a Target name).
```
virtual bool isZeroIdiom(const MachineInstr *MI, APInt &Mask) const {
return false;
}
virtual bool isDependencyBreaking(const MachineInstr *MI, APInt &Mask) const {
return isZeroIdiom(MI);
}
```
An instruction MI is a dependency-breaking instruction if a call to method
isDependencyBreaking(MI) on the STI (TargetSubtargetInfo object) evaluates to
true. Similarly, an instruction MI is a special case of zero-idiom dependency
breaking instruction if a call to STI.isZeroIdiom(MI) returns true.
The extra APInt is used for those targets that may want to select which machine
operands have their dependency broken (see comments in code).
Note that by default, subtargets don't know about the existence of
dependency-breaking. In the absence of external information, those method calls
would always return false.
A new tablegen class named STIPredicate has been added by this patch to let
processor models classify instructions that have properties in common. The idea
is that, a MCInstrPredicate definition can be used to "generate" an instruction
equivalence class, with the idea that instructions of a same class all have a
property in common.
STIPredicate definitions are essentially a collection of instruction equivalence
classes.
Also, different processor models can specify a different variant of the same
STIPredicate with different rules (i.e. predicates) to classify instructions.
Tablegen backends (in this particular case, the SubtargetEmitter) will be able
to process STIPredicate definitions, and automatically generate functions in
XXXGenSubtargetInfo.
This patch introduces two special kind of STIPredicate classes named
IsZeroIdiomFunction and IsDepBreakingFunction in tablegen. It also adds a
definition for those in the BtVer2 scheduling model only.
This patch supersedes the one committed at r338372 (phabricator review: D49310).
The main advantages are:
- We can describe subtarget predicates via tablegen using STIPredicates.
- We can describe zero-idioms / dep-breaking instructions directly via
tablegen in the scheduling models.
In future, the STIPredicates framework can be used for solving other problems.
Examples of future developments are:
- Teach how to identify optimizable register-register moves
- Teach how to identify slow LEA instructions (each subtarget defining its own
concept of "slow" LEA).
- Teach how to identify instructions that have undocumented false dependencies
on the output registers on some processors only.
It is also (in my opinion) an elegant way to expose knowledge to both external
tools like llvm-mca, and codegen passes.
For example, machine schedulers in LLVM could reuse that information when
internally constructing the data dependency graph for a code region.
This new design feature is also an "opt-in" feature. Processor models don't have
to use the new STIPredicates. It has all been designed to be as unintrusive as
possible.
Differential Revision: https://reviews.llvm.org/D52174
llvm-svn: 342555
2018-09-19 17:57:45 +02:00
|
|
|
// Forward declarations.
|
|
|
|
class STIPredicateFunction;
|
|
|
|
class OpcodeGroup;
|
|
|
|
|
|
|
|
class STIPredicateExpander : public PredicateExpander {
|
|
|
|
StringRef ClassPrefix;
|
|
|
|
bool ExpandDefinition;
|
|
|
|
|
|
|
|
STIPredicateExpander(const PredicateExpander &) = delete;
|
|
|
|
STIPredicateExpander &operator=(const PredicateExpander &) = delete;
|
|
|
|
|
|
|
|
void expandHeader(raw_ostream &OS, const STIPredicateFunction &Fn);
|
|
|
|
void expandPrologue(raw_ostream &OS, const STIPredicateFunction &Fn);
|
|
|
|
void expandOpcodeGroup(raw_ostream &OS, const OpcodeGroup &Group,
|
|
|
|
bool ShouldUpdateOpcodeMask);
|
|
|
|
void expandBody(raw_ostream &OS, const STIPredicateFunction &Fn);
|
|
|
|
void expandEpilogue(raw_ostream &OS, const STIPredicateFunction &Fn);
|
|
|
|
|
|
|
|
public:
|
|
|
|
STIPredicateExpander(StringRef Target)
|
|
|
|
: PredicateExpander(Target), ClassPrefix(), ExpandDefinition(false) {}
|
|
|
|
|
|
|
|
bool shouldExpandDefinition() const { return ExpandDefinition; }
|
|
|
|
StringRef getClassPrefix() const { return ClassPrefix; }
|
|
|
|
void setClassPrefix(StringRef S) { ClassPrefix = S; }
|
|
|
|
void setExpandDefinition(bool Value) { ExpandDefinition = Value; }
|
|
|
|
|
|
|
|
void expandSTIPredicate(raw_ostream &OS, const STIPredicateFunction &Fn);
|
|
|
|
};
|
|
|
|
|
2018-05-25 17:55:37 +02:00
|
|
|
} // namespace llvm
|
|
|
|
|
|
|
|
#endif
|