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
18using namespace clang;
19using namespace CodeGen;
20using namespace llvm;
21
22Value *CodeGenFunction::EmitDirectXBuiltinExpr(unsigned BuiltinID,
23 const CallExpr *E) {
24 switch (BuiltinID) {
25 case DirectX::BI__builtin_dx_dot2add: {
26 Value *A = EmitScalarExpr(E: E->getArg(Arg: 0));
27 Value *B = EmitScalarExpr(E: E->getArg(Arg: 1));
28 Value *Acc = EmitScalarExpr(E: E->getArg(Arg: 2));
29
30 Value *AX = Builder.CreateExtractElement(Vec: A, Idx: Builder.getSize(N: 0));
31 Value *AY = Builder.CreateExtractElement(Vec: A, Idx: Builder.getSize(N: 1));
32 Value *BX = Builder.CreateExtractElement(Vec: B, Idx: Builder.getSize(N: 0));
33 Value *BY = Builder.CreateExtractElement(Vec: B, Idx: Builder.getSize(N: 1));
34
35 Intrinsic::ID ID = llvm ::Intrinsic::dx_dot2add;
36 return Builder.CreateIntrinsic(
37 /*ReturnType=*/RetTy: Acc->getType(), ID,
38 Args: ArrayRef<Value *>{Acc, AX, AY, BX, BY}, FMFSource: nullptr, Name: "dx.dot2add");
39 }
40 }
41 return nullptr;
42}
43