aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGHLSLRuntime.cpp
diff options
context:
space:
mode:
authorNathan Gauër <brioche@google.com>2025-09-09 19:42:28 +0200
committerGitHub <noreply@github.com>2025-09-09 17:42:28 +0000
commitd71df8283b0b1bc20565c1b35656c75e180eef61 (patch)
tree27827eaa89ad88b0a4ce3164a862e432f5752ed4 /clang/lib/CodeGen/CGHLSLRuntime.cpp
parentda6283a8b28608936f62f870d1b77b020aee9460 (diff)
downloadllvm-d71df8283b0b1bc20565c1b35656c75e180eef61.zip
llvm-d71df8283b0b1bc20565c1b35656c75e180eef61.tar.gz
llvm-d71df8283b0b1bc20565c1b35656c75e180eef61.tar.bz2
Revert "[HLSL] Rewrite semantics parsing" (#157718)
Reverts llvm/llvm-project#152537 Broke the build in some cases. Need to investigate more for a proper solution.
Diffstat (limited to 'clang/lib/CodeGen/CGHLSLRuntime.cpp')
-rw-r--r--clang/lib/CodeGen/CGHLSLRuntime.cpp72
1 files changed, 19 insertions, 53 deletions
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index afee119..4c8ece9 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -23,7 +23,6 @@
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/Type.h"
#include "clang/Basic/TargetOptions.h"
-#include "clang/Frontend/FrontendDiagnostic.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Frontend/HLSL/RootSignatureMetadata.h"
@@ -566,78 +565,47 @@ static llvm::Value *createSPIRVBuiltinLoad(IRBuilder<> &B, llvm::Module &M,
return B.CreateLoad(Ty, GV);
}
-llvm::Value *
-CGHLSLRuntime::emitSystemSemanticLoad(IRBuilder<> &B, llvm::Type *Type,
- const clang::DeclaratorDecl *Decl,
- SemanticInfo &ActiveSemantic) {
- if (isa<HLSLSV_GroupIndexAttr>(ActiveSemantic.Semantic)) {
+llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> &B,
+ const ParmVarDecl &D,
+ llvm::Type *Ty) {
+ assert(D.hasAttrs() && "Entry parameter missing annotation attribute!");
+ if (D.hasAttr<HLSLSV_GroupIndexAttr>()) {
llvm::Function *GroupIndex =
CGM.getIntrinsic(getFlattenedThreadIdInGroupIntrinsic());
return B.CreateCall(FunctionCallee(GroupIndex));
}
-
- if (isa<HLSLSV_DispatchThreadIDAttr>(ActiveSemantic.Semantic)) {
+ if (D.hasAttr<HLSLSV_DispatchThreadIDAttr>()) {
llvm::Intrinsic::ID IntrinID = getThreadIdIntrinsic();
llvm::Function *ThreadIDIntrinsic =
llvm::Intrinsic::isOverloaded(IntrinID)
? CGM.getIntrinsic(IntrinID, {CGM.Int32Ty})
: CGM.getIntrinsic(IntrinID);
- return buildVectorInput(B, ThreadIDIntrinsic, Type);
+ return buildVectorInput(B, ThreadIDIntrinsic, Ty);
}
-
- if (isa<HLSLSV_GroupThreadIDAttr>(ActiveSemantic.Semantic)) {
+ if (D.hasAttr<HLSLSV_GroupThreadIDAttr>()) {
llvm::Intrinsic::ID IntrinID = getGroupThreadIdIntrinsic();
llvm::Function *GroupThreadIDIntrinsic =
llvm::Intrinsic::isOverloaded(IntrinID)
? CGM.getIntrinsic(IntrinID, {CGM.Int32Ty})
: CGM.getIntrinsic(IntrinID);
- return buildVectorInput(B, GroupThreadIDIntrinsic, Type);
+ return buildVectorInput(B, GroupThreadIDIntrinsic, Ty);
}
-
- if (isa<HLSLSV_GroupIDAttr>(ActiveSemantic.Semantic)) {
+ if (D.hasAttr<HLSLSV_GroupIDAttr>()) {
llvm::Intrinsic::ID IntrinID = getGroupIdIntrinsic();
llvm::Function *GroupIDIntrinsic =
llvm::Intrinsic::isOverloaded(IntrinID)
? CGM.getIntrinsic(IntrinID, {CGM.Int32Ty})
: CGM.getIntrinsic(IntrinID);
- return buildVectorInput(B, GroupIDIntrinsic, Type);
- }
-
- if (HLSLSV_PositionAttr *S =
- dyn_cast<HLSLSV_PositionAttr>(ActiveSemantic.Semantic)) {
- if (CGM.getTriple().getEnvironment() == Triple::EnvironmentType::Pixel)
- return createSPIRVBuiltinLoad(B, CGM.getModule(), Type,
- S->getAttrName()->getName(),
- /* BuiltIn::FragCoord */ 15);
+ return buildVectorInput(B, GroupIDIntrinsic, Ty);
}
-
- llvm_unreachable("non-handled system semantic. FIXME.");
-}
-
-llvm::Value *
-CGHLSLRuntime::handleScalarSemanticLoad(IRBuilder<> &B, llvm::Type *Type,
- const clang::DeclaratorDecl *Decl,
- SemanticInfo &ActiveSemantic) {
-
- if (!ActiveSemantic.Semantic) {
- ActiveSemantic.Semantic = Decl->getAttr<HLSLSemanticAttr>();
- if (!ActiveSemantic.Semantic) {
- CGM.getDiags().Report(Decl->getInnerLocStart(),
- diag::err_hlsl_semantic_missing);
- return nullptr;
- }
- ActiveSemantic.Index = ActiveSemantic.Semantic->getSemanticIndex();
+ if (D.hasAttr<HLSLSV_PositionAttr>()) {
+ if (getArch() == llvm::Triple::spirv)
+ return createSPIRVBuiltinLoad(B, CGM.getModule(), Ty, "sv_position",
+ /* BuiltIn::Position */ 0);
+ llvm_unreachable("SV_Position semantic not implemented for this target.");
}
-
- return emitSystemSemanticLoad(B, Type, Decl, ActiveSemantic);
-}
-
-llvm::Value *
-CGHLSLRuntime::handleSemanticLoad(IRBuilder<> &B, llvm::Type *Type,
- const clang::DeclaratorDecl *Decl,
- SemanticInfo &ActiveSemantic) {
- assert(!Type->isStructTy());
- return handleScalarSemanticLoad(B, Type, Decl, ActiveSemantic);
+ assert(false && "Unhandled parameter attribute");
+ return nullptr;
}
void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
@@ -682,10 +650,8 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
Args.emplace_back(PoisonValue::get(Param.getType()));
continue;
}
-
const ParmVarDecl *PD = FD->getParamDecl(Param.getArgNo() - SRetOffset);
- SemanticInfo ActiveSemantic = {nullptr, 0};
- Args.push_back(handleSemanticLoad(B, Param.getType(), PD, ActiveSemantic));
+ Args.push_back(emitInputSemantic(B, *PD, Param.getType()));
}
CallInst *CI = B.CreateCall(FunctionCallee(Fn), Args, OB);