Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update toolchain to LLVM 18 #105

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
4ce026a
[SOL] Customize README.md
jackcmay Feb 15, 2019
cac5b33
[SOL] Add warning messages for potentially incorrect behavior
jackcmay Feb 15, 2019
9e52700
[SOL] Remove blocks for complex types, update debug messages
jackcmay Feb 15, 2019
8109153
[SOL] Add support for relative relocations
jackcmay Feb 15, 2019
8c7f23a
[SOL] Custom expansions without handlers, expand instead or error
jackcmay Feb 15, 2019
ef3e48e
[SOL] symbols resolved at load time
jackcmay Jun 20, 2019
5741f4d
[SOL] Update warning about more args then BPF currently supports
jackcmay Jun 21, 2019
91b0145
[SOL] Enable auto-demotion of sret values
jackcmay Jun 4, 2019
8684c65
[SOL] Support passing arguments via the stack
jackcmay Jul 11, 2019
0d7f441
[SOL] Fix undefined register error
jackcmay Jul 11, 2019
fe8bfa2
[SOL] Pass stack args in current frame
jackcmay Aug 20, 2019
e8708b2
[SOL] Push stack args to the bottom of the stack
jackcmay Aug 29, 2019
1312901
[SOL] Bump stack frame size
jackcmay Feb 10, 2020
a2c7708
[SOL] Enable BPF shared object creation
dmakarov Feb 4, 2021
c4201ba
[SOL] Disable llvm tests incompatible with Solana BPF backend (#3)
dmakarov Feb 8, 2021
f3f891d
[SOL] Allow selectively disable compiler builtins for BPF target (#4)
dmakarov Feb 17, 2021
888debf
[SOL] Map signed division operation to corresponding intrinsic function
dmakarov Feb 26, 2021
dc6da60
[SOL] Adjust BPF TargetInfo to updated API
dmakarov Feb 26, 2021
e861ac2
[SOL] Allow unaligned store operations
dmakarov Mar 22, 2021
00a1f44
[SOL] Adjust BPF tests
dmakarov Mar 25, 2021
40df440
[SOL] Allow misaligned loads
dmakarov Mar 27, 2021
e500296
[SOL] Add BPF compiler-rt builtins
dmakarov Apr 2, 2021
8594695
[SOL] Enable Solana BPF extensions as subtarget feature
dmakarov Apr 12, 2021
6533d92
[SOL] Fixes required for Solang
seanyoung Apr 13, 2021
718c66e
[SOL] Disable debug info when solana feature flag is set
dmakarov Apr 22, 2021
bed973e
[SOL] Set max stores per mem func depending on the target features
dmakarov Jul 26, 2021
c1e8917
[SOL] Prevent breaking ISelDAG connectivity on replacing loads by con…
dmakarov Oct 22, 2021
59d4d0f
[SOL] Adjust allowsMisalignedMemoryAccesses signature
dmakarov Oct 29, 2021
83ebc8c
[SOL] Adjust rust alloc routines declarations for Library Info test
dmakarov Oct 29, 2021
176a00f
[SOL] Override default getImplicitAddend implementation for BPF arch
dmakarov Nov 3, 2021
7df6f71
[SOL] Add R_BPF_64_ABS64 relocation handling in lld
dmakarov Nov 4, 2021
81c7abc
[SOL] Revert to R_BPF_64_64 for global data object relocations
dmakarov Nov 7, 2021
d9c2c1d
[SOL] Revert to R_BPF_64_32 until support for R_BPF_64_ABS32 added
dmakarov Nov 17, 2021
68135b5
[SOL] Add sbf-solana-solana target triplet
dmakarov Nov 30, 2021
3592de5
[SOL] Turn on solana feature for SBF target by default
dmakarov Dec 2, 2021
c78cb0d
[SOL] Register SBF asm parser
dmakarov Dec 3, 2021
28c1f3e
[SOL] Add SBF compiler-rt builtins
dmakarov Dec 14, 2021
16e29be
[SOL] Add missing SBF conditions to match BPFEL target
dmakarov Dec 19, 2021
35b949b
[SOL] add support for (pseudo) atomics to SBF (#23)
alessandrod Jan 3, 2022
6cbd472
[SOL] disable llvm.bpf.load.* intrinsics on SBF (#24)
alessandrod Jan 7, 2022
3086eb0
[SOL] Xfail unrelated tests
dmakarov Feb 28, 2022
f812eb2
[SOL] Glue the insn setting $r5 to other in-reg passed args insns
dmakarov Mar 29, 2022
ed1002a
[SOL] Introduce dynamic stack frames and the SBFv2 flag
alessandrod Mar 8, 2022
70b4eb5
[SOL] native support for signed division in SBF
alessandrod Mar 10, 2022
aacbc14
[SOL] report exceeded stack size as a warning if dynamic frames are off
alessandrod Apr 5, 2022
6636c64
[SOL] re-enable debug info and add R_BPF_64_{ABS64, ABS32, NODYLD32} …
jawilk Apr 15, 2022
9e742ff
[SOL] lld: emit correct e_flags
alessandrod Apr 28, 2022
3ea9d5d
[SOL] clang: add sbfv2 cpu name
alessandrod May 7, 2022
c3fe309
[SOL] fix 64 bit data relocations
alessandrod Apr 27, 2022
9c08cac
[SOL] revert ABS64 bits of 672d5f8f40ff422ea31571ff2c5f7a65edad7e2e
alessandrod May 7, 2022
22eaf3b
[SOL] sbf: add static-syscalls feature
alessandrod May 7, 2022
9a8fbe2
[SOL] Disable BTF codegen
Apr 28, 2022
a88fae4
[SOL] lldb: add sbf{v2} targets
jawilk May 25, 2022
8e7542a
[SOL] Fix callx in AsmParser
Jun 18, 2022
18e6b3f
[SOL] lldb: pretty print instructions
jawilk Jul 3, 2022
967fd33
[SOL] lldb: skip ranges with DW_AT_low_pc equal to zero
jawilk Jul 2, 2022
0b26bea
[SOL] Adjust BPF TargetInfo to updated API
dmakarov Jul 7, 2022
e85050b
[SOL] Fix lld BPF Arch after upgrade to llvm 14.0
dmakarov Jul 7, 2022
030a98d
[SOL] Update failing tests after upgrade
dmakarov Jul 16, 2022
c794475
[SOL] lldb: Add solana-lldb wrapper
jawilk Jul 30, 2022
34ca1ef
[SOL] Override shouldSignExtendTypeInLibCall to include 32bit values
dmakarov Sep 23, 2022
9e2fd80
[SOL] Initial squash commit for new SBF LLVM back-end and related.
nvjle Oct 14, 2022
e37e5cd
[SOL] Add regression test for shouldSignExtendTypeInLibCall fix.
nvjle Oct 15, 2022
fcf2b9a
[SOL] Add warn_drv_no_solana_with_bpf to warning-flags unit test.
nvjle Oct 21, 2022
0df3210
[SOL] Reworked the SBF textual assembly syntax to match the rbpf-styl…
nvjle Nov 15, 2022
92cf29e
[SOL] Make adjustments after upgrading to llvm 15.0
dmakarov Nov 18, 2022
75fa149
[SOL] Adjust tests
dmakarov Nov 23, 2022
5ec9489
[SOL] Adjust github workflow
dmakarov Nov 23, 2022
a489344
[SOL] Update SBF BTF with upstream changes
dmakarov Nov 28, 2022
9cedb0a
[SOL] Define __ELF__ macro for the SBF target
dmakarov Dec 12, 2022
8547b3f
[SOL] Fix SBF target in LLDB
dmakarov Jan 30, 2023
6a3d944
[SOL] Fix paths in solana lldb wrapper script
dmakarov Feb 7, 2023
964f978
[SOL] Fix bug in LLD
LucasSte Dec 19, 2022
31b3f54
[SOL] Revive BTF/CO-RE crud from bitrot.
nvjle Feb 15, 2023
990b275
[SOL] Fix CI build on macOS
dmakarov Feb 16, 2023
4ce6441
[SOL] Generate EM_SBF binary only for sbfv2 cpu subtarget
dmakarov Feb 18, 2023
374513b
[SOL] Add BPF target to LLDB
dmakarov Feb 26, 2023
b189d63
[SOL] Add implicit addend for R_SBF_64_ABS32 relocations
dmakarov Feb 26, 2023
c7adb51
[SOL] Handle BPF_64_64 relocations in .debug sections as ABS64
dmakarov Feb 27, 2023
2059337
[SOL] Make adjustments after upgrading to llvm 16.0
dmakarov Sep 28, 2023
5009ee1
[SOL] Revert 'Emit table lookup from TargetLowering::expandCTTZ()'
dmakarov Sep 28, 2023
affbaaf
[SOL] Temporarily disable opt-viewer tests for MacOS. (#71)
nvjle Dec 10, 2023
5964783
[SOL] Use ADD for subtracting stack pointer (#70)
LucasSte Dec 12, 2023
8da2e6d
[SOL] Remove now obsolete old syntax bits. (#72)
nvjle Dec 12, 2023
84575f1
[SOL] Remove `neg` and change the semantics of `sub` (#73)
LucasSte Dec 16, 2023
1d7960f
[SOL] Remove LE byte swap and input buffers (#75)
LucasSte Dec 21, 2023
3ad06bc
[SOL] Remove `lddw` instruction (#74)
LucasSte Dec 23, 2023
4deb2bc
[SOL] Add feature flag for the removal of neg and the new semantics o…
LucasSte Jan 3, 2024
ea3088d
[SOL] Add feature flag for disabling `lddw` (#77)
LucasSte Jan 4, 2024
16be570
[SOL] Change encoding of `callx` instruction (#78)
LucasSte Jan 4, 2024
e7a18d9
[SOL] Add tests for call (#79)
LucasSte Jan 9, 2024
492df33
[SOL] Remove `SBF_JMP32` instruction class (#80)
LucasSte Jan 15, 2024
af66dba
[SOL] Create PQR instruction class (#81)
LucasSte Jan 18, 2024
91366ef
[SOL] Fix Predicate naming convention (#82)
LucasSte Jan 19, 2024
bc57edc
[SOL] Allocate call arguments on a fixed stack object (#84)
LucasSte Jan 30, 2024
3a29295
[SOL] Adjust compilation after upgrading to LLVM 17
LucasSte Jan 31, 2024
0c7f94b
[SOL] Bring upstream BPF changes to SBF
LucasSte Jan 31, 2024
1cca672
[SOL] Update references to solana-labs redirecting them to anza-xyz
dmakarov Feb 22, 2024
c7c8086
[SOL] Enable mod instruction (#87)
LucasSte Feb 23, 2024
eb24e08
[SOL] Workaround sccache failure (#93)
LucasSte Mar 4, 2024
1dcdb13
[SOL] Remove cpu probe (#91)
LucasSte Mar 5, 2024
aae4d38
[SOL] Optimize call convention in SBFv2 (#94)
LucasSte Mar 27, 2024
53ecf87
[SOL] Remove icmp BPF builtin (#95)
LucasSte Apr 9, 2024
1b131ae
[SOL] Remove load builtins (#96)
LucasSte May 6, 2024
b131dcb
[SOL] Remove code adjustment (#98)
LucasSte Jun 20, 2024
a725ce4
[SOL] Do not miss stack size errors (#99)
LucasSte Jun 20, 2024
14b9cd9
[SOL] Correctly copy 16-byte aligned memory (#97)
LucasSte Jun 20, 2024
0a1dd96
[SOL] Inform stack size in error message (#100)
LucasSte Jul 2, 2024
25fabf7
[SOL] Error when we overwrite data on the stack (#106)
LucasSte Jul 9, 2024
b909bb5
[SOL] Error out when a function access an invalid offset (#107)
LucasSte Jul 10, 2024
b6a0835
[SOL] Do not crash for stack errors (#108)
LucasSte Jul 17, 2024
77c3646
[SOL] Fix misposiotioned InGlue (#109)
LucasSte Jul 31, 2024
19a1195
[SOL] Adjust backend after upgrade to LLVM 18
LucasSte Jun 30, 2024
2e039cf
[SOL] Expand atomic load and store
LucasSte Jul 23, 2024
c04ae67
[SOL] Implement atomic swap
LucasSte Jul 24, 2024
b07498f
[SOL] Register target
LucasSte Aug 9, 2024
0f67554
[SOL] Do not check relocs for SBF
LucasSte Aug 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .github/workflows/clang-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ permissions:
on:
workflow_dispatch:
push:
ignore-forks: true
branches:
- 'release/**'
paths:
Expand All @@ -14,6 +15,7 @@ on:
- '.github/workflows/llvm-project-tests.yml'
- '!llvm/**'
pull_request:
ignore-forks: true
branches:
- 'release/**'
paths:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/lld-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ permissions:
on:
workflow_dispatch:
push:
ignore-forks: true
branches:
- 'release/**'
paths:
Expand All @@ -14,6 +15,7 @@ on:
- '.github/workflows/llvm-project-tests.yml'
- '!llvm/**'
pull_request:
ignore-forks: true
branches:
- 'release/**'
paths:
Expand Down
63 changes: 25 additions & 38 deletions .github/workflows/llvm-project-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,19 @@ jobs:
strategy:
fail-fast: false
matrix:
os: ${{ fromJSON(inputs.os_list) }}
os:
- ubuntu-latest
# Use windows-2019 due to:
# https://developercommunity.visualstudio.com/t/Prev-Issue---with-__assume-isnan-/1597317
- windows-2019
# We're using a specific version of macOS due to:
# https://github.com/actions/virtual-environments/issues/5900
- macOS-latest
include:
- compile_cache: sccache

- compile_cache: ccache
os: macos-latest
steps:
- name: Setup Windows
if: startsWith(matrix.os, 'windows')
Expand All @@ -79,7 +91,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python_version }}
python-version: '3.11'
- name: Install Ninja
if: runner.os != 'Linux'
uses: llvm/actions/install-ninja@main
Expand All @@ -89,7 +101,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 250
- name: Setup ccache
- name: Setup ${{ matrix.compile_cache }}
uses: hendrikmuhs/ccache-action@v1
with:
# A full build of llvm, clang, lld, and lldb takes about 250MB
Expand All @@ -101,49 +113,24 @@ jobs:
# fit under the 10 GB limit.
# Default to 2G to workaround: https://github.com/hendrikmuhs/ccache-action/issues/174
max-size: 2G
key: ${{ matrix.os }}
variant: sccache
key: ${{ matrix.compile_cache }}-${{ matrix.os }}
variant: ${{ matrix.compile_cache }}
- name: Build and Test
if: "!startsWith(matrix.os, 'windows')"
uses: llvm/actions/build-test-llvm-project@main
env:
# Workaround for https://github.com/actions/virtual-environments/issues/5900.
# This should be a no-op for non-mac OSes
PKG_CONFIG_PATH: /usr/local/Homebrew/Library/Homebrew/os/mac/pkgconfig//12
shell: bash
id: build-llvm
run: |
if [ "${{ runner.os }}" == "Linux" ]; then
builddir="/mnt/build/"
mkdir -p $builddir
extra_cmake_args="-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang"
else
builddir="$(pwd)"/build
fi
if [ "${{ runner.os }}" == "macOS" ]; then
# Workaround test failure on some lld tests on MacOS
# https://github.com/llvm/llvm-project/issues/81967
extra_cmake_args="-DLLVM_DISABLE_ASSEMBLY_FILES=ON"
fi
echo "llvm-builddir=$builddir" >> "$GITHUB_OUTPUT"
cmake -G Ninja \
-B "$builddir" \
-S llvm \
-DLLVM_ENABLE_PROJECTS="${{ inputs.projects }}" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLDB_INCLUDE_TESTS=OFF \
-DCMAKE_C_COMPILER_LAUNCHER=sccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
$extra_cmake_args \
${{ inputs.extra_cmake_args }}
ninja -C "$builddir" '${{ inputs.build_target }}'
with:
cmake_args: '-GNinja -DLLVM_ENABLE_PROJECTS="${{ inputs.projects }}" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="BPF;SBF" -DCMAKE_BUILD_TYPE=Release -DLLDB_INCLUDE_TESTS=OFF -DCMAKE_C_COMPILER_LAUNCHER=${{ matrix.compile_cache }} -DCMAKE_CXX_COMPILER_LAUNCHER=${{ matrix.compile_cache }}'
build_target: '${{ inputs.build_target }}'

- name: Build and Test libclc
if: "!startsWith(matrix.os, 'windows') && contains(inputs.projects, 'libclc')"
env:
LLVM_BUILDDIR: ${{ steps.build-llvm.outputs.llvm-builddir }}
if: "!startsWith(matrix.os, 'windows') && !startsWith(matrix.os, 'macOS') && contains(inputs.projects, 'libclc')"
run: |
# Make sure all of LLVM libraries that llvm-config needs are built.
ninja -C "$LLVM_BUILDDIR"
cmake -G Ninja -S libclc -B libclc-build -DLLVM_DIR="$LLVM_BUILDDIR"/lib/cmake/llvm -DLIBCLC_TARGETS_TO_BUILD="amdgcn--;amdgcn--amdhsa;r600--;nvptx--;nvptx64--;nvptx--nvidiacl;nvptx64--nvidiacl"
ninja -C build
cmake -G Ninja -S libclc -B libclc-build -DLLVM_DIR=$(pwd)/build/lib/cmake/llvm -DLIBCLC_TARGETS_TO_BUILD="amdgcn--;amdgcn--amdhsa;r600--;nvptx--;nvptx64--;nvptx--nvidiacl;nvptx64--nvidiacl"
ninja -C libclc-build
ninja -C libclc-build test
41 changes: 30 additions & 11 deletions .github/workflows/llvm-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ permissions:
on:
workflow_dispatch:
push:
branches:
- 'release/**'
ignore-forks: true
#branches:
# - 'release/**'
paths:
- 'llvm/**'
- '.github/workflows/llvm-tests.yml'
- '.github/workflows/llvm-project-tests.yml'
pull_request:
branches:
- 'release/**'
ignore-forks: true
#branches:
# - 'release/**'
paths:
- 'llvm/**'
- '.github/workflows/llvm-tests.yml'
Expand All @@ -27,16 +29,33 @@ concurrency:
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}

jobs:
check-all:
if: github.repository_owner == 'llvm'
name: Build and Test
check_all:
#if: github.repository_owner == 'llvm'
name: Test llvm,clang,libclc
uses: ./.github/workflows/llvm-project-tests.yml
with:
build_target: check-all
projects: clang;lld;libclc;lldb
projects: clang;libclc

# These need to be separate from the check_all job, becuase there is not enough disk
# space to build all these projects on Windows.
build_lldb:
name: Build lldb
uses: ./.github/workflows/llvm-project-tests.yml
with:
build_target: ''
projects: clang;lldb

check_lld:
#if: github.repository_owner == 'llvm'
name: Test lld
uses: ./.github/workflows/llvm-project-tests.yml
with:
build_target: check-lld
projects: lld

abi-dump-setup:
if: github.repository_owner == 'llvm'
#if: github.repository_owner == 'llvm'
runs-on: ubuntu-latest
outputs:
BASELINE_REF: ${{ steps.vars.outputs.BASELINE_REF }}
Expand Down Expand Up @@ -79,7 +98,7 @@ jobs:
fi

abi-dump:
if: github.repository_owner == 'llvm'
#if: github.repository_owner == 'llvm'
needs: abi-dump-setup
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -150,7 +169,7 @@ jobs:
path: llvm.symbols

abi-compare:
if: github.repository_owner == 'llvm'
#if: github.repository_owner == 'llvm'
runs-on: ubuntu-latest
needs:
- abi-dump-setup
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# The LLVM Compiler Infrastructure modified to support Berkley Packet Filter modules written in Rust

This fork of LLVM is used by [this fork of Rust](https://github.com/anza-xyz/rust)

---

# The LLVM Compiler Infrastructure

[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/llvm/llvm-project/badge)](https://securityscorecards.dev/viewer/?uri=github.com/llvm/llvm-project)
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def TargetARM : TargetArch<["arm", "thumb", "armeb", "thumbeb"]>;
def TargetAArch64 : TargetArch<["aarch64", "aarch64_be", "aarch64_32"]>;
def TargetAnyArm : TargetArch<!listconcat(TargetARM.Arches, TargetAArch64.Arches)>;
def TargetAVR : TargetArch<["avr"]>;
def TargetBPF : TargetArch<["bpfel", "bpfeb"]>;
def TargetBPF : TargetArch<["bpfel", "bpfeb", "sbf"]>;
def TargetLoongArch : TargetArch<["loongarch32", "loongarch64"]>;
def TargetMips32 : TargetArch<["mips", "mipsel"]>;
def TargetAnyMips : TargetArch<["mips", "mipsel", "mips64", "mips64el"]>;
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -798,4 +798,8 @@ def warn_android_unversioned_fallback : Warning<

def err_drv_triple_version_invalid : Error<
"version '%0' in target triple '%1' is invalid">;

def warn_drv_no_solana_with_bpf : Warning<
"'+solana' with bpf target is deprecated; use '-target sbf' instead">;

}
2 changes: 2 additions & 0 deletions clang/lib/Basic/Targets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
case llvm::Triple::bpfeb:
case llvm::Triple::bpfel:
return std::make_unique<BPFTargetInfo>(Triple, Opts);
case llvm::Triple::sbf:
return std::make_unique<BPFTargetInfo>(Triple, Opts);

case llvm::Triple::msp430:
return std::make_unique<MSP430TargetInfo>(Triple, Opts);
Expand Down
15 changes: 14 additions & 1 deletion clang/lib/Basic/Targets/BPF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

#include "BPF.h"
#include "Targets.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/MacroBuilder.h"
#include "clang/Basic/TargetBuiltins.h"
#include "clang/Driver/DriverDiagnostic.h"
#include "llvm/ADT/StringRef.h"

using namespace clang;
Expand Down Expand Up @@ -60,10 +62,15 @@ void BPFTargetInfo::getTargetDefines(const LangOptions &Opts,
Builder.defineMacro("__BPF_FEATURE_GOTOL");
Builder.defineMacro("__BPF_FEATURE_ST");
}

if (HasSolanaFeature) {
Builder.defineMacro("__ELF__");
}
}


static constexpr llvm::StringLiteral ValidCPUNames[] = {"generic", "v1", "v2",
"v3", "v4", "probe"};
"v3", "v4", "probe", "sbfv2"};

bool BPFTargetInfo::isValidCPUName(StringRef Name) const {
return llvm::is_contained(ValidCPUNames, Name);
Expand All @@ -80,6 +87,12 @@ ArrayRef<Builtin::Info> BPFTargetInfo::getTargetBuiltins() const {

bool BPFTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
DiagnosticsEngine &Diags) {
// TODO: The SBF back-end now provides the sbf target. Issue deprecation
// warning directing use of '-target sbf' instead. Eventually remove the
// +solana support from the BPF back-end.
if (getTriple().getArch() != llvm::Triple::sbf && HasSolanaFeature)
Diags.Report(diag::warn_drv_no_solana_with_bpf);

for (const auto &Feature : Features) {
if (Feature == "+alu32") {
HasAlu32 = true;
Expand Down
30 changes: 26 additions & 4 deletions clang/lib/Basic/Targets/BPF.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ namespace clang {
namespace targets {

class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
bool HasSolanaFeature = false;
bool HasAlu32 = false;

public:
BPFTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
BPFTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
: TargetInfo(Triple) {
LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
SizeType = UnsignedLong;
Expand All @@ -34,10 +35,28 @@ class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
IntMaxType = SignedLong;
Int64Type = SignedLong;
RegParmMax = 5;
if (Triple.getArch() == llvm::Triple::sbf) {
HasSolanaFeature = true;
} else {
for (auto& it : Opts.FeaturesAsWritten) {
if (it == "+solana") {
HasSolanaFeature = true;
break;
}
}
}
if (Triple.getArch() == llvm::Triple::bpfeb) {
resetDataLayout("E-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
if (HasSolanaFeature) {
resetDataLayout("E-m:e-p:64:64-i64:64-n32:64-S128");
} else {
resetDataLayout("E-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
}
} else {
resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
if (HasSolanaFeature) {
resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128");
} else {
resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
}
}
MaxAtomicPromoteWidth = 64;
MaxAtomicInlineWidth = 64;
Expand All @@ -48,7 +67,8 @@ class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
MacroBuilder &Builder) const override;

bool hasFeature(StringRef Feature) const override {
return Feature == "bpf" || Feature == "alu32" || Feature == "dwarfris";
return Feature == "bpf" || Feature == "alu32" || Feature == "dwarfris" ||
Feature == "solana";
}

void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
Expand Down Expand Up @@ -113,6 +133,8 @@ class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
StringRef CPUName(Name);
return isValidCPUName(CPUName);
}

bool hasBitIntType() const override { return HasSolanaFeature; }
};
} // namespace targets
} // namespace clang
Expand Down
1 change: 1 addition & 0 deletions clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6019,6 +6019,7 @@ static Value *EmitTargetArchBuiltinExpr(CodeGenFunction *CGF,
return CGF->EmitAArch64BuiltinExpr(BuiltinID, E, Arch);
case llvm::Triple::bpfeb:
case llvm::Triple::bpfel:
case llvm::Triple::sbf:
return CGF->EmitBPFBuiltinExpr(BuiltinID, E);
case llvm::Triple::x86:
case llvm::Triple::x86_64:
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ add_clang_library(clangDriver
ToolChain.cpp
ToolChains/Arch/AArch64.cpp
ToolChains/Arch/ARM.cpp
ToolChains/Arch/BPF.cpp
ToolChains/Arch/CSKY.cpp
ToolChains/Arch/LoongArch.cpp
ToolChains/Arch/M68k.cpp
Expand Down
Loading
Loading