Skip to content

Conversation

@tclin914
Copy link
Contributor

@tclin914 tclin914 commented Sep 9, 2024

No description provided.

@llvmbot llvmbot added clang Clang issues not falling into any other category backend:RISC-V clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Sep 9, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 9, 2024

@llvm/pr-subscribers-clang
@llvm/pr-subscribers-backend-risc-v

@llvm/pr-subscribers-clang-driver

Author: Jim Lin (tclin914)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/107817.diff

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+2-1)
  • (added) clang/test/Driver/riscv-mcmodel.c (+20)
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 0601016c3b14b8..f0e1b59076c738 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2906,7 +2906,8 @@ void tools::addMCModel(const Driver &D, const llvm::opt::ArgList &Args,
         CM = "small";
       else if (CM == "medany")
         CM = "medium";
-      Ok = CM == "small" || CM == "medium";
+      Ok = CM == "small" || CM == "medium" ||
+           (CM == "large" && Triple.isRISCV64());
     } else if (Triple.getArch() == llvm::Triple::x86_64) {
       Ok = llvm::is_contained({"small", "kernel", "medium", "large", "tiny"},
                               CM);
diff --git a/clang/test/Driver/riscv-mcmodel.c b/clang/test/Driver/riscv-mcmodel.c
new file mode 100644
index 00000000000000..2482672d625fe3
--- /dev/null
+++ b/clang/test/Driver/riscv-mcmodel.c
@@ -0,0 +1,20 @@
+// RUN: %clang --target=riscv32 -### -c -mcmodel=small %s 2>&1 | FileCheck --check-prefix=SMALL %s
+// RUN: %clang --target=riscv64 -### -c -mcmodel=small %s 2>&1 | FileCheck --check-prefix=SMALL %s
+
+// RUN: %clang --target=riscv32 -### -c -mcmodel=medlow %s 2>&1 | FileCheck --check-prefix=SMALL %s
+// RUN: %clang --target=riscv64 -### -c -mcmodel=medlow %s 2>&1 | FileCheck --check-prefix=SMALL %s
+
+// RUN: %clang --target=riscv32 -### -c -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=MEDIUM %s
+// RUN: %clang --target=riscv64 -### -c -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=MEDIUM %s
+
+// RUN: %clang --target=riscv32 -### -c -mcmodel=medany %s 2>&1 | FileCheck --check-prefix=MEDIUM %s
+// RUN: %clang --target=riscv64 -### -c -mcmodel=medany %s 2>&1 | FileCheck --check-prefix=MEDIUM %s
+
+// RUN: not %clang --target=riscv32 -### -c -mcmodel=large %s 2>&1 | FileCheck --check-prefix=ERR-LARGE %s
+// RUN: %clang --target=riscv64 -### -c -mcmodel=large %s 2>&1 | FileCheck --check-prefix=LARGE %s
+
+// SMALL: "-mcmodel=small"
+// MEDIUM: "-mcmodel=medium"
+// LARGE: "-mcmodel=large"
+
+// ERR-LARGE:  error: unsupported argument 'large' to option '-mcmodel=' for target 'riscv32'

@lenary
Copy link
Member

lenary commented Sep 9, 2024

What's the status of backend support for the large code model? That would presumably be a prerequisite to landing this.

@wangpc-pp
Copy link
Contributor

What's the status of backend support for the large code model? That would presumably be a prerequisite to landing this.

It was just merged: #70308.

@lenary
Copy link
Member

lenary commented Sep 9, 2024

What's the status of backend support for the large code model? That would presumably be a prerequisite to landing this.

It was just merged: #70308.

I expected I was out of date, thanks for the link.

The psABI says the large code model is not compatible with PIC - this presumably still applies to LLVM's implementation? If so, I think we need to add an unsupported error message in this case.

@asb
Copy link
Contributor

asb commented Sep 10, 2024

I think we want to set a define for this as well, for consistency with medany and medlow (as tested in test/Preprocessor/riscv-cmodel.c). I submitted a trivial PR to riscv-c-api-doc to add this riscv-non-isa/riscv-c-api-doc#86 which I'd hope lands quickly.

EDIT: This change also deserves an entry in clang/docs/ReleaseNotes.rst IMHO.

Copy link

@cmuellner cmuellner left a comment

Choose a reason for hiding this comment

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

What I am missing is:

  • adjustments in clang/lib/Basic/Targets/RISCV.cpp to emit the macro __riscv_cmodel_large
  • new tests in clang/test/Preprocessor/riscv-cmodel.c

Related PRs:

tclin914 added a commit that referenced this pull request Sep 11, 2024
@tclin914 tclin914 force-pushed the codemodel-large-driver-up branch from 7bc57f0 to cb5e946 Compare September 11, 2024 01:47
@tclin914
Copy link
Contributor Author

What I am missing is:

  • adjustments in clang/lib/Basic/Targets/RISCV.cpp to emit the macro __riscv_cmodel_large
  • new tests in clang/test/Preprocessor/riscv-cmodel.c

Related PRs:

A follow-up PR #108131 for __riscv_cmodel_large

Copy link
Member

@lenary lenary left a comment

Choose a reason for hiding this comment

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

LGTM, on the basis the preprocessor changes are in a different PR.

@tclin914 tclin914 merged commit 757d8b3 into llvm:main Sep 12, 2024
@tclin914 tclin914 deleted the codemodel-large-driver-up branch September 12, 2024 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:RISC-V clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants