[llvm] 1ff630d - [LLVM][NVPTX] Add support for brkpt instruction (#104470)

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 16 21:30:27 PDT 2024


Author: Pradeep Kumar
Date: 2024-08-17T10:00:24+05:30
New Revision: 1ff630d5c32e73f5346e5cac0392762c11d1323d

URL: https://github.com/llvm/llvm-project/commit/1ff630d5c32e73f5346e5cac0392762c11d1323d
DIFF: https://github.com/llvm/llvm-project/commit/1ff630d5c32e73f5346e5cac0392762c11d1323d.diff

LOG: [LLVM][NVPTX] Add support for brkpt instruction (#104470)

This commit adds NVPTX codegen support for brkpt instruction
(https://docs.nvidia.com/cuda/parallel-thread-execution/#miscellaneous-instructions-brkpt)
with test under CodeGen/NVPTX/brkpt.ll

Added: 
    llvm/test/CodeGen/NVPTX/brkpt.ll

Modified: 
    llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
    llvm/lib/Target/NVPTX/NVPTXInstrInfo.td

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
index 43a3fbf4d1306a..577141299b9496 100644
--- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
@@ -648,6 +648,8 @@ NVPTXTargetLowering::NVPTXTargetLowering(const NVPTXTargetMachine &TM,
 
   // TRAP can be lowered to PTX trap
   setOperationAction(ISD::TRAP, MVT::Other, Legal);
+  // DEBUGTRAP can be lowered to PTX brkpt
+  setOperationAction(ISD::DEBUGTRAP, MVT::Other, Legal);
 
   // Register custom handling for vector loads/stores
   for (MVT VT : MVT::fixedlen_vector_valuetypes()) {

diff  --git a/llvm/lib/Target/NVPTX/NVPTXInstrInfo.td b/llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
index b57c86fcf697cd..1c116c496658df 100644
--- a/llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
+++ b/llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
@@ -3845,6 +3845,8 @@ def Callseq_End :
 // Emit an `exit` as well to convey to ptxas that `trap` exits the CFG.
 // This won't be necessary in a future version of ptxas.
 def trapinst : NVPTXInst<(outs), (ins), "trap; exit;", [(trap)]>;
+// brkpt instruction
+def debugtrapinst : NVPTXInst<(outs), (ins), "brkpt;", [(debugtrap)]>;
 
 // Call prototype wrapper
 def SDTCallPrototype : SDTypeProfile<0, 1, [SDTCisInt<0>]>;

diff  --git a/llvm/test/CodeGen/NVPTX/brkpt.ll b/llvm/test/CodeGen/NVPTX/brkpt.ll
new file mode 100644
index 00000000000000..beb2ff6aed6c9c
--- /dev/null
+++ b/llvm/test/CodeGen/NVPTX/brkpt.ll
@@ -0,0 +1,8 @@
+; RUN: llc -o - -march=nvptx64 %s | FileCheck %s
+
+; CHECK-LABEL: .func breakpoint
+define void @breakpoint() {
+  ; CHECK: brkpt;
+  call void @llvm.debugtrap()
+  ret void
+}


        


More information about the llvm-commits mailing list