Skip to content

Commit 451e58a

Browse files
committed
Merge remote-tracking branch 'origin/main' into pr/zhinx-subreg
2 parents 98dab0f + 5537ae8 commit 451e58a

File tree

440 files changed

+19129
-3095
lines changed

Some content is hidden

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

440 files changed

+19129
-3095
lines changed

clang/include/clang/Basic/Builtins.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4769,6 +4769,12 @@ def HLSLSelect : LangBuiltin<"HLSL_LANG"> {
47694769
let Prototype = "void(...)";
47704770
}
47714771

4772+
def HLSLSign : LangBuiltin<"HLSL_LANG"> {
4773+
let Spellings = ["__builtin_hlsl_elementwise_sign"];
4774+
let Attributes = [NoThrow, Const];
4775+
let Prototype = "void(...)";
4776+
}
4777+
47724778
// Builtins for XRay.
47734779
def XRayCustomEvent : Builtin {
47744780
let Spellings = ["__xray_customevent"];

clang/include/clang/Lex/Preprocessor.h

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,22 +1053,6 @@ class Preprocessor {
10531053
std::optional<MacroAnnotationInfo> DeprecationInfo;
10541054
std::optional<MacroAnnotationInfo> RestrictExpansionInfo;
10551055
std::optional<SourceLocation> FinalAnnotationLoc;
1056-
1057-
static MacroAnnotations makeDeprecation(SourceLocation Loc,
1058-
std::string Msg) {
1059-
return MacroAnnotations{MacroAnnotationInfo{Loc, std::move(Msg)},
1060-
std::nullopt, std::nullopt};
1061-
}
1062-
1063-
static MacroAnnotations makeRestrictExpansion(SourceLocation Loc,
1064-
std::string Msg) {
1065-
return MacroAnnotations{
1066-
std::nullopt, MacroAnnotationInfo{Loc, std::move(Msg)}, std::nullopt};
1067-
}
1068-
1069-
static MacroAnnotations makeFinal(SourceLocation Loc) {
1070-
return MacroAnnotations{std::nullopt, std::nullopt, Loc};
1071-
}
10721056
};
10731057

10741058
/// Warning information for macro annotations.
@@ -2884,35 +2868,18 @@ class Preprocessor {
28842868

28852869
void addMacroDeprecationMsg(const IdentifierInfo *II, std::string Msg,
28862870
SourceLocation AnnotationLoc) {
2887-
auto Annotations = AnnotationInfos.find(II);
2888-
if (Annotations == AnnotationInfos.end())
2889-
AnnotationInfos.insert(std::make_pair(
2890-
II,
2891-
MacroAnnotations::makeDeprecation(AnnotationLoc, std::move(Msg))));
2892-
else
2893-
Annotations->second.DeprecationInfo =
2894-
MacroAnnotationInfo{AnnotationLoc, std::move(Msg)};
2871+
AnnotationInfos[II].DeprecationInfo =
2872+
MacroAnnotationInfo{AnnotationLoc, std::move(Msg)};
28952873
}
28962874

28972875
void addRestrictExpansionMsg(const IdentifierInfo *II, std::string Msg,
28982876
SourceLocation AnnotationLoc) {
2899-
auto Annotations = AnnotationInfos.find(II);
2900-
if (Annotations == AnnotationInfos.end())
2901-
AnnotationInfos.insert(
2902-
std::make_pair(II, MacroAnnotations::makeRestrictExpansion(
2903-
AnnotationLoc, std::move(Msg))));
2904-
else
2905-
Annotations->second.RestrictExpansionInfo =
2906-
MacroAnnotationInfo{AnnotationLoc, std::move(Msg)};
2877+
AnnotationInfos[II].RestrictExpansionInfo =
2878+
MacroAnnotationInfo{AnnotationLoc, std::move(Msg)};
29072879
}
29082880

29092881
void addFinalLoc(const IdentifierInfo *II, SourceLocation AnnotationLoc) {
2910-
auto Annotations = AnnotationInfos.find(II);
2911-
if (Annotations == AnnotationInfos.end())
2912-
AnnotationInfos.insert(
2913-
std::make_pair(II, MacroAnnotations::makeFinal(AnnotationLoc)));
2914-
else
2915-
Annotations->second.FinalAnnotationLoc = AnnotationLoc;
2882+
AnnotationInfos[II].FinalAnnotationLoc = AnnotationLoc;
29162883
}
29172884

29182885
const MacroAnnotations &getMacroAnnotations(const IdentifierInfo *II) const {

clang/include/clang/Serialization/ASTReader.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,15 @@ class ASTReader
11881188
/// once recursing loading has been completed.
11891189
llvm::SmallVector<NamedDecl *, 16> PendingOdrMergeChecks;
11901190

1191+
/// Lambdas that need to be loaded right after the function they belong to.
1192+
/// It is required to have canonical declaration for lambda class from the
1193+
/// same module as enclosing function. This is required to correctly resolve
1194+
/// captured variables in the lambda. Without this, due to lazy
1195+
/// deserialization canonical declarations for the function and lambdas can
1196+
/// be from different modules and DeclRefExprs may refer to the AST nodes
1197+
/// that don't exist in the function.
1198+
SmallVector<GlobalDeclID, 4> PendingLambdas;
1199+
11911200
using DataPointers =
11921201
std::pair<CXXRecordDecl *, struct CXXRecordDecl::DefinitionData *>;
11931202
using ObjCInterfaceDataPointers =

clang/lib/APINotes/APINotesWriter.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,9 @@ class APINotesWriter::Implementation {
129129
if (Identifier.empty())
130130
return 0;
131131

132-
auto Known = IdentifierIDs.find(Identifier);
133-
if (Known != IdentifierIDs.end())
134-
return Known->second;
135-
136-
// Add to the identifier table.
137-
Known = IdentifierIDs.insert({Identifier, IdentifierIDs.size() + 1}).first;
138-
return Known->second;
132+
// Add to the identifier table if missing.
133+
return IdentifierIDs.try_emplace(Identifier, IdentifierIDs.size() + 1)
134+
.first->second;
139135
}
140136

141137
/// Retrieve the ID for the given selector.

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,26 @@ template <class Emitter> class LoopScope final : public LabelScope<Emitter> {
115115
LoopScope(Compiler<Emitter> *Ctx, LabelTy BreakLabel, LabelTy ContinueLabel)
116116
: LabelScope<Emitter>(Ctx), OldBreakLabel(Ctx->BreakLabel),
117117
OldContinueLabel(Ctx->ContinueLabel),
118-
OldLabelVarScope(Ctx->LabelVarScope) {
118+
OldBreakVarScope(Ctx->BreakVarScope),
119+
OldContinueVarScope(Ctx->ContinueVarScope) {
119120
this->Ctx->BreakLabel = BreakLabel;
120121
this->Ctx->ContinueLabel = ContinueLabel;
121-
this->Ctx->LabelVarScope = this->Ctx->VarScope;
122+
this->Ctx->BreakVarScope = this->Ctx->VarScope;
123+
this->Ctx->ContinueVarScope = this->Ctx->VarScope;
122124
}
123125

124126
~LoopScope() {
125127
this->Ctx->BreakLabel = OldBreakLabel;
126128
this->Ctx->ContinueLabel = OldContinueLabel;
127-
this->Ctx->LabelVarScope = OldLabelVarScope;
129+
this->Ctx->ContinueVarScope = OldContinueVarScope;
130+
this->Ctx->BreakVarScope = OldBreakVarScope;
128131
}
129132

130133
private:
131134
OptLabelTy OldBreakLabel;
132135
OptLabelTy OldContinueLabel;
133-
VariableScope<Emitter> *OldLabelVarScope;
136+
VariableScope<Emitter> *OldBreakVarScope;
137+
VariableScope<Emitter> *OldContinueVarScope;
134138
};
135139

136140
// Sets the context for a switch scope, mapping labels.
@@ -145,18 +149,18 @@ template <class Emitter> class SwitchScope final : public LabelScope<Emitter> {
145149
: LabelScope<Emitter>(Ctx), OldBreakLabel(Ctx->BreakLabel),
146150
OldDefaultLabel(this->Ctx->DefaultLabel),
147151
OldCaseLabels(std::move(this->Ctx->CaseLabels)),
148-
OldLabelVarScope(Ctx->LabelVarScope) {
152+
OldLabelVarScope(Ctx->BreakVarScope) {
149153
this->Ctx->BreakLabel = BreakLabel;
150154
this->Ctx->DefaultLabel = DefaultLabel;
151155
this->Ctx->CaseLabels = std::move(CaseLabels);
152-
this->Ctx->LabelVarScope = this->Ctx->VarScope;
156+
this->Ctx->BreakVarScope = this->Ctx->VarScope;
153157
}
154158

155159
~SwitchScope() {
156160
this->Ctx->BreakLabel = OldBreakLabel;
157161
this->Ctx->DefaultLabel = OldDefaultLabel;
158162
this->Ctx->CaseLabels = std::move(OldCaseLabels);
159-
this->Ctx->LabelVarScope = OldLabelVarScope;
163+
this->Ctx->BreakVarScope = OldLabelVarScope;
160164
}
161165

162166
private:
@@ -4605,18 +4609,23 @@ bool Compiler<Emitter>::visitWhileStmt(const WhileStmt *S) {
46054609
this->fallthrough(CondLabel);
46064610
this->emitLabel(CondLabel);
46074611

4608-
if (const DeclStmt *CondDecl = S->getConditionVariableDeclStmt())
4609-
if (!visitDeclStmt(CondDecl))
4610-
return false;
4612+
{
4613+
LocalScope<Emitter> CondScope(this);
4614+
if (const DeclStmt *CondDecl = S->getConditionVariableDeclStmt())
4615+
if (!visitDeclStmt(CondDecl))
4616+
return false;
46114617

4612-
if (!this->visitBool(Cond))
4613-
return false;
4614-
if (!this->jumpFalse(EndLabel))
4615-
return false;
4618+
if (!this->visitBool(Cond))
4619+
return false;
4620+
if (!this->jumpFalse(EndLabel))
4621+
return false;
46164622

4617-
if (!this->visitStmt(Body))
4618-
return false;
4623+
if (!this->visitStmt(Body))
4624+
return false;
46194625

4626+
if (!CondScope.destroyLocals())
4627+
return false;
4628+
}
46204629
if (!this->jump(CondLabel))
46214630
return false;
46224631
this->fallthrough(EndLabel);
@@ -4636,13 +4645,18 @@ template <class Emitter> bool Compiler<Emitter>::visitDoStmt(const DoStmt *S) {
46364645

46374646
this->fallthrough(StartLabel);
46384647
this->emitLabel(StartLabel);
4648+
46394649
{
4650+
LocalScope<Emitter> CondScope(this);
46404651
if (!this->visitStmt(Body))
46414652
return false;
46424653
this->fallthrough(CondLabel);
46434654
this->emitLabel(CondLabel);
46444655
if (!this->visitBool(Cond))
46454656
return false;
4657+
4658+
if (!CondScope.destroyLocals())
4659+
return false;
46464660
}
46474661
if (!this->jumpTrue(StartLabel))
46484662
return false;
@@ -4671,29 +4685,33 @@ bool Compiler<Emitter>::visitForStmt(const ForStmt *S) {
46714685
this->fallthrough(CondLabel);
46724686
this->emitLabel(CondLabel);
46734687

4674-
if (const DeclStmt *CondDecl = S->getConditionVariableDeclStmt())
4675-
if (!visitDeclStmt(CondDecl))
4676-
return false;
4688+
{
4689+
LocalScope<Emitter> CondScope(this);
4690+
if (const DeclStmt *CondDecl = S->getConditionVariableDeclStmt())
4691+
if (!visitDeclStmt(CondDecl))
4692+
return false;
46774693

4678-
if (Cond) {
4679-
if (!this->visitBool(Cond))
4680-
return false;
4681-
if (!this->jumpFalse(EndLabel))
4682-
return false;
4683-
}
4694+
if (Cond) {
4695+
if (!this->visitBool(Cond))
4696+
return false;
4697+
if (!this->jumpFalse(EndLabel))
4698+
return false;
4699+
}
46844700

4685-
{
46864701
if (Body && !this->visitStmt(Body))
46874702
return false;
46884703

46894704
this->fallthrough(IncLabel);
46904705
this->emitLabel(IncLabel);
46914706
if (Inc && !this->discard(Inc))
46924707
return false;
4693-
}
46944708

4709+
if (!CondScope.destroyLocals())
4710+
return false;
4711+
}
46954712
if (!this->jump(CondLabel))
46964713
return false;
4714+
46974715
this->fallthrough(EndLabel);
46984716
this->emitLabel(EndLabel);
46994717
return true;
@@ -4760,7 +4778,7 @@ bool Compiler<Emitter>::visitBreakStmt(const BreakStmt *S) {
47604778
if (!BreakLabel)
47614779
return false;
47624780

4763-
for (VariableScope<Emitter> *C = VarScope; C != LabelVarScope;
4781+
for (VariableScope<Emitter> *C = VarScope; C != BreakVarScope;
47644782
C = C->getParent())
47654783
C->emitDestruction();
47664784
return this->jump(*BreakLabel);
@@ -4771,8 +4789,8 @@ bool Compiler<Emitter>::visitContinueStmt(const ContinueStmt *S) {
47714789
if (!ContinueLabel)
47724790
return false;
47734791

4774-
for (VariableScope<Emitter> *C = VarScope; C != LabelVarScope;
4775-
C = C->getParent())
4792+
for (VariableScope<Emitter> *C = VarScope;
4793+
C && C->getParent() != ContinueVarScope; C = C->getParent())
47764794
C->emitDestruction();
47774795
return this->jump(*ContinueLabel);
47784796
}
@@ -4781,6 +4799,7 @@ template <class Emitter>
47814799
bool Compiler<Emitter>::visitSwitchStmt(const SwitchStmt *S) {
47824800
const Expr *Cond = S->getCond();
47834801
PrimType CondT = this->classifyPrim(Cond->getType());
4802+
LocalScope<Emitter> LS(this);
47844803

47854804
LabelTy EndLabel = this->getLabel();
47864805
OptLabelTy DefaultLabel = std::nullopt;
@@ -4844,7 +4863,8 @@ bool Compiler<Emitter>::visitSwitchStmt(const SwitchStmt *S) {
48444863
if (!this->visitStmt(S->getBody()))
48454864
return false;
48464865
this->emitLabel(EndLabel);
4847-
return true;
4866+
4867+
return LS.destroyLocals();
48484868
}
48494869

48504870
template <class Emitter>

clang/lib/AST/ByteCode/Compiler.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,12 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, bool>,
409409
/// Switch case mapping.
410410
CaseMap CaseLabels;
411411

412-
/// Scope to cleanup until when chumping to one of the labels.
413-
VariableScope<Emitter> *LabelVarScope = nullptr;
412+
/// Scope to cleanup until when we see a break statement.
413+
VariableScope<Emitter> *BreakVarScope = nullptr;
414414
/// Point to break to.
415415
OptLabelTy BreakLabel;
416+
/// Scope to cleanup until when we see a continue statement.
417+
VariableScope<Emitter> *ContinueVarScope = nullptr;
416418
/// Point to continue to.
417419
OptLabelTy ContinueLabel;
418420
/// Default case label.
@@ -533,7 +535,7 @@ template <class Emitter> class LocalScope : public VariableScope<Emitter> {
533535
return true;
534536
// Emit destructor calls for local variables of record
535537
// type with a destructor.
536-
for (Scope::Local &Local : this->Ctx->Descriptors[*Idx]) {
538+
for (Scope::Local &Local : llvm::reverse(this->Ctx->Descriptors[*Idx])) {
537539
if (!Local.Desc->isPrimitive() && !Local.Desc->isPrimitiveArray()) {
538540
if (!this->Ctx->emitGetPtrLocal(Local.Offset, E))
539541
return false;

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,16 +1177,16 @@ bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,
11771177
return true;
11781178
}
11791179

1180-
bool CallBI(InterpState &S, CodePtr &PC, const Function *Func,
1180+
bool CallBI(InterpState &S, CodePtr OpPC, const Function *Func,
11811181
const CallExpr *CE, uint32_t BuiltinID) {
11821182
if (S.checkingPotentialConstantExpression())
11831183
return false;
1184-
auto NewFrame = std::make_unique<InterpFrame>(S, Func, PC);
1184+
auto NewFrame = std::make_unique<InterpFrame>(S, Func, OpPC);
11851185

11861186
InterpFrame *FrameBefore = S.Current;
11871187
S.Current = NewFrame.get();
11881188

1189-
if (InterpretBuiltin(S, PC, Func, CE, BuiltinID)) {
1189+
if (InterpretBuiltin(S, OpPC, Func, CE, BuiltinID)) {
11901190
NewFrame.release();
11911191
return true;
11921192
}

clang/lib/AST/ByteCode/Interp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ bool Call(InterpState &S, CodePtr OpPC, const Function *Func,
154154
uint32_t VarArgSize);
155155
bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,
156156
uint32_t VarArgSize);
157-
bool CallBI(InterpState &S, CodePtr &PC, const Function *Func,
157+
bool CallBI(InterpState &S, CodePtr OpPC, const Function *Func,
158158
const CallExpr *CE, uint32_t BuiltinID);
159159
bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t ArgSize,
160160
const CallExpr *CE);

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18870,6 +18870,23 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
1887018870
Intrinsic::ID ID = CGM.getHLSLRuntime().getWaveIsFirstLaneIntrinsic();
1887118871
return EmitRuntimeCall(Intrinsic::getDeclaration(&CGM.getModule(), ID));
1887218872
}
18873+
case Builtin::BI__builtin_hlsl_elementwise_sign: {
18874+
Value *Op0 = EmitScalarExpr(E->getArg(0));
18875+
llvm::Type *Xty = Op0->getType();
18876+
llvm::Type *retType = llvm::Type::getInt32Ty(this->getLLVMContext());
18877+
if (Xty->isVectorTy()) {
18878+
auto *XVecTy = E->getArg(0)->getType()->getAs<VectorType>();
18879+
retType = llvm::VectorType::get(
18880+
retType, ElementCount::getFixed(XVecTy->getNumElements()));
18881+
}
18882+
assert((E->getArg(0)->getType()->hasFloatingRepresentation() ||
18883+
E->getArg(0)->getType()->hasSignedIntegerRepresentation()) &&
18884+
"sign operand must have a float or int representation");
18885+
18886+
return Builder.CreateIntrinsic(
18887+
retType, CGM.getHLSLRuntime().getSignIntrinsic(),
18888+
ArrayRef<Value *>{Op0}, nullptr, "hlsl.sign");
18889+
}
1887318890
}
1887418891
return nullptr;
1887518892
}

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,10 @@ Value *ScalarExprEmitter::EmitScalarCast(Value *Src, QualType SrcType,
14551455
return Builder.CreateFPToUI(Src, DstTy, "conv");
14561456
}
14571457

1458+
if ((DstElementTy->is16bitFPTy() && SrcElementTy->is16bitFPTy())) {
1459+
Value *FloatVal = Builder.CreateFPExt(Src, Builder.getFloatTy(), "fpext");
1460+
return Builder.CreateFPTrunc(FloatVal, DstTy, "fptrunc");
1461+
}
14581462
if (DstElementTy->getTypeID() < SrcElementTy->getTypeID())
14591463
return Builder.CreateFPTrunc(Src, DstTy, "conv");
14601464
return Builder.CreateFPExt(Src, DstTy, "conv");

clang/lib/CodeGen/CGHLSLRuntime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class CGHLSLRuntime {
8080
GENERATE_HLSL_INTRINSIC_FUNCTION(Normalize, normalize)
8181
GENERATE_HLSL_INTRINSIC_FUNCTION(Rsqrt, rsqrt)
8282
GENERATE_HLSL_INTRINSIC_FUNCTION(Saturate, saturate)
83+
GENERATE_HLSL_INTRINSIC_FUNCTION(Sign, sign)
8384
GENERATE_HLSL_INTRINSIC_FUNCTION(ThreadId, thread_id)
8485
GENERATE_HLSL_INTRINSIC_FUNCTION(FDot, fdot)
8586
GENERATE_HLSL_INTRINSIC_FUNCTION(SDot, sdot)

0 commit comments

Comments
 (0)