-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Labels
A-incr-compArea: Incremental compilationArea: Incremental compilationC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-compiletimeIssue: Problems and improvements with respect to compile times.Issue: Problems and improvements with respect to compile times.
Description
There are a few attributes, like #[inline], #[cold], and #[target_feature], that would profit from being turned into a query:
- directly accessing the
ast::Attributewill lead to a dependency edge to HIR which is brittle because of spans, - at least #[inline] is searched for a few times, so caching might be good.
The attributes in question are listed in trans::attributes::from_fn_attrs():
rust/src/librustc_trans/attributes.rs
Lines 97 to 132 in 27ede55
| pub fn from_fn_attrs(ccx: &CrateContext, attrs: &[ast::Attribute], llfn: ValueRef) { | |
| use syntax::attr::*; | |
| inline(llfn, find_inline_attr(Some(ccx.sess().diagnostic()), attrs)); | |
| set_frame_pointer_elimination(ccx, llfn); | |
| set_probestack(ccx, llfn); | |
| let mut target_features = vec![]; | |
| for attr in attrs { | |
| if attr.check_name("target_feature") { | |
| if let Some(val) = attr.value_str() { | |
| for feat in val.as_str().split(",").map(|f| f.trim()) { | |
| if !feat.is_empty() && !feat.contains('\0') { | |
| target_features.push(feat.to_string()); | |
| } | |
| } | |
| } | |
| } else if attr.check_name("cold") { | |
| Attribute::Cold.apply_llfn(Function, llfn); | |
| } else if attr.check_name("naked") { | |
| naked(llfn, true); | |
| } else if attr.check_name("allocator") { | |
| Attribute::NoAlias.apply_llfn( | |
| llvm::AttributePlace::ReturnValue, llfn); | |
| } else if attr.check_name("unwind") { | |
| unwind(llfn, true); | |
| } else if attr.check_name("rustc_allocator_nounwind") { | |
| unwind(llfn, false); | |
| } | |
| } | |
| if !target_features.is_empty() { | |
| let val = CString::new(target_features.join(",")).unwrap(); | |
| llvm::AddFunctionAttrStringValue( | |
| llfn, llvm::AttributePlace::Function, | |
| cstr("target-features\0"), &val); | |
| } | |
| } |
A query could return a TransFnAttrs value that looks like:
struct TransFnAttrs {
inline: InlineAttr, // from syntax::attr
flags: TransFnAttrFlags,
target_features: Symbol,
}
bitflags! {
pub struct TransFnAttrFlags: u8 {
const COLD = 0b0000_0001;
const ALLOCATOR = 0b0000_0010;
const UNWIND = 0b0000_0100;
const RUSTC_ALLOCATOR_NOUNWIND = 0b0000_1000;
const NAKED = 0b0001_0000;
}
}The syntax::attr::{find_inline_attr, requests_inline} should be replaced by this new query then.
The ultimate goal of this refactoring is to reduce the number of false positives during incr. comp. cache invalidation by providing a "firewall" between HIR and the compile_codegen_unit query.
hanna-kruppe
Metadata
Metadata
Assignees
Labels
A-incr-compArea: Incremental compilationArea: Incremental compilationC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-compiletimeIssue: Problems and improvements with respect to compile times.Issue: Problems and improvements with respect to compile times.