Skip to content

Commit 6f46bf3

Browse files
committed
merge main into amd-staging
2 parents a212b34 + 2347324 commit 6f46bf3

File tree

39 files changed

+1192
-391
lines changed

39 files changed

+1192
-391
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
#include "clang/AST/RawCommentList.h"
2626
#include "clang/AST/SYCLKernelInfo.h"
2727
#include "clang/AST/TemplateName.h"
28+
#include "clang/AST/TypeOrdering.h"
2829
#include "clang/Basic/LLVM.h"
2930
#include "clang/Basic/PartialDiagnostic.h"
3031
#include "clang/Basic/SourceLocation.h"
3132
#include "llvm/ADT/DenseMap.h"
33+
#include "llvm/ADT/DenseMapInfo.h"
3234
#include "llvm/ADT/DenseSet.h"
3335
#include "llvm/ADT/FoldingSet.h"
3436
#include "llvm/ADT/IntrusiveRefCntPtr.h"
@@ -51,6 +53,36 @@ class FixedPointSemantics;
5153
struct fltSemantics;
5254
template <typename T, unsigned N> class SmallPtrSet;
5355

56+
struct ScalableVecTyKey {
57+
clang::QualType EltTy;
58+
unsigned NumElts;
59+
unsigned NumFields;
60+
61+
bool operator==(const ScalableVecTyKey &RHS) const {
62+
return EltTy == RHS.EltTy && NumElts == RHS.NumElts &&
63+
NumFields == RHS.NumFields;
64+
}
65+
};
66+
67+
// Provide a DenseMapInfo specialization so that ScalableVecTyKey can be used
68+
// as a key in DenseMap.
69+
template <> struct DenseMapInfo<ScalableVecTyKey> {
70+
static inline ScalableVecTyKey getEmptyKey() {
71+
return {DenseMapInfo<clang::QualType>::getEmptyKey(), ~0U, ~0U};
72+
}
73+
static inline ScalableVecTyKey getTombstoneKey() {
74+
return {DenseMapInfo<clang::QualType>::getTombstoneKey(), ~0U, ~0U};
75+
}
76+
static unsigned getHashValue(const ScalableVecTyKey &Val) {
77+
return hash_combine(DenseMapInfo<clang::QualType>::getHashValue(Val.EltTy),
78+
Val.NumElts, Val.NumFields);
79+
}
80+
static bool isEqual(const ScalableVecTyKey &LHS,
81+
const ScalableVecTyKey &RHS) {
82+
return LHS == RHS;
83+
}
84+
};
85+
5486
} // namespace llvm
5587

