Skip to content

Commit 03112b7

Browse files
committed
Update on "[CIR][IR] Refactor for loops"
This patch completes the deprecation of the generic `cir.loop` operation by adding a new `cir.for` operation and removing the `cir.loop` op. The new representation removes some bloat and places the regions in order of execution. [ghstack-poisoned]
2 parents eaa7f6b + a3e92f7 commit 03112b7

File tree

14 files changed

+29
-19
lines changed

14 files changed

+29
-19
lines changed

clang/include/clang/CIR/Dialect/IR/CIRDialect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
#include "clang/CIR/Interfaces/ASTAttrInterfaces.h"
3535
#include "clang/CIR/Interfaces/CIROpInterfaces.h"
36-
#include "clang/CIR/Interfaces/LoopOpInterface.h"
36+
#include "clang/CIR/Interfaces/CIRLoopOpInterface.h"
3737

3838
namespace mlir {
3939
namespace OpTrait {

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ include "clang/CIR/Dialect/IR/CIRAttrs.td"
2020

2121
include "clang/CIR/Interfaces/ASTAttrInterfaces.td"
2222
include "clang/CIR/Interfaces/CIROpInterfaces.td"
23-
include "clang/CIR/Interfaces/LoopOpInterface.td"
23+
include "clang/CIR/Interfaces/CIRLoopOpInterface.td"
2424

2525
include "mlir/Interfaces/ControlFlowInterfaces.td"
2626
include "mlir/Interfaces/FunctionInterfaces.td"

clang/include/clang/CIR/Interfaces/LoopOpInterface.h renamed to clang/include/clang/CIR/Interfaces/CIRLoopOpInterface.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- LoopOpInterface.h - Interface for CIR loop-like ops -----*- C++ -*-===//
1+
//===- CIRLoopOpInterface.h - Interface for CIR loop-like ops --*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -10,8 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef CLANG_INTERFACES_CIR_LOOPOPINTERFACE_H_
14-
#define CLANG_INTERFACES_CIR_LOOPOPINTERFACE_H_
13+
#ifndef CLANG_INTERFACES_CIR_CIRLOOPOPINTERFACE_H_
14+
#define CLANG_INTERFACES_CIR_CIRLOOPOPINTERFACE_H_
1515

1616
#include "mlir/IR/BuiltinTypes.h"
1717
#include "mlir/IR/OpDefinition.h"
@@ -31,6 +31,6 @@ ::mlir::LogicalResult verifyLoopOpInterface(::mlir::Operation *op);
3131
} // namespace mlir
3232

3333
/// Include the tablegen'd interface declarations.
34-
#include "clang/CIR/Interfaces/LoopOpInterface.h.inc"
34+
#include "clang/CIR/Interfaces/CIRLoopOpInterface.h.inc"
3535

36-
#endif // CLANG_INTERFACES_CIR_LOOPOPINTERFACE_H_
36+
#endif // CLANG_INTERFACES_CIR_CIRLOOPOPINTERFACE_H_

clang/include/clang/CIR/Interfaces/LoopOpInterface.td renamed to clang/include/clang/CIR/Interfaces/CIRLoopOpInterface.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
//===- LoopOpInterface.td - Interface for CIR loop-like ops ----*- C++ -*-===//
1+
//===- CIRLoopOpInterface.td - Interface for CIR loop-like ops -*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===---------------------------------------------------------------------===//
88

9-
#ifndef CLANG_CIR_INTERFACES_LOOPOPINTERFACE
10-
#define CLANG_CIR_INTERFACES_LOOPOPINTERFACE
9+
#ifndef CLANG_CIR_INTERFACES_CIRLOOPOPINTERFACE
10+
#define CLANG_CIR_INTERFACES_CIRLOOPOPINTERFACE
1111

1212
include "mlir/IR/OpBase.td"
1313
include "mlir/Interfaces/ControlFlowInterfaces.td"
@@ -97,4 +97,4 @@ def LoopOpInterface : OpInterface<"LoopOpInterface", [
9797
}];
9898
}
9999
100-
#endif // CLANG_CIR_INTERFACES_LOOPOPINTERFACE
100+
#endif // CLANG_CIR_INTERFACES_CIRLOOPOPINTERFACE

clang/include/clang/CIR/Interfaces/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ endfunction()
2222

2323
add_clang_mlir_attr_interface(ASTAttrInterfaces)
2424
add_clang_mlir_op_interface(CIROpInterfaces)
25-
add_clang_mlir_op_interface(LoopOpInterface)
25+
add_clang_mlir_op_interface(CIRLoopOpInterface)

