55 lines · cpp
1//===- TestInterfaces.cpp - Test interface generation and application -----===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "TestTypes.h"10#include "mlir/IR/BuiltinOps.h"11#include "mlir/Pass/Pass.h"12 13using namespace mlir;14using namespace test;15 16namespace {17/// This test checks various aspects of Type interface generation and18/// application.19struct TestTypeInterfaces20 : public PassWrapper<TestTypeInterfaces, OperationPass<ModuleOp>> {21 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestTypeInterfaces)22 23 StringRef getArgument() const final { return "test-type-interfaces"; }24 StringRef getDescription() const final {25 return "Test type interface support.";26 }27 void runOnOperation() override {28 getOperation().walk([](Operation *op) {29 for (Type type : op->getResultTypes()) {30 if (auto testInterface = dyn_cast<TestTypeInterface>(type)) {31 testInterface.printTypeA(op->getLoc());32 testInterface.printTypeB(op->getLoc());33 testInterface.printTypeC(op->getLoc());34 testInterface.printTypeC(op->getLoc(), 42);35 testInterface.printTypeC(op->getLoc(), 3.14f);36 testInterface.printTypeD(op->getLoc());37 // Just check that we can assign the result to a variable of interface38 // type.39 TestTypeInterface result = testInterface.printTypeRet(op->getLoc());40 (void)result;41 }42 if (auto testType = dyn_cast<TestType>(type))43 testType.printTypeE(op->getLoc());44 }45 });46 }47};48} // namespace49 50namespace mlir {51namespace test {52void registerTestInterfaces() { PassRegistration<TestTypeInterfaces>(); }53} // namespace test54} // namespace mlir55