5688
namespace clang {
@@ -505,6 +537,9 @@ class ASTContext : public RefCountedBase<ASTContext> {
505537
SmallVector<const ObjCInterfaceDecl *, 4>>
506538
ObjCSubClasses;
507539

540+
// A mapping from Scalable Vector Type keys to their corresponding QualType.
541+
mutable llvm::DenseMap<llvm::ScalableVecTyKey, QualType> ScalableVecTyMap;
542+
508543
ASTContext &this_() { return *this; }
509544

510545
public:

clang/lib/AST/ASTContext.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4572,6 +4572,10 @@ QualType ASTContext::getWebAssemblyExternrefType() const {
45724572
/// type.
45734573
QualType ASTContext::getScalableVectorType(QualType EltTy, unsigned NumElts,
45744574
unsigned NumFields) const {
4575+
auto K = llvm::ScalableVecTyKey{EltTy, NumElts, NumFields};
4576+
if (auto It = ScalableVecTyMap.find(K); It != ScalableVecTyMap.end())
4577+
return It->second;
4578+
45754579
if (Target->hasAArch64ACLETypes()) {
45764580
uint64_t EltTySize = getTypeSize(EltTy);
45774581

@@ -4580,29 +4584,29 @@ QualType ASTContext::getScalableVectorType(QualType EltTy, unsigned NumElts,
45804584
if (EltTy->hasIntegerRepresentation() && !EltTy->isBooleanType() && \
45814585
EltTy->hasSignedIntegerRepresentation() == IsSigned && \
45824586
EltTySize == ElBits && NumElts == (NumEls * NF) && NumFields == 1) { \
4583-
return SingletonId; \
4587+
return ScalableVecTyMap[K] = SingletonId; \
45844588
}
45854589
#define SVE_VECTOR_TYPE_FLOAT(Name, MangledName, Id, SingletonId, NumEls, \
45864590
ElBits, NF) \
45874591
if (EltTy->hasFloatingRepresentation() && !EltTy->isBFloat16Type() && \
45884592
EltTySize == ElBits && NumElts == (NumEls * NF) && NumFields == 1) { \
4589-
return SingletonId; \
4593+
return ScalableVecTyMap[K] = SingletonId; \
45904594
}
45914595
#define SVE_VECTOR_TYPE_BFLOAT(Name, MangledName, Id, SingletonId, NumEls, \
45924596
ElBits, NF) \
45934597
if (EltTy->hasFloatingRepresentation() && EltTy->isBFloat16Type() && \
45944598
EltTySize == ElBits && NumElts == (NumEls * NF) && NumFields == 1) { \
4595-
return SingletonId; \
4599+
return ScalableVecTyMap[K] = SingletonId; \
45964600
}
45974601
#define SVE_VECTOR_TYPE_MFLOAT(Name, MangledName, Id, SingletonId, NumEls, \
45984602
ElBits, NF) \
45994603
if (EltTy->isMFloat8Type() && EltTySize == ElBits && \
46004604
NumElts == (NumEls * NF) && NumFields == 1) { \
4601-
return SingletonId; \
4605+
return ScalableVecTyMap[K] = SingletonId; \
46024606
}
46034607
#define SVE_PREDICATE_TYPE_ALL(Name, MangledName, Id, SingletonId, NumEls, NF) \
46044608
if (EltTy->isBooleanType() && NumElts == (NumEls * NF) && NumFields == 1) \
4605-
return SingletonId;
4609+
return ScalableVecTyMap[K] = SingletonId;
46064610
#include "clang/Basic/AArch64ACLETypes.def"
46074611
} else if (Target->hasRISCVVTypes()) {
46084612
uint64_t EltTySize = getTypeSize(EltTy);
@@ -4616,10 +4620,10 @@ QualType ASTContext::getScalableVectorType(QualType EltTy, unsigned NumElts,
46164620
(EltTy->hasFloatingRepresentation() && EltTy->isBFloat16Type() && \
46174621
IsBF && !IsFP)) && \
46184622
EltTySize == ElBits && NumElts == NumEls && NumFields == NF) \
4619-
return SingletonId;
4623+
return ScalableVecTyMap[K] = SingletonId;
46204624
#define RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls) \
46214625
if (EltTy->isBooleanType() && NumElts == NumEls) \
4622-
return SingletonId;
4626+
return ScalableVecTyMap[K] = SingletonId;
46234627
#include "clang/Basic/RISCVVTypes.def"
46244628
}
46254629
return QualType();

clang/lib/AST/ByteCode/Pointer.cpp

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,21 @@ Pointer &Pointer::operator=(const Pointer &P) {
110110
StorageKind = P.StorageKind;
111111
Offset = P.Offset;
112112

113-
if (P.isBlockPointer()) {
113+
switch (StorageKind) {
114+
case Storage::Int:
115+
Int = P.Int;
116+
break;
117+
case Storage::Block:
114118
BS = P.BS;
115119

116120
if (BS.Pointee)
117121
BS.Pointee->addPointer(this);
118-
} else if (P.isIntegralPointer()) {
119-
Int = P.Int;
120-
} else if (P.isFunctionPointer()) {
122+
break;
123+
case Storage::Fn:
121124
Fn = P.Fn;
122-
} else if (P.isTypeidPointer()) {
125+
break;
126+
case Storage::Typeid:
123127
Typeid = P.Typeid;
124-
} else {
125-
assert(false && "Unhandled storage kind");
126128
}
127129
return *this;
128130
}
@@ -147,19 +149,21 @@ Pointer &Pointer::operator=(Pointer &&P) {
147149
StorageKind = P.StorageKind;
148150
Offset = P.Offset;
149151

150-
if (P.isBlockPointer()) {
152+
switch (StorageKind) {
153+
case Storage::Int:
154+
Int = P.Int;
155+
break;
156+
case Storage::Block:
151157
BS = P.BS;
152158

153159
if (BS.Pointee)
154160
BS.Pointee->addPointer(this);
155-
} else if (P.isIntegralPointer()) {
156-
Int = P.Int;
157-
} else if (P.isFunctionPointer()) {
161+
break;
162+
case Storage::Fn:
158163
Fn = P.Fn;
159-
} else if (P.isTypeidPointer()) {
164+
break;
165+
case Storage::Typeid:
160166
Typeid = P.Typeid;
161-
} else {
162-
assert(false && "Unhandled storage kind");
163167
}
164168
return *this;
165169
}
@@ -358,13 +362,17 @@ void Pointer::print(llvm::raw_ostream &OS) const {
358362
}
359363

360364
size_t Pointer::computeOffsetForComparison() const {
361-
if (isIntegralPointer())
362-
return asIntPointer().Value + Offset;
363-
if (isTypeidPointer())
365+
switch (StorageKind) {
366+
case Storage::Int:
367+
return Int.Value + Offset;
368+
case Storage::Block:
369+
// See below.
370+
break;
371+
case Storage::Fn:
372+
return Fn.getIntegerRepresentation() + Offset;
373+
case Storage::Typeid:
364374
return reinterpret_cast<uintptr_t>(asTypeidPointer().TypePtr) + Offset;
365-
366-
if (!isBlockPointer())
367-
return Offset;
375+
}
368376

369377
size_t Result = 0;
370378
Pointer P = *this;

clang/lib/AST/ByteCode/Pointer.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct TypeidPointer {
5656
const Type *TypeInfoType;
5757
};
5858

59-
enum class Storage { Block, Int, Fn, Typeid };
59+
enum class Storage { Int, Block, Fn, Typeid };
6060

6161
/// A pointer to a memory block, live or dead.
6262
///
@@ -252,14 +252,16 @@ class Pointer {
252252

253253
/// Checks if the pointer is null.
254254
bool isZero() const {
255-
if (isBlockPointer())
255+
switch (StorageKind) {
256+
case Storage::Int:
257+
return Int.Value == 0 && Offset == 0;
258+
case Storage::Block:
256259
return BS.Pointee == nullptr;
257-
if (isFunctionPointer())
260+
case Storage::Fn:
258261
return Fn.isZero();
259-
if (isTypeidPointer())
262+
case Storage::Typeid:
260263
return false;
261-
assert(isIntegralPointer());
262-
return Int.Value == 0 && Offset == 0;
264+
}
263265
}
264266
/// Checks if the pointer is live.
265267
bool isLive() const {

0 commit comments

Comments
 (0)