Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 66f5bf1

Browse files
committed
extract rustc::middle::codegen_fn_attrs
1 parent c19ed3b commit 66f5bf1

File tree

19 files changed

+151
-149
lines changed

19 files changed

+151
-149
lines changed

src/librustc/hir/mod.rs

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pub use self::UnsafeSource::*;
1010

1111
use crate::hir::def::{DefKind, Res};
1212
use crate::hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
13-
use crate::mir::mono::Linkage;
1413
use crate::ty::query::Providers;
1514
use crate::util::nodemap::{FxHashSet, NodeMap};
1615

@@ -29,7 +28,6 @@ use syntax::ast::{self, AsmDialect, CrateSugar, Ident, Name, NodeId};
2928
use syntax::ast::{AttrVec, Attribute, FloatTy, IntTy, Label, LitKind, StrStyle, UintTy};
3029
pub use syntax::ast::{BorrowKind, ImplPolarity, IsAuto};
3130
pub use syntax::ast::{CaptureBy, Constness, Movability, Mutability, Unsafety};
32-
use syntax::attr::{InlineAttr, OptimizeAttr};
3331
use syntax::tokenstream::TokenStream;
3432
use syntax::util::parser::ExprPrecedence;
3533

@@ -2668,119 +2666,6 @@ pub fn provide(providers: &mut Providers<'_>) {
26682666
upvars::provide(providers);
26692667
}
26702668

