Skip to content

Commit f26eb4c

Browse files
author
Jenkins
committed
merge main into amd-staging
Change-Id: Ibf08976c7c15bdebb3cd43f50076509910fabbcf
2 parents e3e481d + 5b6db43 commit f26eb4c

File tree

80 files changed

+1615
-603
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1615
-603
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,8 +807,12 @@ def gcc_install_dir_EQ : Joined<["--"], "gcc-install-dir=">,
807807
"Note: executables (e.g. ld) used by the compiler are not overridden by the selected GCC installation">;
808808
def gcc_toolchain : Joined<["--"], "gcc-toolchain=">, Flags<[NoXarchOption]>,
809809
Visibility<[ClangOption, FlangOption]>,
810-
HelpText<"Specify a directory where Clang can find 'include' and 'lib{,32,64}/gcc{,-cross}/$triple/$version'. "
811-
"Clang will use the GCC installation with the largest version">;
810+
HelpText<
811+
"Specify a directory where Clang can find 'include' and 'lib{,32,64}/gcc{,-cross}/$triple/$version'. "
812+
"Clang will use the GCC installation with the largest version">,
813+
HelpTextForVariants<[FlangOption],
814+
"Specify a directory where Flang can find 'lib{,32,64}/gcc{,-cross}/$triple/$version'. "
815+
"Flang will use the GCC installation with the largest version">;
812816
def gcc_triple_EQ : Joined<["--"], "gcc-triple=">,
813817
HelpText<"Search for the GCC installation with the specified triple.">;
814818
def CC : Flag<["-"], "CC">, Visibility<[ClangOption, CC1Option]>,

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -922,9 +922,9 @@ bool ByteCodeExprGen<Emitter>::VisitImplicitValueInitExpr(const ImplicitValueIni
922922
return true;
923923
}
924924

