Skip to content

Commit

Permalink
Merge pull request #739 from egraphs-good/oflatt-clean-nightly-output
Browse files Browse the repository at this point in the history
Clean up nightly output
  • Loading branch information
oflatt authored Feb 19, 2025
2 parents 1be2ee1 + 3158e21 commit 058bb25
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
4 changes: 2 additions & 2 deletions infra/generate_cfgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def make_cfgs(bench, data_dir):

# https://llvm.org/docs/Passes.html#dot-cfg-print-cfg-of-function-to-dot-file
# spawn a shell in the path and run opt
opt_res = subprocess.run(f"{opt} -disable-output -passes=dot-cfg optimized.ll", shell=True, cwd=path)
opt_res = subprocess.run(f"{opt} -disable-output -passes=dot-cfg optimized.ll", shell=True, cwd=path, capture_output=True)
if opt_res.returncode != 0:
print(f"Error running opt on {path}/optimized.ll")
exit(1)
Expand All @@ -39,7 +39,7 @@ def make_cfgs(bench, data_dir):

# Convert to png
cmd = f"dot -Tpng -o {path}/{name}.png {path}/{dot}"
dot_res = subprocess.run(cmd, shell=True).returncode
dot_res = subprocess.run(cmd, shell=True, capture_output=True).returncode
if dot_res != 0:
print(f"Error converting {dot} to png")
exit(1)
Expand Down
1 change: 0 additions & 1 deletion infra/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ def get_suite(path):

oldpath = path
path = os.path.dirname(path)
print(os.path.basename(path))
if os.path.basename(path) == "passing":
return os.path.basename(oldpath)

Expand Down
39 changes: 33 additions & 6 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,13 +1144,23 @@ impl Run {
// Also, on some machines, just running `opt-18` hangs, so we pass the version flag
// NB: on newer mac installs, opt-19 and clang-19 will be in the path,
// but opt/clang will not be.
let opt_cmd = if Command::new("opt-18").arg("--version").status().is_ok() {
let opt_cmd = if Command::new("opt-18")
.stdout(Stdio::null())
.arg("--version")
.status()
.is_ok()
{
"opt-18"
} else {
"opt"
};

let clang_cmd = if Command::new("clang-18").arg("--version").status().is_ok() {
let clang_cmd = if Command::new("clang-18")
.arg("--version")
.stdout(Stdio::null())
.status()
.is_ok()
{
"clang-18"
} else {
"clang"
Expand All @@ -1171,6 +1181,12 @@ impl Run {
panic!("Opt failed on following input:\n{p1_string}");
}

let hostmachinearchuntrimmed = expect_command_success(
Command::new(clang_cmd).arg("-dumpmachine"),
"failed to get host machine arch",
);
let hostmachinearch = hostmachinearchuntrimmed.trim();

// Now, run the llvm optimizer and generate optimized llvm
let llvm_time_start = Instant::now();
expect_command_success(
Expand All @@ -1186,6 +1202,11 @@ impl Run {
);
let llvm_time = llvm_time_start.elapsed();

// now add the host machine arch to the generated llvm ir
let mut llvm_ir = std::fs::read_to_string(optimized.clone()).unwrap();
llvm_ir = format!("target triple = \"{}\"\n{}", hostmachinearch, llvm_ir);
std::fs::write(optimized.clone(), llvm_ir).unwrap();

// Lower the optimized LLVM but don't do target-specific optimizations besides register allocation
// We use O0 and disable debug info
expect_command_success(
Expand Down Expand Up @@ -1239,11 +1260,17 @@ impl Run {
}
}

fn expect_command_success(cmd: &mut std::process::Command, message: &str) {
let status = cmd.status().unwrap();
if !status.success() {
panic!("Command failed: {}", message);
fn expect_command_success(cmd: &mut std::process::Command, message: &str) -> String {
let output = cmd.output().unwrap();
if !output.status.success() {
panic!(
"Command failed: {}\nStderr: {}",
message,
String::from_utf8_lossy(&output.stderr)
);
}

String::from_utf8(output.stdout).unwrap()
}

pub(crate) struct FreshNameGen {
Expand Down

0 comments on commit 058bb25

Please sign in to comment.