Skip to content

Commit 1328346

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:1f64dc8f59b9 into amd-gfx:83c7a35b9c6b
Local branch amd-gfx 83c7a35 Merged main:c649fd34e928 into amd-gfx:a460bc1de785 Remote branch main 1f64dc8 [bazel] Port for eaf1590
2 parents 83c7a35 + 1f64dc8 commit 1328346

File tree

20 files changed

+680
-41
lines changed

20 files changed

+680
-41
lines changed

clang/lib/ASTMatchers/ASTMatchFinder.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
#include "clang/ASTMatchers/ASTMatchFinder.h"
1919
#include "clang/AST/ASTConsumer.h"
2020
#include "clang/AST/ASTContext.h"
21+
#include "clang/AST/DeclCXX.h"
2122
#include "clang/AST/RecursiveASTVisitor.h"
2223
#include "llvm/ADT/DenseMap.h"
24+
#include "llvm/ADT/SmallPtrSet.h"
2325
#include "llvm/ADT/StringMap.h"
2426
#include "llvm/Support/PrettyStackTrace.h"
2527
#include "llvm/Support/Timer.h"
@@ -651,11 +653,20 @@ class MatchASTVisitor : public RecursiveASTVisitor<MatchASTVisitor>,
651653
BoundNodesTreeBuilder *Builder,
652654
bool Directly) override;
653655

656+
private:
657+
bool
658+
classIsDerivedFromImpl(const CXXRecordDecl *Declaration,
659+
const Matcher<NamedDecl> &Base,
660+
BoundNodesTreeBuilder *Builder, bool Directly,
661+
llvm::SmallPtrSetImpl<const CXXRecordDecl *> &Visited);
662+
663+
public:
654664
bool objcClassIsDerivedFrom(const ObjCInterfaceDecl *Declaration,
655665
const Matcher<NamedDecl> &Base,
656666
BoundNodesTreeBuilder *Builder,
657667
bool Directly) override;
658668

