2009-07-11 21:39:44 +02:00
|
|
|
//===- AsmMatcherEmitter.cpp - Generate an assembly matcher ---------------===//
|
|
|
|
//
|
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
|
2009-07-11 21:39:44 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This tablegen backend emits a target specifier matcher for converting parsed
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
// assembly operands in the MCInst structures. It also emits a matcher for
|
|
|
|
// custom operand parsing.
|
|
|
|
//
|
|
|
|
// Converting assembly operands into MCInst structures
|
|
|
|
// ---------------------------------------------------
|
2009-07-11 21:39:44 +02:00
|
|
|
//
|
2009-08-07 10:26:05 +02:00
|
|
|
// The input to the target specific matcher is a list of literal tokens and
|
|
|
|
// operands. The target specific parser should generally eliminate any syntax
|
|
|
|
// which is not relevant for matching; for example, comma tokens should have
|
|
|
|
// already been consumed and eliminated by the parser. Most instructions will
|
|
|
|
// end up with a single literal token (the instruction name) and some number of
|
|
|
|
// operands.
|
|
|
|
//
|
|
|
|
// Some example inputs, for X86:
|
|
|
|
// 'addl' (immediate ...) (register ...)
|
|
|
|
// 'add' (immediate ...) (memory ...)
|
2010-10-30 00:13:48 +02:00
|
|
|
// 'call' '*' %epc
|
2009-08-07 10:26:05 +02:00
|
|
|
//
|
|
|
|
// The assembly matcher is responsible for converting this input into a precise
|
|
|
|
// machine instruction (i.e., an instruction with a well defined encoding). This
|
|
|
|
// mapping has several properties which complicate matching:
|
|
|
|
//
|
|
|
|
// - It may be ambiguous; many architectures can legally encode particular
|
|
|
|
// variants of an instruction in different ways (for example, using a smaller
|
|
|
|
// encoding for small immediates). Such ambiguities should never be
|
|
|
|
// arbitrarily resolved by the assembler, the assembler is always responsible
|
|
|
|
// for choosing the "best" available instruction.
|
|
|
|
//
|
|
|
|
// - It may depend on the subtarget or the assembler context. Instructions
|
|
|
|
// which are invalid for the current mode, but otherwise unambiguous (e.g.,
|
|
|
|
// an SSE instruction in a file being assembled for i486) should be accepted
|
|
|
|
// and rejected by the assembler front end. However, if the proper encoding
|
|
|
|
// for an instruction is dependent on the assembler context then the matcher
|
|
|
|
// is responsible for selecting the correct machine instruction for the
|
|
|
|
// current mode.
|
|
|
|
//
|
|
|
|
// The core matching algorithm attempts to exploit the regularity in most
|
|
|
|
// instruction sets to quickly determine the set of possibly matching
|
|
|
|
// instructions, and the simplify the generated code. Additionally, this helps
|
|
|
|
// to ensure that the ambiguities are intentionally resolved by the user.
|
|
|
|
//
|
|
|
|
// The matching is divided into two distinct phases:
|
|
|
|
//
|
|
|
|
// 1. Classification: Each operand is mapped to the unique set which (a)
|
|
|
|
// contains it, and (b) is the largest such subset for which a single
|
|
|
|
// instruction could match all members.
|
|
|
|
//
|
|
|
|
// For register classes, we can generate these subgroups automatically. For
|
|
|
|
// arbitrary operands, we expect the user to define the classes and their
|
|
|
|
// relations to one another (for example, 8-bit signed immediates as a
|
|
|
|
// subset of 32-bit immediates).
|
|
|
|
//
|
|
|
|
// By partitioning the operands in this way, we guarantee that for any
|
|
|
|
// tuple of classes, any single instruction must match either all or none
|
|
|
|
// of the sets of operands which could classify to that tuple.
|
|
|
|
//
|
|
|
|
// In addition, the subset relation amongst classes induces a partial order
|
|
|
|
// on such tuples, which we use to resolve ambiguities.
|
|
|
|
//
|
|
|
|
// 2. The input can now be treated as a tuple of classes (static tokens are
|
|
|
|
// simple singleton sets). Each such tuple should generally map to a single
|
|
|
|
// instruction (we currently ignore cases where this isn't true, whee!!!),
|
|
|
|
// which we can emit a simple matcher for.
|
|
|
|
//
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
// Custom Operand Parsing
|
|
|
|
// ----------------------
|
|
|
|
//
|
|
|
|
// Some targets need a custom way to parse operands, some specific instructions
|
|
|
|
// can contain arguments that can represent processor flags and other kinds of
|
2012-09-18 03:13:36 +02:00
|
|
|
// identifiers that need to be mapped to specific values in the final encoded
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
// instructions. The target specific custom operand parsing works in the
|
|
|
|
// following way:
|
|
|
|
//
|
|
|
|
// 1. A operand match table is built, each entry contains a mnemonic, an
|
|
|
|
// operand class, a mask for all operand positions for that same
|
|
|
|
// class/mnemonic and target features to be checked while trying to match.
|
|
|
|
//
|
|
|
|
// 2. The operand matcher will try every possible entry with the same
|
|
|
|
// mnemonic and will check if the target feature for this mnemonic also
|
|
|
|
// matches. After that, if the operand to be matched has its index
|
2011-04-15 07:18:47 +02:00
|
|
|
// present in the mask, a successful match occurs. Otherwise, fallback
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
// to the regular operand parsing.
|
|
|
|
//
|
|
|
|
// 3. For a match success, each operand class that has a 'ParserMethod'
|
|
|
|
// becomes part of a switch from where the custom method is called.
|
|
|
|
//
|
2009-07-11 21:39:44 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CodeGenTarget.h"
|
2016-11-15 10:51:02 +01:00
|
|
|
#include "SubtargetFeatureInfo.h"
|
2016-11-19 13:21:34 +01:00
|
|
|
#include "Types.h"
|
2016-10-21 23:45:01 +02:00
|
|
|
#include "llvm/ADT/CachedHashString.h"
|
2010-11-04 03:11:18 +01:00
|
|
|
#include "llvm/ADT/PointerUnion.h"
|
2012-12-04 11:37:14 +01:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2010-11-01 02:47:07 +01:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2009-07-31 04:32:59 +02:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2009-08-07 10:26:05 +02:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2018-04-30 16:59:11 +02:00
|
|
|
#include "llvm/Config/llvm-config.h"
|
2009-08-07 10:26:05 +02:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2009-07-31 04:32:59 +02:00
|
|
|
#include "llvm/Support/Debug.h"
|
2012-02-05 08:21:30 +01:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2011-10-01 18:41:13 +02:00
|
|
|
#include "llvm/TableGen/Error.h"
|
|
|
|
#include "llvm/TableGen/Record.h"
|
2012-05-02 19:32:48 +02:00
|
|
|
#include "llvm/TableGen/StringMatcher.h"
|
2013-08-29 07:09:55 +02:00
|
|
|
#include "llvm/TableGen/StringToOffsetTable.h"
|
2012-06-11 17:37:55 +02:00
|
|
|
#include "llvm/TableGen/TableGenBackend.h"
|
|
|
|
#include <cassert>
|
2013-10-12 02:55:57 +02:00
|
|
|
#include <cctype>
|
2016-04-18 11:17:29 +02:00
|
|
|
#include <forward_list>
|
2009-08-08 07:24:34 +02:00
|
|
|
#include <map>
|
|
|
|
#include <set>
|
2016-02-02 19:20:45 +01:00
|
|
|
|
2009-07-11 21:39:44 +02:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 00:55:11 +02:00
|
|
|
#define DEBUG_TYPE "asm-matcher-emitter"
|
|
|
|
|
2017-03-27 15:15:13 +02:00
|
|
|
cl::OptionCategory AsmMatcherEmitterCat("Options for -gen-asm-matcher");
|
|
|
|
|
2009-08-07 22:33:39 +02:00
|
|
|
static cl::opt<std::string>
|
2017-03-27 15:15:13 +02:00
|
|
|
MatchPrefix("match-prefix", cl::init(""),
|
|
|
|
cl::desc("Only match instructions with the given prefix"),
|
|
|
|
cl::cat(AsmMatcherEmitterCat));
|
2009-08-07 10:26:05 +02:00
|
|
|
|
|
|
|
namespace {
|
2011-01-26 22:26:19 +01:00
|
|
|
class AsmMatcherInfo;
|
2010-07-19 07:44:09 +02:00
|
|
|
|
2013-09-16 18:43:19 +02:00
|
|
|
// Register sets are used as keys in some second-order sets TableGen creates
|
|
|
|
// when generating its data structures. This means that the order of two
|
|
|
|
// RegisterSets can be seen in the outputted AsmMatcher tables occasionally, and
|
|
|
|
// can even affect compiler output (at least seen in diagnostics produced when
|
|
|
|
// all matches fail). So we use a type that sorts them consistently.
|
|
|
|
typedef std::set<Record*, LessRecordByID> RegisterSet;
|
|
|
|
|
2012-06-11 17:37:55 +02:00
|
|
|
class AsmMatcherEmitter {
|
|
|
|
RecordKeeper &Records;
|
|
|
|
public:
|
|
|
|
AsmMatcherEmitter(RecordKeeper &R) : Records(R) {}
|
|
|
|
|
|
|
|
void run(raw_ostream &o);
|
|
|
|
};
|
|
|
|
|
2009-08-08 09:50:56 +02:00
|
|
|
/// ClassInfo - Helper class for storing the information about a particular
|
|
|
|
/// class of operands which can be matched.
|
|
|
|
struct ClassInfo {
|
2009-08-09 06:00:06 +02:00
|
|
|
enum ClassInfoKind {
|
2009-08-11 04:59:53 +02:00
|
|
|
/// Invalid kind, for use as a sentinel value.
|
|
|
|
Invalid = 0,
|
|
|
|
|
|
|
|
/// The class for a particular token.
|
|
|
|
Token,
|
|
|
|
|
|
|
|
/// The (first) register class, subsequent register classes are
|
|
|
|
/// RegisterClass0+1, and so on.
|
|
|
|
RegisterClass0,
|
|
|
|
|
|
|
|
/// The (first) user defined class, subsequent user defined classes are
|
|
|
|
/// UserClass0+1, and so on.
|
|
|
|
UserClass0 = 1<<16
|
2009-08-09 06:00:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Kind - The class kind, which is either a predefined kind, or (UserClass0 +
|
|
|
|
/// N) for the Nth user defined class.
|
|
|
|
unsigned Kind;
|
2009-08-08 09:50:56 +02:00
|
|
|
|
2009-08-11 04:59:53 +02:00
|
|
|
/// SuperClasses - The super classes of this class. Note that for simplicities
|
|
|
|
/// sake user operands only record their immediate super class, while register
|
|
|
|
/// operands include all superclasses.
|
|
|
|
std::vector<ClassInfo*> SuperClasses;
|
2009-08-09 09:20:21 +02:00
|
|
|
|
2009-08-09 07:18:30 +02:00
|
|
|
/// Name - The full class name, suitable for use in an enum.
|
2009-08-08 09:50:56 +02:00
|
|
|
std::string Name;
|
|
|
|
|
2009-08-09 07:18:30 +02:00
|
|
|
/// ClassName - The unadorned generic name for this class (e.g., Token).
|
|
|
|
std::string ClassName;
|
|
|
|
|
2009-08-08 09:50:56 +02:00
|
|
|
/// ValueName - The name of the value this class represents; for a token this
|
|
|
|
/// is the literal token string, for an operand it is the TableGen class (or
|
|
|
|
/// empty if this is a derived class).
|
|
|
|
std::string ValueName;
|
|
|
|
|
|
|
|
/// PredicateMethod - The name of the operand method to test whether the
|
2009-08-11 04:59:53 +02:00
|
|
|
/// operand matches this class; this is not valid for Token or register kinds.
|
2009-08-08 09:50:56 +02:00
|
|
|
std::string PredicateMethod;
|
|
|
|
|
|
|
|
/// RenderMethod - The name of the operand method to add this operand to an
|
2009-08-11 04:59:53 +02:00
|
|
|
/// MCInst; this is not valid for Token or register kinds.
|
2009-08-08 09:50:56 +02:00
|
|
|
std::string RenderMethod;
|
2009-08-09 06:00:06 +02:00
|
|
|
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
/// ParserMethod - The name of the operand method to do a target specific
|
|
|
|
/// parsing on the operand.
|
|
|
|
std::string ParserMethod;
|
|
|
|
|
2014-05-20 19:11:11 +02:00
|
|
|
/// For register classes: the records for all the registers in this class.
|
2013-09-16 18:43:19 +02:00
|
|
|
RegisterSet Registers;
|
2009-08-11 22:10:07 +02:00
|
|
|
|
2014-05-20 19:11:11 +02:00
|
|
|
/// For custom match classes: the diagnostic kind for when the predicate fails.
|
2012-06-23 01:56:44 +02:00
|
|
|
std::string DiagnosticType;
|
2016-02-05 20:59:33 +01:00
|
|
|
|
2017-10-03 16:34:57 +02:00
|
|
|
/// For custom match classes: the diagnostic string for when the predicate fails.
|
|
|
|
std::string DiagnosticString;
|
|
|
|
|
2016-02-05 20:59:33 +01:00
|
|
|
/// Is this operand optional and not always required.
|
|
|
|
bool IsOptional;
|
|
|
|
|
2016-05-06 13:31:17 +02:00
|
|
|
/// DefaultMethod - The name of the method that returns the default operand
|
|
|
|
/// for optional operand
|
|
|
|
std::string DefaultMethod;
|
|
|
|
|
2009-08-11 22:10:07 +02:00
|
|
|
public:
|
2009-08-11 04:59:53 +02:00
|
|
|
/// isRegisterClass() - Check if this is a register class.
|
|
|
|
bool isRegisterClass() const {
|
|
|
|
return Kind >= RegisterClass0 && Kind < UserClass0;
|
|
|
|
}
|
|
|
|
|
2009-08-09 09:20:21 +02:00
|
|
|
/// isUserClass() - Check if this is a user defined class.
|
|
|
|
bool isUserClass() const {
|
|
|
|
return Kind >= UserClass0;
|
|
|
|
}
|
|
|
|
|
2012-09-15 22:22:05 +02:00
|
|
|
/// isRelatedTo - Check whether this class is "related" to \p RHS. Classes
|
2009-08-11 04:59:53 +02:00
|
|
|
/// are related if they are in the same class hierarchy.
|
|
|
|
bool isRelatedTo(const ClassInfo &RHS) const {
|
|
|
|
// Tokens are only related to tokens.
|
|
|
|
if (Kind == Token || RHS.Kind == Token)
|
|
|
|
return Kind == Token && RHS.Kind == Token;
|
|
|
|
|
2009-08-11 22:10:07 +02:00
|
|
|
// Registers classes are only related to registers classes, and only if
|
|
|
|
// their intersection is non-empty.
|
|
|
|
if (isRegisterClass() || RHS.isRegisterClass()) {
|
|
|
|
if (!isRegisterClass() || !RHS.isRegisterClass())
|
|
|
|
return false;
|
|
|
|
|
2013-09-16 18:43:19 +02:00
|
|
|
RegisterSet Tmp;
|
|
|
|
std::insert_iterator<RegisterSet> II(Tmp, Tmp.begin());
|
2010-10-30 00:13:48 +02:00
|
|
|
std::set_intersection(Registers.begin(), Registers.end(),
|
2009-08-11 22:10:07 +02:00
|
|
|
RHS.Registers.begin(), RHS.Registers.end(),
|
2013-09-16 18:43:19 +02:00
|
|
|
II, LessRecordByID());
|
2009-08-11 22:10:07 +02:00
|
|
|
|
|
|
|
return !Tmp.empty();
|
|
|
|
}
|
2009-08-11 04:59:53 +02:00
|
|
|
|
|
|
|
// Otherwise we have two users operands; they are related if they are in the
|
|
|
|
// same class hierarchy.
|
2009-08-11 22:10:07 +02:00
|
|
|
//
|
|
|
|
// FIXME: This is an oversimplification, they should only be related if they
|
|
|
|
// intersect, however we don't have that information.
|
2009-08-11 04:59:53 +02:00
|
|
|
assert(isUserClass() && RHS.isUserClass() && "Unexpected class!");
|
|
|
|
const ClassInfo *Root = this;
|
|
|
|
while (!Root->SuperClasses.empty())
|
|
|
|
Root = Root->SuperClasses.front();
|
|
|
|
|
2009-08-11 22:10:07 +02:00
|
|
|
const ClassInfo *RHSRoot = &RHS;
|
2009-08-11 04:59:53 +02:00
|
|
|
while (!RHSRoot->SuperClasses.empty())
|
|
|
|
RHSRoot = RHSRoot->SuperClasses.front();
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2009-08-11 04:59:53 +02:00
|
|
|
return Root == RHSRoot;
|
|
|
|
}
|
|
|
|
|
2012-09-15 22:22:05 +02:00
|
|
|
/// isSubsetOf - Test whether this class is a subset of \p RHS.
|
2009-08-11 04:59:53 +02:00
|
|
|
bool isSubsetOf(const ClassInfo &RHS) const {
|
|
|
|
// This is a subset of RHS if it is the same class...
|
|
|
|
if (this == &RHS)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// ... or if any of its super classes are a subset of RHS.
|
2018-07-13 18:36:14 +02:00
|
|
|
SmallVector<const ClassInfo *, 16> Worklist(SuperClasses.begin(),
|
|
|
|
SuperClasses.end());
|
|
|
|
SmallPtrSet<const ClassInfo *, 16> Visited;
|
|
|
|
while (!Worklist.empty()) {
|
|
|
|
auto *CI = Worklist.pop_back_val();
|
|
|
|
if (CI == &RHS)
|
2009-08-11 04:59:53 +02:00
|
|
|
return true;
|
2018-07-13 18:36:14 +02:00
|
|
|
for (auto *Super : CI->SuperClasses)
|
|
|
|
if (Visited.insert(Super).second)
|
|
|
|
Worklist.push_back(Super);
|
|
|
|
}
|
2009-08-11 04:59:53 +02:00
|
|
|
|
|
|
|
return false;
|
2009-08-09 09:20:21 +02:00
|
|
|
}
|
|
|
|
|
2016-01-25 11:20:19 +01:00
|
|
|
int getTreeDepth() const {
|
|
|
|
int Depth = 0;
|
|
|
|
const ClassInfo *Root = this;
|
|
|
|
while (!Root->SuperClasses.empty()) {
|
|
|
|
Depth++;
|
|
|
|
Root = Root->SuperClasses.front();
|
|
|
|
}
|
|
|
|
return Depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ClassInfo *findRoot() const {
|
|
|
|
const ClassInfo *Root = this;
|
|
|
|
while (!Root->SuperClasses.empty())
|
|
|
|
Root = Root->SuperClasses.front();
|
|
|
|
return Root;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Compare two classes. This does not produce a total ordering, but does
|
|
|
|
/// guarantee that subclasses are sorted before their parents, and that the
|
|
|
|
/// ordering is transitive.
|
2009-08-09 06:00:06 +02:00
|
|
|
bool operator<(const ClassInfo &RHS) const {
|
2010-05-27 07:31:32 +02:00
|
|
|
if (this == &RHS)
|
|
|
|
return false;
|
|
|
|
|
2016-01-25 11:20:19 +01:00
|
|
|
// First, enforce the ordering between the three different types of class.
|
|
|
|
// Tokens sort before registers, which sort before user classes.
|
|
|
|
if (Kind == Token) {
|
|
|
|
if (RHS.Kind != Token)
|
2010-07-12 10:16:59 +02:00
|
|
|
return true;
|
2016-01-25 11:20:19 +01:00
|
|
|
assert(RHS.Kind == Token);
|
|
|
|
} else if (isRegisterClass()) {
|
|
|
|
if (RHS.Kind == Token)
|
2010-07-12 10:16:59 +02:00
|
|
|
return false;
|
2016-01-25 11:20:19 +01:00
|
|
|
else if (RHS.isUserClass())
|
|
|
|
return true;
|
|
|
|
assert(RHS.isRegisterClass());
|
|
|
|
} else if (isUserClass()) {
|
|
|
|
if (!RHS.isUserClass())
|
|
|
|
return false;
|
|
|
|
assert(RHS.isUserClass());
|
|
|
|
} else {
|
|
|
|
llvm_unreachable("Unknown ClassInfoKind");
|
|
|
|
}
|
2010-05-27 07:31:32 +02:00
|
|
|
|
2016-01-25 11:20:19 +01:00
|
|
|
if (Kind == Token || isUserClass()) {
|
|
|
|
// Related tokens and user classes get sorted by depth in the inheritence
|
|
|
|
// tree (so that subclasses are before their parents).
|
|
|
|
if (isRelatedTo(RHS)) {
|
|
|
|
if (getTreeDepth() > RHS.getTreeDepth())
|
|
|
|
return true;
|
|
|
|
if (getTreeDepth() < RHS.getTreeDepth())
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
// Unrelated tokens and user classes are ordered by the name of their
|
|
|
|
// root nodes, so that there is a consistent ordering between
|
|
|
|
// unconnected trees.
|
|
|
|
return findRoot()->ValueName < RHS.findRoot()->ValueName;
|
|
|
|
}
|
|
|
|
} else if (isRegisterClass()) {
|
|
|
|
// For register sets, sort by number of registers. This guarantees that
|
|
|
|
// a set will always sort before all of it's strict supersets.
|
|
|
|
if (Registers.size() != RHS.Registers.size())
|
|
|
|
return Registers.size() < RHS.Registers.size();
|
|
|
|
} else {
|
|
|
|
llvm_unreachable("Unknown ClassInfoKind");
|
2009-08-09 06:00:06 +02:00
|
|
|
}
|
2016-01-25 11:20:19 +01:00
|
|
|
|
|
|
|
// FIXME: We should be able to just return false here, as we only need a
|
|
|
|
// partial order (we use stable sorts, so this is deterministic) and the
|
|
|
|
// name of a class shouldn't be significant. However, some of the backends
|
|
|
|
// accidentally rely on this behaviour, so it will have to stay like this
|
|
|
|
// until they are fixed.
|
|
|
|
return ValueName < RHS.ValueName;
|
2009-08-09 06:00:06 +02:00
|
|
|
}
|
2009-08-08 09:50:56 +02:00
|
|
|
};
|
|
|
|
|
2015-11-09 01:31:07 +01:00
|
|
|
class AsmVariantInfo {
|
|
|
|
public:
|
2017-05-31 23:12:46 +02:00
|
|
|
StringRef RegisterPrefix;
|
|
|
|
StringRef TokenizingCharacters;
|
|
|
|
StringRef SeparatorCharacters;
|
|
|
|
StringRef BreakCharacters;
|
|
|
|
StringRef Name;
|
2015-12-30 07:00:18 +01:00
|
|
|
int AsmVariantNo;
|
2015-11-09 01:31:07 +01:00
|
|
|
};
|
|
|
|
|
2010-11-01 06:06:45 +01:00
|
|
|
/// MatchableInfo - Helper class for storing the necessary information for an
|
|
|
|
/// instruction or alias which is capable of being matched.
|
|
|
|
struct MatchableInfo {
|
2010-11-03 20:47:34 +01:00
|
|
|
struct AsmOperand {
|
2010-11-02 18:30:52 +01:00
|
|
|
/// Token - This is the token that the operand came from.
|
|
|
|
StringRef Token;
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2009-08-08 09:50:56 +02:00
|
|
|
/// The unique class instance this operand should match.
|
|
|
|
ClassInfo *Class;
|
|
|
|
|
2010-11-04 02:42:59 +01:00
|
|
|
/// The operand name this is, if anything.
|
|
|
|
StringRef SrcOpName;
|
2011-01-26 20:44:55 +01:00
|
|
|
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
/// The operand name this is, before renaming for tied operands.
|
|
|
|
StringRef OrigSrcOpName;
|
|
|
|
|
2011-01-26 20:44:55 +01:00
|
|
|
/// The suboperand index within SrcOpName, or -1 for the entire operand.
|
|
|
|
int SubOpIdx;
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2015-05-29 03:03:37 +02:00
|
|
|
/// Whether the token is "isolated", i.e., it is preceded and followed
|
|
|
|
/// by separators.
|
|
|
|
bool IsIsolatedToken;
|
|
|
|
|
2012-01-07 02:33:34 +01:00
|
|
|
/// Register record if this token is singleton register.
|
|
|
|
Record *SingletonReg;
|
|
|
|
|
2015-05-29 03:03:37 +02:00
|
|
|
explicit AsmOperand(bool IsIsolatedToken, StringRef T)
|
|
|
|
: Token(T), Class(nullptr), SubOpIdx(-1),
|
|
|
|
IsIsolatedToken(IsIsolatedToken), SingletonReg(nullptr) {}
|
2009-08-07 10:26:05 +02:00
|
|
|
};
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-11-04 01:43:46 +01:00
|
|
|
/// ResOperand - This represents a single operand in the result instruction
|
|
|
|
/// generated by the match. In cases (like addressing modes) where a single
|
|
|
|
/// assembler operand expands to multiple MCOperands, this represents the
|
|
|
|
/// single assembler operand, not the MCOperand.
|
|
|
|
struct ResOperand {
|
|
|
|
enum {
|
|
|
|
/// RenderAsmOperand - This represents an operand result that is
|
|
|
|
/// generated by calling the render method on the assembly operand. The
|
|
|
|
/// corresponding AsmOperand is specified by AsmOperandNum.
|
|
|
|
RenderAsmOperand,
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-11-04 01:43:46 +01:00
|
|
|
/// TiedOperand - This represents a result operand that is a duplicate of
|
|
|
|
/// a previous result operand.
|
2010-11-06 20:25:43 +01:00
|
|
|
TiedOperand,
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-11-06 20:25:43 +01:00
|
|
|
/// ImmOperand - This represents an immediate value that is dumped into
|
|
|
|
/// the operand.
|
2010-11-06 20:57:21 +01:00
|
|
|
ImmOperand,
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-11-06 20:57:21 +01:00
|
|
|
/// RegOperand - This represents a fixed register that is dumped in.
|
|
|
|
RegOperand
|
2010-11-04 01:43:46 +01:00
|
|
|
} Kind;
|
2011-01-26 22:26:19 +01:00
|
|
|
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
/// Tuple containing the index of the (earlier) result operand that should
|
|
|
|
/// be copied from, as well as the indices of the corresponding (parsed)
|
|
|
|
/// operands in the asm string.
|
|
|
|
struct TiedOperandsTuple {
|
|
|
|
unsigned ResOpnd;
|
|
|
|
unsigned SrcOpnd1Idx;
|
|
|
|
unsigned SrcOpnd2Idx;
|
|
|
|
};
|
|
|
|
|
2010-11-04 01:43:46 +01:00
|
|
|
union {
|
|
|
|
/// This is the operand # in the AsmOperands list that this should be
|
|
|
|
/// copied from.
|
|
|
|
unsigned AsmOperandNum;
|
2011-01-26 22:26:19 +01:00
|
|
|
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
/// Description of tied operands.
|
|
|
|
TiedOperandsTuple TiedOperands;
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-11-06 20:25:43 +01:00
|
|
|
/// ImmVal - This is the immediate value added to the instruction.
|
|
|
|
int64_t ImmVal;
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-11-06 20:57:21 +01:00
|
|
|
/// Register - This is the register record.
|
|
|
|
Record *Register;
|
2010-11-04 01:43:46 +01:00
|
|
|
};
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2011-01-26 20:44:55 +01:00
|
|
|
/// MINumOperands - The number of MCInst operands populated by this
|
|
|
|
/// operand.
|
|
|
|
unsigned MINumOperands;
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2011-01-26 20:44:55 +01:00
|
|
|
static ResOperand getRenderedOp(unsigned AsmOpNum, unsigned NumOperands) {
|
2010-11-04 01:43:46 +01:00
|
|
|
ResOperand X;
|
|
|
|
X.Kind = RenderAsmOperand;
|
|
|
|
X.AsmOperandNum = AsmOpNum;
|
2011-01-26 20:44:55 +01:00
|
|
|
X.MINumOperands = NumOperands;
|
2010-11-04 01:43:46 +01:00
|
|
|
return X;
|
|
|
|
}
|
2011-01-26 22:26:19 +01:00
|
|
|
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
static ResOperand getTiedOp(unsigned TiedOperandNum, unsigned SrcOperand1,
|
|
|
|
unsigned SrcOperand2) {
|
2010-11-04 01:43:46 +01:00
|
|
|
ResOperand X;
|
|
|
|
X.Kind = TiedOperand;
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
X.TiedOperands = { TiedOperandNum, SrcOperand1, SrcOperand2 };
|
2011-01-26 20:44:55 +01:00
|
|
|
X.MINumOperands = 1;
|
2010-11-04 01:43:46 +01:00
|
|
|
return X;
|
|
|
|
}
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2011-01-26 20:44:55 +01:00
|
|
|
static ResOperand getImmOp(int64_t Val) {
|
2010-11-06 20:25:43 +01:00
|
|
|
ResOperand X;
|
|
|
|
X.Kind = ImmOperand;
|
|
|
|
X.ImmVal = Val;
|
2011-01-26 20:44:55 +01:00
|
|
|
X.MINumOperands = 1;
|
2010-11-06 20:25:43 +01:00
|
|
|
return X;
|
|
|
|
}
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2011-01-26 20:44:55 +01:00
|
|
|
static ResOperand getRegOp(Record *Reg) {
|
2010-11-06 20:57:21 +01:00
|
|
|
ResOperand X;
|
|
|
|
X.Kind = RegOperand;
|
|
|
|
X.Register = Reg;
|
2011-01-26 20:44:55 +01:00
|
|
|
X.MINumOperands = 1;
|
2010-11-06 20:57:21 +01:00
|
|
|
return X;
|
|
|
|
}
|
2010-11-04 01:43:46 +01:00
|
|
|
};
|
2009-08-07 10:26:05 +02:00
|
|
|
|
2012-01-10 18:50:43 +01:00
|
|
|
/// AsmVariantID - Target's assembly syntax variant no.
|
|
|
|
int AsmVariantID;
|
|
|
|
|
2014-12-22 22:26:26 +01:00
|
|
|
/// AsmString - The assembly string for this instruction (with variants
|
|
|
|
/// removed), e.g. "movsx $src, $dst".
|
|
|
|
std::string AsmString;
|
|
|
|
|
2010-11-02 18:34:28 +01:00
|
|
|
/// TheDef - This is the definition of the instruction or InstAlias that this
|
|
|
|
/// matchable came from.
|
2010-11-01 05:34:44 +01:00
|
|
|
Record *const TheDef;
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-11-04 03:11:18 +01:00
|
|
|
/// DefRec - This is the definition that it came from.
|
|
|
|
PointerUnion<const CodeGenInstruction*, const CodeGenInstAlias*> DefRec;
|
2011-01-26 22:26:19 +01:00
|
|
|
|
Reimplement BuildResultOperands to be in terms of the result instruction's
operand list instead of the operand list redundantly declared on the alias
or instruction.
With this change, we finally remove the ins/outs list on the alias. Before:
def : InstAlias<(outs GR16:$dst), (ins GR8 :$src),
"movsx $src, $dst",
(MOVSX16rr8W GR16:$dst, GR8:$src)>;
After:
def : InstAlias<"movsx $src, $dst",
(MOVSX16rr8W GR16:$dst, GR8:$src)>;
This also makes the alias mechanism more general and powerful, which will
be exploited in subsequent patches.
llvm-svn: 118329
2010-11-06 08:14:44 +01:00
|
|
|
const CodeGenInstruction *getResultInst() const {
|
|
|
|
if (DefRec.is<const CodeGenInstruction*>())
|
|
|
|
return DefRec.get<const CodeGenInstruction*>();
|
|
|
|
return DefRec.get<const CodeGenInstAlias*>()->ResultInst;
|
|
|
|
}
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-11-04 01:43:46 +01:00
|
|
|
/// ResOperands - This is the operand list that should be built for the result
|
|
|
|
/// MCInst.
|
2012-04-19 19:52:34 +02:00
|
|
|
SmallVector<ResOperand, 8> ResOperands;
|
2009-08-07 10:26:05 +02:00
|
|
|
|
2010-11-02 18:30:52 +01:00
|
|
|
/// Mnemonic - This is the first token of the matched instruction, its
|
|
|
|
/// mnemonic.
|
|
|
|
StringRef Mnemonic;
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-11-02 02:03:43 +01:00
|
|
|
/// AsmOperands - The textual operands that this instruction matches,
|
2010-11-02 18:34:28 +01:00
|
|
|
/// annotated with a class and where in the OperandList they were defined.
|
|
|
|
/// This directly corresponds to the tokenized AsmString after the mnemonic is
|
|
|
|
/// removed.
|
2012-04-19 19:52:34 +02:00
|
|
|
SmallVector<AsmOperand, 8> AsmOperands;
|
2009-08-07 10:26:05 +02:00
|
|
|
|
2010-07-19 07:44:09 +02:00
|
|
|
/// Predicates - The required subtarget features to match this instruction.
|
2014-11-28 23:15:06 +01:00
|
|
|
SmallVector<const SubtargetFeatureInfo *, 4> RequiredFeatures;
|
2010-07-19 07:44:09 +02:00
|
|
|
|
2009-08-08 07:24:34 +02:00
|
|
|
/// ConversionFnKind - The enum value which is passed to the generated
|
2012-09-05 03:02:38 +02:00
|
|
|
/// convertToMCInst to convert parsed operands into an MCInst for this
|
2009-08-08 07:24:34 +02:00
|
|
|
/// function.
|
|
|
|
std::string ConversionFnKind;
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2013-09-12 12:28:05 +02:00
|
|
|
/// If this instruction is deprecated in some form.
|
|
|
|
bool HasDeprecation;
|
|
|
|
|
2015-05-26 17:55:50 +02:00
|
|
|
/// If this is an alias, this is use to determine whether or not to using
|
|
|
|
/// the conversion function defined by the instruction's AsmMatchConverter
|
|
|
|
/// or to use the function generated by the alias.
|
|
|
|
bool UseInstAsmMatchConverter;
|
|
|
|
|
2010-11-01 06:06:45 +01:00
|
|
|
MatchableInfo(const CodeGenInstruction &CGI)
|
2015-05-26 17:55:50 +02:00
|
|
|
: AsmVariantID(0), AsmString(CGI.AsmString), TheDef(CGI.TheDef), DefRec(&CGI),
|
|
|
|
UseInstAsmMatchConverter(true) {
|
2014-11-29 00:00:22 +01:00
|
|
|
}
|
2010-11-01 05:34:44 +01:00
|
|
|
|
2014-12-22 22:26:26 +01:00
|
|
|
MatchableInfo(std::unique_ptr<const CodeGenInstAlias> Alias)
|
2015-05-26 17:55:50 +02:00
|
|
|
: AsmVariantID(0), AsmString(Alias->AsmString), TheDef(Alias->TheDef),
|
|
|
|
DefRec(Alias.release()),
|
|
|
|
UseInstAsmMatchConverter(
|
|
|
|
TheDef->getValueAsBit("UseInstAsmMatchConverter")) {
|
2014-11-29 00:00:22 +01:00
|
|
|
}
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2015-08-01 03:08:30 +02:00
|
|
|
// Could remove this and the dtor if PointerUnion supported unique_ptr
|
|
|
|
// elements with a dynamic failure/assertion (like the one below) in the case
|
|
|
|
// where it was copied while being in an owning state.
|
|
|
|
MatchableInfo(const MatchableInfo &RHS)
|
|
|
|
: AsmVariantID(RHS.AsmVariantID), AsmString(RHS.AsmString),
|
|
|
|
TheDef(RHS.TheDef), DefRec(RHS.DefRec), ResOperands(RHS.ResOperands),
|
|
|
|
Mnemonic(RHS.Mnemonic), AsmOperands(RHS.AsmOperands),
|
|
|
|
RequiredFeatures(RHS.RequiredFeatures),
|
|
|
|
ConversionFnKind(RHS.ConversionFnKind),
|
|
|
|
HasDeprecation(RHS.HasDeprecation),
|
|
|
|
UseInstAsmMatchConverter(RHS.UseInstAsmMatchConverter) {
|
|
|
|
assert(!DefRec.is<const CodeGenInstAlias *>());
|
|
|
|
}
|
|
|
|
|
2014-11-29 00:00:22 +01:00
|
|
|
~MatchableInfo() {
|
2014-12-22 22:26:26 +01:00
|
|
|
delete DefRec.dyn_cast<const CodeGenInstAlias*>();
|
2014-11-29 00:00:22 +01:00
|
|
|
}
|
2014-11-28 06:01:21 +01:00
|
|
|
|
2012-04-20 01:59:23 +02:00
|
|
|
// Two-operand aliases clone from the main matchable, but mark the second
|
|
|
|
// operand as a tied operand of the first for purposes of the assembler.
|
|
|
|
void formTwoOperandAlias(StringRef Constraint);
|
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
void initialize(const AsmMatcherInfo &Info,
|
2014-08-21 07:55:13 +02:00
|
|
|
SmallPtrSetImpl<Record*> &SingletonRegisters,
|
2015-12-31 09:18:23 +01:00
|
|
|
AsmVariantInfo const &Variant,
|
|
|
|
bool HasMnemonicFirst);
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
/// validate - Return true if this matchable is a valid thing to match against
|
2010-11-01 06:06:45 +01:00
|
|
|
/// and perform a bunch of validity checking.
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
bool validate(StringRef CommentDelimiter, bool IsAlias) const;
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
/// findAsmOperand - Find the AsmOperand with the specified name and
|
2011-01-26 20:44:55 +01:00
|
|
|
/// suboperand index.
|
2012-04-19 19:52:32 +02:00
|
|
|
int findAsmOperand(StringRef N, int SubOpIdx) const {
|
2016-08-12 02:18:03 +02:00
|
|
|
auto I = find_if(AsmOperands, [&](const AsmOperand &Op) {
|
|
|
|
return Op.SrcOpName == N && Op.SubOpIdx == SubOpIdx;
|
|
|
|
});
|
2016-01-03 08:33:36 +01:00
|
|
|
return (I != AsmOperands.end()) ? I - AsmOperands.begin() : -1;
|
2011-01-26 20:44:55 +01:00
|
|
|
}
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
/// findAsmOperandNamed - Find the first AsmOperand with the specified name.
|
2011-01-26 20:44:55 +01:00
|
|
|
/// This does not check the suboperand index.
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
int findAsmOperandNamed(StringRef N, int LastIdx = -1) const {
|
|
|
|
auto I = std::find_if(AsmOperands.begin() + LastIdx + 1, AsmOperands.end(),
|
2016-08-12 02:18:03 +02:00
|
|
|
[&](const AsmOperand &Op) { return Op.SrcOpName == N; });
|
2016-01-03 08:33:36 +01:00
|
|
|
return (I != AsmOperands.end()) ? I - AsmOperands.begin() : -1;
|
2010-11-04 02:55:23 +01:00
|
|
|
}
|
2011-01-26 22:26:19 +01:00
|
|
|
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
int findAsmOperandOriginallyNamed(StringRef N) const {
|
|
|
|
auto I =
|
|
|
|
find_if(AsmOperands,
|
|
|
|
[&](const AsmOperand &Op) { return Op.OrigSrcOpName == N; });
|
|
|
|
return (I != AsmOperands.end()) ? I - AsmOperands.begin() : -1;
|
|
|
|
}
|
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
void buildInstructionResultOperands();
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
void buildAliasResultOperands(bool AliasConstraintsAreChecked);
|
2010-11-04 01:43:46 +01:00
|
|
|
|
2010-11-01 06:06:45 +01:00
|
|
|
/// operator< - Compare two matchables.
|
|
|
|
bool operator<(const MatchableInfo &RHS) const {
|
2010-09-06 23:01:37 +02:00
|
|
|
// The primary comparator is the instruction mnemonic.
|
2020-08-13 00:22:58 +02:00
|
|
|
if (int Cmp = Mnemonic.compare_lower(RHS.Mnemonic))
|
2016-06-23 19:09:49 +02:00
|
|
|
return Cmp == -1;
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2010-11-02 02:03:43 +01:00
|
|
|
if (AsmOperands.size() != RHS.AsmOperands.size())
|
|
|
|
return AsmOperands.size() < RHS.AsmOperands.size();
|
2009-08-09 08:05:33 +02:00
|
|
|
|
2009-08-09 10:23:23 +02:00
|
|
|
// Compare lexicographically by operand. The matcher validates that other
|
2012-04-19 19:52:32 +02:00
|
|
|
// orderings wouldn't be ambiguous using \see couldMatchAmbiguouslyWith().
|
2010-11-02 02:03:43 +01:00
|
|
|
for (unsigned i = 0, e = AsmOperands.size(); i != e; ++i) {
|
|
|
|
if (*AsmOperands[i].Class < *RHS.AsmOperands[i].Class)
|
2009-08-09 08:05:33 +02:00
|
|
|
return true;
|
2010-11-02 02:03:43 +01:00
|
|
|
if (*RHS.AsmOperands[i].Class < *AsmOperands[i].Class)
|
2009-08-09 10:23:23 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-29 05:52:57 +02:00
|
|
|
// Give matches that require more features higher precedence. This is useful
|
|
|
|
// because we cannot define AssemblerPredicates with the negation of
|
|
|
|
// processor features. For example, ARM v6 "nop" may be either a HINT or
|
|
|
|
// MOV. With v6, we want to match HINT. The assembler has no way to
|
|
|
|
// predicate MOV under "NoV6", but HINT will always match first because it
|
|
|
|
// requires V6 while MOV does not.
|
|
|
|
if (RequiredFeatures.size() != RHS.RequiredFeatures.size())
|
|
|
|
return RequiredFeatures.size() > RHS.RequiredFeatures.size();
|
|
|
|
|
2009-08-09 08:05:33 +02:00
|
|
|
return false;
|
|
|
|
}
|
2009-08-09 06:00:06 +02:00
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
/// couldMatchAmbiguouslyWith - Check whether this matchable could
|
2012-09-15 22:22:05 +02:00
|
|
|
/// ambiguously match the same set of operands as \p RHS (without being a
|
2009-08-09 08:05:33 +02:00
|
|
|
/// strictly superior match).
|
2014-11-28 04:53:00 +01:00
|
|
|
bool couldMatchAmbiguouslyWith(const MatchableInfo &RHS) const {
|
2010-11-02 00:57:23 +01:00
|
|
|
// The primary comparator is the instruction mnemonic.
|
2010-11-02 18:30:52 +01:00
|
|
|
if (Mnemonic != RHS.Mnemonic)
|
2010-11-02 00:57:23 +01:00
|
|
|
return false;
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2018-01-06 20:20:32 +01:00
|
|
|
// Different variants can't conflict.
|
|
|
|
if (AsmVariantID != RHS.AsmVariantID)
|
|
|
|
return false;
|
|
|
|
|
2009-08-09 08:05:33 +02:00
|
|
|
// The number of operands is unambiguous.
|
2010-11-02 02:03:43 +01:00
|
|
|
if (AsmOperands.size() != RHS.AsmOperands.size())
|
2009-08-09 08:05:33 +02:00
|
|
|
return false;
|
2009-08-09 06:00:06 +02:00
|
|
|
|
2010-01-23 01:26:16 +01:00
|
|
|
// Otherwise, make sure the ordering of the two instructions is unambiguous
|
|
|
|
// by checking that either (a) a token or operand kind discriminates them,
|
|
|
|
// or (b) the ordering among equivalent kinds is consistent.
|
|
|
|
|
2009-08-09 08:05:33 +02:00
|
|
|
// Tokens and operand kinds are unambiguous (assuming a correct target
|
|
|
|
// specific parser).
|
2010-11-02 02:03:43 +01:00
|
|
|
for (unsigned i = 0, e = AsmOperands.size(); i != e; ++i)
|
|
|
|
if (AsmOperands[i].Class->Kind != RHS.AsmOperands[i].Class->Kind ||
|
|
|
|
AsmOperands[i].Class->Kind == ClassInfo::Token)
|
|
|
|
if (*AsmOperands[i].Class < *RHS.AsmOperands[i].Class ||
|
|
|
|
*RHS.AsmOperands[i].Class < *AsmOperands[i].Class)
|
2009-08-09 08:05:33 +02:00
|
|
|
return false;
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2009-08-09 08:05:33 +02:00
|
|
|
// Otherwise, this operand could commute if all operands are equivalent, or
|
|
|
|
// there is a pair of operands that compare less than and a pair that
|
|
|
|
// compare greater than.
|
|
|
|
bool HasLT = false, HasGT = false;
|
2010-11-02 02:03:43 +01:00
|
|
|
for (unsigned i = 0, e = AsmOperands.size(); i != e; ++i) {
|
|
|
|
if (*AsmOperands[i].Class < *RHS.AsmOperands[i].Class)
|
2009-08-09 08:05:33 +02:00
|
|
|
HasLT = true;
|
2010-11-02 02:03:43 +01:00
|
|
|
if (*RHS.AsmOperands[i].Class < *AsmOperands[i].Class)
|
2009-08-09 08:05:33 +02:00
|
|
|
HasGT = true;
|
|
|
|
}
|
2009-08-09 06:00:06 +02:00
|
|
|
|
2016-01-03 08:33:39 +01:00
|
|
|
return HasLT == HasGT;
|
2009-08-09 06:00:06 +02:00
|
|
|
}
|
|
|
|
|
2014-11-28 04:53:00 +01:00
|
|
|
void dump() const;
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-11-02 18:30:52 +01:00
|
|
|
private:
|
2015-11-09 01:31:07 +01:00
|
|
|
void tokenizeAsmString(AsmMatcherInfo const &Info,
|
|
|
|
AsmVariantInfo const &Variant);
|
2015-12-31 06:01:45 +01:00
|
|
|
void addAsmOperand(StringRef Token, bool IsIsolatedToken = false);
|
2009-08-07 10:26:05 +02:00
|
|
|
};
|
|
|
|
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
struct OperandMatchEntry {
|
|
|
|
unsigned OperandMask;
|
2014-11-28 04:53:00 +01:00
|
|
|
const MatchableInfo* MI;
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
ClassInfo *CI;
|
|
|
|
|
2014-11-28 04:53:00 +01:00
|
|
|
static OperandMatchEntry create(const MatchableInfo *mi, ClassInfo *ci,
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
unsigned opMask) {
|
|
|
|
OperandMatchEntry X;
|
|
|
|
X.OperandMask = opMask;
|
|
|
|
X.CI = ci;
|
|
|
|
X.MI = mi;
|
|
|
|
return X;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-08-08 09:50:56 +02:00
|
|
|
class AsmMatcherInfo {
|
|
|
|
public:
|
2010-12-13 01:23:57 +01:00
|
|
|
/// Tracked Records
|
2010-12-15 05:48:22 +01:00
|
|
|
RecordKeeper &Records;
|
2010-12-13 01:23:57 +01:00
|
|
|
|
2009-08-11 22:59:47 +02:00
|
|
|
/// The tablegen AsmParser record.
|
|
|
|
Record *AsmParser;
|
|
|
|
|
2010-11-01 02:37:30 +01:00
|
|
|
/// Target - The target information.
|
|
|
|
CodeGenTarget &Target;
|
|
|
|
|
2009-08-08 09:50:56 +02:00
|
|
|
/// The classes which are needed for matching.
|
2014-11-28 21:35:57 +01:00
|
|
|
std::forward_list<ClassInfo> Classes;
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2010-11-01 06:06:45 +01:00
|
|
|
/// The information on the matchables to match.
|
2014-11-29 00:00:22 +01:00
|
|
|
std::vector<std::unique_ptr<MatchableInfo>> Matchables;
|
2009-08-08 09:50:56 +02:00
|
|
|
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
/// Info for custom matching operands by user defined methods.
|
|
|
|
std::vector<OperandMatchEntry> OperandMatchInfo;
|
|
|
|
|
2009-08-11 04:59:53 +02:00
|
|
|
/// Map of Register records to their class information.
|
2012-09-19 03:47:01 +02:00
|
|
|
typedef std::map<Record*, ClassInfo*, LessRecordByID> RegisterClassesTy;
|
|
|
|
RegisterClassesTy RegisterClasses;
|
2009-08-11 04:59:53 +02:00
|
|
|
|
2010-07-19 07:44:09 +02:00
|
|
|
/// Map of Predicate records to their subtarget information.
|
2014-11-28 23:15:06 +01:00
|
|
|
std::map<Record *, SubtargetFeatureInfo, LessRecordByID> SubtargetFeatures;
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2012-06-23 01:56:44 +02:00
|
|
|
/// Map of AsmOperandClass records to their class information.
|
|
|
|
std::map<Record*, ClassInfo*> AsmOperandClasses;
|
|
|
|
|
2017-10-10 13:00:40 +02:00
|
|
|
/// Map of RegisterClass records to their class information.
|
|
|
|
std::map<Record*, ClassInfo*> RegisterClassClasses;
|
|
|
|
|
2009-08-08 09:50:56 +02:00
|
|
|
private:
|
|
|
|
/// Map of token to class information which has already been constructed.
|
|
|
|
std::map<std::string, ClassInfo*> TokenClasses;
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// getTokenClass - Lookup or create the class for the given token.
|
2010-02-09 01:34:28 +01:00
|
|
|
ClassInfo *getTokenClass(StringRef Token);
|
2009-08-08 09:50:56 +02:00
|
|
|
|
|
|
|
/// getOperandClass - Lookup or create the class for the given operand.
|
2011-01-26 20:44:55 +01:00
|
|
|
ClassInfo *getOperandClass(const CGIOperandList::OperandInfo &OI,
|
2011-10-29 00:32:53 +02:00
|
|
|
int SubOpIdx);
|
|
|
|
ClassInfo *getOperandClass(Record *Rec, int SubOpIdx);
|
2009-08-08 09:50:56 +02:00
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
/// buildRegisterClasses - Build the ClassInfo* instances for register
|
2009-08-11 04:59:53 +02:00
|
|
|
/// classes.
|
2014-08-21 07:55:13 +02:00
|
|
|
void buildRegisterClasses(SmallPtrSetImpl<Record*> &SingletonRegisters);
|
2009-08-11 04:59:53 +02:00
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
/// buildOperandClasses - Build the ClassInfo* instances for user defined
|
2009-08-11 04:59:53 +02:00
|
|
|
/// operand classes.
|
2012-04-19 19:52:32 +02:00
|
|
|
void buildOperandClasses();
|
2009-08-11 04:59:53 +02:00
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
void buildInstructionOperandReference(MatchableInfo *II, StringRef OpName,
|
2011-01-26 20:44:55 +01:00
|
|
|
unsigned AsmOpIdx);
|
2012-04-19 19:52:32 +02:00
|
|
|
void buildAliasOperandReference(MatchableInfo *II, StringRef OpName,
|
2010-11-04 03:11:18 +01:00
|
|
|
MatchableInfo::AsmOperand &Op);
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2009-08-08 09:50:56 +02:00
|
|
|
public:
|
2011-01-26 22:26:19 +01:00
|
|
|
AsmMatcherInfo(Record *AsmParser,
|
|
|
|
CodeGenTarget &Target,
|
2010-12-15 05:48:22 +01:00
|
|
|
RecordKeeper &Records);
|
2009-08-11 22:59:47 +02:00
|
|
|
|
2016-11-15 10:51:02 +01:00
|
|
|
/// Construct the various tables used during matching.
|
2012-04-19 19:52:32 +02:00
|
|
|
void buildInfo();
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
/// buildOperandMatchInfo - Build the necessary information to handle user
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
/// defined operand parsing methods.
|
2012-04-19 19:52:32 +02:00
|
|
|
void buildOperandMatchInfo();
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
|
2010-10-30 22:15:02 +02:00
|
|
|
/// getSubtargetFeature - Lookup or create the subtarget feature info for the
|
|
|
|
/// given operand.
|
2014-11-28 23:15:06 +01:00
|
|
|
const SubtargetFeatureInfo *getSubtargetFeature(Record *Def) const {
|
2010-10-30 22:15:02 +02:00
|
|
|
assert(Def->isSubClassOf("Predicate") && "Invalid predicate type!");
|
2014-11-28 04:53:00 +01:00
|
|
|
const auto &I = SubtargetFeatures.find(Def);
|
2014-11-28 23:15:06 +01:00
|
|
|
return I == SubtargetFeatures.end() ? nullptr : &I->second;
|
2010-10-30 22:15:02 +02:00
|
|
|
}
|
2010-12-13 01:23:57 +01:00
|
|
|
|
2010-12-15 05:48:22 +01:00
|
|
|
RecordKeeper &getRecords() const {
|
|
|
|
return Records;
|
2010-12-13 01:23:57 +01:00
|
|
|
}
|
2016-05-06 13:31:17 +02:00
|
|
|
|
|
|
|
bool hasOptionalOperands() const {
|
2021-01-04 20:42:47 +01:00
|
|
|
return any_of(Classes,
|
|
|
|
[](const ClassInfo &Class) { return Class.IsOptional; });
|
2016-05-06 13:31:17 +02:00
|
|
|
}
|
2009-08-08 09:50:56 +02:00
|
|
|
};
|
|
|
|
|
2016-02-02 19:20:45 +01:00
|
|
|
} // end anonymous namespace
|
2009-08-07 10:26:05 +02:00
|
|
|
|
2017-10-15 16:32:27 +02:00
|
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
2017-05-17 04:20:05 +02:00
|
|
|
LLVM_DUMP_METHOD void MatchableInfo::dump() const {
|
2010-11-06 07:43:11 +01:00
|
|
|
errs() << TheDef->getName() << " -- " << "flattened:\"" << AsmString <<"\"\n";
|
2009-07-31 04:32:59 +02:00
|
|
|
|
2018-01-06 20:20:32 +01:00
|
|
|
errs() << " variant: " << AsmVariantID << "\n";
|
|
|
|
|
2010-11-02 02:03:43 +01:00
|
|
|
for (unsigned i = 0, e = AsmOperands.size(); i != e; ++i) {
|
2014-11-28 04:53:00 +01:00
|
|
|
const AsmOperand &Op = AsmOperands[i];
|
2009-08-09 07:18:30 +02:00
|
|
|
errs() << " op[" << i << "] = " << Op.Class->ClassName << " - ";
|
2010-11-04 01:57:06 +01:00
|
|
|
errs() << '\"' << Op.Token << "\"\n";
|
2009-08-07 10:26:05 +02:00
|
|
|
}
|
|
|
|
}
|
2017-05-17 04:20:05 +02:00
|
|
|
#endif
|
2009-07-31 04:32:59 +02:00
|
|
|
|
2012-04-20 01:59:23 +02:00
|
|
|
static std::pair<StringRef, StringRef>
|
Print out the location of expanded multiclass defs in TableGen errors.
When reporting an error for a defm, we would previously only report the
location of the outer defm, which is not always where the error is.
Now we also print the location of the expanded multiclass defs:
lib/Target/X86/X86InstrSSE.td:2902:12: error: foo
defm ADD : basic_sse12_fp_binop_s<0x58, "add", fadd, SSE_ALU_ITINS_S>,
^
lib/Target/X86/X86InstrSSE.td:2801:11: note: instantiated from multiclass
defm PD : sse12_fp_packed<opc, !strconcat(OpcodeStr, "pd"), OpNode, VR128,
^
lib/Target/X86/X86InstrSSE.td:194:5: note: instantiated from multiclass
def rm : PI<opc, MRMSrcMem, (outs RC:$dst), (ins RC:$src1, x86memop:$src2),
^
llvm-svn: 162409
2012-08-23 01:33:58 +02:00
|
|
|
parseTwoOperandConstraint(StringRef S, ArrayRef<SMLoc> Loc) {
|
2012-04-20 01:59:23 +02:00
|
|
|
// Split via the '='.
|
|
|
|
std::pair<StringRef, StringRef> Ops = S.split('=');
|
|
|
|
if (Ops.second == "")
|
2012-10-25 22:33:17 +02:00
|
|
|
PrintFatalError(Loc, "missing '=' in two-operand alias constraint");
|
2012-04-20 01:59:23 +02:00
|
|
|
// Trim whitespace and the leading '$' on the operand names.
|
|
|
|
size_t start = Ops.first.find_first_of('$');
|
|
|
|
if (start == std::string::npos)
|
2012-10-25 22:33:17 +02:00
|
|
|
PrintFatalError(Loc, "expected '$' prefix on asm operand name");
|
2012-04-20 01:59:23 +02:00
|
|
|
Ops.first = Ops.first.slice(start + 1, std::string::npos);
|
|
|
|
size_t end = Ops.first.find_last_of(" \t");
|
|
|
|
Ops.first = Ops.first.slice(0, end);
|
|
|
|
// Now the second operand.
|
|
|
|
start = Ops.second.find_first_of('$');
|
|
|
|
if (start == std::string::npos)
|
2012-10-25 22:33:17 +02:00
|
|
|
PrintFatalError(Loc, "expected '$' prefix on asm operand name");
|
2012-04-20 01:59:23 +02:00
|
|
|
Ops.second = Ops.second.slice(start + 1, std::string::npos);
|
|
|
|
end = Ops.second.find_last_of(" \t");
|
|
|
|
Ops.first = Ops.first.slice(0, end);
|
|
|
|
return Ops;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MatchableInfo::formTwoOperandAlias(StringRef Constraint) {
|
|
|
|
// Figure out which operands are aliased and mark them as tied.
|
|
|
|
std::pair<StringRef, StringRef> Ops =
|
|
|
|
parseTwoOperandConstraint(Constraint, TheDef->getLoc());
|
|
|
|
|
|
|
|
// Find the AsmOperands that refer to the operands we're aliasing.
|
|
|
|
int SrcAsmOperand = findAsmOperandNamed(Ops.first);
|
|
|
|
int DstAsmOperand = findAsmOperandNamed(Ops.second);
|
|
|
|
if (SrcAsmOperand == -1)
|
2012-10-25 22:33:17 +02:00
|
|
|
PrintFatalError(TheDef->getLoc(),
|
2014-03-29 18:17:15 +01:00
|
|
|
"unknown source two-operand alias operand '" + Ops.first +
|
|
|
|
"'.");
|
2012-04-20 01:59:23 +02:00
|
|
|
if (DstAsmOperand == -1)
|
2012-10-25 22:33:17 +02:00
|
|
|
PrintFatalError(TheDef->getLoc(),
|
2014-03-29 18:17:15 +01:00
|
|
|
"unknown destination two-operand alias operand '" +
|
|
|
|
Ops.second + "'.");
|
2012-04-20 01:59:23 +02:00
|
|
|
|
|
|
|
// Find the ResOperand that refers to the operand we're aliasing away
|
|
|
|
// and update it to refer to the combined operand instead.
|
2015-12-29 08:03:23 +01:00
|
|
|
for (ResOperand &Op : ResOperands) {
|
2012-04-20 01:59:23 +02:00
|
|
|
if (Op.Kind == ResOperand::RenderAsmOperand &&
|
|
|
|
Op.AsmOperandNum == (unsigned)SrcAsmOperand) {
|
|
|
|
Op.AsmOperandNum = DstAsmOperand;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Remove the AsmOperand for the alias operand.
|
|
|
|
AsmOperands.erase(AsmOperands.begin() + SrcAsmOperand);
|
|
|
|
// Adjust the ResOperand references to any AsmOperands that followed
|
|
|
|
// the one we just deleted.
|
2015-12-29 08:03:23 +01:00
|
|
|
for (ResOperand &Op : ResOperands) {
|
2012-04-20 01:59:23 +02:00
|
|
|
switch(Op.Kind) {
|
|
|
|
default:
|
|
|
|
// Nothing to do for operands that don't reference AsmOperands.
|
|
|
|
break;
|
|
|
|
case ResOperand::RenderAsmOperand:
|
|
|
|
if (Op.AsmOperandNum > (unsigned)SrcAsmOperand)
|
|
|
|
--Op.AsmOperandNum;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-13 20:01:25 +02:00
|
|
|
/// extractSingletonRegisterForAsmOperand - Extract singleton register,
|
|
|
|
/// if present, from specified token.
|
|
|
|
static void
|
|
|
|
extractSingletonRegisterForAsmOperand(MatchableInfo::AsmOperand &Op,
|
|
|
|
const AsmMatcherInfo &Info,
|
|
|
|
StringRef RegisterPrefix) {
|
|
|
|
StringRef Tok = Op.Token;
|
|
|
|
|
|
|
|
// If this token is not an isolated token, i.e., it isn't separated from
|
|
|
|
// other tokens (e.g. with whitespace), don't interpret it as a register name.
|
|
|
|
if (!Op.IsIsolatedToken)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (RegisterPrefix.empty()) {
|
|
|
|
std::string LoweredTok = Tok.lower();
|
|
|
|
if (const CodeGenRegister *Reg = Info.Target.getRegisterByName(LoweredTok))
|
|
|
|
Op.SingletonReg = Reg->TheDef;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Tok.startswith(RegisterPrefix))
|
|
|
|
return;
|
|
|
|
|
|
|
|
StringRef RegName = Tok.substr(RegisterPrefix.size());
|
|
|
|
if (const CodeGenRegister *Reg = Info.Target.getRegisterByName(RegName))
|
|
|
|
Op.SingletonReg = Reg->TheDef;
|
|
|
|
|
|
|
|
// If there is no register prefix (i.e. "%" in "%eax"), then this may
|
|
|
|
// be some random non-register token, just ignore it.
|
|
|
|
}
|
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
void MatchableInfo::initialize(const AsmMatcherInfo &Info,
|
2014-08-21 07:55:13 +02:00
|
|
|
SmallPtrSetImpl<Record*> &SingletonRegisters,
|
2015-12-31 09:18:23 +01:00
|
|
|
AsmVariantInfo const &Variant,
|
|
|
|
bool HasMnemonicFirst) {
|
2015-12-30 07:00:18 +01:00
|
|
|
AsmVariantID = Variant.AsmVariantNo;
|
2012-01-24 22:06:59 +01:00
|
|
|
AsmString =
|
2015-12-30 07:00:18 +01:00
|
|
|
CodeGenInstruction::FlattenAsmStringVariants(AsmString,
|
|
|
|
Variant.AsmVariantNo);
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2015-11-09 01:31:07 +01:00
|
|
|
tokenizeAsmString(Info, Variant);
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2015-12-31 09:18:23 +01:00
|
|
|
// The first token of the instruction is the mnemonic, which must be a
|
|
|
|
// simple string, not a $foo variable or a singleton register.
|
|
|
|
if (AsmOperands.empty())
|
|
|
|
PrintFatalError(TheDef->getLoc(),
|
|
|
|
"Instruction '" + TheDef->getName() + "' has no tokens");
|
|
|
|
|
|
|
|
assert(!AsmOperands[0].Token.empty());
|
|
|
|
if (HasMnemonicFirst) {
|
|
|
|
Mnemonic = AsmOperands[0].Token;
|
|
|
|
if (Mnemonic[0] == '$')
|
|
|
|
PrintFatalError(TheDef->getLoc(),
|
|
|
|
"Invalid instruction mnemonic '" + Mnemonic + "'!");
|
|
|
|
|
|
|
|
// Remove the first operand, it is tracked in the mnemonic field.
|
|
|
|
AsmOperands.erase(AsmOperands.begin());
|
|
|
|
} else if (AsmOperands[0].Token[0] != '$')
|
|
|
|
Mnemonic = AsmOperands[0].Token;
|
|
|
|
|
2010-11-01 05:53:48 +01:00
|
|
|
// Compute the require features.
|
2015-09-13 20:01:25 +02:00
|
|
|
for (Record *Predicate : TheDef->getValueAsListOfDefs("Predicates"))
|
2014-11-28 23:15:06 +01:00
|
|
|
if (const SubtargetFeatureInfo *Feature =
|
2015-09-13 20:01:25 +02:00
|
|
|
Info.getSubtargetFeature(Predicate))
|
2010-11-01 05:53:48 +01:00
|
|
|
RequiredFeatures.push_back(Feature);
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-11-01 05:53:48 +01:00
|
|
|
// Collect singleton registers, if used.
|
2015-09-13 20:01:25 +02:00
|
|
|
for (MatchableInfo::AsmOperand &Op : AsmOperands) {
|
2015-12-30 07:00:18 +01:00
|
|
|
extractSingletonRegisterForAsmOperand(Op, Info, Variant.RegisterPrefix);
|
2015-09-13 20:01:25 +02:00
|
|
|
if (Record *Reg = Op.SingletonReg)
|
2010-11-01 05:53:48 +01:00
|
|
|
SingletonRegisters.insert(Reg);
|
|
|
|
}
|
2013-09-12 12:28:05 +02:00
|
|
|
|
|
|
|
const RecordVal *DepMask = TheDef->getValue("DeprecatedFeatureMask");
|
|
|
|
if (!DepMask)
|
|
|
|
DepMask = TheDef->getValue("ComplexDeprecationPredicate");
|
|
|
|
|
|
|
|
HasDeprecation =
|
|
|
|
DepMask ? !DepMask->getValue()->getAsUnquotedString().empty() : false;
|
2010-11-01 05:53:48 +01:00
|
|
|
}
|
|
|
|
|
2015-05-29 02:55:55 +02:00
|
|
|
/// Append an AsmOperand for the given substring of AsmString.
|
2015-12-31 06:01:45 +01:00
|
|
|
void MatchableInfo::addAsmOperand(StringRef Token, bool IsIsolatedToken) {
|
|
|
|
AsmOperands.push_back(AsmOperand(IsIsolatedToken, Token));
|
2015-05-29 02:55:55 +02:00
|
|
|
}
|
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
/// tokenizeAsmString - Tokenize a simplified assembly string.
|
2015-11-09 01:31:07 +01:00
|
|
|
void MatchableInfo::tokenizeAsmString(const AsmMatcherInfo &Info,
|
|
|
|
AsmVariantInfo const &Variant) {
|
2010-11-02 18:30:52 +01:00
|
|
|
StringRef String = AsmString;
|
2015-12-30 07:00:15 +01:00
|
|
|
size_t Prev = 0;
|
2015-11-09 01:31:07 +01:00
|
|
|
bool InTok = false;
|
2015-12-31 06:01:45 +01:00
|
|
|
bool IsIsolatedToken = true;
|
2015-12-30 07:00:15 +01:00
|
|
|
for (size_t i = 0, e = String.size(); i != e; ++i) {
|
2015-12-31 06:01:45 +01:00
|
|
|
char Char = String[i];
|
|
|
|
if (Variant.BreakCharacters.find(Char) != std::string::npos) {
|
|
|
|
if (InTok) {
|
|
|
|
addAsmOperand(String.slice(Prev, i), false);
|
2015-11-09 01:31:07 +01:00
|
|
|
Prev = i;
|
2015-12-31 06:01:45 +01:00
|
|
|
IsIsolatedToken = false;
|
2015-11-09 01:31:07 +01:00
|
|
|
}
|
|
|
|
InTok = true;
|
|
|
|
continue;
|
|
|
|
}
|
2015-12-31 06:01:45 +01:00
|
|
|
if (Variant.TokenizingCharacters.find(Char) != std::string::npos) {
|
|
|
|
if (InTok) {
|
|
|
|
addAsmOperand(String.slice(Prev, i), IsIsolatedToken);
|
2010-11-02 18:30:52 +01:00
|
|
|
InTok = false;
|
2015-12-31 06:01:45 +01:00
|
|
|
IsIsolatedToken = false;
|
2010-11-02 18:30:52 +01:00
|
|
|
}
|
2015-12-31 06:01:45 +01:00
|
|
|
addAsmOperand(String.slice(i, i + 1), IsIsolatedToken);
|
2010-11-02 18:30:52 +01:00
|
|
|
Prev = i + 1;
|
2015-12-31 06:01:45 +01:00
|
|
|
IsIsolatedToken = true;
|
2015-11-09 01:31:07 +01:00
|
|
|
continue;
|
|
|
|
}
|
2015-12-31 06:01:45 +01:00
|
|
|
if (Variant.SeparatorCharacters.find(Char) != std::string::npos) {
|
|
|
|
if (InTok) {
|
|
|
|
addAsmOperand(String.slice(Prev, i), IsIsolatedToken);
|
2015-11-09 01:31:07 +01:00
|
|
|
InTok = false;
|
|
|
|
}
|
|
|
|
Prev = i + 1;
|
2015-12-31 06:01:45 +01:00
|
|
|
IsIsolatedToken = true;
|
2015-11-09 01:31:07 +01:00
|
|
|
continue;
|
|
|
|
}
|
2015-12-31 06:01:45 +01:00
|
|
|
|
|
|
|
switch (Char) {
|
2010-11-02 18:30:52 +01:00
|
|
|
case '\\':
|
|
|
|
if (InTok) {
|
2015-12-31 06:01:45 +01:00
|
|
|
addAsmOperand(String.slice(Prev, i), false);
|
2010-11-02 18:30:52 +01:00
|
|
|
InTok = false;
|
2015-12-31 06:01:45 +01:00
|
|
|
IsIsolatedToken = false;
|
2010-11-02 18:30:52 +01:00
|
|
|
}
|
|
|
|
++i;
|
|
|
|
assert(i != String.size() && "Invalid quoted character");
|
2015-12-31 06:01:45 +01:00
|
|
|
addAsmOperand(String.slice(i, i + 1), IsIsolatedToken);
|
2010-11-02 18:30:52 +01:00
|
|
|
Prev = i + 1;
|
2015-12-31 06:01:45 +01:00
|
|
|
IsIsolatedToken = false;
|
2010-11-02 18:30:52 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '$': {
|
2015-12-31 06:01:45 +01:00
|
|
|
if (InTok) {
|
2020-10-28 17:12:21 +01:00
|
|
|
addAsmOperand(String.slice(Prev, i), IsIsolatedToken);
|
2010-11-06 23:06:03 +01:00
|
|
|
InTok = false;
|
2015-12-31 06:01:45 +01:00
|
|
|
IsIsolatedToken = false;
|
2010-11-06 23:06:03 +01:00
|
|
|
}
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2015-08-10 21:58:06 +02:00
|
|
|
// If this isn't "${", start new identifier looking like "$xxx"
|
2010-11-02 18:30:52 +01:00
|
|
|
if (i + 1 == String.size() || String[i + 1] != '{') {
|
|
|
|
Prev = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-12-30 07:00:15 +01:00
|
|
|
size_t EndPos = String.find('}', i);
|
|
|
|
assert(EndPos != StringRef::npos &&
|
|
|
|
"Missing brace in operand reference!");
|
2015-12-31 06:01:45 +01:00
|
|
|
addAsmOperand(String.slice(i, EndPos+1), IsIsolatedToken);
|
2010-11-02 18:30:52 +01:00
|
|
|
Prev = EndPos + 1;
|
|
|
|
i = EndPos;
|
2015-12-31 06:01:45 +01:00
|
|
|
IsIsolatedToken = false;
|
2010-11-02 18:30:52 +01:00
|
|
|
break;
|
|
|
|
}
|
2015-12-31 06:01:45 +01:00
|
|
|
|
2010-11-02 18:30:52 +01:00
|
|
|
default:
|
|
|
|
InTok = true;
|
2015-12-31 06:01:45 +01:00
|
|
|
break;
|
2010-11-02 18:30:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (InTok && Prev != String.size())
|
2015-12-31 06:01:45 +01:00
|
|
|
addAsmOperand(String.substr(Prev), IsIsolatedToken);
|
2010-11-02 18:30:52 +01:00
|
|
|
}
|
|
|
|
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
bool MatchableInfo::validate(StringRef CommentDelimiter, bool IsAlias) const {
|
2010-11-01 06:06:45 +01:00
|
|
|
// Reject matchables with no .s string.
|
2010-11-01 05:34:44 +01:00
|
|
|
if (AsmString.empty())
|
2012-10-25 22:33:17 +02:00
|
|
|
PrintFatalError(TheDef->getLoc(), "instruction with empty asm string");
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-11-01 06:06:45 +01:00
|
|
|
// Reject any matchables with a newline in them, they should be marked
|
2010-11-01 05:34:44 +01:00
|
|
|
// isCodeGenOnly if they are pseudo instructions.
|
|
|
|
if (AsmString.find('\n') != std::string::npos)
|
2012-10-25 22:33:17 +02:00
|
|
|
PrintFatalError(TheDef->getLoc(),
|
2010-11-01 05:34:44 +01:00
|
|
|
"multiline instruction is not valid for the asmparser, "
|
|
|
|
"mark it isCodeGenOnly");
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-11-01 05:44:29 +01:00
|
|
|
// Remove comments from the asm string. We know that the asmstring only
|
|
|
|
// has one line.
|
|
|
|
if (!CommentDelimiter.empty() &&
|
|
|
|
StringRef(AsmString).find(CommentDelimiter) != StringRef::npos)
|
2012-10-25 22:33:17 +02:00
|
|
|
PrintFatalError(TheDef->getLoc(),
|
2010-11-01 05:44:29 +01:00
|
|
|
"asmstring for instruction has comment character in it, "
|
|
|
|
"mark it isCodeGenOnly");
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-11-01 06:06:45 +01:00
|
|
|
// Reject matchables with operand modifiers, these aren't something we can
|
2011-01-20 19:38:07 +01:00
|
|
|
// handle, the target should be refactored to use operands instead of
|
|
|
|
// modifiers.
|
2010-11-01 05:34:44 +01:00
|
|
|
//
|
[TableGen] AsmMatcher: allow repeated input operands
If an assembly instruction has to mention an input operand name twice,
for example the MVE VMOV instruction that accesses two lanes of the
same vector by writing 'vmov r1, r2, q0[3], q0[1]', then the obvious
way to write its AsmString is to include the same operand (here $Qd)
twice. But this causes the AsmMatcher generator to omit that
instruction completely from the match table, on the basis that the
generator isn't clever enough to deal with the duplication.
But you need to have _some_ way of dealing with an instruction like
this - and in this case, where the mnemonic is shared with many other
instructions that the AsmMatcher does handle, it would be very painful
to take it out of the AsmMatcher system completely.
A nicer way is to add a custom AsmMatchConverter routine, and let that
deal with the problem if the autogenerated converter can't. But that
doesn't work, because TableGen leaves the instruction out of its table
_even_ if you provide a custom converter.
Solution: this change, which makes TableGen relax the restriction on
duplicated operands in the case where there's a custom converter.
Patch by: Simon Tatham
Differential Revision: https://reviews.llvm.org/D60695
llvm-svn: 362066
2019-05-30 09:38:09 +02:00
|
|
|
// Also, check for instructions which reference the operand multiple times,
|
|
|
|
// if they don't define a custom AsmMatcher: this implies a constraint that
|
|
|
|
// the built-in matching code would not honor.
|
2010-11-01 05:34:44 +01:00
|
|
|
std::set<std::string> OperandNames;
|
2015-12-30 07:00:20 +01:00
|
|
|
for (const AsmOperand &Op : AsmOperands) {
|
|
|
|
StringRef Tok = Op.Token;
|
2010-11-02 18:30:52 +01:00
|
|
|
if (Tok[0] == '$' && Tok.find(':') != StringRef::npos)
|
2012-10-25 22:33:17 +02:00
|
|
|
PrintFatalError(TheDef->getLoc(),
|
2014-03-29 18:17:15 +01:00
|
|
|
"matchable with operand modifier '" + Tok +
|
|
|
|
"' not supported by asm matcher. Mark isCodeGenOnly!");
|
2010-11-01 06:06:45 +01:00
|
|
|
// Verify that any operand is only mentioned once.
|
2010-11-03 00:18:43 +01:00
|
|
|
// We reject aliases and ignore instructions for now.
|
[TableGen] AsmMatcher: allow repeated input operands
If an assembly instruction has to mention an input operand name twice,
for example the MVE VMOV instruction that accesses two lanes of the
same vector by writing 'vmov r1, r2, q0[3], q0[1]', then the obvious
way to write its AsmString is to include the same operand (here $Qd)
twice. But this causes the AsmMatcher generator to omit that
instruction completely from the match table, on the basis that the
generator isn't clever enough to deal with the duplication.
But you need to have _some_ way of dealing with an instruction like
this - and in this case, where the mnemonic is shared with many other
instructions that the AsmMatcher does handle, it would be very painful
to take it out of the AsmMatcher system completely.
A nicer way is to add a custom AsmMatchConverter routine, and let that
deal with the problem if the autogenerated converter can't. But that
doesn't work, because TableGen leaves the instruction out of its table
_even_ if you provide a custom converter.
Solution: this change, which makes TableGen relax the restriction on
duplicated operands in the case where there's a custom converter.
Patch by: Simon Tatham
Differential Revision: https://reviews.llvm.org/D60695
llvm-svn: 362066
2019-05-30 09:38:09 +02:00
|
|
|
if (!IsAlias && TheDef->getValueAsString("AsmMatchConverter").empty() &&
|
2020-01-28 20:23:46 +01:00
|
|
|
Tok[0] == '$' && !OperandNames.insert(std::string(Tok)).second) {
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG({
|
2010-11-06 07:43:11 +01:00
|
|
|
errs() << "warning: '" << TheDef->getName() << "': "
|
2010-11-01 06:06:45 +01:00
|
|
|
<< "ignoring instruction with tied operand '"
|
2014-03-29 18:17:15 +01:00
|
|
|
<< Tok << "'\n";
|
2010-11-01 05:34:44 +01:00
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-11-01 05:34:44 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-02-09 01:34:28 +01:00
|
|
|
static std::string getEnumNameForToken(StringRef Str) {
|
2009-08-08 09:50:56 +02:00
|
|
|
std::string Res;
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2021-02-02 05:55:08 +01:00
|
|
|
for (char C : Str) {
|
|
|
|
switch (C) {
|
2009-08-08 09:50:56 +02:00
|
|
|
case '*': Res += "_STAR_"; break;
|
|
|
|
case '%': Res += "_PCT_"; break;
|
|
|
|
case ':': Res += "_COLON_"; break;
|
2010-11-19 00:36:54 +01:00
|
|
|
case '!': Res += "_EXCLAIM_"; break;
|
2011-01-22 10:44:32 +01:00
|
|
|
case '.': Res += "_DOT_"; break;
|
2013-01-10 17:47:31 +01:00
|
|
|
case '<': Res += "_LT_"; break;
|
|
|
|
case '>': Res += "_GT_"; break;
|
2015-01-15 02:33:00 +01:00
|
|
|
case '-': Res += "_MINUS_"; break;
|
2019-09-23 14:52:42 +02:00
|
|
|
case '#': Res += "_HASH_"; break;
|
2009-08-08 09:50:56 +02:00
|
|
|
default:
|
2021-02-02 05:55:08 +01:00
|
|
|
if (isAlnum(C))
|
|
|
|
Res += C;
|
2010-10-31 20:10:56 +01:00
|
|
|
else
|
2021-02-02 05:55:08 +01:00
|
|
|
Res += "_" + utostr((unsigned)C) + "_";
|
2009-08-08 09:50:56 +02:00
|
|
|
}
|
|
|
|
}
|
2009-08-07 10:26:05 +02:00
|
|
|
|
2009-08-08 09:50:56 +02:00
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
2010-02-09 01:34:28 +01:00
|
|
|
ClassInfo *AsmMatcherInfo::getTokenClass(StringRef Token) {
|
2020-01-28 20:23:46 +01:00
|
|
|
ClassInfo *&Entry = TokenClasses[std::string(Token)];
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2009-08-08 09:50:56 +02:00
|
|
|
if (!Entry) {
|
2014-11-28 21:35:57 +01:00
|
|
|
Classes.emplace_front();
|
|
|
|
Entry = &Classes.front();
|
2009-08-08 09:50:56 +02:00
|
|
|
Entry->Kind = ClassInfo::Token;
|
2009-08-09 07:18:30 +02:00
|
|
|
Entry->ClassName = "Token";
|
2009-08-08 09:50:56 +02:00
|
|
|
Entry->Name = "MCK_" + getEnumNameForToken(Token);
|
2020-01-28 20:23:46 +01:00
|
|
|
Entry->ValueName = std::string(Token);
|
2009-08-08 09:50:56 +02:00
|
|
|
Entry->PredicateMethod = "<invalid>";
|
|
|
|
Entry->RenderMethod = "<invalid>";
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
Entry->ParserMethod = "";
|
2012-06-23 01:56:44 +02:00
|
|
|
Entry->DiagnosticType = "";
|
2016-02-05 20:59:33 +01:00
|
|
|
Entry->IsOptional = false;
|
2016-05-06 13:31:17 +02:00
|
|
|
Entry->DefaultMethod = "<invalid>";
|
2009-08-08 09:50:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return Entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClassInfo *
|
2011-01-26 20:44:55 +01:00
|
|
|
AsmMatcherInfo::getOperandClass(const CGIOperandList::OperandInfo &OI,
|
|
|
|
int SubOpIdx) {
|
|
|
|
Record *Rec = OI.Rec;
|
|
|
|
if (SubOpIdx != -1)
|
2012-10-10 22:24:47 +02:00
|
|
|
Rec = cast<DefInit>(OI.MIOperandInfo->getArg(SubOpIdx))->getDef();
|
2011-10-29 00:32:53 +02:00
|
|
|
return getOperandClass(Rec, SubOpIdx);
|
|
|
|
}
|
2011-01-26 20:44:55 +01:00
|
|
|
|
2011-10-29 00:32:53 +02:00
|
|
|
ClassInfo *
|
|
|
|
AsmMatcherInfo::getOperandClass(Record *Rec, int SubOpIdx) {
|
2011-06-27 23:06:21 +02:00
|
|
|
if (Rec->isSubClassOf("RegisterOperand")) {
|
|
|
|
// RegisterOperand may have an associated ParserMatchClass. If it does,
|
|
|
|
// use it, else just fall back to the underlying register class.
|
|
|
|
const RecordVal *R = Rec->getValue("ParserMatchClass");
|
2014-04-15 09:20:03 +02:00
|
|
|
if (!R || !R->getValue())
|
[tablegen] Add locations to many PrintFatalError() calls
Summary:
While working on the GISel Combiner, I noticed I was producing location-less
error messages fairly often and set about fixing this. In the process, I
noticed quite a few places elsewhere in TableGen that also neglected to include
a relevant location.
This patch adds locations to errors that relate to a specific record (or a
field within it) and also have easy access to the relevant location. This is
particularly useful when multiclasses are involved as many of these errors
refer to the full name of a record and it's difficult to guess which substring
is grep-able.
Unfortunately, tablegen currently only supports Record granularity so it's not
currently possible to point at a specific Init so these sometimes point at the
record that caused the error rather than the precise origin of the error.
Reviewers: bogner, aditya_nandakumar, volkan, aemerson, paquette, nhaehnle
Reviewed By: nhaehnle
Subscribers: jdoerfert, nhaehnle, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D58077
llvm-svn: 353862
2019-02-12 18:36:57 +01:00
|
|
|
PrintFatalError(Rec->getLoc(),
|
|
|
|
"Record `" + Rec->getName() +
|
|
|
|
"' does not have a ParserMatchClass!\n");
|
2011-06-27 23:06:21 +02:00
|
|
|
|
2012-10-10 22:24:43 +02:00
|
|
|
if (DefInit *DI= dyn_cast<DefInit>(R->getValue())) {
|
2011-06-27 23:06:21 +02:00
|
|
|
Record *MatchClass = DI->getDef();
|
|
|
|
if (ClassInfo *CI = AsmOperandClasses[MatchClass])
|
|
|
|
return CI;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No custom match class. Just use the register class.
|
|
|
|
Record *ClassRec = Rec->getValueAsDef("RegClass");
|
|
|
|
if (!ClassRec)
|
2012-10-25 22:33:17 +02:00
|
|
|
PrintFatalError(Rec->getLoc(), "RegisterOperand `" + Rec->getName() +
|
2011-06-27 23:06:21 +02:00
|
|
|
"' has no associated register class!\n");
|
|
|
|
if (ClassInfo *CI = RegisterClassClasses[ClassRec])
|
|
|
|
return CI;
|
2012-10-25 22:33:17 +02:00
|
|
|
PrintFatalError(Rec->getLoc(), "register class has no class info!");
|
2011-06-27 23:06:21 +02:00
|
|
|
}
|
|
|
|
|
2011-01-26 20:44:55 +01:00
|
|
|
if (Rec->isSubClassOf("RegisterClass")) {
|
|
|
|
if (ClassInfo *CI = RegisterClassClasses[Rec])
|
2010-11-02 19:10:06 +01:00
|
|
|
return CI;
|
2012-10-25 22:33:17 +02:00
|
|
|
PrintFatalError(Rec->getLoc(), "register class has no class info!");
|
2009-08-11 04:59:53 +02:00
|
|
|
}
|
2009-08-10 20:41:10 +02:00
|
|
|
|
2012-09-12 19:40:25 +02:00
|
|
|
if (!Rec->isSubClassOf("Operand"))
|
2012-10-25 22:33:17 +02:00
|
|
|
PrintFatalError(Rec->getLoc(), "Operand `" + Rec->getName() +
|
2012-09-12 19:40:25 +02:00
|
|
|
"' does not derive from class Operand!\n");
|
2011-01-26 20:44:55 +01:00
|
|
|
Record *MatchClass = Rec->getValueAsDef("ParserMatchClass");
|
2010-11-02 19:10:06 +01:00
|
|
|
if (ClassInfo *CI = AsmOperandClasses[MatchClass])
|
|
|
|
return CI;
|
2009-08-08 09:50:56 +02:00
|
|
|
|
2012-10-25 22:33:17 +02:00
|
|
|
PrintFatalError(Rec->getLoc(), "operand has no match class!");
|
2009-08-10 20:41:10 +02:00
|
|
|
}
|
|
|
|
|
2013-09-16 18:43:19 +02:00
|
|
|
struct LessRegisterSet {
|
2013-09-16 19:33:40 +02:00
|
|
|
bool operator() (const RegisterSet &LHS, const RegisterSet & RHS) const {
|
2013-09-16 18:43:19 +02:00
|
|
|
// std::set<T> defines its own compariso "operator<", but it
|
|
|
|
// performs a lexicographical comparison by T's innate comparison
|
|
|
|
// for some reason. We don't want non-deterministic pointer
|
|
|
|
// comparisons so use this instead.
|
|
|
|
return std::lexicographical_compare(LHS.begin(), LHS.end(),
|
|
|
|
RHS.begin(), RHS.end(),
|
|
|
|
LessRecordByID());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-11-01 02:47:07 +01:00
|
|
|
void AsmMatcherInfo::
|
2014-08-21 07:55:13 +02:00
|
|
|
buildRegisterClasses(SmallPtrSetImpl<Record*> &SingletonRegisters) {
|
2014-11-29 19:13:39 +01:00
|
|
|
const auto &Registers = Target.getRegBank().getRegisters();
|
2014-12-03 20:58:41 +01:00
|
|
|
auto &RegClassList = Target.getRegBank().getRegClasses();
|
2009-08-10 20:41:10 +02:00
|
|
|
|
2013-09-16 18:43:19 +02:00
|
|
|
typedef std::set<RegisterSet, LessRegisterSet> RegisterSetSet;
|
|
|
|
|
2009-08-11 04:59:53 +02:00
|
|
|
// The register sets used for matching.
|
2013-09-16 18:43:19 +02:00
|
|
|
RegisterSetSet RegisterSets;
|
2009-08-11 04:59:53 +02:00
|
|
|
|
2010-10-30 00:13:48 +02:00
|
|
|
// Gather the defined sets.
|
2014-12-03 20:58:45 +01:00
|
|
|
for (const CodeGenRegisterClass &RC : RegClassList)
|
|
|
|
RegisterSets.insert(
|
|
|
|
RegisterSet(RC.getOrder().begin(), RC.getOrder().end()));
|
2009-08-12 01:23:44 +02:00
|
|
|
|
|
|
|
// Add any required singleton sets.
|
2014-11-25 21:11:31 +01:00
|
|
|
for (Record *Rec : SingletonRegisters) {
|
2013-09-16 18:43:19 +02:00
|
|
|
RegisterSets.insert(RegisterSet(&Rec, &Rec + 1));
|
2010-11-01 02:47:07 +01:00
|
|
|
}
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2009-08-11 04:59:53 +02:00
|
|
|
// Introduce derived sets where necessary (when a register does not determine
|
|
|
|
// a unique register set class), and build the mapping of registers to the set
|
|
|
|
// they should classify to.
|
2013-09-16 18:43:19 +02:00
|
|
|
std::map<Record*, RegisterSet> RegisterMap;
|
2014-11-29 19:13:39 +01:00
|
|
|
for (const CodeGenRegister &CGR : Registers) {
|
2009-08-11 04:59:53 +02:00
|
|
|
// Compute the intersection of all sets containing this register.
|
2013-09-16 18:43:19 +02:00
|
|
|
RegisterSet ContainingSet;
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2014-11-25 21:11:31 +01:00
|
|
|
for (const RegisterSet &RS : RegisterSets) {
|
2014-11-29 19:13:39 +01:00
|
|
|
if (!RS.count(CGR.TheDef))
|
2009-08-11 04:59:53 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ContainingSet.empty()) {
|
2014-11-25 21:11:31 +01:00
|
|
|
ContainingSet = RS;
|
2010-11-02 19:10:06 +01:00
|
|
|
continue;
|
2009-08-11 04:59:53 +02:00
|
|
|
}
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2013-09-16 18:43:19 +02:00
|
|
|
RegisterSet Tmp;
|
2010-11-02 19:10:06 +01:00
|
|
|
std::swap(Tmp, ContainingSet);
|
2013-09-16 18:43:19 +02:00
|
|
|
std::insert_iterator<RegisterSet> II(ContainingSet,
|
|
|
|
ContainingSet.begin());
|
2014-11-25 21:11:31 +01:00
|
|
|
std::set_intersection(Tmp.begin(), Tmp.end(), RS.begin(), RS.end(), II,
|
2013-09-16 18:43:19 +02:00
|
|
|
LessRecordByID());
|
2009-08-11 04:59:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ContainingSet.empty()) {
|
|
|
|
RegisterSets.insert(ContainingSet);
|
2014-11-29 19:13:39 +01:00
|
|
|
RegisterMap.insert(std::make_pair(CGR.TheDef, ContainingSet));
|
2009-08-11 04:59:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construct the register classes.
|
2013-09-16 18:43:19 +02:00
|
|
|
std::map<RegisterSet, ClassInfo*, LessRegisterSet> RegisterSetClasses;
|
2009-08-11 04:59:53 +02:00
|
|
|
unsigned Index = 0;
|
2014-11-25 21:11:31 +01:00
|
|
|
for (const RegisterSet &RS : RegisterSets) {
|
2014-11-28 21:35:57 +01:00
|
|
|
Classes.emplace_front();
|
|
|
|
ClassInfo *CI = &Classes.front();
|
2009-08-11 04:59:53 +02:00
|
|
|
CI->Kind = ClassInfo::RegisterClass0 + Index;
|
|
|
|
CI->ClassName = "Reg" + utostr(Index);
|
|
|
|
CI->Name = "MCK_Reg" + utostr(Index);
|
|
|
|
CI->ValueName = "";
|
|
|
|
CI->PredicateMethod = ""; // unused
|
|
|
|
CI->RenderMethod = "addRegOperands";
|
2014-11-25 21:11:31 +01:00
|
|
|
CI->Registers = RS;
|
2012-06-23 01:56:44 +02:00
|
|
|
// FIXME: diagnostic type.
|
|
|
|
CI->DiagnosticType = "";
|
2016-02-05 20:59:33 +01:00
|
|
|
CI->IsOptional = false;
|
2016-05-06 13:31:17 +02:00
|
|
|
CI->DefaultMethod = ""; // unused
|
2014-11-25 21:11:31 +01:00
|
|
|
RegisterSetClasses.insert(std::make_pair(RS, CI));
|
|
|
|
++Index;
|
2009-08-11 04:59:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find the superclasses; we could compute only the subgroup lattice edges,
|
|
|
|
// but there isn't really a point.
|
2014-11-25 21:11:31 +01:00
|
|
|
for (const RegisterSet &RS : RegisterSets) {
|
|
|
|
ClassInfo *CI = RegisterSetClasses[RS];
|
|
|
|
for (const RegisterSet &RS2 : RegisterSets)
|
|
|
|
if (RS != RS2 &&
|
|
|
|
std::includes(RS2.begin(), RS2.end(), RS.begin(), RS.end(),
|
2013-09-16 18:43:19 +02:00
|
|
|
LessRecordByID()))
|
2014-11-25 21:11:31 +01:00
|
|
|
CI->SuperClasses.push_back(RegisterSetClasses[RS2]);
|
2009-08-11 04:59:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Name the register classes which correspond to a user defined RegisterClass.
|
2014-12-03 20:58:45 +01:00
|
|
|
for (const CodeGenRegisterClass &RC : RegClassList) {
|
2011-10-04 17:28:08 +02:00
|
|
|
// Def will be NULL for non-user defined register classes.
|
2014-12-03 20:58:45 +01:00
|
|
|
Record *Def = RC.getDef();
|
2011-10-04 17:28:08 +02:00
|
|
|
if (!Def)
|
|
|
|
continue;
|
2014-12-03 20:58:45 +01:00
|
|
|
ClassInfo *CI = RegisterSetClasses[RegisterSet(RC.getOrder().begin(),
|
|
|
|
RC.getOrder().end())];
|
2009-08-11 04:59:53 +02:00
|
|
|
if (CI->ValueName.empty()) {
|
2014-12-03 20:58:45 +01:00
|
|
|
CI->ClassName = RC.getName();
|
|
|
|
CI->Name = "MCK_" + RC.getName();
|
|
|
|
CI->ValueName = RC.getName();
|
2009-08-11 04:59:53 +02:00
|
|
|
} else
|
2014-12-03 20:58:45 +01:00
|
|
|
CI->ValueName = CI->ValueName + "," + RC.getName();
|
2009-08-11 04:59:53 +02:00
|
|
|
|
2017-10-10 13:00:40 +02:00
|
|
|
Init *DiagnosticType = Def->getValueInit("DiagnosticType");
|
|
|
|
if (StringInit *SI = dyn_cast<StringInit>(DiagnosticType))
|
2020-01-28 20:23:46 +01:00
|
|
|
CI->DiagnosticType = std::string(SI->getValue());
|
2017-10-10 13:00:40 +02:00
|
|
|
|
|
|
|
Init *DiagnosticString = Def->getValueInit("DiagnosticString");
|
|
|
|
if (StringInit *SI = dyn_cast<StringInit>(DiagnosticString))
|
2020-01-28 20:23:46 +01:00
|
|
|
CI->DiagnosticString = std::string(SI->getValue());
|
2017-10-10 13:00:40 +02:00
|
|
|
|
|
|
|
// If we have a diagnostic string but the diagnostic type is not specified
|
|
|
|
// explicitly, create an anonymous diagnostic type.
|
|
|
|
if (!CI->DiagnosticString.empty() && CI->DiagnosticType.empty())
|
|
|
|
CI->DiagnosticType = RC.getName();
|
|
|
|
|
2011-10-04 17:28:08 +02:00
|
|
|
RegisterClassClasses.insert(std::make_pair(Def, CI));
|
2009-08-11 04:59:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Populate the map for individual registers.
|
2013-09-16 18:43:19 +02:00
|
|
|
for (std::map<Record*, RegisterSet>::iterator it = RegisterMap.begin(),
|
2009-08-11 04:59:53 +02:00
|
|
|
ie = RegisterMap.end(); it != ie; ++it)
|
2010-11-02 19:10:06 +01:00
|
|
|
RegisterClasses[it->first] = RegisterSetClasses[it->second];
|
2009-08-12 01:23:44 +02:00
|
|
|
|
|
|
|
// Name the register classes which correspond to singleton registers.
|
2014-11-25 21:11:31 +01:00
|
|
|
for (Record *Rec : SingletonRegisters) {
|
2010-11-02 19:10:06 +01:00
|
|
|
ClassInfo *CI = RegisterClasses[Rec];
|
2010-11-01 02:47:07 +01:00
|
|
|
assert(CI && "Missing singleton register class info!");
|
|
|
|
|
|
|
|
if (CI->ValueName.empty()) {
|
2020-01-28 20:23:46 +01:00
|
|
|
CI->ClassName = std::string(Rec->getName());
|
2016-12-04 06:48:16 +01:00
|
|
|
CI->Name = "MCK_" + Rec->getName().str();
|
2020-01-28 20:23:46 +01:00
|
|
|
CI->ValueName = std::string(Rec->getName());
|
2010-11-01 02:47:07 +01:00
|
|
|
} else
|
2016-12-04 06:48:16 +01:00
|
|
|
CI->ValueName = CI->ValueName + "," + Rec->getName().str();
|
2009-08-12 01:23:44 +02:00
|
|
|
}
|
2009-08-11 04:59:53 +02:00
|
|
|
}
|
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
void AsmMatcherInfo::buildOperandClasses() {
|
2010-11-02 00:57:23 +01:00
|
|
|
std::vector<Record*> AsmOperands =
|
|
|
|
Records.getAllDerivedDefinitions("AsmOperandClass");
|
2010-01-30 02:02:37 +01:00
|
|
|
|
|
|
|
// Pre-populate AsmOperandClasses map.
|
2014-11-28 21:35:57 +01:00
|
|
|
for (Record *Rec : AsmOperands) {
|
|
|
|
Classes.emplace_front();
|
|
|
|
AsmOperandClasses[Rec] = &Classes.front();
|
|
|
|
}
|
2010-01-30 02:02:37 +01:00
|
|
|
|
2009-08-10 20:41:10 +02:00
|
|
|
unsigned Index = 0;
|
2014-11-25 21:11:31 +01:00
|
|
|
for (Record *Rec : AsmOperands) {
|
|
|
|
ClassInfo *CI = AsmOperandClasses[Rec];
|
2009-08-10 20:41:10 +02:00
|
|
|
CI->Kind = ClassInfo::UserClass0 + Index;
|
|
|
|
|
2014-11-25 21:11:31 +01:00
|
|
|
ListInit *Supers = Rec->getValueAsListInit("SuperClasses");
|
2015-06-02 06:15:51 +02:00
|
|
|
for (Init *I : Supers->getValues()) {
|
|
|
|
DefInit *DI = dyn_cast<DefInit>(I);
|
2010-05-22 23:02:29 +02:00
|
|
|
if (!DI) {
|
2014-11-25 21:11:31 +01:00
|
|
|
PrintError(Rec->getLoc(), "Invalid super class reference!");
|
2010-05-22 23:02:29 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-08-11 04:59:53 +02:00
|
|
|
ClassInfo *SC = AsmOperandClasses[DI->getDef()];
|
|
|
|
if (!SC)
|
2014-11-25 21:11:31 +01:00
|
|
|
PrintError(Rec->getLoc(), "Invalid super class reference!");
|
2009-08-11 04:59:53 +02:00
|
|
|
else
|
|
|
|
CI->SuperClasses.push_back(SC);
|
2009-08-08 09:50:56 +02:00
|
|
|
}
|
2020-01-28 20:23:46 +01:00
|
|
|
CI->ClassName = std::string(Rec->getValueAsString("Name"));
|
2009-08-10 20:41:10 +02:00
|
|
|
CI->Name = "MCK_" + CI->ClassName;
|
2020-01-28 20:23:46 +01:00
|
|
|
CI->ValueName = std::string(Rec->getName());
|
2009-08-10 23:00:45 +02:00
|
|
|
|
|
|
|
// Get or construct the predicate method name.
|
2014-11-25 21:11:31 +01:00
|
|
|
Init *PMName = Rec->getValueInit("PredicateMethod");
|
2012-10-10 22:24:43 +02:00
|
|
|
if (StringInit *SI = dyn_cast<StringInit>(PMName)) {
|
2020-01-28 20:23:46 +01:00
|
|
|
CI->PredicateMethod = std::string(SI->getValue());
|
2009-08-10 23:00:45 +02:00
|
|
|
} else {
|
2012-10-10 22:24:47 +02:00
|
|
|
assert(isa<UnsetInit>(PMName) && "Unexpected PredicateMethod field!");
|
2009-08-10 23:00:45 +02:00
|
|
|
CI->PredicateMethod = "is" + CI->ClassName;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get or construct the render method name.
|
2014-11-25 21:11:31 +01:00
|
|
|
Init *RMName = Rec->getValueInit("RenderMethod");
|
2012-10-10 22:24:43 +02:00
|
|
|
if (StringInit *SI = dyn_cast<StringInit>(RMName)) {
|
2020-01-28 20:23:46 +01:00
|
|
|
CI->RenderMethod = std::string(SI->getValue());
|
2009-08-10 23:00:45 +02:00
|
|
|
} else {
|
2012-10-10 22:24:47 +02:00
|
|
|
assert(isa<UnsetInit>(RMName) && "Unexpected RenderMethod field!");
|
2009-08-10 23:00:45 +02:00
|
|
|
CI->RenderMethod = "add" + CI->ClassName + "Operands";
|
|
|
|
}
|
|
|
|
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
// Get the parse method name or leave it as empty.
|
2014-11-25 21:11:31 +01:00
|
|
|
Init *PRMName = Rec->getValueInit("ParserMethod");
|
2012-10-10 22:24:43 +02:00
|
|
|
if (StringInit *SI = dyn_cast<StringInit>(PRMName))
|
2020-01-28 20:23:46 +01:00
|
|
|
CI->ParserMethod = std::string(SI->getValue());
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
|
2017-10-03 16:34:57 +02:00
|
|
|
// Get the diagnostic type and string or leave them as empty.
|
2014-11-25 21:11:31 +01:00
|
|
|
Init *DiagnosticType = Rec->getValueInit("DiagnosticType");
|
2012-10-10 22:24:43 +02:00
|
|
|
if (StringInit *SI = dyn_cast<StringInit>(DiagnosticType))
|
2020-01-28 20:23:46 +01:00
|
|
|
CI->DiagnosticType = std::string(SI->getValue());
|
2017-10-03 16:34:57 +02:00
|
|
|
Init *DiagnosticString = Rec->getValueInit("DiagnosticString");
|
|
|
|
if (StringInit *SI = dyn_cast<StringInit>(DiagnosticString))
|
2020-01-28 20:23:46 +01:00
|
|
|
CI->DiagnosticString = std::string(SI->getValue());
|
2017-10-03 16:34:57 +02:00
|
|
|
// If we have a DiagnosticString, we need a DiagnosticType for use within
|
|
|
|
// the matcher.
|
|
|
|
if (!CI->DiagnosticString.empty() && CI->DiagnosticType.empty())
|
|
|
|
CI->DiagnosticType = CI->ClassName;
|
2012-06-23 01:56:44 +02:00
|
|
|
|
2016-02-05 20:59:33 +01:00
|
|
|
Init *IsOptional = Rec->getValueInit("IsOptional");
|
|
|
|
if (BitInit *BI = dyn_cast<BitInit>(IsOptional))
|
|
|
|
CI->IsOptional = BI->getValue();
|
|
|
|
|
2016-05-06 13:31:17 +02:00
|
|
|
// Get or construct the default method name.
|
|
|
|
Init *DMName = Rec->getValueInit("DefaultMethod");
|
|
|
|
if (StringInit *SI = dyn_cast<StringInit>(DMName)) {
|
2020-01-28 20:23:46 +01:00
|
|
|
CI->DefaultMethod = std::string(SI->getValue());
|
2016-05-06 13:31:17 +02:00
|
|
|
} else {
|
|
|
|
assert(isa<UnsetInit>(DMName) && "Unexpected DefaultMethod field!");
|
|
|
|
CI->DefaultMethod = "default" + CI->ClassName + "Operands";
|
|
|
|
}
|
|
|
|
|
2014-11-25 21:11:31 +01:00
|
|
|
++Index;
|
2009-08-08 09:50:56 +02:00
|
|
|
}
|
2009-08-11 04:59:53 +02:00
|
|
|
}
|
|
|
|
|
2011-01-26 22:26:19 +01:00
|
|
|
AsmMatcherInfo::AsmMatcherInfo(Record *asmParser,
|
|
|
|
CodeGenTarget &target,
|
2010-12-15 05:48:22 +01:00
|
|
|
RecordKeeper &records)
|
2012-01-07 02:33:34 +01:00
|
|
|
: Records(records), AsmParser(asmParser), Target(target) {
|
2009-08-11 22:59:47 +02:00
|
|
|
}
|
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
/// buildOperandMatchInfo - Build the necessary information to handle user
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
/// defined operand parsing methods.
|
2012-04-19 19:52:32 +02:00
|
|
|
void AsmMatcherInfo::buildOperandMatchInfo() {
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
|
2012-04-19 01:46:25 +02:00
|
|
|
/// Map containing a mask with all operands indices that can be found for
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
/// that class inside a instruction.
|
2019-08-22 19:32:16 +02:00
|
|
|
typedef std::map<ClassInfo *, unsigned, deref<std::less<>>> OpClassMaskTy;
|
2012-09-19 03:47:03 +02:00
|
|
|
OpClassMaskTy OpClassMask;
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
|
2014-11-28 04:53:02 +01:00
|
|
|
for (const auto &MI : Matchables) {
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
OpClassMask.clear();
|
|
|
|
|
|
|
|
// Keep track of all operands of this instructions which belong to the
|
|
|
|
// same class.
|
2014-11-29 00:00:22 +01:00
|
|
|
for (unsigned i = 0, e = MI->AsmOperands.size(); i != e; ++i) {
|
|
|
|
const MatchableInfo::AsmOperand &Op = MI->AsmOperands[i];
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
if (Op.Class->ParserMethod.empty())
|
|
|
|
continue;
|
|
|
|
unsigned &OperandMask = OpClassMask[Op.Class];
|
|
|
|
OperandMask |= (1 << i);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate operand match info for each mnemonic/operand class pair.
|
2014-11-28 04:53:00 +01:00
|
|
|
for (const auto &OCM : OpClassMask) {
|
|
|
|
unsigned OpMask = OCM.second;
|
|
|
|
ClassInfo *CI = OCM.first;
|
2014-11-29 00:00:22 +01:00
|
|
|
OperandMatchInfo.push_back(OperandMatchEntry::create(MI.get(), CI,
|
|
|
|
OpMask));
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
void AsmMatcherInfo::buildInfo() {
|
2010-10-30 22:07:57 +02:00
|
|
|
// Build information about all of the AssemblerPredicates.
|
2016-11-15 10:51:02 +01:00
|
|
|
const std::vector<std::pair<Record *, SubtargetFeatureInfo>>
|
|
|
|
&SubtargetFeaturePairs = SubtargetFeatureInfo::getAll(Records);
|
|
|
|
SubtargetFeatures.insert(SubtargetFeaturePairs.begin(),
|
|
|
|
SubtargetFeaturePairs.end());
|
2016-11-15 11:13:09 +01:00
|
|
|
#ifndef NDEBUG
|
2016-11-15 10:51:02 +01:00
|
|
|
for (const auto &Pair : SubtargetFeatures)
|
2018-05-14 14:53:11 +02:00
|
|
|
LLVM_DEBUG(Pair.second.dump());
|
2016-11-15 11:13:09 +01:00
|
|
|
#endif // NDEBUG
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2015-12-31 09:18:23 +01:00
|
|
|
bool HasMnemonicFirst = AsmParser->getValueAsBit("HasMnemonicFirst");
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
bool ReportMultipleNearMisses =
|
|
|
|
AsmParser->getValueAsBit("ReportMultipleNearMisses");
|
2015-12-31 09:18:23 +01:00
|
|
|
|
2010-10-31 20:10:56 +01:00
|
|
|
// Parse the instructions; we need to do this first so that we can gather the
|
|
|
|
// singleton register classes.
|
2010-11-01 02:47:07 +01:00
|
|
|
SmallPtrSet<Record*, 16> SingletonRegisters;
|
2012-01-09 20:13:28 +01:00
|
|
|
unsigned VariantCount = Target.getAsmParserVariantCount();
|
|
|
|
for (unsigned VC = 0; VC != VariantCount; ++VC) {
|
|
|
|
Record *AsmVariant = Target.getAsmParserVariant(VC);
|
2017-05-31 23:12:46 +02:00
|
|
|
StringRef CommentDelimiter =
|
|
|
|
AsmVariant->getValueAsString("CommentDelimiter");
|
2015-11-09 01:31:07 +01:00
|
|
|
AsmVariantInfo Variant;
|
2015-12-30 07:00:18 +01:00
|
|
|
Variant.RegisterPrefix = AsmVariant->getValueAsString("RegisterPrefix");
|
2015-11-09 01:31:07 +01:00
|
|
|
Variant.TokenizingCharacters =
|
|
|
|
AsmVariant->getValueAsString("TokenizingCharacters");
|
|
|
|
Variant.SeparatorCharacters =
|
|
|
|
AsmVariant->getValueAsString("SeparatorCharacters");
|
|
|
|
Variant.BreakCharacters =
|
|
|
|
AsmVariant->getValueAsString("BreakCharacters");
|
2016-09-08 17:50:52 +02:00
|
|
|
Variant.Name = AsmVariant->getValueAsString("Name");
|
2015-12-30 07:00:18 +01:00
|
|
|
Variant.AsmVariantNo = AsmVariant->getValueAsInt("Variant");
|
2012-01-24 22:06:59 +01:00
|
|
|
|
2016-01-17 21:38:18 +01:00
|
|
|
for (const CodeGenInstruction *CGI : Target.getInstructionsByEnumValue()) {
|
2012-01-24 22:06:59 +01:00
|
|
|
|
2012-01-09 20:13:28 +01:00
|
|
|
// If the tblgen -match-prefix option is specified (for tblgen hackers),
|
|
|
|
// filter the set of instructions we consider.
|
2014-11-25 21:11:31 +01:00
|
|
|
if (!StringRef(CGI->TheDef->getName()).startswith(MatchPrefix))
|
2012-04-11 23:02:33 +02:00
|
|
|
continue;
|
2012-01-24 22:06:59 +01:00
|
|
|
|
2012-01-09 20:13:28 +01:00
|
|
|
// Ignore "codegen only" instructions.
|
2014-11-25 21:11:31 +01:00
|
|
|
if (CGI->TheDef->getValueAsBit("isCodeGenOnly"))
|
2012-04-11 23:02:33 +02:00
|
|
|
continue;
|
2012-01-24 22:06:59 +01:00
|
|
|
|
2016-09-08 17:50:52 +02:00
|
|
|
// Ignore instructions for different instructions
|
2017-05-31 23:12:46 +02:00
|
|
|
StringRef V = CGI->TheDef->getValueAsString("AsmVariantName");
|
2016-09-08 17:50:52 +02:00
|
|
|
if (!V.empty() && V != Variant.Name)
|
|
|
|
continue;
|
|
|
|
|
2019-08-15 17:54:37 +02:00
|
|
|
auto II = std::make_unique<MatchableInfo>(*CGI);
|
2012-01-24 22:06:59 +01:00
|
|
|
|
2015-12-31 09:18:23 +01:00
|
|
|
II->initialize(*this, SingletonRegisters, Variant, HasMnemonicFirst);
|
2012-01-24 22:06:59 +01:00
|
|
|
|
2012-01-09 20:13:28 +01:00
|
|
|
// Ignore instructions which shouldn't be matched and diagnose invalid
|
|
|
|
// instruction definitions with an error.
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
if (!II->validate(CommentDelimiter, false))
|
2014-11-29 00:00:22 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
Matchables.push_back(std::move(II));
|
2012-01-09 20:13:28 +01:00
|
|
|
}
|
2012-01-24 22:06:59 +01:00
|
|
|
|
2012-01-09 20:13:28 +01:00
|
|
|
// Parse all of the InstAlias definitions and stick them in the list of
|
|
|
|
// matchables.
|
|
|
|
std::vector<Record*> AllInstAliases =
|
|
|
|
Records.getAllDerivedDefinitions("InstAlias");
|
|
|
|
for (unsigned i = 0, e = AllInstAliases.size(); i != e; ++i) {
|
2019-08-15 17:54:37 +02:00
|
|
|
auto Alias = std::make_unique<CodeGenInstAlias>(AllInstAliases[i],
|
2015-12-30 07:00:18 +01:00
|
|
|
Target);
|
2012-01-24 22:06:59 +01:00
|
|
|
|
2012-01-09 20:13:28 +01:00
|
|
|
// If the tblgen -match-prefix option is specified (for tblgen hackers),
|
|
|
|
// filter the set of instruction aliases we consider, based on the target
|
|
|
|
// instruction.
|
2012-04-17 02:01:04 +02:00
|
|
|
if (!StringRef(Alias->ResultInst->TheDef->getName())
|
|
|
|
.startswith( MatchPrefix))
|
2012-04-11 23:02:33 +02:00
|
|
|
continue;
|
2012-01-24 22:06:59 +01:00
|
|
|
|
2017-05-31 23:12:46 +02:00
|
|
|
StringRef V = Alias->TheDef->getValueAsString("AsmVariantName");
|
2016-09-08 17:50:52 +02:00
|
|
|
if (!V.empty() && V != Variant.Name)
|
|
|
|
continue;
|
|
|
|
|
2019-08-15 17:54:37 +02:00
|
|
|
auto II = std::make_unique<MatchableInfo>(std::move(Alias));
|
2012-01-24 22:06:59 +01:00
|
|
|
|
2015-12-31 09:18:23 +01:00
|
|
|
II->initialize(*this, SingletonRegisters, Variant, HasMnemonicFirst);
|
2012-01-24 22:06:59 +01:00
|
|
|
|
2012-01-09 20:13:28 +01:00
|
|
|
// Validate the alias definitions.
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
II->validate(CommentDelimiter, true);
|
2014-11-29 00:00:22 +01:00
|
|
|
|
|
|
|
Matchables.push_back(std::move(II));
|
2010-11-04 01:43:46 +01:00
|
|
|
}
|
2010-11-01 05:05:41 +01:00
|
|
|
}
|
2010-11-01 05:03:32 +01:00
|
|
|
|
2009-08-12 01:23:44 +02:00
|
|
|
// Build info for the register classes.
|
2012-04-19 19:52:32 +02:00
|
|
|
buildRegisterClasses(SingletonRegisters);
|
2009-08-12 01:23:44 +02:00
|
|
|
|
|
|
|
// Build info for the user defined assembly operand classes.
|
2012-04-19 19:52:32 +02:00
|
|
|
buildOperandClasses();
|
2009-08-12 01:23:44 +02:00
|
|
|
|
2010-11-04 01:57:06 +01:00
|
|
|
// Build the information about matchables, now that we have fully formed
|
|
|
|
// classes.
|
2014-11-29 00:00:22 +01:00
|
|
|
std::vector<std::unique_ptr<MatchableInfo>> NewMatchables;
|
2014-11-28 04:53:02 +01:00
|
|
|
for (auto &II : Matchables) {
|
2010-09-06 23:01:37 +02:00
|
|
|
// Parse the tokens after the mnemonic.
|
2012-04-19 19:52:32 +02:00
|
|
|
// Note: buildInstructionOperandReference may insert new AsmOperands, so
|
2011-01-26 20:44:55 +01:00
|
|
|
// don't precompute the loop bound.
|
2014-11-29 00:00:22 +01:00
|
|
|
for (unsigned i = 0; i != II->AsmOperands.size(); ++i) {
|
|
|
|
MatchableInfo::AsmOperand &Op = II->AsmOperands[i];
|
2010-11-02 18:30:52 +01:00
|
|
|
StringRef Token = Op.Token;
|
2009-08-07 10:26:05 +02:00
|
|
|
|
2009-08-12 01:23:44 +02:00
|
|
|
// Check for singleton registers.
|
2015-12-29 08:03:23 +01:00
|
|
|
if (Record *RegRecord = Op.SingletonReg) {
|
2010-11-02 18:30:52 +01:00
|
|
|
Op.Class = RegisterClasses[RegRecord];
|
2010-11-01 02:37:30 +01:00
|
|
|
assert(Op.Class && Op.Class->Registers.size() == 1 &&
|
|
|
|
"Unexpected class for singleton register");
|
|
|
|
continue;
|
2009-08-12 01:23:44 +02:00
|
|
|
}
|
|
|
|
|
2009-08-07 10:26:05 +02:00
|
|
|
// Check for simple tokens.
|
|
|
|
if (Token[0] != '$') {
|
2010-11-02 18:30:52 +01:00
|
|
|
Op.Class = getTokenClass(Token);
|
2009-08-07 10:26:05 +02:00
|
|
|
continue;
|
|
|
|
}
|
2009-07-31 04:32:59 +02:00
|
|
|
|
2010-11-06 23:06:03 +01:00
|
|
|
if (Token.size() > 1 && isdigit(Token[1])) {
|
|
|
|
Op.Class = getTokenClass(Token);
|
|
|
|
continue;
|
|
|
|
}
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-11-04 03:11:18 +01:00
|
|
|
// Otherwise this is an operand reference.
|
2010-11-04 02:58:23 +01:00
|
|
|
StringRef OperandName;
|
|
|
|
if (Token[1] == '{')
|
|
|
|
OperandName = Token.substr(2, Token.size() - 3);
|
|
|
|
else
|
|
|
|
OperandName = Token.substr(1);
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2014-11-29 00:00:22 +01:00
|
|
|
if (II->DefRec.is<const CodeGenInstruction*>())
|
|
|
|
buildInstructionOperandReference(II.get(), OperandName, i);
|
2010-11-04 03:11:18 +01:00
|
|
|
else
|
2014-11-29 00:00:22 +01:00
|
|
|
buildAliasOperandReference(II.get(), OperandName, Op);
|
2009-08-04 22:36:45 +02:00
|
|
|
}
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2014-11-29 00:00:22 +01:00
|
|
|
if (II->DefRec.is<const CodeGenInstruction*>()) {
|
|
|
|
II->buildInstructionResultOperands();
|
2012-04-20 01:59:23 +02:00
|
|
|
// If the instruction has a two-operand alias, build up the
|
|
|
|
// matchable here. We'll add them in bulk at the end to avoid
|
|
|
|
// confusing this loop.
|
2017-05-31 23:12:46 +02:00
|
|
|
StringRef Constraint =
|
|
|
|
II->TheDef->getValueAsString("TwoOperandAliasConstraint");
|
2012-04-20 01:59:23 +02:00
|
|
|
if (Constraint != "") {
|
|
|
|
// Start by making a copy of the original matchable.
|
2019-08-15 17:54:37 +02:00
|
|
|
auto AliasII = std::make_unique<MatchableInfo>(*II);
|
2012-04-20 01:59:23 +02:00
|
|
|
|
|
|
|
// Adjust it to be a two-operand alias.
|
2014-11-29 00:00:22 +01:00
|
|
|
AliasII->formTwoOperandAlias(Constraint);
|
|
|
|
|
|
|
|
// Add the alias to the matchables list.
|
|
|
|
NewMatchables.push_back(std::move(AliasII));
|
2012-04-20 01:59:23 +02:00
|
|
|
}
|
|
|
|
} else
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
// FIXME: The tied operands checking is not yet integrated with the
|
|
|
|
// framework for reporting multiple near misses. To prevent invalid
|
|
|
|
// formats from being matched with an alias if a tied-operands check
|
|
|
|
// would otherwise have disallowed it, we just disallow such constructs
|
|
|
|
// in TableGen completely.
|
|
|
|
II->buildAliasResultOperands(!ReportMultipleNearMisses);
|
2009-08-07 10:26:05 +02:00
|
|
|
}
|
2014-11-29 00:00:22 +01:00
|
|
|
if (!NewMatchables.empty())
|
2015-02-28 11:11:12 +01:00
|
|
|
Matchables.insert(Matchables.end(),
|
|
|
|
std::make_move_iterator(NewMatchables.begin()),
|
|
|
|
std::make_move_iterator(NewMatchables.end()));
|
2009-08-09 09:20:21 +02:00
|
|
|
|
2011-12-07 00:43:54 +01:00
|
|
|
// Process token alias definitions and set up the associated superclass
|
|
|
|
// information.
|
|
|
|
std::vector<Record*> AllTokenAliases =
|
|
|
|
Records.getAllDerivedDefinitions("TokenAlias");
|
2015-12-29 08:03:23 +01:00
|
|
|
for (Record *Rec : AllTokenAliases) {
|
2011-12-07 00:43:54 +01:00
|
|
|
ClassInfo *FromClass = getTokenClass(Rec->getValueAsString("FromToken"));
|
|
|
|
ClassInfo *ToClass = getTokenClass(Rec->getValueAsString("ToToken"));
|
2012-04-17 23:23:52 +02:00
|
|
|
if (FromClass == ToClass)
|
2012-10-25 22:33:17 +02:00
|
|
|
PrintFatalError(Rec->getLoc(),
|
2012-04-17 23:23:52 +02:00
|
|
|
"error: Destination value identical to source value.");
|
2011-12-07 00:43:54 +01:00
|
|
|
FromClass->SuperClasses.push_back(ToClass);
|
|
|
|
}
|
|
|
|
|
2011-04-15 07:18:47 +02:00
|
|
|
// Reorder classes so that classes precede super classes.
|
2014-11-28 21:35:57 +01:00
|
|
|
Classes.sort();
|
2016-01-25 11:20:19 +01:00
|
|
|
|
2016-12-05 20:44:31 +01:00
|
|
|
#ifdef EXPENSIVE_CHECKS
|
|
|
|
// Verify that the table is sorted and operator < works transitively.
|
2016-01-25 11:20:19 +01:00
|
|
|
for (auto I = Classes.begin(), E = Classes.end(); I != E; ++I) {
|
|
|
|
for (auto J = I; J != E; ++J) {
|
|
|
|
assert(!(*J < *I));
|
|
|
|
assert(I == J || !J->isSubsetOf(*I));
|
|
|
|
}
|
|
|
|
}
|
2016-12-05 20:44:31 +01:00
|
|
|
#endif
|
2009-08-07 10:26:05 +02:00
|
|
|
}
|
2009-07-31 04:32:59 +02:00
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
/// buildInstructionOperandReference - The specified operand is a reference to a
|
2010-11-04 01:57:06 +01:00
|
|
|
/// named operand such as $src. Resolve the Class and OperandInfo pointers.
|
|
|
|
void AsmMatcherInfo::
|
2012-04-19 19:52:32 +02:00
|
|
|
buildInstructionOperandReference(MatchableInfo *II,
|
2010-11-04 02:58:23 +01:00
|
|
|
StringRef OperandName,
|
2011-01-26 20:44:55 +01:00
|
|
|
unsigned AsmOpIdx) {
|
2010-11-04 03:11:18 +01:00
|
|
|
const CodeGenInstruction &CGI = *II->DefRec.get<const CodeGenInstruction*>();
|
|
|
|
const CGIOperandList &Operands = CGI.Operands;
|
2011-01-26 20:44:55 +01:00
|
|
|
MatchableInfo::AsmOperand *Op = &II->AsmOperands[AsmOpIdx];
|
2011-01-26 22:26:19 +01:00
|
|
|
|
Reimplement BuildResultOperands to be in terms of the result instruction's
operand list instead of the operand list redundantly declared on the alias
or instruction.
With this change, we finally remove the ins/outs list on the alias. Before:
def : InstAlias<(outs GR16:$dst), (ins GR8 :$src),
"movsx $src, $dst",
(MOVSX16rr8W GR16:$dst, GR8:$src)>;
After:
def : InstAlias<"movsx $src, $dst",
(MOVSX16rr8W GR16:$dst, GR8:$src)>;
This also makes the alias mechanism more general and powerful, which will
be exploited in subsequent patches.
llvm-svn: 118329
2010-11-06 08:14:44 +01:00
|
|
|
// Map this token to an operand.
|
2010-11-04 01:57:06 +01:00
|
|
|
unsigned Idx;
|
|
|
|
if (!Operands.hasOperandNamed(OperandName, Idx))
|
2014-03-29 18:17:15 +01:00
|
|
|
PrintFatalError(II->TheDef->getLoc(),
|
|
|
|
"error: unable to find operand: '" + OperandName + "'");
|
2010-11-04 02:55:23 +01:00
|
|
|
|
2011-01-26 20:44:55 +01:00
|
|
|
// If the instruction operand has multiple suboperands, but the parser
|
|
|
|
// match class for the asm operand is still the default "ImmAsmOperand",
|
|
|
|
// then handle each suboperand separately.
|
|
|
|
if (Op->SubOpIdx == -1 && Operands[Idx].MINumOperands > 1) {
|
|
|
|
Record *Rec = Operands[Idx].Rec;
|
|
|
|
assert(Rec->isSubClassOf("Operand") && "Unexpected operand!");
|
|
|
|
Record *MatchClass = Rec->getValueAsDef("ParserMatchClass");
|
|
|
|
if (MatchClass && MatchClass->getValueAsString("Name") == "Imm") {
|
|
|
|
// Insert remaining suboperands after AsmOpIdx in II->AsmOperands.
|
|
|
|
StringRef Token = Op->Token; // save this in case Op gets moved
|
|
|
|
for (unsigned SI = 1, SE = Operands[Idx].MINumOperands; SI != SE; ++SI) {
|
2015-05-29 03:03:37 +02:00
|
|
|
MatchableInfo::AsmOperand NewAsmOp(/*IsIsolatedToken=*/true, Token);
|
2011-01-26 20:44:55 +01:00
|
|
|
NewAsmOp.SubOpIdx = SI;
|
|
|
|
II->AsmOperands.insert(II->AsmOperands.begin()+AsmOpIdx+SI, NewAsmOp);
|
|
|
|
}
|
|
|
|
// Replace Op with first suboperand.
|
|
|
|
Op = &II->AsmOperands[AsmOpIdx]; // update the pointer in case it moved
|
|
|
|
Op->SubOpIdx = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-04 02:55:23 +01:00
|
|
|
// Set up the operand class.
|
2011-01-26 20:44:55 +01:00
|
|
|
Op->Class = getOperandClass(Operands[Idx], Op->SubOpIdx);
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
Op->OrigSrcOpName = OperandName;
|
2010-11-04 02:55:23 +01:00
|
|
|
|
|
|
|
// If the named operand is tied, canonicalize it to the untied operand.
|
|
|
|
// For example, something like:
|
|
|
|
// (outs GPR:$dst), (ins GPR:$src)
|
|
|
|
// with an asmstring of
|
|
|
|
// "inc $src"
|
|
|
|
// we want to canonicalize to:
|
2010-11-04 03:11:18 +01:00
|
|
|
// "inc $dst"
|
|
|
|
// so that we know how to provide the $dst operand when filling in the result.
|
Handle tied sub-operands in AsmMatcherEmitter
The problem this patch addresses is the handling of register tie
constraints in AsmMatcherEmitter, where one operand is tied to a
sub-operand of another operand. The typical scenario for this to
happen is the tie between the "write-back" register of a pre-inc
instruction, and the base register sub-operand of the memory address
operand of that instruction.
The current AsmMatcherEmitter code attempts to handle tied
operands by emitting the operand as usual first, and emitting
a CVT_Tied node when handling the second (tied) operand. However,
this really only works correctly if the tied operand does not
have sub-operands (and isn't a sub-operand itself). Under those
circumstances, a wrong MC operand list is generated.
In discussions with Jim Grosbach, it turned out that the MC operand
list really ought not to contain tied operands in the first place;
instead, it ought to consist of exactly those operands that are
named in the AsmString. However, getting there requires significant
rework of (some) targets.
This patch fixes the immediate problem, and at the same time makes
one (small) step in the direction of the long-term solution, by
implementing two changes:
1. Restricts the AsmMatcherEmitter handling of tied operands to
apply solely to simple operands (not complex operands or
sub-operand of such).
This means that at least we don't get silently corrupt MC operand
lists as output. However, if we do have tied sub-operands, they
would now no longer be handled at all, except for:
2. If we have an operand that does not occur in the AsmString,
and also isn't handled as tied operand, simply emit a dummy
MC operand (constant 0).
This works as long as target code never attempts to access
MC operands that do no not occur in the AsmString (and are
not tied simple operands), which happens to be the case for
all targets where this situation can occur (ARM and PowerPC).
[ Note that this change means that many of the ARM custom
converters are now superfluous, since the implement the
same "hack" now performed already by common code. ]
Longer term, we ought to fix targets to never access *any*
MC operand that does not occur in the AsmString (including
tied simple operands), and then finally completely remove
all such operands from the MC operand list.
Patch approved by Jim Grosbach.
llvm-svn: 180677
2013-04-27 20:48:23 +02:00
|
|
|
int OITied = -1;
|
|
|
|
if (Operands[Idx].MINumOperands == 1)
|
|
|
|
OITied = Operands[Idx].getTiedRegister();
|
2010-11-04 03:11:18 +01:00
|
|
|
if (OITied != -1) {
|
|
|
|
// The tied operand index is an MIOperand index, find the operand that
|
|
|
|
// contains it.
|
2011-01-26 20:44:55 +01:00
|
|
|
std::pair<unsigned, unsigned> Idx = Operands.getSubOperandNumber(OITied);
|
|
|
|
OperandName = Operands[Idx.first].Name;
|
|
|
|
Op->SubOpIdx = Idx.second;
|
2010-11-04 03:11:18 +01:00
|
|
|
}
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2011-01-26 20:44:55 +01:00
|
|
|
Op->SrcOpName = OperandName;
|
2010-11-04 03:11:18 +01:00
|
|
|
}
|
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
/// buildAliasOperandReference - When parsing an operand reference out of the
|
2010-11-06 08:06:09 +01:00
|
|
|
/// matching string (e.g. "movsx $src, $dst"), determine what the class of the
|
|
|
|
/// operand reference is by looking it up in the result pattern definition.
|
2012-04-19 19:52:32 +02:00
|
|
|
void AsmMatcherInfo::buildAliasOperandReference(MatchableInfo *II,
|
2010-11-04 03:11:18 +01:00
|
|
|
StringRef OperandName,
|
|
|
|
MatchableInfo::AsmOperand &Op) {
|
|
|
|
const CodeGenInstAlias &CGA = *II->DefRec.get<const CodeGenInstAlias*>();
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-11-04 03:11:18 +01:00
|
|
|
// Set up the operand class.
|
2010-11-06 08:06:09 +01:00
|
|
|
for (unsigned i = 0, e = CGA.ResultOperands.size(); i != e; ++i)
|
2010-11-06 20:25:43 +01:00
|
|
|
if (CGA.ResultOperands[i].isRecord() &&
|
|
|
|
CGA.ResultOperands[i].getName() == OperandName) {
|
Reimplement BuildResultOperands to be in terms of the result instruction's
operand list instead of the operand list redundantly declared on the alias
or instruction.
With this change, we finally remove the ins/outs list on the alias. Before:
def : InstAlias<(outs GR16:$dst), (ins GR8 :$src),
"movsx $src, $dst",
(MOVSX16rr8W GR16:$dst, GR8:$src)>;
After:
def : InstAlias<"movsx $src, $dst",
(MOVSX16rr8W GR16:$dst, GR8:$src)>;
This also makes the alias mechanism more general and powerful, which will
be exploited in subsequent patches.
llvm-svn: 118329
2010-11-06 08:14:44 +01:00
|
|
|
// It's safe to go with the first one we find, because CodeGenInstAlias
|
|
|
|
// validates that all operands with the same name have the same record.
|
2011-01-26 20:44:55 +01:00
|
|
|
Op.SubOpIdx = CGA.ResultInstOperandIndex[i].second;
|
2011-10-29 00:32:53 +02:00
|
|
|
// Use the match class from the Alias definition, not the
|
|
|
|
// destination instruction, as we may have an immediate that's
|
|
|
|
// being munged by the match class.
|
|
|
|
Op.Class = getOperandClass(CGA.ResultOperands[i].getRecord(),
|
2011-01-26 20:44:55 +01:00
|
|
|
Op.SubOpIdx);
|
2010-11-06 08:06:09 +01:00
|
|
|
Op.SrcOpName = OperandName;
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
Op.OrigSrcOpName = OperandName;
|
2010-11-06 08:06:09 +01:00
|
|
|
return;
|
2010-11-04 01:57:06 +01:00
|
|
|
}
|
2010-11-06 08:06:09 +01:00
|
|
|
|
2014-03-29 18:17:15 +01:00
|
|
|
PrintFatalError(II->TheDef->getLoc(),
|
|
|
|
"error: unable to find operand: '" + OperandName + "'");
|
2010-11-04 01:57:06 +01:00
|
|
|
}
|
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
void MatchableInfo::buildInstructionResultOperands() {
|
Reimplement BuildResultOperands to be in terms of the result instruction's
operand list instead of the operand list redundantly declared on the alias
or instruction.
With this change, we finally remove the ins/outs list on the alias. Before:
def : InstAlias<(outs GR16:$dst), (ins GR8 :$src),
"movsx $src, $dst",
(MOVSX16rr8W GR16:$dst, GR8:$src)>;
After:
def : InstAlias<"movsx $src, $dst",
(MOVSX16rr8W GR16:$dst, GR8:$src)>;
This also makes the alias mechanism more general and powerful, which will
be exploited in subsequent patches.
llvm-svn: 118329
2010-11-06 08:14:44 +01:00
|
|
|
const CodeGenInstruction *ResultInst = getResultInst();
|
2011-01-26 22:26:19 +01:00
|
|
|
|
Reimplement BuildResultOperands to be in terms of the result instruction's
operand list instead of the operand list redundantly declared on the alias
or instruction.
With this change, we finally remove the ins/outs list on the alias. Before:
def : InstAlias<(outs GR16:$dst), (ins GR8 :$src),
"movsx $src, $dst",
(MOVSX16rr8W GR16:$dst, GR8:$src)>;
After:
def : InstAlias<"movsx $src, $dst",
(MOVSX16rr8W GR16:$dst, GR8:$src)>;
This also makes the alias mechanism more general and powerful, which will
be exploited in subsequent patches.
llvm-svn: 118329
2010-11-06 08:14:44 +01:00
|
|
|
// Loop over all operands of the result instruction, determining how to
|
|
|
|
// populate them.
|
2015-12-29 08:03:23 +01:00
|
|
|
for (const CGIOperandList::OperandInfo &OpInfo : ResultInst->Operands) {
|
2010-11-04 02:42:59 +01:00
|
|
|
// If this is a tied operand, just copy from the previously handled operand.
|
Handle tied sub-operands in AsmMatcherEmitter
The problem this patch addresses is the handling of register tie
constraints in AsmMatcherEmitter, where one operand is tied to a
sub-operand of another operand. The typical scenario for this to
happen is the tie between the "write-back" register of a pre-inc
instruction, and the base register sub-operand of the memory address
operand of that instruction.
The current AsmMatcherEmitter code attempts to handle tied
operands by emitting the operand as usual first, and emitting
a CVT_Tied node when handling the second (tied) operand. However,
this really only works correctly if the tied operand does not
have sub-operands (and isn't a sub-operand itself). Under those
circumstances, a wrong MC operand list is generated.
In discussions with Jim Grosbach, it turned out that the MC operand
list really ought not to contain tied operands in the first place;
instead, it ought to consist of exactly those operands that are
named in the AsmString. However, getting there requires significant
rework of (some) targets.
This patch fixes the immediate problem, and at the same time makes
one (small) step in the direction of the long-term solution, by
implementing two changes:
1. Restricts the AsmMatcherEmitter handling of tied operands to
apply solely to simple operands (not complex operands or
sub-operand of such).
This means that at least we don't get silently corrupt MC operand
lists as output. However, if we do have tied sub-operands, they
would now no longer be handled at all, except for:
2. If we have an operand that does not occur in the AsmString,
and also isn't handled as tied operand, simply emit a dummy
MC operand (constant 0).
This works as long as target code never attempts to access
MC operands that do no not occur in the AsmString (and are
not tied simple operands), which happens to be the case for
all targets where this situation can occur (ARM and PowerPC).
[ Note that this change means that many of the ARM custom
converters are now superfluous, since the implement the
same "hack" now performed already by common code. ]
Longer term, we ought to fix targets to never access *any*
MC operand that does not occur in the AsmString (including
tied simple operands), and then finally completely remove
all such operands from the MC operand list.
Patch approved by Jim Grosbach.
llvm-svn: 180677
2013-04-27 20:48:23 +02:00
|
|
|
int TiedOp = -1;
|
|
|
|
if (OpInfo.MINumOperands == 1)
|
|
|
|
TiedOp = OpInfo.getTiedRegister();
|
2010-11-04 02:42:59 +01:00
|
|
|
if (TiedOp != -1) {
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
int TiedSrcOperand = findAsmOperandOriginallyNamed(OpInfo.Name);
|
|
|
|
if (TiedSrcOperand != -1 &&
|
|
|
|
ResOperands[TiedOp].Kind == ResOperand::RenderAsmOperand)
|
|
|
|
ResOperands.push_back(ResOperand::getTiedOp(
|
|
|
|
TiedOp, ResOperands[TiedOp].AsmOperandNum, TiedSrcOperand));
|
|
|
|
else
|
|
|
|
ResOperands.push_back(ResOperand::getTiedOp(TiedOp, 0, 0));
|
2010-11-04 02:42:59 +01:00
|
|
|
continue;
|
|
|
|
}
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
int SrcOperand = findAsmOperandNamed(OpInfo.Name);
|
Handle tied sub-operands in AsmMatcherEmitter
The problem this patch addresses is the handling of register tie
constraints in AsmMatcherEmitter, where one operand is tied to a
sub-operand of another operand. The typical scenario for this to
happen is the tie between the "write-back" register of a pre-inc
instruction, and the base register sub-operand of the memory address
operand of that instruction.
The current AsmMatcherEmitter code attempts to handle tied
operands by emitting the operand as usual first, and emitting
a CVT_Tied node when handling the second (tied) operand. However,
this really only works correctly if the tied operand does not
have sub-operands (and isn't a sub-operand itself). Under those
circumstances, a wrong MC operand list is generated.
In discussions with Jim Grosbach, it turned out that the MC operand
list really ought not to contain tied operands in the first place;
instead, it ought to consist of exactly those operands that are
named in the AsmString. However, getting there requires significant
rework of (some) targets.
This patch fixes the immediate problem, and at the same time makes
one (small) step in the direction of the long-term solution, by
implementing two changes:
1. Restricts the AsmMatcherEmitter handling of tied operands to
apply solely to simple operands (not complex operands or
sub-operand of such).
This means that at least we don't get silently corrupt MC operand
lists as output. However, if we do have tied sub-operands, they
would now no longer be handled at all, except for:
2. If we have an operand that does not occur in the AsmString,
and also isn't handled as tied operand, simply emit a dummy
MC operand (constant 0).
This works as long as target code never attempts to access
MC operands that do no not occur in the AsmString (and are
not tied simple operands), which happens to be the case for
all targets where this situation can occur (ARM and PowerPC).
[ Note that this change means that many of the ARM custom
converters are now superfluous, since the implement the
same "hack" now performed already by common code. ]
Longer term, we ought to fix targets to never access *any*
MC operand that does not occur in the AsmString (including
tied simple operands), and then finally completely remove
all such operands from the MC operand list.
Patch approved by Jim Grosbach.
llvm-svn: 180677
2013-04-27 20:48:23 +02:00
|
|
|
if (OpInfo.Name.empty() || SrcOperand == -1) {
|
|
|
|
// This may happen for operands that are tied to a suboperand of a
|
|
|
|
// complex operand. Simply use a dummy value here; nobody should
|
|
|
|
// use this operand slot.
|
|
|
|
// FIXME: The long term goal is for the MCOperand list to not contain
|
|
|
|
// tied operands at all.
|
|
|
|
ResOperands.push_back(ResOperand::getImmOp(0));
|
|
|
|
continue;
|
|
|
|
}
|
2010-11-04 02:42:59 +01:00
|
|
|
|
2011-01-26 20:44:55 +01:00
|
|
|
// Check if the one AsmOperand populates the entire operand.
|
|
|
|
unsigned NumOperands = OpInfo.MINumOperands;
|
|
|
|
if (AsmOperands[SrcOperand].SubOpIdx == -1) {
|
|
|
|
ResOperands.push_back(ResOperand::getRenderedOp(SrcOperand, NumOperands));
|
2010-11-04 01:43:46 +01:00
|
|
|
continue;
|
|
|
|
}
|
2011-01-26 20:44:55 +01:00
|
|
|
|
|
|
|
// Add a separate ResOperand for each suboperand.
|
|
|
|
for (unsigned AI = 0; AI < NumOperands; ++AI) {
|
|
|
|
assert(AsmOperands[SrcOperand+AI].SubOpIdx == (int)AI &&
|
|
|
|
AsmOperands[SrcOperand+AI].SrcOpName == OpInfo.Name &&
|
|
|
|
"unexpected AsmOperands for suboperands");
|
|
|
|
ResOperands.push_back(ResOperand::getRenderedOp(SrcOperand + AI, 1));
|
|
|
|
}
|
2010-11-04 01:43:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
void MatchableInfo::buildAliasResultOperands(bool AliasConstraintsAreChecked) {
|
2010-11-06 08:31:43 +01:00
|
|
|
const CodeGenInstAlias &CGA = *DefRec.get<const CodeGenInstAlias*>();
|
|
|
|
const CodeGenInstruction *ResultInst = getResultInst();
|
2011-01-26 22:26:19 +01:00
|
|
|
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
// Map of: $reg -> #lastref
|
|
|
|
// where $reg is the name of the operand in the asm string
|
|
|
|
// where #lastref is the last processed index where $reg was referenced in
|
|
|
|
// the asm string.
|
|
|
|
SmallDenseMap<StringRef, int> OperandRefs;
|
|
|
|
|
2010-11-06 08:31:43 +01:00
|
|
|
// Loop over all operands of the result instruction, determining how to
|
|
|
|
// populate them.
|
|
|
|
unsigned AliasOpNo = 0;
|
2011-01-26 20:44:55 +01:00
|
|
|
unsigned LastOpNo = CGA.ResultInstOperandIndex.size();
|
2010-11-06 08:31:43 +01:00
|
|
|
for (unsigned i = 0, e = ResultInst->Operands.size(); i != e; ++i) {
|
2011-01-26 20:44:55 +01:00
|
|
|
const CGIOperandList::OperandInfo *OpInfo = &ResultInst->Operands[i];
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-11-06 08:31:43 +01:00
|
|
|
// If this is a tied operand, just copy from the previously handled operand.
|
Handle tied sub-operands in AsmMatcherEmitter
The problem this patch addresses is the handling of register tie
constraints in AsmMatcherEmitter, where one operand is tied to a
sub-operand of another operand. The typical scenario for this to
happen is the tie between the "write-back" register of a pre-inc
instruction, and the base register sub-operand of the memory address
operand of that instruction.
The current AsmMatcherEmitter code attempts to handle tied
operands by emitting the operand as usual first, and emitting
a CVT_Tied node when handling the second (tied) operand. However,
this really only works correctly if the tied operand does not
have sub-operands (and isn't a sub-operand itself). Under those
circumstances, a wrong MC operand list is generated.
In discussions with Jim Grosbach, it turned out that the MC operand
list really ought not to contain tied operands in the first place;
instead, it ought to consist of exactly those operands that are
named in the AsmString. However, getting there requires significant
rework of (some) targets.
This patch fixes the immediate problem, and at the same time makes
one (small) step in the direction of the long-term solution, by
implementing two changes:
1. Restricts the AsmMatcherEmitter handling of tied operands to
apply solely to simple operands (not complex operands or
sub-operand of such).
This means that at least we don't get silently corrupt MC operand
lists as output. However, if we do have tied sub-operands, they
would now no longer be handled at all, except for:
2. If we have an operand that does not occur in the AsmString,
and also isn't handled as tied operand, simply emit a dummy
MC operand (constant 0).
This works as long as target code never attempts to access
MC operands that do no not occur in the AsmString (and are
not tied simple operands), which happens to be the case for
all targets where this situation can occur (ARM and PowerPC).
[ Note that this change means that many of the ARM custom
converters are now superfluous, since the implement the
same "hack" now performed already by common code. ]
Longer term, we ought to fix targets to never access *any*
MC operand that does not occur in the AsmString (including
tied simple operands), and then finally completely remove
all such operands from the MC operand list.
Patch approved by Jim Grosbach.
llvm-svn: 180677
2013-04-27 20:48:23 +02:00
|
|
|
int TiedOp = -1;
|
|
|
|
if (OpInfo->MINumOperands == 1)
|
|
|
|
TiedOp = OpInfo->getTiedRegister();
|
2010-11-06 08:31:43 +01:00
|
|
|
if (TiedOp != -1) {
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
unsigned SrcOp1 = 0;
|
|
|
|
unsigned SrcOp2 = 0;
|
|
|
|
|
|
|
|
// If an operand has been specified twice in the asm string,
|
|
|
|
// add the two source operand's indices to the TiedOp so that
|
|
|
|
// at runtime the 'tied' constraint is checked.
|
|
|
|
if (ResOperands[TiedOp].Kind == ResOperand::RenderAsmOperand) {
|
|
|
|
SrcOp1 = ResOperands[TiedOp].AsmOperandNum;
|
|
|
|
|
|
|
|
// Find the next operand (similarly named operand) in the string.
|
|
|
|
StringRef Name = AsmOperands[SrcOp1].SrcOpName;
|
|
|
|
auto Insert = OperandRefs.try_emplace(Name, SrcOp1);
|
|
|
|
SrcOp2 = findAsmOperandNamed(Name, Insert.first->second);
|
|
|
|
|
|
|
|
// Not updating the record in OperandRefs will cause TableGen
|
|
|
|
// to fail with an error at the end of this function.
|
|
|
|
if (AliasConstraintsAreChecked)
|
|
|
|
Insert.first->second = SrcOp2;
|
|
|
|
|
|
|
|
// In case it only has one reference in the asm string,
|
|
|
|
// it doesn't need to be checked for tied constraints.
|
|
|
|
SrcOp2 = (SrcOp2 == (unsigned)-1) ? SrcOp1 : SrcOp2;
|
|
|
|
}
|
|
|
|
|
[TableGen][AsmMatcherEmitter] Allow tied operands of different classes in aliases.
Allow a tied operand of a different operand class in InstAliases,
so that the operand can be printed (and added to the MC instruction)
as the appropriate register. For example, 'GPR64as32', which would
be printed/parsed as a 32bit register and should match a tied 64bit
register operand, where the former is a sub-register of the latter.
This patch also generalizes the constraint checking to an overrideable
method in MCTargetAsmParser, so that target asmparsers can specify
whether a given operand satisfies the tied register constraint.
Reviewers: olista01, rengolin, fhahn, SjoerdMeijer, samparker, dsanders, craig.topper
Reviewed By: fhahn
Differential Revision: https://reviews.llvm.org/D47714
llvm-svn: 334942
2018-06-18 15:39:29 +02:00
|
|
|
// If the alias operand is of a different operand class, we only want
|
|
|
|
// to benefit from the tied-operands check and just match the operand
|
|
|
|
// as a normal, but not copy the original (TiedOp) to the result
|
|
|
|
// instruction. We do this by passing -1 as the tied operand to copy.
|
|
|
|
if (ResultInst->Operands[i].Rec->getName() !=
|
|
|
|
ResultInst->Operands[TiedOp].Rec->getName()) {
|
|
|
|
SrcOp1 = ResOperands[TiedOp].AsmOperandNum;
|
|
|
|
int SubIdx = CGA.ResultInstOperandIndex[AliasOpNo].second;
|
|
|
|
StringRef Name = CGA.ResultOperands[AliasOpNo].getName();
|
|
|
|
SrcOp2 = findAsmOperand(Name, SubIdx);
|
|
|
|
ResOperands.push_back(
|
|
|
|
ResOperand::getTiedOp((unsigned)-1, SrcOp1, SrcOp2));
|
|
|
|
} else {
|
|
|
|
ResOperands.push_back(ResOperand::getTiedOp(TiedOp, SrcOp1, SrcOp2));
|
|
|
|
continue;
|
|
|
|
}
|
2010-11-06 20:57:21 +01:00
|
|
|
}
|
|
|
|
|
2011-01-26 20:44:55 +01:00
|
|
|
// Handle all the suboperands for this operand.
|
|
|
|
const std::string &OpName = OpInfo->Name;
|
|
|
|
for ( ; AliasOpNo < LastOpNo &&
|
|
|
|
CGA.ResultInstOperandIndex[AliasOpNo].first == i; ++AliasOpNo) {
|
|
|
|
int SubIdx = CGA.ResultInstOperandIndex[AliasOpNo].second;
|
|
|
|
|
|
|
|
// Find out what operand from the asmparser that this MCInst operand
|
|
|
|
// comes from.
|
|
|
|
switch (CGA.ResultOperands[AliasOpNo].Kind) {
|
|
|
|
case CodeGenInstAlias::ResultOperand::K_Record: {
|
|
|
|
StringRef Name = CGA.ResultOperands[AliasOpNo].getName();
|
2012-04-19 19:52:32 +02:00
|
|
|
int SrcOperand = findAsmOperand(Name, SubIdx);
|
2011-01-26 20:44:55 +01:00
|
|
|
if (SrcOperand == -1)
|
2012-10-25 22:33:17 +02:00
|
|
|
PrintFatalError(TheDef->getLoc(), "Instruction '" +
|
2011-01-26 20:44:55 +01:00
|
|
|
TheDef->getName() + "' has operand '" + OpName +
|
|
|
|
"' that doesn't appear in asm string!");
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
|
|
|
|
// Add it to the operand references. If it is added a second time, the
|
|
|
|
// record won't be updated and it will fail later on.
|
|
|
|
OperandRefs.try_emplace(Name, SrcOperand);
|
|
|
|
|
2011-01-26 20:44:55 +01:00
|
|
|
unsigned NumOperands = (SubIdx == -1 ? OpInfo->MINumOperands : 1);
|
|
|
|
ResOperands.push_back(ResOperand::getRenderedOp(SrcOperand,
|
|
|
|
NumOperands));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CodeGenInstAlias::ResultOperand::K_Imm: {
|
|
|
|
int64_t ImmVal = CGA.ResultOperands[AliasOpNo].getImm();
|
|
|
|
ResOperands.push_back(ResOperand::getImmOp(ImmVal));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CodeGenInstAlias::ResultOperand::K_Reg: {
|
|
|
|
Record *Reg = CGA.ResultOperands[AliasOpNo].getRegister();
|
|
|
|
ResOperands.push_back(ResOperand::getRegOp(Reg));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-11-06 20:57:21 +01:00
|
|
|
}
|
2010-11-06 08:31:43 +01:00
|
|
|
}
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
|
|
|
|
// Check that operands are not repeated more times than is supported.
|
|
|
|
for (auto &T : OperandRefs) {
|
|
|
|
if (T.second != -1 && findAsmOperandNamed(T.first, T.second) != -1)
|
|
|
|
PrintFatalError(TheDef->getLoc(),
|
|
|
|
"Operand '" + T.first + "' can never be matched");
|
|
|
|
}
|
2010-11-06 08:31:43 +01:00
|
|
|
}
|
2010-11-04 01:43:46 +01:00
|
|
|
|
2016-10-21 23:45:01 +02:00
|
|
|
static unsigned
|
|
|
|
getConverterOperandID(const std::string &Name,
|
|
|
|
SmallSetVector<CachedHashString, 16> &Table,
|
|
|
|
bool &IsNew) {
|
|
|
|
IsNew = Table.insert(CachedHashString(Name));
|
2012-08-22 03:06:23 +02:00
|
|
|
|
2016-08-12 00:21:41 +02:00
|
|
|
unsigned ID = IsNew ? Table.size() - 1 : find(Table, Name) - Table.begin();
|
2012-08-22 03:06:23 +02:00
|
|
|
|
|
|
|
assert(ID < Table.size());
|
|
|
|
|
|
|
|
return ID;
|
|
|
|
}
|
|
|
|
|
2019-04-02 22:52:04 +02:00
|
|
|
static unsigned
|
|
|
|
emitConvertFuncs(CodeGenTarget &Target, StringRef ClassName,
|
|
|
|
std::vector<std::unique_ptr<MatchableInfo>> &Infos,
|
|
|
|
bool HasMnemonicFirst, bool HasOptionalOperands,
|
|
|
|
raw_ostream &OS) {
|
2016-10-21 23:45:01 +02:00
|
|
|
SmallSetVector<CachedHashString, 16> OperandConversionKinds;
|
|
|
|
SmallSetVector<CachedHashString, 16> InstructionConversionKinds;
|
2012-08-22 03:06:23 +02:00
|
|
|
std::vector<std::vector<uint8_t> > ConversionTable;
|
|
|
|
size_t MaxRowLength = 2; // minimum is custom converter plus terminator.
|
|
|
|
|
|
|
|
// TargetOperandClass - This is the target's operand class, like X86Operand.
|
2016-12-04 06:48:16 +01:00
|
|
|
std::string TargetOperandClass = Target.getName().str() + "Operand";
|
2012-08-22 03:06:23 +02:00
|
|
|
|
2009-08-08 07:24:34 +02:00
|
|
|
// Write the convert function to a separate stream, so we can drop it after
|
2012-08-22 03:06:23 +02:00
|
|
|
// the enum. We'll build up the conversion handlers for the individual
|
|
|
|
// operand types opportunistically as we encounter them.
|
2009-08-08 07:24:34 +02:00
|
|
|
std::string ConvertFnBody;
|
|
|
|
raw_string_ostream CvtOS(ConvertFnBody);
|
|
|
|
// Start the unified conversion function.
|
2016-05-06 13:31:17 +02:00
|
|
|
if (HasOptionalOperands) {
|
|
|
|
CvtOS << "void " << Target.getName() << ClassName << "::\n"
|
|
|
|
<< "convertToMCInst(unsigned Kind, MCInst &Inst, "
|
|
|
|
<< "unsigned Opcode,\n"
|
|
|
|
<< " const OperandVector &Operands,\n"
|
|
|
|
<< " const SmallBitVector &OptionalOperandsMask) {\n";
|
|
|
|
} else {
|
|
|
|
CvtOS << "void " << Target.getName() << ClassName << "::\n"
|
|
|
|
<< "convertToMCInst(unsigned Kind, MCInst &Inst, "
|
|
|
|
<< "unsigned Opcode,\n"
|
|
|
|
<< " const OperandVector &Operands) {\n";
|
|
|
|
}
|
|
|
|
CvtOS << " assert(Kind < CVT_NUM_SIGNATURES && \"Invalid signature!\");\n";
|
|
|
|
CvtOS << " const uint8_t *Converter = ConversionTable[Kind];\n";
|
|
|
|
if (HasOptionalOperands) {
|
[TableGen] AsmMatcher: fix OpIdx computation when HasOptionalOperands is true
Relanding after fixing UB issue with DefaultOffsets.
Consider the following instruction: "inst.eq $dst, $src" where ".eq"
is an optional flag operand. The $src and $dst operands are
registers. If we parse the instruction "inst r0, r1", the flag is not
present and it will be marked in the "OptionalOperandsMask" variable.
After the matching is complete we call the "convertToMCInst" method.
The current implementation works only if the optional operands are at
the end of the array. The "Operands" array looks like [token:"inst",
reg:r0, reg:r1]. The first operand that must be added to the MCInst
is the destination, the r0 register. The "OpIdx" (in the Operands
array) for this register is 2. However, since the flag is not present
in the Operands, the actual index for r0 should be 1. The flag is not
present since we rely on the default value.
This patch removes the "NumDefaults" variable and replaces it with an
array (DefaultsOffset). This array contains an index for each operand
(excluding the mnemonic). At each index, the array contains the
number of optional operands that should be subtracted. For the
previous example, this array looks like this: [0, 1, 1]. When we need
to access the r0 register, we compute its index as 2 -
DefaultsOffset[1] = 1.
Patch by Alexandru Guduleasa!
Reviewers: SamWot, nhaustov, niravd
Reviewed By: niravd
Subscribers: vitalybuka, llvm-commits
Differential Revision: https://reviews.llvm.org/D35998
llvm-svn: 310254
2017-08-07 15:55:27 +02:00
|
|
|
size_t MaxNumOperands = 0;
|
|
|
|
for (const auto &MI : Infos) {
|
|
|
|
MaxNumOperands = std::max(MaxNumOperands, MI->AsmOperands.size());
|
|
|
|
}
|
|
|
|
CvtOS << " unsigned DefaultsOffset[" << (MaxNumOperands + 1)
|
|
|
|
<< "] = { 0 };\n";
|
|
|
|
CvtOS << " assert(OptionalOperandsMask.size() == " << (MaxNumOperands)
|
|
|
|
<< ");\n";
|
|
|
|
CvtOS << " for (unsigned i = 0, NumDefaults = 0; i < " << (MaxNumOperands)
|
|
|
|
<< "; ++i) {\n";
|
|
|
|
CvtOS << " DefaultsOffset[i + 1] = NumDefaults;\n";
|
|
|
|
CvtOS << " NumDefaults += (OptionalOperandsMask[i] ? 1 : 0);\n";
|
|
|
|
CvtOS << " }\n";
|
2016-05-06 13:31:17 +02:00
|
|
|
}
|
|
|
|
CvtOS << " unsigned OpIdx;\n";
|
|
|
|
CvtOS << " Inst.setOpcode(Opcode);\n";
|
2020-11-06 15:19:59 +01:00
|
|
|
CvtOS << " for (const uint8_t *p = Converter; *p; p += 2) {\n";
|
2016-05-06 13:31:17 +02:00
|
|
|
if (HasOptionalOperands) {
|
[TableGen] AsmMatcher: fix OpIdx computation when HasOptionalOperands is true
Relanding after fixing UB issue with DefaultOffsets.
Consider the following instruction: "inst.eq $dst, $src" where ".eq"
is an optional flag operand. The $src and $dst operands are
registers. If we parse the instruction "inst r0, r1", the flag is not
present and it will be marked in the "OptionalOperandsMask" variable.
After the matching is complete we call the "convertToMCInst" method.
The current implementation works only if the optional operands are at
the end of the array. The "Operands" array looks like [token:"inst",
reg:r0, reg:r1]. The first operand that must be added to the MCInst
is the destination, the r0 register. The "OpIdx" (in the Operands
array) for this register is 2. However, since the flag is not present
in the Operands, the actual index for r0 should be 1. The flag is not
present since we rely on the default value.
This patch removes the "NumDefaults" variable and replaces it with an
array (DefaultsOffset). This array contains an index for each operand
(excluding the mnemonic). At each index, the array contains the
number of optional operands that should be subtracted. For the
previous example, this array looks like this: [0, 1, 1]. When we need
to access the r0 register, we compute its index as 2 -
DefaultsOffset[1] = 1.
Patch by Alexandru Guduleasa!
Reviewers: SamWot, nhaustov, niravd
Reviewed By: niravd
Subscribers: vitalybuka, llvm-commits
Differential Revision: https://reviews.llvm.org/D35998
llvm-svn: 310254
2017-08-07 15:55:27 +02:00
|
|
|
CvtOS << " OpIdx = *(p + 1) - DefaultsOffset[*(p + 1)];\n";
|
2016-05-06 13:31:17 +02:00
|
|
|
} else {
|
|
|
|
CvtOS << " OpIdx = *(p + 1);\n";
|
|
|
|
}
|
|
|
|
CvtOS << " switch (*p) {\n";
|
|
|
|
CvtOS << " default: llvm_unreachable(\"invalid conversion entry!\");\n";
|
|
|
|
CvtOS << " case CVT_Reg:\n";
|
|
|
|
CvtOS << " static_cast<" << TargetOperandClass
|
2020-11-06 15:19:59 +01:00
|
|
|
<< " &>(*Operands[OpIdx]).addRegOperands(Inst, 1);\n";
|
2016-05-06 13:31:17 +02:00
|
|
|
CvtOS << " break;\n";
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
CvtOS << " case CVT_Tied: {\n";
|
2018-02-17 13:29:47 +01:00
|
|
|
CvtOS << " assert(OpIdx < (size_t)(std::end(TiedAsmOperandTable) -\n";
|
2020-11-06 15:19:59 +01:00
|
|
|
CvtOS << " std::begin(TiedAsmOperandTable)) &&\n";
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
CvtOS << " \"Tied operand not found\");\n";
|
|
|
|
CvtOS << " unsigned TiedResOpnd = TiedAsmOperandTable[OpIdx][0];\n";
|
2020-11-06 15:19:59 +01:00
|
|
|
CvtOS << " if (TiedResOpnd != (uint8_t)-1)\n";
|
[TableGen][AsmMatcherEmitter] Allow tied operands of different classes in aliases.
Allow a tied operand of a different operand class in InstAliases,
so that the operand can be printed (and added to the MC instruction)
as the appropriate register. For example, 'GPR64as32', which would
be printed/parsed as a 32bit register and should match a tied 64bit
register operand, where the former is a sub-register of the latter.
This patch also generalizes the constraint checking to an overrideable
method in MCTargetAsmParser, so that target asmparsers can specify
whether a given operand satisfies the tied register constraint.
Reviewers: olista01, rengolin, fhahn, SjoerdMeijer, samparker, dsanders, craig.topper
Reviewed By: fhahn
Differential Revision: https://reviews.llvm.org/D47714
llvm-svn: 334942
2018-06-18 15:39:29 +02:00
|
|
|
CvtOS << " Inst.addOperand(Inst.getOperand(TiedResOpnd));\n";
|
2016-05-06 13:31:17 +02:00
|
|
|
CvtOS << " break;\n";
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
CvtOS << " }\n";
|
2012-08-22 03:06:23 +02:00
|
|
|
|
[ms-inline asm] Add a new function, GetMCInstOperandNum, to the
AsmMatcherEmitter. This function maps inline assembly operands to MCInst
operands.
For example, '__asm mov j, eax' is represented by the follow MCInst:
<MCInst 1460 <MCOperand Reg:0> <MCOperand Imm:1> <MCOperand Reg:0>
<MCOperand Expr:(j)> <MCOperand Reg:0> <MCOperand Reg:43>>
The first 5 MCInst operands are a result of j matching as a memory operand
consisting of a BaseReg (Reg:0), MemScale (Imm:1), MemIndexReg(Reg:0),
Expr (Expr:(j), and a MemSegReg (Reg:0). The 6th MCInst operand represents
the eax register (Reg:43).
This translation is necessary to determine the Input and Output Exprs. If a
single asm operand maps to multiple MCInst operands, the index of the first
MCInst operand is returned. Ideally, it would return the operand we really
care out (i.e., the Expr:(j) in this case), but I haven't found an easy way
of doing this yet.
llvm-svn: 162920
2012-08-30 19:59:25 +02:00
|
|
|
std::string OperandFnBody;
|
|
|
|
raw_string_ostream OpOS(OperandFnBody);
|
|
|
|
// Start the operand number lookup function.
|
2012-10-02 01:45:51 +02:00
|
|
|
OpOS << "void " << Target.getName() << ClassName << "::\n"
|
|
|
|
<< "convertToMapAndConstraints(unsigned Kind,\n";
|
2012-10-02 02:25:57 +02:00
|
|
|
OpOS.indent(27);
|
2014-06-08 18:18:35 +02:00
|
|
|
OpOS << "const OperandVector &Operands) {\n"
|
2012-08-31 02:03:31 +02:00
|
|
|
<< " assert(Kind < CVT_NUM_SIGNATURES && \"Invalid signature!\");\n"
|
2012-10-02 01:45:51 +02:00
|
|
|
<< " unsigned NumMCOperands = 0;\n"
|
2012-09-18 03:41:49 +02:00
|
|
|
<< " const uint8_t *Converter = ConversionTable[Kind];\n"
|
2020-11-06 15:19:59 +01:00
|
|
|
<< " for (const uint8_t *p = Converter; *p; p += 2) {\n"
|
[ms-inline asm] Add a new function, GetMCInstOperandNum, to the
AsmMatcherEmitter. This function maps inline assembly operands to MCInst
operands.
For example, '__asm mov j, eax' is represented by the follow MCInst:
<MCInst 1460 <MCOperand Reg:0> <MCOperand Imm:1> <MCOperand Reg:0>
<MCOperand Expr:(j)> <MCOperand Reg:0> <MCOperand Reg:43>>
The first 5 MCInst operands are a result of j matching as a memory operand
consisting of a BaseReg (Reg:0), MemScale (Imm:1), MemIndexReg(Reg:0),
Expr (Expr:(j), and a MemSegReg (Reg:0). The 6th MCInst operand represents
the eax register (Reg:43).
This translation is necessary to determine the Input and Output Exprs. If a
single asm operand maps to multiple MCInst operands, the index of the first
MCInst operand is returned. Ideally, it would return the operand we really
care out (i.e., the Expr:(j) in this case), but I haven't found an easy way
of doing this yet.
llvm-svn: 162920
2012-08-30 19:59:25 +02:00
|
|
|
<< " switch (*p) {\n"
|
|
|
|
<< " default: llvm_unreachable(\"invalid conversion entry!\");\n"
|
|
|
|
<< " case CVT_Reg:\n"
|
2012-10-13 00:53:36 +02:00
|
|
|
<< " Operands[*(p + 1)]->setMCOperandNum(NumMCOperands);\n"
|
2013-01-16 00:07:53 +01:00
|
|
|
<< " Operands[*(p + 1)]->setConstraint(\"r\");\n"
|
2012-10-13 00:53:36 +02:00
|
|
|
<< " ++NumMCOperands;\n"
|
|
|
|
<< " break;\n"
|
[ms-inline asm] Add a new function, GetMCInstOperandNum, to the
AsmMatcherEmitter. This function maps inline assembly operands to MCInst
operands.
For example, '__asm mov j, eax' is represented by the follow MCInst:
<MCInst 1460 <MCOperand Reg:0> <MCOperand Imm:1> <MCOperand Reg:0>
<MCOperand Expr:(j)> <MCOperand Reg:0> <MCOperand Reg:43>>
The first 5 MCInst operands are a result of j matching as a memory operand
consisting of a BaseReg (Reg:0), MemScale (Imm:1), MemIndexReg(Reg:0),
Expr (Expr:(j), and a MemSegReg (Reg:0). The 6th MCInst operand represents
the eax register (Reg:43).
This translation is necessary to determine the Input and Output Exprs. If a
single asm operand maps to multiple MCInst operands, the index of the first
MCInst operand is returned. Ideally, it would return the operand we really
care out (i.e., the Expr:(j) in this case), but I haven't found an easy way
of doing this yet.
llvm-svn: 162920
2012-08-30 19:59:25 +02:00
|
|
|
<< " case CVT_Tied:\n"
|
2012-10-02 01:45:51 +02:00
|
|
|
<< " ++NumMCOperands;\n"
|
[ms-inline asm] Add a new function, GetMCInstOperandNum, to the
AsmMatcherEmitter. This function maps inline assembly operands to MCInst
operands.
For example, '__asm mov j, eax' is represented by the follow MCInst:
<MCInst 1460 <MCOperand Reg:0> <MCOperand Imm:1> <MCOperand Reg:0>
<MCOperand Expr:(j)> <MCOperand Reg:0> <MCOperand Reg:43>>
The first 5 MCInst operands are a result of j matching as a memory operand
consisting of a BaseReg (Reg:0), MemScale (Imm:1), MemIndexReg(Reg:0),
Expr (Expr:(j), and a MemSegReg (Reg:0). The 6th MCInst operand represents
the eax register (Reg:43).
This translation is necessary to determine the Input and Output Exprs. If a
single asm operand maps to multiple MCInst operands, the index of the first
MCInst operand is returned. Ideally, it would return the operand we really
care out (i.e., the Expr:(j) in this case), but I haven't found an easy way
of doing this yet.
llvm-svn: 162920
2012-08-30 19:59:25 +02:00
|
|
|
<< " break;\n";
|
2012-08-22 03:06:23 +02:00
|
|
|
|
|
|
|
// Pre-populate the operand conversion kinds with the standard always
|
|
|
|
// available entries.
|
2016-10-21 23:45:01 +02:00
|
|
|
OperandConversionKinds.insert(CachedHashString("CVT_Done"));
|
|
|
|
OperandConversionKinds.insert(CachedHashString("CVT_Reg"));
|
|
|
|
OperandConversionKinds.insert(CachedHashString("CVT_Tied"));
|
2012-08-22 03:06:23 +02:00
|
|
|
enum { CVT_Done, CVT_Reg, CVT_Tied };
|
2010-10-30 00:13:48 +02:00
|
|
|
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
// Map of e.g. <0, 2, 3> -> "Tie_0_2_3" enum label.
|
[TableGen][AsmMatcherEmitter] Allow tied operands of different classes in aliases.
Allow a tied operand of a different operand class in InstAliases,
so that the operand can be printed (and added to the MC instruction)
as the appropriate register. For example, 'GPR64as32', which would
be printed/parsed as a 32bit register and should match a tied 64bit
register operand, where the former is a sub-register of the latter.
This patch also generalizes the constraint checking to an overrideable
method in MCTargetAsmParser, so that target asmparsers can specify
whether a given operand satisfies the tied register constraint.
Reviewers: olista01, rengolin, fhahn, SjoerdMeijer, samparker, dsanders, craig.topper
Reviewed By: fhahn
Differential Revision: https://reviews.llvm.org/D47714
llvm-svn: 334942
2018-06-18 15:39:29 +02:00
|
|
|
std::map<std::tuple<uint8_t, uint8_t, uint8_t>, std::string>
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
TiedOperandsEnumMap;
|
|
|
|
|
2014-11-28 04:53:02 +01:00
|
|
|
for (auto &II : Infos) {
|
2011-02-04 18:12:15 +01:00
|
|
|
// Check if we have a custom match function.
|
2017-05-31 23:12:46 +02:00
|
|
|
StringRef AsmMatchConverter =
|
|
|
|
II->getResultInst()->TheDef->getValueAsString("AsmMatchConverter");
|
2015-05-26 17:55:50 +02:00
|
|
|
if (!AsmMatchConverter.empty() && II->UseInstAsmMatchConverter) {
|
2017-05-31 23:12:46 +02:00
|
|
|
std::string Signature = ("ConvertCustom_" + AsmMatchConverter).str();
|
2014-11-29 00:00:22 +01:00
|
|
|
II->ConversionFnKind = Signature;
|
2011-02-04 18:12:15 +01:00
|
|
|
|
|
|
|
// Check if we have already generated this signature.
|
2016-10-21 23:45:01 +02:00
|
|
|
if (!InstructionConversionKinds.insert(CachedHashString(Signature)))
|
2011-02-04 18:12:15 +01:00
|
|
|
continue;
|
|
|
|
|
2012-08-22 03:06:23 +02:00
|
|
|
// Remember this converter for the kind enum.
|
|
|
|
unsigned KindID = OperandConversionKinds.size();
|
2016-10-21 23:45:01 +02:00
|
|
|
OperandConversionKinds.insert(
|
|
|
|
CachedHashString("CVT_" + getEnumNameForToken(AsmMatchConverter)));
|
2012-08-22 03:06:23 +02:00
|
|
|
|
|
|
|
// Add the converter row for this instruction.
|
2015-05-29 21:43:39 +02:00
|
|
|
ConversionTable.emplace_back();
|
2012-08-22 03:06:23 +02:00
|
|
|
ConversionTable.back().push_back(KindID);
|
|
|
|
ConversionTable.back().push_back(CVT_Done);
|
2011-02-04 18:12:15 +01:00
|
|
|
|
2012-08-22 03:06:23 +02:00
|
|
|
// Add the handler to the conversion driver function.
|
2013-01-10 17:47:31 +01:00
|
|
|
CvtOS << " case CVT_"
|
|
|
|
<< getEnumNameForToken(AsmMatchConverter) << ":\n"
|
2012-09-01 00:12:31 +02:00
|
|
|
<< " " << AsmMatchConverter << "(Inst, Operands);\n"
|
2012-08-31 02:03:31 +02:00
|
|
|
<< " break;\n";
|
2012-08-22 03:06:23 +02:00
|
|
|
|
[ms-inline asm] Add a new function, GetMCInstOperandNum, to the
AsmMatcherEmitter. This function maps inline assembly operands to MCInst
operands.
For example, '__asm mov j, eax' is represented by the follow MCInst:
<MCInst 1460 <MCOperand Reg:0> <MCOperand Imm:1> <MCOperand Reg:0>
<MCOperand Expr:(j)> <MCOperand Reg:0> <MCOperand Reg:43>>
The first 5 MCInst operands are a result of j matching as a memory operand
consisting of a BaseReg (Reg:0), MemScale (Imm:1), MemIndexReg(Reg:0),
Expr (Expr:(j), and a MemSegReg (Reg:0). The 6th MCInst operand represents
the eax register (Reg:43).
This translation is necessary to determine the Input and Output Exprs. If a
single asm operand maps to multiple MCInst operands, the index of the first
MCInst operand is returned. Ideally, it would return the operand we really
care out (i.e., the Expr:(j) in this case), but I haven't found an easy way
of doing this yet.
llvm-svn: 162920
2012-08-30 19:59:25 +02:00
|
|
|
// FIXME: Handle the operand number lookup for custom match functions.
|
2011-02-04 18:12:15 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-08-07 10:26:05 +02:00
|
|
|
// Build the conversion function signature.
|
|
|
|
std::string Signature = "Convert";
|
2012-08-22 03:06:23 +02:00
|
|
|
|
|
|
|
std::vector<uint8_t> ConversionRow;
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-11-02 22:49:44 +01:00
|
|
|
// Compute the convert enum and the case body.
|
2014-11-29 00:00:22 +01:00
|
|
|
MaxRowLength = std::max(MaxRowLength, II->ResOperands.size()*2 + 1 );
|
2012-08-22 03:06:23 +02:00
|
|
|
|
2014-11-29 00:00:22 +01:00
|
|
|
for (unsigned i = 0, e = II->ResOperands.size(); i != e; ++i) {
|
|
|
|
const MatchableInfo::ResOperand &OpInfo = II->ResOperands[i];
|
2010-11-04 01:43:46 +01:00
|
|
|
|
|
|
|
// Generate code to populate each result operand.
|
|
|
|
switch (OpInfo.Kind) {
|
|
|
|
case MatchableInfo::ResOperand::RenderAsmOperand: {
|
|
|
|
// This comes from something we parsed.
|
2014-11-25 21:11:31 +01:00
|
|
|
const MatchableInfo::AsmOperand &Op =
|
2014-11-29 00:00:22 +01:00
|
|
|
II->AsmOperands[OpInfo.AsmOperandNum];
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-11-02 23:55:03 +01:00
|
|
|
// Registers are always converted the same, don't duplicate the
|
|
|
|
// conversion function based on them.
|
|
|
|
Signature += "__";
|
2012-08-22 03:06:23 +02:00
|
|
|
std::string Class;
|
|
|
|
Class = Op.Class->isRegisterClass() ? "Reg" : Op.Class->ClassName;
|
|
|
|
Signature += Class;
|
2011-01-26 20:44:55 +01:00
|
|
|
Signature += utostr(OpInfo.MINumOperands);
|
2010-11-04 01:43:46 +01:00
|
|
|
Signature += "_" + itostr(OpInfo.AsmOperandNum);
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2012-08-22 03:06:23 +02:00
|
|
|
// Add the conversion kind, if necessary, and get the associated ID
|
|
|
|
// the index of its entry in the vector).
|
|
|
|
std::string Name = "CVT_" + (Op.Class->isRegisterClass() ? "Reg" :
|
|
|
|
Op.Class->RenderMethod);
|
2016-05-06 13:31:17 +02:00
|
|
|
if (Op.Class->IsOptional) {
|
|
|
|
// For optional operands we must also care about DefaultMethod
|
|
|
|
assert(HasOptionalOperands);
|
|
|
|
Name += "_" + Op.Class->DefaultMethod;
|
|
|
|
}
|
2013-01-10 17:47:31 +01:00
|
|
|
Name = getEnumNameForToken(Name);
|
2012-08-22 03:06:23 +02:00
|
|
|
|
|
|
|
bool IsNewConverter = false;
|
|
|
|
unsigned ID = getConverterOperandID(Name, OperandConversionKinds,
|
|
|
|
IsNewConverter);
|
|
|
|
|
|
|
|
// Add the operand entry to the instruction kind conversion row.
|
|
|
|
ConversionRow.push_back(ID);
|
2015-12-31 09:18:23 +01:00
|
|
|
ConversionRow.push_back(OpInfo.AsmOperandNum + HasMnemonicFirst);
|
2012-08-22 03:06:23 +02:00
|
|
|
|
|
|
|
if (!IsNewConverter)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// This is a new operand kind. Add a handler for it to the
|
|
|
|
// converter driver.
|
2016-05-06 13:31:17 +02:00
|
|
|
CvtOS << " case " << Name << ":\n";
|
|
|
|
if (Op.Class->IsOptional) {
|
|
|
|
// If optional operand is not present in actual instruction then we
|
|
|
|
// should call its DefaultMethod before RenderMethod
|
|
|
|
assert(HasOptionalOperands);
|
|
|
|
CvtOS << " if (OptionalOperandsMask[*(p + 1) - 1]) {\n"
|
|
|
|
<< " " << Op.Class->DefaultMethod << "()"
|
|
|
|
<< "->" << Op.Class->RenderMethod << "(Inst, "
|
|
|
|
<< OpInfo.MINumOperands << ");\n"
|
|
|
|
<< " } else {\n"
|
|
|
|
<< " static_cast<" << TargetOperandClass
|
2020-11-06 15:19:59 +01:00
|
|
|
<< " &>(*Operands[OpIdx])." << Op.Class->RenderMethod
|
2016-05-06 13:31:17 +02:00
|
|
|
<< "(Inst, " << OpInfo.MINumOperands << ");\n"
|
|
|
|
<< " }\n";
|
|
|
|
} else {
|
|
|
|
CvtOS << " static_cast<" << TargetOperandClass
|
2020-11-06 15:19:59 +01:00
|
|
|
<< " &>(*Operands[OpIdx])." << Op.Class->RenderMethod
|
2016-05-06 13:31:17 +02:00
|
|
|
<< "(Inst, " << OpInfo.MINumOperands << ");\n";
|
|
|
|
}
|
|
|
|
CvtOS << " break;\n";
|
[ms-inline asm] Add a new function, GetMCInstOperandNum, to the
AsmMatcherEmitter. This function maps inline assembly operands to MCInst
operands.
For example, '__asm mov j, eax' is represented by the follow MCInst:
<MCInst 1460 <MCOperand Reg:0> <MCOperand Imm:1> <MCOperand Reg:0>
<MCOperand Expr:(j)> <MCOperand Reg:0> <MCOperand Reg:43>>
The first 5 MCInst operands are a result of j matching as a memory operand
consisting of a BaseReg (Reg:0), MemScale (Imm:1), MemIndexReg(Reg:0),
Expr (Expr:(j), and a MemSegReg (Reg:0). The 6th MCInst operand represents
the eax register (Reg:43).
This translation is necessary to determine the Input and Output Exprs. If a
single asm operand maps to multiple MCInst operands, the index of the first
MCInst operand is returned. Ideally, it would return the operand we really
care out (i.e., the Expr:(j) in this case), but I haven't found an easy way
of doing this yet.
llvm-svn: 162920
2012-08-30 19:59:25 +02:00
|
|
|
|
|
|
|
// Add a handler for the operand number lookup.
|
|
|
|
OpOS << " case " << Name << ":\n"
|
2013-01-16 00:07:53 +01:00
|
|
|
<< " Operands[*(p + 1)]->setMCOperandNum(NumMCOperands);\n";
|
|
|
|
|
|
|
|
if (Op.Class->isRegisterClass())
|
|
|
|
OpOS << " Operands[*(p + 1)]->setConstraint(\"r\");\n";
|
|
|
|
else
|
|
|
|
OpOS << " Operands[*(p + 1)]->setConstraint(\"m\");\n";
|
|
|
|
OpOS << " NumMCOperands += " << OpInfo.MINumOperands << ";\n"
|
[ms-inline asm] Add a new function, GetMCInstOperandNum, to the
AsmMatcherEmitter. This function maps inline assembly operands to MCInst
operands.
For example, '__asm mov j, eax' is represented by the follow MCInst:
<MCInst 1460 <MCOperand Reg:0> <MCOperand Imm:1> <MCOperand Reg:0>
<MCOperand Expr:(j)> <MCOperand Reg:0> <MCOperand Reg:43>>
The first 5 MCInst operands are a result of j matching as a memory operand
consisting of a BaseReg (Reg:0), MemScale (Imm:1), MemIndexReg(Reg:0),
Expr (Expr:(j), and a MemSegReg (Reg:0). The 6th MCInst operand represents
the eax register (Reg:43).
This translation is necessary to determine the Input and Output Exprs. If a
single asm operand maps to multiple MCInst operands, the index of the first
MCInst operand is returned. Ideally, it would return the operand we really
care out (i.e., the Expr:(j) in this case), but I haven't found an easy way
of doing this yet.
llvm-svn: 162920
2012-08-30 19:59:25 +02:00
|
|
|
<< " break;\n";
|
2010-11-04 01:43:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MatchableInfo::ResOperand::TiedOperand: {
|
|
|
|
// If this operand is tied to a previous one, just copy the MCInst
|
|
|
|
// operand from the earlier one.We can only tie single MCOperand values.
|
Handle tied sub-operands in AsmMatcherEmitter
The problem this patch addresses is the handling of register tie
constraints in AsmMatcherEmitter, where one operand is tied to a
sub-operand of another operand. The typical scenario for this to
happen is the tie between the "write-back" register of a pre-inc
instruction, and the base register sub-operand of the memory address
operand of that instruction.
The current AsmMatcherEmitter code attempts to handle tied
operands by emitting the operand as usual first, and emitting
a CVT_Tied node when handling the second (tied) operand. However,
this really only works correctly if the tied operand does not
have sub-operands (and isn't a sub-operand itself). Under those
circumstances, a wrong MC operand list is generated.
In discussions with Jim Grosbach, it turned out that the MC operand
list really ought not to contain tied operands in the first place;
instead, it ought to consist of exactly those operands that are
named in the AsmString. However, getting there requires significant
rework of (some) targets.
This patch fixes the immediate problem, and at the same time makes
one (small) step in the direction of the long-term solution, by
implementing two changes:
1. Restricts the AsmMatcherEmitter handling of tied operands to
apply solely to simple operands (not complex operands or
sub-operand of such).
This means that at least we don't get silently corrupt MC operand
lists as output. However, if we do have tied sub-operands, they
would now no longer be handled at all, except for:
2. If we have an operand that does not occur in the AsmString,
and also isn't handled as tied operand, simply emit a dummy
MC operand (constant 0).
This works as long as target code never attempts to access
MC operands that do no not occur in the AsmString (and are
not tied simple operands), which happens to be the case for
all targets where this situation can occur (ARM and PowerPC).
[ Note that this change means that many of the ARM custom
converters are now superfluous, since the implement the
same "hack" now performed already by common code. ]
Longer term, we ought to fix targets to never access *any*
MC operand that does not occur in the AsmString (including
tied simple operands), and then finally completely remove
all such operands from the MC operand list.
Patch approved by Jim Grosbach.
llvm-svn: 180677
2013-04-27 20:48:23 +02:00
|
|
|
assert(OpInfo.MINumOperands == 1 && "Not a singular MCOperand");
|
[TableGen][AsmMatcherEmitter] Allow tied operands of different classes in aliases.
Allow a tied operand of a different operand class in InstAliases,
so that the operand can be printed (and added to the MC instruction)
as the appropriate register. For example, 'GPR64as32', which would
be printed/parsed as a 32bit register and should match a tied 64bit
register operand, where the former is a sub-register of the latter.
This patch also generalizes the constraint checking to an overrideable
method in MCTargetAsmParser, so that target asmparsers can specify
whether a given operand satisfies the tied register constraint.
Reviewers: olista01, rengolin, fhahn, SjoerdMeijer, samparker, dsanders, craig.topper
Reviewed By: fhahn
Differential Revision: https://reviews.llvm.org/D47714
llvm-svn: 334942
2018-06-18 15:39:29 +02:00
|
|
|
uint8_t TiedOp = OpInfo.TiedOperands.ResOpnd;
|
|
|
|
uint8_t SrcOp1 =
|
|
|
|
OpInfo.TiedOperands.SrcOpnd1Idx + HasMnemonicFirst;
|
|
|
|
uint8_t SrcOp2 =
|
|
|
|
OpInfo.TiedOperands.SrcOpnd2Idx + HasMnemonicFirst;
|
|
|
|
assert((i > TiedOp || TiedOp == (uint8_t)-1) &&
|
|
|
|
"Tied operand precedes its target!");
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
auto TiedTupleName = std::string("Tie") + utostr(TiedOp) + '_' +
|
|
|
|
utostr(SrcOp1) + '_' + utostr(SrcOp2);
|
|
|
|
Signature += "__" + TiedTupleName;
|
2012-08-22 03:06:23 +02:00
|
|
|
ConversionRow.push_back(CVT_Tied);
|
|
|
|
ConversionRow.push_back(TiedOp);
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
ConversionRow.push_back(SrcOp1);
|
|
|
|
ConversionRow.push_back(SrcOp2);
|
|
|
|
|
|
|
|
// Also create an 'enum' for this combination of tied operands.
|
|
|
|
auto Key = std::make_tuple(TiedOp, SrcOp1, SrcOp2);
|
|
|
|
TiedOperandsEnumMap.emplace(Key, TiedTupleName);
|
2010-11-04 01:43:46 +01:00
|
|
|
break;
|
|
|
|
}
|
2010-11-06 20:25:43 +01:00
|
|
|
case MatchableInfo::ResOperand::ImmOperand: {
|
|
|
|
int64_t Val = OpInfo.ImmVal;
|
2012-08-22 03:06:23 +02:00
|
|
|
std::string Ty = "imm_" + itostr(Val);
|
2015-01-15 02:33:00 +01:00
|
|
|
Ty = getEnumNameForToken(Ty);
|
2012-08-22 03:06:23 +02:00
|
|
|
Signature += "__" + Ty;
|
|
|
|
|
|
|
|
std::string Name = "CVT_" + Ty;
|
|
|
|
bool IsNewConverter = false;
|
|
|
|
unsigned ID = getConverterOperandID(Name, OperandConversionKinds,
|
|
|
|
IsNewConverter);
|
|
|
|
// Add the operand entry to the instruction kind conversion row.
|
|
|
|
ConversionRow.push_back(ID);
|
|
|
|
ConversionRow.push_back(0);
|
|
|
|
|
|
|
|
if (!IsNewConverter)
|
|
|
|
break;
|
|
|
|
|
|
|
|
CvtOS << " case " << Name << ":\n"
|
2015-05-13 20:37:00 +02:00
|
|
|
<< " Inst.addOperand(MCOperand::createImm(" << Val << "));\n"
|
2012-08-22 03:06:23 +02:00
|
|
|
<< " break;\n";
|
|
|
|
|
[ms-inline asm] Add a new function, GetMCInstOperandNum, to the
AsmMatcherEmitter. This function maps inline assembly operands to MCInst
operands.
For example, '__asm mov j, eax' is represented by the follow MCInst:
<MCInst 1460 <MCOperand Reg:0> <MCOperand Imm:1> <MCOperand Reg:0>
<MCOperand Expr:(j)> <MCOperand Reg:0> <MCOperand Reg:43>>
The first 5 MCInst operands are a result of j matching as a memory operand
consisting of a BaseReg (Reg:0), MemScale (Imm:1), MemIndexReg(Reg:0),
Expr (Expr:(j), and a MemSegReg (Reg:0). The 6th MCInst operand represents
the eax register (Reg:43).
This translation is necessary to determine the Input and Output Exprs. If a
single asm operand maps to multiple MCInst operands, the index of the first
MCInst operand is returned. Ideally, it would return the operand we really
care out (i.e., the Expr:(j) in this case), but I haven't found an easy way
of doing this yet.
llvm-svn: 162920
2012-08-30 19:59:25 +02:00
|
|
|
OpOS << " case " << Name << ":\n"
|
2012-10-13 00:53:36 +02:00
|
|
|
<< " Operands[*(p + 1)]->setMCOperandNum(NumMCOperands);\n"
|
|
|
|
<< " Operands[*(p + 1)]->setConstraint(\"\");\n"
|
2012-10-02 01:45:51 +02:00
|
|
|
<< " ++NumMCOperands;\n"
|
[ms-inline asm] Add a new function, GetMCInstOperandNum, to the
AsmMatcherEmitter. This function maps inline assembly operands to MCInst
operands.
For example, '__asm mov j, eax' is represented by the follow MCInst:
<MCInst 1460 <MCOperand Reg:0> <MCOperand Imm:1> <MCOperand Reg:0>
<MCOperand Expr:(j)> <MCOperand Reg:0> <MCOperand Reg:43>>
The first 5 MCInst operands are a result of j matching as a memory operand
consisting of a BaseReg (Reg:0), MemScale (Imm:1), MemIndexReg(Reg:0),
Expr (Expr:(j), and a MemSegReg (Reg:0). The 6th MCInst operand represents
the eax register (Reg:43).
This translation is necessary to determine the Input and Output Exprs. If a
single asm operand maps to multiple MCInst operands, the index of the first
MCInst operand is returned. Ideally, it would return the operand we really
care out (i.e., the Expr:(j) in this case), but I haven't found an easy way
of doing this yet.
llvm-svn: 162920
2012-08-30 19:59:25 +02:00
|
|
|
<< " break;\n";
|
2010-11-06 20:25:43 +01:00
|
|
|
break;
|
|
|
|
}
|
2010-11-06 20:57:21 +01:00
|
|
|
case MatchableInfo::ResOperand::RegOperand: {
|
2012-08-22 03:06:23 +02:00
|
|
|
std::string Reg, Name;
|
2014-04-15 09:20:03 +02:00
|
|
|
if (!OpInfo.Register) {
|
2012-08-22 03:06:23 +02:00
|
|
|
Name = "reg0";
|
|
|
|
Reg = "0";
|
2011-01-14 23:58:09 +01:00
|
|
|
} else {
|
2012-08-22 03:06:23 +02:00
|
|
|
Reg = getQualifiedName(OpInfo.Register);
|
2016-12-04 06:48:16 +01:00
|
|
|
Name = "reg" + OpInfo.Register->getName().str();
|
2011-01-14 23:58:09 +01:00
|
|
|
}
|
2012-08-22 03:06:23 +02:00
|
|
|
Signature += "__" + Name;
|
|
|
|
Name = "CVT_" + Name;
|
|
|
|
bool IsNewConverter = false;
|
|
|
|
unsigned ID = getConverterOperandID(Name, OperandConversionKinds,
|
|
|
|
IsNewConverter);
|
|
|
|
// Add the operand entry to the instruction kind conversion row.
|
|
|
|
ConversionRow.push_back(ID);
|
|
|
|
ConversionRow.push_back(0);
|
|
|
|
|
|
|
|
if (!IsNewConverter)
|
|
|
|
break;
|
|
|
|
CvtOS << " case " << Name << ":\n"
|
2015-05-13 20:37:00 +02:00
|
|
|
<< " Inst.addOperand(MCOperand::createReg(" << Reg << "));\n"
|
2012-08-22 03:06:23 +02:00
|
|
|
<< " break;\n";
|
[ms-inline asm] Add a new function, GetMCInstOperandNum, to the
AsmMatcherEmitter. This function maps inline assembly operands to MCInst
operands.
For example, '__asm mov j, eax' is represented by the follow MCInst:
<MCInst 1460 <MCOperand Reg:0> <MCOperand Imm:1> <MCOperand Reg:0>
<MCOperand Expr:(j)> <MCOperand Reg:0> <MCOperand Reg:43>>
The first 5 MCInst operands are a result of j matching as a memory operand
consisting of a BaseReg (Reg:0), MemScale (Imm:1), MemIndexReg(Reg:0),
Expr (Expr:(j), and a MemSegReg (Reg:0). The 6th MCInst operand represents
the eax register (Reg:43).
This translation is necessary to determine the Input and Output Exprs. If a
single asm operand maps to multiple MCInst operands, the index of the first
MCInst operand is returned. Ideally, it would return the operand we really
care out (i.e., the Expr:(j) in this case), but I haven't found an easy way
of doing this yet.
llvm-svn: 162920
2012-08-30 19:59:25 +02:00
|
|
|
|
|
|
|
OpOS << " case " << Name << ":\n"
|
2012-10-13 00:53:36 +02:00
|
|
|
<< " Operands[*(p + 1)]->setMCOperandNum(NumMCOperands);\n"
|
|
|
|
<< " Operands[*(p + 1)]->setConstraint(\"m\");\n"
|
2012-10-02 01:45:51 +02:00
|
|
|
<< " ++NumMCOperands;\n"
|
[ms-inline asm] Add a new function, GetMCInstOperandNum, to the
AsmMatcherEmitter. This function maps inline assembly operands to MCInst
operands.
For example, '__asm mov j, eax' is represented by the follow MCInst:
<MCInst 1460 <MCOperand Reg:0> <MCOperand Imm:1> <MCOperand Reg:0>
<MCOperand Expr:(j)> <MCOperand Reg:0> <MCOperand Reg:43>>
The first 5 MCInst operands are a result of j matching as a memory operand
consisting of a BaseReg (Reg:0), MemScale (Imm:1), MemIndexReg(Reg:0),
Expr (Expr:(j), and a MemSegReg (Reg:0). The 6th MCInst operand represents
the eax register (Reg:43).
This translation is necessary to determine the Input and Output Exprs. If a
single asm operand maps to multiple MCInst operands, the index of the first
MCInst operand is returned. Ideally, it would return the operand we really
care out (i.e., the Expr:(j) in this case), but I haven't found an easy way
of doing this yet.
llvm-svn: 162920
2012-08-30 19:59:25 +02:00
|
|
|
<< " break;\n";
|
2011-01-26 22:26:19 +01:00
|
|
|
}
|
2010-02-10 09:15:48 +01:00
|
|
|
}
|
2010-11-02 23:55:03 +01:00
|
|
|
}
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2012-08-22 03:06:23 +02:00
|
|
|
// If there were no operands, add to the signature to that effect
|
|
|
|
if (Signature == "Convert")
|
|
|
|
Signature += "_NoOperands";
|
|
|
|
|
2014-11-29 00:00:22 +01:00
|
|
|
II->ConversionFnKind = Signature;
|
2009-07-31 04:32:59 +02:00
|
|
|
|
2012-08-22 03:06:23 +02:00
|
|
|
// Save the signature. If we already have it, don't add a new row
|
|
|
|
// to the table.
|
2016-10-21 23:45:01 +02:00
|
|
|
if (!InstructionConversionKinds.insert(CachedHashString(Signature)))
|
2009-08-07 10:26:05 +02:00
|
|
|
continue;
|
2009-07-31 04:32:59 +02:00
|
|
|
|
2012-08-22 03:06:23 +02:00
|
|
|
// Add the row to the table.
|
2015-08-16 23:27:08 +02:00
|
|
|
ConversionTable.push_back(std::move(ConversionRow));
|
2009-07-31 04:32:59 +02:00
|
|
|
}
|
2009-08-08 07:24:34 +02:00
|
|
|
|
2012-08-22 03:06:23 +02:00
|
|
|
// Finish up the converter driver function.
|
2012-09-03 19:39:57 +02:00
|
|
|
CvtOS << " }\n }\n}\n\n";
|
2009-08-08 07:24:34 +02:00
|
|
|
|
[ms-inline asm] Add a new function, GetMCInstOperandNum, to the
AsmMatcherEmitter. This function maps inline assembly operands to MCInst
operands.
For example, '__asm mov j, eax' is represented by the follow MCInst:
<MCInst 1460 <MCOperand Reg:0> <MCOperand Imm:1> <MCOperand Reg:0>
<MCOperand Expr:(j)> <MCOperand Reg:0> <MCOperand Reg:43>>
The first 5 MCInst operands are a result of j matching as a memory operand
consisting of a BaseReg (Reg:0), MemScale (Imm:1), MemIndexReg(Reg:0),
Expr (Expr:(j), and a MemSegReg (Reg:0). The 6th MCInst operand represents
the eax register (Reg:43).
This translation is necessary to determine the Input and Output Exprs. If a
single asm operand maps to multiple MCInst operands, the index of the first
MCInst operand is returned. Ideally, it would return the operand we really
care out (i.e., the Expr:(j) in this case), but I haven't found an easy way
of doing this yet.
llvm-svn: 162920
2012-08-30 19:59:25 +02:00
|
|
|
// Finish up the operand number lookup function.
|
2012-10-02 01:45:51 +02:00
|
|
|
OpOS << " }\n }\n}\n\n";
|
[ms-inline asm] Add a new function, GetMCInstOperandNum, to the
AsmMatcherEmitter. This function maps inline assembly operands to MCInst
operands.
For example, '__asm mov j, eax' is represented by the follow MCInst:
<MCInst 1460 <MCOperand Reg:0> <MCOperand Imm:1> <MCOperand Reg:0>
<MCOperand Expr:(j)> <MCOperand Reg:0> <MCOperand Reg:43>>
The first 5 MCInst operands are a result of j matching as a memory operand
consisting of a BaseReg (Reg:0), MemScale (Imm:1), MemIndexReg(Reg:0),
Expr (Expr:(j), and a MemSegReg (Reg:0). The 6th MCInst operand represents
the eax register (Reg:43).
This translation is necessary to determine the Input and Output Exprs. If a
single asm operand maps to multiple MCInst operands, the index of the first
MCInst operand is returned. Ideally, it would return the operand we really
care out (i.e., the Expr:(j) in this case), but I haven't found an easy way
of doing this yet.
llvm-svn: 162920
2012-08-30 19:59:25 +02:00
|
|
|
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
// Output a static table for tied operands.
|
|
|
|
if (TiedOperandsEnumMap.size()) {
|
|
|
|
// The number of tied operand combinations will be small in practice,
|
|
|
|
// but just add the assert to be sure.
|
[TableGen][AsmMatcherEmitter] Allow tied operands of different classes in aliases.
Allow a tied operand of a different operand class in InstAliases,
so that the operand can be printed (and added to the MC instruction)
as the appropriate register. For example, 'GPR64as32', which would
be printed/parsed as a 32bit register and should match a tied 64bit
register operand, where the former is a sub-register of the latter.
This patch also generalizes the constraint checking to an overrideable
method in MCTargetAsmParser, so that target asmparsers can specify
whether a given operand satisfies the tied register constraint.
Reviewers: olista01, rengolin, fhahn, SjoerdMeijer, samparker, dsanders, craig.topper
Reviewed By: fhahn
Differential Revision: https://reviews.llvm.org/D47714
llvm-svn: 334942
2018-06-18 15:39:29 +02:00
|
|
|
assert(TiedOperandsEnumMap.size() <= 254 &&
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
"Too many tied-operand combinations to reference with "
|
[TableGen][AsmMatcherEmitter] Allow tied operands of different classes in aliases.
Allow a tied operand of a different operand class in InstAliases,
so that the operand can be printed (and added to the MC instruction)
as the appropriate register. For example, 'GPR64as32', which would
be printed/parsed as a 32bit register and should match a tied 64bit
register operand, where the former is a sub-register of the latter.
This patch also generalizes the constraint checking to an overrideable
method in MCTargetAsmParser, so that target asmparsers can specify
whether a given operand satisfies the tied register constraint.
Reviewers: olista01, rengolin, fhahn, SjoerdMeijer, samparker, dsanders, craig.topper
Reviewed By: fhahn
Differential Revision: https://reviews.llvm.org/D47714
llvm-svn: 334942
2018-06-18 15:39:29 +02:00
|
|
|
"an 8bit offset from the conversion table, where index "
|
|
|
|
"'255' is reserved as operand not to be copied.");
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
|
|
|
|
OS << "enum {\n";
|
|
|
|
for (auto &KV : TiedOperandsEnumMap) {
|
|
|
|
OS << " " << KV.second << ",\n";
|
|
|
|
}
|
|
|
|
OS << "};\n\n";
|
|
|
|
|
2018-06-18 18:17:46 +02:00
|
|
|
OS << "static const uint8_t TiedAsmOperandTable[][3] = {\n";
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
for (auto &KV : TiedOperandsEnumMap) {
|
[TableGen][AsmMatcherEmitter] Allow tied operands of different classes in aliases.
Allow a tied operand of a different operand class in InstAliases,
so that the operand can be printed (and added to the MC instruction)
as the appropriate register. For example, 'GPR64as32', which would
be printed/parsed as a 32bit register and should match a tied 64bit
register operand, where the former is a sub-register of the latter.
This patch also generalizes the constraint checking to an overrideable
method in MCTargetAsmParser, so that target asmparsers can specify
whether a given operand satisfies the tied register constraint.
Reviewers: olista01, rengolin, fhahn, SjoerdMeijer, samparker, dsanders, craig.topper
Reviewed By: fhahn
Differential Revision: https://reviews.llvm.org/D47714
llvm-svn: 334942
2018-06-18 15:39:29 +02:00
|
|
|
OS << " /* " << KV.second << " */ { "
|
|
|
|
<< utostr(std::get<0>(KV.first)) << ", "
|
|
|
|
<< utostr(std::get<1>(KV.first)) << ", "
|
|
|
|
<< utostr(std::get<2>(KV.first)) << " },\n";
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
}
|
|
|
|
OS << "};\n\n";
|
|
|
|
} else
|
2018-06-18 18:17:46 +02:00
|
|
|
OS << "static const uint8_t TiedAsmOperandTable[][3] = "
|
[TableGen][AsmMatcherEmitter] Allow tied operands of different classes in aliases.
Allow a tied operand of a different operand class in InstAliases,
so that the operand can be printed (and added to the MC instruction)
as the appropriate register. For example, 'GPR64as32', which would
be printed/parsed as a 32bit register and should match a tied 64bit
register operand, where the former is a sub-register of the latter.
This patch also generalizes the constraint checking to an overrideable
method in MCTargetAsmParser, so that target asmparsers can specify
whether a given operand satisfies the tied register constraint.
Reviewers: olista01, rengolin, fhahn, SjoerdMeijer, samparker, dsanders, craig.topper
Reviewed By: fhahn
Differential Revision: https://reviews.llvm.org/D47714
llvm-svn: 334942
2018-06-18 15:39:29 +02:00
|
|
|
"{ /* empty */ {0, 0, 0} };\n\n";
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
|
2012-08-22 03:06:23 +02:00
|
|
|
OS << "namespace {\n";
|
2009-08-08 07:24:34 +02:00
|
|
|
|
2012-08-22 03:06:23 +02:00
|
|
|
// Output the operand conversion kind enum.
|
|
|
|
OS << "enum OperatorConversionKind {\n";
|
2016-10-21 23:45:01 +02:00
|
|
|
for (const auto &Converter : OperandConversionKinds)
|
2016-01-03 08:33:30 +01:00
|
|
|
OS << " " << Converter << ",\n";
|
2012-08-22 03:06:23 +02:00
|
|
|
OS << " CVT_NUM_CONVERTERS\n";
|
|
|
|
OS << "};\n\n";
|
2009-08-08 07:24:34 +02:00
|
|
|
|
2012-08-22 03:06:23 +02:00
|
|
|
// Output the instruction conversion kind enum.
|
|
|
|
OS << "enum InstructionConversionKind {\n";
|
2016-10-21 23:45:01 +02:00
|
|
|
for (const auto &Signature : InstructionConversionKinds)
|
2015-08-16 23:27:10 +02:00
|
|
|
OS << " " << Signature << ",\n";
|
2012-08-22 03:06:23 +02:00
|
|
|
OS << " CVT_NUM_SIGNATURES\n";
|
2009-08-08 07:24:34 +02:00
|
|
|
OS << "};\n\n";
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2012-08-22 03:06:23 +02:00
|
|
|
OS << "} // end anonymous namespace\n\n";
|
|
|
|
|
|
|
|
// Output the conversion table.
|
2012-09-18 03:41:49 +02:00
|
|
|
OS << "static const uint8_t ConversionTable[CVT_NUM_SIGNATURES]["
|
2012-08-22 03:06:23 +02:00
|
|
|
<< MaxRowLength << "] = {\n";
|
|
|
|
|
|
|
|
for (unsigned Row = 0, ERow = ConversionTable.size(); Row != ERow; ++Row) {
|
|
|
|
assert(ConversionTable[Row].size() % 2 == 0 && "bad conversion row!");
|
|
|
|
OS << " // " << InstructionConversionKinds[Row] << "\n";
|
|
|
|
OS << " { ";
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
for (unsigned i = 0, e = ConversionTable[Row].size(); i != e; i += 2) {
|
|
|
|
OS << OperandConversionKinds[ConversionTable[Row][i]] << ", ";
|
|
|
|
if (OperandConversionKinds[ConversionTable[Row][i]] !=
|
|
|
|
CachedHashString("CVT_Tied")) {
|
|
|
|
OS << (unsigned)(ConversionTable[Row][i + 1]) << ", ";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For a tied operand, emit a reference to the TiedAsmOperandTable
|
|
|
|
// that contains the operand to copy, and the parsed operands to
|
|
|
|
// check for their tied constraints.
|
[TableGen][AsmMatcherEmitter] Allow tied operands of different classes in aliases.
Allow a tied operand of a different operand class in InstAliases,
so that the operand can be printed (and added to the MC instruction)
as the appropriate register. For example, 'GPR64as32', which would
be printed/parsed as a 32bit register and should match a tied 64bit
register operand, where the former is a sub-register of the latter.
This patch also generalizes the constraint checking to an overrideable
method in MCTargetAsmParser, so that target asmparsers can specify
whether a given operand satisfies the tied register constraint.
Reviewers: olista01, rengolin, fhahn, SjoerdMeijer, samparker, dsanders, craig.topper
Reviewed By: fhahn
Differential Revision: https://reviews.llvm.org/D47714
llvm-svn: 334942
2018-06-18 15:39:29 +02:00
|
|
|
auto Key = std::make_tuple((uint8_t)ConversionTable[Row][i + 1],
|
|
|
|
(uint8_t)ConversionTable[Row][i + 2],
|
|
|
|
(uint8_t)ConversionTable[Row][i + 3]);
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
auto TiedOpndEnum = TiedOperandsEnumMap.find(Key);
|
|
|
|
assert(TiedOpndEnum != TiedOperandsEnumMap.end() &&
|
|
|
|
"No record for tied operand pair");
|
|
|
|
OS << TiedOpndEnum->second << ", ";
|
|
|
|
i += 2;
|
|
|
|
}
|
2012-08-22 03:06:23 +02:00
|
|
|
OS << "CVT_Done },\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << "};\n\n";
|
|
|
|
|
|
|
|
// Spit out the conversion driver function.
|
2009-08-08 07:24:34 +02:00
|
|
|
OS << CvtOS.str();
|
2012-08-22 03:06:23 +02:00
|
|
|
|
[ms-inline asm] Add a new function, GetMCInstOperandNum, to the
AsmMatcherEmitter. This function maps inline assembly operands to MCInst
operands.
For example, '__asm mov j, eax' is represented by the follow MCInst:
<MCInst 1460 <MCOperand Reg:0> <MCOperand Imm:1> <MCOperand Reg:0>
<MCOperand Expr:(j)> <MCOperand Reg:0> <MCOperand Reg:43>>
The first 5 MCInst operands are a result of j matching as a memory operand
consisting of a BaseReg (Reg:0), MemScale (Imm:1), MemIndexReg(Reg:0),
Expr (Expr:(j), and a MemSegReg (Reg:0). The 6th MCInst operand represents
the eax register (Reg:43).
This translation is necessary to determine the Input and Output Exprs. If a
single asm operand maps to multiple MCInst operands, the index of the first
MCInst operand is returned. Ideally, it would return the operand we really
care out (i.e., the Expr:(j) in this case), but I haven't found an easy way
of doing this yet.
llvm-svn: 162920
2012-08-30 19:59:25 +02:00
|
|
|
// Spit out the operand number lookup function.
|
|
|
|
OS << OpOS.str();
|
2019-04-02 22:52:04 +02:00
|
|
|
|
|
|
|
return ConversionTable.size();
|
2009-08-07 10:26:05 +02:00
|
|
|
}
|
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
/// emitMatchClassEnumeration - Emit the enumeration for match class kinds.
|
|
|
|
static void emitMatchClassEnumeration(CodeGenTarget &Target,
|
2014-11-28 21:35:57 +01:00
|
|
|
std::forward_list<ClassInfo> &Infos,
|
|
|
|
raw_ostream &OS) {
|
2009-08-08 09:50:56 +02:00
|
|
|
OS << "namespace {\n\n";
|
|
|
|
|
|
|
|
OS << "/// MatchClassKind - The kinds of classes which participate in\n"
|
|
|
|
<< "/// instruction matching.\n";
|
|
|
|
OS << "enum MatchClassKind {\n";
|
|
|
|
OS << " InvalidMatchClass = 0,\n";
|
2016-02-05 20:59:33 +01:00
|
|
|
OS << " OptionalMatchClass = 1,\n";
|
2017-10-10 13:00:40 +02:00
|
|
|
ClassInfo::ClassInfoKind LastKind = ClassInfo::Token;
|
|
|
|
StringRef LastName = "OptionalMatchClass";
|
2014-11-28 04:53:02 +01:00
|
|
|
for (const auto &CI : Infos) {
|
2017-10-10 13:00:40 +02:00
|
|
|
if (LastKind == ClassInfo::Token && CI.Kind != ClassInfo::Token) {
|
|
|
|
OS << " MCK_LAST_TOKEN = " << LastName << ",\n";
|
|
|
|
} else if (LastKind < ClassInfo::UserClass0 &&
|
|
|
|
CI.Kind >= ClassInfo::UserClass0) {
|
|
|
|
OS << " MCK_LAST_REGISTER = " << LastName << ",\n";
|
|
|
|
}
|
|
|
|
LastKind = (ClassInfo::ClassInfoKind)CI.Kind;
|
|
|
|
LastName = CI.Name;
|
|
|
|
|
2014-11-28 21:35:57 +01:00
|
|
|
OS << " " << CI.Name << ", // ";
|
|
|
|
if (CI.Kind == ClassInfo::Token) {
|
|
|
|
OS << "'" << CI.ValueName << "'\n";
|
|
|
|
} else if (CI.isRegisterClass()) {
|
|
|
|
if (!CI.ValueName.empty())
|
|
|
|
OS << "register class '" << CI.ValueName << "'\n";
|
2009-08-08 09:50:56 +02:00
|
|
|
else
|
|
|
|
OS << "derived register class\n";
|
|
|
|
} else {
|
2014-11-28 21:35:57 +01:00
|
|
|
OS << "user defined class '" << CI.ValueName << "'\n";
|
2009-08-08 09:50:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
OS << " NumMatchClassKinds\n";
|
|
|
|
OS << "};\n\n";
|
|
|
|
|
2019-08-25 12:47:30 +02:00
|
|
|
OS << "} // end anonymous namespace\n\n";
|
2009-08-08 09:50:56 +02:00
|
|
|
}
|
|
|
|
|
2017-10-03 16:34:57 +02:00
|
|
|
/// emitMatchClassDiagStrings - Emit a function to get the diagnostic text to be
|
|
|
|
/// used when an assembly operand does not match the expected operand class.
|
|
|
|
static void emitOperandMatchErrorDiagStrings(AsmMatcherInfo &Info, raw_ostream &OS) {
|
|
|
|
// If the target does not use DiagnosticString for any operands, don't emit
|
|
|
|
// an unused function.
|
2021-01-07 03:27:36 +01:00
|
|
|
if (llvm::all_of(Info.Classes, [](const ClassInfo &CI) {
|
|
|
|
return CI.DiagnosticString.empty();
|
|
|
|
}))
|
2017-10-03 16:34:57 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
OS << "static const char *getMatchKindDiag(" << Info.Target.getName()
|
|
|
|
<< "AsmParser::" << Info.Target.getName()
|
|
|
|
<< "MatchResultTy MatchResult) {\n";
|
|
|
|
OS << " switch (MatchResult) {\n";
|
|
|
|
|
|
|
|
for (const auto &CI: Info.Classes) {
|
|
|
|
if (!CI.DiagnosticString.empty()) {
|
|
|
|
assert(!CI.DiagnosticType.empty() &&
|
|
|
|
"DiagnosticString set without DiagnosticType");
|
|
|
|
OS << " case " << Info.Target.getName()
|
|
|
|
<< "AsmParser::Match_" << CI.DiagnosticType << ":\n";
|
|
|
|
OS << " return \"" << CI.DiagnosticString << "\";\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << " default:\n";
|
|
|
|
OS << " return nullptr;\n";
|
|
|
|
|
|
|
|
OS << " }\n";
|
|
|
|
OS << "}\n\n";
|
|
|
|
}
|
|
|
|
|
2017-10-10 13:00:40 +02:00
|
|
|
static void emitRegisterMatchErrorFunc(AsmMatcherInfo &Info, raw_ostream &OS) {
|
|
|
|
OS << "static unsigned getDiagKindFromRegisterClass(MatchClassKind "
|
|
|
|
"RegisterClass) {\n";
|
2018-10-19 08:12:02 +02:00
|
|
|
if (none_of(Info.Classes, [](const ClassInfo &CI) {
|
|
|
|
return CI.isRegisterClass() && !CI.DiagnosticType.empty();
|
|
|
|
})) {
|
2017-10-12 11:28:23 +02:00
|
|
|
OS << " return MCTargetAsmParser::Match_InvalidOperand;\n";
|
|
|
|
} else {
|
|
|
|
OS << " switch (RegisterClass) {\n";
|
|
|
|
for (const auto &CI: Info.Classes) {
|
|
|
|
if (CI.isRegisterClass() && !CI.DiagnosticType.empty()) {
|
|
|
|
OS << " case " << CI.Name << ":\n";
|
|
|
|
OS << " return " << Info.Target.getName() << "AsmParser::Match_"
|
|
|
|
<< CI.DiagnosticType << ";\n";
|
|
|
|
}
|
2017-10-10 13:00:40 +02:00
|
|
|
}
|
|
|
|
|
2017-10-12 11:28:23 +02:00
|
|
|
OS << " default:\n";
|
|
|
|
OS << " return MCTargetAsmParser::Match_InvalidOperand;\n";
|
2017-10-10 13:00:40 +02:00
|
|
|
|
2017-10-12 11:28:23 +02:00
|
|
|
OS << " }\n";
|
|
|
|
}
|
2017-10-10 13:00:40 +02:00
|
|
|
OS << "}\n\n";
|
|
|
|
}
|
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
/// emitValidateOperandClass - Emit the function to validate an operand class.
|
|
|
|
static void emitValidateOperandClass(AsmMatcherInfo &Info,
|
2011-02-10 01:08:28 +01:00
|
|
|
raw_ostream &OS) {
|
2014-06-08 18:18:35 +02:00
|
|
|
OS << "static unsigned validateOperandClass(MCParsedAsmOperand &GOp, "
|
2011-02-10 01:08:28 +01:00
|
|
|
<< "MatchClassKind Kind) {\n";
|
2014-06-08 18:18:35 +02:00
|
|
|
OS << " " << Info.Target.getName() << "Operand &Operand = ("
|
2020-11-06 15:19:59 +01:00
|
|
|
<< Info.Target.getName() << "Operand &)GOp;\n";
|
2009-08-11 04:59:53 +02:00
|
|
|
|
2011-07-15 20:30:43 +02:00
|
|
|
// The InvalidMatchClass is not to match any operand.
|
|
|
|
OS << " if (Kind == InvalidMatchClass)\n";
|
2012-06-23 01:56:44 +02:00
|
|
|
OS << " return MCTargetAsmParser::Match_InvalidOperand;\n\n";
|
2011-07-15 20:30:43 +02:00
|
|
|
|
2011-02-10 01:08:28 +01:00
|
|
|
// Check for Token operands first.
|
2012-06-23 01:56:44 +02:00
|
|
|
// FIXME: Use a more specific diagnostic type.
|
2017-10-10 13:00:40 +02:00
|
|
|
OS << " if (Operand.isToken() && Kind <= MCK_LAST_TOKEN)\n";
|
2012-06-23 01:56:44 +02:00
|
|
|
OS << " return isSubclass(matchTokenString(Operand.getToken()), Kind) ?\n"
|
|
|
|
<< " MCTargetAsmParser::Match_Success :\n"
|
|
|
|
<< " MCTargetAsmParser::Match_InvalidOperand;\n\n";
|
2009-08-11 04:59:53 +02:00
|
|
|
|
2011-02-10 01:08:28 +01:00
|
|
|
// Check the user classes. We don't care what order since we're only
|
|
|
|
// actually matching against one of them.
|
2016-04-05 18:18:16 +02:00
|
|
|
OS << " switch (Kind) {\n"
|
|
|
|
" default: break;\n";
|
2014-11-28 04:53:02 +01:00
|
|
|
for (const auto &CI : Info.Classes) {
|
2014-11-28 21:35:57 +01:00
|
|
|
if (!CI.isUserClass())
|
2009-08-11 04:59:53 +02:00
|
|
|
continue;
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2014-11-28 21:35:57 +01:00
|
|
|
OS << " // '" << CI.ClassName << "' class\n";
|
[AsmMatcher] Extend PredicateMethod with optional DiagnosticPredicate
An optional, light-weight and backward-compatible mechanism to allow
specifying that a diagnostic _only_ applies to a partial mismatch (NearMiss),
rather than a full mismatch.
Patch [1/2] in a series to improve assembler diagnostics for SVE.
- Patch [1/2]: https://reviews.llvm.org/D45879
- Patch [2/2]: https://reviews.llvm.org/D45880
Reviewers: olista01, stoklund, craig.topper, mcrosier, rengolin, echristo, fhahn, SjoerdMeijer, evandro, javed.absar
Reviewed By: olista01
Differential Revision: https://reviews.llvm.org/D45879
llvm-svn: 330930
2018-04-26 11:24:45 +02:00
|
|
|
OS << " case " << CI.Name << ": {\n";
|
|
|
|
OS << " DiagnosticPredicate DP(Operand." << CI.PredicateMethod
|
|
|
|
<< "());\n";
|
|
|
|
OS << " if (DP.isMatch())\n";
|
2012-06-23 01:56:44 +02:00
|
|
|
OS << " return MCTargetAsmParser::Match_Success;\n";
|
[AsmMatcher] Extend PredicateMethod with optional DiagnosticPredicate
An optional, light-weight and backward-compatible mechanism to allow
specifying that a diagnostic _only_ applies to a partial mismatch (NearMiss),
rather than a full mismatch.
Patch [1/2] in a series to improve assembler diagnostics for SVE.
- Patch [1/2]: https://reviews.llvm.org/D45879
- Patch [2/2]: https://reviews.llvm.org/D45880
Reviewers: olista01, stoklund, craig.topper, mcrosier, rengolin, echristo, fhahn, SjoerdMeijer, evandro, javed.absar
Reviewed By: olista01
Differential Revision: https://reviews.llvm.org/D45879
llvm-svn: 330930
2018-04-26 11:24:45 +02:00
|
|
|
if (!CI.DiagnosticType.empty()) {
|
|
|
|
OS << " if (DP.isNearMatch())\n";
|
|
|
|
OS << " return " << Info.Target.getName() << "AsmParser::Match_"
|
2014-11-28 21:35:57 +01:00
|
|
|
<< CI.DiagnosticType << ";\n";
|
[AsmMatcher] Extend PredicateMethod with optional DiagnosticPredicate
An optional, light-weight and backward-compatible mechanism to allow
specifying that a diagnostic _only_ applies to a partial mismatch (NearMiss),
rather than a full mismatch.
Patch [1/2] in a series to improve assembler diagnostics for SVE.
- Patch [1/2]: https://reviews.llvm.org/D45879
- Patch [2/2]: https://reviews.llvm.org/D45880
Reviewers: olista01, stoklund, craig.topper, mcrosier, rengolin, echristo, fhahn, SjoerdMeijer, evandro, javed.absar
Reviewed By: olista01
Differential Revision: https://reviews.llvm.org/D45879
llvm-svn: 330930
2018-04-26 11:24:45 +02:00
|
|
|
OS << " break;\n";
|
|
|
|
}
|
2016-04-05 18:18:16 +02:00
|
|
|
else
|
|
|
|
OS << " break;\n";
|
[AsmMatcher] Extend PredicateMethod with optional DiagnosticPredicate
An optional, light-weight and backward-compatible mechanism to allow
specifying that a diagnostic _only_ applies to a partial mismatch (NearMiss),
rather than a full mismatch.
Patch [1/2] in a series to improve assembler diagnostics for SVE.
- Patch [1/2]: https://reviews.llvm.org/D45879
- Patch [2/2]: https://reviews.llvm.org/D45880
Reviewers: olista01, stoklund, craig.topper, mcrosier, rengolin, echristo, fhahn, SjoerdMeijer, evandro, javed.absar
Reviewed By: olista01
Differential Revision: https://reviews.llvm.org/D45879
llvm-svn: 330930
2018-04-26 11:24:45 +02:00
|
|
|
OS << " }\n";
|
2009-08-08 09:50:56 +02:00
|
|
|
}
|
2016-04-05 18:18:16 +02:00
|
|
|
OS << " } // end switch (Kind)\n\n";
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2012-07-17 01:20:09 +02:00
|
|
|
// Check for register operands, including sub-classes.
|
|
|
|
OS << " if (Operand.isReg()) {\n";
|
|
|
|
OS << " MatchClassKind OpKind;\n";
|
|
|
|
OS << " switch (Operand.getReg()) {\n";
|
|
|
|
OS << " default: OpKind = InvalidMatchClass; break;\n";
|
2014-11-25 21:11:31 +01:00
|
|
|
for (const auto &RC : Info.RegisterClasses)
|
2017-07-07 07:19:25 +02:00
|
|
|
OS << " case " << RC.first->getValueAsString("Namespace") << "::"
|
2014-11-25 21:11:31 +01:00
|
|
|
<< RC.first->getName() << ": OpKind = " << RC.second->Name
|
2012-07-17 01:20:09 +02:00
|
|
|
<< "; break;\n";
|
|
|
|
OS << " }\n";
|
|
|
|
OS << " return isSubclass(OpKind, Kind) ? "
|
2017-10-10 13:00:40 +02:00
|
|
|
<< "(unsigned)MCTargetAsmParser::Match_Success :\n "
|
|
|
|
<< " getDiagKindFromRegisterClass(Kind);\n }\n\n";
|
|
|
|
|
|
|
|
// Expected operand is a register, but actual is not.
|
|
|
|
OS << " if (Kind > MCK_LAST_TOKEN && Kind <= MCK_LAST_REGISTER)\n";
|
|
|
|
OS << " return getDiagKindFromRegisterClass(Kind);\n\n";
|
2012-07-17 01:20:09 +02:00
|
|
|
|
2012-06-23 01:56:44 +02:00
|
|
|
// Generic fallthrough match failure case for operands that don't have
|
|
|
|
// specialized diagnostic types.
|
|
|
|
OS << " return MCTargetAsmParser::Match_InvalidOperand;\n";
|
2009-08-08 09:50:56 +02:00
|
|
|
OS << "}\n\n";
|
|
|
|
}
|
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
/// emitIsSubclass - Emit the subclass predicate function.
|
|
|
|
static void emitIsSubclass(CodeGenTarget &Target,
|
2014-11-28 21:35:57 +01:00
|
|
|
std::forward_list<ClassInfo> &Infos,
|
2009-08-10 18:05:47 +02:00
|
|
|
raw_ostream &OS) {
|
2012-09-15 22:22:05 +02:00
|
|
|
OS << "/// isSubclass - Compute whether \\p A is a subclass of \\p B.\n";
|
2011-12-06 23:07:02 +01:00
|
|
|
OS << "static bool isSubclass(MatchClassKind A, MatchClassKind B) {\n";
|
2009-08-10 18:05:47 +02:00
|
|
|
OS << " if (A == B)\n";
|
|
|
|
OS << " return true;\n\n";
|
|
|
|
|
2015-12-30 07:00:22 +01:00
|
|
|
bool EmittedSwitch = false;
|
2014-11-28 04:53:02 +01:00
|
|
|
for (const auto &A : Infos) {
|
2011-12-07 00:43:54 +01:00
|
|
|
std::vector<StringRef> SuperClasses;
|
2016-02-05 20:59:33 +01:00
|
|
|
if (A.IsOptional)
|
|
|
|
SuperClasses.push_back("OptionalMatchClass");
|
2014-11-28 04:53:02 +01:00
|
|
|
for (const auto &B : Infos) {
|
2014-11-28 21:35:57 +01:00
|
|
|
if (&A != &B && A.isSubsetOf(B))
|
|
|
|
SuperClasses.push_back(B.Name);
|
2011-12-07 00:43:54 +01:00
|
|
|
}
|
2009-08-10 18:05:47 +02:00
|
|
|
|
2011-12-07 00:43:54 +01:00
|
|
|
if (SuperClasses.empty())
|
|
|
|
continue;
|
2009-08-10 18:05:47 +02:00
|
|
|
|
2015-12-30 07:00:22 +01:00
|
|
|
// If this is the first SuperClass, emit the switch header.
|
|
|
|
if (!EmittedSwitch) {
|
2015-12-30 07:00:24 +01:00
|
|
|
OS << " switch (A) {\n";
|
2015-12-30 07:00:22 +01:00
|
|
|
OS << " default:\n";
|
|
|
|
OS << " return false;\n";
|
|
|
|
EmittedSwitch = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << "\n case " << A.Name << ":\n";
|
2009-08-10 18:05:47 +02:00
|
|
|
|
2011-12-07 00:43:54 +01:00
|
|
|
if (SuperClasses.size() == 1) {
|
2015-12-30 07:00:24 +01:00
|
|
|
OS << " return B == " << SuperClasses.back() << ";\n";
|
2011-12-07 00:43:54 +01:00
|
|
|
continue;
|
2009-08-10 18:05:47 +02:00
|
|
|
}
|
2011-12-07 00:43:54 +01:00
|
|
|
|
2013-07-15 18:53:32 +02:00
|
|
|
if (!SuperClasses.empty()) {
|
2015-12-30 07:00:22 +01:00
|
|
|
OS << " switch (B) {\n";
|
|
|
|
OS << " default: return false;\n";
|
2015-12-30 07:00:20 +01:00
|
|
|
for (StringRef SC : SuperClasses)
|
2015-12-30 07:00:22 +01:00
|
|
|
OS << " case " << SC << ": return true;\n";
|
|
|
|
OS << " }\n";
|
2013-07-15 18:53:32 +02:00
|
|
|
} else {
|
|
|
|
// No case statement to emit
|
2015-12-30 07:00:22 +01:00
|
|
|
OS << " return false;\n";
|
2013-07-15 18:53:32 +02:00
|
|
|
}
|
2009-08-10 18:05:47 +02:00
|
|
|
}
|
2013-07-15 18:53:32 +02:00
|
|
|
|
2015-12-30 07:00:22 +01:00
|
|
|
// If there were case statements emitted into the string stream write the
|
|
|
|
// default.
|
2016-01-03 08:33:34 +01:00
|
|
|
if (EmittedSwitch)
|
|
|
|
OS << " }\n";
|
|
|
|
else
|
2013-07-15 18:53:32 +02:00
|
|
|
OS << " return false;\n";
|
|
|
|
|
2009-08-10 18:05:47 +02:00
|
|
|
OS << "}\n\n";
|
|
|
|
}
|
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
/// emitMatchTokenString - Emit the function to match a token string to the
|
2009-08-08 23:22:41 +02:00
|
|
|
/// appropriate match class value.
|
2012-04-19 19:52:32 +02:00
|
|
|
static void emitMatchTokenString(CodeGenTarget &Target,
|
2014-11-28 21:35:57 +01:00
|
|
|
std::forward_list<ClassInfo> &Infos,
|
2009-08-08 23:22:41 +02:00
|
|
|
raw_ostream &OS) {
|
|
|
|
// Construct the match list.
|
2010-09-06 04:01:51 +02:00
|
|
|
std::vector<StringMatcher::StringPair> Matches;
|
2014-11-28 04:53:02 +01:00
|
|
|
for (const auto &CI : Infos) {
|
2014-11-28 21:35:57 +01:00
|
|
|
if (CI.Kind == ClassInfo::Token)
|
2015-05-29 21:43:39 +02:00
|
|
|
Matches.emplace_back(CI.ValueName, "return " + CI.Name + ";");
|
2009-08-08 23:22:41 +02:00
|
|
|
}
|
|
|
|
|
2011-12-06 23:07:02 +01:00
|
|
|
OS << "static MatchClassKind matchTokenString(StringRef Name) {\n";
|
2009-08-08 23:22:41 +02:00
|
|
|
|
2010-09-06 04:01:51 +02:00
|
|
|
StringMatcher("Name", Matches, OS).Emit();
|
2009-08-08 23:22:41 +02:00
|
|
|
|
|
|
|
OS << " return InvalidMatchClass;\n";
|
|
|
|
OS << "}\n\n";
|
|
|
|
}
|
2009-08-08 22:02:57 +02:00
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
/// emitMatchRegisterName - Emit the function to match a string to the target
|
2009-08-07 23:01:44 +02:00
|
|
|
/// specific register enum.
|
2012-04-19 19:52:32 +02:00
|
|
|
static void emitMatchRegisterName(CodeGenTarget &Target, Record *AsmParser,
|
2009-08-07 23:01:44 +02:00
|
|
|
raw_ostream &OS) {
|
2009-08-08 23:22:41 +02:00
|
|
|
// Construct the match list.
|
2010-09-06 04:01:51 +02:00
|
|
|
std::vector<StringMatcher::StringPair> Matches;
|
2014-11-29 19:13:39 +01:00
|
|
|
const auto &Regs = Target.getRegBank().getRegisters();
|
|
|
|
for (const CodeGenRegister &Reg : Regs) {
|
|
|
|
if (Reg.TheDef->getValueAsString("AsmName").empty())
|
2009-08-07 10:26:05 +02:00
|
|
|
continue;
|
|
|
|
|
2020-01-29 01:01:09 +01:00
|
|
|
Matches.emplace_back(std::string(Reg.TheDef->getValueAsString("AsmName")),
|
2015-05-29 21:43:39 +02:00
|
|
|
"return " + utostr(Reg.EnumValue) + ";");
|
2009-08-07 10:26:05 +02:00
|
|
|
}
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2010-02-09 01:34:28 +01:00
|
|
|
OS << "static unsigned MatchRegisterName(StringRef Name) {\n";
|
2009-08-08 23:22:41 +02:00
|
|
|
|
2017-12-07 10:51:55 +01:00
|
|
|
bool IgnoreDuplicates =
|
|
|
|
AsmParser->getValueAsBit("AllowDuplicateRegisterNames");
|
|
|
|
StringMatcher("Name", Matches, OS).Emit(0, IgnoreDuplicates);
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2009-08-08 23:22:41 +02:00
|
|
|
OS << " return 0;\n";
|
2009-08-07 10:26:05 +02:00
|
|
|
OS << "}\n\n";
|
2009-08-07 23:01:44 +02:00
|
|
|
}
|
|
|
|
|
2016-02-03 11:30:16 +01:00
|
|
|
/// Emit the function to match a string to the target
|
|
|
|
/// specific register enum.
|
|
|
|
static void emitMatchRegisterAltName(CodeGenTarget &Target, Record *AsmParser,
|
|
|
|
raw_ostream &OS) {
|
|
|
|
// Construct the match list.
|
|
|
|
std::vector<StringMatcher::StringPair> Matches;
|
|
|
|
const auto &Regs = Target.getRegBank().getRegisters();
|
|
|
|
for (const CodeGenRegister &Reg : Regs) {
|
|
|
|
|
|
|
|
auto AltNames = Reg.TheDef->getValueAsListOfStrings("AltNames");
|
|
|
|
|
|
|
|
for (auto AltName : AltNames) {
|
|
|
|
AltName = StringRef(AltName).trim();
|
|
|
|
|
|
|
|
// don't handle empty alternative names
|
|
|
|
if (AltName.empty())
|
|
|
|
continue;
|
|
|
|
|
2020-01-29 01:01:09 +01:00
|
|
|
Matches.emplace_back(std::string(AltName),
|
2016-02-03 11:30:16 +01:00
|
|
|
"return " + utostr(Reg.EnumValue) + ";");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << "static unsigned MatchRegisterAltName(StringRef Name) {\n";
|
|
|
|
|
2017-12-07 10:51:55 +01:00
|
|
|
bool IgnoreDuplicates =
|
|
|
|
AsmParser->getValueAsBit("AllowDuplicateRegisterNames");
|
|
|
|
StringMatcher("Name", Matches, OS).Emit(0, IgnoreDuplicates);
|
2016-02-03 11:30:16 +01:00
|
|
|
|
|
|
|
OS << " return 0;\n";
|
|
|
|
OS << "}\n\n";
|
|
|
|
}
|
|
|
|
|
2012-06-23 01:56:44 +02:00
|
|
|
/// emitOperandDiagnosticTypes - Emit the operand matching diagnostic types.
|
|
|
|
static void emitOperandDiagnosticTypes(AsmMatcherInfo &Info, raw_ostream &OS) {
|
|
|
|
// Get the set of diagnostic types from all of the operand classes.
|
|
|
|
std::set<StringRef> Types;
|
2016-01-03 08:33:30 +01:00
|
|
|
for (const auto &OpClassEntry : Info.AsmOperandClasses) {
|
|
|
|
if (!OpClassEntry.second->DiagnosticType.empty())
|
|
|
|
Types.insert(OpClassEntry.second->DiagnosticType);
|
2012-06-23 01:56:44 +02:00
|
|
|
}
|
2017-10-10 13:00:40 +02:00
|
|
|
for (const auto &OpClassEntry : Info.RegisterClassClasses) {
|
|
|
|
if (!OpClassEntry.second->DiagnosticType.empty())
|
|
|
|
Types.insert(OpClassEntry.second->DiagnosticType);
|
|
|
|
}
|
2012-06-23 01:56:44 +02:00
|
|
|
|
|
|
|
if (Types.empty()) return;
|
|
|
|
|
|
|
|
// Now emit the enum entries.
|
2016-01-03 08:33:30 +01:00
|
|
|
for (StringRef Type : Types)
|
|
|
|
OS << " Match_" << Type << ",\n";
|
2012-06-23 01:56:44 +02:00
|
|
|
OS << " END_OPERAND_DIAGNOSTIC_TYPES\n";
|
|
|
|
}
|
|
|
|
|
2012-04-25 00:40:08 +02:00
|
|
|
/// emitGetSubtargetFeatureName - Emit the helper function to get the
|
|
|
|
/// user-level name for a subtarget feature.
|
|
|
|
static void emitGetSubtargetFeatureName(AsmMatcherInfo &Info, raw_ostream &OS) {
|
|
|
|
OS << "// User-level names for subtarget features that participate in\n"
|
|
|
|
<< "// instruction matching.\n"
|
2015-06-30 14:32:53 +02:00
|
|
|
<< "static const char *getSubtargetFeatureName(uint64_t Val) {\n";
|
2013-07-15 18:53:32 +02:00
|
|
|
if (!Info.SubtargetFeatures.empty()) {
|
2015-06-30 14:32:53 +02:00
|
|
|
OS << " switch(Val) {\n";
|
2014-11-28 04:53:00 +01:00
|
|
|
for (const auto &SF : Info.SubtargetFeatures) {
|
2014-11-28 23:15:06 +01:00
|
|
|
const SubtargetFeatureInfo &SFI = SF.second;
|
2013-07-15 18:53:32 +02:00
|
|
|
// FIXME: Totally just a placeholder name to get the algorithm working.
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << " case " << SFI.getEnumBitName() << ": return \""
|
2013-07-15 18:53:32 +02:00
|
|
|
<< SFI.TheDef->getValueAsString("PredicateName") << "\";\n";
|
|
|
|
}
|
|
|
|
OS << " default: return \"(unknown)\";\n";
|
|
|
|
OS << " }\n";
|
|
|
|
} else {
|
|
|
|
// Nothing to emit, so skip the switch
|
|
|
|
OS << " return \"(unknown)\";\n";
|
2012-04-25 00:40:08 +02:00
|
|
|
}
|
2013-07-15 18:53:32 +02:00
|
|
|
OS << "}\n\n";
|
2012-04-25 00:40:08 +02:00
|
|
|
}
|
|
|
|
|
2010-10-30 22:15:02 +02:00
|
|
|
static std::string GetAliasRequiredFeatures(Record *R,
|
|
|
|
const AsmMatcherInfo &Info) {
|
2010-10-30 21:23:13 +02:00
|
|
|
std::vector<Record*> ReqFeatures = R->getValueAsListOfDefs("Predicates");
|
|
|
|
std::string Result;
|
2019-03-11 18:04:35 +01:00
|
|
|
|
|
|
|
if (ReqFeatures.empty())
|
|
|
|
return Result;
|
|
|
|
|
2010-10-30 21:23:13 +02:00
|
|
|
for (unsigned i = 0, e = ReqFeatures.size(); i != e; ++i) {
|
2014-11-28 23:15:06 +01:00
|
|
|
const SubtargetFeatureInfo *F = Info.getSubtargetFeature(ReqFeatures[i]);
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2014-04-15 09:20:03 +02:00
|
|
|
if (!F)
|
2012-10-25 22:33:17 +02:00
|
|
|
PrintFatalError(R->getLoc(), "Predicate '" + ReqFeatures[i]->getName() +
|
2010-11-01 03:09:21 +01:00
|
|
|
"' is not marked as an AssemblerPredicate!");
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2019-03-11 18:04:35 +01:00
|
|
|
if (i)
|
|
|
|
Result += " && ";
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2019-03-11 18:04:35 +01:00
|
|
|
Result += "Features.test(" + F->getEnumBitName() + ')';
|
2010-10-30 21:23:13 +02:00
|
|
|
}
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-10-30 21:23:13 +02:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2013-04-19 00:35:36 +02:00
|
|
|
static void emitMnemonicAliasVariant(raw_ostream &OS,const AsmMatcherInfo &Info,
|
|
|
|
std::vector<Record*> &Aliases,
|
|
|
|
unsigned Indent = 0,
|
|
|
|
StringRef AsmParserVariantName = StringRef()){
|
2010-10-30 20:56:12 +02:00
|
|
|
// Keep track of all the aliases from a mnemonic. Use an std::map so that the
|
|
|
|
// iteration order of the map is stable.
|
|
|
|
std::map<std::string, std::vector<Record*> > AliasesFromMnemonic;
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2016-01-03 08:33:30 +01:00
|
|
|
for (Record *R : Aliases) {
|
2013-04-19 00:35:36 +02:00
|
|
|
// FIXME: Allow AssemblerVariantName to be a comma separated list.
|
2017-05-31 23:12:46 +02:00
|
|
|
StringRef AsmVariantName = R->getValueAsString("AsmVariantName");
|
2013-04-19 00:35:36 +02:00
|
|
|
if (AsmVariantName != AsmParserVariantName)
|
|
|
|
continue;
|
2021-04-16 15:55:42 +02:00
|
|
|
AliasesFromMnemonic[R->getValueAsString("FromMnemonic").lower()]
|
2020-01-28 20:23:46 +01:00
|
|
|
.push_back(R);
|
2010-10-30 20:56:12 +02:00
|
|
|
}
|
2013-04-19 00:35:36 +02:00
|
|
|
if (AliasesFromMnemonic.empty())
|
|
|
|
return;
|
2013-07-16 11:22:38 +02:00
|
|
|
|
2010-10-30 20:56:12 +02:00
|
|
|
// Process each alias a "from" mnemonic at a time, building the code executed
|
|
|
|
// by the string remapper.
|
|
|
|
std::vector<StringMatcher::StringPair> Cases;
|
2016-01-03 08:33:30 +01:00
|
|
|
for (const auto &AliasEntry : AliasesFromMnemonic) {
|
|
|
|
const std::vector<Record*> &ToVec = AliasEntry.second;
|
2010-10-30 21:23:13 +02:00
|
|
|
|
|
|
|
// Loop through each alias and emit code that handles each case. If there
|
|
|
|
// are two instructions without predicates, emit an error. If there is one,
|
|
|
|
// emit it last.
|
|
|
|
std::string MatchCode;
|
|
|
|
int AliasWithNoPredicate = -1;
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-10-30 21:23:13 +02:00
|
|
|
for (unsigned i = 0, e = ToVec.size(); i != e; ++i) {
|
|
|
|
Record *R = ToVec[i];
|
2010-10-30 22:15:02 +02:00
|
|
|
std::string FeatureMask = GetAliasRequiredFeatures(R, Info);
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-10-30 21:23:13 +02:00
|
|
|
// If this unconditionally matches, remember it for later and diagnose
|
|
|
|
// duplicates.
|
|
|
|
if (FeatureMask.empty()) {
|
|
|
|
if (AliasWithNoPredicate != -1) {
|
|
|
|
// We can't have two aliases from the same mnemonic with no predicate.
|
|
|
|
PrintError(ToVec[AliasWithNoPredicate]->getLoc(),
|
|
|
|
"two MnemonicAliases with the same 'from' mnemonic!");
|
2012-10-25 22:33:17 +02:00
|
|
|
PrintFatalError(R->getLoc(), "this is the other MnemonicAlias.");
|
2010-10-30 21:23:13 +02:00
|
|
|
}
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-10-30 21:23:13 +02:00
|
|
|
AliasWithNoPredicate = i;
|
|
|
|
continue;
|
|
|
|
}
|
2016-01-03 08:33:30 +01:00
|
|
|
if (R->getValueAsString("ToMnemonic") == AliasEntry.first)
|
2012-10-25 22:33:17 +02:00
|
|
|
PrintFatalError(R->getLoc(), "MnemonicAlias to the same string");
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-10-30 21:47:49 +02:00
|
|
|
if (!MatchCode.empty())
|
|
|
|
MatchCode += "else ";
|
2019-03-11 18:04:35 +01:00
|
|
|
MatchCode += "if (" + FeatureMask + ")\n";
|
2017-05-31 21:01:11 +02:00
|
|
|
MatchCode += " Mnemonic = \"";
|
2021-04-16 15:55:42 +02:00
|
|
|
MatchCode += R->getValueAsString("ToMnemonic").lower();
|
2017-05-31 21:01:11 +02:00
|
|
|
MatchCode += "\";\n";
|
2010-10-30 21:23:13 +02:00
|
|
|
}
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-10-30 21:23:13 +02:00
|
|
|
if (AliasWithNoPredicate != -1) {
|
|
|
|
Record *R = ToVec[AliasWithNoPredicate];
|
2010-10-30 21:47:49 +02:00
|
|
|
if (!MatchCode.empty())
|
|
|
|
MatchCode += "else\n ";
|
2017-05-31 21:01:11 +02:00
|
|
|
MatchCode += "Mnemonic = \"";
|
2021-04-16 15:55:42 +02:00
|
|
|
MatchCode += R->getValueAsString("ToMnemonic").lower();
|
2017-05-31 21:01:11 +02:00
|
|
|
MatchCode += "\";\n";
|
2010-10-30 20:56:12 +02:00
|
|
|
}
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-10-30 21:23:13 +02:00
|
|
|
MatchCode += "return;";
|
|
|
|
|
2016-01-03 08:33:30 +01:00
|
|
|
Cases.push_back(std::make_pair(AliasEntry.first, MatchCode));
|
2010-10-30 19:36:36 +02:00
|
|
|
}
|
2013-04-19 00:35:36 +02:00
|
|
|
StringMatcher("Mnemonic", Cases, OS).Emit(Indent);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// emitMnemonicAliases - If the target has any MnemonicAlias<> definitions,
|
|
|
|
/// emit a function for them and return true, otherwise return false.
|
|
|
|
static bool emitMnemonicAliases(raw_ostream &OS, const AsmMatcherInfo &Info,
|
|
|
|
CodeGenTarget &Target) {
|
|
|
|
// Ignore aliases when match-prefix is set.
|
|
|
|
if (!MatchPrefix.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::vector<Record*> Aliases =
|
|
|
|
Info.getRecords().getAllDerivedDefinitions("MnemonicAlias");
|
|
|
|
if (Aliases.empty()) return false;
|
|
|
|
|
|
|
|
OS << "static void applyMnemonicAliases(StringRef &Mnemonic, "
|
2019-03-11 18:04:35 +01:00
|
|
|
"const FeatureBitset &Features, unsigned VariantID) {\n";
|
2013-04-19 00:35:36 +02:00
|
|
|
OS << " switch (VariantID) {\n";
|
|
|
|
unsigned VariantCount = Target.getAsmParserVariantCount();
|
|
|
|
for (unsigned VC = 0; VC != VariantCount; ++VC) {
|
|
|
|
Record *AsmVariant = Target.getAsmParserVariant(VC);
|
|
|
|
int AsmParserVariantNo = AsmVariant->getValueAsInt("Variant");
|
2017-05-31 23:12:46 +02:00
|
|
|
StringRef AsmParserVariantName = AsmVariant->getValueAsString("Name");
|
2020-11-06 15:19:59 +01:00
|
|
|
OS << " case " << AsmParserVariantNo << ":\n";
|
2013-04-19 00:35:36 +02:00
|
|
|
emitMnemonicAliasVariant(OS, Info, Aliases, /*Indent=*/2,
|
|
|
|
AsmParserVariantName);
|
|
|
|
OS << " break;\n";
|
|
|
|
}
|
|
|
|
OS << " }\n";
|
|
|
|
|
|
|
|
// Emit aliases that apply to all variants.
|
|
|
|
emitMnemonicAliasVariant(OS, Info, Aliases);
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2011-01-18 02:59:30 +01:00
|
|
|
OS << "}\n\n";
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2010-10-30 20:48:18 +02:00
|
|
|
return true;
|
2010-10-30 19:36:36 +02:00
|
|
|
}
|
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
static void emitCustomOperandParsing(raw_ostream &OS, CodeGenTarget &Target,
|
2012-09-18 09:02:21 +02:00
|
|
|
const AsmMatcherInfo &Info, StringRef ClassName,
|
|
|
|
StringToOffsetTable &StringTable,
|
2019-03-11 18:04:35 +01:00
|
|
|
unsigned MaxMnemonicIndex,
|
|
|
|
unsigned MaxFeaturesIndex,
|
|
|
|
bool HasMnemonicFirst) {
|
2012-09-18 09:02:21 +02:00
|
|
|
unsigned MaxMask = 0;
|
2015-12-31 09:18:20 +01:00
|
|
|
for (const OperandMatchEntry &OMI : Info.OperandMatchInfo) {
|
|
|
|
MaxMask |= OMI.OperandMask;
|
2012-09-18 09:02:21 +02:00
|
|
|
}
|
|
|
|
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
// Emit the static custom operand parsing table;
|
|
|
|
OS << "namespace {\n";
|
|
|
|
OS << " struct OperandMatchEntry {\n";
|
2012-09-18 09:02:21 +02:00
|
|
|
OS << " " << getMinimalTypeForRange(MaxMnemonicIndex)
|
|
|
|
<< " Mnemonic;\n";
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << " " << getMinimalTypeForRange(MaxMask)
|
|
|
|
<< " OperandMask;\n";
|
2014-11-28 21:35:57 +01:00
|
|
|
OS << " " << getMinimalTypeForRange(std::distance(
|
|
|
|
Info.Classes.begin(), Info.Classes.end())) << " Class;\n";
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << " " << getMinimalTypeForRange(MaxFeaturesIndex)
|
|
|
|
<< " RequiredFeaturesIdx;\n\n";
|
2012-03-03 21:44:43 +01:00
|
|
|
OS << " StringRef getMnemonic() const {\n";
|
|
|
|
OS << " return StringRef(MnemonicTable + Mnemonic + 1,\n";
|
|
|
|
OS << " MnemonicTable[Mnemonic]);\n";
|
|
|
|
OS << " }\n";
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
OS << " };\n\n";
|
|
|
|
|
|
|
|
OS << " // Predicate for searching for an opcode.\n";
|
|
|
|
OS << " struct LessOpcodeOperand {\n";
|
|
|
|
OS << " bool operator()(const OperandMatchEntry &LHS, StringRef RHS) {\n";
|
2012-03-03 21:44:43 +01:00
|
|
|
OS << " return LHS.getMnemonic() < RHS;\n";
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
OS << " }\n";
|
|
|
|
OS << " bool operator()(StringRef LHS, const OperandMatchEntry &RHS) {\n";
|
2012-03-03 21:44:43 +01:00
|
|
|
OS << " return LHS < RHS.getMnemonic();\n";
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
OS << " }\n";
|
|
|
|
OS << " bool operator()(const OperandMatchEntry &LHS,";
|
|
|
|
OS << " const OperandMatchEntry &RHS) {\n";
|
2012-03-03 21:44:43 +01:00
|
|
|
OS << " return LHS.getMnemonic() < RHS.getMnemonic();\n";
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
OS << " }\n";
|
|
|
|
OS << " };\n";
|
|
|
|
|
2019-08-25 12:47:30 +02:00
|
|
|
OS << "} // end anonymous namespace\n\n";
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
|
|
|
|
OS << "static const OperandMatchEntry OperandMatchTable["
|
|
|
|
<< Info.OperandMatchInfo.size() << "] = {\n";
|
|
|
|
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << " /* Operand List Mnemonic, Mask, Operand Class, Features */\n";
|
2015-12-31 09:18:20 +01:00
|
|
|
for (const OperandMatchEntry &OMI : Info.OperandMatchInfo) {
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
const MatchableInfo &II = *OMI.MI;
|
|
|
|
|
2012-09-18 09:02:21 +02:00
|
|
|
OS << " { ";
|
|
|
|
|
|
|
|
// Store a pascal-style length byte in the mnemonic.
|
2020-08-13 00:22:58 +02:00
|
|
|
std::string LenMnemonic = char(II.Mnemonic.size()) + II.Mnemonic.lower();
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << StringTable.GetOrAddStringOffset(LenMnemonic, false)
|
2012-09-18 09:02:21 +02:00
|
|
|
<< " /* " << II.Mnemonic << " */, ";
|
|
|
|
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << OMI.OperandMask;
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
OS << " /* ";
|
2021-01-30 18:53:38 +01:00
|
|
|
ListSeparator LS;
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
for (int i = 0, e = 31; i !=e; ++i)
|
2021-01-30 18:53:38 +01:00
|
|
|
if (OMI.OperandMask & (1 << i))
|
|
|
|
OS << LS << i;
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << " */, ";
|
|
|
|
|
|
|
|
OS << OMI.CI->Name;
|
|
|
|
|
|
|
|
// Write the required features mask.
|
|
|
|
OS << ", AMFBS";
|
|
|
|
if (II.RequiredFeatures.empty())
|
|
|
|
OS << "_None";
|
|
|
|
else
|
|
|
|
for (unsigned i = 0, e = II.RequiredFeatures.size(); i != e; ++i)
|
|
|
|
OS << '_' << II.RequiredFeatures[i]->TheDef->getName();
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
|
|
|
|
OS << " },\n";
|
|
|
|
}
|
|
|
|
OS << "};\n\n";
|
|
|
|
|
|
|
|
// Emit the operand class switch to call the correct custom parser for
|
|
|
|
// the found operand class.
|
2016-11-01 17:32:05 +01:00
|
|
|
OS << "OperandMatchResultTy " << Target.getName() << ClassName << "::\n"
|
2014-06-08 18:18:35 +02:00
|
|
|
<< "tryCustomParseOperand(OperandVector"
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
<< " &Operands,\n unsigned MCK) {\n\n"
|
|
|
|
<< " switch(MCK) {\n";
|
|
|
|
|
2014-11-28 04:53:02 +01:00
|
|
|
for (const auto &CI : Info.Classes) {
|
2014-11-28 21:35:57 +01:00
|
|
|
if (CI.ParserMethod.empty())
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
continue;
|
2014-11-28 21:35:57 +01:00
|
|
|
OS << " case " << CI.Name << ":\n"
|
|
|
|
<< " return " << CI.ParserMethod << "(Operands);\n";
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
OS << " default:\n";
|
2011-02-12 02:34:40 +01:00
|
|
|
OS << " return MatchOperand_NoMatch;\n";
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
OS << " }\n";
|
2011-02-12 02:34:40 +01:00
|
|
|
OS << " return MatchOperand_NoMatch;\n";
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
OS << "}\n\n";
|
|
|
|
|
|
|
|
// Emit the static custom operand parser. This code is very similar with
|
|
|
|
// the other matcher. Also use MatchResultTy here just in case we go for
|
|
|
|
// a better error handling.
|
2016-11-01 17:32:05 +01:00
|
|
|
OS << "OperandMatchResultTy " << Target.getName() << ClassName << "::\n"
|
2014-06-08 18:18:35 +02:00
|
|
|
<< "MatchOperandParserImpl(OperandVector"
|
2017-12-20 12:02:42 +01:00
|
|
|
<< " &Operands,\n StringRef Mnemonic,\n"
|
|
|
|
<< " bool ParseForAllFeatures) {\n";
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
|
|
|
|
// Emit code to get the available features.
|
|
|
|
OS << " // Get the current feature set.\n";
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << " const FeatureBitset &AvailableFeatures = getAvailableFeatures();\n\n";
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
|
|
|
|
OS << " // Get the next operand index.\n";
|
2015-12-31 09:18:23 +01:00
|
|
|
OS << " unsigned NextOpNum = Operands.size()"
|
|
|
|
<< (HasMnemonicFirst ? " - 1" : "") << ";\n";
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
|
|
|
|
// Emit code to search the table.
|
|
|
|
OS << " // Search the table.\n";
|
2015-12-31 09:18:23 +01:00
|
|
|
if (HasMnemonicFirst) {
|
|
|
|
OS << " auto MnemonicRange =\n";
|
|
|
|
OS << " std::equal_range(std::begin(OperandMatchTable), "
|
|
|
|
"std::end(OperandMatchTable),\n";
|
|
|
|
OS << " Mnemonic, LessOpcodeOperand());\n\n";
|
|
|
|
} else {
|
|
|
|
OS << " auto MnemonicRange = std::make_pair(std::begin(OperandMatchTable),"
|
|
|
|
" std::end(OperandMatchTable));\n";
|
|
|
|
OS << " if (!Mnemonic.empty())\n";
|
|
|
|
OS << " MnemonicRange =\n";
|
|
|
|
OS << " std::equal_range(std::begin(OperandMatchTable), "
|
|
|
|
"std::end(OperandMatchTable),\n";
|
|
|
|
OS << " Mnemonic, LessOpcodeOperand());\n\n";
|
|
|
|
}
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
|
|
|
|
OS << " if (MnemonicRange.first == MnemonicRange.second)\n";
|
2011-02-12 02:34:40 +01:00
|
|
|
OS << " return MatchOperand_NoMatch;\n\n";
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
|
|
|
|
OS << " for (const OperandMatchEntry *it = MnemonicRange.first,\n"
|
|
|
|
<< " *ie = MnemonicRange.second; it != ie; ++it) {\n";
|
|
|
|
|
|
|
|
OS << " // equal_range guarantees that instruction mnemonic matches.\n";
|
2012-03-03 21:44:43 +01:00
|
|
|
OS << " assert(Mnemonic == it->getMnemonic());\n\n";
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
|
|
|
|
// Emit check that the required features are available.
|
|
|
|
OS << " // check if the available features match\n";
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << " const FeatureBitset &RequiredFeatures = "
|
|
|
|
"FeatureBitsets[it->RequiredFeaturesIdx];\n";
|
2017-12-20 12:02:42 +01:00
|
|
|
OS << " if (!ParseForAllFeatures && (AvailableFeatures & "
|
2019-03-11 18:04:35 +01:00
|
|
|
"RequiredFeatures) != RequiredFeatures)\n";
|
2020-11-06 15:19:59 +01:00
|
|
|
OS << " continue;\n\n";
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
|
|
|
|
// Emit check to ensure the operand number matches.
|
|
|
|
OS << " // check if the operand in question has a custom parser.\n";
|
|
|
|
OS << " if (!(it->OperandMask & (1 << NextOpNum)))\n";
|
|
|
|
OS << " continue;\n\n";
|
|
|
|
|
|
|
|
// Emit call to the custom parser method
|
|
|
|
OS << " // call custom parse method to handle the operand\n";
|
2011-02-12 02:34:40 +01:00
|
|
|
OS << " OperandMatchResultTy Result = ";
|
2011-12-06 23:07:02 +01:00
|
|
|
OS << "tryCustomParseOperand(Operands, it->Class);\n";
|
2011-02-12 02:34:40 +01:00
|
|
|
OS << " if (Result != MatchOperand_NoMatch)\n";
|
|
|
|
OS << " return Result;\n";
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
OS << " }\n\n";
|
|
|
|
|
2011-02-12 02:34:40 +01:00
|
|
|
OS << " // Okay, we had no match.\n";
|
|
|
|
OS << " return MatchOperand_NoMatch;\n";
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
OS << "}\n\n";
|
|
|
|
}
|
|
|
|
|
2018-01-10 11:10:56 +01:00
|
|
|
static void emitAsmTiedOperandConstraints(CodeGenTarget &Target,
|
|
|
|
AsmMatcherInfo &Info,
|
|
|
|
raw_ostream &OS) {
|
[TableGen][AsmMatcherEmitter] Allow tied operands of different classes in aliases.
Allow a tied operand of a different operand class in InstAliases,
so that the operand can be printed (and added to the MC instruction)
as the appropriate register. For example, 'GPR64as32', which would
be printed/parsed as a 32bit register and should match a tied 64bit
register operand, where the former is a sub-register of the latter.
This patch also generalizes the constraint checking to an overrideable
method in MCTargetAsmParser, so that target asmparsers can specify
whether a given operand satisfies the tied register constraint.
Reviewers: olista01, rengolin, fhahn, SjoerdMeijer, samparker, dsanders, craig.topper
Reviewed By: fhahn
Differential Revision: https://reviews.llvm.org/D47714
llvm-svn: 334942
2018-06-18 15:39:29 +02:00
|
|
|
std::string AsmParserName =
|
2020-01-28 20:23:46 +01:00
|
|
|
std::string(Info.AsmParser->getValueAsString("AsmParserClassName"));
|
2018-01-10 11:10:56 +01:00
|
|
|
OS << "static bool ";
|
[TableGen][AsmMatcherEmitter] Allow tied operands of different classes in aliases.
Allow a tied operand of a different operand class in InstAliases,
so that the operand can be printed (and added to the MC instruction)
as the appropriate register. For example, 'GPR64as32', which would
be printed/parsed as a 32bit register and should match a tied 64bit
register operand, where the former is a sub-register of the latter.
This patch also generalizes the constraint checking to an overrideable
method in MCTargetAsmParser, so that target asmparsers can specify
whether a given operand satisfies the tied register constraint.
Reviewers: olista01, rengolin, fhahn, SjoerdMeijer, samparker, dsanders, craig.topper
Reviewed By: fhahn
Differential Revision: https://reviews.llvm.org/D47714
llvm-svn: 334942
2018-06-18 15:39:29 +02:00
|
|
|
OS << "checkAsmTiedOperandConstraints(const " << Target.getName()
|
|
|
|
<< AsmParserName << "&AsmParser,\n";
|
|
|
|
OS << " unsigned Kind,\n";
|
2018-01-10 11:10:56 +01:00
|
|
|
OS << " const OperandVector &Operands,\n";
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
OS << " uint64_t &ErrorInfo) {\n";
|
|
|
|
OS << " assert(Kind < CVT_NUM_SIGNATURES && \"Invalid signature!\");\n";
|
|
|
|
OS << " const uint8_t *Converter = ConversionTable[Kind];\n";
|
2020-11-06 15:19:59 +01:00
|
|
|
OS << " for (const uint8_t *p = Converter; *p; p += 2) {\n";
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
OS << " switch (*p) {\n";
|
|
|
|
OS << " case CVT_Tied: {\n";
|
2020-11-06 15:19:59 +01:00
|
|
|
OS << " unsigned OpIdx = *(p + 1);\n";
|
2018-02-17 13:29:47 +01:00
|
|
|
OS << " assert(OpIdx < (size_t)(std::end(TiedAsmOperandTable) -\n";
|
|
|
|
OS << " std::begin(TiedAsmOperandTable)) &&\n";
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
OS << " \"Tied operand not found\");\n";
|
|
|
|
OS << " unsigned OpndNum1 = TiedAsmOperandTable[OpIdx][1];\n";
|
|
|
|
OS << " unsigned OpndNum2 = TiedAsmOperandTable[OpIdx][2];\n";
|
|
|
|
OS << " if (OpndNum1 != OpndNum2) {\n";
|
|
|
|
OS << " auto &SrcOp1 = Operands[OpndNum1];\n";
|
|
|
|
OS << " auto &SrcOp2 = Operands[OpndNum2];\n";
|
[TableGen][AsmMatcherEmitter] Allow tied operands of different classes in aliases.
Allow a tied operand of a different operand class in InstAliases,
so that the operand can be printed (and added to the MC instruction)
as the appropriate register. For example, 'GPR64as32', which would
be printed/parsed as a 32bit register and should match a tied 64bit
register operand, where the former is a sub-register of the latter.
This patch also generalizes the constraint checking to an overrideable
method in MCTargetAsmParser, so that target asmparsers can specify
whether a given operand satisfies the tied register constraint.
Reviewers: olista01, rengolin, fhahn, SjoerdMeijer, samparker, dsanders, craig.topper
Reviewed By: fhahn
Differential Revision: https://reviews.llvm.org/D47714
llvm-svn: 334942
2018-06-18 15:39:29 +02:00
|
|
|
OS << " if (SrcOp1->isReg() && SrcOp2->isReg()) {\n";
|
|
|
|
OS << " if (!AsmParser.regsEqual(*SrcOp1, *SrcOp2)) {\n";
|
|
|
|
OS << " ErrorInfo = OpndNum2;\n";
|
|
|
|
OS << " return false;\n";
|
|
|
|
OS << " }\n";
|
[TableGen][AsmMatcherEmitter] Fix tied-constraint checking for InstAliases
Summary:
This is a bit of a reimplementation the work done in
https://reviews.llvm.org/D41446, since that patch only really works for
tied operands of instructions, not aliases.
Instead of checking the constraints based on the matched instruction's opcode,
this patch uses the match-info's convert function to check the operand
constraints for that specific instruction/alias.
This is based on the matched operands for the instruction, not the
resulting opcode of the MCInst.
This patch adds the following enum/table to the *GenAsmMatcher.inc file:
enum {
Tie0_1_1,
Tie0_1_2,
Tie0_1_5,
...
};
const char TiedAsmOperandTable[][3] = {
/* Tie0_1_1 */ { 0, 1, 1 },
/* Tie0_1_2 */ { 0, 1, 2 },
/* Tie0_1_5 */ { 0, 1, 5 },
...
};
And it is referenced directly in the ConversionTable, like this:
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][13] = {
...
{ CVT_95_addRegOperands, 1,
CVT_95_addRegOperands, 2,
CVT_Tied, Tie0_1_5,
CVT_95_addRegOperands, 6, CVT_Done },
...
The Tie0_1_5 (and corresponding table) encodes that:
* Result operand 0 is the operand to copy (which is e.g. done when
building up the operands to the MCInst in convertToMCInst())
* Asm operands 1 and 5 should be the same operands (which is checked
in checkAsmTiedOperandConstraints()).
Reviewers: olista01, rengolin, fhahn, craig.topper, echristo, apazos, dsanders
Reviewed By: olista01
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42293
llvm-svn: 324196
2018-02-04 17:24:17 +01:00
|
|
|
OS << " }\n";
|
|
|
|
OS << " }\n";
|
|
|
|
OS << " break;\n";
|
|
|
|
OS << " }\n";
|
|
|
|
OS << " default:\n";
|
|
|
|
OS << " break;\n";
|
2018-01-10 11:10:56 +01:00
|
|
|
OS << " }\n";
|
|
|
|
OS << " }\n";
|
|
|
|
OS << " return true;\n";
|
|
|
|
OS << "}\n\n";
|
|
|
|
}
|
|
|
|
|
2017-07-05 14:39:13 +02:00
|
|
|
static void emitMnemonicSpellChecker(raw_ostream &OS, CodeGenTarget &Target,
|
|
|
|
unsigned VariantCount) {
|
2017-10-26 08:46:40 +02:00
|
|
|
OS << "static std::string " << Target.getName()
|
2019-03-11 18:04:35 +01:00
|
|
|
<< "MnemonicSpellCheck(StringRef S, const FeatureBitset &FBS,"
|
|
|
|
<< " unsigned VariantID) {\n";
|
2017-07-05 14:39:13 +02:00
|
|
|
if (!VariantCount)
|
|
|
|
OS << " return \"\";";
|
|
|
|
else {
|
|
|
|
OS << " const unsigned MaxEditDist = 2;\n";
|
|
|
|
OS << " std::vector<StringRef> Candidates;\n";
|
2017-10-26 08:46:41 +02:00
|
|
|
OS << " StringRef Prev = \"\";\n\n";
|
|
|
|
|
|
|
|
OS << " // Find the appropriate table for this asm variant.\n";
|
|
|
|
OS << " const MatchEntry *Start, *End;\n";
|
|
|
|
OS << " switch (VariantID) {\n";
|
|
|
|
OS << " default: llvm_unreachable(\"invalid variant!\");\n";
|
|
|
|
for (unsigned VC = 0; VC != VariantCount; ++VC) {
|
|
|
|
Record *AsmVariant = Target.getAsmParserVariant(VC);
|
|
|
|
int AsmVariantNo = AsmVariant->getValueAsInt("Variant");
|
|
|
|
OS << " case " << AsmVariantNo << ": Start = std::begin(MatchTable" << VC
|
|
|
|
<< "); End = std::end(MatchTable" << VC << "); break;\n";
|
|
|
|
}
|
|
|
|
OS << " }\n\n";
|
|
|
|
OS << " for (auto I = Start; I < End; I++) {\n";
|
2017-07-05 14:39:13 +02:00
|
|
|
OS << " // Ignore unsupported instructions.\n";
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << " const FeatureBitset &RequiredFeatures = "
|
|
|
|
"FeatureBitsets[I->RequiredFeaturesIdx];\n";
|
|
|
|
OS << " if ((FBS & RequiredFeatures) != RequiredFeatures)\n";
|
2017-07-05 14:39:13 +02:00
|
|
|
OS << " continue;\n";
|
|
|
|
OS << "\n";
|
|
|
|
OS << " StringRef T = I->getMnemonic();\n";
|
|
|
|
OS << " // Avoid recomputing the edit distance for the same string.\n";
|
|
|
|
OS << " if (T.equals(Prev))\n";
|
|
|
|
OS << " continue;\n";
|
|
|
|
OS << "\n";
|
|
|
|
OS << " Prev = T;\n";
|
|
|
|
OS << " unsigned Dist = S.edit_distance(T, false, MaxEditDist);\n";
|
|
|
|
OS << " if (Dist <= MaxEditDist)\n";
|
|
|
|
OS << " Candidates.push_back(T);\n";
|
|
|
|
OS << " }\n";
|
|
|
|
OS << "\n";
|
|
|
|
OS << " if (Candidates.empty())\n";
|
|
|
|
OS << " return \"\";\n";
|
|
|
|
OS << "\n";
|
|
|
|
OS << " std::string Res = \", did you mean: \";\n";
|
|
|
|
OS << " unsigned i = 0;\n";
|
2020-11-06 15:19:59 +01:00
|
|
|
OS << " for (; i < Candidates.size() - 1; i++)\n";
|
2017-07-05 14:39:13 +02:00
|
|
|
OS << " Res += Candidates[i].str() + \", \";\n";
|
|
|
|
OS << " return Res + Candidates[i].str() + \"?\";\n";
|
|
|
|
}
|
|
|
|
OS << "}\n";
|
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
2020-10-05 13:23:41 +02:00
|
|
|
static void emitMnemonicChecker(raw_ostream &OS,
|
|
|
|
CodeGenTarget &Target,
|
|
|
|
unsigned VariantCount,
|
|
|
|
bool HasMnemonicFirst,
|
|
|
|
bool HasMnemonicAliases) {
|
|
|
|
OS << "static bool " << Target.getName()
|
|
|
|
<< "CheckMnemonic(StringRef Mnemonic,\n";
|
|
|
|
OS << " "
|
|
|
|
<< "const FeatureBitset &AvailableFeatures,\n";
|
|
|
|
OS << " "
|
|
|
|
<< "unsigned VariantID) {\n";
|
|
|
|
|
|
|
|
if (!VariantCount) {
|
|
|
|
OS << " return false;\n";
|
|
|
|
} else {
|
|
|
|
if (HasMnemonicAliases) {
|
|
|
|
OS << " // Process all MnemonicAliases to remap the mnemonic.\n";
|
|
|
|
OS << " applyMnemonicAliases(Mnemonic, AvailableFeatures, VariantID);";
|
|
|
|
OS << "\n\n";
|
|
|
|
}
|
|
|
|
OS << " // Find the appropriate table for this asm variant.\n";
|
|
|
|
OS << " const MatchEntry *Start, *End;\n";
|
|
|
|
OS << " switch (VariantID) {\n";
|
|
|
|
OS << " default: llvm_unreachable(\"invalid variant!\");\n";
|
|
|
|
for (unsigned VC = 0; VC != VariantCount; ++VC) {
|
|
|
|
Record *AsmVariant = Target.getAsmParserVariant(VC);
|
|
|
|
int AsmVariantNo = AsmVariant->getValueAsInt("Variant");
|
|
|
|
OS << " case " << AsmVariantNo << ": Start = std::begin(MatchTable" << VC
|
|
|
|
<< "); End = std::end(MatchTable" << VC << "); break;\n";
|
|
|
|
}
|
|
|
|
OS << " }\n\n";
|
|
|
|
|
|
|
|
OS << " // Search the table.\n";
|
|
|
|
if (HasMnemonicFirst) {
|
|
|
|
OS << " auto MnemonicRange = "
|
|
|
|
"std::equal_range(Start, End, Mnemonic, LessOpcode());\n\n";
|
|
|
|
} else {
|
|
|
|
OS << " auto MnemonicRange = std::make_pair(Start, End);\n";
|
|
|
|
OS << " unsigned SIndex = Mnemonic.empty() ? 0 : 1;\n";
|
|
|
|
OS << " if (!Mnemonic.empty())\n";
|
|
|
|
OS << " MnemonicRange = "
|
|
|
|
<< "std::equal_range(Start, End, Mnemonic.lower(), LessOpcode());\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << " if (MnemonicRange.first == MnemonicRange.second)\n";
|
|
|
|
OS << " return false;\n\n";
|
|
|
|
|
|
|
|
OS << " for (const MatchEntry *it = MnemonicRange.first, "
|
|
|
|
<< "*ie = MnemonicRange.second;\n";
|
|
|
|
OS << " it != ie; ++it) {\n";
|
|
|
|
OS << " const FeatureBitset &RequiredFeatures =\n";
|
|
|
|
OS << " FeatureBitsets[it->RequiredFeaturesIdx];\n";
|
|
|
|
OS << " if ((AvailableFeatures & RequiredFeatures) == ";
|
|
|
|
OS << "RequiredFeatures)\n";
|
|
|
|
OS << " return true;\n";
|
|
|
|
OS << " }\n";
|
|
|
|
OS << " return false;\n";
|
|
|
|
}
|
|
|
|
OS << "}\n";
|
|
|
|
OS << "\n";
|
|
|
|
}
|
2017-07-05 14:39:13 +02:00
|
|
|
|
2017-10-11 11:17:43 +02:00
|
|
|
// Emit a function mapping match classes to strings, for debugging.
|
|
|
|
static void emitMatchClassKindNames(std::forward_list<ClassInfo> &Infos,
|
|
|
|
raw_ostream &OS) {
|
|
|
|
OS << "#ifndef NDEBUG\n";
|
|
|
|
OS << "const char *getMatchClassName(MatchClassKind Kind) {\n";
|
|
|
|
OS << " switch (Kind) {\n";
|
|
|
|
|
|
|
|
OS << " case InvalidMatchClass: return \"InvalidMatchClass\";\n";
|
|
|
|
OS << " case OptionalMatchClass: return \"OptionalMatchClass\";\n";
|
|
|
|
for (const auto &CI : Infos) {
|
|
|
|
OS << " case " << CI.Name << ": return \"" << CI.Name << "\";\n";
|
|
|
|
}
|
|
|
|
OS << " case NumMatchClassKinds: return \"NumMatchClassKinds\";\n";
|
|
|
|
|
|
|
|
OS << " }\n";
|
|
|
|
OS << " llvm_unreachable(\"unhandled MatchClassKind!\");\n";
|
|
|
|
OS << "}\n\n";
|
|
|
|
OS << "#endif // NDEBUG\n";
|
|
|
|
}
|
|
|
|
|
2019-03-11 18:04:35 +01:00
|
|
|
static std::string
|
|
|
|
getNameForFeatureBitset(const std::vector<Record *> &FeatureBitset) {
|
|
|
|
std::string Name = "AMFBS";
|
|
|
|
for (const auto &Feature : FeatureBitset)
|
|
|
|
Name += ("_" + Feature->getName()).str();
|
|
|
|
return Name;
|
|
|
|
}
|
|
|
|
|
2009-08-07 23:01:44 +02:00
|
|
|
void AsmMatcherEmitter::run(raw_ostream &OS) {
|
2010-12-13 01:23:57 +01:00
|
|
|
CodeGenTarget Target(Records);
|
2009-08-07 23:01:44 +02:00
|
|
|
Record *AsmParser = Target.getAsmParser();
|
2017-05-31 23:12:46 +02:00
|
|
|
StringRef ClassName = AsmParser->getValueAsString("AsmParserClassName");
|
2009-08-07 23:01:44 +02:00
|
|
|
|
2009-08-08 09:50:56 +02:00
|
|
|
// Compute the information on the instructions to match.
|
2010-12-13 01:23:57 +01:00
|
|
|
AsmMatcherInfo Info(AsmParser, Target, Records);
|
2012-04-19 19:52:32 +02:00
|
|
|
Info.buildInfo();
|
2009-08-07 10:26:05 +02:00
|
|
|
|
2010-02-03 00:46:36 +01:00
|
|
|
// Sort the instruction table using the partial order on classes. We use
|
|
|
|
// stable_sort to ensure that ambiguous instructions are still
|
|
|
|
// deterministically ordered.
|
2019-04-23 16:51:27 +02:00
|
|
|
llvm::stable_sort(
|
|
|
|
Info.Matchables,
|
|
|
|
[](const std::unique_ptr<MatchableInfo> &a,
|
|
|
|
const std::unique_ptr<MatchableInfo> &b) { return *a < *b; });
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2016-12-05 20:44:31 +01:00
|
|
|
#ifdef EXPENSIVE_CHECKS
|
|
|
|
// Verify that the table is sorted and operator < works transitively.
|
|
|
|
for (auto I = Info.Matchables.begin(), E = Info.Matchables.end(); I != E;
|
|
|
|
++I) {
|
|
|
|
for (auto J = I; J != E; ++J) {
|
|
|
|
assert(!(**J < **I));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-08-08 07:24:34 +02:00
|
|
|
DEBUG_WITH_TYPE("instruction_info", {
|
2014-11-28 04:53:02 +01:00
|
|
|
for (const auto &MI : Info.Matchables)
|
2014-11-29 00:00:22 +01:00
|
|
|
MI->dump();
|
2009-08-07 10:26:05 +02:00
|
|
|
});
|
|
|
|
|
2010-11-01 06:06:45 +01:00
|
|
|
// Check for ambiguous matchables.
|
2010-09-06 23:28:52 +02:00
|
|
|
DEBUG_WITH_TYPE("ambiguous_instrs", {
|
|
|
|
unsigned NumAmbiguous = 0;
|
2014-12-22 22:26:38 +01:00
|
|
|
for (auto I = Info.Matchables.begin(), E = Info.Matchables.end(); I != E;
|
|
|
|
++I) {
|
|
|
|
for (auto J = std::next(I); J != E; ++J) {
|
|
|
|
const MatchableInfo &A = **I;
|
|
|
|
const MatchableInfo &B = **J;
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2012-04-19 19:52:32 +02:00
|
|
|
if (A.couldMatchAmbiguouslyWith(B)) {
|
2010-11-01 06:06:45 +01:00
|
|
|
errs() << "warning: ambiguous matchables:\n";
|
2010-09-06 23:28:52 +02:00
|
|
|
A.dump();
|
|
|
|
errs() << "\nis incomparable with:\n";
|
|
|
|
B.dump();
|
|
|
|
errs() << "\n\n";
|
2010-09-06 22:21:47 +02:00
|
|
|
++NumAmbiguous;
|
|
|
|
}
|
2009-08-09 08:05:33 +02:00
|
|
|
}
|
2009-08-09 06:00:06 +02:00
|
|
|
}
|
2010-09-06 22:21:47 +02:00
|
|
|
if (NumAmbiguous)
|
2010-10-30 00:13:48 +02:00
|
|
|
errs() << "warning: " << NumAmbiguous
|
2010-11-01 06:06:45 +01:00
|
|
|
<< " ambiguous matchables!\n";
|
2010-09-06 23:28:52 +02:00
|
|
|
});
|
2009-08-09 06:00:06 +02:00
|
|
|
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
// Compute the information on the custom operand parsing.
|
2012-04-19 19:52:32 +02:00
|
|
|
Info.buildOperandMatchInfo();
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
|
2015-12-31 09:18:23 +01:00
|
|
|
bool HasMnemonicFirst = AsmParser->getValueAsBit("HasMnemonicFirst");
|
2016-05-06 13:31:17 +02:00
|
|
|
bool HasOptionalOperands = Info.hasOptionalOperands();
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
bool ReportMultipleNearMisses =
|
|
|
|
AsmParser->getValueAsBit("ReportMultipleNearMisses");
|
2015-12-31 09:18:23 +01:00
|
|
|
|
2009-08-12 01:23:44 +02:00
|
|
|
// Write the output.
|
|
|
|
|
2010-09-06 21:11:01 +02:00
|
|
|
// Information for the class declaration.
|
|
|
|
OS << "\n#ifdef GET_ASSEMBLER_HEADER\n";
|
|
|
|
OS << "#undef GET_ASSEMBLER_HEADER\n";
|
2011-02-11 22:31:55 +01:00
|
|
|
OS << " // This should be included into the middle of the declaration of\n";
|
2011-07-26 02:24:13 +02:00
|
|
|
OS << " // your subclasses implementation of MCTargetAsmParser.\n";
|
2020-11-06 15:19:59 +01:00
|
|
|
OS << " FeatureBitset ComputeAvailableFeatures(const FeatureBitset &FB) const;\n";
|
2016-05-06 13:31:17 +02:00
|
|
|
if (HasOptionalOperands) {
|
|
|
|
OS << " void convertToMCInst(unsigned Kind, MCInst &Inst, "
|
|
|
|
<< "unsigned Opcode,\n"
|
|
|
|
<< " const OperandVector &Operands,\n"
|
|
|
|
<< " const SmallBitVector &OptionalOperandsMask);\n";
|
|
|
|
} else {
|
|
|
|
OS << " void convertToMCInst(unsigned Kind, MCInst &Inst, "
|
|
|
|
<< "unsigned Opcode,\n"
|
|
|
|
<< " const OperandVector &Operands);\n";
|
|
|
|
}
|
2012-10-02 02:25:57 +02:00
|
|
|
OS << " void convertToMapAndConstraints(unsigned Kind,\n ";
|
2016-10-11 00:49:37 +02:00
|
|
|
OS << " const OperandVector &Operands) override;\n";
|
2015-01-03 09:16:29 +01:00
|
|
|
OS << " unsigned MatchInstructionImpl(const OperandVector &Operands,\n"
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
<< " MCInst &Inst,\n";
|
|
|
|
if (ReportMultipleNearMisses)
|
|
|
|
OS << " SmallVectorImpl<NearMissInfo> *NearMisses,\n";
|
|
|
|
else
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << " uint64_t &ErrorInfo,\n"
|
|
|
|
<< " FeatureBitset &MissingFeatures,\n";
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
OS << " bool matchingInlineAsm,\n"
|
2012-10-02 02:25:57 +02:00
|
|
|
<< " unsigned VariantID = 0);\n";
|
2019-03-11 18:04:35 +01:00
|
|
|
if (!ReportMultipleNearMisses)
|
|
|
|
OS << " unsigned MatchInstructionImpl(const OperandVector &Operands,\n"
|
|
|
|
<< " MCInst &Inst,\n"
|
|
|
|
<< " uint64_t &ErrorInfo,\n"
|
|
|
|
<< " bool matchingInlineAsm,\n"
|
|
|
|
<< " unsigned VariantID = 0) {\n"
|
|
|
|
<< " FeatureBitset MissingFeatures;\n"
|
|
|
|
<< " return MatchInstructionImpl(Operands, Inst, ErrorInfo, MissingFeatures,\n"
|
|
|
|
<< " matchingInlineAsm, VariantID);\n"
|
|
|
|
<< " }\n\n";
|
|
|
|
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
|
2015-01-15 12:41:30 +01:00
|
|
|
if (!Info.OperandMatchInfo.empty()) {
|
2011-02-12 02:34:40 +01:00
|
|
|
OS << " OperandMatchResultTy MatchOperandParserImpl(\n";
|
2014-06-08 18:18:35 +02:00
|
|
|
OS << " OperandVector &Operands,\n";
|
2017-12-20 12:02:42 +01:00
|
|
|
OS << " StringRef Mnemonic,\n";
|
|
|
|
OS << " bool ParseForAllFeatures = false);\n";
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
|
2011-12-06 23:07:02 +01:00
|
|
|
OS << " OperandMatchResultTy tryCustomParseOperand(\n";
|
2014-06-08 18:18:35 +02:00
|
|
|
OS << " OperandVector &Operands,\n";
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
OS << " unsigned MCK);\n\n";
|
|
|
|
}
|
|
|
|
|
2010-09-06 21:11:01 +02:00
|
|
|
OS << "#endif // GET_ASSEMBLER_HEADER_INFO\n\n";
|
|
|
|
|
2012-06-23 01:56:44 +02:00
|
|
|
// Emit the operand match diagnostic enum names.
|
|
|
|
OS << "\n#ifdef GET_OPERAND_DIAGNOSTIC_TYPES\n";
|
|
|
|
OS << "#undef GET_OPERAND_DIAGNOSTIC_TYPES\n\n";
|
|
|
|
emitOperandDiagnosticTypes(Info, OS);
|
|
|
|
OS << "#endif // GET_OPERAND_DIAGNOSTIC_TYPES\n\n";
|
|
|
|
|
2010-09-06 21:11:01 +02:00
|
|
|
OS << "\n#ifdef GET_REGISTER_MATCHER\n";
|
|
|
|
OS << "#undef GET_REGISTER_MATCHER\n\n";
|
|
|
|
|
2010-07-19 07:44:09 +02:00
|
|
|
// Emit the subtarget feature enumeration.
|
2019-03-11 18:04:35 +01:00
|
|
|
SubtargetFeatureInfo::emitSubtargetFeatureBitEnumeration(
|
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
|
|
|
Info.SubtargetFeatures, OS);
|
2010-07-19 07:44:09 +02:00
|
|
|
|
2009-08-12 01:23:44 +02:00
|
|
|
// Emit the function to match a register name to number.
|
2012-08-17 22:16:42 +02:00
|
|
|
// This should be omitted for Mips target
|
|
|
|
if (AsmParser->getValueAsBit("ShouldEmitMatchRegisterName"))
|
|
|
|
emitMatchRegisterName(Target, AsmParser, OS);
|
2010-09-06 21:11:01 +02:00
|
|
|
|
2016-02-03 11:30:16 +01:00
|
|
|
if (AsmParser->getValueAsBit("ShouldEmitMatchRegisterAltName"))
|
|
|
|
emitMatchRegisterAltName(Target, AsmParser, OS);
|
|
|
|
|
2010-09-06 21:11:01 +02:00
|
|
|
OS << "#endif // GET_REGISTER_MATCHER\n\n";
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2012-04-25 08:56:34 +02:00
|
|
|
OS << "\n#ifdef GET_SUBTARGET_FEATURE_NAME\n";
|
|
|
|
OS << "#undef GET_SUBTARGET_FEATURE_NAME\n\n";
|
2009-08-12 01:23:44 +02:00
|
|
|
|
2012-04-25 00:40:08 +02:00
|
|
|
// Generate the helper function to get the names for subtarget features.
|
|
|
|
emitGetSubtargetFeatureName(Info, OS);
|
|
|
|
|
2012-04-25 08:56:34 +02:00
|
|
|
OS << "#endif // GET_SUBTARGET_FEATURE_NAME\n\n";
|
|
|
|
|
|
|
|
OS << "\n#ifdef GET_MATCHER_IMPLEMENTATION\n";
|
|
|
|
OS << "#undef GET_MATCHER_IMPLEMENTATION\n\n";
|
|
|
|
|
2010-10-30 20:48:18 +02:00
|
|
|
// Generate the function that remaps for mnemonic aliases.
|
2013-04-19 00:35:36 +02:00
|
|
|
bool HasMnemonicAliases = emitMnemonicAliases(OS, Info, Target);
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2012-10-02 01:45:51 +02:00
|
|
|
// Generate the convertToMCInst function to convert operands into an MCInst.
|
|
|
|
// Also, generate the convertToMapAndConstraints function for MS-style inline
|
|
|
|
// assembly. The latter doesn't actually generate a MCInst.
|
2019-04-02 22:52:04 +02:00
|
|
|
unsigned NumConverters = emitConvertFuncs(Target, ClassName, Info.Matchables,
|
|
|
|
HasMnemonicFirst,
|
|
|
|
HasOptionalOperands, OS);
|
2009-08-08 09:50:56 +02:00
|
|
|
|
|
|
|
// Emit the enumeration for classes which participate in matching.
|
2012-04-19 19:52:32 +02:00
|
|
|
emitMatchClassEnumeration(Target, Info.Classes, OS);
|
2009-08-07 10:26:05 +02:00
|
|
|
|
2017-10-03 16:34:57 +02:00
|
|
|
// Emit a function to get the user-visible string to describe an operand
|
|
|
|
// match failure in diagnostics.
|
|
|
|
emitOperandMatchErrorDiagStrings(Info, OS);
|
|
|
|
|
2017-10-10 13:00:40 +02:00
|
|
|
// Emit a function to map register classes to operand match failure codes.
|
|
|
|
emitRegisterMatchErrorFunc(Info, OS);
|
|
|
|
|
2009-08-08 09:50:56 +02:00
|
|
|
// Emit the routine to match token strings to their match class.
|
2012-04-19 19:52:32 +02:00
|
|
|
emitMatchTokenString(Target, Info.Classes, OS);
|
2009-08-07 10:26:05 +02:00
|
|
|
|
2009-08-10 18:05:47 +02:00
|
|
|
// Emit the subclass predicate routine.
|
2012-04-19 19:52:32 +02:00
|
|
|
emitIsSubclass(Target, Info.Classes, OS);
|
2009-08-10 18:05:47 +02:00
|
|
|
|
2011-02-10 01:08:28 +01:00
|
|
|
// Emit the routine to validate an operand against a match class.
|
2012-04-19 19:52:32 +02:00
|
|
|
emitValidateOperandClass(Info, OS);
|
2011-02-10 01:08:28 +01:00
|
|
|
|
2017-10-11 11:17:43 +02:00
|
|
|
emitMatchClassKindNames(Info.Classes, OS);
|
|
|
|
|
2010-07-19 07:44:09 +02:00
|
|
|
// Emit the available features compute function.
|
[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
|
|
|
SubtargetFeatureInfo::emitComputeAssemblerAvailableFeatures(
|
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
|
|
|
Info.Target.getName(), ClassName, "ComputeAvailableFeatures",
|
|
|
|
Info.SubtargetFeatures, OS);
|
2010-07-19 07:44:09 +02:00
|
|
|
|
2018-01-10 11:10:56 +01:00
|
|
|
if (!ReportMultipleNearMisses)
|
|
|
|
emitAsmTiedOperandConstraints(Target, Info, OS);
|
|
|
|
|
2012-09-18 08:10:45 +02:00
|
|
|
StringToOffsetTable StringTable;
|
|
|
|
|
2009-08-08 09:50:56 +02:00
|
|
|
size_t MaxNumOperands = 0;
|
2012-09-18 08:10:45 +02:00
|
|
|
unsigned MaxMnemonicIndex = 0;
|
2013-09-12 12:28:05 +02:00
|
|
|
bool HasDeprecation = false;
|
2014-11-28 04:53:02 +01:00
|
|
|
for (const auto &MI : Info.Matchables) {
|
2014-11-29 00:00:22 +01:00
|
|
|
MaxNumOperands = std::max(MaxNumOperands, MI->AsmOperands.size());
|
|
|
|
HasDeprecation |= MI->HasDeprecation;
|
2012-09-18 08:10:45 +02:00
|
|
|
|
|
|
|
// Store a pascal-style length byte in the mnemonic.
|
2020-08-13 00:22:58 +02:00
|
|
|
std::string LenMnemonic = char(MI->Mnemonic.size()) + MI->Mnemonic.lower();
|
2012-09-18 08:10:45 +02:00
|
|
|
MaxMnemonicIndex = std::max(MaxMnemonicIndex,
|
|
|
|
StringTable.GetOrAddStringOffset(LenMnemonic, false));
|
|
|
|
}
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2012-09-18 09:02:21 +02:00
|
|
|
OS << "static const char *const MnemonicTable =\n";
|
|
|
|
StringTable.EmitString(OS);
|
|
|
|
OS << ";\n\n";
|
|
|
|
|
2019-03-11 18:04:35 +01:00
|
|
|
std::vector<std::vector<Record *>> FeatureBitsets;
|
|
|
|
for (const auto &MI : Info.Matchables) {
|
|
|
|
if (MI->RequiredFeatures.empty())
|
|
|
|
continue;
|
|
|
|
FeatureBitsets.emplace_back();
|
|
|
|
for (unsigned I = 0, E = MI->RequiredFeatures.size(); I != E; ++I)
|
|
|
|
FeatureBitsets.back().push_back(MI->RequiredFeatures[I]->TheDef);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::sort(FeatureBitsets, [&](const std::vector<Record *> &A,
|
|
|
|
const std::vector<Record *> &B) {
|
|
|
|
if (A.size() < B.size())
|
|
|
|
return true;
|
|
|
|
if (A.size() > B.size())
|
|
|
|
return false;
|
2019-12-22 18:58:32 +01:00
|
|
|
for (auto Pair : zip(A, B)) {
|
2019-03-11 18:04:35 +01:00
|
|
|
if (std::get<0>(Pair)->getName() < std::get<1>(Pair)->getName())
|
|
|
|
return true;
|
|
|
|
if (std::get<0>(Pair)->getName() > std::get<1>(Pair)->getName())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
FeatureBitsets.erase(
|
|
|
|
std::unique(FeatureBitsets.begin(), FeatureBitsets.end()),
|
|
|
|
FeatureBitsets.end());
|
|
|
|
OS << "// Feature bitsets.\n"
|
|
|
|
<< "enum : " << getMinimalTypeForRange(FeatureBitsets.size()) << " {\n"
|
|
|
|
<< " AMFBS_None,\n";
|
|
|
|
for (const auto &FeatureBitset : FeatureBitsets) {
|
|
|
|
if (FeatureBitset.empty())
|
|
|
|
continue;
|
|
|
|
OS << " " << getNameForFeatureBitset(FeatureBitset) << ",\n";
|
|
|
|
}
|
|
|
|
OS << "};\n\n"
|
2019-08-24 17:02:44 +02:00
|
|
|
<< "static constexpr FeatureBitset FeatureBitsets[] = {\n"
|
2019-03-11 18:04:35 +01:00
|
|
|
<< " {}, // AMFBS_None\n";
|
|
|
|
for (const auto &FeatureBitset : FeatureBitsets) {
|
|
|
|
if (FeatureBitset.empty())
|
|
|
|
continue;
|
|
|
|
OS << " {";
|
|
|
|
for (const auto &Feature : FeatureBitset) {
|
|
|
|
const auto &I = Info.SubtargetFeatures.find(Feature);
|
|
|
|
assert(I != Info.SubtargetFeatures.end() && "Didn't import predicate?");
|
|
|
|
OS << I->second.getEnumBitName() << ", ";
|
|
|
|
}
|
|
|
|
OS << "},\n";
|
|
|
|
}
|
|
|
|
OS << "};\n\n";
|
|
|
|
|
2017-03-31 12:59:37 +02:00
|
|
|
// Emit the static match table; unused classes get initialized to 0 which is
|
2009-08-08 09:50:56 +02:00
|
|
|
// guaranteed to be InvalidMatchClass.
|
|
|
|
//
|
|
|
|
// FIXME: We can reduce the size of this table very easily. First, we change
|
|
|
|
// it so that store the kinds in separate bit-fields for each index, which
|
|
|
|
// only needs to be the max width used for classes at that index (we also need
|
|
|
|
// to reject based on this during classification). If we then make sure to
|
|
|
|
// order the match kinds appropriately (putting mnemonics last), then we
|
|
|
|
// should only end up using a few bits for each class, especially the ones
|
|
|
|
// following the mnemonic.
|
2010-09-06 23:08:38 +02:00
|
|
|
OS << "namespace {\n";
|
|
|
|
OS << " struct MatchEntry {\n";
|
2012-09-18 08:10:45 +02:00
|
|
|
OS << " " << getMinimalTypeForRange(MaxMnemonicIndex)
|
|
|
|
<< " Mnemonic;\n";
|
2012-03-03 20:13:26 +01:00
|
|
|
OS << " uint16_t Opcode;\n";
|
2019-04-02 22:52:04 +02:00
|
|
|
OS << " " << getMinimalTypeForRange(NumConverters)
|
2014-11-29 00:00:22 +01:00
|
|
|
<< " ConvertFn;\n";
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << " " << getMinimalTypeForRange(FeatureBitsets.size())
|
|
|
|
<< " RequiredFeaturesIdx;\n";
|
2014-11-28 21:35:57 +01:00
|
|
|
OS << " " << getMinimalTypeForRange(
|
|
|
|
std::distance(Info.Classes.begin(), Info.Classes.end()))
|
|
|
|
<< " Classes[" << MaxNumOperands << "];\n";
|
2012-03-03 20:13:26 +01:00
|
|
|
OS << " StringRef getMnemonic() const {\n";
|
|
|
|
OS << " return StringRef(MnemonicTable + Mnemonic + 1,\n";
|
|
|
|
OS << " MnemonicTable[Mnemonic]);\n";
|
|
|
|
OS << " }\n";
|
2010-09-06 23:22:45 +02:00
|
|
|
OS << " };\n\n";
|
2010-10-30 00:13:48 +02:00
|
|
|
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
OS << " // Predicate for searching for an opcode.\n";
|
2010-09-06 23:22:45 +02:00
|
|
|
OS << " struct LessOpcode {\n";
|
|
|
|
OS << " bool operator()(const MatchEntry &LHS, StringRef RHS) {\n";
|
2012-03-03 20:13:26 +01:00
|
|
|
OS << " return LHS.getMnemonic() < RHS;\n";
|
2010-09-06 23:22:45 +02:00
|
|
|
OS << " }\n";
|
|
|
|
OS << " bool operator()(StringRef LHS, const MatchEntry &RHS) {\n";
|
2012-03-03 20:13:26 +01:00
|
|
|
OS << " return LHS < RHS.getMnemonic();\n";
|
2010-09-06 23:22:45 +02:00
|
|
|
OS << " }\n";
|
2010-09-07 08:10:48 +02:00
|
|
|
OS << " bool operator()(const MatchEntry &LHS, const MatchEntry &RHS) {\n";
|
2012-03-03 20:13:26 +01:00
|
|
|
OS << " return LHS.getMnemonic() < RHS.getMnemonic();\n";
|
2010-09-07 08:10:48 +02:00
|
|
|
OS << " }\n";
|
2010-09-06 23:08:38 +02:00
|
|
|
OS << " };\n";
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2019-08-25 12:47:30 +02:00
|
|
|
OS << "} // end anonymous namespace\n\n";
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2013-07-24 09:33:14 +02:00
|
|
|
unsigned VariantCount = Target.getAsmParserVariantCount();
|
|
|
|
for (unsigned VC = 0; VC != VariantCount; ++VC) {
|
|
|
|
Record *AsmVariant = Target.getAsmParserVariant(VC);
|
|
|
|
int AsmVariantNo = AsmVariant->getValueAsInt("Variant");
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2013-07-24 09:33:14 +02:00
|
|
|
OS << "static const MatchEntry MatchTable" << VC << "[] = {\n";
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2014-11-28 04:53:02 +01:00
|
|
|
for (const auto &MI : Info.Matchables) {
|
2014-11-29 00:00:22 +01:00
|
|
|
if (MI->AsmVariantID != AsmVariantNo)
|
2013-07-24 09:33:14 +02:00
|
|
|
continue;
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2013-07-24 09:33:14 +02:00
|
|
|
// Store a pascal-style length byte in the mnemonic.
|
2020-08-13 00:22:58 +02:00
|
|
|
std::string LenMnemonic =
|
|
|
|
char(MI->Mnemonic.size()) + MI->Mnemonic.lower();
|
2013-07-24 09:33:14 +02:00
|
|
|
OS << " { " << StringTable.GetOrAddStringOffset(LenMnemonic, false)
|
2014-11-29 00:00:22 +01:00
|
|
|
<< " /* " << MI->Mnemonic << " */, "
|
2017-07-07 07:19:25 +02:00
|
|
|
<< Target.getInstNamespace() << "::"
|
2014-11-29 00:00:22 +01:00
|
|
|
<< MI->getResultInst()->TheDef->getName() << ", "
|
|
|
|
<< MI->ConversionFnKind << ", ";
|
2013-07-24 09:33:14 +02:00
|
|
|
|
|
|
|
// Write the required features mask.
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << "AMFBS";
|
|
|
|
if (MI->RequiredFeatures.empty())
|
|
|
|
OS << "_None";
|
|
|
|
else
|
|
|
|
for (unsigned i = 0, e = MI->RequiredFeatures.size(); i != e; ++i)
|
|
|
|
OS << '_' << MI->RequiredFeatures[i]->TheDef->getName();
|
2012-04-02 09:48:39 +02:00
|
|
|
|
2013-07-24 09:33:14 +02:00
|
|
|
OS << ", { ";
|
2021-02-14 05:41:36 +01:00
|
|
|
ListSeparator LS;
|
|
|
|
for (const MatchableInfo::AsmOperand &Op : MI->AsmOperands)
|
|
|
|
OS << LS << Op.Class->Name;
|
2013-07-24 09:33:14 +02:00
|
|
|
OS << " }, },\n";
|
2012-04-02 09:48:39 +02:00
|
|
|
}
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2013-07-24 09:33:14 +02:00
|
|
|
OS << "};\n\n";
|
|
|
|
}
|
2009-08-08 09:50:56 +02:00
|
|
|
|
2017-10-11 11:17:43 +02:00
|
|
|
OS << "#include \"llvm/Support/Debug.h\"\n";
|
|
|
|
OS << "#include \"llvm/Support/Format.h\"\n\n";
|
|
|
|
|
2010-09-06 23:08:38 +02:00
|
|
|
// Finally, build the match function.
|
2014-06-08 18:18:35 +02:00
|
|
|
OS << "unsigned " << Target.getName() << ClassName << "::\n"
|
2015-01-03 09:16:29 +01:00
|
|
|
<< "MatchInstructionImpl(const OperandVector &Operands,\n";
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
OS << " MCInst &Inst,\n";
|
|
|
|
if (ReportMultipleNearMisses)
|
|
|
|
OS << " SmallVectorImpl<NearMissInfo> *NearMisses,\n";
|
|
|
|
else
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << " uint64_t &ErrorInfo,\n"
|
|
|
|
<< " FeatureBitset &MissingFeatures,\n";
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
OS << " bool matchingInlineAsm, unsigned VariantID) {\n";
|
|
|
|
|
|
|
|
if (!ReportMultipleNearMisses) {
|
|
|
|
OS << " // Eliminate obvious mismatches.\n";
|
|
|
|
OS << " if (Operands.size() > "
|
|
|
|
<< (MaxNumOperands + HasMnemonicFirst) << ") {\n";
|
|
|
|
OS << " ErrorInfo = "
|
|
|
|
<< (MaxNumOperands + HasMnemonicFirst) << ";\n";
|
|
|
|
OS << " return Match_InvalidOperand;\n";
|
|
|
|
OS << " }\n\n";
|
|
|
|
}
|
2012-08-30 23:43:05 +02:00
|
|
|
|
2010-07-19 07:44:09 +02:00
|
|
|
// Emit code to get the available features.
|
|
|
|
OS << " // Get the current feature set.\n";
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << " const FeatureBitset &AvailableFeatures = getAvailableFeatures();\n\n";
|
2010-07-19 07:44:09 +02:00
|
|
|
|
2010-10-30 19:36:36 +02:00
|
|
|
OS << " // Get the instruction mnemonic, which is the first token.\n";
|
2015-12-31 09:18:23 +01:00
|
|
|
if (HasMnemonicFirst) {
|
|
|
|
OS << " StringRef Mnemonic = ((" << Target.getName()
|
2020-11-06 15:19:59 +01:00
|
|
|
<< "Operand &)*Operands[0]).getToken();\n\n";
|
2015-12-31 09:18:23 +01:00
|
|
|
} else {
|
|
|
|
OS << " StringRef Mnemonic;\n";
|
|
|
|
OS << " if (Operands[0]->isToken())\n";
|
|
|
|
OS << " Mnemonic = ((" << Target.getName()
|
2020-11-06 15:19:59 +01:00
|
|
|
<< "Operand &)*Operands[0]).getToken();\n\n";
|
2015-12-31 09:18:23 +01:00
|
|
|
}
|
2010-10-30 19:36:36 +02:00
|
|
|
|
2010-10-30 20:48:18 +02:00
|
|
|
if (HasMnemonicAliases) {
|
|
|
|
OS << " // Process all MnemonicAliases to remap the mnemonic.\n";
|
2013-04-19 00:35:36 +02:00
|
|
|
OS << " applyMnemonicAliases(Mnemonic, AvailableFeatures, VariantID);\n\n";
|
2010-10-30 20:48:18 +02:00
|
|
|
}
|
2011-01-26 22:26:19 +01:00
|
|
|
|
2009-08-08 09:50:56 +02:00
|
|
|
// Emit code to compute the class list for this operand vector.
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
if (!ReportMultipleNearMisses) {
|
|
|
|
OS << " // Some state to try to produce better error messages.\n";
|
|
|
|
OS << " bool HadMatchOtherThanFeatures = false;\n";
|
|
|
|
OS << " bool HadMatchOtherThanPredicate = false;\n";
|
|
|
|
OS << " unsigned RetCode = Match_InvalidOperand;\n";
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << " MissingFeatures.set();\n";
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
OS << " // Set ErrorInfo to the operand that mismatches if it is\n";
|
|
|
|
OS << " // wrong for all instances of the instruction.\n";
|
|
|
|
OS << " ErrorInfo = ~0ULL;\n";
|
|
|
|
}
|
|
|
|
|
2016-05-06 13:31:17 +02:00
|
|
|
if (HasOptionalOperands) {
|
|
|
|
OS << " SmallBitVector OptionalOperandsMask(" << MaxNumOperands << ");\n";
|
|
|
|
}
|
2010-09-06 23:22:45 +02:00
|
|
|
|
2009-08-08 09:50:56 +02:00
|
|
|
// Emit code to search the table.
|
2013-07-24 09:33:14 +02:00
|
|
|
OS << " // Find the appropriate table for this asm variant.\n";
|
|
|
|
OS << " const MatchEntry *Start, *End;\n";
|
|
|
|
OS << " switch (VariantID) {\n";
|
2015-01-03 09:16:14 +01:00
|
|
|
OS << " default: llvm_unreachable(\"invalid variant!\");\n";
|
2013-07-24 09:33:14 +02:00
|
|
|
for (unsigned VC = 0; VC != VariantCount; ++VC) {
|
|
|
|
Record *AsmVariant = Target.getAsmParserVariant(VC);
|
|
|
|
int AsmVariantNo = AsmVariant->getValueAsInt("Variant");
|
2014-04-12 18:15:53 +02:00
|
|
|
OS << " case " << AsmVariantNo << ": Start = std::begin(MatchTable" << VC
|
|
|
|
<< "); End = std::end(MatchTable" << VC << "); break;\n";
|
2013-07-24 09:33:14 +02:00
|
|
|
}
|
|
|
|
OS << " }\n";
|
2015-12-31 09:18:23 +01:00
|
|
|
|
2009-08-08 09:50:56 +02:00
|
|
|
OS << " // Search the table.\n";
|
2015-12-31 09:18:23 +01:00
|
|
|
if (HasMnemonicFirst) {
|
|
|
|
OS << " auto MnemonicRange = "
|
|
|
|
"std::equal_range(Start, End, Mnemonic, LessOpcode());\n\n";
|
|
|
|
} else {
|
|
|
|
OS << " auto MnemonicRange = std::make_pair(Start, End);\n";
|
|
|
|
OS << " unsigned SIndex = Mnemonic.empty() ? 0 : 1;\n";
|
|
|
|
OS << " if (!Mnemonic.empty())\n";
|
|
|
|
OS << " MnemonicRange = "
|
|
|
|
"std::equal_range(Start, End, Mnemonic.lower(), LessOpcode());\n\n";
|
|
|
|
}
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2017-10-11 11:17:43 +02:00
|
|
|
OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"AsmMatcher: found \" <<\n"
|
2020-11-06 15:19:59 +01:00
|
|
|
<< " std::distance(MnemonicRange.first, MnemonicRange.second) <<\n"
|
2017-10-11 11:17:43 +02:00
|
|
|
<< " \" encodings with mnemonic '\" << Mnemonic << \"'\\n\");\n\n";
|
|
|
|
|
2010-09-06 23:54:15 +02:00
|
|
|
OS << " // Return a more specific error code if no mnemonics match.\n";
|
|
|
|
OS << " if (MnemonicRange.first == MnemonicRange.second)\n";
|
|
|
|
OS << " return Match_MnemonicFail;\n\n";
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2010-09-06 23:22:45 +02:00
|
|
|
OS << " for (const MatchEntry *it = MnemonicRange.first, "
|
2010-09-06 23:23:43 +02:00
|
|
|
<< "*ie = MnemonicRange.second;\n";
|
2010-09-06 23:22:45 +02:00
|
|
|
OS << " it != ie; ++it) {\n";
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << " const FeatureBitset &RequiredFeatures = "
|
|
|
|
"FeatureBitsets[it->RequiredFeaturesIdx];\n";
|
2017-12-20 12:02:42 +01:00
|
|
|
OS << " bool HasRequiredFeatures =\n";
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << " (AvailableFeatures & RequiredFeatures) == RequiredFeatures;\n";
|
2017-10-11 11:17:43 +02:00
|
|
|
OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Trying to match opcode \"\n";
|
|
|
|
OS << " << MII.getName(it->Opcode) << \"\\n\");\n";
|
|
|
|
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
if (ReportMultipleNearMisses) {
|
|
|
|
OS << " // Some state to record ways in which this instruction did not match.\n";
|
|
|
|
OS << " NearMissInfo OperandNearMiss = NearMissInfo::getSuccess();\n";
|
|
|
|
OS << " NearMissInfo FeaturesNearMiss = NearMissInfo::getSuccess();\n";
|
|
|
|
OS << " NearMissInfo EarlyPredicateNearMiss = NearMissInfo::getSuccess();\n";
|
|
|
|
OS << " NearMissInfo LatePredicateNearMiss = NearMissInfo::getSuccess();\n";
|
2017-12-04 14:42:22 +01:00
|
|
|
OS << " bool MultipleInvalidOperands = false;\n";
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
}
|
|
|
|
|
2015-12-31 09:18:23 +01:00
|
|
|
if (HasMnemonicFirst) {
|
|
|
|
OS << " // equal_range guarantees that instruction mnemonic matches.\n";
|
|
|
|
OS << " assert(Mnemonic == it->getMnemonic());\n";
|
|
|
|
}
|
|
|
|
|
2010-07-19 07:44:09 +02:00
|
|
|
// Emit check that the subclasses match.
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
if (!ReportMultipleNearMisses)
|
|
|
|
OS << " bool OperandsValid = true;\n";
|
2016-05-06 13:31:17 +02:00
|
|
|
if (HasOptionalOperands) {
|
|
|
|
OS << " OptionalOperandsMask.reset(0, " << MaxNumOperands << ");\n";
|
|
|
|
}
|
2016-03-01 09:34:43 +01:00
|
|
|
OS << " for (unsigned FormalIdx = " << (HasMnemonicFirst ? "0" : "SIndex")
|
|
|
|
<< ", ActualIdx = " << (HasMnemonicFirst ? "1" : "SIndex")
|
|
|
|
<< "; FormalIdx != " << MaxNumOperands << "; ++FormalIdx) {\n";
|
|
|
|
OS << " auto Formal = "
|
|
|
|
<< "static_cast<MatchClassKind>(it->Classes[FormalIdx]);\n";
|
2017-10-11 11:17:43 +02:00
|
|
|
OS << " DEBUG_WITH_TYPE(\"asm-matcher\",\n";
|
|
|
|
OS << " dbgs() << \" Matching formal operand class \" << getMatchClassName(Formal)\n";
|
|
|
|
OS << " << \" against actual operand at index \" << ActualIdx);\n";
|
|
|
|
OS << " if (ActualIdx < Operands.size())\n";
|
|
|
|
OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \" (\";\n";
|
|
|
|
OS << " Operands[ActualIdx]->print(dbgs()); dbgs() << \"): \");\n";
|
|
|
|
OS << " else\n";
|
|
|
|
OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \": \");\n";
|
2016-03-01 09:34:43 +01:00
|
|
|
OS << " if (ActualIdx >= Operands.size()) {\n";
|
2017-10-11 11:17:43 +02:00
|
|
|
OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"actual operand index out of range \");\n";
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
if (ReportMultipleNearMisses) {
|
|
|
|
OS << " bool ThisOperandValid = (Formal == " <<"InvalidMatchClass) || "
|
|
|
|
"isSubclass(Formal, OptionalMatchClass);\n";
|
|
|
|
OS << " if (!ThisOperandValid) {\n";
|
|
|
|
OS << " if (!OperandNearMiss) {\n";
|
|
|
|
OS << " // Record info about match failure for later use.\n";
|
2017-10-11 11:17:43 +02:00
|
|
|
OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"recording too-few-operands near miss\\n\");\n";
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
OS << " OperandNearMiss =\n";
|
|
|
|
OS << " NearMissInfo::getTooFewOperands(Formal, it->Opcode);\n";
|
2017-11-21 16:16:50 +01:00
|
|
|
OS << " } else if (OperandNearMiss.getKind() != NearMissInfo::NearMissTooFewOperands) {\n";
|
2017-12-04 14:42:22 +01:00
|
|
|
OS << " // If more than one operand is invalid, give up on this match entry.\n";
|
2017-10-11 11:17:43 +02:00
|
|
|
OS << " DEBUG_WITH_TYPE(\n";
|
|
|
|
OS << " \"asm-matcher\",\n";
|
|
|
|
OS << " dbgs() << \"second invalid operand, giving up on this opcode\\n\");\n";
|
2017-12-04 14:42:22 +01:00
|
|
|
OS << " MultipleInvalidOperands = true;\n";
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
OS << " break;\n";
|
|
|
|
OS << " }\n";
|
2017-10-11 11:17:43 +02:00
|
|
|
OS << " } else {\n";
|
|
|
|
OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"but formal operand not required\\n\");\n";
|
2017-11-21 16:12:05 +01:00
|
|
|
OS << " break;\n";
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
OS << " }\n";
|
|
|
|
OS << " continue;\n";
|
|
|
|
} else {
|
|
|
|
OS << " OperandsValid = (Formal == InvalidMatchClass) || isSubclass(Formal, OptionalMatchClass);\n";
|
|
|
|
OS << " if (!OperandsValid) ErrorInfo = ActualIdx;\n";
|
|
|
|
if (HasOptionalOperands) {
|
|
|
|
OS << " OptionalOperandsMask.set(FormalIdx, " << MaxNumOperands
|
|
|
|
<< ");\n";
|
|
|
|
}
|
|
|
|
OS << " break;\n";
|
2016-05-06 13:31:17 +02:00
|
|
|
}
|
2011-02-10 01:08:28 +01:00
|
|
|
OS << " }\n";
|
2016-03-01 09:34:43 +01:00
|
|
|
OS << " MCParsedAsmOperand &Actual = *Operands[ActualIdx];\n";
|
2015-11-09 01:46:46 +01:00
|
|
|
OS << " unsigned Diag = validateOperandClass(Actual, Formal);\n";
|
2016-03-01 09:34:43 +01:00
|
|
|
OS << " if (Diag == Match_Success) {\n";
|
2017-10-11 11:17:43 +02:00
|
|
|
OS << " DEBUG_WITH_TYPE(\"asm-matcher\",\n";
|
|
|
|
OS << " dbgs() << \"match success using generic matcher\\n\");\n";
|
2016-03-01 09:34:43 +01:00
|
|
|
OS << " ++ActualIdx;\n";
|
2010-09-07 00:11:18 +02:00
|
|
|
OS << " continue;\n";
|
2016-03-01 09:34:43 +01:00
|
|
|
OS << " }\n";
|
2013-02-06 07:00:06 +01:00
|
|
|
OS << " // If the generic handler indicates an invalid operand\n";
|
|
|
|
OS << " // failure, check for a special case.\n";
|
2017-10-10 13:00:40 +02:00
|
|
|
OS << " if (Diag != Match_Success) {\n";
|
|
|
|
OS << " unsigned TargetDiag = validateTargetOperandClass(Actual, Formal);\n";
|
|
|
|
OS << " if (TargetDiag == Match_Success) {\n";
|
2017-10-11 11:17:43 +02:00
|
|
|
OS << " DEBUG_WITH_TYPE(\"asm-matcher\",\n";
|
|
|
|
OS << " dbgs() << \"match success using target matcher\\n\");\n";
|
2016-03-01 09:34:43 +01:00
|
|
|
OS << " ++ActualIdx;\n";
|
2013-02-06 07:00:06 +01:00
|
|
|
OS << " continue;\n";
|
2016-03-01 09:34:43 +01:00
|
|
|
OS << " }\n";
|
2017-10-10 13:00:40 +02:00
|
|
|
OS << " // If the target matcher returned a specific error code use\n";
|
|
|
|
OS << " // that, else use the one from the generic matcher.\n";
|
2017-12-20 12:02:42 +01:00
|
|
|
OS << " if (TargetDiag != Match_InvalidOperand && "
|
|
|
|
"HasRequiredFeatures)\n";
|
2017-10-10 13:00:40 +02:00
|
|
|
OS << " Diag = TargetDiag;\n";
|
2013-02-06 07:00:06 +01:00
|
|
|
OS << " }\n";
|
2016-03-01 09:34:43 +01:00
|
|
|
OS << " // If current formal operand wasn't matched and it is optional\n"
|
|
|
|
<< " // then try to match next formal operand\n";
|
|
|
|
OS << " if (Diag == Match_InvalidOperand "
|
2016-05-06 13:31:17 +02:00
|
|
|
<< "&& isSubclass(Formal, OptionalMatchClass)) {\n";
|
|
|
|
if (HasOptionalOperands) {
|
|
|
|
OS << " OptionalOperandsMask.set(FormalIdx);\n";
|
|
|
|
}
|
2017-10-11 11:17:43 +02:00
|
|
|
OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"ignoring optional operand\\n\");\n";
|
2016-03-01 09:34:43 +01:00
|
|
|
OS << " continue;\n";
|
2016-05-06 13:31:17 +02:00
|
|
|
OS << " }\n";
|
2010-10-30 00:13:48 +02:00
|
|
|
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
if (ReportMultipleNearMisses) {
|
|
|
|
OS << " if (!OperandNearMiss) {\n";
|
|
|
|
OS << " // If this is the first invalid operand we have seen, record some\n";
|
|
|
|
OS << " // information about it.\n";
|
2017-10-11 11:17:43 +02:00
|
|
|
OS << " DEBUG_WITH_TYPE(\n";
|
|
|
|
OS << " \"asm-matcher\",\n";
|
|
|
|
OS << " dbgs()\n";
|
|
|
|
OS << " << \"operand match failed, recording near-miss with diag code \"\n";
|
|
|
|
OS << " << Diag << \"\\n\");\n";
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
OS << " OperandNearMiss =\n";
|
|
|
|
OS << " NearMissInfo::getMissedOperand(Diag, Formal, it->Opcode, ActualIdx);\n";
|
|
|
|
OS << " ++ActualIdx;\n";
|
|
|
|
OS << " } else {\n";
|
|
|
|
OS << " // If more than one operand is invalid, give up on this match entry.\n";
|
2017-10-11 11:17:43 +02:00
|
|
|
OS << " DEBUG_WITH_TYPE(\n";
|
|
|
|
OS << " \"asm-matcher\",\n";
|
|
|
|
OS << " dbgs() << \"second operand mismatch, skipping this opcode\\n\");\n";
|
2017-12-04 14:42:22 +01:00
|
|
|
OS << " MultipleInvalidOperands = true;\n";
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
OS << " break;\n";
|
|
|
|
OS << " }\n";
|
|
|
|
OS << " }\n\n";
|
|
|
|
} else {
|
|
|
|
OS << " // If this operand is broken for all of the instances of this\n";
|
|
|
|
OS << " // mnemonic, keep track of it so we can report loc info.\n";
|
|
|
|
OS << " // If we already had a match that only failed due to a\n";
|
|
|
|
OS << " // target predicate, that diagnostic is preferred.\n";
|
|
|
|
OS << " if (!HadMatchOtherThanPredicate &&\n";
|
|
|
|
OS << " (it == MnemonicRange.first || ErrorInfo <= ActualIdx)) {\n";
|
2017-12-20 12:02:42 +01:00
|
|
|
OS << " if (HasRequiredFeatures && (ErrorInfo != ActualIdx || Diag "
|
|
|
|
"!= Match_InvalidOperand))\n";
|
2017-11-21 16:07:43 +01:00
|
|
|
OS << " RetCode = Diag;\n";
|
2017-12-14 17:09:48 +01:00
|
|
|
OS << " ErrorInfo = ActualIdx;\n";
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
OS << " }\n";
|
|
|
|
OS << " // Otherwise, just reject this instance of the mnemonic.\n";
|
|
|
|
OS << " OperandsValid = false;\n";
|
|
|
|
OS << " break;\n";
|
|
|
|
OS << " }\n\n";
|
|
|
|
}
|
|
|
|
|
2017-12-04 14:42:22 +01:00
|
|
|
if (ReportMultipleNearMisses)
|
|
|
|
OS << " if (MultipleInvalidOperands) {\n";
|
|
|
|
else
|
2017-10-11 11:17:43 +02:00
|
|
|
OS << " if (!OperandsValid) {\n";
|
2017-12-04 14:42:22 +01:00
|
|
|
OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Opcode result: multiple \"\n";
|
|
|
|
OS << " \"operand mismatches, ignoring \"\n";
|
|
|
|
OS << " \"this opcode\\n\");\n";
|
|
|
|
OS << " continue;\n";
|
|
|
|
OS << " }\n";
|
2010-09-06 22:08:02 +02:00
|
|
|
|
|
|
|
// Emit check that the required features are available.
|
2017-12-20 12:02:42 +01:00
|
|
|
OS << " if (!HasRequiredFeatures) {\n";
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
if (!ReportMultipleNearMisses)
|
|
|
|
OS << " HadMatchOtherThanFeatures = true;\n";
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << " FeatureBitset NewMissingFeatures = RequiredFeatures & "
|
2012-06-18 21:45:46 +02:00
|
|
|
"~AvailableFeatures;\n";
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Missing target features:\";\n";
|
2020-11-06 15:19:59 +01:00
|
|
|
OS << " for (unsigned I = 0, E = NewMissingFeatures.size(); I != E; ++I)\n";
|
|
|
|
OS << " if (NewMissingFeatures[I])\n";
|
|
|
|
OS << " dbgs() << ' ' << I;\n";
|
|
|
|
OS << " dbgs() << \"\\n\");\n";
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
if (ReportMultipleNearMisses) {
|
|
|
|
OS << " FeaturesNearMiss = NearMissInfo::getMissedFeature(NewMissingFeatures);\n";
|
|
|
|
} else {
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << " if (NewMissingFeatures.count() <=\n"
|
|
|
|
" MissingFeatures.count())\n";
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
OS << " MissingFeatures = NewMissingFeatures;\n";
|
|
|
|
OS << " continue;\n";
|
|
|
|
}
|
2010-09-06 22:08:02 +02:00
|
|
|
OS << " }\n";
|
2009-08-08 09:50:56 +02:00
|
|
|
OS << "\n";
|
2014-12-16 19:05:28 +01:00
|
|
|
OS << " Inst.clear();\n\n";
|
[mips][ias] Check '$rs = $rd' constraints when both registers are in AsmText.
Summary:
This is one possible solution to the problem of ignoring constraints that Simon
raised in D21473 but it's a bit of a hack.
The integrated assembler currently ignores violations of the tied register
constraints when the operands involved in a tie are both present in the AsmText.
For example, 'dati $rs, $rt, $imm' with the '$rs = $rt' will silently replace
$rt with $rs. So 'dati $2, $3, 1' is processed as if the user provided
'dati $2, $2, 1' without any diagnostic being emitted.
This is difficult to solve properly because there are multiple parts of the
matcher that are silently forcing these constraints to be met. Tied operands are
rendered to instructions by cloning previously rendered operands but this is
unnecessary because the matcher was already instructed to render the operand it
would have cloned. This is also unnecessary because earlier code has already
replaced the MCParsedOperand with the one it was tied to (so the parsed input
is matched as if it were 'dati <RegIdx 2>, <RegIdx 2>, <Imm 1>'). As a result,
it looks like fixing this properly amounts to a rewrite of the tied operand
handling which affects all targets.
This patch however, merely inserts a checking hook just before the
substitution of MCParsedOperands and the Mips target overrides it. It's not
possible to accurately check the registers are the same this early (because
numeric registers haven't been bound to a register class yet) so it cheats a
bit and checks that the tokens that produced the operand are lexically
identical. This works because tied registers need to have the same register
class but it does have a flaw. It will reject 'dati $4, $a0, 1' for violating
the constraint even though $a0 ends up as the same register as $4.
Reviewers: sdardis
Subscribers: dsanders, llvm-commits, sdardis
Differential Revision: https://reviews.llvm.org/D21994
llvm-svn: 276867
2016-07-27 15:49:44 +02:00
|
|
|
OS << " Inst.setOpcode(it->Opcode);\n";
|
|
|
|
// Verify the instruction with the target-specific match predicate function.
|
|
|
|
OS << " // We have a potential match but have not rendered the operands.\n"
|
|
|
|
<< " // Check the target predicate to handle any context sensitive\n"
|
|
|
|
" // constraints.\n"
|
|
|
|
<< " // For example, Ties that are referenced multiple times must be\n"
|
|
|
|
" // checked here to ensure the input is the same for each match\n"
|
|
|
|
" // constraints. If we leave it any later the ties will have been\n"
|
|
|
|
" // canonicalized\n"
|
|
|
|
<< " unsigned MatchResult;\n"
|
|
|
|
<< " if ((MatchResult = checkEarlyTargetMatchPredicate(Inst, "
|
|
|
|
"Operands)) != Match_Success) {\n"
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
<< " Inst.clear();\n";
|
2017-10-11 11:17:43 +02:00
|
|
|
OS << " DEBUG_WITH_TYPE(\n";
|
|
|
|
OS << " \"asm-matcher\",\n";
|
|
|
|
OS << " dbgs() << \"Early target match predicate failed with diag code \"\n";
|
|
|
|
OS << " << MatchResult << \"\\n\");\n";
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
if (ReportMultipleNearMisses) {
|
|
|
|
OS << " EarlyPredicateNearMiss = NearMissInfo::getMissedPredicate(MatchResult);\n";
|
|
|
|
} else {
|
|
|
|
OS << " RetCode = MatchResult;\n"
|
|
|
|
<< " HadMatchOtherThanPredicate = true;\n"
|
|
|
|
<< " continue;\n";
|
|
|
|
}
|
|
|
|
OS << " }\n\n";
|
|
|
|
|
|
|
|
if (ReportMultipleNearMisses) {
|
|
|
|
OS << " // If we did not successfully match the operands, then we can't convert to\n";
|
|
|
|
OS << " // an MCInst, so bail out on this instruction variant now.\n";
|
|
|
|
OS << " if (OperandNearMiss) {\n";
|
|
|
|
OS << " // If the operand mismatch was the only problem, reprrt it as a near-miss.\n";
|
|
|
|
OS << " if (NearMisses && !FeaturesNearMiss && !EarlyPredicateNearMiss) {\n";
|
2017-10-11 11:17:43 +02:00
|
|
|
OS << " DEBUG_WITH_TYPE(\n";
|
|
|
|
OS << " \"asm-matcher\",\n";
|
|
|
|
OS << " dbgs()\n";
|
|
|
|
OS << " << \"Opcode result: one mismatched operand, adding near-miss\\n\");\n";
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
OS << " NearMisses->push_back(OperandNearMiss);\n";
|
2017-10-11 11:17:43 +02:00
|
|
|
OS << " } else {\n";
|
|
|
|
OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Opcode result: multiple \"\n";
|
|
|
|
OS << " \"types of mismatch, so not \"\n";
|
|
|
|
OS << " \"reporting near-miss\\n\");\n";
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
OS << " }\n";
|
|
|
|
OS << " continue;\n";
|
|
|
|
OS << " }\n\n";
|
|
|
|
}
|
|
|
|
|
2012-10-02 01:45:51 +02:00
|
|
|
OS << " if (matchingInlineAsm) {\n";
|
2012-10-13 00:53:36 +02:00
|
|
|
OS << " convertToMapAndConstraints(it->ConvertFn, Operands);\n";
|
2018-01-10 11:10:56 +01:00
|
|
|
if (!ReportMultipleNearMisses) {
|
[TableGen][AsmMatcherEmitter] Allow tied operands of different classes in aliases.
Allow a tied operand of a different operand class in InstAliases,
so that the operand can be printed (and added to the MC instruction)
as the appropriate register. For example, 'GPR64as32', which would
be printed/parsed as a 32bit register and should match a tied 64bit
register operand, where the former is a sub-register of the latter.
This patch also generalizes the constraint checking to an overrideable
method in MCTargetAsmParser, so that target asmparsers can specify
whether a given operand satisfies the tied register constraint.
Reviewers: olista01, rengolin, fhahn, SjoerdMeijer, samparker, dsanders, craig.topper
Reviewed By: fhahn
Differential Revision: https://reviews.llvm.org/D47714
llvm-svn: 334942
2018-06-18 15:39:29 +02:00
|
|
|
OS << " if (!checkAsmTiedOperandConstraints(*this, it->ConvertFn, "
|
|
|
|
"Operands, ErrorInfo))\n";
|
2018-01-10 11:10:56 +01:00
|
|
|
OS << " return Match_InvalidTiedOperand;\n";
|
|
|
|
OS << "\n";
|
|
|
|
}
|
2012-10-02 01:45:51 +02:00
|
|
|
OS << " return Match_Success;\n";
|
|
|
|
OS << " }\n\n";
|
2011-02-04 18:12:23 +01:00
|
|
|
OS << " // We have selected a definite instruction, convert the parsed\n"
|
|
|
|
<< " // operands into the appropriate MCInst.\n";
|
2016-05-06 13:31:17 +02:00
|
|
|
if (HasOptionalOperands) {
|
|
|
|
OS << " convertToMCInst(it->ConvertFn, Inst, it->Opcode, Operands,\n"
|
|
|
|
<< " OptionalOperandsMask);\n";
|
|
|
|
} else {
|
|
|
|
OS << " convertToMCInst(it->ConvertFn, Inst, it->Opcode, Operands);\n";
|
|
|
|
}
|
2011-02-04 18:12:23 +01:00
|
|
|
OS << "\n";
|
2010-03-18 21:05:56 +01:00
|
|
|
|
2011-08-16 01:03:29 +02:00
|
|
|
// Verify the instruction with the target-specific match predicate function.
|
|
|
|
OS << " // We have a potential match. Check the target predicate to\n"
|
|
|
|
<< " // handle any context sensitive constraints.\n"
|
|
|
|
<< " if ((MatchResult = checkTargetMatchPredicate(Inst)) !="
|
|
|
|
<< " Match_Success) {\n"
|
2017-10-11 11:17:43 +02:00
|
|
|
<< " DEBUG_WITH_TYPE(\"asm-matcher\",\n"
|
|
|
|
<< " dbgs() << \"Target match predicate failed with diag code \"\n"
|
|
|
|
<< " << MatchResult << \"\\n\");\n"
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
<< " Inst.clear();\n";
|
|
|
|
if (ReportMultipleNearMisses) {
|
|
|
|
OS << " LatePredicateNearMiss = NearMissInfo::getMissedPredicate(MatchResult);\n";
|
|
|
|
} else {
|
|
|
|
OS << " RetCode = MatchResult;\n"
|
|
|
|
<< " HadMatchOtherThanPredicate = true;\n"
|
|
|
|
<< " continue;\n";
|
|
|
|
}
|
|
|
|
OS << " }\n\n";
|
|
|
|
|
|
|
|
if (ReportMultipleNearMisses) {
|
|
|
|
OS << " int NumNearMisses = ((int)(bool)OperandNearMiss +\n";
|
|
|
|
OS << " (int)(bool)FeaturesNearMiss +\n";
|
|
|
|
OS << " (int)(bool)EarlyPredicateNearMiss +\n";
|
|
|
|
OS << " (int)(bool)LatePredicateNearMiss);\n";
|
|
|
|
OS << " if (NumNearMisses == 1) {\n";
|
|
|
|
OS << " // We had exactly one type of near-miss, so add that to the list.\n";
|
|
|
|
OS << " assert(!OperandNearMiss && \"OperandNearMiss was handled earlier\");\n";
|
2017-10-11 11:17:43 +02:00
|
|
|
OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Opcode result: found one type of \"\n";
|
|
|
|
OS << " \"mismatch, so reporting a \"\n";
|
|
|
|
OS << " \"near-miss\\n\");\n";
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
OS << " if (NearMisses && FeaturesNearMiss)\n";
|
|
|
|
OS << " NearMisses->push_back(FeaturesNearMiss);\n";
|
|
|
|
OS << " else if (NearMisses && EarlyPredicateNearMiss)\n";
|
|
|
|
OS << " NearMisses->push_back(EarlyPredicateNearMiss);\n";
|
|
|
|
OS << " else if (NearMisses && LatePredicateNearMiss)\n";
|
|
|
|
OS << " NearMisses->push_back(LatePredicateNearMiss);\n";
|
|
|
|
OS << "\n";
|
|
|
|
OS << " continue;\n";
|
|
|
|
OS << " } else if (NumNearMisses > 1) {\n";
|
|
|
|
OS << " // This instruction missed in more than one way, so ignore it.\n";
|
2017-10-11 11:17:43 +02:00
|
|
|
OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Opcode result: multiple \"\n";
|
|
|
|
OS << " \"types of mismatch, so not \"\n";
|
|
|
|
OS << " \"reporting near-miss\\n\");\n";
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
OS << " continue;\n";
|
|
|
|
OS << " }\n";
|
|
|
|
}
|
2011-08-16 01:03:29 +02:00
|
|
|
|
2010-03-18 21:05:56 +01:00
|
|
|
// Call the post-processing function, if used.
|
2017-05-31 23:12:46 +02:00
|
|
|
StringRef InsnCleanupFn = AsmParser->getValueAsString("AsmParserInstCleanup");
|
2010-03-18 21:05:56 +01:00
|
|
|
if (!InsnCleanupFn.empty())
|
|
|
|
OS << " " << InsnCleanupFn << "(Inst);\n";
|
|
|
|
|
2013-09-12 12:28:05 +02:00
|
|
|
if (HasDeprecation) {
|
|
|
|
OS << " std::string Info;\n";
|
2016-12-06 00:55:13 +01:00
|
|
|
OS << " if (!getParser().getTargetParser().\n";
|
|
|
|
OS << " getTargetOptions().MCNoDeprecatedWarn &&\n";
|
2020-03-29 21:09:07 +02:00
|
|
|
OS << " MII.getDeprecatedInfo(Inst, getSTI(), Info)) {\n";
|
2014-06-08 18:18:35 +02:00
|
|
|
OS << " SMLoc Loc = ((" << Target.getName()
|
2020-11-06 15:19:59 +01:00
|
|
|
<< "Operand &)*Operands[0]).getStartLoc();\n";
|
2014-11-11 06:18:41 +01:00
|
|
|
OS << " getParser().Warning(Loc, Info, None);\n";
|
2013-09-12 12:28:05 +02:00
|
|
|
OS << " }\n";
|
|
|
|
}
|
|
|
|
|
2018-01-10 11:10:56 +01:00
|
|
|
if (!ReportMultipleNearMisses) {
|
[TableGen][AsmMatcherEmitter] Allow tied operands of different classes in aliases.
Allow a tied operand of a different operand class in InstAliases,
so that the operand can be printed (and added to the MC instruction)
as the appropriate register. For example, 'GPR64as32', which would
be printed/parsed as a 32bit register and should match a tied 64bit
register operand, where the former is a sub-register of the latter.
This patch also generalizes the constraint checking to an overrideable
method in MCTargetAsmParser, so that target asmparsers can specify
whether a given operand satisfies the tied register constraint.
Reviewers: olista01, rengolin, fhahn, SjoerdMeijer, samparker, dsanders, craig.topper
Reviewed By: fhahn
Differential Revision: https://reviews.llvm.org/D47714
llvm-svn: 334942
2018-06-18 15:39:29 +02:00
|
|
|
OS << " if (!checkAsmTiedOperandConstraints(*this, it->ConvertFn, "
|
|
|
|
"Operands, ErrorInfo))\n";
|
2018-04-25 08:24:51 +02:00
|
|
|
OS << " return Match_InvalidTiedOperand;\n";
|
2018-01-10 11:10:56 +01:00
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
2017-10-11 11:17:43 +02:00
|
|
|
OS << " DEBUG_WITH_TYPE(\n";
|
|
|
|
OS << " \"asm-matcher\",\n";
|
|
|
|
OS << " dbgs() << \"Opcode result: complete match, selecting this opcode\\n\");\n";
|
2010-09-06 21:22:17 +02:00
|
|
|
OS << " return Match_Success;\n";
|
2009-08-08 09:50:56 +02:00
|
|
|
OS << " }\n\n";
|
2009-07-31 04:32:59 +02:00
|
|
|
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
if (ReportMultipleNearMisses) {
|
|
|
|
OS << " // No instruction variants matched exactly.\n";
|
|
|
|
OS << " return Match_NearMisses;\n";
|
|
|
|
} else {
|
|
|
|
OS << " // Okay, we had no match. Try to return a useful error code.\n";
|
|
|
|
OS << " if (HadMatchOtherThanPredicate || !HadMatchOtherThanFeatures)\n";
|
|
|
|
OS << " return RetCode;\n\n";
|
2019-03-11 18:04:35 +01:00
|
|
|
OS << " ErrorInfo = 0;\n";
|
[Assembler] Report multiple near misses for invalid instructions
The current table-generated assembly instruction matcher returns a
64-bit error code when matching fails. Since multiple instruction
encodings with the same mnemonic can fail for different reasons, it uses
some heuristics to decide which message is important.
This heuristic does not work well for targets that have many encodings
with the same mnemonic but different operands, or which have different
versions of instructions controlled by subtarget features, as it is hard
to know which encoding the user was intending to use.
Instead of trying to improve the heuristic in the table-generated
matcher, this patch changes it to report a list of near-miss encodings.
This list contains an entry for each encoding with the correct mnemonic,
but with exactly one thing preventing it from being valid. This thing
could be a single invalid operand, a missing target feature or a failed
target-specific validation function.
The target-specific assembly parser can then report an error message
giving multiple options for instruction variants that the user may have
been trying to use. For example, I am working on a patch to use this for
ARM, which can give this error for an invalid instruction for ARMv6-M:
<stdin>:8:3: error: invalid instruction, multiple near-miss encodings found
adds r0, r1, #0x8
^
<stdin>:8:3: note: for one encoding: instruction requires: thumb2
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected an integer in range [0, 7]
adds r0, r1, #0x8
^
<stdin>:8:16: note: for one encoding: expected a register in range [r0, r7]
adds r0, r1, #0x8
^
This also allows the target-specific assembly parser to apply its own
heuristics to suppress some errors. For example, the error "instruction
requires: arm-mode" is never going to be useful when targeting an
M-profile architecture (which does not have ARM mode).
This patch just adds the target-independent mechanism for doing this,
all targets still use the old mechanism. I've added a bit in the
AsmParser tablegen class to allow targets to switch to this new
mechanism. To use this, the target-specific assembly parser will have to
be modified for the change in signature of MatchInstructionImpl, and to
report errors based on the list of near-misses.
Differential revision: https://reviews.llvm.org/D27620
llvm-svn: 314774
2017-10-03 11:33:12 +02:00
|
|
|
OS << " return Match_MissingFeature;\n";
|
|
|
|
}
|
2009-07-31 04:32:59 +02:00
|
|
|
OS << "}\n\n";
|
2010-10-30 00:13:48 +02:00
|
|
|
|
2015-01-15 12:41:30 +01:00
|
|
|
if (!Info.OperandMatchInfo.empty())
|
2012-09-18 09:02:21 +02:00
|
|
|
emitCustomOperandParsing(OS, Target, Info, ClassName, StringTable,
|
2019-03-11 18:04:35 +01:00
|
|
|
MaxMnemonicIndex, FeatureBitsets.size(),
|
|
|
|
HasMnemonicFirst);
|
Implement support for custom target specific asm parsing of operands.
Motivation: Improve the parsing of not usual (different from registers or
immediates) operand forms.
This commit implements only the generic support. The ARM specific modifications
will come next.
A table like the one below is autogenerated for every instruction
containing a 'ParserMethod' in its AsmOperandClass
static const OperandMatchEntry OperandMatchTable[20] = {
/* Mnemonic, Operand List Mask, Operand Class, Features */
{ "cdp", 29 /* 0, 2, 3, 4 */, MCK_Coproc, Feature_IsThumb|Feature_HasV6 },
{ "cdp", 58 /* 1, 3, 4, 5 */, MCK_Coproc, Feature_IsARM },
A matcher function very similar (but lot more naive) to
MatchInstructionImpl scans the table. After the mnemonic match, the
features are checked and if the "to be parsed" operand index is
present in the mask, there's a real match. Then, a switch like the one
below dispatch the parsing to the custom method provided in
'ParseMethod':
case MCK_Coproc:
return TryParseCoprocessorOperandName(Operands);
llvm-svn: 125030
2011-02-07 20:38:32 +01:00
|
|
|
|
2010-09-06 21:11:01 +02:00
|
|
|
OS << "#endif // GET_MATCHER_IMPLEMENTATION\n\n";
|
2017-10-26 08:46:40 +02:00
|
|
|
|
|
|
|
OS << "\n#ifdef GET_MNEMONIC_SPELL_CHECKER\n";
|
|
|
|
OS << "#undef GET_MNEMONIC_SPELL_CHECKER\n\n";
|
|
|
|
|
|
|
|
emitMnemonicSpellChecker(OS, Target, VariantCount);
|
|
|
|
|
|
|
|
OS << "#endif // GET_MNEMONIC_SPELL_CHECKER\n\n";
|
2020-10-05 13:23:41 +02:00
|
|
|
|
|
|
|
OS << "\n#ifdef GET_MNEMONIC_CHECKER\n";
|
|
|
|
OS << "#undef GET_MNEMONIC_CHECKER\n\n";
|
|
|
|
|
|
|
|
emitMnemonicChecker(OS, Target, VariantCount,
|
|
|
|
HasMnemonicFirst, HasMnemonicAliases);
|
|
|
|
|
|
|
|
OS << "#endif // GET_MNEMONIC_CHECKER\n\n";
|
2009-07-11 21:39:44 +02:00
|
|
|
}
|
2012-06-11 17:37:55 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
void EmitAsmMatcher(RecordKeeper &RK, raw_ostream &OS) {
|
|
|
|
emitSourceFileHeader("Assembly Matcher Source Fragment", OS);
|
|
|
|
AsmMatcherEmitter(RK).run(OS);
|
|
|
|
}
|
|
|
|
|
2016-02-02 19:20:45 +01:00
|
|
|
} // end namespace llvm
|