Skip to content

Commit 8097273

Browse files
authored
[SYCL-MLIR][NFC] Restructure Polygeist dialect (#8357)
Apply following changes to the dialect to follow MLIR dialects conventions: - Change headers locations: - Dialect definition: "mlir/Dialect/Polygeist/IR/" - Transform passes: "mlir/Dialect/Polygeist/Transforms/" - Conversion passes: "mlir/Conversion/PolygeistTo<dialect>/" - Dialect utils: "mlir/Dialect/Polygeist/Utils/<file>.h" - Create a library for each conversion pass. - Conversion passes are defined under the `mlir` namespace. This commit does not intend to be a complete refactoring of the dialect. This is a work in progress, not intending to refactor any code. --------- Signed-off-by: Victor Perez <[email protected]>
1 parent 55c95b6 commit 8097273

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+729
-576
lines changed

mlir-sycl/include/mlir/Dialect/SYCL/Transforms/Passes.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717

1818
#include "mlir/Pass/Pass.h"
1919

20-
#include "polygeist/Dialect.h"
21-
#include "polygeist/Passes/Passes.h"
20+
#include "mlir/Dialect/Polygeist/IR/Polygeist.h"
2221

2322
namespace mlir {
2423
namespace sycl {

mlir-sycl/lib/Conversion/SYCLToLLVM/SYCLToLLVM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
#include "mlir/Conversion/SYCLToLLVM/DialectBuilder.h"
1717
#include "mlir/Dialect/Func/IR/FuncOps.h"
1818
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
19+
#include "mlir/Dialect/Polygeist/Utils/Utils.h"
1920
#include "mlir/Dialect/SYCL/IR/SYCLOps.h"
2021
#include "mlir/IR/Builders.h"
2122
#include "mlir/IR/BuiltinOps.h"
2223
#include "mlir/IR/PatternMatch.h"
2324
#include "mlir/Support/LogicalResult.h"
2425
#include "mlir/Transforms/DialectConversion.h"
25-
#include "polygeist/Passes/Utils.h"
2626
#include "llvm/Support/Debug.h"
2727

2828
#define DEBUG_TYPE "sycl-to-llvm"

mlir-sycl/lib/Dialect/IR/MethodUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
#include "mlir/Dialect/Arith/IR/Arith.h"
1212
#include "mlir/Dialect/MemRef/IR/MemRef.h"
13+
#include "mlir/Dialect/Polygeist/IR/Ops.h"
1314
#include "mlir/Dialect/SYCL/IR/SYCLOps.h"
1415
#include "mlir/IR/Builders.h"
1516
#include "mlir/IR/ValueRange.h"
16-
#include "polygeist/Ops.h"
1717
#include "llvm/ADT/TypeSwitch.h"
1818

1919
#include <algorithm>

mlir-sycl/lib/Transforms/SYCLMethodToSYCLCall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "mlir/Rewrite/FrozenRewritePatternSet.h"
2525
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
2626

27-
#include "polygeist/Ops.h"
27+
#include "mlir/Dialect/Polygeist/IR/Ops.h"
2828
#include "llvm/Support/Debug.h"
2929

3030
#define DEBUG_TYPE "sycl-method-to-sycl-call"

polygeist/include/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
add_subdirectory(polygeist)
1+
add_subdirectory(mlir)

polygeist/include/mlir/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
add_subdirectory(Conversion)
2+
add_subdirectory(Dialect)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
set(LLVM_TARGET_DEFINITIONS PolygeistPasses.td)
2+
mlir_tablegen(PolygeistPasses.h.inc -gen-pass-decls -name Conversion)
3+
add_public_tablegen_target(MLIRPolygeistConversionPassIncGen)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===- PolygeistPasses.h - Conversion Pass Construction and Registration --===//
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+
#ifndef MLIR_CONVERSION_POLYGEISTPASSES_H
10+
#define MLIR_CONVERSION_POLYGEISTPASSES_H
11+
12+
#include "mlir/Conversion/PolygeistToLLVM/PolygeistToLLVMPass.h"
13+
14+
namespace mlir {
15+
namespace polygeist {
16+
/// Generate the code for registering conversion passes.
17+
#define GEN_PASS_REGISTRATION
18+
#include "mlir/Conversion/PolygeistPasses.h.inc"
19+
} // namespace polygeist
20+
} // namespace mlir
21+
22+
#endif // MLIR_CONVERSION_POLYGEISTPASSES_H
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//=== PolygeistPasses.td - Polygeist dialect passes definitions -*- tablegen =//
2+
//
3+
// This file is licensed 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+
#ifndef MLIR_CONVERSION_POLYGEISTPASSES
10+
#define MLIR_CONVERSION_POLYGEISTPASSES
11+
12+
include "mlir/Pass/PassBase.td"
13+
14+
def ConvertPolygeistToLLVM : Pass<"convert-polygeist-to-llvm", "mlir::ModuleOp"> {
15+
let summary = "Convert Polygeist dialect to LLVM dialect";
16+
let constructor = "mlir::createConvertPolygeistToLLVMPass()";
17+
let dependentDialects = ["LLVM::LLVMDialect"];
18+
let options = [
19+
Option<"useBarePtrCallConv", "use-bare-ptr-memref-call-conv", "bool",
20+
/*default=*/"false",
21+
"Replace FuncOp's MemRef arguments with bare pointers to the MemRef "
22+
"element types">,
23+
Option<"emitCWrappers", "emit-c-wrappers", "bool", /*default=*/"false",
24+
"Emit wrappers for C-compatible pointer-to-struct memref "
25+
"descriptors">,
26+
Option<"indexBitwidth", "index-bitwidth", "unsigned",
27+
/*default=kDeriveIndexBitwidthFromDataLayout*/"0",
28+
"Bitwidth of the index type, 0 to use size of machine word">,
29+
Option<"dataLayout", "data-layout", "std::string",
30+
/*default=*/"\"\"",
31+
"String description (LLVM format) of the data layout that is "
32+
"expected on the produced module">
33+
];
34+
}
35+
36+
#endif // MLIR_CONVERSION_POLYGEISTPASSES
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===- PolygeistToLLVMPass.h - Polygeist to LLVM Conversion Pass ----------===//
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+
#ifndef MLIR_CONVERSION_POLYGEISTTOLLVM_POLYGEISTTOLLVMPASS_H
10+
#define MLIR_CONVERSION_POLYGEISTTOLLVM_POLYGEISTTOLLVMPASS_H
11+
12+
#include "mlir/Pass/Pass.h"
13+
14+
#include <memory>
15+
16+
namespace mlir {
17+
class LowerToLLVMOptions;
18+
19+
#define GEN_PASS_DECL_CONVERTPOLYGEISTTOLLVM
20+
#include "mlir/Conversion/PolygeistPasses.h.inc"
21+
#undef GEN_PASS_DECL_CONVERTPOLYGEISTTOLLVM
22+
23+
std::unique_ptr<Pass> createConvertPolygeistToLLVMPass();
24+
std::unique_ptr<Pass>
25+
createConvertPolygeistToLLVMPass(const LowerToLLVMOptions &options);
26+
} // namespace mlir
27+
28+
#endif // MLIR_CONVERSION_POLYGEISTTOLLVM_POLYGEISTTOLLVMPASS_H
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(Polygeist)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
add_subdirectory(IR)
2+
add_subdirectory(Transforms)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
add_mlir_dialect(PolygeistOps polygeist)
2+
add_mlir_doc(PolygeistOps PolygeistOps Dialects/ -gen-dialect-doc -dialect=polygeist)

polygeist/include/polygeist/Ops.h renamed to polygeist/include/mlir/Dialect/Polygeist/IR/Ops.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
//===- Polygeistps.h - Polygeist dialect ops --------------------*- C++ -*-===//
1+
//===- Ops.h - Polygeist dialect ops ----------------------------*- C++ -*-===//
22
//
33
// This file is licensed 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 POLYGEISTOPS_H
10-
#define POLYGEISTOPS_H
9+
#ifndef MLIR_DIALECT_POLYGEIST_IR_OPS_H_
10+
#define MLIR_DIALECT_POLYGEIST_IR_OPS_H_
1111

1212
#include "mlir/Dialect/Affine/IR/AffineOps.h"
1313
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
@@ -22,7 +22,7 @@
2222
#include "llvm/Support/CommandLine.h"
2323

2424
#define GET_OP_CLASSES
25-
#include "polygeist/PolygeistOps.h.inc"
25+
#include "mlir/Dialect/Polygeist/IR/PolygeistOps.h.inc"
2626

2727
#include "mlir/Dialect/Affine/IR/AffineOps.h"
2828
#include "mlir/Dialect/SCF/IR/SCF.h"
@@ -147,4 +147,4 @@ class BarrierElim final
147147
}
148148
};
149149

150-
#endif // POLYGEISTOPS_H
150+
#endif // MLIR_DIALECT_POLYGEIST_IR_OPS_H_
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
//===- BFVDialect.h - BFV dialect -----------------*- C++ -*-===//
1+
//===- Polygeist.h - Polygeist dialect --------------------------*- C++ -*-===//
22
//
33
// This file is licensed 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 BFV_BFVDIALECT_H
10-
#define BFV_BFVDIALECT_H
9+
#ifndef MLIR_DIALECT_POLYGEIST_IR_POLYGEIST_H_
10+
#define MLIR_DIALECT_POLYGEIST_IR_POLYGEIST_H_
1111

1212
#include "mlir/IR/Dialect.h"
1313

14-
#include "polygeist/PolygeistOpsDialect.h.inc"
14+
#include "mlir/Dialect/Polygeist/IR/PolygeistOpsDialect.h.inc"
1515

16-
#endif // BFV_BFVDIALECT_H
16+
#endif // MLIR_DIALECT_POLYGEIST_IR_POLYGEIST_H_
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//=== PolygeistBase.td - Base definitions for polygeist dialect -*- tablegen =//
2+
//
3+
// This file is licensed 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+
#ifndef POLYGEIST_BASE
10+
#define POLYGEIST_BASE
11+
12+
include "mlir/IR/OpBase.td"
13+
14+
def Polygeist_Dialect : Dialect {
15+
let name = "polygeist";
16+
let cppNamespace = "::mlir::polygeist";
17+
let description = [{}];
18+
}
19+
20+
#endif // POLYGEIST_BASE

polygeist/include/polygeist/PolygeistOps.td renamed to polygeist/include/mlir/Dialect/Polygeist/IR/PolygeistOps.td

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- Polygeist.td - Polygeist dialect ops ----------------*- tablegen -*-===//
1+
//===- PolygeistOps.td - Polygeist op definitions ----------*- tablegen -*-===//
22
//
33
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -9,12 +9,14 @@
99
#ifndef POLYGEIST_OPS
1010
#define POLYGEIST_OPS
1111

12-
include "Dialect.td"
12+
include "mlir/Dialect/LLVMIR/LLVMOpBase.td"
13+
include "mlir/Dialect/LLVMIR/LLVMOpsInterfaces.td"
14+
include "mlir/Dialect/Polygeist/IR/PolygeistBase.td"
1315
include "mlir/Interfaces/SideEffectInterfaces.td"
1416
include "mlir/Interfaces/ViewLikeInterface.td"
1517

16-
include "mlir/Dialect/LLVMIR/LLVMOpBase.td"
17-
include "mlir/Dialect/LLVMIR/LLVMOpsInterfaces.td"
18+
class Polygeist_Op<string mnemonic, list<Trait> traits = []>
19+
: Op<Polygeist_Dialect, mnemonic, traits>;
1820

1921
def CacheLoad
2022
: Polygeist_Op<"cacheload"> {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
set(LLVM_TARGET_DEFINITIONS Passes.td)
2-
mlir_tablegen(Passes.h.inc -gen-pass-decls -name polygeist)
2+
mlir_tablegen(Passes.h.inc -gen-pass-decls -name Polygeist)
33
add_public_tablegen_target(MLIRPolygeistPassIncGen)
4+
add_dependencies(mlir-headers MLIRPolygeistPassIncGen)
45

56
add_mlir_doc(Passes PolygeistPasses ./ -gen-pass-doc)
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,39 @@
1-
#ifndef POLYGEIST_DIALECT_POLYGEIST_PASSES_H
2-
#define POLYGEIST_DIALECT_POLYGEIST_PASSES_H
1+
//===- Passes.h - Transform Pass Construction and Registration --*- C++ -*-===//
2+
//
3+
// This file is licensed 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+
#ifndef MLIR_DIALECT_POLYGEIST_TRANSFORMS_PASSES_H
10+
#define MLIR_DIALECT_POLYGEIST_TRANSFORMS_PASSES_H
311

4-
#include "mlir/Conversion/LLVMCommon/LoweringOptions.h"
512
#include "mlir/Pass/Pass.h"
13+
614
#include <memory>
15+
716
namespace mlir {
817
class PatternRewriter;
918
class DominanceInfo;
1019
class LLVMTypeConverter;
1120
namespace polygeist {
12-
std::unique_ptr<Pass> createLICMPass();
21+
//===----------------------------------------------------------------------===//
22+
// Patterns
23+
//===----------------------------------------------------------------------===//
24+
25+
/// Collect a set of patterns to convert memory-related operations from the
26+
/// MemRef dialect to the LLVM dialect forcing a "bare pointer" calling
27+
/// convention.
28+
void populateBareMemRefToLLVMConversionPatterns(LLVMTypeConverter &converter,
29+
RewritePatternSet &patterns);
30+
31+
#define GEN_PASS_DECL
32+
#include "mlir/Dialect/Polygeist/Transforms/Passes.h.inc"
33+
34+
std::unique_ptr<Pass> createParallelLICMPass();
1335
std::unique_ptr<Pass> createMem2RegPass();
36+
std::unique_ptr<Pass> createLICMPass();
1437
std::unique_ptr<Pass> createLoopRestructurePass();
1538
std::unique_ptr<Pass> createInnerSerializationPass();
1639
std::unique_ptr<Pass> replaceAffineCFGPass();
@@ -23,49 +46,15 @@ std::unique_ptr<Pass> detectReductionPass();
2346
std::unique_ptr<Pass> createRemoveTrivialUsePass();
2447
std::unique_ptr<Pass> createParallelLowerPass();
2548
std::unique_ptr<Pass> createLegalizeForSPIRVPass();
26-
std::unique_ptr<Pass>
27-
createConvertPolygeistToLLVMPass(const LowerToLLVMOptions &options);
28-
std::unique_ptr<Pass> createConvertPolygeistToLLVMPass();
29-
30-
/// Collect a set of patterns to convert memory-related operations from the
31-
/// MemRef dialect to the LLVM dialect forcing a "bare pointer" calling
32-
/// convention.
33-
void populateBareMemRefToLLVMConversionPatterns(LLVMTypeConverter &converter,
34-
RewritePatternSet &patterns);
3549

36-
} // namespace polygeist
37-
} // namespace mlir
38-
39-
void fully2ComposeAffineMapAndOperands(
40-
mlir::PatternRewriter &rewriter, mlir::AffineMap *map,
41-
llvm::SmallVectorImpl<mlir::Value> *operands, mlir::DominanceInfo &DI);
42-
bool isValidIndex(mlir::Value val);
43-
44-
namespace mlir {
45-
// Forward declaration from Dialect.h
46-
template <typename ConcreteDialect>
47-
void registerDialect(DialectRegistry &registry);
48-
49-
namespace scf {
50-
class SCFDialect;
51-
} // end namespace scf
52-
53-
namespace memref {
54-
class MemRefDialect;
55-
} // end namespace memref
56-
57-
namespace func {
58-
class FuncDialect;
59-
}
60-
61-
class AffineDialect;
62-
namespace LLVM {
63-
class LLVMDialect;
64-
}
50+
//===----------------------------------------------------------------------===//
51+
// Registration
52+
//===----------------------------------------------------------------------===//
6553

6654
#define GEN_PASS_REGISTRATION
67-
#include "polygeist/Passes/Passes.h.inc"
55+
#include "mlir/Dialect/Polygeist/Transforms/Passes.h.inc"
6856

69-
} // end namespace mlir
57+
} // namespace polygeist
58+
} // namespace mlir
7059

71-
#endif // POLYGEIST_DIALECT_POLYGEIST_PASSES_H
60+
#endif // MLIR_DIALECT_POLYGEIST_TRANSFORMS_PASSES_H

0 commit comments

Comments
 (0)