Skip to content

Commit 562084c

Browse files
committed
[DirectX] add Function name to DiagnosticInfoUnsupported Msg in DXILOpLowering
fixes llvm#135654 In llvm#128613 we added safe guards to prevent the lowering of just any intrinsic in the backend. We used `DiagnosticInfoUnsupported` to do this. What we found was when using `opt` the diagnostic print function was called but when using clang the diagnostic message was used. Printing message in the clang version means we miss valuable debugging information like function name and function type when LLVMContext was only needed to call `getBestLocationFromDebugLoc`. There are a few potential fixes 1. Write a custom DiagnosticInfoUnsupported so we can change the Message just for DirectX. Too heavy handed so rejected. 2. Add the function name to the Message in DirectX code. Very simple one line change. Downside is when using opt you see the function name twice. But makes the clang-dxc bugs more actionable. 3. change CodeGenAction.cpp to always use the print function and not the message directly. Downside is a bunch of innacurate information shows up in the message if you don't specify `-debug-info-kind=standalone`. 4. add some book keeping to know which function called the intrinsic keep a map of these so we can pass the calling function to `DiagnosticInfoUnsupported` instead of the intrinsic. This would only be useful if we had debug info so we could distinguish different uses of the intrinsic. We would also need to change from iterating on every function to doing somethin like a LazyCallGraph. 5. pick a different means of doing a Diagnostic error, because other uses of`DiagnosticInfoUnsupported` error when we are in the body of a function not when we see one being used like in the intrinsic case. This PR went with option 2. Its low code change that also only impacts the DirectX backend.
1 parent 62b9cbd commit 562084c

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %if clang-dxc %{not %clang_dxc -T lib_6_3 %s 2>&1 | FileCheck %s %}
2+
3+
// CHECK: error: Unsupported intrinsic llvm.vector.reduce.and.v4i32 for DXIL lowering
4+
5+
export int vecReduceAndTest(int4 vec) {
6+
return __builtin_reduce_and(vec);
7+
}

llvm/lib/Target/DirectX/DXILOpLowering.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "DXILOpLowering.h"
1010
#include "DXILConstants.h"
11-
#include "DXILIntrinsicExpansion.h"
1211
#include "DXILOpBuilder.h"
1312
#include "DXILShaderFlags.h"
1413
#include "DirectX.h"
@@ -27,6 +26,7 @@
2726
#include "llvm/InitializePasses.h"
2827
#include "llvm/Pass.h"
2928
#include "llvm/Support/ErrorHandling.h"
29+
#include "llvm/Support/FormatVariadic.h"
3030

3131
#define DEBUG_TYPE "dxil-op-lower"
3232

@@ -756,8 +756,11 @@ class OpLowerer {
756756
case Intrinsic::not_intrinsic:
757757
continue;
758758
default: {
759-
DiagnosticInfoUnsupported Diag(
760-
F, "Unsupported intrinsic for DXIL lowering");
759+
std::string Msg =
760+
llvm::formatv("Unsupported intrinsic {0} for DXIL lowering",
761+
F.getName())
762+
.str();
763+
DiagnosticInfoUnsupported Diag(F, Msg);
761764
M.getContext().diagnose(Diag);
762765
HasErrors |= true;
763766
break;

llvm/test/CodeGen/DirectX/unsupported_intrinsic.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
; RUN: not opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s 2>&1 | FileCheck %s
22

3-
; CHECK: error: <unknown>:0:0: in function llvm.vector.reduce.and.v4i32 i32 (<4 x i32>): Unsupported intrinsic for DXIL lowering
3+
; CHECK: Unsupported intrinsic llvm.vector.reduce.and.v4i32 for DXIL lowering
44
define i32 @fn_and(<4 x i32> %0) local_unnamed_addr #0 {
55
%2 = tail call i32 @llvm.vector.reduce.and.v4i32(<4 x i32> %0)
66
ret i32 %2

0 commit comments

Comments
 (0)