Skip to content

Commit 1693601

Browse files
authored
Sync Reduction builder after upstreaming (#1292)
1 parent 388eb4d commit 1693601

File tree

5 files changed

+390
-49
lines changed

5 files changed

+390
-49
lines changed

flang/include/flang/Optimizer/Builder/Runtime/Reduction.h

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8+
//
9+
// The runtime routines generated in this file are generally storing the result
10+
// in a descriptor (represented as a `box` in FIR). Some function might
11+
// have a specialization where the value is returned as a scalar value, e.g.
12+
// `genAll` is a specialization of `genAllDescriptor`.
13+
//
14+
//===----------------------------------------------------------------------===//
815

916
#ifndef FORTRAN_OPTIMIZER_BUILDER_RUNTIME_REDUCTION_H
1017
#define FORTRAN_OPTIMIZER_BUILDER_RUNTIME_REDUCTION_H
@@ -18,126 +25,128 @@ class FirOpBuilder;
1825

1926
namespace fir::runtime {
2027

21-
/// Generate call to all runtime routine.
22-
/// This calls the descriptor based runtime call implementation of the all
28+
/// Generate call to `AllDim` runtime routine.
29+
/// This calls the descriptor based runtime call implementation of the `all`
2330
/// intrinsic.
2431
void genAllDescriptor(fir::FirOpBuilder &builder, mlir::Location loc,
2532
mlir::Value resultBox, mlir::Value maskBox,
2633
mlir::Value dim);
2734

28-
/// Generate call to any runtime routine.
29-
/// This calls the descriptor based runtime call implementation of the any
35+
/// Generate call to `AnyDim` runtime routine.
36+
/// This calls the descriptor based runtime call implementation of the `any`
3037
/// intrinsic.
3138
void genAnyDescriptor(fir::FirOpBuilder &builder, mlir::Location loc,
3239
mlir::Value resultBox, mlir::Value maskBox,
3340
mlir::Value dim);
3441

35-
/// Generate call to all runtime routine. This version of all is specialized
42+
/// Generate call to `All` runtime routine. This version of `all` is specialized
3643
/// for rank 1 mask arguments.
3744
/// This calls the version that returns a scalar logical value.
3845
mlir::Value genAll(fir::FirOpBuilder &builder, mlir::Location loc,
3946
mlir::Value maskBox, mlir::Value dim);
4047

41-
/// Generate call to any runtime routine. This version of any is specialized
48+
/// Generate call to `Any` runtime routine. This version of `any` is specialized
4249
/// for rank 1 mask arguments.
4350
/// This calls the version that returns a scalar logical value.
4451
mlir::Value genAny(fir::FirOpBuilder &builder, mlir::Location loc,
4552
mlir::Value maskBox, mlir::Value dim);
4653

47-
/// Generate call to Count runtime routine. This routine is a specialized
54+
/// Generate call to `Count` runtime routine. This routine is a specialized
4855
/// version when mask is a rank one array or the dim argument is not
4956
/// specified by the user.
5057
mlir::Value genCount(fir::FirOpBuilder &builder, mlir::Location loc,
5158
mlir::Value maskBox, mlir::Value dim);
5259

53-
/// Generate call to general CountDim runtime routine. This routine has a
60+
/// Generate call to general `CountDim` runtime routine. This routine has a
5461
/// descriptor result.
5562
void genCountDim(fir::FirOpBuilder &builder, mlir::Location loc,
5663
mlir::Value resultBox, mlir::Value maskBox, mlir::Value dim,
5764
mlir::Value kind);
5865

59-
/// Generate call to DotProduct intrinsic runtime routine.
66+
/// Generate call to `DotProduct` intrinsic runtime routine.
6067
mlir::Value genDotProduct(fir::FirOpBuilder &builder, mlir::Location loc,
6168
mlir::Value vectorABox, mlir::Value vectorBBox,
6269
mlir::Value resultBox);
6370

64-
/// Generate call to Maxloc intrinsic runtime routine. This is the version
71+
/// Generate call to `Maxloc` intrinsic runtime routine. This is the version
6572
/// that does not take a dim argument.
6673
void genMaxloc(fir::FirOpBuilder &builder, mlir::Location loc,
6774
mlir::Value resultBox, mlir::Value arrayBox, mlir::Value maskBox,
6875
mlir::Value kind, mlir::Value back);
6976

70-
/// Generate call to Maxloc intrinsic runtime routine. This is the version
77+
/// Generate call to `MaxlocDim` intrinsic runtime routine. This is the version
7178
/// that takes a dim argument.
7279
void genMaxlocDim(fir::FirOpBuilder &builder, mlir::Location loc,
7380
mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim,
7481
mlir::Value maskBox, mlir::Value kind, mlir::Value back);
7582

76-
/// Generate call to Minloc intrinsic runtime routine. This is the version
83+
/// Generate call to `Minloc` intrinsic runtime routine. This is the version
7784
/// that does not take a dim argument.
7885
void genMinloc(fir::FirOpBuilder &builder, mlir::Location loc,
7986
mlir::Value resultBox, mlir::Value arrayBox, mlir::Value maskBox,
8087
mlir::Value kind, mlir::Value back);
8188

82-
/// Generate call to Minloc intrinsic runtime routine. This is the version
89+
/// Generate call to `MinlocDim` intrinsic runtime routine. This is the version
8390
/// that takes a dim argument.
8491
void genMinlocDim(fir::FirOpBuilder &builder, mlir::Location loc,
8592
mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim,
8693
mlir::Value maskBox, mlir::Value kind, mlir::Value back);
8794

88-
/// Generate call to Maxval intrinsic runtime routine. This is the version
95+
/// Generate call to `Maxval` intrinsic runtime routine. This is the version
8996
/// that does not take a dim argument.
9097
mlir::Value genMaxval(fir::FirOpBuilder &builder, mlir::Location loc,
9198
mlir::Value arrayBox, mlir::Value maskBox);
9299

93-
/// Generate call to Maxval intrinsic runtime routine. This is the version
94-
/// that that handles 1 dimensional character arrays with no DIM argument.
100+
/// Generate call to `MaxvalCharacter` intrinsic runtime routine. This is the
101+
/// version hat that handles 1 dimensional character arrays with no DIM
102+
/// argument.
95103
void genMaxvalChar(fir::FirOpBuilder &builder, mlir::Location loc,
96104
mlir::Value resultBox, mlir::Value arrayBox,
97105
mlir::Value maskBox);
98106

99-
/// Generate call to Maxval intrinsic runtime routine. This is the version
107+
/// Generate call to `MaxvalDim` intrinsic runtime routine. This is the version
100108
/// that takes arrays of any rank with a dim argument specified.
101109
void genMaxvalDim(fir::FirOpBuilder &builder, mlir::Location loc,
102110
mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim,
103111
mlir::Value maskBox);
104112

105-
/// Generate call to Minval intrinsic runtime routine. This is the version
113+
/// Generate call to `Minval` intrinsic runtime routine. This is the version
106114
/// that does not take a dim argument.
107115
mlir::Value genMinval(fir::FirOpBuilder &builder, mlir::Location loc,
108116
mlir::Value arrayBox, mlir::Value maskBox);
109117

110-
/// Generate call to Minval intrinsic runtime routine. This is the version
111-
/// that that handles 1 dimensional character arrays with no DIM argument.
118+
/// Generate call to `MinvalCharacter` intrinsic runtime routine. This is the
119+
/// version that that handles 1 dimensional character arrays with no DIM
120+
/// argument.
112121
void genMinvalChar(fir::FirOpBuilder &builder, mlir::Location loc,
113122
mlir::Value resultBox, mlir::Value arrayBox,
114123
mlir::Value maskBox);
115124

116-
/// Generate call to Minval intrinsic runtime routine. This is the version
125+
/// Generate call to `MinvalDim` intrinsic runtime routine. This is the version
117126
/// that takes arrays of any rank with a dim argument specified.
118127
void genMinvalDim(fir::FirOpBuilder &builder, mlir::Location loc,
119128
mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim,
120129
mlir::Value maskBox);
121130

122-
/// Generate call to Product intrinsic runtime routine. This is the version
131+
/// Generate call to `Product` intrinsic runtime routine. This is the version
123132
/// that does not take a dim argument.
124133
mlir::Value genProduct(fir::FirOpBuilder &builder, mlir::Location loc,
125134
mlir::Value arrayBox, mlir::Value maskBox,
126135
mlir::Value resultBox);
127136

128-
/// Generate call to Product intrinsic runtime routine. This is the version
137+
/// Generate call to `ProductDim` intrinsic runtime routine. This is the version
129138
/// that takes arrays of any rank with a dim argument specified.
130139
void genProductDim(fir::FirOpBuilder &builder, mlir::Location loc,
131140
mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim,
132141
mlir::Value maskBox);
133142

134-
/// Generate call to Sum intrinsic runtime routine. This is the version
143+
/// Generate call to `Sum` intrinsic runtime routine. This is the version
135144
/// that does not take a dim argument.
136145
mlir::Value genSum(fir::FirOpBuilder &builder, mlir::Location loc,
137146
mlir::Value arrayBox, mlir::Value maskBox,
138147
mlir::Value resultBox);
139148

140-
/// Generate call to Sum intrinsic runtime routine. This is the version
149+
/// Generate call to `SumDim` intrinsic runtime routine. This is the version
141150
/// that takes arrays of any rank with a dim argument specified.
142151
void genSumDim(fir::FirOpBuilder &builder, mlir::Location loc,
143152
mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim,

flang/lib/Optimizer/Builder/Runtime/Reduction.cpp

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,8 @@ genReduction5Args(FN func, fir::FirOpBuilder &builder, mlir::Location loc,
451451
builder.create<fir::CallOp>(loc, func, args);
452452
}
453453

454-
/// Generate call to all runtime routine.
455-
/// This calls the descriptor based runtime call implementation of the all
454+
/// Generate call to `AllDim` runtime routine.
455+
/// This calls the descriptor based runtime call implementation of the `all`
456456
/// intrinsic.
457457
void fir::runtime::genAllDescriptor(fir::FirOpBuilder &builder,
458458
mlir::Location loc, mlir::Value resultBox,
@@ -461,8 +461,8 @@ void fir::runtime::genAllDescriptor(fir::FirOpBuilder &builder,
461461
genReduction2Args(allFunc, builder, loc, resultBox, maskBox, dim);
462462
}
463463

464-
/// Generate call to any runtime routine.
465-
/// This calls the descriptor based runtime call implementation of the any
464+
/// Generate call to `AnyDim` runtime routine.
465+
/// This calls the descriptor based runtime call implementation of the `any`
466466
/// intrinsic.
467467
void fir::runtime::genAnyDescriptor(fir::FirOpBuilder &builder,
468468
mlir::Location loc, mlir::Value resultBox,
@@ -471,23 +471,23 @@ void fir::runtime::genAnyDescriptor(fir::FirOpBuilder &builder,
471471
genReduction2Args(anyFunc, builder, loc, resultBox, maskBox, dim);
472472
}
473473

474-
/// Generate call to All intrinsic runtime routine. This routine is
474+
/// Generate call to `All` intrinsic runtime routine. This routine is
475475
/// specialized for mask arguments with rank == 1.
476476
mlir::Value fir::runtime::genAll(fir::FirOpBuilder &builder, mlir::Location loc,
477477
mlir::Value maskBox, mlir::Value dim) {
478478
auto allFunc = fir::runtime::getRuntimeFunc<mkRTKey(All)>(loc, builder);
479479
return genSpecial2Args(allFunc, builder, loc, maskBox, dim);
480480
}
481481

482-
/// Generate call to Any intrinsic runtime routine. This routine is
482+
/// Generate call to `Any` intrinsic runtime routine. This routine is
483483
/// specialized for mask arguments with rank == 1.
484484
mlir::Value fir::runtime::genAny(fir::FirOpBuilder &builder, mlir::Location loc,
485485
mlir::Value maskBox, mlir::Value dim) {
486486
auto anyFunc = fir::runtime::getRuntimeFunc<mkRTKey(Any)>(loc, builder);
487487
return genSpecial2Args(anyFunc, builder, loc, maskBox, dim);
488488
}
489489

490-
/// Generate call to Count runtime routine. This routine is a specialized
490+
/// Generate call to `Count` runtime routine. This routine is a specialized
491491
/// version when mask is a rank one array or the dim argument is not
492492
/// specified by the user.
493493
mlir::Value fir::runtime::genCount(fir::FirOpBuilder &builder,
@@ -497,7 +497,7 @@ mlir::Value fir::runtime::genCount(fir::FirOpBuilder &builder,
497497
return genSpecial2Args(countFunc, builder, loc, maskBox, dim);
498498
}
499499

500-
/// Generate call to general CountDim runtime routine. This routine has a
500+
/// Generate call to general `CountDim` runtime routine. This routine has a
501501
/// descriptor result.
502502
void fir::runtime::genCountDim(fir::FirOpBuilder &builder, mlir::Location loc,
503503
mlir::Value resultBox, mlir::Value maskBox,
@@ -512,7 +512,7 @@ void fir::runtime::genCountDim(fir::FirOpBuilder &builder, mlir::Location loc,
512512
builder.create<fir::CallOp>(loc, func, args);
513513
}
514514

515-
/// Generate call to Maxloc intrinsic runtime routine. This is the version
515+
/// Generate call to `Maxloc` intrinsic runtime routine. This is the version
516516
/// that does not take a dim argument.
517517
void fir::runtime::genMaxloc(fir::FirOpBuilder &builder, mlir::Location loc,
518518
mlir::Value resultBox, mlir::Value arrayBox,
@@ -523,7 +523,7 @@ void fir::runtime::genMaxloc(fir::FirOpBuilder &builder, mlir::Location loc,
523523
back);
524524
}
525525

526-
/// Generate call to Maxloc intrinsic runtime routine. This is the version
526+
/// Generate call to `MaxlocDim` intrinsic runtime routine. This is the version
527527
/// that takes a dim argument.
528528
void fir::runtime::genMaxlocDim(fir::FirOpBuilder &builder, mlir::Location loc,
529529
mlir::Value resultBox, mlir::Value arrayBox,
@@ -534,7 +534,7 @@ void fir::runtime::genMaxlocDim(fir::FirOpBuilder &builder, mlir::Location loc,
534534
back);
535535
}
536536

537-
/// Generate call to Maxval intrinsic runtime routine. This is the version
537+
/// Generate call to `Maxval` intrinsic runtime routine. This is the version
538538
/// that does not take a dim argument.
539539
mlir::Value fir::runtime::genMaxval(fir::FirOpBuilder &builder,
540540
mlir::Location loc, mlir::Value arrayBox,
@@ -581,7 +581,7 @@ mlir::Value fir::runtime::genMaxval(fir::FirOpBuilder &builder,
581581
return builder.create<fir::CallOp>(loc, func, args).getResult(0);
582582
}
583583

584-
/// Generate call to Maxval intrinsic runtime routine. This is the version
584+
/// Generate call to `MaxvalDim` intrinsic runtime routine. This is the version
585585
/// that handles any rank array with the dim argument specified.
586586
void fir::runtime::genMaxvalDim(fir::FirOpBuilder &builder, mlir::Location loc,
587587
mlir::Value resultBox, mlir::Value arrayBox,
@@ -590,8 +590,8 @@ void fir::runtime::genMaxvalDim(fir::FirOpBuilder &builder, mlir::Location loc,
590590
genReduction3Args(func, builder, loc, resultBox, arrayBox, dim, maskBox);
591591
}
592592

593-
/// Generate call to Maxval intrinsic runtime routine. This is the version
594-
/// that handles character arrays of rank 1 and without a DIM argument.
593+
/// Generate call to `MaxvalCharacter` intrinsic runtime routine. This is the
594+
/// version that handles character arrays of rank 1 and without a DIM argument.
595595
void fir::runtime::genMaxvalChar(fir::FirOpBuilder &builder, mlir::Location loc,
596596
mlir::Value resultBox, mlir::Value arrayBox,
597597
mlir::Value maskBox) {
@@ -606,7 +606,7 @@ void fir::runtime::genMaxvalChar(fir::FirOpBuilder &builder, mlir::Location loc,
606606
builder.create<fir::CallOp>(loc, func, args);
607607
}
608608

609-
/// Generate call to Minloc intrinsic runtime routine. This is the version
609+
/// Generate call to `Minloc` intrinsic runtime routine. This is the version
610610
/// that does not take a dim argument.
611611
void fir::runtime::genMinloc(fir::FirOpBuilder &builder, mlir::Location loc,
612612
mlir::Value resultBox, mlir::Value arrayBox,
@@ -617,7 +617,7 @@ void fir::runtime::genMinloc(fir::FirOpBuilder &builder, mlir::Location loc,
617617
back);
618618
}
619619

620-
/// Generate call to Minloc intrinsic runtime routine. This is the version
620+
/// Generate call to `MinlocDim` intrinsic runtime routine. This is the version
621621
/// that takes a dim argument.
622622
void fir::runtime::genMinlocDim(fir::FirOpBuilder &builder, mlir::Location loc,
623623
mlir::Value resultBox, mlir::Value arrayBox,
@@ -628,7 +628,7 @@ void fir::runtime::genMinlocDim(fir::FirOpBuilder &builder, mlir::Location loc,
628628
back);
629629
}
630630

631-
/// Generate call to Minval intrinsic runtime routine. This is the version
631+
/// Generate call to `MinvalDim` intrinsic runtime routine. This is the version
632632
/// that handles any rank array with the dim argument specified.
633633
void fir::runtime::genMinvalDim(fir::FirOpBuilder &builder, mlir::Location loc,
634634
mlir::Value resultBox, mlir::Value arrayBox,
@@ -637,8 +637,8 @@ void fir::runtime::genMinvalDim(fir::FirOpBuilder &builder, mlir::Location loc,
637637
genReduction3Args(func, builder, loc, resultBox, arrayBox, dim, maskBox);
638638
}
639639

640-
/// Generate call to Minval intrinsic runtime routine. This is the version
641-
/// that handles character arrays of rank 1 and without a DIM argument.
640+
/// Generate call to `MinvalCharacter` intrinsic runtime routine. This is the
641+
/// version that handles character arrays of rank 1 and without a DIM argument.
642642
void fir::runtime::genMinvalChar(fir::FirOpBuilder &builder, mlir::Location loc,
643643
mlir::Value resultBox, mlir::Value arrayBox,
644644
mlir::Value maskBox) {
@@ -653,7 +653,7 @@ void fir::runtime::genMinvalChar(fir::FirOpBuilder &builder, mlir::Location loc,
653653
builder.create<fir::CallOp>(loc, func, args);
654654
}
655655

656-
/// Generate call to Minval intrinsic runtime routine. This is the version
656+
/// Generate call to `Minval` intrinsic runtime routine. This is the version
657657
/// that does not take a dim argument.
658658
mlir::Value fir::runtime::genMinval(fir::FirOpBuilder &builder,
659659
mlir::Location loc, mlir::Value arrayBox,
@@ -700,7 +700,7 @@ mlir::Value fir::runtime::genMinval(fir::FirOpBuilder &builder,
700700
return builder.create<fir::CallOp>(loc, func, args).getResult(0);
701701
}
702702

703-
/// Generate call to Product intrinsic runtime routine. This is the version
703+
/// Generate call to `ProductDim` intrinsic runtime routine. This is the version
704704
/// that handles any rank array with the dim argument specified.
705705
void fir::runtime::genProductDim(fir::FirOpBuilder &builder, mlir::Location loc,
706706
mlir::Value resultBox, mlir::Value arrayBox,
@@ -709,7 +709,7 @@ void fir::runtime::genProductDim(fir::FirOpBuilder &builder, mlir::Location loc,
709709
genReduction3Args(func, builder, loc, resultBox, arrayBox, dim, maskBox);
710710
}
711711

712-
/// Generate call to Product intrinsic runtime routine. This is the version
712+
/// Generate call to `Product` intrinsic runtime routine. This is the version
713713
/// that does not take a dim argument.
714714
mlir::Value fir::runtime::genProduct(fir::FirOpBuilder &builder,
715715
mlir::Location loc, mlir::Value arrayBox,
@@ -777,6 +777,7 @@ mlir::Value fir::runtime::genProduct(fir::FirOpBuilder &builder,
777777
return builder.create<fir::CallOp>(loc, func, args).getResult(0);
778778
}
779779

780+
/// Generate call to `DotProduct` intrinsic runtime routine.
780781
mlir::Value fir::runtime::genDotProduct(fir::FirOpBuilder &builder,
781782
mlir::Location loc,
782783
mlir::Value vectorABox,
@@ -852,7 +853,7 @@ mlir::Value fir::runtime::genDotProduct(fir::FirOpBuilder &builder,
852853
vectorBBox, sourceFile, sourceLine);
853854
return builder.create<fir::CallOp>(loc, func, args).getResult(0);
854855
}
855-
/// Generate call to Sum intrinsic runtime routine. This is the version
856+
/// Generate call to `SumDim` intrinsic runtime routine. This is the version
856857
/// that handles any rank array with the dim argument specified.
857858
void fir::runtime::genSumDim(fir::FirOpBuilder &builder, mlir::Location loc,
858859
mlir::Value resultBox, mlir::Value arrayBox,
@@ -861,7 +862,7 @@ void fir::runtime::genSumDim(fir::FirOpBuilder &builder, mlir::Location loc,
861862
genReduction3Args(func, builder, loc, resultBox, arrayBox, dim, maskBox);
862863
}
863864

864-
/// Generate call to Sum intrinsic runtime routine. This is the version
865+
/// Generate call to `Sum` intrinsic runtime routine. This is the version
865866
/// that does not take a dim argument.
866867
mlir::Value fir::runtime::genSum(fir::FirOpBuilder &builder, mlir::Location loc,
867868
mlir::Value arrayBox, mlir::Value maskBox,

0 commit comments

Comments
 (0)