Skip to content

Commit 1b221cd

Browse files
authored
Integrate LLVM at 3ca2a5fc0b84762f0e7d8a0e613fd69f7e344219 (#4435)
Integrate llvm at 3ca2a5fc0b84762f0e7d8a0e613fd69f7e344219 This includes the **RegionBranchOpInterface** related changes from llvm/llvm-project#175815
1 parent 4411053 commit 1b221cd

3 files changed

Lines changed: 27 additions & 10 deletions

File tree

externals/llvm-project

Submodule llvm-project updated 6783 files

include/torch-mlir/Dialect/Torch/IR/TorchOps.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ def Torch_PrimCallMethodOp : Torch_Op<"prim.CallMethod", []> {
507507
}
508508

509509
def Torch_PrimLoopOp : Torch_Op<"prim.Loop", [
510-
DeclareOpInterfaceMethods<RegionBranchOpInterface, ["getEntrySuccessorOperands"]>]> {
510+
DeclareOpInterfaceMethods<RegionBranchOpInterface, ["getEntrySuccessorOperands", "getSuccessorInputs"]>]> {
511511
let summary = "TorchScript prim::Loop op";
512512
let description = [{
513513
This op (together with prim.Loop.condition) define a looping construct
@@ -559,7 +559,7 @@ def Torch_PrimLoopConditionOp : Torch_Op<"prim.Loop.condition", [
559559
}
560560

561561
def Torch_PrimIfOp : Torch_Op<"prim.If", [
562-
DeclareOpInterfaceMethods<RegionBranchOpInterface>]> {
562+
DeclareOpInterfaceMethods<RegionBranchOpInterface, ["getSuccessorInputs"]>]> {
563563
let summary = "TorchScript prim::If op";
564564
let description = [{
565565
This op (together with prim.If.yield) define a conditional control flow
@@ -1183,7 +1183,7 @@ def Torch_RuntimeAssertOp: Torch_Op<"runtime.assert", [
11831183
//===----------------------------------------------------------------------===//
11841184

11851185
def Torch_ShapeCalculateOp : Torch_Op<"shape.calculate", [
1186-
DeclareOpInterfaceMethods<RegionBranchOpInterface>]> {
1186+
DeclareOpInterfaceMethods<RegionBranchOpInterface, ["getSuccessorInputs"]>]> {
11871187
let summary = "Shape calculation encapsulation op";
11881188
let description = [{
11891189
The `torch.shape.calculate` op captures a shape calculation
@@ -1263,7 +1263,7 @@ def Torch_ShapeCalculateYieldShapesOp : Torch_Op<"shape.calculate.yield.shapes",
12631263
//===----------------------------------------------------------------------===//
12641264

12651265
def Torch_DtypeCalculateOp : Torch_Op<"dtype.calculate", [
1266-
DeclareOpInterfaceMethods<RegionBranchOpInterface>]> {
1266+
DeclareOpInterfaceMethods<RegionBranchOpInterface, ["getSuccessorInputs"]>]> {
12671267
let summary = "Dtype calculation encapsulation op";
12681268
let description = [{
12691269
The `torch.dtype.calculate` op captures a dtype calculation

lib/Dialect/Torch/IR/TorchOps.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,17 @@ void PrimLoopOp::getSuccessorRegions(
423423
RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> &regions) {
424424
Region &region = getRegion();
425425
if (!point.getTerminatorPredecessorOrNull()) {
426-
regions.emplace_back(&region, region.getArguments().slice(1));
426+
regions.emplace_back(&region);
427427
return;
428428
}
429429
assert(point.getTerminatorPredecessorOrNull()->getParentRegion() == &region);
430-
regions.emplace_back(&region, region.getArguments().slice(1));
431-
regions.emplace_back(getOperation(), getResults());
430+
regions.emplace_back(&region);
431+
regions.emplace_back(RegionSuccessor::parent());
432+
}
433+
434+
ValueRange PrimLoopOp::getSuccessorInputs(RegionSuccessor successor) {
435+
return successor.isParent() ? ValueRange(getResults())
436+
: ValueRange(getRegion().getArguments().slice(1));
432437
}
433438

434439
bool PrimLoopOp::isForLike() {
@@ -494,7 +499,7 @@ void PrimIfOp::getSuccessorRegions(RegionBranchPoint point,
494499
SmallVectorImpl<RegionSuccessor> &regions) {
495500
// The `then` and the `else` region branch back to the parent operation.
496501
if (point.getTerminatorPredecessorOrNull()) {
497-
regions.push_back(RegionSuccessor(getOperation(), getResults()));
502+
regions.push_back(RegionSuccessor::parent());
498503
return;
499504
}
500505

@@ -512,6 +517,10 @@ void PrimIfOp::getSuccessorRegions(RegionBranchPoint point,
512517
return;
513518
}
514519

520+
ValueRange PrimIfOp::getSuccessorInputs(RegionSuccessor successor) {
521+
return successor.isParent() ? ValueRange(getResults()) : ValueRange();
522+
}
523+
515524
/// Replaces the given op with the contents of the given single-block region,
516525
/// using the operands of the block terminator to replace operation results.
517526
static void replaceOpWithRegion(PatternRewriter &rewriter, Operation *op,
@@ -5376,7 +5385,7 @@ getSuccessorRegionsForCalculateOp(CalculateOp op, RegionBranchPoint point,
53765385
Region *region = point.getTerminatorPredecessorOrNull()->getParentRegion();
53775386
if (region == &op.getBody()) {
53785387
// Body returns control to the outer op, passing through results.
5379-
regions.emplace_back(op.getOperation(), op.getResults());
5388+
regions.emplace_back(RegionSuccessor::parent());
53805389
return;
53815390
}
53825391
assert(region == &op.getCalculation());
@@ -5389,6 +5398,10 @@ void ShapeCalculateOp::getSuccessorRegions(
53895398
getSuccessorRegionsForCalculateOp(*this, point, regions);
53905399
}
53915400

5401+
ValueRange ShapeCalculateOp::getSuccessorInputs(RegionSuccessor successor) {
5402+
return successor.isParent() ? ValueRange(getResults()) : ValueRange();
5403+
}
5404+
53925405
//===----------------------------------------------------------------------===//
53935406
// DtypeCalculateOp
53945407
//===----------------------------------------------------------------------===//
@@ -5398,6 +5411,10 @@ void DtypeCalculateOp::getSuccessorRegions(
53985411
getSuccessorRegionsForCalculateOp(*this, point, regions);
53995412
}
54005413

5414+
ValueRange DtypeCalculateOp::getSuccessorInputs(RegionSuccessor successor) {
5415+
return successor.isParent() ? ValueRange(getResults()) : ValueRange();
5416+
}
5417+
54015418
//===----------------------------------------------------------------------===//
54025419
// ShapeCalculateYieldShapesOp
54035420
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)