Skip to content

Commit 6671f0c

Browse files
authored
Merge branch 'main' into ckb_srlw
2 parents 14cc218 + 9f9b480 commit 6671f0c

File tree

1,803 files changed

+63952
-25542
lines changed

Some content is hidden

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

1,803 files changed

+63952
-25542
lines changed

.ci/monolithic-linux.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ cmake -S "${MONOREPO_ROOT}"/llvm -B "${BUILD_DIR}" \
6161
-D LLDB_ENABLE_PYTHON=ON \
6262
-D LLDB_ENFORCE_STRICT_TEST_REQUIREMENTS=ON \
6363
-D CMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
64-
-D CMAKE_EXE_LINKER_FLAGS="-no-pie"
64+
-D CMAKE_EXE_LINKER_FLAGS="-no-pie" \
65+
-D LLVM_ENABLE_WERROR=ON
6566

6667
start-group "ninja"
6768

bolt/runtime/instr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,11 @@ static char *getBinaryPath() {
714714
uint32_t Ret = __readlink(FindBuf, TargetPath, sizeof(TargetPath));
715715
assert(Ret != -1 && Ret != BufSize, "readlink error");
716716
TargetPath[Ret] = '\0';
717+
__close(FDdir);
717718
return TargetPath;
718719
}
719720
}
721+
__close(FDdir);
720722
return nullptr;
721723
}
722724

bolt/test/link_fdata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
# Regexes to extract FDATA lines from input and parse FDATA and pre-aggregated
3434
# profile data
35-
prefix_pat = re.compile(f"^# {args.prefix}: (.*)")
35+
prefix_pat = re.compile(f"^(#|//) {args.prefix}: (.*)")
3636

3737
# FDATA records:
3838
# <is symbol?> <closest elf symbol or DSO name> <relative FROM address>
@@ -61,7 +61,7 @@
6161
prefix_match = prefix_pat.match(line)
6262
if not prefix_match:
6363
continue
64-
profile_line = prefix_match.group(1)
64+
profile_line = prefix_match.group(2)
6565
fdata_match = fdata_pat.match(profile_line)
6666
preagg_match = preagg_pat.match(profile_line)
6767
nolbr_match = nolbr_pat.match(profile_line)

bolt/test/runtime/copy_file.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import sys
2+
import shutil
3+
4+
with open(sys.argv[1] + ".output") as log_file:
5+
lines = log_file.readlines()
6+
for line in lines:
7+
if line.startswith(sys.argv[2]):
8+
pid = line.split(" ")[1].strip()
9+
shutil.copy(
10+
sys.argv[1] + "." + pid + ".fdata",
11+
sys.argv[1] + "." + sys.argv[3] + ".fdata",
12+
)
13+
sys.exit(0)
14+
15+
sys.exit(1)

