1 //===--------- DirectX.cpp - Emit LLVM Code for builtins ------------------===//
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 // This contains code to emit Builtin calls as LLVM code.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "CGHLSLRuntime.h"
14 #include "CodeGenFunction.h"
15 #include "clang/Basic/TargetBuiltins.h"
16 #include "llvm/IR/Intrinsics.h"
17
18 using namespace clang;
19 using namespace CodeGen;
20 using namespace llvm;
21
EmitDirectXBuiltinExpr(unsigned BuiltinID,const CallExpr * E)22 Value *CodeGenFunction::EmitDirectXBuiltinExpr(unsigned BuiltinID,
23 const CallExpr *E) {
24 switch (BuiltinID) {
25 case DirectX::BI__builtin_dx_dot2add: {
26 Value *A = EmitScalarExpr(E->getArg(0));
27 Value *B = EmitScalarExpr(E->getArg(1));
28 Value *Acc = EmitScalarExpr(E->getArg(2));
29
30 Value *AX = Builder.CreateExtractElement(A, Builder.getSize(0));
31 Value *AY = Builder.CreateExtractElement(A, Builder.getSize(1));
32 Value *BX = Builder.CreateExtractElement(B, Builder.getSize(0));
33 Value *BY = Builder.CreateExtractElement(B, Builder.getSize(1));
34
35 Intrinsic::ID ID = llvm ::Intrinsic::dx_dot2add;
36 return Builder.CreateIntrinsic(
37 /*ReturnType=*/Acc->getType(), ID,
38 ArrayRef<Value *>{Acc, AX, AY, BX, BY}, nullptr, "dx.dot2add");
39 }
40 }
41 return nullptr;
42 }
43