OLD | NEW |
---|---|
1 //===- subzero/src/IceTargetLoweringX8632.cpp - x86-32 lowering -----------===// | 1 //===- subzero/src/IceTargetLoweringX8632.cpp - x86-32 lowering -----------===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file implements the TargetLoweringX8632 class, which | 10 // This file implements the TargetLoweringX8632 class, which |
(...skipping 1903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1914 // allow an immediate operand. If the operand is an immediate, we could | 1914 // allow an immediate operand. If the operand is an immediate, we could |
1915 // consider computing the strength-reduced result at translation time, | 1915 // consider computing the strength-reduced result at translation time, |
1916 // but we're unlikely to see something like that in the bitcode that | 1916 // but we're unlikely to see something like that in the bitcode that |
1917 // the optimizer wouldn't have already taken care of. | 1917 // the optimizer wouldn't have already taken care of. |
1918 Operand *Src0RM = legalize(Inst->getSrc(0), Legal_Reg | Legal_Mem); | 1918 Operand *Src0RM = legalize(Inst->getSrc(0), Legal_Reg | Legal_Mem); |
1919 if (Dest->getType() == IceType_i64) { | 1919 if (Dest->getType() == IceType_i64) { |
1920 // t1=movsx src; t2=t1; t2=sar t2, 31; dst.lo=t1; dst.hi=t2 | 1920 // t1=movsx src; t2=t1; t2=sar t2, 31; dst.lo=t1; dst.hi=t2 |
1921 Variable *DestLo = llvm::cast<Variable>(loOperand(Dest)); | 1921 Variable *DestLo = llvm::cast<Variable>(loOperand(Dest)); |
1922 Variable *DestHi = llvm::cast<Variable>(hiOperand(Dest)); | 1922 Variable *DestHi = llvm::cast<Variable>(hiOperand(Dest)); |
1923 Variable *T_Lo = makeReg(DestLo->getType()); | 1923 Variable *T_Lo = makeReg(DestLo->getType()); |
1924 if (Src0RM->getType() == IceType_i32) | 1924 if (Src0RM->getType() == IceType_i32) { |
1925 _mov(T_Lo, Src0RM); | 1925 _mov(T_Lo, Src0RM); |
1926 else | 1926 } else if (Src0RM->getType() == IceType_i1) { |
1927 Constant *ShiftAmount = Ctx->getConstantInt(IceType_i32, 31); | |
jvoung (off chromium)
2014/09/04 21:05:41
nit: Since the later Shift is always needed, could
Jim Stichnoth
2014/09/04 21:43:07
Done.
| |
1928 _mov(T_Lo, Src0RM); | |
1929 _shl(T_Lo, ShiftAmount); | |
1930 _sar(T_Lo, ShiftAmount); | |
1931 } else { | |
1927 _movsx(T_Lo, Src0RM); | 1932 _movsx(T_Lo, Src0RM); |
1933 } | |
1928 _mov(DestLo, T_Lo); | 1934 _mov(DestLo, T_Lo); |
1929 Variable *T_Hi = NULL; | 1935 Variable *T_Hi = NULL; |
1930 Constant *Shift = Ctx->getConstantInt(IceType_i32, 31); | 1936 Constant *Shift = Ctx->getConstantInt(IceType_i32, 31); |
1931 _mov(T_Hi, T_Lo); | 1937 _mov(T_Hi, T_Lo); |
1932 _sar(T_Hi, Shift); | 1938 _sar(T_Hi, Shift); |
1933 _mov(DestHi, T_Hi); | 1939 _mov(DestHi, T_Hi); |
1934 } else if (isVectorType(Dest->getType())) { | 1940 } else if (isVectorType(Dest->getType())) { |
1935 Type DestTy = Dest->getType(); | 1941 Type DestTy = Dest->getType(); |
1936 if (DestTy == IceType_v16i8) { | 1942 if (DestTy == IceType_v16i8) { |
1937 // onemask = materialize(1,1,...); dst = (src & onemask) > 0 | 1943 // onemask = materialize(1,1,...); dst = (src & onemask) > 0 |
1938 Variable *OneMask = makeVectorOfOnes(Dest->getType()); | 1944 Variable *OneMask = makeVectorOfOnes(Dest->getType()); |
1939 Variable *T = makeReg(DestTy); | 1945 Variable *T = makeReg(DestTy); |
1940 _movp(T, Src0RM); | 1946 _movp(T, Src0RM); |
1941 _pand(T, OneMask); | 1947 _pand(T, OneMask); |
1942 Variable *Zeros = makeVectorOfZeros(Dest->getType()); | 1948 Variable *Zeros = makeVectorOfZeros(Dest->getType()); |
1943 _pcmpgt(T, Zeros); | 1949 _pcmpgt(T, Zeros); |
1944 _movp(Dest, T); | 1950 _movp(Dest, T); |
1945 } else { | 1951 } else { |
1946 // width = width(elty) - 1; dest = (src << width) >> width | 1952 // width = width(elty) - 1; dest = (src << width) >> width |
1947 SizeT ShiftAmount = | 1953 SizeT ShiftAmount = |
1948 X86_CHAR_BIT * typeWidthInBytes(typeElementType(DestTy)) - 1; | 1954 X86_CHAR_BIT * typeWidthInBytes(typeElementType(DestTy)) - 1; |
1949 Constant *ShiftConstant = Ctx->getConstantInt(IceType_i8, ShiftAmount); | 1955 Constant *ShiftConstant = Ctx->getConstantInt(IceType_i8, ShiftAmount); |
1950 Variable *T = makeReg(DestTy); | 1956 Variable *T = makeReg(DestTy); |
1951 _movp(T, Src0RM); | 1957 _movp(T, Src0RM); |
1952 _psll(T, ShiftConstant); | 1958 _psll(T, ShiftConstant); |
1953 _psra(T, ShiftConstant); | 1959 _psra(T, ShiftConstant); |
1954 _movp(Dest, T); | 1960 _movp(Dest, T); |
1955 } | 1961 } |
1956 } else { | 1962 } else { |
1957 // TODO: Sign-extend an i1 via "shl reg, 31; sar reg, 31", and | |
1958 // also copy to the high operand of a 64-bit variable. | |
1959 // t1 = movsx src; dst = t1 | 1963 // t1 = movsx src; dst = t1 |
1960 Variable *T = makeReg(Dest->getType()); | 1964 // - or - |
1961 _movsx(T, Src0RM); | 1965 // t1 = src |
1962 _mov(Dest, T); | 1966 // shl t1, dst_bitwidth - 1 |
1967 // sar t1, dst_bitwidth - 1 | |
1968 // dst = t1 | |
1969 if (Src0RM->getType() == IceType_i1) { | |
1970 size_t DestBits = CHAR_BIT * typeWidthInBytes(Dest->getType()); | |
jvoung (off chromium)
2014/09/04 21:05:41
Should this be X86_CHAR_BIT instead (which the vec
Jim Stichnoth
2014/09/04 21:43:07
Done.
| |
1971 Constant *ShiftAmount = Ctx->getConstantInt(IceType_i32, DestBits - 1); | |
1972 Variable *T = NULL; | |
1973 _mov(T, Src0RM); | |
1974 _shl(T, ShiftAmount); | |
1975 _sar(T, ShiftAmount); | |
1976 _mov(Dest, T); | |
1977 } else { | |
1978 Variable *T = makeReg(Dest->getType()); | |
1979 _movsx(T, Src0RM); | |
1980 _mov(Dest, T); | |
1981 } | |
1963 } | 1982 } |
1964 break; | 1983 break; |
1965 } | 1984 } |
1966 case InstCast::Zext: { | 1985 case InstCast::Zext: { |
1967 Operand *Src0RM = legalize(Inst->getSrc(0), Legal_Reg | Legal_Mem); | 1986 Operand *Src0RM = legalize(Inst->getSrc(0), Legal_Reg | Legal_Mem); |
1968 if (Dest->getType() == IceType_i64) { | 1987 if (Dest->getType() == IceType_i64) { |
1969 // t1=movzx src; dst.lo=t1; dst.hi=0 | 1988 // t1=movzx src; dst.lo=t1; dst.hi=0 |
1970 Constant *Zero = Ctx->getConstantZero(IceType_i32); | 1989 Constant *Zero = Ctx->getConstantZero(IceType_i32); |
1971 Variable *DestLo = llvm::cast<Variable>(loOperand(Dest)); | 1990 Variable *DestLo = llvm::cast<Variable>(loOperand(Dest)); |
1972 Variable *DestHi = llvm::cast<Variable>(hiOperand(Dest)); | 1991 Variable *DestHi = llvm::cast<Variable>(hiOperand(Dest)); |
1973 Variable *Tmp = makeReg(DestLo->getType()); | 1992 Variable *Tmp = makeReg(DestLo->getType()); |
1974 if (Src0RM->getType() == IceType_i32) | 1993 if (Src0RM->getType() == IceType_i32) { |
1975 _mov(Tmp, Src0RM); | 1994 _mov(Tmp, Src0RM); |
1976 else | 1995 } else if (Src0RM->getType() == IceType_i1) { |
1996 Constant *One = Ctx->getConstantInt(IceType_i32, 1); | |
1997 _mov(Tmp, Src0RM); | |
1998 _and(Tmp, One); | |
1999 } else { | |
1977 _movzx(Tmp, Src0RM); | 2000 _movzx(Tmp, Src0RM); |
2001 } | |
1978 _mov(DestLo, Tmp); | 2002 _mov(DestLo, Tmp); |
1979 _mov(DestHi, Zero); | 2003 _mov(DestHi, Zero); |
1980 } else if (Src0RM->getType() == IceType_i1) { | 2004 } else if (Src0RM->getType() == IceType_i1) { |
1981 // t = Src0RM; t &= 1; Dest = t | 2005 // t = Src0RM; t &= 1; Dest = t |
1982 Operand *One = Ctx->getConstantInt(IceType_i32, 1); | 2006 Constant *One = Ctx->getConstantInt(IceType_i32, 1); |
1983 Variable *T = makeReg(IceType_i32); | 2007 Variable *T = makeReg(IceType_i32); |
1984 _movzx(T, Src0RM); | 2008 _movzx(T, Src0RM); |
1985 _and(T, One); | 2009 _and(T, One); |
1986 _mov(Dest, T); | 2010 _mov(Dest, T); |
1987 } else if (isVectorType(Dest->getType())) { | 2011 } else if (isVectorType(Dest->getType())) { |
1988 // onemask = materialize(1,1,...); dest = onemask & src | 2012 // onemask = materialize(1,1,...); dest = onemask & src |
1989 Type DestTy = Dest->getType(); | 2013 Type DestTy = Dest->getType(); |
1990 Variable *OneMask = makeVectorOfOnes(DestTy); | 2014 Variable *OneMask = makeVectorOfOnes(DestTy); |
1991 Variable *T = makeReg(DestTy); | 2015 Variable *T = makeReg(DestTy); |
1992 _movp(T, Src0RM); | 2016 _movp(T, Src0RM); |
1993 _pand(T, OneMask); | 2017 _pand(T, OneMask); |
1994 _movp(Dest, T); | 2018 _movp(Dest, T); |
1995 } else { | 2019 } else { |
1996 // t1 = movzx src; dst = t1 | 2020 // t1 = movzx src; dst = t1 |
jvoung (off chromium)
2014/09/04 21:05:41
Maybe move the t1 = movzx comment to the } else {
Jim Stichnoth
2014/09/04 21:43:07
Done (as part of the next comment below).
| |
1997 Variable *T = makeReg(Dest->getType()); | 2021 Variable *T = makeReg(Dest->getType()); |
1998 _movzx(T, Src0RM); | 2022 if (Src0RM->getType() == IceType_i1) { |
jvoung (off chromium)
2014/09/04 21:05:41
Is this case possible? Or is it already caught by
Jim Stichnoth
2014/09/04 21:43:07
Oops, somehow I thought the i1 case wasn't being p
| |
2023 Constant *One = Ctx->getConstantInt(IceType_i32, 1); | |
2024 _mov(T, Src0RM); | |
2025 _and(T, One); | |
2026 } else { | |
2027 _movzx(T, Src0RM); | |
2028 } | |
1999 _mov(Dest, T); | 2029 _mov(Dest, T); |
2000 } | 2030 } |
2001 break; | 2031 break; |
2002 } | 2032 } |
2003 case InstCast::Trunc: { | 2033 case InstCast::Trunc: { |
2004 if (isVectorType(Dest->getType())) { | 2034 if (isVectorType(Dest->getType())) { |
2005 // onemask = materialize(1,1,...); dst = src & onemask | 2035 // onemask = materialize(1,1,...); dst = src & onemask |
2006 Operand *Src0RM = legalize(Inst->getSrc(0), Legal_Reg | Legal_Mem); | 2036 Operand *Src0RM = legalize(Inst->getSrc(0), Legal_Reg | Legal_Mem); |
2007 Type Src0Ty = Src0RM->getType(); | 2037 Type Src0Ty = Src0RM->getType(); |
2008 Variable *OneMask = makeVectorOfOnes(Src0Ty); | 2038 Variable *OneMask = makeVectorOfOnes(Src0Ty); |
(...skipping 1904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3913 Operand *Src0 = Inst->getComparison(); | 3943 Operand *Src0 = Inst->getComparison(); |
3914 SizeT NumCases = Inst->getNumCases(); | 3944 SizeT NumCases = Inst->getNumCases(); |
3915 // OK, we'll be slightly less naive by forcing Src into a physical | 3945 // OK, we'll be slightly less naive by forcing Src into a physical |
3916 // register if there are 2 or more uses. | 3946 // register if there are 2 or more uses. |
3917 if (NumCases >= 2) | 3947 if (NumCases >= 2) |
3918 Src0 = legalizeToVar(Src0, true); | 3948 Src0 = legalizeToVar(Src0, true); |
3919 else | 3949 else |
3920 Src0 = legalize(Src0, Legal_Reg | Legal_Mem, true); | 3950 Src0 = legalize(Src0, Legal_Reg | Legal_Mem, true); |
3921 for (SizeT I = 0; I < NumCases; ++I) { | 3951 for (SizeT I = 0; I < NumCases; ++I) { |
3922 // TODO(stichnot): Correct lowering for IceType_i64. | 3952 // TODO(stichnot): Correct lowering for IceType_i64. |
3923 Operand *Value = Ctx->getConstantInt(IceType_i32, Inst->getValue(I)); | 3953 Constant *Value = Ctx->getConstantInt(IceType_i32, Inst->getValue(I)); |
jvoung (off chromium)
2014/09/04 21:05:41
This seems separate. Add a comment in the commit m
Jim Stichnoth
2014/09/04 21:43:07
Done.
| |
3924 _cmp(Src0, Value); | 3954 _cmp(Src0, Value); |
3925 _br(InstX8632Br::Br_e, Inst->getLabel(I)); | 3955 _br(InstX8632Br::Br_e, Inst->getLabel(I)); |
3926 } | 3956 } |
3927 | 3957 |
3928 _br(Inst->getLabelDefault()); | 3958 _br(Inst->getLabelDefault()); |
3929 } | 3959 } |
3930 | 3960 |
3931 void TargetX8632::scalarizeArithmetic(InstArithmetic::OpKind Kind, | 3961 void TargetX8632::scalarizeArithmetic(InstArithmetic::OpKind Kind, |
3932 Variable *Dest, Operand *Src0, | 3962 Variable *Dest, Operand *Src0, |
3933 Operand *Src1) { | 3963 Operand *Src1) { |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4419 Str << "\t.align\t" << Align << "\n"; | 4449 Str << "\t.align\t" << Align << "\n"; |
4420 Str << MangledName << ":\n"; | 4450 Str << MangledName << ":\n"; |
4421 for (SizeT i = 0; i < Size; ++i) { | 4451 for (SizeT i = 0; i < Size; ++i) { |
4422 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; | 4452 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; |
4423 } | 4453 } |
4424 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; | 4454 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; |
4425 } | 4455 } |
4426 } | 4456 } |
4427 | 4457 |
4428 } // end of namespace Ice | 4458 } // end of namespace Ice |
OLD | NEW |