Skip to content

Commit

Permalink
Clean-up duplicate functions from pass dir (#2553)
Browse files Browse the repository at this point in the history
use PassUtil instead
  • Loading branch information
abhigunj committed Sep 19, 2024
1 parent 449d276 commit 376dbf3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
6 changes: 6 additions & 0 deletions stablehlo/transforms/PassUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@ Value getConstantLike(OpBuilder &b, Location loc, const APFloat &constant,
val);
}

bool isAnyQuantizedTypes(TypeRange types) {
return llvm::any_of(types, [](Type type) {
return isa<quant::QuantizedType>(getElementTypeOrSelf(type));
});
}

} // namespace stablehlo
} // namespace mlir
3 changes: 3 additions & 0 deletions stablehlo/transforms/PassUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ Value getConstantLike(OpBuilder &b, Location loc, T constant, Value val) {
Value getConstantLike(OpBuilder &b, Location loc, const APFloat &constant,
Value val);

// Check if any of the given types are mlir::quant::QuantizedType.
bool isAnyQuantizedTypes(TypeRange types);

} // namespace stablehlo
} // namespace mlir

Expand Down
7 changes: 1 addition & 6 deletions stablehlo/transforms/StablehloLegalizeQDQToQuantizedOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ limitations under the License.
#include "mlir/Transforms/DialectConversion.h" // Include for TypeConverter
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "stablehlo/dialect/StablehloOps.h"
#include "stablehlo/transforms/PassUtils.h"
#include "stablehlo/transforms/Passes.h"

namespace mlir {
Expand All @@ -31,12 +32,6 @@ namespace stablehlo {

namespace {

bool isAnyQuantizedTypes(TypeRange types) {
return llvm::any_of(types, [](Type type) {
return isa<quant::QuantizedType>(getElementTypeOrSelf(type));
});
}

struct QuantizedStablehloQDQToQuantizedOpConversion
: public OpRewritePattern<stablehlo::UniformQuantizeOp> {
using OpRewritePattern<stablehlo::UniformQuantizeOp>::OpRewritePattern;
Expand Down
7 changes: 1 addition & 6 deletions stablehlo/transforms/StablehloLegalizeQuantizedOpToQDQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ limitations under the License.
#include "mlir/Transforms/DialectConversion.h" // Include for TypeConverter
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "stablehlo/dialect/StablehloOps.h"
#include "stablehlo/transforms/PassUtils.h"
#include "stablehlo/transforms/Passes.h"

namespace mlir {
Expand All @@ -38,12 +39,6 @@ namespace stablehlo {

namespace {

bool isAnyQuantizedTypes(TypeRange types) {
return llvm::any_of(types, [](Type type) {
return isa<quant::QuantizedType>(getElementTypeOrSelf(type));
});
}

// Gets the QuantizedType associated with the given type, or returns failure if
// not quantized.
FailureOr<quant::QuantizedType> getQuantType(Type type) {
Expand Down

0 comments on commit 376dbf3

Please sign in to comment.