Skip to content

Commit

Permalink
[Driver] Add support for -msve-vector-bits=scalable.
Browse files Browse the repository at this point in the history
No real action is taken for a value of scalable but it provides a
route to disable an earlier specification and is effectively its
default value when omitted.

Patch also removes an "unused variable" warning.

Differential Revision: https://reviews.llvm.org/D84021
  • Loading branch information
paulwalker-arm committed Jul 20, 2020
1 parent b74ab49 commit ab7abd8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
3 changes: 2 additions & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Expand Up @@ -2816,7 +2816,8 @@ def err_attribute_bad_sve_vector_size : Error<
"invalid SVE vector size '%0', must match value set by "
"'-msve-vector-bits' ('%1')">;
def err_attribute_arm_feature_sve_bits_unsupported : Error<
"%0 is not supported when '-msve-vector-bits=<bits>' is not specified">;
"%0 is only supported when '-msve-vector-bits=<bits>' is specified with a "
"value of 128, 256, 512, 1024 or 2048.">;
def err_attribute_requires_positive_integer : Error<
"%0 attribute requires a %select{positive|non-negative}1 "
"integral compile time constant expression">;
Expand Down
5 changes: 3 additions & 2 deletions clang/include/clang/Driver/Options.td
Expand Up @@ -2346,8 +2346,9 @@ foreach i = {8-15,18} in

def msve_vector_bits_EQ : Joined<["-"], "msve-vector-bits=">,
Group<m_aarch64_Features_Group>, Flags<[DriverOption,CC1Option]>,
HelpText<"Set the size of fixed-length SVE vectors in bits.">,
Values<"128,256,512,1024,2048">;
HelpText<"Specify the size in bits of an SVE vector register. Defaults to the"
" vector length agnostic value of \"scalable\". (AArch64 only)">,
Values<"128,256,512,1024,2048,scalable">;

def msign_return_address_EQ : Joined<["-"], "msign-return-address=">,
Flags<[CC1Option]>, Group<m_Group>, Values<"none,all,non-leaf">,
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Driver/ToolChains/Arch/AArch64.cpp
Expand Up @@ -370,8 +370,8 @@ void aarch64::getAArch64TargetFeatures(const Driver &D,
V8_6Pos = Features.insert(std::next(V8_6Pos), {"+i8mm", "+bf16"});

bool HasSve = llvm::is_contained(Features, "+sve");
// -msve_vector_bits=<bits> flag is valid only if SVE is enabled.
if (Arg *A = Args.getLastArg(options::OPT_msve_vector_bits_EQ))
// -msve-vector-bits=<bits> flag is valid only if SVE is enabled.
if (Args.hasArg(options::OPT_msve_vector_bits_EQ))
if (!HasSve)
D.Diag(diag::err_drv_invalid_sve_vector_bits);

Expand Down
12 changes: 6 additions & 6 deletions clang/lib/Driver/ToolChains/Clang.cpp
Expand Up @@ -1720,15 +1720,15 @@ void Clang::AddAArch64TargetArgs(const ArgList &Args,
if (Arg *A = Args.getLastArg(options::OPT_msve_vector_bits_EQ)) {
StringRef Val = A->getValue();
const Driver &D = getToolChain().getDriver();
if (!Val.equals("128") && !Val.equals("256") && !Val.equals("512") &&
!Val.equals("1024") && !Val.equals("2048")) {
if (Val.equals("128") || Val.equals("256") || Val.equals("512") ||
Val.equals("1024") || Val.equals("2048"))
CmdArgs.push_back(
Args.MakeArgString(llvm::Twine("-msve-vector-bits=") + Val));
// Silently drop requests for vector-length agnostic code as it's implied.
else if (!Val.equals("scalable"))
// Handle the unsupported values passed to msve-vector-bits.
D.Diag(diag::err_drv_unsupported_option_argument)
<< A->getOption().getName() << Val;
} else if (A->getOption().matches(options::OPT_msve_vector_bits_EQ)) {
CmdArgs.push_back(
Args.MakeArgString(llvm::Twine("-msve-vector-bits=") + Val));
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion clang/test/Driver/aarch64-sve-vector-bits.c
Expand Up @@ -12,12 +12,15 @@
// RUN: -msve-vector-bits=1024 2>&1 | FileCheck --check-prefix=CHECK-1024 %s
// RUN: %clang -c %s -### -target aarch64-none-linux-gnu -march=armv8-a+sve \
// RUN: -msve-vector-bits=2048 2>&1 | FileCheck --check-prefix=CHECK-2048 %s
// RUN: %clang -c %s -### -target aarch64-none-linux-gnu -march=armv8-a+sve \
// RUN: -msve-vector-bits=scalable 2>&1 | FileCheck --check-prefix=CHECK-SCALABLE %s

// CHECK-128: "-msve-vector-bits=128"
// CHECK-256: "-msve-vector-bits=256"
// CHECK-512: "-msve-vector-bits=512"
// CHECK-1024: "-msve-vector-bits=1024"
// CHECK-2048: "-msve-vector-bits=2048"
// CHECK-SCALABLE-NOT: "-msve-vector-bits=

// Bail out if -msve-vector-bits is specified without SVE enabled
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -47,11 +50,13 @@
// -----------------------------------------------------------------------------
// RUN: not %clang -c %s -o /dev/null -target aarch64-none-linux-gnu \
// RUN: -march=armv8-a+sve 2>&1 | FileCheck --check-prefix=CHECK-NO-FLAG-ERROR %s
// RUN: not %clang -c %s -o /dev/null -target aarch64-none-linux-gnu \
// RUN: -march=armv8-a+sve -msve-vector-bits=scalable 2>&1 | FileCheck --check-prefix=CHECK-NO-FLAG-ERROR %s

typedef __SVInt32_t svint32_t;
typedef svint32_t noflag __attribute__((arm_sve_vector_bits(256)));

// CHECK-NO-FLAG-ERROR: error: 'arm_sve_vector_bits' is not supported when '-msve-vector-bits=<bits>' is not specified
// CHECK-NO-FLAG-ERROR: error: 'arm_sve_vector_bits' is only supported when '-msve-vector-bits=<bits>' is specified with a value of 128, 256, 512, 1024 or 2048

// Error if attribute vector size != -msve-vector-bits
// -----------------------------------------------------------------------------
Expand Down

0 comments on commit ab7abd8

Please sign in to comment.