Skip to content

Commit

Permalink
[Attributor] Make use of analysis in the MustBeExecutedExplorer
Browse files Browse the repository at this point in the history
This commit was made to settle [[ #175 | this issue on GitHub ]].
I added analysis getters for LoopInfo, DominatorTree, and
PostDominatorTree. And I added a test to show an improvement of the
deduction of `dereferenceable` attribute.

Reviewed By: jdoerfert, uenoku

Differential Revision: https://reviews.llvm.org/D76378
  • Loading branch information
okuraofvegetable authored and jdoerfert committed Apr 5, 2020
1 parent 221890d commit 475abe1
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
16 changes: 14 additions & 2 deletions llvm/include/llvm/Transforms/IPO/Attributor.h
Expand Up @@ -107,6 +107,7 @@
#include "llvm/Analysis/InlineCost.h"
#include "llvm/Analysis/LazyCallGraph.h"
#include "llvm/Analysis/MustExecute.h"
#include "llvm/Analysis/PostDominators.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/CallSite.h"
Expand Down Expand Up @@ -566,8 +567,19 @@ struct InformationCache {
InformationCache(const Module &M, AnalysisGetter &AG,
SetVector<Function *> *CGSCC)
: DL(M.getDataLayout()),
Explorer(/* ExploreInterBlock */ true, /* ExploreCFGForward */ true,
/* ExploreCFGBackward */ true),
Explorer(
/* ExploreInterBlock */ true, /* ExploreCFGForward */ true,
/* ExploreCFGBackward */ true,
/* LIGetter */
[&](const Function &F) { return AG.getAnalysis<LoopAnalysis>(F); },
/* DTGetter */
[&](const Function &F) {
return AG.getAnalysis<DominatorTreeAnalysis>(F);
},
/* PDTGetter */
[&](const Function &F) {
return AG.getAnalysis<PostDominatorTreeAnalysis>(F);
}),
AG(AG), CGSCC(CGSCC) {}

/// A map type from opcodes to instructions with this opcode.
Expand Down
45 changes: 45 additions & 0 deletions llvm/test/Transforms/Attributor/dereferenceable-2.ll
@@ -1,4 +1,5 @@
; RUN: opt < %s -attributor --attributor-disable=false -S | FileCheck %s --check-prefix=ATTRIBUTOR
; RUN: opt < %s -passes=attributor --attributor-disable=false -S | FileCheck %s --check-prefix=ATTRIBUTOR_CGSCC_NPM
; Copied from Transforms/InferFunctionAttrs/dereferenceable.ll

; Determine dereference-ability before unused loads get deleted:
Expand Down Expand Up @@ -354,3 +355,47 @@ define void @different_size2(i32* %arg) {
store double 0.000000e+00, double* %arg-cast
ret void
}

; Make use of MustBeExecuted Explorer
;
; [CFG]
; entry
; / \
; l1 l2
; | X |
; l3 l4
; \ /
; l5
; / \
; l6 l7
; \ /
; end
; According to the above CFG, we can see that instructions in l5 Block must be executed.
; Therefore, %p must be dereferenced.
;
; ATTRIBUTOR_CGSCC_NPM-LABEL: define i32 @require_cfg_analysis(i32 %c, i32* {{.*}} dereferenceable(4) %p)
define i32 @require_cfg_analysis(i32 %c, i32* %p) {
%tobool1 = icmp eq i32 %c, 0
br i1 %tobool1, label %l1, label %l2
l1:
%tobool2 = icmp eq i32 %c, 1
br i1 %tobool2, label %l3, label %l4
l2:
%tobool3 = icmp eq i32 %c, 2
br i1 %tobool3, label %l3, label %l4
l3:
br label %l5
l4:
br label %l5
l5:
%tobool4 = icmp eq i32 %c, 4
br i1 %tobool4, label %l6, label %l7
l6:
store i32 0, i32* %p
br label %end
l7:
store i32 1, i32* %p
br label %end
end:
ret i32 1
}

0 comments on commit 475abe1

Please sign in to comment.