summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_llvm
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:29 +0000
commit631cd5845e8de329d0e227aaa707d7ea228b8f8f (patch)
treea1b87c8f8cad01cf18f7c5f57a08f102771ed303 /compiler/rustc_llvm
parentAdding debian version 1.69.0+dfsg1-1. (diff)
downloadrustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.tar.xz
rustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_llvm')
-rw-r--r--compiler/rustc_llvm/build.rs2
-rw-r--r--compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp33
-rw-r--r--compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp102
-rw-r--r--compiler/rustc_llvm/llvm-wrapper/SymbolWrapper.cpp1
-rw-r--r--compiler/rustc_llvm/src/lib.rs10
5 files changed, 62 insertions, 86 deletions
diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs
index 9fe59a1d8..b0783d75d 100644
--- a/compiler/rustc_llvm/build.rs
+++ b/compiler/rustc_llvm/build.rs
@@ -10,6 +10,7 @@ const OPTIONAL_COMPONENTS: &[&str] = &[
"aarch64",
"amdgpu",
"avr",
+ "loongarch",
"m68k",
"mips",
"powerpc",
@@ -333,6 +334,7 @@ fn main() {
} else if target.contains("darwin")
|| target.contains("freebsd")
|| target.contains("windows-gnullvm")
+ || target.contains("aix")
{
"c++"
} else if target.contains("netbsd") && llvm_static_stdcpp.is_some() {
diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
index 4761ce83f..08e38b0c9 100644
--- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
+++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
@@ -26,7 +26,6 @@
#endif
#include "llvm/Support/Host.h"
#include "llvm/Target/TargetMachine.h"
-#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Transforms/IPO/AlwaysInliner.h"
#include "llvm/Transforms/IPO/FunctionImport.h"
#include "llvm/Transforms/IPO/Internalize.h"
@@ -35,7 +34,6 @@
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
#include "llvm/LTO/LTO.h"
#include "llvm/Bitcode/BitcodeWriter.h"
-#include "llvm-c/Transforms/PassManagerBuilder.h"
#include "llvm/Transforms/Instrumentation.h"
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
@@ -148,6 +146,12 @@ extern "C" void LLVMTimeTraceProfilerFinish(const char* FileName) {
#define SUBTARGET_HEXAGON
#endif
+#ifdef LLVM_COMPONENT_LOONGARCH
+#define SUBTARGET_LOONGARCH SUBTARGET(LoongArch)
+#else
+#define SUBTARGET_LOONGARCH
+#endif
+
#define GEN_SUBTARGETS \
SUBTARGET_X86 \
SUBTARGET_ARM \
@@ -161,6 +165,7 @@ extern "C" void LLVMTimeTraceProfilerFinish(const char* FileName) {
SUBTARGET_SPARC \
SUBTARGET_HEXAGON \
SUBTARGET_RISCV \
+ SUBTARGET_LOONGARCH \
#define SUBTARGET(x) \
namespace llvm { \
@@ -370,7 +375,8 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
bool EmitStackSizeSection,
bool RelaxELFRelocations,
bool UseInitArray,
- const char *SplitDwarfFile) {
+ const char *SplitDwarfFile,
+ bool ForceEmulatedTls) {
auto OptLevel = fromRust(RustOptLevel);
auto RM = fromRust(RustReloc);
@@ -402,6 +408,10 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
}
Options.RelaxELFRelocations = RelaxELFRelocations;
Options.UseInitArray = UseInitArray;
+ if (ForceEmulatedTls) {
+ Options.ExplicitEmulatedTLS = true;
+ Options.EmulatedTLS = true;
+ }
if (TrapUnreachable) {
// Tell LLVM to codegen `unreachable` into an explicit trap instruction.
@@ -1160,13 +1170,6 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
// Otherwise, we sometimes lose `static` values -- see #60184.
computeDeadSymbolsWithConstProp(Ret->Index, Ret->GUIDPreservedSymbols,
deadIsPrevailing, /* ImportEnabled = */ false);
- ComputeCrossModuleImport(
- Ret->Index,
- Ret->ModuleToDefinedGVSummaries,
- Ret->ImportLists,
- Ret->ExportLists
- );
-
// Resolve LinkOnce/Weak symbols, this has to be computed early be cause it
// impacts the caching.
//
@@ -1183,6 +1186,16 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
return true;
return Prevailing->second == S;
};
+ ComputeCrossModuleImport(
+ Ret->Index,
+ Ret->ModuleToDefinedGVSummaries,
+#if LLVM_VERSION_GE(17, 0)
+ isPrevailing,
+#endif
+ Ret->ImportLists,
+ Ret->ExportLists
+ );
+
auto recordNewLinkage = [&](StringRef ModuleIdentifier,
GlobalValue::GUID GUID,
GlobalValue::LinkageTypes NewLinkage) {
diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
index e3493caaa..49acd71b3 100644
--- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
+++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
@@ -152,10 +152,6 @@ LLVMRustInsertPrivateGlobal(LLVMModuleRef M, LLVMTypeRef Ty) {
nullptr));
}
-extern "C" LLVMTypeRef LLVMRustMetadataTypeInContext(LLVMContextRef C) {
- return wrap(Type::getMetadataTy(*unwrap(C)));
-}
-
static Attribute::AttrKind fromRust(LLVMRustAttribute Kind) {
switch (Kind) {
case AlwaysInline:
@@ -480,11 +476,6 @@ extern "C" bool LLVMRustInlineAsmVerify(LLVMTypeRef Ty, char *Constraints,
#endif
}
-extern "C" void LLVMRustAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm,
- size_t AsmLen) {
- unwrap(M)->appendModuleInlineAsm(StringRef(Asm, AsmLen));
-}
-
typedef DIBuilder *LLVMRustDIBuilderRef;
template <typename DIT> DIT *unwrapDIPtr(LLVMMetadataRef Ref) {
@@ -682,6 +673,7 @@ enum class LLVMRustDebugEmissionKind {
NoDebug,
FullDebug,
LineTablesOnly,
+ DebugDirectivesOnly,
};
static DICompileUnit::DebugEmissionKind fromRust(LLVMRustDebugEmissionKind Kind) {
@@ -692,6 +684,8 @@ static DICompileUnit::DebugEmissionKind fromRust(LLVMRustDebugEmissionKind Kind)
return DICompileUnit::DebugEmissionKind::FullDebug;
case LLVMRustDebugEmissionKind::LineTablesOnly:
return DICompileUnit::DebugEmissionKind::LineTablesOnly;
+ case LLVMRustDebugEmissionKind::DebugDirectivesOnly:
+ return DICompileUnit::DebugEmissionKind::DebugDirectivesOnly;
default:
report_fatal_error("bad DebugEmissionKind.");
}
@@ -750,10 +744,6 @@ extern "C" bool LLVMRustHasModuleFlag(LLVMModuleRef M, const char *Name,
return unwrap(M)->getModuleFlag(StringRef(Name, Len)) != nullptr;
}
-extern "C" LLVMValueRef LLVMRustMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD) {
- return wrap(MetadataAsValue::get(*unwrap(C), unwrap(MD)));
-}
-
extern "C" void LLVMRustGlobalAddMetadata(
LLVMValueRef Global, unsigned Kind, LLVMMetadataRef MD) {
unwrap<GlobalObject>(Global)->addMetadata(Kind, *unwrap<MDNode>(MD));
@@ -841,6 +831,28 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFunction(
return wrap(Sub);
}
+extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateMethod(
+ LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope,
+ const char *Name, size_t NameLen,
+ const char *LinkageName, size_t LinkageNameLen,
+ LLVMMetadataRef File, unsigned LineNo,
+ LLVMMetadataRef Ty, LLVMRustDIFlags Flags,
+ LLVMRustDISPFlags SPFlags, LLVMMetadataRef TParam) {
+ DITemplateParameterArray TParams =
+ DITemplateParameterArray(unwrap<MDTuple>(TParam));
+ DISubprogram::DISPFlags llvmSPFlags = fromRust(SPFlags);
+ DINode::DIFlags llvmFlags = fromRust(Flags);
+ DISubprogram *Sub = Builder->createMethod(
+ unwrapDI<DIScope>(Scope),
+ StringRef(Name, NameLen),
+ StringRef(LinkageName, LinkageNameLen),
+ unwrapDI<DIFile>(File), LineNo,
+ unwrapDI<DISubroutineType>(Ty),
+ 0, 0, nullptr, // VTable params aren't used
+ llvmFlags, llvmSPFlags, TParams);
+ return wrap(Sub);
+}
+
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateBasicType(
LLVMRustDIBuilderRef Builder, const char *Name, size_t NameLen,
uint64_t SizeInBits, unsigned Encoding) {
@@ -1150,6 +1162,8 @@ extern "C" void LLVMRustWriteValueToString(LLVMValueRef V,
}
// LLVMArrayType function does not support 64-bit ElementCount
+// FIXME: replace with LLVMArrayType2 when bumped minimal version to llvm-17
+// https://github.com/llvm/llvm-project/commit/35276f16e5a2cae0dfb49c0fbf874d4d2f177acc
extern "C" LLVMTypeRef LLVMRustArrayType(LLVMTypeRef ElementTy,
uint64_t ElementCount) {
return wrap(ArrayType::get(unwrap(ElementTy), ElementCount));
@@ -1405,61 +1419,6 @@ extern "C" bool LLVMRustUnpackSMDiagnostic(LLVMSMDiagnosticRef DRef,
return true;
}
-extern "C" LLVMValueRef LLVMRustBuildCleanupPad(LLVMBuilderRef B,
- LLVMValueRef ParentPad,
- unsigned ArgCount,
- LLVMValueRef *LLArgs,
- const char *Name) {
- Value **Args = unwrap(LLArgs);
- if (ParentPad == nullptr) {
- Type *Ty = Type::getTokenTy(unwrap(B)->getContext());
- ParentPad = wrap(Constant::getNullValue(Ty));
- }
- return wrap(unwrap(B)->CreateCleanupPad(
- unwrap(ParentPad), ArrayRef<Value *>(Args, ArgCount), Name));
-}
-
-extern "C" LLVMValueRef LLVMRustBuildCleanupRet(LLVMBuilderRef B,
- LLVMValueRef CleanupPad,
- LLVMBasicBlockRef UnwindBB) {
- CleanupPadInst *Inst = cast<CleanupPadInst>(unwrap(CleanupPad));
- return wrap(unwrap(B)->CreateCleanupRet(Inst, unwrap(UnwindBB)));
-}
-
-extern "C" LLVMValueRef
-LLVMRustBuildCatchPad(LLVMBuilderRef B, LLVMValueRef ParentPad,
- unsigned ArgCount, LLVMValueRef *LLArgs, const char *Name) {
- Value **Args = unwrap(LLArgs);
- return wrap(unwrap(B)->CreateCatchPad(
- unwrap(ParentPad), ArrayRef<Value *>(Args, ArgCount), Name));
-}
-
-extern "C" LLVMValueRef LLVMRustBuildCatchRet(LLVMBuilderRef B,
- LLVMValueRef Pad,
- LLVMBasicBlockRef BB) {
- return wrap(unwrap(B)->CreateCatchRet(cast<CatchPadInst>(unwrap(Pad)),
- unwrap(BB)));
-}
-
-extern "C" LLVMValueRef LLVMRustBuildCatchSwitch(LLVMBuilderRef B,
- LLVMValueRef ParentPad,
- LLVMBasicBlockRef BB,
- unsigned NumHandlers,
- const char *Name) {
- if (ParentPad == nullptr) {
- Type *Ty = Type::getTokenTy(unwrap(B)->getContext());
- ParentPad = wrap(Constant::getNullValue(Ty));
- }
- return wrap(unwrap(B)->CreateCatchSwitch(unwrap(ParentPad), unwrap(BB),
- NumHandlers, Name));
-}
-
-extern "C" void LLVMRustAddHandler(LLVMValueRef CatchSwitchRef,
- LLVMBasicBlockRef Handler) {
- Value *CatchSwitch = unwrap(CatchSwitchRef);
- cast<CatchSwitchInst>(CatchSwitch)->addHandler(unwrap(Handler));
-}
-
extern "C" OperandBundleDef *LLVMRustBuildOperandBundleDef(const char *Name,
LLVMValueRef *Inputs,
unsigned NumInputs) {
@@ -1624,6 +1583,7 @@ extern "C" void LLVMRustSetLinkage(LLVMValueRef V,
LLVMSetLinkage(V, fromRust(RustLinkage));
}
+// FIXME: replace with LLVMConstInBoundsGEP2 when bumped minimal version to llvm-14
extern "C" LLVMValueRef LLVMRustConstInBoundsGEP2(LLVMTypeRef Ty,
LLVMValueRef ConstantVal,
LLVMValueRef *ConstantIndices,
@@ -1701,12 +1661,6 @@ extern "C" LLVMRustVisibility LLVMRustGetVisibility(LLVMValueRef V) {
return toRust(LLVMGetVisibility(V));
}
-// Oh hey, a binding that makes sense for once? (because LLVM’s own do not)
-extern "C" LLVMValueRef LLVMRustBuildIntCast(LLVMBuilderRef B, LLVMValueRef Val,
- LLVMTypeRef DestTy, bool isSigned) {
- return wrap(unwrap(B)->CreateIntCast(unwrap(Val), unwrap(DestTy), isSigned, ""));
-}
-
extern "C" void LLVMRustSetVisibility(LLVMValueRef V,
LLVMRustVisibility RustVisibility) {
LLVMSetVisibility(V, fromRust(RustVisibility));
diff --git a/compiler/rustc_llvm/llvm-wrapper/SymbolWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/SymbolWrapper.cpp
index 974207e91..0493d6b05 100644
--- a/compiler/rustc_llvm/llvm-wrapper/SymbolWrapper.cpp
+++ b/compiler/rustc_llvm/llvm-wrapper/SymbolWrapper.cpp
@@ -9,7 +9,6 @@
#include "llvm/IR/LLVMContext.h"
#include "llvm/Object/ObjectFile.h"
-#include "llvm/ADT/Optional.h"
using namespace llvm;
using namespace llvm::sys;
diff --git a/compiler/rustc_llvm/src/lib.rs b/compiler/rustc_llvm/src/lib.rs
index 8542dcf5b..a49ded4fd 100644
--- a/compiler/rustc_llvm/src/lib.rs
+++ b/compiler/rustc_llvm/src/lib.rs
@@ -30,7 +30,7 @@ pub unsafe extern "C" fn LLVMRustStringWriteImpl(
ptr: *const c_char,
size: size_t,
) {
- let slice = slice::from_raw_parts(ptr as *const u8, size as usize);
+ let slice = slice::from_raw_parts(ptr as *const u8, size);
sr.bytes.borrow_mut().extend_from_slice(slice);
}
@@ -103,6 +103,14 @@ pub fn initialize_available_targets() {
LLVMInitializeM68kAsmParser
);
init_target!(
+ llvm_component = "loongarch",
+ LLVMInitializeLoongArchTargetInfo,
+ LLVMInitializeLoongArchTarget,
+ LLVMInitializeLoongArchTargetMC,
+ LLVMInitializeLoongArchAsmPrinter,
+ LLVMInitializeLoongArchAsmParser
+ );
+ init_target!(
llvm_component = "mips",
LLVMInitializeMipsTargetInfo,
LLVMInitializeMipsTarget,