2017-01-30 19:03:26 +00:00
|
|
|
///===- FastISelEmitter.cpp - Generate an instruction selector ------------===//
|
2008-08-13 20:19:35 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00: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
|
2008-08-13 20:19:35 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2008-09-30 20:48:29 +00:00
|
|
|
// This tablegen backend emits code for use by the "fast" instruction
|
|
|
|
// selection algorithm. See the comments at the top of
|
|
|
|
// lib/CodeGen/SelectionDAG/FastISel.cpp for background.
|
2008-08-13 20:19:35 +00:00
|
|
|
//
|
2008-09-30 20:48:29 +00:00
|
|
|
// This file scans through the target's tablegen instruction-info files
|
|
|
|
// and extracts instructions with obvious-looking patterns, and it emits
|
|
|
|
// code to look up these instructions by type and operator.
|
2008-08-13 20:19:35 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2024-03-25 09:40:35 +01:00
|
|
|
#include "Common/CodeGenDAGPatterns.h"
|
|
|
|
#include "Common/CodeGenInstruction.h"
|
|
|
|
#include "Common/CodeGenRegisters.h"
|
|
|
|
#include "Common/CodeGenTarget.h"
|
|
|
|
#include "Common/InfoByHwMode.h"
|
2014-10-01 22:44:01 +00:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2011-06-07 20:41:31 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2012-06-11 15:37:55 +00:00
|
|
|
#include "llvm/TableGen/Error.h"
|
|
|
|
#include "llvm/TableGen/Record.h"
|
|
|
|
#include "llvm/TableGen/TableGenBackend.h"
|
2023-11-11 12:14:24 -08:00
|
|
|
#include <set>
|
2016-05-27 14:27:24 +00:00
|
|
|
#include <utility>
|
2008-08-13 20:19:35 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2008-08-29 17:45:56 +00:00
|
|
|
/// InstructionMemo - This class holds additional information about an
|
|
|
|
/// instruction needed to emit code for it.
|
|
|
|
///
|
2012-06-11 15:37:55 +00:00
|
|
|
namespace {
|
2008-08-29 17:45:56 +00:00
|
|
|
struct InstructionMemo {
|
|
|
|
std::string Name;
|
|
|
|
const CodeGenRegisterClass *RC;
|
2010-05-24 14:48:12 +00:00
|
|
|
std::string SubRegNo;
|
2018-05-29 17:40:03 +00:00
|
|
|
std::vector<std::string> PhysRegs;
|
2014-11-14 21:05:45 +00:00
|
|
|
std::string PredicateCheck;
|
2018-05-29 17:40:03 +00:00
|
|
|
|
2018-08-28 11:10:27 +00:00
|
|
|
InstructionMemo(StringRef Name, const CodeGenRegisterClass *RC,
|
|
|
|
std::string SubRegNo, std::vector<std::string> PhysRegs,
|
|
|
|
std::string PredicateCheck)
|
|
|
|
: Name(Name), RC(RC), SubRegNo(std::move(SubRegNo)),
|
|
|
|
PhysRegs(std::move(PhysRegs)),
|
|
|
|
PredicateCheck(std::move(PredicateCheck)) {}
|
2018-05-29 18:34:42 +00:00
|
|
|
|
2018-05-29 17:40:03 +00:00
|
|
|
// Make sure we do not copy InstructionMemo.
|
|
|
|
InstructionMemo(const InstructionMemo &Other) = delete;
|
|
|
|
InstructionMemo(InstructionMemo &&Other) = default;
|
2008-08-29 17:45:56 +00:00
|
|
|
};
|
2012-06-11 15:37:55 +00:00
|
|
|
} // End anonymous namespace
|
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
/// ImmPredicateSet - This uniques predicates (represented as a string) and
|
|
|
|
/// gives them unique (small) integer ID's that start at 0.
|
2012-06-11 15:37:55 +00:00
|
|
|
namespace {
|
2011-04-18 06:22:33 +00:00
|
|
|
class ImmPredicateSet {
|
|
|
|
DenseMap<TreePattern *, unsigned> ImmIDs;
|
|
|
|
std::vector<TreePredicateFn> PredsByName;
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2024-02-09 09:27:04 +01:00
|
|
|
public:
|
2011-04-18 06:22:33 +00:00
|
|
|
unsigned getIDFor(TreePredicateFn Pred) {
|
|
|
|
unsigned &Entry = ImmIDs[Pred.getOrigPatFragRecord()];
|
|
|
|
if (Entry == 0) {
|
|
|
|
PredsByName.push_back(Pred);
|
|
|
|
Entry = PredsByName.size();
|
|
|
|
}
|
|
|
|
return Entry - 1;
|
|
|
|
}
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
const TreePredicateFn &getPredicate(unsigned i) {
|
|
|
|
assert(i < PredsByName.size());
|
|
|
|
return PredsByName[i];
|
|
|
|
}
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
typedef std::vector<TreePredicateFn>::const_iterator iterator;
|
|
|
|
iterator begin() const { return PredsByName.begin(); }
|
|
|
|
iterator end() const { return PredsByName.end(); }
|
|
|
|
};
|
2012-06-11 15:37:55 +00:00
|
|
|
} // End anonymous namespace
|
2008-08-29 17:45:56 +00:00
|
|
|
|
2008-08-19 18:06:12 +00:00
|
|
|
/// OperandsSignature - This class holds a description of a list of operand
|
|
|
|
/// types. It has utility methods for emitting text based on the operands.
|
|
|
|
///
|
2012-06-11 15:37:55 +00:00
|
|
|
namespace {
|
2008-08-13 20:19:35 +00:00
|
|
|
struct OperandsSignature {
|
2011-04-17 23:29:05 +00:00
|
|
|
class OpKind {
|
|
|
|
enum { OK_Reg, OK_FP, OK_Imm, OK_Invalid = -1 };
|
|
|
|
char Repr;
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2024-02-09 09:27:04 +01:00
|
|
|
public:
|
2011-04-17 23:29:05 +00:00
|
|
|
OpKind() : Repr(OK_Invalid) {}
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-17 23:29:05 +00:00
|
|
|
bool operator<(OpKind RHS) const { return Repr < RHS.Repr; }
|
2011-04-18 06:22:33 +00:00
|
|
|
bool operator==(OpKind RHS) const { return Repr == RHS.Repr; }
|
2011-04-17 23:29:05 +00:00
|
|
|
|
|
|
|
static OpKind getReg() {
|
|
|
|
OpKind K;
|
|
|
|
K.Repr = OK_Reg;
|
|
|
|
return K;
|
|
|
|
}
|
|
|
|
static OpKind getFP() {
|
|
|
|
OpKind K;
|
|
|
|
K.Repr = OK_FP;
|
|
|
|
return K;
|
|
|
|
}
|
2011-04-18 06:22:33 +00:00
|
|
|
static OpKind getImm(unsigned V) {
|
|
|
|
assert((unsigned)OK_Imm + V < 128 &&
|
|
|
|
"Too many integer predicates for the 'Repr' char");
|
|
|
|
OpKind K;
|
|
|
|
K.Repr = OK_Imm + V;
|
|
|
|
return K;
|
|
|
|
}
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-17 23:29:05 +00:00
|
|
|
bool isReg() const { return Repr == OK_Reg; }
|
|
|
|
bool isFP() const { return Repr == OK_FP; }
|
2011-04-18 06:22:33 +00:00
|
|
|
bool isImm() const { return Repr >= OK_Imm; }
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
unsigned getImmCode() const {
|
|
|
|
assert(isImm());
|
|
|
|
return Repr - OK_Imm;
|
|
|
|
}
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
void printManglingSuffix(raw_ostream &OS, ImmPredicateSet &ImmPredicates,
|
|
|
|
bool StripImmCodes) const {
|
2011-04-17 23:29:05 +00:00
|
|
|
if (isReg())
|
|
|
|
OS << 'r';
|
|
|
|
else if (isFP())
|
|
|
|
OS << 'f';
|
2011-04-18 06:22:33 +00:00
|
|
|
else {
|
2011-04-17 23:29:05 +00:00
|
|
|
OS << 'i';
|
2011-04-18 06:22:33 +00:00
|
|
|
if (!StripImmCodes)
|
|
|
|
if (unsigned Code = getImmCode())
|
|
|
|
OS << "_" << ImmPredicates.getPredicate(Code - 1).getFnName();
|
|
|
|
}
|
2011-04-17 23:29:05 +00:00
|
|
|
}
|
|
|
|
};
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-17 23:29:05 +00:00
|
|
|
SmallVector<OpKind, 3> Operands;
|
2008-08-13 20:19:35 +00:00
|
|
|
|
|
|
|
bool operator<(const OperandsSignature &O) const {
|
|
|
|
return Operands < O.Operands;
|
|
|
|
}
|
2011-04-18 06:22:33 +00:00
|
|
|
bool operator==(const OperandsSignature &O) const {
|
|
|
|
return Operands == O.Operands;
|
|
|
|
}
|
2008-08-13 20:19:35 +00:00
|
|
|
|
|
|
|
bool empty() const { return Operands.empty(); }
|
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
bool hasAnyImmediateCodes() const {
|
|
|
|
for (unsigned i = 0, e = Operands.size(); i != e; ++i)
|
|
|
|
if (Operands[i].isImm() && Operands[i].getImmCode() != 0)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
/// getWithoutImmCodes - Return a copy of this with any immediate codes forced
|
|
|
|
/// to zero.
|
|
|
|
OperandsSignature getWithoutImmCodes() const {
|
|
|
|
OperandsSignature Result;
|
|
|
|
for (unsigned i = 0, e = Operands.size(); i != e; ++i)
|
|
|
|
if (!Operands[i].isImm())
|
|
|
|
Result.Operands.push_back(Operands[i]);
|
|
|
|
else
|
|
|
|
Result.Operands.push_back(OpKind::getImm(0));
|
|
|
|
return Result;
|
|
|
|
}
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
void emitImmediatePredicate(raw_ostream &OS, ImmPredicateSet &ImmPredicates) {
|
|
|
|
bool EmittedAnything = false;
|
|
|
|
for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
|
|
|
|
if (!Operands[i].isImm())
|
|
|
|
continue;
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
unsigned Code = Operands[i].getImmCode();
|
|
|
|
if (Code == 0)
|
|
|
|
continue;
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
if (EmittedAnything)
|
|
|
|
OS << " &&\n ";
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
TreePredicateFn PredFn = ImmPredicates.getPredicate(Code - 1);
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
// Emit the type check.
|
2017-09-14 16:56:21 +00:00
|
|
|
TreePattern *TP = PredFn.getOrigPatFragRecord();
|
|
|
|
ValueTypeByHwMode VVT = TP->getTree(0)->getType(0);
|
|
|
|
assert(VVT.isSimple() &&
|
|
|
|
"Cannot use variable value types with fast isel");
|
|
|
|
OS << "VT == " << getEnumName(VVT.getSimple().SimpleTy) << " && ";
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
OS << PredFn.getFnName() << "(imm" << i << ')';
|
|
|
|
EmittedAnything = true;
|
|
|
|
}
|
|
|
|
}
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2008-08-19 20:56:30 +00:00
|
|
|
/// initialize - Examine the given pattern and initialize the contents
|
|
|
|
/// of the Operands array accordingly. Return true if all the operands
|
|
|
|
/// are supported, false otherwise.
|
|
|
|
///
|
2024-02-09 13:35:42 +00:00
|
|
|
bool initialize(TreePatternNode &InstPatNode, const CodeGenTarget &Target,
|
2013-05-22 20:45:11 +00:00
|
|
|
MVT::SimpleValueType VT, ImmPredicateSet &ImmediatePredicates,
|
|
|
|
const CodeGenRegisterClass *OrigDstRC) {
|
2024-02-09 13:35:42 +00:00
|
|
|
if (InstPatNode.isLeaf())
|
2011-04-18 06:22:33 +00:00
|
|
|
return false;
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2024-02-09 13:35:42 +00:00
|
|
|
if (InstPatNode.getOperator()->getName() == "imm") {
|
2011-04-18 06:22:33 +00:00
|
|
|
Operands.push_back(OpKind::getImm(0));
|
|
|
|
return true;
|
|
|
|
}
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2024-02-09 13:35:42 +00:00
|
|
|
if (InstPatNode.getOperator()->getName() == "fpimm") {
|
2011-04-18 06:22:33 +00:00
|
|
|
Operands.push_back(OpKind::getFP());
|
|
|
|
return true;
|
2008-08-27 01:09:54 +00:00
|
|
|
}
|
2010-12-07 19:36:07 +00:00
|
|
|
|
2014-04-15 07:20:03 +00:00
|
|
|
const CodeGenRegisterClass *DstRC = nullptr;
|
2010-12-07 19:36:07 +00:00
|
|
|
|
2024-12-13 22:05:57 +03:00
|
|
|
for (const TreePatternNode &Op : InstPatNode.children()) {
|
2011-04-18 06:22:33 +00:00
|
|
|
// Handle imm operands specially.
|
2024-02-09 13:35:42 +00:00
|
|
|
if (!Op.isLeaf() && Op.getOperator()->getName() == "imm") {
|
2011-04-18 06:22:33 +00:00
|
|
|
unsigned PredNo = 0;
|
2024-02-09 13:35:42 +00:00
|
|
|
if (!Op.getPredicateCalls().empty()) {
|
|
|
|
TreePredicateFn PredFn = Op.getPredicateCalls()[0].Fn;
|
2011-04-18 06:22:33 +00:00
|
|
|
// If there is more than one predicate weighing in on this operand
|
|
|
|
// then we don't handle it. This doesn't typically happen for
|
|
|
|
// immediates anyway.
|
2024-02-09 13:35:42 +00:00
|
|
|
if (Op.getPredicateCalls().size() > 1 ||
|
TableGen/ISel: Allow PatFrag predicate code to access captured operands
Summary:
This simplifies writing predicates for pattern fragments that are
automatically re-associated or commuted.
For example, a followup patch adds patterns for fragments of the form
(add (shl $x, $y), $z) to the AMDGPU backend. Such patterns are
automatically commuted to (add $z, (shl $x, $y)), which makes it basically
impossible to refer to $x, $y, and $z generically in the PredicateCode.
With this change, the PredicateCode can refer to $x, $y, and $z simply
as `Operands[i]`.
Test confirmed that there are no changes to any of the generated files
when building all (non-experimental) targets.
Change-Id: I61c00ace7eed42c1d4edc4c5351174b56b77a79c
Reviewers: arsenm, rampitec, RKSimon, craig.topper, hfinkel, uweigand
Subscribers: wdng, tpr, llvm-commits
Differential Revision: https://reviews.llvm.org/D51994
llvm-svn: 347992
2018-11-30 14:15:13 +00:00
|
|
|
!PredFn.isImmediatePattern() || PredFn.usesOperands())
|
2011-04-18 06:36:55 +00:00
|
|
|
return false;
|
|
|
|
// Ignore any instruction with 'FastIselShouldIgnore', these are
|
|
|
|
// not needed and just bloat the fast instruction selector. For
|
|
|
|
// example, X86 doesn't need to generate code to match ADD16ri8 since
|
|
|
|
// ADD16ri will do just fine.
|
2024-09-11 08:52:26 -07:00
|
|
|
const Record *Rec = PredFn.getOrigPatFragRecord()->getRecord();
|
2011-04-18 06:36:55 +00:00
|
|
|
if (Rec->getValueAsBit("FastIselShouldIgnore"))
|
2011-04-18 06:22:33 +00:00
|
|
|
return false;
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-18 06:36:55 +00:00
|
|
|
PredNo = ImmediatePredicates.getIDFor(PredFn) + 1;
|
2011-04-18 06:22:33 +00:00
|
|
|
}
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
Operands.push_back(OpKind::getImm(PredNo));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-08-19 20:56:30 +00:00
|
|
|
// For now, filter out any operand with a predicate.
|
2008-08-21 01:41:07 +00:00
|
|
|
// For now, filter out any operand with multiple values.
|
2024-02-09 13:35:42 +00:00
|
|
|
if (!Op.getPredicateCalls().empty() || Op.getNumTypes() != 1)
|
2008-08-21 01:41:07 +00:00
|
|
|
return false;
|
2010-12-07 19:36:07 +00:00
|
|
|
|
2024-02-09 13:35:42 +00:00
|
|
|
if (!Op.isLeaf()) {
|
|
|
|
if (Op.getOperator()->getName() == "fpimm") {
|
2011-04-17 23:29:05 +00:00
|
|
|
Operands.push_back(OpKind::getFP());
|
2009-05-21 22:25:49 +00:00
|
|
|
continue;
|
2008-08-27 01:09:54 +00:00
|
|
|
}
|
2008-08-27 16:18:22 +00:00
|
|
|
// For now, ignore other non-leaf nodes.
|
2008-08-21 01:41:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2024-02-09 13:35:42 +00:00
|
|
|
assert(Op.hasConcreteType(0) && "Type infererence not done?");
|
2011-04-17 20:23:29 +00:00
|
|
|
|
|
|
|
// For now, all the operands must have the same type (if they aren't
|
|
|
|
// immediates). Note that this causes us to reject variable sized shifts
|
|
|
|
// on X86.
|
2024-02-09 13:35:42 +00:00
|
|
|
if (Op.getSimpleType(0) != VT)
|
2011-04-17 20:23:29 +00:00
|
|
|
return false;
|
|
|
|
|
2024-09-23 13:07:31 -07:00
|
|
|
const DefInit *OpDI = dyn_cast<DefInit>(Op.getLeafValue());
|
2008-08-19 20:56:30 +00:00
|
|
|
if (!OpDI)
|
|
|
|
return false;
|
2024-09-18 09:58:04 -07:00
|
|
|
const Record *OpLeafRec = OpDI->getDef();
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2008-08-21 01:41:07 +00:00
|
|
|
// For now, the only other thing we accept is register operands.
|
2014-04-15 07:20:03 +00:00
|
|
|
const CodeGenRegisterClass *RC = nullptr;
|
2011-06-27 21:06:21 +00:00
|
|
|
if (OpLeafRec->isSubClassOf("RegisterOperand"))
|
|
|
|
OpLeafRec = OpLeafRec->getValueAsDef("RegClass");
|
2008-08-29 17:45:56 +00:00
|
|
|
if (OpLeafRec->isSubClassOf("RegisterClass"))
|
|
|
|
RC = &Target.getRegisterClass(OpLeafRec);
|
|
|
|
else if (OpLeafRec->isSubClassOf("Register"))
|
2011-06-15 00:20:40 +00:00
|
|
|
RC = Target.getRegBank().getRegClassForRegister(OpLeafRec);
|
2013-05-22 20:45:11 +00:00
|
|
|
else if (OpLeafRec->isSubClassOf("ValueType")) {
|
|
|
|
RC = OrigDstRC;
|
|
|
|
} else
|
2008-08-19 20:56:30 +00:00
|
|
|
return false;
|
2010-12-07 19:36:07 +00:00
|
|
|
|
2010-08-24 23:21:59 +00:00
|
|
|
// For now, this needs to be a register class of some sort.
|
2008-08-19 20:56:30 +00:00
|
|
|
if (!RC)
|
|
|
|
return false;
|
2010-08-24 23:21:59 +00:00
|
|
|
|
2010-08-25 04:58:56 +00:00
|
|
|
// For now, all the operands must have the same register class or be
|
|
|
|
// a strict subclass of the destination.
|
2008-08-26 01:22:59 +00:00
|
|
|
if (DstRC) {
|
2010-08-25 04:58:56 +00:00
|
|
|
if (DstRC != RC && !DstRC->hasSubClass(RC))
|
2008-08-26 01:22:59 +00:00
|
|
|
return false;
|
|
|
|
} else
|
|
|
|
DstRC = RC;
|
2011-04-17 23:29:05 +00:00
|
|
|
Operands.push_back(OpKind::getReg());
|
2008-08-19 20:56:30 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-07-03 00:10:29 +00:00
|
|
|
void PrintParameters(raw_ostream &OS) const {
|
2021-02-20 21:46:00 -08:00
|
|
|
ListSeparator LS;
|
2008-08-13 20:19:35 +00:00
|
|
|
for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
|
2021-02-20 21:46:00 -08:00
|
|
|
OS << LS;
|
2011-04-17 23:29:05 +00:00
|
|
|
if (Operands[i].isReg()) {
|
2025-03-02 10:24:47 -08:00
|
|
|
OS << "Register Op" << i;
|
2011-04-17 23:29:05 +00:00
|
|
|
} else if (Operands[i].isImm()) {
|
2008-08-21 01:41:07 +00:00
|
|
|
OS << "uint64_t imm" << i;
|
2011-04-17 23:29:05 +00:00
|
|
|
} else if (Operands[i].isFP()) {
|
2012-01-07 08:18:37 +00:00
|
|
|
OS << "const ConstantFP *f" << i;
|
2008-08-13 20:19:35 +00:00
|
|
|
} else {
|
2011-06-07 20:41:31 +00:00
|
|
|
llvm_unreachable("Unknown operand kind!");
|
2008-08-13 20:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-03 00:10:29 +00:00
|
|
|
void PrintArguments(raw_ostream &OS,
|
2011-04-17 23:29:05 +00:00
|
|
|
const std::vector<std::string> &PR) const {
|
2008-08-29 17:45:56 +00:00
|
|
|
assert(PR.size() == Operands.size());
|
2021-02-20 21:46:00 -08:00
|
|
|
ListSeparator LS;
|
2008-08-29 17:45:56 +00:00
|
|
|
for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
|
2008-09-08 08:39:33 +00:00
|
|
|
if (PR[i] != "")
|
|
|
|
// Implicit physical register operand.
|
|
|
|
continue;
|
|
|
|
|
2021-02-20 21:46:00 -08:00
|
|
|
OS << LS;
|
2011-04-17 23:29:05 +00:00
|
|
|
if (Operands[i].isReg()) {
|
2021-03-09 21:04:03 +01:00
|
|
|
OS << "Op" << i;
|
2011-04-17 23:29:05 +00:00
|
|
|
} else if (Operands[i].isImm()) {
|
2008-08-29 17:45:56 +00:00
|
|
|
OS << "imm" << i;
|
2011-04-17 23:29:05 +00:00
|
|
|
} else if (Operands[i].isFP()) {
|
2008-08-29 17:45:56 +00:00
|
|
|
OS << "f" << i;
|
|
|
|
} else {
|
2011-06-07 20:41:31 +00:00
|
|
|
llvm_unreachable("Unknown operand kind!");
|
2008-08-29 17:45:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-03 00:10:29 +00:00
|
|
|
void PrintArguments(raw_ostream &OS) const {
|
2021-02-20 21:46:00 -08:00
|
|
|
ListSeparator LS;
|
2008-08-13 20:19:35 +00:00
|
|
|
for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
|
2021-02-20 21:46:00 -08:00
|
|
|
OS << LS;
|
2011-04-17 23:29:05 +00:00
|
|
|
if (Operands[i].isReg()) {
|
2021-03-09 21:04:03 +01:00
|
|
|
OS << "Op" << i;
|
2011-04-17 23:29:05 +00:00
|
|
|
} else if (Operands[i].isImm()) {
|
2008-08-21 01:41:07 +00:00
|
|
|
OS << "imm" << i;
|
2011-04-17 23:29:05 +00:00
|
|
|
} else if (Operands[i].isFP()) {
|
2008-08-27 01:09:54 +00:00
|
|
|
OS << "f" << i;
|
2008-08-13 20:19:35 +00:00
|
|
|
} else {
|
2011-06-07 20:41:31 +00:00
|
|
|
llvm_unreachable("Unknown operand kind!");
|
2008-08-13 20:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
void PrintManglingSuffix(raw_ostream &OS, const std::vector<std::string> &PR,
|
|
|
|
ImmPredicateSet &ImmPredicates,
|
|
|
|
bool StripImmCodes = false) const {
|
2008-09-08 08:39:33 +00:00
|
|
|
for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
|
|
|
|
if (PR[i] != "")
|
|
|
|
// Implicit physical register operand. e.g. Instruction::Mul expect to
|
|
|
|
// select to a binary op. On x86, mul may take a single operand with
|
|
|
|
// the other operand being implicit. We must emit something that looks
|
2014-09-03 20:56:59 +00:00
|
|
|
// like a binary instruction except for the very inner fastEmitInst_*
|
2008-09-08 08:39:33 +00:00
|
|
|
// call.
|
|
|
|
continue;
|
2011-04-18 06:22:33 +00:00
|
|
|
Operands[i].printManglingSuffix(OS, ImmPredicates, StripImmCodes);
|
2008-09-08 08:39:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
void PrintManglingSuffix(raw_ostream &OS, ImmPredicateSet &ImmPredicates,
|
|
|
|
bool StripImmCodes = false) const {
|
2011-04-17 23:29:05 +00:00
|
|
|
for (unsigned i = 0, e = Operands.size(); i != e; ++i)
|
2011-04-18 06:22:33 +00:00
|
|
|
Operands[i].printManglingSuffix(OS, ImmPredicates, StripImmCodes);
|
2008-08-13 20:19:35 +00:00
|
|
|
}
|
|
|
|
};
|
2012-06-11 15:37:55 +00:00
|
|
|
} // End anonymous namespace
|
2008-08-13 20:19:35 +00:00
|
|
|
|
2012-06-11 15:37:55 +00:00
|
|
|
namespace {
|
2008-08-26 21:21:20 +00:00
|
|
|
class FastISelMap {
|
2017-10-06 15:33:55 +00:00
|
|
|
// A multimap is needed instead of a "plain" map because the key is
|
2014-11-14 21:05:45 +00:00
|
|
|
// the instruction's complexity (an int) and they are not unique.
|
|
|
|
typedef std::multimap<int, InstructionMemo> PredMap;
|
2009-08-11 20:47:22 +00:00
|
|
|
typedef std::map<MVT::SimpleValueType, PredMap> RetPredMap;
|
|
|
|
typedef std::map<MVT::SimpleValueType, RetPredMap> TypeRetPredMap;
|
2008-08-26 21:21:20 +00:00
|
|
|
typedef std::map<std::string, TypeRetPredMap> OpcodeTypeRetPredMap;
|
2010-12-07 19:36:07 +00:00
|
|
|
typedef std::map<OperandsSignature, OpcodeTypeRetPredMap>
|
2010-07-26 17:53:07 +00:00
|
|
|
OperandsOpcodeTypeRetPredMap;
|
2008-08-26 21:21:20 +00:00
|
|
|
|
|
|
|
OperandsOpcodeTypeRetPredMap SimplePatterns;
|
|
|
|
|
2017-10-06 15:33:55 +00:00
|
|
|
// This is used to check that there are no duplicate predicates
|
2022-12-23 22:03:23 -07:00
|
|
|
std::set<std::tuple<OperandsSignature, std::string, MVT::SimpleValueType,
|
|
|
|
MVT::SimpleValueType, std::string>>
|
|
|
|
SimplePatternsCheck;
|
2014-11-14 21:05:45 +00:00
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
std::map<OperandsSignature, std::vector<OperandsSignature>>
|
|
|
|
SignaturesWithConstantForms;
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2017-07-07 06:22:36 +00:00
|
|
|
StringRef InstNS;
|
2011-04-18 06:22:33 +00:00
|
|
|
ImmPredicateSet ImmediatePredicates;
|
2024-02-09 09:27:04 +01:00
|
|
|
|
2008-08-26 21:21:20 +00:00
|
|
|
public:
|
2017-07-07 06:22:36 +00:00
|
|
|
explicit FastISelMap(StringRef InstNS);
|
2008-08-26 21:21:20 +00:00
|
|
|
|
2024-09-18 09:58:04 -07:00
|
|
|
void collectPatterns(const CodeGenDAGPatterns &CGP);
|
2011-04-18 06:22:33 +00:00
|
|
|
void printImmediatePredicates(raw_ostream &OS);
|
|
|
|
void printFunctionDefinitions(raw_ostream &OS);
|
2024-02-09 09:27:04 +01:00
|
|
|
|
2017-10-06 15:33:55 +00:00
|
|
|
private:
|
|
|
|
void emitInstructionCode(raw_ostream &OS, const OperandsSignature &Operands,
|
2014-11-14 21:05:45 +00:00
|
|
|
const PredMap &PM, const std::string &RetVTName);
|
2008-08-26 21:21:20 +00:00
|
|
|
};
|
2012-06-11 15:37:55 +00:00
|
|
|
} // End anonymous namespace
|
2008-08-13 20:19:35 +00:00
|
|
|
|
2024-09-18 09:58:04 -07:00
|
|
|
static std::string getOpcodeName(const Record *Op,
|
|
|
|
const CodeGenDAGPatterns &CGP) {
|
2020-01-28 20:23:46 +01:00
|
|
|
return std::string(CGP.getSDNodeInfo(Op).getEnumName());
|
2008-08-13 20:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static std::string getLegalCName(std::string OpName) {
|
|
|
|
std::string::size_type pos = OpName.find("::");
|
|
|
|
if (pos != std::string::npos)
|
|
|
|
OpName.replace(pos, 2, "_");
|
|
|
|
return OpName;
|
|
|
|
}
|
|
|
|
|
2017-07-07 06:22:36 +00:00
|
|
|
FastISelMap::FastISelMap(StringRef instns) : InstNS(instns) {}
|
2008-08-13 20:19:35 +00:00
|
|
|
|
2024-12-13 22:05:57 +03:00
|
|
|
static std::string PhysRegForNode(const TreePatternNode &Op,
|
|
|
|
const CodeGenTarget &Target) {
|
2011-04-29 21:58:31 +00:00
|
|
|
std::string PhysReg;
|
|
|
|
|
2024-02-09 13:35:42 +00:00
|
|
|
if (!Op.isLeaf())
|
2011-04-29 21:58:31 +00:00
|
|
|
return PhysReg;
|
|
|
|
|
2024-09-18 09:58:04 -07:00
|
|
|
const Record *OpLeafRec = cast<DefInit>(Op.getLeafValue())->getDef();
|
2011-04-29 21:58:31 +00:00
|
|
|
if (!OpLeafRec->isSubClassOf("Register"))
|
|
|
|
return PhysReg;
|
|
|
|
|
2012-10-10 20:24:47 +00:00
|
|
|
PhysReg += cast<StringInit>(OpLeafRec->getValue("Namespace")->getValue())
|
|
|
|
->getValue();
|
2011-04-29 21:58:31 +00:00
|
|
|
PhysReg += "::";
|
2011-06-18 04:26:06 +00:00
|
|
|
PhysReg += Target.getRegBank().getReg(OpLeafRec)->getName();
|
2011-04-29 21:58:31 +00:00
|
|
|
return PhysReg;
|
|
|
|
}
|
|
|
|
|
2024-09-18 09:58:04 -07:00
|
|
|
void FastISelMap::collectPatterns(const CodeGenDAGPatterns &CGP) {
|
2008-08-26 21:21:20 +00:00
|
|
|
const CodeGenTarget &Target = CGP.getTargetInfo();
|
|
|
|
|
2008-08-22 00:28:15 +00:00
|
|
|
// Scan through all the patterns and record the simple ones.
|
2008-08-13 20:19:35 +00:00
|
|
|
for (CodeGenDAGPatterns::ptm_iterator I = CGP.ptm_begin(), E = CGP.ptm_end();
|
|
|
|
I != E; ++I) {
|
|
|
|
const PatternToMatch &Pattern = *I;
|
|
|
|
|
|
|
|
// For now, just look at Instructions, so that we don't have to worry
|
|
|
|
// about emitting multiple instructions for a pattern.
|
2024-02-09 13:35:42 +00:00
|
|
|
TreePatternNode &Dst = Pattern.getDstPattern();
|
|
|
|
if (Dst.isLeaf())
|
2008-08-13 20:19:35 +00:00
|
|
|
continue;
|
2024-09-11 08:52:26 -07:00
|
|
|
const Record *Op = Dst.getOperator();
|
2008-08-13 20:19:35 +00:00
|
|
|
if (!Op->isSubClassOf("Instruction"))
|
|
|
|
continue;
|
2010-03-19 00:07:20 +00:00
|
|
|
CodeGenInstruction &II = CGP.getTargetInfo().getInstruction(Op);
|
2011-04-17 22:24:13 +00:00
|
|
|
if (II.Operands.empty())
|
2008-08-13 20:19:35 +00:00
|
|
|
continue;
|
2010-12-07 19:36:07 +00:00
|
|
|
|
2018-05-22 14:36:58 +00:00
|
|
|
// Allow instructions to be marked as unavailable for FastISel for
|
|
|
|
// certain cases, i.e. an ISA has two 'and' instruction which differ
|
|
|
|
// by what registers they can use but are otherwise identical for
|
|
|
|
// codegen purposes.
|
|
|
|
if (II.FastISelShouldIgnore)
|
|
|
|
continue;
|
|
|
|
|
2008-09-07 08:19:51 +00:00
|
|
|
// For now, ignore multi-instruction patterns.
|
|
|
|
bool MultiInsts = false;
|
2024-12-13 22:05:57 +03:00
|
|
|
for (const TreePatternNode &ChildOp : Dst.children()) {
|
2024-02-09 13:35:42 +00:00
|
|
|
if (ChildOp.isLeaf())
|
2008-09-07 08:19:51 +00:00
|
|
|
continue;
|
2024-02-09 13:35:42 +00:00
|
|
|
if (ChildOp.getOperator()->isSubClassOf("Instruction")) {
|
2008-09-07 08:19:51 +00:00
|
|
|
MultiInsts = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (MultiInsts)
|
|
|
|
continue;
|
|
|
|
|
2008-08-19 20:36:33 +00:00
|
|
|
// For now, ignore instructions where the first operand is not an
|
|
|
|
// output register.
|
2014-04-15 07:20:03 +00:00
|
|
|
const CodeGenRegisterClass *DstRC = nullptr;
|
2010-05-24 14:48:12 +00:00
|
|
|
std::string SubRegNo;
|
2008-08-28 18:06:12 +00:00
|
|
|
if (Op->getName() != "EXTRACT_SUBREG") {
|
2024-09-09 14:33:21 -07:00
|
|
|
const Record *Op0Rec = II.Operands[0].Rec;
|
2011-06-27 21:06:21 +00:00
|
|
|
if (Op0Rec->isSubClassOf("RegisterOperand"))
|
|
|
|
Op0Rec = Op0Rec->getValueAsDef("RegClass");
|
2008-08-28 18:06:12 +00:00
|
|
|
if (!Op0Rec->isSubClassOf("RegisterClass"))
|
|
|
|
continue;
|
|
|
|
DstRC = &Target.getRegisterClass(Op0Rec);
|
|
|
|
if (!DstRC)
|
|
|
|
continue;
|
|
|
|
} else {
|
2010-07-21 22:07:19 +00:00
|
|
|
// If this isn't a leaf, then continue since the register classes are
|
|
|
|
// a bit too complicated for now.
|
2024-02-09 13:35:42 +00:00
|
|
|
if (!Dst.getChild(1).isLeaf())
|
2018-06-14 20:32:58 +00:00
|
|
|
continue;
|
2010-12-07 19:36:07 +00:00
|
|
|
|
2024-09-23 13:07:31 -07:00
|
|
|
const DefInit *SR = dyn_cast<DefInit>(Dst.getChild(1).getLeafValue());
|
2010-05-24 14:48:12 +00:00
|
|
|
if (SR)
|
|
|
|
SubRegNo = getQualifiedName(SR->getDef());
|
|
|
|
else
|
2024-02-09 13:35:42 +00:00
|
|
|
SubRegNo = Dst.getChild(1).getLeafValue()->getAsString();
|
2008-08-28 18:06:12 +00:00
|
|
|
}
|
2008-08-13 20:19:35 +00:00
|
|
|
|
|
|
|
// Inspect the pattern.
|
2024-02-09 13:35:42 +00:00
|
|
|
TreePatternNode &InstPatNode = Pattern.getSrcPattern();
|
|
|
|
if (InstPatNode.isLeaf())
|
2008-08-13 20:19:35 +00:00
|
|
|
continue;
|
|
|
|
|
2010-03-24 00:41:19 +00:00
|
|
|
// Ignore multiple result nodes for now.
|
2024-02-09 13:35:42 +00:00
|
|
|
if (InstPatNode.getNumTypes() > 1)
|
2010-03-24 00:41:19 +00:00
|
|
|
continue;
|
2010-12-07 19:36:07 +00:00
|
|
|
|
2024-09-11 08:52:26 -07:00
|
|
|
const Record *InstPatOp = InstPatNode.getOperator();
|
2008-08-13 20:19:35 +00:00
|
|
|
std::string OpcodeName = getOpcodeName(InstPatOp, CGP);
|
2010-03-19 21:37:09 +00:00
|
|
|
MVT::SimpleValueType RetVT = MVT::isVoid;
|
2024-02-09 13:35:42 +00:00
|
|
|
if (InstPatNode.getNumTypes())
|
|
|
|
RetVT = InstPatNode.getSimpleType(0);
|
2009-08-11 20:47:22 +00:00
|
|
|
MVT::SimpleValueType VT = RetVT;
|
2024-02-09 13:35:42 +00:00
|
|
|
if (InstPatNode.getNumChildren()) {
|
|
|
|
assert(InstPatNode.getChild(0).getNumTypes() == 1);
|
|
|
|
VT = InstPatNode.getChild(0).getSimpleType(0);
|
2010-03-19 21:37:09 +00:00
|
|
|
}
|
2008-08-19 20:30:54 +00:00
|
|
|
|
|
|
|
// For now, filter out any instructions with predicates.
|
2024-02-09 13:35:42 +00:00
|
|
|
if (!InstPatNode.getPredicateCalls().empty())
|
2008-08-19 20:30:54 +00:00
|
|
|
continue;
|
2008-08-13 20:19:35 +00:00
|
|
|
|
2008-08-19 20:36:33 +00:00
|
|
|
// Check all the operands.
|
2008-08-13 20:19:35 +00:00
|
|
|
OperandsSignature Operands;
|
2013-05-22 20:45:11 +00:00
|
|
|
if (!Operands.initialize(InstPatNode, Target, VT, ImmediatePredicates,
|
|
|
|
DstRC))
|
2008-08-19 20:56:30 +00:00
|
|
|
continue;
|
2010-12-07 19:36:07 +00:00
|
|
|
|
2018-05-29 17:40:03 +00:00
|
|
|
std::vector<std::string> PhysRegInputs;
|
2024-02-09 13:35:42 +00:00
|
|
|
if (InstPatNode.getOperator()->getName() == "imm" ||
|
|
|
|
InstPatNode.getOperator()->getName() == "fpimm")
|
2018-05-29 17:40:03 +00:00
|
|
|
PhysRegInputs.push_back("");
|
2011-04-29 21:58:31 +00:00
|
|
|
else {
|
|
|
|
// Compute the PhysRegs used by the given pattern, and check that
|
|
|
|
// the mapping from the src to dst patterns is simple.
|
|
|
|
bool FoundNonSimplePattern = false;
|
|
|
|
unsigned DstIndex = 0;
|
2024-12-13 22:05:57 +03:00
|
|
|
for (const TreePatternNode &SrcChild : InstPatNode.children()) {
|
|
|
|
std::string PhysReg = PhysRegForNode(SrcChild, Target);
|
2011-04-29 21:58:31 +00:00
|
|
|
if (PhysReg.empty()) {
|
2024-02-09 13:35:42 +00:00
|
|
|
if (DstIndex >= Dst.getNumChildren() ||
|
2024-12-13 22:05:57 +03:00
|
|
|
Dst.getChild(DstIndex).getName() != SrcChild.getName()) {
|
2011-04-29 21:58:31 +00:00
|
|
|
FoundNonSimplePattern = true;
|
|
|
|
break;
|
2008-08-29 17:45:56 +00:00
|
|
|
}
|
2011-04-29 21:58:31 +00:00
|
|
|
++DstIndex;
|
2008-08-29 17:45:56 +00:00
|
|
|
}
|
2010-12-07 19:36:07 +00:00
|
|
|
|
2024-11-22 03:48:46 +08:00
|
|
|
PhysRegInputs.push_back(std::move(PhysReg));
|
2008-08-29 17:45:56 +00:00
|
|
|
}
|
2011-04-29 21:58:31 +00:00
|
|
|
|
2024-02-09 13:35:42 +00:00
|
|
|
if (Op->getName() != "EXTRACT_SUBREG" && DstIndex < Dst.getNumChildren())
|
2011-04-29 21:58:31 +00:00
|
|
|
FoundNonSimplePattern = true;
|
|
|
|
|
|
|
|
if (FoundNonSimplePattern)
|
|
|
|
continue;
|
|
|
|
}
|
2008-08-13 20:19:35 +00:00
|
|
|
|
2014-10-01 22:44:01 +00:00
|
|
|
// Check if the operands match one of the patterns handled by FastISel.
|
|
|
|
std::string ManglingSuffix;
|
|
|
|
raw_string_ostream SuffixOS(ManglingSuffix);
|
|
|
|
Operands.PrintManglingSuffix(SuffixOS, ImmediatePredicates, true);
|
|
|
|
if (!StringSwitch<bool>(ManglingSuffix)
|
2016-10-05 19:25:20 +00:00
|
|
|
.Cases("", "r", "rr", "ri", "i", "f", true)
|
2014-10-01 22:44:01 +00:00
|
|
|
.Default(false))
|
|
|
|
continue;
|
|
|
|
|
2008-08-22 00:20:26 +00:00
|
|
|
// Get the predicate that guards this pattern.
|
|
|
|
std::string PredicateCheck = Pattern.getPredicateCheck();
|
|
|
|
|
2008-08-13 20:19:35 +00:00
|
|
|
// Ok, we found a pattern that we can handle. Remember it.
|
2024-02-09 13:35:42 +00:00
|
|
|
InstructionMemo Memo(Pattern.getDstPattern().getOperator()->getName(),
|
2024-11-22 03:48:46 +08:00
|
|
|
DstRC, std::move(SubRegNo), std::move(PhysRegInputs),
|
|
|
|
PredicateCheck);
|
2017-10-06 15:33:55 +00:00
|
|
|
|
2014-11-14 21:05:45 +00:00
|
|
|
int complexity = Pattern.getPatternComplexity(CGP);
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2022-12-23 22:03:23 -07:00
|
|
|
auto inserted_simple_pattern = SimplePatternsCheck.insert(
|
2025-01-16 13:20:41 +00:00
|
|
|
{Operands, OpcodeName, VT, RetVT, PredicateCheck});
|
2022-12-23 22:03:23 -07:00
|
|
|
if (!inserted_simple_pattern.second) {
|
2012-10-25 20:33:17 +00:00
|
|
|
PrintFatalError(Pattern.getSrcRecord()->getLoc(),
|
2014-11-14 21:05:45 +00:00
|
|
|
"Duplicate predicate in FastISel table!");
|
|
|
|
}
|
2010-12-07 23:05:49 +00:00
|
|
|
|
2022-12-23 22:03:23 -07:00
|
|
|
// Note: Instructions with the same complexity will appear in the order
|
|
|
|
// that they are encountered.
|
2018-05-29 17:40:03 +00:00
|
|
|
SimplePatterns[Operands][OpcodeName][VT][RetVT].emplace(complexity,
|
|
|
|
std::move(Memo));
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
// If any of the operands were immediates with predicates on them, strip
|
|
|
|
// them down to a signature that doesn't have predicates so that we can
|
|
|
|
// associate them with the stripped predicate version.
|
|
|
|
if (Operands.hasAnyImmediateCodes()) {
|
|
|
|
SignaturesWithConstantForms[Operands.getWithoutImmCodes()].push_back(
|
|
|
|
Operands);
|
|
|
|
}
|
2008-08-13 20:19:35 +00:00
|
|
|
}
|
2008-08-26 21:21:20 +00:00
|
|
|
}
|
2008-08-13 20:19:35 +00:00
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
void FastISelMap::printImmediatePredicates(raw_ostream &OS) {
|
|
|
|
if (ImmediatePredicates.begin() == ImmediatePredicates.end())
|
|
|
|
return;
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
OS << "\n// FastEmit Immediate Predicate functions.\n";
|
2021-05-06 18:36:52 +08:00
|
|
|
for (auto ImmediatePredicate : ImmediatePredicates) {
|
|
|
|
OS << "static bool " << ImmediatePredicate.getFnName()
|
|
|
|
<< "(int64_t Imm) {\n";
|
|
|
|
OS << ImmediatePredicate.getImmediatePredicateCode() << "\n}\n";
|
2011-04-18 06:22:33 +00:00
|
|
|
}
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
OS << "\n\n";
|
|
|
|
}
|
|
|
|
|
2017-10-06 15:33:55 +00:00
|
|
|
void FastISelMap::emitInstructionCode(raw_ostream &OS,
|
2014-11-14 21:05:45 +00:00
|
|
|
const OperandsSignature &Operands,
|
2017-10-06 15:33:55 +00:00
|
|
|
const PredMap &PM,
|
2014-11-14 21:05:45 +00:00
|
|
|
const std::string &RetVTName) {
|
|
|
|
// Emit code for each possible instruction. There may be
|
|
|
|
// multiple if there are subtarget concerns. A reverse iterator
|
|
|
|
// is used to produce the ones with highest complexity first.
|
|
|
|
|
|
|
|
bool OneHadNoPredicate = false;
|
|
|
|
for (PredMap::const_reverse_iterator PI = PM.rbegin(), PE = PM.rend();
|
|
|
|
PI != PE; ++PI) {
|
|
|
|
const InstructionMemo &Memo = PI->second;
|
|
|
|
std::string PredicateCheck = Memo.PredicateCheck;
|
|
|
|
|
|
|
|
if (PredicateCheck.empty()) {
|
|
|
|
assert(!OneHadNoPredicate &&
|
|
|
|
"Multiple instructions match and more than one had "
|
|
|
|
"no predicate!");
|
|
|
|
OneHadNoPredicate = true;
|
|
|
|
} else {
|
|
|
|
if (OneHadNoPredicate) {
|
2017-01-30 19:03:26 +00:00
|
|
|
PrintFatalError("Multiple instructions match and one with no "
|
|
|
|
"predicate came before one with a predicate! "
|
|
|
|
"name:" +
|
|
|
|
Memo.Name + " predicate: " + PredicateCheck);
|
2014-11-14 21:05:45 +00:00
|
|
|
}
|
|
|
|
OS << " if (" + PredicateCheck + ") {\n";
|
|
|
|
OS << " ";
|
|
|
|
}
|
|
|
|
|
2018-05-29 17:40:03 +00:00
|
|
|
for (unsigned i = 0; i < Memo.PhysRegs.size(); ++i) {
|
|
|
|
if (Memo.PhysRegs[i] != "")
|
2022-09-06 15:49:13 +02:00
|
|
|
OS << " BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD, "
|
2018-05-29 17:40:03 +00:00
|
|
|
<< "TII.get(TargetOpcode::COPY), " << Memo.PhysRegs[i]
|
|
|
|
<< ").addReg(Op" << i << ");\n";
|
2014-11-14 21:05:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OS << " return fastEmitInst_";
|
|
|
|
if (Memo.SubRegNo.empty()) {
|
2018-05-29 17:40:03 +00:00
|
|
|
Operands.PrintManglingSuffix(OS, Memo.PhysRegs, ImmediatePredicates,
|
|
|
|
true);
|
2017-07-07 06:22:36 +00:00
|
|
|
OS << "(" << InstNS << "::" << Memo.Name << ", ";
|
|
|
|
OS << "&" << InstNS << "::" << Memo.RC->getName() << "RegClass";
|
2014-11-14 21:05:45 +00:00
|
|
|
if (!Operands.empty())
|
|
|
|
OS << ", ";
|
2018-05-29 17:40:03 +00:00
|
|
|
Operands.PrintArguments(OS, Memo.PhysRegs);
|
2014-11-14 21:05:45 +00:00
|
|
|
OS << ");\n";
|
|
|
|
} else {
|
|
|
|
OS << "extractsubreg(" << RetVTName << ", Op0, " << Memo.SubRegNo
|
2021-03-09 21:04:03 +01:00
|
|
|
<< ");\n";
|
2014-11-14 21:05:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!PredicateCheck.empty()) {
|
|
|
|
OS << " }\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Return 0 if all of the possibilities had predicates but none
|
|
|
|
// were satisfied.
|
|
|
|
if (!OneHadNoPredicate)
|
|
|
|
OS << " return 0;\n";
|
|
|
|
OS << "}\n";
|
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
void FastISelMap::printFunctionDefinitions(raw_ostream &OS) {
|
2008-08-13 20:19:35 +00:00
|
|
|
// Now emit code for all the patterns that we collected.
|
2021-05-06 18:36:52 +08:00
|
|
|
for (const auto &SimplePattern : SimplePatterns) {
|
|
|
|
const OperandsSignature &Operands = SimplePattern.first;
|
|
|
|
const OpcodeTypeRetPredMap &OTM = SimplePattern.second;
|
2008-08-13 20:19:35 +00:00
|
|
|
|
2021-05-06 18:36:52 +08:00
|
|
|
for (const auto &I : OTM) {
|
|
|
|
const std::string &Opcode = I.first;
|
|
|
|
const TypeRetPredMap &TM = I.second;
|
2008-08-13 20:19:35 +00:00
|
|
|
|
|
|
|
OS << "// FastEmit functions for " << Opcode << ".\n";
|
|
|
|
OS << "\n";
|
|
|
|
|
|
|
|
// Emit one function for each opcode,type pair.
|
2021-05-06 18:36:52 +08:00
|
|
|
for (const auto &TI : TM) {
|
|
|
|
MVT::SimpleValueType VT = TI.first;
|
|
|
|
const RetPredMap &RM = TI.second;
|
2008-08-26 00:42:26 +00:00
|
|
|
if (RM.size() != 1) {
|
2021-05-06 18:36:52 +08:00
|
|
|
for (const auto &RI : RM) {
|
|
|
|
MVT::SimpleValueType RetVT = RI.first;
|
|
|
|
const PredMap &PM = RI.second;
|
2008-08-26 00:42:26 +00:00
|
|
|
|
2020-01-28 20:23:46 +01:00
|
|
|
OS << "unsigned fastEmit_" << getLegalCName(Opcode) << "_"
|
[TableGen] Replace all lingering uses of getName with getEnumName
The former is a wrapper for the latter with two differences: Other is
mapped to "UNKNOWN" (rather than "MVT::Other"), and iPTR(Any) are mapped
to "TLI.getPointerTy()" rather than "MVT::iPTR(Any)".
The only uses are in FastISelMap::printFunctionDefinitions. Most of
these uses are just a form of name mangling to ensure uniqueness, so the
actual string isn't important (and, in the case of MVT::iPTR(Any), were
both to be used, they would clash). Two uses are for a case statement,
which requires the expression to be a constant (of the right type), but
neither UNKNOWN nor TLI.getPointerTy() are constants, so would not work
there. The remaining uses are where an expression is needed, so UNKNOWN
similarly doesn't work, though TLI.getPointerTy() could in this case.
However, neither iPTR nor iPTRAny are supposed to make it this far
through TableGen, and should instead have been replaced with concrete
types, so this case should not be hit. Moreover, for almost all of these
uses, the name is passed to getLegalCName, which will strip an MVT::
prefix but will leave TLI.getPointerTy() unchanged, which is not a valid
C identifier, nor component thereof.
Thus, delete this unnecessary, and mostly-broken, wrapper and just use
the underlying getEnumName. This has been verified to have no effect on
the generated files for any in-tree target, including experimental ones.
Reviewers: arsenm
Reviewed By: arsenm
Pull Request: https://github.com/llvm/llvm-project/pull/113731
2024-10-30 03:12:23 +00:00
|
|
|
<< getLegalCName(std::string(getEnumName(VT))) << "_"
|
|
|
|
<< getLegalCName(std::string(getEnumName(RetVT))) << "_";
|
2011-04-18 06:22:33 +00:00
|
|
|
Operands.PrintManglingSuffix(OS, ImmediatePredicates);
|
2008-08-26 00:42:26 +00:00
|
|
|
OS << "(";
|
|
|
|
Operands.PrintParameters(OS);
|
|
|
|
OS << ") {\n";
|
|
|
|
|
[TableGen] Replace all lingering uses of getName with getEnumName
The former is a wrapper for the latter with two differences: Other is
mapped to "UNKNOWN" (rather than "MVT::Other"), and iPTR(Any) are mapped
to "TLI.getPointerTy()" rather than "MVT::iPTR(Any)".
The only uses are in FastISelMap::printFunctionDefinitions. Most of
these uses are just a form of name mangling to ensure uniqueness, so the
actual string isn't important (and, in the case of MVT::iPTR(Any), were
both to be used, they would clash). Two uses are for a case statement,
which requires the expression to be a constant (of the right type), but
neither UNKNOWN nor TLI.getPointerTy() are constants, so would not work
there. The remaining uses are where an expression is needed, so UNKNOWN
similarly doesn't work, though TLI.getPointerTy() could in this case.
However, neither iPTR nor iPTRAny are supposed to make it this far
through TableGen, and should instead have been replaced with concrete
types, so this case should not be hit. Moreover, for almost all of these
uses, the name is passed to getLegalCName, which will strip an MVT::
prefix but will leave TLI.getPointerTy() unchanged, which is not a valid
C identifier, nor component thereof.
Thus, delete this unnecessary, and mostly-broken, wrapper and just use
the underlying getEnumName. This has been verified to have no effect on
the generated files for any in-tree target, including experimental ones.
Reviewers: arsenm
Reviewed By: arsenm
Pull Request: https://github.com/llvm/llvm-project/pull/113731
2024-10-30 03:12:23 +00:00
|
|
|
emitInstructionCode(OS, Operands, PM,
|
|
|
|
std::string(getEnumName(RetVT)));
|
2008-08-26 00:42:26 +00:00
|
|
|
}
|
2010-12-07 19:36:07 +00:00
|
|
|
|
2008-08-26 00:42:26 +00:00
|
|
|
// Emit one function for the type that demultiplexes on return type.
|
2020-01-28 20:23:46 +01:00
|
|
|
OS << "unsigned fastEmit_" << getLegalCName(Opcode) << "_"
|
[TableGen] Replace all lingering uses of getName with getEnumName
The former is a wrapper for the latter with two differences: Other is
mapped to "UNKNOWN" (rather than "MVT::Other"), and iPTR(Any) are mapped
to "TLI.getPointerTy()" rather than "MVT::iPTR(Any)".
The only uses are in FastISelMap::printFunctionDefinitions. Most of
these uses are just a form of name mangling to ensure uniqueness, so the
actual string isn't important (and, in the case of MVT::iPTR(Any), were
both to be used, they would clash). Two uses are for a case statement,
which requires the expression to be a constant (of the right type), but
neither UNKNOWN nor TLI.getPointerTy() are constants, so would not work
there. The remaining uses are where an expression is needed, so UNKNOWN
similarly doesn't work, though TLI.getPointerTy() could in this case.
However, neither iPTR nor iPTRAny are supposed to make it this far
through TableGen, and should instead have been replaced with concrete
types, so this case should not be hit. Moreover, for almost all of these
uses, the name is passed to getLegalCName, which will strip an MVT::
prefix but will leave TLI.getPointerTy() unchanged, which is not a valid
C identifier, nor component thereof.
Thus, delete this unnecessary, and mostly-broken, wrapper and just use
the underlying getEnumName. This has been verified to have no effect on
the generated files for any in-tree target, including experimental ones.
Reviewers: arsenm
Reviewed By: arsenm
Pull Request: https://github.com/llvm/llvm-project/pull/113731
2024-10-30 03:12:23 +00:00
|
|
|
<< getLegalCName(std::string(getEnumName(VT))) << "_";
|
2011-04-18 06:22:33 +00:00
|
|
|
Operands.PrintManglingSuffix(OS, ImmediatePredicates);
|
2009-08-11 20:47:22 +00:00
|
|
|
OS << "(MVT RetVT";
|
2008-08-26 00:42:26 +00:00
|
|
|
if (!Operands.empty())
|
|
|
|
OS << ", ";
|
|
|
|
Operands.PrintParameters(OS);
|
2009-08-11 20:47:22 +00:00
|
|
|
OS << ") {\nswitch (RetVT.SimpleTy) {\n";
|
2021-05-06 18:36:52 +08:00
|
|
|
for (const auto &RI : RM) {
|
|
|
|
MVT::SimpleValueType RetVT = RI.first;
|
[TableGen] Replace all lingering uses of getName with getEnumName
The former is a wrapper for the latter with two differences: Other is
mapped to "UNKNOWN" (rather than "MVT::Other"), and iPTR(Any) are mapped
to "TLI.getPointerTy()" rather than "MVT::iPTR(Any)".
The only uses are in FastISelMap::printFunctionDefinitions. Most of
these uses are just a form of name mangling to ensure uniqueness, so the
actual string isn't important (and, in the case of MVT::iPTR(Any), were
both to be used, they would clash). Two uses are for a case statement,
which requires the expression to be a constant (of the right type), but
neither UNKNOWN nor TLI.getPointerTy() are constants, so would not work
there. The remaining uses are where an expression is needed, so UNKNOWN
similarly doesn't work, though TLI.getPointerTy() could in this case.
However, neither iPTR nor iPTRAny are supposed to make it this far
through TableGen, and should instead have been replaced with concrete
types, so this case should not be hit. Moreover, for almost all of these
uses, the name is passed to getLegalCName, which will strip an MVT::
prefix but will leave TLI.getPointerTy() unchanged, which is not a valid
C identifier, nor component thereof.
Thus, delete this unnecessary, and mostly-broken, wrapper and just use
the underlying getEnumName. This has been verified to have no effect on
the generated files for any in-tree target, including experimental ones.
Reviewers: arsenm
Reviewed By: arsenm
Pull Request: https://github.com/llvm/llvm-project/pull/113731
2024-10-30 03:12:23 +00:00
|
|
|
OS << " case " << getEnumName(RetVT) << ": return fastEmit_"
|
2020-01-28 20:23:46 +01:00
|
|
|
<< getLegalCName(Opcode) << "_"
|
[TableGen] Replace all lingering uses of getName with getEnumName
The former is a wrapper for the latter with two differences: Other is
mapped to "UNKNOWN" (rather than "MVT::Other"), and iPTR(Any) are mapped
to "TLI.getPointerTy()" rather than "MVT::iPTR(Any)".
The only uses are in FastISelMap::printFunctionDefinitions. Most of
these uses are just a form of name mangling to ensure uniqueness, so the
actual string isn't important (and, in the case of MVT::iPTR(Any), were
both to be used, they would clash). Two uses are for a case statement,
which requires the expression to be a constant (of the right type), but
neither UNKNOWN nor TLI.getPointerTy() are constants, so would not work
there. The remaining uses are where an expression is needed, so UNKNOWN
similarly doesn't work, though TLI.getPointerTy() could in this case.
However, neither iPTR nor iPTRAny are supposed to make it this far
through TableGen, and should instead have been replaced with concrete
types, so this case should not be hit. Moreover, for almost all of these
uses, the name is passed to getLegalCName, which will strip an MVT::
prefix but will leave TLI.getPointerTy() unchanged, which is not a valid
C identifier, nor component thereof.
Thus, delete this unnecessary, and mostly-broken, wrapper and just use
the underlying getEnumName. This has been verified to have no effect on
the generated files for any in-tree target, including experimental ones.
Reviewers: arsenm
Reviewed By: arsenm
Pull Request: https://github.com/llvm/llvm-project/pull/113731
2024-10-30 03:12:23 +00:00
|
|
|
<< getLegalCName(std::string(getEnumName(VT))) << "_"
|
|
|
|
<< getLegalCName(std::string(getEnumName(RetVT))) << "_";
|
2011-04-18 06:22:33 +00:00
|
|
|
Operands.PrintManglingSuffix(OS, ImmediatePredicates);
|
2008-08-26 00:42:26 +00:00
|
|
|
OS << "(";
|
|
|
|
Operands.PrintArguments(OS);
|
|
|
|
OS << ");\n";
|
|
|
|
}
|
|
|
|
OS << " default: return 0;\n}\n}\n\n";
|
2010-12-07 19:36:07 +00:00
|
|
|
|
2008-08-26 00:42:26 +00:00
|
|
|
} else {
|
|
|
|
// Non-variadic return type.
|
2020-01-28 20:23:46 +01:00
|
|
|
OS << "unsigned fastEmit_" << getLegalCName(Opcode) << "_"
|
[TableGen] Replace all lingering uses of getName with getEnumName
The former is a wrapper for the latter with two differences: Other is
mapped to "UNKNOWN" (rather than "MVT::Other"), and iPTR(Any) are mapped
to "TLI.getPointerTy()" rather than "MVT::iPTR(Any)".
The only uses are in FastISelMap::printFunctionDefinitions. Most of
these uses are just a form of name mangling to ensure uniqueness, so the
actual string isn't important (and, in the case of MVT::iPTR(Any), were
both to be used, they would clash). Two uses are for a case statement,
which requires the expression to be a constant (of the right type), but
neither UNKNOWN nor TLI.getPointerTy() are constants, so would not work
there. The remaining uses are where an expression is needed, so UNKNOWN
similarly doesn't work, though TLI.getPointerTy() could in this case.
However, neither iPTR nor iPTRAny are supposed to make it this far
through TableGen, and should instead have been replaced with concrete
types, so this case should not be hit. Moreover, for almost all of these
uses, the name is passed to getLegalCName, which will strip an MVT::
prefix but will leave TLI.getPointerTy() unchanged, which is not a valid
C identifier, nor component thereof.
Thus, delete this unnecessary, and mostly-broken, wrapper and just use
the underlying getEnumName. This has been verified to have no effect on
the generated files for any in-tree target, including experimental ones.
Reviewers: arsenm
Reviewed By: arsenm
Pull Request: https://github.com/llvm/llvm-project/pull/113731
2024-10-30 03:12:23 +00:00
|
|
|
<< getLegalCName(std::string(getEnumName(VT))) << "_";
|
2011-04-18 06:22:33 +00:00
|
|
|
Operands.PrintManglingSuffix(OS, ImmediatePredicates);
|
2009-08-11 20:47:22 +00:00
|
|
|
OS << "(MVT RetVT";
|
2008-08-25 23:58:18 +00:00
|
|
|
if (!Operands.empty())
|
|
|
|
OS << ", ";
|
2008-08-25 23:43:09 +00:00
|
|
|
Operands.PrintParameters(OS);
|
|
|
|
OS << ") {\n";
|
2010-12-07 19:36:07 +00:00
|
|
|
|
[TableGen] Replace all lingering uses of getName with getEnumName
The former is a wrapper for the latter with two differences: Other is
mapped to "UNKNOWN" (rather than "MVT::Other"), and iPTR(Any) are mapped
to "TLI.getPointerTy()" rather than "MVT::iPTR(Any)".
The only uses are in FastISelMap::printFunctionDefinitions. Most of
these uses are just a form of name mangling to ensure uniqueness, so the
actual string isn't important (and, in the case of MVT::iPTR(Any), were
both to be used, they would clash). Two uses are for a case statement,
which requires the expression to be a constant (of the right type), but
neither UNKNOWN nor TLI.getPointerTy() are constants, so would not work
there. The remaining uses are where an expression is needed, so UNKNOWN
similarly doesn't work, though TLI.getPointerTy() could in this case.
However, neither iPTR nor iPTRAny are supposed to make it this far
through TableGen, and should instead have been replaced with concrete
types, so this case should not be hit. Moreover, for almost all of these
uses, the name is passed to getLegalCName, which will strip an MVT::
prefix but will leave TLI.getPointerTy() unchanged, which is not a valid
C identifier, nor component thereof.
Thus, delete this unnecessary, and mostly-broken, wrapper and just use
the underlying getEnumName. This has been verified to have no effect on
the generated files for any in-tree target, including experimental ones.
Reviewers: arsenm
Reviewed By: arsenm
Pull Request: https://github.com/llvm/llvm-project/pull/113731
2024-10-30 03:12:23 +00:00
|
|
|
OS << " if (RetVT.SimpleTy != " << getEnumName(RM.begin()->first)
|
2008-08-26 18:50:00 +00:00
|
|
|
<< ")\n return 0;\n";
|
2010-12-07 19:36:07 +00:00
|
|
|
|
2008-08-26 00:42:26 +00:00
|
|
|
const PredMap &PM = RM.begin()->second;
|
2010-12-07 19:36:07 +00:00
|
|
|
|
2014-11-14 21:05:45 +00:00
|
|
|
emitInstructionCode(OS, Operands, PM, "RetVT");
|
2008-08-22 00:20:26 +00:00
|
|
|
}
|
2008-08-13 20:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Emit one function for the opcode that demultiplexes based on the type.
|
2008-08-21 01:41:07 +00:00
|
|
|
OS << "unsigned fastEmit_" << getLegalCName(Opcode) << "_";
|
2011-04-18 06:22:33 +00:00
|
|
|
Operands.PrintManglingSuffix(OS, ImmediatePredicates);
|
2009-08-11 20:47:22 +00:00
|
|
|
OS << "(MVT VT, MVT RetVT";
|
2008-08-13 20:19:35 +00:00
|
|
|
if (!Operands.empty())
|
|
|
|
OS << ", ";
|
|
|
|
Operands.PrintParameters(OS);
|
|
|
|
OS << ") {\n";
|
2009-08-11 20:47:22 +00:00
|
|
|
OS << " switch (VT.SimpleTy) {\n";
|
2021-05-06 18:36:52 +08:00
|
|
|
for (const auto &TI : TM) {
|
|
|
|
MVT::SimpleValueType VT = TI.first;
|
[TableGen] Replace all lingering uses of getName with getEnumName
The former is a wrapper for the latter with two differences: Other is
mapped to "UNKNOWN" (rather than "MVT::Other"), and iPTR(Any) are mapped
to "TLI.getPointerTy()" rather than "MVT::iPTR(Any)".
The only uses are in FastISelMap::printFunctionDefinitions. Most of
these uses are just a form of name mangling to ensure uniqueness, so the
actual string isn't important (and, in the case of MVT::iPTR(Any), were
both to be used, they would clash). Two uses are for a case statement,
which requires the expression to be a constant (of the right type), but
neither UNKNOWN nor TLI.getPointerTy() are constants, so would not work
there. The remaining uses are where an expression is needed, so UNKNOWN
similarly doesn't work, though TLI.getPointerTy() could in this case.
However, neither iPTR nor iPTRAny are supposed to make it this far
through TableGen, and should instead have been replaced with concrete
types, so this case should not be hit. Moreover, for almost all of these
uses, the name is passed to getLegalCName, which will strip an MVT::
prefix but will leave TLI.getPointerTy() unchanged, which is not a valid
C identifier, nor component thereof.
Thus, delete this unnecessary, and mostly-broken, wrapper and just use
the underlying getEnumName. This has been verified to have no effect on
the generated files for any in-tree target, including experimental ones.
Reviewers: arsenm
Reviewed By: arsenm
Pull Request: https://github.com/llvm/llvm-project/pull/113731
2024-10-30 03:12:23 +00:00
|
|
|
std::string TypeName = std::string(getEnumName(VT));
|
2014-09-03 20:56:59 +00:00
|
|
|
OS << " case " << TypeName << ": return fastEmit_"
|
2008-08-21 01:41:07 +00:00
|
|
|
<< getLegalCName(Opcode) << "_" << getLegalCName(TypeName) << "_";
|
2011-04-18 06:22:33 +00:00
|
|
|
Operands.PrintManglingSuffix(OS, ImmediatePredicates);
|
2008-08-25 23:58:18 +00:00
|
|
|
OS << "(RetVT";
|
|
|
|
if (!Operands.empty())
|
|
|
|
OS << ", ";
|
2008-08-13 20:19:35 +00:00
|
|
|
Operands.PrintArguments(OS);
|
|
|
|
OS << ");\n";
|
|
|
|
}
|
|
|
|
OS << " default: return 0;\n";
|
|
|
|
OS << " }\n";
|
|
|
|
OS << "}\n";
|
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
2008-08-22 00:28:15 +00:00
|
|
|
OS << "// Top-level FastEmit function.\n";
|
|
|
|
OS << "\n";
|
|
|
|
|
2008-08-13 20:19:35 +00:00
|
|
|
// Emit one function for the operand signature that demultiplexes based
|
|
|
|
// on opcode and type.
|
2014-09-03 20:56:59 +00:00
|
|
|
OS << "unsigned fastEmit_";
|
2011-04-18 06:22:33 +00:00
|
|
|
Operands.PrintManglingSuffix(OS, ImmediatePredicates);
|
2010-01-05 22:26:32 +00:00
|
|
|
OS << "(MVT VT, MVT RetVT, unsigned Opcode";
|
2008-08-13 20:19:35 +00:00
|
|
|
if (!Operands.empty())
|
|
|
|
OS << ", ";
|
|
|
|
Operands.PrintParameters(OS);
|
2014-10-01 22:44:01 +00:00
|
|
|
OS << ") ";
|
|
|
|
if (!Operands.hasAnyImmediateCodes())
|
|
|
|
OS << "override ";
|
|
|
|
OS << "{\n";
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2013-08-29 22:41:43 +00:00
|
|
|
// If there are any forms of this signature available that operate on
|
|
|
|
// constrained forms of the immediate (e.g., 32-bit sext immediate in a
|
2011-04-18 06:22:33 +00:00
|
|
|
// 64-bit operand), check them first.
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
std::map<OperandsSignature, std::vector<OperandsSignature>>::iterator MI =
|
|
|
|
SignaturesWithConstantForms.find(Operands);
|
|
|
|
if (MI != SignaturesWithConstantForms.end()) {
|
|
|
|
// Unique any duplicates out of the list.
|
2018-09-30 22:31:29 +00:00
|
|
|
llvm::sort(MI->second);
|
2024-06-02 11:52:12 -07:00
|
|
|
MI->second.erase(llvm::unique(MI->second), MI->second.end());
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
// Check each in order it was seen. It would be nice to have a good
|
|
|
|
// relative ordering between them, but we're not going for optimality
|
|
|
|
// here.
|
|
|
|
for (unsigned i = 0, e = MI->second.size(); i != e; ++i) {
|
|
|
|
OS << " if (";
|
|
|
|
MI->second[i].emitImmediatePredicate(OS, ImmediatePredicates);
|
2014-09-03 20:56:59 +00:00
|
|
|
OS << ")\n if (unsigned Reg = fastEmit_";
|
2011-04-18 06:22:33 +00:00
|
|
|
MI->second[i].PrintManglingSuffix(OS, ImmediatePredicates);
|
|
|
|
OS << "(VT, RetVT, Opcode";
|
|
|
|
if (!MI->second[i].empty())
|
|
|
|
OS << ", ";
|
|
|
|
MI->second[i].PrintArguments(OS);
|
|
|
|
OS << "))\n return Reg;\n\n";
|
|
|
|
}
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
// Done with this, remove it.
|
|
|
|
SignaturesWithConstantForms.erase(MI);
|
|
|
|
}
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2008-08-13 20:19:35 +00:00
|
|
|
OS << " switch (Opcode) {\n";
|
2021-05-06 18:36:52 +08:00
|
|
|
for (const auto &I : OTM) {
|
|
|
|
const std::string &Opcode = I.first;
|
2008-08-13 20:19:35 +00:00
|
|
|
|
2014-09-03 20:56:59 +00:00
|
|
|
OS << " case " << Opcode << ": return fastEmit_" << getLegalCName(Opcode)
|
2008-08-21 01:41:07 +00:00
|
|
|
<< "_";
|
2011-04-18 06:22:33 +00:00
|
|
|
Operands.PrintManglingSuffix(OS, ImmediatePredicates);
|
2008-08-25 23:58:18 +00:00
|
|
|
OS << "(VT, RetVT";
|
2008-08-13 20:19:35 +00:00
|
|
|
if (!Operands.empty())
|
|
|
|
OS << ", ";
|
|
|
|
Operands.PrintArguments(OS);
|
|
|
|
OS << ");\n";
|
|
|
|
}
|
|
|
|
OS << " default: return 0;\n";
|
|
|
|
OS << " }\n";
|
|
|
|
OS << "}\n";
|
|
|
|
OS << "\n";
|
|
|
|
}
|
2013-08-29 22:41:39 +00:00
|
|
|
|
2011-04-18 06:22:33 +00:00
|
|
|
// TODO: SignaturesWithConstantForms should be empty here.
|
2008-08-26 21:21:20 +00:00
|
|
|
}
|
|
|
|
|
2024-09-18 09:58:04 -07:00
|
|
|
static void EmitFastISel(const RecordKeeper &RK, raw_ostream &OS) {
|
|
|
|
const CodeGenDAGPatterns CGP(RK);
|
2008-08-26 21:21:20 +00:00
|
|
|
const CodeGenTarget &Target = CGP.getTargetInfo();
|
2012-06-11 15:37:55 +00:00
|
|
|
emitSourceFileHeader("\"Fast\" Instruction Selector for the " +
|
2016-12-04 05:48:16 +00:00
|
|
|
Target.getName().str() + " target",
|
|
|
|
OS);
|
2008-08-26 21:21:20 +00:00
|
|
|
|
|
|
|
// Determine the target's namespace name.
|
2017-07-07 06:22:36 +00:00
|
|
|
StringRef InstNS = Target.getInstNamespace();
|
|
|
|
assert(!InstNS.empty() && "Can't determine target-specific namespace!");
|
2008-08-26 21:21:20 +00:00
|
|
|
|
|
|
|
FastISelMap F(InstNS);
|
2011-04-18 06:22:33 +00:00
|
|
|
F.collectPatterns(CGP);
|
|
|
|
F.printImmediatePredicates(OS);
|
|
|
|
F.printFunctionDefinitions(OS);
|
2008-08-21 00:19:05 +00:00
|
|
|
}
|
|
|
|
|
2023-02-19 14:30:14 +09:00
|
|
|
static TableGen::Emitter::Opt X("gen-fast-isel", EmitFastISel,
|
|
|
|
"Generate a \"fast\" instruction selector");
|