2671-
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
2672-
pub struct CodegenFnAttrs {
2673-
pub flags: CodegenFnAttrFlags,
2674-
/// Parsed representation of the `#[inline]` attribute
2675-
pub inline: InlineAttr,
2676-
/// Parsed representation of the `#[optimize]` attribute
2677-
pub optimize: OptimizeAttr,
2678-
/// The `#[export_name = "..."]` attribute, indicating a custom symbol a
2679-
/// function should be exported under
2680-
pub export_name: Option<Symbol>,
2681-
/// The `#[link_name = "..."]` attribute, indicating a custom symbol an
2682-
/// imported function should be imported as. Note that `export_name`
2683-
/// probably isn't set when this is set, this is for foreign items while
2684-
/// `#[export_name]` is for Rust-defined functions.
2685-
pub link_name: Option<Symbol>,
2686-
/// The `#[link_ordinal = "..."]` attribute, indicating an ordinal an
2687-
/// imported function has in the dynamic library. Note that this must not
2688-
/// be set when `link_name` is set. This is for foreign items with the
2689-
/// "raw-dylib" kind.
2690-
pub link_ordinal: Option<usize>,
2691-
/// The `#[target_feature(enable = "...")]` attribute and the enabled
2692-
/// features (only enabled features are supported right now).
2693-
pub target_features: Vec<Symbol>,
2694-
/// The `#[linkage = "..."]` attribute and the value we found.
2695-
pub linkage: Option<Linkage>,
2696-
/// The `#[link_section = "..."]` attribute, or what executable section this
2697-
/// should be placed in.
2698-
pub link_section: Option<Symbol>,
2699-
}
2700-
2701-
bitflags! {
2702-
#[derive(RustcEncodable, RustcDecodable, HashStable)]
2703-
pub struct CodegenFnAttrFlags: u32 {
2704-
/// `#[cold]`: a hint to LLVM that this function, when called, is never on
2705-
/// the hot path.
2706-
const COLD = 1 << 0;
2707-
/// `#[rustc_allocator]`: a hint to LLVM that the pointer returned from this
2708-
/// function is never null.
2709-
const ALLOCATOR = 1 << 1;
2710-
/// `#[unwind]`: an indicator that this function may unwind despite what
2711-
/// its ABI signature may otherwise imply.
2712-
const UNWIND = 1 << 2;
2713-
/// `#[rust_allocator_nounwind]`, an indicator that an imported FFI
2714-
/// function will never unwind. Probably obsolete by recent changes with
2715-
/// #[unwind], but hasn't been removed/migrated yet
2716-
const RUSTC_ALLOCATOR_NOUNWIND = 1 << 3;
2717-
/// `#[naked]`: an indicator to LLVM that no function prologue/epilogue
2718-
/// should be generated.
2719-
const NAKED = 1 << 4;
2720-
/// `#[no_mangle]`: an indicator that the function's name should be the same
2721-
/// as its symbol.
2722-
const NO_MANGLE = 1 << 5;
2723-
/// `#[rustc_std_internal_symbol]`: an indicator that this symbol is a
2724-
/// "weird symbol" for the standard library in that it has slightly
2725-
/// different linkage, visibility, and reachability rules.
2726-
const RUSTC_STD_INTERNAL_SYMBOL = 1 << 6;
2727-
/// `#[no_debug]`: an indicator that no debugging information should be
2728-
/// generated for this function by LLVM.
2729-
const NO_DEBUG = 1 << 7;
2730-
/// `#[thread_local]`: indicates a static is actually a thread local
2731-
/// piece of memory
2732-
const THREAD_LOCAL = 1 << 8;
2733-
/// `#[used]`: indicates that LLVM can't eliminate this function (but the
2734-
/// linker can!).
2735-
const USED = 1 << 9;
2736-
/// `#[ffi_returns_twice]`, indicates that an extern function can return
2737-
/// multiple times
2738-
const FFI_RETURNS_TWICE = 1 << 10;
2739-
/// `#[track_caller]`: allow access to the caller location
2740-
const TRACK_CALLER = 1 << 11;
2741-
}
2742-
}
2743-
2744-
impl CodegenFnAttrs {
2745-
pub fn new() -> CodegenFnAttrs {
2746-
CodegenFnAttrs {
2747-
flags: CodegenFnAttrFlags::empty(),
2748-
inline: InlineAttr::None,
2749-
optimize: OptimizeAttr::None,
2750-
export_name: None,
2751-
link_name: None,
2752-
link_ordinal: None,
2753-
target_features: vec![],
2754-
linkage: None,
2755-
link_section: None,
2756-
}
2757-
}
2758-
2759-
/// Returns `true` if `#[inline]` or `#[inline(always)]` is present.
2760-
pub fn requests_inline(&self) -> bool {
2761-
match self.inline {
2762-
InlineAttr::Hint | InlineAttr::Always => true,
2763-
InlineAttr::None | InlineAttr::Never => false,
2764-
}
2765-
}
2766-
2767-
/// Returns `true` if it looks like this symbol needs to be exported, for example:
2768-
///
2769-
/// * `#[no_mangle]` is present
2770-
/// * `#[export_name(...)]` is present
2771-
/// * `#[linkage]` is present
2772-
pub fn contains_extern_indicator(&self) -> bool {
2773-
self.flags.contains(CodegenFnAttrFlags::NO_MANGLE)
2774-
|| self.export_name.is_some()
2775-
|| match self.linkage {
2776-
// These are private, so make sure we don't try to consider
2777-
// them external.
2778-
None | Some(Linkage::Internal) | Some(Linkage::Private) => false,
2779-
Some(_) => true,
2780-
}
2781-
}
2782-
}
2783-
27842669
#[derive(Copy, Clone, Debug)]
27852670
pub enum Node<'hir> {
27862671
Param(&'hir Param<'hir>),
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
use crate::mir::mono::Linkage;
2+
use rustc_span::symbol::Symbol;
3+
use syntax::attr::{InlineAttr, OptimizeAttr};
4+
5+
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
6+
pub struct CodegenFnAttrs {
7+
pub flags: CodegenFnAttrFlags,
8+
/// Parsed representation of the `#[inline]` attribute
9+
pub inline: InlineAttr,
10+
/// Parsed representation of the `#[optimize]` attribute
11+
pub optimize: OptimizeAttr,
12+
/// The `#[export_name = "..."]` attribute, indicating a custom symbol a
13+
/// function should be exported under
14+
pub export_name: Option<Symbol>,
15+
/// The `#[link_name = "..."]` attribute, indicating a custom symbol an
16+
/// imported function should be imported as. Note that `export_name`
17+
/// probably isn't set when this is set, this is for foreign items while
18+
/// `#[export_name]` is for Rust-defined functions.
19+
pub link_name: Option<Symbol>,
20+
/// The `#[link_ordinal = "..."]` attribute, indicating an ordinal an
21+
/// imported function has in the dynamic library. Note that this must not
22+
/// be set when `link_name` is set. This is for foreign items with the
23+
/// "raw-dylib" kind.
24+
pub link_ordinal: Option<usize>,
25+
/// The `#[target_feature(enable = "...")]` attribute and the enabled
26+
/// features (only enabled features are supported right now).
27+
pub target_features: Vec<Symbol>,
28+
/// The `#[linkage = "..."]` attribute and the value we found.
29+
pub linkage: Option<Linkage>,
30+
/// The `#[link_section = "..."]` attribute, or what executable section this
31+
/// should be placed in.
32+
pub link_section: Option<Symbol>,
33+
}
34+
35+
bitflags! {
36+
#[derive(RustcEncodable, RustcDecodable, HashStable)]
37+
pub struct CodegenFnAttrFlags: u32 {
38+
/// `#[cold]`: a hint to LLVM that this function, when called, is never on
39+
/// the hot path.
40+
const COLD = 1 << 0;
41+
/// `#[rustc_allocator]`: a hint to LLVM that the pointer returned from this
42+
/// function is never null.
43+
const ALLOCATOR = 1 << 1;
44+
/// `#[unwind]`: an indicator that this function may unwind despite what
45+
/// its ABI signature may otherwise imply.
46+
const UNWIND = 1 << 2;
47+
/// `#[rust_allocator_nounwind]`, an indicator that an imported FFI
48+
/// function will never unwind. Probably obsolete by recent changes with
49+
/// #[unwind], but hasn't been removed/migrated yet
50+
const RUSTC_ALLOCATOR_NOUNWIND = 1 << 3;
51+
/// `#[naked]`: an indicator to LLVM that no function prologue/epilogue
52+
/// should be generated.
53+
const NAKED = 1 << 4;
54+
/// `#[no_mangle]`: an indicator that the function's name should be the same
55+
/// as its symbol.
56+
const NO_MANGLE = 1 << 5;
57+
/// `#[rustc_std_internal_symbol]`: an indicator that this symbol is a
58+
/// "weird symbol" for the standard library in that it has slightly
59+
/// different linkage, visibility, and reachability rules.
60+
const RUSTC_STD_INTERNAL_SYMBOL = 1 << 6;
61+
/// `#[no_debug]`: an indicator that no debugging information should be
62+
/// generated for this function by LLVM.
63+
const NO_DEBUG = 1 << 7;
64+
/// `#[thread_local]`: indicates a static is actually a thread local
65+
/// piece of memory
66+
const THREAD_LOCAL = 1 << 8;
67+
/// `#[used]`: indicates that LLVM can't eliminate this function (but the
68+
/// linker can!).
69+
const USED = 1 << 9;
70+
/// `#[ffi_returns_twice]`, indicates that an extern function can return
71+
/// multiple times
72+
const FFI_RETURNS_TWICE = 1 << 10;
73+
/// `#[track_caller]`: allow access to the caller location
74+
const TRACK_CALLER = 1 << 11;
75+
}
76+
}
77+
78+
impl CodegenFnAttrs {
79+
pub fn new() -> CodegenFnAttrs {
80+
CodegenFnAttrs {
81+
flags: CodegenFnAttrFlags::empty(),
82+
inline: InlineAttr::None,
83+
optimize: OptimizeAttr::None,
84+
export_name: None,
85+
link_name: None,
86+
link_ordinal: None,
87+
target_features: vec![],
88+
linkage: None,
89+
link_section: None,
90+
}
91+
}
92+
93+
/// Returns `true` if `#[inline]` or `#[inline(always)]` is present.
94+
pub fn requests_inline(&self) -> bool {
95+
match self.inline {
96+
InlineAttr::Hint | InlineAttr::Always => true,
97+
InlineAttr::None | InlineAttr::Never => false,
98+
}
99+
}
100+
101+
/// Returns `true` if it looks like this symbol needs to be exported, for example:
102+
///
103+
/// * `#[no_mangle]` is present
104+
/// * `#[export_name(...)]` is present
105+
/// * `#[linkage]` is present
106+
pub fn contains_extern_indicator(&self) -> bool {
107+
self.flags.contains(CodegenFnAttrFlags::NO_MANGLE)
108+
|| self.export_name.is_some()
109+
|| match self.linkage {
110+
// These are private, so make sure we don't try to consider
111+
// them external.
112+
None | Some(Linkage::Internal) | Some(Linkage::Private) => false,
113+
Some(_) => true,
114+
}
115+
}
116+
}

