summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/lib/Target/BPF/BPFISelLowering.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/lib/Target/BPF/BPFISelLowering.cpp')
-rw-r--r--contrib/llvm/lib/Target/BPF/BPFISelLowering.cpp75
1 files changed, 43 insertions, 32 deletions
diff --git a/contrib/llvm/lib/Target/BPF/BPFISelLowering.cpp b/contrib/llvm/lib/Target/BPF/BPFISelLowering.cpp
index cca3492..81b0aa7 100644
--- a/contrib/llvm/lib/Target/BPF/BPFISelLowering.cpp
+++ b/contrib/llvm/lib/Target/BPF/BPFISelLowering.cpp
@@ -33,7 +33,7 @@ using namespace llvm;
#define DEBUG_TYPE "bpf-lower"
-static void fail(const SDLoc &DL, SelectionDAG &DAG, const char *Msg) {
+static void fail(const SDLoc &DL, SelectionDAG &DAG, const Twine &Msg) {
MachineFunction &MF = DAG.getMachineFunction();
DAG.getContext()->diagnose(
DiagnosticInfoUnsupported(*MF.getFunction(), Msg, DL.getDebugLoc()));
@@ -132,6 +132,10 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
MaxStoresPerMemmove = MaxStoresPerMemmoveOptSize = 128;
}
+bool BPFTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const {
+ return false;
+}
+
SDValue BPFTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
switch (Op.getOpcode()) {
case ISD::BR_CC:
@@ -257,8 +261,7 @@ SDValue BPFTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
}
auto PtrVT = getPointerTy(MF.getDataLayout());
- Chain = DAG.getCALLSEQ_START(
- Chain, DAG.getConstant(NumBytes, CLI.DL, PtrVT, true), CLI.DL);
+ Chain = DAG.getCALLSEQ_START(Chain, NumBytes, 0, CLI.DL);
SmallVector<std::pair<unsigned, SDValue>, MaxArgs> RegsToPass;
@@ -306,11 +309,23 @@ SDValue BPFTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
// If the callee is a GlobalAddress node (quite common, every direct call is)
// turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
// Likewise ExternalSymbol -> TargetExternalSymbol.
- if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
+ if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
+ auto GV = G->getGlobal();
+ fail(CLI.DL, DAG,
+ "A call to global function '" + StringRef(GV->getName())
+ + "' is not supported. "
+ + (GV->isDeclaration() ?
+ "Only calls to predefined BPF helpers are allowed." :
+ "Please use __attribute__((always_inline) to make sure"
+ " this function is inlined."));
Callee = DAG.getTargetGlobalAddress(G->getGlobal(), CLI.DL, PtrVT,
G->getOffset(), 0);
- else if (ExternalSymbolSDNode *E = dyn_cast<ExternalSymbolSDNode>(Callee))
+ } else if (ExternalSymbolSDNode *E = dyn_cast<ExternalSymbolSDNode>(Callee)) {
Callee = DAG.getTargetExternalSymbol(E->getSymbol(), PtrVT, 0);
+ fail(CLI.DL, DAG, Twine("A call to built-in function '"
+ + StringRef(E->getSymbol())
+ + "' is not supported."));
+ }
// Returns a chain & a flag for retval copy to use.
SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
@@ -485,8 +500,11 @@ const char *BPFTargetLowering::getTargetNodeName(unsigned Opcode) const {
SDValue BPFTargetLowering::LowerGlobalAddress(SDValue Op,
SelectionDAG &DAG) const {
+ auto N = cast<GlobalAddressSDNode>(Op);
+ assert(N->getOffset() == 0 && "Invalid offset for global address");
+
SDLoc DL(Op);
- const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
+ const GlobalValue *GV = N->getGlobal();
SDValue GA = DAG.getTargetGlobalAddress(GV, DL, MVT::i64);
return DAG.getNode(BPFISD::Wrapper, DL, MVT::i64, GA);
@@ -497,8 +515,9 @@ BPFTargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI,
MachineBasicBlock *BB) const {
const TargetInstrInfo &TII = *BB->getParent()->getSubtarget().getInstrInfo();
DebugLoc DL = MI.getDebugLoc();
+ bool isSelectOp = MI.getOpcode() == BPF::Select;
- assert(MI.getOpcode() == BPF::Select && "Unexpected instr type to insert");
+ assert((isSelectOp || MI.getOpcode() == BPF::Select_Ri) && "Unexpected instr type to insert");
// To "insert" a SELECT instruction, we actually have to insert the diamond
// control-flow pattern. The incoming instruction knows the destination vreg
@@ -530,48 +549,40 @@ BPFTargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI,
// Insert Branch if Flag
unsigned LHS = MI.getOperand(1).getReg();
- unsigned RHS = MI.getOperand(2).getReg();
int CC = MI.getOperand(3).getImm();
+ int NewCC;
switch (CC) {
case ISD::SETGT:
- BuildMI(BB, DL, TII.get(BPF::JSGT_rr))
- .addReg(LHS)
- .addReg(RHS)
- .addMBB(Copy1MBB);
+ NewCC = isSelectOp ? BPF::JSGT_rr : BPF::JSGT_ri;
break;
case ISD::SETUGT:
- BuildMI(BB, DL, TII.get(BPF::JUGT_rr))
- .addReg(LHS)
- .addReg(RHS)
- .addMBB(Copy1MBB);
+ NewCC = isSelectOp ? BPF::JUGT_rr : BPF::JUGT_ri;
break;
case ISD::SETGE:
- BuildMI(BB, DL, TII.get(BPF::JSGE_rr))
- .addReg(LHS)
- .addReg(RHS)
- .addMBB(Copy1MBB);
+ NewCC = isSelectOp ? BPF::JSGE_rr : BPF::JSGE_ri;
break;
case ISD::SETUGE:
- BuildMI(BB, DL, TII.get(BPF::JUGE_rr))
- .addReg(LHS)
- .addReg(RHS)
- .addMBB(Copy1MBB);
+ NewCC = isSelectOp ? BPF::JUGE_rr : BPF::JUGE_ri;
break;
case ISD::SETEQ:
- BuildMI(BB, DL, TII.get(BPF::JEQ_rr))
- .addReg(LHS)
- .addReg(RHS)
- .addMBB(Copy1MBB);
+ NewCC = isSelectOp ? BPF::JEQ_rr : BPF::JEQ_ri;
break;
case ISD::SETNE:
- BuildMI(BB, DL, TII.get(BPF::JNE_rr))
- .addReg(LHS)
- .addReg(RHS)
- .addMBB(Copy1MBB);
+ NewCC = isSelectOp ? BPF::JNE_rr : BPF::JNE_ri;
break;
default:
report_fatal_error("unimplemented select CondCode " + Twine(CC));
}
+ if (isSelectOp)
+ BuildMI(BB, DL, TII.get(NewCC))
+ .addReg(LHS)
+ .addReg(MI.getOperand(2).getReg())
+ .addMBB(Copy1MBB);
+ else
+ BuildMI(BB, DL, TII.get(NewCC))
+ .addReg(LHS)
+ .addImm(MI.getOperand(2).getImm())
+ .addMBB(Copy1MBB);
// Copy0MBB:
// %FalseValue = ...
OpenPOWER on IntegriCloud