Skip to content

Commit 003c288

Browse files
author
Colin Davidson
committed
[NATIVE_CPU][SYCL] Merge from oneAPI Construction Kit into native_cpu
2 parents 2ae009e + 92e7e22 commit 003c288

File tree

586 files changed

+104597
-0
lines changed

Some content is hidden

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

586 files changed

+104597
-0
lines changed

llvm/lib/SYCLNativeCPUUtils/compiler_passes/compiler_pipeline/docs/overview.rst

Lines changed: 819 additions & 0 deletions
Large diffs are not rendered by default.

llvm/lib/SYCLNativeCPUUtils/compiler_passes/compiler_pipeline/docs/utils.rst

Lines changed: 1308 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (C) Codeplay Software Limited
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License") with LLVM
4+
// Exceptions; you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://github.com/uxlfoundation/oneapi-construction-kit/blob/main/LICENSE.txt
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
// License for the specific language governing permissions and limitations
13+
// under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
16+
17+
/// @file
18+
///
19+
/// LLVM address space identifiers.
20+
21+
#ifndef COMPILER_UTILS_ADDRESS_SPACES_H_INCLUDED
22+
#define COMPILER_UTILS_ADDRESS_SPACES_H_INCLUDED
23+
24+
namespace compiler {
25+
namespace utils {
26+
namespace AddressSpace {
27+
enum {
28+
Private = 0,
29+
Global = 1,
30+
Constant = 2,
31+
Local = 3,
32+
Generic = 4,
33+
};
34+
}
35+
} // namespace utils
36+
} // namespace compiler
37+
38+
#endif // COMPILER_UTILS_ADDRESS_SPACES_H_INCLUDED
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
// Copyright (C) Codeplay Software Limited
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License") with LLVM
4+
// Exceptions; you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://github.com/uxlfoundation/oneapi-construction-kit/blob/main/LICENSE.txt
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
// License for the specific language governing permissions and limitations
13+
// under the License.
14+
//
15+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
16+
17+
#ifndef COMPILER_UTILS_ATTRIBUTES_H_INCLUDED
18+
#define COMPILER_UTILS_ATTRIBUTES_H_INCLUDED
19+
20+
#include <llvm/ADT/StringRef.h>
21+
22+
#include <optional>
23+
24+
namespace llvm {
25+
class CallInst;
26+
class Function;
27+
} // namespace llvm
28+
29+
namespace compiler {
30+
namespace utils {
31+
32+
/// @brief Encodes information that a function is a kernel
33+
///
34+
/// @param[in] F Function in which to encode the information.
35+
void setIsKernel(llvm::Function &F);
36+
37+
/// @brief Encodes information that a function is a kernel entry point
38+
///
39+
/// @param[in] F Function in which to encode the information.
40+
void setIsKernelEntryPt(llvm::Function &F);
41+
42+
/// @brief Returns whether the function is a kernel under compilation.
43+
///
44+
/// @param[in] F Function to check.
45+
bool isKernel(const llvm::Function &F);
46+
47+
/// @brief Returns whether the function is a kernel entry point under
48+
/// compilation.
49+
///
50+
/// @param[in] F Function to check.
51+
bool isKernelEntryPt(const llvm::Function &F);
52+
53+
/// @brief Drops any information about whether a function is a kernel.
54+
///
55+
/// @param[in] F Function to drop information from.
56+
void dropIsKernel(llvm::Function &F);
57+
58+
/// @brief Takes information about kernels from one function to another.
59+
///
60+
/// Removes information from the old function, and overwrites any such
61+
/// information in the new function.
62+
///
63+
/// @param[in] ToF Function to copy to.
64+
/// @param[in] FromF Function to copy from.
65+
void takeIsKernel(llvm::Function &ToF, llvm::Function &FromF);
66+
67+
/// @brief Sets the original function name as an attribute.
68+
void setOrigFnName(llvm::Function &F);
69+
70+
/// @brief Retrieves the original function name from the given Function.
71+
///
72+
/// @return The original function name (via function attributes) or an empty
73+
/// string if none is found.
74+
llvm::StringRef getOrigFnName(const llvm::Function &F);
75+
76+
/// @brief Retrieves the original function name from the given Function, or the
77+
/// Function's name.
78+
///
79+
/// @return The original function name (via function attributes) or the
80+
/// function's name if none is found.
81+
llvm::StringRef getOrigFnNameOrFnName(const llvm::Function &F);
82+
83+
/// @brief Sets the original function name as an attribute.
84+
void setBaseFnName(llvm::Function &F, llvm::StringRef N);
85+
86+
/// @brief Retrieves the base function name component from the given Function.
87+
///
88+
/// @return The base function name (via function attributes) or an empty string
89+
/// if none is found.
90+
llvm::StringRef getBaseFnName(const llvm::Function &F);
91+
92+
/// @brief Retrieves the base function name component from the given Function,
93+
/// or the Function's name.
94+
///
95+
/// @return The base function name (via function attributes) or the function's
96+
/// name if none is found.
97+
llvm::StringRef getBaseFnNameOrFnName(const llvm::Function &F);
98+
99+
/// @brief Retrieves the base function name from the given Function and
100+
/// sets it if none is found.
101+
/// @param F The function to read "base function name" attributes from
102+
/// @param SetFromF The function whose name is set as F's base function
103+
/// name if none is found in F.
104+
llvm::StringRef getOrSetBaseFnName(llvm::Function &F,
105+
const llvm::Function &SetFromF);
106+
107+
/// @brief Sets the local memory usage estimation for the given function.
108+
///
109+
/// @param[in] F the function in which to add the attribute
110+
/// @param[in] LocalMemUsage the (estimated) local memory usage in bytes
111+
void setLocalMemoryUsage(llvm::Function &F, uint64_t LocalMemUsage);
112+
113+
/// @brief Gets the local memory usage estimation for the given function.
114+
///
115+
/// @param[in] F Function from which to pull the attribute
116+
/// @return the (estimated) local memory usage in bytes if present,
117+
/// std::nullopt otherwise.
118+
std::optional<uint64_t> getLocalMemoryUsage(const llvm::Function &F);
119+
120+
/// @brief Sets information about a function's required DMA size as an
121+
/// attribute.
122+
///
123+
/// @param[in] F Function in which to add the attribute.
124+
/// @param[in] DMASizeBytes DMA size in bytes.
125+
void setDMAReqdSizeBytes(llvm::Function &F, uint32_t DMASizeBytes);
126+
127+
/// @brief Retrieves information about a function's required DMA size as an
128+
/// attribute.
129+
///
130+
/// @param[in] F Function from which to pull the attribute
131+
/// @return The required DMA size order if present, else `std::nullopt`
132+
std::optional<uint32_t> getDMAReqdSizeBytes(const llvm::Function &F);
133+
134+
/// @brief Determines the ordering of work item execution after a barrier.
135+
enum class BarrierSchedule {
136+
/// @brief The barrier pass is free to schedule work items in any order.
137+
Unordered = 0,
138+
/// @brief The barrier region is entirely uniform (no dependence on work item
139+
/// ID) such that execution of multiple work items is redundant and we are
140+
/// free to execute the region for only a single work item. Additionally,
141+
/// such a region is not allowed to read from or write to the barrier struct
142+
/// (the region cannot use any variables defined outwith it, nor define any
143+
/// variables used outwith it). Used by work group collectives to initialize
144+
/// their accumulators.
145+
Once,
146+
/// @brief The barrier region should execute all vectorized work items first,
147+
/// followed by the scalar tail.
148+
ScalarTail,
149+
/// @brief The barrier region must be executed in Local Linear ID order.
150+
Linear,
151+
};
152+
153+
/// @brief Sets the work item execution schedule for the given barrier.
154+
///
155+
/// @param[in] CI the barrier call instruction
156+
/// @param[in] Sched the execution schedule to set
157+
void setBarrierSchedule(llvm::CallInst &CI, BarrierSchedule Sched);
158+
159+
/// @brief Gets the work item execution schedule for the given barrier.
160+
///
161+
/// @param[in] CI the barrier call instruction
162+
/// @return the execution schedule for this barrier
163+
BarrierSchedule getBarrierSchedule(const llvm::CallInst &CI);
164+
165+
/// @brief Marks a function as not explicitly using subgroups
166+
///
167+
/// May be set even with unresolved external functions, assuming those don't
168+
/// explicitly use subgroups.
169+
///
170+
/// @param[in] F Function in which to encode the information.
171+
void setHasNoExplicitSubgroups(llvm::Function &F);
172+
173+
/// @brief Returns whether the kernel does not explicitly use subgroups
174+
///
175+
/// @param[in] F Function to check.
176+
bool hasNoExplicitSubgroups(const llvm::Function &F);
177+
178+
/// @brief Returns the mux subgroup size for the current function.
179+
///
180+
/// Currently always returns 1!
181+
unsigned getMuxSubgroupSize(const llvm::Function &F);
182+
183+
} // namespace utils
184+
} // namespace compiler
185+
186+
#endif // COMPILER_UTILS_ATTRIBUTES_H_INCLUDED

0 commit comments

Comments
 (0)