Skip to content

Commit 400b4a2

Browse files
committed
merge main into amd-staging
2 parents bc15782 + 8baa5bf commit 400b4a2

File tree

60 files changed

+1822
-588
lines changed

Some content is hidden

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

60 files changed

+1822
-588
lines changed

clang/include/clang/Basic/BuiltinsX86.td

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,14 @@ let Features = "avx", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWid
461461
def shufps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>, _Vector<8, float>, _Constant int)">;
462462
}
463463

464-
let Features = "avx", Attributes = [NoThrow, Const, RequiredVectorWidth<256>] in {
464+
let Features = "avx", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<256>] in {
465465
def vpermilvarpd : X86Builtin<"_Vector<2, double>(_Vector<2, double>, _Vector<2, long long int>)">;
466466
def vpermilvarps : X86Builtin<"_Vector<4, float>(_Vector<4, float>, _Vector<4, int>)">;
467467
def vpermilvarpd256 : X86Builtin<"_Vector<4, double>(_Vector<4, double>, _Vector<4, long long int>)">;
468468
def vpermilvarps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>, _Vector<8, int>)">;
469+
}
470+
471+
let Features = "avx", Attributes = [NoThrow, Const, RequiredVectorWidth<256>] in {
469472
def dpps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>, _Vector<8, float>, _Constant char)">;
470473
def cmppd256 : X86Builtin<"_Vector<4, double>(_Vector<4, double>, _Vector<4, double>, _Constant char)">;
471474
def cmpps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>, _Vector<8, float>, _Constant char)">;
@@ -1045,24 +1048,24 @@ let Features = "avx512f", Attributes = [NoThrow, RequiredVectorWidth<512>] in {
10451048
def storeaps512_mask : X86Builtin<"void(_Vector<16, float *>, _Vector<16, float>, unsigned short)">;
10461049
}
10471050

1048-
let Features = "avx512f", Attributes = [NoThrow, Const, RequiredVectorWidth<512>] in {
1051+
let Features = "avx512f", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<512>] in {
10491052
def alignq512 : X86Builtin<"_Vector<8, long long int>(_Vector<8, long long int>, _Vector<8, long long int>, _Constant int)">;
10501053
def alignd512 : X86Builtin<"_Vector<16, int>(_Vector<16, int>, _Vector<16, int>, _Constant int)">;
10511054
}
10521055

1053-
let Features = "avx512vl", Attributes = [NoThrow, Const, RequiredVectorWidth<128>] in {
1056+
let Features = "avx512vl", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<128>] in {
10541057
def alignd128 : X86Builtin<"_Vector<4, int>(_Vector<4, int>, _Vector<4, int>, _Constant int)">;
10551058
}
10561059

1057-
let Features = "avx512vl", Attributes = [NoThrow, Const, RequiredVectorWidth<256>] in {
1060+
let Features = "avx512vl", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<256>] in {
10581061
def alignd256 : X86Builtin<"_Vector<8, int>(_Vector<8, int>, _Vector<8, int>, _Constant int)">;
10591062
}
10601063

1061-
let Features = "avx512vl", Attributes = [NoThrow, Const, RequiredVectorWidth<128>] in {
1064+
let Features = "avx512vl", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<128>] in {
10621065
def alignq128 : X86Builtin<"_Vector<2, long long int>(_Vector<2, long long int>, _Vector<2, long long int>, _Constant int)">;
10631066
}
10641067

1065-
let Features = "avx512vl", Attributes = [NoThrow, Const, RequiredVectorWidth<256>] in {
1068+
let Features = "avx512vl", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<256>] in {
10661069
def alignq256 : X86Builtin<"_Vector<4, long long int>(_Vector<4, long long int>, _Vector<4, long long int>, _Constant int)">;
10671070
}
10681071

@@ -1363,15 +1366,15 @@ let Features = "avx512cd", Attributes = [NoThrow, Const, Constexpr, RequiredVect
13631366
def vpconflictsi_512 : X86Builtin<"_Vector<16, int>(_Vector<16, int>)">;
13641367
}
13651368

1366-
let Features = "avx512vl,avx512bitalg", Attributes = [NoThrow, Const, RequiredVectorWidth<128>] in {
1369+
let Features = "avx512vl,avx512bitalg", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<128>] in {
13671370
def vpshufbitqmb128_mask : X86Builtin<"unsigned short(_Vector<16, char>, _Vector<16, char>, unsigned short)">;
13681371
}
13691372

1370-
let Features = "avx512vl,avx512bitalg", Attributes = [NoThrow, Const, RequiredVectorWidth<256>] in {
1373+
let Features = "avx512vl,avx512bitalg", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<256>] in {
13711374
def vpshufbitqmb256_mask : X86Builtin<"unsigned int(_Vector<32, char>, _Vector<32, char>, unsigned int)">;
13721375
}
13731376

