Skip to content

Commit 167a295

Browse files

File tree

157 files changed

+5893
-11019
lines changed

Some content is hidden

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

157 files changed

+5893
-11019
lines changed

clang/include/clang/Basic/BuiltinsX86.td

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,17 @@ let Features = "sse", Header = "xmmintrin.h", Attributes = [NoThrow, RequireDecl
198198
def _mm_sfence : X86LibBuiltin<"void()">;
199199
}
200200

201+
let Features = "sse", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<128>] in {
202+
def shufps : X86Builtin<"_Vector<4, float>(_Vector<4, float>, _Vector<4, float>, _Constant int)">;
203+
}
204+
201205
let Features = "sse", Attributes = [NoThrow, Const, RequiredVectorWidth<128>] in {
202206
def rcpps : X86Builtin<"_Vector<4, float>(_Vector<4, float>)">;
203207
def rcpss : X86Builtin<"_Vector<4, float>(_Vector<4, float>)">;
204208
def rsqrtps : X86Builtin<"_Vector<4, float>(_Vector<4, float>)">;
205209
def rsqrtss : X86Builtin<"_Vector<4, float>(_Vector<4, float>)">;
206210
def sqrtps : X86Builtin<"_Vector<4, float>(_Vector<4, float>)">;
207211
def sqrtss : X86Builtin<"_Vector<4, float>(_Vector<4, float>)">;
208-
def shufps : X86Builtin<"_Vector<4, float>(_Vector<4, float>, _Vector<4, float>, _Constant int)">;
209212
}
210213

211214
let Features = "sse2", Attributes = [NoThrow, RequiredVectorWidth<128>] in {
@@ -222,13 +225,13 @@ let Features = "sse2", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWi
222225
def pshufhw : X86Builtin<"_Vector<8, short>(_Vector<8, short>, _Constant int)">;
223226
def movmskpd : X86Builtin<"int(_Vector<2, double>)">;
224227
def pmovmskb128 : X86Builtin<"int(_Vector<16, char>)">;
228+
def shufpd : X86Builtin<"_Vector<2, double>(_Vector<2, double>, _Vector<2, double>, _Constant int)">;
225229
}
226230

