Skip to content

Commit

Permalink
[fir] Update fir.alloca op
Browse files Browse the repository at this point in the history
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: flang-compiler#1065

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D110815

Co-authored-by: Valentin Clement <clementval@gmail.com>
  • Loading branch information
kiranchandramohan and clementval committed Sep 30, 2021
1 parent c15bbde commit 4cab4f6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 12 deletions.
34 changes: 24 additions & 10 deletions flang/include/flang/Optimizer/Dialect/FIROps.td
Expand Up @@ -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
);
Expand All @@ -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); }];

Expand Down
40 changes: 38 additions & 2 deletions flang/lib/Optimizer/Dialect/FIROps.cpp
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}
Expand Down

0 comments on commit 4cab4f6

Please sign in to comment.