Skip to content

Commit 9e5f7f9

Browse files
committed
cmake
1 parent d4f9d02 commit 9e5f7f9

File tree

15 files changed

+229
-510
lines changed

15 files changed

+229
-510
lines changed

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)
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
11
add_mlir_dialect(PolygeistOps polygeist)
2-
add_mlir_doc(PolygeistDialect -gen-dialect-doc PolygeistDialect Polygeist/)
3-
add_mlir_doc(PolygeistOps -gen-op-doc PolygeistOps Polygeist/)
4-
5-
add_subdirectory(Passes)
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
//===- BFVDialect.h - BFV dialect -----------------*- C++ -*-===//
1+
//===- PolygeistDialect.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_POLYGEISTDIALECT_H
10+
#define MLIR_DIALECT_POLYGEIST_IR_POLYGEISTDIALECT_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_POLYGEISTDIALECT_H

include/mlir/Dialect/Polygeist/IR/PolygeistOps.h

Lines changed: 8 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
//===- Polygeistps.h - Polygeist dialect ops --------------------*- C++ -*-===//
1+
//===--- PolygeistOps.h ---------------------------------------------------===//
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_POLYGEISTOPS_H
10+
#define MLIR_DIALECT_POLYGEIST_IR_POLYGEISTOPS_H
1111

1212
#include "mlir/Dialect/Affine/IR/AffineOps.h"
13-
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
1413
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
14+
#include "mlir/Dialect/Polygeist/IR/PolygeistTypes.h"
1515
#include "mlir/Dialect/SCF/IR/SCF.h"
1616
#include "mlir/IR/BuiltinTypes.h"
1717
#include "mlir/IR/Dialect.h"
@@ -23,7 +23,7 @@
2323
#include "llvm/Support/CommandLine.h"
2424

2525
#define GET_OP_CLASSES
26-
#include "polygeist/PolygeistOps.h.inc"
26+
#include "mlir/Dialect/Polygeist/IR/PolygeistOps.h.inc"
2727

2828
#include "mlir/Dialect/Affine/IR/AffineOps.h"
2929
#include "mlir/Dialect/SCF/IR/SCF.h"
@@ -81,9 +81,8 @@ class BarrierElim final
8181
}
8282

8383
Operation *op = barrier;
84-
if (NotTopLevel &&
85-
isa<mlir::scf::ParallelOp, mlir::affine::AffineParallelOp>(
86-
barrier->getParentOp()))
84+
if (NotTopLevel && isa<mlir::scf::ParallelOp, affine::AffineParallelOp>(
85+
barrier->getParentOp()))
8786
return failure();
8887

8988
{
@@ -149,84 +148,4 @@ class BarrierElim final
149148
}
150149
};
151150

152-
struct ValueOrInt {
153-
bool isValue;
154-
mlir::Value v_val;
155-
int64_t i_val;
156-
ValueOrInt(mlir::Value v) { initValue(v); }
157-
void initValue(mlir::Value v) {
158-
using namespace mlir;
159-
if (v) {
160-
IntegerAttr iattr;
161-
if (matchPattern(v, m_Constant(&iattr))) {
162-
i_val = iattr.getValue().getSExtValue();
163-
v_val = nullptr;
164-
isValue = false;
165-
return;
166-
}
167-
}
168-
isValue = true;
169-
v_val = v;
170-
}
171-
172-
ValueOrInt(size_t i) : isValue(false), v_val(), i_val(i) {}
173-
174-
bool operator>=(int64_t v) {
175-
if (isValue)
176-
return false;
177-
return i_val >= v;
178-
}
179-
bool operator>(int64_t v) {
180-
if (isValue)
181-
return false;
182-
return i_val > v;
183-
}
184-
bool operator==(int64_t v) {
185-
if (isValue)
186-
return false;
187-
return i_val == v;
188-
}
189-
bool operator<(int64_t v) {
190-
if (isValue)
191-
return false;
192-
return i_val < v;
193-
}
194-
bool operator<=(int64_t v) {
195-
if (isValue)
196-
return false;
197-
return i_val <= v;
198-
}
199-
bool operator>=(llvm::APInt v) {
200-
if (isValue)
201-
return false;
202-
return i_val >= v.getSExtValue();
203-
}
204-
bool operator>(llvm::APInt v) {
205-
if (isValue)
206-
return false;
207-
return i_val > v.getSExtValue();
208-
}
209-
bool operator==(llvm::APInt v) {
210-
if (isValue)
211-
return false;
212-
return i_val == v.getSExtValue();
213-
}
214-
bool operator<(llvm::APInt v) {
215-
if (isValue)
216-
return false;
217-
return i_val < v.getSExtValue();
218-
}
219-
bool operator<=(llvm::APInt v) {
220-
if (isValue)
221-
return false;
222-
return i_val <= v.getSExtValue();
223-
}
224-
};
225-
226-
enum class Cmp { EQ, LT, LE, GT, GE };
227-
228-
bool valueCmp(Cmp cmp, mlir::AffineExpr expr, size_t numDim,
229-
mlir::ValueRange operands, ValueOrInt val);
230-
231-
bool valueCmp(Cmp cmp, mlir::Value bval, ValueOrInt val);
232-
#endif // POLYGEISTOPS_H
151+
#endif // MLIR_DIALECT_POLYGEIST_IR_POLYGEISTOPS_H

