Skip to content

Commit

Permalink
fix up llvm output file
Browse files Browse the repository at this point in the history
  • Loading branch information
oflatt committed Nov 14, 2024
1 parent b76e25d commit 74cb517
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 30 deletions.
3 changes: 0 additions & 3 deletions benchmarks/passing/bril/long/function_call.bril
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# ARGS: 25

# failing due to brillvm bug:
# https://github.com/sampsyo/bril/issues/339

@main(starting_m: int) {
res: int = call @myrec starting_m;
print res;
Expand Down
2 changes: 1 addition & 1 deletion infra/nightly-resources/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function shouldHaveLlvm(runMethod) {
"llvm-eggcc-O0-O0",
"llvm-eggcc-sequential-O0-O0",
"llvm-O3-O0",
"llvm-O3-O0",
"llvm-O3-O3",
"llvm-eggcc-O3-O0",
].includes(runMethod);
}
Expand Down
2 changes: 1 addition & 1 deletion infra/nightly-resources/llvm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
async function showIR(benchmark, runMode) {
const llvm = await fetchText(
`./data/llvm/${benchmark}/${runMode}/${benchmark}-${runMode}.ll`,
`./data/llvm/${benchmark}/${runMode}/optimized.ll`,
);
document.getElementById("llvm-ir").innerText = llvm;
}
Expand Down
6 changes: 4 additions & 2 deletions infra/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ def optimize(benchmark):

# get the commands we need to run
(eggcc_run_mode, llvm_args) = get_eggcc_options(benchmark)
llvm_out_dir = f"{DATA_DIR}/llvm/{benchmark.name}/{benchmark.treatment}"
# make the llvm output directory
os.makedirs(f"{DATA_DIR}/llvm/{benchmark.name}/{benchmark.treatment}", exist_ok=True)
llvm_out_file = f"{DATA_DIR}/llvm/{benchmark.name}/{benchmark.treatment}/optimized.ll"

cmd1 = f'{EGGCC_BINARY} {benchmark.path} --run-mode {eggcc_run_mode}'
cmd2 = f'{EGGCC_BINARY} {optimized_bril_file} --add-timing {llvm_args} -o {profile_dir}/{benchmark.treatment} --llvm-output-dir {llvm_out_dir}'
cmd2 = f'{EGGCC_BINARY} {optimized_bril_file} --add-timing {llvm_args} -o {profile_dir}/{benchmark.treatment} --llvm-output-dir {llvm_out_file}'

print(f'Running c1: {cmd1}', flush=True)
start_eggcc = time.time()
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ struct Args {
/// Where to put the executable (only for the brillift and llvm modes)
#[clap(short)]
output_path: Option<String>,
/// Where to put intermediary files (only for OptimizeBrilLLVM mode)
/// Where to put the optimized llvm file (for the llvm mode)
#[clap(long)]
llvm_output_dir: Option<String>,
llvm_output_dir: Option<PathBuf>,
/// For the LLVM run mode, choose whether to first run eggcc
/// to optimize the bril program before going to LLVM.
#[clap(long)]
Expand Down Expand Up @@ -98,7 +98,7 @@ fn main() {
},
profile_out: args.profile_out,
output_path: args.output_path,
llvm_output_dir: args.llvm_output_dir,
optimized_llvm_out: args.llvm_output_dir,
optimize_egglog: args.optimize_egglog,
optimize_brilift: args.optimize_brilift,
optimize_bril_llvm: args.optimize_bril_llvm,
Expand Down
27 changes: 7 additions & 20 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ pub struct Run {
pub test_type: RunMode,
pub interp: InterpMode,
pub profile_out: Option<PathBuf>,
pub llvm_output_dir: Option<String>,
pub optimized_llvm_out: Option<PathBuf>,
pub output_path: Option<String>,
pub optimize_egglog: Option<bool>,
pub optimize_brilift: Option<bool>,
Expand All @@ -401,7 +401,7 @@ impl Run {
interp: InterpMode::None,
profile_out: None,
output_path: None,
llvm_output_dir: None,
optimized_llvm_out: None,
optimize_egglog: None,
optimize_brilift: None,
optimize_bril_llvm: None,
Expand Down Expand Up @@ -472,7 +472,7 @@ impl Run {
prog_with_args: test.read_program(),
profile_out: None,
output_path: None,
llvm_output_dir: None,
optimized_llvm_out: None,
optimize_egglog: None,
optimize_brilift: Some(optimize_brilift),
optimize_bril_llvm: None,
Expand All @@ -489,7 +489,7 @@ impl Run {
prog_with_args: test.read_program(),
profile_out: None,
output_path: None,
llvm_output_dir: None,
optimized_llvm_out: None,
// no need to set optimization flags, since all combinations are tested
optimize_egglog: None,
optimize_brilift: None,
Expand Down Expand Up @@ -549,7 +549,7 @@ impl Run {
prog_with_args: prog.clone(),
profile_out: None,
output_path: None,
llvm_output_dir: None,
optimized_llvm_out: None,
optimize_egglog: Some(optimize_egglog),
optimize_brilift: None,
optimize_bril_llvm: Some(optimize_llvm),
Expand Down Expand Up @@ -1070,17 +1070,6 @@ impl Run {
.clone()
.unwrap_or_else(|| format!("/tmp/{}", unique_name));

// Copy init file to $output_dir
if let Some(output_dir) = &self.llvm_output_dir {
std::fs::create_dir_all(output_dir)
.unwrap_or_else(|_| panic!("could not create output dir {}", output_dir));
std::process::Command::new("cp")
.arg(file_path.clone())
.arg(output_dir)
.status()
.unwrap();
}

let processed = dir.path().join("postprocessed.ll");
let optimized = dir.path().join("optimized.ll");
// HACK: check if opt-18 exists
Expand Down Expand Up @@ -1145,12 +1134,10 @@ impl Run {
"failed to compile llvm ir",
);

if let Some(output_dir) = &self.llvm_output_dir {
if let Some(output_llvm_file) = &self.optimized_llvm_out {
// move optimized.ll to the output dir
expect_command_success(
Command::new("mv")
.arg(optimized)
.arg(format!("{}/{}.ll", output_dir, self.name())),
Command::new("mv").arg(optimized).arg(output_llvm_file),
"failed to move optimized llvm ir",
);
}
Expand Down

0 comments on commit 74cb517

Please sign in to comment.