Skip to content

Rollup of 9 pull requests #136030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 62 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
98d7162
Preparing for merge from rustc
Kobzol Jan 5, 2025
25beca9
add josh-sync build dir to gitignore (#2196)
BoxyUwU Jan 5, 2025
be5d781
Add rustc-dev-guide to the list of repositories managed by josh (#2197)
Kobzol Jan 6, 2025
8561cc8
Only keep label description in Forge docs
jieyouxu Jan 5, 2025
d91316e
Fix broken raw HTML (#2198)
max-heller Jan 7, 2025
a5e424e
Preparing for merge from rustc
Kobzol Jan 8, 2025
2f3ee5d
Merge from rustc
Kobzol Jan 8, 2025
5a11197
Merge pull request #2200 from Kobzol/rustc-pull
Kobzol Jan 8, 2025
9577119
Save linkcheck cache always
marxin Jan 6, 2025
1ffe0ea
Update key
marxin Jan 8, 2025
7e2a690
Print an explicit message if the base repo head commit is up-to-date
Kobzol Jan 8, 2025
f761e1a
Error if there is nothing to pull
Kobzol Jan 8, 2025
42c284e
Merge pull request #2030 from marxin/ci-cache
camelid Jan 9, 2025
b4297e7
ci: Remove incorrect use of `continue-on-error`
camelid Jan 9, 2025
ce0d5c1
Merge pull request #2203 from camelid/ci-fix
Kobzol Jan 9, 2025
fcbcc74
Document how to find the configuration used in CI
ehuss Jan 10, 2025
43848be
Fix calculate-job-matrix.py link
ehuss Jan 10, 2025
f53bce4
Merge pull request #2206 from ehuss/fix-matrix-link
jieyouxu Jan 10, 2025
90e0127
Merge pull request #2205 from ehuss/ci-config
jieyouxu Jan 10, 2025
980412f
Add CI workflow for performing rustc-pull
Kobzol Jan 8, 2025
31f855b
Fix some broken links
camelid Jan 15, 2025
284d05d
Merge pull request #2208 from camelid/fix-some-links
jieyouxu Jan 15, 2025
1327eeb
Merge pull request #2202 from Kobzol/pull-ci
jieyouxu Jan 15, 2025
4a03a9f
fix some more typos
rmehri01 Jan 15, 2025
1df83a7
Merge pull request #2209 from rmehri01/typos
jieyouxu Jan 15, 2025
f8f912d
nyaa
lcnr Jan 15, 2025
3423f1e
Merge pull request #2210 from lcnr/promote-type-tests
lcnr Jan 15, 2025
6a57fbf
compiletest: fix outdated `rustdoc-js` test suite name
jieyouxu Jan 17, 2025
b38aa65
Merge pull request #2212 from jieyouxu/fix-rustdoc-js
jieyouxu Jan 17, 2025
80c664a
remove outdated text about wfx implies
patrickoliveira15 Jan 17, 2025
84fdb51
Merge pull request #2211 from patrickoliveira15/patch/inference-invar…
JohnTitor Jan 17, 2025
01d1aef
document order of items in iterator from drain
hkBst Jan 19, 2025
c282ac8
Fix whitespace
hkBst Jan 19, 2025
d6b0828
docs: document how to install a suitable `josh-proxy` locally
jieyouxu Jan 18, 2025
24f264a
Merge pull request #2213 from jieyouxu/install-josh-proxy
jieyouxu Jan 20, 2025
29be13d
Add portable SIMD to list of subtrees
Kobzol Jan 20, 2025
808bd95
Preparing for merge from rustc
Kobzol Jan 20, 2025
1e0204b
Merge from rustc
Kobzol Jan 20, 2025
1b5b051
Merge pull request #2214 from Kobzol/subtree-portable-simd
jieyouxu Jan 20, 2025
470ab13
Merge pull request #2215 from Kobzol/pull
Kobzol Jan 20, 2025
28b5e11
Send a message to Zulip when a sync finishes
Kobzol Jan 20, 2025
a3f061c
Merge pull request #2216 from Kobzol/ci-pull-zulip
Kobzol Jan 20, 2025
f416648
Add memory layout documentation to generic NonZero<T>
carlsverre Jan 23, 2025
32cf7cc
Use short type string in E0308 secondary span label
estebank Jan 23, 2025
af2ce8b
don't drop types with no drop glue when tailcalling
WaffleLapkin Jan 24, 2025
530f8bb
Fix indent of trait items on mobile
GuillaumeGomez Jan 24, 2025
caacb04
Add GUI regression test for indent of trait items on mobile
GuillaumeGomez Jan 24, 2025
97e07da
Do not assume const params are printed after type params
compiler-errors Jan 19, 2025
ab27463
Add `File already exists` error doc to `hard_link` function
Harshit933 Jan 12, 2025
4a8de9a
Update library/core/src/num/nonzero.rs
carlsverre Jan 24, 2025
83339bf
add a regression test
WaffleLapkin Jan 24, 2025
9b82f20
bless miri test
WaffleLapkin Jan 24, 2025
386c233
Make CodegenCx and Builder generic
ZuseZ4 Jan 24, 2025
0741cc0
Rollup merge of #135415 - Harshit933:hard-link-error, r=ChrisDenton
matthiaskrgr Jan 24, 2025
1e454fe
Rollup merge of #135581 - EnzymeAD:refactor-codgencx, r=oli-obk
matthiaskrgr Jan 24, 2025
5750815
Rollup merge of #135728 - hkBst:patch-8, r=joboet
matthiaskrgr Jan 24, 2025
ca5fa66
Rollup merge of #135749 - compiler-errors:param-ordering, r=davidtwco
matthiaskrgr Jan 24, 2025
dcd43d3
Rollup merge of #135829 - Kobzol:rustc-push, r=jieyouxu
matthiaskrgr Jan 24, 2025
884ec6b
Rollup merge of #135938 - carlsverre:master, r=joboet
matthiaskrgr Jan 24, 2025
8824ae6
Rollup merge of #135949 - estebank:shorten-ty, r=davidtwco
matthiaskrgr Jan 24, 2025
99e34a4
Rollup merge of #135976 - WaffleLapkin:tailcall-nodrop, r=oli-obk
matthiaskrgr Jan 24, 2025
d15cf36
Rollup merge of #135998 - GuillaumeGomez:fix-trait-items-mobile-inden…
matthiaskrgr Jan 24, 2025
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
1 change: 0 additions & 1 deletion compiler/rustc_codegen_gcc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,6 @@ impl WriteBackendMethods for GccCodegenBackend {
}
fn autodiff(
_cgcx: &CodegenContext<Self>,
_tcx: TyCtxt<'_>,
_module: &ModuleCodegen<Self::Module>,
_diff_fncs: Vec<AutoDiffItem>,
_config: &ModuleConfig,
Expand Down
150 changes: 138 additions & 12 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::borrow::Cow;
use std::borrow::{Borrow, Cow};
use std::ops::Deref;
use std::{iter, ptr};

Expand Down Expand Up @@ -31,27 +31,135 @@ use tracing::{debug, instrument};
use crate::abi::FnAbiLlvmExt;
use crate::attributes;
use crate::common::Funclet;
use crate::context::CodegenCx;
use crate::context::{CodegenCx, SimpleCx};
use crate::llvm::{self, AtomicOrdering, AtomicRmwBinOp, BasicBlock, False, True};
use crate::type_::Type;
use crate::type_of::LayoutLlvmExt;
use crate::value::Value;

// All Builders must have an llfn associated with them
#[must_use]
pub(crate) struct Builder<'a, 'll, 'tcx> {
pub(crate) struct GenericBuilder<'a, 'll, CX: Borrow<SimpleCx<'ll>>> {
pub llbuilder: &'ll mut llvm::Builder<'ll>,
pub cx: &'a CodegenCx<'ll, 'tcx>,
pub cx: &'a CX,
}

impl Drop for Builder<'_, '_, '_> {
pub(crate) type SBuilder<'a, 'll> = GenericBuilder<'a, 'll, SimpleCx<'ll>>;
pub(crate) type Builder<'a, 'll, 'tcx> = GenericBuilder<'a, 'll, CodegenCx<'ll, 'tcx>>;

impl<'a, 'll, CX: Borrow<SimpleCx<'ll>>> Drop for GenericBuilder<'a, 'll, CX> {
fn drop(&mut self) {
unsafe {
llvm::LLVMDisposeBuilder(&mut *(self.llbuilder as *mut _));
}
}
}

impl<'a, 'll> SBuilder<'a, 'll> {
fn call(
&mut self,
llty: &'ll Type,
llfn: &'ll Value,
args: &[&'ll Value],
funclet: Option<&Funclet<'ll>>,
) -> &'ll Value {
debug!("call {:?} with args ({:?})", llfn, args);

let args = self.check_call("call", llty, llfn, args);
let funclet_bundle = funclet.map(|funclet| funclet.bundle());
let mut bundles: SmallVec<[_; 2]> = SmallVec::new();
if let Some(funclet_bundle) = funclet_bundle {
bundles.push(funclet_bundle);
}

let call = unsafe {
llvm::LLVMBuildCallWithOperandBundles(
self.llbuilder,
llty,
llfn,
args.as_ptr() as *const &llvm::Value,
args.len() as c_uint,
bundles.as_ptr(),
bundles.len() as c_uint,
c"".as_ptr(),
)
};
call
}

fn with_scx(scx: &'a SimpleCx<'ll>) -> Self {
// Create a fresh builder from the simple context.
let llbuilder = unsafe { llvm::LLVMCreateBuilderInContext(scx.llcx) };
SBuilder { llbuilder, cx: scx }
}
}
impl<'a, 'll, CX: Borrow<SimpleCx<'ll>>> GenericBuilder<'a, 'll, CX> {
pub(crate) fn bitcast(&mut self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
unsafe { llvm::LLVMBuildBitCast(self.llbuilder, val, dest_ty, UNNAMED) }
}

fn ret_void(&mut self) {
unsafe {
llvm::LLVMBuildRetVoid(self.llbuilder);
}
}

fn ret(&mut self, v: &'ll Value) {
unsafe {
llvm::LLVMBuildRet(self.llbuilder, v);
}
}
}
impl<'a, 'll> SBuilder<'a, 'll> {
fn build(cx: &'a SimpleCx<'ll>, llbb: &'ll BasicBlock) -> SBuilder<'a, 'll> {
let bx = SBuilder::with_scx(cx);
unsafe {
llvm::LLVMPositionBuilderAtEnd(bx.llbuilder, llbb);
}
bx
}

fn check_call<'b>(
&mut self,
typ: &str,
fn_ty: &'ll Type,
llfn: &'ll Value,
args: &'b [&'ll Value],
) -> Cow<'b, [&'ll Value]> {
assert!(
self.cx.type_kind(fn_ty) == TypeKind::Function,
"builder::{typ} not passed a function, but {fn_ty:?}"
);

let param_tys = self.cx.func_params_types(fn_ty);

let all_args_match = iter::zip(&param_tys, args.iter().map(|&v| self.cx.val_ty(v)))
.all(|(expected_ty, actual_ty)| *expected_ty == actual_ty);

if all_args_match {
return Cow::Borrowed(args);
}

let casted_args: Vec<_> = iter::zip(param_tys, args)
.enumerate()
.map(|(i, (expected_ty, &actual_val))| {
let actual_ty = self.cx.val_ty(actual_val);
if expected_ty != actual_ty {
debug!(
"type mismatch in function call of {:?}. \
Expected {:?} for param {}, got {:?}; injecting bitcast",
llfn, expected_ty, i, actual_ty
);
self.bitcast(actual_val, expected_ty)
} else {
actual_val
}
})
.collect();

Cow::Owned(casted_args)
}
}

