From 40a150d373d48315adb258bba7f31f0e719dabad Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Wed, 2 Mar 2022 01:23:07 -0500 Subject: [PATCH 01/14] Add type align --- llvm-project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm-project b/llvm-project index 78fb4f9d5dd9..3a880f23d782 160000 --- a/llvm-project +++ b/llvm-project @@ -1 +1 @@ -Subproject commit 78fb4f9d5dd95d26424919f2da184e1119ccb023 +Subproject commit 3a880f23d7825278d14dd1a6d14d8f625ee40f12 From 6f5df456ea0439bcc4c1000025eaba5a959b36ed Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Wed, 2 Mar 2022 01:35:42 -0500 Subject: [PATCH 02/14] Add align --- llvm-project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm-project b/llvm-project index 3a880f23d782..78fb4f9d5dd9 160000 --- a/llvm-project +++ b/llvm-project @@ -1 +1 @@ -Subproject commit 3a880f23d7825278d14dd1a6d14d8f625ee40f12 +Subproject commit 78fb4f9d5dd95d26424919f2da184e1119ccb023 From 4de6ddae8a27d01cb11b77aab244bbf451abc3f1 Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Wed, 2 Mar 2022 11:26:14 -0500 Subject: [PATCH 03/14] Increase --- include/polygeist/BarrierUtils.h | 2 +- include/polygeist/Passes/Passes.h | 5 +- include/polygeist/Passes/Passes.td | 6 +- lib/polygeist/Ops.cpp | 2 +- .../Passes/BarrierRemovalContinuation.cpp | 4 +- lib/polygeist/Passes/CMakeLists.txt | 4 +- lib/polygeist/Passes/CanonicalizeFor.cpp | 3 +- .../Passes/ConvertPolygeistToLLVM.cpp | 4 +- lib/polygeist/Passes/LoopRestructure.cpp | 2 +- lib/polygeist/Passes/Mem2Reg.cpp | 10 +- .../Passes/ParallelLoopDistribute.cpp | 2 +- lib/polygeist/Passes/ParallelLower.cpp | 9 +- lib/polygeist/Passes/RaiseToAffine.cpp | 4 +- llvm-project | 2 +- tools/mlir-clang/Lib/CGCall.cc | 5 +- tools/mlir-clang/Lib/ValueCategory.cc | 2 +- tools/mlir-clang/Lib/clang-mlir.cc | 108 +----------------- tools/mlir-clang/Lib/clang-mlir.h | 2 +- tools/mlir-clang/Test/Verification/size.c | 18 +++ tools/mlir-clang/mlir-clang.cc | 2 +- 20 files changed, 62 insertions(+), 134 deletions(-) create mode 100644 tools/mlir-clang/Test/Verification/size.c diff --git a/include/polygeist/BarrierUtils.h b/include/polygeist/BarrierUtils.h index aca0b329229c..c76499ef212d 100644 --- a/include/polygeist/BarrierUtils.h +++ b/include/polygeist/BarrierUtils.h @@ -13,7 +13,7 @@ #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/SCF/SCF.h" -#include "mlir/Dialect/StandardOps/IR/Ops.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/Block.h" #include "polygeist/Ops.h" #include "llvm/ADT/SetVector.h" diff --git a/include/polygeist/Passes/Passes.h b/include/polygeist/Passes/Passes.h index 7a4fe27c5be4..af0a61178197 100644 --- a/include/polygeist/Passes/Passes.h +++ b/include/polygeist/Passes/Passes.h @@ -40,8 +40,11 @@ namespace memref { class MemRefDialect; } // end namespace memref +namespace func { +class FuncDialect; +} + class AffineDialect; -class StandardOpsDialect; namespace LLVM { class LLVMDialect; } diff --git a/include/polygeist/Passes/Passes.td b/include/polygeist/Passes/Passes.td index 965046c1f84a..c7741b9867bd 100644 --- a/include/polygeist/Passes/Passes.td +++ b/include/polygeist/Passes/Passes.td @@ -16,7 +16,7 @@ def Mem2Reg : Pass<"mem2reg", "FuncOp"> { def ParallelLower : Pass<"parallel-lower", "mlir::ModuleOp"> { let summary = "Replace scf.if and similar with affine.if"; let dependentDialects = - ["memref::MemRefDialect", "StandardOpsDialect", "LLVM::LLVMDialect"]; + ["memref::MemRefDialect", "func::FuncDialect", "LLVM::LLVMDialect"]; let constructor = "mlir::polygeist::createParallelLowerPass()"; } @@ -29,7 +29,7 @@ def SCFCPUify : Pass<"cpuify", "FuncOp"> { let summary = "remove scf.barrier"; let constructor = "mlir::polygeist::createCPUifyPass()"; let dependentDialects = - ["memref::MemRefDialect", "StandardOpsDialect", "LLVM::LLVMDialect"]; + ["memref::MemRefDialect", "func::FuncDialect", "LLVM::LLVMDialect"]; let options = [ Option<"method", "method", "std::string", /*default=*/"\"distribute\"", "Method of doing distribution"> ]; @@ -38,7 +38,7 @@ def SCFCPUify : Pass<"cpuify", "FuncOp"> { def SCFBarrierRemovalContinuation : Pass<"barrier-removal-continuation", "FuncOp"> { let summary = "Remove scf.barrier using continuations"; let constructor = "mlir::polygeist::createBarrierRemovalContinuation()"; - let dependentDialects = ["memref::MemRefDialect", "StandardOpsDialect"]; + let dependentDialects = ["memref::MemRefDialect", "func::FuncDialect"]; } def SCFRaiseToAffine : Pass<"raise-scf-to-affine", "FuncOp"> { diff --git a/lib/polygeist/Ops.cpp b/lib/polygeist/Ops.cpp index 774b2d584ca9..c7812e1c04b1 100644 --- a/lib/polygeist/Ops.cpp +++ b/lib/polygeist/Ops.cpp @@ -22,7 +22,7 @@ #include "mlir/Dialect/Arithmetic/Utils/Utils.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/SCF/SCF.h" -#include "mlir/Dialect/StandardOps/IR/Ops.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/BlockAndValueMapping.h" using namespace mlir; diff --git a/lib/polygeist/Passes/BarrierRemovalContinuation.cpp b/lib/polygeist/Passes/BarrierRemovalContinuation.cpp index f96001d19814..af0bbf0014ff 100644 --- a/lib/polygeist/Passes/BarrierRemovalContinuation.cpp +++ b/lib/polygeist/Passes/BarrierRemovalContinuation.cpp @@ -19,7 +19,7 @@ #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/SCF/Passes.h" #include "mlir/Dialect/SCF/SCF.h" -#include "mlir/Dialect/StandardOps/IR/Ops.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/Dominance.h" @@ -78,7 +78,7 @@ static LogicalResult applyCFGConversion(FuncOp function) { // Configure the target to preserve parallel ops with barriers, unless those // barriers are nested in deeper parallel ops. ConversionTarget target(*function.getContext()); - target.addLegalDialect(); + target.addLegalDialect(); target.addLegalDialect(); target.addIllegalOp(); target.addLegalOp(); diff --git a/lib/polygeist/Passes/CMakeLists.txt b/lib/polygeist/Passes/CMakeLists.txt index 9c10f356bf8b..0e25b54ca869 100644 --- a/lib/polygeist/Passes/CMakeLists.txt +++ b/lib/polygeist/Passes/CMakeLists.txt @@ -21,6 +21,8 @@ add_mlir_dialect_library(MLIRPolygeistTransforms LINK_LIBS PUBLIC MLIRAffine MLIRAffineUtils + MLIRFunc + MLIRFuncTransforms MLIRGPUOps MLIRIR MLIRLLVMIR @@ -29,8 +31,6 @@ add_mlir_dialect_library(MLIRPolygeistTransforms MLIRPass MLIRPolygeist MLIRSideEffectInterfaces - MLIRStandard - MLIRStandardOpsTransforms MLIRSCFToControlFlow MLIRTransformUtils ) diff --git a/lib/polygeist/Passes/CanonicalizeFor.cpp b/lib/polygeist/Passes/CanonicalizeFor.cpp index 9f371af75575..2b051c89a83f 100644 --- a/lib/polygeist/Passes/CanonicalizeFor.cpp +++ b/lib/polygeist/Passes/CanonicalizeFor.cpp @@ -2,7 +2,7 @@ #include "mlir/Dialect/SCF/Passes.h" #include "mlir/Dialect/SCF/SCF.h" -#include "mlir/Dialect/StandardOps/IR/Ops.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Dominance.h" #include "mlir/IR/Matchers.h" @@ -12,6 +12,7 @@ using namespace mlir; using namespace mlir::scf; +using namespace mlir::func; using namespace mlir::arith; using namespace polygeist; diff --git a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp index ceef2c249efe..84786067d801 100644 --- a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp +++ b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp @@ -22,8 +22,8 @@ #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/LLVMIR/LLVMTypes.h" #include "mlir/Dialect/OpenMP/OpenMPDialect.h" -#include "mlir/Dialect/StandardOps/IR/Ops.h" -#include "mlir/Dialect/StandardOps/Transforms/Passes.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" +#include "mlir/Dialect/Func/Transforms/Passes.h" #include "polygeist/Ops.h" #define DEBUG_TYPE "convert-polygeist-to-llvm" diff --git a/lib/polygeist/Passes/LoopRestructure.cpp b/lib/polygeist/Passes/LoopRestructure.cpp index 60d72c7addb2..47f69b432c13 100644 --- a/lib/polygeist/Passes/LoopRestructure.cpp +++ b/lib/polygeist/Passes/LoopRestructure.cpp @@ -12,7 +12,7 @@ #include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/SCF/SCF.h" -#include "mlir/Dialect/StandardOps/IR/Ops.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/Builders.h" #include "mlir/IR/Dominance.h" #include "mlir/IR/PatternMatch.h" diff --git a/lib/polygeist/Passes/Mem2Reg.cpp b/lib/polygeist/Passes/Mem2Reg.cpp index fdf0fca1e811..cd1818f8a47a 100644 --- a/lib/polygeist/Passes/Mem2Reg.cpp +++ b/lib/polygeist/Passes/Mem2Reg.cpp @@ -20,7 +20,7 @@ #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/SCF/SCF.h" -#include "mlir/Dialect/StandardOps/IR/Ops.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/Dominance.h" #include "mlir/Support/LLVM.h" #include "mlir/Transforms/Passes.h" @@ -1057,7 +1057,7 @@ bool Mem2Reg::forwardStoreToLoad(mlir::Value AI, std::vector idx, AliasingStoreOperations.insert(storeOp); continue; } - if (auto callOp = dyn_cast(user)) { + if (auto callOp = dyn_cast(user)) { if (callOp.getCallee() != "free") { LLVM_DEBUG(llvm::dbgs() << "Aliasing Store: " << callOp << "\n"); AliasingStoreOperations.insert(callOp); @@ -1697,9 +1697,9 @@ bool isPromotable(mlir::Value AI) { continue; } else if (isa(U)) { continue; - } else if (isa(U) && cast(U).getCallee() == "free") { + } else if (isa(U) && cast(U).getCallee() == "free") { continue; - } else if (isa(U)) { + } else if (isa(U)) { // TODO check "no capture", currently assume as a fallback always // nocapture continue; @@ -1891,7 +1891,7 @@ void Mem2Reg::runOnOperation() { toErase.push_back(U); } else if (isa(U)) { toErase.push_back(U); - } else if (isa(U) && cast(U).getCallee() == "free") { + } else if (isa(U) && cast(U).getCallee() == "free") { toErase.push_back(U); } else if (auto CO = dyn_cast(U)) { toErase.push_back(U); diff --git a/lib/polygeist/Passes/ParallelLoopDistribute.cpp b/lib/polygeist/Passes/ParallelLoopDistribute.cpp index 5067336a0a61..53dbc9eb848e 100644 --- a/lib/polygeist/Passes/ParallelLoopDistribute.cpp +++ b/lib/polygeist/Passes/ParallelLoopDistribute.cpp @@ -10,10 +10,10 @@ #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/OpenMP/OpenMPDialect.h" #include "mlir/Dialect/SCF/Passes.h" #include "mlir/Dialect/SCF/SCF.h" -#include "mlir/Dialect/StandardOps/IR/Ops.h" #include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Dominance.h" #include "mlir/IR/ImplicitLocOpBuilder.h" diff --git a/lib/polygeist/Passes/ParallelLower.cpp b/lib/polygeist/Passes/ParallelLower.cpp index d236450ae2c4..4348ddce37e2 100644 --- a/lib/polygeist/Passes/ParallelLower.cpp +++ b/lib/polygeist/Passes/ParallelLower.cpp @@ -19,7 +19,7 @@ #include "mlir/Dialect/LLVMIR/NVVMDialect.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/SCF/SCF.h" -#include "mlir/Dialect/StandardOps/IR/Ops.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/Dominance.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "mlir/Transforms/Passes.h" @@ -33,6 +33,7 @@ using namespace mlir; using namespace mlir::arith; +using namespace mlir::func; using namespace polygeist; namespace { @@ -119,7 +120,7 @@ struct AlwaysInlinerInterface : public InlinerInterface { /// as necessary. void handleTerminator(Operation *op, Block *newDest) const final { // Only "std.return" needs to be handled here. - auto returnOp = dyn_cast(op); + auto returnOp = dyn_cast(op); if (!returnOp) return; @@ -134,7 +135,7 @@ struct AlwaysInlinerInterface : public InlinerInterface { void handleTerminator(Operation *op, ArrayRef valuesToRepl) const final { // Only "std.return" needs to be handled here. - auto returnOp = cast(op); + auto returnOp = cast(op); // Replace the values directly with the return operands. assert(returnOp.getNumOperands() == valuesToRepl.size()); @@ -185,7 +186,7 @@ void ParallelLower::runOnOperation() { SymbolTableCollection symbolTable; symbolTable.getSymbolTable(getOperation()); - getOperation()->walk([&](mlir::CallOp bidx) { + getOperation()->walk([&](CallOp bidx) { if (bidx.getCallee() == "cudaThreadSynchronize") bidx.erase(); }); diff --git a/lib/polygeist/Passes/RaiseToAffine.cpp b/lib/polygeist/Passes/RaiseToAffine.cpp index 3a52c84d8084..b622bff133ea 100644 --- a/lib/polygeist/Passes/RaiseToAffine.cpp +++ b/lib/polygeist/Passes/RaiseToAffine.cpp @@ -5,7 +5,7 @@ #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/SCF/Passes.h" #include "mlir/Dialect/SCF/SCF.h" -#include "mlir/Dialect/StandardOps/IR/Ops.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/BlockAndValueMapping.h" #include "mlir/Transforms/DialectConversion.h" #include "polygeist/Passes/Passes.h" @@ -222,7 +222,7 @@ struct ParallelOpRaising : public OpRewritePattern { void RaiseSCFToAffine::runOnOperation() { ConversionTarget target(getContext()); target - .addLegalDialect(); + .addLegalDialect(); RewritePatternSet patterns(&getContext()); patterns.insert(&getContext()); diff --git a/llvm-project b/llvm-project index 78fb4f9d5dd9..8b35d382d3c8 160000 --- a/llvm-project +++ b/llvm-project @@ -1 +1 @@ -Subproject commit 78fb4f9d5dd95d26424919f2da184e1119ccb023 +Subproject commit 8b35d382d3c8cd579797df338ff16349dd57b068 diff --git a/tools/mlir-clang/Lib/CGCall.cc b/tools/mlir-clang/Lib/CGCall.cc index ad90223ec7bc..9f9689bc7938 100644 --- a/tools/mlir-clang/Lib/CGCall.cc +++ b/tools/mlir-clang/Lib/CGCall.cc @@ -16,6 +16,7 @@ using namespace mlir; using namespace std; using namespace mlir::arith; +using namespace mlir::func; using namespace mlirclang; /// Try to typecast the caller arg of type MemRef to fit the corresponding @@ -301,7 +302,7 @@ ValueCategory MLIRScanner::CallHelper( auto oldpoint = builder.getInsertionPoint(); auto oldblock = builder.getInsertionBlock(); builder.setInsertionPointToStart(&op.getRegion().front()); - builder.create(loc, tocall, args); + builder.create(loc, tocall, args); builder.create(loc); builder.setInsertionPoint(oldblock, oldpoint); return nullptr; @@ -310,7 +311,7 @@ ValueCategory MLIRScanner::CallHelper( // Try to rescue some mismatched types. castCallerArgs(tocall, args, builder); - auto op = builder.create(loc, tocall, args); + auto op = builder.create(loc, tocall, args); if (isArrayReturn) { // TODO remedy return diff --git a/tools/mlir-clang/Lib/ValueCategory.cc b/tools/mlir-clang/Lib/ValueCategory.cc index e1a06080eefc..53938d85b37e 100644 --- a/tools/mlir-clang/Lib/ValueCategory.cc +++ b/tools/mlir-clang/Lib/ValueCategory.cc @@ -10,7 +10,7 @@ #include "mlir/Dialect/Arithmetic/IR/Arithmetic.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" -#include "mlir/Dialect/StandardOps/IR/Ops.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/OpDefinition.h" #include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h" #include "polygeist/Ops.h" diff --git a/tools/mlir-clang/Lib/clang-mlir.cc b/tools/mlir-clang/Lib/clang-mlir.cc index 916077f00dbb..21cc2ab0cdc3 100644 --- a/tools/mlir-clang/Lib/clang-mlir.cc +++ b/tools/mlir-clang/Lib/clang-mlir.cc @@ -36,6 +36,7 @@ #include "clang/Sema/SemaDiagnostic.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" +#include "mlir/Target/LLVMIR/Import.h" using namespace std; using namespace clang; @@ -44,6 +45,7 @@ using namespace clang::driver; using namespace llvm::opt; using namespace mlir; using namespace mlir::arith; +using namespace mlir::func; using namespace mlirclang; #define DEBUG_TYPE "clang-mlir" @@ -283,9 +285,9 @@ void MLIRScanner::init(mlir::FuncOp function, const FunctionDecl *fd) { if (function.getType().getResults().size()) { mlir::Value vals[1] = { builder.create(loc, returnVal)}; - builder.create(loc, vals); + builder.create(loc, vals); } else - builder.create(loc); + builder.create(loc); assert(function->getParentOp() == Glob.module.get() && "New function must be inserted into global module"); @@ -4887,101 +4889,6 @@ mlir::Value MLIRScanner::getTypeAlign(clang::QualType t) { #include "clang/Frontend/TextDiagnosticBuffer.h" -static DenseIntElementsAttr -parseDataLayoutTriple(MLIRContext &ctx, StringRef first, StringRef rest) { - using namespace mlir; - auto i32 = mlir::IntegerType::get(&ctx, 32); - int bitwidth; - if (first.getAsInteger(/*Radix=*/10, bitwidth)) - return nullptr; - - StringRef abiString, preferredString; - std::tie(abiString, preferredString) = rest.split(':'); - int abi, preferred; - if (abiString.getAsInteger(/*Radix=*/10, abi)) - return nullptr; - - if (preferredString.empty()) - preferred = abi; - else if (preferredString.getAsInteger(/*Radix=*/10, preferred)) - return nullptr; - - return DenseIntElementsAttr::get(mlir::VectorType::get({3}, i32), - {bitwidth, abi, preferred}); -} - -FloatType getDLFloatType(MLIRContext &ctx, int32_t bitwidth) { - switch (bitwidth) { - case 16: - return mlir::FloatType::getF16(&ctx); - case 32: - return mlir::FloatType::getF32(&ctx); - case 64: - return mlir::FloatType::getF64(&ctx); - case 80: - return mlir::FloatType::getF80(&ctx); - case 128: - return mlir::FloatType::getF128(&ctx); - default: - return nullptr; - } -} - -DataLayoutSpecAttr translateDataLayout(MLIRContext &ctx, StringRef layout) { - using namespace mlir; - SmallVector entries; - while (!layout.empty()) { - // Split at '-'. - std::pair split = layout.split('-'); - StringRef current; - std::tie(current, layout) = split; - - // Split at ':'. - StringRef kind, spec; - std::tie(kind, spec) = current.split(':'); - - char symbol = kind.front(); - StringRef parameter = kind.substr(1); - - if (symbol == 'i') { - DenseIntElementsAttr params = parseDataLayoutTriple(ctx, parameter, spec); - if (!params) - return nullptr; - auto entry = DataLayoutEntryAttr::get( - mlir::IntegerType::get(&ctx, *params.getValues().begin()), - params); - entries.emplace_back(entry); - } else if (symbol == 'f') { - DenseIntElementsAttr params = parseDataLayoutTriple(ctx, parameter, spec); - if (!params) - return nullptr; - mlir::Type fltType = - getDLFloatType(ctx, *params.getValues().begin()); - if (!fltType) - return nullptr; - auto entry = DataLayoutEntryAttr::get(fltType, params); - entries.emplace_back(entry); - } else if (symbol == 'p') { - int addressSpace = 0; - if (!parameter.empty()) { - if (parameter.getAsInteger(/*Radix=*/10, addressSpace)) - return nullptr; - } - StringRef head, tail; - std::tie(head, tail) = spec.split(':'); - DenseIntElementsAttr params = parseDataLayoutTriple(ctx, head, tail); - if (!params) - return nullptr; - auto entry = DataLayoutEntryAttr::get( - LLVM::LLVMPointerType::get(mlir::IntegerType::get(&ctx, 8), - addressSpace), - params); - entries.emplace_back(entry); - } - } - return DataLayoutSpecAttr::get(&ctx, entries); -} - static bool parseMLIR(const char *Argv0, std::vector filenames, std::string fn, std::vector includeDirs, std::vector defines, @@ -5174,13 +5081,10 @@ static bool parseMLIR(const char *Argv0, std::vector filenames, LLVM::LLVMDialect::getDataLayoutAttrName(), StringAttr::get(module->getContext(), Clang->getTarget().getDataLayoutString())); - // TODO does not work - /* + module.get()->setAttr( ("dlti." + DataLayoutSpecAttr::kAttrKeyword).str(), - translateDataLayout(*module->getContext(), - Clang->getTarget().getDataLayoutString())); - */ + translateDataLayout(DL, module->getContext())); } for (const auto &FIF : Clang->getFrontendOpts().Inputs) { diff --git a/tools/mlir-clang/Lib/clang-mlir.h b/tools/mlir-clang/Lib/clang-mlir.h index 0178b92cf64c..de7da4f15490 100644 --- a/tools/mlir-clang/Lib/clang-mlir.h +++ b/tools/mlir-clang/Lib/clang-mlir.h @@ -24,7 +24,7 @@ #include "mlir/Dialect/LLVMIR/NVVMDialect.h" #include "mlir/Dialect/Math/IR/Math.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" -#include "mlir/Dialect/StandardOps/IR/Ops.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/Builders.h" #include "mlir/IR/MLIRContext.h" #include "mlir/IR/OpDefinition.h" diff --git a/tools/mlir-clang/Test/Verification/size.c b/tools/mlir-clang/Test/Verification/size.c new file mode 100644 index 000000000000..759b1ea13990 --- /dev/null +++ b/tools/mlir-clang/Test/Verification/size.c @@ -0,0 +1,18 @@ +// RUN: mlir-clang %s --function=* -S | FileCheck %s + +struct X { + int a; + long long b; +}; +struct Y { + int c; + struct X x; +}; +unsigned long long size() { + return sizeof(struct Y); +} + +// CHECK: func @size() -> i64 attributes {llvm.linkage = #llvm.linkage} { +// CHECK-NEXT: %c24_i64 = arith.constant 24 : i64 +// CHECK-NEXT: return %c24_i64 : i64 +// CHECK-NEXT: } diff --git a/tools/mlir-clang/mlir-clang.cc b/tools/mlir-clang/mlir-clang.cc index de30ee1ab1fd..cacebac9ac85 100644 --- a/tools/mlir-clang/mlir-clang.cc +++ b/tools/mlir-clang/mlir-clang.cc @@ -390,7 +390,7 @@ int main(int argc, char **argv) { context.disableMultithreading(); context.getOrLoadDialect(); - context.getOrLoadDialect(); + context.getOrLoadDialect(); context.getOrLoadDialect(); context.getOrLoadDialect(); context.getOrLoadDialect(); From f4d5a309abbae6b1067eaa19ce6e5412a157989b Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Wed, 2 Mar 2022 12:35:25 -0500 Subject: [PATCH 04/14] Bump LLVM --- llvm-project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm-project b/llvm-project index 8b35d382d3c8..ef9816e43c14 160000 --- a/llvm-project +++ b/llvm-project @@ -1 +1 @@ -Subproject commit 8b35d382d3c8cd579797df338ff16349dd57b068 +Subproject commit ef9816e43c1418da9b481dc750f04e8844f72ef5 From b6fc589f53c6e1a1faec0c2376c27b74b7580e13 Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Wed, 2 Mar 2022 13:02:12 -0500 Subject: [PATCH 05/14] Bump DL --- llvm-project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm-project b/llvm-project index ef9816e43c14..758ddba38113 160000 --- a/llvm-project +++ b/llvm-project @@ -1 +1 @@ -Subproject commit ef9816e43c1418da9b481dc750f04e8844f72ef5 +Subproject commit 758ddba38113b2ab48cd6e45d7617463969bf813 From ab7fa93da8b6d74d4a3a43314d10372ae2106909 Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Wed, 2 Mar 2022 13:29:54 -0500 Subject: [PATCH 06/14] format --- include/polygeist/BarrierUtils.h | 2 +- lib/polygeist/Ops.cpp | 2 +- lib/polygeist/Passes/BarrierRemovalContinuation.cpp | 2 +- lib/polygeist/Passes/CanonicalizeFor.cpp | 2 +- lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp | 4 ++-- lib/polygeist/Passes/LoopRestructure.cpp | 2 +- lib/polygeist/Passes/Mem2Reg.cpp | 8 +++++--- lib/polygeist/Passes/ParallelLoopDistribute.cpp | 2 +- lib/polygeist/Passes/ParallelLower.cpp | 2 +- lib/polygeist/Passes/RaiseToAffine.cpp | 5 ++--- tools/mlir-clang/Lib/ValueCategory.cc | 2 +- tools/mlir-clang/Lib/clang-mlir.cc | 9 ++++----- tools/mlir-clang/Lib/clang-mlir.h | 2 +- 13 files changed, 22 insertions(+), 22 deletions(-) diff --git a/include/polygeist/BarrierUtils.h b/include/polygeist/BarrierUtils.h index c76499ef212d..807ff41406db 100644 --- a/include/polygeist/BarrierUtils.h +++ b/include/polygeist/BarrierUtils.h @@ -10,10 +10,10 @@ #define MLIR_LIB_DIALECT_SCF_TRANSFORMS_BARRIERUTILS_H_ #include "mlir/Analysis/DataLayoutAnalysis.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/SCF/SCF.h" -#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/Block.h" #include "polygeist/Ops.h" #include "llvm/ADT/SetVector.h" diff --git a/lib/polygeist/Ops.cpp b/lib/polygeist/Ops.cpp index c7812e1c04b1..b5f3f07c412e 100644 --- a/lib/polygeist/Ops.cpp +++ b/lib/polygeist/Ops.cpp @@ -20,9 +20,9 @@ #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Arithmetic/Utils/Utils.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/SCF/SCF.h" -#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/BlockAndValueMapping.h" using namespace mlir; diff --git a/lib/polygeist/Passes/BarrierRemovalContinuation.cpp b/lib/polygeist/Passes/BarrierRemovalContinuation.cpp index af0bbf0014ff..075dc533bbe8 100644 --- a/lib/polygeist/Passes/BarrierRemovalContinuation.cpp +++ b/lib/polygeist/Passes/BarrierRemovalContinuation.cpp @@ -16,10 +16,10 @@ #include "mlir/Conversion/SCFToControlFlow/SCFToControlFlow.h" #include "mlir/Dialect/Arithmetic/IR/Arithmetic.h" #include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/SCF/Passes.h" #include "mlir/Dialect/SCF/SCF.h" -#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/Dominance.h" diff --git a/lib/polygeist/Passes/CanonicalizeFor.cpp b/lib/polygeist/Passes/CanonicalizeFor.cpp index 2b051c89a83f..1d9542022a45 100644 --- a/lib/polygeist/Passes/CanonicalizeFor.cpp +++ b/lib/polygeist/Passes/CanonicalizeFor.cpp @@ -1,8 +1,8 @@ #include "PassDetails.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/SCF/Passes.h" #include "mlir/Dialect/SCF/SCF.h" -#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/BlockAndValueMapping.h" #include "mlir/IR/Dominance.h" #include "mlir/IR/Matchers.h" diff --git a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp index 84786067d801..fad99bc60714 100644 --- a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp +++ b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp @@ -19,11 +19,11 @@ #include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h" #include "mlir/Conversion/OpenMPToLLVM/ConvertOpenMPToLLVM.h" #include "mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" +#include "mlir/Dialect/Func/Transforms/Passes.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/LLVMIR/LLVMTypes.h" #include "mlir/Dialect/OpenMP/OpenMPDialect.h" -#include "mlir/Dialect/Func/IR/FuncOps.h" -#include "mlir/Dialect/Func/Transforms/Passes.h" #include "polygeist/Ops.h" #define DEBUG_TYPE "convert-polygeist-to-llvm" diff --git a/lib/polygeist/Passes/LoopRestructure.cpp b/lib/polygeist/Passes/LoopRestructure.cpp index 47f69b432c13..1c47813c0397 100644 --- a/lib/polygeist/Passes/LoopRestructure.cpp +++ b/lib/polygeist/Passes/LoopRestructure.cpp @@ -10,9 +10,9 @@ #include "PassDetails.h" #include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/SCF/SCF.h" -#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/Builders.h" #include "mlir/IR/Dominance.h" #include "mlir/IR/PatternMatch.h" diff --git a/lib/polygeist/Passes/Mem2Reg.cpp b/lib/polygeist/Passes/Mem2Reg.cpp index cd1818f8a47a..09f415b930ef 100644 --- a/lib/polygeist/Passes/Mem2Reg.cpp +++ b/lib/polygeist/Passes/Mem2Reg.cpp @@ -17,10 +17,10 @@ #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Arithmetic/IR/Arithmetic.h" #include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/SCF/SCF.h" -#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/Dominance.h" #include "mlir/Support/LLVM.h" #include "mlir/Transforms/Passes.h" @@ -1697,7 +1697,8 @@ bool isPromotable(mlir::Value AI) { continue; } else if (isa(U)) { continue; - } else if (isa(U) && cast(U).getCallee() == "free") { + } else if (isa(U) && + cast(U).getCallee() == "free") { continue; } else if (isa(U)) { // TODO check "no capture", currently assume as a fallback always @@ -1891,7 +1892,8 @@ void Mem2Reg::runOnOperation() { toErase.push_back(U); } else if (isa(U)) { toErase.push_back(U); - } else if (isa(U) && cast(U).getCallee() == "free") { + } else if (isa(U) && + cast(U).getCallee() == "free") { toErase.push_back(U); } else if (auto CO = dyn_cast(U)) { toErase.push_back(U); diff --git a/lib/polygeist/Passes/ParallelLoopDistribute.cpp b/lib/polygeist/Passes/ParallelLoopDistribute.cpp index 53dbc9eb848e..6d3c983b3cd3 100644 --- a/lib/polygeist/Passes/ParallelLoopDistribute.cpp +++ b/lib/polygeist/Passes/ParallelLoopDistribute.cpp @@ -8,9 +8,9 @@ #include "PassDetails.h" #include "mlir/Dialect/Affine/IR/AffineOps.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" -#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/OpenMP/OpenMPDialect.h" #include "mlir/Dialect/SCF/Passes.h" #include "mlir/Dialect/SCF/SCF.h" diff --git a/lib/polygeist/Passes/ParallelLower.cpp b/lib/polygeist/Passes/ParallelLower.cpp index 4348ddce37e2..b90d1c383675 100644 --- a/lib/polygeist/Passes/ParallelLower.cpp +++ b/lib/polygeist/Passes/ParallelLower.cpp @@ -15,11 +15,11 @@ #include "mlir/Dialect/Affine/Analysis/AffineAnalysis.h" #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/GPU/GPUDialect.h" #include "mlir/Dialect/LLVMIR/NVVMDialect.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/SCF/SCF.h" -#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/Dominance.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "mlir/Transforms/Passes.h" diff --git a/lib/polygeist/Passes/RaiseToAffine.cpp b/lib/polygeist/Passes/RaiseToAffine.cpp index b622bff133ea..8d614f0780f4 100644 --- a/lib/polygeist/Passes/RaiseToAffine.cpp +++ b/lib/polygeist/Passes/RaiseToAffine.cpp @@ -2,10 +2,10 @@ #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Arithmetic/IR/Arithmetic.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/SCF/Passes.h" #include "mlir/Dialect/SCF/SCF.h" -#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/BlockAndValueMapping.h" #include "mlir/Transforms/DialectConversion.h" #include "polygeist/Passes/Passes.h" @@ -221,8 +221,7 @@ struct ParallelOpRaising : public OpRewritePattern { void RaiseSCFToAffine::runOnOperation() { ConversionTarget target(getContext()); - target - .addLegalDialect(); + target.addLegalDialect(); RewritePatternSet patterns(&getContext()); patterns.insert(&getContext()); diff --git a/tools/mlir-clang/Lib/ValueCategory.cc b/tools/mlir-clang/Lib/ValueCategory.cc index 53938d85b37e..88c17c4ddf2a 100644 --- a/tools/mlir-clang/Lib/ValueCategory.cc +++ b/tools/mlir-clang/Lib/ValueCategory.cc @@ -8,9 +8,9 @@ #include "ValueCategory.h" #include "mlir/Dialect/Arithmetic/IR/Arithmetic.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" -#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/OpDefinition.h" #include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h" #include "polygeist/Ops.h" diff --git a/tools/mlir-clang/Lib/clang-mlir.cc b/tools/mlir-clang/Lib/clang-mlir.cc index 21cc2ab0cdc3..281e8be173bc 100644 --- a/tools/mlir-clang/Lib/clang-mlir.cc +++ b/tools/mlir-clang/Lib/clang-mlir.cc @@ -11,6 +11,7 @@ #include "mlir/Dialect/Arithmetic/IR/Arithmetic.h" #include "mlir/Dialect/DLTI/DLTI.h" #include "mlir/Dialect/SCF/SCF.h" +#include "mlir/Target/LLVMIR/Import.h" #include "utils.h" #include "clang/AST/Attr.h" #include "clang/AST/Decl.h" @@ -36,7 +37,6 @@ #include "clang/Sema/SemaDiagnostic.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" -#include "mlir/Target/LLVMIR/Import.h" using namespace std; using namespace clang; @@ -5081,10 +5081,9 @@ static bool parseMLIR(const char *Argv0, std::vector filenames, LLVM::LLVMDialect::getDataLayoutAttrName(), StringAttr::get(module->getContext(), Clang->getTarget().getDataLayoutString())); - - module.get()->setAttr( - ("dlti." + DataLayoutSpecAttr::kAttrKeyword).str(), - translateDataLayout(DL, module->getContext())); + + module.get()->setAttr(("dlti." + DataLayoutSpecAttr::kAttrKeyword).str(), + translateDataLayout(DL, module->getContext())); } for (const auto &FIF : Clang->getFrontendOpts().Inputs) { diff --git a/tools/mlir-clang/Lib/clang-mlir.h b/tools/mlir-clang/Lib/clang-mlir.h index de7da4f15490..d512eeff7aed 100644 --- a/tools/mlir-clang/Lib/clang-mlir.h +++ b/tools/mlir-clang/Lib/clang-mlir.h @@ -19,12 +19,12 @@ #include "AffineUtils.h" #include "ValueCategory.h" #include "mlir/Dialect/Affine/IR/AffineOps.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/LLVMIR/LLVMTypes.h" #include "mlir/Dialect/LLVMIR/NVVMDialect.h" #include "mlir/Dialect/Math/IR/Math.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" -#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/Builders.h" #include "mlir/IR/MLIRContext.h" #include "mlir/IR/OpDefinition.h" From a0b1c9d76c53a0b725b22b819ab4f4b29315b3c5 Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Wed, 2 Mar 2022 13:32:39 -0500 Subject: [PATCH 07/14] Add canonicalizer --- tools/mlir-clang/mlir-clang.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/mlir-clang/mlir-clang.cc b/tools/mlir-clang/mlir-clang.cc index cacebac9ac85..50f5c1e40e9f 100644 --- a/tools/mlir-clang/mlir-clang.cc +++ b/tools/mlir-clang/mlir-clang.cc @@ -560,8 +560,10 @@ int main(int argc, char **argv) { return 4; } mlir::PassManager pm2(&context); - if (SCFOpenMP) + if (SCFOpenMP) { pm2.addPass(createConvertSCFToOpenMPPass()); + pm2.addPass(mlir::createCanonicalizerPass()); + } if (mlir::failed(pm2.run(module.get()))) { module->dump(); return 4; From bf7dc7c9f8f1e355fb2b8239eb35ebde1793fd56 Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Wed, 2 Mar 2022 14:24:45 -0500 Subject: [PATCH 08/14] Fix SCF lowering --- lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp | 2 ++ tools/mlir-clang/mlir-clang.cc | 1 - tools/polygeist-opt/polygeist-opt.cpp | 6 ++++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp index fad99bc60714..dcd66fe19ae0 100644 --- a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp +++ b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp @@ -18,6 +18,7 @@ #include "mlir/Conversion/LLVMCommon/Pattern.h" #include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h" #include "mlir/Conversion/OpenMPToLLVM/ConvertOpenMPToLLVM.h" +#include "mlir/Conversion/SCFToControlFlow/SCFToControlFlow.h" #include "mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/Func/Transforms/Passes.h" @@ -380,6 +381,7 @@ struct ConvertPolygeistToLLVMPass LLVMTypeConverter converter(&getContext(), options, &dataLayoutAnalysis); RewritePatternSet patterns(&getContext()); populatePolygeistToLLVMConversionPatterns(converter, patterns); + populateSCFToControlFlowConversionPatterns(patterns); cf::populateControlFlowToLLVMConversionPatterns(converter, patterns); populateMemRefToLLVMConversionPatterns(converter, patterns); populateStdToLLVMConversionPatterns(converter, patterns); diff --git a/tools/mlir-clang/mlir-clang.cc b/tools/mlir-clang/mlir-clang.cc index 50f5c1e40e9f..2dc514851712 100644 --- a/tools/mlir-clang/mlir-clang.cc +++ b/tools/mlir-clang/mlir-clang.cc @@ -570,7 +570,6 @@ int main(int argc, char **argv) { } module->walk([&](mlir::omp::ParallelOp) { LinkOMP = true; }); mlir::PassManager pm3(&context); - pm3.addPass(mlir::createConvertSCFToCFPass()); LowerToLLVMOptions options(&context); options.dataLayout = DL; // invalid for gemm.c init array diff --git a/tools/polygeist-opt/polygeist-opt.cpp b/tools/polygeist-opt/polygeist-opt.cpp index 275d198928e4..1752ad9746c5 100644 --- a/tools/polygeist-opt/polygeist-opt.cpp +++ b/tools/polygeist-opt/polygeist-opt.cpp @@ -14,13 +14,14 @@ #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Arithmetic/IR/Arithmetic.h" #include "mlir/Dialect/GPU/GPUDialect.h" +#include "mlir/Dialect/DLTI/DLTI.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/LLVMIR/NVVMDialect.h" #include "mlir/Dialect/Math/IR/Math.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/OpenMP/OpenMPDialect.h" #include "mlir/Dialect/SCF/SCF.h" -#include "mlir/Dialect/StandardOps/IR/Ops.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Pass/PassRegistry.h" #include "mlir/Support/MlirOptMain.h" #include "mlir/Transforms/Passes.h" @@ -45,13 +46,14 @@ int main(int argc, char **argv) { registry.insert(); registry.insert(); registry.insert(); - registry.insert(); + registry.insert(); registry.insert(); registry.insert(); registry.insert(); registry.insert(); registry.insert(); registry.insert(); + registry.insert(); registry.insert(); From fc90dace616f104203eebfc937b402a01e7545d6 Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Wed, 2 Mar 2022 14:56:08 -0500 Subject: [PATCH 09/14] SCF lowering --- lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp | 3 +++ tools/mlir-clang/mlir-clang.cc | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp index dcd66fe19ae0..c4c852933c8a 100644 --- a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp +++ b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp @@ -18,6 +18,7 @@ #include "mlir/Conversion/LLVMCommon/Pattern.h" #include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h" #include "mlir/Conversion/OpenMPToLLVM/ConvertOpenMPToLLVM.h" +#include "mlir/Dialect/SCF/SCF.h" #include "mlir/Conversion/SCFToControlFlow/SCFToControlFlow.h" #include "mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h" #include "mlir/Dialect/Func/IR/FuncOps.h" @@ -411,6 +412,8 @@ struct ConvertPolygeistToLLVMPass LLVMConversionTarget target(getContext()); target.addDynamicallyLegalOp( [&](Operation *op) { return converter.isLegal(&op->getRegion(0)); }); + target.addIllegalOp(); target.addLegalOp(); target.addDynamicallyLegalDialect(areAllTypesConverted); diff --git a/tools/mlir-clang/mlir-clang.cc b/tools/mlir-clang/mlir-clang.cc index 2dc514851712..c43cee57475f 100644 --- a/tools/mlir-clang/mlir-clang.cc +++ b/tools/mlir-clang/mlir-clang.cc @@ -575,8 +575,8 @@ int main(int argc, char **argv) { // invalid for gemm.c init array // options.useBarePtrCallConv = true; pm3.addPass(polygeist::createConvertPolygeistToLLVMPass(options)); - pm3.addPass(createConvertOpenMPToLLVMPass()); pm3.addPass(mlir::createLowerToLLVMPass(options)); + pm3.addPass(mlir::createCanonicalizerPass()); if (mlir::failed(pm3.run(module.get()))) { module->dump(); return 4; From 2f96f407288a82ea262947b9c26c6c928305569c Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Wed, 2 Mar 2022 15:20:37 -0500 Subject: [PATCH 10/14] Fix format --- lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp | 4 ++-- tools/polygeist-opt/polygeist-opt.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp index c4c852933c8a..e26e01fdff4d 100644 --- a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp +++ b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp @@ -18,7 +18,6 @@ #include "mlir/Conversion/LLVMCommon/Pattern.h" #include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h" #include "mlir/Conversion/OpenMPToLLVM/ConvertOpenMPToLLVM.h" -#include "mlir/Dialect/SCF/SCF.h" #include "mlir/Conversion/SCFToControlFlow/SCFToControlFlow.h" #include "mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h" #include "mlir/Dialect/Func/IR/FuncOps.h" @@ -26,6 +25,7 @@ #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/LLVMIR/LLVMTypes.h" #include "mlir/Dialect/OpenMP/OpenMPDialect.h" +#include "mlir/Dialect/SCF/SCF.h" #include "polygeist/Ops.h" #define DEBUG_TYPE "convert-polygeist-to-llvm" @@ -413,7 +413,7 @@ struct ConvertPolygeistToLLVMPass target.addDynamicallyLegalOp( [&](Operation *op) { return converter.isLegal(&op->getRegion(0)); }); target.addIllegalOp(); + scf::ExecuteRegionOp>(); target.addLegalOp(); target.addDynamicallyLegalDialect(areAllTypesConverted); diff --git a/tools/polygeist-opt/polygeist-opt.cpp b/tools/polygeist-opt/polygeist-opt.cpp index 1752ad9746c5..6b2900d49002 100644 --- a/tools/polygeist-opt/polygeist-opt.cpp +++ b/tools/polygeist-opt/polygeist-opt.cpp @@ -13,15 +13,15 @@ #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Arithmetic/IR/Arithmetic.h" -#include "mlir/Dialect/GPU/GPUDialect.h" #include "mlir/Dialect/DLTI/DLTI.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" +#include "mlir/Dialect/GPU/GPUDialect.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/LLVMIR/NVVMDialect.h" #include "mlir/Dialect/Math/IR/Math.h" #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/OpenMP/OpenMPDialect.h" #include "mlir/Dialect/SCF/SCF.h" -#include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Pass/PassRegistry.h" #include "mlir/Support/MlirOptMain.h" #include "mlir/Transforms/Passes.h" From bb14f5e7cbbabe9852330e36baceb9ffe0503096 Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Wed, 2 Mar 2022 17:17:44 -0500 Subject: [PATCH 11/14] OpenMPOpt --- include/polygeist/Passes/Passes.h | 11 ++--- include/polygeist/Passes/Passes.td | 17 +++++--- lib/polygeist/Passes/AffineCFG.cpp | 6 +-- lib/polygeist/Passes/AffineReduction.cpp | 6 +-- lib/polygeist/Passes/CMakeLists.txt | 1 + lib/polygeist/Passes/CanonicalizeFor.cpp | 4 +- lib/polygeist/Passes/LoopRestructure.cpp | 6 +-- lib/polygeist/Passes/Mem2Reg.cpp | 8 +--- lib/polygeist/Passes/TrivialUse.cpp | 2 +- llvm-project | 2 +- tools/mlir-clang/mlir-clang.cc | 52 +++++++++++++++++------- tools/polygeist-opt/polygeist-opt.cpp | 2 + 12 files changed, 72 insertions(+), 45 deletions(-) diff --git a/include/polygeist/Passes/Passes.h b/include/polygeist/Passes/Passes.h index af0a61178197..021b94dad52a 100644 --- a/include/polygeist/Passes/Passes.h +++ b/include/polygeist/Passes/Passes.h @@ -6,15 +6,16 @@ #include namespace mlir { namespace polygeist { -std::unique_ptr> createMem2RegPass(); -std::unique_ptr> createLoopRestructurePass(); -std::unique_ptr> replaceAffineCFGPass(); +std::unique_ptr createMem2RegPass(); +std::unique_ptr createLoopRestructurePass(); +std::unique_ptr replaceAffineCFGPass(); +std::unique_ptr createOpenMPOptPass(); std::unique_ptr createCanonicalizeForPass(); std::unique_ptr createRaiseSCFToAffinePass(); std::unique_ptr createCPUifyPass(StringRef method = ""); std::unique_ptr createBarrierRemovalContinuation(); -std::unique_ptr> detectReductionPass(); -std::unique_ptr> createRemoveTrivialUsePass(); +std::unique_ptr detectReductionPass(); +std::unique_ptr createRemoveTrivialUsePass(); std::unique_ptr createParallelLowerPass(); std::unique_ptr createConvertPolygeistToLLVMPass(const LowerToLLVMOptions &options); diff --git a/include/polygeist/Passes/Passes.td b/include/polygeist/Passes/Passes.td index c7741b9867bd..63a47b9456a7 100644 --- a/include/polygeist/Passes/Passes.td +++ b/include/polygeist/Passes/Passes.td @@ -3,7 +3,7 @@ include "mlir/Pass/PassBase.td" -def AffineCFG : Pass<"affine-cfg", "FuncOp"> { +def AffineCFG : Pass<"affine-cfg"> { let summary = "Replace scf.if and similar with affine.if"; let constructor = "mlir::polygeist::replaceAffineCFGPass()"; } @@ -20,7 +20,7 @@ def ParallelLower : Pass<"parallel-lower", "mlir::ModuleOp"> { let constructor = "mlir::polygeist::createParallelLowerPass()"; } -def AffineReduction : Pass<"detect-reduction", "FuncOp"> { +def AffineReduction : Pass<"detect-reduction"> { let summary = "Detect reductions in affine.for"; let constructor = "mlir::polygeist::detectReductionPass()"; } @@ -41,23 +41,28 @@ def SCFBarrierRemovalContinuation : Pass<"barrier-removal-continuation", "FuncOp let dependentDialects = ["memref::MemRefDialect", "func::FuncDialect"]; } -def SCFRaiseToAffine : Pass<"raise-scf-to-affine", "FuncOp"> { +def SCFRaiseToAffine : Pass<"raise-scf-to-affine"> { let summary = "Raise SCF to affine"; let constructor = "mlir::polygeist::createRaiseSCFToAffinePass()"; let dependentDialects = ["AffineDialect"]; } -def SCFCanonicalizeFor : Pass<"canonicalize-scf-for", "FuncOp"> { +def SCFCanonicalizeFor : Pass<"canonicalize-scf-for"> { let summary = "Run some additional canonicalization for scf::for"; let constructor = "mlir::polygeist::createCanonicalizeForPass()"; } -def LoopRestructure : Pass<"loop-restructure", "FuncOp"> { +def OpenMPOptPass : Pass<"openmp-opt"> { + let summary = "Optimize OpenMP"; + let constructor = "mlir::polygeist::createOpenMPOptPass()"; +} + +def LoopRestructure : Pass<"loop-restructure"> { let constructor = "mlir::polygeist::createLoopRestructurePass()"; let dependentDialects = ["::mlir::scf::SCFDialect"]; } -def RemoveTrivialUse : Pass<"trivialuse", "FuncOp"> { +def RemoveTrivialUse : Pass<"trivialuse"> { let constructor = "mlir::polygeist::createRemoveTrivialUsePass()"; } diff --git a/lib/polygeist/Passes/AffineCFG.cpp b/lib/polygeist/Passes/AffineCFG.cpp index 72b1f8fc28ea..688f0850688b 100644 --- a/lib/polygeist/Passes/AffineCFG.cpp +++ b/lib/polygeist/Passes/AffineCFG.cpp @@ -1135,16 +1135,16 @@ struct MoveIfToAffine : public OpRewritePattern { }; void AffineCFGPass::runOnOperation() { - mlir::RewritePatternSet rpl(getOperation().getContext()); + mlir::RewritePatternSet rpl(getOperation()->getContext()); rpl.add, AffineFixup, CanonicalizIfBounds, MoveStoreToAffine, MoveIfToAffine, MoveLoadToAffine, CanonicalieForBounds>( - getOperation().getContext()); + getOperation()->getContext()); GreedyRewriteConfig config; (void)applyPatternsAndFoldGreedily(getOperation(), std::move(rpl), config); } -std::unique_ptr> mlir::polygeist::replaceAffineCFGPass() { +std::unique_ptr mlir::polygeist::replaceAffineCFGPass() { return std::make_unique(); } diff --git a/lib/polygeist/Passes/AffineReduction.cpp b/lib/polygeist/Passes/AffineReduction.cpp index 304360c31ee9..e35350c9f3db 100644 --- a/lib/polygeist/Passes/AffineReduction.cpp +++ b/lib/polygeist/Passes/AffineReduction.cpp @@ -255,15 +255,15 @@ struct AffineForReductionIter : public OpRewritePattern { } // end namespace. void AffineReductionPass::runOnOperation() { - mlir::RewritePatternSet rpl(getOperation().getContext()); - rpl.add(getOperation().getContext()); + mlir::RewritePatternSet rpl(getOperation()->getContext()); + rpl.add(getOperation()->getContext()); GreedyRewriteConfig config; (void)applyPatternsAndFoldGreedily(getOperation(), std::move(rpl), config); } namespace mlir { namespace polygeist { -std::unique_ptr> detectReductionPass() { +std::unique_ptr detectReductionPass() { return std::make_unique(); } } // namespace polygeist diff --git a/lib/polygeist/Passes/CMakeLists.txt b/lib/polygeist/Passes/CMakeLists.txt index 0e25b54ca869..63956990b12e 100644 --- a/lib/polygeist/Passes/CMakeLists.txt +++ b/lib/polygeist/Passes/CMakeLists.txt @@ -5,6 +5,7 @@ add_mlir_dialect_library(MLIRPolygeistTransforms LoopRestructure.cpp Mem2Reg.cpp ParallelLoopDistribute.cpp + OpenMPOpt.cpp BarrierRemovalContinuation.cpp RaiseToAffine.cpp ParallelLower.cpp diff --git a/lib/polygeist/Passes/CanonicalizeFor.cpp b/lib/polygeist/Passes/CanonicalizeFor.cpp index 1d9542022a45..477ea9153c2e 100644 --- a/lib/polygeist/Passes/CanonicalizeFor.cpp +++ b/lib/polygeist/Passes/CanonicalizeFor.cpp @@ -1409,7 +1409,7 @@ struct ReturnSq : public OpRewritePattern { } }; void CanonicalizeFor::runOnOperation() { - mlir::RewritePatternSet rpl(getOperation().getContext()); + mlir::RewritePatternSet rpl(getOperation()->getContext()); rpl.add(getOperation().getContext()); + MoveSideEffectFreeWhile>(getOperation()->getContext()); GreedyRewriteConfig config; config.maxIterations = 47; (void)applyPatternsAndFoldGreedily(getOperation(), std::move(rpl), config); diff --git a/lib/polygeist/Passes/LoopRestructure.cpp b/lib/polygeist/Passes/LoopRestructure.cpp index 1c47813c0397..b65af71aef65 100644 --- a/lib/polygeist/Passes/LoopRestructure.cpp +++ b/lib/polygeist/Passes/LoopRestructure.cpp @@ -224,8 +224,8 @@ template class llvm::LoopInfoBase; void LoopRestructure::runOnOperation() { // FuncOp f = getFunction(); DominanceInfo &domInfo = getAnalysis(); - if (auto region = getOperation().getCallableRegion()) { - runOnRegion(domInfo, *region); + for (auto& region : getOperation()->getRegions()) { + runOnRegion(domInfo, region); } } @@ -680,7 +680,7 @@ void LoopRestructure::runOnRegion(DominanceInfo &domInfo, Region ®ion) { namespace mlir { namespace polygeist { -std::unique_ptr> createLoopRestructurePass() { +std::unique_ptr createLoopRestructurePass() { return std::make_unique(); } } // namespace polygeist diff --git a/lib/polygeist/Passes/Mem2Reg.cpp b/lib/polygeist/Passes/Mem2Reg.cpp index 09f415b930ef..e9f1baf9c5a8 100644 --- a/lib/polygeist/Passes/Mem2Reg.cpp +++ b/lib/polygeist/Passes/Mem2Reg.cpp @@ -87,7 +87,7 @@ struct Mem2Reg : public Mem2RegBase { /// Creates a pass to perform optimizations relying on memref dataflow such as /// store to load forwarding, elimination of dead stores, and dead allocs. -std::unique_ptr> mlir::polygeist::createMem2RegPass() { +std::unique_ptr mlir::polygeist::createMem2RegPass() { return std::make_unique(); } @@ -1792,7 +1792,6 @@ void Mem2Reg::runOnOperation() { // memrefs etc, we may need to do multiple passes (first // to eliminate the outermost one, then inner ones) bool changed; - FuncOp freeRemoved = nullptr; do { changed = false; @@ -1923,9 +1922,4 @@ void Mem2Reg::runOnOperation() { } } while (changed); - if (freeRemoved) { - if (freeRemoved.use_empty()) { - freeRemoved.erase(); - } - } } diff --git a/lib/polygeist/Passes/TrivialUse.cpp b/lib/polygeist/Passes/TrivialUse.cpp index ffbbb6d464e6..d607bf2c07b9 100644 --- a/lib/polygeist/Passes/TrivialUse.cpp +++ b/lib/polygeist/Passes/TrivialUse.cpp @@ -28,7 +28,7 @@ struct RemoveTrivialUse : public RemoveTrivialUseBase { namespace mlir { namespace polygeist { -std::unique_ptr> createRemoveTrivialUsePass() { +std::unique_ptr createRemoveTrivialUsePass() { return std::make_unique(); } } // namespace polygeist diff --git a/llvm-project b/llvm-project index 758ddba38113..82631c919fbb 160000 --- a/llvm-project +++ b/llvm-project @@ -1 +1 @@ -Subproject commit 758ddba38113b2ab48cd6e45d7617463969bf813 +Subproject commit 82631c919fbba968efb3e188d592476903c832a6 diff --git a/tools/mlir-clang/mlir-clang.cc b/tools/mlir-clang/mlir-clang.cc index c43cee57475f..65b155f55c3a 100644 --- a/tools/mlir-clang/mlir-clang.cc +++ b/tools/mlir-clang/mlir-clang.cc @@ -61,6 +61,9 @@ static cl::opt CudaLower("cuda-lower", cl::init(false), static cl::opt EmitLLVM("emit-llvm", cl::init(false), cl::desc("Emit llvm")); +static cl::opt EmitOpenMPIR("emit-openmpir", cl::init(false), + cl::desc("Emit OpenMP IR")); + static cl::opt EmitAssembly("S", cl::init(false), cl::desc("Emit Assembly")); @@ -481,7 +484,19 @@ int main(int argc, char **argv) { if (!Opt0) { optPM.addPass(mlir::createCanonicalizerPass()); optPM.addPass(mlir::createCSEPass()); + // Affine must be lowered to enable inlining + optPM.addPass(mlir::createLowerAffinePass()); + optPM.addPass(mlir::createCanonicalizerPass()); pm.addPass(mlir::createInlinerPass()); + mlir::OpPassManager &optPM2 = pm.nest(); + if (RaiseToAffine) { + optPM2.addPass(polygeist::createRaiseSCFToAffinePass()); + } + optPM2.addPass(polygeist::replaceAffineCFGPass()); + optPM2.addPass(mlir::createCanonicalizerPass()); + optPM2.addPass(mlir::createCSEPass()); + optPM2.addPass(mlir::createLoopInvariantCodeMotionPass()); + optPM2.addPass(mlir::createCanonicalizerPass()); } if (mlir::failed(pm.run(module.get()))) { module->dump(); @@ -499,21 +514,23 @@ int main(int argc, char **argv) { mlir::OpPassManager &noptPM = pm.nest(); noptPM.addPass(mlir::createCanonicalizerPass()); noptPM.addPass(polygeist::createMem2RegPass()); - noptPM.addPass(polygeist::replaceAffineCFGPass()); noptPM.addPass(mlir::createCanonicalizerPass()); pm.addPass(mlir::createInlinerPass()); - - noptPM.addPass(polygeist::createCanonicalizeForPass()); - noptPM.addPass(mlir::createCanonicalizerPass()); - noptPM.addPass(mlir::createLoopInvariantCodeMotionPass()); - noptPM.addPass(mlir::createCanonicalizerPass()); + mlir::OpPassManager &noptPM2 = pm.nest(); + noptPM2.addPass(mlir::createCanonicalizerPass()); + noptPM2.addPass(polygeist::createMem2RegPass()); + noptPM2.addPass(polygeist::createCanonicalizeForPass()); + noptPM2.addPass(mlir::createCanonicalizerPass()); + noptPM2.addPass(mlir::createCSEPass()); + noptPM2.addPass(mlir::createLoopInvariantCodeMotionPass()); + noptPM2.addPass(mlir::createCanonicalizerPass()); if (RaiseToAffine) { - noptPM.addPass(polygeist::createRaiseSCFToAffinePass()); - noptPM.addPass(mlir::createCanonicalizerPass()); - noptPM.addPass(polygeist::replaceAffineCFGPass()); - noptPM.addPass(mlir::createCanonicalizerPass()); + noptPM2.addPass(polygeist::createRaiseSCFToAffinePass()); + noptPM2.addPass(mlir::createCanonicalizerPass()); + noptPM2.addPass(polygeist::replaceAffineCFGPass()); + noptPM2.addPass(mlir::createCanonicalizerPass()); if (ScalarReplacement) - noptPM.addPass(mlir::createAffineScalarReplacementPass()); + noptPM2.addPass(mlir::createAffineScalarReplacementPass()); } if (mlir::failed(pm.run(module.get()))) { module->dump(); @@ -552,9 +569,9 @@ int main(int argc, char **argv) { } pm.addPass(mlir::createSymbolDCEPass()); - if (EmitLLVM || !EmitAssembly) { + if (EmitLLVM || !EmitAssembly || EmitOpenMPIR) { pm.addPass(mlir::createLowerAffinePass()); - pm.nest().addPass(mlir::createConvertMathToLLVMPass()); + // pm.nest().addPass(mlir::createConvertMathToLLVMPass()); if (mlir::failed(pm.run(module.get()))) { module->dump(); return 4; @@ -562,12 +579,18 @@ int main(int argc, char **argv) { mlir::PassManager pm2(&context); if (SCFOpenMP) { pm2.addPass(createConvertSCFToOpenMPPass()); - pm2.addPass(mlir::createCanonicalizerPass()); } + pm2.addPass(mlir::createCanonicalizerPass()); + pm2.addPass(polygeist::createOpenMPOptPass()); + pm2.addPass(mlir::createCanonicalizerPass()); + pm.nest().addPass(polygeist::createMem2RegPass()); + pm2.addPass(mlir::createCSEPass()); + pm2.addPass(mlir::createCanonicalizerPass()); if (mlir::failed(pm2.run(module.get()))) { module->dump(); return 4; } + if (!EmitOpenMPIR) { module->walk([&](mlir::omp::ParallelOp) { LinkOMP = true; }); mlir::PassManager pm3(&context); LowerToLLVMOptions options(&context); @@ -581,6 +604,7 @@ int main(int argc, char **argv) { module->dump(); return 4; } + } } else { if (mlir::failed(pm.run(module.get()))) { diff --git a/tools/polygeist-opt/polygeist-opt.cpp b/tools/polygeist-opt/polygeist-opt.cpp index 6b2900d49002..9940d68b1f70 100644 --- a/tools/polygeist-opt/polygeist-opt.cpp +++ b/tools/polygeist-opt/polygeist-opt.cpp @@ -64,6 +64,8 @@ int main(int argc, char **argv) { mlir::registerSCCPPass(); mlir::registerInlinerPass(); mlir::registerCanonicalizerPass(); + mlir::registerSymbolDCEPass(); + mlir::registerLoopInvariantCodeMotionPass(); registry.addTypeInterface(); From 19d2fa778fd63292f5def1471302ee6e65cf21be Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Wed, 2 Mar 2022 17:32:20 -0500 Subject: [PATCH 12/14] Add OpenMPOpt --- lib/polygeist/Passes/CMakeLists.txt | 2 + .../Passes/ConvertPolygeistToLLVM.cpp | 2 + lib/polygeist/Passes/LoopRestructure.cpp | 2 +- lib/polygeist/Passes/Mem2Reg.cpp | 1 - lib/polygeist/Passes/OpenMPOpt.cpp | 74 +++++++++++++++++++ tools/mlir-clang/mlir-clang.cc | 28 +++---- 6 files changed, 93 insertions(+), 16 deletions(-) create mode 100644 lib/polygeist/Passes/OpenMPOpt.cpp diff --git a/lib/polygeist/Passes/CMakeLists.txt b/lib/polygeist/Passes/CMakeLists.txt index 63956990b12e..4333e6ad61eb 100644 --- a/lib/polygeist/Passes/CMakeLists.txt +++ b/lib/polygeist/Passes/CMakeLists.txt @@ -27,6 +27,8 @@ add_mlir_dialect_library(MLIRPolygeistTransforms MLIRGPUOps MLIRIR MLIRLLVMIR + MLIRMath + MLIRMathToLLVM MLIRMemRef MLIRNVVMIR MLIRPass diff --git a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp index e26e01fdff4d..0289cfb44353 100644 --- a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp +++ b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp @@ -16,6 +16,7 @@ #include "mlir/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.h" #include "mlir/Conversion/LLVMCommon/ConversionTarget.h" #include "mlir/Conversion/LLVMCommon/Pattern.h" +#include "mlir/Conversion/MathToLLVM/MathToLLVM.h" #include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h" #include "mlir/Conversion/OpenMPToLLVM/ConvertOpenMPToLLVM.h" #include "mlir/Conversion/SCFToControlFlow/SCFToControlFlow.h" @@ -386,6 +387,7 @@ struct ConvertPolygeistToLLVMPass cf::populateControlFlowToLLVMConversionPatterns(converter, patterns); populateMemRefToLLVMConversionPatterns(converter, patterns); populateStdToLLVMConversionPatterns(converter, patterns); + populateMathToLLVMConversionPatterns(converter, patterns); populateOpenMPToLLVMConversionPatterns(converter, patterns); arith::populateArithmeticToLLVMConversionPatterns(converter, patterns); diff --git a/lib/polygeist/Passes/LoopRestructure.cpp b/lib/polygeist/Passes/LoopRestructure.cpp index b65af71aef65..5834f82d1776 100644 --- a/lib/polygeist/Passes/LoopRestructure.cpp +++ b/lib/polygeist/Passes/LoopRestructure.cpp @@ -224,7 +224,7 @@ template class llvm::LoopInfoBase; void LoopRestructure::runOnOperation() { // FuncOp f = getFunction(); DominanceInfo &domInfo = getAnalysis(); - for (auto& region : getOperation()->getRegions()) { + for (auto ®ion : getOperation()->getRegions()) { runOnRegion(domInfo, region); } } diff --git a/lib/polygeist/Passes/Mem2Reg.cpp b/lib/polygeist/Passes/Mem2Reg.cpp index e9f1baf9c5a8..31327a510da3 100644 --- a/lib/polygeist/Passes/Mem2Reg.cpp +++ b/lib/polygeist/Passes/Mem2Reg.cpp @@ -1921,5 +1921,4 @@ void Mem2Reg::runOnOperation() { } } } while (changed); - } diff --git a/lib/polygeist/Passes/OpenMPOpt.cpp b/lib/polygeist/Passes/OpenMPOpt.cpp new file mode 100644 index 000000000000..7ff0aeac6a3a --- /dev/null +++ b/lib/polygeist/Passes/OpenMPOpt.cpp @@ -0,0 +1,74 @@ +#include "PassDetails.h" + +#include "mlir/Dialect/Func/IR/FuncOps.h" +#include "mlir/Dialect/OpenMP/OpenMPDialect.h" +#include "mlir/Dialect/SCF/Passes.h" +#include "mlir/Dialect/SCF/SCF.h" +#include "mlir/IR/BlockAndValueMapping.h" +#include "mlir/IR/Dominance.h" +#include "mlir/IR/Matchers.h" +#include "mlir/Transforms/GreedyPatternRewriteDriver.h" +#include "polygeist/Passes/Passes.h" +#include + +using namespace mlir; +using namespace mlir::func; +using namespace mlir::arith; +using namespace polygeist; + +namespace { +struct OpenMPOpt : public OpenMPOptPassBase { + void runOnOperation() override; +}; +} // namespace + +/// Merge any consecutive parallel's +/// +/// omp.parallel { +/// codeA(); +/// } +/// omp.parallel { +/// codeB(); +/// } +/// +/// becomes +/// +/// omp.parallel { +/// codeA(); +/// omp.barrier +/// codeB(); +/// } +struct CombineParallel : public OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + LogicalResult matchAndRewrite(omp::ParallelOp nextParallel, + PatternRewriter &rewriter) const override { + Block *parent = nextParallel->getBlock(); + if (nextParallel == &parent->front()) + return failure(); + + auto prevParallel = dyn_cast(nextParallel->getPrevNode()); + if (!prevParallel) + return failure(); + + rewriter.setInsertionPointToEnd(&prevParallel.getRegion().front()); + rewriter.replaceOpWithNewOp( + prevParallel.getRegion().front().getTerminator(), TypeRange()); + rewriter.mergeBlocks(&nextParallel.getRegion().front(), + &prevParallel.getRegion().front()); + rewriter.eraseOp(nextParallel); + return success(); + } +}; + +void OpenMPOpt::runOnOperation() { + mlir::RewritePatternSet rpl(getOperation()->getContext()); + rpl.add(getOperation()->getContext()); + GreedyRewriteConfig config; + config.maxIterations = 47; + (void)applyPatternsAndFoldGreedily(getOperation(), std::move(rpl), config); +} + +std::unique_ptr mlir::polygeist::createOpenMPOptPass() { + return std::make_unique(); +} diff --git a/tools/mlir-clang/mlir-clang.cc b/tools/mlir-clang/mlir-clang.cc index 65b155f55c3a..2b45406af8b6 100644 --- a/tools/mlir-clang/mlir-clang.cc +++ b/tools/mlir-clang/mlir-clang.cc @@ -62,7 +62,7 @@ static cl::opt EmitLLVM("emit-llvm", cl::init(false), cl::desc("Emit llvm")); static cl::opt EmitOpenMPIR("emit-openmpir", cl::init(false), - cl::desc("Emit OpenMP IR")); + cl::desc("Emit OpenMP IR")); static cl::opt EmitAssembly("S", cl::init(false), cl::desc("Emit Assembly")); @@ -591,19 +591,19 @@ int main(int argc, char **argv) { return 4; } if (!EmitOpenMPIR) { - module->walk([&](mlir::omp::ParallelOp) { LinkOMP = true; }); - mlir::PassManager pm3(&context); - LowerToLLVMOptions options(&context); - options.dataLayout = DL; - // invalid for gemm.c init array - // options.useBarePtrCallConv = true; - pm3.addPass(polygeist::createConvertPolygeistToLLVMPass(options)); - pm3.addPass(mlir::createLowerToLLVMPass(options)); - pm3.addPass(mlir::createCanonicalizerPass()); - if (mlir::failed(pm3.run(module.get()))) { - module->dump(); - return 4; - } + module->walk([&](mlir::omp::ParallelOp) { LinkOMP = true; }); + mlir::PassManager pm3(&context); + LowerToLLVMOptions options(&context); + options.dataLayout = DL; + // invalid for gemm.c init array + // options.useBarePtrCallConv = true; + pm3.addPass(polygeist::createConvertPolygeistToLLVMPass(options)); + pm3.addPass(mlir::createLowerToLLVMPass(options)); + pm3.addPass(mlir::createCanonicalizerPass()); + if (mlir::failed(pm3.run(module.get()))) { + module->dump(); + return 4; + } } } else { From 60cb044931921e68d4b9cc5eed2caf9746ed51f1 Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Thu, 3 Mar 2022 13:22:50 -0500 Subject: [PATCH 13/14] Fix tests --- lib/polygeist/Ops.cpp | 100 ++++++++++++++++++ lib/polygeist/Passes/OpenMPOpt.cpp | 32 +++++- llvm-project | 2 +- tools/mlir-clang/Lib/clang-mlir.cc | 7 +- tools/mlir-clang/Test/Verification/calloc.c | 24 ++--- .../mlir-clang/Test/Verification/capture.cpp | 4 +- .../Test/Verification/charswitch.cpp | 16 +-- .../mlir-clang/Test/Verification/consabi.cpp | 18 ++-- .../Test/Verification/constexpr.cpp | 6 +- tools/mlir-clang/Test/Verification/fscanf.c | 2 +- tools/mlir-clang/Test/Verification/hist.c | 24 +++-- tools/mlir-clang/Test/Verification/ident.cpp | 4 +- tools/mlir-clang/Test/Verification/label.c | 10 +- tools/mlir-clang/Test/Verification/loopinc.c | 8 +- .../Test/Verification/memcpystruct.c | 6 +- tools/mlir-clang/Test/Verification/omp3.c | 10 +- tools/mlir-clang/Test/Verification/omp4.c | 8 +- tools/mlir-clang/Test/Verification/pair.c | 6 +- tools/mlir-clang/Test/Verification/pairinit.c | 4 +- tools/mlir-clang/Test/Verification/pairptr.c | 6 +- .../Test/Verification/recurstruct.c | 6 +- tools/mlir-clang/Test/Verification/scor2.c | 4 +- tools/mlir-clang/Test/Verification/sec.c | 6 +- .../mlir-clang/Test/Verification/staticint.c | 8 +- .../mlir-clang/Test/Verification/switcherr.c | 16 +-- tools/mlir-clang/Test/Verification/tobits.c | 4 +- tools/mlir-clang/Test/Verification/unlinked.c | 4 +- tools/mlir-clang/Test/Verification/virt.cpp | 14 +-- tools/mlir-clang/Test/Verification/virt2.cpp | 6 +- tools/mlir-clang/Test/canonicalization.c | 19 ++-- tools/mlir-clang/mlir-clang.cc | 3 +- tools/polygeist-opt/polygeist-opt.cpp | 3 + 32 files changed, 260 insertions(+), 130 deletions(-) diff --git a/lib/polygeist/Ops.cpp b/lib/polygeist/Ops.cpp index b5f3f07c412e..17062ce73c43 100644 --- a/lib/polygeist/Ops.cpp +++ b/lib/polygeist/Ops.cpp @@ -896,6 +896,105 @@ class CopySimplification final : public OpRewritePattern { } }; +template +class SetSimplification final : public OpRewritePattern { +public: + using OpRewritePattern::OpRewritePattern; + + LogicalResult matchAndRewrite(T op, + PatternRewriter &rewriter) const override { + + Value dstv = op.getDst(); + auto dst = dstv.getDefiningOp(); + if (!dst) + return failure(); + + auto dstTy = dst.source().getType().cast(); + Type elTy = dstTy.getElementType(); + + if (!elTy.isa()) + return failure(); + + size_t width = 1; + if (auto IT = elTy.dyn_cast()) + width = IT.getWidth() / 8; + else if (auto FT = elTy.dyn_cast()) + width = FT.getWidth() / 8; + else { + // TODO extend to llvm compatible type + return failure(); + } + bool first = true; + SmallVector bounds; + for (auto pair : dstTy.getShape()) { + if (first) { + first = false; + continue; + } + bounds.push_back(pair); + width *= pair; + } + + Value len = op.getLen(); + size_t factor = 1; + while (factor % width != 0) { + IntegerAttr constValue; + if (auto ext = len.getDefiningOp()) + len = ext.getIn(); + else if (auto ext = len.getDefiningOp()) + len = ext.getIn(); + else if (auto mul = len.getDefiningOp()) + len = mul.getRhs(); + else if (matchPattern(len, m_Constant(&constValue))) { + factor *= constValue.getValue().getLimitedValue(); + } else + return failure(); + } + + if (factor % width != 0) + return failure(); + + Value c0 = rewriter.create(op.getLoc(), 0); + Value c1 = rewriter.create(op.getLoc(), 1); + SmallVector idxs; + Value val; + + if (auto IT = elTy.dyn_cast()) + val = + rewriter.create(op.getLoc(), 0, IT.getWidth()); + else { + auto FT = elTy.cast(); + val = rewriter.create( + op.getLoc(), APFloat(FT.getFloatSemantics(), "0"), FT); + } + + auto forOp = rewriter.create( + op.getLoc(), c0, + rewriter.create( + op.getLoc(), + rewriter.create( + op.getLoc(), rewriter.getIndexType(), op.getLen()), + rewriter.create(op.getLoc(), width)), + c1); + + rewriter.setInsertionPointToStart(&forOp.getLoopBody().front()); + idxs.push_back(forOp.getInductionVar()); + + for (auto bound : bounds) { + auto forOp = rewriter.create( + op.getLoc(), c0, rewriter.create(op.getLoc(), bound), + c1); + rewriter.setInsertionPointToStart(&forOp.getLoopBody().front()); + idxs.push_back(forOp.getInductionVar()); + } + + rewriter.create(op.getLoc(), val, dst.source(), idxs); + + rewriter.eraseOp(op); + return success(); + } +}; + OpFoldResult Memref2PointerOp::fold(ArrayRef operands) { if (auto subindex = source().getDefiningOp()) { if (auto cop = subindex.index().getDefiningOp()) { @@ -921,6 +1020,7 @@ OpFoldResult Memref2PointerOp::fold(ArrayRef operands) { void Memref2PointerOp::getCanonicalizationPatterns(RewritePatternSet &results, MLIRContext *context) { results.insert, CopySimplification, CopySimplification>(context); } diff --git a/lib/polygeist/Passes/OpenMPOpt.cpp b/lib/polygeist/Passes/OpenMPOpt.cpp index 7ff0aeac6a3a..852ccec8b2cf 100644 --- a/lib/polygeist/Passes/OpenMPOpt.cpp +++ b/lib/polygeist/Passes/OpenMPOpt.cpp @@ -61,9 +61,39 @@ struct CombineParallel : public OpRewritePattern { } }; +struct ParallelForInterchange : public OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + LogicalResult matchAndRewrite(omp::ParallelOp nextParallel, + PatternRewriter &rewriter) const override { + Block *parent = nextParallel->getBlock(); + if (parent->getOperations().size() != 2) + return failure(); + + auto prevFor = dyn_cast(nextParallel->getParentOp()); + if (!prevFor || prevFor->getResults().size()) + return failure(); + + nextParallel->moveBefore(prevFor); + auto yield = nextParallel.getRegion().front().getTerminator(); + auto contents = + rewriter.splitBlock(&nextParallel.getRegion().front(), + nextParallel.getRegion().front().begin()); + rewriter.mergeBlockBefore(contents, &prevFor.getBody()->front()); + rewriter.setInsertionPoint(prevFor.getBody()->getTerminator()); + rewriter.create(nextParallel.getLoc()); + rewriter.setInsertionPointToEnd(&nextParallel.getRegion().front()); + auto newYield = rewriter.clone(*yield); + rewriter.eraseOp(yield); + prevFor->moveBefore(newYield); + return success(); + } +}; + void OpenMPOpt::runOnOperation() { mlir::RewritePatternSet rpl(getOperation()->getContext()); - rpl.add(getOperation()->getContext()); + rpl.add( + getOperation()->getContext()); GreedyRewriteConfig config; config.maxIterations = 47; (void)applyPatternsAndFoldGreedily(getOperation(), std::move(rpl), config); diff --git a/llvm-project b/llvm-project index 82631c919fbb..9abe9693b367 160000 --- a/llvm-project +++ b/llvm-project @@ -1 +1 @@ -Subproject commit 82631c919fbba968efb3e188d592476903c832a6 +Subproject commit 9abe9693b3673edc41948cd954e2552c7e4024c7 diff --git a/tools/mlir-clang/Lib/clang-mlir.cc b/tools/mlir-clang/Lib/clang-mlir.cc index 281e8be173bc..11ada90ad98a 100644 --- a/tools/mlir-clang/Lib/clang-mlir.cc +++ b/tools/mlir-clang/Lib/clang-mlir.cc @@ -3059,6 +3059,10 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { case clang::CastKind::CK_UserDefinedConversion: { return Visit(E->getSubExpr()); } + case clang::CastKind::CK_Dynamic: { + E->dump(); + assert(0 && "dynamic cast not handled yet\n"); + } case clang::CastKind::CK_BaseToDerived: case clang::CastKind::CK_DerivedToBase: case clang::CastKind::CK_UncheckedDerivedToBase: { @@ -3556,7 +3560,8 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { } default: - EmittingFunctionDecl->dump(); + if (EmittingFunctionDecl) + EmittingFunctionDecl->dump(); E->dump(); assert(0 && "unhandled cast"); } diff --git a/tools/mlir-clang/Test/Verification/calloc.c b/tools/mlir-clang/Test/Verification/calloc.c index 483403ee26e1..252c875caf6e 100644 --- a/tools/mlir-clang/Test/Verification/calloc.c +++ b/tools/mlir-clang/Test/Verification/calloc.c @@ -8,20 +8,16 @@ float* zmem(int n) { } // CHECK: func @zmem(%arg0: i32) -> memref attributes {llvm.linkage = #llvm.linkage} { -// CHECK-DAG: %c4_i64 = arith.constant 4 : i64 -// CHECK-DAG: %false = arith.constant false -// CHECK-DAG: %c0_i8 = arith.constant 0 : i8 // CHECK-DAG: %c4 = arith.constant 4 : index +// CHECK-DAG: %cst = arith.constant 0.000000e+00 : f32 +// CHECK-DAG: %c1 = arith.constant 1 : index +// CHECK-DAG: %c0 = arith.constant 0 : index // CHECK-NEXT: %0 = arith.index_cast %arg0 : i32 to index -// CHECK-NEXT: %1 = arith.index_cast %0 : index to i64 -// CHECK-NEXT: %2 = arith.muli %0, %c4 : index -// CHECK-NEXT: %3 = arith.divui %2, %c4 : index -// CHECK-NEXT: %4 = memref.alloc(%3) : memref -// CHECK-NEXT: %5 = "polygeist.memref2pointer"(%4) : (memref) -> !llvm.ptr -// CHECK-NEXT: %6 = arith.muli %1, %c4_i64 : i64 -// CHECK-NEXT: "llvm.intr.memset"(%5, %c0_i8, %6, %false) : (!llvm.ptr, i8, i64, i1) -> () -// TODO-NEXT: scf.for %arg1 = %c0 to %3 step %c1 { -// TODO-NEXT: memref.store %cst, %4[%arg1] : memref -// TODO-NEXT: } -// CHECK-NEXT: return %4 : memref +// CHECK-NEXT: %1 = arith.muli %0, %c4 : index +// CHECK-NEXT: %2 = arith.divui %1, %c4 : index +// CHECK-NEXT: %3 = memref.alloc(%2) : memref +// CHECK-NEXT: scf.for %arg1 = %c0 to %2 step %c1 { +// CHECK-NEXT: memref.store %cst, %3[%arg1] : memref +// CHECK-NEXT: } +// CHECK-NEXT: return %3 : memref // CHECK-NEXT: } diff --git a/tools/mlir-clang/Test/Verification/capture.cpp b/tools/mlir-clang/Test/Verification/capture.cpp index 1779e34e0605..da8256ac528f 100644 --- a/tools/mlir-clang/Test/Verification/capture.cpp +++ b/tools/mlir-clang/Test/Verification/capture.cpp @@ -12,8 +12,8 @@ double kernel_deriche(int x, float y) { } // CHECK: func @kernel_deriche(%arg0: i32, %arg1: f32) -> f64 attributes {llvm.linkage = #llvm.linkage} { -// CHECK-NEXT: %c0_i32 = arith.constant 0 : i32 -// CHECK-NEXT: %c1_i64 = arith.constant 1 : i64 +// CHECK-DAG: %c0_i32 = arith.constant 0 : i32 +// CHECK-DAG: %c1_i64 = arith.constant 1 : i64 // CHECK-NEXT: %0 = llvm.alloca %c1_i64 x !llvm.struct<(memref, i32)> : (i64) -> !llvm.ptr, i32)>> // CHECK-NEXT: %1 = llvm.alloca %c1_i64 x !llvm.struct<(memref, i32)> : (i64) -> !llvm.ptr, i32)>> // CHECK-NEXT: %2 = memref.alloca() : memref<1xf32> diff --git a/tools/mlir-clang/Test/Verification/charswitch.cpp b/tools/mlir-clang/Test/Verification/charswitch.cpp index 6ff1c6e784ec..43598a12f5aa 100644 --- a/tools/mlir-clang/Test/Verification/charswitch.cpp +++ b/tools/mlir-clang/Test/Verification/charswitch.cpp @@ -19,14 +19,14 @@ int foo(char t) { // TODO the select should be canonicalized better // CHECK: func @foo(%arg0: i8) -> i32 attributes {llvm.linkage = #llvm.linkage} { -// CHECK-NEXT: %c-1_i32 = arith.constant -1 : i32 -// CHECK-NEXT: %c30_i32 = arith.constant 30 : i32 -// CHECK-NEXT: %false = arith.constant false -// CHECK-NEXT: %c20_i32 = arith.constant 20 : i32 -// CHECK-NEXT: %c10_i32 = arith.constant 10 : i32 -// CHECK-NEXT: %true = arith.constant true -// CHECK-NEXT: %0 = llvm.mlir.undef : i32 -// CHECK-NEXT: %1 = arith.extsi %arg0 : i8 to i32 +// CHECK-DAG: %c-1_i32 = arith.constant -1 : i32 +// CHECK-DAG: %c30_i32 = arith.constant 30 : i32 +// CHECK-DAG: %false = arith.constant false +// CHECK-DAG: %c20_i32 = arith.constant 20 : i32 +// CHECK-DAG: %c10_i32 = arith.constant 10 : i32 +// CHECK-DAG: %true = arith.constant true +// CHECK-DAG: %0 = llvm.mlir.undef : i32 +// CHECK-DAG: %1 = arith.extsi %arg0 : i8 to i32 // CHECK-NEXT: switch %1 : i32, [ // CHECK-NEXT: default: ^bb1(%c10_i32, %false, %c-1_i32 : i32, i1, i32), // CHECK-NEXT: 97: ^bb1(%c20_i32, %true, %0 : i32, i1, i32), diff --git a/tools/mlir-clang/Test/Verification/consabi.cpp b/tools/mlir-clang/Test/Verification/consabi.cpp index 34bd8ff9a3fd..c01745121fd6 100644 --- a/tools/mlir-clang/Test/Verification/consabi.cpp +++ b/tools/mlir-clang/Test/Verification/consabi.cpp @@ -30,16 +30,14 @@ QStream ilaunch_kernel(QStream x) { // CHECK-NEXT: %1 = llvm.load %0 : !llvm.ptr // CHECK-NEXT: %2 = llvm.bitcast %arg0 : !llvm.ptr, i32)>> to !llvm.ptr // CHECK-NEXT: llvm.store %1, %2 : !llvm.ptr -// CHECK-NEXT: %3 = llvm.bitcast %arg1 : !llvm.ptr, i32)>> to !llvm.ptr -// CHECK-NEXT: %4 = llvm.getelementptr %3[%c1_i32] : (!llvm.ptr, i32) -> !llvm.ptr -// CHECK-NEXT: %5 = llvm.load %4 : !llvm.ptr -// CHECK-NEXT: %6 = llvm.bitcast %arg0 : !llvm.ptr, i32)>> to !llvm.ptr -// CHECK-NEXT: %7 = llvm.getelementptr %6[%c1_i32] : (!llvm.ptr, i32) -> !llvm.ptr -// CHECK-NEXT: llvm.store %5, %7 : !llvm.ptr -// CHECK-NEXT: %8 = llvm.getelementptr %arg1[%c0_i32, 1] : (!llvm.ptr, i32)>>, i32) -> !llvm.ptr -// CHECK-NEXT: %9 = llvm.load %8 : !llvm.ptr -// CHECK-NEXT: %10 = llvm.getelementptr %arg0[%c0_i32, 1] : (!llvm.ptr, i32)>>, i32) -> !llvm.ptr -// CHECK-NEXT: llvm.store %9, %10 : !llvm.ptr +// CHECK-NEXT: %[[a4:.+]] = llvm.getelementptr %0[%c1_i32] : (!llvm.ptr, i32) -> !llvm.ptr +// CHECK-NEXT: %[[a5:.+]] = llvm.load %[[a4]] : !llvm.ptr +// CHECK-NEXT: %[[a7:.+]] = llvm.getelementptr %2[%c1_i32] : (!llvm.ptr, i32) -> !llvm.ptr +// CHECK-NEXT: llvm.store %[[a5]], %[[a7]] : !llvm.ptr +// CHECK-NEXT: %[[a8:.+]] = llvm.getelementptr %arg1[%c0_i32, 1] : (!llvm.ptr, i32)>>, i32) -> !llvm.ptr +// CHECK-NEXT: %[[a9:.+]] = llvm.load %[[a8]] : !llvm.ptr +// CHECK-NEXT: %[[a10:.+]] = llvm.getelementptr %arg0[%c0_i32, 1] : (!llvm.ptr, i32)>>, i32) -> !llvm.ptr +// CHECK-NEXT: llvm.store %[[a9]], %[[a10]] : !llvm.ptr // CHECK-NEXT: return // CHECK-NEXT: } // CHECK-NEXT: func @_ZN1DC1EOS_(%arg0: memref, %arg1: memref) attributes {llvm.linkage = #llvm.linkage} { diff --git a/tools/mlir-clang/Test/Verification/constexpr.cpp b/tools/mlir-clang/Test/Verification/constexpr.cpp index 1d33f0db75d4..bae3a9176636 100644 --- a/tools/mlir-clang/Test/Verification/constexpr.cpp +++ b/tools/mlir-clang/Test/Verification/constexpr.cpp @@ -11,9 +11,9 @@ int foo() { } // CHECK: func @_Z3foov() -> i32 attributes {llvm.linkage = #llvm.linkage} { -// CHECK-NEXT: %c1 = arith.constant 1 : index -// CHECK-NEXT: %c0 = arith.constant 0 : index -// CHECK-NEXT: %c14 = arith.constant 14 : index +// CHECK-DAG: %c1 = arith.constant 1 : index +// CHECK-DAG: %c0 = arith.constant 0 : index +// CHECK-DAG: %c14 = arith.constant 14 : index // CHECK-NEXT: %0 = memref.alloca() : memref<14xi32> // CHECK-NEXT: scf.for %arg0 = %c0 to %c14 step %c1 { // CHECK-NEXT: %3 = arith.index_cast %arg0 : index to i32 diff --git a/tools/mlir-clang/Test/Verification/fscanf.c b/tools/mlir-clang/Test/Verification/fscanf.c index 225c285de4b7..9f738e08b24a 100644 --- a/tools/mlir-clang/Test/Verification/fscanf.c +++ b/tools/mlir-clang/Test/Verification/fscanf.c @@ -37,9 +37,9 @@ int* alloc() { // CHECK-NEXT: %6 = arith.muli %5, %c4 : index // CHECK-NEXT: %7 = arith.divui %6, %c4 : index // CHECK-NEXT: %8 = memref.alloc(%7) : memref -// CHECK-NEXT: scf.for %arg0 = %c0 to %5 step %c1 { // CHECK-NEXT: %9 = llvm.mlir.addressof @str1 : !llvm.ptr> // CHECK-NEXT: %10 = llvm.getelementptr %9[%c0_i32, %c0_i32] : (!llvm.ptr>, i32, i32) -> !llvm.ptr +// CHECK-NEXT: scf.for %arg0 = %c0 to %5 step %c1 { // CHECK-NEXT: %11 = llvm.call @__isoc99_scanf(%10, %0) : (!llvm.ptr, !llvm.ptr) -> i32 // CHECK-NEXT: %12 = llvm.load %0 : !llvm.ptr // CHECK-NEXT: memref.store %12, %8[%arg0] : memref diff --git a/tools/mlir-clang/Test/Verification/hist.c b/tools/mlir-clang/Test/Verification/hist.c index c7b55aaac759..a3042a4f5b18 100644 --- a/tools/mlir-clang/Test/Verification/hist.c +++ b/tools/mlir-clang/Test/Verification/hist.c @@ -11,17 +11,19 @@ int runHisto(int totalNum, int partialNum) { } // CHECK: func @runHisto(%arg0: i32, %arg1: i32) -> i32 -// CHECK-NEXT: %c2_i32 = arith.constant 2 : i32 -// CHECK-NEXT: %c0_i32 = arith.constant 0 : i32 -// CHECK-NEXT: %c0 = arith.constant 0 : index -// CHECK-NEXT: %0 = arith.muli %arg1, %c2_i32 : i32 -// CHECK-NEXT: %1 = arith.index_cast %arg0 : i32 to index -// CHECK-NEXT: %2 = arith.index_cast %0 : i32 to index -// CHECK-NEXT: scf.for %arg2 = %c0 to %1 step %2 { -// CHECK-NEXT: %3 = arith.divui %arg2, %2 : index -// CHECK-NEXT: %4 = arith.index_cast %3 : index to i32 -// CHECK-NEXT: %5 = arith.muli %4, %0 : i32 -// CHECK-NEXT: call @histo_kernel(%5) : (i32) -> () +// CHECK-DAG: %c2_i32 = arith.constant 2 : i32 +// CHECK-DAG: %c0_i32 = arith.constant 0 : i32 +// CHECK-DAG: %c0 = arith.constant 0 : index +// CHECK-DAG: %c2 = arith.constant 2 : index +// CHECK-NEXT: %0 = arith.index_cast %arg1 : i32 to index +// CHECK-NEXT: %1 = arith.muli %arg1, %c2_i32 : i32 +// CHECK-NEXT: %2 = arith.index_cast %arg0 : i32 to index +// CHECK-NEXT: %3 = arith.muli %0, %c2 : index +// CHECK-NEXT: scf.for %arg2 = %c0 to %2 step %3 { +// CHECK-NEXT: %4 = arith.index_cast %arg2 : index to i32 +// CHECK-NEXT: %5 = arith.divui %4, %1 : i32 +// CHECK-NEXT: %6 = arith.muli %5, %1 : i32 +// CHECK-NEXT: call @histo_kernel(%6) : (i32) -> () // CHECK-NEXT: } // CHECK-NEXT: return %c0_i32 : i32 // CHECK-NEXT: } diff --git a/tools/mlir-clang/Test/Verification/ident.cpp b/tools/mlir-clang/Test/Verification/ident.cpp index 96049c556da7..acc39b1f98ac 100644 --- a/tools/mlir-clang/Test/Verification/ident.cpp +++ b/tools/mlir-clang/Test/Verification/ident.cpp @@ -66,8 +66,8 @@ void lt_kernel_cuda(MTensorIterator& iter) { // CHECK-NEXT: return %2 : i8 // CHECK-NEXT: } // CHECK: func private @_ZZ14lt_kernel_cudaENK3$_0clEv(%arg0: !llvm.ptr)>)>>)>>) attributes {llvm.linkage = #llvm.linkage} { -// CHECK-NEXT: %c1_i64 = arith.constant 1 : i64 -// CHECK-NEXT: %c0_i32 = arith.constant 0 : i32 +// CHECK-DAG: %c1_i64 = arith.constant 1 : i64 +// CHECK-DAG: %c0_i32 = arith.constant 0 : i32 // CHECK-NEXT: %0 = llvm.alloca %c1_i64 x !llvm.struct<(i8)> : (i64) -> !llvm.ptr> // CHECK-NEXT: %1 = llvm.alloca %c1_i64 x !llvm.struct<(i8)> : (i64) -> !llvm.ptr> // CHECK-NEXT: %2 = llvm.getelementptr %arg0[%c0_i32, 0] : (!llvm.ptr)>)>>)>>, i32) -> !llvm.ptr)>)>>> diff --git a/tools/mlir-clang/Test/Verification/label.c b/tools/mlir-clang/Test/Verification/label.c index edd7855517b4..3faed11e6c7c 100644 --- a/tools/mlir-clang/Test/Verification/label.c +++ b/tools/mlir-clang/Test/Verification/label.c @@ -13,11 +13,11 @@ int fir (int d_i[1000], int idx[1000] ) { } // CHECK: func @fir(%arg0: memref, %arg1: memref) -> i32 attributes {llvm.linkage = #llvm.linkage} { -// CHECK-NEXT: %c1 = arith.constant 1 : index -// CHECK-NEXT: %c0 = arith.constant 0 : index -// CHECK-NEXT: %c1000 = arith.constant 1000 : index -// CHECK-NEXT: %c999 = arith.constant 999 : index -// CHECK-NEXT: %c0_i32 = arith.constant 0 : i32 +// CHECK-DAG: %c1 = arith.constant 1 : index +// CHECK-DAG: %c0 = arith.constant 0 : index +// CHECK-DAG: %c1000 = arith.constant 1000 : index +// CHECK-DAG: %c999 = arith.constant 999 : index +// CHECK-DAG: %c0_i32 = arith.constant 0 : i32 // CHECK-NEXT: %0:2 = scf.for %arg2 = %c0 to %c1000 step %c1 iter_args(%arg3 = %c0_i32, %arg4 = %c0_i32) -> (i32, i32) { // CHECK-NEXT: %1 = memref.load %arg1[%arg2] : memref // CHECK-NEXT: %2 = arith.subi %c999, %arg2 : index diff --git a/tools/mlir-clang/Test/Verification/loopinc.c b/tools/mlir-clang/Test/Verification/loopinc.c index 8428814bc567..28c209bf1029 100644 --- a/tools/mlir-clang/Test/Verification/loopinc.c +++ b/tools/mlir-clang/Test/Verification/loopinc.c @@ -11,10 +11,10 @@ unsigned int test() { } // CHECK: func @test() -> i32 attributes {llvm.linkage = #llvm.linkage} { -// CHECK-NEXT: %c0_i32 = arith.constant 0 : i32 -// CHECK-NEXT: %c1_i32 = arith.constant 1 : i32 -// CHECK-NEXT: %true = arith.constant true -// CHECK-NEXT: %0 = scf.while (%arg0 = %c0_i32, %arg1 = %true) : (i32, i1) -> i32 { +// CHECK-DAG: %c0_i32 = arith.constant 0 : i32 +// CHECK-DAG: %c1_i32 = arith.constant 1 : i32 +// CHECK-DAG: %true = arith.constant true +// CHECK-DAG: %0 = scf.while (%arg0 = %c0_i32, %arg1 = %true) : (i32, i1) -> i32 { // CHECK-NEXT: scf.condition(%arg1) %arg0 : i32 // CHECK-NEXT: } do { // CHECK-NEXT: ^bb0(%arg0: i32): diff --git a/tools/mlir-clang/Test/Verification/memcpystruct.c b/tools/mlir-clang/Test/Verification/memcpystruct.c index 8f18da91066c..a33b30b9e3b0 100644 --- a/tools/mlir-clang/Test/Verification/memcpystruct.c +++ b/tools/mlir-clang/Test/Verification/memcpystruct.c @@ -10,9 +10,9 @@ void copy(struct N* dst, void* src) { } // CHECK: func @copy(%arg0: memref, %arg1: !llvm.ptr) -// CHECK-NEXT: %false = arith.constant false -// CHECK-NEXT: %c8_i64 = arith.constant 8 : i64 -// CHECK-NEXT: %0 = "polygeist.memref2pointer"(%arg0) : (memref) -> !llvm.ptr +// CHECK-DAG: %false = arith.constant false +// CHECK-DAG: %c8_i64 = arith.constant 8 : i64 +// CHECK-DAG: %0 = "polygeist.memref2pointer"(%arg0) : (memref) -> !llvm.ptr // CHECK-NEXT: "llvm.intr.memcpy"(%0, %arg1, %c8_i64, %false) : (!llvm.ptr, !llvm.ptr, i64, i1) -> () // CHECK-NEXT: return // CHECK-NEXT: } diff --git a/tools/mlir-clang/Test/Verification/omp3.c b/tools/mlir-clang/Test/Verification/omp3.c index 887a56829fb5..71733cafb7c2 100644 --- a/tools/mlir-clang/Test/Verification/omp3.c +++ b/tools/mlir-clang/Test/Verification/omp3.c @@ -11,11 +11,11 @@ void square(double* x) { } // CHECK: func @square(%arg0: memref) -// CHECK-NEXT: %c1 = arith.constant 1 : index -// CHECK-NEXT: %c2 = arith.constant 2 : index -// CHECK-NEXT: %c11 = arith.constant 11 : index -// CHECK-NEXT: %c1_i32 = arith.constant 1 : i32 -// CHECK-NEXT: %c3 = arith.constant 3 : index +// CHECK-DAG: %c1 = arith.constant 1 : index +// CHECK-DAG: %c2 = arith.constant 2 : index +// CHECK-DAG: %c11 = arith.constant 11 : index +// CHECK-DAG: %c1_i32 = arith.constant 1 : i32 +// CHECK-DAG: %c3 = arith.constant 3 : index // CHECK-NEXT: scf.parallel (%arg1) = (%c3) to (%c11) step (%c2) { // CHECK-NEXT: %0 = arith.index_cast %arg1 : index to i32 // CHECK-NEXT: %1 = arith.sitofp %0 : i32 to f64 diff --git a/tools/mlir-clang/Test/Verification/omp4.c b/tools/mlir-clang/Test/Verification/omp4.c index 2d54f34f0ec8..1d053d2b8b36 100644 --- a/tools/mlir-clang/Test/Verification/omp4.c +++ b/tools/mlir-clang/Test/Verification/omp4.c @@ -12,10 +12,10 @@ void square(double* x, int ss) { } // CHECK: func @square(%arg0: memref, %arg1: i32) -// CHECK-NEXT: %c1 = arith.constant 1 : index -// CHECK-NEXT: %c11 = arith.constant 11 : index -// CHECK-NEXT: %c2 = arith.constant 2 : index -// CHECK-NEXT: %c1_i32 = arith.constant 1 : i32 +// CHECK-DAG: %c1 = arith.constant 1 : index +// CHECK-DAG: %c11 = arith.constant 11 : index +// CHECK-DAG: %c2 = arith.constant 2 : index +// CHECK-DAG: %c1_i32 = arith.constant 1 : i32 // CHECK-NEXT: %0 = call @get(%arg1) : (i32) -> i32 // CHECK-NEXT: %1 = arith.index_cast %0 : i32 to index // CHECK-NEXT: %2 = arith.subi %c11, %1 : index diff --git a/tools/mlir-clang/Test/Verification/pair.c b/tools/mlir-clang/Test/Verification/pair.c index a91d6d913975..facfcdf9da32 100644 --- a/tools/mlir-clang/Test/Verification/pair.c +++ b/tools/mlir-clang/Test/Verification/pair.c @@ -27,9 +27,9 @@ int create() { // CHECK-NEXT: return // CHECK-NEXT: } // CHECK: func @create() -> i32 -// CHECK-NEXT: %c2_i32 = arith.constant 2 : i32 -// CHECK-NEXT: %c1_i32 = arith.constant 1 : i32 -// CHECK-NEXT: %c0_i32 = arith.constant 0 : i32 +// CHECK-DAG: %c2_i32 = arith.constant 2 : i32 +// CHECK-DAG: %c1_i32 = arith.constant 1 : i32 +// CHECK-DAG: %c0_i32 = arith.constant 0 : i32 // CHECK-NEXT: %0 = memref.alloca() : memref<1x2xi32> // CHECK-NEXT: %1 = memref.alloca() : memref<1x2xi32> // CHECK-NEXT: affine.store %c0_i32, %1[0, 0] : memref<1x2xi32> diff --git a/tools/mlir-clang/Test/Verification/pairinit.c b/tools/mlir-clang/Test/Verification/pairinit.c index 1830096009e7..7f4ee7624371 100644 --- a/tools/mlir-clang/Test/Verification/pairinit.c +++ b/tools/mlir-clang/Test/Verification/pairinit.c @@ -10,8 +10,8 @@ struct pair func() { } // CHECK: func @func(%arg0: memref) attributes {llvm.linkage = #llvm.linkage} { -// CHECK-NEXT: %c3_i32 = arith.constant 3 : i32 -// CHECK-NEXT: %c2_i32 = arith.constant 2 : i32 +// CHECK-DAG: %c3_i32 = arith.constant 3 : i32 +// CHECK-DAG: %c2_i32 = arith.constant 2 : i32 // CHECK-NEXT: affine.store %c2_i32, %arg0[0, 0] : memref // CHECK-NEXT: affine.store %c3_i32, %arg0[0, 1] : memref // CHECK-NEXT: return diff --git a/tools/mlir-clang/Test/Verification/pairptr.c b/tools/mlir-clang/Test/Verification/pairptr.c index 0ae9eb2c7470..1e65a930b5ac 100644 --- a/tools/mlir-clang/Test/Verification/pairptr.c +++ b/tools/mlir-clang/Test/Verification/pairptr.c @@ -25,9 +25,9 @@ int create() { // CHECK-NEXT: return // CHECK-NEXT: } // CHECK: func @create() -> i32 -// CHECK-NEXT: %c2_i32 = arith.constant 2 : i32 -// CHECK-NEXT: %c1_i32 = arith.constant 1 : i32 -// CHECK-NEXT: %c0_i32 = arith.constant 0 : i32 +// CHECK-DAG: %c2_i32 = arith.constant 2 : i32 +// CHECK-DAG: %c1_i32 = arith.constant 1 : i32 +// CHECK-DAG: %c0_i32 = arith.constant 0 : i32 // CHECK-NEXT: %0 = memref.alloca() : memref<1x2xi32> // CHECK-NEXT: %1 = memref.alloca() : memref<1x2xi32> // CHECK-NEXT: affine.store %c0_i32, %1[0, 0] : memref<1x2xi32> diff --git a/tools/mlir-clang/Test/Verification/recurstruct.c b/tools/mlir-clang/Test/Verification/recurstruct.c index 79a8e83de93a..73486311b3e4 100644 --- a/tools/mlir-clang/Test/Verification/recurstruct.c +++ b/tools/mlir-clang/Test/Verification/recurstruct.c @@ -11,9 +11,9 @@ double sum(struct Node* n) { } // CHECK: func @sum(%arg0: !llvm.ptr>, f64)>>) -> f64 attributes {llvm.linkage = #llvm.linkage} { -// CHECK-NEXT: %c0_i32 = arith.constant 0 : i32 -// CHECK-NEXT: %cst = arith.constant 0.000000e+00 : f64 -// CHECK-NEXT: %0 = llvm.mlir.null : !llvm.ptr>, f64)>> +// CHECK-DAG: %c0_i32 = arith.constant 0 : i32 +// CHECK-DAG: %cst = arith.constant 0.000000e+00 : f64 +// CHECK-DAG: %0 = llvm.mlir.null : !llvm.ptr>, f64)>> // CHECK-NEXT: %1 = llvm.icmp "eq" %arg0, %0 : !llvm.ptr>, f64)>> // CHECK-NEXT: %2 = scf.if %1 -> (f64) { // CHECK-NEXT: scf.yield %cst : f64 diff --git a/tools/mlir-clang/Test/Verification/scor2.c b/tools/mlir-clang/Test/Verification/scor2.c index 4ece43035d75..ce437b80da8d 100644 --- a/tools/mlir-clang/Test/Verification/scor2.c +++ b/tools/mlir-clang/Test/Verification/scor2.c @@ -15,8 +15,8 @@ void kernel_correlation(int m, double corr[28]) } // CHECK: func @kernel_correlation(%arg0: i32, %arg1: memref) -// CHECK-NEXT: %cst = arith.constant 0.000000e+00 : f64 -// CHECK-NEXT: %c-1 = arith.constant -1 : index +// CHECK-DAG: %cst = arith.constant 0.000000e+00 : f64 +// CHECK-DAG: %c-1 = arith.constant -1 : index // CHECK-NEXT: %0 = arith.index_cast %arg0 : i32 to index // CHECK-NEXT: %1 = arith.addi %0, %c-1 : index // CHECK-NEXT: affine.for %arg2 = 0 to %1 { diff --git a/tools/mlir-clang/Test/Verification/sec.c b/tools/mlir-clang/Test/Verification/sec.c index 57f93981d6d9..ba9037fd8d96 100644 --- a/tools/mlir-clang/Test/Verification/sec.c +++ b/tools/mlir-clang/Test/Verification/sec.c @@ -13,9 +13,9 @@ int compute_tran_temp(int total_iterations, int num_iterations) } // CHECK: func @compute_tran_temp(%arg0: i32, %arg1: i32) -> i32 -// CHECK-NEXT: %cst = arith.constant 0.000000e+00 : f32 -// CHECK-NEXT: %c0_i32 = arith.constant 0 : i32 -// CHECK-NEXT: %c1_i32 = arith.constant 1 : i32 +// CHECK-DAG: %cst = arith.constant 0.000000e+00 : f32 +// CHECK-DAG: %c0_i32 = arith.constant 0 : i32 +// CHECK-DAG: %c1_i32 = arith.constant 1 : i32 // CHECK-NEXT: %0 = arith.sitofp %arg0 : i32 to f32 // CHECK-NEXT: %1 = arith.sitofp %arg1 : i32 to f32 // CHECK-NEXT: %2:3 = scf.while (%arg2 = %c0_i32, %arg3 = %c1_i32, %arg4 = %cst) : (i32, i32, f32) -> (i32, i32, f32) { diff --git a/tools/mlir-clang/Test/Verification/staticint.c b/tools/mlir-clang/Test/Verification/staticint.c index 11c642583628..e90ccdb94294 100644 --- a/tools/mlir-clang/Test/Verification/staticint.c +++ b/tools/mlir-clang/Test/Verification/staticint.c @@ -9,10 +9,10 @@ int adder(int x) { // CHECK: memref.global "private" @"adder@static@cur@init" : memref<1xi1> = dense // CHECK: memref.global "private" @"adder@static@cur" : memref<1xi32> = uninitialized // CHECK: func @adder(%arg0: i32) -> i32 attributes {llvm.linkage = #llvm.linkage} { -// CHECK-NEXT: %false = arith.constant false -// CHECK-NEXT: %c0_i32 = arith.constant 0 : i32 -// CHECK-NEXT: %0 = memref.get_global @"adder@static@cur" : memref<1xi32> -// CHECK-NEXT: %1 = memref.get_global @"adder@static@cur@init" : memref<1xi1> +// CHECK-DAG: %false = arith.constant false +// CHECK-DAG: %c0_i32 = arith.constant 0 : i32 +// CHECK-DAG: %0 = memref.get_global @"adder@static@cur" : memref<1xi32> +// CHECK-DAG: %1 = memref.get_global @"adder@static@cur@init" : memref<1xi1> // CHECK-NEXT: %2 = affine.load %1[0] : memref<1xi1> // CHECK-NEXT: scf.if %2 { // CHECK-NEXT: affine.store %false, %1[0] : memref<1xi1> diff --git a/tools/mlir-clang/Test/Verification/switcherr.c b/tools/mlir-clang/Test/Verification/switcherr.c index 29f57b213ec9..f8c1181d49d7 100644 --- a/tools/mlir-clang/Test/Verification/switcherr.c +++ b/tools/mlir-clang/Test/Verification/switcherr.c @@ -17,14 +17,14 @@ int foo(int t) { // TODO the select should be canonicalized better // CHECK: func @foo(%arg0: i32) -> i32 attributes {llvm.linkage = #llvm.linkage} { -// CHECK-NEXT: %c-1_i32 = arith.constant -1 : i32 -// CHECK-NEXT: %c30_i32 = arith.constant 30 : i32 -// CHECK-NEXT: %false = arith.constant false -// CHECK-NEXT: %c20_i32 = arith.constant 20 : i32 -// CHECK-NEXT: %c10_i32 = arith.constant 10 : i32 -// CHECK-NEXT: %true = arith.constant true -// CHECK-NEXT: %0 = llvm.mlir.undef : i32 -// CHECK-NEXT: switch %arg0 : i32, [ +// CHECK-DAG: %c-1_i32 = arith.constant -1 : i32 +// CHECK-DAG: %c30_i32 = arith.constant 30 : i32 +// CHECK-DAG: %false = arith.constant false +// CHECK-DAG: %c20_i32 = arith.constant 20 : i32 +// CHECK-DAG: %c10_i32 = arith.constant 10 : i32 +// CHECK-DAG: %true = arith.constant true +// CHECK-DAG: %0 = llvm.mlir.undef : i32 +// CHECK-DAG: switch %arg0 : i32, [ // CHECK-NEXT: default: ^bb1(%c10_i32, %false, %c-1_i32 : i32, i1, i32), // CHECK-NEXT: 1: ^bb1(%c20_i32, %true, %0 : i32, i1, i32), // CHECK-NEXT: 2: ^bb1(%c30_i32, %true, %0 : i32, i1, i32) diff --git a/tools/mlir-clang/Test/Verification/tobits.c b/tools/mlir-clang/Test/Verification/tobits.c index 001869fde9e3..eec1242f455f 100644 --- a/tools/mlir-clang/Test/Verification/tobits.c +++ b/tools/mlir-clang/Test/Verification/tobits.c @@ -10,8 +10,8 @@ float fp32_from_bits(uint32_t w) { } // CHECK: func @fp32_from_bits(%arg0: i32) -> f32 attributes {llvm.linkage = #llvm.linkage} { -// CHECK-NEXT: %c0_i32 = arith.constant 0 : i32 -// CHECK-NEXT: %c1_i64 = arith.constant 1 : i64 +// CHECK-DAG: %c0_i32 = arith.constant 0 : i32 +// CHECK-DAG: %c1_i64 = arith.constant 1 : i64 // CHECK-NEXT: %0 = llvm.alloca %c1_i64 x !llvm.struct<(i32)> : (i64) -> !llvm.ptr> // CHECK-NEXT: %1 = llvm.getelementptr %0[%c0_i32, 0] : (!llvm.ptr>, i32) -> !llvm.ptr // CHECK-NEXT: llvm.store %arg0, %1 : !llvm.ptr diff --git a/tools/mlir-clang/Test/Verification/unlinked.c b/tools/mlir-clang/Test/Verification/unlinked.c index f1e5aab75f3a..efc01356b7a1 100644 --- a/tools/mlir-clang/Test/Verification/unlinked.c +++ b/tools/mlir-clang/Test/Verification/unlinked.c @@ -19,8 +19,8 @@ void kernel_correlation(int table[N][N]) { } // CHECK: func @kernel_correlation(%arg0: memref) -// CHECK-NEXT: %c9_i32 = arith.constant 9 : i32 -// CHECK-NEXT: %c-1_i32 = arith.constant -1 : i32 +// CHECK-DAG: %c9_i32 = arith.constant 9 : i32 +// CHECK-DAG: %c-1_i32 = arith.constant -1 : i32 // CHECK-NEXT: affine.for %arg1 = 0 to 10 { // CHECK-NEXT: %0 = arith.index_cast %arg1 : index to i32 // CHECK-NEXT: %1 = arith.muli %0, %c-1_i32 : i32 diff --git a/tools/mlir-clang/Test/Verification/virt.cpp b/tools/mlir-clang/Test/Verification/virt.cpp index 804b2e0ea108..615580dd9d19 100644 --- a/tools/mlir-clang/Test/Verification/virt.cpp +++ b/tools/mlir-clang/Test/Verification/virt.cpp @@ -31,16 +31,16 @@ void make() { } // CHECK: func @_Z4makev() attributes {llvm.linkage = #llvm.linkage} { -// CHECK-NEXT: %cst = arith.constant 3.140000e+00 : f64 -// CHECK-NEXT: %c3_i32 = arith.constant 3 : i32 -// CHECK-NEXT: %c1_i64 = arith.constant 1 : i64 +// CHECK-DAG: %cst = arith.constant 3.140000e+00 : f64 +// CHECK-DAG: %c3_i32 = arith.constant 3 : i32 +// CHECK-DAG: %c1_i64 = arith.constant 1 : i64 // CHECK-NEXT: %0 = llvm.alloca %c1_i64 x !llvm.struct<(struct<(i32)>, struct<(f32)>, f64)> : (i64) -> !llvm.ptr, struct<(f32)>, f64)>> // CHECK-NEXT: call @_ZN3SubC1Eid(%0, %c3_i32, %cst) : (!llvm.ptr, struct<(f32)>, f64)>>, i32, f64) -> () // CHECK-NEXT: return // CHECK-NEXT: } // CHECK: func @_ZN3SubC1Eid(%arg0: !llvm.ptr, struct<(f32)>, f64)>>, %arg1: i32, %arg2: f64) attributes {llvm.linkage = #llvm.linkage} { -// CHECK-NEXT: %c0_i32 = arith.constant 0 : i32 -// CHECK-NEXT: %c4_i32 = arith.constant 4 : i32 +// CHECK-DAG: %c0_i32 = arith.constant 0 : i32 +// CHECK-DAG: %c4_i32 = arith.constant 4 : i32 // CHECK-NEXT: %0 = "polygeist.pointer2memref"(%arg0) : (!llvm.ptr, struct<(f32)>, f64)>>) -> memref // CHECK-NEXT: call @_ZN4RootC1Ei(%0, %arg1) : (memref, i32) -> () // CHECK-NEXT: %1 = llvm.bitcast %arg0 : !llvm.ptr, struct<(f32)>, f64)>> to !llvm.ptr @@ -63,8 +63,8 @@ void make() { // CHECK-NEXT: return // CHECK-NEXT: } // CHECK: func @_ZN5FRootC1Ev(%arg0: memref) attributes {llvm.linkage = #llvm.linkage} { -// CHECK-NEXT: %c0_i32 = arith.constant 0 : i32 -// CHECK-NEXT: %cst = arith.constant 2.180000e+00 : f32 +// CHECK-DAG: %c0_i32 = arith.constant 0 : i32 +// CHECK-DAG: %cst = arith.constant 2.180000e+00 : f32 // CHECK-NEXT: affine.store %cst, %arg0[0, 0] : memref // CHECK-NEXT: %[[i1:.+]] = llvm.mlir.addressof @str2 : !llvm.ptr> // CHECK-NEXT: %[[i2:.+]] = llvm.getelementptr %[[i1]][%c0_i32, %c0_i32] : (!llvm.ptr>, i32, i32) -> !llvm.ptr diff --git a/tools/mlir-clang/Test/Verification/virt2.cpp b/tools/mlir-clang/Test/Verification/virt2.cpp index 0596cc4423d9..e4fde5e2003c 100644 --- a/tools/mlir-clang/Test/Verification/virt2.cpp +++ b/tools/mlir-clang/Test/Verification/virt2.cpp @@ -28,9 +28,9 @@ void make() { } // CHECK: func @_Z4makev() attributes {llvm.linkage = #llvm.linkage} { -// CHECK-NEXT: %cst = arith.constant 3.140000e+00 : f64 -// CHECK-NEXT: %c3_i32 = arith.constant 3 : i32 -// CHECK-NEXT: %c1_i64 = arith.constant 1 : i64 +// CHECK-DAG: %cst = arith.constant 3.140000e+00 : f64 +// CHECK-DAG: %c3_i32 = arith.constant 3 : i32 +// CHECK-DAG: %c1_i64 = arith.constant 1 : i64 // CHECK-NEXT: %0 = llvm.alloca %c1_i64 x !llvm.struct<(i8)> : (i64) -> !llvm.ptr> // CHECK-NEXT: call @_ZN3SubC1Eid(%0, %c3_i32, %cst) : (!llvm.ptr>, i32, f64) -> () // CHECK-NEXT: return diff --git a/tools/mlir-clang/Test/canonicalization.c b/tools/mlir-clang/Test/canonicalization.c index cfac74464f44..4691d22d1b2f 100644 --- a/tools/mlir-clang/Test/canonicalization.c +++ b/tools/mlir-clang/Test/canonicalization.c @@ -5,27 +5,22 @@ // CHECK-LABEL: func @matrix_power( // CHECK: %[[VAL_0:.*]]: memref<20x20xi32>, %[[VAL_1:.*]]: memref<20xi32>, %[[VAL_2:.*]]: memref<20xi32>, %[[VAL_3:.*]]: memref<20xi32>) -// CHECK: %[[VAL_4:.*]] = arith.constant 20 : index -// CHECK: %[[VAL_5:.*]] = arith.constant 0 : index -// CHECK: %[[VAL_6:.*]] = arith.constant 1 : index -// CHECK: %[[VAL_7:.*]] = arith.constant 1 : i32 +// CHECK-DAG: %[[VAL_4:.*]] = arith.constant 20 : index +// CHECK-DAG: %[[VAL_5:.*]] = arith.constant 0 : index +// CHECK-DAG: %[[VAL_6:.*]] = arith.constant 1 : index // CHECK: scf.for %[[VAL_8:.*]] = %[[VAL_6]] to %[[VAL_4]] step %[[VAL_6]] { // CHECK: %[[VAL_9:.*]] = arith.subi %[[VAL_8]], %[[VAL_6]] : index -// CHECK: %[[VAL_10:.*]] = arith.index_cast %[[VAL_9]] : index to i32 -// CHECK: %[[VAL_11:.*]] = arith.addi %[[VAL_10]], %[[VAL_7]] : i32 -// CHECK: %[[VAL_12:.*]] = arith.index_cast %[[VAL_11]] : i32 to index // CHECK: scf.for %[[VAL_13:.*]] = %[[VAL_5]] to %[[VAL_4]] step %[[VAL_6]] { // CHECK: %[[VAL_14:.*]] = memref.load %[[VAL_1]]{{\[}}%[[VAL_13]]] : memref<20xi32> // CHECK: %[[VAL_15:.*]] = arith.index_cast %[[VAL_14]] : i32 to index // CHECK: %[[VAL_16:.*]] = memref.load %[[VAL_3]]{{\[}}%[[VAL_13]]] : memref<20xi32> -// CHECK: %[[VAL_17:.*]] = arith.subi %[[VAL_12]], %[[VAL_6]] : index // CHECK: %[[VAL_18:.*]] = memref.load %[[VAL_2]]{{\[}}%[[VAL_13]]] : memref<20xi32> // CHECK: %[[VAL_19:.*]] = arith.index_cast %[[VAL_18]] : i32 to index -// CHECK: %[[VAL_20:.*]] = memref.load %[[VAL_0]]{{\[}}%[[VAL_17]], %[[VAL_19]]] : memref<20x20xi32> +// CHECK: %[[VAL_20:.*]] = memref.load %[[VAL_0]]{{\[}}%[[VAL_9]], %[[VAL_19]]] : memref<20x20xi32> // CHECK: %[[VAL_21:.*]] = arith.muli %[[VAL_16]], %[[VAL_20]] : i32 -// CHECK: %[[VAL_22:.*]] = memref.load %[[VAL_0]]{{\[}}%[[VAL_12]], %[[VAL_15]]] : memref<20x20xi32> +// CHECK: %[[VAL_22:.*]] = memref.load %[[VAL_0]]{{\[}}%[[VAL_8]], %[[VAL_15]]] : memref<20x20xi32> // CHECK: %[[VAL_23:.*]] = arith.addi %[[VAL_22]], %[[VAL_21]] : i32 -// CHECK: memref.store %[[VAL_23]], %[[VAL_0]]{{\[}}%[[VAL_12]], %[[VAL_15]]] : memref<20x20xi32> +// CHECK: memref.store %[[VAL_23]], %[[VAL_0]]{{\[}}%[[VAL_8]], %[[VAL_15]]] : memref<20x20xi32> // CHECK: } // CHECK: } // CHECK: return @@ -36,4 +31,4 @@ void matrix_power(int x[20][20], int row[20], int col[20], int a[20]) { x[k][row[p]] += a[p] * x[k - 1][col[p]]; } } -} \ No newline at end of file +} diff --git a/tools/mlir-clang/mlir-clang.cc b/tools/mlir-clang/mlir-clang.cc index 2b45406af8b6..f0dff7c5b238 100644 --- a/tools/mlir-clang/mlir-clang.cc +++ b/tools/mlir-clang/mlir-clang.cc @@ -485,7 +485,8 @@ int main(int argc, char **argv) { optPM.addPass(mlir::createCanonicalizerPass()); optPM.addPass(mlir::createCSEPass()); // Affine must be lowered to enable inlining - optPM.addPass(mlir::createLowerAffinePass()); + if (RaiseToAffine) + optPM.addPass(mlir::createLowerAffinePass()); optPM.addPass(mlir::createCanonicalizerPass()); pm.addPass(mlir::createInlinerPass()); mlir::OpPassManager &optPM2 = pm.nest(); diff --git a/tools/polygeist-opt/polygeist-opt.cpp b/tools/polygeist-opt/polygeist-opt.cpp index 9940d68b1f70..388e522a6f29 100644 --- a/tools/polygeist-opt/polygeist-opt.cpp +++ b/tools/polygeist-opt/polygeist-opt.cpp @@ -25,6 +25,7 @@ #include "mlir/Pass/PassRegistry.h" #include "mlir/Support/MlirOptMain.h" #include "mlir/Transforms/Passes.h" +#include "mlir/Conversion/Passes.h" #include "polygeist/Dialect.h" #include "polygeist/Passes/Passes.h" @@ -61,11 +62,13 @@ int main(int argc, char **argv) { // Register the standard passes we want. mlir::registerCSEPass(); + mlir::registerConvertAffineToStandardPass(); mlir::registerSCCPPass(); mlir::registerInlinerPass(); mlir::registerCanonicalizerPass(); mlir::registerSymbolDCEPass(); mlir::registerLoopInvariantCodeMotionPass(); + mlir::registerConvertSCFToOpenMPPass(); registry.addTypeInterface(); From 6e5a91d432207112b0264aaa5df919e38d2d82d8 Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Thu, 3 Mar 2022 19:17:28 -0500 Subject: [PATCH 14/14] Allow building --- llvm-project | 2 +- tools/mlir-clang/Test/Verification/combif.c | 3 +-- tools/polygeist-opt/polygeist-opt.cpp | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/llvm-project b/llvm-project index 9abe9693b367..758ddba38113 160000 --- a/llvm-project +++ b/llvm-project @@ -1 +1 @@ -Subproject commit 9abe9693b3673edc41948cd954e2552c7e4024c7 +Subproject commit 758ddba38113b2ab48cd6e45d7617463969bf813 diff --git a/tools/mlir-clang/Test/Verification/combif.c b/tools/mlir-clang/Test/Verification/combif.c index b03faa108f39..314d13fdf230 100644 --- a/tools/mlir-clang/Test/Verification/combif.c +++ b/tools/mlir-clang/Test/Verification/combif.c @@ -1,9 +1,8 @@ // RUN: mlir-clang %s --function=* -S | FileCheck %s -// XFAIL: * // TODO handle negation on if combine // TODO remove unused cyclic phi - +// XFAIL: * void use(float); int solver( float** y, diff --git a/tools/polygeist-opt/polygeist-opt.cpp b/tools/polygeist-opt/polygeist-opt.cpp index 388e522a6f29..457b98efbf50 100644 --- a/tools/polygeist-opt/polygeist-opt.cpp +++ b/tools/polygeist-opt/polygeist-opt.cpp @@ -11,6 +11,7 @@ // //===----------------------------------------------------------------------===// +#include "mlir/Conversion/Passes.h" #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Arithmetic/IR/Arithmetic.h" #include "mlir/Dialect/DLTI/DLTI.h" @@ -25,7 +26,6 @@ #include "mlir/Pass/PassRegistry.h" #include "mlir/Support/MlirOptMain.h" #include "mlir/Transforms/Passes.h" -#include "mlir/Conversion/Passes.h" #include "polygeist/Dialect.h" #include "polygeist/Passes/Passes.h"