Merge pull request #288 from rtfeldman/improvements

Some build improvements
This commit is contained in:
Richard Feldman 2020-04-01 23:36:53 -04:00 committed by GitHub
commit ec9c906262
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 35 additions and 148 deletions

View File

@ -32,7 +32,9 @@ Create `~/.config/cargo` and add this to it:
```
[build]
rustflags = ["-C", "link-arg=-fuse-ld=lld"]
# Link with lld, per https://github.com/rust-lang/rust/issues/39915#issuecomment-538049306
# Use target-cpu=native, per https://deterministic.space/high-performance-rust.html
rustflags = ["-C", "link-arg=-fuse-ld=lld", "-C", "target-cpu=native"]
```
Then install `lld` version 9 (e.g. with `$ sudo apt-get install lld-9`)

View File

@ -24,3 +24,7 @@ members = [
"cli"
]
# Optimizations based on https://deterministic.space/high-performance-rust.html
[profile.release]
lto = "fat"
codegen-units = 1

View File

@ -1,6 +1,6 @@
#!/bin/bash
mkdir -p $HOME/.cargo
echo -e "[build]\nrustflags = [\"-C\", \"link-arg=-fuse-ld=lld\"]" > $HOME/.cargo/config
echo -e "[build]\nrustflags = [\"-C\", \"link-arg=-fuse-ld=lld\", \"-C\", \"target-cpu=native\"]" > $HOME/.cargo/config
ln -s /usr/bin/lld-8 /usr/local/bin/ld.lld

View File

