Skip to content

Commit 9b22521

Browse files
committed
[tblgen][disasm] Allow multiple encodings to disassemble to the same instruction
Summary: Add an AdditionalEncoding class which can be used to define additional encodings for a given instruction. This causes the disassembler to add an additional encoding to its matching tables that map to the specified instruction. Usage: def ADD1 : Instruction { bits<8> Reg; bits<32> Inst; let Size = 4; let Inst{0-7} = Reg; let Inst{8-14} = 0; let Inst{15} = 1; // Continuation bit let Inst{16-31} = 0; ... } def : AdditionalEncoding<ADD1> { bits<8> Reg; bits<16> Inst; // You can also have bits<32> and it will still be a 16-bit encoding let Size = 2; let Inst{0-3} = 0; let Inst{4-7} = Reg; let Inst{8-15} = 0; ... } with those definitions, llvm-mc will successfully disassemble both of these: 0x01 0x00 0x10 0x80 0x00 0x00 to: ADD1 r1 Depends on D52366 Reviewers: bogner, charukcs Reviewed By: bogner Subscribers: nlguillemot, nhaehnle, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D52369 llvm-svn: 363744
1 parent 4f7f70e commit 9b22521

File tree

2 files changed

+144
-78
lines changed

2 files changed

+144
-78
lines changed

llvm/include/llvm/Target/Target.td

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,49 @@ include "llvm/Target/TargetSchedule.td"
398398

399399
class Predicate; // Forward def
400400

401+
class InstructionEncoding {
402+
// Size of encoded instruction.
403+
int Size;
404+
405+
// The "namespace" in which this instruction exists, on targets like ARM
406+
// which multiple ISA namespaces exist.
407+
string DecoderNamespace = "";
408+
409+
// List of predicates which will be turned into isel matching code.
410+
list<Predicate> Predicates = [];
411+
412+
string DecoderMethod = "";
413+
414+
// Is the instruction decoder method able to completely determine if the
415+
// given instruction is valid or not. If the TableGen definition of the
416+
// instruction specifies bitpattern A??B where A and B are static bits, the
417+
// hasCompleteDecoder flag says whether the decoder method fully handles the
418+
// ?? space, i.e. if it is a final arbiter for the instruction validity.
419+
// If not then the decoder attempts to continue decoding when the decoder
420+
// method fails.
421+
//
422+
// This allows to handle situations where the encoding is not fully
423+
// orthogonal. Example:
424+
// * InstA with bitpattern 0b0000????,
425+
// * InstB with bitpattern 0b000000?? but the associated decoder method
426+
// DecodeInstB() returns Fail when ?? is 0b00 or 0b11.
427+
//
428+
// The decoder tries to decode a bitpattern that matches both InstA and
429+
// InstB bitpatterns first as InstB (because it is the most specific
430+
// encoding). In the default case (hasCompleteDecoder = 1), when
431+
// DecodeInstB() returns Fail the bitpattern gets rejected. By setting
432+
// hasCompleteDecoder = 0 in InstB, the decoder is informed that
433+
// DecodeInstB() is not able to determine if all possible values of ?? are
434+
// valid or not. If DecodeInstB() returns Fail the decoder will attempt to
435+
// decode the bitpattern as InstA too.
436+
bit hasCompleteDecoder = 1;
437+
}
438+
401439
//===----------------------------------------------------------------------===//
402440
// Instruction set description - These classes correspond to the C++ classes in
403441
// the Target/TargetInstrInfo.h file.
404442
//
405-
class Instruction {
443+
class Instruction : InstructionEncoding {
406444
string Namespace = "";
407445

408446
dag OutOperandList; // An dag containing the MI def operand list.
@@ -427,10 +465,6 @@ class Instruction {
427465
// from the opcode.
428466
int Size = 0;
429467

430-
// DecoderNamespace - The "namespace" in which this instruction exists, on
431-
// targets like ARM which multiple ISA namespaces exist.
432-
string DecoderNamespace = "";
433-
434468
// Code size, for instruction selection.
435469
// FIXME: What does this actually mean?
436470
int CodeSize = 0;
@@ -532,31 +566,6 @@ class Instruction {
532566
string DisableEncoding = "";
533567

534568
string PostEncoderMethod = "";
535-
string DecoderMethod = "";
536-
537-
// Is the instruction decoder method able to completely determine if the
538-
// given instruction is valid or not. If the TableGen definition of the
539-
// instruction specifies bitpattern A??B where A and B are static bits, the
540-
// hasCompleteDecoder flag says whether the decoder method fully handles the
541-
// ?? space, i.e. if it is a final arbiter for the instruction validity.
542-
// If not then the decoder attempts to continue decoding when the decoder
543-
// method fails.
544-
//
545-
// This allows to handle situations where the encoding is not fully
546-
// orthogonal. Example:
547-
// * InstA with bitpattern 0b0000????,
548-
// * InstB with bitpattern 0b000000?? but the associated decoder method
549-
// DecodeInstB() returns Fail when ?? is 0b00 or 0b11.
550-
//
551-
// The decoder tries to decode a bitpattern that matches both InstA and
552-
// InstB bitpatterns first as InstB (because it is the most specific
553-
// encoding). In the default case (hasCompleteDecoder = 1), when
554-
// DecodeInstB() returns Fail the bitpattern gets rejected. By setting
555-
// hasCompleteDecoder = 0 in InstB, the decoder is informed that
556-
// DecodeInstB() is not able to determine if all possible values of ?? are
557-
// valid or not. If DecodeInstB() returns Fail the decoder will attempt to
558-
// decode the bitpattern as InstA too.
559-
bit hasCompleteDecoder = 1;
560569

561570
/// Target-specific flags. This becomes the TSFlags field in TargetInstrDesc.
562571
bits<64> TSFlags = 0;
@@ -593,6 +602,13 @@ class Instruction {
593602
bit FastISelShouldIgnore = 0;
594603
}
595604

605+
/// Defines an additional encoding that disassembles to the given instruction
606+
/// Like Instruction, the Inst and SoftFail fields are omitted to allow targets
607+
// to specify their size.
608+
class AdditionalEncoding<Instruction I> : InstructionEncoding {
609+
Instruction AliasOf = I;
610+
}
611+
596612
/// PseudoInstExpansion - Expansion information for a pseudo-instruction.
597613
/// Which instruction it expands to and how the operands map from the
598614
/// pseudo.

0 commit comments

Comments
 (0)