[PATCH] D137482: [LoongArch] Support parsing target specific flags for MIR

wanglei via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 10 04:58:52 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG0436cf5f5217: [LoongArch] Support parsing target specific flags for MIR (authored by wangleiat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137482

Files:
  llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
  llvm/lib/Target/LoongArch/LoongArchInstrInfo.h
  llvm/test/CodeGen/LoongArch/mir-target-flags.ll


Index: llvm/test/CodeGen/LoongArch/mir-target-flags.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/mir-target-flags.ll
@@ -0,0 +1,44 @@
+; RUN: llc --mtriple=loongarch64 --stop-after loongarch-prera-expand-pseudo \
+; RUN:     --relocation-model=pic %s -o %t.mir
+; RUN: llc --mtriple=loongarch64 --run-pass loongarch-prera-expand-pseudo \
+; RUN:     %t.mir -o - | FileCheck %s
+
+;; This tests the LoongArch-specific serialization and deserialization of
+;; `target-flags(...)`
+
+ at g_e = external global i32
+ at g_i = internal global i32 0
+ at t_un = external thread_local global i32
+ at t_ld = external thread_local(localdynamic) global i32
+ at t_ie = external thread_local(initialexec) global i32
+ at t_le = external thread_local(localexec) global i32
+
+declare void @callee1() nounwind
+declare dso_local void @callee2() nounwind
+
+define void @caller() nounwind {
+; CHECK-LABEL: name: caller
+; CHECK:      target-flags(loongarch-got-pc-hi) @g_e
+; CHECK-NEXT: target-flags(loongarch-got-pc-lo) @g_e
+; CHECK:      target-flags(loongarch-pcrel-hi) @g_i
+; CHECK-NEXT: target-flags(loongarch-pcrel-lo) @g_i
+; CHECK:      target-flags(loongarch-gd-pc-hi) @t_un
+; CHECK-NEXT: target-flags(loongarch-got-pc-lo) @t_un
+; CHECK:      target-flags(loongarch-ld-pc-hi) @t_ld
+; CHECK-NEXT: target-flags(loongarch-got-pc-lo) @t_ld
+; CHECK:      target-flags(loongarch-ie-pc-hi) @t_ie
+; CHECK-NEXT: target-flags(loongarch-ie-pc-lo) @t_ie
+; CHECK:      target-flags(loongarch-le-hi) @t_le
+; CHECK-NEXT: target-flags(loongarch-le-lo) @t_le
+; CHECK:      target-flags(loongarch-call-plt) @callee1
+; CHECK:      target-flags(loongarch-call) @callee2
+  %a = load volatile i32, ptr @g_e
+  %b = load volatile i32, ptr @g_i
+  %c = load volatile i32, ptr @t_un
+  %d = load volatile i32, ptr @t_ld
+  %e = load volatile i32, ptr @t_ie
+  %f = load volatile i32, ptr @t_le
+  call i32 @callee1()
+  call i32 @callee2()
+  ret void
+}
Index: llvm/lib/Target/LoongArch/LoongArchInstrInfo.h
===================================================================
--- llvm/lib/Target/LoongArch/LoongArchInstrInfo.h
+++ llvm/lib/Target/LoongArch/LoongArchInstrInfo.h
@@ -74,6 +74,12 @@
   bool
   reverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;
 
+  std::pair<unsigned, unsigned>
+  decomposeMachineOperandsTargetFlags(unsigned TF) const override;
+
+  ArrayRef<std::pair<unsigned, const char *>>
+  getSerializableDirectMachineOperandTargetFlags() const override;
+
 protected:
   const LoongArchSubtarget &STI;
 };
Index: llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
===================================================================
--- llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
+++ llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp
@@ -434,3 +434,28 @@
   Cond[0].setImm(getOppositeBranchOpc(Cond[0].getImm()));
   return false;
 }
+
+std::pair<unsigned, unsigned>
+LoongArchInstrInfo::decomposeMachineOperandsTargetFlags(unsigned TF) const {
+  return std::make_pair(TF, 0u);
+}
+
+ArrayRef<std::pair<unsigned, const char *>>
+LoongArchInstrInfo::getSerializableDirectMachineOperandTargetFlags() const {
+  using namespace LoongArchII;
+  // TODO: Add more target flags.
+  static const std::pair<unsigned, const char *> TargetFlags[] = {
+      {MO_CALL, "loongarch-call"},
+      {MO_CALL_PLT, "loongarch-call-plt"},
+      {MO_PCREL_HI, "loongarch-pcrel-hi"},
+      {MO_PCREL_LO, "loongarch-pcrel-lo"},
+      {MO_GOT_PC_HI, "loongarch-got-pc-hi"},
+      {MO_GOT_PC_LO, "loongarch-got-pc-lo"},
+      {MO_LE_HI, "loongarch-le-hi"},
+      {MO_LE_LO, "loongarch-le-lo"},
+      {MO_IE_PC_HI, "loongarch-ie-pc-hi"},
+      {MO_IE_PC_LO, "loongarch-ie-pc-lo"},
+      {MO_LD_PC_HI, "loongarch-ld-pc-hi"},
+      {MO_GD_PC_HI, "loongarch-gd-pc-hi"}};
+  return makeArrayRef(TargetFlags);
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137482.474511.patch
Type: text/x-patch
Size: 3889 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221110/ed7ab0b3/attachment.bin>


More information about the llvm-commits mailing list