bolt/test/runtime/instrumentation-indirect-2.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int main() {
5050
return 0;
5151
}
5252
/*
53-
REQUIRES: system-linux,shell,fuser
53+
REQUIRES: system-linux,fuser
5454
5555
RUN: %clang %cflags %s -o %t.exe -Wl,-q -pie -fpie
5656
@@ -61,10 +61,14 @@ RUN: --instrumentation-wait-forks
6161
6262
# Instrumented program needs to finish returning zero
6363
# Both output and profile must contain all 16 functions
64-
RUN: %t.instrumented_conservative > %t.output
65-
# Wait for profile and output to be fully written
66-
RUN: bash %S/wait_file.sh %t.output
67-
RUN: bash %S/wait_file.sh %t.fdata
64+
# We need to use bash to invoke this as otherwise we hang inside a
65+
# popen.communicate call in lit's internal shell. Eventually we should not
66+
# need this.
67+
# TODO(boomanaiden154): Remove once
68+
# https://github.com/llvm/llvm-project/issues/156484 is fixed.
69+
RUN: bash -c "%t.instrumented_conservative; wait" > %t.output
70+
# We can just read because we ensure the profile will be fully written by
71+
# calling wait inside the bash invocation.
6872
RUN: cat %t.output | FileCheck %s --check-prefix=CHECK-OUTPUT
6973
RUN: cat %t.fdata | FileCheck %s --check-prefix=CHECK-COMMON-PROF
7074
@@ -112,14 +116,8 @@ RUN: bash %S/wait_file.sh %t.output
112116
# Make sure all functions were called
113117
RUN: cat %t.output | FileCheck %s --check-prefix=CHECK-OUTPUT
114118
115-
RUN: child_pid=$(cat %t.output | grep funcA | awk '{print $2;}')
116-
RUN: par_pid=$(cat %t.output | grep funcB | awk '{print $2;}')
117-
118-
RUN: bash %S/wait_file.sh %t.$child_pid.fdata
119-
RUN: bash %S/wait_file.sh %t.$par_pid.fdata
120-
121-
RUN: mv %t.$child_pid.fdata %t.child.fdata
122-
RUN: mv %t.$par_pid.fdata %t.parent.fdata
119+
RUN: %python %S/copy_file.py %t funcA child
120+
RUN: %python %S/copy_file.py %t funcB parent
123121
124122
# Instrumented binary must produce two profiles with only local calls
125123
# recorded. Functions called only in child should not appear in parent's

bolt/test/timers.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
/* This test checks timers for metadata manager phases.
2-
# RUN: %clang %cflags %s -o %t.exe
3-
# RUN: link_fdata %s %t.exe %t.fdata
4-
# RUN: llvm-bolt %t.exe -o %t.null --data %t.fdata -w %t.yaml --time-rewrite \
5-
# RUN: 2>&1 | FileCheck %s
6-
# RUN: link_fdata %s %t.exe %t.preagg PREAGG
7-
# RUN: perf2bolt %t.exe -o %t.null -p %t.preagg --pa --time-rewrite \
8-
# RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-P2B
1+
// This test checks timers for metadata manager phases.
2+
// RUN: %clang %cflags %s -o %t.exe
3+
// RUN: link_fdata %s %t.exe %t.fdata
4+
// RUN: llvm-bolt %t.exe -o %t.null --data %t.fdata -w %t.yaml --time-rewrite \
5+
// RUN: 2>&1 | FileCheck %s
6+
// RUN: link_fdata %s %t.exe %t.preagg PREAGG
7+
// RUN: perf2bolt %t.exe -o %t.null -p %t.preagg --pa --time-rewrite \
8+
// RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-P2B
99

10-
# CHECK-DAG: update metadata post-emit
11-
# CHECK-DAG: process section metadata
12-
# CHECK-DAG: process metadata pre-CFG
13-
# CHECK-DAG: process metadata post-CFG
14-
# CHECK-DAG: finalize metadata pre-emit
10+
// CHECK-DAG: update metadata post-emit
11+
// CHECK-DAG: process section metadata
12+
// CHECK-DAG: process metadata pre-CFG
13+
// CHECK-DAG: process metadata post-CFG
14+
// CHECK-DAG: finalize metadata pre-emit
1515

16-
# CHECK-P2B-DAG: process section metadata
17-
# CHECK-P2B-DAG: process metadata pre-CFG
16+
// CHECK-P2B-DAG: process section metadata
17+
// CHECK-P2B-DAG: process metadata pre-CFG
1818

19-
# FDATA: 0 [unknown] 0 1 main 0 1 0
20-
# PREAGG: B X:0 #main# 1 0
21-
*/
19+
// FDATA: 0 [unknown] 0 1 main 0 1 0
20+
// PREAGG: B X:0 #main# 1 0
2221
int main() { return 0; }

clang-tools-extra/clang-reorder-fields/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS
44
)
55

