LLVM 20.0.0git
DXILResource.cpp
Go to the documentation of this file.
1//===- DXILResource.cpp - Representations of DXIL resources ---------------===//
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
10#include "llvm/ADT/APInt.h"
11#include "llvm/IR/Constants.h"
15#include "llvm/IR/Intrinsics.h"
16#include "llvm/IR/IntrinsicsDirectX.h"
17#include "llvm/IR/Metadata.h"
18#include "llvm/IR/Module.h"
20
21#define DEBUG_TYPE "dxil-resource"
22
23using namespace llvm;
24using namespace dxil;
25
27 switch (RC) {
28 case ResourceClass::SRV:
29 return "SRV";
30 case ResourceClass::UAV:
31 return "UAV";
32 case ResourceClass::CBuffer:
33 return "CBuffer";
34 case ResourceClass::Sampler:
35 return "Sampler";
36 }
37 llvm_unreachable("Unhandled ResourceClass");
38}
39
41 switch (RK) {
42 case ResourceKind::Texture1D:
43 return "Texture1D";
44 case ResourceKind::Texture2D:
45 return "Texture2D";
46 case ResourceKind::Texture2DMS:
47 return "Texture2DMS";
48 case ResourceKind::Texture3D:
49 return "Texture3D";
50 case ResourceKind::TextureCube:
51 return "TextureCube";
52 case ResourceKind::Texture1DArray:
53 return "Texture1DArray";
54 case ResourceKind::Texture2DArray:
55 return "Texture2DArray";
56 case ResourceKind::Texture2DMSArray:
57 return "Texture2DMSArray";
58 case ResourceKind::TextureCubeArray:
59 return "TextureCubeArray";
60 case ResourceKind::TypedBuffer:
61 return "TypedBuffer";
62 case ResourceKind::RawBuffer:
63 return "RawBuffer";
64 case ResourceKind::StructuredBuffer:
65 return "StructuredBuffer";
66 case ResourceKind::CBuffer:
67 return "CBuffer";
68 case ResourceKind::Sampler:
69 return "Sampler";
70 case ResourceKind::TBuffer:
71 return "TBuffer";
72 case ResourceKind::RTAccelerationStructure:
73 return "RTAccelerationStructure";
74 case ResourceKind::FeedbackTexture2D:
75 return "FeedbackTexture2D";
76 case ResourceKind::FeedbackTexture2DArray:
77 return "FeedbackTexture2DArray";
78 case ResourceKind::NumEntries:
79 case ResourceKind::Invalid:
80 return "<invalid>";
81 }
82 llvm_unreachable("Unhandled ResourceKind");
83}
84
86 switch (ET) {
87 case ElementType::I1:
88 return "i1";
89 case ElementType::I16:
90 return "i16";
91 case ElementType::U16:
92 return "u16";
93 case ElementType::I32:
94 return "i32";
95 case ElementType::U32:
96 return "u32";
97 case ElementType::I64:
98 return "i64";
99 case ElementType::U64:
100 return "u64";
101 case ElementType::F16:
102 return "f16";
103 case ElementType::F32:
104 return "f32";
105 case ElementType::F64:
106 return "f64";
107 case ElementType::SNormF16:
108 return "snorm_f16";
109 case ElementType::UNormF16:
110 return "unorm_f16";
111 case ElementType::SNormF32:
112 return "snorm_f32";
113 case ElementType::UNormF32:
114 return "unorm_f32";
115 case ElementType::SNormF64:
116 return "snorm_f64";
117 case ElementType::UNormF64:
118 return "unorm_f64";
119 case ElementType::PackedS8x32:
120 return "p32i8";
121 case ElementType::PackedU8x32:
122 return "p32u8";
123 case ElementType::Invalid:
124 return "<invalid>";
125 }
126 llvm_unreachable("Unhandled ElementType");
127}
128
130 switch (ST) {
131 case SamplerType::Default:
132 return "Default";
133 case SamplerType::Comparison:
134 return "Comparison";
135 case SamplerType::Mono:
136 return "Mono";
137 }
138 llvm_unreachable("Unhandled SamplerType");
139}
140
142 switch (SFT) {
143 case SamplerFeedbackType::MinMip:
144 return "MinMip";
145 case SamplerFeedbackType::MipRegionUsed:
146 return "MipRegionUsed";
147 }
148 llvm_unreachable("Unhandled SamplerFeedbackType");
149}
150
151bool ResourceInfo::isUAV() const { return RC == ResourceClass::UAV; }
152
154
156
158 return Kind == ResourceKind::StructuredBuffer;
159}
160
162 switch (Kind) {
173 return true;
182 return false;
185 llvm_unreachable("Invalid resource kind");
186 }
187 llvm_unreachable("Unhandled ResourceKind enum");
188}
189
191 return Kind == ResourceKind::FeedbackTexture2D ||
193}
194
196 return Kind == ResourceKind::Texture2DMS ||
198}
199
202 ResourceKind Kind) {
203 ResourceInfo RI(ResourceClass::SRV, Kind, Symbol, Name);
204 assert(RI.isTyped() && !(RI.isStruct() || RI.isMultiSample()) &&
205 "Invalid ResourceKind for SRV constructor.");
206 RI.setTyped(ElementTy, ElementCount);
207 return RI;
208}
209
212 return RI;
213}
214
216 uint32_t Stride,
217 MaybeAlign Alignment) {
219 Name);
220 RI.setStruct(Stride, Alignment);
221 return RI;
222}
223
225 ElementType ElementTy,
227 uint32_t SampleCount) {
229 RI.setTyped(ElementTy, ElementCount);
230 RI.setMultiSample(SampleCount);
231 return RI;
232}
233
235 ElementType ElementTy,
237 uint32_t SampleCount) {
239 Name);
240 RI.setTyped(ElementTy, ElementCount);
241 RI.setMultiSample(SampleCount);
242 return RI;
243}
244
247 bool GloballyCoherent, bool IsROV,
248 ResourceKind Kind) {
249 ResourceInfo RI(ResourceClass::UAV, Kind, Symbol, Name);
250 assert(RI.isTyped() && !(RI.isStruct() || RI.isMultiSample()) &&
251 "Invalid ResourceKind for UAV constructor.");
252 RI.setTyped(ElementTy, ElementCount);
253 RI.setUAV(GloballyCoherent, /*HasCounter=*/false, IsROV);
254 return RI;
255}
256
258 bool GloballyCoherent, bool IsROV) {
260 RI.setUAV(GloballyCoherent, /*HasCounter=*/false, IsROV);
261 return RI;
262}
263
265 uint32_t Stride,
266 MaybeAlign Alignment,
267 bool GloballyCoherent, bool IsROV,
268 bool HasCounter) {
270 Name);
271 RI.setStruct(Stride, Alignment);
272 RI.setUAV(GloballyCoherent, HasCounter, IsROV);
273 return RI;
274}
275
277 ElementType ElementTy,
279 uint32_t SampleCount,
280 bool GloballyCoherent) {
282 RI.setTyped(ElementTy, ElementCount);
283 RI.setUAV(GloballyCoherent, /*HasCounter=*/false, /*IsROV=*/false);
284 RI.setMultiSample(SampleCount);
285 return RI;
286}
287
289 ElementType ElementTy,
291 uint32_t SampleCount,
292 bool GloballyCoherent) {
294 Name);
295 RI.setTyped(ElementTy, ElementCount);
296 RI.setUAV(GloballyCoherent, /*HasCounter=*/false, /*IsROV=*/false);
297 RI.setMultiSample(SampleCount);
298 return RI;
299}
300
302 SamplerFeedbackType FeedbackTy) {
304 Name);
305 RI.setUAV(/*GloballyCoherent=*/false, /*HasCounter=*/false, /*IsROV=*/false);
306 RI.setFeedback(FeedbackTy);
307 return RI;
308}
309
312 SamplerFeedbackType FeedbackTy) {
314 Symbol, Name);
315 RI.setUAV(/*GloballyCoherent=*/false, /*HasCounter=*/false, /*IsROV=*/false);
316 RI.setFeedback(FeedbackTy);
317 return RI;
318}
319
321 uint32_t Size) {
323 RI.setCBuffer(Size);
324 return RI;
325}
326
328 SamplerType SamplerTy) {
331 return RI;
332}
333
335 if (std::tie(Symbol, Name, Binding, RC, Kind) !=
336 std::tie(RHS.Symbol, RHS.Name, RHS.Binding, RHS.RC, RHS.Kind))
337 return false;
338 if (isCBuffer())
339 return CBufferSize == RHS.CBufferSize;
340 if (isSampler())
341 return SamplerTy == RHS.SamplerTy;
342 if (isUAV() && UAVFlags != RHS.UAVFlags)
343 return false;
344
345 if (isStruct())
346 return Struct == RHS.Struct;
347 if (isFeedback())
348 return Feedback == RHS.Feedback;
349 if (isTyped() && Typed != RHS.Typed)
350 return false;
351
352 if (isMultiSample())
353 return MultiSample == RHS.MultiSample;
354
355 assert((Kind == ResourceKind::RawBuffer) && "Unhandled resource kind");
356 return true;
357}
358
361
362 Type *I32Ty = Type::getInt32Ty(Ctx);
363 Type *I1Ty = Type::getInt1Ty(Ctx);
364 auto getIntMD = [&I32Ty](uint32_t V) {
366 Constant::getIntegerValue(I32Ty, APInt(32, V)));
367 };
368 auto getBoolMD = [&I1Ty](uint32_t V) {
370 Constant::getIntegerValue(I1Ty, APInt(1, V)));
371 };
372
373 MDVals.push_back(getIntMD(Binding.RecordID));
374 MDVals.push_back(ValueAsMetadata::get(Symbol));
375 MDVals.push_back(MDString::get(Ctx, Name));
376 MDVals.push_back(getIntMD(Binding.Space));
377 MDVals.push_back(getIntMD(Binding.LowerBound));
378 MDVals.push_back(getIntMD(Binding.Size));
379
380 if (isCBuffer()) {
381 MDVals.push_back(getIntMD(CBufferSize));
382 MDVals.push_back(nullptr);
383 } else if (isSampler()) {
384 MDVals.push_back(getIntMD(llvm::to_underlying(SamplerTy)));
385 MDVals.push_back(nullptr);
386 } else {
387 MDVals.push_back(getIntMD(llvm::to_underlying(Kind)));
388
389 if (isUAV()) {
390 MDVals.push_back(getBoolMD(UAVFlags.GloballyCoherent));
391 MDVals.push_back(getBoolMD(UAVFlags.HasCounter));
392 MDVals.push_back(getBoolMD(UAVFlags.IsROV));
393 } else {
394 // All SRVs include sample count in the metadata, but it's only meaningful
395 // for multi-sampled textured. Also, UAVs can be multisampled in SM6.7+,
396 // but this just isn't reflected in the metadata at all.
397 uint32_t SampleCount = isMultiSample() ? MultiSample.Count : 0;
398 MDVals.push_back(getIntMD(SampleCount));
399 }
400
401 // Further properties are attached to a metadata list of tag-value pairs.
403 if (isStruct()) {
404 Tags.push_back(
406 Tags.push_back(getIntMD(Struct.Stride));
407 } else if (isTyped()) {
409 Tags.push_back(getIntMD(llvm::to_underlying(Typed.ElementTy)));
410 } else if (isFeedback()) {
411 Tags.push_back(
413 Tags.push_back(getIntMD(llvm::to_underlying(Feedback.Type)));
414 }
415 MDVals.push_back(Tags.empty() ? nullptr : MDNode::get(Ctx, Tags));
416 }
417
418 return MDNode::get(Ctx, MDVals);
419}
420
421std::pair<uint32_t, uint32_t> ResourceInfo::getAnnotateProps() const {
423 uint32_t AlignLog2 = isStruct() ? Struct.AlignLog2 : 0;
424 bool IsUAV = isUAV();
425 bool IsROV = IsUAV && UAVFlags.IsROV;
426 bool IsGloballyCoherent = IsUAV && UAVFlags.GloballyCoherent;
427 uint8_t SamplerCmpOrHasCounter = 0;
428 if (IsUAV)
429 SamplerCmpOrHasCounter = UAVFlags.HasCounter;
430 else if (isSampler())
431 SamplerCmpOrHasCounter = SamplerTy == SamplerType::Comparison;
432
433 // TODO: Document this format. Currently the only reference is the
434 // implementation of dxc's DxilResourceProperties struct.
435 uint32_t Word0 = 0;
436 Word0 |= ResourceKind & 0xFF;
437 Word0 |= (AlignLog2 & 0xF) << 8;
438 Word0 |= (IsUAV & 1) << 12;
439 Word0 |= (IsROV & 1) << 13;
440 Word0 |= (IsGloballyCoherent & 1) << 14;
441 Word0 |= (SamplerCmpOrHasCounter & 1) << 15;
442
443 uint32_t Word1 = 0;
444 if (isStruct())
445 Word1 = Struct.Stride;
446 else if (isCBuffer())
447 Word1 = CBufferSize;
448 else if (isFeedback())
449 Word1 = llvm::to_underlying(Feedback.Type);
450 else if (isTyped()) {
451 uint32_t CompType = llvm::to_underlying(Typed.ElementTy);
452 uint32_t CompCount = Typed.ElementCount;
453 uint32_t SampleCount = isMultiSample() ? MultiSample.Count : 0;
454
455 Word1 |= (CompType & 0xFF) << 0;
456 Word1 |= (CompCount & 0xFF) << 8;
457 Word1 |= (SampleCount & 0xFF) << 16;
458 }
459
460 return {Word0, Word1};
461}
462
464 OS << " Symbol: ";
465 Symbol->printAsOperand(OS);
466 OS << "\n";
467
468 OS << " Name: \"" << Name << "\"\n"
469 << " Binding:\n"
470 << " Record ID: " << Binding.RecordID << "\n"
471 << " Space: " << Binding.Space << "\n"
472 << " Lower Bound: " << Binding.LowerBound << "\n"
473 << " Size: " << Binding.Size << "\n"
474 << " Class: " << getResourceClassName(RC) << "\n"
475 << " Kind: " << getResourceKindName(Kind) << "\n";
476
477 if (isCBuffer()) {
478 OS << " CBuffer size: " << CBufferSize << "\n";
479 } else if (isSampler()) {
480 OS << " Sampler Type: " << getSamplerTypeName(SamplerTy) << "\n";
481 } else {
482 if (isUAV()) {
483 OS << " Globally Coherent: " << UAVFlags.GloballyCoherent << "\n"
484 << " HasCounter: " << UAVFlags.HasCounter << "\n"
485 << " IsROV: " << UAVFlags.IsROV << "\n";
486 }
487 if (isMultiSample())
488 OS << " Sample Count: " << MultiSample.Count << "\n";
489
490 if (isStruct()) {
491 OS << " Buffer Stride: " << Struct.Stride << "\n";
492 OS << " Alignment: " << Struct.AlignLog2 << "\n";
493 } else if (isTyped()) {
494 OS << " Element Type: " << getElementTypeName(Typed.ElementTy) << "\n"
495 << " Element Count: " << Typed.ElementCount << "\n";
496 } else if (isFeedback())
497 OS << " Feedback Type: " << getSamplerFeedbackTypeName(Feedback.Type)
498 << "\n";
499 }
500}
501
502//===----------------------------------------------------------------------===//
503// ResourceMapper
504
505static dxil::ElementType toDXILElementType(Type *Ty, bool IsSigned) {
506 // TODO: Handle unorm, snorm, and packed.
507 Ty = Ty->getScalarType();
508
509 if (Ty->isIntegerTy()) {
510 switch (Ty->getIntegerBitWidth()) {
511 case 16:
512 return IsSigned ? ElementType::I16 : ElementType::U16;
513 case 32:
514 return IsSigned ? ElementType::I32 : ElementType::U32;
515 case 64:
516 return IsSigned ? ElementType::I64 : ElementType::U64;
517 case 1:
518 default:
520 }
521 } else if (Ty->isFloatTy()) {
522 return ElementType::F32;
523 } else if (Ty->isDoubleTy()) {
524 return ElementType::F64;
525 } else if (Ty->isHalfTy()) {
526 return ElementType::F16;
527 }
528
530}
531
532namespace {
533
534class ResourceMapper {
535 Module &M;
536 LLVMContext &Context;
538
539 // In DXC, Record ID is unique per resource type. Match that.
540 uint32_t NextUAV = 0;
541 uint32_t NextSRV = 0;
542 uint32_t NextCBuf = 0;
543 uint32_t NextSmp = 0;
544
545public:
546 ResourceMapper(Module &M,
548 : M(M), Context(M.getContext()), Resources(Resources) {}
549
550 void diagnoseHandle(CallInst *CI, const Twine &Msg,
551 DiagnosticSeverity Severity = DS_Error) {
552 std::string S;
554 CI->printAsOperand(SS);
555 DiagnosticInfoUnsupported Diag(*CI->getFunction(), Msg + ": " + SS.str(),
556 CI->getDebugLoc(), Severity);
557 Context.diagnose(Diag);
558 }
559
560 ResourceInfo *mapBufferType(CallInst *CI, TargetExtType *HandleTy,
561 bool IsTyped) {
562 if (HandleTy->getNumTypeParameters() != 1 ||
563 HandleTy->getNumIntParameters() != (IsTyped ? 3 : 2)) {
564 diagnoseHandle(CI, Twine("Invalid buffer target type"));
565 return nullptr;
566 }
567
568 Type *ElTy = HandleTy->getTypeParameter(0);
569 unsigned IsWriteable = HandleTy->getIntParameter(0);
570 unsigned IsROV = HandleTy->getIntParameter(1);
571 bool IsSigned = IsTyped && HandleTy->getIntParameter(2);
572
573 ResourceClass RC = IsWriteable ? ResourceClass::UAV : ResourceClass::SRV;
575 if (IsTyped)
576 Kind = ResourceKind::TypedBuffer;
577 else if (ElTy->isIntegerTy(8))
578 Kind = ResourceKind::RawBuffer;
579 else
580 Kind = ResourceKind::StructuredBuffer;
581
582 // TODO: We need to lower to a typed pointer, can we smuggle the type
583 // through?
584 Value *Symbol = UndefValue::get(PointerType::getUnqual(Context));
585 // TODO: We don't actually keep track of the name right now...
586 StringRef Name = "";
587
588 auto [It, Success] = Resources.try_emplace(CI, RC, Kind, Symbol, Name);
589 assert(Success && "Mapping the same CallInst again?");
590 (void)Success;
591 // We grab a pointer into the map's storage, which isn't generally safe.
592 // Since we're just using this to fill in the info the map won't mutate and
593 // the pointer stays valid for as long as we need it to.
594 ResourceInfo *RI = &(It->second);
595
596 if (RI->isUAV())
597 // TODO: We need analysis for GloballyCoherent and HasCounter
598 RI->setUAV(false, false, IsROV);
599
600 if (RI->isTyped()) {
601 dxil::ElementType ET = toDXILElementType(ElTy, IsSigned);
602 uint32_t Count = 1;
603 if (auto *VTy = dyn_cast<FixedVectorType>(ElTy))
604 Count = VTy->getNumElements();
605 RI->setTyped(ET, Count);
606 } else if (RI->isStruct()) {
607 const DataLayout &DL = M.getDataLayout();
608
609 // This mimics what DXC does. Notably, we only ever set the alignment if
610 // the type is actually a struct type.
611 uint32_t Stride = DL.getTypeAllocSize(ElTy);
612 MaybeAlign Alignment;
613 if (auto *STy = dyn_cast<StructType>(ElTy))
614 Alignment = DL.getStructLayout(STy)->getAlignment();
615 RI->setStruct(Stride, Alignment);
616 }
617
618 return RI;
619 }
620
621 ResourceInfo *mapHandleIntrin(CallInst *CI) {
622 FunctionType *FTy = CI->getFunctionType();
623 Type *RetTy = FTy->getReturnType();
624 auto *HandleTy = dyn_cast<TargetExtType>(RetTy);
625 if (!HandleTy) {
626 diagnoseHandle(CI, "dx.handle.fromBinding requires target type");
627 return nullptr;
628 }
629
630 StringRef TypeName = HandleTy->getName();
631 if (TypeName == "dx.TypedBuffer") {
632 return mapBufferType(CI, HandleTy, /*IsTyped=*/true);
633 } else if (TypeName == "dx.RawBuffer") {
634 return mapBufferType(CI, HandleTy, /*IsTyped=*/false);
635 } else if (TypeName == "dx.CBuffer") {
636 // TODO: implement
637 diagnoseHandle(CI, "dx.CBuffer handles are not implemented yet");
638 return nullptr;
639 } else if (TypeName == "dx.Sampler") {
640 // TODO: implement
641 diagnoseHandle(CI, "dx.Sampler handles are not implemented yet");
642 return nullptr;
643 } else if (TypeName == "dx.Texture") {
644 // TODO: implement
645 diagnoseHandle(CI, "dx.Texture handles are not implemented yet");
646 return nullptr;
647 }
648
649 diagnoseHandle(CI, "Invalid target(dx) type");
650 return nullptr;
651 }
652
653 ResourceInfo *mapHandleFromBinding(CallInst *CI) {
654 assert(CI->getIntrinsicID() == Intrinsic::dx_handle_fromBinding &&
655 "Must be dx.handle.fromBinding intrinsic");
656
657 ResourceInfo *RI = mapHandleIntrin(CI);
658 if (!RI)
659 return nullptr;
660
661 uint32_t NextID;
662 if (RI->isCBuffer())
663 NextID = NextCBuf++;
664 else if (RI->isSampler())
665 NextID = NextSmp++;
666 else if (RI->isUAV())
667 NextID = NextUAV++;
668 else
669 NextID = NextSRV++;
670
671 uint32_t Space = cast<ConstantInt>(CI->getArgOperand(0))->getZExtValue();
672 uint32_t LowerBound =
673 cast<ConstantInt>(CI->getArgOperand(1))->getZExtValue();
674 uint32_t Size = cast<ConstantInt>(CI->getArgOperand(2))->getZExtValue();
675
676 RI->bind(NextID, Space, LowerBound, Size);
677
678 return RI;
679 }
680
681 void mapResources() {
682 for (Function &F : M.functions()) {
683 if (!F.isDeclaration())
684 continue;
685 LLVM_DEBUG(dbgs() << "Function: " << F.getName() << "\n");
686 Intrinsic::ID ID = F.getIntrinsicID();
687 switch (ID) {
688 default:
689 // TODO: handle `dx.op` functions.
690 continue;
691 case Intrinsic::dx_handle_fromBinding:
692 for (User *U : F.users()) {
693 LLVM_DEBUG(dbgs() << " Visiting: " << *U << "\n");
694 if (CallInst *CI = dyn_cast<CallInst>(U))
695 mapHandleFromBinding(CI);
696 }
697 break;
698 }
699 }
700 }
701};
702
703} // namespace
704
705//===----------------------------------------------------------------------===//
706// DXILResourceAnalysis and DXILResourcePrinterPass
707
708// Provide an explicit template instantiation for the static ID.
709AnalysisKey DXILResourceAnalysis::Key;
710
714 ResourceMapper(M, Data).mapResources();
715 return Data;
716}
717
722
723 for (const auto &[Handle, Info] : Data) {
724 OS << "Binding for ";
725 Handle->print(OS);
726 OS << "\n";
727 Info.print(OS);
728 OS << "\n";
729 }
730
731 return PreservedAnalyses::all();
732}
733
734//===----------------------------------------------------------------------===//
735// DXILResourceWrapperPass
736
739}
740
742
744 AU.setPreservesAll();
745}
746
748 ResourceMap.reset(new DXILResourceMap());
749 ResourceMapper(M, *ResourceMap).mapResources();
750 return false;
751}
752
753void DXILResourceWrapperPass::releaseMemory() { ResourceMap.reset(); }
754
756 if (!ResourceMap) {
757 OS << "No resource map has been built!\n";
758 return;
759 }
760 for (const auto &[Handle, Info] : *ResourceMap) {
761 OS << "Binding for ";
762 Handle->print(OS);
763 OS << "\n";
764 Info.print(OS);
765 OS << "\n";
766 }
767}
768
769#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
771void DXILResourceWrapperPass::dump() const { print(dbgs(), nullptr); }
772#endif
773
774INITIALIZE_PASS(DXILResourceWrapperPass, DEBUG_TYPE, "DXIL Resource analysis",
775 false, true)
777
779 return new DXILResourceWrapperPass();
780}
#define Success
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static dxil::ElementType toDXILElementType(Type *Ty, bool IsSigned)
static StringRef getResourceClassName(ResourceClass RC)
static StringRef getElementTypeName(ElementType ET)
static StringRef getResourceKindName(ResourceKind RK)
static StringRef getSamplerTypeName(SamplerType ST)
static StringRef getSamplerFeedbackTypeName(SamplerFeedbackType SFT)
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:533
This file contains the declarations for the subclasses of Constant, which represent the different fla...
return RetTy
#define LLVM_DEBUG(X)
Definition: Debug.h:101
std::string Name
uint64_t Size
#define DEBUG_TYPE
#define F(x, y, z)
Definition: MD5.cpp:55
This file contains the declarations for metadata subclasses.
Module.h This file contains the declarations for the Module class.
if(PassOpts->AAPipeline)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
Value * RHS
Class for arbitrary precision integers.
Definition: APInt.h:78
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:405
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1410
FunctionType * getFunctionType() const
Definition: InstrTypes.h:1323
Intrinsic::ID getIntrinsicID() const
Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...
This class represents a function call, abstracting a target machine's calling convention.
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:528
static Constant * getIntegerValue(Type *Ty, const APInt &V)
Return the value for an integer or pointer constant, or a vector thereof, with the given scalar value...
Definition: Constants.cpp:400
DXILResourceMap run(Module &M, ModuleAnalysisManager &AM)
Gather resource info for the module M.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
void print(raw_ostream &OS, const Module *M) const override
print - Print out the internal state of the pass.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
Diagnostic information for unsupported feature in backend.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Definition: Instruction.h:466
const Function * getFunction() const
Return the function this instruction belongs to.
Definition: Instruction.cpp:70
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1542
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:606
Tuple of metadata.
Definition: Metadata.h:1472
Align getAlignment() const
Return alignment of the basic block.
This class implements a map that also provides access to all stored values in a deterministic order.
Definition: MapVector.h:36
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:251
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:117
bool empty() const
Definition: SmallVector.h:94
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Class to represent target extensions types, which are generally unintrospectable from target-independ...
Definition: DerivedTypes.h:720
unsigned getNumIntParameters() const
Definition: DerivedTypes.h:765
Type * getTypeParameter(unsigned i) const
Definition: DerivedTypes.h:755
unsigned getNumTypeParameters() const
Definition: DerivedTypes.h:756
unsigned getIntParameter(unsigned i) const
Definition: DerivedTypes.h:764
StringRef getName() const
Return the name for this target extension type.
Definition: DerivedTypes.h:741
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
unsigned getIntegerBitWidth() const
static IntegerType * getInt1Ty(LLVMContext &C)
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition: Type.h:153
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
Definition: Type.h:142
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition: Type.h:156
static IntegerType * getInt32Ty(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:224
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition: Type.h:343
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1833
static ValueAsMetadata * get(Value *V)
Definition: Metadata.cpp:501
LLVM Value Representation.
Definition: Value.h:74
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
Definition: AsmWriter.cpp:5106
static ResourceInfo Texture2DMSArray(Value *Symbol, StringRef Name, dxil::ElementType ElementTy, uint32_t ElementCount, uint32_t SampleCount)
static ResourceInfo RawBuffer(Value *Symbol, StringRef Name)
void setUAV(bool GloballyCoherent, bool HasCounter, bool IsROV)
Definition: DXILResource.h:141
static ResourceInfo FeedbackTexture2D(Value *Symbol, StringRef Name, dxil::SamplerFeedbackType FeedbackTy)
static ResourceInfo Texture2DMS(Value *Symbol, StringRef Name, dxil::ElementType ElementTy, uint32_t ElementCount, uint32_t SampleCount)
static ResourceInfo RWTexture2DMS(Value *Symbol, StringRef Name, dxil::ElementType ElementTy, uint32_t ElementCount, uint32_t SampleCount, bool GloballyCoherent)
std::pair< uint32_t, uint32_t > getAnnotateProps() const
static ResourceInfo Sampler(Value *Symbol, StringRef Name, dxil::SamplerType SamplerTy)
void setCBuffer(uint32_t Size)
Definition: DXILResource.h:147
static ResourceInfo UAV(Value *Symbol, StringRef Name, dxil::ElementType ElementTy, uint32_t ElementCount, bool GloballyCoherent, bool IsROV, dxil::ResourceKind Kind)
void print(raw_ostream &OS) const
static ResourceInfo RWRawBuffer(Value *Symbol, StringRef Name, bool GloballyCoherent, bool IsROV)
dxil::SamplerType SamplerTy
Definition: DXILResource.h:108
static ResourceInfo SRV(Value *Symbol, StringRef Name, dxil::ElementType ElementTy, uint32_t ElementCount, dxil::ResourceKind Kind)
void setTyped(dxil::ElementType ElementTy, uint32_t ElementCount)
Definition: DXILResource.h:157
bool operator==(const ResourceInfo &RHS) const
void setMultiSample(uint32_t Count)
Definition: DXILResource.h:166
void setSampler(dxil::SamplerType Ty)
Definition: DXILResource.h:151
void setStruct(uint32_t Stride, MaybeAlign Alignment)
Definition: DXILResource.h:152
static ResourceInfo FeedbackTexture2DArray(Value *Symbol, StringRef Name, dxil::SamplerFeedbackType FeedbackTy)
static ResourceInfo RWTexture2DMSArray(Value *Symbol, StringRef Name, dxil::ElementType ElementTy, uint32_t ElementCount, uint32_t SampleCount, bool GloballyCoherent)
MDTuple * getAsMetadata(LLVMContext &Ctx) const
void setFeedback(dxil::SamplerFeedbackType Type)
Definition: DXILResource.h:162
void bind(uint32_t RecordID, uint32_t Space, uint32_t LowerBound, uint32_t Size)
Definition: DXILResource.h:134
static ResourceInfo StructuredBuffer(Value *Symbol, StringRef Name, uint32_t Stride, MaybeAlign Alignment)
static ResourceInfo CBuffer(Value *Symbol, StringRef Name, uint32_t Size)
static ResourceInfo RWStructuredBuffer(Value *Symbol, StringRef Name, uint32_t Stride, MaybeAlign Alignment, bool GloballyCoherent, bool IsROV, bool HasCounter)
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:661
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
@ SS
Definition: X86.h:211
ResourceKind
The kind of resource for an SRV or UAV resource.
Definition: DXILABI.h:34
ResourceClass
Definition: DXILABI.h:25
SamplerFeedbackType
Definition: DXILABI.h:94
ElementType
The element type of an SRV or UAV resource.
Definition: DXILABI.h:58
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void initializeDXILResourceWrapperPassPass(PassRegistry &)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
constexpr std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
ModulePass * createDXILResourceWrapperPassPass()
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
@ DS_Error
MapVector< CallInst *, dxil::ResourceInfo > DXILResourceMap
Definition: DXILResource.h:227
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:28
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117