Commit d2cb4361 by Jim Stichnoth

Subzero: Simplify the constant pools.

Internally, create a separate constant pool for each integer type, instead of a single i64 pool that uses the Ice::Type value as part of the key. This means each constant pool key can be a simple primitive value, rather than a tuple. Represent the pools using std::unordered_map instead of std::map since we're using C++11 now. Use signed integers instead of unsigned integers for the integer constant pools, to benefit from sign extension and to be more consistent. Remove the SuppressMangling field from hash and comparison functions on RelocatableTuple, since we'll never have two symbols with the same name but different values of SuppressMangling. BUG= none R=jvoung@chromium.org Review URL: https://codereview.chromium.org/737513008
parent 144a393b
...@@ -116,16 +116,11 @@ public: ...@@ -116,16 +116,11 @@ public:
if (const auto GV = dyn_cast<GlobalValue>(Const)) { if (const auto GV = dyn_cast<GlobalValue>(Const)) {
Ice::GlobalDeclaration *Decl = getConverter().getGlobalDeclaration(GV); Ice::GlobalDeclaration *Decl = getConverter().getGlobalDeclaration(GV);
const Ice::RelocOffsetT Offset = 0; const Ice::RelocOffsetT Offset = 0;
return Ctx->getConstantSym(TypeConverter.getIcePointerType(), return Ctx->getConstantSym(Offset, Decl->getName(),
Offset, Decl->getName(),
Decl->getSuppressMangling()); Decl->getSuppressMangling());
} else if (const auto CI = dyn_cast<ConstantInt>(Const)) { } else if (const auto CI = dyn_cast<ConstantInt>(Const)) {
Ice::Type Ty = convertToIceType(CI->getType()); Ice::Type Ty = convertToIceType(CI->getType());
if (Ty == Ice::IceType_i64) { return Ctx->getConstantInt(Ty, CI->getSExtValue());
return Ctx->getConstantInt64(Ty, CI->getSExtValue());
} else {
return Ctx->getConstantInt32(Ty, CI->getSExtValue());
}
} else if (const auto CFP = dyn_cast<ConstantFP>(Const)) { } else if (const auto CFP = dyn_cast<ConstantFP>(Const)) {
Ice::Type Type = convertToIceType(CFP->getType()); Ice::Type Type = convertToIceType(CFP->getType());
if (Type == Ice::IceType_f32) if (Type == Ice::IceType_f32)
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <ctype.h> // isdigit(), isupper() #include <ctype.h> // isdigit(), isupper()
#include <locale> // locale #include <locale> // locale
#include <unordered_map>
#include "IceCfg.h" #include "IceCfg.h"
#include "IceClFlags.h" #include "IceClFlags.h"
...@@ -25,29 +26,29 @@ ...@@ -25,29 +26,29 @@
#include "IceTimerTree.h" #include "IceTimerTree.h"
#include "IceTypes.h" #include "IceTypes.h"
template <> struct std::hash<Ice::RelocatableTuple> {
std::size_t operator()(const Ice::RelocatableTuple &Key) const {
return std::hash<Ice::IceString>()(Key.Name) +
std::hash<Ice::RelocOffsetT>()(Key.Offset);
}
};
namespace Ice { namespace Ice {
// TypePool maps constants of type KeyType (e.g. float) to pointers to // TypePool maps constants of type KeyType (e.g. float) to pointers to
// type ValueType (e.g. ConstantFloat). KeyType values are compared // type ValueType (e.g. ConstantFloat).
// using memcmp() because of potential NaN values in KeyType values. template <Type Ty, typename KeyType, typename ValueType> class TypePool {
// KeyTypeHasFP indicates whether KeyType is a floating-point type
// whose values need to be compared using memcmp() for NaN
// correctness. TODO: use std::is_floating_point<KeyType> instead of
// KeyTypeHasFP with C++11.
template <typename KeyType, typename ValueType, bool KeyTypeHasFP = false>
class TypePool {
TypePool(const TypePool &) = delete; TypePool(const TypePool &) = delete;
TypePool &operator=(const TypePool &) = delete; TypePool &operator=(const TypePool &) = delete;
public: public:
TypePool() : NextPoolID(0) {} TypePool() : NextPoolID(0) {}
ValueType *getOrAdd(GlobalContext *Ctx, Type Ty, KeyType Key) { ValueType *getOrAdd(GlobalContext *Ctx, KeyType Key) {
TupleType TupleKey = std::make_pair(Ty, Key); auto Iter = Pool.find(Key);
auto Iter = Pool.find(TupleKey);
if (Iter != Pool.end()) if (Iter != Pool.end())
return Iter->second; return Iter->second;
ValueType *Result = ValueType::create(Ctx, Ty, Key, NextPoolID++); ValueType *Result = ValueType::create(Ctx, Ty, Key, NextPoolID++);
Pool[TupleKey] = Result; Pool[Key] = Result;
return Result; return Result;
} }
ConstantList getConstantPool() const { ConstantList getConstantPool() const {
...@@ -59,17 +60,7 @@ public: ...@@ -59,17 +60,7 @@ public:
} }
private: private:
typedef std::pair<Type, KeyType> TupleType; typedef std::unordered_map<KeyType, ValueType *> ContainerType;
struct TupleCompare {
bool operator()(const TupleType &A, const TupleType &B) const {
if (A.first != B.first)
return A.first < B.first;
if (KeyTypeHasFP)
return memcmp(&A.second, &B.second, sizeof(KeyType)) < 0;
return A.second < B.second;
}
};
typedef std::map<const TupleType, ValueType *, TupleCompare> ContainerType;
ContainerType Pool; ContainerType Pool;
uint32_t NextPoolID; uint32_t NextPoolID;
}; };
...@@ -80,21 +71,17 @@ class UndefPool { ...@@ -80,21 +71,17 @@ class UndefPool {
UndefPool &operator=(const UndefPool &) = delete; UndefPool &operator=(const UndefPool &) = delete;
public: public:
UndefPool() : NextPoolID(0) {} UndefPool() : NextPoolID(0), Pool(IceType_NUM) {}
ConstantUndef *getOrAdd(GlobalContext *Ctx, Type Ty) { ConstantUndef *getOrAdd(GlobalContext *Ctx, Type Ty) {
auto I = Pool.find(Ty); if (Pool[Ty] == NULL)
if (I != Pool.end()) Pool[Ty] = ConstantUndef::create(Ctx, Ty, NextPoolID++);
return I->second; return Pool[Ty];
ConstantUndef *Undef = ConstantUndef::create(Ctx, Ty, NextPoolID++);
Pool[Ty] = Undef;
return Undef;
} }
private: private:
uint32_t NextPoolID; uint32_t NextPoolID;
typedef std::map<Type, ConstantUndef *> ContainerType; std::vector<ConstantUndef *> Pool;
ContainerType Pool;
}; };
// The global constant pool bundles individual pools of each type of // The global constant pool bundles individual pools of each type of
...@@ -105,11 +92,14 @@ class ConstantPool { ...@@ -105,11 +92,14 @@ class ConstantPool {
public: public:
ConstantPool() {} ConstantPool() {}
TypePool<float, ConstantFloat, true> Floats; TypePool<IceType_f32, float, ConstantFloat> Floats;
TypePool<double, ConstantDouble, true> Doubles; TypePool<IceType_f64, double, ConstantDouble> Doubles;
TypePool<uint32_t, ConstantInteger32> Integers32; TypePool<IceType_i1, int8_t, ConstantInteger32> Integers1;
TypePool<uint64_t, ConstantInteger64> Integers64; TypePool<IceType_i8, int8_t, ConstantInteger32> Integers8;
TypePool<RelocatableTuple, ConstantRelocatable> Relocatables; TypePool<IceType_i16, int16_t, ConstantInteger32> Integers16;
TypePool<IceType_i32, int32_t, ConstantInteger32> Integers32;
TypePool<IceType_i64, int64_t, ConstantInteger64> Integers64;
TypePool<IceType_i32, RelocatableTuple, ConstantRelocatable> Relocatables;
UndefPool Undefs; UndefPool Undefs;
}; };
...@@ -294,30 +284,58 @@ GlobalContext::~GlobalContext() { ...@@ -294,30 +284,58 @@ GlobalContext::~GlobalContext() {
llvm::DeleteContainerPointers(GlobalDeclarations); llvm::DeleteContainerPointers(GlobalDeclarations);
} }
Constant *GlobalContext::getConstantInt64(Type Ty, uint64_t ConstantInt64) { Constant *GlobalContext::getConstantInt(Type Ty, int64_t Value) {
assert(Ty == IceType_i64); switch (Ty) {
return ConstPool->Integers64.getOrAdd(this, Ty, ConstantInt64); case IceType_i1:
return getConstantInt1(Value);
case IceType_i8:
return getConstantInt8(Value);
case IceType_i16:
return getConstantInt16(Value);
case IceType_i32:
return getConstantInt32(Value);
case IceType_i64:
return getConstantInt64(Value);
default:
llvm_unreachable("Bad integer type for getConstant");
}
return NULL;
}
Constant *GlobalContext::getConstantInt1(int8_t ConstantInt1) {
ConstantInt1 &= INT8_C(1);
return ConstPool->Integers1.getOrAdd(this, ConstantInt1);
}
Constant *GlobalContext::getConstantInt8(int8_t ConstantInt8) {
return ConstPool->Integers8.getOrAdd(this, ConstantInt8);
}
Constant *GlobalContext::getConstantInt16(int16_t ConstantInt16) {
return ConstPool->Integers16.getOrAdd(this, ConstantInt16);
}
Constant *GlobalContext::getConstantInt32(int32_t ConstantInt32) {
return ConstPool->Integers32.getOrAdd(this, ConstantInt32);
} }
Constant *GlobalContext::getConstantInt32(Type Ty, uint32_t ConstantInt32) { Constant *GlobalContext::getConstantInt64(int64_t ConstantInt64) {
if (Ty == IceType_i1) return ConstPool->Integers64.getOrAdd(this, ConstantInt64);
ConstantInt32 &= UINT32_C(1);
return ConstPool->Integers32.getOrAdd(this, Ty, ConstantInt32);
} }
Constant *GlobalContext::getConstantFloat(float ConstantFloat) { Constant *GlobalContext::getConstantFloat(float ConstantFloat) {
return ConstPool->Floats.getOrAdd(this, IceType_f32, ConstantFloat); return ConstPool->Floats.getOrAdd(this, ConstantFloat);
} }
Constant *GlobalContext::getConstantDouble(double ConstantDouble) { Constant *GlobalContext::getConstantDouble(double ConstantDouble) {
return ConstPool->Doubles.getOrAdd(this, IceType_f64, ConstantDouble); return ConstPool->Doubles.getOrAdd(this, ConstantDouble);
} }
Constant *GlobalContext::getConstantSym(Type Ty, RelocOffsetT Offset, Constant *GlobalContext::getConstantSym(RelocOffsetT Offset,
const IceString &Name, const IceString &Name,
bool SuppressMangling) { bool SuppressMangling) {
return ConstPool->Relocatables.getOrAdd( return ConstPool->Relocatables.getOrAdd(
this, Ty, RelocatableTuple(Offset, Name, SuppressMangling)); this, RelocatableTuple(Offset, Name, SuppressMangling));
} }
Constant *GlobalContext::getConstantUndef(Type Ty) { Constant *GlobalContext::getConstantUndef(Type Ty) {
...@@ -327,12 +345,15 @@ Constant *GlobalContext::getConstantUndef(Type Ty) { ...@@ -327,12 +345,15 @@ Constant *GlobalContext::getConstantUndef(Type Ty) {
Constant *GlobalContext::getConstantZero(Type Ty) { Constant *GlobalContext::getConstantZero(Type Ty) {
switch (Ty) { switch (Ty) {
case IceType_i1: case IceType_i1:
return getConstantInt1(0);
case IceType_i8: case IceType_i8:
return getConstantInt8(0);
case IceType_i16: case IceType_i16:
return getConstantInt16(0);
case IceType_i32: case IceType_i32:
return getConstantInt32(Ty, 0); return getConstantInt32(0);
case IceType_i64: case IceType_i64:
return getConstantInt64(Ty, 0); return getConstantInt64(0);
case IceType_f32: case IceType_f32:
return getConstantFloat(0); return getConstantFloat(0);
case IceType_f64: case IceType_f64:
......
...@@ -113,14 +113,17 @@ public: ...@@ -113,14 +113,17 @@ public:
// Manage Constants. // Manage Constants.
// getConstant*() functions are not const because they might add // getConstant*() functions are not const because they might add
// something to the constant pool. // something to the constant pool.
Constant *getConstantInt32(Type Ty, uint32_t ConstantInt32); Constant *getConstantInt(Type Ty, int64_t Value);
Constant *getConstantInt64(Type Ty, uint64_t ConstantInt64); Constant *getConstantInt1(int8_t ConstantInt1);
Constant *getConstantInt8(int8_t ConstantInt8);
Constant *getConstantInt16(int16_t ConstantInt16);
Constant *getConstantInt32(int32_t ConstantInt32);
Constant *getConstantInt64(int64_t ConstantInt64);
Constant *getConstantFloat(float Value); Constant *getConstantFloat(float Value);
Constant *getConstantDouble(double Value); Constant *getConstantDouble(double Value);
// Returns a symbolic constant. // Returns a symbolic constant.
Constant *getConstantSym(Type Ty, RelocOffsetT Offset, Constant *getConstantSym(RelocOffsetT Offset, const IceString &Name,
const IceString &Name = "", bool SuppressMangling);
bool SuppressMangling = false);
// Returns an undef. // Returns an undef.
Constant *getConstantUndef(Type Ty); Constant *getConstantUndef(Type Ty);
// Returns a zero value. // Returns a zero value.
......
...@@ -20,12 +20,8 @@ ...@@ -20,12 +20,8 @@
namespace Ice { namespace Ice {
bool operator<(const RelocatableTuple &A, const RelocatableTuple &B) { bool operator==(const RelocatableTuple &A, const RelocatableTuple &B) {
if (A.Offset != B.Offset) return A.Offset == B.Offset && A.Name == B.Name;
return A.Offset < B.Offset;
if (A.SuppressMangling != B.SuppressMangling)
return A.SuppressMangling < B.SuppressMangling;
return A.Name < B.Name;
} }
bool operator<(const RegWeight &A, const RegWeight &B) { bool operator<(const RegWeight &A, const RegWeight &B) {
......
...@@ -169,8 +169,8 @@ private: ...@@ -169,8 +169,8 @@ private:
const T Value; const T Value;
}; };
typedef ConstantPrimitive<uint32_t, Operand::kConstInteger32> ConstantInteger32; typedef ConstantPrimitive<int32_t, Operand::kConstInteger32> ConstantInteger32;
typedef ConstantPrimitive<uint64_t, Operand::kConstInteger64> ConstantInteger64; typedef ConstantPrimitive<int64_t, Operand::kConstInteger64> ConstantInteger64;
typedef ConstantPrimitive<float, Operand::kConstFloat> ConstantFloat; typedef ConstantPrimitive<float, Operand::kConstFloat> ConstantFloat;
typedef ConstantPrimitive<double, Operand::kConstDouble> ConstantDouble; typedef ConstantPrimitive<double, Operand::kConstDouble> ConstantDouble;
...@@ -195,20 +195,20 @@ template <> inline void ConstantInteger64::dump(const Cfg *, Ostream &Str) const ...@@ -195,20 +195,20 @@ template <> inline void ConstantInteger64::dump(const Cfg *, Ostream &Str) const
// ConstantRelocatable can fit into the global constant pool // ConstantRelocatable can fit into the global constant pool
// template mechanism. // template mechanism.
class RelocatableTuple { class RelocatableTuple {
// RelocatableTuple(const RelocatableTuple &) = delete;
RelocatableTuple &operator=(const RelocatableTuple &) = delete; RelocatableTuple &operator=(const RelocatableTuple &) = delete;
public: public:
RelocatableTuple(const RelocOffsetT Offset, const IceString &Name, RelocatableTuple(const RelocOffsetT Offset, const IceString &Name,
bool SuppressMangling) bool SuppressMangling)
: Offset(Offset), Name(Name), SuppressMangling(SuppressMangling) {} : Offset(Offset), Name(Name), SuppressMangling(SuppressMangling) {}
RelocatableTuple(const RelocatableTuple &) = default;
const RelocOffsetT Offset; const RelocOffsetT Offset;
const IceString Name; const IceString Name;
bool SuppressMangling; bool SuppressMangling;
}; };
bool operator<(const RelocatableTuple &A, const RelocatableTuple &B); bool operator==(const RelocatableTuple &A, const RelocatableTuple &B);
// ConstantRelocatable represents a symbolic constant combined with // ConstantRelocatable represents a symbolic constant combined with
// a fixed offset. // a fixed offset.
......
...@@ -618,8 +618,7 @@ void TargetX8632::finishArgumentLowering(Variable *Arg, Variable *FramePtr, ...@@ -618,8 +618,7 @@ void TargetX8632::finishArgumentLowering(Variable *Arg, Variable *FramePtr,
if (Arg->hasReg()) { if (Arg->hasReg()) {
assert(Ty != IceType_i64); assert(Ty != IceType_i64);
OperandX8632Mem *Mem = OperandX8632Mem::create( OperandX8632Mem *Mem = OperandX8632Mem::create(
Func, Ty, FramePtr, Func, Ty, FramePtr, Ctx->getConstantInt32(Arg->getStackOffset()));
Ctx->getConstantInt32(IceType_i32, Arg->getStackOffset()));
if (isVectorType(Arg->getType())) { if (isVectorType(Arg->getType())) {
_movp(Arg, Mem); _movp(Arg, Mem);
} else { } else {
...@@ -839,7 +838,7 @@ void TargetX8632::addProlog(CfgNode *Node) { ...@@ -839,7 +838,7 @@ void TargetX8632::addProlog(CfgNode *Node) {
// Generate "sub esp, SpillAreaSizeBytes" // Generate "sub esp, SpillAreaSizeBytes"
if (SpillAreaSizeBytes) if (SpillAreaSizeBytes)
_sub(getPhysicalRegister(RegX8632::Reg_esp), _sub(getPhysicalRegister(RegX8632::Reg_esp),
Ctx->getConstantInt32(IceType_i32, SpillAreaSizeBytes)); Ctx->getConstantInt32(SpillAreaSizeBytes));
Ctx->statsUpdateFrameBytes(SpillAreaSizeBytes); Ctx->statsUpdateFrameBytes(SpillAreaSizeBytes);
resetStackAdjustment(); resetStackAdjustment();
...@@ -951,7 +950,7 @@ void TargetX8632::addEpilog(CfgNode *Node) { ...@@ -951,7 +950,7 @@ void TargetX8632::addEpilog(CfgNode *Node) {
} else { } else {
// add esp, SpillAreaSizeBytes // add esp, SpillAreaSizeBytes
if (SpillAreaSizeBytes) if (SpillAreaSizeBytes)
_add(esp, Ctx->getConstantInt32(IceType_i32, SpillAreaSizeBytes)); _add(esp, Ctx->getConstantInt32(SpillAreaSizeBytes));
} }
// Add pop instructions for preserved registers. // Add pop instructions for preserved registers.
...@@ -1069,8 +1068,7 @@ Operand *TargetX8632::loOperand(Operand *Operand) { ...@@ -1069,8 +1068,7 @@ Operand *TargetX8632::loOperand(Operand *Operand) {
return Var->getLo(); return Var->getLo();
} }
if (ConstantInteger64 *Const = llvm::dyn_cast<ConstantInteger64>(Operand)) { if (ConstantInteger64 *Const = llvm::dyn_cast<ConstantInteger64>(Operand)) {
return Ctx->getConstantInt32(IceType_i32, return Ctx->getConstantInt32(static_cast<uint32_t>(Const->getValue()));
static_cast<uint32_t>(Const->getValue()));
} }
if (OperandX8632Mem *Mem = llvm::dyn_cast<OperandX8632Mem>(Operand)) { if (OperandX8632Mem *Mem = llvm::dyn_cast<OperandX8632Mem>(Operand)) {
return OperandX8632Mem::create(Func, IceType_i32, Mem->getBase(), return OperandX8632Mem::create(Func, IceType_i32, Mem->getBase(),
...@@ -1091,20 +1089,21 @@ Operand *TargetX8632::hiOperand(Operand *Operand) { ...@@ -1091,20 +1089,21 @@ Operand *TargetX8632::hiOperand(Operand *Operand) {
} }
if (ConstantInteger64 *Const = llvm::dyn_cast<ConstantInteger64>(Operand)) { if (ConstantInteger64 *Const = llvm::dyn_cast<ConstantInteger64>(Operand)) {
return Ctx->getConstantInt32( return Ctx->getConstantInt32(
IceType_i32, static_cast<uint32_t>(Const->getValue() >> 32)); static_cast<uint32_t>(Const->getValue() >> 32));
} }
if (OperandX8632Mem *Mem = llvm::dyn_cast<OperandX8632Mem>(Operand)) { if (OperandX8632Mem *Mem = llvm::dyn_cast<OperandX8632Mem>(Operand)) {
Constant *Offset = Mem->getOffset(); Constant *Offset = Mem->getOffset();
if (Offset == NULL) if (Offset == NULL) {
Offset = Ctx->getConstantInt32(IceType_i32, 4); Offset = Ctx->getConstantInt32(4);
else if (ConstantInteger32 *IntOffset = } else if (ConstantInteger32 *IntOffset =
llvm::dyn_cast<ConstantInteger32>(Offset)) { llvm::dyn_cast<ConstantInteger32>(Offset)) {
Offset = Ctx->getConstantInt32(IceType_i32, 4 + IntOffset->getValue()); Offset = Ctx->getConstantInt32(4 + IntOffset->getValue());
} else if (ConstantRelocatable *SymOffset = } else if (ConstantRelocatable *SymOffset =
llvm::dyn_cast<ConstantRelocatable>(Offset)) { llvm::dyn_cast<ConstantRelocatable>(Offset)) {
assert(!Utils::WouldOverflowAdd(SymOffset->getOffset(), 4)); assert(!Utils::WouldOverflowAdd(SymOffset->getOffset(), 4));
Offset = Ctx->getConstantSym(IceType_i32, 4 + SymOffset->getOffset(), Offset =
SymOffset->getName()); Ctx->getConstantSym(4 + SymOffset->getOffset(), SymOffset->getName(),
SymOffset->getSuppressMangling());
} }
return OperandX8632Mem::create(Func, IceType_i32, Mem->getBase(), Offset, return OperandX8632Mem::create(Func, IceType_i32, Mem->getBase(), Offset,
Mem->getIndex(), Mem->getShift(), Mem->getIndex(), Mem->getShift(),
...@@ -1168,20 +1167,20 @@ void TargetX8632::lowerAlloca(const InstAlloca *Inst) { ...@@ -1168,20 +1167,20 @@ void TargetX8632::lowerAlloca(const InstAlloca *Inst) {
uint32_t Alignment = std::max(AlignmentParam, X86_STACK_ALIGNMENT_BYTES); uint32_t Alignment = std::max(AlignmentParam, X86_STACK_ALIGNMENT_BYTES);
if (Alignment > X86_STACK_ALIGNMENT_BYTES) { if (Alignment > X86_STACK_ALIGNMENT_BYTES) {
_and(esp, Ctx->getConstantInt32(IceType_i32, -Alignment)); _and(esp, Ctx->getConstantInt32(-Alignment));
} }
if (ConstantInteger32 *ConstantTotalSize = if (ConstantInteger32 *ConstantTotalSize =
llvm::dyn_cast<ConstantInteger32>(TotalSize)) { llvm::dyn_cast<ConstantInteger32>(TotalSize)) {
uint32_t Value = ConstantTotalSize->getValue(); uint32_t Value = ConstantTotalSize->getValue();
Value = applyAlignment(Value, Alignment); Value = applyAlignment(Value, Alignment);
_sub(esp, Ctx->getConstantInt32(IceType_i32, Value)); _sub(esp, Ctx->getConstantInt32(Value));
} else { } else {
// Non-constant sizes need to be adjusted to the next highest // Non-constant sizes need to be adjusted to the next highest
// multiple of the required alignment at runtime. // multiple of the required alignment at runtime.
Variable *T = makeReg(IceType_i32); Variable *T = makeReg(IceType_i32);
_mov(T, TotalSize); _mov(T, TotalSize);
_add(T, Ctx->getConstantInt32(IceType_i32, Alignment - 1)); _add(T, Ctx->getConstantInt32(Alignment - 1));
_and(T, Ctx->getConstantInt32(IceType_i32, -Alignment)); _and(T, Ctx->getConstantInt32(-Alignment));
_sub(esp, T); _sub(esp, T);
} }
_mov(Dest, esp); _mov(Dest, esp);
...@@ -1291,7 +1290,7 @@ void TargetX8632::lowerArithmetic(const InstArithmetic *Inst) { ...@@ -1291,7 +1290,7 @@ void TargetX8632::lowerArithmetic(const InstArithmetic *Inst) {
// a.lo = t2 // a.lo = t2
// a.hi = t3 // a.hi = t3
Variable *T_1 = NULL, *T_2 = NULL, *T_3 = NULL; Variable *T_1 = NULL, *T_2 = NULL, *T_3 = NULL;
Constant *BitTest = Ctx->getConstantInt32(IceType_i32, 0x20); Constant *BitTest = Ctx->getConstantInt32(0x20);
Constant *Zero = Ctx->getConstantZero(IceType_i32); Constant *Zero = Ctx->getConstantZero(IceType_i32);
InstX8632Label *Label = InstX8632Label::create(Func, this); InstX8632Label *Label = InstX8632Label::create(Func, this);
_mov(T_1, Src1Lo, RegX8632::Reg_ecx); _mov(T_1, Src1Lo, RegX8632::Reg_ecx);
...@@ -1326,7 +1325,7 @@ void TargetX8632::lowerArithmetic(const InstArithmetic *Inst) { ...@@ -1326,7 +1325,7 @@ void TargetX8632::lowerArithmetic(const InstArithmetic *Inst) {
// a.lo = t2 // a.lo = t2
// a.hi = t3 // a.hi = t3
Variable *T_1 = NULL, *T_2 = NULL, *T_3 = NULL; Variable *T_1 = NULL, *T_2 = NULL, *T_3 = NULL;
Constant *BitTest = Ctx->getConstantInt32(IceType_i32, 0x20); Constant *BitTest = Ctx->getConstantInt32(0x20);
Constant *Zero = Ctx->getConstantZero(IceType_i32); Constant *Zero = Ctx->getConstantZero(IceType_i32);
InstX8632Label *Label = InstX8632Label::create(Func, this); InstX8632Label *Label = InstX8632Label::create(Func, this);
_mov(T_1, Src1Lo, RegX8632::Reg_ecx); _mov(T_1, Src1Lo, RegX8632::Reg_ecx);
...@@ -1361,8 +1360,8 @@ void TargetX8632::lowerArithmetic(const InstArithmetic *Inst) { ...@@ -1361,8 +1360,8 @@ void TargetX8632::lowerArithmetic(const InstArithmetic *Inst) {
// a.lo = t2 // a.lo = t2
// a.hi = t3 // a.hi = t3
Variable *T_1 = NULL, *T_2 = NULL, *T_3 = NULL; Variable *T_1 = NULL, *T_2 = NULL, *T_3 = NULL;
Constant *BitTest = Ctx->getConstantInt32(IceType_i32, 0x20); Constant *BitTest = Ctx->getConstantInt32(0x20);
Constant *SignExtend = Ctx->getConstantInt32(IceType_i32, 0x1f); Constant *SignExtend = Ctx->getConstantInt32(0x1f);
InstX8632Label *Label = InstX8632Label::create(Func, this); InstX8632Label *Label = InstX8632Label::create(Func, this);
_mov(T_1, Src1Lo, RegX8632::Reg_ecx); _mov(T_1, Src1Lo, RegX8632::Reg_ecx);
_mov(T_2, Src0Lo); _mov(T_2, Src0Lo);
...@@ -1483,7 +1482,7 @@ void TargetX8632::lowerArithmetic(const InstArithmetic *Inst) { ...@@ -1483,7 +1482,7 @@ void TargetX8632::lowerArithmetic(const InstArithmetic *Inst) {
// Mask that directs pshufd to create a vector with entries // Mask that directs pshufd to create a vector with entries
// Src[1, 0, 3, 0] // Src[1, 0, 3, 0]
const unsigned Constant1030 = 0x31; const unsigned Constant1030 = 0x31;
Constant *Mask1030 = Ctx->getConstantInt32(IceType_i8, Constant1030); Constant *Mask1030 = Ctx->getConstantInt32(Constant1030);
// Mask that directs shufps to create a vector with entries // Mask that directs shufps to create a vector with entries
// Dest[0, 2], Src[0, 2] // Dest[0, 2], Src[0, 2]
const unsigned Mask0202 = 0x88; const unsigned Mask0202 = 0x88;
...@@ -1499,8 +1498,8 @@ void TargetX8632::lowerArithmetic(const InstArithmetic *Inst) { ...@@ -1499,8 +1498,8 @@ void TargetX8632::lowerArithmetic(const InstArithmetic *Inst) {
_pshufd(T3, Src1, Mask1030); _pshufd(T3, Src1, Mask1030);
_pmuludq(T1, Src1); _pmuludq(T1, Src1);
_pmuludq(T2, T3); _pmuludq(T2, T3);
_shufps(T1, T2, Ctx->getConstantInt32(IceType_i8, Mask0202)); _shufps(T1, T2, Ctx->getConstantInt32(Mask0202));
_pshufd(T4, T1, Ctx->getConstantInt32(IceType_i8, Mask0213)); _pshufd(T4, T1, Ctx->getConstantInt32(Mask0213));
_movp(Dest, T4); _movp(Dest, T4);
} else { } else {
assert(Dest->getType() == IceType_v16i8); assert(Dest->getType() == IceType_v16i8);
...@@ -1795,8 +1794,7 @@ void TargetX8632::lowerCall(const InstCall *Instr) { ...@@ -1795,8 +1794,7 @@ void TargetX8632::lowerCall(const InstCall *Instr) {
ParameterAreaSizeBytes = applyStackAlignment(ParameterAreaSizeBytes); ParameterAreaSizeBytes = applyStackAlignment(ParameterAreaSizeBytes);
} }
Variable *esp = Func->getTarget()->getPhysicalRegister(RegX8632::Reg_esp); Variable *esp = Func->getTarget()->getPhysicalRegister(RegX8632::Reg_esp);
Constant *Loc = Constant *Loc = Ctx->getConstantInt32(ParameterAreaSizeBytes);
Ctx->getConstantInt32(IceType_i32, ParameterAreaSizeBytes);
StackArgLocations.push_back(OperandX8632Mem::create(Func, Ty, esp, Loc)); StackArgLocations.push_back(OperandX8632Mem::create(Func, Ty, esp, Loc));
ParameterAreaSizeBytes += typeWidthInBytesOnStack(Arg->getType()); ParameterAreaSizeBytes += typeWidthInBytesOnStack(Arg->getType());
} }
...@@ -1888,7 +1886,7 @@ void TargetX8632::lowerCall(const InstCall *Instr) { ...@@ -1888,7 +1886,7 @@ void TargetX8632::lowerCall(const InstCall *Instr) {
// of resetting the stack offset during emission. // of resetting the stack offset during emission.
if (ParameterAreaSizeBytes) { if (ParameterAreaSizeBytes) {
Variable *esp = Func->getTarget()->getPhysicalRegister(RegX8632::Reg_esp); Variable *esp = Func->getTarget()->getPhysicalRegister(RegX8632::Reg_esp);
_add(esp, Ctx->getConstantInt32(IceType_i32, ParameterAreaSizeBytes)); _add(esp, Ctx->getConstantInt32(ParameterAreaSizeBytes));
} }
// Insert a register-kill pseudo instruction. // Insert a register-kill pseudo instruction.
...@@ -1965,8 +1963,7 @@ void TargetX8632::lowerCast(const InstCast *Inst) { ...@@ -1965,8 +1963,7 @@ void TargetX8632::lowerCast(const InstCast *Inst) {
// width = width(elty) - 1; dest = (src << width) >> width // width = width(elty) - 1; dest = (src << width) >> width
SizeT ShiftAmount = SizeT ShiftAmount =
X86_CHAR_BIT * typeWidthInBytes(typeElementType(DestTy)) - 1; X86_CHAR_BIT * typeWidthInBytes(typeElementType(DestTy)) - 1;
Constant *ShiftConstant = Constant *ShiftConstant = Ctx->getConstantInt8(ShiftAmount);
Ctx->getConstantInt32(IceType_i8, ShiftAmount);
Variable *T = makeReg(DestTy); Variable *T = makeReg(DestTy);
_movp(T, Src0RM); _movp(T, Src0RM);
_psll(T, ShiftConstant); _psll(T, ShiftConstant);
...@@ -1975,7 +1972,7 @@ void TargetX8632::lowerCast(const InstCast *Inst) { ...@@ -1975,7 +1972,7 @@ void TargetX8632::lowerCast(const InstCast *Inst) {
} }
} else if (Dest->getType() == IceType_i64) { } else if (Dest->getType() == IceType_i64) {
// t1=movsx src; t2=t1; t2=sar t2, 31; dst.lo=t1; dst.hi=t2 // t1=movsx src; t2=t1; t2=sar t2, 31; dst.lo=t1; dst.hi=t2
Constant *Shift = Ctx->getConstantInt32(IceType_i32, 31); Constant *Shift = Ctx->getConstantInt32(31);
Variable *DestLo = llvm::cast<Variable>(loOperand(Dest)); Variable *DestLo = llvm::cast<Variable>(loOperand(Dest));
Variable *DestHi = llvm::cast<Variable>(hiOperand(Dest)); Variable *DestHi = llvm::cast<Variable>(hiOperand(Dest));
Variable *T_Lo = makeReg(DestLo->getType()); Variable *T_Lo = makeReg(DestLo->getType());
...@@ -2001,7 +1998,7 @@ void TargetX8632::lowerCast(const InstCast *Inst) { ...@@ -2001,7 +1998,7 @@ void TargetX8632::lowerCast(const InstCast *Inst) {
// sar t1, dst_bitwidth - 1 // sar t1, dst_bitwidth - 1
// dst = t1 // dst = t1
size_t DestBits = X86_CHAR_BIT * typeWidthInBytes(Dest->getType()); size_t DestBits = X86_CHAR_BIT * typeWidthInBytes(Dest->getType());
Constant *ShiftAmount = Ctx->getConstantInt32(IceType_i32, DestBits - 1); Constant *ShiftAmount = Ctx->getConstantInt32(DestBits - 1);
Variable *T = makeReg(Dest->getType()); Variable *T = makeReg(Dest->getType());
if (typeWidthInBytes(Dest->getType()) <= if (typeWidthInBytes(Dest->getType()) <=
typeWidthInBytes(Src0RM->getType())) { typeWidthInBytes(Src0RM->getType())) {
...@@ -2044,14 +2041,14 @@ void TargetX8632::lowerCast(const InstCast *Inst) { ...@@ -2044,14 +2041,14 @@ void TargetX8632::lowerCast(const InstCast *Inst) {
_movzx(Tmp, Src0RM); _movzx(Tmp, Src0RM);
} }
if (Src0RM->getType() == IceType_i1) { if (Src0RM->getType() == IceType_i1) {
Constant *One = Ctx->getConstantInt32(IceType_i32, 1); Constant *One = Ctx->getConstantInt32(1);
_and(Tmp, One); _and(Tmp, One);
} }
_mov(DestLo, Tmp); _mov(DestLo, Tmp);
_mov(DestHi, Zero); _mov(DestHi, Zero);
} else if (Src0RM->getType() == IceType_i1) { } else if (Src0RM->getType() == IceType_i1) {
// t = Src0RM; t &= 1; Dest = t // t = Src0RM; t &= 1; Dest = t
Constant *One = Ctx->getConstantInt32(IceType_i32, 1); Constant *One = Ctx->getConstantInt32(1);
Type DestTy = Dest->getType(); Type DestTy = Dest->getType();
Variable *T; Variable *T;
if (DestTy == IceType_i8) { if (DestTy == IceType_i8) {
...@@ -2091,7 +2088,7 @@ void TargetX8632::lowerCast(const InstCast *Inst) { ...@@ -2091,7 +2088,7 @@ void TargetX8632::lowerCast(const InstCast *Inst) {
Variable *T = NULL; Variable *T = NULL;
_mov(T, Src0RM); _mov(T, Src0RM);
if (Dest->getType() == IceType_i1) if (Dest->getType() == IceType_i1)
_and(T, Ctx->getConstantInt32(IceType_i1, 1)); _and(T, Ctx->getConstantInt1(1));
_mov(Dest, T); _mov(Dest, T);
} }
break; break;
...@@ -2137,7 +2134,7 @@ void TargetX8632::lowerCast(const InstCast *Inst) { ...@@ -2137,7 +2134,7 @@ void TargetX8632::lowerCast(const InstCast *Inst) {
_cvt(T_1, Src0RM, InstX8632Cvt::Tss2si); _cvt(T_1, Src0RM, InstX8632Cvt::Tss2si);
_mov(T_2, T_1); // T_1 and T_2 may have different integer types _mov(T_2, T_1); // T_1 and T_2 may have different integer types
if (Dest->getType() == IceType_i1) if (Dest->getType() == IceType_i1)
_and(T_2, Ctx->getConstantInt32(IceType_i1, 1)); _and(T_2, Ctx->getConstantInt1(1));
_mov(Dest, T_2); _mov(Dest, T_2);
} }
break; break;
...@@ -2173,7 +2170,7 @@ void TargetX8632::lowerCast(const InstCast *Inst) { ...@@ -2173,7 +2170,7 @@ void TargetX8632::lowerCast(const InstCast *Inst) {
_cvt(T_1, Src0RM, InstX8632Cvt::Tss2si); _cvt(T_1, Src0RM, InstX8632Cvt::Tss2si);
_mov(T_2, T_1); // T_1 and T_2 may have different integer types _mov(T_2, T_1); // T_1 and T_2 may have different integer types
if (Dest->getType() == IceType_i1) if (Dest->getType() == IceType_i1)
_and(T_2, Ctx->getConstantInt32(IceType_i1, 1)); _and(T_2, Ctx->getConstantInt1(1));
_mov(Dest, T_2); _mov(Dest, T_2);
} }
break; break;
...@@ -2402,7 +2399,7 @@ void TargetX8632::lowerExtractElement(const InstExtractElement *Inst) { ...@@ -2402,7 +2399,7 @@ void TargetX8632::lowerExtractElement(const InstExtractElement *Inst) {
Ty == IceType_v8i16 || Ty == IceType_v8i1 || InstructionSet >= SSE4_1; Ty == IceType_v8i16 || Ty == IceType_v8i1 || InstructionSet >= SSE4_1;
if (CanUsePextr && Ty != IceType_v4f32) { if (CanUsePextr && Ty != IceType_v4f32) {
// Use pextrb, pextrw, or pextrd. // Use pextrb, pextrw, or pextrd.
Constant *Mask = Ctx->getConstantInt32(IceType_i8, Index); Constant *Mask = Ctx->getConstantInt32(Index);
Variable *SourceVectR = legalizeToVar(SourceVectNotLegalized); Variable *SourceVectR = legalizeToVar(SourceVectNotLegalized);
_pextr(ExtractedElementR, SourceVectR, Mask); _pextr(ExtractedElementR, SourceVectR, Mask);
} else if (Ty == IceType_v4i32 || Ty == IceType_v4f32 || Ty == IceType_v4i1) { } else if (Ty == IceType_v4i32 || Ty == IceType_v4f32 || Ty == IceType_v4i1) {
...@@ -2411,7 +2408,7 @@ void TargetX8632::lowerExtractElement(const InstExtractElement *Inst) { ...@@ -2411,7 +2408,7 @@ void TargetX8632::lowerExtractElement(const InstExtractElement *Inst) {
if (Index) { if (Index) {
// The shuffle only needs to occur if the element to be extracted // The shuffle only needs to occur if the element to be extracted
// is not at the lowest index. // is not at the lowest index.
Constant *Mask = Ctx->getConstantInt32(IceType_i8, Index); Constant *Mask = Ctx->getConstantInt32(Index);
T = makeReg(Ty); T = makeReg(Ty);
_pshufd(T, legalize(SourceVectNotLegalized, Legal_Reg | Legal_Mem), Mask); _pshufd(T, legalize(SourceVectNotLegalized, Legal_Reg | Legal_Mem), Mask);
} else { } else {
...@@ -2549,8 +2546,7 @@ void TargetX8632::lowerFcmp(const InstFcmp *Inst) { ...@@ -2549,8 +2546,7 @@ void TargetX8632::lowerFcmp(const InstFcmp *Inst) {
_mov(T, Src0); _mov(T, Src0);
_ucomiss(T, Src1RM); _ucomiss(T, Src1RM);
} }
Constant *Default = Constant *Default = Ctx->getConstantInt32(TableFcmp[Index].Default);
Ctx->getConstantInt32(IceType_i32, TableFcmp[Index].Default);
_mov(Dest, Default); _mov(Dest, Default);
if (HasC1) { if (HasC1) {
InstX8632Label *Label = InstX8632Label::create(Func, this); InstX8632Label *Label = InstX8632Label::create(Func, this);
...@@ -2558,8 +2554,7 @@ void TargetX8632::lowerFcmp(const InstFcmp *Inst) { ...@@ -2558,8 +2554,7 @@ void TargetX8632::lowerFcmp(const InstFcmp *Inst) {
if (HasC2) { if (HasC2) {
_br(TableFcmp[Index].C2, Label); _br(TableFcmp[Index].C2, Label);
} }
Constant *NonDefault = Constant *NonDefault = Ctx->getConstantInt32(!TableFcmp[Index].Default);
Ctx->getConstantInt32(IceType_i32, !TableFcmp[Index].Default);
_mov_nonkillable(Dest, NonDefault); _mov_nonkillable(Dest, NonDefault);
Context.insert(Label); Context.insert(Label);
} }
...@@ -2700,7 +2695,7 @@ void TargetX8632::lowerIcmp(const InstIcmp *Inst) { ...@@ -2700,7 +2695,7 @@ void TargetX8632::lowerIcmp(const InstIcmp *Inst) {
// a=icmp cond, b, c ==> cmp b,c; a=1; br cond,L1; FakeUse(a); a=0; L1: // a=icmp cond, b, c ==> cmp b,c; a=1; br cond,L1; FakeUse(a); a=0; L1:
Constant *Zero = Ctx->getConstantZero(IceType_i32); Constant *Zero = Ctx->getConstantZero(IceType_i32);
Constant *One = Ctx->getConstantInt32(IceType_i32, 1); Constant *One = Ctx->getConstantInt32(1);
if (Src0->getType() == IceType_i64) { if (Src0->getType() == IceType_i64) {
InstIcmp::ICond Condition = Inst->getCondition(); InstIcmp::ICond Condition = Inst->getCondition();
size_t Index = static_cast<size_t>(Condition); size_t Index = static_cast<size_t>(Condition);
...@@ -2778,9 +2773,9 @@ void TargetX8632::lowerInsertElement(const InstInsertElement *Inst) { ...@@ -2778,9 +2773,9 @@ void TargetX8632::lowerInsertElement(const InstInsertElement *Inst) {
Variable *T = makeReg(Ty); Variable *T = makeReg(Ty);
_movp(T, SourceVectRM); _movp(T, SourceVectRM);
if (Ty == IceType_v4f32) if (Ty == IceType_v4f32)
_insertps(T, ElementRM, Ctx->getConstantInt32(IceType_i8, Index << 4)); _insertps(T, ElementRM, Ctx->getConstantInt32(Index << 4));
else else
_pinsr(T, ElementRM, Ctx->getConstantInt32(IceType_i8, Index)); _pinsr(T, ElementRM, Ctx->getConstantInt32(Index));
_movp(Inst->getDest(), T); _movp(Inst->getDest(), T);
} else if (Ty == IceType_v4i32 || Ty == IceType_v4f32 || Ty == IceType_v4i1) { } else if (Ty == IceType_v4i32 || Ty == IceType_v4f32 || Ty == IceType_v4i1) {
// Use shufps or movss. // Use shufps or movss.
...@@ -2831,10 +2826,8 @@ void TargetX8632::lowerInsertElement(const InstInsertElement *Inst) { ...@@ -2831,10 +2826,8 @@ void TargetX8632::lowerInsertElement(const InstInsertElement *Inst) {
const unsigned char Mask1[3] = { 0, 192, 128 }; const unsigned char Mask1[3] = { 0, 192, 128 };
const unsigned char Mask2[3] = { 227, 196, 52 }; const unsigned char Mask2[3] = { 227, 196, 52 };
Constant *Mask1Constant = Constant *Mask1Constant = Ctx->getConstantInt32(Mask1[Index - 1]);
Ctx->getConstantInt32(IceType_i8, Mask1[Index - 1]); Constant *Mask2Constant = Ctx->getConstantInt32(Mask2[Index - 1]);
Constant *Mask2Constant =
Ctx->getConstantInt32(IceType_i8, Mask2[Index - 1]);
if (Index == 1) { if (Index == 1) {
_shufps(ElementR, SourceVectRM, Mask1Constant); _shufps(ElementR, SourceVectRM, Mask1Constant);
...@@ -2926,7 +2919,7 @@ void TargetX8632::lowerIntrinsicCall(const InstIntrinsicCall *Instr) { ...@@ -2926,7 +2919,7 @@ void TargetX8632::lowerIntrinsicCall(const InstIntrinsicCall *Instr) {
case 2: case 2:
case 4: case 4:
case 8: case 8:
Result = Ctx->getConstantInt32(IceType_i32, 1); Result = Ctx->getConstantInt32(1);
break; break;
} }
_mov(Dest, Result); _mov(Dest, Result);
...@@ -3032,7 +3025,7 @@ void TargetX8632::lowerIntrinsicCall(const InstIntrinsicCall *Instr) { ...@@ -3032,7 +3025,7 @@ void TargetX8632::lowerIntrinsicCall(const InstIntrinsicCall *Instr) {
} else { } else {
assert(Val->getType() == IceType_i16); assert(Val->getType() == IceType_i16);
Val = legalize(Val); Val = legalize(Val);
Constant *Eight = Ctx->getConstantInt32(IceType_i16, 8); Constant *Eight = Ctx->getConstantInt16(8);
Variable *T = NULL; Variable *T = NULL;
_mov(T, Val); _mov(T, Val);
_rol(T, Eight); _rol(T, Eight);
...@@ -3516,12 +3509,12 @@ void TargetX8632::lowerCountZeros(bool Cttz, Type Ty, Variable *Dest, ...@@ -3516,12 +3509,12 @@ void TargetX8632::lowerCountZeros(bool Cttz, Type Ty, Variable *Dest,
_bsr(T, FirstValRM); _bsr(T, FirstValRM);
} }
Variable *T_Dest = makeReg(IceType_i32); Variable *T_Dest = makeReg(IceType_i32);
Constant *ThirtyTwo = Ctx->getConstantInt32(IceType_i32, 32); Constant *ThirtyTwo = Ctx->getConstantInt32(32);
Constant *ThirtyOne = Ctx->getConstantInt32(IceType_i32, 31); Constant *ThirtyOne = Ctx->getConstantInt32(31);
if (Cttz) { if (Cttz) {
_mov(T_Dest, ThirtyTwo); _mov(T_Dest, ThirtyTwo);
} else { } else {
Constant *SixtyThree = Ctx->getConstantInt32(IceType_i32, 63); Constant *SixtyThree = Ctx->getConstantInt32(63);
_mov(T_Dest, SixtyThree); _mov(T_Dest, SixtyThree);
} }
_cmov(T_Dest, T, CondX86::Br_ne); _cmov(T_Dest, T, CondX86::Br_ne);
...@@ -3860,7 +3853,7 @@ void TargetX8632::doAddressOptLoad() { ...@@ -3860,7 +3853,7 @@ void TargetX8632::doAddressOptLoad() {
computeAddressOpt(Func, Inst, Base, Index, Shift, Offset); computeAddressOpt(Func, Inst, Base, Index, Shift, Offset);
if (Base && Addr != Base) { if (Base && Addr != Base) {
Inst->setDeleted(); Inst->setDeleted();
Constant *OffsetOp = Ctx->getConstantInt32(IceType_i32, Offset); Constant *OffsetOp = Ctx->getConstantInt32(Offset);
Addr = OperandX8632Mem::create(Func, Dest->getType(), Base, OffsetOp, Index, Addr = OperandX8632Mem::create(Func, Dest->getType(), Base, OffsetOp, Index,
Shift, SegmentReg); Shift, SegmentReg);
Context.insert(InstLoad::create(Func, Dest, Addr)); Context.insert(InstLoad::create(Func, Dest, Addr));
...@@ -3926,7 +3919,7 @@ void TargetX8632::lowerSelect(const InstSelect *Inst) { ...@@ -3926,7 +3919,7 @@ void TargetX8632::lowerSelect(const InstSelect *Inst) {
Operand *ConditionRM = legalize(Condition, Legal_Reg | Legal_Mem); Operand *ConditionRM = legalize(Condition, Legal_Reg | Legal_Mem);
Variable *xmm0 = makeReg(IceType_v4i32, RegX8632::Reg_xmm0); Variable *xmm0 = makeReg(IceType_v4i32, RegX8632::Reg_xmm0);
_movp(xmm0, ConditionRM); _movp(xmm0, ConditionRM);
_psll(xmm0, Ctx->getConstantInt32(IceType_i8, 31)); _psll(xmm0, Ctx->getConstantInt8(31));
_movp(T, SrcFRM); _movp(T, SrcFRM);
_blendvps(T, SrcTRM, xmm0); _blendvps(T, SrcTRM, xmm0);
_movp(Dest, T); _movp(Dest, T);
...@@ -4038,7 +4031,7 @@ void TargetX8632::doAddressOptStore() { ...@@ -4038,7 +4031,7 @@ void TargetX8632::doAddressOptStore() {
computeAddressOpt(Func, Inst, Base, Index, Shift, Offset); computeAddressOpt(Func, Inst, Base, Index, Shift, Offset);
if (Base && Addr != Base) { if (Base && Addr != Base) {
Inst->setDeleted(); Inst->setDeleted();
Constant *OffsetOp = Ctx->getConstantInt32(IceType_i32, Offset); Constant *OffsetOp = Ctx->getConstantInt32(Offset);
Addr = OperandX8632Mem::create(Func, Data->getType(), Base, OffsetOp, Index, Addr = OperandX8632Mem::create(Func, Data->getType(), Base, OffsetOp, Index,
Shift, SegmentReg); Shift, SegmentReg);
Context.insert(InstStore::create(Func, Data, Addr)); Context.insert(InstStore::create(Func, Data, Addr));
...@@ -4062,9 +4055,8 @@ void TargetX8632::lowerSwitch(const InstSwitch *Inst) { ...@@ -4062,9 +4055,8 @@ void TargetX8632::lowerSwitch(const InstSwitch *Inst) {
Src0Hi = legalize(Src0Hi, Legal_Reg | Legal_Mem); Src0Hi = legalize(Src0Hi, Legal_Reg | Legal_Mem);
} }
for (SizeT I = 0; I < NumCases; ++I) { for (SizeT I = 0; I < NumCases; ++I) {
Constant *ValueLo = Ctx->getConstantInt32(IceType_i32, Inst->getValue(I)); Constant *ValueLo = Ctx->getConstantInt32(Inst->getValue(I));
Constant *ValueHi = Constant *ValueHi = Ctx->getConstantInt32(Inst->getValue(I) >> 32);
Ctx->getConstantInt32(IceType_i32, Inst->getValue(I) >> 32);
InstX8632Label *Label = InstX8632Label::create(Func, this); InstX8632Label *Label = InstX8632Label::create(Func, this);
_cmp(Src0Lo, ValueLo); _cmp(Src0Lo, ValueLo);
_br(CondX86::Br_ne, Label); _br(CondX86::Br_ne, Label);
...@@ -4082,7 +4074,7 @@ void TargetX8632::lowerSwitch(const InstSwitch *Inst) { ...@@ -4082,7 +4074,7 @@ void TargetX8632::lowerSwitch(const InstSwitch *Inst) {
else else
Src0 = legalize(Src0, Legal_Reg | Legal_Mem); Src0 = legalize(Src0, Legal_Reg | Legal_Mem);
for (SizeT I = 0; I < NumCases; ++I) { for (SizeT I = 0; I < NumCases; ++I) {
Constant *Value = Ctx->getConstantInt32(IceType_i32, Inst->getValue(I)); Constant *Value = Ctx->getConstantInt32(Inst->getValue(I));
_cmp(Src0, Value); _cmp(Src0, Value);
_br(CondX86::Br_e, Inst->getLabel(I)); _br(CondX86::Br_e, Inst->getLabel(I));
} }
...@@ -4100,7 +4092,7 @@ void TargetX8632::scalarizeArithmetic(InstArithmetic::OpKind Kind, ...@@ -4100,7 +4092,7 @@ void TargetX8632::scalarizeArithmetic(InstArithmetic::OpKind Kind,
Operand *T = Ctx->getConstantUndef(Ty); Operand *T = Ctx->getConstantUndef(Ty);
for (SizeT I = 0; I < NumElements; ++I) { for (SizeT I = 0; I < NumElements; ++I) {
Constant *Index = Ctx->getConstantInt32(IceType_i32, I); Constant *Index = Ctx->getConstantInt32(I);
// Extract the next two inputs. // Extract the next two inputs.
Variable *Op0 = Func->makeVariable(ElementTy); Variable *Op0 = Func->makeVariable(ElementTy);
...@@ -4348,13 +4340,12 @@ Variable *TargetX8632::makeVectorOfHighOrderBits(Type Ty, int32_t RegNum) { ...@@ -4348,13 +4340,12 @@ Variable *TargetX8632::makeVectorOfHighOrderBits(Type Ty, int32_t RegNum) {
if (Ty == IceType_v4f32 || Ty == IceType_v4i32 || Ty == IceType_v8i16) { if (Ty == IceType_v4f32 || Ty == IceType_v4i32 || Ty == IceType_v8i16) {
Variable *Reg = makeVectorOfOnes(Ty, RegNum); Variable *Reg = makeVectorOfOnes(Ty, RegNum);
SizeT Shift = typeWidthInBytes(typeElementType(Ty)) * X86_CHAR_BIT - 1; SizeT Shift = typeWidthInBytes(typeElementType(Ty)) * X86_CHAR_BIT - 1;
_psll(Reg, Ctx->getConstantInt32(IceType_i8, Shift)); _psll(Reg, Ctx->getConstantInt8(Shift));
return Reg; return Reg;
} else { } else {
// SSE has no left shift operation for vectors of 8 bit integers. // SSE has no left shift operation for vectors of 8 bit integers.
const uint32_t HIGH_ORDER_BITS_MASK = 0x80808080; const uint32_t HIGH_ORDER_BITS_MASK = 0x80808080;
Constant *ConstantMask = Constant *ConstantMask = Ctx->getConstantInt32(HIGH_ORDER_BITS_MASK);
Ctx->getConstantInt32(IceType_i32, HIGH_ORDER_BITS_MASK);
Variable *Reg = makeReg(Ty, RegNum); Variable *Reg = makeReg(Ty, RegNum);
_movd(Reg, legalize(ConstantMask, Legal_Reg | Legal_Mem)); _movd(Reg, legalize(ConstantMask, Legal_Reg | Legal_Mem));
_pshufd(Reg, Reg, Ctx->getConstantZero(IceType_i8)); _pshufd(Reg, Reg, Ctx->getConstantZero(IceType_i8));
...@@ -4375,7 +4366,7 @@ OperandX8632Mem *TargetX8632::getMemoryOperandForStackSlot(Type Ty, ...@@ -4375,7 +4366,7 @@ OperandX8632Mem *TargetX8632::getMemoryOperandForStackSlot(Type Ty,
const Type PointerType = IceType_i32; const Type PointerType = IceType_i32;
Variable *Loc = makeReg(PointerType); Variable *Loc = makeReg(PointerType);
_lea(Loc, Slot); _lea(Loc, Slot);
Constant *ConstantOffset = Ctx->getConstantInt32(IceType_i32, Offset); Constant *ConstantOffset = Ctx->getConstantInt32(Offset);
return OperandX8632Mem::create(Func, Ty, Loc, ConstantOffset); return OperandX8632Mem::create(Func, Ty, Loc, ConstantOffset);
} }
......
...@@ -161,11 +161,12 @@ protected: ...@@ -161,11 +161,12 @@ protected:
Variable *makeReg(Type Ty, int32_t RegNum = Variable::NoRegister); Variable *makeReg(Type Ty, int32_t RegNum = Variable::NoRegister);
InstCall *makeHelperCall(const IceString &Name, Variable *Dest, InstCall *makeHelperCall(const IceString &Name, Variable *Dest,
SizeT MaxSrcs) { SizeT MaxSrcs) {
bool SuppressMangling = true; const bool SuppressMangling = true;
const Type FunctionPointerType = IceType_i32; const bool HasTailCall = false;
Constant *CallTarget = const RelocOffsetT Offset = 0;
Ctx->getConstantSym(FunctionPointerType, 0, Name, SuppressMangling); Constant *CallTarget = Ctx->getConstantSym(Offset, Name, SuppressMangling);
InstCall *Call = InstCall::create(Func, MaxSrcs, Dest, CallTarget, false); InstCall *Call =
InstCall::create(Func, MaxSrcs, Dest, CallTarget, HasTailCall);
return Call; return Call;
} }
static Type stackSlotType(); static Type stackSlotType();
......
...@@ -325,8 +325,8 @@ public: ...@@ -325,8 +325,8 @@ public:
SuppressMangling = false; SuppressMangling = false;
} }
const Ice::RelocOffsetT Offset = 0; const Ice::RelocOffsetT Offset = 0;
C = getTranslator().getContext()->getConstantSym( C = getTranslator().getContext()->getConstantSym(Offset, Name,
getIcePointerType(), Offset, Name, SuppressMangling); SuppressMangling);
ValueIDConstants[ID] = C; ValueIDConstants[ID] = C;
return C; return C;
} }
...@@ -1440,7 +1440,7 @@ private: ...@@ -1440,7 +1440,7 @@ private:
const auto *C = dyn_cast<Ice::ConstantInteger32>(Index); const auto *C = dyn_cast<Ice::ConstantInteger32>(Index);
if (C == nullptr) if (C == nullptr)
return VectorIndexNotConstant; return VectorIndexNotConstant;
if (C->getValue() >= typeNumElements(VecType)) if (static_cast<size_t>(C->getValue()) >= typeNumElements(VecType))
return VectorIndexNotInRange; return VectorIndexNotInRange;
if (Index->getType() != Ice::IceType_i32) if (Index->getType() != Ice::IceType_i32)
return VectorIndexNotI32; return VectorIndexNotI32;
...@@ -2496,16 +2496,14 @@ void ConstantsParser::ProcessRecord() { ...@@ -2496,16 +2496,14 @@ void ConstantsParser::ProcessRecord() {
FuncParser->setNextConstantID(nullptr); FuncParser->setNextConstantID(nullptr);
return; return;
} }
if (IntegerType *IType = dyn_cast<IntegerType>( if (auto IType = dyn_cast<IntegerType>(
Context->convertToLLVMType(NextConstantType))) { Context->convertToLLVMType(NextConstantType))) {
APInt Value(IType->getBitWidth(), NaClDecodeSignRotatedValue(Values[0])); APInt Value(IType->getBitWidth(), NaClDecodeSignRotatedValue(Values[0]));
Ice::Constant *C = (NextConstantType == Ice::IceType_i64) if (Ice::Constant *C = getContext()->getConstantInt(
? getContext()->getConstantInt64( NextConstantType, Value.getSExtValue())) {
NextConstantType, Value.getSExtValue()) FuncParser->setNextConstantID(C);
: getContext()->getConstantInt32( return;
NextConstantType, Value.getSExtValue()); }
FuncParser->setNextConstantID(C);
return;
} }
std::string Buffer; std::string Buffer;
raw_string_ostream StrBuf(Buffer); raw_string_ostream StrBuf(Buffer);
......
...@@ -60,8 +60,7 @@ Address Address::ofConstPool(GlobalContext *Ctx, Assembler *Asm, ...@@ -60,8 +60,7 @@ Address Address::ofConstPool(GlobalContext *Ctx, Assembler *Asm,
StrBuf << ".L$" << Ty << "$" << Imm->getPoolEntryID(); StrBuf << ".L$" << Ty << "$" << Imm->getPoolEntryID();
const RelocOffsetT Offset = 0; const RelocOffsetT Offset = 0;
const bool SuppressMangling = true; const bool SuppressMangling = true;
Constant *Sym = Constant *Sym = Ctx->getConstantSym(Offset, StrBuf.str(), SuppressMangling);
Ctx->getConstantSym(Ty, Offset, StrBuf.str(), SuppressMangling);
AssemblerFixup *Fixup = x86::DisplacementRelocation::create( AssemblerFixup *Fixup = x86::DisplacementRelocation::create(
Asm, FK_Abs_4, llvm::cast<ConstantRelocatable>(Sym)); Asm, FK_Abs_4, llvm::cast<ConstantRelocatable>(Sym));
return x86::Address::Absolute(Fixup); return x86::Address::Absolute(Fixup);
......
...@@ -33,7 +33,7 @@ define float @undef_float() { ...@@ -33,7 +33,7 @@ define float @undef_float() {
entry: entry:
ret float undef ret float undef
; CHECK-LABEL: undef_float ; CHECK-LABEL: undef_float
; CHECK: fld dword ptr [0] ; CHECK: fld dword ptr [4]
} }
define <4 x i1> @undef_v4i1() { define <4 x i1> @undef_v4i1() {
...@@ -186,7 +186,7 @@ entry: ...@@ -186,7 +186,7 @@ entry:
%val = insertelement <4 x float> %arg, float undef, i32 0 %val = insertelement <4 x float> %arg, float undef, i32 0
ret <4 x float> %val ret <4 x float> %val
; CHECK-LABEL: vector_insertelement_arg2 ; CHECK-LABEL: vector_insertelement_arg2
; CHECK: movss {{.*}}, dword ptr [0] ; CHECK: movss {{.*}}, dword ptr [4]
} }
define float @vector_extractelement_v4f32_index_0() { define float @vector_extractelement_v4f32_index_0() {
......
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