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