MLIR  19.0.0git
AttrToLLVMConverter.cpp
Go to the documentation of this file.
1 //===- AttrToLLVMConverter.cpp - Arith attributes conversion to LLVM ------===//
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 
10 
11 using namespace mlir;
12 
13 LLVM::FastmathFlags
14 mlir::arith::convertArithFastMathFlagsToLLVM(arith::FastMathFlags arithFMF) {
15  LLVM::FastmathFlags llvmFMF{};
16  const std::pair<arith::FastMathFlags, LLVM::FastmathFlags> flags[] = {
17  {arith::FastMathFlags::nnan, LLVM::FastmathFlags::nnan},
18  {arith::FastMathFlags::ninf, LLVM::FastmathFlags::ninf},
19  {arith::FastMathFlags::nsz, LLVM::FastmathFlags::nsz},
20  {arith::FastMathFlags::arcp, LLVM::FastmathFlags::arcp},
22  {arith::FastMathFlags::afn, LLVM::FastmathFlags::afn},
23  {arith::FastMathFlags::reassoc, LLVM::FastmathFlags::reassoc}};
24  for (auto [arithFlag, llvmFlag] : flags) {
25  if (bitEnumContainsAny(arithFMF, arithFlag))
26  llvmFMF = llvmFMF | llvmFlag;
27  }
28  return llvmFMF;
29 }
30 
31 LLVM::FastmathFlagsAttr
32 mlir::arith::convertArithFastMathAttrToLLVM(arith::FastMathFlagsAttr fmfAttr) {
33  arith::FastMathFlags arithFMF = fmfAttr.getValue();
35  fmfAttr.getContext(), convertArithFastMathFlagsToLLVM(arithFMF));
36 }
37 
39  arith::IntegerOverflowFlags arithFlags) {
40  LLVM::IntegerOverflowFlags llvmFlags{};
41  const std::pair<arith::IntegerOverflowFlags, LLVM::IntegerOverflowFlags>
42  flags[] = {
43  {arith::IntegerOverflowFlags::nsw, LLVM::IntegerOverflowFlags::nsw},
44  {arith::IntegerOverflowFlags::nuw, LLVM::IntegerOverflowFlags::nuw}};
45  for (auto [arithFlag, llvmFlag] : flags) {
46  if (bitEnumContainsAny(arithFlags, arithFlag))
47  llvmFlags = llvmFlags | llvmFlag;
48  }
49  return llvmFlags;
50 }
51 
52 LLVM::IntegerOverflowFlagsAttr mlir::arith::convertArithOverflowAttrToLLVM(
53  arith::IntegerOverflowFlagsAttr flagsAttr) {
54  arith::IntegerOverflowFlags arithFlags = flagsAttr.getValue();
56  flagsAttr.getContext(), convertArithOverflowFlagsToLLVM(arithFlags));
57 }
static void contract(RootOrderingGraph &graph, ArrayRef< Value > cycle, const DenseMap< Value, unsigned > &parentDepths, DenseMap< Value, Value > &actualSource, DenseMap< Value, Value > &actualTarget)
Contracts the specified cycle in the given graph in-place.
LLVM::IntegerOverflowFlagsAttr convertArithOverflowAttrToLLVM(arith::IntegerOverflowFlagsAttr flagsAttr)
Creates an LLVM overflow attribute from a given arithmetic overflow attribute.
LLVM::FastmathFlagsAttr convertArithFastMathAttrToLLVM(arith::FastMathFlagsAttr fmfAttr)
Creates an LLVM fastmath attribute from a given arithmetic fastmath attribute.
LLVM::IntegerOverflowFlags convertArithOverflowFlagsToLLVM(arith::IntegerOverflowFlags arithFlags)
Maps arithmetic overflow enum values to LLVM enum values.
LLVM::FastmathFlags convertArithFastMathFlagsToLLVM(arith::FastMathFlags arithFMF)
Maps arithmetic fastmath enum values to LLVM enum values.
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...