diff options
author | Hideto Ueno <uenoku.tokotoko@gmail.com> | 2019-09-11 07:00:33 +0000 |
---|---|---|
committer | Hideto Ueno <uenoku.tokotoko@gmail.com> | 2019-09-11 07:00:33 +0000 |
commit | 1d68ed8c24e34231ba495c6ea2823c3eb1d90e85 (patch) | |
tree | 1055a03086393a5f47f1ff9af4704eab54e1d4c8 /llvm/lib | |
parent | 37367646578735c1bd453f959dd7696e2a41d621 (diff) | |
download | bcm5719-llvm-1d68ed8c24e34231ba495c6ea2823c3eb1d90e85.tar.gz bcm5719-llvm-1d68ed8c24e34231ba495c6ea2823c3eb1d90e85.zip |
[Attributor] Implement "noalias" callsite argument deduction
Summary: Now, `nocapture` is deduced in Attributor therefore, this patch introduces deduction for `noalias` callsite argument using `nocapture`.
Reviewers: jdoerfert, sstefan1
Reviewed By: jdoerfert
Subscribers: lebedev.ri, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67286
llvm-svn: 371590
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/IPO/Attributor.cpp | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index 064791897a5..94ed7003c96 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -1672,8 +1672,9 @@ struct AANoAliasFloating final : AANoAliasImpl { /// See AbstractAttribute::initialize(...). void initialize(Attributor &A) override { - // TODO: It isn't sound to initialize as the same with `AANoAliasImpl` - // because `noalias` may not be valid in the current position. + AANoAliasImpl::initialize(A); + if (isa<AllocaInst>(getAnchorValue())) + indicateOptimisticFixpoint(); } /// See AbstractAttribute::updateImpl(...). @@ -1711,8 +1712,53 @@ struct AANoAliasCallSiteArgument final : AANoAliasImpl { /// See AbstractAttribute::updateImpl(...). ChangeStatus updateImpl(Attributor &A) override { - // TODO: Implement this. - return indicatePessimisticFixpoint(); + // We can deduce "noalias" if the following conditions hold. + // (i) Associated value is assumed to be noalias in the definition. + // (ii) Associated value is assumed to be no-capture in all the uses + // possibly executed before this callsite. + // (iii) There is no other pointer argument which could alias with the + // value. + + const Value &V = getAssociatedValue(); + const IRPosition IRP = IRPosition::value(V); + + // (i) Check whether noalias holds in the definition. + + auto &NoAliasAA = A.getAAFor<AANoAlias>(*this, IRP); + + if (!NoAliasAA.isAssumedNoAlias()) + return indicatePessimisticFixpoint(); + + LLVM_DEBUG(dbgs() << "[Attributor][AANoAliasCSArg] " << V + << " is assumed NoAlias in the definition\n"); + + // (ii) Check whether the value is captured in the scope using AANoCapture. + // FIXME: This is conservative though, it is better to look at CFG and + // check only uses possibly executed before this callsite. + + auto &NoCaptureAA = A.getAAFor<AANoCapture>(*this, IRP); + if (!NoCaptureAA.isAssumedNoCaptureMaybeReturned()) + return indicatePessimisticFixpoint(); + + // (iii) Check there is no other pointer argument which could alias with the + // value. + ImmutableCallSite ICS(&getAnchorValue()); + for (unsigned i = 0; i < ICS.getNumArgOperands(); i++) { + if (getArgNo() == (int)i) + continue; + const Value *ArgOp = ICS.getArgOperand(i); + if (!ArgOp->getType()->isPointerTy()) + continue; + + // TODO: Use AliasAnalysis + // AAResults& AAR = ..; + // if(AAR.isNoAlias(&getAssociatedValue(), ArgOp)) + // return indicatePessimitisicFixpoint(); + + return indicatePessimisticFixpoint(); + } + + return ChangeStatus::UNCHANGED; } /// See AbstractAttribute::trackStatistics() |