-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang][X86] Support __attribute__((model("small"/"large"))) #124834
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
Changes from 1 commit
7c40169
8aa6b3f
2fdf2ee
1a32c31
7ce06bd
526e8c3
6779705
2263db1
bf8f7d4
d314c8e
1729029
c664880
f3ecb7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2950,12 +2950,11 @@ static void handleSectionAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |
| } | ||
| } | ||
|
|
||
| static bool isValidCodeModelAttr(Sema &S, StringRef Str) { | ||
| if (S.Context.getTargetInfo().getTriple().isLoongArch()) { | ||
| static bool isValidCodeModelAttr(llvm::Triple Triple, StringRef Str) { | ||
| if (Triple.isLoongArch()) { | ||
| return Str == "normal" || Str == "medium" || Str == "extreme"; | ||
| } else { | ||
| assert(S.Context.getTargetInfo().getTriple().getArch() == | ||
| llvm::Triple::x86_64 && | ||
| assert(Triple.getArch() == llvm::Triple::x86_64 && | ||
| "only loongarch/x86-64 supported"); | ||
| return Str == "small" || Str == "large"; | ||
| } | ||
|
|
@@ -2964,20 +2963,36 @@ static bool isValidCodeModelAttr(Sema &S, StringRef Str) { | |
| static void handleCodeModelAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | ||
| StringRef Str; | ||
| SourceLocation LiteralLoc; | ||
| auto IsTripleSupported = [](const llvm::Triple Triple) { | ||
| return Triple.getArch() == llvm::Triple::ArchType::x86_64 || | ||
| Triple.isLoongArch(); | ||
| }; | ||
|
|
||
| // Check that it is a string. | ||
| if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc)) | ||
| return; | ||
|
|
||
| // Ignore the attribute for GPU device compiles since it only applies to host | ||
| // globals. | ||
| if (S.Context.getTargetInfo().getTriple().isNVPTX() || | ||
| S.Context.getTargetInfo().getTriple().isAMDGPU() || | ||
| S.Context.getTargetInfo().getTriple().isSPIRV()) | ||
| SmallVector<llvm::Triple, 2> Triples = { | ||
| S.Context.getTargetInfo().getTriple()}; | ||
| if (auto *aux = S.Context.getAuxTargetInfo()) { | ||
| Triples.push_back(aux->getTriple()); | ||
| } else if (S.Context.getTargetInfo().getTriple().isNVPTX() || | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not actionable in this patch, but this points to the need for some kind of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i agree. |
||
| S.Context.getTargetInfo().getTriple().isAMDGPU() || | ||
| S.Context.getTargetInfo().getTriple().isSPIRV()) { | ||
| // Ignore the attribute for pure GPU device compiles since it only applies | ||
| // to host globals. | ||
| return; | ||
| } | ||
|
|
||
| auto SupportedTripleIt = llvm::find_if(Triples, IsTripleSupported); | ||
| if (SupportedTripleIt == Triples.end()) { | ||
|
Comment on lines
+2987
to
+2988
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was done this way because we also need the |
||
| S.Diag(LiteralLoc, diag::warn_unknown_attribute_ignored) << AL; | ||
| return; | ||
| } | ||
|
|
||
| llvm::CodeModel::Model CM; | ||
| if (!CodeModelAttr::ConvertStrToModel(Str, CM) || | ||
| !isValidCodeModelAttr(S, Str)) { | ||
| !isValidCodeModelAttr(*SupportedTripleIt, Str)) { | ||
| S.Diag(LiteralLoc, diag::err_attr_codemodel_arg) << Str; | ||
| return; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Triple contains a
std::string, I wouldn't treat it as a cheap-to-copy value type:https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/TargetParser/Triple.h#L321
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. This should be fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done