Skip to content

Commit 4716696

Browse files
committed
[OpenMP] Deprecate the old driver for OpenMP offloading
Recently OpenMP has transitioned to using the "new" driver which primarily merges the device and host linking phases into a single wrapper that handles both at the same time. This replaced a few tools that were only used for OpenMP offloading, such as the `clang-offload-wrapper` and `clang-nvlink-wrapper`. The new driver carries some marked benefits compared to the old driver that is now being deprecated. Things like device-side LTO, static library support, and more compatible tooling. As such, we should be able to completely deprecate the old driver, at least for OpenMP. The old driver support will still exist for CUDA and HIP, although both of these can currently be compiled on Linux with `--offload-new-driver` to use the new method. Note that this does not deprecate the `clang-offload-bundler`, although it is unused by OpenMP now, it is still used by the HIP toolchain both as their device binary format and object format. When I proposed deprecating this code I heard some vendors voice concernes about needing to update their code in their fork. They should be able to just revert this commit if it lands. Reviewed By: jdoerfert, MaskRay, ye-luo Differential Revision: https://reviews.llvm.org/D130020
1 parent eabface commit 4716696

Some content is hidden

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

43 files changed

+243
-2713
lines changed

clang/include/clang/Driver/Action.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ class Action {
7373
VerifyPCHJobClass,
7474
OffloadBundlingJobClass,
7575
OffloadUnbundlingJobClass,
76-
OffloadWrapperJobClass,
7776
OffloadPackagerJobClass,
7877
LinkerWrapperJobClass,
7978
StaticLibJobClass,
@@ -659,17 +658,6 @@ class OffloadUnbundlingJobAction final : public JobAction {
659658
}
660659
};
661660

