Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / utils / TableGen / Types.cpp
blobaca8e36b683db19d96f30c4b51bcba81ed4002df
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 //===----------------------------------------------------------------------===//
9 #include "Types.h"
11 // For LLVM_ATTRIBUTE_UNUSED
12 #include "llvm/Support/Compiler.h"
14 #include <cassert>
16 using namespace llvm;
18 const char *llvm::getMinimalTypeForRange(uint64_t Range, unsigned MaxSize LLVM_ATTRIBUTE_UNUSED) {
19 // TODO: The original callers only used 32 and 64 so these are the only
20 // values permitted. Rather than widen the supported values we should
21 // allow 64 for the callers that currently use 32 and remove the
22 // argument altogether.
23 assert((MaxSize == 32 || MaxSize == 64) && "Unexpected size");
24 assert(MaxSize <= 64 && "Unexpected size");
25 assert(((MaxSize > 32) ? Range <= 0xFFFFFFFFFFFFFFFFULL
26 : Range <= 0xFFFFFFFFULL) &&
27 "Enum too large");
29 if (Range > 0xFFFFFFFFULL)
30 return "uint64_t";
31 if (Range > 0xFFFF)
32 return "uint32_t";
33 if (Range > 0xFF)
34 return "uint16_t";
35 return "uint8_t";