Skip to content

Commit 5f01863

Browse files
authored
Merge branch 'main' into lldb-mcp-multi
2 parents 831a505 + de1baa5 commit 5f01863

File tree

21 files changed

+586
-262
lines changed

21 files changed

+586
-262
lines changed

.ci/all_requirements.txt

Lines changed: 213 additions & 11 deletions
Large diffs are not rendered by default.

.ci/cache_lit_timing_files.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
"""Caches .lit_test_times.txt files between premerge invocations.
5+
6+
.lit_test_times.txt files are used by lit to order tests to best take advantage
7+
of parallelism. Having them around and up to date can result in a ~15%
8+
improvement in test times. This script downloading cached test time files and
9+
uploading new versions to the GCS buckets used for caching.
10+
"""
11+
12+
import sys
13+
import os
14+
import logging
15+
import multiprocessing.pool
16+
import pathlib
17+
import glob
18+
19+
from google.cloud import storage
20+
21+
GCS_PARALLELISM = 100
22+
23+
24+
def _maybe_upload_timing_file(bucket, timing_file_path):
25+
if os.path.exists(timing_file_path):
26+
timing_file_blob = bucket.blob("lit_timing/" + timing_file_path)
27+
timing_file_blob.upload_from_filename(timing_file_path)
28+
29+
30+
def upload_timing_files(storage_client, bucket_name: str):
31+
bucket = storage_client.bucket(bucket_name)
32+
with multiprocessing.pool.ThreadPool(GCS_PARALLELISM) as thread_pool:
33+
futures = []
34+
for timing_file_path in glob.glob("**/.lit_test_times.txt", recursive=True):
35+
futures.append(
36+
thread_pool.apply_async(
37+
_maybe_upload_timing_file, (bucket, timing_file_path)
38+
)
39+
)
40+
for future in futures:
41+
future.get()
42+
print("Done uploading")
43+
44+
45+
def _maybe_download_timing_file(blob):
46+
file_name = blob.name.removeprefix("lit_timing/")
47+
pathlib.Path(os.path.dirname(file_name)).mkdir(parents=True, exist_ok=True)
48+
blob.download_to_filename(file_name)
49+
50+
51+
def download_timing_files(storage_client, bucket_name: str):
52+
bucket = storage_client.bucket(bucket_name)
53+
blobs = bucket.list_blobs(prefix="lit_timing")
54+
with multiprocessing.pool.ThreadPool(GCS_PARALLELISM) as thread_pool:
55+
futures = []
56+
for timing_file_blob in blobs:
57+
futures.append(
58+
thread_pool.apply_async(
59+
_maybe_download_timing_file, (timing_file_blob,)
60+
)
61+
)
62+
for future in futures:
63+
future.get()
64+
print("Done downloading")
65+
66+
67+
if __name__ == "__main__":
68+
if len(sys.argv) != 2:
69+
logging.fatal("Expected usage is cache_lit_timing_files.py <upload/download>")
70+
sys.exit(1)
71+
action = sys.argv[1]
72+
storage_client = storage.Client()
73+
bucket_name = os.environ["CACHE_GCS_BUCKET"]
74+
if action == "download":
75+
download_timing_files(storage_client, bucket_name)
76+
elif action == "upload":
77+
upload_timing_files(storage_client, bucket_name)
78+
else:
79+
logging.fatal("Expected usage is cache_lit_timing_files.py <upload/download>")
80+
sys.exit(1)

.ci/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
junitparser==3.2.0
2+
google-cloud-storage==3.3.0

.github/workflows/containers/github-action-ci/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM docker.io/library/ubuntu:24.04 as base
22
ENV LLVM_SYSROOT=/opt/llvm
33

44
FROM base as stage1-toolchain
5-
ENV LLVM_VERSION=20.1.8
5+
ENV LLVM_VERSION=21.1.0
66

77
RUN apt-get update && \
88
apt-get install -y \

