-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[CIR] Upstream initial for-loop support #132266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,34 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===---------------------------------------------------------------------===// | ||
// | ||
// Defines the interface to generically handle CIR loop operations. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef CLANG_CIR_INTERFACES_CIRLOOPOPINTERFACE_H | ||
#define CLANG_CIR_INTERFACES_CIRLOOPOPINTERFACE_H | ||
|
||
#include "mlir/IR/BuiltinTypes.h" | ||
#include "mlir/IR/OpDefinition.h" | ||
#include "mlir/IR/Operation.h" | ||
#include "mlir/Interfaces/ControlFlowInterfaces.h" | ||
#include "mlir/Interfaces/LoopLikeInterface.h" | ||
|
||
namespace cir { | ||
namespace detail { | ||
|
||
/// Verify invariants of the LoopOpInterface. | ||
mlir::LogicalResult verifyLoopOpInterface(::mlir::Operation *op); | ||
|
||
} // namespace detail | ||
} // namespace cir | ||
|
||
/// Include the tablegen'd interface declarations. | ||
#include "clang/CIR/Interfaces/CIRLoopOpInterface.h.inc" | ||
|
||
#endif // CLANG_CIR_INTERFACES_CIRLOOPOPINTERFACE_H |
This file contains hidden or 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,99 @@ | ||
//===---------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===---------------------------------------------------------------------===// | ||
|
||
#ifndef CLANG_CIR_INTERFACES_CIRLOOPOPINTERFACE | ||
#define CLANG_CIR_INTERFACES_CIRLOOPOPINTERFACE | ||
|
||
include "mlir/IR/OpBase.td" | ||
include "mlir/Interfaces/ControlFlowInterfaces.td" | ||
include "mlir/Interfaces/LoopLikeInterface.td" | ||
|
||
def LoopOpInterface : OpInterface<"LoopOpInterface", [ | ||
DeclareOpInterfaceMethods<RegionBranchOpInterface>, | ||
DeclareOpInterfaceMethods<LoopLikeOpInterface> | ||
]> { | ||
let description = [{ | ||
Contains helper functions to query properties and perform transformations | ||
on a loop. | ||
}]; | ||
let cppNamespace = "::cir"; | ||
|
||
let methods = [ | ||
InterfaceMethod<[{ | ||
Returns the loop's conditional region. | ||
}], | ||
/*retTy=*/"mlir::Region &", | ||
/*methodName=*/"getCond" | ||
>, | ||
InterfaceMethod<[{ | ||
Returns the loop's body region. | ||
}], | ||
/*retTy=*/"mlir::Region &", | ||
/*methodName=*/"getBody" | ||
>, | ||
InterfaceMethod<[{ | ||
Returns a pointer to the loop's step region or nullptr. | ||
}], | ||
/*retTy=*/"mlir::Region *", | ||
/*methodName=*/"maybeGetStep", | ||
/*args=*/(ins), | ||
/*methodBody=*/"", | ||
/*defaultImplementation=*/"return nullptr;" | ||
>, | ||
InterfaceMethod<[{ | ||
Returns the first region to be executed in the loop. | ||
}], | ||
/*retTy=*/"mlir::Region &", | ||
/*methodName=*/"getEntry", | ||
/*args=*/(ins), | ||
/*methodBody=*/"", | ||
/*defaultImplementation=*/"return $_op.getCond();" | ||
>, | ||
InterfaceMethod<[{ | ||
Returns a list of regions in order of execution. | ||
}], | ||
/*retTy=*/"llvm::SmallVector<mlir::Region *>", | ||
/*methodName=*/"getRegionsInExecutionOrder", | ||
/*args=*/(ins), | ||
/*methodBody=*/"", | ||
/*defaultImplementation=*/[{ | ||
return llvm::SmallVector<mlir::Region *, 2>{&$_op.getRegion(0), &$_op.getRegion(1)}; | ||
}] | ||
>, | ||
InterfaceMethod<[{ | ||
Recursively walks the body of the loop in pre-order while skipping | ||
nested loops and executing a callback on every other operation. | ||
}], | ||
/*retTy=*/"mlir::WalkResult", | ||
/*methodName=*/"walkBodySkippingNestedLoops", | ||
/*args=*/(ins "::llvm::function_ref<mlir::WalkResult (mlir::Operation *)>":$callback), | ||
/*methodBody=*/"", | ||
/*defaultImplementation=*/[{ | ||
return $_op.getBody().template walk<mlir::WalkOrder::PreOrder>([&](mlir::Operation *op) { | ||
if (mlir::isa<LoopOpInterface>(op)) | ||
return mlir::WalkResult::skip(); | ||
return callback(op); | ||
}); | ||
}] | ||
> | ||
]; | ||
|
||
let extraClassDeclaration = [{ | ||
/// Generic method to retrieve the successors of a LoopOpInterface operation. | ||
static void getLoopOpSuccessorRegions( | ||
::cir::LoopOpInterface op, ::mlir::RegionBranchPoint point, | ||
::mlir::SmallVectorImpl<::mlir::RegionSuccessor> ®ions); | ||
}]; | ||
|
||
let verify = [{ | ||
/// Verify invariants of the LoopOpInterface. | ||
return detail::verifyLoopOpInterface($_op); | ||
}]; | ||
} | ||
|
||
#endif // CLANG_CIR_INTERFACES_CIRLOOPOPINTERFACE |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentionally missing the init?
ForStmt
has an Init, Condition, Step, and Body, but this handles only 3.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an excellent question. The incubator (and this PR) emits the initialization in front of the
for
op, but it does seem like it is something we would want more tightly associated with thefor
in the emitted CIR.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initialization happens within the scope preceding the actual
cir.for
, etc. We have no intend of reproducing the AST 100% here, because of nested regions within the loop. the alloca needs to be visible and dominate everything insidecir.for
.