|
44 | 44 | #include "flang/Runtime/iostat-consts.h" |
45 | 45 | #include "mlir/Dialect/Complex/IR/Complex.h" |
46 | 46 | #include "mlir/Dialect/LLVMIR/LLVMDialect.h" |
| 47 | +#include "mlir/Dialect/LLVMIR/LLVMTypes.h" |
47 | 48 | #include "mlir/Dialect/Math/IR/Math.h" |
48 | 49 | #include "mlir/Dialect/Vector/IR/VectorOps.h" |
49 | 50 | #include "llvm/Support/CommandLine.h" |
50 | 51 | #include "llvm/Support/Debug.h" |
51 | 52 | #include "llvm/Support/MathExtras.h" |
52 | 53 | #include "llvm/Support/raw_ostream.h" |
53 | 54 | #include <cfenv> // temporary -- only used in genIeeeGetOrSetModesOrStatus |
54 | | -#include <mlir/IR/Value.h> |
55 | 55 | #include <optional> |
56 | 56 |
|
57 | 57 | #define DEBUG_TYPE "flang-lower-intrinsic" |
@@ -147,6 +147,10 @@ static constexpr IntrinsicHandler handlers[]{ |
147 | 147 | {"atan2pi", &I::genAtanpi}, |
148 | 148 | {"atand", &I::genAtand}, |
149 | 149 | {"atanpi", &I::genAtanpi}, |
| 150 | + {"atomicaddd", &I::genAtomicAdd, {{{"a", asAddr}, {"v", asValue}}}, false}, |
| 151 | + {"atomicaddf", &I::genAtomicAdd, {{{"a", asAddr}, {"v", asValue}}}, false}, |
| 152 | + {"atomicaddi", &I::genAtomicAdd, {{{"a", asAddr}, {"v", asValue}}}, false}, |
| 153 | + {"atomicaddl", &I::genAtomicAdd, {{{"a", asAddr}, {"v", asValue}}}, false}, |
150 | 154 | {"bessel_jn", |
151 | 155 | &I::genBesselJn, |
152 | 156 | {{{"n1", asValue}, {"n2", asValue}, {"x", asValue}}}, |
@@ -2574,6 +2578,26 @@ mlir::Value IntrinsicLibrary::genAtanpi(mlir::Type resultType, |
2574 | 2578 | return builder.create<mlir::arith::MulFOp>(loc, atan, factor); |
2575 | 2579 | } |
2576 | 2580 |
|
| 2581 | +static mlir::Value genAtomBinOp(fir::FirOpBuilder &builder, mlir::Location &loc, |
| 2582 | + mlir::LLVM::AtomicBinOp binOp, mlir::Value arg0, |
| 2583 | + mlir::Value arg1) { |
| 2584 | + auto llvmPointerType = mlir::LLVM::LLVMPointerType::get(builder.getContext()); |
| 2585 | + arg0 = builder.createConvert(loc, llvmPointerType, arg0); |
| 2586 | + return builder.create<mlir::LLVM::AtomicRMWOp>( |
| 2587 | + loc, binOp, arg0, arg1, mlir::LLVM::AtomicOrdering::seq_cst); |
| 2588 | +} |
| 2589 | + |
| 2590 | +mlir::Value IntrinsicLibrary::genAtomicAdd(mlir::Type resultType, |
| 2591 | + llvm::ArrayRef<mlir::Value> args) { |
| 2592 | + assert(args.size() == 2); |
| 2593 | + |
| 2594 | + mlir::LLVM::AtomicBinOp binOp = |
| 2595 | + mlir::isa<mlir::IntegerType>(args[1].getType()) |
| 2596 | + ? mlir::LLVM::AtomicBinOp::add |
| 2597 | + : mlir::LLVM::AtomicBinOp::fadd; |
| 2598 | + return genAtomBinOp(builder, loc, binOp, args[0], args[1]); |
| 2599 | +} |
| 2600 | + |
2577 | 2601 | // ASSOCIATED |
2578 | 2602 | fir::ExtendedValue |
2579 | 2603 | IntrinsicLibrary::genAssociated(mlir::Type resultType, |
|
0 commit comments