-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add stablehlo-complex-math-expander pass.
- Loading branch information
Showing
6 changed files
with
162 additions
and
0 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
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,81 @@ | ||
/* Copyright 2024 The StableHLO Authors. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
==============================================================================*/ | ||
|
||
#include <memory> | ||
#include "mlir/Dialect/Func/IR/FuncOps.h" | ||
#include "mlir/Pass/Pass.h" | ||
#include "stablehlo/dialect/ChloOps.h" | ||
#include "stablehlo/dialect/StablehloOps.h" | ||
|
||
#include "llvm/ADT/APFloat.h" | ||
#include "llvm/ADT/STLExtras.h" | ||
#include "llvm/ADT/SmallVector.h" | ||
#include "llvm/Support/ErrorHandling.h" | ||
#include "llvm/Support/MathExtras.h" | ||
#include "mlir/Dialect/Func/IR/FuncOps.h" | ||
#include "mlir/IR/Builders.h" | ||
#include "mlir/IR/BuiltinAttributes.h" | ||
#include "mlir/IR/BuiltinTypeInterfaces.h" | ||
#include "mlir/IR/BuiltinTypes.h" | ||
#include "mlir/IR/Diagnostics.h" | ||
#include "mlir/IR/PatternMatch.h" | ||
#include "mlir/Rewrite/FrozenRewritePatternSet.h" | ||
#include "mlir/Support/LLVM.h" | ||
#include "mlir/Transforms/DialectConversion.h" | ||
#include "mlir/Transforms/GreedyPatternRewriteDriver.h" | ||
#include "stablehlo/dialect/StablehloOps.h" | ||
#include "stablehlo/dialect/Version.h" | ||
#include "stablehlo/transforms/PassUtils.h" | ||
#include "stablehlo/transforms/Passes.h" | ||
|
||
namespace mlir { | ||
namespace stablehlo { | ||
#define GEN_PASS_DEF_STABLEHLOCOMPLEXMATHEXPANDERPASS | ||
#include "stablehlo/transforms/Passes.h.inc" | ||
|
||
namespace { | ||
|
||
static Value getConstantLikeInfValue(OpBuilder &b, Location loc, Value val, | ||
bool negative) { | ||
auto ty = cast<FloatType>(getElementTypeOrSelf(val.getType())); | ||
return getConstantLike( | ||
b, loc, llvm::APFloat::getInf(ty.getFloatSemantics(), negative), val); | ||
} | ||
|
||
static Value getConstantLikeMaxFiniteValue(OpBuilder &b, Location loc, | ||
Value val) { | ||
auto ty = cast<FloatType>(getElementTypeOrSelf(val.getType())); | ||
return getConstantLike( | ||
b, loc, llvm::APFloat::getLargest(ty.getFloatSemantics()), val); | ||
} | ||
|
||
static Value getConstantLikeSmallestNormalizedValue(OpBuilder &b, Location loc, | ||
Value val) { | ||
auto ty = cast<FloatType>(getElementTypeOrSelf(val.getType())); | ||
return getConstantLike( | ||
b, loc, llvm::APFloat::getSmallestNormalized(ty.getFloatSemantics()), | ||
val); | ||
} | ||
|
||
#include "stablehlo/transforms/StablehloComplexMathExpanderPatterns.h.inc" | ||
|
||
} // namespace | ||
|
||
void populateStablehloComplexMathExpanderPatterns( | ||
RewritePatternSet *patterns, MLIRContext *context/*, | ||
vhlo::Version targetVersion*/) { | ||
// StableHLO Log1pOp is introduced in v0.9.0. | ||
patterns->add<Log1pOp_ComplexElementType_ComplexMathExpander>(context); | ||
} | ||
|
||
} // namespace stablehlo | ||
} // namespace mlir |
18 changes: 18 additions & 0 deletions
18
stablehlo/transforms/StablehloComplexMathExpanderPatterns.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,18 @@ | ||
/* Copyright 2024 The StableHLO Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
==============================================================================*/ | ||
|
||
include "ChloDecompositionPatterns.td" | ||
|
||
def Log1pOp_ComplexElementType_ComplexMathExpander : Pat<(StableHLO_Log1pOp ComplexElementType:$input), (CHLO_Log1pOp $input)>; |