1
Fork 0

Add 'compiler/rustc_codegen_cranelift/' from commit '793d26047f'

git-subtree-dir: compiler/rustc_codegen_cranelift
git-subtree-mainline: cf798c1ec6
git-subtree-split: 793d26047f
This commit is contained in:
bjorn3 2020-10-26 09:53:27 +01:00
commit ac4f7deb2f
86 changed files with 16617 additions and 0 deletions

View file

@ -0,0 +1,2 @@
This directory is for scripts that are either never directly invoked or are not used very often.
Scripts that are frequently used should be kept at the project root.

View file

@ -0,0 +1,56 @@
set -e
unamestr=`uname`
if [[ "$unamestr" == 'Linux' ]]; then
dylib_ext='so'
elif [[ "$unamestr" == 'Darwin' ]]; then
dylib_ext='dylib'
else
echo "Unsupported os"
exit 1
fi
HOST_TRIPLE=$(rustc -vV | grep host | cut -d: -f2 | tr -d " ")
TARGET_TRIPLE=$HOST_TRIPLE
#TARGET_TRIPLE="x86_64-pc-windows-gnu"
#TARGET_TRIPLE="aarch64-unknown-linux-gnu"
linker=''
RUN_WRAPPER=''
export JIT_SUPPORTED=1
if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then
export JIT_SUPPORTED=0
if [[ "$TARGET_TRIPLE" == "aarch64-unknown-linux-gnu" ]]; then
# We are cross-compiling for aarch64. Use the correct linker and run tests in qemu.
linker='-Clinker=aarch64-linux-gnu-gcc'
RUN_WRAPPER='qemu-aarch64 -L /usr/aarch64-linux-gnu'
elif [[ "$TARGET_TRIPLE" == "x86_64-pc-windows-gnu" ]]; then
# We are cross-compiling for Windows. Run tests in wine.
RUN_WRAPPER='wine'
else
echo "Unknown non-native platform"
fi
fi
if echo "$RUSTC_WRAPPER" | grep sccache; then
echo
echo -e "\x1b[1;93m=== Warning: Unset RUSTC_WRAPPER to prevent interference with sccache ===\x1b[0m"
echo
export RUSTC_WRAPPER=
fi
export RUSTC=$(pwd)/"target/"$CHANNEL"/cg_clif"
export RUSTFLAGS=$linker
export RUSTDOCFLAGS=$linker' -Ztrim-diagnostic-paths=no -Cpanic=abort -Zpanic-abort-tests '\
'-Zcodegen-backend='$(pwd)'/target/'$CHANNEL'/librustc_codegen_cranelift.'$dylib_ext' --sysroot '$(pwd)'/build_sysroot/sysroot'
# FIXME remove once the atomic shim is gone
if [[ `uname` == 'Darwin' ]]; then
export RUSTFLAGS="$RUSTFLAGS -Clink-arg=-undefined -Clink-arg=dynamic_lookup"
fi
export LD_LIBRARY_PATH="$(pwd)/target/out:$(pwd)/build_sysroot/sysroot/lib/rustlib/"$TARGET_TRIPLE"/lib:\
$(pwd)/target/"$CHANNEL":$(rustc --print sysroot)/lib"
export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH
export CG_CLIF_DISPLAY_CG_TIME=1

View file

