LLVM 19.0.0git
TypeSize.cpp
Go to the documentation of this file.
1//===- TypeSize.cpp - Wrapper around type sizes------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
13
14#include "DebugOptions.h"
15
16using namespace llvm;
17
18#ifndef STRICT_FIXED_SIZE_VECTORS
19namespace {
20struct CreateScalableErrorAsWarning {
21 /// The ScalableErrorAsWarning is a temporary measure to suppress errors from
22 /// using the wrong interface on a scalable vector.
23 static void *call() {
24 return new cl::opt<bool>(
25 "treat-scalable-fixed-error-as-warning", cl::Hidden,
27 "Treat issues where a fixed-width property is requested from a "
28 "scalable type as a warning, instead of an error"));
29 }
30};
31} // namespace
32static ManagedStatic<cl::opt<bool>, CreateScalableErrorAsWarning>
35#else
37#endif
38
39void llvm::reportInvalidSizeRequest(const char *Msg) {
40#ifndef STRICT_FIXED_SIZE_VECTORS
42 WithColor::warning() << "Invalid size request on a scalable vector; " << Msg
43 << "\n";
44 return;
45 }
46#endif
47 report_fatal_error("Invalid size request on a scalable vector.");
48}
49
50TypeSize::operator TypeSize::ScalarTy() const {
51 if (isScalable()) {
53 "Cannot implicitly convert a scalable size to a fixed-width size in "
54 "`TypeSize::operator ScalarTy()`");
55 return getKnownMinValue();
56 }
57 return getFixedValue();
58}
static ManagedStatic< cl::opt< bool >, CreateScalableErrorAsWarning > ScalableErrorAsWarning
Definition: TypeSize.cpp:33
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:83
static raw_ostream & warning()
Convenience method for printing "warning: " to stderr.
Definition: WithColor.cpp:85
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition: TypeSize.h:171
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition: TypeSize.h:168
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
void initTypeSizeOptions()
Definition: TypeSize.cpp:34
void reportInvalidSizeRequest(const char *Msg)
Reports a diagnostic message to indicate an invalid size request has been done on a scalable vector.
Definition: TypeSize.cpp:39