Skip to content

Commit f55da9a

Browse files
committed
Addressed review comments
Signed-off-by: Sergey Dmitriev <[email protected]>
1 parent ed4d6ec commit f55da9a

File tree

1 file changed

+22
-27
lines changed

1 file changed

+22
-27
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2887,7 +2887,7 @@ class OffloadingActionBuilder final {
28872887
virtual void appendLinkDependences(OffloadAction::DeviceDependences &DA) {}
28882888

28892889
/// Append linker actions generated by the builder.
2890-
virtual void addDeviceLinkDependences(OffloadDepsJobAction *DA) {}
2890+
virtual void addDeviceLinkDependencies(OffloadDepsJobAction *DA) {}
28912891

28922892
/// Initialize the builder. Return true if any initialization errors are
28932893
/// found.
@@ -3610,7 +3610,7 @@ class OffloadingActionBuilder final {
36103610

36113611
void appendLinkDependences(OffloadAction::DeviceDependences &DA) override {}
36123612

3613-
void addDeviceLinkDependences(OffloadDepsJobAction *DA) override {
3613+
void addDeviceLinkDependencies(OffloadDepsJobAction *DA) override {
36143614
for (unsigned I = 0; I < ToolChains.size(); ++I) {
36153615
// Register dependent toolchain.
36163616
DA->registerDependentActionInfo(
@@ -4361,7 +4361,7 @@ class OffloadingActionBuilder final {
43614361
}
43624362
}
43634363

4364-
void addDeviceLinkDependences(OffloadDepsJobAction *DA) override {
4364+
void addDeviceLinkDependencies(OffloadDepsJobAction *DA) override {
43654365
for (unsigned I = 0; I < ToolChains.size(); ++I) {
43664366
// Register dependent toolchain.
43674367
DA->registerDependentActionInfo(
@@ -4774,7 +4774,11 @@ class OffloadingActionBuilder final {
47744774
return false;
47754775
}
47764776

4777-
void addDeviceDependencies(ActionList &LinkerInputs) {
4777+
/// Create link job from the given host inputs and feed the result to offload
4778+
/// deps job which fetches device dependencies from the linked host image.
4779+
/// Offload deps output is then forwarded to active device action builders so
4780+
/// they can add it to the device linker inputs.
4781+
void addDeviceLinkDependenciesFromHost(ActionList &LinkerInputs) {
47784782
// Link image for reading dependencies from it.
47794783
auto *LA = C.MakeAction<LinkJobAction>(LinkerInputs, types::TY_Image);
47804784

@@ -4792,7 +4796,7 @@ class OffloadingActionBuilder final {
47924796
for (auto *SB : SpecializedBuilders) {
47934797
if (!SB->isValid())
47944798
continue;
4795-
SB->addDeviceLinkDependences(DA);
4799+
SB->addDeviceLinkDependencies(DA);
47964800
}
47974801
}
47984802

@@ -5123,7 +5127,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
51235127
// With static fat archives we need to create additional steps for
51245128
// generating dependence objects for device link actions.
51255129
if (!LinkerInputs.empty() && C.getDriver().getOffloadStaticLibSeen())
5126-
OffloadBuilder.addDeviceDependencies(LinkerInputs);
5130+
OffloadBuilder.addDeviceLinkDependenciesFromHost(LinkerInputs);
51275131

51285132
// Go through all of the args, and create a Linker specific argument list.
51295133
// When dealing with fat static archives each archive is individually
@@ -6026,11 +6030,10 @@ InputInfo Driver::BuildJobsForActionNoCache(
60266030
const JobAction *JA = cast<JobAction>(A);
60276031
ActionList CollapsedOffloadActions;
60286032

6029-
const ToolChain *TCForTS = TC;
6030-
if (auto *DA = dyn_cast<OffloadDepsJobAction>(A))
6031-
TCForTS = DA->getHostTC();
6033+
auto *DA = dyn_cast<OffloadDepsJobAction>(JA);
6034+
const ToolChain *JATC = DA ? DA->getHostTC() : TC;
60326035

6033-
ToolSelector TS(JA, *TCForTS, C, isSaveTempsEnabled(),
6036+
ToolSelector TS(JA, *JATC, C, isSaveTempsEnabled(),
60346037
embedBitcodeInObject() && !isUsingLTO());
60356038
const Tool *T = TS.getTool(Inputs, CollapsedOffloadActions);
60366039

@@ -6058,15 +6061,10 @@ InputInfo Driver::BuildJobsForActionNoCache(
60586061
// FIXME: Clean this up.
60596062
bool SubJobAtTopLevel =
60606063
AtTopLevel && (isa<DsymutilJobAction>(A) || isa<VerifyJobAction>(A));
6061-
if (auto *DA = dyn_cast<OffloadDepsJobAction>(A))
6062-
InputInfos.push_back(
6063-
BuildJobsForAction(C, Input, DA->getHostTC(), DA->getOffloadingArch(),
6064-
SubJobAtTopLevel, MultipleArchs, LinkingOutput,
6065-
CachedResults, DA->getOffloadingDeviceKind()));
6066-
else
6067-
InputInfos.push_back(BuildJobsForAction(
6068-
C, Input, TC, BoundArch, SubJobAtTopLevel, MultipleArchs,
6069-
LinkingOutput, CachedResults, A->getOffloadingDeviceKind()));
6064+
InputInfos.push_back(BuildJobsForAction(
6065+
C, Input, JATC, DA ? DA->getOffloadingArch() : BoundArch,
6066+
SubJobAtTopLevel, MultipleArchs, LinkingOutput, CachedResults,
6067+
A->getOffloadingDeviceKind()));
60706068
}
60716069
// Check if we are in sub-work for preprocessing for host side. If so we will
60726070
// add another job to print information to terminal later.
@@ -6257,14 +6255,11 @@ InputInfo Driver::BuildJobsForActionNoCache(
62576255

62586256
// Get the unique string identifier for this dependence and cache the
62596257
// result.
6260-
StringRef Arch;
6261-
if (TargetDeviceOffloadKind == Action::OFK_HIP) {
6262-
if (DI.DependentOffloadKind == Action::OFK_Host)
6263-
Arch = StringRef();
6264-
else
6265-
Arch = DI.DependentBoundArch;
6266-
} else
6267-
Arch = BoundArch;
6258+
StringRef Arch = TargetDeviceOffloadKind == Action::OFK_HIP
6259+
? DI.DependentOffloadKind == Action::OFK_Host
6260+
? StringRef()
6261+
: DI.DependentBoundArch
6262+
: BoundArch;
62686263

62696264
CachedResults[{A, GetTriplePlusArchString(DI.DependentToolChain, Arch,
62706265
DI.DependentOffloadKind)}] =

0 commit comments

Comments
 (0)