clang/lib/CodeGen/Targets/NVPTX.cpp

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ class NVPTXTargetCodeGenInfo : public TargetCodeGenInfo {
8787
static void addNVVMMetadata(llvm::GlobalValue *GV, StringRef Name,
8888
int Operand);
8989

90-
static void
91-
addGridConstantNVVMMetadata(llvm::GlobalValue *GV,
92-
const SmallVectorImpl<int> &GridConstantArgs);
93-
9490
private:
9591
static void emitBuiltinSurfTexDeviceCopy(CodeGenFunction &CGF, LValue Dst,
9692
LValue Src) {
@@ -265,27 +261,24 @@ void NVPTXTargetCodeGenInfo::setTargetAttributes(
265261
// By default, all functions are device functions
266262
if (FD->hasAttr<DeviceKernelAttr>() || FD->hasAttr<CUDAGlobalAttr>()) {
267263
// OpenCL/CUDA kernel functions get kernel metadata
268-
// Create !{<func-ref>, metadata !"kernel", i32 1} node
269264
// And kernel functions are not subject to inlining
270265
F->addFnAttr(llvm::Attribute::NoInline);
271266
if (FD->hasAttr<CUDAGlobalAttr>()) {
272-
SmallVector<int, 10> GCI;
267+
F->setCallingConv(llvm::CallingConv::PTX_Kernel);
268+
273269
for (auto IV : llvm::enumerate(FD->parameters()))
274270
if (IV.value()->hasAttr<CUDAGridConstantAttr>())
275-
// For some reason arg indices are 1-based in NVVM
276-
GCI.push_back(IV.index() + 1);
277-
// Create !{<func-ref>, metadata !"kernel", i32 1} node
278-
F->setCallingConv(llvm::CallingConv::PTX_Kernel);
279-
addGridConstantNVVMMetadata(F, GCI);
271+
F->addParamAttr(
272+
IV.index(),
273+
llvm::Attribute::get(F->getContext(), "nvvm.grid_constant"));
280274
}
281275
if (CUDALaunchBoundsAttr *Attr = FD->getAttr<CUDALaunchBoundsAttr>())
282276
M.handleCUDALaunchBoundsAttr(F, Attr);
283277
}
284278
}
285279
// Attach kernel metadata directly if compiling for NVPTX.
286-
if (FD->hasAttr<DeviceKernelAttr>()) {
280+
if (FD->hasAttr<DeviceKernelAttr>())
287281
F->setCallingConv(llvm::CallingConv::PTX_Kernel);
288-
}
289282
}
290283

291284
void NVPTXTargetCodeGenInfo::addNVVMMetadata(llvm::GlobalValue *GV,
@@ -305,29 +298,6 @@ void NVPTXTargetCodeGenInfo::addNVVMMetadata(llvm::GlobalValue *GV,
305298
MD->addOperand(llvm::MDNode::get(Ctx, MDVals));
306299
}
307300

308-
void NVPTXTargetCodeGenInfo::addGridConstantNVVMMetadata(
309-
llvm::GlobalValue *GV, const SmallVectorImpl<int> &GridConstantArgs) {
310-
311-
llvm::Module *M = GV->getParent();
312-
llvm::LLVMContext &Ctx = M->getContext();
313-
314-
// Get "nvvm.annotations" metadata node
315-
llvm::NamedMDNode *MD = M->getOrInsertNamedMetadata("nvvm.annotations");
316-
317-
SmallVector<llvm::Metadata *, 5> MDVals = {llvm::ConstantAsMetadata::get(GV)};
318-
if (!GridConstantArgs.empty()) {
319-
SmallVector<llvm::Metadata *, 10> GCM;
320-
for (int I : GridConstantArgs)
321-
GCM.push_back(llvm::ConstantAsMetadata::get(
322-
llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx), I)));
323-
MDVals.append({llvm::MDString::get(Ctx, "grid_constant"),
324-
llvm::MDNode::get(Ctx, GCM)});
325-
}
326-
327-
// Append metadata to nvvm.annotations
328-
MD->addOperand(llvm::MDNode::get(Ctx, MDVals));
329-
}
330-
331301
bool NVPTXTargetCodeGenInfo::shouldEmitStaticExternCAliases() const {
332302
return false;
333303
}

