|
46 | 46 | #include "mlir/Dialect/LLVMIR/LLVMDialect.h" |
47 | 47 | #include "mlir/Dialect/LLVMIR/LLVMTypes.h" |
48 | 48 | #include "mlir/Dialect/Math/IR/Math.h" |
| 49 | +#include "mlir/Dialect/MemRef/IR/MemRef.h" |
49 | 50 | #include "mlir/Dialect/Vector/IR/VectorOps.h" |
50 | 51 | #include "llvm/Support/CommandLine.h" |
51 | 52 | #include "llvm/Support/Debug.h" |
52 | 53 | #include "llvm/Support/MathExtras.h" |
53 | 54 | #include "llvm/Support/raw_ostream.h" |
54 | 55 | #include <cfenv> // temporary -- only used in genIeeeGetOrSetModesOrStatus |
| 56 | +#include <mlir/IR/BuiltinTypes.h> |
| 57 | +#include <mlir/IR/Types.h> |
55 | 58 | #include <optional> |
56 | 59 |
|
57 | 60 | #define DEBUG_TYPE "flang-lower-intrinsic" |
@@ -151,6 +154,22 @@ static constexpr IntrinsicHandler handlers[]{ |
151 | 154 | {"atomicaddf", &I::genAtomicAdd, {{{"a", asAddr}, {"v", asValue}}}, false}, |
152 | 155 | {"atomicaddi", &I::genAtomicAdd, {{{"a", asAddr}, {"v", asValue}}}, false}, |
153 | 156 | {"atomicaddl", &I::genAtomicAdd, {{{"a", asAddr}, {"v", asValue}}}, false}, |
| 157 | + {"atomicandi", &I::genAtomicAnd, {{{"a", asAddr}, {"v", asValue}}}, false}, |
| 158 | + {"atomicdeci", &I::genAtomicDec, {{{"a", asAddr}, {"v", asValue}}}, false}, |
| 159 | + {"atomicinci", &I::genAtomicInc, {{{"a", asAddr}, {"v", asValue}}}, false}, |
| 160 | + {"atomicmaxd", &I::genAtomicMax, {{{"a", asAddr}, {"v", asValue}}}, false}, |
| 161 | + {"atomicmaxf", &I::genAtomicMax, {{{"a", asAddr}, {"v", asValue}}}, false}, |
| 162 | + {"atomicmaxi", &I::genAtomicMax, {{{"a", asAddr}, {"v", asValue}}}, false}, |
| 163 | + {"atomicmaxl", &I::genAtomicMax, {{{"a", asAddr}, {"v", asValue}}}, false}, |
| 164 | + {"atomicmind", &I::genAtomicMin, {{{"a", asAddr}, {"v", asValue}}}, false}, |
| 165 | + {"atomicminf", &I::genAtomicMin, {{{"a", asAddr}, {"v", asValue}}}, false}, |
| 166 | + {"atomicmini", &I::genAtomicMin, {{{"a", asAddr}, {"v", asValue}}}, false}, |
| 167 | + {"atomicminl", &I::genAtomicMin, {{{"a", asAddr}, {"v", asValue}}}, false}, |
| 168 | + {"atomicori", &I::genAtomicOr, {{{"a", asAddr}, {"v", asValue}}}, false}, |
| 169 | + {"atomicsubd", &I::genAtomicSub, {{{"a", asAddr}, {"v", asValue}}}, false}, |
| 170 | + {"atomicsubf", &I::genAtomicSub, {{{"a", asAddr}, {"v", asValue}}}, false}, |
| 171 | + {"atomicsubi", &I::genAtomicSub, {{{"a", asAddr}, {"v", asValue}}}, false}, |
| 172 | + {"atomicsubl", &I::genAtomicSub, {{{"a", asAddr}, {"v", asValue}}}, false}, |
154 | 173 | {"bessel_jn", |
155 | 174 | &I::genBesselJn, |
156 | 175 | {{{"n1", asValue}, {"n2", asValue}, {"x", asValue}}}, |
@@ -2600,6 +2619,75 @@ mlir::Value IntrinsicLibrary::genAtomicAdd(mlir::Type resultType, |
2600 | 2619 | return genAtomBinOp(builder, loc, binOp, args[0], args[1]); |
2601 | 2620 | } |
2602 | 2621 |
|
| 2622 | +mlir::Value IntrinsicLibrary::genAtomicSub(mlir::Type resultType, |
| 2623 | + llvm::ArrayRef<mlir::Value> args) { |
| 2624 | + assert(args.size() == 2); |
| 2625 | + |
| 2626 | + mlir::LLVM::AtomicBinOp binOp = |
| 2627 | + mlir::isa<mlir::IntegerType>(args[1].getType()) |
| 2628 | + ? mlir::LLVM::AtomicBinOp::sub |
| 2629 | + : mlir::LLVM::AtomicBinOp::fsub; |
| 2630 | + return genAtomBinOp(builder, loc, binOp, args[0], args[1]); |
| 2631 | +} |
| 2632 | + |
| 2633 | +mlir::Value IntrinsicLibrary::genAtomicAnd(mlir::Type resultType, |
| 2634 | + llvm::ArrayRef<mlir::Value> args) { |
| 2635 | + assert(args.size() == 2); |
| 2636 | + assert(mlir::isa<mlir::IntegerType>(args[1].getType())); |
| 2637 | + |
| 2638 | + mlir::LLVM::AtomicBinOp binOp = mlir::LLVM::AtomicBinOp::_and; |
| 2639 | + return genAtomBinOp(builder, loc, binOp, args[0], args[1]); |
| 2640 | +} |
| 2641 | + |
| 2642 | +mlir::Value IntrinsicLibrary::genAtomicOr(mlir::Type resultType, |
| 2643 | + llvm::ArrayRef<mlir::Value> args) { |
| 2644 | + assert(args.size() == 2); |
| 2645 | + assert(mlir::isa<mlir::IntegerType>(args[1].getType())); |
| 2646 | + |
| 2647 | + mlir::LLVM::AtomicBinOp binOp = mlir::LLVM::AtomicBinOp::_or; |
| 2648 | + return genAtomBinOp(builder, loc, binOp, args[0], args[1]); |
| 2649 | +} |
| 2650 | + |
| 2651 | +mlir::Value IntrinsicLibrary::genAtomicDec(mlir::Type resultType, |
| 2652 | + llvm::ArrayRef<mlir::Value> args) { |
| 2653 | + assert(args.size() == 2); |
| 2654 | + assert(mlir::isa<mlir::IntegerType>(args[1].getType())); |
| 2655 | + |
| 2656 | + mlir::LLVM::AtomicBinOp binOp = mlir::LLVM::AtomicBinOp::udec_wrap; |
| 2657 | + return genAtomBinOp(builder, loc, binOp, args[0], args[1]); |
| 2658 | +} |
| 2659 | + |
| 2660 | +mlir::Value IntrinsicLibrary::genAtomicInc(mlir::Type resultType, |
| 2661 | + llvm::ArrayRef<mlir::Value> args) { |
| 2662 | + assert(args.size() == 2); |
| 2663 | + assert(mlir::isa<mlir::IntegerType>(args[1].getType())); |
| 2664 | + |
| 2665 | + mlir::LLVM::AtomicBinOp binOp = mlir::LLVM::AtomicBinOp::uinc_wrap; |
| 2666 | + return genAtomBinOp(builder, loc, binOp, args[0], args[1]); |
| 2667 | +} |
| 2668 | + |
| 2669 | +mlir::Value IntrinsicLibrary::genAtomicMax(mlir::Type resultType, |
| 2670 | + llvm::ArrayRef<mlir::Value> args) { |
| 2671 | + assert(args.size() == 2); |
| 2672 | + |
| 2673 | + mlir::LLVM::AtomicBinOp binOp = |
| 2674 | + mlir::isa<mlir::IntegerType>(args[1].getType()) |
| 2675 | + ? mlir::LLVM::AtomicBinOp::max |
| 2676 | + : mlir::LLVM::AtomicBinOp::fmax; |
| 2677 | + return genAtomBinOp(builder, loc, binOp, args[0], args[1]); |
| 2678 | +} |
| 2679 | + |
| 2680 | +mlir::Value IntrinsicLibrary::genAtomicMin(mlir::Type resultType, |
| 2681 | + llvm::ArrayRef<mlir::Value> args) { |
| 2682 | + assert(args.size() == 2); |
| 2683 | + |
| 2684 | + mlir::LLVM::AtomicBinOp binOp = |
| 2685 | + mlir::isa<mlir::IntegerType>(args[1].getType()) |
| 2686 | + ? mlir::LLVM::AtomicBinOp::min |
| 2687 | + : mlir::LLVM::AtomicBinOp::fmin; |
| 2688 | + return genAtomBinOp(builder, loc, binOp, args[0], args[1]); |
| 2689 | +} |
| 2690 | + |
2603 | 2691 | // ASSOCIATED |
2604 | 2692 | fir::ExtendedValue |
2605 | 2693 | IntrinsicLibrary::genAssociated(mlir::Type resultType, |
|
0 commit comments