Skip to content

Commit

Permalink
Return when unreachable
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasSte committed Jan 14, 2025
1 parent eb621c8 commit aab89b8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
29 changes: 17 additions & 12 deletions llvm/lib/Target/SBF/SBFISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "llvm/IR/DiagnosticPrinter.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"

using namespace llvm;

#define DEBUG_TYPE "sbf-lower"
Expand All @@ -39,18 +40,6 @@ static void fail(const SDLoc &DL, SelectionDAG &DAG, const Twine &Msg) {
DiagnosticInfoUnsupported(MF.getFunction(), Msg, DL.getDebugLoc()));
}

static void fail(const SDLoc &DL, SelectionDAG &DAG, const char *Msg,
SDValue Val) {
MachineFunction &MF = DAG.getMachineFunction();
std::string Str;
raw_string_ostream OS(Str);
OS << Msg;
Val->print(OS);
OS.flush();
DAG.getContext()->diagnose(
DiagnosticInfoUnsupported(MF.getFunction(), Str, DL.getDebugLoc()));
}

SBFTargetLowering::SBFTargetLowering(const TargetMachine &TM,
const SBFSubtarget &STI)
: TargetLowering(TM), Subtarget(&STI) {
Expand All @@ -65,6 +54,9 @@ SBFTargetLowering::SBFTargetLowering(const TargetMachine &TM,

setStackPointerRegisterToSaveRestore(SBF::R10);

if (STI.getHasStaticSyscalls())
setOperationAction(ISD::TRAP, MVT::Other, Custom);

setOperationAction(ISD::BR_CC, MVT::i64, Custom);
setOperationAction(ISD::BR_JT, MVT::Other, Expand);
setOperationAction(ISD::BRIND, MVT::Other, Expand);
Expand Down Expand Up @@ -339,6 +331,17 @@ SDValue SBFTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
return SDValue();
case ISD::DYNAMIC_STACKALLOC:
report_fatal_error("Unsupported dynamic stack allocation");
case ISD::TRAP:
{
SDValue Callee = DAG.getConstant(1, SDLoc(Op), MVT::i64);
SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
SmallVector<SDValue, 2> Ops;
Ops.push_back(Op.getOperand(0));
Ops.push_back(Callee);
SDValue call = DAG.getNode(SBFISD::CALL, SDLoc(Op), NodeTys, Ops);
SDValue val = DAG.getNode(SBFISD::TRAP_RET, SDLoc(Op), MVT::Other, call);
return val;
}
default:
llvm_unreachable("unimplemented operation");
}
Expand Down Expand Up @@ -925,6 +928,8 @@ const char *SBFTargetLowering::getTargetNodeName(unsigned Opcode) const {
return "SBFISD::Wrapper";
case SBFISD::MEMCPY:
return "SBFISD::MEMCPY";
case SBFISD::TRAP_RET:
return "SBFISD::TRAP_RET";
}
return nullptr;
}
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/SBF/SBFISelLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum NodeType : unsigned {
BR_CC,
Wrapper,
MEMCPY,
TRAP_RET,
};
}

Expand Down
5 changes: 4 additions & 1 deletion llvm/lib/Target/SBF/SBFInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ def SDT_SBFMEMCPY : SDTypeProfile<0, 4, [SDTCisVT<0, i64>,
SDTCisVT<1, i64>,
SDTCisVT<2, i64>,
SDTCisVT<3, i64>]>;

def SBFcall : SDNode<"SBFISD::CALL", SDT_SBFCall,
[SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
SDNPVariadic]>;
def SBFretglue : SDNode<"SBFISD::RET_GLUE", SDTNone,
[SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
def SBFtrapglue : SDNode<"SBFISD::TRAP_RET", SDTNone, [SDNPHasChain]>;

def SBFcallseq_start: SDNode<"ISD::CALLSEQ_START", SDT_SBFCallSeqStart,
[SDNPHasChain, SDNPOutGlue]>;
def SBFcallseq_end : SDNode<"ISD::CALLSEQ_END", SDT_SBFCallSeqEnd,
Expand Down Expand Up @@ -900,6 +901,8 @@ let isReturn = 1, isTerminator = 1, hasDelaySlot=0, isBarrier = 1,
def RETURN_v3 : RETURN<"return">;
}

def : Pat<(SBFtrapglue), (RETURN_v3)>, Requires<[SBFHasStaticSyscalls]>;

// ADJCALLSTACKDOWN/UP pseudo insns
let Defs = [R10], Uses = [R10], isCodeGenOnly = 1 in {
def ADJCALLSTACKDOWN : Pseudo<(outs), (ins i64imm:$amt1, i64imm:$amt2),
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/SBF/SBFTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ SBFTargetMachine::SBFTargetMachine(const Target &T, const Triple &TT,
static_cast<SBFMCAsmInfo *>(const_cast<MCAsmInfo *>(AsmInfo.get()));
MAI->setDwarfUsesRelocationsAcrossSections(!Subtarget.getUseDwarfRIS());
MAI->setSupportsDebugInformation(true);
this->Options.TrapUnreachable = true;
}

namespace {
Expand Down

0 comments on commit aab89b8

Please sign in to comment.