662-
class OffloadWrapperJobAction : public JobAction {
663-
void anchor() override;
664-
665-
public:
666-
OffloadWrapperJobAction(ActionList &Inputs, types::ID Type);
667-
668-
static bool classof(const Action *A) {
669-
return A->getKind() == OffloadWrapperJobClass;
670-
}
671-
};
672-
673661
class OffloadPackagerJobAction : public JobAction {
674662
void anchor() override;
675663

clang/include/clang/Driver/ToolChain.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ class ToolChain {
150150
mutable std::unique_ptr<Tool> StaticLibTool;
151151
mutable std::unique_ptr<Tool> IfsMerge;
152152
mutable std::unique_ptr<Tool> OffloadBundler;
153-
mutable std::unique_ptr<Tool> OffloadWrapper;
154153
mutable std::unique_ptr<Tool> OffloadPackager;
155154
mutable std::unique_ptr<Tool> LinkerWrapper;
156155

@@ -162,7 +161,6 @@ class ToolChain {
162161
Tool *getIfsMerge() const;
163162
Tool *getClangAs() const;
164163
Tool *getOffloadBundler() const;
165-
Tool *getOffloadWrapper() const;
166164
Tool *getOffloadPackager() const;
167165
Tool *getLinkerWrapper() const;
168166

clang/lib/Driver/Action.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ const char *Action::getClassName(ActionClass AC) {
4343
return "clang-offload-bundler";
4444
case OffloadUnbundlingJobClass:
4545
return "clang-offload-unbundler";
46-
case OffloadWrapperJobClass:
47-
return "clang-offload-wrapper";
4846
case OffloadPackagerJobClass:
4947
return "clang-offload-packager";
5048
case LinkerWrapperJobClass:
@@ -428,12 +426,6 @@ void OffloadUnbundlingJobAction::anchor() {}
428426
OffloadUnbundlingJobAction::OffloadUnbundlingJobAction(Action *Input)
429427
: JobAction(OffloadUnbundlingJobClass, Input, Input->getType()) {}
430428

431-
void OffloadWrapperJobAction::anchor() {}
432-
433-
OffloadWrapperJobAction::OffloadWrapperJobAction(ActionList &Inputs,
434-
types::ID Type)
435-
: JobAction(OffloadWrapperJobClass, Inputs, Type) {}
436-
437429
void OffloadPackagerJobAction::anchor() {}
438430

439431
OffloadPackagerJobAction::OffloadPackagerJobAction(ActionList &Inputs,

clang/lib/Driver/Driver.cpp

Lines changed: 0 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,178 +3441,6 @@ class OffloadingActionBuilder final {
34413441
void appendLinkDependences(OffloadAction::DeviceDependences &DA) override {}
34423442
};
34433443

3444-
/// OpenMP action builder. The host bitcode is passed to the device frontend
3445-
/// and all the device linked images are passed to the host link phase.
3446-
class OpenMPActionBuilder final : public DeviceActionBuilder {
3447-
/// The OpenMP actions for the current input.
3448-
ActionList OpenMPDeviceActions;
3449-
3450-
/// The linker inputs obtained for each toolchain.
3451-
SmallVector<ActionList, 8> DeviceLinkerInputs;
3452-
3453-
public:
3454-
OpenMPActionBuilder(Compilation &C, DerivedArgList &Args,
3455-
const Driver::InputList &Inputs)
3456-
: DeviceActionBuilder(C, Args, Inputs, Action::OFK_OpenMP) {}
3457-
3458-
ActionBuilderReturnCode
3459-
getDeviceDependences(OffloadAction::DeviceDependences &DA,
3460-
phases::ID CurPhase, phases::ID FinalPhase,
3461-
PhasesTy &Phases) override {
3462-
if (OpenMPDeviceActions.empty())
3463-
return ABRT_Inactive;
3464-
3465-
// We should always have an action for each input.
3466-
assert(OpenMPDeviceActions.size() == ToolChains.size() &&
3467-
"Number of OpenMP actions and toolchains do not match.");
3468-
3469-
// The host only depends on device action in the linking phase, when all
3470-
// the device images have to be embedded in the host image.
3471-
if (CurPhase == phases::Link) {
3472-
assert(ToolChains.size() == DeviceLinkerInputs.size() &&
3473-
"Toolchains and linker inputs sizes do not match.");
3474-
auto LI = DeviceLinkerInputs.begin();
3475-
for (auto *A : OpenMPDeviceActions) {
3476-
LI->push_back(A);
3477-
++LI;
3478-
}
3479-
3480-
// We passed the device action as a host dependence, so we don't need to
3481-
// do anything else with them.
3482-
OpenMPDeviceActions.clear();
3483-
return ABRT_Success;
3484-
}
3485-
3486-
// By default, we produce an action for each device arch.
3487-
for (Action *&A : OpenMPDeviceActions)
3488-
A = C.getDriver().ConstructPhaseAction(C, Args, CurPhase, A);
3489-
3490-
return ABRT_Success;
3491-
}
3492-
3493-
ActionBuilderReturnCode addDeviceDepences(Action *HostAction) override {
3494-
3495-
// If this is an input action replicate it for each OpenMP toolchain.
3496-
if (auto *IA = dyn_cast<InputAction>(HostAction)) {
3497-
OpenMPDeviceActions.clear();
3498-
for (unsigned I = 0; I < ToolChains.size(); ++I)
3499-
OpenMPDeviceActions.push_back(
3500-
C.MakeAction<InputAction>(IA->getInputArg(), IA->getType()));
3501-
return ABRT_Success;
3502-
}
3503-
3504-
// If this is an unbundling action use it as is for each OpenMP toolchain.
3505-
if (auto *UA = dyn_cast<OffloadUnbundlingJobAction>(HostAction)) {
3506-
OpenMPDeviceActions.clear();
3507-
auto *IA = cast<InputAction>(UA->getInputs().back());
3508-
std::string FileName = IA->getInputArg().getAsString(Args);
3509-
// Check if the type of the file is the same as the action. Do not
3510-
// unbundle it if it is not. Do not unbundle .so files, for example,
3511-
// which are not object files.
3512-
if (IA->getType() == types::TY_Object &&
3513-
(!llvm::sys::path::has_extension(FileName) ||
3514-
types::lookupTypeForExtension(
3515-
llvm::sys::path::extension(FileName).drop_front()) !=
3516-
types::TY_Object))
3517-
return ABRT_Inactive;
3518-
for (unsigned I = 0; I < ToolChains.size(); ++I) {
3519-
OpenMPDeviceActions.push_back(UA);
3520-
UA->registerDependentActionInfo(
3521-
ToolChains[I], /*BoundArch=*/StringRef(), Action::OFK_OpenMP);
3522-
}
3523-
return ABRT_Success;
3524-
}
3525-
3526-
// When generating code for OpenMP we use the host compile phase result as
3527-
// a dependence to the device compile phase so that it can learn what
3528-
// declarations should be emitted. However, this is not the only use for
3529-
// the host action, so we prevent it from being collapsed.
3530-
if (isa<CompileJobAction>(HostAction)) {
3531-
HostAction->setCannotBeCollapsedWithNextDependentAction();
3532-
assert(ToolChains.size() == OpenMPDeviceActions.size() &&
3533-
"Toolchains and device action sizes do not match.");
3534-
OffloadAction::HostDependence HDep(
3535-
*HostAction, *C.getSingleOffloadToolChain<Action::OFK_Host>(),
3536-
/*BoundArch=*/nullptr, Action::OFK_OpenMP);
3537-
auto TC = ToolChains.begin();
3538-
for (Action *&A : OpenMPDeviceActions) {
3539-
assert(isa<CompileJobAction>(A));
3540-
OffloadAction::DeviceDependences DDep;
3541-
DDep.add(*A, **TC, /*BoundArch=*/nullptr, Action::OFK_OpenMP);
3542-
A = C.MakeAction<OffloadAction>(HDep, DDep);
3543-
++TC;
3544-
}
3545-
}
3546-
return ABRT_Success;
3547-
}
3548-
3549-
void appendTopLevelActions(ActionList &AL) override {
3550-
if (OpenMPDeviceActions.empty())
3551-
return;
3552-
3553-
// We should always have an action for each input.
3554-
assert(OpenMPDeviceActions.size() == ToolChains.size() &&
3555-
"Number of OpenMP actions and toolchains do not match.");
3556-
3557-
// Append all device actions followed by the proper offload action.
3558-
auto TI = ToolChains.begin();
3559-
for (auto *A : OpenMPDeviceActions) {
3560-
OffloadAction::DeviceDependences Dep;
3561-
Dep.add(*A, **TI, /*BoundArch=*/nullptr, Action::OFK_OpenMP);
3562-
AL.push_back(C.MakeAction<OffloadAction>(Dep, A->getType()));
3563-
++TI;
3564-
}
3565-
// We no longer need the action stored in this builder.
3566-
OpenMPDeviceActions.clear();
3567-
}
3568-
3569-
void appendLinkDeviceActions(ActionList &AL) override {
3570-
assert(ToolChains.size() == DeviceLinkerInputs.size() &&
3571-
"Toolchains and linker inputs sizes do not match.");
3572-
3573-
// Append a new link action for each device.
3574-
auto TC = ToolChains.begin();
3575-
for (auto &LI : DeviceLinkerInputs) {
3576-
auto *DeviceLinkAction =
3577-
C.MakeAction<LinkJobAction>(LI, types::TY_Image);
3578-
OffloadAction::DeviceDependences DeviceLinkDeps;
3579-
DeviceLinkDeps.add(*DeviceLinkAction, **TC, /*BoundArch=*/nullptr,
3580-
Action::OFK_OpenMP);
3581-
AL.push_back(C.MakeAction<OffloadAction>(DeviceLinkDeps,
3582-
DeviceLinkAction->getType()));
3583-
++TC;
3584-
}
3585-
DeviceLinkerInputs.clear();
3586-
}
3587-
3588-
Action* appendLinkHostActions(ActionList &AL) override {
3589-
// Create wrapper bitcode from the result of device link actions and compile
3590-
// it to an object which will be added to the host link command.
3591-
auto *BC = C.MakeAction<OffloadWrapperJobAction>(AL, types::TY_LLVM_BC);
3592-
auto *ASM = C.MakeAction<BackendJobAction>(BC, types::TY_PP_Asm);
3593-
return C.MakeAction<AssembleJobAction>(ASM, types::TY_Object);
3594-
}
3595-
3596-
void appendLinkDependences(OffloadAction::DeviceDependences &DA) override {}
3597-
3598-
bool initialize() override {
3599-
// Get the OpenMP toolchains. If we don't get any, the action builder will
3600-
// know there is nothing to do related to OpenMP offloading.
3601-
auto OpenMPTCRange = C.getOffloadToolChains<Action::OFK_OpenMP>();
3602-
for (auto TI = OpenMPTCRange.first, TE = OpenMPTCRange.second; TI != TE;
3603-
++TI)
3604-
ToolChains.push_back(TI->second);
3605-
3606-
DeviceLinkerInputs.resize(ToolChains.size());
3607-
return false;
3608-
}
3609-
3610-
bool canUseBundlerUnbundler() const override {
3611-
// OpenMP should use bundled files whenever possible.
3612-
return true;
3613-
}
3614-
};
3615-
36163444
///
36173445
/// TODO: Add the implementation for other specialized builders here.
36183446
///
@@ -3637,9 +3465,6 @@ class OffloadingActionBuilder final {
36373465
// Create a specialized builder for HIP.
36383466
SpecializedBuilders.push_back(new HIPActionBuilder(C, Args, Inputs));
36393467

3640-
// Create a specialized builder for OpenMP.
3641-
SpecializedBuilders.push_back(new OpenMPActionBuilder(C, Args, Inputs));
3642-
36433468
//
36443469
// TODO: Build other specialized builders here.
36453470
//
@@ -5505,14 +5330,6 @@ InputInfoList Driver::BuildJobsForActionNoCache(
55055330
/*CreatePrefixForHost=*/isa<OffloadPackagerJobAction>(A) ||
55065331
!(A->getOffloadingHostActiveKinds() == Action::OFK_None ||
55075332
AtTopLevel));
5508-
if (isa<OffloadWrapperJobAction>(JA)) {
5509-
if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o))
5510-
BaseInput = FinalOutput->getValue();
5511-
else
5512-
BaseInput = getDefaultImageName();
5513-
BaseInput =
5514-
C.getArgs().MakeArgString(std::string(BaseInput) + "-wrapper");
5515-
}
55165333
Result = InputInfo(A, GetNamedOutputPath(C, *JA, BaseInput, BoundArch,
55175334
AtTopLevel, MultipleArchs,
55185335
OffloadingPrefix),

clang/lib/Driver/ToolChain.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,6 @@ Tool *ToolChain::getOffloadBundler() const {
351351
return OffloadBundler.get();
352352
}
353353

354-
Tool *ToolChain::getOffloadWrapper() const {
355-
if (!OffloadWrapper)
356-
OffloadWrapper.reset(new tools::OffloadWrapper(*this));
357-
return OffloadWrapper.get();
358-
}
359-
360354
Tool *ToolChain::getOffloadPackager() const {
361355
if (!OffloadPackager)
362356
OffloadPackager.reset(new tools::OffloadPackager(*this));
@@ -406,8 +400,6 @@ Tool *ToolChain::getTool(Action::ActionClass AC) const {
406400
case Action::OffloadUnbundlingJobClass:
407401
return getOffloadBundler();
408402

409-
case Action::OffloadWrapperJobClass:
410-
return getOffloadWrapper();
411403
case Action::OffloadPackagerJobClass:
412404
return getOffloadPackager();
413405
case Action::LinkerWrapperJobClass:

0 commit comments

Comments
 (0)