[PATCH] D156090: [Driver][XRay][test] Add support for loongarch64

2023-07-24 Thread Limin Zhang via Phabricator via cfe-commits
Ami-zhang created this revision.
Ami-zhang added reviewers: SixWeining, probinson, MaskRay.
Herald added a subscriber: dberris.
Herald added a project: All.
Ami-zhang requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Depends on D156089 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156090

Files:
  clang/test/Driver/XRay/lit.local.cfg
  clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
  clang/test/Driver/XRay/xray-instrumentation-bundles-flags.cpp
  clang/test/Driver/XRay/xray-mode-flags.cpp


Index: clang/test/Driver/XRay/xray-mode-flags.cpp
===
--- clang/test/Driver/XRay/xray-mode-flags.cpp
+++ clang/test/Driver/XRay/xray-mode-flags.cpp
@@ -46,4 +46,4 @@
 // NONE-NOT: libclang_rt.xray-basic
 // NONE-NOT: libclang_rt.xray-fdr
 // REQUIRES: target={{.*-(linux|freebsd).*}}
-// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64)-.*}}
+// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64|loongarch64)-.*}}
Index: clang/test/Driver/XRay/xray-instrumentation-bundles-flags.cpp
===
--- clang/test/Driver/XRay/xray-instrumentation-bundles-flags.cpp
+++ clang/test/Driver/XRay/xray-instrumentation-bundles-flags.cpp
@@ -7,4 +7,4 @@
 // CHECK:  -fxray-instrumentation-bundle=function
 //
 // REQUIRES: target={{.*-(linux|freebsd).*}}
-// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64)-.*}}
+// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64|loongarch64)-.*}}
Index: clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
===
--- clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
+++ clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
@@ -6,4 +6,4 @@
 // RUN:   -x c++ -emit-llvm -c -o - %s 2>&1 | FileCheck %s
 // CHECK:  -fxray-ignore-loops
 //
-// REQUIRES: target={{(x86_64|x86_64h)-.*}}
+// REQUIRES: target={{(x86_64|x86_64h|loongarch64)-.*}}
Index: clang/test/Driver/XRay/lit.local.cfg
===
--- clang/test/Driver/XRay/lit.local.cfg
+++ clang/test/Driver/XRay/lit.local.cfg
@@ -13,6 +13,7 @@
 "mipsel",
 "mips64",
 "mips64el",
+"loongarch64",
 ]
 
 # Only on platforms we support.


Index: clang/test/Driver/XRay/xray-mode-flags.cpp
===
--- clang/test/Driver/XRay/xray-mode-flags.cpp
+++ clang/test/Driver/XRay/xray-mode-flags.cpp
@@ -46,4 +46,4 @@
 // NONE-NOT: libclang_rt.xray-basic
 // NONE-NOT: libclang_rt.xray-fdr
 // REQUIRES: target={{.*-(linux|freebsd).*}}
-// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64)-.*}}
+// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64|loongarch64)-.*}}
Index: clang/test/Driver/XRay/xray-instrumentation-bundles-flags.cpp
===
--- clang/test/Driver/XRay/xray-instrumentation-bundles-flags.cpp
+++ clang/test/Driver/XRay/xray-instrumentation-bundles-flags.cpp
@@ -7,4 +7,4 @@
 // CHECK:  -fxray-instrumentation-bundle=function
 //
 // REQUIRES: target={{.*-(linux|freebsd).*}}
-// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64)-.*}}
+// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64|loongarch64)-.*}}
Index: clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
===
--- clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
+++ clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
@@ -6,4 +6,4 @@
 // RUN:   -x c++ -emit-llvm -c -o - %s 2>&1 | FileCheck %s
 // CHECK:  -fxray-ignore-loops
 //
-// REQUIRES: target={{(x86_64|x86_64h)-.*}}
+// REQUIRES: target={{(x86_64|x86_64h|loongarch64)-.*}}
Index: clang/test/Driver/XRay/lit.local.cfg
===
--- clang/test/Driver/XRay/lit.local.cfg
+++ clang/test/Driver/XRay/lit.local.cfg
@@ -13,6 +13,7 @@
 "mipsel",
 "mips64",
 "mips64el",
+"loongarch64",
 ]
 
 # Only on platforms we support.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156090: [Driver][XRay][test] Mark these tests as supported on loongarch64

2023-07-24 Thread Limin Zhang via Phabricator via cfe-commits
Ami-zhang abandoned this revision.
Ami-zhang added a comment.

Thanks @MaskRay .
05c2c09bb1f10261f6f804a2d510c55d97b1584c 
 improved 
these XRay tests.
Abandon this change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156090

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140690: [dfsan] Support Linux loongarch64

2023-07-03 Thread Limin Zhang via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG280d163887ea: [dfsan] Support Linux loongarch64 (authored by 
Ami-zhang).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140690

Files:
  clang/lib/Driver/ToolChains/Linux.cpp
  compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
  compiler-rt/test/dfsan/lit.cfg.py
  llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp


Index: llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
@@ -305,6 +305,14 @@
 };
 // NOLINTEND(readability-identifier-naming)
 
+// loongarch64 Linux
+const MemoryMapParams Linux_LoongArch64_MemoryMapParams = {
+0,  // AndMask (not used)
+0x5000, // XorMask
+0,  // ShadowBase (not used)
+0x1000, // OriginBase
+};
+
 namespace {
 
 class DFSanABIList {
@@ -1128,6 +1136,9 @@
   case Triple::x86_64:
 MapParams = &Linux_X86_64_MemoryMapParams;
 break;
+  case Triple::loongarch64:
+MapParams = &Linux_LoongArch64_MemoryMapParams;
+break;
   default:
 report_fatal_error("unsupported architecture");
   }
Index: compiler-rt/test/dfsan/lit.cfg.py
===
--- compiler-rt/test/dfsan/lit.cfg.py
+++ compiler-rt/test/dfsan/lit.cfg.py
@@ -25,5 +25,5 @@
 config.suffixes = [".c", ".cpp"]
 
 # DataFlowSanitizer tests are currently supported on Linux only.
-if not (config.host_os in ["Linux"] and config.target_arch in ["aarch64", 
"x86_64"]):
+if not (config.host_os in ["Linux"] and config.target_arch in ["aarch64", 
"x86_64", "loongarch64"]):
 config.unsupported = True
Index: compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
===
--- compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -30,7 +30,7 @@
 ${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
 ${LOONGARCH64})
 set(ALL_ASAN_ABI_SUPPORTED_ARCH ${X86_64} ${ARM64})
-set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
+set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${LOONGARCH64})
 
 if(ANDROID)
   set(OS_NAME "Android")
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -795,7 +795,7 @@
   Res |= SanitizerKind::Memory;
   Res |= SanitizerKind::Vptr;
   Res |= SanitizerKind::SafeStack;
-  if (IsX86_64 || IsMIPS64 || IsAArch64)
+  if (IsX86_64 || IsMIPS64 || IsAArch64 || IsLoongArch64)
 Res |= SanitizerKind::DataFlow;
   if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86 || IsArmArch || IsPowerPC64 ||
   IsRISCV64 || IsSystemZ || IsHexagon || IsLoongArch64)


Index: llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
@@ -305,6 +305,14 @@
 };
 // NOLINTEND(readability-identifier-naming)
 
