1 //===- Types.cpp - Helper for the selection of C++ data types. ------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "Types.h" 11 12 // For LLVM_ATTRIBUTE_UNUSED 13 #include "llvm/Support/Compiler.h" 14 15 #include <cassert> 16 17 using namespace llvm; 18 getMinimalTypeForRange(uint64_t Range,unsigned MaxSize LLVM_ATTRIBUTE_UNUSED)19const char *llvm::getMinimalTypeForRange(uint64_t Range, unsigned MaxSize LLVM_ATTRIBUTE_UNUSED) { 20 // TODO: The original callers only used 32 and 64 so these are the only 21 // values permitted. Rather than widen the supported values we should 22 // allow 64 for the callers that currently use 32 and remove the 23 // argument altogether. 24 assert((MaxSize == 32 || MaxSize == 64) && "Unexpected size"); 25 assert(MaxSize <= 64 && "Unexpected size"); 26 assert(((MaxSize > 32) ? Range <= 0xFFFFFFFFFFFFFFFFULL 27 : Range <= 0xFFFFFFFFULL) && 28 "Enum too large"); 29 30 if (Range > 0xFFFFFFFFULL) 31 return "uint64_t"; 32 if (Range > 0xFFFF) 33 return "uint32_t"; 34 if (Range > 0xFF) 35 return "uint16_t"; 36 return "uint8_t"; 37 } 38 getMinimalTypeForEnumBitfield(uint64_t Size)39const char *llvm::getMinimalTypeForEnumBitfield(uint64_t Size) { 40 uint64_t MaxIndex = Size; 41 if (MaxIndex > 0) 42 MaxIndex--; 43 assert(MaxIndex <= 64 && "Too many bits"); 44 return getMinimalTypeForRange(1ULL << MaxIndex); 45 } 46