[Beignet] [PATCH] GBE: add thread_local for class static variable
Pan Xiuli
xiuli.pan at intel.com
Wed Oct 28 01:55:48 PDT 2015
The utest segment fault was casused by a class static
variable printfs. It will be randomly cleared by other
thread and cause the error. To make the gbe thread-safe
just add thread_local for all static variables in
classes.
Signed-off-by: Pan Xiuli <xiuli.pan at intel.com>
---
backend/src/llvm/ExpandLargeIntegers.cpp | 4 ++--
backend/src/llvm/PromoteIntegers.cpp | 4 ++--
backend/src/llvm/StripAttributes.cpp | 4 ++--
backend/src/llvm/llvm_barrier_nodup.cpp | 4 ++--
backend/src/llvm/llvm_gen_backend.cpp | 4 ++--
backend/src/llvm/llvm_intrinsic_lowering.cpp | 4 ++--
backend/src/llvm/llvm_loadstore_optimization.cpp | 4 ++--
backend/src/llvm/llvm_passes.cpp | 4 ++--
backend/src/llvm/llvm_printf_parser.cpp | 8 ++++----
backend/src/llvm/llvm_sampler_fix.cpp | 4 ++--
backend/src/llvm/llvm_scalarize.cpp | 4 ++--
backend/src/llvm/llvm_unroll.cpp | 4 ++--
12 files changed, 26 insertions(+), 26 deletions(-)
diff --git a/backend/src/llvm/ExpandLargeIntegers.cpp b/backend/src/llvm/ExpandLargeIntegers.cpp
index 20fdda9..caca4b4 100644
--- a/backend/src/llvm/ExpandLargeIntegers.cpp
+++ b/backend/src/llvm/ExpandLargeIntegers.cpp
@@ -108,7 +108,7 @@ static const unsigned kChunkBytes = kChunkBits / CHAR_BIT;
namespace {
class ExpandLargeIntegers : public FunctionPass {
public:
- static char ID;
+ thread_local static char ID;
ExpandLargeIntegers() : FunctionPass(ID) {
}
bool runOnFunction(Function &F) override;
@@ -140,7 +140,7 @@ struct ForwardPHI {
};
}
-char ExpandLargeIntegers::ID = 0;
+thread_local char ExpandLargeIntegers::ID = 0;
static bool isLegalBitSize(unsigned Bits) {
assert(Bits && "Can't have zero-size integers");
diff --git a/backend/src/llvm/PromoteIntegers.cpp b/backend/src/llvm/PromoteIntegers.cpp
index b65440f..dbac5ba 100644
--- a/backend/src/llvm/PromoteIntegers.cpp
+++ b/backend/src/llvm/PromoteIntegers.cpp
@@ -93,14 +93,14 @@ using namespace llvm;
namespace {
class PromoteIntegers : public FunctionPass {
public:
- static char ID;
+ thread_local static char ID;
PromoteIntegers() : FunctionPass(ID) {
}
virtual bool runOnFunction(Function &F);
};
}
-char PromoteIntegers::ID = 0;
+thread_local char PromoteIntegers::ID = 0;
// Legal sizes are currently 1, 8, 16, 32, and 64.
// We can't yet expand types above 64 bit, so don't try to touch them for now.
diff --git a/backend/src/llvm/StripAttributes.cpp b/backend/src/llvm/StripAttributes.cpp
index e6df312..ecc6b0e 100644
--- a/backend/src/llvm/StripAttributes.cpp
+++ b/backend/src/llvm/StripAttributes.cpp
@@ -78,7 +78,7 @@ using namespace llvm;
namespace {
class StripAttributes : public FunctionPass {
public:
- static char ID; // Pass identification, replacement for typeid
+ thread_local static char ID; // Pass identification, replacement for typeid
StripAttributes() : FunctionPass(ID) {
}
@@ -86,7 +86,7 @@ namespace {
};
}
-char StripAttributes::ID = 0;
+thread_local char StripAttributes::ID = 0;
bool StripAttributes::runOnFunction(Function &Func) {
if (!gbe::isKernelFunction(Func))
diff --git a/backend/src/llvm/llvm_barrier_nodup.cpp b/backend/src/llvm/llvm_barrier_nodup.cpp
index 727e6bd..e8e5062 100644
--- a/backend/src/llvm/llvm_barrier_nodup.cpp
+++ b/backend/src/llvm/llvm_barrier_nodup.cpp
@@ -40,7 +40,7 @@ namespace gbe {
class BarrierNodup : public ModulePass
{
public:
- static char ID;
+ thread_local static char ID;
BarrierNodup(bool nodup) :
ModulePass(ID), nodup(nodup) {}
@@ -88,5 +88,5 @@ namespace gbe {
return new BarrierNodup(Nodup);
}
- char BarrierNodup::ID = 0;
+ thread_local char BarrierNodup::ID = 0;
} // end namespace
diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
index 3d76265..c8bafef 100644
--- a/backend/src/llvm/llvm_gen_backend.cpp
+++ b/backend/src/llvm/llvm_gen_backend.cpp
@@ -438,7 +438,7 @@ namespace gbe
const Module *TheModule;
int btiBase;
public:
- static char ID;
+ thread_local static char ID;
explicit GenWriter(ir::Unit &unit)
: FunctionPass(ID),
unit(unit),
@@ -645,7 +645,7 @@ namespace gbe
ir::ImmediateIndex processConstantVector(ConstantVector *cv, int index);
};
- char GenWriter::ID = 0;
+ thread_local char GenWriter::ID = 0;
static void updatePointerSource(Value *parent, Value *theUser, Value *source, SmallVector<Value *, 4> &pointers) {
if (isa<SelectInst>(theUser)) {
diff --git a/backend/src/llvm/llvm_intrinsic_lowering.cpp b/backend/src/llvm/llvm_intrinsic_lowering.cpp
index b35d1e6..33869a4 100644
--- a/backend/src/llvm/llvm_intrinsic_lowering.cpp
+++ b/backend/src/llvm/llvm_intrinsic_lowering.cpp
@@ -32,7 +32,7 @@ namespace gbe {
class InstrinsicLowering : public BasicBlockPass
{
public:
- static char ID;
+ thread_local static char ID;
InstrinsicLowering() :
BasicBlockPass(ID) {}
@@ -152,7 +152,7 @@ namespace gbe {
}
};
- char InstrinsicLowering::ID = 0;
+ thread_local char InstrinsicLowering::ID = 0;
BasicBlockPass *createIntrinsicLoweringPass() {
return new InstrinsicLowering();
diff --git a/backend/src/llvm/llvm_loadstore_optimization.cpp b/backend/src/llvm/llvm_loadstore_optimization.cpp
index 698fdc2..5d1f13c 100644
--- a/backend/src/llvm/llvm_loadstore_optimization.cpp
+++ b/backend/src/llvm/llvm_loadstore_optimization.cpp
@@ -29,7 +29,7 @@ namespace gbe {
class GenLoadStoreOptimization : public BasicBlockPass {
public:
- static char ID;
+ thread_local static char ID;
ScalarEvolution *SE;
const DataLayout *TD;
GenLoadStoreOptimization() : BasicBlockPass(ID) {}
@@ -72,7 +72,7 @@ namespace gbe {
}
};
- char GenLoadStoreOptimization::ID = 0;
+ thread_local char GenLoadStoreOptimization::ID = 0;
Value *GenLoadStoreOptimization::getPointerOperand(Value *I) {
if (LoadInst *LI = dyn_cast<LoadInst>(I)) return LI->getPointerOperand();
diff --git a/backend/src/llvm/llvm_passes.cpp b/backend/src/llvm/llvm_passes.cpp
index d5d965b..9653c37 100644
--- a/backend/src/llvm/llvm_passes.cpp
+++ b/backend/src/llvm/llvm_passes.cpp
@@ -188,7 +188,7 @@ namespace gbe
{
public:
- static char ID;
+ thread_local static char ID;
GenRemoveGEPPasss(const ir::Unit &unit) :
BasicBlockPass(ID),
unit(unit) {}
@@ -216,7 +216,7 @@ namespace gbe
}
};
- char GenRemoveGEPPasss::ID = 0;
+ thread_local char GenRemoveGEPPasss::ID = 0;
bool GenRemoveGEPPasss::simplifyGEPInstructions(GetElementPtrInst* GEPInst)
{
diff --git a/backend/src/llvm/llvm_printf_parser.cpp b/backend/src/llvm/llvm_printf_parser.cpp
index bdaed8a..3a94074 100644
--- a/backend/src/llvm/llvm_printf_parser.cpp
+++ b/backend/src/llvm/llvm_printf_parser.cpp
@@ -290,7 +290,7 @@ error:
class PrintfParser : public FunctionPass
{
public:
- static char ID;
+ thread_local static char ID;
typedef std::pair<Instruction*, bool> PrintfInst;
std::vector<PrintfInst> deadprintfs;
Module* module;
@@ -301,7 +301,7 @@ error:
Value* g1Xg2Xg3;
Value* wg_offset;
int out_buf_sizeof_offset;
- static map<CallInst*, PrintfSet::PrintfFmt*> printfs;
+ thread_local static map<CallInst*, PrintfSet::PrintfFmt*> printfs;
int printf_num;
int totalSizeofSize;
@@ -972,7 +972,7 @@ error:
return false;
}
- map<CallInst*, PrintfSet::PrintfFmt*> PrintfParser::printfs;
+ thread_local map<CallInst*, PrintfSet::PrintfFmt*> PrintfParser::printfs;
void* getPrintfInfo(CallInst* inst)
{
@@ -985,6 +985,6 @@ error:
{
return new PrintfParser();
}
- char PrintfParser::ID = 0;
+ thread_local char PrintfParser::ID = 0;
} // end namespace
diff --git a/backend/src/llvm/llvm_sampler_fix.cpp b/backend/src/llvm/llvm_sampler_fix.cpp
index 01db8fe..0002d48 100644
--- a/backend/src/llvm/llvm_sampler_fix.cpp
+++ b/backend/src/llvm/llvm_sampler_fix.cpp
@@ -115,11 +115,11 @@ namespace gbe {
return changed;
}
- static char ID;
+ thread_local static char ID;
};
FunctionPass* createSamplerFixPass() {
return new SamplerFix();
}
- char SamplerFix::ID = 0;
+ thread_local char SamplerFix::ID = 0;
};
diff --git a/backend/src/llvm/llvm_scalarize.cpp b/backend/src/llvm/llvm_scalarize.cpp
index 7ee5259..657a4d9 100644
--- a/backend/src/llvm/llvm_scalarize.cpp
+++ b/backend/src/llvm/llvm_scalarize.cpp
@@ -92,7 +92,7 @@ namespace gbe {
public:
// Standard pass stuff
- static char ID;
+ thread_local static char ID;
Scalarize() : FunctionPass(ID)
{
@@ -872,6 +872,6 @@ namespace gbe {
{
return new Scalarize();
}
- char Scalarize::ID = 0;
+ thread_local char Scalarize::ID = 0;
} // end namespace
diff --git a/backend/src/llvm/llvm_unroll.cpp b/backend/src/llvm/llvm_unroll.cpp
index 6990e39..4f235bb 100644
--- a/backend/src/llvm/llvm_unroll.cpp
+++ b/backend/src/llvm/llvm_unroll.cpp
@@ -31,7 +31,7 @@ namespace gbe {
class CustomLoopUnroll : public LoopPass
{
public:
- static char ID;
+ thread_local static char ID;
CustomLoopUnroll() :
LoopPass(ID) {}
@@ -219,7 +219,7 @@ namespace gbe {
};
- char CustomLoopUnroll::ID = 0;
+ thread_local char CustomLoopUnroll::ID = 0;
LoopPass *createCustomLoopUnrollPass() {
return new CustomLoopUnroll();
--
2.1.4
More information about the Beignet
mailing list