1374-
let Features = "avx512bitalg", Attributes = [NoThrow, Const, RequiredVectorWidth<512>] in {
1377+
let Features = "avx512bitalg", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<512>] in {
13751378
def vpshufbitqmb512_mask : X86Builtin<"unsigned long long int(_Vector<64, char>, _Vector<64, char>, unsigned long long int)">;
13761379
}
13771380

@@ -2338,15 +2341,6 @@ let Features = "avx512f", Attributes = [NoThrow, Const, RequiredVectorWidth<128>
23382341
def vcvttss2si32 : X86Builtin<"int(_Vector<4, float>, _Constant int)">;
23392342
def vcvttss2usi32 : X86Builtin<"unsigned int(_Vector<4, float>, _Constant int)">;
23402343
}
2341-
let Features = "avx512f", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<512>] in {
2342-
def vpermilpd512 : X86Builtin<"_Vector<8, double>(_Vector<8, double>, _Constant int)">;
2343-
def vpermilps512 : X86Builtin<"_Vector<16, float>(_Vector<16, float>, _Constant int)">;
2344-
}
2345-
2346-
let Features = "avx512f", Attributes = [NoThrow, Const, RequiredVectorWidth<512>] in {
2347-
def vpermilvarpd512 : X86Builtin<"_Vector<8, double>(_Vector<8, double>, _Vector<8, long long int>)">;
2348-
def vpermilvarps512 : X86Builtin<"_Vector<16, float>(_Vector<16, float>, _Vector<16, int>)">;
2349-
}
23502344

23512345
let Features = "avx512f", Attributes = [NoThrow, Const, RequiredVectorWidth<128>] in {
23522346
def rndscalesd_round_mask : X86Builtin<"_Vector<2, double>(_Vector<2, double>, _Vector<2, double>, _Vector<2, double>, unsigned char, _Constant int, _Constant int)">;
@@ -2439,6 +2433,14 @@ let Features = "avx512f", Attributes = [NoThrow, Const, RequiredVectorWidth<512>
24392433
let Features = "avx512f", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<512>] in {
24402434
def shufpd512 : X86Builtin<"_Vector<8, double>(_Vector<8, double>, _Vector<8, double>, _Constant int)">;
24412435
def shufps512 : X86Builtin<"_Vector<16, float>(_Vector<16, float>, _Vector<16, float>, _Constant int)">;
2436+
def vpermilpd512
2437+
: X86Builtin<"_Vector<8, double>(_Vector<8, double>, _Constant int)">;
2438+
def vpermilps512
2439+
: X86Builtin<"_Vector<16, float>(_Vector<16, float>, _Constant int)">;
2440+
def vpermilvarpd512 : X86Builtin<"_Vector<8, double>(_Vector<8, double>, "
2441+
"_Vector<8, long long int>)">;
2442+
def vpermilvarps512
2443+
: X86Builtin<"_Vector<16, float>(_Vector<16, float>, _Vector<16, int>)">;
24422444
}
24432445

24442446
let Features = "avx512vl", Attributes = [NoThrow, Const, RequiredVectorWidth<256>] in {

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5939,8 +5939,10 @@ bool Compiler<Emitter>::visitBreakStmt(const BreakStmt *S) {
59395939
assert(TargetLabel);
59405940

59415941
for (VariableScope<Emitter> *C = this->VarScope; C != BreakScope;
5942-
C = C->getParent())
5943-
C->emitDestruction();
5942+
C = C->getParent()) {
5943+
if (!C->destroyLocals())
5944+
return false;
5945+
}
59445946

59455947
return this->jump(*TargetLabel);
59465948
}
@@ -5974,8 +5976,10 @@ bool Compiler<Emitter>::visitContinueStmt(const ContinueStmt *S) {
59745976
assert(TargetLabel);
59755977

59765978
for (VariableScope<Emitter> *C = VarScope; C != ContinueScope;
5977-
C = C->getParent())
5978-
C->emitDestruction();
5979+
C = C->getParent()) {
5980+
if (!C->destroyLocals())
5981+
return false;
5982+
}
59795983

59805984
return this->jump(*TargetLabel);
59815985
}
@@ -7159,9 +7163,12 @@ bool Compiler<Emitter>::VisitDeclRefExpr(const DeclRefExpr *E) {
71597163
return this->visitDeclRef(D, E);
71607164
}
71617165

