Skip to content

Commit

Permalink
Update on "[CIR][IR] Refactor for loops"
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
sitio-couto committed Jan 20, 2024
2 parents eaa7f6b + a3e92f7 commit 03112b7
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/CIR/Dialect/IR/CIRDialect.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#include "clang/CIR/Interfaces/ASTAttrInterfaces.h"
#include "clang/CIR/Interfaces/CIROpInterfaces.h"
#include "clang/CIR/Interfaces/LoopOpInterface.h"
#include "clang/CIR/Interfaces/CIRLoopOpInterface.h"

namespace mlir {
namespace OpTrait {
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ include "clang/CIR/Dialect/IR/CIRAttrs.td"

include "clang/CIR/Interfaces/ASTAttrInterfaces.td"
include "clang/CIR/Interfaces/CIROpInterfaces.td"
include "clang/CIR/Interfaces/LoopOpInterface.td"
include "clang/CIR/Interfaces/CIRLoopOpInterface.td"

include "mlir/Interfaces/ControlFlowInterfaces.td"
include "mlir/Interfaces/FunctionInterfaces.td"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===- LoopOpInterface.h - Interface for CIR loop-like ops -----*- C++ -*-===//
//===- CIRLoopOpInterface.h - Interface for CIR loop-like ops --*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -10,8 +10,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef CLANG_INTERFACES_CIR_LOOPOPINTERFACE_H_
#define CLANG_INTERFACES_CIR_LOOPOPINTERFACE_H_
#ifndef CLANG_INTERFACES_CIR_CIRLOOPOPINTERFACE_H_
#define CLANG_INTERFACES_CIR_CIRLOOPOPINTERFACE_H_

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

/// Include the tablegen'd interface declarations.
#include "clang/CIR/Interfaces/LoopOpInterface.h.inc"
#include "clang/CIR/Interfaces/CIRLoopOpInterface.h.inc"

#endif // CLANG_INTERFACES_CIR_LOOPOPINTERFACE_H_
#endif // CLANG_INTERFACES_CIR_CIRLOOPOPINTERFACE_H_
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//===- LoopOpInterface.td - Interface for CIR loop-like ops ----*- C++ -*-===//
//===- CIRLoopOpInterface.td - Interface for CIR loop-like ops -*- C++ -*-===//
//
// 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_LOOPOPINTERFACE
#define CLANG_CIR_INTERFACES_LOOPOPINTERFACE
#ifndef CLANG_CIR_INTERFACES_CIRLOOPOPINTERFACE
#define CLANG_CIR_INTERFACES_CIRLOOPOPINTERFACE

include "mlir/IR/OpBase.td"
include "mlir/Interfaces/ControlFlowInterfaces.td"
Expand Down Expand Up @@ -97,4 +97,4 @@ def LoopOpInterface : OpInterface<"LoopOpInterface", [
}];
}
#endif // CLANG_CIR_INTERFACES_LOOPOPINTERFACE
#endif // CLANG_CIR_INTERFACES_CIRLOOPOPINTERFACE
2 changes: 1 addition & 1 deletion clang/include/clang/CIR/Interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ endfunction()

