Commit 90e58703 authored by guruhegde's avatar guruhegde

Add LoopSplitter test case

parent 73443b95
......@@ -17,7 +17,6 @@ class TASForLoop;
class LoopSplitter {
llvm::Function * F;
llvm::LoopInfo * LI;
llvm::DominatorTree * DT;
llvm::SmallVector<llvm::Value *, 4> AnnotatedVariables;
llvm::SmallVector<llvm::Instruction *, 4> AnnotatedVariableDefPoints;
llvm::SmallVector<llvm::Value *, 4> PrefetchAddresses;
......@@ -25,7 +24,7 @@ class LoopSplitter {
public:
LoopSplitter(llvm::Function * F_, llvm::LoopInfo * LI_, llvm::DominatorTree * DT_)
: F(F_), LI(LI_), DT(DT_) {}
: F(F_), LI(LI_) {}
bool run();
void addEmptyLoop(llvm::BasicBlock * InsertBefore);
......
......@@ -5,6 +5,7 @@ add_executable(tests
blockPredication_test.cpp
cacheAnalysis_test.cpp
common_test.cpp
loopSplitter_test.cpp
utils_test.cpp)
set(LLVM_LINK_COMPONENTS
......
#include <stdlib.h>
#define EXPENSIVE __attribute__((annotate("expensive")))
// Function with single loop
int fn(int *in, int N) {
int * a EXPENSIVE = in;
int b = 0;
for (int i = 0; i < N; ++i) {
*a = *a + i;
b = b + i;
}
return b;
}
int fn_ref(int *in, int N) {
int * a = in;
int b = 0;
for (int i = 0; i < N; ++i) {
*a = *a + i;
b = b + i;
}
return b;
}
int main() {
int rc = 0;
{
int N = 2;
int * in = (int *) malloc(sizeof(int) * N);
int * ref_in = (int *) malloc(sizeof(int) * N);
int ret = fn(in, N);
if (ret != fn_ref(ref_in, N))
rc--;
free(in);
free(ref_in);
}
return rc;
}
#include "catch.hpp"
#include "LoopSplitter.h"
#include "Util.h"
#include "ToolUtil.h"
#include <llvm/AsmParser/Parser.h>
#include <llvm/ADT/PostOrderIterator.h>
#include <llvm/ADT/SCCIterator.h>
#include <llvm/ADT/SmallVector.h>
#include <llvm/Bitcode/BitcodeWriter.h>
#include <llvm/IR/CFG.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/Instruction.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/TypeFinder.h>
#include <llvm/IR/Verifier.h>
#include <llvm/IRReader/IRReader.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/Support/SourceMgr.h>
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<Module> parseIR(string Filename, string FileDir) {
std::unique_ptr<Module> 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 = "multiblock_fn";
auto M = parseIR(generateIR(filePrefix + string(".c"), input_dir), input_dir);
REQUIRE(M != nullptr);
// Function with 2 arguments and int return type.
auto F = M->getFunction(functionName);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment