Skip to content

Commit d0469d1

Browse files
authored
[mlir] Move WalkResult to Support (#145649)
This also enables moving StateStack, both are relatively generic helper structs not tied to IR.
1 parent ad87d95 commit d0469d1

File tree

9 files changed

+69
-44
lines changed

9 files changed

+69
-44
lines changed

flang/lib/Lower/Bridge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
#include "mlir/IR/BuiltinAttributes.h"
6969
#include "mlir/IR/Matchers.h"
7070
#include "mlir/IR/PatternMatch.h"
71-
#include "mlir/IR/StateStack.h"
7271
#include "mlir/Parser/Parser.h"
72+
#include "mlir/Support/StateStack.h"
7373
#include "mlir/Transforms/RegionUtils.h"
7474
#include "llvm/ADT/SmallVector.h"
7575
#include "llvm/ADT/StringSet.h"

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include "flang/Support/OpenMP-utils.h"
4040
#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
4141
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
42-
#include "mlir/IR/StateStack.h"
42+
#include "mlir/Support/StateStack.h"
4343
#include "mlir/Transforms/RegionUtils.h"
4444
#include "llvm/ADT/STLExtras.h"
4545
#include "llvm/Frontend/OpenMP/OMPConstants.h"

mlir/include/mlir/IR/Visitors.h

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define MLIR_IR_VISITORS_H
1515

1616
#include "mlir/Support/LLVM.h"
17+
#include "mlir/Support/WalkResult.h"
1718
#include "llvm/ADT/STLExtras.h"
1819

1920
namespace mlir {
@@ -23,41 +24,6 @@ class Operation;
2324
class Block;
2425
class Region;
2526

26-
/// A utility result that is used to signal how to proceed with an ongoing walk:
27-
/// * Interrupt: the walk will be interrupted and no more operations, regions
28-
/// or blocks will be visited.
29-
/// * Advance: the walk will continue.
30-
/// * Skip: the walk of the current operation, region or block and their
31-
/// nested elements that haven't been visited already will be skipped and will
32-
/// continue with the next operation, region or block.
33-
class WalkResult {
34-
enum ResultEnum { Interrupt, Advance, Skip } result;
35-
36-
public:
37-
WalkResult(ResultEnum result = Advance) : result(result) {}
38-
39-
/// Allow LogicalResult to interrupt the walk on failure.
40-
WalkResult(LogicalResult result)
41-
: result(failed(result) ? Interrupt : Advance) {}
42-
43-
/// Allow diagnostics to interrupt the walk.
44-
WalkResult(Diagnostic &&) : result(Interrupt) {}
45-
WalkResult(InFlightDiagnostic &&) : result(Interrupt) {}
46-
47-
bool operator==(const WalkResult &rhs) const { return result == rhs.result; }
48-
bool operator!=(const WalkResult &rhs) const { return result != rhs.result; }
49-
50-
static WalkResult interrupt() { return {Interrupt}; }
51-
static WalkResult advance() { return {Advance}; }
52-
static WalkResult skip() { return {Skip}; }
53-
54-
/// Returns true if the walk was interrupted.
55-
bool wasInterrupted() const { return result == Interrupt; }
56-
57-
/// Returns true if the walk was skipped.
58-
bool wasSkipped() const { return result == Skip; }
59-
};
60-
6127
/// Traversal order for region, block and operation walk utilities.
6228
enum class WalkOrder { PreOrder, PostOrder };
6329

mlir/include/mlir/IR/StateStack.h renamed to mlir/include/mlir/Support/StateStack.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#ifndef MLIR_IR_STACKFRAME_H
16-
#define MLIR_IR_STACKFRAME_H
15+
#ifndef MLIR_SUPPORT_STACKFRAME_H
16+
#define MLIR_SUPPORT_STACKFRAME_H
1717

18-
#include "mlir/IR/Visitors.h"
1918
#include "mlir/Support/TypeID.h"
19+
#include "mlir/Support/WalkResult.h"
2020
#include <memory>
2121

2222
namespace mlir {
@@ -125,4 +125,4 @@ struct isa_impl<T, ::mlir::StateStackFrame> {
125125
};
126126
} // namespace llvm
127127

128-
#endif // MLIR_IR_STACKFRAME_H
128+
#endif // MLIR_SUPPORT_STACKFRAME_H
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//===- WalkResult.h - Status of completed walk ------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// Result kind for completed walk.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef MLIR_SUPPORT_WALKRESULT_H
14+
#define MLIR_SUPPORT_WALKRESULT_H
15+
16+
#include "mlir/Support/LLVM.h"
17+
18+
namespace mlir {
19+
class Diagnostic;
20+
class InFlightDiagnostic;
21+
22+
/// A utility result that is used to signal how to proceed with an ongoing walk:
23+
/// * Interrupt: the walk will be interrupted and no more operations, regions
24+
/// or blocks will be visited.
25+
/// * Advance: the walk will continue.
26+
/// * Skip: the walk of the current operation, region or block and their
27+
/// nested elements that haven't been visited already will be skipped and will
28+
/// continue with the next operation, region or block.
29+
class WalkResult {
30+
enum ResultEnum { Interrupt, Advance, Skip } result;
31+
32+
public:
33+
WalkResult(ResultEnum result = Advance) : result(result) {}
34+
35+
/// Allow LogicalResult to interrupt the walk on failure.
36+
WalkResult(LogicalResult result)
37+
: result(failed(result) ? Interrupt : Advance) {}
38+
39+
/// Allow diagnostics to interrupt the walk.
40+
WalkResult(Diagnostic &&) : result(Interrupt) {}
41+
WalkResult(InFlightDiagnostic &&) : result(Interrupt) {}
42+
43+
bool operator==(const WalkResult &rhs) const { return result == rhs.result; }
44+
bool operator!=(const WalkResult &rhs) const { return result != rhs.result; }
45+
46+
static WalkResult interrupt() { return {Interrupt}; }
47+
static WalkResult advance() { return {Advance}; }
48+
static WalkResult skip() { return {Skip}; }
49+
50+
/// Returns true if the walk was interrupted.
51+
bool wasInterrupted() const { return result == Interrupt; }
52+
53+
/// Returns true if the walk was skipped.
54+
bool wasSkipped() const { return result == Skip; }
55+
};
56+
57+
} // namespace mlir
58+
59+
#endif

mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
#include "mlir/Dialect/LLVMIR/LLVMInterfaces.h"
1818
#include "mlir/IR/Operation.h"
19-
#include "mlir/IR/StateStack.h"
2019
#include "mlir/IR/SymbolTable.h"
2120
#include "mlir/IR/Value.h"
21+
#include "mlir/Support/StateStack.h"
2222
#include "mlir/Target/LLVMIR/Export.h"
2323
#include "mlir/Target/LLVMIR/LLVMTranslationInterface.h"
2424
#include "mlir/Target/LLVMIR/TypeToLLVM.h"

mlir/lib/IR/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ add_mlir_library(MLIRIR
3232
PatternMatch.cpp
3333
Region.cpp
3434
RegionKindInterface.cpp
35-
StateStack.cpp
3635
SymbolTable.cpp
3736
TensorEncoding.cpp
3837
Types.cpp

mlir/lib/Support/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ add_mlir_library(MLIRSupport
1111
FileUtilities.cpp
1212
InterfaceSupport.cpp
1313
RawOstreamExtras.cpp
14+
StateStack.cpp
1415
StorageUniquer.cpp
1516
Timing.cpp
1617
ToolUtilities.cpp

mlir/lib/IR/StateStack.cpp renamed to mlir/lib/Support/StateStack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "mlir/IR/StateStack.h"
9+
#include "mlir/Support/StateStack.h"
1010

1111
namespace mlir {
1212

0 commit comments

Comments
 (0)