LLVM 22.0.0git
DXILIntrinsicExpansion.cpp
Go to the documentation of this file.
1//===- DXILIntrinsicExpansion.cpp - Prepare LLVM Module for DXIL encoding--===//
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/// \file This file contains DXIL intrinsic expansions for those that don't have
10// opcodes in DirectX Intermediate Language (DXIL).
11//===----------------------------------------------------------------------===//
12
14#include "DirectX.h"
15#include "llvm/ADT/STLExtras.h"
17#include "llvm/CodeGen/Passes.h"
18#include "llvm/IR/IRBuilder.h"
19#include "llvm/IR/InstrTypes.h"
20#include "llvm/IR/Instruction.h"
22#include "llvm/IR/Intrinsics.h"
23#include "llvm/IR/IntrinsicsDirectX.h"
24#include "llvm/IR/Module.h"
25#include "llvm/IR/PassManager.h"
26#include "llvm/IR/Type.h"
27#include "llvm/Pass.h"
31
32#define DEBUG_TYPE "dxil-intrinsic-expansion"
33
34using namespace llvm;
35
37
38public:
39 bool runOnModule(Module &M) override;
41
42 static char ID; // Pass identification.
43};
44
45static bool resourceAccessNeeds64BitExpansion(Module *M, Type *OverloadTy,
46 bool IsRaw) {
47 if (IsRaw && M->getTargetTriple().getDXILVersion() > VersionTuple(1, 2))
48 return false;
49
50 Type *ScalarTy = OverloadTy->getScalarType();
51 return ScalarTy->isDoubleTy() || ScalarTy->isIntegerTy(64);
52}
53
55 Module *M = Orig->getModule();
56 if (M->getTargetTriple().getDXILVersion() >= VersionTuple(1, 9))
57 return nullptr;
58
59 Value *Val = Orig->getOperand(0);
60 Type *ValTy = Val->getType();
61 if (!ValTy->getScalarType()->isHalfTy())
62 return nullptr;
63
64 IRBuilder<> Builder(Orig);
65 Type *IType = Type::getInt16Ty(M->getContext());
66 Constant *PosInf =
67 ValTy->isVectorTy()
71 ConstantInt::get(IType, 0x7c00))
72 : ConstantInt::get(IType, 0x7c00);
73
74 Constant *NegInf =
75 ValTy->isVectorTy()
79 ConstantInt::get(IType, 0xfc00))
80 : ConstantInt::get(IType, 0xfc00);
81
82 Value *IVal = Builder.CreateBitCast(Val, PosInf->getType());
83 Value *B1 = Builder.CreateICmpEQ(IVal, PosInf);
84 Value *B2 = Builder.CreateICmpEQ(IVal, NegInf);
85 Value *B3 = Builder.CreateOr(B1, B2);
86 return B3;
87}
88
90 Module *M = Orig->getModule();
91 if (M->getTargetTriple().getDXILVersion() >= VersionTuple(1, 9))
92 return nullptr;
93
94 Value *Val = Orig->getOperand(0);
95 Type *ValTy = Val->getType();
96 if (!ValTy->getScalarType()->isHalfTy())
97 return nullptr;
98
99 IRBuilder<> Builder(Orig);
100 Type *IType = Type::getInt16Ty(M->getContext());
101
102 Constant *ExpBitMask =
103 ValTy->isVectorTy()
107 ConstantInt::get(IType, 0x7c00))
108 : ConstantInt::get(IType, 0x7c00);
109 Constant *SigBitMask =
110 ValTy->isVectorTy()
114 ConstantInt::get(IType, 0x3ff))
115 : ConstantInt::get(IType, 0x3ff);
116
117 Constant *Zero =
118 ValTy->isVectorTy()
122 ConstantInt::get(IType, 0))
123 : ConstantInt::get(IType, 0);
124
125 Value *IVal = Builder.CreateBitCast(Val, ExpBitMask->getType());
126 Value *Exp = Builder.CreateAnd(IVal, ExpBitMask);
127 Value *B1 = Builder.CreateICmpEQ(Exp, ExpBitMask);
128
129 Value *Sig = Builder.CreateAnd(IVal, SigBitMask);
130 Value *B2 = Builder.CreateICmpNE(Sig, Zero);
131 Value *B3 = Builder.CreateAnd(B1, B2);
132 return B3;
133}
134
136 Module *M = Orig->getModule();
137 if (M->getTargetTriple().getDXILVersion() >= VersionTuple(1, 9))
138 return nullptr;
139
140 Value *Val = Orig->getOperand(0);
141 Type *ValTy = Val->getType();
142 if (!ValTy->getScalarType()->isHalfTy())
143 return nullptr;
144
145 IRBuilder<> Builder(Orig);
146 Type *IType = Type::getInt16Ty(M->getContext());
147
148 Constant *ExpBitMask =
149 ValTy->isVectorTy()
153 ConstantInt::get(IType, 0x7c00))
154 : ConstantInt::get(IType, 0x7c00);
155
156 Value *IVal = Builder.CreateBitCast(Val, ExpBitMask->getType());
157 Value *Exp = Builder.CreateAnd(IVal, ExpBitMask);
158 Value *B1 = Builder.CreateICmpNE(Exp, ExpBitMask);
159 return B1;
160}
161
163 Module *M = Orig->getModule();
164 if (M->getTargetTriple().getDXILVersion() >= VersionTuple(1, 9))
165 return nullptr;
166
167 Value *Val = Orig->getOperand(0);
168 Type *ValTy = Val->getType();
169 if (!ValTy->getScalarType()->isHalfTy())
170 return nullptr;
171
172 IRBuilder<> Builder(Orig);
173 Type *IType = Type::getInt16Ty(M->getContext());
174
175 Constant *ExpBitMask =
176 ValTy->isVectorTy()
180 ConstantInt::get(IType, 0x7c00))
181 : ConstantInt::get(IType, 0x7c00);
182 Constant *Zero =
183 ValTy->isVectorTy()
187 ConstantInt::get(IType, 0))
188 : ConstantInt::get(IType, 0);
189
190 Value *IVal = Builder.CreateBitCast(Val, ExpBitMask->getType());
191 Value *Exp = Builder.CreateAnd(IVal, ExpBitMask);
192 Value *NotAllZeroes = Builder.CreateICmpNE(Exp, Zero);
193 Value *NotAllOnes = Builder.CreateICmpNE(Exp, ExpBitMask);
194 Value *B1 = Builder.CreateAnd(NotAllZeroes, NotAllOnes);
195 return B1;
196}
197
199 switch (F.getIntrinsicID()) {
200 case Intrinsic::abs:
201 case Intrinsic::atan2:
202 case Intrinsic::exp:
203 case Intrinsic::is_fpclass:
204 case Intrinsic::log:
205 case Intrinsic::log10:
206 case Intrinsic::pow:
207 case Intrinsic::powi:
208 case Intrinsic::dx_all:
209 case Intrinsic::dx_any:
210 case Intrinsic::dx_cross:
211 case Intrinsic::dx_uclamp:
212 case Intrinsic::dx_sclamp:
213 case Intrinsic::dx_nclamp:
214 case Intrinsic::dx_degrees:
215 case Intrinsic::dx_isinf:
216 case Intrinsic::dx_lerp:
217 case Intrinsic::dx_normalize:
218 case Intrinsic::dx_fdot:
219 case Intrinsic::dx_sdot:
220 case Intrinsic::dx_udot:
221 case Intrinsic::dx_sign:
222 case Intrinsic::dx_step:
223 case Intrinsic::dx_radians:
224 case Intrinsic::usub_sat:
225 case Intrinsic::vector_reduce_add:
226 case Intrinsic::vector_reduce_fadd:
227 return true;
228 case Intrinsic::dx_resource_load_rawbuffer:
230 F.getParent(), F.getReturnType()->getStructElementType(0),
231 /*IsRaw*/ true);
232 case Intrinsic::dx_resource_load_typedbuffer:
234 F.getParent(), F.getReturnType()->getStructElementType(0),
235 /*IsRaw*/ false);
236 case Intrinsic::dx_resource_store_rawbuffer:
238 F.getParent(), F.getFunctionType()->getParamType(3), /*IsRaw*/ true);
239 case Intrinsic::dx_resource_store_typedbuffer:
241 F.getParent(), F.getFunctionType()->getParamType(2), /*IsRaw*/ false);
242 }
243 return false;
244}
245
247 Value *A = Orig->getArgOperand(0);
248 Value *B = Orig->getArgOperand(1);
249 Type *Ty = A->getType();
250
251 IRBuilder<> Builder(Orig);
252
253 Value *Cmp = Builder.CreateICmpULT(A, B, "usub.cmp");
254 Value *Sub = Builder.CreateSub(A, B, "usub.sub");
255 Value *Zero = ConstantInt::get(Ty, 0);
256 return Builder.CreateSelect(Cmp, Zero, Sub, "usub.sat");
257}
258
259static Value *expandVecReduceAdd(CallInst *Orig, Intrinsic::ID IntrinsicId) {
260 assert(IntrinsicId == Intrinsic::vector_reduce_add ||
261 IntrinsicId == Intrinsic::vector_reduce_fadd);
262
263 IRBuilder<> Builder(Orig);
264 bool IsFAdd = (IntrinsicId == Intrinsic::vector_reduce_fadd);
265
266 Value *X = Orig->getOperand(IsFAdd ? 1 : 0);
267 Type *Ty = X->getType();
268 auto *XVec = dyn_cast<FixedVectorType>(Ty);
269 unsigned XVecSize = XVec->getNumElements();
270 Value *Sum = Builder.CreateExtractElement(X, static_cast<uint64_t>(0));
271
272 // Handle the initial start value for floating-point addition.
273 if (IsFAdd) {
274 Constant *StartValue = dyn_cast<Constant>(Orig->getOperand(0));
275 if (StartValue && !StartValue->isZeroValue())
276 Sum = Builder.CreateFAdd(Sum, StartValue);
277 }
278
279 // Accumulate the remaining vector elements.
280 for (unsigned I = 1; I < XVecSize; I++) {
281 Value *Elt = Builder.CreateExtractElement(X, I);
282 if (IsFAdd)
283 Sum = Builder.CreateFAdd(Sum, Elt);
284 else
285 Sum = Builder.CreateAdd(Sum, Elt);
286 }
287
288 return Sum;
289}
290
291static Value *expandAbs(CallInst *Orig) {
292 Value *X = Orig->getOperand(0);
293 IRBuilder<> Builder(Orig);
294 Type *Ty = X->getType();
295 Type *EltTy = Ty->getScalarType();
296 Constant *Zero = Ty->isVectorTy()
300 ConstantInt::get(EltTy, 0))
301 : ConstantInt::get(EltTy, 0);
302 auto *V = Builder.CreateSub(Zero, X);
303 return Builder.CreateIntrinsic(Ty, Intrinsic::smax, {X, V}, nullptr,
304 "dx.max");
305}
306
308
309 VectorType *VT = cast<VectorType>(Orig->getType());
311 reportFatalUsageError("return vector must have exactly 3 elements");
312
313 Value *op0 = Orig->getOperand(0);
314 Value *op1 = Orig->getOperand(1);
315 IRBuilder<> Builder(Orig);
316
317 Value *op0_x = Builder.CreateExtractElement(op0, (uint64_t)0, "x0");
318 Value *op0_y = Builder.CreateExtractElement(op0, 1, "x1");
319 Value *op0_z = Builder.CreateExtractElement(op0, 2, "x2");
320
321 Value *op1_x = Builder.CreateExtractElement(op1, (uint64_t)0, "y0");
322 Value *op1_y = Builder.CreateExtractElement(op1, 1, "y1");
323 Value *op1_z = Builder.CreateExtractElement(op1, 2, "y2");
324
325 auto MulSub = [&](Value *x0, Value *y0, Value *x1, Value *y1) -> Value * {
326 Value *xy = Builder.CreateFMul(x0, y1);
327 Value *yx = Builder.CreateFMul(y0, x1);
328 return Builder.CreateFSub(xy, yx, Orig->getName());
329 };
330
331 Value *yz_zy = MulSub(op0_y, op0_z, op1_y, op1_z);
332 Value *zx_xz = MulSub(op0_z, op0_x, op1_z, op1_x);
333 Value *xy_yx = MulSub(op0_x, op0_y, op1_x, op1_y);
334
335 Value *cross = PoisonValue::get(VT);
336 cross = Builder.CreateInsertElement(cross, yz_zy, (uint64_t)0);
337 cross = Builder.CreateInsertElement(cross, zx_xz, 1);
338 cross = Builder.CreateInsertElement(cross, xy_yx, 2);
339 return cross;
340}
341
342// Create appropriate DXIL float dot intrinsic for the given A and B operands
343// The appropriate opcode will be determined by the size of the operands
344// The dot product is placed in the position indicated by Orig
346 Type *ATy = A->getType();
347 [[maybe_unused]] Type *BTy = B->getType();
348 assert(ATy->isVectorTy() && BTy->isVectorTy());
349
350 IRBuilder<> Builder(Orig);
351
352 auto *AVec = dyn_cast<FixedVectorType>(ATy);
353
355
356 Intrinsic::ID DotIntrinsic = Intrinsic::dx_dot4;
357 int NumElts = AVec->getNumElements();
358 switch (NumElts) {
359 case 2:
360 DotIntrinsic = Intrinsic::dx_dot2;
361 break;
362 case 3:
363 DotIntrinsic = Intrinsic::dx_dot3;
364 break;
365 case 4:
366 DotIntrinsic = Intrinsic::dx_dot4;
367 break;
368 default:
370 "Invalid dot product input vector: length is outside 2-4");
371 return nullptr;
372 }
373
375 for (int I = 0; I < NumElts; ++I)
376 Args.push_back(Builder.CreateExtractElement(A, Builder.getInt32(I)));
377 for (int I = 0; I < NumElts; ++I)
378 Args.push_back(Builder.CreateExtractElement(B, Builder.getInt32(I)));
379 return Builder.CreateIntrinsic(ATy->getScalarType(), DotIntrinsic, Args,
380 nullptr, "dot");
381}
382
383// Create the appropriate DXIL float dot intrinsic for the operands of Orig
384// The appropriate opcode will be determined by the size of the operands
385// The dot product is placed in the position indicated by Orig
387 return expandFloatDotIntrinsic(Orig, Orig->getOperand(0),
388 Orig->getOperand(1));
389}
390
391// Expand integer dot product to multiply and add ops
393 Intrinsic::ID DotIntrinsic) {
394 assert(DotIntrinsic == Intrinsic::dx_sdot ||
395 DotIntrinsic == Intrinsic::dx_udot);
396 Value *A = Orig->getOperand(0);
397 Value *B = Orig->getOperand(1);
398 Type *ATy = A->getType();
399 [[maybe_unused]] Type *BTy = B->getType();
400 assert(ATy->isVectorTy() && BTy->isVectorTy());
401
402 IRBuilder<> Builder(Orig);
403
404 auto *AVec = dyn_cast<FixedVectorType>(ATy);
405
407
408 Value *Result;
409 Intrinsic::ID MadIntrinsic = DotIntrinsic == Intrinsic::dx_sdot
410 ? Intrinsic::dx_imad
411 : Intrinsic::dx_umad;
412 Value *Elt0 = Builder.CreateExtractElement(A, (uint64_t)0);
413 Value *Elt1 = Builder.CreateExtractElement(B, (uint64_t)0);
414 Result = Builder.CreateMul(Elt0, Elt1);
415 for (unsigned I = 1; I < AVec->getNumElements(); I++) {
416 Elt0 = Builder.CreateExtractElement(A, I);
417 Elt1 = Builder.CreateExtractElement(B, I);
418 Result = Builder.CreateIntrinsic(Result->getType(), MadIntrinsic,
419 ArrayRef<Value *>{Elt0, Elt1, Result},
420 nullptr, "dx.mad");
421 }
422 return Result;
423}
424
426 Value *X = Orig->getOperand(0);
427 IRBuilder<> Builder(Orig);
428 Type *Ty = X->getType();
429 Type *EltTy = Ty->getScalarType();
430 Constant *Log2eConst =
431 Ty->isVectorTy() ? ConstantVector::getSplat(
434 ConstantFP::get(EltTy, numbers::log2ef))
435 : ConstantFP::get(EltTy, numbers::log2ef);
436 Value *NewX = Builder.CreateFMul(Log2eConst, X);
437 auto *Exp2Call =
438 Builder.CreateIntrinsic(Ty, Intrinsic::exp2, {NewX}, nullptr, "dx.exp2");
439 Exp2Call->setTailCall(Orig->isTailCall());
440 Exp2Call->setAttributes(Orig->getAttributes());
441 return Exp2Call;
442}
443
445 Value *T = Orig->getArgOperand(1);
446 auto *TCI = dyn_cast<ConstantInt>(T);
447
448 // These FPClassTest cases have DXIL opcodes, so they will be handled in
449 // DXIL Op Lowering instead for all non f16 cases.
450 switch (TCI->getZExtValue()) {
452 return expand16BitIsInf(Orig);
454 return expand16BitIsNaN(Orig);
456 return expand16BitIsNormal(Orig);
458 return expand16BitIsFinite(Orig);
459 }
460
461 IRBuilder<> Builder(Orig);
462
463 Value *F = Orig->getArgOperand(0);
464 Type *FTy = F->getType();
465 unsigned FNumElem = 0; // 0 => F is not a vector
466
467 unsigned BitWidth; // Bit width of F or the ElemTy of F
468 Type *BitCastTy; // An IntNTy of the same bitwidth as F or ElemTy of F
469
470 if (auto *FVecTy = dyn_cast<FixedVectorType>(FTy)) {
471 Type *ElemTy = FVecTy->getElementType();
472 FNumElem = FVecTy->getNumElements();
473 BitWidth = ElemTy->getPrimitiveSizeInBits();
474 BitCastTy = FixedVectorType::get(Builder.getIntNTy(BitWidth), FNumElem);
475 } else {
477 BitCastTy = Builder.getIntNTy(BitWidth);
478 }
479
480 Value *FBitCast = Builder.CreateBitCast(F, BitCastTy);
481 switch (TCI->getZExtValue()) {
483 Value *NegZero =
484 ConstantInt::get(Builder.getIntNTy(BitWidth), 1 << (BitWidth - 1));
485 Value *RetVal;
486 if (FNumElem) {
487 Value *NegZeroSplat = Builder.CreateVectorSplat(FNumElem, NegZero);
488 RetVal =
489 Builder.CreateICmpEQ(FBitCast, NegZeroSplat, "is.fpclass.negzero");
490 } else
491 RetVal = Builder.CreateICmpEQ(FBitCast, NegZero, "is.fpclass.negzero");
492 return RetVal;
493 }
494 default:
495 reportFatalUsageError("Unsupported FPClassTest");
496 }
497}
498
500 Intrinsic::ID IntrinsicId) {
501 Value *X = Orig->getOperand(0);
502 IRBuilder<> Builder(Orig);
503 Type *Ty = X->getType();
504 Type *EltTy = Ty->getScalarType();
505
506 auto ApplyOp = [&Builder](Intrinsic::ID IntrinsicId, Value *Result,
507 Value *Elt) {
508 if (IntrinsicId == Intrinsic::dx_any)
509 return Builder.CreateOr(Result, Elt);
510 assert(IntrinsicId == Intrinsic::dx_all);
511 return Builder.CreateAnd(Result, Elt);
512 };
513
514 Value *Result = nullptr;
515 if (!Ty->isVectorTy()) {
516 Result = EltTy->isFloatingPointTy()
517 ? Builder.CreateFCmpUNE(X, ConstantFP::get(EltTy, 0))
518 : Builder.CreateICmpNE(X, ConstantInt::get(EltTy, 0));
519 } else {
520 auto *XVec = dyn_cast<FixedVectorType>(Ty);
521 Value *Cond =
522 EltTy->isFloatingPointTy()
523 ? Builder.CreateFCmpUNE(
525 ElementCount::getFixed(XVec->getNumElements()),
526 ConstantFP::get(EltTy, 0)))
527 : Builder.CreateICmpNE(
529 ElementCount::getFixed(XVec->getNumElements()),
530 ConstantInt::get(EltTy, 0)));
531 Result = Builder.CreateExtractElement(Cond, (uint64_t)0);
532 for (unsigned I = 1; I < XVec->getNumElements(); I++) {
533 Value *Elt = Builder.CreateExtractElement(Cond, I);
534 Result = ApplyOp(IntrinsicId, Result, Elt);
535 }
536 }
537 return Result;
538}
539
541 Value *X = Orig->getOperand(0);
542 Value *Y = Orig->getOperand(1);
543 Value *S = Orig->getOperand(2);
544 IRBuilder<> Builder(Orig);
545 auto *V = Builder.CreateFSub(Y, X);
546 V = Builder.CreateFMul(S, V);
547 return Builder.CreateFAdd(X, V, "dx.lerp");
548}
549
551 float LogConstVal = numbers::ln2f) {
552 Value *X = Orig->getOperand(0);
553 IRBuilder<> Builder(Orig);
554 Type *Ty = X->getType();
555 Type *EltTy = Ty->getScalarType();
556 Constant *Ln2Const =
557 Ty->isVectorTy() ? ConstantVector::getSplat(
560 ConstantFP::get(EltTy, LogConstVal))
561 : ConstantFP::get(EltTy, LogConstVal);
562 auto *Log2Call =
563 Builder.CreateIntrinsic(Ty, Intrinsic::log2, {X}, nullptr, "elt.log2");
564 Log2Call->setTailCall(Orig->isTailCall());
565 Log2Call->setAttributes(Orig->getAttributes());
566 return Builder.CreateFMul(Ln2Const, Log2Call);
567}
571
572// Use dot product of vector operand with itself to calculate the length.
573// Divide the vector by that length to normalize it.
575 Value *X = Orig->getOperand(0);
576 Type *Ty = Orig->getType();
577 Type *EltTy = Ty->getScalarType();
578 IRBuilder<> Builder(Orig);
579
580 auto *XVec = dyn_cast<FixedVectorType>(Ty);
581 if (!XVec) {
582 if (auto *constantFP = dyn_cast<ConstantFP>(X)) {
583 const APFloat &fpVal = constantFP->getValueAPF();
584 if (fpVal.isZero())
585 reportFatalUsageError("Invalid input scalar: length is zero");
586 }
587 return Builder.CreateFDiv(X, X);
588 }
589
590 Value *DotProduct = expandFloatDotIntrinsic(Orig, X, X);
591
592 // verify that the length is non-zero
593 // (if the dot product is non-zero, then the length is non-zero)
594 if (auto *constantFP = dyn_cast<ConstantFP>(DotProduct)) {
595 const APFloat &fpVal = constantFP->getValueAPF();
596 if (fpVal.isZero())
597 reportFatalUsageError("Invalid input vector: length is zero");
598 }
599
600 Value *Multiplicand = Builder.CreateIntrinsic(EltTy, Intrinsic::dx_rsqrt,
601 ArrayRef<Value *>{DotProduct},
602 nullptr, "dx.rsqrt");
603
604 Value *MultiplicandVec =
605 Builder.CreateVectorSplat(XVec->getNumElements(), Multiplicand);
606 return Builder.CreateFMul(X, MultiplicandVec);
607}
608
610 Value *Y = Orig->getOperand(0);
611 Value *X = Orig->getOperand(1);
612 Type *Ty = X->getType();
613 IRBuilder<> Builder(Orig);
614 Builder.setFastMathFlags(Orig->getFastMathFlags());
615
616 Value *Tan = Builder.CreateFDiv(Y, X);
617
618 CallInst *Atan =
619 Builder.CreateIntrinsic(Ty, Intrinsic::atan, {Tan}, nullptr, "Elt.Atan");
620 Atan->setTailCall(Orig->isTailCall());
621 Atan->setAttributes(Orig->getAttributes());
622
623 // Modify atan result based on https://en.wikipedia.org/wiki/Atan2.
624 Constant *Pi = ConstantFP::get(Ty, llvm::numbers::pi);
625 Constant *HalfPi = ConstantFP::get(Ty, llvm::numbers::pi / 2);
626 Constant *NegHalfPi = ConstantFP::get(Ty, -llvm::numbers::pi / 2);
627 Constant *Zero = ConstantFP::get(Ty, 0);
628 Value *AtanAddPi = Builder.CreateFAdd(Atan, Pi);
629 Value *AtanSubPi = Builder.CreateFSub(Atan, Pi);
630
631 // x > 0 -> atan.
632 Value *Result = Atan;
633 Value *XLt0 = Builder.CreateFCmpOLT(X, Zero);
634 Value *XEq0 = Builder.CreateFCmpOEQ(X, Zero);
635 Value *YGe0 = Builder.CreateFCmpOGE(Y, Zero);
636 Value *YLt0 = Builder.CreateFCmpOLT(Y, Zero);
637
638 // x < 0, y >= 0 -> atan + pi.
639 Value *XLt0AndYGe0 = Builder.CreateAnd(XLt0, YGe0);
640 Result = Builder.CreateSelect(XLt0AndYGe0, AtanAddPi, Result);
641
642 // x < 0, y < 0 -> atan - pi.
643 Value *XLt0AndYLt0 = Builder.CreateAnd(XLt0, YLt0);
644 Result = Builder.CreateSelect(XLt0AndYLt0, AtanSubPi, Result);
645
646 // x == 0, y < 0 -> -pi/2
647 Value *XEq0AndYLt0 = Builder.CreateAnd(XEq0, YLt0);
648 Result = Builder.CreateSelect(XEq0AndYLt0, NegHalfPi, Result);
649
650 // x == 0, y > 0 -> pi/2
651 Value *XEq0AndYGe0 = Builder.CreateAnd(XEq0, YGe0);
652 Result = Builder.CreateSelect(XEq0AndYGe0, HalfPi, Result);
653
654 return Result;
655}
656
657static Value *expandPowIntrinsic(CallInst *Orig, Intrinsic::ID IntrinsicId) {
658
659 Value *X = Orig->getOperand(0);
660 Value *Y = Orig->getOperand(1);
661 Type *Ty = X->getType();
662 IRBuilder<> Builder(Orig);
663
664 if (IntrinsicId == Intrinsic::powi)
665 Y = Builder.CreateSIToFP(Y, Ty);
666
667 auto *Log2Call =
668 Builder.CreateIntrinsic(Ty, Intrinsic::log2, {X}, nullptr, "elt.log2");
669 auto *Mul = Builder.CreateFMul(Log2Call, Y);
670 auto *Exp2Call =
671 Builder.CreateIntrinsic(Ty, Intrinsic::exp2, {Mul}, nullptr, "elt.exp2");
672 Exp2Call->setTailCall(Orig->isTailCall());
673 Exp2Call->setAttributes(Orig->getAttributes());
674 return Exp2Call;
675}
676
678
679 Value *X = Orig->getOperand(0);
680 Value *Y = Orig->getOperand(1);
681 Type *Ty = X->getType();
682 IRBuilder<> Builder(Orig);
683
684 Constant *One = ConstantFP::get(Ty->getScalarType(), 1.0);
685 Constant *Zero = ConstantFP::get(Ty->getScalarType(), 0.0);
686 Value *Cond = Builder.CreateFCmpOLT(Y, X);
687
688 if (Ty != Ty->getScalarType()) {
689 auto *XVec = dyn_cast<FixedVectorType>(Ty);
691 ElementCount::getFixed(XVec->getNumElements()), One);
693 ElementCount::getFixed(XVec->getNumElements()), Zero);
694 }
695
696 return Builder.CreateSelect(Cond, Zero, One);
697}
698
700 Value *X = Orig->getOperand(0);
701 Type *Ty = X->getType();
702 IRBuilder<> Builder(Orig);
703 Value *PiOver180 = ConstantFP::get(Ty, llvm::numbers::pi / 180.0);
704 return Builder.CreateFMul(X, PiOver180);
705}
706
707static bool expandBufferLoadIntrinsic(CallInst *Orig, bool IsRaw) {
708 IRBuilder<> Builder(Orig);
709
710 Type *BufferTy = Orig->getType()->getStructElementType(0);
711 Type *ScalarTy = BufferTy->getScalarType();
712 bool IsDouble = ScalarTy->isDoubleTy();
713 assert(IsDouble || ScalarTy->isIntegerTy(64) &&
714 "Only expand double or int64 scalars or vectors");
715 bool IsVector = false;
716 unsigned ExtractNum = 2;
717 if (auto *VT = dyn_cast<FixedVectorType>(BufferTy)) {
718 ExtractNum = 2 * VT->getNumElements();
719 IsVector = true;
720 assert(IsRaw || ExtractNum == 4 && "TypedBufferLoad vector must be size 2");
721 }
722
724 Value *Result = PoisonValue::get(BufferTy);
725 unsigned Base = 0;
726 // If we need to extract more than 4 i32; we need to break it up into
727 // more than one load. LoadNum tells us how many i32s we are loading in
728 // each load
729 while (ExtractNum > 0) {
730 unsigned LoadNum = std::min(ExtractNum, 4u);
731 Type *Ty = VectorType::get(Builder.getInt32Ty(), LoadNum, false);
732
733 Type *LoadType = StructType::get(Ty, Builder.getInt1Ty());
734 Intrinsic::ID LoadIntrinsic = Intrinsic::dx_resource_load_typedbuffer;
735 SmallVector<Value *, 3> Args = {Orig->getOperand(0), Orig->getOperand(1)};
736 if (IsRaw) {
737 LoadIntrinsic = Intrinsic::dx_resource_load_rawbuffer;
738 Value *Tmp = Builder.getInt32(4 * Base * 2);
739 Args.push_back(Builder.CreateAdd(Orig->getOperand(2), Tmp));
740 }
741
742 CallInst *Load = Builder.CreateIntrinsic(LoadType, LoadIntrinsic, Args);
743 Loads.push_back(Load);
744
745 // extract the buffer load's result
746 Value *Extract = Builder.CreateExtractValue(Load, {0});
747
748 SmallVector<Value *> ExtractElements;
749 for (unsigned I = 0; I < LoadNum; ++I)
750 ExtractElements.push_back(
751 Builder.CreateExtractElement(Extract, Builder.getInt32(I)));
752
753 // combine into double(s) or int64(s)
754 for (unsigned I = 0; I < LoadNum; I += 2) {
755 Value *Combined = nullptr;
756 if (IsDouble)
757 // For doubles, use dx_asdouble intrinsic
758 Combined = Builder.CreateIntrinsic(
759 Builder.getDoubleTy(), Intrinsic::dx_asdouble,
760 {ExtractElements[I], ExtractElements[I + 1]});
761 else {
762 // For int64, manually combine two int32s
763 // First, zero-extend both values to i64
764 Value *Lo =
765 Builder.CreateZExt(ExtractElements[I], Builder.getInt64Ty());
766 Value *Hi =
767 Builder.CreateZExt(ExtractElements[I + 1], Builder.getInt64Ty());
768 // Shift the high bits left by 32 bits
769 Value *ShiftedHi = Builder.CreateShl(Hi, Builder.getInt64(32));
770 // OR the high and low bits together
771 Combined = Builder.CreateOr(Lo, ShiftedHi);
772 }
773
774 if (IsVector)
775 Result = Builder.CreateInsertElement(Result, Combined,
776 Builder.getInt32((I / 2) + Base));
777 else
778 Result = Combined;
779 }
780
781 ExtractNum -= LoadNum;
782 Base += LoadNum / 2;
783 }
784
785 Value *CheckBit = nullptr;
786 for (User *U : make_early_inc_range(Orig->users())) {
787 // If it's not a ExtractValueInst, we don't know how to
788 // handle it
789 auto *EVI = dyn_cast<ExtractValueInst>(U);
790 if (!EVI)
791 llvm_unreachable("Unexpected user of typedbufferload");
792
793 ArrayRef<unsigned> Indices = EVI->getIndices();
794 assert(Indices.size() == 1);
795
796 if (Indices[0] == 0) {
797 // Use of the value(s)
798 EVI->replaceAllUsesWith(Result);
799 } else {
800 // Use of the check bit
801 assert(Indices[0] == 1 && "Unexpected type for typedbufferload");
802 // Note: This does not always match the historical behaviour of DXC.
803 // See https://github.com/microsoft/DirectXShaderCompiler/issues/7622
804 if (!CheckBit) {
805 SmallVector<Value *, 2> CheckBits;
806 for (Value *L : Loads)
807 CheckBits.push_back(Builder.CreateExtractValue(L, {1}));
808 CheckBit = Builder.CreateAnd(CheckBits);
809 }
810 EVI->replaceAllUsesWith(CheckBit);
811 }
812 EVI->eraseFromParent();
813 }
814 Orig->eraseFromParent();
815 return true;
816}
817
818static bool expandBufferStoreIntrinsic(CallInst *Orig, bool IsRaw) {
819 IRBuilder<> Builder(Orig);
820
821 unsigned ValIndex = IsRaw ? 3 : 2;
822 Type *BufferTy = Orig->getFunctionType()->getParamType(ValIndex);
823 Type *ScalarTy = BufferTy->getScalarType();
824 bool IsDouble = ScalarTy->isDoubleTy();
825 assert((IsDouble || ScalarTy->isIntegerTy(64)) &&
826 "Only expand double or int64 scalars or vectors");
827
828 // Determine if we're dealing with a vector or scalar
829 bool IsVector = false;
830 unsigned ExtractNum = 2;
831 unsigned VecLen = 0;
832 if (auto *VT = dyn_cast<FixedVectorType>(BufferTy)) {
833 VecLen = VT->getNumElements();
834 assert(IsRaw || VecLen == 2 && "TypedBufferStore vector must be size 2");
835 ExtractNum = VecLen * 2;
836 IsVector = true;
837 }
838
839 // Create the appropriate vector type for the result
840 Type *Int32Ty = Builder.getInt32Ty();
841 Type *ResultTy = VectorType::get(Int32Ty, ExtractNum, false);
842 Value *Val = PoisonValue::get(ResultTy);
843
844 Type *SplitElementTy = Int32Ty;
845 if (IsVector)
846 SplitElementTy = VectorType::get(SplitElementTy, VecLen, false);
847
848 Value *LowBits = nullptr;
849 Value *HighBits = nullptr;
850 // Split the 64-bit values into 32-bit components
851 if (IsDouble) {
852 auto *SplitTy = llvm::StructType::get(SplitElementTy, SplitElementTy);
853 Value *Split = Builder.CreateIntrinsic(SplitTy, Intrinsic::dx_splitdouble,
854 {Orig->getOperand(ValIndex)});
855 LowBits = Builder.CreateExtractValue(Split, 0);
856 HighBits = Builder.CreateExtractValue(Split, 1);
857 } else {
858 // Handle int64 type(s)
859 Value *InputVal = Orig->getOperand(ValIndex);
860 Constant *ShiftAmt = Builder.getInt64(32);
861 if (IsVector)
862 ShiftAmt =
864
865 // Split into low and high 32-bit parts
866 LowBits = Builder.CreateTrunc(InputVal, SplitElementTy);
867 Value *ShiftedVal = Builder.CreateLShr(InputVal, ShiftAmt);
868 HighBits = Builder.CreateTrunc(ShiftedVal, SplitElementTy);
869 }
870
871 if (IsVector) {
873 for (unsigned I = 0; I < VecLen; ++I) {
874 Mask.push_back(I);
875 Mask.push_back(I + VecLen);
876 }
877 Val = Builder.CreateShuffleVector(LowBits, HighBits, Mask);
878 } else {
879 Val = Builder.CreateInsertElement(Val, LowBits, Builder.getInt32(0));
880 Val = Builder.CreateInsertElement(Val, HighBits, Builder.getInt32(1));
881 }
882
883 // If we need to extract more than 4 i32; we need to break it up into
884 // more than one store. StoreNum tells us how many i32s we are storing in
885 // each store
886 unsigned Base = 0;
887 while (ExtractNum > 0) {
888 unsigned StoreNum = std::min(ExtractNum, 4u);
889
890 Intrinsic::ID StoreIntrinsic = Intrinsic::dx_resource_store_typedbuffer;
891 SmallVector<Value *, 4> Args = {Orig->getOperand(0), Orig->getOperand(1)};
892 if (IsRaw) {
893 StoreIntrinsic = Intrinsic::dx_resource_store_rawbuffer;
894 Value *Tmp = Builder.getInt32(4 * Base);
895 Args.push_back(Builder.CreateAdd(Orig->getOperand(2), Tmp));
896 }
897
899 for (unsigned I = 0; I < StoreNum; ++I) {
900 Mask.push_back(Base + I);
901 }
902
903 Value *SubVal = Val;
904 if (VecLen > 2)
905 SubVal = Builder.CreateShuffleVector(Val, Mask);
906
907 Args.push_back(SubVal);
908 // Create the final intrinsic call
909 Builder.CreateIntrinsic(Builder.getVoidTy(), StoreIntrinsic, Args);
910
911 ExtractNum -= StoreNum;
912 Base += StoreNum;
913 }
914 Orig->eraseFromParent();
915 return true;
916}
917
919 if (ClampIntrinsic == Intrinsic::dx_uclamp)
920 return Intrinsic::umax;
921 if (ClampIntrinsic == Intrinsic::dx_sclamp)
922 return Intrinsic::smax;
923 assert(ClampIntrinsic == Intrinsic::dx_nclamp);
924 return Intrinsic::maxnum;
925}
926
928 if (ClampIntrinsic == Intrinsic::dx_uclamp)
929 return Intrinsic::umin;
930 if (ClampIntrinsic == Intrinsic::dx_sclamp)
931 return Intrinsic::smin;
932 assert(ClampIntrinsic == Intrinsic::dx_nclamp);
933 return Intrinsic::minnum;
934}
935
937 Intrinsic::ID ClampIntrinsic) {
938 Value *X = Orig->getOperand(0);
939 Value *Min = Orig->getOperand(1);
940 Value *Max = Orig->getOperand(2);
941 Type *Ty = X->getType();
942 IRBuilder<> Builder(Orig);
943 auto *MaxCall = Builder.CreateIntrinsic(Ty, getMaxForClamp(ClampIntrinsic),
944 {X, Min}, nullptr, "dx.max");
945 return Builder.CreateIntrinsic(Ty, getMinForClamp(ClampIntrinsic),
946 {MaxCall, Max}, nullptr, "dx.min");
947}
948
950 Value *X = Orig->getOperand(0);
951 Type *Ty = X->getType();
952 IRBuilder<> Builder(Orig);
953 Value *DegreesRatio = ConstantFP::get(Ty, 180.0 * llvm::numbers::inv_pi);
954 return Builder.CreateFMul(X, DegreesRatio);
955}
956
958 Value *X = Orig->getOperand(0);
959 Type *Ty = X->getType();
960 Type *ScalarTy = Ty->getScalarType();
961 Type *RetTy = Orig->getType();
963
964 IRBuilder<> Builder(Orig);
965
966 Value *GT;
967 Value *LT;
968 if (ScalarTy->isFloatingPointTy()) {
969 GT = Builder.CreateFCmpOLT(Zero, X);
970 LT = Builder.CreateFCmpOLT(X, Zero);
971 } else {
972 assert(ScalarTy->isIntegerTy());
973 GT = Builder.CreateICmpSLT(Zero, X);
974 LT = Builder.CreateICmpSLT(X, Zero);
975 }
976
977 Value *ZextGT = Builder.CreateZExt(GT, RetTy);
978 Value *ZextLT = Builder.CreateZExt(LT, RetTy);
979
980 return Builder.CreateSub(ZextGT, ZextLT);
981}
982
983static bool expandIntrinsic(Function &F, CallInst *Orig) {
984 Value *Result = nullptr;
985 Intrinsic::ID IntrinsicId = F.getIntrinsicID();
986 switch (IntrinsicId) {
987 case Intrinsic::abs:
988 Result = expandAbs(Orig);
989 break;
990 case Intrinsic::atan2:
991 Result = expandAtan2Intrinsic(Orig);
992 break;
993 case Intrinsic::exp:
994 Result = expandExpIntrinsic(Orig);
995 break;
996 case Intrinsic::is_fpclass:
997 Result = expandIsFPClass(Orig);
998 break;
999 case Intrinsic::log:
1000 Result = expandLogIntrinsic(Orig);
1001 break;
1002 case Intrinsic::log10:
1003 Result = expandLog10Intrinsic(Orig);
1004 break;
1005 case Intrinsic::pow:
1006 case Intrinsic::powi:
1007 Result = expandPowIntrinsic(Orig, IntrinsicId);
1008 break;
1009 case Intrinsic::dx_all:
1010 case Intrinsic::dx_any:
1011 Result = expandAnyOrAllIntrinsic(Orig, IntrinsicId);
1012 break;
1013 case Intrinsic::dx_cross:
1014 Result = expandCrossIntrinsic(Orig);
1015 break;
1016 case Intrinsic::dx_uclamp:
1017 case Intrinsic::dx_sclamp:
1018 case Intrinsic::dx_nclamp:
1019 Result = expandClampIntrinsic(Orig, IntrinsicId);
1020 break;
1021 case Intrinsic::dx_degrees:
1022 Result = expandDegreesIntrinsic(Orig);
1023 break;
1024 case Intrinsic::dx_isinf:
1025 Result = expand16BitIsInf(Orig);
1026 break;
1027 case Intrinsic::dx_lerp:
1028 Result = expandLerpIntrinsic(Orig);
1029 break;
1030 case Intrinsic::dx_normalize:
1031 Result = expandNormalizeIntrinsic(Orig);
1032 break;
1033 case Intrinsic::dx_fdot:
1034 Result = expandFloatDotIntrinsic(Orig);
1035 break;
1036 case Intrinsic::dx_sdot:
1037 case Intrinsic::dx_udot:
1038 Result = expandIntegerDotIntrinsic(Orig, IntrinsicId);
1039 break;
1040 case Intrinsic::dx_sign:
1041 Result = expandSignIntrinsic(Orig);
1042 break;
1043 case Intrinsic::dx_step:
1044 Result = expandStepIntrinsic(Orig);
1045 break;
1046 case Intrinsic::dx_radians:
1047 Result = expandRadiansIntrinsic(Orig);
1048 break;
1049 case Intrinsic::dx_resource_load_rawbuffer:
1050 if (expandBufferLoadIntrinsic(Orig, /*IsRaw*/ true))
1051 return true;
1052 break;
1053 case Intrinsic::dx_resource_store_rawbuffer:
1054 if (expandBufferStoreIntrinsic(Orig, /*IsRaw*/ true))
1055 return true;
1056 break;
1057 case Intrinsic::dx_resource_load_typedbuffer:
1058 if (expandBufferLoadIntrinsic(Orig, /*IsRaw*/ false))
1059 return true;
1060 break;
1061 case Intrinsic::dx_resource_store_typedbuffer:
1062 if (expandBufferStoreIntrinsic(Orig, /*IsRaw*/ false))
1063 return true;
1064 break;
1065 case Intrinsic::usub_sat:
1066 Result = expandUsubSat(Orig);
1067 break;
1068 case Intrinsic::vector_reduce_add:
1069 case Intrinsic::vector_reduce_fadd:
1070 Result = expandVecReduceAdd(Orig, IntrinsicId);
1071 break;
1072 }
1073 if (Result) {
1074 Orig->replaceAllUsesWith(Result);
1075 Orig->eraseFromParent();
1076 return true;
1077 }
1078 return false;
1079}
1080
1082 for (auto &F : make_early_inc_range(M.functions())) {
1083 if (!isIntrinsicExpansion(F))
1084 continue;
1085 bool IntrinsicExpanded = false;
1086 for (User *U : make_early_inc_range(F.users())) {
1087 auto *IntrinsicCall = dyn_cast<CallInst>(U);
1088 if (!IntrinsicCall)
1089 continue;
1090 IntrinsicExpanded = expandIntrinsic(F, IntrinsicCall);
1091 }
1092 if (F.user_empty() && IntrinsicExpanded)
1093 F.eraseFromParent();
1094 }
1095 return true;
1096}
1097
1104
1108
1110
1112 "DXIL Intrinsic Expansion", false, false)
1114 "DXIL Intrinsic Expansion", false, false)
1115
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static Value * expand16BitIsNormal(CallInst *Orig)
static Value * expandNormalizeIntrinsic(CallInst *Orig)
static bool expandIntrinsic(Function &F, CallInst *Orig)
static Value * expandClampIntrinsic(CallInst *Orig, Intrinsic::ID ClampIntrinsic)
static Value * expand16BitIsInf(CallInst *Orig)
static bool expansionIntrinsics(Module &M)
static Value * expand16BitIsFinite(CallInst *Orig)
static Value * expandLerpIntrinsic(CallInst *Orig)
static Value * expandCrossIntrinsic(CallInst *Orig)
static Value * expandUsubSat(CallInst *Orig)
static Value * expandAnyOrAllIntrinsic(CallInst *Orig, Intrinsic::ID IntrinsicId)
static Value * expandVecReduceAdd(CallInst *Orig, Intrinsic::ID IntrinsicId)
static Value * expandAtan2Intrinsic(CallInst *Orig)
static Value * expandLog10Intrinsic(CallInst *Orig)
static Intrinsic::ID getMinForClamp(Intrinsic::ID ClampIntrinsic)
static Value * expandStepIntrinsic(CallInst *Orig)
static Value * expandIntegerDotIntrinsic(CallInst *Orig, Intrinsic::ID DotIntrinsic)
static bool expandBufferStoreIntrinsic(CallInst *Orig, bool IsRaw)
static Value * expandLogIntrinsic(CallInst *Orig, float LogConstVal=numbers::ln2f)
static Value * expandDegreesIntrinsic(CallInst *Orig)
static Value * expandPowIntrinsic(CallInst *Orig, Intrinsic::ID IntrinsicId)
static bool resourceAccessNeeds64BitExpansion(Module *M, Type *OverloadTy, bool IsRaw)
static Value * expandExpIntrinsic(CallInst *Orig)
static Value * expand16BitIsNaN(CallInst *Orig)
static Value * expandSignIntrinsic(CallInst *Orig)
static Intrinsic::ID getMaxForClamp(Intrinsic::ID ClampIntrinsic)
static Value * expandAbs(CallInst *Orig)
static Value * expandFloatDotIntrinsic(CallInst *Orig, Value *A, Value *B)
static Value * expandRadiansIntrinsic(CallInst *Orig)
static bool isIntrinsicExpansion(Function &F)
static bool expandBufferLoadIntrinsic(CallInst *Orig, bool IsRaw)
static Value * expandIsFPClass(CallInst *Orig)
#define DEBUG_TYPE
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition MD5.cpp:55
#define I(x, y, z)
Definition MD5.cpp:58
#define T
#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
const SmallVectorImpl< MachineOperand > & Cond
static unsigned getNumElements(Type *Ty)
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallVector class.
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
BinaryOperator * Mul
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
bool isZero() const
Definition APFloat.h:1445
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition ArrayRef.h:147
void setAttributes(AttributeList A)
Set the attributes for this call.
Value * getArgOperand(unsigned i) const
FunctionType * getFunctionType() const
AttributeList getAttributes() const
Return the attributes for this call.
This class represents a function call, abstracting a target machine's calling convention.
bool isTailCall() const
void setTailCall(bool IsTc=true)
static LLVM_ABI Constant * getSplat(ElementCount EC, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
This is an important base class in LLVM.
Definition Constant.h:43
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
LLVM_ABI bool isZeroValue() const
Return true if the value is negative zero or null value.
Definition Constants.cpp:76
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition TypeSize.h:309
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition Type.cpp:803
Type * getParamType(unsigned i) const
Parameter type accessors.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2780
LLVM_ABI const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
LLVM_ABI FastMathFlags getFastMathFlags() const LLVM_READONLY
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition Pass.h:255
ModulePass(char &pid)
Definition Pass.h:257
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 none()
Convenience factory function for the empty preserved set.
Definition Analysis.h:115
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition Type.cpp:414
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
LLVM_ABI Type * getStructElementType(unsigned N) const
bool isVectorTy() const
True if this is an instance of VectorType.
Definition Type.h:273
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:352
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition Type.cpp:198
static LLVM_ABI IntegerType * getInt16Ty(LLVMContext &C)
Definition Type.cpp:296
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition Type.h:156
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
Definition Type.h:184
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:240
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition Type.cpp:301
Value * getOperand(unsigned i) const
Definition User.h:232
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:256
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
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:322
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Represents a version number in the form major[.minor[.subminor[.build]]].
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr double inv_pi
Definition MathExtras.h:54
constexpr float ln10f
Definition MathExtras.h:65
constexpr float log2ef
Definition MathExtras.h:66
constexpr double pi
Definition MathExtras.h:53
constexpr float ln2f
Definition MathExtras.h:64
This is an optimization pass for GlobalISel generic memory operations.
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
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:646
ModulePass * createDXILIntrinsicExpansionLegacyPass()
Pass to expand intrinsic operations that lack DXIL opCodes.
@ Sub
Subtraction of integers.
constexpr unsigned BitWidth
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
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:180