python3kgae created this revision. python3kgae added reviewers: simoll, k-ishizaka, kaz7. Herald added subscribers: Anastasia, dexonsmith, hiraditya, mgorny. Herald added a project: All. python3kgae requested review of this revision. Herald added subscribers: llvm-commits, cfe-commits, jdoerfert. Herald added projects: clang, LLVM.
A directx specific llvm intrinsic is introduced: float @llvm.dx.sin.f32(float) It is for https://github.com/Microsoft/DirectXShaderCompiler/blob/master/docs/DXIL.rst#sin. This change the llvm intrinsic and test it can be generated from clang codeGen. The clang builtin change is in https://reviews.llvm.org/D124593 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D124595 Files: clang/include/clang/Basic/BuiltinsDirectX.def clang/include/clang/Basic/TargetBuiltins.h clang/lib/Basic/Targets/DirectX.cpp clang/lib/Basic/Targets/DirectX.h clang/test/CodeGenHLSL/Builtins/sin_f32.hlsl clang/test/SemaHLSL/Builtins/sin_f32.hlsl llvm/include/llvm/IR/CMakeLists.txt llvm/include/llvm/IR/Intrinsics.td llvm/include/llvm/IR/IntrinsicsDirectX.td llvm/lib/IR/Function.cpp
Index: llvm/lib/IR/Function.cpp =================================================================== --- llvm/lib/IR/Function.cpp +++ llvm/lib/IR/Function.cpp @@ -36,6 +36,7 @@ #include "llvm/IR/IntrinsicsAMDGPU.h" #include "llvm/IR/IntrinsicsARM.h" #include "llvm/IR/IntrinsicsBPF.h" +#include "llvm/IR/IntrinsicsDirectX.h" #include "llvm/IR/IntrinsicsHexagon.h" #include "llvm/IR/IntrinsicsMips.h" #include "llvm/IR/IntrinsicsNVPTX.h" Index: llvm/include/llvm/IR/IntrinsicsDirectX.td =================================================================== --- /dev/null +++ llvm/include/llvm/IR/IntrinsicsDirectX.td @@ -0,0 +1,17 @@ +//===- IntrinsicsDirectX.td - Defines DirectX intrinsics ---*- tablegen -*-===// +// +// 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 file defines all of the DirectX-specific intrinsics. +// +//===----------------------------------------------------------------------===// + +// Specialized loads from packet +let TargetPrefix = "dx" in { // All intrinsics start with "llvm.dx." + def int_dx_sin_f32 : GCCBuiltin<"__builtin_dx_sin_f32">, + Intrinsic<[llvm_float_ty], [llvm_float_ty], [IntrNoMem]>; +} Index: llvm/include/llvm/IR/Intrinsics.td =================================================================== --- llvm/include/llvm/IR/Intrinsics.td +++ llvm/include/llvm/IR/Intrinsics.td @@ -2047,3 +2047,4 @@ include "llvm/IR/IntrinsicsWebAssembly.td" include "llvm/IR/IntrinsicsRISCV.td" include "llvm/IR/IntrinsicsVE.td" +include "llvm/IR/IntrinsicsDirectX.td" Index: llvm/include/llvm/IR/CMakeLists.txt =================================================================== --- llvm/include/llvm/IR/CMakeLists.txt +++ llvm/include/llvm/IR/CMakeLists.txt @@ -8,6 +8,7 @@ tablegen(LLVM IntrinsicsAMDGPU.h -gen-intrinsic-enums -intrinsic-prefix=amdgcn) tablegen(LLVM IntrinsicsARM.h -gen-intrinsic-enums -intrinsic-prefix=arm) tablegen(LLVM IntrinsicsBPF.h -gen-intrinsic-enums -intrinsic-prefix=bpf) +tablegen(LLVM IntrinsicsDirectX.h -gen-intrinsic-enums -intrinsic-prefix=dx) tablegen(LLVM IntrinsicsHexagon.h -gen-intrinsic-enums -intrinsic-prefix=hexagon) tablegen(LLVM IntrinsicsMips.h -gen-intrinsic-enums -intrinsic-prefix=mips) tablegen(LLVM IntrinsicsNVPTX.h -gen-intrinsic-enums -intrinsic-prefix=nvvm) Index: clang/test/SemaHLSL/Builtins/sin_f32.hlsl =================================================================== --- /dev/null +++ clang/test/SemaHLSL/Builtins/sin_f32.hlsl @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.15-library -x hlsl -ast-dump -o - %s | FileCheck %s + +//CHECK: CallExpr 0x{{.+}} <col:10, col:32> 'float' +//CHECK-NEXT:ImplicitCastExpr 0x{{.+}} <col:10> 'float (*)(float) throw()' <BuiltinFnToFnPtr> +//CHECK-NEXT`-DeclRefExpr 0x{{.+}} <col:10> '<builtin fn type>' Function 0x26df56e3fc0 '__builtin_dx_sin_f32' + +float foo(float a) { + return __builtin_dx_sin_f32(a); +} Index: clang/test/CodeGenHLSL/Builtins/sin_f32.hlsl =================================================================== --- /dev/null +++ clang/test/CodeGenHLSL/Builtins/sin_f32.hlsl @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.15-library -x hlsl -S -emit-llvm -o - %s | FileCheck %s + +//CHECK:call float @llvm.dx.sin.f32 + +float foo(float a) { + return __builtin_dx_sin_f32(a); +} Index: clang/lib/Basic/Targets/DirectX.h =================================================================== --- clang/lib/Basic/Targets/DirectX.h +++ clang/lib/Basic/Targets/DirectX.h @@ -44,6 +44,9 @@ }; class LLVM_LIBRARY_VISIBILITY DirectXTargetInfo : public TargetInfo { + + static const Builtin::Info BuiltinInfo[]; + public: DirectXTargetInfo(const llvm::Triple &Triple, const TargetOptions &) : TargetInfo(Triple) { @@ -66,7 +69,7 @@ return Feature == "directx"; } - ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; } + ArrayRef<Builtin::Info> getTargetBuiltins() const override; const char *getClobbers() const override { return ""; } Index: clang/lib/Basic/Targets/DirectX.cpp =================================================================== --- clang/lib/Basic/Targets/DirectX.cpp +++ clang/lib/Basic/Targets/DirectX.cpp @@ -12,6 +12,8 @@ #include "DirectX.h" #include "Targets.h" +#include "clang/Basic/Builtins.h" +#include "clang/Basic/TargetBuiltins.h" using namespace clang; using namespace clang::targets; @@ -20,3 +22,16 @@ MacroBuilder &Builder) const { DefineStd(Builder, "DIRECTX", Opts); } + +const Builtin::Info DirectXTargetInfo::BuiltinInfo[] = { +#define BUILTIN(ID, TYPE, ATTRS) \ + {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr}, +#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) \ + {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, FEATURE}, +#include "clang/Basic/BuiltinsDirectX.def" +}; + +ArrayRef<Builtin::Info> DirectXTargetInfo::getTargetBuiltins() const { + return llvm::makeArrayRef(BuiltinInfo, clang::DirectX::LastTSBuiltin - + Builtin::FirstTSBuiltin); +} Index: clang/include/clang/Basic/TargetBuiltins.h =================================================================== --- clang/include/clang/Basic/TargetBuiltins.h +++ clang/include/clang/Basic/TargetBuiltins.h @@ -75,6 +75,16 @@ }; } + /// DirectX builtins + namespace DirectX { + enum { + LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1, +#define BUILTIN(ID, TYPE, ATTRS) BI##ID, +#include "clang/Basic/BuiltinsDirectX.def" + LastTSBuiltin + }; + } // namespace DirectX + /// PPC builtins namespace PPC { enum { Index: clang/include/clang/Basic/BuiltinsDirectX.def =================================================================== --- /dev/null +++ clang/include/clang/Basic/BuiltinsDirectX.def @@ -0,0 +1,27 @@ +//===-- BuiltinsDirectX.def - DirectX Builtin function database -*- C++ -*-===// +// +// 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 file defines the DirectX-specific builtin function database. Users of +// this file must define the BUILTIN macro to make use of this information. +// +//===----------------------------------------------------------------------===// + +// The format of this database matches clang/Basic/Builtins.def. + +#if defined(BUILTIN) && !defined(TARGET_BUILTIN) +# define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) BUILTIN(ID, TYPE, ATTRS) +#endif + +#if defined(BUILTIN) && !defined(TARGET_HEADER_BUILTIN) +# define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANG, FEATURE) BUILTIN(ID, TYPE, ATTRS) +#endif + +BUILTIN(__builtin_dx_sin_f32, "ff", "ne") + +#undef BUILTIN +#undef TARGET_BUILTIN
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits