diff options
Diffstat (limited to 'llvm/lib/Target')
-rw-r--r-- | llvm/lib/Target/BPF/BPF.td | 6 | ||||
-rw-r--r-- | llvm/lib/Target/BPF/BPFISelLowering.cpp | 21 | ||||
-rw-r--r-- | llvm/lib/Target/BPF/BPFISelLowering.h | 5 | ||||
-rw-r--r-- | llvm/lib/Target/BPF/BPFInstrInfo.td | 12 | ||||
-rw-r--r-- | llvm/lib/Target/BPF/BPFSubtarget.cpp | 26 | ||||
-rw-r--r-- | llvm/lib/Target/BPF/BPFSubtarget.h | 15 |
6 files changed, 82 insertions, 3 deletions
diff --git a/llvm/lib/Target/BPF/BPF.td b/llvm/lib/Target/BPF/BPF.td index 11abe520c50..2d0c22a3a51 100644 --- a/llvm/lib/Target/BPF/BPF.td +++ b/llvm/lib/Target/BPF/BPF.td @@ -19,6 +19,12 @@ class Proc<string Name, list<SubtargetFeature> Features> : Processor<Name, NoItineraries, Features>; def : Proc<"generic", []>; +def : Proc<"v1", []>; +def : Proc<"v2", []>; +def : Proc<"probe", []>; + +def DummyFeature : SubtargetFeature<"dummy", "isDummyMode", + "true", "unused feature">; def BPFInstPrinter : AsmWriter { string AsmWriterClassName = "InstPrinter"; diff --git a/llvm/lib/Target/BPF/BPFISelLowering.cpp b/llvm/lib/Target/BPF/BPFISelLowering.cpp index 360de1467b3..94b3c7a16aa 100644 --- a/llvm/lib/Target/BPF/BPFISelLowering.cpp +++ b/llvm/lib/Target/BPF/BPFISelLowering.cpp @@ -130,6 +130,9 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM, MaxStoresPerMemset = MaxStoresPerMemsetOptSize = 128; MaxStoresPerMemcpy = MaxStoresPerMemcpyOptSize = 128; MaxStoresPerMemmove = MaxStoresPerMemmoveOptSize = 128; + + // CPU/Feature control + HasJmpExt = STI.getHasJmpExt(); } bool BPFTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { @@ -456,7 +459,8 @@ SDValue BPFTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const { SDValue Dest = Op.getOperand(4); SDLoc DL(Op); - NegateCC(LHS, RHS, CC); + if (!getHasJmpExt()) + NegateCC(LHS, RHS, CC); return DAG.getNode(BPFISD::BR_CC, DL, Op.getValueType(), Chain, LHS, RHS, DAG.getConstant(CC, DL, MVT::i64), Dest); @@ -470,7 +474,8 @@ SDValue BPFTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const { ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get(); SDLoc DL(Op); - NegateCC(LHS, RHS, CC); + if (!getHasJmpExt()) + NegateCC(LHS, RHS, CC); SDValue TargetCC = DAG.getConstant(CC, DL, MVT::i64); @@ -570,6 +575,18 @@ BPFTargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI, case ISD::SETNE: NewCC = isSelectOp ? BPF::JNE_rr : BPF::JNE_ri; break; + case ISD::SETLT: + NewCC = isSelectOp ? BPF::JSLT_rr : BPF::JSLT_ri; + break; + case ISD::SETULT: + NewCC = isSelectOp ? BPF::JULT_rr : BPF::JULT_ri; + break; + case ISD::SETLE: + NewCC = isSelectOp ? BPF::JSLE_rr : BPF::JSLE_ri; + break; + case ISD::SETULE: + NewCC = isSelectOp ? BPF::JULE_rr : BPF::JULE_ri; + break; default: report_fatal_error("unimplemented select CondCode " + Twine(CC)); } diff --git a/llvm/lib/Target/BPF/BPFISelLowering.h b/llvm/lib/Target/BPF/BPFISelLowering.h index 0b8a8ca20c3..35065f26495 100644 --- a/llvm/lib/Target/BPF/BPFISelLowering.h +++ b/llvm/lib/Target/BPF/BPFISelLowering.h @@ -50,7 +50,12 @@ public: EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *BB) const override; + bool getHasJmpExt() const { return HasJmpExt; } + private: + // Control Instruction Selection Features + bool HasJmpExt; + SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG) const; SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const; SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const; diff --git a/llvm/lib/Target/BPF/BPFInstrInfo.td b/llvm/lib/Target/BPF/BPFInstrInfo.td index f68357809ad..3b239e7463d 100644 --- a/llvm/lib/Target/BPF/BPFInstrInfo.td +++ b/llvm/lib/Target/BPF/BPFInstrInfo.td @@ -79,6 +79,14 @@ def BPF_CC_GTU : PatLeaf<(i64 imm), [{return (N->getZExtValue() == ISD::SETUGT);}]>; def BPF_CC_GEU : PatLeaf<(i64 imm), [{return (N->getZExtValue() == ISD::SETUGE);}]>; +def BPF_CC_LE : PatLeaf<(i64 imm), + [{return (N->getZExtValue() == ISD::SETLE);}]>; +def BPF_CC_LT : PatLeaf<(i64 imm), + [{return (N->getZExtValue() == ISD::SETLT);}]>; +def BPF_CC_LTU : PatLeaf<(i64 imm), + [{return (N->getZExtValue() == ISD::SETULT);}]>; +def BPF_CC_LEU : PatLeaf<(i64 imm), + [{return (N->getZExtValue() == ISD::SETULE);}]>; // jump instructions class JMP_RR<bits<4> Opc, string OpcodeStr, PatLeaf Cond> @@ -136,6 +144,10 @@ defm JUGE : J<0x3, ">=", BPF_CC_GEU>; defm JNE : J<0x5, "!=", BPF_CC_NE>; defm JSGT : J<0x6, "s>", BPF_CC_GT>; defm JSGE : J<0x7, "s>=", BPF_CC_GE>; +defm JULT : J<0xa, "<", BPF_CC_LTU>; +defm JULE : J<0xb, "<=", BPF_CC_LEU>; +defm JSLT : J<0xc, "s<", BPF_CC_LT>; +defm JSLE : J<0xd, "s<=", BPF_CC_LE>; } // ALU instructions diff --git a/llvm/lib/Target/BPF/BPFSubtarget.cpp b/llvm/lib/Target/BPF/BPFSubtarget.cpp index c3a8b1caa63..42ca87f9ef6 100644 --- a/llvm/lib/Target/BPF/BPFSubtarget.cpp +++ b/llvm/lib/Target/BPF/BPFSubtarget.cpp @@ -13,6 +13,7 @@ #include "BPFSubtarget.h" #include "BPF.h" +#include "llvm/Support/Host.h" #include "llvm/Support/TargetRegistry.h" using namespace llvm; @@ -25,7 +26,30 @@ using namespace llvm; void BPFSubtarget::anchor() {} +BPFSubtarget &BPFSubtarget::initializeSubtargetDependencies(StringRef CPU, + StringRef FS) { + initializeEnvironment(); + initSubtargetFeatures(CPU, FS); + return *this; +} + +void BPFSubtarget::initializeEnvironment() { + HasJmpExt = false; +} + +void BPFSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) { + if (CPU == "probe") + CPU = sys::detail::getHostCPUNameForBPF(); + if (CPU == "generic" || CPU == "v1") + return; + if (CPU == "v2") { + HasJmpExt = true; + return; + } +} + BPFSubtarget::BPFSubtarget(const Triple &TT, const std::string &CPU, const std::string &FS, const TargetMachine &TM) - : BPFGenSubtargetInfo(TT, CPU, FS), InstrInfo(), FrameLowering(*this), + : BPFGenSubtargetInfo(TT, CPU, FS), InstrInfo(), + FrameLowering(initializeSubtargetDependencies(CPU, FS)), TLInfo(TM, *this) {} diff --git a/llvm/lib/Target/BPF/BPFSubtarget.h b/llvm/lib/Target/BPF/BPFSubtarget.h index 27cc9a262fc..d88d70d09ad 100644 --- a/llvm/lib/Target/BPF/BPFSubtarget.h +++ b/llvm/lib/Target/BPF/BPFSubtarget.h @@ -35,15 +35,30 @@ class BPFSubtarget : public BPFGenSubtargetInfo { BPFTargetLowering TLInfo; SelectionDAGTargetInfo TSInfo; +private: + void initializeEnvironment(); + void initSubtargetFeatures(StringRef CPU, StringRef FS); + bool probeJmpExt(); + +protected: + // unused + bool isDummyMode; + + // whether the cpu supports jmp ext + bool HasJmpExt; + public: // This constructor initializes the data members to match that // of the specified triple. BPFSubtarget(const Triple &TT, const std::string &CPU, const std::string &FS, const TargetMachine &TM); + BPFSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS); + // ParseSubtargetFeatures - Parses features string setting specified // subtarget options. Definition of function is auto generated by tblgen. void ParseSubtargetFeatures(StringRef CPU, StringRef FS); + bool getHasJmpExt() const { return HasJmpExt; } const BPFInstrInfo *getInstrInfo() const override { return &InstrInfo; } const BPFFrameLowering *getFrameLowering() const override { |