Skip to content

Commit

Permalink
Auto merge of #47209 - eddyb:ccx, r=nikomatsakis
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jan 16, 2018
2 parents 79a521b + 4e40a0d commit da569fa
Show file tree
Hide file tree
Showing 47 changed files with 2,137 additions and 2,371 deletions.
1 change: 0 additions & 1 deletion src/librustc_llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1661,7 +1661,6 @@ extern "C" {
pub fn LLVMRustArchiveMemberFree(Member: RustArchiveMemberRef);

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

pub fn LLVMRustBuildOperandBundleDef(Name: *const c_char,
Inputs: *const ValueRef,
Expand Down
208 changes: 104 additions & 104 deletions src/librustc_trans/abi.rs

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions src/librustc_trans/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use libc::{c_uint, c_char};

// Take an inline assembly expression and splat it out via LLVM
pub fn trans_inline_asm<'a, 'tcx>(
bcx: &Builder<'a, 'tcx>,
bx: &Builder<'a, 'tcx>,
ia: &hir::InlineAsm,
outputs: Vec<PlaceRef<'tcx>>,
mut inputs: Vec<ValueRef>
Expand All @@ -39,13 +39,13 @@ pub fn trans_inline_asm<'a, 'tcx>(
let mut indirect_outputs = vec![];
for (i, (out, place)) in ia.outputs.iter().zip(&outputs).enumerate() {
if out.is_rw {
inputs.push(place.load(bcx).immediate());
inputs.push(place.load(bx).immediate());
ext_constraints.push(i.to_string());
}
if out.is_indirect {
indirect_outputs.push(place.load(bcx).immediate());
indirect_outputs.push(place.load(bx).immediate());
} else {
output_types.push(place.layout.llvm_type(bcx.ccx));
output_types.push(place.layout.llvm_type(bx.cx));
}
}
if !indirect_outputs.is_empty() {
Expand All @@ -58,7 +58,7 @@ pub fn trans_inline_asm<'a, 'tcx>(

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

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

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

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

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

llvm::LLVMSetMetadata(r, kind,
llvm::LLVMMDNodeInContext(bcx.ccx.llcx(), &val, 1));
llvm::LLVMMDNodeInContext(bx.cx.llcx, &val, 1));
}
}

pub fn trans_global_asm<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
pub fn trans_global_asm<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
ga: &hir::GlobalAsm) {
let asm = CString::new(ga.asm.as_str().as_bytes()).unwrap();
unsafe {
llvm::LLVMRustAppendModuleInlineAsm(ccx.llmod(), asm.as_ptr());
llvm::LLVMRustAppendModuleInlineAsm(cx.llmod, asm.as_ptr());
}
}
24 changes: 12 additions & 12 deletions src/librustc_trans/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use llvm::AttributePlace::Function;
use llvm_util;
pub use syntax::attr::{self, InlineAttr};
use syntax::ast;
use context::CrateContext;
use context::CodegenCx;

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

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

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

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

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

set_frame_pointer_elimination(ccx, llfn);
set_probestack(ccx, llfn);
set_frame_pointer_elimination(cx, llfn);
set_probestack(cx, llfn);

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

let target_features = ccx.tcx().target_features_enabled(id);
let target_features = cx.tcx.target_features_enabled(id);
if !target_features.is_empty() {
let val = CString::new(target_features.join(",")).unwrap();
llvm::AddFunctionAttrStringValue(
Expand Down
Loading

0 comments on commit da569fa

Please sign in to comment.