llvm/clang/lib/Sema/SemaHLSL.cpp

//===- SemaHLSL.cpp - Semantic Analysis for HLSL constructs ---------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// This implements Semantic Analysis for HLSL constructs.
//===----------------------------------------------------------------------===//

#include "clang/Sema/SemaHLSL.h"
#include "clang/AST/Decl.h"
#include "clang/AST/Expr.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Basic/DiagnosticSema.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Sema/Initialization.h"
#include "clang/Sema/ParsedAttr.h"
#include "clang/Sema/Sema.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/DXILABI.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/TargetParser/Triple.h"
#include <iterator>

usingnamespaceclang;

SemaHLSL::SemaHLSL(Sema &S) :{}

Decl *SemaHLSL::ActOnStartBuffer(Scope *BufferScope, bool CBuffer,
                                 SourceLocation KwLoc, IdentifierInfo *Ident,
                                 SourceLocation IdentLoc,
                                 SourceLocation LBrace) {}

// Calculate the size of a legacy cbuffer type based on
// https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-packing-rules
static unsigned calculateLegacyCbufferSize(const ASTContext &Context,
                                           QualType T) {}

void SemaHLSL::ActOnFinishBuffer(Decl *Dcl, SourceLocation RBrace) {}

HLSLNumThreadsAttr *SemaHLSL::mergeNumThreadsAttr(Decl *D,
                                                  const AttributeCommonInfo &AL,
                                                  int X, int Y, int Z) {}

HLSLWaveSizeAttr *SemaHLSL::mergeWaveSizeAttr(Decl *D,
                                              const AttributeCommonInfo &AL,
                                              int Min, int Max, int Preferred,
                                              int SpelledArgsCount) {}

HLSLShaderAttr *
SemaHLSL::mergeShaderAttr(Decl *D, const AttributeCommonInfo &AL,
                          llvm::Triple::EnvironmentType ShaderType) {}

HLSLParamModifierAttr *
SemaHLSL::mergeParamModifierAttr(Decl *D, const AttributeCommonInfo &AL,
                                 HLSLParamModifierAttr::Spelling Spelling) {}

void SemaHLSL::ActOnTopLevelFunction(FunctionDecl *FD) {}

void SemaHLSL::CheckEntryPoint(FunctionDecl *FD) {}

void SemaHLSL::CheckSemanticAnnotation(
    FunctionDecl *EntryPoint, const Decl *Param,
    const HLSLAnnotationAttr *AnnotationAttr) {}

void SemaHLSL::DiagnoseAttrStageMismatch(
    const Attr *A, llvm::Triple::EnvironmentType Stage,
    std::initializer_list<llvm::Triple::EnvironmentType> AllowedStages) {}

void SemaHLSL::handleNumThreadsAttr(Decl *D, const ParsedAttr &AL) {}

static bool isValidWaveSizeValue(unsigned Value) {}

void SemaHLSL::handleWaveSizeAttr(Decl *D, const ParsedAttr &AL) {}

static bool isLegalTypeForHLSLSV_DispatchThreadID(QualType T) {}

void SemaHLSL::handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL) {}

void SemaHLSL::handlePackOffsetAttr(Decl *D, const ParsedAttr &AL) {}

void SemaHLSL::handleShaderAttr(Decl *D, const ParsedAttr &AL) {}

void SemaHLSL::handleResourceClassAttr(Decl *D, const ParsedAttr &AL) {}

// Validates HLSL resource type attribute and adds it to the list to be
// processed into a single HLSLAttributedResourceType later on.
// Returns false if the attribute is invalid.
bool SemaHLSL::handleResourceTypeAttr(const ParsedAttr &AL) {}

// Combines all resource type attributes and create HLSLAttributedResourceType.
QualType SemaHLSL::ProcessResourceTypeAttributes(QualType CurrentType) {}

// Returns source location for the HLSLAttributedResourceType
SourceLocation
SemaHLSL::TakeLocForHLSLAttribute(const HLSLAttributedResourceType *RT) {}

struct RegisterBindingFlags {};

static bool isDeclaredWithinCOrTBuffer(const Decl *TheDecl) {}

// get the record decl from a var decl that we expect
// represents a resource
static CXXRecordDecl *getRecordDeclFromVarDecl(VarDecl *VD) {}

static void updateResourceClassFlagsFromDeclResourceClass(
    RegisterBindingFlags &Flags, llvm::hlsl::ResourceClass DeclResourceClass) {}

