];
}
+def hlfir_NullOp : hlfir_Op<"null", [NoMemoryEffect, fir_FortranVariableOpInterface]> {
+ let summary = "create a NULL() address";
+
+ let description = [{
+ Create a NULL() address.
+ So far is not intended to represent NULL(MOLD).
+ }];
+
+ let results = (outs AnyFortranVariable);
+ let builders = [OpBuilder<(ins)>];
+
+ let assemblyFormat = "type(results) attr-dict";
+ let extraClassDeclaration = [{
+ // Implement FortranVariableInterface interface.
+ std::optional<fir::FortranVariableFlagsEnum> getFortranAttrs() const {
+ return std::nullopt;
+ }
+ mlir::Value getShape() const {return mlir::Value{};}
+ mlir::OperandRange getExplicitTypeParams() const {
+ // Return an empty range.
+ return {(*this)->getOperands().begin(), (*this)->getOperands().begin()};
+ }
+ }];
+}
+
#endif // FORTRAN_DIALECT_HLFIR_OPS
build(builder, odsState, resultType, expr, indices, typeparams);
}
+//===----------------------------------------------------------------------===//
+// NullOp
+//===----------------------------------------------------------------------===//
+
+void hlfir::NullOp::build(mlir::OpBuilder &builder,
+ mlir::OperationState &odsState) {
+ return build(builder, odsState,
+ fir::ReferenceType::get(builder.getNoneType()));
+}
+
#define GET_OP_CLASSES
#include "flang/Optimizer/HLFIR/HLFIROps.cpp.inc"
}
};
+class NullOpConversion : public mlir::OpRewritePattern<hlfir::NullOp> {
+public:
+ explicit NullOpConversion(mlir::MLIRContext *ctx) : OpRewritePattern{ctx} {}
+
+ mlir::LogicalResult
+ matchAndRewrite(hlfir::NullOp nullop,
+ mlir::PatternRewriter &rewriter) const override {
+ rewriter.replaceOpWithNewOp<fir::ZeroOp>(nullop, nullop.getType());
+ return mlir::success();
+ }
+};
+
class ConvertHLFIRtoFIR
: public hlfir::impl::ConvertHLFIRtoFIRBase<ConvertHLFIRtoFIR> {
public:
auto module = this->getOperation();
auto *context = &getContext();
mlir::RewritePatternSet patterns(context);
- patterns.insert<AssignOpConversion, DeclareOpConversion,
- DesignateOpConversion, NoReassocOpConversion>(context);
+ patterns
+ .insert<AssignOpConversion, DeclareOpConversion, DesignateOpConversion,
+ NoReassocOpConversion, NullOpConversion>(context);
mlir::ConversionTarget target(*context);
target.addIllegalDialect<hlfir::hlfirDialect>();
target.markUnknownOpDynamicallyLegal(
--- /dev/null
+// Test hlfir.null code generation to FIR
+
+// RUN: fir-opt %s -convert-hlfir-to-fir | FileCheck %s
+
+func.func @test() {
+ // CHECK: fir.zero_bits !fir.ref<none>
+ %0 = hlfir.null !fir.ref<none>
+ return
+}
--- /dev/null
+// Test hlfir.null operation parse, verify (no errors), and unparse.
+
+// RUN: fir-opt %s | fir-opt | FileCheck %s
+
+func.func @test() {
+ // CHECK: hlfir.null !fir.ref<none>
+ %0 = hlfir.null !fir.ref<none>
+ return
+}