Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit fa78a16

Browse files
committed
Update llpc from commit f07302bd
[Continuations] Refactor 'TypeLowering::lowerFunctionArguments' Fix performance gap caused by LDS bank conflict [CompilerUtils] Assert return types are not changed [CompilerUtils] Fixup alloca alignment in type lowering [llvmraytracing] Remove plugin pass info function for dynamically loaded plugins [CompilerUtils] Add LLVM plugin Remove deprecated assert Cleanup useless VgtGsVertItemsize calculation assignment [Continuations] Support '_AmdIsLlpc' intrinsic Remove deprecated interface forceEnablePrimStats Fix build failure due to llvm memory issue [Continuations] Introduce 'RCR' argument for 'lgc.cps.jump', refactor wait mask handling Add support for no return image sample intrinsics in builder [Continuations] Improve payload size reporting lgc : replace threadMaskedSelect function to use inverseballot [Continuations] Move 'lgc.ilcps.return' op building to 'LowerRaytracingPipeline' Compiler::buildShaderCacheHash: Fix fragment hash [Continuations] Improve stats reporting Force wave64 mode for legacy GS on GFX10 Change in/out semantics representation [Continuations] Remove payload size reporting in bytes Fix component addressing issue of 64-bit FS input lgc : fix logic issues of tryOptimizeWorkgroupId Implement the mapping from CLIP_DIST_4/5/6/7 to CLIP_DIST_0/1/2/3 accordingly [Continuations] Add 'complete' intrinsic, generate 'lgc.cps.jump' Disable AllowReassoc for reflect operations Correct processing of mesh shader output semantics [RT] Don't compile kernel entry for pipeline library lgc : fix global pointer access for buffer strided pointer [RT] Support AmdTraceRayInitStaticId Record debugprintf usermapping to the elf [Continuations] Add payload serialization alloca for Traversal in lgc.cps mode [Continuations] Use 'lgc.cps.complete' for program termination Rename some classes and files in lower pass Add strix1 support
1 parent 5278a3f commit fa78a16

208 files changed

Lines changed: 8327 additions & 2366 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-format

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ AllowShortFunctionsOnASingleLine: InlineOnly
44
IncludeBlocks: Merge
55
IncludeCategories:
66
- Regex: '^"lgc/'
7-
Priority: 2
8-
- Regex: '^"(llvm|llvm-c|llvm-dialects|clang|clang-c)/'
97
Priority: 3
10-
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
8+
- Regex: '^"(llvm|llvm-c|llvm-dialects|clang|clang-c)/'
119
Priority: 4
10+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
11+
Priority: 5
12+
- Regex: '.*/'
13+
Priority: 2
1214
- Regex: '.*'
1315
Priority: 1

.typos.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ UE = "UE"
1313
OpBuildNDRange = "OpBuildNDRange"
1414
serDataNode = "serDataNode"
1515
rcall = "rcall"
16+
Fo = "Fo"
1617

1718
[default.extend-words]
1819
ba = "ba"
@@ -28,4 +29,3 @@ dne = "dne"
2829
offen = "offen"
2930
varing = "varing"
3031
Derivate = "Derivate"
31-
Fo = "Fo"

