Skip to content

Commit 7b13f31

Browse files
author
iclsrc
committed
Merge from 'master' to 'sycl-web'
2 parents 194afac + 23657d9 commit 7b13f31

File tree

58 files changed

+1941
-561
lines changed

Some content is hidden

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

58 files changed

+1941
-561
lines changed

clang/include/clang/Driver/Compilation.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ class Compilation {
115115
/// Optional redirection for stdin, stdout, stderr.
116116
std::vector<Optional<StringRef>> Redirects;
117117

118+
/// Callback called after compilation job has been finished.
119+
/// Arguments of the callback are the compilation job as an instance of
120+
/// class Command and the exit status of the corresponding child process.
121+
std::function<void(const Command &, int)> PostCallback;
122+
118123
/// Whether we're compiling for diagnostic purposes.
119124
bool ForDiagnostics = false;
120125

@@ -212,6 +217,14 @@ class Compilation {
212217
return FailureResultFiles;
213218
}
214219

220+
/// Installs a handler that is executed when a compilation job is finished.
221+
/// The arguments of the callback specify the compilation job as an instance
222+
/// of class Command and the exit status of the child process executed that
223+
/// job.
224+
void setPostCallback(const std::function<void(const Command &, int)> &CB) {
225+
PostCallback = CB;
226+
}
227+
215228
/// Returns the sysroot path.
216229
StringRef getSysRoot() const;
217230

clang/include/clang/Tooling/Syntax/Tree.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ class Node {
118118

119119
const Node *getNextSibling() const { return NextSibling; }
120120
Node *getNextSibling() { return NextSibling; }
121+
const Node *getPreviousSibling() const { return PreviousSibling; }
122+
Node *getPreviousSibling() { return PreviousSibling; }
121123

122124
/// Dumps the structure of a subtree. For debugging and testing purposes.
123125
std::string dump(const SourceManager &SM) const;
@@ -144,6 +146,7 @@ class Node {
144146

145147
Tree *Parent;
146148
Node *NextSibling;
149+
Node *PreviousSibling;
147150
unsigned Kind : 16;
148151
unsigned Role : 8;
149152
unsigned Original : 1;
@@ -197,6 +200,8 @@ class Tree : public Node {
197200

198201
Node *getFirstChild() { return FirstChild; }
199202
const Node *getFirstChild() const { return FirstChild; }
203+
Node *getLastChild() { return LastChild; }
204+
const Node *getLastChild() const { return LastChild; }
200205

201206
const Leaf *findFirstLeaf() const;
202207
Leaf *findFirstLeaf() {
@@ -236,25 +241,32 @@ class Tree : public Node {
236241
using Node::Node;
237242

238243
private:
239-
/// Prepend \p Child to the list of children and and sets the parent pointer.
244+
/// Append \p Child to the list of children and sets the parent pointer.
240245
/// A very low-level operation that does not check any invariants, only used
241246
/// by TreeBuilder and FactoryImpl.
242247
/// EXPECTS: Role != Detached.
248+
void appendChildLowLevel(Node *Child, NodeRole Role);
249+
/// Similar but prepends.
243250
void prependChildLowLevel(Node *Child, NodeRole Role);
244-
/// Like the previous overload, but does not set role for \p Child.
251+
252+
/// Like the previous overloads, but does not set role for \p Child.
245253
/// EXPECTS: Child->Role != Detached
254+
void appendChildLowLevel(Node *Child);
246255
void prependChildLowLevel(Node *Child);
247256
friend class TreeBuilder;
248257
friend class FactoryImpl;
249258

250-
/// Replace a range of children [BeforeBegin->NextSibling, End) with a list of
259+
/// Replace a range of children [Begin, End) with a list of
251260
/// new nodes starting at \p New.
252261
/// Only used by MutationsImpl to implement higher-level mutation operations.
253262
/// (!) \p New can be null to model removal of the child range.
254-
void replaceChildRangeLowLevel(Node *BeforeBegin, Node *End, Node *New);
263+
/// (!) \p End can be null to model one past the end.
264+
/// (!) \p Begin can be null to model an append.
265+
void replaceChildRangeLowLevel(Node *Begin, Node *End, Node *New);
255266
friend class MutationsImpl;
256267

257268
Node *FirstChild = nullptr;
269+
Node *LastChild = nullptr;
258270
};
259271

260272
// Provide missing non_const == const overload.

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,9 @@ static PassBuilder::OptimizationLevel mapToLevel(const CodeGenOptions &Opts) {
10531053
default:
10541054
llvm_unreachable("Invalid optimization level!");
10551055

1056+
case 0:
1057+
return PassBuilder::OptimizationLevel::O0;
1058+
10561059
case 1:
10571060
return PassBuilder::OptimizationLevel::O1;
10581061

@@ -1282,6 +1285,10 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
12821285
ModulePassManager MPM(CodeGenOpts.DebugPassManager);
12831286

12841287
if (!CodeGenOpts.DisableLLVMPasses) {
1288+
// Map our optimization levels into one of the distinct levels used to
1289+
// configure the pipeline.
1290+
PassBuilder::OptimizationLevel Level = mapToLevel(CodeGenOpts);
1291+
12851292
bool IsThinLTO = CodeGenOpts.PrepareForThinLTO;
12861293
bool IsLTO = CodeGenOpts.PrepareForLTO;
12871294

@@ -1330,10 +1337,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
13301337
MPM.addPass(NameAnonGlobalPass());
13311338
}
13321339
} else {
1333-
// Map our optimization levels into one of the distinct levels used to
1334-
// configure the pipeline.
1335-
PassBuilder::OptimizationLevel Level = mapToLevel(CodeGenOpts);
1336-
13371340
// If we reached here with a non-empty index file name, then the index
13381341
// file was empty and we are not performing ThinLTO backend compilation
13391342
// (used in testing in a distributed build environment). Drop any the type
@@ -1471,6 +1474,8 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
14711474
}
14721475

14731476
if (CodeGenOpts.OptimizationLevel == 0) {
1477+
PB.runRegisteredEPCallbacks(MPM, Level, CodeGenOpts.DebugPassManager);
1478+
14741479
// FIXME: the backends do not handle matrix intrinsics currently. Make
14751480
// sure they are also lowered in O0. A lightweight version of the pass
14761481
// should run in the backend pipeline on demand.

clang/lib/Driver/Compilation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ int Compilation::ExecuteCommand(const Command &C,
228228
std::string Error;
229229
bool ExecutionFailed;
230230
int Res = C.Execute(Redirects, &Error, &ExecutionFailed);
231+
if (PostCallback)
232+
PostCallback(C, Res);
231233
if (!Error.empty()) {
232234
assert(Res && "Error string set with 0 result code!");
233235
getDriver().Diag(diag::err_drv_command_failure) << Error;

clang/lib/Tooling/Syntax/BuildTree.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,12 +636,11 @@ class syntax::TreeBuilder {
636636
(EndChildren == Trees.end() || EndChildren->first == Tokens.end()) &&
637637
"fold crosses boundaries of existing subtrees");
638638

639-
// We need to go in reverse order, because we can only prepend.
640-
for (auto It = EndChildren; It != BeginChildren; --It) {
641-
auto *C = std::prev(It)->second;
639+
for (auto It = BeginChildren; It != EndChildren; ++It) {
640+
auto *C = It->second;
642641
if (C->getRole() == NodeRole::Detached)
643642
C->setRole(NodeRole::Unknown);
644-
Node->prependChildLowLevel(C);
643+
Node->appendChildLowLevel(C);
645644
}
646645

647646
// Mark that this node came from the AST and is backed by the source code.

clang/lib/Tooling/Syntax/Mutations.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@
2323

2424
using namespace clang;
2525

26-
static syntax::Node *findPrevious(syntax::Node *N) {
27-
assert(N);
28-
assert(N->getParent());
29-
if (N->getParent()->getFirstChild() == N)
30-
return nullptr;
31-
for (syntax::Node *C = N->getParent()->getFirstChild(); C != nullptr;
32-
C = C->getNextSibling()) {
33-
if (C->getNextSibling() == N)
34-
return C;
35-
}
36-
llvm_unreachable("could not find a child node");
37-
}
38-
3926
// This class has access to the internals of tree nodes. Its sole purpose is to
4027
// define helpers that allow implementing the high-level mutation operations.
4128
class syntax::MutationsImpl {
@@ -46,12 +33,14 @@ class syntax::MutationsImpl {
4633
assert(Anchor->Parent != nullptr);
4734
assert(New->Parent == nullptr);
4835
assert(New->NextSibling == nullptr);
36+
assert(New->PreviousSibling == nullptr);
4937
assert(New->isDetached());
5038
assert(Role != NodeRole::Detached);
5139

5240
New->setRole(Role);
5341
auto *P = Anchor->getParent();
54-
P->replaceChildRangeLowLevel(Anchor, Anchor->getNextSibling(), New);
42+
P->replaceChildRangeLowLevel(Anchor->getNextSibling(),
43+
Anchor->getNextSibling(), New);
5544

5645
P->assertInvariants();
5746
}
@@ -63,11 +52,12 @@ class syntax::MutationsImpl {
6352
assert(Old->canModify());
6453
assert(New->Parent == nullptr);
6554
assert(New->NextSibling == nullptr);
55+
assert(New->PreviousSibling == nullptr);
6656
assert(New->isDetached());
6757

6858
New->Role = Old->Role;
6959
auto *P = Old->getParent();
70-
P->replaceChildRangeLowLevel(findPrevious(Old), Old->getNextSibling(), New);
60+
P->replaceChildRangeLowLevel(Old, Old->getNextSibling(), New);
7161

7262
P->assertInvariants();
7363
}
@@ -79,7 +69,7 @@ class syntax::MutationsImpl {
7969
assert(N->canModify());
8070

8171
auto *P = N->getParent();
82-
P->replaceChildRangeLowLevel(findPrevious(N), N->getNextSibling(),
72+
P->replaceChildRangeLowLevel(N, N->getNextSibling(),
8373
/*New=*/nullptr);
8474

8575
P->assertInvariants();

clang/lib/Tooling/Syntax/Synthesis.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ class clang::syntax::FactoryImpl {
2121
syntax::NodeRole R) {
2222
T->prependChildLowLevel(Child, R);
2323
}
24+
static void appendChildLowLevel(syntax::Tree *T, syntax::Node *Child,
25+
syntax::NodeRole R) {
26+
T->appendChildLowLevel(Child, R);
27+
}
2428

2529
static std::pair<FileID, ArrayRef<Token>>
2630
lexBuffer(syntax::Arena &A, std::unique_ptr<llvm::MemoryBuffer> Buffer) {
@@ -196,8 +200,8 @@ syntax::Tree *clang::syntax::createTree(
196200
syntax::NodeKind K) {
197201
auto *T = allocateTree(A, K);
198202
FactoryImpl::setCanModify(T);
199-
for (auto ChildIt = Children.rbegin(); ChildIt != Children.rend(); ++ChildIt)
200-
FactoryImpl::prependChildLowLevel(T, ChildIt->first, ChildIt->second);
203+
for (const auto &Child : Children)
204+
FactoryImpl::appendChildLowLevel(T, Child.first, Child.second);
201205

202206
T->assertInvariants();
203207
return T;

0 commit comments

Comments
 (0)