-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1309 from j2kun:analysis-visit-external-call
PiperOrigin-RevId: 720257505
- Loading branch information
Showing
15 changed files
with
163 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package( | ||
default_applicable_licenses = ["@heir//:license"], | ||
default_visibility = ["//visibility:public"], | ||
) | ||
|
||
cc_library( | ||
name = "Utils", | ||
hdrs = ["Utils.h"], | ||
deps = [ | ||
"@llvm-project//mlir:Analysis", | ||
"@llvm-project//mlir:CallOpInterfaces", | ||
"@llvm-project//mlir:Support", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef LIB_ANALYSIS_UTILS_H_ | ||
#define LIB_ANALYSIS_UTILS_H_ | ||
|
||
#include <functional> | ||
|
||
#include "mlir/include/mlir/Analysis/DataFlowFramework.h" // from @llvm-project | ||
#include "mlir/include/mlir/Interfaces/CallInterfaces.h" // from @llvm-project | ||
#include "mlir/include/mlir/Support/LLVM.h" // from @llvm-project | ||
|
||
namespace mlir { | ||
namespace heir { | ||
|
||
// A generalized version of visitExternalCall that joins all arguments to the | ||
// func.call op, and then propagates this joined value to all results. This is | ||
// useful for debug functions where there is a single operand that is not | ||
// changed by the external call, but can also be useful for some analyses like | ||
// secretness, where the result of the call is secret if any operand is secret. | ||
template <typename StateT, typename LatticeT> | ||
void visitExternalCall(CallOpInterface call, | ||
ArrayRef<const LatticeT *> argumentLattices, | ||
ArrayRef<LatticeT *> resultLattices, | ||
const std::function<void(AnalysisState *, ChangeResult)> | ||
&propagateIfChanged) { | ||
StateT resultState = StateT(); | ||
|
||
for (const LatticeT *operand : argumentLattices) { | ||
const StateT operandState = operand->getValue(); | ||
resultState = StateT::join(resultState, operandState); | ||
} | ||
|
||
for (LatticeT *result : resultLattices) { | ||
propagateIfChanged(result, result->join(resultState)); | ||
} | ||
} | ||
|
||
} // namespace heir | ||
} // namespace mlir | ||
|
||
#endif // LIB_ANALYSIS_UTILS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters