Skip to content

Commit

Permalink
slice activity analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses committed Dec 28, 2024
1 parent 9fe27b8 commit 7e4b13f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions enzyme/Enzyme/ActivityAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,10 @@ bool ActivityAnalyzer::isFunctionArgumentConstant(CallInst *CI, Value *val) {
if (Name == "jl_reshape_array" || Name == "ijl_reshape_array")
return val != CI->getArgOperand(1);

// Only the 0-th arg impacts activity
if (Name == "jl_genericmemory_copy_slice" || Name == "ijl_genericmemory_copy_slice")
return val != CI->getArgOperand(0);

// Allocations, deallocations, and c++ guards don't impact the activity
// of arguments
if (isAllocationFunction(Name, TLI) || isDeallocationFunction(Name, TLI))
Expand Down Expand Up @@ -660,6 +664,12 @@ static inline void propagateArgumentInformation(
return;
}

// Only the 0-th arg impacts activity
if (Name == "jl_genericmemory_copy_slice" || Name == "ijl_genericmemory_copy_slice") {
propagateFromOperand(CI.getArgOperand(1));
return;
}

// Only the 1-th arg impacts activity
if (Name == "jl_reshape_array" || Name == "ijl_reshape_array") {
propagateFromOperand(CI.getArgOperand(1));
Expand Down Expand Up @@ -1583,6 +1593,27 @@ bool ActivityAnalyzer::isConstantValue(TypeResults const &TR, Value *Val) {
return true;
}

if (funcName == "jl_genericmemory_copy_slice" || funcName == "ijl_genericmemory_copy_slice") {
if (directions == UP) {
if (isConstantValue(TR, op->getArgOperand(0))) {
InsertConstantValue(TR, Val);
return true;
}
} else {
if (UpHypothesis->isConstantValue(TR, op->getArgOperand(0))) {
InsertConstantValue(TR, Val);
insertConstantsFrom(TR, *UpHypothesis);
return true;
}
}
if (EnzymeEnableRecursiveHypotheses) {
ReEvaluateValueIfInactiveValue[op->getArgOperand(0)].insert(Val);
if (TmpOrig != Val) {
ReEvaluateValueIfInactiveValue[op->getArgOperand(0)].insert(TmpOrig);
}
}
}

// If requesting empty unknown functions to be considered inactive,
// abide by those rules
if (called && EnzymeEmptyFnInactive && called->empty() &&
Expand Down

0 comments on commit 7e4b13f

Please sign in to comment.