include/mlir/Dialect/Polygeist/IR/PolygeistOps.td

Lines changed: 10 additions & 131 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,47 +9,15 @@
99
#ifndef POLYGEIST_OPS
1010
#define POLYGEIST_OPS
1111

12-
include "Dialect.td"
13-
include "mlir/Interfaces/SideEffectInterfaces.td"
14-
include "mlir/Interfaces/ViewLikeInterface.td"
15-
include "mlir/Interfaces/ControlFlowInterfaces.td"
16-
include "mlir/IR/SymbolInterfaces.td"
17-
1812
include "mlir/Dialect/LLVMIR/LLVMOpBase.td"
1913
include "mlir/Dialect/LLVMIR/LLVMInterfaces.td"
14+
include "mlir/Dialect/Polygeist/IR/PolygeistBase.td"
15+
include "mlir/Dialect/Polygeist/IR/PolygeistTypes.td"
16+
include "mlir/Interfaces/SideEffectInterfaces.td"
17+
include "mlir/Interfaces/ViewLikeInterface.td"
2018

21-
def UndefOp
22-
: Polygeist_Op<"undef", [Pure]> {
23-
let summary = "More flexible undef op";
24-
let skipDefaultBuilders = 1;
25-
let results = (outs AnyType:$result);
26-
let builders = [
27-
OpBuilder<(ins "Type":$type), [{
28-
$_state.types.push_back(type);
29-
}]>];
30-
let hasCanonicalizer = true;
31-
}
32-
33-
def NoopOp
34-
: Polygeist_Op<"noop",
35-
[DeclareOpInterfaceMethods<MemoryEffectsOpInterface>]> {
36-
let summary = "Noop for preventing folding or transformations";
37-
let arguments = (ins Variadic<Index>:$blockDims);
38-
let skipDefaultBuilders = 1;
39-
let builders = [
40-
OpBuilder<(ins "ValueRange":$indices)>];
41-
let description = [{}];
42-
}
43-
44-
def GetDeviceGlobalOp
45-
: Polygeist_Op<"get_device_global",
46-
[DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
47-
DeclareOpInterfaceMethods<SymbolUserOpInterface>]> {
48-
let summary = "";
49-
let arguments = (ins FlatSymbolRefAttr:$name);
50-
let results = (outs AnyStaticShapeMemRef:$result);
51-
let description = [{}];
52-
}
19+
class Polygeist_Op<string mnemonic, list<Trait> traits = []>
20+
: Op<Polygeist_Dialect, mnemonic, traits>;
5321

