Skip to content

Commit a1f1990

Browse files
authored
[SYCL-MLIR][NFC] Restructure Polygeist dialect (#8266)
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 5d81e30 commit a1f1990

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

+667
-548
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
@@ -25,7 +25,7 @@
2525
#include "mlir/Rewrite/FrozenRewritePatternSet.h"
2626
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
2727

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

3131
#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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#ifndef MLIR_CONVERSION_POLYGEISTPASSES
2+
#define MLIR_CONVERSION_POLYGEISTPASSES
3+
4+
include "mlir/Pass/PassBase.td"
5+
6+
def ConvertPolygeistToLLVM : Pass<"convert-polygeist-to-llvm", "mlir::ModuleOp"> {
7+
let summary = "Convert scalar and vector operations from the Standard to the "
8+
"LLVM dialect";
9+
let description = [{
10+
Convert standard operations into the LLVM IR dialect operations.
11+
12+
#### Input invariant
13+
14+
- operations including: arithmetic on integers and floats, constants,
15+
direct calls, returns and branches;
16+
- no `tensor` types;
17+
- all `vector` are one-dimensional;
18+
- all blocks are reachable by following the successors of the first basic
19+
block;
20+
21+
If other operations are present and their results are required by the LLVM
22+
IR dialect operations, the pass will fail. Any LLVM IR operations or types
23+
already present in the IR will be kept as is.
24+
25+
#### Output IR
26+
27+
Functions converted to LLVM IR. Function arguments types are converted
28+
one-to-one. Function results are converted one-to-one and, in case more than
29+
1 value is returned, packed into an LLVM IR struct type. Function calls and
30+
returns are updated accordingly. Block argument types are updated to use
31+
LLVM IR types.
32+
}];
33+
let constructor = "mlir::createConvertPolygeistToLLVMPass()";
34+
let dependentDialects = ["LLVM::LLVMDialect"];
35+
let options = [
36+
Option<"useBarePtrCallConv", "use-bare-ptr-memref-call-conv", "bool",
37+
/*default=*/"false",
38+
"Replace FuncOp's MemRef arguments with bare pointers to the MemRef "
39+
"element types">,
40+
Option<"emitCWrappers", "emit-c-wrappers", "bool", /*default=*/"false",
41+
"Emit wrappers for C-compatible pointer-to-struct memref "
42+
"descriptors">,
43+
Option<"indexBitwidth", "index-bitwidth", "unsigned",
44+
/*default=kDeriveIndexBitwidthFromDataLayout*/"0",
45+
"Bitwidth of the index type, 0 to use size of machine word">,
46+
Option<"dataLayout", "data-layout", "std::string",
47+
/*default=*/"\"\"",
48+
"String description (LLVM format) of the data layout that is "
49+
"expected on the produced module">
50+
];
51+
}
52+
53+
#endif // MLIR_CONVERSION_POLYGEISTPASSES
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef MLIR_CONVERSION_POLYGEISTTOLLVM_POLYGEISTTOLLVMPASS_H
2+
#define MLIR_CONVERSION_POLYGEISTTOLLVM_POLYGEISTTOLLVMPASS_H
3+
4+
#include "mlir/Pass/Pass.h"
5+
6+
#include <memory>
7+
8+
namespace mlir {
9+
class LowerToLLVMOptions;
10+
11+
#define GEN_PASS_DECL_CONVERTPOLYGEISTTOLLVM
12+
#include "mlir/Conversion/PolygeistPasses.h.inc"
13+
#undef GEN_PASS_DECL_CONVERTPOLYGEISTTOLLVM
14+
15+
std::unique_ptr<Pass> createConvertPolygeistToLLVMPass();
16+
std::unique_ptr<Pass>
17+
createConvertPolygeistToLLVMPass(const LowerToLLVMOptions &options);
18+
} // namespace mlir
19+
20+
#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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
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_

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
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,14 +1,28 @@
1-
#ifndef POLYGEIST_DIALECT_POLYGEIST_PASSES_H
2-
#define POLYGEIST_DIALECT_POLYGEIST_PASSES_H
1+
#ifndef MLIR_DIALECT_POLYGEIST_TRANSFORMS_PASSES_H
2+
#define MLIR_DIALECT_POLYGEIST_TRANSFORMS_PASSES_H
33

4-
#include "mlir/Conversion/LLVMCommon/LoweringOptions.h"
54
#include "mlir/Pass/Pass.h"
5+
66
#include <memory>
7+
78
namespace mlir {
89
class PatternRewriter;
910
class DominanceInfo;
1011
class LLVMTypeConverter;
1112
namespace polygeist {
13+
//===----------------------------------------------------------------------===//
14+
// Patterns
15+
//===----------------------------------------------------------------------===//
16+
17+
/// Collect a set of patterns to convert memory-related operations from the
18+
/// MemRef dialect to the LLVM dialect forcing a "bare pointer" calling
19+
/// convention.
20+
void populateBareMemRefToLLVMConversionPatterns(LLVMTypeConverter &converter,
21+
RewritePatternSet &patterns);
22+
23+
#define GEN_PASS_DECL
24+
#include "mlir/Dialect/Polygeist/Transforms/Passes.h.inc"
25+
1226
std::unique_ptr<Pass> createParallelLICMPass();
1327
std::unique_ptr<Pass> createMem2RegPass();
1428
std::unique_ptr<Pass> createLoopRestructurePass();
@@ -23,49 +37,15 @@ std::unique_ptr<Pass> detectReductionPass();
2337
std::unique_ptr<Pass> createRemoveTrivialUsePass();
2438
std::unique_ptr<Pass> createParallelLowerPass();
2539
std::unique_ptr<Pass> createLegalizeForSPIRVPass();
26-
std::unique_ptr<Pass>
27-
createConvertPolygeistToLLVMPass(const LowerToLLVMOptions &options);
28-
std::unique_ptr<Pass> createConvertPolygeistToLLVMPass();
2940

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);
35-
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-
}
41+
//===----------------------------------------------------------------------===//
42+
// Registration
43+
//===----------------------------------------------------------------------===//
6544

6645
#define GEN_PASS_REGISTRATION
67-
#include "polygeist/Passes/Passes.h.inc"
46+
#include "mlir/Dialect/Polygeist/Transforms/Passes.h.inc"
6847

69-
} // end namespace mlir
48+
} // namespace polygeist
49+
} // namespace mlir
7050

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

0 commit comments

Comments
 (0)