summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPan Xiuli <xiuli.pan@intel.com>2015-11-20 15:07:42 +0800
committerYang Rong <rong.r.yang@intel.com>2016-04-27 16:17:13 +0800
commit34013270f313e8af0b43376e85529df38e0eba5d (patch)
tree2cbc635b2ce8278cdb7a137742ac1121a352a8a4
parent320c37a39f602e65f8a1f563733f74d09951f2f8 (diff)
downloadbeignet-34013270f313e8af0b43376e85529df38e0eba5d.tar.gz
Backend: Refine printfs into ir unit
Move the printfs of PrintfParser into the ir::Unit to make the gbe thread safe. The old static printfs will be cleared by othrer thread when running in multithread. V2: Rebase the patch Signed-off-by: Pan Xiuli <xiuli.pan@intel.com> Reviewed-by: Yang Rong <rong.r.yang@intel.com>
-rw-r--r--backend/src/ir/printf.cpp1
-rw-r--r--backend/src/ir/printf.hpp2
-rw-r--r--backend/src/ir/unit.cpp1
-rw-r--r--backend/src/ir/unit.hpp5
-rw-r--r--backend/src/llvm/llvm_gen_backend.cpp8
-rw-r--r--backend/src/llvm/llvm_gen_backend.hpp2
-rw-r--r--backend/src/llvm/llvm_printf_parser.cpp35
-rw-r--r--backend/src/llvm/llvm_to_gen.cpp2
8 files changed, 26 insertions, 30 deletions
diff --git a/backend/src/ir/printf.cpp b/backend/src/ir/printf.cpp
index eb1c1990..2e082484 100644
--- a/backend/src/ir/printf.cpp
+++ b/backend/src/ir/printf.cpp
@@ -23,6 +23,7 @@
#include <stdarg.h>
#include "printf.hpp"
+#include "ir/unit.hpp"
namespace gbe
{
diff --git a/backend/src/ir/printf.hpp b/backend/src/ir/printf.hpp
index df58437b..85153a5f 100644
--- a/backend/src/ir/printf.hpp
+++ b/backend/src/ir/printf.hpp
@@ -26,12 +26,12 @@
#include <string.h>
#include "sys/map.hpp"
#include "sys/vector.hpp"
-#include "unit.hpp"
namespace gbe
{
namespace ir
{
+ class Unit;
/* Things about printf info. */
enum {
diff --git a/backend/src/ir/unit.cpp b/backend/src/ir/unit.cpp
index a2a1096a..26d3fb95 100644
--- a/backend/src/ir/unit.cpp
+++ b/backend/src/ir/unit.cpp
@@ -30,6 +30,7 @@ namespace ir {
Unit::Unit(PointerSize pointerSize) : pointerSize(pointerSize), valid(true) {}
Unit::~Unit(void) {
for (const auto &pair : functions) GBE_DELETE(pair.second);
+ for (const auto &pair : printfs) GBE_DELETE(pair.second);
}
Function *Unit::getFunction(const std::string &name) const {
auto it = functions.find(name);
diff --git a/backend/src/ir/unit.hpp b/backend/src/ir/unit.hpp
index cbdab2fd..b69ba8b4 100644
--- a/backend/src/ir/unit.hpp
+++ b/backend/src/ir/unit.hpp
@@ -26,9 +26,12 @@
#include "ir/constant.hpp"
#include "ir/register.hpp"
+#include "ir/printf.hpp"
#include "sys/map.hpp"
#include <string.h>
+#include "llvm/IR/Instructions.h"
+
namespace gbe {
namespace ir {
@@ -88,6 +91,8 @@ namespace ir {
{
public:
typedef map<std::string, Function*> FunctionSet;
+ /*! Moved from printf pass */
+ map<llvm::CallInst*, PrintfSet::PrintfFmt*> printfs;
/*! Create an empty unit */
Unit(PointerSize pointerSize = POINTER_32_BITS);
/*! Release everything (*including* the function pointers) */
diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
index 7e53d79e..549d0c14 100644
--- a/backend/src/llvm/llvm_gen_backend.cpp
+++ b/backend/src/llvm/llvm_gen_backend.cpp
@@ -748,7 +748,13 @@ namespace gbe
// handle load of dword/qword with unaligned address
void emitUnalignedDQLoadStore(ir::Register ptr, Value *llvmValues, ir::AddressSpace addrSpace, ir::Register bti, bool isLoad, bool dwAligned, bool fixedBTI);
void visitInstruction(Instruction &I) {NOT_SUPPORTED;}
- void emitAtomicInstHelper(const ir::AtomicOps opcode,const ir::Type type, const ir::Register dst, llvm::Value* llvmPtr, const ir::Tuple payloadTuple);
+ void emitAtomicInstHelper(const ir::AtomicOps opcode,const ir::Type type, const ir::Register dst, llvm::Value* llvmPtr, const ir::Tuple payloadTuple);
+ void* getPrintfInfo(CallInst* inst)
+ {
+ if (unit.printfs[inst])
+ return (void*)unit.printfs[inst];
+ return NULL;
+ }
private:
ir::ImmediateIndex processConstantImmIndexImpl(Constant *CPV, int32_t index = 0u);
template <typename T, typename P = T>
diff --git a/backend/src/llvm/llvm_gen_backend.hpp b/backend/src/llvm/llvm_gen_backend.hpp
index 94a377b1..800f78f4 100644
--- a/backend/src/llvm/llvm_gen_backend.hpp
+++ b/backend/src/llvm/llvm_gen_backend.hpp
@@ -140,7 +140,7 @@ namespace gbe
llvm::BasicBlockPass *createIntrinsicLoweringPass();
/*! Passer the printf function call. */
- llvm::FunctionPass* createPrintfParserPass();
+ llvm::FunctionPass* createPrintfParserPass(ir::Unit &unit);
#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
/* customized loop unrolling pass. */
diff --git a/backend/src/llvm/llvm_printf_parser.cpp b/backend/src/llvm/llvm_printf_parser.cpp
index 063037d6..4f72f6fd 100644
--- a/backend/src/llvm/llvm_printf_parser.cpp
+++ b/backend/src/llvm/llvm_printf_parser.cpp
@@ -38,6 +38,7 @@
#include "llvm/llvm_gen_backend.hpp"
#include "sys/map.hpp"
#include "ir/printf.hpp"
+#include "ir/unit.hpp"
using namespace llvm;
@@ -301,7 +302,7 @@ error:
Value* g1Xg2Xg3;
Value* wg_offset;
int out_buf_sizeof_offset;
- static map<CallInst*, PrintfSet::PrintfFmt*> printfs;
+ ir::Unit &unit;
int printf_num;
int totalSizeofSize;
@@ -310,13 +311,13 @@ error:
PrintfSet::PrintfFmt* printf_fmt;
};
- PrintfParser(void) : FunctionPass(ID)
+ PrintfParser(ir::Unit &unit) : FunctionPass(ID),
+ unit(unit)
{
module = NULL;
builder = NULL;
intTy = NULL;
out_buf_sizeof_offset = 0;
- printfs.clear();
pbuf_ptr = NULL;
index_buf_ptr = NULL;
g1Xg2Xg3 = NULL;
@@ -325,15 +326,6 @@ error:
totalSizeofSize = 0;
}
- ~PrintfParser(void)
- {
- for (auto &s : printfs) {
- delete s.second;
- s.second = NULL;
- }
- printfs.clear();
- }
-
bool parseOnePrintfInstruction(CallInst * call, PrintfParserInfo& info, int& sizeof_size);
bool generateOneParameterInst(PrintfSlot& slot, Value*& arg, Type*& dst_type, int& sizeof_size);
bool generateOnePrintfInstruction(PrintfParserInfo& pInfo);
@@ -433,9 +425,9 @@ error:
CallInst* printf_inst = builder->CreateCall(cast<llvm::Function>(module->getOrInsertFunction(
"__gen_ocl_printf", Type::getVoidTy(module->getContext()),
NULL)));
- assert(printfs[printf_inst] == NULL);
- printfs[printf_inst] = pInfo.printf_fmt;
- printfs[printf_inst]->second = printf_num;
+ assert(unit.printfs[printf_inst] == NULL);
+ unit.printfs[printf_inst] = pInfo.printf_fmt;
+ unit.printfs[printf_inst]->second = printf_num;
printf_num++;
return true;
}
@@ -983,18 +975,9 @@ error:
return false;
}
- map<CallInst*, PrintfSet::PrintfFmt*> PrintfParser::printfs;
-
- void* getPrintfInfo(CallInst* inst)
- {
- if (PrintfParser::printfs[inst])
- return (void*)PrintfParser::printfs[inst];
- return NULL;
- }
-
- FunctionPass* createPrintfParserPass()
+ FunctionPass* createPrintfParserPass(ir::Unit &unit)
{
- return new PrintfParser();
+ return new PrintfParser(unit);
}
char PrintfParser::ID = 0;
diff --git a/backend/src/llvm/llvm_to_gen.cpp b/backend/src/llvm/llvm_to_gen.cpp
index 11cb79f7..aa470ed1 100644
--- a/backend/src/llvm/llvm_to_gen.cpp
+++ b/backend/src/llvm/llvm_to_gen.cpp
@@ -319,7 +319,7 @@ namespace gbe
passes.add(createPromoteMemoryToRegisterPass());
if(optLevel > 0)
passes.add(createGVNPass()); // Remove redundancies
- passes.add(createPrintfParserPass());
+ passes.add(createPrintfParserPass(unit));
passes.add(createExpandConstantExprPass()); // expand ConstantExpr
passes.add(createScalarizePass()); // Expand all vector ops
passes.add(createExpandLargeIntegersPass()); // legalize large integer operation