aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Luc Brouillet <jeanluc@google.com>2017-02-21 02:29:48 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-02-21 02:29:49 +0000
commita6712f80778cb292e6ee361a07ca08f27feb01a8 (patch)
treea5002f34c5984705ec5ad66f3397e3f696f5327c
parenta9dd44f7e6c67a62fa9c0a91ef6248a8ce8111a1 (diff)
parent8486498c5f6083b8ab0f7aebb1944eaed33bd290 (diff)
downloadlibbcc-a6712f80778cb292e6ee361a07ca08f27feb01a8.tar.gz
Merge changes Ic4218b49,Ib91e16d8
* changes: Remove unused File code in libbcc. Merge RSScript.cpp and Script.cpp
-rw-r--r--include/bcc/RSCompilerDriver.h8
-rw-r--r--include/bcc/RSScript.h132
-rw-r--r--include/bcc/Script.h84
-rw-r--r--lib/Android.bp1
-rw-r--r--lib/Compiler.cpp43
-rw-r--r--lib/File.h72
-rw-r--r--lib/FileBase.cpp71
-rw-r--r--lib/FileBase.h14
-rw-r--r--lib/FileMutex.h11
-rw-r--r--lib/InputFile.cpp2
-rw-r--r--lib/InputFile.h4
-rw-r--r--lib/OutputFile.cpp2
-rw-r--r--lib/OutputFile.h4
-rw-r--r--lib/RSCompilerDriver.cpp29
-rw-r--r--lib/RSScript.cpp77
-rw-r--r--lib/Script.cpp40
-rw-r--r--tools/bcc/Main.cpp3
-rw-r--r--tools/bcc_compat/Main.cpp10
18 files changed, 151 insertions, 456 deletions
diff --git a/include/bcc/RSCompilerDriver.h b/include/bcc/RSCompilerDriver.h
index 6023cc6..c5b4fe7 100644
--- a/include/bcc/RSCompilerDriver.h
+++ b/include/bcc/RSCompilerDriver.h
@@ -18,7 +18,7 @@
#define BCC_RS_COMPILER_DRIVER_H
#include "bcc/Compiler.h"
-#include "bcc/RSScript.h"
+#include "bcc/Script.h"
#include "bcinfo/MetadataExtractor.h"
@@ -66,11 +66,11 @@ private:
// Setup the compiler config for the given script. Return true if mConfig has
// been changed and false if it remains unchanged.
- bool setupConfig(const RSScript &pScript);
+ bool setupConfig(const Script &pScript);
// Compiles the provided bitcode, placing the binary at pOutputPath.
// - If pDumpIR is true, a ".ll" file will also be created.
- Compiler::ErrorCode compileScript(RSScript& pScript, const char* pScriptName,
+ Compiler::ErrorCode compileScript(Script& pScript, const char* pScriptName,
const char* pOutputPath,
const char* pRuntimePath,
const char* pBuildChecksum,
@@ -157,7 +157,7 @@ public:
const std::list<std::string>& invokeBatchNames);
// Returns true if script is successfully compiled.
- bool buildForCompatLib(RSScript &pScript, const char *pOut,
+ bool buildForCompatLib(Script &pScript, const char *pOut,
const char *pBuildChecksum, const char *pRuntimePath,
bool pDumpIR);
};
diff --git a/include/bcc/RSScript.h b/include/bcc/RSScript.h
deleted file mode 100644
index 21bfab8..0000000
--- a/include/bcc/RSScript.h
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright 2012, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef BCC_RS_SCRIPT_H
-#define BCC_RS_SCRIPT_H
-
-#include "bcc/Script.h"
-
-namespace llvm {
- class Module;
-}
-
-namespace bcc {
-
-class RSScript;
-class Source;
-class CompilerConfig;
-
-typedef llvm::Module* (*RSLinkRuntimeCallback) (bcc::RSScript *, llvm::Module *, llvm::Module *);
-
-
-class RSScript : public Script {
-public:
- // This is one-one mapping with the llvm::CodeGenOpt::Level in
- // llvm/Support/CodeGen.h. Therefore, value of this type can safely cast
- // to llvm::CodeGenOpt::Level. This makes RSScript LLVM-free.
- enum OptimizationLevel {
- kOptLvl0, // -O0
- kOptLvl1, // -O1
- kOptLvl2, // -O2, -Os
- kOptLvl3 // -O3
- };
-
-private:
- unsigned mCompilerVersion;
-
- OptimizationLevel mOptimizationLevel;
-
- RSLinkRuntimeCallback mLinkRuntimeCallback;
-
- bool mEmbedInfo;
-
- // Specifies whether we should embed global variable information in the
- // code via special RS variables that can be examined later by the driver.
- bool mEmbedGlobalInfo;
-
- // Specifies whether we should skip constant (immutable) global variables
- // when potentially embedding information about globals.
- bool mEmbedGlobalInfoSkipConstant;
-
-private:
- // This will be invoked when the containing source has been reset.
- virtual bool doReset();
-
-public:
- static bool LinkRuntime(RSScript &pScript, const char *rt_path = nullptr);
-
- explicit RSScript(Source &pSource);
-
- // Passing in the CompilerConfig allows the optimization level to
- // be derived rather than defaulted to aggressive (-O3)
- RSScript(Source &pSource, const CompilerConfig * pCompilerConfig);
-
- virtual ~RSScript() { }
-
- void setCompilerVersion(unsigned pCompilerVersion) {
- mCompilerVersion = pCompilerVersion;
- }
-
- unsigned getCompilerVersion() const {
- return mCompilerVersion;
- }
-
- void setOptimizationLevel(OptimizationLevel pOptimizationLevel) {
- mOptimizationLevel = pOptimizationLevel;
- }
-
- OptimizationLevel getOptimizationLevel() const {
- return mOptimizationLevel;
- }
-
- void setLinkRuntimeCallback(RSLinkRuntimeCallback fn){
- mLinkRuntimeCallback = fn;
- }
-
- void setEmbedInfo(bool pEnable) {
- mEmbedInfo = pEnable;
- }
-
- bool getEmbedInfo() const {
- return mEmbedInfo;
- }
-
- // Set to true if we should embed global variable information in the code.
- void setEmbedGlobalInfo(bool pEnable) {
- mEmbedGlobalInfo = pEnable;
- }
-
- // Returns true if we should embed global variable information in the code.
- bool getEmbedGlobalInfo() const {
- return mEmbedGlobalInfo;
- }
-
- // Set to true if we should skip constant (immutable) global variables when
- // potentially embedding information about globals.
- void setEmbedGlobalInfoSkipConstant(bool pEnable) {
- mEmbedGlobalInfoSkipConstant = pEnable;
- }
-
- // Returns true if we should skip constant (immutable) global variables when
- // potentially embedding information about globals.
- bool getEmbedGlobalInfoSkipConstant() const {
- return mEmbedGlobalInfoSkipConstant;
- }
-};
-
-} // end namespace bcc
-
-#endif // BCC_RS_SCRIPT_H
diff --git a/include/bcc/Script.h b/include/bcc/Script.h
index 660cbee..62c7369 100644
--- a/include/bcc/Script.h
+++ b/include/bcc/Script.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2012, The Android Open Source Project
+ * Copyright 2012, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,32 +17,82 @@
#ifndef BCC_SCRIPT_H
#define BCC_SCRIPT_H
+#include <llvm/Support/CodeGen.h>
+
+namespace llvm {
+class Module;
+}
+
namespace bcc {
+class Script;
class Source;
+class CompilerConfig;
+
+typedef llvm::Module *(*RSLinkRuntimeCallback)(bcc::Script *, llvm::Module *,
+ llvm::Module *);
class Script {
private:
// This is the source associated with this object and is going to be
// compiled.
+ // TODO(jeanluc) Verify that the lifetime is managed correctly.
Source *mSource;
-protected:
- // This hook will be invoked after the script object is successfully reset.
- virtual bool doReset()
- { return true; }
+ llvm::CodeGenOpt::Level mOptimizationLevel;
+
+ RSLinkRuntimeCallback mLinkRuntimeCallback;
+
+ bool mEmbedInfo;
+
+ // Specifies whether we should embed global variable information in the
+ // code via special RS variables that can be examined later by the driver.
+ bool mEmbedGlobalInfo;
+
+ // Specifies whether we should skip constant (immutable) global variables
+ // when potentially embedding information about globals.
+ bool mEmbedGlobalInfoSkipConstant;
public:
- explicit Script(Source &pSource) : mSource(&pSource) { }
+ explicit Script(Source *pSource);
+
+ ~Script() {}
+
+ bool LinkRuntime(const char *rt_path);
+
+ void setOptimizationLevel(llvm::CodeGenOpt::Level pOptimizationLevel) {
+ mOptimizationLevel = pOptimizationLevel;
+ }
+
+ llvm::CodeGenOpt::Level getOptimizationLevel() const {
+ return mOptimizationLevel;
+ }
+
+ void setLinkRuntimeCallback(RSLinkRuntimeCallback fn) {
+ mLinkRuntimeCallback = fn;
+ }
+
+ void setEmbedInfo(bool pEnable) { mEmbedInfo = pEnable; }
+
+ bool getEmbedInfo() const { return mEmbedInfo; }
+
+ // Set to true if we should embed global variable information in the code.
+ void setEmbedGlobalInfo(bool pEnable) { mEmbedGlobalInfo = pEnable; }
+
+ // Returns true if we should embed global variable information in the code.
+ bool getEmbedGlobalInfo() const { return mEmbedGlobalInfo; }
- virtual ~Script() { }
+ // Set to true if we should skip constant (immutable) global variables when
+ // potentially embedding information about globals.
+ void setEmbedGlobalInfoSkipConstant(bool pEnable) {
+ mEmbedGlobalInfoSkipConstant = pEnable;
+ }
- // Reset this object with the new source supplied. Return false if this
- // object remains unchanged after the call (e.g., the supplied source is
- // the same with the one contain in this object.) If pPreserveCurrent is
- // false, the current containing source will be destroyed after successfully
- // reset.
- bool reset(Source &pSource, bool pPreserveCurrent = false);
+ // Returns true if we should skip constant (immutable) global variables when
+ // potentially embedding information about globals.
+ inline bool getEmbedGlobalInfoSkipConstant() const {
+ return mEmbedGlobalInfoSkipConstant;
+ }
// Merge (or link) another source into the current source associated with
// this Script object. Return false on error.
@@ -50,12 +100,10 @@ public:
// This is equivalent to the call to Script::merge(...) on mSource.
bool mergeSource(Source &pSource);
- inline Source &getSource()
- { return *mSource; }
- inline const Source &getSource() const
- { return *mSource; }
+ inline Source &getSource() { return *mSource; }
+ inline const Source &getSource() const { return *mSource; }
};
} // end namespace bcc
-#endif // BCC_SCRIPT_H
+#endif // BCC_SCRIPT_H
diff --git a/lib/Android.bp b/lib/Android.bp
index 4212b9b..efbf687 100644
--- a/lib/Android.bp
+++ b/lib/Android.bp
@@ -36,7 +36,6 @@ cc_library_shared {
"RSIsThreadablePass.cpp",
"RSKernelExpand.cpp",
"RSScreenFunctionsPass.cpp",
- "RSScript.cpp",
"RSScriptGroupFusion.cpp",
"RSStubsWhiteList.cpp",
"RSX86CallConvPass.cpp",
diff --git a/lib/Compiler.cpp b/lib/Compiler.cpp
index 1a3662e..dd20e98 100644
--- a/lib/Compiler.cpp
+++ b/lib/Compiler.cpp
@@ -24,7 +24,6 @@
#include "bcc/Compiler.h"
#include "bcc/CompilerConfig.h"
#include "bcc/Config.h"
-#include "bcc/RSScript.h"
#include "bcc/Script.h"
#include "bcc/Source.h"
#include "bcinfo/MetadataExtractor.h"
@@ -150,7 +149,7 @@ Compiler::~Compiler() {
// This function has complete responsibility for creating and executing the
// exact list of compiler passes.
-enum Compiler::ErrorCode Compiler::runPasses(Script &pScript,
+enum Compiler::ErrorCode Compiler::runPasses(Script &script,
llvm::raw_pwrite_stream &pResult) {
// Pass manager for link-time optimization
llvm::legacy::PassManager transformPasses;
@@ -164,13 +163,13 @@ enum Compiler::ErrorCode Compiler::runPasses(Script &pScript,
// Add some initial custom passes.
addInvokeHelperPass(transformPasses);
addExpandKernelPass(transformPasses);
- addDebugInfoPass(pScript, transformPasses);
+ addDebugInfoPass(script, transformPasses);
addInvariantPass(transformPasses);
if (mTarget->getOptLevel() != llvm::CodeGenOpt::None) {
- if (!addInternalizeSymbolsPass(pScript, transformPasses))
+ if (!addInternalizeSymbolsPass(script, transformPasses))
return kErrCustomPasses;
}
- addGlobalInfoPass(pScript, transformPasses);
+ addGlobalInfoPass(script, transformPasses);
if (mTarget->getOptLevel() == llvm::CodeGenOpt::None) {
transformPasses.add(llvm::createGlobalOptimizerPass());
@@ -207,13 +206,11 @@ enum Compiler::ErrorCode Compiler::runPasses(Script &pScript,
// RSEmbedInfoPass needs to come after we have scanned for non-threadable
// functions.
- // Script passed to RSCompiler must be a RSScript.
- RSScript &script = static_cast<RSScript &>(pScript);
if (script.getEmbedInfo())
transformPasses.add(createRSEmbedInfoPass());
// Execute the passes.
- transformPasses.run(pScript.getSource().getModule());
+ transformPasses.run(script.getSource().getModule());
// Run backend separately to avoid interference between debug metadata
// generation and backend initialization.
@@ -226,15 +223,15 @@ enum Compiler::ErrorCode Compiler::runPasses(Script &pScript,
}
// Execute the passes.
- codeGenPasses.run(pScript.getSource().getModule());
+ codeGenPasses.run(script.getSource().getModule());
return kSuccess;
}
-enum Compiler::ErrorCode Compiler::compile(Script &pScript,
+enum Compiler::ErrorCode Compiler::compile(Script &script,
llvm::raw_pwrite_stream &pResult,
llvm::raw_ostream *IRStream) {
- llvm::Module &module = pScript.getSource().getModule();
+ llvm::Module &module = script.getSource().getModule();
enum ErrorCode err;
if (mTarget == nullptr) {
@@ -282,7 +279,7 @@ enum Compiler::ErrorCode Compiler::compile(Script &pScript,
}
}
- if ((err = runPasses(pScript, pResult)) != kSuccess) {
+ if ((err = runPasses(script, pResult)) != kSuccess) {
return err;
}
@@ -293,7 +290,7 @@ enum Compiler::ErrorCode Compiler::compile(Script &pScript,
return kSuccess;
}
-enum Compiler::ErrorCode Compiler::compile(Script &pScript,
+enum Compiler::ErrorCode Compiler::compile(Script &script,
OutputFile &pResult,
llvm::raw_ostream *IRStream) {
// Check the state of the specified output file.
@@ -308,7 +305,7 @@ enum Compiler::ErrorCode Compiler::compile(Script &pScript,
}
// Delegate the request.
- enum Compiler::ErrorCode err = compile(pScript, *out, IRStream);
+ enum Compiler::ErrorCode err = compile(script, *out, IRStream);
// Close the output before return.
delete out;
@@ -316,10 +313,9 @@ enum Compiler::ErrorCode Compiler::compile(Script &pScript,
return err;
}
-bool Compiler::addInternalizeSymbolsPass(Script &pScript, llvm::legacy::PassManager &pPM) {
+bool Compiler::addInternalizeSymbolsPass(Script &script, llvm::legacy::PassManager &pPM) {
// Add a pass to internalize the symbols that don't need to have global
// visibility.
- RSScript &script = static_cast<RSScript &>(pScript);
llvm::Module &module = script.getSource().getModule();
bcinfo::MetadataExtractor me(&module);
if (!me.extract()) {
@@ -414,8 +410,8 @@ void Compiler::addInvokeHelperPass(llvm::legacy::PassManager &pPM) {
}
}
-void Compiler::addDebugInfoPass(Script &pScript, llvm::legacy::PassManager &pPM) {
- if (pScript.getSource().getDebugInfoEnabled())
+void Compiler::addDebugInfoPass(Script &script, llvm::legacy::PassManager &pPM) {
+ if (script.getSource().getDebugInfoEnabled())
pPM.add(createRSAddDebugInfoPass());
}
@@ -425,9 +421,8 @@ void Compiler::addExpandKernelPass(llvm::legacy::PassManager &pPM) {
pPM.add(createRSKernelExpandPass(pEnableStepOpt));
}
-void Compiler::addGlobalInfoPass(Script &pScript, llvm::legacy::PassManager &pPM) {
+void Compiler::addGlobalInfoPass(Script &script, llvm::legacy::PassManager &pPM) {
// Add additional information about RS global variables inside the Module.
- RSScript &script = static_cast<RSScript &>(pScript);
if (script.getEmbedGlobalInfo()) {
pPM.add(createRSGlobalInfoPass(script.getEmbedGlobalInfoSkipConstant()));
}
@@ -439,8 +434,8 @@ void Compiler::addInvariantPass(llvm::legacy::PassManager &pPM) {
pPM.add(createRSInvariantPass());
}
-enum Compiler::ErrorCode Compiler::screenGlobalFunctions(Script &pScript) {
- llvm::Module &module = pScript.getSource().getModule();
+enum Compiler::ErrorCode Compiler::screenGlobalFunctions(Script &script) {
+ llvm::Module &module = script.getSource().getModule();
// Materialize the bitcode module in case this is a lazy-load module. Do not
// clear the materializer by calling materializeAllPermanently since the
@@ -463,10 +458,10 @@ enum Compiler::ErrorCode Compiler::screenGlobalFunctions(Script &pScript) {
}
-void Compiler::translateGEPs(Script &pScript) {
+void Compiler::translateGEPs(Script &script) {
llvm::legacy::PassManager pPM;
pPM.add(createRSX86TranslateGEPPass());
// Materialization done in screenGlobalFunctions above.
- pPM.run(pScript.getSource().getModule());
+ pPM.run(script.getSource().getModule());
}
diff --git a/lib/File.h b/lib/File.h
deleted file mode 100644
index 38cd020..0000000
--- a/lib/File.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2012, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef BCC_SUPPORT_FILE_H
-#define BCC_SUPPORT_FILE_H
-
-#include "FileBase.h"
-
-namespace bcc {
-
-template<enum FileBase::OpenModeEnum OpenMode>
-struct FileAttribute {
- // The flags to the 2nd argument in ::open().
- enum { kOpenFlags };
-
- // Default value of LockMode.
- enum { kDefaultLockMode };
-};
-
-// FileAttribute for accessing read-only file
-template<>
-struct FileAttribute<FileBase::kReadMode> {
- enum { kOpenFlags = O_RDONLY };
- enum { kDefaultLockMode = FileBase::kReadLock };
-};
-
-// FileAttribute for accessing writable file
-template<>
-struct FileAttribute<FileBase::kWriteMode> {
- enum { kOpenFlags = O_RDWR | O_CREAT };
- enum { kDefaultLockMode = FileBase::kWriteLock };
-};
-
-template<enum FileBase::OpenModeEnum OpenMode>
-class File : public FileBase {
-public:
- File(const std::string &pFilename, unsigned pFlags)
- : FileBase(pFilename, FileAttribute<OpenMode>::kOpenFlags, pFlags) { }
-
- inline bool lock(enum LockModeEnum pMode = static_cast<enum LockModeEnum>(
- FileAttribute<OpenMode>::kDefaultLockMode),
- bool pNonblocking = true,
- unsigned pMaxRetry = FileBase::kDefaultMaxRetryLock,
- useconds_t pRetryInterval =
- FileBase::kDefaultRetryLockInterval) {
- return FileBase::lock(pMode, pNonblocking, pMaxRetry, pRetryInterval);
- }
-
- inline android::FileMap *createMap(off_t pOffset, size_t pLength,
- bool pIsReadOnly =
- (OpenMode == FileBase::kReadMode)) {
- return FileBase::createMap(pOffset, pLength, pIsReadOnly);
- }
-};
-
-
-} // end namespace bcc
-
-#endif // BCC_SUPPORT_FILE_H
diff --git a/lib/FileBase.cpp b/lib/FileBase.cpp
index 5bace51..8e91e1c 100644
--- a/lib/FileBase.cpp
+++ b/lib/FileBase.cpp
@@ -221,77 +221,6 @@ void FileBase::unlock() {
return;
}
-android::FileMap *FileBase::createMap(off_t pOffset, size_t pLength,
- bool pIsReadOnly) {
- if (mFD < 0 || hasError()) {
- return nullptr;
- }
-
- android::FileMap *map = new (std::nothrow) android::FileMap();
- if (map == nullptr) {
- mError = make_error_code(std::errc::not_enough_memory);
- return nullptr;
- }
-
- if (!map->create(nullptr, mFD, pOffset, pLength, pIsReadOnly)) {
- detectError();
- delete map;
- return nullptr;
- }
-
- return map;
-}
-
-size_t FileBase::getSize() {
- if (mFD < 0 || hasError()) {
- return static_cast<size_t>(-1);
- }
-
- struct stat file_stat;
- do {
- if (::fstat(mFD, &file_stat) == 0) {
- break;
- } else if (errno != EINTR) {
- detectError();
- return static_cast<size_t>(-1);
- }
- } while (true);
-
- return file_stat.st_size;
-}
-
-off_t FileBase::seek(off_t pOffset) {
- if ((mFD < 0) || hasError()) {
- return static_cast<off_t>(-1);
- }
-
- do {
- off_t result = ::lseek(mFD, pOffset, SEEK_SET);
- if (result == pOffset) {
- return result;
- }
- } while (errno == EINTR);
-
- detectError();
- return static_cast<off_t>(-1);
-}
-
-off_t FileBase::tell() {
- if ((mFD < 0) || hasError()) {
- return static_cast<off_t>(-1);
- }
-
- do {
- off_t result = ::lseek(mFD, 0, SEEK_CUR);
- if (result != static_cast<off_t>(-1)) {
- return result;
- }
- } while (errno == EINTR);
-
- detectError();
- return static_cast<off_t>(-1);
-}
-
void FileBase::close() {
if (mShouldUnlock) {
unlock();
diff --git a/lib/FileBase.h b/lib/FileBase.h
index cf9c998..efadac0 100644
--- a/lib/FileBase.h
+++ b/lib/FileBase.h
@@ -120,17 +120,6 @@ public:
void unlock();
- // Map the file content to the memory.
- //
- // One who gets non-null android::FileMap returned from this API is responsible
- // for destroying it after the use.
- android::FileMap *createMap(off_t pOffset, size_t pLength, bool pIsReadOnly);
-
- size_t getSize();
-
- off_t seek(off_t pOffset);
- off_t tell();
-
inline bool hasError() const
{ return (bool) mError; }
@@ -142,9 +131,6 @@ public:
inline std::string getErrorMessage() const
{ return mError.message(); }
- inline const std::string &getName() const
- { return mName; }
-
void close();
virtual ~FileBase();
diff --git a/lib/FileMutex.h b/lib/FileMutex.h
index d5e4582..fdea8c0 100644
--- a/lib/FileMutex.h
+++ b/lib/FileMutex.h
@@ -23,18 +23,17 @@
namespace bcc {
-template<enum FileBase::LockModeEnum LockMode>
+// This class is used to acquire write locks.
+// TODO(jeanluc) More documentation.
class FileMutex : public FileBase {
public:
explicit FileMutex(const std::string &pFileToLock)
: FileBase(pFileToLock + ".lock", O_RDONLY | O_CREAT, kDeleteOnClose) { }
// Provide a lock() interface filled with default configuration.
- inline bool lock(bool pNonblocking = true,
- unsigned pMaxRetry = FileBase::kDefaultMaxRetryLock,
- useconds_t pRetryInterval =
- FileBase::kDefaultRetryLockInterval) {
- return FileBase::lock(LockMode, pNonblocking, pMaxRetry, pRetryInterval);
+ inline bool lockMutex() {
+ return FileBase::lock(FileBase::kWriteLock, true, FileBase::kDefaultMaxRetryLock,
+ FileBase::kDefaultRetryLockInterval);
}
};
diff --git a/lib/InputFile.cpp b/lib/InputFile.cpp
index e5c59d0..86cd2dd 100644
--- a/lib/InputFile.cpp
+++ b/lib/InputFile.cpp
@@ -21,7 +21,7 @@
using namespace bcc;
InputFile::InputFile(const std::string &pFilename, unsigned pFlags)
- : super(pFilename, pFlags) { }
+ : FileBase(pFilename, O_RDONLY, pFlags) { }
ssize_t InputFile::read(void *pBuf, size_t count) {
if ((mFD < 0) || hasError()) {
diff --git a/lib/InputFile.h b/lib/InputFile.h
index 01c7542..5391e6f 100644
--- a/lib/InputFile.h
+++ b/lib/InputFile.h
@@ -17,13 +17,11 @@
#ifndef BCC_SUPPORT_INPUT_FILE_H
#define BCC_SUPPORT_INPUT_FILE_H
-#include "File.h"
#include "FileBase.h"
namespace bcc {
-class InputFile : public File<FileBase::kReadMode> {
- typedef File<FileBase::kReadMode> super;
+class InputFile : public FileBase {
public:
explicit InputFile(const std::string &pFilename, unsigned pFlags = 0);
diff --git a/lib/OutputFile.cpp b/lib/OutputFile.cpp
index e58d27e..78a8d61 100644
--- a/lib/OutputFile.cpp
+++ b/lib/OutputFile.cpp
@@ -24,7 +24,7 @@
using namespace bcc;
OutputFile::OutputFile(const std::string &pFilename, unsigned pFlags)
- : super(pFilename, pFlags) { }
+ : FileBase(pFilename, O_RDWR | O_CREAT, pFlags) { }
ssize_t OutputFile::write(const void *pBuf, size_t count) {
if ((mFD < 0) || hasError()) {
diff --git a/lib/OutputFile.h b/lib/OutputFile.h
index 716a627..af3d16f 100644
--- a/lib/OutputFile.h
+++ b/lib/OutputFile.h
@@ -17,7 +17,6 @@
#ifndef BCC_SUPPORT_OUTPUT_FILE_H
#define BCC_SUPPORT_OUTPUT_FILE_H
-#include "File.h"
#include "FileBase.h"
namespace llvm {
@@ -26,8 +25,7 @@ namespace llvm {
namespace bcc {
-class OutputFile : public File<FileBase::kWriteMode> {
- typedef File<FileBase::kWriteMode> super;
+class OutputFile : public FileBase {
public:
explicit OutputFile(const std::string &pFilename, unsigned pFlags = 0);
diff --git a/lib/RSCompilerDriver.cpp b/lib/RSCompilerDriver.cpp
index 6c53ebe..ba4c666 100644
--- a/lib/RSCompilerDriver.cpp
+++ b/lib/RSCompilerDriver.cpp
@@ -28,7 +28,7 @@
#include "bcc/CompilerConfig.h"
#include "bcc/Config.h"
#include "bcc/Initialization.h"
-#include "bcc/RSScript.h"
+#include "bcc/Script.h"
#include "bcc/Source.h"
#include "bcinfo/BitcodeWrapper.h"
#include "bcinfo/MetadataExtractor.h"
@@ -68,11 +68,10 @@ RSCompilerDriver::~RSCompilerDriver() {
extern llvm::cl::opt<bool> EnableGlobalMerge;
#endif
-bool RSCompilerDriver::setupConfig(const RSScript &pScript) {
+bool RSCompilerDriver::setupConfig(const Script &pScript) {
bool changed = false;
- const llvm::CodeGenOpt::Level script_opt_level =
- static_cast<llvm::CodeGenOpt::Level>(pScript.getOptimizationLevel());
+ const llvm::CodeGenOpt::Level script_opt_level = pScript.getOptimizationLevel();
#if defined(PROVIDE_ARM_CODEGEN)
EnableGlobalMerge = mEnableGlobalMerge;
@@ -112,7 +111,7 @@ bool RSCompilerDriver::setupConfig(const RSScript &pScript) {
return changed;
}
-Compiler::ErrorCode RSCompilerDriver::compileScript(RSScript& pScript, const char* pScriptName,
+Compiler::ErrorCode RSCompilerDriver::compileScript(Script& pScript, const char* pScriptName,
const char* pOutputPath,
const char* pRuntimePath,
const char* pBuildChecksum,
@@ -144,7 +143,7 @@ Compiler::ErrorCode RSCompilerDriver::compileScript(RSScript& pScript, const cha
//===--------------------------------------------------------------------===//
// Link RS script with Renderscript runtime.
//===--------------------------------------------------------------------===//
- if (!RSScript::LinkRuntime(pScript, pRuntimePath)) {
+ if (!pScript.LinkRuntime(pRuntimePath)) {
ALOGE("Failed to link script '%s' with Renderscript runtime %s!",
pScriptName, pRuntimePath);
return Compiler::kErrInvalidSource;
@@ -157,9 +156,9 @@ Compiler::ErrorCode RSCompilerDriver::compileScript(RSScript& pScript, const cha
//===------------------------------------------------------------------===//
// Acquire the write lock for writing output object file.
//===------------------------------------------------------------------===//
- FileMutex<FileBase::kWriteLock> write_output_mutex(pOutputPath);
+ FileMutex write_output_mutex(pOutputPath);
- if (write_output_mutex.hasError() || !write_output_mutex.lock()) {
+ if (write_output_mutex.hasError() || !write_output_mutex.lockMutex()) {
ALOGE("Unable to acquire the lock for writing %s! (%s)",
pOutputPath, write_output_mutex.getErrorMessage().c_str());
return Compiler::kErrInvalidSource;
@@ -265,7 +264,8 @@ bool RSCompilerDriver::build(BCCContext &pContext,
return false;
}
- RSScript script(*source, getConfig());
+ Script script(source);
+ script.setOptimizationLevel(getConfig()->getOptimizationLevel());
if (pLinkRuntimeCallback) {
setLinkRuntimeCallback(pLinkRuntimeCallback);
}
@@ -277,8 +277,7 @@ bool RSCompilerDriver::build(BCCContext &pContext,
// Read information from bitcode wrapper.
bcinfo::BitcodeWrapper wrapper(pBitcode, pBitcodeSize);
- script.setCompilerVersion(wrapper.getCompilerVersion());
- script.setOptimizationLevel(static_cast<RSScript::OptimizationLevel>(
+ script.setOptimizationLevel(static_cast<llvm::CodeGenOpt::Level>(
wrapper.getOptimizationLevel()));
// Assertion-enabled builds can't compile legacy bitcode (due to the use of
@@ -385,11 +384,13 @@ bool RSCompilerDriver::buildScriptGroup(
const std::unique_ptr<Source> source(
Source::CreateFromModule(Context, pOutputFilepath, module, true));
- RSScript script(*source);
+ Script script(source.get());
// Embed the info string directly in the ELF
script.setEmbedInfo(true);
- script.setOptimizationLevel(RSScript::kOptLvl3);
+ // TODO jeanluc Should we override the config's optimization?
+ // i.e., why not script.setOptimizationLevel(getConfig()->getOptimizationLevel)?
+ script.setOptimizationLevel(llvm::CodeGenOpt::Level::Aggressive);
script.setEmbedGlobalInfo(mEmbedGlobalInfo);
script.setEmbedGlobalInfoSkipConstant(mEmbedGlobalInfoSkipConstant);
@@ -412,7 +413,7 @@ bool RSCompilerDriver::buildScriptGroup(
return true;
}
-bool RSCompilerDriver::buildForCompatLib(RSScript &pScript, const char *pOut,
+bool RSCompilerDriver::buildForCompatLib(Script &pScript, const char *pOut,
const char *pBuildChecksum,
const char *pRuntimePath,
bool pDumpIR) {
diff --git a/lib/RSScript.cpp b/lib/RSScript.cpp
deleted file mode 100644
index b7b843c..0000000
--- a/lib/RSScript.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright 2012, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "bcc/RSScript.h"
-
-#include "Assert.h"
-#include "Log.h"
-
-#include "bcc/CompilerConfig.h"
-#include "bcc/Source.h"
-
-using namespace bcc;
-
-bool RSScript::LinkRuntime(RSScript &pScript, const char *core_lib) {
- bccAssert(core_lib != nullptr);
-
- // Using the same context with the source in pScript.
- BCCContext &context = pScript.getSource().getContext();
-
- Source *libclcore_source = Source::CreateFromFile(context, core_lib);
- if (libclcore_source == nullptr) {
- ALOGE("Failed to load Renderscript library '%s' to link!", core_lib);
- return false;
- }
-
- if (pScript.mLinkRuntimeCallback != nullptr) {
- pScript.mLinkRuntimeCallback(&pScript,
- &pScript.getSource().getModule(), &libclcore_source->getModule());
- }
-
- if (!pScript.getSource().merge(*libclcore_source)) {
- ALOGE("Failed to link Renderscript library '%s'!", core_lib);
- delete libclcore_source;
- return false;
- }
-
- return true;
-}
-
-RSScript::RSScript(Source &pSource)
- : Script(pSource), mCompilerVersion(0),
- mOptimizationLevel(kOptLvl3), mLinkRuntimeCallback(nullptr),
- mEmbedInfo(false), mEmbedGlobalInfo(false),
- mEmbedGlobalInfoSkipConstant(false) { }
-
-RSScript::RSScript(Source &pSource, const CompilerConfig * pCompilerConfig): RSScript(pSource)
-{
- switch (pCompilerConfig->getOptimizationLevel()) {
- case llvm::CodeGenOpt::None: mOptimizationLevel = kOptLvl0; break;
- case llvm::CodeGenOpt::Less: mOptimizationLevel = kOptLvl1; break;
- case llvm::CodeGenOpt::Default: mOptimizationLevel = kOptLvl2; break;
- case llvm::CodeGenOpt::Aggressive: //Intentional fallthrough
- default: {
- mOptimizationLevel = kOptLvl3;
- break;
- }
- }
-}
-
-bool RSScript::doReset() {
- mCompilerVersion = 0;
- mOptimizationLevel = kOptLvl3;
- return true;
-}
diff --git a/lib/Script.cpp b/lib/Script.cpp
index 22d173b..fad070d 100644
--- a/lib/Script.cpp
+++ b/lib/Script.cpp
@@ -16,22 +16,44 @@
#include "bcc/Script.h"
+#include "Assert.h"
+#include "Log.h"
+
+#include "bcc/CompilerConfig.h"
#include "bcc/Source.h"
using namespace bcc;
-bool Script::reset(Source &pSource, bool pPreserveCurrent) {
- if (mSource == &pSource) {
+Script::Script(Source *pSource)
+ : mSource(pSource),
+ mOptimizationLevel(llvm::CodeGenOpt::Aggressive),
+ mLinkRuntimeCallback(nullptr), mEmbedInfo(false), mEmbedGlobalInfo(false),
+ mEmbedGlobalInfoSkipConstant(false) {}
+
+bool Script::LinkRuntime(const char *core_lib) {
+ bccAssert(core_lib != nullptr);
+
+ // Using the same context with the source.
+ BCCContext &context = mSource->getContext();
+
+ Source *libclcore_source = Source::CreateFromFile(context, core_lib);
+ if (libclcore_source == nullptr) {
+ ALOGE("Failed to load Renderscript library '%s' to link!", core_lib);
return false;
}
- if (!pPreserveCurrent) {
- delete mSource;
+ if (mLinkRuntimeCallback != nullptr) {
+ mLinkRuntimeCallback(this, &mSource->getModule(),
+ &libclcore_source->getModule());
}
- mSource = &pSource;
- return doReset();
-}
-bool Script::mergeSource(Source &pSource) {
- return mSource->merge(pSource);
+ if (!mSource->merge(*libclcore_source)) {
+ ALOGE("Failed to link Renderscript library '%s'!", core_lib);
+ delete libclcore_source;
+ return false;
+ }
+
+ return true;
}
+
+bool Script::mergeSource(Source &pSource) { return mSource->merge(pSource); }
diff --git a/tools/bcc/Main.cpp b/tools/bcc/Main.cpp
index 3cc2ae6..3887bd9 100644
--- a/tools/bcc/Main.cpp
+++ b/tools/bcc/Main.cpp
@@ -345,7 +345,7 @@ int main(int argc, char **argv) {
return EXIT_FAILURE;
}
- std::unique_ptr<RSScript> s(new (std::nothrow) RSScript(*source, RSCD.getConfig()));
+ std::unique_ptr<Script> s(new (std::nothrow) Script(source));
if (s == nullptr) {
llvm::errs() << "Out of memory when creating script for file `"
<< OptInputFilenames[0] << "'!\n";
@@ -353,6 +353,7 @@ int main(int argc, char **argv) {
return EXIT_FAILURE;
}
+ s->setOptimizationLevel(RSCD.getConfig()->getOptimizationLevel());
llvm::SmallString<80> output(OptOutputPath);
llvm::sys::path::append(output, "/", OptOutputFilename);
llvm::sys::path::replace_extension(output, ".o");
diff --git a/tools/bcc_compat/Main.cpp b/tools/bcc_compat/Main.cpp
index da4ed38..bc42a44 100644
--- a/tools/bcc_compat/Main.cpp
+++ b/tools/bcc_compat/Main.cpp
@@ -109,9 +109,9 @@ void BCCVersionPrinter() {
} // end anonymous namespace
-RSScript *PrepareRSScript(BCCContext &pContext,
- const llvm::cl::list<std::string> &pBitcodeFiles) {
- RSScript *result = nullptr;
+Script *PrepareScript(BCCContext &pContext,
+ const llvm::cl::list<std::string> &pBitcodeFiles) {
+ Script *result = nullptr;
for (unsigned i = 0; i < pBitcodeFiles.size(); i++) {
const std::string &input_bitcode = pBitcodeFiles[i];
@@ -130,7 +130,7 @@ RSScript *PrepareRSScript(BCCContext &pContext,
return nullptr;
}
} else {
- result = new (std::nothrow) RSScript(*source);
+ result = new (std::nothrow) Script(source);
if (result == nullptr) {
llvm::errs() << "Out of memory when create script for file `"
<< input_bitcode << "'!\n";
@@ -270,7 +270,7 @@ int main(int argc, char **argv) {
return EXIT_FAILURE;
}
- std::unique_ptr<RSScript> s(PrepareRSScript(context, OptInputFilenames));
+ std::unique_ptr<Script> s(PrepareScript(context, OptInputFilenames));
if (!rscd.buildForCompatLib(*s, OutputFilename.c_str(), nullptr, OptRuntimePath.c_str(), false)) {
fprintf(stderr, "Failed to compile script!");
return EXIT_FAILURE;