Skip to content

Commit da569fa

Browse files
committed
Auto merge of #47209 - eddyb:ccx, r=nikomatsakis
rustc_trans: reorganize CrateContext and rename context types. Firstly, the `{Shared,Local}CrateContext` hasn't been meaningful for a while now, and this PR resolves it by moving all their fields to `CrateContext` and removing redundant accessor methods. Secondly, this PR contains the following mass-renames: * `ccx: CrateContext` -> `cx: CodegenCx` * `mircx: MirContext` -> `fx: FunctionCx` * `bcx: Builder` -> `bx: Builder` r? @nikomatsakis
2 parents 79a521b + 4e40a0d commit da569fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2137
-2371
lines changed

src/librustc_llvm/ffi.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,6 @@ extern "C" {
16611661
pub fn LLVMRustArchiveMemberFree(Member: RustArchiveMemberRef);
16621662

16631663
pub fn LLVMRustSetDataLayoutFromTargetMachine(M: ModuleRef, TM: TargetMachineRef);
1664-
pub fn LLVMRustGetModuleDataLayout(M: ModuleRef) -> TargetDataRef;
16651664

16661665
pub fn LLVMRustBuildOperandBundleDef(Name: *const c_char,
16671666
Inputs: *const ValueRef,

src/librustc_trans/abi.rs

+104-104
Large diffs are not rendered by default.

src/librustc_trans/asm.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use libc::{c_uint, c_char};
2727

2828
// Take an inline assembly expression and splat it out via LLVM
2929
pub fn trans_inline_asm<'a, 'tcx>(
30-
bcx: &Builder<'a, 'tcx>,
30+
bx: &Builder<'a, 'tcx>,
3131
ia: &hir::InlineAsm,
3232
outputs: Vec<PlaceRef<'tcx>>,
3333
mut inputs: Vec<ValueRef>
@@ -39,13 +39,13 @@ pub fn trans_inline_asm<'a, 'tcx>(
3939
let mut indirect_outputs = vec![];
4040
for (i, (out, place)) in ia.outputs.iter().zip(&outputs).enumerate() {
4141
if out.is_rw {
42-
inputs.push(place.load(bcx).immediate());
42+
inputs.push(place.load(bx).immediate());
4343
ext_constraints.push(i.to_string());
4444
}
4545
if out.is_indirect {
46-
indirect_outputs.push(place.load(bcx).immediate());
46+
indirect_outputs.push(place.load(bx).immediate());
4747
} else {
48-
output_types.push(place.layout.llvm_type(bcx.ccx));
48+
output_types.push(place.layout.llvm_type(bx.cx));
4949
}
5050
}
5151
if !indirect_outputs.is_empty() {
@@ -58,7 +58,7 @@ pub fn trans_inline_asm<'a, 'tcx>(
5858

5959
// Default per-arch clobbers
6060
// Basically what clang does
61-
let arch_clobbers = match &bcx.sess().target.target.arch[..] {
61+
let arch_clobbers = match &bx.sess().target.target.arch[..] {
6262
"x86" | "x86_64" => vec!["~{dirflag}", "~{fpsr}", "~{flags}"],
6363
_ => Vec::new()
6464
};
@@ -76,9 +76,9 @@ pub fn trans_inline_asm<'a, 'tcx>(
7676
// Depending on how many outputs we have, the return type is different
7777
let num_outputs = output_types.len();
7878
let output_type = match num_outputs {
79-
0 => Type::void(bcx.ccx),
79+
0 => Type::void(bx.cx),
8080
1 => output_types[0],
81-
_ => Type::struct_(bcx.ccx, &output_types, false)
81+
_ => Type::struct_(bx.cx, &output_types, false)
8282
};
8383

8484
let dialect = match ia.dialect {
@@ -88,7 +88,7 @@ pub fn trans_inline_asm<'a, 'tcx>(
8888

8989
let asm = CString::new(ia.asm.as_str().as_bytes()).unwrap();
9090
let constraint_cstr = CString::new(all_constraints).unwrap();
91-
let r = bcx.inline_asm_call(
91+
let r = bx.inline_asm_call(
9292
asm.as_ptr(),
9393
constraint_cstr.as_ptr(),
9494
&inputs,
@@ -101,28 +101,28 @@ pub fn trans_inline_asm<'a, 'tcx>(
101101
// Again, based on how many outputs we have
102102
let outputs = ia.outputs.iter().zip(&outputs).filter(|&(ref o, _)| !o.is_indirect);
103103
for (i, (_, &place)) in outputs.enumerate() {
104-
let v = if num_outputs == 1 { r } else { bcx.extract_value(r, i as u64) };
105-
OperandValue::Immediate(v).store(bcx, place);
104+
let v = if num_outputs == 1 { r } else { bx.extract_value(r, i as u64) };
105+
OperandValue::Immediate(v).store(bx, place);
106106
}
107107

108108
// Store mark in a metadata node so we can map LLVM errors
109109
// back to source locations. See #17552.
110110
unsafe {
111111
let key = "srcloc";
112-
let kind = llvm::LLVMGetMDKindIDInContext(bcx.ccx.llcx(),
112+
let kind = llvm::LLVMGetMDKindIDInContext(bx.cx.llcx,
113113
key.as_ptr() as *const c_char, key.len() as c_uint);
114114

115-
let val: llvm::ValueRef = C_i32(bcx.ccx, ia.ctxt.outer().as_u32() as i32);
115+
let val: llvm::ValueRef = C_i32(bx.cx, ia.ctxt.outer().as_u32() as i32);
116116

117117
llvm::LLVMSetMetadata(r, kind,
118-
llvm::LLVMMDNodeInContext(bcx.ccx.llcx(), &val, 1));
118+
llvm::LLVMMDNodeInContext(bx.cx.llcx, &val, 1));
119119
}
120120
}
121121

122-
pub fn trans_global_asm<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
122+
pub fn trans_global_asm<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
123123
ga: &hir::GlobalAsm) {
124124
let asm = CString::new(ga.asm.as_str().as_bytes()).unwrap();
125125
unsafe {
126-
llvm::LLVMRustAppendModuleInlineAsm(ccx.llmod(), asm.as_ptr());
126+
llvm::LLVMRustAppendModuleInlineAsm(cx.llmod, asm.as_ptr());
127127
}
128128
}

src/librustc_trans/attributes.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use llvm::AttributePlace::Function;
2424
use llvm_util;
2525
pub use syntax::attr::{self, InlineAttr};
2626
use syntax::ast;
27-
use context::CrateContext;
27+
use context::CodegenCx;
2828

2929
/// Mark LLVM function to use provided inline heuristic.
3030
#[inline]
@@ -67,27 +67,27 @@ pub fn naked(val: ValueRef, is_naked: bool) {
6767
Attribute::Naked.toggle_llfn(Function, val, is_naked);
6868
}
6969

70-
pub fn set_frame_pointer_elimination(ccx: &CrateContext, llfn: ValueRef) {
70+
pub fn set_frame_pointer_elimination(cx: &CodegenCx, llfn: ValueRef) {
7171
// FIXME: #11906: Omitting frame pointers breaks retrieving the value of a
7272
// parameter.
73-
if ccx.sess().must_not_eliminate_frame_pointers() {
73+
if cx.sess().must_not_eliminate_frame_pointers() {
7474
llvm::AddFunctionAttrStringValue(
7575
llfn, llvm::AttributePlace::Function,
7676
cstr("no-frame-pointer-elim\0"), cstr("true\0"));
7777
}
7878
}
7979

80-
pub fn set_probestack(ccx: &CrateContext, llfn: ValueRef) {
80+
pub fn set_probestack(cx: &CodegenCx, llfn: ValueRef) {
8181
// Only use stack probes if the target specification indicates that we
8282
// should be using stack probes
83-
if !ccx.sess().target.target.options.stack_probes {
83+
if !cx.sess().target.target.options.stack_probes {
8484
return
8585
}
8686

8787
// Currently stack probes seem somewhat incompatible with the address
8888
// sanitizer. With asan we're already protected from stack overflow anyway
8989
// so we don't really need stack probes regardless.
90-
match ccx.sess().opts.debugging_opts.sanitizer {
90+
match cx.sess().opts.debugging_opts.sanitizer {
9191
Some(Sanitizer::Address) => return,
9292
_ => {}
9393
}
@@ -101,13 +101,13 @@ pub fn set_probestack(ccx: &CrateContext, llfn: ValueRef) {
101101

102102
/// Composite function which sets LLVM attributes for function depending on its AST (#[attribute])
103103
/// attributes.
104-
pub fn from_fn_attrs(ccx: &CrateContext, llfn: ValueRef, id: DefId) {
104+
pub fn from_fn_attrs(cx: &CodegenCx, llfn: ValueRef, id: DefId) {
105105
use syntax::attr::*;
106-
let attrs = ccx.tcx().get_attrs(id);
107-
inline(llfn, find_inline_attr(Some(ccx.sess().diagnostic()), &attrs));
106+
let attrs = cx.tcx.get_attrs(id);
107+
inline(llfn, find_inline_attr(Some(cx.sess().diagnostic()), &attrs));
108108

109-
set_frame_pointer_elimination(ccx, llfn);
110-
set_probestack(ccx, llfn);
109+
set_frame_pointer_elimination(cx, llfn);
110+
set_probestack(cx, llfn);
111111

112112
for attr in attrs.iter() {
113113
if attr.check_name("cold") {
@@ -124,7 +124,7 @@ pub fn from_fn_attrs(ccx: &CrateContext, llfn: ValueRef, id: DefId) {
124124
}
125125
}
126126

127-
let target_features = ccx.tcx().target_features_enabled(id);
127+
let target_features = cx.tcx.target_features_enabled(id);
128128
if !target_features.is_empty() {
129129
let val = CString::new(target_features.join(",")).unwrap();
130130
llvm::AddFunctionAttrStringValue(

0 commit comments

Comments
 (0)