Skip to content

Commit

Permalink
[AliasAnalysis] Make the dependence on SideEffectsAnalysis internal.
Browse files Browse the repository at this point in the history
This commit removes the public method for fetching SideEffectsAnalysis. The
dependency on SEA is now an implementation detail of AliasAnalysis and
computeMemoryBehavior.
  • Loading branch information
nadavrot committed Nov 24, 2015
1 parent 3d35b03 commit a3020a8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
4 changes: 1 addition & 3 deletions include/swift/SILAnalysis/AliasAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ class AliasAnalysis : public SILAnalysis {

virtual void initialize(SILPassManager *PM);

SideEffectAnalysis *getSideEffectAnalysis() const { return SEA; }

/// Perform an alias query to see if V1, V2 refer to the same values.
AliasResult alias(SILValue V1, SILValue V2, SILType TBAAType1 = SILType(),
SILType TBAAType2 = SILType());
Expand Down Expand Up @@ -112,7 +110,7 @@ class AliasAnalysis : public SILAnalysis {
/// respect to V.
///
/// TODO: When ref count behavior is separated from generic memory behavior,
/// the IgnoreRefCountIncrements flag will be unnecessary.
/// the InspectionMode flag will be unnecessary.
MemoryBehavior computeMemoryBehavior(SILInstruction *Inst, SILValue V,
RetainObserveKind);

Expand Down
34 changes: 18 additions & 16 deletions lib/SILAnalysis/MemoryBehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ using MemBehavior = SILInstruction::MemoryBehavior;
class MemoryBehaviorVisitor
: public SILInstructionVisitor<MemoryBehaviorVisitor, MemBehavior> {

/// The alias analysis for any queries we may need.
AliasAnalysis &AA;
AliasAnalysis *AA;

SideEffectAnalysis *SEA;

/// The value we are attempting to discover memory behavior relative to.
SILValue V;
Expand All @@ -45,12 +46,12 @@ class MemoryBehaviorVisitor

/// Should we treat instructions that increment ref counts as None instead of
/// MayHaveSideEffects.
RetainObserveKind IgnoreRefCountIncrements;
RetainObserveKind InspectionMode;

public:
MemoryBehaviorVisitor(AliasAnalysis &AA, SILValue V,
MemoryBehaviorVisitor(AliasAnalysis *AA, SideEffectAnalysis *SEA, SILValue V,
RetainObserveKind IgnoreRefCountIncs)
: AA(AA), V(V), IgnoreRefCountIncrements(IgnoreRefCountIncs) {}
: AA(AA), SEA(SEA), V(V), InspectionMode(IgnoreRefCountIncs) {}

SILType getValueTBAAType() {
if (!TypedAccessTy)
Expand Down Expand Up @@ -98,7 +99,7 @@ class MemoryBehaviorVisitor
#define OPERANDALIAS_MEMBEHAVIOR_INST(Name) \
MemBehavior visit##Name(Name *I) { \
for (Operand &Op : I->getAllOperands()) { \
if (!AA.isNoAlias(Op.get(), V)) { \
if (!AA->isNoAlias(Op.get(), V)) { \
DEBUG(llvm::dbgs() << " " #Name \
" does alias inst. Returning Normal behavior.\n"); \
return I->getMemoryBehavior(); \
Expand Down Expand Up @@ -133,7 +134,7 @@ class MemoryBehaviorVisitor
// memory this will be unnecessary.
#define REFCOUNTINC_MEMBEHAVIOR_INST(Name) \
MemBehavior visit##Name(Name *I) { \
if (IgnoreRefCountIncrements == RetainObserveKind::IgnoreRetains) \
if (InspectionMode == RetainObserveKind::IgnoreRetains) \
return MemBehavior::None; \
return I->getMemoryBehavior(); \
}
Expand All @@ -148,7 +149,7 @@ class MemoryBehaviorVisitor
} // end anonymous namespace

MemBehavior MemoryBehaviorVisitor::visitLoadInst(LoadInst *LI) {
if (AA.isNoAlias(LI->getOperand(), V, computeTBAAType(LI->getOperand()),
if (AA->isNoAlias(LI->getOperand(), V, computeTBAAType(LI->getOperand()),
getValueTBAAType())) {
DEBUG(llvm::dbgs() << " Load Operand does not alias inst. Returning "
"None.\n");
Expand All @@ -168,7 +169,7 @@ MemBehavior MemoryBehaviorVisitor::visitStoreInst(StoreInst *SI) {

// If the store dest cannot alias the pointer in question, then the
// specified value can not be modified by the store.
if (AA.isNoAlias(SI->getDest(), V, computeTBAAType(SI->getDest()),
if (AA->isNoAlias(SI->getDest(), V, computeTBAAType(SI->getDest()),
getValueTBAAType())) {
DEBUG(llvm::dbgs() << " Store Dst does not alias inst. Returning "
"None.\n");
Expand Down Expand Up @@ -228,29 +229,29 @@ MemBehavior MemoryBehaviorVisitor::visitTryApplyInst(TryApplyInst *AI) {
MemBehavior MemoryBehaviorVisitor::visitApplyInst(ApplyInst *AI) {

SideEffectAnalysis::FunctionEffects ApplyEffects;
AA.getSideEffectAnalysis()->getEffects(ApplyEffects, AI);
SEA->getEffects(ApplyEffects, AI);

MemBehavior Behavior = MemBehavior::None;

// We can ignore mayTrap().
if (ApplyEffects.mayReadRC() ||
(IgnoreRefCountIncrements == RetainObserveKind::ObserveRetains &&
(InspectionMode == RetainObserveKind::ObserveRetains &&
ApplyEffects.mayAllocObjects())) {
Behavior = MemBehavior::MayHaveSideEffects;
} else {
auto &GlobalEffects = ApplyEffects.getGlobalEffects();
Behavior = GlobalEffects.getMemBehavior(IgnoreRefCountIncrements);
Behavior = GlobalEffects.getMemBehavior(InspectionMode);

// Check all parameter effects.
for (unsigned Idx = 0, End = AI->getNumArguments();
Idx < End && Behavior < MemBehavior::MayHaveSideEffects; ++Idx) {
auto &ArgEffect = ApplyEffects.getParameterEffects()[Idx];
auto ArgBehavior = ArgEffect.getMemBehavior(IgnoreRefCountIncrements);
auto ArgBehavior = ArgEffect.getMemBehavior(InspectionMode);
if (ArgBehavior > Behavior) {
SILValue Arg = AI->getArgument(Idx);
// We only consider the argument effects if the argument aliases V.
if (!Arg.getType().isAddress() ||
!AA.isNoAlias(Arg, V, computeTBAAType(Arg), getValueTBAAType())) {
!AA->isNoAlias(Arg, V, computeTBAAType(Arg), getValueTBAAType())) {
Behavior = ArgBehavior;
}
}
Expand Down Expand Up @@ -307,8 +308,9 @@ MemBehavior MemoryBehaviorVisitor::visitReleaseValueInst(ReleaseValueInst *SI) {

MemBehavior
AliasAnalysis::computeMemoryBehavior(SILInstruction *Inst, SILValue V,
RetainObserveKind IgnoreRefCountIncrements) {
RetainObserveKind InspectionMode) {
DEBUG(llvm::dbgs() << "GET MEMORY BEHAVIOR FOR:\n " << *Inst << " "
<< *V.getDef());
return MemoryBehaviorVisitor(*this, V, IgnoreRefCountIncrements).visit(Inst);
assert(SEA && "SideEffectsAnalysis must be initialized!");
return MemoryBehaviorVisitor(this, SEA, V, InspectionMode).visit(Inst);
}

0 comments on commit a3020a8

Please sign in to comment.