@@ -2465,6 +2465,9 @@ class OffloadingActionBuilder final {
2465
2465
// / Map between an input argument and the offload kinds used to process it.
2466
2466
std::map<const Arg *, unsigned > InputArgToOffloadKindMap;
2467
2467
2468
+ // / Map between a host action and its originating input argument.
2469
+ std::map<Action *, const Arg *> HostActionToInputArgMap;
2470
+
2468
2471
// / Builder interface. It doesn't build anything or keep any state.
2469
2472
class DeviceActionBuilder {
2470
2473
public:
@@ -3449,6 +3452,17 @@ class OffloadingActionBuilder final {
3449
3452
delete SB;
3450
3453
}
3451
3454
3455
+ // / Record a host action and its originating input argument.
3456
+ void recordHostAction (Action *HostAction, const Arg *InputArg) {
3457
+ assert (HostAction && " Invalid host action" );
3458
+ assert (InputArg && " Invalid input argument" );
3459
+ auto Loc = HostActionToInputArgMap.find (HostAction);
3460
+ if (Loc == HostActionToInputArgMap.end ())
3461
+ HostActionToInputArgMap[HostAction] = InputArg;
3462
+ assert (HostActionToInputArgMap[HostAction] == InputArg &&
3463
+ " host action mapped to multiple input arguments" );
3464
+ }
3465
+
3452
3466
// / Generate an action that adds device dependences (if any) to a host action.
3453
3467
// / If no device dependence actions exist, just return the host action \a
3454
3468
// / HostAction. If an error is found or if no builder requires the host action
@@ -3464,6 +3478,7 @@ class OffloadingActionBuilder final {
3464
3478
return HostAction;
3465
3479
3466
3480
assert (HostAction && " Invalid host action!" );
3481
+ recordHostAction (HostAction, InputArg);
3467
3482
3468
3483
OffloadAction::DeviceDependences DDeps;
3469
3484
// Check if all the programming models agree we should not emit the host
@@ -3517,6 +3532,8 @@ class OffloadingActionBuilder final {
3517
3532
if (!IsValid)
3518
3533
return true ;
3519
3534
3535
+ recordHostAction (HostAction, InputArg);
3536
+
3520
3537
// If we are supporting bundling/unbundling and the current action is an
3521
3538
// input action of non-source file, we replace the host action by the
3522
3539
// unbundling action. The bundler tool has the logic to detect if an input
@@ -3533,6 +3550,7 @@ class OffloadingActionBuilder final {
3533
3550
C.getSingleOffloadToolChain <Action::OFK_Host>(),
3534
3551
/* BoundArch=*/ StringRef (), Action::OFK_Host);
3535
3552
HostAction = UnbundlingHostAction;
3553
+ recordHostAction (HostAction, InputArg);
3536
3554
}
3537
3555
3538
3556
assert (HostAction && " Invalid host action!" );
@@ -3569,6 +3587,9 @@ class OffloadingActionBuilder final {
3569
3587
// / programming models allow it.
3570
3588
bool appendTopLevelActions (ActionList &AL, Action *HostAction,
3571
3589
const Arg *InputArg) {
3590
+ if (HostAction)
3591
+ recordHostAction (HostAction, InputArg);
3592
+
3572
3593
// Get the device actions to be appended.
3573
3594
ActionList OffloadAL;
3574
3595
for (auto *SB : SpecializedBuilders) {
@@ -3590,6 +3611,7 @@ class OffloadingActionBuilder final {
3590
3611
// before this method was called.
3591
3612
assert (HostAction == AL.back () && " Host action not in the list??" );
3592
3613
HostAction = C.MakeAction <OffloadBundlingJobAction>(OffloadAL);
3614
+ recordHostAction (HostAction, InputArg);
3593
3615
AL.back () = HostAction;
3594
3616
} else
3595
3617
AL.append (OffloadAL.begin (), OffloadAL.end ());
@@ -3623,6 +3645,11 @@ class OffloadingActionBuilder final {
3623
3645
if (!SB->isValid ())
3624
3646
continue ;
3625
3647
HA = SB->appendLinkHostActions (DeviceAL);
3648
+ // This created host action has no originating input argument, therefore
3649
+ // needs to set its offloading kind directly.
3650
+ if (HA)
3651
+ HA->propagateHostOffloadInfo (SB->getAssociatedOffloadKind (),
3652
+ /* BoundArch=*/ nullptr );
3626
3653
}
3627
3654
return HA;
3628
3655
}
@@ -3649,10 +3676,22 @@ class OffloadingActionBuilder final {
3649
3676
// If we don't have device dependencies, we don't have to create an offload
3650
3677
// action.
3651
3678
if (DDeps.getActions ().empty ()) {
3652
- // Propagate all the active kinds to host action. Given that it is a link
3653
- // action it is assumed to depend on all actions generated so far.
3654
- HostAction->propagateHostOffloadInfo (ActiveOffloadKinds,
3655
- /* BoundArch=*/ nullptr );
3679
+ // Set all the active offloading kinds to the link action. Given that it
3680
+ // is a link action it is assumed to depend on all actions generated so
3681
+ // far.
3682
+ HostAction->setHostOffloadInfo (ActiveOffloadKinds,
3683
+ /* BoundArch=*/ nullptr );
3684
+ // Propagate active offloading kinds for each input to the link action.
3685
+ // Each input may have different active offloading kind.
3686
+ for (auto A : HostAction->inputs ()) {
3687
+ auto ArgLoc = HostActionToInputArgMap.find (A);
3688
+ if (ArgLoc == HostActionToInputArgMap.end ())
3689
+ continue ;
3690
+ auto OFKLoc = InputArgToOffloadKindMap.find (ArgLoc->second );
3691
+ if (OFKLoc == InputArgToOffloadKindMap.end ())
3692
+ continue ;
3693
+ A->propagateHostOffloadInfo (OFKLoc->second , /* BoundArch=*/ nullptr );
3694
+ }
3656
3695
return HostAction;
3657
3696
}
3658
3697
0 commit comments