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 *, 16> Worklist;
255 SmallPtrSet<Value *, 16> Visited;
256 Worklist.push_back(IndexOp);
257
258 while (!Worklist.empty()) {
259 Value *V = Worklist.pop_back_val();
260
261 if (isa<llvm::Constant>(V))
262 continue;
263
264 if (!Visited.insert(V).second)
265 continue;
266
267 if (auto *CI = dyn_cast<CallInst>(V))
268 if (CI->getIntrinsicID() == Intrinsic::dx_resource_nonuniformindex)
269 return true;
270
271 // If it's a PHI node, check ALL incoming values —
272 // taint from ANY predecessor counts
273 if (auto *Phi = dyn_cast<PHINode>(V)) {
274 for (Value *Incoming : Phi->incoming_values())
275 Worklist.push_back(Incoming);
276 continue;
277 }
278
279 if (auto *Inst = dyn_cast<Instruction>(V))
280 if (Inst->getNumOperands() > 0 && !Inst->isTerminator())
281 for (Value *Op : Inst->operands())
282 Worklist.push_back(Op);
283 }
284 return false;
285 }
286
287 Error validateRawBufferElementIndex(Value *Resource, Value *ElementIndex) {
288 bool IsStructured =
289 cast<RawBufferExtType>(Resource->getType())->isStructured();
290 bool IsPoison = isa<PoisonValue>(ElementIndex);
291
292 if (IsStructured && IsPoison)
294 "Element index of structured buffer may not be poison",
296
297 if (!IsStructured && !IsPoison)
299 "Element index of raw buffer must be poison",
301
302 return Error::success();
303 }
304
305 [[nodiscard]] bool lowerToCreateHandle(Function &F) {
306 IRBuilder<> &IRB = OpBuilder.getIRB();
307 Type *Int8Ty = IRB.getInt8Ty();
308 Type *Int32Ty = IRB.getInt32Ty();
309 Type *Int1Ty = IRB.getInt1Ty();
310
311 return replaceFunction(F, [&](CallInst *CI) -> Error {
312 IRB.SetInsertPoint(CI);
313
314 auto *It = DRM.find(CI);
315 assert(It != DRM.end() && "Resource not in map?");
316 dxil::ResourceInfo &RI = *It;
317
318 const auto &Binding = RI.getBinding();
319 dxil::ResourceClass RC = DRTM[RI.getHandleTy()].getResourceClass();
320
321 Value *IndexOp = CI->getArgOperand(3);
322 if (Binding.LowerBound != 0)
323 IndexOp = IRB.CreateAdd(IndexOp,
324 ConstantInt::get(Int32Ty, Binding.LowerBound));
325
326 bool HasNonUniformIndex =
327 (Binding.Size == 1) ? false : hasNonUniformIndex(IndexOp);
328 std::array<Value *, 4> Args{
329 ConstantInt::get(Int8Ty, llvm::to_underlying(RC)),
330 ConstantInt::get(Int32Ty, Binding.RecordID), IndexOp,
331 ConstantInt::get(Int1Ty, HasNonUniformIndex)};
332 Expected<CallInst *> OpCall =
333 OpBuilder.tryCreateOp(OpCode::CreateHandle, Args, CI->getName());
334 if (Error E = OpCall.takeError())
335 return E;
336
337 Value *Cast = createTmpHandleCast(*OpCall, CI->getType());
338 replaceHandleFromBindingCall(CI, Cast);
339 return Error::success();
340 });
341 }
342
343 [[nodiscard]] bool lowerToBindAndAnnotateHandle(Function &F) {
344 IRBuilder<> &IRB = OpBuilder.getIRB();
345 Type *Int32Ty = IRB.getInt32Ty();
346 Type *Int1Ty = IRB.getInt1Ty();
347
348 return replaceFunction(F, [&](CallInst *CI) -> Error {
349 IRB.SetInsertPoint(CI);
350
351 auto *It = DRM.find(CI);
352 assert(It != DRM.end() && "Resource not in map?");
353 dxil::ResourceInfo &RI = *It;
354
355 const auto &Binding = RI.getBinding();
356 dxil::ResourceTypeInfo &RTI = DRTM[RI.getHandleTy()];
358
359 Value *IndexOp = CI->getArgOperand(3);
360 if (Binding.LowerBound != 0)
361 IndexOp = IRB.CreateAdd(IndexOp,
362 ConstantInt::get(Int32Ty, Binding.LowerBound));
363
364 std::pair<uint32_t, uint32_t> Props =
365 RI.getAnnotateProps(*F.getParent(), RTI);
366
367 // For `CreateHandleFromBinding` we need the upper bound rather than the
368 // size, so we need to be careful about the difference for "unbounded".
369 uint32_t UpperBound = Binding.Size == 0
370 ? std::numeric_limits<uint32_t>::max()
371 : Binding.LowerBound + Binding.Size - 1;
372 Constant *ResBind = OpBuilder.getResBind(Binding.LowerBound, UpperBound,
373 Binding.Space, RC);
374 bool NonUniformIndex =
375 (Binding.Size == 1) ? false : hasNonUniformIndex(IndexOp);
376 Constant *NonUniformOp = ConstantInt::get(Int1Ty, NonUniformIndex);
377 std::array<Value *, 3> BindArgs{ResBind, IndexOp, NonUniformOp};
378 Expected<CallInst *> OpBind = OpBuilder.tryCreateOp(
379 OpCode::CreateHandleFromBinding, BindArgs, CI->getName());
380 if (Error E = OpBind.takeError())
381 return E;
382
383 std::array<Value *, 2> AnnotateArgs{
384 *OpBind, OpBuilder.getResProps(Props.first, Props.second)};
385 Expected<CallInst *> OpAnnotate = OpBuilder.tryCreateOp(
386 OpCode::AnnotateHandle, AnnotateArgs,
387 CI->hasName() ? CI->getName() + "_annot" : Twine());
388 if (Error E = OpAnnotate.takeError())
389 return E;
390
391 Value *Cast = createTmpHandleCast(*OpAnnotate, CI->getType());
392 replaceHandleFromBindingCall(CI, Cast);
393 return Error::success();
394 });
395 }
396
397 /// Lower `dx.resource.handlefrombinding` intrinsics depending on the shader
398 /// model and taking into account binding information from
399 /// DXILResourceAnalysis.
400 bool lowerHandleFromBinding(Function &F) {
401 if (MMDI.DXILVersion < VersionTuple(1, 6))
402 return lowerToCreateHandle(F);
403 return lowerToBindAndAnnotateHandle(F);
404 }
405
406 /// Replace uses of \c Intrin with the values in the `dx.ResRet` of \c Op.
407 /// Since we expect to be post-scalarization, make an effort to avoid vectors.
408 Error replaceResRetUses(CallInst *Intrin, CallInst *Op, bool HasCheckBit) {
409 IRBuilder<> &IRB = OpBuilder.getIRB();
410
411 Instruction *OldResult = Intrin;
412 Type *OldTy = Intrin->getType();
413
414 if (HasCheckBit) {
415 auto *ST = cast<StructType>(OldTy);
416
417 Value *CheckOp = nullptr;
418 Type *Int32Ty = IRB.getInt32Ty();
419 for (Use &U : make_early_inc_range(OldResult->uses())) {
420 if (auto *EVI = dyn_cast<ExtractValueInst>(U.getUser())) {
421 ArrayRef<unsigned> Indices = EVI->getIndices();
422 assert(Indices.size() == 1);
423 // We're only interested in uses of the check bit for now.
424 if (Indices[0] != 1)
425 continue;
426 if (!CheckOp) {
427 Value *NewEVI = IRB.CreateExtractValue(Op, 4);
428 Expected<CallInst *> OpCall = OpBuilder.tryCreateOp(
429 OpCode::CheckAccessFullyMapped, {NewEVI},
430 OldResult->hasName() ? OldResult->getName() + "_check"
431 : Twine(),
432 Int32Ty);
433 if (Error E = OpCall.takeError())
434 return E;
435 CheckOp = *OpCall;
436 }
437 EVI->replaceAllUsesWith(CheckOp);
438 EVI->eraseFromParent();
439 }
440 }
441
442 if (OldResult->use_empty()) {
443 // Only the check bit was used, so we're done here.
444 OldResult->eraseFromParent();
445 return Error::success();
446 }
447
448 assert(OldResult->hasOneUse() &&
449 isa<ExtractValueInst>(*OldResult->user_begin()) &&
450 "Expected only use to be extract of first element");
451 OldResult = cast<Instruction>(*OldResult->user_begin());
452 OldTy = ST->getElementType(0);
453 }
454
455 // For scalars, we just extract the first element.
456 if (!isa<FixedVectorType>(OldTy)) {
457 Value *EVI = IRB.CreateExtractValue(Op, 0);
458 OldResult->replaceAllUsesWith(EVI);
459 OldResult->eraseFromParent();
460 if (OldResult != Intrin) {
461 assert(Intrin->use_empty() && "Intrinsic still has uses?");
462 Intrin->eraseFromParent();
463 }
464 return Error::success();
465 }
466
467 std::array<Value *, 4> Extracts = {};
468 SmallVector<ExtractElementInst *> DynamicAccesses;
469
470 // The users of the operation should all be scalarized, so we attempt to
471 // replace the extractelements with extractvalues directly.
472 for (Use &U : make_early_inc_range(OldResult->uses())) {
473 if (auto *EEI = dyn_cast<ExtractElementInst>(U.getUser())) {
474 if (auto *IndexOp = dyn_cast<ConstantInt>(EEI->getIndexOperand())) {
475 size_t IndexVal = IndexOp->getZExtValue();
476 assert(IndexVal < 4 && "Index into buffer load out of range");
477 if (!Extracts[IndexVal])
478 Extracts[IndexVal] = IRB.CreateExtractValue(Op, IndexVal);
479 EEI->replaceAllUsesWith(Extracts[IndexVal]);
480 EEI->eraseFromParent();
481 } else {
482 DynamicAccesses.push_back(EEI);
483 }
484 }
485 }
486
487 const auto *VecTy = cast<FixedVectorType>(OldTy);
488 const unsigned N = VecTy->getNumElements();
489
490 // If there's a dynamic access we need to round trip through stack memory so
491 // that we don't leave vectors around.
492 if (!DynamicAccesses.empty()) {
493 Type *Int32Ty = IRB.getInt32Ty();
494 Constant *Zero = ConstantInt::get(Int32Ty, 0);
495
496 Type *ElTy = VecTy->getElementType();
497 Type *ArrayTy = ArrayType::get(ElTy, N);
498 Value *Alloca = IRB.CreateAlloca(ArrayTy);
499
500 for (int I = 0, E = N; I != E; ++I) {
501 if (!Extracts[I])
502 Extracts[I] = IRB.CreateExtractValue(Op, I);
504 ArrayTy, Alloca, {Zero, ConstantInt::get(Int32Ty, I)});
505 IRB.CreateStore(Extracts[I], GEP);
506 }
507
508 for (ExtractElementInst *EEI : DynamicAccesses) {
509 Value *GEP = IRB.CreateInBoundsGEP(ArrayTy, Alloca,
510 {Zero, EEI->getIndexOperand()});
511 Value *Load = IRB.CreateLoad(ElTy, GEP);
512 EEI->replaceAllUsesWith(Load);
513 EEI->eraseFromParent();
514 }
515 }
516
517 // If we still have uses, then we're not fully scalarized and need to
518 // recreate the vector. This should only happen for things like exported
519 // functions from libraries.
520 if (!OldResult->use_empty()) {
521 for (int I = 0, E = N; I != E; ++I)
522 if (!Extracts[I])
523 Extracts[I] = IRB.CreateExtractValue(Op, I);
524
525 Value *Vec = PoisonValue::get(OldTy);
526 for (int I = 0, E = N; I != E; ++I)
527 Vec = IRB.CreateInsertElement(Vec, Extracts[I], I);
528 OldResult->replaceAllUsesWith(Vec);
529 }
530
531 OldResult->eraseFromParent();
532 if (OldResult != Intrin) {
533 assert(Intrin->use_empty() && "Intrinsic still has uses?");
534 Intrin->eraseFromParent();
535 }
536
537 return Error::success();
538 }
539
540 [[nodiscard]] bool lowerTypedBufferLoad(Function &F, bool HasCheckBit) {
541 IRBuilder<> &IRB = OpBuilder.getIRB();
542 Type *Int32Ty = IRB.getInt32Ty();
543
544 return replaceFunction(F, [&](CallInst *CI) -> Error {
545 IRB.SetInsertPoint(CI);
546
547 Value *Handle =
548 createTmpHandleCast(CI->getArgOperand(0), OpBuilder.getHandleType());
549 Value *Index0 = CI->getArgOperand(1);
550 Value *Index1 = UndefValue::get(Int32Ty);
551
552 Type *OldTy = CI->getType();
553 if (HasCheckBit)
554 OldTy = cast<StructType>(OldTy)->getElementType(0);
555 Type *NewRetTy = OpBuilder.getResRetType(OldTy->getScalarType());
556
557 std::array<Value *, 3> Args{Handle, Index0, Index1};
558 Expected<CallInst *> OpCall = OpBuilder.tryCreateOp(
559 OpCode::BufferLoad, Args, CI->getName(), NewRetTy);
560 if (Error E = OpCall.takeError())
561 return E;
562 if (Error E = replaceResRetUses(CI, *OpCall, HasCheckBit))
563 return E;
564
565 return Error::success();
566 });
567 }
568
569 [[nodiscard]] bool lowerRawBufferLoad(Function &F) {
570 const DataLayout &DL = F.getDataLayout();
571 IRBuilder<> &IRB = OpBuilder.getIRB();
572 Type *Int8Ty = IRB.getInt8Ty();
573 Type *Int32Ty = IRB.getInt32Ty();
574
575 return replaceFunction(F, [&](CallInst *CI) -> Error {
576 IRB.SetInsertPoint(CI);
577
578 Type *OldTy = cast<StructType>(CI->getType())->getElementType(0);
579 Type *ScalarTy = OldTy->getScalarType();
580 Type *NewRetTy = OpBuilder.getResRetType(ScalarTy);
581
582 Value *Handle =
583 createTmpHandleCast(CI->getArgOperand(0), OpBuilder.getHandleType());
584 Value *Index0 = CI->getArgOperand(1);
585 Value *Index1 = CI->getArgOperand(2);
586 uint64_t NumElements =
587 DL.getTypeSizeInBits(OldTy) / DL.getTypeSizeInBits(ScalarTy);
588 Value *Mask = ConstantInt::get(Int8Ty, ~(~0U << NumElements));
589 Value *Align =
590 ConstantInt::get(Int32Ty, DL.getPrefTypeAlign(ScalarTy).value());
591
592 if (Error E = validateRawBufferElementIndex(CI->getOperand(0), Index1))
593 return E;
594 if (isa<PoisonValue>(Index1))
595 Index1 = UndefValue::get(Index1->getType());
596
597 Expected<CallInst *> OpCall =
598 MMDI.DXILVersion >= VersionTuple(1, 2)
599 ? OpBuilder.tryCreateOp(OpCode::RawBufferLoad,
600 {Handle, Index0, Index1, Mask, Align},
601 CI->getName(), NewRetTy)
602 : OpBuilder.tryCreateOp(OpCode::BufferLoad,
603 {Handle, Index0, Index1}, CI->getName(),
604 NewRetTy);
605 if (Error E = OpCall.takeError())
606 return E;
607 if (Error E = replaceResRetUses(CI, *OpCall, /*HasCheckBit=*/true))
608 return E;
609
610 return Error::success();
611 });
612 }
613
614 [[nodiscard]] bool lowerCBufferLoad(Function &F) {
615 IRBuilder<> &IRB = OpBuilder.getIRB();
616
617 return replaceFunction(F, [&](CallInst *CI) -> Error {
618 IRB.SetInsertPoint(CI);
619
620 Type *OldTy = cast<StructType>(CI->getType())->getElementType(0);
621 Type *ScalarTy = OldTy->getScalarType();
622 Type *NewRetTy = OpBuilder.getCBufRetType(ScalarTy);
623
624 Value *Handle =
625 createTmpHandleCast(CI->getArgOperand(0), OpBuilder.getHandleType());
626 Value *Index = CI->getArgOperand(1);
627
628 Expected<CallInst *> OpCall = OpBuilder.tryCreateOp(
629 OpCode::CBufferLoadLegacy, {Handle, Index}, CI->getName(), NewRetTy);
630 if (Error E = OpCall.takeError())
631 return E;
632 if (Error E = replaceNamedStructUses(CI, *OpCall))
633 return E;
634
635 CI->eraseFromParent();
636 return Error::success();
637 });
638 }
639
640 [[nodiscard]] bool lowerUpdateCounter(Function &F) {
641 IRBuilder<> &IRB = OpBuilder.getIRB();
642 Type *Int32Ty = IRB.getInt32Ty();
643
644 return replaceFunction(F, [&](CallInst *CI) -> Error {
645 IRB.SetInsertPoint(CI);
646 Value *Handle =
647 createTmpHandleCast(CI->getArgOperand(0), OpBuilder.getHandleType());
648 Value *Op1 = CI->getArgOperand(1);
649
650 std::array<Value *, 2> Args{Handle, Op1};
651
652 Expected<CallInst *> OpCall = OpBuilder.tryCreateOp(
653 OpCode::UpdateCounter, Args, CI->getName(), Int32Ty);
654
655 if (Error E = OpCall.takeError())
656 return E;
657
658 CI->replaceAllUsesWith(*OpCall);
659 CI->eraseFromParent();
660 return Error::success();
661 });
662 }
663
664 [[nodiscard]] bool lowerGetDimensionsX(Function &F) {
665 IRBuilder<> &IRB = OpBuilder.getIRB();
666 Type *Int32Ty = IRB.getInt32Ty();
667
668 return replaceFunction(F, [&](CallInst *CI) -> Error {
669 IRB.SetInsertPoint(CI);
670 Value *Handle =
671 createTmpHandleCast(CI->getArgOperand(0), OpBuilder.getHandleType());
673
674 Expected<CallInst *> OpCall = OpBuilder.tryCreateOp(
675 OpCode::GetDimensions, {Handle, Undef}, CI->getName(), Int32Ty);
676 if (Error E = OpCall.takeError())
677 return E;
678 Value *Dim = IRB.CreateExtractValue(*OpCall, 0);
679
680 CI->replaceAllUsesWith(Dim);
681 CI->eraseFromParent();
682 return Error::success();
683 });
684 }
685
686 [[nodiscard]] bool lowerGetPointer(Function &F) {
687 // These should have already been handled in DXILResourceAccess, so we can
688 // just clean up the dead prototype.
689 assert(F.user_empty() && "getpointer operations should have been removed");
690 F.eraseFromParent();
691 return false;
692 }
693
694 [[nodiscard]] bool lowerBufferStore(Function &F, bool IsRaw) {
695 const DataLayout &DL = F.getDataLayout();
696 IRBuilder<> &IRB = OpBuilder.getIRB();
697 Type *Int8Ty = IRB.getInt8Ty();
698 Type *Int32Ty = IRB.getInt32Ty();
699
700 return replaceFunction(F, [&](CallInst *CI) -> Error {
701 IRB.SetInsertPoint(CI);
702
703 Value *Handle =
704 createTmpHandleCast(CI->getArgOperand(0), OpBuilder.getHandleType());
705 Value *Index0 = CI->getArgOperand(1);
706 Value *Index1 = IsRaw ? CI->getArgOperand(2) : UndefValue::get(Int32Ty);
707
708 if (IsRaw) {
709 if (Error E = validateRawBufferElementIndex(CI->getOperand(0), Index1))
710 return E;
711 if (isa<PoisonValue>(Index1))
712 Index1 = UndefValue::get(Index1->getType());
713 }
714
715 Value *Data = CI->getArgOperand(IsRaw ? 3 : 2);
716 Type *DataTy = Data->getType();
717 Type *ScalarTy = DataTy->getScalarType();
718
719 uint64_t NumElements =
720 DL.getTypeSizeInBits(DataTy) / DL.getTypeSizeInBits(ScalarTy);
721 Value *Mask =
722 ConstantInt::get(Int8Ty, IsRaw ? ~(~0U << NumElements) : 15U);
723
724 // TODO: check that we only have vector or scalar...
725 if (NumElements > 4)
727 "Buffer store data must have at most 4 elements",
729
730 std::array<Value *, 4> DataElements{nullptr, nullptr, nullptr, nullptr};
731 if (DataTy == ScalarTy)
732 DataElements[0] = Data;
733 else {
734 // Since we're post-scalarizer, if we see a vector here it's likely
735 // constructed solely for the argument of the store. Just use the scalar
736 // values from before they're inserted into the temporary.
738 while (IEI) {
739 auto *IndexOp = dyn_cast<ConstantInt>(IEI->getOperand(2));
740 if (!IndexOp)
741 break;
742 size_t IndexVal = IndexOp->getZExtValue();
743 assert(IndexVal < 4 && "Too many elements for buffer store");
744 DataElements[IndexVal] = IEI->getOperand(1);
745 IEI = dyn_cast<InsertElementInst>(IEI->getOperand(0));
746 }
747 }
748
749 // If for some reason we weren't able to forward the arguments from the
750 // scalarizer artifact, then we may need to actually extract elements from
751 // the vector.
752 for (int I = 0, E = NumElements; I < E; ++I)
753 if (DataElements[I] == nullptr)
754 DataElements[I] =
755 IRB.CreateExtractElement(Data, ConstantInt::get(Int32Ty, I));
756
757 // For any elements beyond the length of the vector, we should fill it up
758 // with undef - however, for typed buffers we repeat the first element to
759 // match DXC.
760 for (int I = NumElements, E = 4; I < E; ++I)
761 if (DataElements[I] == nullptr)
762 DataElements[I] = IsRaw ? UndefValue::get(ScalarTy) : DataElements[0];
763
764 dxil::OpCode Op = OpCode::BufferStore;
766 Handle, Index0, Index1, DataElements[0],
767 DataElements[1], DataElements[2], DataElements[3], Mask};
768 if (IsRaw && MMDI.DXILVersion >= VersionTuple(1, 2)) {
769 Op = OpCode::RawBufferStore;
770 // RawBufferStore requires the alignment
771 Args.push_back(
772 ConstantInt::get(Int32Ty, DL.getPrefTypeAlign(ScalarTy).value()));
773 }
774 Expected<CallInst *> OpCall =
775 OpBuilder.tryCreateOp(Op, Args, CI->getName());
776 if (Error E = OpCall.takeError())
777 return E;
778
779 CI->eraseFromParent();
780 // Clean up any leftover `insertelement`s
782 while (IEI && IEI->use_empty()) {
783 InsertElementInst *Tmp = IEI;
784 IEI = dyn_cast<InsertElementInst>(IEI->getOperand(0));
785 Tmp->eraseFromParent();
786 }
787
788 return Error::success();
789 });
790 }
791
792 [[nodiscard]] bool lowerCtpopToCountBits(Function &F) {
793 IRBuilder<> &IRB = OpBuilder.getIRB();
794 Type *Int32Ty = IRB.getInt32Ty();
795
796 return replaceFunction(F, [&](CallInst *CI) -> Error {
797 IRB.SetInsertPoint(CI);
799 Args.append(CI->arg_begin(), CI->arg_end());
800
801 Type *RetTy = Int32Ty;
802 Type *FRT = F.getReturnType();
803 if (const auto *VT = dyn_cast<VectorType>(FRT))
804 RetTy = VectorType::get(RetTy, VT);
805
806 Expected<CallInst *> OpCall = OpBuilder.tryCreateOp(
807 dxil::OpCode::CountBits, Args, CI->getName(), RetTy);
808 if (Error E = OpCall.takeError())
809 return E;
810
811 // If the result type is 32 bits we can do a direct replacement.
812 if (FRT->isIntOrIntVectorTy(32)) {
813 CI->replaceAllUsesWith(*OpCall);
814 CI->eraseFromParent();
815 return Error::success();
816 }
817
818 unsigned CastOp;
819 unsigned CastOp2;
820 if (FRT->isIntOrIntVectorTy(16)) {
821 CastOp = Instruction::ZExt;
822 CastOp2 = Instruction::SExt;
823 } else { // must be 64 bits
824 assert(FRT->isIntOrIntVectorTy(64) &&
825 "Currently only lowering 16, 32, or 64 bit ctpop to CountBits \
826 is supported.");
827 CastOp = Instruction::Trunc;
828 CastOp2 = Instruction::Trunc;
829 }
830
831 // It is correct to replace the ctpop with the dxil op and
832 // remove all casts to i32
833 bool NeedsCast = false;
834 for (User *User : make_early_inc_range(CI->users())) {
836 if (I && (I->getOpcode() == CastOp || I->getOpcode() == CastOp2) &&
837 I->getType() == RetTy) {
838 I->replaceAllUsesWith(*OpCall);
839 I->eraseFromParent();
840 } else
841 NeedsCast = true;
842 }
843
844 // It is correct to replace a ctpop with the dxil op and
845 // a cast from i32 to the return type of the ctpop
846 // the cast is emitted here if there is a non-cast to i32
847 // instr which uses the ctpop
848 if (NeedsCast) {
849 Value *Cast =
850 IRB.CreateZExtOrTrunc(*OpCall, F.getReturnType(), "ctpop.cast");
851 CI->replaceAllUsesWith(Cast);
852 }
853
854 CI->eraseFromParent();
855 return Error::success();
856 });
857 }
858
859 [[nodiscard]] bool lowerLifetimeIntrinsic(Function &F) {
860 IRBuilder<> &IRB = OpBuilder.getIRB();
861 return replaceFunction(F, [&](CallInst *CI) -> Error {
862 IRB.SetInsertPoint(CI);
863 Value *Ptr = CI->getArgOperand(0);
864 assert(Ptr->getType()->isPointerTy() &&
865 "Expected operand of lifetime intrinsic to be a pointer");
866
867 auto ZeroOrUndef = [&](Type *Ty) {
868 return MMDI.ValidatorVersion < VersionTuple(1, 6)
870 : UndefValue::get(Ty);
871 };
872
873 Value *Val = nullptr;
874 if (auto *GV = dyn_cast<GlobalVariable>(Ptr)) {
875 if (GV->hasInitializer() || GV->isExternallyInitialized())
876 return Error::success();
877 Val = ZeroOrUndef(GV->getValueType());
878 } else if (auto *AI = dyn_cast<AllocaInst>(Ptr))
879 Val = ZeroOrUndef(AI->getAllocatedType());
880
881 assert(Val && "Expected operand of lifetime intrinsic to be a global "
882 "variable or alloca instruction");
883 IRB.CreateStore(Val, Ptr, false);
884
885 CI->eraseFromParent();
886 return Error::success();
887 });
888 }
889
890 [[nodiscard]] bool lowerIsFPClass(Function &F) {
891 IRBuilder<> &IRB = OpBuilder.getIRB();
892 Type *RetTy = IRB.getInt1Ty();
893
894 return replaceFunction(F, [&](CallInst *CI) -> Error {
895 IRB.SetInsertPoint(CI);
897 Value *Fl = CI->getArgOperand(0);
898 Args.push_back(Fl);
899
901 Value *T = CI->getArgOperand(1);
902 auto *TCI = dyn_cast<ConstantInt>(T);
903 switch (TCI->getZExtValue()) {
904 case FPClassTest::fcInf:
905 OpCode = dxil::OpCode::IsInf;
906 break;
907 case FPClassTest::fcNan:
908 OpCode = dxil::OpCode::IsNaN;
909 break;
910 case FPClassTest::fcNormal:
911 OpCode = dxil::OpCode::IsNormal;
912 break;
913 case FPClassTest::fcFinite:
914 OpCode = dxil::OpCode::IsFinite;
915 break;
916 default:
917 SmallString<128> Msg =
918 formatv("Unsupported FPClassTest {0} for DXIL Op Lowering",
919 TCI->getZExtValue());
921 }
922
923 Expected<CallInst *> OpCall =
924 OpBuilder.tryCreateOp(OpCode, Args, CI->getName(), RetTy);
925 if (Error E = OpCall.takeError())
926 return E;
927
928 CI->replaceAllUsesWith(*OpCall);
929 CI->eraseFromParent();
930 return Error::success();
931 });
932 }
933
934 bool lowerIntrinsics() {
935 bool Updated = false;
936 bool HasErrors = false;
937
938 for (Function &F : make_early_inc_range(M.functions())) {
939 if (!F.isDeclaration())
940 continue;
941 Intrinsic::ID ID = F.getIntrinsicID();
942 switch (ID) {
943 // NOTE: Skip dx_resource_casthandle here. They are
944 // resolved after this loop in cleanupHandleCasts.
945 case Intrinsic::dx_resource_casthandle:
946 // NOTE: llvm.dbg.value is supported as is in DXIL.
947 case Intrinsic::dbg_value:
949 if (F.use_empty())
950 F.eraseFromParent();
951 continue;
952 default:
953 if (F.use_empty())
954 F.eraseFromParent();
955 else {
956 SmallString<128> Msg = formatv(
957 "Unsupported intrinsic {0} for DXIL lowering", F.getName());
958 M.getContext().emitError(Msg);
959 HasErrors |= true;
960 }
961 break;
962
963#define DXIL_OP_INTRINSIC(OpCode, Intrin, ...) \
964 case Intrin: \
965 HasErrors |= replaceFunctionWithOp( \
966 F, OpCode, ArrayRef<IntrinArgSelect>{__VA_ARGS__}); \
967 break;
968#include "DXILOperation.inc"
969 case Intrinsic::dx_resource_handlefrombinding:
970 HasErrors |= lowerHandleFromBinding(F);
971 break;
972 case Intrinsic::dx_resource_getpointer:
973 HasErrors |= lowerGetPointer(F);
974 break;
975 case Intrinsic::dx_resource_nonuniformindex:
976 assert(!CleanupNURI &&
977 "overloaded llvm.dx.resource.nonuniformindex intrinsics?");
978 CleanupNURI = &F;
979 break;
980 case Intrinsic::dx_resource_load_typedbuffer:
981 HasErrors |= lowerTypedBufferLoad(F, /*HasCheckBit=*/true);
982 break;
983 case Intrinsic::dx_resource_store_typedbuffer:
984 HasErrors |= lowerBufferStore(F, /*IsRaw=*/false);
985 break;
986 case Intrinsic::dx_resource_load_rawbuffer:
987 HasErrors |= lowerRawBufferLoad(F);
988 break;
989 case Intrinsic::dx_resource_store_rawbuffer:
990 HasErrors |= lowerBufferStore(F, /*IsRaw=*/true);
991 break;
992 case Intrinsic::dx_resource_load_cbufferrow_2:
993 case Intrinsic::dx_resource_load_cbufferrow_4:
994 case Intrinsic::dx_resource_load_cbufferrow_8:
995 HasErrors |= lowerCBufferLoad(F);
996 break;
997 case Intrinsic::dx_resource_updatecounter:
998 HasErrors |= lowerUpdateCounter(F);
999 break;
1000 case Intrinsic::dx_resource_getdimensions_x:
1001 HasErrors |= lowerGetDimensionsX(F);
1002 break;
1003 case Intrinsic::ctpop:
1004 HasErrors |= lowerCtpopToCountBits(F);
1005 break;
1006 case Intrinsic::lifetime_start:
1007 case Intrinsic::lifetime_end:
1008 if (F.use_empty())
1009 F.eraseFromParent();
1010 else {
1011 if (MMDI.DXILVersion < VersionTuple(1, 6))
1012 HasErrors |= lowerLifetimeIntrinsic(F);
1013 else
1014 continue;
1015 }
1016 break;
1017 case Intrinsic::is_fpclass:
1018 HasErrors |= lowerIsFPClass(F);
1019 break;
1020 }
1021 Updated = true;
1022 }
1023 if (Updated && !HasErrors) {
1024 cleanupHandleCasts();
1025 cleanupNonUniformResourceIndexCalls();
1026 }
1027
1028 return Updated;
1029 }
1030};
1031} // namespace
1032
1034 DXILResourceMap &DRM = MAM.getResult<DXILResourceAnalysis>(M);
1035 DXILResourceTypeMap &DRTM = MAM.getResult<DXILResourceTypeAnalysis>(M);
1036 const ModuleMetadataInfo MMDI = MAM.getResult<DXILMetadataAnalysis>(M);
1037
1038 const bool MadeChanges = OpLowerer(M, DRM, DRTM, MMDI).lowerIntrinsics();
1039 if (!MadeChanges)
1040 return PreservedAnalyses::all();
1046 return PA;
1047}
1048
1049namespace {
1050class DXILOpLoweringLegacy : public ModulePass {
1051public:
1052 bool runOnModule(Module &M) override {
1053 DXILResourceMap &DRM =
1054 getAnalysis<DXILResourceWrapperPass>().getResourceMap();
1055 DXILResourceTypeMap &DRTM =
1056 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
1057 const ModuleMetadataInfo MMDI =
1058 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
1059
1060 return OpLowerer(M, DRM, DRTM, MMDI).lowerIntrinsics();
1061 }
1062 StringRef getPassName() const override { return "DXIL Op Lowering"; }
1063 DXILOpLoweringLegacy() : ModulePass(ID) {}
1064
1065 static char ID; // Pass identification.
1066 void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {
1067 AU.addRequired<DXILResourceTypeWrapperPass>();
1068 AU.addRequired<DXILResourceWrapperPass>();
1069 AU.addRequired<DXILMetadataAnalysisWrapperPass>();
1070 AU.addPreserved<DXILResourceWrapperPass>();
1071 AU.addPreserved<DXILMetadataAnalysisWrapperPass>();
1072 AU.addPreserved<ShaderFlagsAnalysisWrapper>();
1073 AU.addPreserved<RootSignatureAnalysisWrapper>();
1074 }
1075};
1076char DXILOpLoweringLegacy::ID = 0;
1077} // end anonymous namespace
1078
1079INITIALIZE_PASS_BEGIN(DXILOpLoweringLegacy, DEBUG_TYPE, "DXIL Op Lowering",
1080 false, false)
1083INITIALIZE_PASS_END(DXILOpLoweringLegacy, DEBUG_TYPE, "DXIL Op Lowering", false,
1084 false)
1085
1087 return new DXILOpLoweringLegacy();
1088}
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.
LLVM_ABI 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 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:2585
AllocaInst * CreateAlloca(Type *Ty, unsigned AddrSpace, Value *ArraySize=nullptr, const Twine &Name="")
Definition IRBuilder.h:1861
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:2573
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
Definition IRBuilder.h:2096
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
Definition IRBuilder.h:2632
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:1976
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:1878
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Definition IRBuilder.h:1891
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Definition IRBuilder.h:1430
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
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
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:255
user_iterator user_begin()
Definition Value.h:402
bool hasOneUse() const
Return true if there is exactly one use of this value.
Definition Value.h:439
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition Value.cpp:549
iterator_range< user_iterator > users()
Definition Value.h:426
bool use_empty() const
Definition Value.h:346
iterator_range< use_iterator > uses()
Definition Value.h:380
bool hasName() const
Definition Value.h:261
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:318
bool user_empty() const
Definition Value.h:389
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< PhiNode * > Phi
Definition RDFGraph.h:390
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.
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:328
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:221
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