clang/lib/CIR/CodeGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ add_clang_library(clangCIR
4141
MLIRCIROpsIncGen
4242
MLIRCIRASTAttrInterfacesIncGen
4343
MLIRCIROpInterfacesIncGen
44+
MLIRCIRLoopOpInterfaceIncGen
4445
${dialect_libs}
4546

4647
LINK_LIBS

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "clang/CIR/Dialect/IR/CIRAttrs.h"
1515
#include "clang/CIR/Dialect/IR/CIROpsEnums.h"
1616
#include "clang/CIR/Dialect/IR/CIRTypes.h"
17-
#include "clang/CIR/Interfaces/LoopOpInterface.h"
17+
#include "clang/CIR/Interfaces/CIRLoopOpInterface.h"
1818
#include "llvm/Support/ErrorHandling.h"
1919
#include <optional>
2020

clang/lib/CIR/Dialect/IR/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ add_clang_library(MLIRCIR
1111
MLIRSymbolInterfacesIncGen
1212
MLIRCIRASTAttrInterfacesIncGen
1313
MLIRCIROpInterfacesIncGen
14+
MLIRCIRLoopOpInterfaceIncGen
1415

1516
LINK_LIBS PUBLIC
1617
MLIRIR

clang/lib/CIR/Dialect/Transforms/LifetimeCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "clang/CIR/Dialect/IR/CIRDialect.h"
1717
#include "clang/CIR/Dialect/Passes.h"
1818

19-
#include "clang/CIR/Interfaces/LoopOpInterface.h"
19+
#include "clang/CIR/Interfaces/CIRLoopOpInterface.h"
2020
#include "llvm/ADT/SetOperations.h"
2121
#include "llvm/ADT/SmallSet.h"
2222

clang/lib/CIR/FrontendAction/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ add_clang_library(clangCIRFrontendAction
1212
MLIRCIROpsIncGen
1313
MLIRCIRASTAttrInterfacesIncGen
1414
MLIRCIROpInterfacesIncGen
15+
MLIRCIRLoopOpInterfaceIncGen
1516
MLIRBuiltinLocationAttributesIncGen
1617
MLIRBuiltinTypeInterfacesIncGen
1718
MLIRFunctionInterfacesIncGen

clang/lib/CIR/Interfaces/LoopOpInterface.cpp renamed to clang/lib/CIR/Interfaces/CIRLoopOpInterface.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
//===- LoopOpInterface.cpp - Interface for CIR loop-like ops ---*- C++ -*-===//
1+
//===- CIRLoopOpInterface.cpp - Interface for CIR loop-like ops *- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===---------------------------------------------------------------------===//
88

9-
#include "clang/CIR/Interfaces/LoopOpInterface.h"
9+
#include "clang/CIR/Interfaces/CIRLoopOpInterface.h"
1010

1111
#include "clang/CIR/Dialect/IR/CIRDialect.h"
12-
#include "clang/CIR/Interfaces/LoopOpInterface.cpp.inc"
12+
#include "clang/CIR/Interfaces/CIRLoopOpInterface.cpp.inc"
13+
#include "llvm/Support/ErrorHandling.h"
1314

1415
namespace mlir {
1516
namespace cir {
@@ -28,14 +29,17 @@ void LoopOpInterface::getLoopOpSuccessorRegions(
2829
regions.emplace_back(RegionSuccessor(op->getResults()));
2930
regions.emplace_back(&op.getBody(), op.getBody().getArguments());
3031
}
31-
// Branching from body: go to step (for) or condition (while).
32+
// Branching from body: go to step (for) or condition.
3233
else if (&op.getBody() == point.getRegionOrNull()) {
34+
// FIXME(cir): Should we consider break/continue statements here?
3335
auto *afterBody = (op.maybeGetStep() ? op.maybeGetStep() : &op.getCond());
3436
regions.emplace_back(afterBody, afterBody->getArguments());
3537
}
3638
// Branching from step: go to condition.
3739
else if (op.maybeGetStep() == point.getRegionOrNull()) {
3840
regions.emplace_back(&op.getCond(), op.getCond().getArguments());
41+
} else {
42+
llvm_unreachable("unexpected branch origin");
3943
}
4044
}
4145

clang/lib/CIR/Interfaces/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
add_clang_library(MLIRCIRInterfaces
22
ASTAttrInterfaces.cpp
33
CIROpInterfaces.cpp
4-
LoopOpInterface.cpp
4+
CIRLoopOpInterface.cpp
55

66
ADDITIONAL_HEADER_DIRS
77
${MLIR_MAIN_INCLUDE_DIR}/mlir/Interfaces
88

99
DEPENDS
1010
MLIRCIRASTAttrInterfacesIncGen
1111
MLIRCIROpInterfacesIncGen
12+
MLIRCIRLoopOpInterfaceIncGen
1213

1314
LINK_LIBS
1415
${dialect_libs}

clang/lib/CIR/Lowering/DirectToLLVM/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ add_clang_library(clangCIRLoweringDirectToLLVM
1414
MLIRCIROpsIncGen
1515
MLIRCIRASTAttrInterfacesIncGen
1616
MLIRCIROpInterfacesIncGen
17+
MLIRCIRLoopOpInterfaceIncGen
1718
MLIRBuiltinLocationAttributesIncGen
1819
MLIRBuiltinTypeInterfacesIncGen
1920
MLIRFunctionInterfacesIncGen

clang/lib/CIR/Lowering/ThroughMLIR/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ add_clang_library(clangCIRLoweringThroughMLIR
1414
MLIRCIREnumsGen
1515
MLIRCIRASTAttrInterfacesIncGen
1616
MLIRCIROpInterfacesIncGen
17+
MLIRCIRLoopOpInterfaceIncGen
1718
MLIRBuiltinLocationAttributesIncGen
1819
MLIRBuiltinTypeInterfacesIncGen
1920
MLIRFunctionInterfacesIncGen

0 commit comments

Comments
 (0)