-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BPF][GlobalISel] add initial gisel support for BPF
This adds initial codegen support for BPF backend. Only implemented ir-translator for "RET" (but not support isel). Depends on: #74998
- Loading branch information
Showing
16 changed files
with
404 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//===-- BPFCallLowering.cpp - Call lowering for GlobalISel ------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// \file | ||
/// This file implements the lowering of LLVM calls to machine code calls for | ||
/// GlobalISel. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "BPFCallLowering.h" | ||
#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h" | ||
#include "llvm/Support/Debug.h" | ||
|
||
#define DEBUG_TYPE "bpf-call-lowering" | ||
|
||
using namespace llvm; | ||
|
||
BPFCallLowering::BPFCallLowering(const BPFTargetLowering &TLI) | ||
: CallLowering(&TLI) {} | ||
|
||
bool BPFCallLowering::lowerReturn(MachineIRBuilder &MIRBuilder, | ||
const Value *Val, ArrayRef<Register> VRegs, | ||
FunctionLoweringInfo &FLI, | ||
Register SwiftErrorVReg) const { | ||
if (!VRegs.empty()) | ||
return false; | ||
MIRBuilder.buildInstr(BPF::RET); | ||
return true; | ||
} | ||
|
||
bool BPFCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder, | ||
const Function &F, | ||
ArrayRef<ArrayRef<Register>> VRegs, | ||
FunctionLoweringInfo &FLI) const { | ||
return VRegs.empty(); | ||
} | ||
|
||
bool BPFCallLowering::lowerCall(MachineIRBuilder &MIRBuilder, | ||
CallLoweringInfo &Info) const { | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//===-- BPFCallLowering.h - Call lowering for GlobalISel --------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// \file | ||
/// This file describes how to lower LLVM calls to machine code calls. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIB_TARGET_BPF_GISEL_BPFCALLLOWERING_H | ||
#define LLVM_LIB_TARGET_BPF_GISEL_BPFCALLLOWERING_H | ||
|
||
#include "BPFISelLowering.h" | ||
#include "llvm/CodeGen/GlobalISel/CallLowering.h" | ||
#include "llvm/IR/CallingConv.h" | ||
|
||
namespace llvm { | ||
|
||
class BPFTargetLowering; | ||
|
||
class BPFCallLowering : public CallLowering { | ||
public: | ||
BPFCallLowering(const BPFTargetLowering &TLI); | ||
bool lowerReturn(MachineIRBuilder &MIRBuilder, const Value *Val, | ||
ArrayRef<Register> VRegs, FunctionLoweringInfo &FLI, | ||
Register SwiftErrorVReg) const override; | ||
bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F, | ||
ArrayRef<ArrayRef<Register>> VRegs, | ||
FunctionLoweringInfo &FLI) const override; | ||
bool lowerCall(MachineIRBuilder &MIRBuilder, | ||
CallLoweringInfo &Info) const override; | ||
}; | ||
} // namespace llvm | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
//===- BPFInstructionSelector.cpp --------------------------------*- C++ -*-==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// \file | ||
/// This file implements the targeting of the InstructionSelector class for BPF. | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "BPFInstrInfo.h" | ||
#include "BPFRegisterBankInfo.h" | ||
#include "BPFSubtarget.h" | ||
#include "BPFTargetMachine.h" | ||
#include "llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h" | ||
#include "llvm/CodeGen/GlobalISel/InstructionSelector.h" | ||
#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h" | ||
#include "llvm/CodeGen/MachineFunction.h" | ||
#include "llvm/IR/IntrinsicsBPF.h" | ||
#include "llvm/Support/Debug.h" | ||
|
||
#define DEBUG_TYPE "bpf-gisel" | ||
|
||
using namespace llvm; | ||
|
||
namespace { | ||
|
||
#define GET_GLOBALISEL_PREDICATE_BITSET | ||
#include "BPFGenGlobalISel.inc" | ||
#undef GET_GLOBALISEL_PREDICATE_BITSET | ||
|
||
class BPFInstructionSelector : public InstructionSelector { | ||
public: | ||
BPFInstructionSelector(const BPFTargetMachine &TM, const BPFSubtarget &STI, | ||
const BPFRegisterBankInfo &RBI); | ||
|
||
bool select(MachineInstr &I) override; | ||
static const char *getName() { return DEBUG_TYPE; } | ||
|
||
private: | ||
/// tblgen generated 'select' implementation that is used as the initial | ||
/// selector for the patterns that do not require complex C++. | ||
bool selectImpl(MachineInstr &I, CodeGenCoverage &CoverageInfo) const; | ||
|
||
const BPFInstrInfo &TII; | ||
const BPFRegisterInfo &TRI; | ||
const BPFRegisterBankInfo &RBI; | ||
|
||
#define GET_GLOBALISEL_PREDICATES_DECL | ||
#include "BPFGenGlobalISel.inc" | ||
#undef GET_GLOBALISEL_PREDICATES_DECL | ||
|
||
#define GET_GLOBALISEL_TEMPORARIES_DECL | ||
#include "BPFGenGlobalISel.inc" | ||
#undef GET_GLOBALISEL_TEMPORARIES_DECL | ||
}; | ||
|
||
} // namespace | ||
|
||
#define GET_GLOBALISEL_IMPL | ||
#include "BPFGenGlobalISel.inc" | ||
#undef GET_GLOBALISEL_IMPL | ||
|
||
BPFInstructionSelector::BPFInstructionSelector(const BPFTargetMachine &TM, | ||
const BPFSubtarget &STI, | ||
const BPFRegisterBankInfo &RBI) | ||
: TII(*STI.getInstrInfo()), TRI(*STI.getRegisterInfo()), RBI(RBI), | ||
#define GET_GLOBALISEL_PREDICATES_INIT | ||
#include "BPFGenGlobalISel.inc" | ||
#undef GET_GLOBALISEL_PREDICATES_INIT | ||
#define GET_GLOBALISEL_TEMPORARIES_INIT | ||
#include "BPFGenGlobalISel.inc" | ||
#undef GET_GLOBALISEL_TEMPORARIES_INIT | ||
{ | ||
} | ||
|
||
bool BPFInstructionSelector::select(MachineInstr &I) { | ||
if (selectImpl(I, *CoverageInfo)) | ||
return true; | ||
return false; | ||
} | ||
|
||
namespace llvm { | ||
InstructionSelector * | ||
createBPFInstructionSelector(const BPFTargetMachine &TM, | ||
const BPFSubtarget &Subtarget, | ||
const BPFRegisterBankInfo &RBI) { | ||
return new BPFInstructionSelector(TM, Subtarget, RBI); | ||
} | ||
} // namespace llvm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//===- BPFLegalizerInfo.h ----------------------------------------*- C++ -*-==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// \file | ||
/// This file implements the targeting of the Machinelegalizer class for BPF | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "BPFLegalizerInfo.h" | ||
#include "llvm/Support/Debug.h" | ||
|
||
#define DEBUG_TYPE "bpf-legalinfo" | ||
|
||
using namespace llvm; | ||
using namespace LegalizeActions; | ||
|
||
BPFLegalizerInfo::BPFLegalizerInfo(const BPFSubtarget &ST) { | ||
getLegacyLegalizerInfo().computeTables(); | ||
} |
Oops, something went wrong.