Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ghpvnist authored Jul 25, 2024
1 parent b056d3d commit 8555db7
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ workspace(name = "stablehlo")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

LLVM_COMMIT = "dd7d81ea49bf39e1d69bbb84bd3f31bd95519369"
LLVM_COMMIT = "84658fb82b67fc22ecba1560d0cddd09f9104178"

LLVM_SHA256 = "fbd43ef20f4209b0619e209e48c431f76008917714a8c5336063e1ff51d8d084"
LLVM_SHA256 = "b4a50d36a8ab0284f7022f61bbf07a2fb3ea25c6bb2cc422d2418c23b61366da"

http_archive(
name = "llvm-raw",
Expand Down
2 changes: 1 addition & 1 deletion build_tools/llvm_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dd7d81ea49bf39e1d69bbb84bd3f31bd95519369
84658fb82b67fc22ecba1560d0cddd09f9104178
22 changes: 15 additions & 7 deletions stablehlo/conversions/linalg/transforms/TypeConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,25 @@ std::optional<Value> materializeCastToIllegal(OpBuilder &builder, Type type,
->getResult(0);
}

std::optional<Value> scalarToTensor(OpBuilder &builder, Type /*type*/,
std::optional<Value> scalarToTensor(OpBuilder &builder, Type type,
ValueRange inputs, Location loc) {
assert(inputs.size() == 1);
if (llvm::isa<ShapedType>(inputs.front().getType())) {
if (mlir::isa<ShapedType>(inputs.front().getType())) {
return std::nullopt;
}
return builder
.create<tensor::FromElementsOp>(
loc, RankedTensorType::get({}, inputs.front().getType()),
inputs.front())
.getResult();
Value result =
builder
.create<tensor::FromElementsOp>(
loc, RankedTensorType::get({}, inputs.front().getType()),
inputs.front())
.getResult();
// Convert to a signed integer if necessary.
Type elementType = mlir::getElementTypeOrSelf(type);
if (elementType.isInteger() && !elementType.isSignlessInteger()) {
result = builder.create<UnrealizedConversionCastOp>(loc, type, result)
->getResult(0);
}
return result;
}

} // namespace
Expand Down
Binary file modified stablehlo/tests/vhlo/stablehlo_legalize_to_vhlo.0_18_0.mlir.bc
Binary file not shown.
Binary file modified stablehlo/tests/vhlo/stablehlo_legalize_to_vhlo.0_19_0.mlir.bc
Binary file not shown.
Binary file modified stablehlo/tests/vhlo/stablehlo_legalize_to_vhlo.0_20_0.mlir.bc
Binary file not shown.
Binary file modified stablehlo/tests/vhlo/stablehlo_legalize_to_vhlo.1_0_0.mlir.bc
Binary file not shown.
Binary file modified stablehlo/tests/vhlo/stablehlo_legalize_to_vhlo.1_1_0.mlir.bc
Binary file not shown.
Binary file modified stablehlo/tests/vhlo/stablehlo_legalize_to_vhlo.1_2_0.mlir.bc
Binary file not shown.
Binary file modified stablehlo/tests/vhlo/stablehlo_legalize_to_vhlo.1_3_0.mlir.bc
Binary file not shown.
Binary file modified stablehlo/tests/vhlo/stablehlo_legalize_to_vhlo.1_4_0.mlir.bc
Binary file not shown.
9 changes: 5 additions & 4 deletions stablehlo/transforms/StablehloLegalizeQuantToInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1270,12 +1270,13 @@ class ConvertGenericOp : public ConversionPattern {
OperationState state(op->getLoc(), op->getName().getStringRef(), operands,
newResultTypes, op->getAttrs(), op->getSuccessors());
for (Region &region : op->getRegions()) {
Region &newRegion = *state.addRegion();
rewriter.inlineRegionBefore(region, newRegion, newRegion.begin());
if (failed(
rewriter.convertRegionTypes(&newRegion, *getTypeConverter()))) {
auto newRegion = std::make_unique<Region>(op);
rewriter.inlineRegionBefore(region, *newRegion, newRegion->begin());
if (failed(rewriter.convertRegionTypes(newRegion.get(),
*getTypeConverter()))) {
return failure();
}
state.addRegion(std::move(newRegion));
}
Operation *newOp = rewriter.create(state);
rewriter.replaceOp(op, newOp);
Expand Down

0 comments on commit 8555db7

Please sign in to comment.