1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 04:02:41 +01:00

[GlobalISel][AArch64] Adding -disable-gisel-legality-check CL option

Currently it's impossible to test InstructionSelect pass with MIR which
is considered illegal by the Legalizer in Assert builds. In early stages
of porting an existing backend from SelectionDAG ISel to GlobalISel,
however, we would have very basic CallLowering, Legalizer, and
RegBankSelect implementations, but rather functional Instruction Select
with quite a few patterns selectable due to the semi-automatic porting
process borrowing them from SelectionDAG ISel.

As we are trying to define legality as a property of being selectable by
the instruction selector, it would be nice to be able to easily check
what the selector can do in its current state w/o the legality check
provided by the Legalizer getting in the way.

It also seems beneficial to have a regression testing set up that would
not allow the selector to silently regress in its support of the MIR not
supported yet by the previous passes in the GlobalISel pipeline.

This commit adds -disable-gisel-legality-check command line option to
llc that disables those legality checks in RegBankSelect and
InstructionSelect passes.

It also adds quite a few MIR test cases for AArch64's Instruction
Selector. Every one of them would fail on the legality check at the
moment, but will select just fine if the check is disabled. Every test
MachineFunction is intended to exercise a specific selection rule and
that rule only, encoded in the MachineFunction's name by the rule's
number, ID, and index of its GIM_Try opcode in TableGen'erated
MatchTable (-optimize-match-table=false).

Reviewers: ab, dsanders, qcolombet, rovka

Reviewed By: bogner

Subscribers: kristof.beyls, volkan, aditya_nandakumar, aemerson,
rengolin, t.p.northover, javed.absar, llvm-commits

Differential Revision: https://reviews.llvm.org/D42886

llvm-svn: 326396
This commit is contained in:
Roman Tereshin 2018-03-01 00:27:48 +00:00
parent b59678d79c
commit 4dc6df117e
5 changed files with 4589 additions and 27 deletions

View File

@ -20,6 +20,7 @@
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/TargetOpcodes.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/LowLevelTypeImpl.h"
@ -31,6 +32,8 @@
namespace llvm {
extern cl::opt<bool> DisableGISelLegalityCheck;
class MachineInstr;
class MachineIRBuilder;
class MachineRegisterInfo;
@ -906,6 +909,12 @@ private:
LegalizeRuleSet RulesForOpcode[LastOp - FirstOp + 1];
};
#ifndef NDEBUG
/// Checks that MIR is fully legal, returns an illegal instruction if it's not,
/// nullptr otherwise
const MachineInstr *machineFunctionIsIllegal(const MachineFunction &MF);
#endif
} // end namespace llvm.
#endif // LLVM_CODEGEN_GLOBALISEL_LEGALIZERINFO_H

View File

@ -81,20 +81,14 @@ bool InstructionSelect::runOnMachineFunction(MachineFunction &MF) {
#ifndef NDEBUG
// Check that our input is fully legal: we require the function to have the
// Legalized property, so it should be.
// FIXME: This should be in the MachineVerifier, but it can't use the
// LegalizerInfo as it's currently in the separate GlobalISel library.
// The RegBankSelected property is already checked in the verifier. Note
// that it has the same layering problem, but we only use inline methods so
// end up not needing to link against the GlobalISel library.
if (const LegalizerInfo *MLI = MF.getSubtarget().getLegalizerInfo())
for (MachineBasicBlock &MBB : MF)
for (MachineInstr &MI : MBB)
if (isPreISelGenericOpcode(MI.getOpcode()) && !MLI->isLegal(MI, MRI)) {
reportGISelFailure(MF, TPC, MORE, "gisel-select",
"instruction is not legal", MI);
return false;
}
// FIXME: This should be in the MachineVerifier, as the RegBankSelected
// property check already is.
if (!DisableGISelLegalityCheck)
if (const MachineInstr *MI = machineFunctionIsIllegal(MF)) {
reportGISelFailure(MF, TPC, MORE, "gisel-select",
"instruction is not legal", *MI);
return false;
}
#endif
// FIXME: We could introduce new blocks and will need to fix the outer loop.
// Until then, keep track of the number of blocks to assert that we don't.

View File

@ -36,6 +36,11 @@ using namespace LegalizeActions;
#define DEBUG_TYPE "legalizer-info"
cl::opt<bool> llvm::DisableGISelLegalityCheck(
"disable-gisel-legality-check",
cl::desc("Don't verify that MIR is fully legal between GlobalISel passes"),
cl::Hidden);
raw_ostream &LegalityQuery::print(raw_ostream &OS) const {
OS << Opcode << ", {";
for (const auto &Type : Types) {
@ -495,3 +500,21 @@ LegalizerInfo::findVectorLegalAction(const InstrAspect &Aspect) const {
LLT::vector(NumElementsAndAction.first,
IntermediateType.getScalarSizeInBits())};
}
#ifndef NDEBUG
// FIXME: This should be in the MachineVerifier, but it can't use the
// LegalizerInfo as it's currently in the separate GlobalISel library.
// Note that RegBankSelected property already checked in the verifier
// has the same layering problem, but we only use inline methods so
// end up not needing to link against the GlobalISel library.
const MachineInstr *llvm::machineFunctionIsIllegal(const MachineFunction &MF) {
if (const LegalizerInfo *MLI = MF.getSubtarget().getLegalizerInfo()) {
const MachineRegisterInfo &MRI = MF.getRegInfo();
for (const MachineBasicBlock &MBB : MF)
for (const MachineInstr &MI : MBB)
if (isPreISelGenericOpcode(MI.getOpcode()) && !MLI->isLegal(MI, MRI))
return &MI;
}
return nullptr;
}
#endif

View File

@ -610,20 +610,13 @@ bool RegBankSelect::runOnMachineFunction(MachineFunction &MF) {
#ifndef NDEBUG
// Check that our input is fully legal: we require the function to have the
// Legalized property, so it should be.
// FIXME: This should be in the MachineVerifier, but it can't use the
// LegalizerInfo as it's currently in the separate GlobalISel library.
const MachineRegisterInfo &MRI = MF.getRegInfo();
if (const LegalizerInfo *MLI = MF.getSubtarget().getLegalizerInfo()) {
for (MachineBasicBlock &MBB : MF) {
for (MachineInstr &MI : MBB) {
if (isPreISelGenericOpcode(MI.getOpcode()) && !MLI->isLegal(MI, MRI)) {
reportGISelFailure(MF, *TPC, *MORE, "gisel-regbankselect",
"instruction is not legal", MI);
return false;
}
}
// FIXME: This should be in the MachineVerifier.
if (!DisableGISelLegalityCheck)
if (const MachineInstr *MI = machineFunctionIsIllegal(MF)) {
reportGISelFailure(MF, *TPC, *MORE, "gisel-regbankselect",
"instruction is not legal", *MI);
return false;
}
}
#endif
// Walk the function and assign register banks to all operands.

File diff suppressed because it is too large Load Diff