Commit b0051dfa by Jim Stichnoth

Subzero: Fix g++ warnings.

This tries to use the same -W options that the buildbots use, to reduce the amount of warning spam in the logs. BUG= none R=jpp@chromium.org Review URL: https://codereview.chromium.org/1575873006 .
parent 5aa4b89f
...@@ -189,9 +189,14 @@ LLVM_EXTRA_WARNINGS := -Wcovered-switch-default ...@@ -189,9 +189,14 @@ LLVM_EXTRA_WARNINGS := -Wcovered-switch-default
ifdef GPLUSPLUS ifdef GPLUSPLUS
CXX := CCACHE_CPP2=yes $(CCACHE) g++ CXX := CCACHE_CPP2=yes $(CCACHE) g++
STDLIB_FLAGS := STDLIB_FLAGS :=
LLVM_EXTRA_WARNINGS := -Wno-unknown-pragmas -Wno-unused-parameter \ LLVM_EXTRA_WARNINGS := \
-Wno-comment -Wno-enum-compare -Wno-strict-aliasing \ -Wcast-qual \
-Wno-return-type -Wno-comment \
-Wno-long-long \
-Wno-maybe-uninitialized \
-Wno-missing-field-initializers \
-Wno-unused-parameter \
-Wwrite-strings
OBJDIR := $(OBJDIR)+Gplusplus OBJDIR := $(OBJDIR)+Gplusplus
endif endif
......
...@@ -387,6 +387,7 @@ IValueT encodeImmRegOffset(OpEncoding AddressEncoding, IValueT Reg, ...@@ -387,6 +387,7 @@ IValueT encodeImmRegOffset(OpEncoding AddressEncoding, IValueT Reg,
assert(Mode == OperandARM32Mem::Offset); assert(Mode == OperandARM32Mem::Offset);
return Reg << kRnShift; return Reg << kRnShift;
} }
llvm_unreachable("(silence g++ warning)");
} }
// Encodes memory address Opnd, and encodes that information into Value, based // Encodes memory address Opnd, and encodes that information into Value, based
......
...@@ -526,6 +526,7 @@ void CfgNode::advancedPhiLowering() { ...@@ -526,6 +526,7 @@ void CfgNode::advancedPhiLowering() {
} }
} }
assert(Found); assert(Found);
(void)Found;
} }
// Now that a cycle (if any) has been broken, create the actual // Now that a cycle (if any) has been broken, create the actual
// assignment. // assignment.
......
...@@ -19,10 +19,16 @@ ...@@ -19,10 +19,16 @@
#include "IceClFlagsExtra.h" #include "IceClFlagsExtra.h"
#ifdef __clang__
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter" #pragma clang diagnostic ignored "-Wunused-parameter"
#endif // __clang__
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#ifdef __clang__
#pragma clang diagnostic pop #pragma clang diagnostic pop
#endif // __clang__
namespace cl = llvm::cl; namespace cl = llvm::cl;
......
...@@ -17,11 +17,17 @@ ...@@ -17,11 +17,17 @@
#include "IceDefs.h" #include "IceDefs.h"
#ifdef __clang__
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter" #pragma clang diagnostic ignored "-Wunused-parameter"
#pragma clang diagnostic ignored "-Wredundant-move" #pragma clang diagnostic ignored "-Wredundant-move"
#endif // __clang__
#include "llvm/IRReader/IRReader.h" #include "llvm/IRReader/IRReader.h"
#ifdef __clang__
#pragma clang diagnostic pop #pragma clang diagnostic pop
#endif // __clang__
namespace Ice { namespace Ice {
......
...@@ -19,15 +19,21 @@ ...@@ -19,15 +19,21 @@
#include "IceELFStreamer.h" #include "IceELFStreamer.h"
#include "IceGlobalContext.h" #include "IceGlobalContext.h"
#ifdef __clang__
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter" #pragma clang diagnostic ignored "-Wunused-parameter"
#endif // __clang__
#include "llvm/Bitcode/NaCl/NaClBitcodeMungeUtils.h" #include "llvm/Bitcode/NaCl/NaClBitcodeMungeUtils.h"
#include "llvm/Support/FileSystem.h" #include "llvm/Support/FileSystem.h"
#include "llvm/Support/raw_os_ostream.h" #include "llvm/Support/raw_os_ostream.h"
#include "llvm/Support/Signals.h" #include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h" #include "llvm/Support/SourceMgr.h"
#include "llvm/Support/StreamingMemoryObject.h" #include "llvm/Support/StreamingMemoryObject.h"
#ifdef __clang__
#pragma clang diagnostic pop #pragma clang diagnostic pop
#endif // __clang__
#include <cstdio> #include <cstdio>
#include <fstream> #include <fstream>
......
...@@ -27,8 +27,11 @@ ...@@ -27,8 +27,11 @@
#include "IceELFObjectWriter.h" #include "IceELFObjectWriter.h"
#include "PNaClTranslator.h" #include "PNaClTranslator.h"
#ifdef __clang__
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter" #pragma clang diagnostic ignored "-Wunused-parameter"
#endif // __clang__
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
#include "llvm/Bitcode/NaCl/NaClReaderWriter.h" #include "llvm/Bitcode/NaCl/NaClReaderWriter.h"
#include "llvm/IR/LLVMContext.h" #include "llvm/IR/LLVMContext.h"
...@@ -37,9 +40,11 @@ ...@@ -37,9 +40,11 @@
#include "llvm/Support/SourceMgr.h" #include "llvm/Support/SourceMgr.h"
#include "llvm/Support/StreamingMemoryObject.h" #include "llvm/Support/StreamingMemoryObject.h"
#include <regex> #ifdef __clang__
#pragma clang diagnostic pop #pragma clang diagnostic pop
#endif // __clang__
#include <regex>
namespace Ice { namespace Ice {
......
...@@ -26,8 +26,11 @@ ...@@ -26,8 +26,11 @@
#include "IceTypes.h" #include "IceTypes.h"
#include "IceTypeConverter.h" #include "IceTypeConverter.h"
#ifdef __clang__
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter" #pragma clang diagnostic ignored "-Wunused-parameter"
#endif // __clang__
#include "llvm/IR/Constant.h" #include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h" #include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h" #include "llvm/IR/DataLayout.h"
...@@ -35,7 +38,10 @@ ...@@ -35,7 +38,10 @@
#include "llvm/IR/Instructions.h" #include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h" #include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h" #include "llvm/IR/Module.h"
#ifdef __clang__
#pragma clang diagnostic pop #pragma clang diagnostic pop
#endif // __clang__
// TODO(kschimpf): Remove two namespaces being visible at once. // TODO(kschimpf): Remove two namespaces being visible at once.
using namespace llvm; using namespace llvm;
......
...@@ -26,10 +26,16 @@ ...@@ -26,10 +26,16 @@
#include "IceTimerTree.h" #include "IceTimerTree.h"
#include "IceTypes.h" #include "IceTypes.h"
#ifdef __clang__
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter" #pragma clang diagnostic ignored "-Wunused-parameter"
#endif // __clang__
#include "llvm/Support/Timer.h" #include "llvm/Support/Timer.h"
#ifdef __clang__
#pragma clang diagnostic pop #pragma clang diagnostic pop
#endif // __clang__
#include <algorithm> // max() #include <algorithm> // max()
#include <cctype> // isdigit(), isupper() #include <cctype> // isdigit(), isupper()
......
...@@ -23,13 +23,19 @@ ...@@ -23,13 +23,19 @@
#include "IceGlobalContext.h" #include "IceGlobalContext.h"
#include "IceTypes.h" #include "IceTypes.h"
#ifdef __clang__
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter" #pragma clang diagnostic ignored "-Wunused-parameter"
#pragma clang diagnostic ignored "-Wredundant-move" #pragma clang diagnostic ignored "-Wredundant-move"
#endif // __clang__
#include "llvm/Bitcode/NaCl/NaClBitcodeParser.h" // for NaClBitcodeRecord. #include "llvm/Bitcode/NaCl/NaClBitcodeParser.h" // for NaClBitcodeRecord.
#include "llvm/IR/CallingConv.h" #include "llvm/IR/CallingConv.h"
#include "llvm/IR/GlobalValue.h" // for GlobalValue::LinkageTypes. #include "llvm/IR/GlobalValue.h" // for GlobalValue::LinkageTypes.
#ifdef __clang__
#pragma clang diagnostic pop #pragma clang diagnostic pop
#endif // __clang__
#include <memory> #include <memory>
#include <utility> #include <utility>
......
...@@ -347,7 +347,7 @@ bool OperandARM32FlexFpImm::canHoldImm(Operand *C, uint32_t *ModifiedImm) { ...@@ -347,7 +347,7 @@ bool OperandARM32FlexFpImm::canHoldImm(Operand *C, uint32_t *ModifiedImm) {
static_assert(AllowedBits == 0xFFF80000u, static_assert(AllowedBits == 0xFFF80000u,
"Invalid mask for f32 modified immediates."); "Invalid mask for f32 modified immediates.");
const float F32 = llvm::cast<ConstantFloat>(C)->getValue(); const float F32 = llvm::cast<ConstantFloat>(C)->getValue();
const uint32_t I32 = *reinterpret_cast<const uint32_t *>(&F32); const uint32_t I32 = Utils::bitCopy<uint32_t>(F32);
if (I32 & ~AllowedBits) { if (I32 & ~AllowedBits) {
// constant has disallowed bits. // constant has disallowed bits.
return false; return false;
...@@ -376,7 +376,7 @@ bool OperandARM32FlexFpImm::canHoldImm(Operand *C, uint32_t *ModifiedImm) { ...@@ -376,7 +376,7 @@ bool OperandARM32FlexFpImm::canHoldImm(Operand *C, uint32_t *ModifiedImm) {
static_assert(AllowedBits == 0xFFFF0000u, static_assert(AllowedBits == 0xFFFF0000u,
"Invalid mask for f64 modified immediates."); "Invalid mask for f64 modified immediates.");
const double F64 = llvm::cast<ConstantDouble>(C)->getValue(); const double F64 = llvm::cast<ConstantDouble>(C)->getValue();
const uint64_t I64 = *reinterpret_cast<const uint64_t *>(&F64); const uint64_t I64 = Utils::bitCopy<uint64_t>(F64);
if (I64 & 0xFFFFFFFFu) { if (I64 & 0xFFFFFFFFu) {
// constant has disallowed bits. // constant has disallowed bits.
return false; return false;
...@@ -2100,7 +2100,7 @@ float materializeFloatImmediate(uint32_t ModifiedImm) { ...@@ -2100,7 +2100,7 @@ float materializeFloatImmediate(uint32_t ModifiedImm) {
const uint32_t Ret = ((ModifiedImm & a) ? 0x80000000 : 0) | const uint32_t Ret = ((ModifiedImm & a) ? 0x80000000 : 0) |
((ModifiedImm & b) ? 0x3E000000 : 0x40000000) | ((ModifiedImm & b) ? 0x3E000000 : 0x40000000) |
((ModifiedImm & cdefgh) << 19); ((ModifiedImm & cdefgh) << 19);
return *reinterpret_cast<const float *>(&Ret); return Utils::bitCopy<float>(Ret);
} }
} // end of anonymous namespace } // end of anonymous namespace
......
...@@ -2623,6 +2623,7 @@ public: ...@@ -2623,6 +2623,7 @@ public:
case AO_Sub: case AO_Sub:
return false; return false;
} }
llvm_unreachable("(silence g++ warning)");
} }
uint32_t shAmt() const { return ShAmt; } uint32_t shAmt() const { return ShAmt; }
...@@ -3767,11 +3768,11 @@ enum { ...@@ -3767,11 +3768,11 @@ enum {
_fcmp_hl_NUM _fcmp_hl_NUM
}; };
static_assert(_fcmp_hl_NUM == _fcmp_ll_NUM, static_assert((uint32_t)_fcmp_hl_NUM == (uint32_t)_fcmp_ll_NUM,
"Inconsistency between high-level and low-level fcmp tags."); "Inconsistency between high-level and low-level fcmp tags.");
#define X(tag, str) \ #define X(tag, str) \
static_assert( \ static_assert( \
_fcmp_hl_##tag == _fcmp_ll_##tag, \ (uint32_t)_fcmp_hl_##tag == (uint32_t)_fcmp_ll_##tag, \
"Inconsistency between high-level and low-level fcmp tag " #tag); "Inconsistency between high-level and low-level fcmp tag " #tag);
ICEINSTFCMP_TABLE ICEINSTFCMP_TABLE
#undef X #undef X
...@@ -6302,7 +6303,7 @@ template <> struct ConstantPoolEmitterTraits<float> { ...@@ -6302,7 +6303,7 @@ template <> struct ConstantPoolEmitterTraits<float> {
static uint64_t bitcastToUint64(float Value) { static uint64_t bitcastToUint64(float Value) {
static_assert(sizeof(Value) == sizeof(uint32_t), static_assert(sizeof(Value) == sizeof(uint32_t),
"Float should be 4 bytes."); "Float should be 4 bytes.");
uint32_t IntValue = *reinterpret_cast<uint32_t *>(&Value); const uint32_t IntValue = Utils::bitCopy<uint32_t>(Value);
return static_cast<uint64_t>(IntValue); return static_cast<uint64_t>(IntValue);
} }
}; };
...@@ -6317,7 +6318,7 @@ template <> struct ConstantPoolEmitterTraits<double> { ...@@ -6317,7 +6318,7 @@ template <> struct ConstantPoolEmitterTraits<double> {
static uint64_t bitcastToUint64(double Value) { static uint64_t bitcastToUint64(double Value) {
static_assert(sizeof(double) == sizeof(uint64_t), static_assert(sizeof(double) == sizeof(uint64_t),
"Double should be 8 bytes."); "Double should be 8 bytes.");
return *reinterpret_cast<uint64_t *>(&Value); return Utils::bitCopy<uint64_t>(Value);
} }
}; };
const char ConstantPoolEmitterTraits<double>::AsmTag[] = ".quad"; const char ConstantPoolEmitterTraits<double>::AsmTag[] = ".quad";
......
...@@ -116,7 +116,10 @@ struct TargetX8632Traits { ...@@ -116,7 +116,10 @@ struct TargetX8632Traits {
int32_t disp32() const { int32_t disp32() const {
assert(length_ >= 5); assert(length_ >= 5);
return bit_copy<int32_t>(encoding_[length_ - 4]); // TODO(stichnot): This method is not currently used. Delete it along
// with other unused methods, or use a safe version of bitCopy().
llvm::report_fatal_error("Unexpected call to disp32()");
// return Utils::bitCopy<int32_t>(encoding_[length_ - 4]);
} }
AssemblerFixup *fixup() const { return fixup_; } AssemblerFixup *fixup() const { return fixup_; }
......
...@@ -132,7 +132,10 @@ struct TargetX8664Traits { ...@@ -132,7 +132,10 @@ struct TargetX8664Traits {
int32_t disp32() const { int32_t disp32() const {
assert(length_ >= 5); assert(length_ >= 5);
return bit_copy<int32_t>(encoding_[length_ - 4]); // TODO(stichnot): This method is not currently used. Delete it along
// with other unused methods, or use a safe version of bitCopy().
llvm::report_fatal_error("Unexpected call to disp32()");
// return Utils::bitCopy<int32_t>(encoding_[length_ - 4]);
} }
AssemblerFixup *fixup() const { return fixup_; } AssemblerFixup *fixup() const { return fixup_; }
......
...@@ -17,10 +17,16 @@ ...@@ -17,10 +17,16 @@
#include "IceDefs.h" #include "IceDefs.h"
#ifdef __clang__
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter" #pragma clang diagnostic ignored "-Wunused-parameter"
#endif // __clang__
#include "llvm/Support/Timer.h" #include "llvm/Support/Timer.h"
#ifdef __clang__
#pragma clang diagnostic pop #pragma clang diagnostic pop
#endif // __clang__
namespace Ice { namespace Ice {
......
...@@ -18,11 +18,18 @@ ...@@ -18,11 +18,18 @@
#include "IceDefs.h" #include "IceDefs.h"
#include "IceTypes.h" #include "IceTypes.h"
#ifdef __clang__
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter" #pragma clang diagnostic ignored "-Wunused-parameter"
#pragma clang diagnostic ignored "-Wredundant-move" #pragma clang diagnostic ignored "-Wredundant-move"
#endif // __clang__
#include "llvm/IR/DerivedTypes.h" #include "llvm/IR/DerivedTypes.h"
#ifdef __clang__
#pragma clang diagnostic pop #pragma clang diagnostic pop
#endif // __clang__
namespace llvm { namespace llvm {
class LLVMContext; class LLVMContext;
......
...@@ -19,114 +19,111 @@ ...@@ -19,114 +19,111 @@
#include <cmath> // std::signbit() #include <cmath> // std::signbit()
namespace Ice { namespace Ice {
namespace Utils {
/// Similar to bit_cast, but allows copying from types of unrelated sizes. This
/// method was introduced to enable the strict aliasing optimizations of GCC /// Allows copying from types of unrelated sizes. This method was introduced to
/// 4.4. Basically, GCC mindlessly relies on obscure details in the C++ standard /// enable the strict aliasing optimizations of GCC 4.4. Basically, GCC
/// that make reinterpret_cast virtually useless. /// mindlessly relies on obscure details in the C++ standard that make
template <class D, class S> inline D bit_copy(const S &source) { /// reinterpret_cast virtually useless.
D destination; template <typename D, typename S> inline D bitCopy(const S &Source) {
static_assert(sizeof(D) <= sizeof(S),
"bitCopy between incompatible type widths");
static_assert(!std::is_pointer<S>::value, "");
D Destination;
// This use of memcpy is safe: source and destination cannot overlap. // This use of memcpy is safe: source and destination cannot overlap.
memcpy(&destination, reinterpret_cast<const void *>(&source), memcpy(&Destination, reinterpret_cast<const void *>(&Source), sizeof(D));
sizeof(destination)); return Destination;
return destination; }
/// Check whether an N-bit two's-complement representation can hold value.
template <typename T> static inline bool IsInt(int N, T value) {
assert((0 < N) &&
(static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(value))));
T limit = static_cast<T>(1) << (N - 1);
return (-limit <= value) && (value < limit);
} }
class Utils { template <typename T> static inline bool IsUint(int N, T value) {
Utils() = delete; assert((0 < N) &&
Utils(const Utils &) = delete; (static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(value))));
Utils &operator=(const Utils &) = delete; T limit = static_cast<T>(1) << N;
return (0 <= value) && (value < limit);
public: }
/// Check whether an N-bit two's-complement representation can hold value.
template <typename T> static inline bool IsInt(int N, T value) { /// Check whether the magnitude of value fits in N bits, i.e., whether an
assert((0 < N) && /// (N+1)-bit sign-magnitude representation can hold value.
(static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(value)))); template <typename T> static inline bool IsAbsoluteUint(int N, T Value) {
T limit = static_cast<T>(1) << (N - 1); assert((0 < N) &&
return (-limit <= value) && (value < limit); (static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(Value))));
} if (Value < 0)
Value = -Value;
template <typename T> static inline bool IsUint(int N, T value) { return IsUint(N, Value);
assert((0 < N) && }
(static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(value))));
T limit = static_cast<T>(1) << N; /// Return true if the addition X + Y will cause integer overflow for integers
return (0 <= value) && (value < limit); /// of type T.
} template <typename T> static inline bool WouldOverflowAdd(T X, T Y) {
return ((X > 0 && Y > 0 && (X > std::numeric_limits<T>::max() - Y)) ||
/// Check whether the magnitude of value fits in N bits, i.e., whether an (X < 0 && Y < 0 && (X < std::numeric_limits<T>::min() - Y)));
/// (N+1)-bit sign-magnitude representation can hold value. }
template <typename T> static inline bool IsAbsoluteUint(int N, T Value) {
assert((0 < N) && /// Adds x to y and stores the result in sum. Returns true if the addition
(static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(Value)))); /// overflowed.
if (Value < 0) static inline bool add_overflow(uint32_t x, uint32_t y, uint32_t *sum) {
Value = -Value; static_assert(std::is_same<uint32_t, unsigned>::value, "Must match type");
return IsUint(N, Value);
}
/// Return true if the addition X + Y will cause integer overflow for integers
/// of type T.
template <typename T> static inline bool WouldOverflowAdd(T X, T Y) {
return ((X > 0 && Y > 0 && (X > std::numeric_limits<T>::max() - Y)) ||
(X < 0 && Y < 0 && (X < std::numeric_limits<T>::min() - Y)));
}
/// Adds x to y and stores the result in sum. Returns true if the addition
/// overflowed.
static inline bool add_overflow(uint32_t x, uint32_t y, uint32_t *sum) {
static_assert(std::is_same<uint32_t, unsigned>::value, "Must match type");
#if __has_builtin(__builtin_uadd_overflow) #if __has_builtin(__builtin_uadd_overflow)
return __builtin_uadd_overflow(x, y, sum); return __builtin_uadd_overflow(x, y, sum);
#else #else
*sum = x + y; *sum = x + y;
return WouldOverflowAdd(x, y); return WouldOverflowAdd(x, y);
#endif #endif
} }
/// Return true if X is already aligned by N, where N is a power of 2. /// Return true if X is already aligned by N, where N is a power of 2.
template <typename T> static inline bool IsAligned(T X, intptr_t N) { template <typename T> static inline bool IsAligned(T X, intptr_t N) {
assert(llvm::isPowerOf2_64(N)); assert(llvm::isPowerOf2_64(N));
return (X & (N - 1)) == 0; return (X & (N - 1)) == 0;
} }
/// Return Value adjusted to the next highest multiple of Alignment. /// Return Value adjusted to the next highest multiple of Alignment.
static inline uint32_t applyAlignment(uint32_t Value, uint32_t Alignment) { static inline uint32_t applyAlignment(uint32_t Value, uint32_t Alignment) {
assert(llvm::isPowerOf2_32(Alignment)); assert(llvm::isPowerOf2_32(Alignment));
return (Value + Alignment - 1) & -Alignment; return (Value + Alignment - 1) & -Alignment;
} }
/// Return amount which must be added to adjust Pos to the next highest /// Return amount which must be added to adjust Pos to the next highest
/// multiple of Align. /// multiple of Align.
static inline uint64_t OffsetToAlignment(uint64_t Pos, uint64_t Align) { static inline uint64_t OffsetToAlignment(uint64_t Pos, uint64_t Align) {
assert(llvm::isPowerOf2_64(Align)); assert(llvm::isPowerOf2_64(Align));
uint64_t Mod = Pos & (Align - 1); uint64_t Mod = Pos & (Align - 1);
if (Mod == 0) if (Mod == 0)
return 0; return 0;
return Align - Mod; return Align - Mod;
} }
/// Rotate the value bit pattern to the left by shift bits. /// Rotate the value bit pattern to the left by shift bits.
/// Precondition: 0 <= shift < 32 /// Precondition: 0 <= shift < 32
static inline uint32_t rotateLeft32(uint32_t value, uint32_t shift) { static inline uint32_t rotateLeft32(uint32_t value, uint32_t shift) {
if (shift == 0) if (shift == 0)
return value; return value;
return (value << shift) | (value >> (32 - shift)); return (value << shift) | (value >> (32 - shift));
} }
/// Rotate the value bit pattern to the right by shift bits. /// Rotate the value bit pattern to the right by shift bits.
static inline uint32_t rotateRight32(uint32_t value, uint32_t shift) { static inline uint32_t rotateRight32(uint32_t value, uint32_t shift) {
if (shift == 0) if (shift == 0)
return value; return value;
return (value >> shift) | (value << (32 - shift)); return (value >> shift) | (value << (32 - shift));
} }
/// Returns true if Val is +0.0. It requires T to be a floating point type. /// Returns true if Val is +0.0. It requires T to be a floating point type.
template <typename T> static bool isPositiveZero(T Val) { template <typename T> static bool isPositiveZero(T Val) {
static_assert(std::is_floating_point<T>::value, static_assert(std::is_floating_point<T>::value,
"Input type must be floating point"); "Input type must be floating point");
return Val == 0 && !std::signbit(Val); return Val == 0 && !std::signbit(Val);
} }
};
} // end of namespace Utils
} // end of namespace Ice } // end of namespace Ice
#endif // SUBZERO_SRC_ICEUTILS_H #endif // SUBZERO_SRC_ICEUTILS_H
...@@ -23,8 +23,11 @@ ...@@ -23,8 +23,11 @@
#include "IceInst.h" #include "IceInst.h"
#include "IceOperand.h" #include "IceOperand.h"
#ifdef __clang__
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter" #pragma clang diagnostic ignored "-Wunused-parameter"
#endif // __clang__
#include "llvm/ADT/Hashing.h" #include "llvm/ADT/Hashing.h"
#include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallString.h"
#include "llvm/Bitcode/NaCl/NaClBitcodeDecoders.h" #include "llvm/Bitcode/NaCl/NaClBitcodeDecoders.h"
...@@ -35,8 +38,12 @@ ...@@ -35,8 +38,12 @@
#include "llvm/Support/Format.h" #include "llvm/Support/Format.h"
#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include <unordered_set>
#ifdef __clang__
#pragma clang diagnostic pop #pragma clang diagnostic pop
#endif // __clang__
#include <unordered_set>
// Define a hash function for SmallString's, so that it can be used in hash // Define a hash function for SmallString's, so that it can be used in hash
// tables. // tables.
...@@ -190,7 +197,7 @@ public: ...@@ -190,7 +197,7 @@ public:
"IntType and FpType should be the same width"); "IntType and FpType should be the same width");
assert(BitWidth == sizeof(IntType) * CHAR_BIT); assert(BitWidth == sizeof(IntType) * CHAR_BIT);
auto V = static_cast<IntType>(Val); auto V = static_cast<IntType>(Val);
return reinterpret_cast<FpType &>(V); return Ice::Utils::bitCopy<FpType>(V);
} }
private: private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment