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)
2 files changed