LLVM 24.0.0git
DXILResourceAccess.cpp
Go to the documentation of this file.
1//===- DXILResourceAccess.cpp - Resource access via load/store ------------===//
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 "DirectX.h"
11#include "llvm/ADT/DenseMap.h"
12#include "llvm/ADT/SetVector.h"
13#include "llvm/ADT/SmallSet.h"
17#include "llvm/IR/BasicBlock.h"
18#include "llvm/IR/Dominators.h"
19#include "llvm/IR/IRBuilder.h"
20#include "llvm/IR/Instruction.h"
23#include "llvm/IR/Intrinsics.h"
24#include "llvm/IR/IntrinsicsDirectX.h"
25#include "llvm/IR/LLVMContext.h"
26#include "llvm/IR/User.h"
27#include "llvm/IR/ValueHandle.h"
33#include <optional>
34
35#define DEBUG_TYPE "dxil-resource-access"
36
37using namespace llvm;
38
41 LLVMContext &Context = I->getContext();
42 std::string InstStr;
43 raw_string_ostream InstOS(InstStr);
44 I->print(InstOS);
45 Context.diagnose(
46 DiagnosticInfoGeneric("At resource access:" + Twine(InstStr), DS_Note));
47
48 for (auto *Handle : Handles) {
49 std::string HandleStr;
50 raw_string_ostream HandleOS(HandleStr);
51 Handle->print(HandleOS);
52 Context.diagnose(DiagnosticInfoGeneric(
53 "Uses resource handle:" + Twine(HandleStr), DS_Note));
54 }
55 Context.diagnose(DiagnosticInfoGeneric(
56 "Resource access is not guaranteed to map to a unique global resource"));
57}
58
60 Value *Ptr, uint64_t AccessSize) {
61 Value *Offset = nullptr;
62
63 while (Ptr) {
64 if (auto *II = dyn_cast<IntrinsicInst>(Ptr)) {
65 assert((II->getIntrinsicID() == Intrinsic::dx_resource_getpointer ||
66 II->getIntrinsicID() == Intrinsic::dx_resource_getbasepointer) &&
67 "Resource access through unexpected intrinsic");
68 return Offset ? Offset : ConstantInt::get(Builder.getInt32Ty(), 0);
69 }
70
72 assert(GEP && "Resource access through unexpected instruction");
73
74 unsigned NumIndices = GEP->getNumIndices();
75 uint64_t IndexScale = DL.getTypeAllocSize(GEP->getSourceElementType());
76 APInt ConstantOffset(DL.getIndexTypeSizeInBits(GEP->getType()), 0);
77 Value *GEPOffset;
78 if (GEP->accumulateConstantOffset(DL, ConstantOffset)) {
79 // We have a constant offset (in bytes).
80 GEPOffset =
81 ConstantInt::get(DL.getIndexType(GEP->getType()), ConstantOffset);
82 IndexScale = 1;
83 } else if (NumIndices == 1) {
84 // If we have a single index we're indexing into a top level array. This
85 // generally only happens with cbuffers.
86 GEPOffset = *GEP->idx_begin();
87 } else if (NumIndices == 2) {
88 // If we have two indices, this should be an access through a pointer.
89 auto *IndexIt = GEP->idx_begin();
90 assert(cast<ConstantInt>(IndexIt)->getZExtValue() == 0 &&
91 "GEP is not indexing through pointer");
92 GEPOffset = *(++IndexIt);
93 } else
94 llvm_unreachable("Unhandled GEP structure for resource access");
95
96 uint64_t ElemSize = AccessSize;
97 if (!(IndexScale % ElemSize)) {
98 // If our scale is an exact multiple of the access size, adjust the
99 // scaling to avoid an unnecessary division.
100 IndexScale /= ElemSize;
101 ElemSize = 1;
102 }
103 if (IndexScale != 1)
104 GEPOffset = Builder.CreateMul(
105 GEPOffset, ConstantInt::get(Builder.getInt32Ty(), IndexScale));
106 if (ElemSize != 1)
107 GEPOffset = Builder.CreateUDiv(
108 GEPOffset, ConstantInt::get(Builder.getInt32Ty(), ElemSize));
109
110 Offset = Offset ? Builder.CreateAdd(Offset, GEPOffset) : GEPOffset;
111 Ptr = GEP->getPointerOperand();
112 }
113
114 llvm_unreachable("GEP of null pointer?");
115}
116
119 const DataLayout &DL = SI->getDataLayout();
120 IRBuilder<> Builder(SI);
121 Type *ContainedType = RTI.getHandleTy()->getTypeParameter(0);
122 Type *ScalarType = ContainedType->getScalarType();
123 Type *LoadType = StructType::get(ContainedType, Builder.getInt1Ty());
124
125 Value *V = SI->getValueOperand();
126 if (V->getType() == ContainedType) {
127 // V is already the right type.
128 assert(SI->getPointerOperand() == II &&
129 "Store of whole element has mismatched address to store to");
130 } else if (V->getType() == ScalarType) {
131 // We're storing a scalar, so we need to load the current value and only
132 // replace the relevant part.
133 auto *Load = Builder.CreateIntrinsic(
134 LoadType, Intrinsic::dx_resource_load_typedbuffer,
135 {II->getOperand(0), II->getOperand(1)});
136 auto *Struct = Builder.CreateExtractValue(Load, {0});
137
138 uint64_t AccessSize = DL.getTypeSizeInBits(ScalarType) / 8;
139 Value *Offset =
140 traverseGEPOffsets(DL, Builder, SI->getPointerOperand(), AccessSize);
141 V = Builder.CreateInsertElement(Struct, V, Offset);
142 } else {
143 llvm_unreachable("Store to typed resource has invalid type");
144 }
145
146 auto *Inst = Builder.CreateIntrinsic(
147 Builder.getVoidTy(), Intrinsic::dx_resource_store_typedbuffer,
148 {II->getOperand(0), II->getOperand(1), V});
149 SI->replaceAllUsesWith(Inst);
150}
151
152/// Build a zero-initialized offset operand matching the shape of the given
153/// coordinate operand. Accesses through `operator[]` never have offsets.
154static Value *getNullOffsetsFor(IRBuilder<> &Builder, Value *Coords) {
155 Type *CoordTy = Coords->getType();
156 Type *OffsetTy;
157 if (auto *VecTy = dyn_cast<FixedVectorType>(CoordTy))
158 OffsetTy =
159 FixedVectorType::get(Builder.getInt32Ty(), VecTy->getNumElements());
160 else
161 OffsetTy = Builder.getInt32Ty();
162 return Constant::getNullValue(OffsetTy);
163}
164
167 const DataLayout &DL = SI->getDataLayout();
168 IRBuilder<> Builder(SI);
169 Type *ContainedType = RTI.getHandleTy()->getTypeParameter(0);
170 Type *ScalarType = ContainedType->getScalarType();
171
172 Value *Handle = II->getOperand(0);
173 Value *Coords = II->getOperand(1);
174
175 Value *V = SI->getValueOperand();
176 if (V->getType() == ContainedType) {
177 // V is already the right type.
178 assert(SI->getPointerOperand() == II &&
179 "Store of whole element has mismatched address to store to");
180 } else if (V->getType() == ScalarType) {
181 // We're storing a scalar, so we need to load the current value and only
182 // replace the relevant part. For operator[] the mip level and the offsets
183 // are always zero; DXILOpLowering drops the mip level for UAVs.
184 Value *MipLevel = Builder.getInt32(0);
185 Value *Offsets = getNullOffsetsFor(Builder, Coords);
186 auto *Load = Builder.CreateIntrinsic(ContainedType,
187 Intrinsic::dx_resource_load_level,
188 {Handle, Coords, MipLevel, Offsets});
189
190 uint64_t AccessSize = DL.getTypeSizeInBits(ScalarType) / 8;
191 Value *Offset =
192 traverseGEPOffsets(DL, Builder, SI->getPointerOperand(), AccessSize);
193 V = Builder.CreateInsertElement(Load, V, Offset);
194 } else {
195 llvm_unreachable("Store to texture resource has invalid type");
196 }
197
198 auto *Inst = Builder.CreateIntrinsic(Builder.getVoidTy(),
199 Intrinsic::dx_resource_store_texture,
200 {Handle, Coords, V});
201 SI->replaceAllUsesWith(Inst);
202}
203
204static void emitRawStore(IRBuilder<> &Builder, Value *Buffer, Value *Index,
206 // For raw buffer (ie, HLSL's ByteAddressBuffer), we need to fold the access
207 // entirely into the index.
208 if (!RTI.isStruct()) {
209 auto *ConstantOffset = dyn_cast<ConstantInt>(Offset);
210 if (!ConstantOffset || !ConstantOffset->isZero())
211 Index = Builder.CreateAdd(Index, Offset);
212 Offset = llvm::PoisonValue::get(Builder.getInt32Ty());
213 }
214
215 Builder.CreateIntrinsic(Builder.getVoidTy(),
216 Intrinsic::dx_resource_store_rawbuffer,
217 {Buffer, Index, Offset, V});
218}
219
222 const DataLayout &DL = SI->getDataLayout();
223 IRBuilder<> Builder(SI);
224
225 Value *V = SI->getValueOperand();
226 assert(!V->getType()->isAggregateType() &&
227 "Resource store should be scalar or vector type");
228
229 Value *Index = II->getOperand(1);
230 // The offset for the rawbuffer load and store ops is always in bytes.
231 uint64_t AccessSize = 1;
232 Value *Offset =
233 traverseGEPOffsets(DL, Builder, SI->getPointerOperand(), AccessSize);
234
235 auto *VT = dyn_cast<FixedVectorType>(V->getType());
236 if (VT && VT->getNumElements() > 4) {
237 // Split into stores of at most 4 elements.
238 Type *EltTy = VT->getElementType();
239 Value *Stride = ConstantInt::get(Builder.getInt32Ty(),
240 4 * (DL.getTypeSizeInBits(EltTy) / 8));
241
242 SmallVector<int, 4> Indices;
243 for (unsigned int I = 0, N = VT->getNumElements(); I < N; I += 4) {
244 if (I > 0)
245 Offset = Builder.CreateAdd(Offset, Stride);
246
247 for (unsigned int J = I, E = std::min(N, J + 4); J < E; ++J)
248 Indices.push_back(J);
249 Value *Part = Builder.CreateShuffleVector(V, Indices);
250 emitRawStore(Builder, II->getOperand(0), Index, Offset, Part, RTI);
251
252 Indices.clear();
253 }
254 } else
255 emitRawStore(Builder, II->getOperand(0), Index, Offset, V, RTI);
256}
257
291
292static std::optional<dxil::AtomicBinOpCode>
332
335 std::optional<dxil::AtomicBinOpCode> BinOpCode =
337 if (!BinOpCode) {
338 reportFatalUsageError("DXIL resource atomicrmw operation not implemented");
339 return;
340 }
341
342 const DataLayout &DL = AI->getDataLayout();
343 IRBuilder<> Builder(AI);
344 Value *Index = II->getOperand(1);
345
346 // The offset for the rawbuffer load/store/atomic ops is always in bytes.
347 uint64_t AccessSize = 1;
348 Value *Offset =
349 traverseGEPOffsets(DL, Builder, AI->getPointerOperand(), AccessSize);
350
351 // For non-struct buffers (RawBuffer or TypedBuffer), fold the byte offset
352 // into the index and mark the coord1 arg as poison — only StructuredBuffer
353 // atomics use both a struct index and a byte offset.
354 if (!RTI.isStruct()) {
355 auto *ConstantOffset = dyn_cast<ConstantInt>(Offset);
356 if (!ConstantOffset || !ConstantOffset->isZero())
357 Index = Builder.CreateAdd(Index, Offset);
358 Offset = llvm::PoisonValue::get(Builder.getInt32Ty());
359 }
360
361 Value *BinOp = Builder.getInt32(static_cast<uint32_t>(*BinOpCode));
362
363 // Emit the target-independent intrinsic; DXILOpLowering lowers it to the
364 // DXIL `AtomicBinOp` op and handles the target-ext-typed handle cast via
365 // its `createTmpHandleCast` bookkeeping.
366 Value *Result = Builder.CreateIntrinsic(
367 AI->getType(), Intrinsic::dx_resource_atomic_binop,
368 {II->getOperand(0), BinOp, Index, Offset, AI->getValOperand()});
369
370 AI->replaceAllUsesWith(Result);
371}
372
407
410 const DataLayout &DL = LI->getDataLayout();
411 IRBuilder<> Builder(LI);
412 Type *ContainedType = RTI.getHandleTy()->getTypeParameter(0);
413 Type *LoadType = StructType::get(ContainedType, Builder.getInt1Ty());
414
415 Value *V =
416 Builder.CreateIntrinsic(LoadType, Intrinsic::dx_resource_load_typedbuffer,
417 {II->getOperand(0), II->getOperand(1)});
418 V = Builder.CreateExtractValue(V, {0});
419
420 Type *ScalarType = ContainedType->getScalarType();
421 uint64_t AccessSize = DL.getTypeSizeInBits(ScalarType) / 8;
422 Value *Offset =
423 traverseGEPOffsets(DL, Builder, LI->getPointerOperand(), AccessSize);
424 auto *ConstantOffset = dyn_cast<ConstantInt>(Offset);
425 if (!ConstantOffset || !ConstantOffset->isZero())
426 V = Builder.CreateExtractElement(V, Offset);
427
428 // If we loaded a <1 x ...> instead of a scalar (presumably to feed a
429 // shufflevector), then make sure we're maintaining the resulting type.
430 if (auto *VT = dyn_cast<FixedVectorType>(LI->getType()))
431 if (VT->getNumElements() == 1 && !isa<FixedVectorType>(V->getType()))
432 V = Builder.CreateInsertElement(PoisonValue::get(VT), V,
433 Builder.getInt32(0));
434
435 LI->replaceAllUsesWith(V);
436}
437
440 const DataLayout &DL = LI->getDataLayout();
441 IRBuilder<> Builder(LI);
442 Type *ContainedType = RTI.getHandleTy()->getTypeParameter(0);
443
444 Value *Handle = II->getOperand(0);
445 Value *Coords = II->getOperand(1);
446
447 // For operator[], mip level is 0.
448 Value *MipLevel = Builder.getInt32(0);
449
450 // For operator[], offsets are zero.
451 Value *Offsets = getNullOffsetsFor(Builder, Coords);
452
453 Value *V =
454 Builder.CreateIntrinsic(ContainedType, Intrinsic::dx_resource_load_level,
455 {Handle, Coords, MipLevel, Offsets});
456
457 Type *ScalarType = ContainedType->getScalarType();
458 uint64_t AccessSize = DL.getTypeSizeInBits(ScalarType) / 8;
459 Value *Offset =
460 traverseGEPOffsets(DL, Builder, LI->getPointerOperand(), AccessSize);
461 auto *ConstantOffset = dyn_cast<ConstantInt>(Offset);
462 if (!ConstantOffset || !ConstantOffset->isZero())
463 V = Builder.CreateExtractElement(V, Offset);
464
465 // If we loaded a <1 x ...> instead of a scalar (presumably to feed a
466 // shufflevector), then make sure we're maintaining the resulting type.
467 if (auto *VT = dyn_cast<FixedVectorType>(LI->getType()))
468 if (VT->getNumElements() == 1 && !isa<FixedVectorType>(V->getType()))
469 V = Builder.CreateInsertElement(PoisonValue::get(VT), V,
470 Builder.getInt32(0));
471
472 LI->replaceAllUsesWith(V);
473}
474
475static Value *emitRawLoad(IRBuilder<> &Builder, Type *Ty, Value *Buffer,
476 Value *Index, Value *Offset,
478 // For raw buffer (ie, HLSL's ByteAddressBuffer), we need to fold the access
479 // entirely into the index.
480 if (!RTI.isStruct()) {
481 auto *ConstantOffset = dyn_cast<ConstantInt>(Offset);
482 if (!ConstantOffset || !ConstantOffset->isZero())
483 Index = Builder.CreateAdd(Index, Offset);
484 Offset = llvm::PoisonValue::get(Builder.getInt32Ty());
485 }
486
487 // The load intrinsic includes the bit for CheckAccessFullyMapped, so we need
488 // to add that to the return type.
489 Type *TypeWithCheck = StructType::get(Ty, Builder.getInt1Ty());
490 Value *V = Builder.CreateIntrinsic(TypeWithCheck,
491 Intrinsic::dx_resource_load_rawbuffer,
492 {Buffer, Index, Offset});
493 return Builder.CreateExtractValue(V, {0});
494}
495
498 const DataLayout &DL = LI->getDataLayout();
499 IRBuilder<> Builder(LI);
500
501 Value *Index = II->getOperand(1);
502 // The offset for the rawbuffer load and store ops is always in bytes.
503 uint64_t AccessSize = 1;
504 Value *Offset =
505 traverseGEPOffsets(DL, Builder, LI->getPointerOperand(), AccessSize);
506
507 // TODO: We could make this handle aggregates by walking the structure and
508 // handling each field individually, but we don't ever generate code that
509 // would hit that so it seems superfluous.
510 assert(!LI->getType()->isAggregateType() &&
511 "Resource load should be scalar or vector type");
512
513 Value *V;
514 if (auto *VT = dyn_cast<FixedVectorType>(LI->getType())) {
515 // Split into loads of at most 4 elements.
516 Type *EltTy = VT->getElementType();
517 Value *Stride = ConstantInt::get(Builder.getInt32Ty(),
518 4 * (DL.getTypeSizeInBits(EltTy) / 8));
519
521 for (unsigned int I = 0, N = VT->getNumElements(); I < N; I += 4) {
522 Type *Ty = FixedVectorType::get(EltTy, N - I < 4 ? N - I : 4);
523 if (I > 0)
524 Offset = Builder.CreateAdd(Offset, Stride);
525 Parts.push_back(
526 emitRawLoad(Builder, Ty, II->getOperand(0), Index, Offset, RTI));
527 }
528
529 V = Parts.size() > 1 ? concatenateVectors(Builder, Parts) : Parts[0];
530 } else
531 V = emitRawLoad(Builder, LI->getType(), II->getOperand(0), Index, Offset,
532 RTI);
533
534 LI->replaceAllUsesWith(V);
535}
536
537namespace {
538/// Helper for building a `load.cbufferrow` intrinsic given a simple type.
539struct CBufferRowIntrin {
540 Intrinsic::ID IID;
541 Type *RetTy;
542 unsigned int EltSize;
543 unsigned int NumElts;
544
545 CBufferRowIntrin(const DataLayout &DL, Type *Ty) {
546 assert(Ty == Ty->getScalarType() && "Expected scalar type");
547
548 switch (DL.getTypeSizeInBits(Ty)) {
549 case 16:
550 IID = Intrinsic::dx_resource_load_cbufferrow_8;
551 RetTy = StructType::get(Ty, Ty, Ty, Ty, Ty, Ty, Ty, Ty);
552 EltSize = 2;
553 NumElts = 8;
554 break;
555 case 32:
556 IID = Intrinsic::dx_resource_load_cbufferrow_4;
557 RetTy = StructType::get(Ty, Ty, Ty, Ty);
558 EltSize = 4;
559 NumElts = 4;
560 break;
561 case 64:
562 IID = Intrinsic::dx_resource_load_cbufferrow_2;
563 RetTy = StructType::get(Ty, Ty);
564 EltSize = 8;
565 NumElts = 2;
566 break;
567 default:
568 llvm_unreachable("Only 16, 32, and 64 bit types supported");
569 }
570 }
571};
572} // namespace
573
576 const DataLayout &DL = LI->getDataLayout();
577
578 Type *Ty = LI->getType();
579 assert(!isa<StructType>(Ty) && "Structs not handled yet");
580 CBufferRowIntrin Intrin(DL, Ty->getScalarType());
581
582 StringRef Name = LI->getName();
583 Value *Handle = II->getOperand(0);
584
585 IRBuilder<> Builder(LI);
586
587 ConstantInt *GlobalOffset =
588 II->getIntrinsicID() == Intrinsic::dx_resource_getbasepointer
589 ? ConstantInt::get(Builder.getInt32Ty(), 0)
590 : dyn_cast<ConstantInt>(II->getOperand(1));
591 assert(GlobalOffset && "CBuffer getpointer index must be constant");
592
593 uint64_t GlobalOffsetVal = GlobalOffset->getZExtValue();
594 Value *CurrentRow = ConstantInt::get(
595 Builder.getInt32Ty(), GlobalOffsetVal / hlsl::CBufferRowSizeInBytes);
596 unsigned int CurrentIndex =
597 (GlobalOffsetVal % hlsl::CBufferRowSizeInBytes) / Intrin.EltSize;
598
599 // Every object in a cbuffer either fits in a row or is aligned to a row. This
600 // means that only the very last pointer access can point into a row.
601 auto *LastGEP = dyn_cast<GEPOperator>(LI->getPointerOperand());
602 if (!LastGEP) {
603 // If we don't have a GEP at all we're just accessing the resource through
604 // the result of getpointer directly.
605 assert(LI->getPointerOperand() == II &&
606 "Unexpected indirect access to resource without GEP");
607 } else {
608 Value *GEPOffset = traverseGEPOffsets(
609 DL, Builder, LastGEP->getPointerOperand(), hlsl::CBufferRowSizeInBytes);
610 CurrentRow = Builder.CreateAdd(GEPOffset, CurrentRow);
611
612 APInt ConstantOffset(DL.getIndexTypeSizeInBits(LastGEP->getType()), 0);
613 if (LastGEP->accumulateConstantOffset(DL, ConstantOffset)) {
614 APInt Remainder(DL.getIndexTypeSizeInBits(LastGEP->getType()),
616 APInt::udivrem(ConstantOffset, Remainder, ConstantOffset, Remainder);
617 CurrentRow = Builder.CreateAdd(
618 CurrentRow, ConstantInt::get(Builder.getInt32Ty(), ConstantOffset));
619 CurrentIndex += Remainder.udiv(Intrin.EltSize).getZExtValue();
620 } else {
621 assert(LastGEP->getNumIndices() == 1 &&
622 "Last GEP of cbuffer access is not array or struct access");
623 // We assume a non-constant access will be row-aligned. This is safe
624 // because arrays and structs are always row aligned, and accesses to
625 // vector elements will show up as a load of the vector followed by an
626 // extractelement.
627 CurrentRow = cast<ConstantInt>(CurrentRow)->isZero()
628 ? *LastGEP->idx_begin()
629 : Builder.CreateAdd(CurrentRow, *LastGEP->idx_begin());
630 CurrentIndex = 0;
631 }
632 }
633
634 auto *CBufLoad = Builder.CreateIntrinsic(
635 Intrin.RetTy, Intrin.IID, {Handle, CurrentRow}, nullptr, Name + ".load");
636 auto *Elt =
637 Builder.CreateExtractValue(CBufLoad, {CurrentIndex++}, Name + ".extract");
638
639 // At this point we've loaded the first scalar of our result, but our original
640 // type may have been a vector.
641 unsigned int Remaining =
642 ((DL.getTypeSizeInBits(Ty) / 8) / Intrin.EltSize) - 1;
643 if (Remaining == 0) {
644 // We only have a single element, so we're done.
645 Value *Result = Elt;
646
647 // However, if we loaded a <1 x T>, then we need to adjust the type.
648 if (auto *VT = dyn_cast<FixedVectorType>(Ty)) {
649 assert(VT->getNumElements() == 1 && "Can't have multiple elements here");
650 Result = Builder.CreateInsertElement(PoisonValue::get(VT), Result,
651 Builder.getInt32(0), Name);
652 }
653 LI->replaceAllUsesWith(Result);
654 return;
655 }
656
657 // Walk each element and extract it, wrapping to new rows as needed.
658 SmallVector<Value *> Extracts{Elt};
659 while (Remaining--) {
660 CurrentIndex %= Intrin.NumElts;
661
662 if (CurrentIndex == 0) {
663 CurrentRow = Builder.CreateAdd(CurrentRow,
664 ConstantInt::get(Builder.getInt32Ty(), 1));
665 CBufLoad = Builder.CreateIntrinsic(Intrin.RetTy, Intrin.IID,
666 {Handle, CurrentRow}, nullptr,
667 Name + ".load");
668 }
669
670 Extracts.push_back(Builder.CreateExtractValue(CBufLoad, {CurrentIndex++},
671 Name + ".extract"));
672 }
673
674 // Finally, we build up the original loaded value.
675 Value *Result = PoisonValue::get(Ty);
676 for (int I = 0, E = Extracts.size(); I < E; ++I)
677 Result = Builder.CreateInsertElement(
678 Result, Extracts[I], Builder.getInt32(I), Name + formatv(".upto{}", I));
679 LI->replaceAllUsesWith(Result);
680}
681
715
717 if (auto *LI = dyn_cast<LoadInst>(AI))
718 return dyn_cast<Instruction>(LI->getPointerOperand());
719 if (auto *SI = dyn_cast<StoreInst>(AI))
720 return dyn_cast<Instruction>(SI->getPointerOperand());
721 if (auto *RMWI = dyn_cast<AtomicRMWInst>(AI))
722 return dyn_cast<Instruction>(RMWI->getPointerOperand());
723
724 return nullptr;
725}
726
727static const std::array<Intrinsic::ID, 2> HandleIntrins = {
728 Intrinsic::dx_resource_handlefrombinding,
729 Intrinsic::dx_resource_handlefromimplicitbinding,
730};
731
733 SmallVector<Value *> Worklist = {Ptr};
735 SmallSet<Value *, 4> VisitedPhis;
736
737 while (!Worklist.empty()) {
738 Value *X = Worklist.pop_back_val();
739
740 if (!X->getType()->isPointerTy() && !X->getType()->isTargetExtTy())
741 return {}; // Early exit on store/load into non-resource
742
743 if (auto *Phi = dyn_cast<PHINode>(X)) {
744 if (VisitedPhis.contains(X))
745 continue;
746 for (Use &V : Phi->incoming_values())
747 Worklist.push_back(V.get());
748 VisitedPhis.insert(Phi);
749 } else if (auto *Select = dyn_cast<SelectInst>(X))
750 for (Value *V : {Select->getTrueValue(), Select->getFalseValue()})
751 Worklist.push_back(V);
752 else if (auto *II = dyn_cast<IntrinsicInst>(X)) {
753 Intrinsic::ID IID = II->getIntrinsicID();
754
755 if (IID == Intrinsic::dx_resource_getpointer)
756 Worklist.push_back(II->getArgOperand(/*Handle=*/0));
757
759 Handles.push_back(II);
760 }
761 }
762
763 return Handles;
764}
765
767 DXILResourceTypeMap &DRTM) {
769 "Only expects a Handle as determined from collectUsedHandles.");
770
771 auto *HandleTy = cast<TargetExtType>(Handle->getType());
772 dxil::ResourceClass Class = DRTM[HandleTy].getResourceClass();
773 uint32_t Space = cast<ConstantInt>(Handle->getArgOperand(0))->getZExtValue();
774 uint32_t LowerBound =
775 cast<ConstantInt>(Handle->getArgOperand(1))->getZExtValue();
776 uint32_t Size = cast<ConstantInt>(Handle->getArgOperand(2))->getZExtValue();
777 uint32_t UpperBound = Size == UINT32_MAX ? UINT32_MAX : LowerBound + Size - 1;
778
779 return hlsl::Binding(Class, Space, LowerBound, UpperBound, nullptr);
780}
781
782namespace {
783/// Helper for propagating the current handle and ptr indices.
784struct AccessIndices {
785 Value *GetPtrIdx;
786 Value *HandleIdx;
787
788 bool hasGetPtrIdx() { return GetPtrIdx != nullptr; }
789 bool hasHandleIdx() { return HandleIdx != nullptr; }
790};
791} // namespace
792
793// getAccessIndices traverses up the control flow that a ptr came from and
794// propagates back the indicies used to access the resource (AccessIndices):
795//
796// - GetPtrIdx is the index of dx.resource.getpointer
797// - HandleIdx is the index of dx.resource.handlefrom.*
798static AccessIndices
801 if (auto *II = dyn_cast<IntrinsicInst>(I)) {
802 if (llvm::is_contained(HandleIntrins, II->getIntrinsicID())) {
803 DeadInsts.insert(II);
804 return {nullptr, II->getArgOperand(/*Index=*/3)};
805 }
806
807 if (II->getIntrinsicID() == Intrinsic::dx_resource_getpointer) {
808 auto *V = dyn_cast<Instruction>(II->getArgOperand(/*Handle=*/0));
809 auto AccessIdx = getAccessIndices(V, DeadInsts, VisitedPhis);
810 assert(!AccessIdx.hasGetPtrIdx() &&
811 "Encountered multiple dx.resource.getpointers in ptr chain?");
812 AccessIdx.GetPtrIdx = II->getArgOperand(1);
813
814 DeadInsts.insert(II);
815 return AccessIdx;
816 }
817 }
818
819 if (auto *Phi = dyn_cast<PHINode>(I)) {
820 // If we're already building indices for this phi, return a ref to the phi
821 if (auto It = VisitedPhis.find(Phi); It != VisitedPhis.end())
822 return {nullptr, It->second};
823
824 unsigned NumEdges = Phi->getNumIncomingValues();
825 assert(NumEdges != 0 && "Malformed Phi Node");
826
827 IRBuilder<> Builder(Phi);
828 PHINode *GetPtrPhi = PHINode::Create(Builder.getInt32Ty(), NumEdges);
829 PHINode *HandlePhi = PHINode::Create(Builder.getInt32Ty(), NumEdges);
830
831 // Register a ref to this phi for a recursive phi
832 if (Phi->getType()->isTargetExtTy())
833 VisitedPhis[Phi] = HandlePhi;
834
835 bool HasGetPtr = true;
836 for (unsigned Idx = 0; Idx < NumEdges; Idx++) {
837 auto *BB = Phi->getIncomingBlock(Idx);
838 auto *V = dyn_cast<Instruction>(Phi->getIncomingValue(Idx));
839 auto AccessIdx = getAccessIndices(V, DeadInsts, VisitedPhis);
840 HasGetPtr &= AccessIdx.hasGetPtrIdx();
841 if (HasGetPtr)
842 GetPtrPhi->addIncoming(AccessIdx.GetPtrIdx, BB);
843 HandlePhi->addIncoming(AccessIdx.HandleIdx, BB);
844 }
845
846 if (HasGetPtr)
847 Builder.Insert(GetPtrPhi);
848 else
849 GetPtrPhi = nullptr;
850
851 Builder.Insert(HandlePhi);
852
853 DeadInsts.insert(Phi);
854
855 Value *GetPtrIdx = GetPtrPhi;
856 Value *HandleIdx = HandlePhi;
857
858 if (GetPtrPhi)
859 if (Value *ConstantGetPtr = GetPtrPhi->hasConstantValue()) {
860 GetPtrIdx = ConstantGetPtr;
861 DeadInsts.insert(GetPtrPhi);
862 }
863
864 if (Value *ConstantHandle = HandlePhi->hasConstantValue()) {
865 HandleIdx = ConstantHandle;
866 DeadInsts.insert(HandlePhi);
867 }
868
869 return {GetPtrIdx, HandleIdx};
870 }
871
872 if (auto *Select = dyn_cast<SelectInst>(I)) {
873 auto *TrueV = dyn_cast<Instruction>(Select->getTrueValue());
874 auto TrueAccessIdx = getAccessIndices(TrueV, DeadInsts, VisitedPhis);
875
876 auto *FalseV = dyn_cast<Instruction>(Select->getFalseValue());
877 auto FalseAccessIdx = getAccessIndices(FalseV, DeadInsts, VisitedPhis);
878
879 IRBuilder<> Builder(Select);
880 Value *GetPtrSelect = nullptr;
881
882 if (TrueAccessIdx.hasGetPtrIdx() && FalseAccessIdx.hasGetPtrIdx())
883 GetPtrSelect =
884 Builder.CreateSelect(Select->getCondition(), TrueAccessIdx.GetPtrIdx,
885 FalseAccessIdx.GetPtrIdx);
886
887 auto *HandleSelect =
888 Builder.CreateSelect(Select->getCondition(), TrueAccessIdx.HandleIdx,
889 FalseAccessIdx.HandleIdx);
890 DeadInsts.insert(Select);
891 return {GetPtrSelect, HandleSelect};
892 }
893
894 llvm_unreachable("collectUsedHandles should assure this does not occur");
895}
896
897static void
901 auto AccessIdx = getAccessIndices(Ptr, DeadInsts, VisitedPhis);
902 assert(AccessIdx.hasGetPtrIdx() && AccessIdx.hasHandleIdx() &&
903 "Couldn't retrieve indices. This is guaranteed by getAccessIndices");
904
905 IRBuilder<> Builder(Ptr);
906 if (isa<PHINode>(Ptr))
907 Builder.SetInsertPoint(Ptr->getParent()->getFirstNonPHIIt());
908 IntrinsicInst *Handle = cast<IntrinsicInst>(OldHandle->clone());
909 Handle->setArgOperand(/*Index=*/3, AccessIdx.HandleIdx);
910 Builder.Insert(Handle);
911
912 auto *GetPtr =
913 Builder.CreateIntrinsic(Ptr->getType(), Intrinsic::dx_resource_getpointer,
914 {Handle, AccessIdx.GetPtrIdx});
915
916 Ptr->replaceAllUsesWith(GetPtr);
917 DeadInsts.insert(Ptr);
918}
919
920// Try to legalize dx.resource.handlefrom.*.binding and dx.resource.getpointer
921// calls with their respective index values and propagate the index values to
922// be used at resource access.
923//
924// If it can't be transformed to be legal then:
925//
926// Reports an error if a resource access is not guaranteed into a unique global
927// resource.
928//
929// Returns true if any changes are made.
933
934 for (BasicBlock &BB : make_early_inc_range(F)) {
935 for (Instruction &I : BB) {
936 if (auto *PtrOp = getStoreLoadPointerOperand(&I)) {
938 unsigned NumHandles = Handles.size();
939 if (NumHandles <= 1)
940 continue; // Legal, no-replacement required
941
942 bool SameGlobalBinding = true;
943 hlsl::Binding B = getHandleIntrinsicBinding(Handles[0], DRTM);
944 for (unsigned Idx = 1; Idx < NumHandles; Idx++)
945 SameGlobalBinding &=
946 (B == getHandleIntrinsicBinding(Handles[Idx], DRTM));
947
948 if (!SameGlobalBinding) {
950 continue;
951 }
952
953 replaceHandleWithIndices(PtrOp, Handles[0], DeadInsts, VisitedPhis);
954 }
955 }
956 }
957
958 bool MadeChanges = false;
959
960 // Set up the phis to track if they are erased below
961 SmallVector<WeakTrackingVH> ResourcePhis;
962 for (const auto &HandleToIndex : VisitedPhis)
963 ResourcePhis.push_back(HandleToIndex.first);
964
965 for (auto *I : llvm::reverse(DeadInsts))
966 if (I->hasNUses(0)) { // Handle can still be used outside of replaced path
967 I->eraseFromParent();
968 MadeChanges = true;
969 }
970
971 // Any remaining phi nodes are now looped with another phi node and have no
972 // other uses
973 for (WeakTrackingVH &VH : ResourcePhis)
974 if (VH) // True if not removed above or already in this loop
976
977 return MadeChanges;
978}
979
981 SmallVector<User *> Worklist;
982 for (User *U : II->users())
983 Worklist.push_back(U);
984
986 while (!Worklist.empty()) {
987 User *U = Worklist.back();
988 Worklist.pop_back();
989
990 if (auto *GEP = dyn_cast<GetElementPtrInst>(U)) {
991 for (User *U : GEP->users())
992 Worklist.push_back(U);
993 DeadInsts.push_back(GEP);
994
995 } else if (auto *SI = dyn_cast<StoreInst>(U)) {
996 assert(SI->getValueOperand() != II && "Pointer escaped!");
998 DeadInsts.push_back(SI);
999
1000 } else if (auto *LI = dyn_cast<LoadInst>(U)) {
1001 createLoadIntrinsic(II, LI, RTI);
1002 DeadInsts.push_back(LI);
1003 } else if (auto *AI = dyn_cast<AtomicRMWInst>(U)) {
1005 DeadInsts.push_back(AI);
1006 } else
1007 llvm_unreachable("Unhandled instruction - pointer escaped?");
1008 }
1009
1010 // Traverse the now-dead instructions in RPO and remove them.
1011 for (Instruction *Dead : llvm::reverse(DeadInsts))
1012 Dead->eraseFromParent();
1013 II->eraseFromParent();
1014}
1015
1018 for (BasicBlock &BB : make_early_inc_range(F))
1019 for (Instruction &I : BB)
1020 if (auto *II = dyn_cast<IntrinsicInst>(&I))
1021 if (II->getIntrinsicID() == Intrinsic::dx_resource_getpointer ||
1022 II->getIntrinsicID() == Intrinsic::dx_resource_getbasepointer) {
1023 auto *HandleTy = cast<TargetExtType>(II->getArgOperand(0)->getType());
1024 assert(
1025 (DRTM[HandleTy].isCBuffer() ||
1026 II->getIntrinsicID() != Intrinsic::dx_resource_getbasepointer) &&
1027 "dx_resource_getbasepointer should only be used by cbuffers");
1028 Resources.emplace_back(II, DRTM[HandleTy]);
1029 }
1030
1031 for (auto &[II, RI] : Resources)
1032 replaceAccess(II, RI);
1033
1034 return !Resources.empty();
1035}
1036
1039 auto &MAMProxy = FAM.getResult<ModuleAnalysisManagerFunctionProxy>(F);
1040 DXILResourceTypeMap *DRTM =
1041 MAMProxy.getCachedResult<DXILResourceTypeAnalysis>(*F.getParent());
1042 assert(DRTM && "DXILResourceTypeAnalysis must be available");
1043
1044 bool MadeHandleChanges = legalizeResourceHandles(F, *DRTM);
1045 bool MadeResourceChanges = transformResourcePointers(F, *DRTM);
1046 if (!(MadeHandleChanges || MadeResourceChanges))
1047 return PreservedAnalyses::all();
1048
1052 return PA;
1053}
1054
1055namespace {
1056class DXILResourceAccessLegacy : public FunctionPass {
1057public:
1058 bool runOnFunction(Function &F) override {
1059 DXILResourceTypeMap &DRTM =
1060 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
1061 bool MadeHandleChanges = legalizeResourceHandles(F, DRTM);
1062 bool MadeResourceChanges = transformResourcePointers(F, DRTM);
1063 return MadeHandleChanges || MadeResourceChanges;
1064 }
1065 StringRef getPassName() const override { return "DXIL Resource Access"; }
1066 DXILResourceAccessLegacy() : FunctionPass(ID) {}
1067
1068 static char ID; // Pass identification.
1069 void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {
1070 AU.addRequired<DXILResourceTypeWrapperPass>();
1071 AU.addPreserved<DominatorTreeWrapperPass>();
1072 }
1073};
1074char DXILResourceAccessLegacy::ID = 0;
1075} // end anonymous namespace
1076
1077INITIALIZE_PASS_BEGIN(DXILResourceAccessLegacy, DEBUG_TYPE,
1078 "DXIL Resource Access", false, false)
1080INITIALIZE_PASS_END(DXILResourceAccessLegacy, DEBUG_TYPE,
1081 "DXIL Resource Access", false, false)
1082
1084 return new DXILResourceAccessLegacy();
1085}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned uint64_t
AMDGPU Register Bank Select
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define X(NUM, ENUM, NAME)
Definition ELF.h:856
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
DXIL Remove Unused Resources
static void diagnoseNonUniqueResourceAccess(Instruction *I, ArrayRef< IntrinsicInst * > Handles)
static AccessIndices getAccessIndices(Instruction *I, SmallSetVector< Instruction *, 16 > &DeadInsts, SmallDenseMap< PHINode *, PHINode * > &VisitedPhis)
static std::optional< dxil::AtomicBinOpCode > getAtomicBinOpCode(AtomicRMWInst::BinOp BinOp)
static void createLoadIntrinsic(IntrinsicInst *II, LoadInst *LI, dxil::ResourceTypeInfo &RTI)
static void createTextureStore(IntrinsicInst *II, StoreInst *SI, dxil::ResourceTypeInfo &RTI)
static Value * emitRawLoad(IRBuilder<> &Builder, Type *Ty, Value *Buffer, Value *Index, Value *Offset, dxil::ResourceTypeInfo &RTI)
static bool legalizeResourceHandles(Function &F, DXILResourceTypeMap &DRTM)
static void createTypedBufferLoad(IntrinsicInst *II, LoadInst *LI, dxil::ResourceTypeInfo &RTI)
static void createTypedBufferStore(IntrinsicInst *II, StoreInst *SI, dxil::ResourceTypeInfo &RTI)
static SmallVector< IntrinsicInst * > collectUsedHandles(Value *Ptr)
static const std::array< Intrinsic::ID, 2 > HandleIntrins
static bool transformResourcePointers(Function &F, DXILResourceTypeMap &DRTM)
static void createTextureLoad(IntrinsicInst *II, LoadInst *LI, dxil::ResourceTypeInfo &RTI)
static void emitRawStore(IRBuilder<> &Builder, Value *Buffer, Value *Index, Value *Offset, Value *V, dxil::ResourceTypeInfo &RTI)
static Value * getNullOffsetsFor(IRBuilder<> &Builder, Value *Coords)
Build a zero-initialized offset operand matching the shape of the given coordinate operand.
static void replaceHandleWithIndices(Instruction *Ptr, IntrinsicInst *OldHandle, SmallSetVector< Instruction *, 16 > &DeadInsts, SmallDenseMap< PHINode *, PHINode * > &VisitedPhis)
static Value * traverseGEPOffsets(const DataLayout &DL, IRBuilder<> &Builder, Value *Ptr, uint64_t AccessSize)
static hlsl::Binding getHandleIntrinsicBinding(IntrinsicInst *Handle, DXILResourceTypeMap &DRTM)
static void createStoreIntrinsic(IntrinsicInst *II, StoreInst *SI, dxil::ResourceTypeInfo &RTI)
static void createCBufferLoad(IntrinsicInst *II, LoadInst *LI, dxil::ResourceTypeInfo &RTI)
static void createRawStores(IntrinsicInst *II, StoreInst *SI, dxil::ResourceTypeInfo &RTI)
static void createRawLoads(IntrinsicInst *II, LoadInst *LI, dxil::ResourceTypeInfo &RTI)
static void createAtomicBinOp(IntrinsicInst *II, AtomicRMWInst *AI, dxil::ResourceTypeInfo &RTI)
static Instruction * getStoreLoadPointerOperand(Instruction *AI)
static void createAtomicBinOpIntrinsic(IntrinsicInst *II, AtomicRMWInst *AI, dxil::ResourceTypeInfo &RTI)
static void replaceAccess(IntrinsicInst *II, dxil::ResourceTypeInfo &RTI)
This file defines the DenseMap class.
static bool runOnFunction(Function &F, bool PostInlining)
#define DEBUG_TYPE
Hexagon Common GEP
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
uint64_t IntrinsicInst * II
FunctionAnalysisManager FAM
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition PassSupport.h:42
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition PassSupport.h:44
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition PassSupport.h:39
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallSet class.
Class for arbitrary precision integers.
Definition APInt.h:78
LLVM_ABI APInt udiv(const APInt &RHS) const
Unsigned division operation.
Definition APInt.cpp:1600
static LLVM_ABI void udivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
Dual division/remainder interface.
Definition APInt.cpp:1794
uint64_t getZExtValue() const
Get zero extended value.
Definition APInt.h:1561
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
an instruction that atomically reads a memory location, combines it with another value,...
BinOp
This enumeration lists the possible modifications atomicrmw can make.
@ Add
*p = old + v
@ FAdd
*p = old + v
@ USubCond
Subtract only if no unsigned overflow.
@ FMinimum
*p = minimum(old, v) minimum matches the behavior of llvm.minimum.
@ Min
*p = old <signed v ? old : v
@ Sub
*p = old - v
@ And
*p = old & v
@ Xor
*p = old ^ v
@ USubSat
*p = usub.sat(old, v) usub.sat matches the behavior of llvm.usub.sat.
@ FMaximum
*p = maximum(old, v) maximum matches the behavior of llvm.maximum.
@ FSub
*p = old - v
@ UIncWrap
Increment one up to a maximum value.
@ Max
*p = old >signed v ? old : v
@ UMin
*p = old <unsigned v ? old : v
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
@ UMax
*p = old >unsigned v ? old : v
@ FMaximumNum
*p = maximumnum(old, v) maximumnum matches the behavior of llvm.maximumnum.
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
@ UDecWrap
Decrement one until a minimum value or zero.
@ FMinimumNum
*p = minimumnum(old, v) minimumnum matches the behavior of llvm.minimumnum.
@ Nand
*p = ~(old & v)
Value * getPointerOperand()
BinOp getOperation() const
LLVM Basic Block Representation.
Definition BasicBlock.h:62
Value * getArgOperand(unsigned i) const
void setArgOperand(unsigned i, Value *v)
This is the shared class of boolean and integer constants.
Definition Constants.h:87
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition Constants.h:168
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
iterator find(const_arg_type_t< KeyT > Val)
Definition DenseMap.h:223
iterator end()
Definition DenseMap.h:141
Analysis pass which computes a DominatorTree.
Definition Dominators.h:241
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition Type.cpp:867
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2893
LLVM_ABI Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following:
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this instruction belongs to.
A wrapper class for inspecting calls to intrinsic functions.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
An instruction for reading from memory.
Value * getPointerOperand()
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
LLVM_ABI Value * hasConstantValue() const
If the specified PHI node always merges together the same value, return the value,...
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses & preserve()
Mark an analysis as preserved.
Definition Analysis.h:132
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition SetVector.h:157
A SetVector that performs no allocations if smaller than a certain size.
Definition SetVector.h:345
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition SmallSet.h:134
bool contains(const T &V) const
Check if the SmallSet contains the given element.
Definition SmallSet.h:229
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition SmallSet.h:184
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition Type.cpp:477
Type * getTypeParameter(unsigned i) const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:309
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:368
bool isAggregateType() const
Return true if the type is an aggregate type.
Definition Type.h:319
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
Definition Type.cpp:306
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:255
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition Value.cpp:553
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:319
Value handle that is nullable, but tries to track the Value.
TargetExtType * getHandleTy() const
LLVM_ABI bool isStruct() const
dxil::ResourceKind getResourceKind() const
const ParentTy * getParent() const
Definition ilist_node.h:34
A raw_ostream that writes to an std::string.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const unsigned CBufferRowSizeInBytes
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:578
@ Dead
Unused definition.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
@ Load
The value being inserted comes from a load (InsertElement only).
OuterAnalysisManagerProxy< ModuleAnalysisManager, Function > ModuleAnalysisManagerFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition STLExtras.h:633
LLVM_ABI Value * concatenateVectors(IRBuilderBase &Builder, ArrayRef< Value * > Vecs)
Concatenate a list of vectors.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
auto reverse(ContainerTy &&C)
Definition STLExtras.h:407
FunctionPass * createDXILResourceAccessLegacyPass()
Pass to update resource accesses to use load/store directly.
LLVM_ABI bool RecursivelyDeleteDeadPHINode(PHINode *PN, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, SmallPtrSetImpl< PHINode * > *KnownNonDeadPHIs=nullptr)
If the specified value is an effectively dead PHI node, due to being a def-use chain of single-use no...
Definition Local.cpp:635
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1947
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:177
#define N