]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #51966 - alexcrichton:llvm7, r=michaelwoerister
authorbors <bors@rust-lang.org>
Wed, 11 Jul 2018 07:20:14 +0000 (07:20 +0000)
committerbors <bors@rust-lang.org>
Wed, 11 Jul 2018 07:20:14 +0000 (07:20 +0000)
Upgrade to LLVM's master branch (LLVM 7)

### Current status

~~Blocked on a [performance regression](https://github.com/rust-lang/rust/pull/51966#issuecomment-402320576). The performance regression has an [upstream LLVM issue](https://bugs.llvm.org/show_bug.cgi?id=38047) and has also [been bisected](https://reviews.llvm.org/D44282) to an LLVM revision.~~

Ready to merge!

---

This commit upgrades the main LLVM submodule to LLVM's current master branch.
The LLD submodule is updated in tandem as well as compiler-builtins.

Along the way support was also added for LLVM 7's new features. This primarily
includes the support for custom section concatenation natively in LLD so we now
add wasm custom sections in LLVM IR rather than having custom support in rustc
itself for doing so.

Some other miscellaneous changes are:

* We now pass `--gc-sections` to `wasm-ld`
* The optimization level is now passed to `wasm-ld`
* A `--stack-first` option is passed to LLD to have stack overflow always cause
  a trap instead of corrupting static data
* The wasm target for LLVM switched to `wasm32-unknown-unknown`.
* The syntax for aligned pointers has changed in LLVM IR and tests are updated
  to reflect this.
* ~~The `thumbv6m-none-eabi` target is disabled due to an [LLVM bug][llbug]~~

Nowadays we've been mostly only upgrading whenever there's a major release of
LLVM but enough changes have been happening on the wasm target that there's been
growing motivation for quite some time now to upgrade out version of LLD. To
upgrade LLD, however, we need to upgrade LLVM to avoid needing to build yet
another version of LLVM on the builders.

The revision of LLVM in use here is arbitrarily chosen. We will likely need to
continue to update it over time if and when we discover bugs. Once LLVM 7 is
fully released we can switch to that channel as well.

[llbug]: https://bugs.llvm.org/show_bug.cgi?id=37382

cc #50543

1  2 
src/librustc/hir/mod.rs
src/librustc_codegen_llvm/base.rs

diff --combined src/librustc/hir/mod.rs
index f18846b8574df4ae347fc2f821dc0ae28027dd66,2a515fe3f2d46452d4f377c76d9a376f8108217c..bae443bfc582403a036c732964b20ad4cd19f811
@@@ -402,15 -402,6 +402,15 @@@ pub enum GenericArg 
      Type(Ty),
  }
  
 +impl GenericArg {
 +    pub fn span(&self) -> Span {
 +        match self {
 +            GenericArg::Lifetime(l) => l.span,
 +            GenericArg::Type(t) => t.span,
 +        }
 +    }
 +}
 +
  #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
  pub struct GenericArgs {
      /// The generic arguments for this path segment.
@@@ -2268,6 -2259,7 +2268,7 @@@ pub struct CodegenFnAttrs 
      pub export_name: Option<Symbol>,
      pub target_features: Vec<Symbol>,
      pub linkage: Option<Linkage>,
+     pub wasm_custom_section: Option<Symbol>,
  }
  
  bitflags! {
@@@ -2292,6 -2284,7 +2293,7 @@@ impl CodegenFnAttrs 
              export_name: None,
              target_features: vec![],
              linkage: None,
+             wasm_custom_section: None,
          }
      }
  
index 2598e7c86f9dac67de3048754a2e773ca2df896b,70b66dd436b805cb1987c4846b43fe9e81e021e4..179fffc4e7f4ab1a41ef610b05da4f0986c4c970
@@@ -33,6 -33,7 +33,7 @@@ use back::link
  use back::write::{self, OngoingCodegen, create_target_machine};
  use llvm::{ContextRef, ModuleRef, ValueRef, Vector, get_param};
  use llvm;
+ use libc::c_uint;
  use metadata;
  use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
  use rustc::middle::lang_items::StartFnLangItem;
@@@ -74,10 -75,8 +75,8 @@@ use type_of::LayoutLlvmExt
  use rustc::util::nodemap::{FxHashMap, FxHashSet, DefIdSet};
  use CrateInfo;
  use rustc_data_structures::sync::Lrc;
- use rustc_target::spec::TargetTriple;
  
  use std::any::Any;
- use std::collections::BTreeMap;
  use std::ffi::CString;
  use std::str;
  use std::sync::Arc;
@@@ -266,8 -265,8 +265,8 @@@ pub fn unsize_thin_ptr<'a, 'tcx>
              }
              let (lldata, llextra) = result.unwrap();
              // HACK(eddyb) have to bitcast pointers until LLVM removes pointee types.
 -            (bx.bitcast(lldata, dst_layout.scalar_pair_element_llvm_type(bx.cx, 0)),
 -             bx.bitcast(llextra, dst_layout.scalar_pair_element_llvm_type(bx.cx, 1)))
 +            (bx.bitcast(lldata, dst_layout.scalar_pair_element_llvm_type(bx.cx, 0, true)),
 +             bx.bitcast(llextra, dst_layout.scalar_pair_element_llvm_type(bx.cx, 1, true)))
          }
          _ => bug!("unsize_thin_ptr: called on bad types"),
      }
