1 //===-- LegalizeTypesSplit.cpp - Vector Splitting for LegalizeTypes -------===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
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.
15 //===----------------------------------------------------------------------===//
17 #include "LegalizeTypes.h"
20 //===----------------------------------------------------------------------===//
21 // Result Vector Splitting
22 //===----------------------------------------------------------------------===//
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
29 void DAGTypeLegalizer::SplitResult(SDNode *N, unsigned ResNo) {
30 DEBUG(cerr << "Expand node result: "; N->dump(&DAG); cerr << "\n");
32 Lo = Hi = SDOperand();
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);
48 switch (N->getOpcode()) {
51 cerr << "SplitResult #" << ResNo << ": ";
52 N->dump(&DAG); cerr << "\n";
54 assert(0 && "Do not know how to split the result of this operator!");
58 case ISD::UNDEF: SplitResult_UNDEF(N, Lo, Hi); break;
62 // If Lo/Hi is null, the sub-method took care of registering results etc.
64 SetSplitOp(SDOperand(N, ResNo), Lo, Hi);
68 //===----------------------------------------------------------------------===//
69 // Operand Vector Splitting
70 //===----------------------------------------------------------------------===//
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");
81 if (TLI.getOperationAction(N->getOpcode(), N->getValueType(0)) ==
82 TargetLowering::Custom)
83 Res = TLI.LowerOperation(SDOperand(N, 0), DAG);
87 switch (N->getOpcode()) {
90 cerr << "SplitOperand Op #" << OpNo << ": ";
91 N->dump(&DAG); cerr << "\n";
93 assert(0 && "Do not know how to split this operator's operand!");
97 Res = ExpandOperand_STORE(cast<StoreSDNode>(N), OpNo);
103 // If the result is null, the sub-method took care of registering results etc.
104 if (!Res.Val) return false;
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.
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);
117 assert(Res.getValueType() == N->getValueType(0) && N->getNumValues() == 1 &&
118 "Invalid operand expansion");
120 ReplaceValueWith(SDOperand(N, 0), Res);