#include "catch.hpp" #include "LoopSplitter.h" #include "Util.h" #include "ToolUtil.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include extern std::string input_dir; // This contains path to input test files using namespace llvm; using namespace std; using namespace tas; static LLVMContext C; static SMDiagnostic Err; static unique_ptr parseIR(string Filename, string FileDir) { std::unique_ptr M (parseIRFile(FileDir + Filename, Err, C)); if (!M) Err.print("Error parsing IR: ", errs()); return M; } TEST_CASE("fn with single loop") { std::string filePrefix = "loopsplitter_test1"; std::string functionName = "fn"; auto IR = generateIR(filePrefix + string(".c"), input_dir); /* vector OptList {"indvars", "loop-simplify", "lcssa"}; IR= runOpt(IR, input_dir, OptList); */ auto M = parseIR(IR, input_dir); REQUIRE(M != nullptr); // Function with 2 arguments and int return type. auto F = M->getFunction(functionName); DominatorTree DT(*F); LoopInfo LI(DT); LoopSplitter LS(F, &LI); LS.run(); REQUIRE(LS.getStats().AnnotatedVarsSize == 1); REQUIRE(LS.getStats().VarUsePointsSize == 1); //F->print(errs()); auto asmFile = writeToAsmFile(*M); auto TestObject = generateObject(asmFile); auto binary = linkObjects(vector{TestObject}, string("loopSplitter_test11")); // Run the binary binary.insert(0, "./"); auto ret = system(binary.c_str()); REQUIRE(ret == 0); } TEST_CASE("fast_flows_packet loop split") { std::string filePrefix = "fast_flows"; auto M = parseIR(generateIR(filePrefix + string(".c"), input_dir, true), input_dir); REQUIRE(M != nullptr); M->setSourceFileName(filePrefix + string("_batch.ll")); { std::string functionName = "fast_flows_packet"; auto F = M->getFunction(functionName); DominatorTree DT(*F); LoopInfo LI(DT); LoopSplitter LS(F, &LI); LS.run(); //F->print(errs()); auto asmFile = writeToAsmFile(*M); auto TestObject = generateObject(asmFile); } }