add_clang_mlir_attr_interface(ASTAttrInterfaces)
add_clang_mlir_op_interface(CIROpInterfaces)
add_clang_mlir_op_interface(LoopOpInterface)
add_clang_mlir_op_interface(CIRLoopOpInterface)
1 change: 1 addition & 0 deletions clang/lib/CIR/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ add_clang_library(clangCIR
MLIRCIROpsIncGen
MLIRCIRASTAttrInterfacesIncGen
MLIRCIROpInterfacesIncGen
MLIRCIRLoopOpInterfaceIncGen
${dialect_libs}

LINK_LIBS
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "clang/CIR/Dialect/IR/CIRAttrs.h"
#include "clang/CIR/Dialect/IR/CIROpsEnums.h"
#include "clang/CIR/Dialect/IR/CIRTypes.h"
#include "clang/CIR/Interfaces/LoopOpInterface.h"
#include "clang/CIR/Interfaces/CIRLoopOpInterface.h"
#include "llvm/Support/ErrorHandling.h"
#include <optional>

Expand Down
1 change: 1 addition & 0 deletions clang/lib/CIR/Dialect/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ add_clang_library(MLIRCIR
MLIRSymbolInterfacesIncGen
MLIRCIRASTAttrInterfacesIncGen
MLIRCIROpInterfacesIncGen
MLIRCIRLoopOpInterfaceIncGen

LINK_LIBS PUBLIC
MLIRIR
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/Dialect/Transforms/LifetimeCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "clang/CIR/Dialect/IR/CIRDialect.h"
#include "clang/CIR/Dialect/Passes.h"

#include "clang/CIR/Interfaces/LoopOpInterface.h"
#include "clang/CIR/Interfaces/CIRLoopOpInterface.h"
#include "llvm/ADT/SetOperations.h"
#include "llvm/ADT/SmallSet.h"

Expand Down
1 change: 1 addition & 0 deletions clang/lib/CIR/FrontendAction/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ add_clang_library(clangCIRFrontendAction
MLIRCIROpsIncGen
MLIRCIRASTAttrInterfacesIncGen
MLIRCIROpInterfacesIncGen
MLIRCIRLoopOpInterfaceIncGen
MLIRBuiltinLocationAttributesIncGen
MLIRBuiltinTypeInterfacesIncGen
MLIRFunctionInterfacesIncGen
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
//===- LoopOpInterface.cpp - Interface for CIR loop-like ops ---*- C++ -*-===//
//===- CIRLoopOpInterface.cpp - Interface for CIR loop-like ops *- C++ -*-===//
//
// 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
//
//===---------------------------------------------------------------------===//

#include "clang/CIR/Interfaces/LoopOpInterface.h"
#include "clang/CIR/Interfaces/CIRLoopOpInterface.h"

#include "clang/CIR/Dialect/IR/CIRDialect.h"
#include "clang/CIR/Interfaces/LoopOpInterface.cpp.inc"
#include "clang/CIR/Interfaces/CIRLoopOpInterface.cpp.inc"
#include "llvm/Support/ErrorHandling.h"

namespace mlir {
namespace cir {
Expand All @@ -28,14 +29,17 @@ void LoopOpInterface::getLoopOpSuccessorRegions(
regions.emplace_back(RegionSuccessor(op->getResults()));
regions.emplace_back(&op.getBody(), op.getBody().getArguments());
}
// Branching from body: go to step (for) or condition (while).
// Branching from body: go to step (for) or condition.
else if (&op.getBody() == point.getRegionOrNull()) {
// FIXME(cir): Should we consider break/continue statements here?
auto *afterBody = (op.maybeGetStep() ? op.maybeGetStep() : &op.getCond());
regions.emplace_back(afterBody, afterBody->getArguments());
}
// Branching from step: go to condition.
else if (op.maybeGetStep() == point.getRegionOrNull()) {
regions.emplace_back(&op.getCond(), op.getCond().getArguments());
} else {
llvm_unreachable("unexpected branch origin");
}
}

Expand Down
3 changes: 2 additions & 1 deletion clang/lib/CIR/Interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
add_clang_library(MLIRCIRInterfaces
ASTAttrInterfaces.cpp
CIROpInterfaces.cpp
LoopOpInterface.cpp
CIRLoopOpInterface.cpp

ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Interfaces

DEPENDS
MLIRCIRASTAttrInterfacesIncGen
MLIRCIROpInterfacesIncGen
MLIRCIRLoopOpInterfaceIncGen

LINK_LIBS
${dialect_libs}
Expand Down
1 change: 1 addition & 0 deletions clang/lib/CIR/Lowering/DirectToLLVM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ add_clang_library(clangCIRLoweringDirectToLLVM
MLIRCIROpsIncGen
MLIRCIRASTAttrInterfacesIncGen
MLIRCIROpInterfacesIncGen
MLIRCIRLoopOpInterfaceIncGen
MLIRBuiltinLocationAttributesIncGen
MLIRBuiltinTypeInterfacesIncGen
MLIRFunctionInterfacesIncGen
Expand Down
1 change: 1 addition & 0 deletions clang/lib/CIR/Lowering/ThroughMLIR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ add_clang_library(clangCIRLoweringThroughMLIR
MLIRCIREnumsGen
MLIRCIRASTAttrInterfacesIncGen
MLIRCIROpInterfacesIncGen
MLIRCIRLoopOpInterfaceIncGen
MLIRBuiltinLocationAttributesIncGen
MLIRBuiltinTypeInterfacesIncGen
MLIRFunctionInterfacesIncGen
Expand Down

0 comments on commit 03112b7

Please sign in to comment.