669+
public:
659670
// Implements ASTMatchFinder::matchesChildOf.
660671
bool matchesChildOf(const DynTypedNode &Node, ASTContext &Ctx,
661672
const DynTypedMatcher &Matcher,
@@ -1361,8 +1372,18 @@ bool MatchASTVisitor::classIsDerivedFrom(const CXXRecordDecl *Declaration,
13611372
const Matcher<NamedDecl> &Base,
13621373
BoundNodesTreeBuilder *Builder,
13631374
bool Directly) {
1375+
llvm::SmallPtrSet<const CXXRecordDecl *, 8> Visited;
1376+
return classIsDerivedFromImpl(Declaration, Base, Builder, Directly, Visited);
1377+
}
1378+
1379+
bool MatchASTVisitor::classIsDerivedFromImpl(
1380+
const CXXRecordDecl *Declaration, const Matcher<NamedDecl> &Base,
1381+
BoundNodesTreeBuilder *Builder, bool Directly,
1382+
llvm::SmallPtrSetImpl<const CXXRecordDecl *> &Visited) {
13641383
if (!Declaration->hasDefinition())
13651384
return false;
1385+
if (!Visited.insert(Declaration).second)
1386+
return false;
13661387
for (const auto &It : Declaration->bases()) {
13671388
const Type *TypeNode = It.getType().getTypePtr();
13681389

@@ -1384,7 +1405,8 @@ bool MatchASTVisitor::classIsDerivedFrom(const CXXRecordDecl *Declaration,
13841405
*Builder = std::move(Result);
13851406
return true;
13861407
}
1387-
if (!Directly && classIsDerivedFrom(ClassDecl, Base, Builder, Directly))
1408+
if (!Directly &&
1409+
classIsDerivedFromImpl(ClassDecl, Base, Builder, Directly, Visited))
13881410
return true;
13891411
}
13901412
return false;

clang/lib/CodeGen/CodeGenTypes.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ CodeGenTypes::CodeGenTypes(CodeGenModule &cgm)
3434
Target(cgm.getTarget()), TheCXXABI(cgm.getCXXABI()),
3535
TheABIInfo(cgm.getTargetCodeGenInfo().getABIInfo()) {
3636
SkippedLayout = false;
37+
LongDoubleReferenced = false;
3738
}
3839

3940
CodeGenTypes::~CodeGenTypes() {
@@ -406,10 +407,12 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
406407
Context.getLangOpts().NativeHalfType ||
407408
!Context.getTargetInfo().useFP16ConversionIntrinsics());
408409
break;
410+
case BuiltinType::LongDouble:
411+
LongDoubleReferenced = true;
412+
LLVM_FALLTHROUGH;
409413
case BuiltinType::BFloat16:
410414
case BuiltinType::Float:
411415
case BuiltinType::Double:
412-
case BuiltinType::LongDouble:
413416
case BuiltinType::Float128:
414417
case BuiltinType::Ibm128:
415418
ResultType = getTypeForFormat(getLLVMContext(),

clang/lib/CodeGen/CodeGenTypes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ class CodeGenTypes {
8484
/// a recursive struct conversion, set this to true.
8585
bool SkippedLayout;
8686

87+
/// True if any instance of long double types are used.
88+
bool LongDoubleReferenced;
89+
8790
/// This map keeps cache of llvm::Types and maps clang::Type to
8891
/// corresponding llvm::Type.
8992
llvm::DenseMap<const Type *, llvm::Type *> TypeCache;
@@ -289,6 +292,7 @@ class CodeGenTypes {
289292
/// zero-initialized (in the C++ sense) with an LLVM zeroinitializer.
290293
bool isZeroInitializable(const RecordDecl *RD);
291294

295+
bool isLongDoubleReferenced() const { return LongDoubleReferenced; }
292296
bool isRecordLayoutComplete(const Type *Ty) const;
293297
unsigned getTargetAddressSpace(QualType T) const;
294298
};

clang/lib/CodeGen/Targets/PPC.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,9 @@ class PPC64_SVR4_TargetCodeGenInfo : public TargetCodeGenInfo {
620620

621621
bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
622622
llvm::Value *Address) const override;
623+
void emitTargetMetadata(CodeGen::CodeGenModule &CGM,
624+
const llvm::MapVector<GlobalDecl, StringRef>
625+
&MangledDeclNames) const override;
623626
};
624627

625628
class PPC64TargetCodeGenInfo : public TargetCodeGenInfo {
@@ -940,6 +943,24 @@ PPC64_SVR4_TargetCodeGenInfo::initDwarfEHRegSizeTable(
940943
/*IsAIX*/ false);
941944
}
942945

946+
void PPC64_SVR4_TargetCodeGenInfo::emitTargetMetadata(
947+
CodeGen::CodeGenModule &CGM,
948+
const llvm::MapVector<GlobalDecl, StringRef> &MangledDeclNames) const {
949+
if (CGM.getTypes().isLongDoubleReferenced()) {
950+
llvm::LLVMContext &Ctx = CGM.getLLVMContext();
951+
const auto *flt = &CGM.getTarget().getLongDoubleFormat();
952+
if (flt == &llvm::APFloat::PPCDoubleDouble())
953+
CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
954+
llvm::MDString::get(Ctx, "doubledouble"));
955+
else if (flt == &llvm::APFloat::IEEEquad())
956+
CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
957+
llvm::MDString::get(Ctx, "ieeequad"));
958+
else if (flt == &llvm::APFloat::IEEEdouble())
959+
CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
960+
llvm::MDString::get(Ctx, "ieeedouble"));
961+
}
962+
}
963+
943964
bool
944965
PPC64TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
945966
llvm::Value *Address) const {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu %s -emit-llvm -o - | FileCheck %s
2+
// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu %s -emit-llvm -mabi=ieeelongdouble -o - | FileCheck %s --check-prefix=IEEE
3+
// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu %s -emit-llvm -mlong-double-64 -o - | FileCheck %s --check-prefix=LDBL64
4+
// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu %s -emit-llvm -DNOLDBL -o - | FileCheck %s --check-prefix=NOLDBL
5+
6+
#ifndef NOLDBL
7+
long double foo(long double a, long double b) {
8+
return a + b;
9+
}
10+
#endif
11+
12+
int bar() { return 1; }
13+
14+
// CHECK: ![[#]] = !{i32 1, !"float-abi", !"doubledouble"}
15+
// IEEE: ![[#]] = !{i32 1, !"float-abi", !"ieeequad"}
16+
// LDBL64: ![[#]] = !{i32 1, !"float-abi", !"ieeedouble"}
17+
// NOLDBL-NOT: ![[#]] = !{i32 1, !"float-abi"

clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,6 +2369,80 @@ TEST_P(ASTMatchersTest, LambdaCaptureTest_BindsToCaptureOfReferenceType) {
23692369
"}", matcher));
23702370
}
23712371