5422
def CacheLoad
5523
: Polygeist_Op<"cacheload"> {
@@ -60,7 +28,7 @@ def CacheLoad
6028
let results = (outs AnyType:$result);
6129
let builders = [
6230
OpBuilder<(ins "Value":$memref, CArg<"ValueRange", "{}">:$indices), [{
63-
auto memrefType = memref.getType().cast<MemRefType>();
31+
auto memrefType = cast<MemRefType>(memref.getType());
6432
$_state.addOperands(memref);
6533
$_state.addOperands(indices);
6634
$_state.types.push_back(memrefType.getElementType());
@@ -100,73 +68,6 @@ def SubIndexOp : Polygeist_Op<"subindex", [
10068
}];
10169
}
10270

103-
def GPUBlockOp : Polygeist_Op<"gpu_block", [
104-
RecursiveMemoryEffects,
105-
SingleBlockImplicitTerminator<"polygeist::PolygeistYieldOp">]>,
106-
Arguments<(ins Index:$blockIndexX, Index:$blockIndexY, Index:$blockIndexZ)> {
107-
let summary = "Wraps a GPU kernel block to prevent restructuring";
108-
let regions = (region SizedRegion<1>:$region);
109-
let skipDefaultBuilders = 1;
110-
let builders = [OpBuilder<(ins
111-
"Value":$blockIndexX, "Value":$blockIndexY, "Value":$blockIndexZ)>];
112-
}
113-
114-
def GPUThreadOp : Polygeist_Op<"gpu_thread", [
115-
RecursiveMemoryEffects,
116-
SingleBlockImplicitTerminator<"polygeist::PolygeistYieldOp">]>,
117-
Arguments<(ins Index:$threadIndexX, Index:$threadIndexY, Index:$threadIndexZ)> {
118-
let summary = "Wraps a GPU kernel thread to prevent restructuring";
119-
let regions = (region SizedRegion<1>:$region);
120-
let skipDefaultBuilders = 1;
121-
let builders = [OpBuilder<(ins
122-
"Value":$threadIndexX, "Value":$threadIndexY, "Value":$threadIndexZ)>];
123-
}
124-
125-
def AlternativesOp : Polygeist_Op<"alternatives", [
126-
RecursiveMemoryEffects]> {
127-
let summary = "Provides several alternatives kernels for gpu code";
128-
let regions = (region VariadicRegion<SizedRegion<1>>:$regions);
129-
let skipDefaultBuilders = 1;
130-
let builders = [OpBuilder<(ins "int":$regionNum)>];
131-
let hasCanonicalizer = 1;
132-
}
133-
134-
def GPUWrapperOp : Polygeist_Op<"gpu_wrapper", [
135-
RecursiveMemoryEffects,
136-
AutomaticAllocationScope,
137-
SingleBlockImplicitTerminator<"polygeist::PolygeistYieldOp">]> {
138-
let arguments = (ins Variadic<Index>:$blockDims);
139-
let summary = "Indicates the region contained must be executed on the GPU";
140-
let description = [{
141-
The optional arguments to this operation are suggestions about what block
142-
dimensions this gpu kernel should have - usually taken from kernel launch
143-
params
144-
}];
145-
let results = (outs Index : $result);
146-
let regions = (region SizedRegion<1>:$region);
147-
let skipDefaultBuilders = 1;
148-
let builders = [
149-
OpBuilder<(ins "ValueRange":$blockSizes)>,
150-
OpBuilder<(ins)>];
151-
}
152-
153-
def GPUErrorOp : Polygeist_Op<"gpu_error", [
154-
RecursiveMemoryEffects,
155-
SingleBlockImplicitTerminator<"polygeist::PolygeistYieldOp">]>,
156-
Arguments<(ins)> {
157-
let summary = "Gets the error returned by the gpu operation inside";
158-
// TODO should be i32, not index
159-
let results = (outs Index : $result);
160-
let regions = (region SizedRegion<1>:$region);
161-
let skipDefaultBuilders = 1;
162-
let builders = [OpBuilder<(ins)>];
163-
164-
}
165-
166-
def PolygeistYieldOp : Polygeist_Op<"polygeist_yield", [Pure, ReturnLike, Terminator,
167-
ParentOneOf<["AlternativesOp", "GPUWrapperOp", "GPUErrorOp", "GPUBlockOp", "GPUThreadOp"]>]> {
168-
let summary = "Polygeist ops terminator";
169-
}
17071

17172
def StreamToTokenOp : Polygeist_Op<"stream2token", [
17273
Pure
@@ -191,27 +92,13 @@ def Memref2PointerOp : Polygeist_Op<"memref2pointer", [
19192

19293
let hasFolder = 1;
19394
let hasCanonicalizer = 1;
95+
let hasVerifier = 1;
19496

19597
let extraClassDeclaration = [{
19698
::mlir::Value getViewSource() { return getSource(); }
19799
}];
198100
}
199101

200-
def MemrefCastOp : Polygeist_Op<"memref_cast", [
201-
ViewLikeOpInterface, Pure
202-
]> {
203-
let summary = "Cast memrefs like c/c++ pointers";
204-
205-
let arguments = (ins AnyMemRef : $source);
206-
let results = (outs AnyMemRef : $result);
207-
208-
//let hasFolder = 1;
209-
//let hasCanonicalizer = 1;
210-
let extraClassDeclaration = [{
211-
::mlir::Value getViewSource() { return getSource(); }
212-
}];
213-
}
214-
215102
def Pointer2MemrefOp : Polygeist_Op<"pointer2memref", [
216103
ViewLikeOpInterface, Pure
217104
]> {
@@ -222,21 +109,13 @@ def Pointer2MemrefOp : Polygeist_Op<"pointer2memref", [
222109

223110
let hasFolder = 1;
224111
let hasCanonicalizer = 1;
112+
let hasVerifier = 1;
225113

226114
let extraClassDeclaration = [{
227115
::mlir::Value getViewSource() { return getSource(); }
228116
}];
229117
}
230118

231-
def GetFuncOp : Polygeist_Op<"get_func",
232-
[Pure, DeclareOpInterfaceMethods<SymbolUserOpInterface>]> {
233-
let summary = "get the pointer pointing to a function";
234-
let arguments = (ins FlatSymbolRefAttr:$name);
235-
let results = (outs LLVM_AnyPointer : $result);
236-
// let assemblyFormat = "$name `:` type($result) attr-dict";
237-
let hasCanonicalizer = 1;
238-
}
239-
240119
def TrivialUseOp : Polygeist_Op<"trivialuse"> {
241120
let summary = "memref subview operation";
242121

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
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-
5-
add_mlir_doc(Passes PolygeistPasses ./ -gen-pass-doc)
4+
add_dependencies(mlir-headers MLIRPolygeistPassIncGen)

0 commit comments

Comments
 (0)