2018-12-15 22:29:36 -05:00
|
|
|
#include <cstring>
|
|
|
|
#include <cstdio>
|
2019-01-05 14:50:31 -05:00
|
|
|
#include "ast/ast.h"
|
2019-01-03 17:14:54 -05:00
|
|
|
#include "ir/context.h"
|
|
|
|
#include "ir/module.h"
|
2019-01-07 04:08:55 -05:00
|
|
|
#include "codegen/selection.h"
|
2019-01-08 17:44:31 -05:00
|
|
|
#include "codegen/tune.h"
|
2019-01-12 23:24:25 -05:00
|
|
|
#include "codegen/shared_copy.h"
|
|
|
|
#include "codegen/allocation.h"
|
|
|
|
#include "codegen/liveness.h"
|
2019-01-05 19:23:00 -05:00
|
|
|
#include "llvm/IR/IRPrintingPasses.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
2019-01-06 00:53:11 -05:00
|
|
|
#include "llvm/IR/PassManager.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2018-12-15 22:29:36 -05:00
|
|
|
|
|
|
|
typedef struct yy_buffer_state * YY_BUFFER_STATE;
|
|
|
|
extern int yyparse();
|
|
|
|
extern YY_BUFFER_STATE yy_scan_string(const char * str);
|
|
|
|
extern void yy_delete_buffer(YY_BUFFER_STATE buffer);
|
2018-12-17 10:43:49 -05:00
|
|
|
using tdl::ast::translation_unit;
|
2018-12-16 16:15:40 -05:00
|
|
|
extern translation_unit *ast_root;
|
2018-12-15 22:29:36 -05:00
|
|
|
|
2018-12-16 12:35:28 -05:00
|
|
|
const char src[] =
|
|
|
|
"\
|
2019-01-10 23:53:27 -05:00
|
|
|
void test(fp32 *a, fp32 *b, fp32 *c, int32 M, int32 N, int32 K){\
|
2019-01-23 00:11:42 -05:00
|
|
|
int32 rx[32] = get_global_range[32](0);\
|
|
|
|
int32 ry[32] = get_global_range[32](1);\
|
2019-01-10 23:53:27 -05:00
|
|
|
int32 rka[8] = 0 ... 8;\
|
|
|
|
int32 rkb[8] = 0 ... 8;\
|
2019-01-23 00:11:42 -05:00
|
|
|
fp32 C[32, 32] = 0;\
|
2019-01-10 16:50:47 -05:00
|
|
|
int32 k;\
|
2019-01-23 00:11:42 -05:00
|
|
|
fp32* pa[32, 8] = a + rx[:, newaxis] + rka[newaxis, :]*M;\
|
|
|
|
fp32* pb[32, 8] = b + ry[:, newaxis] + rkb[newaxis, :]*K;\
|
2019-01-26 02:05:56 -05:00
|
|
|
fp32* pc[32, 32] = c + rx[:, newaxis] + ry[newaxis, :]*M;\
|
2019-02-06 23:34:45 -05:00
|
|
|
for(k = K; k >= 0; k = k - 8){\
|
2019-02-07 17:03:19 -05:00
|
|
|
fp32 a[32, 8] = *pa;\
|
|
|
|
fp32 b[32, 8] = *pb;\
|
2019-02-06 23:34:45 -05:00
|
|
|
C = C + 1;\
|
2019-02-07 17:03:19 -05:00
|
|
|
pa = pa + 8*M;\
|
|
|
|
pb = pb + 8*K;\
|
2019-02-06 23:34:45 -05:00
|
|
|
}\
|
2019-01-10 23:53:27 -05:00
|
|
|
*pc = C;\
|
2018-12-16 12:35:28 -05:00
|
|
|
}\
|
|
|
|
";
|
|
|
|
|
2018-12-15 22:29:36 -05:00
|
|
|
int main() {
|
2018-12-16 12:35:28 -05:00
|
|
|
YY_BUFFER_STATE buffer = yy_scan_string(src);
|
|
|
|
yyparse();
|
2018-12-15 22:29:36 -05:00
|
|
|
yy_delete_buffer(buffer);
|
2019-01-03 17:14:54 -05:00
|
|
|
translation_unit *program = ast_root;
|
|
|
|
tdl::ir::context context;
|
|
|
|
tdl::ir::module module("matrix", context);
|
|
|
|
program->codegen(&module);
|
2019-01-05 19:23:00 -05:00
|
|
|
llvm::LLVMContext llvm_context;
|
|
|
|
llvm::Module llvm_module("test", llvm_context);
|
2019-01-08 17:44:31 -05:00
|
|
|
// lowering passes
|
2019-01-12 23:24:25 -05:00
|
|
|
tdl::codegen::place_shared_copy shared;
|
2019-01-08 17:44:31 -05:00
|
|
|
tdl::codegen::tune tune;
|
2019-01-12 23:24:25 -05:00
|
|
|
tdl::codegen::liveness liveness;
|
|
|
|
tdl::codegen::allocation allocation(&liveness);
|
2019-01-23 00:11:42 -05:00
|
|
|
tdl::codegen::selection selection(&allocation, &tune);
|
2019-01-08 17:44:31 -05:00
|
|
|
tune.run(module);
|
2019-01-23 00:11:42 -05:00
|
|
|
std::vector<unsigned> params = {
|
|
|
|
// asm
|
2019-01-26 02:05:56 -05:00
|
|
|
2, 8, 1,
|
2019-01-23 00:11:42 -05:00
|
|
|
// bsn
|
2019-01-26 02:05:56 -05:00
|
|
|
4, 4, 1,
|
2019-01-23 00:11:42 -05:00
|
|
|
// pa
|
2019-01-26 02:05:56 -05:00
|
|
|
2, 4, 1,
|
2019-01-23 00:11:42 -05:00
|
|
|
// pb
|
2019-01-26 02:05:56 -05:00
|
|
|
1, 8, 1,
|
2019-01-23 00:11:42 -05:00
|
|
|
};
|
|
|
|
std::map<tdl::ir::value*, std::vector<std::string>> errors;
|
|
|
|
unsigned i = 0;
|
|
|
|
std::cout << tune.get_params(module).size() << std::endl;
|
|
|
|
for(unsigned *x: tune.get_params(module))
|
|
|
|
*x = params[i++];
|
|
|
|
tune.check_constraints(module, errors);
|
2019-01-26 02:05:56 -05:00
|
|
|
std::cout << "errors: " << errors.size() << std::endl;
|
|
|
|
for(auto &x: errors){
|
|
|
|
for(auto &e: x.second)
|
|
|
|
std::cout << e << std::endl;
|
|
|
|
}
|
2019-01-12 23:24:25 -05:00
|
|
|
shared.run(module);
|
|
|
|
liveness.run(module);
|
|
|
|
allocation.run();
|
2019-01-23 00:11:42 -05:00
|
|
|
selection.run(module, llvm_module);
|
|
|
|
// std::vector<unsigned*> params = tune.get_params(module);
|
|
|
|
// std::cout << params.size() << std::endl;
|
2019-01-08 17:44:31 -05:00
|
|
|
// selection.run(module, llvm_module);
|
2019-02-06 17:21:07 -05:00
|
|
|
// print LLVM program
|
|
|
|
llvm::PrintModulePass print(llvm::outs());
|
|
|
|
llvm::AnalysisManager<llvm::Module> analysis;
|
|
|
|
print.run(llvm_module, analysis);
|
2018-12-15 22:29:36 -05:00
|
|
|
return 0;
|
|
|
|
}
|