LGTM, pushed, thanks.
> -----Original Message----- > From: Beignet [mailto:[email protected]] On Behalf Of > Pan Xiuli > Sent: Friday, November 20, 2015 15:08 > To: [email protected] > Cc: Pan, Xiuli > Subject: [Beignet] [PATCH V2] 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 <[email protected]> > --- > backend/src/ir/printf.cpp | 1 + > backend/src/ir/printf.hpp | 2 +- > backend/src/ir/unit.cpp | 1 + > backend/src/ir/unit.hpp | 5 +++++ > backend/src/llvm/llvm_gen_backend.cpp | 6 ++++++ > backend/src/llvm/llvm_gen_backend.hpp | 2 +- > backend/src/llvm/llvm_printf_parser.cpp | 35 +++++++++---------------------- > -- > backend/src/llvm/llvm_to_gen.cpp | 2 +- > 8 files changed, 25 insertions(+), 29 deletions(-) > > diff --git a/backend/src/ir/printf.cpp b/backend/src/ir/printf.cpp index > eb1c199..2e08248 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 > df58437..85153a5 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 > 5604244..a350c60 100644 > --- a/backend/src/ir/unit.cpp > +++ b/backend/src/ir/unit.cpp > @@ -34,6 +34,7 @@ namespace ir { > Unit::~Unit(void) { > for (const auto &pair : functions) GBE_DELETE(pair.second); > delete profilingInfo; > + 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 > 41dc1ae..10a1af6 100644 > --- a/backend/src/ir/unit.hpp > +++ b/backend/src/ir/unit.hpp > @@ -27,8 +27,11 @@ > #include "ir/constant.hpp" > #include "ir/register.hpp" > #include "ir/profiling.hpp" > +#include "ir/printf.hpp" > #include "sys/map.hpp" > > +#include "llvm/IR/Instructions.h" > + > namespace gbe { > namespace ir { > > @@ -43,6 +46,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 d1b6f98..0252746 100644 > --- a/backend/src/llvm/llvm_gen_backend.cpp > +++ b/backend/src/llvm/llvm_gen_backend.cpp > @@ -672,6 +672,12 @@ 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* 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 cf601d3..23688f5 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); > > /*! Insert the time stamp for profiling. */ > llvm::FunctionPass* createProfilingInserterPass(int profilingType, ir::Unit > &unit); diff --git a/backend/src/llvm/llvm_printf_parser.cpp > b/backend/src/llvm/llvm_printf_parser.cpp > index e2adcd8..422f16b 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); @@ -428,9 > +420,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; > } > @@ -972,18 +964,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 8a076ca..83b56ae 100644 > --- a/backend/src/llvm/llvm_to_gen.cpp > +++ b/backend/src/llvm/llvm_to_gen.cpp > @@ -275,7 +275,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 > -- > 2.1.4 > > _______________________________________________ > Beignet mailing list > [email protected] > http://lists.freedesktop.org/mailman/listinfo/beignet _______________________________________________ Beignet mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/beignet