+// loongarch64 Linux
+const MemoryMapParams Linux_LoongArch64_MemoryMapParams = {
+0,  // AndMask (not used)
+0x5000, // XorMask
+0,  // ShadowBase (not used)
+0x1000, // OriginBase
+};
+
 namespace {
 
 class DFSanABIList {
@@ -1128,6 +1136,9 @@
   case Triple::x86_64:
 MapParams = &Linux_X86_64_MemoryMapParams;
 break;
+  case Triple::loongarch64:
+MapParams = &Linux_LoongArch64_MemoryMapParams;
+break;
   default:
 report_fatal_error("unsupported architecture");
   }
Index: compiler-rt/test/dfsan/lit.cfg.py
===
--- compiler-rt/test/dfsan/lit.cfg.py
+++ compiler-rt/test/dfsan/lit.cfg.py
@@ -25,5 +25,5 @@
 config.suffixes = [".c", ".cpp"]
 
 # DataFlowSanitizer tests are currently supported on Linux only.
-if not (config.host_os in ["Linux"] and config.target_arch in ["aarch64", "x86_64"]):
+if not (config.host_os in ["Linux"] and config.target_arch in ["aarch64", "x86_64", "loongarch64"]):
 config.unsupported = True
Index: compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
===
--- compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -30,7 +30,7 @@
 ${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
 ${LOONGARCH64})
 set(ALL_ASAN_ABI_SUPPORTED_ARCH ${X86_64} ${ARM64})
-set(ALL_DFSAN_SUPPORTED_ARCH 

[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-05 Thread Limin Zhang via Phabricator via cfe-commits
Ami-zhang updated this revision to Diff 537564.
Ami-zhang added a comment.

(1) Rebase
(2) Make some minor changes to xray-attribute-instrumentation.ll


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140727

Files:
  clang/lib/Driver/XRayArgs.cpp
  compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
  compiler-rt/lib/xray/CMakeLists.txt
  compiler-rt/lib/xray/xray_interface.cpp
  compiler-rt/lib/xray/xray_loongarch64.cpp
  compiler-rt/lib/xray/xray_trampoline_loongarch64.S
  compiler-rt/lib/xray/xray_tsc.h
  compiler-rt/test/xray/TestCases/Posix/always-never-instrument.cpp
  compiler-rt/test/xray/TestCases/Posix/arg1-arg0-logging.cpp
  compiler-rt/test/xray/TestCases/Posix/arg1-logger.cpp
  compiler-rt/test/xray/TestCases/Posix/arg1-logging-implicit-this.cpp
  compiler-rt/test/xray/TestCases/Posix/basic-filtering.cpp
  compiler-rt/test/xray/TestCases/Posix/c-test.cpp
  compiler-rt/test/xray/TestCases/Posix/clang-no-xray-instrument.cpp
  compiler-rt/test/xray/TestCases/Posix/fdr-mode-inmemory.cpp
  compiler-rt/test/xray/TestCases/Posix/fdr-mode-multiple.cpp
  compiler-rt/test/xray/TestCases/Posix/fdr-single-thread.cpp
  compiler-rt/test/xray/TestCases/Posix/fdr-thread-order.cpp
  compiler-rt/test/xray/TestCases/Posix/profiling-multi-threaded.cpp
  compiler-rt/test/xray/TestCases/Posix/profiling-single-threaded.cpp
  compiler-rt/test/xray/TestCases/Posix/quiet-start.cpp
  llvm/lib/CodeGen/XRayInstrumentation.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
  llvm/lib/Target/LoongArch/LoongArchSubtarget.h
  llvm/lib/XRay/InstrumentationMap.cpp
  llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll

Index: llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll
@@ -0,0 +1,55 @@
+; RUN: llc --mtriple=loongarch64 %s -o - | FileCheck %s
+; RUN: llc --mtriple=loongarch64 -filetype=obj %s -o %t
+; RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=RELOC
+
+define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" {
+; CHECK-LABEL: foo:
+; CHECK-LABEL: .Lfunc_begin0:
+; CHECK:   .p2align 2
+; CHECK-LABEL: .Lxray_sled_begin0:
+; CHECK-NEXT:  b .Lxray_sled_end0
+; CHECK-COUNT-11:  nop
+; CHECK-LABEL: .Lxray_sled_end0:
+  ret i32 0
+; CHECK-LABEL: .Lxray_sled_begin1:
+; CHECK-NEXT:  b .Lxray_sled_end1
+; CHECK-COUNT-11:  nop
+; CHECK-NEXT: .Lxray_sled_end1:
+; CHECK-NEXT:  ret
+; CHECK-NEXT: .Lfunc_end0:
+}
+
+; CHECK-LABEL: .section xray_instr_map
+; CHECK-NEXT: .Lxray_sleds_start0:
+; CHECK-NEXT: .Ltmp0:
+; CHECK-NEXT: .dword .Lxray_sled_begin0-.Ltmp0
+; CHECK-NEXT: .dword .Lfunc_begin0-(.Ltmp0+8)
+; CHECK-NEXT: .byte 0x00
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x00
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: .Ltmp1:
+; CHECK-NEXT: .dword .Lxray_sled_begin1-.Ltmp1
+; CHECK-NEXT: .dword .Lfunc_begin0-(.Ltmp1+8)
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x00
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: .Lxray_sleds_end0:
+
+; CHECK-LABEL:  .section xray_fn_idx
+; CHECK:  .dword .Lxray_sleds_start0-.Lxray_fn_idx0
+; CHECK-NEXT: .dword 2
+
+; RELOC:  Section ([[#]]) .relaxray_instr_map {
+; RELOC-NEXT:   0x0 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT:   0x8 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT:   0x20 R_LARCH_64_PCREL .text 0x34
+; RELOC-NEXT:   0x28 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT: }
+; RELOC-NEXT: Section ([[#]]) .relaxray_fn_idx {
+; RELOC-NEXT:   0x0 R_LARCH_64_PCREL xray_instr_map 0x0
+; RELOC-NEXT: }
+; RELOC-NEXT: Section ([[#]]) .rela.eh_frame {
+; RELOC-NEXT:   0x1C R_LARCH_32_PCREL .text 0x0
+; RELOC-NEXT: }
Index: llvm/lib/XRay/InstrumentationMap.cpp
===
--- llvm/lib/XRay/InstrumentationMap.cpp
+++ llvm/lib/XRay/InstrumentationMap.cpp
@@ -60,6 +60,7 @@
   // Find the section named "xray_instr_map".
   if ((!ObjFile.getBinary()->isELF() && !ObjFile.getBinary()->isMachO()) ||
   !(ObjFile.getBinary()->getArch() == Triple::x86_64 ||
+ObjFile.getBinary()->getArch() == Triple::loongarch64 ||
 ObjFile.getBinary()->getArch() == Triple::ppc64le ||
 ObjFile.getBinary()->getArch() == Triple::arm ||
 ObjFile.getBinary()->getArch() == Triple::aarch64))
Index: llvm/lib/Target/LoongArch/LoongArchSubtarget.h
===
--- llvm/lib/Target/LoongArch/LoongArchSubtarget.h
+++ llvm/lib/Target/LoongArch/LoongArchSubtarget.h
@@ -96,6 +96,7 @@
   MVT getGRLenVT() const { return GRLenVT; }
   unsigned getGRLen() const { return GRLen; }
   LoongArchABI::ABI getTargetABI() const { return TargetABI; }
+  bool isXRaySupported() const override { return is64Bit(); }
 };
 } // end namespace llvm
 
Index: llv

[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-07 Thread Limin Zhang via Phabricator via cfe-commits
Ami-zhang added inline comments.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:23
+enum PatchOpcodes : uint32_t {
+  PO_ADDID = 0x02c0,  // addi.d rd, rj, imm
+  PO_SD = 0x29c0, // st.d rd, base, offset

MaskRay wrote:
> I think the `PO_` style actually harms readability. Most instructions are 
> used just once. It's more readable just using the magic number when it is 
> needed paired with an inline comment
> 
> `Address[10] = insn2RI12(0x02c0, RegNum::RN_S, ...) // addi.d ...`
Ok, updated it. Thanks for your suggestion.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:153
+   const XRaySledEntry &Sled) XRAY_NEVER_INSTRUMENT {
+  // FIXME: In the future we'd need to distinguish between non-tail exits and
+  // tail exits for better information preservation.

MaskRay wrote:
> I know you copy the pattern from other patterns, but we should use TODO here. 
> An unimplemented minor feature is not FIXME.
Done.



Comment at: compiler-rt/lib/xray/xray_trampoline_loongarch64.S:27
+  .cfi_offset 1, -8
+  st.d$a7, $sp, 120
+  st.d$a6, $sp, 112

MaskRay wrote:
> You can use `.irpc` to simplify this a bit. See 
> libunwind/src/UnwindRegistersSave.S
Done. 



Comment at: compiler-rt/test/xray/TestCases/Posix/arg1-arg0-logging.cpp:9
 // TODO: Support these in ARM and PPC
-// XFAIL: target={{(arm|aarch64|mips).*}}
+// XFAIL: target={{(arm|aarch64|loongarch64|mips).*}}
 // UNSUPPORTED: target=powerpc64le{{.*}}

MaskRay wrote:
> I added aarch64 support. You may rebase and add loongarch64 on the 
> `REQUIRES:` line.
Rebased.



Comment at: compiler-rt/test/xray/TestCases/Posix/basic-filtering.cpp:26
 //
-// REQUIRES: x86_64-target-arch
+// REQUIRES: x86_64-target-arch || loongarch64-target-arch
 // REQUIRES: built-in-llvm-tree

MaskRay wrote:
> Most `REQUIRES: x86_64-target-arch` are unnecessarily constrained. I just 
> removed them. You may rebase and avoid changes to these test files.
Rebased.



Comment at: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp:187
+  OutStreamer->emitLabel(EndOfSled);
+  recordSled(BeginOfSled, MI, Kind); // FIXME: use version 2
 }

SixWeining wrote:
> should use version 2:
> 
> ```
> recordSled(BeginOfSled, MI, Kind, 2);
> ```
Yes, updated it.



Comment at: llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll:11
+; CHECK-NEXT:  b .Lxray_sled_end0
+; CHECK-NEXT:  nop
+; CHECK-NEXT:  nop

SixWeining wrote:
> CHECK-COUNT-11
Done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140727

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-07 Thread Limin Zhang via Phabricator via cfe-commits
Ami-zhang updated this revision to Diff 538022.
Ami-zhang added a comment.

Rebase and make some improvements.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140727

Files:
  clang/lib/Driver/XRayArgs.cpp
  compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
  compiler-rt/lib/xray/CMakeLists.txt
  compiler-rt/lib/xray/xray_interface.cpp
  compiler-rt/lib/xray/xray_loongarch64.cpp
  compiler-rt/lib/xray/xray_trampoline_loongarch64.S
  compiler-rt/lib/xray/xray_tsc.h
  compiler-rt/test/xray/TestCases/Posix/c-test.cpp
  compiler-rt/test/xray/TestCases/Posix/fdr-thread-order.cpp
  llvm/lib/CodeGen/XRayInstrumentation.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
  llvm/lib/Target/LoongArch/LoongArchSubtarget.h
  llvm/lib/XRay/InstrumentationMap.cpp
  llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll

Index: llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll
@@ -0,0 +1,56 @@
+; RUN: llc --mtriple=loongarch64 %s -o - | FileCheck %s
+; RUN: llc --mtriple=loongarch64 -filetype=obj %s -o %t
+; RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=RELOC
+
+define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" {
+; CHECK-LABEL: foo:
+; CHECK-LABEL: .Lfunc_begin0:
+; CHECK:   .p2align 2
+; CHECK-LABEL: .Lxray_sled_begin0:
+; CHECK-NEXT:  b .Lxray_sled_end0
+; CHECK-COUNT-11:  nop
+; CHECK-LABEL: .Lxray_sled_end0:
+  ret i32 0
+; CHECK-LABEL: .Lxray_sled_begin1:
+; CHECK-NEXT:  b .Lxray_sled_end1
+; CHECK-COUNT-11:  nop
+; CHECK-NEXT: .Lxray_sled_end1:
+; CHECK-NEXT:  ret
+; CHECK-NEXT: .Lfunc_end0:
+}
+
+; CHECK-LABEL: .section xray_instr_map
+; CHECK-NEXT: .Lxray_sleds_start0:
+; CHECK-NEXT: .Ltmp0:
+; CHECK-NEXT: .dword .Lxray_sled_begin0-.Ltmp0
+; CHECK-NEXT: .dword .Lfunc_begin0-(.Ltmp0+8)
+; CHECK-NEXT: .byte 0x00
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x02
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: .Ltmp1:
+; CHECK-NEXT: .dword .Lxray_sled_begin1-.Ltmp1
+; CHECK-NEXT: .dword .Lfunc_begin0-(.Ltmp1+8)
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x02
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: .Lxray_sleds_end0:
+
+; CHECK-LABEL:  .section xray_fn_idx
+; CHECK-LABEL:  .Lxray_fn_idx0:
+; CHECK:  .dword .Lxray_sleds_start0-.Lxray_fn_idx0
+; CHECK-NEXT: .dword 2
+
+; RELOC:  Section ([[#]]) .relaxray_instr_map {
+; RELOC-NEXT:   0x0 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT:   0x8 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT:   0x20 R_LARCH_64_PCREL .text 0x34
+; RELOC-NEXT:   0x28 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT: }
+; RELOC-NEXT: Section ([[#]]) .relaxray_fn_idx {
+; RELOC-NEXT:   0x0 R_LARCH_64_PCREL xray_instr_map 0x0
+; RELOC-NEXT: }
+; RELOC-NEXT: Section ([[#]]) .rela.eh_frame {
+; RELOC-NEXT:   0x1C R_LARCH_32_PCREL .text 0x0
+; RELOC-NEXT: }
Index: llvm/lib/XRay/InstrumentationMap.cpp
===
--- llvm/lib/XRay/InstrumentationMap.cpp
+++ llvm/lib/XRay/InstrumentationMap.cpp
@@ -60,6 +60,7 @@
   // Find the section named "xray_instr_map".
   if ((!ObjFile.getBinary()->isELF() && !ObjFile.getBinary()->isMachO()) ||
   !(ObjFile.getBinary()->getArch() == Triple::x86_64 ||
+ObjFile.getBinary()->getArch() == Triple::loongarch64 ||
 ObjFile.getBinary()->getArch() == Triple::ppc64le ||
 ObjFile.getBinary()->getArch() == Triple::arm ||
 ObjFile.getBinary()->getArch() == Triple::aarch64))
Index: llvm/lib/Target/LoongArch/LoongArchSubtarget.h
===
--- llvm/lib/Target/LoongArch/LoongArchSubtarget.h
+++ llvm/lib/Target/LoongArch/LoongArchSubtarget.h
@@ -96,6 +96,7 @@
   MVT getGRLenVT() const { return GRLenVT; }
   unsigned getGRLen() const { return GRLen; }
   LoongArchABI::ABI getTargetABI() const { return TargetABI; }
+  bool isXRaySupported() const override { return is64Bit(); }
 };
 } // end namespace llvm
 
Index: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
===
--- llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
+++ llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
@@ -42,6 +42,9 @@
  const char *ExtraCode, raw_ostream &OS) override;
 
   void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI);
+  void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI);
+  void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI);
+  void emitSled(const MachineInstr &MI, SledKind Kind);
 
   // tblgen'erated function.
   bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
Index: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
===

[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-11 Thread Limin Zhang via Phabricator via cfe-commits
Ami-zhang added inline comments.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:22-25
+  RN_T0 = 0xC,
+  RN_T1 = 0xD,
+  RN_RA = 0x1,
+  RN_SP = 0x3,

xen0n wrote:
> I think people usually just declare the register ABI names with decimal 
> numbers for readability?
> 
> This is minor but I personally find it slightly distracting to have to think 
> about what's `0xc` in decimal (that's the case even though I'm already very 
> familiar with these kinds of thing). Not sure if others also prefer decimals 
> though...
Ok,  use decimal numbers to declare the register ABI names.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:32
+   uint32_t Imm) XRAY_NEVER_INSTRUMENT {
+  return (Opcode | Rj << 5 | Rd | Imm << 10);
+}

xen0n wrote:
> Parens not needed in this case. (If you want to enhance readability for those 
> people having difficulties remembering precedence and associativeness of 
> operators, you should instead put the parens around `Rj << 5` and `Imm << 
> 10`...)
> 
> I'd suggest re-ordering the operands too, to imitate the expected bit layout 
> of the result.
What you said makes sense. Thanks for your suggestion and attentiveness. I have 
adjusted parens and operands order.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:39
+   uint32_t Imm) XRAY_NEVER_INSTRUMENT {
+  return (Opcode | Rd | Imm << 5);
+}

xen0n wrote:
> Similarly here.
Done.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:42-47
+// Encode instructions in 2RI16 format, e.g. jirl.
+inline static uint32_t
+encodeInstruction2RI16(uint32_t Opcode, uint32_t Rd, uint32_t Rj,
+   uint32_t Imm) XRAY_NEVER_INSTRUMENT {
+  return (Opcode | Rj << 5 | Rd | Imm << 10);
+}

xen0n wrote:
> Does this look *very* similar to `encodeInstruction2RI12`? ;-)
> 
> Actually, if you don't bounds-check the operands, you only need one helper 
> for each combination of slots involved. Check for example the `static 
> uint32_t insn` implementation in my D138135, or [[ 
> https://gitlab.com/qemu-project/qemu/-/blob/master/tcg/loongarch64/tcg-insn-defs.c.inc
>  | the auto-generated encoding helpers for the QEMU TCG LoongArch64 port ]], 
> for some alternative approaches.
It is indeed similar to `encodeInstruction2RI12`. Given its exclusive use in 
this context, I prefer the unified `2RIx` format.

Thanks for the suggestion. While we appreciate it, we are more inclined to use 
one `2RIx` format helper here.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:58
+  //   11 NOPs (44 bytes)
+  //   .tmpN
+  //

xen0n wrote:
> `.tmpN:` for it to not look like a directive?
Use the real `.Lxray_sled_endN`.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:71
+  //   ori t1, t1, %abs_lo12(function_id);pass function id
+  //   jirlra, t0, 0 ;call Tracing hook
+  //   ld.dra, sp, 8 ;restore return address

xen0n wrote:
> All-lowercase i.e. `tracing` for consistency? Or am I missing something?
It should be a copy from `mips`. I think it can be written `tracing hook` or 
`TracingHook`. To maintain all-lowercase consistency here, I use `tracing hook`.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:73
+  //   ld.dra, sp, 8 ;restore return address
+  //   addi.d  sp, sp, 16;delete stack frame
+  //

xen0n wrote:
> I think idiomatically it's not "create/delete stack frame" but rather 
> "(de-)allocate" or "setup/teardown"... anyway please fix the usage of 
> articles (put the "the"'s properly) and also add a space after the `;` 
> because it's usually aesthetically better.
> 
> This is all minor though, and it's not like people will misunderstand 
> anything otherwise, but rather it's mostly just me pushing for more natural 
> English usage.
Ok, a space after the `;`   is added.  About article `the`,  i also added it. 
But i am not sure whether the usage of `the` is proper. If  there are any 
further issues , I would greatly appreciate your feedback.

Thanks for your effort.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:80
+  //
+  // When |Enable|==false, we set back the first instruction in the sled to be
+  //   B #48

xen0n wrote:
> ("set back" happens to be an idiomatic phrase verb so I got confused here for 
> ~1 second, so I think it's probably easier to just avoid this coincidence.)
Done.



Comment at: compiler-rt/lib/xray/xray_trampoline_loongarch64.S:83
+  // a1=1 means that we are tracing an exit event
+  ori $a1, $zero, 1
+  // Function ID is in t1 (the first parameter).

xen0n wrote:
> Use pseudo-instruction for idiomatic expression of inten

[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-11 Thread Limin Zhang via Phabricator via cfe-commits
Ami-zhang updated this revision to Diff 538948.
Ami-zhang added a comment.

Addressed @xen0n's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140727

Files:
  clang/lib/Driver/XRayArgs.cpp
  compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
  compiler-rt/lib/xray/CMakeLists.txt
  compiler-rt/lib/xray/xray_interface.cpp
  compiler-rt/lib/xray/xray_loongarch64.cpp
  compiler-rt/lib/xray/xray_trampoline_loongarch64.S
  compiler-rt/lib/xray/xray_tsc.h
  compiler-rt/test/xray/TestCases/Posix/c-test.cpp
  compiler-rt/test/xray/TestCases/Posix/fdr-thread-order.cpp
  llvm/lib/CodeGen/XRayInstrumentation.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
  llvm/lib/Target/LoongArch/LoongArchSubtarget.h
  llvm/lib/XRay/InstrumentationMap.cpp
  llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll

Index: llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll
@@ -0,0 +1,56 @@
+; RUN: llc --mtriple=loongarch64 %s -o - | FileCheck %s
+; RUN: llc --mtriple=loongarch64 -filetype=obj %s -o %t
+; RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=RELOC
+
+define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" {
+; CHECK-LABEL: foo:
+; CHECK-LABEL: .Lfunc_begin0:
+; CHECK:   .p2align 2
+; CHECK-LABEL: .Lxray_sled_begin0:
+; CHECK-NEXT:  b .Lxray_sled_end0
+; CHECK-COUNT-11:  nop
+; CHECK-LABEL: .Lxray_sled_end0:
+  ret i32 0
+; CHECK-LABEL: .Lxray_sled_begin1:
+; CHECK-NEXT:  b .Lxray_sled_end1
+; CHECK-COUNT-11:  nop
+; CHECK-NEXT: .Lxray_sled_end1:
+; CHECK-NEXT:  ret
+; CHECK-NEXT: .Lfunc_end0:
+}
+
+; CHECK-LABEL: .section xray_instr_map
+; CHECK-NEXT: .Lxray_sleds_start0:
+; CHECK-NEXT: .Ltmp0:
+; CHECK-NEXT: .dword .Lxray_sled_begin0-.Ltmp0
+; CHECK-NEXT: .dword .Lfunc_begin0-(.Ltmp0+8)
+; CHECK-NEXT: .byte 0x00
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x02
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: .Ltmp1:
+; CHECK-NEXT: .dword .Lxray_sled_begin1-.Ltmp1
+; CHECK-NEXT: .dword .Lfunc_begin0-(.Ltmp1+8)
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x02
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: .Lxray_sleds_end0:
+
+; CHECK-LABEL:  .section xray_fn_idx
+; CHECK-LABEL:  .Lxray_fn_idx0:
+; CHECK:  .dword .Lxray_sleds_start0-.Lxray_fn_idx0
+; CHECK-NEXT: .dword 2
+
+; RELOC:  Section ([[#]]) .relaxray_instr_map {
+; RELOC-NEXT:   0x0 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT:   0x8 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT:   0x20 R_LARCH_64_PCREL .text 0x34
+; RELOC-NEXT:   0x28 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT: }
+; RELOC-NEXT: Section ([[#]]) .relaxray_fn_idx {
+; RELOC-NEXT:   0x0 R_LARCH_64_PCREL xray_instr_map 0x0
+; RELOC-NEXT: }
+; RELOC-NEXT: Section ([[#]]) .rela.eh_frame {
+; RELOC-NEXT:   0x1C R_LARCH_32_PCREL .text 0x0
+; RELOC-NEXT: }
Index: llvm/lib/XRay/InstrumentationMap.cpp
===
--- llvm/lib/XRay/InstrumentationMap.cpp
+++ llvm/lib/XRay/InstrumentationMap.cpp
@@ -60,6 +60,7 @@
   // Find the section named "xray_instr_map".
   if ((!ObjFile.getBinary()->isELF() && !ObjFile.getBinary()->isMachO()) ||
   !(ObjFile.getBinary()->getArch() == Triple::x86_64 ||
+ObjFile.getBinary()->getArch() == Triple::loongarch64 ||
 ObjFile.getBinary()->getArch() == Triple::ppc64le ||
 ObjFile.getBinary()->getArch() == Triple::arm ||
 ObjFile.getBinary()->getArch() == Triple::aarch64))
Index: llvm/lib/Target/LoongArch/LoongArchSubtarget.h
===
--- llvm/lib/Target/LoongArch/LoongArchSubtarget.h
+++ llvm/lib/Target/LoongArch/LoongArchSubtarget.h
@@ -96,6 +96,7 @@
   MVT getGRLenVT() const { return GRLenVT; }
   unsigned getGRLen() const { return GRLen; }
   LoongArchABI::ABI getTargetABI() const { return TargetABI; }
+  bool isXRaySupported() const override { return is64Bit(); }
 };
 } // end namespace llvm
 
Index: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
===
--- llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
+++ llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
@@ -42,6 +42,9 @@
  const char *ExtraCode, raw_ostream &OS) override;
 
   void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI);
+  void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI);
+  void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI);
+  void emitSled(const MachineInstr &MI, SledKind Kind);
 
   // tblgen'erated function.
   bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
Index: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
===
--- ll

[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-12 Thread Limin Zhang via Phabricator via cfe-commits
Ami-zhang added inline comments.



Comment at: compiler-rt/lib/xray/xray_loongarch64.cpp:30
+// are 2RI12-type and 2RI16-type.
+inline static uint32_t
+encodeInstruction2RIx(uint32_t Opcode, uint32_t Rd, uint32_t Rj,

MaskRay wrote:
> Early xray code unfortunately does not respect the conventional style that 
> well.
> The usual order is `static inline`
Done, adjusted to `static inline`.



Comment at: compiler-rt/lib/xray/xray_trampoline_loongarch64.S:20
+  .type __xray_FunctionEntry,@function
+__xray_FunctionEntry:
+  .cfi_startproc

MaskRay wrote:
> The symbol needs to be hidden and consider using some macros. See 
> xray_trampoline_AArch64.S
> 
Ok, I have modified them.
Thanks for your suggestion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140727

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-12 Thread Limin Zhang via Phabricator via cfe-commits
Ami-zhang updated this revision to Diff 539465.
Ami-zhang added a comment.

Hide some symbols and using some macros in asm.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140727

Files:
  clang/lib/Driver/XRayArgs.cpp
  compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
  compiler-rt/lib/xray/CMakeLists.txt
  compiler-rt/lib/xray/xray_interface.cpp
  compiler-rt/lib/xray/xray_loongarch64.cpp
  compiler-rt/lib/xray/xray_trampoline_loongarch64.S
  compiler-rt/lib/xray/xray_tsc.h
  compiler-rt/test/xray/TestCases/Posix/c-test.cpp
  compiler-rt/test/xray/TestCases/Posix/fdr-thread-order.cpp
  llvm/lib/CodeGen/XRayInstrumentation.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
  llvm/lib/Target/LoongArch/LoongArchSubtarget.h
  llvm/lib/XRay/InstrumentationMap.cpp
  llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll

Index: llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll
@@ -0,0 +1,56 @@
+; RUN: llc --mtriple=loongarch64 %s -o - | FileCheck %s
+; RUN: llc --mtriple=loongarch64 -filetype=obj %s -o %t
+; RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=RELOC
+
+define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" {
+; CHECK-LABEL: foo:
+; CHECK-LABEL: .Lfunc_begin0:
+; CHECK:   .p2align 2
+; CHECK-LABEL: .Lxray_sled_begin0:
+; CHECK-NEXT:  b .Lxray_sled_end0
+; CHECK-COUNT-11:  nop
+; CHECK-LABEL: .Lxray_sled_end0:
+  ret i32 0
+; CHECK-LABEL: .Lxray_sled_begin1:
+; CHECK-NEXT:  b .Lxray_sled_end1
+; CHECK-COUNT-11:  nop
+; CHECK-NEXT: .Lxray_sled_end1:
+; CHECK-NEXT:  ret
+; CHECK-NEXT: .Lfunc_end0:
+}
+
+; CHECK-LABEL: .section xray_instr_map
+; CHECK-NEXT: .Lxray_sleds_start0:
+; CHECK-NEXT: .Ltmp0:
+; CHECK-NEXT: .dword .Lxray_sled_begin0-.Ltmp0
+; CHECK-NEXT: .dword .Lfunc_begin0-(.Ltmp0+8)
+; CHECK-NEXT: .byte 0x00
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x02
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: .Ltmp1:
+; CHECK-NEXT: .dword .Lxray_sled_begin1-.Ltmp1
+; CHECK-NEXT: .dword .Lfunc_begin0-(.Ltmp1+8)
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x02
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: .Lxray_sleds_end0:
+
+; CHECK-LABEL:  .section xray_fn_idx
+; CHECK-LABEL:  .Lxray_fn_idx0:
+; CHECK:  .dword .Lxray_sleds_start0-.Lxray_fn_idx0
+; CHECK-NEXT: .dword 2
+
+; RELOC:  Section ([[#]]) .relaxray_instr_map {
+; RELOC-NEXT:   0x0 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT:   0x8 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT:   0x20 R_LARCH_64_PCREL .text 0x34
+; RELOC-NEXT:   0x28 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT: }
+; RELOC-NEXT: Section ([[#]]) .relaxray_fn_idx {
+; RELOC-NEXT:   0x0 R_LARCH_64_PCREL xray_instr_map 0x0
+; RELOC-NEXT: }
+; RELOC-NEXT: Section ([[#]]) .rela.eh_frame {
+; RELOC-NEXT:   0x1C R_LARCH_32_PCREL .text 0x0
+; RELOC-NEXT: }
Index: llvm/lib/XRay/InstrumentationMap.cpp
===
--- llvm/lib/XRay/InstrumentationMap.cpp
+++ llvm/lib/XRay/InstrumentationMap.cpp
@@ -60,6 +60,7 @@
   // Find the section named "xray_instr_map".
   if ((!ObjFile.getBinary()->isELF() && !ObjFile.getBinary()->isMachO()) ||
   !(ObjFile.getBinary()->getArch() == Triple::x86_64 ||
+ObjFile.getBinary()->getArch() == Triple::loongarch64 ||
 ObjFile.getBinary()->getArch() == Triple::ppc64le ||
 ObjFile.getBinary()->getArch() == Triple::arm ||
 ObjFile.getBinary()->getArch() == Triple::aarch64))
Index: llvm/lib/Target/LoongArch/LoongArchSubtarget.h
===
--- llvm/lib/Target/LoongArch/LoongArchSubtarget.h
+++ llvm/lib/Target/LoongArch/LoongArchSubtarget.h
@@ -96,6 +96,7 @@
   MVT getGRLenVT() const { return GRLenVT; }
   unsigned getGRLen() const { return GRLen; }
   LoongArchABI::ABI getTargetABI() const { return TargetABI; }
+  bool isXRaySupported() const override { return is64Bit(); }
 };
 } // end namespace llvm
 
Index: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
===
--- llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
+++ llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
@@ -42,6 +42,9 @@
  const char *ExtraCode, raw_ostream &OS) override;
 
   void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI);
+  void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI);
+  void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI);
+  void emitSled(const MachineInstr &MI, SledKind Kind);
 
   // tblgen'erated function.
   bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
Index: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
===

[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-12 Thread Limin Zhang via Phabricator via cfe-commits
Ami-zhang added inline comments.



Comment at: llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll:24
+; CHECK-NEXT: .Lxray_sleds_start0:
+; CHECK-NEXT: .Ltmp0:
+; CHECK-NEXT: .dword .Lxray_sled_begin0-.Ltmp0

MaskRay wrote:
> See `llvm/test/CodeGen/X86/xray-attribute-instrumentation.ll`. I use 
> something like `[[TMP:.Ltmp[0-9]+]]:` so that we don't need to adjust the 
> test if the compiler happens to produce more `.Ltmp*` symbols.
Done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140727

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-12 Thread Limin Zhang via Phabricator via cfe-commits
Ami-zhang updated this revision to Diff 539818.
Ami-zhang added a comment.

Make xray-attribute-instrumentation.ll less sensitive to .Ltmp/.Lxray_fn_idx 
label changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140727

Files:
  clang/lib/Driver/XRayArgs.cpp
  compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
  compiler-rt/lib/xray/CMakeLists.txt
  compiler-rt/lib/xray/xray_interface.cpp
  compiler-rt/lib/xray/xray_loongarch64.cpp
  compiler-rt/lib/xray/xray_trampoline_loongarch64.S
  compiler-rt/lib/xray/xray_tsc.h
  compiler-rt/test/xray/TestCases/Posix/c-test.cpp
  compiler-rt/test/xray/TestCases/Posix/fdr-thread-order.cpp
  llvm/lib/CodeGen/XRayInstrumentation.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
  llvm/lib/Target/LoongArch/LoongArchSubtarget.h
  llvm/lib/XRay/InstrumentationMap.cpp
  llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll

Index: llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll
@@ -0,0 +1,56 @@
+; RUN: llc --mtriple=loongarch64 %s -o - | FileCheck %s
+; RUN: llc --mtriple=loongarch64 -filetype=obj %s -o %t
+; RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=RELOC
+
+define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" {
+; CHECK-LABEL: foo:
+; CHECK-LABEL: .Lfunc_begin0:
+; CHECK:   .p2align 2
+; CHECK-LABEL: .Lxray_sled_begin0:
+; CHECK-NEXT:  b .Lxray_sled_end0
+; CHECK-COUNT-11:  nop
+; CHECK-LABEL: .Lxray_sled_end0:
+  ret i32 0
+; CHECK-LABEL: .Lxray_sled_begin1:
+; CHECK-NEXT:  b .Lxray_sled_end1
+; CHECK-COUNT-11:  nop
+; CHECK-NEXT: .Lxray_sled_end1:
+; CHECK-NEXT:  ret
+; CHECK-NEXT: .Lfunc_end0:
+}
+
+; CHECK-LABEL: .section xray_instr_map
+; CHECK-NEXT: .Lxray_sleds_start0:
+; CHECK-NEXT: [[TMP:.Ltmp[0-9]+]]:
+; CHECK-NEXT: .dword .Lxray_sled_begin0-[[TMP]]
+; CHECK-NEXT: .dword .Lfunc_begin0-([[TMP]]+8)
+; CHECK-NEXT: .byte 0x00
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x02
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: [[TMP:.Ltmp[0-9]+]]:
+; CHECK-NEXT: .dword .Lxray_sled_begin1-[[TMP]]
+; CHECK-NEXT: .dword .Lfunc_begin0-([[TMP]]+8)
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x02
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: .Lxray_sleds_end0:
+
+; CHECK-LABEL:  .section xray_fn_idx
+; CHECK:  [[IDX:\.Lxray_fn_idx[0-9]+]]:
+; CHECK:  .dword .Lxray_sleds_start0-[[IDX]]
+; CHECK-NEXT: .dword 2
+
+; RELOC:  Section ([[#]]) .relaxray_instr_map {
+; RELOC-NEXT:   0x0 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT:   0x8 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT:   0x20 R_LARCH_64_PCREL .text 0x34
+; RELOC-NEXT:   0x28 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT: }
+; RELOC-NEXT: Section ([[#]]) .relaxray_fn_idx {
+; RELOC-NEXT:   0x0 R_LARCH_64_PCREL xray_instr_map 0x0
+; RELOC-NEXT: }
+; RELOC-NEXT: Section ([[#]]) .rela.eh_frame {
+; RELOC-NEXT:   0x1C R_LARCH_32_PCREL .text 0x0
+; RELOC-NEXT: }
Index: llvm/lib/XRay/InstrumentationMap.cpp
===
--- llvm/lib/XRay/InstrumentationMap.cpp
+++ llvm/lib/XRay/InstrumentationMap.cpp
@@ -60,6 +60,7 @@
   // Find the section named "xray_instr_map".
   if ((!ObjFile.getBinary()->isELF() && !ObjFile.getBinary()->isMachO()) ||
   !(ObjFile.getBinary()->getArch() == Triple::x86_64 ||
+ObjFile.getBinary()->getArch() == Triple::loongarch64 ||
 ObjFile.getBinary()->getArch() == Triple::ppc64le ||
 ObjFile.getBinary()->getArch() == Triple::arm ||
 ObjFile.getBinary()->getArch() == Triple::aarch64))
Index: llvm/lib/Target/LoongArch/LoongArchSubtarget.h
===
--- llvm/lib/Target/LoongArch/LoongArchSubtarget.h
+++ llvm/lib/Target/LoongArch/LoongArchSubtarget.h
@@ -96,6 +96,7 @@
   MVT getGRLenVT() const { return GRLenVT; }
   unsigned getGRLen() const { return GRLen; }
   LoongArchABI::ABI getTargetABI() const { return TargetABI; }
+  bool isXRaySupported() const override { return is64Bit(); }
 };
 } // end namespace llvm
 
Index: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
===
--- llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
+++ llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
@@ -42,6 +42,9 @@
  const char *ExtraCode, raw_ostream &OS) override;
 
   void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI);
+  void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI);
+  void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI);
+  void emitSled(const MachineInstr &MI, SledKind Kind);
 
   // tblgen'erated function.
   bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
Index: llvm/lib/Target/LoongArch/

[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-12 Thread Limin Zhang via Phabricator via cfe-commits
Ami-zhang updated this revision to Diff 539836.
Ami-zhang added a comment.

Remove unnecessary '\' symbol in xray-attribute-instrumentation.ll


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140727

Files:
  clang/lib/Driver/XRayArgs.cpp
  compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
  compiler-rt/lib/xray/CMakeLists.txt
  compiler-rt/lib/xray/xray_interface.cpp
  compiler-rt/lib/xray/xray_loongarch64.cpp
  compiler-rt/lib/xray/xray_trampoline_loongarch64.S
  compiler-rt/lib/xray/xray_tsc.h
  compiler-rt/test/xray/TestCases/Posix/c-test.cpp
  compiler-rt/test/xray/TestCases/Posix/fdr-thread-order.cpp
  llvm/lib/CodeGen/XRayInstrumentation.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
  llvm/lib/Target/LoongArch/LoongArchSubtarget.h
  llvm/lib/XRay/InstrumentationMap.cpp
  llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll

Index: llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll
@@ -0,0 +1,56 @@
+; RUN: llc --mtriple=loongarch64 %s -o - | FileCheck %s
+; RUN: llc --mtriple=loongarch64 -filetype=obj %s -o %t
+; RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=RELOC
+
+define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" {
+; CHECK-LABEL: foo:
+; CHECK-LABEL: .Lfunc_begin0:
+; CHECK:   .p2align 2
+; CHECK-LABEL: .Lxray_sled_begin0:
+; CHECK-NEXT:  b .Lxray_sled_end0
+; CHECK-COUNT-11:  nop
+; CHECK-LABEL: .Lxray_sled_end0:
+  ret i32 0
+; CHECK-LABEL: .Lxray_sled_begin1:
+; CHECK-NEXT:  b .Lxray_sled_end1
+; CHECK-COUNT-11:  nop
+; CHECK-NEXT: .Lxray_sled_end1:
+; CHECK-NEXT:  ret
+; CHECK-NEXT: .Lfunc_end0:
+}
+
+; CHECK-LABEL: .section xray_instr_map
+; CHECK-NEXT: .Lxray_sleds_start0:
+; CHECK-NEXT: [[TMP:.Ltmp[0-9]+]]:
+; CHECK-NEXT: .dword .Lxray_sled_begin0-[[TMP]]
+; CHECK-NEXT: .dword .Lfunc_begin0-([[TMP]]+8)
+; CHECK-NEXT: .byte 0x00
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x02
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: [[TMP:.Ltmp[0-9]+]]:
+; CHECK-NEXT: .dword .Lxray_sled_begin1-[[TMP]]
+; CHECK-NEXT: .dword .Lfunc_begin0-([[TMP]]+8)
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x02
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: .Lxray_sleds_end0:
+
+; CHECK-LABEL:  .section xray_fn_idx
+; CHECK:  [[IDX:.Lxray_fn_idx[0-9]+]]:
+; CHECK:  .dword .Lxray_sleds_start0-[[IDX]]
+; CHECK-NEXT: .dword 2
+
+; RELOC:  Section ([[#]]) .relaxray_instr_map {
+; RELOC-NEXT:   0x0 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT:   0x8 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT:   0x20 R_LARCH_64_PCREL .text 0x34
+; RELOC-NEXT:   0x28 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT: }
+; RELOC-NEXT: Section ([[#]]) .relaxray_fn_idx {
+; RELOC-NEXT:   0x0 R_LARCH_64_PCREL xray_instr_map 0x0
+; RELOC-NEXT: }
+; RELOC-NEXT: Section ([[#]]) .rela.eh_frame {
+; RELOC-NEXT:   0x1C R_LARCH_32_PCREL .text 0x0
+; RELOC-NEXT: }
Index: llvm/lib/XRay/InstrumentationMap.cpp
===
--- llvm/lib/XRay/InstrumentationMap.cpp
+++ llvm/lib/XRay/InstrumentationMap.cpp
@@ -60,6 +60,7 @@
   // Find the section named "xray_instr_map".
   if ((!ObjFile.getBinary()->isELF() && !ObjFile.getBinary()->isMachO()) ||
   !(ObjFile.getBinary()->getArch() == Triple::x86_64 ||
+ObjFile.getBinary()->getArch() == Triple::loongarch64 ||
 ObjFile.getBinary()->getArch() == Triple::ppc64le ||
 ObjFile.getBinary()->getArch() == Triple::arm ||
 ObjFile.getBinary()->getArch() == Triple::aarch64))
Index: llvm/lib/Target/LoongArch/LoongArchSubtarget.h
===
--- llvm/lib/Target/LoongArch/LoongArchSubtarget.h
+++ llvm/lib/Target/LoongArch/LoongArchSubtarget.h
@@ -96,6 +96,7 @@
   MVT getGRLenVT() const { return GRLenVT; }
   unsigned getGRLen() const { return GRLen; }
   LoongArchABI::ABI getTargetABI() const { return TargetABI; }
+  bool isXRaySupported() const override { return is64Bit(); }
 };
 } // end namespace llvm
 
Index: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
===
--- llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
+++ llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
@@ -42,6 +42,9 @@
  const char *ExtraCode, raw_ostream &OS) override;
 
   void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI);
+  void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI);
+  void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI);
+  void emitSled(const MachineInstr &MI, SledKind Kind);
 
   // tblgen'erated function.
   bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
Index: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
==

[PATCH] D140727: [XRay] Add initial support for loongarch64

2023-07-13 Thread Limin Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGef33d6cbfc2d: [XRay] Add initial support for loongarch64 
(authored by SixWeining, committed by Ami-zhang).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140727

Files:
  clang/lib/Driver/XRayArgs.cpp
  compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
  compiler-rt/lib/xray/CMakeLists.txt
  compiler-rt/lib/xray/xray_interface.cpp
  compiler-rt/lib/xray/xray_loongarch64.cpp
  compiler-rt/lib/xray/xray_trampoline_loongarch64.S
  compiler-rt/lib/xray/xray_tsc.h
  compiler-rt/test/xray/TestCases/Posix/c-test.cpp
  compiler-rt/test/xray/TestCases/Posix/fdr-thread-order.cpp
  llvm/lib/CodeGen/XRayInstrumentation.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
  llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
  llvm/lib/Target/LoongArch/LoongArchSubtarget.h
  llvm/lib/XRay/InstrumentationMap.cpp
  llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll

Index: llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/xray-attribute-instrumentation.ll
@@ -0,0 +1,56 @@
+; RUN: llc --mtriple=loongarch64 %s -o - | FileCheck %s
+; RUN: llc --mtriple=loongarch64 -filetype=obj %s -o %t
+; RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=RELOC
+
+define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" {
+; CHECK-LABEL: foo:
+; CHECK-LABEL: .Lfunc_begin0:
+; CHECK:   .p2align 2
+; CHECK-LABEL: .Lxray_sled_begin0:
+; CHECK-NEXT:  b .Lxray_sled_end0
+; CHECK-COUNT-11:  nop
+; CHECK-LABEL: .Lxray_sled_end0:
+  ret i32 0
+; CHECK-LABEL: .Lxray_sled_begin1:
+; CHECK-NEXT:  b .Lxray_sled_end1
+; CHECK-COUNT-11:  nop
+; CHECK-NEXT: .Lxray_sled_end1:
+; CHECK-NEXT:  ret
+; CHECK-NEXT: .Lfunc_end0:
+}
+
+; CHECK-LABEL: .section xray_instr_map
+; CHECK-NEXT: .Lxray_sleds_start0:
+; CHECK-NEXT: [[TMP:.Ltmp[0-9]+]]:
+; CHECK-NEXT: .dword .Lxray_sled_begin0-[[TMP]]
+; CHECK-NEXT: .dword .Lfunc_begin0-([[TMP]]+8)
+; CHECK-NEXT: .byte 0x00
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x02
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: [[TMP:.Ltmp[0-9]+]]:
+; CHECK-NEXT: .dword .Lxray_sled_begin1-[[TMP]]
+; CHECK-NEXT: .dword .Lfunc_begin0-([[TMP]]+8)
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x01
+; CHECK-NEXT: .byte 0x02
+; CHECK-NEXT: .space 13
+; CHECK-NEXT: .Lxray_sleds_end0:
+
+; CHECK-LABEL:  .section xray_fn_idx
+; CHECK:  [[IDX:.Lxray_fn_idx[0-9]+]]:
+; CHECK:  .dword .Lxray_sleds_start0-[[IDX]]
+; CHECK-NEXT: .dword 2
+
+; RELOC:  Section ([[#]]) .relaxray_instr_map {
+; RELOC-NEXT:   0x0 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT:   0x8 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT:   0x20 R_LARCH_64_PCREL .text 0x34
+; RELOC-NEXT:   0x28 R_LARCH_64_PCREL .text 0x0
+; RELOC-NEXT: }
+; RELOC-NEXT: Section ([[#]]) .relaxray_fn_idx {
+; RELOC-NEXT:   0x0 R_LARCH_64_PCREL xray_instr_map 0x0
+; RELOC-NEXT: }
+; RELOC-NEXT: Section ([[#]]) .rela.eh_frame {
+; RELOC-NEXT:   0x1C R_LARCH_32_PCREL .text 0x0
+; RELOC-NEXT: }
Index: llvm/lib/XRay/InstrumentationMap.cpp
===
--- llvm/lib/XRay/InstrumentationMap.cpp
+++ llvm/lib/XRay/InstrumentationMap.cpp
@@ -60,6 +60,7 @@
   // Find the section named "xray_instr_map".
   if ((!ObjFile.getBinary()->isELF() && !ObjFile.getBinary()->isMachO()) ||
   !(ObjFile.getBinary()->getArch() == Triple::x86_64 ||
+ObjFile.getBinary()->getArch() == Triple::loongarch64 ||
 ObjFile.getBinary()->getArch() == Triple::ppc64le ||
 ObjFile.getBinary()->getArch() == Triple::arm ||
 ObjFile.getBinary()->getArch() == Triple::aarch64))
Index: llvm/lib/Target/LoongArch/LoongArchSubtarget.h
===
--- llvm/lib/Target/LoongArch/LoongArchSubtarget.h
+++ llvm/lib/Target/LoongArch/LoongArchSubtarget.h
@@ -96,6 +96,7 @@
   MVT getGRLenVT() const { return GRLenVT; }
   unsigned getGRLen() const { return GRLen; }
   LoongArchABI::ABI getTargetABI() const { return TargetABI; }
+  bool isXRaySupported() const override { return is64Bit(); }
 };
 } // end namespace llvm
 
Index: llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
===
--- llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
+++ llvm/lib/Target/LoongArch/LoongArchAsmPrinter.h
@@ -42,6 +42,9 @@
  const char *ExtraCode, raw_ostream &OS) override;
 
   void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI);
+  void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI);
+  void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI);
+  void emitSled(const MachineInstr &MI, SledKind Kind);
 
   // tblgen'erated function.
   bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
In

[PATCH] D140690: [dfsan] Support Linux loongarch64

2023-06-29 Thread Limin Zhang via Phabricator via cfe-commits
Ami-zhang updated this revision to Diff 536091.
Ami-zhang retitled this revision from "[compiler-rt][dfsan] Enable loongarch64 
and add test support" to "[dfsan] Support Linux loongarch64".
Ami-zhang edited the summary of this revision.
Ami-zhang added a comment.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140690

Files:
  clang/lib/Driver/ToolChains/Linux.cpp
  compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
  compiler-rt/test/dfsan/lit.cfg.py
  llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp


Index: llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
@@ -305,6 +305,14 @@
 };
 // NOLINTEND(readability-identifier-naming)
 
+// loongarch64 Linux
+const MemoryMapParams Linux_LoongArch64_MemoryMapParams = {
+0,  // AndMask (not used)
+0x5000, // XorMask
+0,  // ShadowBase (not used)
+0x1000, // OriginBase
+};
+
 namespace {
 
 class DFSanABIList {
@@ -1128,6 +1136,9 @@
   case Triple::x86_64:
 MapParams = &Linux_X86_64_MemoryMapParams;
 break;
+  case Triple::loongarch64:
+MapParams = &Linux_LoongArch64_MemoryMapParams;
+break;
   default:
 report_fatal_error("unsupported architecture");
   }
Index: compiler-rt/test/dfsan/lit.cfg.py
===
--- compiler-rt/test/dfsan/lit.cfg.py
+++ compiler-rt/test/dfsan/lit.cfg.py
@@ -25,5 +25,5 @@
 config.suffixes = [".c", ".cpp"]
 
 # DataFlowSanitizer tests are currently supported on Linux only.
-if not (config.host_os in ["Linux"] and config.target_arch in ["aarch64", 
"x86_64"]):
+if not (config.host_os in ["Linux"] and config.target_arch in ["aarch64", 
"x86_64", "loongarch64"]):
 config.unsupported = True
Index: compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
===
--- compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -30,7 +30,7 @@
 ${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
 ${LOONGARCH64})
 set(ALL_ASAN_ABI_SUPPORTED_ARCH ${X86_64} ${ARM64})
-set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
+set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${LOONGARCH64})
 
 if(ANDROID)
   set(OS_NAME "Android")
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -795,7 +795,7 @@
   Res |= SanitizerKind::Memory;
   Res |= SanitizerKind::Vptr;
   Res |= SanitizerKind::SafeStack;
-  if (IsX86_64 || IsMIPS64 || IsAArch64)
+  if (IsX86_64 || IsMIPS64 || IsAArch64 || IsLoongArch64)
 Res |= SanitizerKind::DataFlow;
   if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86 || IsArmArch || IsPowerPC64 ||
   IsRISCV64 || IsSystemZ || IsHexagon || IsLoongArch64)


Index: llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
@@ -305,6 +305,14 @@
 };
 // NOLINTEND(readability-identifier-naming)
 
+// loongarch64 Linux
+const MemoryMapParams Linux_LoongArch64_MemoryMapParams = {
+0,  // AndMask (not used)
+0x5000, // XorMask
+0,  // ShadowBase (not used)
+0x1000, // OriginBase
+};
+
 namespace {
 
 class DFSanABIList {
@@ -1128,6 +1136,9 @@
   case Triple::x86_64:
 MapParams = &Linux_X86_64_MemoryMapParams;
 break;
+  case Triple::loongarch64:
+MapParams = &Linux_LoongArch64_MemoryMapParams;
+break;
   default:
 report_fatal_error("unsupported architecture");
   }
Index: compiler-rt/test/dfsan/lit.cfg.py
===
--- compiler-rt/test/dfsan/lit.cfg.py
+++ compiler-rt/test/dfsan/lit.cfg.py
@@ -25,5 +25,5 @@
 config.suffixes = [".c", ".cpp"]
 
 # DataFlowSanitizer tests are currently supported on Linux only.
-if not (config.host_os in ["Linux"] and config.target_arch in ["aarch64", "x86_64"]):
+if not (config.host_os in ["Linux"] and config.target_arch in ["aarch64", "x86_64", "loongarch64"]):
 config.unsupported = True
Index: compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
===
--- compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -30,7 +30,7 @@
 ${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SP