Skip to content

[BPF] Allow selectively disable compiler builtins for BPF target #4

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

Merged
merged 2 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions llvm/include/llvm/ADT/Triple.h
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,11 @@ class Triple {
return getArch() == Triple::aarch64 || getArch() == Triple::aarch64_be;
}

/// Tests whether the target is BPF (little and big endian).
bool isBPF() const {
return getArch() == Triple::bpfel || getArch() == Triple::bpfeb;
}

/// Tests whether the target is MIPS 32-bit (little and big endian).
bool isMIPS32() const {
return getArch() == Triple::mips || getArch() == Triple::mipsel;
Expand Down
10 changes: 8 additions & 2 deletions llvm/lib/Analysis/TargetLibraryInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,12 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
TLI.setUnavailable(LibFunc_nvvm_reflect);
}

if (T.isBPF()) {
TLI.setUnavailable(LibFunc_rust_alloc);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does llvm have to have any knowledge of these rust functions?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does. It replaces them with internal built-ins, which these calls to TLI.setUnavailable() prevent from happening.

TLI.setUnavailable(LibFunc_rust_dealloc);
TLI.setUnavailable(LibFunc_rust_realloc);
}

TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary);
}

Expand Down Expand Up @@ -1503,9 +1509,9 @@ bool TargetLibraryInfoImpl::getLibFunc(const Function &FDecl,
LibFunc &F) const {
// Intrinsics don't overlap w/libcalls; if our module has a large number of
// intrinsics, this ends up being an interesting compile time win since we
// avoid string normalization and comparison.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes probably not necessary

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep it... the trailing white space is bad in source code (my editor automatically deletes it on saving a file)

// avoid string normalization and comparison.
if (FDecl.isIntrinsic()) return false;

const DataLayout *DL =
FDecl.getParent() ? &FDecl.getParent()->getDataLayout() : nullptr;
return getLibFunc(FDecl.getName(), F) &&
Expand Down