[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@gmail.com>
This commit is contained in:
Kiran Chandramohan 2021-09-30 17:00:17 +02:00 committed by Valentin Clement
parent c15bbdeaff
commit 4cab4f6b1c
No known key found for this signature in database
GPG key ID: 086D54783C928776
2 changed files with 62 additions and 12 deletions

View file

@ -129,6 +129,7 @@ def fir_AllocaOp : fir_Op<"alloca", [AttrSizedOperandSegments,
TypeAttr:$in_type, TypeAttr:$in_type,
OptionalAttr<StrAttr>:$uniq_name, OptionalAttr<StrAttr>:$uniq_name,
OptionalAttr<StrAttr>:$bindc_name, OptionalAttr<StrAttr>:$bindc_name,
UnitAttr:$pinned,
Variadic<AnyIntegerType>:$typeparams, Variadic<AnyIntegerType>:$typeparams,
Variadic<AnyIntegerType>:$shape Variadic<AnyIntegerType>:$shape
); );
@ -142,16 +143,29 @@ def fir_AllocaOp : fir_Op<"alloca", [AttrSizedOperandSegments,
let builders = [ let builders = [
OpBuilder<(ins "mlir::Type":$inType, "llvm::StringRef":$uniqName, OpBuilder<(ins "mlir::Type":$inType, "llvm::StringRef":$uniqName,
"llvm::StringRef":$bindcName, CArg<"mlir::ValueRange", "{}">:$typeparams, "llvm::StringRef":$bindcName, CArg<"mlir::ValueRange", "{}">:$typeparams,
CArg<"mlir::ValueRange", "{}">:$shape, CArg<"mlir::ValueRange", "{}">:$shape,
CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>, CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>,
OpBuilder<(ins "mlir::Type":$inType, "llvm::StringRef":$uniqName, OpBuilder<(ins "mlir::Type":$inType, "llvm::StringRef":$uniqName,
CArg<"mlir::ValueRange", "{}">:$typeparams, "llvm::StringRef":$bindcName, "bool":$pinned,
CArg<"mlir::ValueRange", "{}">:$shape, CArg<"mlir::ValueRange", "{}">:$typeparams,
CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>, CArg<"mlir::ValueRange", "{}">:$shape,
OpBuilder<(ins "mlir::Type":$in_type, CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>,
CArg<"mlir::ValueRange", "{}">:$typeparams, OpBuilder<(ins "mlir::Type":$inType, "llvm::StringRef":$uniqName,
CArg<"mlir::ValueRange", "{}">:$shape, CArg<"mlir::ValueRange", "{}">:$typeparams,
CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attributes)>]; 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); }]; let verifier = [{ return ::verify(*this); }];

View file

@ -169,7 +169,18 @@ void fir::AllocaOp::build(mlir::OpBuilder &builder,
llvm::ArrayRef<mlir::NamedAttribute> attributes) { llvm::ArrayRef<mlir::NamedAttribute> attributes) {
auto nameAttr = builder.getStringAttr(uniqName); auto nameAttr = builder.getStringAttr(uniqName);
build(builder, result, wrapAllocaResultType(inType), inType, nameAttr, {}, 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); result.addAttributes(attributes);
} }
@ -183,7 +194,22 @@ void fir::AllocaOp::build(mlir::OpBuilder &builder,
auto bindcAttr = auto bindcAttr =
bindcName.empty() ? mlir::StringAttr{} : builder.getStringAttr(bindcName); bindcName.empty() ? mlir::StringAttr{} : builder.getStringAttr(bindcName);
build(builder, result, wrapAllocaResultType(inType), inType, nameAttr, 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); result.addAttributes(attributes);
} }
@ -192,6 +218,16 @@ void fir::AllocaOp::build(mlir::OpBuilder &builder,
mlir::ValueRange typeparams, mlir::ValueRange shape, mlir::ValueRange typeparams, mlir::ValueRange shape,
llvm::ArrayRef<mlir::NamedAttribute> attributes) { llvm::ArrayRef<mlir::NamedAttribute> attributes) {
build(builder, result, wrapAllocaResultType(inType), inType, {}, {}, 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); typeparams, shape);
result.addAttributes(attributes); result.addAttributes(attributes);
} }