1//===- Types.cpp - Helper for the selection of C++ data types. ------------===//
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
9#include "Types.h"
10
11#include <cassert>
12
13using namespace llvm;
14
15const char *llvm::getMinimalTypeForRange(uint64_t Range,
16 [[maybe_unused]] unsigned MaxSize) {
17 // TODO: The original callers only used 32 and 64 so these are the only
18 // values permitted. Rather than widen the supported values we should
19 // allow 64 for the callers that currently use 32 and remove the
20 // argument altogether.
21 assert((MaxSize == 32 || MaxSize == 64) && "Unexpected size");
22 assert(MaxSize <= 64 && "Unexpected size");
23 assert(((MaxSize > 32) ? Range <= 0xFFFFFFFFFFFFFFFFULL
24 : Range <= 0xFFFFFFFFULL) &&
25 "Enum too large");
26
27 if (Range > 0xFFFFFFFFULL)
28 return "uint64_t";
29 if (Range > 0xFFFF)
30 return "uint32_t";
31 if (Range > 0xFF)
32 return "uint16_t";
33 return "uint8_t";
34}
35