Skip to content

release/18.x: [SPARC] Support reserving arbitrary general purpose registers (#74927) #81397

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

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 12 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -5815,6 +5815,18 @@ def mvis3 : Flag<["-"], "mvis3">, Group<m_sparc_Features_Group>;
def mno_vis3 : Flag<["-"], "mno-vis3">, Group<m_sparc_Features_Group>;
def mhard_quad_float : Flag<["-"], "mhard-quad-float">, Group<m_sparc_Features_Group>;
def msoft_quad_float : Flag<["-"], "msoft-quad-float">, Group<m_sparc_Features_Group>;
foreach i = 1 ... 7 in
def ffixed_g#i : Flag<["-"], "ffixed-g"#i>, Group<m_sparc_Features_Group>,
HelpText<"Reserve the G"#i#" register (SPARC only)">;
foreach i = 0 ... 5 in
def ffixed_o#i : Flag<["-"], "ffixed-o"#i>, Group<m_sparc_Features_Group>,
HelpText<"Reserve the O"#i#" register (SPARC only)">;
foreach i = 0 ... 7 in
def ffixed_l#i : Flag<["-"], "ffixed-l"#i>, Group<m_sparc_Features_Group>,
HelpText<"Reserve the L"#i#" register (SPARC only)">;
foreach i = 0 ... 5 in
def ffixed_i#i : Flag<["-"], "ffixed-i"#i>, Group<m_sparc_Features_Group>,
HelpText<"Reserve the I"#i#" register (SPARC only)">;
} // let Flags = [TargetSpecific]

// M68k features flags
Expand Down
81 changes: 81 additions & 0 deletions clang/lib/Driver/ToolChains/Arch/Sparc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,85 @@ void sparc::getSparcTargetFeatures(const Driver &D, const ArgList &Args,
else
Features.push_back("-hard-quad-float");
}

if (Args.hasArg(options::OPT_ffixed_g1))
Features.push_back("+reserve-g1");

if (Args.hasArg(options::OPT_ffixed_g2))
Features.push_back("+reserve-g2");

if (Args.hasArg(options::OPT_ffixed_g3))
Features.push_back("+reserve-g3");

if (Args.hasArg(options::OPT_ffixed_g4))
Features.push_back("+reserve-g4");

if (Args.hasArg(options::OPT_ffixed_g5))
Features.push_back("+reserve-g5");

if (Args.hasArg(options::OPT_ffixed_g6))
Features.push_back("+reserve-g6");

if (Args.hasArg(options::OPT_ffixed_g7))
Features.push_back("+reserve-g7");

if (Args.hasArg(options::OPT_ffixed_o0))
Features.push_back("+reserve-o0");

if (Args.hasArg(options::OPT_ffixed_o1))
Features.push_back("+reserve-o1");

if (Args.hasArg(options::OPT_ffixed_o2))
Features.push_back("+reserve-o2");

if (Args.hasArg(options::OPT_ffixed_o3))
Features.push_back("+reserve-o3");

if (Args.hasArg(options::OPT_ffixed_o4))
Features.push_back("+reserve-o4");

if (Args.hasArg(options::OPT_ffixed_o5))
Features.push_back("+reserve-o5");

if (Args.hasArg(options::OPT_ffixed_l0))
Features.push_back("+reserve-l0");

if (Args.hasArg(options::OPT_ffixed_l1))
Features.push_back("+reserve-l1");

if (Args.hasArg(options::OPT_ffixed_l2))
Features.push_back("+reserve-l2");

if (Args.hasArg(options::OPT_ffixed_l3))
Features.push_back("+reserve-l3");

if (Args.hasArg(options::OPT_ffixed_l4))
Features.push_back("+reserve-l4");

if (Args.hasArg(options::OPT_ffixed_l5))
Features.push_back("+reserve-l5");

if (Args.hasArg(options::OPT_ffixed_l6))
Features.push_back("+reserve-l6");

if (Args.hasArg(options::OPT_ffixed_l7))
Features.push_back("+reserve-l7");

if (Args.hasArg(options::OPT_ffixed_i0))
Features.push_back("+reserve-i0");

if (Args.hasArg(options::OPT_ffixed_i1))
Features.push_back("+reserve-i1");

if (Args.hasArg(options::OPT_ffixed_i2))
Features.push_back("+reserve-i2");

if (Args.hasArg(options::OPT_ffixed_i3))
Features.push_back("+reserve-i3");

if (Args.hasArg(options::OPT_ffixed_i4))
Features.push_back("+reserve-i4");

if (Args.hasArg(options::OPT_ffixed_i5))
Features.push_back("+reserve-i5");
}
181 changes: 181 additions & 0 deletions clang/test/Driver/sparc-fixed-register.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
// RUN: %clang --target=sparc-none-gnu -ffixed-g1 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-G1 < %t %s
// CHECK-FIXED-G1: "-target-feature" "+reserve-g1"

