[flang-commits] [flang] 4cab4f6 - [fir] Update fir.alloca op
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Thu Sep 30 08:02:43 PDT 2021
Author: Kiran Chandramohan
Date: 2021-09-30T17:02:32+02:00
New Revision: 4cab4f6b1c089fe51d50b4b4d931976db64fecce
URL: https://github.com/llvm/llvm-project/commit/4cab4f6b1c089fe51d50b4b4d931976db64fecce
DIFF: https://github.com/llvm/llvm-project/commit/4cab4f6b1c089fe51d50b4b4d931976db64fecce.diff
LOG: [fir] Update fir.alloca op
Add pinned attributes and speicifc builders.
The pinned attribute helps mark those allocas in OpenMP regions that should not
be hoisted out by an alloca hoisting pass.
This patch is part of the upstreaming effort from fir-dev branch.
Coming from PR: https://github.com/flang-compiler/f18-llvm-project/pull/1065
Reviewed By: kiranchandramohan
Differential Revision: https://reviews.llvm.org/D110815
Co-authored-by: Valentin Clement <clementval at gmail.com>
Added:
Modified:
flang/include/flang/Optimizer/Dialect/FIROps.td
flang/lib/Optimizer/Dialect/FIROps.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td
index 0e6cd354c7e7..217f1490047e 100644
--- a/flang/include/flang/Optimizer/Dialect/FIROps.td
+++ b/flang/include/flang/Optimizer/Dialect/FIROps.td
@@ -129,6 +129,7 @@ def fir_AllocaOp : fir_Op<"alloca", [AttrSizedOperandSegments,
TypeAttr:$in_type,
OptionalAttr<StrAttr>:$uniq_name,
OptionalAttr<StrAttr>:$bindc_name,
+ UnitAttr:$pinned,
Variadic<AnyIntegerType>:$typeparams,
Variadic<AnyIntegerType>:$shape
);
@@ -142,16 +143,29 @@ def fir_AllocaOp : fir_Op<"alloca", [AttrSizedOperandSegments,
let builders = [
OpBuilder<(ins "mlir::Type":$inType, "llvm::StringRef":$uniqName,
"llvm::StringRef":$bindcName, CArg<"mlir::ValueRange", "{}">:$typeparams,
- CArg<"mlir::ValueRange", "{}">:$shape,
- CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>,
- OpBuilder<(ins "mlir::Type":$inType, "llvm::StringRef":$uniqName,
- CArg<"mlir::ValueRange", "{}">:$typeparams,
- CArg<"mlir::ValueRange", "{}">:$shape,
- CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>,
- OpBuilder<(ins "mlir::Type":$in_type,
- CArg<"mlir::ValueRange", "{}">:$typeparams,
- CArg<"mlir::ValueRange", "{}">:$shape,
- CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>];
+ CArg<"mlir::ValueRange", "{}">:$shape,
+ CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>,
+ OpBuilder<(ins "mlir::Type":$inType, "llvm::StringRef":$uniqName,
+ "llvm::StringRef":$bindcName, "bool":$pinned,
+ CArg<"mlir::ValueRange", "{}">:$typeparams,
+ CArg<"mlir::ValueRange", "{}">:$shape,
+ CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>,
+ OpBuilder<(ins "mlir::Type":$inType, "llvm::StringRef":$uniqName,
+ CArg<"mlir::ValueRange", "{}">:$typeparams,
+ CArg<"mlir::ValueRange", "{}">:$shape,
+ CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>,
+ OpBuilder<(ins "mlir::Type":$inType, "llvm::StringRef":$uniqName,
+ "bool":$pinned, CArg<"mlir::ValueRange", "{}">:$typeparams,
+ CArg<"mlir::ValueRange", "{}">:$shape,
+ CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>,
+ OpBuilder<(ins "mlir::Type":$inType, "bool":$pinned,
+ CArg<"mlir::ValueRange", "{}">:$typeparams,
+ CArg<"mlir::ValueRange", "{}">:$shape,
+ CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>,
+ OpBuilder<(ins "mlir::Type":$inType,
+ CArg<"mlir::ValueRange", "{}">:$typeparams,
+ CArg<"mlir::ValueRange", "{}">:$shape,
+ CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>];
let verifier = [{ return ::verify(*this); }];
diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index 974765a293d7..197f336d1bc4 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -169,7 +169,18 @@ void fir::AllocaOp::build(mlir::OpBuilder &builder,
llvm::ArrayRef<mlir::NamedAttribute> attributes) {
auto nameAttr = builder.getStringAttr(uniqName);
build(builder, result, wrapAllocaResultType(inType), inType, nameAttr, {},
- typeparams, shape);
+ /*pinned=*/false, typeparams, shape);
+ result.addAttributes(attributes);
+}
+
+void fir::AllocaOp::build(mlir::OpBuilder &builder,
+ mlir::OperationState &result, mlir::Type inType,
+ llvm::StringRef uniqName, bool pinned,
+ mlir::ValueRange typeparams, mlir::ValueRange shape,
+ llvm::ArrayRef<mlir::NamedAttribute> attributes) {
+ auto nameAttr = builder.getStringAttr(uniqName);
+ build(builder, result, wrapAllocaResultType(inType), inType, nameAttr, {},
+ pinned, typeparams, shape);
result.addAttributes(attributes);
}
@@ -183,7 +194,22 @@ void fir::AllocaOp::build(mlir::OpBuilder &builder,
auto bindcAttr =
bindcName.empty() ? mlir::StringAttr{} : builder.getStringAttr(bindcName);
build(builder, result, wrapAllocaResultType(inType), inType, nameAttr,
- bindcAttr, typeparams, shape);
+ bindcAttr, /*pinned=*/false, typeparams, shape);
+ result.addAttributes(attributes);
+}
+
+void fir::AllocaOp::build(mlir::OpBuilder &builder,
+ mlir::OperationState &result, mlir::Type inType,
+ llvm::StringRef uniqName, llvm::StringRef bindcName,
+ bool pinned, mlir::ValueRange typeparams,
+ mlir::ValueRange shape,
+ llvm::ArrayRef<mlir::NamedAttribute> attributes) {
+ auto nameAttr =
+ uniqName.empty() ? mlir::StringAttr{} : builder.getStringAttr(uniqName);
+ auto bindcAttr =
+ bindcName.empty() ? mlir::StringAttr{} : builder.getStringAttr(bindcName);
+ build(builder, result, wrapAllocaResultType(inType), inType, nameAttr,
+ bindcAttr, pinned, typeparams, shape);
result.addAttributes(attributes);
}
@@ -192,6 +218,16 @@ void fir::AllocaOp::build(mlir::OpBuilder &builder,
mlir::ValueRange typeparams, mlir::ValueRange shape,
llvm::ArrayRef<mlir::NamedAttribute> attributes) {
build(builder, result, wrapAllocaResultType(inType), inType, {}, {},
+ /*pinned=*/false, typeparams, shape);
+ result.addAttributes(attributes);
+}
+
+void fir::AllocaOp::build(mlir::OpBuilder &builder,
+ mlir::OperationState &result, mlir::Type inType,
+ bool pinned, mlir::ValueRange typeparams,
+ mlir::ValueRange shape,
+ llvm::ArrayRef<mlir::NamedAttribute> attributes) {
+ build(builder, result, wrapAllocaResultType(inType), inType, {}, {}, pinned,
typeparams, shape);
result.addAttributes(attributes);
}
More information about the flang-commits
mailing list