Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AnnotateScop] new pass annotates scop.ignored #107

Merged
merged 3 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/polymer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(Transforms)
3 changes: 3 additions & 0 deletions include/polymer/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name Transforms)
add_public_tablegen_target(PolymerTransformsIncGen)
17 changes: 17 additions & 0 deletions include/polymer/Transforms/Passes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===- Passes.h - Include Tblgen pass defs ------------C++-===//
#ifndef POLYMER_TRANSFORMS_PASSES_H
#define POLYMER_TRANSFORMS_PASSES_H

#include "mlir/Pass/Pass.h"

namespace polymer {

std::unique_ptr<mlir::OperationPass<mlir::FuncOp>> createAnnotateScopPass();

/// Generate the code for registering passes.
#define GEN_PASS_REGISTRATION
#include "polymer/Transforms/Passes.h.inc"

} // namespace polymer

#endif
21 changes: 21 additions & 0 deletions include/polymer/Transforms/Passes.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef POLYMER_TRANSFORMS_PASSES
#define POLYMER_TRANSFORMS_PASSES

include "mlir/Pass/PassBase.td"
include "mlir/Rewrite/PassUtil.td"

def AnnotateScop : FunctionPass<"annotate-scop"> {
let summary = "Annotate scop.ignore to unselected functions.";
let constructor = "polymer::createAnnotateScopPass()";

let options = [
ListOption<
"includedFunctions",
"functions",
"std::string",
"A list of functions to be included.",
"llvm::cl::ZeroOrMore, llvm::cl::MiscFlags::CommaSeparated">
];
}

#endif
34 changes: 34 additions & 0 deletions lib/Transforms/AnnotateScop.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//===- AnnotateScop.cc --------------------------------------*- C++ -*-===//

#include "PassDetail.h"

#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/SCF/SCF.h"
#include "mlir/Transforms/LoopUtils.h"
#include "mlir/Transforms/Passes.h"
#include "mlir/Transforms/RegionUtils.h"
#include "llvm/Support/Debug.h"

using namespace mlir;
using namespace llvm;
using namespace polymer;

namespace {
struct AnnotateScop : public polymer::AnnotateScopBase<AnnotateScop> {
void runOnFunction() override {
FuncOp f = getOperation();
OpBuilder b(f.getContext());

for (auto &name : includedFunctions)
if (name == f.getName())
return;

f->setAttr("scop.ignored", b.getUnitAttr());
} // namespace
};
} // namespace

std::unique_ptr<OperationPass<FuncOp>> polymer::createAnnotateScopPass() {
return std::make_unique<AnnotateScop>();
}
3 changes: 2 additions & 1 deletion lib/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ add_mlir_conversion_library(PolymerTransforms
LoopAnnotate.cc
LoopExtract.cc
FoldSCFIf.cc
AnnotateScop.cc

ADDITIONAL_HEADER_DIRS
"${POLYMER_MAIN_INCLUDE_DIR}/polymer/Transforms"

DEPENDS
${POLYMER_TRANSFORM_DEPENDS}
PolymerTransformsIncGen

LINK_LIBS PUBLIC
MLIRAffine
Expand Down
6 changes: 5 additions & 1 deletion lib/Transforms/ExtractScopStmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,11 @@ class ExtractScopStmtPass
OpBuilder b(m.getContext());

SmallVector<mlir::FuncOp, 4> funcs;
m.walk([&](mlir::FuncOp f) { funcs.push_back(f); });
m.walk([&](mlir::FuncOp f) {
if (f->hasAttr("scop.ignored"))
return;
funcs.push_back(f);
});

unsigned numCallees = 0;
for (mlir::FuncOp f : funcs) {
Expand Down
14 changes: 14 additions & 0 deletions lib/Transforms/PassDetail.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//===- PassDetail.h - Transforms Pass class details -------------*- C++ -*-===//

#ifndef POLYMER_TRANSFORMS_PASSDETAIL_H_
#define POLYMER_TRANSFORMS_PASSDETAIL_H_

#include "mlir/Pass/Pass.h"
#include "polymer/Transforms/Passes.h"

namespace polymer {
#define GEN_PASS_CLASSES
#include "polymer/Transforms/Passes.h.inc"
} // namespace polymer

#endif
2 changes: 1 addition & 1 deletion lib/Transforms/PlutoTransform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class PlutoTransformPass
llvm::DenseMap<mlir::FuncOp, mlir::FuncOp> funcMap;

m.walk([&](mlir::FuncOp f) {
if (!f->getAttr("scop.stmt"))
if (!f->getAttr("scop.stmt") && !f->hasAttr("scop.ignored"))
funcOps.push_back(f);
});

Expand Down
3 changes: 3 additions & 0 deletions lib/Transforms/Reg2Mem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ class RegToMemPass
mlir::FuncOp f = getOperation();
auto builder = OpBuilder(f.getContext());

if (f->hasAttr("scop.ignored"))
return;

separateAffineIfBlocks(f, builder);
demoteRegisterToMemory(f, builder);
}
Expand Down
12 changes: 12 additions & 0 deletions test/polymer-opt/AnnotateScop/annotate-single.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: polymer-opt %s -annotate-scop="functions=foo" | FileCheck %s

func @foo() {
return
}

func @bar() {
return
}

// CHECK: func @foo() {
// CHECK: func @bar() attributes {scop.ignored} {
14 changes: 14 additions & 0 deletions test/polymer-opt/Reg2Mem/ignored.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// RUN: polymer-opt %s -reg2mem | FileCheck %s
func @foo(%A: memref<?xf32>) attributes {scop.ignored} {
%0 = affine.load %A[0] : memref<?xf32>
affine.for %i = 1 to 30 {
affine.store %0, %A[%i] : memref<?xf32>
}

return
}

// CHECK: func @foo
// CHECK-NEXT: %[[v0:.*]] = affine.load
// CHECK-NEXT: affine.for %{{.*}} = 1 to 30
// CHECK-NEXT: affine.store %[[v0]]
2 changes: 2 additions & 0 deletions tools/polymer-opt/polymer-opt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "polymer/Transforms/FoldSCFIf.h"
#include "polymer/Transforms/LoopAnnotate.h"
#include "polymer/Transforms/LoopExtract.h"
#include "polymer/Transforms/Passes.h"
#include "polymer/Transforms/PlutoTransform.h"
#include "polymer/Transforms/Reg2Mem.h"
#include "polymer/Transforms/ScopStmtOpt.h"
Expand Down Expand Up @@ -61,6 +62,7 @@ int main(int argc, char *argv[]) {
registerLoopAnnotatePasses();
registerLoopExtractPasses();
registerFoldSCFIfPass();
registerAnnotateScopPass();

// Register any pass manager command line options.
registerMLIRContextCLOptions();
Expand Down