RenderTargetOptions(Triple, Args, KernelOrKext, CmdArgs);
+ // FIXME: For now we want to demote any errors to warnings, when they have
+ // been raised for asking the wrong question of scalable vectors, such as
+ // asking for the fixed number of elements. This may happen because code that
+ // is not yet ported to work for scalable vectors uses the wrong interfaces,
+ // whereas the behaviour is actually correct. Emitting a warning helps bring
+ // up scalable vector support in an incremental way. When scalable vector
+ // support is stable enough, all uses of wrong interfaces should be considered
+ // as errors, but until then, we can live with a warning being emitted by the
+ // compiler. This way, Clang can be used to compile code with scalable vectors
+ // and identify possible issues.
+ if (isa<BackendJobAction>(JA)) {
+ CmdArgs.push_back("-mllvm");
+ CmdArgs.push_back("-treat-scalable-fixed-error-as-warning");
+ }
+
// These two are potentially updated by AddClangCLArgs.
codegenoptions::DebugInfoKind DebugInfoKind = codegenoptions::NoDebugInfo;
bool EmitCodeView = false;
/// Given a vector type, return the number of elements it contains.
unsigned getVectorNumElements() const {
-#ifdef STRICT_FIXED_SIZE_VECTORS
- assert(isFixedLengthVector() && "Invalid vector type!");
-#else
assert(isVector() && "Invalid vector type!");
+
if (isScalableVector())
- WithColor::warning()
- << "Possible incorrect use of EVT::getVectorNumElements() for "
- "scalable vector. Scalable flag may be dropped, use "
- "EVT::getVectorElementCount() instead\n";
-#endif
- if (isSimple())
- return V.getVectorNumElements();
- return getExtendedVectorNumElements();
+ llvm::reportInvalidSizeRequest(
+ "Possible incorrect use of EVT::getVectorNumElements() for "
+ "scalable vector. Scalable flag may be dropped, use "
+ "EVT::getVectorElementCount() instead");
+
+ return isSimple() ? V.getVectorNumElements()
+ : getExtendedVectorNumElements();
}
// Given a (possibly scalable) vector type, return the ElementCount
namespace llvm {
+/// Reports a diagnostic message to indicate an invalid size request has been
+/// done on a scalable vector. This function may not return.
+void reportInvalidSizeRequest(const char *Msg);
+
template <typename LeafTy> struct LinearPolyBaseTypeTraits {};
//===----------------------------------------------------------------------===//
// else
// bail out early for scalable vectors and use getFixedValue()
// }
- operator ScalarTy() const {
-#ifdef STRICT_FIXED_SIZE_VECTORS
- return getFixedValue();
-#else
- if (isScalable())
- WithColor::warning() << "Compiler has made implicit assumption that "
- "TypeSize is not scalable. This may or may not "
- "lead to broken code.\n";
- return getKnownMinValue();
-#endif
- }
+ operator ScalarTy() const;
// Additional operators needed to avoid ambiguous parses
// because of the implicit conversion hack.
if (Q.isUndefValue(Ops[0]))
return UndefValue::get(GEPTy);
- bool IsScalableVec = isa<ScalableVectorType>(SrcTy);
+ bool IsScalableVec =
+ isa<ScalableVectorType>(SrcTy) || any_of(Ops, [](const Value *V) {
+ return isa<ScalableVectorType>(V->getType());
+ });
if (Ops.size() == 2) {
// getelementptr P, 0 -> P.
assert(VT.isVector() && "This DAG node is restricted to vector types.");
assert(Operand.getValueType().bitsLE(VT) &&
"The input must be the same size or smaller than the result.");
- assert(VT.getVectorNumElements() <
- Operand.getValueType().getVectorNumElements() &&
+ assert(VT.getVectorMinNumElements() <
+ Operand.getValueType().getVectorMinNumElements() &&
"The destination vector type must have fewer lanes than the input.");
break;
case ISD::ABS:
TrigramIndex.cpp
Triple.cpp
Twine.cpp
+ TypeSize.cpp
Unicode.cpp
UnicodeCaseFold.cpp
VersionTuple.cpp
--- /dev/null
+//===- TypeSize.cpp - Wrapper around type sizes------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/TypeSize.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace llvm;
+
+/// The ScalableErrorAsWarning is a temporary measure to suppress errors from
+/// using the wrong interface on a scalable vector.
+cl::opt<bool> ScalableErrorAsWarning(
+ "treat-scalable-fixed-error-as-warning", cl::Hidden, cl::init(false),
+ cl::desc("Treat issues where a fixed-width property is requested from a "
+ "scalable type as a warning, instead of an error."),
+ cl::ZeroOrMore);
+
+void llvm::reportInvalidSizeRequest(const char *Msg) {
+#ifndef STRICT_FIXED_SIZE_VECTORS
+ if (ScalableErrorAsWarning) {
+ WithColor::warning() << "Invalid size request on a scalable vector; " << Msg
+ << "\n";
+ return;
+ }
+#endif
+ report_fatal_error("Invalid size request on a scalable vector.");
+}
+
+TypeSize::operator TypeSize::ScalarTy() const {
+ if (isScalable()) {
+ reportInvalidSizeRequest(
+ "Cannot implicitly convert a scalable size to a fixed-width size in "
+ "`TypeSize::operator ScalarTy()`");
+ return getKnownMinValue();
+ }
+ return getFixedValue();
+}
// Check convenience size scaling methods.
EXPECT_EQ(v2i32.getSizeInBits() * 2, v4i32.getSizeInBits());
EXPECT_EQ(2 * nxv2i32.getSizeInBits(), nxv4i32.getSizeInBits());
- EXPECT_EQ(nxv2f64.getSizeInBits() / 2, nxv2i32.getSizeInBits());
+ EXPECT_EQ(nxv2f64.getSizeInBits().divideCoefficientBy(2),
+ nxv2i32.getSizeInBits());
}
} // end anonymous namespace