diff --git a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp --- a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp +++ b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp @@ -29,6 +29,7 @@ #include "flang/Optimizer/Dialect/FIRType.h" #include "flang/Optimizer/Support/FIRContext.h" #include "flang/Optimizer/Transforms/Passes.h" +#include "flang/Runtime/entry-names.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/IR/Matchers.h" #include "mlir/IR/TypeUtilities.h" @@ -45,6 +46,10 @@ #include "flang/Optimizer/Transforms/Passes.h.inc" } // namespace fir +#define RTNAME_STRINGIFY2(x) #x +#define RTNAME_STRINGIFY(x) RTNAME_STRINGIFY2(x) +#define RTNAME_STRING(x) RTNAME_STRINGIFY(RTNAME(x)) + #define DEBUG_TYPE "flang-simplify-intrinsics" namespace { @@ -84,7 +89,7 @@ } // namespace -/// Generate function type for the simplified version of FortranASum and +/// Generate function type for the simplified version of RTNAME(Sum) and /// similar functions with a fir.box type returning \p elementType. static mlir::FunctionType genNoneBoxType(fir::FirOpBuilder &builder, const mlir::Type &elementType) { @@ -158,21 +163,21 @@ builder.create(loc, resultVal); } -/// Generate function body of the simplified version of FortranASum +/// Generate function body of the simplified version of RTNAME(Sum) /// with signature provided by \p funcOp. The caller is responsible /// for saving/restoring the original insertion point of \p builder. /// \p funcOp is expected to be empty on entry to this function. -static void genFortranASumBody(fir::FirOpBuilder &builder, - mlir::func::FuncOp &funcOp) { - // function FortranASum_simplified(arr) +static void genRuntimeSumBody(fir::FirOpBuilder &builder, + mlir::func::FuncOp &funcOp) { + // function RTNAME(Sum)_simplified(arr) // T, dimension(:) :: arr // T sum = 0 // integer iter // do iter = 0, extent(arr) // sum = sum + arr[iter] // end do - // FortranASum_simplified = sum - // end function FortranASum_simplified + // RTNAME(Sum)_simplified = sum + // end function RTNAME(Sum)_simplified auto zero = [](fir::FirOpBuilder builder, mlir::Location loc, mlir::Type elementType) { return elementType.isa() @@ -196,8 +201,8 @@ genReductionLoop(builder, funcOp, zero, genBodyOp); } -static void genFortranAMaxvalBody(fir::FirOpBuilder &builder, - mlir::func::FuncOp &funcOp) { +static void genRuntimeMaxvalBody(fir::FirOpBuilder &builder, + mlir::func::FuncOp &funcOp) { auto init = [](fir::FirOpBuilder builder, mlir::Location loc, mlir::Type elementType) { if (auto ty = elementType.dyn_cast()) { @@ -224,35 +229,35 @@ genReductionLoop(builder, funcOp, init, genBodyOp); } -/// Generate function type for the simplified version of FortranADotProduct +/// Generate function type for the simplified version of RTNAME(DotProduct) /// operating on the given \p elementType. -static mlir::FunctionType genFortranADotType(fir::FirOpBuilder &builder, - const mlir::Type &elementType) { +static mlir::FunctionType genRuntimeDotType(fir::FirOpBuilder &builder, + const mlir::Type &elementType) { mlir::Type boxType = fir::BoxType::get(builder.getNoneType()); return mlir::FunctionType::get(builder.getContext(), {boxType, boxType}, {elementType}); } -/// Generate function body of the simplified version of FortranADotProduct +/// Generate function body of the simplified version of RTNAME(DotProduct) /// with signature provided by \p funcOp. The caller is responsible /// for saving/restoring the original insertion point of \p builder. /// \p funcOp is expected to be empty on entry to this function. /// \p arg1ElementTy and \p arg2ElementTy specify elements types /// of the underlying array objects - they are used to generate proper /// element accesses. -static void genFortranADotBody(fir::FirOpBuilder &builder, - mlir::func::FuncOp &funcOp, - mlir::Type arg1ElementTy, - mlir::Type arg2ElementTy) { - // function FortranADotProduct_simplified(arr1, arr2) +static void genRuntimeDotBody(fir::FirOpBuilder &builder, + mlir::func::FuncOp &funcOp, + mlir::Type arg1ElementTy, + mlir::Type arg2ElementTy) { + // function RTNAME(DotProduct)_simplified(arr1, arr2) // T, dimension(:) :: arr1, arr2 // T product = 0 // integer iter // do iter = 0, extent(arr1) // product = product + arr1[iter] * arr2[iter] // end do - // FortranADotProduct_simplified = product - // end function FortranADotProduct_simplified + // RTNAME(ADotProduct)_simplified = product + // end function RTNAME(DotProduct)_simplified auto loc = mlir::UnknownLoc::get(builder.getContext()); mlir::Type resultElementType = funcOp.getResultTypes()[0]; builder.setInsertionPointToEnd(funcOp.addEntryBlock()); @@ -498,11 +503,11 @@ // RTNAME(Sum)(const Descriptor &x, const char *source, int line, // int dim, const Descriptor *mask) // - if (funcName.startswith("_FortranASum")) { - simplifyReduction(call, kindMap, genFortranASumBody); + if (funcName.startswith(RTNAME_STRING(Sum))) { + simplifyReduction(call, kindMap, genRuntimeSumBody); return; } - if (funcName.startswith("_FortranADotProduct")) { + if (funcName.startswith(RTNAME_STRING(DotProduct))) { LLVM_DEBUG(llvm::dbgs() << "Handling " << funcName << "\n"); LLVM_DEBUG(llvm::dbgs() << "Call operation:\n"; op->dump(); llvm::dbgs() << "\n"); @@ -533,12 +538,12 @@ return; auto typeGenerator = [&type](fir::FirOpBuilder &builder) { - return genFortranADotType(builder, type); + return genRuntimeDotType(builder, type); }; auto bodyGenerator = [&arg1Type, &arg2Type](fir::FirOpBuilder &builder, mlir::func::FuncOp &funcOp) { - genFortranADotBody(builder, funcOp, *arg1Type, *arg2Type); + genRuntimeDotBody(builder, funcOp, *arg1Type, *arg2Type); }; // Suffix the function name with the element types @@ -562,8 +567,8 @@ llvm::dbgs() << "\n"); return; } - if (funcName.startswith("_FortranAMaxval")) { - simplifyReduction(call, kindMap, genFortranAMaxvalBody); + if (funcName.startswith(RTNAME_STRING(Maxval))) { + simplifyReduction(call, kindMap, genRuntimeMaxvalBody); return; } }