Skip to content

Commit

Permalink
Revert "[flang] Set LLVM specific attributes to fir.call's of Fortran…
Browse files Browse the repository at this point in the history
… runtime. (llvm#128093)"

This reverts commit 36fdeb2.
  • Loading branch information
vzakhari committed Feb 24, 2025
1 parent 4d53616 commit 69cc16f
Show file tree
Hide file tree
Showing 19 changed files with 162 additions and 1,971 deletions.
9 changes: 0 additions & 9 deletions flang/include/flang/Optimizer/Builder/FIRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,6 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
mlir::FunctionType ty,
mlir::SymbolTable *);

/// Returns a named function for a Fortran runtime API, creating
/// it, if it does not exist in the module yet.
/// If \p isIO is set to true, then the function corresponds
/// to one of Fortran runtime IO APIs.
mlir::func::FuncOp createRuntimeFunction(mlir::Location loc,
llvm::StringRef name,
mlir::FunctionType ty,
bool isIO = false);

/// Cast the input value to IndexType.
mlir::Value convertToIndexType(mlir::Location loc, mlir::Value val) {
return createConvert(loc, getIndexType(), val);
Expand Down
42 changes: 4 additions & 38 deletions flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "flang/Optimizer/Builder/FIRBuilder.h"
#include "flang/Optimizer/Dialect/FIRDialect.h"
#include "flang/Optimizer/Dialect/FIRType.h"
#include "flang/Runtime/io-api-consts.h"
#include "flang/Runtime/reduce.h"
#include "flang/Support/Fortran.h"
#include "mlir/IR/BuiltinTypes.h"
Expand Down Expand Up @@ -587,33 +586,6 @@ constexpr TypeBuilderFunc getModel<void>() {
};
}

// Define additional runtime type models specific to IO.
template <>
constexpr TypeBuilderFunc getModel<Fortran::runtime::io::IoStatementState *>() {
return getModel<char *>();
}
template <>
constexpr TypeBuilderFunc getModel<Fortran::runtime::io::Iostat>() {
return [](mlir::MLIRContext *context) -> mlir::Type {
return mlir::IntegerType::get(context,
8 * sizeof(Fortran::runtime::io::Iostat));
};
}
template <>
constexpr TypeBuilderFunc
getModel<const Fortran::runtime::io::NamelistGroup &>() {
return [](mlir::MLIRContext *context) -> mlir::Type {
return fir::ReferenceType::get(mlir::TupleType::get(context));
};
}
template <>
constexpr TypeBuilderFunc
getModel<const Fortran::runtime::io::NonTbpDefinedIoTable *>() {
return [](mlir::MLIRContext *context) -> mlir::Type {
return fir::ReferenceType::get(mlir::TupleType::get(context));
};
}

REDUCTION_REF_OPERATION_MODEL(std::int8_t)
REDUCTION_VALUE_OPERATION_MODEL(std::int8_t)
REDUCTION_REF_OPERATION_MODEL(std::int16_t)
Expand Down Expand Up @@ -806,22 +778,16 @@ struct RuntimeTableEntry<RuntimeTableKey<KT>, RuntimeIdentifier<Cs...>> {
/// argument is intended to be of the form: <mkRTKey(runtime function name)>.
template <typename RuntimeEntry>
static mlir::func::FuncOp getRuntimeFunc(mlir::Location loc,
fir::FirOpBuilder &builder,
bool isIO = false) {
fir::FirOpBuilder &builder) {
using namespace Fortran::runtime;
auto name = RuntimeEntry::name;
auto func = builder.getNamedFunction(name);
if (func)
return func;
auto funTy = RuntimeEntry::getTypeModel()(builder.getContext());
return builder.createRuntimeFunction(loc, name, funTy, isIO);
}

/// Get (or generate) the MLIR FuncOp for a given IO runtime function.
template <typename E>
static mlir::func::FuncOp getIORuntimeFunc(mlir::Location loc,
fir::FirOpBuilder &builder) {
return getRuntimeFunc<E>(loc, builder, /*isIO=*/true);
func = builder.createFunction(loc, name, funTy);
func->setAttr(FIROpsDialect::getFirRuntimeAttrName(), builder.getUnitAttr());
return func;
}

namespace helper {
Expand Down
12 changes: 0 additions & 12 deletions flang/include/flang/Optimizer/Dialect/FIRDialect.td
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,6 @@ def FIROpsDialect : Dialect {
static constexpr llvm::StringRef getFirRuntimeAttrName() {
return "fir.runtime";
}
// Return string name of fir.memory attributes.
// It is attached to fir.call operations to convey
// llvm.memory attributes to LLVM IR.
// Its value is intended to be mlir::LLVM::MemoryEffectsAttr.
// TODO: we should probably make it an inherent attribute
// of fir.call, though, it is supposed to be a short-lived
// attribute that appears right before CodeGen and only
// meaningful for LLVM, so it is unclear if embedding
// it into fir.call makes sense.
static constexpr llvm::StringRef getFirCallMemoryAttrName() {
return "fir.llvm_memory";
}
}];
}

Expand Down
2 changes: 0 additions & 2 deletions flang/include/flang/Optimizer/Transforms/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ namespace fir {
#define GEN_PASS_DECL_FUNCTIONATTR
#define GEN_PASS_DECL_CONSTANTARGUMENTGLOBALISATIONOPT
#define GEN_PASS_DECL_COMPILERGENERATEDNAMESCONVERSION
#define GEN_PASS_DECL_SETRUNTIMECALLATTRIBUTES
#define GEN_PASS_DECL_GENRUNTIMECALLSFORTEST

#include "flang/Optimizer/Transforms/Passes.h.inc"

Expand Down
33 changes: 0 additions & 33 deletions flang/include/flang/Optimizer/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -453,37 +453,4 @@ def CUFGPUToLLVMConversion : Pass<"cuf-gpu-convert-to-llvm", "mlir::ModuleOp"> {
];
}

def SetRuntimeCallAttributes
: Pass<"set-runtime-call-attrs", "mlir::func::FuncOp"> {
let summary = "Set Fortran runtime fir.call attributes targeting LLVM IR";
let description = [{
This pass sets different attributes for Fortran runtime calls
that enable more optimizations in LLVM backend.
For the time being, the meaning of these attributes is not
strictly defined for HLFIR/FIR.
}];
let dependentDialects = ["fir::FIROpsDialect", "mlir::LLVM::LLVMDialect"];
}

def GenRuntimeCallsForTest
: Pass<"gen-runtime-calls-for-test", "mlir::ModuleOp"> {
let summary =
"Print FIR containing declarations/calls of Fortran runtime functions";
let description = [{
This pass is only for developers to be able to print FIR
that declares and calls Fortran runtime functions.
It helps producing/updating tests for passes that modify
the func/call operations based on some knowledge of
Fortran runtime.
}];
let options =
[Option<"doGenerateCalls", "do-generate-calls", "bool",
/*default=*/"false",
"Generate thin wrapper functions that call Fortran runtime "
"functions. If it is set to false, then only the declarations "
"are generated.">,
];
let dependentDialects = ["fir::FIROpsDialect", "mlir::func::FuncDialect"];
}

#endif // FLANG_OPTIMIZER_TRANSFORMS_PASSES
111 changes: 0 additions & 111 deletions flang/include/flang/Optimizer/Transforms/RuntimeFunctions.inc

This file was deleted.

Loading

0 comments on commit 69cc16f

Please sign in to comment.