[llvm-branch-commits] [llvm] [BPF][GlobalISel] add initial gisel support for BPF (PR #74999)
https://github.com/inclyc created https://github.com/llvm/llvm-project/pull/74999 This adds initial codegen support for BPF backend. Only implemented ir-translator for "RET" (but not support isel). Depends on: #74998 >From 5549edd4862b6242c41df44a40a23adfa245ddb1 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Sun, 10 Dec 2023 22:57:39 +0800 Subject: [PATCH] [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 --- llvm/lib/Target/BPF/BPF.h | 7 ++ llvm/lib/Target/BPF/BPF.td| 1 + llvm/lib/Target/BPF/BPFSubtarget.cpp | 28 ++ llvm/lib/Target/BPF/BPFSubtarget.h| 17 +++- llvm/lib/Target/BPF/BPFTargetMachine.cpp | 31 +++ llvm/lib/Target/BPF/CMakeLists.txt| 7 ++ llvm/lib/Target/BPF/GISel/BPFCallLowering.cpp | 46 ++ llvm/lib/Target/BPF/GISel/BPFCallLowering.h | 39 .../BPF/GISel/BPFInstructionSelector.cpp | 91 +++ .../lib/Target/BPF/GISel/BPFLegalizerInfo.cpp | 22 + llvm/lib/Target/BPF/GISel/BPFLegalizerInfo.h | 28 ++ .../Target/BPF/GISel/BPFRegisterBankInfo.cpp | 25 + .../Target/BPF/GISel/BPFRegisterBankInfo.h| 39 llvm/lib/Target/BPF/GISel/BPFRegisterBanks.td | 15 +++ .../Target/BPF/MCTargetDesc/BPFMCTargetDesc.h | 5 +- .../BPF/GlobalISel/ir-translator-ret.ll | 7 ++ 16 files changed, 404 insertions(+), 4 deletions(-) create mode 100644 llvm/lib/Target/BPF/GISel/BPFCallLowering.cpp create mode 100644 llvm/lib/Target/BPF/GISel/BPFCallLowering.h create mode 100644 llvm/lib/Target/BPF/GISel/BPFInstructionSelector.cpp create mode 100644 llvm/lib/Target/BPF/GISel/BPFLegalizerInfo.cpp create mode 100644 llvm/lib/Target/BPF/GISel/BPFLegalizerInfo.h create mode 100644 llvm/lib/Target/BPF/GISel/BPFRegisterBankInfo.cpp create mode 100644 llvm/lib/Target/BPF/GISel/BPFRegisterBankInfo.h create mode 100644 llvm/lib/Target/BPF/GISel/BPFRegisterBanks.td create mode 100644 llvm/test/CodeGen/BPF/GlobalISel/ir-translator-ret.ll diff --git a/llvm/lib/Target/BPF/BPF.h b/llvm/lib/Target/BPF/BPF.h index 436cd62c258138..5c77d183e1ef3d 100644 --- a/llvm/lib/Target/BPF/BPF.h +++ b/llvm/lib/Target/BPF/BPF.h @@ -16,7 +16,10 @@ #include "llvm/Target/TargetMachine.h" namespace llvm { +class BPFRegisterBankInfo; +class BPFSubtarget; class BPFTargetMachine; +class InstructionSelector; class PassRegistry; ModulePass *createBPFCheckAndAdjustIR(); @@ -27,6 +30,10 @@ FunctionPass *createBPFMIPeepholePass(); FunctionPass *createBPFMIPreEmitPeepholePass(); FunctionPass *createBPFMIPreEmitCheckingPass(); +InstructionSelector *createBPFInstructionSelector(const BPFTargetMachine &, + const BPFSubtarget &, + const BPFRegisterBankInfo &); + void initializeBPFCheckAndAdjustIRPass(PassRegistry&); void initializeBPFDAGToDAGISelPass(PassRegistry &); void initializeBPFMIPeepholePass(PassRegistry &); diff --git a/llvm/lib/Target/BPF/BPF.td b/llvm/lib/Target/BPF/BPF.td index 7f38fbdd8c5c10..dff76ca07af511 100644 --- a/llvm/lib/Target/BPF/BPF.td +++ b/llvm/lib/Target/BPF/BPF.td @@ -11,6 +11,7 @@ include "llvm/Target/Target.td" include "BPFRegisterInfo.td" include "BPFCallingConv.td" include "BPFInstrInfo.td" +include "GISel/BPFRegisterBanks.td" def BPFInstrInfo : InstrInfo; diff --git a/llvm/lib/Target/BPF/BPFSubtarget.cpp b/llvm/lib/Target/BPF/BPFSubtarget.cpp index 5e79142ea9e1c8..9a8e42f3237114 100644 --- a/llvm/lib/Target/BPF/BPFSubtarget.cpp +++ b/llvm/lib/Target/BPF/BPFSubtarget.cpp @@ -12,6 +12,10 @@ #include "BPFSubtarget.h" #include "BPF.h" +#include "BPFTargetMachine.h" +#include "GISel/BPFCallLowering.h" +#include "GISel/BPFLegalizerInfo.h" +#include "GISel/BPFRegisterBankInfo.h" #include "llvm/MC/TargetRegistry.h" #include "llvm/TargetParser/Host.h" @@ -95,4 +99,28 @@ BPFSubtarget::BPFSubtarget(const Triple &TT, const std::string &CPU, FrameLowering(initializeSubtargetDependencies(CPU, FS)), TLInfo(TM, *this) { IsLittleEndian = TT.isLittleEndian(); + + CallLoweringInfo.reset(new BPFCallLowering(*getTargetLowering())); + Legalizer.reset(new BPFLegalizerInfo(*this)); + auto *RBI = new BPFRegisterBankInfo(*getRegisterInfo()); + RegBankInfo.reset(RBI); + + InstSelector.reset(createBPFInstructionSelector( + *static_cast(&TM), *this, *RBI)); +} + +const CallLowering *BPFSubtarget::getCallLowering() const { + return CallLoweringInfo.get(); +} + +InstructionSelector *BPFSubtarget::getInstructionSelector() const { + return InstSelector.get(); +} + +const LegalizerInfo *BPFSubtarget::getLegalizerInfo() const { + return Legalizer.get(); +} + +const RegisterBankInfo *BPFSubtarget::getRegBankInfo() const { + return RegBankInfo.get(); } diff --git a/llvm/lib/Target/BPF/BPFSub
[llvm-branch-commits] [llvm] [BPF][GlobalISel] add initial gisel support for BPF (PR #74999)
llvmbot wrote: @llvm/pr-subscribers-llvm-globalisel Author: Yingchi Long (inclyc) Changes This adds initial codegen support for BPF backend. Only implemented ir-translator for "RET" (but not support isel). Depends on: #74998 --- Patch is 21.69 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/74999.diff 16 Files Affected: - (modified) llvm/lib/Target/BPF/BPF.h (+7) - (modified) llvm/lib/Target/BPF/BPF.td (+1) - (modified) llvm/lib/Target/BPF/BPFSubtarget.cpp (+28) - (modified) llvm/lib/Target/BPF/BPFSubtarget.h (+16-1) - (modified) llvm/lib/Target/BPF/BPFTargetMachine.cpp (+31) - (modified) llvm/lib/Target/BPF/CMakeLists.txt (+7) - (added) llvm/lib/Target/BPF/GISel/BPFCallLowering.cpp (+46) - (added) llvm/lib/Target/BPF/GISel/BPFCallLowering.h (+39) - (added) llvm/lib/Target/BPF/GISel/BPFInstructionSelector.cpp (+91) - (added) llvm/lib/Target/BPF/GISel/BPFLegalizerInfo.cpp (+22) - (added) llvm/lib/Target/BPF/GISel/BPFLegalizerInfo.h (+28) - (added) llvm/lib/Target/BPF/GISel/BPFRegisterBankInfo.cpp (+25) - (added) llvm/lib/Target/BPF/GISel/BPFRegisterBankInfo.h (+39) - (added) llvm/lib/Target/BPF/GISel/BPFRegisterBanks.td (+15) - (modified) llvm/lib/Target/BPF/MCTargetDesc/BPFMCTargetDesc.h (+2-3) - (added) llvm/test/CodeGen/BPF/GlobalISel/ir-translator-ret.ll (+7) ``diff diff --git a/llvm/lib/Target/BPF/BPF.h b/llvm/lib/Target/BPF/BPF.h index 436cd62c258138..5c77d183e1ef3d 100644 --- a/llvm/lib/Target/BPF/BPF.h +++ b/llvm/lib/Target/BPF/BPF.h @@ -16,7 +16,10 @@ #include "llvm/Target/TargetMachine.h" namespace llvm { +class BPFRegisterBankInfo; +class BPFSubtarget; class BPFTargetMachine; +class InstructionSelector; class PassRegistry; ModulePass *createBPFCheckAndAdjustIR(); @@ -27,6 +30,10 @@ FunctionPass *createBPFMIPeepholePass(); FunctionPass *createBPFMIPreEmitPeepholePass(); FunctionPass *createBPFMIPreEmitCheckingPass(); +InstructionSelector *createBPFInstructionSelector(const BPFTargetMachine &, + const BPFSubtarget &, + const BPFRegisterBankInfo &); + void initializeBPFCheckAndAdjustIRPass(PassRegistry&); void initializeBPFDAGToDAGISelPass(PassRegistry &); void initializeBPFMIPeepholePass(PassRegistry &); diff --git a/llvm/lib/Target/BPF/BPF.td b/llvm/lib/Target/BPF/BPF.td index 7f38fbdd8c5c10..dff76ca07af511 100644 --- a/llvm/lib/Target/BPF/BPF.td +++ b/llvm/lib/Target/BPF/BPF.td @@ -11,6 +11,7 @@ include "llvm/Target/Target.td" include "BPFRegisterInfo.td" include "BPFCallingConv.td" include "BPFInstrInfo.td" +include "GISel/BPFRegisterBanks.td" def BPFInstrInfo : InstrInfo; diff --git a/llvm/lib/Target/BPF/BPFSubtarget.cpp b/llvm/lib/Target/BPF/BPFSubtarget.cpp index 5e79142ea9e1c8..9a8e42f3237114 100644 --- a/llvm/lib/Target/BPF/BPFSubtarget.cpp +++ b/llvm/lib/Target/BPF/BPFSubtarget.cpp @@ -12,6 +12,10 @@ #include "BPFSubtarget.h" #include "BPF.h" +#include "BPFTargetMachine.h" +#include "GISel/BPFCallLowering.h" +#include "GISel/BPFLegalizerInfo.h" +#include "GISel/BPFRegisterBankInfo.h" #include "llvm/MC/TargetRegistry.h" #include "llvm/TargetParser/Host.h" @@ -95,4 +99,28 @@ BPFSubtarget::BPFSubtarget(const Triple &TT, const std::string &CPU, FrameLowering(initializeSubtargetDependencies(CPU, FS)), TLInfo(TM, *this) { IsLittleEndian = TT.isLittleEndian(); + + CallLoweringInfo.reset(new BPFCallLowering(*getTargetLowering())); + Legalizer.reset(new BPFLegalizerInfo(*this)); + auto *RBI = new BPFRegisterBankInfo(*getRegisterInfo()); + RegBankInfo.reset(RBI); + + InstSelector.reset(createBPFInstructionSelector( + *static_cast(&TM), *this, *RBI)); +} + +const CallLowering *BPFSubtarget::getCallLowering() const { + return CallLoweringInfo.get(); +} + +InstructionSelector *BPFSubtarget::getInstructionSelector() const { + return InstSelector.get(); +} + +const LegalizerInfo *BPFSubtarget::getLegalizerInfo() const { + return Legalizer.get(); +} + +const RegisterBankInfo *BPFSubtarget::getRegBankInfo() const { + return RegBankInfo.get(); } diff --git a/llvm/lib/Target/BPF/BPFSubtarget.h b/llvm/lib/Target/BPF/BPFSubtarget.h index a55ae618f4d1d3..33747546eadc3b 100644 --- a/llvm/lib/Target/BPF/BPFSubtarget.h +++ b/llvm/lib/Target/BPF/BPFSubtarget.h @@ -16,7 +16,12 @@ #include "BPFFrameLowering.h" #include "BPFISelLowering.h" #include "BPFInstrInfo.h" +#include "BPFRegisterInfo.h" #include "BPFSelectionDAGInfo.h" +#include "llvm/CodeGen/GlobalISel/CallLowering.h" +#include "llvm/CodeGen/GlobalISel/InstructionSelector.h" +#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h" +#include "llvm/CodeGen/RegisterBankInfo.h" #include "llvm/CodeGen/SelectionDAGTargetInfo.h" #include "llvm/CodeGen/TargetSubtargetInfo.h" #include "llvm/IR/DataLayout.h" @@ -61,6 +66,11 @@ class BPFSubtarget : public BPFGenSubtargetInfo { // whether cpu v4 insns are enabled. bo
[llvm-branch-commits] [llvm] [TextAPI] Add support to convert RecordSlices -> InterfaceFile (PR #75007)
https://github.com/cyndyishida created https://github.com/llvm/llvm-project/pull/75007 *Note*: This is a part of a stack. Please review https://github.com/llvm/llvm-project/pull/75006 first. Introduce RecordVisitor. This is used for different clients that want to extract information out of RecordSlice types. The first and immediate use case is for serializing symbol information into TBD files. >From d5e97577651b558b56de64f9ed74cd7893cea7ec Mon Sep 17 00:00:00 2001 From: Cyndy Ishida Date: Thu, 7 Dec 2023 13:57:17 -0800 Subject: [PATCH] [TextAPI] Add support to convert RecordSlices -> InterfaceFile Introduce RecordVisitor. This is used for different clients that want to extract information out of RecordSlice types. The first and immediate usecase is for serializing symbol information into TBD files. --- llvm/include/llvm/TextAPI/DylibReader.h | 5 + llvm/include/llvm/TextAPI/Record.h| 9 +- llvm/include/llvm/TextAPI/RecordVisitor.h | 54 ++ llvm/include/llvm/TextAPI/RecordsSlice.h | 6 +- llvm/lib/TextAPI/CMakeLists.txt | 1 + llvm/lib/TextAPI/DylibReader.cpp | 10 ++ llvm/lib/TextAPI/RecordVisitor.cpp| 67 llvm/lib/TextAPI/RecordsSlice.cpp | 124 +- 8 files changed, 272 insertions(+), 4 deletions(-) create mode 100644 llvm/include/llvm/TextAPI/RecordVisitor.h create mode 100644 llvm/lib/TextAPI/RecordVisitor.cpp diff --git a/llvm/include/llvm/TextAPI/DylibReader.h b/llvm/include/llvm/TextAPI/DylibReader.h index aa98df99c99fa..3d4ddb9745ddd 100644 --- a/llvm/include/llvm/TextAPI/DylibReader.h +++ b/llvm/include/llvm/TextAPI/DylibReader.h @@ -42,6 +42,11 @@ struct ParseOption { /// \return List of record slices. Expected readFile(MemoryBufferRef Buffer, const ParseOption &Opt); +/// Get TAPI file representation of binary dylib. +/// +/// \param Buffer Data that points to dylib. +Expected> get(MemoryBufferRef Buffer); + } // namespace DylibReader } // end namespace MachO. diff --git a/llvm/include/llvm/TextAPI/Record.h b/llvm/include/llvm/TextAPI/Record.h index 5317982cbfa2b..ec93098b320ce 100644 --- a/llvm/include/llvm/TextAPI/Record.h +++ b/llvm/include/llvm/TextAPI/Record.h @@ -14,6 +14,7 @@ #ifndef LLVM_TEXTAPI_RECORD_H #define LLVM_TEXTAPI_RECORD_H +#include "llvm/ADT/MapVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Casting.h" #include "llvm/TextAPI/Symbol.h" @@ -50,7 +51,7 @@ class Record { public: Record() = default; Record(StringRef Name, RecordLinkage Linkage, SymbolFlags Flags) - : Name(Name), Linkage(Linkage), Flags(Flags) {} + : Name(Name), Linkage(Linkage), Flags(mergeFlags(Flags, Linkage)) {} bool isWeakDefined() const { return (Flags & SymbolFlags::WeakDefined) == SymbolFlags::WeakDefined; @@ -79,6 +80,10 @@ class Record { bool isRexported() const { return Linkage == RecordLinkage::Rexported; } StringRef getName() const { return Name; } + SymbolFlags getFlags() const { return Flags; } + +private: + SymbolFlags mergeFlags(SymbolFlags Flags, RecordLinkage Linkage); protected: StringRef Name; @@ -137,6 +142,7 @@ class ObjCContainerRecord : public Record { ObjCIVarRecord *addObjCIVar(StringRef IVar, RecordLinkage Linkage); ObjCIVarRecord *findObjCIVar(StringRef IVar) const; + std::vector getObjCIVars() const; private: RecordMap IVars; @@ -163,6 +169,7 @@ class ObjCInterfaceRecord : public ObjCContainerRecord { bool hasExceptionAttribute() const { return HasEHType; } bool addObjCCategory(ObjCCategoryRecord *Record); + std::vector getObjCCategories() const; private: bool HasEHType; diff --git a/llvm/include/llvm/TextAPI/RecordVisitor.h b/llvm/include/llvm/TextAPI/RecordVisitor.h new file mode 100644 index 0..34e43f5b0027f --- /dev/null +++ b/llvm/include/llvm/TextAPI/RecordVisitor.h @@ -0,0 +1,54 @@ +//===- llvm/TextAPI/RecordSlice.h - TAPI RecordSlice *- 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 +// +//===--===// +/// +/// Defines the TAPI Record Visitor. +/// +//===--===// + +#ifndef LLVM_TEXTAPI_RECORDVISITOR_H +#define LLVM_TEXTAPI_RECORDVISITOR_H + +#include "llvm/TextAPI/Record.h" +#include "llvm/TextAPI/SymbolSet.h" + +namespace llvm { +namespace MachO { + +/// Base class for any usage of traversing over collected Records. +class RecordVisitor { +public: + virtual ~RecordVisitor(); + + virtual void visitGlobal(const GlobalRecord &) = 0; + virtual void visitObjCInterface(const ObjCInterfaceRecord &); + virtual void visitObjCCategory(const ObjCCategoryRecord &); +}; + +/// Specialized RecordVisitor for collecting exported symbols +/// a
[llvm-branch-commits] [llvm] [BPF][GlobalISel] add initial gisel support for BPF (PR #74999)
https://github.com/inclyc ready_for_review https://github.com/llvm/llvm-project/pull/74999 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [compiler-rt] [llvm] [clang] [GlobalISel] Always direct-call IFuncs and Aliases (PR #74902)
https://github.com/aemerson approved this pull request. LGTM. https://github.com/llvm/llvm-project/pull/74902 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits