[PATCH] D134368: [LoongArch] Support llvm.thread.pointer

Lu Weining via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 25 18:59:48 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf89f0990db44: [LoongArch] Support llvm.thread.pointer (authored by WANG Xuerui <git at xen0n.name>, committed by SixWeining).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134368

Files:
  llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
  llvm/lib/Target/LoongArch/LoongArchISelLowering.h
  llvm/test/CodeGen/LoongArch/thread-pointer.ll


Index: llvm/test/CodeGen/LoongArch/thread-pointer.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/thread-pointer.ll
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s --mtriple=loongarch32 | FileCheck %s
+; RUN: llc < %s --mtriple=loongarch64 | FileCheck %s
+
+declare ptr @llvm.thread.pointer()
+
+define ptr @thread_pointer() nounwind {
+; CHECK-LABEL: thread_pointer:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    move $a0, $tp
+; CHECK-NEXT:    ret
+  %1 = tail call ptr @llvm.thread.pointer()
+  ret ptr %1
+}
Index: llvm/lib/Target/LoongArch/LoongArchISelLowering.h
===================================================================
--- llvm/lib/Target/LoongArch/LoongArchISelLowering.h
+++ llvm/lib/Target/LoongArch/LoongArchISelLowering.h
@@ -143,6 +143,7 @@
   SDValue lowerBITCAST(SDValue Op, SelectionDAG &DAG) const;
   SDValue lowerUINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
   SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const;
+  SDValue lowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
 
   bool isFPImmLegal(const APFloat &Imm, EVT VT,
                     bool ForCodeSize) const override;
Index: llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
===================================================================
--- llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -60,6 +60,8 @@
 
   setOperationAction({ISD::GlobalAddress, ISD::ConstantPool}, GRLenVT, Custom);
 
+  setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
+
   setOperationAction(ISD::EH_DWARF_CFA, MVT::i32, Custom);
   if (Subtarget.is64Bit())
     setOperationAction(ISD::EH_DWARF_CFA, MVT::i64, Custom);
@@ -176,6 +178,8 @@
     return lowerEH_DWARF_CFA(Op, DAG);
   case ISD::GlobalAddress:
     return lowerGlobalAddress(Op, DAG);
+  case ISD::INTRINSIC_WO_CHAIN:
+    return lowerINTRINSIC_WO_CHAIN(Op, DAG);
   case ISD::SHL_PARTS:
     return lowerShiftLeftParts(Op, DAG);
   case ISD::SRA_PARTS:
@@ -310,6 +314,20 @@
   report_fatal_error("Unable to lowerGlobalAddress");
 }
 
+SDValue LoongArchTargetLowering::lowerINTRINSIC_WO_CHAIN(SDValue Op,
+                                                         SelectionDAG &DAG) const {
+  unsigned IntNo = Op.getConstantOperandVal(0);
+
+  switch (IntNo) {
+  default:
+    return SDValue(); // Don't custom lower most intrinsics.
+  case Intrinsic::thread_pointer: {
+    EVT PtrVT = getPointerTy(DAG.getDataLayout());
+    return DAG.getRegister(LoongArch::R2, PtrVT);
+  }
+  }
+}
+
 SDValue LoongArchTargetLowering::lowerShiftLeftParts(SDValue Op,
                                                      SelectionDAG &DAG) const {
   SDLoc DL(Op);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134368.462786.patch
Type: text/x-patch
Size: 2824 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220926/af78d8e0/attachment.bin>


More information about the llvm-commits mailing list