Skip to content

Commit a3824c7

Browse files
committed
[AutoBump] Merge with 67efbd0 (Jan 08)
2 parents 51f92bc + 67efbd0 commit a3824c7

35 files changed

+360
-78
lines changed

flang/docs/Extensions.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ end
160160
* `<>` as synonym for `.NE.` and `/=`
161161
* `$` and `@` as legal characters in names
162162
* Initialization in type declaration statements using `/values/`
163-
* Saved variables without explicit or default initializers are zero initialized.
163+
* Saved variables without explicit or default initializers are zero initialized,
164+
except for scalar variables from the main program that are not explicitly
165+
initialized or marked with an explicit SAVE attribute (these variables may be
166+
placed on the stack by flang and not zero initialized). It is not advised to
167+
rely on this extension in new code.
164168
* In a saved entity of a type with a default initializer, components without default
165169
values are zero initialized.
166170
* Kind specification with `*`, e.g. `REAL*4`

flang/lib/Optimizer/Transforms/StackArrays.cpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,18 @@ std::optional<AllocationState> LatticePoint::get(mlir::Value val) const {
330330
return it->second;
331331
}
332332

333+
static mlir::Value lookThroughDeclaresAndConverts(mlir::Value value) {
334+
while (mlir::Operation *op = value.getDefiningOp()) {
335+
if (auto declareOp = llvm::dyn_cast<fir::DeclareOp>(op))
336+
value = declareOp.getMemref();
337+
else if (auto convertOp = llvm::dyn_cast<fir::ConvertOp>(op))
338+
value = convertOp->getOperand(0);
339+
else
340+
return value;
341+
}
342+
return value;
343+
}
344+
333345
mlir::LogicalResult AllocationAnalysis::visitOperation(
334346
mlir::Operation *op, const LatticePoint &before, LatticePoint *after) {
335347
LLVM_DEBUG(llvm::dbgs() << "StackArrays: Visiting operation: " << *op
@@ -363,10 +375,10 @@ mlir::LogicalResult AllocationAnalysis::visitOperation(
363375
mlir::Value operand = op->getOperand(0);
364376

365377
// Note: StackArrays is scheduled in the pass pipeline after lowering hlfir
366-
// to fir. Therefore, we only need to handle `fir::DeclareOp`s.
367-
if (auto declareOp =
368-
llvm::dyn_cast_if_present<fir::DeclareOp>(operand.getDefiningOp()))
369-
operand = declareOp.getMemref();
378+
// to fir. Therefore, we only need to handle `fir::DeclareOp`s. Also look
379+
// past converts in case the pointer was changed between different pointer
380+
// types.
381+
operand = lookThroughDeclaresAndConverts(operand);
370382

371383
std::optional<AllocationState> operandState = before.get(operand);
372384
if (operandState && *operandState == AllocationState::Allocated) {
@@ -535,17 +547,12 @@ AllocMemConversion::matchAndRewrite(fir::AllocMemOp allocmem,
535547

536548
// remove freemem operations
537549
llvm::SmallVector<mlir::Operation *> erases;
538-
for (mlir::Operation *user : allocmem.getOperation()->getUsers()) {
539-
if (auto declareOp = mlir::dyn_cast_if_present<fir::DeclareOp>(user)) {
540-
for (mlir::Operation *user : declareOp->getUsers()) {
541-
if (mlir::isa<fir::FreeMemOp>(user))
542-
erases.push_back(user);
543-
}
544-
}
545-
546-
if (mlir::isa<fir::FreeMemOp>(user))
547-
erases.push_back(user);
548-
}
550+
mlir::Operation *parent = allocmem->getParentOp();
551+
// TODO: this shouldn't need to be re-calculated for every allocmem
552+
parent->walk([&](fir::FreeMemOp freeOp) {
553+
if (lookThroughDeclaresAndConverts(freeOp->getOperand(0)) == allocmem)
554+
erases.push_back(freeOp);
555+
});
549556

550557
// now we are done iterating the users, it is safe to mutate them
551558
for (mlir::Operation *erase : erases)

flang/test/Transforms/stack-arrays.fir

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ func.func @placement_loop_declare() {
379379
%3 = arith.addi %c1, %c2 : index
380380
// operand is now available
381381
%4 = fir.allocmem !fir.array<?xi32>, %3
382-
%5 = fir.declare %4 {uniq_name = "temp"} : (!fir.heap<!fir.array<?xi32>>) -> !fir.heap<!fir.array<?xi32>>
382+
%shape = fir.shape %3 : (index) -> !fir.shape<1>
383+
%5 = fir.declare %4(%shape) {uniq_name = "temp"} : (!fir.heap<!fir.array<?xi32>>, !fir.shape<1>) -> !fir.heap<!fir.array<?xi32>>
383384
// ...
384385
fir.freemem %5 : !fir.heap<!fir.array<?xi32>>
385386
fir.result %3, %c1_i32 : index, i32
@@ -400,3 +401,20 @@ func.func @placement_loop_declare() {
400401
// CHECK-NEXT: }
401402
// CHECK-NEXT: return
402403
// CHECK-NEXT: }
404+
405+
// Can we look through fir.convert and fir.declare?
406+
func.func @lookthrough() {
407+
%0 = fir.allocmem !fir.array<42xi32>
408+
%c42 = arith.constant 42 : index
409+
%shape = fir.shape %c42 : (index) -> !fir.shape<1>
410+
%1 = fir.declare %0(%shape) {uniq_name = "name"} : (!fir.heap<!fir.array<42xi32>>, !fir.shape<1>) -> !fir.heap<!fir.array<42xi32>>
411+
%2 = fir.convert %1 : (!fir.heap<!fir.array<42xi32>>) -> !fir.ref<!fir.array<42xi32>>
412+
// use the ref so the converts aren't folded
413+
%3 = fir.load %2 : !fir.ref<!fir.array<42xi32>>
414+
%4 = fir.convert %2 : (!fir.ref<!fir.array<42xi32>>) -> !fir.heap<!fir.array<42xi32>>
415+
fir.freemem %4 : !fir.heap<!fir.array<42xi32>>
416+
return
417+
}
418+
// CHECK: func.func @lookthrough() {
419+
// CHECK: fir.alloca !fir.array<42xi32>
420+
// CHECK-NOT: fir.freemem

llvm/Maintainers.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ [email protected], [email protected] (email), [arsenm](https://github.co
4545

4646
#### Inlining
4747

48-
Chandler Carruth \
49-
[email protected], [email protected] (email), [chandlerc](https://github.com/chandlerc) (GitHub)
48+
Arthur Eubanks \
49+
[email protected] (email), [aeubanks](https://github.com/aeubanks) (GitHub) \
50+
Mircea Trofin (esp. ML inliner) \
51+
[email protected] (email), [mtrofin](https://github.com/mtrofin) (GitHub) \
52+
Kazu Hirata (esp. module inliner and inline order) \
53+
[email protected] (email), [kazutakahirata](https://github.com/kazutakahirata) (GitHub)
5054

5155
#### InstCombine, InstSimplify, ValueTracking, ConstantFold
5256

@@ -65,6 +69,11 @@ [email protected] (email), [bogner](https://github.com/bogner) (GitHub)
6569
Diego Novillo \
6670
[email protected] (email), [dnovillo](https://github.com/dnovillo) (GitHub)
6771

72+
#### New pass manager, CGSCC, LazyCallGraph
73+
74+
Arthur Eubanks \
75+
[email protected] (email), [aeubanks](https://github.com/aeubanks) (GitHub)
76+
6877
#### LoopStrengthReduce
6978

7079
Quentin Colombet \
@@ -462,7 +471,7 @@ [email protected] (email), [lattner](https://github.com/lattner) (GitHub), clattn
462471

463472
Paul C. Anagnostopoulos ([email protected], [Paul-C-Anagnostopoulos](https://github.com/Paul-C-Anagnostopoulos)) -- TableGen \
464473
Justin Bogner ([email protected], [bogner](https://github.com/bogner)) -- SelectionDAG \
465-
Chandler Carruth ([email protected], [email protected], [chandlerc](https://github.com/chandlerc)) -- ADT, Support \
474+
Chandler Carruth ([email protected], [email protected], [chandlerc](https://github.com/chandlerc)) -- ADT, Support, Inlining \
466475
Peter Collingbourne ([email protected], [pcc](https://github.com/pcc)) -- LTO \
467476
Evan Cheng ([email protected]) -- Parts of code generator not covered by someone else \
468477
Jake Ehrlich ([email protected], [jakehehrlich](https://github.com/jakehehrlich)) -- llvm-objcopy and ObjCopy library \

llvm/include/llvm/ADT/STLFunctionalExtras.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ namespace llvm {
3636
/// a function_ref.
3737
template<typename Fn> class function_ref;
3838

39-
template<typename Ret, typename ...Params>
40-
class function_ref<Ret(Params...)> {
39+
template <typename Ret, typename... Params>
40+
class LLVM_GSL_POINTER function_ref<Ret(Params...)> {
4141
Ret (*callback)(intptr_t callable, Params ...params) = nullptr;
4242
intptr_t callable;
4343

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static cl::opt<unsigned> RangeIterThreshold(
226226

227227
static cl::opt<unsigned> MaxLoopGuardCollectionDepth(
228228
"scalar-evolution-max-loop-guard-collection-depth", cl::Hidden,
229-
cl::desc("Maximum depth for recrusive loop guard collection"), cl::init(1));
229+
cl::desc("Maximum depth for recursive loop guard collection"), cl::init(1));
230230

231231
static cl::opt<bool>
232232
ClassifyExpressions("scalar-evolution-classify-expressions",

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static cl::opt<bool>
152152

153153
static cl::opt<bool>
154154
EnableAndCmpSinking("enable-andcmp-sinking", cl::Hidden, cl::init(true),
155-
cl::desc("Enable sinkinig and/cmp into branches."));
155+
cl::desc("Enable sinking and/cmp into branches."));
156156

157157
static cl::opt<bool> DisableStoreExtract(
158158
"disable-cgp-store-extract", cl::Hidden, cl::init(false),

llvm/lib/CodeGen/MIRSampleProfile.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ static cl::opt<bool> ShowFSBranchProb(
4646
cl::desc("Print setting flow sensitive branch probabilities"));
4747
static cl::opt<unsigned> FSProfileDebugProbDiffThreshold(
4848
"fs-profile-debug-prob-diff-threshold", cl::init(10),
49-
cl::desc("Only show debug message if the branch probility is greater than "
50-
"this value (in percentage)."));
49+
cl::desc(
50+
"Only show debug message if the branch probability is greater than "
51+
"this value (in percentage)."));
5152

5253
static cl::opt<unsigned> FSProfileDebugBWThreshold(
5354
"fs-profile-debug-bw-threshold", cl::init(10000),

llvm/lib/CodeGen/MachineBlockPlacement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static cl::opt<unsigned> JumpInstCost("jump-inst-cost",
149149
static cl::opt<bool>
150150
TailDupPlacement("tail-dup-placement",
151151
cl::desc("Perform tail duplication during placement. "
152-
"Creates more fallthrough opportunites in "
152+
"Creates more fallthrough opportunities in "
153153
"outline branches."),
154154
cl::init(true), cl::Hidden);
155155

llvm/lib/CodeGen/MachineBranchProbabilityInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace llvm {
2929
cl::opt<unsigned>
3030
StaticLikelyProb("static-likely-prob",
3131
cl::desc("branch probability threshold in percentage"
32-
"to be considered very likely"),
32+
" to be considered very likely"),
3333
cl::init(80), cl::Hidden);
3434

3535
cl::opt<unsigned> ProfileLikelyProb(

0 commit comments

Comments
 (0)