src/librustc/middle/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod codegen_fn_attrs;
12
pub mod cstore;
23
pub mod dependency_format;
34
pub mod exported_symbols;

src/librustc/ty/instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::hir::def::Namespace;
22
use crate::hir::def_id::DefId;
3-
use crate::hir::CodegenFnAttrFlags;
3+
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
44
use crate::middle::lang_items::DropInPlaceFnLangItem;
55
use crate::traits;
66
use crate::ty::print::{FmtPrinter, Printer};

src/librustc/ty/query/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use crate::dep_graph::{self, DepNode};
22
use crate::hir::def::{DefKind, Export};
33
use crate::hir::def_id::{CrateNum, DefId, DefIndex};
4-
use crate::hir::{self, CodegenFnAttrs, ItemLocalId, TraitCandidate};
4+
use crate::hir::{self, ItemLocalId, TraitCandidate};
55
use crate::infer::canonical::{self, Canonical};
66
use crate::lint;
7+
use crate::middle::codegen_fn_attrs::CodegenFnAttrs;
78
use crate::middle::cstore::{CrateSource, DepKind, NativeLibraryKind};
89
use crate::middle::cstore::{ExternCrate, ForeignModule, LinkagePreference, NativeLibrary};
910
use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};

src/librustc_codegen_llvm/attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::ffi::CString;
44

