Skip to content
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
31 changes: 31 additions & 0 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,36 @@ static bool initTargetOptions(const CompilerInstance &CI,
Options.JMCInstrument = CodeGenOpts.JMCInstrument;
Options.XCOFFReadOnlyPointers = CodeGenOpts.XCOFFReadOnlyPointers;

switch (CodeGenOpts.getVecLib()) {
case llvm::driver::VectorLibrary::NoLibrary:
Options.VectorLibrary = llvm::VectorLibrary::NoLibrary;
break;
case llvm::driver::VectorLibrary::Accelerate:
Options.VectorLibrary = llvm::VectorLibrary::Accelerate;
break;
case llvm::driver::VectorLibrary::Darwin_libsystem_m:
Options.VectorLibrary = llvm::VectorLibrary::DarwinLibSystemM;
break;
case llvm::driver::VectorLibrary::LIBMVEC:
Options.VectorLibrary = llvm::VectorLibrary::LIBMVEC;
break;
case llvm::driver::VectorLibrary::MASSV:
Options.VectorLibrary = llvm::VectorLibrary::MASSV;
break;
case llvm::driver::VectorLibrary::SVML:
Options.VectorLibrary = llvm::VectorLibrary::SVML;
break;
case llvm::driver::VectorLibrary::SLEEF:
Options.VectorLibrary = llvm::VectorLibrary::SLEEFGNUABI;
break;
case llvm::driver::VectorLibrary::ArmPL:
Options.VectorLibrary = llvm::VectorLibrary::ArmPL;
break;
case llvm::driver::VectorLibrary::AMDLIBM:
Options.VectorLibrary = llvm::VectorLibrary::AMDLIBM;
break;
}

switch (CodeGenOpts.getSwiftAsyncFramePointer()) {
case CodeGenOptions::SwiftAsyncFramePointerKind::Auto:
Options.SwiftAsyncFramePointer =
Expand Down Expand Up @@ -584,6 +614,7 @@ static void setCommandLineOpts(const CodeGenOptions &CodeGenOpts,
BackendArgs.push_back("-limit-float-precision");
BackendArgs.push_back(CodeGenOpts.LimitFloatPrecision.c_str());
}

// Check for the default "clang" invocation that won't set any cl::opt values.
// Skip trying to parse the command line invocation to avoid the issues
// described below.
Expand Down
7 changes: 7 additions & 0 deletions cross-project-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ add_lit_testsuite(check-cross-dtlto "Running DTLTO cross-project tests"
DEPENDS ${CROSS_PROJECT_TEST_DEPS}
)

# veclib tests.
add_lit_testsuite(check-cross-veclib "Running veclib cross-project tests"
${CMAKE_CURRENT_BINARY_DIR}/veclib
EXCLUDE_FROM_CHECK_ALL
DEPENDS ${CROSS_PROJECT_TEST_DEPS}
)

# Add check-cross-project-* targets.
add_lit_testsuites(CROSS_PROJECT ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${CROSS_PROJECT_TEST_DEPS}
Expand Down
2 changes: 2 additions & 0 deletions cross-project-tests/veclib/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
if "clang" not in config.available_features:
config.unsupported = True
21 changes: 21 additions & 0 deletions cross-project-tests/veclib/veclib-sincos.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// REQUIRES: aarch64-registered-target
// RUN: %clang -S -target aarch64-unknown-linux-gnu -O2 -fno-math-errno \
// RUN: -fveclib=ArmPL -o - %s | FileCheck -check-prefix=ARMPL %s
// RUN: %clang -S -target aarch64-unknown-linux-gnu -O2 -fno-math-errno \
// RUN: -fveclib=SLEEF -o - %s | FileCheck -check-prefix=SLEEF %s

typedef __SIZE_TYPE__ size_t;

void sincos(double, double *, double *);

// ARMPL: armpl_vsincosq_f64
// ARMPL: armpl_vsincosq_f64

// SLEEF: _ZGVnN2vl8l8_sincos
// SLEEF: _ZGVnN2vl8l8_sincos
void vectorize_sincos(double *restrict x, double *restrict s,
double *restrict c, size_t n) {
for (size_t i = 0; i < n; ++i) {
sincos(x[i], &s[i], &c[i]);
}
}
2 changes: 1 addition & 1 deletion llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class LLVM_ABI RuntimeLibraryAnalysis
friend AnalysisInfoMixin<RuntimeLibraryAnalysis>;
LLVM_ABI static AnalysisKey Key;

RTLIB::RuntimeLibcallsInfo LibcallsInfo;
std::optional<RTLIB::RuntimeLibcallsInfo> LibcallsInfo;
};

class LLVM_ABI RuntimeLibraryInfoWrapper : public ImmutablePass {
Expand Down
5 changes: 3 additions & 2 deletions llvm/include/llvm/Analysis/TargetLibraryInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/SystemLibraries.h"
#include "llvm/Pass.h"
#include "llvm/Support/Compiler.h"
#include "llvm/TargetParser/Triple.h"
Expand All @@ -23,7 +24,6 @@
namespace llvm {

template <typename T> class ArrayRef;
enum class VectorLibrary;

/// Provides info so a possible vectorization of a function can be
/// computed. Function 'VectorFnName' is equivalent to 'ScalarFnName'
Expand Down Expand Up @@ -119,7 +119,8 @@ class TargetLibraryInfoImpl {

public:
TargetLibraryInfoImpl() = delete;
LLVM_ABI explicit TargetLibraryInfoImpl(const Triple &T);
LLVM_ABI explicit TargetLibraryInfoImpl(
const Triple &T, VectorLibrary VecLib = VectorLibrary::NoLibrary);

// Provide value semantics.
LLVM_ABI TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI);
Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/CodeGen/CommandFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ LLVM_ABI llvm::EABI getEABIVersion();

LLVM_ABI llvm::DebuggerKind getDebuggerTuningOpt();

LLVM_ABI llvm::VectorLibrary getVectorLibrary();

LLVM_ABI bool getEnableStackSizeSection();

LLVM_ABI bool getEnableAddrsig();
Expand Down
4 changes: 3 additions & 1 deletion llvm/include/llvm/IR/RuntimeLibcalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/SystemLibraries.h"
#include "llvm/Support/AtomicOrdering.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/Compiler.h"
Expand Down Expand Up @@ -83,7 +84,8 @@ struct RuntimeLibcallsInfo {
const Triple &TT,
ExceptionHandling ExceptionModel = ExceptionHandling::None,
FloatABI::ABIType FloatABI = FloatABI::Default,
EABI EABIVersion = EABI::Default, StringRef ABIName = "");
EABI EABIVersion = EABI::Default, StringRef ABIName = "",
VectorLibrary VecLib = VectorLibrary::NoLibrary);

explicit RuntimeLibcallsInfo(const Module &M);

Expand Down
5 changes: 0 additions & 5 deletions llvm/include/llvm/IR/SystemLibraries.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ enum class VectorLibrary {
AMDLIBM // AMD Math Vector library.
};

/// Command line flag value for the vector math library to use
///
/// FIXME: This should come from a module flag, and not be mutually exclusive
extern VectorLibrary ClVectorLibrary;

} // namespace llvm

#endif // LLVM_IR_SYSTEMLIBRARIES_H
4 changes: 4 additions & 0 deletions llvm/include/llvm/Target/TargetOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define LLVM_TARGET_TARGETOPTIONS_H

#include "llvm/ADT/FloatingPointMode.h"
#include "llvm/IR/SystemLibraries.h"
#include "llvm/MC/MCTargetOptions.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/Compiler.h"
Expand Down Expand Up @@ -409,6 +410,9 @@ class TargetOptions {
/// Which debugger to tune for.
DebuggerKind DebuggerTuning = DebuggerKind::Default;

/// Vector math library to use.
VectorLibrary VectorLibrary = VectorLibrary::NoLibrary;

private:
/// Flushing mode to assume in default FP environment.
DenormalMode FPDenormalMode;
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Analysis/RuntimeLibcallInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ AnalysisKey RuntimeLibraryAnalysis::Key;

RTLIB::RuntimeLibcallsInfo
RuntimeLibraryAnalysis::run(const Module &M, ModuleAnalysisManager &) {
return RTLIB::RuntimeLibcallsInfo(M);
if (!LibcallsInfo)
LibcallsInfo = RTLIB::RuntimeLibcallsInfo(M);
return *LibcallsInfo;
}

INITIALIZE_PASS(RuntimeLibraryInfoWrapper, "runtime-library-info",
Expand Down
15 changes: 9 additions & 6 deletions llvm/lib/Analysis/TargetLibraryInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ static void initializeBase(TargetLibraryInfoImpl &TLI, const Triple &T) {
/// target triple. This should be carefully written so that a missing target
/// triple gets a sane set of defaults.
static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
ArrayRef<StringLiteral> StandardNames) {
ArrayRef<StringLiteral> StandardNames,
VectorLibrary VecLib) {
// Set IO unlocked variants as unavailable
// Set them as available per system below
TLI.setUnavailable(LibFunc_getc_unlocked);
Expand Down Expand Up @@ -924,23 +925,25 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
if (T.isOSAIX())
TLI.setUnavailable(LibFunc_memrchr);

TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary, T);
TLI.addVectorizableFunctionsFromVecLib(VecLib, T);
}

/// Initialize the set of available library functions based on the specified
/// target triple. This should be carefully written so that a missing target
/// triple gets a sane set of defaults.
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
ArrayRef<StringLiteral> StandardNames) {
ArrayRef<StringLiteral> StandardNames,
VectorLibrary VecLib) {
initializeBase(TLI, T);
initializeLibCalls(TLI, T, StandardNames);
initializeLibCalls(TLI, T, StandardNames, VecLib);
}

TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T) {
TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T,
VectorLibrary VecLib) {
// Default to everything being available.
memset(AvailableArray, -1, sizeof(AvailableArray));

initialize(*this, T, StandardNames);
initialize(*this, T, StandardNames, VecLib);
}

TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI)
Expand Down
24 changes: 24 additions & 0 deletions llvm/lib/CodeGen/CommandFlags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ CGOPT(bool, UniqueBasicBlockSectionNames)
CGOPT(bool, SeparateNamedSections)
CGOPT(EABI, EABIVersion)
CGOPT(DebuggerKind, DebuggerTuningOpt)
CGOPT(VectorLibrary, VectorLibrary)
CGOPT(bool, EnableStackSizeSection)
CGOPT(bool, EnableAddrsig)
CGOPT(bool, EnableCallGraphSection)
Expand Down Expand Up @@ -451,6 +452,28 @@ codegen::RegisterCodeGenFlags::RegisterCodeGenFlags() {
clEnumValN(DebuggerKind::SCE, "sce", "SCE targets (e.g. PS4)")));
CGBINDOPT(DebuggerTuningOpt);

static cl::opt<VectorLibrary> VectorLibrary(
"vector-library", cl::Hidden, cl::desc("Vector functions library"),
cl::init(VectorLibrary::NoLibrary),
cl::values(
clEnumValN(VectorLibrary::NoLibrary, "none",
"No vector functions library"),
clEnumValN(VectorLibrary::Accelerate, "Accelerate",
"Accelerate framework"),
clEnumValN(VectorLibrary::DarwinLibSystemM, "Darwin_libsystem_m",
"Darwin libsystem_m"),
clEnumValN(VectorLibrary::LIBMVEC, "LIBMVEC",
"GLIBC Vector Math library"),
clEnumValN(VectorLibrary::MASSV, "MASSV", "IBM MASS vector library"),
clEnumValN(VectorLibrary::SVML, "SVML", "Intel SVML library"),
clEnumValN(VectorLibrary::SLEEFGNUABI, "sleefgnuabi",
"SIMD Library for Evaluating Elementary Functions"),
clEnumValN(VectorLibrary::ArmPL, "ArmPL",
"Arm Performance Libraries"),
clEnumValN(VectorLibrary::AMDLIBM, "AMDLIBM",
"AMD vector math library")));
CGBINDOPT(VectorLibrary);

static cl::opt<bool> EnableStackSizeSection(
"stack-size-section",
cl::desc("Emit a section containing stack size metadata"),
Expand Down Expand Up @@ -609,6 +632,7 @@ codegen::InitTargetOptionsFromCodeGenFlags(const Triple &TheTriple) {
Options.EnableTLSDESC =
getExplicitEnableTLSDESC().value_or(TheTriple.hasDefaultTLSDESC());
Options.ExceptionModel = getExceptionModel();
Options.VectorLibrary = getVectorLibrary();
Options.EmitStackSizeSection = getEnableStackSizeSection();
Options.EnableMachineFunctionSplitter = getEnableMachineFunctionSplitter();
Options.EnableStaticDataPartitioning = getEnableStaticDataPartitioning();
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/CodeGen/TargetLoweringBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,8 @@ TargetLoweringBase::TargetLoweringBase(const TargetMachine &tm)
: TM(tm),
RuntimeLibcallInfo(TM.getTargetTriple(), TM.Options.ExceptionModel,
TM.Options.FloatABIType, TM.Options.EABIVersion,
TM.Options.MCOptions.getABIName()),
TM.Options.MCOptions.getABIName(),
TM.Options.VectorLibrary),
Libcalls(RuntimeLibcallInfo) {
initActions();

Expand Down
1 change: 0 additions & 1 deletion llvm/lib/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ add_llvm_component_library(LLVMCore
ReplaceConstant.cpp
Statepoint.cpp
StructuralHash.cpp
SystemLibraries.cpp
Type.cpp
TypedPointerType.cpp
TypeFinder.cpp
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/IR/RuntimeLibcalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ using namespace RTLIB;
RuntimeLibcallsInfo::RuntimeLibcallsInfo(const Triple &TT,
ExceptionHandling ExceptionModel,
FloatABI::ABIType FloatABI,
EABI EABIVersion, StringRef ABIName) {
EABI EABIVersion, StringRef ABIName,
VectorLibrary VecLib) {
// FIXME: The ExceptionModel parameter is to handle the field in
// TargetOptions. This interface fails to distinguish the forced disable
// case for targets which support exceptions by default. This should
Expand All @@ -40,7 +41,7 @@ RuntimeLibcallsInfo::RuntimeLibcallsInfo(const Triple &TT,
initLibcalls(TT, ExceptionModel, FloatABI, EABIVersion, ABIName);

// TODO: Tablegen should generate these sets
switch (ClVectorLibrary) {
switch (VecLib) {
case VectorLibrary::SLEEFGNUABI:
for (RTLIB::LibcallImpl Impl :
{RTLIB::impl__ZGVnN2vl8_modf, RTLIB::impl__ZGVnN4vl4_modff,
Expand Down
34 changes: 0 additions & 34 deletions llvm/lib/IR/SystemLibraries.cpp

This file was deleted.

5 changes: 4 additions & 1 deletion llvm/lib/Transforms/Utils/DeclareRuntimeLibcalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

#include "llvm/Transforms/Utils/DeclareRuntimeLibcalls.h"
#include "llvm/Analysis/RuntimeLibcallInfo.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/RuntimeLibcalls.h"

Expand Down Expand Up @@ -49,7 +50,9 @@ static void mergeAttributes(LLVMContext &Ctx, const Module &M,

PreservedAnalyses DeclareRuntimeLibcallsPass::run(Module &M,
ModuleAnalysisManager &MAM) {
RTLIB::RuntimeLibcallsInfo RTLCI(M.getTargetTriple());
const RTLIB::RuntimeLibcallsInfo &RTLCI =
MAM.getResult<RuntimeLibraryAnalysis>(M);

LLVMContext &Ctx = M.getContext();
const DataLayout &DL = M.getDataLayout();
const Triple &TT = M.getTargetTriple();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
; REQUIRES: arm-registered-target

; Make sure that codegen flags work to change the set of libcalls
; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=arm-none-linux-gnueabi -float-abi=hard -exception-model=sjlj -meabi=4 < %s | FileCheck %s

; Depends on -exception-model
; CHECK: declare arm_aapcs_vfpcc void @_Unwind_SjLj_Register(...)
; CHECK: declare arm_aapcs_vfpcc void @_Unwind_SjLj_Resume(...)
; CHECK: declare arm_aapcs_vfpcc void @_Unwind_SjLj_Unregister(...)

; Calling convention depends on -float-abi
; CHECK: declare arm_aapcs_vfpcc void @__addtf3(...)

; memclr functions depend on -meabi
; CHECK: declare arm_aapcscc void @__aeabi_memclr(...)
; CHECK: declare arm_aapcscc void @__aeabi_memclr4(...)
; CHECK: declare arm_aapcscc void @__aeabi_memclr8(...)
3 changes: 2 additions & 1 deletion llvm/tools/llc/llc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,8 @@ static int compileModule(char **argv, LLVMContext &Context,
}

// Add an appropriate TargetLibraryInfo pass for the module's triple.
TargetLibraryInfoImpl TLII(M->getTargetTriple());
TargetLibraryInfoImpl TLII(M->getTargetTriple(),
Target->Options.VectorLibrary);

// The -disable-simplify-libcalls flag actually disables all builtin optzns.
if (DisableSimplifyLibCalls)
Expand Down
Loading
Loading