compilerutils/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ endfunction()
1414
add_llvm_library(LLVMCompilerUtils
1515
lib/ArgPromotion.cpp
1616
lib/CompilerUtils.cpp
17+
lib/DxilToLlvm.cpp
1718
lib/TypeLowering.cpp
1819
lib/TypesMetadata.cpp
1920

@@ -39,5 +40,6 @@ set_compiler_options(LLVMCompilerUtils)
3940
target_compile_features(LLVMCompilerUtils PUBLIC cxx_std_17)
4041
set_target_properties(LLVMCompilerUtils PROPERTIES CXX_EXTENSIONS OFF)
4142

43+
add_subdirectory(plugin)
4244
add_subdirectory(tool/cross-module-inline)
4345
add_subdirectory(test)

compilerutils/include/compilerutils/CompilerUtils.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,17 @@
3838
#include "llvm/IR/Attributes.h"
3939
#include "llvm/IR/IRBuilder.h"
4040

41+
namespace llvm {
42+
43+
class PassBuilder;
44+
45+
} // namespace llvm
46+
4147
namespace CompilerUtils {
4248

49+
// Register compiler utils passes.
50+
void RegisterPasses(llvm::PassBuilder &PB);
51+
4352
// Create an LLVM function call to the named function. The callee is built
4453
// automatically based on return type and its parameters.
4554
//
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
***********************************************************************************************************************
3+
*
4+
* Copyright (c) 2024 Advanced Micro Devices, Inc. All Rights Reserved.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to
8+
* deal in the Software without restriction, including without limitation the
9+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10+
* sell copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22+
* IN THE SOFTWARE.
23+
*
24+
**********************************************************************************************************************/
25+
26+
//===- DxilToLlvm.h - --------------------------------------------------------------------------------------------===//
27+
//
28+
// This pass converts a DXIL module into an LLVM module by fixing constructs that have different semantics in the two.
29+
// The output module will still contain DXIL intrinsics and metadata, because we only fix incompatibilities, and don't
30+
// lower away DXIL.
31+
//
32+
// The following modifications are made:
33+
//
34+
// * i1 vectors are replaced by i32 vectors
35+
// This works around a more general difference between DXIL and LLVM:
36+
// In LLVM, vectors are always bit-packed and ignore the elements' alignment.
37+
// In DXIL, vectors respect the elements' alignment, and i1s have 32-bit alignment.
38+
// Thus, in DXIL, the elements of <2 x i1> are 32 bits apart, while they are bit-packed in LLVM,
39+
// and DXC relies on this by bit-casting allocas between <2 x i1> and <2 x i32>.
40+
// This only seems to affect HLSL i1 *matrices*, which are lowered to arrays of i1 vectors in DXIL,
41+
// and not HLSL i1 vectors, which are lowered to i32 arrays in DXIL.
42+
// To fix this, we replace all i1 vectors by i32 vectors.
43+
// We don't apply the same to other vectors that were overaligned in the original DXIL data layout (e.g. i16)
44+
// because this may harm performance, and we haven't observed cases yet where DXC relies on this layout.
45+
// See https://github.com/microsoft/DirectXShaderCompiler/issues/6082 for some background.
46+
//
47+
// Further known, not yet handled differences:
48+
//
49+
// * vectors of non-i1 elements that are overaligned in DXIL (see above)
50+
// * potentially: overaligned types in general
51+
// After importing DXIL modules, we change the data layout to match what the backend does. Doing so potentially
52+
// breaks the module if it relies on the existing DL. For instance, after changing the alignment of i16 from 32 to 16,
53+
// storing as [4 x i16] and reading back the second dword behaves differently. Strictly speaking, when changing the
54+
// DL, we would need to update such occurrences. We don't do that because we haven't yet observed such cases, and
55+
// because it is difficult in general. For instance, we could transparently replace i16s by i32s to preserve the
56+
// 32-bit size, but replacing half by float is more problematic. Although there is no spec, it appears DXC tries to
57+
// emit DXIL that supports such DL changes, by only using structured GEPs and avoiding transformations based on byte
58+
// offsets. Also, such fixups are only possible locally (e.g. for allocas), and not through opaque memory.
59+
// * UDiv/URem/FPTrunc differences
60+
// * fast math flags
61+
//
62+
//===--------------------------------------------------------------------------------------------------------------===//
63+
64+
#pragma once
65+
66+
#include "llvm/IR/PassManager.h"
67+
#include "llvm/Pass.h"
68+
69+
namespace CompilerUtils {
70+
71+
class DxilToLlvmPass : public llvm::PassInfoMixin<DxilToLlvmPass> {
72+
public:
73+
llvm::PreservedAnalyses run(llvm::Module &Module, llvm::ModuleAnalysisManager &AnalysisManager);
74+
75+
static llvm::StringRef name() { return "Convert DXIL to LLVM IR"; }
76+
};
77+
78+
} // namespace CompilerUtils

compilerutils/lib/CompilerUtils.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
**********************************************************************************************************************/
2525

2626
#include "compilerutils/CompilerUtils.h"
27+
#include "compilerutils/DxilToLlvm.h"
2728
#include "llvm/ADT/StringExtras.h"
2829
#include "llvm/ADT/iterator_range.h"
2930
#include "llvm/IR/Attributes.h"
@@ -32,6 +33,7 @@
3233
#include "llvm/IR/Module.h"
3334
#include "llvm/IR/Type.h"
3435
#include "llvm/IR/Value.h"
36+
#include "llvm/Passes/PassBuilder.h"
3537
#include "llvm/Support/ErrorHandling.h"
3638
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
3739
#include "llvm/Transforms/Utils/Cloning.h"
@@ -544,3 +546,20 @@ void CompilerUtils::replaceAllPointerUses(IRBuilder<> *builder, Value *oldPointe
544546
assert(PhiElems.empty() && "All phi inputs need to be handled, otherwise we end in an inconsistent state");
545547
#endif
546548
}
549+
550+
void CompilerUtils::RegisterPasses(llvm::PassBuilder &PB) {
551+
#define HANDLE_PASS(NAME, CREATE_PASS) \
552+
if (innerPipeline.empty() && name == NAME) { \
553+
passMgr.addPass(CREATE_PASS); \
554+
return true; \
555+
}
556+
557+
PB.registerPipelineParsingCallback(
558+
[](StringRef name, ModulePassManager &passMgr, ArrayRef<PassBuilder::PipelineElement> innerPipeline) {
559+
StringRef Params;
560+
(void)Params;
561+
#define COMPILERUTILS_PASS HANDLE_PASS
562+
#include "PassRegistry.inc"
563+
return false;
564+
});
565+
}

0 commit comments

Comments
 (0)