[clang] [clang][X86] Support __attribute__((model("small"/"large"))) (PR #124834)
Pranav Kant via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 12 14:55:35 PST 2025
================
@@ -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() ||
+ 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()) {
----------------
pranavk wrote:
this was done this way because we also need the `SupportedTripleIt` later in line 2995
https://github.com/llvm/llvm-project/pull/124834
More information about the cfe-commits
mailing list