From 55b88a4bb6cafc139aa6940184dbdcc33c00e1fb Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Wed, 17 Feb 2021 20:34:06 +0100 Subject: [PATCH] [BPF] Allow selectively disable compiler builtins for BPF target (#4) * [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 --- llvm/include/llvm/ADT/Triple.h | 5 +++++ llvm/lib/Analysis/TargetLibraryInfo.cpp | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/ADT/Triple.h b/llvm/include/llvm/ADT/Triple.h index 76a754d671fb69..2ce02a3d9e273c 100644 --- a/llvm/include/llvm/ADT/Triple.h +++ b/llvm/include/llvm/ADT/Triple.h @@ -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; diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp index 21c625df97ddad..46188bbcfab5aa 100644 --- a/llvm/lib/Analysis/TargetLibraryInfo.cpp +++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp @@ -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); } @@ -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) &&