227231
let Features = "sse2", Attributes = [NoThrow, Const, RequiredVectorWidth<128>] in {
228232
def psadbw128 : X86Builtin<"_Vector<2, long long int>(_Vector<16, char>, _Vector<16, char>)">;
229233
def sqrtpd : X86Builtin<"_Vector<2, double>(_Vector<2, double>)">;
230234
def sqrtsd : X86Builtin<"_Vector<2, double>(_Vector<2, double>)">;
231-
def shufpd : X86Builtin<"_Vector<2, double>(_Vector<2, double>, _Vector<2, double>, _Constant int)">;
232235
def cvtpd2dq : X86Builtin<"_Vector<2, long long int>(_Vector<2, double>)">;
233236
def cvtpd2ps : X86Builtin<"_Vector<4, float>(_Vector<2, double>)">;
234237
def cvttpd2dq : X86Builtin<"_Vector<4, int>(_Vector<2, double>)">;
@@ -488,13 +491,16 @@ let Features = "avx512f,vpclmulqdq", Attributes = [NoThrow, Const, RequiredVecto
488491
def pclmulqdq512 : X86Builtin<"_Vector<8, long long int>(_Vector<8, long long int>, _Vector<8, long long int>, _Constant char)">;
489492
}
490493

494+
let Features = "avx", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<256>] in {
495+
def shufpd256 : X86Builtin<"_Vector<4, double>(_Vector<4, double>, _Vector<4, double>, _Constant int)">;
496+
def shufps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>, _Vector<8, float>, _Constant int)">;
497+
}
498+
491499
let Features = "avx", Attributes = [NoThrow, Const, RequiredVectorWidth<256>] in {
492500
def vpermilvarpd : X86Builtin<"_Vector<2, double>(_Vector<2, double>, _Vector<2, long long int>)">;
493501
def vpermilvarps : X86Builtin<"_Vector<4, float>(_Vector<4, float>, _Vector<4, int>)">;
494502
def vpermilvarpd256 : X86Builtin<"_Vector<4, double>(_Vector<4, double>, _Vector<4, long long int>)">;
495503
def vpermilvarps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>, _Vector<8, int>)">;
496-
def shufpd256 : X86Builtin<"_Vector<4, double>(_Vector<4, double>, _Vector<4, double>, _Constant int)">;
497-
def shufps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>, _Vector<8, float>, _Constant int)">;
498504
def dpps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>, _Vector<8, float>, _Constant char)">;
499505
def cmppd256 : X86Builtin<"_Vector<4, double>(_Vector<4, double>, _Vector<4, double>, _Constant char)">;
500506
def cmpps256 : X86Builtin<"_Vector<8, float>(_Vector<8, float>, _Vector<8, float>, _Constant char)">;
@@ -2474,6 +2480,9 @@ let Features = "avx512f", Attributes = [NoThrow, Const, RequiredVectorWidth<512>
24742480
def shuf_f64x2 : X86Builtin<"_Vector<8, double>(_Vector<8, double>, _Vector<8, double>, _Constant int)">;
24752481
def shuf_i32x4 : X86Builtin<"_Vector<16, int>(_Vector<16, int>, _Vector<16, int>, _Constant int)">;
24762482
def shuf_i64x2 : X86Builtin<"_Vector<8, long long int>(_Vector<8, long long int>, _Vector<8, long long int>, _Constant int)">;
2483+
}
2484+
2485+
let Features = "avx512f", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<512>] in {
24772486
def shufpd512 : X86Builtin<"_Vector<8, double>(_Vector<8, double>, _Vector<8, double>, _Constant int)">;
24782487
def shufps512 : X86Builtin<"_Vector<16, float>(_Vector<16, float>, _Vector<16, float>, _Constant int)">;
24792488
}

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3352,6 +3352,33 @@ static bool interp__builtin_x86_byteshift(
33523352
return true;
33533353
}
33543354

