diff options
author | Mehdi Amini <aminim@google.com> | 2019-12-24 02:47:41 +0000 |
---|---|---|
committer | Mehdi Amini <aminim@google.com> | 2019-12-24 02:47:41 +0000 |
commit | 0f0d0ed1c78f1a80139a1f2133fad5284691a121 (patch) | |
tree | 31979a3137c364e3eb58e0169a7c4029c7ee7db3 /mlir/test/lib/IR/TestFunc.cpp | |
parent | 6f635f90929da9545dd696071a829a1a42f84b30 (diff) | |
parent | 5b4a01d4a63cb66ab981e52548f940813393bf42 (diff) | |
download | bcm5719-llvm-0f0d0ed1c78f1a80139a1f2133fad5284691a121.tar.gz bcm5719-llvm-0f0d0ed1c78f1a80139a1f2133fad5284691a121.zip |
Import MLIR into the LLVM tree
Diffstat (limited to 'mlir/test/lib/IR/TestFunc.cpp')
-rw-r--r-- | mlir/test/lib/IR/TestFunc.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/mlir/test/lib/IR/TestFunc.cpp b/mlir/test/lib/IR/TestFunc.cpp new file mode 100644 index 00000000000..3e131590fae --- /dev/null +++ b/mlir/test/lib/IR/TestFunc.cpp @@ -0,0 +1,58 @@ +//===- TestFunctionLike.cpp - Pass to test helpers on FunctionLike --------===// +// +// Part of the MLIR Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "mlir/IR/Function.h" +#include "mlir/Pass/Pass.h" + +using namespace mlir; + +namespace { +/// This is a test pass for verifying FuncOp's eraseArgument method. +struct TestFuncEraseArg : public ModulePass<TestFuncEraseArg> { + void runOnModule() override { + auto module = getModule(); + + for (FuncOp func : module.getOps<FuncOp>()) { + SmallVector<unsigned, 4> indicesToErase; + for (auto argIndex : llvm::seq<int>(0, func.getNumArguments())) { + if (func.getArgAttr(argIndex, "test.erase_this_arg")) { + // Push back twice to test that duplicate arg indices are handled + // correctly. + indicesToErase.push_back(argIndex); + indicesToErase.push_back(argIndex); + } + } + // Reverse the order to test that unsorted index lists are handled + // correctly. + std::reverse(indicesToErase.begin(), indicesToErase.end()); + func.eraseArguments(indicesToErase); + } + } +}; + +/// This is a test pass for verifying FuncOp's setType method. +struct TestFuncSetType : public ModulePass<TestFuncSetType> { + void runOnModule() override { + auto module = getModule(); + SymbolTable symbolTable(module); + + for (FuncOp func : module.getOps<FuncOp>()) { + auto sym = func.getAttrOfType<FlatSymbolRefAttr>("test.set_type_from"); + if (!sym) + continue; + func.setType(symbolTable.lookup<FuncOp>(sym.getValue()).getType()); + } + } +}; +} // end anonymous namespace + +static PassRegistration<TestFuncEraseArg> pass("test-func-erase-arg", + "Test erasing func args."); + +static PassRegistration<TestFuncSetType> pass2("test-func-set-type", + "Test FuncOp::setType."); |