llvm-project/llvm/lib/Target/NVPTX
Ulrich Weigand c48aefb63b [TableGen] Support multi-alternative pattern fragments
A TableGen instruction record usually contains a DAG pattern that will
describe the SelectionDAG operation that can be implemented by this
instruction. However, there will be cases where several different DAG
patterns can all be implemented by the same instruction. The way to
represent this today is to write additional patterns in the Pattern
(or usually Pat) class that map those extra DAG patterns to the
instruction. This usually also works fine.

However, I've noticed cases where the current setup seems to require
quite a bit of extra (and duplicated) text in the target .td files.
For example, in the SystemZ back-end, there are quite a number of
instructions that can implement an "add-with-overflow" operation.
The same instructions also need to be used to implement just plain
addition (simply ignoring the extra overflow output). The current
solution requires creating extra Pat pattern for every instruction,
duplicating the information about which particular add operands
map best to which particular instruction.

This patch enhances TableGen to support a new PatFrags class, which
can be used to encapsulate multiple alternative patterns that may
all match to the same instruction.  It operates the same way as the
existing PatFrag class, except that it accepts a list of DAG patterns
to match instead of just a single one.  As an example, we can now define
a PatFrags to match either an "add-with-overflow" or a regular add
operation:

  def z_sadd : PatFrags<(ops node:$src1, node:$src2),
                        [(z_saddo node:$src1, node:$src2),
                         (add node:$src1, node:$src2)]>;

and then use this in the add instruction pattern:

  defm AR : BinaryRRAndK<"ar", 0x1A, 0xB9F8, z_sadd, GR32, GR32>;

These SystemZ target changes are implemented here as well.


Note that PatFrag is now defined as a subclass of PatFrags, which
means that some users of internals of PatFrag need to be updated.
(E.g. instead of using PatFrag.Fragment you now need to use
!head(PatFrag.Fragments).)


The implementation is based on the following main ideas:
- InlinePatternFragments may now replace each original pattern
  with several result patterns, not just one.
- parseInstructionPattern delays calling InlinePatternFragments
  and InferAllTypes.  Instead, it extracts a single DAG match
  pattern from the main instruction pattern.
- Processing of the DAG match pattern part of the main instruction
  pattern now shares most code with processing match patterns from
  the Pattern class.
- Direct use of main instruction patterns in InferFromPattern and
  EmitResultInstructionAsOperand is removed; everything now operates
  solely on DAG match patterns.


Reviewed by: hfinkel

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

