Skip to content

Commit 80150e5

Browse files
committed
Merge "merge main into amd-staging" into amd-staging
2 parents 4f0cdb0 + 4a7def4 commit 80150e5

File tree

112 files changed

+2508
-959
lines changed

Some content is hidden

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

112 files changed

+2508
-959
lines changed

clang/lib/AST/TypePrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2077,7 +2077,7 @@ void TypePrinter::printHLSLAttributedResourceAfter(
20772077
<< HLSLResourceClassAttr::ConvertResourceClassToStr(Attrs.ResourceClass)
20782078
<< ")]]";
20792079
if (Attrs.IsROV)
2080-
OS << " [[hlsl::is_rov()]]";
2080+
OS << " [[hlsl::is_rov]]";
20812081
}
20822082

20832083
void TypePrinter::printObjCInterfaceBefore(const ObjCInterfaceType *T,

clang/lib/CodeGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ add_clang_library(clangCodeGen
122122
Targets/AVR.cpp
123123
Targets/BPF.cpp
124124
Targets/CSKY.cpp
125+
Targets/DirectX.cpp
125126
Targets/Hexagon.cpp
126127
Targets/Lanai.cpp
127128
Targets/LoongArch.cpp

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
302302
case llvm::Triple::spirv32:
303303
case llvm::Triple::spirv64:
304304
return createSPIRVTargetCodeGenInfo(CGM);
305+
case llvm::Triple::dxil:
306+
return createDirectXTargetCodeGenInfo(CGM);
305307
case llvm::Triple::ve:
306308
return createVETargetCodeGenInfo(CGM);
307309
case llvm::Triple::csky: {

clang/lib/CodeGen/TargetInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@ createTCETargetCodeGenInfo(CodeGenModule &CGM);
555555
std::unique_ptr<TargetCodeGenInfo>
556556
createVETargetCodeGenInfo(CodeGenModule &CGM);
557557

558+
std::unique_ptr<TargetCodeGenInfo>
559+
createDirectXTargetCodeGenInfo(CodeGenModule &CGM);
560+
558561
enum class WebAssemblyABIKind {
559562
MVP = 0,
560563
ExperimentalMV = 1,
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//===- DirectX.cpp---------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "ABIInfoImpl.h"
10+
#include "TargetInfo.h"
11+
#include "llvm/IR/DerivedTypes.h"
12+
13+
using namespace clang;
14+
using namespace clang::CodeGen;
15+
16+
//===----------------------------------------------------------------------===//
17+
// Target codegen info implementation for DirectX.
18+
//===----------------------------------------------------------------------===//
19+
20+
namespace {
21+
22+
class DirectXTargetCodeGenInfo : public TargetCodeGenInfo {
23+
public:
24+
DirectXTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
25+
: TargetCodeGenInfo(std::make_unique<DefaultABIInfo>(CGT)) {}
26+
27+
llvm::Type *getHLSLType(CodeGenModule &CGM, const Type *T) const override;
28+
};
29+
30+
llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM,
31+
const Type *Ty) const {
32+
auto *BuiltinTy = dyn_cast<BuiltinType>(Ty);
33+
if (!BuiltinTy || BuiltinTy->getKind() != BuiltinType::HLSLResource)
34+
return nullptr;
35+
36+
llvm::LLVMContext &Ctx = CGM.getLLVMContext();
37+
// FIXME: translate __hlsl_resource_t to target("dx.TypedBuffer", <4 x float>,
38+
// 1, 0, 0) only for now (RWBuffer<float4>); more work us needed to determine
39+
// the target ext type and its parameters based on the handle type
40+
// attributes (not yet implemented)
41+
llvm::FixedVectorType *ElemType =
42+
llvm::FixedVectorType::get(llvm::Type::getFloatTy(Ctx), 4);
43+
unsigned Flags[] = {/*IsWriteable*/ 1, /*IsROV*/ 0, /*IsSigned*/ 0};
44+
return llvm::TargetExtType::get(Ctx, "dx.TypedBuffer", {ElemType}, Flags);
45+
}
46+
47+
} // namespace
48+
49+
std::unique_ptr<TargetCodeGenInfo>
50+
CodeGen::createDirectXTargetCodeGenInfo(CodeGenModule &CGM) {
51+
return std::make_unique<DirectXTargetCodeGenInfo>(CGM.getTypes());
52+
}

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,10 @@ bool clang::CreateHLSLAttributedResourceType(Sema &S, QualType Wrapped,
592592
break;
593593
}
594594
case attr::HLSLROV:
595+
if (ResAttrs.IsROV) {
596+
S.Diag(A->getLocation(), diag::warn_duplicate_attribute_exact) << A;
597+
return false;
598+
}
595599
ResAttrs.IsROV = true;
596600
break;
597601
default:

clang/lib/Sema/SemaOpenACC.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,10 @@ ExprResult SemaOpenACC::CheckReductionVar(Expr *VarExpr) {
12101210

12111211
void SemaOpenACC::ActOnConstruct(OpenACCDirectiveKind K,
12121212
SourceLocation DirLoc) {
1213+
// Start an evaluation context to parse the clause arguments on.
1214+
SemaRef.PushExpressionEvaluationContext(
1215+
Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
1216+
12131217
switch (K) {
12141218
case OpenACCDirectiveKind::Invalid:
12151219
// Nothing to do here, an invalid kind has nothing we can check here. We
@@ -1626,6 +1630,8 @@ ExprResult SemaOpenACC::ActOnArraySectionExpr(Expr *Base, SourceLocation LBLoc,
16261630

16271631
bool SemaOpenACC::ActOnStartStmtDirective(OpenACCDirectiveKind K,
16281632
SourceLocation StartLoc) {
1633+
SemaRef.DiscardCleanupsInEvaluationContext();
1634+
SemaRef.PopExpressionEvaluationContext();
16291635
return diagnoseConstructAppertainment(*this, K, StartLoc, /*IsStmt=*/true);
16301636
}
16311637

@@ -1649,6 +1655,7 @@ StmtResult SemaOpenACC::ActOnEndStmtDirective(OpenACCDirectiveKind K,
16491655
ParentlessLoopConstructs);
16501656

16511657
ParentlessLoopConstructs.clear();
1658+
16521659
return ComputeConstruct;
16531660
}
16541661
case OpenACCDirectiveKind::Loop: {
@@ -1704,6 +1711,11 @@ StmtResult SemaOpenACC::ActOnAssociatedStmt(SourceLocation DirectiveLoc,
17041711

17051712
bool SemaOpenACC::ActOnStartDeclDirective(OpenACCDirectiveKind K,
17061713
SourceLocation StartLoc) {
1714+
// OpenCC3.3 2.1 (line 889)
1715+
// A program must not depend on the order of evaluation of expressions in
1716+
// clause arguments or on any side effects of the evaluations.
1717+
SemaRef.DiscardCleanupsInEvaluationContext();
1718+
SemaRef.PopExpressionEvaluationContext();
17071719
return diagnoseConstructAppertainment(*this, K, StartLoc, /*IsStmt=*/false);
17081720
}
17091721

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5502,10 +5502,6 @@ static TemplateDeductionResult CheckDeductionConsistency(
55025502
ArrayRef<TemplateArgument> DeducedArgs, bool CheckConsistency) {
55035503
MultiLevelTemplateArgumentList MLTAL(FTD, DeducedArgs,
55045504
/*Final=*/true);
5505-
if (ArgIdx != -1)
5506-
if (auto *MD = dyn_cast<CXXMethodDecl>(FTD->getTemplatedDecl());
5507-
MD && MD->isImplicitObjectMemberFunction())
5508-
ArgIdx -= 1;
55095505
Sema::ArgumentPackSubstitutionIndexRAII PackIndex(
55105506
S, ArgIdx != -1 ? ::getPackIndexForParam(S, FTD, MLTAL, ArgIdx) : -1);
55115507
bool IsIncompleteSubstitution = false;
@@ -5576,12 +5572,10 @@ static TemplateDeductionResult FinishTemplateArgumentDeduction(
55765572

55775573
/// Determine whether the function template \p FT1 is at least as
55785574
/// specialized as \p FT2.
5579-
static bool isAtLeastAsSpecializedAs(Sema &S, SourceLocation Loc,
5580-
FunctionTemplateDecl *FT1,
5581-
FunctionTemplateDecl *FT2,
5582-
TemplatePartialOrderingContext TPOC,
5583-
ArrayRef<QualType> Args1,
5584-
ArrayRef<QualType> Args2) {
5575+
static bool isAtLeastAsSpecializedAs(
5576+
Sema &S, SourceLocation Loc, FunctionTemplateDecl *FT1,
5577+
FunctionTemplateDecl *FT2, TemplatePartialOrderingContext TPOC,
5578+
ArrayRef<QualType> Args1, ArrayRef<QualType> Args2, bool Args1Offset) {
55855579
FunctionDecl *FD1 = FT1->getTemplatedDecl();
55865580
FunctionDecl *FD2 = FT2->getTemplatedDecl();
55875581
const FunctionProtoType *Proto1 = FD1->getType()->getAs<FunctionProtoType>();
@@ -5676,6 +5670,8 @@ static bool isAtLeastAsSpecializedAs(Sema &S, SourceLocation Loc,
56765670
TemplateDeductionInfo &Info,
56775671
SmallVectorImpl<DeducedTemplateArgument> &Deduced,
56785672
PartialOrderingKind) {
5673+
if (ArgIdx != -1)
5674+
ArgIdx -= Args1Offset;
56795675
return ::CheckDeductionConsistency(
56805676
S, FTD, ArgIdx, P, A, DeducedArgs,
56815677
/*CheckConsistency=*/HasDeducedParam[ParamIdx]);
@@ -5763,6 +5759,8 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
57635759
const FunctionDecl *FD2 = FT2->getTemplatedDecl();
57645760
bool ShouldConvert1 = false;
57655761
bool ShouldConvert2 = false;
5762+
bool Args1Offset = false;
5763+
bool Args2Offset = false;
57665764
QualType Obj1Ty;
57675765
QualType Obj2Ty;
57685766
if (TPOC == TPOC_Call) {
@@ -5811,6 +5809,7 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
58115809
Obj1Ty = GetImplicitObjectParameterType(this->Context, Method1,
58125810
RawObj1Ty, IsRValRef2);
58135811
Args1.push_back(Obj1Ty);
5812+
Args1Offset = true;
58145813
}
58155814
if (ShouldConvert2) {
58165815
bool IsRValRef1 =
@@ -5821,6 +5820,7 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
58215820
Obj2Ty = GetImplicitObjectParameterType(this->Context, Method2,
58225821
RawObj2Ty, IsRValRef1);
58235822
Args2.push_back(Obj2Ty);
5823+
Args2Offset = true;
58245824
}
58255825
} else {
58265826
if (NonStaticMethod1 && Method1->hasCXXExplicitFunctionObjectParameter())
@@ -5842,10 +5842,10 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
58425842
} else {
58435843
assert(!Reversed && "Only call context could have reversed arguments");
58445844
}
5845-
bool Better1 =
5846-
isAtLeastAsSpecializedAs(*this, Loc, FT1, FT2, TPOC, Args1, Args2);
5847-
bool Better2 =
5848-
isAtLeastAsSpecializedAs(*this, Loc, FT2, FT1, TPOC, Args2, Args1);
5845+
bool Better1 = isAtLeastAsSpecializedAs(*this, Loc, FT1, FT2, TPOC, Args1,
5846+
Args2, Args2Offset);
5847+
bool Better2 = isAtLeastAsSpecializedAs(*this, Loc, FT2, FT1, TPOC, Args2,
5848+
Args1, Args1Offset);
58495849
// C++ [temp.deduct.partial]p10:
58505850
// F is more specialized than G if F is at least as specialized as G and G
58515851
// is not at least as specialized as F.

clang/lib/Sema/SemaType.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8841,7 +8841,11 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type,
88418841
}
88428842
case ParsedAttr::AT_HLSLResourceClass:
88438843
case ParsedAttr::AT_HLSLROV: {
8844-
if (state.getSema().HLSL().handleResourceTypeAttr(attr))
8844+
// Only collect HLSL resource type attributes that are in
8845+
// decl-specifier-seq; do not collect attributes on declarations or those
8846+
// that get to slide after declaration name.
8847+
if (TAL == TAL_DeclSpec &&
8848+
state.getSema().HLSL().handleResourceTypeAttr(attr))
88458849
attr.setUsedAsTypeAttr();
88468850
break;
88478851
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -O1 -o - %s | FileCheck %s
2+
3+
void foo(__hlsl_resource_t res);
4+
5+
// CHECK: define void @"?bar@@YAXU__hlsl_resource_t@@@Z"(target("dx.TypedBuffer", <4 x float>, 1, 0, 0) %[[PARAM:[a-zA-Z0-9]+]])
6+
// CHECK: call void @"?foo@@YAXU__hlsl_resource_t@@@Z"(target("dx.TypedBuffer", <4 x float>, 1, 0, 0) %[[PARAM]])
7+
void bar(__hlsl_resource_t a) {
8+
foo(a);
9+
}

0 commit comments

Comments
 (0)