Skip to content

Commit 2f40a23

Browse files
committed
Merge branch 'master_prm' into dev
2 parents f5542ee + aa4fe8b commit 2f40a23

File tree

204 files changed

+11369
-7981
lines changed

Some content is hidden

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

204 files changed

+11369
-7981
lines changed

CMakeLists.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,21 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
3333
set(LLPC_IS_STANDALONE ON)
3434
endif()
3535

36+
### Version info ###
37+
include(cmake/llpc_version.cmake)
38+
add_llpc_version_projects()
39+
3640
### Top-level VKGC Interface ###
3741
add_library(vkgc INTERFACE)
3842

3943
### VKGC header-only library ###
4044
add_library(vkgc_headers INTERFACE)
4145

46+
target_link_libraries(vkgc_headers INTERFACE llpc_version)
47+
4248
### Cached Project Options #############################################################################################
4349
option(LLPC_BUILD_TOOLS "LLPC build all tools" OFF)
44-
4550
### Options that affect the headers ####################################################################################
46-
if (LLPC_CLIENT_INTERFACE_MAJOR_VERSION)
47-
target_compile_definitions(vkgc_headers INTERFACE LLPC_CLIENT_INTERFACE_MAJOR_VERSION=${LLPC_CLIENT_INTERFACE_MAJOR_VERSION})
48-
else()
49-
message(FATAL_ERROR "Client of LLPC must set LLPC_CLIENT_INTERFACE_MAJOR_VERSION")
50-
endif()
51-
5251
#if VKI_BUILD_GFX11
5352
if(LLPC_BUILD_GFX11)
5453
target_compile_definitions(vkgc_headers INTERFACE VKI_BUILD_GFX11)

cmake/continuations.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525