@ -76,17 +76,14 @@ fn gen(src: &str, target: Triple, dest_filename: &Path) {
fpm.initialize();
// Compute main_fn_type before moving subs to Env
let pointer_bytes = target.pointer_width().unwrap().bytes() as u32;
let layout = Layout::from_content(&arena, content, &subs, pointer_bytes)
.unwrap_or_else(|err| panic!("Code gen error in test: could not convert to layout. Err was {:?} and Subs were {:?}", err, subs));
let ptr_bytes = target.pointer_width().unwrap().bytes() as u32;
let layout = Layout::from_content(&arena, content, &subs, ptr_bytes).unwrap_or_else(|err| {
panic!(
"Code gen error in test: could not convert to layout. Err was {:?} and Subs were {:?}",
err, subs
)
});
let execution_engine = module
.create_jit_execution_engine(OptimizationLevel::None)
.expect("Error creating JIT execution engine for test");
let ptr_bytes = execution_engine
.get_target_data()
.get_pointer_byte_size(None);
let main_fn_type =
basic_type_from_layout(&arena, &context, &layout, ptr_bytes).fn_type(&[], false);
let main_fn_name = "$Test.main";
@ -111,7 +108,7 @@ fn gen(src: &str, target: Triple, dest_filename: &Path) {
&mut procs,
home,
&mut ident_ids,
pointer_bytes,
ptr_bytes,
);
// Put this module's ident_ids back in the interns, so we can use them in env.

View File

@ -8,3 +8,6 @@ edition = "2018"
description = "Generate LLVM bitcode for Roc builtins"
license = "Apache-2.0"
[build]
target-dir="~/code/roc/copmiler/builtins/bitcode/"

View File

@ -22,7 +22,9 @@ $ cargo rustc --release --lib -- --emit=llvm-bc
Then look in the root `roc` source directory under `target/release/deps/` for a file
with a name like `roc_builtins_bitcode-8da0901c58a73ebf.bc` - except
probably with a different hash before the `.bc`. There should be only one `*.bc` file in that directory.
probably with a different hash before the `.bc`. If there's more than one
`*.bc` file in that directory, delete the whole `deps/` directory and re-run
the `cargo rustc` command above to regenerate it.
> If you want to take a look at the human-readable LLVM IR rather than the
> bitcode, run this instead and look for a `.ll` file instead of a `.bc` file:
@ -37,17 +39,18 @@ The bitcode is a bunch of bytes that aren't particularly human-readable.
Since Roc is designed to be distributed as a single binary, these bytes
need to be included in the raw source somewhere.
We have a script that generates this file and writes it to stdout.
To use it, run this command, replacing `bitcode.bc` with the path to the
generated file in `target/release/deps/` from earlier.
The `llvm/src/build.rs` file statically imports these raw bytes
using the [`include_bytes!` macro](https://doc.rust-lang.org/std/macro.include_bytes.html),
so we just need to move the `.bc` file from the previous step to the correct
location.
`$ ./import.pl bitcode.bc > ../../gen/src/llvm/builtins.rs`
The current `.bc` file is located at:
If the script succeeds, `git status` should show that the appropriate
`.rs` file has been updated.
```
compiler/gen/src/llvm/builtins.bc
```
Before checking it in, make sure to run `cargo fmt` on the root of
the project! Otherwise that file will not be formatted properly and
will fail the build.
...so you want to overwrite it with the new `.bc` file in `target/deps/`
Once you've formatted the `builtins.rs` file, check it in and you're done!
Once that's done, `git status` should show that the `builtins.bc` file
has been changed. Commit that change and you're done!

View File

@ -1,40 +0,0 @@
#!/usr/bin/perl
$num_args = $#ARGV + 1;
if ($num_args != 1) {
die "\nUsage: import.pl path-to-roc_builtins_bitcode-hashgoeshere.bc\n";
}
my $filename = $ARGV[0];
my $before_bitcode = "// GENERATED FILE - NEVER EDIT BY HAND!\n//\n// See compiler/builtins/bitcode/README.md for how to generate.\n\npub const BUILTINS_BITCODE: &[u8] = &[\n ";
my $after_bitcode = "\n];";
# Get a filehandle to the raw binary data in the file
open(my $fh, '<:raw', $filename)
or die "Could not open file '$filename'\n\n$!";
my $bitcode = '';
while (1) {
# Read 1 byte
my $success = read $fh, my $byte, 1;
if (not defined $success) {
# Explode on error.
die $!
} elsif (not $success) {
# Exit the loop if no bytes were read.
last;
} else {
if (length($bitcode) > 0) {
$bitcode .= ', ';
}
# Print the numeric representation of the byte
$bitcode .= ord($byte);
}
}
close $fh;
print "$before_bitcode$bitcode$after_bitcode\n";

View File

@ -10,7 +10,6 @@ use inkwell::values::BasicValueEnum::{self, *};
use inkwell::values::{FunctionValue, IntValue, PointerValue, StructValue};
use inkwell::{FloatPredicate, IntPredicate};
use crate::llvm::builtins::BUILTINS_BITCODE;
use crate::llvm::convert::{
basic_type_from_layout, collection_wrapper, empty_collection, get_fn_type, ptr_int,
};
@ -50,7 +49,8 @@ impl<'a, 'ctx, 'env> Env<'a, 'ctx, 'env> {
}
pub fn module_from_builtins<'ctx>(ctx: &'ctx Context, module_name: &str) -> Module<'ctx> {
let memory_buffer = MemoryBuffer::create_from_memory_range(BUILTINS_BITCODE, module_name);
let memory_buffer =
MemoryBuffer::create_from_memory_range(include_bytes!("builtins.bc"), module_name);
Module::parse_bitcode_from_buffer(&memory_buffer, ctx)
.unwrap_or_else(|err| panic!("Unable to import builtins bitcode. LLVM error: {:?}", err))

Binary file not shown.

View File

@ -1,81 +0,0 @@
// GENERATED FILE - NEVER EDIT BY HAND!
//
// See compiler/builtins/bitcode/README.md for how to generate.
pub const BUILTINS_BITCODE: &[u8] = &[
66, 67, 192, 222, 53, 20, 0, 0, 14, 0, 0, 0, 98, 12, 48, 28, 1, 199, 10, 172, 96, 11, 173, 144,
7, 110, 0, 7, 110, 16, 7, 109, 32, 15, 245, 48, 15, 244, 208, 6, 113, 224, 6, 116, 32, 7, 110,
0, 7, 109, 48, 15, 244, 16, 14, 226, 192, 14, 229, 32, 68, 1, 50, 5, 0, 0, 0, 0, 33, 12, 0, 0,
88, 1, 0, 0, 11, 2, 33, 0, 2, 0, 0, 0, 22, 0, 0, 0, 7, 129, 35, 145, 65, 200, 4, 73, 6, 16, 50,
57, 146, 1, 132, 12, 37, 5, 8, 25, 30, 4, 139, 98, 128, 12, 69, 2, 66, 146, 11, 66, 100, 16,
50, 20, 56, 8, 24, 75, 10, 50, 50, 136, 72, 112, 196, 33, 35, 68, 18, 135, 140, 16, 65, 146, 2,
100, 200, 8, 177, 20, 32, 67, 70, 136, 32, 201, 1, 50, 50, 132, 24, 42, 40, 42, 144, 49, 124,
176, 92, 145, 32, 195, 200, 0, 0, 0, 137, 32, 0, 0, 12, 0, 0, 0, 50, 34, 200, 8, 32, 100, 133,
4, 147, 33, 164, 132, 4, 147, 33, 227, 132, 161, 144, 20, 18, 76, 134, 140, 11, 132, 100, 76,
16, 28, 67, 0, 115, 4, 160, 80, 4, 132, 52, 16, 48, 71, 0, 6, 35, 0, 0, 0, 81, 24, 0, 0, 23, 0,
0, 0, 27, 252, 32, 248, 255, 255, 255, 255, 1, 128, 3, 64, 2, 30, 128, 2, 194, 128, 128, 7,
121, 120, 7, 113, 40, 135, 54, 152, 7, 122, 8, 135, 113, 88, 7, 224, 23, 126, 65, 30, 234, 97,
30, 232, 225, 23, 224, 65, 30, 222, 65, 28, 202, 97, 30, 232, 33, 28, 198, 97, 29, 0, 130, 30,
194, 65, 30, 206, 161, 28, 232, 161, 13, 198, 1, 30, 234, 1, 192, 7, 60, 176, 131, 54, 176, 3,
58, 0, 0, 0, 0, 0, 73, 24, 0, 0, 1, 0, 0, 0, 19, 130, 0, 0, 19, 48, 124, 192, 3, 59, 248, 5,
59, 160, 131, 54, 168, 7, 119, 88, 7, 119, 120, 135, 123, 112, 135, 54, 96, 135, 116, 112, 135,
122, 192, 135, 54, 56, 7, 119, 168, 135, 13, 101, 80, 14, 109, 208, 14, 122, 80, 14, 109, 144,
14, 118, 64, 7, 122, 96, 7, 116, 208, 6, 230, 128, 7, 112, 160, 7, 113, 32, 7, 120, 208, 6,
238, 128, 7, 122, 16, 7, 118, 160, 7, 115, 32, 7, 122, 96, 7, 116, 208, 6, 179, 16, 7, 114,
128, 7, 26, 33, 76, 14, 199, 64, 254, 30, 127, 197, 245, 52, 155, 158, 118, 207, 191, 226, 52,
125, 252, 38, 151, 93, 180, 115, 45, 45, 207, 177, 213, 173, 241, 185, 238, 130, 13, 169, 128,
69, 0, 0, 32, 0, 0, 0, 8, 0, 0, 0, 0, 0, 88, 0, 137, 13, 2, 69, 189, 2, 0, 0, 178, 64, 6, 0, 0,
0, 50, 30, 152, 12, 25, 17, 76, 144, 140, 9, 38, 71, 198, 4, 67, 106, 57, 20, 65, 9, 0, 0, 0,
0, 177, 24, 0, 0, 137, 0, 0, 0, 51, 8, 128, 28, 196, 225, 28, 102, 20, 1, 61, 136, 67, 56, 132,
195, 140, 66, 128, 7, 121, 120, 7, 115, 152, 113, 12, 230, 0, 15, 237, 16, 14, 244, 128, 14,
51, 12, 66, 30, 194, 193, 29, 206, 161, 28, 102, 48, 5, 61, 136, 67, 56, 132, 131, 27, 204, 3,
61, 200, 67, 61, 140, 3, 61, 204, 120, 140, 116, 112, 7, 123, 8, 7, 121, 72, 135, 112, 112, 7,
122, 112, 3, 118, 120, 135, 112, 32, 135, 25, 204, 17, 14, 236, 144, 14, 225, 48, 15, 110, 48,
15, 227, 240, 14, 240, 80, 14, 51, 16, 196, 29, 222, 33, 28, 216, 33, 29, 194, 97, 30, 102, 48,
137, 59, 188, 131, 59, 208, 67, 57, 180, 3, 60, 188, 131, 60, 132, 3, 59, 204, 240, 20, 118,
96, 7, 123, 104, 7, 55, 104, 135, 114, 104, 7, 55, 128, 135, 112, 144, 135, 112, 96, 7, 118,
40, 7, 118, 248, 5, 118, 120, 135, 119, 128, 135, 95, 8, 135, 113, 24, 135, 114, 152, 135, 121,
152, 129, 44, 238, 240, 14, 238, 224, 14, 245, 192, 14, 236, 48, 3, 98, 200, 161, 28, 228, 161,
28, 204, 161, 28, 228, 161, 28, 220, 97, 28, 202, 33, 28, 196, 129, 29, 202, 97, 6, 214, 144,
67, 57, 200, 67, 57, 152, 67, 57, 200, 67, 57, 184, 195, 56, 148, 67, 56, 136, 3, 59, 148, 195,
47, 188, 131, 60, 252, 130, 59, 212, 3, 59, 176, 195, 12, 199, 105, 135, 112, 88, 135, 114,
112, 131, 116, 104, 7, 120, 96, 135, 116, 24, 135, 116, 160, 135, 25, 206, 83, 15, 238, 0, 15,
242, 80, 14, 228, 144, 14, 227, 64, 15, 225, 32, 14, 236, 80, 14, 51, 32, 40, 29, 220, 193, 30,
194, 65, 30, 210, 33, 28, 220, 129, 30, 220, 224, 28, 228, 225, 29, 234, 1, 30, 102, 24, 81,
56, 176, 67, 58, 156, 131, 59, 204, 80, 36, 118, 96, 7, 123, 104, 7, 55, 96, 135, 119, 120, 7,
120, 152, 81, 76, 244, 144, 15, 240, 80, 14, 51, 30, 106, 30, 202, 97, 28, 232, 33, 29, 222,
193, 29, 126, 1, 30, 228, 161, 28, 204, 33, 29, 240, 97, 6, 84, 133, 131, 56, 204, 195, 59,
176, 67, 61, 208, 67, 57, 252, 194, 60, 228, 67, 59, 136, 195, 59, 176, 195, 140, 197, 10, 135,
121, 152, 135, 119, 24, 135, 116, 8, 7, 122, 40, 7, 114, 152, 129, 92, 227, 16, 14, 236, 192,
14, 229, 80, 14, 243, 48, 35, 193, 210, 65, 30, 228, 225, 23, 216, 225, 29, 222, 1, 30, 102,
72, 25, 59, 176, 131, 61, 180, 131, 27, 132, 195, 56, 140, 67, 57, 204, 195, 60, 184, 193, 57,
200, 195, 59, 212, 3, 60, 204, 72, 180, 113, 8, 7, 118, 96, 7, 113, 8, 135, 113, 88, 135, 25,
219, 198, 14, 236, 96, 15, 237, 224, 6, 240, 32, 15, 229, 48, 15, 229, 32, 15, 246, 80, 14,
110, 16, 14, 227, 48, 14, 229, 48, 15, 243, 224, 6, 233, 224, 14, 228, 80, 14, 248, 0, 0, 0, 0,
121, 32, 0, 0, 27, 0, 0, 0, 114, 30, 72, 32, 67, 136, 12, 25, 9, 114, 50, 72, 32, 35, 129, 140,
145, 145, 209, 68, 160, 16, 40, 100, 60, 49, 50, 66, 142, 144, 33, 163, 40, 16, 24, 0, 201, 2,
0, 0, 80, 73, 67, 32, 76, 101, 118, 101, 108, 82, 116, 76, 105, 98, 85, 115, 101, 71, 79, 84,
35, 8, 69, 48, 130, 80, 8, 35, 8, 197, 48, 195, 48, 4, 196, 12, 3, 33, 20, 50, 18, 152, 160,
140, 216, 216, 236, 218, 92, 218, 222, 200, 234, 216, 202, 92, 204, 216, 194, 206, 230, 70, 17,
10, 3, 0, 0, 0, 169, 24, 0, 0, 11, 0, 0, 0, 11, 10, 114, 40, 135, 119, 128, 7, 122, 88, 112,
152, 67, 61, 184, 195, 56, 176, 67, 57, 208, 195, 130, 230, 28, 198, 161, 13, 232, 65, 30, 194,
193, 29, 230, 33, 29, 232, 33, 29, 222, 193, 29, 0, 209, 16, 0, 0, 6, 0, 0, 0, 7, 204, 60, 164,
131, 59, 156, 3, 59, 148, 3, 61, 160, 131, 60, 148, 67, 56, 144, 195, 1, 0, 0, 0, 97, 32, 0, 0,
8, 0, 0, 0, 19, 4, 65, 6, 176, 13, 194, 129, 0, 0, 0, 0, 3, 0, 0, 0, 70, 48, 52, 20, 115, 0,
133, 52, 1, 209, 4, 0, 0, 0, 0, 0, 161, 32, 0, 0, 16, 0, 0, 0, 163, 4, 199, 80, 1, 32, 170, 0,
33, 50, 132, 136, 16, 33, 66, 196, 8, 137, 26, 64, 136, 12, 33, 34, 68, 136, 16, 49, 66, 82,
14, 16, 34, 99, 132, 196, 188, 32, 68, 134, 136, 17, 18, 242, 128, 16, 25, 66, 82, 90, 16, 34,
100, 132, 10, 0, 16, 40, 0, 0, 0, 0, 0, 0, 113, 32, 0, 0, 3, 0, 0, 0, 50, 14, 16, 34, 132, 0,
194, 2, 0, 0, 0, 0, 139, 138, 191, 252, 105, 31, 31, 88, 17, 135, 229, 53, 128, 231, 83, 204,
67, 1, 116, 229, 220, 21, 133, 255, 102, 211, 221, 20, 0, 0, 0, 0, 101, 12, 0, 0, 31, 0, 0, 0,
18, 3, 148, 240, 0, 0, 0, 0, 2, 0, 0, 0, 11, 0, 0, 0, 24, 0, 0, 0, 76, 0, 0, 0, 1, 0, 0, 0, 88,
0, 0, 0, 0, 0, 0, 0, 88, 0, 0, 0, 1, 0, 0, 0, 112, 0, 0, 0, 0, 0, 0, 0, 35, 0, 0, 0, 24, 0, 0,
0, 59, 0, 0, 0, 35, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 112, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 255, 255, 255, 255, 0,
52, 0, 0, 0, 0, 0, 0, 93, 12, 0, 0, 27, 0, 0, 0, 18, 3, 148, 190, 0, 0, 0, 0, 105, 54, 52, 95,
116, 111, 95, 102, 54, 52, 95, 57, 46, 48, 46, 49, 45, 114, 117, 115, 116, 45, 49, 46, 52, 50,
46, 48, 45, 115, 116, 97, 98, 108, 101, 120, 56, 54, 95, 54, 52, 45, 117, 110, 107, 110, 111,
119, 110, 45, 108, 105, 110, 117, 120, 45, 103, 110, 117, 114, 111, 99, 95, 98, 117, 105, 108,
116, 105, 110, 115, 95, 98, 105, 116, 99, 111, 100, 101, 46, 52, 103, 53, 105, 114, 57, 108,
106, 45, 99, 103, 117, 46, 48, 0, 0, 0, 0, 0, 0,
];

View File

@ -1,3 +1,2 @@
pub mod build;
pub mod builtins;
pub mod convert;