[all-commits] [llvm/llvm-project] ed5b0e: Add length builtins and length HLSL function to Di...

Joshua Batista via All-commits all-commits at lists.llvm.org
Fri Aug 2 21:16:46 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ed5b0e1e6986a652de8be88fa5ff92bf75c40a21
      https://github.com/llvm/llvm-project/commit/ed5b0e1e6986a652de8be88fa5ff92bf75c40a21
  Author: Joshua Batista <jbatista at microsoft.com>
  Date:   2024-08-02 (Fri, 02 Aug 2024)

  Changed paths:
    M clang/include/clang/Basic/Builtins.td
    M clang/lib/CodeGen/CGBuiltin.cpp
    M clang/lib/CodeGen/CGHLSLRuntime.h
    M clang/lib/Headers/hlsl/hlsl_intrinsics.h
    M clang/lib/Sema/SemaHLSL.cpp
    A clang/test/CodeGenHLSL/builtins/length.hlsl
    A clang/test/SemaHLSL/BuiltIns/length-errors.hlsl
    M llvm/include/llvm/IR/IntrinsicsDirectX.td
    M llvm/include/llvm/IR/IntrinsicsSPIRV.td
    M llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
    A llvm/test/CodeGen/DirectX/length.ll
    A llvm/test/CodeGen/DirectX/length_error.ll
    A llvm/test/CodeGen/DirectX/length_invalid_intrinsic_error.ll
    A llvm/test/CodeGen/DirectX/length_invalid_intrinsic_error_scalar.ll

  Log Message:
  -----------
  Add length builtins and length HLSL function to DirectX Backend (#101256)

This PR adds the length intrinsic and an HLSL function that uses it.
The SPIRV implementation is left for a future PR.
This PR addresses #99134, though some SPIR-V changes still need to be
made to complete the task. Below is how this PR addresses #99134.
- "Implement `length` clang builtin" was done by defining `HLSLL ength`
in Builtins.td
- "Link `length` clang builtin with hlsl_intrinsics.h" was done by using
the alias attribute to make `length` an alias of
`__builtin_hlsl_elementwise_length` in hlsl_intrinsics.h
- "Add sema checks for `length` to `CheckHLSLBuiltinFunctionCall` in
`SemaChecking.cpp` " was done, but in this case not in SemaChecking.cpp,
rather SemaHLSL.cpp. A case was added to the builtin to check for
semantic failures, and set `TheCall` up to have the right return type.
- "Add codegen for `length` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`"
was done. For scalars, fabs is emitted, otherwise, length is emitted.
- "Add codegen tests to `clang/test/CodeGenHLSL/builtins/length.hlsl`
was done to test that `length` in HLSL emits the right intrinsic.
- "Add sema tests to `clang/test/SemaHLSL/BuiltIns/length-errors.hlsl`"
was done to test for diagnostics emitted in SemaHLSL.cpp
- "Create the `int_dx_length` intrinsic in `IntrinsicsDirectX.td`" was
done. Specifying return types and parameter types was difficult, but
`idot` was used for reference, and `llvm\include\llvm\IR\Intrinsics.td`
contains all the ways to express return / parameter types.
- "Create an intrinsic expansion of `int_dx_length` in
`llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp`" was done, and was
mostly derived by looking at `TranslateLength` in `HLOperationLower.cpp`
in the DXC codebase.
- "Create the `length.ll` and `length_errors.ll` tests in
`llvm/test/CodeGen/DirectX/`" was done by taking the DXIL output of
`clang/test/CodeGenHLSL/builtins/length.hlsl` and running `opt -S
-dxil-intrinsic-expansion` and ` opt -S -dxil-op-lower` on it, checking
for how the length intrinsic was either expanded or lowered.
- "Create the `int_spv_length` intrinsic in `IntrinsicsSPIRV.td`" was
done by copying `IntrinsicsDirectX.td`.

---------

Co-authored-by: Justin Bogner <mail at justinbogner.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list