Skip to content

Commit 0d8ce24

Browse files
committed
Merge from 'master' to 'sycl-web' (#6)
CONFLICT (content): Merge conflict in clang/lib/Driver/Driver.cpp
2 parents 8205e86 + 406de17 commit 0d8ce24

Some content is hidden

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

65 files changed

+888
-150
lines changed

clang/include/clang/Driver/Action.h

+12
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class Action {
6565
BackendJobClass,
6666
AssembleJobClass,
6767
LinkJobClass,
68+
IfsMergeJobClass,
6869
LipoJobClass,
6970
DsymutilJobClass,
7071
VerifyDebugInfoJobClass,
@@ -490,6 +491,17 @@ class AssembleJobAction : public JobAction {
490491
}
491492
};
492493

494+
class IfsMergeJobAction : public JobAction {
495+
void anchor() override;
496+
497+
public:
498+
IfsMergeJobAction(ActionList &Inputs, types::ID Type);
499+
500+
static bool classof(const Action *A) {
501+
return A->getKind() == IfsMergeJobClass;
502+
}
503+
};
504+
493505
class LinkJobAction : public JobAction {
494506
void anchor() override;
495507

clang/include/clang/Driver/Options.td

+3
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,9 @@ def emit_llvm : Flag<["-"], "emit-llvm">, Flags<[CC1Option]>, Group<Action_Group
655655
HelpText<"Use the LLVM representation for assembler and object files">;
656656
def emit_iterface_stubs : Flag<["-"], "emit-interface-stubs">, Flags<[CC1Option]>, Group<Action_Group>,
657657
HelpText<"Generate Inteface Stub Files.">;
658+
def emit_merged_ifs : Flag<["-"], "emit-merged-ifs">,
659+
Flags<[CC1Option]>, Group<Action_Group>,
660+
HelpText<"Generate Interface Stub Files, emit merged text not binary.">;
658661
def iterface_stub_version_EQ : JoinedOrSeparate<["-"], "interface-stub-version=">, Flags<[CC1Option]>;
659662
def exported__symbols__list : Separate<["-"], "exported_symbols_list">;
660663
def e : JoinedOrSeparate<["-"], "e">, Group<Link_Group>;

clang/include/clang/Driver/Phases.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ namespace phases {
2020
Compile,
2121
Backend,
2222
Assemble,
23-
Link
23+
Link,
24+
IfsMerge,
2425
};
2526

2627
enum {

clang/include/clang/Driver/ToolChain.h

+2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ class ToolChain {
136136
mutable std::unique_ptr<Tool> Clang;
137137
mutable std::unique_ptr<Tool> Assemble;
138138
mutable std::unique_ptr<Tool> Link;
139+
mutable std::unique_ptr<Tool> IfsMerge;
139140
mutable std::unique_ptr<Tool> OffloadBundler;
140141
mutable std::unique_ptr<Tool> OffloadWrapper;
141142
mutable std::unique_ptr<Tool> SPIRVTranslator;
@@ -145,6 +146,7 @@ class ToolChain {
145146
Tool *getClang() const;
146147
Tool *getAssemble() const;
147148
Tool *getLink() const;
149+
Tool *getIfsMerge() const;
148150
Tool *getClangAs() const;
149151
Tool *getOffloadBundler() const;
150152
Tool *getOffloadWrapper() const;

clang/include/clang/Driver/Types.def

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ TYPE("lto-bc", LTO_BC, INVALID, "o", phases
8484

8585
// Misc.
8686
TYPE("ast", AST, INVALID, "ast", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
87-
TYPE("ifs", IFS, INVALID, "ifs", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
87+
TYPE("ifs", IFS, INVALID, "ifs", phases::IfsMerge)
88+
TYPE("ifs-cpp", IFS_CPP, INVALID, "ifs", phases::Compile, phases::IfsMerge)
8889
TYPE("pcm", ModuleFile, INVALID, "pcm", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
8990
TYPE("plist", Plist, INVALID, "plist", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
9091
TYPE("rewritten-objc", RewrittenObjC,INVALID, "cpp", phases::Compile, phases::Backend, phases::Assemble, phases::Link)

clang/lib/CodeGen/CodeGenPGO.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class CodeGenPGO {
4141

4242
public:
4343
CodeGenPGO(CodeGenModule &CGM)
44-
: CGM(CGM), NumValueSites({{0}}), NumRegionCounters(0), FunctionHash(0),
45-
CurrentRegionCount(0) {}
44+
: CGM(CGM), FuncNameVar(nullptr), NumValueSites({{0}}),
45+
NumRegionCounters(0), FunctionHash(0), CurrentRegionCount(0) {}
4646

4747
/// Whether or not we have PGO region data for the current function. This is
4848
/// false both when we have no data at all and when our data has been

clang/lib/CodeGen/ItaniumCXXABI.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,8 @@ CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer(
580580

581581
const FunctionProtoType *FPT =
582582
MPT->getPointeeType()->getAs<FunctionProtoType>();
583-
const CXXRecordDecl *RD =
584-
cast<CXXRecordDecl>(MPT->getClass()->getAs<RecordType>()->getDecl());
583+
auto *RD =
584+
cast<CXXRecordDecl>(MPT->getClass()->castAs<RecordType>()->getDecl());
585585

586586
llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(
587587
CGM.getTypes().arrangeCXXMethodType(RD, FPT, /*FD=*/nullptr));
@@ -1143,7 +1143,7 @@ void ItaniumCXXABI::emitVirtualObjectDelete(CodeGenFunction &CGF,
11431143

11441144
// Grab the vtable pointer as an intptr_t*.
11451145
auto *ClassDecl =
1146-
cast<CXXRecordDecl>(ElementType->getAs<RecordType>()->getDecl());
1146+
cast<CXXRecordDecl>(ElementType->castAs<RecordType>()->getDecl());
11471147
llvm::Value *VTable =
11481148
CGF.GetVTablePtr(Ptr, CGF.IntPtrTy->getPointerTo(), ClassDecl);
11491149

@@ -1346,7 +1346,7 @@ llvm::Value *ItaniumCXXABI::EmitTypeid(CodeGenFunction &CGF,
13461346
Address ThisPtr,
13471347
llvm::Type *StdTypeInfoPtrTy) {
13481348
auto *ClassDecl =
1349-
cast<CXXRecordDecl>(SrcRecordTy->getAs<RecordType>()->getDecl());
1349+
cast<CXXRecordDecl>(SrcRecordTy->castAs<RecordType>()->getDecl());
13501350
llvm::Value *Value =
13511351
CGF.GetVTablePtr(ThisPtr, StdTypeInfoPtrTy->getPointerTo(), ClassDecl);
13521352

@@ -1412,7 +1412,7 @@ llvm::Value *ItaniumCXXABI::EmitDynamicCastToVoid(CodeGenFunction &CGF,
14121412
llvm::Type *DestLTy = CGF.ConvertType(DestTy);
14131413

14141414
auto *ClassDecl =
1415-
cast<CXXRecordDecl>(SrcRecordTy->getAs<RecordType>()->getDecl());
1415+
cast<CXXRecordDecl>(SrcRecordTy->castAs<RecordType>()->getDecl());
14161416
// Get the vtable pointer.
14171417
llvm::Value *VTable = CGF.GetVTablePtr(ThisAddr, PtrDiffLTy->getPointerTo(),
14181418
ClassDecl);
@@ -3100,8 +3100,8 @@ static bool CanUseSingleInheritance(const CXXRecordDecl *RD) {
31003100
return false;
31013101

31023102
// Check that the class is dynamic iff the base is.
3103-
const CXXRecordDecl *BaseDecl =
3104-
cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
3103+
auto *BaseDecl =
3104+
cast<CXXRecordDecl>(Base->getType()->castAs<RecordType>()->getDecl());
31053105
if (!BaseDecl->isEmpty() &&
31063106
BaseDecl->isDynamicClass() != RD->isDynamicClass())
31073107
return false;
@@ -3564,8 +3564,8 @@ static unsigned ComputeVMIClassTypeInfoFlags(const CXXBaseSpecifier *Base,
35643564

35653565
unsigned Flags = 0;
35663566

3567-
const CXXRecordDecl *BaseDecl =
3568-
cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
3567+
auto *BaseDecl =
3568+
cast<CXXRecordDecl>(Base->getType()->castAs<RecordType>()->getDecl());
35693569

35703570
if (Base->isVirtual()) {
35713571
// Mark the virtual base as seen.
@@ -3663,8 +3663,8 @@ void ItaniumRTTIBuilder::BuildVMIClassTypeInfo(const CXXRecordDecl *RD) {
36633663
// The __base_type member points to the RTTI for the base type.
36643664
Fields.push_back(ItaniumRTTIBuilder(CXXABI).BuildTypeInfo(Base.getType()));
36653665

3666-
const CXXRecordDecl *BaseDecl =
3667-
cast<CXXRecordDecl>(Base.getType()->getAs<RecordType>()->getDecl());
3666+
auto *BaseDecl =
3667+
cast<CXXRecordDecl>(Base.getType()->castAs<RecordType>()->getDecl());
36683668

36693669
int64_t OffsetFlags = 0;
36703670

clang/lib/Driver/Action.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const char *Action::getClassName(ActionClass AC) {
3131
case CompileJobClass: return "compiler";
3232
case BackendJobClass: return "backend";
3333
case AssembleJobClass: return "assembler";
34+
case IfsMergeJobClass: return "interface-stub-merger";
3435
case LinkJobClass: return "linker";
3536
case LipoJobClass: return "lipo";
3637
case DsymutilJobClass: return "dsymutil";
@@ -371,6 +372,11 @@ void AssembleJobAction::anchor() {}
371372
AssembleJobAction::AssembleJobAction(Action *Input, types::ID OutputType)
372373
: JobAction(AssembleJobClass, Input, OutputType) {}
373374

375+
void IfsMergeJobAction::anchor() {}
376+
377+
IfsMergeJobAction::IfsMergeJobAction(ActionList &Inputs, types::ID Type)
378+
: JobAction(IfsMergeJobClass, Inputs, Type) {}
379+
374380
void LinkJobAction::anchor() {}
375381

376382
LinkJobAction::LinkJobAction(ActionList &Inputs, types::ID Type)

clang/lib/Driver/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ add_clang_library(clangDriver
6767
ToolChains/XCore.cpp
6868
ToolChains/SYCL.cpp
6969
ToolChains/PPCLinux.cpp
70+
ToolChains/InterfaceStubs.cpp
7071
Types.cpp
7172
XRayArgs.cpp
7273

clang/lib/Driver/Driver.cpp

+28-6
Original file line numberDiff line numberDiff line change
@@ -275,33 +275,36 @@ phases::ID Driver::getFinalPhase(const DerivedArgList &DAL,
275275
(PhaseArg = DAL.getLastArg(options::OPT__SLASH_P))) {
276276
FinalPhase = phases::Preprocess;
277277

278-
// --precompile only runs up to precompilation.
278+
// --precompile only runs up to precompilation.
279279
} else if ((PhaseArg = DAL.getLastArg(options::OPT__precompile))) {
280280
FinalPhase = phases::Precompile;
281281

282-
// -{fsyntax-only,-analyze,emit-ast} only run up to the compiler.
282+
// -{fsyntax-only,-analyze,emit-ast} only run up to the compiler.
283283
} else if ((PhaseArg = DAL.getLastArg(options::OPT_fsyntax_only)) ||
284284
(PhaseArg = DAL.getLastArg(options::OPT_print_supported_cpus)) ||
285285
(PhaseArg = DAL.getLastArg(options::OPT_module_file_info)) ||
286286
(PhaseArg = DAL.getLastArg(options::OPT_verify_pch)) ||
287287
(PhaseArg = DAL.getLastArg(options::OPT_rewrite_objc)) ||
288288
(PhaseArg = DAL.getLastArg(options::OPT_rewrite_legacy_objc)) ||
289289
(PhaseArg = DAL.getLastArg(options::OPT__migrate)) ||
290-
(PhaseArg = DAL.getLastArg(options::OPT_emit_iterface_stubs)) ||
291290
(PhaseArg = DAL.getLastArg(options::OPT__analyze)) ||
292291
(PhaseArg = DAL.getLastArg(options::OPT_emit_ast))) {
293292
FinalPhase = phases::Compile;
294293

294+
// clang interface stubs
295+
} else if ((PhaseArg = DAL.getLastArg(options::OPT_emit_iterface_stubs))) {
296+
FinalPhase = phases::IfsMerge;
297+
295298
// -S only runs up to the backend.
296299
} else if ((PhaseArg = DAL.getLastArg(options::OPT_S)) ||
297300
(PhaseArg = DAL.getLastArg(options::OPT_sycl_device_only))) {
298301
FinalPhase = phases::Backend;
299302

300-
// -c compilation only runs up to the assembler.
303+
// -c compilation only runs up to the assembler.
301304
} else if ((PhaseArg = DAL.getLastArg(options::OPT_c))) {
302305
FinalPhase = phases::Assemble;
303306

304-
// Otherwise do everything.
307+
// Otherwise do everything.
305308
} else
306309
FinalPhase = phases::Link;
307310

@@ -4085,6 +4088,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
40854088
// Construct the actions to perform.
40864089
HeaderModulePrecompileJobAction *HeaderModuleAction = nullptr;
40874090
ActionList LinkerInputs;
4091+
ActionList MergerInputs;
40884092

40894093
llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> PL;
40904094
for (auto &I : Inputs) {
@@ -4124,6 +4128,17 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
41244128
break;
41254129
}
41264130

4131+
// TODO: Consider removing this because the merged may not end up being
4132+
// the final Phase in the pipeline. Perhaps the merged could just merge
4133+
// and then pass an artifact of some sort to the Link Phase.
4134+
// Queue merger inputs.
4135+
if (Phase == phases::IfsMerge) {
4136+
assert(Phase == PL.back() && "merging must be final compilation step.");
4137+
MergerInputs.push_back(Current);
4138+
Current = nullptr;
4139+
break;
4140+
}
4141+
41274142
// Each precompiled header file after a module file action is a module
41284143
// header of that same module file, rather than being compiled to a
41294144
// separate PCH.
@@ -4253,6 +4268,11 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
42534268
Actions.push_back(LA);
42544269
}
42554270

4271+
// Add an interface stubs merge action if necessary.
4272+
if (!MergerInputs.empty())
4273+
Actions.push_back(
4274+
C.MakeAction<IfsMergeJobAction>(MergerInputs, types::TY_Image));
4275+
42564276
// If --print-supported-cpus, -mcpu=? or -mtune=? is specified, build a custom
42574277
// Compile phase that prints out supported cpu models and quits.
42584278
if (Arg *A = Args.getLastArg(options::OPT_print_supported_cpus)) {
@@ -4289,6 +4309,8 @@ Action *Driver::ConstructPhaseAction(
42894309
switch (Phase) {
42904310
case phases::Link:
42914311
llvm_unreachable("link action invalid here.");
4312+
case phases::IfsMerge:
4313+
llvm_unreachable("ifsmerge action invalid here.");
42924314
case phases::Preprocess: {
42934315
types::ID OutputTy;
42944316
// -M and -MM specify the dependency file name by altering the output type,
@@ -4353,7 +4375,7 @@ Action *Driver::ConstructPhaseAction(
43534375
if (Args.hasArg(options::OPT_verify_pch))
43544376
return C.MakeAction<VerifyPCHJobAction>(Input, types::TY_Nothing);
43554377
if (Args.hasArg(options::OPT_emit_iterface_stubs))
4356-
return C.MakeAction<CompileJobAction>(Input, types::TY_IFS);
4378+
return C.MakeAction<CompileJobAction>(Input, types::TY_IFS_CPP);
43574379
return C.MakeAction<CompileJobAction>(Input, types::TY_LLVM_BC);
43584380
}
43594381
case phases::Backend: {

clang/lib/Driver/Phases.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const char *phases::getPhaseName(ID Id) {
2020
case Backend: return "backend";
2121
case Assemble: return "assembler";
2222
case Link: return "linker";
23+
case IfsMerge: return "ifsmerger";
2324
}
2425

2526
llvm_unreachable("Invalid phase id.");

clang/lib/Driver/ToolChain.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "InputInfo.h"
1111
#include "ToolChains/Arch/ARM.h"
1212
#include "ToolChains/Clang.h"
13+
#include "ToolChains/InterfaceStubs.h"
1314
#include "clang/Basic/ObjCRuntime.h"
1415
#include "clang/Basic/Sanitizers.h"
1516
#include "clang/Config/config.h"
@@ -283,6 +284,12 @@ Tool *ToolChain::getLink() const {
283284
return Link.get();
284285
}
285286

287+
Tool *ToolChain::getIfsMerge() const {
288+
if (!IfsMerge)
289+
IfsMerge.reset(new tools::ifstool::Merger(*this));
290+
return IfsMerge.get();
291+
}
292+
286293
Tool *ToolChain::getOffloadBundler() const {
287294
if (!OffloadBundler)
288295
OffloadBundler.reset(new tools::OffloadBundler(*this));
@@ -318,6 +325,9 @@ Tool *ToolChain::getTool(Action::ActionClass AC) const {
318325
case Action::AssembleJobClass:
319326
return getAssemble();
320327

328+
case Action::IfsMergeJobClass:
329+
return getIfsMerge();
330+
321331
case Action::LinkJobClass:
322332
return getLink();
323333

clang/lib/Driver/ToolChains/Clang.cpp

+4-21
Original file line numberDiff line numberDiff line change
@@ -3766,32 +3766,15 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
37663766
} else if (JA.getType() == types::TY_LLVM_BC ||
37673767
JA.getType() == types::TY_LTO_BC) {
37683768
CmdArgs.push_back("-emit-llvm-bc");
3769-
} else if (JA.getType() == types::TY_IFS) {
3769+
} else if (JA.getType() == types::TY_IFS ||
3770+
JA.getType() == types::TY_IFS_CPP) {
37703771
StringRef ArgStr =
37713772
Args.hasArg(options::OPT_iterface_stub_version_EQ)
37723773
? Args.getLastArgValue(options::OPT_iterface_stub_version_EQ)
3773-
: "";
3774-
StringRef StubFormat =
3775-
llvm::StringSwitch<StringRef>(ArgStr)
3776-
.Case("experimental-ifs-v1", "experimental-ifs-v1")
3777-
.Default("");
3778-
3779-
if (StubFormat.empty()) {
3780-
std::string ErrorMessage =
3781-
"Invalid interface stub format: " + ArgStr.str() +
3782-
((ArgStr == "experimental-yaml-elf-v1" ||
3783-
ArgStr == "experimental-tapi-elf-v1")
3784-
? " is deprecated."
3785-
: ".");
3786-
D.Diag(diag::err_drv_invalid_value)
3787-
<< "Must specify a valid interface stub format type, ie: "
3788-
"-interface-stub-version=experimental-ifs-v1"
3789-
<< ErrorMessage;
3790-
}
3791-
3774+
: "experimental-ifs-v1";
37923775
CmdArgs.push_back("-emit-interface-stubs");
37933776
CmdArgs.push_back(
3794-
Args.MakeArgString(Twine("-interface-stub-version=") + StubFormat));
3777+
Args.MakeArgString(Twine("-interface-stub-version=") + ArgStr.str()));
37953778
} else if (JA.getType() == types::TY_PP_Asm) {
37963779
CmdArgs.push_back("-S");
37973780
} else if (JA.getType() == types::TY_AST) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===--- InterfaceStubs.cpp - Base InterfaceStubs Implementations 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+
#include "InterfaceStubs.h"
10+
#include "CommonArgs.h"
11+
#include "clang/Driver/Compilation.h"
12+
13+
namespace clang {
14+
namespace driver {
15+
namespace tools {
16+
namespace ifstool {
17+
void Merger::ConstructJob(Compilation &C, const JobAction &JA,
18+
const InputInfo &Output, const InputInfoList &Inputs,
19+
const llvm::opt::ArgList &Args,
20+
const char *LinkingOutput) const {
21+
std::string Merger = getToolChain().GetProgramPath(getShortName());
22+
llvm::opt::ArgStringList CmdArgs;
23+
CmdArgs.push_back("-action");
24+
CmdArgs.push_back(Args.getLastArg(options::OPT_emit_merged_ifs)
25+
? "write-ifs"
26+
: "write-bin");
27+
CmdArgs.push_back("-o");
28+
CmdArgs.push_back(Output.getFilename());
29+
for (const auto &Input : Inputs)
30+
CmdArgs.push_back(Input.getFilename());
31+
C.addCommand(std::make_unique<Command>(JA, *this, Args.MakeArgString(Merger),
32+
CmdArgs, Inputs));
33+
}
34+
} // namespace ifstool
35+
} // namespace tools
36+
} // namespace driver
37+
} // namespace clang

0 commit comments

Comments
 (0)