This PR adds WavePrefixProduct intrinsic support in HLSL with codegen for both DirectX and SPIRV backends. Resolves https://github.com/llvm/llvm-project/issues/99173. - [x] Implement `WavePrefixProduct` clang builtin - [x] Link `WavePrefixProduct` clang builtin with `hlsl_intrinsics.h` - [x] Add sema checks for `WavePrefixProduct` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp` - [x] Add codegen for `WavePrefixProduct` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp` - [x] Add codegen tests to `clang/test/CodeGenHLSL/builtins/WavePrefixProduct.hlsl` - [x] Add sema tests to `clang/test/SemaHLSL/BuiltIns/WavePrefixProduct-errors.hlsl` - [x] Create the `int_dx_WavePrefixProduct` intrinsic in `IntrinsicsDirectX.td` - [x] Create the `DXILOpMapping` of `int_dx_WavePrefixProduct` to `121` in `DXIL.td` - [x] Create the `WavePrefixProduct.ll` and `WavePrefixProduct_errors.ll` tests in `llvm/test/CodeGen/DirectX/` - [x] Create the `int_spv_WavePrefixProduct` intrinsic in `IntrinsicsSPIRV.td` - [x] In `SPIRVInstructionSelector.cpp` create the `WavePrefixProduct` lowering and map it to `int_spv_WavePrefixProduct` in `SPIRVInstructionSelector::selectIntrinsic`. - [x] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WavePrefixProduct.ll`
82 lines
2.4 KiB
C++
82 lines
2.4 KiB
C++
//===- DirectXTargetTransformInfo.cpp - DirectX TTI ---------------*- 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "DirectXTargetTransformInfo.h"
|
|
#include "llvm/IR/Intrinsics.h"
|
|
#include "llvm/IR/IntrinsicsDirectX.h"
|
|
|
|
using namespace llvm;
|
|
|
|
bool DirectXTTIImpl::isTargetIntrinsicWithScalarOpAtArg(
|
|
Intrinsic::ID ID, unsigned ScalarOpdIdx) const {
|
|
switch (ID) {
|
|
case Intrinsic::dx_wave_readlane:
|
|
return ScalarOpdIdx == 1;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
bool DirectXTTIImpl::isTargetIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID,
|
|
int OpdIdx) const {
|
|
switch (ID) {
|
|
case Intrinsic::dx_asdouble:
|
|
case Intrinsic::dx_firstbitlow:
|
|
case Intrinsic::dx_firstbitshigh:
|
|
case Intrinsic::dx_firstbituhigh:
|
|
case Intrinsic::dx_isinf:
|
|
case Intrinsic::dx_isnan:
|
|
case Intrinsic::dx_legacyf16tof32:
|
|
case Intrinsic::dx_legacyf32tof16:
|
|
return OpdIdx == 0;
|
|
default:
|
|
return OpdIdx == -1;
|
|
}
|
|
}
|
|
|
|
bool DirectXTTIImpl::isTargetIntrinsicTriviallyScalarizable(
|
|
Intrinsic::ID ID) const {
|
|
switch (ID) {
|
|
case Intrinsic::dx_asdouble:
|
|
case Intrinsic::dx_firstbitlow:
|
|
case Intrinsic::dx_firstbitshigh:
|
|
case Intrinsic::dx_firstbituhigh:
|
|
case Intrinsic::dx_frac:
|
|
case Intrinsic::dx_isinf:
|
|
case Intrinsic::dx_isnan:
|
|
case Intrinsic::dx_legacyf16tof32:
|
|
case Intrinsic::dx_legacyf32tof16:
|
|
case Intrinsic::dx_rsqrt:
|
|
case Intrinsic::dx_saturate:
|
|
case Intrinsic::dx_splitdouble:
|
|
case Intrinsic::dx_wave_readlane:
|
|
case Intrinsic::dx_wave_reduce_max:
|
|
case Intrinsic::dx_wave_reduce_min:
|
|
case Intrinsic::dx_wave_reduce_sum:
|
|
case Intrinsic::dx_wave_prefix_sum:
|
|
case Intrinsic::dx_wave_prefix_product:
|
|
case Intrinsic::dx_wave_reduce_umax:
|
|
case Intrinsic::dx_wave_reduce_umin:
|
|
case Intrinsic::dx_wave_reduce_usum:
|
|
case Intrinsic::dx_wave_prefix_usum:
|
|
case Intrinsic::dx_wave_prefix_uproduct:
|
|
case Intrinsic::dx_imad:
|
|
case Intrinsic::dx_umad:
|
|
case Intrinsic::dx_ddx_coarse:
|
|
case Intrinsic::dx_ddy_coarse:
|
|
case Intrinsic::dx_ddx_fine:
|
|
case Intrinsic::dx_ddy_fine:
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|