Index: MicroBenchmarks/CMakeLists.txt =================================================================== --- MicroBenchmarks/CMakeLists.txt +++ MicroBenchmarks/CMakeLists.txt @@ -5,4 +5,4 @@ add_subdirectory(LCALS) add_subdirectory(harris) add_subdirectory(ImageProcessing) - +add_subdirectory(LoopInterchange) Index: MicroBenchmarks/LoopInterchange/CMakeLists.txt =================================================================== --- /dev/null +++ MicroBenchmarks/LoopInterchange/CMakeLists.txt @@ -0,0 +1,9 @@ +llvm_test_run(WORKDIR ${CMAKE_CURRENT_BINARY_DIR}) + +llvm_test_verify(WORKDIR ${CMAKE_CURRENT_BINARY_DIR} + ${FPCMP} LoopInterchange.reference_output LoopInterchange.txt +) +llvm_test_executable(LoopInterchange main.cpp) +llvm_test_data(LoopInterchange LoopInterchange.reference_output) + +target_link_libraries(LoopInterchange benchmark) Index: MicroBenchmarks/LoopInterchange/LoopInterchange.reference_output =================================================================== --- /dev/null +++ MicroBenchmarks/LoopInterchange/LoopInterchange.reference_output @@ -0,0 +1 @@ +test1: 14950 Index: MicroBenchmarks/LoopInterchange/main.cpp =================================================================== --- /dev/null +++ MicroBenchmarks/LoopInterchange/main.cpp @@ -0,0 +1,67 @@ +#include +#include +#include + +#define BENCHMARK_LIB +#ifdef BENCHMARK_LIB +#include "benchmark/benchmark.h" +#endif + +int A[1000][1000]; +void init() { + for (unsigned i = 0; i < 1000; i++) + for (unsigned j = 0; j < 1000; j++) + A[i][j] = i + j; +} + +int y = 0; + +static int test1(int M, int N) { + + for (unsigned i = 0; i < 100; i++) { + y = 0; + for (unsigned j = 0; j < 100; j++) { + A[i][j] += 1; + y += A[i][j]; + } + } + return y; +} + +int main(int argc, char *argv[]) { +#ifdef BENCHMARK_LIB + ::benchmark::Initialize(&argc, argv); +#endif + + init(); + + // Run kernels once, to test functionality. + std::ofstream myfile ("./LoopInterchange.txt"); + if (myfile.is_open()) { + int y = test1(100, 100); + myfile << "test1: " << y << "\n"; + myfile.close(); + } +#ifdef BENCHMARK_LIB + ::benchmark::RunSpecifiedBenchmarks(); +#endif + return (EXIT_SUCCESS); +} + +#ifdef BENCHMARK_LIB +void BENCHMARK_LI1(benchmark::State &state) { + int N = state.range(0); + int M = state.range(0); + + while (state.KeepRunning()) { + int y = test1(M, N); + if (state.range(0) == 20) + printf("%d\n", y); + } +} +#endif + +BENCHMARK(BENCHMARK_LI1) + ->RangeMultiplier(2) + ->Range(500, 1000) + ->Unit(benchmark::kMicrosecond);