From eee5d2d37c761e71d7a406acc112be0c71f4c3af Mon Sep 17 00:00:00 2001 From: Michael Maitland Date: Wed, 10 Jul 2024 15:39:08 -0400 Subject: [PATCH 01/10] [RISCV] Add ability to list extensions enabled for a target (#98207) bb83a3d introduced `--print-enabled-extensions` command line option for AArch64. This patch introduces RISC-V support for this option. This patch adds documentation for this option. `riscvExtensionsHelp` is renamed to `printSupportedExtensions` to by synonymous with AArch64 and so it is clear what that function does. --- clang/docs/CommandGuide/clang.rst | 6 +++ clang/include/clang/Driver/Options.td | 2 +- clang/lib/Driver/Driver.cpp | 1 + clang/tools/driver/cc1_main.cpp | 13 ++++-- llvm/include/llvm/TargetParser/RISCVISAInfo.h | 7 +++- llvm/lib/TargetParser/RISCVISAInfo.cpp | 42 ++++++++++++++++++- .../TargetParser/RISCVISAInfoTest.cpp | 31 +++++++++++++- 7 files changed, 94 insertions(+), 8 deletions(-) diff --git a/clang/docs/CommandGuide/clang.rst b/clang/docs/CommandGuide/clang.rst index 14400c39e91908..a348f3640c5eb8 100644 --- a/clang/docs/CommandGuide/clang.rst +++ b/clang/docs/CommandGuide/clang.rst @@ -393,6 +393,12 @@ number of cross compilers, or may only support a native target. allowed to generate instructions that are valid on i486 and later processors, but which may not exist on earlier ones. +.. option:: --print-enabled-extensions + + Prints the list of extensions that are enabled for the target specified by the + combination of `--target`, `-march`, and `-mcpu` values. Currently, this + option is only supported on AArch64 and RISC-V. On RISC-V, this option also + prints out the ISA string of enabled extensions. Code Generation Options ~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 5a79d99c22e098..cfb37b3c5b474d 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5731,7 +5731,7 @@ def print_supported_extensions : Flag<["-", "--"], "print-supported-extensions"> def print_enabled_extensions : Flag<["-", "--"], "print-enabled-extensions">, Visibility<[ClangOption, CC1Option, CLOption]>, HelpText<"Print the extensions enabled by the given target and -march/-mcpu options." - " (AArch64 only)">, + " (AArch64 and RISC-V only)">, MarshallingInfoFlag>; def : Flag<["-"], "mcpu=help">, Alias; def : Flag<["-"], "mtune=help">, Alias; diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 021c5b8a33dba9..28c3b52483e510 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -4367,6 +4367,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args, return; } if (Opt == options::OPT_print_enabled_extensions && + !C.getDefaultToolChain().getTriple().isRISCV() && !C.getDefaultToolChain().getTriple().isAArch64()) { C.getDriver().Diag(diag::err_opt_not_valid_on_target) << "--print-enabled-extensions"; diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp index 3c0599c2e51491..c2ccb47a15bc85 100644 --- a/clang/tools/driver/cc1_main.cpp +++ b/clang/tools/driver/cc1_main.cpp @@ -147,7 +147,7 @@ static int PrintSupportedExtensions(std::string TargetStr) { DescMap.insert({feature.Key, feature.Desc}); if (MachineTriple.isRISCV()) - llvm::riscvExtensionsHelp(DescMap); + llvm::RISCVISAInfo::printSupportedExtensions(DescMap); else if (MachineTriple.isAArch64()) llvm::AArch64::PrintSupportedExtensions(); else if (MachineTriple.isARM()) @@ -190,13 +190,20 @@ static int PrintEnabledExtensions(const TargetOptions& TargetOpts) { for (const llvm::SubtargetFeatureKV &feature : Features) EnabledFeatureNames.insert(feature.Key); - if (!MachineTriple.isAArch64()) { + if (MachineTriple.isAArch64()) + llvm::AArch64::printEnabledExtensions(EnabledFeatureNames); + else if (MachineTriple.isRISCV()) { + llvm::StringMap DescMap; + for (const llvm::SubtargetFeatureKV &feature : Features) + DescMap.insert({feature.Key, feature.Desc}); + llvm::RISCVISAInfo::printEnabledExtensions(MachineTriple.isArch64Bit(), + EnabledFeatureNames, DescMap); + } else { // The option was already checked in Driver::HandleImmediateArgs, // so we do not expect to get here if we are not a supported architecture. assert(0 && "Unhandled triple for --print-enabled-extensions option."); return 1; } - llvm::AArch64::printEnabledExtensions(EnabledFeatureNames); return 0; } diff --git a/llvm/include/llvm/TargetParser/RISCVISAInfo.h b/llvm/include/llvm/TargetParser/RISCVISAInfo.h index 5d3f3e113e96d3..d7a08013fa6ac2 100644 --- a/llvm/include/llvm/TargetParser/RISCVISAInfo.h +++ b/llvm/include/llvm/TargetParser/RISCVISAInfo.h @@ -15,11 +15,11 @@ #include "llvm/Support/RISCVISAUtils.h" #include +#include #include #include namespace llvm { -void riscvExtensionsHelp(StringMap DescMap); class RISCVISAInfo { public: @@ -75,6 +75,11 @@ class RISCVISAInfo { unsigned MinorVersion); static std::string getTargetFeatureForExtension(StringRef Ext); + static void printSupportedExtensions(StringMap &DescMap); + static void printEnabledExtensions(bool IsRV64, + std::set &EnabledFeatureNames, + StringMap &DescMap); + private: RISCVISAInfo(unsigned XLen) : XLen(XLen) {} diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp index 0229b5a140f91b..254a3f8aa95e07 100644 --- a/llvm/lib/TargetParser/RISCVISAInfo.cpp +++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp @@ -80,8 +80,7 @@ static void PrintExtension(StringRef Name, StringRef Version, << Description << "\n"; } -void llvm::riscvExtensionsHelp(StringMap DescMap) { - +void RISCVISAInfo::printSupportedExtensions(StringMap &DescMap) { outs() << "All available -march extensions for RISC-V\n\n"; PrintExtension("Name", "Version", (DescMap.empty() ? "" : "Description")); @@ -116,6 +115,45 @@ void llvm::riscvExtensionsHelp(StringMap DescMap) { "For example, clang -march=rv32i_v1p0\n"; } +void RISCVISAInfo::printEnabledExtensions( + bool IsRV64, std::set &EnabledFeatureNames, + StringMap &DescMap) { + outs() << "Extensions enabled for the given RISC-V target\n\n"; + PrintExtension("Name", "Version", (DescMap.empty() ? "" : "Description")); + + RISCVISAUtils::OrderedExtensionMap FullExtMap; + RISCVISAUtils::OrderedExtensionMap ExtMap; + for (const auto &E : SupportedExtensions) + if (EnabledFeatureNames.count(E.Name) != 0) { + FullExtMap[E.Name] = {E.Version.Major, E.Version.Minor}; + ExtMap[E.Name] = {E.Version.Major, E.Version.Minor}; + } + for (const auto &E : ExtMap) { + std::string Version = + std::to_string(E.second.Major) + "." + std::to_string(E.second.Minor); + PrintExtension(E.first, Version, DescMap[E.first]); + } + + outs() << "\nExperimental extensions\n"; + ExtMap.clear(); + for (const auto &E : SupportedExperimentalExtensions) { + StringRef Name(E.Name); + if (EnabledFeatureNames.count("experimental-" + Name.str()) != 0) { + FullExtMap[E.Name] = {E.Version.Major, E.Version.Minor}; + ExtMap[E.Name] = {E.Version.Major, E.Version.Minor}; + } + } + for (const auto &E : ExtMap) { + std::string Version = + std::to_string(E.second.Major) + "." + std::to_string(E.second.Minor); + PrintExtension(E.first, Version, DescMap["experimental-" + E.first]); + } + + unsigned XLen = IsRV64 ? 64 : 32; + if (auto ISAString = RISCVISAInfo::createFromExtMap(XLen, FullExtMap)) + outs() << "\nISA String: " << ISAString.get()->toString(); +} + static bool stripExperimentalPrefix(StringRef &Ext) { return Ext.consume_front("experimental-"); } diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp index 50a8d7b6b12119..889fbec6c60088 100644 --- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp +++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp @@ -1060,7 +1060,7 @@ For example, clang -march=rv32i_v1p0)"; outs().flush(); testing::internal::CaptureStdout(); - riscvExtensionsHelp(DummyMap); + RISCVISAInfo::printSupportedExtensions(DummyMap); outs().flush(); std::string CapturedOutput = testing::internal::GetCapturedStdout(); @@ -1068,3 +1068,32 @@ For example, clang -march=rv32i_v1p0)"; return Captured.find(Expected) != std::string::npos; }(CapturedOutput, ExpectedOutput)); } + +TEST(TargetParserTest, RISCVPrintEnabledExtensions) { + // clang-format off + std::string ExpectedOutput = +R"(Extensions enabled for the given RISC-V target + + Name Version Description + i 2.1 'I' (Base Integer Instruction Set) + +Experimental extensions + zicfilp 0.4 'Zicfilp' (Landing pad) + +ISA String: rv64i2p1_zicfilp0p4_zicsr2p0)"; + // clang-format on + + StringMap DescMap; + DescMap["i"] = "'I' (Base Integer Instruction Set)"; + DescMap["experimental-zicfilp"] = "'Zicfilp' (Landing pad)"; + std::set EnabledExtensions = {"i", "experimental-zicfilp"}; + + outs().flush(); + testing::internal::CaptureStdout(); + RISCVISAInfo::printEnabledExtensions(/*IsRV64=*/true, EnabledExtensions, + DescMap); + outs().flush(); + std::string CapturedOutput = testing::internal::GetCapturedStdout(); + + EXPECT_EQ(CapturedOutput, ExpectedOutput); +} From 8c664a9f507fb36aaec995a895178d88566ad58f Mon Sep 17 00:00:00 2001 From: Poseydon42 Date: Wed, 10 Jul 2024 20:51:55 +0100 Subject: [PATCH 02/10] [InstCombine] Fold negation of calls to `ucmp/scmp` by swapping its operands (#98360) Proofs: https://alive2.llvm.org/ce/z/cp_a36 --- .../InstCombine/InstCombineNegator.cpp | 5 ++++ llvm/test/Transforms/InstCombine/scmp.ll | 29 +++++++++++++++++++ llvm/test/Transforms/InstCombine/ucmp.ll | 29 +++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp index b3426562a4d879..e4895b59f4b4a9 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp @@ -222,6 +222,11 @@ std::array Negator::getSortedOperandsOfBinOp(Instruction *I) { } break; } + case Instruction::Call: + if (auto *CI = dyn_cast(I); CI && CI->hasOneUse()) + return Builder.CreateIntrinsic(CI->getType(), CI->getIntrinsicID(), + {CI->getRHS(), CI->getLHS()}); + break; default: break; // Other instructions require recursive reasoning. } diff --git a/llvm/test/Transforms/InstCombine/scmp.ll b/llvm/test/Transforms/InstCombine/scmp.ll index 4f903a79afd5d4..2523872562cad9 100644 --- a/llvm/test/Transforms/InstCombine/scmp.ll +++ b/llvm/test/Transforms/InstCombine/scmp.ll @@ -1,6 +1,8 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s +declare void @use(i8 %value) + define i1 @scmp_eq_0(i32 %x, i32 %y) { ; CHECK-LABEL: define i1 @scmp_eq_0( ; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) { @@ -154,3 +156,30 @@ define i1 @scmp_sle_neg_1(i32 %x, i32 %y) { %2 = icmp sle i8 %1, -1 ret i1 %2 } + +; ========== Fold -scmp(x, y) => scmp(y, x) ========== +define i8 @scmp_negated(i32 %x, i32 %y) { +; CHECK-LABEL: define i8 @scmp_negated( +; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) { +; CHECK-NEXT: [[TMP2:%.*]] = call i8 @llvm.scmp.i8.i32(i32 [[Y]], i32 [[X]]) +; CHECK-NEXT: ret i8 [[TMP2]] +; + %1 = call i8 @llvm.scmp(i32 %x, i32 %y) + %2 = sub i8 0, %1 + ret i8 %2 +} + +; Negative test: do not fold if the original scmp result is already used +define i8 @scmp_negated_multiuse(i32 %x, i32 %y) { +; CHECK-LABEL: define i8 @scmp_negated_multiuse( +; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) { +; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.scmp.i8.i32(i32 [[X]], i32 [[Y]]) +; CHECK-NEXT: call void @use(i8 [[TMP1]]) +; CHECK-NEXT: [[TMP2:%.*]] = sub nsw i8 0, [[TMP1]] +; CHECK-NEXT: ret i8 [[TMP2]] +; + %1 = call i8 @llvm.scmp(i32 %x, i32 %y) + call void @use(i8 %1) + %2 = sub i8 0, %1 + ret i8 %2 +} diff --git a/llvm/test/Transforms/InstCombine/ucmp.ll b/llvm/test/Transforms/InstCombine/ucmp.ll index 9ab67560c91173..7210455094baac 100644 --- a/llvm/test/Transforms/InstCombine/ucmp.ll +++ b/llvm/test/Transforms/InstCombine/ucmp.ll @@ -1,6 +1,8 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s +declare void @use(i8 %value) + define i1 @ucmp_eq_0(i32 %x, i32 %y) { ; CHECK-LABEL: define i1 @ucmp_eq_0( ; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) { @@ -154,3 +156,30 @@ define i1 @ucmp_sle_neg_1(i32 %x, i32 %y) { %2 = icmp sle i8 %1, -1 ret i1 %2 } + +; ========== Fold -ucmp(x, y) => ucmp(y, x) ========== +define i8 @ucmp_negated(i32 %x, i32 %y) { +; CHECK-LABEL: define i8 @ucmp_negated( +; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) { +; CHECK-NEXT: [[TMP2:%.*]] = call i8 @llvm.ucmp.i8.i32(i32 [[Y]], i32 [[X]]) +; CHECK-NEXT: ret i8 [[TMP2]] +; + %1 = call i8 @llvm.ucmp(i32 %x, i32 %y) + %2 = sub i8 0, %1 + ret i8 %2 +} + +; Negative test: do not fold if the original ucmp result is already used +define i8 @ucmp_negated_multiuse(i32 %x, i32 %y) { +; CHECK-LABEL: define i8 @ucmp_negated_multiuse( +; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) { +; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.ucmp.i8.i32(i32 [[X]], i32 [[Y]]) +; CHECK-NEXT: call void @use(i8 [[TMP1]]) +; CHECK-NEXT: [[TMP2:%.*]] = sub nsw i8 0, [[TMP1]] +; CHECK-NEXT: ret i8 [[TMP2]] +; + %1 = call i8 @llvm.ucmp(i32 %x, i32 %y) + call void @use(i8 %1) + %2 = sub i8 0, %1 + ret i8 %2 +} From c97a8e4bcf6f11d87c7137a4c31c468299687420 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Wed, 10 Jul 2024 12:53:23 -0700 Subject: [PATCH 03/10] [AMDGPU] Remove unneed static_cast from GCNSubtarget constructor. NFC RegBankInfo is a std::unique_ptr so we don't need the cast. --- llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp b/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp index b46adb9f1a0b3a..21fe1bc31a27e4 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp @@ -199,8 +199,7 @@ GCNSubtarget::GCNSubtarget(const Triple &TT, StringRef GPU, StringRef FS, InlineAsmLoweringInfo.reset(new InlineAsmLowering(getTargetLowering())); Legalizer.reset(new AMDGPULegalizerInfo(*this, TM)); RegBankInfo.reset(new AMDGPURegisterBankInfo(*this)); - InstSelector.reset(new AMDGPUInstructionSelector( - *this, *static_cast(RegBankInfo.get()), TM)); + InstSelector.reset(new AMDGPUInstructionSelector(*this, *RegBankInfo, TM)); } unsigned GCNSubtarget::getConstantBusLimit(unsigned Opcode) const { From ed17431bf7489c87ea81a6a67af5c7c206da0080 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Wed, 10 Jul 2024 12:58:42 -0700 Subject: [PATCH 04/10] [rtsan] Disable ${ARM32} Still fails after #98268 --- compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake index 7e99df0a3c7f54..48425882b7dff8 100644 --- a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake +++ b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake @@ -32,7 +32,7 @@ set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64} ${LOONGARCH64}) set(ALL_ASAN_ABI_SUPPORTED_ARCH ${X86_64} ${ARM64} ${ARM64_32}) set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${LOONGARCH64}) -set(ALL_RTSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}) +set(ALL_RTSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64}) if(ANDROID) set(OS_NAME "Android") From d18ca43edc6fed920db86a99ed9f7e3bcafc99d2 Mon Sep 17 00:00:00 2001 From: Poseydon42 Date: Wed, 10 Jul 2024 20:59:59 +0100 Subject: [PATCH 05/10] [ConstraintElimination] Add support for UCMP/SCMP intrinsics (#97974) This adds checks to fold calls to `ucmp`/`scmp` where a comparative relationship between the arguments can be established. --- .../Scalar/ConstraintElimination.cpp | 26 +++ .../Transforms/ConstraintElimination/uscmp.ll | 149 ++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 llvm/test/Transforms/ConstraintElimination/uscmp.ll diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp index 52d9969426105c..c31173879af1e6 100644 --- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp +++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp @@ -1087,6 +1087,8 @@ void State::addInfoFor(BasicBlock &BB) { } // Enqueue ssub_with_overflow for simplification. case Intrinsic::ssub_with_overflow: + case Intrinsic::ucmp: + case Intrinsic::scmp: WorkList.push_back( FactOrCheck::getCheck(DT.getNode(&BB), cast(&I))); break; @@ -1448,6 +1450,28 @@ static bool checkAndReplaceMinMax(MinMaxIntrinsic *MinMax, ConstraintInfo &Info, return false; } +static bool checkAndReplaceCmp(CmpIntrinsic *I, ConstraintInfo &Info, + SmallVectorImpl &ToRemove) { + Value *LHS = I->getOperand(0); + Value *RHS = I->getOperand(1); + if (checkCondition(I->getGTPredicate(), LHS, RHS, I, Info).value_or(false)) { + I->replaceAllUsesWith(ConstantInt::get(I->getType(), 1)); + ToRemove.push_back(I); + return true; + } + if (checkCondition(I->getLTPredicate(), LHS, RHS, I, Info).value_or(false)) { + I->replaceAllUsesWith(ConstantInt::getSigned(I->getType(), -1)); + ToRemove.push_back(I); + return true; + } + if (checkCondition(ICmpInst::ICMP_EQ, LHS, RHS, I, Info)) { + I->replaceAllUsesWith(ConstantInt::get(I->getType(), 0)); + ToRemove.push_back(I); + return true; + } + return false; +} + static void removeEntryFromStack(const StackEntry &E, ConstraintInfo &Info, Module *ReproducerModule, @@ -1750,6 +1774,8 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT, LoopInfo &LI, Changed |= Simplified; } else if (auto *MinMax = dyn_cast(Inst)) { Changed |= checkAndReplaceMinMax(MinMax, Info, ToRemove); + } else if (auto *CmpIntr = dyn_cast(Inst)) { + Changed |= checkAndReplaceCmp(CmpIntr, Info, ToRemove); } continue; } diff --git a/llvm/test/Transforms/ConstraintElimination/uscmp.ll b/llvm/test/Transforms/ConstraintElimination/uscmp.ll new file mode 100644 index 00000000000000..63ac050f2c3c5e --- /dev/null +++ b/llvm/test/Transforms/ConstraintElimination/uscmp.ll @@ -0,0 +1,149 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s + +define i8 @scmp_1(i32 %x, i32 %y) { +; CHECK-LABEL: @scmp_1( +; CHECK-NEXT: [[COND:%.*]] = icmp sgt i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: br i1 [[COND]], label [[TRUE:%.*]], label [[FALSE:%.*]] +; CHECK: true: +; CHECK-NEXT: ret i8 1 +; CHECK: false: +; CHECK-NEXT: ret i8 20 +; + %cond = icmp sgt i32 %x, %y + br i1 %cond, label %true, label %false +true: + %r = call i8 @llvm.scmp(i32 %x, i32 %y) + ret i8 %r +false: + ret i8 20 +} + +define i8 @ucmp_1(i32 %x, i32 %y) { +; CHECK-LABEL: @ucmp_1( +; CHECK-NEXT: [[COND:%.*]] = icmp ult i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: br i1 [[COND]], label [[TRUE:%.*]], label [[FALSE:%.*]] +; CHECK: true: +; CHECK-NEXT: ret i8 -1 +; CHECK: false: +; CHECK-NEXT: ret i8 20 +; + %cond = icmp ult i32 %x, %y + br i1 %cond, label %true, label %false +true: + %r = call i8 @llvm.ucmp(i32 %x, i32 %y) + ret i8 %r +false: + ret i8 20 +} + +define i8 @scmp_2(i32 %x, i32 %y) { +; CHECK-LABEL: @scmp_2( +; CHECK-NEXT: [[COND:%.*]] = icmp sge i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: br i1 [[COND]], label [[TRUE:%.*]], label [[FALSE:%.*]] +; CHECK: true: +; CHECK-NEXT: ret i8 20 +; CHECK: false: +; CHECK-NEXT: ret i8 -1 +; + %cond = icmp sge i32 %x, %y + br i1 %cond, label %true, label %false +true: + ret i8 20 +false: + %r = call i8 @llvm.scmp(i32 %x, i32 %y) + ret i8 %r +} + +define i8 @ucmp_2(i32 %x, i32 %y) { +; CHECK-LABEL: @ucmp_2( +; CHECK-NEXT: [[COND:%.*]] = icmp ule i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: br i1 [[COND]], label [[TRUE:%.*]], label [[FALSE:%.*]] +; CHECK: true: +; CHECK-NEXT: ret i8 20 +; CHECK: false: +; CHECK-NEXT: ret i8 1 +; + %cond = icmp ule i32 %x, %y + br i1 %cond, label %true, label %false +true: + ret i8 20 +false: + %r = call i8 @llvm.ucmp(i32 %x, i32 %y) + ret i8 %r +} + +define i8 @scmp_3(i32 %x, i32 %y) { +; CHECK-LABEL: @scmp_3( +; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: br i1 [[COND]], label [[TRUE:%.*]], label [[FALSE:%.*]] +; CHECK: true: +; CHECK-NEXT: ret i8 0 +; CHECK: false: +; CHECK-NEXT: ret i8 20 +; + %cond = icmp eq i32 %x, %y + br i1 %cond, label %true, label %false +true: + %r = call i8 @llvm.scmp(i32 %x, i32 %y) + ret i8 %r +false: + ret i8 20 +} + +define i8 @ucmp_3(i32 %x, i32 %y) { +; CHECK-LABEL: @ucmp_3( +; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: br i1 [[COND]], label [[TRUE:%.*]], label [[FALSE:%.*]] +; CHECK: true: +; CHECK-NEXT: ret i8 0 +; CHECK: false: +; CHECK-NEXT: ret i8 20 +; + %cond = icmp eq i32 %x, %y + br i1 %cond, label %true, label %false +true: + %r = call i8 @llvm.ucmp(i32 %x, i32 %y) + ret i8 %r +false: + ret i8 20 +} + +; Negative test: signedness mismatch +define i8 @scmp_4(i32 %x, i32 %y) { +; CHECK-LABEL: @scmp_4( +; CHECK-NEXT: [[COND:%.*]] = icmp ugt i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: br i1 [[COND]], label [[TRUE:%.*]], label [[FALSE:%.*]] +; CHECK: true: +; CHECK-NEXT: ret i8 20 +; CHECK: false: +; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.scmp.i8.i32(i32 [[X]], i32 [[Y]]) +; CHECK-NEXT: ret i8 [[R]] +; + %cond = icmp ugt i32 %x, %y + br i1 %cond, label %true, label %false +true: + ret i8 20 +false: + %r = call i8 @llvm.scmp(i32 %x, i32 %y) + ret i8 %r +} + +define i8 @ucmp_4(i32 %x, i32 %y) { +; CHECK-LABEL: @ucmp_4( +; CHECK-NEXT: [[COND:%.*]] = icmp slt i32 [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: br i1 [[COND]], label [[TRUE:%.*]], label [[FALSE:%.*]] +; CHECK: true: +; CHECK-NEXT: ret i8 20 +; CHECK: false: +; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.ucmp.i8.i32(i32 [[X]], i32 [[Y]]) +; CHECK-NEXT: ret i8 [[R]] +; + %cond = icmp slt i32 %x, %y + br i1 %cond, label %true, label %false +true: + ret i8 20 +false: + %r = call i8 @llvm.ucmp(i32 %x, i32 %y) + ret i8 %r +} From 34c544e1cc852d9a1039ff57773db0481c1a79e1 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Wed, 10 Jul 2024 22:00:54 +0200 Subject: [PATCH 06/10] [mlir][linalg] Remove unused #includes. NFC. --- mlir/lib/Dialect/Linalg/Transforms/WinogradConv2D.cpp | 2 -- utils/bazel/llvm-project-overlay/mlir/BUILD.bazel | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/mlir/lib/Dialect/Linalg/Transforms/WinogradConv2D.cpp b/mlir/lib/Dialect/Linalg/Transforms/WinogradConv2D.cpp index 351549bf2b4341..76742f2a824e71 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/WinogradConv2D.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/WinogradConv2D.cpp @@ -15,9 +15,7 @@ #include "mlir/Dialect/Linalg/IR/Linalg.h" #include "mlir/Dialect/Linalg/Utils/Utils.h" #include "mlir/Dialect/Tensor/IR/Tensor.h" -#include "mlir/Dialect/Tosa/Utils/ConversionUtils.h" #include "mlir/Dialect/Utils/StaticValueUtils.h" -#include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "llvm/Support/MathExtras.h" namespace mlir { diff --git a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel index 33166bc70af205..ab3757342c76f5 100644 --- a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel @@ -1032,9 +1032,9 @@ cc_library( ":CAPIAsyncHeaders", ":CAPIDebugHeaders", ":CAPIIRHeaders", - ":config", ":MLIRBindingsPythonHeaders", ":Support", + ":config", "//llvm:Support", "@local_config_python//:python_headers", "@pybind11", @@ -11350,7 +11350,6 @@ cc_library( ":TensorTransforms", ":TensorUtils", ":TilingInterface", - ":TosaDialect", ":TransformUtils", ":ValueBoundsOpInterface", ":VectorDialect", From ed8565cf0b64ea5e88cc94f321b1870bb105d09d Mon Sep 17 00:00:00 2001 From: Thurston Dang Date: Wed, 10 Jul 2024 13:02:41 -0700 Subject: [PATCH 07/10] [sanitizer_common] Block asynchronous signals only (#98200) This changes the behavior of `BlockSignals` and `ScopedBlockSignals` to block only asynchronous signals. This extension is intended to be used in a future fix for MSan (block async signals during `MsanThread::Destroy`). --- compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp index 12df3ef73da4bc..54f972c74794b2 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp @@ -155,6 +155,7 @@ void SetSigProcMask(__sanitizer_sigset_t *set, __sanitizer_sigset_t *oldset) { CHECK_EQ(0, internal_sigprocmask(SIG_SETMASK, set, oldset)); } +// Block asynchronous signals void BlockSignals(__sanitizer_sigset_t *oldset) { __sanitizer_sigset_t set; internal_sigfillset(&set); @@ -170,6 +171,16 @@ void BlockSignals(__sanitizer_sigset_t *oldset) { // hang. internal_sigdelset(&set, 31); # endif + + // Don't block synchronous signals + internal_sigdelset(&set, SIGSEGV); + internal_sigdelset(&set, SIGBUS); + internal_sigdelset(&set, SIGILL); + internal_sigdelset(&set, SIGTRAP); + internal_sigdelset(&set, SIGABRT); + internal_sigdelset(&set, SIGFPE); + internal_sigdelset(&set, SIGPIPE); + SetSigProcMask(&set, oldset); } From e4b1813bb85d2efe76c2d69781a8dab0698c823b Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Wed, 10 Jul 2024 13:03:22 -0700 Subject: [PATCH 08/10] Fix deps for clean "ninja check-compiler-rt" (#98266) Without the patch even FileCheck is missing. --- llvm/runtimes/CMakeLists.txt | 52 +++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt index 52e95193947426..f2c273b0b9050a 100644 --- a/llvm/runtimes/CMakeLists.txt +++ b/llvm/runtimes/CMakeLists.txt @@ -444,6 +444,35 @@ if(build_runtimes) set(extra_deps "") set(extra_cmake_args "") + if(LLVM_INCLUDE_TESTS) + foreach(dep FileCheck + clang + count + lld + lli + llvm-cov + llvm-lto + llvm-jitlink + llvm-nm + llvm-objdump + llvm-profdata + llvm-size + llvm-symbolizer + llvm-xray + not + obj2yaml + opt + sancov + sanstats + llvm_gtest_main + llvm_gtest + split-file) + if(TARGET ${dep}) + list(APPEND extra_deps ${dep}) + endif() + endforeach() + endif() + # Forward user-provived system configuration to runtimes for requirement introspection. # CMAKE_PREFIX_PATH is the search path for CMake packages. if(CMAKE_PREFIX_PATH) @@ -612,29 +641,10 @@ if(build_runtimes) if(LLVM_INCLUDE_TESTS) set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_DEPENDS runtimes-test-depends) - set(RUNTIMES_TEST_DEPENDS - FileCheck - count - llvm-cov - llvm-lto - llvm-nm - llvm-objdump - llvm-profdata - llvm-size - llvm-xray - not - obj2yaml - opt - sancov - sanstats - llvm_gtest_main - llvm_gtest - split-file - ) foreach(target ${test_targets} ${SUB_CHECK_TARGETS}) - add_dependencies(${target} ${RUNTIMES_TEST_DEPENDS}) + add_dependencies(${target} ${extra_deps}) endforeach() - set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_TARGETS runtimes ${RUNTIMES_TEST_DEPENDS}) + set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_TARGETS runtimes ${extra_deps}) endif() endif() From e6352604cda75270b24f55c02eddbd4bc648d537 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Wed, 10 Jul 2024 13:03:48 -0700 Subject: [PATCH 09/10] [compiler-rt] Remove redundant COMPILER_RT_HAS_*SAN checks (#98240) They are checked in the parent CMakeLists in `compiler_rt_build_runtime` and `compiler_rt_test_runtime`. There are non-redundant checks when a sanitizer checks for the presense of another one. They should not be removed. --- compiler-rt/lib/CMakeLists.txt | 4 +- compiler-rt/lib/gwp_asan/CMakeLists.txt | 76 +++---- compiler-rt/lib/lsan/CMakeLists.txt | 68 +++--- compiler-rt/lib/nsan/CMakeLists.txt | 48 ++-- .../lib/scudo/standalone/CMakeLists.txt | 94 ++++---- .../lib/scudo/standalone/tests/CMakeLists.txt | 38 ++-- compiler-rt/lib/ubsan/CMakeLists.txt | 212 +++++++++--------- compiler-rt/lib/ubsan_minimal/CMakeLists.txt | 54 +++-- compiler-rt/test/cfi/CMakeLists.txt | 4 +- compiler-rt/test/gwp_asan/CMakeLists.txt | 4 +- compiler-rt/test/orc/CMakeLists.txt | 2 +- compiler-rt/test/rtsan/CMakeLists.txt | 24 +- .../test/scudo/standalone/CMakeLists.txt | 2 +- compiler-rt/test/xray/CMakeLists.txt | 5 +- 14 files changed, 307 insertions(+), 328 deletions(-) diff --git a/compiler-rt/lib/CMakeLists.txt b/compiler-rt/lib/CMakeLists.txt index f9e96563b88090..73a2ee46291ee5 100644 --- a/compiler-rt/lib/CMakeLists.txt +++ b/compiler-rt/lib/CMakeLists.txt @@ -47,11 +47,11 @@ if(COMPILER_RT_BUILD_SANITIZERS) endforeach() endif() -if(COMPILER_RT_BUILD_PROFILE AND COMPILER_RT_HAS_PROFILE) +if(COMPILER_RT_BUILD_PROFILE) compiler_rt_build_runtime(profile) endif() -if(COMPILER_RT_BUILD_CTX_PROFILE AND COMPILER_RT_HAS_CTX_PROFILE) +if(COMPILER_RT_BUILD_CTX_PROFILE) compiler_rt_build_runtime(ctx_profile) endif() diff --git a/compiler-rt/lib/gwp_asan/CMakeLists.txt b/compiler-rt/lib/gwp_asan/CMakeLists.txt index bb5b2902f99dbf..fdb6a95fe14043 100644 --- a/compiler-rt/lib/gwp_asan/CMakeLists.txt +++ b/compiler-rt/lib/gwp_asan/CMakeLists.txt @@ -65,48 +65,46 @@ set(GWP_ASAN_SEGV_HANDLER_HEADERS set(GWP_ASAN_OPTIONS_PARSER_CFLAGS ${GWP_ASAN_CFLAGS}) -if (COMPILER_RT_HAS_GWP_ASAN) - foreach(arch ${GWP_ASAN_SUPPORTED_ARCH}) - add_compiler_rt_runtime( - clang_rt.gwp_asan - STATIC - ARCHS ${arch} - SOURCES ${GWP_ASAN_SOURCES} - ADDITIONAL_HEADERS ${GWP_ASAN_HEADERS} - CFLAGS ${GWP_ASAN_CFLAGS} - PARENT_TARGET gwp_asan - ) - endforeach() +foreach(arch ${GWP_ASAN_SUPPORTED_ARCH}) + add_compiler_rt_runtime( + clang_rt.gwp_asan + STATIC + ARCHS ${arch} + SOURCES ${GWP_ASAN_SOURCES} + ADDITIONAL_HEADERS ${GWP_ASAN_HEADERS} + CFLAGS ${GWP_ASAN_CFLAGS} + PARENT_TARGET gwp_asan + ) +endforeach() - add_compiler_rt_object_libraries(RTGwpAsan - ARCHS ${GWP_ASAN_SUPPORTED_ARCH} - SOURCES ${GWP_ASAN_SOURCES} - ADDITIONAL_HEADERS ${GWP_ASAN_HEADERS} - CFLAGS ${GWP_ASAN_CFLAGS}) +add_compiler_rt_object_libraries(RTGwpAsan + ARCHS ${GWP_ASAN_SUPPORTED_ARCH} + SOURCES ${GWP_ASAN_SOURCES} + ADDITIONAL_HEADERS ${GWP_ASAN_HEADERS} + CFLAGS ${GWP_ASAN_CFLAGS}) - add_compiler_rt_object_libraries(RTGwpAsanOptionsParser - ARCHS ${GWP_ASAN_SUPPORTED_ARCH} - SOURCES ${GWP_ASAN_OPTIONS_PARSER_SOURCES} - ADDITIONAL_HEADERS ${GWP_ASAN_OPTIONS_PARSER_HEADERS} - CFLAGS ${GWP_ASAN_OPTIONS_PARSER_CFLAGS}) +add_compiler_rt_object_libraries(RTGwpAsanOptionsParser + ARCHS ${GWP_ASAN_SUPPORTED_ARCH} + SOURCES ${GWP_ASAN_OPTIONS_PARSER_SOURCES} + ADDITIONAL_HEADERS ${GWP_ASAN_OPTIONS_PARSER_HEADERS} + CFLAGS ${GWP_ASAN_OPTIONS_PARSER_CFLAGS}) - # As above, build the pre-implemented optional backtrace support libraries. - add_compiler_rt_object_libraries(RTGwpAsanBacktraceLibc - ARCHS ${GWP_ASAN_SUPPORTED_ARCH} - SOURCES optional/backtrace_linux_libc.cpp - ADDITIONAL_HEADERS ${GWP_ASAN_BACKTRACE_HEADERS} - CFLAGS ${GWP_ASAN_CFLAGS}) - add_compiler_rt_object_libraries(RTGwpAsanSegvHandler - ARCHS ${GWP_ASAN_SUPPORTED_ARCH} - SOURCES optional/segv_handler_posix.cpp - ADDITIONAL_HEADERS ${GWP_ASAN_SEGV_HANDLER_HEADERS} - CFLAGS ${GWP_ASAN_CFLAGS}) - add_compiler_rt_object_libraries(RTGwpAsanBacktraceSanitizerCommon - ARCHS ${GWP_ASAN_SUPPORTED_ARCH} - SOURCES optional/backtrace_sanitizer_common.cpp - ADDITIONAL_HEADERS ${GWP_ASAN_BACKTRACE_HEADERS} - CFLAGS ${GWP_ASAN_CFLAGS} ${SANITIZER_COMMON_CFLAGS}) -endif() +# As above, build the pre-implemented optional backtrace support libraries. +add_compiler_rt_object_libraries(RTGwpAsanBacktraceLibc + ARCHS ${GWP_ASAN_SUPPORTED_ARCH} + SOURCES optional/backtrace_linux_libc.cpp + ADDITIONAL_HEADERS ${GWP_ASAN_BACKTRACE_HEADERS} + CFLAGS ${GWP_ASAN_CFLAGS}) +add_compiler_rt_object_libraries(RTGwpAsanSegvHandler + ARCHS ${GWP_ASAN_SUPPORTED_ARCH} + SOURCES optional/segv_handler_posix.cpp + ADDITIONAL_HEADERS ${GWP_ASAN_SEGV_HANDLER_HEADERS} + CFLAGS ${GWP_ASAN_CFLAGS}) +add_compiler_rt_object_libraries(RTGwpAsanBacktraceSanitizerCommon + ARCHS ${GWP_ASAN_SUPPORTED_ARCH} + SOURCES optional/backtrace_sanitizer_common.cpp + ADDITIONAL_HEADERS ${GWP_ASAN_BACKTRACE_HEADERS} + CFLAGS ${GWP_ASAN_CFLAGS} ${SANITIZER_COMMON_CFLAGS}) if(COMPILER_RT_INCLUDE_TESTS) add_subdirectory(tests) diff --git a/compiler-rt/lib/lsan/CMakeLists.txt b/compiler-rt/lib/lsan/CMakeLists.txt index 8e9861cd6b7c09..c7bb6449982c20 100644 --- a/compiler-rt/lib/lsan/CMakeLists.txt +++ b/compiler-rt/lib/lsan/CMakeLists.txt @@ -43,46 +43,44 @@ add_compiler_rt_object_libraries(RTLSanCommon ADDITIONAL_HEADERS ${LSAN_HEADERS} CFLAGS ${LSAN_CFLAGS}) -if(COMPILER_RT_HAS_LSAN) - add_compiler_rt_component(lsan) - if(APPLE) - set(LSAN_LINK_LIBS ${SANITIZER_COMMON_LINK_LIBS}) +add_compiler_rt_component(lsan) +if(APPLE) + set(LSAN_LINK_LIBS ${SANITIZER_COMMON_LINK_LIBS}) - add_weak_symbols("lsan" WEAK_SYMBOL_LINK_FLAGS) - add_weak_symbols("sanitizer_common" WEAK_SYMBOL_LINK_FLAGS) + add_weak_symbols("lsan" WEAK_SYMBOL_LINK_FLAGS) + add_weak_symbols("sanitizer_common" WEAK_SYMBOL_LINK_FLAGS) + add_compiler_rt_runtime(clang_rt.lsan + SHARED + OS ${LSAN_SUPPORTED_OS} + ARCHS ${LSAN_SUPPORTED_ARCH} + SOURCES ${LSAN_SOURCES} + ADDITIONAL_HEADERS ${LSAN_HEADERS} + OBJECT_LIBS RTLSanCommon + RTInterception + RTSanitizerCommon + RTSanitizerCommonLibc + RTSanitizerCommonCoverage + RTSanitizerCommonSymbolizer + CFLAGS ${LSAN_CFLAGS} + LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS} + LINK_LIBS ${LSAN_LINK_LIBS} + PARENT_TARGET lsan) +else() + foreach(arch ${LSAN_SUPPORTED_ARCH}) add_compiler_rt_runtime(clang_rt.lsan - SHARED - OS ${LSAN_SUPPORTED_OS} - ARCHS ${LSAN_SUPPORTED_ARCH} + STATIC + ARCHS ${arch} SOURCES ${LSAN_SOURCES} + $ + $ + $ + $ + $ + $ + $ ADDITIONAL_HEADERS ${LSAN_HEADERS} - OBJECT_LIBS RTLSanCommon - RTInterception - RTSanitizerCommon - RTSanitizerCommonLibc - RTSanitizerCommonCoverage - RTSanitizerCommonSymbolizer CFLAGS ${LSAN_CFLAGS} - LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS} - LINK_LIBS ${LSAN_LINK_LIBS} PARENT_TARGET lsan) - else() - foreach(arch ${LSAN_SUPPORTED_ARCH}) - add_compiler_rt_runtime(clang_rt.lsan - STATIC - ARCHS ${arch} - SOURCES ${LSAN_SOURCES} - $ - $ - $ - $ - $ - $ - $ - ADDITIONAL_HEADERS ${LSAN_HEADERS} - CFLAGS ${LSAN_CFLAGS} - PARENT_TARGET lsan) - endforeach() - endif() + endforeach() endif() diff --git a/compiler-rt/lib/nsan/CMakeLists.txt b/compiler-rt/lib/nsan/CMakeLists.txt index 36c7b2b9dfada4..aef9b651ab2ec8 100644 --- a/compiler-rt/lib/nsan/CMakeLists.txt +++ b/compiler-rt/lib/nsan/CMakeLists.txt @@ -25,31 +25,29 @@ set(NSAN_DYNAMIC_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS}) set(NSAN_CFLAGS ${SANITIZER_COMMON_CFLAGS}) -if (COMPILER_RT_HAS_NSAN) - foreach(arch ${NSAN_SUPPORTED_ARCH}) - add_compiler_rt_runtime( - clang_rt.nsan - STATIC - ARCHS ${arch} - SOURCES ${NSAN_SOURCES} - $ - $ - $ - $ - $ - $ - ADDITIONAL_HEADERS ${NSAN_HEADERS} - CFLAGS ${NSAN_CFLAGS} - PARENT_TARGET nsan - ) - endforeach() - - add_compiler_rt_object_libraries(RTNsan - ARCHS ${NSAN_SUPPORTED_ARCH} - SOURCES ${NSAN_SOURCES} - ADDITIONAL_HEADERS ${NSAN_HEADERS} - CFLAGS ${NSAN_CFLAGS}) -endif() +foreach(arch ${NSAN_SUPPORTED_ARCH}) + add_compiler_rt_runtime( + clang_rt.nsan + STATIC + ARCHS ${arch} + SOURCES ${NSAN_SOURCES} + $ + $ + $ + $ + $ + $ + ADDITIONAL_HEADERS ${NSAN_HEADERS} + CFLAGS ${NSAN_CFLAGS} + PARENT_TARGET nsan + ) +endforeach() + +add_compiler_rt_object_libraries(RTNsan + ARCHS ${NSAN_SUPPORTED_ARCH} + SOURCES ${NSAN_SOURCES} + ADDITIONAL_HEADERS ${NSAN_HEADERS} + CFLAGS ${NSAN_CFLAGS}) if(COMPILER_RT_INCLUDE_TESTS) add_subdirectory(tests) diff --git a/compiler-rt/lib/scudo/standalone/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/CMakeLists.txt index 6fb4e88de3155f..8fc245eb2cf389 100644 --- a/compiler-rt/lib/scudo/standalone/CMakeLists.txt +++ b/compiler-rt/lib/scudo/standalone/CMakeLists.txt @@ -195,60 +195,58 @@ if(COMPILER_RT_DEFAULT_TARGET_ARCH MATCHES "mips|mips64|mipsel|mips64el") list(APPEND SCUDO_LINK_LIBS atomic) endif() -if(COMPILER_RT_HAS_SCUDO_STANDALONE) - add_compiler_rt_object_libraries(RTScudoStandalone - ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH} - SOURCES ${SCUDO_SOURCES} - ADDITIONAL_HEADERS ${SCUDO_HEADERS} - CFLAGS ${SCUDO_CFLAGS} - DEPS ${SCUDO_DEPS}) - add_compiler_rt_object_libraries(RTScudoStandaloneCWrappers - ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH} - SOURCES ${SCUDO_SOURCES_C_WRAPPERS} - ADDITIONAL_HEADERS ${SCUDO_HEADERS} - CFLAGS ${SCUDO_CFLAGS} - DEPS ${SCUDO_DEPS}) - add_compiler_rt_object_libraries(RTScudoStandaloneCxxWrappers - ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH} - SOURCES ${SCUDO_SOURCES_CXX_WRAPPERS} - ADDITIONAL_HEADERS ${SCUDO_HEADERS} - CFLAGS ${SCUDO_CFLAGS} - DEPS ${SCUDO_DEPS}) - +add_compiler_rt_object_libraries(RTScudoStandalone + ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH} + SOURCES ${SCUDO_SOURCES} + ADDITIONAL_HEADERS ${SCUDO_HEADERS} + CFLAGS ${SCUDO_CFLAGS} + DEPS ${SCUDO_DEPS}) +add_compiler_rt_object_libraries(RTScudoStandaloneCWrappers + ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH} + SOURCES ${SCUDO_SOURCES_C_WRAPPERS} + ADDITIONAL_HEADERS ${SCUDO_HEADERS} + CFLAGS ${SCUDO_CFLAGS} + DEPS ${SCUDO_DEPS}) +add_compiler_rt_object_libraries(RTScudoStandaloneCxxWrappers + ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH} + SOURCES ${SCUDO_SOURCES_CXX_WRAPPERS} + ADDITIONAL_HEADERS ${SCUDO_HEADERS} + CFLAGS ${SCUDO_CFLAGS} + DEPS ${SCUDO_DEPS}) + +add_compiler_rt_runtime(clang_rt.scudo_standalone + STATIC + ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH} + SOURCES ${SCUDO_SOURCES} ${SCUDO_SOURCES_C_WRAPPERS} + ADDITIONAL_HEADERS ${SCUDO_HEADERS} + CFLAGS ${SCUDO_CFLAGS} + DEPS ${SCUDO_DEPS} + OBJECT_LIBS ${SCUDO_OBJECT_LIBS} + PARENT_TARGET scudo_standalone) +add_compiler_rt_runtime(clang_rt.scudo_standalone_cxx + STATIC + ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH} + SOURCES ${SCUDO_SOURCES_CXX_WRAPPERS} + ADDITIONAL_HEADERS ${SCUDO_HEADERS} + CFLAGS ${SCUDO_CFLAGS} + DEPS ${SCUDO_DEPS} + PARENT_TARGET scudo_standalone) + +if(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED) add_compiler_rt_runtime(clang_rt.scudo_standalone - STATIC + SHARED ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH} - SOURCES ${SCUDO_SOURCES} ${SCUDO_SOURCES_C_WRAPPERS} + SOURCES ${SCUDO_SOURCES} ${SCUDO_SOURCES_C_WRAPPERS} ${SCUDO_SOURCES_CXX_WRAPPERS} ADDITIONAL_HEADERS ${SCUDO_HEADERS} CFLAGS ${SCUDO_CFLAGS} DEPS ${SCUDO_DEPS} OBJECT_LIBS ${SCUDO_OBJECT_LIBS} + LINK_FLAGS ${SCUDO_LINK_FLAGS} + LINK_LIBS ${SCUDO_LINK_LIBS} PARENT_TARGET scudo_standalone) - add_compiler_rt_runtime(clang_rt.scudo_standalone_cxx - STATIC - ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH} - SOURCES ${SCUDO_SOURCES_CXX_WRAPPERS} - ADDITIONAL_HEADERS ${SCUDO_HEADERS} - CFLAGS ${SCUDO_CFLAGS} - DEPS ${SCUDO_DEPS} - PARENT_TARGET scudo_standalone) - - if(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED) - add_compiler_rt_runtime(clang_rt.scudo_standalone - SHARED - ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH} - SOURCES ${SCUDO_SOURCES} ${SCUDO_SOURCES_C_WRAPPERS} ${SCUDO_SOURCES_CXX_WRAPPERS} - ADDITIONAL_HEADERS ${SCUDO_HEADERS} - CFLAGS ${SCUDO_CFLAGS} - DEPS ${SCUDO_DEPS} - OBJECT_LIBS ${SCUDO_OBJECT_LIBS} - LINK_FLAGS ${SCUDO_LINK_FLAGS} - LINK_LIBS ${SCUDO_LINK_LIBS} - PARENT_TARGET scudo_standalone) - endif() +endif() - add_subdirectory(benchmarks) - if(COMPILER_RT_INCLUDE_TESTS) - add_subdirectory(tests) - endif() +add_subdirectory(benchmarks) +if(COMPILER_RT_INCLUDE_TESTS) + add_subdirectory(tests) endif() diff --git a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt index 1786756fa5ea68..672cdc0ba655ea 100644 --- a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt +++ b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt @@ -66,27 +66,25 @@ macro(add_scudo_unittest testname) RTGwpAsan RTGwpAsanBacktraceLibc RTGwpAsanSegvHandler) endif() - if(COMPILER_RT_HAS_SCUDO_STANDALONE) - foreach(arch ${SCUDO_TEST_ARCH}) - # Additional runtime objects get added along RTScudoStandalone - set(SCUDO_TEST_RTOBJECTS $) - foreach(rtobject ${TEST_ADDITIONAL_RTOBJECTS}) - list(APPEND SCUDO_TEST_RTOBJECTS $) - endforeach() - # Add the static runtime library made of all the runtime objects - set(RUNTIME RT${testname}.${arch}) - add_library(${RUNTIME} STATIC ${SCUDO_TEST_RTOBJECTS}) - set(ScudoUnitTestsObjects) - generate_compiler_rt_tests(ScudoUnitTestsObjects ScudoUnitTests - "${testname}-${arch}-Test" ${arch} - SOURCES ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE} - COMPILE_DEPS ${SCUDO_TEST_HEADERS} - DEPS scudo_standalone - RUNTIME ${RUNTIME} - CFLAGS ${SCUDO_UNITTEST_CFLAGS} - LINK_FLAGS ${SCUDO_UNITTEST_LINK_FLAGS}) + foreach(arch ${SCUDO_TEST_ARCH}) + # Additional runtime objects get added along RTScudoStandalone + set(SCUDO_TEST_RTOBJECTS $) + foreach(rtobject ${TEST_ADDITIONAL_RTOBJECTS}) + list(APPEND SCUDO_TEST_RTOBJECTS $) endforeach() - endif() + # Add the static runtime library made of all the runtime objects + set(RUNTIME RT${testname}.${arch}) + add_library(${RUNTIME} STATIC ${SCUDO_TEST_RTOBJECTS}) + set(ScudoUnitTestsObjects) + generate_compiler_rt_tests(ScudoUnitTestsObjects ScudoUnitTests + "${testname}-${arch}-Test" ${arch} + SOURCES ${TEST_SOURCES} ${COMPILER_RT_GTEST_SOURCE} + COMPILE_DEPS ${SCUDO_TEST_HEADERS} + DEPS scudo_standalone + RUNTIME ${RUNTIME} + CFLAGS ${SCUDO_UNITTEST_CFLAGS} + LINK_FLAGS ${SCUDO_UNITTEST_LINK_FLAGS}) + endforeach() endmacro() set(SCUDO_UNIT_TEST_SOURCES diff --git a/compiler-rt/lib/ubsan/CMakeLists.txt b/compiler-rt/lib/ubsan/CMakeLists.txt index db0b33f1276ef2..a1cfbe93b068d0 100644 --- a/compiler-rt/lib/ubsan/CMakeLists.txt +++ b/compiler-rt/lib/ubsan/CMakeLists.txt @@ -92,47 +92,45 @@ if(APPLE) ADDITIONAL_HEADERS ${UBSAN_HEADERS} CFLAGS ${UBSAN_CXXFLAGS}) - if(COMPILER_RT_HAS_UBSAN) - # Initializer of standalone UBSan runtime. - add_compiler_rt_object_libraries(RTUbsan_standalone - OS ${UBSAN_SUPPORTED_OS} - ARCHS ${UBSAN_SUPPORTED_ARCH} - SOURCES ${UBSAN_STANDALONE_SOURCES} - ADDITIONAL_HEADERS ${UBSAN_HEADERS} - CFLAGS ${UBSAN_STANDALONE_CFLAGS}) + # Initializer of standalone UBSan runtime. + add_compiler_rt_object_libraries(RTUbsan_standalone + OS ${UBSAN_SUPPORTED_OS} + ARCHS ${UBSAN_SUPPORTED_ARCH} + SOURCES ${UBSAN_STANDALONE_SOURCES} + ADDITIONAL_HEADERS ${UBSAN_HEADERS} + CFLAGS ${UBSAN_STANDALONE_CFLAGS}) + + add_weak_symbols("ubsan" WEAK_SYMBOL_LINK_FLAGS) + add_weak_symbols("sanitizer_common" WEAK_SYMBOL_LINK_FLAGS) - add_weak_symbols("ubsan" WEAK_SYMBOL_LINK_FLAGS) - add_weak_symbols("sanitizer_common" WEAK_SYMBOL_LINK_FLAGS) + add_compiler_rt_runtime(clang_rt.ubsan + SHARED + OS ${UBSAN_SUPPORTED_OS} + ARCHS ${UBSAN_SUPPORTED_ARCH} + OBJECT_LIBS RTUbsan + RTUbsan_standalone + RTSanitizerCommon + RTSanitizerCommonLibc + RTSanitizerCommonCoverage + RTSanitizerCommonSymbolizer + RTInterception + LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS} + PARENT_TARGET ubsan) + if (NOT APPLE) add_compiler_rt_runtime(clang_rt.ubsan - SHARED + STATIC OS ${UBSAN_SUPPORTED_OS} ARCHS ${UBSAN_SUPPORTED_ARCH} OBJECT_LIBS RTUbsan RTUbsan_standalone - RTSanitizerCommon - RTSanitizerCommonLibc + RTSanitizerCommonNoHooks + RTSanitizerCommonLibcNoHooks RTSanitizerCommonCoverage - RTSanitizerCommonSymbolizer + RTSanitizerCommonSymbolizerNoHooks RTInterception LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS} PARENT_TARGET ubsan) - - if (NOT APPLE) - add_compiler_rt_runtime(clang_rt.ubsan - STATIC - OS ${UBSAN_SUPPORTED_OS} - ARCHS ${UBSAN_SUPPORTED_ARCH} - OBJECT_LIBS RTUbsan - RTUbsan_standalone - RTSanitizerCommonNoHooks - RTSanitizerCommonLibcNoHooks - RTSanitizerCommonCoverage - RTSanitizerCommonSymbolizerNoHooks - RTInterception - LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS} - PARENT_TARGET ubsan) - endif() endif() else() @@ -190,91 +188,89 @@ else() DEFS ${UBSAN_COMMON_DEFINITIONS}) endif() - if(COMPILER_RT_HAS_UBSAN) - add_compiler_rt_object_libraries(RTUbsan_standalone - ARCHS ${UBSAN_SUPPORTED_ARCH} - SOURCES ${UBSAN_STANDALONE_SOURCES} - ADDITIONAL_HEADERS ${UBSAN_HEADERS} - CFLAGS ${UBSAN_STANDALONE_CFLAGS}) - - # Standalone UBSan runtimes. - add_compiler_rt_runtime(clang_rt.ubsan_standalone - STATIC + add_compiler_rt_object_libraries(RTUbsan_standalone + ARCHS ${UBSAN_SUPPORTED_ARCH} + SOURCES ${UBSAN_STANDALONE_SOURCES} + ADDITIONAL_HEADERS ${UBSAN_HEADERS} + CFLAGS ${UBSAN_STANDALONE_CFLAGS}) + + # Standalone UBSan runtimes. + add_compiler_rt_runtime(clang_rt.ubsan_standalone + STATIC + ARCHS ${UBSAN_SUPPORTED_ARCH} + SOURCES + ubsan_init_standalone_preinit.cpp + ADDITIONAL_HEADERS ${UBSAN_HEADERS} + OBJECT_LIBS RTSanitizerCommon + RTSanitizerCommonLibc + RTSanitizerCommonCoverage + RTSanitizerCommonSymbolizer + RTSanitizerCommonSymbolizerInternal + RTUbsan + RTUbsan_standalone + RTInterception + CFLAGS ${UBSAN_CFLAGS} + PARENT_TARGET ubsan) + + add_compiler_rt_runtime(clang_rt.ubsan_standalone_cxx + STATIC + ARCHS ${UBSAN_SUPPORTED_ARCH} + OBJECT_LIBS RTUbsan_cxx + CFLAGS ${UBSAN_CXXFLAGS} + PARENT_TARGET ubsan) + + if (COMPILER_RT_HAS_VERSION_SCRIPT) + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "") + add_compiler_rt_object_libraries(RTUbsan_dynamic_version_script_dummy ARCHS ${UBSAN_SUPPORTED_ARCH} - SOURCES - ubsan_init_standalone_preinit.cpp - ADDITIONAL_HEADERS ${UBSAN_HEADERS} - OBJECT_LIBS RTSanitizerCommon + SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp + CFLAGS ${UBSAN_CFLAGS}) + + foreach(arch ${UBSAN_SUPPORTED_ARCH}) + add_sanitizer_rt_version_list(clang_rt.ubsan_standalone-dynamic-${arch} + LIBS clang_rt.ubsan_standalone-${arch} + clang_rt.ubsan_standalone_cxx-${arch} + EXTRA ubsan.syms.extra) + set(VERSION_SCRIPT_FLAG + -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/clang_rt.ubsan_standalone-dynamic-${arch}.vers) + # The Solaris 11.4 linker supports a subset of GNU ld version scripts, + # but requires a special option to enable it. + if (COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT) + list(APPEND VERSION_SCRIPT_FLAG -Wl,-z,gnu-version-script-compat) + endif() + set_property(SOURCE + ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp + APPEND PROPERTY + OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clang_rt.ubsan_standalone-dynamic-${arch}.vers) + + add_compiler_rt_runtime(clang_rt.ubsan_standalone + SHARED + ARCHS ${arch} + OBJECT_LIBS RTSanitizerCommon RTSanitizerCommonLibc RTSanitizerCommonCoverage RTSanitizerCommonSymbolizer RTSanitizerCommonSymbolizerInternal RTUbsan + RTUbsan_cxx RTUbsan_standalone RTInterception - CFLAGS ${UBSAN_CFLAGS} - PARENT_TARGET ubsan) - - add_compiler_rt_runtime(clang_rt.ubsan_standalone_cxx - STATIC - ARCHS ${UBSAN_SUPPORTED_ARCH} - OBJECT_LIBS RTUbsan_cxx - CFLAGS ${UBSAN_CXXFLAGS} - PARENT_TARGET ubsan) - - if (COMPILER_RT_HAS_VERSION_SCRIPT) - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "") - add_compiler_rt_object_libraries(RTUbsan_dynamic_version_script_dummy - ARCHS ${UBSAN_SUPPORTED_ARCH} - SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp - CFLAGS ${UBSAN_CFLAGS}) - - foreach(arch ${UBSAN_SUPPORTED_ARCH}) - add_sanitizer_rt_version_list(clang_rt.ubsan_standalone-dynamic-${arch} - LIBS clang_rt.ubsan_standalone-${arch} - clang_rt.ubsan_standalone_cxx-${arch} - EXTRA ubsan.syms.extra) - set(VERSION_SCRIPT_FLAG - -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/clang_rt.ubsan_standalone-dynamic-${arch}.vers) - # The Solaris 11.4 linker supports a subset of GNU ld version scripts, - # but requires a special option to enable it. - if (COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT) - list(APPEND VERSION_SCRIPT_FLAG -Wl,-z,gnu-version-script-compat) - endif() - set_property(SOURCE - ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp - APPEND PROPERTY - OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clang_rt.ubsan_standalone-dynamic-${arch}.vers) - - add_compiler_rt_runtime(clang_rt.ubsan_standalone - SHARED - ARCHS ${arch} - OBJECT_LIBS RTSanitizerCommon - RTSanitizerCommonLibc - RTSanitizerCommonCoverage - RTSanitizerCommonSymbolizer - RTSanitizerCommonSymbolizerInternal - RTUbsan - RTUbsan_cxx - RTUbsan_standalone - RTInterception - RTUbsan_dynamic_version_script_dummy - CFLAGS ${UBSAN_CFLAGS} - LINK_FLAGS ${UBSAN_LINK_FLAGS} ${VERSION_SCRIPT_FLAG} - LINK_LIBS ${UBSAN_DYNAMIC_LIBS} - PARENT_TARGET ubsan) - endforeach() - - set(ARCHS_FOR_SYMBOLS ${UBSAN_SUPPORTED_ARCH}) - list(REMOVE_ITEM ARCHS_FOR_SYMBOLS i386) - add_sanitizer_rt_symbols(clang_rt.ubsan_standalone - ARCHS ${ARCHS_FOR_SYMBOLS} - PARENT_TARGET ubsan - EXTRA ubsan.syms.extra) - add_sanitizer_rt_symbols(clang_rt.ubsan_standalone_cxx - ARCHS ${ARCHS_FOR_SYMBOLS} - PARENT_TARGET ubsan - EXTRA ubsan.syms.extra) - endif() + RTUbsan_dynamic_version_script_dummy + CFLAGS ${UBSAN_CFLAGS} + LINK_FLAGS ${UBSAN_LINK_FLAGS} ${VERSION_SCRIPT_FLAG} + LINK_LIBS ${UBSAN_DYNAMIC_LIBS} + PARENT_TARGET ubsan) + endforeach() + + set(ARCHS_FOR_SYMBOLS ${UBSAN_SUPPORTED_ARCH}) + list(REMOVE_ITEM ARCHS_FOR_SYMBOLS i386) + add_sanitizer_rt_symbols(clang_rt.ubsan_standalone + ARCHS ${ARCHS_FOR_SYMBOLS} + PARENT_TARGET ubsan + EXTRA ubsan.syms.extra) + add_sanitizer_rt_symbols(clang_rt.ubsan_standalone_cxx + ARCHS ${ARCHS_FOR_SYMBOLS} + PARENT_TARGET ubsan + EXTRA ubsan.syms.extra) endif() endif() diff --git a/compiler-rt/lib/ubsan_minimal/CMakeLists.txt b/compiler-rt/lib/ubsan_minimal/CMakeLists.txt index 07e96a70a49dce..1f6e50857e9dd6 100644 --- a/compiler-rt/lib/ubsan_minimal/CMakeLists.txt +++ b/compiler-rt/lib/ubsan_minimal/CMakeLists.txt @@ -24,32 +24,30 @@ add_compiler_rt_object_libraries(RTUbsan_minimal SOURCES ${UBSAN_MINIMAL_SOURCES} CFLAGS ${UBSAN_CFLAGS}) -if(COMPILER_RT_HAS_UBSAN_MINIMAL) - # Standalone minimal UBSan runtimes. - add_compiler_rt_runtime(clang_rt.ubsan_minimal - STATIC - OS ${UBSAN_SUPPORTED_OS} - ARCHS ${UBSAN_SUPPORTED_ARCH} - OBJECT_LIBS RTUbsan_minimal - CFLAGS ${UBSAN_CFLAGS} - PARENT_TARGET ubsan-minimal) - - add_compiler_rt_runtime(clang_rt.ubsan_minimal - SHARED - OS ${UBSAN_SUPPORTED_OS} - ARCHS ${UBSAN_SUPPORTED_ARCH} - OBJECT_LIBS RTUbsan_minimal - CFLAGS ${UBSAN_CFLAGS} - LINK_FLAGS ${UBSAN_LINK_FLAGS} - LINK_LIBS ${UBSAN_DYNAMIC_LIBS} - PARENT_TARGET ubsan-minimal) - - if (SANITIZER_USE_SYMBOLS AND NOT APPLE) - set(ARCHS_FOR_SYMBOLS ${UBSAN_SUPPORTED_ARCH}) - list(REMOVE_ITEM ARCHS_FOR_SYMBOLS i386 i686) - add_sanitizer_rt_symbols(clang_rt.ubsan_minimal - ARCHS ${ARCHS_FOR_SYMBOLS} - PARENT_TARGET ubsan-minimal - EXTRA ubsan.syms.extra) - endif() +# Standalone minimal UBSan runtimes. +add_compiler_rt_runtime(clang_rt.ubsan_minimal + STATIC + OS ${UBSAN_SUPPORTED_OS} + ARCHS ${UBSAN_SUPPORTED_ARCH} + OBJECT_LIBS RTUbsan_minimal + CFLAGS ${UBSAN_CFLAGS} + PARENT_TARGET ubsan-minimal) + +add_compiler_rt_runtime(clang_rt.ubsan_minimal + SHARED + OS ${UBSAN_SUPPORTED_OS} + ARCHS ${UBSAN_SUPPORTED_ARCH} + OBJECT_LIBS RTUbsan_minimal + CFLAGS ${UBSAN_CFLAGS} + LINK_FLAGS ${UBSAN_LINK_FLAGS} + LINK_LIBS ${UBSAN_DYNAMIC_LIBS} + PARENT_TARGET ubsan-minimal) + +if (SANITIZER_USE_SYMBOLS AND NOT APPLE) + set(ARCHS_FOR_SYMBOLS ${UBSAN_SUPPORTED_ARCH}) + list(REMOVE_ITEM ARCHS_FOR_SYMBOLS i386 i686) + add_sanitizer_rt_symbols(clang_rt.ubsan_minimal + ARCHS ${ARCHS_FOR_SYMBOLS} + PARENT_TARGET ubsan-minimal + EXTRA ubsan.syms.extra) endif() diff --git a/compiler-rt/test/cfi/CMakeLists.txt b/compiler-rt/test/cfi/CMakeLists.txt index 88def444d7dda1..98c328fdcf1152 100644 --- a/compiler-rt/test/cfi/CMakeLists.txt +++ b/compiler-rt/test/cfi/CMakeLists.txt @@ -59,9 +59,7 @@ list(APPEND CFI_TEST_DEPS ubsan stats ) -if(COMPILER_RT_HAS_CFI) - list(APPEND CFI_TEST_DEPS cfi) -endif() +list(APPEND CFI_TEST_DEPS cfi) if(NOT COMPILER_RT_STANDALONE_BUILD) list(APPEND CFI_TEST_DEPS diff --git a/compiler-rt/test/gwp_asan/CMakeLists.txt b/compiler-rt/test/gwp_asan/CMakeLists.txt index 2a043cbae1c646..f9580e2592b2fe 100644 --- a/compiler-rt/test/gwp_asan/CMakeLists.txt +++ b/compiler-rt/test/gwp_asan/CMakeLists.txt @@ -14,7 +14,7 @@ set(GWP_ASAN_TEST_DEPS # exported libc++ from the Android NDK is x86-64, even though it's part of the # ARM[64] toolchain... See similar measures for ASan and sanitizer-common that # disable unit tests for Android. -if (COMPILER_RT_INCLUDE_TESTS AND COMPILER_RT_HAS_GWP_ASAN AND NOT ANDROID) +if (COMPILER_RT_INCLUDE_TESTS AND NOT ANDROID) list(APPEND GWP_ASAN_TEST_DEPS GwpAsanUnitTests) configure_lit_site_cfg( ${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.py.in @@ -22,7 +22,7 @@ if (COMPILER_RT_INCLUDE_TESTS AND COMPILER_RT_HAS_GWP_ASAN AND NOT ANDROID) list(APPEND GWP_ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/unit) endif() -if (COMPILER_RT_INCLUDE_TESTS AND COMPILER_RT_HAS_SCUDO_STANDALONE AND COMPILER_RT_HAS_GWP_ASAN) +if (COMPILER_RT_INCLUDE_TESTS AND COMPILER_RT_HAS_SCUDO_STANDALONE) foreach(arch ${GWP_ASAN_SUPPORTED_ARCH}) set(GWP_ASAN_TEST_TARGET_ARCH ${arch}) string(TOLOWER "-${arch}" GWP_ASAN_TEST_CONFIG_SUFFIX) diff --git a/compiler-rt/test/orc/CMakeLists.txt b/compiler-rt/test/orc/CMakeLists.txt index 944753bf5c33c9..927a8dac1cbd44 100644 --- a/compiler-rt/test/orc/CMakeLists.txt +++ b/compiler-rt/test/orc/CMakeLists.txt @@ -13,7 +13,7 @@ if (NOT ANDROID AND NOT COMPILER_RT_STANDALONE_BUILD AND endif() set(ORC_TEST_ARCH ${ORC_SUPPORTED_ARCH}) -if (COMPILER_RT_BUILD_ORC AND COMPILER_RT_HAS_ORC) +if (COMPILER_RT_BUILD_ORC) list(APPEND ORC_TEST_DEPS orc) foreach(arch ${ORC_TEST_ARCH}) set(ORC_TEST_TARGET_ARCH ${arch}) diff --git a/compiler-rt/test/rtsan/CMakeLists.txt b/compiler-rt/test/rtsan/CMakeLists.txt index ba1070467f1a37..2a59a57f273720 100644 --- a/compiler-rt/test/rtsan/CMakeLists.txt +++ b/compiler-rt/test/rtsan/CMakeLists.txt @@ -21,20 +21,18 @@ if(APPLE) darwin_filter_host_archs(RTSAN_SUPPORTED_ARCH RTSAN_TEST_ARCH) endif() -if (COMPILER_RT_HAS_RTSAN) - foreach(arch ${RTSAN_TEST_ARCH}) - set(RTSAN_TEST_TARGET_ARCH ${arch}) - string(TOLOWER "-${arch}-${OS_NAME}" RTSAN_TEST_CONFIG_SUFFIX) - get_test_cc_for_arch(${arch} RTSAN_TEST_TARGET_CC RTSAN_TEST_TARGET_CFLAGS) - string(TOUPPER ${arch} ARCH_UPPER_CASE) - set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config) +foreach(arch ${RTSAN_TEST_ARCH}) + set(RTSAN_TEST_TARGET_ARCH ${arch}) + string(TOLOWER "-${arch}-${OS_NAME}" RTSAN_TEST_CONFIG_SUFFIX) + get_test_cc_for_arch(${arch} RTSAN_TEST_TARGET_CC RTSAN_TEST_TARGET_CFLAGS) + string(TOUPPER ${arch} ARCH_UPPER_CASE) + set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config) - configure_lit_site_cfg( - ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in - ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py) - list(APPEND RTSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}) - endforeach() -endif() + configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in + ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py) + list(APPEND RTSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}) +endforeach() if(COMPILER_RT_INCLUDE_TESTS) configure_lit_site_cfg( diff --git a/compiler-rt/test/scudo/standalone/CMakeLists.txt b/compiler-rt/test/scudo/standalone/CMakeLists.txt index aba057e677e28b..0034cea360f377 100644 --- a/compiler-rt/test/scudo/standalone/CMakeLists.txt +++ b/compiler-rt/test/scudo/standalone/CMakeLists.txt @@ -1,4 +1,4 @@ -if(COMPILER_RT_INCLUDE_TESTS AND COMPILER_RT_HAS_SCUDO_STANDALONE) +if(COMPILER_RT_INCLUDE_TESTS) configure_lit_site_cfg( ${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.py.in ${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg.py) diff --git a/compiler-rt/test/xray/CMakeLists.txt b/compiler-rt/test/xray/CMakeLists.txt index fd2a2f43e195dd..8c352d1fcfcb2e 100644 --- a/compiler-rt/test/xray/CMakeLists.txt +++ b/compiler-rt/test/xray/CMakeLists.txt @@ -5,13 +5,12 @@ set(XRAY_FDR_TESTSUITES) set(XRAY_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS} xray) -if(NOT COMPILER_RT_STANDALONE_BUILD AND COMPILER_RT_BUILD_XRAY AND - COMPILER_RT_HAS_XRAY) +if(NOT COMPILER_RT_STANDALONE_BUILD AND COMPILER_RT_BUILD_XRAY) list(APPEND XRAY_TEST_DEPS llvm-xray) endif() set(XRAY_TEST_ARCH ${XRAY_SUPPORTED_ARCH}) -if (COMPILER_RT_BUILD_XRAY AND COMPILER_RT_HAS_XRAY) +if (COMPILER_RT_BUILD_XRAY) foreach(arch ${XRAY_TEST_ARCH}) set(XRAY_TEST_TARGET_ARCH ${arch}) string(TOLOWER "-${arch}-${OS_NAME}" XRAY_TEST_CONFIG_SUFFIX) From dad7442aff5c85ff9141b0d0f231bcd731cbadc6 Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Wed, 10 Jul 2024 15:07:11 -0500 Subject: [PATCH 10/10] [compiler-rt] Initial support for builtins on GPU targets (#95304) Summary: This patch adds initial support to build the `builtins` library for GPU targets. Primarily this requires adding a few new architectures for `amdgcn` and `nvptx64`. I built this using the following invocations. ```console $ cmake ../compiler-rt -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release -GNinja -DCMAKE_C_COMPILER_TARGET= -DCMAKE_CXX_COMPILER_TARGET= -DCMAKE_C_COMPILER_WORKS=1 -DCMAKE_CXX_COMPILER_WORKS=1 -DLLVM_CMAKE_DIR=../cmake/Modules -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON -C ../compiler-rt/cmake/caches/GPU.cmake ``` Some pointers would be appreciated for how to test this using a standard (non-default target only) build. GPU builds are somewhat finnicky. We only expect this to be built with a sufficiently new clang, as it's the only compiler that supports the target and output we distribute. Distribution is done as LLVM-IR blobs for now. GPUs have little backward compatibility, so linking object files is left to a future patch. More work is necessary to build correctly for all targets and ship into the correct clang resource directory. Additionally we need to use the `libc` project's support for running unit tests. --- compiler-rt/cmake/Modules/AddCompilerRT.cmake | 5 ++-- compiler-rt/cmake/Modules/BuiltinTests.cmake | 2 +- .../cmake/Modules/CompilerRTUtils.cmake | 27 ++++++++++++++++++- compiler-rt/cmake/base-config-ix.cmake | 7 +++++ compiler-rt/cmake/builtin-config-ix.cmake | 13 ++++++--- compiler-rt/cmake/caches/GPU.cmake | 18 +++++++++++++ compiler-rt/lib/builtins/CMakeLists.txt | 21 ++++++++++++++- 7 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 compiler-rt/cmake/caches/GPU.cmake diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake index 298093462f80b3..6962b733733a6a 100644 --- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake +++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake @@ -175,8 +175,9 @@ function(add_compiler_rt_runtime name type) ${ARGN}) set(libnames) # Until we support this some other way, build compiler-rt runtime without LTO - # to allow non-LTO projects to link with it. - if(COMPILER_RT_HAS_FNO_LTO_FLAG) + # to allow non-LTO projects to link with it. GPU targets can currently only be + # distributed as LLVM-IR and ignore this. + if(COMPILER_RT_HAS_FNO_LTO_FLAG AND NOT COMPILER_RT_GPU_BUILD) set(NO_LTO_FLAGS "-fno-lto") else() set(NO_LTO_FLAGS "") diff --git a/compiler-rt/cmake/Modules/BuiltinTests.cmake b/compiler-rt/cmake/Modules/BuiltinTests.cmake index 7d71ca3f71efd5..63c5f47cb5010e 100644 --- a/compiler-rt/cmake/Modules/BuiltinTests.cmake +++ b/compiler-rt/cmake/Modules/BuiltinTests.cmake @@ -112,7 +112,7 @@ endfunction() function(builtin_check_c_compiler_flag flag output) if(NOT DEFINED ${output}) message(STATUS "Performing Test ${output}") - try_compile_only(result FLAGS ${flag}) + try_compile_only(result FLAGS ${flag} ${CMAKE_REQUIRED_FLAGS}) set(${output} ${result} CACHE INTERNAL "Compiler supports ${flag}") if(${result}) message(STATUS "Performing Test ${output} - Success") diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake index cec7af929fb2b6..58b02fe48cd8f5 100644 --- a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake +++ b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake @@ -146,6 +146,7 @@ macro(test_target_arch arch def) endmacro() macro(detect_target_arch) + check_symbol_exists(__AMDGPU__ "" __AMDGPU) check_symbol_exists(__arm__ "" __ARM) check_symbol_exists(__AVR__ "" __AVR) check_symbol_exists(__aarch64__ "" __AARCH64) @@ -154,6 +155,7 @@ macro(detect_target_arch) check_symbol_exists(__loongarch__ "" __LOONGARCH) check_symbol_exists(__mips__ "" __MIPS) check_symbol_exists(__mips64__ "" __MIPS64) + check_symbol_exists(__NVPTX__ "" __NVPTX) check_symbol_exists(__powerpc__ "" __PPC) check_symbol_exists(__powerpc64__ "" __PPC64) check_symbol_exists(__powerpc64le__ "" __PPC64LE) @@ -164,7 +166,9 @@ macro(detect_target_arch) check_symbol_exists(__wasm32__ "" __WEBASSEMBLY32) check_symbol_exists(__wasm64__ "" __WEBASSEMBLY64) check_symbol_exists(__ve__ "" __VE) - if(__ARM) + if(__AMDGPU) + add_default_target_arch(amdgcn) + elseif(__ARM) add_default_target_arch(arm) elseif(__AVR) add_default_target_arch(avr) @@ -192,6 +196,8 @@ macro(detect_target_arch) add_default_target_arch(mips64) elseif(__MIPS) add_default_target_arch(mips) + elseif(__NVPTX) + add_default_target_arch(nvptx64) elseif(__PPC64) # must be checked before __PPC add_default_target_arch(powerpc64) elseif(__PPC64LE) @@ -397,6 +403,21 @@ macro(construct_compiler_rt_default_triple) set(COMPILER_RT_DEFAULT_TARGET_ARCH "i386") endif() + # If we are directly targeting a GPU we need to check that the compiler is + # compatible and pass some default arguments. + if(COMPILER_RT_DEFAULT_TARGET_ONLY) + + # Pass the necessary flags to make flag detection work. + if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn") + set(COMPILER_RT_GPU_BUILD ON) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nogpulib") + elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "nvptx") + set(COMPILER_RT_GPU_BUILD ON) + set(CMAKE_REQUIRED_FLAGS + "${CMAKE_REQUIRED_FLAGS} -flto -c -Wno-unused-command-line-argument") + endif() + endif() + # Determine if test target triple is specified explicitly, and doesn't match the # default. if(NOT COMPILER_RT_DEFAULT_TARGET_TRIPLE STREQUAL LLVM_TARGET_TRIPLE) @@ -475,6 +496,10 @@ function(get_compiler_rt_target arch variable) endif() endif() set(target "${arch}${triple_suffix}") + elseif("${arch}" MATCHES "^amdgcn") + set(target "amdgcn-amd-amdhsa") + elseif("${arch}" MATCHES "^nvptx") + set(target "nvptx64-nvidia-cuda") else() set(target "${arch}${triple_suffix}") endif() diff --git a/compiler-rt/cmake/base-config-ix.cmake b/compiler-rt/cmake/base-config-ix.cmake index 87137b3d111b68..2d6342b28ea313 100644 --- a/compiler-rt/cmake/base-config-ix.cmake +++ b/compiler-rt/cmake/base-config-ix.cmake @@ -214,6 +214,10 @@ macro(test_targets) test_target_arch(x86_64 "" "") endif() endif() + elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn") + test_target_arch(amdgcn "" "--target=amdgcn-amd-amdhsa" "-nogpulib" + "-flto" "-fconvergent-functions" + "-Xclang -mcode-object-version=none") elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "loongarch64") test_target_arch(loongarch64 "" "") elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc64le|ppc64le") @@ -254,6 +258,9 @@ macro(test_targets) test_target_arch(mips "" "-mips32r2" "-mabi=32" "-D_LARGEFILE_SOURCE=1" "-D_FILE_OFFSET_BITS=64") test_target_arch(mips64 "" "-mips64r2" "-mabi=64") endif() + elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "nvptx") + test_target_arch(nvptx64 "" "--nvptx64-nvidia-cuda" "-nogpulib" "-flto" + "-fconvergent-functions" "-c") elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "arm") if(WIN32) test_target_arch(arm "" "" "") diff --git a/compiler-rt/cmake/builtin-config-ix.cmake b/compiler-rt/cmake/builtin-config-ix.cmake index 33c97b1ac28aff..1f63e158409ca4 100644 --- a/compiler-rt/cmake/builtin-config-ix.cmake +++ b/compiler-rt/cmake/builtin-config-ix.cmake @@ -19,6 +19,10 @@ builtin_check_c_compiler_flag(-fno-profile-generate COMPILER_RT_HAS_FNO_PROFILE_ builtin_check_c_compiler_flag(-fno-profile-instr-generate COMPILER_RT_HAS_FNO_PROFILE_INSTR_GENERATE_FLAG) builtin_check_c_compiler_flag(-fno-profile-instr-use COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG) builtin_check_c_compiler_flag(-Wno-pedantic COMPILER_RT_HAS_WNO_PEDANTIC) +builtin_check_c_compiler_flag(-nogpulib COMPILER_RT_HAS_NOGPULIB_FLAG) +builtin_check_c_compiler_flag(-flto COMPILER_RT_HAS_FLTO_FLAG) +builtin_check_c_compiler_flag(-fconvergent-functions COMPILER_RT_HAS_FCONVERGENT_FUNCTIONS_FLAG) +builtin_check_c_compiler_flag("-Xclang -mcode-object-version=none" COMPILER_RT_HAS_CODE_OBJECT_VERSION_FLAG) builtin_check_c_compiler_flag(-Wbuiltin-declaration-mismatch COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG) builtin_check_c_compiler_flag(/Zl COMPILER_RT_HAS_ZL_FLAG) @@ -52,6 +56,7 @@ else() set(OS_NAME "${CMAKE_SYSTEM_NAME}") endif() +set(AMDGPU amdgcn) set(ARM64 aarch64) set(ARM32 arm armhf armv4t armv5te armv6 armv6m armv7m armv7em armv7 armv7s armv7k armv8m.base armv8m.main armv8.1m.main) set(AVR avr) @@ -61,6 +66,7 @@ set(X86_64 x86_64) set(LOONGARCH64 loongarch64) set(MIPS32 mips mipsel) set(MIPS64 mips64 mips64el) +set(NVPTX nvptx64) set(PPC32 powerpc powerpcspe) set(PPC64 powerpc64 powerpc64le) set(RISCV32 riscv32) @@ -78,8 +84,8 @@ if(APPLE) endif() set(ALL_BUILTIN_SUPPORTED_ARCH - ${X86} ${X86_64} ${ARM32} ${ARM64} ${AVR} - ${HEXAGON} ${MIPS32} ${MIPS64} ${PPC32} ${PPC64} + ${X86} ${X86_64} ${AMDGPU} ${ARM32} ${ARM64} ${AVR} + ${HEXAGON} ${MIPS32} ${MIPS64} ${NVPTX} ${PPC32} ${PPC64} ${RISCV32} ${RISCV64} ${SPARC} ${SPARCV9} ${WASM32} ${WASM64} ${VE} ${LOONGARCH64}) @@ -245,7 +251,8 @@ else() ${ALL_BUILTIN_SUPPORTED_ARCH}) endif() -if (OS_NAME MATCHES "Linux|SerenityOS" AND NOT LLVM_USE_SANITIZER) +if(OS_NAME MATCHES "Linux|SerenityOS" AND NOT LLVM_USE_SANITIZER AND NOT + COMPILER_RT_GPU_BUILD) set(COMPILER_RT_HAS_CRT TRUE) else() set(COMPILER_RT_HAS_CRT FALSE) diff --git a/compiler-rt/cmake/caches/GPU.cmake b/compiler-rt/cmake/caches/GPU.cmake new file mode 100644 index 00000000000000..e448774cf14576 --- /dev/null +++ b/compiler-rt/cmake/caches/GPU.cmake @@ -0,0 +1,18 @@ +# This file sets up a CMakeCache for GPU builds of compiler-rt. This supports +# amdgcn and nvptx builds targeting the builtins library. + +set(COMPILER_RT_INCLUDE_TESTS OFF CACHE BOOL "") +set(COMPILER_RT_HAS_SAFESTACK OFF CACHE BOOL "") + +set(COMPILER_RT_BUILD_BUILTINS ON CACHE BOOL "") +set(COMPILER_RT_BAREMETAL_BUILD ON CACHE BOOL "") +set(COMPILER_RT_BUILD_CRT OFF CACHE BOOL "") +set(COMPILER_RT_BUILD_SANITIZERS OFF CACHE BOOL "") +set(COMPILER_RT_BUILD_XRAY OFF CACHE BOOL "") +set(COMPILER_RT_BUILD_LIBFUZZER OFF CACHE BOOL "") +set(COMPILER_RT_BUILD_PROFILE OFF CACHE BOOL "") +set(COMPILER_RT_BUILD_MEMPROF OFF CACHE BOOL "") +set(COMPILER_RT_BUILD_XRAY_NO_PREINIT OFF CACHE BOOL "") +set(COMPILER_RT_BUILD_ORC OFF CACHE BOOL "") +set(COMPILER_RT_BUILD_GWP_ASAN OFF CACHE BOOL "") +set(COMPILER_RT_BUILD_SCUDO_SANTDALONE_WITH_LLVM_LIBC OFF CACHE BOOL "") diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt index ba81c78f16608a..f780b917cbdb1a 100644 --- a/compiler-rt/lib/builtins/CMakeLists.txt +++ b/compiler-rt/lib/builtins/CMakeLists.txt @@ -228,7 +228,7 @@ option(COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN "Skip the atomic builtin (these should normally be provided by a shared library)" On) -if(NOT FUCHSIA AND NOT COMPILER_RT_BAREMETAL_BUILD) +if(NOT FUCHSIA AND NOT COMPILER_RT_BAREMETAL_BUILD AND NOT COMPILER_RT_GPU_BUILD) set(GENERIC_SOURCES ${GENERIC_SOURCES} emutls.c @@ -627,6 +627,8 @@ if (MINGW) ) endif() +set(amdgcn_SOURCES ${GENERIC_SOURCES}) + set(armv4t_SOURCES ${arm_min_SOURCES}) set(armv5te_SOURCES ${arm_min_SOURCES}) set(armv6_SOURCES ${arm_min_SOURCES}) @@ -706,6 +708,8 @@ set(mips64_SOURCES ${GENERIC_TF_SOURCES} set(mips64el_SOURCES ${GENERIC_TF_SOURCES} ${mips_SOURCES}) +set(nvptx64_SOURCES ${GENERIC_SOURCES}) + set(powerpc_SOURCES ${GENERIC_SOURCES}) set(powerpcspe_SOURCES ${GENERIC_SOURCES}) @@ -811,6 +815,21 @@ else () endif() endif() + # Directly targeting the GPU requires a few extra flags. + if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn|nvptx") + append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding BUILTIN_CFLAGS) + append_list_if(COMPILER_RT_HAS_NOGPULIB_FLAG -nogpulib BUILTIN_CFLAGS) + append_list_if(COMPILER_RT_HAS_FLTO_FLAG -flto BUILTIN_CFLAGS) + append_list_if(COMPILER_RT_HAS_FCONVERGENT_FUNCTIONS_FLAG + -fconvergent-functions BUILTIN_CFLAGS) + + # AMDGPU targets want to use a generic ABI. + if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn") + append_list_if(COMPILER_RT_HAS_CODE_OBJECT_VERSION_FLAG + "SHELL:-Xclang -mcode-object-version=none" BUILTIN_CFLAGS) + endif() + endif() + set(BUILTIN_DEFS "") if(COMPILER_RT_BUILTINS_HIDE_SYMBOLS)