925-
if (QT->isAnyComplexType()) {
925+
if (const auto *ComplexTy = E->getType()->getAs<ComplexType>()) {
926926
assert(Initializing);
927-
QualType ElemQT = QT->getAs<ComplexType>()->getElementType();
927+
QualType ElemQT = ComplexTy->getElementType();
928928
PrimType ElemT = classifyPrim(ElemQT);
929929
for (unsigned I = 0; I < 2; ++I) {
930930
if (!this->visitZeroInitializer(ElemT, ElemQT, E))
@@ -935,6 +935,20 @@ bool ByteCodeExprGen<Emitter>::VisitImplicitValueInitExpr(const ImplicitValueIni
935935
return true;
936936
}
937937

938+
if (const auto *VecT = E->getType()->getAs<VectorType>()) {
939+
unsigned NumVecElements = VecT->getNumElements();
940+
QualType ElemQT = VecT->getElementType();
941+
PrimType ElemT = classifyPrim(ElemQT);
942+
943+
for (unsigned I = 0; I < NumVecElements; ++I) {
944+
if (!this->visitZeroInitializer(ElemT, ElemQT, E))
945+
return false;
946+
if (!this->emitInitElem(ElemT, I, E))
947+
return false;
948+
}
949+
return true;
950+
}
951+
938952
return false;
939953
}
940954

@@ -1098,13 +1112,13 @@ bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
10981112
return true;
10991113
}
11001114

1101-
if (T->isAnyComplexType()) {
1115+
if (const auto *ComplexTy = E->getType()->getAs<ComplexType>()) {
11021116
unsigned NumInits = E->getNumInits();
11031117

11041118
if (NumInits == 1)
11051119
return this->delegate(E->inits()[0]);
11061120

1107-
QualType ElemQT = E->getType()->getAs<ComplexType>()->getElementType();
1121+
QualType ElemQT = ComplexTy->getElementType();
11081122
PrimType ElemT = classifyPrim(ElemQT);
11091123
if (NumInits == 0) {
11101124
// Zero-initialize both elements.

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType,
15401540
if (auto DstPT = dyn_cast<llvm::PointerType>(DstTy)) {
15411541
// The source value may be an integer, or a pointer.
15421542
if (isa<llvm::PointerType>(SrcTy))
1543-
return Builder.CreateBitCast(Src, DstTy, "conv");
1543+
return Src;
15441544

15451545
assert(SrcType->isIntegerType() && "Not ptr->ptr or int->ptr conversion?");
15461546
// First, convert to the correct width so that we control the kind of

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void Flang::addOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
118118
Arg *gNArg = Args.getLastArg(options::OPT_gN_Group);
119119
DebugInfoKind = debugLevelToInfoKind(*gNArg);
120120
} else if (Args.hasArg(options::OPT_g_Flag)) {
121-
DebugInfoKind = llvm::codegenoptions::DebugLineTablesOnly;
121+
DebugInfoKind = llvm::codegenoptions::FullDebugInfo;
122122
} else {
123123
DebugInfoKind = llvm::codegenoptions::NoDebugInfo;
124124
}

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2962,19 +2962,6 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
29622962
Context.getCanonicalTemplateArgument(
29632963
Context.getInjectedTemplateArg(NewParam));
29642964
}
2965-
// Substitute new template parameters into requires-clause if present.
2966-
Expr *RequiresClause =
2967-
transformRequireClause(SemaRef, F, TemplateArgsForBuildingFPrime);
2968-
// FIXME: implement the is_deducible constraint per C++
2969-
// [over.match.class.deduct]p3.3:
2970-
// ... and a constraint that is satisfied if and only if the arguments
2971-
// of A are deducible (see below) from the return type.
2972-
auto *FPrimeTemplateParamList = TemplateParameterList::Create(
2973-
Context, AliasTemplate->getTemplateParameters()->getTemplateLoc(),
2974-
AliasTemplate->getTemplateParameters()->getLAngleLoc(),
2975-
FPrimeTemplateParams,
2976-
AliasTemplate->getTemplateParameters()->getRAngleLoc(),
2977-
/*RequiresClause=*/RequiresClause);
29782965

29792966
// To form a deduction guide f' from f, we leverage clang's instantiation
29802967
// mechanism, we construct a template argument list where the template
@@ -3020,6 +3007,20 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
30203007
F, TemplateArgListForBuildingFPrime, AliasTemplate->getLocation(),
30213008
Sema::CodeSynthesisContext::BuildingDeductionGuides)) {
30223009
auto *GG = cast<CXXDeductionGuideDecl>(FPrime);
3010+
// Substitute new template parameters into requires-clause if present.
3011+
Expr *RequiresClause =
3012+
transformRequireClause(SemaRef, F, TemplateArgsForBuildingFPrime);
3013+
// FIXME: implement the is_deducible constraint per C++
3014+
// [over.match.class.deduct]p3.3:
3015+
// ... and a constraint that is satisfied if and only if the arguments
3016+
// of A are deducible (see below) from the return type.
3017+
auto *FPrimeTemplateParamList = TemplateParameterList::Create(
3018+
Context, AliasTemplate->getTemplateParameters()->getTemplateLoc(),
3019+
AliasTemplate->getTemplateParameters()->getLAngleLoc(),
3020+
FPrimeTemplateParams,
3021+
AliasTemplate->getTemplateParameters()->getRAngleLoc(),
3022+
/*RequiresClause=*/RequiresClause);
3023+
30233024
buildDeductionGuide(SemaRef, AliasTemplate, FPrimeTemplateParamList,
30243025
GG->getCorrespondingConstructor(),
30253026
GG->getExplicitSpecifier(), GG->getTypeSourceInfo(),

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2501,10 +2501,7 @@ TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB,
25012501
assert(Arg.getKind() == TemplateArgument::Type &&
25022502
"unexpected nontype template argument kind in template rewrite");
25032503
QualType NewT = Arg.getAsType();
2504-
assert(isa<TemplateTypeParmType>(NewT) &&
2505-
"type parm not rewritten to type parm");
2506-
auto NewTL = TLB.push<TemplateTypeParmTypeLoc>(NewT);
2507-
NewTL.setNameLoc(TL.getNameLoc());
2504+
TLB.pushTrivial(SemaRef.Context, NewT, TL.getNameLoc());
25082505
return NewT;
25092506
}
25102507

clang/test/AST/Interp/vectors.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ static_assert(A[1] == 2, ""); // ref-error {{not an integral constant expression
88
static_assert(A[2] == 3, ""); // ref-error {{not an integral constant expression}}
99
static_assert(A[3] == 4, ""); // ref-error {{not an integral constant expression}}
1010

11+
12+
/// FIXME: It would be nice if the note said 'vector' instead of 'array'.
13+
static_assert(A[12] == 4, ""); // ref-error {{not an integral constant expression}} \
14+
// expected-error {{not an integral constant expression}} \
15+
// expected-note {{cannot refer to element 12 of array of 4 elements in a constant expression}}
16+
17+
1118
/// VectorSplat casts
1219
typedef __attribute__(( ext_vector_type(4) )) float float4;
1320
constexpr float4 vec4_0 = (float4)0.5f;
@@ -18,6 +25,19 @@ static_assert(vec4_0[3] == 0.5, ""); // ref-error {{not an integral constant exp
1825
constexpr int vec4_0_discarded = ((float4)12.0f, 0);
1926

2027

28+
/// ImplicitValueInitExpr of vector type
29+
constexpr float4 arr4[2] = {
30+
{1,2,3,4},
31+
};
32+
static_assert(arr4[0][0] == 1, ""); // ref-error {{not an integral constant expression}}
33+
static_assert(arr4[0][1] == 2, ""); // ref-error {{not an integral constant expression}}
34+
static_assert(arr4[0][2] == 3, ""); // ref-error {{not an integral constant expression}}
35+
static_assert(arr4[0][3] == 4, ""); // ref-error {{not an integral constant expression}}
36+
static_assert(arr4[1][0] == 0, ""); // ref-error {{not an integral constant expression}}
37+
static_assert(arr4[1][0] == 0, ""); // ref-error {{not an integral constant expression}}
38+
static_assert(arr4[1][0] == 0, ""); // ref-error {{not an integral constant expression}}
39+
static_assert(arr4[1][0] == 0, ""); // ref-error {{not an integral constant expression}}
40+
2141

2242
/// From constant-expression-cxx11.cpp
2343
namespace Vector {

clang/test/SemaCXX/cxx20-ctad-type-alias.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,21 @@ using String = Array<char, N>;
289289
// Verify no crash on constructing the aggregate deduction guides.
290290
String s("hello");
291291
} // namespace test21
292+
293+
// GH89013
294+
namespace test22 {
295+
class Base {};
296+
template <typename T>
297+
class Derived final : public Base {};
298+
299+
template <typename T, typename D>
300+
requires __is_base_of(Base, D)
301+
struct Foo {
302+
explicit Foo(D) {}
303+
};
304+
305+
template <typename U>
306+
using AFoo = Foo<int, Derived<U>>;
307+
308+
AFoo a(Derived<int>{});
309+
} // namespace test22

clang/test/SemaTemplate/deduction-guide.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,31 @@ AG ag = {1};
260260
// CHECK: |-TemplateArgument type 'int'
261261
// CHECK: | `-BuiltinType {{.*}} 'int'
262262
// CHECK: `-ParmVarDecl {{.*}} 'int'
263+
264+
template <typename D>
265+
requires (sizeof(D) == 4)
266+
struct Foo {
267+
Foo(D);
268+
};
269+
270+
template <typename U>
271+
using AFoo = Foo<G<U>>;
272+
// Verify that the require-clause from the Foo deduction guide is transformed.
273+
// The D occurrence should be rewritten to G<type-parameter-0-0>.
274+
//
275+
// CHECK-LABEL: Dumping <deduction guide for AFoo>
276+
// CHECK: FunctionTemplateDecl {{.*}} implicit <deduction guide for AFoo>
277+
// CHECK-NEXT: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 0 U
278+
// CHECK-NEXT: |-ParenExpr {{.*}} 'bool'
279+
// CHECK-NEXT: | `-BinaryOperator {{.*}} 'bool' '=='
280+
// CHECK-NEXT: | |-UnaryExprOrTypeTraitExpr {{.*}} 'G<type-parameter-0-0>'
281+
// CHECK-NEXT: | `-ImplicitCastExpr {{.*}}
282+
// CHECK-NEXT: | `-IntegerLiteral {{.*}}
283+
// CHECK-NEXT: |-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for AFoo> 'auto (G<type-parameter-0-0>) -> Foo<G<type-parameter-0-0>>'
284+
// CHECK-NEXT: | `-ParmVarDecl {{.*}} 'G<type-parameter-0-0>'
285+
// CHECK-NEXT: `-CXXDeductionGuideDecl {{.*}} implicit used <deduction guide for AFoo> 'auto (G<int>) -> Foo<G<int>>' implicit_instantiation
286+
// CHECK-NEXT: |-TemplateArgument type 'int'
287+
// CHECK-NEXT: | `-BuiltinType {{.*}} 'int'
288+
// CHECK-NEXT: `-ParmVarDecl {{.*}} 'G<int>'
289+
290+
AFoo aa(G<int>{});

flang/include/flang/Optimizer/Transforms/Passes.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ namespace fir {
3131
// Passes defined in Passes.td
3232
//===----------------------------------------------------------------------===//
3333

34-
#define GEN_PASS_DECL_ABSTRACTRESULTONFUNCOPT
35-
#define GEN_PASS_DECL_ABSTRACTRESULTONGLOBALOPT
34+
#define GEN_PASS_DECL_ABSTRACTRESULTOPT
3635
#define GEN_PASS_DECL_AFFINEDIALECTPROMOTION
3736
#define GEN_PASS_DECL_AFFINEDIALECTDEMOTION
3837
#define GEN_PASS_DECL_ANNOTATECONSTANTOPERANDS
@@ -50,8 +49,6 @@ namespace fir {
5049
#define GEN_PASS_DECL_OPENACCDATAOPERANDCONVERSION
5150
#include "flang/Optimizer/Transforms/Passes.h.inc"
5251

53-
std::unique_ptr<mlir::Pass> createAbstractResultOnFuncOptPass();
54-
std::unique_ptr<mlir::Pass> createAbstractResultOnGlobalOptPass();
5552
std::unique_ptr<mlir::Pass> createAffineDemotionPass();
5653
std::unique_ptr<mlir::Pass>
5754
createArrayValueCopyPass(fir::ArrayValueCopyOptions options = {});

flang/include/flang/Optimizer/Transforms/Passes.td

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
include "mlir/Pass/PassBase.td"
1818

19-
class AbstractResultOptBase<string optExt, string operation>
20-
: Pass<"abstract-result-on-" # optExt # "-opt", operation> {
19+
def AbstractResultOpt
20+
: Pass<"abstract-result"> {
2121
let summary = "Convert fir.array, fir.box and fir.rec function result to "
2222
"function argument";
2323
let description = [{
@@ -35,14 +35,6 @@ class AbstractResultOptBase<string optExt, string operation>
3535
];
3636
}
3737

38-
def AbstractResultOnFuncOpt : AbstractResultOptBase<"func", "mlir::func::FuncOp"> {
39-
let constructor = "::fir::createAbstractResultOnFuncOptPass()";
40-
}
41-
42-
def AbstractResultOnGlobalOpt : AbstractResultOptBase<"global", "fir::GlobalOp"> {
43-
let constructor = "::fir::createAbstractResultOnGlobalOptPass()";
44-
}
45-
4638
def AffineDialectPromotion : Pass<"promote-to-affine", "::mlir::func::FuncOp"> {
4739
let summary = "Promotes `fir.{do_loop,if}` to `affine.{for,if}`.";
4840
let description = [{

flang/include/flang/Tools/CLOptions.inc

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "flang/Optimizer/Transforms/Passes.h"
2020
#include "llvm/Passes/OptimizationLevel.h"
2121
#include "llvm/Support/CommandLine.h"
22+
#include <type_traits>
2223

2324
#define DisableOption(DOName, DOOption, DODescription) \
2425
static llvm::cl::opt<bool> disable##DOName("disable-" DOOption, \
@@ -86,6 +87,29 @@ DisableOption(BoxedProcedureRewrite, "boxed-procedure-rewrite",
8687
DisableOption(ExternalNameConversion, "external-name-interop",
8788
"convert names with external convention");
8889

90+
// TODO: remove once these are used for non-codegen passes
91+
#if !defined(FLANG_EXCLUDE_CODEGEN)
92+
using PassConstructor = std::unique_ptr<mlir::Pass>();
93+
94+
template <typename OP>
95+
void addNestedPassToOps(mlir::PassManager &pm, PassConstructor ctor) {
96+
pm.addNestedPass<OP>(ctor());
97+
}
98+
99+
template <typename OP, typename... OPS,
100+
typename = std::enable_if_t<sizeof...(OPS) != 0>>
101+
void addNestedPassToOps(mlir::PassManager &pm, PassConstructor ctor) {
102+
addNestedPassToOps<OP>(pm, ctor);
103+
addNestedPassToOps<OPS...>(pm, ctor);
104+
}
105+
106+
void addNestedPassToAllTopLevelOperations(
107+
mlir::PassManager &pm, PassConstructor ctor) {
108+
addNestedPassToOps<mlir::func::FuncOp, mlir::omp::DeclareReductionOp,
109+
fir::GlobalOp>(pm, ctor);
110+
}
111+
#endif
112+
89113
/// Generic for adding a pass to the pass manager if it is not disabled.
90114
template <typename F>
91115
void addPassConditionally(
@@ -304,9 +328,7 @@ inline void createDebugPasses(
304328
inline void createDefaultFIRCodeGenPassPipeline(
305329
mlir::PassManager &pm, MLIRToLLVMPassPipelineConfig config) {
306330
fir::addBoxedProcedurePass(pm);
307-
pm.addNestedPass<mlir::func::FuncOp>(
308-
fir::createAbstractResultOnFuncOptPass());
309-
pm.addNestedPass<fir::GlobalOp>(fir::createAbstractResultOnGlobalOptPass());
331+
addNestedPassToAllTopLevelOperations(pm, fir::createAbstractResultOpt);
310332
fir::addCodeGenRewritePass(pm);
311333
fir::addTargetRewritePass(pm);
312334
fir::addExternalNameConversionPass(pm, config.Underscoring);

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ static bool parseDebugArgs(Fortran::frontend::CodeGenOptions &opts,
145145
}
146146
opts.setDebugInfo(val.value());
147147
if (val != llvm::codegenoptions::DebugLineTablesOnly &&
148+
val != llvm::codegenoptions::FullDebugInfo &&
148149
val != llvm::codegenoptions::NoDebugInfo) {
149150
const auto debugWarning = diags.getCustomDiagID(
150151
clang::DiagnosticsEngine::Warning, "Unsupported debug option: %0");

flang/lib/Optimizer/Analysis/AliasAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ using namespace mlir;
2929
//===----------------------------------------------------------------------===//
3030

3131
static bool isDummyArgument(mlir::Value v) {
32-
auto blockArg{v.dyn_cast<mlir::BlockArgument>()};
32+
auto blockArg{mlir::dyn_cast<mlir::BlockArgument>(v)};
3333
if (!blockArg)
3434
return false;
3535

flang/lib/Optimizer/Dialect/FIROps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,7 +2165,7 @@ mlir::ParseResult fir::DoLoopOp::parse(mlir::OpAsmParser &parser,
21652165
}
21662166

21672167
fir::DoLoopOp fir::getForInductionVarOwner(mlir::Value val) {
2168-
auto ivArg = val.dyn_cast<mlir::BlockArgument>();
2168+
auto ivArg = mlir::dyn_cast<mlir::BlockArgument>(val);
21692169
if (!ivArg)
21702170
return {};
21712171
assert(ivArg.getOwner() && "unlinked block argument");
@@ -3777,7 +3777,7 @@ valueCheckFirAttributes(mlir::Value value,
37773777
if (auto loadOp = mlir::dyn_cast<fir::LoadOp>(definingOp))
37783778
value = loadOp.getMemref();
37793779
// If this is a function argument, look in the argument attributes.
3780-
if (auto blockArg = value.dyn_cast<mlir::BlockArgument>()) {
3780+
if (auto blockArg = mlir::dyn_cast<mlir::BlockArgument>(value)) {
37813781
if (blockArg.getOwner() && blockArg.getOwner()->isEntryBlock())
37823782
if (auto funcOp = mlir::dyn_cast<mlir::func::FuncOp>(
37833783
blockArg.getOwner()->getParentOp()))

0 commit comments

Comments
 (0)