7162-
template <class Emitter> void Compiler<Emitter>::emitCleanup() {
7163-
for (VariableScope<Emitter> *C = VarScope; C; C = C->getParent())
7164-
C->emitDestruction();
7166+
template <class Emitter> bool Compiler<Emitter>::emitCleanup() {
7167+
for (VariableScope<Emitter> *C = VarScope; C; C = C->getParent()) {
7168+
if (!C->destroyLocals())
7169+
return false;
7170+
}
7171+
return true;
71657172
}
71667173

71677174
template <class Emitter>

clang/lib/AST/ByteCode/Compiler.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, bool>,
258258

259259
protected:
260260
/// Emits scope cleanup instructions.
261-
void emitCleanup();
261+
bool emitCleanup();
262262

263263
/// Returns a record type from a record or pointer type.
264264
const RecordType *getRecordTy(QualType Ty);
@@ -524,7 +524,6 @@ template <class Emitter> class VariableScope {
524524
this->addLocal(Local);
525525
}
526526

527-
virtual void emitDestruction() {}
528527
virtual bool emitDestructors(const Expr *E = nullptr) { return true; }
529528
virtual bool destroyLocals(const Expr *E = nullptr) { return true; }
530529
VariableScope *getParent() const { return Parent; }
@@ -555,15 +554,6 @@ template <class Emitter> class LocalScope : public VariableScope<Emitter> {
555554
removeStoredOpaqueValues();
556555
}
557556

558-
/// Overriden to support explicit destruction.
559-
void emitDestruction() override {
560-
if (!Idx)
561-
return;
562-
563-
this->emitDestructors();
564-
this->Ctx->emitDestroy(*Idx, SourceInfo{});
565-
}
566-
567557
/// Explicit destruction of local variables.
568558
bool destroyLocals(const Expr *E = nullptr) override {
569559
if (!Idx)

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3468,6 +3468,69 @@ static bool interp__builtin_ia32_shuffle_generic(
34683468
return true;
34693469
}
34703470

3471+
static bool interp__builtin_ia32_shufbitqmb_mask(InterpState &S, CodePtr OpPC,
3472+
const CallExpr *Call) {
3473+
3474+
assert(Call->getNumArgs() == 3);
3475+
3476+
QualType SourceType = Call->getArg(0)->getType();
3477+
QualType ShuffleMaskType = Call->getArg(1)->getType();
3478+
QualType ZeroMaskType = Call->getArg(2)->getType();
3479+
if (!SourceType->isVectorType() || !ShuffleMaskType->isVectorType() ||
3480+
!ZeroMaskType->isIntegerType()) {
3481+
return false;
3482+
}
3483+
3484+
Pointer Source, ShuffleMask;
3485+
APSInt ZeroMask = popToAPSInt(S, Call->getArg(2));
3486+
ShuffleMask = S.Stk.pop<Pointer>();
3487+
Source = S.Stk.pop<Pointer>();
3488+
3489+
const auto *SourceVecT = SourceType->castAs<VectorType>();
3490+
const auto *ShuffleMaskVecT = ShuffleMaskType->castAs<VectorType>();
3491+
assert(SourceVecT->getNumElements() == ShuffleMaskVecT->getNumElements());
3492+
assert(ZeroMask.getBitWidth() == SourceVecT->getNumElements());
3493+
3494+
PrimType SourceElemT = *S.getContext().classify(SourceVecT->getElementType());
3495+
PrimType ShuffleMaskElemT =
3496+
*S.getContext().classify(ShuffleMaskVecT->getElementType());
3497+
3498+
unsigned NumBytesInQWord = 8;
3499+
unsigned NumBitsInByte = 8;
3500+
unsigned NumBytes = SourceVecT->getNumElements();
3501+
unsigned NumQWords = NumBytes / NumBytesInQWord;
3502+
unsigned RetWidth = ZeroMask.getBitWidth();
3503+
APSInt RetMask(llvm::APInt(RetWidth, 0), /*isUnsigned=*/true);
3504+
3505+
for (unsigned QWordId = 0; QWordId != NumQWords; ++QWordId) {
3506+
APInt SourceQWord(64, 0);
3507+
for (unsigned ByteIdx = 0; ByteIdx != NumBytesInQWord; ++ByteIdx) {
3508+
uint64_t Byte = 0;
3509+
INT_TYPE_SWITCH(SourceElemT, {
3510+
Byte = static_cast<uint64_t>(
3511+
Source.elem<T>(QWordId * NumBytesInQWord + ByteIdx));
3512+
});
3513+
SourceQWord.insertBits(APInt(8, Byte & 0xFF), ByteIdx * NumBitsInByte);
3514+
}
3515+
3516+
for (unsigned ByteIdx = 0; ByteIdx != NumBytesInQWord; ++ByteIdx) {
3517+
unsigned SelIdx = QWordId * NumBytesInQWord + ByteIdx;
3518+
unsigned M = 0;
3519+
INT_TYPE_SWITCH(ShuffleMaskElemT, {
3520+
M = static_cast<unsigned>(ShuffleMask.elem<T>(SelIdx)) & 0x3F;
3521+
});
3522+
3523+
if (ZeroMask[SelIdx]) {
3524+
RetMask.setBitVal(SelIdx, SourceQWord[M]);
3525+
}
3526+
}
3527+
}
3528+
3529+
pushInteger(S, RetMask, Call->getType());
3530+
3531+
return true;
3532+
}
3533+
34713534
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
34723535
uint32_t BuiltinID) {
34733536
if (!S.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
@@ -4653,6 +4716,30 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
46534716
return std::make_pair(0, static_cast<int>(LaneBase + Sel));
46544717
});
46554718

4719+
case X86::BI__builtin_ia32_vpermilvarpd:
4720+
case X86::BI__builtin_ia32_vpermilvarpd256:
4721+
case X86::BI__builtin_ia32_vpermilvarpd512:
4722+
return interp__builtin_ia32_shuffle_generic(
4723+
S, OpPC, Call, [](unsigned DstIdx, unsigned ShuffleMask) {
4724+
unsigned NumElemPerLane = 2;
4725+
unsigned Lane = DstIdx / NumElemPerLane;
4726+
unsigned Offset = ShuffleMask & 0b10 ? 1 : 0;
4727+
return std::make_pair(
4728+
0, static_cast<int>(Lane * NumElemPerLane + Offset));
4729+
});
4730+
4731+
case X86::BI__builtin_ia32_vpermilvarps:
4732+
case X86::BI__builtin_ia32_vpermilvarps256:
4733+
case X86::BI__builtin_ia32_vpermilvarps512:
4734+
return interp__builtin_ia32_shuffle_generic(
4735+
S, OpPC, Call, [](unsigned DstIdx, unsigned ShuffleMask) {
4736+
unsigned NumElemPerLane = 4;
4737+
unsigned Lane = DstIdx / NumElemPerLane;
4738+
unsigned Offset = ShuffleMask & 0b11;
4739+
return std::make_pair(
4740+
0, static_cast<int>(Lane * NumElemPerLane + Offset));
4741+
});
4742+
46564743
case X86::BI__builtin_ia32_vpermilpd:
46574744
case X86::BI__builtin_ia32_vpermilpd256:
46584745
case X86::BI__builtin_ia32_vpermilpd512:
@@ -4844,6 +4931,12 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
48444931
case X86::BI__builtin_ia32_ucmpq512_mask:
48454932
return interp__builtin_ia32_cmp_mask(S, OpPC, Call, BuiltinID,
48464933
/*IsUnsigned=*/true);
4934+
4935+
case X86::BI__builtin_ia32_vpshufbitqmb128_mask:
4936+
case X86::BI__builtin_ia32_vpshufbitqmb256_mask:
4937+
case X86::BI__builtin_ia32_vpshufbitqmb512_mask:
4938+
return interp__builtin_ia32_shufbitqmb_mask(S, OpPC, Call);
4939+
48474940
case X86::BI__builtin_ia32_pslldqi128_byteshift:
48484941
case X86::BI__builtin_ia32_pslldqi256_byteshift:
48494942
case X86::BI__builtin_ia32_pslldqi512_byteshift:
@@ -4906,6 +4999,24 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
49064999
return std::pair<unsigned, int>{VecIdx, ElemIdx};
49075000
});
49085001

