From 6dc15f7c706149b3d09d6a459c5805bdefebab74 Mon Sep 17 00:00:00 2001 From: Emil VATAI Date: Fri, 15 Sep 2023 14:33:02 +0900 Subject: [PATCH] Make a step (probably) in the right direction --- tools/polymer/CMakeLists.txt | 4 ++ tools/polymer/cmake/AddPluto.cmake | 2 +- .../polymer/include/polymer/Support/OslScop.h | 2 +- .../include/polymer/Support/ScopStmt.h | 4 +- .../polymer/include/polymer/Target/OpenScop.h | 3 +- .../include/polymer/Transforms/Passes.td | 2 +- tools/polymer/lib/Support/OslScop.cc | 4 +- tools/polymer/lib/Support/OslScopStmtOpSet.cc | 2 +- tools/polymer/lib/Support/ScopStmt.cc | 14 +++--- .../Target/OpenScop/ConvertFromOpenScop.cc | 24 +++++----- .../lib/Target/OpenScop/ConvertToOpenScop.cc | 23 +++++----- tools/polymer/lib/Transforms/AnnotateScop.cc | 2 +- .../polymer/lib/Transforms/ExtractScopStmt.cc | 35 +++++++-------- tools/polymer/lib/Transforms/FoldSCFIf.cc | 2 +- .../polymer/lib/Transforms/PlutoTransform.cc | 24 +++++----- tools/polymer/lib/Transforms/Reg2Mem.cc | 45 +++++++++---------- tools/polymer/lib/Transforms/ScopStmtOpt.cc | 2 +- .../polymer/tools/polymer-opt/polymer-opt.cc | 4 +- .../polymer-translate/polymer-translate.cc | 3 +- 19 files changed, 102 insertions(+), 99 deletions(-) diff --git a/tools/polymer/CMakeLists.txt b/tools/polymer/CMakeLists.txt index 0389c3789760..a08b9567415c 100644 --- a/tools/polymer/CMakeLists.txt +++ b/tools/polymer/CMakeLists.txt @@ -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}") diff --git a/tools/polymer/cmake/AddPluto.cmake b/tools/polymer/cmake/AddPluto.cmake index 23bab266f1ac..b6f2969fbe02 100644 --- a/tools/polymer/cmake/AddPluto.cmake +++ b/tools/polymer/cmake/AddPluto.cmake @@ -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") diff --git a/tools/polymer/include/polymer/Support/OslScop.h b/tools/polymer/include/polymer/Support/OslScop.h index c35aee7c39c8..04e6f3f04244 100644 --- a/tools/polymer/include/polymer/Support/OslScop.h +++ b/tools/polymer/include/polymer/Support/OslScop.h @@ -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; diff --git a/tools/polymer/include/polymer/Support/ScopStmt.h b/tools/polymer/include/polymer/Support/ScopStmt.h index 3aa6dd189869..fc11a75ec19e 100644 --- a/tools/polymer/include/polymer/Support/ScopStmt.h +++ b/tools/polymer/include/polymer/Support/ScopStmt.h @@ -9,8 +9,8 @@ #include +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "llvm/ADT/SmallVector.h" - namespace mlir { class Operation; class FlatAffineValueConstraints; @@ -44,7 +44,7 @@ class ScopStmt { void getEnclosingOps(llvm::SmallVectorImpl &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 diff --git a/tools/polymer/include/polymer/Target/OpenScop.h b/tools/polymer/include/polymer/Target/OpenScop.h index efd4d7e34606..42a9f3e8d754 100644 --- a/tools/polymer/include/polymer/Target/OpenScop.h +++ b/tools/polymer/include/polymer/Target/OpenScop.h @@ -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" @@ -31,7 +32,7 @@ namespace polymer { class OslScop; class OslSymbolTable; -std::unique_ptr createOpenScopFromFuncOp(mlir::FuncOp funcOp, +std::unique_ptr createOpenScopFromFuncOp(mlir::func::FuncOp funcOp, OslSymbolTable &symTable); /// Create a function (FuncOp) from the given OpenScop object in the given diff --git a/tools/polymer/include/polymer/Transforms/Passes.td b/tools/polymer/include/polymer/Transforms/Passes.td index 3e6ff9a70304..9c9ed4ae7f7d 100644 --- a/tools/polymer/include/polymer/Transforms/Passes.td +++ b/tools/polymer/include/polymer/Transforms/Passes.td @@ -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()"; diff --git a/tools/polymer/lib/Support/OslScop.cc b/tools/polymer/lib/Support/OslScop.cc index 11c091fe5ec3..bd82644efee9 100644 --- a/tools/polymer/lib/Support/OslScop.cc +++ b/tools/polymer/lib/Support/OslScop.cc @@ -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 ivs; @@ -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(); diff --git a/tools/polymer/lib/Support/OslScopStmtOpSet.cc b/tools/polymer/lib/Support/OslScopStmtOpSet.cc index dc1b2e16c805..5800394c6d49 100644 --- a/tools/polymer/lib/Support/OslScopStmtOpSet.cc +++ b/tools/polymer/lib/Support/OslScopStmtOpSet.cc @@ -36,7 +36,7 @@ LogicalResult OslScopStmtOpSet::getEnclosingOps( for (auto op : opSet) { if (isa(op)) { ops.clear(); - getEnclosingAffineForAndIfOps(*op, &ops); + getEnclosingAffineOps(*op, &ops); for (auto enclosingOp : ops) { if (visited.find(enclosingOp) == visited.end()) { visited.insert(enclosingOp); diff --git a/tools/polymer/lib/Support/ScopStmt.cc b/tools/polymer/lib/Support/ScopStmt.cc index 45947c523bf9..3b48578ebf39 100644 --- a/tools/polymer/lib/Support/ScopStmt.cc +++ b/tools/polymer/lib/Support/ScopStmt.cc @@ -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" @@ -35,7 +35,7 @@ class ScopStmtImpl { using EnclosingOpList = SmallVector; 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 get(mlir::Operation *callerOp, @@ -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. @@ -66,9 +66,9 @@ class ScopStmtImpl { std::unique_ptr 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(callerOp); - mlir::FuncOp callee = cast(calleeOp); + mlir::func::FuncOp callee = cast(calleeOp); llvm::StringRef name = caller.getCallee(); // Create the stmt instance. @@ -95,7 +95,7 @@ static void promoteSymbolToTopLevel(mlir::Value val, FlatAffineValueConstraints &domain, llvm::DenseMap &symMap) { BlockArgument arg = findTopLevelBlockArgument(val); - assert(isa(arg.getOwner()->getParentOp()) && + assert(isa(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. @@ -185,7 +185,7 @@ void ScopStmt::getEnclosingOps(llvm::SmallVectorImpl &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) { diff --git a/tools/polymer/lib/Target/OpenScop/ConvertFromOpenScop.cc b/tools/polymer/lib/Target/OpenScop/ConvertFromOpenScop.cc index b2f5b5c2717e..a2c2be5a885c 100644 --- a/tools/polymer/lib/Target/OpenScop/ConvertFromOpenScop.cc +++ b/tools/polymer/lib/Target/OpenScop/ConvertFromOpenScop.cc @@ -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" @@ -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 &operands, @@ -470,7 +468,7 @@ class Importer { /// A helper to create a callee. void createCalleeAndCallerArgs(llvm::StringRef calleeName, llvm::ArrayRef args, - mlir::FuncOp &callee, + mlir::func::FuncOp &callee, SmallVectorImpl &callerArgs); /// Number of internal functions created. @@ -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(sourceFuncOp) && - "Found sourceFuncOp should be of type mlir::FuncOp."); - return cast(sourceFuncOp); + assert(isa(sourceFuncOp) && + "Found sourceFuncOp should be of type mlir::func::FuncOp."); + return cast(sourceFuncOp); } /// If there is anything in the comment, we will use it as a function name. @@ -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()); @@ -673,7 +671,7 @@ void Importer::initializeSymbol(mlir::Value val) { hasInsertionPoint = true; b.setInsertionPointToStart(blockToInsert); } - } else if (mlir::FuncOp funOp = dyn_cast(parentOp)) { + } else if (mlir::func::FuncOp funOp = dyn_cast(parentOp)) { // Insert at the beginning of this function. hasInsertionPoint = true; b.setInsertionPointToStart(&entryBlock); @@ -769,7 +767,7 @@ Importer::parseUserStmtBody(llvm::StringRef body, std::string &calleeName, void Importer::createCalleeAndCallerArgs( llvm::StringRef calleeName, llvm::ArrayRef args, - mlir::FuncOp &callee, SmallVectorImpl &callerArgs) { + mlir::func::FuncOp &callee, SmallVectorImpl &callerArgs) { // TODO: avoid duplicated callee creation // Cache the current insertion point before changing it for the new callee // function. @@ -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::func::FuncOp func = b.create( forOp->getLoc(), std::string("T") + std::to_string(numInternalFunctions), funcTy); numInternalFunctions++; diff --git a/tools/polymer/lib/Target/OpenScop/ConvertToOpenScop.cc b/tools/polymer/lib/Target/OpenScop/ConvertToOpenScop.cc index c902569108c8..b24ba7ea9452 100644 --- a/tools/polymer/lib/Target/OpenScop/ConvertToOpenScop.cc +++ b/tools/polymer/lib/Target/OpenScop/ConvertToOpenScop.cc @@ -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" @@ -54,11 +53,12 @@ class OslScopBuilder { OslScopBuilder() {} /// Build a scop from a common FuncOp. - std::unique_ptr build(mlir::FuncOp f); + std::unique_ptr 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 @@ -79,7 +79,7 @@ static void sanityCheckDomain(FlatAffineValueConstraints &dom) { } /// Build OslScop from a given FuncOp. -std::unique_ptr OslScopBuilder::build(mlir::FuncOp f) { +std::unique_ptr OslScopBuilder::build(mlir::func::FuncOp f) { /// Context constraints. FlatAffineValueConstraints ctx; @@ -124,7 +124,7 @@ std::unique_ptr OslScopBuilder::build(mlir::FuncOp f) { llvm::SmallVector enclosingOps; stmt.getEnclosingOps(enclosingOps); // Get the callee. - mlir::FuncOp callee = stmt.getCallee(); + mlir::func::FuncOp callee = stmt.getCallee(); LLVM_DEBUG({ dbgs() << "Callee:\n"; @@ -173,7 +173,7 @@ std::unique_ptr 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(f->getParentOp()); @@ -181,7 +181,8 @@ void OslScopBuilder::buildScopStmtMap(mlir::FuncOp f, f.walk([&](mlir::Operation *op) { if (mlir::CallOp caller = dyn_cast(op)) { llvm::StringRef calleeName = caller.getCallee(); - mlir::FuncOp callee = m.lookupSymbol(calleeName); + mlir::func::FuncOp callee = + m.lookupSymbol(calleeName); // If the callee is of scop.stmt, we create a new instance in the map if (callee->getAttr(SCOP_STMT_ATTR_NAME)) { @@ -313,7 +314,8 @@ void OslScopBuilder::buildScopContext(OslScop *scop, } std::unique_ptr -polymer::createOpenScopFromFuncOp(mlir::FuncOp f, OslSymbolTable &symTable) { +polymer::createOpenScopFromFuncOp(mlir::func::FuncOp f, + OslSymbolTable &symTable) { return OslScopBuilder().build(f); } @@ -380,7 +382,8 @@ class ModuleEmitter : public OpenScopEmitterBase { }; LogicalResult ModuleEmitter::emitFuncOp( - mlir::FuncOp func, llvm::SmallVectorImpl> &scops) { + mlir::func::FuncOp func, + llvm::SmallVectorImpl> &scops) { OslSymbolTable symTable; auto scop = createOpenScopFromFuncOp(func, symTable); if (scop) @@ -393,7 +396,7 @@ void ModuleEmitter::emitMLIRModule( ModuleOp module, llvm::SmallVectorImpl> &scops) { // Emit a single OpenScop definition for each function. for (auto &op : *module.getBody()) { - if (auto func = dyn_cast(op)) { + if (auto func = dyn_cast(op)) { // Will only look at functions that are not attributed as scop.stmt if (func->getAttr(SCOP_STMT_ATTR_NAME)) continue; diff --git a/tools/polymer/lib/Transforms/AnnotateScop.cc b/tools/polymer/lib/Transforms/AnnotateScop.cc index dcb426b25f7f..d17c2949c75e 100644 --- a/tools/polymer/lib/Transforms/AnnotateScop.cc +++ b/tools/polymer/lib/Transforms/AnnotateScop.cc @@ -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" diff --git a/tools/polymer/lib/Transforms/ExtractScopStmt.cc b/tools/polymer/lib/Transforms/ExtractScopStmt.cc index d30cd018935c..967e11a9ccb7 100644 --- a/tools/polymer/lib/Transforms/ExtractScopStmt.cc +++ b/tools/polymer/lib/Transforms/ExtractScopStmt.cc @@ -12,13 +12,12 @@ #include "mlir/Dialect/Affine/Analysis/AffineStructures.h" #include "mlir/Dialect/Affine/IR/AffineOps.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/Dominance.h" -#include "mlir/IR/Function.h" #include "mlir/IR/OpImplementation.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/Types.h" @@ -44,7 +43,7 @@ using CalleeToCallersMap = /// Discover the operations that have memory write effects. /// TODO: support CallOp. -static void discoverMemWriteOps(mlir::FuncOp f, +static void discoverMemWriteOps(mlir::func::FuncOp f, SmallVectorImpl &ops) { f.getOperation()->walk([&](Operation *op) { if (isa(op)) @@ -57,7 +56,7 @@ static mlir::Value insertScratchpadForInterprocUses(mlir::Operation *defOp, mlir::Operation *defInCalleeOp, CalleeToCallersMap &calleeToCallers, - mlir::FuncOp topLevelFun, OpBuilder &b) { + mlir::func::FuncOp topLevelFun, OpBuilder &b) { assert(defOp->getNumResults() == 1); assert(topLevelFun.getBlocks().size() != 0); @@ -77,12 +76,12 @@ insertScratchpadForInterprocUses(mlir::Operation *defOp, // Give the callee an additional argument mlir::Operation *calleeOp = defInCalleeOp; while (calleeOp != nullptr) { - if (isa(calleeOp)) + if (isa(calleeOp)) break; calleeOp = calleeOp->getParentOp(); } - mlir::FuncOp callee = cast(calleeOp); + mlir::func::FuncOp callee = cast(calleeOp); mlir::Block &calleeEntryBlock = *callee.getBlocks().begin(); mlir::BlockArgument scratchpad = calleeEntryBlock.addArgument(memrefType, b.getUnknownLoc()); @@ -136,7 +135,7 @@ static Value getMemRef(Operation *op) { /// is later updated by a store op that dominates the current op. We should use /// a proper RAW checker for this purpose. static bool isUpdatedByDominatingStore(Operation *op, Operation *domOp, - mlir::FuncOp f) { + mlir::func::FuncOp f) { LLVM_DEBUG(dbgs() << " -- Checking if " << (*op) << " is updated by a store that dominates:\n" @@ -189,7 +188,7 @@ static void getScopStmtOps(Operation *writeOp, llvm::SetVector &args, OpToCalleeMap &opToCallee, CalleeToCallersMap &calleeToCallers, - mlir::FuncOp topLevelFun, OpBuilder &b) { + mlir::func::FuncOp topLevelFun, OpBuilder &b) { SmallVector worklist; worklist.push_back(writeOp); ops.insert(writeOp); @@ -286,7 +285,7 @@ static void getCalleeName(unsigned calleeId, CalleeName &calleeName, /// contents will be ops, and its type depends on the given list of args. This /// callee function has a single block in it, and it has no returned value. The /// callee will be inserted at the end of the whole module. -static mlir::FuncOp createCallee(StringRef calleeName, +static mlir::func::FuncOp createCallee(StringRef calleeName, const llvm::SetVector &ops, const llvm::SetVector &args, mlir::ModuleOp m, Operation *writeOp, @@ -306,8 +305,8 @@ static mlir::FuncOp createCallee(StringRef calleeName, b.setInsertionPoint(m.getBody(), std::prev(m.getBody()->end())); // Create the callee. Its loc is determined by the writeOp. - mlir::FuncOp callee = - b.create(writeOp->getLoc(), calleeName, calleeType); + mlir::func::FuncOp callee = + b.create(writeOp->getLoc(), calleeName, calleeType); mlir::Block *entryBlock = callee.addEntryBlock(); b.setInsertionPointToStart(entryBlock); // Terminator @@ -366,7 +365,7 @@ static mlir::FuncOp createCallee(StringRef calleeName, /// Create a caller to the callee right after the writeOp, which will be removed /// later. -static mlir::func::CallOp createCaller(mlir::FuncOp callee, +static mlir::func::CallOp createCaller(mlir::func::FuncOp callee, const llvm::SetVector &args, Operation *writeOp, OpBuilder &b) { // llvm::errs() << "Create caller for: " << callee.getName() << "\n"; @@ -395,7 +394,7 @@ static void removeExtractedOps(llvm::SetVector &opsToRemove) { /// The main function that extracts scop statements as functions. Returns the /// number of callees extracted from this function. -static unsigned extractScopStmt(mlir::FuncOp f, unsigned numCallees, +static unsigned extractScopStmt(mlir::func::FuncOp f, unsigned numCallees, OpBuilder &b) { // First discover those write ops that will be the "terminator" of each scop // statement in the given function. @@ -432,7 +431,7 @@ static unsigned extractScopStmt(mlir::FuncOp f, unsigned numCallees, getCalleeName(i + numCallees, calleeName); // Create the callee. - mlir::FuncOp callee = + mlir::func::FuncOp callee = createCallee(calleeName, ops, args, m, writeOp, opToCallee, b); // Create the caller. mlir::func::CallOp caller = createCaller(callee, args, writeOp, b); @@ -455,7 +454,7 @@ static unsigned extractScopStmt(mlir::FuncOp f, unsigned numCallees, /// Given a value, if any of its uses is a StoreOp, we try to replace other uses /// by a load from that store. -static void replaceUsesByStored(mlir::FuncOp f, OpBuilder &b) { +static void replaceUsesByStored(mlir::func::FuncOp f, OpBuilder &b) { SmallVector storeOps; f.walk([&](Operation *op) { @@ -516,15 +515,15 @@ class ExtractScopStmtPass mlir::ModuleOp m = getOperation(); OpBuilder b(m.getContext()); - SmallVector funcs; - m.walk([&](mlir::FuncOp f) { + SmallVector funcs; + m.walk([&](mlir::func::FuncOp f) { if (f->hasAttr("scop.ignored")) return; funcs.push_back(f); }); unsigned numCallees = 0; - for (mlir::FuncOp f : funcs) { + for (mlir::func::FuncOp f : funcs) { replaceUsesByStored(f, b); numCallees += extractScopStmt(f, numCallees, b); diff --git a/tools/polymer/lib/Transforms/FoldSCFIf.cc b/tools/polymer/lib/Transforms/FoldSCFIf.cc index 4f275509fa4f..626b2e6d73f9 100644 --- a/tools/polymer/lib/Transforms/FoldSCFIf.cc +++ b/tools/polymer/lib/Transforms/FoldSCFIf.cc @@ -11,7 +11,7 @@ #include "mlir/Dialect/Affine/Passes.h" #include "mlir/Dialect/Affine/Utils.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" -#include "mlir/Dialect/SCF/SCF.h" +#include "mlir/Dialect/SCF/IR/SCF.h" #include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Builders.h" #include "mlir/IR/Dominance.h" diff --git a/tools/polymer/lib/Transforms/PlutoTransform.cc b/tools/polymer/lib/Transforms/PlutoTransform.cc index 5682da6eff17..c293c7e6ddb1 100644 --- a/tools/polymer/lib/Transforms/PlutoTransform.cc +++ b/tools/polymer/lib/Transforms/PlutoTransform.cc @@ -69,7 +69,7 @@ struct PlutoOptPipelineOptions /// The main function that implements the Pluto based optimization. /// TODO: transform options? -static mlir::FuncOp plutoTransform(mlir::FuncOp f, OpBuilder &rewriter, +static mlir::func::FuncOp plutoTransform(mlir::func::FuncOp f, OpBuilder &rewriter, std::string dumpClastAfterPluto, bool parallelize = false, bool debug = false, int cloogf = -1, int cloogl = -1, @@ -123,7 +123,7 @@ static mlir::FuncOp plutoTransform(mlir::FuncOp f, OpBuilder &rewriter, SmallVector argAttrs; f.getAllArgAttrs(argAttrs); - mlir::FuncOp g = cast(createFuncOpFromOpenScop( + mlir::func::FuncOp g = cast(createFuncOpFromOpenScop( std::move(scop), m, dstTable, rewriter.getContext(), prog, dumpClastAfterPlutoStr)); g.setAllArgAttrs(argAttrs); @@ -156,17 +156,17 @@ class PlutoTransformPass mlir::ModuleOp m = getOperation(); mlir::OpBuilder b(m.getContext()); - SmallVector funcOps; - llvm::DenseMap funcMap; + SmallVector funcOps; + llvm::DenseMap funcMap; - m.walk([&](mlir::FuncOp f) { + m.walk([&](mlir::func::FuncOp f) { if (!f->getAttr("scop.stmt") && !f->hasAttr("scop.ignored")) { funcOps.push_back(f); } }); - for (mlir::FuncOp f : funcOps) - if (mlir::FuncOp g = + for (mlir::func::FuncOp f : funcOps) + if (mlir::func::FuncOp g = plutoTransform(f, b, dumpClastAfterPluto, parallelize, debug, cloogf, cloogl, diamondTiling)) { funcMap[f] = g; @@ -177,7 +177,7 @@ class PlutoTransformPass // Finally, we delete the definition of the original function, and make the // Pluto optimized version have the same name. for (const auto &it : funcMap) { - mlir::FuncOp from, to; + mlir::func::FuncOp from, to; std::tie(from, to) = it; to.setName(std::string(from.getName())); @@ -191,7 +191,7 @@ class PlutoTransformPass // -------------------------- PlutoParallelizePass ---------------------------- /// Find a single affine.for with scop.parallelizable attr. -static mlir::AffineForOp findParallelizableLoop(mlir::FuncOp f) { +static mlir::AffineForOp findParallelizableLoop(mlir::func::FuncOp f) { mlir::AffineForOp ret = nullptr; f.walk([&ret](mlir::AffineForOp forOp) { if (!ret && forOp->hasAttr("scop.parallelizable")) @@ -253,7 +253,7 @@ static bool isBoundParallelizable(mlir::AffineForOp forOp) { /// Iteratively replace affine.for with scop.parallelizable with /// affine.parallel. -static void plutoParallelize(mlir::FuncOp f, OpBuilder b) { +static void plutoParallelize(mlir::func::FuncOp f, OpBuilder b) { mlir::AffineForOp forOp = nullptr; while ((forOp = findParallelizableLoop(f)) != nullptr) { if (!isBoundParallelizable(forOp)) @@ -268,7 +268,7 @@ namespace { /// affine.parallel operation. struct PlutoParallelizePass : public mlir::PassWrapper> { + OperationPass> { void runOnOperation() override { FuncOp f = getOperation(); OpBuilder b(f.getContext()); @@ -306,7 +306,7 @@ static void dedupIndexCast(FuncOp f) { namespace { struct DedupIndexCastPass : public mlir::PassWrapper> { + OperationPass> { void runOnOperation() override { dedupIndexCast(getOperation()); } }; } // namespace diff --git a/tools/polymer/lib/Transforms/Reg2Mem.cc b/tools/polymer/lib/Transforms/Reg2Mem.cc index 5387746fae21..8e433df75b8a 100644 --- a/tools/polymer/lib/Transforms/Reg2Mem.cc +++ b/tools/polymer/lib/Transforms/Reg2Mem.cc @@ -13,12 +13,11 @@ #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Affine/Passes.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/Function.h" #include "mlir/IR/IntegerSet.h" #include "mlir/IR/OpImplementation.h" #include "mlir/IR/Types.h" @@ -48,7 +47,7 @@ using DefToUsesMap = /// Note that we only care about those values that are on the use-def chain that /// ends up with an affine write operation, or one with side effects. We also /// ignore all the def-use pairs that are in the same block. -static void mapDefToUses(mlir::FuncOp f, DefToUsesMap &defToUses) { +static void mapDefToUses(mlir::func::FuncOp f, DefToUsesMap &defToUses) { f.walk([&](mlir::Operation *useOp) { // Op that belongs to AffineWriteOpInterface (e.g., affine.store) or has // recursive side effects will be treated as . @@ -178,7 +177,7 @@ static mlir::AffineLoadOp createScratchpadLoadOp(memref::AllocaOp allocaOp, std::vector()); } -static void demoteRegisterToMemory(mlir::FuncOp f, OpBuilder &b) { +static void demoteRegisterToMemory(mlir::func::FuncOp f, OpBuilder &b) { if (f.getBlocks().size() == 0) return; @@ -261,7 +260,7 @@ static IntegerSet getIntegerSetForElse(const IntegerSet &iSet, OpBuilder &b) { /// Turns affine.if with else block into two affine.if. It works iteratively: /// one affine.if op (with else) should be handled at one time. -static void separateAffineIfBlocks(mlir::FuncOp f, OpBuilder &b) { +static void separateAffineIfBlocks(mlir::func::FuncOp f, OpBuilder &b) { // Get the first affine.if operation that has an else block. auto findIfWithElse = [&](auto &f) { Operation *opFound = nullptr; @@ -307,11 +306,11 @@ static void separateAffineIfBlocks(mlir::FuncOp f, OpBuilder &b) { namespace { class RegToMemPass - : public mlir::PassWrapper> { + : public mlir::PassWrapper> { public: void runOnOperation() override { - mlir::FuncOp f = getOperation(); + mlir::func::FuncOp f = getOperation(); auto builder = OpBuilder(f.getContext()); if (f->hasAttr("scop.ignored")) @@ -325,7 +324,7 @@ class RegToMemPass } // namespace /// TODO: value analysis -static void insertRedundantLoad(mlir::FuncOp f, OpBuilder &b) { +static void insertRedundantLoad(mlir::func::FuncOp f, OpBuilder &b) { DominanceInfo dom(f); SmallVector storeOps; @@ -389,11 +388,11 @@ static void insertRedundantLoad(mlir::FuncOp f, OpBuilder &b) { namespace { class InsertRedundantLoadPass : public mlir::PassWrapper> { + OperationPass> { public: void runOnOperation() override { - mlir::FuncOp f = getOperation(); + mlir::func::FuncOp f = getOperation(); OpBuilder b(f.getContext()); insertRedundantLoad(f, b); @@ -406,7 +405,7 @@ namespace { using IterArgToMemMap = llvm::MapVector; } -static void findReductionLoops(mlir::FuncOp f, +static void findReductionLoops(mlir::func::FuncOp f, SmallVectorImpl &forOps) { f.walk([&](mlir::AffineForOp forOp) { if (!forOp.getIterOperands().empty()) @@ -508,7 +507,7 @@ static mlir::AffineForOp cloneAffineForWithoutIterArgs(mlir::AffineForOp forOp, return newForOp; } -static void demoteLoopReduction(mlir::FuncOp f, mlir::AffineForOp forOp, +static void demoteLoopReduction(mlir::func::FuncOp f, mlir::AffineForOp forOp, OpBuilder &b) { SmallVector initVals{forOp.getIterOperands()}; mlir::Block *body = forOp.getBody(); @@ -534,7 +533,7 @@ static void demoteLoopReduction(mlir::FuncOp f, mlir::AffineForOp forOp, forOp.erase(); } -static void demoteLoopReduction(mlir::FuncOp f, OpBuilder &b) { +static void demoteLoopReduction(mlir::func::FuncOp f, OpBuilder &b) { SmallVector forOps; findReductionLoops(f, forOps); @@ -545,10 +544,10 @@ static void demoteLoopReduction(mlir::FuncOp f, OpBuilder &b) { namespace { class DemoteLoopReductionPass : public mlir::PassWrapper> { + OperationPass> { public: void runOnOperation() override { - mlir::FuncOp f = getOperation(); + mlir::func::FuncOp f = getOperation(); OpBuilder b(f.getContext()); demoteLoopReduction(f, b); @@ -559,7 +558,7 @@ class DemoteLoopReductionPass /// ---------------- Array Expansion ------------------- -static void findAllScratchpads(mlir::FuncOp f, +static void findAllScratchpads(mlir::func::FuncOp f, SmallVector &spads) { // All scratchpads are allocated by AllocaOp. f.walk([&](memref::AllocaOp op) { @@ -730,7 +729,7 @@ static void getLowerOrUpperBound(unsigned int dimId, bool isUpper, affMap = mlir::AffineMap::get(0, operands.size(), exprs, b.getContext()); } -static mlir::Value findInsertionPointAfter(mlir::FuncOp f, mlir::Value spad, +static mlir::Value findInsertionPointAfter(mlir::func::FuncOp f, mlir::Value spad, ArrayRef candidates) { DominanceInfo dom(f); for (auto v1 : candidates) { @@ -755,7 +754,7 @@ static mlir::Value findInsertionPointAfter(mlir::FuncOp f, mlir::Value spad, } static memref::AllocaOp -createScratchpadAllocaOp(mlir::FuncOp f, mlir::Value spad, +createScratchpadAllocaOp(mlir::func::FuncOp f, mlir::Value spad, const FlatAffineValueConstraints &domain, OpBuilder &b) { OpBuilder::InsertionGuard guard(b); @@ -792,7 +791,7 @@ createScratchpadAllocaOp(mlir::FuncOp f, mlir::Value spad, return b.create(spad.getLoc(), memRefType, memSizes); } -static void resetLoadAndStoreOpsToScratchpad(mlir::FuncOp f, mlir::Value spad, +static void resetLoadAndStoreOpsToScratchpad(mlir::func::FuncOp f, mlir::Value spad, OpBuilder &b) { OpBuilder::InsertionGuard guard(b); @@ -845,7 +844,7 @@ static void resetLoadAndStoreOpsToScratchpad(mlir::FuncOp f, mlir::Value spad, /// Expand scratchpad based on its deepest/widest loop nest. /// TODO: allow expansion to a specific depth. -static void expandScratchpad(mlir::FuncOp f, mlir::Value spad, OpBuilder &b) { +static void expandScratchpad(mlir::func::FuncOp f, mlir::Value spad, OpBuilder &b) { mlir::SmallVector domains; getScratchpadIterDomains(spad, domains); FlatAffineValueConstraints unionDomain = unionScratchpadIterDomains(domains); @@ -857,7 +856,7 @@ static void expandScratchpad(mlir::FuncOp f, mlir::Value spad, OpBuilder &b) { spad.getDefiningOp()->erase(); } -static void arrayExpansion(mlir::FuncOp f, OpBuilder &b) { +static void arrayExpansion(mlir::func::FuncOp f, OpBuilder &b) { SmallVector spads; findAllScratchpads(f, spads); for (mlir::Value spad : spads) @@ -867,10 +866,10 @@ static void arrayExpansion(mlir::FuncOp f, OpBuilder &b) { namespace { class ArrayExpansionPass : public mlir::PassWrapper> { + OperationPass> { public: void runOnOperation() override { - mlir::FuncOp f = getOperation(); + mlir::func::FuncOp f = getOperation(); OpBuilder b(f.getContext()); arrayExpansion(f, b); diff --git a/tools/polymer/lib/Transforms/ScopStmtOpt.cc b/tools/polymer/lib/Transforms/ScopStmtOpt.cc index 72fb35b4356b..63b0b0cf7668 100644 --- a/tools/polymer/lib/Transforms/ScopStmtOpt.cc +++ b/tools/polymer/lib/Transforms/ScopStmtOpt.cc @@ -9,7 +9,7 @@ #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Affine/IR/AffineValueMap.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" diff --git a/tools/polymer/tools/polymer-opt/polymer-opt.cc b/tools/polymer/tools/polymer-opt/polymer-opt.cc index 6c331f6d8c85..273b4c0e7f27 100644 --- a/tools/polymer/tools/polymer-opt/polymer-opt.cc +++ b/tools/polymer/tools/polymer-opt/polymer-opt.cc @@ -16,12 +16,12 @@ #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Affine/Passes.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/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/Math/IR/Math.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" -#include "mlir/Dialect/SCF/SCF.h" +#include "mlir/Dialect/SCF/IR/SCF.h" #include "mlir/IR/AsmState.h" #include "mlir/Pass/Pass.h" #include "mlir/Pass/PassManager.h" diff --git a/tools/polymer/tools/polymer-translate/polymer-translate.cc b/tools/polymer/tools/polymer-translate/polymer-translate.cc index 32ec5da90e25..38aab077c101 100644 --- a/tools/polymer/tools/polymer-translate/polymer-translate.cc +++ b/tools/polymer/tools/polymer-translate/polymer-translate.cc @@ -13,14 +13,13 @@ #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" -#include "mlir/Dialect/SCF/SCF.h" +#include "mlir/Dialect/SCF/IR/SCF.h" #include "mlir/IR/AsmState.h" #include "mlir/IR/Diagnostics.h" #include "mlir/IR/Dialect.h" #include "mlir/IR/MLIRContext.h" #include "mlir/Support/FileUtilities.h" #include "mlir/Support/ToolUtilities.h" -#include "mlir/Translation.h" using namespace mlir; using namespace polymer;