@ -0,0 +1,126 @@
#!/bin/bash
#![forbid(unsafe_code)]/* This line is ignored by bash
# This block is ignored by rustc
CHANNEL="release"
pushd $(dirname "$0")/../
source scripts/config.sh
popd
PROFILE=$1 OUTPUT=$2 exec $RUSTC $RUSTFLAGS --jit $0
#*/
//! This program filters away uninteresting samples and trims uninteresting frames for stackcollapse
//! profiles.
//!
//! Usage: ./filter_profile.rs <profile in stackcollapse format> <output file>
//!
//! This file is specially crafted to be both a valid bash script and valid rust source file. If
//! executed as bash script this will run the rust source using cg_clif in JIT mode.
use std::io::Write;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let profile_name = std::env::var("PROFILE").unwrap();
let output_name = std::env::var("OUTPUT").unwrap();
if profile_name.is_empty() || output_name.is_empty() {
println!("Usage: ./filter_profile.rs <profile in stackcollapse format> <output file>");
std::process::exit(1);
}
let profile = std::fs::read_to_string(profile_name)
.map_err(|err| format!("Failed to read profile {}", err))?;
let mut output = std::fs::OpenOptions::new()
.create(true)
.write(true)
.truncate(true)
.open(output_name)?;
for line in profile.lines() {
let mut stack = &line[..line.rfind(" ").unwrap()];
let count = &line[line.rfind(" ").unwrap() + 1..];
// Filter away uninteresting samples
if !stack.contains("rustc_codegen_cranelift") {
continue;
}
if stack.contains("rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items")
|| stack.contains("rustc_incremental::assert_dep_graph::assert_dep_graph")
|| stack.contains("rustc_symbol_mangling::test::report_symbol_names")
{
continue;
}
// Trim start
if let Some(index) = stack.find("rustc_interface::passes::configure_and_expand") {
stack = &stack[index..];
} else if let Some(index) = stack.find("rustc_interface::passes::analysis") {
stack = &stack[index..];
} else if let Some(index) = stack.find("rustc_interface::passes::start_codegen") {
stack = &stack[index..];
} else if let Some(index) = stack.find("rustc_interface::queries::Linker::link") {
stack = &stack[index..];
}
if let Some(index) = stack.find("rustc_codegen_cranelift::driver::aot::module_codegen") {
stack = &stack[index..];
}
// Trim end
const MALLOC: &str = "malloc";
if let Some(index) = stack.find(MALLOC) {
stack = &stack[..index + MALLOC.len()];
}
const FREE: &str = "free";
if let Some(index) = stack.find(FREE) {
stack = &stack[..index + FREE.len()];
}
const TYPECK_ITEM_BODIES: &str = "rustc_typeck::check::typeck_item_bodies";
if let Some(index) = stack.find(TYPECK_ITEM_BODIES) {
stack = &stack[..index + TYPECK_ITEM_BODIES.len()];
}
const COLLECT_AND_PARTITION_MONO_ITEMS: &str =
"rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items";
if let Some(index) = stack.find(COLLECT_AND_PARTITION_MONO_ITEMS) {
stack = &stack[..index + COLLECT_AND_PARTITION_MONO_ITEMS.len()];
}
const ASSERT_DEP_GRAPH: &str = "rustc_incremental::assert_dep_graph::assert_dep_graph";
if let Some(index) = stack.find(ASSERT_DEP_GRAPH) {
stack = &stack[..index + ASSERT_DEP_GRAPH.len()];
}
const REPORT_SYMBOL_NAMES: &str = "rustc_symbol_mangling::test::report_symbol_names";
if let Some(index) = stack.find(REPORT_SYMBOL_NAMES) {
stack = &stack[..index + REPORT_SYMBOL_NAMES.len()];
}
const ENCODE_METADATA: &str = "rustc_middle::ty::context::TyCtxt::encode_metadata";
if let Some(index) = stack.find(ENCODE_METADATA) {
stack = &stack[..index + ENCODE_METADATA.len()];
}
const SUBST_AND_NORMALIZE_ERASING_REGIONS: &str = "rustc_middle::ty::normalize_erasing_regions::<impl rustc_middle::ty::context::TyCtxt>::subst_and_normalize_erasing_regions";
if let Some(index) = stack.find(SUBST_AND_NORMALIZE_ERASING_REGIONS) {
stack = &stack[..index + SUBST_AND_NORMALIZE_ERASING_REGIONS.len()];
}
const NORMALIZE_ERASING_LATE_BOUND_REGIONS: &str = "rustc_middle::ty::normalize_erasing_regions::<impl rustc_middle::ty::context::TyCtxt>::normalize_erasing_late_bound_regions";
if let Some(index) = stack.find(NORMALIZE_ERASING_LATE_BOUND_REGIONS) {
stack = &stack[..index + NORMALIZE_ERASING_LATE_BOUND_REGIONS.len()];
}
const INST_BUILD: &str = "<cranelift_frontend::frontend::FuncInstBuilder as cranelift_codegen::ir::builder::InstBuilderBase>::build";
if let Some(index) = stack.find(INST_BUILD) {
stack = &stack[..index + INST_BUILD.len()];
}
output.write_all(stack.as_bytes())?;
output.write_all(&*b" ")?;
output.write_all(count.as_bytes())?;
output.write_all(&*b"\n")?;
}
Ok(())
}

View file

@ -0,0 +1,33 @@
#!/bin/bash
set -e
case $1 in
"prepare")
TOOLCHAIN=$(date +%Y-%m-%d)
echo "=> Installing new nightly"
rustup toolchain install --profile minimal nightly-${TOOLCHAIN} # Sanity check to see if the nightly exists
echo nightly-${TOOLCHAIN} > rust-toolchain
rustup component add rustfmt || true
echo "=> Uninstalling all old nighlies"
for nightly in $(rustup toolchain list | grep nightly | grep -v $TOOLCHAIN | grep -v nightly-x86_64); do
rustup toolchain uninstall $nightly
done
./clean_all.sh
./prepare.sh
(cd build_sysroot && cargo update)
;;
"commit")
git add rust-toolchain build_sysroot/Cargo.lock
git commit -m "Rustup to $(rustc -V)"
;;
*)
echo "Unknown command '$1'"
echo "Usage: ./rustup.sh prepare|commit"
;;
esac