// RUN: %clang --target=sparc-none-gnu -ffixed-g2 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-G2 < %t %s
// CHECK-FIXED-G2: "-target-feature" "+reserve-g2"

// RUN: %clang --target=sparc-none-gnu -ffixed-g3 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-G3 < %t %s
// CHECK-FIXED-G3: "-target-feature" "+reserve-g3"

// RUN: %clang --target=sparc-none-gnu -ffixed-g4 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-G4 < %t %s
// CHECK-FIXED-G4: "-target-feature" "+reserve-g4"

// RUN: %clang --target=sparc-none-gnu -ffixed-g5 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-G5 < %t %s
// CHECK-FIXED-G5: "-target-feature" "+reserve-g5"

// RUN: %clang --target=sparc-none-gnu -ffixed-g6 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-G6 < %t %s
// CHECK-FIXED-G6: "-target-feature" "+reserve-g6"

// RUN: %clang --target=sparc-none-gnu -ffixed-g7 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-G7 < %t %s
// CHECK-FIXED-G7: "-target-feature" "+reserve-g7"

// RUN: %clang --target=sparc-none-gnu -ffixed-o0 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-O0 < %t %s
// CHECK-FIXED-O0: "-target-feature" "+reserve-o0"

// RUN: %clang --target=sparc-none-gnu -ffixed-o1 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-O1 < %t %s
// CHECK-FIXED-O1: "-target-feature" "+reserve-o1"

// RUN: %clang --target=sparc-none-gnu -ffixed-o2 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-O2 < %t %s
// CHECK-FIXED-O2: "-target-feature" "+reserve-o2"

// RUN: %clang --target=sparc-none-gnu -ffixed-o3 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-O3 < %t %s
// CHECK-FIXED-O3: "-target-feature" "+reserve-o3"

// RUN: %clang --target=sparc-none-gnu -ffixed-o4 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-O4 < %t %s
// CHECK-FIXED-O4: "-target-feature" "+reserve-o4"

// RUN: %clang --target=sparc-none-gnu -ffixed-o5 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-O5 < %t %s
// CHECK-FIXED-O5: "-target-feature" "+reserve-o5"

// RUN: %clang --target=sparc-none-gnu -ffixed-l0 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-L0 < %t %s
// CHECK-FIXED-L0: "-target-feature" "+reserve-l0"

// RUN: %clang --target=sparc-none-gnu -ffixed-l1 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-L1 < %t %s
// CHECK-FIXED-L1: "-target-feature" "+reserve-l1"

// RUN: %clang --target=sparc-none-gnu -ffixed-l2 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-L2 < %t %s
// CHECK-FIXED-L2: "-target-feature" "+reserve-l2"

// RUN: %clang --target=sparc-none-gnu -ffixed-l3 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-L3 < %t %s
// CHECK-FIXED-L3: "-target-feature" "+reserve-l3"

// RUN: %clang --target=sparc-none-gnu -ffixed-l4 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-L4 < %t %s
// CHECK-FIXED-L4: "-target-feature" "+reserve-l4"

// RUN: %clang --target=sparc-none-gnu -ffixed-l5 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-L5 < %t %s
// CHECK-FIXED-L5: "-target-feature" "+reserve-l5"

// RUN: %clang --target=sparc-none-gnu -ffixed-l6 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-L6 < %t %s
// CHECK-FIXED-L6: "-target-feature" "+reserve-l6"

// RUN: %clang --target=sparc-none-gnu -ffixed-l7 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-L7 < %t %s
// CHECK-FIXED-L7: "-target-feature" "+reserve-l7"

// RUN: %clang --target=sparc-none-gnu -ffixed-i0 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-I0 < %t %s
// CHECK-FIXED-I0: "-target-feature" "+reserve-i0"

// RUN: %clang --target=sparc-none-gnu -ffixed-i1 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-I1 < %t %s
// CHECK-FIXED-I1: "-target-feature" "+reserve-i1"

// RUN: %clang --target=sparc-none-gnu -ffixed-i2 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-I2 < %t %s
// CHECK-FIXED-I2: "-target-feature" "+reserve-i2"

// RUN: %clang --target=sparc-none-gnu -ffixed-i3 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-I3 < %t %s
// CHECK-FIXED-I3: "-target-feature" "+reserve-i3"

// RUN: %clang --target=sparc-none-gnu -ffixed-i4 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-I4 < %t %s
// CHECK-FIXED-I4: "-target-feature" "+reserve-i4"

// RUN: %clang --target=sparc-none-gnu -ffixed-i5 -### %s 2> %t
// RUN: FileCheck --check-prefix=CHECK-FIXED-I5 < %t %s
// CHECK-FIXED-I5: "-target-feature" "+reserve-i5"

