-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[DirectX] Add target builtins #134439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DirectX] Add target builtins #134439
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//===--- BuiltinsDirectX.td - DirectX Builtin function database -----------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
include "clang/Basic/BuiltinsBase.td" | ||
|
||
def DxDot2Add : Builtin { | ||
let Spellings = ["__builtin_dx_dot2add"]; | ||
let Attributes = [NoThrow, Const]; | ||
let Prototype = "float(_ExtVector<2, _Float16>, _ExtVector<2, _Float16>, float)"; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//===----- SemaDirectX.h ----- Semantic Analysis for DirectX | ||
// constructs--------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// \file | ||
/// This file declares semantic analysis for DirectX constructs. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CLANG_SEMA_SEMADIRECTX_H | ||
#define LLVM_CLANG_SEMA_SEMADIRECTX_H | ||
|
||
#include "clang/AST/ASTFwd.h" | ||
#include "clang/Sema/SemaBase.h" | ||
|
||
namespace clang { | ||
class SemaDirectX : public SemaBase { | ||
public: | ||
SemaDirectX(Sema &S); | ||
|
||
bool CheckDirectXBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); | ||
}; | ||
} // namespace clang | ||
|
||
#endif // LLVM_CLANG_SEMA_SEMADIRECTX_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//===--------- DirectX.cpp - Emit LLVM Code for builtins ------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This contains code to emit Builtin calls as LLVM code. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "CGHLSLRuntime.h" | ||
#include "CodeGenFunction.h" | ||
#include "clang/Basic/TargetBuiltins.h" | ||
#include "llvm/IR/Intrinsics.h" | ||
|
||
using namespace clang; | ||
using namespace CodeGen; | ||
using namespace llvm; | ||
|
||
Value *CodeGenFunction::EmitDirectXBuiltinExpr(unsigned BuiltinID, | ||
const CallExpr *E) { | ||
switch (BuiltinID) { | ||
case DirectX::BI__builtin_dx_dot2add: { | ||
Value *A = EmitScalarExpr(E->getArg(0)); | ||
Value *B = EmitScalarExpr(E->getArg(1)); | ||
Value *C = EmitScalarExpr(E->getArg(2)); | ||
|
||
Intrinsic::ID ID = llvm ::Intrinsic::dx_dot2add; | ||
return Builder.CreateIntrinsic( | ||
/*ReturnType=*/C->getType(), ID, ArrayRef<Value *>{A, B, C}, nullptr, | ||
"dx.dot2add"); | ||
} | ||
} | ||
return nullptr; | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,23 @@ | ||||||||||||||
//===- SemaDirectX.cpp - Semantic Analysis for DirectX constructs----------===// | ||||||||||||||
// | ||||||||||||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||||||||||||
// See https://llvm.org/LICENSE.txt for license information. | ||||||||||||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||||||||||||
// | ||||||||||||||
//===----------------------------------------------------------------------===// | ||||||||||||||
// This implements Semantic Analysis for DirectX constructs. | ||||||||||||||
//===----------------------------------------------------------------------===// | ||||||||||||||
|
||||||||||||||
#include "clang/Sema/SemaDirectX.h" | ||||||||||||||
#include "clang/Basic/TargetBuiltins.h" | ||||||||||||||
#include "clang/Sema/Sema.h" | ||||||||||||||
|
||||||||||||||
namespace clang { | ||||||||||||||
|
||||||||||||||
SemaDirectX::SemaDirectX(Sema &S) : SemaBase(S) {} | ||||||||||||||
|
||||||||||||||
bool SemaDirectX::CheckDirectXBuiltinFunctionCall(unsigned BuiltinID, | ||||||||||||||
CallExpr *TheCall) { | ||||||||||||||
return false; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there really no checking needed for the
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the Prototype for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In that case, I think that if we want to add empty switch cases for this then it should be a separate PR to change it for all other the other builtins at once. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The plan right now is that we do target builtins when one of our two targets has an opcode and the other does not. Im not aware of another case right now for directx. The problem i have with removing sema scaffolding when i don’t have another candidate in mind is it feel like we have incomplete support for target builtins if we strip out all the sema changes. |
||||||||||||||
} | ||||||||||||||
} // namespace clang |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The filename should probably be dot2add.hlsl. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No this is a c only test. Since we are exposing the backend api as a target any frontend is technically suppose to be able to access it. This test is to confirm that we aren't gating the directX backend. |
||
|
||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -emit-llvm -o - | FileCheck %s | ||
|
||
typedef _Float16 half; | ||
typedef half half2 __attribute__((ext_vector_type(2))); | ||
|
||
// CHECK-LABEL: define float @test_dot2add( | ||
// CHECK-SAME: <2 x half> noundef [[X:%.*]], <2 x half> noundef [[Y:%.*]], float noundef [[Z:%.*]]) #[[ATTR0:[0-9]+]] { | ||
// CHECK-NEXT: [[ENTRY:.*:]] | ||
// CHECK-NEXT: [[X_ADDR:%.*]] = alloca <2 x half>, align 4 | ||
// CHECK-NEXT: [[Y_ADDR:%.*]] = alloca <2 x half>, align 4 | ||
// CHECK-NEXT: [[Z_ADDR:%.*]] = alloca float, align 4 | ||
// CHECK-NEXT: store <2 x half> [[X]], ptr [[X_ADDR]], align 4 | ||
// CHECK-NEXT: store <2 x half> [[Y]], ptr [[Y_ADDR]], align 4 | ||
// CHECK-NEXT: store float [[Z]], ptr [[Z_ADDR]], align 4 | ||
// CHECK-NEXT: [[TMP0:%.*]] = load <2 x half>, ptr [[X_ADDR]], align 4 | ||
// CHECK-NEXT: [[TMP1:%.*]] = load <2 x half>, ptr [[Y_ADDR]], align 4 | ||
// CHECK-NEXT: [[TMP2:%.*]] = load float, ptr [[Z_ADDR]], align 4 | ||
// CHECK-NEXT: [[DX_DOT2ADD:%.*]] = call float @llvm.dx.dot2add.v2f16(<2 x half> [[TMP0]], <2 x half> [[TMP1]], float [[TMP2]]) | ||
// CHECK-NEXT: ret float [[DX_DOT2ADD]] | ||
// | ||
float test_dot2add(half2 X, half2 Y, float Z) { return __builtin_dx_dot2add(X, Y, Z); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this supposed to be on 2 lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch. no this should be one line