2016-07-27 22:31:55 +08:00
|
|
|
//===- llvm/CodeGen/GlobalISel/InstructionSelect.cpp - InstructionSelect ---==//
|
|
|
|
//
|
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
|
2016-07-27 22:31:55 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \file
|
|
|
|
/// This file implements the InstructionSelect class.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/GlobalISel/InstructionSelect.h"
|
|
|
|
#include "llvm/ADT/PostOrderIterator.h"
|
|
|
|
#include "llvm/ADT/Twine.h"
|
|
|
|
#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
|
2016-10-15 06:18:18 +08:00
|
|
|
#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
|
2017-02-24 05:05:42 +08:00
|
|
|
#include "llvm/CodeGen/GlobalISel/Utils.h"
|
|
|
|
#include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
|
2016-07-27 22:31:55 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2017-11-17 09:07:10 +08:00
|
|
|
#include "llvm/CodeGen/TargetLowering.h"
|
2016-08-27 10:38:24 +08:00
|
|
|
#include "llvm/CodeGen/TargetPassConfig.h"
|
2017-11-17 09:07:10 +08:00
|
|
|
#include "llvm/CodeGen/TargetSubtargetInfo.h"
|
[globalisel][tablegen] Generate rule coverage and use it to identify untested rules
Summary:
This patch adds a LLVM_ENABLE_GISEL_COV which, like LLVM_ENABLE_DAGISEL_COV,
causes TableGen to instrument the generated table to collect rule coverage
information. However, LLVM_ENABLE_GISEL_COV goes a bit further than
LLVM_ENABLE_DAGISEL_COV. The information is written to files
(${CMAKE_BINARY_DIR}/gisel-coverage-* by default). These files can then be
concatenated into ${LLVM_GISEL_COV_PREFIX}-all after which TableGen will
read this information and use it to emit warnings about untested rules.
This technique could also be used by SelectionDAG and can be further
extended to detect hot rules and give them priority over colder rules.
Usage:
* Enable LLVM_ENABLE_GISEL_COV in CMake
* Build the compiler and run some tests
* cat gisel-coverage-[0-9]* > gisel-coverage-all
* Delete lib/Target/*/*GenGlobalISel.inc*
* Build the compiler
Known issues:
* ${LLVM_GISEL_COV_PREFIX}-all must be generated as a manual
step due to a lack of a portable 'cat' command. It should be the
concatenation of all ${LLVM_GISEL_COV_PREFIX}-[0-9]* files.
* There's no mechanism to discard coverage information when the ruleset
changes
Depends on D39742
Reviewers: ab, qcolombet, t.p.northover, aditya_nandakumar, rovka
Reviewed By: rovka
Subscribers: vsk, arsenm, nhaehnle, mgorny, kristof.beyls, javed.absar, igorb, llvm-commits
Differential Revision: https://reviews.llvm.org/D39747
llvm-svn: 318356
2017-11-16 08:46:35 +08:00
|
|
|
#include "llvm/Config/config.h"
|
2017-02-25 05:21:38 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
2016-07-27 22:31:55 +08:00
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
[globalisel][tablegen] Generate rule coverage and use it to identify untested rules
Summary:
This patch adds a LLVM_ENABLE_GISEL_COV which, like LLVM_ENABLE_DAGISEL_COV,
causes TableGen to instrument the generated table to collect rule coverage
information. However, LLVM_ENABLE_GISEL_COV goes a bit further than
LLVM_ENABLE_DAGISEL_COV. The information is written to files
(${CMAKE_BINARY_DIR}/gisel-coverage-* by default). These files can then be
concatenated into ${LLVM_GISEL_COV_PREFIX}-all after which TableGen will
read this information and use it to emit warnings about untested rules.
This technique could also be used by SelectionDAG and can be further
extended to detect hot rules and give them priority over colder rules.
Usage:
* Enable LLVM_ENABLE_GISEL_COV in CMake
* Build the compiler and run some tests
* cat gisel-coverage-[0-9]* > gisel-coverage-all
* Delete lib/Target/*/*GenGlobalISel.inc*
* Build the compiler
Known issues:
* ${LLVM_GISEL_COV_PREFIX}-all must be generated as a manual
step due to a lack of a portable 'cat' command. It should be the
concatenation of all ${LLVM_GISEL_COV_PREFIX}-[0-9]* files.
* There's no mechanism to discard coverage information when the ruleset
changes
Depends on D39742
Reviewers: ab, qcolombet, t.p.northover, aditya_nandakumar, rovka
Reviewed By: rovka
Subscribers: vsk, arsenm, nhaehnle, mgorny, kristof.beyls, javed.absar, igorb, llvm-commits
Differential Revision: https://reviews.llvm.org/D39747
llvm-svn: 318356
2017-11-16 08:46:35 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2016-07-27 22:31:55 +08:00
|
|
|
|
|
|
|
#define DEBUG_TYPE "instruction-select"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
[globalisel][tablegen] Generate rule coverage and use it to identify untested rules
Summary:
This patch adds a LLVM_ENABLE_GISEL_COV which, like LLVM_ENABLE_DAGISEL_COV,
causes TableGen to instrument the generated table to collect rule coverage
information. However, LLVM_ENABLE_GISEL_COV goes a bit further than
LLVM_ENABLE_DAGISEL_COV. The information is written to files
(${CMAKE_BINARY_DIR}/gisel-coverage-* by default). These files can then be
concatenated into ${LLVM_GISEL_COV_PREFIX}-all after which TableGen will
read this information and use it to emit warnings about untested rules.
This technique could also be used by SelectionDAG and can be further
extended to detect hot rules and give them priority over colder rules.
Usage:
* Enable LLVM_ENABLE_GISEL_COV in CMake
* Build the compiler and run some tests
* cat gisel-coverage-[0-9]* > gisel-coverage-all
* Delete lib/Target/*/*GenGlobalISel.inc*
* Build the compiler
Known issues:
* ${LLVM_GISEL_COV_PREFIX}-all must be generated as a manual
step due to a lack of a portable 'cat' command. It should be the
concatenation of all ${LLVM_GISEL_COV_PREFIX}-[0-9]* files.
* There's no mechanism to discard coverage information when the ruleset
changes
Depends on D39742
Reviewers: ab, qcolombet, t.p.northover, aditya_nandakumar, rovka
Reviewed By: rovka
Subscribers: vsk, arsenm, nhaehnle, mgorny, kristof.beyls, javed.absar, igorb, llvm-commits
Differential Revision: https://reviews.llvm.org/D39747
llvm-svn: 318356
2017-11-16 08:46:35 +08:00
|
|
|
#ifdef LLVM_GISEL_COV_PREFIX
|
|
|
|
static cl::opt<std::string>
|
|
|
|
CoveragePrefix("gisel-coverage-prefix", cl::init(LLVM_GISEL_COV_PREFIX),
|
|
|
|
cl::desc("Record GlobalISel rule coverage files of this "
|
|
|
|
"prefix if instrumentation was generated"));
|
|
|
|
#else
|
|
|
|
static const std::string CoveragePrefix = "";
|
|
|
|
#endif
|
|
|
|
|
2016-07-27 22:31:55 +08:00
|
|
|
char InstructionSelect::ID = 0;
|
2016-08-27 10:38:24 +08:00
|
|
|
INITIALIZE_PASS_BEGIN(InstructionSelect, DEBUG_TYPE,
|
|
|
|
"Select target instructions out of generic instructions",
|
|
|
|
false, false)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)
|
|
|
|
INITIALIZE_PASS_END(InstructionSelect, DEBUG_TYPE,
|
|
|
|
"Select target instructions out of generic instructions",
|
|
|
|
false, false)
|
2016-07-27 22:31:55 +08:00
|
|
|
|
|
|
|
InstructionSelect::InstructionSelect() : MachineFunctionPass(ID) {
|
|
|
|
initializeInstructionSelectPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
2016-08-27 10:38:24 +08:00
|
|
|
void InstructionSelect::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.addRequired<TargetPassConfig>();
|
2018-07-13 08:08:38 +08:00
|
|
|
getSelectionDAGFallbackAnalysisUsage(AU);
|
2016-08-27 10:38:24 +08:00
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
|
2016-07-27 22:31:55 +08:00
|
|
|
bool InstructionSelect::runOnMachineFunction(MachineFunction &MF) {
|
2016-08-27 08:18:24 +08:00
|
|
|
// If the ISel pipeline failed, do not bother running that pass.
|
|
|
|
if (MF.getProperties().hasProperty(
|
|
|
|
MachineFunctionProperties::Property::FailedISel))
|
|
|
|
return false;
|
|
|
|
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "Selecting function: " << MF.getName() << '\n');
|
2016-07-27 22:31:55 +08:00
|
|
|
|
2016-08-27 10:38:24 +08:00
|
|
|
const TargetPassConfig &TPC = getAnalysis<TargetPassConfig>();
|
2016-07-27 22:31:55 +08:00
|
|
|
const InstructionSelector *ISel = MF.getSubtarget().getInstructionSelector();
|
[globalisel][tablegen] Generate rule coverage and use it to identify untested rules
Summary:
This patch adds a LLVM_ENABLE_GISEL_COV which, like LLVM_ENABLE_DAGISEL_COV,
causes TableGen to instrument the generated table to collect rule coverage
information. However, LLVM_ENABLE_GISEL_COV goes a bit further than
LLVM_ENABLE_DAGISEL_COV. The information is written to files
(${CMAKE_BINARY_DIR}/gisel-coverage-* by default). These files can then be
concatenated into ${LLVM_GISEL_COV_PREFIX}-all after which TableGen will
read this information and use it to emit warnings about untested rules.
This technique could also be used by SelectionDAG and can be further
extended to detect hot rules and give them priority over colder rules.
Usage:
* Enable LLVM_ENABLE_GISEL_COV in CMake
* Build the compiler and run some tests
* cat gisel-coverage-[0-9]* > gisel-coverage-all
* Delete lib/Target/*/*GenGlobalISel.inc*
* Build the compiler
Known issues:
* ${LLVM_GISEL_COV_PREFIX}-all must be generated as a manual
step due to a lack of a portable 'cat' command. It should be the
concatenation of all ${LLVM_GISEL_COV_PREFIX}-[0-9]* files.
* There's no mechanism to discard coverage information when the ruleset
changes
Depends on D39742
Reviewers: ab, qcolombet, t.p.northover, aditya_nandakumar, rovka
Reviewed By: rovka
Subscribers: vsk, arsenm, nhaehnle, mgorny, kristof.beyls, javed.absar, igorb, llvm-commits
Differential Revision: https://reviews.llvm.org/D39747
llvm-svn: 318356
2017-11-16 08:46:35 +08:00
|
|
|
CodeGenCoverage CoverageInfo;
|
2016-07-27 22:31:55 +08:00
|
|
|
assert(ISel && "Cannot work without InstructionSelector");
|
|
|
|
|
2017-02-24 05:05:42 +08:00
|
|
|
// An optimization remark emitter. Used to report failures.
|
|
|
|
MachineOptimizationRemarkEmitter MORE(MF, /*MBFI=*/nullptr);
|
|
|
|
|
2017-05-06 06:04:05 +08:00
|
|
|
// FIXME: There are many other MF/MFI fields we need to initialize.
|
2016-07-27 22:31:55 +08:00
|
|
|
|
2018-05-24 05:12:02 +08:00
|
|
|
MachineRegisterInfo &MRI = MF.getRegInfo();
|
2016-07-27 22:31:55 +08:00
|
|
|
#ifndef NDEBUG
|
2016-08-02 23:10:32 +08:00
|
|
|
// Check that our input is fully legal: we require the function to have the
|
|
|
|
// Legalized property, so it should be.
|
[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
2018-03-01 08:27:48 +08:00
|
|
|
// 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;
|
|
|
|
}
|
2016-07-27 22:31:55 +08:00
|
|
|
// 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.
|
|
|
|
const size_t NumBlocks = MF.size();
|
2019-03-16 09:02:10 +08:00
|
|
|
#endif
|
2016-07-27 22:31:55 +08:00
|
|
|
|
|
|
|
for (MachineBasicBlock *MBB : post_order(&MF)) {
|
2016-11-09 03:27:10 +08:00
|
|
|
if (MBB->empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Select instructions in reverse block order. We permit erasing so have
|
|
|
|
// to resort to manually iterating and recognizing the begin (rend) case.
|
|
|
|
bool ReachedBegin = false;
|
|
|
|
for (auto MII = std::prev(MBB->end()), Begin = MBB->begin();
|
|
|
|
!ReachedBegin;) {
|
2016-11-09 06:03:23 +08:00
|
|
|
#ifndef NDEBUG
|
2016-11-09 03:27:10 +08:00
|
|
|
// Keep track of the insertion range for debug printing.
|
|
|
|
const auto AfterIt = std::next(MII);
|
2016-11-09 06:03:23 +08:00
|
|
|
#endif
|
2016-11-09 03:27:10 +08:00
|
|
|
// Select this instruction.
|
|
|
|
MachineInstr &MI = *MII;
|
|
|
|
|
|
|
|
// And have our iterator point to the next instruction, if there is one.
|
|
|
|
if (MII == Begin)
|
|
|
|
ReachedBegin = true;
|
|
|
|
else
|
|
|
|
--MII;
|
|
|
|
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "Selecting: \n " << MI);
|
2016-11-09 03:27:10 +08:00
|
|
|
|
2017-03-20 00:13:00 +08:00
|
|
|
// We could have folded this instruction away already, making it dead.
|
|
|
|
// If so, erase it.
|
|
|
|
if (isTriviallyDead(MI, MRI)) {
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "Is dead; erasing.\n");
|
2017-03-22 07:42:54 +08:00
|
|
|
MI.eraseFromParentAndMarkDBGValuesForRemoval();
|
2017-03-20 00:13:00 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
[globalisel][tablegen] Generate rule coverage and use it to identify untested rules
Summary:
This patch adds a LLVM_ENABLE_GISEL_COV which, like LLVM_ENABLE_DAGISEL_COV,
causes TableGen to instrument the generated table to collect rule coverage
information. However, LLVM_ENABLE_GISEL_COV goes a bit further than
LLVM_ENABLE_DAGISEL_COV. The information is written to files
(${CMAKE_BINARY_DIR}/gisel-coverage-* by default). These files can then be
concatenated into ${LLVM_GISEL_COV_PREFIX}-all after which TableGen will
read this information and use it to emit warnings about untested rules.
This technique could also be used by SelectionDAG and can be further
extended to detect hot rules and give them priority over colder rules.
Usage:
* Enable LLVM_ENABLE_GISEL_COV in CMake
* Build the compiler and run some tests
* cat gisel-coverage-[0-9]* > gisel-coverage-all
* Delete lib/Target/*/*GenGlobalISel.inc*
* Build the compiler
Known issues:
* ${LLVM_GISEL_COV_PREFIX}-all must be generated as a manual
step due to a lack of a portable 'cat' command. It should be the
concatenation of all ${LLVM_GISEL_COV_PREFIX}-[0-9]* files.
* There's no mechanism to discard coverage information when the ruleset
changes
Depends on D39742
Reviewers: ab, qcolombet, t.p.northover, aditya_nandakumar, rovka
Reviewed By: rovka
Subscribers: vsk, arsenm, nhaehnle, mgorny, kristof.beyls, javed.absar, igorb, llvm-commits
Differential Revision: https://reviews.llvm.org/D39747
llvm-svn: 318356
2017-11-16 08:46:35 +08:00
|
|
|
if (!ISel->select(MI, CoverageInfo)) {
|
2017-02-24 05:05:42 +08:00
|
|
|
// FIXME: It would be nice to dump all inserted instructions. It's
|
|
|
|
// not obvious how, esp. considering select() can insert after MI.
|
|
|
|
reportGISelFailure(MF, TPC, MORE, "gisel-select", "cannot select", MI);
|
2017-02-24 03:17:24 +08:00
|
|
|
return false;
|
2016-08-27 10:38:24 +08:00
|
|
|
}
|
2016-11-09 03:27:13 +08:00
|
|
|
|
|
|
|
// Dump the range of instructions that MI expanded into.
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG({
|
2016-11-09 03:27:13 +08:00
|
|
|
auto InsertedBegin = ReachedBegin ? MBB->begin() : std::next(MII);
|
|
|
|
dbgs() << "Into:\n";
|
|
|
|
for (auto &InsertedMI : make_range(InsertedBegin, AfterIt))
|
|
|
|
dbgs() << " " << InsertedMI;
|
|
|
|
dbgs() << '\n';
|
|
|
|
});
|
2016-07-27 22:31:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-24 09:35:26 +08:00
|
|
|
for (MachineBasicBlock &MBB : MF) {
|
|
|
|
if (MBB.empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Try to find redundant copies b/w vregs of the same register class.
|
|
|
|
bool ReachedBegin = false;
|
|
|
|
for (auto MII = std::prev(MBB.end()), Begin = MBB.begin(); !ReachedBegin;) {
|
|
|
|
// Select this instruction.
|
|
|
|
MachineInstr &MI = *MII;
|
|
|
|
|
|
|
|
// And have our iterator point to the next instruction, if there is one.
|
|
|
|
if (MII == Begin)
|
|
|
|
ReachedBegin = true;
|
|
|
|
else
|
|
|
|
--MII;
|
|
|
|
if (MI.getOpcode() != TargetOpcode::COPY)
|
|
|
|
continue;
|
|
|
|
unsigned SrcReg = MI.getOperand(1).getReg();
|
|
|
|
unsigned DstReg = MI.getOperand(0).getReg();
|
|
|
|
if (TargetRegisterInfo::isVirtualRegister(SrcReg) &&
|
|
|
|
TargetRegisterInfo::isVirtualRegister(DstReg)) {
|
|
|
|
auto SrcRC = MRI.getRegClass(SrcReg);
|
|
|
|
auto DstRC = MRI.getRegClass(DstReg);
|
|
|
|
if (SrcRC == DstRC) {
|
|
|
|
MRI.replaceRegWith(DstReg, SrcReg);
|
|
|
|
MI.eraseFromParentAndMarkDBGValuesForRemoval();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-16 09:02:10 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
|
2016-11-09 04:39:03 +08:00
|
|
|
// Now that selection is complete, there are no more generic vregs. Verify
|
|
|
|
// that the size of the now-constrained vreg is unchanged and that it has a
|
|
|
|
// register class.
|
2018-05-24 05:12:02 +08:00
|
|
|
for (unsigned I = 0, E = MRI.getNumVirtRegs(); I != E; ++I) {
|
|
|
|
unsigned VReg = TargetRegisterInfo::index2VirtReg(I);
|
|
|
|
|
2017-01-31 03:12:50 +08:00
|
|
|
MachineInstr *MI = nullptr;
|
2017-01-31 04:52:37 +08:00
|
|
|
if (!MRI.def_empty(VReg))
|
2017-01-31 03:12:50 +08:00
|
|
|
MI = &*MRI.def_instr_begin(VReg);
|
2017-01-31 04:52:37 +08:00
|
|
|
else if (!MRI.use_empty(VReg))
|
2017-01-31 03:12:50 +08:00
|
|
|
MI = &*MRI.use_instr_begin(VReg);
|
2018-05-24 05:12:02 +08:00
|
|
|
if (!MI)
|
|
|
|
continue;
|
2017-01-31 03:12:50 +08:00
|
|
|
|
2018-05-24 05:12:02 +08:00
|
|
|
const TargetRegisterClass *RC = MRI.getRegClassOrNull(VReg);
|
|
|
|
if (!RC) {
|
2017-02-24 05:05:42 +08:00
|
|
|
reportGISelFailure(MF, TPC, MORE, "gisel-select",
|
|
|
|
"VReg has no regclass after selection", *MI);
|
2017-02-24 03:17:24 +08:00
|
|
|
return false;
|
2018-05-24 05:12:02 +08:00
|
|
|
}
|
2016-11-09 04:39:03 +08:00
|
|
|
|
2018-05-24 05:12:02 +08:00
|
|
|
const LLT Ty = MRI.getType(VReg);
|
|
|
|
if (Ty.isValid() && Ty.getSizeInBits() > TRI.getRegSizeInBits(*RC)) {
|
|
|
|
reportGISelFailure(
|
|
|
|
MF, TPC, MORE, "gisel-select",
|
|
|
|
"VReg's low-level type and register class have different sizes", *MI);
|
2017-02-24 03:17:24 +08:00
|
|
|
return false;
|
2016-11-09 04:39:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-24 03:17:24 +08:00
|
|
|
if (MF.size() != NumBlocks) {
|
2017-02-24 05:05:42 +08:00
|
|
|
MachineOptimizationRemarkMissed R("gisel-select", "GISelFailure",
|
2017-12-16 06:22:58 +08:00
|
|
|
MF.getFunction().getSubprogram(),
|
2017-02-24 08:34:44 +08:00
|
|
|
/*MBB=*/nullptr);
|
2017-02-24 05:05:42 +08:00
|
|
|
R << "inserting blocks is not supported yet";
|
|
|
|
reportGISelFailure(MF, TPC, MORE, R);
|
2016-08-27 10:38:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
2019-03-16 09:02:10 +08:00
|
|
|
#endif
|
2017-05-06 06:04:05 +08:00
|
|
|
auto &TLI = *MF.getSubtarget().getTargetLowering();
|
|
|
|
TLI.finalizeLowering(MF);
|
|
|
|
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG({
|
2018-04-27 04:22:17 +08:00
|
|
|
dbgs() << "Rules covered by selecting function: " << MF.getName() << ":";
|
|
|
|
for (auto RuleID : CoverageInfo.covered())
|
|
|
|
dbgs() << " id" << RuleID;
|
|
|
|
dbgs() << "\n\n";
|
|
|
|
});
|
[globalisel][tablegen] Generate rule coverage and use it to identify untested rules
Summary:
This patch adds a LLVM_ENABLE_GISEL_COV which, like LLVM_ENABLE_DAGISEL_COV,
causes TableGen to instrument the generated table to collect rule coverage
information. However, LLVM_ENABLE_GISEL_COV goes a bit further than
LLVM_ENABLE_DAGISEL_COV. The information is written to files
(${CMAKE_BINARY_DIR}/gisel-coverage-* by default). These files can then be
concatenated into ${LLVM_GISEL_COV_PREFIX}-all after which TableGen will
read this information and use it to emit warnings about untested rules.
This technique could also be used by SelectionDAG and can be further
extended to detect hot rules and give them priority over colder rules.
Usage:
* Enable LLVM_ENABLE_GISEL_COV in CMake
* Build the compiler and run some tests
* cat gisel-coverage-[0-9]* > gisel-coverage-all
* Delete lib/Target/*/*GenGlobalISel.inc*
* Build the compiler
Known issues:
* ${LLVM_GISEL_COV_PREFIX}-all must be generated as a manual
step due to a lack of a portable 'cat' command. It should be the
concatenation of all ${LLVM_GISEL_COV_PREFIX}-[0-9]* files.
* There's no mechanism to discard coverage information when the ruleset
changes
Depends on D39742
Reviewers: ab, qcolombet, t.p.northover, aditya_nandakumar, rovka
Reviewed By: rovka
Subscribers: vsk, arsenm, nhaehnle, mgorny, kristof.beyls, javed.absar, igorb, llvm-commits
Differential Revision: https://reviews.llvm.org/D39747
llvm-svn: 318356
2017-11-16 08:46:35 +08:00
|
|
|
CoverageInfo.emit(CoveragePrefix,
|
|
|
|
MF.getSubtarget()
|
|
|
|
.getTargetLowering()
|
|
|
|
->getTargetMachine()
|
|
|
|
.getTarget()
|
|
|
|
.getBackendName());
|
|
|
|
|
[GlobalISel] Print/Parse FailedISel MachineFunction property
FailedISel MachineFunction property is part of the CodeGen pipeline
state as much as every other property, notably, Legalized,
RegBankSelected, and Selected. Let's make that part of the state also
serializable / de-serializable, so if GlobalISel aborts on some of the
functions of a large module, but not the others, it could be easily seen
and the state of the pipeline could be maintained through llc's
invocations with -stop-after / -start-after.
To make MIR printable and generally to not to break it too much too
soon, this patch also defers cleaning up the vreg -> LLT map until
ResetMachineFunctionPass.
To make MIR with FailedISel: true also machine verifiable, machine
verifier is changed so it treats a MIR-module as non-regbankselected and
non-selected if there is FailedISel property set.
Reviewers: qcolombet, ab
Reviewed By: dsanders
Subscribers: javed.absar, rovka, kristof.beyls, llvm-commits
Differential Revision: https://reviews.llvm.org/D42877
llvm-svn: 326343
2018-03-01 01:55:45 +08:00
|
|
|
// If we successfully selected the function nothing is going to use the vreg
|
|
|
|
// types after us (otherwise MIRPrinter would need them). Make sure the types
|
|
|
|
// disappear.
|
2018-05-24 05:12:02 +08:00
|
|
|
MRI.clearVirtRegTypes();
|
[GlobalISel] Print/Parse FailedISel MachineFunction property
FailedISel MachineFunction property is part of the CodeGen pipeline
state as much as every other property, notably, Legalized,
RegBankSelected, and Selected. Let's make that part of the state also
serializable / de-serializable, so if GlobalISel aborts on some of the
functions of a large module, but not the others, it could be easily seen
and the state of the pipeline could be maintained through llc's
invocations with -stop-after / -start-after.
To make MIR printable and generally to not to break it too much too
soon, this patch also defers cleaning up the vreg -> LLT map until
ResetMachineFunctionPass.
To make MIR with FailedISel: true also machine verifiable, machine
verifier is changed so it treats a MIR-module as non-regbankselected and
non-selected if there is FailedISel property set.
Reviewers: qcolombet, ab
Reviewed By: dsanders
Subscribers: javed.absar, rovka, kristof.beyls, llvm-commits
Differential Revision: https://reviews.llvm.org/D42877
llvm-svn: 326343
2018-03-01 01:55:45 +08:00
|
|
|
|
2016-07-27 22:31:55 +08:00
|
|
|
// FIXME: Should we accurately track changes?
|
|
|
|
return true;
|
|
|
|
}
|