Skip to content

Commit 4d42aa6

Browse files
Enable shared library build. (#281)
* Enable shared library build. * This patch can enable Polygeist as shared library. aka, when cmake config append with `-DBUILD_SHARED_LIBS=ON`. * Change is simple, just add missing libray and move two functions to Ops.cpp from OpenMPOpt.cpp. Signed-off-by: fanfuqiang <[email protected]> * Fix clang-format. * fix clang-format. Signed-off-by: fanfuqiang <[email protected]> Signed-off-by: fanfuqiang <[email protected]>
1 parent f4c806d commit 4d42aa6

File tree

4 files changed

+71
-61
lines changed

4 files changed

+71
-61
lines changed

lib/polygeist/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@ MLIRPolygeistOpsIncGen
1111
LINK_LIBS PUBLIC
1212
MLIRIR
1313
MLIRMemRefDialect
14+
MLIRLLVMDialect
15+
MLIROpenMPDialect
16+
MLIRAffineDialect
17+
MLIRSupport
18+
MLIRSCFTransforms
1419
)
1520
add_subdirectory(Passes)

lib/polygeist/Ops.cpp

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,66 @@ void BarrierOp::getEffects(
199199
return;
200200
}
201201

202-
bool isReadNone(Operation *op);
202+
bool isReadOnly(Operation *op) {
203+
bool hasRecursiveEffects = op->hasTrait<OpTrait::HasRecursiveSideEffects>();
204+
if (hasRecursiveEffects) {
205+
for (Region &region : op->getRegions()) {
206+
for (auto &block : region) {
207+
for (auto &nestedOp : block)
208+
if (!isReadOnly(&nestedOp))
209+
return false;
210+
}
211+
}
212+
return true;
213+
}
214+
215+
// If the op has memory effects, try to characterize them to see if the op
216+
// is trivially dead here.
217+
if (auto effectInterface = dyn_cast<MemoryEffectOpInterface>(op)) {
218+
// Check to see if this op either has no effects, or only allocates/reads
219+
// memory.
220+
SmallVector<MemoryEffects::EffectInstance, 1> effects;
221+
effectInterface.getEffects(effects);
222+
if (!llvm::all_of(effects, [op](const MemoryEffects::EffectInstance &it) {
223+
return isa<MemoryEffects::Read>(it.getEffect());
224+
})) {
225+
return false;
226+
}
227+
return true;
228+
}
229+
return false;
230+
}
231+
232+
bool isReadNone(Operation *op) {
233+
bool hasRecursiveEffects = op->hasTrait<OpTrait::HasRecursiveSideEffects>();
234+
if (hasRecursiveEffects) {
235+
for (Region &region : op->getRegions()) {
236+
for (auto &block : region) {
237+
for (auto &nestedOp : block)
238+
if (!isReadNone(&nestedOp))
239+
return false;
240+
}
241+
}
242+
return true;
243+
}
244+
245+
// If the op has memory effects, try to characterize them to see if the op
246+
// is trivially dead here.
247+
if (auto effectInterface = dyn_cast<MemoryEffectOpInterface>(op)) {
248+
// Check to see if this op either has no effects, or only allocates/reads
249+
// memory.
250+
SmallVector<MemoryEffects::EffectInstance, 1> effects;
251+
effectInterface.getEffects(effects);
252+
if (llvm::any_of(effects, [op](const MemoryEffects::EffectInstance &it) {
253+
return isa<MemoryEffects::Read>(it.getEffect()) ||
254+
isa<MemoryEffects::Write>(it.getEffect());
255+
})) {
256+
return false;
257+
}
258+
return true;
259+
}
260+
return false;
261+
}
203262

204263
class BarrierHoist final : public OpRewritePattern<BarrierOp> {
205264
public:

lib/polygeist/Passes/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ add_mlir_dialect_library(MLIRPolygeistTransforms
4141
MLIRSideEffectInterfaces
4242
MLIRSCFToControlFlow
4343
MLIRTransformUtils
44+
MLIRControlFlowToLLVM
45+
MLIRMemRefToLLVM
46+
MLIRFuncToLLVM
47+
MLIRArithToLLVM
48+
MLIROpenMPToLLVM
4449
)

lib/polygeist/Passes/OpenMPOpt.cpp

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "mlir/IR/Dominance.h"
1010
#include "mlir/IR/Matchers.h"
1111
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
12+
#include "polygeist/Ops.h"
1213
#include "polygeist/Passes/Passes.h"
1314
#include <mlir/Dialect/Arith/IR/Arith.h>
1415

@@ -39,66 +40,6 @@ struct OpenMPOpt : public OpenMPOptPassBase<OpenMPOpt> {
3940
/// omp.barrier
4041
/// codeB();
4142
/// }
42-
bool isReadOnly(Operation *op) {
43-
bool hasRecursiveEffects = op->hasTrait<OpTrait::HasRecursiveSideEffects>();
44-
if (hasRecursiveEffects) {
45-
for (Region &region : op->getRegions()) {
46-
for (auto &block : region) {
47-
for (auto &nestedOp : block)
48-
if (!isReadOnly(&nestedOp))
49-
return false;
50-
}
51-
}
52-
return true;
53-
}
54-
55-
// If the op has memory effects, try to characterize them to see if the op
56-
// is trivially dead here.
57-
if (auto effectInterface = dyn_cast<MemoryEffectOpInterface>(op)) {
58-
// Check to see if this op either has no effects, or only allocates/reads
59-
// memory.
60-
SmallVector<MemoryEffects::EffectInstance, 1> effects;
61-
effectInterface.getEffects(effects);
62-
if (!llvm::all_of(effects, [op](const MemoryEffects::EffectInstance &it) {
63-
return isa<MemoryEffects::Read>(it.getEffect());
64-
})) {
65-
return false;
66-
}
67-
return true;
68-
}
69-
return false;
70-
}
71-
72-
bool isReadNone(Operation *op) {
73-
bool hasRecursiveEffects = op->hasTrait<OpTrait::HasRecursiveSideEffects>();
74-
if (hasRecursiveEffects) {
75-
for (Region &region : op->getRegions()) {
76-
for (auto &block : region) {
77-
for (auto &nestedOp : block)
78-
if (!isReadNone(&nestedOp))
79-
return false;
80-
}
81-
}
82-
return true;
83-
}
84-
85-
// If the op has memory effects, try to characterize them to see if the op
86-
// is trivially dead here.
87-
if (auto effectInterface = dyn_cast<MemoryEffectOpInterface>(op)) {
88-
// Check to see if this op either has no effects, or only allocates/reads
89-
// memory.
90-
SmallVector<MemoryEffects::EffectInstance, 1> effects;
91-
effectInterface.getEffects(effects);
92-
if (llvm::any_of(effects, [op](const MemoryEffects::EffectInstance &it) {
93-
return isa<MemoryEffects::Read>(it.getEffect()) ||
94-
isa<MemoryEffects::Write>(it.getEffect());
95-
})) {
96-
return false;
97-
}
98-
return true;
99-
}
100-
return false;
101-
}
10243

10344
Value getBase(Value v);
10445
bool isStackAlloca(Value v);

0 commit comments

Comments
 (0)