5002+
case X86::BI__builtin_ia32_alignd128:
5003+
case X86::BI__builtin_ia32_alignd256:
5004+
case X86::BI__builtin_ia32_alignd512:
5005+
case X86::BI__builtin_ia32_alignq128:
5006+
case X86::BI__builtin_ia32_alignq256:
5007+
case X86::BI__builtin_ia32_alignq512: {
5008+
unsigned NumElems = Call->getType()->castAs<VectorType>()->getNumElements();
5009+
return interp__builtin_ia32_shuffle_generic(
5010+
S, OpPC, Call, [NumElems](unsigned DstIdx, unsigned Shift) {
5011+
unsigned Imm = Shift & 0xFF;
5012+
unsigned EffectiveShift = Imm & (NumElems - 1);
5013+
unsigned SourcePos = DstIdx + EffectiveShift;
5014+
unsigned VecIdx = SourcePos < NumElems ? 1u : 0u;
5015+
unsigned ElemIdx = SourcePos & (NumElems - 1);
5016+
return std::pair<unsigned, int>{VecIdx, static_cast<int>(ElemIdx)};
5017+
});
5018+
}
5019+
49095020
default:
49105021
S.FFDiag(S.Current->getLocation(OpPC),
49115022
diag::note_invalid_subexpr_in_const_expr)

0 commit comments

Comments
 (0)