@@ -146,7 +146,7 @@ HLSLNumThreadsAttr *SemaHLSL::mergeNumThreadsAttr(Decl *D,
146
146
147
147
HLSLShaderAttr *
148
148
SemaHLSL::mergeShaderAttr (Decl *D, const AttributeCommonInfo &AL,
149
- HLSLShaderAttr::ShaderType ShaderType) {
149
+ llvm::Triple::EnvironmentType ShaderType) {
150
150
if (HLSLShaderAttr *NT = D->getAttr <HLSLShaderAttr>()) {
151
151
if (NT->getType () != ShaderType) {
152
152
Diag (NT->getLocation (), diag::err_hlsl_attribute_param_mismatch) << AL;
@@ -184,25 +184,24 @@ void SemaHLSL::ActOnTopLevelFunction(FunctionDecl *FD) {
184
184
if (FD->getName () != TargetInfo.getTargetOpts ().HLSLEntry )
185
185
return ;
186
186
187
- StringRef Env = TargetInfo.getTriple ().getEnvironmentName ();
188
- HLSLShaderAttr::ShaderType ShaderType;
189
- if (HLSLShaderAttr::ConvertStrToShaderType (Env, ShaderType)) {
187
+ llvm::Triple::EnvironmentType Env = TargetInfo.getTriple ().getEnvironment ();
188
+ if (HLSLShaderAttr::isValidShaderType (Env) && Env != llvm::Triple::Library) {
190
189
if (const auto *Shader = FD->getAttr <HLSLShaderAttr>()) {
191
190
// The entry point is already annotated - check that it matches the
192
191
// triple.
193
- if (Shader->getType () != ShaderType ) {
192
+ if (Shader->getType () != Env ) {
194
193
Diag (Shader->getLocation (), diag::err_hlsl_entry_shader_attr_mismatch)
195
194
<< Shader;
196
195
FD->setInvalidDecl ();
197
196
}
198
197
} else {
199
198
// Implicitly add the shader attribute if the entry function isn't
200
199
// explicitly annotated.
201
- FD->addAttr (HLSLShaderAttr::CreateImplicit (getASTContext (), ShaderType ,
200
+ FD->addAttr (HLSLShaderAttr::CreateImplicit (getASTContext (), Env ,
202
201
FD->getBeginLoc ()));
203
202
}
204
203
} else {
205
- switch (TargetInfo. getTriple (). getEnvironment () ) {
204
+ switch (Env ) {
206
205
case llvm::Triple::UnknownEnvironment:
207
206
case llvm::Triple::Library:
208
207
break ;
@@ -215,38 +214,40 @@ void SemaHLSL::ActOnTopLevelFunction(FunctionDecl *FD) {
215
214
void SemaHLSL::CheckEntryPoint (FunctionDecl *FD) {
216
215
const auto *ShaderAttr = FD->getAttr <HLSLShaderAttr>();
217
216
assert (ShaderAttr && " Entry point has no shader attribute" );
218
- HLSLShaderAttr::ShaderType ST = ShaderAttr->getType ();
217
+ llvm::Triple::EnvironmentType ST = ShaderAttr->getType ();
219
218
220
219
switch (ST) {
221
- case HLSLShaderAttr ::Pixel:
222
- case HLSLShaderAttr ::Vertex:
223
- case HLSLShaderAttr ::Geometry:
224
- case HLSLShaderAttr ::Hull:
225
- case HLSLShaderAttr ::Domain:
226
- case HLSLShaderAttr ::RayGeneration:
227
- case HLSLShaderAttr ::Intersection:
228
- case HLSLShaderAttr ::AnyHit:
229
- case HLSLShaderAttr ::ClosestHit:
230
- case HLSLShaderAttr ::Miss:
231
- case HLSLShaderAttr ::Callable:
220
+ case llvm::Triple ::Pixel:
221
+ case llvm::Triple ::Vertex:
222
+ case llvm::Triple ::Geometry:
223
+ case llvm::Triple ::Hull:
224
+ case llvm::Triple ::Domain:
225
+ case llvm::Triple ::RayGeneration:
226
+ case llvm::Triple ::Intersection:
227
+ case llvm::Triple ::AnyHit:
228
+ case llvm::Triple ::ClosestHit:
229
+ case llvm::Triple ::Miss:
230
+ case llvm::Triple ::Callable:
232
231
if (const auto *NT = FD->getAttr <HLSLNumThreadsAttr>()) {
233
232
DiagnoseAttrStageMismatch (NT, ST,
234
- {HLSLShaderAttr ::Compute,
235
- HLSLShaderAttr ::Amplification,
236
- HLSLShaderAttr ::Mesh});
233
+ {llvm::Triple ::Compute,
234
+ llvm::Triple ::Amplification,
235
+ llvm::Triple ::Mesh});
237
236
FD->setInvalidDecl ();
238
237
}
239
238
break ;
240
239
241
- case HLSLShaderAttr ::Compute:
242
- case HLSLShaderAttr ::Amplification:
243
- case HLSLShaderAttr ::Mesh:
240
+ case llvm::Triple ::Compute:
241
+ case llvm::Triple ::Amplification:
242
+ case llvm::Triple ::Mesh:
244
243
if (!FD->hasAttr <HLSLNumThreadsAttr>()) {
245
244
Diag (FD->getLocation (), diag::err_hlsl_missing_numthreads)
246
- << HLSLShaderAttr::ConvertShaderTypeToStr (ST);
245
+ << llvm::Triple::getEnvironmentTypeName (ST);
247
246
FD->setInvalidDecl ();
248
247
}
249
248
break ;
249
+ default :
250
+ llvm_unreachable (" Unhandled environment in triple" );
250
251
}
251
252
252
253
for (ParmVarDecl *Param : FD->parameters ()) {
@@ -268,31 +269,31 @@ void SemaHLSL::CheckSemanticAnnotation(
268
269
const HLSLAnnotationAttr *AnnotationAttr) {
269
270
auto *ShaderAttr = EntryPoint->getAttr <HLSLShaderAttr>();
270
271
assert (ShaderAttr && " Entry point has no shader attribute" );
271
- HLSLShaderAttr::ShaderType ST = ShaderAttr->getType ();
272
+ llvm::Triple::EnvironmentType ST = ShaderAttr->getType ();
272
273
273
274
switch (AnnotationAttr->getKind ()) {
274
275
case attr::HLSLSV_DispatchThreadID:
275
276
case attr::HLSLSV_GroupIndex:
276
- if (ST == HLSLShaderAttr ::Compute)
277
+ if (ST == llvm::Triple ::Compute)
277
278
return ;
278
- DiagnoseAttrStageMismatch (AnnotationAttr, ST, {HLSLShaderAttr ::Compute});
279
+ DiagnoseAttrStageMismatch (AnnotationAttr, ST, {llvm::Triple ::Compute});
279
280
break ;
280
281
default :
281
282
llvm_unreachable (" Unknown HLSLAnnotationAttr" );
282
283
}
283
284
}
284
285
285
286
void SemaHLSL::DiagnoseAttrStageMismatch (
286
- const Attr *A, HLSLShaderAttr::ShaderType Stage,
287
- std::initializer_list<HLSLShaderAttr::ShaderType > AllowedStages) {
287
+ const Attr *A, llvm::Triple::EnvironmentType Stage,
288
+ std::initializer_list<llvm::Triple::EnvironmentType > AllowedStages) {
288
289
SmallVector<StringRef, 8 > StageStrings;
289
290
llvm::transform (AllowedStages, std::back_inserter (StageStrings),
290
- [](HLSLShaderAttr::ShaderType ST) {
291
+ [](llvm::Triple::EnvironmentType ST) {
291
292
return StringRef (
292
- HLSLShaderAttr::ConvertShaderTypeToStr (ST));
293
+ HLSLShaderAttr::ConvertEnvironmentTypeToStr (ST));
293
294
});
294
295
Diag (A->getLoc (), diag::err_hlsl_attr_unsupported_in_stage)
295
- << A << HLSLShaderAttr::ConvertShaderTypeToStr (Stage)
296
+ << A << llvm::Triple::getEnvironmentTypeName (Stage)
296
297
<< (AllowedStages.size () != 1 ) << join (StageStrings, " , " );
297
298
}
298
299
@@ -430,8 +431,8 @@ void SemaHLSL::handleShaderAttr(Decl *D, const ParsedAttr &AL) {
430
431
if (!SemaRef.checkStringLiteralArgumentAttr (AL, 0 , Str, &ArgLoc))
431
432
return ;
432
433
433
- HLSLShaderAttr::ShaderType ShaderType;
434
- if (!HLSLShaderAttr::ConvertStrToShaderType (Str, ShaderType)) {
434
+ llvm::Triple::EnvironmentType ShaderType;
435
+ if (!HLSLShaderAttr::ConvertStrToEnvironmentType (Str, ShaderType)) {
435
436
Diag (AL.getLoc (), diag::warn_attribute_type_not_supported)
436
437
<< AL << Str << ArgLoc;
437
438
return ;
@@ -549,16 +550,22 @@ class DiagnoseHLSLAvailability
549
550
//
550
551
// Maps FunctionDecl to an unsigned number that represents the set of shader
551
552
// environments the function has been scanned for.
552
- // Since HLSLShaderAttr::ShaderType enum is generated from Attr.td and is
553
- // defined without any assigned values, it is guaranteed to be numbered
554
- // sequentially from 0 up and we can use it to 'index' individual bits
555
- // in the set.
553
+ // The llvm::Triple::EnvironmentType enum values for shader stages guaranteed
554
+ // to be numbered from llvm::Triple::Pixel to llvm::Triple::Amplification
555
+ // (verified by static_asserts in Triple.cpp), we can use it to index
556
+ // individual bits in the set, as long as we shift the values to start with 0
557
+ // by subtracting the value of llvm::Triple::Pixel first.
558
+ //
556
559
// The N'th bit in the set will be set if the function has been scanned
557
- // in shader environment whose ShaderType integer value equals N.
560
+ // in shader environment whose llvm::Triple::EnvironmentType integer value
561
+ // equals (llvm::Triple::Pixel + N).
562
+ //
558
563
// For example, if a function has been scanned in compute and pixel stage
559
- // environment, the value will be 0x21 (100001 binary) because
560
- // (int)HLSLShaderAttr::ShaderType::Pixel == 1 and
561
- // (int)HLSLShaderAttr::ShaderType::Compute == 5.
564
+ // environment, the value will be 0x21 (100001 binary) because:
565
+ //
566
+ // (int)(llvm::Triple::Pixel - llvm::Triple::Pixel) == 0
567
+ // (int)(llvm::Triple::Compute - llvm::Triple::Pixel) == 5
568
+ //
562
569
// A FunctionDecl is mapped to 0 (or not included in the map) if it has not
563
570
// been scanned in any environment.
564
571
llvm::DenseMap<const FunctionDecl *, unsigned > ScannedDecls;
@@ -574,12 +581,16 @@ class DiagnoseHLSLAvailability
574
581
bool ReportOnlyShaderStageIssues;
575
582
576
583
// Helper methods for dealing with current stage context / environment
577
- void SetShaderStageContext (HLSLShaderAttr::ShaderType ShaderType) {
584
+ void SetShaderStageContext (llvm::Triple::EnvironmentType ShaderType) {
578
585
static_assert (sizeof (unsigned ) >= 4 );
579
- assert ((unsigned )ShaderType < 31 ); // 31 is reserved for "unknown"
580
-
581
- CurrentShaderEnvironment = HLSLShaderAttr::getTypeAsEnvironment (ShaderType);
582
- CurrentShaderStageBit = (1 << ShaderType);
586
+ assert (HLSLShaderAttr::isValidShaderType (ShaderType));
587
+ assert ((unsigned )(ShaderType - llvm::Triple::Pixel) < 31 &&
588
+ " ShaderType is too big for this bitmap" ); // 31 is reserved for
589
+ // "unknown"
590
+
591
+ unsigned bitmapIndex = ShaderType - llvm::Triple::Pixel;
592
+ CurrentShaderEnvironment = ShaderType;
593
+ CurrentShaderStageBit = (1 << bitmapIndex);
583
594
}
584
595
585
596
void SetUnknownShaderStageContext () {
0 commit comments