DAG: Fix assuming f16 is the only 16-bit fp type in concat vector combine (#121637)
[llvm-project.git] / flang / lib / Optimizer / Transforms / VScaleAttr.cpp
blobd311167c58b4d63f949b6ee2fb369d9bb33eb948
1 //===- VScaleAttr.cpp -------------------------------------------------===//
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-exception
6 //
7 //===----------------------------------------------------------------------===//
9 //===----------------------------------------------------------------------===//
10 /// \file
11 /// This pass adds a `vscale_range` attribute to function definitions.
12 /// The attribute is used for scalable vector operations on Arm processors
13 /// and should only be run on processors that support this feature. [It is
14 /// likely harmless to run it on something else, but it is also not valuable].
15 //===----------------------------------------------------------------------===//
17 #include "flang/ISO_Fortran_binding_wrapper.h"
18 #include "flang/Optimizer/Builder/BoxValue.h"
19 #include "flang/Optimizer/Builder/FIRBuilder.h"
20 #include "flang/Optimizer/Builder/Runtime/Inquiry.h"
21 #include "flang/Optimizer/Dialect/FIRDialect.h"
22 #include "flang/Optimizer/Dialect/FIROps.h"
23 #include "flang/Optimizer/Dialect/FIRType.h"
24 #include "flang/Optimizer/Dialect/Support/FIRContext.h"
25 #include "flang/Optimizer/Dialect/Support/KindMapping.h"
26 #include "flang/Optimizer/Transforms/Passes.h"
27 #include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
28 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
29 #include "mlir/IR/Matchers.h"
30 #include "mlir/IR/TypeUtilities.h"
31 #include "mlir/Pass/Pass.h"
32 #include "mlir/Transforms/DialectConversion.h"
33 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
34 #include "mlir/Transforms/RegionUtils.h"
35 #include "llvm/Support/Debug.h"
36 #include "llvm/Support/raw_ostream.h"
38 #include <algorithm>
40 namespace fir {
41 #define GEN_PASS_DEF_VSCALEATTR
42 #include "flang/Optimizer/Transforms/Passes.h.inc"
43 } // namespace fir
45 #define DEBUG_TYPE "vscale-attr"
47 namespace {
49 class VScaleAttrPass : public fir::impl::VScaleAttrBase<VScaleAttrPass> {
50 public:
51 VScaleAttrPass(const fir::VScaleAttrOptions &options) {
52 vscaleRange = options.vscaleRange;
54 VScaleAttrPass() {}
55 void runOnOperation() override;
58 } // namespace
60 void VScaleAttrPass::runOnOperation() {
61 LLVM_DEBUG(llvm::dbgs() << "=== Begin " DEBUG_TYPE " ===\n");
62 mlir::func::FuncOp func = getOperation();
64 LLVM_DEBUG(llvm::dbgs() << "Func-name:" << func.getSymName() << "\n");
66 auto context = &getContext();
68 auto intTy = mlir::IntegerType::get(context, 32);
70 assert(vscaleRange.first && "VScaleRange minimum should be non-zero");
72 func->setAttr("vscale_range",
73 mlir::LLVM::VScaleRangeAttr::get(
74 context, mlir::IntegerAttr::get(intTy, vscaleRange.first),
75 mlir::IntegerAttr::get(intTy, vscaleRange.second)));
77 LLVM_DEBUG(llvm::dbgs() << "=== End " DEBUG_TYPE " ===\n");