Skip to content

Commit

Permalink
[BPF] Allow selectively disable compiler builtins for BPF target (#4)
Browse files Browse the repository at this point in the history
* [BPF] Add method to check whether a triple is a BPF architecture

* [BPF] Make rust allocation builtins unavailable for BPF target

- the calls to rust alloc/dealloc routines need to be preserved and
not replaced by compiler generated builtin inlined code
  • Loading branch information
dmakarov authored Feb 17, 2021
1 parent a38156a commit 55b88a4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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);
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.
// 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

0 comments on commit 55b88a4

Please sign in to comment.