|
45 | 45 | #include "clang/Sema/ParsedTemplate.h" |
46 | 46 | #include "clang/Sema/Scope.h" |
47 | 47 | #include "clang/Sema/ScopeInfo.h" |
| 48 | +#include "clang/Sema/SemaHLSL.h" |
48 | 49 | #include "clang/Sema/SemaInternal.h" |
49 | 50 | #include "clang/Sema/Template.h" |
50 | 51 | #include "llvm/ADT/SmallString.h" |
@@ -2972,10 +2973,10 @@ static bool mergeDeclAttribute(Sema &S, NamedDecl *D, |
2972 | 2973 | else if (const auto *BTFA = dyn_cast<BTFDeclTagAttr>(Attr)) |
2973 | 2974 | NewAttr = S.mergeBTFDeclTagAttr(D, *BTFA); |
2974 | 2975 | else if (const auto *NT = dyn_cast<HLSLNumThreadsAttr>(Attr)) |
2975 | | - NewAttr = |
2976 | | - S.mergeHLSLNumThreadsAttr(D, *NT, NT->getX(), NT->getY(), NT->getZ()); |
| 2976 | + NewAttr = S.HLSL().mergeNumThreadsAttr(D, *NT, NT->getX(), NT->getY(), |
| 2977 | + NT->getZ()); |
2977 | 2978 | else if (const auto *SA = dyn_cast<HLSLShaderAttr>(Attr)) |
2978 | | - NewAttr = S.mergeHLSLShaderAttr(D, *SA, SA->getType()); |
| 2979 | + NewAttr = S.HLSL().mergeShaderAttr(D, *SA, SA->getType()); |
2979 | 2980 | else if (isa<SuppressAttr>(Attr)) |
2980 | 2981 | // Do nothing. Each redeclaration should be suppressed separately. |
2981 | 2982 | NewAttr = nullptr; |
@@ -10808,10 +10809,10 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, |
10808 | 10809 | if (getLangOpts().HLSL && D.isFunctionDefinition()) { |
10809 | 10810 | // Any top level function could potentially be specified as an entry. |
10810 | 10811 | if (!NewFD->isInvalidDecl() && S->getDepth() == 0 && Name.isIdentifier()) |
10811 | | - ActOnHLSLTopLevelFunction(NewFD); |
| 10812 | + HLSL().ActOnTopLevelFunction(NewFD); |
10812 | 10813 |
|
10813 | 10814 | if (NewFD->hasAttr<HLSLShaderAttr>()) |
10814 | | - CheckHLSLEntryPoint(NewFD); |
| 10815 | + HLSL().CheckEntryPoint(NewFD); |
10815 | 10816 | } |
10816 | 10817 |
|
10817 | 10818 | // If this is the first declaration of a library builtin function, add |
@@ -12665,125 +12666,6 @@ void Sema::CheckMSVCRTEntryPoint(FunctionDecl *FD) { |
12665 | 12666 | } |
12666 | 12667 | } |
12667 | 12668 |
|
12668 | | -void Sema::ActOnHLSLTopLevelFunction(FunctionDecl *FD) { |
12669 | | - auto &TargetInfo = getASTContext().getTargetInfo(); |
12670 | | - |
12671 | | - if (FD->getName() != TargetInfo.getTargetOpts().HLSLEntry) |
12672 | | - return; |
12673 | | - |
12674 | | - StringRef Env = TargetInfo.getTriple().getEnvironmentName(); |
12675 | | - HLSLShaderAttr::ShaderType ShaderType; |
12676 | | - if (HLSLShaderAttr::ConvertStrToShaderType(Env, ShaderType)) { |
12677 | | - if (const auto *Shader = FD->getAttr<HLSLShaderAttr>()) { |
12678 | | - // The entry point is already annotated - check that it matches the |
12679 | | - // triple. |
12680 | | - if (Shader->getType() != ShaderType) { |
12681 | | - Diag(Shader->getLocation(), diag::err_hlsl_entry_shader_attr_mismatch) |
12682 | | - << Shader; |
12683 | | - FD->setInvalidDecl(); |
12684 | | - } |
12685 | | - } else { |
12686 | | - // Implicitly add the shader attribute if the entry function isn't |
12687 | | - // explicitly annotated. |
12688 | | - FD->addAttr(HLSLShaderAttr::CreateImplicit(Context, ShaderType, |
12689 | | - FD->getBeginLoc())); |
12690 | | - } |
12691 | | - } else { |
12692 | | - switch (TargetInfo.getTriple().getEnvironment()) { |
12693 | | - case llvm::Triple::UnknownEnvironment: |
12694 | | - case llvm::Triple::Library: |
12695 | | - break; |
12696 | | - default: |
12697 | | - llvm_unreachable("Unhandled environment in triple"); |
12698 | | - } |
12699 | | - } |
12700 | | -} |
12701 | | - |
12702 | | -void Sema::CheckHLSLEntryPoint(FunctionDecl *FD) { |
12703 | | - const auto *ShaderAttr = FD->getAttr<HLSLShaderAttr>(); |
12704 | | - assert(ShaderAttr && "Entry point has no shader attribute"); |
12705 | | - HLSLShaderAttr::ShaderType ST = ShaderAttr->getType(); |
12706 | | - |
12707 | | - switch (ST) { |
12708 | | - case HLSLShaderAttr::Pixel: |
12709 | | - case HLSLShaderAttr::Vertex: |
12710 | | - case HLSLShaderAttr::Geometry: |
12711 | | - case HLSLShaderAttr::Hull: |
12712 | | - case HLSLShaderAttr::Domain: |
12713 | | - case HLSLShaderAttr::RayGeneration: |
12714 | | - case HLSLShaderAttr::Intersection: |
12715 | | - case HLSLShaderAttr::AnyHit: |
12716 | | - case HLSLShaderAttr::ClosestHit: |
12717 | | - case HLSLShaderAttr::Miss: |
12718 | | - case HLSLShaderAttr::Callable: |
12719 | | - if (const auto *NT = FD->getAttr<HLSLNumThreadsAttr>()) { |
12720 | | - DiagnoseHLSLAttrStageMismatch(NT, ST, |
12721 | | - {HLSLShaderAttr::Compute, |
12722 | | - HLSLShaderAttr::Amplification, |
12723 | | - HLSLShaderAttr::Mesh}); |
12724 | | - FD->setInvalidDecl(); |
12725 | | - } |
12726 | | - break; |
12727 | | - |
12728 | | - case HLSLShaderAttr::Compute: |
12729 | | - case HLSLShaderAttr::Amplification: |
12730 | | - case HLSLShaderAttr::Mesh: |
12731 | | - if (!FD->hasAttr<HLSLNumThreadsAttr>()) { |
12732 | | - Diag(FD->getLocation(), diag::err_hlsl_missing_numthreads) |
12733 | | - << HLSLShaderAttr::ConvertShaderTypeToStr(ST); |
12734 | | - FD->setInvalidDecl(); |
12735 | | - } |
12736 | | - break; |
12737 | | - } |
12738 | | - |
12739 | | - for (ParmVarDecl *Param : FD->parameters()) { |
12740 | | - if (const auto *AnnotationAttr = Param->getAttr<HLSLAnnotationAttr>()) { |
12741 | | - CheckHLSLSemanticAnnotation(FD, Param, AnnotationAttr); |
12742 | | - } else { |
12743 | | - // FIXME: Handle struct parameters where annotations are on struct fields. |
12744 | | - // See: https://github.com/llvm/llvm-project/issues/57875 |
12745 | | - Diag(FD->getLocation(), diag::err_hlsl_missing_semantic_annotation); |
12746 | | - Diag(Param->getLocation(), diag::note_previous_decl) << Param; |
12747 | | - FD->setInvalidDecl(); |
12748 | | - } |
12749 | | - } |
12750 | | - // FIXME: Verify return type semantic annotation. |
12751 | | -} |
12752 | | - |
12753 | | -void Sema::CheckHLSLSemanticAnnotation( |
12754 | | - FunctionDecl *EntryPoint, const Decl *Param, |
12755 | | - const HLSLAnnotationAttr *AnnotationAttr) { |
12756 | | - auto *ShaderAttr = EntryPoint->getAttr<HLSLShaderAttr>(); |
12757 | | - assert(ShaderAttr && "Entry point has no shader attribute"); |
12758 | | - HLSLShaderAttr::ShaderType ST = ShaderAttr->getType(); |
12759 | | - |
12760 | | - switch (AnnotationAttr->getKind()) { |
12761 | | - case attr::HLSLSV_DispatchThreadID: |
12762 | | - case attr::HLSLSV_GroupIndex: |
12763 | | - if (ST == HLSLShaderAttr::Compute) |
12764 | | - return; |
12765 | | - DiagnoseHLSLAttrStageMismatch(AnnotationAttr, ST, |
12766 | | - {HLSLShaderAttr::Compute}); |
12767 | | - break; |
12768 | | - default: |
12769 | | - llvm_unreachable("Unknown HLSLAnnotationAttr"); |
12770 | | - } |
12771 | | -} |
12772 | | - |
12773 | | -void Sema::DiagnoseHLSLAttrStageMismatch( |
12774 | | - const Attr *A, HLSLShaderAttr::ShaderType Stage, |
12775 | | - std::initializer_list<HLSLShaderAttr::ShaderType> AllowedStages) { |
12776 | | - SmallVector<StringRef, 8> StageStrings; |
12777 | | - llvm::transform(AllowedStages, std::back_inserter(StageStrings), |
12778 | | - [](HLSLShaderAttr::ShaderType ST) { |
12779 | | - return StringRef( |
12780 | | - HLSLShaderAttr::ConvertShaderTypeToStr(ST)); |
12781 | | - }); |
12782 | | - Diag(A->getLoc(), diag::err_hlsl_attr_unsupported_in_stage) |
12783 | | - << A << HLSLShaderAttr::ConvertShaderTypeToStr(Stage) |
12784 | | - << (AllowedStages.size() != 1) << join(StageStrings, ", "); |
12785 | | -} |
12786 | | - |
12787 | 12669 | bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT) { |
12788 | 12670 | // FIXME: Need strict checking. In C89, we need to check for |
12789 | 12671 | // any assignment, increment, decrement, function-calls, or |
|
0 commit comments