├── src
├── Release+Asserts
│ ├── .dir
│ ├── Cast.o
│ ├── GEP.o
│ ├── test.o
│ ├── Power.o
│ ├── ArrayName.o
│ ├── LoopDepth.o
│ ├── Loop_II.o
│ ├── MemOpNum.o
│ ├── Resource.o
│ ├── SetPragma.o
│ ├── UpdateMem.o
│ ├── Dataflow_II.o
│ ├── FindLatency.o
│ ├── Function_II.o
│ ├── InstLibrary.o
│ ├── LoopLatency.o
│ ├── Reschedule.o
│ ├── LoopInterface.o
│ ├── PartitionNum.o
│ ├── SetParameter.o
│ ├── ComputeFixedPath.o
│ ├── FunctionLatency.o
│ ├── LoopUnrollFactor.o
│ ├── PartitionFactor.o
│ ├── ComputeCriticalPath.o
│ ├── ComputeMemLatency.o
│ ├── EvaluateDependency.o
│ ├── Power.d
│ ├── GEP.d
│ ├── Cast.d
│ ├── ArrayName.d
│ ├── LoopDepth.d
│ ├── SetPragma.d
│ └── ComputeFixedPath.d
├── Makefile
├── LoopDepth.h
├── InstLibrary.h
├── PartitionFactor.h
├── Power.h
├── Cast.h
├── ArrayName.h
├── Dataflow_II.h
├── LoopInterface.h
├── Constant.h
├── EvaluateDependency.h
├── LoopUnrollFactor.h
├── MemOpNum.h
├── PartitionNum.h
├── GEP.h
├── SetParameter.h
├── Cast.cpp
├── SetPragma.h
├── LoopDepth.cpp
├── FunctionLatency.h
├── Loop_II.h
├── Function_II.h
├── PartitionFactor.cpp
├── FindLatency.h
├── UpdateMem.h
├── LoopLatency.h
├── Power.cpp
├── ComputeFixedPath.h
├── Resource.h
├── LoopInterface.cpp
├── ArrayName.cpp
├── ComputeMemLatency.h
├── ComputeCriticalPath.h
├── Reschedule.h
├── LoopUnrollFactor.cpp
├── test.h
├── EvaluateDependency.cpp
├── Dataflow_II.cpp
├── Library.h
├── FindLatency.cpp
├── MemOpNum.cpp
├── InstLibrary.cpp
└── UpdateMem.cpp
├── cfg
├── bicg.png
└── gemm.png
├── runMyPro.sh
├── test_c
├── utilities
│ ├── papi_counters.list
│ ├── benchmark_list
│ ├── clean.pl
│ ├── run-all.pl
│ ├── create_cpped_version.pl
│ ├── makefile-gen.pl
│ ├── polybench.spec
│ ├── template-for-new-benchmark.c
│ ├── time_benchmark.sh
│ ├── header-gen.pl
│ └── polybench.R
├── bicg
│ ├── bicg.c
│ ├── bicg.h
│ └── main.c
└── gemm
│ ├── gemm.c
│ ├── gemm.h
│ └── main.c
├── .project
├── CMakeLists.txt
├── test
├── bicg.ll
└── gemm.ll
└── README.md
/src/Release+Asserts/.dir:
--------------------------------------------------------------------------------
1 | Sun Oct 1 15:02:55 CST 2017
2 |
--------------------------------------------------------------------------------
/cfg/bicg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/cfg/bicg.png
--------------------------------------------------------------------------------
/cfg/gemm.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/cfg/gemm.png
--------------------------------------------------------------------------------
/src/Release+Asserts/Cast.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/Cast.o
--------------------------------------------------------------------------------
/src/Release+Asserts/GEP.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/GEP.o
--------------------------------------------------------------------------------
/src/Release+Asserts/test.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/test.o
--------------------------------------------------------------------------------
/src/Release+Asserts/Power.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/Power.o
--------------------------------------------------------------------------------
/src/Release+Asserts/ArrayName.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/ArrayName.o
--------------------------------------------------------------------------------
/src/Release+Asserts/LoopDepth.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/LoopDepth.o
--------------------------------------------------------------------------------
/src/Release+Asserts/Loop_II.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/Loop_II.o
--------------------------------------------------------------------------------
/src/Release+Asserts/MemOpNum.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/MemOpNum.o
--------------------------------------------------------------------------------
/src/Release+Asserts/Resource.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/Resource.o
--------------------------------------------------------------------------------
/src/Release+Asserts/SetPragma.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/SetPragma.o
--------------------------------------------------------------------------------
/src/Release+Asserts/UpdateMem.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/UpdateMem.o
--------------------------------------------------------------------------------
/src/Release+Asserts/Dataflow_II.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/Dataflow_II.o
--------------------------------------------------------------------------------
/src/Release+Asserts/FindLatency.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/FindLatency.o
--------------------------------------------------------------------------------
/src/Release+Asserts/Function_II.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/Function_II.o
--------------------------------------------------------------------------------
/src/Release+Asserts/InstLibrary.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/InstLibrary.o
--------------------------------------------------------------------------------
/src/Release+Asserts/LoopLatency.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/LoopLatency.o
--------------------------------------------------------------------------------
/src/Release+Asserts/Reschedule.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/Reschedule.o
--------------------------------------------------------------------------------
/src/Release+Asserts/LoopInterface.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/LoopInterface.o
--------------------------------------------------------------------------------
/src/Release+Asserts/PartitionNum.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/PartitionNum.o
--------------------------------------------------------------------------------
/src/Release+Asserts/SetParameter.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/SetParameter.o
--------------------------------------------------------------------------------
/src/Release+Asserts/ComputeFixedPath.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/ComputeFixedPath.o
--------------------------------------------------------------------------------
/src/Release+Asserts/FunctionLatency.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/FunctionLatency.o
--------------------------------------------------------------------------------
/src/Release+Asserts/LoopUnrollFactor.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/LoopUnrollFactor.o
--------------------------------------------------------------------------------
/src/Release+Asserts/PartitionFactor.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/PartitionFactor.o
--------------------------------------------------------------------------------
/src/Release+Asserts/ComputeCriticalPath.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/ComputeCriticalPath.o
--------------------------------------------------------------------------------
/src/Release+Asserts/ComputeMemLatency.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/ComputeMemLatency.o
--------------------------------------------------------------------------------
/src/Release+Asserts/EvaluateDependency.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjru/COMBA/HEAD/src/Release+Asserts/EvaluateDependency.o
--------------------------------------------------------------------------------
/runMyPro.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | rm -rf /home/zjr/HLSModel/llvm-3.4/lib/Transforms/Comba/src/Release+Asserts
3 | cd ./src
4 | make
5 |
--------------------------------------------------------------------------------
/src/Makefile:
--------------------------------------------------------------------------------
1 | LEVEL = ../../../..
2 | LIBRARYNAME = LLVMTest
3 | LOADABLE_MODULE = 1
4 | USEDLIBS =
5 |
6 | include $(LEVEL)/Makefile.common
7 |
--------------------------------------------------------------------------------
/test_c/utilities/papi_counters.list:
--------------------------------------------------------------------------------
1 | // Counters must be delimited with ',' including the last one.
2 | // C/C++ comments are allowed.
3 | // Both native and standard PAPI events are supported.
4 | "PAPI_TOT_CYC",
5 | "L1D:REPL",
6 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | comba
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/Release+Asserts/Power.d:
--------------------------------------------------------------------------------
1 | /home/zjr/HLSModel/llvm-3.4/lib/Transforms/Comba/src/Release+Asserts/Power.o \
2 | /home/zjr/HLSModel/llvm-3.4/lib/Transforms/Comba/src/Release+Asserts/Power.d: \
3 | Power.cpp Constant.h Power.h
4 |
5 | Constant.h:
6 |
7 | Power.h:
8 |
--------------------------------------------------------------------------------
/src/LoopDepth.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef LOOPDEPTH_H_
15 | #define LOOPDEPTH_H_
16 |
17 | #include "test.h"
18 |
19 | int nested_loop_depth_for_loop(Loop* L);
20 |
21 | #endif
22 |
--------------------------------------------------------------------------------
/src/InstLibrary.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef INSTLIBRARY_H_
15 | #define INSTLIBRARY_H_
16 |
17 | #include "test.h"
18 |
19 | float inst_latency_in_library(Instruction *inst);
20 |
21 | #endif
22 |
--------------------------------------------------------------------------------
/src/PartitionFactor.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef PARTITIONFACTOR_H_
15 | #define PARTITIONFACTOR_H_
16 |
17 | #include "test.h"
18 |
19 | int partition_factor(Instruction *inst);
20 |
21 | #endif
22 |
--------------------------------------------------------------------------------
/src/Power.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef POWER_H_
15 | #define POWER_H_
16 |
17 | bool is_power_of_two(int n);
18 | int closest_bound_power_two(int n);
19 | int get_power_of_two(int n);
20 |
21 | #endif
22 |
23 |
--------------------------------------------------------------------------------
/src/Cast.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef CAST_H_
15 | #define CAST_H_
16 |
17 | #include "test.h"
18 |
19 | bool inst_is_cast(Instruction *inst);
20 | Instruction *get_cast_inst(Instruction *inst);
21 |
22 | #endif
23 |
--------------------------------------------------------------------------------
/src/ArrayName.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 | #ifndef ARRAYNAME_H_
14 | #define ARRAYNAME_H_
15 |
16 | #include "test.h"
17 |
18 | Value *check_PHI_operand(PHINode *phi);
19 | Value *get_array_name(Instruction *inst);
20 |
21 | #endif
22 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_llvm_loadable_module( LLVMTest
2 | test.cpp
3 | ArrayName.cpp
4 | Cast.cpp
5 | ComputeCriticalPath.cpp
6 | ComputeFixedPath.cpp
7 | ComputeMemLatency.cpp
8 | EvaluateDependency.cpp
9 | FindLatency.cpp
10 | GEP.cpp
11 | InstLibrary.cpp
12 | Loop_II.cpp
13 | LoopDepth.cpp
14 | LoopLatency.cpp
15 | LoopUnrollFactor.cpp
16 | MemOpNum.cpp
17 | PartitionFactor.cpp
18 | PartitionNum.cpp
19 | Power.cpp
20 | Reschedule.cpp
21 | UpdateMem.cpp
22 | )
23 |
--------------------------------------------------------------------------------
/src/Dataflow_II.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef DATAFLOW_II_H_
15 | #define DATAFLOW_II_H_
16 |
17 | #include "test.h"
18 |
19 | bool check_dataflow(Function *F, LoopInfo* LI);
20 | int compute_dataflow_II(Function *F, LoopInfo* LI);
21 |
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/src/LoopInterface.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef LOOPINTERFACE_H_
15 | #define LOOPINTERFACE_H_
16 |
17 | #include "test.h"
18 |
19 | void get_loop_input(Loop *L, std::vector &loop_read);
20 | void get_loop_output(Loop *L, std::vector &loop_write);
21 |
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/src/Constant.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef CONSTANT_H_
15 | #define CONSTANT_H_
16 |
17 |
18 | #define inf 1<<30
19 | #define INSN_NUM_MUX 200
20 | #define INSN_NUM 1000
21 |
22 | #define port_num_read 2
23 | #define port_num_write_diff 2
24 | #define port_num_write_same 1
25 |
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/src/EvaluateDependency.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef EVALUATEDEPENDENCY_H_
15 | #define EVALUATEDEPENDENCY_H_
16 |
17 | #include "test.h"
18 |
19 | bool load_store_dependency(Instruction *inst_l, Instruction *inst_s);
20 | bool store_store_dependency(Instruction *inst_s1, Instruction *inst_s2);
21 | bool test_loop_carried_dependence(LoopInfo* LI, Loop *L);
22 |
23 |
24 | #endif
25 |
--------------------------------------------------------------------------------
/src/LoopUnrollFactor.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef LOOPUNROLLFACTOR_H_
15 | #define LOOPUNROLLFACTOR_H_
16 |
17 | #include "test.h"
18 |
19 | int total_unroll_factor(Loop *L);
20 | bool unroll_loop_relation(Loop *L1, Loop *L2);
21 | int total_unroll_factor_ls(LoopInfo *LI, Loop *L, Instruction *inst);
22 | int total_unroll_factor_op(LoopInfo *LI, Loop *L, Instruction *inst);
23 |
24 | #endif
25 |
--------------------------------------------------------------------------------
/src/MemOpNum.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef MEMOPNUM_H_
15 | #define MEMOPNUM_H_
16 |
17 | #include "test.h"
18 |
19 | int compute_BB_load_num(BasicBlock *itb, Instruction *inst);
20 | int compute_BB_store_num(BasicBlock *itb, Instruction *inst);
21 | int partition_mem_op_num(LoopInfo *LI, BasicBlock *bb, Instruction *inst);
22 | int compute_total_LS_num(LoopInfo* LI, Instruction *inst);
23 |
24 |
25 | #endif
26 |
--------------------------------------------------------------------------------
/src/PartitionNum.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef PARTITIONNUM_H_
15 | #define PARTITIONNUM_H_
16 |
17 | #include "test.h"
18 |
19 | int get_bank_number(Instruction *inst);
20 | int compute_array_element_offset(Instruction *inst, BasicBlock *bb, int base_variable);
21 | int get_unroll_SameBank_num(BasicBlock *bb, Instruction *inst, Instruction *inst1, std::vector &array_element_counted);
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/src/GEP.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef GEP_H_
15 | #define GEP_H_
16 |
17 | #include "test.h"
18 |
19 | GetElementPtrInst *get_GEP(Instruction *inst);
20 | int compute_gep_operand(Value *op, bool second_iteration_flag, int compute_second);
21 | int get_phi_second(Loop *L, PHINode *PHI);
22 | PHINode *get_phi(Instruction *inst, PHINode *PHI);
23 | int get_gep_phi(GetElementPtrInst *gep, PHINode *PHI);
24 |
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/src/SetParameter.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef SETPARAMETER_H_
15 | #define SETPARAMETER_H_
16 |
17 | #include "test.h"
18 |
19 |
20 | void set_loop_map(Loop *L,Loop *parent,Loop *loop,std::map loop_index_tmp,std::vector *loop_index);
21 | void set_loop_index(Function *F, LoopInfo* LI, Loop *L,std::map &loop_index_tmp,std::vector *loop_index);
22 | void set_array_index(Module &M);
23 | void set_array_map(Module &M);
24 | void store_function_IO(Module &M);
25 |
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/test_c/bicg/bicg.c:
--------------------------------------------------------------------------------
1 | /**
2 | * This version is stamped on May 10, 2016
3 | *
4 | * Contact:
5 | * Louis-Noel Pouchet
6 | * Tomofumi Yuki
7 | *
8 | * Web address: http://polybench.sourceforge.net
9 | */
10 | /* bicg.c: this file is part of PolyBench/C */
11 |
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 | #include "bicg.h"
18 |
19 | void kernel_bicg(int A[N][M], int s[M], int q[N], int p[M], int r[N])
20 | {
21 | int i, j;
22 | int m=M;
23 | int n=N;
24 | kernel_bicg_label2:for (i = 0; i < n; i++)
25 | {
26 | kernel_bicg_label0:for (j = 0; j < m; j++)
27 | {
28 | s[j] = s[j] + r[i] * A[i][j];
29 | q[i] = q[i] + A[i][j] * p[j];
30 | }
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/Cast.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #include "Cast.h"
15 |
16 | bool inst_is_cast(Instruction *inst)
17 | {
18 | unsigned opcode=inst->getOpcode();
19 | if((opcode==Instruction::Trunc)||(opcode==Instruction::ZExt)||(opcode==Instruction::SExt)||(opcode==Instruction::FPTrunc)||(opcode==Instruction::FPExt)){
20 | return true;
21 | }
22 | else{
23 | return false;
24 | }
25 |
26 | }
27 |
28 | Instruction *get_cast_inst(Instruction *inst)
29 | {
30 | Instruction *op_inst=NULL;
31 | Value *op=inst->getOperand(0);
32 | op_inst=dyn_cast(op);
33 | return op_inst;
34 | }
35 |
--------------------------------------------------------------------------------
/src/SetPragma.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef SETPRAGMA_H_
15 | #define SETPRAGMA_H_
16 |
17 | #include "test.h"
18 |
19 | void set_dataflow(Module &M);
20 | bool function_is_inline(Function *F);
21 | bool function_is_noinline(Function *F);
22 | bool has_subFn(Function *F);
23 | bool Fn_pipeline_modify(Function *F);
24 | void set_function_pipeline(Module &M);
25 | bool set_subFn_pipeline(Loop *L);
26 | void set_loop_counter_ul_pipeline(LoopInfo* LI, Function *F);
27 | void set_array_partition(Module &M);
28 | void keep_array_consistent(Function *callee, CallInst *call);
29 |
30 | #endif
31 |
--------------------------------------------------------------------------------
/src/LoopDepth.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #include "LoopDepth.h"
15 |
16 | int nested_loop_depth_for_loop(Loop* L)
17 | {
18 | int counter_depth=0;
19 | std::vector subLoops=L->getSubLoops();
20 | int subLoop_num = subLoops.size();
21 | if(subLoops.empty()){
22 | counter_depth += 1;
23 | }
24 | else{
25 | int counter=0;
26 | for(int j=0;j &instr_index_loop, std::vector > *dependence_loop);
20 | void reorder_load(Function *F, std::map &load_order_buff);
21 | void store_complete_subloop(Loop *L, std::map &Complete_Loop_Index);
22 | void store_complete_loop(LoopInfo* LI, std::map &Complete_Loop_Index);
23 | Loop *get_top_loop(Loop *L);
24 | bool all_is_small(BasicBlock *bb, Instruction *inst);
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/src/Loop_II.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef LOOP_II_H_
15 | #define LOOP_II_H_
16 |
17 | #include "test.h"
18 |
19 | int compute_II(LoopInfo* LI, Loop* L, std::map &instr_index_loop, std::map &load_order_buff, std::vector > *dependence_loop);
20 | int find_array_offset(LoopInfo* LI, Instruction *inst);
21 | int find_distance(LoopInfo* LI, Instruction *inst_l, Instruction *inst_s);
22 | int find_max_rec_II(LoopInfo* LI, Loop *L, Instruction *inst, PHINode *phi, std::map &instr_index_loop, std::vector > *dependence_loop);
23 | int find_ResMII(LoopInfo* LI, Loop *L, std::map &load_order_buff);
24 |
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/src/Function_II.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef FUNCTION_II_H_
15 | #define FUNCTION_II_H_
16 |
17 | #include "test.h"
18 |
19 | int compute_Fn_II(Function *F, LoopInfo* LI,std::map &instr_index_loop, std::vector > *dependence_loop,std::vector > *function_arg_II);
20 | int find_Fn_ResMII(Function *F, LoopInfo* LI, std::vector > *function_arg_II);
21 | bool is_call_argument(CallInst *call, Value *arg);
22 | unsigned get_arg_number(CallInst *call, Value *arg);
23 | int find_Fns_ResMII(Function *F, LoopInfo* LI, std::map &instr_index_loop, std::vector > *dependence_loop,std::vector > *function_arg_II);
24 |
25 |
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/test_c/gemm/gemm.c:
--------------------------------------------------------------------------------
1 | /**
2 | * This version is stamped on May 10, 2016
3 | *
4 | * Contact:
5 | * Louis-Noel Pouchet
6 | * Tomofumi Yuki
7 | *
8 | * Web address: http://polybench.sourceforge.net
9 | */
10 | /* gemm.c: this file is part of PolyBench/C */
11 |
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 | /* Include benchmark-specific header. */
18 | #include "gemm.h"
19 |
20 | /* Main computational kernel. The whole function will be timed,
21 | including the call and return. */
22 | void kernel_gemm(int C[NI][NJ], int A[NI][NK],int B[NK][NJ])
23 | {
24 | int i, j, k;
25 | int alpha=3;
26 | int beta=2;
27 | int ni=NI;
28 | int nj=NJ;
29 | int nk=NK;
30 | kernel_gemm_label3:for (i = 0; i < ni; i++) {
31 | for (j = 0; j < nj; j++){
32 | C[i][j] *= beta;
33 | }
34 | for (k = 0; k < nk; k++) {
35 | kernel_gemm_label1:for (j = 0; j < nj; j++){
36 | C[i][j] += alpha * A[i][k] * B[k][j];
37 | }
38 | }
39 | }
40 |
41 | }
42 |
43 |
--------------------------------------------------------------------------------
/src/PartitionFactor.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #include "PartitionFactor.h"
15 | #include "ArrayName.h"
16 |
17 |
18 | int partition_factor(Instruction *inst)
19 | {
20 | int factor=1;
21 | Value *array_name=get_array_name(inst);
22 | if(array_number.count(array_name)){
23 | int array_index=array_number[array_name];
24 | int dim=array_dimension[array_index];
25 | if(dim==1){
26 | std::vector< std::pair >::iterator it = array_partition[array_index].begin();
27 | factor=it->second;
28 | }
29 | else if(dim>1){
30 | int fac=1;
31 | for(std::vector< std::pair >::iterator it= array_partition[array_index].begin(); it!=array_partition[array_index].end(); ++it){
32 | fac=it->second;
33 | factor *=fac;
34 | }
35 | }
36 | else{
37 | errs()<<"Dim is 0, wrong!\n";
38 | }
39 | }
40 | return factor;
41 | }
42 |
43 |
--------------------------------------------------------------------------------
/src/FindLatency.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef FINDLATENCY_H_
15 | #define FINDLATENCY_H_
16 |
17 | #include "test.h"
18 |
19 |
20 | float find_latency_before_inst(Instruction *inst, std::map &instr_index_loop, std::vector > *dependence_loop);
21 | float find_latency_after_inst(Instruction *inst, std::map &instr_index_loop, std::vector > *dependence_loop);
22 | float find_latency(Instruction *inst_begin, Instruction *inst_end, std::map &instr_index_loop, std::vector > *dependence_loop);
23 | float get_inst_latency(Instruction *inst, std::map &instr_index_loop,std::vector > *dependence_loop);
24 | void set_inst_latency(Instruction *inst,float latency,std::map &instr_index_loop,std::vector > *dependence_loop);
25 |
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/test_c/utilities/benchmark_list:
--------------------------------------------------------------------------------
1 | ./datamining/correlation/correlation.c
2 | ./datamining/covariance/covariance.c
3 | ./linear-algebra/kernels/2mm/2mm.c
4 | ./linear-algebra/kernels/3mm/3mm.c
5 | ./linear-algebra/kernels/atax/atax.c
6 | ./linear-algebra/kernels/bicg/bicg.c
7 | ./linear-algebra/kernels/doitgen/doitgen.c
8 | ./linear-algebra/kernels/mvt/mvt.c
9 | ./linear-algebra/blas/gemm/gemm.c
10 | ./linear-algebra/blas/gemver/gemver.c
11 | ./linear-algebra/blas/gesummv/gesummv.c
12 | ./linear-algebra/blas/symm/symm.c
13 | ./linear-algebra/blas/syr2k/syr2k.c
14 | ./linear-algebra/blas/syrk/syrk.c
15 | ./linear-algebra/blas/trmm/trmm.c
16 | ./linear-algebra/solvers/cholesky/cholesky.c
17 | ./linear-algebra/solvers/durbin/durbin.c
18 | ./linear-algebra/solvers/gramschmidt/gramschmidt.c
19 | ./linear-algebra/solvers/lu/lu.c
20 | ./linear-algebra/solvers/ludcmp/ludcmp.c
21 | ./linear-algebra/solvers/trisolv/trisolv.c
22 | ./medley/deriche/deriche.c
23 | ./medley/floyd-warshall/floyd-warshall.c
24 | ./medley/nussinov/nussinov.c
25 | ./stencils/adi/adi.c
26 | ./stencils/fdtd-2d/fdtd-2d.c
27 | ./stencils/heat-3d/heat-3d.c
28 | ./stencils/jacobi-1d/jacobi-1d.c
29 | ./stencils/jacobi-2d/jacobi-2d.c
30 | ./stencils/seidel-2d/seidel-2d.c
31 |
--------------------------------------------------------------------------------
/src/UpdateMem.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef UPDATEMEM_H_
15 | #define UPDATEMEM_H_
16 |
17 | #include "test.h"
18 |
19 | void complete_load_update(Loop *L1, Loop *L2, float latency,float latency_delta, unsigned index1,unsigned index2, Instruction* inst,std::vector > *dependence_loop);
20 | void update_load(LoopInfo* LI, Instruction *inst, std::map &instr_index_loop, std::vector > *dependence_loop);
21 | void replace_write_latency(int store_num1, int store_num2, unsigned index, Instruction *inst,std::vector > *dependence_loop);
22 | void complete_store_update(Loop *L1, Loop *L2, int store_num1, int store_num2, unsigned index, Instruction *inst, std::vector > *dependence_loop);
23 | void update_store(LoopInfo* LI, Instruction *inst, std::map &instr_index_loop, std::vector > *dependence_loop);
24 |
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/test_c/utilities/clean.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | # Visits every directory, calls make clean, and then removes the Makefile
4 | #
5 | # Written by Tomofumi Yuki, 11/21 2014
6 | #
7 |
8 | my $TARGET_DIR = ".";
9 |
10 | if ($#ARGV != 0) {
11 | printf("usage perl clean.pl target-dir\n");
12 | exit(1);
13 | }
14 |
15 |
16 |
17 | if ($#ARGV == 0) {
18 | $TARGET_DIR = $ARGV[0];
19 | }
20 |
21 |
22 | my @categories = ('linear-algebra/blas',
23 | 'linear-algebra/kernels',
24 | 'linear-algebra/solvers',
25 | 'datamining',
26 | 'stencils',
27 | 'medley');
28 |
29 |
30 | foreach $cat (@categories) {
31 | my $target = $TARGET_DIR.'/'.$cat;
32 | opendir DIR, $target or die "directory $target not found.\n";
33 | while (my $dir = readdir DIR) {
34 | next if ($dir=~'^\..*');
35 | next if (!(-d $target.'/'.$dir));
36 |
37 | my $targetDir = $target.'/'.$dir;
38 | my $command = "cd $targetDir; make clean; rm -f Makefile";
39 | print($command."\n");
40 | system($command);
41 | }
42 |
43 | closedir DIR;
44 | }
45 |
46 | my $cfgFile = $TARGET_DIR.'/'.'config.mk';
47 | if (-e $cfgFile) {
48 | unlink $cfgFile;
49 | }
50 |
51 |
--------------------------------------------------------------------------------
/src/LoopLatency.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef LOOPLATENCY_H_
15 | #define LOOPLATENCY_H_
16 |
17 | #include "test.h"
18 |
19 | bool test_loop_is_perfect(Loop* L);
20 | float pipeline_iteration_latency(LoopInfo* LI, Loop *L,int II, std::map &instr_index_loop, std::map &load_order_buff, std::vector > *dependence_loop);
21 | float perfect_pipeline_iteration_latency(LoopInfo* LI, Loop *L, int II, std::map &instr_index_loop,std::map &load_order_buff, std::vector > *dependence_loop);
22 | float compute_cycles_in_loop(LoopInfo* LI, Loop* L, std::map &load_order_buff);
23 | void Loop_insert(LoopInfo* LI, Loop *L, unsigned &index_loop, std::map &instr_index_loop, std::map &load_order_buff, std::vector > *dependence_loop, std::map > &inst_map_branch);
24 |
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/src/Power.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #include "Constant.h"
15 | #include "Power.h"
16 |
17 | bool is_power_of_two(int n)
18 | {
19 | if(n==0)
20 | return false;
21 | else if(n==1)
22 | return true;
23 | else if(n%2)
24 | return false;
25 | else
26 | return is_power_of_two(n/2);
27 | }
28 |
29 | int closest_bound_power_two(int n)
30 | {
31 | int m1=0;
32 | int m2=0;
33 | int m=0;
34 | if(n<0){
35 | n=-n;
36 | }
37 | for(int i=n;i>0;--i){
38 | bool is_power_two=is_power_of_two(i);
39 | if(is_power_two==true){
40 | m1=i;
41 | break;
42 | }
43 | }
44 | for(int i=n;idelta_m2){
54 | m=m2;
55 | }
56 | else{
57 | m=m1;
58 | }
59 | return m;
60 | }
61 |
62 | int get_power_of_two(int n)
63 | {
64 | int power=1;
65 | if(n==1){
66 | power=0;
67 | }
68 | else if(is_power_of_two(n)==true){
69 | power+=get_power_of_two(n/2);
70 | }
71 | else{
72 | n--;
73 | power=get_power_of_two(n);
74 | }
75 | return power;
76 | }
77 |
--------------------------------------------------------------------------------
/test_c/utilities/run-all.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | # Visits every directory, calls make, and then executes the benchmark
4 | # (Designed for making sure every kernel compiles/runs after modifications)
5 | #
6 | # Written by Tomofumi Yuki, 01/15 2015
7 | #
8 |
9 | my $TARGET_DIR = ".";
10 |
11 | if ($#ARGV != 0 && $#ARGV != 1) {
12 | printf("usage perl run-all.pl target-dir [output-file]\n");
13 | exit(1);
14 | }
15 |
16 |
17 |
18 | if ($#ARGV >= 0) {
19 | $TARGET_DIR = $ARGV[0];
20 | }
21 |
22 | my $OUTFILE = "";
23 | if ($#ARGV == 1) {
24 | $OUTFILE = $ARGV[1];
25 | }
26 |
27 |
28 | my @categories = ('linear-algebra/blas',
29 | 'linear-algebra/kernels',
30 | 'linear-algebra/solvers',
31 | 'datamining',
32 | 'stencils',
33 | 'medley');
34 |
35 |
36 | foreach $cat (@categories) {
37 | my $target = $TARGET_DIR.'/'.$cat;
38 | opendir DIR, $target or die "directory $target not found.\n";
39 | while (my $dir = readdir DIR) {
40 | next if ($dir=~'^\..*');
41 | next if (!(-d $target.'/'.$dir));
42 |
43 | my $kernel = $dir;
44 | my $targetDir = $target.'/'.$dir;
45 | my $command = "cd $targetDir; make clean; make; ./$kernel";
46 | $command .= " 2>> $OUTFILE" if ($OUTFILE ne '');
47 | print($command."\n");
48 | system($command);
49 | }
50 |
51 | closedir DIR;
52 | }
53 |
54 |
--------------------------------------------------------------------------------
/src/ComputeFixedPath.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef COMPUTEFIXEDPATH_H_
15 | #define COMPUTEFIXEDPATH_H_
16 |
17 | #include "test.h"
18 |
19 | void loop_computeCP_gep_fixed_latency(Loop *L, Instruction *inst, float latency, unsigned &index_loop, std::map &instr_index_loop, std::vector > *dependence_loop);
20 | void loop_computeCP_fixed_latency(Loop *L, Instruction * inst, float latency, unsigned &index_loop, std::map &instr_index_loop, std::vector > *dependence_loop);
21 | void loop_computeCP_call_fixed_latency(Loop *L, Instruction *inst, float latency, unsigned &index_loop, std::map &instr_index_loop, std::vector > *dependence_loop);
22 | void loop_computeCP_phi_fixed_latency(Loop *L, Instruction *inst, float latency, unsigned &index_loop, std::map &instr_index_loop, std::vector > *dependence_loop);
23 | void update_fix_latency(Loop *L, Instruction *inst, float latency, unsigned &index_loop, std::map &instr_index_loop, std::vector > *dependence_loop);
24 |
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/src/Resource.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef RESOURCE_H_
15 | #define RESOURCE_H_
16 |
17 | #include "test.h"
18 |
19 | void inst_map_resource(Instruction *inst, bool &shareable_unit,std::map &inst_unit);
20 | void get_unit_resource(Instruction *inst, std::map &inst_unit, std::map &resource_usage,std::vector > *function_resource);
21 | void compute_resource(Instruction *inst,std::map &loop_resource, std::vector > *function_resource, std::map &inst_unit, std::map &scheduled_inst_unit, std::map &instr_index, std::vector > *dependence);
22 | bool loop_pipeline_is_set(Loop *L);
23 | Loop *get_pipelined_loop(Loop *L);
24 | void count_related_loops(Loop *L, std::map &Loop_counted);
25 | bool all_loop_unrolled(Loop *L);
26 | void compute_loop_resource(LoopInfo* LI, Loop *L,std::vector > *function_resource, std::map &loop_resource, std::map &load_buff,std::map &Loop_counted);
27 | void resource_accumulation(LoopInfo* LI,Function *F,std::vector > *function_resource, std::map &instr_index_loop, std::vector > *dependence_loop);
28 | void bram_accumulation(LoopInfo* LI,Function *F,std::vector > *function_resource);
29 |
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/test_c/utilities/create_cpped_version.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | # Creates C Pre-Processed Version
4 | # Additional arguments to the script are all passed to gcc.
5 | # At least the include path of polybench.h must be added.
6 | #
7 | # Written by Tomofumi Yuki, 01/14 2015
8 | #
9 |
10 | if ($#ARGV == -1) {
11 | printf("usage perl create-cpped-version.pl filename [cflags]\n");
12 | exit(1);
13 | }
14 |
15 | my @CFLAGS = @ARGV;
16 | my $TARGET = shift @CFLAGS;
17 |
18 | my $TEMP_T = '.__poly_top.c';
19 | my $TEMP_B = '.__poly_bottom.c';
20 | my $TEMP_P = '.__poly_bottom.pp.c';
21 |
22 | $TARGET =~ /([^\.\/]+)\.c$/;
23 | my $KERNEL = $1;
24 | $TARGET_DIR = substr $TARGET, 0, -length($KERNEL)-2;
25 | $TARGET_DIR = '.' if $TARGET_DIR eq '';
26 |
27 | open FILE, $TARGET or die "Error opening $TARGET";
28 |
29 | my $top;
30 | my $bottom;
31 | my $current = \$top;
32 | while () {
33 | my $line = $_;
34 | if ($line =~ /polybench\.h/) {
35 | $current = \$bottom;
36 | }
37 | $$current .= $line;
38 | }
39 | close FILE;
40 |
41 | &writeToFile($TEMP_T, $top);
42 | &writeToFile($TEMP_B, $bottom);
43 |
44 | my $ignoreLibs = "-D_STDLIB_H_ -D_STDIO_H_ -D_MATH_H_ -D_STRING_H_ -D_UNISTD_H_";
45 |
46 | my $command = 'gcc -E '.$ignoreLibs.' '.$TEMP_B.' -I '.$TARGET_DIR.' '.join(" ", @CFLAGS).' 2>/dev/null > '.$TEMP_P;
47 | system($command);
48 |
49 | my $OUTFILE = $TARGET_DIR.'/'.$KERNEL.'.preproc.c';
50 | system('cat '.$TEMP_T.' > '.$OUTFILE);
51 | system('echo "#include" >> '.$OUTFILE);
52 | $command = 'sed -e "s~'.$TEMP_B.'~'.$KERNEL.'.c~g" '.$TEMP_P.' >> '.$OUTFILE;
53 | system($command);
54 |
55 | unlink $TEMP_P;
56 | unlink $TEMP_B;
57 | unlink $TEMP_T;
58 |
59 | sub writeToFile() {
60 | my $file = $_[0];
61 | my $content = $_[1];
62 |
63 | open FILE, ">$file" or die "Error writing to $file";
64 |
65 | print FILE $content;
66 |
67 | close FILE;
68 | }
69 |
--------------------------------------------------------------------------------
/test_c/bicg/bicg.h:
--------------------------------------------------------------------------------
1 | /**
2 | * This version is stamped on May 10, 2016
3 | *
4 | * Contact:
5 | * Louis-Noel Pouchet
6 | * Tomofumi Yuki
7 | *
8 | * Web address: http://polybench.sourceforge.net
9 | */
10 | #ifndef _BICG_H
11 | # define _BICG_H
12 |
13 | /* Default to LARGE_DATASET. */
14 | # if !defined(MINI_DATASET) && !defined(SMALL_DATASET) && !defined(MEDIUM_DATASET) && !defined(LARGE_DATASET) && !defined(EXTRALARGE_DATASET)
15 | # define MINI_DATASET
16 | # endif
17 |
18 | # if !defined(M) && !defined(N)
19 | /* Define sample dataset sizes. */
20 | # ifdef MINI_DATASET
21 | # define M 32//38
22 | # define N 32//42
23 | # endif
24 |
25 | # ifdef SMALL_DATASET
26 | # define M 116
27 | # define N 124
28 | # endif
29 |
30 | # ifdef MEDIUM_DATASET
31 | # define M 390
32 | # define N 410
33 | # endif
34 |
35 | # ifdef LARGE_DATASET
36 | # define M 1900
37 | # define N 2100
38 | # endif
39 |
40 | # ifdef EXTRALARGE_DATASET
41 | # define M 1800
42 | # define N 2200
43 | # endif
44 |
45 |
46 | #endif /* !(M N) */
47 |
48 | # define _PB_M POLYBENCH_LOOP_BOUND(M,m)
49 | # define _PB_N POLYBENCH_LOOP_BOUND(N,n)
50 |
51 |
52 | /* Default data type */
53 | # if !defined(DATA_TYPE_IS_INT) && !defined(DATA_TYPE_IS_FLOAT) && !defined(DATA_TYPE_IS_DOUBLE)
54 | # define DATA_TYPE_IS_INT
55 | # endif
56 |
57 | #ifdef DATA_TYPE_IS_INT
58 | # define DATA_TYPE int
59 | # define DATA_PRINTF_MODIFIER "%d "
60 | #endif
61 |
62 | #ifdef DATA_TYPE_IS_FLOAT
63 | # define DATA_TYPE float
64 | # define DATA_PRINTF_MODIFIER "%0.2f "
65 | # define SCALAR_VAL(x) x##f
66 | # define SQRT_FUN(x) sqrtf(x)
67 | # define EXP_FUN(x) expf(x)
68 | # define POW_FUN(x,y) powf(x,y)
69 | # endif
70 |
71 | #ifdef DATA_TYPE_IS_DOUBLE
72 | # define DATA_TYPE double
73 | # define DATA_PRINTF_MODIFIER "%0.2lf "
74 | # define SCALAR_VAL(x) x
75 | # define SQRT_FUN(x) sqrt(x)
76 | # define EXP_FUN(x) exp(x)
77 | # define POW_FUN(x,y) pow(x,y)
78 | # endif
79 |
80 | #endif /* !_BICG_H */
81 |
--------------------------------------------------------------------------------
/src/LoopInterface.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #include "LoopInterface.h"
15 | #include "ArrayName.h"
16 |
17 |
18 | void get_loop_input(Loop *L, std::vector &loop_read)
19 | {
20 | for(Loop::block_iterator BI=L->block_begin(), BE=L->block_end(); BI !=BE; ++BI)
21 | {
22 | BasicBlock *bb=*BI;
23 | for(auto iti=bb->begin();iti!=bb->end();++iti)
24 | {
25 | if(isa(iti)){
26 | Value *array=get_array_name(iti);
27 | std::vector::iterator i;
28 | if(loop_read.empty()){
29 | loop_read.push_back(array);
30 | }
31 | else{
32 | for(i=loop_read.begin();i!=loop_read.end();++i)
33 | {
34 | Value *array1=*i;
35 | if(array1==array){
36 | break;
37 | }
38 | }
39 |
40 | if(i==loop_read.end()){
41 | i--;
42 | Value *array2=*i;
43 | if(array != array2){
44 | loop_read.push_back(array);
45 | }
46 | }
47 | }
48 | }
49 | }
50 | }
51 | }
52 |
53 | void get_loop_output(Loop *L, std::vector &loop_write)
54 | {
55 | for(Loop::block_iterator BI=L->block_begin(), BE=L->block_end(); BI !=BE; ++BI)
56 | {
57 | BasicBlock *bb=*BI;
58 | for(auto iti=bb->begin();iti!=bb->end();++iti)
59 | {
60 | if(isa(iti)){
61 | Value *array=get_array_name(iti);
62 | std::vector::iterator i;
63 | if(loop_write.empty()){
64 | loop_write.push_back(array);
65 | }
66 | else{
67 | for(i=loop_write.begin();i!=loop_write.end();++i)
68 | {
69 | Value *array1=*i;
70 | if(array1==array){
71 | break;
72 | }
73 | }
74 | if(i==loop_write.end()){
75 | i--;
76 | Value *array2=*i;
77 | if(array != array2){
78 | loop_write.push_back(array);
79 | }
80 | }
81 | }
82 | }
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/test_c/utilities/makefile-gen.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | # Generates Makefile for each benchmark in polybench
4 | # Expects to be executed from root folder of polybench
5 | #
6 | # Written by Tomofumi Yuki, 11/21 2014
7 | #
8 |
9 | my $GEN_CONFIG = 0;
10 | my $TARGET_DIR = ".";
11 |
12 | if ($#ARGV !=0 && $#ARGV != 1) {
13 | printf("usage perl makefile-gen.pl output-dir [-cfg]\n");
14 | printf(" -cfg option generates config.mk in the output-dir.\n");
15 | exit(1);
16 | }
17 |
18 |
19 |
20 | foreach my $arg (@ARGV) {
21 | if ($arg =~ /-cfg/) {
22 | $GEN_CONFIG = 1;
23 | } elsif (!($arg =~ /^-/)) {
24 | $TARGET_DIR = $arg;
25 | }
26 | }
27 |
28 |
29 | my %categories = (
30 | 'linear-algebra/blas' => 3,
31 | 'linear-algebra/kernels' => 3,
32 | 'linear-algebra/solvers' => 3,
33 | 'datamining' => 2,
34 | 'stencils' => 2,
35 | 'medley' => 2
36 | );
37 |
38 | my %extra_flags = (
39 | 'cholesky' => '-lm',
40 | 'gramschmidt' => '-lm',
41 | 'correlation' => '-lm'
42 | );
43 |
44 | foreach $key (keys %categories) {
45 | my $target = $TARGET_DIR.'/'.$key;
46 | opendir DIR, $target or die "directory $target not found.\n";
47 | while (my $dir = readdir DIR) {
48 | next if ($dir=~'^\..*');
49 | next if (!(-d $target.'/'.$dir));
50 |
51 | my $kernel = $dir;
52 | my $file = $target.'/'.$dir.'/Makefile';
53 | my $polybenchRoot = '../'x$categories{$key};
54 | my $configFile = $polybenchRoot.'config.mk';
55 | my $utilityDir = $polybenchRoot.'utilities';
56 |
57 | open FILE, ">$file" or die "failed to open $file.";
58 |
59 | print FILE << "EOF";
60 | include $configFile
61 |
62 | EXTRA_FLAGS=$extra_flags{$kernel}
63 |
64 | $kernel: $kernel.c $kernel.h
65 | \${VERBOSE} \${CC} -o $kernel $kernel.c \${CFLAGS} -I. -I$utilityDir $utilityDir/polybench.c \${EXTRA_FLAGS}
66 |
67 | clean:
68 | @ rm -f $kernel
69 |
70 | EOF
71 |
72 | close FILE;
73 | }
74 |
75 |
76 | closedir DIR;
77 | }
78 |
79 | if ($GEN_CONFIG) {
80 | open FILE, '>'.$TARGET_DIR.'/config.mk';
81 |
82 | print FILE << "EOF";
83 | CC=gcc
84 | CFLAGS=-O2 -DPOLYBENCH_DUMP_ARRAYS -DPOLYBENCH_USE_C99_PROTO
85 | EOF
86 |
87 | close FILE;
88 |
89 | }
90 |
91 |
--------------------------------------------------------------------------------
/test_c/gemm/gemm.h:
--------------------------------------------------------------------------------
1 | /**
2 | * This version is stamped on May 10, 2016
3 | *
4 | * Contact:
5 | * Louis-Noel Pouchet
6 | * Tomofumi Yuki
7 | *
8 | * Web address: http://polybench.sourceforge.net
9 | */
10 | #ifndef _GEMM_H
11 | # define _GEMM_H
12 |
13 | /* Default to LARGE_DATASET. */
14 | # if !defined(MINI_DATASET) && !defined(SMALL_DATASET) && !defined(MEDIUM_DATASET) && !defined(LARGE_DATASET) && !defined(EXTRALARGE_DATASET)
15 | # define MINI_DATASET
16 | # endif
17 |
18 | # if !defined(NI) && !defined(NJ) && !defined(NK)
19 | /* Define sample dataset sizes. */
20 | # ifdef MINI_DATASET
21 | # define NI 16//20
22 | # define NJ 16//25
23 | # define NK 16//30
24 | # endif
25 |
26 | # ifdef SMALL_DATASET
27 | # define NI 60
28 | # define NJ 70
29 | # define NK 80
30 | # endif
31 |
32 | # ifdef MEDIUM_DATASET
33 | # define NI 200
34 | # define NJ 220
35 | # define NK 240
36 | # endif
37 |
38 | # ifdef LARGE_DATASET
39 | # define NI 1000
40 | # define NJ 1100
41 | # define NK 1200
42 | # endif
43 |
44 | # ifdef EXTRALARGE_DATASET
45 | # define NI 2000
46 | # define NJ 2300
47 | # define NK 2600
48 | # endif
49 |
50 |
51 | #endif /* !(NI NJ NK) */
52 |
53 | # define _PB_NI POLYBENCH_LOOP_BOUND(NI,ni)
54 | # define _PB_NJ POLYBENCH_LOOP_BOUND(NJ,nj)
55 | # define _PB_NK POLYBENCH_LOOP_BOUND(NK,nk)
56 |
57 |
58 | /* Default data type */
59 | # if !defined(DATA_TYPE_IS_INT) && !defined(DATA_TYPE_IS_FLOAT) && !defined(DATA_TYPE_IS_DOUBLE)
60 | # define DATA_TYPE_IS_INT
61 | # endif
62 |
63 | #ifdef DATA_TYPE_IS_INT
64 | # define DATA_TYPE int
65 | # define DATA_PRINTF_MODIFIER "%d "
66 | #endif
67 |
68 | #ifdef DATA_TYPE_IS_FLOAT
69 | # define DATA_TYPE float
70 | # define DATA_PRINTF_MODIFIER "%0.2f "
71 | # define SCALAR_VAL(x) x##f
72 | # define SQRT_FUN(x) sqrtf(x)
73 | # define EXP_FUN(x) expf(x)
74 | # define POW_FUN(x,y) powf(x,y)
75 | # endif
76 |
77 | #ifdef DATA_TYPE_IS_DOUBLE
78 | # define DATA_TYPE double
79 | # define DATA_PRINTF_MODIFIER "%0.2lf "
80 | # define SCALAR_VAL(x) x
81 | # define SQRT_FUN(x) sqrt(x)
82 | # define EXP_FUN(x) exp(x)
83 | # define POW_FUN(x,y) pow(x,y)
84 | # endif
85 |
86 | #endif /* !_GEMM_H */
87 |
--------------------------------------------------------------------------------
/src/ArrayName.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #include "ArrayName.h"
15 |
16 |
17 | Value *check_PHI_operand(PHINode *phi)
18 | {
19 | Value *val=NULL;
20 | Value *val_tmp=NULL;
21 | for(unsigned i=0, e=phi->getNumIncomingValues();i!=e;i++)
22 | {
23 | Value *incoming=phi->getIncomingValue(i);
24 | if( (!(isa(incoming))) && (!(isa(incoming))) )
25 | {
26 | val=incoming;
27 | return val; //consider most cases to break and continue
28 | }
29 | else if(GetElementPtrInst *GEP_incoming=dyn_cast(incoming))
30 | {
31 | val_tmp=GEP_incoming->getPointerOperand();
32 | if(isa(val_tmp))
33 | {
34 | if(val_tmp==phi){
35 | val=val_tmp;
36 | //return val;
37 | }
38 | else{
39 | val=0;
40 | }
41 | }
42 | else{
43 | val=val_tmp;
44 | return val;
45 | }
46 | }
47 | else if(isa(incoming))
48 | {
49 | val=0;
50 | continue;
51 | }
52 | }
53 | return val;
54 | }
55 |
56 |
57 | Value *get_array_name(Instruction *inst)
58 | {
59 | Value *array_name=NULL;
60 | Value *op=NULL;
61 |
62 | if(LoadInst *load_inst=dyn_cast(inst)){
63 | op=load_inst->getPointerOperand();
64 | }
65 | else if(StoreInst *store_inst=dyn_cast(inst)){
66 | op=store_inst->getPointerOperand();
67 | }
68 | //else errs()<<"This instruction is neither a load nor a store.\n";
69 |
70 | if(GetElementPtrInst *OP_GEP=dyn_cast(op)){
71 | array_name=OP_GEP->getPointerOperand();
72 | }
73 | else if(PHINode *OP_PHI=dyn_cast(op)){
74 | array_name=check_PHI_operand(OP_PHI);
75 | }
76 | else if(Instruction *OP_Inst=dyn_cast(op)){
77 | for(unsigned i=0; i!=OP_Inst->getNumOperands(); ++i){
78 | Value *OP = OP_Inst->getOperand(i);
79 | if(GetElementPtrInst *tmp_inst = dyn_cast(OP)){
80 | array_name=tmp_inst->getPointerOperand();
81 | break;
82 | }
83 | else{
84 | array_name=OP;//Modified
85 | }
86 | }
87 | }
88 | else{
89 | array_name=op;
90 | }
91 | return array_name;
92 | }
93 |
--------------------------------------------------------------------------------
/test_c/utilities/polybench.spec:
--------------------------------------------------------------------------------
1 | kernel category datatype params MINI SMALL MEDIUM LARGE EXTRALARGE
2 | correlation datamining double M N 28 32 80 100 240 260 1200 1400 2600 3000
3 | covariance datamining double M N 28 32 80 100 240 260 1200 1400 2600 3000
4 | 2mm linear-algebra/kernels double NI NJ NK NL 16 18 22 24 40 50 70 80 180 190 210 220 800 900 1100 1200 1600 1800 2200 2400
5 | 3mm linear-algebra/kernels double NI NJ NK NL NM 16 18 20 22 24 40 50 60 70 80 180 190 200 210 220 800 900 1000 1100 1200 1600 1800 2000 2200 2400
6 | atax linear-algebra/kernels double M N 38 42 116 124 390 410 1900 2100 1800 2200
7 | bicg linear-algebra/kernels double M N 38 42 116 124 390 410 1900 2100 1800 2200
8 | doitgen linear-algebra/kernels double NQ NR NP 8 10 12 20 25 30 40 50 60 140 150 160 220 250 270
9 | mvt linear-algebra/kernels double N 40 120 400 2000 4000
10 | gemm linear-algebra/blas double NI NJ NK 20 25 30 60 70 80 200 220 240 1000 1100 1200 2000 2300 2600
11 | gemver linear-algebra/blas double N 40 120 400 2000 4000
12 | gesummv linear-algebra/blas double N 30 90 250 1300 2800
13 | symm linear-algebra/blas double M N 20 30 60 80 200 240 1000 1200 2000 2600
14 | syr2k linear-algebra/blas double M N 20 30 60 80 200 240 1000 1200 2000 2600
15 | syrk linear-algebra/blas double M N 20 30 60 80 200 240 1000 1200 2000 2600
16 | trmm linear-algebra/blas double M N 20 30 60 80 200 240 1000 1200 2000 2600
17 | cholesky linear-algebra/solvers double N 40 120 400 2000 4000
18 | durbin linear-algebra/solvers double N 40 120 400 2000 4000
19 | gramschmidt linear-algebra/solvers double M N 20 30 60 80 200 240 1000 1200 2000 2600
20 | lu linear-algebra/solvers double N 40 120 400 2000 4000
21 | ludcmp linear-algebra/solvers double N 40 120 400 2000 4000
22 | trisolv linear-algebra/solvers double N 40 120 400 2000 4000
23 | deriche medley float W H 64 64 192 128 720 480 4096 2160 7680 4320
24 | floyd-warshall medley int N 60 180 500 2800 5600
25 | nussinov medley int N 60 180 500 2500 5500
26 | adi stencils double TSTEPS N 20 20 40 60 100 200 500 1000 1000 2000
27 | fdtd-2d stencils double TMAX NX NY 20 20 30 40 60 80 100 200 240 500 1000 1200 1000 2000 2600
28 | heat-3d stencils double TSTEPS N 20 10 40 20 100 40 500 120 1000 200
29 | jacobi-1d stencils double TSTEPS N 20 30 40 120 100 400 500 2000 1000 4000
30 | jacobi-2d stencils double TSTEPS N 20 30 40 90 100 250 500 1300 1000 2800
31 | seidel-2d stencils double TSTEPS N 20 40 40 120 100 400 500 2000 1000 4000
--------------------------------------------------------------------------------
/src/ComputeMemLatency.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef COMPUTEMEMLATENCY_H_
15 | #define COMPUTEMEMLATENCY_H_
16 |
17 | #include "test.h"
18 |
19 | int partition_load_num(LoopInfo *LI, BasicBlock *bb, Instruction *inst, std::map &instr_index_loop, std::map &load_order_buff);
20 | int partition_store_num(LoopInfo* LI, BasicBlock *bb, Instruction *inst, unsigned &index_loop, std::map &instr_index_loop, std::vector > *dependence_loop);
21 | int compute_asap_load_num(BasicBlock *bb, Instruction *inst, std::map &instr_index_loop, std::map &load_order_buff);
22 | int compute_asap_store_num(LoopInfo* LI, BasicBlock *bb, Instruction *inst, unsigned &index_loop, std::map &instr_index_loop, std::vector > *dependence_loop);
23 | float mux_latency(LoopInfo* LI, BasicBlock *bb, Instruction *inst);
24 | float get_load_latency(LoopInfo* LI, Instruction *inst, std::map &instr_index_loop, std::map &load_order_buff);
25 | bool load_before_store_partitioned(LoopInfo* LI, Instruction *inst, std::map &instr_index_loop, std::vector > *dependence_loop);
26 | float get_store_latency(LoopInfo* LI, Instruction *inst, unsigned &index_loop, std::map &instr_index_loop, std::vector > *dependence_loop);
27 | PHINode *get_previous_phi(Instruction *inst);
28 | bool loop_unroll_effective(Loop *L);
29 | bool loop_carry_load_store_dependency(LoopInfo *LI, Instruction *load, Instruction *store);
30 | void reset_sameArray_store_latency(LoopInfo *LI, BasicBlock *bb, Instruction *inst, int unroll_factor, std::map &instr_index_loop, std::vector > *dependence_loop);
31 | void update_after_store(LoopInfo* LI, Instruction *inst, std::map &instr_index_loop, std::vector > *dependence_loop);
32 | void update_after_load(Instruction *inst, std::map &instr_index_loop, std::vector > *dependence_loop);
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/test_c/gemm/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | /* Include polybench common header. */
7 | #include "../utilities/polybench.h"
8 |
9 | /* Include benchmark-specific header. */
10 | #include "gemm.h"
11 | /* Array initialization. */
12 | void init_array(int ni, int nj, int nk, int C[NI][NJ],int A[NI][NK],int B[NK][NJ])
13 | {
14 | int i, j;
15 | for (i = 0; i < ni; i++)
16 | for (j = 0; j < nj; j++)
17 | C[i][j] = (int) ((i*j+1) % ni) / ni;
18 | for (i = 0; i < ni; i++)
19 | for (j = 0; j < nk; j++)
20 | A[i][j] = (int) (i*(j+1) % nk) / nk;
21 | for (i = 0; i < nk; i++)
22 | for (j = 0; j < nj; j++)
23 | B[i][j] = (int) (i*(j+2) % nj) / nj;
24 | }
25 |
26 |
27 | /* DCE code. Must scan the entire live-out data.
28 | Can be used also to check the correctness of the output. */
29 | void print_array(int ni, int nj, int C[NI][NJ])
30 | {
31 | int i, j;
32 |
33 | POLYBENCH_DUMP_START;
34 | POLYBENCH_DUMP_BEGIN("C");
35 | for (i = 0; i < ni; i++)
36 | for (j = 0; j < nj; j++) {
37 | if ((i * ni + j) % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
38 | fprintf (POLYBENCH_DUMP_TARGET, DATA_PRINTF_MODIFIER, C[i][j]);
39 | }
40 | POLYBENCH_DUMP_END("C");
41 | POLYBENCH_DUMP_FINISH;
42 | }
43 |
44 |
45 | int main(int argc, char** argv)
46 | {
47 | /* Retrieve problem size. */
48 | int ni = NI;
49 | int nj = NJ;
50 | int nk = NK;
51 |
52 | /* Variable declaration/allocation. */
53 | POLYBENCH_2D_ARRAY_DECL(C,int,NI,NJ,ni,nj);
54 | POLYBENCH_2D_ARRAY_DECL(A,int,NI,NK,ni,nk);
55 | POLYBENCH_2D_ARRAY_DECL(B,int,NK,NJ,nk,nj);
56 |
57 | /* Initialize array(s). */
58 | init_array (ni, nj, nk,
59 | POLYBENCH_ARRAY(C),
60 | POLYBENCH_ARRAY(A),
61 | POLYBENCH_ARRAY(B));
62 |
63 | /* Start timer. */
64 | polybench_start_instruments;
65 |
66 | /* Run kernel. */
67 | kernel_gemm (POLYBENCH_ARRAY(C),
68 | POLYBENCH_ARRAY(A),
69 | POLYBENCH_ARRAY(B));
70 |
71 | /* Stop and print timer. */
72 | polybench_stop_instruments;
73 | polybench_print_instruments;
74 |
75 | /* Prevent dead-code elimination. All live-out data must be printed
76 | by the function call in argument. */
77 | polybench_prevent_dce(print_array(ni, nj, POLYBENCH_ARRAY(C)));
78 |
79 | /* Be clean. */
80 | POLYBENCH_FREE_ARRAY(C);
81 | POLYBENCH_FREE_ARRAY(A);
82 | POLYBENCH_FREE_ARRAY(B);
83 |
84 | return 0;
85 | }
86 |
--------------------------------------------------------------------------------
/test_c/utilities/template-for-new-benchmark.c:
--------------------------------------------------------------------------------
1 | /**
2 | * This version is stamped on May 10, 2016
3 | *
4 | * Contact:
5 | * Louis-Noel Pouchet
6 | * Tomofumi Yuki
7 | *
8 | * Web address: http://polybench.sourceforge.net
9 | */
10 | #include
11 | #include
12 | #include
13 | #include
14 |
15 | /* Include polybench common header. */
16 | #include "../utilities/polybench.h"
17 |
18 | /* Include benchmark-specific header. */
19 | /* Default data type is double, default size is N=1024. */
20 | #include "template-for-new-benchmark.h"
21 |
22 |
23 | /* Array initialization. */
24 | static
25 | void init_array(int n, DATA_TYPE POLYBENCH_2D(C,N,N,n,n))
26 | {
27 | int i, j;
28 |
29 | for (i = 0; i < n; i++)
30 | for (j = 0; j < n; j++)
31 | C[i][j] = 42;
32 | }
33 |
34 |
35 | /* DCE code. Must scan the entire live-out data.
36 | Can be used also to check the correctness of the output. */
37 | static
38 | void print_array(int n, DATA_TYPE POLYBENCH_2D(C,N,N,n,n))
39 | {
40 | int i, j;
41 |
42 | for (i = 0; i < n; i++)
43 | for (j = 0; j < n; j++) {
44 | fprintf (stderr, DATA_PRINTF_MODIFIER, C[i][j]);
45 | if (i % 20 == 0) fprintf (stderr, "\n");
46 | }
47 | fprintf (stderr, "\n");
48 | }
49 |
50 |
51 | /* Main computational kernel. The whole function will be timed,
52 | including the call and return. */
53 | static
54 | void kernel_template(int n, DATA_TYPE POLYBENCH_2D(C,N,N,n,n))
55 | {
56 | int i, j;
57 |
58 | #pragma scop
59 | for (i = 0; i < _PB_N; i++)
60 | for (j = 0; j < _PB_N; j++)
61 | C[i][j] += 42;
62 | #pragma endscop
63 |
64 | }
65 |
66 |
67 | int main(int argc, char** argv)
68 | {
69 | /* Retrieve problem size. */
70 | int n = N;
71 |
72 | /* Variable declaration/allocation. */
73 | POLYBENCH_2D_ARRAY_DECL(C,DATA_TYPE,N,N,n,n);
74 |
75 | /* Initialize array(s). */
76 | init_array (n, POLYBENCH_ARRAY(C));
77 |
78 | /* Start timer. */
79 | polybench_start_instruments;
80 |
81 | /* Run kernel. */
82 | kernel_template (n, POLYBENCH_ARRAY(C));
83 |
84 | /* Stop and print timer. */
85 | polybench_stop_instruments;
86 | polybench_print_instruments;
87 |
88 | /* Prevent dead-code elimination. All live-out data must be printed
89 | by the function call in argument. */
90 | polybench_prevent_dce(print_array(n, POLYBENCH_ARRAY(C)));
91 |
92 | /* Be clean. */
93 | POLYBENCH_FREE_ARRAY(C);
94 |
95 | return 0;
96 | }
97 |
--------------------------------------------------------------------------------
/src/ComputeCriticalPath.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef COMPUTECRITICALPATH_H_
15 | #define COMPUTECRITICALPATH_H_
16 |
17 | #include "test.h"
18 |
19 | void loop_compute_critical_path_gep(Instruction *inst, float latency, unsigned &index_loop, std::map &instr_index_loop, std::vector > *dependence_loop, std::map > &inst_map_branch);
20 | void loop_compute_critical_path(Instruction * inst, float latency, unsigned &index_loop, std::map &instr_index_loop, std::vector > *dependence_loop, std::map > &inst_map_branch);
21 | void loop_compute_critical_path_call(Instruction *inst, unsigned &index_loop, std::map &instr_index_loop, std::vector > *dependence_loop, std::map > &inst_map_branch);
22 | void loop_compute_critical_path_branch(LoopInfo* LI, Instruction *inst, unsigned &index_loop, std::map &instr_index_loop, std::vector > *dependence_loop, std::map > &inst_map_branch);
23 | void loop_compute_critical_path_switch(LoopInfo* LI, Instruction *inst, unsigned &index_loop, std::map &instr_index_loop, std::vector > *dependence_loop, std::map > &inst_map_branch);
24 | void update(LoopInfo* LI, Instruction *inst, unsigned &index_loop, std::map &instr_index_loop, std::map &load_order_buff, std::vector > *dependence_loop, std::map > &inst_map_branch);
25 | float loop_solveCP(std::vector > *dependence, std::map &loop_inst_till_latency);
26 | void dependence_set(LoopInfo* LI, Loop *L, std::map &instr_index_loop, std::map &load_order_buff, std::vector > *dependence_loop, std::map > &inst_map_branch);
27 | float loopCP(LoopInfo* LI, Loop* L, std::map &load_order_buff);
28 | float dependent_loopCP(LoopInfo* LI, Loop *L, std::map &load_order_buff);
29 | float update_loopCP(LoopInfo* LI, Loop *L, std::map &load_order_buff);
30 |
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/src/Reschedule.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #ifndef RESCHEDULE_H_
15 | #define RESCHEDULE_H_
16 |
17 | #include "test.h"
18 |
19 | void reschedule_dependence(LoopInfo* LI, int freq, std::map &instr_index_loop,std::vector > *dependence_loop);
20 | void reschedule_dependence_100(Instruction *inst, std::map::iterator it, std::vector >::iterator i, std::map &instr_index_loop, std::vector > *dependence_loop);
21 | void reschedule_dependence_125(Instruction *inst, std::map::iterator it, std::vector >::iterator i, std::map &instr_index_loop, std::vector > *dependence_loop);
22 | void reschedule_dependence_150(Instruction *inst, std::map::iterator it, std::vector >::iterator i, std::map &instr_index_loop, std::vector > *dependence_loop);
23 | void reschedule_dependence_200(Instruction *inst, std::map::iterator it, std::vector >::iterator i, std::map &instr_index_loop, std::vector > *dependence_loop);
24 | void reschedule_dependence_250(Instruction *inst, std::map::iterator it, std::vector >::iterator i, std::map &instr_index_loop, std::vector > *dependence_loop);
25 | bool num_is_int(float number);
26 | bool latency_is_large(Instruction *inst,std::map &instr_index_loop,std::vector > *dependence_loop);
27 | bool latency_is_large125(Instruction *inst,std::map &instr_index_loop,std::vector > *dependence_loop);
28 | void reschedule_load_freq125(bool large_latency_flag,Instruction *inst,Instruction *inst1,std::map &instr_index_loop,std::vector > *dependence_loop);
29 | bool load_shift_store(Instruction*inst,std::map &instr_index_loop,std::vector > *dependence_loop);
30 | bool before_inst_large(Instruction *inst,std::map &instr_index_loop,std::vector > *dependence_loop);
31 | bool after_inst_large(Instruction *inst,std::map &instr_index_loop,std::vector > *dependence_loop);
32 |
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/test/bicg.ll:
--------------------------------------------------------------------------------
1 | ; ModuleID = 'bicg.c'
2 | target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
3 | target triple = "x86_64-unknown-linux-gnu"
4 |
5 | ; Function Attrs: nounwind uwtable
6 | define void @kernel_bicg([38 x i32]* nocapture readonly %A, i32* nocapture %s, i32* nocapture %q, i32* nocapture readonly %p, i32* nocapture readonly %r) #0 {
7 | entry:
8 | br label %for.body
9 |
10 | for.body: ; preds = %for.inc26, %entry
11 | %indvars.iv48 = phi i64 [ 0, %entry ], [ %indvars.iv.next49, %for.inc26 ]
12 | %arrayidx = getelementptr inbounds i32* %q, i64 %indvars.iv48
13 | store i32 0, i32* %arrayidx, align 4, !tbaa !1
14 | %arrayidx7 = getelementptr inbounds i32* %r, i64 %indvars.iv48
15 | br label %for.body3
16 |
17 | for.body3: ; preds = %for.body3, %for.body
18 | %indvars.iv = phi i64 [ 0, %for.body ], [ %indvars.iv.next, %for.body3 ]
19 | %arrayidx5 = getelementptr inbounds i32* %s, i64 %indvars.iv
20 | %0 = load i32* %arrayidx5, align 4, !tbaa !1
21 | %1 = load i32* %arrayidx7, align 4, !tbaa !1
22 | %arrayidx11 = getelementptr inbounds [38 x i32]* %A, i64 %indvars.iv48, i64 %indvars.iv
23 | %2 = load i32* %arrayidx11, align 4, !tbaa !1
24 | %mul = mul nsw i32 %2, %1
25 | %add = add nsw i32 %mul, %0
26 | store i32 %add, i32* %arrayidx5, align 4, !tbaa !1
27 | %3 = load i32* %arrayidx, align 4, !tbaa !1
28 | %4 = load i32* %arrayidx11, align 4, !tbaa !1
29 | %arrayidx21 = getelementptr inbounds i32* %p, i64 %indvars.iv
30 | %5 = load i32* %arrayidx21, align 4, !tbaa !1
31 | %mul22 = mul nsw i32 %5, %4
32 | %add23 = add nsw i32 %mul22, %3
33 | store i32 %add23, i32* %arrayidx, align 4, !tbaa !1
34 | %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
35 | %exitcond = icmp eq i64 %indvars.iv.next, 38
36 | br i1 %exitcond, label %for.inc26, label %for.body3
37 |
38 | for.inc26: ; preds = %for.body3
39 | %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
40 | %exitcond50 = icmp eq i64 %indvars.iv.next49, 42
41 | br i1 %exitcond50, label %for.end28, label %for.body
42 |
43 | for.end28: ; preds = %for.inc26
44 | ret void
45 | }
46 |
47 | attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
48 |
49 | !llvm.ident = !{!0}
50 |
51 | !0 = metadata !{metadata !"clang version 3.4 (tags/RELEASE_34/final)"}
52 | !1 = metadata !{metadata !2, metadata !2, i64 0}
53 | !2 = metadata !{metadata !"int", metadata !3, i64 0}
54 | !3 = metadata !{metadata !"omnipotent char", metadata !4, i64 0}
55 | !4 = metadata !{metadata !"Simple C/C++ TBAA"}
56 |
--------------------------------------------------------------------------------
/test_c/bicg/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | /* Include polybench common header. */
7 | #include "../utilities/polybench.h"
8 |
9 | /* Include benchmark-specific header. */
10 | #include "bicg.h"
11 |
12 |
13 | /* Array initialization. */
14 | static
15 | void init_array (int m, int n,
16 | DATA_TYPE POLYBENCH_2D(A,N,M,n,m),
17 | DATA_TYPE POLYBENCH_1D(r,N,n),
18 | DATA_TYPE POLYBENCH_1D(p,M,m))
19 | {
20 | int i, j;
21 |
22 | for (i = 0; i < m; i++)
23 | p[i] = (DATA_TYPE)(i % m) / m;
24 | for (i = 0; i < n; i++) {
25 | r[i] = (DATA_TYPE)(i % n) / n;
26 | for (j = 0; j < m; j++)
27 | A[i][j] = (DATA_TYPE) (i*(j+1) % n)/n;
28 | }
29 | }
30 |
31 |
32 | /* DCE code. Must scan the entire live-out data.
33 | Can be used also to check the correctness of the output. */
34 | static
35 | void print_array(int m, int n,
36 | DATA_TYPE POLYBENCH_1D(s,M,m),
37 | DATA_TYPE POLYBENCH_1D(q,N,n))
38 |
39 | {
40 | int i;
41 |
42 | POLYBENCH_DUMP_START;
43 | POLYBENCH_DUMP_BEGIN("s");
44 | for (i = 0; i < m; i++) {
45 | if (i % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
46 | fprintf (POLYBENCH_DUMP_TARGET, DATA_PRINTF_MODIFIER, s[i]);
47 | }
48 | POLYBENCH_DUMP_END("s");
49 | POLYBENCH_DUMP_BEGIN("q");
50 | for (i = 0; i < n; i++) {
51 | if (i % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
52 | fprintf (POLYBENCH_DUMP_TARGET, DATA_PRINTF_MODIFIER, q[i]);
53 | }
54 | POLYBENCH_DUMP_END("q");
55 | POLYBENCH_DUMP_FINISH;
56 | }
57 |
58 |
59 | int main(int argc, char** argv)
60 | {
61 | /* Retrieve problem size. */
62 | int n = N;
63 | int m = M;
64 |
65 | /* Variable declaration/allocation. */
66 | POLYBENCH_2D_ARRAY_DECL(A, int, N, M, n, m);
67 | POLYBENCH_1D_ARRAY_DECL(s, int, M, m);
68 | POLYBENCH_1D_ARRAY_DECL(q, int, N, n);
69 | POLYBENCH_1D_ARRAY_DECL(p, int, M, m);
70 | POLYBENCH_1D_ARRAY_DECL(r, int, N, n);
71 |
72 | /* Initialize array(s). */
73 | init_array (m, n,
74 | POLYBENCH_ARRAY(A),
75 | POLYBENCH_ARRAY(r),
76 | POLYBENCH_ARRAY(p));
77 |
78 | /* Start timer. */
79 | polybench_start_instruments;
80 |
81 | /* Run kernel. */
82 | kernel_bicg (
83 | POLYBENCH_ARRAY(A),
84 | POLYBENCH_ARRAY(s),
85 | POLYBENCH_ARRAY(q),
86 | POLYBENCH_ARRAY(p),
87 | POLYBENCH_ARRAY(r));
88 |
89 | /* Stop and print timer. */
90 | polybench_stop_instruments;
91 | polybench_print_instruments;
92 |
93 | /* Prevent dead-code elimination. All live-out data must be printed
94 | by the function call in argument. */
95 | polybench_prevent_dce(print_array(m, n, POLYBENCH_ARRAY(s), POLYBENCH_ARRAY(q)));
96 |
97 | /* Be clean. */
98 | POLYBENCH_FREE_ARRAY(A);
99 | POLYBENCH_FREE_ARRAY(s);
100 | POLYBENCH_FREE_ARRAY(q);
101 | POLYBENCH_FREE_ARRAY(p);
102 | POLYBENCH_FREE_ARRAY(r);
103 |
104 | return 0;
105 | }
106 |
--------------------------------------------------------------------------------
/test_c/utilities/time_benchmark.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | ## time_benchmark.sh for in /Users/pouchet
3 | ##
4 | ## Made by Louis-Noel Pouchet
5 | ## Contact:
6 | ##
7 | ## Started on Sat Oct 29 00:03:48 2011 Louis-Noel Pouchet
8 | ## Last update Fri Apr 22 15:39:13 2016 Louis-Noel Pouchet
9 | ##
10 |
11 | ## Maximal variance accepted between the 3 median runs for performance results.
12 | ## Here 5%
13 | VARIANCE_ACCEPTED=5;
14 |
15 | if [ $# -ne 1 ]; then
16 | echo "Usage: ./time_benchmarh.sh ";
17 | echo "Example: ./time_benchmarh.sh \"./a.out\"";
18 | echo "Note: the file must be a Polybench program compiled with -DPOLYBENCH_TIME";
19 | exit 1;
20 | fi;
21 |
22 |
23 | compute_mean_exec_time()
24 | {
25 | file="$1";
26 | benchcomputed="$2";
27 | cat "$file" | grep "[0-9]\+" | sort -n | head -n 4 | tail -n 3 > avg.out;
28 | expr="(0";
29 | while read n; do
30 | expr="$expr+$n";
31 | done < avg.out;
32 | time=`echo "scale=8;$expr)/3" | bc`;
33 | tmp=`echo "$time" | cut -d '.' -f 1`;
34 | if [ -z "$tmp" ]; then
35 | time="0$time";
36 | fi;
37 | val1=`cat avg.out | head -n 1`;
38 | val2=`cat avg.out | head -n 2 | tail -n 1`;
39 | val3=`cat avg.out | head -n 3 | tail -n 1`;
40 | val11=`echo "a=$val1 - $time;if(0>a)a*=-1;a" | bc 2>&1`;
41 | test_err=`echo "$val11" | grep error`;
42 | if ! [ -z "$test_err" ]; then
43 | echo "[ERROR] Program output does not match expected single-line with time.";
44 | echo "[ERROR] The program must be a PolyBench, compiled with -DPOLYBENCH_TIME";
45 | exit 1;
46 | fi;
47 | val12=`echo "a=$val2 - $time;if(0>a)a*=-1;a" | bc`;
48 | val13=`echo "a=$val3 - $time;if(0>a)a*=-1;a" | bc`;
49 | myvar=`echo "$val11 $val12 $val13" | awk '{ if ($1 > $2) { if ($1 > $3) print $1; else print $3; } else { if ($2 > $3) print $2; else print $3; } }'`;
50 | variance=`echo "scale=5;($myvar/$time)*100" | bc`;
51 | tmp=`echo "$variance" | cut -d '.' -f 1`;
52 | if [ -z "$tmp" ]; then
53 | variance="0$variance";
54 | fi;
55 | compvar=`echo "$variance $VARIANCE_ACCEPTED" | awk '{ if ($1 < $2) print "ok"; else print "error"; }'`;
56 | if [ "$compvar" = "error" ]; then
57 | echo "[WARNING] Variance is above thresold, unsafe performance measurement";
58 | echo " => max deviation=$variance%, tolerance=$VARIANCE_ACCEPTED%";
59 | WARNING_VARIANCE="$WARNING_VARIANCE\n$benchcomputed: max deviation=$variance%, tolerance=$VARIANCE_ACCEPTED%";
60 | else
61 | echo "[INFO] Maximal deviation from arithmetic mean of 3 average runs: $variance%";
62 | fi;
63 | PROCESSED_TIME="$time";
64 | rm -f avg.out;
65 | }
66 |
67 | echo "[INFO] Running 5 times $1..."
68 | echo "[INFO] Maximal variance authorized on 3 average runs: $VARIANCE_ACCEPTED%...";
69 |
70 | $1 > ____tempfile.data.polybench;
71 | $1 >> ____tempfile.data.polybench;
72 | $1 >> ____tempfile.data.polybench;
73 | $1 >> ____tempfile.data.polybench;
74 | $1 >> ____tempfile.data.polybench;
75 |
76 | compute_mean_exec_time "____tempfile.data.polybench" "$1";
77 | echo "[INFO] Normalized time: $PROCESSED_TIME";
78 | rm -f ____tempfile.data.polybench;
79 |
--------------------------------------------------------------------------------
/test/gemm.ll:
--------------------------------------------------------------------------------
1 | ; ModuleID = 'gemm.c'
2 | target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
3 | target triple = "x86_64-unknown-linux-gnu"
4 |
5 | ; Function Attrs: nounwind uwtable
6 | define void @kernel_gemm([25 x i32]* nocapture %C, [30 x i32]* nocapture readonly %A, [25 x i32]* nocapture readonly %B) #0 {
7 | entry:
8 | br label %for.cond1.preheader
9 |
10 | for.cond1.preheader: ; preds = %for.inc32, %entry
11 | %indvars.iv60 = phi i64 [ 0, %entry ], [ %indvars.iv.next61, %for.inc32 ]
12 | br label %for.body3
13 |
14 | for.body3: ; preds = %for.body3, %for.cond1.preheader
15 | %indvars.iv = phi i64 [ 0, %for.cond1.preheader ], [ %indvars.iv.next, %for.body3 ]
16 | %arrayidx5 = getelementptr inbounds [25 x i32]* %C, i64 %indvars.iv60, i64 %indvars.iv
17 | %0 = load i32* %arrayidx5, align 4, !tbaa !1
18 | %mul = shl nsw i32 %0, 1
19 | store i32 %mul, i32* %arrayidx5, align 4, !tbaa !1
20 | %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
21 | %exitcond = icmp eq i64 %indvars.iv.next, 25
22 | br i1 %exitcond, label %for.cond9.preheader, label %for.body3
23 |
24 | for.cond9.preheader: ; preds = %for.body3, %for.inc29
25 | %indvars.iv57 = phi i64 [ %indvars.iv.next58, %for.inc29 ], [ 0, %for.body3 ]
26 | %arrayidx15 = getelementptr inbounds [30 x i32]* %A, i64 %indvars.iv60, i64 %indvars.iv57
27 | br label %for.body11
28 |
29 | for.body11: ; preds = %for.body11, %for.cond9.preheader
30 | %indvars.iv54 = phi i64 [ 0, %for.cond9.preheader ], [ %indvars.iv.next55, %for.body11 ]
31 | %1 = load i32* %arrayidx15, align 4, !tbaa !1
32 | %mul16 = mul nsw i32 %1, 3
33 | %arrayidx20 = getelementptr inbounds [25 x i32]* %B, i64 %indvars.iv57, i64 %indvars.iv54
34 | %2 = load i32* %arrayidx20, align 4, !tbaa !1
35 | %mul21 = mul nsw i32 %mul16, %2
36 | %arrayidx25 = getelementptr inbounds [25 x i32]* %C, i64 %indvars.iv60, i64 %indvars.iv54
37 | %3 = load i32* %arrayidx25, align 4, !tbaa !1
38 | %add = add nsw i32 %3, %mul21
39 | store i32 %add, i32* %arrayidx25, align 4, !tbaa !1
40 | %indvars.iv.next55 = add nuw nsw i64 %indvars.iv54, 1
41 | %exitcond56 = icmp eq i64 %indvars.iv.next55, 25
42 | br i1 %exitcond56, label %for.inc29, label %for.body11
43 |
44 | for.inc29: ; preds = %for.body11
45 | %indvars.iv.next58 = add nuw nsw i64 %indvars.iv57, 1
46 | %exitcond59 = icmp eq i64 %indvars.iv.next58, 30
47 | br i1 %exitcond59, label %for.inc32, label %for.cond9.preheader
48 |
49 | for.inc32: ; preds = %for.inc29
50 | %indvars.iv.next61 = add nuw nsw i64 %indvars.iv60, 1
51 | %exitcond62 = icmp eq i64 %indvars.iv.next61, 20
52 | br i1 %exitcond62, label %for.end34, label %for.cond1.preheader
53 |
54 | for.end34: ; preds = %for.inc32
55 | ret void
56 | }
57 |
58 | attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
59 |
60 | !llvm.ident = !{!0}
61 |
62 | !0 = metadata !{metadata !"clang version 3.4 (tags/RELEASE_34/final)"}
63 | !1 = metadata !{metadata !2, metadata !2, i64 0}
64 | !2 = metadata !{metadata !"int", metadata !3, i64 0}
65 | !3 = metadata !{metadata !"omnipotent char", metadata !4, i64 0}
66 | !4 = metadata !{metadata !"Simple C/C++ TBAA"}
67 |
--------------------------------------------------------------------------------
/test_c/utilities/header-gen.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 |
3 | # Generates headers using specification in polybench.spec
4 | #
5 | # Written by Tomofumi Yuki, 11/21 2014
6 | #
7 |
8 | use File::Path;
9 |
10 | if ($#ARGV != 0) {
11 | printf("usage perl header-gen.pl output-dir\n");
12 | exit(1);
13 | }
14 |
15 | my $SPECFILE = 'polybench.spec';
16 | my $OUTDIR = $ARGV[0];
17 | my @DATASET_NAMES = ('MINI', 'SMALL', 'MEDIUM', 'LARGE', 'EXTRALARGE');
18 |
19 | if (!(-e $OUTDIR)) {
20 | mkdir $OUTDIR;
21 | }
22 |
23 | my %INPUT;
24 | my @keys;
25 |
26 | open FILE, $SPECFILE or die;
27 | while () {
28 | my $line = $_;
29 | $line =~ s/\r|\n//g;
30 | #lines tarting with # is treated as comments
31 | next if ($line=~/^\s*#/);
32 | next if ($line=~/^\s*[\r|\n]+$/);
33 | my @line = split(/\t+/, $line);
34 |
35 | if (!keys %INPUT ) {
36 | foreach (@line) {
37 | $INPUT{$_} = [];
38 | }
39 | @keys = @line;
40 | } else {
41 | for (my $i = 0; $i <= $#line; $i++) {
42 | push @{$INPUT{$keys[$i]}}, $line[$i] ;
43 | }
44 | }
45 | }
46 |
47 | close FILE;
48 |
49 | for (my $r = 0; $r <= $#{$INPUT{'kernel'}}; $r++) {
50 | &generateHeader($r);
51 | }
52 |
53 | sub generateHeader() {
54 |
55 | my $row = $_[0];
56 | my $name = $INPUT{'kernel'}[$row];
57 | my $category = $INPUT{'category'}[$row];
58 | my $datatype = $INPUT{'datatype'}[$row];
59 | my $datatypeUC = uc $datatype;
60 | my @params = split /\s+/, $INPUT{'params'}[$row];
61 |
62 |
63 | my $headerDef = '_'. uc $name . '_H';
64 | $headerDef =~ s/-/_/g;
65 |
66 | my $paramDefs;
67 | foreach $set (@DATASET_NAMES) {
68 | my @sizes = split /\s+/, $INPUT{$set}[$row];
69 | $paramDefs .= '# ifdef '.$set."_DATASET\n";
70 | for (my $i = 0; $i <= $#params; $i++) {
71 | $paramDefs .= '# define '.$params[$i].' '.$sizes[$i]."\n";
72 | }
73 | $paramDefs .= '# endif '."\n\n";
74 | }
75 |
76 | my $paramCheck = '# if';
77 | my $loopBoundDef = '';
78 | {
79 | my $first = 1;
80 | foreach (@params) {
81 | $paramCheck.= ' &&' if (!$first);
82 | $paramCheck .= " !defined($_)";
83 | $first = 0;
84 | $loopBoundDef .= '# define _PB_'.$_.' POLYBENCH_LOOP_BOUND('.$_.','.lc $_.')'."\n";
85 | }
86 | }
87 |
88 | my $kernelPath = "$OUTDIR/$category/$name";
89 | if (!(-e $kernelPath)) {
90 | mkpath $kernelPath;
91 | }
92 |
93 | open HFILE, ">$kernelPath/$name.h";
94 | print HFILE << "EOF";
95 | #ifndef $headerDef
96 | # define $headerDef
97 |
98 | /* Default to LARGE_DATASET. */
99 | # if !defined(MINI_DATASET) && !defined(SMALL_DATASET) && !defined(MEDIUM_DATASET) && !defined(LARGE_DATASET) && !defined(EXTRALARGE_DATASET)
100 | # define LARGE_DATASET
101 | # endif
102 |
103 | $paramCheck
104 | /* Define sample dataset sizes. */
105 | $paramDefs
106 | #endif /* !(@params) */
107 |
108 | $loopBoundDef
109 |
110 | /* Default data type */
111 | # if !defined(DATA_TYPE_IS_INT) && !defined(DATA_TYPE_IS_FLOAT) && !defined(DATA_TYPE_IS_DOUBLE)
112 | # define DATA_TYPE_IS_$datatypeUC
113 | # endif
114 |
115 | #ifdef DATA_TYPE_IS_INT
116 | # define DATA_TYPE int
117 | # define DATA_PRINTF_MODIFIER "%d "
118 | #endif
119 |
120 | #ifdef DATA_TYPE_IS_FLOAT
121 | # define DATA_TYPE float
122 | # define DATA_PRINTF_MODIFIER "%0.2f "
123 | # define SCALAR_VAL(x) x##f
124 | # define SQRT_FUN(x) sqrtf(x)
125 | # define EXP_FUN(x) expf(x)
126 | # define POW_FUN(x,y) powf(x,y)
127 | # endif
128 |
129 | #ifdef DATA_TYPE_IS_DOUBLE
130 | # define DATA_TYPE double
131 | # define DATA_PRINTF_MODIFIER "%0.2lf "
132 | # define SCALAR_VAL(x) x
133 | # define SQRT_FUN(x) sqrt(x)
134 | # define EXP_FUN(x) exp(x)
135 | # define POW_FUN(x,y) pow(x,y)
136 | # endif
137 |
138 | #endif /* !$headerDef */
139 |
140 | EOF
141 | close HFILE;
142 | }
143 |
144 |
--------------------------------------------------------------------------------
/src/LoopUnrollFactor.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | *
11 | */
12 |
13 |
14 | #include "LoopUnrollFactor.h"
15 | #include "GEP.h"
16 |
17 |
18 | int total_unroll_factor(Loop *L)
19 | {
20 | int factor=1;
21 | if(L!=NULL){
22 | if(Loops_unroll[L]>=Loops_counter[L]){
23 | Loop *parent=L->getParentLoop();
24 | int parent_factor=total_unroll_factor(parent);
25 | factor=factor * Loops_unroll[L] *parent_factor;
26 | }
27 | else{
28 | factor=factor * Loops_unroll[L];
29 | }
30 | }
31 | return factor;
32 | }
33 |
34 | bool unroll_loop_relation(Loop *L1, Loop *L2)
35 | {
36 | bool unroll_related=false;
37 | if(L1==L2){
38 | unroll_related=true;
39 | }
40 | else{
41 | if(L2->contains(L1)){
42 | if(Loops_unroll[L1]>=Loops_counter[L1]){
43 | Loop *parent=L1->getParentLoop();
44 | unroll_related=unroll_loop_relation(parent,L2);
45 | }
46 | }
47 | }
48 | return unroll_related;
49 | }
50 |
51 | int total_unroll_factor_ls(LoopInfo *LI, Loop *L, Instruction *inst)
52 | {
53 | int factor=1;
54 | int total_factor=total_unroll_factor(L);
55 | if(isa(inst)||isa(inst)){
56 | GetElementPtrInst *gep=get_GEP(inst);
57 | if(gep!=NULL){
58 | for(User::op_iterator II=gep->idx_begin(),IE=gep->idx_end(); II!=IE; ++II)
59 | {
60 | if(Instruction *tmp_inst=dyn_cast(*II))
61 | {
62 | BasicBlock *bb=tmp_inst->getParent();
63 | Loop *l=LI->getLoopFor(bb);
64 | if(l!=NULL){
65 | bool related=unroll_loop_relation(L,l);
66 | if(related==true){
67 | factor *= Loops_unroll[l];
68 | }
69 | }
70 | }
71 | else{
72 | BasicBlock *bb=gep->getParent();
73 | Loop *l=LI->getLoopFor(bb);
74 | if(l!=NULL){
75 | bool related=unroll_loop_relation(L,l);
76 | if(related==true){
77 | factor *= Loops_unroll[l];
78 | }
79 | }
80 | }
81 | }
82 | }
83 | else{
84 | factor=total_factor;
85 | }
86 | }
87 | return factor;
88 | }
89 |
90 |
91 | int total_unroll_factor_op(LoopInfo *LI, Loop *L, Instruction *inst)
92 | {
93 | int factor=1;
94 | int total_factor=total_unroll_factor(L);
95 | bool op_is_ls=false;
96 | std::map loop_ul_counted;
97 | for(unsigned op=0; op!=inst->getNumOperands(); ++op)
98 | {
99 | Value *OP = inst->getOperand(op);
100 | if(Instruction *inst_op=dyn_cast(OP)){
101 | if(isa(inst_op)||isa(inst_op))
102 | {
103 | GetElementPtrInst *gep=get_GEP(inst_op);
104 | if(gep!=NULL)
105 | {
106 | for(User::op_iterator II=gep->idx_begin(),IE=gep->idx_end(); II!=IE; ++II)
107 | {
108 | if(Instruction *tmp_inst=dyn_cast(*II))
109 | {
110 | BasicBlock *bb=tmp_inst->getParent();
111 | Loop *l=LI->getLoopFor(bb);
112 | if(l!=NULL){
113 | if(!loop_ul_counted.count(l)){
114 | bool related=unroll_loop_relation(L,l);
115 | if(related==true){
116 | factor *= Loops_unroll[l];
117 | loop_ul_counted[l]=factor;
118 | op_is_ls=true;
119 | }
120 | }
121 | }
122 | }
123 | }
124 | }
125 | }
126 | else{
127 | for(unsigned op1=0; op1!=inst_op->getNumOperands(); ++op1)
128 | {
129 | Value *OP1=inst_op->getOperand(op1);
130 | if(Instruction *inst_op1=dyn_cast(OP1))
131 | {
132 | if(isa(inst_op1)||isa(inst_op1))
133 | {
134 | GetElementPtrInst *gep=get_GEP(inst_op1);
135 | if(gep!=NULL){
136 | for(User::op_iterator II=gep->idx_begin(),IE=gep->idx_end(); II!=IE; ++II){
137 | if(Instruction *tmp_inst=dyn_cast(*II)){
138 | BasicBlock *bb=tmp_inst->getParent();
139 | Loop *l=LI->getLoopFor(bb);
140 | if(l!=NULL){
141 | if(!loop_ul_counted.count(l)){
142 | bool related=unroll_loop_relation(L,l);
143 | if(related==true){
144 | factor *= Loops_unroll[l];
145 | loop_ul_counted[l]=factor;
146 | op_is_ls=true;
147 | }
148 | }
149 | }
150 | }
151 | }
152 | }
153 | }
154 | }
155 | }
156 | }
157 | }
158 | }
159 | if(op_is_ls==false){
160 | factor=total_factor;
161 | }
162 | return factor;
163 | }
164 |
--------------------------------------------------------------------------------
/src/test.h:
--------------------------------------------------------------------------------
1 | /*
2 | * COMBA
3 | * Copyright (C) 2017 RCSL, HKUST
4 | *
5 | * ONLY FOR ACADEMIC USE, NOT FOR COMMERCIAL USE.
6 | *
7 | * Please use our tool at academic institutions and non-profit
8 | * research organizations for research use.
9 | *
10 | ***************************************************************
11 | *
12 | * test.h
13 | *
14 | * Created on: Dec 20, 2016
15 | * Author: zjr
16 | */
17 |
18 | #ifndef TEST_H_
19 | #define TEST_H_
20 |
21 | #include "llvm/Pass.h"
22 | #include "llvm/IR/Function.h"
23 | #include "llvm/Support/raw_ostream.h"
24 | #include "llvm/Support/CFG.h"
25 | #include "llvm/Support/GraphWriter.h"
26 | #include "llvm/IR/Intrinsics.h"
27 | #include "llvm/Analysis/LoopInfo.h"
28 | #include "llvm/IR/Constants.h"
29 | #include "llvm/IR/Module.h"
30 | #include "llvm/IR/Instructions.h"
31 | #include "llvm/Support/SourceMgr.h"
32 | #include "llvm/IR/LLVMContext.h"
33 | #include "llvm/IRReader/IRReader.h"
34 | #include
35 | #include "llvm/ADT/Statistic.h"
36 | #include "llvm/Support/InstIterator.h"
37 | #include "llvm/IR/InstrTypes.h"
38 | #include "llvm/PassAnalysisSupport.h"
39 | #include
40 | #include
41 | #include
42 | #include
43 | #include
44 | #include