Skip to content

Commit

Permalink
Make a step (probably) in the right direction
Browse files Browse the repository at this point in the history
  • Loading branch information
vatai committed Sep 15, 2023
1 parent d75f71c commit 6dc15f7
Show file tree
Hide file tree
Showing 19 changed files with 102 additions and 99 deletions.
4 changes: 4 additions & 0 deletions tools/polymer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ include_directories("${PLUTO_INCLUDE_DIR}")
message(STATUS "Will build and use Polymer-bundled Pluto")

include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/OpenScop.cmake")
include_directories("${OSL_INCLUDE_DIR}")

include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/CLooG.cmake")
include_directories("${CLOOG_INCLUDE_DIR}")


# ------------------------------------------------- This project
include_directories("${POLYMER_MAIN_INCLUDE_DIR}")
Expand Down
2 changes: 1 addition & 1 deletion tools/polymer/cmake/AddPluto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

include(ExternalProject)

set(PLUTO_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/pluto/include")
set(PLUTO_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/pluto/install/include")
set(PLUTO_LIB_DIR "${CMAKE_CURRENT_BINARY_DIR}/pluto/lib")
set(PLUTO_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/pluto")
set(PLUTO_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/pluto")
Expand Down
2 changes: 1 addition & 1 deletion tools/polymer/include/polymer/Support/OslScop.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class OslScop {
osl_generic *getExtension(llvm::StringRef interface) const;

/// Initialize the symbol table.
void initializeSymbolTable(mlir::FuncOp f,
void initializeSymbolTable(mlir::func::FuncOp f,
mlir::FlatAffineValueConstraints *cst);

bool isParameterSymbol(llvm::StringRef name) const;
Expand Down
4 changes: 2 additions & 2 deletions tools/polymer/include/polymer/Support/ScopStmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

#include <memory>

#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "llvm/ADT/SmallVector.h"

namespace mlir {
class Operation;
class FlatAffineValueConstraints;
Expand Down Expand Up @@ -44,7 +44,7 @@ class ScopStmt {
void getEnclosingOps(llvm::SmallVectorImpl<mlir::Operation *> &ops,
bool forOnly = false) const;
/// Get the callee of this scop stmt.
mlir::FuncOp getCallee() const;
mlir::func::FuncOp getCallee() const;
/// Get the caller of this scop stmt.
mlir::func::CallOp getCaller() const;
/// Get the access AffineValueMap of an op in the callee and the memref in the
Expand Down
3 changes: 2 additions & 1 deletion tools/polymer/include/polymer/Target/OpenScop.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "pluto/internal/pluto.h"

#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Support/LLVM.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
Expand All @@ -31,7 +32,7 @@ namespace polymer {
class OslScop;
class OslSymbolTable;

std::unique_ptr<OslScop> createOpenScopFromFuncOp(mlir::FuncOp funcOp,
std::unique_ptr<OslScop> createOpenScopFromFuncOp(mlir::func::FuncOp funcOp,
OslSymbolTable &symTable);

/// Create a function (FuncOp) from the given OpenScop object in the given
Expand Down
2 changes: 1 addition & 1 deletion tools/polymer/include/polymer/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
include "mlir/Pass/PassBase.td"
include "mlir/Rewrite/PassUtil.td"

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

Expand Down
4 changes: 2 additions & 2 deletions tools/polymer/lib/Support/OslScop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ void OslScop::addBodyExtension(int stmtId, const ScopStmt &stmt) {
ss << "i" << i << " ";

mlir::func::CallOp caller = stmt.getCaller();
mlir::FuncOp callee = stmt.getCallee();
mlir::func::FuncOp callee = stmt.getCallee();
ss << "\n" << callee.getName() << "(";

SmallVector<std::string, 8> ivs;
Expand Down Expand Up @@ -488,7 +488,7 @@ void OslScop::addBodyExtension(int stmtId, const ScopStmt &stmt) {
addGeneric(stmtId + 1, "body", body);
}

void OslScop::initializeSymbolTable(mlir::FuncOp f,
void OslScop::initializeSymbolTable(mlir::func::FuncOp f,
FlatAffineValueConstraints *cst) {
symbolTable.clear();

Expand Down
2 changes: 1 addition & 1 deletion tools/polymer/lib/Support/OslScopStmtOpSet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ LogicalResult OslScopStmtOpSet::getEnclosingOps(
for (auto op : opSet) {
if (isa<mlir::AffineLoadOp, mlir::AffineStoreOp>(op)) {
ops.clear();
getEnclosingAffineForAndIfOps(*op, &ops);
getEnclosingAffineOps(*op, &ops);
for (auto enclosingOp : ops) {
if (visited.find(enclosingOp) == visited.end()) {
visited.insert(enclosingOp);
Expand Down
14 changes: 7 additions & 7 deletions tools/polymer/lib/Support/ScopStmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "mlir/Dialect/Affine/Analysis/Utils.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Affine/IR/AffineValueMap.h"
#include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/IR/BlockAndValueMapping.h"
#include "mlir/IR/Builders.h"
Expand All @@ -35,7 +35,7 @@ class ScopStmtImpl {
using EnclosingOpList = SmallVector<Operation *, 8>;

ScopStmtImpl(llvm::StringRef name, mlir::func::CallOp caller,
mlir::FuncOp callee)
mlir::func::FuncOp callee)
: name(name), caller(caller), callee(callee) {}

static std::unique_ptr<ScopStmtImpl> get(mlir::Operation *callerOp,
Expand All @@ -53,7 +53,7 @@ class ScopStmtImpl {
/// The caller to the scop.stmt func.
mlir::func::CallOp caller;
/// The scop.stmt callee.
mlir::FuncOp callee;
mlir::func::FuncOp callee;
/// The domain of the caller.
FlatAffineValueConstraints domain;
/// Enclosing for/if operations for the caller.
Expand All @@ -66,9 +66,9 @@ class ScopStmtImpl {
std::unique_ptr<ScopStmtImpl> ScopStmtImpl::get(mlir::Operation *callerOp,
mlir::Operation *calleeOp) {
// We assume that the callerOp is of type mlir::func::CallOp, and the calleeOp
// is a mlir::FuncOp. If not, these two cast lines will raise error.
// is a mlir::func::FuncOp. If not, these two cast lines will raise error.
mlir::func::CallOp caller = cast<mlir::func::CallOp>(callerOp);
mlir::FuncOp callee = cast<mlir::FuncOp>(calleeOp);
mlir::func::FuncOp callee = cast<mlir::func::FuncOp>(calleeOp);
llvm::StringRef name = caller.getCallee();

// Create the stmt instance.
Expand All @@ -95,7 +95,7 @@ static void
promoteSymbolToTopLevel(mlir::Value val, FlatAffineValueConstraints &domain,
llvm::DenseMap<mlir::Value, mlir::Value> &symMap) {
BlockArgument arg = findTopLevelBlockArgument(val);
assert(isa<mlir::FuncOp>(arg.getOwner()->getParentOp()) &&
assert(isa<mlir::func::FuncOp>(arg.getOwner()->getParentOp()) &&
"Found top-level argument should be a FuncOp argument.");
// NOTE: This cannot pass since the found argument may not be of index type,
// i.e., it will be index cast later.
Expand Down Expand Up @@ -185,7 +185,7 @@ void ScopStmt::getEnclosingOps(llvm::SmallVectorImpl<mlir::Operation *> &ops,
ops.push_back(op);
}

mlir::FuncOp ScopStmt::getCallee() const { return impl->callee; }
mlir::func::FuncOp ScopStmt::getCallee() const { return impl->callee; }
mlir::func::CallOp ScopStmt::getCaller() const { return impl->caller; }

static mlir::Value findBlockArg(mlir::Value v) {
Expand Down
24 changes: 11 additions & 13 deletions tools/polymer/lib/Target/OpenScop/ConvertFromOpenScop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,15 @@ extern "C" {
#include "mlir/Dialect/Affine/IR/AffineValueMap.h"
#include "mlir/Dialect/Affine/LoopUtils.h"
#include "mlir/Dialect/Affine/Utils.h"
#include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/IR/BlockAndValueMapping.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Dominance.h"
#include "mlir/IR/Function.h"
#include "mlir/IR/IntegerSet.h"
#include "mlir/IR/MLIRContext.h"
#include "mlir/Translation.h"

#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
Expand Down Expand Up @@ -446,7 +444,7 @@ class Importer {
LogicalResult processStmt(clast_assignment *ass);

std::string getSourceFuncName() const;
mlir::FuncOp getSourceFuncOp();
mlir::func::FuncOp getSourceFuncOp();

LogicalResult getAffineLoopBound(clast_expr *expr,
llvm::SmallVectorImpl<mlir::Value> &operands,
Expand All @@ -470,7 +468,7 @@ class Importer {
/// A helper to create a callee.
void createCalleeAndCallerArgs(llvm::StringRef calleeName,
llvm::ArrayRef<std::string> args,
mlir::FuncOp &callee,
mlir::func::FuncOp &callee,
SmallVectorImpl<mlir::Value> &callerArgs);

/// Number of internal functions created.
Expand Down Expand Up @@ -519,15 +517,15 @@ Importer::Importer(MLIRContext *context, ModuleOp module,
b.setInsertionPointToStart(module.getBody());
}

mlir::FuncOp Importer::getSourceFuncOp() {
mlir::func::FuncOp Importer::getSourceFuncOp() {
std::string sourceFuncName = getSourceFuncName();
mlir::Operation *sourceFuncOp = module.lookupSymbol(sourceFuncName);

assert(sourceFuncOp != nullptr &&
"sourceFuncName cannot be found in the module");
assert(isa<mlir::FuncOp>(sourceFuncOp) &&
"Found sourceFuncOp should be of type mlir::FuncOp.");
return cast<mlir::FuncOp>(sourceFuncOp);
assert(isa<mlir::func::FuncOp>(sourceFuncOp) &&
"Found sourceFuncOp should be of type mlir::func::FuncOp.");
return cast<mlir::func::FuncOp>(sourceFuncOp);
}

/// If there is anything in the comment, we will use it as a function name.
Expand Down Expand Up @@ -576,7 +574,7 @@ void Importer::initializeFuncOpInterface() {
OslScop::ValueTable *oslValueTable = scop->getValueTable();

/// First collect the source FuncOp in the original MLIR code.
mlir::FuncOp sourceFuncOp = getSourceFuncOp();
mlir::func::FuncOp sourceFuncOp = getSourceFuncOp();

// OpBuilder::InsertionGuard guard(b);
b.setInsertionPoint(module.getBody(), getFuncInsertPt());
Expand Down Expand Up @@ -673,7 +671,7 @@ void Importer::initializeSymbol(mlir::Value val) {
hasInsertionPoint = true;
b.setInsertionPointToStart(blockToInsert);
}
} else if (mlir::FuncOp funOp = dyn_cast<mlir::FuncOp>(parentOp)) {
} else if (mlir::func::FuncOp funOp = dyn_cast<mlir::func::FuncOp>(parentOp)) {
// Insert at the beginning of this function.
hasInsertionPoint = true;
b.setInsertionPointToStart(&entryBlock);
Expand Down Expand Up @@ -769,7 +767,7 @@ Importer::parseUserStmtBody(llvm::StringRef body, std::string &calleeName,

void Importer::createCalleeAndCallerArgs(
llvm::StringRef calleeName, llvm::ArrayRef<std::string> args,
mlir::FuncOp &callee, SmallVectorImpl<mlir::Value> &callerArgs) {
mlir::func::FuncOp &callee, SmallVectorImpl<mlir::Value> &callerArgs) {
// TODO: avoid duplicated callee creation
// Cache the current insertion point before changing it for the new callee
// function.
Expand Down Expand Up @@ -1306,7 +1304,7 @@ LogicalResult Importer::processStmt(clast_for *forStmt) {
mlir::FunctionType funcTy =
b.getFunctionType(TypeRange(args.getArrayRef()), llvm::None);
b.setInsertionPoint(&*getFuncInsertPt());
mlir::FuncOp func = b.create<mlir::FuncOp>(
mlir::func::FuncOp func = b.create<mlir::func::FuncOp>(
forOp->getLoc(), std::string("T") + std::to_string(numInternalFunctions),
funcTy);
numInternalFunctions++;
Expand Down
23 changes: 13 additions & 10 deletions tools/polymer/lib/Target/OpenScop/ConvertToOpenScop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
#include "mlir/Translation.h"

#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SetVector.h"
Expand Down Expand Up @@ -54,11 +53,12 @@ class OslScopBuilder {
OslScopBuilder() {}

/// Build a scop from a common FuncOp.
std::unique_ptr<OslScop> build(mlir::FuncOp f);
std::unique_ptr<OslScop> build(mlir::func::FuncOp f);

private:
/// Find all statements that calls a scop.stmt.
void buildScopStmtMap(mlir::FuncOp f, OslScop::ScopStmtNames *scopStmtNames,
void buildScopStmtMap(mlir::func::FuncOp f,
OslScop::ScopStmtNames *scopStmtNames,
OslScop::ScopStmtMap *scopStmtMap) const;

/// Build the scop context. The domain of each scop stmt will be updated, by
Expand All @@ -79,7 +79,7 @@ static void sanityCheckDomain(FlatAffineValueConstraints &dom) {
}

/// Build OslScop from a given FuncOp.
std::unique_ptr<OslScop> OslScopBuilder::build(mlir::FuncOp f) {
std::unique_ptr<OslScop> OslScopBuilder::build(mlir::func::FuncOp f) {

/// Context constraints.
FlatAffineValueConstraints ctx;
Expand Down Expand Up @@ -124,7 +124,7 @@ std::unique_ptr<OslScop> OslScopBuilder::build(mlir::FuncOp f) {
llvm::SmallVector<mlir::Operation *, 8> enclosingOps;
stmt.getEnclosingOps(enclosingOps);
// Get the callee.
mlir::FuncOp callee = stmt.getCallee();
mlir::func::FuncOp callee = stmt.getCallee();

LLVM_DEBUG({
dbgs() << "Callee:\n";
Expand Down Expand Up @@ -173,15 +173,16 @@ std::unique_ptr<OslScop> OslScopBuilder::build(mlir::FuncOp f) {
}

/// Find all statements that calls a scop.stmt.
void OslScopBuilder::buildScopStmtMap(mlir::FuncOp f,
void OslScopBuilder::buildScopStmtMap(mlir::func::FuncOp f,
OslScop::ScopStmtNames *scopStmtNames,
OslScop::ScopStmtMap *scopStmtMap) const {
mlir::ModuleOp m = cast<mlir::ModuleOp>(f->getParentOp());

f.walk([&](mlir::Operation *op) {
if (mlir::CallOp caller = dyn_cast<mlir::CallOp>(op)) {
llvm::StringRef calleeName = caller.getCallee();
mlir::FuncOp callee = m.lookupSymbol<mlir::FuncOp>(calleeName);
mlir::func::FuncOp callee =
m.lookupSymbol<mlir::func::FuncOp>(calleeName);

// If the callee is of scop.stmt, we create a new instance in the map
if (callee->getAttr(SCOP_STMT_ATTR_NAME)) {
Expand Down Expand Up @@ -313,7 +314,8 @@ void OslScopBuilder::buildScopContext(OslScop *scop,
}

std::unique_ptr<OslScop>
polymer::createOpenScopFromFuncOp(mlir::FuncOp f, OslSymbolTable &symTable) {
polymer::createOpenScopFromFuncOp(mlir::func::FuncOp f,
OslSymbolTable &symTable) {
return OslScopBuilder().build(f);
}

Expand Down Expand Up @@ -380,7 +382,8 @@ class ModuleEmitter : public OpenScopEmitterBase {
};

LogicalResult ModuleEmitter::emitFuncOp(
mlir::FuncOp func, llvm::SmallVectorImpl<std::unique_ptr<OslScop>> &scops) {
mlir::func::FuncOp func,
llvm::SmallVectorImpl<std::unique_ptr<OslScop>> &scops) {
OslSymbolTable symTable;
auto scop = createOpenScopFromFuncOp(func, symTable);
if (scop)
Expand All @@ -393,7 +396,7 @@ void ModuleEmitter::emitMLIRModule(
ModuleOp module, llvm::SmallVectorImpl<std::unique_ptr<OslScop>> &scops) {
// Emit a single OpenScop definition for each function.
for (auto &op : *module.getBody()) {
if (auto func = dyn_cast<mlir::FuncOp>(op)) {
if (auto func = dyn_cast<mlir::func::FuncOp>(op)) {
// Will only look at functions that are not attributed as scop.stmt
if (func->getAttr(SCOP_STMT_ATTR_NAME))
continue;
Expand Down
2 changes: 1 addition & 1 deletion tools/polymer/lib/Transforms/AnnotateScop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Affine/LoopUtils.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/SCF/SCF.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/Transforms/Passes.h"
#include "mlir/Transforms/RegionUtils.h"
#include "llvm/Support/Debug.h"
Expand Down
Loading

0 comments on commit 6dc15f7

Please sign in to comment.