-
Notifications
You must be signed in to change notification settings - Fork 6
/
ir_cudaclang.cc
executable file
·134 lines (96 loc) · 4.58 KB
/
ir_cudaclang.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*****************************************************************************
Copyright (C) 2009 University of Utah
All Rights Reserved.
Purpose:
CHiLL's CLANG interface.
Notes:
Array supports mixed pointer and array type in a single declaration.
History:
2/2/2011 Created by Protonu Basu.
*****************************************************************************/
#include <typeinfo>
#include "ir_cudaclang.hh"
#include "loop.hh"
#include "loop_cuda_clang.hh"
IR_cudaclangCode::IR_cudaclangCode(const char *paramfilename, const char* proc_name) :
IR_clangCode(paramfilename, strdup(proc_name)) {
// filename and procedurename are internal to IR_clangcode and therefore part of IR_cudaclangcode
debug_fprintf(stderr, "IR_cudaxxxxCode::IR_cudaxxxxCode( %s, %s )\n", filename, procedurename); // proc_name );
char *fname = strdup(paramfilename);
char *f = fname;
char *ptr = rindex(fname, '/');
if (ptr) fname = ptr + 1;
std::string orig_name(fname);
char *dot = index(fname, '.');
if (dot) *dot = '\0';
std::string naked_name( fname );
cudaFileToWrite = "clang_" + naked_name + ".cu";
//debug_fprintf(stderr, "will write file %s\n", cudaFileToWrite.c_str());
chillfunc->getSourceFile()->setFileToWrite( strdup( cudaFileToWrite.c_str()) );
func_defn = chillfunc;
debug_fprintf(stderr, "IR_cudaxxxxCode::IR_cudaxxxxCode() DONE\n");
}
IR_ArraySymbol *IR_cudaclangCode::CreateArraySymbol(const IR_Symbol *sym,
std::vector<omega::CG_outputRepr *> &size,
int sharedAnnotation) {
debug_fprintf(stderr, "IR_cudaclangCode::CreateArraySymbol( sym = %s )\n", sym->name().c_str());
debug_fprintf(stderr, "size.size() %d\n", size.size());
static int clang_array_counter = 1;
std::string s = std::string("_P") + omega::to_string(clang_array_counter++);
debug_fprintf(stderr, "new array name is %s\n", s.c_str());
if (typeid(*sym) == typeid(IR_clangArraySymbol)) {
//debug_fprintf(stderr, "%s is an array\n", sym->name().c_str());
IR_clangArraySymbol *asym = (IR_clangArraySymbol *) sym;
chillAST_VarDecl *vd = asym->chillvd; // ((const IR_clangArraySymbol *)sym)->chillvd;
vd->print(); printf("\n"); fflush(stdout);
debug_fprintf(stderr, "%s %s %d dimensions arraypart '%s'\n", vd->vartype, vd->varname, vd->numdimensions, vd->arraypart);
chillAST_VarDecl *newarray = (chillAST_VarDecl *)vd->clone();
char arraystring[128];
char *aptr = arraystring;
for (int i=0; i<size.size(); i++) {
omega::CG_chillRepr *CR = (omega::CG_chillRepr *) size[i];
chillAST_IntegerLiteral *IL = (chillAST_IntegerLiteral *) ( (CR->getChillCode()) [0]);
printf("size[%d] ", i); IL->print(); printf("\n"); fflush(stdout);
newarray->arraysizes[i] = IL->value; // this could die if new var will have MORE dimensions than the one we're copying
sprintf(aptr, "[%d]", IL->value);
aptr += strlen(aptr);
}
debug_fprintf(stderr, "arraypart WAS %s now %s\n", newarray->arraypart, arraystring);
newarray->arraypart = strdup(arraystring);
newarray->numdimensions = size.size();
debug_fprintf(stderr, "newarray numdimensions %d\n", newarray->numdimensions);
newarray->varname = strdup(s.c_str());
IR_clangArraySymbol *newsym = new IR_clangArraySymbol( asym->ir_, newarray, asym->offset_ );
if (sharedAnnotation == 1) {
debug_fprintf(stderr, "%s is SHARED\n", newarray->varname );
newarray->isShared = true;
}
debug_fprintf(stderr, "done making a new array symbol\n");
return newsym;
}
debug_fprintf(stderr, "IR_cudaclangCode::CreateArraySymbol() but old symbol is not an array???\n");
exit(-1);
IR_ArraySymbol *smb = new IR_clangArraySymbol(this, NULL);
debug_fprintf(stderr, "done making a new array symbol\n\n");
return smb;
}
bool IR_cudaclangCode::commit_loop(Loop *loop, int loop_num) {
if (loop == NULL)
return true;
debug_fprintf(stderr, " IR_cudaxxxxCode::commit_loop()\n");
loop->printCode();
debug_fprintf(stderr, "loop->printCode done\n\n");
LoopCuda *cu_loop = (LoopCuda *) loop;
chillAST_node * loopcode = cu_loop->codegen();
if (!loopcode)
return false;
debug_fprintf(stderr, "IR_cudaxxxxCode::commit_loop() codegen DONE\n");
debug_fprintf(stderr, "loopcode is\n");
loopcode->print(); fflush(stdout);
debug_fprintf(stderr, "(END LOOPCODE)\n\n\n");
// put "loopcode" into GPUside ?? easier in codegen
entire_file_AST->print();
return NULL;
}
IR_cudaclangCode::~IR_cudaclangCode() {
}