diff options
author | I-Jui (Ray) Sung <ijsung@google.com> | 2017-03-27 15:33:22 -0700 |
---|---|---|
committer | I-Jui (Ray) Sung <ijsung@google.com> | 2017-04-10 14:44:58 -0700 |
commit | bbf0b0eac5b1aa65ded878d80a0adc83e48527c8 (patch) | |
tree | 577699797c4c1a774e31466f39559baf61675b12 | |
parent | 32c621a863f574584b104ec3bd279f90738c40bf (diff) | |
download | rs-bbf0b0eac5b1aa65ded878d80a0adc83e48527c8.tar.gz |
Fix RSoV compiler regression
c/299496/ revised the protocol between bcc and bcinfo; bcc now injects
some metadata into the module which is in turn parsed by the
bcinfo::MetadataExtractor(Module *) constructor. Since RSoV uses bcinfo
on non-bcc-processed bitcodes, those missing data caused the constructor
to fail.
This CL uses a different MetadataExtractor constructor so that all the
required information are passed to the MetadataExtractor via full bitcode.
Bug: 30964317
Bug: 36657118
Test: RSoV LIT test, RSoVTest on Angler
Change-Id: I9b423ad8d0bcab5d261e595c10d4676486ec4b3b
(cherry picked from commit 56813de7a00f872fad490b1b3fe5ab1b620c1be5)
-rw-r--r-- | rsov/compiler/Context.cpp | 9 | ||||
-rw-r--r-- | rsov/compiler/Context.h | 22 | ||||
-rw-r--r-- | rsov/compiler/RSSPIRVWriter.cpp | 5 | ||||
-rw-r--r-- | rsov/compiler/RSSPIRVWriter.h | 7 | ||||
-rw-r--r-- | rsov/compiler/rs2spirv.cpp | 14 |
5 files changed, 31 insertions, 26 deletions
diff --git a/rsov/compiler/Context.cpp b/rsov/compiler/Context.cpp index c4f5b40f..79c13b2e 100644 --- a/rsov/compiler/Context.cpp +++ b/rsov/compiler/Context.cpp @@ -27,19 +27,18 @@ Context &Context::getInstance() { return c; } -Context::Context() : mInitialized(false) { -} +Context::Context() : mInitialized(false) {} -bool Context::Initialize(llvm::Module *M) { +bool Context::Initialize(std::unique_ptr<bcinfo::MetadataExtractor> ME) { if (mInitialized) { return true; } - mMetadata.reset(new bcinfo::MetadataExtractor(M)); + mMetadata = std::move(ME); if (!mMetadata->extract()) { llvm::errs() << "cannot extract metadata\n"; - return false;; + return false; } const char **varNames = mMetadata->getExportVarNameList(); diff --git a/rsov/compiler/Context.h b/rsov/compiler/Context.h index 99f232b9..cc86accd 100644 --- a/rsov/compiler/Context.h +++ b/rsov/compiler/Context.h @@ -23,19 +23,19 @@ #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" -#include <stdint.h> #include <limits> +#include <stdint.h> #include <vector> // Declare a friend relationship in a class with a test. Used rather that // FRIEND_TEST to avoid globally importing gtest/gtest.h into the main // RSoV header files. #ifdef __HOST__ -#define RSOV_FRIEND_TEST(test_set_name, individual_test)\ -friend class test_set_name##_##individual_test##_Test +#define RSOV_FRIEND_TEST(test_set_name, individual_test) \ + friend class test_set_name##_##individual_test##_Test #else #define RSOV_FRIEND_TEST(test_set_name, individual_test) -#endif // __HOST__ +#endif // __HOST__ namespace bcinfo { class MetadataExtractor; @@ -60,12 +60,10 @@ public: // Initialize the internal data struture such as the slot number lookup table, // etc. - bool Initialize(llvm::Module *M); + bool Initialize(std::unique_ptr<bcinfo::MetadataExtractor> ME); // Returns the total number of exported variables - uint32_t getNumExportVar() const { - return mExportVarIndices.size(); - } + uint32_t getNumExportVar() const { return mExportVarIndices.size(); } // Adds the mapping from the slot number of an exported variable to the index // of its field in the global buffer @@ -91,18 +89,14 @@ public: } // Returns the total number of foreach kernels - uint32_t getNumForEachKernel() const { - return mForEachNameToSlot.size(); - } + uint32_t getNumForEachKernel() const { return mForEachNameToSlot.size(); } // Checks if a name refers to a foreach kernel function bool isForEachKernel(llvm::StringRef name) const { return mForEachNameToSlot.count(name) != 0; } - const bcinfo::MetadataExtractor &getMetadata() const { - return *mMetadata; - } + const bcinfo::MetadataExtractor &getMetadata() const { return *mMetadata; } llvm::SmallVectorImpl<RSAllocationInfo> &getGlobalAllocs() { return mGlobalAllocs; diff --git a/rsov/compiler/RSSPIRVWriter.cpp b/rsov/compiler/RSSPIRVWriter.cpp index 4f6da2cd..22e739dd 100644 --- a/rsov/compiler/RSSPIRVWriter.cpp +++ b/rsov/compiler/RSSPIRVWriter.cpp @@ -100,12 +100,13 @@ void addPassesForRS2SPIRV(llvm::legacy::PassManager &PassMgr) { PassMgr.add(createSPIRVLowerBool()); } -bool WriteSPIRV(llvm::Module *M, llvm::raw_ostream &OS, std::string &ErrMsg) { +bool WriteSPIRV(llvm::Module *M, std::unique_ptr<bcinfo::MetadataExtractor> ME, + llvm::raw_ostream &OS, std::string &ErrMsg) { HandleTargetTriple(*M); Context &Ctxt = Context::getInstance(); - if (!Ctxt.Initialize(M)) { + if (!Ctxt.Initialize(std::move(ME))) { ErrMsg = "Failed to intialize rs2spirv"; return false; } diff --git a/rsov/compiler/RSSPIRVWriter.h b/rsov/compiler/RSSPIRVWriter.h index 91fe4d06..4b0d80c5 100644 --- a/rsov/compiler/RSSPIRVWriter.h +++ b/rsov/compiler/RSSPIRVWriter.h @@ -24,9 +24,14 @@ class Module; class raw_ostream; } // namespace llvm +namespace bcinfo { +class MetadataExtractor; +} // namespace bcinfo + namespace rs2spirv { -bool WriteSPIRV(llvm::Module *M, llvm::raw_ostream &OS, std::string &ErrMsg); +bool WriteSPIRV(llvm::Module *M, std::unique_ptr<bcinfo::MetadataExtractor> ME, + llvm::raw_ostream &OS, std::string &ErrMsg); } // namespace rs2spirv diff --git a/rsov/compiler/rs2spirv.cpp b/rsov/compiler/rs2spirv.cpp index 0c1ff298..6701d27b 100644 --- a/rsov/compiler/rs2spirv.cpp +++ b/rsov/compiler/rs2spirv.cpp @@ -14,6 +14,10 @@ * limitations under the License. */ +#include "RSSPIRVWriter.h" +#include "bcinfo/MetadataExtractor.h" +#include "spirit/file_utils.h" + #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" @@ -26,8 +30,6 @@ #include "llvm/Support/ToolOutputFile.h" #include "llvm/Support/raw_ostream.h" -#include "RSSPIRVWriter.h" - #define DEBUG_TYPE "rs2spirv" namespace kExt { @@ -59,7 +61,6 @@ static int convertLLVMToSPIRV() { errs() << "Fails to open input file: " << Err; return -1; } - ErrorOr<std::unique_ptr<Module>> MOrErr = getStreamedBitcodeModule(InputFile, std::move(DS), Context); @@ -85,7 +86,12 @@ static int convertLLVMToSPIRV() { llvm::StringRef outFile(OutputFile); std::error_code EC; llvm::raw_fd_ostream OFS(outFile, EC, llvm::sys::fs::F_None); - if (!rs2spirv::WriteSPIRV(M.get(), OFS, Err)) { + + std::vector<char> bitcode = android::spirit::readFile<char>(InputFile); + std::unique_ptr<bcinfo::MetadataExtractor> ME( + new bcinfo::MetadataExtractor(bitcode.data(), bitcode.size())); + + if (!rs2spirv::WriteSPIRV(M.get(), std::move(ME), OFS, Err)) { errs() << "compiler error: " << Err << '\n'; return -1; } |