brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 4717ce3 Raw
50 lines · cpp
1//===- TestBuiltinDistinctAttributes.cpp - Test DistinctAttributes --------===//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 "TestDialect.h"10#include "mlir/IR/BuiltinAttributes.h"11#include "mlir/Pass/Pass.h"12 13using namespace mlir;14 15namespace {16/// This is a distinct attribute test pass that tests if distinct attributes can17/// be created in parallel in a deterministic way.18struct DistinctAttributesPass19    : public PassWrapper<DistinctAttributesPass, OperationPass<func::FuncOp>> {20  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(DistinctAttributesPass)21 22  StringRef getArgument() const final { return "test-distinct-attrs"; }23  StringRef getDescription() const final {24    return "Test parallel creation of distinct attributes";25  }26 27  void runOnOperation() override {28    auto funcOp = getOperation();29 30    /// Walk all operations and create a distinct output attribute given a31    /// distinct input attribute.32    funcOp->walk([](Operation *op) {33      auto distinctAttr = op->getAttrOfType<DistinctAttr>("distinct.input");34      if (!distinctAttr)35        return;36      op->setAttr("distinct.output",37                  DistinctAttr::create(distinctAttr.getReferencedAttr()));38    });39  }40};41} // namespace42 43namespace mlir {44namespace test {45void registerTestBuiltinDistinctAttributes() {46  PassRegistration<DistinctAttributesPass>();47}48} // namespace test49} // namespace mlir50