2626
set(LLPC_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/..")
2727

28+
include("${LLPC_SOURCE_DIR}/cmake/llpc_version.cmake")
2829
include("${LLPC_SOURCE_DIR}/cmake/compilerutils.cmake")
2930

3031
# Macro to add continuations and its dependencies as LLVM external projects.
3132
# This appends the project names to LLVM_EXTERNAL_PROJECTS and sets each LLVM_EXTERNAL_*_SOURCE_DIR,
3233
# all in the caller's scope.
3334
macro(add_continuations_projects)
35+
add_llpc_version_projects()
3436
add_compilerutils_projects()
3537
if (NOT continuations IN_LIST LLVM_EXTERNAL_PROJECTS)
3638
if (NOT llvm_dialects IN_LIST LLVM_EXTERNAL_PROJECTS)

cmake/lgc.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525

2626
set(LLPC_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/..")
2727

28+
include("${LLPC_SOURCE_DIR}/cmake/llpc_version.cmake")
2829
include("${LLPC_SOURCE_DIR}/cmake/continuations.cmake")
2930

3031
# Macro to add LGC and its dependencies as LLVM external projects.
3132
# This appends the project names to LLVM_EXTERNAL_PROJECTS and sets each LLVM_EXTERNAL_*_SOURCE_DIR,
3233
# all in the caller's scope.
3334
macro(add_lgc_projects)
35+
add_llpc_version_projects()
3436
add_continuations_projects()
3537
if (NOT lgc IN_LIST LLVM_EXTERNAL_PROJECTS)
3638
if (NOT llvm_dialects IN_LIST LLVM_EXTERNAL_PROJECTS)

cmake/llpc_version.cmake

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
##
2+
#######################################################################################################################
3+
#
4+
# Copyright (c) 2023 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 deal
8+
# in the Software without restriction, including without limitation the rights
9+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
# 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 FROM,
21+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
# SOFTWARE.
23+
#
24+
#######################################################################################################################
25+
26+
set(LLPC_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/..")
27+
28+
macro(add_llpc_version_projects)
29+
if (NOT TARGET llpc_version)
30+
# Force the binary directory to account for the possibility that LLPC is
31+
# taken from an external source directory.
32+
add_subdirectory(${LLPC_SOURCE_DIR}/version ${CMAKE_CURRENT_BINARY_DIR}/llpc_version)
33+
endif()
34+
endmacro()

compilerutils/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ add_llvm_library(LLVMCompilerUtils
2222
Analysis
2323
Core
2424
Support
25+
TransformUtils
2526
)
2627

2728
target_include_directories(LLVMCompilerUtils PUBLIC
@@ -35,3 +36,6 @@ set_compiler_options(LLVMCompilerUtils)
3536

3637
target_compile_features(LLVMCompilerUtils PUBLIC cxx_std_17)
3738
set_target_properties(LLVMCompilerUtils PROPERTIES CXX_EXTENSIONS OFF)
39+
40+
add_subdirectory(tool/cross-module-inline)
41+
add_subdirectory(test)

compilerutils/include/compilerutils/CompilerUtils.h

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

41-
namespace llvm {
42-
43-
class CallInst;
44-
class Function;
45-
class Type;
46-
class Value;
47-
48-
} // namespace llvm
49-
5041
namespace CompilerUtils {
5142

5243
// Create an LLVM function call to the named function. The callee is built
@@ -66,6 +57,56 @@ llvm::CallInst *createNamedCall(llvm::IRBuilder<> &, llvm::StringRef, llvm::Type
6657
llvm::Function *mutateFunctionArguments(llvm::Function &, llvm::Type *, const llvm::ArrayRef<llvm::Type *>,
6758
llvm::AttributeList);
6859

60+
// Create a new function based on another function, copying attributes and
61+
// other properties.
62+
// Specify targetModule to create the function in a different module than f.
63+
llvm::Function *cloneFunctionHeader(llvm::Function &f, llvm::FunctionType *newType, llvm::AttributeList attributes,
64+
llvm::Module *targetModule = nullptr);
65+
66+
// Overload of cloneFunctionHeader that takes the new attributes for arguments and preserves the rest.
67+
llvm::Function *cloneFunctionHeader(llvm::Function &f, llvm::FunctionType *newType,
68+
llvm::ArrayRef<llvm::AttributeSet> argAttrs, llvm::Module *targetModule = nullptr);
69+
70+
struct CrossModuleInlinerResult {
71+
llvm::Value *returnValue;
72+
llvm::iterator_range<llvm::Function::iterator> newBBs;
73+
};
74+
75+
// The class caches already mapped constants. Reusing an instance of this class is more efficient than creating a new
76+
// instance every time but it does not have an impact on the generated code.
77+
// One CrossModuleInliner instance must only be used for a single target module, otherwise things can go wrong.
78+
class CrossModuleInliner {
79+
public:
80+
CrossModuleInliner() = default;
81+
82+
// Inline a call to a function even if the called function is in a different module.
83+
// If the result of that function call should be used, a use must exist before calling this function.
84+
// Returns the new created basic blocks. These blocks may also contain instructions that were already
85+
// there before, if the function got inlined into an existing block.
86+
//
87+
// The insertion point of existing IRBuilders may have their insertion point invalidated because this
88+
// function splits basic blocks.
89+
// They can be made functional again with b.SetInsertPoint(&*b.GetInsertPoint()).
90+
llvm::iterator_range<llvm::Function::iterator> inlineCall(llvm::CallBase &cb);
91+
92+
// Inline a call to a function even if the called function is in a different module.
93+
// Returns the result of the call and new created basic blocks. These blocks may also contain instructions that were
94+
// already there before, if the function got inlined into an existing block.
95+
//
96+
// This is a convenience wrapper around inlineCall(CallBase&). As users of the callee's return value are not known
97+
// while inlining, using this function can result in slightly less folding in the IR.
98+
CrossModuleInlinerResult inlineCall(llvm::IRBuilder<> &b, llvm::Function *callee,
99+
llvm::ArrayRef<llvm::Value *> args = std::nullopt);
100+
101+
// Find a global value (function or variable) that was copied by the cross-module inliner.
102+
// Arguments are the global from the source module and the target module. Returns the corresponding global from the
103+
// target module.
104+
llvm::GlobalValue *findCopiedGlobal(llvm::GlobalValue &sourceGv, llvm::Module &targetModule);
105+
106+
private:
107+
llvm::SmallDenseMap<llvm::GlobalValue *, llvm::GlobalValue *> mappedGlobals;
108+
};
109+
69110
} // namespace CompilerUtils
70111

71112
#endif

0 commit comments

Comments
 (0)