-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #608 from egraphs-good/ajpal-cfg
Show CFGs on Nightly
- Loading branch information
Showing
11 changed files
with
252 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python3 | ||
import glob | ||
import os | ||
|
||
def make_cfgs(bench, data_dir): | ||
cwd = os.getcwd() | ||
path = f"{data_dir}/{bench}" | ||
runmodes = os.listdir(path) | ||
for mode in runmodes: | ||
os.chdir(f"{path}/{mode}") | ||
|
||
# HACK: check if opt-18 exists | ||
# otherwise use opt | ||
# On Linux, sometimes it's called opt-18, while on mac it seems to be just opt | ||
# Also, on some machines, just running `opt-18` hangs, so we pass the version flag | ||
if os.system("opt-18 --version") == 0: | ||
opt = "opt-18" | ||
else: | ||
opt = "opt" | ||
|
||
# https://llvm.org/docs/Passes.html#dot-cfg-print-cfg-of-function-to-dot-file | ||
cmd = f"{opt} -disable-output -passes=dot-cfg {bench}-{mode}.ll" | ||
os.system(cmd) | ||
|
||
# Delete the -init.ll file (We don't need it for nightly, | ||
# so just reduce the amount of clutter we copy to the nightly machine) | ||
os.system(f"rm {bench}-{mode}-init.ll") | ||
|
||
# Find all the dot files (can't use glob because it doesn't match hidden files) | ||
# There are also a bunch of files that start with ._Z that I don't think we care about? | ||
dots = [f for f in os.listdir(".") if f.endswith(".dot") and not f.startswith("._Z") and not f.startswith("._bril")] | ||
for dot in dots: | ||
name = dot.split(".")[1] | ||
|
||
# Convert to png | ||
cmd = f"dot -Tpng -o {name}.png {dot}" | ||
os.system(cmd) | ||
|
||
pngs = glob.glob("*.png") | ||
print(f"Generated {len(pngs)} CFGs for {bench} {mode}") | ||
with open("png_names.txt", "w") as f: | ||
f.write("\n".join(pngs)) | ||
|
||
# Clean up dot files | ||
os.system("rm .*.dot") | ||
|
||
# Reset dir | ||
os.chdir(cwd) | ||
|
||
|
||
if __name__ == '__main__': | ||
# expect a single argument | ||
if len(os.sys.argv) != 2: | ||
print("Usage: generate_line_counts.py <data directory>") | ||
exit(1) | ||
data_dir = os.sys.argv[1] | ||
benchmarks = os.listdir(data_dir) | ||
for bench in benchmarks: | ||
make_cfgs(bench, data_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
async function showIR(benchmark, runMode) { | ||
const llvm = await fetchText( | ||
`./data/llvm/${benchmark}/${runMode}/${benchmark}-${runMode}.ll`, | ||
); | ||
document.getElementById("llvm-ir").innerText = llvm; | ||
} | ||
|
||
async function showCFGs(benchmark, runMode) { | ||
let pngs = ( | ||
await fetchText(`./data/llvm/${benchmark}/${runMode}/png_names.txt`) | ||
).split("\n"); | ||
|
||
// Move main.png and _main.png to top | ||
const _main = "_main.png"; | ||
if (pngs.includes(_main)) { | ||
pngs = pngs.filter((x) => x !== _main); | ||
pngs.unshift(_main); | ||
} | ||
const main = "main.png"; | ||
if (pngs.includes(main)) { | ||
pngs = pngs.filter((x) => x !== main); | ||
pngs.unshift(main); | ||
} | ||
|
||
const pngContainer = document.getElementById("llvm-cfg"); | ||
pngs.forEach((png) => { | ||
const elt = document.createElement("div"); | ||
|
||
const btn = document.createElement("button"); | ||
btn.innerText = `\u25B6 Show ${png}`; | ||
btn.classList.add("collapsible"); | ||
btn.classList.add("pngToggle"); | ||
btn.onclick = (elt) => | ||
toggle(elt.target, `\u25B6 Show ${png}`, `\u25BC Hide ${png}`); | ||
|
||
elt.appendChild(btn); | ||
|
||
const img = document.createElement("img"); | ||
img.classList.add("cfg"); | ||
img.classList.add("collapsed"); | ||
img.src = `data/llvm/${benchmark}/${runMode}/${png}`; | ||
elt.appendChild(img); | ||
|
||
pngContainer.appendChild(elt); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.