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/Constants.h"
19#include "llvm/IR/IRBuilder.h"
20#include "llvm/IR/InstrTypes.h"
21#include "llvm/IR/Instruction.h"
23#include "llvm/IR/Intrinsics.h"
24#include "llvm/IR/IntrinsicsDirectX.h"
25#include "llvm/IR/Module.h"
26#include "llvm/IR/PassManager.h"
27#include "llvm/IR/Type.h"
28#include "llvm/Pass.h"
32
33#define DEBUG_TYPE "dxil-intrinsic-expansion"
34
35using namespace llvm;
36
38
39public:
40 bool runOnModule(Module &M) override;
42
43 static char ID; // Pass identification.
44};
45
46static bool resourceAccessNeeds64BitExpansion(Module *M, Type *OverloadTy,
47 bool IsRaw) {
48 if (IsRaw && M->getTargetTriple().getDXILVersion() > VersionTuple(1, 2))
49 return false;
50
51 Type *ScalarTy = OverloadTy->getScalarType();
52 return ScalarTy->isDoubleTy() || ScalarTy->isIntegerTy(64);
53}
54
56 Module *M = Orig->getModule();
57 if (M->getTargetTriple().getDXILVersion() >= VersionTuple(1, 9))
58 return nullptr;
59
60 Value *Val = Orig->getOperand(0);
61 Type *ValTy = Val->getType();
62 if (!ValTy->getScalarType()->isHalfTy())
63 return nullptr;
64
65 IRBuilder<> Builder(Orig);
66 Type *IType = Type::getInt16Ty(M->getContext());
67 Constant *PosInf =
68 ValTy->isVectorTy()
72 ConstantInt::get(IType, 0x7c00))
73 : ConstantInt::get(IType, 0x7c00);
74
75 Constant *NegInf =
76 ValTy->isVectorTy()
80 ConstantInt::get(IType, 0xfc00))
81 : ConstantInt::get(IType, 0xfc00);
82
83 Value *IVal = Builder.CreateBitCast(Val, PosInf->getType());
84 Value *B1 = Builder.CreateICmpEQ(IVal, PosInf);
85 Value *B2 = Builder.CreateICmpEQ(IVal, NegInf);
86 Value *B3 = Builder.CreateOr(B1, B2);
87 return B3;
88}
89
91 Module *M = Orig->getModule();
92 if (M->getTargetTriple().getDXILVersion() >= VersionTuple(1, 9))
93 return nullptr;
94
95 Value *Val = Orig->getOperand(0);
96 Type *ValTy = Val->getType();
97 if (!ValTy->getScalarType()->isHalfTy())
98 return nullptr;
99
100 IRBuilder<> Builder(Orig);
101 Type *IType = Type::getInt16Ty(M->getContext());
102
103 Constant *ExpBitMask =
104 ValTy->isVectorTy()
108 ConstantInt::get(IType, 0x7c00))
109 : ConstantInt::get(IType, 0x7c00);
110 Constant *SigBitMask =
111 ValTy->isVectorTy()
115 ConstantInt::get(IType, 0x3ff))
116 : ConstantInt::get(IType, 0x3ff);
117
118 Constant *Zero =
119 ValTy->isVectorTy()
123 ConstantInt::get(IType, 0))
124 : ConstantInt::get(IType, 0);
125
126 Value *IVal = Builder.CreateBitCast(Val, ExpBitMask->getType());
127 Value *Exp = Builder.CreateAnd(IVal, ExpBitMask);
128 Value *B1 = Builder.CreateICmpEQ(Exp, ExpBitMask);
129
130 Value *Sig = Builder.CreateAnd(IVal, SigBitMask);
131 Value *B2 = Builder.CreateICmpNE(Sig, Zero);
132 Value *B3 = Builder.CreateAnd(B1, B2);
133 return B3;
134}
135
137 Module *M = Orig->getModule();
138 if (M->getTargetTriple().getDXILVersion() >= VersionTuple(1, 9))
139 return nullptr;
140
141 Value *Val = Orig->getOperand(0);
142 Type *ValTy = Val->getType();
143 if (!ValTy->getScalarType()->isHalfTy())
144 return nullptr;
145
146 IRBuilder<> Builder(Orig);
147 Type *IType = Type::getInt16Ty(M->getContext());
148
149 Constant *ExpBitMask =
150 ValTy->isVectorTy()
154 ConstantInt::get(IType, 0x7c00))
155 : ConstantInt::get(IType, 0x7c00);
156
157 Value *IVal = Builder.CreateBitCast(Val, ExpBitMask->getType());
158 Value *Exp = Builder.CreateAnd(IVal, ExpBitMask);
159 Value *B1 = Builder.CreateICmpNE(Exp, ExpBitMask);
160 return B1;
161}
162
164 Module *M = Orig->getModule();
165 if (M->getTargetTriple().getDXILVersion() >= VersionTuple(1, 9))
166 return nullptr;
167
168 Value *Val = Orig->getOperand(0);
169 Type *ValTy = Val->getType();
170 if (!ValTy->getScalarType()->isHalfTy())
171 return nullptr;
172
173 IRBuilder<> Builder(Orig);
174 Type *IType = Type::getInt16Ty(M->getContext());
175
176 Constant *ExpBitMask =
177 ValTy->isVectorTy()
181 ConstantInt::get(IType, 0x7c00))
182 : ConstantInt::get(IType, 0x7c00);
183 Constant *Zero =
184 ValTy->isVectorTy()
188 ConstantInt::get(IType, 0))
189 : ConstantInt::get(IType, 0);
190
191 Value *IVal = Builder.CreateBitCast(Val, ExpBitMask->getType());
192 Value *Exp = Builder.CreateAnd(IVal, ExpBitMask);
193 Value *NotAllZeroes = Builder.CreateICmpNE(Exp, Zero);
194 Value *NotAllOnes = Builder.CreateICmpNE(Exp, ExpBitMask);
195 Value *B1 = Builder.CreateAnd(NotAllZeroes, NotAllOnes);
196 return B1;
197}
198
200 switch (F.getIntrinsicID()) {
201 case Intrinsic::assume:
202 case Intrinsic::abs:
203 case Intrinsic::atan2:
204 case Intrinsic::fshl:
205 case Intrinsic::fshr:
206 case Intrinsic::exp:
207 case Intrinsic::is_fpclass:
208 case Intrinsic::log:
209 case Intrinsic::log10:
210 case Intrinsic::pow:
211 case Intrinsic::powi:
212 case Intrinsic::dx_all:
213 case Intrinsic::dx_any:
214 case Intrinsic::dx_cross:
215 case Intrinsic::dx_uclamp:
216 case Intrinsic::dx_sclamp:
217 case Intrinsic::dx_nclamp:
218 case Intrinsic::dx_degrees:
219 case Intrinsic::dx_isinf:
220 case Intrinsic::dx_isnan:
221 case Intrinsic::dx_lerp:
222 case Intrinsic::dx_normalize:
223 case Intrinsic::dx_fdot:
224 case Intrinsic::dx_sdot:
225 case Intrinsic::dx_udot:
226 case Intrinsic::dx_sign:
227 case Intrinsic::dx_step:
228 case Intrinsic::dx_radians:
229 case Intrinsic::usub_sat:
230 case Intrinsic::vector_reduce_add:
231 case Intrinsic::vector_reduce_fadd:
232 return true;
233 case Intrinsic::dx_resource_load_rawbuffer:
235 F.getParent(), F.getReturnType()->getStructElementType(0),
236 /*IsRaw*/ true);
237 case Intrinsic::dx_resource_load_typedbuffer:
239 F.getParent(), F.getReturnType()->getStructElementType(0),
240 /*IsRaw*/ false);
241 case Intrinsic::dx_resource_store_rawbuffer:
243 F.getParent(), F.getFunctionType()->getParamType(3), /*IsRaw*/ true);
244 case Intrinsic::dx_resource_store_typedbuffer:
246 F.getParent(), F.getFunctionType()->getParamType(2), /*IsRaw*/ false);
247 }
248 return false;
249}
250
252 Value *A = Orig->getArgOperand(0);
253 Value *B = Orig->getArgOperand(1);
254 Type *Ty = A->getType();
255
256 IRBuilder<> Builder(Orig);
257
258 Value *Cmp = Builder.CreateICmpULT(A, B, "usub.cmp");
259 Value *Sub = Builder.CreateSub(A, B, "usub.sub");
260 Value *Zero = ConstantInt::get(Ty, 0);
261 return Builder.CreateSelect(Cmp, Zero, Sub, "usub.sat");
262}
263
264static Value *expandVecReduceAdd(CallInst *Orig, Intrinsic::ID IntrinsicId) {
265 assert(IntrinsicId == Intrinsic::vector_reduce_add ||
266 IntrinsicId == Intrinsic::vector_reduce_fadd);
267
268 IRBuilder<> Builder(Orig);
269 bool IsFAdd = (IntrinsicId == Intrinsic::vector_reduce_fadd);
270
271 Value *X = Orig->getOperand(IsFAdd ? 1 : 0);
272 Type *Ty = X->getType();
273 auto *XVec = dyn_cast<FixedVectorType>(Ty);
274 unsigned XVecSize = XVec->getNumElements();
275 Value *Sum = Builder.CreateExtractElement(X, static_cast<uint64_t>(0));
276
277 // Handle the initial start value for floating-point addition.
278 if (IsFAdd) {
279 Constant *StartValue = dyn_cast<Constant>(Orig->getOperand(0));
280 if (StartValue && !StartValue->isZeroValue())
281 Sum = Builder.CreateFAdd(Sum, StartValue);
282 }
283
284 // Accumulate the remaining vector elements.
285 for (unsigned I = 1; I < XVecSize; I++) {
286 Value *Elt = Builder.CreateExtractElement(X, I);
287 if (IsFAdd)
288 Sum = Builder.CreateFAdd(Sum, Elt);
289 else
290 Sum = Builder.CreateAdd(Sum, Elt);
291 }
292
293 return Sum;
294}
295
296static Value *expandAbs(CallInst *Orig) {
297 Value *X = Orig->getOperand(0);
298 IRBuilder<> Builder(Orig);
299 Type *Ty = X->getType();
300 Type *EltTy = Ty->getScalarType();
301 Constant *Zero = Ty->isVectorTy()
305 ConstantInt::get(EltTy, 0))
306 : ConstantInt::get(EltTy, 0);
307 auto *V = Builder.CreateSub(Zero, X);
308 return Builder.CreateIntrinsic(Ty, Intrinsic::smax, {X, V}, nullptr,
309 "dx.max");
310}
311
313
314 VectorType *VT = cast<VectorType>(Orig->getType());
316 reportFatalUsageError("return vector must have exactly 3 elements");
317
318 Value *op0 = Orig->getOperand(0);
319 Value *op1 = Orig->getOperand(1);
320 IRBuilder<> Builder(Orig);
321
322 Value *op0_x = Builder.CreateExtractElement(op0, (uint64_t)0, "x0");
323 Value *op0_y = Builder.CreateExtractElement(op0, 1, "x1");
324 Value *op0_z = Builder.CreateExtractElement(op0, 2, "x2");
325
326 Value *op1_x = Builder.CreateExtractElement(op1, (uint64_t)0, "y0");
327 Value *op1_y = Builder.CreateExtractElement(op1, 1, "y1");
328 Value *op1_z = Builder.CreateExtractElement(op1, 2, "y2");
329
330 auto MulSub = [&](Value *x0, Value *y0, Value *x1, Value *y1) -> Value * {
331 Value *xy = Builder.CreateFMul(x0, y1);
332 Value *yx = Builder.CreateFMul(y0, x1);
333 return Builder.CreateFSub(xy, yx, Orig->getName());
334 };
335
336 Value *yz_zy = MulSub(op0_y, op0_z, op1_y, op1_z);
337 Value *zx_xz = MulSub(op0_z, op0_x, op1_z, op1_x);
338 Value *xy_yx = MulSub(op0_x, op0_y, op1_x, op1_y);
339
340 Value *cross = PoisonValue::get(VT);
341 cross = Builder.CreateInsertElement(cross, yz_zy, (uint64_t)0);
342 cross = Builder.CreateInsertElement(cross, zx_xz, 1);
343 cross = Builder.CreateInsertElement(cross, xy_yx, 2);
344 return cross;
345}
346
347// Create appropriate DXIL float dot intrinsic for the given A and B operands
348// The appropriate opcode will be determined by the size of the operands
349// The dot product is placed in the position indicated by Orig
351 Type *ATy = A->getType();
352 [[maybe_unused]] Type *BTy = B->getType();
353 assert(ATy->isVectorTy() && BTy->isVectorTy());
354
355 IRBuilder<> Builder(Orig);
356
357 auto *AVec = dyn_cast<FixedVectorType>(ATy);
358
360
361 Intrinsic::ID DotIntrinsic = Intrinsic::dx_dot4;
362 int NumElts = AVec->getNumElements();
363 switch (NumElts) {
364 case 2:
365 DotIntrinsic = Intrinsic::dx_dot2;
366 break;
367 case 3:
368 DotIntrinsic = Intrinsic::dx_dot3;
369 break;
370 case 4:
371 DotIntrinsic = Intrinsic::dx_dot4;
372 break;
373 default:
375 "Invalid dot product input vector: length is outside 2-4");
376 return nullptr;
377 }
378
380 for (int I = 0; I < NumElts; ++I)
381 Args.push_back(Builder.CreateExtractElement(A, Builder.getInt32(I)));
382 for (int I = 0; I < NumElts; ++I)
383 Args.push_back(Builder.CreateExtractElement(B, Builder.getInt32(I)));
384 return Builder.CreateIntrinsic(ATy->getScalarType(), DotIntrinsic, Args,
385 nullptr, "dot");
386}
387
388// Create the appropriate DXIL float dot intrinsic for the operands of Orig
389// The appropriate opcode will be determined by the size of the operands
390// The dot product is placed in the position indicated by Orig
392 return expandFloatDotIntrinsic(Orig, Orig->getOperand(0),
393 Orig->getOperand(1));
394}
395
396// Expand integer dot product to multiply and add ops
398 Intrinsic::ID DotIntrinsic) {
399 assert(DotIntrinsic == Intrinsic::dx_sdot ||
400 DotIntrinsic == Intrinsic::dx_udot);
401 Value *A = Orig->getOperand(0);
402 Value *B = Orig->getOperand(1);
403 Type *ATy = A->getType();
404 [[maybe_unused]] Type *BTy = B->getType();
405 assert(ATy->isVectorTy() && BTy->isVectorTy());
406
407 IRBuilder<> Builder(Orig);
408
409 auto *AVec = dyn_cast<FixedVectorType>(ATy);
410
412
413 Value *Result;
414 Intrinsic::ID MadIntrinsic = DotIntrinsic == Intrinsic::dx_sdot
415 ? Intrinsic::dx_imad
416 : Intrinsic::dx_umad;
417 Value *Elt0 = Builder.CreateExtractElement(A, (uint64_t)0);
418 Value *Elt1 = Builder.CreateExtractElement(B, (uint64_t)0);
419 Result = Builder.CreateMul(Elt0, Elt1);
420 for (unsigned I = 1; I < AVec->getNumElements(); I++) {
421 Elt0 = Builder.CreateExtractElement(A, I);
422 Elt1 = Builder.CreateExtractElement(B, I);
423 Result = Builder.CreateIntrinsic(Result->getType(), MadIntrinsic,
424 ArrayRef<Value *>{Elt0, Elt1, Result},
425 nullptr, "dx.mad");
426 }
427 return Result;
428}
429
431 Value *X = Orig->getOperand(0);
432 IRBuilder<> Builder(Orig);
433 Type *Ty = X->getType();
434 Type *EltTy = Ty->getScalarType();
435 Constant *Log2eConst =
436 Ty->isVectorTy() ? ConstantVector::getSplat(
439 ConstantFP::get(EltTy, numbers::log2ef))
440 : ConstantFP::get(EltTy, numbers::log2ef);
441 Value *NewX = Builder.CreateFMul(Log2eConst, X);
442 auto *Exp2Call =
443 Builder.CreateIntrinsic(Ty, Intrinsic::exp2, {NewX}, nullptr, "dx.exp2");
444 Exp2Call->setTailCall(Orig->isTailCall());
445 Exp2Call->setAttributes(Orig->getAttributes());
446 return Exp2Call;
447}
448
450 Value *T = Orig->getArgOperand(1);
451 auto *TCI = dyn_cast<ConstantInt>(T);
452
453 // These FPClassTest cases have DXIL opcodes, so they will be handled in
454 // DXIL Op Lowering instead for all non f16 cases.
455 switch (TCI->getZExtValue()) {
457 return expand16BitIsInf(Orig);
459 return expand16BitIsNaN(Orig);
461 return expand16BitIsNormal(Orig);
463 return expand16BitIsFinite(Orig);
464 }
465
466 IRBuilder<> Builder(Orig);
467
468 Value *F = Orig->getArgOperand(0);
469 Type *FTy = F->getType();
470 unsigned FNumElem = 0; // 0 => F is not a vector
471
472 unsigned BitWidth; // Bit width of F or the ElemTy of F
473 Type *BitCastTy; // An IntNTy of the same bitwidth as F or ElemTy of F
474
475 if (auto *FVecTy = dyn_cast<FixedVectorType>(FTy)) {
476 Type *ElemTy = FVecTy->getElementType();
477 FNumElem = FVecTy->getNumElements();
478 BitWidth = ElemTy->getPrimitiveSizeInBits();
479 BitCastTy = FixedVectorType::get(Builder.getIntNTy(BitWidth), FNumElem);
480 } else {
482 BitCastTy = Builder.getIntNTy(BitWidth);
483 }
484
485 Value *FBitCast = Builder.CreateBitCast(F, BitCastTy);
486 switch (TCI->getZExtValue()) {
488 Value *NegZero =
489 ConstantInt::get(Builder.getIntNTy(BitWidth), 1 << (BitWidth - 1));
490 Value *RetVal;
491 if (FNumElem) {
492 Value *NegZeroSplat = Builder.CreateVectorSplat(FNumElem, NegZero);
493 RetVal =
494 Builder.CreateICmpEQ(FBitCast, NegZeroSplat, "is.fpclass.negzero");
495 } else
496 RetVal = Builder.CreateICmpEQ(FBitCast, NegZero, "is.fpclass.negzero");
497 return RetVal;
498 }
499 default:
500 reportFatalUsageError("Unsupported FPClassTest");
501 }
502}
503
505 Intrinsic::ID IntrinsicId) {
506 Value *X = Orig->getOperand(0);
507 IRBuilder<> Builder(Orig);
508 Type *Ty = X->getType();
509 Type *EltTy = Ty->getScalarType();
510
511 auto ApplyOp = [&Builder](Intrinsic::ID IntrinsicId, Value *Result,
512 Value *Elt) {
513 if (IntrinsicId == Intrinsic::dx_any)
514 return Builder.CreateOr(Result, Elt);
515 assert(IntrinsicId == Intrinsic::dx_all);
516 return Builder.CreateAnd(Result, Elt);
517 };
518
519 Value *Result = nullptr;
520 if (!Ty->isVectorTy()) {
521 Result = EltTy->isFloatingPointTy()
522 ? Builder.CreateFCmpUNE(X, ConstantFP::get(EltTy, 0))
523 : Builder.CreateICmpNE(X, ConstantInt::get(EltTy, 0));
524 } else {
525 auto *XVec = dyn_cast<FixedVectorType>(Ty);
526 Value *Cond =
527 EltTy->isFloatingPointTy()
528 ? Builder.CreateFCmpUNE(
530 ElementCount::getFixed(XVec->getNumElements()),
531 ConstantFP::get(EltTy, 0)))
532 : Builder.CreateICmpNE(
534 ElementCount::getFixed(XVec->getNumElements()),
535 ConstantInt::get(EltTy, 0)));
536 Result = Builder.CreateExtractElement(Cond, (uint64_t)0);
537 for (unsigned I = 1; I < XVec->getNumElements(); I++) {
538 Value *Elt = Builder.CreateExtractElement(Cond, I);
539 Result = ApplyOp(IntrinsicId, Result, Elt);
540 }
541 }
542 return Result;
543}
544
546 Value *X = Orig->getOperand(0);
547 Value *Y = Orig->getOperand(1);
548 Value *S = Orig->getOperand(2);
549 IRBuilder<> Builder(Orig);
550 auto *V = Builder.CreateFSub(Y, X);
551 V = Builder.CreateFMul(S, V);
552 return Builder.CreateFAdd(X, V, "dx.lerp");
553}
554
556 float LogConstVal = numbers::ln2f) {
557 Value *X = Orig->getOperand(0);
558 IRBuilder<> Builder(Orig);
559 Type *Ty = X->getType();
560 Type *EltTy = Ty->getScalarType();
561 Constant *Ln2Const =
562 Ty->isVectorTy() ? ConstantVector::getSplat(
565 ConstantFP::get(EltTy, LogConstVal))
566 : ConstantFP::get(EltTy, LogConstVal);
567 auto *Log2Call =
568 Builder.CreateIntrinsic(Ty, Intrinsic::log2, {X}, nullptr, "elt.log2");
569 Log2Call->setTailCall(Orig->isTailCall());
570 Log2Call->setAttributes(Orig->getAttributes());
571 return Builder.CreateFMul(Ln2Const, Log2Call);
572}
576
577// Use dot product of vector operand with itself to calculate the length.
578// Divide the vector by that length to normalize it.
580 Value *X = Orig->getOperand(0);
581 Type *Ty = Orig->getType();
582 Type *EltTy = Ty->getScalarType();
583 IRBuilder<> Builder(Orig);
584
585 auto *XVec = dyn_cast<FixedVectorType>(Ty);
586 if (!XVec) {
587 if (auto *constantFP = dyn_cast<ConstantFP>(X)) {
588 const APFloat &fpVal = constantFP->getValueAPF();
589 if (fpVal.isZero())
590 reportFatalUsageError("Invalid input scalar: length is zero");
591 }
592 return Builder.CreateFDiv(X, X);
593 }
594
595 Value *DotProduct = expandFloatDotIntrinsic(Orig, X, X);
596
597 // verify that the length is non-zero
598 // (if the dot product is non-zero, then the length is non-zero)
599 if (auto *constantFP = dyn_cast<ConstantFP>(DotProduct)) {
600 const APFloat &fpVal = constantFP->getValueAPF();
601 if (fpVal.isZero())
602 reportFatalUsageError("Invalid input vector: length is zero");
603 }
604
605 Value *Multiplicand = Builder.CreateIntrinsic(EltTy, Intrinsic::dx_rsqrt,
606 ArrayRef<Value *>{DotProduct},
607 nullptr, "dx.rsqrt");
608
609 Value *MultiplicandVec =
610 Builder.CreateVectorSplat(XVec->getNumElements(), Multiplicand);
611 return Builder.CreateFMul(X, MultiplicandVec);
612}
613
615 Value *Y = Orig->getOperand(0);
616 Value *X = Orig->getOperand(1);
617 Type *Ty = X->getType();
618 IRBuilder<> Builder(Orig);
619 Builder.setFastMathFlags(Orig->getFastMathFlags());
620
621 Value *Tan = Builder.CreateFDiv(Y, X);
622
623 CallInst *Atan =
624 Builder.CreateIntrinsic(Ty, Intrinsic::atan, {Tan}, nullptr, "Elt.Atan");
625 Atan->setTailCall(Orig->isTailCall());
626 Atan->setAttributes(Orig->getAttributes());
627
628 // Modify atan result based on https://en.wikipedia.org/wiki/Atan2.
629 Constant *Pi = ConstantFP::get(Ty, llvm::numbers::pi);
630 Constant *HalfPi = ConstantFP::get(Ty, llvm::numbers::pi / 2);
631 Constant *NegHalfPi = ConstantFP::get(Ty, -llvm::numbers::pi / 2);
632 Constant *Zero = ConstantFP::get(Ty, 0);
633 Value *AtanAddPi = Builder.CreateFAdd(Atan, Pi);
634 Value *AtanSubPi = Builder.CreateFSub(Atan, Pi);
635
636 // x > 0 -> atan.
637 Value *Result = Atan;
638 Value *XLt0 = Builder.CreateFCmpOLT(X, Zero);
639 Value *XEq0 = Builder.CreateFCmpOEQ(X, Zero);
640 Value *YGe0 = Builder.CreateFCmpOGE(Y, Zero);
641 Value *YLt0 = Builder.CreateFCmpOLT(Y, Zero);
642
643 // x < 0, y >= 0 -> atan + pi.
644 Value *XLt0AndYGe0 = Builder.CreateAnd(XLt0, YGe0);
645 Result = Builder.CreateSelect(XLt0AndYGe0, AtanAddPi, Result);
646
647 // x < 0, y < 0 -> atan - pi.
648 Value *XLt0AndYLt0 = Builder.CreateAnd(XLt0, YLt0);
649 Result = Builder.CreateSelect(XLt0AndYLt0, AtanSubPi, Result);
650
651 // x == 0, y < 0 -> -pi/2
652 Value *XEq0AndYLt0 = Builder.CreateAnd(XEq0, YLt0);
653 Result = Builder.CreateSelect(XEq0AndYLt0, NegHalfPi, Result);
654
655 // x == 0, y > 0 -> pi/2
656 Value *XEq0AndYGe0 = Builder.CreateAnd(XEq0, YGe0);
657 Result = Builder.CreateSelect(XEq0AndYGe0, HalfPi, Result);
658
659 return Result;
660}
661
662template <bool LeftFunnel>
664 Type *Ty = Orig->getType();
665 Value *A = Orig->getOperand(0);
666 Value *B = Orig->getOperand(1);
667 Value *Shift = Orig->getOperand(2);
668
669 IRBuilder<> Builder(Orig);
670
671 unsigned BitWidth = Ty->getScalarSizeInBits();
673 "Can't use Mask to compute modulo and inverse");
674
675 // Note: if (Shift % BitWidth) == 0 then (BitWidth - Shift) == BitWidth,
676 // shifting by the bitwidth for shl/lshr returns a poisoned result. As such,
677 // we implement the same formula as LegalizerHelper::lowerFunnelShiftAsShifts.
678 //
679 // The funnel shift is expanded like so:
680 // fshl
681 // -> msb_extract((concat(A, B) << (Shift % BitWidth)), BitWidth)
682 // -> A << (Shift % BitWidth) | B >> 1 >> (BitWidth - 1 - (Shift % BitWidth))
683 // fshr
684 // -> lsb_extract((concat(A, B) >> (Shift % BitWidth), BitWidth))
685 // -> A << 1 << (BitWidth - 1 - (Shift % BitWidth)) | B >> (Shift % BitWidth)
686
687 // (BitWidth - 1) -> Mask
688 Constant *Mask = ConstantInt::get(Ty, Ty->getScalarSizeInBits() - 1);
689
690 // Shift % BitWidth
691 // -> Shift & (BitWidth - 1)
692 // -> Shift & Mask
693 Value *MaskedShift = Builder.CreateAnd(Shift, Mask);
694
695 // (BitWidth - 1) - (Shift % BitWidth)
696 // -> ~Shift & (BitWidth - 1)
697 // -> ~Shift & Mask
698 Value *NotShift = Builder.CreateNot(Shift);
699 Value *InverseShift = Builder.CreateAnd(NotShift, Mask);
700
701 Constant *One = ConstantInt::get(Ty, 1);
702 Value *ShiftedA;
703 Value *ShiftedB;
704
705 if (LeftFunnel) {
706 ShiftedA = Builder.CreateShl(A, MaskedShift);
707 Value *ShiftB1 = Builder.CreateLShr(B, One);
708 ShiftedB = Builder.CreateLShr(ShiftB1, InverseShift);
709 } else {
710 Value *ShiftA1 = Builder.CreateShl(A, One);
711 ShiftedA = Builder.CreateShl(ShiftA1, InverseShift);
712 ShiftedB = Builder.CreateLShr(B, MaskedShift);
713 }
714
715 Value *Result = Builder.CreateOr(ShiftedA, ShiftedB);
716 return Result;
717}
718
719static Value *expandPowIntrinsic(CallInst *Orig, Intrinsic::ID IntrinsicId) {
720
721 Value *X = Orig->getOperand(0);
722 Value *Y = Orig->getOperand(1);
723 Type *Ty = X->getType();
724 IRBuilder<> Builder(Orig);
725
726 if (IntrinsicId == Intrinsic::powi)
727 Y = Builder.CreateSIToFP(Y, Ty);
728
729 auto *Log2Call =
730 Builder.CreateIntrinsic(Ty, Intrinsic::log2, {X}, nullptr, "elt.log2");
731 auto *Mul = Builder.CreateFMul(Log2Call, Y);
732 auto *Exp2Call =
733 Builder.CreateIntrinsic(Ty, Intrinsic::exp2, {Mul}, nullptr, "elt.exp2");
734 Exp2Call->setTailCall(Orig->isTailCall());
735 Exp2Call->setAttributes(Orig->getAttributes());
736 return Exp2Call;
737}
738
740
741 Value *X = Orig->getOperand(0);
742 Value *Y = Orig->getOperand(1);
743 Type *Ty = X->getType();
744 IRBuilder<> Builder(Orig);
745
746 Constant *One = ConstantFP::get(Ty->getScalarType(), 1.0);
747 Constant *Zero = ConstantFP::get(Ty->getScalarType(), 0.0);
748 Value *Cond = Builder.CreateFCmpOLT(Y, X);
749
750 if (Ty != Ty->getScalarType()) {
751 auto *XVec = dyn_cast<FixedVectorType>(Ty);
753 ElementCount::getFixed(XVec->getNumElements()), One);
755 ElementCount::getFixed(XVec->getNumElements()), Zero);
756 }
757
758 return Builder.CreateSelect(Cond, Zero, One);
759}
760
762 Value *X = Orig->getOperand(0);
763 Type *Ty = X->getType();
764 IRBuilder<> Builder(Orig);
765 Value *PiOver180 = ConstantFP::get(Ty, llvm::numbers::pi / 180.0);
766 return Builder.CreateFMul(X, PiOver180);
767}
768
769static bool expandBufferLoadIntrinsic(CallInst *Orig, bool IsRaw) {
770 IRBuilder<> Builder(Orig);
771
772 Type *BufferTy = Orig->getType()->getStructElementType(0);
773 Type *ScalarTy = BufferTy->getScalarType();
774 bool IsDouble = ScalarTy->isDoubleTy();
775 assert(IsDouble || ScalarTy->isIntegerTy(64) &&
776 "Only expand double or int64 scalars or vectors");
777 bool IsVector = false;
778 unsigned ExtractNum = 2;
779 if (auto *VT = dyn_cast<FixedVectorType>(BufferTy)) {
780 ExtractNum = 2 * VT->getNumElements();
781 IsVector = true;
782 assert(IsRaw || ExtractNum == 4 && "TypedBufferLoad vector must be size 2");
783 }
784
786 Value *Result = PoisonValue::get(BufferTy);
787 unsigned Base = 0;
788 // If we need to extract more than 4 i32; we need to break it up into
789 // more than one load. LoadNum tells us how many i32s we are loading in
790 // each load
791 while (ExtractNum > 0) {
792 unsigned LoadNum = std::min(ExtractNum, 4u);
793 Type *Ty = VectorType::get(Builder.getInt32Ty(), LoadNum, false);
794
795 Type *LoadType = StructType::get(Ty, Builder.getInt1Ty());
796 Intrinsic::ID LoadIntrinsic = Intrinsic::dx_resource_load_typedbuffer;
797 SmallVector<Value *, 3> Args = {Orig->getOperand(0), Orig->getOperand(1)};
798 if (IsRaw) {
799 LoadIntrinsic = Intrinsic::dx_resource_load_rawbuffer;
800 Value *Tmp = Builder.getInt32(4 * Base * 2);
801 Args.push_back(Builder.CreateAdd(Orig->getOperand(2), Tmp));
802 }
803
804 CallInst *Load = Builder.CreateIntrinsic(LoadType, LoadIntrinsic, Args);
805 Loads.push_back(Load);
806
807 // extract the buffer load's result
808 Value *Extract = Builder.CreateExtractValue(Load, {0});
809
810 SmallVector<Value *> ExtractElements;
811 for (unsigned I = 0; I < LoadNum; ++I)
812 ExtractElements.push_back(
813 Builder.CreateExtractElement(Extract, Builder.getInt32(I)));
814
815 // combine into double(s) or int64(s)
816 for (unsigned I = 0; I < LoadNum; I += 2) {
817 Value *Combined = nullptr;
818 if (IsDouble)
819 // For doubles, use dx_asdouble intrinsic
820 Combined = Builder.CreateIntrinsic(
821 Builder.getDoubleTy(), Intrinsic::dx_asdouble,
822 {ExtractElements[I], ExtractElements[I + 1]});
823 else {
824 // For int64, manually combine two int32s
825 // First, zero-extend both values to i64
826 Value *Lo =
827 Builder.CreateZExt(ExtractElements[I], Builder.getInt64Ty());
828 Value *Hi =
829 Builder.CreateZExt(ExtractElements[I + 1], Builder.getInt64Ty());
830 // Shift the high bits left by 32 bits
831 Value *ShiftedHi = Builder.CreateShl(Hi, Builder.getInt64(32));
832 // OR the high and low bits together
833 Combined = Builder.CreateOr(Lo, ShiftedHi);
834 }
835
836 if (IsVector)
837 Result = Builder.CreateInsertElement(Result, Combined,
838 Builder.getInt32((I / 2) + Base));
839 else
840 Result = Combined;
841 }
842
843 ExtractNum -= LoadNum;
844 Base += LoadNum / 2;
845 }
846
847 Value *CheckBit = nullptr;
848 for (User *U : make_early_inc_range(Orig->users())) {
849 // If it's not a ExtractValueInst, we don't know how to
850 // handle it
851 auto *EVI = dyn_cast<ExtractValueInst>(U);
852 if (!EVI)
853 llvm_unreachable("Unexpected user of typedbufferload");
854
855 ArrayRef<unsigned> Indices = EVI->getIndices();
856 assert(Indices.size() == 1);
857
858 if (Indices[0] == 0) {
859 // Use of the value(s)
860 EVI->replaceAllUsesWith(Result);
861 } else {
862 // Use of the check bit
863 assert(Indices[0] == 1 && "Unexpected type for typedbufferload");
864 // Note: This does not always match the historical behaviour of DXC.
865 // See https://github.com/microsoft/DirectXShaderCompiler/issues/7622
866 if (!CheckBit) {
867 SmallVector<Value *, 2> CheckBits;
868 for (Value *L : Loads)
869 CheckBits.push_back(Builder.CreateExtractValue(L, {1}));
870 CheckBit = Builder.CreateAnd(CheckBits);
871 }
872 EVI->replaceAllUsesWith(CheckBit);
873 }
874 EVI->eraseFromParent();
875 }
876 Orig->eraseFromParent();
877 return true;
878}
879
880static bool expandBufferStoreIntrinsic(CallInst *Orig, bool IsRaw) {
881 IRBuilder<> Builder(Orig);
882
883 unsigned ValIndex = IsRaw ? 3 : 2;
884 Type *BufferTy = Orig->getFunctionType()->getParamType(ValIndex);
885 Type *ScalarTy = BufferTy->getScalarType();
886 bool IsDouble = ScalarTy->isDoubleTy();
887 assert((IsDouble || ScalarTy->isIntegerTy(64)) &&
888 "Only expand double or int64 scalars or vectors");
889
890 // Determine if we're dealing with a vector or scalar
891 bool IsVector = false;
892 unsigned ExtractNum = 2;
893 unsigned VecLen = 0;
894 if (auto *VT = dyn_cast<FixedVectorType>(BufferTy)) {
895 VecLen = VT->getNumElements();
896 assert(IsRaw || VecLen == 2 && "TypedBufferStore vector must be size 2");
897 ExtractNum = VecLen * 2;
898 IsVector = true;
899 }
900
901 // Create the appropriate vector type for the result
902 Type *Int32Ty = Builder.getInt32Ty();
903 Type *ResultTy = VectorType::get(Int32Ty, ExtractNum, false);
904 Value *Val = PoisonValue::get(ResultTy);
905
906 Type *SplitElementTy = Int32Ty;
907 if (IsVector)
908 SplitElementTy = VectorType::get(SplitElementTy, VecLen, false);
909
910 Value *LowBits = nullptr;
911 Value *HighBits = nullptr;
912 // Split the 64-bit values into 32-bit components
913 if (IsDouble) {
914 auto *SplitTy = llvm::StructType::get(SplitElementTy, SplitElementTy);
915 Value *Split = Builder.CreateIntrinsic(SplitTy, Intrinsic::dx_splitdouble,
916 {Orig->getOperand(ValIndex)});
917 LowBits = Builder.CreateExtractValue(Split, 0);
918 HighBits = Builder.CreateExtractValue(Split, 1);
919 } else {
920 // Handle int64 type(s)
921 Value *InputVal = Orig->getOperand(ValIndex);
922 Constant *ShiftAmt = Builder.getInt64(32);
923 if (IsVector)
924 ShiftAmt =
926
927 // Split into low and high 32-bit parts
928 LowBits = Builder.CreateTrunc(InputVal, SplitElementTy);
929 Value *ShiftedVal = Builder.CreateLShr(InputVal, ShiftAmt);
930 HighBits = Builder.CreateTrunc(ShiftedVal, SplitElementTy);
931 }
932
933 if (IsVector) {
935 for (unsigned I = 0; I < VecLen; ++I) {
936 Mask.push_back(I);
937 Mask.push_back(I + VecLen);
938 }
939 Val = Builder.CreateShuffleVector(LowBits, HighBits, Mask);
940 } else {
941 Val = Builder.CreateInsertElement(Val, LowBits, Builder.getInt32(0));
942 Val = Builder.CreateInsertElement(Val, HighBits, Builder.getInt32(1));
943 }
944
945 // If we need to extract more than 4 i32; we need to break it up into
946 // more than one store. StoreNum tells us how many i32s we are storing in
947 // each store
948 unsigned Base = 0;
949 while (ExtractNum > 0) {
950 unsigned StoreNum = std::min(ExtractNum, 4u);
951
952 Intrinsic::ID StoreIntrinsic = Intrinsic::dx_resource_store_typedbuffer;
953 SmallVector<Value *, 4> Args = {Orig->getOperand(0), Orig->getOperand(1)};
954 if (IsRaw) {
955 StoreIntrinsic = Intrinsic::dx_resource_store_rawbuffer;
956 Value *Tmp = Builder.getInt32(4 * Base);
957 Args.push_back(Builder.CreateAdd(Orig->getOperand(2), Tmp));
958 }
959
961 for (unsigned I = 0; I < StoreNum; ++I) {
962 Mask.push_back(Base + I);
963 }
964
965 Value *SubVal = Val;
966 if (VecLen > 2)
967 SubVal = Builder.CreateShuffleVector(Val, Mask);
968
969 Args.push_back(SubVal);
970 // Create the final intrinsic call
971 Builder.CreateIntrinsic(Builder.getVoidTy(), StoreIntrinsic, Args);
972
973 ExtractNum -= StoreNum;
974 Base += StoreNum;
975 }
976 Orig->eraseFromParent();
977 return true;
978}
979
981 if (ClampIntrinsic == Intrinsic::dx_uclamp)
982 return Intrinsic::umax;
983 if (ClampIntrinsic == Intrinsic::dx_sclamp)
984 return Intrinsic::smax;
985 assert(ClampIntrinsic == Intrinsic::dx_nclamp);
986 return Intrinsic::maxnum;
987}
988
990 if (ClampIntrinsic == Intrinsic::dx_uclamp)
991 return Intrinsic::umin;
992 if (ClampIntrinsic == Intrinsic::dx_sclamp)
993 return Intrinsic::smin;
994 assert(ClampIntrinsic == Intrinsic::dx_nclamp);
995 return Intrinsic::minnum;
996}
997
999 Intrinsic::ID ClampIntrinsic) {
1000 Value *X = Orig->getOperand(0);
1001 Value *Min = Orig->getOperand(1);
1002 Value *Max = Orig->getOperand(2);
1003 Type *Ty = X->getType();
1004 IRBuilder<> Builder(Orig);
1005 auto *MaxCall = Builder.CreateIntrinsic(Ty, getMaxForClamp(ClampIntrinsic),
1006 {X, Min}, nullptr, "dx.max");
1007 return Builder.CreateIntrinsic(Ty, getMinForClamp(ClampIntrinsic),
1008 {MaxCall, Max}, nullptr, "dx.min");
1009}
1010
1012 Value *X = Orig->getOperand(0);
1013 Type *Ty = X->getType();
1014 IRBuilder<> Builder(Orig);
1015 Value *DegreesRatio = ConstantFP::get(Ty, 180.0 * llvm::numbers::inv_pi);
1016 return Builder.CreateFMul(X, DegreesRatio);
1017}
1018
1020 Value *X = Orig->getOperand(0);
1021 Type *Ty = X->getType();
1022 Type *ScalarTy = Ty->getScalarType();
1023 Type *RetTy = Orig->getType();
1024 Constant *Zero = Constant::getNullValue(Ty);
1025
1026 IRBuilder<> Builder(Orig);
1027
1028 Value *GT;
1029 Value *LT;
1030 if (ScalarTy->isFloatingPointTy()) {
1031 GT = Builder.CreateFCmpOLT(Zero, X);
1032 LT = Builder.CreateFCmpOLT(X, Zero);
1033 } else {
1034 assert(ScalarTy->isIntegerTy());
1035 GT = Builder.CreateICmpSLT(Zero, X);
1036 LT = Builder.CreateICmpSLT(X, Zero);
1037 }
1038
1039 Value *ZextGT = Builder.CreateZExt(GT, RetTy);
1040 Value *ZextLT = Builder.CreateZExt(LT, RetTy);
1041
1042 return Builder.CreateSub(ZextGT, ZextLT);
1043}
1044
1045static bool expandIntrinsic(Function &F, CallInst *Orig) {
1046 Value *Result = nullptr;
1047 Intrinsic::ID IntrinsicId = F.getIntrinsicID();
1048 switch (IntrinsicId) {
1049 case Intrinsic::abs:
1050 Result = expandAbs(Orig);
1051 break;
1052 case Intrinsic::assume:
1053 Orig->eraseFromParent();
1054 return true;
1055 case Intrinsic::atan2:
1056 Result = expandAtan2Intrinsic(Orig);
1057 break;
1058 case Intrinsic::fshl:
1059 Result = expandFunnelShiftIntrinsic<true>(Orig);
1060 break;
1061 case Intrinsic::fshr:
1062 Result = expandFunnelShiftIntrinsic<false>(Orig);
1063 break;
1064 case Intrinsic::exp:
1065 Result = expandExpIntrinsic(Orig);
1066 break;
1067 case Intrinsic::is_fpclass:
1068 Result = expandIsFPClass(Orig);
1069 break;
1070 case Intrinsic::log:
1071 Result = expandLogIntrinsic(Orig);
1072 break;
1073 case Intrinsic::log10:
1074 Result = expandLog10Intrinsic(Orig);
1075 break;
1076 case Intrinsic::pow:
1077 case Intrinsic::powi:
1078 Result = expandPowIntrinsic(Orig, IntrinsicId);
1079 break;
1080 case Intrinsic::dx_all:
1081 case Intrinsic::dx_any:
1082 Result = expandAnyOrAllIntrinsic(Orig, IntrinsicId);
1083 break;
1084 case Intrinsic::dx_cross:
1085 Result = expandCrossIntrinsic(Orig);
1086 break;
1087 case Intrinsic::dx_uclamp:
1088 case Intrinsic::dx_sclamp:
1089 case Intrinsic::dx_nclamp:
1090 Result = expandClampIntrinsic(Orig, IntrinsicId);
1091 break;
1092 case Intrinsic::dx_degrees:
1093 Result = expandDegreesIntrinsic(Orig);
1094 break;
1095 case Intrinsic::dx_isinf:
1096 Result = expand16BitIsInf(Orig);
1097 break;
1098 case Intrinsic::dx_isnan:
1099 Result = expand16BitIsNaN(Orig);
1100 break;
1101 case Intrinsic::dx_lerp:
1102 Result = expandLerpIntrinsic(Orig);
1103 break;
1104 case Intrinsic::dx_normalize:
1105 Result = expandNormalizeIntrinsic(Orig);
1106 break;
1107 case Intrinsic::dx_fdot:
1108 Result = expandFloatDotIntrinsic(Orig);
1109 break;
1110 case Intrinsic::dx_sdot:
1111 case Intrinsic::dx_udot:
1112 Result = expandIntegerDotIntrinsic(Orig, IntrinsicId);
1113 break;
1114 case Intrinsic::dx_sign:
1115 Result = expandSignIntrinsic(Orig);
1116 break;
1117 case Intrinsic::dx_step:
1118 Result = expandStepIntrinsic(Orig);
1119 break;
1120 case Intrinsic::dx_radians:
1121 Result = expandRadiansIntrinsic(Orig);
1122 break;
1123 case Intrinsic::dx_resource_load_rawbuffer:
1124 if (expandBufferLoadIntrinsic(Orig, /*IsRaw*/ true))
1125 return true;
1126 break;
1127 case Intrinsic::dx_resource_store_rawbuffer:
1128 if (expandBufferStoreIntrinsic(Orig, /*IsRaw*/ true))
1129 return true;
1130 break;
1131 case Intrinsic::dx_resource_load_typedbuffer:
1132 if (expandBufferLoadIntrinsic(Orig, /*IsRaw*/ false))
1133 return true;
1134 break;
1135 case Intrinsic::dx_resource_store_typedbuffer:
1136 if (expandBufferStoreIntrinsic(Orig, /*IsRaw*/ false))
1137 return true;
1138 break;
1139 case Intrinsic::usub_sat:
1140 Result = expandUsubSat(Orig);
1141 break;
1142 case Intrinsic::vector_reduce_add:
1143 case Intrinsic::vector_reduce_fadd:
1144 Result = expandVecReduceAdd(Orig, IntrinsicId);
1145 break;
1146 }
1147 if (Result) {
1148 Orig->replaceAllUsesWith(Result);
1149 Orig->eraseFromParent();
1150 return true;
1151 }
1152 return false;
1153}
1154
1156 for (auto &F : make_early_inc_range(M.functions())) {
1157 if (!isIntrinsicExpansion(F))
1158 continue;
1159 bool IntrinsicExpanded = false;
1160 for (User *U : make_early_inc_range(F.users())) {
1161 auto *IntrinsicCall = dyn_cast<CallInst>(U);
1162 if (!IntrinsicCall)
1163 continue;
1164 IntrinsicExpanded = expandIntrinsic(F, IntrinsicCall);
1165 }
1166 if (F.user_empty() && IntrinsicExpanded)
1167 F.eraseFromParent();
1168 }
1169 return true;
1170}
1171
1178
1182
1184
1186 "DXIL Intrinsic Expansion", false, false)
1188 "DXIL Intrinsic Expansion", false, false)
1189
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")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
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)
static Value * expandFunnelShiftIntrinsic(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:54
#define I(x, y, z)
Definition MD5.cpp:57
#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:1427
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
size - Get the array size.
Definition ArrayRef.h:142
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:802
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:2788
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:413
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:197
static LLVM_ABI IntegerType * getInt16Ty(LLVMContext &C)
Definition Type.cpp:295
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:300
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
constexpr float ln10f
Definition MathExtras.h:50
constexpr float log2ef
Definition MathExtras.h:51
constexpr double pi
constexpr float ln2f
Definition MathExtras.h:49
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:643
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:632
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
Definition MathExtras.h:279
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:559
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