clang/test/CodeGenCUDA/grid-constant.cu

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,9 @@ void foo() {
1919
tkernel_const<S><<<1,1>>>({});
2020
tkernel<const S><<<1,1>>>(1, {});
2121
}
22-
//.
23-
//.
24-
// CHECK: [[META0:![0-9]+]] = !{ptr @_Z6kernel1Sii, !"grid_constant", [[META1:![0-9]+]]}
25-
// CHECK: [[META1]] = !{i32 1, i32 3}
26-
// CHECK: [[META2:![0-9]+]] = !{ptr @_Z13tkernel_constIK1SEvT_, !"grid_constant", [[META3:![0-9]+]]}
27-
// CHECK: [[META3]] = !{i32 1}
28-
// CHECK: [[META4:![0-9]+]] = !{ptr @_Z13tkernel_constI1SEvT_, !"grid_constant", [[META3]]}
29-
// CHECK: [[META5:![0-9]+]] = !{ptr @_Z7tkernelIK1SEviT_, !"grid_constant", [[META6:![0-9]+]]}
30-
// CHECK: [[META6]] = !{i32 2}
31-
//.
22+
23+
// CHECK: define dso_local ptx_kernel void @_Z6kernel1Sii(ptr noundef byval(%struct.S) align 1 "nvvm.grid_constant" %gc_arg1, i32 noundef %arg2, i32 noundef "nvvm.grid_constant" %gc_arg3)
24+
// CHECK: define ptx_kernel void @_Z13tkernel_constIK1SEvT_(ptr noundef byval(%struct.S) align 1 "nvvm.grid_constant" %arg)
25+
// CHECK: define ptx_kernel void @_Z13tkernel_constI1SEvT_(ptr noundef byval(%struct.S) align 1 "nvvm.grid_constant" %arg)
26+
// CHECK: define ptx_kernel void @_Z7tkernelIK1SEviT_(i32 noundef %dummy, ptr noundef byval(%struct.S) align 1 "nvvm.grid_constant" %arg)
27+

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "llvm/Support/Debug.h"
3030
#include <list>
3131
#include <map>
32-
#include <sstream>
3332

