LLVM 23.0.0git
DXILOpLowering.cpp
Go to the documentation of this file.
1//===- DXILOpLowering.cpp - Lowering to DXIL operations -------------------===//
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
9#include "DXILOpLowering.h"
10#include "DXILConstants.h"
11#include "DXILOpBuilder.h"
12#include "DXILRootSignature.h"
13#include "DXILShaderFlags.h"
14#include "DirectX.h"
18#include "llvm/CodeGen/Passes.h"
19#include "llvm/IR/Constant.h"
21#include "llvm/IR/IRBuilder.h"
22#include "llvm/IR/Instruction.h"
24#include "llvm/IR/Intrinsics.h"
25#include "llvm/IR/IntrinsicsDirectX.h"
26#include "llvm/IR/Module.h"
27#include "llvm/IR/PassManager.h"
28#include "llvm/IR/Use.h"
30#include "llvm/Pass.h"
33
34#define DEBUG_TYPE "dxil-op-lower"
35
36using namespace llvm;
37using namespace llvm::dxil;
38
39namespace {
40class OpLowerer {
41 Module &M;
42 DXILOpBuilder OpBuilder;
43 DXILResourceMap &DRM;
45 const ModuleMetadataInfo &MMDI;
46 SmallVector<CallInst *> CleanupCasts;
47 Function *CleanupNURI = nullptr;
48
49public:
50 OpLowerer(Module &M, DXILResourceMap &DRM, DXILResourceTypeMap &DRTM,
51 const ModuleMetadataInfo &MMDI)
52 : M(M), OpBuilder(M), DRM(DRM), DRTM(DRTM), MMDI(MMDI) {}
53
54 /// Replace every call to \c F using \c ReplaceCall, and then erase \c F. If
55 /// there is an error replacing a call, we emit a diagnostic and return true.
56 [[nodiscard]] bool
57 replaceFunction(Function &F,
58 llvm::function_ref<Error(CallInst *CI)> ReplaceCall) {
59 for (User *U : make_early_inc_range(F.users())) {
61 if (!CI)
62 continue;
63
64 if (Error E = ReplaceCall(CI)) {
65 std::string Message(toString(std::move(E)));
66 M.getContext().diagnose(DiagnosticInfoUnsupported(
67 *CI->getFunction(), Message, CI->getDebugLoc()));
68
69 return true;
70 }
71 }
72 if (F.user_empty())
73 F.eraseFromParent();
74 return false;
75 }
76
77 struct IntrinArgSelect {
78 enum class Type {
79#define DXIL_OP_INTRINSIC_ARG_SELECT_TYPE(name) name,
80#include "DXILOperation.inc"
81 };
82 Type Type;
83 int Value;
84 };
85
86 /// Replaces uses of a struct with uses of an equivalent named struct.
87 ///
88 /// DXIL operations that return structs give them well known names, so we need
89 /// to update uses when we switch from an LLVM intrinsic to an op.
90 Error replaceNamedStructUses(CallInst *Intrin, CallInst *DXILOp) {
91 auto *IntrinTy = cast<StructType>(Intrin->getType());
92 auto *DXILOpTy = cast<StructType>(DXILOp->getType());
93 if (!IntrinTy->isLayoutIdentical(DXILOpTy))
95 "Type mismatch between intrinsic and DXIL op",
97
98 for (Use &U : make_early_inc_range(Intrin->uses()))
99 if (auto *EVI = dyn_cast<ExtractValueInst>(U.getUser()))
100 EVI->setOperand(0, DXILOp);
101 else if (auto *IVI = dyn_cast<InsertValueInst>(U.getUser()))
102 IVI->setOperand(0, DXILOp);
103 else
104 return make_error<StringError>("DXIL ops that return structs may only "
105 "be used by insert- and extractvalue",
107 return Error::success();
108 }
109
110 [[nodiscard]] bool
111 replaceFunctionWithOp(Function &F, dxil::OpCode DXILOp,
112 ArrayRef<IntrinArgSelect> ArgSelects) {
113 return replaceFunction(F, [&](CallInst *CI) -> Error {
114 OpBuilder.getIRB().SetInsertPoint(CI);
116 if (ArgSelects.size()) {
117 for (const IntrinArgSelect &A : ArgSelects) {
118 switch (A.Type) {
119 case IntrinArgSelect::Type::Index:
120 Args.push_back(CI->getArgOperand(A.Value));
121 break;
122 case IntrinArgSelect::Type::I8:
123 Args.push_back(OpBuilder.getIRB().getInt8((uint8_t)A.Value));
124 break;
125 case IntrinArgSelect::Type::I32:
126 Args.push_back(OpBuilder.getIRB().getInt32(A.Value));
127 break;
128 }
129 }
130 } else {
131 Args.append(CI->arg_begin(), CI->arg_end());
132 }
133
134 Expected<CallInst *> OpCall =
135 OpBuilder.tryCreateOp(DXILOp, Args, CI->getName(), F.getReturnType());
136 if (Error E = OpCall.takeError())
137 return E;
138
139 if (isa<StructType>(CI->getType())) {
140 if (Error E = replaceNamedStructUses(CI, *OpCall))
141 return E;
142 } else
143 CI->replaceAllUsesWith(*OpCall);
144
145 CI->eraseFromParent();
146 return Error::success();
147 });
148 }
149
150 /// Create a cast between a `target("dx")` type and `dx.types.Handle`, which
151 /// is intended to be removed by the end of lowering. This is used to allow
152 /// lowering of ops which need to change their return or argument types in a
153 /// piecemeal way - we can add the casts in to avoid updating all of the uses
154 /// or defs, and by the end all of the casts will be redundant.
155 Value *createTmpHandleCast(Value *V, Type *Ty) {
156 CallInst *Cast = OpBuilder.getIRB().CreateIntrinsic(
157 Intrinsic::dx_resource_casthandle, {Ty, V->getType()}, {V});
158 CleanupCasts.push_back(Cast);
159 return Cast;
160 }
161
162 void cleanupHandleCasts() {
165
166 for (CallInst *Cast : CleanupCasts) {
167 // These casts were only put in to ease the move from `target("dx")` types
168 // to `dx.types.Handle in a piecemeal way. At this point, all of the
169 // non-cast uses should now be `dx.types.Handle`, and remaining casts
170 // should all form pairs to and from the now unused `target("dx")` type.
171 CastFns.push_back(Cast->getCalledFunction());
172
173 // If the cast is not to `dx.types.Handle`, it should be the first part of
174 // the pair. Keep track so we can remove it once it has no more uses.
175 if (Cast->getType() != OpBuilder.getHandleType()) {
176 ToRemove.push_back(Cast);
177 continue;
178 }
179 // Otherwise, we're the second handle in a pair. Forward the arguments and
180 // remove the (second) cast.
181 CallInst *Def = cast<CallInst>(Cast->getOperand(0));
182 assert(Def->getIntrinsicID() == Intrinsic::dx_resource_casthandle &&
183 "Unbalanced pair of temporary handle casts");
184 Cast->replaceAllUsesWith(Def->getOperand(0));
185 Cast->eraseFromParent();
186 }
187 for (CallInst *Cast : ToRemove) {
188 assert(Cast->user_empty() && "Temporary handle cast still has users");
189 Cast->eraseFromParent();
190 }
191
192 // Deduplicate the cast functions so that we only erase each one once.
193 llvm::sort(CastFns);
194 CastFns.erase(llvm::unique(CastFns), CastFns.end());
195 for (Function *F : CastFns)
196 F->eraseFromParent();
197
198 CleanupCasts.clear();
199 }
200
201 void cleanupNonUniformResourceIndexCalls() {
202 // Replace all NonUniformResourceIndex calls with their argument.
203 if (!CleanupNURI)
204 return;
205 for (User *U : make_early_inc_range(CleanupNURI->users())) {
206 CallInst *CI = dyn_cast<CallInst>(U);
207 if (!CI)
208 continue;
210 CI->eraseFromParent();
211 }
212 CleanupNURI->eraseFromParent();
213 CleanupNURI = nullptr;
214 }
215
216 // Remove the resource global associated with the handleFromBinding call
217 // instruction and their uses as they aren't needed anymore.
218 // TODO: We should verify that all the globals get removed.
219 // It's expected we'll need a custom pass in the future that will eliminate
220 // the need for this here.
221 void removeResourceGlobals(CallInst *CI) {
222 for (User *User : make_early_inc_range(CI->users())) {
223 if (StoreInst *Store = dyn_cast<StoreInst>(User)) {
224 Value *V = Store->getOperand(1);
225 Store->eraseFromParent();
226 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
227 if (GV->use_empty()) {
228 GV->removeDeadConstantUsers();
229 GV->eraseFromParent();
230 }
231 }
232 }
233 }
234
235 void replaceHandleFromBindingCall(CallInst *CI, Value *Replacement) {
237 Intrinsic::dx_resource_handlefrombinding);
238
239 removeResourceGlobals(CI);
240
241 auto *NameGlobal = dyn_cast<llvm::GlobalVariable>(CI->getArgOperand(4));
242
243 CI->replaceAllUsesWith(Replacement);
244 CI->eraseFromParent();
245
246 if (NameGlobal && NameGlobal->use_empty())
247 NameGlobal->removeFromParent();
248 }
249
250 bool hasNonUniformIndex(Value *IndexOp) {
251 if (isa<llvm::Constant>(IndexOp))
252 return false;
253
254 SmallVector<Value *> WorkList;
255 WorkList.push_back(IndexOp);
256
257 while (!WorkList.empty()) {
258 Value *V = WorkList.pop_back_val();
259 if (auto *CI = dyn_cast<CallInst>(V)) {
260 if (CI->getCalledFunction()->getIntrinsicID() ==
261 Intrinsic::dx_resource_nonuniformindex)
262 return true;
263 }
264 if (auto *U = llvm::dyn_cast<llvm::User>(V)) {
265 for (llvm::Value *Op : U->operands()) {
267 continue;
268 WorkList.push_back(Op);
269 }
270 }
271 }
272 return false;
273 }
274
275 Error validateRawBufferElementIndex(Value *Resource, Value *ElementIndex) {
276 bool IsStructured =
277 cast<RawBufferExtType>(Resource->getType())->isStructured();
278 bool IsPoison = isa<PoisonValue>(ElementIndex);
279
280 if (IsStructured && IsPoison)
282 "Element index of structured buffer may not be poison",
284
285 if (!IsStructured && !IsPoison)
287 "Element index of raw buffer must be poison",
289
290 return Error::success();
291 }
292
293 [[nodiscard]] bool lowerToCreateHandle(Function &F) {
294 IRBuilder<> &IRB = OpBuilder.getIRB();
295 Type *Int8Ty = IRB.getInt8Ty();
296 Type *Int32Ty = IRB.getInt32Ty();
297 Type *Int1Ty = IRB.getInt1Ty();
298
299 return replaceFunction(F, [&](CallInst *CI) -> Error {
300 IRB.SetInsertPoint(CI);
301
302 auto *It = DRM.find(CI);
303 assert(It != DRM.end() && "Resource not in map?");
304 dxil::ResourceInfo &RI = *It;
305
306 const auto &Binding = RI.getBinding();
307 dxil::ResourceClass RC = DRTM[RI.getHandleTy()].getResourceClass();
308
309 Value *IndexOp = CI->getArgOperand(3);
310 if (Binding.LowerBound != 0)
311 IndexOp = IRB.CreateAdd(IndexOp,
312 ConstantInt::get(Int32Ty, Binding.LowerBound));
313
314 bool HasNonUniformIndex =
315 (Binding.Size == 1) ? false : hasNonUniformIndex(IndexOp);
316 std::array<Value *, 4> Args{
317 ConstantInt::get(Int8Ty, llvm::to_underlying(RC)),
318 ConstantInt::get(Int32Ty, Binding.RecordID), IndexOp,
319 ConstantInt::get(Int1Ty, HasNonUniformIndex)};
320 Expected<CallInst *> OpCall =
321 OpBuilder.tryCreateOp(OpCode::CreateHandle, Args, CI->getName());
322 if (Error E = OpCall.takeError())
323 return E;
324
325 Value *Cast = createTmpHandleCast(*OpCall, CI->getType());
326 replaceHandleFromBindingCall(CI, Cast);
327 return Error::success();
328 });
329 }
330
331 [[nodiscard]] bool lowerToBindAndAnnotateHandle(Function &F) {
332 IRBuilder<> &IRB = OpBuilder.getIRB();
333 Type *Int32Ty = IRB.getInt32Ty();
334 Type *Int1Ty = IRB.getInt1Ty();
335
336 return replaceFunction(F, [&](CallInst *CI) -> Error {
337 IRB.SetInsertPoint(CI);
338
339 auto *It = DRM.find(CI);
340 assert(It != DRM.end() && "Resource not in map?");
341 dxil::ResourceInfo &RI = *It;
342
343 const auto &Binding = RI.getBinding();
344 dxil::ResourceTypeInfo &RTI = DRTM[RI.getHandleTy()];
346
347 Value *IndexOp = CI->getArgOperand(3);
348 if (Binding.LowerBound != 0)
349 IndexOp = IRB.CreateAdd(IndexOp,
350 ConstantInt::get(Int32Ty, Binding.LowerBound));
351
352 std::pair<uint32_t, uint32_t> Props =
353 RI.getAnnotateProps(*F.getParent(), RTI);
354
355 // For `CreateHandleFromBinding` we need the upper bound rather than the
356 // size, so we need to be careful about the difference for "unbounded".
357 uint32_t UpperBound = Binding.Size == 0
358 ? std::numeric_limits<uint32_t>::max()
359 : Binding.LowerBound + Binding.Size - 1;
360 Constant *ResBind = OpBuilder.getResBind(Binding.LowerBound, UpperBound,
361 Binding.Space, RC);
362 bool NonUniformIndex =
363 (Binding.Size == 1) ? false : hasNonUniformIndex(IndexOp);
364 Constant *NonUniformOp = ConstantInt::get(Int1Ty, NonUniformIndex);
365 std::array<Value *, 3> BindArgs{ResBind, IndexOp, NonUniformOp};
366 Expected<CallInst *> OpBind = OpBuilder.tryCreateOp(
367 OpCode::CreateHandleFromBinding, BindArgs, CI->getName());
368 if (Error E = OpBind.takeError())
369 return E;
370
371 std::array<Value *, 2> AnnotateArgs{
372 *OpBind, OpBuilder.getResProps(Props.first, Props.second)};
373 Expected<CallInst *> OpAnnotate = OpBuilder.tryCreateOp(
374 OpCode::AnnotateHandle, AnnotateArgs,
375 CI->hasName() ? CI->getName() + "_annot" : Twine());
376 if (Error E = OpAnnotate.takeError())
377 return E;
378
379 Value *Cast = createTmpHandleCast(*OpAnnotate, CI->getType());
380 replaceHandleFromBindingCall(CI, Cast);
381 return Error::success();
382 });
383 }
384
385 /// Lower `dx.resource.handlefrombinding` intrinsics depending on the shader
386 /// model and taking into account binding information from
387 /// DXILResourceAnalysis.
388 bool lowerHandleFromBinding(Function &F) {
389 if (MMDI.DXILVersion < VersionTuple(1, 6))
390 return lowerToCreateHandle(F);
391 return lowerToBindAndAnnotateHandle(F);
392 }
393
394 /// Replace uses of \c Intrin with the values in the `dx.ResRet` of \c Op.
395 /// Since we expect to be post-scalarization, make an effort to avoid vectors.
396 Error replaceResRetUses(CallInst *Intrin, CallInst *Op, bool HasCheckBit) {
397 IRBuilder<> &IRB = OpBuilder.getIRB();
398
399 Instruction *OldResult = Intrin;
400 Type *OldTy = Intrin->getType();
401
402 if (HasCheckBit) {
403 auto *ST = cast<StructType>(OldTy);
404
405 Value *CheckOp = nullptr;
406 Type *Int32Ty = IRB.getInt32Ty();
407 for (Use &U : make_early_inc_range(OldResult->uses())) {
408 if (auto *EVI = dyn_cast<ExtractValueInst>(U.getUser())) {
409 ArrayRef<unsigned> Indices = EVI->getIndices();
410 assert(Indices.size() == 1);
411 // We're only interested in uses of the check bit for now.
412 if (Indices[0] != 1)
413 continue;
414 if (!CheckOp) {
415 Value *NewEVI = IRB.CreateExtractValue(Op, 4);
416 Expected<CallInst *> OpCall = OpBuilder.tryCreateOp(
417 OpCode::CheckAccessFullyMapped, {NewEVI},
418 OldResult->hasName() ? OldResult->getName() + "_check"
419 : Twine(),
420 Int32Ty);
421 if (Error E = OpCall.takeError())
422 return E;
423 CheckOp = *OpCall;
424 }
425 EVI->replaceAllUsesWith(CheckOp);
426 EVI->eraseFromParent();
427 }
428 }
429
430 if (OldResult->use_empty()) {
431 // Only the check bit was used, so we're done here.
432 OldResult->eraseFromParent();
433 return Error::success();
434 }
435
436 assert(OldResult->hasOneUse() &&
437 isa<ExtractValueInst>(*OldResult->user_begin()) &&
438 "Expected only use to be extract of first element");
439 OldResult = cast<Instruction>(*OldResult->user_begin());
440 OldTy = ST->getElementType(0);
441 }
442
443 // For scalars, we just extract the first element.
444 if (!isa<FixedVectorType>(OldTy)) {
445 Value *EVI = IRB.CreateExtractValue(Op, 0);
446 OldResult->replaceAllUsesWith(EVI);
447 OldResult->eraseFromParent();
448 if (OldResult != Intrin) {
449 assert(Intrin->use_empty() && "Intrinsic still has uses?");
450 Intrin->eraseFromParent();
451 }
452 return Error::success();
453 }
454
455 std::array<Value *, 4> Extracts = {};
456 SmallVector<ExtractElementInst *> DynamicAccesses;
457
458 // The users of the operation should all be scalarized, so we attempt to
459 // replace the extractelements with extractvalues directly.
460 for (Use &U : make_early_inc_range(OldResult->uses())) {
461 if (auto *EEI = dyn_cast<ExtractElementInst>(U.getUser())) {
462 if (auto *IndexOp = dyn_cast<ConstantInt>(EEI->getIndexOperand())) {
463 size_t IndexVal = IndexOp->getZExtValue();
464 assert(IndexVal < 4 && "Index into buffer load out of range");
465 if (!Extracts[IndexVal])
466 Extracts[IndexVal] = IRB.CreateExtractValue(Op, IndexVal);
467 EEI->replaceAllUsesWith(Extracts[IndexVal]);
468 EEI->eraseFromParent();
469 } else {
470 DynamicAccesses.push_back(EEI);
471 }
472 }
473 }
474
475 const auto *VecTy = cast<FixedVectorType>(OldTy);
476 const unsigned N = VecTy->getNumElements();
477
478 // If there's a dynamic access we need to round trip through stack memory so
479 // that we don't leave vectors around.
480 if (!DynamicAccesses.empty()) {
481 Type *Int32Ty = IRB.getInt32Ty();
482 Constant *Zero = ConstantInt::get(Int32Ty, 0);
483
484 Type *ElTy = VecTy->getElementType();
485 Type *ArrayTy = ArrayType::get(ElTy, N);
486 Value *Alloca = IRB.CreateAlloca(ArrayTy);
487
488 for (int I = 0, E = N; I != E; ++I) {
489 if (!Extracts[I])
490 Extracts[I] = IRB.CreateExtractValue(Op, I);
492 ArrayTy, Alloca, {Zero, ConstantInt::get(Int32Ty, I)});
493 IRB.CreateStore(Extracts[I], GEP);
494 }
495
496 for (ExtractElementInst *EEI : DynamicAccesses) {
497 Value *GEP = IRB.CreateInBoundsGEP(ArrayTy, Alloca,
498 {Zero, EEI->getIndexOperand()});
499 Value *Load = IRB.CreateLoad(ElTy, GEP);
500 EEI->replaceAllUsesWith(Load);
501 EEI->eraseFromParent();
502 }
503 }
504
505 // If we still have uses, then we're not fully scalarized and need to
506 // recreate the vector. This should only happen for things like exported
507 // functions from libraries.
508 if (!OldResult->use_empty()) {
509 for (int I = 0, E = N; I != E; ++I)
510 if (!Extracts[I])
511 Extracts[I] = IRB.CreateExtractValue(Op, I);
512
513 Value *Vec = PoisonValue::get(OldTy);
514 for (int I = 0, E = N; I != E; ++I)
515 Vec = IRB.CreateInsertElement(Vec, Extracts[I], I);
516 OldResult->replaceAllUsesWith(Vec);
517 }
518
519 OldResult->eraseFromParent();
520 if (OldResult != Intrin) {
521 assert(Intrin->use_empty() && "Intrinsic still has uses?");
522 Intrin->eraseFromParent();
523 }
524
525 return Error::success();
526 }
527
528 [[nodiscard]] bool lowerTypedBufferLoad(Function &F, bool HasCheckBit) {
529 IRBuilder<> &IRB = OpBuilder.getIRB();
530 Type *Int32Ty = IRB.getInt32Ty();
531
532 return replaceFunction(F, [&](CallInst *CI) -> Error {
533 IRB.SetInsertPoint(CI);
534
535 Value *Handle =
536 createTmpHandleCast(CI->getArgOperand(0), OpBuilder.getHandleType());
537 Value *Index0 = CI->getArgOperand(1);
538 Value *Index1 = UndefValue::get(Int32Ty);
539
540 Type *OldTy = CI->getType();
541 if (HasCheckBit)
542 OldTy = cast<StructType>(OldTy)->getElementType(0);
543 Type *NewRetTy = OpBuilder.getResRetType(OldTy->getScalarType());
544
545 std::array<Value *, 3> Args{Handle, Index0, Index1};
546 Expected<CallInst *> OpCall = OpBuilder.tryCreateOp(
547 OpCode::BufferLoad, Args, CI->getName(), NewRetTy);
548 if (Error E = OpCall.takeError())
549 return E;
550 if (Error E = replaceResRetUses(CI, *OpCall, HasCheckBit))
551 return E;
552
553 return Error::success();
554 });
555 }
556
557 [[nodiscard]] bool lowerRawBufferLoad(Function &F) {
558 const DataLayout &DL = F.getDataLayout();
559 IRBuilder<> &IRB = OpBuilder.getIRB();
560 Type *Int8Ty = IRB.getInt8Ty();
561 Type *Int32Ty = IRB.getInt32Ty();
562
563 return replaceFunction(F, [&](CallInst *CI) -> Error {
564 IRB.SetInsertPoint(CI);
565
566 Type *OldTy = cast<StructType>(CI->getType())->getElementType(0);
567 Type *ScalarTy = OldTy->getScalarType();
568 Type *NewRetTy = OpBuilder.getResRetType(ScalarTy);
569
570 Value *Handle =
571 createTmpHandleCast(CI->getArgOperand(0), OpBuilder.getHandleType());
572 Value *Index0 = CI->getArgOperand(1);
573 Value *Index1 = CI->getArgOperand(2);
574 uint64_t NumElements =
575 DL.getTypeSizeInBits(OldTy) / DL.getTypeSizeInBits(ScalarTy);
576 Value *Mask = ConstantInt::get(Int8Ty, ~(~0U << NumElements));
577 Value *Align =
578 ConstantInt::get(Int32Ty, DL.getPrefTypeAlign(ScalarTy).value());
579
580 if (Error E = validateRawBufferElementIndex(CI->getOperand(0), Index1))
581 return E;
582 if (isa<PoisonValue>(Index1))
583 Index1 = UndefValue::get(Index1->getType());
584
585 Expected<CallInst *> OpCall =
586 MMDI.DXILVersion >= VersionTuple(1, 2)
587 ? OpBuilder.tryCreateOp(OpCode::RawBufferLoad,
588 {Handle, Index0, Index1, Mask, Align},
589 CI->getName(), NewRetTy)
590 : OpBuilder.tryCreateOp(OpCode::BufferLoad,
591 {Handle, Index0, Index1}, CI->getName(),
592 NewRetTy);
593 if (Error E = OpCall.takeError())
594 return E;
595 if (Error E = replaceResRetUses(CI, *OpCall, /*HasCheckBit=*/true))
596 return E;
597
598 return Error::success();
599 });
600 }
601
602 [[nodiscard]] bool lowerCBufferLoad(Function &F) {
603 IRBuilder<> &IRB = OpBuilder.getIRB();
604
605 return replaceFunction(F, [&](CallInst *CI) -> Error {
606 IRB.SetInsertPoint(CI);
607
608 Type *OldTy = cast<StructType>(CI->getType())->getElementType(0);
609 Type *ScalarTy = OldTy->getScalarType();
610 Type *NewRetTy = OpBuilder.getCBufRetType(ScalarTy);
611
612 Value *Handle =
613 createTmpHandleCast(CI->getArgOperand(0), OpBuilder.getHandleType());
614 Value *Index = CI->getArgOperand(1);
615
616 Expected<CallInst *> OpCall = OpBuilder.tryCreateOp(
617 OpCode::CBufferLoadLegacy, {Handle, Index}, CI->getName(), NewRetTy);
618 if (Error E = OpCall.takeError())
619 return E;
620 if (Error E = replaceNamedStructUses(CI, *OpCall))
621 return E;
622
623 CI->eraseFromParent();
624 return Error::success();
625 });
626 }
627
628 [[nodiscard]] bool lowerUpdateCounter(Function &F) {
629 IRBuilder<> &IRB = OpBuilder.getIRB();
630 Type *Int32Ty = IRB.getInt32Ty();
631
632 return replaceFunction(F, [&](CallInst *CI) -> Error {
633 IRB.SetInsertPoint(CI);
634 Value *Handle =
635 createTmpHandleCast(CI->getArgOperand(0), OpBuilder.getHandleType());
636 Value *Op1 = CI->getArgOperand(1);
637
638 std::array<Value *, 2> Args{Handle, Op1};
639
640 Expected<CallInst *> OpCall = OpBuilder.tryCreateOp(
641 OpCode::UpdateCounter, Args, CI->getName(), Int32Ty);
642
643 if (Error E = OpCall.takeError())
644 return E;
645
646 CI->replaceAllUsesWith(*OpCall);
647 CI->eraseFromParent();
648 return Error::success();
649 });
650 }
651
652 [[nodiscard]] bool lowerGetDimensionsX(Function &F) {
653 IRBuilder<> &IRB = OpBuilder.getIRB();
654 Type *Int32Ty = IRB.getInt32Ty();
655
656 return replaceFunction(F, [&](CallInst *CI) -> Error {
657 IRB.SetInsertPoint(CI);
658 Value *Handle =
659 createTmpHandleCast(CI->getArgOperand(0), OpBuilder.getHandleType());
661
662 Expected<CallInst *> OpCall = OpBuilder.tryCreateOp(
663 OpCode::GetDimensions, {Handle, Undef}, CI->getName(), Int32Ty);
664 if (Error E = OpCall.takeError())
665 return E;
666 Value *Dim = IRB.CreateExtractValue(*OpCall, 0);
667
668 CI->replaceAllUsesWith(Dim);
669 CI->eraseFromParent();
670 return Error::success();
671 });
672 }
673
674 [[nodiscard]] bool lowerGetPointer(Function &F) {
675 // These should have already been handled in DXILResourceAccess, so we can
676 // just clean up the dead prototype.
677 assert(F.user_empty() && "getpointer operations should have been removed");
678 F.eraseFromParent();
679 return false;
680 }
681
682 [[nodiscard]] bool lowerBufferStore(Function &F, bool IsRaw) {
683 const DataLayout &DL = F.getDataLayout();
684 IRBuilder<> &IRB = OpBuilder.getIRB();
685 Type *Int8Ty = IRB.getInt8Ty();
686 Type *Int32Ty = IRB.getInt32Ty();
687
688 return replaceFunction(F, [&](CallInst *CI) -> Error {
689 IRB.SetInsertPoint(CI);
690
691 Value *Handle =
692 createTmpHandleCast(CI->getArgOperand(0), OpBuilder.getHandleType());
693 Value *Index0 = CI->getArgOperand(1);
694 Value *Index1 = IsRaw ? CI->getArgOperand(2) : UndefValue::get(Int32Ty);
695
696 if (IsRaw) {
697 if (Error E = validateRawBufferElementIndex(CI->getOperand(0), Index1))
698 return E;
699 if (isa<PoisonValue>(Index1))
700 Index1 = UndefValue::get(Index1->getType());
701 }
702
703 Value *Data = CI->getArgOperand(IsRaw ? 3 : 2);
704 Type *DataTy = Data->getType();
705 Type *ScalarTy = DataTy->getScalarType();
706
707 uint64_t NumElements =
708 DL.getTypeSizeInBits(DataTy) / DL.getTypeSizeInBits(ScalarTy);
709 Value *Mask =
710 ConstantInt::get(Int8Ty, IsRaw ? ~(~0U << NumElements) : 15U);
711
712 // TODO: check that we only have vector or scalar...
713 if (NumElements > 4)
715 "Buffer store data must have at most 4 elements",
717
718 std::array<Value *, 4> DataElements{nullptr, nullptr, nullptr, nullptr};
719 if (DataTy == ScalarTy)
720 DataElements[0] = Data;
721 else {
722 // Since we're post-scalarizer, if we see a vector here it's likely
723 // constructed solely for the argument of the store. Just use the scalar
724 // values from before they're inserted into the temporary.
726 while (IEI) {
727 auto *IndexOp = dyn_cast<ConstantInt>(IEI->getOperand(2));
728 if (!IndexOp)
729 break;
730 size_t IndexVal = IndexOp->getZExtValue();
731 assert(IndexVal < 4 && "Too many elements for buffer store");
732 DataElements[IndexVal] = IEI->getOperand(1);
733 IEI = dyn_cast<InsertElementInst>(IEI->getOperand(0));
734 }
735 }
736
737 // If for some reason we weren't able to forward the arguments from the
738 // scalarizer artifact, then we may need to actually extract elements from
739 // the vector.
740 for (int I = 0, E = NumElements; I < E; ++I)
741 if (DataElements[I] == nullptr)
742 DataElements[I] =
743 IRB.CreateExtractElement(Data, ConstantInt::get(Int32Ty, I));
744
745 // For any elements beyond the length of the vector, we should fill it up
746 // with undef - however, for typed buffers we repeat the first element to
747 // match DXC.
748 for (int I = NumElements, E = 4; I < E; ++I)
749 if (DataElements[I] == nullptr)
750 DataElements[I] = IsRaw ? UndefValue::get(ScalarTy) : DataElements[0];
751
752 dxil::OpCode Op = OpCode::BufferStore;
754 Handle, Index0, Index1, DataElements[0],
755 DataElements[1], DataElements[2], DataElements[3], Mask};
756 if (IsRaw && MMDI.DXILVersion >= VersionTuple(1, 2)) {
757 Op = OpCode::RawBufferStore;
758 // RawBufferStore requires the alignment
759 Args.push_back(
760 ConstantInt::get(Int32Ty, DL.getPrefTypeAlign(ScalarTy).value()));
761 }
762 Expected<CallInst *> OpCall =
763 OpBuilder.tryCreateOp(Op, Args, CI->getName());
764 if (Error E = OpCall.takeError())
765 return E;
766
767 CI->eraseFromParent();
768 // Clean up any leftover `insertelement`s
770 while (IEI && IEI->use_empty()) {
771 InsertElementInst *Tmp = IEI;
772 IEI = dyn_cast<InsertElementInst>(IEI->getOperand(0));
773 Tmp->eraseFromParent();
774 }
775
776 return Error::success();
777 });
778 }
779
780 [[nodiscard]] bool lowerCtpopToCountBits(Function &F) {
781 IRBuilder<> &IRB = OpBuilder.getIRB();
782 Type *Int32Ty = IRB.getInt32Ty();
783
784 return replaceFunction(F, [&](CallInst *CI) -> Error {
785 IRB.SetInsertPoint(CI);
787 Args.append(CI->arg_begin(), CI->arg_end());
788
789 Type *RetTy = Int32Ty;
790 Type *FRT = F.getReturnType();
791 if (const auto *VT = dyn_cast<VectorType>(FRT))
792 RetTy = VectorType::get(RetTy, VT);
793
794 Expected<CallInst *> OpCall = OpBuilder.tryCreateOp(
795 dxil::OpCode::CountBits, Args, CI->getName(), RetTy);
796 if (Error E = OpCall.takeError())
797 return E;
798
799 // If the result type is 32 bits we can do a direct replacement.
800 if (FRT->isIntOrIntVectorTy(32)) {
801 CI->replaceAllUsesWith(*OpCall);
802 CI->eraseFromParent();
803 return Error::success();
804 }
805
806 unsigned CastOp;
807 unsigned CastOp2;
808 if (FRT->isIntOrIntVectorTy(16)) {
809 CastOp = Instruction::ZExt;
810 CastOp2 = Instruction::SExt;
811 } else { // must be 64 bits
812 assert(FRT->isIntOrIntVectorTy(64) &&
813 "Currently only lowering 16, 32, or 64 bit ctpop to CountBits \
814 is supported.");
815 CastOp = Instruction::Trunc;
816 CastOp2 = Instruction::Trunc;
817 }
818
819 // It is correct to replace the ctpop with the dxil op and
820 // remove all casts to i32
821 bool NeedsCast = false;
822 for (User *User : make_early_inc_range(CI->users())) {
824 if (I && (I->getOpcode() == CastOp || I->getOpcode() == CastOp2) &&
825 I->getType() == RetTy) {
826 I->replaceAllUsesWith(*OpCall);
827 I->eraseFromParent();
828 } else
829 NeedsCast = true;
830 }
831
832 // It is correct to replace a ctpop with the dxil op and
833 // a cast from i32 to the return type of the ctpop
834 // the cast is emitted here if there is a non-cast to i32
835 // instr which uses the ctpop
836 if (NeedsCast) {
837 Value *Cast =
838 IRB.CreateZExtOrTrunc(*OpCall, F.getReturnType(), "ctpop.cast");
839 CI->replaceAllUsesWith(Cast);
840 }
841
842 CI->eraseFromParent();
843 return Error::success();
844 });
845 }
846
847 [[nodiscard]] bool lowerLifetimeIntrinsic(Function &F) {
848 IRBuilder<> &IRB = OpBuilder.getIRB();
849 return replaceFunction(F, [&](CallInst *CI) -> Error {
850 IRB.SetInsertPoint(CI);
851 Value *Ptr = CI->getArgOperand(0);
852 assert(Ptr->getType()->isPointerTy() &&
853 "Expected operand of lifetime intrinsic to be a pointer");
854
855 auto ZeroOrUndef = [&](Type *Ty) {
856 return MMDI.ValidatorVersion < VersionTuple(1, 6)
858 : UndefValue::get(Ty);
859 };
860
861 Value *Val = nullptr;
862 if (auto *GV = dyn_cast<GlobalVariable>(Ptr)) {
863 if (GV->hasInitializer() || GV->isExternallyInitialized())
864 return Error::success();
865 Val = ZeroOrUndef(GV->getValueType());
866 } else if (auto *AI = dyn_cast<AllocaInst>(Ptr))
867 Val = ZeroOrUndef(AI->getAllocatedType());
868
869 assert(Val && "Expected operand of lifetime intrinsic to be a global "
870 "variable or alloca instruction");
871 IRB.CreateStore(Val, Ptr, false);
872
873 CI->eraseFromParent();
874 return Error::success();
875 });
876 }
877
878 [[nodiscard]] bool lowerIsFPClass(Function &F) {
879 IRBuilder<> &IRB = OpBuilder.getIRB();
880 Type *RetTy = IRB.getInt1Ty();
881
882 return replaceFunction(F, [&](CallInst *CI) -> Error {
883 IRB.SetInsertPoint(CI);
885 Value *Fl = CI->getArgOperand(0);
886 Args.push_back(Fl);
887
889 Value *T = CI->getArgOperand(1);
890 auto *TCI = dyn_cast<ConstantInt>(T);
891 switch (TCI->getZExtValue()) {
892 case FPClassTest::fcInf:
893 OpCode = dxil::OpCode::IsInf;
894 break;
895 case FPClassTest::fcNan:
896 OpCode = dxil::OpCode::IsNaN;
897 break;
898 case FPClassTest::fcNormal:
899 OpCode = dxil::OpCode::IsNormal;
900 break;
901 case FPClassTest::fcFinite:
902 OpCode = dxil::OpCode::IsFinite;
903 break;
904 default:
905 SmallString<128> Msg =
906 formatv("Unsupported FPClassTest {0} for DXIL Op Lowering",
907 TCI->getZExtValue());
909 }
910
911 Expected<CallInst *> OpCall =
912 OpBuilder.tryCreateOp(OpCode, Args, CI->getName(), RetTy);
913 if (Error E = OpCall.takeError())
914 return E;
915
916 CI->replaceAllUsesWith(*OpCall);
917 CI->eraseFromParent();
918 return Error::success();
919 });
920 }
921
922 bool lowerIntrinsics() {
923 bool Updated = false;
924 bool HasErrors = false;
925
926 for (Function &F : make_early_inc_range(M.functions())) {
927 if (!F.isDeclaration())
928 continue;
929 Intrinsic::ID ID = F.getIntrinsicID();
930 switch (ID) {
931 // NOTE: Skip dx_resource_casthandle here. They are
932 // resolved after this loop in cleanupHandleCasts.
933 case Intrinsic::dx_resource_casthandle:
934 // NOTE: llvm.dbg.value is supported as is in DXIL.
935 case Intrinsic::dbg_value:
937 if (F.use_empty())
938 F.eraseFromParent();
939 continue;
940 default:
941 if (F.use_empty())
942 F.eraseFromParent();
943 else {
944 SmallString<128> Msg = formatv(
945 "Unsupported intrinsic {0} for DXIL lowering", F.getName());
946 M.getContext().emitError(Msg);
947 HasErrors |= true;
948 }
949 break;
950
951#define DXIL_OP_INTRINSIC(OpCode, Intrin, ...) \
952 case Intrin: \
953 HasErrors |= replaceFunctionWithOp( \
954 F, OpCode, ArrayRef<IntrinArgSelect>{__VA_ARGS__}); \
955 break;
956#include "DXILOperation.inc"
957 case Intrinsic::dx_resource_handlefrombinding:
958 HasErrors |= lowerHandleFromBinding(F);
959 break;
960 case Intrinsic::dx_resource_getpointer:
961 HasErrors |= lowerGetPointer(F);
962 break;
963 case Intrinsic::dx_resource_nonuniformindex:
964 assert(!CleanupNURI &&
965 "overloaded llvm.dx.resource.nonuniformindex intrinsics?");
966 CleanupNURI = &F;
967 break;
968 case Intrinsic::dx_resource_load_typedbuffer:
969 HasErrors |= lowerTypedBufferLoad(F, /*HasCheckBit=*/true);
970 break;
971 case Intrinsic::dx_resource_store_typedbuffer:
972 HasErrors |= lowerBufferStore(F, /*IsRaw=*/false);
973 break;
974 case Intrinsic::dx_resource_load_rawbuffer:
975 HasErrors |= lowerRawBufferLoad(F);
976 break;
977 case Intrinsic::dx_resource_store_rawbuffer:
978 HasErrors |= lowerBufferStore(F, /*IsRaw=*/true);
979 break;
980 case Intrinsic::dx_resource_load_cbufferrow_2:
981 case Intrinsic::dx_resource_load_cbufferrow_4:
982 case Intrinsic::dx_resource_load_cbufferrow_8:
983 HasErrors |= lowerCBufferLoad(F);
984 break;
985 case Intrinsic::dx_resource_updatecounter:
986 HasErrors |= lowerUpdateCounter(F);
987 break;
988 case Intrinsic::dx_resource_getdimensions_x:
989 HasErrors |= lowerGetDimensionsX(F);
990 break;
991 case Intrinsic::ctpop:
992 HasErrors |= lowerCtpopToCountBits(F);
993 break;
994 case Intrinsic::lifetime_start:
995 case Intrinsic::lifetime_end:
996 if (F.use_empty())
997 F.eraseFromParent();
998 else {
999 if (MMDI.DXILVersion < VersionTuple(1, 6))
1000 HasErrors |= lowerLifetimeIntrinsic(F);
1001 else
1002 continue;
1003 }
1004 break;
1005 case Intrinsic::is_fpclass:
1006 HasErrors |= lowerIsFPClass(F);
1007 break;
1008 }
1009 Updated = true;
1010 }
1011 if (Updated && !HasErrors) {
1012 cleanupHandleCasts();
1013 cleanupNonUniformResourceIndexCalls();
1014 }
1015
1016 return Updated;
1017 }
1018};
1019} // namespace
1020
1022 DXILResourceMap &DRM = MAM.getResult<DXILResourceAnalysis>(M);
1023 DXILResourceTypeMap &DRTM = MAM.getResult<DXILResourceTypeAnalysis>(M);
1024 const ModuleMetadataInfo MMDI = MAM.getResult<DXILMetadataAnalysis>(M);
1025
1026 const bool MadeChanges = OpLowerer(M, DRM, DRTM, MMDI).lowerIntrinsics();
1027 if (!MadeChanges)
1028 return PreservedAnalyses::all();
1034 return PA;
1035}
1036
1037namespace {
1038class DXILOpLoweringLegacy : public ModulePass {
1039public:
1040 bool runOnModule(Module &M) override {
1041 DXILResourceMap &DRM =
1042 getAnalysis<DXILResourceWrapperPass>().getResourceMap();
1043 DXILResourceTypeMap &DRTM =
1044 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
1045 const ModuleMetadataInfo MMDI =
1046 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
1047
1048 return OpLowerer(M, DRM, DRTM, MMDI).lowerIntrinsics();
1049 }
1050 StringRef getPassName() const override { return "DXIL Op Lowering"; }
1051 DXILOpLoweringLegacy() : ModulePass(ID) {}
1052
1053 static char ID; // Pass identification.
1054 void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {
1055 AU.addRequired<DXILResourceTypeWrapperPass>();
1056 AU.addRequired<DXILResourceWrapperPass>();
1057 AU.addRequired<DXILMetadataAnalysisWrapperPass>();
1058 AU.addPreserved<DXILResourceWrapperPass>();
1059 AU.addPreserved<DXILMetadataAnalysisWrapperPass>();
1060 AU.addPreserved<ShaderFlagsAnalysisWrapper>();
1061 AU.addPreserved<RootSignatureAnalysisWrapper>();
1062 }
1063};
1064char DXILOpLoweringLegacy::ID = 0;
1065} // end anonymous namespace
1066
1067INITIALIZE_PASS_BEGIN(DXILOpLoweringLegacy, DEBUG_TYPE, "DXIL Op Lowering",
1068 false, false)
1071INITIALIZE_PASS_END(DXILOpLoweringLegacy, DEBUG_TYPE, "DXIL Op Lowering", false,
1072 false)
1073
1075 return new DXILOpLoweringLegacy();
1076}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
ReachingDefInfo InstSet & ToRemove
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
DXIL Resource Implicit Binding
#define DEBUG_TYPE
Hexagon Common GEP
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
This defines the Use class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define T
ModuleAnalysisManager MAM
if(PassOpts->AAPipeline)
#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 defines the SmallVector class.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
size_t size() const
size - Get the array size.
Definition ArrayRef.h:142
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
Value * getArgOperand(unsigned i) const
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
This class represents a function call, abstracting a target machine's calling convention.
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
Diagnostic information for unsupported feature in backend.
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Error takeError()
Take ownership of the stored error.
Definition Error.h:612
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Definition Function.h:246
Value * CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx, const Twine &Name="")
Definition IRBuilder.h:2584
AllocaInst * CreateAlloca(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="")
Definition IRBuilder.h:1860
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
Definition IRBuilder.h:564
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
Definition IRBuilder.h:2572
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
Definition IRBuilder.h:2095
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
Definition IRBuilder.h:2631
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
Definition IRBuilder.h:579
Value * CreateInBoundsGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
Definition IRBuilder.h:1975
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
Definition IRBuilder.h:1877
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition IRBuilder.h:1890
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1429
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
Definition IRBuilder.h:207
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
Definition IRBuilder.h:569
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition Pass.h:255
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
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
iterator erase(const_iterator CI)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition Type.h:263
bool isPointerTy() const
True if this is an instance of PointerType.
Definition Type.h:284
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:370
static LLVM_ABI UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Value * getOperand(unsigned i) const
Definition User.h:207
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
user_iterator user_begin()
Definition Value.h:403
bool hasOneUse() const
Return true if there is exactly one use of this value.
Definition Value.h:440
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition Value.cpp:553
iterator_range< user_iterator > users()
Definition Value.h:427
bool use_empty() const
Definition Value.h:347
iterator_range< use_iterator > uses()
Definition Value.h:381
bool hasName() const
Definition Value.h:262
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:322
bool user_empty() const
Definition Value.h:390
TargetExtType * getHandleTy() const
LLVM_ABI std::pair< uint32_t, uint32_t > getAnnotateProps(Module &M, dxil::ResourceTypeInfo &RTI) const
const ResourceBinding & getBinding() const
dxil::ResourceClass getResourceClass() const
An efficient, type-erasing, non-owning reference to a callable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
NodeAddr< DefNode * > Def
Definition RDFGraph.h:384
NodeAddr< UseNode * > Use
Definition RDFGraph.h:385
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
@ Undef
Value of the register doesn't matter.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
FunctionAddr VTableAddr uintptr_t uintptr_t Int32Ty
Definition InstrProf.h:296
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition Error.cpp:94
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:634
auto unique(Range &&R, Predicate P)
Definition STLExtras.h:2134
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1636
constexpr std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
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
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:189
IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *, ArrayRef< OperandBundleDef >) -> IRBuilder< FolderTy, InserterTy >
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
ModulePass * createDXILOpLoweringLegacyPass()
Pass to lowering LLVM intrinsic call to DXIL op function call.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
#define N