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