Skip to content
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

[Driver] Default -msmall-data-limit= to 0 and clean up code #83093

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
41 changes: 4 additions & 37 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2029,42 +2029,6 @@ void Clang::AddPPCTargetArgs(const ArgList &Args,
}
}

static void SetRISCVSmallDataLimit(const ToolChain &TC, const ArgList &Args,
ArgStringList &CmdArgs) {
const Driver &D = TC.getDriver();
const llvm::Triple &Triple = TC.getTriple();
// Default small data limitation is eight.
const char *SmallDataLimit = "8";
// Get small data limitation.
if (Args.getLastArg(options::OPT_shared, options::OPT_fpic,
options::OPT_fPIC)) {
// Not support linker relaxation for PIC.
SmallDataLimit = "0";
if (Args.hasArg(options::OPT_G)) {
D.Diag(diag::warn_drv_unsupported_sdata);
}
} else if (Args.getLastArgValue(options::OPT_mcmodel_EQ)
.equals_insensitive("large") &&
(Triple.getArch() == llvm::Triple::riscv64)) {
// Not support linker relaxation for RV64 with large code model.
SmallDataLimit = "0";
if (Args.hasArg(options::OPT_G)) {
D.Diag(diag::warn_drv_unsupported_sdata);
}
} else if (Triple.isAndroid()) {
// GP relaxation is not supported on Android.
SmallDataLimit = "0";
if (Args.hasArg(options::OPT_G)) {
D.Diag(diag::warn_drv_unsupported_sdata);
}
} else if (Arg *A = Args.getLastArg(options::OPT_G)) {
SmallDataLimit = A->getValue();
}
// Forward the -msmall-data-limit= option.
CmdArgs.push_back("-msmall-data-limit");
CmdArgs.push_back(SmallDataLimit);
}

void Clang::AddRISCVTargetArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
const llvm::Triple &Triple = getToolChain().getTriple();
Expand All @@ -2073,7 +2037,10 @@ void Clang::AddRISCVTargetArgs(const ArgList &Args,
CmdArgs.push_back("-target-abi");
CmdArgs.push_back(ABIName.data());

SetRISCVSmallDataLimit(getToolChain(), Args, CmdArgs);
if (Arg *A = Args.getLastArg(options::OPT_G)) {
CmdArgs.push_back("-msmall-data-limit");
CmdArgs.push_back(A->getValue());
}

if (!Args.hasFlag(options::OPT_mimplicit_float,
options::OPT_mno_implicit_float, true))
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CodeGen/RISCV/riscv-sdata-module-flag.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@

void test(void) {}

// RV32-DEFAULT: !{i32 8, !"SmallDataLimit", i32 8}
// RV32-DEFAULT: !{i32 8, !"SmallDataLimit", i32 0}
// RV32-G4: !{i32 8, !"SmallDataLimit", i32 4}
// RV32-S0: !{i32 8, !"SmallDataLimit", i32 0}
// RV32-S2G4: !{i32 8, !"SmallDataLimit", i32 4}
// RV32-T16: !{i32 8, !"SmallDataLimit", i32 16}
// RV32-PIC: !{i32 8, !"SmallDataLimit", i32 0}

// RV64-DEFAULT: !{i32 8, !"SmallDataLimit", i32 8}
// RV64-DEFAULT: !{i32 8, !"SmallDataLimit", i32 0}
// RV64-G4: !{i32 8, !"SmallDataLimit", i32 4}
// RV64-S0: !{i32 8, !"SmallDataLimit", i32 0}
// RV64-S2G4: !{i32 8, !"SmallDataLimit", i32 4}
Expand Down
4 changes: 0 additions & 4 deletions clang/test/Driver/riscv-sdata-warning.c

This file was deleted.

5 changes: 5 additions & 0 deletions clang/test/Driver/riscv-sdata.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: %clang -### -S --target=riscv64 %s 2>&1 | FileCheck %s
// RUN: %clang -### -S --target=riscv64 -msmall-data-limit=8 %s 2>&1 | FileCheck %s --check-prefix=EIGHT

// CHECK-NOT: "-msmall-data-limit"
// EIGHT: "-msmall-data-limit" "8"
2 changes: 1 addition & 1 deletion llvm/lib/Target/RISCV/RISCVTargetObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace llvm {
class RISCVELFTargetObjectFile : public TargetLoweringObjectFileELF {
MCSection *SmallDataSection;
MCSection *SmallBSSSection;
unsigned SSThreshold = 8;
unsigned SSThreshold = 0;

public:
unsigned getTextSectionAlignment() const override;
Expand Down
Loading