llvm/utils/TableGen/Types.cpp
Daniel Sanders b313c742da Check that emitted instructions meet their predicates on all targets except ARM, Mips, and X86.
Summary:
* ARM is omitted from this patch because this check appears to expose bugs in this target.
* Mips is omitted from this patch because this check either detects bugs or deliberate
  emission of instructions that don't satisfy their predicates. One deliberate
  use is the SYNC instruction where the version with an operand is correctly
  defined as requiring MIPS32 while the version without an operand is defined
  as an alias of 'SYNC 0' and requires MIPS2.
* X86 is omitted from this patch because it doesn't use the tablegen-erated
  MCCodeEmitter infrastructure.

Patches for ARM and Mips will follow.

Depends on D25617

Reviewers: tstellarAMD, jmolloy

Subscribers: wdng, jmolloy, aemerson, rengolin, arsenm, jyknight, nemanjai, nhaehnle, tstellarAMD, llvm-commits

Differential Revision: https://reviews.llvm.org/D25618

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287439 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-19 13:05:44 +00:00

45 lines
1.4 KiB
C++

//===- Types.cpp - Helper for the selection of C++ data types. ------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "Types.h"
// For LLVM_ATTRIBUTE_UNUSED
#include "llvm/Support/Compiler.h"
#include <cassert>
using namespace llvm;
const char *llvm::getMinimalTypeForRange(uint64_t Range, unsigned MaxSize LLVM_ATTRIBUTE_UNUSED) {
// TODO: The original callers only used 32 and 64 so these are the only
// values permitted. Rather than widen the supported values we should
// allow 64 for the callers that currently use 32 and remove the
// argument altogether.
assert((MaxSize == 32 || MaxSize == 64) && "Unexpected size");
assert(MaxSize <= 64 && "Unexpected size");
assert(((MaxSize > 32) ? Range <= 0xFFFFFFFFFFFFFFFFULL
: Range <= 0xFFFFFFFFULL) &&
"Enum too large");
if (Range > 0xFFFFFFFFULL)
return "uint64_t";
if (Range > 0xFFFF)
return "uint32_t";
if (Range > 0xFF)
return "uint16_t";
return "uint8_t";
}
const char *llvm::getMinimalTypeForEnumBitfield(uint64_t Size) {
uint64_t MaxIndex = Size;
if (MaxIndex > 0)
MaxIndex--;
return getMinimalTypeForRange(1ULL << MaxIndex);
}