3433
template <typename T>
3534
static Fortran::semantics::Scope *GetScope(
@@ -61,6 +60,13 @@ template <typename T> class DirectiveAttributeVisitor {
6160
parser::OmpDefaultmapClause::ImplicitBehavior>
6261
defaultMap;
6362

63+
std::optional<Symbol::Flag> FindSymbolWithDSA(const Symbol &symbol) {
64+
if (auto it{objectWithDSA.find(&symbol)}; it != objectWithDSA.end()) {
65+
return it->second;
66+
}
67+
return std::nullopt;
68+
}
69+
6470
bool withinConstruct{false};
6571
std::int64_t associatedLoopLevel{0};
6672
};
@@ -75,10 +81,19 @@ template <typename T> class DirectiveAttributeVisitor {
7581
: std::make_optional<DirContext>(dirContext_.back());
7682
}
7783
void PushContext(const parser::CharBlock &source, T dir, Scope &scope) {
78-
dirContext_.emplace_back(source, dir, scope);
84+
if constexpr (std::is_same_v<T, llvm::acc::Directive>) {
85+
dirContext_.emplace_back(source, dir, scope);
86+
if (std::size_t size{dirContext_.size()}; size > 1) {
87+
std::size_t lastIndex{size - 1};
88+
dirContext_[lastIndex].defaultDSA =
89+
dirContext_[lastIndex - 1].defaultDSA;
90+
}
91+
} else {
92+
dirContext_.emplace_back(source, dir, scope);
93+
}
7994
}
8095
void PushContext(const parser::CharBlock &source, T dir) {
81-
dirContext_.emplace_back(source, dir, context_.FindScope(source));
96+
PushContext(source, dir, context_.FindScope(source));
8297
}
8398
void PopContext() { dirContext_.pop_back(); }
8499
void SetContextDirectiveSource(parser::CharBlock &dir) {
@@ -100,9 +115,21 @@ template <typename T> class DirectiveAttributeVisitor {
100115
AddToContextObjectWithDSA(symbol, flag, GetContext());
101116
}
102117
bool IsObjectWithDSA(const Symbol &symbol) {
103-
auto it{GetContext().objectWithDSA.find(&symbol)};
104-
return it != GetContext().objectWithDSA.end();
118+
return GetContext().FindSymbolWithDSA(symbol).has_value();
119+
}
120+
bool IsObjectWithVisibleDSA(const Symbol &symbol) {
121+
for (std::size_t i{dirContext_.size()}; i != 0; i--) {
122+
if (dirContext_[i - 1].FindSymbolWithDSA(symbol).has_value()) {
123+
return true;
124+
}
125+
}
126+
return false;
105127
}
128+
129+
bool WithinConstruct() {
130+
return !dirContext_.empty() && GetContext().withinConstruct;
131+
}
132+
106133
void SetContextAssociatedLoopLevel(std::int64_t level) {
107134
GetContext().associatedLoopLevel = level;
108135
}
@@ -1573,10 +1600,10 @@ void AccAttributeVisitor::Post(const parser::AccDefaultClause &x) {
15731600
// and adjust the symbol for each Name if necessary
15741601
void AccAttributeVisitor::Post(const parser::Name &name) {
15751602
auto *symbol{name.symbol};
1576-
if (symbol && !dirContext_.empty() && GetContext().withinConstruct) {
1603+
if (symbol && WithinConstruct()) {
15771604
symbol = &symbol->GetUltimate();
15781605
if (!symbol->owner().IsDerivedType() && !symbol->has<ProcEntityDetails>() &&
1579-
!symbol->has<SubprogramDetails>() && !IsObjectWithDSA(*symbol)) {
1606+
!symbol->has<SubprogramDetails>() && !IsObjectWithVisibleDSA(*symbol)) {
15801607
if (Symbol * found{currScope().FindSymbol(name.source)}) {
15811608
if (symbol != found) {
15821609
name.symbol = found; // adjust the symbol within region
@@ -1959,7 +1986,7 @@ void OmpAttributeVisitor::ResolveSeqLoopIndexInParallelOrTaskConstruct(
19591986
// till OpenMP-5.0 standard.
19601987
// In above both cases we skip the privatization of iteration variables.
19611988
bool OmpAttributeVisitor::Pre(const parser::DoConstruct &x) {
1962-
if (!dirContext_.empty() && GetContext().withinConstruct) {
1989+
if (WithinConstruct()) {
19631990
llvm::SmallVector<const parser::Name *> ivs;
19641991
if (x.IsDoNormal()) {
19651992
const parser::Name *iv{GetLoopIndex(x)};
@@ -2685,7 +2712,7 @@ void OmpAttributeVisitor::CreateImplicitSymbols(const Symbol *symbol) {
26852712
void OmpAttributeVisitor::Post(const parser::Name &name) {
26862713
auto *symbol{name.symbol};
26872714

2688-
if (symbol && !dirContext_.empty() && GetContext().withinConstruct) {
2715+
if (symbol && WithinConstruct()) {
26892716
if (IsPrivatizable(symbol) && !IsObjectWithDSA(*symbol)) {
26902717
// TODO: create a separate function to go through the rules for
26912718
// predetermined, explicitly determined, and implicitly

flang/test/Semantics/OpenACC/acc-parallel.f90

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,25 @@ program openacc_parallel_validity
200200
!$acc end parallel
201201

202202
end program openacc_parallel_validity
203+
204+
subroutine acc_parallel_default_none
205+
integer :: i, l
206+
real :: a(10,10)
207+
l = 10
208+
!$acc parallel default(none)
209+
!$acc loop
210+
!ERROR: The DEFAULT(NONE) clause requires that 'l' must be listed in a data-mapping clause
211+
do i = 1, l
212+
!ERROR: The DEFAULT(NONE) clause requires that 'a' must be listed in a data-mapping clause
213+
a(1,i) = 1
214+
end do
215+
!$acc end parallel
216+
217+
!$acc data copy(a)
218+
!$acc parallel loop firstprivate(l) default(none)
219+
do i = 1, l
220+
a(1,i) = 1
221+
end do
222+
!$acc end parallel
223+
!$acc end data
224+
end subroutine acc_parallel_default_none

lldb/tools/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_subdirectory(lldb-fuzzer EXCLUDE_FROM_ALL)
1010

1111
add_lldb_tool_subdirectory(lldb-instr)
1212
add_lldb_tool_subdirectory(lldb-dap)
13+
add_lldb_tool_subdirectory(lldb-mcp)
1314
if (LLDB_BUILD_LLDBRPC)
1415
add_lldb_tool_subdirectory(lldb-rpc-gen)
1516
endif()

lldb/tools/lldb-mcp/CMakeLists.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
add_lldb_tool(lldb-mcp
2+
lldb-mcp.cpp
3+
4+
LINK_COMPONENTS
5+
Option
6+
Support
7+
LINK_LIBS
8+
liblldb
9+
lldbHost
10+
lldbProtocolMCP
11+
)
12+
13+
if(APPLE)
14+
configure_file(
15+
${CMAKE_CURRENT_SOURCE_DIR}/lldb-mcp-Info.plist.in
16+
${CMAKE_CURRENT_BINARY_DIR}/lldb-mcp-Info.plist
17+
)
18+
target_link_options(lldb-mcp
19+
PRIVATE LINKER:-sectcreate,__TEXT,__info_plist,${CMAKE_CURRENT_BINARY_DIR}/lldb-mcp-Info.plist)
20+
endif()
21+
22+
if(LLDB_BUILD_FRAMEWORK)
23+
# In the build-tree, we know the exact path to the framework directory.
24+
# The installed framework can be in different locations.
25+
lldb_setup_rpaths(lldb-mcp
26+
BUILD_RPATH
27+
"${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}"
28+
INSTALL_RPATH
29+
"@loader_path/../../../SharedFrameworks"
30+
"@loader_path/../../System/Library/PrivateFrameworks"
31+
"@loader_path/../../Library/PrivateFrameworks"
32+
)
33+
endif()

0 commit comments

Comments
 (0)