From: Junyan He junyan...@linux.intel.com
The llvm will generate ir which has if.else block before
if.then block. We parse the printf statement before llvm_to_gen.
The later if-else analysis will reorder the if-else blocks.
This cause when we print out the result, we get the wrong message
from another printf statement.
Add printf index to the index buffer to record which one the result
belongs to, and so this bug is fixed.
Signed-off-by: Junyan He junyan...@linux.intel.com
---
backend/src/ir/printf.cpp | 25 -
backend/src/ir/printf.hpp | 2 +-
backend/src/llvm/llvm_printf_parser.cpp | 19 ---
src/cl_command_queue_gen7.c | 2 +-
4 files changed, 34 insertions(+), 14 deletions(-)
diff --git a/backend/src/ir/printf.cpp b/backend/src/ir/printf.cpp
index fa108dc..3d9b2fd 100644
--- a/backend/src/ir/printf.cpp
+++ b/backend/src/ir/printf.cpp
@@ -34,8 +34,9 @@ namespace gbe
uint32_t PrintfSet::append(PrintfFmt* fmt, Unit unit)
{
fmts.push_back(*fmt);
+ vectorPrintfSlot vp = fmts.back().first;
- for (PrintfFmt::iterator f = fmts.back().begin(); f !=
fmts.back().end(); ++f) {
+ for (vectorPrintfSlot::iterator f = vp.begin(); f != vp.end(); ++f) {
if (f-type == PRINTF_SLOT_TYPE_STRING)
continue;
@@ -126,14 +127,27 @@ namespace gbe
int stmt = 0;
for (size_t count = 0; count fmts.size(); ++count) {
-PrintfFmt pf = fmts[count];
for (i = 0; i global_wk_sz0; i++) {
for (j = 0; j global_wk_sz1; j++) {
for (k = 0; k global_wk_sz2; k++) {
- int loop_num = ((int
*)index_addr)[stmt*global_wk_sz0*global_wk_sz1*global_wk_sz2
- +
k*global_wk_sz0*global_wk_sz1 + j*global_wk_sz0 + i];
+ int loop_num = ((int
*)index_addr)[(stmt*global_wk_sz0*global_wk_sz1*global_wk_sz2
+ +
k*global_wk_sz0*global_wk_sz1 + j*global_wk_sz0 + i)*2];
+ int printf_num = ((int
*)index_addr)[(stmt*global_wk_sz0*global_wk_sz1*global_wk_sz2
+ +
k*global_wk_sz0*global_wk_sz1 + j*global_wk_sz0 + i)*2 + 1];
+ if (!loop_num) continue;
+
+ PrintfFmt* ppf = NULL;
+ for (auto f : fmts) {
+if (f.second == printf_num) {
+ ppf = f;
+ break;
+}
+ }
+
+ PrintfFmt pf = *ppf;
+
for (int n = 0; n loop_num; n++) {
-for (PrintfFmt::iterator pfit = pf.begin(); pfit != pf.end();
++pfit) {
+for (vectorPrintfSlot::iterator pfit = pf.first.begin();
pfit != pf.first.end(); ++pfit) {
PrintfSlot slot = *pfit;
pf_str = ;
int vec_num;
@@ -146,6 +160,7 @@ namespace gbe
generatePrintfFmtString(*slot.state, pf_str);
+
vec_num = slot.state-vector_n 0 ? slot.state-vector_n :
1;
for (int vec_i = 0; vec_i vec_num; vec_i++) {
diff --git a/backend/src/ir/printf.hpp b/backend/src/ir/printf.hpp
index f6c6bcf..cbab759 100644
--- a/backend/src/ir/printf.hpp
+++ b/backend/src/ir/printf.hpp
@@ -198,7 +198,7 @@ namespace gbe
}
};
- typedef vectorPrintfSlot PrintfFmt;
+ typedef std::pairvectorPrintfSlot, int PrintfFmt;
uint32_t append(PrintfFmt* fmt, Unit unit);
uint32_t getPrintfNum(void) const {
diff --git a/backend/src/llvm/llvm_printf_parser.cpp
b/backend/src/llvm/llvm_printf_parser.cpp
index 8fec683..52da2e5 100644
--- a/backend/src/llvm/llvm_printf_parser.cpp
+++ b/backend/src/llvm/llvm_printf_parser.cpp
@@ -268,7 +268,7 @@ again:
if (p != begin) {
std::string s = std::string(begin, size_t(p - begin));
-printf_fmt-push_back(PrintfSlot(s.c_str()));
+printf_fmt-first.push_back(PrintfSlot(s.c_str()));
}
if (p == end) // finish
@@ -279,7 +279,7 @@ again:
if (ret_char 0)
goto error;
- printf_fmt-push_back(state);
+ printf_fmt-first.push_back(state);
num++;
if (rend == end)
@@ -385,14 +385,14 @@ error:
/
/* calculate index address.
- index_addr = (index_offset + wg_offset )* sizeof(int) + index_buf_ptr
+ index_addr = (index_offset + wg_offset )* sizeof(int) * 2 +
index_buf_ptr
index_offset = global_size2 * global_size1 * global_size0 * printf_num
*/
Value* index_offset = builder-CreateMul(g1Xg2Xg3, ConstantInt::get(intTy,
printf_num));
// index_offset + offset
op0 = builder-CreateAdd(index_offset, wg_offset);
-// (index_offset + offset)* sizeof(int)
-op0 = builder-CreateMul(op0, ConstantInt::get(intTy, sizeof(int)));
+// (index_offset + offset)* sizeof(int) * 2
+