Update RS driver to support extraction of global variable properties.
Bug: 20306487
This patch adds some new enums to classify properties (such as "static",
"constant", and "pointer") for global variables. The reference driver
is also extended to provide methods to examine these properties (when
the bitcode is compiled with bcc).
Change-Id: I331756f8a8990caf5ebdf85599060434a7cfdcb7
diff --git a/cpu_ref/rsCpuExecutable.cpp b/cpu_ref/rsCpuExecutable.cpp
index f229f52..e2c27b5 100644
--- a/cpu_ref/rsCpuExecutable.cpp
+++ b/cpu_ref/rsCpuExecutable.cpp
@@ -311,12 +311,13 @@
const char ** pragmaValues = nullptr;
uint32_t checksum = 0;
- const char *rsInfo = (const char *) dlsym(sharedObj, ".rs.info");
+ const char *rsInfo = (const char *) dlsym(sharedObj, kRsInfo);
int numEntries = 0;
- const int *rsGlobalEntries = (const int *) dlsym(sharedObj, ".rs.global_entries");
- const char **rsGlobalNames = (const char **) dlsym(sharedObj, ".rs.global_names");
- const void **rsGlobalAddresses = (const void **) dlsym(sharedObj, ".rs.global_addresses");
- const size_t *rsGlobalSizes = (const size_t *) dlsym(sharedObj, ".rs.global_sizes");
+ const int *rsGlobalEntries = (const int *) dlsym(sharedObj, kRsGlobalEntries);
+ const char **rsGlobalNames = (const char **) dlsym(sharedObj, kRsGlobalNames);
+ const void **rsGlobalAddresses = (const void **) dlsym(sharedObj, kRsGlobalAddresses);
+ const size_t *rsGlobalSizes = (const size_t *) dlsym(sharedObj, kRsGlobalSizes);
+ const uint32_t *rsGlobalProperties = (const uint32_t *) dlsym(sharedObj, kRsGlobalProperties);
if (strgets(line, MAXLINE, &rsInfo) == nullptr) {
return nullptr;
@@ -559,6 +560,7 @@
rsAssert(rsGlobalNames);
rsAssert(rsGlobalAddresses);
rsAssert(rsGlobalSizes);
+ rsAssert(rsGlobalProperties);
}
} else {
ALOGD("Missing .rs.global_entries from shared object");
@@ -569,8 +571,8 @@
invokeFunctions, funcCount,
forEachFunctions, forEachSignatures, forEachCount,
pragmaKeys, pragmaValues, pragmaCount,
- rsGlobalNames, rsGlobalAddresses, rsGlobalSizes, numEntries,
- isThreadable, checksum);
+ rsGlobalNames, rsGlobalAddresses, rsGlobalSizes, rsGlobalProperties,
+ numEntries, isThreadable, checksum);
error:
@@ -612,9 +614,18 @@
bool ScriptExecutable::dumpGlobalInfo() const {
ALOGE("Globals: %p %p %p", mGlobalAddresses, mGlobalSizes, mGlobalNames);
+ ALOGE("P - Pointer");
+ ALOGE(" C - Constant");
+ ALOGE(" S - Static");
for (int i = 0; i < mGlobalEntries; i++) {
ALOGE("Global[%d]: %p %zu %s", i, mGlobalAddresses[i], mGlobalSizes[i],
mGlobalNames[i]);
+ uint32_t properties = mGlobalProperties[i];
+ ALOGE("%c%c%c Type: %u",
+ isGlobalPointer(properties) ? 'P' : ' ',
+ isGlobalConstant(properties) ? 'C' : ' ',
+ isGlobalStatic(properties) ? 'S' : ' ',
+ getGlobalRsType(properties));
}
return true;
}
diff --git a/cpu_ref/rsCpuExecutable.h b/cpu_ref/rsCpuExecutable.h
index ec872f6..0464dac 100644
--- a/cpu_ref/rsCpuExecutable.h
+++ b/cpu_ref/rsCpuExecutable.h
@@ -67,7 +67,8 @@
const char** pragmaKeys, const char** pragmaValues,
size_t pragmaCount,
const char **globalNames, const void **globalAddresses,
- const size_t *globalSizes, size_t globalEntries,
+ const size_t *globalSizes,
+ const uint32_t *globalProperties, size_t globalEntries,
bool isThreadable, uint32_t buildChecksum) :
mFieldAddress(fieldAddress), mFieldIsObject(fieldIsObject),
mFieldName(fieldName), mExportedVarCount(varCount),
@@ -77,8 +78,9 @@
mPragmaKeys(pragmaKeys), mPragmaValues(pragmaValues),
mPragmaCount(pragmaCount), mGlobalNames(globalNames),
mGlobalAddresses(globalAddresses), mGlobalSizes(globalSizes),
- mGlobalEntries(globalEntries), mIsThreadable(isThreadable),
- mBuildChecksum(buildChecksum), mRS(RSContext) {
+ mGlobalProperties(globalProperties), mGlobalEntries(globalEntries),
+ mIsThreadable(isThreadable), mBuildChecksum(buildChecksum),
+ mRS(RSContext) {
}
~ScriptExecutable() {
@@ -159,6 +161,13 @@
return 0;
}
}
+ uint32_t getGlobalProperties(int i) const {
+ if (i < mGlobalEntries) {
+ return mGlobalProperties[i];
+ } else {
+ return 0;
+ }
+ }
int getGlobalEntries() const { return mGlobalEntries; }
bool getThreadable() const { return mIsThreadable; }
@@ -187,6 +196,7 @@
const char ** mGlobalNames;
const void ** mGlobalAddresses;
const size_t * mGlobalSizes;
+ const uint32_t * mGlobalProperties;
int mGlobalEntries;
bool mIsThreadable;
diff --git a/cpu_ref/rsCpuScript.cpp b/cpu_ref/rsCpuScript.cpp
index 65ced66..9bcb4ac 100644
--- a/cpu_ref/rsCpuScript.cpp
+++ b/cpu_ref/rsCpuScript.cpp
@@ -922,6 +922,10 @@
return mScriptExec->getGlobalSize(i);
}
+uint32_t RsdCpuScriptImpl::getGlobalProperties(int i) const {
+ return mScriptExec->getGlobalProperties(i);
+}
+
void RsdCpuScriptImpl::preLaunch(uint32_t slot, const Allocation ** ains,
uint32_t inLen, Allocation * aout,
const void * usr, uint32_t usrLen,
diff --git a/cpu_ref/rsCpuScript.h b/cpu_ref/rsCpuScript.h
index 4844b34..efbb39f 100644
--- a/cpu_ref/rsCpuScript.h
+++ b/cpu_ref/rsCpuScript.h
@@ -112,6 +112,7 @@
const char * getGlobalName(int i) const override;
const void * getGlobalAddress(int i) const override;
size_t getGlobalSize(int i) const override;
+ uint32_t getGlobalProperties(int i) const override;
protected:
RsdCpuReferenceImpl *mCtx;
diff --git a/cpu_ref/rsd_cpu.h b/cpu_ref/rsd_cpu.h
index 6bfd913..0eed22c 100644
--- a/cpu_ref/rsd_cpu.h
+++ b/cpu_ref/rsd_cpu.h
@@ -97,6 +97,8 @@
virtual const void * getGlobalAddress(int i) const = 0;
// Returns the size (in bytes) of the global variable at index i.
virtual size_t getGlobalSize(int i) const = 0;
+ // Returns the properties of the global variable at index i.
+ virtual uint32_t getGlobalProperties(int i) const = 0;
virtual ~CpuScript() {}
};
diff --git a/rsDefines.h b/rsDefines.h
index fdb0720..18ba08a 100644
--- a/rsDefines.h
+++ b/rsDefines.h
@@ -116,7 +116,7 @@
};
enum RsDataType {
- RS_TYPE_NONE,
+ RS_TYPE_NONE = 0,
RS_TYPE_FLOAT_16,
RS_TYPE_FLOAT_32,
RS_TYPE_FLOAT_64,
@@ -465,6 +465,37 @@
uint32_t c_mult_int;
} RsBlasCall;
+enum RsGlobalProperty {
+ RS_GLOBAL_TYPE = 0x0000FFFF,
+ RS_GLOBAL_CONSTANT = 0x00010000,
+ RS_GLOBAL_STATIC = 0x00020000,
+ RS_GLOBAL_POINTER = 0x00040000
+};
+
+// Special symbols embedded into a shared object compiled by bcc.
+static const char kRoot[] = "root";
+static const char kInit[] = "init";
+static const char kRsDtor[] = ".rs.dtor";
+static const char kRsInfo[] = ".rs.info";
+static const char kRsGlobalEntries[] = ".rs.global_entries";
+static const char kRsGlobalNames[] = ".rs.global_names";
+static const char kRsGlobalAddresses[] = ".rs.global_addresses";
+static const char kRsGlobalSizes[] = ".rs.global_sizes";
+static const char kRsGlobalProperties[] = ".rs.global_properties";
+
+static inline uint32_t getGlobalRsType(uint32_t properties) {
+ return properties & RS_GLOBAL_TYPE;
+}
+static inline bool isGlobalConstant(uint32_t properties) {
+ return properties & RS_GLOBAL_CONSTANT;
+}
+static inline bool isGlobalStatic(uint32_t properties) {
+ return properties & RS_GLOBAL_STATIC;
+}
+static inline bool isGlobalPointer(uint32_t properties) {
+ return properties & RS_GLOBAL_POINTER;
+}
+
#ifdef __cplusplus
};
#endif