Skip to content

Commit 105afd1

Browse files
Merge branch 'main' into main
2 parents 8b2f656 + 7108b12 commit 105afd1

File tree

18 files changed

+180
-177
lines changed

18 files changed

+180
-177
lines changed

bolt/include/bolt/Rewrite/RewriteInstance.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ class RewriteInstance {
139139
void handleRelocation(const object::SectionRef &RelocatedSection,
140140
const RelocationRef &Rel);
141141

142+
/// Collect functions that are specified to be bumped.
143+
void selectFunctionsToPrint();
144+
142145
/// Mark functions that are not meant for processing as ignored.
143146
void selectFunctionsToProcess();
144147

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ extern cl::OptionCategory BoltOptCategory;
6161

6262
extern cl::opt<bool> EnableBAT;
6363
extern cl::opt<bool> Instrument;
64+
extern cl::list<std::string> PrintOnly;
65+
extern cl::opt<std::string> PrintOnlyFile;
6466
extern cl::opt<bool> StrictMode;
6567
extern cl::opt<bool> UpdateDebugSections;
6668
extern cl::opt<unsigned> Verbosity;
@@ -133,14 +135,6 @@ PrintDynoStatsOnly("print-dyno-stats-only",
133135
cl::Hidden,
134136
cl::cat(BoltCategory));
135137

136-
static cl::list<std::string>
137-
PrintOnly("print-only",
138-
cl::CommaSeparated,
139-
cl::desc("list of functions to print"),
140-
cl::value_desc("func1,func2,func3,..."),
141-
cl::Hidden,
142-
cl::cat(BoltCategory));
143-
144138
cl::opt<bool>
145139
TimeBuild("time-build",
146140
cl::desc("print time spent constructing binary functions"),

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ extern cl::opt<bool> Hugify;
8282
extern cl::opt<bool> Instrument;
8383
extern cl::opt<bool> KeepNops;
8484
extern cl::opt<bool> Lite;
85+
extern cl::list<std::string> PrintOnly;
86+
extern cl::opt<std::string> PrintOnlyFile;
8587
extern cl::list<std::string> ReorderData;
8688
extern cl::opt<bolt::ReorderFunctions::ReorderType> ReorderFunctions;
8789
extern cl::opt<bool> TerminalHLT;
@@ -730,6 +732,8 @@ Error RewriteInstance::run() {
730732
<< "\n";
731733
BC->outs() << "BOLT-INFO: BOLT version: " << BoltRevision << "\n";
732734

735+
selectFunctionsToPrint();
736+
733737
if (Error E = discoverStorage())
734738
return E;
735739
if (Error E = readSpecialSections())
@@ -3100,17 +3104,22 @@ static BinaryFunction *getInitFunctionIfStaticBinary(BinaryContext &BC) {
31003104
return BC.getBinaryFunctionAtAddress(BD->getAddress());
31013105
}
31023106

3107+
static void populateFunctionNames(cl::opt<std::string> &FunctionNamesFile,
3108+
cl::list<std::string> &FunctionNames) {
3109+
if (FunctionNamesFile.empty())
3110+
return;
3111+
std::ifstream FuncsFile(FunctionNamesFile, std::ios::in);
3112+
std::string FuncName;
3113+
while (std::getline(FuncsFile, FuncName))
3114+
FunctionNames.push_back(FuncName);
3115+
}
3116+
3117+
void RewriteInstance::selectFunctionsToPrint() {
3118+
populateFunctionNames(opts::PrintOnlyFile, opts::PrintOnly);
3119+
}
3120+
31033121
void RewriteInstance::selectFunctionsToProcess() {
31043122
// Extend the list of functions to process or skip from a file.
3105-
auto populateFunctionNames = [](cl::opt<std::string> &FunctionNamesFile,
3106-
cl::list<std::string> &FunctionNames) {
3107-
if (FunctionNamesFile.empty())
3108-
return;
3109-
std::ifstream FuncsFile(FunctionNamesFile, std::ios::in);
3110-
std::string FuncName;
3111-
while (std::getline(FuncsFile, FuncName))
3112-
FunctionNames.push_back(FuncName);
3113-
};
31143123
populateFunctionNames(opts::FunctionNamesFile, opts::ForceFunctionNames);
31153124
populateFunctionNames(opts::SkipFunctionNamesFile, opts::SkipFunctionNames);
31163125
populateFunctionNames(opts::FunctionNamesFileNR, opts::ForceFunctionNamesNR);

bolt/lib/Utils/CommandLineOpts.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,16 @@ cl::opt<bool> PrintCacheMetrics(
245245
cl::desc("calculate and print various metrics for instruction cache"),
246246
cl::cat(BoltOptCategory));
247247

248+
cl::list<std::string> PrintOnly("print-only", cl::CommaSeparated,
249+
cl::desc("list of functions to print"),
250+
cl::value_desc("func1,func2,func3,..."),
251+
cl::Hidden, cl::cat(BoltCategory));
252+
253+
cl::opt<std::string>
254+
PrintOnlyFile("print-only-file",
255+
cl::desc("file with list of functions to print"), cl::Hidden,
256+
cl::cat(BoltCategory));
257+
248258
cl::opt<bool> PrintSections("print-sections",
249259
cl::desc("print all registered sections"),
250260
cl::Hidden, cl::cat(BoltCategory));

bolt/test/print-only.test

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Verify if `--print-only` and `--print-only-files` work fine.
2+
3+
# REQUIRES: system-linux
4+
5+
# RUN: %clang %cflags -x c %p/Inputs/bolt_icf.cpp -o %t -Wl,-q
6+
# RUN: llvm-bolt %t -o %t.bolt --icf=none --print-cfg \
7+
# RUN: --print-only=foo.*,bar.*,main.* 2>&1 | FileCheck %s
8+
9+
# RUN: echo "bar.*" > %t.pof
10+
# RUN: echo "main.*" >> %t.pof
11+
# RUN: llvm-bolt %t -o %t.bolt --icf=none --print-cfg \
12+
# RUN: --print-only=foo.* --print-only-file=%t.pof \
13+
# RUN: 2>&1 | FileCheck %s
14+
15+
# RUN: echo "foo.*" >> %t.pof
16+
# RUN: llvm-bolt %t -o %t.bolt --icf=none --print-cfg \
17+
# RUN: --print-only-file=%t.pof 2>&1 | FileCheck %s
18+
19+
# CHECK-NOT: Binary Function "fiz" after building cfg
20+
# CHECK-NOT: Binary Function "faz" after building cfg
21+
# CHECK-NOT: Binary Function "zip" after building cfg
22+
# CHECK-NOT: Binary Function "zap" after building cfg
23+
# CHECK: Binary Function "foo" after building cfg
24+
# CHECK: Binary Function "bar" after building cfg
25+
# CHECK: Binary Function "main" after building cfg

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,15 +1364,15 @@ DSAStackTy::DSAVarData DSAStackTy::getDSA(const_iterator &Iter,
13641364
DefaultDataSharingAttributes IterDA = Iter->DefaultAttr;
13651365
switch (Iter->DefaultVCAttr) {
13661366
case DSA_VC_aggregate:
1367-
if (!D->getType()->isAggregateType())
1367+
if (!VD->getType()->isAggregateType())
13681368
IterDA = DSA_none;
13691369
break;
13701370
case DSA_VC_pointer:
1371-
if (!D->getType()->isPointerType())
1371+
if (!VD->getType()->isPointerType())
13721372
IterDA = DSA_none;
13731373
break;
13741374
case DSA_VC_scalar:
1375-
if (!D->getType()->isScalarType())
1375+
if (!VD->getType()->isScalarType())
13761376
IterDA = DSA_none;
13771377
break;
13781378
case DSA_VC_all:

clang/test/OpenMP/parallel_default_variableCategory_codegen.cpp

Lines changed: 0 additions & 92 deletions
This file was deleted.

libc/cmake/modules/LLVMLibCArchitectures.cmake

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,37 @@ else()
215215
"Unsupported libc target operating system ${LIBC_TARGET_OS}")
216216
endif()
217217

218+
# If the compiler target triple is not the same as the triple specified by
219+
# LIBC_TARGET_TRIPLE or LLVM_RUNTIMES_TARGET, we will add a --target option
220+
# if the compiler is clang. If the compiler is GCC we just error out as there
221+
# is no equivalent of an option like --target.
222+
if(explicit_target_triple AND
223+
(NOT (libc_compiler_triple STREQUAL explicit_target_triple)))
224+
set(LIBC_CROSSBUILD TRUE)
225+
if(CMAKE_COMPILER_IS_GNUCXX)
226+
message(FATAL_ERROR
227+
"GCC target triple (${libc_compiler_triple}) and the explicity "
228+
"specified target triple (${explicit_target_triple}) do not match.")
229+
else()
230+
list(APPEND
231+
LIBC_COMPILE_OPTIONS_DEFAULT "--target=${explicit_target_triple}")
232+
endif()
233+
endif()
234+
235+
if(LIBC_TARGET_OS_IS_DARWIN)
236+
execute_process(
237+
COMMAND xcrun --sdk macosx --show-sdk-path
238+
OUTPUT_VARIABLE MACOSX_SDK_PATH
239+
RESULT_VARIABLE MACOSX_SDK_PATH_RESULT
240+
OUTPUT_STRIP_TRAILING_WHITESPACE
241+
)
242+
if(MACOSX_SDK_PATH_RESULT EQUAL 0)
243+
list(APPEND LIBC_COMPILE_OPTIONS_DEFAULT "-I" "${MACOSX_SDK_PATH}/usr/include")
244+
else()
245+
message(WARNING "Could not find macOS SDK path. `xcrun --sdk macosx --show-sdk-path` failed.")
246+
endif()
247+
endif()
248+
218249
# Windows does not support full mode build.
219250
if (LIBC_TARGET_OS_IS_WINDOWS AND LLVM_LIBC_FULL_BUILD)
220251
message(FATAL_ERROR "Windows does not support full mode build.")

libc/include/sys/syscall.h.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LLVM_LIBC_SYS_SYSCALL_H
1010
#define LLVM_LIBC_SYS_SYSCALL_H
1111

12-
//TODO: Handle non-linux syscalls
12+
#if defined(__linux__)
1313

1414
#include <asm/unistd.h>
1515

@@ -2361,5 +2361,6 @@
23612361
#define SYS_writev __NR_writev
23622362
#endif
23632363

2364+
#endif // __linux__
23642365

23652366
#endif // LLVM_LIBC_SYS_SYSCALL_H

libc/src/__support/File/file.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "src/__support/CPP/span.h"
1616
#include "src/__support/libc_errno.h" // For error macros
1717
#include "src/__support/macros/config.h"
18+
#include "src/string/memory_utils/inline_memcpy.h"
1819

1920
namespace LIBC_NAMESPACE_DECL {
2021

@@ -85,9 +86,7 @@ FileIOResult File::write_unlocked_fbf(const uint8_t *data, size_t len) {
8586
cpp::span<uint8_t> bufref(static_cast<uint8_t *>(buf), bufsize);
8687

8788
// Copy the first piece into the buffer.
88-
// TODO: Replace the for loop below with a call to internal memcpy.
89-
for (size_t i = 0; i < primary.size(); ++i)
90-
bufref[pos + i] = primary[i];
89+
inline_memcpy(bufref.data() + pos, primary.data(), primary.size());
9190
pos += primary.size();
9291

9392
// If there is no remainder, we can return early, since the first piece has
@@ -115,9 +114,7 @@ FileIOResult File::write_unlocked_fbf(const uint8_t *data, size_t len) {
115114
// know that if the second piece has data in it then the buffer has been
116115
// flushed, meaning that pos is always 0.
117116
if (remainder.size() < bufsize) {
118-
// TODO: Replace the for loop below with a call to internal memcpy.
119-
for (size_t i = 0; i < remainder.size(); ++i)
120-
bufref[i] = remainder[i];
117+
inline_memcpy(bufref.data(), remainder.data(), remainder.size());
121118
pos = remainder.size();
122119
} else {
123120

@@ -209,9 +206,7 @@ size_t File::copy_data_from_buf(uint8_t *data, size_t len) {
209206
// available_data is never a wrapped around value.
210207
size_t available_data = read_limit - pos;
211208
if (len <= available_data) {
212-
// TODO: Replace the for loop below with a call to internal memcpy.
213-
for (size_t i = 0; i < len; ++i)
214-
dataref[i] = bufref[i + pos];
209+
inline_memcpy(dataref.data(), bufref.data() + pos, len);
215210
pos += len;
216211
return len;
217212
}
@@ -255,8 +250,7 @@ FileIOResult File::read_unlocked_fbf(uint8_t *data, size_t len) {
255250
size_t fetched_size = result.value;
256251
read_limit += fetched_size;
257252
size_t transfer_size = fetched_size >= to_fetch ? to_fetch : fetched_size;
258-
for (size_t i = 0; i < transfer_size; ++i)
259-
dataref[i] = buf[i];
253+
inline_memcpy(dataref.data(), buf, transfer_size);
260254
pos += transfer_size;
261255
if (result.has_error() || fetched_size < to_fetch) {
262256
if (!result.has_error())

0 commit comments

Comments
 (0)