summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp')
-rw-r--r--compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp76
1 files changed, 60 insertions, 16 deletions
diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
index c43a02724..b566ea496 100644
--- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
+++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
@@ -1,5 +1,6 @@
#include <stdio.h>
+#include <iomanip>
#include <vector>
#include <set>
@@ -24,11 +25,11 @@
#if LLVM_VERSION_GE(17, 0)
#include "llvm/Support/VirtualFileSystem.h"
#endif
-#include "llvm/Support/Host.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/IPO/AlwaysInliner.h"
#include "llvm/Transforms/IPO/FunctionImport.h"
#include "llvm/Transforms/IPO/Internalize.h"
+#include "llvm/Transforms/IPO/LowerTypeTests.h"
#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
#include "llvm/Transforms/Utils/AddDiscriminators.h"
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
@@ -104,6 +105,12 @@ extern "C" void LLVMTimeTraceProfilerFinish(const char* FileName) {
#define SUBTARGET_M68K
#endif
+#ifdef LLVM_COMPONENT_CSKY
+#define SUBTARGET_CSKY SUBTARGET(CSKY)
+#else
+#define SUBTARGET_CSKY
+#endif
+
#ifdef LLVM_COMPONENT_MIPS
#define SUBTARGET_MIPS SUBTARGET(Mips)
#else
@@ -158,6 +165,7 @@ extern "C" void LLVMTimeTraceProfilerFinish(const char* FileName) {
SUBTARGET_AARCH64 \
SUBTARGET_AVR \
SUBTARGET_M68K \
+ SUBTARGET_CSKY \
SUBTARGET_MIPS \
SUBTARGET_PPC \
SUBTARGET_SYSTEMZ \
@@ -306,44 +314,53 @@ static size_t getLongestEntryLength(ArrayRef<KV> Table) {
return MaxLen;
}
-extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM, const char* TargetCPU) {
+using PrintBackendInfo = void(void*, const char* Data, size_t Len);
+
+extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM,
+ const char* TargetCPU,
+ PrintBackendInfo Print,
+ void* Out) {
const TargetMachine *Target = unwrap(TM);
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
const Triple::ArchType HostArch = Triple(sys::getDefaultTargetTriple()).getArch();
const Triple::ArchType TargetArch = Target->getTargetTriple().getArch();
+ std::ostringstream Buf;
+
#if LLVM_VERSION_GE(17, 0)
const ArrayRef<SubtargetSubTypeKV> CPUTable = MCInfo->getAllProcessorDescriptions();
-#elif defined(LLVM_RUSTLLVM)
- const ArrayRef<SubtargetSubTypeKV> CPUTable = MCInfo->getCPUTable();
#else
- printf("Full target CPU help is not supported by this LLVM version.\n\n");
+ Buf << "Full target CPU help is not supported by this LLVM version.\n\n";
SubtargetSubTypeKV TargetCPUKV = { TargetCPU, {{}}, {{}} };
const ArrayRef<SubtargetSubTypeKV> CPUTable = TargetCPUKV;
#endif
unsigned MaxCPULen = getLongestEntryLength(CPUTable);
- printf("Available CPUs for this target:\n");
+ Buf << "Available CPUs for this target:\n";
// Don't print the "native" entry when the user specifies --target with a
// different arch since that could be wrong or misleading.
if (HostArch == TargetArch) {
MaxCPULen = std::max(MaxCPULen, (unsigned) std::strlen("native"));
const StringRef HostCPU = sys::getHostCPUName();
- printf(" %-*s - Select the CPU of the current host (currently %.*s).\n",
- MaxCPULen, "native", (int)HostCPU.size(), HostCPU.data());
+ Buf << " " << std::left << std::setw(MaxCPULen) << "native"
+ << " - Select the CPU of the current host "
+ "(currently " << HostCPU.str() << ").\n";
}
for (auto &CPU : CPUTable) {
// Compare cpu against current target to label the default
if (strcmp(CPU.Key, TargetCPU) == 0) {
- printf(" %-*s - This is the default target CPU"
- " for the current build target (currently %s).",
- MaxCPULen, CPU.Key, Target->getTargetTriple().str().c_str());
+ Buf << " " << std::left << std::setw(MaxCPULen) << CPU.Key
+ << " - This is the default target CPU for the current build target "
+ "(currently " << Target->getTargetTriple().str() << ").";
}
else {
- printf(" %-*s", MaxCPULen, CPU.Key);
+ Buf << " " << CPU.Key;
}
- printf("\n");
+ Buf << "\n";
}
+
+ const auto &BufString = Buf.str();
+ Print(Out, BufString.data(), BufString.size());
}
extern "C" size_t LLVMRustGetTargetFeaturesCount(LLVMTargetMachineRef TM) {
@@ -599,6 +616,8 @@ enum class LLVMRustOptStage {
struct LLVMRustSanitizerOptions {
bool SanitizeAddress;
bool SanitizeAddressRecover;
+ bool SanitizeCFI;
+ bool SanitizeKCFI;
bool SanitizeMemory;
bool SanitizeMemoryRecover;
int SanitizeMemoryTrackOrigins;
@@ -615,6 +634,7 @@ LLVMRustOptimize(
LLVMTargetMachineRef TMRef,
LLVMRustPassBuilderOptLevel OptLevelRust,
LLVMRustOptStage OptStage,
+ bool IsLinkerPluginLTO,
bool NoPrepopulatePasses, bool VerifyIR, bool UseThinLTOBuffers,
bool MergeFunctions, bool UnrollLoops, bool SLPVectorize, bool LoopVectorize,
bool DisableSimplifyLibCalls, bool EmitLifetimeMarkers,
@@ -667,6 +687,7 @@ LLVMRustOptimize(
assert(!PGOUsePath && !PGOSampleUsePath);
PGOOpt = PGOOptions(PGOGenPath, "", "",
#if LLVM_VERSION_GE(17, 0)
+ "",
FS,
#endif
PGOOptions::IRInstr, PGOOptions::NoCSAction,
@@ -675,6 +696,7 @@ LLVMRustOptimize(
assert(!PGOSampleUsePath);
PGOOpt = PGOOptions(PGOUsePath, "", "",
#if LLVM_VERSION_GE(17, 0)
+ "",
FS,
#endif
PGOOptions::IRUse, PGOOptions::NoCSAction,
@@ -682,6 +704,7 @@ LLVMRustOptimize(
} else if (PGOSampleUsePath) {
PGOOpt = PGOOptions(PGOSampleUsePath, "", "",
#if LLVM_VERSION_GE(17, 0)
+ "",
FS,
#endif
PGOOptions::SampleUse, PGOOptions::NoCSAction,
@@ -689,6 +712,7 @@ LLVMRustOptimize(
} else if (DebugInfoForProfiling) {
PGOOpt = PGOOptions("", "", "",
#if LLVM_VERSION_GE(17, 0)
+ "",
FS,
#endif
PGOOptions::NoAction, PGOOptions::NoCSAction,
@@ -722,6 +746,18 @@ LLVMRustOptimize(
std::vector<std::function<void(ModulePassManager &, OptimizationLevel)>>
OptimizerLastEPCallbacks;
+ if (!IsLinkerPluginLTO
+ && SanitizerOptions && SanitizerOptions->SanitizeCFI
+ && !NoPrepopulatePasses) {
+ PipelineStartEPCallbacks.push_back(
+ [](ModulePassManager &MPM, OptimizationLevel Level) {
+ MPM.addPass(LowerTypeTestsPass(/*ExportSummary=*/nullptr,
+ /*ImportSummary=*/nullptr,
+ /*DropTypeTests=*/false));
+ }
+ );
+ }
+
if (VerifyIR) {
PipelineStartEPCallbacks.push_back(
[VerifyIR](ModulePassManager &MPM, OptimizationLevel Level) {
@@ -785,9 +821,6 @@ LLVMRustOptimize(
OptimizerLastEPCallbacks.push_back(
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
auto CompileKernel = SanitizerOptions->SanitizeKernelAddress;
-#if LLVM_VERSION_LT(15, 0)
- MPM.addPass(RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>());
-#endif
AddressSanitizerOptions opts = AddressSanitizerOptions{
CompileKernel,
SanitizerOptions->SanitizeAddressRecover
@@ -1107,9 +1140,15 @@ struct LLVMRustThinLTOData {
// Not 100% sure what these are, but they impact what's internalized and
// what's inlined across modules, I believe.
+#if LLVM_VERSION_GE(18, 0)
+ DenseMap<StringRef, FunctionImporter::ImportMapTy> ImportLists;
+ DenseMap<StringRef, FunctionImporter::ExportSetTy> ExportLists;
+ DenseMap<StringRef, GVSummaryMapTy> ModuleToDefinedGVSummaries;
+#else
StringMap<FunctionImporter::ImportMapTy> ImportLists;
StringMap<FunctionImporter::ExportSetTy> ExportLists;
StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries;
+#endif
StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>> ResolvedODR;
LLVMRustThinLTOData() : Index(/* HaveGVs = */ false) {}
@@ -1350,6 +1389,11 @@ LLVMRustPrepareThinLTOImport(const LLVMRustThinLTOData *Data, LLVMModuleRef M,
if (WasmCustomSections)
WasmCustomSections->eraseFromParent();
+ // `llvm.ident` named metadata also gets duplicated.
+ auto *llvmIdent = (*MOrErr)->getNamedMetadata("llvm.ident");
+ if (llvmIdent)
+ llvmIdent->eraseFromParent();
+
return MOrErr;
};
bool ClearDSOLocal = clearDSOLocalOnDeclarations(Mod, Target);