[RISCV] Regenerate autogen test to remove spurious diff
[llvm-project.git] / llvm / examples / Kaleidoscope / MCJIT / cached / split-lib.py
blob7a289e868a9ce508d448de2208e2c7dd9a540c9b
1 #!/usr/bin/env python
3 from __future__ import print_function
6 class TimingScriptGenerator:
7 """Used to generate a bash script which will invoke the toy and time it"""
9 def __init__(self, scriptname, outputname):
10 self.shfile = open(scriptname, "w")
11 self.timeFile = outputname
12 self.shfile.write('echo "" > %s\n' % self.timeFile)
14 def writeTimingCall(self, irname, callname):
15 """Echo some comments and invoke both versions of toy"""
16 rootname = irname
17 if "." in irname:
18 rootname = irname[: irname.rfind(".")]
19 self.shfile.write(
20 'echo "%s: Calls %s" >> %s\n' % (callname, irname, self.timeFile)
22 self.shfile.write('echo "" >> %s\n' % self.timeFile)
23 self.shfile.write('echo "With MCJIT" >> %s\n' % self.timeFile)
24 self.shfile.write(
25 '/usr/bin/time -f "Command %C\\n\\tuser time: %U s\\n\\tsytem time: %S s\\n\\tmax set: %M kb"'
27 self.shfile.write(" -o %s -a " % self.timeFile)
28 self.shfile.write(
29 "./toy-mcjit -use-object-cache -input-IR=%s < %s > %s-mcjit.out 2> %s-mcjit.err\n"
30 % (irname, callname, rootname, rootname)
32 self.shfile.write('echo "" >> %s\n' % self.timeFile)
33 self.shfile.write('echo "With MCJIT again" >> %s\n' % self.timeFile)
34 self.shfile.write(
35 '/usr/bin/time -f "Command %C\\n\\tuser time: %U s\\n\\tsytem time: %S s\\n\\tmax set: %M kb"'
37 self.shfile.write(" -o %s -a " % self.timeFile)
38 self.shfile.write(
39 "./toy-mcjit -use-object-cache -input-IR=%s < %s > %s-mcjit.out 2> %s-mcjit.err\n"
40 % (irname, callname, rootname, rootname)
42 self.shfile.write('echo "" >> %s\n' % self.timeFile)
43 self.shfile.write('echo "With JIT" >> %s\n' % self.timeFile)
44 self.shfile.write(
45 '/usr/bin/time -f "Command %C\\n\\tuser time: %U s\\n\\tsytem time: %S s\\n\\tmax set: %M kb"'
47 self.shfile.write(" -o %s -a " % self.timeFile)
48 self.shfile.write(
49 "./toy-jit -input-IR=%s < %s > %s-mcjit.out 2> %s-mcjit.err\n"
50 % (irname, callname, rootname, rootname)
52 self.shfile.write('echo "" >> %s\n' % self.timeFile)
53 self.shfile.write('echo "" >> %s\n' % self.timeFile)
56 class LibScriptGenerator:
57 """Used to generate a bash script which will convert Kaleidoscope files to IR"""
59 def __init__(self, filename):
60 self.shfile = open(filename, "w")
62 def writeLibGenCall(self, libname, irname):
63 self.shfile.write("./toy-ir-gen < %s 2> %s\n" % (libname, irname))
66 def splitScript(inputname, libGenScript, timingScript):
67 rootname = inputname[:-2]
68 libname = rootname + "-lib.k"
69 irname = rootname + "-lib.ir"
70 callname = rootname + "-call.k"
71 infile = open(inputname, "r")
72 libfile = open(libname, "w")
73 callfile = open(callname, "w")
74 print("Splitting %s into %s and %s" % (inputname, callname, libname))
75 for line in infile:
76 if not line.startswith("#"):
77 if line.startswith("print"):
78 callfile.write(line)
79 else:
80 libfile.write(line)
81 libGenScript.writeLibGenCall(libname, irname)
82 timingScript.writeTimingCall(irname, callname)
85 # Execution begins here
86 libGenScript = LibScriptGenerator("make-libs.sh")
87 timingScript = TimingScriptGenerator("time-lib.sh", "lib-timing.txt")
89 script_list = [
90 "test-5000-3-50-50.k",
91 "test-5000-10-100-10.k",
92 "test-5000-10-5-10.k",
93 "test-5000-10-1-0.k",
94 "test-1000-3-10-50.k",
95 "test-1000-10-100-10.k",
96 "test-1000-10-5-10.k",
97 "test-1000-10-1-0.k",
98 "test-200-3-2-50.k",
99 "test-200-10-40-10.k",
100 "test-200-10-2-10.k",
101 "test-200-10-1-0.k",
104 for script in script_list:
105 splitScript(script, libGenScript, timingScript)
106 print("All done!")