Index: head/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVISelLowering.cpp =================================================================== --- head/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ head/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -185,6 +185,9 @@ setOperationAction(ISD::READCYCLECOUNTER, MVT::i64, Subtarget.is64Bit() ? Legal : Custom); + setOperationAction(ISD::TRAP, MVT::Other, Legal); + setOperationAction(ISD::DEBUGTRAP, MVT::Other, Legal); + if (Subtarget.hasStdExtA()) { setMaxAtomicSizeInBitsSupported(Subtarget.getXLen()); setMinCmpXchgSizeInBits(32); Index: head/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVInstrInfo.td =================================================================== --- head/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVInstrInfo.td +++ head/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVInstrInfo.td @@ -1075,6 +1075,16 @@ mayLoad = 0, mayStore = 0, hasNoSchedulingInfo = 1 in def ReadCycleWide : Pseudo<(outs GPR:$lo, GPR:$hi), (ins), [], "", "">; +/// traps + +// We lower `trap` to `unimp`, as this causes a hard exception on nearly all +// systems. +def : Pat<(trap), (UNIMP)>; + +// We lower `debugtrap` to `ebreak`, as this will get the attention of the +// debugger if possible. +def : Pat<(debugtrap), (EBREAK)>; + //===----------------------------------------------------------------------===// // Standard extensions //===----------------------------------------------------------------------===//