summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunyan He <junyan.he@linux.intel.com>2014-06-24 23:33:20 +0800
committerZhigang Gong <zhigang.gong@intel.com>2014-06-24 23:34:46 +0800
commit8cc0f05202749e305b804fe7f952b4f79ab06975 (patch)
tree3f9a5d98a108e0a7fa1f38ad26bfc1ad3119cc88
parent1a64ca328fdcd7c5f60e73b19938f945d0b2fc7b (diff)
downloadbeignet-8cc0f05202749e305b804fe7f952b4f79ab06975.tar.gz
Implement the %p in the printf
Signed-off-by: Junyan He <junyan.he@linux.intel.com> Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
-rw-r--r--backend/src/ir/printf.cpp3
-rw-r--r--backend/src/ir/printf.hpp3
-rw-r--r--backend/src/llvm/llvm_printf_parser.cpp21
3 files changed, 22 insertions, 5 deletions
diff --git a/backend/src/ir/printf.cpp b/backend/src/ir/printf.cpp
index 68b2ce48..9d604021 100644
--- a/backend/src/ir/printf.cpp
+++ b/backend/src/ir/printf.cpp
@@ -193,6 +193,9 @@ namespace gbe
case PRINTF_CONVERSION_a:
PRINT_SOMETHING(float, a);
break;
+ case PRINTF_CONVERSION_P:
+ PRINT_SOMETHING(int, p);
+ break;
case PRINTF_CONVERSION_S:
pf_str = pf_str + "s";
diff --git a/backend/src/ir/printf.hpp b/backend/src/ir/printf.hpp
index 680b8e6b..1aef767f 100644
--- a/backend/src/ir/printf.hpp
+++ b/backend/src/ir/printf.hpp
@@ -196,7 +196,8 @@ namespace gbe
case PRINTF_CONVERSION_U:
case PRINTF_CONVERSION_X:
case PRINTF_CONVERSION_x:
- /* Char will be aligned to sizeof(int) here. */
+ case PRINTF_CONVERSION_P:
+ /* Char will be aligned to sizeof(int) here. */
case PRINTF_CONVERSION_C:
return (uint32_t)(sizeof(int) * vec_num);
case PRINTF_CONVERSION_E:
diff --git a/backend/src/llvm/llvm_printf_parser.cpp b/backend/src/llvm/llvm_printf_parser.cpp
index ff8e2591..74b57ab0 100644
--- a/backend/src/llvm/llvm_printf_parser.cpp
+++ b/backend/src/llvm/llvm_printf_parser.cpp
@@ -228,7 +228,7 @@ namespace gbe
CONVERSION_SPEC_AND_RET('s', S)
CONVERSION_SPEC_AND_RET('p', P)
- // %% has been handled
+ // %% has been handled
default:
return -1;
@@ -334,7 +334,8 @@ error:
static map<CallInst*, PrintfSet::PrintfFmt*> printfs;
int printf_num;
- PrintfParser(void) : FunctionPass(ID) {
+ PrintfParser(void) : FunctionPass(ID)
+ {
module = NULL;
builder = NULL;
intTy = NULL;
@@ -345,7 +346,8 @@ error:
printf_num = 0;
}
- ~PrintfParser(void) {
+ ~PrintfParser(void)
+ {
for (auto &s : printfs) {
delete s.second;
s.second = NULL;
@@ -357,7 +359,8 @@ error:
bool parseOnePrintfInstruction(CallInst *& call);
bool generateOneParameterInst(PrintfSlot& slot, Value*& arg, Type*& dst_type, int& sizeof_size);
- virtual const char *getPassName() const {
+ virtual const char *getPassName() const
+ {
return "Printf Parser";
}
@@ -744,8 +747,18 @@ error:
slot.state->str = fmt_arg->getAsCString();
return true;
}
+ case PRINTF_CONVERSION_P: {
+ arg = builder->CreatePtrToInt(arg, Type::getInt32Ty(module->getContext()));
+ dst_type = arg->getType()->getPointerTo(1);
+ sizeof_size = sizeof(int);
+ return true;
+ }
+ default:
+ return false;
}
+ break;
+
case Type::VectorTyID: {
Type* vect_type = arg->getType();
Type* elt_type = vect_type->getVectorElementType();