add scaffolding for splitting of vectors.
[oota-llvm.git] / lib / CodeGen / SelectionDAG / LegalizeTypesSplit.cpp
1 //===-- LegalizeTypesSplit.cpp - Vector Splitting for LegalizeTypes -------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Chris Lattner and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements vector splitting support for LegalizeTypes.  Vector
11 // splitting is the act of changing a computation in an invalid vector type to
12 // be a computation in multiple vectors of a smaller type.  For example,
13 // implementing <128 x f32> operations in terms of two <64 x f32> operations.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #include "LegalizeTypes.h"
18 using namespace llvm;
19
20 //===----------------------------------------------------------------------===//
21 //  Result Vector Splitting
22 //===----------------------------------------------------------------------===//
23
24 /// SplitResult - This method is called when the specified result of the
25 /// specified node is found to need vector splitting.  At this point, the node
26 /// may also have invalid operands or may have other results that need
27 /// legalization, we just know that (at least) one result needs vector
28 /// splitting.
29 void DAGTypeLegalizer::SplitResult(SDNode *N, unsigned ResNo) {
30   DEBUG(cerr << "Expand node result: "; N->dump(&DAG); cerr << "\n");
31   SDOperand Lo, Hi;
32   Lo = Hi = SDOperand();
33   
34 #if 0
35   // See if the target wants to custom expand this node.
36   if (TLI.getOperationAction(N->getOpcode(), N->getValueType(0)) == 
37       TargetLowering::Custom) {
38     // If the target wants to, allow it to lower this itself.
39     if (SDNode *P = TLI.ExpandOperationResult(N, DAG)) {
40       // Everything that once used N now uses P.  We are guaranteed that the
41       // result value types of N and the result value types of P match.
42       ReplaceNodeWith(N, P);
43       return;
44     }
45   }
46 #endif
47   
48   switch (N->getOpcode()) {
49   default:
50 #ifndef NDEBUG
51     cerr << "SplitResult #" << ResNo << ": ";
52     N->dump(&DAG); cerr << "\n";
53 #endif
54     assert(0 && "Do not know how to split the result of this operator!");
55     abort();
56     
57 #if 0
58   case ISD::UNDEF:       SplitResult_UNDEF(N, Lo, Hi); break;
59 #endif
60   }
61   
62   // If Lo/Hi is null, the sub-method took care of registering results etc.
63   if (Lo.Val)
64     SetSplitOp(SDOperand(N, ResNo), Lo, Hi);
65 }
66
67
68 //===----------------------------------------------------------------------===//
69 //  Operand Vector Splitting
70 //===----------------------------------------------------------------------===//
71
72 /// SplitOperand - This method is called when the specified operand of the
73 /// specified node is found to need vector splitting.  At this point, all of the
74 /// result types of the node are known to be legal, but other operands of the
75 /// node may need legalization as well as the specified one.
76 bool DAGTypeLegalizer::SplitOperand(SDNode *N, unsigned OpNo) {
77   DEBUG(cerr << "Split node operand: "; N->dump(&DAG); cerr << "\n");
78   SDOperand Res(0, 0);
79   
80 #if 0
81   if (TLI.getOperationAction(N->getOpcode(), N->getValueType(0)) == 
82       TargetLowering::Custom)
83     Res = TLI.LowerOperation(SDOperand(N, 0), DAG);
84 #endif
85   
86   if (Res.Val == 0) {
87     switch (N->getOpcode()) {
88     default:
89 #ifndef NDEBUG
90       cerr << "SplitOperand Op #" << OpNo << ": ";
91       N->dump(&DAG); cerr << "\n";
92 #endif
93       assert(0 && "Do not know how to split this operator's operand!");
94       abort();
95 #if 0
96     case ISD::STORE:
97       Res = ExpandOperand_STORE(cast<StoreSDNode>(N), OpNo);
98       break;
99 #endif
100     }
101   }
102   
103   // If the result is null, the sub-method took care of registering results etc.
104   if (!Res.Val) return false;
105   
106   // If the result is N, the sub-method updated N in place.  Check to see if any
107   // operands are new, and if so, mark them.
108   if (Res.Val == N) {
109     // Mark N as new and remark N and its operands.  This allows us to correctly
110     // revisit N if it needs another step of promotion and allows us to visit
111     // any new operands to N.
112     N->setNodeId(NewNode);
113     MarkNewNodes(N);
114     return true;
115   }
116   
117   assert(Res.getValueType() == N->getValueType(0) && N->getNumValues() == 1 &&
118          "Invalid operand expansion");
119   
120   ReplaceValueWith(SDOperand(N, 0), Res);
121   return false;
122 }