fixup before submit
This commit is contained in:
parent
8e570f6b4d
commit
648350d743
3
.vscode/launch.json
vendored
3
.vscode/launch.json
vendored
@ -11,7 +11,8 @@
|
|||||||
"program": "${workspaceFolder}/build/sysy",
|
"program": "${workspaceFolder}/build/sysy",
|
||||||
// "args": ["../sysytests/functional_2021/069_greatest_common_divisor.sy", "-S", "-o", "build/my.s", "-O1", "-emit-llvm"],
|
// "args": ["../sysytests/functional_2021/069_greatest_common_divisor.sy", "-S", "-o", "build/my.s", "-O1", "-emit-llvm"],
|
||||||
// "args" : ["-S", "../sysytests/functional_2022/21_if_test2.sy", "-o", "build/dbg.s", "-emit-llvm", "-O1",],
|
// "args" : ["-S", "../sysytests/functional_2022/21_if_test2.sy", "-o", "build/dbg.s", "-emit-llvm", "-O1",],
|
||||||
"args" : ["-S", "../sysytests/functional_h_2022/29_long_line.sy", "-o", "build/dbg.s", "-emit-llvm", "-O1",],
|
// "args" : ["-S", "../sysytests/functional_h_2022/29_long_line.sy", "-o", "build/dbg.s", "-emit-llvm", "-O1",],
|
||||||
|
"args" : ["-S", "../sysytests/performance_2021fin/conv0.sy", "-o", "build/dbg.s", "-emit-llvm", "-O1",],
|
||||||
"cwd": "${workspaceFolder}"
|
"cwd": "${workspaceFolder}"
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|||||||
@ -207,31 +207,46 @@ class BatTest:
|
|||||||
self.count_error = 0
|
self.count_error = 0
|
||||||
self.label = f"{compiler.scheme['name']}_{compiler_rf.scheme['name']}"
|
self.label = f"{compiler.scheme['name']}_{compiler_rf.scheme['name']}"
|
||||||
self.diffout_template = f"{compiler.target_dir}/{{testcase}}/{self.label}.diff"
|
self.diffout_template = f"{compiler.target_dir}/{{testcase}}/{self.label}.diff"
|
||||||
|
self.perf_template = f"perf.log"
|
||||||
|
|
||||||
def bat_case(self, testcase, compile=False, emit_llvm=True):
|
def bat_case(self, testcase, compile=False, emit_llvm=True, perf=False):
|
||||||
Print_C.print_subheader(f"Diff test {self.label} on {testcase}")
|
Print_C.print_subheader(f"Diff test {self.label} on {testcase}")
|
||||||
if compile:
|
if compile:
|
||||||
self.compiler.clean_case(testcase)
|
self.compiler.clean_case(testcase)
|
||||||
self.compiler_rf.clean_case(testcase)
|
self.compiler_rf.clean_case(testcase)
|
||||||
self.compiler.compile_case(testcase, emit_llvm)
|
self.compiler.compile_case(testcase, emit_llvm)
|
||||||
self.compiler_rf.compile_case(testcase, emit_llvm)
|
self.compiler_rf.compile_case(testcase, emit_llvm)
|
||||||
if not compiler.run_case(testcase, 0): return False
|
if not perf:
|
||||||
if not compiler_rf.run_case(testcase, 0): return False
|
# should not run diff out when in perf mode, since running time may be different
|
||||||
myout = compiler.myout_template.format(testcase=testcase)
|
if not compiler.run_case(testcase, 0): return False
|
||||||
refout = compiler_rf.myout_template.format(testcase=testcase)
|
if not compiler_rf.run_case(testcase, 0): return False
|
||||||
diffout = self.diffout_template.format(testcase=testcase)
|
myout = compiler.myout_template.format(testcase=testcase)
|
||||||
diffout_file = open(diffout, "w")
|
refout = compiler_rf.myout_template.format(testcase=testcase)
|
||||||
p = subprocess.run(f"diff {myout} {refout}".split(), stdout=diffout_file, stderr=diffout_file, bufsize=1)
|
null_file = open(os.devnull, "w")
|
||||||
diffout_file.close()
|
subprocess.run(f"sed -i /TOTAL/d {myout} {refout}".split(), bufsize=1)
|
||||||
if p.returncode != 0:
|
null_file.close()
|
||||||
Print_C.print_error(f"Different output for {testcase}. See {diffout}")
|
diffout = self.diffout_template.format(testcase=testcase)
|
||||||
return False
|
diffout_file = open(diffout, "w")
|
||||||
|
p = subprocess.run(f"diff -B {myout} {refout}".split(), stdout=diffout_file, stderr=diffout_file, bufsize=1)
|
||||||
|
diffout_file.close()
|
||||||
|
if p.returncode != 0:
|
||||||
|
Print_C.print_error(f"Different output for {testcase}. See {diffout}")
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
perflog_file = open(self.perf_template, "a")
|
||||||
|
t0 = time.time()
|
||||||
|
if not compiler.run_case(testcase, 0): return False
|
||||||
|
t1 = time.time()
|
||||||
|
perflog_file.write("{testcase}_my: {time:.3f}\n".format(testcase=testcase, time=(t1-t0)))
|
||||||
|
if not compiler_rf.run_case(testcase, 0): return False
|
||||||
|
t2 = time.time()
|
||||||
|
perflog_file.write("{testcase}_rf: {time:.3f}\n".format(testcase=testcase, time=(t2-t1)))
|
||||||
|
perflog_file.close()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def bat_all_tests(self, compile=False, emit_llvm=True):
|
def bat_all_tests(self, compile=False, emit_llvm=True, perf=False):
|
||||||
|
|
||||||
for testcase in self.testcases:
|
for testcase in self.testcases:
|
||||||
if not self.bat_case(testcase, compile, emit_llvm): break
|
if not self.bat_case(testcase, compile, emit_llvm, perf): break
|
||||||
|
|
||||||
scheme_ref = {
|
scheme_ref = {
|
||||||
"name": "ref",
|
"name": "ref",
|
||||||
@ -257,7 +272,7 @@ scheme_my_rv64 = {
|
|||||||
"ir_asm": "llc --march=x86 --relocation-model=pic {ir} -o {asm}",
|
"ir_asm": "llc --march=x86 --relocation-model=pic {ir} -o {asm}",
|
||||||
"asm_obj": "riscv64-linux-gnu-as {asm} -o {obj}",
|
"asm_obj": "riscv64-linux-gnu-as {asm} -o {obj}",
|
||||||
"obj_bin": f"riscv64-linux-gnu-gcc -static {{obj}} {LIB_PATH_RV64} -o {{bin}}",
|
"obj_bin": f"riscv64-linux-gnu-gcc -static {{obj}} {LIB_PATH_RV64} -o {{bin}}",
|
||||||
"sy_asm": f"build/sysy -S {{sy}} -o {{asm}} -emit-llvm -O1",
|
"sy_asm": f"build/sysy -S {{sy}} -o {{asm}} -O1",
|
||||||
"run": f"spike /usr/local/riscv64-linux-gnu/bin/pk {{bin}}",
|
"run": f"spike /usr/local/riscv64-linux-gnu/bin/pk {{bin}}",
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,11 +292,22 @@ scheme_ref_rv64 = {
|
|||||||
"run": f"spike /usr/local/riscv64-linux-gnu/bin/pk {{bin}}",
|
"run": f"spike /usr/local/riscv64-linux-gnu/bin/pk {{bin}}",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scheme_ref_rv64_o2 = {
|
||||||
|
"name" : "ref_rv64",
|
||||||
|
"sy_ir": f"clang -x c -c -fPIE -fno-stack-protector -S -emit-llvm --target=riscv64-linux-gnu -include {HDR_PATH} {{sy}} -o {{ir}}",
|
||||||
|
"ir_asm": "llc --march=riscv64 --relocation-model=pic --float-abi=hard -mcpu=sifive-7-rv64 -mattr=+f,+m,+d {ir} -o {asm}",
|
||||||
|
"asm_obj": "riscv64-linux-gnu-as {asm} -o {obj}",
|
||||||
|
"obj_bin": f"riscv64-linux-gnu-gcc -static {{obj}} {LIB_PATH_RV64} -o {{bin}}",
|
||||||
|
"sy_asm": f"clang -O2 -x c -S -fno-stack-protector -no-integrated-as --target=riscv64-linux-gnu -march=rv64gc -fPIE -mfloat-abi=hard -mcpu=sifive-7-rv64 -include {HDR_PATH} {{sy}} -o {{asm}}",
|
||||||
|
"run": f"spike /usr/local/riscv64-linux-gnu/bin/pk {{bin}}",
|
||||||
|
}
|
||||||
|
|
||||||
schemes = {
|
schemes = {
|
||||||
"my": scheme_my,
|
"my": scheme_my,
|
||||||
"ref": scheme_ref,
|
"ref": scheme_ref,
|
||||||
"ref_rv64": scheme_ref_rv64,
|
"ref_rv64": scheme_ref_rv64,
|
||||||
"my_rv64": scheme_my_rv64,
|
"my_rv64": scheme_my_rv64,
|
||||||
|
"ref_rv64_o2": scheme_ref_rv64_o2,
|
||||||
}
|
}
|
||||||
# subprocess.run(f"llc -O3 -march=arm -mcpu=cortex-a72 -float-abi=hard -filetype=asm {ir} -o {asm}".split(), stdout=log_file, stderr=log_file, bufsize=1)
|
# subprocess.run(f"llc -O3 -march=arm -mcpu=cortex-a72 -float-abi=hard -filetype=asm {ir} -o {asm}".split(), stdout=log_file, stderr=log_file, bufsize=1)
|
||||||
# subprocess.run(f"as -march=armv7-a -mfloat-abi=hard {asm} -o {obj}".split(), stdout=log_file, stderr=log_file, bufsize=1)
|
# subprocess.run(f"as -march=armv7-a -mfloat-abi=hard {asm} -o {obj}".split(), stdout=log_file, stderr=log_file, bufsize=1)
|
||||||
@ -299,6 +325,7 @@ if __name__ == "__main__":
|
|||||||
parser.add_argument('--run', action='store_true', default=False)
|
parser.add_argument('--run', action='store_true', default=False)
|
||||||
parser.add_argument('--bat', action='store_true', default=False)
|
parser.add_argument('--bat', action='store_true', default=False)
|
||||||
parser.add_argument('--emit_llvm', action='store_true', default=False)
|
parser.add_argument('--emit_llvm', action='store_true', default=False)
|
||||||
|
parser.add_argument('--perf', action='store_true', default=False)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
print(args)
|
print(args)
|
||||||
testcases = case_collector(args.case_selector, args.case_prefix)
|
testcases = case_collector(args.case_selector, args.case_prefix)
|
||||||
@ -313,12 +340,15 @@ if __name__ == "__main__":
|
|||||||
if not os.path.exists(testcase_dir):
|
if not os.path.exists(testcase_dir):
|
||||||
os.makedirs(testcase_dir)
|
os.makedirs(testcase_dir)
|
||||||
os.system(f"cp {testcase_src}.* {testcase_dir}/")
|
os.system(f"cp {testcase_src}.* {testcase_dir}/")
|
||||||
|
if args.perf:
|
||||||
|
schemes[args.scheme]["run"] = f"qemu-riscv64 {{bin}}"
|
||||||
|
schemes[args.ref]["run"] = f"qemu-riscv64 {{bin}}"
|
||||||
current_schem = schemes[args.scheme]
|
current_schem = schemes[args.scheme]
|
||||||
if args.bat:
|
if args.bat:
|
||||||
compiler = Compiler(scheme=current_schem,target_dir=target_dir, testcases=testcases)
|
compiler = Compiler(scheme=current_schem,target_dir=target_dir, testcases=testcases)
|
||||||
compiler_rf = Compiler(scheme=schemes[args.ref],target_dir=target_dir, testcases=testcases)
|
compiler_rf = Compiler(scheme=schemes[args.ref],target_dir=target_dir, testcases=testcases)
|
||||||
battester = BatTest(compiler, compiler_rf, testcases)
|
battester = BatTest(compiler, compiler_rf, testcases)
|
||||||
battester.bat_all_tests(args.compile, args.emit_llvm)
|
battester.bat_all_tests(args.compile, args.emit_llvm, args.perf)
|
||||||
elif args.compile:
|
elif args.compile:
|
||||||
compiler = Compiler(scheme=current_schem,target_dir=target_dir, testcases=testcases)
|
compiler = Compiler(scheme=current_schem,target_dir=target_dir, testcases=testcases)
|
||||||
compiler.prepare_dir()
|
compiler.prepare_dir()
|
||||||
|
|||||||
@ -232,7 +232,6 @@ std::any Visitor::visitVarDef(SysyParser::VarDefContext *ctx) {
|
|||||||
{base_ptr, CONST0, ConstantInt::New(array_value.size() * 4)},
|
{base_ptr, CONST0, ConstantInt::New(array_value.size() * 4)},
|
||||||
_state.current_bb
|
_state.current_bb
|
||||||
);
|
);
|
||||||
// TODO: BAAU-2021 calls memset in `libc` (not sysylib) to optimize this process
|
|
||||||
if (array_value[0]) InstStore::New(array_value[0], base_ptr, _state.current_bb);
|
if (array_value[0]) InstStore::New(array_value[0], base_ptr, _state.current_bb);
|
||||||
for (int i = 1; i < array_value.size(); ++i) {
|
for (int i = 1; i < array_value.size(); ++i) {
|
||||||
if (!array_value[i]) continue;
|
if (!array_value[i]) continue;
|
||||||
@ -625,6 +624,11 @@ std::any Visitor::visitUnaryExp(SysyParser::UnaryExpContext *ctx) {
|
|||||||
args.push_back(exp);
|
args.push_back(exp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (func->is_libfunc()) {
|
||||||
|
if (func_name == "starttime" || func_name == "stoptime") {
|
||||||
|
args.push_back(CONST0);
|
||||||
|
}
|
||||||
|
}
|
||||||
return InstCall::New(func, args, _state.current_bb);
|
return InstCall::New(func, args, _state.current_bb);
|
||||||
}
|
}
|
||||||
else if (ctx->primaryExp()) {
|
else if (ctx->primaryExp()) {
|
||||||
|
|||||||
@ -482,7 +482,7 @@ void Visitor::llir_gen(std::ostream &ostr) {
|
|||||||
auto lib_func_type = std::dynamic_pointer_cast<FunctionType>(lib_func->type);
|
auto lib_func_type = std::dynamic_pointer_cast<FunctionType>(lib_func->type);
|
||||||
ostr << "declare"
|
ostr << "declare"
|
||||||
<< " " << lib_func_type->return_type->to_IR_string() << " "
|
<< " " << lib_func_type->return_type->to_IR_string() << " "
|
||||||
<< "@" << lib_func_name << "(";
|
<< "@" << lib_func->name << "(";
|
||||||
auto ¶m_list = lib_func->fparam_list;
|
auto ¶m_list = lib_func->fparam_list;
|
||||||
for (int i = 0; i < (int)param_list.size() - 1; ++i) {
|
for (int i = 0; i < (int)param_list.size() - 1; ++i) {
|
||||||
ostr << param_list[i]->type->to_IR_string() << ", ";
|
ostr << param_list[i]->type->to_IR_string() << ", ";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user