3355+
static bool interp__builtin_ia32_shuffle_generic(
3356+
InterpState &S, CodePtr OpPC, const CallExpr *Call,
3357+
llvm::function_ref<std::pair<unsigned, unsigned>(unsigned, unsigned)>
3358+
GetSourceIndex) {
3359+
3360+
assert(Call->getNumArgs() == 3);
3361+
unsigned ShuffleMask = popToAPSInt(S, Call->getArg(2)).getZExtValue();
3362+
3363+
QualType Arg0Type = Call->getArg(0)->getType();
3364+
const auto *VecT = Arg0Type->castAs<VectorType>();
3365+
PrimType ElemT = *S.getContext().classify(VecT->getElementType());
3366+
unsigned NumElems = VecT->getNumElements();
3367+
3368+
const Pointer &B = S.Stk.pop<Pointer>();
3369+
const Pointer &A = S.Stk.pop<Pointer>();
3370+
const Pointer &Dst = S.Stk.peek<Pointer>();
3371+
3372+
for (unsigned DstIdx = 0; DstIdx != NumElems; ++DstIdx) {
3373+
auto [SrcVecIdx, SrcIdx] = GetSourceIndex(DstIdx, ShuffleMask);
3374+
const Pointer &Src = (SrcVecIdx == 0) ? A : B;
3375+
TYPE_SWITCH(ElemT, { Dst.elem<T>(DstIdx) = Src.elem<T>(SrcIdx); });
3376+
}
3377+
Dst.initializeAllElements();
3378+
3379+
return true;
3380+
}
3381+
33553382
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
33563383
uint32_t BuiltinID) {
33573384
if (!S.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
@@ -4282,6 +4309,42 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
42824309
case X86::BI__builtin_ia32_selectpd_512:
42834310
return interp__builtin_select(S, OpPC, Call);
42844311

4312+
case X86::BI__builtin_ia32_shufps:
4313+
case X86::BI__builtin_ia32_shufps256:
4314+
case X86::BI__builtin_ia32_shufps512:
4315+
return interp__builtin_ia32_shuffle_generic(
4316+
S, OpPC, Call, [](unsigned DstIdx, unsigned ShuffleMask) {
4317+
unsigned NumElemPerLane = 4;
4318+
unsigned NumSelectableElems = NumElemPerLane / 2;
4319+
unsigned BitsPerElem = 2;
4320+
unsigned IndexMask = 0x3;
4321+
unsigned MaskBits = 8;
4322+
unsigned Lane = DstIdx / NumElemPerLane;
4323+
unsigned ElemInLane = DstIdx % NumElemPerLane;
4324+
unsigned LaneOffset = Lane * NumElemPerLane;
4325+
unsigned SrcIdx = ElemInLane >= NumSelectableElems ? 1 : 0;
4326+
unsigned BitIndex = (DstIdx * BitsPerElem) % MaskBits;
4327+
unsigned Index = (ShuffleMask >> BitIndex) & IndexMask;
4328+
return std::pair<unsigned, unsigned>{SrcIdx, LaneOffset + Index};
4329+
});
4330+
case X86::BI__builtin_ia32_shufpd:
4331+
case X86::BI__builtin_ia32_shufpd256:
4332+
case X86::BI__builtin_ia32_shufpd512:
4333+
return interp__builtin_ia32_shuffle_generic(
4334+
S, OpPC, Call, [](unsigned DstIdx, unsigned ShuffleMask) {
4335+
unsigned NumElemPerLane = 2;
4336+
unsigned NumSelectableElems = NumElemPerLane / 2;
4337+
unsigned BitsPerElem = 1;
4338+
unsigned IndexMask = 0x1;
4339+
unsigned MaskBits = 8;
4340+
unsigned Lane = DstIdx / NumElemPerLane;
4341+
unsigned ElemInLane = DstIdx % NumElemPerLane;
4342+
unsigned LaneOffset = Lane * NumElemPerLane;
4343+
unsigned SrcIdx = ElemInLane >= NumSelectableElems ? 1 : 0;
4344+
unsigned BitIndex = (DstIdx * BitsPerElem) % MaskBits;
4345+
unsigned Index = (ShuffleMask >> BitIndex) & IndexMask;
4346+
return std::pair<unsigned, unsigned>{SrcIdx, LaneOffset + Index};
4347+
});
42854348
case X86::BI__builtin_ia32_pshufb128:
42864349
case X86::BI__builtin_ia32_pshufb256:
42874350
case X86::BI__builtin_ia32_pshufb512:

clang/lib/AST/ExprConstant.cpp

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11619,6 +11619,39 @@ static bool evalPackBuiltin(const CallExpr *E, EvalInfo &Info, APValue &Result,
1161911619
return true;
1162011620
}
1162111621

11622+
static bool evalShuffleGeneric(
11623+
EvalInfo &Info, const CallExpr *Call, APValue &Out,
11624+
llvm::function_ref<std::pair<unsigned, unsigned>(unsigned, unsigned)>
11625+
GetSourceIndex) {
11626+
11627+
const auto *VT = Call->getType()->getAs<VectorType>();
11628+
if (!VT)
11629+
return false;
11630+
11631+
APSInt MaskImm;
11632+
if (!EvaluateInteger(Call->getArg(2), MaskImm, Info))
11633+
return false;
11634+
unsigned ShuffleMask = static_cast<unsigned>(MaskImm.getZExtValue());
11635+
11636+
APValue A, B;
11637+
if (!EvaluateAsRValue(Info, Call->getArg(0), A) ||
11638+
!EvaluateAsRValue(Info, Call->getArg(1), B))
11639+
return false;
11640+
11641+
unsigned NumElts = VT->getNumElements();
11642+
SmallVector<APValue, 16> ResultElements;
11643+
ResultElements.reserve(NumElts);
11644+
11645+
for (unsigned DstIdx = 0; DstIdx != NumElts; ++DstIdx) {
11646+
auto [SrcVecIdx, SrcIdx] = GetSourceIndex(DstIdx, ShuffleMask);
11647+
const APValue &Src = (SrcVecIdx == 0) ? A : B;
11648+
ResultElements.push_back(Src.getVectorElt(SrcIdx));
11649+
}
11650+
11651+
Out = APValue(ResultElements.data(), ResultElements.size());
11652+
return true;
11653+
}
11654+
1162211655
static bool evalPshufbBuiltin(EvalInfo &Info, const CallExpr *Call,
1162311656
APValue &Out) {
1162411657
APValue SrcVec, ControlVec;
@@ -12398,7 +12431,56 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
1239812431

1239912432
return Success(APValue(ResultElements.data(), ResultElements.size()), E);
1240012433
}
12401-
12434+
case X86::BI__builtin_ia32_shufps:
12435+
case X86::BI__builtin_ia32_shufps256:
12436+
case X86::BI__builtin_ia32_shufps512: {
12437+
APValue R;
12438+
if (!evalShuffleGeneric(
12439+
Info, E, R,
12440+
[](unsigned DstIdx,
12441+
unsigned ShuffleMask) -> std::pair<unsigned, unsigned> {
12442+
constexpr unsigned LaneBits = 128u;
12443+
unsigned NumElemPerLane = LaneBits / 32;
12444+
unsigned NumSelectableElems = NumElemPerLane / 2;
12445+
unsigned BitsPerElem = 2;
12446+
unsigned IndexMask = (1u << BitsPerElem) - 1;
12447+
unsigned MaskBits = 8;
12448+
unsigned Lane = DstIdx / NumElemPerLane;
12449+
unsigned ElemInLane = DstIdx % NumElemPerLane;
12450+
unsigned LaneOffset = Lane * NumElemPerLane;
12451+
unsigned BitIndex = (DstIdx * BitsPerElem) % MaskBits;
12452+
unsigned SrcIdx = (ElemInLane < NumSelectableElems) ? 0 : 1;
12453+
unsigned Index = (ShuffleMask >> BitIndex) & IndexMask;
12454+
return {SrcIdx, LaneOffset + Index};
12455+
}))
12456+
return false;
12457+
return Success(R, E);
12458+
}
12459+
case X86::BI__builtin_ia32_shufpd:
12460+
case X86::BI__builtin_ia32_shufpd256:
12461+
case X86::BI__builtin_ia32_shufpd512: {
12462+
APValue R;
12463+
if (!evalShuffleGeneric(
12464+
Info, E, R,
12465+
[](unsigned DstIdx,
12466+
unsigned ShuffleMask) -> std::pair<unsigned, unsigned> {
12467+
constexpr unsigned LaneBits = 128u;
12468+
unsigned NumElemPerLane = LaneBits / 64;
12469+
unsigned NumSelectableElems = NumElemPerLane / 2;
12470+
unsigned BitsPerElem = 1;
12471+
unsigned IndexMask = (1u << BitsPerElem) - 1;
12472+
unsigned MaskBits = 8;
12473+
unsigned Lane = DstIdx / NumElemPerLane;
12474+
unsigned ElemInLane = DstIdx % NumElemPerLane;
12475+
unsigned LaneOffset = Lane * NumElemPerLane;
12476+
unsigned BitIndex = (DstIdx * BitsPerElem) % MaskBits;
12477+
unsigned SrcIdx = (ElemInLane < NumSelectableElems) ? 0 : 1;
12478+
unsigned Index = (ShuffleMask >> BitIndex) & IndexMask;
12479+
return {SrcIdx, LaneOffset + Index};
12480+
}))
12481+
return false;
12482+
return Success(R, E);
12483+
}
1240212484
case X86::BI__builtin_ia32_pshufb128:
1240312485
case X86::BI__builtin_ia32_pshufb256:
1240412486
case X86::BI__builtin_ia32_pshufb512: {

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ AArch64TargetInfo::AArch64TargetInfo(const llvm::Triple &Triple,
206206
StringRef AArch64TargetInfo::getABI() const { return ABI; }
207207

208208
bool AArch64TargetInfo::setABI(const std::string &Name) {
209-
if (Name != "aapcs" && Name != "aapcs-soft" && Name != "darwinpcs" &&
210-
Name != "pauthtest")
209+
if (Name != "aapcs" && Name != "aapcs-soft" && Name != "darwinpcs")
211210
return false;
212211

213212
ABI = Name;
@@ -221,12 +220,6 @@ bool AArch64TargetInfo::validateTarget(DiagnosticsEngine &Diags) const {
221220
Diags.Report(diag::err_target_unsupported_abi_with_fpu) << ABI;
222221
return false;
223222
}
224-
if (getTriple().getEnvironment() == llvm::Triple::PAuthTest &&
225-
getTriple().getOS() != llvm::Triple::Linux) {
226-
Diags.Report(diag::err_target_unsupported_abi_for_triple)
227-
<< getTriple().getEnvironmentName() << getTriple().getTriple();
228-
return false;
229-
}
230223
return true;
231224
}
232225

clang/lib/Basic/Targets/AArch64.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
135135

136136
const llvm::AArch64::ArchInfo *ArchInfo = &llvm::AArch64::ARMV8A;
137137

138+
protected:
138139
std::string ABI;
139140

140141
public:
@@ -279,6 +280,16 @@ class LLVM_LIBRARY_VISIBILITY AArch64leTargetInfo : public AArch64TargetInfo {
279280
void setDataLayout() override;
280281
};
281282

283+
template <>
284+
inline bool
285+
LinuxTargetInfo<AArch64leTargetInfo>::setABI(const std::string &Name) {
286+
if (Name == "pauthtest") {
287+
ABI = Name;
288+
return true;
289+
}
290+
return AArch64leTargetInfo::setABI(Name);
291+
}
292+
282293
class LLVM_LIBRARY_VISIBILITY WindowsARM64TargetInfo
283294
: public WindowsTargetInfo<AArch64leTargetInfo> {
284295
const llvm::Triple Triple;

clang/lib/Basic/Targets/OSTargets.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
#include "OSTargets.h"
13+
#include "AArch64.h"
1314
#include "clang/Basic/MacroBuilder.h"
1415
#include "llvm/ADT/StringRef.h"
1516

clang/lib/Basic/Targets/OSTargets.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,12 @@ class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public OSTargetInfo<Target> {
408408
const char *getStaticInitSectionSpecifier() const override {
409409
return ".text.startup";
410410
}
411+
412+
// This allows template specializations, see
413+
// LinuxTargetInfo<AArch64leTargetInfo>::setABI
414+
bool setABI(const std::string &Name) override {
415+
return OSTargetInfo<Target>::setABI(Name);
416+
}
411417
};
412418

413419
// Managarm Target

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
150150
return createWindowsAArch64TargetCodeGenInfo(CGM, AArch64ABIKind::Win64);
151151
else if (Target.getABI() == "aapcs-soft")
152152
Kind = AArch64ABIKind::AAPCSSoft;
153-
else if (Target.getABI() == "pauthtest")
154-
Kind = AArch64ABIKind::PAuthTest;
155153

156154
return createAArch64TargetCodeGenInfo(CGM, Kind);
157155
}

clang/lib/CodeGen/TargetInfo.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,6 @@ enum class AArch64ABIKind {
483483
DarwinPCS,
484484
Win64,
485485
AAPCSSoft,
486-
PAuthTest,
487486
};
488487

489488
std::unique_ptr<TargetCodeGenInfo>

clang/lib/Driver/ToolChain.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,6 @@ std::string ToolChain::ComputeLLVMTriple(const ArgList &Args,
12521252
}
12531253
case llvm::Triple::aarch64: {
12541254
llvm::Triple Triple = getTriple();
1255-
tools::aarch64::setPAuthABIInTriple(getDriver(), Args, Triple);
12561255
if (!Triple.isOSBinFormatMachO())
12571256
return Triple.getTriple();
12581257

0 commit comments

Comments
 (0)