MLIR  18.0.0git
AttrToLLVMConverter.h
Go to the documentation of this file.
1 //===- AttrToLLVMConverter.h - Arith attributes conversion ------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
8 
9 #ifndef MLIR_CONVERSION_ARITHCOMMON_ATTRTOLLVMCONVERTER_H
10 #define MLIR_CONVERSION_ARITHCOMMON_ATTRTOLLVMCONVERTER_H
11 
14 
15 //===----------------------------------------------------------------------===//
16 // Support for converting Arith FastMathFlags to LLVM FastmathFlags
17 //===----------------------------------------------------------------------===//
18 
19 namespace mlir {
20 namespace arith {
21 // Map arithmetic fastmath enum values to LLVMIR enum values.
22 LLVM::FastmathFlags
23 convertArithFastMathFlagsToLLVM(arith::FastMathFlags arithFMF);
24 
25 // Create an LLVM fastmath attribute from a given arithmetic fastmath attribute.
26 LLVM::FastmathFlagsAttr
27 convertArithFastMathAttrToLLVM(arith::FastMathFlagsAttr fmfAttr);
28 
29 // Attribute converter that populates a NamedAttrList by removing the fastmath
30 // attribute from the source operation attributes, and replacing it with an
31 // equivalent LLVM fastmath attribute.
32 template <typename SourceOp, typename TargetOp>
34 public:
35  AttrConvertFastMathToLLVM(SourceOp srcOp) {
36  // Copy the source attributes.
37  convertedAttr = NamedAttrList{srcOp->getAttrs()};
38  // Get the name of the arith fastmath attribute.
39  llvm::StringRef arithFMFAttrName = SourceOp::getFastMathAttrName();
40  // Remove the source fastmath attribute.
41  auto arithFMFAttr = dyn_cast_or_null<arith::FastMathFlagsAttr>(
42  convertedAttr.erase(arithFMFAttrName));
43  if (arithFMFAttr) {
44  llvm::StringRef targetAttrName = TargetOp::getFastmathAttrName();
45  convertedAttr.set(targetAttrName,
46  convertArithFastMathAttrToLLVM(arithFMFAttr));
47  }
48  }
49 
50  ArrayRef<NamedAttribute> getAttrs() const { return convertedAttr.getAttrs(); }
51 
52 private:
53  NamedAttrList convertedAttr;
54 };
55 } // namespace arith
56 } // namespace mlir
57 
58 #endif // MLIR_CONVERSION_ARITHCOMMON_ATTRTOLLVMCONVERTER_H
NamedAttrList is array of NamedAttributes that tracks whether it is sorted and does some basic work t...
ArrayRef< NamedAttribute > getAttrs() const
Return all of the attributes on this operation.
Attribute erase(StringAttr name)
Erase the attribute with the given name from the list.
Attribute set(StringAttr name, Attribute value)
If the an attribute exists with the specified name, change it to the new value.
ArrayRef< NamedAttribute > getAttrs() const
LLVM::FastmathFlagsAttr convertArithFastMathAttrToLLVM(arith::FastMathFlagsAttr fmfAttr)
LLVM::FastmathFlags convertArithFastMathFlagsToLLVM(arith::FastMathFlags arithFMF)
Include the generated interface declarations.