66
add_clang_library(clangReorderFields STATIC
7+
Designator.cpp
78
ReorderFieldsAction.cpp
89

910
DEPENDS
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
//===-- tools/extra/clang-reorder-fields/utils/Designator.cpp ---*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
///
9+
/// \file
10+
/// This file contains the definition of the Designator and Designators utility
11+
/// classes.
12+
///
13+
//===----------------------------------------------------------------------===//
14+
15+
#include "Designator.h"
16+
#include "clang/AST/ASTContext.h"
17+
#include "clang/AST/Expr.h"
18+
#include "llvm/Support/raw_ostream.h"
19+
20+
namespace clang {
21+
namespace reorder_fields {
22+
23+
void Designator::advanceToNextField() {
24+
assert(!isFinished() && "Iterator is already finished");
25+
switch (Tag) {
26+
case STRUCT:
27+
if (StructIt.Record->isUnion()) {
28+
// Union always finishes on first increment.
29+
StructIt.Field = StructIt.Record->field_end();
30+
Type = QualType();
31+
break;
32+
}
33+
++StructIt.Field;
34+
if (StructIt.Field != StructIt.Record->field_end()) {
35+
Type = StructIt.Field->getType();
36+
} else {
37+
Type = QualType();
38+
}
39+
break;
40+
case ARRAY:
41+
++ArrayIt.Index;
42+
break;
43+
case ARRAY_RANGE:
44+
ArrayIt.Index = ArrayRangeIt.End + 1;
45+
ArrayIt.Size = ArrayRangeIt.Size;
46+
Tag = ARRAY;
47+
break;
48+
}
49+
}
50+
51+
bool Designator::isFinished() {
52+
switch (Tag) {
53+
case STRUCT:
54+
return StructIt.Field == StructIt.Record->field_end();
55+
case ARRAY:
56+
return ArrayIt.Index == ArrayIt.Size;
57+
case ARRAY_RANGE:
58+
return ArrayRangeIt.End == ArrayRangeIt.Size;
59+
}
60+
return false;
61+
}
62+
63+
Designators::Designators(const Expr *Init, const InitListExpr *ILE,
64+
const ASTContext *Context)
65+
: Context(Context) {
66+
if (ILE->getType()->isArrayType()) {
67+
const ConstantArrayType *CAT =
68+
Context->getAsConstantArrayType(ILE->getType());
69+
// Only constant size arrays are supported.
70+
if (!CAT) {
71+
DesignatorList.clear();
72+
return;
73+
}
74+
DesignatorList.push_back(
75+
{CAT->getElementType(), 0, CAT->getSize().getZExtValue()});
76+
} else {
77+
const RecordDecl *DesignatorRD = ILE->getType()->getAsRecordDecl();
78+
DesignatorList.push_back({DesignatorRD->field_begin()->getType(),
79+
DesignatorRD->field_begin(), DesignatorRD});
80+
}
81+
82+
// If the designator list is empty at this point, then there must be excess
83+
// elements in the initializer list. They are not currently supported.
84+
if (DesignatorList.empty())
85+
return;
86+
87+
if (!enterImplicitInitLists(Init))
88+
DesignatorList.clear();
89+
}
90+
91+
Designators::Designators(const DesignatedInitExpr *DIE, const InitListExpr *ILE,
92+
const ASTContext *Context)
93+
: Context(Context) {
94+
for (const auto &D : DIE->designators()) {
95+
if (D.isFieldDesignator()) {
96+
RecordDecl *DesignatorRecord = D.getFieldDecl()->getParent();
97+
for (auto FieldIt = DesignatorRecord->field_begin();
98+
FieldIt != DesignatorRecord->field_end(); ++FieldIt) {
99+
if (*FieldIt == D.getFieldDecl()) {
100+
DesignatorList.push_back(
101+
{FieldIt->getType(), FieldIt, DesignatorRecord});
102+
break;
103+
}
104+
}
105+
} else {
106+
const QualType CurrentType = DesignatorList.empty()
107+
? ILE->getType()
108+
: DesignatorList.back().getType();
109+
const ConstantArrayType *CAT =
110+
Context->getAsConstantArrayType(CurrentType);
111+
if (!CAT) {
112+
// Non-constant-sized arrays are not supported.
113+
DesignatorList.clear();
114+
return;
115+
}
116+
if (D.isArrayDesignator()) {
117+
DesignatorList.push_back({CAT->getElementType(),
118+
DIE->getArrayIndex(D)
119+
->EvaluateKnownConstInt(*Context)
120+
.getZExtValue(),
121+
CAT->getSize().getZExtValue()});
122+
} else if (D.isArrayRangeDesignator()) {
123+
DesignatorList.push_back({CAT->getElementType(),
124+
DIE->getArrayRangeStart(D)
125+
->EvaluateKnownConstInt(*Context)
126+
.getZExtValue(),
127+
DIE->getArrayRangeEnd(D)
128+
->EvaluateKnownConstInt(*Context)
129+
.getZExtValue(),
130+
CAT->getSize().getZExtValue()});
131+
} else {
132+
llvm_unreachable("Unexpected designator kind");
133+
}
134+
}
135+
}
136+
}
137+
138+
bool Designators::advanceToNextField(const Expr *Init) {
139+
// Remove all designators that refer to the last field of a struct or final
140+
// element of the array.
141+
while (!DesignatorList.empty()) {
142+
auto &CurrentDesignator = DesignatorList.back();
143+
CurrentDesignator.advanceToNextField();
144+
if (CurrentDesignator.isFinished()) {
145+
DesignatorList.pop_back();
146+
continue;
147+
}
148+
break;
149+
}
150+
151+
// If the designator list is empty at this point, then there must be excess
152+
// elements in the initializer list. They are not currently supported.
153+
if (DesignatorList.empty())
154+
return false;
155+
156+
if (!enterImplicitInitLists(Init)) {
157+
DesignatorList.clear();
158+
return false;
159+
}
160+
161+
return true;
162+
}
163+
164+
bool Designators::enterImplicitInitLists(const Expr *Init) {
165+
// Check for missing braces by comparing the type of the last designator and
166+
// type of Init.
167+
while (true) {
168+
const QualType T = DesignatorList.back().getType();
169+
// If the types match, there are no missing braces.
170+
if (Init->getType() == T)
171+
break;
172+
173+
// If the current type is a struct, then get its first field.
174+
if (T->isRecordType()) {
175+
DesignatorList.push_back({T->getAsRecordDecl()->field_begin()->getType(),
176+
T->getAsRecordDecl()->field_begin(),
177+
T->getAsRecordDecl()});
178+
continue;
179+
}
180+
// If the current type is an array, then get its first element.
181+
if (T->isArrayType()) {
182+
DesignatorList.push_back(
183+
{Context->getAsArrayType(T)->getElementType(), 0,
184+
Context->getAsConstantArrayType(T)->getSize().getZExtValue()});
185+
continue;
186+
}
187+
188+
// The initializer doesn't match the expected type. The initializer list is
189+
// invalid.
190+
return false;
191+
}
192+
193+
return true;
194+
}
195+
196+
std::string Designators::toString() const {
197+
if (DesignatorList.empty())
198+
return "";
199+
std::string Designator;
200+
llvm::raw_string_ostream OS(Designator);
201+
for (auto &I : DesignatorList) {
202+
switch (I.getTag()) {
203+
case Designator::STRUCT:
204+
OS << '.' << I.getStructIter()->getName();
205+
break;
206+
case Designator::ARRAY:
207+
OS << '[' << I.getArrayIndex() << ']';
208+
break;
209+
case Designator::ARRAY_RANGE:
210+
OS << '[' << I.getArrayRangeStart() << "..." << I.getArrayRangeEnd()
211+
<< ']';
212+
}
213+
}
214+
OS << " = ";
215+
return Designator;
216+
}
217+
218+
} // namespace reorder_fields
219+
} // namespace clang

0 commit comments

Comments
 (0)