brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · 2f0ea2e Raw
54 lines · cpp
1//===- MathToSPIRVPass.cpp - Math to SPIR-V Passes ------------------------===//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// This file implements a pass to convert standard dialect to SPIR-V dialect.10//11//===----------------------------------------------------------------------===//12 13#include "mlir/Conversion/MathToSPIRV/MathToSPIRVPass.h"14 15#include "mlir/Conversion/MathToSPIRV/MathToSPIRV.h"16#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"17#include "mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h"18 19namespace mlir {20#define GEN_PASS_DEF_CONVERTMATHTOSPIRVPASS21#include "mlir/Conversion/Passes.h.inc"22} // namespace mlir23 24using namespace mlir;25 26namespace {27/// A pass converting MLIR Math operations into the SPIR-V dialect.28class ConvertMathToSPIRVPass29    : public impl::ConvertMathToSPIRVPassBase<ConvertMathToSPIRVPass> {30  void runOnOperation() override;31};32} // namespace33 34void ConvertMathToSPIRVPass::runOnOperation() {35  MLIRContext *context = &getContext();36  Operation *op = getOperation();37 38  auto targetAttr = spirv::lookupTargetEnvOrDefault(op);39  std::unique_ptr<ConversionTarget> target =40      SPIRVConversionTarget::get(targetAttr);41 42  SPIRVTypeConverter typeConverter(targetAttr);43 44  // Use UnrealizedConversionCast as the bridge so that we don't need to pull45  // in patterns for other dialects.46  target->addLegalOp<UnrealizedConversionCastOp>();47 48  RewritePatternSet patterns(context);49  populateMathToSPIRVPatterns(typeConverter, patterns);50 51  if (failed(applyPartialConversion(op, *target, std::move(patterns))))52    return signalPassFailure();53}54