@@@ -397,14 -396,9 +396,14 @@@ pub fn from_immediate(bx: &Builder, val
  
  pub fn to_immediate(bx: &Builder, val: ValueRef, layout: layout::TyLayout) -> ValueRef {
      if let layout::Abi::Scalar(ref scalar) = layout.abi {
 -        if scalar.is_bool() {
 -            return bx.trunc(val, Type::i1(bx.cx));
 -        }
 +        return to_immediate_scalar(bx, val, scalar);
 +    }
 +    val
 +}
 +
 +pub fn to_immediate_scalar(bx: &Builder, val: ValueRef, scalar: &layout::Scalar) -> ValueRef {
 +    if scalar.is_bool() {
 +        return bx.trunc(val, Type::i1(bx.cx));
      }
      val
  }
@@@ -1100,7 -1094,6 +1099,6 @@@ impl CrateInfo 
              used_crates_dynamic: cstore::used_crates(tcx, LinkagePreference::RequireDynamic),
              used_crates_static: cstore::used_crates(tcx, LinkagePreference::RequireStatic),
              used_crate_source: FxHashMap(),
-             wasm_custom_sections: BTreeMap::new(),
              wasm_imports: FxHashMap(),
              lang_item_to_crate: FxHashMap(),
              missing_lang_items: FxHashMap(),
          let load_wasm_items = tcx.sess.crate_types.borrow()
              .iter()
              .any(|c| *c != config::CrateTypeRlib) &&
-             tcx.sess.opts.target_triple == TargetTriple::from_triple("wasm32-unknown-unknown");
+             tcx.sess.opts.target_triple.triple() == "wasm32-unknown-unknown";
  
          if load_wasm_items {
-             info!("attempting to load all wasm sections");
-             for &id in tcx.wasm_custom_sections(LOCAL_CRATE).iter() {
-                 let (name, contents) = fetch_wasm_section(tcx, id);
-                 info.wasm_custom_sections.entry(name)
-                     .or_insert(Vec::new())
-                     .extend(contents);
-             }
              info.load_wasm_imports(tcx, LOCAL_CRATE);
          }
  
                  info.is_no_builtins.insert(cnum);
              }
              if load_wasm_items {
-                 for &id in tcx.wasm_custom_sections(cnum).iter() {
-                     let (name, contents) = fetch_wasm_section(tcx, id);
-                     info.wasm_custom_sections.entry(name)
-                         .or_insert(Vec::new())
-                         .extend(contents);
-                 }
                  info.load_wasm_imports(tcx, cnum);
              }
              let missing = tcx.missing_lang_items(cnum);
@@@ -1385,25 -1365,41 +1370,41 @@@ mod temp_stable_hash_impls 
      }
  }
  
fn fetch_wasm_section(tcx: TyCtxt, id: DefId) -> (String, Vec<u8>) {
pub fn define_custom_section(cx: &CodegenCx, def_id: DefId) {
      use rustc::mir::interpret::GlobalId;
  
-     info!("loading wasm section {:?}", id);
+     assert!(cx.tcx.sess.opts.target_triple.triple().starts_with("wasm32"));
+     info!("loading wasm section {:?}", def_id);
  
-     let section = tcx.get_attrs(id)
-         .iter()
-         .find(|a| a.check_name("wasm_custom_section"))
-         .expect("missing #[wasm_custom_section] attribute")
-         .value_str()
-         .expect("malformed #[wasm_custom_section] attribute");
+     let section = cx.tcx.codegen_fn_attrs(def_id).wasm_custom_section.unwrap();
  
-     let instance = ty::Instance::mono(tcx, id);
+     let instance = ty::Instance::mono(cx.tcx, def_id);
      let cid = GlobalId {
          instance,
          promoted: None
      };
      let param_env = ty::ParamEnv::reveal_all();
-     let val = tcx.const_eval(param_env.and(cid)).unwrap();
-     let alloc = tcx.const_value_to_allocation(val);
-     (section.to_string(), alloc.bytes.clone())
+     let val = cx.tcx.const_eval(param_env.and(cid)).unwrap();
+     let alloc = cx.tcx.const_value_to_allocation(val);
+     unsafe {
+         let section = llvm::LLVMMDStringInContext(
+             cx.llcx,
+             section.as_str().as_ptr() as *const _,
+             section.as_str().len() as c_uint,
+         );
+         let alloc = llvm::LLVMMDStringInContext(
+             cx.llcx,
+             alloc.bytes.as_ptr() as *const _,
+             alloc.bytes.len() as c_uint,
+         );
+         let data = [section, alloc];
+         let meta = llvm::LLVMMDNodeInContext(cx.llcx, data.as_ptr(), 2);
+         llvm::LLVMAddNamedMetadataOperand(
+             cx.llmod,
+             "wasm.custom_sections\0".as_ptr() as *const _,
+             meta,
+         );
+     }
  }