Skip to content

[SYCL] Add splitting module capabilities when compiling for NVPTX and AMDGCN #4107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions clang/include/clang/Driver/Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Action {
InputClass = 0,
BindArchClass,
OffloadClass,
ForEachWrappingClass,
PreprocessJobClass,
PrecompileJobClass,
HeaderModulePrecompileJobClass,
Expand Down Expand Up @@ -737,7 +738,15 @@ class SYCLPostLinkJobAction : public JobAction {
void anchor() override;

public:
SYCLPostLinkJobAction(Action *Input, types::ID OutputType);
// The tempfiletable management relies on a shadowing the main file type by
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// The tempfiletable management relies on a shadowing the main file type by
// The tempfiletable management relies on shadowing the main file type by

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure that using article in this case is incorrect.

// types::TY_Tempfiletable. The problem of shadowing is it prevents its
// integration with clang tools that relies on the file type to properly set
// args.
// We "trick" the driver by declaring the underlying file type and set a
// "true output type" which will be used by the SYCLPostLinkJobAction
// to properly set the job.
SYCLPostLinkJobAction(Action *Input, types::ID ShadowOutputType,
types::ID TrueOutputType);

static bool classof(const Action *A) {
return A->getKind() == SYCLPostLinkJobClass;
Expand All @@ -747,8 +756,11 @@ class SYCLPostLinkJobAction : public JobAction {

bool getRTSetsSpecConstants() const { return RTSetsSpecConsts; }

types::ID getTrueType() const { return TrueOutputType; }

private:
bool RTSetsSpecConsts = true;
types::ID TrueOutputType;
};

class BackendCompileJobAction : public JobAction {
Expand All @@ -771,6 +783,9 @@ class FileTableTformJobAction : public JobAction {
void anchor() override;

public:
static constexpr const char *COL_CODE = "Code";
static constexpr const char *COL_ZERO = "0";

struct Tform {
enum Kind {
EXTRACT,
Expand All @@ -791,8 +806,10 @@ class FileTableTformJobAction : public JobAction {
SmallVector<std::string, 2> TheArgs;
};

FileTableTformJobAction(Action *Input, types::ID OutputType);
FileTableTformJobAction(ActionList &Inputs, types::ID OutputType);
FileTableTformJobAction(Action *Input, types::ID ShadowOutputType,
types::ID TrueOutputType);
FileTableTformJobAction(ActionList &Inputs, types::ID ShadowOutputType,
types::ID TrueOutputType);

// Deletes all columns except the one with given name.
void addExtractColumnTform(StringRef ColumnName, bool WithColTitle = true);
Expand Down Expand Up @@ -820,7 +837,10 @@ class FileTableTformJobAction : public JobAction {

const ArrayRef<Tform> getTforms() const { return Tforms; }

types::ID getTrueType() const { return TrueOutputType; }

private:
types::ID TrueOutputType;
SmallVector<Tform, 2> Tforms; // transformation actions requested

// column to copy single file from if requested
Expand Down Expand Up @@ -849,6 +869,30 @@ class StaticLibJobAction : public JobAction {
}
};

/// Wrap all jobs performed between TFormInput (excluded) and Job (included)
/// behind a `llvm-foreach` call.
///
/// Assumptions:
/// - No change of toolchain, boundarch and offloading kind should occur
/// within the sub-region;
/// - No job should produce multiple outputs;
/// - Results of action within the sub-region should not be used outside the
/// wrapped region.
/// Note: this doesn't bind to a tool directly and this need special casing
/// anyhow. Hence why this is an Action and not a JobAction, even if there is a
/// command behind.
class ForEachWrappingAction : public Action {
public:
ForEachWrappingAction(JobAction *TFormInput, JobAction *Job);

JobAction *getTFormInput() const;
JobAction *getJobAction() const;

static bool classof(const Action *A) {
return A->getKind() == ForEachWrappingClass;
}
};

} // namespace driver
} // namespace clang

Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Driver/Job.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ class JobList {
/// Clear the job list.
void clear();

/// Return a mutable list of Jobs for llvm-foreach wrapping.
list_type &getJobsForOverride() { return Jobs; }
const list_type &getJobs() const { return Jobs; }

bool empty() const { return Jobs.empty(); }
Expand Down
34 changes: 28 additions & 6 deletions clang/lib/Driver/Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const char *Action::getClassName(ActionClass AC) {
return "append-footer";
case StaticLibJobClass:
return "static-lib-linker";
case ForEachWrappingClass:
return "foreach";
}

llvm_unreachable("invalid class");
Expand Down Expand Up @@ -474,8 +476,11 @@ SPIRCheckJobAction::SPIRCheckJobAction(Action *Input, types::ID Type)

void SYCLPostLinkJobAction::anchor() {}

SYCLPostLinkJobAction::SYCLPostLinkJobAction(Action *Input, types::ID Type)
: JobAction(SYCLPostLinkJobClass, Input, Type) {}
SYCLPostLinkJobAction::SYCLPostLinkJobAction(Action *Input,
types::ID ShadowOutputType,
types::ID TrueOutputType)
: JobAction(SYCLPostLinkJobClass, Input, ShadowOutputType),
TrueOutputType(TrueOutputType) {}

void BackendCompileJobAction::anchor() {}

Expand All @@ -489,12 +494,17 @@ BackendCompileJobAction::BackendCompileJobAction(Action *Input,

void FileTableTformJobAction::anchor() {}

FileTableTformJobAction::FileTableTformJobAction(Action *Input, types::ID Type)
: JobAction(FileTableTformJobClass, Input, Type) {}
FileTableTformJobAction::FileTableTformJobAction(Action *Input,
types::ID ShadowOutputType,
types::ID TrueOutputType)
: JobAction(FileTableTformJobClass, Input, ShadowOutputType),
TrueOutputType(TrueOutputType) {}

FileTableTformJobAction::FileTableTformJobAction(ActionList &Inputs,
types::ID Type)
: JobAction(FileTableTformJobClass, Inputs, Type) {}
types::ID ShadowOutputType,
types::ID TrueOutputType)
: JobAction(FileTableTformJobClass, Inputs, ShadowOutputType),
TrueOutputType(TrueOutputType) {}

void FileTableTformJobAction::addExtractColumnTform(StringRef ColumnName,
bool WithColTitle) {
Expand Down Expand Up @@ -533,3 +543,15 @@ void StaticLibJobAction::anchor() {}

StaticLibJobAction::StaticLibJobAction(ActionList &Inputs, types::ID Type)
: JobAction(StaticLibJobClass, Inputs, Type) {}

ForEachWrappingAction::ForEachWrappingAction(JobAction *TFormInput,
JobAction *Job)
: Action(ForEachWrappingClass, {TFormInput, Job}, Job->getType()) {}

JobAction *ForEachWrappingAction::getTFormInput() const {
return llvm::cast<JobAction>(getInputs()[0]);
}

JobAction *ForEachWrappingAction::getJobAction() const {
return llvm::cast<JobAction>(getInputs()[1]);
}
Loading