llvm-svn: 336999
2018-07-13 13:18:00 +00:00
..
InstPrinter
MCTargetDesc Revert "Temporarily revert "[DEBUG] Initial adaptation of NVPTX target for debug info emission."" 2018-05-18 03:13:08 +00:00
TargetInfo Add backend name to Target to enable runtime info to be fed back into TableGen 2017-11-15 23:55:44 +00:00
CMakeLists.txt Consistently sort add_subdirectory calls in lib/Target/*/CMakeLists.txt 2018-04-23 12:49:34 +00:00
LLVMBuild.txt
ManagedStringPool.h
NVPTX.h
NVPTX.td [NVPTX, CUDA] Added support for m8n32k16 and m32n8k16 variants of wmma instructions. 2018-04-18 21:51:48 +00:00
NVPTXAllocaHoisting.cpp
NVPTXAllocaHoisting.h
NVPTXAsmPrinter.cpp Use Type::isIntOrPtrTy where possible, NFC 2018-07-06 20:17:42 +00:00
NVPTXAsmPrinter.h [NVPTX] Delete dead code from the AsmPrinter. 2018-06-04 16:12:33 +00:00
NVPTXAssignValidGlobalNames.cpp Remove \brief commands from doxygen comments. 2018-05-01 15:54:18 +00:00
NVPTXFrameLowering.cpp Target/TargetInstrInfo.h -> CodeGen/TargetInstrInfo.h to match layering 2017-11-08 01:01:31 +00:00
NVPTXFrameLowering.h Move TargetFrameLowering.h to CodeGen where it's implemented 2017-11-03 22:32:11 +00:00
NVPTXGenericToNVVM.cpp [IR][CodeGen] Remove dependency on EVT from IR/Function.cpp. Move EVT to CodeGen layer. 2018-03-29 17:21:10 +00:00
NVPTXISelDAGToDAG.cpp [NVPTX] Delete dead code 2018-06-28 20:05:35 +00:00
NVPTXISelDAGToDAG.h [NVPTX] Delete dead code 2018-06-28 20:05:35 +00:00
NVPTXISelLowering.cpp [NVPTX] Expand v2f16 INSERT_VECTOR_ELT 2018-07-03 20:40:04 +00:00
NVPTXISelLowering.h TLI: Allow using PSV for intrinsic mem operands 2017-12-14 22:34:10 +00:00
NVPTXImageOptimizer.cpp
NVPTXInstrFormats.td
NVPTXInstrInfo.cpp [NVPTX] Delete dead code 2018-06-28 20:05:35 +00:00
NVPTXInstrInfo.h [NVPTX] Delete dead code 2018-06-28 20:05:35 +00:00
NVPTXInstrInfo.td [NVPTX] Added a feature to use short pointers for const/local/shared AS. 2018-05-09 23:46:19 +00:00
NVPTXIntrinsics.td [TableGen] Support multi-alternative pattern fragments 2018-07-13 13:18:00 +00:00
NVPTXLowerAggrCopies.cpp [Memcpy Loop Lowering] Remove the fixed int8 lowering. 2017-12-18 15:31:14 +00:00
NVPTXLowerAggrCopies.h
NVPTXLowerAlloca.cpp
NVPTXLowerArgs.cpp
NVPTXMCExpr.cpp Avoid int to string conversion in Twine or raw_ostream contexts. 2017-12-28 16:58:54 +00:00
NVPTXMCExpr.h
NVPTXMachineFunctionInfo.h
NVPTXPeephole.cpp MachineFunction: Return reference from getFunction(); NFC 2017-12-15 22:22:58 +00:00
NVPTXPrologEpilogPass.cpp Rename DEBUG macro to LLVM_DEBUG. 2018-05-14 12:53:11 +00:00
NVPTXRegisterInfo.cpp Target/TargetInstrInfo.h -> CodeGen/TargetInstrInfo.h to match layering 2017-11-08 01:01:31 +00:00
NVPTXRegisterInfo.h Fix a bunch more layering of CodeGen headers that are in Target 2017-11-17 01:07:10 +00:00
NVPTXRegisterInfo.td
NVPTXReplaceImageHandles.cpp MachineFunction: Return reference from getFunction(); NFC 2017-12-15 22:22:58 +00:00
NVPTXSubtarget.cpp
NVPTXSubtarget.h [NVPTX] Delete dead code 2018-06-28 20:05:35 +00:00
NVPTXTargetMachine.cpp [NVPTX] Added a feature to use short pointers for const/local/shared AS. 2018-05-09 23:46:19 +00:00
NVPTXTargetMachine.h [NVPTX] Added a feature to use short pointers for const/local/shared AS. 2018-05-09 23:46:19 +00:00
NVPTXTargetObjectFile.h Revert "Temporarily revert "[DEBUG] Initial adaptation of NVPTX target for debug info emission."" 2018-05-18 03:13:08 +00:00
NVPTXTargetTransformInfo.cpp Fix a bunch more layering of CodeGen headers that are in Target 2017-11-17 01:07:10 +00:00
NVPTXTargetTransformInfo.h [NVPTX] Ignore target-cpu and -features for inlining 2018-06-17 09:55:20 +00:00
NVPTXUtilities.cpp
NVPTXUtilities.h
NVVMIntrRange.cpp
NVVMReflect.cpp Rename DEBUG macro to LLVM_DEBUG. 2018-05-14 12:53:11 +00:00
cl_common_defines.h