// Test multiple of reserve-* options together.
// RUN: %clang --target=sparc-none-gnu \
// RUN: -ffixed-g1 \
// RUN: -ffixed-o2 \
// RUN: -ffixed-l3 \
// RUN: -ffixed-i4 \
// RUN: -### %s 2> %t
// RUN: FileCheck \
// RUN: --check-prefix=CHECK-FIXED-G1 \
// RUN: --check-prefix=CHECK-FIXED-O2 \
// RUN: --check-prefix=CHECK-FIXED-L3 \
// RUN: --check-prefix=CHECK-FIXED-I4 \
// RUN: < %t %s

// Test all reserve-* options together.
// RUN: %clang --target=sparc-none-gnu \
// RUN: -ffixed-g1 \
// RUN: -ffixed-g2 \
// RUN: -ffixed-g3 \
// RUN: -ffixed-g4 \
// RUN: -ffixed-g5 \
// RUN: -ffixed-g6 \
// RUN: -ffixed-g7 \
// RUN: -ffixed-o0 \
// RUN: -ffixed-o1 \
// RUN: -ffixed-o2 \
// RUN: -ffixed-o3 \
// RUN: -ffixed-o4 \
// RUN: -ffixed-o5 \
// RUN: -ffixed-l0 \
// RUN: -ffixed-l1 \
// RUN: -ffixed-l2 \
// RUN: -ffixed-l3 \
// RUN: -ffixed-l4 \
// RUN: -ffixed-l5 \
// RUN: -ffixed-l6 \
// RUN: -ffixed-l7 \
// RUN: -ffixed-i0 \
// RUN: -ffixed-i1 \
// RUN: -ffixed-i2 \
// RUN: -ffixed-i3 \
// RUN: -ffixed-i4 \
// RUN: -ffixed-i5 \
// RUN: -### %s 2> %t
// RUN: FileCheck \
// RUN: --check-prefix=CHECK-FIXED-G1 \
// RUN: --check-prefix=CHECK-FIXED-G2 \
// RUN: --check-prefix=CHECK-FIXED-G3 \
// RUN: --check-prefix=CHECK-FIXED-G4 \
// RUN: --check-prefix=CHECK-FIXED-G5 \
// RUN: --check-prefix=CHECK-FIXED-G6 \
// RUN: --check-prefix=CHECK-FIXED-G7 \
// RUN: --check-prefix=CHECK-FIXED-O0 \
// RUN: --check-prefix=CHECK-FIXED-O1 \
// RUN: --check-prefix=CHECK-FIXED-O2 \
// RUN: --check-prefix=CHECK-FIXED-O3 \
// RUN: --check-prefix=CHECK-FIXED-O4 \
// RUN: --check-prefix=CHECK-FIXED-O5 \
// RUN: --check-prefix=CHECK-FIXED-L0 \
// RUN: --check-prefix=CHECK-FIXED-L1 \
// RUN: --check-prefix=CHECK-FIXED-L2 \
// RUN: --check-prefix=CHECK-FIXED-L3 \
// RUN: --check-prefix=CHECK-FIXED-L4 \
// RUN: --check-prefix=CHECK-FIXED-L5 \
// RUN: --check-prefix=CHECK-FIXED-L6 \
// RUN: --check-prefix=CHECK-FIXED-L7 \
// RUN: --check-prefix=CHECK-FIXED-I0 \
// RUN: --check-prefix=CHECK-FIXED-I1 \
// RUN: --check-prefix=CHECK-FIXED-I2 \
// RUN: --check-prefix=CHECK-FIXED-I3 \
// RUN: --check-prefix=CHECK-FIXED-I4 \
// RUN: --check-prefix=CHECK-FIXED-I5 \
// RUN: < %t %s
14 changes: 14 additions & 0 deletions llvm/lib/Target/Sparc/Sparc.td
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ def TuneSlowRDPC : SubtargetFeature<"slow-rdpc", "HasSlowRDPC", "true",
//==== Features added predmoninantly for LEON subtarget support
include "LeonFeatures.td"

//==== Register allocation tweaks needed by some low-level software
foreach i = 1 ... 7 in
def FeatureReserveG#i : SubtargetFeature<"reserve-g"#i, "ReserveRegister["#i#" + SP::G0]", "true",
"Reserve G"#i#", making it unavailable as a GPR">;
foreach i = 0 ... 5 in
def FeatureReserveO#i : SubtargetFeature<"reserve-o"#i, "ReserveRegister["#i#" + SP::O0]", "true",
"Reserve O"#i#", making it unavailable as a GPR">;
foreach i = 0 ... 7 in
def FeatureReserveL#i : SubtargetFeature<"reserve-l"#i, "ReserveRegister["#i#" + SP::L0]", "true",
"Reserve L"#i#", making it unavailable as a GPR">;
foreach i = 0 ... 5 in
def FeatureReserveI#i : SubtargetFeature<"reserve-i"#i, "ReserveRegister["#i#" + SP::I0]", "true",
"Reserve I"#i#", making it unavailable as a GPR">;

//===----------------------------------------------------------------------===//
// Register File, Calling Conv, Instruction Descriptions
//===----------------------------------------------------------------------===//
Expand Down
Loading