[flang] add hlfir.no_reassoc definition

Same as fir.no_reassoc but accepts hlfir.expr type. It is needed because
FIR operation can only produce FIR types, and I do not want to change
that for now.

Depends on D139519

Differential Revision: https://reviews.llvm.org/D139520
This commit is contained in:
Jean Perier 2022-12-07 14:44:29 +01:00
parent cf73faef9b
commit 80e5ff775f
3 changed files with 41 additions and 0 deletions

View File

@ -13,6 +13,7 @@
#include "flang/Optimizer/Dialect/FIRType.h"
#include "flang/Optimizer/Dialect/FortranVariableInterface.h"
#include "flang/Optimizer/HLFIR/HLFIRDialect.h"
#include "mlir/Interfaces/InferTypeOpInterface.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
#define GET_OP_CLASSES

View File

@ -318,5 +318,18 @@ def hlfir_AsExprOp : hlfir_Op<"as_expr", []> {
let builders = [OpBuilder<(ins "mlir::Value":$var)>];
}
def hlfir_NoReassocOp : hlfir_Op<"no_reassoc", [NoMemoryEffect, SameOperandsAndResultType]> {
let summary = "synthetic op to prevent reassociation";
let description = [{
Same as fir.reassoc, except it accepts hlfir.expr arguments.
}];
let arguments = (ins AnyFortranEntity:$val);
let results = (outs AnyFortranEntity);
let assemblyFormat = "$val attr-dict `:` type($val)";
}
#endif // FORTRAN_DIALECT_HLFIR_OPS

View File

@ -0,0 +1,27 @@
// Test hlfir.no_reassoc operation parse, verify (no errors), and unparse.
// RUN: fir-opt %s | fir-opt | FileCheck %s
func.func @no_reassoc_value(%arg0: i32) {
%0 = hlfir.no_reassoc %arg0 : i32
return
}
// CHECK-LABEL: func.func @no_reassoc_value(
// CHECK-SAME: %[[VAL_0:.*]]: i32) {
// CHECK: hlfir.no_reassoc %[[VAL_0]] : i32
func.func @no_reassoc_var(%arg0: !fir.ref<i32>) {
%0 = hlfir.no_reassoc %arg0 : !fir.ref<i32>
return
}
// CHECK-LABEL: func.func @no_reassoc_var(
// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32>) {
// CHECK: hlfir.no_reassoc %[[VAL_0]] : !fir.ref<i32>
func.func @no_reassoc_expr(%arg0: !hlfir.expr<10xi32>) {
%0 = hlfir.no_reassoc %arg0 : !hlfir.expr<10xi32>
return
}
// CHECK-LABEL: func.func @no_reassoc_expr(
// CHECK-SAME: %[[VAL_0:.*]]: !hlfir.expr<10xi32>) {
// CHECK: hlfir.no_reassoc %[[VAL_0]] : !hlfir.expr<10xi32>