55
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
6-
use rustc::hir::CodegenFnAttrFlags;
6+
use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags;
77
use rustc::session::config::{OptLevel, Sanitizer};
88
use rustc::session::Session;
99
use rustc::ty::layout::HasTyCtxt;

src/librustc_codegen_llvm/base.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,32 @@
1414
//! int)` and `rec(x=int, y=int, z=int)` will have the same `llvm::Type`.
1515
1616
use super::{LlvmCodegenBackend, ModuleLlvm};
17-
use rustc_codegen_ssa::base::maybe_create_entry_wrapper;
18-
use rustc_codegen_ssa::{ModuleCodegen, ModuleKind};
1917

2018
use crate::builder::Builder;
2119
use crate::common;
2220
use crate::context::CodegenCx;
2321
use crate::llvm;
2422
use crate::metadata;
23+
use crate::value::Value;
24+
2525
use rustc::dep_graph;
26+
use rustc::middle::codegen_fn_attrs::CodegenFnAttrs;
2627
use rustc::middle::cstore::EncodedMetadata;
2728
use rustc::middle::exported_symbols;
2829
use rustc::mir::mono::{Linkage, Visibility};
2930
use rustc::session::config::DebugInfo;
3031
use rustc::ty::TyCtxt;
31-
use rustc_codegen_ssa::mono_item::MonoItemExt;
32-
use rustc_data_structures::small_c_str::SmallCStr;
33-
3432
use rustc_codegen_ssa::back::write::submit_codegened_module_to_llvm;
33+
use rustc_codegen_ssa::base::maybe_create_entry_wrapper;
34+
use rustc_codegen_ssa::mono_item::MonoItemExt;
3535
use rustc_codegen_ssa::traits::*;
36-
37-
use rustc::hir::CodegenFnAttrs;
36+
use rustc_codegen_ssa::{ModuleCodegen, ModuleKind};
37+
use rustc_data_structures::small_c_str::SmallCStr;
3838
use rustc_span::symbol::Symbol;
39+
3940
use std::ffi::CString;
4041
use std::time::Instant;
4142

42-
use crate::value::Value;
43-
4443
pub fn write_compressed_metadata<'tcx>(
4544
tcx: TyCtxt<'tcx>,
4645
metadata: &EncodedMetadata,

src/librustc_codegen_llvm/consts.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,18 @@ use crate::value::Value;
88
use libc::c_uint;
99
use log::debug;
1010
use rustc::hir::def_id::DefId;
11-
use rustc::hir::Node;
11+
use rustc::hir::{self, Node};
12+
use rustc::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
1213
use rustc::mir::interpret::{read_target_uint, Allocation, ConstValue, ErrorHandled, Pointer};
1314
use rustc::mir::mono::MonoItem;
15+
use rustc::ty::layout::{self, Align, LayoutOf, Size};
1416
use rustc::ty::{self, Instance, Ty};
1517
use rustc::{bug, span_bug};
1618
use rustc_codegen_ssa::traits::*;
1719
use rustc_span::symbol::{sym, Symbol};
1820
use rustc_span::Span;
1921
use rustc_target::abi::HasDataLayout;
2022

21-
use rustc::ty::layout::{self, Align, LayoutOf, Size};
22-
23-
use rustc::hir::{self, CodegenFnAttrFlags, CodegenFnAttrs};
24-
2523
use std::ffi::CStr;
2624

2725
pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll Value {

src/librustc_codegen_llvm/debuginfo/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use crate::value::Value;
2222
use log::debug;
2323
use rustc::hir::def::CtorKind;
2424
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
25-
use rustc::hir::CodegenFnAttrFlags;
2625
use rustc::ich::NodeIdHashingMode;
26+
use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags;
2727
use rustc::mir::interpret::truncate;
2828
use rustc::mir::{self, Field, GeneratorLayout};
2929
use rustc::session::config::{self, DebugInfo};

src/librustc_codegen_llvm/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::llvm::debuginfo::{
1414
DIArray, DIBuilder, DIFile, DIFlags, DILexicalBlock, DISPFlags, DIScope, DIType,
1515
};
1616
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
17-
use rustc::hir::CodegenFnAttrFlags;
17+
use rustc::middle::codegen_fn_attrs::CodegenFnAttrFlags;
1818
use rustc::ty::subst::{GenericArgKind, SubstsRef};
1919

2020
use crate::abi::FnAbi;

0 commit comments

Comments
 (0)