-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(compiler): clean statistic passes
- Loading branch information
Showing
17 changed files
with
599 additions
and
578 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
compilers/concrete-compiler/compiler/include/concretelang/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Part of the Concrete Compiler Project, under the BSD3 License with Zama | ||
// Exceptions. See | ||
// https://github.com/zama-ai/concrete-compiler-internal/blob/main/LICENSE.txt | ||
// for license information. | ||
|
||
#ifndef CONCRETELANG_ANALYSIS_UTILS_H | ||
#define CONCRETELANG_ANALYSIS_UTILS_H | ||
|
||
#include <boost/outcome.h> | ||
#include <concretelang/Common/Error.h> | ||
#include <mlir/Dialect/SCF/IR/SCF.h> | ||
#include <mlir/IR/Location.h> | ||
|
||
namespace mlir { | ||
namespace concretelang { | ||
|
||
/// Get the string representation of a location | ||
std::string locationString(mlir::Location loc); | ||
|
||
/// Compute the number of iterations based on loop info | ||
int64_t calculateNumberOfIterations(int64_t start, int64_t stop, int64_t step); | ||
|
||
/// Compute the number of iterations of an scf for loop | ||
outcome::checked<int64_t, ::concretelang::error::StringError> | ||
calculateNumberOfIterations(scf::ForOp &op); | ||
|
||
} // namespace concretelang | ||
} // namespace mlir | ||
|
||
#endif |
13 changes: 13 additions & 0 deletions
13
...ers/concrete-compiler/compiler/include/concretelang/Dialect/Concrete/Analysis/Analysis.td
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,13 @@ | ||
#ifndef CONCRETELANG_DIALECT_CONCRETE_ANALYSIS | ||
#define CONCRETELANG_DIALECT_CONCRETE_ANALYSIS | ||
|
||
include "mlir/Pass/PassBase.td" | ||
|
||
def MemoryUsage : Pass<"MemoryUsage", "::mlir::ModuleOp"> { | ||
let summary = "Compute memory usage"; | ||
let description = [{ | ||
Computes memory usage per location, and provides those numbers throught the CompilationFeedback. | ||
}]; | ||
} | ||
|
||
#endif |
4 changes: 4 additions & 0 deletions
4
.../concrete-compiler/compiler/include/concretelang/Dialect/Concrete/Analysis/CMakeLists.txt
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,4 @@ | ||
set(LLVM_TARGET_DEFINITIONS Analysis.td) | ||
mlir_tablegen(Analysis.h.inc -gen-pass-decls -name Analysis) | ||
add_public_tablegen_target(ConcretelangConcreteAnalysisPassIncGen) | ||
add_dependencies(mlir-headers ConcretelangConcreteAnalysisPassIncGen) |
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
1 change: 1 addition & 0 deletions
1
compilers/concrete-compiler/compiler/include/concretelang/Dialect/Concrete/CMakeLists.txt
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
add_subdirectory(Analysis) | ||
add_subdirectory(IR) | ||
add_subdirectory(Transforms) |
14 changes: 14 additions & 0 deletions
14
compilers/concrete-compiler/compiler/include/concretelang/Dialect/TFHE/Analysis/Analysis.td
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 @@ | ||
#ifndef CONCRETELANG_DIALECT_TFHE_ANALYSIS | ||
#define CONCRETELANG_DIALECT_TFHE_ANALYSIS | ||
|
||
include "mlir/Pass/PassBase.td" | ||
|
||
def ExtractStatistics : Pass<"ExtractStatistics", "::mlir::ModuleOp"> { | ||
let summary = "Extracts statistics"; | ||
let description = [{ | ||
Extracts different statistics (e.g. number of certain crypto operations), | ||
and provides those numbers throught the CompilationFeedback. | ||
}]; | ||
} | ||
|
||
#endif |
4 changes: 4 additions & 0 deletions
4
...lers/concrete-compiler/compiler/include/concretelang/Dialect/TFHE/Analysis/CMakeLists.txt
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,4 @@ | ||
set(LLVM_TARGET_DEFINITIONS Analysis.td) | ||
mlir_tablegen(Analysis.h.inc -gen-pass-decls -name Analysis) | ||
add_public_tablegen_target(ConcretelangTFHEAnalysisPassIncGen) | ||
add_dependencies(mlir-headers ConcretelangTFHEAnalysisPassIncGen) |
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
1 change: 1 addition & 0 deletions
1
compilers/concrete-compiler/compiler/include/concretelang/Dialect/TFHE/CMakeLists.txt
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
add_subdirectory(Analysis) | ||
add_subdirectory(IR) | ||
add_subdirectory(Transforms) |
9 changes: 9 additions & 0 deletions
9
compilers/concrete-compiler/compiler/lib/Analysis/CMakeLists.txt
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,9 @@ | ||
add_mlir_library( | ||
AnalysisUtils | ||
Utils.cpp | ||
DEPENDS | ||
mlir-headers | ||
LINK_LIBS | ||
PUBLIC | ||
MLIRIR | ||
) |
67 changes: 67 additions & 0 deletions
67
compilers/concrete-compiler/compiler/lib/Analysis/Utils.cpp
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,67 @@ | ||
#include <concretelang/Analysis/Utils.h> | ||
#include <mlir/Dialect/Arith/IR/Arith.h> | ||
|
||
using ::concretelang::error::StringError; | ||
|
||
namespace mlir { | ||
namespace concretelang { | ||
std::string locationString(mlir::Location loc) { | ||
auto location = std::string(); | ||
auto locationStream = llvm::raw_string_ostream(location); | ||
loc->print(locationStream); | ||
return location; | ||
} | ||
|
||
int64_t calculateNumberOfIterations(int64_t start, int64_t stop, int64_t step) { | ||
int64_t high; | ||
int64_t low; | ||
|
||
if (step > 0) { | ||
low = start; | ||
high = stop; | ||
} else { | ||
low = stop; | ||
high = start; | ||
step = -step; | ||
} | ||
|
||
if (low >= high) { | ||
return 0; | ||
} | ||
|
||
return ((high - low - 1) / step) + 1; | ||
} | ||
|
||
outcome::checked<int64_t, StringError> | ||
calculateNumberOfIterations(scf::ForOp &op) { | ||
mlir::Value startValue = op.getLowerBound(); | ||
mlir::Value stopValue = op.getUpperBound(); | ||
mlir::Value stepValue = op.getStep(); | ||
|
||
auto startOp = | ||
llvm::dyn_cast_or_null<arith::ConstantOp>(startValue.getDefiningOp()); | ||
auto stopOp = | ||
llvm::dyn_cast_or_null<arith::ConstantOp>(stopValue.getDefiningOp()); | ||
auto stepOp = | ||
llvm::dyn_cast_or_null<arith::ConstantOp>(stepValue.getDefiningOp()); | ||
|
||
if (!startOp || !stopOp || !stepOp) { | ||
return StringError("only static loops can be analyzed"); | ||
} | ||
|
||
auto startAttr = startOp.getValue().cast<mlir::IntegerAttr>(); | ||
auto stopAttr = stopOp.getValue().cast<mlir::IntegerAttr>(); | ||
auto stepAttr = stepOp.getValue().cast<mlir::IntegerAttr>(); | ||
|
||
if (!startOp || !stopOp || !stepOp) { | ||
return StringError("only integer loops can be analyzed"); | ||
} | ||
|
||
int64_t start = startAttr.getInt(); | ||
int64_t stop = stopAttr.getInt(); | ||
int64_t step = stepAttr.getInt(); | ||
|
||
return calculateNumberOfIterations(start, stop, step); | ||
} | ||
} // namespace concretelang | ||
} // namespace mlir |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
add_subdirectory(Analysis) | ||
add_subdirectory(Dialect) | ||
add_subdirectory(Conversion) | ||
add_subdirectory(Transforms) | ||
|
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 |
---|---|---|
|
@@ -9,4 +9,5 @@ add_mlir_library( | |
LINK_LIBS | ||
PUBLIC | ||
MLIRIR | ||
ConcreteDialect) | ||
ConcreteDialect | ||
AnalysisUtils) |
Oops, something went wrong.