2005-01-07 07:47:09 +00:00
|
|
|
//===-- LegalizeDAG.cpp - Implement SelectionDAG::Legalize ----------------===//
|
2005-04-21 22:36:52 +00:00
|
|
|
//
|
2005-01-07 07:47:09 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:36:52 +00:00
|
|
|
//
|
2005-01-07 07:47:09 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the SelectionDAG::Legalize method.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2005-01-15 07:15:18 +00:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2006-12-14 19:17:33 +00:00
|
|
|
#include "llvm/CodeGen/MachineJumpTableInfo.h"
|
2007-12-31 04:13:23 +00:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2008-02-06 22:27:42 +00:00
|
|
|
#include "llvm/CodeGen/PseudoSourceValue.h"
|
2007-08-16 23:50:06 +00:00
|
|
|
#include "llvm/Target/TargetFrameInfo.h"
|
2005-01-07 07:47:09 +00:00
|
|
|
#include "llvm/Target/TargetLowering.h"
|
2005-01-11 05:57:22 +00:00
|
|
|
#include "llvm/Target/TargetData.h"
|
2006-10-30 08:00:44 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2005-01-15 06:18:18 +00:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
Drop ISD::MEMSET, ISD::MEMMOVE, and ISD::MEMCPY, which are not Legal
on any current target and aren't optimized in DAGCombiner. Instead
of using intermediate nodes, expand the operations, choosing between
simple loads/stores, target-specific code, and library calls,
immediately.
Previously, the code to emit optimized code for these operations
was only used at initial SelectionDAG construction time; now it is
used at all times. This fixes some cases where rep;movs was being
used for small copies where simple loads/stores would be better.
This also cleans up code that checks for alignments less than 4;
let the targets make that decision instead of doing it in
target-independent code. This allows x86 to use rep;movs in
low-alignment cases.
Also, this fixes a bug that resulted in the use of rep;stos for
memsets of 0 with non-constant memory size when the alignment was
at least 4. It's better to use the library in this case, which
can be significantly faster when the size is large.
This also preserves more SourceValue information when memory
intrinsics are lowered into simple loads/stores.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49572 91177308-0d34-0410-b5e6-96231b3b80d8
2008-04-12 04:36:06 +00:00
|
|
|
#include "llvm/Target/TargetSubtarget.h"
|
2005-05-13 18:50:42 +00:00
|
|
|
#include "llvm/CallingConv.h"
|
2005-01-07 07:47:09 +00:00
|
|
|
#include "llvm/Constants.h"
|
2007-01-19 21:13:56 +00:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2006-04-02 03:07:27 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2006-08-27 12:54:02 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2007-10-28 12:59:45 +00:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2007-02-03 01:12:36 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2006-08-08 01:09:31 +00:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2007-02-04 00:27:56 +00:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2006-03-24 01:17:21 +00:00
|
|
|
#include <map>
|
2005-01-07 07:47:09 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2006-04-02 03:07:27 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
static cl::opt<bool>
|
|
|
|
ViewLegalizeDAGs("view-legalize-dags", cl::Hidden,
|
|
|
|
cl::desc("Pop up a window to show dags before legalize"));
|
|
|
|
#else
|
|
|
|
static const bool ViewLegalizeDAGs = 0;
|
|
|
|
#endif
|
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// SelectionDAGLegalize - This takes an arbitrary SelectionDAG as input and
|
|
|
|
/// hacks on it until the target machine can handle it. This involves
|
|
|
|
/// eliminating value sizes the machine cannot handle (promoting small sizes to
|
|
|
|
/// large sizes or splitting up large values into small values) as well as
|
|
|
|
/// eliminating operations the machine cannot handle.
|
|
|
|
///
|
|
|
|
/// This code also does a small amount of optimization and recognition of idioms
|
|
|
|
/// as part of its processing. For example, if a target does not support a
|
|
|
|
/// 'setcc' instruction efficiently, but does support 'brcc' instruction, this
|
|
|
|
/// will attempt merge setcc and brc instructions into brcc's.
|
|
|
|
///
|
|
|
|
namespace {
|
2006-06-28 21:58:30 +00:00
|
|
|
class VISIBILITY_HIDDEN SelectionDAGLegalize {
|
2005-01-07 07:47:09 +00:00
|
|
|
TargetLowering &TLI;
|
|
|
|
SelectionDAG &DAG;
|
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
// Libcall insertion helpers.
|
|
|
|
|
|
|
|
/// LastCALLSEQ_END - This keeps track of the CALLSEQ_END node that has been
|
|
|
|
/// legalized. We use this to ensure that calls are properly serialized
|
|
|
|
/// against each other, including inserted libcalls.
|
|
|
|
SDOperand LastCALLSEQ_END;
|
|
|
|
|
|
|
|
/// IsLegalizingCall - This member is used *only* for purposes of providing
|
|
|
|
/// helpful assertions that a libcall isn't created while another call is
|
|
|
|
/// being legalized (which could lead to non-serialized call sequences).
|
|
|
|
bool IsLegalizingCall;
|
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
enum LegalizeAction {
|
2006-01-29 08:42:06 +00:00
|
|
|
Legal, // The target natively supports this operation.
|
|
|
|
Promote, // This operation should be executed in a larger type.
|
2006-05-24 17:04:05 +00:00
|
|
|
Expand // Try to expand this to other ops, otherwise use a libcall.
|
2005-01-07 07:47:09 +00:00
|
|
|
};
|
2006-02-13 09:18:02 +00:00
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
/// ValueTypeActions - This is a bitvector that contains two bits for each
|
|
|
|
/// value type, where the two bits correspond to the LegalizeAction enum.
|
|
|
|
/// This can be queried with "getTypeAction(VT)".
|
2006-01-29 08:42:06 +00:00
|
|
|
TargetLowering::ValueTypeActionImpl ValueTypeActions;
|
2005-01-07 07:47:09 +00:00
|
|
|
|
|
|
|
/// LegalizedNodes - For nodes that are of legal width, and that have more
|
|
|
|
/// than one use, this map indicates what regularized operand to use. This
|
|
|
|
/// allows us to avoid legalizing the same thing more than once.
|
2008-04-16 16:15:27 +00:00
|
|
|
DenseMap<SDOperand, SDOperand> LegalizedNodes;
|
2005-01-07 07:47:09 +00:00
|
|
|
|
2005-01-15 05:21:40 +00:00
|
|
|
/// PromotedNodes - For nodes that are below legal width, and that have more
|
|
|
|
/// than one use, this map indicates what promoted value to use. This allows
|
|
|
|
/// us to avoid promoting the same thing more than once.
|
2008-04-16 16:15:27 +00:00
|
|
|
DenseMap<SDOperand, SDOperand> PromotedNodes;
|
2005-01-15 05:21:40 +00:00
|
|
|
|
2006-03-18 01:44:44 +00:00
|
|
|
/// ExpandedNodes - For nodes that need to be expanded this map indicates
|
|
|
|
/// which which operands are the expanded version of the input. This allows
|
|
|
|
/// us to avoid expanding the same node more than once.
|
2008-04-16 16:15:27 +00:00
|
|
|
DenseMap<SDOperand, std::pair<SDOperand, SDOperand> > ExpandedNodes;
|
2005-01-07 07:47:09 +00:00
|
|
|
|
2006-03-18 01:44:44 +00:00
|
|
|
/// SplitNodes - For vector nodes that need to be split, this map indicates
|
|
|
|
/// which which operands are the split version of the input. This allows us
|
|
|
|
/// to avoid splitting the same node more than once.
|
|
|
|
std::map<SDOperand, std::pair<SDOperand, SDOperand> > SplitNodes;
|
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
/// ScalarizedNodes - For nodes that need to be converted from vector types to
|
|
|
|
/// scalar types, this contains the mapping of ones we have already
|
2006-03-18 01:44:44 +00:00
|
|
|
/// processed to the result.
|
2007-06-25 16:23:39 +00:00
|
|
|
std::map<SDOperand, SDOperand> ScalarizedNodes;
|
2006-03-18 01:44:44 +00:00
|
|
|
|
2005-01-07 22:28:47 +00:00
|
|
|
void AddLegalizedOperand(SDOperand From, SDOperand To) {
|
2005-12-20 00:53:54 +00:00
|
|
|
LegalizedNodes.insert(std::make_pair(From, To));
|
|
|
|
// If someone requests legalization of the new node, return itself.
|
|
|
|
if (From != To)
|
|
|
|
LegalizedNodes.insert(std::make_pair(To, To));
|
2005-01-07 22:28:47 +00:00
|
|
|
}
|
2005-01-15 05:21:40 +00:00
|
|
|
void AddPromotedOperand(SDOperand From, SDOperand To) {
|
2007-02-04 01:17:38 +00:00
|
|
|
bool isNew = PromotedNodes.insert(std::make_pair(From, To));
|
2005-01-15 05:21:40 +00:00
|
|
|
assert(isNew && "Got into the map somehow?");
|
2005-12-20 00:53:54 +00:00
|
|
|
// If someone requests legalization of the new node, return itself.
|
|
|
|
LegalizedNodes.insert(std::make_pair(To, To));
|
2005-01-15 05:21:40 +00:00
|
|
|
}
|
2005-01-07 22:28:47 +00:00
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
public:
|
|
|
|
|
2005-01-23 04:42:50 +00:00
|
|
|
SelectionDAGLegalize(SelectionDAG &DAG);
|
2005-01-07 07:47:09 +00:00
|
|
|
|
|
|
|
/// getTypeAction - Return how we should legalize values of this type, either
|
|
|
|
/// it is already legal or we need to expand it into multiple registers of
|
|
|
|
/// smaller integer type, or we need to promote it to a larger type.
|
|
|
|
LegalizeAction getTypeAction(MVT::ValueType VT) const {
|
2006-01-29 08:42:06 +00:00
|
|
|
return (LegalizeAction)ValueTypeActions.getTypeAction(VT);
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// isTypeLegal - Return true if this type is legal on this target.
|
|
|
|
///
|
|
|
|
bool isTypeLegal(MVT::ValueType VT) const {
|
|
|
|
return getTypeAction(VT) == Legal;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LegalizeDAG();
|
|
|
|
|
2006-01-28 07:39:30 +00:00
|
|
|
private:
|
2007-06-25 16:23:39 +00:00
|
|
|
/// HandleOp - Legalize, Promote, or Expand the specified operand as
|
2006-03-18 01:44:44 +00:00
|
|
|
/// appropriate for its type.
|
|
|
|
void HandleOp(SDOperand Op);
|
|
|
|
|
|
|
|
/// LegalizeOp - We know that the specified value has a legal type.
|
|
|
|
/// Recursively ensure that the operands have legal types, then return the
|
|
|
|
/// result.
|
2005-01-07 07:47:09 +00:00
|
|
|
SDOperand LegalizeOp(SDOperand O);
|
2006-03-18 01:44:44 +00:00
|
|
|
|
2007-10-11 23:57:53 +00:00
|
|
|
/// UnrollVectorOp - We know that the given vector has a legal type, however
|
|
|
|
/// the operation it performs is not legal and is an operation that we have
|
|
|
|
/// no way of lowering. "Unroll" the vector, splitting out the scalars and
|
|
|
|
/// operating on each element individually.
|
|
|
|
SDOperand UnrollVectorOp(SDOperand O);
|
2008-04-25 18:07:40 +00:00
|
|
|
|
|
|
|
/// PerformInsertVectorEltInMemory - Some target cannot handle a variable
|
|
|
|
/// insertion index for the INSERT_VECTOR_ELT instruction. In this case, it
|
|
|
|
/// is necessary to spill the vector being inserted into to memory, perform
|
|
|
|
/// the insert there, and then read the result back.
|
|
|
|
SDOperand PerformInsertVectorEltInMemory(SDOperand Vec, SDOperand Val,
|
|
|
|
SDOperand Idx);
|
2007-10-11 23:57:53 +00:00
|
|
|
|
2006-03-18 01:44:44 +00:00
|
|
|
/// PromoteOp - Given an operation that produces a value in an invalid type,
|
|
|
|
/// promote it to compute the value into a larger type. The produced value
|
|
|
|
/// will have the correct bits for the low portion of the register, but no
|
|
|
|
/// guarantee is made about the top bits: it may be zero, sign-extended, or
|
|
|
|
/// garbage.
|
2005-01-15 05:21:40 +00:00
|
|
|
SDOperand PromoteOp(SDOperand O);
|
2005-01-07 07:47:09 +00:00
|
|
|
|
2006-03-18 01:44:44 +00:00
|
|
|
/// ExpandOp - Expand the specified SDOperand into its two component pieces
|
|
|
|
/// Lo&Hi. Note that the Op MUST be an expanded type. As a result of this,
|
|
|
|
/// the LegalizeNodes map is filled in for any results that are not expanded,
|
|
|
|
/// the ExpandedNodes map is filled in for any results that are expanded, and
|
|
|
|
/// the Lo/Hi values are returned. This applies to integer types and Vector
|
|
|
|
/// types.
|
|
|
|
void ExpandOp(SDOperand O, SDOperand &Lo, SDOperand &Hi);
|
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
/// SplitVectorOp - Given an operand of vector type, break it down into
|
|
|
|
/// two smaller values.
|
2006-03-18 01:44:44 +00:00
|
|
|
void SplitVectorOp(SDOperand O, SDOperand &Lo, SDOperand &Hi);
|
|
|
|
|
2007-06-27 14:06:22 +00:00
|
|
|
/// ScalarizeVectorOp - Given an operand of single-element vector type
|
|
|
|
/// (e.g. v1f32), convert it into the equivalent operation that returns a
|
|
|
|
/// scalar (e.g. f32) value.
|
2007-06-25 16:23:39 +00:00
|
|
|
SDOperand ScalarizeVectorOp(SDOperand O);
|
2006-03-18 01:44:44 +00:00
|
|
|
|
2006-04-04 17:23:26 +00:00
|
|
|
/// isShuffleLegal - Return true if a vector shuffle is legal with the
|
|
|
|
/// specified mask and type. Targets can specify exactly which masks they
|
|
|
|
/// support and the code generator is tasked with not creating illegal masks.
|
|
|
|
///
|
|
|
|
/// Note that this will also return true for shuffles that are promoted to a
|
|
|
|
/// different type.
|
|
|
|
///
|
|
|
|
/// If this is a legal shuffle, this method returns the (possibly promoted)
|
|
|
|
/// build_vector Mask. If it's not a legal shuffle, it returns null.
|
|
|
|
SDNode *isShuffleLegal(MVT::ValueType VT, SDOperand Mask) const;
|
|
|
|
|
2006-07-26 23:55:56 +00:00
|
|
|
bool LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest,
|
2007-02-04 00:27:56 +00:00
|
|
|
SmallPtrSet<SDNode*, 32> &NodesLeadingTo);
|
2006-02-13 09:18:02 +00:00
|
|
|
|
2006-02-01 07:19:44 +00:00
|
|
|
void LegalizeSetCCOperands(SDOperand &LHS, SDOperand &RHS, SDOperand &CC);
|
|
|
|
|
2008-04-12 17:14:18 +00:00
|
|
|
SDOperand ExpandLibCall(RTLIB::Libcall LC, SDNode *Node, bool isSigned,
|
2005-01-21 06:05:23 +00:00
|
|
|
SDOperand &Hi);
|
|
|
|
SDOperand ExpandIntToFP(bool isSigned, MVT::ValueType DestTy,
|
|
|
|
SDOperand Source);
|
2005-07-16 00:19:57 +00:00
|
|
|
|
2008-01-16 07:45:30 +00:00
|
|
|
SDOperand EmitStackConvert(SDOperand SrcOp, MVT::ValueType SlotVT,
|
|
|
|
MVT::ValueType DestVT);
|
2006-03-19 06:31:19 +00:00
|
|
|
SDOperand ExpandBUILD_VECTOR(SDNode *Node);
|
2006-04-04 17:23:26 +00:00
|
|
|
SDOperand ExpandSCALAR_TO_VECTOR(SDNode *Node);
|
Added generic code expansion for [signed|unsigned] i32 to [f32|f64] casts in the
legalizer. PowerPC now uses this expansion instead of ISel version.
Example:
// signed integer to double conversion
double f1(signed x) {
return (double)x;
}
// unsigned integer to double conversion
double f2(unsigned x) {
return (double)x;
}
// signed integer to float conversion
float f3(signed x) {
return (float)x;
}
// unsigned integer to float conversion
float f4(unsigned x) {
return (float)x;
}
Byte Code:
internal fastcc double %_Z2f1i(int %x) {
entry:
%tmp.1 = cast int %x to double ; <double> [#uses=1]
ret double %tmp.1
}
internal fastcc double %_Z2f2j(uint %x) {
entry:
%tmp.1 = cast uint %x to double ; <double> [#uses=1]
ret double %tmp.1
}
internal fastcc float %_Z2f3i(int %x) {
entry:
%tmp.1 = cast int %x to float ; <float> [#uses=1]
ret float %tmp.1
}
internal fastcc float %_Z2f4j(uint %x) {
entry:
%tmp.1 = cast uint %x to float ; <float> [#uses=1]
ret float %tmp.1
}
internal fastcc double %_Z2g1i(int %x) {
entry:
%buffer = alloca [2 x uint] ; <[2 x uint]*> [#uses=3]
%tmp.0 = getelementptr [2 x uint]* %buffer, int 0, int 0 ; <uint*> [#uses=1]
store uint 1127219200, uint* %tmp.0
%tmp.2 = cast int %x to uint ; <uint> [#uses=1]
%tmp.3 = xor uint %tmp.2, 2147483648 ; <uint> [#uses=1]
%tmp.5 = getelementptr [2 x uint]* %buffer, int 0, int 1 ; <uint*> [#uses=1]
store uint %tmp.3, uint* %tmp.5
%tmp.9 = cast [2 x uint]* %buffer to double* ; <double*> [#uses=1]
%tmp.10 = load double* %tmp.9 ; <double> [#uses=1]
%tmp.13 = load double* cast (long* %signed_bias to double*) ; <double> [#uses=1]
%tmp.14 = sub double %tmp.10, %tmp.13 ; <double> [#uses=1]
ret double %tmp.14
}
internal fastcc double %_Z2g2j(uint %x) {
entry:
%buffer = alloca [2 x uint] ; <[2 x uint]*> [#uses=3]
%tmp.0 = getelementptr [2 x uint]* %buffer, int 0, int 0 ; <uint*> [#uses=1]
store uint 1127219200, uint* %tmp.0
%tmp.1 = getelementptr [2 x uint]* %buffer, int 0, int 1 ; <uint*> [#uses=1]
store uint %x, uint* %tmp.1
%tmp.4 = cast [2 x uint]* %buffer to double* ; <double*> [#uses=1]
%tmp.5 = load double* %tmp.4 ; <double> [#uses=1]
%tmp.8 = load double* cast (long* %unsigned_bias to double*) ; <double> [#uses=1]
%tmp.9 = sub double %tmp.5, %tmp.8 ; <double> [#uses=1]
ret double %tmp.9
}
internal fastcc float %_Z2g3i(int %x) {
entry:
%buffer = alloca [2 x uint] ; <[2 x uint]*> [#uses=3]
%tmp.0 = getelementptr [2 x uint]* %buffer, int 0, int 0 ; <uint*> [#uses=1]
store uint 1127219200, uint* %tmp.0
%tmp.2 = cast int %x to uint ; <uint> [#uses=1]
%tmp.3 = xor uint %tmp.2, 2147483648 ; <uint> [#uses=1]
%tmp.5 = getelementptr [2 x uint]* %buffer, int 0, int 1 ; <uint*> [#uses=1]
store uint %tmp.3, uint* %tmp.5
%tmp.9 = cast [2 x uint]* %buffer to double* ; <double*> [#uses=1]
%tmp.10 = load double* %tmp.9 ; <double> [#uses=1]
%tmp.13 = load double* cast (long* %signed_bias to double*) ; <double> [#uses=1]
%tmp.14 = sub double %tmp.10, %tmp.13 ; <double> [#uses=1]
%tmp.16 = cast double %tmp.14 to float ; <float> [#uses=1]
ret float %tmp.16
}
internal fastcc float %_Z2g4j(uint %x) {
entry:
%buffer = alloca [2 x uint] ; <[2 x uint]*> [#uses=3]
%tmp.0 = getelementptr [2 x uint]* %buffer, int 0, int 0 ; <uint*> [#uses=1]
store uint 1127219200, uint* %tmp.0
%tmp.1 = getelementptr [2 x uint]* %buffer, int 0, int 1 ; <uint*> [#uses=1]
store uint %x, uint* %tmp.1
%tmp.4 = cast [2 x uint]* %buffer to double* ; <double*> [#uses=1]
%tmp.5 = load double* %tmp.4 ; <double> [#uses=1]
%tmp.8 = load double* cast (long* %unsigned_bias to double*) ; <double> [#uses=1]
%tmp.9 = sub double %tmp.5, %tmp.8 ; <double> [#uses=1]
%tmp.11 = cast double %tmp.9 to float ; <float> [#uses=1]
ret float %tmp.11
}
PowerPC Code:
.machine ppc970
.const
.align 2
.CPIl1__Z2f1i_0: ; float 0x4330000080000000
.long 1501560836 ; float 4.5036e+15
.text
.align 2
.globl l1__Z2f1i
l1__Z2f1i:
.LBBl1__Z2f1i_0: ; entry
xoris r2, r3, 32768
stw r2, -4(r1)
lis r2, 17200
stw r2, -8(r1)
lfd f0, -8(r1)
lis r2, ha16(.CPIl1__Z2f1i_0)
lfs f1, lo16(.CPIl1__Z2f1i_0)(r2)
fsub f1, f0, f1
blr
.const
.align 2
.CPIl2__Z2f2j_0: ; float 0x4330000000000000
.long 1501560832 ; float 4.5036e+15
.text
.align 2
.globl l2__Z2f2j
l2__Z2f2j:
.LBBl2__Z2f2j_0: ; entry
stw r3, -4(r1)
lis r2, 17200
stw r2, -8(r1)
lfd f0, -8(r1)
lis r2, ha16(.CPIl2__Z2f2j_0)
lfs f1, lo16(.CPIl2__Z2f2j_0)(r2)
fsub f1, f0, f1
blr
.const
.align 2
.CPIl3__Z2f3i_0: ; float 0x4330000080000000
.long 1501560836 ; float 4.5036e+15
.text
.align 2
.globl l3__Z2f3i
l3__Z2f3i:
.LBBl3__Z2f3i_0: ; entry
xoris r2, r3, 32768
stw r2, -4(r1)
lis r2, 17200
stw r2, -8(r1)
lfd f0, -8(r1)
lis r2, ha16(.CPIl3__Z2f3i_0)
lfs f1, lo16(.CPIl3__Z2f3i_0)(r2)
fsub f0, f0, f1
frsp f1, f0
blr
.const
.align 2
.CPIl4__Z2f4j_0: ; float 0x4330000000000000
.long 1501560832 ; float 4.5036e+15
.text
.align 2
.globl l4__Z2f4j
l4__Z2f4j:
.LBBl4__Z2f4j_0: ; entry
stw r3, -4(r1)
lis r2, 17200
stw r2, -8(r1)
lfd f0, -8(r1)
lis r2, ha16(.CPIl4__Z2f4j_0)
lfs f1, lo16(.CPIl4__Z2f4j_0)(r2)
fsub f0, f0, f1
frsp f1, f0
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22814 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-17 00:39:29 +00:00
|
|
|
SDOperand ExpandLegalINT_TO_FP(bool isSigned,
|
|
|
|
SDOperand LegalOp,
|
|
|
|
MVT::ValueType DestVT);
|
Teach the legalizer how to promote SINT_TO_FP to a wider SINT_TO_FP that
the target natively supports. This eliminates some special-case code from
the x86 backend and generates better code as well.
For an i8 to f64 conversion, before & after:
_x87 before:
subl $2, %esp
movb 6(%esp), %al
movsbw %al, %ax
movw %ax, (%esp)
filds (%esp)
addl $2, %esp
ret
_x87 after:
subl $2, %esp
movsbw 6(%esp), %ax
movw %ax, (%esp)
filds (%esp)
addl $2, %esp
ret
_sse before:
subl $12, %esp
movb 16(%esp), %al
movsbl %al, %eax
cvtsi2sd %eax, %xmm0
addl $12, %esp
ret
_sse after:
subl $12, %esp
movsbl 16(%esp), %eax
cvtsi2sd %eax, %xmm0
addl $12, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22452 91177308-0d34-0410-b5e6-96231b3b80d8
2005-07-16 02:02:34 +00:00
|
|
|
SDOperand PromoteLegalINT_TO_FP(SDOperand LegalOp, MVT::ValueType DestVT,
|
|
|
|
bool isSigned);
|
2005-07-29 00:11:56 +00:00
|
|
|
SDOperand PromoteLegalFP_TO_INT(SDOperand LegalOp, MVT::ValueType DestVT,
|
|
|
|
bool isSigned);
|
2005-07-27 06:12:32 +00:00
|
|
|
|
2006-01-28 07:39:30 +00:00
|
|
|
SDOperand ExpandBSWAP(SDOperand Op);
|
|
|
|
SDOperand ExpandBitCount(unsigned Opc, SDOperand Op);
|
2005-01-19 04:19:40 +00:00
|
|
|
bool ExpandShift(unsigned Opc, SDOperand Op, SDOperand Amt,
|
|
|
|
SDOperand &Lo, SDOperand &Hi);
|
2005-04-02 04:00:59 +00:00
|
|
|
void ExpandShiftParts(unsigned NodeOp, SDOperand Op, SDOperand Amt,
|
|
|
|
SDOperand &Lo, SDOperand &Hi);
|
2005-05-12 04:49:08 +00:00
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
SDOperand ExpandEXTRACT_SUBVECTOR(SDOperand Op);
|
2006-04-02 05:06:04 +00:00
|
|
|
SDOperand ExpandEXTRACT_VECTOR_ELT(SDOperand Op);
|
2005-01-07 07:47:09 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2006-04-04 17:23:26 +00:00
|
|
|
/// isVectorShuffleLegal - Return true if a vector shuffle is legal with the
|
|
|
|
/// specified mask and type. Targets can specify exactly which masks they
|
|
|
|
/// support and the code generator is tasked with not creating illegal masks.
|
|
|
|
///
|
|
|
|
/// Note that this will also return true for shuffles that are promoted to a
|
|
|
|
/// different type.
|
|
|
|
SDNode *SelectionDAGLegalize::isShuffleLegal(MVT::ValueType VT,
|
|
|
|
SDOperand Mask) const {
|
|
|
|
switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE, VT)) {
|
|
|
|
default: return 0;
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
break;
|
|
|
|
case TargetLowering::Promote: {
|
|
|
|
// If this is promoted to a different type, convert the shuffle mask and
|
|
|
|
// ask if it is legal in the promoted type!
|
|
|
|
MVT::ValueType NVT = TLI.getTypeToPromoteTo(ISD::VECTOR_SHUFFLE, VT);
|
|
|
|
|
|
|
|
// If we changed # elements, change the shuffle mask.
|
|
|
|
unsigned NumEltsGrowth =
|
|
|
|
MVT::getVectorNumElements(NVT) / MVT::getVectorNumElements(VT);
|
|
|
|
assert(NumEltsGrowth && "Cannot promote to vector type with fewer elts!");
|
|
|
|
if (NumEltsGrowth > 1) {
|
|
|
|
// Renumber the elements.
|
2006-08-08 02:23:42 +00:00
|
|
|
SmallVector<SDOperand, 8> Ops;
|
2006-04-04 17:23:26 +00:00
|
|
|
for (unsigned i = 0, e = Mask.getNumOperands(); i != e; ++i) {
|
|
|
|
SDOperand InOp = Mask.getOperand(i);
|
|
|
|
for (unsigned j = 0; j != NumEltsGrowth; ++j) {
|
|
|
|
if (InOp.getOpcode() == ISD::UNDEF)
|
|
|
|
Ops.push_back(DAG.getNode(ISD::UNDEF, MVT::i32));
|
|
|
|
else {
|
|
|
|
unsigned InEltNo = cast<ConstantSDNode>(InOp)->getValue();
|
|
|
|
Ops.push_back(DAG.getConstant(InEltNo*NumEltsGrowth+j, MVT::i32));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-08-08 02:23:42 +00:00
|
|
|
Mask = DAG.getNode(ISD::BUILD_VECTOR, NVT, &Ops[0], Ops.size());
|
2006-04-04 17:23:26 +00:00
|
|
|
}
|
|
|
|
VT = NVT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TLI.isShuffleMaskLegal(Mask, VT) ? Mask.Val : 0;
|
|
|
|
}
|
|
|
|
|
2005-01-23 04:42:50 +00:00
|
|
|
SelectionDAGLegalize::SelectionDAGLegalize(SelectionDAG &dag)
|
|
|
|
: TLI(dag.getTargetLoweringInfo()), DAG(dag),
|
|
|
|
ValueTypeActions(TLI.getValueTypeActions()) {
|
2005-11-29 05:45:29 +00:00
|
|
|
assert(MVT::LAST_VALUETYPE <= 32 &&
|
2005-01-07 07:47:09 +00:00
|
|
|
"Too many value types for ValueTypeActions to hold!");
|
|
|
|
}
|
|
|
|
|
2007-06-18 21:28:10 +00:00
|
|
|
/// ComputeTopDownOrdering - Compute a top-down ordering of the dag, where Order
|
|
|
|
/// contains all of a nodes operands before it contains the node.
|
|
|
|
static void ComputeTopDownOrdering(SelectionDAG &DAG,
|
|
|
|
SmallVector<SDNode*, 64> &Order) {
|
|
|
|
|
|
|
|
DenseMap<SDNode*, unsigned> Visited;
|
|
|
|
std::vector<SDNode*> Worklist;
|
|
|
|
Worklist.reserve(128);
|
2005-10-06 01:20:27 +00:00
|
|
|
|
2007-06-18 21:28:10 +00:00
|
|
|
// Compute ordering from all of the leaves in the graphs, those (like the
|
|
|
|
// entry node) that have no operands.
|
|
|
|
for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(),
|
|
|
|
E = DAG.allnodes_end(); I != E; ++I) {
|
|
|
|
if (I->getNumOperands() == 0) {
|
|
|
|
Visited[I] = 0 - 1U;
|
|
|
|
Worklist.push_back(I);
|
|
|
|
}
|
2005-10-06 01:20:27 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 21:28:10 +00:00
|
|
|
while (!Worklist.empty()) {
|
|
|
|
SDNode *N = Worklist.back();
|
|
|
|
Worklist.pop_back();
|
|
|
|
|
|
|
|
if (++Visited[N] != N->getNumOperands())
|
|
|
|
continue; // Haven't visited all operands yet
|
|
|
|
|
|
|
|
Order.push_back(N);
|
|
|
|
|
|
|
|
// Now that we have N in, add anything that uses it if all of their operands
|
|
|
|
// are now done.
|
|
|
|
for (SDNode::use_iterator UI = N->use_begin(), E = N->use_end();
|
|
|
|
UI != E; ++UI)
|
2008-04-07 10:06:32 +00:00
|
|
|
Worklist.push_back(UI->getUser());
|
2007-06-18 21:28:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(Order.size() == Visited.size() &&
|
|
|
|
Order.size() ==
|
|
|
|
(unsigned)std::distance(DAG.allnodes_begin(), DAG.allnodes_end()) &&
|
|
|
|
"Error: DAG is cyclic!");
|
2005-10-06 01:20:27 +00:00
|
|
|
}
|
|
|
|
|
2005-07-29 00:11:56 +00:00
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
void SelectionDAGLegalize::LegalizeDAG() {
|
2006-02-13 09:18:02 +00:00
|
|
|
LastCALLSEQ_END = DAG.getEntryNode();
|
|
|
|
IsLegalizingCall = false;
|
|
|
|
|
2005-10-02 17:49:46 +00:00
|
|
|
// The legalize process is inherently a bottom-up recursive process (users
|
|
|
|
// legalize their uses before themselves). Given infinite stack space, we
|
|
|
|
// could just start legalizing on the root and traverse the whole graph. In
|
|
|
|
// practice however, this causes us to run out of stack space on large basic
|
2005-10-06 01:20:27 +00:00
|
|
|
// blocks. To avoid this problem, compute an ordering of the nodes where each
|
|
|
|
// node is only legalized after all of its operands are legalized.
|
2007-02-04 01:20:02 +00:00
|
|
|
SmallVector<SDNode*, 64> Order;
|
2007-06-18 21:28:10 +00:00
|
|
|
ComputeTopDownOrdering(DAG, Order);
|
2005-10-02 17:49:46 +00:00
|
|
|
|
2006-03-18 01:44:44 +00:00
|
|
|
for (unsigned i = 0, e = Order.size(); i != e; ++i)
|
|
|
|
HandleOp(SDOperand(Order[i], 0));
|
2005-10-06 01:20:27 +00:00
|
|
|
|
|
|
|
// Finally, it's possible the root changed. Get the new root.
|
2005-01-07 07:47:09 +00:00
|
|
|
SDOperand OldRoot = DAG.getRoot();
|
2005-10-06 01:20:27 +00:00
|
|
|
assert(LegalizedNodes.count(OldRoot) && "Root didn't get legalized?");
|
|
|
|
DAG.setRoot(LegalizedNodes[OldRoot]);
|
2005-01-07 07:47:09 +00:00
|
|
|
|
|
|
|
ExpandedNodes.clear();
|
|
|
|
LegalizedNodes.clear();
|
2005-01-16 01:11:45 +00:00
|
|
|
PromotedNodes.clear();
|
2006-03-18 01:44:44 +00:00
|
|
|
SplitNodes.clear();
|
2007-06-25 16:23:39 +00:00
|
|
|
ScalarizedNodes.clear();
|
2005-01-07 07:47:09 +00:00
|
|
|
|
|
|
|
// Remove dead nodes now.
|
2006-08-04 17:45:20 +00:00
|
|
|
DAG.RemoveDeadNodes();
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
|
|
|
|
/// FindCallEndFromCallStart - Given a chained node that is part of a call
|
|
|
|
/// sequence, find the CALLSEQ_END node that terminates the call sequence.
|
|
|
|
static SDNode *FindCallEndFromCallStart(SDNode *Node) {
|
|
|
|
if (Node->getOpcode() == ISD::CALLSEQ_END)
|
|
|
|
return Node;
|
|
|
|
if (Node->use_empty())
|
|
|
|
return 0; // No CallSeqEnd
|
|
|
|
|
|
|
|
// The chain is usually at the end.
|
|
|
|
SDOperand TheChain(Node, Node->getNumValues()-1);
|
|
|
|
if (TheChain.getValueType() != MVT::Other) {
|
|
|
|
// Sometimes it's at the beginning.
|
|
|
|
TheChain = SDOperand(Node, 0);
|
|
|
|
if (TheChain.getValueType() != MVT::Other) {
|
|
|
|
// Otherwise, hunt for it.
|
|
|
|
for (unsigned i = 1, e = Node->getNumValues(); i != e; ++i)
|
|
|
|
if (Node->getValueType(i) == MVT::Other) {
|
|
|
|
TheChain = SDOperand(Node, i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we walked into a node without a chain.
|
|
|
|
if (TheChain.getValueType() != MVT::Other)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (SDNode::use_iterator UI = Node->use_begin(),
|
|
|
|
E = Node->use_end(); UI != E; ++UI) {
|
|
|
|
|
|
|
|
// Make sure to only follow users of our token chain.
|
2008-04-07 10:06:32 +00:00
|
|
|
SDNode *User = UI->getUser();
|
2006-02-13 09:18:02 +00:00
|
|
|
for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i)
|
|
|
|
if (User->getOperand(i) == TheChain)
|
|
|
|
if (SDNode *Result = FindCallEndFromCallStart(User))
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// FindCallStartFromCallEnd - Given a chained node that is part of a call
|
|
|
|
/// sequence, find the CALLSEQ_START node that initiates the call sequence.
|
|
|
|
static SDNode *FindCallStartFromCallEnd(SDNode *Node) {
|
|
|
|
assert(Node && "Didn't find callseq_start for a call??");
|
|
|
|
if (Node->getOpcode() == ISD::CALLSEQ_START) return Node;
|
|
|
|
|
|
|
|
assert(Node->getOperand(0).getValueType() == MVT::Other &&
|
|
|
|
"Node doesn't have a token chain argument!");
|
|
|
|
return FindCallStartFromCallEnd(Node->getOperand(0).Val);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// LegalizeAllNodesNotLeadingTo - Recursively walk the uses of N, looking to
|
|
|
|
/// see if any uses can reach Dest. If no dest operands can get to dest,
|
|
|
|
/// legalize them, legalize ourself, and return false, otherwise, return true.
|
2006-07-26 23:55:56 +00:00
|
|
|
///
|
|
|
|
/// Keep track of the nodes we fine that actually do lead to Dest in
|
|
|
|
/// NodesLeadingTo. This avoids retraversing them exponential number of times.
|
|
|
|
///
|
|
|
|
bool SelectionDAGLegalize::LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest,
|
2007-02-04 00:27:56 +00:00
|
|
|
SmallPtrSet<SDNode*, 32> &NodesLeadingTo) {
|
2006-02-13 09:18:02 +00:00
|
|
|
if (N == Dest) return true; // N certainly leads to Dest :)
|
|
|
|
|
2006-07-26 23:55:56 +00:00
|
|
|
// If we've already processed this node and it does lead to Dest, there is no
|
|
|
|
// need to reprocess it.
|
|
|
|
if (NodesLeadingTo.count(N)) return true;
|
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
// If the first result of this node has been already legalized, then it cannot
|
|
|
|
// reach N.
|
|
|
|
switch (getTypeAction(N->getValueType(0))) {
|
|
|
|
case Legal:
|
|
|
|
if (LegalizedNodes.count(SDOperand(N, 0))) return false;
|
|
|
|
break;
|
|
|
|
case Promote:
|
|
|
|
if (PromotedNodes.count(SDOperand(N, 0))) return false;
|
|
|
|
break;
|
|
|
|
case Expand:
|
|
|
|
if (ExpandedNodes.count(SDOperand(N, 0))) return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Okay, this node has not already been legalized. Check and legalize all
|
|
|
|
// operands. If none lead to Dest, then we can legalize this node.
|
|
|
|
bool OperandsLeadToDest = false;
|
|
|
|
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
|
|
|
|
OperandsLeadToDest |= // If an operand leads to Dest, so do we.
|
2006-07-26 23:55:56 +00:00
|
|
|
LegalizeAllNodesNotLeadingTo(N->getOperand(i).Val, Dest, NodesLeadingTo);
|
2006-02-13 09:18:02 +00:00
|
|
|
|
2006-07-26 23:55:56 +00:00
|
|
|
if (OperandsLeadToDest) {
|
|
|
|
NodesLeadingTo.insert(N);
|
|
|
|
return true;
|
|
|
|
}
|
2006-02-13 09:18:02 +00:00
|
|
|
|
|
|
|
// Okay, this node looks safe, legalize it and return false.
|
2006-04-17 22:10:08 +00:00
|
|
|
HandleOp(SDOperand(N, 0));
|
2006-02-13 09:18:02 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
/// HandleOp - Legalize, Promote, or Expand the specified operand as
|
2006-03-18 01:44:44 +00:00
|
|
|
/// appropriate for its type.
|
|
|
|
void SelectionDAGLegalize::HandleOp(SDOperand Op) {
|
2007-06-25 16:23:39 +00:00
|
|
|
MVT::ValueType VT = Op.getValueType();
|
|
|
|
switch (getTypeAction(VT)) {
|
2006-03-18 01:44:44 +00:00
|
|
|
default: assert(0 && "Bad type action!");
|
2007-06-25 16:23:39 +00:00
|
|
|
case Legal: (void)LegalizeOp(Op); break;
|
|
|
|
case Promote: (void)PromoteOp(Op); break;
|
2006-03-18 01:44:44 +00:00
|
|
|
case Expand:
|
2007-06-25 16:23:39 +00:00
|
|
|
if (!MVT::isVector(VT)) {
|
|
|
|
// If this is an illegal scalar, expand it into its two component
|
|
|
|
// pieces.
|
2006-03-18 01:44:44 +00:00
|
|
|
SDOperand X, Y;
|
2007-08-25 01:00:22 +00:00
|
|
|
if (Op.getOpcode() == ISD::TargetConstant)
|
|
|
|
break; // Allow illegal target nodes.
|
2006-03-18 01:44:44 +00:00
|
|
|
ExpandOp(Op, X, Y);
|
2007-06-25 16:23:39 +00:00
|
|
|
} else if (MVT::getVectorNumElements(VT) == 1) {
|
|
|
|
// If this is an illegal single element vector, convert it to a
|
|
|
|
// scalar operation.
|
|
|
|
(void)ScalarizeVectorOp(Op);
|
2006-03-18 01:44:44 +00:00
|
|
|
} else {
|
2007-06-25 16:23:39 +00:00
|
|
|
// Otherwise, this is an illegal multiple element vector.
|
|
|
|
// Split it in half and legalize both parts.
|
|
|
|
SDOperand X, Y;
|
|
|
|
SplitVectorOp(Op, X, Y);
|
2006-03-18 01:44:44 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-02-13 09:18:02 +00:00
|
|
|
|
2006-12-13 20:57:08 +00:00
|
|
|
/// ExpandConstantFP - Expands the ConstantFP node to an integer constant or
|
|
|
|
/// a load from the constant pool.
|
|
|
|
static SDOperand ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP,
|
2006-12-12 22:19:28 +00:00
|
|
|
SelectionDAG &DAG, TargetLowering &TLI) {
|
2006-12-12 21:32:44 +00:00
|
|
|
bool Extend = false;
|
|
|
|
|
|
|
|
// If a FP immediate is precise when represented as a float and if the
|
|
|
|
// target can do an extending load from float to double, we put it into
|
|
|
|
// the constant pool as a float, even if it's is statically typed as a
|
2008-03-05 06:46:58 +00:00
|
|
|
// double. This shrinks FP constants and canonicalizes them for targets where
|
|
|
|
// an FP extending load is the same cost as a normal load (such as on the x87
|
|
|
|
// fp stack or PPC FP unit).
|
2006-12-12 21:32:44 +00:00
|
|
|
MVT::ValueType VT = CFP->getValueType(0);
|
2008-04-20 00:41:09 +00:00
|
|
|
ConstantFP *LLVMC = ConstantFP::get(CFP->getValueAPF());
|
2006-12-13 20:57:08 +00:00
|
|
|
if (!UseCP) {
|
2007-09-14 22:26:36 +00:00
|
|
|
if (VT!=MVT::f64 && VT!=MVT::f32)
|
|
|
|
assert(0 && "Invalid type expansion");
|
2008-03-11 00:11:06 +00:00
|
|
|
return DAG.getConstant(LLVMC->getValueAPF().convertToAPInt(),
|
2008-03-04 08:05:30 +00:00
|
|
|
(VT == MVT::f64) ? MVT::i64 : MVT::i32);
|
2006-12-12 22:19:28 +00:00
|
|
|
}
|
|
|
|
|
2008-03-04 08:05:30 +00:00
|
|
|
MVT::ValueType OrigVT = VT;
|
|
|
|
MVT::ValueType SVT = VT;
|
|
|
|
while (SVT != MVT::f32) {
|
|
|
|
SVT = (unsigned)SVT - 1;
|
|
|
|
if (CFP->isValueValidForType(SVT, CFP->getValueAPF()) &&
|
|
|
|
// Only do this if the target has a native EXTLOAD instruction from
|
|
|
|
// smaller type.
|
2008-03-05 01:30:59 +00:00
|
|
|
TLI.isLoadXLegal(ISD::EXTLOAD, SVT) &&
|
2008-03-05 06:46:58 +00:00
|
|
|
TLI.ShouldShrinkFPConstant(OrigVT)) {
|
2008-03-04 08:05:30 +00:00
|
|
|
const Type *SType = MVT::getTypeForValueType(SVT);
|
|
|
|
LLVMC = cast<ConstantFP>(ConstantExpr::getFPTrunc(LLVMC, SType));
|
|
|
|
VT = SVT;
|
|
|
|
Extend = true;
|
|
|
|
}
|
2006-12-12 21:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SDOperand CPIdx = DAG.getConstantPool(LLVMC, TLI.getPointerTy());
|
2008-03-04 08:05:30 +00:00
|
|
|
if (Extend)
|
|
|
|
return DAG.getExtLoad(ISD::EXTLOAD, OrigVT, DAG.getEntryNode(),
|
2008-02-07 18:41:25 +00:00
|
|
|
CPIdx, PseudoSourceValue::getConstantPool(),
|
2008-03-04 08:05:30 +00:00
|
|
|
0, VT);
|
|
|
|
return DAG.getLoad(OrigVT, DAG.getEntryNode(), CPIdx,
|
|
|
|
PseudoSourceValue::getConstantPool(), 0);
|
2006-12-12 21:32:44 +00:00
|
|
|
}
|
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
|
2007-01-04 21:56:39 +00:00
|
|
|
/// ExpandFCOPYSIGNToBitwiseOps - Expands fcopysign to a series of bitwise
|
|
|
|
/// operations.
|
|
|
|
static
|
|
|
|
SDOperand ExpandFCOPYSIGNToBitwiseOps(SDNode *Node, MVT::ValueType NVT,
|
|
|
|
SelectionDAG &DAG, TargetLowering &TLI) {
|
2007-01-05 21:31:51 +00:00
|
|
|
MVT::ValueType VT = Node->getValueType(0);
|
2007-01-04 21:56:39 +00:00
|
|
|
MVT::ValueType SrcVT = Node->getOperand(1).getValueType();
|
2007-06-25 16:23:39 +00:00
|
|
|
assert((SrcVT == MVT::f32 || SrcVT == MVT::f64) &&
|
|
|
|
"fcopysign expansion only supported for f32 and f64");
|
2007-01-04 21:56:39 +00:00
|
|
|
MVT::ValueType SrcNVT = (SrcVT == MVT::f64) ? MVT::i64 : MVT::i32;
|
2007-01-05 21:31:51 +00:00
|
|
|
|
2007-01-04 21:56:39 +00:00
|
|
|
// First get the sign bit of second operand.
|
2007-01-05 21:31:51 +00:00
|
|
|
SDOperand Mask1 = (SrcVT == MVT::f64)
|
2007-01-04 21:56:39 +00:00
|
|
|
? DAG.getConstantFP(BitsToDouble(1ULL << 63), SrcVT)
|
|
|
|
: DAG.getConstantFP(BitsToFloat(1U << 31), SrcVT);
|
2007-01-05 21:31:51 +00:00
|
|
|
Mask1 = DAG.getNode(ISD::BIT_CONVERT, SrcNVT, Mask1);
|
2007-01-04 21:56:39 +00:00
|
|
|
SDOperand SignBit= DAG.getNode(ISD::BIT_CONVERT, SrcNVT, Node->getOperand(1));
|
2007-01-05 21:31:51 +00:00
|
|
|
SignBit = DAG.getNode(ISD::AND, SrcNVT, SignBit, Mask1);
|
2007-01-04 21:56:39 +00:00
|
|
|
// Shift right or sign-extend it if the two operands have different types.
|
|
|
|
int SizeDiff = MVT::getSizeInBits(SrcNVT) - MVT::getSizeInBits(NVT);
|
|
|
|
if (SizeDiff > 0) {
|
|
|
|
SignBit = DAG.getNode(ISD::SRL, SrcNVT, SignBit,
|
|
|
|
DAG.getConstant(SizeDiff, TLI.getShiftAmountTy()));
|
|
|
|
SignBit = DAG.getNode(ISD::TRUNCATE, NVT, SignBit);
|
|
|
|
} else if (SizeDiff < 0)
|
|
|
|
SignBit = DAG.getNode(ISD::SIGN_EXTEND, NVT, SignBit);
|
2007-01-05 21:31:51 +00:00
|
|
|
|
|
|
|
// Clear the sign bit of first operand.
|
|
|
|
SDOperand Mask2 = (VT == MVT::f64)
|
|
|
|
? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT)
|
|
|
|
: DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT);
|
|
|
|
Mask2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask2);
|
2007-01-04 21:56:39 +00:00
|
|
|
SDOperand Result = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0));
|
2007-01-05 21:31:51 +00:00
|
|
|
Result = DAG.getNode(ISD::AND, NVT, Result, Mask2);
|
|
|
|
|
|
|
|
// Or the value with the sign bit.
|
2007-01-04 21:56:39 +00:00
|
|
|
Result = DAG.getNode(ISD::OR, NVT, Result, SignBit);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2007-08-01 19:34:21 +00:00
|
|
|
/// ExpandUnalignedStore - Expands an unaligned store to 2 half-size stores.
|
|
|
|
static
|
|
|
|
SDOperand ExpandUnalignedStore(StoreSDNode *ST, SelectionDAG &DAG,
|
|
|
|
TargetLowering &TLI) {
|
|
|
|
SDOperand Chain = ST->getChain();
|
|
|
|
SDOperand Ptr = ST->getBasePtr();
|
|
|
|
SDOperand Val = ST->getValue();
|
|
|
|
MVT::ValueType VT = Val.getValueType();
|
2007-09-08 19:29:23 +00:00
|
|
|
int Alignment = ST->getAlignment();
|
|
|
|
int SVOffset = ST->getSrcValueOffset();
|
2008-02-27 22:36:00 +00:00
|
|
|
if (MVT::isFloatingPoint(ST->getMemoryVT()) ||
|
|
|
|
MVT::isVector(ST->getMemoryVT())) {
|
2007-09-08 19:29:23 +00:00
|
|
|
// Expand to a bitconvert of the value to the integer type of the
|
|
|
|
// same size, then a (misaligned) int store.
|
|
|
|
MVT::ValueType intVT;
|
2008-03-01 03:40:57 +00:00
|
|
|
if (MVT::is128BitVector(VT) || VT == MVT::ppcf128 || VT == MVT::f128)
|
2008-02-27 22:36:00 +00:00
|
|
|
intVT = MVT::i128;
|
2008-03-01 03:40:57 +00:00
|
|
|
else if (MVT::is64BitVector(VT) || VT==MVT::f64)
|
2007-09-08 19:29:23 +00:00
|
|
|
intVT = MVT::i64;
|
|
|
|
else if (VT==MVT::f32)
|
|
|
|
intVT = MVT::i32;
|
|
|
|
else
|
2008-02-28 18:36:51 +00:00
|
|
|
assert(0 && "Unaligned store of unsupported type");
|
2007-09-08 19:29:23 +00:00
|
|
|
|
|
|
|
SDOperand Result = DAG.getNode(ISD::BIT_CONVERT, intVT, Val);
|
|
|
|
return DAG.getStore(Chain, Result, Ptr, ST->getSrcValue(),
|
|
|
|
SVOffset, ST->isVolatile(), Alignment);
|
|
|
|
}
|
2008-01-30 00:15:11 +00:00
|
|
|
assert(MVT::isInteger(ST->getMemoryVT()) &&
|
2008-02-27 22:36:00 +00:00
|
|
|
!MVT::isVector(ST->getMemoryVT()) &&
|
2007-09-08 19:29:23 +00:00
|
|
|
"Unaligned store of unknown type.");
|
2007-08-01 19:34:21 +00:00
|
|
|
// Get the half-size VT
|
2008-01-30 00:15:11 +00:00
|
|
|
MVT::ValueType NewStoredVT = ST->getMemoryVT() - 1;
|
2007-08-01 19:34:21 +00:00
|
|
|
int NumBits = MVT::getSizeInBits(NewStoredVT);
|
|
|
|
int IncrementSize = NumBits / 8;
|
|
|
|
|
|
|
|
// Divide the stored value in two parts.
|
|
|
|
SDOperand ShiftAmount = DAG.getConstant(NumBits, TLI.getShiftAmountTy());
|
|
|
|
SDOperand Lo = Val;
|
|
|
|
SDOperand Hi = DAG.getNode(ISD::SRL, VT, Val, ShiftAmount);
|
|
|
|
|
|
|
|
// Store the two parts
|
|
|
|
SDOperand Store1, Store2;
|
|
|
|
Store1 = DAG.getTruncStore(Chain, TLI.isLittleEndian()?Lo:Hi, Ptr,
|
|
|
|
ST->getSrcValue(), SVOffset, NewStoredVT,
|
|
|
|
ST->isVolatile(), Alignment);
|
|
|
|
Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr,
|
|
|
|
DAG.getConstant(IncrementSize, TLI.getPointerTy()));
|
2007-10-28 12:59:45 +00:00
|
|
|
Alignment = MinAlign(Alignment, IncrementSize);
|
2007-08-01 19:34:21 +00:00
|
|
|
Store2 = DAG.getTruncStore(Chain, TLI.isLittleEndian()?Hi:Lo, Ptr,
|
|
|
|
ST->getSrcValue(), SVOffset + IncrementSize,
|
|
|
|
NewStoredVT, ST->isVolatile(), Alignment);
|
|
|
|
|
|
|
|
return DAG.getNode(ISD::TokenFactor, MVT::Other, Store1, Store2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ExpandUnalignedLoad - Expands an unaligned load to 2 half-size loads.
|
|
|
|
static
|
|
|
|
SDOperand ExpandUnalignedLoad(LoadSDNode *LD, SelectionDAG &DAG,
|
|
|
|
TargetLowering &TLI) {
|
|
|
|
int SVOffset = LD->getSrcValueOffset();
|
|
|
|
SDOperand Chain = LD->getChain();
|
|
|
|
SDOperand Ptr = LD->getBasePtr();
|
|
|
|
MVT::ValueType VT = LD->getValueType(0);
|
2008-01-30 00:15:11 +00:00
|
|
|
MVT::ValueType LoadedVT = LD->getMemoryVT();
|
2008-02-27 22:36:00 +00:00
|
|
|
if (MVT::isFloatingPoint(VT) || MVT::isVector(VT)) {
|
2007-09-08 19:29:23 +00:00
|
|
|
// Expand to a (misaligned) integer load of the same size,
|
2008-02-27 22:36:00 +00:00
|
|
|
// then bitconvert to floating point or vector.
|
2007-09-08 19:29:23 +00:00
|
|
|
MVT::ValueType intVT;
|
2008-03-01 03:40:57 +00:00
|
|
|
if (MVT::is128BitVector(LoadedVT) ||
|
|
|
|
LoadedVT == MVT::ppcf128 || LoadedVT == MVT::f128)
|
2008-02-27 22:36:00 +00:00
|
|
|
intVT = MVT::i128;
|
2008-03-01 03:40:57 +00:00
|
|
|
else if (MVT::is64BitVector(LoadedVT) || LoadedVT == MVT::f64)
|
2007-09-08 19:29:23 +00:00
|
|
|
intVT = MVT::i64;
|
2007-11-19 21:38:03 +00:00
|
|
|
else if (LoadedVT == MVT::f32)
|
2007-09-08 19:29:23 +00:00
|
|
|
intVT = MVT::i32;
|
|
|
|
else
|
2008-02-27 22:36:00 +00:00
|
|
|
assert(0 && "Unaligned load of unsupported type");
|
2007-09-08 19:29:23 +00:00
|
|
|
|
|
|
|
SDOperand newLoad = DAG.getLoad(intVT, Chain, Ptr, LD->getSrcValue(),
|
|
|
|
SVOffset, LD->isVolatile(),
|
|
|
|
LD->getAlignment());
|
|
|
|
SDOperand Result = DAG.getNode(ISD::BIT_CONVERT, LoadedVT, newLoad);
|
2008-02-27 22:36:00 +00:00
|
|
|
if (MVT::isFloatingPoint(VT) && LoadedVT != VT)
|
2007-09-08 19:29:23 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_EXTEND, VT, Result);
|
|
|
|
|
|
|
|
SDOperand Ops[] = { Result, Chain };
|
|
|
|
return DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other),
|
|
|
|
Ops, 2);
|
|
|
|
}
|
2008-02-27 22:36:00 +00:00
|
|
|
assert(MVT::isInteger(LoadedVT) && !MVT::isVector(LoadedVT) &&
|
2007-11-19 21:38:03 +00:00
|
|
|
"Unaligned load of unsupported type.");
|
|
|
|
|
2008-02-27 22:36:00 +00:00
|
|
|
// Compute the new VT that is half the size of the old one. This is an
|
|
|
|
// integer MVT.
|
2007-11-19 21:38:03 +00:00
|
|
|
unsigned NumBits = MVT::getSizeInBits(LoadedVT);
|
|
|
|
MVT::ValueType NewLoadedVT;
|
2008-02-27 22:36:00 +00:00
|
|
|
NewLoadedVT = MVT::getIntegerType(NumBits/2);
|
2007-11-19 21:38:03 +00:00
|
|
|
NumBits >>= 1;
|
|
|
|
|
|
|
|
unsigned Alignment = LD->getAlignment();
|
|
|
|
unsigned IncrementSize = NumBits / 8;
|
2007-08-01 19:34:21 +00:00
|
|
|
ISD::LoadExtType HiExtType = LD->getExtensionType();
|
|
|
|
|
|
|
|
// If the original load is NON_EXTLOAD, the hi part load must be ZEXTLOAD.
|
|
|
|
if (HiExtType == ISD::NON_EXTLOAD)
|
|
|
|
HiExtType = ISD::ZEXTLOAD;
|
|
|
|
|
|
|
|
// Load the value in two parts
|
|
|
|
SDOperand Lo, Hi;
|
|
|
|
if (TLI.isLittleEndian()) {
|
|
|
|
Lo = DAG.getExtLoad(ISD::ZEXTLOAD, VT, Chain, Ptr, LD->getSrcValue(),
|
|
|
|
SVOffset, NewLoadedVT, LD->isVolatile(), Alignment);
|
|
|
|
Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr,
|
|
|
|
DAG.getConstant(IncrementSize, TLI.getPointerTy()));
|
|
|
|
Hi = DAG.getExtLoad(HiExtType, VT, Chain, Ptr, LD->getSrcValue(),
|
|
|
|
SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(),
|
2007-10-28 12:59:45 +00:00
|
|
|
MinAlign(Alignment, IncrementSize));
|
2007-08-01 19:34:21 +00:00
|
|
|
} else {
|
|
|
|
Hi = DAG.getExtLoad(HiExtType, VT, Chain, Ptr, LD->getSrcValue(), SVOffset,
|
|
|
|
NewLoadedVT,LD->isVolatile(), Alignment);
|
|
|
|
Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr,
|
|
|
|
DAG.getConstant(IncrementSize, TLI.getPointerTy()));
|
|
|
|
Lo = DAG.getExtLoad(ISD::ZEXTLOAD, VT, Chain, Ptr, LD->getSrcValue(),
|
|
|
|
SVOffset + IncrementSize, NewLoadedVT, LD->isVolatile(),
|
2007-10-28 12:59:45 +00:00
|
|
|
MinAlign(Alignment, IncrementSize));
|
2007-08-01 19:34:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// aggregate the two parts
|
|
|
|
SDOperand ShiftAmount = DAG.getConstant(NumBits, TLI.getShiftAmountTy());
|
|
|
|
SDOperand Result = DAG.getNode(ISD::SHL, VT, Hi, ShiftAmount);
|
|
|
|
Result = DAG.getNode(ISD::OR, VT, Result, Lo);
|
|
|
|
|
|
|
|
SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1),
|
|
|
|
Hi.getValue(1));
|
|
|
|
|
|
|
|
SDOperand Ops[] = { Result, TF };
|
|
|
|
return DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other), Ops, 2);
|
|
|
|
}
|
2007-01-04 21:56:39 +00:00
|
|
|
|
2007-10-11 23:57:53 +00:00
|
|
|
/// UnrollVectorOp - We know that the given vector has a legal type, however
|
|
|
|
/// the operation it performs is not legal and is an operation that we have
|
|
|
|
/// no way of lowering. "Unroll" the vector, splitting out the scalars and
|
|
|
|
/// operating on each element individually.
|
|
|
|
SDOperand SelectionDAGLegalize::UnrollVectorOp(SDOperand Op) {
|
|
|
|
MVT::ValueType VT = Op.getValueType();
|
|
|
|
assert(isTypeLegal(VT) &&
|
|
|
|
"Caller should expand or promote operands that are not legal!");
|
|
|
|
assert(Op.Val->getNumValues() == 1 &&
|
|
|
|
"Can't unroll a vector with multiple results!");
|
|
|
|
unsigned NE = MVT::getVectorNumElements(VT);
|
|
|
|
MVT::ValueType EltVT = MVT::getVectorElementType(VT);
|
|
|
|
|
|
|
|
SmallVector<SDOperand, 8> Scalars;
|
|
|
|
SmallVector<SDOperand, 4> Operands(Op.getNumOperands());
|
|
|
|
for (unsigned i = 0; i != NE; ++i) {
|
|
|
|
for (unsigned j = 0; j != Op.getNumOperands(); ++j) {
|
|
|
|
SDOperand Operand = Op.getOperand(j);
|
|
|
|
MVT::ValueType OperandVT = Operand.getValueType();
|
|
|
|
if (MVT::isVector(OperandVT)) {
|
|
|
|
// A vector operand; extract a single element.
|
|
|
|
MVT::ValueType OperandEltVT = MVT::getVectorElementType(OperandVT);
|
|
|
|
Operands[j] = DAG.getNode(ISD::EXTRACT_VECTOR_ELT,
|
|
|
|
OperandEltVT,
|
|
|
|
Operand,
|
|
|
|
DAG.getConstant(i, MVT::i32));
|
|
|
|
} else {
|
|
|
|
// A scalar operand; just use it as is.
|
|
|
|
Operands[j] = Operand;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Scalars.push_back(DAG.getNode(Op.getOpcode(), EltVT,
|
|
|
|
&Operands[0], Operands.size()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return DAG.getNode(ISD::BUILD_VECTOR, VT, &Scalars[0], Scalars.size());
|
|
|
|
}
|
|
|
|
|
2008-01-10 10:28:30 +00:00
|
|
|
/// GetFPLibCall - Return the right libcall for the given floating point type.
|
|
|
|
static RTLIB::Libcall GetFPLibCall(MVT::ValueType VT,
|
|
|
|
RTLIB::Libcall Call_F32,
|
|
|
|
RTLIB::Libcall Call_F64,
|
|
|
|
RTLIB::Libcall Call_F80,
|
|
|
|
RTLIB::Libcall Call_PPCF128) {
|
|
|
|
return
|
|
|
|
VT == MVT::f32 ? Call_F32 :
|
|
|
|
VT == MVT::f64 ? Call_F64 :
|
|
|
|
VT == MVT::f80 ? Call_F80 :
|
|
|
|
VT == MVT::ppcf128 ? Call_PPCF128 :
|
|
|
|
RTLIB::UNKNOWN_LIBCALL;
|
|
|
|
}
|
|
|
|
|
2008-04-25 18:07:40 +00:00
|
|
|
/// PerformInsertVectorEltInMemory - Some target cannot handle a variable
|
|
|
|
/// insertion index for the INSERT_VECTOR_ELT instruction. In this case, it
|
|
|
|
/// is necessary to spill the vector being inserted into to memory, perform
|
|
|
|
/// the insert there, and then read the result back.
|
|
|
|
SDOperand SelectionDAGLegalize::
|
|
|
|
PerformInsertVectorEltInMemory(SDOperand Vec, SDOperand Val, SDOperand Idx) {
|
|
|
|
SDOperand Tmp1 = Vec;
|
|
|
|
SDOperand Tmp2 = Val;
|
|
|
|
SDOperand Tmp3 = Idx;
|
|
|
|
|
|
|
|
// If the target doesn't support this, we have to spill the input vector
|
|
|
|
// to a temporary stack slot, update the element, then reload it. This is
|
|
|
|
// badness. We could also load the value into a vector register (either
|
|
|
|
// with a "move to register" or "extload into register" instruction, then
|
|
|
|
// permute it into place, if the idx is a constant and if the idx is
|
|
|
|
// supported by the target.
|
|
|
|
MVT::ValueType VT = Tmp1.getValueType();
|
|
|
|
MVT::ValueType EltVT = MVT::getVectorElementType(VT);
|
|
|
|
MVT::ValueType IdxVT = Tmp3.getValueType();
|
|
|
|
MVT::ValueType PtrVT = TLI.getPointerTy();
|
|
|
|
SDOperand StackPtr = DAG.CreateStackTemporary(VT);
|
|
|
|
|
|
|
|
FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(StackPtr.Val);
|
|
|
|
int SPFI = StackPtrFI->getIndex();
|
|
|
|
|
|
|
|
// Store the vector.
|
|
|
|
SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Tmp1, StackPtr,
|
|
|
|
PseudoSourceValue::getFixedStack(),
|
|
|
|
SPFI);
|
|
|
|
|
|
|
|
// Truncate or zero extend offset to target pointer type.
|
|
|
|
unsigned CastOpc = (IdxVT > PtrVT) ? ISD::TRUNCATE : ISD::ZERO_EXTEND;
|
|
|
|
Tmp3 = DAG.getNode(CastOpc, PtrVT, Tmp3);
|
|
|
|
// Add the offset to the index.
|
|
|
|
unsigned EltSize = MVT::getSizeInBits(EltVT)/8;
|
|
|
|
Tmp3 = DAG.getNode(ISD::MUL, IdxVT, Tmp3,DAG.getConstant(EltSize, IdxVT));
|
|
|
|
SDOperand StackPtr2 = DAG.getNode(ISD::ADD, IdxVT, Tmp3, StackPtr);
|
|
|
|
// Store the scalar value.
|
|
|
|
Ch = DAG.getTruncStore(Ch, Tmp2, StackPtr2,
|
|
|
|
PseudoSourceValue::getFixedStack(), SPFI, EltVT);
|
|
|
|
// Load the updated vector.
|
|
|
|
return DAG.getLoad(VT, Ch, StackPtr, PseudoSourceValue::getFixedStack(),SPFI);
|
|
|
|
}
|
|
|
|
|
2007-07-13 20:14:11 +00:00
|
|
|
/// LegalizeOp - We know that the specified value has a legal type, and
|
|
|
|
/// that its operands are legal. Now ensure that the operation itself
|
|
|
|
/// is legal, recursively ensuring that the operands' operations remain
|
|
|
|
/// legal.
|
2005-01-07 07:47:09 +00:00
|
|
|
SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
|
2007-08-25 01:00:22 +00:00
|
|
|
if (Op.getOpcode() == ISD::TargetConstant) // Allow illegal target nodes.
|
|
|
|
return Op;
|
|
|
|
|
2005-08-24 16:35:28 +00:00
|
|
|
assert(isTypeLegal(Op.getValueType()) &&
|
2005-01-08 20:35:13 +00:00
|
|
|
"Caller should expand or promote operands that are not legal!");
|
2005-05-12 16:53:42 +00:00
|
|
|
SDNode *Node = Op.Val;
|
2005-01-08 20:35:13 +00:00
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
// If this operation defines any values that cannot be represented in a
|
2005-01-08 20:35:13 +00:00
|
|
|
// register on this target, make sure to expand or promote them.
|
2005-05-12 16:53:42 +00:00
|
|
|
if (Node->getNumValues() > 1) {
|
|
|
|
for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i)
|
2006-03-18 01:44:44 +00:00
|
|
|
if (getTypeAction(Node->getValueType(i)) != Legal) {
|
|
|
|
HandleOp(Op.getValue(i));
|
2005-01-07 07:47:09 +00:00
|
|
|
assert(LegalizedNodes.count(Op) &&
|
2006-03-18 01:44:44 +00:00
|
|
|
"Handling didn't add legal operands!");
|
2005-01-15 05:21:40 +00:00
|
|
|
return LegalizedNodes[Op];
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-12 16:53:42 +00:00
|
|
|
// Note that LegalizeOp may be reentered even from single-use nodes, which
|
|
|
|
// means that we always must cache transformed nodes.
|
2008-04-16 16:15:27 +00:00
|
|
|
DenseMap<SDOperand, SDOperand>::iterator I = LegalizedNodes.find(Op);
|
2005-01-11 05:57:22 +00:00
|
|
|
if (I != LegalizedNodes.end()) return I->second;
|
2005-01-07 07:47:09 +00:00
|
|
|
|
2005-08-10 20:51:12 +00:00
|
|
|
SDOperand Tmp1, Tmp2, Tmp3, Tmp4;
|
2005-01-07 07:47:09 +00:00
|
|
|
SDOperand Result = Op;
|
2006-01-28 07:39:30 +00:00
|
|
|
bool isCustom = false;
|
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
switch (Node->getOpcode()) {
|
2006-01-28 08:31:04 +00:00
|
|
|
case ISD::FrameIndex:
|
|
|
|
case ISD::EntryToken:
|
|
|
|
case ISD::Register:
|
|
|
|
case ISD::BasicBlock:
|
|
|
|
case ISD::TargetFrameIndex:
|
2006-04-22 18:53:45 +00:00
|
|
|
case ISD::TargetJumpTable:
|
2006-01-28 08:31:04 +00:00
|
|
|
case ISD::TargetConstant:
|
2006-01-29 06:26:56 +00:00
|
|
|
case ISD::TargetConstantFP:
|
2006-01-28 08:31:04 +00:00
|
|
|
case ISD::TargetConstantPool:
|
|
|
|
case ISD::TargetGlobalAddress:
|
2007-04-20 21:38:10 +00:00
|
|
|
case ISD::TargetGlobalTLSAddress:
|
2006-01-28 08:31:04 +00:00
|
|
|
case ISD::TargetExternalSymbol:
|
|
|
|
case ISD::VALUETYPE:
|
|
|
|
case ISD::SRCVALUE:
|
2008-02-06 22:27:42 +00:00
|
|
|
case ISD::MEMOPERAND:
|
2006-01-28 08:31:04 +00:00
|
|
|
case ISD::STRING:
|
|
|
|
case ISD::CONDCODE:
|
2008-03-21 09:14:45 +00:00
|
|
|
case ISD::ARG_FLAGS:
|
2006-01-28 08:31:04 +00:00
|
|
|
// Primitives must all be legal.
|
2007-10-16 09:07:20 +00:00
|
|
|
assert(TLI.isOperationLegal(Node->getOpcode(), Node->getValueType(0)) &&
|
2006-01-28 08:31:04 +00:00
|
|
|
"This must be legal!");
|
|
|
|
break;
|
2005-01-07 07:47:09 +00:00
|
|
|
default:
|
2005-05-14 06:34:48 +00:00
|
|
|
if (Node->getOpcode() >= ISD::BUILTIN_OP_END) {
|
|
|
|
// If this is a target node, legalize it by legalizing the operands then
|
|
|
|
// passing it through.
|
2006-08-08 01:09:31 +00:00
|
|
|
SmallVector<SDOperand, 8> Ops;
|
2006-05-17 18:00:08 +00:00
|
|
|
for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
|
2005-05-14 06:34:48 +00:00
|
|
|
Ops.push_back(LegalizeOp(Node->getOperand(i)));
|
2006-05-17 18:00:08 +00:00
|
|
|
|
2006-08-08 01:09:31 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result.getValue(0), &Ops[0], Ops.size());
|
2005-05-14 06:34:48 +00:00
|
|
|
|
|
|
|
for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i)
|
|
|
|
AddLegalizedOperand(Op.getValue(i), Result.getValue(i));
|
|
|
|
return Result.getValue(Op.ResNo);
|
|
|
|
}
|
|
|
|
// Otherwise this is an unhandled builtin node. splat.
|
2006-07-11 17:58:07 +00:00
|
|
|
#ifndef NDEBUG
|
2007-06-04 16:17:33 +00:00
|
|
|
cerr << "NODE: "; Node->dump(&DAG); cerr << "\n";
|
2006-07-11 17:58:07 +00:00
|
|
|
#endif
|
2005-01-07 07:47:09 +00:00
|
|
|
assert(0 && "Do not know how to legalize this operator!");
|
|
|
|
abort();
|
2007-04-20 23:02:39 +00:00
|
|
|
case ISD::GLOBAL_OFFSET_TABLE:
|
2005-01-07 07:47:09 +00:00
|
|
|
case ISD::GlobalAddress:
|
2007-04-20 21:38:10 +00:00
|
|
|
case ISD::GlobalTLSAddress:
|
2005-01-07 21:45:56 +00:00
|
|
|
case ISD::ExternalSymbol:
|
2006-04-22 18:53:45 +00:00
|
|
|
case ISD::ConstantPool:
|
|
|
|
case ISD::JumpTable: // Nothing to do.
|
2005-11-17 06:41:44 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-28 08:31:04 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Op, DAG);
|
|
|
|
if (Tmp1.Val) Result = Tmp1;
|
|
|
|
// FALLTHROUGH if the target doesn't want to lower this op after all.
|
2005-11-17 06:41:44 +00:00
|
|
|
case TargetLowering::Legal:
|
|
|
|
break;
|
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
2007-01-29 22:58:52 +00:00
|
|
|
case ISD::FRAMEADDR:
|
|
|
|
case ISD::RETURNADDR:
|
|
|
|
// The only option for these nodes is to custom lower them. If the target
|
|
|
|
// does not custom lower them, then return zero.
|
|
|
|
Tmp1 = TLI.LowerOperation(Op, DAG);
|
|
|
|
if (Tmp1.Val)
|
|
|
|
Result = Tmp1;
|
|
|
|
else
|
|
|
|
Result = DAG.getConstant(0, TLI.getPointerTy());
|
|
|
|
break;
|
2007-08-29 23:18:48 +00:00
|
|
|
case ISD::FRAME_TO_ARGS_OFFSET: {
|
2007-08-29 19:28:29 +00:00
|
|
|
MVT::ValueType VT = Node->getValueType(0);
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), VT)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Op, DAG);
|
|
|
|
if (Result.Val) break;
|
|
|
|
// Fall Thru
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
Result = DAG.getConstant(0, VT);
|
|
|
|
break;
|
|
|
|
}
|
2007-08-29 23:18:48 +00:00
|
|
|
}
|
2007-08-29 19:28:29 +00:00
|
|
|
break;
|
2007-02-22 15:37:19 +00:00
|
|
|
case ISD::EXCEPTIONADDR: {
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
MVT::ValueType VT = Node->getValueType(0);
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), VT)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Expand: {
|
2007-02-28 20:43:58 +00:00
|
|
|
unsigned Reg = TLI.getExceptionAddressRegister();
|
2007-12-31 18:35:50 +00:00
|
|
|
Result = DAG.getCopyFromReg(Tmp1, Reg, VT);
|
2007-02-22 15:37:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Op, DAG);
|
|
|
|
if (Result.Val) break;
|
|
|
|
// Fall Thru
|
2007-04-27 17:12:52 +00:00
|
|
|
case TargetLowering::Legal: {
|
|
|
|
SDOperand Ops[] = { DAG.getConstant(0, VT), Tmp1 };
|
|
|
|
Result = DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other),
|
2007-12-31 18:35:50 +00:00
|
|
|
Ops, 2);
|
2007-02-28 20:43:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-04-27 17:12:52 +00:00
|
|
|
}
|
2007-12-31 18:35:50 +00:00
|
|
|
if (Result.Val->getNumValues() == 1) break;
|
|
|
|
|
|
|
|
assert(Result.Val->getNumValues() == 2 &&
|
|
|
|
"Cannot return more than two values!");
|
|
|
|
|
|
|
|
// Since we produced two values, make sure to remember that we
|
|
|
|
// legalized both of them.
|
|
|
|
Tmp1 = LegalizeOp(Result);
|
|
|
|
Tmp2 = LegalizeOp(Result.getValue(1));
|
|
|
|
AddLegalizedOperand(Op.getValue(0), Tmp1);
|
|
|
|
AddLegalizedOperand(Op.getValue(1), Tmp2);
|
|
|
|
return Op.ResNo ? Tmp2 : Tmp1;
|
2007-02-28 20:43:58 +00:00
|
|
|
case ISD::EHSELECTION: {
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1));
|
|
|
|
MVT::ValueType VT = Node->getValueType(0);
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), VT)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Expand: {
|
|
|
|
unsigned Reg = TLI.getExceptionSelectorRegister();
|
2007-12-31 18:35:50 +00:00
|
|
|
Result = DAG.getCopyFromReg(Tmp2, Reg, VT);
|
2007-02-28 20:43:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Op, DAG);
|
|
|
|
if (Result.Val) break;
|
|
|
|
// Fall Thru
|
2007-04-27 17:12:52 +00:00
|
|
|
case TargetLowering::Legal: {
|
|
|
|
SDOperand Ops[] = { DAG.getConstant(0, VT), Tmp2 };
|
|
|
|
Result = DAG.getNode(ISD::MERGE_VALUES, DAG.getVTList(VT, MVT::Other),
|
2007-12-31 18:35:50 +00:00
|
|
|
Ops, 2);
|
2007-02-22 15:37:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-04-27 17:12:52 +00:00
|
|
|
}
|
2007-12-31 18:35:50 +00:00
|
|
|
if (Result.Val->getNumValues() == 1) break;
|
|
|
|
|
|
|
|
assert(Result.Val->getNumValues() == 2 &&
|
|
|
|
"Cannot return more than two values!");
|
|
|
|
|
|
|
|
// Since we produced two values, make sure to remember that we
|
|
|
|
// legalized both of them.
|
|
|
|
Tmp1 = LegalizeOp(Result);
|
|
|
|
Tmp2 = LegalizeOp(Result.getValue(1));
|
|
|
|
AddLegalizedOperand(Op.getValue(0), Tmp1);
|
|
|
|
AddLegalizedOperand(Op.getValue(1), Tmp2);
|
|
|
|
return Op.ResNo ? Tmp2 : Tmp1;
|
2007-07-14 15:11:14 +00:00
|
|
|
case ISD::EH_RETURN: {
|
2007-07-14 14:06:15 +00:00
|
|
|
MVT::ValueType VT = Node->getValueType(0);
|
|
|
|
// The only "good" option for this node is to custom lower it.
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), VT)) {
|
|
|
|
default: assert(0 && "This action is not supported at all!");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Op, DAG);
|
|
|
|
if (Result.Val) break;
|
|
|
|
// Fall Thru
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
// Target does not know, how to lower this, lower to noop
|
|
|
|
Result = LegalizeOp(Node->getOperand(0));
|
|
|
|
break;
|
|
|
|
}
|
2007-07-14 15:11:14 +00:00
|
|
|
}
|
2007-07-14 14:06:15 +00:00
|
|
|
break;
|
2005-09-02 01:15:01 +00:00
|
|
|
case ISD::AssertSext:
|
|
|
|
case ISD::AssertZext:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1));
|
2005-09-02 01:15:01 +00:00
|
|
|
break;
|
2005-11-20 22:56:56 +00:00
|
|
|
case ISD::MERGE_VALUES:
|
2006-01-28 10:58:55 +00:00
|
|
|
// Legalize eliminates MERGE_VALUES nodes.
|
2006-01-28 07:39:30 +00:00
|
|
|
Result = Node->getOperand(Op.ResNo);
|
|
|
|
break;
|
2005-01-14 22:38:01 +00:00
|
|
|
case ISD::CopyFromReg:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
2005-12-18 15:27:43 +00:00
|
|
|
Result = Op.getValue(0);
|
2005-12-18 15:36:21 +00:00
|
|
|
if (Node->getNumValues() == 2) {
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1));
|
2005-12-18 15:27:43 +00:00
|
|
|
} else {
|
2005-12-18 15:36:21 +00:00
|
|
|
assert(Node->getNumValues() == 3 && "Invalid copyfromreg!");
|
2006-01-28 10:58:55 +00:00
|
|
|
if (Node->getNumOperands() == 3) {
|
2005-12-18 15:36:21 +00:00
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(2));
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2);
|
|
|
|
} else {
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1));
|
|
|
|
}
|
2005-12-18 15:27:43 +00:00
|
|
|
AddLegalizedOperand(Op.getValue(2), Result.getValue(2));
|
|
|
|
}
|
2005-01-28 06:27:38 +00:00
|
|
|
// Since CopyFromReg produces two values, make sure to remember that we
|
|
|
|
// legalized both of them.
|
|
|
|
AddLegalizedOperand(Op.getValue(0), Result);
|
|
|
|
AddLegalizedOperand(Op.getValue(1), Result.getValue(1));
|
|
|
|
return Result.getValue(Op.ResNo);
|
2005-04-01 22:34:39 +00:00
|
|
|
case ISD::UNDEF: {
|
|
|
|
MVT::ValueType VT = Op.getValueType();
|
|
|
|
switch (TLI.getOperationAction(ISD::UNDEF, VT)) {
|
2005-04-02 00:41:14 +00:00
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Expand:
|
2005-04-01 22:34:39 +00:00
|
|
|
if (MVT::isInteger(VT))
|
|
|
|
Result = DAG.getConstant(0, VT);
|
|
|
|
else if (MVT::isFloatingPoint(VT))
|
2007-09-26 17:26:49 +00:00
|
|
|
Result = DAG.getConstantFP(APFloat(APInt(MVT::getSizeInBits(VT), 0)),
|
|
|
|
VT);
|
2005-04-01 22:34:39 +00:00
|
|
|
else
|
|
|
|
assert(0 && "Unknown value type!");
|
|
|
|
break;
|
2005-04-02 00:41:14 +00:00
|
|
|
case TargetLowering::Legal:
|
2005-04-01 22:34:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-03-24 02:26:29 +00:00
|
|
|
|
2006-03-28 00:40:33 +00:00
|
|
|
case ISD::INTRINSIC_W_CHAIN:
|
|
|
|
case ISD::INTRINSIC_WO_CHAIN:
|
|
|
|
case ISD::INTRINSIC_VOID: {
|
2006-08-08 01:09:31 +00:00
|
|
|
SmallVector<SDOperand, 8> Ops;
|
2006-03-24 02:26:29 +00:00
|
|
|
for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
|
|
|
|
Ops.push_back(LegalizeOp(Node->getOperand(i)));
|
2006-08-08 01:09:31 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size());
|
2006-03-26 09:12:51 +00:00
|
|
|
|
|
|
|
// Allow the target to custom lower its intrinsics if it wants to.
|
2006-03-28 00:40:33 +00:00
|
|
|
if (TLI.getOperationAction(Node->getOpcode(), MVT::Other) ==
|
2006-03-26 09:12:51 +00:00
|
|
|
TargetLowering::Custom) {
|
|
|
|
Tmp3 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp3.Val) Result = Tmp3;
|
2006-03-27 20:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Result.Val->getNumValues() == 1) break;
|
|
|
|
|
|
|
|
// Must have return value and chain result.
|
|
|
|
assert(Result.Val->getNumValues() == 2 &&
|
|
|
|
"Cannot return more than two values!");
|
|
|
|
|
|
|
|
// Since loads produce two values, make sure to remember that we
|
|
|
|
// legalized both of them.
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0));
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1));
|
|
|
|
return Result.getValue(Op.ResNo);
|
2006-03-24 02:26:29 +00:00
|
|
|
}
|
2005-11-29 06:21:05 +00:00
|
|
|
|
|
|
|
case ISD::LOCATION:
|
|
|
|
assert(Node->getNumOperands() == 5 && "Invalid LOCATION node!");
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input chain.
|
|
|
|
|
|
|
|
switch (TLI.getOperationAction(ISD::LOCATION, MVT::Other)) {
|
|
|
|
case TargetLowering::Promote:
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2005-12-16 22:45:29 +00:00
|
|
|
case TargetLowering::Expand: {
|
2007-01-26 21:22:28 +00:00
|
|
|
MachineModuleInfo *MMI = DAG.getMachineModuleInfo();
|
2006-01-05 01:25:28 +00:00
|
|
|
bool useDEBUG_LOC = TLI.isOperationLegal(ISD::DEBUG_LOC, MVT::Other);
|
2007-01-26 14:34:52 +00:00
|
|
|
bool useLABEL = TLI.isOperationLegal(ISD::LABEL, MVT::Other);
|
2006-01-05 01:25:28 +00:00
|
|
|
|
2007-01-26 21:22:28 +00:00
|
|
|
if (MMI && (useDEBUG_LOC || useLABEL)) {
|
2006-01-05 01:25:28 +00:00
|
|
|
const std::string &FName =
|
2005-12-21 20:51:37 +00:00
|
|
|
cast<StringSDNode>(Node->getOperand(3))->getValue();
|
2006-01-05 01:25:28 +00:00
|
|
|
const std::string &DirName =
|
2005-12-21 20:51:37 +00:00
|
|
|
cast<StringSDNode>(Node->getOperand(4))->getValue();
|
2007-01-26 21:22:28 +00:00
|
|
|
unsigned SrcFile = MMI->RecordSource(DirName, FName);
|
2006-01-05 01:25:28 +00:00
|
|
|
|
2006-08-08 02:23:42 +00:00
|
|
|
SmallVector<SDOperand, 8> Ops;
|
2006-01-05 01:25:28 +00:00
|
|
|
Ops.push_back(Tmp1); // chain
|
|
|
|
SDOperand LineOp = Node->getOperand(1);
|
|
|
|
SDOperand ColOp = Node->getOperand(2);
|
|
|
|
|
|
|
|
if (useDEBUG_LOC) {
|
|
|
|
Ops.push_back(LineOp); // line #
|
|
|
|
Ops.push_back(ColOp); // col #
|
|
|
|
Ops.push_back(DAG.getConstant(SrcFile, MVT::i32)); // source file id
|
2006-08-08 02:23:42 +00:00
|
|
|
Result = DAG.getNode(ISD::DEBUG_LOC, MVT::Other, &Ops[0], Ops.size());
|
2006-01-05 01:25:28 +00:00
|
|
|
} else {
|
2006-02-15 19:34:44 +00:00
|
|
|
unsigned Line = cast<ConstantSDNode>(LineOp)->getValue();
|
|
|
|
unsigned Col = cast<ConstantSDNode>(ColOp)->getValue();
|
2008-02-01 02:05:57 +00:00
|
|
|
unsigned ID = MMI->RecordSourceLine(Line, Col, SrcFile);
|
2006-01-05 01:25:28 +00:00
|
|
|
Ops.push_back(DAG.getConstant(ID, MVT::i32));
|
2008-01-31 09:59:15 +00:00
|
|
|
Ops.push_back(DAG.getConstant(0, MVT::i32)); // a debug label
|
|
|
|
Result = DAG.getNode(ISD::LABEL, MVT::Other, &Ops[0], Ops.size());
|
2006-01-05 01:25:28 +00:00
|
|
|
}
|
2005-12-21 20:51:37 +00:00
|
|
|
} else {
|
|
|
|
Result = Tmp1; // chain
|
|
|
|
}
|
2005-11-29 06:21:05 +00:00
|
|
|
break;
|
2005-12-18 23:54:29 +00:00
|
|
|
}
|
2005-11-29 06:21:05 +00:00
|
|
|
case TargetLowering::Legal:
|
2005-12-01 18:21:35 +00:00
|
|
|
if (Tmp1 != Node->getOperand(0) ||
|
|
|
|
getTypeAction(Node->getOperand(1).getValueType()) == Promote) {
|
2006-08-08 01:09:31 +00:00
|
|
|
SmallVector<SDOperand, 8> Ops;
|
2005-11-29 06:21:05 +00:00
|
|
|
Ops.push_back(Tmp1);
|
2005-12-01 18:21:35 +00:00
|
|
|
if (getTypeAction(Node->getOperand(1).getValueType()) == Legal) {
|
|
|
|
Ops.push_back(Node->getOperand(1)); // line # must be legal.
|
|
|
|
Ops.push_back(Node->getOperand(2)); // col # must be legal.
|
|
|
|
} else {
|
|
|
|
// Otherwise promote them.
|
|
|
|
Ops.push_back(PromoteOp(Node->getOperand(1)));
|
|
|
|
Ops.push_back(PromoteOp(Node->getOperand(2)));
|
|
|
|
}
|
2005-11-29 06:21:05 +00:00
|
|
|
Ops.push_back(Node->getOperand(3)); // filename must be legal.
|
|
|
|
Ops.push_back(Node->getOperand(4)); // working dir # must be legal.
|
2006-08-08 01:09:31 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size());
|
2005-11-29 06:21:05 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2008-02-02 04:07:54 +00:00
|
|
|
|
|
|
|
case ISD::DECLARE:
|
|
|
|
assert(Node->getNumOperands() == 3 && "Invalid DECLARE node!");
|
|
|
|
switch (TLI.getOperationAction(ISD::DECLARE, MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the address.
|
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the variable.
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
|
|
|
break;
|
2008-02-28 05:53:40 +00:00
|
|
|
case TargetLowering::Expand:
|
|
|
|
Result = LegalizeOp(Node->getOperand(0));
|
|
|
|
break;
|
2008-02-02 04:07:54 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-12-16 22:45:29 +00:00
|
|
|
|
|
|
|
case ISD::DEBUG_LOC:
|
2006-01-05 01:25:28 +00:00
|
|
|
assert(Node->getNumOperands() == 4 && "Invalid DEBUG_LOC node!");
|
2005-12-16 22:45:29 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::DEBUG_LOC, MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-05 01:25:28 +00:00
|
|
|
case TargetLowering::Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the line #.
|
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the col #.
|
|
|
|
Tmp4 = LegalizeOp(Node->getOperand(3)); // Legalize the source file id.
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4);
|
2006-01-05 01:25:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-01-26 14:34:52 +00:00
|
|
|
case ISD::LABEL:
|
2008-01-31 09:59:15 +00:00
|
|
|
assert(Node->getNumOperands() == 3 && "Invalid LABEL node!");
|
2007-01-26 14:34:52 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::LABEL, MVT::Other)) {
|
2006-01-05 01:25:28 +00:00
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the label id.
|
2008-01-31 09:59:15 +00:00
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the "flavor" operand.
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
2005-12-16 22:45:29 +00:00
|
|
|
break;
|
2007-03-03 19:21:38 +00:00
|
|
|
case TargetLowering::Expand:
|
|
|
|
Result = LegalizeOp(Node->getOperand(0));
|
|
|
|
break;
|
2005-12-16 22:45:29 +00:00
|
|
|
}
|
2006-02-17 05:43:56 +00:00
|
|
|
break;
|
2005-11-29 06:21:05 +00:00
|
|
|
|
2008-03-08 00:58:38 +00:00
|
|
|
case ISD::PREFETCH:
|
|
|
|
assert(Node->getNumOperands() == 4 && "Invalid Prefetch node!");
|
|
|
|
switch (TLI.getOperationAction(ISD::PREFETCH, MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the address.
|
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the rw specifier.
|
|
|
|
Tmp4 = LegalizeOp(Node->getOperand(3)); // Legalize locality specifier.
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4);
|
|
|
|
break;
|
|
|
|
case TargetLowering::Expand:
|
|
|
|
// It's a noop.
|
|
|
|
Result = LegalizeOp(Node->getOperand(0));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-02-16 01:24:58 +00:00
|
|
|
case ISD::MEMBARRIER: {
|
|
|
|
assert(Node->getNumOperands() == 6 && "Invalid MemBarrier node!");
|
2008-02-16 14:46:26 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::MEMBARRIER, MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal: {
|
|
|
|
SDOperand Ops[6];
|
|
|
|
Ops[0] = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
2008-02-27 08:53:44 +00:00
|
|
|
for (int x = 1; x < 6; ++x) {
|
|
|
|
Ops[x] = Node->getOperand(x);
|
|
|
|
if (!isTypeLegal(Ops[x].getValueType()))
|
|
|
|
Ops[x] = PromoteOp(Ops[x]);
|
|
|
|
}
|
2008-02-16 14:46:26 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], 6);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TargetLowering::Expand:
|
|
|
|
//There is no libgcc call for this op
|
|
|
|
Result = Node->getOperand(0); // Noop
|
|
|
|
break;
|
|
|
|
}
|
2008-02-16 01:24:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-05 19:05:59 +00:00
|
|
|
case ISD::ATOMIC_LCS: {
|
|
|
|
unsigned int num_operands = 4;
|
|
|
|
assert(Node->getNumOperands() == num_operands && "Invalid Atomic node!");
|
|
|
|
SDOperand Ops[4];
|
|
|
|
for (unsigned int x = 0; x < num_operands; ++x)
|
|
|
|
Ops[x] = LegalizeOp(Node->getOperand(x));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], num_operands);
|
|
|
|
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Result, DAG);
|
|
|
|
break;
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0));
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1));
|
|
|
|
return Result.getValue(Op.ResNo);
|
|
|
|
}
|
2008-02-21 06:45:13 +00:00
|
|
|
case ISD::ATOMIC_LAS:
|
2008-05-05 19:05:59 +00:00
|
|
|
case ISD::ATOMIC_LSS:
|
|
|
|
case ISD::ATOMIC_LOAD_AND:
|
|
|
|
case ISD::ATOMIC_LOAD_OR:
|
|
|
|
case ISD::ATOMIC_LOAD_XOR:
|
|
|
|
case ISD::ATOMIC_LOAD_MIN:
|
|
|
|
case ISD::ATOMIC_LOAD_MAX:
|
|
|
|
case ISD::ATOMIC_LOAD_UMIN:
|
|
|
|
case ISD::ATOMIC_LOAD_UMAX:
|
2008-02-21 06:45:13 +00:00
|
|
|
case ISD::ATOMIC_SWAP: {
|
2008-05-05 19:05:59 +00:00
|
|
|
unsigned int num_operands = 3;
|
|
|
|
assert(Node->getNumOperands() == num_operands && "Invalid Atomic node!");
|
|
|
|
SDOperand Ops[3];
|
|
|
|
for (unsigned int x = 0; x < num_operands; ++x)
|
2008-03-01 21:52:34 +00:00
|
|
|
Ops[x] = LegalizeOp(Node->getOperand(x));
|
2008-05-05 19:05:59 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], num_operands);
|
2008-03-01 21:52:34 +00:00
|
|
|
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
2008-02-21 06:45:13 +00:00
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2008-03-01 21:52:34 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Result, DAG);
|
|
|
|
break;
|
2008-05-05 19:05:59 +00:00
|
|
|
case TargetLowering::Expand:
|
|
|
|
Result = SDOperand(TLI.ExpandOperationResult(Op.Val, DAG),0);
|
|
|
|
break;
|
2008-03-01 21:52:34 +00:00
|
|
|
case TargetLowering::Legal:
|
2008-02-21 06:45:13 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-01 21:52:34 +00:00
|
|
|
AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0));
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1));
|
|
|
|
return Result.getValue(Op.ResNo);
|
2008-05-05 19:05:59 +00:00
|
|
|
}
|
2007-08-08 23:23:31 +00:00
|
|
|
case ISD::Constant: {
|
|
|
|
ConstantSDNode *CN = cast<ConstantSDNode>(Node);
|
|
|
|
unsigned opAction =
|
|
|
|
TLI.getOperationAction(ISD::Constant, CN->getValueType(0));
|
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
// We know we don't need to expand constants here, constants only have one
|
|
|
|
// value and we check that it is fine above.
|
|
|
|
|
2007-08-08 23:23:31 +00:00
|
|
|
if (opAction == TargetLowering::Custom) {
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.Val)
|
|
|
|
Result = Tmp1;
|
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
2007-08-08 23:23:31 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
case ISD::ConstantFP: {
|
|
|
|
// Spill FP immediates to the constant pool if the target cannot directly
|
|
|
|
// codegen them. Targets often have some immediate values that can be
|
|
|
|
// efficiently generated into an FP register without a load. We explicitly
|
|
|
|
// leave these constants as ConstantFP nodes for the target to deal with.
|
|
|
|
ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node);
|
|
|
|
|
2006-01-29 06:26:56 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::ConstantFP, CFP->getValueType(0))) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2008-02-14 08:57:00 +00:00
|
|
|
case TargetLowering::Legal:
|
|
|
|
break;
|
2006-01-29 06:26:56 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp3 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp3.Val) {
|
|
|
|
Result = Tmp3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// FALLTHROUGH
|
2008-02-14 08:57:00 +00:00
|
|
|
case TargetLowering::Expand: {
|
|
|
|
// Check to see if this FP immediate is already legal.
|
|
|
|
bool isLegal = false;
|
|
|
|
for (TargetLowering::legal_fpimm_iterator I = TLI.legal_fpimm_begin(),
|
|
|
|
E = TLI.legal_fpimm_end(); I != E; ++I) {
|
|
|
|
if (CFP->isExactlyValue(*I)) {
|
|
|
|
isLegal = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If this is a legal constant, turn it into a TargetConstantFP node.
|
|
|
|
if (isLegal)
|
|
|
|
break;
|
2006-12-12 22:19:28 +00:00
|
|
|
Result = ExpandConstantFP(CFP, true, DAG, TLI);
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
2008-02-14 08:57:00 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-11-09 18:48:57 +00:00
|
|
|
case ISD::TokenFactor:
|
|
|
|
if (Node->getNumOperands() == 2) {
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
|
|
|
} else if (Node->getNumOperands() == 3) {
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1));
|
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(2));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
2005-11-09 18:48:57 +00:00
|
|
|
} else {
|
2006-08-08 01:09:31 +00:00
|
|
|
SmallVector<SDOperand, 8> Ops;
|
2005-11-09 18:48:57 +00:00
|
|
|
// Legalize the operands.
|
2006-01-28 10:58:55 +00:00
|
|
|
for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
|
|
|
|
Ops.push_back(LegalizeOp(Node->getOperand(i)));
|
2006-08-08 01:09:31 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size());
|
2005-01-13 17:59:25 +00:00
|
|
|
}
|
|
|
|
break;
|
2006-04-12 16:20:43 +00:00
|
|
|
|
|
|
|
case ISD::FORMAL_ARGUMENTS:
|
2006-05-16 22:53:20 +00:00
|
|
|
case ISD::CALL:
|
2006-04-12 16:20:43 +00:00
|
|
|
// The only option for this is to custom lower it.
|
2006-05-17 17:55:45 +00:00
|
|
|
Tmp3 = TLI.LowerOperation(Result.getValue(0), DAG);
|
|
|
|
assert(Tmp3.Val && "Target didn't custom lower this node!");
|
2008-03-05 19:14:03 +00:00
|
|
|
// A call within a calling sequence must be legalized to something
|
|
|
|
// other than the normal CALLSEQ_END. Violating this gets Legalize
|
|
|
|
// into an infinite loop.
|
|
|
|
assert ((!IsLegalizingCall ||
|
|
|
|
Node->getOpcode() != ISD::CALL ||
|
|
|
|
Tmp3.Val->getOpcode() != ISD::CALLSEQ_END) &&
|
|
|
|
"Nested CALLSEQ_START..CALLSEQ_END not supported.");
|
2007-11-13 00:44:25 +00:00
|
|
|
|
|
|
|
// The number of incoming and outgoing values should match; unless the final
|
|
|
|
// outgoing value is a flag.
|
|
|
|
assert((Tmp3.Val->getNumValues() == Result.Val->getNumValues() ||
|
|
|
|
(Tmp3.Val->getNumValues() == Result.Val->getNumValues() + 1 &&
|
|
|
|
Tmp3.Val->getValueType(Tmp3.Val->getNumValues() - 1) ==
|
|
|
|
MVT::Flag)) &&
|
2006-05-17 17:55:45 +00:00
|
|
|
"Lowering call/formal_arguments produced unexpected # results!");
|
2006-05-16 05:49:56 +00:00
|
|
|
|
2006-05-16 22:53:20 +00:00
|
|
|
// Since CALL/FORMAL_ARGUMENTS nodes produce multiple values, make sure to
|
2006-05-16 05:49:56 +00:00
|
|
|
// remember that we legalized all of them, so it doesn't get relegalized.
|
2006-05-17 17:55:45 +00:00
|
|
|
for (unsigned i = 0, e = Tmp3.Val->getNumValues(); i != e; ++i) {
|
2007-11-13 00:44:25 +00:00
|
|
|
if (Tmp3.Val->getValueType(i) == MVT::Flag)
|
|
|
|
continue;
|
2006-05-17 17:55:45 +00:00
|
|
|
Tmp1 = LegalizeOp(Tmp3.getValue(i));
|
2006-05-16 05:49:56 +00:00
|
|
|
if (Op.ResNo == i)
|
|
|
|
Tmp2 = Tmp1;
|
|
|
|
AddLegalizedOperand(SDOperand(Node, i), Tmp1);
|
|
|
|
}
|
|
|
|
return Tmp2;
|
2007-07-26 07:34:40 +00:00
|
|
|
case ISD::EXTRACT_SUBREG: {
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
ConstantSDNode *idx = dyn_cast<ConstantSDNode>(Node->getOperand(1));
|
|
|
|
assert(idx && "Operand must be a constant");
|
|
|
|
Tmp2 = DAG.getTargetConstant(idx->getValue(), idx->getValueType(0));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ISD::INSERT_SUBREG: {
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1));
|
|
|
|
ConstantSDNode *idx = dyn_cast<ConstantSDNode>(Node->getOperand(2));
|
|
|
|
assert(idx && "Operand must be a constant");
|
|
|
|
Tmp3 = DAG.getTargetConstant(idx->getValue(), idx->getValueType(0));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
|
|
|
}
|
|
|
|
break;
|
2006-03-19 00:52:58 +00:00
|
|
|
case ISD::BUILD_VECTOR:
|
|
|
|
switch (TLI.getOperationAction(ISD::BUILD_VECTOR, Node->getValueType(0))) {
|
2006-03-19 01:17:20 +00:00
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp3 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp3.Val) {
|
|
|
|
Result = Tmp3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// FALLTHROUGH
|
2006-03-19 06:31:19 +00:00
|
|
|
case TargetLowering::Expand:
|
|
|
|
Result = ExpandBUILD_VECTOR(Result.Val);
|
2006-03-19 00:52:58 +00:00
|
|
|
break;
|
2006-03-19 01:17:20 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ISD::INSERT_VECTOR_ELT:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // InVec
|
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(2)); // InEltNo
|
2008-02-13 06:43:04 +00:00
|
|
|
|
|
|
|
// The type of the value to insert may not be legal, even though the vector
|
|
|
|
// type is legal. Legalize/Promote accordingly. We do not handle Expand
|
|
|
|
// here.
|
|
|
|
switch (getTypeAction(Node->getOperand(1).getValueType())) {
|
|
|
|
default: assert(0 && "Cannot expand insert element operand");
|
|
|
|
case Legal: Tmp2 = LegalizeOp(Node->getOperand(1)); break;
|
|
|
|
case Promote: Tmp2 = PromoteOp(Node->getOperand(1)); break;
|
|
|
|
}
|
2006-03-19 01:17:20 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
|
|
|
|
|
|
|
switch (TLI.getOperationAction(ISD::INSERT_VECTOR_ELT,
|
|
|
|
Node->getValueType(0))) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
break;
|
|
|
|
case TargetLowering::Custom:
|
2008-01-05 20:47:37 +00:00
|
|
|
Tmp4 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp4.Val) {
|
|
|
|
Result = Tmp4;
|
2006-03-19 01:17:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// FALLTHROUGH
|
|
|
|
case TargetLowering::Expand: {
|
Codegen insertelement with constant insertion points as scalar_to_vector
and a shuffle. For this:
void %test2(<4 x float>* %F, float %f) {
%tmp = load <4 x float>* %F ; <<4 x float>> [#uses=2]
%tmp3 = add <4 x float> %tmp, %tmp ; <<4 x float>> [#uses=1]
%tmp2 = insertelement <4 x float> %tmp3, float %f, uint 2 ; <<4 x float>> [#uses=2]
%tmp6 = add <4 x float> %tmp2, %tmp2 ; <<4 x float>> [#uses=1]
store <4 x float> %tmp6, <4 x float>* %F
ret void
}
we now get this on X86 (which will get better):
_test2:
movl 4(%esp), %eax
movaps (%eax), %xmm0
addps %xmm0, %xmm0
movaps %xmm0, %xmm1
shufps $3, %xmm1, %xmm1
movaps %xmm0, %xmm2
shufps $1, %xmm2, %xmm2
unpcklps %xmm1, %xmm2
movss 8(%esp), %xmm1
unpcklps %xmm1, %xmm0
unpcklps %xmm2, %xmm0
addps %xmm0, %xmm0
movaps %xmm0, (%eax)
ret
instead of:
_test2:
subl $28, %esp
movl 32(%esp), %eax
movaps (%eax), %xmm0
addps %xmm0, %xmm0
movaps %xmm0, (%esp)
movss 36(%esp), %xmm0
movss %xmm0, 8(%esp)
movaps (%esp), %xmm0
addps %xmm0, %xmm0
movaps %xmm0, (%eax)
addl $28, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27765 91177308-0d34-0410-b5e6-96231b3b80d8
2006-04-17 19:21:01 +00:00
|
|
|
// If the insert index is a constant, codegen this as a scalar_to_vector,
|
|
|
|
// then a shuffle that inserts it into the right position in the vector.
|
|
|
|
if (ConstantSDNode *InsertPos = dyn_cast<ConstantSDNode>(Tmp3)) {
|
2008-02-13 06:43:04 +00:00
|
|
|
// SCALAR_TO_VECTOR requires that the type of the value being inserted
|
|
|
|
// match the element type of the vector being created.
|
|
|
|
if (Tmp2.getValueType() ==
|
|
|
|
MVT::getVectorElementType(Op.getValueType())) {
|
|
|
|
SDOperand ScVec = DAG.getNode(ISD::SCALAR_TO_VECTOR,
|
|
|
|
Tmp1.getValueType(), Tmp2);
|
|
|
|
|
|
|
|
unsigned NumElts = MVT::getVectorNumElements(Tmp1.getValueType());
|
|
|
|
MVT::ValueType ShufMaskVT = MVT::getIntVectorWithNumElements(NumElts);
|
|
|
|
MVT::ValueType ShufMaskEltVT = MVT::getVectorElementType(ShufMaskVT);
|
|
|
|
|
|
|
|
// We generate a shuffle of InVec and ScVec, so the shuffle mask
|
|
|
|
// should be 0,1,2,3,4,5... with the appropriate element replaced with
|
|
|
|
// elt 0 of the RHS.
|
|
|
|
SmallVector<SDOperand, 8> ShufOps;
|
|
|
|
for (unsigned i = 0; i != NumElts; ++i) {
|
|
|
|
if (i != InsertPos->getValue())
|
|
|
|
ShufOps.push_back(DAG.getConstant(i, ShufMaskEltVT));
|
|
|
|
else
|
|
|
|
ShufOps.push_back(DAG.getConstant(NumElts, ShufMaskEltVT));
|
|
|
|
}
|
|
|
|
SDOperand ShufMask = DAG.getNode(ISD::BUILD_VECTOR, ShufMaskVT,
|
|
|
|
&ShufOps[0], ShufOps.size());
|
|
|
|
|
|
|
|
Result = DAG.getNode(ISD::VECTOR_SHUFFLE, Tmp1.getValueType(),
|
|
|
|
Tmp1, ScVec, ShufMask);
|
|
|
|
Result = LegalizeOp(Result);
|
|
|
|
break;
|
Codegen insertelement with constant insertion points as scalar_to_vector
and a shuffle. For this:
void %test2(<4 x float>* %F, float %f) {
%tmp = load <4 x float>* %F ; <<4 x float>> [#uses=2]
%tmp3 = add <4 x float> %tmp, %tmp ; <<4 x float>> [#uses=1]
%tmp2 = insertelement <4 x float> %tmp3, float %f, uint 2 ; <<4 x float>> [#uses=2]
%tmp6 = add <4 x float> %tmp2, %tmp2 ; <<4 x float>> [#uses=1]
store <4 x float> %tmp6, <4 x float>* %F
ret void
}
we now get this on X86 (which will get better):
_test2:
movl 4(%esp), %eax
movaps (%eax), %xmm0
addps %xmm0, %xmm0
movaps %xmm0, %xmm1
shufps $3, %xmm1, %xmm1
movaps %xmm0, %xmm2
shufps $1, %xmm2, %xmm2
unpcklps %xmm1, %xmm2
movss 8(%esp), %xmm1
unpcklps %xmm1, %xmm0
unpcklps %xmm2, %xmm0
addps %xmm0, %xmm0
movaps %xmm0, (%eax)
ret
instead of:
_test2:
subl $28, %esp
movl 32(%esp), %eax
movaps (%eax), %xmm0
addps %xmm0, %xmm0
movaps %xmm0, (%esp)
movss 36(%esp), %xmm0
movss %xmm0, 8(%esp)
movaps (%esp), %xmm0
addps %xmm0, %xmm0
movaps %xmm0, (%eax)
addl $28, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27765 91177308-0d34-0410-b5e6-96231b3b80d8
2006-04-17 19:21:01 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-25 18:07:40 +00:00
|
|
|
Result = PerformInsertVectorEltInMemory(Tmp1, Tmp2, Tmp3);
|
2006-03-19 01:17:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-03-19 06:31:19 +00:00
|
|
|
case ISD::SCALAR_TO_VECTOR:
|
2006-04-04 17:23:26 +00:00
|
|
|
if (!TLI.isTypeLegal(Node->getOperand(0).getValueType())) {
|
|
|
|
Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-03-19 06:31:19 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // InVal
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
|
|
|
switch (TLI.getOperationAction(ISD::SCALAR_TO_VECTOR,
|
|
|
|
Node->getValueType(0))) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
break;
|
2006-03-19 06:47:21 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp3 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp3.Val) {
|
|
|
|
Result = Tmp3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// FALLTHROUGH
|
2006-04-04 17:23:26 +00:00
|
|
|
case TargetLowering::Expand:
|
|
|
|
Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node));
|
2006-03-19 06:31:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2006-03-20 01:52:29 +00:00
|
|
|
case ISD::VECTOR_SHUFFLE:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input vectors,
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // but not the shuffle mask.
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2));
|
|
|
|
|
|
|
|
// Allow targets to custom lower the SHUFFLEs they support.
|
2006-04-04 17:23:26 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE,Result.getValueType())) {
|
|
|
|
default: assert(0 && "Unknown operation action!");
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
assert(isShuffleLegal(Result.getValueType(), Node->getOperand(2)) &&
|
|
|
|
"vector shuffle should not be created if not legal!");
|
|
|
|
break;
|
|
|
|
case TargetLowering::Custom:
|
2006-04-05 06:07:11 +00:00
|
|
|
Tmp3 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp3.Val) {
|
|
|
|
Result = Tmp3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// FALLTHROUGH
|
|
|
|
case TargetLowering::Expand: {
|
|
|
|
MVT::ValueType VT = Node->getValueType(0);
|
2007-06-14 22:58:02 +00:00
|
|
|
MVT::ValueType EltVT = MVT::getVectorElementType(VT);
|
2006-04-05 06:07:11 +00:00
|
|
|
MVT::ValueType PtrVT = TLI.getPointerTy();
|
|
|
|
SDOperand Mask = Node->getOperand(2);
|
|
|
|
unsigned NumElems = Mask.getNumOperands();
|
2006-08-08 02:23:42 +00:00
|
|
|
SmallVector<SDOperand,8> Ops;
|
2006-04-05 06:07:11 +00:00
|
|
|
for (unsigned i = 0; i != NumElems; ++i) {
|
|
|
|
SDOperand Arg = Mask.getOperand(i);
|
|
|
|
if (Arg.getOpcode() == ISD::UNDEF) {
|
|
|
|
Ops.push_back(DAG.getNode(ISD::UNDEF, EltVT));
|
|
|
|
} else {
|
|
|
|
assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!");
|
|
|
|
unsigned Idx = cast<ConstantSDNode>(Arg)->getValue();
|
|
|
|
if (Idx < NumElems)
|
|
|
|
Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp1,
|
|
|
|
DAG.getConstant(Idx, PtrVT)));
|
|
|
|
else
|
|
|
|
Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp2,
|
|
|
|
DAG.getConstant(Idx - NumElems, PtrVT)));
|
|
|
|
}
|
|
|
|
}
|
2006-08-08 02:23:42 +00:00
|
|
|
Result = DAG.getNode(ISD::BUILD_VECTOR, VT, &Ops[0], Ops.size());
|
2006-04-04 17:23:26 +00:00
|
|
|
break;
|
2006-04-05 06:07:11 +00:00
|
|
|
}
|
2006-04-04 17:23:26 +00:00
|
|
|
case TargetLowering::Promote: {
|
|
|
|
// Change base type to a different vector type.
|
|
|
|
MVT::ValueType OVT = Node->getValueType(0);
|
|
|
|
MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT);
|
|
|
|
|
|
|
|
// Cast the two input vectors.
|
|
|
|
Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1);
|
|
|
|
Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2);
|
|
|
|
|
|
|
|
// Convert the shuffle mask to the right # elements.
|
|
|
|
Tmp3 = SDOperand(isShuffleLegal(OVT, Node->getOperand(2)), 0);
|
|
|
|
assert(Tmp3.Val && "Shuffle not legal?");
|
|
|
|
Result = DAG.getNode(ISD::VECTOR_SHUFFLE, NVT, Tmp1, Tmp2, Tmp3);
|
|
|
|
Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result);
|
|
|
|
break;
|
|
|
|
}
|
2006-03-20 01:52:29 +00:00
|
|
|
}
|
|
|
|
break;
|
2006-03-21 20:44:12 +00:00
|
|
|
|
|
|
|
case ISD::EXTRACT_VECTOR_ELT:
|
2007-06-25 16:23:39 +00:00
|
|
|
Tmp1 = Node->getOperand(0);
|
2006-03-21 20:44:12 +00:00
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
2007-06-25 16:23:39 +00:00
|
|
|
Result = ExpandEXTRACT_VECTOR_ELT(Result);
|
2006-03-21 20:44:12 +00:00
|
|
|
break;
|
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::EXTRACT_SUBVECTOR:
|
|
|
|
Tmp1 = Node->getOperand(0);
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
|
|
|
Result = ExpandEXTRACT_SUBVECTOR(Result);
|
2007-06-13 15:12:02 +00:00
|
|
|
break;
|
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
case ISD::CALLSEQ_START: {
|
|
|
|
SDNode *CallEnd = FindCallEndFromCallStart(Node);
|
|
|
|
|
|
|
|
// Recursively Legalize all of the inputs of the call end that do not lead
|
|
|
|
// to this call start. This ensures that any libcalls that need be inserted
|
|
|
|
// are inserted *before* the CALLSEQ_START.
|
2007-02-04 00:27:56 +00:00
|
|
|
{SmallPtrSet<SDNode*, 32> NodesLeadingTo;
|
2006-02-13 09:18:02 +00:00
|
|
|
for (unsigned i = 0, e = CallEnd->getNumOperands(); i != e; ++i)
|
2006-07-26 23:55:56 +00:00
|
|
|
LegalizeAllNodesNotLeadingTo(CallEnd->getOperand(i).Val, Node,
|
|
|
|
NodesLeadingTo);
|
|
|
|
}
|
2006-02-13 09:18:02 +00:00
|
|
|
|
|
|
|
// Now that we legalized all of the inputs (which may have inserted
|
|
|
|
// libcalls) create the new CALLSEQ_START node.
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
|
|
|
|
// Merge in the last call, to ensure that this call start after the last
|
|
|
|
// call ended.
|
2006-05-17 18:00:08 +00:00
|
|
|
if (LastCALLSEQ_END.getOpcode() != ISD::EntryToken) {
|
2006-05-17 17:55:45 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END);
|
|
|
|
Tmp1 = LegalizeOp(Tmp1);
|
|
|
|
}
|
2006-02-13 09:18:02 +00:00
|
|
|
|
|
|
|
// Do not try to legalize the target-specific arguments (#1+).
|
|
|
|
if (Tmp1 != Node->getOperand(0)) {
|
2006-08-08 01:09:31 +00:00
|
|
|
SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end());
|
2006-02-13 09:18:02 +00:00
|
|
|
Ops[0] = Tmp1;
|
2006-08-08 01:09:31 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size());
|
2006-02-13 09:18:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remember that the CALLSEQ_START is legalized.
|
2006-02-14 00:55:02 +00:00
|
|
|
AddLegalizedOperand(Op.getValue(0), Result);
|
|
|
|
if (Node->getNumValues() == 2) // If this has a flag result, remember it.
|
|
|
|
AddLegalizedOperand(Op.getValue(1), Result.getValue(1));
|
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
// Now that the callseq_start and all of the non-call nodes above this call
|
|
|
|
// sequence have been legalized, legalize the call itself. During this
|
|
|
|
// process, no libcalls can/will be inserted, guaranteeing that no calls
|
|
|
|
// can overlap.
|
|
|
|
assert(!IsLegalizingCall && "Inconsistent sequentialization of calls!");
|
|
|
|
SDOperand InCallSEQ = LastCALLSEQ_END;
|
|
|
|
// Note that we are selecting this call!
|
|
|
|
LastCALLSEQ_END = SDOperand(CallEnd, 0);
|
|
|
|
IsLegalizingCall = true;
|
|
|
|
|
|
|
|
// Legalize the call, starting from the CALLSEQ_END.
|
|
|
|
LegalizeOp(LastCALLSEQ_END);
|
|
|
|
assert(!IsLegalizingCall && "CALLSEQ_END should have cleared this!");
|
|
|
|
return Result;
|
|
|
|
}
|
2005-05-12 23:24:06 +00:00
|
|
|
case ISD::CALLSEQ_END:
|
2006-02-13 09:18:02 +00:00
|
|
|
// If the CALLSEQ_START node hasn't been legalized first, legalize it. This
|
|
|
|
// will cause this node to be legalized as well as handling libcalls right.
|
|
|
|
if (LastCALLSEQ_END.Val != Node) {
|
|
|
|
LegalizeOp(SDOperand(FindCallStartFromCallEnd(Node), 0));
|
2008-04-16 16:15:27 +00:00
|
|
|
DenseMap<SDOperand, SDOperand>::iterator I = LegalizedNodes.find(Op);
|
2006-02-13 09:18:02 +00:00
|
|
|
assert(I != LegalizedNodes.end() &&
|
|
|
|
"Legalizing the call start should have legalized this node!");
|
|
|
|
return I->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, the call start has been legalized and everything is going
|
|
|
|
// according to plan. Just legalize ourselves normally here.
|
2005-01-07 07:47:09 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
2006-01-29 07:58:15 +00:00
|
|
|
// Do not try to legalize the target-specific arguments (#1+), except for
|
|
|
|
// an optional flag input.
|
|
|
|
if (Node->getOperand(Node->getNumOperands()-1).getValueType() != MVT::Flag){
|
|
|
|
if (Tmp1 != Node->getOperand(0)) {
|
2006-08-08 01:09:31 +00:00
|
|
|
SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end());
|
2006-01-29 07:58:15 +00:00
|
|
|
Ops[0] = Tmp1;
|
2006-08-08 01:09:31 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size());
|
2006-01-29 07:58:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(Node->getNumOperands()-1));
|
|
|
|
if (Tmp1 != Node->getOperand(0) ||
|
|
|
|
Tmp2 != Node->getOperand(Node->getNumOperands()-1)) {
|
2006-08-08 01:09:31 +00:00
|
|
|
SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end());
|
2006-01-29 07:58:15 +00:00
|
|
|
Ops[0] = Tmp1;
|
|
|
|
Ops.back() = Tmp2;
|
2006-08-08 01:09:31 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size());
|
2006-01-29 07:58:15 +00:00
|
|
|
}
|
2006-01-24 05:48:21 +00:00
|
|
|
}
|
2006-02-14 00:55:02 +00:00
|
|
|
assert(IsLegalizingCall && "Call sequence imbalance between start/end?");
|
2006-02-13 09:18:02 +00:00
|
|
|
// This finishes up call legalization.
|
|
|
|
IsLegalizingCall = false;
|
2006-02-14 00:55:02 +00:00
|
|
|
|
|
|
|
// If the CALLSEQ_END node has a flag, remember that we legalized it.
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0));
|
|
|
|
if (Node->getNumValues() == 2)
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1));
|
|
|
|
return Result.getValue(Op.ResNo);
|
2006-01-11 22:14:47 +00:00
|
|
|
case ISD::DYNAMIC_STACKALLOC: {
|
2007-08-16 23:50:06 +00:00
|
|
|
MVT::ValueType VT = Node->getValueType(0);
|
2005-01-09 19:03:49 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the size.
|
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the alignment.
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
2005-01-09 19:03:49 +00:00
|
|
|
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp1 = Result.getValue(0);
|
2006-01-15 08:43:08 +00:00
|
|
|
Tmp2 = Result.getValue(1);
|
2007-08-16 23:50:06 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), VT)) {
|
2006-01-11 22:14:47 +00:00
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-15 08:54:32 +00:00
|
|
|
case TargetLowering::Expand: {
|
|
|
|
unsigned SPReg = TLI.getStackPointerRegisterToSaveRestore();
|
|
|
|
assert(SPReg && "Target cannot require DYNAMIC_STACKALLOC expansion and"
|
|
|
|
" not tell us which reg is the stack pointer!");
|
|
|
|
SDOperand Chain = Tmp1.getOperand(0);
|
2007-11-13 00:44:25 +00:00
|
|
|
|
|
|
|
// Chain the dynamic stack allocation so that it doesn't modify the stack
|
|
|
|
// pointer when other instructions are using the stack.
|
|
|
|
Chain = DAG.getCALLSEQ_START(Chain,
|
|
|
|
DAG.getConstant(0, TLI.getPointerTy()));
|
|
|
|
|
2006-01-15 08:54:32 +00:00
|
|
|
SDOperand Size = Tmp2.getOperand(1);
|
2007-08-16 23:50:06 +00:00
|
|
|
SDOperand SP = DAG.getCopyFromReg(Chain, SPReg, VT);
|
|
|
|
Chain = SP.getValue(1);
|
|
|
|
unsigned Align = cast<ConstantSDNode>(Tmp3)->getValue();
|
|
|
|
unsigned StackAlign =
|
|
|
|
TLI.getTargetMachine().getFrameInfo()->getStackAlignment();
|
|
|
|
if (Align > StackAlign)
|
2007-08-17 18:02:22 +00:00
|
|
|
SP = DAG.getNode(ISD::AND, VT, SP,
|
|
|
|
DAG.getConstant(-(uint64_t)Align, VT));
|
2007-08-16 23:50:06 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::SUB, VT, SP, Size); // Value
|
2007-11-13 00:44:25 +00:00
|
|
|
Chain = DAG.getCopyToReg(Chain, SPReg, Tmp1); // Output chain
|
|
|
|
|
|
|
|
Tmp2 =
|
|
|
|
DAG.getCALLSEQ_END(Chain,
|
|
|
|
DAG.getConstant(0, TLI.getPointerTy()),
|
|
|
|
DAG.getConstant(0, TLI.getPointerTy()),
|
|
|
|
SDOperand());
|
|
|
|
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp1 = LegalizeOp(Tmp1);
|
|
|
|
Tmp2 = LegalizeOp(Tmp2);
|
2006-01-15 08:54:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TargetLowering::Custom:
|
2006-01-15 08:43:08 +00:00
|
|
|
Tmp3 = TLI.LowerOperation(Tmp1, DAG);
|
|
|
|
if (Tmp3.Val) {
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp1 = LegalizeOp(Tmp3);
|
|
|
|
Tmp2 = LegalizeOp(Tmp3.getValue(1));
|
2006-01-11 22:14:47 +00:00
|
|
|
}
|
2006-01-15 08:54:32 +00:00
|
|
|
break;
|
2006-01-11 22:14:47 +00:00
|
|
|
case TargetLowering::Legal:
|
2006-01-15 08:54:32 +00:00
|
|
|
break;
|
2006-01-11 22:14:47 +00:00
|
|
|
}
|
2006-01-15 08:54:32 +00:00
|
|
|
// Since this op produce two values, make sure to remember that we
|
|
|
|
// legalized both of them.
|
2006-01-28 10:58:55 +00:00
|
|
|
AddLegalizedOperand(SDOperand(Node, 0), Tmp1);
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 1), Tmp2);
|
2006-01-15 08:54:32 +00:00
|
|
|
return Op.ResNo ? Tmp2 : Tmp1;
|
2006-01-11 22:14:47 +00:00
|
|
|
}
|
2006-07-11 01:40:09 +00:00
|
|
|
case ISD::INLINEASM: {
|
2006-08-08 01:09:31 +00:00
|
|
|
SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end());
|
2006-07-11 01:40:09 +00:00
|
|
|
bool Changed = false;
|
|
|
|
// Legalize all of the operands of the inline asm, in case they are nodes
|
|
|
|
// that need to be expanded or something. Note we skip the asm string and
|
|
|
|
// all of the TargetConstant flags.
|
|
|
|
SDOperand Op = LegalizeOp(Ops[0]);
|
|
|
|
Changed = Op != Ops[0];
|
|
|
|
Ops[0] = Op;
|
|
|
|
|
|
|
|
bool HasInFlag = Ops.back().getValueType() == MVT::Flag;
|
|
|
|
for (unsigned i = 2, e = Ops.size()-HasInFlag; i < e; ) {
|
|
|
|
unsigned NumVals = cast<ConstantSDNode>(Ops[i])->getValue() >> 3;
|
|
|
|
for (++i; NumVals; ++i, --NumVals) {
|
|
|
|
SDOperand Op = LegalizeOp(Ops[i]);
|
|
|
|
if (Op != Ops[i]) {
|
|
|
|
Changed = true;
|
|
|
|
Ops[i] = Op;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HasInFlag) {
|
|
|
|
Op = LegalizeOp(Ops.back());
|
|
|
|
Changed |= Op != Ops.back();
|
|
|
|
Ops.back() = Op;
|
|
|
|
}
|
2006-01-26 22:24:51 +00:00
|
|
|
|
2006-07-11 01:40:09 +00:00
|
|
|
if (Changed)
|
2006-08-08 01:09:31 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size());
|
2006-01-26 22:24:51 +00:00
|
|
|
|
|
|
|
// INLINE asm returns a chain and flag, make sure to add both to the map.
|
2006-01-28 10:58:55 +00:00
|
|
|
AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0));
|
2006-01-26 22:24:51 +00:00
|
|
|
AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1));
|
|
|
|
return Result.getValue(Op.ResNo);
|
2006-07-11 01:40:09 +00:00
|
|
|
}
|
2005-01-07 22:12:08 +00:00
|
|
|
case ISD::BR:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
2006-02-13 09:18:02 +00:00
|
|
|
// Ensure that libcalls are emitted before a branch.
|
|
|
|
Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END);
|
|
|
|
Tmp1 = LegalizeOp(Tmp1);
|
|
|
|
LastCALLSEQ_END = DAG.getEntryNode();
|
|
|
|
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1));
|
2005-01-07 22:12:08 +00:00
|
|
|
break;
|
2006-04-22 18:53:45 +00:00
|
|
|
case ISD::BRIND:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
// Ensure that libcalls are emitted before a branch.
|
|
|
|
Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END);
|
|
|
|
Tmp1 = LegalizeOp(Tmp1);
|
|
|
|
LastCALLSEQ_END = DAG.getEntryNode();
|
|
|
|
|
|
|
|
switch (getTypeAction(Node->getOperand(1).getValueType())) {
|
|
|
|
default: assert(0 && "Indirect target must be legal type (pointer)!");
|
|
|
|
case Legal:
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
|
|
|
break;
|
2006-10-30 08:00:44 +00:00
|
|
|
case ISD::BR_JT:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
// Ensure that libcalls are emitted before a branch.
|
|
|
|
Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END);
|
|
|
|
Tmp1 = LegalizeOp(Tmp1);
|
|
|
|
LastCALLSEQ_END = DAG.getEntryNode();
|
|
|
|
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the jumptable node.
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2));
|
|
|
|
|
|
|
|
switch (TLI.getOperationAction(ISD::BR_JT, MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.Val) Result = Tmp1;
|
|
|
|
break;
|
|
|
|
case TargetLowering::Expand: {
|
|
|
|
SDOperand Chain = Result.getOperand(0);
|
|
|
|
SDOperand Table = Result.getOperand(1);
|
|
|
|
SDOperand Index = Result.getOperand(2);
|
|
|
|
|
|
|
|
MVT::ValueType PTy = TLI.getPointerTy();
|
2006-12-14 19:17:33 +00:00
|
|
|
MachineFunction &MF = DAG.getMachineFunction();
|
|
|
|
unsigned EntrySize = MF.getJumpTableInfo()->getEntrySize();
|
2006-10-30 08:00:44 +00:00
|
|
|
Index= DAG.getNode(ISD::MUL, PTy, Index, DAG.getConstant(EntrySize, PTy));
|
|
|
|
SDOperand Addr = DAG.getNode(ISD::ADD, PTy, Index, Table);
|
2006-12-14 19:17:33 +00:00
|
|
|
|
|
|
|
SDOperand LD;
|
|
|
|
switch (EntrySize) {
|
|
|
|
default: assert(0 && "Size of jump table not supported yet."); break;
|
2008-02-06 22:27:42 +00:00
|
|
|
case 4: LD = DAG.getLoad(MVT::i32, Chain, Addr,
|
2008-02-07 18:41:25 +00:00
|
|
|
PseudoSourceValue::getJumpTable(), 0); break;
|
2008-02-06 22:27:42 +00:00
|
|
|
case 8: LD = DAG.getLoad(MVT::i64, Chain, Addr,
|
2008-02-07 18:41:25 +00:00
|
|
|
PseudoSourceValue::getJumpTable(), 0); break;
|
2006-12-14 19:17:33 +00:00
|
|
|
}
|
|
|
|
|
Much improved pic jumptable codegen:
Then:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
imull $4, %ecx, %ecx
leal LJTI1_0-"L1$pb"(%eax), %edx
addl LJTI1_0-"L1$pb"(%ecx,%eax), %edx
jmpl *%edx
.align 2
.set L1_0_set_3,LBB1_3-LJTI1_0
.set L1_0_set_2,LBB1_2-LJTI1_0
.set L1_0_set_5,LBB1_5-LJTI1_0
.set L1_0_set_4,LBB1_4-LJTI1_0
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
Now:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
addl LJTI1_0-"L1$pb"(%eax,%ecx,4), %eax
jmpl *%eax
.align 2
.set L1_0_set_3,LBB1_3-"L1$pb"
.set L1_0_set_2,LBB1_2-"L1$pb"
.set L1_0_set_5,LBB1_5-"L1$pb"
.set L1_0_set_4,LBB1_4-"L1$pb"
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43924 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-09 01:32:10 +00:00
|
|
|
Addr = LD;
|
2006-12-14 19:17:33 +00:00
|
|
|
if (TLI.getTargetMachine().getRelocationModel() == Reloc::PIC_) {
|
2006-10-30 08:00:44 +00:00
|
|
|
// For PIC, the sequence is:
|
|
|
|
// BRIND(load(Jumptable + index) + RelocBase)
|
Much improved pic jumptable codegen:
Then:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
imull $4, %ecx, %ecx
leal LJTI1_0-"L1$pb"(%eax), %edx
addl LJTI1_0-"L1$pb"(%ecx,%eax), %edx
jmpl *%edx
.align 2
.set L1_0_set_3,LBB1_3-LJTI1_0
.set L1_0_set_2,LBB1_2-LJTI1_0
.set L1_0_set_5,LBB1_5-LJTI1_0
.set L1_0_set_4,LBB1_4-LJTI1_0
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
Now:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
addl LJTI1_0-"L1$pb"(%eax,%ecx,4), %eax
jmpl *%eax
.align 2
.set L1_0_set_3,LBB1_3-"L1$pb"
.set L1_0_set_2,LBB1_2-"L1$pb"
.set L1_0_set_5,LBB1_5-"L1$pb"
.set L1_0_set_4,LBB1_4-"L1$pb"
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43924 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-09 01:32:10 +00:00
|
|
|
// RelocBase can be JumpTable, GOT or some sort of global base.
|
|
|
|
if (PTy != MVT::i32)
|
|
|
|
Addr = DAG.getNode(ISD::SIGN_EXTEND, PTy, Addr);
|
|
|
|
Addr = DAG.getNode(ISD::ADD, PTy, Addr,
|
|
|
|
TLI.getPICJumpTableRelocBase(Table, DAG));
|
2006-10-30 08:00:44 +00:00
|
|
|
}
|
Much improved pic jumptable codegen:
Then:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
imull $4, %ecx, %ecx
leal LJTI1_0-"L1$pb"(%eax), %edx
addl LJTI1_0-"L1$pb"(%ecx,%eax), %edx
jmpl *%edx
.align 2
.set L1_0_set_3,LBB1_3-LJTI1_0
.set L1_0_set_2,LBB1_2-LJTI1_0
.set L1_0_set_5,LBB1_5-LJTI1_0
.set L1_0_set_4,LBB1_4-LJTI1_0
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
Now:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
addl LJTI1_0-"L1$pb"(%eax,%ecx,4), %eax
jmpl *%eax
.align 2
.set L1_0_set_3,LBB1_3-"L1$pb"
.set L1_0_set_2,LBB1_2-"L1$pb"
.set L1_0_set_5,LBB1_5-"L1$pb"
.set L1_0_set_4,LBB1_4-"L1$pb"
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43924 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-09 01:32:10 +00:00
|
|
|
Result = DAG.getNode(ISD::BRIND, MVT::Other, LD.getValue(1), Addr);
|
2006-10-30 08:00:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2005-01-07 08:19:42 +00:00
|
|
|
case ISD::BRCOND:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
2006-02-13 09:18:02 +00:00
|
|
|
// Ensure that libcalls are emitted before a return.
|
|
|
|
Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END);
|
|
|
|
Tmp1 = LegalizeOp(Tmp1);
|
|
|
|
LastCALLSEQ_END = DAG.getEntryNode();
|
|
|
|
|
2005-01-18 19:27:06 +00:00
|
|
|
switch (getTypeAction(Node->getOperand(1).getValueType())) {
|
|
|
|
case Expand: assert(0 && "It's impossible to expand bools");
|
|
|
|
case Legal:
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition.
|
|
|
|
break;
|
2008-02-25 21:11:39 +00:00
|
|
|
case Promote: {
|
2005-01-18 19:27:06 +00:00
|
|
|
Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the condition.
|
2006-11-27 04:39:56 +00:00
|
|
|
|
|
|
|
// The top bits of the promoted condition are not necessarily zero, ensure
|
|
|
|
// that the value is properly zero extended.
|
2008-02-25 21:11:39 +00:00
|
|
|
unsigned BitWidth = Tmp2.getValueSizeInBits();
|
2007-06-22 14:59:07 +00:00
|
|
|
if (!DAG.MaskedValueIsZero(Tmp2,
|
2008-02-25 21:11:39 +00:00
|
|
|
APInt::getHighBitsSet(BitWidth, BitWidth-1)))
|
2006-11-27 04:39:56 +00:00
|
|
|
Tmp2 = DAG.getZeroExtendInReg(Tmp2, MVT::i1);
|
2005-01-18 19:27:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-02-25 21:11:39 +00:00
|
|
|
}
|
2006-01-28 07:39:30 +00:00
|
|
|
|
|
|
|
// Basic block destination (Op#2) is always legal.
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2));
|
2005-08-16 19:49:35 +00:00
|
|
|
|
|
|
|
switch (TLI.getOperationAction(ISD::BRCOND, MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.Val) Result = Tmp1;
|
|
|
|
break;
|
2005-08-16 19:49:35 +00:00
|
|
|
case TargetLowering::Expand:
|
|
|
|
// Expand brcond's setcc into its constituent parts and create a BR_CC
|
|
|
|
// Node.
|
|
|
|
if (Tmp2.getOpcode() == ISD::SETCC) {
|
|
|
|
Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, Tmp2.getOperand(2),
|
|
|
|
Tmp2.getOperand(0), Tmp2.getOperand(1),
|
|
|
|
Node->getOperand(2));
|
|
|
|
} else {
|
|
|
|
Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1,
|
|
|
|
DAG.getCondCode(ISD::SETNE), Tmp2,
|
|
|
|
DAG.getConstant(0, Tmp2.getValueType()),
|
|
|
|
Node->getOperand(2));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ISD::BR_CC:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
2006-02-13 09:18:02 +00:00
|
|
|
// Ensure that libcalls are emitted before a branch.
|
|
|
|
Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END);
|
|
|
|
Tmp1 = LegalizeOp(Tmp1);
|
2006-02-01 07:19:44 +00:00
|
|
|
Tmp2 = Node->getOperand(2); // LHS
|
|
|
|
Tmp3 = Node->getOperand(3); // RHS
|
|
|
|
Tmp4 = Node->getOperand(1); // CC
|
2005-12-17 23:46:46 +00:00
|
|
|
|
2006-02-01 07:19:44 +00:00
|
|
|
LegalizeSetCCOperands(Tmp2, Tmp3, Tmp4);
|
2006-12-18 22:55:34 +00:00
|
|
|
LastCALLSEQ_END = DAG.getEntryNode();
|
|
|
|
|
2006-02-01 07:19:44 +00:00
|
|
|
// If we didn't get both a LHS and RHS back from LegalizeSetCCOperands,
|
|
|
|
// the LHS is a legal SETCC itself. In this case, we need to compare
|
|
|
|
// the result against zero to select between true and false values.
|
|
|
|
if (Tmp3.Val == 0) {
|
|
|
|
Tmp3 = DAG.getConstant(0, Tmp2.getValueType());
|
|
|
|
Tmp4 = DAG.getCondCode(ISD::SETNE);
|
|
|
|
}
|
|
|
|
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp4, Tmp2, Tmp3,
|
|
|
|
Node->getOperand(4));
|
2006-01-28 07:39:30 +00:00
|
|
|
|
2005-12-17 23:46:46 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::BR_CC, Tmp3.getValueType())) {
|
|
|
|
default: assert(0 && "Unexpected action for BR_CC!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp4 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp4.Val) Result = Tmp4;
|
2005-12-17 23:46:46 +00:00
|
|
|
break;
|
2005-08-16 19:49:35 +00:00
|
|
|
}
|
2005-01-07 08:19:42 +00:00
|
|
|
break;
|
2005-12-23 07:29:34 +00:00
|
|
|
case ISD::LOAD: {
|
2006-10-09 20:57:25 +00:00
|
|
|
LoadSDNode *LD = cast<LoadSDNode>(Node);
|
|
|
|
Tmp1 = LegalizeOp(LD->getChain()); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(LD->getBasePtr()); // Legalize the base pointer.
|
2005-04-27 20:10:01 +00:00
|
|
|
|
2006-10-09 20:57:25 +00:00
|
|
|
ISD::LoadExtType ExtType = LD->getExtensionType();
|
|
|
|
if (ExtType == ISD::NON_EXTLOAD) {
|
|
|
|
MVT::ValueType VT = Node->getValueType(0);
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset());
|
|
|
|
Tmp3 = Result.getValue(0);
|
|
|
|
Tmp4 = Result.getValue(1);
|
2006-01-28 07:39:30 +00:00
|
|
|
|
2006-10-09 20:57:25 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), VT)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2007-08-01 19:34:21 +00:00
|
|
|
case TargetLowering::Legal:
|
|
|
|
// If this is an unaligned load and the target doesn't support it,
|
|
|
|
// expand it.
|
|
|
|
if (!TLI.allowsUnalignedMemoryAccesses()) {
|
|
|
|
unsigned ABIAlignment = TLI.getTargetData()->
|
2008-01-30 00:15:11 +00:00
|
|
|
getABITypeAlignment(MVT::getTypeForValueType(LD->getMemoryVT()));
|
2007-08-01 19:34:21 +00:00
|
|
|
if (LD->getAlignment() < ABIAlignment){
|
|
|
|
Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.Val), DAG,
|
|
|
|
TLI);
|
|
|
|
Tmp3 = Result.getOperand(0);
|
|
|
|
Tmp4 = Result.getOperand(1);
|
2007-09-08 19:29:23 +00:00
|
|
|
Tmp3 = LegalizeOp(Tmp3);
|
|
|
|
Tmp4 = LegalizeOp(Tmp4);
|
2007-08-01 19:34:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-10-09 20:57:25 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Tmp3, DAG);
|
|
|
|
if (Tmp1.Val) {
|
|
|
|
Tmp3 = LegalizeOp(Tmp1);
|
|
|
|
Tmp4 = LegalizeOp(Tmp1.getValue(1));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TargetLowering::Promote: {
|
|
|
|
// Only promote a load of vector type to another.
|
|
|
|
assert(MVT::isVector(VT) && "Cannot promote this load!");
|
|
|
|
// Change base type to a different vector type.
|
|
|
|
MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT);
|
|
|
|
|
|
|
|
Tmp1 = DAG.getLoad(NVT, Tmp1, Tmp2, LD->getSrcValue(),
|
2007-07-09 22:18:38 +00:00
|
|
|
LD->getSrcValueOffset(),
|
|
|
|
LD->isVolatile(), LD->getAlignment());
|
2006-10-09 20:57:25 +00:00
|
|
|
Tmp3 = LegalizeOp(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp1));
|
2006-04-12 16:33:18 +00:00
|
|
|
Tmp4 = LegalizeOp(Tmp1.getValue(1));
|
2006-10-09 20:57:25 +00:00
|
|
|
break;
|
2005-12-23 07:29:34 +00:00
|
|
|
}
|
2006-10-09 20:57:25 +00:00
|
|
|
}
|
|
|
|
// Since loads produce two values, make sure to remember that we
|
|
|
|
// legalized both of them.
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 0), Tmp3);
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 1), Tmp4);
|
|
|
|
return Op.ResNo ? Tmp4 : Tmp3;
|
|
|
|
} else {
|
2008-01-30 00:15:11 +00:00
|
|
|
MVT::ValueType SrcVT = LD->getMemoryVT();
|
2008-01-23 20:39:46 +00:00
|
|
|
unsigned SrcWidth = MVT::getSizeInBits(SrcVT);
|
|
|
|
int SVOffset = LD->getSrcValueOffset();
|
|
|
|
unsigned Alignment = LD->getAlignment();
|
|
|
|
bool isVolatile = LD->isVolatile();
|
|
|
|
|
|
|
|
if (SrcWidth != MVT::getStoreSizeInBits(SrcVT) &&
|
|
|
|
// Some targets pretend to have an i1 loading operation, and actually
|
|
|
|
// load an i8. This trick is correct for ZEXTLOAD because the top 7
|
|
|
|
// bits are guaranteed to be zero; it helps the optimizers understand
|
|
|
|
// that these bits are zero. It is also useful for EXTLOAD, since it
|
|
|
|
// tells the optimizers that those bits are undefined. It would be
|
|
|
|
// nice to have an effective generic way of getting these benefits...
|
|
|
|
// Until such a way is found, don't insist on promoting i1 here.
|
|
|
|
(SrcVT != MVT::i1 ||
|
|
|
|
TLI.getLoadXAction(ExtType, MVT::i1) == TargetLowering::Promote)) {
|
|
|
|
// Promote to a byte-sized load if not loading an integral number of
|
|
|
|
// bytes. For example, promote EXTLOAD:i20 -> EXTLOAD:i24.
|
|
|
|
unsigned NewWidth = MVT::getStoreSizeInBits(SrcVT);
|
|
|
|
MVT::ValueType NVT = MVT::getIntegerType(NewWidth);
|
|
|
|
SDOperand Ch;
|
|
|
|
|
|
|
|
// The extra bits are guaranteed to be zero, since we stored them that
|
|
|
|
// way. A zext load from NVT thus automatically gives zext from SrcVT.
|
|
|
|
|
|
|
|
ISD::LoadExtType NewExtType =
|
|
|
|
ExtType == ISD::ZEXTLOAD ? ISD::ZEXTLOAD : ISD::EXTLOAD;
|
|
|
|
|
|
|
|
Result = DAG.getExtLoad(NewExtType, Node->getValueType(0),
|
|
|
|
Tmp1, Tmp2, LD->getSrcValue(), SVOffset,
|
|
|
|
NVT, isVolatile, Alignment);
|
|
|
|
|
|
|
|
Ch = Result.getValue(1); // The chain.
|
|
|
|
|
|
|
|
if (ExtType == ISD::SEXTLOAD)
|
|
|
|
// Having the top bits zero doesn't help when sign extending.
|
|
|
|
Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(),
|
|
|
|
Result, DAG.getValueType(SrcVT));
|
|
|
|
else if (ExtType == ISD::ZEXTLOAD || NVT == Result.getValueType())
|
|
|
|
// All the top bits are guaranteed to be zero - inform the optimizers.
|
|
|
|
Result = DAG.getNode(ISD::AssertZext, Result.getValueType(), Result,
|
|
|
|
DAG.getValueType(SrcVT));
|
|
|
|
|
|
|
|
Tmp1 = LegalizeOp(Result);
|
|
|
|
Tmp2 = LegalizeOp(Ch);
|
|
|
|
} else if (SrcWidth & (SrcWidth - 1)) {
|
|
|
|
// If not loading a power-of-2 number of bits, expand as two loads.
|
|
|
|
assert(MVT::isExtendedVT(SrcVT) && !MVT::isVector(SrcVT) &&
|
|
|
|
"Unsupported extload!");
|
|
|
|
unsigned RoundWidth = 1 << Log2_32(SrcWidth);
|
|
|
|
assert(RoundWidth < SrcWidth);
|
|
|
|
unsigned ExtraWidth = SrcWidth - RoundWidth;
|
|
|
|
assert(ExtraWidth < RoundWidth);
|
|
|
|
assert(!(RoundWidth % 8) && !(ExtraWidth % 8) &&
|
|
|
|
"Load size not an integral number of bytes!");
|
|
|
|
MVT::ValueType RoundVT = MVT::getIntegerType(RoundWidth);
|
|
|
|
MVT::ValueType ExtraVT = MVT::getIntegerType(ExtraWidth);
|
|
|
|
SDOperand Lo, Hi, Ch;
|
|
|
|
unsigned IncrementSize;
|
|
|
|
|
|
|
|
if (TLI.isLittleEndian()) {
|
|
|
|
// EXTLOAD:i24 -> ZEXTLOAD:i16 | (shl EXTLOAD@+2:i8, 16)
|
|
|
|
// Load the bottom RoundWidth bits.
|
|
|
|
Lo = DAG.getExtLoad(ISD::ZEXTLOAD, Node->getValueType(0), Tmp1, Tmp2,
|
|
|
|
LD->getSrcValue(), SVOffset, RoundVT, isVolatile,
|
|
|
|
Alignment);
|
|
|
|
|
|
|
|
// Load the remaining ExtraWidth bits.
|
|
|
|
IncrementSize = RoundWidth / 8;
|
|
|
|
Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2,
|
|
|
|
DAG.getIntPtrConstant(IncrementSize));
|
|
|
|
Hi = DAG.getExtLoad(ExtType, Node->getValueType(0), Tmp1, Tmp2,
|
|
|
|
LD->getSrcValue(), SVOffset + IncrementSize,
|
|
|
|
ExtraVT, isVolatile,
|
|
|
|
MinAlign(Alignment, IncrementSize));
|
|
|
|
|
|
|
|
// Build a factor node to remember that this load is independent of the
|
|
|
|
// other one.
|
|
|
|
Ch = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1),
|
|
|
|
Hi.getValue(1));
|
|
|
|
|
|
|
|
// Move the top bits to the right place.
|
|
|
|
Hi = DAG.getNode(ISD::SHL, Hi.getValueType(), Hi,
|
|
|
|
DAG.getConstant(RoundWidth, TLI.getShiftAmountTy()));
|
|
|
|
|
|
|
|
// Join the hi and lo parts.
|
|
|
|
Result = DAG.getNode(ISD::OR, Node->getValueType(0), Lo, Hi);
|
2007-08-01 19:34:21 +00:00
|
|
|
} else {
|
2008-01-23 20:39:46 +00:00
|
|
|
// Big endian - avoid unaligned loads.
|
|
|
|
// EXTLOAD:i24 -> (shl EXTLOAD:i16, 8) | ZEXTLOAD@+2:i8
|
|
|
|
// Load the top RoundWidth bits.
|
|
|
|
Hi = DAG.getExtLoad(ExtType, Node->getValueType(0), Tmp1, Tmp2,
|
|
|
|
LD->getSrcValue(), SVOffset, RoundVT, isVolatile,
|
|
|
|
Alignment);
|
|
|
|
|
|
|
|
// Load the remaining ExtraWidth bits.
|
|
|
|
IncrementSize = RoundWidth / 8;
|
|
|
|
Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2,
|
|
|
|
DAG.getIntPtrConstant(IncrementSize));
|
|
|
|
Lo = DAG.getExtLoad(ISD::ZEXTLOAD, Node->getValueType(0), Tmp1, Tmp2,
|
|
|
|
LD->getSrcValue(), SVOffset + IncrementSize,
|
|
|
|
ExtraVT, isVolatile,
|
|
|
|
MinAlign(Alignment, IncrementSize));
|
|
|
|
|
|
|
|
// Build a factor node to remember that this load is independent of the
|
|
|
|
// other one.
|
|
|
|
Ch = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1),
|
|
|
|
Hi.getValue(1));
|
|
|
|
|
|
|
|
// Move the top bits to the right place.
|
|
|
|
Hi = DAG.getNode(ISD::SHL, Hi.getValueType(), Hi,
|
|
|
|
DAG.getConstant(ExtraWidth, TLI.getShiftAmountTy()));
|
|
|
|
|
|
|
|
// Join the hi and lo parts.
|
|
|
|
Result = DAG.getNode(ISD::OR, Node->getValueType(0), Lo, Hi);
|
|
|
|
}
|
|
|
|
|
|
|
|
Tmp1 = LegalizeOp(Result);
|
|
|
|
Tmp2 = LegalizeOp(Ch);
|
|
|
|
} else {
|
|
|
|
switch (TLI.getLoadXAction(ExtType, SrcVT)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
isCustom = true;
|
|
|
|
// FALLTHROUGH
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset());
|
|
|
|
Tmp1 = Result.getValue(0);
|
|
|
|
Tmp2 = Result.getValue(1);
|
|
|
|
|
|
|
|
if (isCustom) {
|
|
|
|
Tmp3 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp3.Val) {
|
|
|
|
Tmp1 = LegalizeOp(Tmp3);
|
|
|
|
Tmp2 = LegalizeOp(Tmp3.getValue(1));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If this is an unaligned load and the target doesn't support it,
|
|
|
|
// expand it.
|
|
|
|
if (!TLI.allowsUnalignedMemoryAccesses()) {
|
|
|
|
unsigned ABIAlignment = TLI.getTargetData()->
|
2008-01-30 00:15:11 +00:00
|
|
|
getABITypeAlignment(MVT::getTypeForValueType(LD->getMemoryVT()));
|
2008-01-23 20:39:46 +00:00
|
|
|
if (LD->getAlignment() < ABIAlignment){
|
|
|
|
Result = ExpandUnalignedLoad(cast<LoadSDNode>(Result.Val), DAG,
|
|
|
|
TLI);
|
|
|
|
Tmp1 = Result.getOperand(0);
|
|
|
|
Tmp2 = Result.getOperand(1);
|
|
|
|
Tmp1 = LegalizeOp(Tmp1);
|
|
|
|
Tmp2 = LegalizeOp(Tmp2);
|
|
|
|
}
|
2007-08-01 19:34:21 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-23 20:39:46 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Expand:
|
|
|
|
// f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND
|
|
|
|
if (SrcVT == MVT::f32 && Node->getValueType(0) == MVT::f64) {
|
|
|
|
SDOperand Load = DAG.getLoad(SrcVT, Tmp1, Tmp2, LD->getSrcValue(),
|
|
|
|
LD->getSrcValueOffset(),
|
|
|
|
LD->isVolatile(), LD->getAlignment());
|
|
|
|
Result = DAG.getNode(ISD::FP_EXTEND, Node->getValueType(0), Load);
|
|
|
|
Tmp1 = LegalizeOp(Result); // Relegalize new nodes.
|
|
|
|
Tmp2 = LegalizeOp(Load.getValue(1));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
assert(ExtType != ISD::EXTLOAD &&"EXTLOAD should always be supported!");
|
|
|
|
// Turn the unsupported load into an EXTLOAD followed by an explicit
|
|
|
|
// zero/sign extend inreg.
|
|
|
|
Result = DAG.getExtLoad(ISD::EXTLOAD, Node->getValueType(0),
|
|
|
|
Tmp1, Tmp2, LD->getSrcValue(),
|
|
|
|
LD->getSrcValueOffset(), SrcVT,
|
|
|
|
LD->isVolatile(), LD->getAlignment());
|
|
|
|
SDOperand ValRes;
|
|
|
|
if (ExtType == ISD::SEXTLOAD)
|
|
|
|
ValRes = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(),
|
|
|
|
Result, DAG.getValueType(SrcVT));
|
|
|
|
else
|
|
|
|
ValRes = DAG.getZeroExtendInReg(Result, SrcVT);
|
|
|
|
Tmp1 = LegalizeOp(ValRes); // Relegalize new nodes.
|
|
|
|
Tmp2 = LegalizeOp(Result.getValue(1)); // Relegalize new nodes.
|
2006-10-09 20:57:25 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-06-30 19:22:37 +00:00
|
|
|
}
|
2008-01-23 20:39:46 +00:00
|
|
|
|
2006-10-09 20:57:25 +00:00
|
|
|
// Since loads produce two values, make sure to remember that we legalized
|
|
|
|
// both of them.
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 0), Tmp1);
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 1), Tmp2);
|
|
|
|
return Op.ResNo ? Tmp2 : Tmp1;
|
2005-04-10 22:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
2005-10-19 00:06:56 +00:00
|
|
|
case ISD::EXTRACT_ELEMENT: {
|
|
|
|
MVT::ValueType OpTy = Node->getOperand(0).getValueType();
|
|
|
|
switch (getTypeAction(OpTy)) {
|
2006-01-28 10:58:55 +00:00
|
|
|
default: assert(0 && "EXTRACT_ELEMENT action for type unimplemented!");
|
2005-10-19 00:06:56 +00:00
|
|
|
case Legal:
|
|
|
|
if (cast<ConstantSDNode>(Node->getOperand(1))->getValue()) {
|
|
|
|
// 1 -> Hi
|
|
|
|
Result = DAG.getNode(ISD::SRL, OpTy, Node->getOperand(0),
|
|
|
|
DAG.getConstant(MVT::getSizeInBits(OpTy)/2,
|
|
|
|
TLI.getShiftAmountTy()));
|
|
|
|
Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Result);
|
|
|
|
} else {
|
|
|
|
// 0 -> Lo
|
|
|
|
Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0),
|
|
|
|
Node->getOperand(0));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Expand:
|
|
|
|
// Get both the low and high parts.
|
|
|
|
ExpandOp(Node->getOperand(0), Tmp1, Tmp2);
|
|
|
|
if (cast<ConstantSDNode>(Node->getOperand(1))->getValue())
|
|
|
|
Result = Tmp2; // 1 -> Hi
|
|
|
|
else
|
|
|
|
Result = Tmp1; // 0 -> Lo
|
|
|
|
break;
|
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
2005-10-19 00:06:56 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
|
|
|
|
case ISD::CopyToReg:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
2005-04-21 22:36:52 +00:00
|
|
|
|
2005-08-24 16:35:28 +00:00
|
|
|
assert(isTypeLegal(Node->getOperand(2).getValueType()) &&
|
2005-08-16 21:55:35 +00:00
|
|
|
"Register type must be legal!");
|
2005-12-18 15:27:43 +00:00
|
|
|
// Legalize the incoming value (must be a legal type).
|
2005-08-16 21:55:35 +00:00
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(2));
|
2005-12-18 15:36:21 +00:00
|
|
|
if (Node->getNumValues() == 1) {
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2);
|
2005-12-18 15:27:43 +00:00
|
|
|
} else {
|
2005-12-18 15:36:21 +00:00
|
|
|
assert(Node->getNumValues() == 2 && "Unknown CopyToReg");
|
2006-01-28 10:58:55 +00:00
|
|
|
if (Node->getNumOperands() == 4) {
|
2005-12-18 15:36:21 +00:00
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(3));
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2,
|
|
|
|
Tmp3);
|
|
|
|
} else {
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2);
|
2005-12-18 15:27:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Since this produces two values, make sure to remember that we legalized
|
|
|
|
// both of them.
|
2006-01-28 10:58:55 +00:00
|
|
|
AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0));
|
2005-12-18 15:27:43 +00:00
|
|
|
AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1));
|
2006-01-28 10:58:55 +00:00
|
|
|
return Result;
|
2005-12-18 15:27:43 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ISD::RET:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
2006-02-13 09:18:02 +00:00
|
|
|
|
|
|
|
// Ensure that libcalls are emitted before a return.
|
|
|
|
Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END);
|
|
|
|
Tmp1 = LegalizeOp(Tmp1);
|
|
|
|
LastCALLSEQ_END = DAG.getEntryNode();
|
2006-04-11 01:31:51 +00:00
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
switch (Node->getNumOperands()) {
|
2006-05-26 23:09:09 +00:00
|
|
|
case 3: // ret val
|
2006-04-11 06:33:39 +00:00
|
|
|
Tmp2 = Node->getOperand(1);
|
2006-05-26 23:09:09 +00:00
|
|
|
Tmp3 = Node->getOperand(2); // Signness
|
2006-04-11 01:31:51 +00:00
|
|
|
switch (getTypeAction(Tmp2.getValueType())) {
|
2005-01-07 07:47:09 +00:00
|
|
|
case Legal:
|
2006-05-26 23:09:09 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, LegalizeOp(Tmp2), Tmp3);
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
2006-04-11 01:31:51 +00:00
|
|
|
case Expand:
|
2007-06-25 16:23:39 +00:00
|
|
|
if (!MVT::isVector(Tmp2.getValueType())) {
|
2006-04-11 01:31:51 +00:00
|
|
|
SDOperand Lo, Hi;
|
|
|
|
ExpandOp(Tmp2, Lo, Hi);
|
2007-03-06 20:01:06 +00:00
|
|
|
|
|
|
|
// Big endian systems want the hi reg first.
|
2008-02-11 10:37:04 +00:00
|
|
|
if (TLI.isBigEndian())
|
2007-03-06 20:01:06 +00:00
|
|
|
std::swap(Lo, Hi);
|
|
|
|
|
2006-12-11 19:27:14 +00:00
|
|
|
if (Hi.Val)
|
|
|
|
Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3);
|
|
|
|
else
|
|
|
|
Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3);
|
2006-08-21 20:24:53 +00:00
|
|
|
Result = LegalizeOp(Result);
|
2006-04-11 01:31:51 +00:00
|
|
|
} else {
|
|
|
|
SDNode *InVal = Tmp2.Val;
|
2007-10-20 00:07:52 +00:00
|
|
|
int InIx = Tmp2.ResNo;
|
|
|
|
unsigned NumElems = MVT::getVectorNumElements(InVal->getValueType(InIx));
|
|
|
|
MVT::ValueType EVT = MVT::getVectorElementType(InVal->getValueType(InIx));
|
2006-04-11 01:31:51 +00:00
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
// Figure out if there is a simple type corresponding to this Vector
|
2007-02-15 03:39:18 +00:00
|
|
|
// type. If so, convert to the vector type.
|
2006-04-11 01:31:51 +00:00
|
|
|
MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems);
|
2007-06-25 16:23:39 +00:00
|
|
|
if (TLI.isTypeLegal(TVT)) {
|
2007-02-15 03:39:18 +00:00
|
|
|
// Turn this into a return of the vector type.
|
2007-06-25 16:23:39 +00:00
|
|
|
Tmp2 = LegalizeOp(Tmp2);
|
2006-05-26 23:09:09 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
2006-04-11 01:31:51 +00:00
|
|
|
} else if (NumElems == 1) {
|
|
|
|
// Turn this into a return of the scalar type.
|
2007-06-25 16:23:39 +00:00
|
|
|
Tmp2 = ScalarizeVectorOp(Tmp2);
|
|
|
|
Tmp2 = LegalizeOp(Tmp2);
|
2006-05-26 23:09:09 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
2006-04-11 02:00:08 +00:00
|
|
|
|
|
|
|
// FIXME: Returns of gcc generic vectors smaller than a legal type
|
|
|
|
// should be returned in integer registers!
|
|
|
|
|
2006-04-11 01:31:51 +00:00
|
|
|
// The scalarized value type may not be legal, e.g. it might require
|
|
|
|
// promotion or expansion. Relegalize the return.
|
|
|
|
Result = LegalizeOp(Result);
|
|
|
|
} else {
|
2006-04-11 02:00:08 +00:00
|
|
|
// FIXME: Returns of gcc generic vectors larger than a legal vector
|
|
|
|
// type should be returned by reference!
|
2006-04-11 01:31:51 +00:00
|
|
|
SDOperand Lo, Hi;
|
|
|
|
SplitVectorOp(Tmp2, Lo, Hi);
|
2007-02-01 04:55:59 +00:00
|
|
|
Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3);
|
2006-04-11 01:31:51 +00:00
|
|
|
Result = LegalizeOp(Result);
|
|
|
|
}
|
|
|
|
}
|
2005-04-21 22:36:52 +00:00
|
|
|
break;
|
2005-01-07 07:47:09 +00:00
|
|
|
case Promote:
|
2005-01-15 22:16:26 +00:00
|
|
|
Tmp2 = PromoteOp(Node->getOperand(1));
|
2006-05-26 23:09:09 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = LegalizeOp(Result);
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1: // ret void
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
|
|
|
default: { // ret <values>
|
2006-08-08 01:09:31 +00:00
|
|
|
SmallVector<SDOperand, 8> NewValues;
|
2005-01-07 07:47:09 +00:00
|
|
|
NewValues.push_back(Tmp1);
|
2006-05-26 23:09:09 +00:00
|
|
|
for (unsigned i = 1, e = Node->getNumOperands(); i < e; i += 2)
|
2005-01-07 07:47:09 +00:00
|
|
|
switch (getTypeAction(Node->getOperand(i).getValueType())) {
|
|
|
|
case Legal:
|
2005-01-08 19:27:05 +00:00
|
|
|
NewValues.push_back(LegalizeOp(Node->getOperand(i)));
|
2006-05-26 23:09:09 +00:00
|
|
|
NewValues.push_back(Node->getOperand(i+1));
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
|
|
|
case Expand: {
|
|
|
|
SDOperand Lo, Hi;
|
2007-06-27 16:08:04 +00:00
|
|
|
assert(!MVT::isExtendedVT(Node->getOperand(i).getValueType()) &&
|
2006-04-11 02:00:08 +00:00
|
|
|
"FIXME: TODO: implement returning non-legal vector types!");
|
2005-01-07 07:47:09 +00:00
|
|
|
ExpandOp(Node->getOperand(i), Lo, Hi);
|
|
|
|
NewValues.push_back(Lo);
|
2006-05-26 23:09:09 +00:00
|
|
|
NewValues.push_back(Node->getOperand(i+1));
|
2006-12-11 19:27:14 +00:00
|
|
|
if (Hi.Val) {
|
|
|
|
NewValues.push_back(Hi);
|
|
|
|
NewValues.push_back(Node->getOperand(i+1));
|
|
|
|
}
|
2005-04-21 22:36:52 +00:00
|
|
|
break;
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
|
|
|
case Promote:
|
2005-01-15 22:16:26 +00:00
|
|
|
assert(0 && "Can't promote multiple return value yet!");
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
2006-01-28 10:58:55 +00:00
|
|
|
|
|
|
|
if (NewValues.size() == Node->getNumOperands())
|
2006-08-08 01:09:31 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, &NewValues[0],NewValues.size());
|
2006-01-28 10:58:55 +00:00
|
|
|
else
|
2006-08-08 01:09:31 +00:00
|
|
|
Result = DAG.getNode(ISD::RET, MVT::Other,
|
|
|
|
&NewValues[0], NewValues.size());
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-01-06 00:41:43 +00:00
|
|
|
|
2006-01-29 21:02:23 +00:00
|
|
|
if (Result.getOpcode() == ISD::RET) {
|
|
|
|
switch (TLI.getOperationAction(Result.getOpcode(), MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.Val) Result = Tmp1;
|
|
|
|
break;
|
|
|
|
}
|
2006-01-06 00:41:43 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
2005-12-23 07:29:34 +00:00
|
|
|
case ISD::STORE: {
|
2006-10-13 21:14:26 +00:00
|
|
|
StoreSDNode *ST = cast<StoreSDNode>(Node);
|
|
|
|
Tmp1 = LegalizeOp(ST->getChain()); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(ST->getBasePtr()); // Legalize the pointer.
|
2007-07-09 22:18:38 +00:00
|
|
|
int SVOffset = ST->getSrcValueOffset();
|
|
|
|
unsigned Alignment = ST->getAlignment();
|
|
|
|
bool isVolatile = ST->isVolatile();
|
2006-10-13 21:14:26 +00:00
|
|
|
|
|
|
|
if (!ST->isTruncatingStore()) {
|
2006-12-12 04:18:56 +00:00
|
|
|
// Turn 'store float 1.0, Ptr' -> 'store int 0x12345678, Ptr'
|
|
|
|
// FIXME: We shouldn't do this for TargetConstantFP's.
|
|
|
|
// FIXME: move this to the DAG Combiner! Note that we can't regress due
|
|
|
|
// to phase ordering between legalized code and the dag combiner. This
|
|
|
|
// probably means that we need to integrate dag combiner and legalizer
|
|
|
|
// together.
|
2007-09-14 22:26:36 +00:00
|
|
|
// We generally can't do this one for long doubles.
|
2007-10-13 06:35:54 +00:00
|
|
|
if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(ST->getValue())) {
|
2007-10-15 05:46:06 +00:00
|
|
|
if (CFP->getValueType(0) == MVT::f32 &&
|
|
|
|
getTypeAction(MVT::i32) == Legal) {
|
2008-03-11 00:11:06 +00:00
|
|
|
Tmp3 = DAG.getConstant(CFP->getValueAPF().
|
|
|
|
convertToAPInt().zextOrTrunc(32),
|
2007-09-11 18:32:33 +00:00
|
|
|
MVT::i32);
|
2007-09-14 22:26:36 +00:00
|
|
|
Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(),
|
|
|
|
SVOffset, isVolatile, Alignment);
|
|
|
|
break;
|
|
|
|
} else if (CFP->getValueType(0) == MVT::f64) {
|
2007-10-15 05:46:06 +00:00
|
|
|
// If this target supports 64-bit registers, do a single 64-bit store.
|
|
|
|
if (getTypeAction(MVT::i64) == Legal) {
|
|
|
|
Tmp3 = DAG.getConstant(CFP->getValueAPF().convertToAPInt().
|
2008-03-11 00:11:06 +00:00
|
|
|
zextOrTrunc(64), MVT::i64);
|
2007-10-15 05:46:06 +00:00
|
|
|
Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(),
|
|
|
|
SVOffset, isVolatile, Alignment);
|
|
|
|
break;
|
|
|
|
} else if (getTypeAction(MVT::i32) == Legal) {
|
|
|
|
// Otherwise, if the target supports 32-bit registers, use 2 32-bit
|
|
|
|
// stores. If the target supports neither 32- nor 64-bits, this
|
|
|
|
// xform is certainly not worth it.
|
2008-03-11 00:11:06 +00:00
|
|
|
const APInt &IntVal =CFP->getValueAPF().convertToAPInt();
|
|
|
|
SDOperand Lo = DAG.getConstant(APInt(IntVal).trunc(32), MVT::i32);
|
|
|
|
SDOperand Hi = DAG.getConstant(IntVal.lshr(32).trunc(32), MVT::i32);
|
2008-02-11 10:37:04 +00:00
|
|
|
if (TLI.isBigEndian()) std::swap(Lo, Hi);
|
2007-10-15 05:46:06 +00:00
|
|
|
|
|
|
|
Lo = DAG.getStore(Tmp1, Lo, Tmp2, ST->getSrcValue(),
|
|
|
|
SVOffset, isVolatile, Alignment);
|
|
|
|
Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2,
|
2008-01-17 07:00:52 +00:00
|
|
|
DAG.getIntPtrConstant(4));
|
2007-10-15 05:46:06 +00:00
|
|
|
Hi = DAG.getStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), SVOffset+4,
|
2007-10-28 12:59:45 +00:00
|
|
|
isVolatile, MinAlign(Alignment, 4U));
|
2007-10-15 05:46:06 +00:00
|
|
|
|
|
|
|
Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
2006-12-12 04:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-30 00:15:11 +00:00
|
|
|
switch (getTypeAction(ST->getMemoryVT())) {
|
2006-10-13 21:14:26 +00:00
|
|
|
case Legal: {
|
|
|
|
Tmp3 = LegalizeOp(ST->getValue());
|
2006-04-16 01:36:45 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2,
|
2006-10-13 21:14:26 +00:00
|
|
|
ST->getOffset());
|
|
|
|
|
|
|
|
MVT::ValueType VT = Tmp3.getValueType();
|
|
|
|
switch (TLI.getOperationAction(ISD::STORE, VT)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2007-08-01 19:34:21 +00:00
|
|
|
case TargetLowering::Legal:
|
|
|
|
// If this is an unaligned store and the target doesn't support it,
|
|
|
|
// expand it.
|
|
|
|
if (!TLI.allowsUnalignedMemoryAccesses()) {
|
|
|
|
unsigned ABIAlignment = TLI.getTargetData()->
|
2008-01-30 00:15:11 +00:00
|
|
|
getABITypeAlignment(MVT::getTypeForValueType(ST->getMemoryVT()));
|
2007-08-01 19:34:21 +00:00
|
|
|
if (ST->getAlignment() < ABIAlignment)
|
|
|
|
Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.Val), DAG,
|
|
|
|
TLI);
|
|
|
|
}
|
|
|
|
break;
|
2006-10-13 21:14:26 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.Val) Result = Tmp1;
|
|
|
|
break;
|
|
|
|
case TargetLowering::Promote:
|
|
|
|
assert(MVT::isVector(VT) && "Unknown legal promote case!");
|
|
|
|
Tmp3 = DAG.getNode(ISD::BIT_CONVERT,
|
|
|
|
TLI.getTypeToPromoteTo(ISD::STORE, VT), Tmp3);
|
|
|
|
Result = DAG.getStore(Tmp1, Tmp3, Tmp2,
|
2007-07-09 22:18:38 +00:00
|
|
|
ST->getSrcValue(), SVOffset, isVolatile,
|
|
|
|
Alignment);
|
2006-10-13 21:14:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-04-16 01:36:45 +00:00
|
|
|
break;
|
2005-12-23 07:29:34 +00:00
|
|
|
}
|
2006-10-13 21:14:26 +00:00
|
|
|
case Promote:
|
|
|
|
// Truncate the value and store the result.
|
|
|
|
Tmp3 = PromoteOp(ST->getValue());
|
|
|
|
Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(),
|
2008-01-30 00:15:11 +00:00
|
|
|
SVOffset, ST->getMemoryVT(),
|
2007-07-09 22:18:38 +00:00
|
|
|
isVolatile, Alignment);
|
2006-10-13 21:14:26 +00:00
|
|
|
break;
|
2005-01-15 05:21:40 +00:00
|
|
|
|
2006-10-13 21:14:26 +00:00
|
|
|
case Expand:
|
|
|
|
unsigned IncrementSize = 0;
|
|
|
|
SDOperand Lo, Hi;
|
2006-03-18 01:44:44 +00:00
|
|
|
|
2006-10-13 21:14:26 +00:00
|
|
|
// If this is a vector type, then we have to calculate the increment as
|
|
|
|
// the product of the element size in bytes, and the number of elements
|
|
|
|
// in the high half of the vector.
|
2007-06-25 16:23:39 +00:00
|
|
|
if (MVT::isVector(ST->getValue().getValueType())) {
|
2006-10-13 21:14:26 +00:00
|
|
|
SDNode *InVal = ST->getValue().Val;
|
2007-10-20 00:07:52 +00:00
|
|
|
int InIx = ST->getValue().ResNo;
|
2008-01-17 07:00:52 +00:00
|
|
|
MVT::ValueType InVT = InVal->getValueType(InIx);
|
|
|
|
unsigned NumElems = MVT::getVectorNumElements(InVT);
|
|
|
|
MVT::ValueType EVT = MVT::getVectorElementType(InVT);
|
2006-10-13 21:14:26 +00:00
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
// Figure out if there is a simple type corresponding to this Vector
|
2007-02-15 03:39:18 +00:00
|
|
|
// type. If so, convert to the vector type.
|
2006-10-13 21:14:26 +00:00
|
|
|
MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems);
|
2007-06-25 16:23:39 +00:00
|
|
|
if (TLI.isTypeLegal(TVT)) {
|
2007-02-15 03:39:18 +00:00
|
|
|
// Turn this into a normal store of the vector type.
|
2008-02-15 18:11:59 +00:00
|
|
|
Tmp3 = LegalizeOp(ST->getValue());
|
2006-10-13 21:14:26 +00:00
|
|
|
Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(),
|
2007-07-09 22:18:38 +00:00
|
|
|
SVOffset, isVolatile, Alignment);
|
2006-10-13 21:14:26 +00:00
|
|
|
Result = LegalizeOp(Result);
|
|
|
|
break;
|
|
|
|
} else if (NumElems == 1) {
|
|
|
|
// Turn this into a normal store of the scalar type.
|
2008-02-15 18:11:59 +00:00
|
|
|
Tmp3 = ScalarizeVectorOp(ST->getValue());
|
2006-10-13 21:14:26 +00:00
|
|
|
Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(),
|
2007-07-09 22:18:38 +00:00
|
|
|
SVOffset, isVolatile, Alignment);
|
2006-10-13 21:14:26 +00:00
|
|
|
// The scalarized value type may not be legal, e.g. it might require
|
|
|
|
// promotion or expansion. Relegalize the scalar store.
|
|
|
|
Result = LegalizeOp(Result);
|
|
|
|
break;
|
|
|
|
} else {
|
2008-02-15 18:11:59 +00:00
|
|
|
SplitVectorOp(ST->getValue(), Lo, Hi);
|
2007-11-15 21:15:26 +00:00
|
|
|
IncrementSize = MVT::getVectorNumElements(Lo.Val->getValueType(0)) *
|
|
|
|
MVT::getSizeInBits(EVT)/8;
|
2006-10-13 21:14:26 +00:00
|
|
|
}
|
2006-03-18 01:44:44 +00:00
|
|
|
} else {
|
2008-02-15 18:11:59 +00:00
|
|
|
ExpandOp(ST->getValue(), Lo, Hi);
|
2006-12-12 19:53:13 +00:00
|
|
|
IncrementSize = Hi.Val ? MVT::getSizeInBits(Hi.getValueType())/8 : 0;
|
2006-10-13 21:14:26 +00:00
|
|
|
|
2008-02-11 10:37:04 +00:00
|
|
|
if (TLI.isBigEndian())
|
2006-10-13 21:14:26 +00:00
|
|
|
std::swap(Lo, Hi);
|
2006-03-18 01:44:44 +00:00
|
|
|
}
|
|
|
|
|
2006-10-13 21:14:26 +00:00
|
|
|
Lo = DAG.getStore(Tmp1, Lo, Tmp2, ST->getSrcValue(),
|
2007-07-09 22:18:38 +00:00
|
|
|
SVOffset, isVolatile, Alignment);
|
2006-12-12 19:53:13 +00:00
|
|
|
|
|
|
|
if (Hi.Val == NULL) {
|
|
|
|
// Must be int <-> float one-to-one expansion.
|
|
|
|
Result = Lo;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-10-13 21:14:26 +00:00
|
|
|
Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2,
|
2008-01-17 07:00:52 +00:00
|
|
|
DAG.getIntPtrConstant(IncrementSize));
|
2006-10-13 21:14:26 +00:00
|
|
|
assert(isTypeLegal(Tmp2.getValueType()) &&
|
|
|
|
"Pointers must be legal!");
|
2007-07-09 22:18:38 +00:00
|
|
|
SVOffset += IncrementSize;
|
2007-10-28 12:59:45 +00:00
|
|
|
Alignment = MinAlign(Alignment, IncrementSize);
|
2006-10-13 21:14:26 +00:00
|
|
|
Hi = DAG.getStore(Tmp1, Hi, Tmp2, ST->getSrcValue(),
|
2007-07-09 22:18:38 +00:00
|
|
|
SVOffset, isVolatile, Alignment);
|
2006-10-13 21:14:26 +00:00
|
|
|
Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2008-01-17 19:59:44 +00:00
|
|
|
switch (getTypeAction(ST->getValue().getValueType())) {
|
|
|
|
case Legal:
|
|
|
|
Tmp3 = LegalizeOp(ST->getValue());
|
|
|
|
break;
|
|
|
|
case Promote:
|
|
|
|
// We can promote the value, the truncstore will still take care of it.
|
|
|
|
Tmp3 = PromoteOp(ST->getValue());
|
|
|
|
break;
|
|
|
|
case Expand:
|
|
|
|
// Just store the low part. This may become a non-trunc store, so make
|
|
|
|
// sure to use getTruncStore, not UpdateNodeOperands below.
|
|
|
|
ExpandOp(ST->getValue(), Tmp3, Tmp4);
|
|
|
|
return DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(),
|
|
|
|
SVOffset, MVT::i8, isVolatile, Alignment);
|
|
|
|
}
|
2008-01-22 07:17:34 +00:00
|
|
|
|
2008-01-30 00:15:11 +00:00
|
|
|
MVT::ValueType StVT = ST->getMemoryVT();
|
2008-01-22 07:17:34 +00:00
|
|
|
unsigned StWidth = MVT::getSizeInBits(StVT);
|
|
|
|
|
|
|
|
if (StWidth != MVT::getStoreSizeInBits(StVT)) {
|
|
|
|
// Promote to a byte-sized store with upper bits zero if not
|
|
|
|
// storing an integral number of bytes. For example, promote
|
|
|
|
// TRUNCSTORE:i1 X -> TRUNCSTORE:i8 (and X, 1)
|
|
|
|
MVT::ValueType NVT = MVT::getIntegerType(MVT::getStoreSizeInBits(StVT));
|
|
|
|
Tmp3 = DAG.getZeroExtendInReg(Tmp3, StVT);
|
2006-10-13 21:14:26 +00:00
|
|
|
Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(),
|
2008-01-22 07:17:34 +00:00
|
|
|
SVOffset, NVT, isVolatile, Alignment);
|
|
|
|
} else if (StWidth & (StWidth - 1)) {
|
|
|
|
// If not storing a power-of-2 number of bits, expand as two stores.
|
|
|
|
assert(MVT::isExtendedVT(StVT) && !MVT::isVector(StVT) &&
|
|
|
|
"Unsupported truncstore!");
|
|
|
|
unsigned RoundWidth = 1 << Log2_32(StWidth);
|
|
|
|
assert(RoundWidth < StWidth);
|
|
|
|
unsigned ExtraWidth = StWidth - RoundWidth;
|
|
|
|
assert(ExtraWidth < RoundWidth);
|
|
|
|
assert(!(RoundWidth % 8) && !(ExtraWidth % 8) &&
|
|
|
|
"Store size not an integral number of bytes!");
|
|
|
|
MVT::ValueType RoundVT = MVT::getIntegerType(RoundWidth);
|
|
|
|
MVT::ValueType ExtraVT = MVT::getIntegerType(ExtraWidth);
|
|
|
|
SDOperand Lo, Hi;
|
|
|
|
unsigned IncrementSize;
|
|
|
|
|
|
|
|
if (TLI.isLittleEndian()) {
|
|
|
|
// TRUNCSTORE:i24 X -> TRUNCSTORE:i16 X, TRUNCSTORE@+2:i8 (srl X, 16)
|
|
|
|
// Store the bottom RoundWidth bits.
|
|
|
|
Lo = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(),
|
|
|
|
SVOffset, RoundVT,
|
|
|
|
isVolatile, Alignment);
|
|
|
|
|
|
|
|
// Store the remaining ExtraWidth bits.
|
|
|
|
IncrementSize = RoundWidth / 8;
|
|
|
|
Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2,
|
|
|
|
DAG.getIntPtrConstant(IncrementSize));
|
|
|
|
Hi = DAG.getNode(ISD::SRL, Tmp3.getValueType(), Tmp3,
|
|
|
|
DAG.getConstant(RoundWidth, TLI.getShiftAmountTy()));
|
|
|
|
Hi = DAG.getTruncStore(Tmp1, Hi, Tmp2, ST->getSrcValue(),
|
|
|
|
SVOffset + IncrementSize, ExtraVT, isVolatile,
|
|
|
|
MinAlign(Alignment, IncrementSize));
|
|
|
|
} else {
|
|
|
|
// Big endian - avoid unaligned stores.
|
|
|
|
// TRUNCSTORE:i24 X -> TRUNCSTORE:i16 (srl X, 8), TRUNCSTORE@+2:i8 X
|
|
|
|
// Store the top RoundWidth bits.
|
|
|
|
Hi = DAG.getNode(ISD::SRL, Tmp3.getValueType(), Tmp3,
|
|
|
|
DAG.getConstant(ExtraWidth, TLI.getShiftAmountTy()));
|
|
|
|
Hi = DAG.getTruncStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), SVOffset,
|
|
|
|
RoundVT, isVolatile, Alignment);
|
|
|
|
|
|
|
|
// Store the remaining ExtraWidth bits.
|
|
|
|
IncrementSize = RoundWidth / 8;
|
|
|
|
Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2,
|
|
|
|
DAG.getIntPtrConstant(IncrementSize));
|
|
|
|
Lo = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(),
|
|
|
|
SVOffset + IncrementSize, ExtraVT, isVolatile,
|
|
|
|
MinAlign(Alignment, IncrementSize));
|
|
|
|
}
|
2006-03-18 01:44:44 +00:00
|
|
|
|
2008-01-22 07:17:34 +00:00
|
|
|
// The order of the stores doesn't matter.
|
|
|
|
Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi);
|
|
|
|
} else {
|
|
|
|
if (Tmp1 != ST->getChain() || Tmp3 != ST->getValue() ||
|
|
|
|
Tmp2 != ST->getBasePtr())
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2,
|
|
|
|
ST->getOffset());
|
|
|
|
|
|
|
|
switch (TLI.getTruncStoreAction(ST->getValue().getValueType(), StVT)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
// If this is an unaligned store and the target doesn't support it,
|
|
|
|
// expand it.
|
|
|
|
if (!TLI.allowsUnalignedMemoryAccesses()) {
|
|
|
|
unsigned ABIAlignment = TLI.getTargetData()->
|
2008-01-30 00:15:11 +00:00
|
|
|
getABITypeAlignment(MVT::getTypeForValueType(ST->getMemoryVT()));
|
2008-01-22 07:17:34 +00:00
|
|
|
if (ST->getAlignment() < ABIAlignment)
|
|
|
|
Result = ExpandUnalignedStore(cast<StoreSDNode>(Result.Val), DAG,
|
|
|
|
TLI);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Result, DAG);
|
|
|
|
break;
|
|
|
|
case Expand:
|
|
|
|
// TRUNCSTORE:i16 i32 -> STORE i16
|
|
|
|
assert(isTypeLegal(StVT) && "Do not know how to expand this store!");
|
|
|
|
Tmp3 = DAG.getNode(ISD::TRUNCATE, StVT, Tmp3);
|
|
|
|
Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), SVOffset,
|
|
|
|
isVolatile, Alignment);
|
|
|
|
break;
|
2007-08-01 19:34:21 +00:00
|
|
|
}
|
2006-10-13 21:14:26 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-12-23 07:29:34 +00:00
|
|
|
}
|
2005-03-31 21:24:06 +00:00
|
|
|
case ISD::PCMARKER:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1));
|
2005-03-31 21:24:06 +00:00
|
|
|
break;
|
2006-01-13 02:50:02 +00:00
|
|
|
case ISD::STACKSAVE:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
|
|
|
Tmp1 = Result.getValue(0);
|
|
|
|
Tmp2 = Result.getValue(1);
|
2006-01-28 07:39:30 +00:00
|
|
|
|
2006-01-13 02:50:02 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::STACKSAVE, MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp3 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp3.Val) {
|
|
|
|
Tmp1 = LegalizeOp(Tmp3);
|
|
|
|
Tmp2 = LegalizeOp(Tmp3.getValue(1));
|
2006-01-13 02:50:02 +00:00
|
|
|
}
|
2006-01-28 07:39:30 +00:00
|
|
|
break;
|
2006-01-13 02:50:02 +00:00
|
|
|
case TargetLowering::Expand:
|
2006-01-13 17:48:44 +00:00
|
|
|
// Expand to CopyFromReg if the target set
|
|
|
|
// StackPointerRegisterToSaveRestore.
|
|
|
|
if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) {
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp1 = DAG.getCopyFromReg(Result.getOperand(0), SP,
|
2006-01-13 17:48:44 +00:00
|
|
|
Node->getValueType(0));
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp2 = Tmp1.getValue(1);
|
2006-01-13 17:48:44 +00:00
|
|
|
} else {
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::UNDEF, Node->getValueType(0));
|
|
|
|
Tmp2 = Node->getOperand(0);
|
2006-01-13 17:48:44 +00:00
|
|
|
}
|
2006-01-28 07:39:30 +00:00
|
|
|
break;
|
2006-01-13 02:50:02 +00:00
|
|
|
}
|
2006-01-28 07:39:30 +00:00
|
|
|
|
|
|
|
// Since stacksave produce two values, make sure to remember that we
|
|
|
|
// legalized both of them.
|
2006-01-28 10:58:55 +00:00
|
|
|
AddLegalizedOperand(SDOperand(Node, 0), Tmp1);
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 1), Tmp2);
|
|
|
|
return Op.ResNo ? Tmp2 : Tmp1;
|
2006-01-28 07:39:30 +00:00
|
|
|
|
2006-01-13 02:50:02 +00:00
|
|
|
case ISD::STACKRESTORE:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer.
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
2006-01-13 02:50:02 +00:00
|
|
|
|
|
|
|
switch (TLI.getOperationAction(ISD::STACKRESTORE, MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.Val) Result = Tmp1;
|
2006-01-13 02:50:02 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Expand:
|
2006-01-13 17:48:44 +00:00
|
|
|
// Expand to CopyToReg if the target set
|
|
|
|
// StackPointerRegisterToSaveRestore.
|
|
|
|
if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) {
|
|
|
|
Result = DAG.getCopyToReg(Tmp1, SP, Tmp2);
|
|
|
|
} else {
|
|
|
|
Result = Tmp1;
|
|
|
|
}
|
2006-01-13 02:50:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-11-11 16:47:30 +00:00
|
|
|
case ISD::READCYCLECOUNTER:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
2006-11-29 08:26:18 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::READCYCLECOUNTER,
|
|
|
|
Node->getValueType(0))) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-11-29 19:13:47 +00:00
|
|
|
case TargetLowering::Legal:
|
|
|
|
Tmp1 = Result.getValue(0);
|
|
|
|
Tmp2 = Result.getValue(1);
|
|
|
|
break;
|
2006-11-29 08:26:18 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Result, DAG);
|
2006-11-29 19:13:47 +00:00
|
|
|
Tmp1 = LegalizeOp(Result.getValue(0));
|
|
|
|
Tmp2 = LegalizeOp(Result.getValue(1));
|
2006-11-29 08:26:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-12-02 04:56:24 +00:00
|
|
|
|
|
|
|
// Since rdcc produce two values, make sure to remember that we legalized
|
|
|
|
// both of them.
|
2006-11-29 19:13:47 +00:00
|
|
|
AddLegalizedOperand(SDOperand(Node, 0), Tmp1);
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 1), Tmp2);
|
2006-01-28 10:58:55 +00:00
|
|
|
return Result;
|
2005-11-20 21:32:07 +00:00
|
|
|
|
2005-01-14 22:08:15 +00:00
|
|
|
case ISD::SELECT:
|
2005-01-18 19:27:06 +00:00
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Expand: assert(0 && "It's impossible to expand bools");
|
|
|
|
case Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the condition.
|
|
|
|
break;
|
2008-02-25 21:11:39 +00:00
|
|
|
case Promote: {
|
2005-01-18 19:27:06 +00:00
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0)); // Promote the condition.
|
2006-11-28 01:03:30 +00:00
|
|
|
// Make sure the condition is either zero or one.
|
2008-02-25 21:11:39 +00:00
|
|
|
unsigned BitWidth = Tmp1.getValueSizeInBits();
|
2007-06-22 14:59:07 +00:00
|
|
|
if (!DAG.MaskedValueIsZero(Tmp1,
|
2008-02-25 21:11:39 +00:00
|
|
|
APInt::getHighBitsSet(BitWidth, BitWidth-1)))
|
2006-11-28 01:03:30 +00:00
|
|
|
Tmp1 = DAG.getZeroExtendInReg(Tmp1, MVT::i1);
|
2005-01-18 19:27:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-02-25 21:11:39 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // TrueVal
|
2005-01-14 22:08:15 +00:00
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(2)); // FalseVal
|
2005-01-16 07:29:19 +00:00
|
|
|
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
2006-01-28 07:39:30 +00:00
|
|
|
|
2005-08-23 04:29:48 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::SELECT, Tmp2.getValueType())) {
|
2005-01-16 07:29:19 +00:00
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom: {
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.Val) Result = Tmp1;
|
|
|
|
break;
|
|
|
|
}
|
2005-08-10 20:51:12 +00:00
|
|
|
case TargetLowering::Expand:
|
|
|
|
if (Tmp1.getOpcode() == ISD::SETCC) {
|
|
|
|
Result = DAG.getSelectCC(Tmp1.getOperand(0), Tmp1.getOperand(1),
|
|
|
|
Tmp2, Tmp3,
|
|
|
|
cast<CondCodeSDNode>(Tmp1.getOperand(2))->get());
|
|
|
|
} else {
|
|
|
|
Result = DAG.getSelectCC(Tmp1,
|
|
|
|
DAG.getConstant(0, Tmp1.getValueType()),
|
|
|
|
Tmp2, Tmp3, ISD::SETNE);
|
|
|
|
}
|
2005-01-16 07:29:19 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Promote: {
|
|
|
|
MVT::ValueType NVT =
|
|
|
|
TLI.getTypeToPromoteTo(ISD::SELECT, Tmp2.getValueType());
|
|
|
|
unsigned ExtOp, TruncOp;
|
2006-04-12 16:33:18 +00:00
|
|
|
if (MVT::isVector(Tmp2.getValueType())) {
|
|
|
|
ExtOp = ISD::BIT_CONVERT;
|
|
|
|
TruncOp = ISD::BIT_CONVERT;
|
|
|
|
} else if (MVT::isInteger(Tmp2.getValueType())) {
|
2006-01-28 07:39:30 +00:00
|
|
|
ExtOp = ISD::ANY_EXTEND;
|
|
|
|
TruncOp = ISD::TRUNCATE;
|
2005-01-16 07:29:19 +00:00
|
|
|
} else {
|
2006-01-28 07:39:30 +00:00
|
|
|
ExtOp = ISD::FP_EXTEND;
|
|
|
|
TruncOp = ISD::FP_ROUND;
|
2005-01-16 07:29:19 +00:00
|
|
|
}
|
|
|
|
// Promote each of the values to the new type.
|
|
|
|
Tmp2 = DAG.getNode(ExtOp, NVT, Tmp2);
|
|
|
|
Tmp3 = DAG.getNode(ExtOp, NVT, Tmp3);
|
|
|
|
// Perform the larger operation, then round down.
|
|
|
|
Result = DAG.getNode(ISD::SELECT, NVT, Tmp1, Tmp2,Tmp3);
|
2008-01-17 07:00:52 +00:00
|
|
|
if (TruncOp != ISD::FP_ROUND)
|
|
|
|
Result = DAG.getNode(TruncOp, Node->getValueType(0), Result);
|
|
|
|
else
|
|
|
|
Result = DAG.getNode(TruncOp, Node->getValueType(0), Result,
|
|
|
|
DAG.getIntPtrConstant(0));
|
2005-01-16 07:29:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
2006-02-01 07:19:44 +00:00
|
|
|
case ISD::SELECT_CC: {
|
|
|
|
Tmp1 = Node->getOperand(0); // LHS
|
|
|
|
Tmp2 = Node->getOperand(1); // RHS
|
2005-08-10 20:51:12 +00:00
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(2)); // True
|
|
|
|
Tmp4 = LegalizeOp(Node->getOperand(3)); // False
|
2006-02-01 07:19:44 +00:00
|
|
|
SDOperand CC = Node->getOperand(4);
|
2005-08-10 20:51:12 +00:00
|
|
|
|
2006-02-01 07:19:44 +00:00
|
|
|
LegalizeSetCCOperands(Tmp1, Tmp2, CC);
|
|
|
|
|
|
|
|
// If we didn't get both a LHS and RHS back from LegalizeSetCCOperands,
|
|
|
|
// the LHS is a legal SETCC itself. In this case, we need to compare
|
|
|
|
// the result against zero to select between true and false values.
|
|
|
|
if (Tmp2.Val == 0) {
|
|
|
|
Tmp2 = DAG.getConstant(0, Tmp1.getValueType());
|
|
|
|
CC = DAG.getCondCode(ISD::SETNE);
|
|
|
|
}
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4, CC);
|
|
|
|
|
|
|
|
// Everything is legal, see if we should expand this op or something.
|
|
|
|
switch (TLI.getOperationAction(ISD::SELECT_CC, Tmp3.getValueType())) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.Val) Result = Tmp1;
|
2005-08-10 20:51:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2006-02-01 07:19:44 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
case ISD::SETCC:
|
2006-02-01 07:19:44 +00:00
|
|
|
Tmp1 = Node->getOperand(0);
|
|
|
|
Tmp2 = Node->getOperand(1);
|
|
|
|
Tmp3 = Node->getOperand(2);
|
|
|
|
LegalizeSetCCOperands(Tmp1, Tmp2, Tmp3);
|
|
|
|
|
|
|
|
// If we had to Expand the SetCC operands into a SELECT node, then it may
|
|
|
|
// not always be possible to return a true LHS & RHS. In this case, just
|
|
|
|
// return the value we legalized, returned in the LHS
|
|
|
|
if (Tmp2.Val == 0) {
|
|
|
|
Result = Tmp1;
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-08-23 04:29:48 +00:00
|
|
|
|
2006-01-30 22:43:50 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::SETCC, Tmp1.getValueType())) {
|
2006-01-28 07:39:30 +00:00
|
|
|
default: assert(0 && "Cannot handle this action for SETCC yet!");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
isCustom = true;
|
|
|
|
// FALLTHROUGH.
|
|
|
|
case TargetLowering::Legal:
|
2006-12-15 02:59:56 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
2006-01-28 07:39:30 +00:00
|
|
|
if (isCustom) {
|
2006-12-15 02:59:56 +00:00
|
|
|
Tmp4 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp4.Val) Result = Tmp4;
|
2006-01-28 07:39:30 +00:00
|
|
|
}
|
2005-08-23 04:29:48 +00:00
|
|
|
break;
|
2005-11-30 17:12:26 +00:00
|
|
|
case TargetLowering::Promote: {
|
|
|
|
// First step, figure out the appropriate operation to use.
|
|
|
|
// Allow SETCC to not be supported for all legal data types
|
|
|
|
// Mostly this targets FP
|
|
|
|
MVT::ValueType NewInTy = Node->getOperand(0).getValueType();
|
2007-02-04 00:27:56 +00:00
|
|
|
MVT::ValueType OldVT = NewInTy; OldVT = OldVT;
|
2005-11-30 17:12:26 +00:00
|
|
|
|
|
|
|
// Scan for the appropriate larger type to use.
|
|
|
|
while (1) {
|
|
|
|
NewInTy = (MVT::ValueType)(NewInTy+1);
|
|
|
|
|
|
|
|
assert(MVT::isInteger(NewInTy) == MVT::isInteger(OldVT) &&
|
|
|
|
"Fell off of the edge of the integer world");
|
|
|
|
assert(MVT::isFloatingPoint(NewInTy) == MVT::isFloatingPoint(OldVT) &&
|
|
|
|
"Fell off of the edge of the floating point world");
|
|
|
|
|
|
|
|
// If the target supports SETCC of this type, use it.
|
2005-12-22 05:23:45 +00:00
|
|
|
if (TLI.isOperationLegal(ISD::SETCC, NewInTy))
|
2005-11-30 17:12:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (MVT::isInteger(NewInTy))
|
|
|
|
assert(0 && "Cannot promote Legal Integer SETCC yet");
|
|
|
|
else {
|
|
|
|
Tmp1 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp1);
|
|
|
|
Tmp2 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp2);
|
|
|
|
}
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp1 = LegalizeOp(Tmp1);
|
|
|
|
Tmp2 = LegalizeOp(Tmp2);
|
2006-12-15 02:59:56 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
2006-01-17 19:47:13 +00:00
|
|
|
Result = LegalizeOp(Result);
|
2005-08-29 20:46:51 +00:00
|
|
|
break;
|
2005-11-30 17:12:26 +00:00
|
|
|
}
|
2005-08-23 04:29:48 +00:00
|
|
|
case TargetLowering::Expand:
|
|
|
|
// Expand a setcc node into a select_cc of the same condition, lhs, and
|
|
|
|
// rhs that selects between const 1 (true) and const 0 (false).
|
|
|
|
MVT::ValueType VT = Node->getValueType(0);
|
|
|
|
Result = DAG.getNode(ISD::SELECT_CC, VT, Tmp1, Tmp2,
|
|
|
|
DAG.getConstant(1, VT), DAG.getConstant(0, VT),
|
2006-12-15 02:59:56 +00:00
|
|
|
Tmp3);
|
2005-08-23 04:29:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
2008-05-12 19:40:03 +00:00
|
|
|
case ISD::VSETCC: {
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS
|
|
|
|
SDOperand CC = Node->getOperand(2);
|
|
|
|
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, CC);
|
|
|
|
|
|
|
|
// Everything is legal, see if we should expand this op or something.
|
|
|
|
switch (TLI.getOperationAction(ISD::VSETCC, Tmp1.getValueType())) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.Val) Result = Tmp1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-05-09 20:23:03 +00:00
|
|
|
|
2005-04-02 04:00:59 +00:00
|
|
|
case ISD::SHL_PARTS:
|
|
|
|
case ISD::SRA_PARTS:
|
|
|
|
case ISD::SRL_PARTS: {
|
2006-08-08 01:09:31 +00:00
|
|
|
SmallVector<SDOperand, 8> Ops;
|
2005-01-20 18:52:28 +00:00
|
|
|
bool Changed = false;
|
|
|
|
for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) {
|
|
|
|
Ops.push_back(LegalizeOp(Node->getOperand(i)));
|
|
|
|
Changed |= Ops.back() != Node->getOperand(i);
|
|
|
|
}
|
2006-01-28 10:58:55 +00:00
|
|
|
if (Changed)
|
2006-08-08 01:09:31 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size());
|
2005-04-02 05:00:07 +00:00
|
|
|
|
2006-01-09 18:31:59 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(),
|
|
|
|
Node->getValueType(0))) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.Val) {
|
|
|
|
SDOperand Tmp2, RetVal(0, 0);
|
2006-01-09 18:31:59 +00:00
|
|
|
for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) {
|
2006-01-28 07:39:30 +00:00
|
|
|
Tmp2 = LegalizeOp(Tmp1.getValue(i));
|
2006-01-09 18:31:59 +00:00
|
|
|
AddLegalizedOperand(SDOperand(Node, i), Tmp2);
|
|
|
|
if (i == Op.ResNo)
|
2006-01-19 04:54:52 +00:00
|
|
|
RetVal = Tmp2;
|
2006-01-09 18:31:59 +00:00
|
|
|
}
|
2006-01-10 19:43:26 +00:00
|
|
|
assert(RetVal.Val && "Illegal result number");
|
2006-01-09 18:31:59 +00:00
|
|
|
return RetVal;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-04-02 05:00:07 +00:00
|
|
|
// Since these produce multiple values, make sure to remember that we
|
|
|
|
// legalized all of them.
|
|
|
|
for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i)
|
|
|
|
AddLegalizedOperand(SDOperand(Node, i), Result.getValue(i));
|
|
|
|
return Result.getValue(Op.ResNo);
|
2005-01-20 18:52:28 +00:00
|
|
|
}
|
2005-04-02 05:00:07 +00:00
|
|
|
|
|
|
|
// Binary operators
|
2005-01-07 07:47:09 +00:00
|
|
|
case ISD::ADD:
|
|
|
|
case ISD::SUB:
|
|
|
|
case ISD::MUL:
|
2005-04-11 03:01:51 +00:00
|
|
|
case ISD::MULHS:
|
|
|
|
case ISD::MULHU:
|
2005-01-07 07:47:09 +00:00
|
|
|
case ISD::UDIV:
|
|
|
|
case ISD::SDIV:
|
|
|
|
case ISD::AND:
|
|
|
|
case ISD::OR:
|
|
|
|
case ISD::XOR:
|
2005-01-07 21:45:56 +00:00
|
|
|
case ISD::SHL:
|
|
|
|
case ISD::SRL:
|
|
|
|
case ISD::SRA:
|
2005-09-28 22:28:18 +00:00
|
|
|
case ISD::FADD:
|
|
|
|
case ISD::FSUB:
|
|
|
|
case ISD::FMUL:
|
|
|
|
case ISD::FDIV:
|
2007-10-11 23:57:53 +00:00
|
|
|
case ISD::FPOW:
|
2005-01-07 07:47:09 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS
|
2005-07-05 19:52:39 +00:00
|
|
|
switch (getTypeAction(Node->getOperand(1).getValueType())) {
|
|
|
|
case Expand: assert(0 && "Not possible");
|
|
|
|
case Legal:
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS.
|
|
|
|
break;
|
|
|
|
case Promote:
|
|
|
|
Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS.
|
|
|
|
break;
|
|
|
|
}
|
2006-01-28 10:58:55 +00:00
|
|
|
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
2006-01-28 07:39:30 +00:00
|
|
|
|
2005-12-24 23:42:32 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
2006-04-02 03:57:31 +00:00
|
|
|
default: assert(0 && "BinOp legalize operation not supported");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.Val) Result = Tmp1;
|
2005-12-25 01:07:37 +00:00
|
|
|
break;
|
2006-04-02 03:57:31 +00:00
|
|
|
case TargetLowering::Expand: {
|
2007-10-08 18:33:35 +00:00
|
|
|
MVT::ValueType VT = Op.getValueType();
|
|
|
|
|
|
|
|
// See if multiply or divide can be lowered using two-result operations.
|
|
|
|
SDVTList VTs = DAG.getVTList(VT, VT);
|
|
|
|
if (Node->getOpcode() == ISD::MUL) {
|
|
|
|
// We just need the low half of the multiply; try both the signed
|
|
|
|
// and unsigned forms. If the target supports both SMUL_LOHI and
|
|
|
|
// UMUL_LOHI, form a preference by checking which forms of plain
|
|
|
|
// MULH it supports.
|
|
|
|
bool HasSMUL_LOHI = TLI.isOperationLegal(ISD::SMUL_LOHI, VT);
|
|
|
|
bool HasUMUL_LOHI = TLI.isOperationLegal(ISD::UMUL_LOHI, VT);
|
|
|
|
bool HasMULHS = TLI.isOperationLegal(ISD::MULHS, VT);
|
|
|
|
bool HasMULHU = TLI.isOperationLegal(ISD::MULHU, VT);
|
|
|
|
unsigned OpToUse = 0;
|
|
|
|
if (HasSMUL_LOHI && !HasMULHS) {
|
|
|
|
OpToUse = ISD::SMUL_LOHI;
|
|
|
|
} else if (HasUMUL_LOHI && !HasMULHU) {
|
|
|
|
OpToUse = ISD::UMUL_LOHI;
|
|
|
|
} else if (HasSMUL_LOHI) {
|
|
|
|
OpToUse = ISD::SMUL_LOHI;
|
|
|
|
} else if (HasUMUL_LOHI) {
|
|
|
|
OpToUse = ISD::UMUL_LOHI;
|
|
|
|
}
|
|
|
|
if (OpToUse) {
|
|
|
|
Result = SDOperand(DAG.getNode(OpToUse, VTs, Tmp1, Tmp2).Val, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Node->getOpcode() == ISD::MULHS &&
|
|
|
|
TLI.isOperationLegal(ISD::SMUL_LOHI, VT)) {
|
|
|
|
Result = SDOperand(DAG.getNode(ISD::SMUL_LOHI, VTs, Tmp1, Tmp2).Val, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (Node->getOpcode() == ISD::MULHU &&
|
|
|
|
TLI.isOperationLegal(ISD::UMUL_LOHI, VT)) {
|
|
|
|
Result = SDOperand(DAG.getNode(ISD::UMUL_LOHI, VTs, Tmp1, Tmp2).Val, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (Node->getOpcode() == ISD::SDIV &&
|
|
|
|
TLI.isOperationLegal(ISD::SDIVREM, VT)) {
|
|
|
|
Result = SDOperand(DAG.getNode(ISD::SDIVREM, VTs, Tmp1, Tmp2).Val, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (Node->getOpcode() == ISD::UDIV &&
|
|
|
|
TLI.isOperationLegal(ISD::UDIVREM, VT)) {
|
|
|
|
Result = SDOperand(DAG.getNode(ISD::UDIVREM, VTs, Tmp1, Tmp2).Val, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-10-11 23:57:53 +00:00
|
|
|
// Check to see if we have a libcall for this operator.
|
|
|
|
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
|
|
|
|
bool isSigned = false;
|
|
|
|
switch (Node->getOpcode()) {
|
|
|
|
case ISD::UDIV:
|
|
|
|
case ISD::SDIV:
|
|
|
|
if (VT == MVT::i32) {
|
|
|
|
LC = Node->getOpcode() == ISD::UDIV
|
2007-01-12 02:11:51 +00:00
|
|
|
? RTLIB::UDIV_I32 : RTLIB::SDIV_I32;
|
2007-10-11 23:57:53 +00:00
|
|
|
isSigned = Node->getOpcode() == ISD::SDIV;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ISD::FPOW:
|
2008-01-10 10:28:30 +00:00
|
|
|
LC = GetFPLibCall(VT, RTLIB::POW_F32, RTLIB::POW_F64, RTLIB::POW_F80,
|
|
|
|
RTLIB::POW_PPCF128);
|
2007-10-11 23:57:53 +00:00
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
if (LC != RTLIB::UNKNOWN_LIBCALL) {
|
|
|
|
SDOperand Dummy;
|
2008-04-12 17:14:18 +00:00
|
|
|
Result = ExpandLibCall(LC, Node, isSigned, Dummy);
|
2006-09-18 21:49:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-04-02 03:57:31 +00:00
|
|
|
assert(MVT::isVector(Node->getValueType(0)) &&
|
|
|
|
"Cannot expand this binary operator!");
|
|
|
|
// Expand the operation into a bunch of nasty scalar code.
|
2007-10-11 23:57:53 +00:00
|
|
|
Result = LegalizeOp(UnrollVectorOp(Op));
|
2006-04-02 03:57:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-04-12 21:20:24 +00:00
|
|
|
case TargetLowering::Promote: {
|
|
|
|
switch (Node->getOpcode()) {
|
|
|
|
default: assert(0 && "Do not know how to promote this BinOp!");
|
|
|
|
case ISD::AND:
|
|
|
|
case ISD::OR:
|
|
|
|
case ISD::XOR: {
|
|
|
|
MVT::ValueType OVT = Node->getValueType(0);
|
|
|
|
MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT);
|
|
|
|
assert(MVT::isVector(OVT) && "Cannot promote this BinOp!");
|
|
|
|
// Bit convert each of the values to the new type.
|
|
|
|
Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1);
|
|
|
|
Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2);
|
|
|
|
Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2);
|
|
|
|
// Bit convert the result back the original type.
|
|
|
|
Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-12-24 23:42:32 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
2006-03-05 05:09:38 +00:00
|
|
|
|
2007-10-05 14:17:22 +00:00
|
|
|
case ISD::SMUL_LOHI:
|
|
|
|
case ISD::UMUL_LOHI:
|
|
|
|
case ISD::SDIVREM:
|
|
|
|
case ISD::UDIVREM:
|
|
|
|
// These nodes will only be produced by target-specific lowering, so
|
|
|
|
// they shouldn't be here if they aren't legal.
|
2007-10-16 09:07:20 +00:00
|
|
|
assert(TLI.isOperationLegal(Node->getOpcode(), Node->getValueType(0)) &&
|
2007-10-05 14:17:22 +00:00
|
|
|
"This must be legal!");
|
2007-10-08 18:33:35 +00:00
|
|
|
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
2007-10-05 14:17:22 +00:00
|
|
|
break;
|
|
|
|
|
2006-03-05 05:09:38 +00:00
|
|
|
case ISD::FCOPYSIGN: // FCOPYSIGN does not require LHS/RHS to match type!
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS
|
|
|
|
switch (getTypeAction(Node->getOperand(1).getValueType())) {
|
|
|
|
case Expand: assert(0 && "Not possible");
|
|
|
|
case Legal:
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS.
|
|
|
|
break;
|
|
|
|
case Promote:
|
|
|
|
Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
|
|
|
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
|
|
|
default: assert(0 && "Operation not supported");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.Val) Result = Tmp1;
|
2006-03-13 06:08:38 +00:00
|
|
|
break;
|
2006-03-05 05:09:38 +00:00
|
|
|
case TargetLowering::Legal: break;
|
2007-01-04 21:56:39 +00:00
|
|
|
case TargetLowering::Expand: {
|
2007-01-05 23:33:44 +00:00
|
|
|
// If this target supports fabs/fneg natively and select is cheap,
|
|
|
|
// do this efficiently.
|
|
|
|
if (!TLI.isSelectExpensive() &&
|
|
|
|
TLI.getOperationAction(ISD::FABS, Tmp1.getValueType()) ==
|
|
|
|
TargetLowering::Legal &&
|
2007-01-04 21:56:39 +00:00
|
|
|
TLI.getOperationAction(ISD::FNEG, Tmp1.getValueType()) ==
|
2007-01-05 23:33:44 +00:00
|
|
|
TargetLowering::Legal) {
|
2006-03-13 06:08:38 +00:00
|
|
|
// Get the sign bit of the RHS.
|
|
|
|
MVT::ValueType IVT =
|
|
|
|
Tmp2.getValueType() == MVT::f32 ? MVT::i32 : MVT::i64;
|
|
|
|
SDOperand SignBit = DAG.getNode(ISD::BIT_CONVERT, IVT, Tmp2);
|
2008-03-10 15:42:14 +00:00
|
|
|
SignBit = DAG.getSetCC(TLI.getSetCCResultType(SignBit),
|
2006-03-13 06:08:38 +00:00
|
|
|
SignBit, DAG.getConstant(0, IVT), ISD::SETLT);
|
|
|
|
// Get the absolute value of the result.
|
|
|
|
SDOperand AbsVal = DAG.getNode(ISD::FABS, Tmp1.getValueType(), Tmp1);
|
|
|
|
// Select between the nabs and abs value based on the sign bit of
|
|
|
|
// the input.
|
|
|
|
Result = DAG.getNode(ISD::SELECT, AbsVal.getValueType(), SignBit,
|
|
|
|
DAG.getNode(ISD::FNEG, AbsVal.getValueType(),
|
|
|
|
AbsVal),
|
|
|
|
AbsVal);
|
|
|
|
Result = LegalizeOp(Result);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, do bitwise ops!
|
2007-01-04 21:56:39 +00:00
|
|
|
MVT::ValueType NVT =
|
|
|
|
Node->getValueType(0) == MVT::f32 ? MVT::i32 : MVT::i64;
|
|
|
|
Result = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI);
|
|
|
|
Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), Result);
|
|
|
|
Result = LegalizeOp(Result);
|
2006-03-05 05:09:38 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-01-04 21:56:39 +00:00
|
|
|
}
|
2006-03-05 05:09:38 +00:00
|
|
|
break;
|
|
|
|
|
2006-02-17 05:43:56 +00:00
|
|
|
case ISD::ADDC:
|
|
|
|
case ISD::SUBC:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
|
|
|
// Since this produces two values, make sure to remember that we legalized
|
|
|
|
// both of them.
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0));
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1));
|
|
|
|
return Result;
|
2005-04-21 22:36:52 +00:00
|
|
|
|
2006-02-17 05:43:56 +00:00
|
|
|
case ISD::ADDE:
|
|
|
|
case ISD::SUBE:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1));
|
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(2));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
|
|
|
|
// Since this produces two values, make sure to remember that we legalized
|
|
|
|
// both of them.
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0));
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1));
|
|
|
|
return Result;
|
|
|
|
|
2005-10-18 00:27:41 +00:00
|
|
|
case ISD::BUILD_PAIR: {
|
|
|
|
MVT::ValueType PairTy = Node->getValueType(0);
|
|
|
|
// TODO: handle the case where the Lo and Hi operands are not of legal type
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Lo
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Hi
|
|
|
|
switch (TLI.getOperationAction(ISD::BUILD_PAIR, PairTy)) {
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Promote:
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
assert(0 && "Cannot promote/custom this yet!");
|
2005-10-18 00:27:41 +00:00
|
|
|
case TargetLowering::Legal:
|
|
|
|
if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1))
|
|
|
|
Result = DAG.getNode(ISD::BUILD_PAIR, PairTy, Tmp1, Tmp2);
|
|
|
|
break;
|
|
|
|
case TargetLowering::Expand:
|
|
|
|
Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, PairTy, Tmp1);
|
|
|
|
Tmp2 = DAG.getNode(ISD::ANY_EXTEND, PairTy, Tmp2);
|
|
|
|
Tmp2 = DAG.getNode(ISD::SHL, PairTy, Tmp2,
|
|
|
|
DAG.getConstant(MVT::getSizeInBits(PairTy)/2,
|
|
|
|
TLI.getShiftAmountTy()));
|
2006-01-28 07:39:30 +00:00
|
|
|
Result = DAG.getNode(ISD::OR, PairTy, Tmp1, Tmp2);
|
2005-10-18 00:27:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-04-06 00:23:54 +00:00
|
|
|
case ISD::UREM:
|
|
|
|
case ISD::SREM:
|
2005-09-28 22:28:18 +00:00
|
|
|
case ISD::FREM:
|
2005-04-06 00:23:54 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS
|
2006-01-28 07:39:30 +00:00
|
|
|
|
2005-04-06 00:23:54 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Promote: assert(0 && "Cannot promote this yet!");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
isCustom = true;
|
|
|
|
// FALLTHROUGH
|
2005-12-25 01:07:37 +00:00
|
|
|
case TargetLowering::Legal:
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
2006-01-28 07:39:30 +00:00
|
|
|
if (isCustom) {
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.Val) Result = Tmp1;
|
|
|
|
}
|
2005-12-25 01:07:37 +00:00
|
|
|
break;
|
2007-10-08 18:33:35 +00:00
|
|
|
case TargetLowering::Expand: {
|
2006-09-18 23:28:33 +00:00
|
|
|
unsigned DivOpc= (Node->getOpcode() == ISD::UREM) ? ISD::UDIV : ISD::SDIV;
|
2006-12-31 05:55:36 +00:00
|
|
|
bool isSigned = DivOpc == ISD::SDIV;
|
2007-10-08 18:33:35 +00:00
|
|
|
MVT::ValueType VT = Node->getValueType(0);
|
|
|
|
|
|
|
|
// See if remainder can be lowered using two-result operations.
|
|
|
|
SDVTList VTs = DAG.getVTList(VT, VT);
|
|
|
|
if (Node->getOpcode() == ISD::SREM &&
|
|
|
|
TLI.isOperationLegal(ISD::SDIVREM, VT)) {
|
|
|
|
Result = SDOperand(DAG.getNode(ISD::SDIVREM, VTs, Tmp1, Tmp2).Val, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (Node->getOpcode() == ISD::UREM &&
|
|
|
|
TLI.isOperationLegal(ISD::UDIVREM, VT)) {
|
|
|
|
Result = SDOperand(DAG.getNode(ISD::UDIVREM, VTs, Tmp1, Tmp2).Val, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MVT::isInteger(VT)) {
|
|
|
|
if (TLI.getOperationAction(DivOpc, VT) ==
|
2006-09-18 21:49:04 +00:00
|
|
|
TargetLowering::Legal) {
|
|
|
|
// X % Y -> X-X/Y*Y
|
2006-09-18 23:28:33 +00:00
|
|
|
Result = DAG.getNode(DivOpc, VT, Tmp1, Tmp2);
|
2006-09-18 21:49:04 +00:00
|
|
|
Result = DAG.getNode(ISD::MUL, VT, Result, Tmp2);
|
|
|
|
Result = DAG.getNode(ISD::SUB, VT, Tmp1, Result);
|
2007-11-05 23:35:22 +00:00
|
|
|
} else if (MVT::isVector(VT)) {
|
|
|
|
Result = LegalizeOp(UnrollVectorOp(Op));
|
2006-09-18 21:49:04 +00:00
|
|
|
} else {
|
2007-10-08 18:33:35 +00:00
|
|
|
assert(VT == MVT::i32 &&
|
2006-09-18 21:49:04 +00:00
|
|
|
"Cannot expand this binary operator!");
|
2007-01-12 02:11:51 +00:00
|
|
|
RTLIB::Libcall LC = Node->getOpcode() == ISD::UREM
|
|
|
|
? RTLIB::UREM_I32 : RTLIB::SREM_I32;
|
2006-09-18 21:49:04 +00:00
|
|
|
SDOperand Dummy;
|
2008-04-12 17:14:18 +00:00
|
|
|
Result = ExpandLibCall(LC, Node, isSigned, Dummy);
|
2006-09-18 21:49:04 +00:00
|
|
|
}
|
2007-11-06 22:11:54 +00:00
|
|
|
} else {
|
|
|
|
assert(MVT::isFloatingPoint(VT) &&
|
|
|
|
"remainder op must have integer or floating-point type");
|
2007-11-05 23:35:22 +00:00
|
|
|
if (MVT::isVector(VT)) {
|
|
|
|
Result = LegalizeOp(UnrollVectorOp(Op));
|
|
|
|
} else {
|
|
|
|
// Floating point mod -> fmod libcall.
|
2008-01-10 10:28:30 +00:00
|
|
|
RTLIB::Libcall LC = GetFPLibCall(VT, RTLIB::REM_F32, RTLIB::REM_F64,
|
|
|
|
RTLIB::REM_F80, RTLIB::REM_PPCF128);
|
2007-11-05 23:35:22 +00:00
|
|
|
SDOperand Dummy;
|
2008-04-12 17:14:18 +00:00
|
|
|
Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy);
|
2007-11-05 23:35:22 +00:00
|
|
|
}
|
2005-04-06 00:23:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-10-08 18:33:35 +00:00
|
|
|
}
|
2005-04-06 00:23:54 +00:00
|
|
|
break;
|
2006-01-25 18:21:52 +00:00
|
|
|
case ISD::VAARG: {
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer.
|
|
|
|
|
2006-01-28 07:42:08 +00:00
|
|
|
MVT::ValueType VT = Node->getValueType(0);
|
2006-01-25 18:21:52 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
isCustom = true;
|
|
|
|
// FALLTHROUGH
|
2006-01-25 18:21:52 +00:00
|
|
|
case TargetLowering::Legal:
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2));
|
|
|
|
Result = Result.getValue(0);
|
2006-01-28 07:39:30 +00:00
|
|
|
Tmp1 = Result.getValue(1);
|
|
|
|
|
|
|
|
if (isCustom) {
|
|
|
|
Tmp2 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp2.Val) {
|
|
|
|
Result = LegalizeOp(Tmp2);
|
|
|
|
Tmp1 = LegalizeOp(Tmp2.getValue(1));
|
|
|
|
}
|
|
|
|
}
|
2006-01-25 18:21:52 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Expand: {
|
2008-02-06 22:27:42 +00:00
|
|
|
const Value *V = cast<SrcValueSDNode>(Node->getOperand(2))->getValue();
|
|
|
|
SDOperand VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, V, 0);
|
2006-01-25 18:21:52 +00:00
|
|
|
// Increment the pointer, VAList, to the next vaarg
|
|
|
|
Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList,
|
|
|
|
DAG.getConstant(MVT::getSizeInBits(VT)/8,
|
|
|
|
TLI.getPointerTy()));
|
|
|
|
// Store the incremented VAList to the legalized pointer
|
2008-02-06 22:27:42 +00:00
|
|
|
Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, V, 0);
|
2006-01-25 18:21:52 +00:00
|
|
|
// Load the actual argument out of the pointer VAList
|
2006-10-09 20:57:25 +00:00
|
|
|
Result = DAG.getLoad(VT, Tmp3, VAList, NULL, 0);
|
2006-01-28 07:39:30 +00:00
|
|
|
Tmp1 = LegalizeOp(Result.getValue(1));
|
2006-01-25 18:21:52 +00:00
|
|
|
Result = LegalizeOp(Result);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Since VAARG produces two values, make sure to remember that we
|
|
|
|
// legalized both of them.
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 0), Result);
|
2006-01-28 07:39:30 +00:00
|
|
|
AddLegalizedOperand(SDOperand(Node, 1), Tmp1);
|
|
|
|
return Op.ResNo ? Tmp1 : Result;
|
2006-01-25 18:21:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case ISD::VACOPY:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the dest pointer.
|
|
|
|
Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the source pointer.
|
|
|
|
|
|
|
|
switch (TLI.getOperationAction(ISD::VACOPY, MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
isCustom = true;
|
|
|
|
// FALLTHROUGH
|
2006-01-25 18:21:52 +00:00
|
|
|
case TargetLowering::Legal:
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3,
|
|
|
|
Node->getOperand(3), Node->getOperand(4));
|
2006-01-28 07:39:30 +00:00
|
|
|
if (isCustom) {
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.Val) Result = Tmp1;
|
|
|
|
}
|
2006-01-25 18:21:52 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Expand:
|
|
|
|
// This defaults to loading a pointer from the input and storing it to the
|
|
|
|
// output, returning the chain.
|
2008-02-06 22:27:42 +00:00
|
|
|
const Value *VD = cast<SrcValueSDNode>(Node->getOperand(3))->getValue();
|
|
|
|
const Value *VS = cast<SrcValueSDNode>(Node->getOperand(4))->getValue();
|
2008-04-17 02:09:26 +00:00
|
|
|
Tmp4 = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp3, VS, 0);
|
|
|
|
Result = DAG.getStore(Tmp4.getValue(1), Tmp4, Tmp2, VD, 0);
|
2006-01-25 18:21:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ISD::VAEND:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer.
|
|
|
|
|
|
|
|
switch (TLI.getOperationAction(ISD::VAEND, MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
isCustom = true;
|
|
|
|
// FALLTHROUGH
|
2006-01-25 18:21:52 +00:00
|
|
|
case TargetLowering::Legal:
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2));
|
2006-01-28 07:39:30 +00:00
|
|
|
if (isCustom) {
|
|
|
|
Tmp1 = TLI.LowerOperation(Tmp1, DAG);
|
|
|
|
if (Tmp1.Val) Result = Tmp1;
|
|
|
|
}
|
2006-01-25 18:21:52 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Expand:
|
|
|
|
Result = Tmp1; // Default to a no-op, return the chain
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ISD::VASTART:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain.
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer.
|
|
|
|
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2));
|
|
|
|
|
2006-01-25 18:21:52 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::VASTART, MVT::Other)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Legal: break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.Val) Result = Tmp1;
|
2006-01-25 18:21:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-01-11 21:21:00 +00:00
|
|
|
case ISD::ROTL:
|
|
|
|
case ISD::ROTR:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS
|
|
|
|
Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
|
2007-04-02 21:36:32 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
|
|
|
default:
|
|
|
|
assert(0 && "ROTL/ROTR legalize operation not supported");
|
|
|
|
break;
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
break;
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.Val) Result = Tmp1;
|
|
|
|
break;
|
|
|
|
case TargetLowering::Promote:
|
|
|
|
assert(0 && "Do not know how to promote ROTL/ROTR");
|
|
|
|
break;
|
|
|
|
case TargetLowering::Expand:
|
|
|
|
assert(0 && "Do not know how to expand ROTL/ROTR");
|
|
|
|
break;
|
|
|
|
}
|
2006-01-11 21:21:00 +00:00
|
|
|
break;
|
|
|
|
|
2006-01-14 03:14:10 +00:00
|
|
|
case ISD::BSWAP:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Op
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
assert(0 && "Cannot custom legalize this yet!");
|
|
|
|
case TargetLowering::Legal:
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
2006-01-28 07:39:30 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Promote: {
|
|
|
|
MVT::ValueType OVT = Tmp1.getValueType();
|
|
|
|
MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT);
|
2007-05-18 17:52:13 +00:00
|
|
|
unsigned DiffBits = MVT::getSizeInBits(NVT) - MVT::getSizeInBits(OVT);
|
2006-01-28 07:39:30 +00:00
|
|
|
|
|
|
|
Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1);
|
|
|
|
Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1);
|
|
|
|
Result = DAG.getNode(ISD::SRL, NVT, Tmp1,
|
|
|
|
DAG.getConstant(DiffBits, TLI.getShiftAmountTy()));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TargetLowering::Expand:
|
|
|
|
Result = ExpandBSWAP(Tmp1);
|
|
|
|
break;
|
2006-01-14 03:14:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-05-03 17:19:30 +00:00
|
|
|
case ISD::CTPOP:
|
|
|
|
case ISD::CTTZ:
|
|
|
|
case ISD::CTLZ:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0)); // Op
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
2007-07-30 21:00:31 +00:00
|
|
|
case TargetLowering::Custom:
|
2005-05-03 17:19:30 +00:00
|
|
|
case TargetLowering::Legal:
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
2007-07-30 21:00:31 +00:00
|
|
|
if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) ==
|
2007-08-02 02:22:46 +00:00
|
|
|
TargetLowering::Custom) {
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.Val) {
|
|
|
|
Result = Tmp1;
|
|
|
|
}
|
2007-07-30 21:00:31 +00:00
|
|
|
}
|
2005-05-03 17:19:30 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Promote: {
|
|
|
|
MVT::ValueType OVT = Tmp1.getValueType();
|
|
|
|
MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT);
|
2005-05-11 04:51:16 +00:00
|
|
|
|
|
|
|
// Zero extend the argument.
|
2005-05-03 17:19:30 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1);
|
|
|
|
// Perform the larger operation, then subtract if needed.
|
|
|
|
Tmp1 = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1);
|
2006-01-28 07:39:30 +00:00
|
|
|
switch (Node->getOpcode()) {
|
2005-05-03 17:19:30 +00:00
|
|
|
case ISD::CTPOP:
|
|
|
|
Result = Tmp1;
|
|
|
|
break;
|
|
|
|
case ISD::CTTZ:
|
|
|
|
//if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT)
|
2008-03-10 15:42:14 +00:00
|
|
|
Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(Tmp1), Tmp1,
|
2007-05-18 17:52:13 +00:00
|
|
|
DAG.getConstant(MVT::getSizeInBits(NVT), NVT),
|
2005-08-09 20:20:18 +00:00
|
|
|
ISD::SETEQ);
|
2005-07-27 06:12:32 +00:00
|
|
|
Result = DAG.getNode(ISD::SELECT, NVT, Tmp2,
|
2007-07-30 21:00:31 +00:00
|
|
|
DAG.getConstant(MVT::getSizeInBits(OVT),NVT), Tmp1);
|
2005-05-03 17:19:30 +00:00
|
|
|
break;
|
|
|
|
case ISD::CTLZ:
|
2006-01-28 07:39:30 +00:00
|
|
|
// Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT))
|
2005-07-27 06:12:32 +00:00
|
|
|
Result = DAG.getNode(ISD::SUB, NVT, Tmp1,
|
2007-05-18 17:52:13 +00:00
|
|
|
DAG.getConstant(MVT::getSizeInBits(NVT) -
|
|
|
|
MVT::getSizeInBits(OVT), NVT));
|
2005-05-03 17:19:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TargetLowering::Expand:
|
2006-01-28 07:39:30 +00:00
|
|
|
Result = ExpandBitCount(Node->getOpcode(), Tmp1);
|
2005-05-03 17:19:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2005-07-27 06:12:32 +00:00
|
|
|
|
2005-04-02 05:00:07 +00:00
|
|
|
// Unary operators
|
|
|
|
case ISD::FABS:
|
|
|
|
case ISD::FNEG:
|
2005-04-28 21:44:33 +00:00
|
|
|
case ISD::FSQRT:
|
|
|
|
case ISD::FSIN:
|
|
|
|
case ISD::FCOS:
|
2005-04-02 05:00:07 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Promote:
|
|
|
|
case TargetLowering::Custom:
|
2006-01-31 18:14:25 +00:00
|
|
|
isCustom = true;
|
|
|
|
// FALLTHROUGH
|
2005-04-02 05:00:07 +00:00
|
|
|
case TargetLowering::Legal:
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
2006-01-31 18:14:25 +00:00
|
|
|
if (isCustom) {
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.Val) Result = Tmp1;
|
|
|
|
}
|
2005-04-02 05:00:07 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Expand:
|
2006-01-28 07:39:30 +00:00
|
|
|
switch (Node->getOpcode()) {
|
|
|
|
default: assert(0 && "Unreachable!");
|
|
|
|
case ISD::FNEG:
|
2005-04-02 05:00:07 +00:00
|
|
|
// Expand Y = FNEG(X) -> Y = SUB -0.0, X
|
|
|
|
Tmp2 = DAG.getConstantFP(-0.0, Node->getValueType(0));
|
2006-01-28 07:39:30 +00:00
|
|
|
Result = DAG.getNode(ISD::FSUB, Node->getValueType(0), Tmp2, Tmp1);
|
2005-04-30 04:43:14 +00:00
|
|
|
break;
|
|
|
|
case ISD::FABS: {
|
2005-04-02 05:26:37 +00:00
|
|
|
// Expand Y = FABS(X) -> Y = (X >u 0.0) ? X : fneg(X).
|
|
|
|
MVT::ValueType VT = Node->getValueType(0);
|
|
|
|
Tmp2 = DAG.getConstantFP(0.0, VT);
|
2008-03-10 15:42:14 +00:00
|
|
|
Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(Tmp1), Tmp1, Tmp2,
|
2008-03-14 00:53:31 +00:00
|
|
|
ISD::SETUGT);
|
2005-04-02 05:26:37 +00:00
|
|
|
Tmp3 = DAG.getNode(ISD::FNEG, VT, Tmp1);
|
|
|
|
Result = DAG.getNode(ISD::SELECT, VT, Tmp2, Tmp1, Tmp3);
|
2005-04-30 04:43:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISD::FSQRT:
|
|
|
|
case ISD::FSIN:
|
|
|
|
case ISD::FCOS: {
|
|
|
|
MVT::ValueType VT = Node->getValueType(0);
|
2007-10-11 23:57:53 +00:00
|
|
|
|
|
|
|
// Expand unsupported unary vector operators by unrolling them.
|
|
|
|
if (MVT::isVector(VT)) {
|
|
|
|
Result = LegalizeOp(UnrollVectorOp(Op));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-01-12 02:11:51 +00:00
|
|
|
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
|
2005-04-30 04:43:14 +00:00
|
|
|
switch(Node->getOpcode()) {
|
2007-01-12 02:11:51 +00:00
|
|
|
case ISD::FSQRT:
|
2008-01-10 10:28:30 +00:00
|
|
|
LC = GetFPLibCall(VT, RTLIB::SQRT_F32, RTLIB::SQRT_F64,
|
|
|
|
RTLIB::SQRT_F80, RTLIB::SQRT_PPCF128);
|
2007-01-12 02:11:51 +00:00
|
|
|
break;
|
|
|
|
case ISD::FSIN:
|
2008-01-10 10:28:30 +00:00
|
|
|
LC = GetFPLibCall(VT, RTLIB::SIN_F32, RTLIB::SIN_F64,
|
|
|
|
RTLIB::SIN_F80, RTLIB::SIN_PPCF128);
|
2007-01-12 02:11:51 +00:00
|
|
|
break;
|
|
|
|
case ISD::FCOS:
|
2008-01-10 10:28:30 +00:00
|
|
|
LC = GetFPLibCall(VT, RTLIB::COS_F32, RTLIB::COS_F64,
|
|
|
|
RTLIB::COS_F80, RTLIB::COS_PPCF128);
|
2007-01-12 02:11:51 +00:00
|
|
|
break;
|
2005-04-30 04:43:14 +00:00
|
|
|
default: assert(0 && "Unreachable!");
|
|
|
|
}
|
2005-08-04 21:43:28 +00:00
|
|
|
SDOperand Dummy;
|
2008-04-12 17:14:18 +00:00
|
|
|
Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy);
|
2005-04-30 04:43:14 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-04-02 05:00:07 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2006-09-09 06:03:30 +00:00
|
|
|
case ISD::FPOWI: {
|
2007-10-11 23:57:53 +00:00
|
|
|
MVT::ValueType VT = Node->getValueType(0);
|
|
|
|
|
|
|
|
// Expand unsupported unary vector operators by unrolling them.
|
|
|
|
if (MVT::isVector(VT)) {
|
|
|
|
Result = LegalizeOp(UnrollVectorOp(Op));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We always lower FPOWI into a libcall. No target support for it yet.
|
2008-01-10 10:28:30 +00:00
|
|
|
RTLIB::Libcall LC = GetFPLibCall(VT, RTLIB::POWI_F32, RTLIB::POWI_F64,
|
|
|
|
RTLIB::POWI_F80, RTLIB::POWI_PPCF128);
|
2006-09-09 06:03:30 +00:00
|
|
|
SDOperand Dummy;
|
2008-04-12 17:14:18 +00:00
|
|
|
Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy);
|
2006-09-09 06:03:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-12-23 00:16:34 +00:00
|
|
|
case ISD::BIT_CONVERT:
|
2006-01-23 07:30:46 +00:00
|
|
|
if (!isTypeLegal(Node->getOperand(0).getValueType())) {
|
2008-01-16 07:45:30 +00:00
|
|
|
Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0),
|
|
|
|
Node->getValueType(0));
|
2007-06-25 16:23:39 +00:00
|
|
|
} else if (MVT::isVector(Op.getOperand(0).getValueType())) {
|
|
|
|
// The input has to be a vector type, we have to either scalarize it, pack
|
|
|
|
// it, or convert it based on whether the input vector type is legal.
|
|
|
|
SDNode *InVal = Node->getOperand(0).Val;
|
2007-10-20 00:07:52 +00:00
|
|
|
int InIx = Node->getOperand(0).ResNo;
|
|
|
|
unsigned NumElems = MVT::getVectorNumElements(InVal->getValueType(InIx));
|
|
|
|
MVT::ValueType EVT = MVT::getVectorElementType(InVal->getValueType(InIx));
|
2007-06-25 16:23:39 +00:00
|
|
|
|
|
|
|
// Figure out if there is a simple type corresponding to this Vector
|
|
|
|
// type. If so, convert to the vector type.
|
|
|
|
MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems);
|
|
|
|
if (TLI.isTypeLegal(TVT)) {
|
2007-07-16 14:29:03 +00:00
|
|
|
// Turn this into a bit convert of the vector input.
|
2007-06-25 16:23:39 +00:00
|
|
|
Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0),
|
|
|
|
LegalizeOp(Node->getOperand(0)));
|
|
|
|
break;
|
|
|
|
} else if (NumElems == 1) {
|
|
|
|
// Turn this into a bit convert of the scalar input.
|
|
|
|
Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0),
|
|
|
|
ScalarizeVectorOp(Node->getOperand(0)));
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
// FIXME: UNIMP! Store then reload
|
|
|
|
assert(0 && "Cast from unsupported vector type not implemented yet!");
|
|
|
|
}
|
2006-01-23 07:30:46 +00:00
|
|
|
} else {
|
2005-12-23 00:16:34 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::BIT_CONVERT,
|
|
|
|
Node->getOperand(0).getValueType())) {
|
|
|
|
default: assert(0 && "Unknown operation action!");
|
|
|
|
case TargetLowering::Expand:
|
2008-01-16 07:45:30 +00:00
|
|
|
Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0),
|
|
|
|
Node->getValueType(0));
|
2005-12-23 00:16:34 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
2005-12-23 00:16:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-03-24 02:26:29 +00:00
|
|
|
|
2005-04-02 05:00:07 +00:00
|
|
|
// Conversion operators. The source and destination have different types.
|
2005-07-28 23:31:12 +00:00
|
|
|
case ISD::SINT_TO_FP:
|
|
|
|
case ISD::UINT_TO_FP: {
|
|
|
|
bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP;
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Legal:
|
2005-07-30 18:33:25 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(),
|
2005-07-28 23:31:12 +00:00
|
|
|
Node->getOperand(0).getValueType())) {
|
|
|
|
default: assert(0 && "Unknown operation action!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
isCustom = true;
|
|
|
|
// FALLTHROUGH
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
2006-01-28 07:39:30 +00:00
|
|
|
if (isCustom) {
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.Val) Result = Tmp1;
|
|
|
|
}
|
|
|
|
break;
|
2005-07-28 23:31:12 +00:00
|
|
|
case TargetLowering::Expand:
|
Added generic code expansion for [signed|unsigned] i32 to [f32|f64] casts in the
legalizer. PowerPC now uses this expansion instead of ISel version.
Example:
// signed integer to double conversion
double f1(signed x) {
return (double)x;
}
// unsigned integer to double conversion
double f2(unsigned x) {
return (double)x;
}
// signed integer to float conversion
float f3(signed x) {
return (float)x;
}
// unsigned integer to float conversion
float f4(unsigned x) {
return (float)x;
}
Byte Code:
internal fastcc double %_Z2f1i(int %x) {
entry:
%tmp.1 = cast int %x to double ; <double> [#uses=1]
ret double %tmp.1
}
internal fastcc double %_Z2f2j(uint %x) {
entry:
%tmp.1 = cast uint %x to double ; <double> [#uses=1]
ret double %tmp.1
}
internal fastcc float %_Z2f3i(int %x) {
entry:
%tmp.1 = cast int %x to float ; <float> [#uses=1]
ret float %tmp.1
}
internal fastcc float %_Z2f4j(uint %x) {
entry:
%tmp.1 = cast uint %x to float ; <float> [#uses=1]
ret float %tmp.1
}
internal fastcc double %_Z2g1i(int %x) {
entry:
%buffer = alloca [2 x uint] ; <[2 x uint]*> [#uses=3]
%tmp.0 = getelementptr [2 x uint]* %buffer, int 0, int 0 ; <uint*> [#uses=1]
store uint 1127219200, uint* %tmp.0
%tmp.2 = cast int %x to uint ; <uint> [#uses=1]
%tmp.3 = xor uint %tmp.2, 2147483648 ; <uint> [#uses=1]
%tmp.5 = getelementptr [2 x uint]* %buffer, int 0, int 1 ; <uint*> [#uses=1]
store uint %tmp.3, uint* %tmp.5
%tmp.9 = cast [2 x uint]* %buffer to double* ; <double*> [#uses=1]
%tmp.10 = load double* %tmp.9 ; <double> [#uses=1]
%tmp.13 = load double* cast (long* %signed_bias to double*) ; <double> [#uses=1]
%tmp.14 = sub double %tmp.10, %tmp.13 ; <double> [#uses=1]
ret double %tmp.14
}
internal fastcc double %_Z2g2j(uint %x) {
entry:
%buffer = alloca [2 x uint] ; <[2 x uint]*> [#uses=3]
%tmp.0 = getelementptr [2 x uint]* %buffer, int 0, int 0 ; <uint*> [#uses=1]
store uint 1127219200, uint* %tmp.0
%tmp.1 = getelementptr [2 x uint]* %buffer, int 0, int 1 ; <uint*> [#uses=1]
store uint %x, uint* %tmp.1
%tmp.4 = cast [2 x uint]* %buffer to double* ; <double*> [#uses=1]
%tmp.5 = load double* %tmp.4 ; <double> [#uses=1]
%tmp.8 = load double* cast (long* %unsigned_bias to double*) ; <double> [#uses=1]
%tmp.9 = sub double %tmp.5, %tmp.8 ; <double> [#uses=1]
ret double %tmp.9
}
internal fastcc float %_Z2g3i(int %x) {
entry:
%buffer = alloca [2 x uint] ; <[2 x uint]*> [#uses=3]
%tmp.0 = getelementptr [2 x uint]* %buffer, int 0, int 0 ; <uint*> [#uses=1]
store uint 1127219200, uint* %tmp.0
%tmp.2 = cast int %x to uint ; <uint> [#uses=1]
%tmp.3 = xor uint %tmp.2, 2147483648 ; <uint> [#uses=1]
%tmp.5 = getelementptr [2 x uint]* %buffer, int 0, int 1 ; <uint*> [#uses=1]
store uint %tmp.3, uint* %tmp.5
%tmp.9 = cast [2 x uint]* %buffer to double* ; <double*> [#uses=1]
%tmp.10 = load double* %tmp.9 ; <double> [#uses=1]
%tmp.13 = load double* cast (long* %signed_bias to double*) ; <double> [#uses=1]
%tmp.14 = sub double %tmp.10, %tmp.13 ; <double> [#uses=1]
%tmp.16 = cast double %tmp.14 to float ; <float> [#uses=1]
ret float %tmp.16
}
internal fastcc float %_Z2g4j(uint %x) {
entry:
%buffer = alloca [2 x uint] ; <[2 x uint]*> [#uses=3]
%tmp.0 = getelementptr [2 x uint]* %buffer, int 0, int 0 ; <uint*> [#uses=1]
store uint 1127219200, uint* %tmp.0
%tmp.1 = getelementptr [2 x uint]* %buffer, int 0, int 1 ; <uint*> [#uses=1]
store uint %x, uint* %tmp.1
%tmp.4 = cast [2 x uint]* %buffer to double* ; <double*> [#uses=1]
%tmp.5 = load double* %tmp.4 ; <double> [#uses=1]
%tmp.8 = load double* cast (long* %unsigned_bias to double*) ; <double> [#uses=1]
%tmp.9 = sub double %tmp.5, %tmp.8 ; <double> [#uses=1]
%tmp.11 = cast double %tmp.9 to float ; <float> [#uses=1]
ret float %tmp.11
}
PowerPC Code:
.machine ppc970
.const
.align 2
.CPIl1__Z2f1i_0: ; float 0x4330000080000000
.long 1501560836 ; float 4.5036e+15
.text
.align 2
.globl l1__Z2f1i
l1__Z2f1i:
.LBBl1__Z2f1i_0: ; entry
xoris r2, r3, 32768
stw r2, -4(r1)
lis r2, 17200
stw r2, -8(r1)
lfd f0, -8(r1)
lis r2, ha16(.CPIl1__Z2f1i_0)
lfs f1, lo16(.CPIl1__Z2f1i_0)(r2)
fsub f1, f0, f1
blr
.const
.align 2
.CPIl2__Z2f2j_0: ; float 0x4330000000000000
.long 1501560832 ; float 4.5036e+15
.text
.align 2
.globl l2__Z2f2j
l2__Z2f2j:
.LBBl2__Z2f2j_0: ; entry
stw r3, -4(r1)
lis r2, 17200
stw r2, -8(r1)
lfd f0, -8(r1)
lis r2, ha16(.CPIl2__Z2f2j_0)
lfs f1, lo16(.CPIl2__Z2f2j_0)(r2)
fsub f1, f0, f1
blr
.const
.align 2
.CPIl3__Z2f3i_0: ; float 0x4330000080000000
.long 1501560836 ; float 4.5036e+15
.text
.align 2
.globl l3__Z2f3i
l3__Z2f3i:
.LBBl3__Z2f3i_0: ; entry
xoris r2, r3, 32768
stw r2, -4(r1)
lis r2, 17200
stw r2, -8(r1)
lfd f0, -8(r1)
lis r2, ha16(.CPIl3__Z2f3i_0)
lfs f1, lo16(.CPIl3__Z2f3i_0)(r2)
fsub f0, f0, f1
frsp f1, f0
blr
.const
.align 2
.CPIl4__Z2f4j_0: ; float 0x4330000000000000
.long 1501560832 ; float 4.5036e+15
.text
.align 2
.globl l4__Z2f4j
l4__Z2f4j:
.LBBl4__Z2f4j_0: ; entry
stw r3, -4(r1)
lis r2, 17200
stw r2, -8(r1)
lfd f0, -8(r1)
lis r2, ha16(.CPIl4__Z2f4j_0)
lfs f1, lo16(.CPIl4__Z2f4j_0)(r2)
fsub f0, f0, f1
frsp f1, f0
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22814 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-17 00:39:29 +00:00
|
|
|
Result = ExpandLegalINT_TO_FP(isSigned,
|
|
|
|
LegalizeOp(Node->getOperand(0)),
|
|
|
|
Node->getValueType(0));
|
2006-01-28 07:39:30 +00:00
|
|
|
break;
|
2005-07-28 23:31:12 +00:00
|
|
|
case TargetLowering::Promote:
|
|
|
|
Result = PromoteLegalINT_TO_FP(LegalizeOp(Node->getOperand(0)),
|
|
|
|
Node->getValueType(0),
|
|
|
|
isSigned);
|
|
|
|
break;
|
2005-11-30 06:43:03 +00:00
|
|
|
}
|
2005-07-28 23:31:12 +00:00
|
|
|
break;
|
|
|
|
case Expand:
|
|
|
|
Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP,
|
|
|
|
Node->getValueType(0), Node->getOperand(0));
|
|
|
|
break;
|
|
|
|
case Promote:
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
2005-07-28 23:31:12 +00:00
|
|
|
if (isSigned) {
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp1.getValueType(),
|
|
|
|
Tmp1, DAG.getValueType(Node->getOperand(0).getValueType()));
|
2005-07-28 23:31:12 +00:00
|
|
|
} else {
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp1 = DAG.getZeroExtendInReg(Tmp1,
|
|
|
|
Node->getOperand(0).getValueType());
|
2005-07-28 23:31:12 +00:00
|
|
|
}
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
|
|
|
Result = LegalizeOp(Result); // The 'op' is not necessarily legal!
|
2005-07-28 23:31:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISD::TRUNCATE:
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
2005-07-28 23:31:12 +00:00
|
|
|
break;
|
|
|
|
case Expand:
|
|
|
|
ExpandOp(Node->getOperand(0), Tmp1, Tmp2);
|
|
|
|
|
|
|
|
// Since the result is legal, we should just be able to truncate the low
|
|
|
|
// part of the source.
|
|
|
|
Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Tmp1);
|
|
|
|
break;
|
|
|
|
case Promote:
|
|
|
|
Result = PromoteOp(Node->getOperand(0));
|
|
|
|
Result = DAG.getNode(ISD::TRUNCATE, Op.getValueType(), Result);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2005-07-30 18:33:25 +00:00
|
|
|
|
2005-07-28 23:31:12 +00:00
|
|
|
case ISD::FP_TO_SINT:
|
|
|
|
case ISD::FP_TO_UINT:
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Legal:
|
2005-07-30 00:04:12 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
|
2005-07-29 00:11:56 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))){
|
|
|
|
default: assert(0 && "Unknown operation action!");
|
2006-01-28 07:39:30 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
isCustom = true;
|
|
|
|
// FALLTHROUGH
|
|
|
|
case TargetLowering::Legal:
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
2006-01-28 07:39:30 +00:00
|
|
|
if (isCustom) {
|
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.Val) Result = Tmp1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TargetLowering::Promote:
|
|
|
|
Result = PromoteLegalFP_TO_INT(Tmp1, Node->getValueType(0),
|
|
|
|
Node->getOpcode() == ISD::FP_TO_SINT);
|
|
|
|
break;
|
2005-07-29 00:11:56 +00:00
|
|
|
case TargetLowering::Expand:
|
Teach the legalizer how to legalize FP_TO_UINT.
Teach the legalizer to promote FP_TO_UINT to FP_TO_SINT if the wider
FP_TO_UINT is also illegal. This allows us on PPC to codegen
unsigned short foo(float a) { return a; }
as:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
rlwinm r3, r2, 0, 16, 31
blr
instead of:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
lis r3, ha16(.CPI_foo_0)
lfs f0, lo16(.CPI_foo_0)(r3)
fcmpu cr0, f1, f0
blt .LBB_foo_2 ; entry
.LBB_foo_1: ; entry
fsubs f0, f1, f0
fctiwz f0, f0
stfd f0, -16(r1)
lwz r2, -12(r1)
xoris r2, r2, 32768
.LBB_foo_2: ; entry
rlwinm r3, r2, 0, 16, 31
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22785 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-14 01:20:53 +00:00
|
|
|
if (Node->getOpcode() == ISD::FP_TO_UINT) {
|
|
|
|
SDOperand True, False;
|
|
|
|
MVT::ValueType VT = Node->getOperand(0).getValueType();
|
|
|
|
MVT::ValueType NVT = Node->getValueType(0);
|
2007-09-19 23:55:34 +00:00
|
|
|
const uint64_t zero[] = {0, 0};
|
|
|
|
APFloat apf = APFloat(APInt(MVT::getSizeInBits(VT), 2, zero));
|
2008-02-29 01:44:25 +00:00
|
|
|
APInt x = APInt::getSignBit(MVT::getSizeInBits(NVT));
|
|
|
|
(void)apf.convertFromAPInt(x, false, APFloat::rmNearestTiesToEven);
|
2007-09-19 23:55:34 +00:00
|
|
|
Tmp2 = DAG.getConstantFP(apf, VT);
|
2008-03-10 15:42:14 +00:00
|
|
|
Tmp3 = DAG.getSetCC(TLI.getSetCCResultType(Node->getOperand(0)),
|
Teach the legalizer how to legalize FP_TO_UINT.
Teach the legalizer to promote FP_TO_UINT to FP_TO_SINT if the wider
FP_TO_UINT is also illegal. This allows us on PPC to codegen
unsigned short foo(float a) { return a; }
as:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
rlwinm r3, r2, 0, 16, 31
blr
instead of:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
lis r3, ha16(.CPI_foo_0)
lfs f0, lo16(.CPI_foo_0)(r3)
fcmpu cr0, f1, f0
blt .LBB_foo_2 ; entry
.LBB_foo_1: ; entry
fsubs f0, f1, f0
fctiwz f0, f0
stfd f0, -16(r1)
lwz r2, -12(r1)
xoris r2, r2, 32768
.LBB_foo_2: ; entry
rlwinm r3, r2, 0, 16, 31
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22785 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-14 01:20:53 +00:00
|
|
|
Node->getOperand(0), Tmp2, ISD::SETLT);
|
|
|
|
True = DAG.getNode(ISD::FP_TO_SINT, NVT, Node->getOperand(0));
|
|
|
|
False = DAG.getNode(ISD::FP_TO_SINT, NVT,
|
2005-09-28 22:28:18 +00:00
|
|
|
DAG.getNode(ISD::FSUB, VT, Node->getOperand(0),
|
Teach the legalizer how to legalize FP_TO_UINT.
Teach the legalizer to promote FP_TO_UINT to FP_TO_SINT if the wider
FP_TO_UINT is also illegal. This allows us on PPC to codegen
unsigned short foo(float a) { return a; }
as:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
rlwinm r3, r2, 0, 16, 31
blr
instead of:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
lis r3, ha16(.CPI_foo_0)
lfs f0, lo16(.CPI_foo_0)(r3)
fcmpu cr0, f1, f0
blt .LBB_foo_2 ; entry
.LBB_foo_1: ; entry
fsubs f0, f1, f0
fctiwz f0, f0
stfd f0, -16(r1)
lwz r2, -12(r1)
xoris r2, r2, 32768
.LBB_foo_2: ; entry
rlwinm r3, r2, 0, 16, 31
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22785 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-14 01:20:53 +00:00
|
|
|
Tmp2));
|
|
|
|
False = DAG.getNode(ISD::XOR, NVT, False,
|
2008-02-29 01:44:25 +00:00
|
|
|
DAG.getConstant(x, NVT));
|
2006-01-28 07:39:30 +00:00
|
|
|
Result = DAG.getNode(ISD::SELECT, NVT, Tmp3, True, False);
|
|
|
|
break;
|
Teach the legalizer how to legalize FP_TO_UINT.
Teach the legalizer to promote FP_TO_UINT to FP_TO_SINT if the wider
FP_TO_UINT is also illegal. This allows us on PPC to codegen
unsigned short foo(float a) { return a; }
as:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
rlwinm r3, r2, 0, 16, 31
blr
instead of:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
lis r3, ha16(.CPI_foo_0)
lfs f0, lo16(.CPI_foo_0)(r3)
fcmpu cr0, f1, f0
blt .LBB_foo_2 ; entry
.LBB_foo_1: ; entry
fsubs f0, f1, f0
fctiwz f0, f0
stfd f0, -16(r1)
lwz r2, -12(r1)
xoris r2, r2, 32768
.LBB_foo_2: ; entry
rlwinm r3, r2, 0, 16, 31
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22785 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-14 01:20:53 +00:00
|
|
|
} else {
|
|
|
|
assert(0 && "Do not know how to expand FP_TO_SINT yet!");
|
|
|
|
}
|
|
|
|
break;
|
2005-07-29 00:11:56 +00:00
|
|
|
}
|
2005-07-28 23:31:12 +00:00
|
|
|
break;
|
2006-12-13 01:57:55 +00:00
|
|
|
case Expand: {
|
|
|
|
MVT::ValueType VT = Op.getValueType();
|
2007-10-10 01:01:31 +00:00
|
|
|
MVT::ValueType OVT = Node->getOperand(0).getValueType();
|
2007-10-11 23:32:15 +00:00
|
|
|
// Convert ppcf128 to i32
|
2007-10-10 01:01:31 +00:00
|
|
|
if (OVT == MVT::ppcf128 && VT == MVT::i32) {
|
2008-01-17 07:00:52 +00:00
|
|
|
if (Node->getOpcode() == ISD::FP_TO_SINT) {
|
|
|
|
Result = DAG.getNode(ISD::FP_ROUND_INREG, MVT::ppcf128,
|
|
|
|
Node->getOperand(0), DAG.getValueType(MVT::f64));
|
|
|
|
Result = DAG.getNode(ISD::FP_ROUND, MVT::f64, Result,
|
|
|
|
DAG.getIntPtrConstant(1));
|
|
|
|
Result = DAG.getNode(ISD::FP_TO_SINT, VT, Result);
|
|
|
|
} else {
|
2007-10-11 23:32:15 +00:00
|
|
|
const uint64_t TwoE31[] = {0x41e0000000000000LL, 0};
|
|
|
|
APFloat apf = APFloat(APInt(128, 2, TwoE31));
|
|
|
|
Tmp2 = DAG.getConstantFP(apf, OVT);
|
|
|
|
// X>=2^31 ? (int)(X-2^31)+0x80000000 : (int)X
|
|
|
|
// FIXME: generated code sucks.
|
|
|
|
Result = DAG.getNode(ISD::SELECT_CC, VT, Node->getOperand(0), Tmp2,
|
|
|
|
DAG.getNode(ISD::ADD, MVT::i32,
|
|
|
|
DAG.getNode(ISD::FP_TO_SINT, VT,
|
|
|
|
DAG.getNode(ISD::FSUB, OVT,
|
|
|
|
Node->getOperand(0), Tmp2)),
|
|
|
|
DAG.getConstant(0x80000000, MVT::i32)),
|
|
|
|
DAG.getNode(ISD::FP_TO_SINT, VT,
|
|
|
|
Node->getOperand(0)),
|
|
|
|
DAG.getCondCode(ISD::SETGE));
|
|
|
|
}
|
2007-10-10 01:01:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-10 23:03:31 +00:00
|
|
|
// Convert f32 / f64 to i32 / i64 / i128.
|
2007-01-12 02:11:51 +00:00
|
|
|
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
|
2006-12-13 01:57:55 +00:00
|
|
|
switch (Node->getOpcode()) {
|
2007-09-19 23:55:34 +00:00
|
|
|
case ISD::FP_TO_SINT: {
|
2008-03-10 23:03:31 +00:00
|
|
|
if (VT == MVT::i32) {
|
|
|
|
if (OVT == MVT::f32)
|
|
|
|
LC = RTLIB::FPTOSINT_F32_I32;
|
|
|
|
else if (OVT == MVT::f64)
|
|
|
|
LC = RTLIB::FPTOSINT_F64_I32;
|
|
|
|
else
|
|
|
|
assert(0 && "Unexpected i32-to-fp conversion!");
|
|
|
|
} else if (VT == MVT::i64) {
|
|
|
|
if (OVT == MVT::f32)
|
|
|
|
LC = RTLIB::FPTOSINT_F32_I64;
|
|
|
|
else if (OVT == MVT::f64)
|
|
|
|
LC = RTLIB::FPTOSINT_F64_I64;
|
|
|
|
else if (OVT == MVT::f80)
|
|
|
|
LC = RTLIB::FPTOSINT_F80_I64;
|
|
|
|
else if (OVT == MVT::ppcf128)
|
|
|
|
LC = RTLIB::FPTOSINT_PPCF128_I64;
|
|
|
|
else
|
|
|
|
assert(0 && "Unexpected i64-to-fp conversion!");
|
|
|
|
} else if (VT == MVT::i128) {
|
|
|
|
if (OVT == MVT::f32)
|
|
|
|
LC = RTLIB::FPTOSINT_F32_I128;
|
|
|
|
else if (OVT == MVT::f64)
|
|
|
|
LC = RTLIB::FPTOSINT_F64_I128;
|
|
|
|
else if (OVT == MVT::f80)
|
|
|
|
LC = RTLIB::FPTOSINT_F80_I128;
|
|
|
|
else if (OVT == MVT::ppcf128)
|
|
|
|
LC = RTLIB::FPTOSINT_PPCF128_I128;
|
|
|
|
else
|
|
|
|
assert(0 && "Unexpected i128-to-fp conversion!");
|
|
|
|
} else {
|
|
|
|
assert(0 && "Unexpectd int-to-fp conversion!");
|
2007-09-19 23:55:34 +00:00
|
|
|
}
|
2006-12-13 01:57:55 +00:00
|
|
|
break;
|
2007-09-19 23:55:34 +00:00
|
|
|
}
|
|
|
|
case ISD::FP_TO_UINT: {
|
2008-03-10 23:03:31 +00:00
|
|
|
if (VT == MVT::i32) {
|
|
|
|
if (OVT == MVT::f32)
|
|
|
|
LC = RTLIB::FPTOUINT_F32_I32;
|
|
|
|
else if (OVT == MVT::f64)
|
|
|
|
LC = RTLIB::FPTOUINT_F64_I32;
|
|
|
|
else if (OVT == MVT::f80)
|
|
|
|
LC = RTLIB::FPTOUINT_F80_I32;
|
|
|
|
else
|
|
|
|
assert(0 && "Unexpected i32-to-fp conversion!");
|
|
|
|
} else if (VT == MVT::i64) {
|
|
|
|
if (OVT == MVT::f32)
|
|
|
|
LC = RTLIB::FPTOUINT_F32_I64;
|
|
|
|
else if (OVT == MVT::f64)
|
|
|
|
LC = RTLIB::FPTOUINT_F64_I64;
|
|
|
|
else if (OVT == MVT::f80)
|
|
|
|
LC = RTLIB::FPTOUINT_F80_I64;
|
|
|
|
else if (OVT == MVT::ppcf128)
|
|
|
|
LC = RTLIB::FPTOUINT_PPCF128_I64;
|
|
|
|
else
|
|
|
|
assert(0 && "Unexpected i64-to-fp conversion!");
|
|
|
|
} else if (VT == MVT::i128) {
|
|
|
|
if (OVT == MVT::f32)
|
|
|
|
LC = RTLIB::FPTOUINT_F32_I128;
|
|
|
|
else if (OVT == MVT::f64)
|
|
|
|
LC = RTLIB::FPTOUINT_F64_I128;
|
|
|
|
else if (OVT == MVT::f80)
|
|
|
|
LC = RTLIB::FPTOUINT_F80_I128;
|
|
|
|
else if (OVT == MVT::ppcf128)
|
|
|
|
LC = RTLIB::FPTOUINT_PPCF128_I128;
|
|
|
|
else
|
|
|
|
assert(0 && "Unexpected i128-to-fp conversion!");
|
|
|
|
} else {
|
|
|
|
assert(0 && "Unexpectd int-to-fp conversion!");
|
2007-09-19 23:55:34 +00:00
|
|
|
}
|
2006-12-13 01:57:55 +00:00
|
|
|
break;
|
2007-09-19 23:55:34 +00:00
|
|
|
}
|
2006-12-13 01:57:55 +00:00
|
|
|
default: assert(0 && "Unreachable!");
|
|
|
|
}
|
|
|
|
SDOperand Dummy;
|
2008-04-12 17:14:18 +00:00
|
|
|
Result = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Dummy);
|
2006-12-13 01:57:55 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-07-28 23:31:12 +00:00
|
|
|
case Promote:
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, LegalizeOp(Tmp1));
|
|
|
|
Result = LegalizeOp(Result);
|
2005-07-28 23:31:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2005-07-30 18:33:25 +00:00
|
|
|
|
2008-01-16 06:57:07 +00:00
|
|
|
case ISD::FP_EXTEND: {
|
2008-01-17 07:00:52 +00:00
|
|
|
MVT::ValueType DstVT = Op.getValueType();
|
|
|
|
MVT::ValueType SrcVT = Op.getOperand(0).getValueType();
|
|
|
|
if (TLI.getConvertAction(SrcVT, DstVT) == TargetLowering::Expand) {
|
|
|
|
// The only other way we can lower this is to turn it into a STORE,
|
|
|
|
// LOAD pair, targetting a temporary location (a stack slot).
|
|
|
|
Result = EmitStackConvert(Node->getOperand(0), SrcVT, DstVT);
|
|
|
|
break;
|
2008-01-16 06:57:07 +00:00
|
|
|
}
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Expand: assert(0 && "Shouldn't need to expand other operators here!");
|
|
|
|
case Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
|
|
|
break;
|
|
|
|
case Promote:
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
|
|
|
Result = DAG.getNode(ISD::FP_EXTEND, Op.getValueType(), Tmp1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2008-01-17 07:00:52 +00:00
|
|
|
}
|
2007-08-09 01:04:01 +00:00
|
|
|
case ISD::FP_ROUND: {
|
2008-01-17 07:00:52 +00:00
|
|
|
MVT::ValueType DstVT = Op.getValueType();
|
|
|
|
MVT::ValueType SrcVT = Op.getOperand(0).getValueType();
|
|
|
|
if (TLI.getConvertAction(SrcVT, DstVT) == TargetLowering::Expand) {
|
|
|
|
if (SrcVT == MVT::ppcf128) {
|
2008-01-20 01:18:38 +00:00
|
|
|
SDOperand Lo;
|
|
|
|
ExpandOp(Node->getOperand(0), Lo, Result);
|
2008-01-17 07:00:52 +00:00
|
|
|
// Round it the rest of the way (e.g. to f32) if needed.
|
2008-01-20 01:18:38 +00:00
|
|
|
if (DstVT!=MVT::f64)
|
|
|
|
Result = DAG.getNode(ISD::FP_ROUND, DstVT, Result, Op.getOperand(1));
|
2008-01-17 07:00:52 +00:00
|
|
|
break;
|
2007-08-09 01:04:01 +00:00
|
|
|
}
|
2008-01-17 07:00:52 +00:00
|
|
|
// The only other way we can lower this is to turn it into a STORE,
|
|
|
|
// LOAD pair, targetting a temporary location (a stack slot).
|
|
|
|
Result = EmitStackConvert(Node->getOperand(0), DstVT, DstVT);
|
|
|
|
break;
|
2007-07-03 00:53:03 +00:00
|
|
|
}
|
2008-01-16 06:57:07 +00:00
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Expand: assert(0 && "Shouldn't need to expand other operators here!");
|
|
|
|
case Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
2008-01-17 07:00:52 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1));
|
2008-01-16 06:57:07 +00:00
|
|
|
break;
|
|
|
|
case Promote:
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
2008-01-17 07:00:52 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_ROUND, Op.getValueType(), Tmp1,
|
|
|
|
Node->getOperand(1));
|
2008-01-16 06:57:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2008-01-17 07:00:52 +00:00
|
|
|
}
|
2005-09-02 00:18:10 +00:00
|
|
|
case ISD::ANY_EXTEND:
|
2005-01-07 07:47:09 +00:00
|
|
|
case ISD::ZERO_EXTEND:
|
|
|
|
case ISD::SIGN_EXTEND:
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
2006-01-28 07:39:30 +00:00
|
|
|
case Expand: assert(0 && "Shouldn't need to expand other operators here!");
|
2005-01-07 07:47:09 +00:00
|
|
|
case Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
2008-04-30 00:26:38 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
2008-02-15 23:05:48 +00:00
|
|
|
if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) ==
|
|
|
|
TargetLowering::Custom) {
|
2008-04-30 00:26:38 +00:00
|
|
|
Tmp1 = TLI.LowerOperation(Result, DAG);
|
|
|
|
if (Tmp1.Val) Result = Tmp1;
|
2008-02-15 23:05:48 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
2005-01-15 05:21:40 +00:00
|
|
|
case Promote:
|
|
|
|
switch (Node->getOpcode()) {
|
2005-09-02 00:18:10 +00:00
|
|
|
case ISD::ANY_EXTEND:
|
2006-01-28 10:58:55 +00:00
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
|
|
|
Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Tmp1);
|
2005-09-02 00:18:10 +00:00
|
|
|
break;
|
2005-01-16 00:38:00 +00:00
|
|
|
case ISD::ZERO_EXTEND:
|
|
|
|
Result = PromoteOp(Node->getOperand(0));
|
2005-09-02 00:18:10 +00:00
|
|
|
Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result);
|
2005-04-13 02:38:47 +00:00
|
|
|
Result = DAG.getZeroExtendInReg(Result,
|
|
|
|
Node->getOperand(0).getValueType());
|
2005-01-15 05:21:40 +00:00
|
|
|
break;
|
|
|
|
case ISD::SIGN_EXTEND:
|
2005-01-16 00:38:00 +00:00
|
|
|
Result = PromoteOp(Node->getOperand(0));
|
2005-09-02 00:18:10 +00:00
|
|
|
Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result);
|
2005-01-16 00:38:00 +00:00
|
|
|
Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(),
|
2005-07-10 00:07:11 +00:00
|
|
|
Result,
|
|
|
|
DAG.getValueType(Node->getOperand(0).getValueType()));
|
2005-01-16 00:38:00 +00:00
|
|
|
break;
|
2005-01-15 05:21:40 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-01-15 06:18:18 +00:00
|
|
|
case ISD::FP_ROUND_INREG:
|
2005-04-13 02:38:47 +00:00
|
|
|
case ISD::SIGN_EXTEND_INREG: {
|
2005-01-15 06:18:18 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
2005-07-10 00:07:11 +00:00
|
|
|
MVT::ValueType ExtraVT = cast<VTSDNode>(Node->getOperand(1))->getVT();
|
2005-01-15 07:15:18 +00:00
|
|
|
|
|
|
|
// If this operation is not supported, convert it to a shl/shr or load/store
|
|
|
|
// pair.
|
2005-01-16 07:29:19 +00:00
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), ExtraVT)) {
|
|
|
|
default: assert(0 && "This action not supported for this op yet!");
|
|
|
|
case TargetLowering::Legal:
|
2006-01-28 10:58:55 +00:00
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1));
|
2005-01-16 07:29:19 +00:00
|
|
|
break;
|
|
|
|
case TargetLowering::Expand:
|
2005-01-15 07:15:18 +00:00
|
|
|
// If this is an integer extend and shifts are supported, do that.
|
2005-04-13 02:38:47 +00:00
|
|
|
if (Node->getOpcode() == ISD::SIGN_EXTEND_INREG) {
|
2005-01-15 07:15:18 +00:00
|
|
|
// NOTE: we could fall back on load/store here too for targets without
|
|
|
|
// SAR. However, it is doubtful that any exist.
|
|
|
|
unsigned BitsDiff = MVT::getSizeInBits(Node->getValueType(0)) -
|
|
|
|
MVT::getSizeInBits(ExtraVT);
|
2005-01-22 00:31:52 +00:00
|
|
|
SDOperand ShiftCst = DAG.getConstant(BitsDiff, TLI.getShiftAmountTy());
|
2005-01-15 07:15:18 +00:00
|
|
|
Result = DAG.getNode(ISD::SHL, Node->getValueType(0),
|
|
|
|
Node->getOperand(0), ShiftCst);
|
|
|
|
Result = DAG.getNode(ISD::SRA, Node->getValueType(0),
|
|
|
|
Result, ShiftCst);
|
|
|
|
} else if (Node->getOpcode() == ISD::FP_ROUND_INREG) {
|
2006-10-11 17:52:19 +00:00
|
|
|
// The only way we can lower this is to turn it into a TRUNCSTORE,
|
2005-01-15 07:15:18 +00:00
|
|
|
// EXTLOAD pair, targetting a temporary location (a stack slot).
|
|
|
|
|
|
|
|
// NOTE: there is a choice here between constantly creating new stack
|
|
|
|
// slots and always reusing the same one. We currently always create
|
|
|
|
// new ones, as reuse may inhibit scheduling.
|
2008-01-16 07:51:34 +00:00
|
|
|
Result = EmitStackConvert(Node->getOperand(0), ExtraVT,
|
|
|
|
Node->getValueType(0));
|
2005-01-15 07:15:18 +00:00
|
|
|
} else {
|
|
|
|
assert(0 && "Unknown op");
|
|
|
|
}
|
2005-01-16 07:29:19 +00:00
|
|
|
break;
|
2005-01-15 07:15:18 +00:00
|
|
|
}
|
2005-01-15 06:18:18 +00:00
|
|
|
break;
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
2007-07-27 12:58:54 +00:00
|
|
|
case ISD::TRAMPOLINE: {
|
|
|
|
SDOperand Ops[6];
|
|
|
|
for (unsigned i = 0; i != 6; ++i)
|
|
|
|
Ops[i] = LegalizeOp(Node->getOperand(i));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Ops, 6);
|
|
|
|
// The only option for this node is to custom lower it.
|
|
|
|
Result = TLI.LowerOperation(Result, DAG);
|
|
|
|
assert(Result.Val && "Should always custom lower!");
|
2007-09-11 14:10:23 +00:00
|
|
|
|
|
|
|
// Since trampoline produces two values, make sure to remember that we
|
|
|
|
// legalized both of them.
|
|
|
|
Tmp1 = LegalizeOp(Result.getValue(1));
|
|
|
|
Result = LegalizeOp(Result);
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 0), Result);
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 1), Tmp1);
|
|
|
|
return Op.ResNo ? Tmp1 : Result;
|
2007-11-15 23:25:33 +00:00
|
|
|
}
|
2008-05-14 00:43:10 +00:00
|
|
|
case ISD::FLT_ROUNDS_: {
|
2007-11-15 23:25:33 +00:00
|
|
|
MVT::ValueType VT = Node->getValueType(0);
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), VT)) {
|
|
|
|
default: assert(0 && "This action not supported for this op yet!");
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Op, DAG);
|
|
|
|
if (Result.Val) break;
|
|
|
|
// Fall Thru
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
// If this operation is not supported, lower it to constant 1
|
|
|
|
Result = DAG.getConstant(1, VT);
|
|
|
|
break;
|
|
|
|
}
|
2008-05-12 16:07:15 +00:00
|
|
|
break;
|
2008-01-15 07:02:33 +00:00
|
|
|
}
|
2008-01-15 21:58:08 +00:00
|
|
|
case ISD::TRAP: {
|
2008-01-15 07:02:33 +00:00
|
|
|
MVT::ValueType VT = Node->getValueType(0);
|
|
|
|
switch (TLI.getOperationAction(Node->getOpcode(), VT)) {
|
|
|
|
default: assert(0 && "This action not supported for this op yet!");
|
2008-01-15 21:58:08 +00:00
|
|
|
case TargetLowering::Legal:
|
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
|
|
|
Result = DAG.UpdateNodeOperands(Result, Tmp1);
|
|
|
|
break;
|
2008-01-15 07:02:33 +00:00
|
|
|
case TargetLowering::Custom:
|
|
|
|
Result = TLI.LowerOperation(Op, DAG);
|
|
|
|
if (Result.Val) break;
|
|
|
|
// Fall Thru
|
2008-01-15 21:58:08 +00:00
|
|
|
case TargetLowering::Expand:
|
2008-01-15 07:02:33 +00:00
|
|
|
// If this operation is not supported, lower it to 'abort()' call
|
2008-01-15 21:58:08 +00:00
|
|
|
Tmp1 = LegalizeOp(Node->getOperand(0));
|
2008-01-15 07:02:33 +00:00
|
|
|
TargetLowering::ArgListTy Args;
|
|
|
|
std::pair<SDOperand,SDOperand> CallResult =
|
2008-02-14 17:28:50 +00:00
|
|
|
TLI.LowerCallTo(Tmp1, Type::VoidTy,
|
|
|
|
false, false, false, CallingConv::C, false,
|
2008-01-15 22:09:33 +00:00
|
|
|
DAG.getExternalSymbol("abort", TLI.getPointerTy()),
|
|
|
|
Args, DAG);
|
2008-01-15 07:02:33 +00:00
|
|
|
Result = CallResult.second;
|
|
|
|
break;
|
|
|
|
}
|
2008-01-15 21:58:08 +00:00
|
|
|
break;
|
2007-07-27 12:58:54 +00:00
|
|
|
}
|
2005-01-15 07:15:18 +00:00
|
|
|
}
|
2006-01-28 07:39:30 +00:00
|
|
|
|
2006-04-08 04:13:17 +00:00
|
|
|
assert(Result.getValueType() == Op.getValueType() &&
|
|
|
|
"Bad legalization!");
|
|
|
|
|
2006-01-28 07:39:30 +00:00
|
|
|
// Make sure that the generated code is itself legal.
|
|
|
|
if (Result != Op)
|
|
|
|
Result = LegalizeOp(Result);
|
2005-01-07 07:47:09 +00:00
|
|
|
|
2005-05-12 16:53:42 +00:00
|
|
|
// Note that LegalizeOp may be reentered even from single-use nodes, which
|
|
|
|
// means that we always must cache transformed nodes.
|
|
|
|
AddLegalizedOperand(Op, Result);
|
2005-01-07 07:47:09 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2005-01-15 22:16:26 +00:00
|
|
|
/// PromoteOp - Given an operation that produces a value in an invalid type,
|
|
|
|
/// promote it to compute the value into a larger type. The produced value will
|
|
|
|
/// have the correct bits for the low portion of the register, but no guarantee
|
|
|
|
/// is made about the top bits: it may be zero, sign-extended, or garbage.
|
2005-01-15 05:21:40 +00:00
|
|
|
SDOperand SelectionDAGLegalize::PromoteOp(SDOperand Op) {
|
|
|
|
MVT::ValueType VT = Op.getValueType();
|
2005-01-16 01:11:45 +00:00
|
|
|
MVT::ValueType NVT = TLI.getTypeToTransformTo(VT);
|
2005-01-15 05:21:40 +00:00
|
|
|
assert(getTypeAction(VT) == Promote &&
|
|
|
|
"Caller should expand or legalize operands that are not promotable!");
|
|
|
|
assert(NVT > VT && MVT::isInteger(NVT) == MVT::isInteger(VT) &&
|
|
|
|
"Cannot promote to smaller type!");
|
|
|
|
|
|
|
|
SDOperand Tmp1, Tmp2, Tmp3;
|
|
|
|
SDOperand Result;
|
|
|
|
SDNode *Node = Op.Val;
|
|
|
|
|
2008-04-16 16:15:27 +00:00
|
|
|
DenseMap<SDOperand, SDOperand>::iterator I = PromotedNodes.find(Op);
|
2005-09-02 20:32:45 +00:00
|
|
|
if (I != PromotedNodes.end()) return I->second;
|
2005-05-12 16:53:42 +00:00
|
|
|
|
2005-01-15 05:21:40 +00:00
|
|
|
switch (Node->getOpcode()) {
|
2005-08-16 21:55:35 +00:00
|
|
|
case ISD::CopyFromReg:
|
|
|
|
assert(0 && "CopyFromReg must be legal!");
|
2005-01-15 05:21:40 +00:00
|
|
|
default:
|
2006-07-11 17:58:07 +00:00
|
|
|
#ifndef NDEBUG
|
2007-06-04 16:17:33 +00:00
|
|
|
cerr << "NODE: "; Node->dump(&DAG); cerr << "\n";
|
2006-07-11 17:58:07 +00:00
|
|
|
#endif
|
2005-01-15 05:21:40 +00:00
|
|
|
assert(0 && "Do not know how to promote this operator!");
|
|
|
|
abort();
|
2005-04-01 22:34:39 +00:00
|
|
|
case ISD::UNDEF:
|
|
|
|
Result = DAG.getNode(ISD::UNDEF, NVT);
|
|
|
|
break;
|
2005-01-15 05:21:40 +00:00
|
|
|
case ISD::Constant:
|
2005-08-30 16:56:19 +00:00
|
|
|
if (VT != MVT::i1)
|
|
|
|
Result = DAG.getNode(ISD::SIGN_EXTEND, NVT, Op);
|
|
|
|
else
|
|
|
|
Result = DAG.getNode(ISD::ZERO_EXTEND, NVT, Op);
|
2005-01-15 05:21:40 +00:00
|
|
|
assert(isa<ConstantSDNode>(Result) && "Didn't constant fold zext?");
|
|
|
|
break;
|
|
|
|
case ISD::ConstantFP:
|
|
|
|
Result = DAG.getNode(ISD::FP_EXTEND, NVT, Op);
|
|
|
|
assert(isa<ConstantFPSDNode>(Result) && "Didn't constant fold fp_extend?");
|
|
|
|
break;
|
2005-01-18 17:54:55 +00:00
|
|
|
|
2005-01-18 02:59:52 +00:00
|
|
|
case ISD::SETCC:
|
2008-03-10 15:42:14 +00:00
|
|
|
assert(isTypeLegal(TLI.getSetCCResultType(Node->getOperand(0)))
|
2008-03-14 00:53:31 +00:00
|
|
|
&& "SetCC type is not legal??");
|
2008-03-10 15:42:14 +00:00
|
|
|
Result = DAG.getNode(ISD::SETCC,
|
2008-03-14 00:53:31 +00:00
|
|
|
TLI.getSetCCResultType(Node->getOperand(0)),
|
|
|
|
Node->getOperand(0), Node->getOperand(1),
|
|
|
|
Node->getOperand(2));
|
2005-01-18 02:59:52 +00:00
|
|
|
break;
|
2006-04-12 16:20:43 +00:00
|
|
|
|
2005-01-15 05:21:40 +00:00
|
|
|
case ISD::TRUNCATE:
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Legal:
|
|
|
|
Result = LegalizeOp(Node->getOperand(0));
|
|
|
|
assert(Result.getValueType() >= NVT &&
|
|
|
|
"This truncation doesn't make sense!");
|
|
|
|
if (Result.getValueType() > NVT) // Truncate to NVT instead of VT
|
|
|
|
Result = DAG.getNode(ISD::TRUNCATE, NVT, Result);
|
|
|
|
break;
|
2005-01-28 22:52:50 +00:00
|
|
|
case Promote:
|
|
|
|
// The truncation is not required, because we don't guarantee anything
|
|
|
|
// about high bits anyway.
|
|
|
|
Result = PromoteOp(Node->getOperand(0));
|
|
|
|
break;
|
2005-01-15 05:21:40 +00:00
|
|
|
case Expand:
|
2005-04-04 00:57:08 +00:00
|
|
|
ExpandOp(Node->getOperand(0), Tmp1, Tmp2);
|
|
|
|
// Truncate the low part of the expanded value to the result type
|
2005-08-01 18:16:37 +00:00
|
|
|
Result = DAG.getNode(ISD::TRUNCATE, NVT, Tmp1);
|
2005-01-15 05:21:40 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-01-15 22:16:26 +00:00
|
|
|
case ISD::SIGN_EXTEND:
|
|
|
|
case ISD::ZERO_EXTEND:
|
2005-09-02 00:18:10 +00:00
|
|
|
case ISD::ANY_EXTEND:
|
2005-01-15 22:16:26 +00:00
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Expand: assert(0 && "BUG: Smaller reg should have been promoted!");
|
|
|
|
case Legal:
|
|
|
|
// Input is legal? Just do extend all the way to the larger type.
|
2006-01-28 07:39:30 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0));
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
|
|
|
case Promote:
|
|
|
|
// Promote the reg if it's smaller.
|
|
|
|
Result = PromoteOp(Node->getOperand(0));
|
|
|
|
// The high bits are not guaranteed to be anything. Insert an extend.
|
|
|
|
if (Node->getOpcode() == ISD::SIGN_EXTEND)
|
2005-02-04 18:39:19 +00:00
|
|
|
Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result,
|
2005-07-10 00:07:11 +00:00
|
|
|
DAG.getValueType(Node->getOperand(0).getValueType()));
|
2005-09-02 00:18:10 +00:00
|
|
|
else if (Node->getOpcode() == ISD::ZERO_EXTEND)
|
2005-04-13 02:38:47 +00:00
|
|
|
Result = DAG.getZeroExtendInReg(Result,
|
|
|
|
Node->getOperand(0).getValueType());
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2005-12-23 00:16:34 +00:00
|
|
|
case ISD::BIT_CONVERT:
|
2008-01-16 07:45:30 +00:00
|
|
|
Result = EmitStackConvert(Node->getOperand(0), Node->getValueType(0),
|
|
|
|
Node->getValueType(0));
|
2005-12-23 00:16:34 +00:00
|
|
|
Result = PromoteOp(Result);
|
|
|
|
break;
|
|
|
|
|
2005-01-15 22:16:26 +00:00
|
|
|
case ISD::FP_EXTEND:
|
|
|
|
assert(0 && "Case not implemented. Dynamically dead with 2 FP types!");
|
|
|
|
case ISD::FP_ROUND:
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Expand: assert(0 && "BUG: Cannot expand FP regs!");
|
|
|
|
case Promote: assert(0 && "Unreachable with 2 FP types!");
|
|
|
|
case Legal:
|
2008-01-17 07:00:52 +00:00
|
|
|
if (Node->getConstantOperandVal(1) == 0) {
|
|
|
|
// Input is legal? Do an FP_ROUND_INREG.
|
|
|
|
Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Node->getOperand(0),
|
|
|
|
DAG.getValueType(VT));
|
|
|
|
} else {
|
|
|
|
// Just remove the truncate, it isn't affecting the value.
|
|
|
|
Result = DAG.getNode(ISD::FP_ROUND, NVT, Node->getOperand(0),
|
|
|
|
Node->getOperand(1));
|
|
|
|
}
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ISD::SINT_TO_FP:
|
|
|
|
case ISD::UINT_TO_FP:
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Legal:
|
2005-01-21 06:05:23 +00:00
|
|
|
// No extra round required here.
|
2006-01-28 07:39:30 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0));
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Promote:
|
|
|
|
Result = PromoteOp(Node->getOperand(0));
|
|
|
|
if (Node->getOpcode() == ISD::SINT_TO_FP)
|
|
|
|
Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(),
|
2005-07-10 00:07:11 +00:00
|
|
|
Result,
|
|
|
|
DAG.getValueType(Node->getOperand(0).getValueType()));
|
2005-01-15 22:16:26 +00:00
|
|
|
else
|
2005-04-13 02:38:47 +00:00
|
|
|
Result = DAG.getZeroExtendInReg(Result,
|
|
|
|
Node->getOperand(0).getValueType());
|
2005-01-21 06:05:23 +00:00
|
|
|
// No extra round required here.
|
|
|
|
Result = DAG.getNode(Node->getOpcode(), NVT, Result);
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
|
|
|
case Expand:
|
2005-01-21 06:05:23 +00:00
|
|
|
Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, NVT,
|
|
|
|
Node->getOperand(0));
|
|
|
|
// Round if we cannot tolerate excess precision.
|
|
|
|
if (NoExcessFPPrecision)
|
2005-07-10 00:07:11 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result,
|
|
|
|
DAG.getValueType(VT));
|
2005-01-21 06:05:23 +00:00
|
|
|
break;
|
2005-01-15 22:16:26 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-12-09 17:32:47 +00:00
|
|
|
case ISD::SIGN_EXTEND_INREG:
|
|
|
|
Result = PromoteOp(Node->getOperand(0));
|
|
|
|
Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result,
|
|
|
|
Node->getOperand(1));
|
|
|
|
break;
|
2005-01-15 22:16:26 +00:00
|
|
|
case ISD::FP_TO_SINT:
|
|
|
|
case ISD::FP_TO_UINT:
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Legal:
|
2006-12-16 02:10:30 +00:00
|
|
|
case Expand:
|
2006-01-28 07:39:30 +00:00
|
|
|
Tmp1 = Node->getOperand(0);
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
|
|
|
case Promote:
|
|
|
|
// The input result is prerounded, so we don't have to do anything
|
|
|
|
// special.
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
|
|
|
break;
|
|
|
|
}
|
Teach the legalizer how to legalize FP_TO_UINT.
Teach the legalizer to promote FP_TO_UINT to FP_TO_SINT if the wider
FP_TO_UINT is also illegal. This allows us on PPC to codegen
unsigned short foo(float a) { return a; }
as:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
rlwinm r3, r2, 0, 16, 31
blr
instead of:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
lis r3, ha16(.CPI_foo_0)
lfs f0, lo16(.CPI_foo_0)(r3)
fcmpu cr0, f1, f0
blt .LBB_foo_2 ; entry
.LBB_foo_1: ; entry
fsubs f0, f1, f0
fctiwz f0, f0
stfd f0, -16(r1)
lwz r2, -12(r1)
xoris r2, r2, 32768
.LBB_foo_2: ; entry
rlwinm r3, r2, 0, 16, 31
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22785 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-14 01:20:53 +00:00
|
|
|
// If we're promoting a UINT to a larger size, check to see if the new node
|
|
|
|
// will be legal. If it isn't, check to see if FP_TO_SINT is legal, since
|
|
|
|
// we can use that instead. This allows us to generate better code for
|
|
|
|
// FP_TO_UINT for small destination sizes on targets where FP_TO_UINT is not
|
|
|
|
// legal, such as PowerPC.
|
|
|
|
if (Node->getOpcode() == ISD::FP_TO_UINT &&
|
2005-08-24 16:35:28 +00:00
|
|
|
!TLI.isOperationLegal(ISD::FP_TO_UINT, NVT) &&
|
2005-10-25 23:47:25 +00:00
|
|
|
(TLI.isOperationLegal(ISD::FP_TO_SINT, NVT) ||
|
|
|
|
TLI.getOperationAction(ISD::FP_TO_SINT, NVT)==TargetLowering::Custom)){
|
Teach the legalizer how to legalize FP_TO_UINT.
Teach the legalizer to promote FP_TO_UINT to FP_TO_SINT if the wider
FP_TO_UINT is also illegal. This allows us on PPC to codegen
unsigned short foo(float a) { return a; }
as:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
rlwinm r3, r2, 0, 16, 31
blr
instead of:
_foo:
.LBB_foo_0: ; entry
fctiwz f0, f1
stfd f0, -8(r1)
lwz r2, -4(r1)
lis r3, ha16(.CPI_foo_0)
lfs f0, lo16(.CPI_foo_0)(r3)
fcmpu cr0, f1, f0
blt .LBB_foo_2 ; entry
.LBB_foo_1: ; entry
fsubs f0, f1, f0
fctiwz f0, f0
stfd f0, -16(r1)
lwz r2, -12(r1)
xoris r2, r2, 32768
.LBB_foo_2: ; entry
rlwinm r3, r2, 0, 16, 31
blr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22785 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-14 01:20:53 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_TO_SINT, NVT, Tmp1);
|
|
|
|
} else {
|
|
|
|
Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1);
|
|
|
|
}
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
|
|
|
|
2005-04-02 05:00:07 +00:00
|
|
|
case ISD::FABS:
|
|
|
|
case ISD::FNEG:
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
|
|
|
assert(Tmp1.getValueType() == NVT);
|
|
|
|
Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1);
|
|
|
|
// NOTE: we do not have to do any extra rounding here for
|
|
|
|
// NoExcessFPPrecision, because we know the input will have the appropriate
|
|
|
|
// precision, and these operations don't modify precision at all.
|
|
|
|
break;
|
|
|
|
|
2005-04-28 21:44:33 +00:00
|
|
|
case ISD::FSQRT:
|
|
|
|
case ISD::FSIN:
|
|
|
|
case ISD::FCOS:
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
|
|
|
assert(Tmp1.getValueType() == NVT);
|
|
|
|
Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1);
|
2006-01-28 07:39:30 +00:00
|
|
|
if (NoExcessFPPrecision)
|
2005-07-10 00:07:11 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result,
|
|
|
|
DAG.getValueType(VT));
|
2005-04-28 21:44:33 +00:00
|
|
|
break;
|
|
|
|
|
2007-03-03 23:43:21 +00:00
|
|
|
case ISD::FPOWI: {
|
|
|
|
// Promote f32 powi to f64 powi. Note that this could insert a libcall
|
|
|
|
// directly as well, which may be better.
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
|
|
|
assert(Tmp1.getValueType() == NVT);
|
|
|
|
Result = DAG.getNode(ISD::FPOWI, NVT, Tmp1, Node->getOperand(1));
|
|
|
|
if (NoExcessFPPrecision)
|
|
|
|
Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result,
|
|
|
|
DAG.getValueType(VT));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-02-21 06:45:13 +00:00
|
|
|
case ISD::ATOMIC_LCS: {
|
|
|
|
Tmp2 = PromoteOp(Node->getOperand(2));
|
|
|
|
Tmp3 = PromoteOp(Node->getOperand(3));
|
|
|
|
Result = DAG.getAtomic(Node->getOpcode(), Node->getOperand(0),
|
|
|
|
Node->getOperand(1), Tmp2, Tmp3,
|
|
|
|
cast<AtomicSDNode>(Node)->getVT());
|
|
|
|
// Remember that we legalized the chain.
|
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISD::ATOMIC_LAS:
|
2008-05-05 19:05:59 +00:00
|
|
|
case ISD::ATOMIC_LSS:
|
|
|
|
case ISD::ATOMIC_LOAD_AND:
|
|
|
|
case ISD::ATOMIC_LOAD_OR:
|
|
|
|
case ISD::ATOMIC_LOAD_XOR:
|
|
|
|
case ISD::ATOMIC_LOAD_MIN:
|
|
|
|
case ISD::ATOMIC_LOAD_MAX:
|
|
|
|
case ISD::ATOMIC_LOAD_UMIN:
|
|
|
|
case ISD::ATOMIC_LOAD_UMAX:
|
2008-02-21 06:45:13 +00:00
|
|
|
case ISD::ATOMIC_SWAP: {
|
|
|
|
Tmp2 = PromoteOp(Node->getOperand(2));
|
|
|
|
Result = DAG.getAtomic(Node->getOpcode(), Node->getOperand(0),
|
|
|
|
Node->getOperand(1), Tmp2,
|
|
|
|
cast<AtomicSDNode>(Node)->getVT());
|
|
|
|
// Remember that we legalized the chain.
|
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-01-15 05:21:40 +00:00
|
|
|
case ISD::AND:
|
|
|
|
case ISD::OR:
|
|
|
|
case ISD::XOR:
|
2005-01-15 06:18:18 +00:00
|
|
|
case ISD::ADD:
|
2005-01-15 22:16:26 +00:00
|
|
|
case ISD::SUB:
|
2005-01-15 06:18:18 +00:00
|
|
|
case ISD::MUL:
|
|
|
|
// The input may have strange things in the top bits of the registers, but
|
2005-09-28 22:28:18 +00:00
|
|
|
// these operations don't care. They may have weird bits going out, but
|
2005-01-15 06:18:18 +00:00
|
|
|
// that too is okay if they are integer operations.
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
|
|
|
Tmp2 = PromoteOp(Node->getOperand(1));
|
|
|
|
assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT);
|
|
|
|
Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2);
|
2005-09-28 22:28:18 +00:00
|
|
|
break;
|
|
|
|
case ISD::FADD:
|
|
|
|
case ISD::FSUB:
|
|
|
|
case ISD::FMUL:
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
|
|
|
Tmp2 = PromoteOp(Node->getOperand(1));
|
|
|
|
assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT);
|
|
|
|
Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2);
|
|
|
|
|
|
|
|
// Floating point operations will give excess precision that we may not be
|
|
|
|
// able to tolerate. If we DO allow excess precision, just leave it,
|
|
|
|
// otherwise excise it.
|
2005-01-15 22:16:26 +00:00
|
|
|
// FIXME: Why would we need to round FP ops more than integer ones?
|
|
|
|
// Is Round(Add(Add(A,B),C)) != Round(Add(Round(Add(A,B)), C))
|
2005-09-28 22:28:18 +00:00
|
|
|
if (NoExcessFPPrecision)
|
2005-07-10 00:07:11 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result,
|
|
|
|
DAG.getValueType(VT));
|
2005-01-15 06:18:18 +00:00
|
|
|
break;
|
|
|
|
|
2005-01-15 22:16:26 +00:00
|
|
|
case ISD::SDIV:
|
|
|
|
case ISD::SREM:
|
|
|
|
// These operators require that their input be sign extended.
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
|
|
|
Tmp2 = PromoteOp(Node->getOperand(1));
|
|
|
|
if (MVT::isInteger(NVT)) {
|
2005-07-10 00:07:11 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1,
|
|
|
|
DAG.getValueType(VT));
|
|
|
|
Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2,
|
|
|
|
DAG.getValueType(VT));
|
2005-01-15 22:16:26 +00:00
|
|
|
}
|
|
|
|
Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2);
|
|
|
|
|
|
|
|
// Perform FP_ROUND: this is probably overly pessimistic.
|
|
|
|
if (MVT::isFloatingPoint(NVT) && NoExcessFPPrecision)
|
2005-07-10 00:07:11 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result,
|
|
|
|
DAG.getValueType(VT));
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
2005-09-28 22:28:18 +00:00
|
|
|
case ISD::FDIV:
|
|
|
|
case ISD::FREM:
|
2006-03-05 05:09:38 +00:00
|
|
|
case ISD::FCOPYSIGN:
|
2005-09-28 22:28:18 +00:00
|
|
|
// These operators require that their input be fp extended.
|
2006-05-09 18:20:51 +00:00
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
2008-01-17 07:00:52 +00:00
|
|
|
case Expand: assert(0 && "not implemented");
|
|
|
|
case Legal: Tmp1 = LegalizeOp(Node->getOperand(0)); break;
|
|
|
|
case Promote: Tmp1 = PromoteOp(Node->getOperand(0)); break;
|
2006-05-09 18:20:51 +00:00
|
|
|
}
|
|
|
|
switch (getTypeAction(Node->getOperand(1).getValueType())) {
|
2008-01-17 07:00:52 +00:00
|
|
|
case Expand: assert(0 && "not implemented");
|
|
|
|
case Legal: Tmp2 = LegalizeOp(Node->getOperand(1)); break;
|
|
|
|
case Promote: Tmp2 = PromoteOp(Node->getOperand(1)); break;
|
2006-05-09 18:20:51 +00:00
|
|
|
}
|
2005-09-28 22:28:18 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2);
|
|
|
|
|
|
|
|
// Perform FP_ROUND: this is probably overly pessimistic.
|
2006-03-05 05:09:38 +00:00
|
|
|
if (NoExcessFPPrecision && Node->getOpcode() != ISD::FCOPYSIGN)
|
2005-09-28 22:28:18 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result,
|
|
|
|
DAG.getValueType(VT));
|
|
|
|
break;
|
2005-01-15 22:16:26 +00:00
|
|
|
|
|
|
|
case ISD::UDIV:
|
|
|
|
case ISD::UREM:
|
|
|
|
// These operators require that their input be zero extended.
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
|
|
|
Tmp2 = PromoteOp(Node->getOperand(1));
|
|
|
|
assert(MVT::isInteger(NVT) && "Operators don't apply to FP!");
|
2005-04-13 02:38:47 +00:00
|
|
|
Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT);
|
|
|
|
Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT);
|
2005-01-15 22:16:26 +00:00
|
|
|
Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ISD::SHL:
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
2006-01-28 07:39:30 +00:00
|
|
|
Result = DAG.getNode(ISD::SHL, NVT, Tmp1, Node->getOperand(1));
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
|
|
|
case ISD::SRA:
|
|
|
|
// The input value must be properly sign extended.
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
2005-07-10 00:07:11 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1,
|
|
|
|
DAG.getValueType(VT));
|
2006-01-28 07:39:30 +00:00
|
|
|
Result = DAG.getNode(ISD::SRA, NVT, Tmp1, Node->getOperand(1));
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
|
|
|
case ISD::SRL:
|
|
|
|
// The input value must be properly zero extended.
|
|
|
|
Tmp1 = PromoteOp(Node->getOperand(0));
|
2005-04-13 02:38:47 +00:00
|
|
|
Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT);
|
2006-01-28 07:39:30 +00:00
|
|
|
Result = DAG.getNode(ISD::SRL, NVT, Tmp1, Node->getOperand(1));
|
2005-01-15 22:16:26 +00:00
|
|
|
break;
|
2006-01-28 03:14:31 +00:00
|
|
|
|
|
|
|
case ISD::VAARG:
|
2006-01-28 07:39:30 +00:00
|
|
|
Tmp1 = Node->getOperand(0); // Get the chain.
|
|
|
|
Tmp2 = Node->getOperand(1); // Get the pointer.
|
2006-01-28 03:14:31 +00:00
|
|
|
if (TLI.getOperationAction(ISD::VAARG, VT) == TargetLowering::Custom) {
|
|
|
|
Tmp3 = DAG.getVAArg(VT, Tmp1, Tmp2, Node->getOperand(2));
|
|
|
|
Result = TLI.CustomPromoteOperation(Tmp3, DAG);
|
|
|
|
} else {
|
2008-02-06 22:27:42 +00:00
|
|
|
const Value *V = cast<SrcValueSDNode>(Node->getOperand(2))->getValue();
|
|
|
|
SDOperand VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, V, 0);
|
2006-01-28 03:14:31 +00:00
|
|
|
// Increment the pointer, VAList, to the next vaarg
|
|
|
|
Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList,
|
|
|
|
DAG.getConstant(MVT::getSizeInBits(VT)/8,
|
|
|
|
TLI.getPointerTy()));
|
|
|
|
// Store the incremented VAList to the legalized pointer
|
2008-02-06 22:27:42 +00:00
|
|
|
Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, V, 0);
|
2006-01-28 03:14:31 +00:00
|
|
|
// Load the actual argument out of the pointer VAList
|
2006-10-09 20:57:25 +00:00
|
|
|
Result = DAG.getExtLoad(ISD::EXTLOAD, NVT, Tmp3, VAList, NULL, 0, VT);
|
2006-01-28 03:14:31 +00:00
|
|
|
}
|
|
|
|
// Remember that we legalized the chain.
|
2006-01-28 07:39:30 +00:00
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1)));
|
2006-01-28 03:14:31 +00:00
|
|
|
break;
|
|
|
|
|
2006-10-09 20:57:25 +00:00
|
|
|
case ISD::LOAD: {
|
|
|
|
LoadSDNode *LD = cast<LoadSDNode>(Node);
|
2006-10-10 07:51:21 +00:00
|
|
|
ISD::LoadExtType ExtType = ISD::isNON_EXTLoad(Node)
|
|
|
|
? ISD::EXTLOAD : LD->getExtensionType();
|
|
|
|
Result = DAG.getExtLoad(ExtType, NVT,
|
|
|
|
LD->getChain(), LD->getBasePtr(),
|
2006-10-10 18:54:19 +00:00
|
|
|
LD->getSrcValue(), LD->getSrcValueOffset(),
|
2008-01-30 00:15:11 +00:00
|
|
|
LD->getMemoryVT(),
|
2007-07-09 22:18:38 +00:00
|
|
|
LD->isVolatile(),
|
|
|
|
LD->getAlignment());
|
2005-10-13 20:07:41 +00:00
|
|
|
// Remember that we legalized the chain.
|
2006-01-28 07:39:30 +00:00
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1)));
|
2005-10-13 20:07:41 +00:00
|
|
|
break;
|
2006-10-09 20:57:25 +00:00
|
|
|
}
|
2005-01-15 05:21:40 +00:00
|
|
|
case ISD::SELECT:
|
|
|
|
Tmp2 = PromoteOp(Node->getOperand(1)); // Legalize the op0
|
|
|
|
Tmp3 = PromoteOp(Node->getOperand(2)); // Legalize the op1
|
2006-01-28 07:39:30 +00:00
|
|
|
Result = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), Tmp2, Tmp3);
|
2005-01-15 05:21:40 +00:00
|
|
|
break;
|
2005-08-10 20:51:12 +00:00
|
|
|
case ISD::SELECT_CC:
|
|
|
|
Tmp2 = PromoteOp(Node->getOperand(2)); // True
|
|
|
|
Tmp3 = PromoteOp(Node->getOperand(3)); // False
|
|
|
|
Result = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0),
|
2006-01-28 07:39:30 +00:00
|
|
|
Node->getOperand(1), Tmp2, Tmp3, Node->getOperand(4));
|
2005-08-10 20:51:12 +00:00
|
|
|
break;
|
2006-01-14 03:14:10 +00:00
|
|
|
case ISD::BSWAP:
|
|
|
|
Tmp1 = Node->getOperand(0);
|
|
|
|
Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1);
|
|
|
|
Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1);
|
|
|
|
Result = DAG.getNode(ISD::SRL, NVT, Tmp1,
|
2007-05-18 17:52:13 +00:00
|
|
|
DAG.getConstant(MVT::getSizeInBits(NVT) -
|
|
|
|
MVT::getSizeInBits(VT),
|
2006-01-14 03:14:10 +00:00
|
|
|
TLI.getShiftAmountTy()));
|
|
|
|
break;
|
2005-05-04 19:11:05 +00:00
|
|
|
case ISD::CTPOP:
|
|
|
|
case ISD::CTTZ:
|
|
|
|
case ISD::CTLZ:
|
2006-01-28 07:39:30 +00:00
|
|
|
// Zero extend the argument
|
|
|
|
Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0));
|
2005-05-04 19:11:05 +00:00
|
|
|
// Perform the larger operation, then subtract if needed.
|
|
|
|
Tmp1 = DAG.getNode(Node->getOpcode(), NVT, Tmp1);
|
2006-01-28 07:39:30 +00:00
|
|
|
switch(Node->getOpcode()) {
|
2005-05-04 19:11:05 +00:00
|
|
|
case ISD::CTPOP:
|
|
|
|
Result = Tmp1;
|
|
|
|
break;
|
|
|
|
case ISD::CTTZ:
|
2006-01-28 07:39:30 +00:00
|
|
|
// if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT)
|
2008-03-10 15:42:14 +00:00
|
|
|
Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(Tmp1), Tmp1,
|
2007-05-18 17:52:13 +00:00
|
|
|
DAG.getConstant(MVT::getSizeInBits(NVT), NVT),
|
|
|
|
ISD::SETEQ);
|
2005-07-27 06:12:32 +00:00
|
|
|
Result = DAG.getNode(ISD::SELECT, NVT, Tmp2,
|
2007-05-18 17:52:13 +00:00
|
|
|
DAG.getConstant(MVT::getSizeInBits(VT), NVT), Tmp1);
|
2005-05-04 19:11:05 +00:00
|
|
|
break;
|
|
|
|
case ISD::CTLZ:
|
|
|
|
//Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT))
|
2005-07-27 06:12:32 +00:00
|
|
|
Result = DAG.getNode(ISD::SUB, NVT, Tmp1,
|
2007-05-18 17:52:13 +00:00
|
|
|
DAG.getConstant(MVT::getSizeInBits(NVT) -
|
|
|
|
MVT::getSizeInBits(VT), NVT));
|
2005-05-04 19:11:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::EXTRACT_SUBVECTOR:
|
|
|
|
Result = PromoteOp(ExpandEXTRACT_SUBVECTOR(Op));
|
2007-06-13 15:12:02 +00:00
|
|
|
break;
|
2006-04-02 05:06:04 +00:00
|
|
|
case ISD::EXTRACT_VECTOR_ELT:
|
|
|
|
Result = PromoteOp(ExpandEXTRACT_VECTOR_ELT(Op));
|
|
|
|
break;
|
2005-01-15 05:21:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(Result.Val && "Didn't set a result!");
|
2006-01-28 07:39:30 +00:00
|
|
|
|
|
|
|
// Make sure the result is itself legal.
|
|
|
|
Result = LegalizeOp(Result);
|
|
|
|
|
|
|
|
// Remember that we promoted this!
|
2005-01-15 05:21:40 +00:00
|
|
|
AddPromotedOperand(Op, Result);
|
|
|
|
return Result;
|
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
/// ExpandEXTRACT_VECTOR_ELT - Expand an EXTRACT_VECTOR_ELT operation into
|
|
|
|
/// a legal EXTRACT_VECTOR_ELT operation, scalar code, or memory traffic,
|
|
|
|
/// based on the vector type. The return type of this matches the element type
|
|
|
|
/// of the vector, which may not be legal for the target.
|
|
|
|
SDOperand SelectionDAGLegalize::ExpandEXTRACT_VECTOR_ELT(SDOperand Op) {
|
2006-03-31 17:55:51 +00:00
|
|
|
// We know that operand #0 is the Vec vector. If the index is a constant
|
|
|
|
// or if the invec is a supported hardware type, we can use it. Otherwise,
|
|
|
|
// lower to a store then an indexed load.
|
|
|
|
SDOperand Vec = Op.getOperand(0);
|
2007-06-25 16:23:39 +00:00
|
|
|
SDOperand Idx = Op.getOperand(1);
|
2006-03-31 17:55:51 +00:00
|
|
|
|
2007-09-24 15:54:53 +00:00
|
|
|
MVT::ValueType TVT = Vec.getValueType();
|
2007-06-25 16:23:39 +00:00
|
|
|
unsigned NumElems = MVT::getVectorNumElements(TVT);
|
2006-03-31 17:55:51 +00:00
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::EXTRACT_VECTOR_ELT, TVT)) {
|
|
|
|
default: assert(0 && "This action is not supported yet!");
|
|
|
|
case TargetLowering::Custom: {
|
|
|
|
Vec = LegalizeOp(Vec);
|
|
|
|
Op = DAG.UpdateNodeOperands(Op, Vec, Idx);
|
|
|
|
SDOperand Tmp3 = TLI.LowerOperation(Op, DAG);
|
|
|
|
if (Tmp3.Val)
|
|
|
|
return Tmp3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
if (isTypeLegal(TVT)) {
|
|
|
|
Vec = LegalizeOp(Vec);
|
|
|
|
Op = DAG.UpdateNodeOperands(Op, Vec, Idx);
|
2007-07-26 03:33:13 +00:00
|
|
|
return Op;
|
2007-06-25 16:23:39 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TargetLowering::Expand:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NumElems == 1) {
|
2006-03-31 17:55:51 +00:00
|
|
|
// This must be an access of the only element. Return it.
|
2007-06-25 16:23:39 +00:00
|
|
|
Op = ScalarizeVectorOp(Vec);
|
|
|
|
} else if (!TLI.isTypeLegal(TVT) && isa<ConstantSDNode>(Idx)) {
|
2008-01-29 02:24:00 +00:00
|
|
|
unsigned NumLoElts = 1 << Log2_32(NumElems-1);
|
2007-06-25 16:23:39 +00:00
|
|
|
ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx);
|
2006-03-31 17:55:51 +00:00
|
|
|
SDOperand Lo, Hi;
|
|
|
|
SplitVectorOp(Vec, Lo, Hi);
|
2008-01-29 02:24:00 +00:00
|
|
|
if (CIdx->getValue() < NumLoElts) {
|
2006-03-31 17:55:51 +00:00
|
|
|
Vec = Lo;
|
|
|
|
} else {
|
|
|
|
Vec = Hi;
|
2008-01-29 02:24:00 +00:00
|
|
|
Idx = DAG.getConstant(CIdx->getValue() - NumLoElts,
|
2007-06-25 16:23:39 +00:00
|
|
|
Idx.getValueType());
|
2006-03-31 17:55:51 +00:00
|
|
|
}
|
2007-06-25 16:23:39 +00:00
|
|
|
|
2006-03-31 17:55:51 +00:00
|
|
|
// It's now an extract from the appropriate high or low part. Recurse.
|
|
|
|
Op = DAG.UpdateNodeOperands(Op, Vec, Idx);
|
2007-06-25 16:23:39 +00:00
|
|
|
Op = ExpandEXTRACT_VECTOR_ELT(Op);
|
2006-03-31 17:55:51 +00:00
|
|
|
} else {
|
2007-06-25 16:23:39 +00:00
|
|
|
// Store the value to a temporary stack slot, then LOAD the scalar
|
|
|
|
// element back out.
|
2007-10-15 17:48:57 +00:00
|
|
|
SDOperand StackPtr = DAG.CreateStackTemporary(Vec.getValueType());
|
2007-06-25 16:23:39 +00:00
|
|
|
SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Vec, StackPtr, NULL, 0);
|
|
|
|
|
|
|
|
// Add the offset to the index.
|
|
|
|
unsigned EltSize = MVT::getSizeInBits(Op.getValueType())/8;
|
|
|
|
Idx = DAG.getNode(ISD::MUL, Idx.getValueType(), Idx,
|
|
|
|
DAG.getConstant(EltSize, Idx.getValueType()));
|
2007-10-18 08:32:37 +00:00
|
|
|
|
|
|
|
if (MVT::getSizeInBits(Idx.getValueType()) >
|
|
|
|
MVT::getSizeInBits(TLI.getPointerTy()))
|
2007-10-19 16:47:35 +00:00
|
|
|
Idx = DAG.getNode(ISD::TRUNCATE, TLI.getPointerTy(), Idx);
|
2007-10-18 08:32:37 +00:00
|
|
|
else
|
2007-10-19 16:47:35 +00:00
|
|
|
Idx = DAG.getNode(ISD::ZERO_EXTEND, TLI.getPointerTy(), Idx);
|
2007-10-18 08:32:37 +00:00
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
StackPtr = DAG.getNode(ISD::ADD, Idx.getValueType(), Idx, StackPtr);
|
|
|
|
|
|
|
|
Op = DAG.getLoad(Op.getValueType(), Ch, StackPtr, NULL, 0);
|
2006-03-31 17:55:51 +00:00
|
|
|
}
|
2007-06-25 16:23:39 +00:00
|
|
|
return Op;
|
2006-03-31 17:55:51 +00:00
|
|
|
}
|
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
/// ExpandEXTRACT_SUBVECTOR - Expand a EXTRACT_SUBVECTOR operation. For now
|
2007-06-13 15:12:02 +00:00
|
|
|
/// we assume the operation can be split if it is not already legal.
|
2007-06-25 16:23:39 +00:00
|
|
|
SDOperand SelectionDAGLegalize::ExpandEXTRACT_SUBVECTOR(SDOperand Op) {
|
2007-06-13 15:12:02 +00:00
|
|
|
// We know that operand #0 is the Vec vector. For now we assume the index
|
|
|
|
// is a constant and that the extracted result is a supported hardware type.
|
|
|
|
SDOperand Vec = Op.getOperand(0);
|
|
|
|
SDOperand Idx = LegalizeOp(Op.getOperand(1));
|
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
unsigned NumElems = MVT::getVectorNumElements(Vec.getValueType());
|
2007-06-13 15:12:02 +00:00
|
|
|
|
|
|
|
if (NumElems == MVT::getVectorNumElements(Op.getValueType())) {
|
|
|
|
// This must be an access of the desired vector length. Return it.
|
2007-06-25 16:23:39 +00:00
|
|
|
return Vec;
|
2007-06-13 15:12:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ConstantSDNode *CIdx = cast<ConstantSDNode>(Idx);
|
|
|
|
SDOperand Lo, Hi;
|
|
|
|
SplitVectorOp(Vec, Lo, Hi);
|
|
|
|
if (CIdx->getValue() < NumElems/2) {
|
|
|
|
Vec = Lo;
|
|
|
|
} else {
|
|
|
|
Vec = Hi;
|
|
|
|
Idx = DAG.getConstant(CIdx->getValue() - NumElems/2, Idx.getValueType());
|
|
|
|
}
|
|
|
|
|
|
|
|
// It's now an extract from the appropriate high or low part. Recurse.
|
|
|
|
Op = DAG.UpdateNodeOperands(Op, Vec, Idx);
|
2007-06-25 16:23:39 +00:00
|
|
|
return ExpandEXTRACT_SUBVECTOR(Op);
|
2006-04-02 05:06:04 +00:00
|
|
|
}
|
|
|
|
|
2006-02-01 07:19:44 +00:00
|
|
|
/// LegalizeSetCCOperands - Attempts to create a legal LHS and RHS for a SETCC
|
|
|
|
/// with condition CC on the current target. This usually involves legalizing
|
|
|
|
/// or promoting the arguments. In the case where LHS and RHS must be expanded,
|
|
|
|
/// there may be no choice but to create a new SetCC node to represent the
|
|
|
|
/// legalized value of setcc lhs, rhs. In this case, the value is returned in
|
|
|
|
/// LHS, and the SDOperand returned in RHS has a nil SDNode value.
|
|
|
|
void SelectionDAGLegalize::LegalizeSetCCOperands(SDOperand &LHS,
|
|
|
|
SDOperand &RHS,
|
|
|
|
SDOperand &CC) {
|
2007-10-06 01:24:11 +00:00
|
|
|
SDOperand Tmp1, Tmp2, Tmp3, Result;
|
2006-02-01 07:19:44 +00:00
|
|
|
|
|
|
|
switch (getTypeAction(LHS.getValueType())) {
|
|
|
|
case Legal:
|
|
|
|
Tmp1 = LegalizeOp(LHS); // LHS
|
|
|
|
Tmp2 = LegalizeOp(RHS); // RHS
|
|
|
|
break;
|
|
|
|
case Promote:
|
|
|
|
Tmp1 = PromoteOp(LHS); // LHS
|
|
|
|
Tmp2 = PromoteOp(RHS); // RHS
|
|
|
|
|
|
|
|
// If this is an FP compare, the operands have already been extended.
|
|
|
|
if (MVT::isInteger(LHS.getValueType())) {
|
|
|
|
MVT::ValueType VT = LHS.getValueType();
|
|
|
|
MVT::ValueType NVT = TLI.getTypeToTransformTo(VT);
|
|
|
|
|
|
|
|
// Otherwise, we have to insert explicit sign or zero extends. Note
|
|
|
|
// that we could insert sign extends for ALL conditions, but zero extend
|
|
|
|
// is cheaper on many machines (an AND instead of two shifts), so prefer
|
|
|
|
// it.
|
|
|
|
switch (cast<CondCodeSDNode>(CC)->get()) {
|
|
|
|
default: assert(0 && "Unknown integer comparison!");
|
|
|
|
case ISD::SETEQ:
|
|
|
|
case ISD::SETNE:
|
|
|
|
case ISD::SETUGE:
|
|
|
|
case ISD::SETUGT:
|
|
|
|
case ISD::SETULE:
|
|
|
|
case ISD::SETULT:
|
|
|
|
// ALL of these operations will work if we either sign or zero extend
|
|
|
|
// the operands (including the unsigned comparisons!). Zero extend is
|
|
|
|
// usually a simpler/cheaper operation, so prefer it.
|
|
|
|
Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT);
|
|
|
|
Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT);
|
|
|
|
break;
|
|
|
|
case ISD::SETGE:
|
|
|
|
case ISD::SETGT:
|
|
|
|
case ISD::SETLT:
|
|
|
|
case ISD::SETLE:
|
|
|
|
Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1,
|
|
|
|
DAG.getValueType(VT));
|
|
|
|
Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2,
|
|
|
|
DAG.getValueType(VT));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2006-12-15 02:59:56 +00:00
|
|
|
case Expand: {
|
|
|
|
MVT::ValueType VT = LHS.getValueType();
|
|
|
|
if (VT == MVT::f32 || VT == MVT::f64) {
|
|
|
|
// Expand into one or more soft-fp libcall(s).
|
2007-01-12 02:11:51 +00:00
|
|
|
RTLIB::Libcall LC1, LC2 = RTLIB::UNKNOWN_LIBCALL;
|
2006-12-15 02:59:56 +00:00
|
|
|
switch (cast<CondCodeSDNode>(CC)->get()) {
|
|
|
|
case ISD::SETEQ:
|
|
|
|
case ISD::SETOEQ:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC1 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
|
|
|
case ISD::SETNE:
|
|
|
|
case ISD::SETUNE:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC1 = (VT == MVT::f32) ? RTLIB::UNE_F32 : RTLIB::UNE_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
|
|
|
case ISD::SETGE:
|
|
|
|
case ISD::SETOGE:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC1 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
|
|
|
case ISD::SETLT:
|
|
|
|
case ISD::SETOLT:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
|
|
|
case ISD::SETLE:
|
|
|
|
case ISD::SETOLE:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC1 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
|
|
|
case ISD::SETGT:
|
|
|
|
case ISD::SETOGT:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC1 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
|
|
|
case ISD::SETUO:
|
2007-01-31 09:29:11 +00:00
|
|
|
LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64;
|
|
|
|
break;
|
2006-12-15 02:59:56 +00:00
|
|
|
case ISD::SETO:
|
2007-02-03 00:43:46 +00:00
|
|
|
LC1 = (VT == MVT::f32) ? RTLIB::O_F32 : RTLIB::O_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
switch (cast<CondCodeSDNode>(CC)->get()) {
|
|
|
|
case ISD::SETONE:
|
|
|
|
// SETONE = SETOLT | SETOGT
|
2007-01-12 02:11:51 +00:00
|
|
|
LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
// Fallthrough
|
|
|
|
case ISD::SETUGT:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC2 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
|
|
|
case ISD::SETUGE:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC2 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
|
|
|
case ISD::SETULT:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC2 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
|
|
|
case ISD::SETULE:
|
2007-01-12 02:11:51 +00:00
|
|
|
LC2 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64;
|
2006-12-15 02:59:56 +00:00
|
|
|
break;
|
2007-01-12 02:11:51 +00:00
|
|
|
case ISD::SETUEQ:
|
|
|
|
LC2 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64;
|
|
|
|
break;
|
2006-12-15 02:59:56 +00:00
|
|
|
default: assert(0 && "Unsupported FP setcc!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SDOperand Dummy;
|
2008-04-12 17:14:18 +00:00
|
|
|
Tmp1 = ExpandLibCall(LC1,
|
2006-12-31 05:55:36 +00:00
|
|
|
DAG.getNode(ISD::MERGE_VALUES, VT, LHS, RHS).Val,
|
2007-01-03 04:22:32 +00:00
|
|
|
false /*sign irrelevant*/, Dummy);
|
2006-12-15 02:59:56 +00:00
|
|
|
Tmp2 = DAG.getConstant(0, MVT::i32);
|
2007-01-31 09:29:11 +00:00
|
|
|
CC = DAG.getCondCode(TLI.getCmpLibcallCC(LC1));
|
2007-01-12 02:11:51 +00:00
|
|
|
if (LC2 != RTLIB::UNKNOWN_LIBCALL) {
|
2008-03-10 15:42:14 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(Tmp1), Tmp1, Tmp2,
|
2008-03-14 00:53:31 +00:00
|
|
|
CC);
|
2008-04-12 17:14:18 +00:00
|
|
|
LHS = ExpandLibCall(LC2,
|
|
|
|
DAG.getNode(ISD::MERGE_VALUES, VT, LHS, RHS).Val,
|
2007-01-03 04:22:32 +00:00
|
|
|
false /*sign irrelevant*/, Dummy);
|
2008-03-10 15:42:14 +00:00
|
|
|
Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(LHS), LHS, Tmp2,
|
2007-01-31 09:29:11 +00:00
|
|
|
DAG.getCondCode(TLI.getCmpLibcallCC(LC2)));
|
2006-12-15 02:59:56 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2);
|
|
|
|
Tmp2 = SDOperand();
|
|
|
|
}
|
|
|
|
LHS = Tmp1;
|
|
|
|
RHS = Tmp2;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-02-01 07:19:44 +00:00
|
|
|
SDOperand LHSLo, LHSHi, RHSLo, RHSHi;
|
|
|
|
ExpandOp(LHS, LHSLo, LHSHi);
|
2007-10-06 01:24:11 +00:00
|
|
|
ExpandOp(RHS, RHSLo, RHSHi);
|
|
|
|
ISD::CondCode CCCode = cast<CondCodeSDNode>(CC)->get();
|
|
|
|
|
|
|
|
if (VT==MVT::ppcf128) {
|
|
|
|
// FIXME: This generated code sucks. We want to generate
|
|
|
|
// FCMP crN, hi1, hi2
|
|
|
|
// BNE crN, L:
|
|
|
|
// FCMP crN, lo1, lo2
|
|
|
|
// The following can be improved, but not that much.
|
2008-03-10 15:42:14 +00:00
|
|
|
Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, ISD::SETEQ);
|
|
|
|
Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(LHSLo), LHSLo, RHSLo, CCCode);
|
2007-10-06 01:24:11 +00:00
|
|
|
Tmp3 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2);
|
2008-03-10 15:42:14 +00:00
|
|
|
Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, ISD::SETNE);
|
|
|
|
Tmp2 = DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi, CCCode);
|
2007-10-06 01:24:11 +00:00
|
|
|
Tmp1 = DAG.getNode(ISD::AND, Tmp1.getValueType(), Tmp1, Tmp2);
|
|
|
|
Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp3);
|
|
|
|
Tmp2 = SDOperand();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (CCCode) {
|
2006-02-01 07:19:44 +00:00
|
|
|
case ISD::SETEQ:
|
|
|
|
case ISD::SETNE:
|
|
|
|
if (RHSLo == RHSHi)
|
|
|
|
if (ConstantSDNode *RHSCST = dyn_cast<ConstantSDNode>(RHSLo))
|
|
|
|
if (RHSCST->isAllOnesValue()) {
|
|
|
|
// Comparison to -1.
|
|
|
|
Tmp1 = DAG.getNode(ISD::AND, LHSLo.getValueType(), LHSLo, LHSHi);
|
|
|
|
Tmp2 = RHSLo;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tmp1 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSLo, RHSLo);
|
|
|
|
Tmp2 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSHi, RHSHi);
|
|
|
|
Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2);
|
|
|
|
Tmp2 = DAG.getConstant(0, Tmp1.getValueType());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// If this is a comparison of the sign bit, just look at the top part.
|
|
|
|
// X > -1, x < 0
|
|
|
|
if (ConstantSDNode *CST = dyn_cast<ConstantSDNode>(RHS))
|
|
|
|
if ((cast<CondCodeSDNode>(CC)->get() == ISD::SETLT &&
|
2008-03-13 22:13:53 +00:00
|
|
|
CST->isNullValue()) || // X < 0
|
2006-02-01 07:19:44 +00:00
|
|
|
(cast<CondCodeSDNode>(CC)->get() == ISD::SETGT &&
|
|
|
|
CST->isAllOnesValue())) { // X > -1
|
|
|
|
Tmp1 = LHSHi;
|
|
|
|
Tmp2 = RHSHi;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: This generated code sucks.
|
|
|
|
ISD::CondCode LowCC;
|
2007-02-08 22:16:19 +00:00
|
|
|
switch (CCCode) {
|
2006-02-01 07:19:44 +00:00
|
|
|
default: assert(0 && "Unknown integer setcc!");
|
|
|
|
case ISD::SETLT:
|
|
|
|
case ISD::SETULT: LowCC = ISD::SETULT; break;
|
|
|
|
case ISD::SETGT:
|
|
|
|
case ISD::SETUGT: LowCC = ISD::SETUGT; break;
|
|
|
|
case ISD::SETLE:
|
|
|
|
case ISD::SETULE: LowCC = ISD::SETULE; break;
|
|
|
|
case ISD::SETGE:
|
|
|
|
case ISD::SETUGE: LowCC = ISD::SETUGE; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tmp1 = lo(op1) < lo(op2) // Always unsigned comparison
|
|
|
|
// Tmp2 = hi(op1) < hi(op2) // Signedness depends on operands
|
|
|
|
// dest = hi(op1) == hi(op2) ? Tmp1 : Tmp2;
|
|
|
|
|
|
|
|
// NOTE: on targets without efficient SELECT of bools, we can always use
|
|
|
|
// this identity: (B1 ? B2 : B3) --> (B1 & B2)|(!B1&B3)
|
2007-02-08 22:16:19 +00:00
|
|
|
TargetLowering::DAGCombinerInfo DagCombineInfo(DAG, false, true, NULL);
|
2008-03-10 15:42:14 +00:00
|
|
|
Tmp1 = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSLo), LHSLo, RHSLo,
|
2008-03-14 00:53:31 +00:00
|
|
|
LowCC, false, DagCombineInfo);
|
2007-02-08 22:16:19 +00:00
|
|
|
if (!Tmp1.Val)
|
2008-03-10 15:42:14 +00:00
|
|
|
Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSLo), LHSLo, RHSLo, LowCC);
|
|
|
|
Tmp2 = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi,
|
2007-02-08 22:16:19 +00:00
|
|
|
CCCode, false, DagCombineInfo);
|
|
|
|
if (!Tmp2.Val)
|
2008-03-10 15:42:14 +00:00
|
|
|
Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(LHSHi), LHSHi,
|
2008-03-14 00:53:31 +00:00
|
|
|
RHSHi,CC);
|
2007-02-08 22:16:19 +00:00
|
|
|
|
|
|
|
ConstantSDNode *Tmp1C = dyn_cast<ConstantSDNode>(Tmp1.Val);
|
|
|
|
ConstantSDNode *Tmp2C = dyn_cast<ConstantSDNode>(Tmp2.Val);
|
2008-03-13 22:13:53 +00:00
|
|
|
if ((Tmp1C && Tmp1C->isNullValue()) ||
|
|
|
|
(Tmp2C && Tmp2C->isNullValue() &&
|
2007-02-08 22:16:19 +00:00
|
|
|
(CCCode == ISD::SETLE || CCCode == ISD::SETGE ||
|
|
|
|
CCCode == ISD::SETUGE || CCCode == ISD::SETULE)) ||
|
2008-03-13 22:13:53 +00:00
|
|
|
(Tmp2C && Tmp2C->getAPIntValue() == 1 &&
|
2007-02-08 22:16:19 +00:00
|
|
|
(CCCode == ISD::SETLT || CCCode == ISD::SETGT ||
|
|
|
|
CCCode == ISD::SETUGT || CCCode == ISD::SETULT))) {
|
|
|
|
// low part is known false, returns high part.
|
|
|
|
// For LE / GE, if high part is known false, ignore the low part.
|
|
|
|
// For LT / GT, if high part is known true, ignore the low part.
|
|
|
|
Tmp1 = Tmp2;
|
|
|
|
Tmp2 = SDOperand();
|
|
|
|
} else {
|
2008-03-10 15:42:14 +00:00
|
|
|
Result = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi,
|
2007-02-08 22:16:19 +00:00
|
|
|
ISD::SETEQ, false, DagCombineInfo);
|
|
|
|
if (!Result.Val)
|
2008-03-10 15:42:14 +00:00
|
|
|
Result=DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi,
|
2008-03-14 00:53:31 +00:00
|
|
|
ISD::SETEQ);
|
2007-02-08 22:16:19 +00:00
|
|
|
Result = LegalizeOp(DAG.getNode(ISD::SELECT, Tmp1.getValueType(),
|
|
|
|
Result, Tmp1, Tmp2));
|
|
|
|
Tmp1 = Result;
|
|
|
|
Tmp2 = SDOperand();
|
|
|
|
}
|
2006-02-01 07:19:44 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-15 02:59:56 +00:00
|
|
|
}
|
2006-02-01 07:19:44 +00:00
|
|
|
LHS = Tmp1;
|
|
|
|
RHS = Tmp2;
|
|
|
|
}
|
|
|
|
|
2008-01-16 07:45:30 +00:00
|
|
|
/// EmitStackConvert - Emit a store/load combination to the stack. This stores
|
|
|
|
/// SrcOp to a stack slot of type SlotVT, truncating it if needed. It then does
|
|
|
|
/// a load from the stack slot to DestVT, extending it if needed.
|
|
|
|
/// The resultant code need not be legal.
|
|
|
|
SDOperand SelectionDAGLegalize::EmitStackConvert(SDOperand SrcOp,
|
|
|
|
MVT::ValueType SlotVT,
|
|
|
|
MVT::ValueType DestVT) {
|
2005-12-23 00:16:34 +00:00
|
|
|
// Create the stack frame object.
|
2008-01-16 07:45:30 +00:00
|
|
|
SDOperand FIPtr = DAG.CreateStackTemporary(SlotVT);
|
|
|
|
|
2008-02-11 18:58:42 +00:00
|
|
|
FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(FIPtr);
|
2008-02-06 22:27:42 +00:00
|
|
|
int SPFI = StackPtrFI->getIndex();
|
|
|
|
|
2008-01-16 07:45:30 +00:00
|
|
|
unsigned SrcSize = MVT::getSizeInBits(SrcOp.getValueType());
|
|
|
|
unsigned SlotSize = MVT::getSizeInBits(SlotVT);
|
|
|
|
unsigned DestSize = MVT::getSizeInBits(DestVT);
|
|
|
|
|
|
|
|
// Emit a store to the stack slot. Use a truncstore if the input value is
|
|
|
|
// later than DestVT.
|
|
|
|
SDOperand Store;
|
|
|
|
if (SrcSize > SlotSize)
|
2008-02-06 22:27:42 +00:00
|
|
|
Store = DAG.getTruncStore(DAG.getEntryNode(), SrcOp, FIPtr,
|
2008-02-07 18:41:25 +00:00
|
|
|
PseudoSourceValue::getFixedStack(),
|
2008-02-06 22:27:42 +00:00
|
|
|
SPFI, SlotVT);
|
2008-01-16 07:45:30 +00:00
|
|
|
else {
|
|
|
|
assert(SrcSize == SlotSize && "Invalid store");
|
2008-02-06 22:27:42 +00:00
|
|
|
Store = DAG.getStore(DAG.getEntryNode(), SrcOp, FIPtr,
|
2008-02-07 18:41:25 +00:00
|
|
|
PseudoSourceValue::getFixedStack(),
|
2008-02-06 22:27:42 +00:00
|
|
|
SPFI, SlotVT);
|
2008-01-16 07:45:30 +00:00
|
|
|
}
|
2005-12-23 00:16:34 +00:00
|
|
|
|
|
|
|
// Result is a load from the stack slot.
|
2008-01-16 07:45:30 +00:00
|
|
|
if (SlotSize == DestSize)
|
|
|
|
return DAG.getLoad(DestVT, Store, FIPtr, NULL, 0);
|
|
|
|
|
|
|
|
assert(SlotSize < DestSize && "Unknown extension!");
|
|
|
|
return DAG.getExtLoad(ISD::EXTLOAD, DestVT, Store, FIPtr, NULL, 0, SlotVT);
|
2005-12-23 00:16:34 +00:00
|
|
|
}
|
|
|
|
|
2006-04-04 17:23:26 +00:00
|
|
|
SDOperand SelectionDAGLegalize::ExpandSCALAR_TO_VECTOR(SDNode *Node) {
|
|
|
|
// Create a vector sized/aligned stack slot, store the value to element #0,
|
|
|
|
// then load the whole vector back out.
|
2007-10-15 17:48:57 +00:00
|
|
|
SDOperand StackPtr = DAG.CreateStackTemporary(Node->getValueType(0));
|
2008-02-06 22:27:42 +00:00
|
|
|
|
2008-02-11 18:58:42 +00:00
|
|
|
FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(StackPtr);
|
2008-02-06 22:27:42 +00:00
|
|
|
int SPFI = StackPtrFI->getIndex();
|
|
|
|
|
2006-10-05 23:01:46 +00:00
|
|
|
SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Node->getOperand(0), StackPtr,
|
2008-02-07 18:41:25 +00:00
|
|
|
PseudoSourceValue::getFixedStack(), SPFI);
|
2008-02-06 22:27:42 +00:00
|
|
|
return DAG.getLoad(Node->getValueType(0), Ch, StackPtr,
|
2008-02-07 18:41:25 +00:00
|
|
|
PseudoSourceValue::getFixedStack(), SPFI);
|
2006-04-04 17:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-19 06:31:19 +00:00
|
|
|
/// ExpandBUILD_VECTOR - Expand a BUILD_VECTOR node on targets that don't
|
2007-07-16 14:29:03 +00:00
|
|
|
/// support the operation, but do support the resultant vector type.
|
2006-03-19 06:31:19 +00:00
|
|
|
SDOperand SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) {
|
|
|
|
|
|
|
|
// If the only non-undef value is the low element, turn this into a
|
2006-03-20 01:52:29 +00:00
|
|
|
// SCALAR_TO_VECTOR node. If this is { X, X, X, X }, determine X.
|
2006-03-24 01:17:21 +00:00
|
|
|
unsigned NumElems = Node->getNumOperands();
|
2006-03-19 06:31:19 +00:00
|
|
|
bool isOnlyLowElement = true;
|
2006-03-20 01:52:29 +00:00
|
|
|
SDOperand SplatValue = Node->getOperand(0);
|
2008-03-09 00:29:42 +00:00
|
|
|
|
|
|
|
// FIXME: it would be far nicer to change this into map<SDOperand,uint64_t>
|
|
|
|
// and use a bitmask instead of a list of elements.
|
2006-03-24 01:17:21 +00:00
|
|
|
std::map<SDOperand, std::vector<unsigned> > Values;
|
|
|
|
Values[SplatValue].push_back(0);
|
2006-03-24 07:29:17 +00:00
|
|
|
bool isConstant = true;
|
|
|
|
if (!isa<ConstantFPSDNode>(SplatValue) && !isa<ConstantSDNode>(SplatValue) &&
|
|
|
|
SplatValue.getOpcode() != ISD::UNDEF)
|
|
|
|
isConstant = false;
|
|
|
|
|
2006-03-24 01:17:21 +00:00
|
|
|
for (unsigned i = 1; i < NumElems; ++i) {
|
|
|
|
SDOperand V = Node->getOperand(i);
|
2006-04-19 23:17:50 +00:00
|
|
|
Values[V].push_back(i);
|
2006-03-24 01:17:21 +00:00
|
|
|
if (V.getOpcode() != ISD::UNDEF)
|
2006-03-19 06:31:19 +00:00
|
|
|
isOnlyLowElement = false;
|
2006-03-24 01:17:21 +00:00
|
|
|
if (SplatValue != V)
|
2006-03-20 01:52:29 +00:00
|
|
|
SplatValue = SDOperand(0,0);
|
2006-03-24 07:29:17 +00:00
|
|
|
|
|
|
|
// If this isn't a constant element or an undef, we can't use a constant
|
|
|
|
// pool load.
|
|
|
|
if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V) &&
|
|
|
|
V.getOpcode() != ISD::UNDEF)
|
|
|
|
isConstant = false;
|
2006-03-19 06:31:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isOnlyLowElement) {
|
|
|
|
// If the low element is an undef too, then this whole things is an undef.
|
|
|
|
if (Node->getOperand(0).getOpcode() == ISD::UNDEF)
|
|
|
|
return DAG.getNode(ISD::UNDEF, Node->getValueType(0));
|
|
|
|
// Otherwise, turn this into a scalar_to_vector node.
|
|
|
|
return DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0),
|
|
|
|
Node->getOperand(0));
|
|
|
|
}
|
|
|
|
|
2006-03-24 07:29:17 +00:00
|
|
|
// If all elements are constants, create a load from the constant pool.
|
2006-03-19 06:31:19 +00:00
|
|
|
if (isConstant) {
|
|
|
|
MVT::ValueType VT = Node->getValueType(0);
|
|
|
|
std::vector<Constant*> CV;
|
2006-03-24 01:17:21 +00:00
|
|
|
for (unsigned i = 0, e = NumElems; i != e; ++i) {
|
2006-03-19 06:31:19 +00:00
|
|
|
if (ConstantFPSDNode *V =
|
|
|
|
dyn_cast<ConstantFPSDNode>(Node->getOperand(i))) {
|
2008-04-20 00:41:09 +00:00
|
|
|
CV.push_back(ConstantFP::get(V->getValueAPF()));
|
2006-03-19 06:31:19 +00:00
|
|
|
} else if (ConstantSDNode *V =
|
2008-04-20 00:41:09 +00:00
|
|
|
dyn_cast<ConstantSDNode>(Node->getOperand(i))) {
|
|
|
|
CV.push_back(ConstantInt::get(V->getAPIntValue()));
|
2006-03-19 06:31:19 +00:00
|
|
|
} else {
|
|
|
|
assert(Node->getOperand(i).getOpcode() == ISD::UNDEF);
|
2008-04-20 00:41:09 +00:00
|
|
|
const Type *OpNTy =
|
|
|
|
MVT::getTypeForValueType(Node->getOperand(0).getValueType());
|
2006-03-19 06:31:19 +00:00
|
|
|
CV.push_back(UndefValue::get(OpNTy));
|
|
|
|
}
|
|
|
|
}
|
2007-02-15 02:26:10 +00:00
|
|
|
Constant *CP = ConstantVector::get(CV);
|
2006-03-19 06:31:19 +00:00
|
|
|
SDOperand CPIdx = DAG.getConstantPool(CP, TLI.getPointerTy());
|
2008-02-06 22:27:42 +00:00
|
|
|
return DAG.getLoad(VT, DAG.getEntryNode(), CPIdx,
|
2008-02-07 18:41:25 +00:00
|
|
|
PseudoSourceValue::getConstantPool(), 0);
|
2006-03-19 06:31:19 +00:00
|
|
|
}
|
2006-03-24 07:29:17 +00:00
|
|
|
|
|
|
|
if (SplatValue.Val) { // Splat of one value?
|
|
|
|
// Build the shuffle constant vector: <0, 0, 0, 0>
|
|
|
|
MVT::ValueType MaskVT =
|
|
|
|
MVT::getIntVectorWithNumElements(NumElems);
|
2007-06-14 22:58:02 +00:00
|
|
|
SDOperand Zero = DAG.getConstant(0, MVT::getVectorElementType(MaskVT));
|
2006-03-24 07:29:17 +00:00
|
|
|
std::vector<SDOperand> ZeroVec(NumElems, Zero);
|
2006-08-08 02:23:42 +00:00
|
|
|
SDOperand SplatMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT,
|
|
|
|
&ZeroVec[0], ZeroVec.size());
|
2006-03-24 01:17:21 +00:00
|
|
|
|
2006-03-24 07:29:17 +00:00
|
|
|
// If the target supports VECTOR_SHUFFLE and this shuffle mask, use it.
|
2006-04-04 17:23:26 +00:00
|
|
|
if (isShuffleLegal(Node->getValueType(0), SplatMask)) {
|
2006-03-24 07:29:17 +00:00
|
|
|
// Get the splatted value into the low element of a vector register.
|
|
|
|
SDOperand LowValVec =
|
|
|
|
DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), SplatValue);
|
|
|
|
|
|
|
|
// Return shuffle(LowValVec, undef, <0,0,0,0>)
|
|
|
|
return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), LowValVec,
|
|
|
|
DAG.getNode(ISD::UNDEF, Node->getValueType(0)),
|
|
|
|
SplatMask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-24 01:17:21 +00:00
|
|
|
// If there are only two unique elements, we may be able to turn this into a
|
|
|
|
// vector shuffle.
|
|
|
|
if (Values.size() == 2) {
|
2008-03-09 00:29:42 +00:00
|
|
|
// Get the two values in deterministic order.
|
|
|
|
SDOperand Val1 = Node->getOperand(1);
|
|
|
|
SDOperand Val2;
|
|
|
|
std::map<SDOperand, std::vector<unsigned> >::iterator MI = Values.begin();
|
|
|
|
if (MI->first != Val1)
|
|
|
|
Val2 = MI->first;
|
|
|
|
else
|
|
|
|
Val2 = (++MI)->first;
|
|
|
|
|
|
|
|
// If Val1 is an undef, make sure end ends up as Val2, to ensure that our
|
|
|
|
// vector shuffle has the undef vector on the RHS.
|
|
|
|
if (Val1.getOpcode() == ISD::UNDEF)
|
|
|
|
std::swap(Val1, Val2);
|
|
|
|
|
2006-03-24 01:17:21 +00:00
|
|
|
// Build the shuffle constant vector: e.g. <0, 4, 0, 4>
|
2008-03-09 00:29:42 +00:00
|
|
|
MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(NumElems);
|
|
|
|
MVT::ValueType MaskEltVT = MVT::getVectorElementType(MaskVT);
|
2006-03-24 01:17:21 +00:00
|
|
|
std::vector<SDOperand> MaskVec(NumElems);
|
2008-03-09 00:29:42 +00:00
|
|
|
|
|
|
|
// Set elements of the shuffle mask for Val1.
|
|
|
|
std::vector<unsigned> &Val1Elts = Values[Val1];
|
|
|
|
for (unsigned i = 0, e = Val1Elts.size(); i != e; ++i)
|
|
|
|
MaskVec[Val1Elts[i]] = DAG.getConstant(0, MaskEltVT);
|
|
|
|
|
|
|
|
// Set elements of the shuffle mask for Val2.
|
|
|
|
std::vector<unsigned> &Val2Elts = Values[Val2];
|
|
|
|
for (unsigned i = 0, e = Val2Elts.size(); i != e; ++i)
|
|
|
|
if (Val2.getOpcode() != ISD::UNDEF)
|
|
|
|
MaskVec[Val2Elts[i]] = DAG.getConstant(NumElems, MaskEltVT);
|
|
|
|
else
|
|
|
|
MaskVec[Val2Elts[i]] = DAG.getNode(ISD::UNDEF, MaskEltVT);
|
|
|
|
|
2006-08-08 02:23:42 +00:00
|
|
|
SDOperand ShuffleMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT,
|
|
|
|
&MaskVec[0], MaskVec.size());
|
2006-03-24 01:17:21 +00:00
|
|
|
|
2008-03-09 00:29:42 +00:00
|
|
|
// If the target supports SCALAR_TO_VECTOR and this shuffle mask, use it.
|
2006-04-04 17:23:26 +00:00
|
|
|
if (TLI.isOperationLegal(ISD::SCALAR_TO_VECTOR, Node->getValueType(0)) &&
|
|
|
|
isShuffleLegal(Node->getValueType(0), ShuffleMask)) {
|
2008-03-09 00:29:42 +00:00
|
|
|
Val1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), Val1);
|
|
|
|
Val2 = DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), Val2);
|
|
|
|
SDOperand Ops[] = { Val1, Val2, ShuffleMask };
|
2006-03-24 01:17:21 +00:00
|
|
|
|
|
|
|
// Return shuffle(LoValVec, HiValVec, <0,1,0,1>)
|
2008-03-09 00:29:42 +00:00
|
|
|
return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), Ops, 3);
|
2006-03-24 01:17:21 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-19 06:31:19 +00:00
|
|
|
|
|
|
|
// Otherwise, we can't handle this case efficiently. Allocate a sufficiently
|
|
|
|
// aligned object on the stack, store each element into it, then load
|
|
|
|
// the result as a vector.
|
|
|
|
MVT::ValueType VT = Node->getValueType(0);
|
|
|
|
// Create the stack frame object.
|
2007-10-15 17:48:57 +00:00
|
|
|
SDOperand FIPtr = DAG.CreateStackTemporary(VT);
|
2006-03-19 06:31:19 +00:00
|
|
|
|
|
|
|
// Emit a store of each element to the stack slot.
|
2006-08-08 02:23:42 +00:00
|
|
|
SmallVector<SDOperand, 8> Stores;
|
2006-03-19 06:31:19 +00:00
|
|
|
unsigned TypeByteSize =
|
|
|
|
MVT::getSizeInBits(Node->getOperand(0).getValueType())/8;
|
|
|
|
// Store (in the right endianness) the elements to memory.
|
|
|
|
for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) {
|
|
|
|
// Ignore undef elements.
|
|
|
|
if (Node->getOperand(i).getOpcode() == ISD::UNDEF) continue;
|
|
|
|
|
2006-03-22 01:46:54 +00:00
|
|
|
unsigned Offset = TypeByteSize*i;
|
2006-03-19 06:31:19 +00:00
|
|
|
|
|
|
|
SDOperand Idx = DAG.getConstant(Offset, FIPtr.getValueType());
|
|
|
|
Idx = DAG.getNode(ISD::ADD, FIPtr.getValueType(), FIPtr, Idx);
|
|
|
|
|
2006-10-05 23:01:46 +00:00
|
|
|
Stores.push_back(DAG.getStore(DAG.getEntryNode(), Node->getOperand(i), Idx,
|
2006-10-13 21:14:26 +00:00
|
|
|
NULL, 0));
|
2006-03-19 06:31:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SDOperand StoreChain;
|
|
|
|
if (!Stores.empty()) // Not all undef elements?
|
2006-08-08 02:23:42 +00:00
|
|
|
StoreChain = DAG.getNode(ISD::TokenFactor, MVT::Other,
|
|
|
|
&Stores[0], Stores.size());
|
2006-03-19 06:31:19 +00:00
|
|
|
else
|
|
|
|
StoreChain = DAG.getEntryNode();
|
|
|
|
|
|
|
|
// Result is a load from the stack slot.
|
2006-10-09 20:57:25 +00:00
|
|
|
return DAG.getLoad(VT, StoreChain, FIPtr, NULL, 0);
|
2006-03-19 06:31:19 +00:00
|
|
|
}
|
|
|
|
|
2005-04-02 04:00:59 +00:00
|
|
|
void SelectionDAGLegalize::ExpandShiftParts(unsigned NodeOp,
|
|
|
|
SDOperand Op, SDOperand Amt,
|
|
|
|
SDOperand &Lo, SDOperand &Hi) {
|
|
|
|
// Expand the subcomponents.
|
|
|
|
SDOperand LHSL, LHSH;
|
|
|
|
ExpandOp(Op, LHSL, LHSH);
|
|
|
|
|
2006-08-08 02:23:42 +00:00
|
|
|
SDOperand Ops[] = { LHSL, LHSH, Amt };
|
2006-08-14 23:53:35 +00:00
|
|
|
MVT::ValueType VT = LHSL.getValueType();
|
|
|
|
Lo = DAG.getNode(NodeOp, DAG.getNodeValueTypes(VT, VT), 2, Ops, 3);
|
2005-04-02 04:00:59 +00:00
|
|
|
Hi = Lo.getValue(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-19 04:19:40 +00:00
|
|
|
/// ExpandShift - Try to find a clever way to expand this shift operation out to
|
|
|
|
/// smaller elements. If we can't find a way that is more efficient than a
|
|
|
|
/// libcall on this target, return false. Otherwise, return true with the
|
|
|
|
/// low-parts expanded into Lo and Hi.
|
|
|
|
bool SelectionDAGLegalize::ExpandShift(unsigned Opc, SDOperand Op,SDOperand Amt,
|
|
|
|
SDOperand &Lo, SDOperand &Hi) {
|
|
|
|
assert((Opc == ISD::SHL || Opc == ISD::SRA || Opc == ISD::SRL) &&
|
|
|
|
"This is not a shift!");
|
2005-04-06 21:13:14 +00:00
|
|
|
|
2005-01-19 04:19:40 +00:00
|
|
|
MVT::ValueType NVT = TLI.getTypeToTransformTo(Op.getValueType());
|
2005-04-06 21:13:14 +00:00
|
|
|
SDOperand ShAmt = LegalizeOp(Amt);
|
|
|
|
MVT::ValueType ShTy = ShAmt.getValueType();
|
2008-02-20 16:57:27 +00:00
|
|
|
unsigned ShBits = MVT::getSizeInBits(ShTy);
|
2005-04-06 21:13:14 +00:00
|
|
|
unsigned VTBits = MVT::getSizeInBits(Op.getValueType());
|
|
|
|
unsigned NVTBits = MVT::getSizeInBits(NVT);
|
|
|
|
|
2007-10-14 20:35:12 +00:00
|
|
|
// Handle the case when Amt is an immediate.
|
2005-04-06 21:13:14 +00:00
|
|
|
if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Amt.Val)) {
|
|
|
|
unsigned Cst = CN->getValue();
|
|
|
|
// Expand the incoming operand to be shifted, so that we have its parts
|
|
|
|
SDOperand InL, InH;
|
|
|
|
ExpandOp(Op, InL, InH);
|
|
|
|
switch(Opc) {
|
|
|
|
case ISD::SHL:
|
|
|
|
if (Cst > VTBits) {
|
|
|
|
Lo = DAG.getConstant(0, NVT);
|
|
|
|
Hi = DAG.getConstant(0, NVT);
|
|
|
|
} else if (Cst > NVTBits) {
|
|
|
|
Lo = DAG.getConstant(0, NVT);
|
|
|
|
Hi = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst-NVTBits,ShTy));
|
2005-04-11 20:08:52 +00:00
|
|
|
} else if (Cst == NVTBits) {
|
|
|
|
Lo = DAG.getConstant(0, NVT);
|
|
|
|
Hi = InL;
|
2005-04-06 21:13:14 +00:00
|
|
|
} else {
|
|
|
|
Lo = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst, ShTy));
|
|
|
|
Hi = DAG.getNode(ISD::OR, NVT,
|
|
|
|
DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(Cst, ShTy)),
|
|
|
|
DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(NVTBits-Cst, ShTy)));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case ISD::SRL:
|
|
|
|
if (Cst > VTBits) {
|
|
|
|
Lo = DAG.getConstant(0, NVT);
|
|
|
|
Hi = DAG.getConstant(0, NVT);
|
|
|
|
} else if (Cst > NVTBits) {
|
|
|
|
Lo = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst-NVTBits,ShTy));
|
|
|
|
Hi = DAG.getConstant(0, NVT);
|
2005-04-11 20:08:52 +00:00
|
|
|
} else if (Cst == NVTBits) {
|
|
|
|
Lo = InH;
|
|
|
|
Hi = DAG.getConstant(0, NVT);
|
2005-04-06 21:13:14 +00:00
|
|
|
} else {
|
|
|
|
Lo = DAG.getNode(ISD::OR, NVT,
|
|
|
|
DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)),
|
|
|
|
DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy)));
|
|
|
|
Hi = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst, ShTy));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case ISD::SRA:
|
|
|
|
if (Cst > VTBits) {
|
2005-04-21 22:36:52 +00:00
|
|
|
Hi = Lo = DAG.getNode(ISD::SRA, NVT, InH,
|
2005-04-06 21:13:14 +00:00
|
|
|
DAG.getConstant(NVTBits-1, ShTy));
|
|
|
|
} else if (Cst > NVTBits) {
|
2005-04-21 22:36:52 +00:00
|
|
|
Lo = DAG.getNode(ISD::SRA, NVT, InH,
|
2005-04-06 21:13:14 +00:00
|
|
|
DAG.getConstant(Cst-NVTBits, ShTy));
|
2005-04-21 22:36:52 +00:00
|
|
|
Hi = DAG.getNode(ISD::SRA, NVT, InH,
|
2005-04-06 21:13:14 +00:00
|
|
|
DAG.getConstant(NVTBits-1, ShTy));
|
2005-04-11 20:08:52 +00:00
|
|
|
} else if (Cst == NVTBits) {
|
|
|
|
Lo = InH;
|
2005-04-21 22:36:52 +00:00
|
|
|
Hi = DAG.getNode(ISD::SRA, NVT, InH,
|
2005-04-11 20:08:52 +00:00
|
|
|
DAG.getConstant(NVTBits-1, ShTy));
|
2005-04-06 21:13:14 +00:00
|
|
|
} else {
|
|
|
|
Lo = DAG.getNode(ISD::OR, NVT,
|
|
|
|
DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)),
|
|
|
|
DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy)));
|
|
|
|
Hi = DAG.getNode(ISD::SRA, NVT, InH, DAG.getConstant(Cst, ShTy));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
Expand 64-bit shifts more optimally if we know that the high bit of the
shift amount is one or zero. For example, for:
long long foo1(long long X, int C) {
return X << (C|32);
}
long long foo2(long long X, int C) {
return X << (C&~32);
}
we get:
_foo1:
movb $31, %cl
movl 4(%esp), %edx
andb 12(%esp), %cl
shll %cl, %edx
xorl %eax, %eax
ret
_foo2:
movb $223, %cl
movl 4(%esp), %eax
movl 8(%esp), %edx
andb 12(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
ret
instead of:
_foo1:
subl $4, %esp
movl %ebx, (%esp)
movb $32, %bl
movl 8(%esp), %eax
movl 12(%esp), %edx
movb %bl, %cl
orb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
_foo2:
subl $4, %esp
movl %ebx, (%esp)
movb $223, %cl
movl 8(%esp), %eax
movl 12(%esp), %edx
andb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
xorb %bl, %bl
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30506 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-20 03:38:48 +00:00
|
|
|
|
|
|
|
// Okay, the shift amount isn't constant. However, if we can tell that it is
|
|
|
|
// >= 32 or < 32, we can still simplify it, without knowing the actual value.
|
2008-02-20 16:57:27 +00:00
|
|
|
APInt Mask = APInt::getHighBitsSet(ShBits, ShBits - Log2_32(NVTBits));
|
|
|
|
APInt KnownZero, KnownOne;
|
2007-06-22 14:59:07 +00:00
|
|
|
DAG.ComputeMaskedBits(Amt, Mask, KnownZero, KnownOne);
|
Expand 64-bit shifts more optimally if we know that the high bit of the
shift amount is one or zero. For example, for:
long long foo1(long long X, int C) {
return X << (C|32);
}
long long foo2(long long X, int C) {
return X << (C&~32);
}
we get:
_foo1:
movb $31, %cl
movl 4(%esp), %edx
andb 12(%esp), %cl
shll %cl, %edx
xorl %eax, %eax
ret
_foo2:
movb $223, %cl
movl 4(%esp), %eax
movl 8(%esp), %edx
andb 12(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
ret
instead of:
_foo1:
subl $4, %esp
movl %ebx, (%esp)
movb $32, %bl
movl 8(%esp), %eax
movl 12(%esp), %edx
movb %bl, %cl
orb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
_foo2:
subl $4, %esp
movl %ebx, (%esp)
movb $223, %cl
movl 8(%esp), %eax
movl 12(%esp), %edx
andb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
xorb %bl, %bl
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30506 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-20 03:38:48 +00:00
|
|
|
|
2008-02-22 01:12:31 +00:00
|
|
|
// If we know that if any of the high bits of the shift amount are one, then
|
|
|
|
// we can do this as a couple of simple shifts.
|
2008-02-20 16:57:27 +00:00
|
|
|
if (KnownOne.intersects(Mask)) {
|
Expand 64-bit shifts more optimally if we know that the high bit of the
shift amount is one or zero. For example, for:
long long foo1(long long X, int C) {
return X << (C|32);
}
long long foo2(long long X, int C) {
return X << (C&~32);
}
we get:
_foo1:
movb $31, %cl
movl 4(%esp), %edx
andb 12(%esp), %cl
shll %cl, %edx
xorl %eax, %eax
ret
_foo2:
movb $223, %cl
movl 4(%esp), %eax
movl 8(%esp), %edx
andb 12(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
ret
instead of:
_foo1:
subl $4, %esp
movl %ebx, (%esp)
movb $32, %bl
movl 8(%esp), %eax
movl 12(%esp), %edx
movb %bl, %cl
orb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
_foo2:
subl $4, %esp
movl %ebx, (%esp)
movb $223, %cl
movl 8(%esp), %eax
movl 12(%esp), %edx
andb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
xorb %bl, %bl
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30506 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-20 03:38:48 +00:00
|
|
|
// Mask out the high bit, which we know is set.
|
|
|
|
Amt = DAG.getNode(ISD::AND, Amt.getValueType(), Amt,
|
2008-02-20 16:57:27 +00:00
|
|
|
DAG.getConstant(~Mask, Amt.getValueType()));
|
Expand 64-bit shifts more optimally if we know that the high bit of the
shift amount is one or zero. For example, for:
long long foo1(long long X, int C) {
return X << (C|32);
}
long long foo2(long long X, int C) {
return X << (C&~32);
}
we get:
_foo1:
movb $31, %cl
movl 4(%esp), %edx
andb 12(%esp), %cl
shll %cl, %edx
xorl %eax, %eax
ret
_foo2:
movb $223, %cl
movl 4(%esp), %eax
movl 8(%esp), %edx
andb 12(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
ret
instead of:
_foo1:
subl $4, %esp
movl %ebx, (%esp)
movb $32, %bl
movl 8(%esp), %eax
movl 12(%esp), %edx
movb %bl, %cl
orb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
_foo2:
subl $4, %esp
movl %ebx, (%esp)
movb $223, %cl
movl 8(%esp), %eax
movl 12(%esp), %edx
andb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
xorb %bl, %bl
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30506 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-20 03:38:48 +00:00
|
|
|
|
|
|
|
// Expand the incoming operand to be shifted, so that we have its parts
|
|
|
|
SDOperand InL, InH;
|
|
|
|
ExpandOp(Op, InL, InH);
|
|
|
|
switch(Opc) {
|
|
|
|
case ISD::SHL:
|
|
|
|
Lo = DAG.getConstant(0, NVT); // Low part is zero.
|
|
|
|
Hi = DAG.getNode(ISD::SHL, NVT, InL, Amt); // High part from Lo part.
|
|
|
|
return true;
|
|
|
|
case ISD::SRL:
|
|
|
|
Hi = DAG.getConstant(0, NVT); // Hi part is zero.
|
|
|
|
Lo = DAG.getNode(ISD::SRL, NVT, InH, Amt); // Lo part from Hi part.
|
|
|
|
return true;
|
|
|
|
case ISD::SRA:
|
|
|
|
Hi = DAG.getNode(ISD::SRA, NVT, InH, // Sign extend high part.
|
|
|
|
DAG.getConstant(NVTBits-1, Amt.getValueType()));
|
|
|
|
Lo = DAG.getNode(ISD::SRA, NVT, InH, Amt); // Lo part from Hi part.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-22 01:12:31 +00:00
|
|
|
// If we know that the high bits of the shift amount are all zero, then we can
|
|
|
|
// do this as a couple of simple shifts.
|
|
|
|
if ((KnownZero & Mask) == Mask) {
|
Expand 64-bit shifts more optimally if we know that the high bit of the
shift amount is one or zero. For example, for:
long long foo1(long long X, int C) {
return X << (C|32);
}
long long foo2(long long X, int C) {
return X << (C&~32);
}
we get:
_foo1:
movb $31, %cl
movl 4(%esp), %edx
andb 12(%esp), %cl
shll %cl, %edx
xorl %eax, %eax
ret
_foo2:
movb $223, %cl
movl 4(%esp), %eax
movl 8(%esp), %edx
andb 12(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
ret
instead of:
_foo1:
subl $4, %esp
movl %ebx, (%esp)
movb $32, %bl
movl 8(%esp), %eax
movl 12(%esp), %edx
movb %bl, %cl
orb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
_foo2:
subl $4, %esp
movl %ebx, (%esp)
movb $223, %cl
movl 8(%esp), %eax
movl 12(%esp), %edx
andb 16(%esp), %cl
shldl %cl, %eax, %edx
shll %cl, %eax
xorl %ecx, %ecx
xorb %bl, %bl
testb %bl, %bl
cmovne %eax, %edx
cmovne %ecx, %eax
movl (%esp), %ebx
addl $4, %esp
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30506 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-20 03:38:48 +00:00
|
|
|
// Compute 32-amt.
|
|
|
|
SDOperand Amt2 = DAG.getNode(ISD::SUB, Amt.getValueType(),
|
|
|
|
DAG.getConstant(NVTBits, Amt.getValueType()),
|
|
|
|
Amt);
|
|
|
|
|
|
|
|
// Expand the incoming operand to be shifted, so that we have its parts
|
|
|
|
SDOperand InL, InH;
|
|
|
|
ExpandOp(Op, InL, InH);
|
|
|
|
switch(Opc) {
|
|
|
|
case ISD::SHL:
|
|
|
|
Lo = DAG.getNode(ISD::SHL, NVT, InL, Amt);
|
|
|
|
Hi = DAG.getNode(ISD::OR, NVT,
|
|
|
|
DAG.getNode(ISD::SHL, NVT, InH, Amt),
|
|
|
|
DAG.getNode(ISD::SRL, NVT, InL, Amt2));
|
|
|
|
return true;
|
|
|
|
case ISD::SRL:
|
|
|
|
Hi = DAG.getNode(ISD::SRL, NVT, InH, Amt);
|
|
|
|
Lo = DAG.getNode(ISD::OR, NVT,
|
|
|
|
DAG.getNode(ISD::SRL, NVT, InL, Amt),
|
|
|
|
DAG.getNode(ISD::SHL, NVT, InH, Amt2));
|
|
|
|
return true;
|
|
|
|
case ISD::SRA:
|
|
|
|
Hi = DAG.getNode(ISD::SRA, NVT, InH, Amt);
|
|
|
|
Lo = DAG.getNode(ISD::OR, NVT,
|
|
|
|
DAG.getNode(ISD::SRL, NVT, InL, Amt),
|
|
|
|
DAG.getNode(ISD::SHL, NVT, InH, Amt2));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-06 21:13:14 +00:00
|
|
|
return false;
|
2005-01-19 04:19:40 +00:00
|
|
|
}
|
2005-01-21 06:05:23 +00:00
|
|
|
|
2005-01-23 04:42:50 +00:00
|
|
|
|
2005-01-21 06:05:23 +00:00
|
|
|
// ExpandLibCall - Expand a node into a call to a libcall. If the result value
|
|
|
|
// does not fit into a register, return the lo part and set the hi part to the
|
|
|
|
// by-reg argument. If it does fit into a single register, return the result
|
|
|
|
// and leave the Hi part unset.
|
2008-04-12 17:14:18 +00:00
|
|
|
SDOperand SelectionDAGLegalize::ExpandLibCall(RTLIB::Libcall LC, SDNode *Node,
|
2006-12-31 05:55:36 +00:00
|
|
|
bool isSigned, SDOperand &Hi) {
|
2006-02-13 09:18:02 +00:00
|
|
|
assert(!IsLegalizingCall && "Cannot overlap legalization of calls!");
|
|
|
|
// The input chain to this libcall is the entry node of the function.
|
|
|
|
// Legalizing the call will automatically add the previous call to the
|
|
|
|
// dependence.
|
|
|
|
SDOperand InChain = DAG.getEntryNode();
|
|
|
|
|
2005-01-21 06:05:23 +00:00
|
|
|
TargetLowering::ArgListTy Args;
|
2006-12-31 05:55:36 +00:00
|
|
|
TargetLowering::ArgListEntry Entry;
|
2005-01-21 06:05:23 +00:00
|
|
|
for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) {
|
|
|
|
MVT::ValueType ArgVT = Node->getOperand(i).getValueType();
|
|
|
|
const Type *ArgTy = MVT::getTypeForValueType(ArgVT);
|
2006-12-31 05:55:36 +00:00
|
|
|
Entry.Node = Node->getOperand(i); Entry.Ty = ArgTy;
|
2007-03-07 16:25:09 +00:00
|
|
|
Entry.isSExt = isSigned;
|
2008-02-14 17:28:50 +00:00
|
|
|
Entry.isZExt = !isSigned;
|
2006-12-31 05:55:36 +00:00
|
|
|
Args.push_back(Entry);
|
2005-01-21 06:05:23 +00:00
|
|
|
}
|
2008-04-12 17:14:18 +00:00
|
|
|
SDOperand Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
|
|
|
|
TLI.getPointerTy());
|
2005-04-21 22:36:52 +00:00
|
|
|
|
2005-05-11 19:02:11 +00:00
|
|
|
// Splice the libcall in wherever FindInputOutputChains tells us to.
|
2005-01-21 06:05:23 +00:00
|
|
|
const Type *RetTy = MVT::getTypeForValueType(Node->getValueType(0));
|
2005-05-11 19:02:11 +00:00
|
|
|
std::pair<SDOperand,SDOperand> CallInfo =
|
2008-02-14 17:28:50 +00:00
|
|
|
TLI.LowerCallTo(InChain, RetTy, isSigned, !isSigned, false, CallingConv::C,
|
|
|
|
false, Callee, Args, DAG);
|
2005-05-11 19:02:11 +00:00
|
|
|
|
2006-02-13 09:18:02 +00:00
|
|
|
// Legalize the call sequence, starting with the chain. This will advance
|
|
|
|
// the LastCALLSEQ_END to the legalized version of the CALLSEQ_END node that
|
|
|
|
// was added by LowerCallTo (guaranteeing proper serialization of calls).
|
|
|
|
LegalizeOp(CallInfo.second);
|
2005-09-02 20:26:58 +00:00
|
|
|
SDOperand Result;
|
2005-05-11 19:02:11 +00:00
|
|
|
switch (getTypeAction(CallInfo.first.getValueType())) {
|
2005-01-21 06:05:23 +00:00
|
|
|
default: assert(0 && "Unknown thing");
|
|
|
|
case Legal:
|
2006-01-28 07:39:30 +00:00
|
|
|
Result = CallInfo.first;
|
2005-09-02 20:26:58 +00:00
|
|
|
break;
|
2005-01-21 06:05:23 +00:00
|
|
|
case Expand:
|
2005-09-02 20:26:58 +00:00
|
|
|
ExpandOp(CallInfo.first, Result, Hi);
|
|
|
|
break;
|
2005-01-21 06:05:23 +00:00
|
|
|
}
|
2006-01-28 08:25:58 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-27 07:33:31 +00:00
|
|
|
/// ExpandIntToFP - Expand a [US]INT_TO_FP operation.
|
|
|
|
///
|
2006-01-28 08:25:58 +00:00
|
|
|
SDOperand SelectionDAGLegalize::
|
|
|
|
ExpandIntToFP(bool isSigned, MVT::ValueType DestTy, SDOperand Source) {
|
2008-03-05 01:08:17 +00:00
|
|
|
MVT::ValueType SourceVT = Source.getValueType();
|
2008-03-11 01:59:03 +00:00
|
|
|
bool ExpandSource = getTypeAction(SourceVT) == Expand;
|
2006-01-28 08:25:58 +00:00
|
|
|
|
2008-04-01 02:18:22 +00:00
|
|
|
// Special case for i32 source to take advantage of UINTTOFP_I32_F32, etc.
|
|
|
|
if (!isSigned && SourceVT != MVT::i32) {
|
2008-03-05 02:07:31 +00:00
|
|
|
// The integer value loaded will be incorrectly if the 'sign bit' of the
|
2006-01-28 08:25:58 +00:00
|
|
|
// incoming integer is set. To handle this, we dynamically test to see if
|
|
|
|
// it is set, and, if so, add a fudge factor.
|
2008-03-11 01:59:03 +00:00
|
|
|
SDOperand Hi;
|
|
|
|
if (ExpandSource) {
|
|
|
|
SDOperand Lo;
|
|
|
|
ExpandOp(Source, Lo, Hi);
|
|
|
|
Source = DAG.getNode(ISD::BUILD_PAIR, SourceVT, Lo, Hi);
|
|
|
|
} else {
|
|
|
|
// The comparison for the sign bit will use the entire operand.
|
|
|
|
Hi = Source;
|
|
|
|
}
|
2006-01-28 08:25:58 +00:00
|
|
|
|
|
|
|
// If this is unsigned, and not supported, first perform the conversion to
|
|
|
|
// signed, then adjust the result if the sign bit is set.
|
2008-03-11 01:59:03 +00:00
|
|
|
SDOperand SignedConv = ExpandIntToFP(true, DestTy, Source);
|
2006-01-28 08:25:58 +00:00
|
|
|
|
2008-03-10 15:42:14 +00:00
|
|
|
SDOperand SignSet = DAG.getSetCC(TLI.getSetCCResultType(Hi), Hi,
|
2006-01-28 08:25:58 +00:00
|
|
|
DAG.getConstant(0, Hi.getValueType()),
|
|
|
|
ISD::SETLT);
|
2008-01-17 07:00:52 +00:00
|
|
|
SDOperand Zero = DAG.getIntPtrConstant(0), Four = DAG.getIntPtrConstant(4);
|
2006-01-28 08:25:58 +00:00
|
|
|
SDOperand CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(),
|
|
|
|
SignSet, Four, Zero);
|
|
|
|
uint64_t FF = 0x5f800000ULL;
|
|
|
|
if (TLI.isLittleEndian()) FF <<= 32;
|
2008-03-05 02:07:31 +00:00
|
|
|
static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF);
|
2006-01-28 08:25:58 +00:00
|
|
|
|
|
|
|
SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy());
|
|
|
|
CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset);
|
|
|
|
SDOperand FudgeInReg;
|
|
|
|
if (DestTy == MVT::f32)
|
2008-02-06 22:27:42 +00:00
|
|
|
FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx,
|
2008-02-07 18:41:25 +00:00
|
|
|
PseudoSourceValue::getConstantPool(), 0);
|
2007-09-16 16:51:49 +00:00
|
|
|
else if (MVT::getSizeInBits(DestTy) > MVT::getSizeInBits(MVT::f32))
|
2007-04-27 07:33:31 +00:00
|
|
|
// FIXME: Avoid the extend by construction the right constantpool?
|
2007-09-16 16:51:49 +00:00
|
|
|
FudgeInReg = DAG.getExtLoad(ISD::EXTLOAD, DestTy, DAG.getEntryNode(),
|
2008-02-06 22:27:42 +00:00
|
|
|
CPIdx,
|
2008-02-07 18:41:25 +00:00
|
|
|
PseudoSourceValue::getConstantPool(), 0,
|
2008-02-06 22:27:42 +00:00
|
|
|
MVT::f32);
|
2007-09-14 22:26:36 +00:00
|
|
|
else
|
|
|
|
assert(0 && "Unexpected conversion");
|
|
|
|
|
2007-04-27 07:33:31 +00:00
|
|
|
MVT::ValueType SCVT = SignedConv.getValueType();
|
|
|
|
if (SCVT != DestTy) {
|
|
|
|
// Destination type needs to be expanded as well. The FADD now we are
|
|
|
|
// constructing will be expanded into a libcall.
|
|
|
|
if (MVT::getSizeInBits(SCVT) != MVT::getSizeInBits(DestTy)) {
|
2008-03-05 01:08:17 +00:00
|
|
|
assert(MVT::getSizeInBits(SCVT) * 2 == MVT::getSizeInBits(DestTy));
|
|
|
|
SignedConv = DAG.getNode(ISD::BUILD_PAIR, DestTy,
|
2007-04-27 07:33:31 +00:00
|
|
|
SignedConv, SignedConv.getValue(1));
|
|
|
|
}
|
|
|
|
SignedConv = DAG.getNode(ISD::BIT_CONVERT, DestTy, SignedConv);
|
|
|
|
}
|
2006-01-28 08:25:58 +00:00
|
|
|
return DAG.getNode(ISD::FADD, DestTy, SignedConv, FudgeInReg);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if the target has a custom way to lower this. If so, use it.
|
2008-03-05 01:08:17 +00:00
|
|
|
switch (TLI.getOperationAction(ISD::SINT_TO_FP, SourceVT)) {
|
2006-01-28 08:25:58 +00:00
|
|
|
default: assert(0 && "This action not implemented for this operation!");
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
case TargetLowering::Expand:
|
|
|
|
break; // This case is handled below.
|
|
|
|
case TargetLowering::Custom: {
|
|
|
|
SDOperand NV = TLI.LowerOperation(DAG.getNode(ISD::SINT_TO_FP, DestTy,
|
|
|
|
Source), DAG);
|
|
|
|
if (NV.Val)
|
|
|
|
return LegalizeOp(NV);
|
|
|
|
break; // The target decided this was legal after all
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Expand the source, then glue it back together for the call. We must expand
|
|
|
|
// the source in case it is shared (this pass of legalize must traverse it).
|
2008-03-11 01:59:03 +00:00
|
|
|
if (ExpandSource) {
|
|
|
|
SDOperand SrcLo, SrcHi;
|
|
|
|
ExpandOp(Source, SrcLo, SrcHi);
|
|
|
|
Source = DAG.getNode(ISD::BUILD_PAIR, SourceVT, SrcLo, SrcHi);
|
|
|
|
}
|
2006-01-28 08:25:58 +00:00
|
|
|
|
2007-01-12 02:11:51 +00:00
|
|
|
RTLIB::Libcall LC;
|
2008-04-01 01:50:16 +00:00
|
|
|
if (SourceVT == MVT::i32) {
|
|
|
|
if (DestTy == MVT::f32)
|
2008-04-01 02:00:09 +00:00
|
|
|
LC = isSigned ? RTLIB::SINTTOFP_I32_F32 : RTLIB::UINTTOFP_I32_F32;
|
2008-04-01 01:50:16 +00:00
|
|
|
else {
|
|
|
|
assert(DestTy == MVT::f64 && "Unknown fp value type!");
|
|
|
|
LC = isSigned ? RTLIB::SINTTOFP_I32_F64 : RTLIB::UINTTOFP_I32_F64;
|
|
|
|
}
|
|
|
|
} else if (SourceVT == MVT::i64) {
|
2008-03-05 01:08:17 +00:00
|
|
|
if (DestTy == MVT::f32)
|
|
|
|
LC = RTLIB::SINTTOFP_I64_F32;
|
2008-03-11 01:59:03 +00:00
|
|
|
else if (DestTy == MVT::f64)
|
2008-03-05 01:08:17 +00:00
|
|
|
LC = RTLIB::SINTTOFP_I64_F64;
|
2008-03-11 01:59:03 +00:00
|
|
|
else if (DestTy == MVT::f80)
|
|
|
|
LC = RTLIB::SINTTOFP_I64_F80;
|
|
|
|
else {
|
|
|
|
assert(DestTy == MVT::ppcf128 && "Unknown fp value type!");
|
|
|
|
LC = RTLIB::SINTTOFP_I64_PPCF128;
|
2008-03-05 01:08:17 +00:00
|
|
|
}
|
|
|
|
} else if (SourceVT == MVT::i128) {
|
|
|
|
if (DestTy == MVT::f32)
|
|
|
|
LC = RTLIB::SINTTOFP_I128_F32;
|
|
|
|
else if (DestTy == MVT::f64)
|
|
|
|
LC = RTLIB::SINTTOFP_I128_F64;
|
|
|
|
else if (DestTy == MVT::f80)
|
|
|
|
LC = RTLIB::SINTTOFP_I128_F80;
|
|
|
|
else {
|
|
|
|
assert(DestTy == MVT::ppcf128 && "Unknown fp value type!");
|
|
|
|
LC = RTLIB::SINTTOFP_I128_PPCF128;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
assert(0 && "Unknown int value type");
|
2006-01-28 08:25:58 +00:00
|
|
|
}
|
2006-02-13 09:18:02 +00:00
|
|
|
|
2007-04-27 07:33:31 +00:00
|
|
|
assert(TLI.getLibcallName(LC) && "Don't know how to expand this SINT_TO_FP!");
|
2006-02-13 09:18:02 +00:00
|
|
|
Source = DAG.getNode(ISD::SINT_TO_FP, DestTy, Source);
|
2008-03-10 23:03:31 +00:00
|
|
|
SDOperand HiPart;
|
2008-04-12 17:14:18 +00:00
|
|
|
SDOperand Result = ExpandLibCall(LC, Source.Val, isSigned, HiPart);
|
2008-04-01 01:50:16 +00:00
|
|
|
if (Result.getValueType() != DestTy && HiPart.Val)
|
2008-03-10 23:03:31 +00:00
|
|
|
Result = DAG.getNode(ISD::BUILD_PAIR, DestTy, Result, HiPart);
|
|
|
|
return Result;
|
2006-01-28 08:25:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ExpandLegalINT_TO_FP - This function is responsible for legalizing a
|
|
|
|
/// INT_TO_FP operation of the specified operand when the target requests that
|
|
|
|
/// we expand it. At this point, we know that the result and operand types are
|
|
|
|
/// legal for the target.
|
|
|
|
SDOperand SelectionDAGLegalize::ExpandLegalINT_TO_FP(bool isSigned,
|
|
|
|
SDOperand Op0,
|
|
|
|
MVT::ValueType DestVT) {
|
|
|
|
if (Op0.getValueType() == MVT::i32) {
|
|
|
|
// simple 32-bit [signed|unsigned] integer to float/double expansion
|
|
|
|
|
2008-01-16 07:03:22 +00:00
|
|
|
// Get the stack frame index of a 8 byte buffer.
|
|
|
|
SDOperand StackSlot = DAG.CreateStackTemporary(MVT::f64);
|
|
|
|
|
2006-01-28 08:25:58 +00:00
|
|
|
// word offset constant for Hi/Lo address computation
|
|
|
|
SDOperand WordOff = DAG.getConstant(sizeof(int), TLI.getPointerTy());
|
|
|
|
// set up Hi and Lo (into buffer) address based on endian
|
2006-03-23 05:29:04 +00:00
|
|
|
SDOperand Hi = StackSlot;
|
|
|
|
SDOperand Lo = DAG.getNode(ISD::ADD, TLI.getPointerTy(), StackSlot,WordOff);
|
|
|
|
if (TLI.isLittleEndian())
|
|
|
|
std::swap(Hi, Lo);
|
|
|
|
|
2006-01-28 08:25:58 +00:00
|
|
|
// if signed map to unsigned space
|
|
|
|
SDOperand Op0Mapped;
|
|
|
|
if (isSigned) {
|
|
|
|
// constant used to invert sign bit (signed to unsigned mapping)
|
|
|
|
SDOperand SignBit = DAG.getConstant(0x80000000u, MVT::i32);
|
|
|
|
Op0Mapped = DAG.getNode(ISD::XOR, MVT::i32, Op0, SignBit);
|
|
|
|
} else {
|
|
|
|
Op0Mapped = Op0;
|
|
|
|
}
|
|
|
|
// store the lo of the constructed double - based on integer input
|
2006-10-05 23:01:46 +00:00
|
|
|
SDOperand Store1 = DAG.getStore(DAG.getEntryNode(),
|
2006-10-13 21:14:26 +00:00
|
|
|
Op0Mapped, Lo, NULL, 0);
|
2006-01-28 08:25:58 +00:00
|
|
|
// initial hi portion of constructed double
|
|
|
|
SDOperand InitialHi = DAG.getConstant(0x43300000u, MVT::i32);
|
|
|
|
// store the hi of the constructed double - biased exponent
|
2006-10-13 21:14:26 +00:00
|
|
|
SDOperand Store2=DAG.getStore(Store1, InitialHi, Hi, NULL, 0);
|
2006-01-28 08:25:58 +00:00
|
|
|
// load the constructed double
|
2006-10-09 20:57:25 +00:00
|
|
|
SDOperand Load = DAG.getLoad(MVT::f64, Store2, StackSlot, NULL, 0);
|
2006-01-28 08:25:58 +00:00
|
|
|
// FP constant to bias correct the final result
|
|
|
|
SDOperand Bias = DAG.getConstantFP(isSigned ?
|
|
|
|
BitsToDouble(0x4330000080000000ULL)
|
|
|
|
: BitsToDouble(0x4330000000000000ULL),
|
|
|
|
MVT::f64);
|
|
|
|
// subtract the bias
|
|
|
|
SDOperand Sub = DAG.getNode(ISD::FSUB, MVT::f64, Load, Bias);
|
|
|
|
// final result
|
|
|
|
SDOperand Result;
|
|
|
|
// handle final rounding
|
|
|
|
if (DestVT == MVT::f64) {
|
|
|
|
// do nothing
|
|
|
|
Result = Sub;
|
2007-09-16 16:51:49 +00:00
|
|
|
} else if (MVT::getSizeInBits(DestVT) < MVT::getSizeInBits(MVT::f64)) {
|
2008-01-17 07:00:52 +00:00
|
|
|
Result = DAG.getNode(ISD::FP_ROUND, DestVT, Sub,
|
|
|
|
DAG.getIntPtrConstant(0));
|
2007-09-16 16:51:49 +00:00
|
|
|
} else if (MVT::getSizeInBits(DestVT) > MVT::getSizeInBits(MVT::f64)) {
|
|
|
|
Result = DAG.getNode(ISD::FP_EXTEND, DestVT, Sub);
|
2006-01-28 08:25:58 +00:00
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
assert(!isSigned && "Legalize cannot Expand SINT_TO_FP for i64 yet");
|
|
|
|
SDOperand Tmp1 = DAG.getNode(ISD::SINT_TO_FP, DestVT, Op0);
|
|
|
|
|
2008-03-10 15:42:14 +00:00
|
|
|
SDOperand SignSet = DAG.getSetCC(TLI.getSetCCResultType(Op0), Op0,
|
2006-01-28 08:25:58 +00:00
|
|
|
DAG.getConstant(0, Op0.getValueType()),
|
|
|
|
ISD::SETLT);
|
2008-01-17 07:00:52 +00:00
|
|
|
SDOperand Zero = DAG.getIntPtrConstant(0), Four = DAG.getIntPtrConstant(4);
|
2006-01-28 08:25:58 +00:00
|
|
|
SDOperand CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(),
|
|
|
|
SignSet, Four, Zero);
|
|
|
|
|
|
|
|
// If the sign bit of the integer is set, the large number will be treated
|
|
|
|
// as a negative number. To counteract this, the dynamic code adds an
|
|
|
|
// offset depending on the data type.
|
|
|
|
uint64_t FF;
|
|
|
|
switch (Op0.getValueType()) {
|
|
|
|
default: assert(0 && "Unsupported integer type!");
|
|
|
|
case MVT::i8 : FF = 0x43800000ULL; break; // 2^8 (as a float)
|
|
|
|
case MVT::i16: FF = 0x47800000ULL; break; // 2^16 (as a float)
|
|
|
|
case MVT::i32: FF = 0x4F800000ULL; break; // 2^32 (as a float)
|
|
|
|
case MVT::i64: FF = 0x5F800000ULL; break; // 2^64 (as a float)
|
|
|
|
}
|
|
|
|
if (TLI.isLittleEndian()) FF <<= 32;
|
2006-12-31 05:55:36 +00:00
|
|
|
static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF);
|
2006-01-28 08:25:58 +00:00
|
|
|
|
|
|
|
SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy());
|
|
|
|
CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset);
|
|
|
|
SDOperand FudgeInReg;
|
|
|
|
if (DestVT == MVT::f32)
|
2008-02-06 22:27:42 +00:00
|
|
|
FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx,
|
2008-02-07 18:41:25 +00:00
|
|
|
PseudoSourceValue::getConstantPool(), 0);
|
2006-01-28 08:25:58 +00:00
|
|
|
else {
|
2008-02-06 22:27:42 +00:00
|
|
|
FudgeInReg =
|
|
|
|
LegalizeOp(DAG.getExtLoad(ISD::EXTLOAD, DestVT,
|
|
|
|
DAG.getEntryNode(), CPIdx,
|
2008-02-07 18:41:25 +00:00
|
|
|
PseudoSourceValue::getConstantPool(), 0,
|
2008-02-06 22:27:42 +00:00
|
|
|
MVT::f32));
|
2006-01-28 08:25:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return DAG.getNode(ISD::FADD, DestVT, Tmp1, FudgeInReg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// PromoteLegalINT_TO_FP - This function is responsible for legalizing a
|
|
|
|
/// *INT_TO_FP operation of the specified operand when the target requests that
|
|
|
|
/// we promote it. At this point, we know that the result and operand types are
|
|
|
|
/// legal for the target, and that there is a legal UINT_TO_FP or SINT_TO_FP
|
|
|
|
/// operation that takes a larger input.
|
|
|
|
SDOperand SelectionDAGLegalize::PromoteLegalINT_TO_FP(SDOperand LegalOp,
|
|
|
|
MVT::ValueType DestVT,
|
|
|
|
bool isSigned) {
|
|
|
|
// First step, figure out the appropriate *INT_TO_FP operation to use.
|
|
|
|
MVT::ValueType NewInTy = LegalOp.getValueType();
|
|
|
|
|
|
|
|
unsigned OpToUse = 0;
|
|
|
|
|
|
|
|
// Scan for the appropriate larger type to use.
|
|
|
|
while (1) {
|
|
|
|
NewInTy = (MVT::ValueType)(NewInTy+1);
|
|
|
|
assert(MVT::isInteger(NewInTy) && "Ran out of possibilities!");
|
|
|
|
|
|
|
|
// If the target supports SINT_TO_FP of this type, use it.
|
|
|
|
switch (TLI.getOperationAction(ISD::SINT_TO_FP, NewInTy)) {
|
|
|
|
default: break;
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
if (!TLI.isTypeLegal(NewInTy))
|
|
|
|
break; // Can't use this datatype.
|
|
|
|
// FALL THROUGH.
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
OpToUse = ISD::SINT_TO_FP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (OpToUse) break;
|
|
|
|
if (isSigned) continue;
|
|
|
|
|
|
|
|
// If the target supports UINT_TO_FP of this type, use it.
|
|
|
|
switch (TLI.getOperationAction(ISD::UINT_TO_FP, NewInTy)) {
|
|
|
|
default: break;
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
if (!TLI.isTypeLegal(NewInTy))
|
|
|
|
break; // Can't use this datatype.
|
|
|
|
// FALL THROUGH.
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
OpToUse = ISD::UINT_TO_FP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (OpToUse) break;
|
|
|
|
|
|
|
|
// Otherwise, try a larger type.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Okay, we found the operation and type to use. Zero extend our input to the
|
|
|
|
// desired type then run the operation on it.
|
|
|
|
return DAG.getNode(OpToUse, DestVT,
|
|
|
|
DAG.getNode(isSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND,
|
|
|
|
NewInTy, LegalOp));
|
2005-01-21 06:05:23 +00:00
|
|
|
}
|
|
|
|
|
2006-01-28 08:25:58 +00:00
|
|
|
/// PromoteLegalFP_TO_INT - This function is responsible for legalizing a
|
|
|
|
/// FP_TO_*INT operation of the specified operand when the target requests that
|
|
|
|
/// we promote it. At this point, we know that the result and operand types are
|
|
|
|
/// legal for the target, and that there is a legal FP_TO_UINT or FP_TO_SINT
|
|
|
|
/// operation that returns a larger result.
|
|
|
|
SDOperand SelectionDAGLegalize::PromoteLegalFP_TO_INT(SDOperand LegalOp,
|
|
|
|
MVT::ValueType DestVT,
|
|
|
|
bool isSigned) {
|
|
|
|
// First step, figure out the appropriate FP_TO*INT operation to use.
|
|
|
|
MVT::ValueType NewOutTy = DestVT;
|
2005-01-23 04:42:50 +00:00
|
|
|
|
2006-01-28 08:25:58 +00:00
|
|
|
unsigned OpToUse = 0;
|
2005-04-13 05:09:42 +00:00
|
|
|
|
2006-01-28 08:25:58 +00:00
|
|
|
// Scan for the appropriate larger type to use.
|
|
|
|
while (1) {
|
|
|
|
NewOutTy = (MVT::ValueType)(NewOutTy+1);
|
|
|
|
assert(MVT::isInteger(NewOutTy) && "Ran out of possibilities!");
|
2005-05-13 04:45:13 +00:00
|
|
|
|
2006-01-28 08:25:58 +00:00
|
|
|
// If the target supports FP_TO_SINT returning this type, use it.
|
|
|
|
switch (TLI.getOperationAction(ISD::FP_TO_SINT, NewOutTy)) {
|
|
|
|
default: break;
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
if (!TLI.isTypeLegal(NewOutTy))
|
|
|
|
break; // Can't use this datatype.
|
|
|
|
// FALL THROUGH.
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
OpToUse = ISD::FP_TO_SINT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (OpToUse) break;
|
2005-04-13 05:09:42 +00:00
|
|
|
|
2006-01-28 08:25:58 +00:00
|
|
|
// If the target supports FP_TO_UINT of this type, use it.
|
|
|
|
switch (TLI.getOperationAction(ISD::FP_TO_UINT, NewOutTy)) {
|
|
|
|
default: break;
|
|
|
|
case TargetLowering::Legal:
|
|
|
|
if (!TLI.isTypeLegal(NewOutTy))
|
|
|
|
break; // Can't use this datatype.
|
|
|
|
// FALL THROUGH.
|
|
|
|
case TargetLowering::Custom:
|
|
|
|
OpToUse = ISD::FP_TO_UINT;
|
|
|
|
break;
|
2005-04-13 05:09:42 +00:00
|
|
|
}
|
2006-01-28 08:25:58 +00:00
|
|
|
if (OpToUse) break;
|
2005-05-11 19:02:11 +00:00
|
|
|
|
2006-01-28 08:25:58 +00:00
|
|
|
// Otherwise, try a larger type.
|
2005-05-14 05:33:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-24 07:07:01 +00:00
|
|
|
|
|
|
|
// Okay, we found the operation and type to use.
|
|
|
|
SDOperand Operation = DAG.getNode(OpToUse, NewOutTy, LegalOp);
|
|
|
|
|
|
|
|
// If the operation produces an invalid type, it must be custom lowered. Use
|
|
|
|
// the target lowering hooks to expand it. Just keep the low part of the
|
|
|
|
// expanded operation, we know that we're truncating anyway.
|
|
|
|
if (getTypeAction(NewOutTy) == Expand) {
|
|
|
|
Operation = SDOperand(TLI.ExpandOperationResult(Operation.Val, DAG), 0);
|
|
|
|
assert(Operation.Val && "Didn't return anything");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Truncate the result of the extended FP_TO_*INT operation to the desired
|
|
|
|
// size.
|
|
|
|
return DAG.getNode(ISD::TRUNCATE, DestVT, Operation);
|
2006-01-28 08:25:58 +00:00
|
|
|
}
|
2005-05-12 07:00:44 +00:00
|
|
|
|
2006-01-28 08:25:58 +00:00
|
|
|
/// ExpandBSWAP - Open code the operations for BSWAP of the specified operation.
|
|
|
|
///
|
|
|
|
SDOperand SelectionDAGLegalize::ExpandBSWAP(SDOperand Op) {
|
|
|
|
MVT::ValueType VT = Op.getValueType();
|
|
|
|
MVT::ValueType SHVT = TLI.getShiftAmountTy();
|
|
|
|
SDOperand Tmp1, Tmp2, Tmp3, Tmp4, Tmp5, Tmp6, Tmp7, Tmp8;
|
|
|
|
switch (VT) {
|
|
|
|
default: assert(0 && "Unhandled Expand type in BSWAP!"); abort();
|
|
|
|
case MVT::i16:
|
|
|
|
Tmp2 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT));
|
|
|
|
Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT));
|
|
|
|
return DAG.getNode(ISD::OR, VT, Tmp1, Tmp2);
|
|
|
|
case MVT::i32:
|
|
|
|
Tmp4 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT));
|
|
|
|
Tmp3 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT));
|
|
|
|
Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT));
|
|
|
|
Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT));
|
|
|
|
Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(0xFF0000, VT));
|
|
|
|
Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(0xFF00, VT));
|
|
|
|
Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3);
|
|
|
|
Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1);
|
|
|
|
return DAG.getNode(ISD::OR, VT, Tmp4, Tmp2);
|
|
|
|
case MVT::i64:
|
|
|
|
Tmp8 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(56, SHVT));
|
|
|
|
Tmp7 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(40, SHVT));
|
|
|
|
Tmp6 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT));
|
|
|
|
Tmp5 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT));
|
|
|
|
Tmp4 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT));
|
|
|
|
Tmp3 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT));
|
|
|
|
Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(40, SHVT));
|
|
|
|
Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(56, SHVT));
|
|
|
|
Tmp7 = DAG.getNode(ISD::AND, VT, Tmp7, DAG.getConstant(255ULL<<48, VT));
|
|
|
|
Tmp6 = DAG.getNode(ISD::AND, VT, Tmp6, DAG.getConstant(255ULL<<40, VT));
|
|
|
|
Tmp5 = DAG.getNode(ISD::AND, VT, Tmp5, DAG.getConstant(255ULL<<32, VT));
|
|
|
|
Tmp4 = DAG.getNode(ISD::AND, VT, Tmp4, DAG.getConstant(255ULL<<24, VT));
|
|
|
|
Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(255ULL<<16, VT));
|
|
|
|
Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(255ULL<<8 , VT));
|
|
|
|
Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp7);
|
|
|
|
Tmp6 = DAG.getNode(ISD::OR, VT, Tmp6, Tmp5);
|
|
|
|
Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3);
|
|
|
|
Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1);
|
|
|
|
Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp6);
|
|
|
|
Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp2);
|
|
|
|
return DAG.getNode(ISD::OR, VT, Tmp8, Tmp4);
|
2005-05-11 19:02:11 +00:00
|
|
|
}
|
2005-01-21 06:05:23 +00:00
|
|
|
}
|
2005-04-21 22:36:52 +00:00
|
|
|
|
2006-01-28 08:25:58 +00:00
|
|
|
/// ExpandBitCount - Expand the specified bitcount instruction into operations.
|
|
|
|
///
|
|
|
|
SDOperand SelectionDAGLegalize::ExpandBitCount(unsigned Opc, SDOperand Op) {
|
|
|
|
switch (Opc) {
|
|
|
|
default: assert(0 && "Cannot expand this yet!");
|
|
|
|
case ISD::CTPOP: {
|
|
|
|
static const uint64_t mask[6] = {
|
|
|
|
0x5555555555555555ULL, 0x3333333333333333ULL,
|
|
|
|
0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL,
|
|
|
|
0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL
|
|
|
|
};
|
|
|
|
MVT::ValueType VT = Op.getValueType();
|
|
|
|
MVT::ValueType ShVT = TLI.getShiftAmountTy();
|
2007-05-18 17:52:13 +00:00
|
|
|
unsigned len = MVT::getSizeInBits(VT);
|
2006-01-28 08:25:58 +00:00
|
|
|
for (unsigned i = 0; (1U << i) <= (len / 2); ++i) {
|
|
|
|
//x = (x & mask[i][len/8]) + (x >> (1 << i) & mask[i][len/8])
|
|
|
|
SDOperand Tmp2 = DAG.getConstant(mask[i], VT);
|
|
|
|
SDOperand Tmp3 = DAG.getConstant(1ULL << i, ShVT);
|
|
|
|
Op = DAG.getNode(ISD::ADD, VT, DAG.getNode(ISD::AND, VT, Op, Tmp2),
|
|
|
|
DAG.getNode(ISD::AND, VT,
|
|
|
|
DAG.getNode(ISD::SRL, VT, Op, Tmp3),Tmp2));
|
|
|
|
}
|
|
|
|
return Op;
|
|
|
|
}
|
|
|
|
case ISD::CTLZ: {
|
|
|
|
// for now, we do this:
|
|
|
|
// x = x | (x >> 1);
|
|
|
|
// x = x | (x >> 2);
|
|
|
|
// ...
|
|
|
|
// x = x | (x >>16);
|
|
|
|
// x = x | (x >>32); // for 64-bit input
|
|
|
|
// return popcount(~x);
|
|
|
|
//
|
|
|
|
// but see also: http://www.hackersdelight.org/HDcode/nlz.cc
|
|
|
|
MVT::ValueType VT = Op.getValueType();
|
|
|
|
MVT::ValueType ShVT = TLI.getShiftAmountTy();
|
2007-05-18 17:52:13 +00:00
|
|
|
unsigned len = MVT::getSizeInBits(VT);
|
2006-01-28 08:25:58 +00:00
|
|
|
for (unsigned i = 0; (1U << i) <= (len / 2); ++i) {
|
|
|
|
SDOperand Tmp3 = DAG.getConstant(1ULL << i, ShVT);
|
|
|
|
Op = DAG.getNode(ISD::OR, VT, Op, DAG.getNode(ISD::SRL, VT, Op, Tmp3));
|
|
|
|
}
|
|
|
|
Op = DAG.getNode(ISD::XOR, VT, Op, DAG.getConstant(~0ULL, VT));
|
|
|
|
return DAG.getNode(ISD::CTPOP, VT, Op);
|
|
|
|
}
|
|
|
|
case ISD::CTTZ: {
|
|
|
|
// for now, we use: { return popcount(~x & (x - 1)); }
|
|
|
|
// unless the target has ctlz but not ctpop, in which case we use:
|
|
|
|
// { return 32 - nlz(~x & (x-1)); }
|
|
|
|
// see also http://www.hackersdelight.org/HDcode/ntz.cc
|
|
|
|
MVT::ValueType VT = Op.getValueType();
|
|
|
|
SDOperand Tmp2 = DAG.getConstant(~0ULL, VT);
|
|
|
|
SDOperand Tmp3 = DAG.getNode(ISD::AND, VT,
|
|
|
|
DAG.getNode(ISD::XOR, VT, Op, Tmp2),
|
|
|
|
DAG.getNode(ISD::SUB, VT, Op, DAG.getConstant(1, VT)));
|
|
|
|
// If ISD::CTLZ is legal and CTPOP isn't, then do that instead.
|
|
|
|
if (!TLI.isOperationLegal(ISD::CTPOP, VT) &&
|
|
|
|
TLI.isOperationLegal(ISD::CTLZ, VT))
|
|
|
|
return DAG.getNode(ISD::SUB, VT,
|
2007-05-18 17:52:13 +00:00
|
|
|
DAG.getConstant(MVT::getSizeInBits(VT), VT),
|
2006-01-28 08:25:58 +00:00
|
|
|
DAG.getNode(ISD::CTLZ, VT, Tmp3));
|
|
|
|
return DAG.getNode(ISD::CTPOP, VT, Tmp3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-01-19 04:19:40 +00:00
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
/// ExpandOp - Expand the specified SDOperand into its two component pieces
|
|
|
|
/// Lo&Hi. Note that the Op MUST be an expanded type. As a result of this, the
|
|
|
|
/// LegalizeNodes map is filled in for any results that are not expanded, the
|
|
|
|
/// ExpandedNodes map is filled in for any results that are expanded, and the
|
|
|
|
/// Lo/Hi values are returned.
|
|
|
|
void SelectionDAGLegalize::ExpandOp(SDOperand Op, SDOperand &Lo, SDOperand &Hi){
|
|
|
|
MVT::ValueType VT = Op.getValueType();
|
2005-01-16 01:11:45 +00:00
|
|
|
MVT::ValueType NVT = TLI.getTypeToTransformTo(VT);
|
2005-01-07 07:47:09 +00:00
|
|
|
SDNode *Node = Op.Val;
|
|
|
|
assert(getTypeAction(VT) == Expand && "Not an expanded type!");
|
2006-12-09 02:42:38 +00:00
|
|
|
assert(((MVT::isInteger(NVT) && NVT < VT) || MVT::isFloatingPoint(VT) ||
|
2007-06-25 16:23:39 +00:00
|
|
|
MVT::isVector(VT)) &&
|
2005-01-07 07:47:09 +00:00
|
|
|
"Cannot expand to FP value or to larger int value!");
|
|
|
|
|
2005-09-02 20:32:45 +00:00
|
|
|
// See if we already expanded it.
|
2008-04-16 16:15:27 +00:00
|
|
|
DenseMap<SDOperand, std::pair<SDOperand, SDOperand> >::iterator I
|
2005-09-02 20:32:45 +00:00
|
|
|
= ExpandedNodes.find(Op);
|
|
|
|
if (I != ExpandedNodes.end()) {
|
|
|
|
Lo = I->second.first;
|
|
|
|
Hi = I->second.second;
|
|
|
|
return;
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (Node->getOpcode()) {
|
2006-01-21 04:27:00 +00:00
|
|
|
case ISD::CopyFromReg:
|
|
|
|
assert(0 && "CopyFromReg must be legal!");
|
2007-10-10 01:01:31 +00:00
|
|
|
case ISD::FP_ROUND_INREG:
|
|
|
|
if (VT == MVT::ppcf128 &&
|
|
|
|
TLI.getOperationAction(ISD::FP_ROUND_INREG, VT) ==
|
|
|
|
TargetLowering::Custom) {
|
2007-10-11 23:32:15 +00:00
|
|
|
SDOperand SrcLo, SrcHi, Src;
|
|
|
|
ExpandOp(Op.getOperand(0), SrcLo, SrcHi);
|
|
|
|
Src = DAG.getNode(ISD::BUILD_PAIR, VT, SrcLo, SrcHi);
|
|
|
|
SDOperand Result = TLI.LowerOperation(
|
|
|
|
DAG.getNode(ISD::FP_ROUND_INREG, VT, Src, Op.getOperand(1)), DAG);
|
2007-10-10 01:01:31 +00:00
|
|
|
assert(Result.Val->getOpcode() == ISD::BUILD_PAIR);
|
|
|
|
Lo = Result.Val->getOperand(0);
|
|
|
|
Hi = Result.Val->getOperand(1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// fall through
|
2006-01-21 04:27:00 +00:00
|
|
|
default:
|
2006-07-11 17:58:07 +00:00
|
|
|
#ifndef NDEBUG
|
2007-06-04 16:17:33 +00:00
|
|
|
cerr << "NODE: "; Node->dump(&DAG); cerr << "\n";
|
2006-07-11 17:58:07 +00:00
|
|
|
#endif
|
2005-01-07 07:47:09 +00:00
|
|
|
assert(0 && "Do not know how to expand this operator!");
|
|
|
|
abort();
|
2008-02-27 01:52:30 +00:00
|
|
|
case ISD::EXTRACT_ELEMENT:
|
|
|
|
ExpandOp(Node->getOperand(0), Lo, Hi);
|
|
|
|
if (cast<ConstantSDNode>(Node->getOperand(1))->getValue())
|
|
|
|
return ExpandOp(Hi, Lo, Hi);
|
2008-02-27 19:44:57 +00:00
|
|
|
return ExpandOp(Lo, Lo, Hi);
|
2007-10-31 00:32:36 +00:00
|
|
|
case ISD::EXTRACT_VECTOR_ELT:
|
|
|
|
assert(VT==MVT::i64 && "Do not know how to expand this operator!");
|
|
|
|
// ExpandEXTRACT_VECTOR_ELT tolerates invalid result types.
|
|
|
|
Lo = ExpandEXTRACT_VECTOR_ELT(Op);
|
|
|
|
return ExpandOp(Lo, Lo, Hi);
|
2005-04-01 22:34:39 +00:00
|
|
|
case ISD::UNDEF:
|
2006-12-16 02:20:50 +00:00
|
|
|
NVT = TLI.getTypeToExpandTo(VT);
|
2005-04-01 22:34:39 +00:00
|
|
|
Lo = DAG.getNode(ISD::UNDEF, NVT);
|
|
|
|
Hi = DAG.getNode(ISD::UNDEF, NVT);
|
|
|
|
break;
|
2005-01-07 07:47:09 +00:00
|
|
|
case ISD::Constant: {
|
2008-03-03 22:20:46 +00:00
|
|
|
unsigned NVTBits = MVT::getSizeInBits(NVT);
|
|
|
|
const APInt &Cst = cast<ConstantSDNode>(Node)->getAPIntValue();
|
|
|
|
Lo = DAG.getConstant(APInt(Cst).trunc(NVTBits), NVT);
|
|
|
|
Hi = DAG.getConstant(Cst.lshr(NVTBits).trunc(NVTBits), NVT);
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-12-12 21:32:44 +00:00
|
|
|
case ISD::ConstantFP: {
|
|
|
|
ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node);
|
2007-10-11 18:07:22 +00:00
|
|
|
if (CFP->getValueType(0) == MVT::ppcf128) {
|
|
|
|
APInt api = CFP->getValueAPF().convertToAPInt();
|
|
|
|
Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[1])),
|
|
|
|
MVT::f64);
|
|
|
|
Hi = DAG.getConstantFP(APFloat(APInt(64, 1, &api.getRawData()[0])),
|
|
|
|
MVT::f64);
|
|
|
|
break;
|
|
|
|
}
|
2006-12-12 22:19:28 +00:00
|
|
|
Lo = ExpandConstantFP(CFP, false, DAG, TLI);
|
2006-12-13 20:57:08 +00:00
|
|
|
if (getTypeAction(Lo.getValueType()) == Expand)
|
|
|
|
ExpandOp(Lo, Lo, Hi);
|
2006-12-12 21:32:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-03-28 22:03:13 +00:00
|
|
|
case ISD::BUILD_PAIR:
|
2006-01-28 05:07:51 +00:00
|
|
|
// Return the operands.
|
|
|
|
Lo = Node->getOperand(0);
|
|
|
|
Hi = Node->getOperand(1);
|
2005-03-28 22:03:13 +00:00
|
|
|
break;
|
2007-11-24 07:07:01 +00:00
|
|
|
|
|
|
|
case ISD::MERGE_VALUES:
|
2007-11-24 19:12:15 +00:00
|
|
|
if (Node->getNumValues() == 1) {
|
|
|
|
ExpandOp(Op.getOperand(0), Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
2007-11-24 07:07:01 +00:00
|
|
|
// FIXME: For now only expand i64,chain = MERGE_VALUES (x, y)
|
|
|
|
assert(Op.ResNo == 0 && Node->getNumValues() == 2 &&
|
|
|
|
Op.getValue(1).getValueType() == MVT::Other &&
|
|
|
|
"unhandled MERGE_VALUES");
|
|
|
|
ExpandOp(Op.getOperand(0), Lo, Hi);
|
|
|
|
// Remember that we legalized the chain.
|
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(Op.getOperand(1)));
|
|
|
|
break;
|
2005-12-12 22:27:43 +00:00
|
|
|
|
|
|
|
case ISD::SIGN_EXTEND_INREG:
|
|
|
|
ExpandOp(Node->getOperand(0), Lo, Hi);
|
2006-10-06 17:34:12 +00:00
|
|
|
// sext_inreg the low part if needed.
|
|
|
|
Lo = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Lo, Node->getOperand(1));
|
|
|
|
|
|
|
|
// The high part gets the sign extension from the lo-part. This handles
|
|
|
|
// things like sextinreg V:i64 from i8.
|
2005-12-12 22:27:43 +00:00
|
|
|
Hi = DAG.getNode(ISD::SRA, NVT, Lo,
|
|
|
|
DAG.getConstant(MVT::getSizeInBits(NVT)-1,
|
|
|
|
TLI.getShiftAmountTy()));
|
|
|
|
break;
|
2005-03-28 22:03:13 +00:00
|
|
|
|
2006-01-14 03:14:10 +00:00
|
|
|
case ISD::BSWAP: {
|
|
|
|
ExpandOp(Node->getOperand(0), Lo, Hi);
|
|
|
|
SDOperand TempLo = DAG.getNode(ISD::BSWAP, NVT, Hi);
|
|
|
|
Hi = DAG.getNode(ISD::BSWAP, NVT, Lo);
|
|
|
|
Lo = TempLo;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-05-11 04:51:16 +00:00
|
|
|
case ISD::CTPOP:
|
|
|
|
ExpandOp(Node->getOperand(0), Lo, Hi);
|
2005-05-11 05:09:47 +00:00
|
|
|
Lo = DAG.getNode(ISD::ADD, NVT, // ctpop(HL) -> ctpop(H)+ctpop(L)
|
|
|
|
DAG.getNode(ISD::CTPOP, NVT, Lo),
|
|
|
|
DAG.getNode(ISD::CTPOP, NVT, Hi));
|
2005-05-11 04:51:16 +00:00
|
|
|
Hi = DAG.getConstant(0, NVT);
|
|
|
|
break;
|
|
|
|
|
2005-05-12 19:05:01 +00:00
|
|
|
case ISD::CTLZ: {
|
|
|
|
// ctlz (HL) -> ctlz(H) != 32 ? ctlz(H) : (ctlz(L)+32)
|
2005-05-12 19:27:51 +00:00
|
|
|
ExpandOp(Node->getOperand(0), Lo, Hi);
|
2005-05-12 19:05:01 +00:00
|
|
|
SDOperand BitsC = DAG.getConstant(MVT::getSizeInBits(NVT), NVT);
|
|
|
|
SDOperand HLZ = DAG.getNode(ISD::CTLZ, NVT, Hi);
|
2008-03-10 15:42:14 +00:00
|
|
|
SDOperand TopNotZero = DAG.getSetCC(TLI.getSetCCResultType(HLZ), HLZ, BitsC,
|
2005-08-09 20:20:18 +00:00
|
|
|
ISD::SETNE);
|
2005-05-12 19:05:01 +00:00
|
|
|
SDOperand LowPart = DAG.getNode(ISD::CTLZ, NVT, Lo);
|
|
|
|
LowPart = DAG.getNode(ISD::ADD, NVT, LowPart, BitsC);
|
|
|
|
|
|
|
|
Lo = DAG.getNode(ISD::SELECT, NVT, TopNotZero, HLZ, LowPart);
|
|
|
|
Hi = DAG.getConstant(0, NVT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISD::CTTZ: {
|
|
|
|
// cttz (HL) -> cttz(L) != 32 ? cttz(L) : (cttz(H)+32)
|
2005-05-12 19:27:51 +00:00
|
|
|
ExpandOp(Node->getOperand(0), Lo, Hi);
|
2005-05-12 19:05:01 +00:00
|
|
|
SDOperand BitsC = DAG.getConstant(MVT::getSizeInBits(NVT), NVT);
|
|
|
|
SDOperand LTZ = DAG.getNode(ISD::CTTZ, NVT, Lo);
|
2008-03-10 15:42:14 +00:00
|
|
|
SDOperand BotNotZero = DAG.getSetCC(TLI.getSetCCResultType(LTZ), LTZ, BitsC,
|
2005-08-09 20:20:18 +00:00
|
|
|
ISD::SETNE);
|
2005-05-12 19:05:01 +00:00
|
|
|
SDOperand HiPart = DAG.getNode(ISD::CTTZ, NVT, Hi);
|
|
|
|
HiPart = DAG.getNode(ISD::ADD, NVT, HiPart, BitsC);
|
|
|
|
|
|
|
|
Lo = DAG.getNode(ISD::SELECT, NVT, BotNotZero, LTZ, HiPart);
|
|
|
|
Hi = DAG.getConstant(0, NVT);
|
|
|
|
break;
|
|
|
|
}
|
2005-05-11 04:51:16 +00:00
|
|
|
|
2006-01-25 18:21:52 +00:00
|
|
|
case ISD::VAARG: {
|
2006-01-28 05:07:51 +00:00
|
|
|
SDOperand Ch = Node->getOperand(0); // Legalize the chain.
|
|
|
|
SDOperand Ptr = Node->getOperand(1); // Legalize the pointer.
|
2006-01-25 18:21:52 +00:00
|
|
|
Lo = DAG.getVAArg(NVT, Ch, Ptr, Node->getOperand(2));
|
|
|
|
Hi = DAG.getVAArg(NVT, Lo.getValue(1), Ptr, Node->getOperand(2));
|
|
|
|
|
|
|
|
// Remember that we legalized the chain.
|
2006-01-28 05:07:51 +00:00
|
|
|
Hi = LegalizeOp(Hi);
|
2006-01-25 18:21:52 +00:00
|
|
|
AddLegalizedOperand(Op.getValue(1), Hi.getValue(1));
|
2008-02-11 10:37:04 +00:00
|
|
|
if (TLI.isBigEndian())
|
2006-01-25 18:21:52 +00:00
|
|
|
std::swap(Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
case ISD::LOAD: {
|
2006-10-09 20:57:25 +00:00
|
|
|
LoadSDNode *LD = cast<LoadSDNode>(Node);
|
|
|
|
SDOperand Ch = LD->getChain(); // Legalize the chain.
|
|
|
|
SDOperand Ptr = LD->getBasePtr(); // Legalize the pointer.
|
|
|
|
ISD::LoadExtType ExtType = LD->getExtensionType();
|
2007-07-09 22:18:38 +00:00
|
|
|
int SVOffset = LD->getSrcValueOffset();
|
|
|
|
unsigned Alignment = LD->getAlignment();
|
|
|
|
bool isVolatile = LD->isVolatile();
|
2006-10-09 20:57:25 +00:00
|
|
|
|
|
|
|
if (ExtType == ISD::NON_EXTLOAD) {
|
2007-07-09 22:18:38 +00:00
|
|
|
Lo = DAG.getLoad(NVT, Ch, Ptr, LD->getSrcValue(), SVOffset,
|
|
|
|
isVolatile, Alignment);
|
2006-12-12 21:32:44 +00:00
|
|
|
if (VT == MVT::f32 || VT == MVT::f64) {
|
|
|
|
// f32->i32 or f64->i64 one to one expansion.
|
|
|
|
// Remember that we legalized the chain.
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 1), LegalizeOp(Lo.getValue(1)));
|
2006-12-13 20:57:08 +00:00
|
|
|
// Recursively expand the new load.
|
|
|
|
if (getTypeAction(NVT) == Expand)
|
|
|
|
ExpandOp(Lo, Lo, Hi);
|
2006-12-12 21:32:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-10-09 20:57:25 +00:00
|
|
|
|
|
|
|
// Increment the pointer to the other half.
|
|
|
|
unsigned IncrementSize = MVT::getSizeInBits(Lo.getValueType())/8;
|
|
|
|
Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr,
|
2008-01-17 07:00:52 +00:00
|
|
|
DAG.getIntPtrConstant(IncrementSize));
|
2007-06-25 16:23:39 +00:00
|
|
|
SVOffset += IncrementSize;
|
2007-10-28 12:59:45 +00:00
|
|
|
Alignment = MinAlign(Alignment, IncrementSize);
|
2007-07-09 22:18:38 +00:00
|
|
|
Hi = DAG.getLoad(NVT, Ch, Ptr, LD->getSrcValue(), SVOffset,
|
|
|
|
isVolatile, Alignment);
|
2006-10-09 20:57:25 +00:00
|
|
|
|
|
|
|
// Build a factor node to remember that this load is independent of the
|
|
|
|
// other one.
|
|
|
|
SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1),
|
|
|
|
Hi.getValue(1));
|
|
|
|
|
|
|
|
// Remember that we legalized the chain.
|
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF));
|
2008-02-11 10:37:04 +00:00
|
|
|
if (TLI.isBigEndian())
|
2006-10-09 20:57:25 +00:00
|
|
|
std::swap(Lo, Hi);
|
|
|
|
} else {
|
2008-01-30 00:15:11 +00:00
|
|
|
MVT::ValueType EVT = LD->getMemoryVT();
|
2006-12-13 03:19:57 +00:00
|
|
|
|
2007-10-19 20:29:00 +00:00
|
|
|
if ((VT == MVT::f64 && EVT == MVT::f32) ||
|
|
|
|
(VT == MVT::ppcf128 && (EVT==MVT::f64 || EVT==MVT::f32))) {
|
2006-12-13 03:19:57 +00:00
|
|
|
// f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND
|
|
|
|
SDOperand Load = DAG.getLoad(EVT, Ch, Ptr, LD->getSrcValue(),
|
2007-07-09 22:18:38 +00:00
|
|
|
SVOffset, isVolatile, Alignment);
|
2006-12-13 03:19:57 +00:00
|
|
|
// Remember that we legalized the chain.
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 1), LegalizeOp(Load.getValue(1)));
|
|
|
|
ExpandOp(DAG.getNode(ISD::FP_EXTEND, VT, Load), Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
2006-10-09 20:57:25 +00:00
|
|
|
|
|
|
|
if (EVT == NVT)
|
|
|
|
Lo = DAG.getLoad(NVT, Ch, Ptr, LD->getSrcValue(),
|
2007-07-09 22:18:38 +00:00
|
|
|
SVOffset, isVolatile, Alignment);
|
2006-10-09 20:57:25 +00:00
|
|
|
else
|
|
|
|
Lo = DAG.getExtLoad(ExtType, NVT, Ch, Ptr, LD->getSrcValue(),
|
2007-07-09 22:18:38 +00:00
|
|
|
SVOffset, EVT, isVolatile,
|
|
|
|
Alignment);
|
2006-10-09 20:57:25 +00:00
|
|
|
|
|
|
|
// Remember that we legalized the chain.
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 1), LegalizeOp(Lo.getValue(1)));
|
|
|
|
|
|
|
|
if (ExtType == ISD::SEXTLOAD) {
|
|
|
|
// The high part is obtained by SRA'ing all but one of the bits of the
|
|
|
|
// lo part.
|
|
|
|
unsigned LoSize = MVT::getSizeInBits(Lo.getValueType());
|
|
|
|
Hi = DAG.getNode(ISD::SRA, NVT, Lo,
|
|
|
|
DAG.getConstant(LoSize-1, TLI.getShiftAmountTy()));
|
|
|
|
} else if (ExtType == ISD::ZEXTLOAD) {
|
|
|
|
// The high part is just a zero.
|
|
|
|
Hi = DAG.getConstant(0, NVT);
|
|
|
|
} else /* if (ExtType == ISD::EXTLOAD) */ {
|
|
|
|
// The high part is undefined.
|
|
|
|
Hi = DAG.getNode(ISD::UNDEF, NVT);
|
|
|
|
}
|
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISD::AND:
|
|
|
|
case ISD::OR:
|
|
|
|
case ISD::XOR: { // Simple logical operators -> two trivial pieces.
|
|
|
|
SDOperand LL, LH, RL, RH;
|
|
|
|
ExpandOp(Node->getOperand(0), LL, LH);
|
|
|
|
ExpandOp(Node->getOperand(1), RL, RH);
|
|
|
|
Lo = DAG.getNode(Node->getOpcode(), NVT, LL, RL);
|
|
|
|
Hi = DAG.getNode(Node->getOpcode(), NVT, LH, RH);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISD::SELECT: {
|
2006-01-28 07:39:30 +00:00
|
|
|
SDOperand LL, LH, RL, RH;
|
2005-01-07 07:47:09 +00:00
|
|
|
ExpandOp(Node->getOperand(1), LL, LH);
|
|
|
|
ExpandOp(Node->getOperand(2), RL, RH);
|
2006-12-15 22:42:55 +00:00
|
|
|
if (getTypeAction(NVT) == Expand)
|
|
|
|
NVT = TLI.getTypeToExpandTo(NVT);
|
2006-01-28 07:39:30 +00:00
|
|
|
Lo = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LL, RL);
|
2006-12-15 22:42:55 +00:00
|
|
|
if (VT != MVT::f32)
|
|
|
|
Hi = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LH, RH);
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-08-10 20:51:12 +00:00
|
|
|
case ISD::SELECT_CC: {
|
|
|
|
SDOperand TL, TH, FL, FH;
|
|
|
|
ExpandOp(Node->getOperand(2), TL, TH);
|
|
|
|
ExpandOp(Node->getOperand(3), FL, FH);
|
2006-12-15 22:42:55 +00:00
|
|
|
if (getTypeAction(NVT) == Expand)
|
|
|
|
NVT = TLI.getTypeToExpandTo(NVT);
|
2005-08-10 20:51:12 +00:00
|
|
|
Lo = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0),
|
|
|
|
Node->getOperand(1), TL, FL, Node->getOperand(4));
|
2006-12-15 22:42:55 +00:00
|
|
|
if (VT != MVT::f32)
|
|
|
|
Hi = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0),
|
|
|
|
Node->getOperand(1), TH, FH, Node->getOperand(4));
|
2005-08-10 20:51:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-01-28 05:07:51 +00:00
|
|
|
case ISD::ANY_EXTEND:
|
2005-09-02 00:18:10 +00:00
|
|
|
// The low part is any extension of the input (which degenerates to a copy).
|
2006-01-28 05:07:51 +00:00
|
|
|
Lo = DAG.getNode(ISD::ANY_EXTEND, NVT, Node->getOperand(0));
|
2005-09-02 00:18:10 +00:00
|
|
|
// The high part is undefined.
|
|
|
|
Hi = DAG.getNode(ISD::UNDEF, NVT);
|
|
|
|
break;
|
2005-01-07 07:47:09 +00:00
|
|
|
case ISD::SIGN_EXTEND: {
|
|
|
|
// The low part is just a sign extension of the input (which degenerates to
|
|
|
|
// a copy).
|
2006-01-28 05:07:51 +00:00
|
|
|
Lo = DAG.getNode(ISD::SIGN_EXTEND, NVT, Node->getOperand(0));
|
2005-04-21 22:36:52 +00:00
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
// The high part is obtained by SRA'ing all but one of the bits of the lo
|
|
|
|
// part.
|
2005-01-12 18:19:52 +00:00
|
|
|
unsigned LoSize = MVT::getSizeInBits(Lo.getValueType());
|
2006-01-28 05:07:51 +00:00
|
|
|
Hi = DAG.getNode(ISD::SRA, NVT, Lo,
|
|
|
|
DAG.getConstant(LoSize-1, TLI.getShiftAmountTy()));
|
2005-01-07 07:47:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-01-28 05:07:51 +00:00
|
|
|
case ISD::ZERO_EXTEND:
|
2005-01-07 07:47:09 +00:00
|
|
|
// The low part is just a zero extension of the input (which degenerates to
|
|
|
|
// a copy).
|
2006-01-28 05:07:51 +00:00
|
|
|
Lo = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0));
|
2005-04-21 22:36:52 +00:00
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
// The high part is just a zero.
|
|
|
|
Hi = DAG.getConstant(0, NVT);
|
|
|
|
break;
|
2005-12-23 00:16:34 +00:00
|
|
|
|
2007-02-13 23:55:16 +00:00
|
|
|
case ISD::TRUNCATE: {
|
|
|
|
// The input value must be larger than this value. Expand *it*.
|
|
|
|
SDOperand NewLo;
|
|
|
|
ExpandOp(Node->getOperand(0), NewLo, Hi);
|
|
|
|
|
|
|
|
// The low part is now either the right size, or it is closer. If not the
|
|
|
|
// right size, make an illegal truncate so we recursively expand it.
|
|
|
|
if (NewLo.getValueType() != Node->getValueType(0))
|
|
|
|
NewLo = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), NewLo);
|
|
|
|
ExpandOp(NewLo, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-12-23 00:16:34 +00:00
|
|
|
case ISD::BIT_CONVERT: {
|
2006-09-09 00:20:27 +00:00
|
|
|
SDOperand Tmp;
|
|
|
|
if (TLI.getOperationAction(ISD::BIT_CONVERT, VT) == TargetLowering::Custom){
|
|
|
|
// If the target wants to, allow it to lower this itself.
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Expand: assert(0 && "cannot expand FP!");
|
|
|
|
case Legal: Tmp = LegalizeOp(Node->getOperand(0)); break;
|
|
|
|
case Promote: Tmp = PromoteOp (Node->getOperand(0)); break;
|
|
|
|
}
|
|
|
|
Tmp = TLI.LowerOperation(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp), DAG);
|
|
|
|
}
|
|
|
|
|
2006-12-09 02:42:38 +00:00
|
|
|
// f32 / f64 must be expanded to i32 / i64.
|
2006-12-11 19:27:14 +00:00
|
|
|
if (VT == MVT::f32 || VT == MVT::f64) {
|
|
|
|
Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0));
|
2006-12-15 22:42:55 +00:00
|
|
|
if (getTypeAction(NVT) == Expand)
|
|
|
|
ExpandOp(Lo, Lo, Hi);
|
2006-12-12 19:53:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If source operand will be expanded to the same type as VT, i.e.
|
|
|
|
// i64 <- f64, i32 <- f32, expand the source operand instead.
|
|
|
|
MVT::ValueType VT0 = Node->getOperand(0).getValueType();
|
|
|
|
if (getTypeAction(VT0) == Expand && TLI.getTypeToTransformTo(VT0) == VT) {
|
|
|
|
ExpandOp(Node->getOperand(0), Lo, Hi);
|
2006-12-09 02:42:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-09-09 00:20:27 +00:00
|
|
|
// Turn this into a load/store pair by default.
|
|
|
|
if (Tmp.Val == 0)
|
2008-01-16 07:45:30 +00:00
|
|
|
Tmp = EmitStackConvert(Node->getOperand(0), VT, VT);
|
2006-09-09 00:20:27 +00:00
|
|
|
|
2005-12-23 00:16:34 +00:00
|
|
|
ExpandOp(Tmp, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
2005-11-20 21:32:07 +00:00
|
|
|
|
2007-11-24 07:07:01 +00:00
|
|
|
case ISD::READCYCLECOUNTER: {
|
2005-11-20 22:56:56 +00:00
|
|
|
assert(TLI.getOperationAction(ISD::READCYCLECOUNTER, VT) ==
|
|
|
|
TargetLowering::Custom &&
|
|
|
|
"Must custom expand ReadCycleCounter");
|
2007-11-24 07:07:01 +00:00
|
|
|
SDOperand Tmp = TLI.LowerOperation(Op, DAG);
|
|
|
|
assert(Tmp.Val && "Node must be custom expanded!");
|
|
|
|
ExpandOp(Tmp.getValue(0), Lo, Hi);
|
2005-11-20 22:56:56 +00:00
|
|
|
AddLegalizedOperand(SDOperand(Node, 1), // Remember we legalized the chain.
|
2007-11-24 07:07:01 +00:00
|
|
|
LegalizeOp(Tmp.getValue(1)));
|
2005-11-20 21:32:07 +00:00
|
|
|
break;
|
2007-11-24 07:07:01 +00:00
|
|
|
}
|
2005-11-20 21:32:07 +00:00
|
|
|
|
2008-03-05 01:15:49 +00:00
|
|
|
case ISD::ATOMIC_LCS: {
|
|
|
|
SDOperand Tmp = TLI.LowerOperation(Op, DAG);
|
|
|
|
assert(Tmp.Val && "Node must be custom expanded!");
|
|
|
|
ExpandOp(Tmp.getValue(0), Lo, Hi);
|
|
|
|
AddLegalizedOperand(SDOperand(Node, 1), // Remember we legalized the chain.
|
|
|
|
LegalizeOp(Tmp.getValue(1)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-01-08 19:27:05 +00:00
|
|
|
// These operators cannot be expanded directly, emit them as calls to
|
|
|
|
// library functions.
|
2007-01-12 02:11:51 +00:00
|
|
|
case ISD::FP_TO_SINT: {
|
2005-07-29 00:33:32 +00:00
|
|
|
if (TLI.getOperationAction(ISD::FP_TO_SINT, VT) == TargetLowering::Custom) {
|
2005-07-30 01:40:57 +00:00
|
|
|
SDOperand Op;
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Expand: assert(0 && "cannot expand FP!");
|
2006-01-28 05:07:51 +00:00
|
|
|
case Legal: Op = LegalizeOp(Node->getOperand(0)); break;
|
|
|
|
case Promote: Op = PromoteOp (Node->getOperand(0)); break;
|
2005-07-30 01:40:57 +00:00
|
|
|
}
|
2005-07-30 18:33:25 +00:00
|
|
|
|
2005-07-30 01:40:57 +00:00
|
|
|
Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_SINT, VT, Op), DAG);
|
|
|
|
|
2005-07-29 00:33:32 +00:00
|
|
|
// Now that the custom expander is done, expand the result, which is still
|
|
|
|
// VT.
|
2005-08-26 00:14:16 +00:00
|
|
|
if (Op.Val) {
|
|
|
|
ExpandOp(Op, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
2005-07-29 00:33:32 +00:00
|
|
|
}
|
2005-07-30 18:33:25 +00:00
|
|
|
|
2007-10-05 20:04:43 +00:00
|
|
|
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
|
2008-03-10 23:03:31 +00:00
|
|
|
if (VT == MVT::i64) {
|
|
|
|
if (Node->getOperand(0).getValueType() == MVT::f32)
|
|
|
|
LC = RTLIB::FPTOSINT_F32_I64;
|
|
|
|
else if (Node->getOperand(0).getValueType() == MVT::f64)
|
|
|
|
LC = RTLIB::FPTOSINT_F64_I64;
|
|
|
|
else if (Node->getOperand(0).getValueType() == MVT::f80)
|
|
|
|
LC = RTLIB::FPTOSINT_F80_I64;
|
|
|
|
else if (Node->getOperand(0).getValueType() == MVT::ppcf128)
|
|
|
|
LC = RTLIB::FPTOSINT_PPCF128_I64;
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Hi);
|
2008-03-10 23:03:31 +00:00
|
|
|
} else if (VT == MVT::i128) {
|
|
|
|
if (Node->getOperand(0).getValueType() == MVT::f32)
|
|
|
|
LC = RTLIB::FPTOSINT_F32_I128;
|
|
|
|
else if (Node->getOperand(0).getValueType() == MVT::f64)
|
|
|
|
LC = RTLIB::FPTOSINT_F64_I128;
|
|
|
|
else if (Node->getOperand(0).getValueType() == MVT::f80)
|
|
|
|
LC = RTLIB::FPTOSINT_F80_I128;
|
|
|
|
else if (Node->getOperand(0).getValueType() == MVT::ppcf128)
|
|
|
|
LC = RTLIB::FPTOSINT_PPCF128_I128;
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Hi);
|
2008-03-10 23:03:31 +00:00
|
|
|
} else {
|
|
|
|
assert(0 && "Unexpected uint-to-fp conversion!");
|
|
|
|
}
|
2005-01-08 19:27:05 +00:00
|
|
|
break;
|
2007-01-12 02:11:51 +00:00
|
|
|
}
|
2005-07-30 18:33:25 +00:00
|
|
|
|
2007-01-12 02:11:51 +00:00
|
|
|
case ISD::FP_TO_UINT: {
|
2005-07-29 00:33:32 +00:00
|
|
|
if (TLI.getOperationAction(ISD::FP_TO_UINT, VT) == TargetLowering::Custom) {
|
2006-01-28 05:07:51 +00:00
|
|
|
SDOperand Op;
|
|
|
|
switch (getTypeAction(Node->getOperand(0).getValueType())) {
|
|
|
|
case Expand: assert(0 && "cannot expand FP!");
|
|
|
|
case Legal: Op = LegalizeOp(Node->getOperand(0)); break;
|
|
|
|
case Promote: Op = PromoteOp (Node->getOperand(0)); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_UINT, VT, Op), DAG);
|
|
|
|
|
|
|
|
// Now that the custom expander is done, expand the result.
|
2005-08-26 00:14:16 +00:00
|
|
|
if (Op.Val) {
|
|
|
|
ExpandOp(Op, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
2005-07-29 00:33:32 +00:00
|
|
|
}
|
2005-07-30 18:33:25 +00:00
|
|
|
|
2007-10-05 01:09:32 +00:00
|
|
|
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
|
2008-03-10 23:03:31 +00:00
|
|
|
if (VT == MVT::i64) {
|
|
|
|
if (Node->getOperand(0).getValueType() == MVT::f32)
|
|
|
|
LC = RTLIB::FPTOUINT_F32_I64;
|
|
|
|
else if (Node->getOperand(0).getValueType() == MVT::f64)
|
|
|
|
LC = RTLIB::FPTOUINT_F64_I64;
|
|
|
|
else if (Node->getOperand(0).getValueType() == MVT::f80)
|
|
|
|
LC = RTLIB::FPTOUINT_F80_I64;
|
|
|
|
else if (Node->getOperand(0).getValueType() == MVT::ppcf128)
|
|
|
|
LC = RTLIB::FPTOUINT_PPCF128_I64;
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Hi);
|
2008-03-10 23:03:31 +00:00
|
|
|
} else if (VT == MVT::i128) {
|
|
|
|
if (Node->getOperand(0).getValueType() == MVT::f32)
|
|
|
|
LC = RTLIB::FPTOUINT_F32_I128;
|
|
|
|
else if (Node->getOperand(0).getValueType() == MVT::f64)
|
|
|
|
LC = RTLIB::FPTOUINT_F64_I128;
|
|
|
|
else if (Node->getOperand(0).getValueType() == MVT::f80)
|
|
|
|
LC = RTLIB::FPTOUINT_F80_I128;
|
|
|
|
else if (Node->getOperand(0).getValueType() == MVT::ppcf128)
|
|
|
|
LC = RTLIB::FPTOUINT_PPCF128_I128;
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(LC, Node, false/*sign irrelevant*/, Hi);
|
2008-03-10 23:03:31 +00:00
|
|
|
} else {
|
|
|
|
assert(0 && "Unexpected uint-to-fp conversion!");
|
|
|
|
}
|
2005-01-08 19:27:05 +00:00
|
|
|
break;
|
2007-01-12 02:11:51 +00:00
|
|
|
}
|
2005-01-08 19:27:05 +00:00
|
|
|
|
2006-01-09 18:31:59 +00:00
|
|
|
case ISD::SHL: {
|
2005-08-31 19:01:53 +00:00
|
|
|
// If the target wants custom lowering, do so.
|
2006-01-21 04:27:00 +00:00
|
|
|
SDOperand ShiftAmt = LegalizeOp(Node->getOperand(1));
|
2005-08-31 19:01:53 +00:00
|
|
|
if (TLI.getOperationAction(ISD::SHL, VT) == TargetLowering::Custom) {
|
2006-01-28 05:07:51 +00:00
|
|
|
SDOperand Op = DAG.getNode(ISD::SHL, VT, Node->getOperand(0), ShiftAmt);
|
2005-08-31 19:01:53 +00:00
|
|
|
Op = TLI.LowerOperation(Op, DAG);
|
|
|
|
if (Op.Val) {
|
|
|
|
// Now that the custom expander is done, expand the result, which is
|
|
|
|
// still VT.
|
|
|
|
ExpandOp(Op, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Compile X << 1 (where X is a long-long) to:
addl %ecx, %ecx
adcl %eax, %eax
instead of:
movl %ecx, %edx
addl %edx, %edx
shrl $31, %ecx
addl %eax, %eax
orl %ecx, %eax
and to:
addc r5, r5, r5
adde r4, r4, r4
instead of:
slwi r2,r9,1
srwi r0,r11,31
slwi r3,r11,1
or r2,r0,r2
on PPC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30284 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-13 03:50:39 +00:00
|
|
|
// If ADDC/ADDE are supported and if the shift amount is a constant 1, emit
|
|
|
|
// this X << 1 as X+X.
|
|
|
|
if (ConstantSDNode *ShAmt = dyn_cast<ConstantSDNode>(ShiftAmt)) {
|
2008-03-13 22:13:53 +00:00
|
|
|
if (ShAmt->getAPIntValue() == 1 && TLI.isOperationLegal(ISD::ADDC, NVT) &&
|
Compile X << 1 (where X is a long-long) to:
addl %ecx, %ecx
adcl %eax, %eax
instead of:
movl %ecx, %edx
addl %edx, %edx
shrl $31, %ecx
addl %eax, %eax
orl %ecx, %eax
and to:
addc r5, r5, r5
adde r4, r4, r4
instead of:
slwi r2,r9,1
srwi r0,r11,31
slwi r3,r11,1
or r2,r0,r2
on PPC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30284 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-13 03:50:39 +00:00
|
|
|
TLI.isOperationLegal(ISD::ADDE, NVT)) {
|
|
|
|
SDOperand LoOps[2], HiOps[3];
|
|
|
|
ExpandOp(Node->getOperand(0), LoOps[0], HiOps[0]);
|
|
|
|
SDVTList VTList = DAG.getVTList(LoOps[0].getValueType(), MVT::Flag);
|
|
|
|
LoOps[1] = LoOps[0];
|
|
|
|
Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2);
|
|
|
|
|
|
|
|
HiOps[1] = HiOps[0];
|
|
|
|
HiOps[2] = Lo.getValue(1);
|
|
|
|
Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-19 04:19:40 +00:00
|
|
|
// If we can emit an efficient shift operation, do so now.
|
2006-01-21 04:27:00 +00:00
|
|
|
if (ExpandShift(ISD::SHL, Node->getOperand(0), ShiftAmt, Lo, Hi))
|
2005-01-19 04:19:40 +00:00
|
|
|
break;
|
2005-04-02 03:38:53 +00:00
|
|
|
|
|
|
|
// If this target supports SHL_PARTS, use it.
|
2006-01-09 18:31:59 +00:00
|
|
|
TargetLowering::LegalizeAction Action =
|
|
|
|
TLI.getOperationAction(ISD::SHL_PARTS, NVT);
|
|
|
|
if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) ||
|
|
|
|
Action == TargetLowering::Custom) {
|
2006-01-21 04:27:00 +00:00
|
|
|
ExpandShiftParts(ISD::SHL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi);
|
2005-04-02 03:38:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-01-19 04:19:40 +00:00
|
|
|
// Otherwise, emit a libcall.
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(RTLIB::SHL_I64, Node, false/*left shift=unsigned*/, Hi);
|
2005-01-19 04:19:40 +00:00
|
|
|
break;
|
2006-01-09 18:31:59 +00:00
|
|
|
}
|
2005-01-19 04:19:40 +00:00
|
|
|
|
2006-01-09 18:31:59 +00:00
|
|
|
case ISD::SRA: {
|
2005-08-31 19:01:53 +00:00
|
|
|
// If the target wants custom lowering, do so.
|
2006-01-21 04:27:00 +00:00
|
|
|
SDOperand ShiftAmt = LegalizeOp(Node->getOperand(1));
|
2005-08-31 19:01:53 +00:00
|
|
|
if (TLI.getOperationAction(ISD::SRA, VT) == TargetLowering::Custom) {
|
2006-01-28 05:07:51 +00:00
|
|
|
SDOperand Op = DAG.getNode(ISD::SRA, VT, Node->getOperand(0), ShiftAmt);
|
2005-08-31 19:01:53 +00:00
|
|
|
Op = TLI.LowerOperation(Op, DAG);
|
|
|
|
if (Op.Val) {
|
|
|
|
// Now that the custom expander is done, expand the result, which is
|
|
|
|
// still VT.
|
|
|
|
ExpandOp(Op, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-19 04:19:40 +00:00
|
|
|
// If we can emit an efficient shift operation, do so now.
|
2006-01-21 04:27:00 +00:00
|
|
|
if (ExpandShift(ISD::SRA, Node->getOperand(0), ShiftAmt, Lo, Hi))
|
2005-01-19 04:19:40 +00:00
|
|
|
break;
|
2005-04-02 03:38:53 +00:00
|
|
|
|
|
|
|
// If this target supports SRA_PARTS, use it.
|
2006-01-09 18:31:59 +00:00
|
|
|
TargetLowering::LegalizeAction Action =
|
|
|
|
TLI.getOperationAction(ISD::SRA_PARTS, NVT);
|
|
|
|
if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) ||
|
|
|
|
Action == TargetLowering::Custom) {
|
2006-01-21 04:27:00 +00:00
|
|
|
ExpandShiftParts(ISD::SRA_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi);
|
2005-04-02 03:38:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-01-19 04:19:40 +00:00
|
|
|
// Otherwise, emit a libcall.
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(RTLIB::SRA_I64, Node, true/*ashr is signed*/, Hi);
|
2005-01-19 04:19:40 +00:00
|
|
|
break;
|
2006-01-09 18:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case ISD::SRL: {
|
2005-08-31 19:01:53 +00:00
|
|
|
// If the target wants custom lowering, do so.
|
2006-01-21 04:27:00 +00:00
|
|
|
SDOperand ShiftAmt = LegalizeOp(Node->getOperand(1));
|
2005-08-31 19:01:53 +00:00
|
|
|
if (TLI.getOperationAction(ISD::SRL, VT) == TargetLowering::Custom) {
|
2006-01-28 05:07:51 +00:00
|
|
|
SDOperand Op = DAG.getNode(ISD::SRL, VT, Node->getOperand(0), ShiftAmt);
|
2005-08-31 19:01:53 +00:00
|
|
|
Op = TLI.LowerOperation(Op, DAG);
|
|
|
|
if (Op.Val) {
|
|
|
|
// Now that the custom expander is done, expand the result, which is
|
|
|
|
// still VT.
|
|
|
|
ExpandOp(Op, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-19 04:19:40 +00:00
|
|
|
// If we can emit an efficient shift operation, do so now.
|
2006-01-21 04:27:00 +00:00
|
|
|
if (ExpandShift(ISD::SRL, Node->getOperand(0), ShiftAmt, Lo, Hi))
|
2005-01-19 04:19:40 +00:00
|
|
|
break;
|
2005-04-02 03:38:53 +00:00
|
|
|
|
|
|
|
// If this target supports SRL_PARTS, use it.
|
2006-01-09 18:31:59 +00:00
|
|
|
TargetLowering::LegalizeAction Action =
|
|
|
|
TLI.getOperationAction(ISD::SRL_PARTS, NVT);
|
|
|
|
if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) ||
|
|
|
|
Action == TargetLowering::Custom) {
|
2006-01-21 04:27:00 +00:00
|
|
|
ExpandShiftParts(ISD::SRL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi);
|
2005-04-02 03:38:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-01-19 04:19:40 +00:00
|
|
|
// Otherwise, emit a libcall.
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(RTLIB::SRL_I64, Node, false/*lshr is unsigned*/, Hi);
|
2005-01-19 04:19:40 +00:00
|
|
|
break;
|
2006-01-09 18:31:59 +00:00
|
|
|
}
|
2005-01-19 04:19:40 +00:00
|
|
|
|
2005-04-21 22:36:52 +00:00
|
|
|
case ISD::ADD:
|
2006-01-28 05:07:51 +00:00
|
|
|
case ISD::SUB: {
|
|
|
|
// If the target wants to custom expand this, let them.
|
|
|
|
if (TLI.getOperationAction(Node->getOpcode(), VT) ==
|
|
|
|
TargetLowering::Custom) {
|
|
|
|
Op = TLI.LowerOperation(Op, DAG);
|
|
|
|
if (Op.Val) {
|
|
|
|
ExpandOp(Op, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Expand the subcomponents.
|
|
|
|
SDOperand LHSL, LHSH, RHSL, RHSH;
|
|
|
|
ExpandOp(Node->getOperand(0), LHSL, LHSH);
|
|
|
|
ExpandOp(Node->getOperand(1), RHSL, RHSH);
|
Compile X << 1 (where X is a long-long) to:
addl %ecx, %ecx
adcl %eax, %eax
instead of:
movl %ecx, %edx
addl %edx, %edx
shrl $31, %ecx
addl %eax, %eax
orl %ecx, %eax
and to:
addc r5, r5, r5
adde r4, r4, r4
instead of:
slwi r2,r9,1
srwi r0,r11,31
slwi r3,r11,1
or r2,r0,r2
on PPC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30284 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-13 03:50:39 +00:00
|
|
|
SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag);
|
|
|
|
SDOperand LoOps[2], HiOps[3];
|
2006-08-08 02:23:42 +00:00
|
|
|
LoOps[0] = LHSL;
|
|
|
|
LoOps[1] = RHSL;
|
|
|
|
HiOps[0] = LHSH;
|
|
|
|
HiOps[1] = RHSH;
|
2006-02-17 05:43:56 +00:00
|
|
|
if (Node->getOpcode() == ISD::ADD) {
|
Compile X << 1 (where X is a long-long) to:
addl %ecx, %ecx
adcl %eax, %eax
instead of:
movl %ecx, %edx
addl %edx, %edx
shrl $31, %ecx
addl %eax, %eax
orl %ecx, %eax
and to:
addc r5, r5, r5
adde r4, r4, r4
instead of:
slwi r2,r9,1
srwi r0,r11,31
slwi r3,r11,1
or r2,r0,r2
on PPC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30284 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-13 03:50:39 +00:00
|
|
|
Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2);
|
2006-08-08 02:23:42 +00:00
|
|
|
HiOps[2] = Lo.getValue(1);
|
Compile X << 1 (where X is a long-long) to:
addl %ecx, %ecx
adcl %eax, %eax
instead of:
movl %ecx, %edx
addl %edx, %edx
shrl $31, %ecx
addl %eax, %eax
orl %ecx, %eax
and to:
addc r5, r5, r5
adde r4, r4, r4
instead of:
slwi r2,r9,1
srwi r0,r11,31
slwi r3,r11,1
or r2,r0,r2
on PPC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30284 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-13 03:50:39 +00:00
|
|
|
Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3);
|
2006-02-17 05:43:56 +00:00
|
|
|
} else {
|
Compile X << 1 (where X is a long-long) to:
addl %ecx, %ecx
adcl %eax, %eax
instead of:
movl %ecx, %edx
addl %edx, %edx
shrl $31, %ecx
addl %eax, %eax
orl %ecx, %eax
and to:
addc r5, r5, r5
adde r4, r4, r4
instead of:
slwi r2,r9,1
srwi r0,r11,31
slwi r3,r11,1
or r2,r0,r2
on PPC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30284 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-13 03:50:39 +00:00
|
|
|
Lo = DAG.getNode(ISD::SUBC, VTList, LoOps, 2);
|
2006-08-08 02:23:42 +00:00
|
|
|
HiOps[2] = Lo.getValue(1);
|
Compile X << 1 (where X is a long-long) to:
addl %ecx, %ecx
adcl %eax, %eax
instead of:
movl %ecx, %edx
addl %edx, %edx
shrl $31, %ecx
addl %eax, %eax
orl %ecx, %eax
and to:
addc r5, r5, r5
adde r4, r4, r4
instead of:
slwi r2,r9,1
srwi r0,r11,31
slwi r3,r11,1
or r2,r0,r2
on PPC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30284 91177308-0d34-0410-b5e6-96231b3b80d8
2006-09-13 03:50:39 +00:00
|
|
|
Hi = DAG.getNode(ISD::SUBE, VTList, HiOps, 3);
|
2006-02-17 05:43:56 +00:00
|
|
|
}
|
2005-01-20 18:52:28 +00:00
|
|
|
break;
|
2006-01-28 05:07:51 +00:00
|
|
|
}
|
2007-05-17 18:15:41 +00:00
|
|
|
|
|
|
|
case ISD::ADDC:
|
|
|
|
case ISD::SUBC: {
|
|
|
|
// Expand the subcomponents.
|
|
|
|
SDOperand LHSL, LHSH, RHSL, RHSH;
|
|
|
|
ExpandOp(Node->getOperand(0), LHSL, LHSH);
|
|
|
|
ExpandOp(Node->getOperand(1), RHSL, RHSH);
|
|
|
|
SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag);
|
|
|
|
SDOperand LoOps[2] = { LHSL, RHSL };
|
|
|
|
SDOperand HiOps[3] = { LHSH, RHSH };
|
|
|
|
|
|
|
|
if (Node->getOpcode() == ISD::ADDC) {
|
|
|
|
Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2);
|
|
|
|
HiOps[2] = Lo.getValue(1);
|
|
|
|
Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3);
|
|
|
|
} else {
|
|
|
|
Lo = DAG.getNode(ISD::SUBC, VTList, LoOps, 2);
|
|
|
|
HiOps[2] = Lo.getValue(1);
|
|
|
|
Hi = DAG.getNode(ISD::SUBE, VTList, HiOps, 3);
|
|
|
|
}
|
|
|
|
// Remember that we legalized the flag.
|
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISD::ADDE:
|
|
|
|
case ISD::SUBE: {
|
|
|
|
// Expand the subcomponents.
|
|
|
|
SDOperand LHSL, LHSH, RHSL, RHSH;
|
|
|
|
ExpandOp(Node->getOperand(0), LHSL, LHSH);
|
|
|
|
ExpandOp(Node->getOperand(1), RHSL, RHSH);
|
|
|
|
SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag);
|
|
|
|
SDOperand LoOps[3] = { LHSL, RHSL, Node->getOperand(2) };
|
|
|
|
SDOperand HiOps[3] = { LHSH, RHSH };
|
|
|
|
|
|
|
|
Lo = DAG.getNode(Node->getOpcode(), VTList, LoOps, 3);
|
|
|
|
HiOps[2] = Lo.getValue(1);
|
|
|
|
Hi = DAG.getNode(Node->getOpcode(), VTList, HiOps, 3);
|
|
|
|
|
|
|
|
// Remember that we legalized the flag.
|
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(Hi.getValue(1)));
|
|
|
|
break;
|
|
|
|
}
|
2005-04-11 03:01:51 +00:00
|
|
|
case ISD::MUL: {
|
2006-09-16 00:09:24 +00:00
|
|
|
// If the target wants to custom expand this, let them.
|
|
|
|
if (TLI.getOperationAction(ISD::MUL, VT) == TargetLowering::Custom) {
|
2006-09-16 05:08:34 +00:00
|
|
|
SDOperand New = TLI.LowerOperation(Op, DAG);
|
|
|
|
if (New.Val) {
|
|
|
|
ExpandOp(New, Lo, Hi);
|
2006-09-16 00:09:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-01 18:17:58 +00:00
|
|
|
bool HasMULHS = TLI.isOperationLegal(ISD::MULHS, NVT);
|
|
|
|
bool HasMULHU = TLI.isOperationLegal(ISD::MULHU, NVT);
|
2007-10-08 18:33:35 +00:00
|
|
|
bool HasSMUL_LOHI = TLI.isOperationLegal(ISD::SMUL_LOHI, NVT);
|
|
|
|
bool HasUMUL_LOHI = TLI.isOperationLegal(ISD::UMUL_LOHI, NVT);
|
|
|
|
if (HasMULHU || HasMULHS || HasUMUL_LOHI || HasSMUL_LOHI) {
|
2005-04-11 03:01:51 +00:00
|
|
|
SDOperand LL, LH, RL, RH;
|
|
|
|
ExpandOp(Node->getOperand(0), LL, LH);
|
|
|
|
ExpandOp(Node->getOperand(1), RL, RH);
|
2008-02-25 21:11:39 +00:00
|
|
|
unsigned OuterBitSize = Op.getValueSizeInBits();
|
|
|
|
unsigned InnerBitSize = RH.getValueSizeInBits();
|
2007-10-08 18:33:35 +00:00
|
|
|
unsigned LHSSB = DAG.ComputeNumSignBits(Op.getOperand(0));
|
|
|
|
unsigned RHSSB = DAG.ComputeNumSignBits(Op.getOperand(1));
|
2008-03-10 20:42:19 +00:00
|
|
|
APInt HighMask = APInt::getHighBitsSet(OuterBitSize, InnerBitSize);
|
|
|
|
if (DAG.MaskedValueIsZero(Node->getOperand(0), HighMask) &&
|
|
|
|
DAG.MaskedValueIsZero(Node->getOperand(1), HighMask)) {
|
2007-10-08 18:33:35 +00:00
|
|
|
// The inputs are both zero-extended.
|
|
|
|
if (HasUMUL_LOHI) {
|
|
|
|
// We can emit a umul_lohi.
|
|
|
|
Lo = DAG.getNode(ISD::UMUL_LOHI, DAG.getVTList(NVT, NVT), LL, RL);
|
|
|
|
Hi = SDOperand(Lo.Val, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (HasMULHU) {
|
|
|
|
// We can emit a mulhu+mul.
|
|
|
|
Lo = DAG.getNode(ISD::MUL, NVT, LL, RL);
|
|
|
|
Hi = DAG.getNode(ISD::MULHU, NVT, LL, RL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-02-25 21:11:39 +00:00
|
|
|
if (LHSSB > InnerBitSize && RHSSB > InnerBitSize) {
|
2007-10-08 18:33:35 +00:00
|
|
|
// The input values are both sign-extended.
|
|
|
|
if (HasSMUL_LOHI) {
|
|
|
|
// We can emit a smul_lohi.
|
|
|
|
Lo = DAG.getNode(ISD::SMUL_LOHI, DAG.getVTList(NVT, NVT), LL, RL);
|
|
|
|
Hi = SDOperand(Lo.Val, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (HasMULHS) {
|
|
|
|
// We can emit a mulhs+mul.
|
|
|
|
Lo = DAG.getNode(ISD::MUL, NVT, LL, RL);
|
|
|
|
Hi = DAG.getNode(ISD::MULHS, NVT, LL, RL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (HasUMUL_LOHI) {
|
|
|
|
// Lo,Hi = umul LHS, RHS.
|
|
|
|
SDOperand UMulLOHI = DAG.getNode(ISD::UMUL_LOHI,
|
|
|
|
DAG.getVTList(NVT, NVT), LL, RL);
|
|
|
|
Lo = UMulLOHI;
|
|
|
|
Hi = UMulLOHI.getValue(1);
|
Add support for AssertSext and AssertZext, folding other extensions with
them. This allows for elminination of redundant extends in the entry
blocks of functions on PowerPC.
Add support for i32 x i32 -> i64 multiplies, by recognizing when the inputs
to ISD::MUL in ExpandOp are actually just extended i32 values and not real
i64 values. this allows us to codegen
int mulhs(int a, int b) { return ((long long)a * b) >> 32; }
as:
_mulhs:
mulhw r3, r4, r3
blr
instead of:
_mulhs:
mulhwu r2, r4, r3
srawi r5, r3, 31
mullw r5, r4, r5
add r2, r2, r5
srawi r4, r4, 31
mullw r3, r4, r3
add r3, r2, r3
blr
with a similar improvement on x86.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23147 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-30 02:44:00 +00:00
|
|
|
RH = DAG.getNode(ISD::MUL, NVT, LL, RH);
|
|
|
|
LH = DAG.getNode(ISD::MUL, NVT, LH, RL);
|
|
|
|
Hi = DAG.getNode(ISD::ADD, NVT, Hi, RH);
|
|
|
|
Hi = DAG.getNode(ISD::ADD, NVT, Hi, LH);
|
2006-09-16 00:21:44 +00:00
|
|
|
break;
|
Add support for AssertSext and AssertZext, folding other extensions with
them. This allows for elminination of redundant extends in the entry
blocks of functions on PowerPC.
Add support for i32 x i32 -> i64 multiplies, by recognizing when the inputs
to ISD::MUL in ExpandOp are actually just extended i32 values and not real
i64 values. this allows us to codegen
int mulhs(int a, int b) { return ((long long)a * b) >> 32; }
as:
_mulhs:
mulhw r3, r4, r3
blr
instead of:
_mulhs:
mulhwu r2, r4, r3
srawi r5, r3, 31
mullw r5, r4, r5
add r2, r2, r5
srawi r4, r4, 31
mullw r3, r4, r3
add r3, r2, r3
blr
with a similar improvement on x86.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23147 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-30 02:44:00 +00:00
|
|
|
}
|
2007-10-24 22:26:08 +00:00
|
|
|
if (HasMULHU) {
|
|
|
|
Lo = DAG.getNode(ISD::MUL, NVT, LL, RL);
|
|
|
|
Hi = DAG.getNode(ISD::MULHU, NVT, LL, RL);
|
|
|
|
RH = DAG.getNode(ISD::MUL, NVT, LL, RH);
|
|
|
|
LH = DAG.getNode(ISD::MUL, NVT, LH, RL);
|
|
|
|
Hi = DAG.getNode(ISD::ADD, NVT, Hi, RH);
|
|
|
|
Hi = DAG.getNode(ISD::ADD, NVT, Hi, LH);
|
|
|
|
break;
|
|
|
|
}
|
2005-04-11 03:01:51 +00:00
|
|
|
}
|
2006-09-01 18:17:58 +00:00
|
|
|
|
2007-10-08 18:33:35 +00:00
|
|
|
// If nothing else, we can make a libcall.
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(RTLIB::MUL_I64, Node, false/*sign irrelevant*/, Hi);
|
2005-04-11 03:01:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-01-12 02:11:51 +00:00
|
|
|
case ISD::SDIV:
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(RTLIB::SDIV_I64, Node, true, Hi);
|
2007-01-12 02:11:51 +00:00
|
|
|
break;
|
|
|
|
case ISD::UDIV:
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(RTLIB::UDIV_I64, Node, true, Hi);
|
2007-01-12 02:11:51 +00:00
|
|
|
break;
|
|
|
|
case ISD::SREM:
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(RTLIB::SREM_I64, Node, true, Hi);
|
2007-01-12 02:11:51 +00:00
|
|
|
break;
|
|
|
|
case ISD::UREM:
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(RTLIB::UREM_I64, Node, true, Hi);
|
2007-01-12 02:11:51 +00:00
|
|
|
break;
|
2006-12-12 21:51:17 +00:00
|
|
|
|
2006-12-09 02:42:38 +00:00
|
|
|
case ISD::FADD:
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::ADD_F32,
|
|
|
|
RTLIB::ADD_F64,
|
|
|
|
RTLIB::ADD_F80,
|
|
|
|
RTLIB::ADD_PPCF128),
|
2007-01-12 02:11:51 +00:00
|
|
|
Node, false, Hi);
|
2006-12-09 02:42:38 +00:00
|
|
|
break;
|
|
|
|
case ISD::FSUB:
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::SUB_F32,
|
|
|
|
RTLIB::SUB_F64,
|
|
|
|
RTLIB::SUB_F80,
|
|
|
|
RTLIB::SUB_PPCF128),
|
2007-01-12 02:11:51 +00:00
|
|
|
Node, false, Hi);
|
2006-12-09 02:42:38 +00:00
|
|
|
break;
|
|
|
|
case ISD::FMUL:
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::MUL_F32,
|
|
|
|
RTLIB::MUL_F64,
|
|
|
|
RTLIB::MUL_F80,
|
|
|
|
RTLIB::MUL_PPCF128),
|
2007-01-12 02:11:51 +00:00
|
|
|
Node, false, Hi);
|
2006-12-09 02:42:38 +00:00
|
|
|
break;
|
|
|
|
case ISD::FDIV:
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::DIV_F32,
|
|
|
|
RTLIB::DIV_F64,
|
|
|
|
RTLIB::DIV_F80,
|
|
|
|
RTLIB::DIV_PPCF128),
|
2007-01-12 02:11:51 +00:00
|
|
|
Node, false, Hi);
|
2006-12-09 02:42:38 +00:00
|
|
|
break;
|
|
|
|
case ISD::FP_EXTEND:
|
2007-10-12 01:37:08 +00:00
|
|
|
if (VT == MVT::ppcf128) {
|
|
|
|
assert(Node->getOperand(0).getValueType()==MVT::f32 ||
|
|
|
|
Node->getOperand(0).getValueType()==MVT::f64);
|
|
|
|
const uint64_t zero = 0;
|
|
|
|
if (Node->getOperand(0).getValueType()==MVT::f32)
|
|
|
|
Hi = DAG.getNode(ISD::FP_EXTEND, MVT::f64, Node->getOperand(0));
|
|
|
|
else
|
|
|
|
Hi = Node->getOperand(0);
|
|
|
|
Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64);
|
|
|
|
break;
|
|
|
|
}
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(RTLIB::FPEXT_F32_F64, Node, true, Hi);
|
2006-12-09 02:42:38 +00:00
|
|
|
break;
|
|
|
|
case ISD::FP_ROUND:
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(RTLIB::FPROUND_F64_F32, Node, true, Hi);
|
2006-12-09 02:42:38 +00:00
|
|
|
break;
|
2007-08-15 22:13:27 +00:00
|
|
|
case ISD::FPOWI:
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(GetFPLibCall(VT, RTLIB::POWI_F32,
|
|
|
|
RTLIB::POWI_F64,
|
|
|
|
RTLIB::POWI_F80,
|
|
|
|
RTLIB::POWI_PPCF128),
|
2007-08-15 22:13:27 +00:00
|
|
|
Node, false, Hi);
|
|
|
|
break;
|
2006-12-13 02:38:13 +00:00
|
|
|
case ISD::FSQRT:
|
|
|
|
case ISD::FSIN:
|
|
|
|
case ISD::FCOS: {
|
2007-01-12 02:11:51 +00:00
|
|
|
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
|
2006-12-13 02:38:13 +00:00
|
|
|
switch(Node->getOpcode()) {
|
2007-01-12 02:11:51 +00:00
|
|
|
case ISD::FSQRT:
|
2008-01-10 10:28:30 +00:00
|
|
|
LC = GetFPLibCall(VT, RTLIB::SQRT_F32, RTLIB::SQRT_F64,
|
|
|
|
RTLIB::SQRT_F80, RTLIB::SQRT_PPCF128);
|
2007-01-12 02:11:51 +00:00
|
|
|
break;
|
|
|
|
case ISD::FSIN:
|
2008-01-10 10:28:30 +00:00
|
|
|
LC = GetFPLibCall(VT, RTLIB::SIN_F32, RTLIB::SIN_F64,
|
|
|
|
RTLIB::SIN_F80, RTLIB::SIN_PPCF128);
|
2007-01-12 02:11:51 +00:00
|
|
|
break;
|
|
|
|
case ISD::FCOS:
|
2008-01-10 10:28:30 +00:00
|
|
|
LC = GetFPLibCall(VT, RTLIB::COS_F32, RTLIB::COS_F64,
|
|
|
|
RTLIB::COS_F80, RTLIB::COS_PPCF128);
|
2007-01-12 02:11:51 +00:00
|
|
|
break;
|
2006-12-13 02:38:13 +00:00
|
|
|
default: assert(0 && "Unreachable!");
|
|
|
|
}
|
2008-04-12 17:14:18 +00:00
|
|
|
Lo = ExpandLibCall(LC, Node, false, Hi);
|
2006-12-13 02:38:13 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-12-16 00:52:40 +00:00
|
|
|
case ISD::FABS: {
|
2007-10-12 19:02:17 +00:00
|
|
|
if (VT == MVT::ppcf128) {
|
|
|
|
SDOperand Tmp;
|
|
|
|
ExpandOp(Node->getOperand(0), Lo, Tmp);
|
|
|
|
Hi = DAG.getNode(ISD::FABS, NVT, Tmp);
|
|
|
|
// lo = hi==fabs(hi) ? lo : -lo;
|
|
|
|
Lo = DAG.getNode(ISD::SELECT_CC, NVT, Hi, Tmp,
|
|
|
|
Lo, DAG.getNode(ISD::FNEG, NVT, Lo),
|
|
|
|
DAG.getCondCode(ISD::SETEQ));
|
|
|
|
break;
|
|
|
|
}
|
2006-12-16 00:52:40 +00:00
|
|
|
SDOperand Mask = (VT == MVT::f64)
|
|
|
|
? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT)
|
|
|
|
: DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT);
|
|
|
|
Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask);
|
|
|
|
Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0));
|
|
|
|
Lo = DAG.getNode(ISD::AND, NVT, Lo, Mask);
|
|
|
|
if (getTypeAction(NVT) == Expand)
|
|
|
|
ExpandOp(Lo, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISD::FNEG: {
|
2007-10-12 19:02:17 +00:00
|
|
|
if (VT == MVT::ppcf128) {
|
|
|
|
ExpandOp(Node->getOperand(0), Lo, Hi);
|
|
|
|
Lo = DAG.getNode(ISD::FNEG, MVT::f64, Lo);
|
|
|
|
Hi = DAG.getNode(ISD::FNEG, MVT::f64, Hi);
|
|
|
|
break;
|
|
|
|
}
|
2006-12-16 00:52:40 +00:00
|
|
|
SDOperand Mask = (VT == MVT::f64)
|
|
|
|
? DAG.getConstantFP(BitsToDouble(1ULL << 63), VT)
|
|
|
|
: DAG.getConstantFP(BitsToFloat(1U << 31), VT);
|
|
|
|
Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask);
|
|
|
|
Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0));
|
|
|
|
Lo = DAG.getNode(ISD::XOR, NVT, Lo, Mask);
|
|
|
|
if (getTypeAction(NVT) == Expand)
|
|
|
|
ExpandOp(Lo, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
2007-01-04 21:56:39 +00:00
|
|
|
case ISD::FCOPYSIGN: {
|
|
|
|
Lo = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI);
|
|
|
|
if (getTypeAction(NVT) == Expand)
|
|
|
|
ExpandOp(Lo, Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
2006-12-19 01:44:04 +00:00
|
|
|
case ISD::SINT_TO_FP:
|
|
|
|
case ISD::UINT_TO_FP: {
|
|
|
|
bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP;
|
|
|
|
MVT::ValueType SrcVT = Node->getOperand(0).getValueType();
|
2008-03-18 17:28:38 +00:00
|
|
|
|
|
|
|
// Promote the operand if needed. Do this before checking for
|
|
|
|
// ppcf128 so conversions of i16 and i8 work.
|
|
|
|
if (getTypeAction(SrcVT) == Promote) {
|
|
|
|
SDOperand Tmp = PromoteOp(Node->getOperand(0));
|
|
|
|
Tmp = isSigned
|
|
|
|
? DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp.getValueType(), Tmp,
|
|
|
|
DAG.getValueType(SrcVT))
|
|
|
|
: DAG.getZeroExtendInReg(Tmp, SrcVT);
|
|
|
|
Node = DAG.UpdateNodeOperands(Op, Tmp).Val;
|
|
|
|
SrcVT = Node->getOperand(0).getValueType();
|
|
|
|
}
|
|
|
|
|
2008-03-10 23:03:31 +00:00
|
|
|
if (VT == MVT::ppcf128 && SrcVT == MVT::i32) {
|
2008-02-25 21:39:34 +00:00
|
|
|
static const uint64_t zero = 0;
|
2007-10-12 01:37:08 +00:00
|
|
|
if (isSigned) {
|
|
|
|
Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, MVT::f64,
|
|
|
|
Node->getOperand(0)));
|
|
|
|
Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64);
|
|
|
|
} else {
|
2008-02-25 21:39:34 +00:00
|
|
|
static const uint64_t TwoE32[] = { 0x41f0000000000000LL, 0 };
|
2007-10-12 01:37:08 +00:00
|
|
|
Hi = LegalizeOp(DAG.getNode(ISD::SINT_TO_FP, MVT::f64,
|
|
|
|
Node->getOperand(0)));
|
|
|
|
Lo = DAG.getConstantFP(APFloat(APInt(64, 1, &zero)), MVT::f64);
|
|
|
|
Hi = DAG.getNode(ISD::BUILD_PAIR, VT, Lo, Hi);
|
2007-10-12 17:52:03 +00:00
|
|
|
// X>=0 ? {(f64)x, 0} : {(f64)x, 0} + 2^32
|
2007-10-12 01:37:08 +00:00
|
|
|
ExpandOp(DAG.getNode(ISD::SELECT_CC, MVT::ppcf128, Node->getOperand(0),
|
|
|
|
DAG.getConstant(0, MVT::i32),
|
|
|
|
DAG.getNode(ISD::FADD, MVT::ppcf128, Hi,
|
|
|
|
DAG.getConstantFP(
|
|
|
|
APFloat(APInt(128, 2, TwoE32)),
|
|
|
|
MVT::ppcf128)),
|
|
|
|
Hi,
|
|
|
|
DAG.getCondCode(ISD::SETLT)),
|
|
|
|
Lo, Hi);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-10-12 17:52:03 +00:00
|
|
|
if (VT == MVT::ppcf128 && SrcVT == MVT::i64 && !isSigned) {
|
|
|
|
// si64->ppcf128 done by libcall, below
|
2008-02-25 21:39:34 +00:00
|
|
|
static const uint64_t TwoE64[] = { 0x43f0000000000000LL, 0 };
|
2007-10-12 17:52:03 +00:00
|
|
|
ExpandOp(DAG.getNode(ISD::SINT_TO_FP, MVT::ppcf128, Node->getOperand(0)),
|
|
|
|
Lo, Hi);
|
|
|
|
Hi = DAG.getNode(ISD::BUILD_PAIR, VT, Lo, Hi);
|
|
|
|
// x>=0 ? (ppcf128)(i64)x : (ppcf128)(i64)x + 2^64
|
|
|
|
ExpandOp(DAG.getNode(ISD::SELECT_CC, MVT::ppcf128, Node->getOperand(0),
|
|
|
|
DAG.getConstant(0, MVT::i64),
|
|
|
|
DAG.getNode(ISD::FADD, MVT::ppcf128, Hi,
|
|
|
|
DAG.getConstantFP(
|
|
|
|
APFloat(APInt(128, 2, TwoE64)),
|
|
|
|
MVT::ppcf128)),
|
|
|
|
Hi,
|
|
|
|
DAG.getCondCode(ISD::SETLT)),
|
|
|
|
Lo, Hi);
|
|
|
|
break;
|
|
|
|
}
|
2006-12-19 01:44:04 +00:00
|
|
|
|
2008-03-10 23:03:31 +00:00
|
|
|
Lo = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, VT,
|
|
|
|
Node->getOperand(0));
|
2008-04-01 01:50:16 +00:00
|
|
|
if (getTypeAction(Lo.getValueType()) == Expand)
|
2008-04-01 01:51:26 +00:00
|
|
|
// float to i32 etc. can be 'expanded' to a single node.
|
2008-04-01 01:50:16 +00:00
|
|
|
ExpandOp(Lo, Lo, Hi);
|
2006-12-19 01:44:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-12-13 02:38:13 +00:00
|
|
|
}
|
2005-01-07 07:47:09 +00:00
|
|
|
|
2005-12-21 18:02:52 +00:00
|
|
|
// Make sure the resultant values have been legalized themselves, unless this
|
|
|
|
// is a type that requires multi-step expansion.
|
|
|
|
if (getTypeAction(NVT) != Expand && NVT != MVT::isVoid) {
|
|
|
|
Lo = LegalizeOp(Lo);
|
2006-12-11 19:27:14 +00:00
|
|
|
if (Hi.Val)
|
|
|
|
// Don't legalize the high part if it is expanded to a single node.
|
|
|
|
Hi = LegalizeOp(Hi);
|
2005-12-21 18:02:52 +00:00
|
|
|
}
|
2006-01-09 18:31:59 +00:00
|
|
|
|
|
|
|
// Remember in a map if the values will be reused later.
|
2007-02-04 01:17:38 +00:00
|
|
|
bool isNew = ExpandedNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi)));
|
2006-01-09 18:31:59 +00:00
|
|
|
assert(isNew && "Value already expanded?!?");
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
/// SplitVectorOp - Given an operand of vector type, break it down into
|
|
|
|
/// two smaller values, still of vector type.
|
2006-03-18 01:44:44 +00:00
|
|
|
void SelectionDAGLegalize::SplitVectorOp(SDOperand Op, SDOperand &Lo,
|
|
|
|
SDOperand &Hi) {
|
2007-06-25 16:23:39 +00:00
|
|
|
assert(MVT::isVector(Op.getValueType()) && "Cannot split non-vector type!");
|
2006-03-18 01:44:44 +00:00
|
|
|
SDNode *Node = Op.Val;
|
2007-09-24 15:54:53 +00:00
|
|
|
unsigned NumElements = MVT::getVectorNumElements(Op.getValueType());
|
2006-03-18 01:44:44 +00:00
|
|
|
assert(NumElements > 1 && "Cannot split a single element vector!");
|
2007-11-15 21:15:26 +00:00
|
|
|
|
2007-09-24 15:54:53 +00:00
|
|
|
MVT::ValueType NewEltVT = MVT::getVectorElementType(Op.getValueType());
|
2007-11-15 21:15:26 +00:00
|
|
|
|
|
|
|
unsigned NewNumElts_Lo = 1 << Log2_32(NumElements-1);
|
|
|
|
unsigned NewNumElts_Hi = NumElements - NewNumElts_Lo;
|
|
|
|
|
|
|
|
MVT::ValueType NewVT_Lo = MVT::getVectorType(NewEltVT, NewNumElts_Lo);
|
|
|
|
MVT::ValueType NewVT_Hi = MVT::getVectorType(NewEltVT, NewNumElts_Hi);
|
|
|
|
|
2006-03-18 01:44:44 +00:00
|
|
|
// See if we already split it.
|
|
|
|
std::map<SDOperand, std::pair<SDOperand, SDOperand> >::iterator I
|
|
|
|
= SplitNodes.find(Op);
|
|
|
|
if (I != SplitNodes.end()) {
|
|
|
|
Lo = I->second.first;
|
|
|
|
Hi = I->second.second;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (Node->getOpcode()) {
|
2006-07-11 17:58:07 +00:00
|
|
|
default:
|
|
|
|
#ifndef NDEBUG
|
2007-06-04 16:17:33 +00:00
|
|
|
Node->dump(&DAG);
|
2006-07-11 17:58:07 +00:00
|
|
|
#endif
|
|
|
|
assert(0 && "Unhandled operation in SplitVectorOp!");
|
2007-11-19 20:21:32 +00:00
|
|
|
case ISD::UNDEF:
|
|
|
|
Lo = DAG.getNode(ISD::UNDEF, NewVT_Lo);
|
|
|
|
Hi = DAG.getNode(ISD::UNDEF, NewVT_Hi);
|
|
|
|
break;
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::BUILD_PAIR:
|
|
|
|
Lo = Node->getOperand(0);
|
|
|
|
Hi = Node->getOperand(1);
|
|
|
|
break;
|
2007-09-28 23:53:40 +00:00
|
|
|
case ISD::INSERT_VECTOR_ELT: {
|
2008-04-25 18:07:40 +00:00
|
|
|
if (ConstantSDNode *Idx = dyn_cast<ConstantSDNode>(Node->getOperand(2))) {
|
|
|
|
SplitVectorOp(Node->getOperand(0), Lo, Hi);
|
|
|
|
unsigned Index = Idx->getValue();
|
|
|
|
SDOperand ScalarOp = Node->getOperand(1);
|
|
|
|
if (Index < NewNumElts_Lo)
|
|
|
|
Lo = DAG.getNode(ISD::INSERT_VECTOR_ELT, NewVT_Lo, Lo, ScalarOp,
|
|
|
|
DAG.getIntPtrConstant(Index));
|
|
|
|
else
|
|
|
|
Hi = DAG.getNode(ISD::INSERT_VECTOR_ELT, NewVT_Hi, Hi, ScalarOp,
|
|
|
|
DAG.getIntPtrConstant(Index - NewNumElts_Lo));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SDOperand Tmp = PerformInsertVectorEltInMemory(Node->getOperand(0),
|
|
|
|
Node->getOperand(1),
|
|
|
|
Node->getOperand(2));
|
|
|
|
SplitVectorOp(Tmp, Lo, Hi);
|
2007-09-28 23:53:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-11-19 21:16:54 +00:00
|
|
|
case ISD::VECTOR_SHUFFLE: {
|
|
|
|
// Build the low part.
|
|
|
|
SDOperand Mask = Node->getOperand(2);
|
|
|
|
SmallVector<SDOperand, 8> Ops;
|
|
|
|
MVT::ValueType PtrVT = TLI.getPointerTy();
|
|
|
|
|
|
|
|
// Insert all of the elements from the input that are needed. We use
|
|
|
|
// buildvector of extractelement here because the input vectors will have
|
|
|
|
// to be legalized, so this makes the code simpler.
|
|
|
|
for (unsigned i = 0; i != NewNumElts_Lo; ++i) {
|
2008-03-14 00:53:31 +00:00
|
|
|
SDOperand IdxNode = Mask.getOperand(i);
|
|
|
|
if (IdxNode.getOpcode() == ISD::UNDEF) {
|
|
|
|
Ops.push_back(DAG.getNode(ISD::UNDEF, NewEltVT));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
unsigned Idx = cast<ConstantSDNode>(IdxNode)->getValue();
|
2007-11-19 21:16:54 +00:00
|
|
|
SDOperand InVec = Node->getOperand(0);
|
|
|
|
if (Idx >= NumElements) {
|
|
|
|
InVec = Node->getOperand(1);
|
|
|
|
Idx -= NumElements;
|
|
|
|
}
|
|
|
|
Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, NewEltVT, InVec,
|
|
|
|
DAG.getConstant(Idx, PtrVT)));
|
|
|
|
}
|
|
|
|
Lo = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Lo, &Ops[0], Ops.size());
|
|
|
|
Ops.clear();
|
|
|
|
|
|
|
|
for (unsigned i = NewNumElts_Lo; i != NumElements; ++i) {
|
2008-03-14 00:53:31 +00:00
|
|
|
SDOperand IdxNode = Mask.getOperand(i);
|
|
|
|
if (IdxNode.getOpcode() == ISD::UNDEF) {
|
|
|
|
Ops.push_back(DAG.getNode(ISD::UNDEF, NewEltVT));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
unsigned Idx = cast<ConstantSDNode>(IdxNode)->getValue();
|
2007-11-19 21:16:54 +00:00
|
|
|
SDOperand InVec = Node->getOperand(0);
|
|
|
|
if (Idx >= NumElements) {
|
|
|
|
InVec = Node->getOperand(1);
|
|
|
|
Idx -= NumElements;
|
|
|
|
}
|
|
|
|
Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, NewEltVT, InVec,
|
|
|
|
DAG.getConstant(Idx, PtrVT)));
|
|
|
|
}
|
|
|
|
Hi = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Lo, &Ops[0], Ops.size());
|
|
|
|
break;
|
|
|
|
}
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::BUILD_VECTOR: {
|
2006-08-08 02:23:42 +00:00
|
|
|
SmallVector<SDOperand, 8> LoOps(Node->op_begin(),
|
2007-11-15 21:15:26 +00:00
|
|
|
Node->op_begin()+NewNumElts_Lo);
|
|
|
|
Lo = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Lo, &LoOps[0], LoOps.size());
|
2006-03-18 01:44:44 +00:00
|
|
|
|
2007-11-15 21:15:26 +00:00
|
|
|
SmallVector<SDOperand, 8> HiOps(Node->op_begin()+NewNumElts_Lo,
|
2007-06-25 16:23:39 +00:00
|
|
|
Node->op_end());
|
2007-11-15 21:15:26 +00:00
|
|
|
Hi = DAG.getNode(ISD::BUILD_VECTOR, NewVT_Hi, &HiOps[0], HiOps.size());
|
2006-03-18 01:44:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::CONCAT_VECTORS: {
|
2007-11-15 21:15:26 +00:00
|
|
|
// FIXME: Handle non-power-of-two vectors?
|
2007-06-25 16:23:39 +00:00
|
|
|
unsigned NewNumSubvectors = Node->getNumOperands() / 2;
|
|
|
|
if (NewNumSubvectors == 1) {
|
|
|
|
Lo = Node->getOperand(0);
|
|
|
|
Hi = Node->getOperand(1);
|
|
|
|
} else {
|
|
|
|
SmallVector<SDOperand, 8> LoOps(Node->op_begin(),
|
|
|
|
Node->op_begin()+NewNumSubvectors);
|
2007-11-15 21:15:26 +00:00
|
|
|
Lo = DAG.getNode(ISD::CONCAT_VECTORS, NewVT_Lo, &LoOps[0], LoOps.size());
|
2007-06-13 15:12:02 +00:00
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
SmallVector<SDOperand, 8> HiOps(Node->op_begin()+NewNumSubvectors,
|
|
|
|
Node->op_end());
|
2007-11-15 21:15:26 +00:00
|
|
|
Hi = DAG.getNode(ISD::CONCAT_VECTORS, NewVT_Hi, &HiOps[0], HiOps.size());
|
2007-06-25 16:23:39 +00:00
|
|
|
}
|
2007-06-13 15:12:02 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-10-17 14:48:28 +00:00
|
|
|
case ISD::SELECT: {
|
|
|
|
SDOperand Cond = Node->getOperand(0);
|
|
|
|
|
|
|
|
SDOperand LL, LH, RL, RH;
|
|
|
|
SplitVectorOp(Node->getOperand(1), LL, LH);
|
|
|
|
SplitVectorOp(Node->getOperand(2), RL, RH);
|
|
|
|
|
|
|
|
if (MVT::isVector(Cond.getValueType())) {
|
|
|
|
// Handle a vector merge.
|
|
|
|
SDOperand CL, CH;
|
|
|
|
SplitVectorOp(Cond, CL, CH);
|
2007-11-15 21:15:26 +00:00
|
|
|
Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, CL, LL, RL);
|
|
|
|
Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, CH, LH, RH);
|
2007-10-17 14:48:28 +00:00
|
|
|
} else {
|
|
|
|
// Handle a simple select with vector operands.
|
2007-11-15 21:15:26 +00:00
|
|
|
Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, Cond, LL, RL);
|
|
|
|
Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, Cond, LH, RH);
|
2007-10-17 14:48:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-05-12 19:40:03 +00:00
|
|
|
case ISD::VSETCC: {
|
|
|
|
SDOperand LL, LH, RL, RH;
|
|
|
|
SplitVectorOp(Node->getOperand(0), LL, LH);
|
|
|
|
SplitVectorOp(Node->getOperand(1), RL, RH);
|
|
|
|
Lo = DAG.getNode(ISD::VSETCC, NewVT_Lo, LL, RL, Node->getOperand(2));
|
|
|
|
Hi = DAG.getNode(ISD::VSETCC, NewVT_Hi, LH, RH, Node->getOperand(2));
|
|
|
|
break;
|
|
|
|
}
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::ADD:
|
|
|
|
case ISD::SUB:
|
|
|
|
case ISD::MUL:
|
|
|
|
case ISD::FADD:
|
|
|
|
case ISD::FSUB:
|
|
|
|
case ISD::FMUL:
|
|
|
|
case ISD::SDIV:
|
|
|
|
case ISD::UDIV:
|
|
|
|
case ISD::FDIV:
|
2007-10-11 23:57:53 +00:00
|
|
|
case ISD::FPOW:
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::AND:
|
|
|
|
case ISD::OR:
|
2007-11-19 15:15:03 +00:00
|
|
|
case ISD::XOR:
|
|
|
|
case ISD::UREM:
|
|
|
|
case ISD::SREM:
|
|
|
|
case ISD::FREM: {
|
2006-03-18 01:44:44 +00:00
|
|
|
SDOperand LL, LH, RL, RH;
|
|
|
|
SplitVectorOp(Node->getOperand(0), LL, LH);
|
|
|
|
SplitVectorOp(Node->getOperand(1), RL, RH);
|
|
|
|
|
2007-11-15 21:15:26 +00:00
|
|
|
Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, LL, RL);
|
|
|
|
Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, LH, RH);
|
2006-03-18 01:44:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-10-11 23:57:53 +00:00
|
|
|
case ISD::FPOWI: {
|
|
|
|
SDOperand L, H;
|
|
|
|
SplitVectorOp(Node->getOperand(0), L, H);
|
|
|
|
|
2007-11-15 21:15:26 +00:00
|
|
|
Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, L, Node->getOperand(1));
|
|
|
|
Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, H, Node->getOperand(1));
|
2007-10-11 23:57:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISD::CTTZ:
|
|
|
|
case ISD::CTLZ:
|
|
|
|
case ISD::CTPOP:
|
|
|
|
case ISD::FNEG:
|
|
|
|
case ISD::FABS:
|
|
|
|
case ISD::FSQRT:
|
|
|
|
case ISD::FSIN:
|
2007-11-17 03:58:34 +00:00
|
|
|
case ISD::FCOS:
|
|
|
|
case ISD::FP_TO_SINT:
|
|
|
|
case ISD::FP_TO_UINT:
|
|
|
|
case ISD::SINT_TO_FP:
|
|
|
|
case ISD::UINT_TO_FP: {
|
2007-10-11 23:57:53 +00:00
|
|
|
SDOperand L, H;
|
|
|
|
SplitVectorOp(Node->getOperand(0), L, H);
|
|
|
|
|
2007-11-15 21:15:26 +00:00
|
|
|
Lo = DAG.getNode(Node->getOpcode(), NewVT_Lo, L);
|
|
|
|
Hi = DAG.getNode(Node->getOpcode(), NewVT_Hi, H);
|
2007-10-11 23:57:53 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::LOAD: {
|
|
|
|
LoadSDNode *LD = cast<LoadSDNode>(Node);
|
|
|
|
SDOperand Ch = LD->getChain();
|
|
|
|
SDOperand Ptr = LD->getBasePtr();
|
|
|
|
const Value *SV = LD->getSrcValue();
|
|
|
|
int SVOffset = LD->getSrcValueOffset();
|
|
|
|
unsigned Alignment = LD->getAlignment();
|
|
|
|
bool isVolatile = LD->isVolatile();
|
|
|
|
|
2007-11-15 21:15:26 +00:00
|
|
|
Lo = DAG.getLoad(NewVT_Lo, Ch, Ptr, SV, SVOffset, isVolatile, Alignment);
|
|
|
|
unsigned IncrementSize = NewNumElts_Lo * MVT::getSizeInBits(NewEltVT)/8;
|
2006-03-18 01:44:44 +00:00
|
|
|
Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr,
|
2008-01-17 07:00:52 +00:00
|
|
|
DAG.getIntPtrConstant(IncrementSize));
|
2007-06-25 16:23:39 +00:00
|
|
|
SVOffset += IncrementSize;
|
2007-10-28 12:59:45 +00:00
|
|
|
Alignment = MinAlign(Alignment, IncrementSize);
|
2007-11-15 21:15:26 +00:00
|
|
|
Hi = DAG.getLoad(NewVT_Hi, Ch, Ptr, SV, SVOffset, isVolatile, Alignment);
|
2006-03-18 01:44:44 +00:00
|
|
|
|
|
|
|
// Build a factor node to remember that this load is independent of the
|
|
|
|
// other one.
|
|
|
|
SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1),
|
|
|
|
Hi.getValue(1));
|
|
|
|
|
|
|
|
// Remember that we legalized the chain.
|
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF));
|
|
|
|
break;
|
|
|
|
}
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::BIT_CONVERT: {
|
2006-03-23 21:16:34 +00:00
|
|
|
// We know the result is a vector. The input may be either a vector or a
|
|
|
|
// scalar value.
|
2007-06-29 00:09:08 +00:00
|
|
|
SDOperand InOp = Node->getOperand(0);
|
|
|
|
if (!MVT::isVector(InOp.getValueType()) ||
|
|
|
|
MVT::getVectorNumElements(InOp.getValueType()) == 1) {
|
|
|
|
// The input is a scalar or single-element vector.
|
|
|
|
// Lower to a store/load so that it can be split.
|
|
|
|
// FIXME: this could be improved probably.
|
2007-10-15 17:48:57 +00:00
|
|
|
SDOperand Ptr = DAG.CreateStackTemporary(InOp.getValueType());
|
2008-02-11 18:58:42 +00:00
|
|
|
FrameIndexSDNode *FI = cast<FrameIndexSDNode>(Ptr.Val);
|
2006-03-23 21:16:34 +00:00
|
|
|
|
2006-10-05 23:01:46 +00:00
|
|
|
SDOperand St = DAG.getStore(DAG.getEntryNode(),
|
2008-02-06 22:27:42 +00:00
|
|
|
InOp, Ptr,
|
2008-02-07 18:41:25 +00:00
|
|
|
PseudoSourceValue::getFixedStack(),
|
2008-02-06 22:27:42 +00:00
|
|
|
FI->getIndex());
|
|
|
|
InOp = DAG.getLoad(Op.getValueType(), St, Ptr,
|
2008-02-07 18:41:25 +00:00
|
|
|
PseudoSourceValue::getFixedStack(),
|
2008-02-06 22:27:42 +00:00
|
|
|
FI->getIndex());
|
2006-03-23 21:16:34 +00:00
|
|
|
}
|
2007-06-29 00:09:08 +00:00
|
|
|
// Split the vector and convert each of the pieces now.
|
|
|
|
SplitVectorOp(InOp, Lo, Hi);
|
2007-11-15 21:15:26 +00:00
|
|
|
Lo = DAG.getNode(ISD::BIT_CONVERT, NewVT_Lo, Lo);
|
|
|
|
Hi = DAG.getNode(ISD::BIT_CONVERT, NewVT_Hi, Hi);
|
2007-06-29 00:09:08 +00:00
|
|
|
break;
|
2006-03-23 21:16:34 +00:00
|
|
|
}
|
2006-03-18 01:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remember in a map if the values will be reused later.
|
2007-02-04 01:17:38 +00:00
|
|
|
bool isNew =
|
2006-03-18 01:44:44 +00:00
|
|
|
SplitNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))).second;
|
2007-06-29 00:09:08 +00:00
|
|
|
assert(isNew && "Value already split?!?");
|
2006-03-18 01:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-27 14:06:22 +00:00
|
|
|
/// ScalarizeVectorOp - Given an operand of single-element vector type
|
|
|
|
/// (e.g. v1f32), convert it into the equivalent operation that returns a
|
|
|
|
/// scalar (e.g. f32) value.
|
2007-06-25 16:23:39 +00:00
|
|
|
SDOperand SelectionDAGLegalize::ScalarizeVectorOp(SDOperand Op) {
|
|
|
|
assert(MVT::isVector(Op.getValueType()) &&
|
|
|
|
"Bad ScalarizeVectorOp invocation!");
|
2006-03-18 01:44:44 +00:00
|
|
|
SDNode *Node = Op.Val;
|
2007-06-25 16:23:39 +00:00
|
|
|
MVT::ValueType NewVT = MVT::getVectorElementType(Op.getValueType());
|
|
|
|
assert(MVT::getVectorNumElements(Op.getValueType()) == 1);
|
2006-03-18 01:44:44 +00:00
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
// See if we already scalarized it.
|
|
|
|
std::map<SDOperand, SDOperand>::iterator I = ScalarizedNodes.find(Op);
|
|
|
|
if (I != ScalarizedNodes.end()) return I->second;
|
2006-03-18 01:44:44 +00:00
|
|
|
|
|
|
|
SDOperand Result;
|
|
|
|
switch (Node->getOpcode()) {
|
2006-03-19 01:17:20 +00:00
|
|
|
default:
|
2006-07-11 17:58:07 +00:00
|
|
|
#ifndef NDEBUG
|
2007-06-04 16:17:33 +00:00
|
|
|
Node->dump(&DAG); cerr << "\n";
|
2006-07-11 17:58:07 +00:00
|
|
|
#endif
|
2007-06-25 16:23:39 +00:00
|
|
|
assert(0 && "Unknown vector operation in ScalarizeVectorOp!");
|
|
|
|
case ISD::ADD:
|
|
|
|
case ISD::FADD:
|
|
|
|
case ISD::SUB:
|
|
|
|
case ISD::FSUB:
|
|
|
|
case ISD::MUL:
|
|
|
|
case ISD::FMUL:
|
|
|
|
case ISD::SDIV:
|
|
|
|
case ISD::UDIV:
|
|
|
|
case ISD::FDIV:
|
|
|
|
case ISD::SREM:
|
|
|
|
case ISD::UREM:
|
|
|
|
case ISD::FREM:
|
2007-10-11 23:57:53 +00:00
|
|
|
case ISD::FPOW:
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::AND:
|
|
|
|
case ISD::OR:
|
|
|
|
case ISD::XOR:
|
|
|
|
Result = DAG.getNode(Node->getOpcode(),
|
2006-03-18 01:44:44 +00:00
|
|
|
NewVT,
|
2007-06-25 16:23:39 +00:00
|
|
|
ScalarizeVectorOp(Node->getOperand(0)),
|
|
|
|
ScalarizeVectorOp(Node->getOperand(1)));
|
2006-03-18 01:44:44 +00:00
|
|
|
break;
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::FNEG:
|
|
|
|
case ISD::FABS:
|
|
|
|
case ISD::FSQRT:
|
|
|
|
case ISD::FSIN:
|
|
|
|
case ISD::FCOS:
|
|
|
|
Result = DAG.getNode(Node->getOpcode(),
|
|
|
|
NewVT,
|
|
|
|
ScalarizeVectorOp(Node->getOperand(0)));
|
|
|
|
break;
|
2007-10-12 14:13:46 +00:00
|
|
|
case ISD::FPOWI:
|
|
|
|
Result = DAG.getNode(Node->getOpcode(),
|
|
|
|
NewVT,
|
|
|
|
ScalarizeVectorOp(Node->getOperand(0)),
|
|
|
|
Node->getOperand(1));
|
|
|
|
break;
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::LOAD: {
|
|
|
|
LoadSDNode *LD = cast<LoadSDNode>(Node);
|
|
|
|
SDOperand Ch = LegalizeOp(LD->getChain()); // Legalize the chain.
|
|
|
|
SDOperand Ptr = LegalizeOp(LD->getBasePtr()); // Legalize the pointer.
|
2006-03-18 01:44:44 +00:00
|
|
|
|
2007-06-25 16:23:39 +00:00
|
|
|
const Value *SV = LD->getSrcValue();
|
|
|
|
int SVOffset = LD->getSrcValueOffset();
|
|
|
|
Result = DAG.getLoad(NewVT, Ch, Ptr, SV, SVOffset,
|
|
|
|
LD->isVolatile(), LD->getAlignment());
|
|
|
|
|
2006-03-18 01:44:44 +00:00
|
|
|
// Remember that we legalized the chain.
|
|
|
|
AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1)));
|
|
|
|
break;
|
|
|
|
}
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::BUILD_VECTOR:
|
|
|
|
Result = Node->getOperand(0);
|
|
|
|
break;
|
|
|
|
case ISD::INSERT_VECTOR_ELT:
|
|
|
|
// Returning the inserted scalar element.
|
|
|
|
Result = Node->getOperand(1);
|
2006-03-18 01:44:44 +00:00
|
|
|
break;
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::CONCAT_VECTORS:
|
2007-06-13 15:12:02 +00:00
|
|
|
assert(Node->getOperand(0).getValueType() == NewVT &&
|
|
|
|
"Concat of non-legal vectors not yet supported!");
|
|
|
|
Result = Node->getOperand(0);
|
|
|
|
break;
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::VECTOR_SHUFFLE: {
|
|
|
|
// Figure out if the scalar is the LHS or RHS and return it.
|
|
|
|
SDOperand EltNum = Node->getOperand(2).getOperand(0);
|
|
|
|
if (cast<ConstantSDNode>(EltNum)->getValue())
|
|
|
|
Result = ScalarizeVectorOp(Node->getOperand(1));
|
|
|
|
else
|
|
|
|
Result = ScalarizeVectorOp(Node->getOperand(0));
|
2006-03-19 01:17:20 +00:00
|
|
|
break;
|
2007-06-25 16:23:39 +00:00
|
|
|
}
|
|
|
|
case ISD::EXTRACT_SUBVECTOR:
|
|
|
|
Result = Node->getOperand(0);
|
2007-06-13 15:12:02 +00:00
|
|
|
assert(Result.getValueType() == NewVT);
|
|
|
|
break;
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::BIT_CONVERT:
|
|
|
|
Result = DAG.getNode(ISD::BIT_CONVERT, NewVT, Op.getOperand(0));
|
2006-04-10 18:54:36 +00:00
|
|
|
break;
|
2007-06-25 16:23:39 +00:00
|
|
|
case ISD::SELECT:
|
2006-04-08 22:22:57 +00:00
|
|
|
Result = DAG.getNode(ISD::SELECT, NewVT, Op.getOperand(0),
|
2007-06-25 16:23:39 +00:00
|
|
|
ScalarizeVectorOp(Op.getOperand(1)),
|
|
|
|
ScalarizeVectorOp(Op.getOperand(2)));
|
2006-04-08 22:22:57 +00:00
|
|
|
break;
|
2008-05-12 23:09:43 +00:00
|
|
|
case ISD::VSETCC: {
|
|
|
|
SDOperand Op0 = ScalarizeVectorOp(Op.getOperand(0));
|
|
|
|
SDOperand Op1 = ScalarizeVectorOp(Op.getOperand(1));
|
|
|
|
Result = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(Op0), Op0, Op1,
|
|
|
|
Op.getOperand(2));
|
|
|
|
Result = DAG.getNode(ISD::SELECT, NewVT, Result,
|
|
|
|
DAG.getConstant(-1ULL, NewVT),
|
|
|
|
DAG.getConstant(0ULL, NewVT));
|
|
|
|
break;
|
|
|
|
}
|
2006-03-18 01:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (TLI.isTypeLegal(NewVT))
|
|
|
|
Result = LegalizeOp(Result);
|
2007-06-25 16:23:39 +00:00
|
|
|
bool isNew = ScalarizedNodes.insert(std::make_pair(Op, Result)).second;
|
|
|
|
assert(isNew && "Value already scalarized?");
|
2006-03-18 01:44:44 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
|
|
|
|
// SelectionDAG::Legalize - This is the entry point for the file.
|
|
|
|
//
|
2005-01-23 04:42:50 +00:00
|
|
|
void SelectionDAG::Legalize() {
|
2006-04-02 03:07:27 +00:00
|
|
|
if (ViewLegalizeDAGs) viewGraph();
|
|
|
|
|
2005-01-07 07:47:09 +00:00
|
|
|
/// run - This is the main entry point to this class.
|
|
|
|
///
|
2006-01-28 07:39:30 +00:00
|
|
|
SelectionDAGLegalize(*this).LegalizeDAG();
|
2005-01-07 07:47:09 +00:00
|
|
|
}
|
|
|
|
|