LegalizeDAG.cpp revision b10308e440c80dd6ffb4b478f741ff7e5f30cb48
13e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner//===-- LegalizeDAG.cpp - Implement SelectionDAG::Legalize ----------------===// 2edf128a7fa90f2b0b7ee24741a04a7ae1ecd6f7eMisha Brukman// 33e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner// The LLVM Compiler Infrastructure 43e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner// 53e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner// This file was developed by the LLVM research group and is distributed under 63e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner// the University of Illinois Open Source License. See LICENSE.TXT for details. 7edf128a7fa90f2b0b7ee24741a04a7ae1ecd6f7eMisha Brukman// 83e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner//===----------------------------------------------------------------------===// 93e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner// 103e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner// This file implements the SelectionDAG::Legalize method. 113e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner// 123e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner//===----------------------------------------------------------------------===// 133e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 143e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner#include "llvm/CodeGen/SelectionDAG.h" 153e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner#include "llvm/CodeGen/MachineFunction.h" 1645b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner#include "llvm/CodeGen/MachineFrameInfo.h" 17acd80ac7bb19f8bdfa55336d567c9ecbe695c8b8Jim Laskey#include "llvm/CodeGen/MachineJumpTableInfo.h" 183e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner#include "llvm/Target/TargetLowering.h" 19e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner#include "llvm/Target/TargetData.h" 203d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng#include "llvm/Target/TargetMachine.h" 210f69b2910810b7c0971a739f18b37fae2a20eca5Chris Lattner#include "llvm/Target/TargetOptions.h" 22adf6a965a321372c640845407195594835921eb4Chris Lattner#include "llvm/CallingConv.h" 233e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner#include "llvm/Constants.h" 24c10305743c313558405079452138f03124e87581Reid Spencer#include "llvm/DerivedTypes.h" 255e46a19ec848cd4fc9649bd5170c43d9e657668cChris Lattner#include "llvm/Support/MathExtras.h" 265e46a19ec848cd4fc9649bd5170c43d9e657668cChris Lattner#include "llvm/Support/CommandLine.h" 27a4f0b3a084d120cfc5b5bb06f64b222f5cb72740Chris Lattner#include "llvm/Support/Compiler.h" 28f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner#include "llvm/ADT/SmallVector.h" 29033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng#include <map> 303e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattnerusing namespace llvm; 313e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 325e46a19ec848cd4fc9649bd5170c43d9e657668cChris Lattner#ifndef NDEBUG 335e46a19ec848cd4fc9649bd5170c43d9e657668cChris Lattnerstatic cl::opt<bool> 345e46a19ec848cd4fc9649bd5170c43d9e657668cChris LattnerViewLegalizeDAGs("view-legalize-dags", cl::Hidden, 355e46a19ec848cd4fc9649bd5170c43d9e657668cChris Lattner cl::desc("Pop up a window to show dags before legalize")); 365e46a19ec848cd4fc9649bd5170c43d9e657668cChris Lattner#else 375e46a19ec848cd4fc9649bd5170c43d9e657668cChris Lattnerstatic const bool ViewLegalizeDAGs = 0; 385e46a19ec848cd4fc9649bd5170c43d9e657668cChris Lattner#endif 395e46a19ec848cd4fc9649bd5170c43d9e657668cChris Lattner 403e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner//===----------------------------------------------------------------------===// 413e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner/// SelectionDAGLegalize - This takes an arbitrary SelectionDAG as input and 423e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner/// hacks on it until the target machine can handle it. This involves 433e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner/// eliminating value sizes the machine cannot handle (promoting small sizes to 443e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner/// large sizes or splitting up large values into small values) as well as 453e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner/// eliminating operations the machine cannot handle. 463e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner/// 473e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner/// This code also does a small amount of optimization and recognition of idioms 483e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner/// as part of its processing. For example, if a target does not support a 493e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner/// 'setcc' instruction efficiently, but does support 'brcc' instruction, this 503e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner/// will attempt merge setcc and brc instructions into brcc's. 513e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner/// 523e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattnernamespace { 53360e8200ec544a3c877ff74b48f445140ac9bbd6Chris Lattnerclass VISIBILITY_HIDDEN SelectionDAGLegalize { 543e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner TargetLowering &TLI; 553e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner SelectionDAG &DAG; 563e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 576831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Libcall insertion helpers. 586831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 596831a815999dde4cf801e2076e66b4943964daf2Chris Lattner /// LastCALLSEQ_END - This keeps track of the CALLSEQ_END node that has been 606831a815999dde4cf801e2076e66b4943964daf2Chris Lattner /// legalized. We use this to ensure that calls are properly serialized 616831a815999dde4cf801e2076e66b4943964daf2Chris Lattner /// against each other, including inserted libcalls. 626831a815999dde4cf801e2076e66b4943964daf2Chris Lattner SDOperand LastCALLSEQ_END; 636831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 646831a815999dde4cf801e2076e66b4943964daf2Chris Lattner /// IsLegalizingCall - This member is used *only* for purposes of providing 656831a815999dde4cf801e2076e66b4943964daf2Chris Lattner /// helpful assertions that a libcall isn't created while another call is 666831a815999dde4cf801e2076e66b4943964daf2Chris Lattner /// being legalized (which could lead to non-serialized call sequences). 676831a815999dde4cf801e2076e66b4943964daf2Chris Lattner bool IsLegalizingCall; 686831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 693e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner enum LegalizeAction { 7068a17febc70d9beb5353454e0c6d136ca1e87605Chris Lattner Legal, // The target natively supports this operation. 7168a17febc70d9beb5353454e0c6d136ca1e87605Chris Lattner Promote, // This operation should be executed in a larger type. 72d74ea2bbd8bb630331f35ead42d385249bd42af8Chris Lattner Expand // Try to expand this to other ops, otherwise use a libcall. 733e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner }; 746831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 753e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner /// ValueTypeActions - This is a bitvector that contains two bits for each 763e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner /// value type, where the two bits correspond to the LegalizeAction enum. 773e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner /// This can be queried with "getTypeAction(VT)". 7868a17febc70d9beb5353454e0c6d136ca1e87605Chris Lattner TargetLowering::ValueTypeActionImpl ValueTypeActions; 793e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 803e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner /// LegalizedNodes - For nodes that are of legal width, and that have more 813e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner /// than one use, this map indicates what regularized operand to use. This 823e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner /// allows us to avoid legalizing the same thing more than once. 833e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner std::map<SDOperand, SDOperand> LegalizedNodes; 843e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 8503c8546ec57523970874917854a2fb77b1ff598eChris Lattner /// PromotedNodes - For nodes that are below legal width, and that have more 8603c8546ec57523970874917854a2fb77b1ff598eChris Lattner /// than one use, this map indicates what promoted value to use. This allows 8703c8546ec57523970874917854a2fb77b1ff598eChris Lattner /// us to avoid promoting the same thing more than once. 8803c8546ec57523970874917854a2fb77b1ff598eChris Lattner std::map<SDOperand, SDOperand> PromotedNodes; 8903c8546ec57523970874917854a2fb77b1ff598eChris Lattner 90c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// ExpandedNodes - For nodes that need to be expanded this map indicates 91c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// which which operands are the expanded version of the input. This allows 92c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// us to avoid expanding the same node more than once. 933e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner std::map<SDOperand, std::pair<SDOperand, SDOperand> > ExpandedNodes; 943e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 95c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// SplitNodes - For vector nodes that need to be split, this map indicates 96c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// which which operands are the split version of the input. This allows us 97c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// to avoid splitting the same node more than once. 98c7029805ef35ce9805931067b841e6af11db382eChris Lattner std::map<SDOperand, std::pair<SDOperand, SDOperand> > SplitNodes; 99c7029805ef35ce9805931067b841e6af11db382eChris Lattner 100c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// PackedNodes - For nodes that need to be packed from MVT::Vector types to 101c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// concrete packed types, this contains the mapping of ones we have already 102c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// processed to the result. 103c7029805ef35ce9805931067b841e6af11db382eChris Lattner std::map<SDOperand, SDOperand> PackedNodes; 104c7029805ef35ce9805931067b841e6af11db382eChris Lattner 1058afc48e44ad8868c1d41511db645e2ba1a4b894eChris Lattner void AddLegalizedOperand(SDOperand From, SDOperand To) { 10669a889eb35d59a10e78a07cc26d41cbab31eddceChris Lattner LegalizedNodes.insert(std::make_pair(From, To)); 10769a889eb35d59a10e78a07cc26d41cbab31eddceChris Lattner // If someone requests legalization of the new node, return itself. 10869a889eb35d59a10e78a07cc26d41cbab31eddceChris Lattner if (From != To) 10969a889eb35d59a10e78a07cc26d41cbab31eddceChris Lattner LegalizedNodes.insert(std::make_pair(To, To)); 1108afc48e44ad8868c1d41511db645e2ba1a4b894eChris Lattner } 11103c8546ec57523970874917854a2fb77b1ff598eChris Lattner void AddPromotedOperand(SDOperand From, SDOperand To) { 11203c8546ec57523970874917854a2fb77b1ff598eChris Lattner bool isNew = PromotedNodes.insert(std::make_pair(From, To)).second; 11303c8546ec57523970874917854a2fb77b1ff598eChris Lattner assert(isNew && "Got into the map somehow?"); 11469a889eb35d59a10e78a07cc26d41cbab31eddceChris Lattner // If someone requests legalization of the new node, return itself. 11569a889eb35d59a10e78a07cc26d41cbab31eddceChris Lattner LegalizedNodes.insert(std::make_pair(To, To)); 11603c8546ec57523970874917854a2fb77b1ff598eChris Lattner } 1178afc48e44ad8868c1d41511db645e2ba1a4b894eChris Lattner 1183e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattnerpublic: 1193e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 1209c32d3b798dc6caeebe6cea2effe80ca5e84e66eChris Lattner SelectionDAGLegalize(SelectionDAG &DAG); 1213e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 1223e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner /// getTypeAction - Return how we should legalize values of this type, either 1233e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner /// it is already legal or we need to expand it into multiple registers of 1243e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner /// smaller integer type, or we need to promote it to a larger type. 1253e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner LegalizeAction getTypeAction(MVT::ValueType VT) const { 12668a17febc70d9beb5353454e0c6d136ca1e87605Chris Lattner return (LegalizeAction)ValueTypeActions.getTypeAction(VT); 1273e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 1283e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 1293e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner /// isTypeLegal - Return true if this type is legal on this target. 1303e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner /// 1313e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner bool isTypeLegal(MVT::ValueType VT) const { 1323e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner return getTypeAction(VT) == Legal; 1333e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 1343e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 1353e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner void LegalizeDAG(); 1363e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 137456a93afcec7740c45cafa8354317f7b17987a6dChris Lattnerprivate: 138c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// HandleOp - Legalize, Promote, Expand or Pack the specified operand as 139c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// appropriate for its type. 140c7029805ef35ce9805931067b841e6af11db382eChris Lattner void HandleOp(SDOperand Op); 141c7029805ef35ce9805931067b841e6af11db382eChris Lattner 142c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// LegalizeOp - We know that the specified value has a legal type. 143c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// Recursively ensure that the operands have legal types, then return the 144c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// result. 1453e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner SDOperand LegalizeOp(SDOperand O); 146c7029805ef35ce9805931067b841e6af11db382eChris Lattner 147c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// PromoteOp - Given an operation that produces a value in an invalid type, 148c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// promote it to compute the value into a larger type. The produced value 149c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// will have the correct bits for the low portion of the register, but no 150c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// guarantee is made about the top bits: it may be zero, sign-extended, or 151c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// garbage. 15203c8546ec57523970874917854a2fb77b1ff598eChris Lattner SDOperand PromoteOp(SDOperand O); 1533e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 154c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// ExpandOp - Expand the specified SDOperand into its two component pieces 155c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// Lo&Hi. Note that the Op MUST be an expanded type. As a result of this, 156c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// the LegalizeNodes map is filled in for any results that are not expanded, 157c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// the ExpandedNodes map is filled in for any results that are expanded, and 158c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// the Lo/Hi values are returned. This applies to integer types and Vector 159c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// types. 160c7029805ef35ce9805931067b841e6af11db382eChris Lattner void ExpandOp(SDOperand O, SDOperand &Lo, SDOperand &Hi); 161c7029805ef35ce9805931067b841e6af11db382eChris Lattner 162c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// SplitVectorOp - Given an operand of MVT::Vector type, break it down into 163c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// two smaller values of MVT::Vector type. 164c7029805ef35ce9805931067b841e6af11db382eChris Lattner void SplitVectorOp(SDOperand O, SDOperand &Lo, SDOperand &Hi); 165c7029805ef35ce9805931067b841e6af11db382eChris Lattner 166c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// PackVectorOp - Given an operand of MVT::Vector type, convert it into the 167c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// equivalent operation that returns a packed value (e.g. MVT::V4F32). When 168c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// this is called, we know that PackedVT is the right type for the result and 169c7029805ef35ce9805931067b841e6af11db382eChris Lattner /// we know that this type is legal for the target. 170c7029805ef35ce9805931067b841e6af11db382eChris Lattner SDOperand PackVectorOp(SDOperand O, MVT::ValueType PackedVT); 171c7029805ef35ce9805931067b841e6af11db382eChris Lattner 1724352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner /// isShuffleLegal - Return true if a vector shuffle is legal with the 1734352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner /// specified mask and type. Targets can specify exactly which masks they 1744352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner /// support and the code generator is tasked with not creating illegal masks. 1754352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner /// 1764352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner /// Note that this will also return true for shuffles that are promoted to a 1774352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner /// different type. 1784352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner /// 1794352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner /// If this is a legal shuffle, this method returns the (possibly promoted) 1804352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner /// build_vector Mask. If it's not a legal shuffle, it returns null. 1814352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner SDNode *isShuffleLegal(MVT::ValueType VT, SDOperand Mask) const; 1824352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner 183c9cf4f1a7573ac7e379efd6ad15d7bd0a84a097cChris Lattner bool LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest, 184c9cf4f1a7573ac7e379efd6ad15d7bd0a84a097cChris Lattner std::set<SDNode*> &NodesLeadingTo); 1856831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 186750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman void LegalizeSetCCOperands(SDOperand &LHS, SDOperand &RHS, SDOperand &CC); 187750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman 188ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner SDOperand CreateStackTemporary(MVT::ValueType VT); 189ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner 19047857812e29324a9d1560796a05b53d3a9217fd9Reid Spencer SDOperand ExpandLibCall(const char *Name, SDNode *Node, bool isSigned, 19177e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner SDOperand &Hi); 19277e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner SDOperand ExpandIntToFP(bool isSigned, MVT::ValueType DestTy, 19377e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner SDOperand Source); 194cad063f1a8ecda4fd556a733dc5eaa8a96acb80dChris Lattner 19535481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner SDOperand ExpandBIT_CONVERT(MVT::ValueType DestVT, SDOperand SrcOp); 196ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner SDOperand ExpandBUILD_VECTOR(SDNode *Node); 1974352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner SDOperand ExpandSCALAR_TO_VECTOR(SDNode *Node); 1986269ed125fc492d81dc5e3f48482816fc9d47f49Jim Laskey SDOperand ExpandLegalINT_TO_FP(bool isSigned, 1996269ed125fc492d81dc5e3f48482816fc9d47f49Jim Laskey SDOperand LegalOp, 2006269ed125fc492d81dc5e3f48482816fc9d47f49Jim Laskey MVT::ValueType DestVT); 2015a8441ea3fc145393d6274156bd05c4a006099eaNate Begeman SDOperand PromoteLegalINT_TO_FP(SDOperand LegalOp, MVT::ValueType DestVT, 2025a8441ea3fc145393d6274156bd05c4a006099eaNate Begeman bool isSigned); 2031618bebcf6f9cd19c4e05de3bfffda28c246bb12Chris Lattner SDOperand PromoteLegalFP_TO_INT(SDOperand LegalOp, MVT::ValueType DestVT, 2041618bebcf6f9cd19c4e05de3bfffda28c246bb12Chris Lattner bool isSigned); 20500b16889ab461b7ecef1c91ade101186b7f1fce2Jeff Cohen 206456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner SDOperand ExpandBSWAP(SDOperand Op); 207456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner SDOperand ExpandBitCount(unsigned Opc, SDOperand Op); 208e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner bool ExpandShift(unsigned Opc, SDOperand Op, SDOperand Amt, 209e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner SDOperand &Lo, SDOperand &Hi); 2105b359c6c4f052e41579ad7da9af37db4f54207d9Chris Lattner void ExpandShiftParts(unsigned NodeOp, SDOperand Op, SDOperand Amt, 2115b359c6c4f052e41579ad7da9af37db4f54207d9Chris Lattner SDOperand &Lo, SDOperand &Hi); 212b9fa3bc8f39bf1e8df48b85eae4563032dd20bfcChris Lattner 2131597221eace1c53ce5f84a7018397497d11a8393Chris Lattner SDOperand LowerVEXTRACT_VECTOR_ELT(SDOperand Op); 2144aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner SDOperand ExpandEXTRACT_VECTOR_ELT(SDOperand Op); 2151597221eace1c53ce5f84a7018397497d11a8393Chris Lattner 2163e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner SDOperand getIntPtrConstant(uint64_t Val) { 2173e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner return DAG.getConstant(Val, TLI.getPointerTy()); 2183e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 2193e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner}; 2203e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner} 2213e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 2224352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner/// isVectorShuffleLegal - Return true if a vector shuffle is legal with the 2234352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner/// specified mask and type. Targets can specify exactly which masks they 2244352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner/// support and the code generator is tasked with not creating illegal masks. 2254352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner/// 2264352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner/// Note that this will also return true for shuffles that are promoted to a 2274352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner/// different type. 2284352cc9e217e4482ad53f5a7b92c3543f569eb6eChris LattnerSDNode *SelectionDAGLegalize::isShuffleLegal(MVT::ValueType VT, 2294352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner SDOperand Mask) const { 2304352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE, VT)) { 2314352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner default: return 0; 2324352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner case TargetLowering::Legal: 2334352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner case TargetLowering::Custom: 2344352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner break; 2354352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner case TargetLowering::Promote: { 2364352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner // If this is promoted to a different type, convert the shuffle mask and 2374352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner // ask if it is legal in the promoted type! 2384352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner MVT::ValueType NVT = TLI.getTypeToPromoteTo(ISD::VECTOR_SHUFFLE, VT); 2394352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner 2404352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner // If we changed # elements, change the shuffle mask. 2414352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner unsigned NumEltsGrowth = 2424352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner MVT::getVectorNumElements(NVT) / MVT::getVectorNumElements(VT); 2434352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner assert(NumEltsGrowth && "Cannot promote to vector type with fewer elts!"); 2444352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner if (NumEltsGrowth > 1) { 2454352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner // Renumber the elements. 246bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner SmallVector<SDOperand, 8> Ops; 2474352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner for (unsigned i = 0, e = Mask.getNumOperands(); i != e; ++i) { 2484352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner SDOperand InOp = Mask.getOperand(i); 2494352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner for (unsigned j = 0; j != NumEltsGrowth; ++j) { 2504352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner if (InOp.getOpcode() == ISD::UNDEF) 2514352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner Ops.push_back(DAG.getNode(ISD::UNDEF, MVT::i32)); 2524352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner else { 2534352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner unsigned InEltNo = cast<ConstantSDNode>(InOp)->getValue(); 2544352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner Ops.push_back(DAG.getConstant(InEltNo*NumEltsGrowth+j, MVT::i32)); 2554352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner } 2564352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner } 2574352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner } 258bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner Mask = DAG.getNode(ISD::BUILD_VECTOR, NVT, &Ops[0], Ops.size()); 2594352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner } 2604352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner VT = NVT; 2614352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner break; 2624352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner } 2634352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner } 2644352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner return TLI.isShuffleMaskLegal(Mask, VT) ? Mask.Val : 0; 2654352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner} 2664352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner 267c7029805ef35ce9805931067b841e6af11db382eChris Lattner/// getScalarizedOpcode - Return the scalar opcode that corresponds to the 268c7029805ef35ce9805931067b841e6af11db382eChris Lattner/// specified vector opcode. 269b89175feffa7148c05d1d30a8e382b8d321edae5Chris Lattnerstatic unsigned getScalarizedOpcode(unsigned VecOp, MVT::ValueType VT) { 2705fbb5d2459a5410590f285250faa604576308a93Nate Begeman switch (VecOp) { 2715fbb5d2459a5410590f285250faa604576308a93Nate Begeman default: assert(0 && "Don't know how to scalarize this opcode!"); 2723e1ce5a44d3d59b2b9ca68a21261f0f487d69269Evan Cheng case ISD::VADD: return MVT::isInteger(VT) ? ISD::ADD : ISD::FADD; 2733e1ce5a44d3d59b2b9ca68a21261f0f487d69269Evan Cheng case ISD::VSUB: return MVT::isInteger(VT) ? ISD::SUB : ISD::FSUB; 2743e1ce5a44d3d59b2b9ca68a21261f0f487d69269Evan Cheng case ISD::VMUL: return MVT::isInteger(VT) ? ISD::MUL : ISD::FMUL; 2753e1ce5a44d3d59b2b9ca68a21261f0f487d69269Evan Cheng case ISD::VSDIV: return MVT::isInteger(VT) ? ISD::SDIV: ISD::FDIV; 2763e1ce5a44d3d59b2b9ca68a21261f0f487d69269Evan Cheng case ISD::VUDIV: return MVT::isInteger(VT) ? ISD::UDIV: ISD::FDIV; 2773e1ce5a44d3d59b2b9ca68a21261f0f487d69269Evan Cheng case ISD::VAND: return MVT::isInteger(VT) ? ISD::AND : 0; 2783e1ce5a44d3d59b2b9ca68a21261f0f487d69269Evan Cheng case ISD::VOR: return MVT::isInteger(VT) ? ISD::OR : 0; 2793e1ce5a44d3d59b2b9ca68a21261f0f487d69269Evan Cheng case ISD::VXOR: return MVT::isInteger(VT) ? ISD::XOR : 0; 2805fbb5d2459a5410590f285250faa604576308a93Nate Begeman } 2815fbb5d2459a5410590f285250faa604576308a93Nate Begeman} 2823e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 2839c32d3b798dc6caeebe6cea2effe80ca5e84e66eChris LattnerSelectionDAGLegalize::SelectionDAGLegalize(SelectionDAG &dag) 2849c32d3b798dc6caeebe6cea2effe80ca5e84e66eChris Lattner : TLI(dag.getTargetLoweringInfo()), DAG(dag), 2859c32d3b798dc6caeebe6cea2effe80ca5e84e66eChris Lattner ValueTypeActions(TLI.getValueTypeActions()) { 2866a648614e88586e85a36ceb5c1d3b84e4f55b458Nate Begeman assert(MVT::LAST_VALUETYPE <= 32 && 2873e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner "Too many value types for ValueTypeActions to hold!"); 2883e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner} 2893e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 29032fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner/// ComputeTopDownOrdering - Add the specified node to the Order list if it has 29132fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner/// not been visited yet and if all of its operands have already been visited. 29232fca00a23a9872c31999d054b4dd7c724276d9dChris Lattnerstatic void ComputeTopDownOrdering(SDNode *N, std::vector<SDNode*> &Order, 29332fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner std::map<SDNode*, unsigned> &Visited) { 29432fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner if (++Visited[N] != N->getNumOperands()) 29532fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner return; // Haven't visited all operands yet 29632fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner 29732fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner Order.push_back(N); 29832fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner 29932fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner if (N->hasOneUse()) { // Tail recurse in common case. 30032fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner ComputeTopDownOrdering(*N->use_begin(), Order, Visited); 30132fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner return; 30232fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner } 30332fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner 30432fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner // Now that we have N in, add anything that uses it if all of their operands 30532fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner // are now done. 30632fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner for (SDNode::use_iterator UI = N->use_begin(), E = N->use_end(); UI != E;++UI) 30732fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner ComputeTopDownOrdering(*UI, Order, Visited); 30832fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner} 30932fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner 3101618bebcf6f9cd19c4e05de3bfffda28c246bb12Chris Lattner 3113e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattnervoid SelectionDAGLegalize::LegalizeDAG() { 3126831a815999dde4cf801e2076e66b4943964daf2Chris Lattner LastCALLSEQ_END = DAG.getEntryNode(); 3136831a815999dde4cf801e2076e66b4943964daf2Chris Lattner IsLegalizingCall = false; 3146831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 315ab510a76d6fed412f2dbbb29b3e123eef34f9c0aChris Lattner // The legalize process is inherently a bottom-up recursive process (users 316ab510a76d6fed412f2dbbb29b3e123eef34f9c0aChris Lattner // legalize their uses before themselves). Given infinite stack space, we 317ab510a76d6fed412f2dbbb29b3e123eef34f9c0aChris Lattner // could just start legalizing on the root and traverse the whole graph. In 318ab510a76d6fed412f2dbbb29b3e123eef34f9c0aChris Lattner // practice however, this causes us to run out of stack space on large basic 31932fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner // blocks. To avoid this problem, compute an ordering of the nodes where each 32032fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner // node is only legalized after all of its operands are legalized. 32132fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner std::map<SDNode*, unsigned> Visited; 32232fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner std::vector<SDNode*> Order; 323ab510a76d6fed412f2dbbb29b3e123eef34f9c0aChris Lattner 32432fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner // Compute ordering from all of the leaves in the graphs, those (like the 32532fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner // entry node) that have no operands. 32632fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(), 32732fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner E = DAG.allnodes_end(); I != E; ++I) { 328de202b3cda00f17ba2c047be7270b51f9585a413Chris Lattner if (I->getNumOperands() == 0) { 329de202b3cda00f17ba2c047be7270b51f9585a413Chris Lattner Visited[I] = 0 - 1U; 330de202b3cda00f17ba2c047be7270b51f9585a413Chris Lattner ComputeTopDownOrdering(I, Order, Visited); 331ab510a76d6fed412f2dbbb29b3e123eef34f9c0aChris Lattner } 332ab510a76d6fed412f2dbbb29b3e123eef34f9c0aChris Lattner } 333ab510a76d6fed412f2dbbb29b3e123eef34f9c0aChris Lattner 334de202b3cda00f17ba2c047be7270b51f9585a413Chris Lattner assert(Order.size() == Visited.size() && 335de202b3cda00f17ba2c047be7270b51f9585a413Chris Lattner Order.size() == 336de202b3cda00f17ba2c047be7270b51f9585a413Chris Lattner (unsigned)std::distance(DAG.allnodes_begin(), DAG.allnodes_end()) && 33732fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner "Error: DAG is cyclic!"); 33832fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner Visited.clear(); 339ab510a76d6fed412f2dbbb29b3e123eef34f9c0aChris Lattner 340c7029805ef35ce9805931067b841e6af11db382eChris Lattner for (unsigned i = 0, e = Order.size(); i != e; ++i) 341c7029805ef35ce9805931067b841e6af11db382eChris Lattner HandleOp(SDOperand(Order[i], 0)); 34232fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner 34332fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner // Finally, it's possible the root changed. Get the new root. 3443e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner SDOperand OldRoot = DAG.getRoot(); 34532fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner assert(LegalizedNodes.count(OldRoot) && "Root didn't get legalized?"); 34632fca00a23a9872c31999d054b4dd7c724276d9dChris Lattner DAG.setRoot(LegalizedNodes[OldRoot]); 3473e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 3483e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner ExpandedNodes.clear(); 3493e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner LegalizedNodes.clear(); 35071c42a0190300a8903aaea80467b88f15f327ea9Chris Lattner PromotedNodes.clear(); 351c7029805ef35ce9805931067b841e6af11db382eChris Lattner SplitNodes.clear(); 352c7029805ef35ce9805931067b841e6af11db382eChris Lattner PackedNodes.clear(); 3533e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 3543e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner // Remove dead nodes now. 355190a418bf6b49a4ef1c1980229a2f0d516e8a2cdChris Lattner DAG.RemoveDeadNodes(); 3563e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner} 3573e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 3586831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 3596831a815999dde4cf801e2076e66b4943964daf2Chris Lattner/// FindCallEndFromCallStart - Given a chained node that is part of a call 3606831a815999dde4cf801e2076e66b4943964daf2Chris Lattner/// sequence, find the CALLSEQ_END node that terminates the call sequence. 3616831a815999dde4cf801e2076e66b4943964daf2Chris Lattnerstatic SDNode *FindCallEndFromCallStart(SDNode *Node) { 3626831a815999dde4cf801e2076e66b4943964daf2Chris Lattner if (Node->getOpcode() == ISD::CALLSEQ_END) 3636831a815999dde4cf801e2076e66b4943964daf2Chris Lattner return Node; 3646831a815999dde4cf801e2076e66b4943964daf2Chris Lattner if (Node->use_empty()) 3656831a815999dde4cf801e2076e66b4943964daf2Chris Lattner return 0; // No CallSeqEnd 3666831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 3676831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // The chain is usually at the end. 3686831a815999dde4cf801e2076e66b4943964daf2Chris Lattner SDOperand TheChain(Node, Node->getNumValues()-1); 3696831a815999dde4cf801e2076e66b4943964daf2Chris Lattner if (TheChain.getValueType() != MVT::Other) { 3706831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Sometimes it's at the beginning. 3716831a815999dde4cf801e2076e66b4943964daf2Chris Lattner TheChain = SDOperand(Node, 0); 3726831a815999dde4cf801e2076e66b4943964daf2Chris Lattner if (TheChain.getValueType() != MVT::Other) { 3736831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Otherwise, hunt for it. 3746831a815999dde4cf801e2076e66b4943964daf2Chris Lattner for (unsigned i = 1, e = Node->getNumValues(); i != e; ++i) 3756831a815999dde4cf801e2076e66b4943964daf2Chris Lattner if (Node->getValueType(i) == MVT::Other) { 3766831a815999dde4cf801e2076e66b4943964daf2Chris Lattner TheChain = SDOperand(Node, i); 3776831a815999dde4cf801e2076e66b4943964daf2Chris Lattner break; 3786831a815999dde4cf801e2076e66b4943964daf2Chris Lattner } 3796831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 3806831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Otherwise, we walked into a node without a chain. 3816831a815999dde4cf801e2076e66b4943964daf2Chris Lattner if (TheChain.getValueType() != MVT::Other) 3826831a815999dde4cf801e2076e66b4943964daf2Chris Lattner return 0; 3836831a815999dde4cf801e2076e66b4943964daf2Chris Lattner } 3846831a815999dde4cf801e2076e66b4943964daf2Chris Lattner } 3856831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 3866831a815999dde4cf801e2076e66b4943964daf2Chris Lattner for (SDNode::use_iterator UI = Node->use_begin(), 3876831a815999dde4cf801e2076e66b4943964daf2Chris Lattner E = Node->use_end(); UI != E; ++UI) { 3886831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 3896831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Make sure to only follow users of our token chain. 3906831a815999dde4cf801e2076e66b4943964daf2Chris Lattner SDNode *User = *UI; 3916831a815999dde4cf801e2076e66b4943964daf2Chris Lattner for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i) 3926831a815999dde4cf801e2076e66b4943964daf2Chris Lattner if (User->getOperand(i) == TheChain) 3936831a815999dde4cf801e2076e66b4943964daf2Chris Lattner if (SDNode *Result = FindCallEndFromCallStart(User)) 3946831a815999dde4cf801e2076e66b4943964daf2Chris Lattner return Result; 3956831a815999dde4cf801e2076e66b4943964daf2Chris Lattner } 3966831a815999dde4cf801e2076e66b4943964daf2Chris Lattner return 0; 3976831a815999dde4cf801e2076e66b4943964daf2Chris Lattner} 3986831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 3996831a815999dde4cf801e2076e66b4943964daf2Chris Lattner/// FindCallStartFromCallEnd - Given a chained node that is part of a call 4006831a815999dde4cf801e2076e66b4943964daf2Chris Lattner/// sequence, find the CALLSEQ_START node that initiates the call sequence. 4016831a815999dde4cf801e2076e66b4943964daf2Chris Lattnerstatic SDNode *FindCallStartFromCallEnd(SDNode *Node) { 4026831a815999dde4cf801e2076e66b4943964daf2Chris Lattner assert(Node && "Didn't find callseq_start for a call??"); 4036831a815999dde4cf801e2076e66b4943964daf2Chris Lattner if (Node->getOpcode() == ISD::CALLSEQ_START) return Node; 4046831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 4056831a815999dde4cf801e2076e66b4943964daf2Chris Lattner assert(Node->getOperand(0).getValueType() == MVT::Other && 4066831a815999dde4cf801e2076e66b4943964daf2Chris Lattner "Node doesn't have a token chain argument!"); 4076831a815999dde4cf801e2076e66b4943964daf2Chris Lattner return FindCallStartFromCallEnd(Node->getOperand(0).Val); 4086831a815999dde4cf801e2076e66b4943964daf2Chris Lattner} 4096831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 4106831a815999dde4cf801e2076e66b4943964daf2Chris Lattner/// LegalizeAllNodesNotLeadingTo - Recursively walk the uses of N, looking to 4116831a815999dde4cf801e2076e66b4943964daf2Chris Lattner/// see if any uses can reach Dest. If no dest operands can get to dest, 4126831a815999dde4cf801e2076e66b4943964daf2Chris Lattner/// legalize them, legalize ourself, and return false, otherwise, return true. 413c9cf4f1a7573ac7e379efd6ad15d7bd0a84a097cChris Lattner/// 414c9cf4f1a7573ac7e379efd6ad15d7bd0a84a097cChris Lattner/// Keep track of the nodes we fine that actually do lead to Dest in 415c9cf4f1a7573ac7e379efd6ad15d7bd0a84a097cChris Lattner/// NodesLeadingTo. This avoids retraversing them exponential number of times. 416c9cf4f1a7573ac7e379efd6ad15d7bd0a84a097cChris Lattner/// 417c9cf4f1a7573ac7e379efd6ad15d7bd0a84a097cChris Lattnerbool SelectionDAGLegalize::LegalizeAllNodesNotLeadingTo(SDNode *N, SDNode *Dest, 418c9cf4f1a7573ac7e379efd6ad15d7bd0a84a097cChris Lattner std::set<SDNode*> &NodesLeadingTo) { 4196831a815999dde4cf801e2076e66b4943964daf2Chris Lattner if (N == Dest) return true; // N certainly leads to Dest :) 4206831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 421c9cf4f1a7573ac7e379efd6ad15d7bd0a84a097cChris Lattner // If we've already processed this node and it does lead to Dest, there is no 422c9cf4f1a7573ac7e379efd6ad15d7bd0a84a097cChris Lattner // need to reprocess it. 423c9cf4f1a7573ac7e379efd6ad15d7bd0a84a097cChris Lattner if (NodesLeadingTo.count(N)) return true; 424c9cf4f1a7573ac7e379efd6ad15d7bd0a84a097cChris Lattner 4256831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // If the first result of this node has been already legalized, then it cannot 4266831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // reach N. 4276831a815999dde4cf801e2076e66b4943964daf2Chris Lattner switch (getTypeAction(N->getValueType(0))) { 4286831a815999dde4cf801e2076e66b4943964daf2Chris Lattner case Legal: 4296831a815999dde4cf801e2076e66b4943964daf2Chris Lattner if (LegalizedNodes.count(SDOperand(N, 0))) return false; 4306831a815999dde4cf801e2076e66b4943964daf2Chris Lattner break; 4316831a815999dde4cf801e2076e66b4943964daf2Chris Lattner case Promote: 4326831a815999dde4cf801e2076e66b4943964daf2Chris Lattner if (PromotedNodes.count(SDOperand(N, 0))) return false; 4336831a815999dde4cf801e2076e66b4943964daf2Chris Lattner break; 4346831a815999dde4cf801e2076e66b4943964daf2Chris Lattner case Expand: 4356831a815999dde4cf801e2076e66b4943964daf2Chris Lattner if (ExpandedNodes.count(SDOperand(N, 0))) return false; 4366831a815999dde4cf801e2076e66b4943964daf2Chris Lattner break; 4376831a815999dde4cf801e2076e66b4943964daf2Chris Lattner } 4386831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 4396831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Okay, this node has not already been legalized. Check and legalize all 4406831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // operands. If none lead to Dest, then we can legalize this node. 4416831a815999dde4cf801e2076e66b4943964daf2Chris Lattner bool OperandsLeadToDest = false; 4426831a815999dde4cf801e2076e66b4943964daf2Chris Lattner for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) 4436831a815999dde4cf801e2076e66b4943964daf2Chris Lattner OperandsLeadToDest |= // If an operand leads to Dest, so do we. 444c9cf4f1a7573ac7e379efd6ad15d7bd0a84a097cChris Lattner LegalizeAllNodesNotLeadingTo(N->getOperand(i).Val, Dest, NodesLeadingTo); 4456831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 446c9cf4f1a7573ac7e379efd6ad15d7bd0a84a097cChris Lattner if (OperandsLeadToDest) { 447c9cf4f1a7573ac7e379efd6ad15d7bd0a84a097cChris Lattner NodesLeadingTo.insert(N); 448c9cf4f1a7573ac7e379efd6ad15d7bd0a84a097cChris Lattner return true; 449c9cf4f1a7573ac7e379efd6ad15d7bd0a84a097cChris Lattner } 4506831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 4516831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Okay, this node looks safe, legalize it and return false. 45280edfb3af5ed214c5cd7797b37cb3bb024e98cc6Chris Lattner HandleOp(SDOperand(N, 0)); 4536831a815999dde4cf801e2076e66b4943964daf2Chris Lattner return false; 4546831a815999dde4cf801e2076e66b4943964daf2Chris Lattner} 4556831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 456c7029805ef35ce9805931067b841e6af11db382eChris Lattner/// HandleOp - Legalize, Promote, Expand or Pack the specified operand as 457c7029805ef35ce9805931067b841e6af11db382eChris Lattner/// appropriate for its type. 458c7029805ef35ce9805931067b841e6af11db382eChris Lattnervoid SelectionDAGLegalize::HandleOp(SDOperand Op) { 459c7029805ef35ce9805931067b841e6af11db382eChris Lattner switch (getTypeAction(Op.getValueType())) { 460c7029805ef35ce9805931067b841e6af11db382eChris Lattner default: assert(0 && "Bad type action!"); 461c7029805ef35ce9805931067b841e6af11db382eChris Lattner case Legal: LegalizeOp(Op); break; 462c7029805ef35ce9805931067b841e6af11db382eChris Lattner case Promote: PromoteOp(Op); break; 463c7029805ef35ce9805931067b841e6af11db382eChris Lattner case Expand: 464c7029805ef35ce9805931067b841e6af11db382eChris Lattner if (Op.getValueType() != MVT::Vector) { 465c7029805ef35ce9805931067b841e6af11db382eChris Lattner SDOperand X, Y; 466c7029805ef35ce9805931067b841e6af11db382eChris Lattner ExpandOp(Op, X, Y); 467c7029805ef35ce9805931067b841e6af11db382eChris Lattner } else { 468c7029805ef35ce9805931067b841e6af11db382eChris Lattner SDNode *N = Op.Val; 469c7029805ef35ce9805931067b841e6af11db382eChris Lattner unsigned NumOps = N->getNumOperands(); 470c7029805ef35ce9805931067b841e6af11db382eChris Lattner unsigned NumElements = 471c7029805ef35ce9805931067b841e6af11db382eChris Lattner cast<ConstantSDNode>(N->getOperand(NumOps-2))->getValue(); 472c7029805ef35ce9805931067b841e6af11db382eChris Lattner MVT::ValueType EVT = cast<VTSDNode>(N->getOperand(NumOps-1))->getVT(); 473c7029805ef35ce9805931067b841e6af11db382eChris Lattner MVT::ValueType PackedVT = getVectorType(EVT, NumElements); 474c7029805ef35ce9805931067b841e6af11db382eChris Lattner if (PackedVT != MVT::Other && TLI.isTypeLegal(PackedVT)) { 475c7029805ef35ce9805931067b841e6af11db382eChris Lattner // In the common case, this is a legal vector type, convert it to the 476c7029805ef35ce9805931067b841e6af11db382eChris Lattner // packed operation and type now. 477c7029805ef35ce9805931067b841e6af11db382eChris Lattner PackVectorOp(Op, PackedVT); 478c7029805ef35ce9805931067b841e6af11db382eChris Lattner } else if (NumElements == 1) { 479c7029805ef35ce9805931067b841e6af11db382eChris Lattner // Otherwise, if this is a single element vector, convert it to a 480c7029805ef35ce9805931067b841e6af11db382eChris Lattner // scalar operation. 481c7029805ef35ce9805931067b841e6af11db382eChris Lattner PackVectorOp(Op, EVT); 482c7029805ef35ce9805931067b841e6af11db382eChris Lattner } else { 483c7029805ef35ce9805931067b841e6af11db382eChris Lattner // Otherwise, this is a multiple element vector that isn't supported. 484c7029805ef35ce9805931067b841e6af11db382eChris Lattner // Split it in half and legalize both parts. 485c7029805ef35ce9805931067b841e6af11db382eChris Lattner SDOperand X, Y; 4864794a6b6a09e3440438cd653ec09cf0c2e45be1cChris Lattner SplitVectorOp(Op, X, Y); 487c7029805ef35ce9805931067b841e6af11db382eChris Lattner } 488c7029805ef35ce9805931067b841e6af11db382eChris Lattner } 489c7029805ef35ce9805931067b841e6af11db382eChris Lattner break; 490c7029805ef35ce9805931067b841e6af11db382eChris Lattner } 491c7029805ef35ce9805931067b841e6af11db382eChris Lattner} 4926831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 4939f87788040786b1bc6530763e4cf7e105bfb2924Evan Cheng/// ExpandConstantFP - Expands the ConstantFP node to an integer constant or 4949f87788040786b1bc6530763e4cf7e105bfb2924Evan Cheng/// a load from the constant pool. 4959f87788040786b1bc6530763e4cf7e105bfb2924Evan Chengstatic SDOperand ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP, 496279101eb1ac61e2d5b83d5bdcc5be56e710d2cd7Evan Cheng SelectionDAG &DAG, TargetLowering &TLI) { 497004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng bool Extend = false; 498004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng 499004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng // If a FP immediate is precise when represented as a float and if the 500004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng // target can do an extending load from float to double, we put it into 501004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng // the constant pool as a float, even if it's is statically typed as a 502004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng // double. 503004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng MVT::ValueType VT = CFP->getValueType(0); 504004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng bool isDouble = VT == MVT::f64; 505004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng ConstantFP *LLVMC = ConstantFP::get(isDouble ? Type::DoubleTy : 506004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng Type::FloatTy, CFP->getValue()); 5079f87788040786b1bc6530763e4cf7e105bfb2924Evan Cheng if (!UseCP) { 508279101eb1ac61e2d5b83d5bdcc5be56e710d2cd7Evan Cheng double Val = LLVMC->getValue(); 509279101eb1ac61e2d5b83d5bdcc5be56e710d2cd7Evan Cheng return isDouble 510279101eb1ac61e2d5b83d5bdcc5be56e710d2cd7Evan Cheng ? DAG.getConstant(DoubleToBits(Val), MVT::i64) 511279101eb1ac61e2d5b83d5bdcc5be56e710d2cd7Evan Cheng : DAG.getConstant(FloatToBits(Val), MVT::i32); 512279101eb1ac61e2d5b83d5bdcc5be56e710d2cd7Evan Cheng } 513279101eb1ac61e2d5b83d5bdcc5be56e710d2cd7Evan Cheng 514004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng if (isDouble && CFP->isExactlyValue((float)CFP->getValue()) && 515004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng // Only do this if the target has a native EXTLOAD instruction from f32. 516004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng TLI.isLoadXLegal(ISD::EXTLOAD, MVT::f32)) { 517004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng LLVMC = cast<ConstantFP>(ConstantExpr::getFPTrunc(LLVMC,Type::FloatTy)); 518004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng VT = MVT::f32; 519004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng Extend = true; 520004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng } 521004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng 522004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng SDOperand CPIdx = DAG.getConstantPool(LLVMC, TLI.getPointerTy()); 523004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng if (Extend) { 524004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng return DAG.getExtLoad(ISD::EXTLOAD, MVT::f64, DAG.getEntryNode(), 525004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng CPIdx, NULL, 0, MVT::f32); 526004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng } else { 527004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng return DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, NULL, 0); 528004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng } 529004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng} 530004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng 5316831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 532912095becac923ff614d7b07728eb345ada67765Evan Cheng/// ExpandFCOPYSIGNToBitwiseOps - Expands fcopysign to a series of bitwise 533912095becac923ff614d7b07728eb345ada67765Evan Cheng/// operations. 534912095becac923ff614d7b07728eb345ada67765Evan Chengstatic 535912095becac923ff614d7b07728eb345ada67765Evan ChengSDOperand ExpandFCOPYSIGNToBitwiseOps(SDNode *Node, MVT::ValueType NVT, 536912095becac923ff614d7b07728eb345ada67765Evan Cheng SelectionDAG &DAG, TargetLowering &TLI) { 537068c5f47ea9243b353a49ca7eb07fac0cb32f1eeEvan Cheng MVT::ValueType VT = Node->getValueType(0); 538912095becac923ff614d7b07728eb345ada67765Evan Cheng MVT::ValueType SrcVT = Node->getOperand(1).getValueType(); 539912095becac923ff614d7b07728eb345ada67765Evan Cheng MVT::ValueType SrcNVT = (SrcVT == MVT::f64) ? MVT::i64 : MVT::i32; 540068c5f47ea9243b353a49ca7eb07fac0cb32f1eeEvan Cheng 541912095becac923ff614d7b07728eb345ada67765Evan Cheng // First get the sign bit of second operand. 542068c5f47ea9243b353a49ca7eb07fac0cb32f1eeEvan Cheng SDOperand Mask1 = (SrcVT == MVT::f64) 543912095becac923ff614d7b07728eb345ada67765Evan Cheng ? DAG.getConstantFP(BitsToDouble(1ULL << 63), SrcVT) 544912095becac923ff614d7b07728eb345ada67765Evan Cheng : DAG.getConstantFP(BitsToFloat(1U << 31), SrcVT); 545068c5f47ea9243b353a49ca7eb07fac0cb32f1eeEvan Cheng Mask1 = DAG.getNode(ISD::BIT_CONVERT, SrcNVT, Mask1); 546912095becac923ff614d7b07728eb345ada67765Evan Cheng SDOperand SignBit= DAG.getNode(ISD::BIT_CONVERT, SrcNVT, Node->getOperand(1)); 547068c5f47ea9243b353a49ca7eb07fac0cb32f1eeEvan Cheng SignBit = DAG.getNode(ISD::AND, SrcNVT, SignBit, Mask1); 548912095becac923ff614d7b07728eb345ada67765Evan Cheng // Shift right or sign-extend it if the two operands have different types. 549912095becac923ff614d7b07728eb345ada67765Evan Cheng int SizeDiff = MVT::getSizeInBits(SrcNVT) - MVT::getSizeInBits(NVT); 550912095becac923ff614d7b07728eb345ada67765Evan Cheng if (SizeDiff > 0) { 551912095becac923ff614d7b07728eb345ada67765Evan Cheng SignBit = DAG.getNode(ISD::SRL, SrcNVT, SignBit, 552912095becac923ff614d7b07728eb345ada67765Evan Cheng DAG.getConstant(SizeDiff, TLI.getShiftAmountTy())); 553912095becac923ff614d7b07728eb345ada67765Evan Cheng SignBit = DAG.getNode(ISD::TRUNCATE, NVT, SignBit); 554912095becac923ff614d7b07728eb345ada67765Evan Cheng } else if (SizeDiff < 0) 555912095becac923ff614d7b07728eb345ada67765Evan Cheng SignBit = DAG.getNode(ISD::SIGN_EXTEND, NVT, SignBit); 556068c5f47ea9243b353a49ca7eb07fac0cb32f1eeEvan Cheng 557068c5f47ea9243b353a49ca7eb07fac0cb32f1eeEvan Cheng // Clear the sign bit of first operand. 558068c5f47ea9243b353a49ca7eb07fac0cb32f1eeEvan Cheng SDOperand Mask2 = (VT == MVT::f64) 559068c5f47ea9243b353a49ca7eb07fac0cb32f1eeEvan Cheng ? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT) 560068c5f47ea9243b353a49ca7eb07fac0cb32f1eeEvan Cheng : DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT); 561068c5f47ea9243b353a49ca7eb07fac0cb32f1eeEvan Cheng Mask2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask2); 562912095becac923ff614d7b07728eb345ada67765Evan Cheng SDOperand Result = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); 563068c5f47ea9243b353a49ca7eb07fac0cb32f1eeEvan Cheng Result = DAG.getNode(ISD::AND, NVT, Result, Mask2); 564068c5f47ea9243b353a49ca7eb07fac0cb32f1eeEvan Cheng 565068c5f47ea9243b353a49ca7eb07fac0cb32f1eeEvan Cheng // Or the value with the sign bit. 566912095becac923ff614d7b07728eb345ada67765Evan Cheng Result = DAG.getNode(ISD::OR, NVT, Result, SignBit); 567912095becac923ff614d7b07728eb345ada67765Evan Cheng return Result; 568912095becac923ff614d7b07728eb345ada67765Evan Cheng} 569912095becac923ff614d7b07728eb345ada67765Evan Cheng 570912095becac923ff614d7b07728eb345ada67765Evan Cheng 571c7029805ef35ce9805931067b841e6af11db382eChris Lattner/// LegalizeOp - We know that the specified value has a legal type. 572c7029805ef35ce9805931067b841e6af11db382eChris Lattner/// Recursively ensure that the operands have legal types, then return the 573c7029805ef35ce9805931067b841e6af11db382eChris Lattner/// result. 5743e928bbd6153eb08641cbd0ad7d8487378a8b12aChris LattnerSDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) { 575c9c60f6429416d362c2131b14d097ce0a9ac9599Chris Lattner assert(isTypeLegal(Op.getValueType()) && 576e3304a3d24afc952d3cb415d1b504d973573c5c5Chris Lattner "Caller should expand or promote operands that are not legal!"); 57745982dad53cd184fe8947a1b0206b0b16964f359Chris Lattner SDNode *Node = Op.Val; 578e3304a3d24afc952d3cb415d1b504d973573c5c5Chris Lattner 5793e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner // If this operation defines any values that cannot be represented in a 580e3304a3d24afc952d3cb415d1b504d973573c5c5Chris Lattner // register on this target, make sure to expand or promote them. 58145982dad53cd184fe8947a1b0206b0b16964f359Chris Lattner if (Node->getNumValues() > 1) { 58245982dad53cd184fe8947a1b0206b0b16964f359Chris Lattner for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) 583c7029805ef35ce9805931067b841e6af11db382eChris Lattner if (getTypeAction(Node->getValueType(i)) != Legal) { 584c7029805ef35ce9805931067b841e6af11db382eChris Lattner HandleOp(Op.getValue(i)); 5853e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner assert(LegalizedNodes.count(Op) && 586c7029805ef35ce9805931067b841e6af11db382eChris Lattner "Handling didn't add legal operands!"); 58703c8546ec57523970874917854a2fb77b1ff598eChris Lattner return LegalizedNodes[Op]; 5883e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 5893e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 5903e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 59145982dad53cd184fe8947a1b0206b0b16964f359Chris Lattner // Note that LegalizeOp may be reentered even from single-use nodes, which 59245982dad53cd184fe8947a1b0206b0b16964f359Chris Lattner // means that we always must cache transformed nodes. 593e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner std::map<SDOperand, SDOperand>::iterator I = LegalizedNodes.find(Op); 594e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner if (I != LegalizedNodes.end()) return I->second; 5953e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 5969373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman SDOperand Tmp1, Tmp2, Tmp3, Tmp4; 5973e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner SDOperand Result = Op; 598456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner bool isCustom = false; 599456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner 6003e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner switch (Node->getOpcode()) { 601948c1b1cda280c6428dbeaa03a6c2c559dbb93f4Chris Lattner case ISD::FrameIndex: 602948c1b1cda280c6428dbeaa03a6c2c559dbb93f4Chris Lattner case ISD::EntryToken: 603948c1b1cda280c6428dbeaa03a6c2c559dbb93f4Chris Lattner case ISD::Register: 604948c1b1cda280c6428dbeaa03a6c2c559dbb93f4Chris Lattner case ISD::BasicBlock: 605948c1b1cda280c6428dbeaa03a6c2c559dbb93f4Chris Lattner case ISD::TargetFrameIndex: 60637efe6764568a3829fee26aba532283131d1a104Nate Begeman case ISD::TargetJumpTable: 607948c1b1cda280c6428dbeaa03a6c2c559dbb93f4Chris Lattner case ISD::TargetConstant: 6083181a771ff5b2090b7ed55f9b18a684ea8fe625aChris Lattner case ISD::TargetConstantFP: 609948c1b1cda280c6428dbeaa03a6c2c559dbb93f4Chris Lattner case ISD::TargetConstantPool: 610948c1b1cda280c6428dbeaa03a6c2c559dbb93f4Chris Lattner case ISD::TargetGlobalAddress: 611948c1b1cda280c6428dbeaa03a6c2c559dbb93f4Chris Lattner case ISD::TargetExternalSymbol: 612948c1b1cda280c6428dbeaa03a6c2c559dbb93f4Chris Lattner case ISD::VALUETYPE: 613948c1b1cda280c6428dbeaa03a6c2c559dbb93f4Chris Lattner case ISD::SRCVALUE: 614948c1b1cda280c6428dbeaa03a6c2c559dbb93f4Chris Lattner case ISD::STRING: 615948c1b1cda280c6428dbeaa03a6c2c559dbb93f4Chris Lattner case ISD::CONDCODE: 61682c3d8f81ab20dc7571f29ffc46a5bb1b7ed8323Andrew Lenharth case ISD::GLOBAL_OFFSET_TABLE: 617948c1b1cda280c6428dbeaa03a6c2c559dbb93f4Chris Lattner // Primitives must all be legal. 618948c1b1cda280c6428dbeaa03a6c2c559dbb93f4Chris Lattner assert(TLI.isOperationLegal(Node->getValueType(0), Node->getValueType(0)) && 619948c1b1cda280c6428dbeaa03a6c2c559dbb93f4Chris Lattner "This must be legal!"); 620948c1b1cda280c6428dbeaa03a6c2c559dbb93f4Chris Lattner break; 6213e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner default: 622d73cc5d0585e86bf6d350ab9fd9caf85bdfc8b52Chris Lattner if (Node->getOpcode() >= ISD::BUILTIN_OP_END) { 623d73cc5d0585e86bf6d350ab9fd9caf85bdfc8b52Chris Lattner // If this is a target node, legalize it by legalizing the operands then 624d73cc5d0585e86bf6d350ab9fd9caf85bdfc8b52Chris Lattner // passing it through. 625f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner SmallVector<SDOperand, 8> Ops; 626c5d7d7c715f7b7a4eeea1ceaafefc3d1d6df2addChris Lattner for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) 627d73cc5d0585e86bf6d350ab9fd9caf85bdfc8b52Chris Lattner Ops.push_back(LegalizeOp(Node->getOperand(i))); 628c5d7d7c715f7b7a4eeea1ceaafefc3d1d6df2addChris Lattner 629f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner Result = DAG.UpdateNodeOperands(Result.getValue(0), &Ops[0], Ops.size()); 630d73cc5d0585e86bf6d350ab9fd9caf85bdfc8b52Chris Lattner 631d73cc5d0585e86bf6d350ab9fd9caf85bdfc8b52Chris Lattner for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) 632d73cc5d0585e86bf6d350ab9fd9caf85bdfc8b52Chris Lattner AddLegalizedOperand(Op.getValue(i), Result.getValue(i)); 633d73cc5d0585e86bf6d350ab9fd9caf85bdfc8b52Chris Lattner return Result.getValue(Op.ResNo); 634d73cc5d0585e86bf6d350ab9fd9caf85bdfc8b52Chris Lattner } 635d73cc5d0585e86bf6d350ab9fd9caf85bdfc8b52Chris Lattner // Otherwise this is an unhandled builtin node. splat. 636e37fe9b3a1cadceb42ac27fa0718f5a10ea2f0e6Jim Laskey#ifndef NDEBUG 637832171cb9724d2d31c8dfb73172e2be8f6dd13eeBill Wendling cerr << "NODE: "; Node->dump(); cerr << "\n"; 638e37fe9b3a1cadceb42ac27fa0718f5a10ea2f0e6Jim Laskey#endif 6393e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner assert(0 && "Do not know how to legalize this operator!"); 6403e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner abort(); 6413e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::GlobalAddress: 64203c0cf822e9a57109d1b4e6a2705d68852c93e1dChris Lattner case ISD::ExternalSymbol: 64337efe6764568a3829fee26aba532283131d1a104Nate Begeman case ISD::ConstantPool: 64437efe6764568a3829fee26aba532283131d1a104Nate Begeman case ISD::JumpTable: // Nothing to do. 6450c8fbe33a4bdf7c60e0cfd5a9c86499c817d9f1aChris Lattner switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { 6460c8fbe33a4bdf7c60e0cfd5a9c86499c817d9f1aChris Lattner default: assert(0 && "This action is not supported yet!"); 647948c1b1cda280c6428dbeaa03a6c2c559dbb93f4Chris Lattner case TargetLowering::Custom: 648948c1b1cda280c6428dbeaa03a6c2c559dbb93f4Chris Lattner Tmp1 = TLI.LowerOperation(Op, DAG); 649948c1b1cda280c6428dbeaa03a6c2c559dbb93f4Chris Lattner if (Tmp1.Val) Result = Tmp1; 650948c1b1cda280c6428dbeaa03a6c2c559dbb93f4Chris Lattner // FALLTHROUGH if the target doesn't want to lower this op after all. 6510c8fbe33a4bdf7c60e0cfd5a9c86499c817d9f1aChris Lattner case TargetLowering::Legal: 6520c8fbe33a4bdf7c60e0cfd5a9c86499c817d9f1aChris Lattner break; 6530c8fbe33a4bdf7c60e0cfd5a9c86499c817d9f1aChris Lattner } 6543e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 65508951a32fbc1de3ec3746e14109a74ca506ca251Chris Lattner case ISD::AssertSext: 65608951a32fbc1de3ec3746e14109a74ca506ca251Chris Lattner case ISD::AssertZext: 65708951a32fbc1de3ec3746e14109a74ca506ca251Chris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); 658c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); 65908951a32fbc1de3ec3746e14109a74ca506ca251Chris Lattner break; 660308575be66ec3870d27b19df044fda18448feb41Chris Lattner case ISD::MERGE_VALUES: 661c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner // Legalize eliminates MERGE_VALUES nodes. 662456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Result = Node->getOperand(Op.ResNo); 663456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner break; 66469a52155d2eff066b49dbac385113002fd9dba14Chris Lattner case ISD::CopyFromReg: 66569a52155d2eff066b49dbac385113002fd9dba14Chris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); 6667310fb11f2a074069bf9ec3fc169c742ac48d32bChris Lattner Result = Op.getValue(0); 667f1a47c3371ecd5bb449f39736a36ebbebd4e9e14Chris Lattner if (Node->getNumValues() == 2) { 668c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); 6697310fb11f2a074069bf9ec3fc169c742ac48d32bChris Lattner } else { 670f1a47c3371ecd5bb449f39736a36ebbebd4e9e14Chris Lattner assert(Node->getNumValues() == 3 && "Invalid copyfromreg!"); 671c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner if (Node->getNumOperands() == 3) { 672f1a47c3371ecd5bb449f39736a36ebbebd4e9e14Chris Lattner Tmp2 = LegalizeOp(Node->getOperand(2)); 673c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2); 674c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner } else { 675c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); 676c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner } 6777310fb11f2a074069bf9ec3fc169c742ac48d32bChris Lattner AddLegalizedOperand(Op.getValue(2), Result.getValue(2)); 6787310fb11f2a074069bf9ec3fc169c742ac48d32bChris Lattner } 67913c184de29c09294ed63b01ac43e1b46c049278eChris Lattner // Since CopyFromReg produces two values, make sure to remember that we 68013c184de29c09294ed63b01ac43e1b46c049278eChris Lattner // legalized both of them. 68113c184de29c09294ed63b01ac43e1b46c049278eChris Lattner AddLegalizedOperand(Op.getValue(0), Result); 68213c184de29c09294ed63b01ac43e1b46c049278eChris Lattner AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); 68313c184de29c09294ed63b01ac43e1b46c049278eChris Lattner return Result.getValue(Op.ResNo); 684fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman case ISD::UNDEF: { 685fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman MVT::ValueType VT = Op.getValueType(); 686fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman switch (TLI.getOperationAction(ISD::UNDEF, VT)) { 687ea19cd51aaf87c5cc19e7cdc2c32ddbefcac7b8fNate Begeman default: assert(0 && "This action is not supported yet!"); 688ea19cd51aaf87c5cc19e7cdc2c32ddbefcac7b8fNate Begeman case TargetLowering::Expand: 689fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman if (MVT::isInteger(VT)) 690fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman Result = DAG.getConstant(0, VT); 691fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman else if (MVT::isFloatingPoint(VT)) 692fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman Result = DAG.getConstantFP(0, VT); 693fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman else 694fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman assert(0 && "Unknown value type!"); 695fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman break; 696ea19cd51aaf87c5cc19e7cdc2c32ddbefcac7b8fNate Begeman case TargetLowering::Legal: 697fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman break; 698fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman } 699fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman break; 700fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman } 701d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner 70248b61a729df6576c8833a83893d4086bddff69a5Chris Lattner case ISD::INTRINSIC_W_CHAIN: 70348b61a729df6576c8833a83893d4086bddff69a5Chris Lattner case ISD::INTRINSIC_WO_CHAIN: 70448b61a729df6576c8833a83893d4086bddff69a5Chris Lattner case ISD::INTRINSIC_VOID: { 705f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner SmallVector<SDOperand, 8> Ops; 706d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) 707d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner Ops.push_back(LegalizeOp(Node->getOperand(i))); 708f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); 70910d7fa62fffbceed580c34a00bd30f16643f6607Chris Lattner 71010d7fa62fffbceed580c34a00bd30f16643f6607Chris Lattner // Allow the target to custom lower its intrinsics if it wants to. 71148b61a729df6576c8833a83893d4086bddff69a5Chris Lattner if (TLI.getOperationAction(Node->getOpcode(), MVT::Other) == 71210d7fa62fffbceed580c34a00bd30f16643f6607Chris Lattner TargetLowering::Custom) { 71310d7fa62fffbceed580c34a00bd30f16643f6607Chris Lattner Tmp3 = TLI.LowerOperation(Result, DAG); 71410d7fa62fffbceed580c34a00bd30f16643f6607Chris Lattner if (Tmp3.Val) Result = Tmp3; 71513fc2f1d270cdedffb72b33621369cee9a2cdaaaChris Lattner } 71613fc2f1d270cdedffb72b33621369cee9a2cdaaaChris Lattner 71713fc2f1d270cdedffb72b33621369cee9a2cdaaaChris Lattner if (Result.Val->getNumValues() == 1) break; 71813fc2f1d270cdedffb72b33621369cee9a2cdaaaChris Lattner 71913fc2f1d270cdedffb72b33621369cee9a2cdaaaChris Lattner // Must have return value and chain result. 72013fc2f1d270cdedffb72b33621369cee9a2cdaaaChris Lattner assert(Result.Val->getNumValues() == 2 && 72113fc2f1d270cdedffb72b33621369cee9a2cdaaaChris Lattner "Cannot return more than two values!"); 72213fc2f1d270cdedffb72b33621369cee9a2cdaaaChris Lattner 72313fc2f1d270cdedffb72b33621369cee9a2cdaaaChris Lattner // Since loads produce two values, make sure to remember that we 72413fc2f1d270cdedffb72b33621369cee9a2cdaaaChris Lattner // legalized both of them. 72513fc2f1d270cdedffb72b33621369cee9a2cdaaaChris Lattner AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); 72613fc2f1d270cdedffb72b33621369cee9a2cdaaaChris Lattner AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); 72713fc2f1d270cdedffb72b33621369cee9a2cdaaaChris Lattner return Result.getValue(Op.ResNo); 728d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner } 72936ce69195ed488034d0bb11180cc2ebd923679c8Chris Lattner 73036ce69195ed488034d0bb11180cc2ebd923679c8Chris Lattner case ISD::LOCATION: 73136ce69195ed488034d0bb11180cc2ebd923679c8Chris Lattner assert(Node->getNumOperands() == 5 && "Invalid LOCATION node!"); 73236ce69195ed488034d0bb11180cc2ebd923679c8Chris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input chain. 73336ce69195ed488034d0bb11180cc2ebd923679c8Chris Lattner 73436ce69195ed488034d0bb11180cc2ebd923679c8Chris Lattner switch (TLI.getOperationAction(ISD::LOCATION, MVT::Other)) { 73536ce69195ed488034d0bb11180cc2ebd923679c8Chris Lattner case TargetLowering::Promote: 73636ce69195ed488034d0bb11180cc2ebd923679c8Chris Lattner default: assert(0 && "This action is not supported yet!"); 737f5395cee6a24699a016b2e379cf4804b09ce5030Jim Laskey case TargetLowering::Expand: { 73844c3b9fdd416c79f4b67cde1aecfced5921efd81Jim Laskey MachineModuleInfo *MMI = DAG.getMachineModuleInfo(); 739abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey bool useDEBUG_LOC = TLI.isOperationLegal(ISD::DEBUG_LOC, MVT::Other); 7401ee29257428960fede862fcfdbe80d5d007927e9Jim Laskey bool useLABEL = TLI.isOperationLegal(ISD::LABEL, MVT::Other); 741abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey 74244c3b9fdd416c79f4b67cde1aecfced5921efd81Jim Laskey if (MMI && (useDEBUG_LOC || useLABEL)) { 743abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey const std::string &FName = 744e81aecbae69d4b3bd24523ec87673632d3b0beecJim Laskey cast<StringSDNode>(Node->getOperand(3))->getValue(); 745abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey const std::string &DirName = 746e81aecbae69d4b3bd24523ec87673632d3b0beecJim Laskey cast<StringSDNode>(Node->getOperand(4))->getValue(); 74744c3b9fdd416c79f4b67cde1aecfced5921efd81Jim Laskey unsigned SrcFile = MMI->RecordSource(DirName, FName); 748abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey 749bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner SmallVector<SDOperand, 8> Ops; 750abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey Ops.push_back(Tmp1); // chain 751abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey SDOperand LineOp = Node->getOperand(1); 752abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey SDOperand ColOp = Node->getOperand(2); 753abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey 754abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey if (useDEBUG_LOC) { 755abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey Ops.push_back(LineOp); // line # 756abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey Ops.push_back(ColOp); // col # 757abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey Ops.push_back(DAG.getConstant(SrcFile, MVT::i32)); // source file id 758bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner Result = DAG.getNode(ISD::DEBUG_LOC, MVT::Other, &Ops[0], Ops.size()); 759abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey } else { 760d0e58e36a9857c45ecdc910ec8db04c21e143db5Jim Laskey unsigned Line = cast<ConstantSDNode>(LineOp)->getValue(); 761d0e58e36a9857c45ecdc910ec8db04c21e143db5Jim Laskey unsigned Col = cast<ConstantSDNode>(ColOp)->getValue(); 76244c3b9fdd416c79f4b67cde1aecfced5921efd81Jim Laskey unsigned ID = MMI->RecordLabel(Line, Col, SrcFile); 763abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey Ops.push_back(DAG.getConstant(ID, MVT::i32)); 7641ee29257428960fede862fcfdbe80d5d007927e9Jim Laskey Result = DAG.getNode(ISD::LABEL, MVT::Other,&Ops[0],Ops.size()); 765abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey } 766e81aecbae69d4b3bd24523ec87673632d3b0beecJim Laskey } else { 767e81aecbae69d4b3bd24523ec87673632d3b0beecJim Laskey Result = Tmp1; // chain 768e81aecbae69d4b3bd24523ec87673632d3b0beecJim Laskey } 76936ce69195ed488034d0bb11180cc2ebd923679c8Chris Lattner break; 770e773673d8e0094bbff2f9ab2f2da9ecb5c4d0909Chris Lattner } 77136ce69195ed488034d0bb11180cc2ebd923679c8Chris Lattner case TargetLowering::Legal: 7729ad17c9c9abfd6e011751d2fd2b03448e1dccb71Chris Lattner if (Tmp1 != Node->getOperand(0) || 7739ad17c9c9abfd6e011751d2fd2b03448e1dccb71Chris Lattner getTypeAction(Node->getOperand(1).getValueType()) == Promote) { 774f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner SmallVector<SDOperand, 8> Ops; 77536ce69195ed488034d0bb11180cc2ebd923679c8Chris Lattner Ops.push_back(Tmp1); 7769ad17c9c9abfd6e011751d2fd2b03448e1dccb71Chris Lattner if (getTypeAction(Node->getOperand(1).getValueType()) == Legal) { 7779ad17c9c9abfd6e011751d2fd2b03448e1dccb71Chris Lattner Ops.push_back(Node->getOperand(1)); // line # must be legal. 7789ad17c9c9abfd6e011751d2fd2b03448e1dccb71Chris Lattner Ops.push_back(Node->getOperand(2)); // col # must be legal. 7799ad17c9c9abfd6e011751d2fd2b03448e1dccb71Chris Lattner } else { 7809ad17c9c9abfd6e011751d2fd2b03448e1dccb71Chris Lattner // Otherwise promote them. 7819ad17c9c9abfd6e011751d2fd2b03448e1dccb71Chris Lattner Ops.push_back(PromoteOp(Node->getOperand(1))); 7829ad17c9c9abfd6e011751d2fd2b03448e1dccb71Chris Lattner Ops.push_back(PromoteOp(Node->getOperand(2))); 7839ad17c9c9abfd6e011751d2fd2b03448e1dccb71Chris Lattner } 78436ce69195ed488034d0bb11180cc2ebd923679c8Chris Lattner Ops.push_back(Node->getOperand(3)); // filename must be legal. 78536ce69195ed488034d0bb11180cc2ebd923679c8Chris Lattner Ops.push_back(Node->getOperand(4)); // working dir # must be legal. 786f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); 78736ce69195ed488034d0bb11180cc2ebd923679c8Chris Lattner } 78836ce69195ed488034d0bb11180cc2ebd923679c8Chris Lattner break; 78936ce69195ed488034d0bb11180cc2ebd923679c8Chris Lattner } 79036ce69195ed488034d0bb11180cc2ebd923679c8Chris Lattner break; 791f5395cee6a24699a016b2e379cf4804b09ce5030Jim Laskey 792f5395cee6a24699a016b2e379cf4804b09ce5030Jim Laskey case ISD::DEBUG_LOC: 793abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey assert(Node->getNumOperands() == 4 && "Invalid DEBUG_LOC node!"); 794f5395cee6a24699a016b2e379cf4804b09ce5030Jim Laskey switch (TLI.getOperationAction(ISD::DEBUG_LOC, MVT::Other)) { 795f5395cee6a24699a016b2e379cf4804b09ce5030Jim Laskey default: assert(0 && "This action is not supported yet!"); 796abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey case TargetLowering::Legal: 797abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. 798abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the line #. 799abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the col #. 800abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey Tmp4 = LegalizeOp(Node->getOperand(3)); // Legalize the source file id. 801c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4); 802abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey break; 803abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey } 804abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey break; 805abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey 8061ee29257428960fede862fcfdbe80d5d007927e9Jim Laskey case ISD::LABEL: 8071ee29257428960fede862fcfdbe80d5d007927e9Jim Laskey assert(Node->getNumOperands() == 2 && "Invalid LABEL node!"); 8081ee29257428960fede862fcfdbe80d5d007927e9Jim Laskey switch (TLI.getOperationAction(ISD::LABEL, MVT::Other)) { 809abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey default: assert(0 && "This action is not supported yet!"); 810abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey case TargetLowering::Legal: 811abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. 812abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the label id. 813c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); 814f5395cee6a24699a016b2e379cf4804b09ce5030Jim Laskey break; 815f5395cee6a24699a016b2e379cf4804b09ce5030Jim Laskey } 816551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman break; 81736ce69195ed488034d0bb11180cc2ebd923679c8Chris Lattner 8183e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::Constant: 8193e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner // We know we don't need to expand constants here, constants only have one 8203e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner // value and we check that it is fine above. 8213e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 8223e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner // FIXME: Maybe we should handle things like targets that don't support full 8233e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner // 32-bit immediates? 8243e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 8253e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::ConstantFP: { 8263e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner // Spill FP immediates to the constant pool if the target cannot directly 8273e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner // codegen them. Targets often have some immediate values that can be 8283e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner // efficiently generated into an FP register without a load. We explicitly 8293e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner // leave these constants as ConstantFP nodes for the target to deal with. 8303e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); 8313e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 8323e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner // Check to see if this FP immediate is already legal. 8333e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner bool isLegal = false; 8343e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner for (TargetLowering::legal_fpimm_iterator I = TLI.legal_fpimm_begin(), 8353e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner E = TLI.legal_fpimm_end(); I != E; ++I) 8363e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner if (CFP->isExactlyValue(*I)) { 8373e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner isLegal = true; 8383e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 8393e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 8403e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 8413181a771ff5b2090b7ed55f9b18a684ea8fe625aChris Lattner // If this is a legal constant, turn it into a TargetConstantFP node. 8423181a771ff5b2090b7ed55f9b18a684ea8fe625aChris Lattner if (isLegal) { 8433181a771ff5b2090b7ed55f9b18a684ea8fe625aChris Lattner Result = DAG.getTargetConstantFP(CFP->getValue(), CFP->getValueType(0)); 8443181a771ff5b2090b7ed55f9b18a684ea8fe625aChris Lattner break; 8453181a771ff5b2090b7ed55f9b18a684ea8fe625aChris Lattner } 8463181a771ff5b2090b7ed55f9b18a684ea8fe625aChris Lattner 8473181a771ff5b2090b7ed55f9b18a684ea8fe625aChris Lattner switch (TLI.getOperationAction(ISD::ConstantFP, CFP->getValueType(0))) { 8483181a771ff5b2090b7ed55f9b18a684ea8fe625aChris Lattner default: assert(0 && "This action is not supported yet!"); 8493181a771ff5b2090b7ed55f9b18a684ea8fe625aChris Lattner case TargetLowering::Custom: 8503181a771ff5b2090b7ed55f9b18a684ea8fe625aChris Lattner Tmp3 = TLI.LowerOperation(Result, DAG); 8513181a771ff5b2090b7ed55f9b18a684ea8fe625aChris Lattner if (Tmp3.Val) { 8523181a771ff5b2090b7ed55f9b18a684ea8fe625aChris Lattner Result = Tmp3; 8533181a771ff5b2090b7ed55f9b18a684ea8fe625aChris Lattner break; 8543181a771ff5b2090b7ed55f9b18a684ea8fe625aChris Lattner } 8553181a771ff5b2090b7ed55f9b18a684ea8fe625aChris Lattner // FALLTHROUGH 8563181a771ff5b2090b7ed55f9b18a684ea8fe625aChris Lattner case TargetLowering::Expand: 857279101eb1ac61e2d5b83d5bdcc5be56e710d2cd7Evan Cheng Result = ExpandConstantFP(CFP, true, DAG, TLI); 8583e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 8593e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 8603e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 861040c11c24e9f6c172eaf680e135d9bb466c284b2Chris Lattner case ISD::TokenFactor: 862040c11c24e9f6c172eaf680e135d9bb466c284b2Chris Lattner if (Node->getNumOperands() == 2) { 863c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); 864c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp2 = LegalizeOp(Node->getOperand(1)); 865c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); 866c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner } else if (Node->getNumOperands() == 3) { 867c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); 868c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp2 = LegalizeOp(Node->getOperand(1)); 869c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp3 = LegalizeOp(Node->getOperand(2)); 870c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); 871040c11c24e9f6c172eaf680e135d9bb466c284b2Chris Lattner } else { 872f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner SmallVector<SDOperand, 8> Ops; 873040c11c24e9f6c172eaf680e135d9bb466c284b2Chris Lattner // Legalize the operands. 874c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) 875c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Ops.push_back(LegalizeOp(Node->getOperand(i))); 876f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); 877a385e9b20fa7d37d3842ce15afd412f617d83a27Chris Lattner } 878a385e9b20fa7d37d3842ce15afd412f617d83a27Chris Lattner break; 879fdfded55888e35b76bb70231a5bb2f60877c2f6aChris Lattner 880fdfded55888e35b76bb70231a5bb2f60877c2f6aChris Lattner case ISD::FORMAL_ARGUMENTS: 881f4ec817299a4187044a6162c2f520772b3ad69a0Chris Lattner case ISD::CALL: 882fdfded55888e35b76bb70231a5bb2f60877c2f6aChris Lattner // The only option for this is to custom lower it. 883b248e16afd105fd8c01e08d8bf997b08ff08d127Chris Lattner Tmp3 = TLI.LowerOperation(Result.getValue(0), DAG); 884b248e16afd105fd8c01e08d8bf997b08ff08d127Chris Lattner assert(Tmp3.Val && "Target didn't custom lower this node!"); 885b248e16afd105fd8c01e08d8bf997b08ff08d127Chris Lattner assert(Tmp3.Val->getNumValues() == Result.Val->getNumValues() && 886b248e16afd105fd8c01e08d8bf997b08ff08d127Chris Lattner "Lowering call/formal_arguments produced unexpected # results!"); 887e2e41730ccfa9bebfabbd17ab3454aa2bb620b2aChris Lattner 888f4ec817299a4187044a6162c2f520772b3ad69a0Chris Lattner // Since CALL/FORMAL_ARGUMENTS nodes produce multiple values, make sure to 889e2e41730ccfa9bebfabbd17ab3454aa2bb620b2aChris Lattner // remember that we legalized all of them, so it doesn't get relegalized. 890b248e16afd105fd8c01e08d8bf997b08ff08d127Chris Lattner for (unsigned i = 0, e = Tmp3.Val->getNumValues(); i != e; ++i) { 891b248e16afd105fd8c01e08d8bf997b08ff08d127Chris Lattner Tmp1 = LegalizeOp(Tmp3.getValue(i)); 892e2e41730ccfa9bebfabbd17ab3454aa2bb620b2aChris Lattner if (Op.ResNo == i) 893e2e41730ccfa9bebfabbd17ab3454aa2bb620b2aChris Lattner Tmp2 = Tmp1; 894e2e41730ccfa9bebfabbd17ab3454aa2bb620b2aChris Lattner AddLegalizedOperand(SDOperand(Node, i), Tmp1); 895e2e41730ccfa9bebfabbd17ab3454aa2bb620b2aChris Lattner } 896e2e41730ccfa9bebfabbd17ab3454aa2bb620b2aChris Lattner return Tmp2; 897fdfded55888e35b76bb70231a5bb2f60877c2f6aChris Lattner 898b2827b0901162169bb2692b77a839c9767849134Chris Lattner case ISD::BUILD_VECTOR: 899b2827b0901162169bb2692b77a839c9767849134Chris Lattner switch (TLI.getOperationAction(ISD::BUILD_VECTOR, Node->getValueType(0))) { 9002332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner default: assert(0 && "This action is not supported yet!"); 9012332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner case TargetLowering::Custom: 9022332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner Tmp3 = TLI.LowerOperation(Result, DAG); 9032332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner if (Tmp3.Val) { 9042332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner Result = Tmp3; 9052332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner break; 9062332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner } 9072332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner // FALLTHROUGH 908ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner case TargetLowering::Expand: 909ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner Result = ExpandBUILD_VECTOR(Result.Val); 910b2827b0901162169bb2692b77a839c9767849134Chris Lattner break; 9112332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner } 9122332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner break; 9132332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner case ISD::INSERT_VECTOR_ELT: 9142332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); // InVec 9152332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner Tmp2 = LegalizeOp(Node->getOperand(1)); // InVal 9162332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner Tmp3 = LegalizeOp(Node->getOperand(2)); // InEltNo 9172332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); 9182332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner 9192332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner switch (TLI.getOperationAction(ISD::INSERT_VECTOR_ELT, 9202332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner Node->getValueType(0))) { 9212332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner default: assert(0 && "This action is not supported yet!"); 9222332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner case TargetLowering::Legal: 9232332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner break; 9242332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner case TargetLowering::Custom: 9252332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner Tmp3 = TLI.LowerOperation(Result, DAG); 9262332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner if (Tmp3.Val) { 9272332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner Result = Tmp3; 9282332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner break; 9292332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner } 9302332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner // FALLTHROUGH 9312332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner case TargetLowering::Expand: { 9328d5a894501b7546dee94df03118b90126c420820Chris Lattner // If the insert index is a constant, codegen this as a scalar_to_vector, 9338d5a894501b7546dee94df03118b90126c420820Chris Lattner // then a shuffle that inserts it into the right position in the vector. 9348d5a894501b7546dee94df03118b90126c420820Chris Lattner if (ConstantSDNode *InsertPos = dyn_cast<ConstantSDNode>(Tmp3)) { 9358d5a894501b7546dee94df03118b90126c420820Chris Lattner SDOperand ScVec = DAG.getNode(ISD::SCALAR_TO_VECTOR, 9368d5a894501b7546dee94df03118b90126c420820Chris Lattner Tmp1.getValueType(), Tmp2); 9378d5a894501b7546dee94df03118b90126c420820Chris Lattner 9388d5a894501b7546dee94df03118b90126c420820Chris Lattner unsigned NumElts = MVT::getVectorNumElements(Tmp1.getValueType()); 9398d5a894501b7546dee94df03118b90126c420820Chris Lattner MVT::ValueType ShufMaskVT = MVT::getIntVectorWithNumElements(NumElts); 9408d5a894501b7546dee94df03118b90126c420820Chris Lattner MVT::ValueType ShufMaskEltVT = MVT::getVectorBaseType(ShufMaskVT); 9418d5a894501b7546dee94df03118b90126c420820Chris Lattner 9428d5a894501b7546dee94df03118b90126c420820Chris Lattner // We generate a shuffle of InVec and ScVec, so the shuffle mask should 9438d5a894501b7546dee94df03118b90126c420820Chris Lattner // be 0,1,2,3,4,5... with the appropriate element replaced with elt 0 of 9448d5a894501b7546dee94df03118b90126c420820Chris Lattner // the RHS. 945bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner SmallVector<SDOperand, 8> ShufOps; 9468d5a894501b7546dee94df03118b90126c420820Chris Lattner for (unsigned i = 0; i != NumElts; ++i) { 9478d5a894501b7546dee94df03118b90126c420820Chris Lattner if (i != InsertPos->getValue()) 9488d5a894501b7546dee94df03118b90126c420820Chris Lattner ShufOps.push_back(DAG.getConstant(i, ShufMaskEltVT)); 9498d5a894501b7546dee94df03118b90126c420820Chris Lattner else 9508d5a894501b7546dee94df03118b90126c420820Chris Lattner ShufOps.push_back(DAG.getConstant(NumElts, ShufMaskEltVT)); 9518d5a894501b7546dee94df03118b90126c420820Chris Lattner } 952bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner SDOperand ShufMask = DAG.getNode(ISD::BUILD_VECTOR, ShufMaskVT, 953bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner &ShufOps[0], ShufOps.size()); 9548d5a894501b7546dee94df03118b90126c420820Chris Lattner 9558d5a894501b7546dee94df03118b90126c420820Chris Lattner Result = DAG.getNode(ISD::VECTOR_SHUFFLE, Tmp1.getValueType(), 9568d5a894501b7546dee94df03118b90126c420820Chris Lattner Tmp1, ScVec, ShufMask); 9578d5a894501b7546dee94df03118b90126c420820Chris Lattner Result = LegalizeOp(Result); 9588d5a894501b7546dee94df03118b90126c420820Chris Lattner break; 9598d5a894501b7546dee94df03118b90126c420820Chris Lattner } 9608d5a894501b7546dee94df03118b90126c420820Chris Lattner 9612332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner // If the target doesn't support this, we have to spill the input vector 9622332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner // to a temporary stack slot, update the element, then reload it. This is 9632332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner // badness. We could also load the value into a vector register (either 9642332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner // with a "move to register" or "extload into register" instruction, then 9652332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner // permute it into place, if the idx is a constant and if the idx is 9662332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner // supported by the target. 967f6bf87f2cc685d13d6a8fa37693425956b33a840Evan Cheng MVT::ValueType VT = Tmp1.getValueType(); 968f6bf87f2cc685d13d6a8fa37693425956b33a840Evan Cheng MVT::ValueType EltVT = Tmp2.getValueType(); 969f6bf87f2cc685d13d6a8fa37693425956b33a840Evan Cheng MVT::ValueType IdxVT = Tmp3.getValueType(); 970f6bf87f2cc685d13d6a8fa37693425956b33a840Evan Cheng MVT::ValueType PtrVT = TLI.getPointerTy(); 971f6bf87f2cc685d13d6a8fa37693425956b33a840Evan Cheng SDOperand StackPtr = CreateStackTemporary(VT); 972eb0b461cf4884bf2c98e463663a298e5c4ae9883Evan Cheng // Store the vector. 9738b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Tmp1, StackPtr, NULL, 0); 974eb0b461cf4884bf2c98e463663a298e5c4ae9883Evan Cheng 975eb0b461cf4884bf2c98e463663a298e5c4ae9883Evan Cheng // Truncate or zero extend offset to target pointer type. 976f6bf87f2cc685d13d6a8fa37693425956b33a840Evan Cheng unsigned CastOpc = (IdxVT > PtrVT) ? ISD::TRUNCATE : ISD::ZERO_EXTEND; 977f6bf87f2cc685d13d6a8fa37693425956b33a840Evan Cheng Tmp3 = DAG.getNode(CastOpc, PtrVT, Tmp3); 978eb0b461cf4884bf2c98e463663a298e5c4ae9883Evan Cheng // Add the offset to the index. 979f6bf87f2cc685d13d6a8fa37693425956b33a840Evan Cheng unsigned EltSize = MVT::getSizeInBits(EltVT)/8; 980f6bf87f2cc685d13d6a8fa37693425956b33a840Evan Cheng Tmp3 = DAG.getNode(ISD::MUL, IdxVT, Tmp3,DAG.getConstant(EltSize, IdxVT)); 981f6bf87f2cc685d13d6a8fa37693425956b33a840Evan Cheng SDOperand StackPtr2 = DAG.getNode(ISD::ADD, IdxVT, Tmp3, StackPtr); 982eb0b461cf4884bf2c98e463663a298e5c4ae9883Evan Cheng // Store the scalar value. 9838b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Ch = DAG.getStore(Ch, Tmp2, StackPtr2, NULL, 0); 984eb0b461cf4884bf2c98e463663a298e5c4ae9883Evan Cheng // Load the updated vector. 985466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Result = DAG.getLoad(VT, Ch, StackPtr, NULL, 0); 9862332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner break; 9872332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner } 9882332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner } 9892332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner break; 990ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner case ISD::SCALAR_TO_VECTOR: 9914352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner if (!TLI.isTypeLegal(Node->getOperand(0).getValueType())) { 9924352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node)); 9934352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner break; 9944352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner } 9954352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner 996ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); // InVal 997ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1); 998ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner switch (TLI.getOperationAction(ISD::SCALAR_TO_VECTOR, 999ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner Node->getValueType(0))) { 1000ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner default: assert(0 && "This action is not supported yet!"); 1001ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner case TargetLowering::Legal: 1002ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner break; 10034d3abee6183f110c9db56b94b0a4b5f8c985002aChris Lattner case TargetLowering::Custom: 10044d3abee6183f110c9db56b94b0a4b5f8c985002aChris Lattner Tmp3 = TLI.LowerOperation(Result, DAG); 10054d3abee6183f110c9db56b94b0a4b5f8c985002aChris Lattner if (Tmp3.Val) { 10064d3abee6183f110c9db56b94b0a4b5f8c985002aChris Lattner Result = Tmp3; 10074d3abee6183f110c9db56b94b0a4b5f8c985002aChris Lattner break; 10084d3abee6183f110c9db56b94b0a4b5f8c985002aChris Lattner } 10094d3abee6183f110c9db56b94b0a4b5f8c985002aChris Lattner // FALLTHROUGH 10104352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner case TargetLowering::Expand: 10114352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner Result = LegalizeOp(ExpandSCALAR_TO_VECTOR(Node)); 1012ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner break; 1013ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner } 1014ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner break; 101587100e0b83b808757bf44dabecd1d1048255d1adChris Lattner case ISD::VECTOR_SHUFFLE: 101687100e0b83b808757bf44dabecd1d1048255d1adChris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the input vectors, 101787100e0b83b808757bf44dabecd1d1048255d1adChris Lattner Tmp2 = LegalizeOp(Node->getOperand(1)); // but not the shuffle mask. 101887100e0b83b808757bf44dabecd1d1048255d1adChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); 101987100e0b83b808757bf44dabecd1d1048255d1adChris Lattner 102087100e0b83b808757bf44dabecd1d1048255d1adChris Lattner // Allow targets to custom lower the SHUFFLEs they support. 10214352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner switch (TLI.getOperationAction(ISD::VECTOR_SHUFFLE,Result.getValueType())) { 10224352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner default: assert(0 && "Unknown operation action!"); 10234352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner case TargetLowering::Legal: 10244352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner assert(isShuffleLegal(Result.getValueType(), Node->getOperand(2)) && 10254352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner "vector shuffle should not be created if not legal!"); 10264352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner break; 10274352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner case TargetLowering::Custom: 102818dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng Tmp3 = TLI.LowerOperation(Result, DAG); 102918dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng if (Tmp3.Val) { 103018dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng Result = Tmp3; 103118dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng break; 103218dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng } 103318dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng // FALLTHROUGH 103418dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng case TargetLowering::Expand: { 103518dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng MVT::ValueType VT = Node->getValueType(0); 103618dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng MVT::ValueType EltVT = MVT::getVectorBaseType(VT); 103718dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng MVT::ValueType PtrVT = TLI.getPointerTy(); 103818dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng SDOperand Mask = Node->getOperand(2); 103918dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng unsigned NumElems = Mask.getNumOperands(); 1040bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner SmallVector<SDOperand,8> Ops; 104118dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng for (unsigned i = 0; i != NumElems; ++i) { 104218dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng SDOperand Arg = Mask.getOperand(i); 104318dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng if (Arg.getOpcode() == ISD::UNDEF) { 104418dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng Ops.push_back(DAG.getNode(ISD::UNDEF, EltVT)); 104518dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng } else { 104618dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); 104718dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng unsigned Idx = cast<ConstantSDNode>(Arg)->getValue(); 104818dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng if (Idx < NumElems) 104918dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp1, 105018dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng DAG.getConstant(Idx, PtrVT))); 105118dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng else 105218dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp2, 105318dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng DAG.getConstant(Idx - NumElems, PtrVT))); 105418dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng } 105518dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng } 1056bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner Result = DAG.getNode(ISD::BUILD_VECTOR, VT, &Ops[0], Ops.size()); 10574352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner break; 105818dd6d0a2aeb3b827391f46996a7b40c9b1f907aEvan Cheng } 10594352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner case TargetLowering::Promote: { 10604352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner // Change base type to a different vector type. 10614352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner MVT::ValueType OVT = Node->getValueType(0); 10624352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); 10634352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner 10644352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner // Cast the two input vectors. 10654352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1); 10664352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2); 10674352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner 10684352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner // Convert the shuffle mask to the right # elements. 10694352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner Tmp3 = SDOperand(isShuffleLegal(OVT, Node->getOperand(2)), 0); 10704352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner assert(Tmp3.Val && "Shuffle not legal?"); 10714352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner Result = DAG.getNode(ISD::VECTOR_SHUFFLE, NVT, Tmp1, Tmp2, Tmp3); 10724352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result); 10734352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner break; 10744352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner } 107587100e0b83b808757bf44dabecd1d1048255d1adChris Lattner } 107687100e0b83b808757bf44dabecd1d1048255d1adChris Lattner break; 1077384504cea6c392125a2318d8bbb7f25aa0bbff7eChris Lattner 1078384504cea6c392125a2318d8bbb7f25aa0bbff7eChris Lattner case ISD::EXTRACT_VECTOR_ELT: 1079384504cea6c392125a2318d8bbb7f25aa0bbff7eChris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); 1080384504cea6c392125a2318d8bbb7f25aa0bbff7eChris Lattner Tmp2 = LegalizeOp(Node->getOperand(1)); 1081384504cea6c392125a2318d8bbb7f25aa0bbff7eChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); 1082e35c218f3e8e15f96cb44c5fbc70c7ea20d6c962Chris Lattner 1083e35c218f3e8e15f96cb44c5fbc70c7ea20d6c962Chris Lattner switch (TLI.getOperationAction(ISD::EXTRACT_VECTOR_ELT, 1084e35c218f3e8e15f96cb44c5fbc70c7ea20d6c962Chris Lattner Tmp1.getValueType())) { 1085e35c218f3e8e15f96cb44c5fbc70c7ea20d6c962Chris Lattner default: assert(0 && "This action is not supported yet!"); 1086e35c218f3e8e15f96cb44c5fbc70c7ea20d6c962Chris Lattner case TargetLowering::Legal: 1087e35c218f3e8e15f96cb44c5fbc70c7ea20d6c962Chris Lattner break; 1088e35c218f3e8e15f96cb44c5fbc70c7ea20d6c962Chris Lattner case TargetLowering::Custom: 1089e35c218f3e8e15f96cb44c5fbc70c7ea20d6c962Chris Lattner Tmp3 = TLI.LowerOperation(Result, DAG); 1090e35c218f3e8e15f96cb44c5fbc70c7ea20d6c962Chris Lattner if (Tmp3.Val) { 1091e35c218f3e8e15f96cb44c5fbc70c7ea20d6c962Chris Lattner Result = Tmp3; 1092e35c218f3e8e15f96cb44c5fbc70c7ea20d6c962Chris Lattner break; 1093e35c218f3e8e15f96cb44c5fbc70c7ea20d6c962Chris Lattner } 1094e35c218f3e8e15f96cb44c5fbc70c7ea20d6c962Chris Lattner // FALLTHROUGH 10954aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner case TargetLowering::Expand: 10964aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner Result = ExpandEXTRACT_VECTOR_ELT(Result); 1097e35c218f3e8e15f96cb44c5fbc70c7ea20d6c962Chris Lattner break; 1098e35c218f3e8e15f96cb44c5fbc70c7ea20d6c962Chris Lattner } 1099384504cea6c392125a2318d8bbb7f25aa0bbff7eChris Lattner break; 1100384504cea6c392125a2318d8bbb7f25aa0bbff7eChris Lattner 11011597221eace1c53ce5f84a7018397497d11a8393Chris Lattner case ISD::VEXTRACT_VECTOR_ELT: 11021597221eace1c53ce5f84a7018397497d11a8393Chris Lattner Result = LegalizeOp(LowerVEXTRACT_VECTOR_ELT(Op)); 1103384504cea6c392125a2318d8bbb7f25aa0bbff7eChris Lattner break; 110487100e0b83b808757bf44dabecd1d1048255d1adChris Lattner 11056831a815999dde4cf801e2076e66b4943964daf2Chris Lattner case ISD::CALLSEQ_START: { 11066831a815999dde4cf801e2076e66b4943964daf2Chris Lattner SDNode *CallEnd = FindCallEndFromCallStart(Node); 11076831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 11086831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Recursively Legalize all of the inputs of the call end that do not lead 11096831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // to this call start. This ensures that any libcalls that need be inserted 11106831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // are inserted *before* the CALLSEQ_START. 1111c9cf4f1a7573ac7e379efd6ad15d7bd0a84a097cChris Lattner {std::set<SDNode*> NodesLeadingTo; 11126831a815999dde4cf801e2076e66b4943964daf2Chris Lattner for (unsigned i = 0, e = CallEnd->getNumOperands(); i != e; ++i) 1113c9cf4f1a7573ac7e379efd6ad15d7bd0a84a097cChris Lattner LegalizeAllNodesNotLeadingTo(CallEnd->getOperand(i).Val, Node, 1114c9cf4f1a7573ac7e379efd6ad15d7bd0a84a097cChris Lattner NodesLeadingTo); 1115c9cf4f1a7573ac7e379efd6ad15d7bd0a84a097cChris Lattner } 11166831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 11176831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Now that we legalized all of the inputs (which may have inserted 11186831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // libcalls) create the new CALLSEQ_START node. 11196831a815999dde4cf801e2076e66b4943964daf2Chris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. 11206831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 11216831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Merge in the last call, to ensure that this call start after the last 11226831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // call ended. 1123c5d7d7c715f7b7a4eeea1ceaafefc3d1d6df2addChris Lattner if (LastCALLSEQ_END.getOpcode() != ISD::EntryToken) { 1124b248e16afd105fd8c01e08d8bf997b08ff08d127Chris Lattner Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); 1125b248e16afd105fd8c01e08d8bf997b08ff08d127Chris Lattner Tmp1 = LegalizeOp(Tmp1); 1126b248e16afd105fd8c01e08d8bf997b08ff08d127Chris Lattner } 11276831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 11286831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Do not try to legalize the target-specific arguments (#1+). 11296831a815999dde4cf801e2076e66b4943964daf2Chris Lattner if (Tmp1 != Node->getOperand(0)) { 1130f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); 11316831a815999dde4cf801e2076e66b4943964daf2Chris Lattner Ops[0] = Tmp1; 1132f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); 11336831a815999dde4cf801e2076e66b4943964daf2Chris Lattner } 11346831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 11356831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Remember that the CALLSEQ_START is legalized. 11364b653a0405bb16b555334d134c1eb8a97366ec3dChris Lattner AddLegalizedOperand(Op.getValue(0), Result); 11374b653a0405bb16b555334d134c1eb8a97366ec3dChris Lattner if (Node->getNumValues() == 2) // If this has a flag result, remember it. 11384b653a0405bb16b555334d134c1eb8a97366ec3dChris Lattner AddLegalizedOperand(Op.getValue(1), Result.getValue(1)); 11394b653a0405bb16b555334d134c1eb8a97366ec3dChris Lattner 11406831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Now that the callseq_start and all of the non-call nodes above this call 11416831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // sequence have been legalized, legalize the call itself. During this 11426831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // process, no libcalls can/will be inserted, guaranteeing that no calls 11436831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // can overlap. 11446831a815999dde4cf801e2076e66b4943964daf2Chris Lattner assert(!IsLegalizingCall && "Inconsistent sequentialization of calls!"); 11456831a815999dde4cf801e2076e66b4943964daf2Chris Lattner SDOperand InCallSEQ = LastCALLSEQ_END; 11466831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Note that we are selecting this call! 11476831a815999dde4cf801e2076e66b4943964daf2Chris Lattner LastCALLSEQ_END = SDOperand(CallEnd, 0); 11486831a815999dde4cf801e2076e66b4943964daf2Chris Lattner IsLegalizingCall = true; 11496831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 11506831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Legalize the call, starting from the CALLSEQ_END. 11516831a815999dde4cf801e2076e66b4943964daf2Chris Lattner LegalizeOp(LastCALLSEQ_END); 11526831a815999dde4cf801e2076e66b4943964daf2Chris Lattner assert(!IsLegalizingCall && "CALLSEQ_END should have cleared this!"); 11536831a815999dde4cf801e2076e66b4943964daf2Chris Lattner return Result; 11546831a815999dde4cf801e2076e66b4943964daf2Chris Lattner } 115516cd04d26c53c6f81313cafb85f6c0e7a07cdff6Chris Lattner case ISD::CALLSEQ_END: 11566831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // If the CALLSEQ_START node hasn't been legalized first, legalize it. This 11576831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // will cause this node to be legalized as well as handling libcalls right. 11586831a815999dde4cf801e2076e66b4943964daf2Chris Lattner if (LastCALLSEQ_END.Val != Node) { 11596831a815999dde4cf801e2076e66b4943964daf2Chris Lattner LegalizeOp(SDOperand(FindCallStartFromCallEnd(Node), 0)); 11606831a815999dde4cf801e2076e66b4943964daf2Chris Lattner std::map<SDOperand, SDOperand>::iterator I = LegalizedNodes.find(Op); 11616831a815999dde4cf801e2076e66b4943964daf2Chris Lattner assert(I != LegalizedNodes.end() && 11626831a815999dde4cf801e2076e66b4943964daf2Chris Lattner "Legalizing the call start should have legalized this node!"); 11636831a815999dde4cf801e2076e66b4943964daf2Chris Lattner return I->second; 11646831a815999dde4cf801e2076e66b4943964daf2Chris Lattner } 11656831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 11666831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Otherwise, the call start has been legalized and everything is going 11676831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // according to plan. Just legalize ourselves normally here. 11683e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. 116970814bc38435d61a8c7cc32f2375c09e21f12a8aChris Lattner // Do not try to legalize the target-specific arguments (#1+), except for 117070814bc38435d61a8c7cc32f2375c09e21f12a8aChris Lattner // an optional flag input. 117170814bc38435d61a8c7cc32f2375c09e21f12a8aChris Lattner if (Node->getOperand(Node->getNumOperands()-1).getValueType() != MVT::Flag){ 117270814bc38435d61a8c7cc32f2375c09e21f12a8aChris Lattner if (Tmp1 != Node->getOperand(0)) { 1173f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); 117470814bc38435d61a8c7cc32f2375c09e21f12a8aChris Lattner Ops[0] = Tmp1; 1175f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); 117670814bc38435d61a8c7cc32f2375c09e21f12a8aChris Lattner } 117770814bc38435d61a8c7cc32f2375c09e21f12a8aChris Lattner } else { 117870814bc38435d61a8c7cc32f2375c09e21f12a8aChris Lattner Tmp2 = LegalizeOp(Node->getOperand(Node->getNumOperands()-1)); 117970814bc38435d61a8c7cc32f2375c09e21f12a8aChris Lattner if (Tmp1 != Node->getOperand(0) || 118070814bc38435d61a8c7cc32f2375c09e21f12a8aChris Lattner Tmp2 != Node->getOperand(Node->getNumOperands()-1)) { 1181f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); 118270814bc38435d61a8c7cc32f2375c09e21f12a8aChris Lattner Ops[0] = Tmp1; 118370814bc38435d61a8c7cc32f2375c09e21f12a8aChris Lattner Ops.back() = Tmp2; 1184f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); 118570814bc38435d61a8c7cc32f2375c09e21f12a8aChris Lattner } 11866a5428934ba6159c1acc541944332e51a6cfa59aChris Lattner } 11874b653a0405bb16b555334d134c1eb8a97366ec3dChris Lattner assert(IsLegalizingCall && "Call sequence imbalance between start/end?"); 11886831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // This finishes up call legalization. 11896831a815999dde4cf801e2076e66b4943964daf2Chris Lattner IsLegalizingCall = false; 11904b653a0405bb16b555334d134c1eb8a97366ec3dChris Lattner 11914b653a0405bb16b555334d134c1eb8a97366ec3dChris Lattner // If the CALLSEQ_END node has a flag, remember that we legalized it. 11924b653a0405bb16b555334d134c1eb8a97366ec3dChris Lattner AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); 11934b653a0405bb16b555334d134c1eb8a97366ec3dChris Lattner if (Node->getNumValues() == 2) 11944b653a0405bb16b555334d134c1eb8a97366ec3dChris Lattner AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); 11954b653a0405bb16b555334d134c1eb8a97366ec3dChris Lattner return Result.getValue(Op.ResNo); 1196a7dce3c6c29fb9513d215c1bc44b01865571b4c2Evan Cheng case ISD::DYNAMIC_STACKALLOC: { 1197fa404e8a76abfdafefb8806b35f596d288609496Chris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. 1198fa404e8a76abfdafefb8806b35f596d288609496Chris Lattner Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the size. 1199fa404e8a76abfdafefb8806b35f596d288609496Chris Lattner Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the alignment. 1200c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); 1201fa404e8a76abfdafefb8806b35f596d288609496Chris Lattner 1202c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp1 = Result.getValue(0); 12035f652295c27826f26547cf5eb4096a59d86b56b8Chris Lattner Tmp2 = Result.getValue(1); 1204a7dce3c6c29fb9513d215c1bc44b01865571b4c2Evan Cheng switch (TLI.getOperationAction(Node->getOpcode(), 1205a7dce3c6c29fb9513d215c1bc44b01865571b4c2Evan Cheng Node->getValueType(0))) { 1206a7dce3c6c29fb9513d215c1bc44b01865571b4c2Evan Cheng default: assert(0 && "This action is not supported yet!"); 1207903d278a9b7398d8905c90832e587e0556c52789Chris Lattner case TargetLowering::Expand: { 1208903d278a9b7398d8905c90832e587e0556c52789Chris Lattner unsigned SPReg = TLI.getStackPointerRegisterToSaveRestore(); 1209903d278a9b7398d8905c90832e587e0556c52789Chris Lattner assert(SPReg && "Target cannot require DYNAMIC_STACKALLOC expansion and" 1210903d278a9b7398d8905c90832e587e0556c52789Chris Lattner " not tell us which reg is the stack pointer!"); 1211903d278a9b7398d8905c90832e587e0556c52789Chris Lattner SDOperand Chain = Tmp1.getOperand(0); 1212903d278a9b7398d8905c90832e587e0556c52789Chris Lattner SDOperand Size = Tmp2.getOperand(1); 1213903d278a9b7398d8905c90832e587e0556c52789Chris Lattner SDOperand SP = DAG.getCopyFromReg(Chain, SPReg, Node->getValueType(0)); 1214903d278a9b7398d8905c90832e587e0556c52789Chris Lattner Tmp1 = DAG.getNode(ISD::SUB, Node->getValueType(0), SP, Size); // Value 1215903d278a9b7398d8905c90832e587e0556c52789Chris Lattner Tmp2 = DAG.getCopyToReg(SP.getValue(1), SPReg, Tmp1); // Output chain 1216c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp1 = LegalizeOp(Tmp1); 1217c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp2 = LegalizeOp(Tmp2); 1218903d278a9b7398d8905c90832e587e0556c52789Chris Lattner break; 1219903d278a9b7398d8905c90832e587e0556c52789Chris Lattner } 1220903d278a9b7398d8905c90832e587e0556c52789Chris Lattner case TargetLowering::Custom: 12215f652295c27826f26547cf5eb4096a59d86b56b8Chris Lattner Tmp3 = TLI.LowerOperation(Tmp1, DAG); 12225f652295c27826f26547cf5eb4096a59d86b56b8Chris Lattner if (Tmp3.Val) { 1223c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp1 = LegalizeOp(Tmp3); 1224c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp2 = LegalizeOp(Tmp3.getValue(1)); 1225a7dce3c6c29fb9513d215c1bc44b01865571b4c2Evan Cheng } 1226903d278a9b7398d8905c90832e587e0556c52789Chris Lattner break; 1227a7dce3c6c29fb9513d215c1bc44b01865571b4c2Evan Cheng case TargetLowering::Legal: 1228903d278a9b7398d8905c90832e587e0556c52789Chris Lattner break; 1229a7dce3c6c29fb9513d215c1bc44b01865571b4c2Evan Cheng } 1230903d278a9b7398d8905c90832e587e0556c52789Chris Lattner // Since this op produce two values, make sure to remember that we 1231903d278a9b7398d8905c90832e587e0556c52789Chris Lattner // legalized both of them. 1232c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner AddLegalizedOperand(SDOperand(Node, 0), Tmp1); 1233c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner AddLegalizedOperand(SDOperand(Node, 1), Tmp2); 1234903d278a9b7398d8905c90832e587e0556c52789Chris Lattner return Op.ResNo ? Tmp2 : Tmp1; 1235a7dce3c6c29fb9513d215c1bc44b01865571b4c2Evan Cheng } 123625a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner case ISD::INLINEASM: { 1237f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner SmallVector<SDOperand, 8> Ops(Node->op_begin(), Node->op_end()); 123825a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner bool Changed = false; 123925a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner // Legalize all of the operands of the inline asm, in case they are nodes 124025a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner // that need to be expanded or something. Note we skip the asm string and 124125a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner // all of the TargetConstant flags. 124225a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner SDOperand Op = LegalizeOp(Ops[0]); 124325a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner Changed = Op != Ops[0]; 124425a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner Ops[0] = Op; 124525a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner 124625a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner bool HasInFlag = Ops.back().getValueType() == MVT::Flag; 124725a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner for (unsigned i = 2, e = Ops.size()-HasInFlag; i < e; ) { 124825a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner unsigned NumVals = cast<ConstantSDNode>(Ops[i])->getValue() >> 3; 124925a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner for (++i; NumVals; ++i, --NumVals) { 125025a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner SDOperand Op = LegalizeOp(Ops[i]); 125125a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner if (Op != Ops[i]) { 125225a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner Changed = true; 125325a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner Ops[i] = Op; 125425a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner } 125525a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner } 125625a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner } 125725a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner 125825a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner if (HasInFlag) { 125925a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner Op = LegalizeOp(Ops.back()); 126025a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner Changed |= Op != Ops.back(); 126125a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner Ops.back() = Op; 126225a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner } 1263ce7518ce92f45568dc7d4cbb863284afb962fec5Chris Lattner 126425a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner if (Changed) 1265f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); 1266ce7518ce92f45568dc7d4cbb863284afb962fec5Chris Lattner 1267ce7518ce92f45568dc7d4cbb863284afb962fec5Chris Lattner // INLINE asm returns a chain and flag, make sure to add both to the map. 1268c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); 1269ce7518ce92f45568dc7d4cbb863284afb962fec5Chris Lattner AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); 1270ce7518ce92f45568dc7d4cbb863284afb962fec5Chris Lattner return Result.getValue(Op.ResNo); 127125a022c7801b047b31d7610386e8a9ddca878cb1Chris Lattner } 1272c7af17923e3bb6053f529679ef0be5399d3519edChris Lattner case ISD::BR: 1273c7af17923e3bb6053f529679ef0be5399d3519edChris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. 12746831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Ensure that libcalls are emitted before a branch. 12756831a815999dde4cf801e2076e66b4943964daf2Chris Lattner Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); 12766831a815999dde4cf801e2076e66b4943964daf2Chris Lattner Tmp1 = LegalizeOp(Tmp1); 12776831a815999dde4cf801e2076e66b4943964daf2Chris Lattner LastCALLSEQ_END = DAG.getEntryNode(); 12786831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 1279c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); 1280c7af17923e3bb6053f529679ef0be5399d3519edChris Lattner break; 128137efe6764568a3829fee26aba532283131d1a104Nate Begeman case ISD::BRIND: 128237efe6764568a3829fee26aba532283131d1a104Nate Begeman Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. 128337efe6764568a3829fee26aba532283131d1a104Nate Begeman // Ensure that libcalls are emitted before a branch. 128437efe6764568a3829fee26aba532283131d1a104Nate Begeman Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); 128537efe6764568a3829fee26aba532283131d1a104Nate Begeman Tmp1 = LegalizeOp(Tmp1); 128637efe6764568a3829fee26aba532283131d1a104Nate Begeman LastCALLSEQ_END = DAG.getEntryNode(); 128737efe6764568a3829fee26aba532283131d1a104Nate Begeman 128837efe6764568a3829fee26aba532283131d1a104Nate Begeman switch (getTypeAction(Node->getOperand(1).getValueType())) { 128937efe6764568a3829fee26aba532283131d1a104Nate Begeman default: assert(0 && "Indirect target must be legal type (pointer)!"); 129037efe6764568a3829fee26aba532283131d1a104Nate Begeman case Legal: 129137efe6764568a3829fee26aba532283131d1a104Nate Begeman Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. 129237efe6764568a3829fee26aba532283131d1a104Nate Begeman break; 129337efe6764568a3829fee26aba532283131d1a104Nate Begeman } 129437efe6764568a3829fee26aba532283131d1a104Nate Begeman Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); 129537efe6764568a3829fee26aba532283131d1a104Nate Begeman break; 12963d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng case ISD::BR_JT: 12973d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. 12983d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng // Ensure that libcalls are emitted before a branch. 12993d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); 13003d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng Tmp1 = LegalizeOp(Tmp1); 13013d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng LastCALLSEQ_END = DAG.getEntryNode(); 13023d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng 13033d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the jumptable node. 13043d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); 13053d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng 13063d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng switch (TLI.getOperationAction(ISD::BR_JT, MVT::Other)) { 13073d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng default: assert(0 && "This action is not supported yet!"); 13083d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng case TargetLowering::Legal: break; 13093d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng case TargetLowering::Custom: 13103d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng Tmp1 = TLI.LowerOperation(Result, DAG); 13113d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng if (Tmp1.Val) Result = Tmp1; 13123d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng break; 13133d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng case TargetLowering::Expand: { 13143d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng SDOperand Chain = Result.getOperand(0); 13153d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng SDOperand Table = Result.getOperand(1); 13163d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng SDOperand Index = Result.getOperand(2); 13173d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng 13183d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng MVT::ValueType PTy = TLI.getPointerTy(); 1319acd80ac7bb19f8bdfa55336d567c9ecbe695c8b8Jim Laskey MachineFunction &MF = DAG.getMachineFunction(); 1320acd80ac7bb19f8bdfa55336d567c9ecbe695c8b8Jim Laskey unsigned EntrySize = MF.getJumpTableInfo()->getEntrySize(); 13213d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng Index= DAG.getNode(ISD::MUL, PTy, Index, DAG.getConstant(EntrySize, PTy)); 13223d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng SDOperand Addr = DAG.getNode(ISD::ADD, PTy, Index, Table); 1323acd80ac7bb19f8bdfa55336d567c9ecbe695c8b8Jim Laskey 1324acd80ac7bb19f8bdfa55336d567c9ecbe695c8b8Jim Laskey SDOperand LD; 1325acd80ac7bb19f8bdfa55336d567c9ecbe695c8b8Jim Laskey switch (EntrySize) { 1326acd80ac7bb19f8bdfa55336d567c9ecbe695c8b8Jim Laskey default: assert(0 && "Size of jump table not supported yet."); break; 1327acd80ac7bb19f8bdfa55336d567c9ecbe695c8b8Jim Laskey case 4: LD = DAG.getLoad(MVT::i32, Chain, Addr, NULL, 0); break; 1328acd80ac7bb19f8bdfa55336d567c9ecbe695c8b8Jim Laskey case 8: LD = DAG.getLoad(MVT::i64, Chain, Addr, NULL, 0); break; 1329acd80ac7bb19f8bdfa55336d567c9ecbe695c8b8Jim Laskey } 1330acd80ac7bb19f8bdfa55336d567c9ecbe695c8b8Jim Laskey 1331acd80ac7bb19f8bdfa55336d567c9ecbe695c8b8Jim Laskey if (TLI.getTargetMachine().getRelocationModel() == Reloc::PIC_) { 13323d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng // For PIC, the sequence is: 13333d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng // BRIND(load(Jumptable + index) + RelocBase) 13343d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng // RelocBase is the JumpTable on PPC and X86, GOT on Alpha 13353d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng SDOperand Reloc; 13363d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng if (TLI.usesGlobalOffsetTable()) 13373d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng Reloc = DAG.getNode(ISD::GLOBAL_OFFSET_TABLE, PTy); 13383d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng else 13393d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng Reloc = Table; 1340d063189c0958536aae7ecebec5676541b2cdef9bEvan Cheng Addr = (PTy != MVT::i32) ? DAG.getNode(ISD::SIGN_EXTEND, PTy, LD) : LD; 13413d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng Addr = DAG.getNode(ISD::ADD, PTy, Addr, Reloc); 13423d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng Result = DAG.getNode(ISD::BRIND, MVT::Other, LD.getValue(1), Addr); 13433d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng } else { 13443d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng Result = DAG.getNode(ISD::BRIND, MVT::Other, LD.getValue(1), LD); 13453d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng } 13463d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng } 13473d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng } 13483d4ce1108520a4dcf31cb01523e145d286ee64c1Evan Cheng break; 1349c18ae4cb6a263cf31283c0ef51ace24350f8d72bChris Lattner case ISD::BRCOND: 1350c18ae4cb6a263cf31283c0ef51ace24350f8d72bChris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. 13516831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Ensure that libcalls are emitted before a return. 13526831a815999dde4cf801e2076e66b4943964daf2Chris Lattner Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); 13536831a815999dde4cf801e2076e66b4943964daf2Chris Lattner Tmp1 = LegalizeOp(Tmp1); 13546831a815999dde4cf801e2076e66b4943964daf2Chris Lattner LastCALLSEQ_END = DAG.getEntryNode(); 13556831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 135647e9223e06390897c3834f8c527001df392570ffChris Lattner switch (getTypeAction(Node->getOperand(1).getValueType())) { 135747e9223e06390897c3834f8c527001df392570ffChris Lattner case Expand: assert(0 && "It's impossible to expand bools"); 135847e9223e06390897c3834f8c527001df392570ffChris Lattner case Legal: 135947e9223e06390897c3834f8c527001df392570ffChris Lattner Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the condition. 136047e9223e06390897c3834f8c527001df392570ffChris Lattner break; 136147e9223e06390897c3834f8c527001df392570ffChris Lattner case Promote: 136247e9223e06390897c3834f8c527001df392570ffChris Lattner Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the condition. 1363f9908172e980aab15a36bd110ccdbc5f7afa44f6Chris Lattner 1364f9908172e980aab15a36bd110ccdbc5f7afa44f6Chris Lattner // The top bits of the promoted condition are not necessarily zero, ensure 1365f9908172e980aab15a36bd110ccdbc5f7afa44f6Chris Lattner // that the value is properly zero extended. 1366f9908172e980aab15a36bd110ccdbc5f7afa44f6Chris Lattner if (!TLI.MaskedValueIsZero(Tmp2, 1367f9908172e980aab15a36bd110ccdbc5f7afa44f6Chris Lattner MVT::getIntVTBitMask(Tmp2.getValueType())^1)) 1368f9908172e980aab15a36bd110ccdbc5f7afa44f6Chris Lattner Tmp2 = DAG.getZeroExtendInReg(Tmp2, MVT::i1); 136947e9223e06390897c3834f8c527001df392570ffChris Lattner break; 137047e9223e06390897c3834f8c527001df392570ffChris Lattner } 1371456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner 1372456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner // Basic block destination (Op#2) is always legal. 1373c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); 13747cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman 13757cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman switch (TLI.getOperationAction(ISD::BRCOND, MVT::Other)) { 13767cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman default: assert(0 && "This action is not supported yet!"); 1377456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Legal: break; 1378456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Custom: 1379456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp1 = TLI.LowerOperation(Result, DAG); 1380456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (Tmp1.Val) Result = Tmp1; 1381456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner break; 13827cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman case TargetLowering::Expand: 13837cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman // Expand brcond's setcc into its constituent parts and create a BR_CC 13847cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman // Node. 13857cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman if (Tmp2.getOpcode() == ISD::SETCC) { 13867cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, Tmp2.getOperand(2), 13877cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman Tmp2.getOperand(0), Tmp2.getOperand(1), 13887cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman Node->getOperand(2)); 13897cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman } else { 13907cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman Result = DAG.getNode(ISD::BR_CC, MVT::Other, Tmp1, 13917cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman DAG.getCondCode(ISD::SETNE), Tmp2, 13927cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman DAG.getConstant(0, Tmp2.getValueType()), 13937cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman Node->getOperand(2)); 13947cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman } 13957cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman break; 13967cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman } 13977cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman break; 13987cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman case ISD::BR_CC: 13997cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. 14006831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Ensure that libcalls are emitted before a branch. 14016831a815999dde4cf801e2076e66b4943964daf2Chris Lattner Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); 14026831a815999dde4cf801e2076e66b4943964daf2Chris Lattner Tmp1 = LegalizeOp(Tmp1); 1403750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp2 = Node->getOperand(2); // LHS 1404750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp3 = Node->getOperand(3); // RHS 1405750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp4 = Node->getOperand(1); // CC 1406181b7a382fbdd3d03ce373a6ffac2204e763f9c3Chris Lattner 1407750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman LegalizeSetCCOperands(Tmp2, Tmp3, Tmp4); 1408722cb360690e5d7742b01a9f497fdb65bf8079d5Evan Cheng LastCALLSEQ_END = DAG.getEntryNode(); 1409722cb360690e5d7742b01a9f497fdb65bf8079d5Evan Cheng 1410750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // If we didn't get both a LHS and RHS back from LegalizeSetCCOperands, 1411750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // the LHS is a legal SETCC itself. In this case, we need to compare 1412750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // the result against zero to select between true and false values. 1413750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman if (Tmp3.Val == 0) { 1414750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp3 = DAG.getConstant(0, Tmp2.getValueType()); 1415750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp4 = DAG.getCondCode(ISD::SETNE); 1416750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman } 1417750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman 1418750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp4, Tmp2, Tmp3, 1419750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Node->getOperand(4)); 1420456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner 1421181b7a382fbdd3d03ce373a6ffac2204e763f9c3Chris Lattner switch (TLI.getOperationAction(ISD::BR_CC, Tmp3.getValueType())) { 1422181b7a382fbdd3d03ce373a6ffac2204e763f9c3Chris Lattner default: assert(0 && "Unexpected action for BR_CC!"); 1423456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Legal: break; 1424456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Custom: 1425456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp4 = TLI.LowerOperation(Result, DAG); 1426456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (Tmp4.Val) Result = Tmp4; 1427181b7a382fbdd3d03ce373a6ffac2204e763f9c3Chris Lattner break; 14287cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman } 1429c18ae4cb6a263cf31283c0ef51ace24350f8d72bChris Lattner break; 1430f3fd9fe20dbcb40f3dffc1518ab955a0b5d6fa23Evan Cheng case ISD::LOAD: { 1431466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng LoadSDNode *LD = cast<LoadSDNode>(Node); 1432466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Tmp1 = LegalizeOp(LD->getChain()); // Legalize the chain. 1433466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Tmp2 = LegalizeOp(LD->getBasePtr()); // Legalize the base pointer. 14342d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth 1435466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng ISD::LoadExtType ExtType = LD->getExtensionType(); 1436466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng if (ExtType == ISD::NON_EXTLOAD) { 1437466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng MVT::ValueType VT = Node->getValueType(0); 1438466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset()); 1439466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Tmp3 = Result.getValue(0); 1440466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Tmp4 = Result.getValue(1); 1441456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner 1442466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng switch (TLI.getOperationAction(Node->getOpcode(), VT)) { 1443466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng default: assert(0 && "This action is not supported yet!"); 1444466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng case TargetLowering::Legal: break; 1445466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng case TargetLowering::Custom: 1446466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Tmp1 = TLI.LowerOperation(Tmp3, DAG); 1447466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng if (Tmp1.Val) { 1448466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Tmp3 = LegalizeOp(Tmp1); 1449466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Tmp4 = LegalizeOp(Tmp1.getValue(1)); 1450466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng } 1451466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng break; 1452466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng case TargetLowering::Promote: { 1453466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng // Only promote a load of vector type to another. 1454466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng assert(MVT::isVector(VT) && "Cannot promote this load!"); 1455466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng // Change base type to a different vector type. 1456466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), VT); 1457466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng 1458466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Tmp1 = DAG.getLoad(NVT, Tmp1, Tmp2, LD->getSrcValue(), 1459466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng LD->getSrcValueOffset()); 1460466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Tmp3 = LegalizeOp(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp1)); 146141f6cbbeb21d7d4376b8c0302b9766c3e43be5f2Evan Cheng Tmp4 = LegalizeOp(Tmp1.getValue(1)); 1462466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng break; 1463f3fd9fe20dbcb40f3dffc1518ab955a0b5d6fa23Evan Cheng } 1464466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng } 1465466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng // Since loads produce two values, make sure to remember that we 1466466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng // legalized both of them. 1467466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng AddLegalizedOperand(SDOperand(Node, 0), Tmp3); 1468466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng AddLegalizedOperand(SDOperand(Node, 1), Tmp4); 1469466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng return Op.ResNo ? Tmp4 : Tmp3; 1470466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng } else { 14712e49f090f9656af7d5ed4d5c4e9fa26af59c7233Evan Cheng MVT::ValueType SrcVT = LD->getLoadedVT(); 1472466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng switch (TLI.getLoadXAction(ExtType, SrcVT)) { 1473466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng default: assert(0 && "This action is not supported yet!"); 1474466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng case TargetLowering::Promote: 1475466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng assert(SrcVT == MVT::i1 && 1476466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng "Can only promote extending LOAD from i1 -> i8!"); 1477466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Result = DAG.getExtLoad(ExtType, Node->getValueType(0), Tmp1, Tmp2, 1478466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng LD->getSrcValue(), LD->getSrcValueOffset(), 1479466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng MVT::i8); 1480c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp1 = Result.getValue(0); 1481c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp2 = Result.getValue(1); 1482c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner break; 1483466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng case TargetLowering::Custom: 1484466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng isCustom = true; 1485466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng // FALLTHROUGH 1486466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng case TargetLowering::Legal: 1487466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, LD->getOffset()); 1488466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Tmp1 = Result.getValue(0); 1489466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Tmp2 = Result.getValue(1); 1490456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner 1491466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng if (isCustom) { 1492466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Tmp3 = TLI.LowerOperation(Result, DAG); 1493466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng if (Tmp3.Val) { 1494466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Tmp1 = LegalizeOp(Tmp3); 1495466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Tmp2 = LegalizeOp(Tmp3.getValue(1)); 1496466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng } 1497456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner } 1498466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng break; 1499466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng case TargetLowering::Expand: 1500466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng // f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND 1501466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng if (SrcVT == MVT::f32 && Node->getValueType(0) == MVT::f64) { 1502466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng SDOperand Load = DAG.getLoad(SrcVT, Tmp1, Tmp2, LD->getSrcValue(), 1503466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng LD->getSrcValueOffset()); 1504466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Result = DAG.getNode(ISD::FP_EXTEND, Node->getValueType(0), Load); 1505466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Tmp1 = LegalizeOp(Result); // Relegalize new nodes. 1506466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Tmp2 = LegalizeOp(Load.getValue(1)); 1507466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng break; 1508466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng } 1509466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng assert(ExtType != ISD::EXTLOAD && "EXTLOAD should always be supported!"); 1510466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng // Turn the unsupported load into an EXTLOAD followed by an explicit 1511466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng // zero/sign extend inreg. 1512466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Result = DAG.getExtLoad(ISD::EXTLOAD, Node->getValueType(0), 1513466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Tmp1, Tmp2, LD->getSrcValue(), 1514466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng LD->getSrcValueOffset(), SrcVT); 1515466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng SDOperand ValRes; 1516466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng if (ExtType == ISD::SEXTLOAD) 1517466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng ValRes = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), 1518466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Result, DAG.getValueType(SrcVT)); 1519466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng else 1520466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng ValRes = DAG.getZeroExtendInReg(Result, SrcVT); 1521466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Tmp1 = LegalizeOp(ValRes); // Relegalize new nodes. 1522466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Tmp2 = LegalizeOp(Result.getValue(1)); // Relegalize new nodes. 1523c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner break; 15249d416f713e8b9e4f0c0c2b3f6f57ce2dd8993209Andrew Lenharth } 1525466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng // Since loads produce two values, make sure to remember that we legalized 1526466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng // both of them. 1527466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng AddLegalizedOperand(SDOperand(Node, 0), Tmp1); 1528466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng AddLegalizedOperand(SDOperand(Node, 1), Tmp2); 1529466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng return Op.ResNo ? Tmp2 : Tmp1; 153001ff7216dd7829d4094754086baf28aa2d7149acChris Lattner } 153101ff7216dd7829d4094754086baf28aa2d7149acChris Lattner } 15325dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman case ISD::EXTRACT_ELEMENT: { 15335dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman MVT::ValueType OpTy = Node->getOperand(0).getValueType(); 15345dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman switch (getTypeAction(OpTy)) { 1535c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner default: assert(0 && "EXTRACT_ELEMENT action for type unimplemented!"); 15365dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman case Legal: 15375dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman if (cast<ConstantSDNode>(Node->getOperand(1))->getValue()) { 15385dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman // 1 -> Hi 15395dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman Result = DAG.getNode(ISD::SRL, OpTy, Node->getOperand(0), 15405dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman DAG.getConstant(MVT::getSizeInBits(OpTy)/2, 15415dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman TLI.getShiftAmountTy())); 15425dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Result); 15435dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman } else { 15445dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman // 0 -> Lo 15455dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), 15465dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman Node->getOperand(0)); 15475dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman } 15485dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman break; 15495dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman case Expand: 15505dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman // Get both the low and high parts. 15515dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman ExpandOp(Node->getOperand(0), Tmp1, Tmp2); 15525dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman if (cast<ConstantSDNode>(Node->getOperand(1))->getValue()) 15535dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman Result = Tmp2; // 1 -> Hi 15545dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman else 15555dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman Result = Tmp1; // 0 -> Lo 15565dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman break; 15575dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman } 15583e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 15595dc897b0e4e5eb4513adc2f161412ce23f6bf2e0Nate Begeman } 15603e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 15613e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::CopyToReg: 15623e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. 1563edf128a7fa90f2b0b7ee24741a04a7ae1ecd6f7eMisha Brukman 1564c9c60f6429416d362c2131b14d097ce0a9ac9599Chris Lattner assert(isTypeLegal(Node->getOperand(2).getValueType()) && 1565d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner "Register type must be legal!"); 15667310fb11f2a074069bf9ec3fc169c742ac48d32bChris Lattner // Legalize the incoming value (must be a legal type). 1567d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner Tmp2 = LegalizeOp(Node->getOperand(2)); 1568f1a47c3371ecd5bb449f39736a36ebbebd4e9e14Chris Lattner if (Node->getNumValues() == 1) { 1569c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2); 15707310fb11f2a074069bf9ec3fc169c742ac48d32bChris Lattner } else { 1571f1a47c3371ecd5bb449f39736a36ebbebd4e9e14Chris Lattner assert(Node->getNumValues() == 2 && "Unknown CopyToReg"); 1572c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner if (Node->getNumOperands() == 4) { 1573f1a47c3371ecd5bb449f39736a36ebbebd4e9e14Chris Lattner Tmp3 = LegalizeOp(Node->getOperand(3)); 1574c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1), Tmp2, 1575c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp3); 1576c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner } else { 1577c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1),Tmp2); 15787310fb11f2a074069bf9ec3fc169c742ac48d32bChris Lattner } 15797310fb11f2a074069bf9ec3fc169c742ac48d32bChris Lattner 15807310fb11f2a074069bf9ec3fc169c742ac48d32bChris Lattner // Since this produces two values, make sure to remember that we legalized 15817310fb11f2a074069bf9ec3fc169c742ac48d32bChris Lattner // both of them. 1582c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); 15837310fb11f2a074069bf9ec3fc169c742ac48d32bChris Lattner AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); 1584c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner return Result; 15857310fb11f2a074069bf9ec3fc169c742ac48d32bChris Lattner } 15863e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 15873e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 15883e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::RET: 15893e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. 15906831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 15916831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Ensure that libcalls are emitted before a return. 15926831a815999dde4cf801e2076e66b4943964daf2Chris Lattner Tmp1 = DAG.getNode(ISD::TokenFactor, MVT::Other, Tmp1, LastCALLSEQ_END); 15936831a815999dde4cf801e2076e66b4943964daf2Chris Lattner Tmp1 = LegalizeOp(Tmp1); 15946831a815999dde4cf801e2076e66b4943964daf2Chris Lattner LastCALLSEQ_END = DAG.getEntryNode(); 1595f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner 15963e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner switch (Node->getNumOperands()) { 15978e7d056bc5c0688501f6721994c8f4074d699c69Evan Cheng case 3: // ret val 159898f8aeb45fc1e54437cbb8f2a7445c609deab832Evan Cheng Tmp2 = Node->getOperand(1); 15998e7d056bc5c0688501f6721994c8f4074d699c69Evan Cheng Tmp3 = Node->getOperand(2); // Signness 1600f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner switch (getTypeAction(Tmp2.getValueType())) { 16013e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case Legal: 16028e7d056bc5c0688501f6721994c8f4074d699c69Evan Cheng Result = DAG.UpdateNodeOperands(Result, Tmp1, LegalizeOp(Tmp2), Tmp3); 16033e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 1604f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner case Expand: 1605f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner if (Tmp2.getValueType() != MVT::Vector) { 1606f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner SDOperand Lo, Hi; 1607f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner ExpandOp(Tmp2, Lo, Hi); 160813acce3ef03d29679c2b241bdba6ca015644e8b6Evan Cheng if (Hi.Val) 160913acce3ef03d29679c2b241bdba6ca015644e8b6Evan Cheng Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3); 161013acce3ef03d29679c2b241bdba6ca015644e8b6Evan Cheng else 161113acce3ef03d29679c2b241bdba6ca015644e8b6Evan Cheng Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3); 1612f921a518912df706a8edf1f867f52e8afc6e2b55Chris Lattner Result = LegalizeOp(Result); 1613f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner } else { 1614f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner SDNode *InVal = Tmp2.Val; 1615f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner unsigned NumElems = 1616f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner cast<ConstantSDNode>(*(InVal->op_end()-2))->getValue(); 1617f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner MVT::ValueType EVT = cast<VTSDNode>(*(InVal->op_end()-1))->getVT(); 1618f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner 1619f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner // Figure out if there is a Packed type corresponding to this Vector 1620f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner // type. If so, convert to the packed type. 1621f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems); 1622f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner if (TVT != MVT::Other && TLI.isTypeLegal(TVT)) { 1623f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner // Turn this into a return of the packed type. 1624f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner Tmp2 = PackVectorOp(Tmp2, TVT); 16258e7d056bc5c0688501f6721994c8f4074d699c69Evan Cheng Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); 1626f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner } else if (NumElems == 1) { 1627f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner // Turn this into a return of the scalar type. 1628f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner Tmp2 = PackVectorOp(Tmp2, EVT); 16298e7d056bc5c0688501f6721994c8f4074d699c69Evan Cheng Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); 1630b49e52c7e2d828c45583f862c0f7e1a4a2649acaChris Lattner 1631b49e52c7e2d828c45583f862c0f7e1a4a2649acaChris Lattner // FIXME: Returns of gcc generic vectors smaller than a legal type 1632b49e52c7e2d828c45583f862c0f7e1a4a2649acaChris Lattner // should be returned in integer registers! 1633b49e52c7e2d828c45583f862c0f7e1a4a2649acaChris Lattner 1634f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner // The scalarized value type may not be legal, e.g. it might require 1635f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner // promotion or expansion. Relegalize the return. 1636f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner Result = LegalizeOp(Result); 1637f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner } else { 1638b49e52c7e2d828c45583f862c0f7e1a4a2649acaChris Lattner // FIXME: Returns of gcc generic vectors larger than a legal vector 1639b49e52c7e2d828c45583f862c0f7e1a4a2649acaChris Lattner // type should be returned by reference! 1640f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner SDOperand Lo, Hi; 1641f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner SplitVectorOp(Tmp2, Lo, Hi); 16428e7d056bc5c0688501f6721994c8f4074d699c69Evan Cheng Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi, Tmp3); 1643f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner Result = LegalizeOp(Result); 1644f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner } 1645f87324e44de88da5b3d57d6aeda5bc9d30f86374Chris Lattner } 1646edf128a7fa90f2b0b7ee24741a04a7ae1ecd6f7eMisha Brukman break; 16473e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case Promote: 16488b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner Tmp2 = PromoteOp(Node->getOperand(1)); 16498e7d056bc5c0688501f6721994c8f4074d699c69Evan Cheng Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); 1650c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = LegalizeOp(Result); 16518b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner break; 16523e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 16533e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 16543e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case 1: // ret void 1655c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1); 16563e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 16573e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner default: { // ret <values> 1658f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner SmallVector<SDOperand, 8> NewValues; 16593e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner NewValues.push_back(Tmp1); 16608e7d056bc5c0688501f6721994c8f4074d699c69Evan Cheng for (unsigned i = 1, e = Node->getNumOperands(); i < e; i += 2) 16613e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner switch (getTypeAction(Node->getOperand(i).getValueType())) { 16623e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case Legal: 16634e6c74689944be1de80c99dc0688ec0bcbd743aaChris Lattner NewValues.push_back(LegalizeOp(Node->getOperand(i))); 16648e7d056bc5c0688501f6721994c8f4074d699c69Evan Cheng NewValues.push_back(Node->getOperand(i+1)); 16653e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 16663e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case Expand: { 16673e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner SDOperand Lo, Hi; 1668b49e52c7e2d828c45583f862c0f7e1a4a2649acaChris Lattner assert(Node->getOperand(i).getValueType() != MVT::Vector && 1669b49e52c7e2d828c45583f862c0f7e1a4a2649acaChris Lattner "FIXME: TODO: implement returning non-legal vector types!"); 16703e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner ExpandOp(Node->getOperand(i), Lo, Hi); 16713e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner NewValues.push_back(Lo); 16728e7d056bc5c0688501f6721994c8f4074d699c69Evan Cheng NewValues.push_back(Node->getOperand(i+1)); 167313acce3ef03d29679c2b241bdba6ca015644e8b6Evan Cheng if (Hi.Val) { 167413acce3ef03d29679c2b241bdba6ca015644e8b6Evan Cheng NewValues.push_back(Hi); 167513acce3ef03d29679c2b241bdba6ca015644e8b6Evan Cheng NewValues.push_back(Node->getOperand(i+1)); 167613acce3ef03d29679c2b241bdba6ca015644e8b6Evan Cheng } 1677edf128a7fa90f2b0b7ee24741a04a7ae1ecd6f7eMisha Brukman break; 16783e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 16793e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case Promote: 16808b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner assert(0 && "Can't promote multiple return value yet!"); 16813e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 1682c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner 1683c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner if (NewValues.size() == Node->getNumOperands()) 1684f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner Result = DAG.UpdateNodeOperands(Result, &NewValues[0],NewValues.size()); 1685c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner else 1686f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner Result = DAG.getNode(ISD::RET, MVT::Other, 1687f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner &NewValues[0], NewValues.size()); 16883e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 16893e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 16903e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 169117c428e23dbeac1f985d725905ce6be1c725491fEvan Cheng 16926862dbc446f2f633f6f4905d07a3bafd96741da2Chris Lattner if (Result.getOpcode() == ISD::RET) { 16936862dbc446f2f633f6f4905d07a3bafd96741da2Chris Lattner switch (TLI.getOperationAction(Result.getOpcode(), MVT::Other)) { 16946862dbc446f2f633f6f4905d07a3bafd96741da2Chris Lattner default: assert(0 && "This action is not supported yet!"); 16956862dbc446f2f633f6f4905d07a3bafd96741da2Chris Lattner case TargetLowering::Legal: break; 16966862dbc446f2f633f6f4905d07a3bafd96741da2Chris Lattner case TargetLowering::Custom: 16976862dbc446f2f633f6f4905d07a3bafd96741da2Chris Lattner Tmp1 = TLI.LowerOperation(Result, DAG); 16986862dbc446f2f633f6f4905d07a3bafd96741da2Chris Lattner if (Tmp1.Val) Result = Tmp1; 16996862dbc446f2f633f6f4905d07a3bafd96741da2Chris Lattner break; 17006862dbc446f2f633f6f4905d07a3bafd96741da2Chris Lattner } 170117c428e23dbeac1f985d725905ce6be1c725491fEvan Cheng } 17023e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 1703f3fd9fe20dbcb40f3dffc1518ab955a0b5d6fa23Evan Cheng case ISD::STORE: { 17048b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng StoreSDNode *ST = cast<StoreSDNode>(Node); 17058b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Tmp1 = LegalizeOp(ST->getChain()); // Legalize the chain. 17068b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Tmp2 = LegalizeOp(ST->getBasePtr()); // Legalize the pointer. 17078b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng 17088b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng if (!ST->isTruncatingStore()) { 1709d93d46ee7e0a0e539d42139b85c71b2b8c3968feChris Lattner // Turn 'store float 1.0, Ptr' -> 'store int 0x12345678, Ptr' 1710d93d46ee7e0a0e539d42139b85c71b2b8c3968feChris Lattner // FIXME: We shouldn't do this for TargetConstantFP's. 1711d93d46ee7e0a0e539d42139b85c71b2b8c3968feChris Lattner // FIXME: move this to the DAG Combiner! Note that we can't regress due 1712d93d46ee7e0a0e539d42139b85c71b2b8c3968feChris Lattner // to phase ordering between legalized code and the dag combiner. This 1713d93d46ee7e0a0e539d42139b85c71b2b8c3968feChris Lattner // probably means that we need to integrate dag combiner and legalizer 1714d93d46ee7e0a0e539d42139b85c71b2b8c3968feChris Lattner // together. 1715d93d46ee7e0a0e539d42139b85c71b2b8c3968feChris Lattner if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(ST->getValue())) { 1716d93d46ee7e0a0e539d42139b85c71b2b8c3968feChris Lattner if (CFP->getValueType(0) == MVT::f32) { 1717d93d46ee7e0a0e539d42139b85c71b2b8c3968feChris Lattner Tmp3 = DAG.getConstant(FloatToBits(CFP->getValue()), MVT::i32); 1718d93d46ee7e0a0e539d42139b85c71b2b8c3968feChris Lattner } else { 1719d93d46ee7e0a0e539d42139b85c71b2b8c3968feChris Lattner assert(CFP->getValueType(0) == MVT::f64 && "Unknown FP type!"); 1720d93d46ee7e0a0e539d42139b85c71b2b8c3968feChris Lattner Tmp3 = DAG.getConstant(DoubleToBits(CFP->getValue()), MVT::i64); 1721d93d46ee7e0a0e539d42139b85c71b2b8c3968feChris Lattner } 1722d93d46ee7e0a0e539d42139b85c71b2b8c3968feChris Lattner Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), 1723d93d46ee7e0a0e539d42139b85c71b2b8c3968feChris Lattner ST->getSrcValueOffset()); 1724d93d46ee7e0a0e539d42139b85c71b2b8c3968feChris Lattner break; 1725d93d46ee7e0a0e539d42139b85c71b2b8c3968feChris Lattner } 1726d93d46ee7e0a0e539d42139b85c71b2b8c3968feChris Lattner 17278b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng switch (getTypeAction(ST->getStoredVT())) { 17288b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng case Legal: { 17298b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Tmp3 = LegalizeOp(ST->getValue()); 17302efce0a589e2a688a1a06b5dc2ed0db32ae79924Chris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, 17318b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng ST->getOffset()); 17328b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng 17338b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng MVT::ValueType VT = Tmp3.getValueType(); 17348b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng switch (TLI.getOperationAction(ISD::STORE, VT)) { 17358b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng default: assert(0 && "This action is not supported yet!"); 17368b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng case TargetLowering::Legal: break; 17378b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng case TargetLowering::Custom: 17388b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Tmp1 = TLI.LowerOperation(Result, DAG); 17398b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng if (Tmp1.Val) Result = Tmp1; 17408b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng break; 17418b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng case TargetLowering::Promote: 17428b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng assert(MVT::isVector(VT) && "Unknown legal promote case!"); 17438b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Tmp3 = DAG.getNode(ISD::BIT_CONVERT, 17448b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng TLI.getTypeToPromoteTo(ISD::STORE, VT), Tmp3); 17458b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Result = DAG.getStore(Tmp1, Tmp3, Tmp2, 17468b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng ST->getSrcValue(), ST->getSrcValueOffset()); 17478b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng break; 17488b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng } 17492efce0a589e2a688a1a06b5dc2ed0db32ae79924Chris Lattner break; 1750f3fd9fe20dbcb40f3dffc1518ab955a0b5d6fa23Evan Cheng } 17518b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng case Promote: 17528b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng // Truncate the value and store the result. 17538b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Tmp3 = PromoteOp(ST->getValue()); 17548b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), 17558b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng ST->getSrcValueOffset(), ST->getStoredVT()); 17568b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng break; 175703c8546ec57523970874917854a2fb77b1ff598eChris Lattner 17588b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng case Expand: 17598b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng unsigned IncrementSize = 0; 17608b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng SDOperand Lo, Hi; 1761c7029805ef35ce9805931067b841e6af11db382eChris Lattner 17628b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng // If this is a vector type, then we have to calculate the increment as 17638b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng // the product of the element size in bytes, and the number of elements 17648b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng // in the high half of the vector. 17658b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng if (ST->getValue().getValueType() == MVT::Vector) { 17668b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng SDNode *InVal = ST->getValue().Val; 17678b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng unsigned NumElems = 17688b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng cast<ConstantSDNode>(*(InVal->op_end()-2))->getValue(); 17698b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng MVT::ValueType EVT = cast<VTSDNode>(*(InVal->op_end()-1))->getVT(); 17708b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng 17718b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng // Figure out if there is a Packed type corresponding to this Vector 17728b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng // type. If so, convert to the packed type. 17738b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems); 17748b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng if (TVT != MVT::Other && TLI.isTypeLegal(TVT)) { 17758b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng // Turn this into a normal store of the packed type. 17768b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Tmp3 = PackVectorOp(Node->getOperand(1), TVT); 17778b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), 17788b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng ST->getSrcValueOffset()); 17798b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Result = LegalizeOp(Result); 17808b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng break; 17818b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng } else if (NumElems == 1) { 17828b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng // Turn this into a normal store of the scalar type. 17838b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Tmp3 = PackVectorOp(Node->getOperand(1), EVT); 17848b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), 17858b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng ST->getSrcValueOffset()); 17868b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng // The scalarized value type may not be legal, e.g. it might require 17878b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng // promotion or expansion. Relegalize the scalar store. 17888b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Result = LegalizeOp(Result); 17898b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng break; 17908b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng } else { 17918b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng SplitVectorOp(Node->getOperand(1), Lo, Hi); 17928b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng IncrementSize = NumElems/2 * MVT::getSizeInBits(EVT)/8; 17938b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng } 1794c7029805ef35ce9805931067b841e6af11db382eChris Lattner } else { 17958b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng ExpandOp(Node->getOperand(1), Lo, Hi); 17967b2b5c846c371f58db73f453a007e52eda62da89Evan Cheng IncrementSize = Hi.Val ? MVT::getSizeInBits(Hi.getValueType())/8 : 0; 17978b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng 17988b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng if (!TLI.isLittleEndian()) 17998b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng std::swap(Lo, Hi); 1800c7029805ef35ce9805931067b841e6af11db382eChris Lattner } 1801c7029805ef35ce9805931067b841e6af11db382eChris Lattner 18028b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Lo = DAG.getStore(Tmp1, Lo, Tmp2, ST->getSrcValue(), 18038b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng ST->getSrcValueOffset()); 18047b2b5c846c371f58db73f453a007e52eda62da89Evan Cheng 18057b2b5c846c371f58db73f453a007e52eda62da89Evan Cheng if (Hi.Val == NULL) { 18067b2b5c846c371f58db73f453a007e52eda62da89Evan Cheng // Must be int <-> float one-to-one expansion. 18077b2b5c846c371f58db73f453a007e52eda62da89Evan Cheng Result = Lo; 18087b2b5c846c371f58db73f453a007e52eda62da89Evan Cheng break; 18097b2b5c846c371f58db73f453a007e52eda62da89Evan Cheng } 18107b2b5c846c371f58db73f453a007e52eda62da89Evan Cheng 18118b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Tmp2 = DAG.getNode(ISD::ADD, Tmp2.getValueType(), Tmp2, 18128b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng getIntPtrConstant(IncrementSize)); 18138b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng assert(isTypeLegal(Tmp2.getValueType()) && 18148b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng "Pointers must be legal!"); 18158b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng // FIXME: This sets the srcvalue of both halves to be the same, which is 18168b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng // wrong. 18178b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Hi = DAG.getStore(Tmp1, Hi, Tmp2, ST->getSrcValue(), 18188b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng ST->getSrcValueOffset()); 18198b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Result = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo, Hi); 18208b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng break; 18218b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng } 18228b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng } else { 18238b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng // Truncating store 18248b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng assert(isTypeLegal(ST->getValue().getValueType()) && 18258b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng "Cannot handle illegal TRUNCSTORE yet!"); 18268b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Tmp3 = LegalizeOp(ST->getValue()); 18278b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng 18288b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng // The only promote case we handle is TRUNCSTORE:i1 X into 18298b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng // -> TRUNCSTORE:i8 (and X, 1) 18308b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng if (ST->getStoredVT() == MVT::i1 && 18318b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng TLI.getStoreXAction(MVT::i1) == TargetLowering::Promote) { 18328b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng // Promote the bool to a mask then store. 18338b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Tmp3 = DAG.getNode(ISD::AND, Tmp3.getValueType(), Tmp3, 18348b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng DAG.getConstant(1, Tmp3.getValueType())); 18358b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Result = DAG.getTruncStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(), 18368b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng ST->getSrcValueOffset(), MVT::i8); 18378b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng } else if (Tmp1 != ST->getChain() || Tmp3 != ST->getValue() || 18388b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Tmp2 != ST->getBasePtr()) { 18398b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp3, Tmp2, 18408b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng ST->getOffset()); 1841d9731af75b38f30c02f19d6e81333b9c2599ad5fChris Lattner } 1842c7029805ef35ce9805931067b841e6af11db382eChris Lattner 18438b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng MVT::ValueType StVT = cast<StoreSDNode>(Result.Val)->getStoredVT(); 18448b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng switch (TLI.getStoreXAction(StVT)) { 18458b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng default: assert(0 && "This action is not supported yet!"); 18468b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng case TargetLowering::Legal: break; 18478b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng case TargetLowering::Custom: 18488b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Tmp1 = TLI.LowerOperation(Result, DAG); 18498b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng if (Tmp1.Val) Result = Tmp1; 18508b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng break; 18518b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng } 18523e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 18533e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 1854f3fd9fe20dbcb40f3dffc1518ab955a0b5d6fa23Evan Cheng } 185595762124a1d781cc0f8cbc4c22e9c5c1358d7ea0Andrew Lenharth case ISD::PCMARKER: 185695762124a1d781cc0f8cbc4c22e9c5c1358d7ea0Andrew Lenharth Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. 1857c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); 185895762124a1d781cc0f8cbc4c22e9c5c1358d7ea0Andrew Lenharth break; 1859140d53c99c3a70b9d3858a3c87f8ecb098994748Chris Lattner case ISD::STACKSAVE: 1860140d53c99c3a70b9d3858a3c87f8ecb098994748Chris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. 1861c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1); 1862c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp1 = Result.getValue(0); 1863c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp2 = Result.getValue(1); 1864456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner 1865140d53c99c3a70b9d3858a3c87f8ecb098994748Chris Lattner switch (TLI.getOperationAction(ISD::STACKSAVE, MVT::Other)) { 1866140d53c99c3a70b9d3858a3c87f8ecb098994748Chris Lattner default: assert(0 && "This action is not supported yet!"); 1867456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Legal: break; 1868456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Custom: 1869c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp3 = TLI.LowerOperation(Result, DAG); 1870c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner if (Tmp3.Val) { 1871c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp1 = LegalizeOp(Tmp3); 1872c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp2 = LegalizeOp(Tmp3.getValue(1)); 1873140d53c99c3a70b9d3858a3c87f8ecb098994748Chris Lattner } 1874456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner break; 1875140d53c99c3a70b9d3858a3c87f8ecb098994748Chris Lattner case TargetLowering::Expand: 18764f0d8e4018d50c5796660a4fa167763f46259646Chris Lattner // Expand to CopyFromReg if the target set 18774f0d8e4018d50c5796660a4fa167763f46259646Chris Lattner // StackPointerRegisterToSaveRestore. 18784f0d8e4018d50c5796660a4fa167763f46259646Chris Lattner if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { 1879c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp1 = DAG.getCopyFromReg(Result.getOperand(0), SP, 18804f0d8e4018d50c5796660a4fa167763f46259646Chris Lattner Node->getValueType(0)); 1881c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp2 = Tmp1.getValue(1); 18824f0d8e4018d50c5796660a4fa167763f46259646Chris Lattner } else { 1883c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp1 = DAG.getNode(ISD::UNDEF, Node->getValueType(0)); 1884c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp2 = Node->getOperand(0); 18854f0d8e4018d50c5796660a4fa167763f46259646Chris Lattner } 1886456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner break; 1887140d53c99c3a70b9d3858a3c87f8ecb098994748Chris Lattner } 1888456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner 1889456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner // Since stacksave produce two values, make sure to remember that we 1890456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner // legalized both of them. 1891c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner AddLegalizedOperand(SDOperand(Node, 0), Tmp1); 1892c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner AddLegalizedOperand(SDOperand(Node, 1), Tmp2); 1893c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner return Op.ResNo ? Tmp2 : Tmp1; 1894456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner 1895140d53c99c3a70b9d3858a3c87f8ecb098994748Chris Lattner case ISD::STACKRESTORE: 1896140d53c99c3a70b9d3858a3c87f8ecb098994748Chris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. 1897140d53c99c3a70b9d3858a3c87f8ecb098994748Chris Lattner Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. 1898c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); 1899140d53c99c3a70b9d3858a3c87f8ecb098994748Chris Lattner 1900140d53c99c3a70b9d3858a3c87f8ecb098994748Chris Lattner switch (TLI.getOperationAction(ISD::STACKRESTORE, MVT::Other)) { 1901140d53c99c3a70b9d3858a3c87f8ecb098994748Chris Lattner default: assert(0 && "This action is not supported yet!"); 1902456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Legal: break; 1903456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Custom: 1904456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp1 = TLI.LowerOperation(Result, DAG); 1905456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (Tmp1.Val) Result = Tmp1; 1906140d53c99c3a70b9d3858a3c87f8ecb098994748Chris Lattner break; 1907140d53c99c3a70b9d3858a3c87f8ecb098994748Chris Lattner case TargetLowering::Expand: 19084f0d8e4018d50c5796660a4fa167763f46259646Chris Lattner // Expand to CopyToReg if the target set 19094f0d8e4018d50c5796660a4fa167763f46259646Chris Lattner // StackPointerRegisterToSaveRestore. 19104f0d8e4018d50c5796660a4fa167763f46259646Chris Lattner if (unsigned SP = TLI.getStackPointerRegisterToSaveRestore()) { 19114f0d8e4018d50c5796660a4fa167763f46259646Chris Lattner Result = DAG.getCopyToReg(Tmp1, SP, Tmp2); 19124f0d8e4018d50c5796660a4fa167763f46259646Chris Lattner } else { 19134f0d8e4018d50c5796660a4fa167763f46259646Chris Lattner Result = Tmp1; 19144f0d8e4018d50c5796660a4fa167763f46259646Chris Lattner } 1915140d53c99c3a70b9d3858a3c87f8ecb098994748Chris Lattner break; 1916140d53c99c3a70b9d3858a3c87f8ecb098994748Chris Lattner } 1917140d53c99c3a70b9d3858a3c87f8ecb098994748Chris Lattner break; 1918140d53c99c3a70b9d3858a3c87f8ecb098994748Chris Lattner 191951b8d54922350b7e1c2cd5a5183ef2c5f5d1b1d5Andrew Lenharth case ISD::READCYCLECOUNTER: 192051b8d54922350b7e1c2cd5a5183ef2c5f5d1b1d5Andrew Lenharth Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain 1921c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1); 1922f0b3ba6752a49a8868d423ddc2704a52b7101571Evan Cheng switch (TLI.getOperationAction(ISD::READCYCLECOUNTER, 1923f0b3ba6752a49a8868d423ddc2704a52b7101571Evan Cheng Node->getValueType(0))) { 1924f0b3ba6752a49a8868d423ddc2704a52b7101571Evan Cheng default: assert(0 && "This action is not supported yet!"); 19256a16c5ab2d7786583d3c9a79646dc85fbda6cd41Evan Cheng case TargetLowering::Legal: 19266a16c5ab2d7786583d3c9a79646dc85fbda6cd41Evan Cheng Tmp1 = Result.getValue(0); 19276a16c5ab2d7786583d3c9a79646dc85fbda6cd41Evan Cheng Tmp2 = Result.getValue(1); 19286a16c5ab2d7786583d3c9a79646dc85fbda6cd41Evan Cheng break; 1929f0b3ba6752a49a8868d423ddc2704a52b7101571Evan Cheng case TargetLowering::Custom: 1930f0b3ba6752a49a8868d423ddc2704a52b7101571Evan Cheng Result = TLI.LowerOperation(Result, DAG); 19316a16c5ab2d7786583d3c9a79646dc85fbda6cd41Evan Cheng Tmp1 = LegalizeOp(Result.getValue(0)); 19326a16c5ab2d7786583d3c9a79646dc85fbda6cd41Evan Cheng Tmp2 = LegalizeOp(Result.getValue(1)); 1933f0b3ba6752a49a8868d423ddc2704a52b7101571Evan Cheng break; 1934f0b3ba6752a49a8868d423ddc2704a52b7101571Evan Cheng } 193549c709f891a3e49db58b56ca94eafa98cbb12c4dAndrew Lenharth 193649c709f891a3e49db58b56ca94eafa98cbb12c4dAndrew Lenharth // Since rdcc produce two values, make sure to remember that we legalized 193749c709f891a3e49db58b56ca94eafa98cbb12c4dAndrew Lenharth // both of them. 19386a16c5ab2d7786583d3c9a79646dc85fbda6cd41Evan Cheng AddLegalizedOperand(SDOperand(Node, 0), Tmp1); 19396a16c5ab2d7786583d3c9a79646dc85fbda6cd41Evan Cheng AddLegalizedOperand(SDOperand(Node, 1), Tmp2); 1940c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner return Result; 1941f70e30b41dc6a92733681dcea2c06d8b3dd488dbAndrew Lenharth 19422ee743ff9be43c350075a2fa15d11a79bff36775Chris Lattner case ISD::SELECT: 194347e9223e06390897c3834f8c527001df392570ffChris Lattner switch (getTypeAction(Node->getOperand(0).getValueType())) { 194447e9223e06390897c3834f8c527001df392570ffChris Lattner case Expand: assert(0 && "It's impossible to expand bools"); 194547e9223e06390897c3834f8c527001df392570ffChris Lattner case Legal: 194647e9223e06390897c3834f8c527001df392570ffChris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the condition. 194747e9223e06390897c3834f8c527001df392570ffChris Lattner break; 194847e9223e06390897c3834f8c527001df392570ffChris Lattner case Promote: 194947e9223e06390897c3834f8c527001df392570ffChris Lattner Tmp1 = PromoteOp(Node->getOperand(0)); // Promote the condition. 1950b6c806045bbd4a650f90f613a96cee01a1584412Chris Lattner // Make sure the condition is either zero or one. 1951b6c806045bbd4a650f90f613a96cee01a1584412Chris Lattner if (!TLI.MaskedValueIsZero(Tmp1, 1952b6c806045bbd4a650f90f613a96cee01a1584412Chris Lattner MVT::getIntVTBitMask(Tmp1.getValueType())^1)) 1953b6c806045bbd4a650f90f613a96cee01a1584412Chris Lattner Tmp1 = DAG.getZeroExtendInReg(Tmp1, MVT::i1); 195447e9223e06390897c3834f8c527001df392570ffChris Lattner break; 195547e9223e06390897c3834f8c527001df392570ffChris Lattner } 19563e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner Tmp2 = LegalizeOp(Node->getOperand(1)); // TrueVal 19572ee743ff9be43c350075a2fa15d11a79bff36775Chris Lattner Tmp3 = LegalizeOp(Node->getOperand(2)); // FalseVal 195855ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner 1959c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); 1960456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner 1961b942a3dd5f9318b2c57f137d2991440c2f0262adNate Begeman switch (TLI.getOperationAction(ISD::SELECT, Tmp2.getValueType())) { 196255ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner default: assert(0 && "This action is not supported yet!"); 1963456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Legal: break; 1964456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Custom: { 1965456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp1 = TLI.LowerOperation(Result, DAG); 1966456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (Tmp1.Val) Result = Tmp1; 1967456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner break; 1968456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner } 19699373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman case TargetLowering::Expand: 19709373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman if (Tmp1.getOpcode() == ISD::SETCC) { 19719373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman Result = DAG.getSelectCC(Tmp1.getOperand(0), Tmp1.getOperand(1), 19729373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman Tmp2, Tmp3, 19739373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman cast<CondCodeSDNode>(Tmp1.getOperand(2))->get()); 19749373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman } else { 19759373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman Result = DAG.getSelectCC(Tmp1, 19769373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman DAG.getConstant(0, Tmp1.getValueType()), 19779373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman Tmp2, Tmp3, ISD::SETNE); 19789373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman } 197955ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner break; 198055ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner case TargetLowering::Promote: { 198155ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner MVT::ValueType NVT = 198255ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner TLI.getTypeToPromoteTo(ISD::SELECT, Tmp2.getValueType()); 198355ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner unsigned ExtOp, TruncOp; 198441f6cbbeb21d7d4376b8c0302b9766c3e43be5f2Evan Cheng if (MVT::isVector(Tmp2.getValueType())) { 198541f6cbbeb21d7d4376b8c0302b9766c3e43be5f2Evan Cheng ExtOp = ISD::BIT_CONVERT; 198641f6cbbeb21d7d4376b8c0302b9766c3e43be5f2Evan Cheng TruncOp = ISD::BIT_CONVERT; 198741f6cbbeb21d7d4376b8c0302b9766c3e43be5f2Evan Cheng } else if (MVT::isInteger(Tmp2.getValueType())) { 1988456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner ExtOp = ISD::ANY_EXTEND; 1989456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner TruncOp = ISD::TRUNCATE; 199055ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner } else { 1991456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner ExtOp = ISD::FP_EXTEND; 1992456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner TruncOp = ISD::FP_ROUND; 199355ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner } 199455ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner // Promote each of the values to the new type. 199555ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner Tmp2 = DAG.getNode(ExtOp, NVT, Tmp2); 199655ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner Tmp3 = DAG.getNode(ExtOp, NVT, Tmp3); 199755ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner // Perform the larger operation, then round down. 199855ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner Result = DAG.getNode(ISD::SELECT, NVT, Tmp1, Tmp2,Tmp3); 199955ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner Result = DAG.getNode(TruncOp, Node->getValueType(0), Result); 200055ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner break; 200155ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner } 200255ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner } 20033e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 2004750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case ISD::SELECT_CC: { 2005750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp1 = Node->getOperand(0); // LHS 2006750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp2 = Node->getOperand(1); // RHS 20079373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman Tmp3 = LegalizeOp(Node->getOperand(2)); // True 20089373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman Tmp4 = LegalizeOp(Node->getOperand(3)); // False 2009750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman SDOperand CC = Node->getOperand(4); 20109373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman 2011750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman LegalizeSetCCOperands(Tmp1, Tmp2, CC); 2012750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman 2013750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // If we didn't get both a LHS and RHS back from LegalizeSetCCOperands, 2014750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // the LHS is a legal SETCC itself. In this case, we need to compare 2015750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // the result against zero to select between true and false values. 2016750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman if (Tmp2.Val == 0) { 2017750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp2 = DAG.getConstant(0, Tmp1.getValueType()); 2018750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman CC = DAG.getCondCode(ISD::SETNE); 2019750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman } 2020750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4, CC); 2021750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman 2022750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // Everything is legal, see if we should expand this op or something. 2023750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman switch (TLI.getOperationAction(ISD::SELECT_CC, Tmp3.getValueType())) { 2024750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman default: assert(0 && "This action is not supported yet!"); 2025750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case TargetLowering::Legal: break; 2026750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case TargetLowering::Custom: 2027750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp1 = TLI.LowerOperation(Result, DAG); 2028750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman if (Tmp1.Val) Result = Tmp1; 20299373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman break; 20309373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman } 20319373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman break; 2032750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman } 20333e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::SETCC: 2034750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp1 = Node->getOperand(0); 2035750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp2 = Node->getOperand(1); 2036750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp3 = Node->getOperand(2); 2037750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman LegalizeSetCCOperands(Tmp1, Tmp2, Tmp3); 2038750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman 2039750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // If we had to Expand the SetCC operands into a SELECT node, then it may 2040750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // not always be possible to return a true LHS & RHS. In this case, just 2041750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // return the value we legalized, returned in the LHS 2042750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman if (Tmp2.Val == 0) { 2043750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Result = Tmp1; 20443e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 20453e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 2046b942a3dd5f9318b2c57f137d2991440c2f0262adNate Begeman 204773e142f2b6a3b5223de2d557d646f319ca8168cfChris Lattner switch (TLI.getOperationAction(ISD::SETCC, Tmp1.getValueType())) { 2048456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner default: assert(0 && "Cannot handle this action for SETCC yet!"); 2049456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Custom: 2050456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner isCustom = true; 2051456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner // FALLTHROUGH. 2052456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Legal: 20532b49c500838666dd0186d021389d4dd70ffda240Evan Cheng Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); 2054456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (isCustom) { 20552b49c500838666dd0186d021389d4dd70ffda240Evan Cheng Tmp4 = TLI.LowerOperation(Result, DAG); 20562b49c500838666dd0186d021389d4dd70ffda240Evan Cheng if (Tmp4.Val) Result = Tmp4; 2057456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner } 2058b942a3dd5f9318b2c57f137d2991440c2f0262adNate Begeman break; 2059ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth case TargetLowering::Promote: { 2060ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth // First step, figure out the appropriate operation to use. 2061ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth // Allow SETCC to not be supported for all legal data types 2062ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth // Mostly this targets FP 2063ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth MVT::ValueType NewInTy = Node->getOperand(0).getValueType(); 2064ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth MVT::ValueType OldVT = NewInTy; 2065ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth 2066ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth // Scan for the appropriate larger type to use. 2067ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth while (1) { 2068ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth NewInTy = (MVT::ValueType)(NewInTy+1); 2069ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth 2070ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth assert(MVT::isInteger(NewInTy) == MVT::isInteger(OldVT) && 2071ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth "Fell off of the edge of the integer world"); 2072ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth assert(MVT::isFloatingPoint(NewInTy) == MVT::isFloatingPoint(OldVT) && 2073ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth "Fell off of the edge of the floating point world"); 2074ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth 2075ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth // If the target supports SETCC of this type, use it. 20761ccf26a6392034a11827aeaa0d58d025ecb2b85aChris Lattner if (TLI.isOperationLegal(ISD::SETCC, NewInTy)) 2077ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth break; 2078ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth } 2079ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth if (MVT::isInteger(NewInTy)) 2080ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth assert(0 && "Cannot promote Legal Integer SETCC yet"); 2081ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth else { 2082ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth Tmp1 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp1); 2083ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth Tmp2 = DAG.getNode(ISD::FP_EXTEND, NewInTy, Tmp2); 2084ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth } 2085c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp1 = LegalizeOp(Tmp1); 2086c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp2 = LegalizeOp(Tmp2); 20872b49c500838666dd0186d021389d4dd70ffda240Evan Cheng Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); 2088433f8acefb78f1c8a2cf79c12b101ce7c4b20202Evan Cheng Result = LegalizeOp(Result); 20895e3efbc2ca459621400211f7370d7f121d4827d9Andrew Lenharth break; 2090ae35575957a3ab446e2766aa05d03020ced27d14Andrew Lenharth } 2091b942a3dd5f9318b2c57f137d2991440c2f0262adNate Begeman case TargetLowering::Expand: 2092b942a3dd5f9318b2c57f137d2991440c2f0262adNate Begeman // Expand a setcc node into a select_cc of the same condition, lhs, and 2093b942a3dd5f9318b2c57f137d2991440c2f0262adNate Begeman // rhs that selects between const 1 (true) and const 0 (false). 2094b942a3dd5f9318b2c57f137d2991440c2f0262adNate Begeman MVT::ValueType VT = Node->getValueType(0); 2095b942a3dd5f9318b2c57f137d2991440c2f0262adNate Begeman Result = DAG.getNode(ISD::SELECT_CC, VT, Tmp1, Tmp2, 2096b942a3dd5f9318b2c57f137d2991440c2f0262adNate Begeman DAG.getConstant(1, VT), DAG.getConstant(0, VT), 20972b49c500838666dd0186d021389d4dd70ffda240Evan Cheng Tmp3); 2098b942a3dd5f9318b2c57f137d2991440c2f0262adNate Begeman break; 2099b942a3dd5f9318b2c57f137d2991440c2f0262adNate Begeman } 21003e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 2101e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner case ISD::MEMSET: 2102e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner case ISD::MEMCPY: 2103e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner case ISD::MEMMOVE: { 2104deb692e756cd3826e4ecc6eaec3397177c8b89ceChris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); // Chain 2105e560521f1af300a10717ca5c73d42df9ffb1b121Chris Lattner Tmp2 = LegalizeOp(Node->getOperand(1)); // Pointer 2106e560521f1af300a10717ca5c73d42df9ffb1b121Chris Lattner 2107e560521f1af300a10717ca5c73d42df9ffb1b121Chris Lattner if (Node->getOpcode() == ISD::MEMSET) { // memset = ubyte 2108e560521f1af300a10717ca5c73d42df9ffb1b121Chris Lattner switch (getTypeAction(Node->getOperand(2).getValueType())) { 2109e560521f1af300a10717ca5c73d42df9ffb1b121Chris Lattner case Expand: assert(0 && "Cannot expand a byte!"); 2110e560521f1af300a10717ca5c73d42df9ffb1b121Chris Lattner case Legal: 2111deb692e756cd3826e4ecc6eaec3397177c8b89ceChris Lattner Tmp3 = LegalizeOp(Node->getOperand(2)); 2112e560521f1af300a10717ca5c73d42df9ffb1b121Chris Lattner break; 2113e560521f1af300a10717ca5c73d42df9ffb1b121Chris Lattner case Promote: 2114deb692e756cd3826e4ecc6eaec3397177c8b89ceChris Lattner Tmp3 = PromoteOp(Node->getOperand(2)); 2115e560521f1af300a10717ca5c73d42df9ffb1b121Chris Lattner break; 2116e560521f1af300a10717ca5c73d42df9ffb1b121Chris Lattner } 2117e560521f1af300a10717ca5c73d42df9ffb1b121Chris Lattner } else { 2118edf128a7fa90f2b0b7ee24741a04a7ae1ecd6f7eMisha Brukman Tmp3 = LegalizeOp(Node->getOperand(2)); // memcpy/move = pointer, 2119e560521f1af300a10717ca5c73d42df9ffb1b121Chris Lattner } 2120272455b404eabe70ce9e033ba19ec1b6cfe603a5Chris Lattner 2121272455b404eabe70ce9e033ba19ec1b6cfe603a5Chris Lattner SDOperand Tmp4; 2122272455b404eabe70ce9e033ba19ec1b6cfe603a5Chris Lattner switch (getTypeAction(Node->getOperand(3).getValueType())) { 21236814f1522dd7cdeb4674a9ad199f482a2e7aaea1Chris Lattner case Expand: { 21246814f1522dd7cdeb4674a9ad199f482a2e7aaea1Chris Lattner // Length is too big, just take the lo-part of the length. 21256814f1522dd7cdeb4674a9ad199f482a2e7aaea1Chris Lattner SDOperand HiPart; 2126fa9aa2b424d0a7d9f7201f8fdcf5ccfa05db3a80Chris Lattner ExpandOp(Node->getOperand(3), Tmp4, HiPart); 21276814f1522dd7cdeb4674a9ad199f482a2e7aaea1Chris Lattner break; 21286814f1522dd7cdeb4674a9ad199f482a2e7aaea1Chris Lattner } 2129e560521f1af300a10717ca5c73d42df9ffb1b121Chris Lattner case Legal: 2130e560521f1af300a10717ca5c73d42df9ffb1b121Chris Lattner Tmp4 = LegalizeOp(Node->getOperand(3)); 2131e560521f1af300a10717ca5c73d42df9ffb1b121Chris Lattner break; 2132e560521f1af300a10717ca5c73d42df9ffb1b121Chris Lattner case Promote: 2133e560521f1af300a10717ca5c73d42df9ffb1b121Chris Lattner Tmp4 = PromoteOp(Node->getOperand(3)); 2134272455b404eabe70ce9e033ba19ec1b6cfe603a5Chris Lattner break; 2135272455b404eabe70ce9e033ba19ec1b6cfe603a5Chris Lattner } 2136272455b404eabe70ce9e033ba19ec1b6cfe603a5Chris Lattner 2137272455b404eabe70ce9e033ba19ec1b6cfe603a5Chris Lattner SDOperand Tmp5; 2138272455b404eabe70ce9e033ba19ec1b6cfe603a5Chris Lattner switch (getTypeAction(Node->getOperand(4).getValueType())) { // uint 2139272455b404eabe70ce9e033ba19ec1b6cfe603a5Chris Lattner case Expand: assert(0 && "Cannot expand this yet!"); 2140272455b404eabe70ce9e033ba19ec1b6cfe603a5Chris Lattner case Legal: 2141272455b404eabe70ce9e033ba19ec1b6cfe603a5Chris Lattner Tmp5 = LegalizeOp(Node->getOperand(4)); 2142272455b404eabe70ce9e033ba19ec1b6cfe603a5Chris Lattner break; 2143272455b404eabe70ce9e033ba19ec1b6cfe603a5Chris Lattner case Promote: 2144e560521f1af300a10717ca5c73d42df9ffb1b121Chris Lattner Tmp5 = PromoteOp(Node->getOperand(4)); 2145e560521f1af300a10717ca5c73d42df9ffb1b121Chris Lattner break; 2146e560521f1af300a10717ca5c73d42df9ffb1b121Chris Lattner } 214755ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner 214855ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { 214955ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner default: assert(0 && "This action not implemented for this operation!"); 2150456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Custom: 2151456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner isCustom = true; 2152456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner // FALLTHROUGH 215355ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner case TargetLowering::Legal: 2154c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, Tmp4, Tmp5); 2155456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (isCustom) { 2156456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp1 = TLI.LowerOperation(Result, DAG); 2157456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (Tmp1.Val) Result = Tmp1; 2158456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner } 215955ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner break; 216055ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner case TargetLowering::Expand: { 2161e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner // Otherwise, the target does not support this operation. Lower the 2162e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner // operation to an explicit libcall as appropriate. 2163e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner MVT::ValueType IntPtr = TLI.getPointerTy(); 2164a69571c7991813c93cba64e88eced6899ce93d81Owen Anderson const Type *IntPtrTy = TLI.getTargetData()->getIntPtrType(); 216547857812e29324a9d1560796a05b53d3a9217fd9Reid Spencer TargetLowering::ArgListTy Args; 216647857812e29324a9d1560796a05b53d3a9217fd9Reid Spencer TargetLowering::ArgListEntry Entry; 2167e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner 21683bfbf4ea990930d153e58e153f319408341a94feReid Spencer const char *FnName = 0; 2169e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner if (Node->getOpcode() == ISD::MEMSET) { 2170b47b25cfda5aee910e128c89d08c630722eb480bReid Spencer Entry.Node = Tmp2; Entry.isSigned = false; Entry.Ty = IntPtrTy; 2171b10308e440c80dd6ffb4b478f741ff7e5f30cb48Anton Korobeynikov Entry.isInReg = false; 217247857812e29324a9d1560796a05b53d3a9217fd9Reid Spencer Args.push_back(Entry); 2173dca7abed918c8191de6e258ddf394cf11de240f2Chris Lattner // Extend the (previously legalized) ubyte argument to be an int value 2174dca7abed918c8191de6e258ddf394cf11de240f2Chris Lattner // for the call. 2175dca7abed918c8191de6e258ddf394cf11de240f2Chris Lattner if (Tmp3.getValueType() > MVT::i32) 2176dca7abed918c8191de6e258ddf394cf11de240f2Chris Lattner Tmp3 = DAG.getNode(ISD::TRUNCATE, MVT::i32, Tmp3); 2177dca7abed918c8191de6e258ddf394cf11de240f2Chris Lattner else 2178dca7abed918c8191de6e258ddf394cf11de240f2Chris Lattner Tmp3 = DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Tmp3); 217947857812e29324a9d1560796a05b53d3a9217fd9Reid Spencer Entry.Node = Tmp3; Entry.Ty = Type::Int32Ty; Entry.isSigned = true; 2180b10308e440c80dd6ffb4b478f741ff7e5f30cb48Anton Korobeynikov Entry.isInReg = false; 218147857812e29324a9d1560796a05b53d3a9217fd9Reid Spencer Args.push_back(Entry); 218247857812e29324a9d1560796a05b53d3a9217fd9Reid Spencer Entry.Node = Tmp4; Entry.Ty = IntPtrTy; Entry.isSigned = false; 218347857812e29324a9d1560796a05b53d3a9217fd9Reid Spencer Args.push_back(Entry); 2184e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner 2185e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner FnName = "memset"; 2186e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner } else if (Node->getOpcode() == ISD::MEMCPY || 2187e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner Node->getOpcode() == ISD::MEMMOVE) { 2188b10308e440c80dd6ffb4b478f741ff7e5f30cb48Anton Korobeynikov Entry.Ty = IntPtrTy; Entry.isSigned = false; Entry.isInReg = false; 2189b47b25cfda5aee910e128c89d08c630722eb480bReid Spencer Entry.Node = Tmp2; Args.push_back(Entry); 2190b47b25cfda5aee910e128c89d08c630722eb480bReid Spencer Entry.Node = Tmp3; Args.push_back(Entry); 2191b47b25cfda5aee910e128c89d08c630722eb480bReid Spencer Entry.Node = Tmp4; Args.push_back(Entry); 2192e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner FnName = Node->getOpcode() == ISD::MEMMOVE ? "memmove" : "memcpy"; 2193e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner } else { 2194e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner assert(0 && "Unknown op!"); 2195e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner } 219645982dad53cd184fe8947a1b0206b0b16964f359Chris Lattner 2197e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner std::pair<SDOperand,SDOperand> CallResult = 219847857812e29324a9d1560796a05b53d3a9217fd9Reid Spencer TLI.LowerCallTo(Tmp1, Type::VoidTy, false, false, CallingConv::C, false, 2199e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner DAG.getExternalSymbol(FnName, IntPtr), Args, DAG); 2200456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Result = CallResult.second; 220155ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner break; 220255ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner } 2203e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner } 2204e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner break; 2205e1bd822ddb0099406d9f280535461033dfeeb190Chris Lattner } 220652d08bd9d8a8dcc06148525c7fad6f2ebcad0a42Chris Lattner 22075b359c6c4f052e41579ad7da9af37db4f54207d9Chris Lattner case ISD::SHL_PARTS: 22085b359c6c4f052e41579ad7da9af37db4f54207d9Chris Lattner case ISD::SRA_PARTS: 22095b359c6c4f052e41579ad7da9af37db4f54207d9Chris Lattner case ISD::SRL_PARTS: { 2210f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner SmallVector<SDOperand, 8> Ops; 221184f6788044f9b1b47945e98ce23a6cf4d7d32579Chris Lattner bool Changed = false; 221284f6788044f9b1b47945e98ce23a6cf4d7d32579Chris Lattner for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { 221384f6788044f9b1b47945e98ce23a6cf4d7d32579Chris Lattner Ops.push_back(LegalizeOp(Node->getOperand(i))); 221484f6788044f9b1b47945e98ce23a6cf4d7d32579Chris Lattner Changed |= Ops.back() != Node->getOperand(i); 221584f6788044f9b1b47945e98ce23a6cf4d7d32579Chris Lattner } 2216c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner if (Changed) 2217f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner Result = DAG.UpdateNodeOperands(Result, &Ops[0], Ops.size()); 22182c8086f4b9916b2d02842be5e375276023225fbaChris Lattner 221905a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng switch (TLI.getOperationAction(Node->getOpcode(), 222005a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng Node->getValueType(0))) { 222105a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng default: assert(0 && "This action is not supported yet!"); 2222456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Legal: break; 2223456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Custom: 2224456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp1 = TLI.LowerOperation(Result, DAG); 2225456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (Tmp1.Val) { 2226456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner SDOperand Tmp2, RetVal(0, 0); 222705a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) { 2228456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp2 = LegalizeOp(Tmp1.getValue(i)); 222905a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng AddLegalizedOperand(SDOperand(Node, i), Tmp2); 223005a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng if (i == Op.ResNo) 223112f2274ba8c6af21e8b6c71ef872afe43a64b6d7Evan Cheng RetVal = Tmp2; 223205a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng } 2233269f8c069105e13f3845a8dbc7796ac9a15dc882Chris Lattner assert(RetVal.Val && "Illegal result number"); 223405a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng return RetVal; 223505a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng } 223605a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng break; 223705a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng } 223805a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng 22392c8086f4b9916b2d02842be5e375276023225fbaChris Lattner // Since these produce multiple values, make sure to remember that we 22402c8086f4b9916b2d02842be5e375276023225fbaChris Lattner // legalized all of them. 22412c8086f4b9916b2d02842be5e375276023225fbaChris Lattner for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) 22422c8086f4b9916b2d02842be5e375276023225fbaChris Lattner AddLegalizedOperand(SDOperand(Node, i), Result.getValue(i)); 22432c8086f4b9916b2d02842be5e375276023225fbaChris Lattner return Result.getValue(Op.ResNo); 224484f6788044f9b1b47945e98ce23a6cf4d7d32579Chris Lattner } 22452c8086f4b9916b2d02842be5e375276023225fbaChris Lattner 22462c8086f4b9916b2d02842be5e375276023225fbaChris Lattner // Binary operators 22473e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::ADD: 22483e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::SUB: 22493e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::MUL: 2250c7c16575fea9aeffe8a63ddabe7c3c25f81ed799Nate Begeman case ISD::MULHS: 2251c7c16575fea9aeffe8a63ddabe7c3c25f81ed799Nate Begeman case ISD::MULHU: 22523e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::UDIV: 22533e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::SDIV: 22543e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::AND: 22553e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::OR: 22563e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::XOR: 225703c0cf822e9a57109d1b4e6a2705d68852c93e1dChris Lattner case ISD::SHL: 225803c0cf822e9a57109d1b4e6a2705d68852c93e1dChris Lattner case ISD::SRL: 225903c0cf822e9a57109d1b4e6a2705d68852c93e1dChris Lattner case ISD::SRA: 226001b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner case ISD::FADD: 226101b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner case ISD::FSUB: 226201b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner case ISD::FMUL: 226301b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner case ISD::FDIV: 22643e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS 2265f2eb1396b8fe7b5b1c4bd5f27903209cfa4d20aeAndrew Lenharth switch (getTypeAction(Node->getOperand(1).getValueType())) { 2266f2eb1396b8fe7b5b1c4bd5f27903209cfa4d20aeAndrew Lenharth case Expand: assert(0 && "Not possible"); 2267f2eb1396b8fe7b5b1c4bd5f27903209cfa4d20aeAndrew Lenharth case Legal: 2268f2eb1396b8fe7b5b1c4bd5f27903209cfa4d20aeAndrew Lenharth Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS. 2269f2eb1396b8fe7b5b1c4bd5f27903209cfa4d20aeAndrew Lenharth break; 2270f2eb1396b8fe7b5b1c4bd5f27903209cfa4d20aeAndrew Lenharth case Promote: 2271f2eb1396b8fe7b5b1c4bd5f27903209cfa4d20aeAndrew Lenharth Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS. 2272f2eb1396b8fe7b5b1c4bd5f27903209cfa4d20aeAndrew Lenharth break; 2273f2eb1396b8fe7b5b1c4bd5f27903209cfa4d20aeAndrew Lenharth } 2274c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner 2275c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); 2276456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner 2277e8f65f1e62ea1d4f2ca9fd0137ae2e0ce20e26e1Andrew Lenharth switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { 2278bc70cf8be95f33f9aa30c8c3d0fd79e3fa636360Chris Lattner default: assert(0 && "BinOp legalize operation not supported"); 2279456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Legal: break; 2280456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Custom: 2281456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp1 = TLI.LowerOperation(Result, DAG); 2282456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (Tmp1.Val) Result = Tmp1; 228357030e36e41ebd982a24632e7cea5b584b2d49fcAndrew Lenharth break; 2284bc70cf8be95f33f9aa30c8c3d0fd79e3fa636360Chris Lattner case TargetLowering::Expand: { 228552cc1ea2a1a374b58801398460a6289723089d91Evan Cheng if (Node->getValueType(0) == MVT::i32) { 228652cc1ea2a1a374b58801398460a6289723089d91Evan Cheng switch (Node->getOpcode()) { 228752cc1ea2a1a374b58801398460a6289723089d91Evan Cheng default: assert(0 && "Do not know how to expand this integer BinOp!"); 228852cc1ea2a1a374b58801398460a6289723089d91Evan Cheng case ISD::UDIV: 228952cc1ea2a1a374b58801398460a6289723089d91Evan Cheng case ISD::SDIV: 229056966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng RTLIB::Libcall LC = Node->getOpcode() == ISD::UDIV 229156966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng ? RTLIB::UDIV_I32 : RTLIB::SDIV_I32; 229252cc1ea2a1a374b58801398460a6289723089d91Evan Cheng SDOperand Dummy; 229347857812e29324a9d1560796a05b53d3a9217fd9Reid Spencer bool isSigned = Node->getOpcode() == ISD::SDIV; 229456966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Result = ExpandLibCall(TLI.getLibcallName(LC), Node, isSigned, Dummy); 229552cc1ea2a1a374b58801398460a6289723089d91Evan Cheng }; 229652cc1ea2a1a374b58801398460a6289723089d91Evan Cheng break; 229752cc1ea2a1a374b58801398460a6289723089d91Evan Cheng } 229852cc1ea2a1a374b58801398460a6289723089d91Evan Cheng 2299bc70cf8be95f33f9aa30c8c3d0fd79e3fa636360Chris Lattner assert(MVT::isVector(Node->getValueType(0)) && 2300bc70cf8be95f33f9aa30c8c3d0fd79e3fa636360Chris Lattner "Cannot expand this binary operator!"); 2301bc70cf8be95f33f9aa30c8c3d0fd79e3fa636360Chris Lattner // Expand the operation into a bunch of nasty scalar code. 2302bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner SmallVector<SDOperand, 8> Ops; 2303bc70cf8be95f33f9aa30c8c3d0fd79e3fa636360Chris Lattner MVT::ValueType EltVT = MVT::getVectorBaseType(Node->getValueType(0)); 2304bc70cf8be95f33f9aa30c8c3d0fd79e3fa636360Chris Lattner MVT::ValueType PtrVT = TLI.getPointerTy(); 2305bc70cf8be95f33f9aa30c8c3d0fd79e3fa636360Chris Lattner for (unsigned i = 0, e = MVT::getVectorNumElements(Node->getValueType(0)); 2306bc70cf8be95f33f9aa30c8c3d0fd79e3fa636360Chris Lattner i != e; ++i) { 2307bc70cf8be95f33f9aa30c8c3d0fd79e3fa636360Chris Lattner SDOperand Idx = DAG.getConstant(i, PtrVT); 2308bc70cf8be95f33f9aa30c8c3d0fd79e3fa636360Chris Lattner SDOperand LHS = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp1, Idx); 2309bc70cf8be95f33f9aa30c8c3d0fd79e3fa636360Chris Lattner SDOperand RHS = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, EltVT, Tmp2, Idx); 2310bc70cf8be95f33f9aa30c8c3d0fd79e3fa636360Chris Lattner Ops.push_back(DAG.getNode(Node->getOpcode(), EltVT, LHS, RHS)); 2311bc70cf8be95f33f9aa30c8c3d0fd79e3fa636360Chris Lattner } 2312bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner Result = DAG.getNode(ISD::BUILD_VECTOR, Node->getValueType(0), 2313bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner &Ops[0], Ops.size()); 2314bc70cf8be95f33f9aa30c8c3d0fd79e3fa636360Chris Lattner break; 2315bc70cf8be95f33f9aa30c8c3d0fd79e3fa636360Chris Lattner } 2316cc9876124e7096d050e6750dd075758320f2cdceEvan Cheng case TargetLowering::Promote: { 2317cc9876124e7096d050e6750dd075758320f2cdceEvan Cheng switch (Node->getOpcode()) { 2318cc9876124e7096d050e6750dd075758320f2cdceEvan Cheng default: assert(0 && "Do not know how to promote this BinOp!"); 2319cc9876124e7096d050e6750dd075758320f2cdceEvan Cheng case ISD::AND: 2320cc9876124e7096d050e6750dd075758320f2cdceEvan Cheng case ISD::OR: 2321cc9876124e7096d050e6750dd075758320f2cdceEvan Cheng case ISD::XOR: { 2322cc9876124e7096d050e6750dd075758320f2cdceEvan Cheng MVT::ValueType OVT = Node->getValueType(0); 2323cc9876124e7096d050e6750dd075758320f2cdceEvan Cheng MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); 2324cc9876124e7096d050e6750dd075758320f2cdceEvan Cheng assert(MVT::isVector(OVT) && "Cannot promote this BinOp!"); 2325cc9876124e7096d050e6750dd075758320f2cdceEvan Cheng // Bit convert each of the values to the new type. 2326cc9876124e7096d050e6750dd075758320f2cdceEvan Cheng Tmp1 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp1); 2327cc9876124e7096d050e6750dd075758320f2cdceEvan Cheng Tmp2 = DAG.getNode(ISD::BIT_CONVERT, NVT, Tmp2); 2328cc9876124e7096d050e6750dd075758320f2cdceEvan Cheng Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); 2329cc9876124e7096d050e6750dd075758320f2cdceEvan Cheng // Bit convert the result back the original type. 2330cc9876124e7096d050e6750dd075758320f2cdceEvan Cheng Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result); 2331cc9876124e7096d050e6750dd075758320f2cdceEvan Cheng break; 2332cc9876124e7096d050e6750dd075758320f2cdceEvan Cheng } 2333cc9876124e7096d050e6750dd075758320f2cdceEvan Cheng } 2334cc9876124e7096d050e6750dd075758320f2cdceEvan Cheng } 2335e8f65f1e62ea1d4f2ca9fd0137ae2e0ce20e26e1Andrew Lenharth } 23363e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 2337a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner 2338a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner case ISD::FCOPYSIGN: // FCOPYSIGN does not require LHS/RHS to match type! 2339a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS 2340a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner switch (getTypeAction(Node->getOperand(1).getValueType())) { 2341a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner case Expand: assert(0 && "Not possible"); 2342a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner case Legal: 2343a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the RHS. 2344a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner break; 2345a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner case Promote: 2346a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner Tmp2 = PromoteOp(Node->getOperand(1)); // Promote the RHS. 2347a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner break; 2348a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner } 2349a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner 2350a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); 2351a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner 2352a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { 2353a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner default: assert(0 && "Operation not supported"); 2354a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner case TargetLowering::Custom: 2355a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner Tmp1 = TLI.LowerOperation(Result, DAG); 2356a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner if (Tmp1.Val) Result = Tmp1; 23578f4191d61978529e9e9d7ddc24dbcd528ef7dd4cChris Lattner break; 2358a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner case TargetLowering::Legal: break; 2359912095becac923ff614d7b07728eb345ada67765Evan Cheng case TargetLowering::Expand: { 2360636c753b6ba2418ed707ef0efb31444ec70a46f2Evan Cheng // If this target supports fabs/fneg natively and select is cheap, 2361636c753b6ba2418ed707ef0efb31444ec70a46f2Evan Cheng // do this efficiently. 2362636c753b6ba2418ed707ef0efb31444ec70a46f2Evan Cheng if (!TLI.isSelectExpensive() && 2363636c753b6ba2418ed707ef0efb31444ec70a46f2Evan Cheng TLI.getOperationAction(ISD::FABS, Tmp1.getValueType()) == 2364636c753b6ba2418ed707ef0efb31444ec70a46f2Evan Cheng TargetLowering::Legal && 2365912095becac923ff614d7b07728eb345ada67765Evan Cheng TLI.getOperationAction(ISD::FNEG, Tmp1.getValueType()) == 2366636c753b6ba2418ed707ef0efb31444ec70a46f2Evan Cheng TargetLowering::Legal) { 23678f4191d61978529e9e9d7ddc24dbcd528ef7dd4cChris Lattner // Get the sign bit of the RHS. 23688f4191d61978529e9e9d7ddc24dbcd528ef7dd4cChris Lattner MVT::ValueType IVT = 23698f4191d61978529e9e9d7ddc24dbcd528ef7dd4cChris Lattner Tmp2.getValueType() == MVT::f32 ? MVT::i32 : MVT::i64; 23708f4191d61978529e9e9d7ddc24dbcd528ef7dd4cChris Lattner SDOperand SignBit = DAG.getNode(ISD::BIT_CONVERT, IVT, Tmp2); 23718f4191d61978529e9e9d7ddc24dbcd528ef7dd4cChris Lattner SignBit = DAG.getSetCC(TLI.getSetCCResultTy(), 23728f4191d61978529e9e9d7ddc24dbcd528ef7dd4cChris Lattner SignBit, DAG.getConstant(0, IVT), ISD::SETLT); 23738f4191d61978529e9e9d7ddc24dbcd528ef7dd4cChris Lattner // Get the absolute value of the result. 23748f4191d61978529e9e9d7ddc24dbcd528ef7dd4cChris Lattner SDOperand AbsVal = DAG.getNode(ISD::FABS, Tmp1.getValueType(), Tmp1); 23758f4191d61978529e9e9d7ddc24dbcd528ef7dd4cChris Lattner // Select between the nabs and abs value based on the sign bit of 23768f4191d61978529e9e9d7ddc24dbcd528ef7dd4cChris Lattner // the input. 23778f4191d61978529e9e9d7ddc24dbcd528ef7dd4cChris Lattner Result = DAG.getNode(ISD::SELECT, AbsVal.getValueType(), SignBit, 23788f4191d61978529e9e9d7ddc24dbcd528ef7dd4cChris Lattner DAG.getNode(ISD::FNEG, AbsVal.getValueType(), 23798f4191d61978529e9e9d7ddc24dbcd528ef7dd4cChris Lattner AbsVal), 23808f4191d61978529e9e9d7ddc24dbcd528ef7dd4cChris Lattner AbsVal); 23818f4191d61978529e9e9d7ddc24dbcd528ef7dd4cChris Lattner Result = LegalizeOp(Result); 23828f4191d61978529e9e9d7ddc24dbcd528ef7dd4cChris Lattner break; 23838f4191d61978529e9e9d7ddc24dbcd528ef7dd4cChris Lattner } 23848f4191d61978529e9e9d7ddc24dbcd528ef7dd4cChris Lattner 23858f4191d61978529e9e9d7ddc24dbcd528ef7dd4cChris Lattner // Otherwise, do bitwise ops! 2386912095becac923ff614d7b07728eb345ada67765Evan Cheng MVT::ValueType NVT = 2387912095becac923ff614d7b07728eb345ada67765Evan Cheng Node->getValueType(0) == MVT::f32 ? MVT::i32 : MVT::i64; 2388912095becac923ff614d7b07728eb345ada67765Evan Cheng Result = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI); 2389912095becac923ff614d7b07728eb345ada67765Evan Cheng Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), Result); 2390912095becac923ff614d7b07728eb345ada67765Evan Cheng Result = LegalizeOp(Result); 2391a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner break; 2392a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner } 2393912095becac923ff614d7b07728eb345ada67765Evan Cheng } 2394a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner break; 2395a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner 2396551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman case ISD::ADDC: 2397551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman case ISD::SUBC: 2398551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman Tmp1 = LegalizeOp(Node->getOperand(0)); 2399551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman Tmp2 = LegalizeOp(Node->getOperand(1)); 2400551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); 2401551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman // Since this produces two values, make sure to remember that we legalized 2402551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman // both of them. 2403551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); 2404551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); 2405551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman return Result; 2406edf128a7fa90f2b0b7ee24741a04a7ae1ecd6f7eMisha Brukman 2407551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman case ISD::ADDE: 2408551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman case ISD::SUBE: 2409551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman Tmp1 = LegalizeOp(Node->getOperand(0)); 2410551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman Tmp2 = LegalizeOp(Node->getOperand(1)); 2411551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman Tmp3 = LegalizeOp(Node->getOperand(2)); 2412551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3); 2413551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman // Since this produces two values, make sure to remember that we legalized 2414551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman // both of them. 2415551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); 2416551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); 2417551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman return Result; 2418551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman 2419419f8b62f73541dd783aa98c9eda6e483a487d51Nate Begeman case ISD::BUILD_PAIR: { 2420419f8b62f73541dd783aa98c9eda6e483a487d51Nate Begeman MVT::ValueType PairTy = Node->getValueType(0); 2421419f8b62f73541dd783aa98c9eda6e483a487d51Nate Begeman // TODO: handle the case where the Lo and Hi operands are not of legal type 2422419f8b62f73541dd783aa98c9eda6e483a487d51Nate Begeman Tmp1 = LegalizeOp(Node->getOperand(0)); // Lo 2423419f8b62f73541dd783aa98c9eda6e483a487d51Nate Begeman Tmp2 = LegalizeOp(Node->getOperand(1)); // Hi 2424419f8b62f73541dd783aa98c9eda6e483a487d51Nate Begeman switch (TLI.getOperationAction(ISD::BUILD_PAIR, PairTy)) { 2425456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Promote: 2426456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Custom: 2427456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner assert(0 && "Cannot promote/custom this yet!"); 2428419f8b62f73541dd783aa98c9eda6e483a487d51Nate Begeman case TargetLowering::Legal: 2429419f8b62f73541dd783aa98c9eda6e483a487d51Nate Begeman if (Tmp1 != Node->getOperand(0) || Tmp2 != Node->getOperand(1)) 2430419f8b62f73541dd783aa98c9eda6e483a487d51Nate Begeman Result = DAG.getNode(ISD::BUILD_PAIR, PairTy, Tmp1, Tmp2); 2431419f8b62f73541dd783aa98c9eda6e483a487d51Nate Begeman break; 2432419f8b62f73541dd783aa98c9eda6e483a487d51Nate Begeman case TargetLowering::Expand: 2433419f8b62f73541dd783aa98c9eda6e483a487d51Nate Begeman Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, PairTy, Tmp1); 2434419f8b62f73541dd783aa98c9eda6e483a487d51Nate Begeman Tmp2 = DAG.getNode(ISD::ANY_EXTEND, PairTy, Tmp2); 2435419f8b62f73541dd783aa98c9eda6e483a487d51Nate Begeman Tmp2 = DAG.getNode(ISD::SHL, PairTy, Tmp2, 2436419f8b62f73541dd783aa98c9eda6e483a487d51Nate Begeman DAG.getConstant(MVT::getSizeInBits(PairTy)/2, 2437419f8b62f73541dd783aa98c9eda6e483a487d51Nate Begeman TLI.getShiftAmountTy())); 2438456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Result = DAG.getNode(ISD::OR, PairTy, Tmp1, Tmp2); 2439419f8b62f73541dd783aa98c9eda6e483a487d51Nate Begeman break; 2440419f8b62f73541dd783aa98c9eda6e483a487d51Nate Begeman } 2441419f8b62f73541dd783aa98c9eda6e483a487d51Nate Begeman break; 2442419f8b62f73541dd783aa98c9eda6e483a487d51Nate Begeman } 2443419f8b62f73541dd783aa98c9eda6e483a487d51Nate Begeman 2444c105e19864f2792c52bc6bb765d365308f38f461Nate Begeman case ISD::UREM: 2445c105e19864f2792c52bc6bb765d365308f38f461Nate Begeman case ISD::SREM: 244601b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner case ISD::FREM: 2447c105e19864f2792c52bc6bb765d365308f38f461Nate Begeman Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS 2448c105e19864f2792c52bc6bb765d365308f38f461Nate Begeman Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS 2449456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner 2450c105e19864f2792c52bc6bb765d365308f38f461Nate Begeman switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { 2451456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Promote: assert(0 && "Cannot promote this yet!"); 2452456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Custom: 2453456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner isCustom = true; 2454456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner // FALLTHROUGH 245557030e36e41ebd982a24632e7cea5b584b2d49fcAndrew Lenharth case TargetLowering::Legal: 2456c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); 2457456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (isCustom) { 2458456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp1 = TLI.LowerOperation(Result, DAG); 2459456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (Tmp1.Val) Result = Tmp1; 2460456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner } 246157030e36e41ebd982a24632e7cea5b584b2d49fcAndrew Lenharth break; 24624c64dd7977bc676399df0d5d2bf8016a3242780eChris Lattner case TargetLowering::Expand: 24636b5578f052c2405c0d622192ccacfd47563c99a8Evan Cheng unsigned DivOpc= (Node->getOpcode() == ISD::UREM) ? ISD::UDIV : ISD::SDIV; 246447857812e29324a9d1560796a05b53d3a9217fd9Reid Spencer bool isSigned = DivOpc == ISD::SDIV; 24654c64dd7977bc676399df0d5d2bf8016a3242780eChris Lattner if (MVT::isInteger(Node->getValueType(0))) { 246652cc1ea2a1a374b58801398460a6289723089d91Evan Cheng if (TLI.getOperationAction(DivOpc, Node->getValueType(0)) == 246752cc1ea2a1a374b58801398460a6289723089d91Evan Cheng TargetLowering::Legal) { 246852cc1ea2a1a374b58801398460a6289723089d91Evan Cheng // X % Y -> X-X/Y*Y 246952cc1ea2a1a374b58801398460a6289723089d91Evan Cheng MVT::ValueType VT = Node->getValueType(0); 24706b5578f052c2405c0d622192ccacfd47563c99a8Evan Cheng Result = DAG.getNode(DivOpc, VT, Tmp1, Tmp2); 247152cc1ea2a1a374b58801398460a6289723089d91Evan Cheng Result = DAG.getNode(ISD::MUL, VT, Result, Tmp2); 247252cc1ea2a1a374b58801398460a6289723089d91Evan Cheng Result = DAG.getNode(ISD::SUB, VT, Tmp1, Result); 247352cc1ea2a1a374b58801398460a6289723089d91Evan Cheng } else { 247452cc1ea2a1a374b58801398460a6289723089d91Evan Cheng assert(Node->getValueType(0) == MVT::i32 && 247552cc1ea2a1a374b58801398460a6289723089d91Evan Cheng "Cannot expand this binary operator!"); 247656966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng RTLIB::Libcall LC = Node->getOpcode() == ISD::UREM 247756966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng ? RTLIB::UREM_I32 : RTLIB::SREM_I32; 247852cc1ea2a1a374b58801398460a6289723089d91Evan Cheng SDOperand Dummy; 247956966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Result = ExpandLibCall(TLI.getLibcallName(LC), Node, isSigned, Dummy); 248052cc1ea2a1a374b58801398460a6289723089d91Evan Cheng } 24814c64dd7977bc676399df0d5d2bf8016a3242780eChris Lattner } else { 24824c64dd7977bc676399df0d5d2bf8016a3242780eChris Lattner // Floating point mod -> fmod libcall. 248356966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng RTLIB::Libcall LC = Node->getValueType(0) == MVT::f32 248456966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng ? RTLIB::REM_F32 : RTLIB::REM_F64; 24854c64dd7977bc676399df0d5d2bf8016a3242780eChris Lattner SDOperand Dummy; 248656966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Result = ExpandLibCall(TLI.getLibcallName(LC), Node, 248756966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng false/*sign irrelevant*/, Dummy); 2488c105e19864f2792c52bc6bb765d365308f38f461Nate Begeman } 2489c105e19864f2792c52bc6bb765d365308f38f461Nate Begeman break; 2490c105e19864f2792c52bc6bb765d365308f38f461Nate Begeman } 2491c105e19864f2792c52bc6bb765d365308f38f461Nate Begeman break; 2492acc398c195a697795bff3245943d104eb19192b9Nate Begeman case ISD::VAARG: { 2493acc398c195a697795bff3245943d104eb19192b9Nate Begeman Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. 2494acc398c195a697795bff3245943d104eb19192b9Nate Begeman Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. 2495acc398c195a697795bff3245943d104eb19192b9Nate Begeman 24965c62f337fe846247f5e72acb32844e24b4f18b71Chris Lattner MVT::ValueType VT = Node->getValueType(0); 2497acc398c195a697795bff3245943d104eb19192b9Nate Begeman switch (TLI.getOperationAction(Node->getOpcode(), MVT::Other)) { 2498acc398c195a697795bff3245943d104eb19192b9Nate Begeman default: assert(0 && "This action is not supported yet!"); 2499456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Custom: 2500456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner isCustom = true; 2501456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner // FALLTHROUGH 2502acc398c195a697795bff3245943d104eb19192b9Nate Begeman case TargetLowering::Legal: 2503c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); 2504c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = Result.getValue(0); 2505456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp1 = Result.getValue(1); 2506456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner 2507456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (isCustom) { 2508456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp2 = TLI.LowerOperation(Result, DAG); 2509456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (Tmp2.Val) { 2510456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Result = LegalizeOp(Tmp2); 2511456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp1 = LegalizeOp(Tmp2.getValue(1)); 2512456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner } 2513456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner } 2514acc398c195a697795bff3245943d104eb19192b9Nate Begeman break; 2515acc398c195a697795bff3245943d104eb19192b9Nate Begeman case TargetLowering::Expand: { 2516466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng SrcValueSDNode *SV = cast<SrcValueSDNode>(Node->getOperand(2)); 2517acc398c195a697795bff3245943d104eb19192b9Nate Begeman SDOperand VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, 2518466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng SV->getValue(), SV->getOffset()); 2519acc398c195a697795bff3245943d104eb19192b9Nate Begeman // Increment the pointer, VAList, to the next vaarg 2520acc398c195a697795bff3245943d104eb19192b9Nate Begeman Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList, 2521acc398c195a697795bff3245943d104eb19192b9Nate Begeman DAG.getConstant(MVT::getSizeInBits(VT)/8, 2522acc398c195a697795bff3245943d104eb19192b9Nate Begeman TLI.getPointerTy())); 2523acc398c195a697795bff3245943d104eb19192b9Nate Begeman // Store the incremented VAList to the legalized pointer 25248b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, SV->getValue(), 25258b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng SV->getOffset()); 2526acc398c195a697795bff3245943d104eb19192b9Nate Begeman // Load the actual argument out of the pointer VAList 2527466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Result = DAG.getLoad(VT, Tmp3, VAList, NULL, 0); 2528456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp1 = LegalizeOp(Result.getValue(1)); 2529acc398c195a697795bff3245943d104eb19192b9Nate Begeman Result = LegalizeOp(Result); 2530acc398c195a697795bff3245943d104eb19192b9Nate Begeman break; 2531acc398c195a697795bff3245943d104eb19192b9Nate Begeman } 2532acc398c195a697795bff3245943d104eb19192b9Nate Begeman } 2533acc398c195a697795bff3245943d104eb19192b9Nate Begeman // Since VAARG produces two values, make sure to remember that we 2534acc398c195a697795bff3245943d104eb19192b9Nate Begeman // legalized both of them. 2535acc398c195a697795bff3245943d104eb19192b9Nate Begeman AddLegalizedOperand(SDOperand(Node, 0), Result); 2536456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner AddLegalizedOperand(SDOperand(Node, 1), Tmp1); 2537456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner return Op.ResNo ? Tmp1 : Result; 2538acc398c195a697795bff3245943d104eb19192b9Nate Begeman } 2539acc398c195a697795bff3245943d104eb19192b9Nate Begeman 2540acc398c195a697795bff3245943d104eb19192b9Nate Begeman case ISD::VACOPY: 2541acc398c195a697795bff3245943d104eb19192b9Nate Begeman Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. 2542acc398c195a697795bff3245943d104eb19192b9Nate Begeman Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the dest pointer. 2543acc398c195a697795bff3245943d104eb19192b9Nate Begeman Tmp3 = LegalizeOp(Node->getOperand(2)); // Legalize the source pointer. 2544acc398c195a697795bff3245943d104eb19192b9Nate Begeman 2545acc398c195a697795bff3245943d104eb19192b9Nate Begeman switch (TLI.getOperationAction(ISD::VACOPY, MVT::Other)) { 2546acc398c195a697795bff3245943d104eb19192b9Nate Begeman default: assert(0 && "This action is not supported yet!"); 2547456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Custom: 2548456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner isCustom = true; 2549456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner // FALLTHROUGH 2550acc398c195a697795bff3245943d104eb19192b9Nate Begeman case TargetLowering::Legal: 2551c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3, 2552c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Node->getOperand(3), Node->getOperand(4)); 2553456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (isCustom) { 2554456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp1 = TLI.LowerOperation(Result, DAG); 2555456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (Tmp1.Val) Result = Tmp1; 2556456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner } 2557acc398c195a697795bff3245943d104eb19192b9Nate Begeman break; 2558acc398c195a697795bff3245943d104eb19192b9Nate Begeman case TargetLowering::Expand: 2559acc398c195a697795bff3245943d104eb19192b9Nate Begeman // This defaults to loading a pointer from the input and storing it to the 2560acc398c195a697795bff3245943d104eb19192b9Nate Begeman // output, returning the chain. 2561466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng SrcValueSDNode *SVD = cast<SrcValueSDNode>(Node->getOperand(3)); 25628b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng SrcValueSDNode *SVS = cast<SrcValueSDNode>(Node->getOperand(4)); 2563466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Tmp4 = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp3, SVD->getValue(), 2564466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng SVD->getOffset()); 25658b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Result = DAG.getStore(Tmp4.getValue(1), Tmp4, Tmp2, SVS->getValue(), 25668b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng SVS->getOffset()); 2567acc398c195a697795bff3245943d104eb19192b9Nate Begeman break; 2568acc398c195a697795bff3245943d104eb19192b9Nate Begeman } 2569acc398c195a697795bff3245943d104eb19192b9Nate Begeman break; 2570acc398c195a697795bff3245943d104eb19192b9Nate Begeman 2571acc398c195a697795bff3245943d104eb19192b9Nate Begeman case ISD::VAEND: 2572acc398c195a697795bff3245943d104eb19192b9Nate Begeman Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. 2573acc398c195a697795bff3245943d104eb19192b9Nate Begeman Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. 2574acc398c195a697795bff3245943d104eb19192b9Nate Begeman 2575acc398c195a697795bff3245943d104eb19192b9Nate Begeman switch (TLI.getOperationAction(ISD::VAEND, MVT::Other)) { 2576acc398c195a697795bff3245943d104eb19192b9Nate Begeman default: assert(0 && "This action is not supported yet!"); 2577456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Custom: 2578456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner isCustom = true; 2579456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner // FALLTHROUGH 2580acc398c195a697795bff3245943d104eb19192b9Nate Begeman case TargetLowering::Legal: 2581c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); 2582456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (isCustom) { 2583456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp1 = TLI.LowerOperation(Tmp1, DAG); 2584456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (Tmp1.Val) Result = Tmp1; 2585456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner } 2586acc398c195a697795bff3245943d104eb19192b9Nate Begeman break; 2587acc398c195a697795bff3245943d104eb19192b9Nate Begeman case TargetLowering::Expand: 2588acc398c195a697795bff3245943d104eb19192b9Nate Begeman Result = Tmp1; // Default to a no-op, return the chain 2589acc398c195a697795bff3245943d104eb19192b9Nate Begeman break; 2590acc398c195a697795bff3245943d104eb19192b9Nate Begeman } 2591acc398c195a697795bff3245943d104eb19192b9Nate Begeman break; 2592acc398c195a697795bff3245943d104eb19192b9Nate Begeman 2593acc398c195a697795bff3245943d104eb19192b9Nate Begeman case ISD::VASTART: 2594acc398c195a697795bff3245943d104eb19192b9Nate Begeman Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. 2595acc398c195a697795bff3245943d104eb19192b9Nate Begeman Tmp2 = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. 2596acc398c195a697795bff3245943d104eb19192b9Nate Begeman 2597c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2)); 2598c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner 2599acc398c195a697795bff3245943d104eb19192b9Nate Begeman switch (TLI.getOperationAction(ISD::VASTART, MVT::Other)) { 2600acc398c195a697795bff3245943d104eb19192b9Nate Begeman default: assert(0 && "This action is not supported yet!"); 2601456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Legal: break; 2602456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Custom: 2603456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp1 = TLI.LowerOperation(Result, DAG); 2604456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (Tmp1.Val) Result = Tmp1; 2605acc398c195a697795bff3245943d104eb19192b9Nate Begeman break; 2606acc398c195a697795bff3245943d104eb19192b9Nate Begeman } 2607acc398c195a697795bff3245943d104eb19192b9Nate Begeman break; 2608acc398c195a697795bff3245943d104eb19192b9Nate Begeman 260935ef913ec21de0f4f1b39c811b4335438717a9b8Nate Begeman case ISD::ROTL: 261035ef913ec21de0f4f1b39c811b4335438717a9b8Nate Begeman case ISD::ROTR: 261135ef913ec21de0f4f1b39c811b4335438717a9b8Nate Begeman Tmp1 = LegalizeOp(Node->getOperand(0)); // LHS 261235ef913ec21de0f4f1b39c811b4335438717a9b8Nate Begeman Tmp2 = LegalizeOp(Node->getOperand(1)); // RHS 2613456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner 2614456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner assert(TLI.isOperationLegal(Node->getOpcode(), Node->getValueType(0)) && 2615456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner "Cannot handle this yet!"); 2616c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2); 261735ef913ec21de0f4f1b39c811b4335438717a9b8Nate Begeman break; 261835ef913ec21de0f4f1b39c811b4335438717a9b8Nate Begeman 2619d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman case ISD::BSWAP: 2620d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman Tmp1 = LegalizeOp(Node->getOperand(0)); // Op 2621d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { 2622456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Custom: 2623456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner assert(0 && "Cannot custom legalize this yet!"); 2624456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Legal: 2625c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1); 2626456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner break; 2627456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Promote: { 2628456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner MVT::ValueType OVT = Tmp1.getValueType(); 2629456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); 2630456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner unsigned DiffBits = getSizeInBits(NVT) - getSizeInBits(OVT); 2631456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner 2632456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); 2633456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1); 2634456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Result = DAG.getNode(ISD::SRL, NVT, Tmp1, 2635456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner DAG.getConstant(DiffBits, TLI.getShiftAmountTy())); 2636456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner break; 2637456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner } 2638456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Expand: 2639456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Result = ExpandBSWAP(Tmp1); 2640456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner break; 2641d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman } 2642d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman break; 2643d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman 2644691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth case ISD::CTPOP: 2645691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth case ISD::CTTZ: 2646691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth case ISD::CTLZ: 2647691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth Tmp1 = LegalizeOp(Node->getOperand(0)); // Op 2648691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { 2649456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Custom: assert(0 && "Cannot custom handle this yet!"); 2650691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth case TargetLowering::Legal: 2651c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1); 2652691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth break; 2653691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth case TargetLowering::Promote: { 2654691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth MVT::ValueType OVT = Tmp1.getValueType(); 2655691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth MVT::ValueType NVT = TLI.getTypeToPromoteTo(Node->getOpcode(), OVT); 2656edb1add9a093efa266c94b6d0a34c26f5b2d5d7bChris Lattner 2657edb1add9a093efa266c94b6d0a34c26f5b2d5d7bChris Lattner // Zero extend the argument. 2658691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); 2659691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth // Perform the larger operation, then subtract if needed. 2660691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth Tmp1 = DAG.getNode(Node->getOpcode(), Node->getValueType(0), Tmp1); 2661456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner switch (Node->getOpcode()) { 2662691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth case ISD::CTPOP: 2663691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth Result = Tmp1; 2664691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth break; 2665691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth case ISD::CTTZ: 2666691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth //if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) 26677cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), Tmp1, 26687cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner DAG.getConstant(getSizeInBits(NVT), NVT), 26697cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner ISD::SETEQ); 267000b16889ab461b7ecef1c91ade101186b7f1fce2Jeff Cohen Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, 2671691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth DAG.getConstant(getSizeInBits(OVT),NVT), Tmp1); 2672691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth break; 2673691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth case ISD::CTLZ: 2674456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner // Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) 267500b16889ab461b7ecef1c91ade101186b7f1fce2Jeff Cohen Result = DAG.getNode(ISD::SUB, NVT, Tmp1, 267600b16889ab461b7ecef1c91ade101186b7f1fce2Jeff Cohen DAG.getConstant(getSizeInBits(NVT) - 2677691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth getSizeInBits(OVT), NVT)); 2678691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth break; 2679691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth } 2680691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth break; 2681691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth } 2682691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth case TargetLowering::Expand: 2683456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Result = ExpandBitCount(Node->getOpcode(), Tmp1); 2684691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth break; 2685691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth } 2686691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth break; 268700b16889ab461b7ecef1c91ade101186b7f1fce2Jeff Cohen 26882c8086f4b9916b2d02842be5e375276023225fbaChris Lattner // Unary operators 26892c8086f4b9916b2d02842be5e375276023225fbaChris Lattner case ISD::FABS: 26902c8086f4b9916b2d02842be5e375276023225fbaChris Lattner case ISD::FNEG: 2691da6ba87d234a934409e8d8d5b131b7341ab4bf97Chris Lattner case ISD::FSQRT: 2692da6ba87d234a934409e8d8d5b131b7341ab4bf97Chris Lattner case ISD::FSIN: 2693da6ba87d234a934409e8d8d5b131b7341ab4bf97Chris Lattner case ISD::FCOS: 26942c8086f4b9916b2d02842be5e375276023225fbaChris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); 26952c8086f4b9916b2d02842be5e375276023225fbaChris Lattner switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { 2696456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Promote: 2697456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Custom: 269859ad781e0118021d1ca7dfbc9f8db2ed828745e0Evan Cheng isCustom = true; 269959ad781e0118021d1ca7dfbc9f8db2ed828745e0Evan Cheng // FALLTHROUGH 27002c8086f4b9916b2d02842be5e375276023225fbaChris Lattner case TargetLowering::Legal: 2701c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1); 270259ad781e0118021d1ca7dfbc9f8db2ed828745e0Evan Cheng if (isCustom) { 270359ad781e0118021d1ca7dfbc9f8db2ed828745e0Evan Cheng Tmp1 = TLI.LowerOperation(Result, DAG); 270459ad781e0118021d1ca7dfbc9f8db2ed828745e0Evan Cheng if (Tmp1.Val) Result = Tmp1; 270559ad781e0118021d1ca7dfbc9f8db2ed828745e0Evan Cheng } 27062c8086f4b9916b2d02842be5e375276023225fbaChris Lattner break; 27072c8086f4b9916b2d02842be5e375276023225fbaChris Lattner case TargetLowering::Expand: 2708456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner switch (Node->getOpcode()) { 2709456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner default: assert(0 && "Unreachable!"); 2710456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case ISD::FNEG: 27112c8086f4b9916b2d02842be5e375276023225fbaChris Lattner // Expand Y = FNEG(X) -> Y = SUB -0.0, X 27122c8086f4b9916b2d02842be5e375276023225fbaChris Lattner Tmp2 = DAG.getConstantFP(-0.0, Node->getValueType(0)); 2713456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Result = DAG.getNode(ISD::FSUB, Node->getValueType(0), Tmp2, Tmp1); 2714f76e7dc8d8ac1855ef59698e82c757548ef4ca65Chris Lattner break; 2715f76e7dc8d8ac1855ef59698e82c757548ef4ca65Chris Lattner case ISD::FABS: { 27164af6e0d7836126630f579b0a34f054321187f00bChris Lattner // Expand Y = FABS(X) -> Y = (X >u 0.0) ? X : fneg(X). 27174af6e0d7836126630f579b0a34f054321187f00bChris Lattner MVT::ValueType VT = Node->getValueType(0); 27184af6e0d7836126630f579b0a34f054321187f00bChris Lattner Tmp2 = DAG.getConstantFP(0.0, VT); 27197cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), Tmp1, Tmp2, ISD::SETUGT); 27204af6e0d7836126630f579b0a34f054321187f00bChris Lattner Tmp3 = DAG.getNode(ISD::FNEG, VT, Tmp1); 27214af6e0d7836126630f579b0a34f054321187f00bChris Lattner Result = DAG.getNode(ISD::SELECT, VT, Tmp2, Tmp1, Tmp3); 2722f76e7dc8d8ac1855ef59698e82c757548ef4ca65Chris Lattner break; 2723f76e7dc8d8ac1855ef59698e82c757548ef4ca65Chris Lattner } 2724f76e7dc8d8ac1855ef59698e82c757548ef4ca65Chris Lattner case ISD::FSQRT: 2725f76e7dc8d8ac1855ef59698e82c757548ef4ca65Chris Lattner case ISD::FSIN: 2726f76e7dc8d8ac1855ef59698e82c757548ef4ca65Chris Lattner case ISD::FCOS: { 2727f76e7dc8d8ac1855ef59698e82c757548ef4ca65Chris Lattner MVT::ValueType VT = Node->getValueType(0); 272856966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; 2729f76e7dc8d8ac1855ef59698e82c757548ef4ca65Chris Lattner switch(Node->getOpcode()) { 273056966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng case ISD::FSQRT: 273156966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC = VT == MVT::f32 ? RTLIB::SQRT_F32 : RTLIB::SQRT_F64; 273256966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng break; 273356966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng case ISD::FSIN: 273456966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC = VT == MVT::f32 ? RTLIB::SIN_F32 : RTLIB::SIN_F64; 273556966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng break; 273656966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng case ISD::FCOS: 273756966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC = VT == MVT::f32 ? RTLIB::COS_F32 : RTLIB::COS_F64; 273856966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng break; 2739f76e7dc8d8ac1855ef59698e82c757548ef4ca65Chris Lattner default: assert(0 && "Unreachable!"); 2740f76e7dc8d8ac1855ef59698e82c757548ef4ca65Chris Lattner } 27412ac4fc032050ff1e0f06bd8e27126e979406effbNate Begeman SDOperand Dummy; 274256966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Result = ExpandLibCall(TLI.getLibcallName(LC), Node, 274356966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng false/*sign irrelevant*/, Dummy); 2744f76e7dc8d8ac1855ef59698e82c757548ef4ca65Chris Lattner break; 2745f76e7dc8d8ac1855ef59698e82c757548ef4ca65Chris Lattner } 27462c8086f4b9916b2d02842be5e375276023225fbaChris Lattner } 27472c8086f4b9916b2d02842be5e375276023225fbaChris Lattner break; 27482c8086f4b9916b2d02842be5e375276023225fbaChris Lattner } 27492c8086f4b9916b2d02842be5e375276023225fbaChris Lattner break; 27506ddf8ed6fe2d0aa5e15f7b9ad7e5049e2223bbd1Chris Lattner case ISD::FPOWI: { 27516ddf8ed6fe2d0aa5e15f7b9ad7e5049e2223bbd1Chris Lattner // We always lower FPOWI into a libcall. No target support it yet. 275256966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng RTLIB::Libcall LC = Node->getValueType(0) == MVT::f32 275356966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng ? RTLIB::POWI_F32 : RTLIB::POWI_F64; 27546ddf8ed6fe2d0aa5e15f7b9ad7e5049e2223bbd1Chris Lattner SDOperand Dummy; 275556966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Result = ExpandLibCall(TLI.getLibcallName(LC), Node, 275656966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng false/*sign irrelevant*/, Dummy); 27576ddf8ed6fe2d0aa5e15f7b9ad7e5049e2223bbd1Chris Lattner break; 27586ddf8ed6fe2d0aa5e15f7b9ad7e5049e2223bbd1Chris Lattner } 275935481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner case ISD::BIT_CONVERT: 276067993f7b974cd17e4372a6b7b9f9cad5ed174df1Chris Lattner if (!isTypeLegal(Node->getOperand(0).getValueType())) { 276135481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner Result = ExpandBIT_CONVERT(Node->getValueType(0), Node->getOperand(0)); 276267993f7b974cd17e4372a6b7b9f9cad5ed174df1Chris Lattner } else { 276335481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner switch (TLI.getOperationAction(ISD::BIT_CONVERT, 276435481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner Node->getOperand(0).getValueType())) { 276535481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner default: assert(0 && "Unknown operation action!"); 276635481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner case TargetLowering::Expand: 276735481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner Result = ExpandBIT_CONVERT(Node->getValueType(0), Node->getOperand(0)); 276835481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner break; 276935481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner case TargetLowering::Legal: 277035481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); 2771c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1); 277235481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner break; 277335481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner } 277435481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner } 277535481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner break; 2776d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner case ISD::VBIT_CONVERT: { 2777d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner assert(Op.getOperand(0).getValueType() == MVT::Vector && 2778d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner "Can only have VBIT_CONVERT where input or output is MVT::Vector!"); 2779d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner 2780d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner // The input has to be a vector type, we have to either scalarize it, pack 2781d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner // it, or convert it based on whether the input vector type is legal. 2782d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner SDNode *InVal = Node->getOperand(0).Val; 2783d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner unsigned NumElems = 2784d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner cast<ConstantSDNode>(*(InVal->op_end()-2))->getValue(); 2785d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner MVT::ValueType EVT = cast<VTSDNode>(*(InVal->op_end()-1))->getVT(); 2786d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner 2787d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner // Figure out if there is a Packed type corresponding to this Vector 2788d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner // type. If so, convert to the packed type. 2789d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems); 2790d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner if (TVT != MVT::Other && TLI.isTypeLegal(TVT)) { 2791d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner // Turn this into a bit convert of the packed input. 2792d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), 2793d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner PackVectorOp(Node->getOperand(0), TVT)); 2794d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner break; 2795d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner } else if (NumElems == 1) { 2796d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner // Turn this into a bit convert of the scalar input. 2797d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner Result = DAG.getNode(ISD::BIT_CONVERT, Node->getValueType(0), 2798d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner PackVectorOp(Node->getOperand(0), EVT)); 2799d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner break; 2800d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner } else { 2801d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner // FIXME: UNIMP! Store then reload 2802d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner assert(0 && "Cast from unsupported vector type not implemented yet!"); 2803d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner } 2804d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner } 2805d1f04d40a078d6ca7c876b16a178992a109af774Chris Lattner 28062c8086f4b9916b2d02842be5e375276023225fbaChris Lattner // Conversion operators. The source and destination have different types. 2807fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner case ISD::SINT_TO_FP: 2808fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner case ISD::UINT_TO_FP: { 2809fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP; 2810fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner switch (getTypeAction(Node->getOperand(0).getValueType())) { 2811fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner case Legal: 2812d29b6aa608d69f19b57ebd2ae630b040b1c4951dJeff Cohen switch (TLI.getOperationAction(Node->getOpcode(), 2813fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner Node->getOperand(0).getValueType())) { 2814fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner default: assert(0 && "Unknown operation action!"); 2815456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Custom: 2816456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner isCustom = true; 2817456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner // FALLTHROUGH 2818456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Legal: 2819456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); 2820c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1); 2821456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (isCustom) { 2822456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp1 = TLI.LowerOperation(Result, DAG); 2823456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (Tmp1.Val) Result = Tmp1; 2824456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner } 2825456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner break; 2826fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner case TargetLowering::Expand: 28276269ed125fc492d81dc5e3f48482816fc9d47f49Jim Laskey Result = ExpandLegalINT_TO_FP(isSigned, 28286269ed125fc492d81dc5e3f48482816fc9d47f49Jim Laskey LegalizeOp(Node->getOperand(0)), 28296269ed125fc492d81dc5e3f48482816fc9d47f49Jim Laskey Node->getValueType(0)); 2830456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner break; 2831fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner case TargetLowering::Promote: 2832fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner Result = PromoteLegalINT_TO_FP(LegalizeOp(Node->getOperand(0)), 2833fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner Node->getValueType(0), 2834fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner isSigned); 2835fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner break; 28365b5b8c27556e5dc8792e37436e4ddd7ab157192dAndrew Lenharth } 2837fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner break; 2838fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner case Expand: 2839fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, 2840fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner Node->getValueType(0), Node->getOperand(0)); 2841fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner break; 2842fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner case Promote: 2843c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp1 = PromoteOp(Node->getOperand(0)); 2844fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner if (isSigned) { 2845c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp1.getValueType(), 2846c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp1, DAG.getValueType(Node->getOperand(0).getValueType())); 2847fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner } else { 2848c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp1 = DAG.getZeroExtendInReg(Tmp1, 2849c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Node->getOperand(0).getValueType()); 2850fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner } 2851c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1); 2852c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = LegalizeOp(Result); // The 'op' is not necessarily legal! 2853fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner break; 2854fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner } 2855fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner break; 2856fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner } 2857fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner case ISD::TRUNCATE: 2858fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner switch (getTypeAction(Node->getOperand(0).getValueType())) { 2859fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner case Legal: 2860fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); 2861c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1); 2862fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner break; 2863fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner case Expand: 2864fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner ExpandOp(Node->getOperand(0), Tmp1, Tmp2); 2865fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner 2866fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner // Since the result is legal, we should just be able to truncate the low 2867fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner // part of the source. 2868fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner Result = DAG.getNode(ISD::TRUNCATE, Node->getValueType(0), Tmp1); 2869fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner break; 2870fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner case Promote: 2871fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner Result = PromoteOp(Node->getOperand(0)); 2872fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner Result = DAG.getNode(ISD::TRUNCATE, Op.getValueType(), Result); 2873fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner break; 2874fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner } 2875fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner break; 2876d29b6aa608d69f19b57ebd2ae630b040b1c4951dJeff Cohen 2877fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner case ISD::FP_TO_SINT: 2878fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner case ISD::FP_TO_UINT: 2879fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner switch (getTypeAction(Node->getOperand(0).getValueType())) { 2880fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner case Legal: 2881f1fa74ee0d30dfdb854f7d3f5ee67437cc82e250Chris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); 2882f1fa74ee0d30dfdb854f7d3f5ee67437cc82e250Chris Lattner 28831618bebcf6f9cd19c4e05de3bfffda28c246bb12Chris Lattner switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))){ 28841618bebcf6f9cd19c4e05de3bfffda28c246bb12Chris Lattner default: assert(0 && "Unknown operation action!"); 2885456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Custom: 2886456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner isCustom = true; 2887456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner // FALLTHROUGH 2888456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Legal: 2889c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1); 2890456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (isCustom) { 2891456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp1 = TLI.LowerOperation(Result, DAG); 2892456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (Tmp1.Val) Result = Tmp1; 2893456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner } 2894456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner break; 2895456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case TargetLowering::Promote: 2896456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Result = PromoteLegalFP_TO_INT(Tmp1, Node->getValueType(0), 2897456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Node->getOpcode() == ISD::FP_TO_SINT); 2898456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner break; 28991618bebcf6f9cd19c4e05de3bfffda28c246bb12Chris Lattner case TargetLowering::Expand: 2900d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman if (Node->getOpcode() == ISD::FP_TO_UINT) { 2901d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman SDOperand True, False; 2902d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman MVT::ValueType VT = Node->getOperand(0).getValueType(); 2903d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman MVT::ValueType NVT = Node->getValueType(0); 2904d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman unsigned ShiftAmt = MVT::getSizeInBits(Node->getValueType(0))-1; 2905d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman Tmp2 = DAG.getConstantFP((double)(1ULL << ShiftAmt), VT); 2906d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman Tmp3 = DAG.getSetCC(TLI.getSetCCResultTy(), 2907d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman Node->getOperand(0), Tmp2, ISD::SETLT); 2908d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman True = DAG.getNode(ISD::FP_TO_SINT, NVT, Node->getOperand(0)); 2909d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman False = DAG.getNode(ISD::FP_TO_SINT, NVT, 291001b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner DAG.getNode(ISD::FSUB, VT, Node->getOperand(0), 2911d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman Tmp2)); 2912d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman False = DAG.getNode(ISD::XOR, NVT, False, 2913d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman DAG.getConstant(1ULL << ShiftAmt, NVT)); 2914456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Result = DAG.getNode(ISD::SELECT, NVT, Tmp3, True, False); 2915456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner break; 2916d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman } else { 2917d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman assert(0 && "Do not know how to expand FP_TO_SINT yet!"); 2918d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman } 2919d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman break; 29201618bebcf6f9cd19c4e05de3bfffda28c246bb12Chris Lattner } 2921fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner break; 29226af00d588c1b353d9d7a3dd8f58927056eccd6c1Evan Cheng case Expand: { 29236af00d588c1b353d9d7a3dd8f58927056eccd6c1Evan Cheng // Convert f32 / f64 to i32 / i64. 29246af00d588c1b353d9d7a3dd8f58927056eccd6c1Evan Cheng MVT::ValueType VT = Op.getValueType(); 292556966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; 29266af00d588c1b353d9d7a3dd8f58927056eccd6c1Evan Cheng switch (Node->getOpcode()) { 29276af00d588c1b353d9d7a3dd8f58927056eccd6c1Evan Cheng case ISD::FP_TO_SINT: 29286af00d588c1b353d9d7a3dd8f58927056eccd6c1Evan Cheng if (Node->getOperand(0).getValueType() == MVT::f32) 292956966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC = (VT == MVT::i32) 293056966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng ? RTLIB::FPTOSINT_F32_I32 : RTLIB::FPTOSINT_F32_I64; 29316af00d588c1b353d9d7a3dd8f58927056eccd6c1Evan Cheng else 293256966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC = (VT == MVT::i32) 293356966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng ? RTLIB::FPTOSINT_F64_I32 : RTLIB::FPTOSINT_F64_I64; 29346af00d588c1b353d9d7a3dd8f58927056eccd6c1Evan Cheng break; 29356af00d588c1b353d9d7a3dd8f58927056eccd6c1Evan Cheng case ISD::FP_TO_UINT: 29366af00d588c1b353d9d7a3dd8f58927056eccd6c1Evan Cheng if (Node->getOperand(0).getValueType() == MVT::f32) 293756966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC = (VT == MVT::i32) 293856966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng ? RTLIB::FPTOUINT_F32_I32 : RTLIB::FPTOSINT_F32_I64; 29396af00d588c1b353d9d7a3dd8f58927056eccd6c1Evan Cheng else 294056966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC = (VT == MVT::i32) 294156966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng ? RTLIB::FPTOUINT_F64_I32 : RTLIB::FPTOSINT_F64_I64; 29426af00d588c1b353d9d7a3dd8f58927056eccd6c1Evan Cheng break; 29436af00d588c1b353d9d7a3dd8f58927056eccd6c1Evan Cheng default: assert(0 && "Unreachable!"); 29446af00d588c1b353d9d7a3dd8f58927056eccd6c1Evan Cheng } 29456af00d588c1b353d9d7a3dd8f58927056eccd6c1Evan Cheng SDOperand Dummy; 294656966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Result = ExpandLibCall(TLI.getLibcallName(LC), Node, 294756966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng false/*sign irrelevant*/, Dummy); 29486af00d588c1b353d9d7a3dd8f58927056eccd6c1Evan Cheng break; 29496af00d588c1b353d9d7a3dd8f58927056eccd6c1Evan Cheng } 2950fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner case Promote: 2951c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp1 = PromoteOp(Node->getOperand(0)); 2952c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, LegalizeOp(Tmp1)); 2953c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = LegalizeOp(Result); 2954fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner break; 2955fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner } 2956fa9c801a6b42609dc2a934afb6535e3d51d61a3eChris Lattner break; 2957d29b6aa608d69f19b57ebd2ae630b040b1c4951dJeff Cohen 295813c78e2e5f158e9008b279b43b685ff02bb3cbeaChris Lattner case ISD::ANY_EXTEND: 29593e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::ZERO_EXTEND: 29603e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::SIGN_EXTEND: 296103c0cf822e9a57109d1b4e6a2705d68852c93e1dChris Lattner case ISD::FP_EXTEND: 296203c0cf822e9a57109d1b4e6a2705d68852c93e1dChris Lattner case ISD::FP_ROUND: 29633e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner switch (getTypeAction(Node->getOperand(0).getValueType())) { 2964456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner case Expand: assert(0 && "Shouldn't need to expand other operators here!"); 29653e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case Legal: 29663e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); 2967c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1); 29683e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 296903c8546ec57523970874917854a2fb77b1ff598eChris Lattner case Promote: 297003c8546ec57523970874917854a2fb77b1ff598eChris Lattner switch (Node->getOpcode()) { 297113c78e2e5f158e9008b279b43b685ff02bb3cbeaChris Lattner case ISD::ANY_EXTEND: 2972c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Tmp1 = PromoteOp(Node->getOperand(0)); 2973c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Tmp1); 297413c78e2e5f158e9008b279b43b685ff02bb3cbeaChris Lattner break; 29751713e73b8ac53f045150cb2a7d7ba9781dc35ef8Chris Lattner case ISD::ZERO_EXTEND: 29761713e73b8ac53f045150cb2a7d7ba9781dc35ef8Chris Lattner Result = PromoteOp(Node->getOperand(0)); 297713c78e2e5f158e9008b279b43b685ff02bb3cbeaChris Lattner Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); 297823993561e24b2a6eaf0e036062522ab825c30d3fChris Lattner Result = DAG.getZeroExtendInReg(Result, 297923993561e24b2a6eaf0e036062522ab825c30d3fChris Lattner Node->getOperand(0).getValueType()); 298003c8546ec57523970874917854a2fb77b1ff598eChris Lattner break; 298103c8546ec57523970874917854a2fb77b1ff598eChris Lattner case ISD::SIGN_EXTEND: 29821713e73b8ac53f045150cb2a7d7ba9781dc35ef8Chris Lattner Result = PromoteOp(Node->getOperand(0)); 298313c78e2e5f158e9008b279b43b685ff02bb3cbeaChris Lattner Result = DAG.getNode(ISD::ANY_EXTEND, Op.getValueType(), Result); 29841713e73b8ac53f045150cb2a7d7ba9781dc35ef8Chris Lattner Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), 298515e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner Result, 298615e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner DAG.getValueType(Node->getOperand(0).getValueType())); 29871713e73b8ac53f045150cb2a7d7ba9781dc35ef8Chris Lattner break; 298803c8546ec57523970874917854a2fb77b1ff598eChris Lattner case ISD::FP_EXTEND: 29891713e73b8ac53f045150cb2a7d7ba9781dc35ef8Chris Lattner Result = PromoteOp(Node->getOperand(0)); 29901713e73b8ac53f045150cb2a7d7ba9781dc35ef8Chris Lattner if (Result.getValueType() != Op.getValueType()) 29911713e73b8ac53f045150cb2a7d7ba9781dc35ef8Chris Lattner // Dynamically dead while we have only 2 FP types. 29921713e73b8ac53f045150cb2a7d7ba9781dc35ef8Chris Lattner Result = DAG.getNode(ISD::FP_EXTEND, Op.getValueType(), Result); 29931713e73b8ac53f045150cb2a7d7ba9781dc35ef8Chris Lattner break; 299403c8546ec57523970874917854a2fb77b1ff598eChris Lattner case ISD::FP_ROUND: 2995f8161d83f0201a32a33a0c875eb43df81d8586abChris Lattner Result = PromoteOp(Node->getOperand(0)); 2996f8161d83f0201a32a33a0c875eb43df81d8586abChris Lattner Result = DAG.getNode(Node->getOpcode(), Op.getValueType(), Result); 2997f8161d83f0201a32a33a0c875eb43df81d8586abChris Lattner break; 299803c8546ec57523970874917854a2fb77b1ff598eChris Lattner } 29993e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 30003e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 30010f69b2910810b7c0971a739f18b37fae2a20eca5Chris Lattner case ISD::FP_ROUND_INREG: 300223993561e24b2a6eaf0e036062522ab825c30d3fChris Lattner case ISD::SIGN_EXTEND_INREG: { 30030f69b2910810b7c0971a739f18b37fae2a20eca5Chris Lattner Tmp1 = LegalizeOp(Node->getOperand(0)); 300415e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner MVT::ValueType ExtraVT = cast<VTSDNode>(Node->getOperand(1))->getVT(); 300545b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner 300645b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner // If this operation is not supported, convert it to a shl/shr or load/store 300745b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner // pair. 300855ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner switch (TLI.getOperationAction(Node->getOpcode(), ExtraVT)) { 300955ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner default: assert(0 && "This action not supported for this op yet!"); 301055ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner case TargetLowering::Legal: 3011c52ad4f04ea5f51a1b4c67e585acea5c0525fc3dChris Lattner Result = DAG.UpdateNodeOperands(Result, Tmp1, Node->getOperand(1)); 301255ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner break; 301355ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner case TargetLowering::Expand: 301445b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner // If this is an integer extend and shifts are supported, do that. 301523993561e24b2a6eaf0e036062522ab825c30d3fChris Lattner if (Node->getOpcode() == ISD::SIGN_EXTEND_INREG) { 301645b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner // NOTE: we could fall back on load/store here too for targets without 301745b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner // SAR. However, it is doubtful that any exist. 301845b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner unsigned BitsDiff = MVT::getSizeInBits(Node->getValueType(0)) - 301945b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner MVT::getSizeInBits(ExtraVT); 302027ff112948d059524e5f4ebe249a1da0b7c710e8Chris Lattner SDOperand ShiftCst = DAG.getConstant(BitsDiff, TLI.getShiftAmountTy()); 302145b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner Result = DAG.getNode(ISD::SHL, Node->getValueType(0), 302245b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner Node->getOperand(0), ShiftCst); 302345b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner Result = DAG.getNode(ISD::SRA, Node->getValueType(0), 302445b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner Result, ShiftCst); 302545b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner } else if (Node->getOpcode() == ISD::FP_ROUND_INREG) { 30262d84c4c7b314242346dea1a7f48563333476a4d5Jim Laskey // The only way we can lower this is to turn it into a TRUNCSTORE, 302745b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner // EXTLOAD pair, targetting a temporary location (a stack slot). 302845b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner 302945b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner // NOTE: there is a choice here between constantly creating new stack 303045b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner // slots and always reusing the same one. We currently always create 303145b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner // new ones, as reuse may inhibit scheduling. 303245b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner const Type *Ty = MVT::getTypeForValueType(ExtraVT); 3033a69571c7991813c93cba64e88eced6899ce93d81Owen Anderson unsigned TySize = (unsigned)TLI.getTargetData()->getTypeSize(Ty); 303458092e35a3368e130438cbc793c8f9dce2e4fe0fChris Lattner unsigned Align = TLI.getTargetData()->getTypeAlignmentPref(Ty); 303545b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner MachineFunction &MF = DAG.getMachineFunction(); 3036edf128a7fa90f2b0b7ee24741a04a7ae1ecd6f7eMisha Brukman int SSFI = 303745b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner MF.getFrameInfo()->CreateStackObject((unsigned)TySize, Align); 303845b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner SDOperand StackSlot = DAG.getFrameIndex(SSFI, TLI.getPointerTy()); 30398b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Result = DAG.getTruncStore(DAG.getEntryNode(), Node->getOperand(0), 30408b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng StackSlot, NULL, 0, ExtraVT); 30415f056bf4b862a7c31388a68711dd3b3ed5de2be8Chris Lattner Result = DAG.getExtLoad(ISD::EXTLOAD, Node->getValueType(0), 3042466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Result, StackSlot, NULL, 0, ExtraVT); 304345b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner } else { 304445b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner assert(0 && "Unknown op"); 304545b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner } 304655ba8fba750ee0a51a9d74fa33b7242d24a4ff35Chris Lattner break; 304745b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner } 30480f69b2910810b7c0971a739f18b37fae2a20eca5Chris Lattner break; 30493e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 305045b8caf1c5a1fd8337038d64c6da8fba2d299fdfChris Lattner } 3051456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner 30524ddd283f6928fc337c1bf3277566d7b31526e8d9Chris Lattner assert(Result.getValueType() == Op.getValueType() && 30534ddd283f6928fc337c1bf3277566d7b31526e8d9Chris Lattner "Bad legalization!"); 30544ddd283f6928fc337c1bf3277566d7b31526e8d9Chris Lattner 3055456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner // Make sure that the generated code is itself legal. 3056456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (Result != Op) 3057456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Result = LegalizeOp(Result); 30583e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 305945982dad53cd184fe8947a1b0206b0b16964f359Chris Lattner // Note that LegalizeOp may be reentered even from single-use nodes, which 306045982dad53cd184fe8947a1b0206b0b16964f359Chris Lattner // means that we always must cache transformed nodes. 306145982dad53cd184fe8947a1b0206b0b16964f359Chris Lattner AddLegalizedOperand(Op, Result); 30623e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner return Result; 30633e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner} 30643e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 30658b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner/// PromoteOp - Given an operation that produces a value in an invalid type, 30668b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner/// promote it to compute the value into a larger type. The produced value will 30678b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner/// have the correct bits for the low portion of the register, but no guarantee 30688b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner/// is made about the top bits: it may be zero, sign-extended, or garbage. 306903c8546ec57523970874917854a2fb77b1ff598eChris LattnerSDOperand SelectionDAGLegalize::PromoteOp(SDOperand Op) { 307003c8546ec57523970874917854a2fb77b1ff598eChris Lattner MVT::ValueType VT = Op.getValueType(); 307171c42a0190300a8903aaea80467b88f15f327ea9Chris Lattner MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); 307203c8546ec57523970874917854a2fb77b1ff598eChris Lattner assert(getTypeAction(VT) == Promote && 307303c8546ec57523970874917854a2fb77b1ff598eChris Lattner "Caller should expand or legalize operands that are not promotable!"); 307403c8546ec57523970874917854a2fb77b1ff598eChris Lattner assert(NVT > VT && MVT::isInteger(NVT) == MVT::isInteger(VT) && 307503c8546ec57523970874917854a2fb77b1ff598eChris Lattner "Cannot promote to smaller type!"); 307603c8546ec57523970874917854a2fb77b1ff598eChris Lattner 307703c8546ec57523970874917854a2fb77b1ff598eChris Lattner SDOperand Tmp1, Tmp2, Tmp3; 307803c8546ec57523970874917854a2fb77b1ff598eChris Lattner SDOperand Result; 307903c8546ec57523970874917854a2fb77b1ff598eChris Lattner SDNode *Node = Op.Val; 308003c8546ec57523970874917854a2fb77b1ff598eChris Lattner 30816fdcb250d5692235813b30274cdfcd0e76377f00Chris Lattner std::map<SDOperand, SDOperand>::iterator I = PromotedNodes.find(Op); 30826fdcb250d5692235813b30274cdfcd0e76377f00Chris Lattner if (I != PromotedNodes.end()) return I->second; 308345982dad53cd184fe8947a1b0206b0b16964f359Chris Lattner 308403c8546ec57523970874917854a2fb77b1ff598eChris Lattner switch (Node->getOpcode()) { 3085d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner case ISD::CopyFromReg: 3086d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner assert(0 && "CopyFromReg must be legal!"); 308703c8546ec57523970874917854a2fb77b1ff598eChris Lattner default: 3088e37fe9b3a1cadceb42ac27fa0718f5a10ea2f0e6Jim Laskey#ifndef NDEBUG 3089832171cb9724d2d31c8dfb73172e2be8f6dd13eeBill Wendling cerr << "NODE: "; Node->dump(); cerr << "\n"; 3090e37fe9b3a1cadceb42ac27fa0718f5a10ea2f0e6Jim Laskey#endif 309103c8546ec57523970874917854a2fb77b1ff598eChris Lattner assert(0 && "Do not know how to promote this operator!"); 309203c8546ec57523970874917854a2fb77b1ff598eChris Lattner abort(); 3093fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman case ISD::UNDEF: 3094fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman Result = DAG.getNode(ISD::UNDEF, NVT); 3095fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman break; 309603c8546ec57523970874917854a2fb77b1ff598eChris Lattner case ISD::Constant: 3097ec176e30d655f96d75b49e620a849008bf0f63a2Chris Lattner if (VT != MVT::i1) 3098ec176e30d655f96d75b49e620a849008bf0f63a2Chris Lattner Result = DAG.getNode(ISD::SIGN_EXTEND, NVT, Op); 3099ec176e30d655f96d75b49e620a849008bf0f63a2Chris Lattner else 3100ec176e30d655f96d75b49e620a849008bf0f63a2Chris Lattner Result = DAG.getNode(ISD::ZERO_EXTEND, NVT, Op); 310103c8546ec57523970874917854a2fb77b1ff598eChris Lattner assert(isa<ConstantSDNode>(Result) && "Didn't constant fold zext?"); 310203c8546ec57523970874917854a2fb77b1ff598eChris Lattner break; 310303c8546ec57523970874917854a2fb77b1ff598eChris Lattner case ISD::ConstantFP: 310403c8546ec57523970874917854a2fb77b1ff598eChris Lattner Result = DAG.getNode(ISD::FP_EXTEND, NVT, Op); 310503c8546ec57523970874917854a2fb77b1ff598eChris Lattner assert(isa<ConstantFPSDNode>(Result) && "Didn't constant fold fp_extend?"); 310603c8546ec57523970874917854a2fb77b1ff598eChris Lattner break; 3107ef5cd1d3cf7d0b20987a545fcd2d0af2bfe6c422Chris Lattner 310882fbfb6984c1feb7d44a077ac2dc031f4a950005Chris Lattner case ISD::SETCC: 3109c9c60f6429416d362c2131b14d097ce0a9ac9599Chris Lattner assert(isTypeLegal(TLI.getSetCCResultTy()) && "SetCC type is not legal??"); 31107cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner Result = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(),Node->getOperand(0), 31117cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner Node->getOperand(1), Node->getOperand(2)); 311282fbfb6984c1feb7d44a077ac2dc031f4a950005Chris Lattner break; 3113fdfded55888e35b76bb70231a5bb2f60877c2f6aChris Lattner 311403c8546ec57523970874917854a2fb77b1ff598eChris Lattner case ISD::TRUNCATE: 311503c8546ec57523970874917854a2fb77b1ff598eChris Lattner switch (getTypeAction(Node->getOperand(0).getValueType())) { 311603c8546ec57523970874917854a2fb77b1ff598eChris Lattner case Legal: 311703c8546ec57523970874917854a2fb77b1ff598eChris Lattner Result = LegalizeOp(Node->getOperand(0)); 311803c8546ec57523970874917854a2fb77b1ff598eChris Lattner assert(Result.getValueType() >= NVT && 311903c8546ec57523970874917854a2fb77b1ff598eChris Lattner "This truncation doesn't make sense!"); 312003c8546ec57523970874917854a2fb77b1ff598eChris Lattner if (Result.getValueType() > NVT) // Truncate to NVT instead of VT 312103c8546ec57523970874917854a2fb77b1ff598eChris Lattner Result = DAG.getNode(ISD::TRUNCATE, NVT, Result); 312203c8546ec57523970874917854a2fb77b1ff598eChris Lattner break; 3123e76ad6de40b5e4c0399257b0438914c8c85ceaa1Chris Lattner case Promote: 3124e76ad6de40b5e4c0399257b0438914c8c85ceaa1Chris Lattner // The truncation is not required, because we don't guarantee anything 3125e76ad6de40b5e4c0399257b0438914c8c85ceaa1Chris Lattner // about high bits anyway. 3126e76ad6de40b5e4c0399257b0438914c8c85ceaa1Chris Lattner Result = PromoteOp(Node->getOperand(0)); 3127e76ad6de40b5e4c0399257b0438914c8c85ceaa1Chris Lattner break; 312803c8546ec57523970874917854a2fb77b1ff598eChris Lattner case Expand: 312979e46acd35df36477029e9f534ab1a366a98df56Nate Begeman ExpandOp(Node->getOperand(0), Tmp1, Tmp2); 313079e46acd35df36477029e9f534ab1a366a98df56Nate Begeman // Truncate the low part of the expanded value to the result type 3131e21c305ed85b2be4a27784ba52471f6b68fdd255Chris Lattner Result = DAG.getNode(ISD::TRUNCATE, NVT, Tmp1); 313203c8546ec57523970874917854a2fb77b1ff598eChris Lattner } 313303c8546ec57523970874917854a2fb77b1ff598eChris Lattner break; 31348b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case ISD::SIGN_EXTEND: 31358b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case ISD::ZERO_EXTEND: 313613c78e2e5f158e9008b279b43b685ff02bb3cbeaChris Lattner case ISD::ANY_EXTEND: 31378b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner switch (getTypeAction(Node->getOperand(0).getValueType())) { 31388b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case Expand: assert(0 && "BUG: Smaller reg should have been promoted!"); 31398b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case Legal: 31408b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner // Input is legal? Just do extend all the way to the larger type. 3141456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0)); 31428b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner break; 31438b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case Promote: 31448b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner // Promote the reg if it's smaller. 31458b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner Result = PromoteOp(Node->getOperand(0)); 31468b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner // The high bits are not guaranteed to be anything. Insert an extend. 31478b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner if (Node->getOpcode() == ISD::SIGN_EXTEND) 3148595dc5408ad809b9a9a417db275c43242e54b8dcChris Lattner Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, 314915e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner DAG.getValueType(Node->getOperand(0).getValueType())); 315013c78e2e5f158e9008b279b43b685ff02bb3cbeaChris Lattner else if (Node->getOpcode() == ISD::ZERO_EXTEND) 315123993561e24b2a6eaf0e036062522ab825c30d3fChris Lattner Result = DAG.getZeroExtendInReg(Result, 315223993561e24b2a6eaf0e036062522ab825c30d3fChris Lattner Node->getOperand(0).getValueType()); 31538b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner break; 31548b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner } 31558b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner break; 315635481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner case ISD::BIT_CONVERT: 315735481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner Result = ExpandBIT_CONVERT(Node->getValueType(0), Node->getOperand(0)); 315835481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner Result = PromoteOp(Result); 315935481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner break; 316035481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner 31618b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case ISD::FP_EXTEND: 31628b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner assert(0 && "Case not implemented. Dynamically dead with 2 FP types!"); 31638b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case ISD::FP_ROUND: 31648b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner switch (getTypeAction(Node->getOperand(0).getValueType())) { 31658b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case Expand: assert(0 && "BUG: Cannot expand FP regs!"); 31668b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case Promote: assert(0 && "Unreachable with 2 FP types!"); 31678b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case Legal: 31688b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner // Input is legal? Do an FP_ROUND_INREG. 3169456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Node->getOperand(0), 317015e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner DAG.getValueType(VT)); 31718b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner break; 31728b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner } 31738b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner break; 31748b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner 31758b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case ISD::SINT_TO_FP: 31768b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case ISD::UINT_TO_FP: 31778b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner switch (getTypeAction(Node->getOperand(0).getValueType())) { 31788b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case Legal: 317977e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner // No extra round required here. 3180456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Result = DAG.getNode(Node->getOpcode(), NVT, Node->getOperand(0)); 31818b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner break; 31828b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner 31838b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case Promote: 31848b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner Result = PromoteOp(Node->getOperand(0)); 31858b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner if (Node->getOpcode() == ISD::SINT_TO_FP) 31868b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, Result.getValueType(), 318715e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner Result, 318815e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner DAG.getValueType(Node->getOperand(0).getValueType())); 31898b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner else 319023993561e24b2a6eaf0e036062522ab825c30d3fChris Lattner Result = DAG.getZeroExtendInReg(Result, 319123993561e24b2a6eaf0e036062522ab825c30d3fChris Lattner Node->getOperand(0).getValueType()); 319277e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner // No extra round required here. 319377e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner Result = DAG.getNode(Node->getOpcode(), NVT, Result); 31948b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner break; 31958b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case Expand: 319677e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner Result = ExpandIntToFP(Node->getOpcode() == ISD::SINT_TO_FP, NVT, 319777e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner Node->getOperand(0)); 319877e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner // Round if we cannot tolerate excess precision. 319977e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner if (NoExcessFPPrecision) 320015e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, 320115e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner DAG.getValueType(VT)); 320277e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner break; 32038b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner } 32048b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner break; 32058b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner 32065e3c5b4e13d45d631cddf42176b380f64fde918fChris Lattner case ISD::SIGN_EXTEND_INREG: 32075e3c5b4e13d45d631cddf42176b380f64fde918fChris Lattner Result = PromoteOp(Node->getOperand(0)); 32085e3c5b4e13d45d631cddf42176b380f64fde918fChris Lattner Result = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Result, 32095e3c5b4e13d45d631cddf42176b380f64fde918fChris Lattner Node->getOperand(1)); 32105e3c5b4e13d45d631cddf42176b380f64fde918fChris Lattner break; 32118b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case ISD::FP_TO_SINT: 32128b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case ISD::FP_TO_UINT: 32138b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner switch (getTypeAction(Node->getOperand(0).getValueType())) { 32148b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case Legal: 32150b1b9dcf22745b533562134c2f0472098fe085fdEvan Cheng case Expand: 3216456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp1 = Node->getOperand(0); 32178b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner break; 32188b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case Promote: 32198b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner // The input result is prerounded, so we don't have to do anything 32208b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner // special. 32218b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner Tmp1 = PromoteOp(Node->getOperand(0)); 32228b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner break; 32238b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner } 3224d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman // If we're promoting a UINT to a larger size, check to see if the new node 3225d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman // will be legal. If it isn't, check to see if FP_TO_SINT is legal, since 3226d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman // we can use that instead. This allows us to generate better code for 3227d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman // FP_TO_UINT for small destination sizes on targets where FP_TO_UINT is not 3228d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman // legal, such as PowerPC. 3229d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman if (Node->getOpcode() == ISD::FP_TO_UINT && 3230c9c60f6429416d362c2131b14d097ce0a9ac9599Chris Lattner !TLI.isOperationLegal(ISD::FP_TO_UINT, NVT) && 3231b7f6ef12f682c7068ca7513e088177a0d1046b35Nate Begeman (TLI.isOperationLegal(ISD::FP_TO_SINT, NVT) || 3232b7f6ef12f682c7068ca7513e088177a0d1046b35Nate Begeman TLI.getOperationAction(ISD::FP_TO_SINT, NVT)==TargetLowering::Custom)){ 3233d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman Result = DAG.getNode(ISD::FP_TO_SINT, NVT, Tmp1); 3234d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman } else { 3235d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); 3236d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman } 32378b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner break; 32388b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner 32392c8086f4b9916b2d02842be5e375276023225fbaChris Lattner case ISD::FABS: 32402c8086f4b9916b2d02842be5e375276023225fbaChris Lattner case ISD::FNEG: 32412c8086f4b9916b2d02842be5e375276023225fbaChris Lattner Tmp1 = PromoteOp(Node->getOperand(0)); 32422c8086f4b9916b2d02842be5e375276023225fbaChris Lattner assert(Tmp1.getValueType() == NVT); 32432c8086f4b9916b2d02842be5e375276023225fbaChris Lattner Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); 32442c8086f4b9916b2d02842be5e375276023225fbaChris Lattner // NOTE: we do not have to do any extra rounding here for 32452c8086f4b9916b2d02842be5e375276023225fbaChris Lattner // NoExcessFPPrecision, because we know the input will have the appropriate 32462c8086f4b9916b2d02842be5e375276023225fbaChris Lattner // precision, and these operations don't modify precision at all. 32472c8086f4b9916b2d02842be5e375276023225fbaChris Lattner break; 32482c8086f4b9916b2d02842be5e375276023225fbaChris Lattner 3249da6ba87d234a934409e8d8d5b131b7341ab4bf97Chris Lattner case ISD::FSQRT: 3250da6ba87d234a934409e8d8d5b131b7341ab4bf97Chris Lattner case ISD::FSIN: 3251da6ba87d234a934409e8d8d5b131b7341ab4bf97Chris Lattner case ISD::FCOS: 3252da6ba87d234a934409e8d8d5b131b7341ab4bf97Chris Lattner Tmp1 = PromoteOp(Node->getOperand(0)); 3253da6ba87d234a934409e8d8d5b131b7341ab4bf97Chris Lattner assert(Tmp1.getValueType() == NVT); 3254da6ba87d234a934409e8d8d5b131b7341ab4bf97Chris Lattner Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1); 3255456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner if (NoExcessFPPrecision) 325615e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, 325715e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner DAG.getValueType(VT)); 3258da6ba87d234a934409e8d8d5b131b7341ab4bf97Chris Lattner break; 3259da6ba87d234a934409e8d8d5b131b7341ab4bf97Chris Lattner 326003c8546ec57523970874917854a2fb77b1ff598eChris Lattner case ISD::AND: 326103c8546ec57523970874917854a2fb77b1ff598eChris Lattner case ISD::OR: 326203c8546ec57523970874917854a2fb77b1ff598eChris Lattner case ISD::XOR: 32630f69b2910810b7c0971a739f18b37fae2a20eca5Chris Lattner case ISD::ADD: 32648b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case ISD::SUB: 32650f69b2910810b7c0971a739f18b37fae2a20eca5Chris Lattner case ISD::MUL: 32660f69b2910810b7c0971a739f18b37fae2a20eca5Chris Lattner // The input may have strange things in the top bits of the registers, but 326701b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner // these operations don't care. They may have weird bits going out, but 32680f69b2910810b7c0971a739f18b37fae2a20eca5Chris Lattner // that too is okay if they are integer operations. 32690f69b2910810b7c0971a739f18b37fae2a20eca5Chris Lattner Tmp1 = PromoteOp(Node->getOperand(0)); 32700f69b2910810b7c0971a739f18b37fae2a20eca5Chris Lattner Tmp2 = PromoteOp(Node->getOperand(1)); 32710f69b2910810b7c0971a739f18b37fae2a20eca5Chris Lattner assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); 32720f69b2910810b7c0971a739f18b37fae2a20eca5Chris Lattner Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); 327301b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner break; 327401b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner case ISD::FADD: 327501b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner case ISD::FSUB: 327601b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner case ISD::FMUL: 327701b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner Tmp1 = PromoteOp(Node->getOperand(0)); 327801b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner Tmp2 = PromoteOp(Node->getOperand(1)); 327901b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner assert(Tmp1.getValueType() == NVT && Tmp2.getValueType() == NVT); 328001b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); 328101b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner 328201b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner // Floating point operations will give excess precision that we may not be 328301b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner // able to tolerate. If we DO allow excess precision, just leave it, 328401b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner // otherwise excise it. 32858b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner // FIXME: Why would we need to round FP ops more than integer ones? 32868b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner // Is Round(Add(Add(A,B),C)) != Round(Add(Round(Add(A,B)), C)) 328701b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner if (NoExcessFPPrecision) 328815e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, 328915e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner DAG.getValueType(VT)); 32900f69b2910810b7c0971a739f18b37fae2a20eca5Chris Lattner break; 32910f69b2910810b7c0971a739f18b37fae2a20eca5Chris Lattner 32928b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case ISD::SDIV: 32938b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case ISD::SREM: 32948b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner // These operators require that their input be sign extended. 32958b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner Tmp1 = PromoteOp(Node->getOperand(0)); 32968b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner Tmp2 = PromoteOp(Node->getOperand(1)); 32978b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner if (MVT::isInteger(NVT)) { 329815e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, 329915e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner DAG.getValueType(VT)); 330015e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, 330115e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner DAG.getValueType(VT)); 33028b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner } 33038b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); 33048b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner 33058b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner // Perform FP_ROUND: this is probably overly pessimistic. 33068b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner if (MVT::isFloatingPoint(NVT) && NoExcessFPPrecision) 330715e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, 330815e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner DAG.getValueType(VT)); 33098b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner break; 331001b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner case ISD::FDIV: 331101b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner case ISD::FREM: 3312a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner case ISD::FCOPYSIGN: 331301b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner // These operators require that their input be fp extended. 3314ec57fd91af6be26a29535e7dd3dcb63beb71d898Nate Begeman switch (getTypeAction(Node->getOperand(0).getValueType())) { 3315ec57fd91af6be26a29535e7dd3dcb63beb71d898Nate Begeman case Legal: 3316ec57fd91af6be26a29535e7dd3dcb63beb71d898Nate Begeman Tmp1 = LegalizeOp(Node->getOperand(0)); 3317ec57fd91af6be26a29535e7dd3dcb63beb71d898Nate Begeman break; 3318ec57fd91af6be26a29535e7dd3dcb63beb71d898Nate Begeman case Promote: 3319ec57fd91af6be26a29535e7dd3dcb63beb71d898Nate Begeman Tmp1 = PromoteOp(Node->getOperand(0)); 3320ec57fd91af6be26a29535e7dd3dcb63beb71d898Nate Begeman break; 3321ec57fd91af6be26a29535e7dd3dcb63beb71d898Nate Begeman case Expand: 3322ec57fd91af6be26a29535e7dd3dcb63beb71d898Nate Begeman assert(0 && "not implemented"); 3323ec57fd91af6be26a29535e7dd3dcb63beb71d898Nate Begeman } 3324ec57fd91af6be26a29535e7dd3dcb63beb71d898Nate Begeman switch (getTypeAction(Node->getOperand(1).getValueType())) { 3325ec57fd91af6be26a29535e7dd3dcb63beb71d898Nate Begeman case Legal: 3326ec57fd91af6be26a29535e7dd3dcb63beb71d898Nate Begeman Tmp2 = LegalizeOp(Node->getOperand(1)); 3327ec57fd91af6be26a29535e7dd3dcb63beb71d898Nate Begeman break; 3328ec57fd91af6be26a29535e7dd3dcb63beb71d898Nate Begeman case Promote: 3329ec57fd91af6be26a29535e7dd3dcb63beb71d898Nate Begeman Tmp2 = PromoteOp(Node->getOperand(1)); 3330ec57fd91af6be26a29535e7dd3dcb63beb71d898Nate Begeman break; 3331ec57fd91af6be26a29535e7dd3dcb63beb71d898Nate Begeman case Expand: 3332ec57fd91af6be26a29535e7dd3dcb63beb71d898Nate Begeman assert(0 && "not implemented"); 3333ec57fd91af6be26a29535e7dd3dcb63beb71d898Nate Begeman } 333401b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); 333501b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner 333601b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner // Perform FP_ROUND: this is probably overly pessimistic. 3337a09f848c11c9db3c2614e0275a3256310ac26653Chris Lattner if (NoExcessFPPrecision && Node->getOpcode() != ISD::FCOPYSIGN) 333801b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner Result = DAG.getNode(ISD::FP_ROUND_INREG, NVT, Result, 333901b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner DAG.getValueType(VT)); 334001b3d73c20f5afb8265ae943a8ba23c2238c5eeaChris Lattner break; 33418b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner 33428b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case ISD::UDIV: 33438b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case ISD::UREM: 33448b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner // These operators require that their input be zero extended. 33458b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner Tmp1 = PromoteOp(Node->getOperand(0)); 33468b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner Tmp2 = PromoteOp(Node->getOperand(1)); 33478b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner assert(MVT::isInteger(NVT) && "Operators don't apply to FP!"); 334823993561e24b2a6eaf0e036062522ab825c30d3fChris Lattner Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); 334923993561e24b2a6eaf0e036062522ab825c30d3fChris Lattner Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); 33508b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner Result = DAG.getNode(Node->getOpcode(), NVT, Tmp1, Tmp2); 33518b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner break; 33528b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner 33538b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case ISD::SHL: 33548b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner Tmp1 = PromoteOp(Node->getOperand(0)); 3355456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Result = DAG.getNode(ISD::SHL, NVT, Tmp1, Node->getOperand(1)); 33568b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner break; 33578b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case ISD::SRA: 33588b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner // The input value must be properly sign extended. 33598b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner Tmp1 = PromoteOp(Node->getOperand(0)); 336015e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, 336115e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner DAG.getValueType(VT)); 3362456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Result = DAG.getNode(ISD::SRA, NVT, Tmp1, Node->getOperand(1)); 33638b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner break; 33648b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner case ISD::SRL: 33658b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner // The input value must be properly zero extended. 33668b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner Tmp1 = PromoteOp(Node->getOperand(0)); 336723993561e24b2a6eaf0e036062522ab825c30d3fChris Lattner Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); 3368456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Result = DAG.getNode(ISD::SRL, NVT, Tmp1, Node->getOperand(1)); 33698b6fa22e722e1de7522aae51d6cdd0f552d489daChris Lattner break; 33700aed7840ec8cc85f91b4aa6e69318bba0cbd1f03Nate Begeman 33710aed7840ec8cc85f91b4aa6e69318bba0cbd1f03Nate Begeman case ISD::VAARG: 3372456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp1 = Node->getOperand(0); // Get the chain. 3373456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp2 = Node->getOperand(1); // Get the pointer. 33740aed7840ec8cc85f91b4aa6e69318bba0cbd1f03Nate Begeman if (TLI.getOperationAction(ISD::VAARG, VT) == TargetLowering::Custom) { 33750aed7840ec8cc85f91b4aa6e69318bba0cbd1f03Nate Begeman Tmp3 = DAG.getVAArg(VT, Tmp1, Tmp2, Node->getOperand(2)); 33760aed7840ec8cc85f91b4aa6e69318bba0cbd1f03Nate Begeman Result = TLI.CustomPromoteOperation(Tmp3, DAG); 33770aed7840ec8cc85f91b4aa6e69318bba0cbd1f03Nate Begeman } else { 3378466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng SrcValueSDNode *SV = cast<SrcValueSDNode>(Node->getOperand(2)); 33790aed7840ec8cc85f91b4aa6e69318bba0cbd1f03Nate Begeman SDOperand VAList = DAG.getLoad(TLI.getPointerTy(), Tmp1, Tmp2, 3380466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng SV->getValue(), SV->getOffset()); 33810aed7840ec8cc85f91b4aa6e69318bba0cbd1f03Nate Begeman // Increment the pointer, VAList, to the next vaarg 33820aed7840ec8cc85f91b4aa6e69318bba0cbd1f03Nate Begeman Tmp3 = DAG.getNode(ISD::ADD, TLI.getPointerTy(), VAList, 33830aed7840ec8cc85f91b4aa6e69318bba0cbd1f03Nate Begeman DAG.getConstant(MVT::getSizeInBits(VT)/8, 33840aed7840ec8cc85f91b4aa6e69318bba0cbd1f03Nate Begeman TLI.getPointerTy())); 33850aed7840ec8cc85f91b4aa6e69318bba0cbd1f03Nate Begeman // Store the incremented VAList to the legalized pointer 33868b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Tmp3 = DAG.getStore(VAList.getValue(1), Tmp3, Tmp2, SV->getValue(), 33878b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng SV->getOffset()); 33880aed7840ec8cc85f91b4aa6e69318bba0cbd1f03Nate Begeman // Load the actual argument out of the pointer VAList 3389466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Result = DAG.getExtLoad(ISD::EXTLOAD, NVT, Tmp3, VAList, NULL, 0, VT); 33900aed7840ec8cc85f91b4aa6e69318bba0cbd1f03Nate Begeman } 33910aed7840ec8cc85f91b4aa6e69318bba0cbd1f03Nate Begeman // Remember that we legalized the chain. 3392456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); 33930aed7840ec8cc85f91b4aa6e69318bba0cbd1f03Nate Begeman break; 33940aed7840ec8cc85f91b4aa6e69318bba0cbd1f03Nate Begeman 3395466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng case ISD::LOAD: { 3396466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng LoadSDNode *LD = cast<LoadSDNode>(Node); 339762f2a3c7aa0eba3e7bc5e2d59e268c5e1f48fb46Evan Cheng ISD::LoadExtType ExtType = ISD::isNON_EXTLoad(Node) 339862f2a3c7aa0eba3e7bc5e2d59e268c5e1f48fb46Evan Cheng ? ISD::EXTLOAD : LD->getExtensionType(); 339962f2a3c7aa0eba3e7bc5e2d59e268c5e1f48fb46Evan Cheng Result = DAG.getExtLoad(ExtType, NVT, 340062f2a3c7aa0eba3e7bc5e2d59e268c5e1f48fb46Evan Cheng LD->getChain(), LD->getBasePtr(), 340155b5708b6bbffc79cf133c31faa51d144bfc5d4aChris Lattner LD->getSrcValue(), LD->getSrcValueOffset(), 34022e49f090f9656af7d5ed4d5c4e9fa26af59c7233Evan Cheng LD->getLoadedVT()); 34034c8f8f0481b26818d7810a6a585e7ecf52973e93Chris Lattner // Remember that we legalized the chain. 3404456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); 34054c8f8f0481b26818d7810a6a585e7ecf52973e93Chris Lattner break; 3406466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng } 340703c8546ec57523970874917854a2fb77b1ff598eChris Lattner case ISD::SELECT: 340803c8546ec57523970874917854a2fb77b1ff598eChris Lattner Tmp2 = PromoteOp(Node->getOperand(1)); // Legalize the op0 340903c8546ec57523970874917854a2fb77b1ff598eChris Lattner Tmp3 = PromoteOp(Node->getOperand(2)); // Legalize the op1 3410456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Result = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), Tmp2, Tmp3); 341103c8546ec57523970874917854a2fb77b1ff598eChris Lattner break; 34129373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman case ISD::SELECT_CC: 34139373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman Tmp2 = PromoteOp(Node->getOperand(2)); // True 34149373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman Tmp3 = PromoteOp(Node->getOperand(3)); // False 34159373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman Result = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), 3416456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Node->getOperand(1), Tmp2, Tmp3, Node->getOperand(4)); 34179373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman break; 3418d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman case ISD::BSWAP: 3419d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman Tmp1 = Node->getOperand(0); 3420d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Tmp1); 3421d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman Tmp1 = DAG.getNode(ISD::BSWAP, NVT, Tmp1); 3422d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman Result = DAG.getNode(ISD::SRL, NVT, Tmp1, 3423d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman DAG.getConstant(getSizeInBits(NVT) - getSizeInBits(VT), 3424d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman TLI.getShiftAmountTy())); 3425d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman break; 3426fecf095292991bdf9396fec474011446107f9813Andrew Lenharth case ISD::CTPOP: 3427fecf095292991bdf9396fec474011446107f9813Andrew Lenharth case ISD::CTTZ: 3428fecf095292991bdf9396fec474011446107f9813Andrew Lenharth case ISD::CTLZ: 3429456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner // Zero extend the argument 3430456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0)); 3431fecf095292991bdf9396fec474011446107f9813Andrew Lenharth // Perform the larger operation, then subtract if needed. 3432fecf095292991bdf9396fec474011446107f9813Andrew Lenharth Tmp1 = DAG.getNode(Node->getOpcode(), NVT, Tmp1); 3433456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner switch(Node->getOpcode()) { 3434fecf095292991bdf9396fec474011446107f9813Andrew Lenharth case ISD::CTPOP: 3435fecf095292991bdf9396fec474011446107f9813Andrew Lenharth Result = Tmp1; 3436fecf095292991bdf9396fec474011446107f9813Andrew Lenharth break; 3437fecf095292991bdf9396fec474011446107f9813Andrew Lenharth case ISD::CTTZ: 3438456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner // if Tmp1 == sizeinbits(NVT) then Tmp1 = sizeinbits(Old VT) 3439d2558e3e4af2930730e2314868afd09ba005e282Nate Begeman Tmp2 = DAG.getSetCC(TLI.getSetCCResultTy(), Tmp1, 34407cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner DAG.getConstant(getSizeInBits(NVT), NVT), ISD::SETEQ); 344100b16889ab461b7ecef1c91ade101186b7f1fce2Jeff Cohen Result = DAG.getNode(ISD::SELECT, NVT, Tmp2, 3442456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner DAG.getConstant(getSizeInBits(VT), NVT), Tmp1); 3443fecf095292991bdf9396fec474011446107f9813Andrew Lenharth break; 3444fecf095292991bdf9396fec474011446107f9813Andrew Lenharth case ISD::CTLZ: 3445fecf095292991bdf9396fec474011446107f9813Andrew Lenharth //Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT)) 344600b16889ab461b7ecef1c91ade101186b7f1fce2Jeff Cohen Result = DAG.getNode(ISD::SUB, NVT, Tmp1, 344700b16889ab461b7ecef1c91ade101186b7f1fce2Jeff Cohen DAG.getConstant(getSizeInBits(NVT) - 3448fecf095292991bdf9396fec474011446107f9813Andrew Lenharth getSizeInBits(VT), NVT)); 3449fecf095292991bdf9396fec474011446107f9813Andrew Lenharth break; 3450fecf095292991bdf9396fec474011446107f9813Andrew Lenharth } 3451fecf095292991bdf9396fec474011446107f9813Andrew Lenharth break; 34521597221eace1c53ce5f84a7018397497d11a8393Chris Lattner case ISD::VEXTRACT_VECTOR_ELT: 34531597221eace1c53ce5f84a7018397497d11a8393Chris Lattner Result = PromoteOp(LowerVEXTRACT_VECTOR_ELT(Op)); 34541597221eace1c53ce5f84a7018397497d11a8393Chris Lattner break; 34554aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner case ISD::EXTRACT_VECTOR_ELT: 34564aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner Result = PromoteOp(ExpandEXTRACT_VECTOR_ELT(Op)); 34574aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner break; 345803c8546ec57523970874917854a2fb77b1ff598eChris Lattner } 345903c8546ec57523970874917854a2fb77b1ff598eChris Lattner 346003c8546ec57523970874917854a2fb77b1ff598eChris Lattner assert(Result.Val && "Didn't set a result!"); 3461456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner 3462456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner // Make sure the result is itself legal. 3463456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Result = LegalizeOp(Result); 3464456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner 3465456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner // Remember that we promoted this! 346603c8546ec57523970874917854a2fb77b1ff598eChris Lattner AddPromotedOperand(Op, Result); 346703c8546ec57523970874917854a2fb77b1ff598eChris Lattner return Result; 346803c8546ec57523970874917854a2fb77b1ff598eChris Lattner} 34693e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 34701597221eace1c53ce5f84a7018397497d11a8393Chris Lattner/// LowerVEXTRACT_VECTOR_ELT - Lower a VEXTRACT_VECTOR_ELT operation into a 34711597221eace1c53ce5f84a7018397497d11a8393Chris Lattner/// EXTRACT_VECTOR_ELT operation, to memory operations, or to scalar code based 34721597221eace1c53ce5f84a7018397497d11a8393Chris Lattner/// on the vector type. The return type of this matches the element type of the 34731597221eace1c53ce5f84a7018397497d11a8393Chris Lattner/// vector, which may not be legal for the target. 34741597221eace1c53ce5f84a7018397497d11a8393Chris LattnerSDOperand SelectionDAGLegalize::LowerVEXTRACT_VECTOR_ELT(SDOperand Op) { 34751597221eace1c53ce5f84a7018397497d11a8393Chris Lattner // We know that operand #0 is the Vec vector. If the index is a constant 34761597221eace1c53ce5f84a7018397497d11a8393Chris Lattner // or if the invec is a supported hardware type, we can use it. Otherwise, 34771597221eace1c53ce5f84a7018397497d11a8393Chris Lattner // lower to a store then an indexed load. 34781597221eace1c53ce5f84a7018397497d11a8393Chris Lattner SDOperand Vec = Op.getOperand(0); 34791597221eace1c53ce5f84a7018397497d11a8393Chris Lattner SDOperand Idx = LegalizeOp(Op.getOperand(1)); 34801597221eace1c53ce5f84a7018397497d11a8393Chris Lattner 34811597221eace1c53ce5f84a7018397497d11a8393Chris Lattner SDNode *InVal = Vec.Val; 34821597221eace1c53ce5f84a7018397497d11a8393Chris Lattner unsigned NumElems = cast<ConstantSDNode>(*(InVal->op_end()-2))->getValue(); 34831597221eace1c53ce5f84a7018397497d11a8393Chris Lattner MVT::ValueType EVT = cast<VTSDNode>(*(InVal->op_end()-1))->getVT(); 34841597221eace1c53ce5f84a7018397497d11a8393Chris Lattner 34851597221eace1c53ce5f84a7018397497d11a8393Chris Lattner // Figure out if there is a Packed type corresponding to this Vector 34861597221eace1c53ce5f84a7018397497d11a8393Chris Lattner // type. If so, convert to the packed type. 34871597221eace1c53ce5f84a7018397497d11a8393Chris Lattner MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems); 34881597221eace1c53ce5f84a7018397497d11a8393Chris Lattner if (TVT != MVT::Other && TLI.isTypeLegal(TVT)) { 34891597221eace1c53ce5f84a7018397497d11a8393Chris Lattner // Turn this into a packed extract_vector_elt operation. 34901597221eace1c53ce5f84a7018397497d11a8393Chris Lattner Vec = PackVectorOp(Vec, TVT); 34911597221eace1c53ce5f84a7018397497d11a8393Chris Lattner return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, Op.getValueType(), Vec, Idx); 34921597221eace1c53ce5f84a7018397497d11a8393Chris Lattner } else if (NumElems == 1) { 34931597221eace1c53ce5f84a7018397497d11a8393Chris Lattner // This must be an access of the only element. Return it. 34941597221eace1c53ce5f84a7018397497d11a8393Chris Lattner return PackVectorOp(Vec, EVT); 34951597221eace1c53ce5f84a7018397497d11a8393Chris Lattner } else if (ConstantSDNode *CIdx = dyn_cast<ConstantSDNode>(Idx)) { 34961597221eace1c53ce5f84a7018397497d11a8393Chris Lattner SDOperand Lo, Hi; 34971597221eace1c53ce5f84a7018397497d11a8393Chris Lattner SplitVectorOp(Vec, Lo, Hi); 34981597221eace1c53ce5f84a7018397497d11a8393Chris Lattner if (CIdx->getValue() < NumElems/2) { 34991597221eace1c53ce5f84a7018397497d11a8393Chris Lattner Vec = Lo; 35001597221eace1c53ce5f84a7018397497d11a8393Chris Lattner } else { 35011597221eace1c53ce5f84a7018397497d11a8393Chris Lattner Vec = Hi; 35021597221eace1c53ce5f84a7018397497d11a8393Chris Lattner Idx = DAG.getConstant(CIdx->getValue() - NumElems/2, Idx.getValueType()); 35031597221eace1c53ce5f84a7018397497d11a8393Chris Lattner } 35041597221eace1c53ce5f84a7018397497d11a8393Chris Lattner 35051597221eace1c53ce5f84a7018397497d11a8393Chris Lattner // It's now an extract from the appropriate high or low part. Recurse. 35061597221eace1c53ce5f84a7018397497d11a8393Chris Lattner Op = DAG.UpdateNodeOperands(Op, Vec, Idx); 35071597221eace1c53ce5f84a7018397497d11a8393Chris Lattner return LowerVEXTRACT_VECTOR_ELT(Op); 35081597221eace1c53ce5f84a7018397497d11a8393Chris Lattner } else { 35091597221eace1c53ce5f84a7018397497d11a8393Chris Lattner // Variable index case for extract element. 35101597221eace1c53ce5f84a7018397497d11a8393Chris Lattner // FIXME: IMPLEMENT STORE/LOAD lowering. Need alignment of stack slot!! 35111597221eace1c53ce5f84a7018397497d11a8393Chris Lattner assert(0 && "unimp!"); 35121597221eace1c53ce5f84a7018397497d11a8393Chris Lattner return SDOperand(); 35131597221eace1c53ce5f84a7018397497d11a8393Chris Lattner } 35141597221eace1c53ce5f84a7018397497d11a8393Chris Lattner} 35151597221eace1c53ce5f84a7018397497d11a8393Chris Lattner 35164aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner/// ExpandEXTRACT_VECTOR_ELT - Expand an EXTRACT_VECTOR_ELT operation into 35174aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner/// memory traffic. 35184aab2f4ab50d2b04dc559c7b197f1de7612c896bChris LattnerSDOperand SelectionDAGLegalize::ExpandEXTRACT_VECTOR_ELT(SDOperand Op) { 35194aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner SDOperand Vector = Op.getOperand(0); 35204aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner SDOperand Idx = Op.getOperand(1); 35214aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner 35224aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner // If the target doesn't support this, store the value to a temporary 35234aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner // stack slot, then LOAD the scalar element back out. 35244aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner SDOperand StackPtr = CreateStackTemporary(Vector.getValueType()); 35258b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Vector, StackPtr, NULL, 0); 35264aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner 35274aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner // Add the offset to the index. 35284aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner unsigned EltSize = MVT::getSizeInBits(Op.getValueType())/8; 35294aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner Idx = DAG.getNode(ISD::MUL, Idx.getValueType(), Idx, 35304aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner DAG.getConstant(EltSize, Idx.getValueType())); 35314aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner StackPtr = DAG.getNode(ISD::ADD, Idx.getValueType(), Idx, StackPtr); 35324aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner 3533466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng return DAG.getLoad(Op.getValueType(), Ch, StackPtr, NULL, 0); 35344aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner} 35354aab2f4ab50d2b04dc559c7b197f1de7612c896bChris Lattner 35361597221eace1c53ce5f84a7018397497d11a8393Chris Lattner 3537750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman/// LegalizeSetCCOperands - Attempts to create a legal LHS and RHS for a SETCC 3538750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman/// with condition CC on the current target. This usually involves legalizing 3539750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman/// or promoting the arguments. In the case where LHS and RHS must be expanded, 3540750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman/// there may be no choice but to create a new SetCC node to represent the 3541750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman/// legalized value of setcc lhs, rhs. In this case, the value is returned in 3542750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman/// LHS, and the SDOperand returned in RHS has a nil SDNode value. 3543750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begemanvoid SelectionDAGLegalize::LegalizeSetCCOperands(SDOperand &LHS, 3544750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman SDOperand &RHS, 3545750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman SDOperand &CC) { 3546750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman SDOperand Tmp1, Tmp2, Result; 3547750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman 3548750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman switch (getTypeAction(LHS.getValueType())) { 3549750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case Legal: 3550750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp1 = LegalizeOp(LHS); // LHS 3551750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp2 = LegalizeOp(RHS); // RHS 3552750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman break; 3553750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case Promote: 3554750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp1 = PromoteOp(LHS); // LHS 3555750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp2 = PromoteOp(RHS); // RHS 3556750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman 3557750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // If this is an FP compare, the operands have already been extended. 3558750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman if (MVT::isInteger(LHS.getValueType())) { 3559750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman MVT::ValueType VT = LHS.getValueType(); 3560750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); 3561750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman 3562750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // Otherwise, we have to insert explicit sign or zero extends. Note 3563750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // that we could insert sign extends for ALL conditions, but zero extend 3564750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // is cheaper on many machines (an AND instead of two shifts), so prefer 3565750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // it. 3566750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman switch (cast<CondCodeSDNode>(CC)->get()) { 3567750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman default: assert(0 && "Unknown integer comparison!"); 3568750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case ISD::SETEQ: 3569750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case ISD::SETNE: 3570750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case ISD::SETUGE: 3571750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case ISD::SETUGT: 3572750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case ISD::SETULE: 3573750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case ISD::SETULT: 3574750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // ALL of these operations will work if we either sign or zero extend 3575750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // the operands (including the unsigned comparisons!). Zero extend is 3576750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // usually a simpler/cheaper operation, so prefer it. 3577750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp1 = DAG.getZeroExtendInReg(Tmp1, VT); 3578750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp2 = DAG.getZeroExtendInReg(Tmp2, VT); 3579750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman break; 3580750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case ISD::SETGE: 3581750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case ISD::SETGT: 3582750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case ISD::SETLT: 3583750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case ISD::SETLE: 3584750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp1 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp1, 3585750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman DAG.getValueType(VT)); 3586750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp2 = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Tmp2, 3587750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman DAG.getValueType(VT)); 3588750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman break; 3589750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman } 3590750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman } 3591750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman break; 35922b49c500838666dd0186d021389d4dd70ffda240Evan Cheng case Expand: { 35932b49c500838666dd0186d021389d4dd70ffda240Evan Cheng MVT::ValueType VT = LHS.getValueType(); 35942b49c500838666dd0186d021389d4dd70ffda240Evan Cheng if (VT == MVT::f32 || VT == MVT::f64) { 35952b49c500838666dd0186d021389d4dd70ffda240Evan Cheng // Expand into one or more soft-fp libcall(s). 359656966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng RTLIB::Libcall LC1, LC2 = RTLIB::UNKNOWN_LIBCALL; 35972d53a320b4dbcd4af54b17458ed81c3963b544fdChris Lattner ISD::CondCode CC1, CC2 = ISD::SETCC_INVALID; 35982b49c500838666dd0186d021389d4dd70ffda240Evan Cheng switch (cast<CondCodeSDNode>(CC)->get()) { 35992b49c500838666dd0186d021389d4dd70ffda240Evan Cheng case ISD::SETEQ: 36002b49c500838666dd0186d021389d4dd70ffda240Evan Cheng case ISD::SETOEQ: 360156966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC1 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; 36022b49c500838666dd0186d021389d4dd70ffda240Evan Cheng CC1 = ISD::SETEQ; 36032b49c500838666dd0186d021389d4dd70ffda240Evan Cheng break; 36042b49c500838666dd0186d021389d4dd70ffda240Evan Cheng case ISD::SETNE: 36052b49c500838666dd0186d021389d4dd70ffda240Evan Cheng case ISD::SETUNE: 360656966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC1 = (VT == MVT::f32) ? RTLIB::UNE_F32 : RTLIB::UNE_F64; 36072b49c500838666dd0186d021389d4dd70ffda240Evan Cheng CC1 = ISD::SETNE; 36082b49c500838666dd0186d021389d4dd70ffda240Evan Cheng break; 36092b49c500838666dd0186d021389d4dd70ffda240Evan Cheng case ISD::SETGE: 36102b49c500838666dd0186d021389d4dd70ffda240Evan Cheng case ISD::SETOGE: 361156966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC1 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; 36122b49c500838666dd0186d021389d4dd70ffda240Evan Cheng CC1 = ISD::SETGE; 36132b49c500838666dd0186d021389d4dd70ffda240Evan Cheng break; 36142b49c500838666dd0186d021389d4dd70ffda240Evan Cheng case ISD::SETLT: 36152b49c500838666dd0186d021389d4dd70ffda240Evan Cheng case ISD::SETOLT: 361656966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; 36172b49c500838666dd0186d021389d4dd70ffda240Evan Cheng CC1 = ISD::SETLT; 36182b49c500838666dd0186d021389d4dd70ffda240Evan Cheng break; 36192b49c500838666dd0186d021389d4dd70ffda240Evan Cheng case ISD::SETLE: 36202b49c500838666dd0186d021389d4dd70ffda240Evan Cheng case ISD::SETOLE: 362156966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC1 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; 36222b49c500838666dd0186d021389d4dd70ffda240Evan Cheng CC1 = ISD::SETLE; 36232b49c500838666dd0186d021389d4dd70ffda240Evan Cheng break; 36242b49c500838666dd0186d021389d4dd70ffda240Evan Cheng case ISD::SETGT: 36252b49c500838666dd0186d021389d4dd70ffda240Evan Cheng case ISD::SETOGT: 362656966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC1 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; 36272b49c500838666dd0186d021389d4dd70ffda240Evan Cheng CC1 = ISD::SETGT; 36282b49c500838666dd0186d021389d4dd70ffda240Evan Cheng break; 36292b49c500838666dd0186d021389d4dd70ffda240Evan Cheng case ISD::SETUO: 36302b49c500838666dd0186d021389d4dd70ffda240Evan Cheng case ISD::SETO: 363156966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; 36322b49c500838666dd0186d021389d4dd70ffda240Evan Cheng CC1 = cast<CondCodeSDNode>(CC)->get() == ISD::SETO 36332b49c500838666dd0186d021389d4dd70ffda240Evan Cheng ? ISD::SETEQ : ISD::SETNE; 36342b49c500838666dd0186d021389d4dd70ffda240Evan Cheng break; 36352b49c500838666dd0186d021389d4dd70ffda240Evan Cheng default: 363656966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC1 = (VT == MVT::f32) ? RTLIB::UO_F32 : RTLIB::UO_F64; 36372b49c500838666dd0186d021389d4dd70ffda240Evan Cheng CC1 = ISD::SETNE; 36382b49c500838666dd0186d021389d4dd70ffda240Evan Cheng switch (cast<CondCodeSDNode>(CC)->get()) { 36392b49c500838666dd0186d021389d4dd70ffda240Evan Cheng case ISD::SETONE: 36402b49c500838666dd0186d021389d4dd70ffda240Evan Cheng // SETONE = SETOLT | SETOGT 364156966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC1 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; 36422b49c500838666dd0186d021389d4dd70ffda240Evan Cheng CC1 = ISD::SETLT; 36432b49c500838666dd0186d021389d4dd70ffda240Evan Cheng // Fallthrough 36442b49c500838666dd0186d021389d4dd70ffda240Evan Cheng case ISD::SETUGT: 364556966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC2 = (VT == MVT::f32) ? RTLIB::OGT_F32 : RTLIB::OGT_F64; 36462b49c500838666dd0186d021389d4dd70ffda240Evan Cheng CC2 = ISD::SETGT; 36472b49c500838666dd0186d021389d4dd70ffda240Evan Cheng break; 36482b49c500838666dd0186d021389d4dd70ffda240Evan Cheng case ISD::SETUGE: 364956966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC2 = (VT == MVT::f32) ? RTLIB::OGE_F32 : RTLIB::OGE_F64; 36502b49c500838666dd0186d021389d4dd70ffda240Evan Cheng CC2 = ISD::SETGE; 36512b49c500838666dd0186d021389d4dd70ffda240Evan Cheng break; 36522b49c500838666dd0186d021389d4dd70ffda240Evan Cheng case ISD::SETULT: 365356966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC2 = (VT == MVT::f32) ? RTLIB::OLT_F32 : RTLIB::OLT_F64; 36542b49c500838666dd0186d021389d4dd70ffda240Evan Cheng CC2 = ISD::SETLT; 36552b49c500838666dd0186d021389d4dd70ffda240Evan Cheng break; 36562b49c500838666dd0186d021389d4dd70ffda240Evan Cheng case ISD::SETULE: 365756966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC2 = (VT == MVT::f32) ? RTLIB::OLE_F32 : RTLIB::OLE_F64; 36582b49c500838666dd0186d021389d4dd70ffda240Evan Cheng CC2 = ISD::SETLE; 36592b49c500838666dd0186d021389d4dd70ffda240Evan Cheng break; 366056966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng case ISD::SETUEQ: 366156966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC2 = (VT == MVT::f32) ? RTLIB::OEQ_F32 : RTLIB::OEQ_F64; 366256966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng CC2 = ISD::SETEQ; 366356966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng break; 36642b49c500838666dd0186d021389d4dd70ffda240Evan Cheng default: assert(0 && "Unsupported FP setcc!"); 36652b49c500838666dd0186d021389d4dd70ffda240Evan Cheng } 36662b49c500838666dd0186d021389d4dd70ffda240Evan Cheng } 36672b49c500838666dd0186d021389d4dd70ffda240Evan Cheng 36682b49c500838666dd0186d021389d4dd70ffda240Evan Cheng SDOperand Dummy; 366956966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Tmp1 = ExpandLibCall(TLI.getLibcallName(LC1), 367047857812e29324a9d1560796a05b53d3a9217fd9Reid Spencer DAG.getNode(ISD::MERGE_VALUES, VT, LHS, RHS).Val, 3671b47b25cfda5aee910e128c89d08c630722eb480bReid Spencer false /*sign irrelevant*/, Dummy); 36722b49c500838666dd0186d021389d4dd70ffda240Evan Cheng Tmp2 = DAG.getConstant(0, MVT::i32); 36732b49c500838666dd0186d021389d4dd70ffda240Evan Cheng CC = DAG.getCondCode(CC1); 367456966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng if (LC2 != RTLIB::UNKNOWN_LIBCALL) { 36752b49c500838666dd0186d021389d4dd70ffda240Evan Cheng Tmp1 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), Tmp1, Tmp2, CC); 367656966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LHS = ExpandLibCall(TLI.getLibcallName(LC2), 367747857812e29324a9d1560796a05b53d3a9217fd9Reid Spencer DAG.getNode(ISD::MERGE_VALUES, VT, LHS, RHS).Val, 3678b47b25cfda5aee910e128c89d08c630722eb480bReid Spencer false /*sign irrelevant*/, Dummy); 36792b49c500838666dd0186d021389d4dd70ffda240Evan Cheng Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), LHS, Tmp2, 36802b49c500838666dd0186d021389d4dd70ffda240Evan Cheng DAG.getCondCode(CC2)); 36812b49c500838666dd0186d021389d4dd70ffda240Evan Cheng Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); 36822b49c500838666dd0186d021389d4dd70ffda240Evan Cheng Tmp2 = SDOperand(); 36832b49c500838666dd0186d021389d4dd70ffda240Evan Cheng } 36842b49c500838666dd0186d021389d4dd70ffda240Evan Cheng LHS = Tmp1; 36852b49c500838666dd0186d021389d4dd70ffda240Evan Cheng RHS = Tmp2; 36862b49c500838666dd0186d021389d4dd70ffda240Evan Cheng return; 36872b49c500838666dd0186d021389d4dd70ffda240Evan Cheng } 36882b49c500838666dd0186d021389d4dd70ffda240Evan Cheng 3689750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman SDOperand LHSLo, LHSHi, RHSLo, RHSHi; 3690750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman ExpandOp(LHS, LHSLo, LHSHi); 36912b49c500838666dd0186d021389d4dd70ffda240Evan Cheng ExpandOp(RHS, RHSLo, RHSHi); 3692750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman switch (cast<CondCodeSDNode>(CC)->get()) { 3693750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case ISD::SETEQ: 3694750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case ISD::SETNE: 3695750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman if (RHSLo == RHSHi) 3696750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman if (ConstantSDNode *RHSCST = dyn_cast<ConstantSDNode>(RHSLo)) 3697750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman if (RHSCST->isAllOnesValue()) { 3698750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // Comparison to -1. 3699750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp1 = DAG.getNode(ISD::AND, LHSLo.getValueType(), LHSLo, LHSHi); 3700750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp2 = RHSLo; 3701750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman break; 3702750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman } 3703750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman 3704750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp1 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSLo, RHSLo); 3705750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp2 = DAG.getNode(ISD::XOR, LHSLo.getValueType(), LHSHi, RHSHi); 3706750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp1 = DAG.getNode(ISD::OR, Tmp1.getValueType(), Tmp1, Tmp2); 3707750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp2 = DAG.getConstant(0, Tmp1.getValueType()); 3708750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman break; 3709750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman default: 3710750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // If this is a comparison of the sign bit, just look at the top part. 3711750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // X > -1, x < 0 3712750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman if (ConstantSDNode *CST = dyn_cast<ConstantSDNode>(RHS)) 3713750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman if ((cast<CondCodeSDNode>(CC)->get() == ISD::SETLT && 3714750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman CST->getValue() == 0) || // X < 0 3715750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman (cast<CondCodeSDNode>(CC)->get() == ISD::SETGT && 3716750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman CST->isAllOnesValue())) { // X > -1 3717750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp1 = LHSHi; 3718750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp2 = RHSHi; 3719750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman break; 3720750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman } 3721750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman 3722750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // FIXME: This generated code sucks. 3723750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman ISD::CondCode LowCC; 3724750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman switch (cast<CondCodeSDNode>(CC)->get()) { 3725750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman default: assert(0 && "Unknown integer setcc!"); 3726750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case ISD::SETLT: 3727750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case ISD::SETULT: LowCC = ISD::SETULT; break; 3728750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case ISD::SETGT: 3729750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case ISD::SETUGT: LowCC = ISD::SETUGT; break; 3730750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case ISD::SETLE: 3731750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case ISD::SETULE: LowCC = ISD::SETULE; break; 3732750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case ISD::SETGE: 3733750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman case ISD::SETUGE: LowCC = ISD::SETUGE; break; 3734750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman } 3735750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman 3736750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // Tmp1 = lo(op1) < lo(op2) // Always unsigned comparison 3737750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // Tmp2 = hi(op1) < hi(op2) // Signedness depends on operands 3738750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // dest = hi(op1) == hi(op2) ? Tmp1 : Tmp2; 3739750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman 3740750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // NOTE: on targets without efficient SELECT of bools, we can always use 3741750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman // this identity: (B1 ? B2 : B3) --> (B1 & B2)|(!B1&B3) 3742750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp1 = DAG.getSetCC(TLI.getSetCCResultTy(), LHSLo, RHSLo, LowCC); 3743750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultTy(), LHSHi, RHSHi, CC); 3744750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Result = DAG.getSetCC(TLI.getSetCCResultTy(), LHSHi, RHSHi, ISD::SETEQ); 3745750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Result = LegalizeOp(DAG.getNode(ISD::SELECT, Tmp1.getValueType(), 3746750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Result, Tmp1, Tmp2)); 3747750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman Tmp1 = Result; 3748da06e9e665a1a94886541ed85e97315f58b357b0Nate Begeman Tmp2 = SDOperand(); 3749750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman } 3750750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman } 37512b49c500838666dd0186d021389d4dd70ffda240Evan Cheng } 3752750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman LHS = Tmp1; 3753750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman RHS = Tmp2; 3754750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman} 3755750ac1bdfa6f09bddfd9efce1d6360dde8fa74c0Nate Begeman 375635481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner/// ExpandBIT_CONVERT - Expand a BIT_CONVERT node into a store/load combination. 3757232348d66fcfe8f42f8b14cfacd2df3d00d2596eChris Lattner/// The resultant code need not be legal. Note that SrcOp is the input operand 3758232348d66fcfe8f42f8b14cfacd2df3d00d2596eChris Lattner/// to the BIT_CONVERT, not the BIT_CONVERT node itself. 375935481892da1e5634bf497c8a0cabb1bb5a8b8fefChris LattnerSDOperand SelectionDAGLegalize::ExpandBIT_CONVERT(MVT::ValueType DestVT, 376035481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner SDOperand SrcOp) { 376135481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner // Create the stack frame object. 3762ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner SDOperand FIPtr = CreateStackTemporary(DestVT); 376335481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner 376435481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner // Emit a store to the stack slot. 37658b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng SDOperand Store = DAG.getStore(DAG.getEntryNode(), SrcOp, FIPtr, NULL, 0); 376635481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner // Result is a load from the stack slot. 3767466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng return DAG.getLoad(DestVT, Store, FIPtr, NULL, 0); 376835481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner} 376935481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner 37704352cc9e217e4482ad53f5a7b92c3543f569eb6eChris LattnerSDOperand SelectionDAGLegalize::ExpandSCALAR_TO_VECTOR(SDNode *Node) { 37714352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner // Create a vector sized/aligned stack slot, store the value to element #0, 37724352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner // then load the whole vector back out. 37734352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner SDOperand StackPtr = CreateStackTemporary(Node->getValueType(0)); 3774786225adf09e606c795ef68a1f789c12f37869f2Evan Cheng SDOperand Ch = DAG.getStore(DAG.getEntryNode(), Node->getOperand(0), StackPtr, 37758b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng NULL, 0); 3776466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng return DAG.getLoad(Node->getValueType(0), Ch, StackPtr, NULL, 0); 37774352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner} 37784352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner 37794352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner 3780ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner/// ExpandBUILD_VECTOR - Expand a BUILD_VECTOR node on targets that don't 3781ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner/// support the operation, but do support the resultant packed vector type. 3782ce87215131efcc68dcf7fca61055ad783a7aeb0eChris LattnerSDOperand SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) { 3783ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner 3784ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner // If the only non-undef value is the low element, turn this into a 378587100e0b83b808757bf44dabecd1d1048255d1adChris Lattner // SCALAR_TO_VECTOR node. If this is { X, X, X, X }, determine X. 3786033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng unsigned NumElems = Node->getNumOperands(); 3787ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner bool isOnlyLowElement = true; 378887100e0b83b808757bf44dabecd1d1048255d1adChris Lattner SDOperand SplatValue = Node->getOperand(0); 3789033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng std::map<SDOperand, std::vector<unsigned> > Values; 3790033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng Values[SplatValue].push_back(0); 37912eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner bool isConstant = true; 37922eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner if (!isa<ConstantFPSDNode>(SplatValue) && !isa<ConstantSDNode>(SplatValue) && 37932eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner SplatValue.getOpcode() != ISD::UNDEF) 37942eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner isConstant = false; 37952eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner 3796033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng for (unsigned i = 1; i < NumElems; ++i) { 3797033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng SDOperand V = Node->getOperand(i); 379889a1b380a475cbe477e50ff4b94335596b37f21aChris Lattner Values[V].push_back(i); 3799033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng if (V.getOpcode() != ISD::UNDEF) 3800ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner isOnlyLowElement = false; 3801033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng if (SplatValue != V) 380287100e0b83b808757bf44dabecd1d1048255d1adChris Lattner SplatValue = SDOperand(0,0); 38032eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner 38042eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner // If this isn't a constant element or an undef, we can't use a constant 38052eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner // pool load. 38062eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V) && 38072eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner V.getOpcode() != ISD::UNDEF) 38082eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner isConstant = false; 3809ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner } 3810ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner 3811ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner if (isOnlyLowElement) { 3812ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner // If the low element is an undef too, then this whole things is an undef. 3813ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner if (Node->getOperand(0).getOpcode() == ISD::UNDEF) 3814ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner return DAG.getNode(ISD::UNDEF, Node->getValueType(0)); 3815ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner // Otherwise, turn this into a scalar_to_vector node. 3816ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner return DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), 3817ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner Node->getOperand(0)); 3818ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner } 3819ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner 38202eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner // If all elements are constants, create a load from the constant pool. 3821ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner if (isConstant) { 3822ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner MVT::ValueType VT = Node->getValueType(0); 3823ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner const Type *OpNTy = 3824ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner MVT::getTypeForValueType(Node->getOperand(0).getValueType()); 3825ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner std::vector<Constant*> CV; 3826033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng for (unsigned i = 0, e = NumElems; i != e; ++i) { 3827ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner if (ConstantFPSDNode *V = 3828ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner dyn_cast<ConstantFPSDNode>(Node->getOperand(i))) { 3829ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner CV.push_back(ConstantFP::get(OpNTy, V->getValue())); 3830ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner } else if (ConstantSDNode *V = 3831ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner dyn_cast<ConstantSDNode>(Node->getOperand(i))) { 3832b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer CV.push_back(ConstantInt::get(OpNTy, V->getValue())); 3833ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner } else { 3834ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner assert(Node->getOperand(i).getOpcode() == ISD::UNDEF); 3835ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner CV.push_back(UndefValue::get(OpNTy)); 3836ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner } 3837ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner } 3838ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner Constant *CP = ConstantPacked::get(CV); 3839ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner SDOperand CPIdx = DAG.getConstantPool(CP, TLI.getPointerTy()); 3840466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng return DAG.getLoad(VT, DAG.getEntryNode(), CPIdx, NULL, 0); 3841ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner } 38422eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner 38432eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner if (SplatValue.Val) { // Splat of one value? 38442eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner // Build the shuffle constant vector: <0, 0, 0, 0> 38452eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner MVT::ValueType MaskVT = 38462eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner MVT::getIntVectorWithNumElements(NumElems); 38472eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner SDOperand Zero = DAG.getConstant(0, MVT::getVectorBaseType(MaskVT)); 38482eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner std::vector<SDOperand> ZeroVec(NumElems, Zero); 3849bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner SDOperand SplatMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, 3850bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner &ZeroVec[0], ZeroVec.size()); 3851033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng 38522eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner // If the target supports VECTOR_SHUFFLE and this shuffle mask, use it. 38534352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner if (isShuffleLegal(Node->getValueType(0), SplatMask)) { 38542eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner // Get the splatted value into the low element of a vector register. 38552eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner SDOperand LowValVec = 38562eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), SplatValue); 38572eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner 38582eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner // Return shuffle(LowValVec, undef, <0,0,0,0>) 38592eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), LowValVec, 38602eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner DAG.getNode(ISD::UNDEF, Node->getValueType(0)), 38612eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner SplatMask); 38622eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner } 38632eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner } 38642eb8653157ccd318b357af74bfd517c76ef166b8Chris Lattner 3865033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng // If there are only two unique elements, we may be able to turn this into a 3866033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng // vector shuffle. 3867033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng if (Values.size() == 2) { 3868033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng // Build the shuffle constant vector: e.g. <0, 4, 0, 4> 3869033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng MVT::ValueType MaskVT = 3870033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng MVT::getIntVectorWithNumElements(NumElems); 3871033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng std::vector<SDOperand> MaskVec(NumElems); 3872033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng unsigned i = 0; 3873033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng for (std::map<SDOperand,std::vector<unsigned> >::iterator I=Values.begin(), 3874033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng E = Values.end(); I != E; ++I) { 3875033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng for (std::vector<unsigned>::iterator II = I->second.begin(), 3876033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng EE = I->second.end(); II != EE; ++II) 3877033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng MaskVec[*II] = DAG.getConstant(i, MVT::getVectorBaseType(MaskVT)); 3878033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng i += NumElems; 3879033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng } 3880bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner SDOperand ShuffleMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, 3881bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner &MaskVec[0], MaskVec.size()); 3882033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng 3883033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng // If the target supports VECTOR_SHUFFLE and this shuffle mask, use it. 38844352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner if (TLI.isOperationLegal(ISD::SCALAR_TO_VECTOR, Node->getValueType(0)) && 38854352cc9e217e4482ad53f5a7b92c3543f569eb6eChris Lattner isShuffleLegal(Node->getValueType(0), ShuffleMask)) { 3886bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner SmallVector<SDOperand, 8> Ops; 3887033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng for(std::map<SDOperand,std::vector<unsigned> >::iterator I=Values.begin(), 3888033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng E = Values.end(); I != E; ++I) { 3889033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng SDOperand Op = DAG.getNode(ISD::SCALAR_TO_VECTOR, Node->getValueType(0), 3890033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng I->first); 3891033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng Ops.push_back(Op); 3892033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng } 3893033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng Ops.push_back(ShuffleMask); 3894033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng 3895033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng // Return shuffle(LoValVec, HiValVec, <0,1,0,1>) 3896bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner return DAG.getNode(ISD::VECTOR_SHUFFLE, Node->getValueType(0), 3897bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner &Ops[0], Ops.size()); 3898033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng } 3899033e6816668da71ff0866a61f5c0a7e7e795d069Evan Cheng } 3900ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner 3901ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner // Otherwise, we can't handle this case efficiently. Allocate a sufficiently 3902ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner // aligned object on the stack, store each element into it, then load 3903ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner // the result as a vector. 3904ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner MVT::ValueType VT = Node->getValueType(0); 3905ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner // Create the stack frame object. 3906ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner SDOperand FIPtr = CreateStackTemporary(VT); 3907ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner 3908ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner // Emit a store of each element to the stack slot. 3909bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner SmallVector<SDOperand, 8> Stores; 3910ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner unsigned TypeByteSize = 3911ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner MVT::getSizeInBits(Node->getOperand(0).getValueType())/8; 3912ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner // Store (in the right endianness) the elements to memory. 3913ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { 3914ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner // Ignore undef elements. 3915ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner if (Node->getOperand(i).getOpcode() == ISD::UNDEF) continue; 3916ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner 3917841c882f5dae8c953ea99b5824108313549cfaf8Chris Lattner unsigned Offset = TypeByteSize*i; 3918ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner 3919ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner SDOperand Idx = DAG.getConstant(Offset, FIPtr.getValueType()); 3920ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner Idx = DAG.getNode(ISD::ADD, FIPtr.getValueType(), FIPtr, Idx); 3921ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner 3922786225adf09e606c795ef68a1f789c12f37869f2Evan Cheng Stores.push_back(DAG.getStore(DAG.getEntryNode(), Node->getOperand(i), Idx, 39238b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng NULL, 0)); 3924ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner } 3925ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner 3926ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner SDOperand StoreChain; 3927ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner if (!Stores.empty()) // Not all undef elements? 3928bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner StoreChain = DAG.getNode(ISD::TokenFactor, MVT::Other, 3929bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner &Stores[0], Stores.size()); 3930ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner else 3931ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner StoreChain = DAG.getEntryNode(); 3932ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner 3933ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner // Result is a load from the stack slot. 3934466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng return DAG.getLoad(VT, StoreChain, FIPtr, NULL, 0); 3935ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner} 3936ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner 3937ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner/// CreateStackTemporary - Create a stack temporary, suitable for holding the 3938ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner/// specified value type. 3939ce87215131efcc68dcf7fca61055ad783a7aeb0eChris LattnerSDOperand SelectionDAGLegalize::CreateStackTemporary(MVT::ValueType VT) { 3940ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner MachineFrameInfo *FrameInfo = DAG.getMachineFunction().getFrameInfo(); 3941ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner unsigned ByteSize = MVT::getSizeInBits(VT)/8; 394258092e35a3368e130438cbc793c8f9dce2e4fe0fChris Lattner const Type *Ty = MVT::getTypeForValueType(VT); 394358092e35a3368e130438cbc793c8f9dce2e4fe0fChris Lattner unsigned StackAlign = (unsigned)TLI.getTargetData()->getTypeAlignmentPref(Ty); 394458092e35a3368e130438cbc793c8f9dce2e4fe0fChris Lattner int FrameIdx = FrameInfo->CreateStackObject(ByteSize, StackAlign); 3945ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner return DAG.getFrameIndex(FrameIdx, TLI.getPointerTy()); 3946ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner} 3947ce87215131efcc68dcf7fca61055ad783a7aeb0eChris Lattner 39485b359c6c4f052e41579ad7da9af37db4f54207d9Chris Lattnervoid SelectionDAGLegalize::ExpandShiftParts(unsigned NodeOp, 39495b359c6c4f052e41579ad7da9af37db4f54207d9Chris Lattner SDOperand Op, SDOperand Amt, 39505b359c6c4f052e41579ad7da9af37db4f54207d9Chris Lattner SDOperand &Lo, SDOperand &Hi) { 39515b359c6c4f052e41579ad7da9af37db4f54207d9Chris Lattner // Expand the subcomponents. 39525b359c6c4f052e41579ad7da9af37db4f54207d9Chris Lattner SDOperand LHSL, LHSH; 39535b359c6c4f052e41579ad7da9af37db4f54207d9Chris Lattner ExpandOp(Op, LHSL, LHSH); 39545b359c6c4f052e41579ad7da9af37db4f54207d9Chris Lattner 3955bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner SDOperand Ops[] = { LHSL, LHSH, Amt }; 3956f9f37fc52c444e34bad7846729ae5481a65e0a53Chris Lattner MVT::ValueType VT = LHSL.getValueType(); 3957f9f37fc52c444e34bad7846729ae5481a65e0a53Chris Lattner Lo = DAG.getNode(NodeOp, DAG.getNodeValueTypes(VT, VT), 2, Ops, 3); 39585b359c6c4f052e41579ad7da9af37db4f54207d9Chris Lattner Hi = Lo.getValue(1); 39595b359c6c4f052e41579ad7da9af37db4f54207d9Chris Lattner} 39605b359c6c4f052e41579ad7da9af37db4f54207d9Chris Lattner 39615b359c6c4f052e41579ad7da9af37db4f54207d9Chris Lattner 3962e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner/// ExpandShift - Try to find a clever way to expand this shift operation out to 3963e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner/// smaller elements. If we can't find a way that is more efficient than a 3964e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner/// libcall on this target, return false. Otherwise, return true with the 3965e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner/// low-parts expanded into Lo and Hi. 3966e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattnerbool SelectionDAGLegalize::ExpandShift(unsigned Opc, SDOperand Op,SDOperand Amt, 3967e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner SDOperand &Lo, SDOperand &Hi) { 3968e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner assert((Opc == ISD::SHL || Opc == ISD::SRA || Opc == ISD::SRL) && 3969e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner "This is not a shift!"); 3970f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman 3971e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner MVT::ValueType NVT = TLI.getTypeToTransformTo(Op.getValueType()); 3972f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman SDOperand ShAmt = LegalizeOp(Amt); 3973f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman MVT::ValueType ShTy = ShAmt.getValueType(); 3974f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman unsigned VTBits = MVT::getSizeInBits(Op.getValueType()); 3975f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman unsigned NVTBits = MVT::getSizeInBits(NVT); 3976f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman 3977f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman // Handle the case when Amt is an immediate. Other cases are currently broken 3978f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman // and are disabled. 3979f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Amt.Val)) { 3980f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman unsigned Cst = CN->getValue(); 3981f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman // Expand the incoming operand to be shifted, so that we have its parts 3982f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman SDOperand InL, InH; 3983f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman ExpandOp(Op, InL, InH); 3984f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman switch(Opc) { 3985f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman case ISD::SHL: 3986f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman if (Cst > VTBits) { 3987f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman Lo = DAG.getConstant(0, NVT); 3988f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman Hi = DAG.getConstant(0, NVT); 3989f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman } else if (Cst > NVTBits) { 3990f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman Lo = DAG.getConstant(0, NVT); 3991f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman Hi = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst-NVTBits,ShTy)); 3992ee27f57a6a4dd7fa9259b3604f563907da1f65efChris Lattner } else if (Cst == NVTBits) { 3993ee27f57a6a4dd7fa9259b3604f563907da1f65efChris Lattner Lo = DAG.getConstant(0, NVT); 3994ee27f57a6a4dd7fa9259b3604f563907da1f65efChris Lattner Hi = InL; 3995f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman } else { 3996f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman Lo = DAG.getNode(ISD::SHL, NVT, InL, DAG.getConstant(Cst, ShTy)); 3997f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman Hi = DAG.getNode(ISD::OR, NVT, 3998f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(Cst, ShTy)), 3999f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(NVTBits-Cst, ShTy))); 4000f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman } 4001f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman return true; 4002f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman case ISD::SRL: 4003f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman if (Cst > VTBits) { 4004f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman Lo = DAG.getConstant(0, NVT); 4005f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman Hi = DAG.getConstant(0, NVT); 4006f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman } else if (Cst > NVTBits) { 4007f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman Lo = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst-NVTBits,ShTy)); 4008f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman Hi = DAG.getConstant(0, NVT); 4009ee27f57a6a4dd7fa9259b3604f563907da1f65efChris Lattner } else if (Cst == NVTBits) { 4010ee27f57a6a4dd7fa9259b3604f563907da1f65efChris Lattner Lo = InH; 4011ee27f57a6a4dd7fa9259b3604f563907da1f65efChris Lattner Hi = DAG.getConstant(0, NVT); 4012f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman } else { 4013f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman Lo = DAG.getNode(ISD::OR, NVT, 4014f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), 4015f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); 4016f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman Hi = DAG.getNode(ISD::SRL, NVT, InH, DAG.getConstant(Cst, ShTy)); 4017f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman } 4018f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman return true; 4019f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman case ISD::SRA: 4020f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman if (Cst > VTBits) { 4021edf128a7fa90f2b0b7ee24741a04a7ae1ecd6f7eMisha Brukman Hi = Lo = DAG.getNode(ISD::SRA, NVT, InH, 4022f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman DAG.getConstant(NVTBits-1, ShTy)); 4023f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman } else if (Cst > NVTBits) { 4024edf128a7fa90f2b0b7ee24741a04a7ae1ecd6f7eMisha Brukman Lo = DAG.getNode(ISD::SRA, NVT, InH, 4025f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman DAG.getConstant(Cst-NVTBits, ShTy)); 4026edf128a7fa90f2b0b7ee24741a04a7ae1ecd6f7eMisha Brukman Hi = DAG.getNode(ISD::SRA, NVT, InH, 4027f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman DAG.getConstant(NVTBits-1, ShTy)); 4028ee27f57a6a4dd7fa9259b3604f563907da1f65efChris Lattner } else if (Cst == NVTBits) { 4029ee27f57a6a4dd7fa9259b3604f563907da1f65efChris Lattner Lo = InH; 4030edf128a7fa90f2b0b7ee24741a04a7ae1ecd6f7eMisha Brukman Hi = DAG.getNode(ISD::SRA, NVT, InH, 4031ee27f57a6a4dd7fa9259b3604f563907da1f65efChris Lattner DAG.getConstant(NVTBits-1, ShTy)); 4032f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman } else { 4033f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman Lo = DAG.getNode(ISD::OR, NVT, 4034f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman DAG.getNode(ISD::SRL, NVT, InL, DAG.getConstant(Cst, ShTy)), 4035f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman DAG.getNode(ISD::SHL, NVT, InH, DAG.getConstant(NVTBits-Cst, ShTy))); 4036f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman Hi = DAG.getNode(ISD::SRA, NVT, InH, DAG.getConstant(Cst, ShTy)); 4037f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman } 4038f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman return true; 4039f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman } 4040f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman } 40410ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner 40420ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner // Okay, the shift amount isn't constant. However, if we can tell that it is 40430ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner // >= 32 or < 32, we can still simplify it, without knowing the actual value. 40440ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner uint64_t Mask = NVTBits, KnownZero, KnownOne; 40450ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner TLI.ComputeMaskedBits(Amt, Mask, KnownZero, KnownOne); 40460ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner 40470ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner // If we know that the high bit of the shift amount is one, then we can do 40480ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner // this as a couple of simple shifts. 40490ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner if (KnownOne & Mask) { 40500ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner // Mask out the high bit, which we know is set. 40510ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner Amt = DAG.getNode(ISD::AND, Amt.getValueType(), Amt, 40520ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner DAG.getConstant(NVTBits-1, Amt.getValueType())); 40530ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner 40540ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner // Expand the incoming operand to be shifted, so that we have its parts 40550ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner SDOperand InL, InH; 40560ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner ExpandOp(Op, InL, InH); 40570ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner switch(Opc) { 40580ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner case ISD::SHL: 40590ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner Lo = DAG.getConstant(0, NVT); // Low part is zero. 40600ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner Hi = DAG.getNode(ISD::SHL, NVT, InL, Amt); // High part from Lo part. 40610ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner return true; 40620ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner case ISD::SRL: 40630ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner Hi = DAG.getConstant(0, NVT); // Hi part is zero. 40640ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner Lo = DAG.getNode(ISD::SRL, NVT, InH, Amt); // Lo part from Hi part. 40650ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner return true; 40660ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner case ISD::SRA: 40670ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner Hi = DAG.getNode(ISD::SRA, NVT, InH, // Sign extend high part. 40680ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner DAG.getConstant(NVTBits-1, Amt.getValueType())); 40690ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner Lo = DAG.getNode(ISD::SRA, NVT, InH, Amt); // Lo part from Hi part. 40700ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner return true; 40710ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner } 40720ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner } 40730ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner 40740ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner // If we know that the high bit of the shift amount is zero, then we can do 40750ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner // this as a couple of simple shifts. 40760ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner if (KnownZero & Mask) { 40770ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner // Compute 32-amt. 40780ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner SDOperand Amt2 = DAG.getNode(ISD::SUB, Amt.getValueType(), 40790ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner DAG.getConstant(NVTBits, Amt.getValueType()), 40800ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner Amt); 40810ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner 40820ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner // Expand the incoming operand to be shifted, so that we have its parts 40830ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner SDOperand InL, InH; 40840ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner ExpandOp(Op, InL, InH); 40850ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner switch(Opc) { 40860ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner case ISD::SHL: 40870ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner Lo = DAG.getNode(ISD::SHL, NVT, InL, Amt); 40880ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner Hi = DAG.getNode(ISD::OR, NVT, 40890ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner DAG.getNode(ISD::SHL, NVT, InH, Amt), 40900ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner DAG.getNode(ISD::SRL, NVT, InL, Amt2)); 40910ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner return true; 40920ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner case ISD::SRL: 40930ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner Hi = DAG.getNode(ISD::SRL, NVT, InH, Amt); 40940ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner Lo = DAG.getNode(ISD::OR, NVT, 40950ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner DAG.getNode(ISD::SRL, NVT, InL, Amt), 40960ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner DAG.getNode(ISD::SHL, NVT, InH, Amt2)); 40970ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner return true; 40980ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner case ISD::SRA: 40990ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner Hi = DAG.getNode(ISD::SRA, NVT, InH, Amt); 41000ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner Lo = DAG.getNode(ISD::OR, NVT, 41010ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner DAG.getNode(ISD::SRL, NVT, InL, Amt), 41020ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner DAG.getNode(ISD::SHL, NVT, InH, Amt2)); 41030ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner return true; 41040ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner } 41050ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner } 41060ea26ca45b56b2b4cc1839cdbccc13a38b066969Chris Lattner 4107f1fe32e337cf825a27a57bb3e9fb847bc91a26ceNate Begeman return false; 4108e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner} 410977e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner 41109c32d3b798dc6caeebe6cea2effe80ca5e84e66eChris Lattner 411177e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner// ExpandLibCall - Expand a node into a call to a libcall. If the result value 411277e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner// does not fit into a register, return the lo part and set the hi part to the 411377e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner// by-reg argument. If it does fit into a single register, return the result 411477e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner// and leave the Hi part unset. 411577e77a6aa0ab25a812947aed477220dd11220a18Chris LattnerSDOperand SelectionDAGLegalize::ExpandLibCall(const char *Name, SDNode *Node, 411647857812e29324a9d1560796a05b53d3a9217fd9Reid Spencer bool isSigned, SDOperand &Hi) { 41176831a815999dde4cf801e2076e66b4943964daf2Chris Lattner assert(!IsLegalizingCall && "Cannot overlap legalization of calls!"); 41186831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // The input chain to this libcall is the entry node of the function. 41196831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Legalizing the call will automatically add the previous call to the 41206831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // dependence. 41216831a815999dde4cf801e2076e66b4943964daf2Chris Lattner SDOperand InChain = DAG.getEntryNode(); 41226831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 412377e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner TargetLowering::ArgListTy Args; 412447857812e29324a9d1560796a05b53d3a9217fd9Reid Spencer TargetLowering::ArgListEntry Entry; 412577e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) { 412677e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner MVT::ValueType ArgVT = Node->getOperand(i).getValueType(); 412777e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner const Type *ArgTy = MVT::getTypeForValueType(ArgVT); 412847857812e29324a9d1560796a05b53d3a9217fd9Reid Spencer Entry.Node = Node->getOperand(i); Entry.Ty = ArgTy; 4129b10308e440c80dd6ffb4b478f741ff7e5f30cb48Anton Korobeynikov Entry.isSigned = isSigned; Entry.isInReg = false; 413047857812e29324a9d1560796a05b53d3a9217fd9Reid Spencer Args.push_back(Entry); 413177e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner } 413277e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner SDOperand Callee = DAG.getExternalSymbol(Name, TLI.getPointerTy()); 4133edf128a7fa90f2b0b7ee24741a04a7ae1ecd6f7eMisha Brukman 41340d67f0c80f0295aa44f826ec1402ea73d6b4bd22Chris Lattner // Splice the libcall in wherever FindInputOutputChains tells us to. 413577e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner const Type *RetTy = MVT::getTypeForValueType(Node->getValueType(0)); 41360d67f0c80f0295aa44f826ec1402ea73d6b4bd22Chris Lattner std::pair<SDOperand,SDOperand> CallInfo = 413747857812e29324a9d1560796a05b53d3a9217fd9Reid Spencer TLI.LowerCallTo(InChain, RetTy, isSigned, false, CallingConv::C, false, 4138adf6a965a321372c640845407195594835921eb4Chris Lattner Callee, Args, DAG); 41390d67f0c80f0295aa44f826ec1402ea73d6b4bd22Chris Lattner 41406831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // Legalize the call sequence, starting with the chain. This will advance 41416831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // the LastCALLSEQ_END to the legalized version of the CALLSEQ_END node that 41426831a815999dde4cf801e2076e66b4943964daf2Chris Lattner // was added by LowerCallTo (guaranteeing proper serialization of calls). 41436831a815999dde4cf801e2076e66b4943964daf2Chris Lattner LegalizeOp(CallInfo.second); 414499c25b86aa85b0093f24b2394a5aa37f66294b2bChris Lattner SDOperand Result; 41450d67f0c80f0295aa44f826ec1402ea73d6b4bd22Chris Lattner switch (getTypeAction(CallInfo.first.getValueType())) { 414677e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner default: assert(0 && "Unknown thing"); 414777e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner case Legal: 4148456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Result = CallInfo.first; 414999c25b86aa85b0093f24b2394a5aa37f66294b2bChris Lattner break; 415077e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner case Expand: 415199c25b86aa85b0093f24b2394a5aa37f66294b2bChris Lattner ExpandOp(CallInfo.first, Result, Hi); 415299c25b86aa85b0093f24b2394a5aa37f66294b2bChris Lattner break; 415377e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner } 415422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner return Result; 415522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner} 415622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 415722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 415822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner/// ExpandIntToFP - Expand a [US]INT_TO_FP operation, assuming that the 415922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner/// destination type is legal. 416022cde6a518782cafc2115ad8d8233f79c9e9d52eChris LattnerSDOperand SelectionDAGLegalize:: 416122cde6a518782cafc2115ad8d8233f79c9e9d52eChris LattnerExpandIntToFP(bool isSigned, MVT::ValueType DestTy, SDOperand Source) { 416222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner assert(isTypeLegal(DestTy) && "Destination type is not legal!"); 416322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner assert(getTypeAction(Source.getValueType()) == Expand && 416422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner "This is not an expansion!"); 416522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner assert(Source.getValueType() == MVT::i64 && "Only handle expand from i64!"); 416622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 416722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner if (!isSigned) { 416822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner assert(Source.getValueType() == MVT::i64 && 416922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner "This only works for 64-bit -> FP"); 417022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // The 64-bit value loaded will be incorrectly if the 'sign bit' of the 417122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // incoming integer is set. To handle this, we dynamically test to see if 417222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // it is set, and, if so, add a fudge factor. 417322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand Lo, Hi; 417422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner ExpandOp(Source, Lo, Hi); 417522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 417622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // If this is unsigned, and not supported, first perform the conversion to 417722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // signed, then adjust the result if the sign bit is set. 417822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand SignedConv = ExpandIntToFP(true, DestTy, 417922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner DAG.getNode(ISD::BUILD_PAIR, Source.getValueType(), Lo, Hi)); 418022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 418122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand SignSet = DAG.getSetCC(TLI.getSetCCResultTy(), Hi, 418222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner DAG.getConstant(0, Hi.getValueType()), 418322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner ISD::SETLT); 418422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand Zero = getIntPtrConstant(0), Four = getIntPtrConstant(4); 418522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), 418622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SignSet, Four, Zero); 418722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner uint64_t FF = 0x5f800000ULL; 418822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner if (TLI.isLittleEndian()) FF <<= 32; 418947857812e29324a9d1560796a05b53d3a9217fd9Reid Spencer static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); 419022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 419122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); 419222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); 419322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand FudgeInReg; 419422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner if (DestTy == MVT::f32) 4195466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, NULL, 0); 419622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner else { 419722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner assert(DestTy == MVT::f64 && "Unexpected conversion"); 419822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner FudgeInReg = DAG.getExtLoad(ISD::EXTLOAD, MVT::f64, DAG.getEntryNode(), 4199466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng CPIdx, NULL, 0, MVT::f32); 420022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } 420122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner return DAG.getNode(ISD::FADD, DestTy, SignedConv, FudgeInReg); 420222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } 420322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 420422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // Check to see if the target has a custom way to lower this. If so, use it. 420522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner switch (TLI.getOperationAction(ISD::SINT_TO_FP, Source.getValueType())) { 420622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner default: assert(0 && "This action not implemented for this operation!"); 420722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner case TargetLowering::Legal: 420822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner case TargetLowering::Expand: 420922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner break; // This case is handled below. 421022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner case TargetLowering::Custom: { 421122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand NV = TLI.LowerOperation(DAG.getNode(ISD::SINT_TO_FP, DestTy, 421222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Source), DAG); 421322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner if (NV.Val) 421422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner return LegalizeOp(NV); 421522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner break; // The target decided this was legal after all 421622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } 421722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } 421822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 421922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // Expand the source, then glue it back together for the call. We must expand 422022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // the source in case it is shared (this pass of legalize must traverse it). 422122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand SrcLo, SrcHi; 422222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner ExpandOp(Source, SrcLo, SrcHi); 422322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Source = DAG.getNode(ISD::BUILD_PAIR, Source.getValueType(), SrcLo, SrcHi); 422422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 422556966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng RTLIB::Libcall LC; 422622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner if (DestTy == MVT::f32) 422756966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC = RTLIB::SINTTOFP_I64_F32; 422822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner else { 422922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner assert(DestTy == MVT::f64 && "Unknown fp value type!"); 423056966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC = RTLIB::SINTTOFP_I64_F64; 423122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } 42326831a815999dde4cf801e2076e66b4943964daf2Chris Lattner 42336831a815999dde4cf801e2076e66b4943964daf2Chris Lattner Source = DAG.getNode(ISD::SINT_TO_FP, DestTy, Source); 42346831a815999dde4cf801e2076e66b4943964daf2Chris Lattner SDOperand UnusedHiPart; 423556966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng return ExpandLibCall(TLI.getLibcallName(LC), Source.Val, isSigned, 423656966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng UnusedHiPart); 423722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner} 423822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 423922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner/// ExpandLegalINT_TO_FP - This function is responsible for legalizing a 424022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner/// INT_TO_FP operation of the specified operand when the target requests that 424122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner/// we expand it. At this point, we know that the result and operand types are 424222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner/// legal for the target. 424322cde6a518782cafc2115ad8d8233f79c9e9d52eChris LattnerSDOperand SelectionDAGLegalize::ExpandLegalINT_TO_FP(bool isSigned, 424422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand Op0, 424522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner MVT::ValueType DestVT) { 424622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner if (Op0.getValueType() == MVT::i32) { 424722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // simple 32-bit [signed|unsigned] integer to float/double expansion 424822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 424958092e35a3368e130438cbc793c8f9dce2e4fe0fChris Lattner // get the stack frame index of a 8 byte buffer, pessimistically aligned 425022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner MachineFunction &MF = DAG.getMachineFunction(); 425158092e35a3368e130438cbc793c8f9dce2e4fe0fChris Lattner const Type *F64Type = MVT::getTypeForValueType(MVT::f64); 425258092e35a3368e130438cbc793c8f9dce2e4fe0fChris Lattner unsigned StackAlign = 425358092e35a3368e130438cbc793c8f9dce2e4fe0fChris Lattner (unsigned)TLI.getTargetData()->getTypeAlignmentPref(F64Type); 425458092e35a3368e130438cbc793c8f9dce2e4fe0fChris Lattner int SSFI = MF.getFrameInfo()->CreateStackObject(8, StackAlign); 425522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // get address of 8 byte buffer 425622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand StackSlot = DAG.getFrameIndex(SSFI, TLI.getPointerTy()); 425722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // word offset constant for Hi/Lo address computation 425822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand WordOff = DAG.getConstant(sizeof(int), TLI.getPointerTy()); 425922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // set up Hi and Lo (into buffer) address based on endian 4260408c428096df3a3970a8387f9dd258ae948663a6Chris Lattner SDOperand Hi = StackSlot; 4261408c428096df3a3970a8387f9dd258ae948663a6Chris Lattner SDOperand Lo = DAG.getNode(ISD::ADD, TLI.getPointerTy(), StackSlot,WordOff); 4262408c428096df3a3970a8387f9dd258ae948663a6Chris Lattner if (TLI.isLittleEndian()) 4263408c428096df3a3970a8387f9dd258ae948663a6Chris Lattner std::swap(Hi, Lo); 4264408c428096df3a3970a8387f9dd258ae948663a6Chris Lattner 426522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // if signed map to unsigned space 426622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand Op0Mapped; 426722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner if (isSigned) { 426822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // constant used to invert sign bit (signed to unsigned mapping) 426922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand SignBit = DAG.getConstant(0x80000000u, MVT::i32); 427022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Op0Mapped = DAG.getNode(ISD::XOR, MVT::i32, Op0, SignBit); 427122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } else { 427222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Op0Mapped = Op0; 427322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } 427422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // store the lo of the constructed double - based on integer input 4275786225adf09e606c795ef68a1f789c12f37869f2Evan Cheng SDOperand Store1 = DAG.getStore(DAG.getEntryNode(), 42768b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Op0Mapped, Lo, NULL, 0); 427722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // initial hi portion of constructed double 427822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand InitialHi = DAG.getConstant(0x43300000u, MVT::i32); 427922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // store the hi of the constructed double - biased exponent 42808b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng SDOperand Store2=DAG.getStore(Store1, InitialHi, Hi, NULL, 0); 428122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // load the constructed double 4282466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng SDOperand Load = DAG.getLoad(MVT::f64, Store2, StackSlot, NULL, 0); 428322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // FP constant to bias correct the final result 428422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand Bias = DAG.getConstantFP(isSigned ? 428522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner BitsToDouble(0x4330000080000000ULL) 428622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner : BitsToDouble(0x4330000000000000ULL), 428722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner MVT::f64); 428822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // subtract the bias 428922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand Sub = DAG.getNode(ISD::FSUB, MVT::f64, Load, Bias); 429022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // final result 429122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand Result; 429222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // handle final rounding 429322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner if (DestVT == MVT::f64) { 429422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // do nothing 429522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Result = Sub; 429622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } else { 429722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // if f32 then cast to f32 429822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Result = DAG.getNode(ISD::FP_ROUND, MVT::f32, Sub); 429922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } 430022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner return Result; 430122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } 430222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner assert(!isSigned && "Legalize cannot Expand SINT_TO_FP for i64 yet"); 430322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand Tmp1 = DAG.getNode(ISD::SINT_TO_FP, DestVT, Op0); 430422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 430522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand SignSet = DAG.getSetCC(TLI.getSetCCResultTy(), Op0, 430622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner DAG.getConstant(0, Op0.getValueType()), 430722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner ISD::SETLT); 430822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand Zero = getIntPtrConstant(0), Four = getIntPtrConstant(4); 430922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(), 431022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SignSet, Four, Zero); 431122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 431222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // If the sign bit of the integer is set, the large number will be treated 431322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // as a negative number. To counteract this, the dynamic code adds an 431422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // offset depending on the data type. 431522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner uint64_t FF; 431622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner switch (Op0.getValueType()) { 431722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner default: assert(0 && "Unsupported integer type!"); 431822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner case MVT::i8 : FF = 0x43800000ULL; break; // 2^8 (as a float) 431922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner case MVT::i16: FF = 0x47800000ULL; break; // 2^16 (as a float) 432022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner case MVT::i32: FF = 0x4F800000ULL; break; // 2^32 (as a float) 432122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner case MVT::i64: FF = 0x5F800000ULL; break; // 2^64 (as a float) 432222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } 432322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner if (TLI.isLittleEndian()) FF <<= 32; 432447857812e29324a9d1560796a05b53d3a9217fd9Reid Spencer static Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); 432522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 432622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); 432722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset); 432822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand FudgeInReg; 432922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner if (DestVT == MVT::f32) 4330466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, NULL, 0); 433122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner else { 433222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner assert(DestVT == MVT::f64 && "Unexpected conversion"); 433322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner FudgeInReg = LegalizeOp(DAG.getExtLoad(ISD::EXTLOAD, MVT::f64, 433422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner DAG.getEntryNode(), CPIdx, 4335466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng NULL, 0, MVT::f32)); 433622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } 433722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 433822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner return DAG.getNode(ISD::FADD, DestVT, Tmp1, FudgeInReg); 433922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner} 434022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 434122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner/// PromoteLegalINT_TO_FP - This function is responsible for legalizing a 434222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner/// *INT_TO_FP operation of the specified operand when the target requests that 434322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner/// we promote it. At this point, we know that the result and operand types are 434422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner/// legal for the target, and that there is a legal UINT_TO_FP or SINT_TO_FP 434522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner/// operation that takes a larger input. 434622cde6a518782cafc2115ad8d8233f79c9e9d52eChris LattnerSDOperand SelectionDAGLegalize::PromoteLegalINT_TO_FP(SDOperand LegalOp, 434722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner MVT::ValueType DestVT, 434822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner bool isSigned) { 434922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // First step, figure out the appropriate *INT_TO_FP operation to use. 435022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner MVT::ValueType NewInTy = LegalOp.getValueType(); 435122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 435222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner unsigned OpToUse = 0; 435322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 435422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // Scan for the appropriate larger type to use. 435522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner while (1) { 435622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner NewInTy = (MVT::ValueType)(NewInTy+1); 435722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner assert(MVT::isInteger(NewInTy) && "Ran out of possibilities!"); 435822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 435922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // If the target supports SINT_TO_FP of this type, use it. 436022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner switch (TLI.getOperationAction(ISD::SINT_TO_FP, NewInTy)) { 436122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner default: break; 436222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner case TargetLowering::Legal: 436322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner if (!TLI.isTypeLegal(NewInTy)) 436422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner break; // Can't use this datatype. 436522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // FALL THROUGH. 436622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner case TargetLowering::Custom: 436722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner OpToUse = ISD::SINT_TO_FP; 436822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner break; 436922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } 437022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner if (OpToUse) break; 437122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner if (isSigned) continue; 437222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 437322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // If the target supports UINT_TO_FP of this type, use it. 437422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner switch (TLI.getOperationAction(ISD::UINT_TO_FP, NewInTy)) { 437522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner default: break; 437622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner case TargetLowering::Legal: 437722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner if (!TLI.isTypeLegal(NewInTy)) 437822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner break; // Can't use this datatype. 437922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // FALL THROUGH. 438022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner case TargetLowering::Custom: 438122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner OpToUse = ISD::UINT_TO_FP; 438222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner break; 438322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } 438422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner if (OpToUse) break; 438522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 438622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // Otherwise, try a larger type. 438722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } 438822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 438922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // Okay, we found the operation and type to use. Zero extend our input to the 439022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // desired type then run the operation on it. 439122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner return DAG.getNode(OpToUse, DestVT, 439222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner DAG.getNode(isSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, 439322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner NewInTy, LegalOp)); 439477e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner} 439577e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner 439622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner/// PromoteLegalFP_TO_INT - This function is responsible for legalizing a 439722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner/// FP_TO_*INT operation of the specified operand when the target requests that 439822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner/// we promote it. At this point, we know that the result and operand types are 439922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner/// legal for the target, and that there is a legal FP_TO_UINT or FP_TO_SINT 440022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner/// operation that returns a larger result. 440122cde6a518782cafc2115ad8d8233f79c9e9d52eChris LattnerSDOperand SelectionDAGLegalize::PromoteLegalFP_TO_INT(SDOperand LegalOp, 440222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner MVT::ValueType DestVT, 440322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner bool isSigned) { 440422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // First step, figure out the appropriate FP_TO*INT operation to use. 440522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner MVT::ValueType NewOutTy = DestVT; 44069c32d3b798dc6caeebe6cea2effe80ca5e84e66eChris Lattner 440722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner unsigned OpToUse = 0; 4408e9c35e7309a8293852ba71d874fa4dc99e07e6feChris Lattner 440922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // Scan for the appropriate larger type to use. 441022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner while (1) { 441122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner NewOutTy = (MVT::ValueType)(NewOutTy+1); 441222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner assert(MVT::isInteger(NewOutTy) && "Ran out of possibilities!"); 441366de05b606cf31f1f23ed0c4eb1f097738cd1506Chris Lattner 441422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // If the target supports FP_TO_SINT returning this type, use it. 441522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner switch (TLI.getOperationAction(ISD::FP_TO_SINT, NewOutTy)) { 441622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner default: break; 441722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner case TargetLowering::Legal: 441822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner if (!TLI.isTypeLegal(NewOutTy)) 441922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner break; // Can't use this datatype. 442022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // FALL THROUGH. 442122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner case TargetLowering::Custom: 442222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner OpToUse = ISD::FP_TO_SINT; 442322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner break; 442422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } 442522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner if (OpToUse) break; 4426e9c35e7309a8293852ba71d874fa4dc99e07e6feChris Lattner 442722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // If the target supports FP_TO_UINT of this type, use it. 442822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner switch (TLI.getOperationAction(ISD::FP_TO_UINT, NewOutTy)) { 442922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner default: break; 443022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner case TargetLowering::Legal: 443122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner if (!TLI.isTypeLegal(NewOutTy)) 443222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner break; // Can't use this datatype. 443322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // FALL THROUGH. 443422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner case TargetLowering::Custom: 443522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner OpToUse = ISD::FP_TO_UINT; 443622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner break; 4437e9c35e7309a8293852ba71d874fa4dc99e07e6feChris Lattner } 443822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner if (OpToUse) break; 44390d67f0c80f0295aa44f826ec1402ea73d6b4bd22Chris Lattner 444022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // Otherwise, try a larger type. 4441a88a260dbd874a3bdd3e47f4f15ab0d7c7803044Chris Lattner } 4442a88a260dbd874a3bdd3e47f4f15ab0d7c7803044Chris Lattner 444322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // Okay, we found the operation and type to use. Truncate the result of the 444422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // extended FP_TO_*INT operation to the desired size. 444522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner return DAG.getNode(ISD::TRUNCATE, DestVT, 444622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner DAG.getNode(OpToUse, NewOutTy, LegalOp)); 444722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner} 444813689e2009e71f7982d1313ed699e0e6a50157d0Chris Lattner 444922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner/// ExpandBSWAP - Open code the operations for BSWAP of the specified operation. 445022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner/// 445122cde6a518782cafc2115ad8d8233f79c9e9d52eChris LattnerSDOperand SelectionDAGLegalize::ExpandBSWAP(SDOperand Op) { 445222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner MVT::ValueType VT = Op.getValueType(); 445322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner MVT::ValueType SHVT = TLI.getShiftAmountTy(); 445422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand Tmp1, Tmp2, Tmp3, Tmp4, Tmp5, Tmp6, Tmp7, Tmp8; 445522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner switch (VT) { 445622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner default: assert(0 && "Unhandled Expand type in BSWAP!"); abort(); 445722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner case MVT::i16: 445822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp2 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); 445922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); 446022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner return DAG.getNode(ISD::OR, VT, Tmp1, Tmp2); 446122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner case MVT::i32: 446222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp4 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT)); 446322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp3 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); 446422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); 446522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT)); 446622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(0xFF0000, VT)); 446722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(0xFF00, VT)); 446822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3); 446922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1); 447022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner return DAG.getNode(ISD::OR, VT, Tmp4, Tmp2); 447122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner case MVT::i64: 447222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp8 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(56, SHVT)); 447322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp7 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(40, SHVT)); 447422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp6 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(24, SHVT)); 447522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp5 = DAG.getNode(ISD::SHL, VT, Op, DAG.getConstant(8, SHVT)); 447622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp4 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(8, SHVT)); 447722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp3 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(24, SHVT)); 447822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp2 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(40, SHVT)); 447922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp1 = DAG.getNode(ISD::SRL, VT, Op, DAG.getConstant(56, SHVT)); 448022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp7 = DAG.getNode(ISD::AND, VT, Tmp7, DAG.getConstant(255ULL<<48, VT)); 448122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp6 = DAG.getNode(ISD::AND, VT, Tmp6, DAG.getConstant(255ULL<<40, VT)); 448222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp5 = DAG.getNode(ISD::AND, VT, Tmp5, DAG.getConstant(255ULL<<32, VT)); 448322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp4 = DAG.getNode(ISD::AND, VT, Tmp4, DAG.getConstant(255ULL<<24, VT)); 448422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp3 = DAG.getNode(ISD::AND, VT, Tmp3, DAG.getConstant(255ULL<<16, VT)); 448522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp2 = DAG.getNode(ISD::AND, VT, Tmp2, DAG.getConstant(255ULL<<8 , VT)); 448622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp7); 448722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp6 = DAG.getNode(ISD::OR, VT, Tmp6, Tmp5); 448822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp3); 448922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp2 = DAG.getNode(ISD::OR, VT, Tmp2, Tmp1); 449022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp8 = DAG.getNode(ISD::OR, VT, Tmp8, Tmp6); 449122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Tmp4 = DAG.getNode(ISD::OR, VT, Tmp4, Tmp2); 449222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner return DAG.getNode(ISD::OR, VT, Tmp8, Tmp4); 44930d67f0c80f0295aa44f826ec1402ea73d6b4bd22Chris Lattner } 449477e77a6aa0ab25a812947aed477220dd11220a18Chris Lattner} 4495edf128a7fa90f2b0b7ee24741a04a7ae1ecd6f7eMisha Brukman 449622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner/// ExpandBitCount - Expand the specified bitcount instruction into operations. 449722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner/// 449822cde6a518782cafc2115ad8d8233f79c9e9d52eChris LattnerSDOperand SelectionDAGLegalize::ExpandBitCount(unsigned Opc, SDOperand Op) { 449922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner switch (Opc) { 450022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner default: assert(0 && "Cannot expand this yet!"); 450122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner case ISD::CTPOP: { 450222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner static const uint64_t mask[6] = { 450322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 0x5555555555555555ULL, 0x3333333333333333ULL, 450422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 0x0F0F0F0F0F0F0F0FULL, 0x00FF00FF00FF00FFULL, 450522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner 0x0000FFFF0000FFFFULL, 0x00000000FFFFFFFFULL 450622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner }; 450722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner MVT::ValueType VT = Op.getValueType(); 450822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner MVT::ValueType ShVT = TLI.getShiftAmountTy(); 450922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner unsigned len = getSizeInBits(VT); 451022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { 451122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner //x = (x & mask[i][len/8]) + (x >> (1 << i) & mask[i][len/8]) 451222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand Tmp2 = DAG.getConstant(mask[i], VT); 451322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand Tmp3 = DAG.getConstant(1ULL << i, ShVT); 451422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Op = DAG.getNode(ISD::ADD, VT, DAG.getNode(ISD::AND, VT, Op, Tmp2), 451522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner DAG.getNode(ISD::AND, VT, 451622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner DAG.getNode(ISD::SRL, VT, Op, Tmp3),Tmp2)); 451722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } 451822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner return Op; 451922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } 452022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner case ISD::CTLZ: { 452122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // for now, we do this: 452222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // x = x | (x >> 1); 452322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // x = x | (x >> 2); 452422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // ... 452522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // x = x | (x >>16); 452622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // x = x | (x >>32); // for 64-bit input 452722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // return popcount(~x); 452822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // 452922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // but see also: http://www.hackersdelight.org/HDcode/nlz.cc 453022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner MVT::ValueType VT = Op.getValueType(); 453122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner MVT::ValueType ShVT = TLI.getShiftAmountTy(); 453222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner unsigned len = getSizeInBits(VT); 453322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner for (unsigned i = 0; (1U << i) <= (len / 2); ++i) { 453422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand Tmp3 = DAG.getConstant(1ULL << i, ShVT); 453522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Op = DAG.getNode(ISD::OR, VT, Op, DAG.getNode(ISD::SRL, VT, Op, Tmp3)); 453622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } 453722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner Op = DAG.getNode(ISD::XOR, VT, Op, DAG.getConstant(~0ULL, VT)); 453822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner return DAG.getNode(ISD::CTPOP, VT, Op); 453922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } 454022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner case ISD::CTTZ: { 454122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // for now, we use: { return popcount(~x & (x - 1)); } 454222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // unless the target has ctlz but not ctpop, in which case we use: 454322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // { return 32 - nlz(~x & (x-1)); } 454422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // see also http://www.hackersdelight.org/HDcode/ntz.cc 454522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner MVT::ValueType VT = Op.getValueType(); 454622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand Tmp2 = DAG.getConstant(~0ULL, VT); 454722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner SDOperand Tmp3 = DAG.getNode(ISD::AND, VT, 454822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner DAG.getNode(ISD::XOR, VT, Op, Tmp2), 454922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner DAG.getNode(ISD::SUB, VT, Op, DAG.getConstant(1, VT))); 455022cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner // If ISD::CTLZ is legal and CTPOP isn't, then do that instead. 455122cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner if (!TLI.isOperationLegal(ISD::CTPOP, VT) && 455222cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner TLI.isOperationLegal(ISD::CTLZ, VT)) 455322cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner return DAG.getNode(ISD::SUB, VT, 455422cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner DAG.getConstant(getSizeInBits(VT), VT), 455522cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner DAG.getNode(ISD::CTLZ, VT, Tmp3)); 455622cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner return DAG.getNode(ISD::CTPOP, VT, Tmp3); 455722cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } 455822cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner } 455922cde6a518782cafc2115ad8d8233f79c9e9d52eChris Lattner} 4560e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner 45613e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner/// ExpandOp - Expand the specified SDOperand into its two component pieces 45623e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner/// Lo&Hi. Note that the Op MUST be an expanded type. As a result of this, the 45633e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner/// LegalizeNodes map is filled in for any results that are not expanded, the 45643e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner/// ExpandedNodes map is filled in for any results that are expanded, and the 45653e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner/// Lo/Hi values are returned. 45663e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattnervoid SelectionDAGLegalize::ExpandOp(SDOperand Op, SDOperand &Lo, SDOperand &Hi){ 45673e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner MVT::ValueType VT = Op.getValueType(); 456871c42a0190300a8903aaea80467b88f15f327ea9Chris Lattner MVT::ValueType NVT = TLI.getTypeToTransformTo(VT); 45693e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner SDNode *Node = Op.Val; 45703e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner assert(getTypeAction(VT) == Expand && "Not an expanded type!"); 45711a8f1fe676f1d83e0da7336e744ebcdcc14a88c4Evan Cheng assert(((MVT::isInteger(NVT) && NVT < VT) || MVT::isFloatingPoint(VT) || 45721a8f1fe676f1d83e0da7336e744ebcdcc14a88c4Evan Cheng VT == MVT::Vector) && 45733e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner "Cannot expand to FP value or to larger int value!"); 45743e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 45756fdcb250d5692235813b30274cdfcd0e76377f00Chris Lattner // See if we already expanded it. 45766fdcb250d5692235813b30274cdfcd0e76377f00Chris Lattner std::map<SDOperand, std::pair<SDOperand, SDOperand> >::iterator I 45776fdcb250d5692235813b30274cdfcd0e76377f00Chris Lattner = ExpandedNodes.find(Op); 45786fdcb250d5692235813b30274cdfcd0e76377f00Chris Lattner if (I != ExpandedNodes.end()) { 45796fdcb250d5692235813b30274cdfcd0e76377f00Chris Lattner Lo = I->second.first; 45806fdcb250d5692235813b30274cdfcd0e76377f00Chris Lattner Hi = I->second.second; 45816fdcb250d5692235813b30274cdfcd0e76377f00Chris Lattner return; 45823e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 45833e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 45843e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner switch (Node->getOpcode()) { 4585348e93c8f7132c6ecbaf5866048e087feb7520e2Chris Lattner case ISD::CopyFromReg: 4586348e93c8f7132c6ecbaf5866048e087feb7520e2Chris Lattner assert(0 && "CopyFromReg must be legal!"); 4587348e93c8f7132c6ecbaf5866048e087feb7520e2Chris Lattner default: 4588e37fe9b3a1cadceb42ac27fa0718f5a10ea2f0e6Jim Laskey#ifndef NDEBUG 4589832171cb9724d2d31c8dfb73172e2be8f6dd13eeBill Wendling cerr << "NODE: "; Node->dump(); cerr << "\n"; 4590e37fe9b3a1cadceb42ac27fa0718f5a10ea2f0e6Jim Laskey#endif 45913e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner assert(0 && "Do not know how to expand this operator!"); 45923e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner abort(); 4593fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman case ISD::UNDEF: 4594aa975c1c4785a1d7930f2cd1026cb40ce54d21e4Evan Cheng NVT = TLI.getTypeToExpandTo(VT); 4595fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman Lo = DAG.getNode(ISD::UNDEF, NVT); 4596fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman Hi = DAG.getNode(ISD::UNDEF, NVT); 4597fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman break; 45983e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::Constant: { 45993e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner uint64_t Cst = cast<ConstantSDNode>(Node)->getValue(); 46003e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner Lo = DAG.getConstant(Cst, NVT); 46013e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner Hi = DAG.getConstant(Cst >> MVT::getSizeInBits(NVT), NVT); 46023e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 46033e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 4604004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng case ISD::ConstantFP: { 4605004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node); 4606279101eb1ac61e2d5b83d5bdcc5be56e710d2cd7Evan Cheng Lo = ExpandConstantFP(CFP, false, DAG, TLI); 46079f87788040786b1bc6530763e4cf7e105bfb2924Evan Cheng if (getTypeAction(Lo.getValueType()) == Expand) 46089f87788040786b1bc6530763e4cf7e105bfb2924Evan Cheng ExpandOp(Lo, Lo, Hi); 4609004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng break; 4610004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng } 4611d4e50bb2e23b8f9ddde629a28dab3bcdaf0633e4Chris Lattner case ISD::BUILD_PAIR: 46128137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner // Return the operands. 46138137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner Lo = Node->getOperand(0); 46148137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner Hi = Node->getOperand(1); 4615d4e50bb2e23b8f9ddde629a28dab3bcdaf0633e4Chris Lattner break; 461658f7963b8b3cb8894623a7d7663cc54005fea8f9Chris Lattner 461758f7963b8b3cb8894623a7d7663cc54005fea8f9Chris Lattner case ISD::SIGN_EXTEND_INREG: 461858f7963b8b3cb8894623a7d7663cc54005fea8f9Chris Lattner ExpandOp(Node->getOperand(0), Lo, Hi); 46194bdd2753db4a9d92b64c68b042c8b38f7223238dChris Lattner // sext_inreg the low part if needed. 46204bdd2753db4a9d92b64c68b042c8b38f7223238dChris Lattner Lo = DAG.getNode(ISD::SIGN_EXTEND_INREG, NVT, Lo, Node->getOperand(1)); 46214bdd2753db4a9d92b64c68b042c8b38f7223238dChris Lattner 46224bdd2753db4a9d92b64c68b042c8b38f7223238dChris Lattner // The high part gets the sign extension from the lo-part. This handles 46234bdd2753db4a9d92b64c68b042c8b38f7223238dChris Lattner // things like sextinreg V:i64 from i8. 462458f7963b8b3cb8894623a7d7663cc54005fea8f9Chris Lattner Hi = DAG.getNode(ISD::SRA, NVT, Lo, 462558f7963b8b3cb8894623a7d7663cc54005fea8f9Chris Lattner DAG.getConstant(MVT::getSizeInBits(NVT)-1, 462658f7963b8b3cb8894623a7d7663cc54005fea8f9Chris Lattner TLI.getShiftAmountTy())); 462758f7963b8b3cb8894623a7d7663cc54005fea8f9Chris Lattner break; 4628d4e50bb2e23b8f9ddde629a28dab3bcdaf0633e4Chris Lattner 4629d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman case ISD::BSWAP: { 4630d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman ExpandOp(Node->getOperand(0), Lo, Hi); 4631d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman SDOperand TempLo = DAG.getNode(ISD::BSWAP, NVT, Hi); 4632d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman Hi = DAG.getNode(ISD::BSWAP, NVT, Lo); 4633d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman Lo = TempLo; 4634d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman break; 4635d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman } 4636d88fc03602947b5baa35c8b09fe8bcfa2b4a03c1Nate Begeman 4637edb1add9a093efa266c94b6d0a34c26f5b2d5d7bChris Lattner case ISD::CTPOP: 4638edb1add9a093efa266c94b6d0a34c26f5b2d5d7bChris Lattner ExpandOp(Node->getOperand(0), Lo, Hi); 46399b583b49103f21888ac3de3f7941a98a63a23aeaChris Lattner Lo = DAG.getNode(ISD::ADD, NVT, // ctpop(HL) -> ctpop(H)+ctpop(L) 46409b583b49103f21888ac3de3f7941a98a63a23aeaChris Lattner DAG.getNode(ISD::CTPOP, NVT, Lo), 46419b583b49103f21888ac3de3f7941a98a63a23aeaChris Lattner DAG.getNode(ISD::CTPOP, NVT, Hi)); 4642edb1add9a093efa266c94b6d0a34c26f5b2d5d7bChris Lattner Hi = DAG.getConstant(0, NVT); 4643edb1add9a093efa266c94b6d0a34c26f5b2d5d7bChris Lattner break; 4644edb1add9a093efa266c94b6d0a34c26f5b2d5d7bChris Lattner 464539a8f336305a492fc6d2625f39f08968185616d2Chris Lattner case ISD::CTLZ: { 464639a8f336305a492fc6d2625f39f08968185616d2Chris Lattner // ctlz (HL) -> ctlz(H) != 32 ? ctlz(H) : (ctlz(L)+32) 46473becf2026bec881a60cbbe0031d8c51f4d6d4e28Chris Lattner ExpandOp(Node->getOperand(0), Lo, Hi); 464839a8f336305a492fc6d2625f39f08968185616d2Chris Lattner SDOperand BitsC = DAG.getConstant(MVT::getSizeInBits(NVT), NVT); 464939a8f336305a492fc6d2625f39f08968185616d2Chris Lattner SDOperand HLZ = DAG.getNode(ISD::CTLZ, NVT, Hi); 46507cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner SDOperand TopNotZero = DAG.getSetCC(TLI.getSetCCResultTy(), HLZ, BitsC, 46517cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner ISD::SETNE); 465239a8f336305a492fc6d2625f39f08968185616d2Chris Lattner SDOperand LowPart = DAG.getNode(ISD::CTLZ, NVT, Lo); 465339a8f336305a492fc6d2625f39f08968185616d2Chris Lattner LowPart = DAG.getNode(ISD::ADD, NVT, LowPart, BitsC); 465439a8f336305a492fc6d2625f39f08968185616d2Chris Lattner 465539a8f336305a492fc6d2625f39f08968185616d2Chris Lattner Lo = DAG.getNode(ISD::SELECT, NVT, TopNotZero, HLZ, LowPart); 465639a8f336305a492fc6d2625f39f08968185616d2Chris Lattner Hi = DAG.getConstant(0, NVT); 465739a8f336305a492fc6d2625f39f08968185616d2Chris Lattner break; 465839a8f336305a492fc6d2625f39f08968185616d2Chris Lattner } 465939a8f336305a492fc6d2625f39f08968185616d2Chris Lattner 466039a8f336305a492fc6d2625f39f08968185616d2Chris Lattner case ISD::CTTZ: { 466139a8f336305a492fc6d2625f39f08968185616d2Chris Lattner // cttz (HL) -> cttz(L) != 32 ? cttz(L) : (cttz(H)+32) 46623becf2026bec881a60cbbe0031d8c51f4d6d4e28Chris Lattner ExpandOp(Node->getOperand(0), Lo, Hi); 466339a8f336305a492fc6d2625f39f08968185616d2Chris Lattner SDOperand BitsC = DAG.getConstant(MVT::getSizeInBits(NVT), NVT); 466439a8f336305a492fc6d2625f39f08968185616d2Chris Lattner SDOperand LTZ = DAG.getNode(ISD::CTTZ, NVT, Lo); 46657cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner SDOperand BotNotZero = DAG.getSetCC(TLI.getSetCCResultTy(), LTZ, BitsC, 46667cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner ISD::SETNE); 466739a8f336305a492fc6d2625f39f08968185616d2Chris Lattner SDOperand HiPart = DAG.getNode(ISD::CTTZ, NVT, Hi); 466839a8f336305a492fc6d2625f39f08968185616d2Chris Lattner HiPart = DAG.getNode(ISD::ADD, NVT, HiPart, BitsC); 466939a8f336305a492fc6d2625f39f08968185616d2Chris Lattner 467039a8f336305a492fc6d2625f39f08968185616d2Chris Lattner Lo = DAG.getNode(ISD::SELECT, NVT, BotNotZero, LTZ, HiPart); 467139a8f336305a492fc6d2625f39f08968185616d2Chris Lattner Hi = DAG.getConstant(0, NVT); 467239a8f336305a492fc6d2625f39f08968185616d2Chris Lattner break; 467339a8f336305a492fc6d2625f39f08968185616d2Chris Lattner } 4674edb1add9a093efa266c94b6d0a34c26f5b2d5d7bChris Lattner 4675acc398c195a697795bff3245943d104eb19192b9Nate Begeman case ISD::VAARG: { 46768137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner SDOperand Ch = Node->getOperand(0); // Legalize the chain. 46778137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner SDOperand Ptr = Node->getOperand(1); // Legalize the pointer. 4678acc398c195a697795bff3245943d104eb19192b9Nate Begeman Lo = DAG.getVAArg(NVT, Ch, Ptr, Node->getOperand(2)); 4679acc398c195a697795bff3245943d104eb19192b9Nate Begeman Hi = DAG.getVAArg(NVT, Lo.getValue(1), Ptr, Node->getOperand(2)); 4680acc398c195a697795bff3245943d104eb19192b9Nate Begeman 4681acc398c195a697795bff3245943d104eb19192b9Nate Begeman // Remember that we legalized the chain. 46828137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner Hi = LegalizeOp(Hi); 4683acc398c195a697795bff3245943d104eb19192b9Nate Begeman AddLegalizedOperand(Op.getValue(1), Hi.getValue(1)); 4684acc398c195a697795bff3245943d104eb19192b9Nate Begeman if (!TLI.isLittleEndian()) 4685acc398c195a697795bff3245943d104eb19192b9Nate Begeman std::swap(Lo, Hi); 4686acc398c195a697795bff3245943d104eb19192b9Nate Begeman break; 4687acc398c195a697795bff3245943d104eb19192b9Nate Begeman } 4688acc398c195a697795bff3245943d104eb19192b9Nate Begeman 46893e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::LOAD: { 4690466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng LoadSDNode *LD = cast<LoadSDNode>(Node); 4691466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng SDOperand Ch = LD->getChain(); // Legalize the chain. 4692466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng SDOperand Ptr = LD->getBasePtr(); // Legalize the pointer. 4693466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng ISD::LoadExtType ExtType = LD->getExtensionType(); 4694466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng 4695466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng if (ExtType == ISD::NON_EXTLOAD) { 4696466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Lo = DAG.getLoad(NVT, Ch, Ptr, LD->getSrcValue(), LD->getSrcValueOffset()); 4697004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng if (VT == MVT::f32 || VT == MVT::f64) { 4698004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng // f32->i32 or f64->i64 one to one expansion. 4699004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng // Remember that we legalized the chain. 4700004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng AddLegalizedOperand(SDOperand(Node, 1), LegalizeOp(Lo.getValue(1))); 47019f87788040786b1bc6530763e4cf7e105bfb2924Evan Cheng // Recursively expand the new load. 47029f87788040786b1bc6530763e4cf7e105bfb2924Evan Cheng if (getTypeAction(NVT) == Expand) 47039f87788040786b1bc6530763e4cf7e105bfb2924Evan Cheng ExpandOp(Lo, Lo, Hi); 4704004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng break; 4705004952140f3cf92ee098c2c5b8cdee1449bdc2edEvan Cheng } 4706466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng 4707466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng // Increment the pointer to the other half. 4708466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng unsigned IncrementSize = MVT::getSizeInBits(Lo.getValueType())/8; 4709466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, 4710466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng getIntPtrConstant(IncrementSize)); 4711466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng // FIXME: This creates a bogus srcvalue! 4712466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Hi = DAG.getLoad(NVT, Ch, Ptr, LD->getSrcValue(), LD->getSrcValueOffset()); 4713466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng 4714466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng // Build a factor node to remember that this load is independent of the 4715466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng // other one. 4716466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), 4717466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Hi.getValue(1)); 4718466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng 4719466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng // Remember that we legalized the chain. 4720466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF)); 4721466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng if (!TLI.isLittleEndian()) 4722466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng std::swap(Lo, Hi); 4723466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng } else { 47242e49f090f9656af7d5ed4d5c4e9fa26af59c7233Evan Cheng MVT::ValueType EVT = LD->getLoadedVT(); 4725548f611baeb53e821e7e80f97722b048ab6b09b2Evan Cheng 4726548f611baeb53e821e7e80f97722b048ab6b09b2Evan Cheng if (VT == MVT::f64 && EVT == MVT::f32) { 4727548f611baeb53e821e7e80f97722b048ab6b09b2Evan Cheng // f64 = EXTLOAD f32 should expand to LOAD, FP_EXTEND 4728548f611baeb53e821e7e80f97722b048ab6b09b2Evan Cheng SDOperand Load = DAG.getLoad(EVT, Ch, Ptr, LD->getSrcValue(), 4729548f611baeb53e821e7e80f97722b048ab6b09b2Evan Cheng LD->getSrcValueOffset()); 4730548f611baeb53e821e7e80f97722b048ab6b09b2Evan Cheng // Remember that we legalized the chain. 4731548f611baeb53e821e7e80f97722b048ab6b09b2Evan Cheng AddLegalizedOperand(SDOperand(Node, 1), LegalizeOp(Load.getValue(1))); 4732548f611baeb53e821e7e80f97722b048ab6b09b2Evan Cheng ExpandOp(DAG.getNode(ISD::FP_EXTEND, VT, Load), Lo, Hi); 4733548f611baeb53e821e7e80f97722b048ab6b09b2Evan Cheng break; 4734548f611baeb53e821e7e80f97722b048ab6b09b2Evan Cheng } 4735466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng 4736466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng if (EVT == NVT) 4737466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Lo = DAG.getLoad(NVT, Ch, Ptr, LD->getSrcValue(), 4738466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng LD->getSrcValueOffset()); 4739466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng else 4740466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Lo = DAG.getExtLoad(ExtType, NVT, Ch, Ptr, LD->getSrcValue(), 4741466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng LD->getSrcValueOffset(), EVT); 4742466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng 4743466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng // Remember that we legalized the chain. 4744466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng AddLegalizedOperand(SDOperand(Node, 1), LegalizeOp(Lo.getValue(1))); 4745466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng 4746466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng if (ExtType == ISD::SEXTLOAD) { 4747466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng // The high part is obtained by SRA'ing all but one of the bits of the 4748466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng // lo part. 4749466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng unsigned LoSize = MVT::getSizeInBits(Lo.getValueType()); 4750466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Hi = DAG.getNode(ISD::SRA, NVT, Lo, 4751466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng DAG.getConstant(LoSize-1, TLI.getShiftAmountTy())); 4752466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng } else if (ExtType == ISD::ZEXTLOAD) { 4753466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng // The high part is just a zero. 4754466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Hi = DAG.getConstant(0, NVT); 4755466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng } else /* if (ExtType == ISD::EXTLOAD) */ { 4756466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng // The high part is undefined. 4757466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Hi = DAG.getNode(ISD::UNDEF, NVT); 4758466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng } 4759466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng } 47603e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 47613e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 47623e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::AND: 47633e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::OR: 47643e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::XOR: { // Simple logical operators -> two trivial pieces. 47653e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner SDOperand LL, LH, RL, RH; 47663e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner ExpandOp(Node->getOperand(0), LL, LH); 47673e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner ExpandOp(Node->getOperand(1), RL, RH); 47683e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner Lo = DAG.getNode(Node->getOpcode(), NVT, LL, RL); 47693e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner Hi = DAG.getNode(Node->getOpcode(), NVT, LH, RH); 47703e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 47713e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 47723e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::SELECT: { 4773456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner SDOperand LL, LH, RL, RH; 47743e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner ExpandOp(Node->getOperand(1), LL, LH); 47753e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner ExpandOp(Node->getOperand(2), RL, RH); 477619103b11ecbd5153537a1c64ffefa922fe591addEvan Cheng if (getTypeAction(NVT) == Expand) 477719103b11ecbd5153537a1c64ffefa922fe591addEvan Cheng NVT = TLI.getTypeToExpandTo(NVT); 4778456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner Lo = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LL, RL); 477919103b11ecbd5153537a1c64ffefa922fe591addEvan Cheng if (VT != MVT::f32) 478019103b11ecbd5153537a1c64ffefa922fe591addEvan Cheng Hi = DAG.getNode(ISD::SELECT, NVT, Node->getOperand(0), LH, RH); 47813e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 47823e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 47839373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman case ISD::SELECT_CC: { 47849373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman SDOperand TL, TH, FL, FH; 47859373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman ExpandOp(Node->getOperand(2), TL, TH); 47869373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman ExpandOp(Node->getOperand(3), FL, FH); 478719103b11ecbd5153537a1c64ffefa922fe591addEvan Cheng if (getTypeAction(NVT) == Expand) 478819103b11ecbd5153537a1c64ffefa922fe591addEvan Cheng NVT = TLI.getTypeToExpandTo(NVT); 47899373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman Lo = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), 47909373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman Node->getOperand(1), TL, FL, Node->getOperand(4)); 479119103b11ecbd5153537a1c64ffefa922fe591addEvan Cheng if (VT != MVT::f32) 479219103b11ecbd5153537a1c64ffefa922fe591addEvan Cheng Hi = DAG.getNode(ISD::SELECT_CC, NVT, Node->getOperand(0), 479319103b11ecbd5153537a1c64ffefa922fe591addEvan Cheng Node->getOperand(1), TH, FH, Node->getOperand(4)); 47949373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman break; 47959373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman } 47968137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner case ISD::ANY_EXTEND: 479713c78e2e5f158e9008b279b43b685ff02bb3cbeaChris Lattner // The low part is any extension of the input (which degenerates to a copy). 47988137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner Lo = DAG.getNode(ISD::ANY_EXTEND, NVT, Node->getOperand(0)); 479913c78e2e5f158e9008b279b43b685ff02bb3cbeaChris Lattner // The high part is undefined. 480013c78e2e5f158e9008b279b43b685ff02bb3cbeaChris Lattner Hi = DAG.getNode(ISD::UNDEF, NVT); 480113c78e2e5f158e9008b279b43b685ff02bb3cbeaChris Lattner break; 48023e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner case ISD::SIGN_EXTEND: { 48033e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner // The low part is just a sign extension of the input (which degenerates to 48043e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner // a copy). 48058137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner Lo = DAG.getNode(ISD::SIGN_EXTEND, NVT, Node->getOperand(0)); 4806edf128a7fa90f2b0b7ee24741a04a7ae1ecd6f7eMisha Brukman 48073e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner // The high part is obtained by SRA'ing all but one of the bits of the lo 48083e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner // part. 48092dad454af674cb41a14a85ad6ce5c85c43959acdChris Lattner unsigned LoSize = MVT::getSizeInBits(Lo.getValueType()); 48108137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner Hi = DAG.getNode(ISD::SRA, NVT, Lo, 48118137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner DAG.getConstant(LoSize-1, TLI.getShiftAmountTy())); 48123e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 48133e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner } 48148137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner case ISD::ZERO_EXTEND: 48153e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner // The low part is just a zero extension of the input (which degenerates to 48163e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner // a copy). 48178137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner Lo = DAG.getNode(ISD::ZERO_EXTEND, NVT, Node->getOperand(0)); 4818edf128a7fa90f2b0b7ee24741a04a7ae1ecd6f7eMisha Brukman 48193e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner // The high part is just a zero. 48203e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner Hi = DAG.getConstant(0, NVT); 48213e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner break; 482235481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner 482335481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner case ISD::BIT_CONVERT: { 4824f3f333dbd67afde147165bb5ba87889d76a6f436Chris Lattner SDOperand Tmp; 4825f3f333dbd67afde147165bb5ba87889d76a6f436Chris Lattner if (TLI.getOperationAction(ISD::BIT_CONVERT, VT) == TargetLowering::Custom){ 4826f3f333dbd67afde147165bb5ba87889d76a6f436Chris Lattner // If the target wants to, allow it to lower this itself. 4827f3f333dbd67afde147165bb5ba87889d76a6f436Chris Lattner switch (getTypeAction(Node->getOperand(0).getValueType())) { 4828f3f333dbd67afde147165bb5ba87889d76a6f436Chris Lattner case Expand: assert(0 && "cannot expand FP!"); 4829f3f333dbd67afde147165bb5ba87889d76a6f436Chris Lattner case Legal: Tmp = LegalizeOp(Node->getOperand(0)); break; 4830f3f333dbd67afde147165bb5ba87889d76a6f436Chris Lattner case Promote: Tmp = PromoteOp (Node->getOperand(0)); break; 4831f3f333dbd67afde147165bb5ba87889d76a6f436Chris Lattner } 4832f3f333dbd67afde147165bb5ba87889d76a6f436Chris Lattner Tmp = TLI.LowerOperation(DAG.getNode(ISD::BIT_CONVERT, VT, Tmp), DAG); 4833f3f333dbd67afde147165bb5ba87889d76a6f436Chris Lattner } 4834f3f333dbd67afde147165bb5ba87889d76a6f436Chris Lattner 48351a8f1fe676f1d83e0da7336e744ebcdcc14a88c4Evan Cheng // f32 / f64 must be expanded to i32 / i64. 483613acce3ef03d29679c2b241bdba6ca015644e8b6Evan Cheng if (VT == MVT::f32 || VT == MVT::f64) { 483713acce3ef03d29679c2b241bdba6ca015644e8b6Evan Cheng Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); 483819103b11ecbd5153537a1c64ffefa922fe591addEvan Cheng if (getTypeAction(NVT) == Expand) 483919103b11ecbd5153537a1c64ffefa922fe591addEvan Cheng ExpandOp(Lo, Lo, Hi); 48407b2b5c846c371f58db73f453a007e52eda62da89Evan Cheng break; 48417b2b5c846c371f58db73f453a007e52eda62da89Evan Cheng } 48427b2b5c846c371f58db73f453a007e52eda62da89Evan Cheng 48437b2b5c846c371f58db73f453a007e52eda62da89Evan Cheng // If source operand will be expanded to the same type as VT, i.e. 48447b2b5c846c371f58db73f453a007e52eda62da89Evan Cheng // i64 <- f64, i32 <- f32, expand the source operand instead. 48457b2b5c846c371f58db73f453a007e52eda62da89Evan Cheng MVT::ValueType VT0 = Node->getOperand(0).getValueType(); 48467b2b5c846c371f58db73f453a007e52eda62da89Evan Cheng if (getTypeAction(VT0) == Expand && TLI.getTypeToTransformTo(VT0) == VT) { 48477b2b5c846c371f58db73f453a007e52eda62da89Evan Cheng ExpandOp(Node->getOperand(0), Lo, Hi); 48481a8f1fe676f1d83e0da7336e744ebcdcc14a88c4Evan Cheng break; 48491a8f1fe676f1d83e0da7336e744ebcdcc14a88c4Evan Cheng } 48501a8f1fe676f1d83e0da7336e744ebcdcc14a88c4Evan Cheng 4851f3f333dbd67afde147165bb5ba87889d76a6f436Chris Lattner // Turn this into a load/store pair by default. 4852f3f333dbd67afde147165bb5ba87889d76a6f436Chris Lattner if (Tmp.Val == 0) 485313acce3ef03d29679c2b241bdba6ca015644e8b6Evan Cheng Tmp = ExpandBIT_CONVERT(VT, Node->getOperand(0)); 4854f3f333dbd67afde147165bb5ba87889d76a6f436Chris Lattner 485535481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner ExpandOp(Tmp, Lo, Hi); 485635481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner break; 485735481892da1e5634bf497c8a0cabb1bb5a8b8fefChris Lattner } 4858f70e30b41dc6a92733681dcea2c06d8b3dd488dbAndrew Lenharth 48598137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner case ISD::READCYCLECOUNTER: 4860308575be66ec3870d27b19df044fda18448feb41Chris Lattner assert(TLI.getOperationAction(ISD::READCYCLECOUNTER, VT) == 4861308575be66ec3870d27b19df044fda18448feb41Chris Lattner TargetLowering::Custom && 4862308575be66ec3870d27b19df044fda18448feb41Chris Lattner "Must custom expand ReadCycleCounter"); 48638137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner Lo = TLI.LowerOperation(Op, DAG); 48648137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner assert(Lo.Val && "Node must be custom expanded!"); 48658137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner Hi = Lo.getValue(1); 4866308575be66ec3870d27b19df044fda18448feb41Chris Lattner AddLegalizedOperand(SDOperand(Node, 1), // Remember we legalized the chain. 48678137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner LegalizeOp(Lo.getValue(2))); 4868f70e30b41dc6a92733681dcea2c06d8b3dd488dbAndrew Lenharth break; 4869f70e30b41dc6a92733681dcea2c06d8b3dd488dbAndrew Lenharth 48704e6c74689944be1de80c99dc0688ec0bcbd743aaChris Lattner // These operators cannot be expanded directly, emit them as calls to 48714e6c74689944be1de80c99dc0688ec0bcbd743aaChris Lattner // library functions. 487256966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng case ISD::FP_TO_SINT: { 487380a3e94653574c69ac805d9684a23a94ed3e4b5dChris Lattner if (TLI.getOperationAction(ISD::FP_TO_SINT, VT) == TargetLowering::Custom) { 4874f20d183c2268553c738fefb014959ea924dd0555Chris Lattner SDOperand Op; 4875f20d183c2268553c738fefb014959ea924dd0555Chris Lattner switch (getTypeAction(Node->getOperand(0).getValueType())) { 4876f20d183c2268553c738fefb014959ea924dd0555Chris Lattner case Expand: assert(0 && "cannot expand FP!"); 48778137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner case Legal: Op = LegalizeOp(Node->getOperand(0)); break; 48788137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner case Promote: Op = PromoteOp (Node->getOperand(0)); break; 4879f20d183c2268553c738fefb014959ea924dd0555Chris Lattner } 4880d29b6aa608d69f19b57ebd2ae630b040b1c4951dJeff Cohen 4881f20d183c2268553c738fefb014959ea924dd0555Chris Lattner Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_SINT, VT, Op), DAG); 4882f20d183c2268553c738fefb014959ea924dd0555Chris Lattner 488380a3e94653574c69ac805d9684a23a94ed3e4b5dChris Lattner // Now that the custom expander is done, expand the result, which is still 488480a3e94653574c69ac805d9684a23a94ed3e4b5dChris Lattner // VT. 488507dffd6af673c73352150583150b242a93694f00Chris Lattner if (Op.Val) { 488607dffd6af673c73352150583150b242a93694f00Chris Lattner ExpandOp(Op, Lo, Hi); 488707dffd6af673c73352150583150b242a93694f00Chris Lattner break; 488807dffd6af673c73352150583150b242a93694f00Chris Lattner } 488980a3e94653574c69ac805d9684a23a94ed3e4b5dChris Lattner } 4890d29b6aa608d69f19b57ebd2ae630b040b1c4951dJeff Cohen 489156966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng RTLIB::Libcall LC; 48924e6c74689944be1de80c99dc0688ec0bcbd743aaChris Lattner if (Node->getOperand(0).getValueType() == MVT::f32) 489356966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC = RTLIB::FPTOSINT_F32_I64; 48944e6c74689944be1de80c99dc0688ec0bcbd743aaChris Lattner else 489556966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC = RTLIB::FPTOSINT_F64_I64; 489656966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, 489756966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng false/*sign irrelevant*/, Hi); 48984e6c74689944be1de80c99dc0688ec0bcbd743aaChris Lattner break; 489956966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng } 4900d29b6aa608d69f19b57ebd2ae630b040b1c4951dJeff Cohen 490156966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng case ISD::FP_TO_UINT: { 490280a3e94653574c69ac805d9684a23a94ed3e4b5dChris Lattner if (TLI.getOperationAction(ISD::FP_TO_UINT, VT) == TargetLowering::Custom) { 49038137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner SDOperand Op; 49048137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner switch (getTypeAction(Node->getOperand(0).getValueType())) { 49058137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner case Expand: assert(0 && "cannot expand FP!"); 49068137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner case Legal: Op = LegalizeOp(Node->getOperand(0)); break; 49078137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner case Promote: Op = PromoteOp (Node->getOperand(0)); break; 49088137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner } 49098137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner 49108137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_UINT, VT, Op), DAG); 49118137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner 49128137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner // Now that the custom expander is done, expand the result. 491307dffd6af673c73352150583150b242a93694f00Chris Lattner if (Op.Val) { 491407dffd6af673c73352150583150b242a93694f00Chris Lattner ExpandOp(Op, Lo, Hi); 491507dffd6af673c73352150583150b242a93694f00Chris Lattner break; 491607dffd6af673c73352150583150b242a93694f00Chris Lattner } 491780a3e94653574c69ac805d9684a23a94ed3e4b5dChris Lattner } 4918d29b6aa608d69f19b57ebd2ae630b040b1c4951dJeff Cohen 491956966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng RTLIB::Libcall LC; 49204e6c74689944be1de80c99dc0688ec0bcbd743aaChris Lattner if (Node->getOperand(0).getValueType() == MVT::f32) 492156966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC = RTLIB::FPTOUINT_F32_I64; 49224e6c74689944be1de80c99dc0688ec0bcbd743aaChris Lattner else 492356966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC = RTLIB::FPTOUINT_F64_I64; 492456966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, 492556966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng false/*sign irrelevant*/, Hi); 49264e6c74689944be1de80c99dc0688ec0bcbd743aaChris Lattner break; 492756966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng } 49284e6c74689944be1de80c99dc0688ec0bcbd743aaChris Lattner 492905a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng case ISD::SHL: { 493050ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner // If the target wants custom lowering, do so. 4931348e93c8f7132c6ecbaf5866048e087feb7520e2Chris Lattner SDOperand ShiftAmt = LegalizeOp(Node->getOperand(1)); 493250ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner if (TLI.getOperationAction(ISD::SHL, VT) == TargetLowering::Custom) { 49338137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner SDOperand Op = DAG.getNode(ISD::SHL, VT, Node->getOperand(0), ShiftAmt); 493450ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner Op = TLI.LowerOperation(Op, DAG); 493550ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner if (Op.Val) { 493650ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner // Now that the custom expander is done, expand the result, which is 493750ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner // still VT. 493850ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner ExpandOp(Op, Lo, Hi); 493950ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner break; 494050ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner } 494150ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner } 494250ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner 494379980b07dab50da1a8f572f9504674bfa853d484Chris Lattner // If ADDC/ADDE are supported and if the shift amount is a constant 1, emit 494479980b07dab50da1a8f572f9504674bfa853d484Chris Lattner // this X << 1 as X+X. 494579980b07dab50da1a8f572f9504674bfa853d484Chris Lattner if (ConstantSDNode *ShAmt = dyn_cast<ConstantSDNode>(ShiftAmt)) { 494679980b07dab50da1a8f572f9504674bfa853d484Chris Lattner if (ShAmt->getValue() == 1 && TLI.isOperationLegal(ISD::ADDC, NVT) && 494779980b07dab50da1a8f572f9504674bfa853d484Chris Lattner TLI.isOperationLegal(ISD::ADDE, NVT)) { 494879980b07dab50da1a8f572f9504674bfa853d484Chris Lattner SDOperand LoOps[2], HiOps[3]; 494979980b07dab50da1a8f572f9504674bfa853d484Chris Lattner ExpandOp(Node->getOperand(0), LoOps[0], HiOps[0]); 495079980b07dab50da1a8f572f9504674bfa853d484Chris Lattner SDVTList VTList = DAG.getVTList(LoOps[0].getValueType(), MVT::Flag); 495179980b07dab50da1a8f572f9504674bfa853d484Chris Lattner LoOps[1] = LoOps[0]; 495279980b07dab50da1a8f572f9504674bfa853d484Chris Lattner Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); 495379980b07dab50da1a8f572f9504674bfa853d484Chris Lattner 495479980b07dab50da1a8f572f9504674bfa853d484Chris Lattner HiOps[1] = HiOps[0]; 495579980b07dab50da1a8f572f9504674bfa853d484Chris Lattner HiOps[2] = Lo.getValue(1); 495679980b07dab50da1a8f572f9504674bfa853d484Chris Lattner Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); 495779980b07dab50da1a8f572f9504674bfa853d484Chris Lattner break; 495879980b07dab50da1a8f572f9504674bfa853d484Chris Lattner } 495979980b07dab50da1a8f572f9504674bfa853d484Chris Lattner } 496079980b07dab50da1a8f572f9504674bfa853d484Chris Lattner 4961e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner // If we can emit an efficient shift operation, do so now. 4962348e93c8f7132c6ecbaf5866048e087feb7520e2Chris Lattner if (ExpandShift(ISD::SHL, Node->getOperand(0), ShiftAmt, Lo, Hi)) 4963e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner break; 49644759982a2d4ab597fb69d4a1113d0f35e673a4e1Chris Lattner 49654759982a2d4ab597fb69d4a1113d0f35e673a4e1Chris Lattner // If this target supports SHL_PARTS, use it. 496605a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng TargetLowering::LegalizeAction Action = 496705a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng TLI.getOperationAction(ISD::SHL_PARTS, NVT); 496805a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || 496905a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng Action == TargetLowering::Custom) { 4970348e93c8f7132c6ecbaf5866048e087feb7520e2Chris Lattner ExpandShiftParts(ISD::SHL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); 49714759982a2d4ab597fb69d4a1113d0f35e673a4e1Chris Lattner break; 49724759982a2d4ab597fb69d4a1113d0f35e673a4e1Chris Lattner } 49734759982a2d4ab597fb69d4a1113d0f35e673a4e1Chris Lattner 4974e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner // Otherwise, emit a libcall. 497556966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SHL_I64), Node, 497656966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng false/*left shift=unsigned*/, Hi); 4977e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner break; 497805a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng } 4979e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner 498005a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng case ISD::SRA: { 498150ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner // If the target wants custom lowering, do so. 4982348e93c8f7132c6ecbaf5866048e087feb7520e2Chris Lattner SDOperand ShiftAmt = LegalizeOp(Node->getOperand(1)); 498350ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner if (TLI.getOperationAction(ISD::SRA, VT) == TargetLowering::Custom) { 49848137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner SDOperand Op = DAG.getNode(ISD::SRA, VT, Node->getOperand(0), ShiftAmt); 498550ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner Op = TLI.LowerOperation(Op, DAG); 498650ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner if (Op.Val) { 498750ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner // Now that the custom expander is done, expand the result, which is 498850ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner // still VT. 498950ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner ExpandOp(Op, Lo, Hi); 499050ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner break; 499150ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner } 499250ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner } 499350ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner 4994e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner // If we can emit an efficient shift operation, do so now. 4995348e93c8f7132c6ecbaf5866048e087feb7520e2Chris Lattner if (ExpandShift(ISD::SRA, Node->getOperand(0), ShiftAmt, Lo, Hi)) 4996e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner break; 49974759982a2d4ab597fb69d4a1113d0f35e673a4e1Chris Lattner 49984759982a2d4ab597fb69d4a1113d0f35e673a4e1Chris Lattner // If this target supports SRA_PARTS, use it. 499905a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng TargetLowering::LegalizeAction Action = 500005a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng TLI.getOperationAction(ISD::SRA_PARTS, NVT); 500105a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || 500205a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng Action == TargetLowering::Custom) { 5003348e93c8f7132c6ecbaf5866048e087feb7520e2Chris Lattner ExpandShiftParts(ISD::SRA_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); 50044759982a2d4ab597fb69d4a1113d0f35e673a4e1Chris Lattner break; 50054759982a2d4ab597fb69d4a1113d0f35e673a4e1Chris Lattner } 50064759982a2d4ab597fb69d4a1113d0f35e673a4e1Chris Lattner 5007e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner // Otherwise, emit a libcall. 500856966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SRA_I64), Node, 500956966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng true/*ashr is signed*/, Hi); 5010e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner break; 501105a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng } 501205a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng 501305a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng case ISD::SRL: { 501450ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner // If the target wants custom lowering, do so. 5015348e93c8f7132c6ecbaf5866048e087feb7520e2Chris Lattner SDOperand ShiftAmt = LegalizeOp(Node->getOperand(1)); 501650ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner if (TLI.getOperationAction(ISD::SRL, VT) == TargetLowering::Custom) { 50178137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner SDOperand Op = DAG.getNode(ISD::SRL, VT, Node->getOperand(0), ShiftAmt); 501850ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner Op = TLI.LowerOperation(Op, DAG); 501950ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner if (Op.Val) { 502050ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner // Now that the custom expander is done, expand the result, which is 502150ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner // still VT. 502250ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner ExpandOp(Op, Lo, Hi); 502350ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner break; 502450ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner } 502550ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner } 502650ec8979047065bd0ff41fac4ffd44f744b77723Chris Lattner 5027e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner // If we can emit an efficient shift operation, do so now. 5028348e93c8f7132c6ecbaf5866048e087feb7520e2Chris Lattner if (ExpandShift(ISD::SRL, Node->getOperand(0), ShiftAmt, Lo, Hi)) 5029e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner break; 50304759982a2d4ab597fb69d4a1113d0f35e673a4e1Chris Lattner 50314759982a2d4ab597fb69d4a1113d0f35e673a4e1Chris Lattner // If this target supports SRL_PARTS, use it. 503205a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng TargetLowering::LegalizeAction Action = 503305a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng TLI.getOperationAction(ISD::SRL_PARTS, NVT); 503405a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng if ((Action == TargetLowering::Legal && TLI.isTypeLegal(NVT)) || 503505a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng Action == TargetLowering::Custom) { 5036348e93c8f7132c6ecbaf5866048e087feb7520e2Chris Lattner ExpandShiftParts(ISD::SRL_PARTS, Node->getOperand(0), ShiftAmt, Lo, Hi); 50374759982a2d4ab597fb69d4a1113d0f35e673a4e1Chris Lattner break; 50384759982a2d4ab597fb69d4a1113d0f35e673a4e1Chris Lattner } 50394759982a2d4ab597fb69d4a1113d0f35e673a4e1Chris Lattner 5040e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner // Otherwise, emit a libcall. 504156966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SRL_I64), Node, 504256966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng false/*lshr is unsigned*/, Hi); 5043e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner break; 504405a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng } 5045e34b396ab7d28469bf3d9679a748b643d8e30458Chris Lattner 5046edf128a7fa90f2b0b7ee24741a04a7ae1ecd6f7eMisha Brukman case ISD::ADD: 50478137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner case ISD::SUB: { 50488137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner // If the target wants to custom expand this, let them. 50498137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner if (TLI.getOperationAction(Node->getOpcode(), VT) == 50508137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner TargetLowering::Custom) { 50518137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner Op = TLI.LowerOperation(Op, DAG); 50528137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner if (Op.Val) { 50538137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner ExpandOp(Op, Lo, Hi); 50548137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner break; 50558137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner } 50568137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner } 50578137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner 50588137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner // Expand the subcomponents. 50598137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner SDOperand LHSL, LHSH, RHSL, RHSH; 50608137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner ExpandOp(Node->getOperand(0), LHSL, LHSH); 50618137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner ExpandOp(Node->getOperand(1), RHSL, RHSH); 506279980b07dab50da1a8f572f9504674bfa853d484Chris Lattner SDVTList VTList = DAG.getVTList(LHSL.getValueType(), MVT::Flag); 506379980b07dab50da1a8f572f9504674bfa853d484Chris Lattner SDOperand LoOps[2], HiOps[3]; 5064bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner LoOps[0] = LHSL; 5065bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner LoOps[1] = RHSL; 5066bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner HiOps[0] = LHSH; 5067bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner HiOps[1] = RHSH; 5068551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman if (Node->getOpcode() == ISD::ADD) { 506979980b07dab50da1a8f572f9504674bfa853d484Chris Lattner Lo = DAG.getNode(ISD::ADDC, VTList, LoOps, 2); 5070bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner HiOps[2] = Lo.getValue(1); 507179980b07dab50da1a8f572f9504674bfa853d484Chris Lattner Hi = DAG.getNode(ISD::ADDE, VTList, HiOps, 3); 5072551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman } else { 507379980b07dab50da1a8f572f9504674bfa853d484Chris Lattner Lo = DAG.getNode(ISD::SUBC, VTList, LoOps, 2); 5074bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner HiOps[2] = Lo.getValue(1); 507579980b07dab50da1a8f572f9504674bfa853d484Chris Lattner Hi = DAG.getNode(ISD::SUBE, VTList, HiOps, 3); 5076551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman } 507784f6788044f9b1b47945e98ce23a6cf4d7d32579Chris Lattner break; 50788137c9e41d69943ac84066e6c7a95390b84e29f2Chris Lattner } 5079c7c16575fea9aeffe8a63ddabe7c3c25f81ed799Nate Begeman case ISD::MUL: { 50807d7bffe157c0896cc850ed384dd748aae1a00c7bChris Lattner // If the target wants to custom expand this, let them. 50817d7bffe157c0896cc850ed384dd748aae1a00c7bChris Lattner if (TLI.getOperationAction(ISD::MUL, VT) == TargetLowering::Custom) { 50828829dc88a8637fe588e299d96de394afc3ecc528Chris Lattner SDOperand New = TLI.LowerOperation(Op, DAG); 50838829dc88a8637fe588e299d96de394afc3ecc528Chris Lattner if (New.Val) { 50848829dc88a8637fe588e299d96de394afc3ecc528Chris Lattner ExpandOp(New, Lo, Hi); 50857d7bffe157c0896cc850ed384dd748aae1a00c7bChris Lattner break; 50867d7bffe157c0896cc850ed384dd748aae1a00c7bChris Lattner } 50877d7bffe157c0896cc850ed384dd748aae1a00c7bChris Lattner } 50887d7bffe157c0896cc850ed384dd748aae1a00c7bChris Lattner 50893f4fd0fd644faec87330ef17ebcb93acb74da9c6Evan Cheng bool HasMULHS = TLI.isOperationLegal(ISD::MULHS, NVT); 50903f4fd0fd644faec87330ef17ebcb93acb74da9c6Evan Cheng bool HasMULHU = TLI.isOperationLegal(ISD::MULHU, NVT); 50913f4fd0fd644faec87330ef17ebcb93acb74da9c6Evan Cheng if (HasMULHS || HasMULHU) { 5092c7c16575fea9aeffe8a63ddabe7c3c25f81ed799Nate Begeman SDOperand LL, LH, RL, RH; 5093c7c16575fea9aeffe8a63ddabe7c3c25f81ed799Nate Begeman ExpandOp(Node->getOperand(0), LL, LH); 5094c7c16575fea9aeffe8a63ddabe7c3c25f81ed799Nate Begeman ExpandOp(Node->getOperand(1), RL, RH); 509556eb86806d5d178d42108f17d11098b3e640b996Nate Begeman unsigned SH = MVT::getSizeInBits(RH.getValueType())-1; 50962cbba8934745fe30662f2d5a59d03545ad5212c5Nate Begeman // FIXME: Move this to the dag combiner. 509756eb86806d5d178d42108f17d11098b3e640b996Nate Begeman // MULHS implicitly sign extends its inputs. Check to see if ExpandOp 509856eb86806d5d178d42108f17d11098b3e640b996Nate Begeman // extended the sign bit of the low half through the upper half, and if so 509956eb86806d5d178d42108f17d11098b3e640b996Nate Begeman // emit a MULHS instead of the alternate sequence that is valid for any 510056eb86806d5d178d42108f17d11098b3e640b996Nate Begeman // i64 x i64 multiply. 51013f4fd0fd644faec87330ef17ebcb93acb74da9c6Evan Cheng if (HasMULHS && 510256eb86806d5d178d42108f17d11098b3e640b996Nate Begeman // is RH an extension of the sign bit of RL? 510356eb86806d5d178d42108f17d11098b3e640b996Nate Begeman RH.getOpcode() == ISD::SRA && RH.getOperand(0) == RL && 510456eb86806d5d178d42108f17d11098b3e640b996Nate Begeman RH.getOperand(1).getOpcode() == ISD::Constant && 510556eb86806d5d178d42108f17d11098b3e640b996Nate Begeman cast<ConstantSDNode>(RH.getOperand(1))->getValue() == SH && 510656eb86806d5d178d42108f17d11098b3e640b996Nate Begeman // is LH an extension of the sign bit of LL? 510756eb86806d5d178d42108f17d11098b3e640b996Nate Begeman LH.getOpcode() == ISD::SRA && LH.getOperand(0) == LL && 510856eb86806d5d178d42108f17d11098b3e640b996Nate Begeman LH.getOperand(1).getOpcode() == ISD::Constant && 510956eb86806d5d178d42108f17d11098b3e640b996Nate Begeman cast<ConstantSDNode>(LH.getOperand(1))->getValue() == SH) { 5110a89654b1a17478a272af33221e325b7feb9aec1bChris Lattner // Low part: 5111a89654b1a17478a272af33221e325b7feb9aec1bChris Lattner Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); 5112a89654b1a17478a272af33221e325b7feb9aec1bChris Lattner // High part: 511356eb86806d5d178d42108f17d11098b3e640b996Nate Begeman Hi = DAG.getNode(ISD::MULHS, NVT, LL, RL); 5114a89654b1a17478a272af33221e325b7feb9aec1bChris Lattner break; 51153f4fd0fd644faec87330ef17ebcb93acb74da9c6Evan Cheng } else if (HasMULHU) { 5116a89654b1a17478a272af33221e325b7feb9aec1bChris Lattner // Low part: 5117a89654b1a17478a272af33221e325b7feb9aec1bChris Lattner Lo = DAG.getNode(ISD::MUL, NVT, LL, RL); 5118a89654b1a17478a272af33221e325b7feb9aec1bChris Lattner 5119a89654b1a17478a272af33221e325b7feb9aec1bChris Lattner // High part: 512056eb86806d5d178d42108f17d11098b3e640b996Nate Begeman Hi = DAG.getNode(ISD::MULHU, NVT, LL, RL); 512156eb86806d5d178d42108f17d11098b3e640b996Nate Begeman RH = DAG.getNode(ISD::MUL, NVT, LL, RH); 512256eb86806d5d178d42108f17d11098b3e640b996Nate Begeman LH = DAG.getNode(ISD::MUL, NVT, LH, RL); 512356eb86806d5d178d42108f17d11098b3e640b996Nate Begeman Hi = DAG.getNode(ISD::ADD, NVT, Hi, RH); 512456eb86806d5d178d42108f17d11098b3e640b996Nate Begeman Hi = DAG.getNode(ISD::ADD, NVT, Hi, LH); 5125a89654b1a17478a272af33221e325b7feb9aec1bChris Lattner break; 512656eb86806d5d178d42108f17d11098b3e640b996Nate Begeman } 5127c7c16575fea9aeffe8a63ddabe7c3c25f81ed799Nate Begeman } 51283f4fd0fd644faec87330ef17ebcb93acb74da9c6Evan Cheng 512956966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::MUL_I64), Node, 513056966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng false/*sign irrelevant*/, Hi); 5131c7c16575fea9aeffe8a63ddabe7c3c25f81ed799Nate Begeman break; 5132c7c16575fea9aeffe8a63ddabe7c3c25f81ed799Nate Begeman } 513356966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng case ISD::SDIV: 513456966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SDIV_I64), Node, true, Hi); 513556966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng break; 513656966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng case ISD::UDIV: 513756966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::UDIV_I64), Node, true, Hi); 513856966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng break; 513956966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng case ISD::SREM: 514056966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::SREM_I64), Node, true, Hi); 514156966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng break; 514256966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng case ISD::UREM: 514356966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::UREM_I64), Node, true, Hi); 514456966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng break; 51455c9ce1893a4bee65bc05c7c48f11734f55405692Evan Cheng 51461a8f1fe676f1d83e0da7336e744ebcdcc14a88c4Evan Cheng case ISD::FADD: 514756966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Lo = ExpandLibCall(TLI.getLibcallName((VT == MVT::f32) 514856966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng ? RTLIB::ADD_F32 : RTLIB::ADD_F64), 514956966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Node, false, Hi); 51501a8f1fe676f1d83e0da7336e744ebcdcc14a88c4Evan Cheng break; 51511a8f1fe676f1d83e0da7336e744ebcdcc14a88c4Evan Cheng case ISD::FSUB: 515256966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Lo = ExpandLibCall(TLI.getLibcallName((VT == MVT::f32) 515356966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng ? RTLIB::SUB_F32 : RTLIB::SUB_F64), 515456966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Node, false, Hi); 51551a8f1fe676f1d83e0da7336e744ebcdcc14a88c4Evan Cheng break; 51561a8f1fe676f1d83e0da7336e744ebcdcc14a88c4Evan Cheng case ISD::FMUL: 515756966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Lo = ExpandLibCall(TLI.getLibcallName((VT == MVT::f32) 515856966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng ? RTLIB::MUL_F32 : RTLIB::MUL_F64), 515956966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Node, false, Hi); 51601a8f1fe676f1d83e0da7336e744ebcdcc14a88c4Evan Cheng break; 51611a8f1fe676f1d83e0da7336e744ebcdcc14a88c4Evan Cheng case ISD::FDIV: 516256966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Lo = ExpandLibCall(TLI.getLibcallName((VT == MVT::f32) 516356966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng ? RTLIB::DIV_F32 : RTLIB::DIV_F64), 516456966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Node, false, Hi); 51651a8f1fe676f1d83e0da7336e744ebcdcc14a88c4Evan Cheng break; 51661a8f1fe676f1d83e0da7336e744ebcdcc14a88c4Evan Cheng case ISD::FP_EXTEND: 516756966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::FPEXT_F32_F64), Node, true,Hi); 51681a8f1fe676f1d83e0da7336e744ebcdcc14a88c4Evan Cheng break; 51691a8f1fe676f1d83e0da7336e744ebcdcc14a88c4Evan Cheng case ISD::FP_ROUND: 517056966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Lo = ExpandLibCall(TLI.getLibcallName(RTLIB::FPROUND_F64_F32),Node,true,Hi); 51711a8f1fe676f1d83e0da7336e744ebcdcc14a88c4Evan Cheng break; 517298ff3b979af4916ba8a82eda7d77a66cdad31842Evan Cheng case ISD::FSQRT: 517398ff3b979af4916ba8a82eda7d77a66cdad31842Evan Cheng case ISD::FSIN: 517498ff3b979af4916ba8a82eda7d77a66cdad31842Evan Cheng case ISD::FCOS: { 517556966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; 517698ff3b979af4916ba8a82eda7d77a66cdad31842Evan Cheng switch(Node->getOpcode()) { 517756966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng case ISD::FSQRT: 517856966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC = (VT == MVT::f32) ? RTLIB::SQRT_F32 : RTLIB::SQRT_F64; 517956966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng break; 518056966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng case ISD::FSIN: 518156966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC = (VT == MVT::f32) ? RTLIB::SIN_F32 : RTLIB::SIN_F64; 518256966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng break; 518356966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng case ISD::FCOS: 518456966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC = (VT == MVT::f32) ? RTLIB::COS_F32 : RTLIB::COS_F64; 518556966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng break; 518698ff3b979af4916ba8a82eda7d77a66cdad31842Evan Cheng default: assert(0 && "Unreachable!"); 518798ff3b979af4916ba8a82eda7d77a66cdad31842Evan Cheng } 518856966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, false, Hi); 518998ff3b979af4916ba8a82eda7d77a66cdad31842Evan Cheng break; 519098ff3b979af4916ba8a82eda7d77a66cdad31842Evan Cheng } 5191966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng case ISD::FABS: { 5192966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng SDOperand Mask = (VT == MVT::f64) 5193966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng ? DAG.getConstantFP(BitsToDouble(~(1ULL << 63)), VT) 5194966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng : DAG.getConstantFP(BitsToFloat(~(1U << 31)), VT); 5195966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask); 5196966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); 5197966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng Lo = DAG.getNode(ISD::AND, NVT, Lo, Mask); 5198966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng if (getTypeAction(NVT) == Expand) 5199966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng ExpandOp(Lo, Lo, Hi); 5200966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng break; 5201966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng } 5202966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng case ISD::FNEG: { 5203966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng SDOperand Mask = (VT == MVT::f64) 5204966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng ? DAG.getConstantFP(BitsToDouble(1ULL << 63), VT) 5205966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng : DAG.getConstantFP(BitsToFloat(1U << 31), VT); 5206966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng Mask = DAG.getNode(ISD::BIT_CONVERT, NVT, Mask); 5207966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng Lo = DAG.getNode(ISD::BIT_CONVERT, NVT, Node->getOperand(0)); 5208966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng Lo = DAG.getNode(ISD::XOR, NVT, Lo, Mask); 5209966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng if (getTypeAction(NVT) == Expand) 5210966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng ExpandOp(Lo, Lo, Hi); 5211966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng break; 5212966bf24491f7e53238fc4127bb9fcf43e6739586Evan Cheng } 5213912095becac923ff614d7b07728eb345ada67765Evan Cheng case ISD::FCOPYSIGN: { 5214912095becac923ff614d7b07728eb345ada67765Evan Cheng Lo = ExpandFCOPYSIGNToBitwiseOps(Node, NVT, DAG, TLI); 5215912095becac923ff614d7b07728eb345ada67765Evan Cheng if (getTypeAction(NVT) == Expand) 5216912095becac923ff614d7b07728eb345ada67765Evan Cheng ExpandOp(Lo, Lo, Hi); 5217912095becac923ff614d7b07728eb345ada67765Evan Cheng break; 5218912095becac923ff614d7b07728eb345ada67765Evan Cheng } 52197df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng case ISD::SINT_TO_FP: 52207df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng case ISD::UINT_TO_FP: { 52217df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng bool isSigned = Node->getOpcode() == ISD::SINT_TO_FP; 52227df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng MVT::ValueType SrcVT = Node->getOperand(0).getValueType(); 522356966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng RTLIB::Libcall LC; 52247df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng if (Node->getOperand(0).getValueType() == MVT::i64) { 52257df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng if (VT == MVT::f32) 522656966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC = isSigned ? RTLIB::SINTTOFP_I64_F32 : RTLIB::UINTTOFP_I64_F32; 52277df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng else 522856966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC = isSigned ? RTLIB::SINTTOFP_I64_F64 : RTLIB::UINTTOFP_I64_F64; 52297df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng } else { 52307df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng if (VT == MVT::f32) 523156966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC = isSigned ? RTLIB::SINTTOFP_I32_F32 : RTLIB::UINTTOFP_I32_F32; 52327df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng else 523356966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng LC = isSigned ? RTLIB::SINTTOFP_I32_F64 : RTLIB::UINTTOFP_I32_F64; 52347df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng } 52357df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng 52367df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng // Promote the operand if needed. 52377df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng if (getTypeAction(SrcVT) == Promote) { 52387df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng SDOperand Tmp = PromoteOp(Node->getOperand(0)); 52397df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng Tmp = isSigned 52407df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng ? DAG.getNode(ISD::SIGN_EXTEND_INREG, Tmp.getValueType(), Tmp, 52417df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng DAG.getValueType(SrcVT)) 52427df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng : DAG.getZeroExtendInReg(Tmp, SrcVT); 52437df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng Node = DAG.UpdateNodeOperands(Op, Tmp).Val; 52447df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng } 524556966225d1eed9f9a6951d2167bfbbec9628c8d6Evan Cheng Lo = ExpandLibCall(TLI.getLibcallName(LC), Node, isSigned, Hi); 52467df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng break; 52477df28dc9d7160772c3c0aabd72c32830c1bb5e57Evan Cheng } 524898ff3b979af4916ba8a82eda7d77a66cdad31842Evan Cheng } 52493e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 525083397363348662e9352455ea1e6e88e7026300a4Chris Lattner // Make sure the resultant values have been legalized themselves, unless this 525183397363348662e9352455ea1e6e88e7026300a4Chris Lattner // is a type that requires multi-step expansion. 525283397363348662e9352455ea1e6e88e7026300a4Chris Lattner if (getTypeAction(NVT) != Expand && NVT != MVT::isVoid) { 525383397363348662e9352455ea1e6e88e7026300a4Chris Lattner Lo = LegalizeOp(Lo); 525413acce3ef03d29679c2b241bdba6ca015644e8b6Evan Cheng if (Hi.Val) 525513acce3ef03d29679c2b241bdba6ca015644e8b6Evan Cheng // Don't legalize the high part if it is expanded to a single node. 525613acce3ef03d29679c2b241bdba6ca015644e8b6Evan Cheng Hi = LegalizeOp(Hi); 525783397363348662e9352455ea1e6e88e7026300a4Chris Lattner } 525805a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng 525905a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng // Remember in a map if the values will be reused later. 526005a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng bool isNew = 526105a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng ExpandedNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))).second; 526205a2d568c60b8d547a5ac78f99107c476e6612b5Evan Cheng assert(isNew && "Value already expanded?!?"); 52633e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner} 52643e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 5265c7029805ef35ce9805931067b841e6af11db382eChris Lattner/// SplitVectorOp - Given an operand of MVT::Vector type, break it down into 5266c7029805ef35ce9805931067b841e6af11db382eChris Lattner/// two smaller values of MVT::Vector type. 5267c7029805ef35ce9805931067b841e6af11db382eChris Lattnervoid SelectionDAGLegalize::SplitVectorOp(SDOperand Op, SDOperand &Lo, 5268c7029805ef35ce9805931067b841e6af11db382eChris Lattner SDOperand &Hi) { 5269c7029805ef35ce9805931067b841e6af11db382eChris Lattner assert(Op.getValueType() == MVT::Vector && "Cannot split non-vector type!"); 5270c7029805ef35ce9805931067b841e6af11db382eChris Lattner SDNode *Node = Op.Val; 5271c7029805ef35ce9805931067b841e6af11db382eChris Lattner unsigned NumElements = cast<ConstantSDNode>(*(Node->op_end()-2))->getValue(); 5272c7029805ef35ce9805931067b841e6af11db382eChris Lattner assert(NumElements > 1 && "Cannot split a single element vector!"); 5273c7029805ef35ce9805931067b841e6af11db382eChris Lattner unsigned NewNumElts = NumElements/2; 5274c7029805ef35ce9805931067b841e6af11db382eChris Lattner SDOperand NewNumEltsNode = DAG.getConstant(NewNumElts, MVT::i32); 5275c7029805ef35ce9805931067b841e6af11db382eChris Lattner SDOperand TypeNode = *(Node->op_end()-1); 5276c7029805ef35ce9805931067b841e6af11db382eChris Lattner 5277c7029805ef35ce9805931067b841e6af11db382eChris Lattner // See if we already split it. 5278c7029805ef35ce9805931067b841e6af11db382eChris Lattner std::map<SDOperand, std::pair<SDOperand, SDOperand> >::iterator I 5279c7029805ef35ce9805931067b841e6af11db382eChris Lattner = SplitNodes.find(Op); 5280c7029805ef35ce9805931067b841e6af11db382eChris Lattner if (I != SplitNodes.end()) { 5281c7029805ef35ce9805931067b841e6af11db382eChris Lattner Lo = I->second.first; 5282c7029805ef35ce9805931067b841e6af11db382eChris Lattner Hi = I->second.second; 5283c7029805ef35ce9805931067b841e6af11db382eChris Lattner return; 5284c7029805ef35ce9805931067b841e6af11db382eChris Lattner } 5285c7029805ef35ce9805931067b841e6af11db382eChris Lattner 5286c7029805ef35ce9805931067b841e6af11db382eChris Lattner switch (Node->getOpcode()) { 5287e37fe9b3a1cadceb42ac27fa0718f5a10ea2f0e6Jim Laskey default: 5288e37fe9b3a1cadceb42ac27fa0718f5a10ea2f0e6Jim Laskey#ifndef NDEBUG 5289e37fe9b3a1cadceb42ac27fa0718f5a10ea2f0e6Jim Laskey Node->dump(); 5290e37fe9b3a1cadceb42ac27fa0718f5a10ea2f0e6Jim Laskey#endif 5291e37fe9b3a1cadceb42ac27fa0718f5a10ea2f0e6Jim Laskey assert(0 && "Unhandled operation in SplitVectorOp!"); 5292b2827b0901162169bb2692b77a839c9767849134Chris Lattner case ISD::VBUILD_VECTOR: { 5293bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner SmallVector<SDOperand, 8> LoOps(Node->op_begin(), 5294bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner Node->op_begin()+NewNumElts); 5295c7029805ef35ce9805931067b841e6af11db382eChris Lattner LoOps.push_back(NewNumEltsNode); 5296c7029805ef35ce9805931067b841e6af11db382eChris Lattner LoOps.push_back(TypeNode); 5297bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner Lo = DAG.getNode(ISD::VBUILD_VECTOR, MVT::Vector, &LoOps[0], LoOps.size()); 5298c7029805ef35ce9805931067b841e6af11db382eChris Lattner 5299bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner SmallVector<SDOperand, 8> HiOps(Node->op_begin()+NewNumElts, 5300bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner Node->op_end()-2); 5301c7029805ef35ce9805931067b841e6af11db382eChris Lattner HiOps.push_back(NewNumEltsNode); 5302c7029805ef35ce9805931067b841e6af11db382eChris Lattner HiOps.push_back(TypeNode); 5303bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner Hi = DAG.getNode(ISD::VBUILD_VECTOR, MVT::Vector, &HiOps[0], HiOps.size()); 5304c7029805ef35ce9805931067b841e6af11db382eChris Lattner break; 5305c7029805ef35ce9805931067b841e6af11db382eChris Lattner } 5306c7029805ef35ce9805931067b841e6af11db382eChris Lattner case ISD::VADD: 5307c7029805ef35ce9805931067b841e6af11db382eChris Lattner case ISD::VSUB: 5308c7029805ef35ce9805931067b841e6af11db382eChris Lattner case ISD::VMUL: 5309c7029805ef35ce9805931067b841e6af11db382eChris Lattner case ISD::VSDIV: 5310c7029805ef35ce9805931067b841e6af11db382eChris Lattner case ISD::VUDIV: 5311c7029805ef35ce9805931067b841e6af11db382eChris Lattner case ISD::VAND: 5312c7029805ef35ce9805931067b841e6af11db382eChris Lattner case ISD::VOR: 5313c7029805ef35ce9805931067b841e6af11db382eChris Lattner case ISD::VXOR: { 5314c7029805ef35ce9805931067b841e6af11db382eChris Lattner SDOperand LL, LH, RL, RH; 5315c7029805ef35ce9805931067b841e6af11db382eChris Lattner SplitVectorOp(Node->getOperand(0), LL, LH); 5316c7029805ef35ce9805931067b841e6af11db382eChris Lattner SplitVectorOp(Node->getOperand(1), RL, RH); 5317c7029805ef35ce9805931067b841e6af11db382eChris Lattner 5318c7029805ef35ce9805931067b841e6af11db382eChris Lattner Lo = DAG.getNode(Node->getOpcode(), MVT::Vector, LL, RL, 5319c7029805ef35ce9805931067b841e6af11db382eChris Lattner NewNumEltsNode, TypeNode); 5320c7029805ef35ce9805931067b841e6af11db382eChris Lattner Hi = DAG.getNode(Node->getOpcode(), MVT::Vector, LH, RH, 5321c7029805ef35ce9805931067b841e6af11db382eChris Lattner NewNumEltsNode, TypeNode); 5322c7029805ef35ce9805931067b841e6af11db382eChris Lattner break; 5323c7029805ef35ce9805931067b841e6af11db382eChris Lattner } 5324c7029805ef35ce9805931067b841e6af11db382eChris Lattner case ISD::VLOAD: { 5325c7029805ef35ce9805931067b841e6af11db382eChris Lattner SDOperand Ch = Node->getOperand(0); // Legalize the chain. 5326c7029805ef35ce9805931067b841e6af11db382eChris Lattner SDOperand Ptr = Node->getOperand(1); // Legalize the pointer. 5327c7029805ef35ce9805931067b841e6af11db382eChris Lattner MVT::ValueType EVT = cast<VTSDNode>(TypeNode)->getVT(); 5328c7029805ef35ce9805931067b841e6af11db382eChris Lattner 5329c7029805ef35ce9805931067b841e6af11db382eChris Lattner Lo = DAG.getVecLoad(NewNumElts, EVT, Ch, Ptr, Node->getOperand(2)); 5330c7029805ef35ce9805931067b841e6af11db382eChris Lattner unsigned IncrementSize = NewNumElts * MVT::getSizeInBits(EVT)/8; 5331c7029805ef35ce9805931067b841e6af11db382eChris Lattner Ptr = DAG.getNode(ISD::ADD, Ptr.getValueType(), Ptr, 5332c7029805ef35ce9805931067b841e6af11db382eChris Lattner getIntPtrConstant(IncrementSize)); 5333c7029805ef35ce9805931067b841e6af11db382eChris Lattner // FIXME: This creates a bogus srcvalue! 5334c7029805ef35ce9805931067b841e6af11db382eChris Lattner Hi = DAG.getVecLoad(NewNumElts, EVT, Ch, Ptr, Node->getOperand(2)); 5335c7029805ef35ce9805931067b841e6af11db382eChris Lattner 5336c7029805ef35ce9805931067b841e6af11db382eChris Lattner // Build a factor node to remember that this load is independent of the 5337c7029805ef35ce9805931067b841e6af11db382eChris Lattner // other one. 5338c7029805ef35ce9805931067b841e6af11db382eChris Lattner SDOperand TF = DAG.getNode(ISD::TokenFactor, MVT::Other, Lo.getValue(1), 5339c7029805ef35ce9805931067b841e6af11db382eChris Lattner Hi.getValue(1)); 5340c7029805ef35ce9805931067b841e6af11db382eChris Lattner 5341c7029805ef35ce9805931067b841e6af11db382eChris Lattner // Remember that we legalized the chain. 5342c7029805ef35ce9805931067b841e6af11db382eChris Lattner AddLegalizedOperand(Op.getValue(1), LegalizeOp(TF)); 5343c7029805ef35ce9805931067b841e6af11db382eChris Lattner break; 5344c7029805ef35ce9805931067b841e6af11db382eChris Lattner } 53457692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner case ISD::VBIT_CONVERT: { 53467692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner // We know the result is a vector. The input may be either a vector or a 53477692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner // scalar value. 53487692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner if (Op.getOperand(0).getValueType() != MVT::Vector) { 53497692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner // Lower to a store/load. FIXME: this could be improved probably. 53507692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner SDOperand Ptr = CreateStackTemporary(Op.getOperand(0).getValueType()); 53517692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner 5352786225adf09e606c795ef68a1f789c12f37869f2Evan Cheng SDOperand St = DAG.getStore(DAG.getEntryNode(), 53538b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng Op.getOperand(0), Ptr, NULL, 0); 53547692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner MVT::ValueType EVT = cast<VTSDNode>(TypeNode)->getVT(); 53557692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner St = DAG.getVecLoad(NumElements, EVT, St, Ptr, DAG.getSrcValue(0)); 53567692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner SplitVectorOp(St, Lo, Hi); 53577692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner } else { 53587692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner // If the input is a vector type, we have to either scalarize it, pack it 53597692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner // or convert it based on whether the input vector type is legal. 53607692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner SDNode *InVal = Node->getOperand(0).Val; 53617692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner unsigned NumElems = 53627692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner cast<ConstantSDNode>(*(InVal->op_end()-2))->getValue(); 53637692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner MVT::ValueType EVT = cast<VTSDNode>(*(InVal->op_end()-1))->getVT(); 53647692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner 53657692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner // If the input is from a single element vector, scalarize the vector, 53667692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner // then treat like a scalar. 53677692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner if (NumElems == 1) { 53687692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner SDOperand Scalar = PackVectorOp(Op.getOperand(0), EVT); 53697692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner Scalar = DAG.getNode(ISD::VBIT_CONVERT, MVT::Vector, Scalar, 53707692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner Op.getOperand(1), Op.getOperand(2)); 53717692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner SplitVectorOp(Scalar, Lo, Hi); 53727692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner } else { 53737692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner // Split the input vector. 53747692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner SplitVectorOp(Op.getOperand(0), Lo, Hi); 53757692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner 53767692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner // Convert each of the pieces now. 53777692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner Lo = DAG.getNode(ISD::VBIT_CONVERT, MVT::Vector, Lo, 53787692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner NewNumEltsNode, TypeNode); 53797692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner Hi = DAG.getNode(ISD::VBIT_CONVERT, MVT::Vector, Hi, 53807692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner NewNumEltsNode, TypeNode); 53817692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner } 53827692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner break; 53837692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner } 53847692eb4201e2071fb2afddcdaa6ba93b5e6abad4Chris Lattner } 5385c7029805ef35ce9805931067b841e6af11db382eChris Lattner } 5386c7029805ef35ce9805931067b841e6af11db382eChris Lattner 5387c7029805ef35ce9805931067b841e6af11db382eChris Lattner // Remember in a map if the values will be reused later. 5388c7029805ef35ce9805931067b841e6af11db382eChris Lattner bool isNew = 5389c7029805ef35ce9805931067b841e6af11db382eChris Lattner SplitNodes.insert(std::make_pair(Op, std::make_pair(Lo, Hi))).second; 5390c7029805ef35ce9805931067b841e6af11db382eChris Lattner assert(isNew && "Value already expanded?!?"); 5391c7029805ef35ce9805931067b841e6af11db382eChris Lattner} 5392c7029805ef35ce9805931067b841e6af11db382eChris Lattner 5393c7029805ef35ce9805931067b841e6af11db382eChris Lattner 5394c7029805ef35ce9805931067b841e6af11db382eChris Lattner/// PackVectorOp - Given an operand of MVT::Vector type, convert it into the 5395c7029805ef35ce9805931067b841e6af11db382eChris Lattner/// equivalent operation that returns a scalar (e.g. F32) or packed value 5396c7029805ef35ce9805931067b841e6af11db382eChris Lattner/// (e.g. MVT::V4F32). When this is called, we know that PackedVT is the right 5397c7029805ef35ce9805931067b841e6af11db382eChris Lattner/// type for the result. 5398c7029805ef35ce9805931067b841e6af11db382eChris LattnerSDOperand SelectionDAGLegalize::PackVectorOp(SDOperand Op, 5399c7029805ef35ce9805931067b841e6af11db382eChris Lattner MVT::ValueType NewVT) { 5400c7029805ef35ce9805931067b841e6af11db382eChris Lattner assert(Op.getValueType() == MVT::Vector && "Bad PackVectorOp invocation!"); 5401c7029805ef35ce9805931067b841e6af11db382eChris Lattner SDNode *Node = Op.Val; 5402c7029805ef35ce9805931067b841e6af11db382eChris Lattner 5403c7029805ef35ce9805931067b841e6af11db382eChris Lattner // See if we already packed it. 5404c7029805ef35ce9805931067b841e6af11db382eChris Lattner std::map<SDOperand, SDOperand>::iterator I = PackedNodes.find(Op); 5405c7029805ef35ce9805931067b841e6af11db382eChris Lattner if (I != PackedNodes.end()) return I->second; 5406c7029805ef35ce9805931067b841e6af11db382eChris Lattner 5407c7029805ef35ce9805931067b841e6af11db382eChris Lattner SDOperand Result; 5408c7029805ef35ce9805931067b841e6af11db382eChris Lattner switch (Node->getOpcode()) { 54092332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner default: 5410e37fe9b3a1cadceb42ac27fa0718f5a10ea2f0e6Jim Laskey#ifndef NDEBUG 5411832171cb9724d2d31c8dfb73172e2be8f6dd13eeBill Wendling Node->dump(); cerr << "\n"; 5412e37fe9b3a1cadceb42ac27fa0718f5a10ea2f0e6Jim Laskey#endif 54132332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner assert(0 && "Unknown vector operation in PackVectorOp!"); 5414c7029805ef35ce9805931067b841e6af11db382eChris Lattner case ISD::VADD: 5415c7029805ef35ce9805931067b841e6af11db382eChris Lattner case ISD::VSUB: 5416c7029805ef35ce9805931067b841e6af11db382eChris Lattner case ISD::VMUL: 5417c7029805ef35ce9805931067b841e6af11db382eChris Lattner case ISD::VSDIV: 5418c7029805ef35ce9805931067b841e6af11db382eChris Lattner case ISD::VUDIV: 5419c7029805ef35ce9805931067b841e6af11db382eChris Lattner case ISD::VAND: 5420c7029805ef35ce9805931067b841e6af11db382eChris Lattner case ISD::VOR: 5421c7029805ef35ce9805931067b841e6af11db382eChris Lattner case ISD::VXOR: 5422c7029805ef35ce9805931067b841e6af11db382eChris Lattner Result = DAG.getNode(getScalarizedOpcode(Node->getOpcode(), NewVT), 5423c7029805ef35ce9805931067b841e6af11db382eChris Lattner NewVT, 5424c7029805ef35ce9805931067b841e6af11db382eChris Lattner PackVectorOp(Node->getOperand(0), NewVT), 5425c7029805ef35ce9805931067b841e6af11db382eChris Lattner PackVectorOp(Node->getOperand(1), NewVT)); 5426c7029805ef35ce9805931067b841e6af11db382eChris Lattner break; 5427c7029805ef35ce9805931067b841e6af11db382eChris Lattner case ISD::VLOAD: { 54284794a6b6a09e3440438cd653ec09cf0c2e45be1cChris Lattner SDOperand Ch = LegalizeOp(Node->getOperand(0)); // Legalize the chain. 54294794a6b6a09e3440438cd653ec09cf0c2e45be1cChris Lattner SDOperand Ptr = LegalizeOp(Node->getOperand(1)); // Legalize the pointer. 5430c7029805ef35ce9805931067b841e6af11db382eChris Lattner 5431466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng SrcValueSDNode *SV = cast<SrcValueSDNode>(Node->getOperand(2)); 5432466685d41a9ea4905b9486fea38e83802e46f196Evan Cheng Result = DAG.getLoad(NewVT, Ch, Ptr, SV->getValue(), SV->getOffset()); 5433c7029805ef35ce9805931067b841e6af11db382eChris Lattner 5434c7029805ef35ce9805931067b841e6af11db382eChris Lattner // Remember that we legalized the chain. 5435c7029805ef35ce9805931067b841e6af11db382eChris Lattner AddLegalizedOperand(Op.getValue(1), LegalizeOp(Result.getValue(1))); 5436c7029805ef35ce9805931067b841e6af11db382eChris Lattner break; 5437c7029805ef35ce9805931067b841e6af11db382eChris Lattner } 5438b2827b0901162169bb2692b77a839c9767849134Chris Lattner case ISD::VBUILD_VECTOR: 543970c2a61e0a0fb0a7e8b9bddd26bdcc92762772f0Chris Lattner if (Node->getOperand(0).getValueType() == NewVT) { 5440b2827b0901162169bb2692b77a839c9767849134Chris Lattner // Returning a scalar? 5441c7029805ef35ce9805931067b841e6af11db382eChris Lattner Result = Node->getOperand(0); 5442c7029805ef35ce9805931067b841e6af11db382eChris Lattner } else { 5443b2827b0901162169bb2692b77a839c9767849134Chris Lattner // Returning a BUILD_VECTOR? 544417614ea63db9189050b6ca0310f535d12bdedb81Chris Lattner 544517614ea63db9189050b6ca0310f535d12bdedb81Chris Lattner // If all elements of the build_vector are undefs, return an undef. 544617614ea63db9189050b6ca0310f535d12bdedb81Chris Lattner bool AllUndef = true; 544717614ea63db9189050b6ca0310f535d12bdedb81Chris Lattner for (unsigned i = 0, e = Node->getNumOperands()-2; i != e; ++i) 544817614ea63db9189050b6ca0310f535d12bdedb81Chris Lattner if (Node->getOperand(i).getOpcode() != ISD::UNDEF) { 544917614ea63db9189050b6ca0310f535d12bdedb81Chris Lattner AllUndef = false; 545017614ea63db9189050b6ca0310f535d12bdedb81Chris Lattner break; 545117614ea63db9189050b6ca0310f535d12bdedb81Chris Lattner } 545217614ea63db9189050b6ca0310f535d12bdedb81Chris Lattner if (AllUndef) { 545317614ea63db9189050b6ca0310f535d12bdedb81Chris Lattner Result = DAG.getNode(ISD::UNDEF, NewVT); 545417614ea63db9189050b6ca0310f535d12bdedb81Chris Lattner } else { 5455bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner Result = DAG.getNode(ISD::BUILD_VECTOR, NewVT, Node->op_begin(), 5456bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner Node->getNumOperands()-2); 545717614ea63db9189050b6ca0310f535d12bdedb81Chris Lattner } 5458c7029805ef35ce9805931067b841e6af11db382eChris Lattner } 5459c7029805ef35ce9805931067b841e6af11db382eChris Lattner break; 54602332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner case ISD::VINSERT_VECTOR_ELT: 54612332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner if (!MVT::isVector(NewVT)) { 54622332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner // Returning a scalar? Must be the inserted element. 54632332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner Result = Node->getOperand(1); 54642332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner } else { 54652332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner Result = DAG.getNode(ISD::INSERT_VECTOR_ELT, NewVT, 54662332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner PackVectorOp(Node->getOperand(0), NewVT), 54672332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner Node->getOperand(1), Node->getOperand(2)); 54682332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner } 54692332b9f16fe17d1886566729b2241b8cd90f9916Chris Lattner break; 54705b2316e2b06e0fb6aea31d9d3eb61376b40c23a6Chris Lattner case ISD::VVECTOR_SHUFFLE: 54715b2316e2b06e0fb6aea31d9d3eb61376b40c23a6Chris Lattner if (!MVT::isVector(NewVT)) { 54725b2316e2b06e0fb6aea31d9d3eb61376b40c23a6Chris Lattner // Returning a scalar? Figure out if it is the LHS or RHS and return it. 54735b2316e2b06e0fb6aea31d9d3eb61376b40c23a6Chris Lattner SDOperand EltNum = Node->getOperand(2).getOperand(0); 54745b2316e2b06e0fb6aea31d9d3eb61376b40c23a6Chris Lattner if (cast<ConstantSDNode>(EltNum)->getValue()) 54755b2316e2b06e0fb6aea31d9d3eb61376b40c23a6Chris Lattner Result = PackVectorOp(Node->getOperand(1), NewVT); 54765b2316e2b06e0fb6aea31d9d3eb61376b40c23a6Chris Lattner else 54775b2316e2b06e0fb6aea31d9d3eb61376b40c23a6Chris Lattner Result = PackVectorOp(Node->getOperand(0), NewVT); 54785b2316e2b06e0fb6aea31d9d3eb61376b40c23a6Chris Lattner } else { 54795b2316e2b06e0fb6aea31d9d3eb61376b40c23a6Chris Lattner // Otherwise, return a VECTOR_SHUFFLE node. First convert the index 54805b2316e2b06e0fb6aea31d9d3eb61376b40c23a6Chris Lattner // vector from a VBUILD_VECTOR to a BUILD_VECTOR. 54815b2316e2b06e0fb6aea31d9d3eb61376b40c23a6Chris Lattner std::vector<SDOperand> BuildVecIdx(Node->getOperand(2).Val->op_begin(), 54825b2316e2b06e0fb6aea31d9d3eb61376b40c23a6Chris Lattner Node->getOperand(2).Val->op_end()-2); 54835b2316e2b06e0fb6aea31d9d3eb61376b40c23a6Chris Lattner MVT::ValueType BVT = MVT::getIntVectorWithNumElements(BuildVecIdx.size()); 5484bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner SDOperand BV = DAG.getNode(ISD::BUILD_VECTOR, BVT, 5485bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner Node->getOperand(2).Val->op_begin(), 5486bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner Node->getOperand(2).Val->getNumOperands()-2); 54875b2316e2b06e0fb6aea31d9d3eb61376b40c23a6Chris Lattner 54885b2316e2b06e0fb6aea31d9d3eb61376b40c23a6Chris Lattner Result = DAG.getNode(ISD::VECTOR_SHUFFLE, NewVT, 54895b2316e2b06e0fb6aea31d9d3eb61376b40c23a6Chris Lattner PackVectorOp(Node->getOperand(0), NewVT), 54905b2316e2b06e0fb6aea31d9d3eb61376b40c23a6Chris Lattner PackVectorOp(Node->getOperand(1), NewVT), BV); 54915b2316e2b06e0fb6aea31d9d3eb61376b40c23a6Chris Lattner } 54925b2316e2b06e0fb6aea31d9d3eb61376b40c23a6Chris Lattner break; 5493e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner case ISD::VBIT_CONVERT: 5494e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner if (Op.getOperand(0).getValueType() != MVT::Vector) 5495e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner Result = DAG.getNode(ISD::BIT_CONVERT, NewVT, Op.getOperand(0)); 5496e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner else { 5497e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner // If the input is a vector type, we have to either scalarize it, pack it 5498e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner // or convert it based on whether the input vector type is legal. 5499e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner SDNode *InVal = Node->getOperand(0).Val; 5500e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner unsigned NumElems = 5501e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner cast<ConstantSDNode>(*(InVal->op_end()-2))->getValue(); 5502e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner MVT::ValueType EVT = cast<VTSDNode>(*(InVal->op_end()-1))->getVT(); 5503e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner 5504e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner // Figure out if there is a Packed type corresponding to this Vector 5505e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner // type. If so, convert to the packed type. 5506e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner MVT::ValueType TVT = MVT::getVectorType(EVT, NumElems); 5507e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner if (TVT != MVT::Other && TLI.isTypeLegal(TVT)) { 5508e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner // Turn this into a bit convert of the packed input. 5509e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner Result = DAG.getNode(ISD::BIT_CONVERT, NewVT, 5510e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner PackVectorOp(Node->getOperand(0), TVT)); 5511e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner break; 5512e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner } else if (NumElems == 1) { 5513e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner // Turn this into a bit convert of the scalar input. 5514e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner Result = DAG.getNode(ISD::BIT_CONVERT, NewVT, 5515e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner PackVectorOp(Node->getOperand(0), EVT)); 5516e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner break; 5517e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner } else { 5518e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner // FIXME: UNIMP! 5519e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner assert(0 && "Cast from unsupported vector type not implemented yet!"); 5520e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner } 5521e25ca692c0478af5e15170fce23cea2a5b5fd0b9Chris Lattner } 5522db3c626eb9e85e9192dbee59ff0c4d143c37c94dEvan Cheng break; 5523b22e35a3c3bec07f5559c1476b3143e0d6d64269Chris Lattner case ISD::VSELECT: 5524b22e35a3c3bec07f5559c1476b3143e0d6d64269Chris Lattner Result = DAG.getNode(ISD::SELECT, NewVT, Op.getOperand(0), 5525b22e35a3c3bec07f5559c1476b3143e0d6d64269Chris Lattner PackVectorOp(Op.getOperand(1), NewVT), 5526b22e35a3c3bec07f5559c1476b3143e0d6d64269Chris Lattner PackVectorOp(Op.getOperand(2), NewVT)); 5527b22e35a3c3bec07f5559c1476b3143e0d6d64269Chris Lattner break; 5528c7029805ef35ce9805931067b841e6af11db382eChris Lattner } 5529c7029805ef35ce9805931067b841e6af11db382eChris Lattner 5530c7029805ef35ce9805931067b841e6af11db382eChris Lattner if (TLI.isTypeLegal(NewVT)) 5531c7029805ef35ce9805931067b841e6af11db382eChris Lattner Result = LegalizeOp(Result); 5532c7029805ef35ce9805931067b841e6af11db382eChris Lattner bool isNew = PackedNodes.insert(std::make_pair(Op, Result)).second; 5533c7029805ef35ce9805931067b841e6af11db382eChris Lattner assert(isNew && "Value already packed?"); 5534c7029805ef35ce9805931067b841e6af11db382eChris Lattner return Result; 5535c7029805ef35ce9805931067b841e6af11db382eChris Lattner} 5536c7029805ef35ce9805931067b841e6af11db382eChris Lattner 55373e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 55383e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner// SelectionDAG::Legalize - This is the entry point for the file. 55393e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner// 55409c32d3b798dc6caeebe6cea2effe80ca5e84e66eChris Lattnervoid SelectionDAG::Legalize() { 55415e46a19ec848cd4fc9649bd5170c43d9e657668cChris Lattner if (ViewLegalizeDAGs) viewGraph(); 55425e46a19ec848cd4fc9649bd5170c43d9e657668cChris Lattner 55433e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner /// run - This is the main entry point to this class. 55443e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner /// 5545456a93afcec7740c45cafa8354317f7b17987a6dChris Lattner SelectionDAGLegalize(*this).LegalizeDAG(); 55463e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner} 55473e928bbd6153eb08641cbd0ad7d8487378a8b12aChris Lattner 5548