template <typename T>
static const T *getSpecifiedHLSLAttrFromRecordDecl(RecordDecl *TheRecordDecl) {}

template <typename T>
static const T *getSpecifiedHLSLAttrFromVarDecl(VarDecl *VD) {}

static void updateFlagsFromType(QualType TheQualTy,
                                RegisterBindingFlags &Flags);

static void updateResourceClassFlagsFromRecordDecl(RegisterBindingFlags &Flags,
                                                   const RecordDecl *RD) {}

static void updateFlagsFromType(QualType TheQualTy,
                                RegisterBindingFlags &Flags) {}

static RegisterBindingFlags HLSLFillRegisterBindingFlags(Sema &S,
                                                         Decl *TheDecl) {}

enum class RegisterType {};

static RegisterType getRegisterType(StringRef Slot) {}

static void ValidateMultipleRegisterAnnotations(Sema &S, Decl *TheDecl,
                                                RegisterType regType) {}

static void DiagnoseHLSLRegisterAttribute(Sema &S, SourceLocation &ArgLoc,
                                          Decl *TheDecl, RegisterType regType) {}

void SemaHLSL::handleResourceBindingAttr(Decl *TheDecl, const ParsedAttr &AL) {}

void SemaHLSL::handleParamModifierAttr(Decl *D, const ParsedAttr &AL) {}

namespace {

/// This class implements HLSL availability diagnostics for default
/// and relaxed mode
///
/// The goal of this diagnostic is to emit an error or warning when an
/// unavailable API is found in code that is reachable from the shader
/// entry function or from an exported function (when compiling a shader
/// library).
///
/// This is done by traversing the AST of all shader entry point functions
/// and of all exported functions, and any functions that are referenced
/// from this AST. In other words, any functions that are reachable from
/// the entry points.
class DiagnoseHLSLAvailability
    : public RecursiveASTVisitor<DiagnoseHLSLAvailability> {};

void DiagnoseHLSLAvailability::HandleFunctionOrMethodRef(FunctionDecl *FD,
                                                         Expr *RefExpr) {}

void DiagnoseHLSLAvailability::RunOnTranslationUnit(
    const TranslationUnitDecl *TU) {}

void DiagnoseHLSLAvailability::RunOnFunction(const FunctionDecl *FD) {}

bool DiagnoseHLSLAvailability::HasMatchingEnvironmentOrNone(
    const AvailabilityAttr *AA) {}

const AvailabilityAttr *
DiagnoseHLSLAvailability::FindAvailabilityAttr(const Decl *D) {}

// Check availability against target shader model version and current shader
// stage and emit diagnostic
void DiagnoseHLSLAvailability::CheckDeclAvailability(NamedDecl *D,
                                                     const AvailabilityAttr *AA,
                                                     SourceRange Range) {}

} // namespace

void SemaHLSL::DiagnoseAvailabilityViolations(TranslationUnitDecl *TU) {}

// Helper function for CheckHLSLBuiltinFunctionCall
bool CheckVectorElementCallArgs(Sema *S, CallExpr *TheCall) {}

bool CheckArgsTypesAreCorrect(
    Sema *S, CallExpr *TheCall, QualType ExpectedType,
    llvm::function_ref<bool(clang::QualType PassedType)> Check) {}

bool CheckAllArgsHaveFloatRepresentation(Sema *S, CallExpr *TheCall) {}

bool CheckFloatOrHalfRepresentations(Sema *S, CallExpr *TheCall) {}

bool CheckNoDoubleVectors(Sema *S, CallExpr *TheCall) {}

bool CheckUnsignedIntRepresentation(Sema *S, CallExpr *TheCall) {}

void SetElementTypeAsReturnType(Sema *S, CallExpr *TheCall,
                                QualType ReturnType) {}

// Note: returning true in this case results in CheckBuiltinFunctionCall
// returning an ExprError
bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {}

static void BuildFlattenedTypeList(QualType BaseTy,
                                   llvm::SmallVectorImpl<QualType> &List) {}

bool SemaHLSL::IsScalarizedLayoutCompatible(QualType T1, QualType T2) const {}

bool SemaHLSL::CheckCompatibleParameterABI(FunctionDecl *New,
                                           FunctionDecl *Old) {}

ExprResult SemaHLSL::ActOnOutParamExpr(ParmVarDecl *Param, Expr *Arg) {}

QualType SemaHLSL::getInoutParameterType(QualType Ty) {}