diff options
author | Mark Seaborn <mseaborn@chromium.org> | 2013-06-04 17:18:01 -0700 |
---|---|---|
committer | Mark Seaborn <mseaborn@chromium.org> | 2013-06-04 17:18:01 -0700 |
commit | 51c0650c7bb78fed8ce0aba537312aea17f58d7d (patch) | |
tree | 1d19c01c79b858427a95b37862d47c393de3fbf6 | |
parent | a4dba98995121b623698f1b8951da71e17ec634d (diff) |
PNaCl: Enable RewritePNaClLibraryCalls and fix it to remove unused decls
Removing the unused declarations of setjmp()/longjmp() will be
necessary for future ABI checks which will reject these external
function declarations because they are not intrinsics.
StripDeadPrototypes is supposed to remove these declarations, but it
fails to do so because there are dead ConstantExprs referencing the
declarations. I suspect these are left behind by ReplacePtrsWithInts.
We could fix this by adding calls to removeDeadConstantUsers() to
StripDeadPrototypes or to ReplacePtrsWithInts, but for now it seems
cleaner to fix RewritePNaClLibraryCalls.
BUG=https://code.google.com/p/nativeclient/issues/detail?id=3429
TEST=*.ll tests + tested along with an ABI check
Review URL: https://codereview.chromium.org/15931009
-rw-r--r-- | lib/Transforms/NaCl/PNaClABISimplify.cpp | 2 | ||||
-rw-r--r-- | lib/Transforms/NaCl/RewritePNaClLibraryCalls.cpp | 5 | ||||
-rw-r--r-- | test/Transforms/NaCl/rewrite-longjmp-no-store.ll | 5 | ||||
-rw-r--r-- | test/Transforms/NaCl/rewrite-setlongjmp-calls.ll | 4 |
4 files changed, 14 insertions, 2 deletions
diff --git a/lib/Transforms/NaCl/PNaClABISimplify.cpp b/lib/Transforms/NaCl/PNaClABISimplify.cpp index 74a9f0730e..684be734c2 100644 --- a/lib/Transforms/NaCl/PNaClABISimplify.cpp +++ b/lib/Transforms/NaCl/PNaClABISimplify.cpp @@ -42,6 +42,8 @@ void llvm::PNaClABISimplifyAddPreOptPasses(PassManager &PM) { } void llvm::PNaClABISimplifyAddPostOptPasses(PassManager &PM) { + PM.add(createRewritePNaClLibraryCallsPass()); + // We place ExpandByVal after optimization passes because some byval // arguments can be expanded away by the ArgPromotion pass. Leaving // in "byval" during optimization also allows some dead stores to be diff --git a/lib/Transforms/NaCl/RewritePNaClLibraryCalls.cpp b/lib/Transforms/NaCl/RewritePNaClLibraryCalls.cpp index 2373343f59..ea50457070 100644 --- a/lib/Transforms/NaCl/RewritePNaClLibraryCalls.cpp +++ b/lib/Transforms/NaCl/RewritePNaClLibraryCalls.cpp @@ -86,6 +86,7 @@ bool RewritePNaClLibraryCalls::runOnModule(Module &M) { report_fatal_error("Taking the address of setjmp is invalid"); } } + SetjmpFunc->eraseFromParent(); } // For longjmp things are a little more complicated, since longjmp's address @@ -109,7 +110,9 @@ bool RewritePNaClLibraryCalls::runOnModule(Module &M) { } // If additional uses remain, these aren't calls; populate the wrapper. - if (!LongjmpFunc->use_empty()) { + if (LongjmpFunc->use_empty()) { + LongjmpFunc->eraseFromParent(); + } else { populateLongjmpWrapper(LongjmpFunc); Changed = true; } diff --git a/test/Transforms/NaCl/rewrite-longjmp-no-store.ll b/test/Transforms/NaCl/rewrite-longjmp-no-store.ll index fa2cd3b620..134593ad39 100644 --- a/test/Transforms/NaCl/rewrite-longjmp-no-store.ll +++ b/test/Transforms/NaCl/rewrite-longjmp-no-store.ll @@ -1,9 +1,12 @@ ; RUN: opt < %s -rewrite-pnacl-library-calls -S | FileCheck %s +; RUN: opt < %s -rewrite-pnacl-library-calls -S | FileCheck %s -check-prefix=CLEANED ; Test that when there are no uses other than calls to longjmp, ; no function body is generated. declare void @longjmp(i64*, i32) -; CHECK-NOT: define{{.*}}@longjmp(i64* %env, i32 %val) { + +; No declaration or definition of longjmp() should remain. +; CLEANED-NOT: @longjmp define void @call_longjmp(i64* %arg, i32 %num) { call void @longjmp(i64* %arg, i32 %num) diff --git a/test/Transforms/NaCl/rewrite-setlongjmp-calls.ll b/test/Transforms/NaCl/rewrite-setlongjmp-calls.ll index 6ce3294244..f34f004d7f 100644 --- a/test/Transforms/NaCl/rewrite-setlongjmp-calls.ll +++ b/test/Transforms/NaCl/rewrite-setlongjmp-calls.ll @@ -1,9 +1,13 @@ ; RUN: opt < %s -rewrite-pnacl-library-calls -S | FileCheck %s +; RUN: opt < %s -rewrite-pnacl-library-calls -S | FileCheck %s -check-prefix=CLEANED ; Test the RewritePNaClLibraryCalls pass declare i32 @setjmp(i64*) declare void @longjmp(i64*, i32) +; No declaration or definition of setjmp() should remain. +; CLEANED-NOT: @setjmp + ; Since the address of longjmp is being taken here, a body is generated ; for it, which does a cast and calls an intrinsic |