[flang-commits] [flang] [Flang] Extracting internal constants from scalar literals (PR #73829)
via flang-commits
flang-commits at lists.llvm.org
Wed Dec 13 04:11:44 PST 2023
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 0ccef6a723cbfe3d72b85d34963badb37a6a9a53 f936dde64196dcd0004238525a12fd84b1b3838f -- flang/lib/Optimizer/Transforms/ConstExtruder.cpp flang/include/flang/Optimizer/Transforms/Passes.h flang/include/flang/Tools/CLOptions.inc
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/flang/lib/Optimizer/Transforms/ConstExtruder.cpp b/flang/lib/Optimizer/Transforms/ConstExtruder.cpp
index 355166f342..796a6a05a5 100644
--- a/flang/lib/Optimizer/Transforms/ConstExtruder.cpp
+++ b/flang/lib/Optimizer/Transforms/ConstExtruder.cpp
@@ -47,8 +47,7 @@ public:
llvm::SmallVector<mlir::Value> newOperands;
llvm::SmallVector<mlir::Operation *> toErase;
for (const mlir::Value &a : callOp.getArgs()) {
- auto alloca =
- mlir::dyn_cast_or_null<fir::AllocaOp>(a.getDefiningOp());
+ auto alloca = mlir::dyn_cast_or_null<fir::AllocaOp>(a.getDefiningOp());
// We can convert arguments that are alloca, and that has
// the value by reference attribute. All else is just added
// to the argument list.
@@ -56,17 +55,17 @@ public:
newOperands.push_back(a);
continue;
}
-
+
mlir::Type varTy = alloca.getInType();
assert(!fir::hasDynamicSize(varTy) &&
- "only expect statically sized scalars to be by value");
+ "only expect statically sized scalars to be by value");
// Find immediate store with const argument
mlir::Operation *store = nullptr;
for (mlir::Operation *s : alloca->getUsers()) {
if (mlir::isa<fir::StoreOp>(s) && di.dominates(s, callOp)) {
// We can only deal with ONE store - if already found one,
- // set to nullptr and exit the loop.
+ // set to nullptr and exit the loop.
if (store) {
store = nullptr;
break;
@@ -74,13 +73,13 @@ public:
store = s;
}
}
-
+
// If we didn't find one signle store, add argument as is, and move on.
if (!store) {
newOperands.push_back(a);
continue;
}
-
+
LLVM_DEBUG(llvm::dbgs() << " found store " << *store << "\n");
mlir::Operation *constant_def = store->getOperand(0).getDefiningOp();
@@ -95,8 +94,9 @@ public:
LLVM_DEBUG(llvm::dbgs() << " found define " << *constant_def << "\n");
std::string globalName = "_extruded_." + std::to_string(uniqueLitId++);
- assert(!builder.getNamedGlobal(globalName) && "We should have a unique name here");
-
+ assert(!builder.getNamedGlobal(globalName) &&
+ "We should have a unique name here");
+
unsigned count = 0;
for (mlir::Operation *s : alloca->getUsers())
if (di.dominates(store, s))
@@ -106,19 +106,20 @@ public:
// be callOp)
if (count == 2)
toErase.push_back(store);
-
+
auto loc = callOp.getLoc();
fir::GlobalOp global = builder.createGlobalConstant(
loc, varTy, globalName,
[&](fir::FirOpBuilder &builder) {
mlir::Operation *cln = constant_def->clone();
builder.insert(cln);
- mlir::Value val = builder.createConvert(loc, varTy, cln->getResult(0));
+ mlir::Value val =
+ builder.createConvert(loc, varTy, cln->getResult(0));
builder.create<fir::HasValueOp>(loc, val);
},
builder.createInternalLinkage());
mlir::Value addr = {builder.create<fir::AddrOfOp>(
- loc, global.resultType(), global.getSymbol())};
+ loc, global.resultType(), global.getSymbol())};
newOperands.push_back(addr);
needUpdate = true;
}
@@ -131,14 +132,14 @@ public:
fir::CallOp newOp = builder.create<fir::CallOp>(
loc, newResultTypes,
callOp.getCallee().has_value() ? callOp.getCallee().value()
- : mlir::SymbolRefAttr{},
+ : mlir::SymbolRefAttr{},
newOperands, callOp.getFastmathAttr());
rewriter.replaceOp(callOp, newOp);
for (auto e : toErase)
rewriter.eraseOp(e);
LLVM_DEBUG(llvm::dbgs() << "extruded constant for " << callOp << " as "
- << newOp << '\n');
+ << newOp << '\n');
return mlir::success();
}
@@ -161,7 +162,7 @@ public:
mod.walk([di, this](mlir::func::FuncOp func) { runOnFunc(func, di); });
}
- void runOnFunc(mlir::func::FuncOp &func, const mlir::DominanceInfo* di) {
+ void runOnFunc(mlir::func::FuncOp &func, const mlir::DominanceInfo *di) {
// If func is a declaration, skip it.
if (func.empty())
return;
``````````
</details>
https://github.com/llvm/llvm-project/pull/73829
More information about the flang-commits
mailing list