Skip to content
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

Improve opaque pointers support #86873

Merged
merged 4 commits into from
Jul 10, 2021
Merged

Improve opaque pointers support #86873

merged 4 commits into from
Jul 10, 2021

Conversation

nikic
Copy link
Contributor

@nikic nikic commented Jul 4, 2021

Opaque pointers are coming, and rustc is not ready.

This adds partial support by passing an explicit load type to LLVM. Two issues I've encountered:

  • The necessary type was not available at the point where non-temporal copies were generated. I've pushed the code for that upwards out of the memcpy implementation and moved the position of a cast to make do with the types we have available. (I'm not sure that cast is needed at all, but have retained it in the interest of conservativeness.)
  • The PlaceRef::project_deref() function used during debuginfo generation seems to be buggy in some way -- though I haven't figured out specifically what it does wrong. Replacing it with load_operand().deref() did the trick, but I don't really know what I'm doing here.

@rust-highfive
Copy link
Collaborator

r? @varkor

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 4, 2021
@nikic
Copy link
Contributor Author

nikic commented Jul 4, 2021

r? @nagisa

@rust-highfive rust-highfive assigned nagisa and unassigned varkor Jul 4, 2021
@nagisa
Copy link
Member

nagisa commented Jul 9, 2021

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 9, 2021
@bors
Copy link
Contributor

bors commented Jul 9, 2021

⌛ Trying commit c4d595890da5d8387accc188d707a2ffa5c5bf37 with merge e84cde51e33cced276b7f47049d33d6df462ec20...

@@ -403,15 +403,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
}

pub fn project_deref<Bx: BuilderMethods<'a, 'tcx, Value = V>>(&self, bx: &mut Bx) -> Self {
Copy link
Member

@nagisa nagisa Jul 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it was an optimisation to me. Added in #83941, which suggests that perhaps it has something to do with complexity? cc @wesleywiser do you remember why you created this method instead of the more straightforward load_operand().deref()?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm struggling to remember but I think I just didn't realize you could do that. From a quick glance, it seems to fine to me to replace this with load_operand().deref().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case I would perhaps explore inlining this method into its only use-site.

@bors
Copy link
Contributor

bors commented Jul 9, 2021

💔 Test failed - checks-actions

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 9, 2021
@rust-log-analyzer

This comment has been minimized.

@@ -486,7 +488,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
}
}
let llval = const_llval.unwrap_or_else(|| {
let load = self.load(place.llval, place.align);
let load = self.load(self.backend_type(place.layout), place.llval, place.align);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Since this is within LLVM specific code, I would probably call the more direct place.layout.llvm_type(self) here, as is done throughout the rest of this crate.

@@ -39,7 +39,7 @@ fn emit_direct_ptr_va_arg(
list.immediate()
};

let ptr = bx.load(va_list_addr, bx.tcx().data_layout.pointer_align.abi);
let ptr = bx.load(bx.type_i8p(), va_list_addr, bx.tcx().data_layout.pointer_align.abi);
Copy link
Member

@nagisa nagisa Jul 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps:

let va_list_ty = bx.type_i8p()
let va_list_ptr_ty = bx.type_ptr_to(va_list_ty);
// <snip>
let ptr = bx.load(va_list_ty, va_list_addr, bx.tcx().data_layout.pointer_align.abi);

@@ -287,8 +287,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
llval
}
};
let addr = bx.pointercast(llslot, bx.type_ptr_to(bx.cast_backend_type(&cast_ty)));
bx.load(addr, self.fn_abi.ret.layout.align.abi)
let llty = bx.cast_backend_type(&cast_ty);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessarily a llvm type . Perhaps just ty? (though we call vals llval still...)

@nagisa
Copy link
Member

nagisa commented Jul 9, 2021

Broadly speaking this seems good, but I imagine we'll need a similar change for stores too, and later down the line geps, etc?

nikic added 4 commits July 9, 2021 22:00
Instead of determining it from the pointer type, explicitly pass
the type to load.
This makes load generation compatible with opaque pointers.

The generation of nontemporal copies still accesses the pointer
element type, as fixing this requires more movement.
I'm not really sure what is wrong here, but I was getting load
type mismatches in the debuginfo code (which is the only place
using this function).

Replacing the project_deref() implementation with a generic
load_operand + deref did the trick.
Simply shift the bitcast from the store to the load, so that
we can use the destination type. I'm not sure the bitcast is
really necessary, but keeping it for now.
@nikic
Copy link
Contributor Author

nikic commented Jul 9, 2021

Broadly speaking this seems good, but I imagine we'll need a similar change for stores too, and later down the line geps, etc?

It's not needed for stores (because the value type is available through the value operand), but will have to be done for GEPs and calls.

@nikic
Copy link
Contributor Author

nikic commented Jul 9, 2021

@bors try @rust-timer queue

Should work after the rebase...

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@bors
Copy link
Contributor

bors commented Jul 9, 2021

⌛ Trying commit 2ce1add with merge 66df3dd988767179a593e0afd748a4eee48991ac...

@bors
Copy link
Contributor

bors commented Jul 9, 2021

☀️ Try build successful - checks-actions
Build commit: 66df3dd988767179a593e0afd748a4eee48991ac (66df3dd988767179a593e0afd748a4eee48991ac)

@rust-timer
Copy link
Collaborator

Queued 66df3dd988767179a593e0afd748a4eee48991ac with parent 3eff244, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (66df3dd988767179a593e0afd748a4eee48991ac): comparison url.

Summary: This benchmark run did not return any significant changes.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jul 10, 2021
@nagisa
Copy link
Member

nagisa commented Jul 10, 2021

@bors r+ Nice!

@bors
Copy link
Contributor

bors commented Jul 10, 2021

📌 Commit 2ce1add has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 10, 2021
@bors
Copy link
Contributor

bors commented Jul 10, 2021

⌛ Testing commit 2ce1add with merge a4d6c8b00efab9c22f0a7c3b84e05056c948c1cb...

@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@bors
Copy link
Contributor

bors commented Jul 10, 2021

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 10, 2021
@nagisa
Copy link
Member

nagisa commented Jul 10, 2021

@bors retry looks like a spurious infrastructure failure.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 10, 2021
@bors
Copy link
Contributor

bors commented Jul 10, 2021

⌛ Testing commit 2ce1add with merge 432e145...

@bors
Copy link
Contributor

bors commented Jul 10, 2021

☀️ Test successful - checks-actions
Approved by: nagisa
Pushing 432e145 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 10, 2021
@bors bors merged commit 432e145 into rust-lang:master Jul 10, 2021
@rustbot rustbot added this to the 1.55.0 milestone Jul 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants