22
33#include " larq_compute_engine/core/bitpacking/bitpack.h"
44#include " larq_compute_engine/mlir/ir/lce_ops.h"
5+ #include " larq_compute_engine/mlir/transforms/common.h"
56#include " larq_compute_engine/mlir/transforms/passes.h"
67#include " llvm/ADT/Optional.h"
78#include " llvm/ADT/STLExtras.h"
1617namespace mlir {
1718namespace TFL {
1819
19- namespace {
20-
2120// Optimize LCE operations in functions.
2221struct OptimizeLCE
2322 : public PassWrapper<OptimizeLCE, OperationPass<mlir::func::FuncOp>> {
@@ -38,15 +37,6 @@ struct OptimizeLCE
3837 clEnumValN (LCETarget::XCORE, " xcore" , " XCORE target" ))};
3938};
4039
41- bool IsConstantValue (Attribute values, float expected_value) {
42- if (!values.isa <DenseElementsAttr>()) return false ;
43-
44- for (auto value : values.cast <DenseElementsAttr>().getValues <float >()) {
45- if (value != expected_value) return false ;
46- }
47- return true ;
48- }
49-
5040/* *
5141 * =================================================
5242 * Computing thresholds for writing bitpacked output
@@ -254,15 +244,15 @@ DenseElementsAttr GetBitpackedOutputThresholds(
254244 return DenseElementsAttr::get (type, thresholds);
255245}
256246
257- namespace target_arm {
247+ namespace optimize_target_arm {
258248#include " larq_compute_engine/mlir/transforms/generated_optimize_target_arm.inc"
259249}
260250
261- namespace target_other {
251+ namespace optimize_target_other {
262252#include " larq_compute_engine/mlir/transforms/generated_optimize_target_other.inc"
263253}
264254
265- namespace bitpack_activations {
255+ namespace optimize_bitpack_activations {
266256#include " larq_compute_engine/mlir/transforms/generated_bitpack_activations.inc"
267257}
268258
@@ -271,17 +261,15 @@ void OptimizeLCE::runOnOperation() {
271261 auto func = getOperation ();
272262
273263 if (target_ == LCETarget::ARM) {
274- target_arm ::populateWithGenerated (patterns);
264+ optimize_target_arm ::populateWithGenerated (patterns);
275265 } else {
276- target_other ::populateWithGenerated (patterns);
266+ optimize_target_other ::populateWithGenerated (patterns);
277267 }
278- bitpack_activations ::populateWithGenerated (patterns);
268+ optimize_bitpack_activations ::populateWithGenerated (patterns);
279269
280270 (void )applyPatternsAndFoldGreedily (func, std::move (patterns));
281271}
282272
283- } // namespace
284-
285273// Creates an instance of the TensorFlow dialect OptimizeLCE pass.
286274std::unique_ptr<OperationPass<mlir::func::FuncOp>> CreateOptimizeLCEPass (
287275 const LCETarget target) {
0 commit comments