/// Empty string, to be used where LLVM expects an instruction name, indicating
/// that the instruction is to be left unnamed (i.e. numbered, in textual IR).
// FIXME(eddyb) pass `&CStr` directly to FFI once it's a thin pointer.
Expand Down Expand Up @@ -1222,6 +1330,14 @@ impl<'ll> StaticBuilderMethods for Builder<'_, 'll, '_> {
}

impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
fn build(cx: &'a CodegenCx<'ll, 'tcx>, llbb: &'ll BasicBlock) -> Builder<'a, 'll, 'tcx> {
let bx = Builder::with_cx(cx);
unsafe {
llvm::LLVMPositionBuilderAtEnd(bx.llbuilder, llbb);
}
bx
}

fn with_cx(cx: &'a CodegenCx<'ll, 'tcx>) -> Self {
// Create a fresh builder from the crate context.
let llbuilder = unsafe { llvm::LLVMCreateBuilderInContext(cx.llcx) };
Expand All @@ -1231,13 +1347,16 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
pub(crate) fn llfn(&self) -> &'ll Value {
unsafe { llvm::LLVMGetBasicBlockParent(self.llbb()) }
}
}

impl<'a, 'll, CX: Borrow<SimpleCx<'ll>>> GenericBuilder<'a, 'll, CX> {
fn position_at_start(&mut self, llbb: &'ll BasicBlock) {
unsafe {
llvm::LLVMRustPositionBuilderAtStart(self.llbuilder, llbb);
}
}

}
impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
fn align_metadata(&mut self, load: &'ll Value, align: Align) {
unsafe {
let md = [llvm::LLVMValueAsMetadata(self.cx.const_u64(align.bytes()))];
Expand All @@ -1259,7 +1378,8 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
self.set_metadata(inst, llvm::MD_unpredictable, md);
}
}

}
impl<'a, 'll, CX: Borrow<SimpleCx<'ll>>> GenericBuilder<'a, 'll, CX> {
pub(crate) fn minnum(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
unsafe { llvm::LLVMRustBuildMinNum(self.llbuilder, lhs, rhs) }
}
Expand Down Expand Up @@ -1360,7 +1480,9 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
let ret = unsafe { llvm::LLVMBuildCatchRet(self.llbuilder, funclet.cleanuppad(), unwind) };
ret.expect("LLVM does not have support for catchret")
}
}

impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
fn check_call<'b>(
&mut self,
typ: &str,
Expand Down Expand Up @@ -1401,11 +1523,13 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {

Cow::Owned(casted_args)
}

}
impl<'a, 'll, CX: Borrow<SimpleCx<'ll>>> GenericBuilder<'a, 'll, CX> {
pub(crate) fn va_arg(&mut self, list: &'ll Value, ty: &'ll Type) -> &'ll Value {
unsafe { llvm::LLVMBuildVAArg(self.llbuilder, list, ty, UNNAMED) }
}

}
impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
pub(crate) fn call_intrinsic(&mut self, intrinsic: &str, args: &[&'ll Value]) -> &'ll Value {
let (ty, f) = self.cx.get_intrinsic(intrinsic);
self.call(ty, None, None, f, args, None, None)
Expand All @@ -1423,7 +1547,8 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {

self.call_intrinsic(intrinsic, &[self.cx.const_u64(size), ptr]);
}

}
impl<'a, 'll, CX: Borrow<SimpleCx<'ll>>> GenericBuilder<'a, 'll, CX> {
pub(crate) fn phi(
&mut self,
ty: &'ll Type,
Expand All @@ -1443,7 +1568,8 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
llvm::LLVMAddIncoming(phi, &val, &bb, 1 as c_uint);
}
}

}
impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
fn fptoint_sat(&mut self, signed: bool, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
let src_ty = self.cx.val_ty(val);
let (float_ty, int_ty, vector_length) = if self.cx.type_kind(src_ty) == TypeKind::Vector {
Expand Down
25 changes: 11 additions & 14 deletions compiler/rustc_codegen_llvm/src/builder/autodiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@ use std::ptr;
use rustc_ast::expand::autodiff_attrs::{AutoDiffAttrs, AutoDiffItem, DiffActivity, DiffMode};
use rustc_codegen_ssa::ModuleCodegen;
use rustc_codegen_ssa::back::write::ModuleConfig;
use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, BuilderMethods};
use rustc_errors::FatalError;
use rustc_middle::ty::TyCtxt;
use rustc_session::config::Lto;
use tracing::{debug, trace};

use crate::back::write::{llvm_err, llvm_optimize};
use crate::builder::Builder;
use crate::declare::declare_raw_fn;
use crate::builder::SBuilder;
use crate::context::SimpleCx;
use crate::declare::declare_simple_fn;
use crate::errors::LlvmError;
use crate::llvm::AttributePlace::Function;
use crate::llvm::{Metadata, True};
use crate::value::Value;
use crate::{CodegenContext, LlvmCodegenBackend, ModuleLlvm, attributes, context, llvm};
use crate::{CodegenContext, LlvmCodegenBackend, ModuleLlvm, attributes, llvm};

fn get_params(fnc: &Value) -> Vec<&Value> {
unsafe {
Expand All @@ -38,8 +37,8 @@ fn get_params(fnc: &Value) -> Vec<&Value> {
/// [^1]: <https://enzyme.mit.edu/getting_started/CallingConvention/>
// FIXME(ZuseZ4): `outer_fn` should include upstream safety checks to
// cover some assumptions of enzyme/autodiff, which could lead to UB otherwise.
fn generate_enzyme_call<'ll, 'tcx>(
cx: &context::CodegenCx<'ll, 'tcx>,
fn generate_enzyme_call<'ll>(
cx: &SimpleCx<'ll>,
fn_to_diff: &'ll Value,
outer_fn: &'ll Value,
attrs: AutoDiffAttrs,
Expand Down Expand Up @@ -112,7 +111,7 @@ fn generate_enzyme_call<'ll, 'tcx>(
//FIXME(ZuseZ4): the CC/Addr/Vis values are best effort guesses, we should look at tests and
// think a bit more about what should go here.
let cc = llvm::LLVMGetFunctionCallConv(outer_fn);
let ad_fn = declare_raw_fn(
let ad_fn = declare_simple_fn(
cx,
&ad_name,
llvm::CallConv::try_from(cc).expect("invalid callconv"),
Expand All @@ -132,7 +131,7 @@ fn generate_enzyme_call<'ll, 'tcx>(
llvm::LLVMRustEraseInstFromParent(br);

let last_inst = llvm::LLVMRustGetLastInstruction(entry).unwrap();
let mut builder = Builder::build(cx, entry);
let mut builder = SBuilder::build(cx, entry);

let num_args = llvm::LLVMCountParams(&fn_to_diff);
let mut args = Vec::with_capacity(num_args as usize + 1);
Expand Down Expand Up @@ -236,7 +235,7 @@ fn generate_enzyme_call<'ll, 'tcx>(
}
}

let call = builder.call(enzyme_ty, None, None, ad_fn, &args, None, None);
let call = builder.call(enzyme_ty, ad_fn, &args, None);

// This part is a bit iffy. LLVM requires that a call to an inlineable function has some
// metadata attachted to it, but we just created this code oota. Given that the
Expand Down Expand Up @@ -274,10 +273,9 @@ fn generate_enzyme_call<'ll, 'tcx>(
}
}

pub(crate) fn differentiate<'ll, 'tcx>(
pub(crate) fn differentiate<'ll>(
module: &'ll ModuleCodegen<ModuleLlvm>,
cgcx: &CodegenContext<LlvmCodegenBackend>,
tcx: TyCtxt<'tcx>,
diff_items: Vec<AutoDiffItem>,
config: &ModuleConfig,
) -> Result<(), FatalError> {
Expand All @@ -286,8 +284,7 @@ pub(crate) fn differentiate<'ll, 'tcx>(
}

let diag_handler = cgcx.create_dcx();
let (_, cgus) = tcx.collect_and_partition_mono_items(());
let cx = context::CodegenCx::new(tcx, &cgus.first().unwrap(), &module.module_llvm);
let cx = SimpleCx { llmod: module.module_llvm.llmod(), llcx: module.module_llvm.llcx };

// Before dumping the module, we want all the TypeTrees to become part of the module.
for item in diff_items.iter() {
Expand Down
Loading
Loading