2372+
TEST_P(ASTMatchersTest, IsDerivedFromRecursion) {
2373+
if (!GetParam().isCXX11OrLater())
2374+
return;
2375+
2376+
// Check we don't crash on cycles in the traversal and inheritance hierarchy.
2377+
// Clang will normally enforce there are no cycles, but matchers opted to
2378+
// traverse primary template for dependent specializations, spuriously
2379+
// creating the cycles.
2380+
DeclarationMatcher matcher = cxxRecordDecl(isDerivedFrom("X"));
2381+
EXPECT_TRUE(notMatches(R"cpp(
2382+
template <typename T1, typename T2>
2383+
struct M;
2384+
2385+
template <typename T1>
2386+
struct M<T1, void> {};
2387+
2388+
template <typename T1, typename T2>
2389+
struct L : M<T1, T2> {};
2390+
2391+
template <typename T1, typename T2>
2392+
struct M : L<M<T1, T2>, M<T1, T2>> {};
2393+
)cpp",
2394+
matcher));
2395+
2396+
// Check the running time is not exponential. The number of subojects to
2397+
// traverse grows as fibonacci numbers even though the number of bases to
2398+
// traverse is quadratic.
2399+
// The test will hang if implementation of matchers traverses all subojects.
2400+
EXPECT_TRUE(notMatches(R"cpp(
2401+
template <class T> struct A0 {};
2402+
template <class T> struct A1 : A0<T> {};
2403+
template <class T> struct A2 : A1<T>, A0<T> {};
2404+
template <class T> struct A3 : A2<T>, A1<T> {};
2405+
template <class T> struct A4 : A3<T>, A2<T> {};
2406+
template <class T> struct A5 : A4<T>, A3<T> {};
2407+
template <class T> struct A6 : A5<T>, A4<T> {};
2408+
template <class T> struct A7 : A6<T>, A5<T> {};
2409+
template <class T> struct A8 : A7<T>, A6<T> {};
2410+
template <class T> struct A9 : A8<T>, A7<T> {};
2411+
template <class T> struct A10 : A9<T>, A8<T> {};
2412+
template <class T> struct A11 : A10<T>, A9<T> {};
2413+
template <class T> struct A12 : A11<T>, A10<T> {};
2414+
template <class T> struct A13 : A12<T>, A11<T> {};
2415+
template <class T> struct A14 : A13<T>, A12<T> {};
2416+
template <class T> struct A15 : A14<T>, A13<T> {};
2417+
template <class T> struct A16 : A15<T>, A14<T> {};
2418+
template <class T> struct A17 : A16<T>, A15<T> {};
2419+
template <class T> struct A18 : A17<T>, A16<T> {};
2420+
template <class T> struct A19 : A18<T>, A17<T> {};
2421+
template <class T> struct A20 : A19<T>, A18<T> {};
2422+
template <class T> struct A21 : A20<T>, A19<T> {};
2423+
template <class T> struct A22 : A21<T>, A20<T> {};
2424+
template <class T> struct A23 : A22<T>, A21<T> {};
2425+
template <class T> struct A24 : A23<T>, A22<T> {};
2426+
template <class T> struct A25 : A24<T>, A23<T> {};
2427+
template <class T> struct A26 : A25<T>, A24<T> {};
2428+
template <class T> struct A27 : A26<T>, A25<T> {};
2429+
template <class T> struct A28 : A27<T>, A26<T> {};
2430+
template <class T> struct A29 : A28<T>, A27<T> {};
2431+
template <class T> struct A30 : A29<T>, A28<T> {};
2432+
template <class T> struct A31 : A30<T>, A29<T> {};
2433+
template <class T> struct A32 : A31<T>, A30<T> {};
2434+
template <class T> struct A33 : A32<T>, A31<T> {};
2435+
template <class T> struct A34 : A33<T>, A32<T> {};
2436+
template <class T> struct A35 : A34<T>, A33<T> {};
2437+
template <class T> struct A36 : A35<T>, A34<T> {};
2438+
template <class T> struct A37 : A36<T>, A35<T> {};
2439+
template <class T> struct A38 : A37<T>, A36<T> {};
2440+
template <class T> struct A39 : A38<T>, A37<T> {};
2441+
template <class T> struct A40 : A39<T>, A38<T> {};
2442+
)cpp",
2443+
matcher));
2444+
}
2445+
23722446
TEST(ASTMatchersTestObjC, ObjCMessageCalees) {
23732447
StatementMatcher MessagingFoo =
23742448
objcMessageExpr(callee(objcMethodDecl(hasName("foo"))));

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 475812
19+
#define LLVM_MAIN_REVISION 475822
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ class VPBuilder {
120120
InsertPt = IP;
121121
}
122122

123+
/// This specifies that created instructions should be inserted at the
124+
/// specified point.
125+
void setInsertPoint(VPRecipeBase *IP) {
126+
BB = IP->getParent();
127+
InsertPt = IP->getIterator();
128+
}
129+
123130
/// Create an N-ary operation with \p Opcode, \p Operands and set \p Inst as
124131
/// its underlying Instruction.
125132
VPValue *createNaryOp(unsigned Opcode, ArrayRef<VPValue *> Operands,

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9133,7 +9133,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
91339133
VPValue *CondOp = nullptr;
91349134
if (CM.blockNeedsPredicationForAnyReason(BB)) {
91359135
VPBuilder::InsertPointGuard Guard(Builder);
9136-
Builder.setInsertPoint(LinkVPBB, CurrentLink->getIterator());
9136+
Builder.setInsertPoint(CurrentLink);
91379137
CondOp = RecipeBuilder.createBlockInMask(BB, *Plan);
91389138
}
91399139

@@ -9153,7 +9153,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
91539153
// and the live-out instruction of each reduction, at the beginning of the
91549154
// dedicated latch block.
91559155
if (CM.foldTailByMasking()) {
9156-
Builder.setInsertPoint(LatchVPBB, LatchVPBB->begin());
9156+
Builder.setInsertPoint(&*LatchVPBB->begin());
91579157
for (VPRecipeBase &R :
91589158
Plan->getVectorLoopRegion()->getEntryBasicBlock()->phis()) {
91599159
VPReductionPHIRecipe *PhiR = dyn_cast<VPReductionPHIRecipe>(&R);

llvm/test/TableGen/generic-tables.td

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,34 @@ include "llvm/TableGen/SearchableTable.td"
2525
// CHECK-LABEL: GET_ATable_IMPL
2626
// CHECK: constexpr AEntry ATable[] = {
2727
// CHECK-NOT: { "aaa"
28-
// CHECK: { "baz"
29-
// CHECK: { "foo"
30-
// CHECK: { "foobar"
31-
// CHECK: { "bar"
28+
// CHECK: { "baz", 0x2, 0x6, 0xFFFFFFFF00000000 },
29+
// CHECK: { "foo", 0x4, 0x4, 0x100000000 },
30+
// CHECK: { "foobar", 0x4, 0x5, 0x100000000 },
31+
// CHECK: { "bar", 0x5, 0x3, 0x100000000 },
3232
// CHECK: };
3333

3434
// CHECK: const AEntry *lookupATableByValues(uint8_t Val1, uint16_t Val2) {
3535
// CHECK: return &*Idx;
3636
// CHECK: }
3737

38-
class AEntry<string str, int val1, int val2> {
38+
class AEntry<string str, int val1, int val2, bits<64> val3> {
3939
string Str = str;
4040
bits<8> Val1 = val1;
4141
bits<10> Val2 = val2;
42+
bits<64> Val3 = val3;
4243
bit IsNeeded = 1;
4344
}
4445

45-
def : AEntry<"aaa", 0, 0> { let IsNeeded = 0; }
46-
def : AEntry<"bar", 5, 3>;
47-
def : AEntry<"baz", 2, 6>;
48-
def : AEntry<"foo", 4, 4>;
49-
def : AEntry<"foobar", 4, 5>;
46+
def : AEntry<"aaa", 0, 0, 0> { let IsNeeded = 0; }
47+
def : AEntry<"bar", 5, 3, 0x100000000>;
48+
def : AEntry<"baz", 2, 6, 0xFFFFFFFF00000000>;
49+
def : AEntry<"foo", 4, 4, 0b0000000000000000000000000000000100000000000000000000000000000000>;
50+
def : AEntry<"foobar", 4, 5, 4294967296>;
5051

5152
def ATable : GenericTable {
5253
let FilterClass = "AEntry";
5354
let FilterClassField = "IsNeeded";
54-
let Fields = ["Str", "Val1", "Val2"];
55+
let Fields = ["Str", "Val1", "Val2", "Val3"];
5556

5657
let PrimaryKey = ["Val1", "Val2"];
5758
let PrimaryKeyName = "lookupATableByValues";

llvm/utils/TableGen/SearchableTableEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ using namespace llvm;
3131

3232
namespace {
3333

34-
int getAsInt(Init *B) {
34+
int64_t getAsInt(Init *B) {
3535
return cast<IntInit>(
3636
B->convertInitializerTo(IntRecTy::get(B->getRecordKeeper())))
3737
->getValue();
3838
}
39-
int getInt(Record *R, StringRef Field) {
39+
int64_t getInt(Record *R, StringRef Field) {
4040
return getAsInt(R->getValueInit(Field));
4141
}
4242

mlir/include/mlir/Dialect/ArmSME/IR/ArmSME.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def ArmSME_Dialect : Dialect {
3636
https://developer.arm.com/documentation/ddi0616
3737
https://developer.arm.com/documentation/ddi0602/2023-03/SME-Instructions
3838
}];
39-
let dependentDialects = ["scf::SCFDialect", "vector::VectorDialect"];
39+
let dependentDialects = ["scf::SCFDialect", "vector::VectorDialect",
40+
"memref::MemRefDialect"];
4041
let useDefaultAttributePrinterParser = 1;
4142
}
4243

0 commit comments

Comments
 (0)