[PATCH] D91331: [NFC] Add hook for target to customize different legalization action according to the input type

Qing Shan Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 16 04:08:38 PST 2020


steven.zhang updated this revision to Diff 305466.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91331/new/

https://reviews.llvm.org/D91331

Files:
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp


Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -998,8 +998,16 @@
       Action = TLI.getOperationAction(Node->getOpcode(), MVT::Other);
     break;
   case ISD::FP_TO_FP16:
+  case ISD::FP_ROUND:
+  case ISD::FP_EXTEND:
   case ISD::SINT_TO_FP:
   case ISD::UINT_TO_FP:
+  case ISD::FP_TO_UINT:
+  case ISD::FP_TO_SINT:
+    Action = TLI.getCastOperationAction(Node->getOpcode(),
+                                        Node->getOperand(0).getValueType(),
+                                        Node->getValueType(0));
+    break;
   case ISD::EXTRACT_VECTOR_ELT:
   case ISD::LROUND:
   case ISD::LLROUND:
Index: llvm/include/llvm/CodeGen/TargetLowering.h
===================================================================
--- llvm/include/llvm/CodeGen/TargetLowering.h
+++ llvm/include/llvm/CodeGen/TargetLowering.h
@@ -1042,6 +1042,40 @@
     return OpActions[(unsigned)VT.getSimpleVT().SimpleTy][Op];
   }
 
+  /// Some cast operations may be natively supported by the target but only for
+  /// specific \p SrcVT. This method allows for checking both the \p SrcVT and
+  /// \p DestVT for a given operation.
+  LegalizeAction getCastOperationAction(unsigned Op, EVT SrcVT,
+                                        EVT DestVT) const {
+    LegalizeAction Action = Legal;
+    switch (Op) {
+    default:
+      llvm_unreachable("Unexpected cast operation.");
+    case ISD::FP_TO_FP16:
+    case ISD::SINT_TO_FP:
+    case ISD::UINT_TO_FP:
+      Action = getOperationAction(Op, SrcVT);
+      break;
+    case ISD::FP_ROUND:
+    case ISD::FP_EXTEND:
+    case ISD::FP_TO_UINT:
+    case ISD::FP_TO_SINT:
+      Action = getOperationAction(Op, DestVT);
+      break;
+    }
+    if (Action != Legal && Action != Custom)
+      return Action;
+    return isSupportedCastOperation(Op, SrcVT, DestVT) ? Action : LibCall;
+  }
+
+  /// Custom method defined by each target to indicate if an cast operation
+  /// which cast from \p SrcVT to \p DestVT is supported natively by the
+  /// target. If not, the operation is illegal.
+  virtual bool isSupportedCastOperation(unsigned Op, EVT SrcVT,
+                                        EVT DestVT) const {
+    return true;
+  }
+
   /// Custom method defined by each target to indicate if an operation which
   /// may require a scale is supported natively by the target.
   /// If not, the operation is illegal.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91331.305466.patch
Type: text/x-patch
Size: 2545 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201116/36e8481e/attachment.bin>


More information about the llvm-commits mailing list