2019-02-21 16:48:10 +01:00
|
|
|
//===- SubtargetFeatureInfo.h - Helpers for subtarget features --*- C++ -*-===//
|
2016-11-15 10:51:02 +01:00
|
|
|
//
|
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
|
2016-11-15 10:51:02 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H
|
|
|
|
#define LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H
|
|
|
|
|
|
|
|
#include "llvm/TableGen/Record.h"
|
|
|
|
#include <map>
|
Check that emitted instructions meet their predicates on all targets except ARM, Mips, and X86.
Summary:
* ARM is omitted from this patch because this check appears to expose bugs in this target.
* Mips is omitted from this patch because this check either detects bugs or deliberate
emission of instructions that don't satisfy their predicates. One deliberate
use is the SYNC instruction where the version with an operand is correctly
defined as requiring MIPS32 while the version without an operand is defined
as an alias of 'SYNC 0' and requires MIPS2.
* X86 is omitted from this patch because it doesn't use the tablegen-erated
MCCodeEmitter infrastructure.
Patches for ARM and Mips will follow.
Depends on D25617
Reviewers: tstellarAMD, jmolloy
Subscribers: wdng, jmolloy, aemerson, rengolin, arsenm, jyknight, nemanjai, nhaehnle, tstellarAMD, llvm-commits
Differential Revision: https://reviews.llvm.org/D25618
llvm-svn: 287439
2016-11-19 14:05:44 +01:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2016-11-15 10:51:02 +01:00
|
|
|
|
|
|
|
namespace llvm {
|
2017-04-29 19:30:09 +02:00
|
|
|
struct SubtargetFeatureInfo;
|
|
|
|
using SubtargetFeatureInfoMap = std::map<Record *, SubtargetFeatureInfo, LessRecordByID>;
|
|
|
|
|
2016-11-15 10:51:02 +01:00
|
|
|
/// Helper class for storing information on a subtarget feature which
|
|
|
|
/// participates in instruction matching.
|
|
|
|
struct SubtargetFeatureInfo {
|
2018-05-01 17:54:18 +02:00
|
|
|
/// The predicate record for this feature.
|
2016-11-15 10:51:02 +01:00
|
|
|
Record *TheDef;
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// An unique index assigned to represent this feature.
|
2016-11-15 10:51:02 +01:00
|
|
|
uint64_t Index;
|
|
|
|
|
|
|
|
SubtargetFeatureInfo(Record *D, uint64_t Idx) : TheDef(D), Index(Idx) {}
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// The name of the enumerated constant identifying this feature.
|
2016-12-04 06:48:16 +01:00
|
|
|
std::string getEnumName() const {
|
|
|
|
return "Feature_" + TheDef->getName().str();
|
|
|
|
}
|
2016-11-15 10:51:02 +01:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// The name of the enumerated constant identifying the bitnumber for
|
[globalisel][tablegen] Import SelectionDAG's rule predicates and support the equivalent in GIRule.
Summary:
The SelectionDAG importer now imports rules with Predicate's attached via
Requires, PredicateControl, etc. These predicates are implemented as
bitset's to allow multiple predicates to be tested together. However,
unlike the MC layer subtarget features, each target only pays for it's own
predicates (e.g. AArch64 doesn't have 192 feature bits just because X86
needs a lot).
Both AArch64 and X86 derive at least one predicate from the MachineFunction
or Function so they must re-initialize AvailableFeatures before each
function. They also declare locals in <Target>InstructionSelector so that
computeAvailableFeatures() can use the code from SelectionDAG without
modification.
Reviewers: rovka, qcolombet, aditya_nandakumar, t.p.northover, ab
Reviewed By: rovka
Subscribers: aemerson, rengolin, dberris, kristof.beyls, llvm-commits, igorb
Differential Revision: https://reviews.llvm.org/D31418
llvm-svn: 300993
2017-04-21 17:59:56 +02:00
|
|
|
/// this feature.
|
|
|
|
std::string getEnumBitName() const {
|
|
|
|
return "Feature_" + TheDef->getName().str() + "Bit";
|
|
|
|
}
|
|
|
|
|
2017-04-29 19:30:09 +02:00
|
|
|
bool mustRecomputePerFunction() const {
|
|
|
|
return TheDef->getValueAsBit("RecomputePerFunction");
|
|
|
|
}
|
|
|
|
|
2016-11-15 10:51:02 +01:00
|
|
|
void dump() const;
|
|
|
|
static std::vector<std::pair<Record *, SubtargetFeatureInfo>>
|
|
|
|
getAll(const RecordKeeper &Records);
|
|
|
|
|
[globalisel][tablegen] Import SelectionDAG's rule predicates and support the equivalent in GIRule.
Summary:
The SelectionDAG importer now imports rules with Predicate's attached via
Requires, PredicateControl, etc. These predicates are implemented as
bitset's to allow multiple predicates to be tested together. However,
unlike the MC layer subtarget features, each target only pays for it's own
predicates (e.g. AArch64 doesn't have 192 feature bits just because X86
needs a lot).
Both AArch64 and X86 derive at least one predicate from the MachineFunction
or Function so they must re-initialize AvailableFeatures before each
function. They also declare locals in <Target>InstructionSelector so that
computeAvailableFeatures() can use the code from SelectionDAG without
modification.
Reviewers: rovka, qcolombet, aditya_nandakumar, t.p.northover, ab
Reviewed By: rovka
Subscribers: aemerson, rengolin, dberris, kristof.beyls, llvm-commits, igorb
Differential Revision: https://reviews.llvm.org/D31418
llvm-svn: 300993
2017-04-21 17:59:56 +02:00
|
|
|
/// Emit the subtarget feature flag definitions.
|
|
|
|
///
|
|
|
|
/// This version emits the bit index for the feature and can therefore support
|
|
|
|
/// more than 64 feature bits.
|
2017-04-29 19:30:09 +02:00
|
|
|
static void
|
|
|
|
emitSubtargetFeatureBitEnumeration(SubtargetFeatureInfoMap &SubtargetFeatures,
|
|
|
|
raw_ostream &OS);
|
[globalisel][tablegen] Import SelectionDAG's rule predicates and support the equivalent in GIRule.
Summary:
The SelectionDAG importer now imports rules with Predicate's attached via
Requires, PredicateControl, etc. These predicates are implemented as
bitset's to allow multiple predicates to be tested together. However,
unlike the MC layer subtarget features, each target only pays for it's own
predicates (e.g. AArch64 doesn't have 192 feature bits just because X86
needs a lot).
Both AArch64 and X86 derive at least one predicate from the MachineFunction
or Function so they must re-initialize AvailableFeatures before each
function. They also declare locals in <Target>InstructionSelector so that
computeAvailableFeatures() can use the code from SelectionDAG without
modification.
Reviewers: rovka, qcolombet, aditya_nandakumar, t.p.northover, ab
Reviewed By: rovka
Subscribers: aemerson, rengolin, dberris, kristof.beyls, llvm-commits, igorb
Differential Revision: https://reviews.llvm.org/D31418
llvm-svn: 300993
2017-04-21 17:59:56 +02:00
|
|
|
|
2017-04-29 19:30:09 +02:00
|
|
|
static void emitNameTable(SubtargetFeatureInfoMap &SubtargetFeatures,
|
Check that emitted instructions meet their predicates on all targets except ARM, Mips, and X86.
Summary:
* ARM is omitted from this patch because this check appears to expose bugs in this target.
* Mips is omitted from this patch because this check either detects bugs or deliberate
emission of instructions that don't satisfy their predicates. One deliberate
use is the SYNC instruction where the version with an operand is correctly
defined as requiring MIPS32 while the version without an operand is defined
as an alias of 'SYNC 0' and requires MIPS2.
* X86 is omitted from this patch because it doesn't use the tablegen-erated
MCCodeEmitter infrastructure.
Patches for ARM and Mips will follow.
Depends on D25617
Reviewers: tstellarAMD, jmolloy
Subscribers: wdng, jmolloy, aemerson, rengolin, arsenm, jyknight, nemanjai, nhaehnle, tstellarAMD, llvm-commits
Differential Revision: https://reviews.llvm.org/D25618
llvm-svn: 287439
2016-11-19 14:05:44 +01:00
|
|
|
raw_ostream &OS);
|
|
|
|
|
2016-11-15 10:51:02 +01:00
|
|
|
/// Emit the function to compute the list of available features given a
|
|
|
|
/// subtarget.
|
|
|
|
///
|
[globalisel][tablegen] Import SelectionDAG's rule predicates and support the equivalent in GIRule.
Summary:
The SelectionDAG importer now imports rules with Predicate's attached via
Requires, PredicateControl, etc. These predicates are implemented as
bitset's to allow multiple predicates to be tested together. However,
unlike the MC layer subtarget features, each target only pays for it's own
predicates (e.g. AArch64 doesn't have 192 feature bits just because X86
needs a lot).
Both AArch64 and X86 derive at least one predicate from the MachineFunction
or Function so they must re-initialize AvailableFeatures before each
function. They also declare locals in <Target>InstructionSelector so that
computeAvailableFeatures() can use the code from SelectionDAG without
modification.
Reviewers: rovka, qcolombet, aditya_nandakumar, t.p.northover, ab
Reviewed By: rovka
Subscribers: aemerson, rengolin, dberris, kristof.beyls, llvm-commits, igorb
Differential Revision: https://reviews.llvm.org/D31418
llvm-svn: 300993
2017-04-21 17:59:56 +02:00
|
|
|
/// This version is used for subtarget features defined using Predicate<>
|
|
|
|
/// and supports more than 64 feature bits.
|
|
|
|
///
|
2016-11-15 10:51:02 +01:00
|
|
|
/// \param TargetName The name of the target as used in class prefixes (e.g.
|
|
|
|
/// <TargetName>Subtarget)
|
|
|
|
/// \param ClassName The name of the class (without the <Target> prefix)
|
|
|
|
/// that will contain the generated functions.
|
Check that emitted instructions meet their predicates on all targets except ARM, Mips, and X86.
Summary:
* ARM is omitted from this patch because this check appears to expose bugs in this target.
* Mips is omitted from this patch because this check either detects bugs or deliberate
emission of instructions that don't satisfy their predicates. One deliberate
use is the SYNC instruction where the version with an operand is correctly
defined as requiring MIPS32 while the version without an operand is defined
as an alias of 'SYNC 0' and requires MIPS2.
* X86 is omitted from this patch because it doesn't use the tablegen-erated
MCCodeEmitter infrastructure.
Patches for ARM and Mips will follow.
Depends on D25617
Reviewers: tstellarAMD, jmolloy
Subscribers: wdng, jmolloy, aemerson, rengolin, arsenm, jyknight, nemanjai, nhaehnle, tstellarAMD, llvm-commits
Differential Revision: https://reviews.llvm.org/D25618
llvm-svn: 287439
2016-11-19 14:05:44 +01:00
|
|
|
/// \param FuncName The name of the function to emit.
|
2016-11-15 10:51:02 +01:00
|
|
|
/// \param SubtargetFeatures A map of TableGen records to the
|
|
|
|
/// SubtargetFeatureInfo equivalent.
|
2017-04-29 19:30:09 +02:00
|
|
|
/// \param ExtraParams Additional arguments to the generated function.
|
|
|
|
static void
|
|
|
|
emitComputeAvailableFeatures(StringRef TargetName, StringRef ClassName,
|
|
|
|
StringRef FuncName,
|
|
|
|
SubtargetFeatureInfoMap &SubtargetFeatures,
|
|
|
|
raw_ostream &OS, StringRef ExtraParams = "");
|
[globalisel][tablegen] Import SelectionDAG's rule predicates and support the equivalent in GIRule.
Summary:
The SelectionDAG importer now imports rules with Predicate's attached via
Requires, PredicateControl, etc. These predicates are implemented as
bitset's to allow multiple predicates to be tested together. However,
unlike the MC layer subtarget features, each target only pays for it's own
predicates (e.g. AArch64 doesn't have 192 feature bits just because X86
needs a lot).
Both AArch64 and X86 derive at least one predicate from the MachineFunction
or Function so they must re-initialize AvailableFeatures before each
function. They also declare locals in <Target>InstructionSelector so that
computeAvailableFeatures() can use the code from SelectionDAG without
modification.
Reviewers: rovka, qcolombet, aditya_nandakumar, t.p.northover, ab
Reviewed By: rovka
Subscribers: aemerson, rengolin, dberris, kristof.beyls, llvm-commits, igorb
Differential Revision: https://reviews.llvm.org/D31418
llvm-svn: 300993
2017-04-21 17:59:56 +02:00
|
|
|
|
|
|
|
/// Emit the function to compute the list of available features given a
|
|
|
|
/// subtarget.
|
|
|
|
///
|
|
|
|
/// This version is used for subtarget features defined using
|
|
|
|
/// AssemblerPredicate<> and supports up to 64 feature bits.
|
|
|
|
///
|
|
|
|
/// \param TargetName The name of the target as used in class prefixes (e.g.
|
|
|
|
/// <TargetName>Subtarget)
|
|
|
|
/// \param ClassName The name of the class (without the <Target> prefix)
|
|
|
|
/// that will contain the generated functions.
|
|
|
|
/// \param FuncName The name of the function to emit.
|
|
|
|
/// \param SubtargetFeatures A map of TableGen records to the
|
|
|
|
/// SubtargetFeatureInfo equivalent.
|
|
|
|
static void emitComputeAssemblerAvailableFeatures(
|
|
|
|
StringRef TargetName, StringRef ClassName, StringRef FuncName,
|
2017-04-29 19:30:09 +02:00
|
|
|
SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS);
|
2016-11-15 10:51:02 +01:00
|
|
|
};
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif // LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H
|