aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Gross <dgross@google.com>2017-05-11 13:57:07 -0700
committerDavid Gross <dgross@google.com>2017-06-08 14:29:16 -0700
commit5760088f32935148cab77621f39c21d3e30995b0 (patch)
tree4feafe8cc8ededfc3d2d05f6808b5955342abef2
parent6834cd0d47a7b421430b3e3724b57d0508986d79 (diff)
downloadlibbcc-5760088f32935148cab77621f39c21d3e30995b0.tar.gz
Strip unknown attributes during bitcode translation.
We need to remove attributes unknown to old versions of LLVM before writing out bitcode, to avoid errors when writing or reading the bitcode. Why do we need to strip unknown attributes during bitcode translation (which always translates from an older version of bitcode to a newer version of bitcode), even if the input .bc does not contain those attributes? Because the LLVM bitcode reader calls llvm::UpgradeCallsToIntrinsic() to canonicalize the attributes of intrinsic functions. For example, rslist.bc from RsTest_11 contains calls to @llvm.lifetime.start and @llvm.lifetime.end, which get canonicalized to have the argmemonly attribute. Remember that we're writing an old fixed version of bitcode, older than the "native" LLVM IR we're using, so there may be attributes in that IR that are not representible in that old fixed version of bitcode. Furthermore, argmemonly is one of a set of attributes that seem to be designed as "transient" -- they can appear in the IR (possibly only on intrinsics, or as the result of some analysis?) but can never appear in bitcode. Bug: 37720701 Test: aosp_x86_64-eng FORCE_BUILD_LLVM_DISABLE_NDEBUG=true 1) slang/tests 2) slang/lit-tests 3) RsTest (32-bit, 64-bit) -- but did not run math_fp16 (http://b/62452374) 4) RsTest_11 -- but then got runtime error (http://b/62452065) 5) cts -m RenderscriptTest Change-Id: I42374acb34029f7cf5a3dbf7d9a701250d53ecc8 (cherry picked from commit bcb03e5437a811eeaf1dfa895bfe93d841e76660)
-rw-r--r--bcinfo/Android.bp1
-rw-r--r--bcinfo/BitcodeTranslator.cpp9
2 files changed, 10 insertions, 0 deletions
diff --git a/bcinfo/Android.bp b/bcinfo/Android.bp
index bd4fee5..e35bbd0 100644
--- a/bcinfo/Android.bp
+++ b/bcinfo/Android.bp
@@ -56,6 +56,7 @@ cc_library_shared {
"libLLVMBitReader_2_7",
"libLLVMBitReader_3_0",
"libLLVMBitWriter_3_2",
+ "libStripUnkAttr",
],
target: {
diff --git a/bcinfo/BitcodeTranslator.cpp b/bcinfo/BitcodeTranslator.cpp
index 5335eba..b3bce31 100644
--- a/bcinfo/BitcodeTranslator.cpp
+++ b/bcinfo/BitcodeTranslator.cpp
@@ -23,6 +23,8 @@
#include "BitWriter_3_2/ReaderWriter_3_2.h"
+#include "StripUnkAttr/strip_unknown_attributes.h"
+
#define LOG_TAG "bcinfo"
#include <log/log.h>
@@ -68,6 +70,11 @@ static const unsigned int kMinimumCompatibleVersion_LLVM_3_0 = 14;
static const unsigned int kMinimumCompatibleVersion_LLVM_2_7 = 11;
+static void stripUnknownAttributes(llvm::Module *M) {
+ for (llvm::Function &F : *M)
+ slang::stripUnknownAttributes(F);
+}
+
BitcodeTranslator::BitcodeTranslator(const char *bitcode, size_t bitcodeSize,
unsigned int version)
: mBitcode(bitcode), mBitcodeSize(bitcodeSize), mTranslatedBitcode(nullptr),
@@ -145,6 +152,8 @@ bool BitcodeTranslator::translate() {
// Module ownership is handled by the context, so we don't need to free it.
llvm::Module *module = MOrErr.get();
+ stripUnknownAttributes(module);
+
std::string Buffer;
llvm::raw_string_ostream OS(Buffer);