[Beignet] [PATCH v2] improve multithread calling of llvm
Homer Hsing
homer.xing at intel.com
Wed Nov 6 23:32:56 PST 2013
call llvm multithread function instead of using a semaphore.
also exit llvm multithread mode at the end of life.
v2: not call llvm::shutdown() if llvm is older than 3.4
Signed-off-by: Homer Hsing <homer.xing at intel.com>
---
backend/src/backend/gen_program.cpp | 7 -------
backend/src/backend/gen_program.h | 2 --
backend/src/backend/program.cpp | 13 ++++++++++---
3 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp
index 781152d..40ab176 100644
--- a/backend/src/backend/gen_program.cpp
+++ b/backend/src/backend/gen_program.cpp
@@ -159,10 +159,3 @@ void genSetupCallBacks(void)
gbe_program_new_from_binary = gbe::genProgramNewFromBinary;
gbe_program_new_from_llvm = gbe::genProgramNewFromLLVM;
}
-
-sem_t llvm_semaphore;
-
-void genSetupLLVMSemaphore(void)
-{
- sem_init(&llvm_semaphore, 0, 1);
-}
diff --git a/backend/src/backend/gen_program.h b/backend/src/backend/gen_program.h
index a498a5d..8d37a70 100644
--- a/backend/src/backend/gen_program.h
+++ b/backend/src/backend/gen_program.h
@@ -33,8 +33,6 @@
/*! This will make the compiler output Gen ISA code */
extern void genSetupCallBacks(void);
-extern sem_t llvm_semaphore;
-extern void genSetupLLVMSemaphore(void);
#endif /* __GBE_GEN_PROGRAM_H__ */
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index 937f95b..25be484 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -32,6 +32,8 @@
#include "ir/unit.hpp"
#include "llvm/llvm_to_gen.hpp"
#include "llvm/Config/config.h"
+#include "llvm/Support/Threading.h"
+#include "llvm/Support/ManagedStatic.h"
#include <cstring>
#include <algorithm>
#include <fstream>
@@ -557,9 +559,7 @@ namespace gbe {
// Create an action and make the compiler instance carry it out
llvm::OwningPtr<clang::CodeGenAction> Act(new clang::EmitLLVMOnlyAction());
- sem_wait(&llvm_semaphore);
auto retVal = Clang.ExecuteAction(*Act);
- sem_post(&llvm_semaphore);
if (!retVal)
return;
@@ -854,7 +854,14 @@ namespace gbe
gbe_get_image_base_index = gbe::getImageBaseIndex;
gbe_set_image_base_index = gbe::setImageBaseIndex;
genSetupCallBacks();
- genSetupLLVMSemaphore();
+ llvm::llvm_start_multithreaded();
+ }
+
+ ~CallBackInitializer() {
+ llvm::llvm_stop_multithreaded();
+#if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR > 3)
+ llvm::llvm_shutdown();
+#endif
}
};
--
1.8.3.2
More information about the Beignet
mailing list