Skip to content

Conversation

@zahiraam
Copy link
Contributor

@zahiraam zahiraam commented Oct 8, 2024

This is needed to support compilation with ccache.
When compiling with ccache, the integration header and footer shouldn't be printed in the pre-processed output to not confuse ccache. In order to do that we added a new option called include-internal-footer to include the integration footer. For consistency the include option, that was including the integration header was renamed -include-internal-header.

@zahiraam zahiraam changed the title Save temps [SYCL] Don't print the header and footer in the preprocessed output. Oct 11, 2024
@zahiraam zahiraam marked this pull request as ready for review October 14, 2024 08:08
@zahiraam zahiraam requested review from a team as code owners October 14, 2024 08:08
@@ -0,0 +1,86 @@
/// Check compilation tool steps when using the integration footer
Copy link
Contributor

Choose a reason for hiding this comment

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

Test name is sycl-int-header.cpp but comments in the test are checking for the footer, but the tests themselves are checking for both. Can this ben cleaned up?

}

// Add the -include-footer option to add the integration footer
// Add the -include-internal-footer option to add the integration footer
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Add the comment inside the 'if' construct so that it reads similar to the
'header' option?

///
/// @param path Input path.
/// @result The cleaned-up \a path.
StringRef remove_leading_dotbackslah(StringRef path);
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
StringRef remove_leading_dotbackslah(StringRef path);
StringRef remove_leading_dotbackslash(StringRef path);

return Path;
}

StringRef remove_leading_dotbackslah(StringRef Path) {
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
StringRef remove_leading_dotbackslah(StringRef Path) {
StringRef remove_leading_dotbackslash(StringRef Path) {

OS->write_escaped(CurFilename);
*OS << '"';
StringRef CurFilenameWithNoLeaningDotSlash =
llvm::sys::path::remove_leading_dotbackslah(CurFilename.str());
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
llvm::sys::path::remove_leading_dotbackslah(CurFilename.str());
llvm::sys::path::remove_leading_dotbackslash(CurFilename.str());

unsigned ExtraLen) {
startNewLineIfNeeded();

// Emit #line directives or GNU line markers depending on what mode we're in.
Copy link
Contributor

Choose a reason for hiding this comment

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

May be comment should be moved a bit down?

MetaVarName<"<file>">, HelpText<"Include file before parsing">,
Visibility<[ClangOption, CC1Option]>;
def include_footer : Separate<["-"], "include-footer">, Group<clang_i_Group>,
def include_internal_footer : Separate<["-"], "include-internal-footer">, Group<clang_i_Group>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a possibility where we want to include header and not footer...or the other way around? Just wondering if we need two options here.

Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. @premanandrao What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

The behavior of -include-internal-header and -include-internal-footer is more than just the ability to pass in a file to be included, it also designates where in the preprocessing the file is expanded, so we need to have 2 options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks Mike!

if (types::getPreprocessedType(Input.getType()) != types::TY_INVALID &&
!Args.hasArg(options::OPT_fno_sycl_use_footer) && !Footer.empty()) {
CmdArgs.push_back("-include-footer");
// Add the -include-internal-footer option to add the integration foote
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
// Add the -include-internal-footer option to add the integration foote
// Add the -include-internal-footer option to add the integration footer

AddImplicitInclude(Builder, Path);
}

// Process -include-internal-header directive.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this comment accurate? Is the 'processing' happening inside the function call?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. A #include header.h is added to the stream.

Comment on lines 269 to 271
if (value == '\\')
return true;
return false;
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
if (value == '\\')
return true;
return false;
return value == '\\';

Copy link
Contributor

@asudarsa asudarsa left a comment

Choose a reason for hiding this comment

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

Minor nits. Overall looks good. Thanks

Copy link
Contributor

@asudarsa asudarsa left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks

@zahiraam
Copy link
Contributor Author

@intel/dpcpp-cfe-reviewers can you please review this? Thanks.

Copy link
Contributor

@elizabethandrews elizabethandrews left a comment

Choose a reason for hiding this comment

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

@premanandrao can you please take a look at this? I believe you reviewed previous versions of this functionality.

Comment on lines 275 to 279
StringRef CurFilenameWithNoLeaningDotSlash =
llvm::sys::path::remove_leading_dotbackslash(CurFilename.str());
if ((CurFilenameWithNoLeaningDotSlash ==
PP.getPreprocessorOpts().IncludeFooter) ||
CurFilenameWithNoLeaningDotSlash ==
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
StringRef CurFilenameWithNoLeaningDotSlash =
llvm::sys::path::remove_leading_dotbackslash(CurFilename.str());
if ((CurFilenameWithNoLeaningDotSlash ==
PP.getPreprocessorOpts().IncludeFooter) ||
CurFilenameWithNoLeaningDotSlash ==
StringRef CurFilenameWithNoLeadingDotSlash =
llvm::sys::path::remove_leading_dotbackslash(CurFilename.str());
if ((CurFilenameWithNoLeadingDotSlash ==
PP.getPreprocessorOpts().IncludeFooter) ||
CurFilenameWithNoLeadingDotSlash ==

PP.getPreprocessorOpts().IncludeHeader) {
CurFilename = "<uninit>";
}
// Emit #line directives or GNU line markers depending on what mode we're in.
Copy link
Contributor

Choose a reason for hiding this comment

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

The indentation starting this line seems off to me. Please check.

int bar() { return 21; }

// CHECK: # 21 ""
// CHECK: # 1 "[[INPUT:.+\.c]]" 2
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this line for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for the empty line. Fixed that.

Path = Path.substr(2);
return Path;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of a new routine, can remove_leading_dotslash be reused with the appropriate Style?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not the Style argument that's the issue, it's the call to is_separator that would make the change more complicated than it should be. Furthermore, we only need to check if we have the .\\ at the beginning of the string, no need to visit the entire string which is what remove_leading_dotslash is doing.
But I can make the change if you don't want to see this additional function.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. You specifically don't want the loop? In that case, I am fine with your new function - except maybe give it a distinct name, so the leading vs all distinction is clear.

How about something like: remove_leading_dotbackslash_only? Just a suggestion. Please pick a spelling that sounds good to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I can name it that way. Thanks.

Copy link
Contributor

@premanandrao premanandrao left a comment

Choose a reason for hiding this comment

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

Just one minor nit. Other than that, looks good.

startNewLineIfNeeded();

if (PP.getLangOpts().isSYCL()) {
StringRef CurFilenameWithNoLeadingDotSlash =
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation.

@zahiraam
Copy link
Contributor Author

@intel/llvm-gatekeepers Can this be merged in please? Thanks.

@martygrant martygrant merged commit 4c47642 into intel:sycl Oct 23, 2024
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants