mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-27 16:17:17 +00:00
Implement framework for scalarizing node results. This is sufficient
to codegen this: define float @test_extract_elt(<1 x float> * %P) { %p = load <1 x float>* %P %R = extractelement <1 x float> %p, i32 0 ret float %R } git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44570 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -202,6 +202,11 @@ private:
|
|||||||
SDOperand &Lo, SDOperand &Hi);
|
SDOperand &Lo, SDOperand &Hi);
|
||||||
bool ExpandShiftWithKnownAmountBit(SDNode *N, SDOperand &Lo, SDOperand &Hi);
|
bool ExpandShiftWithKnownAmountBit(SDNode *N, SDOperand &Lo, SDOperand &Hi);
|
||||||
|
|
||||||
|
// Result Vector Scalarization: <1 x ty> -> ty.
|
||||||
|
void ScalarizeResult(SDNode *N, unsigned OpNo);
|
||||||
|
SDOperand ScalarizeRes_UNDEF(SDNode *N);
|
||||||
|
SDOperand ScalarizeRes_LOAD(LoadSDNode *N);
|
||||||
|
|
||||||
// Operand Promotion.
|
// Operand Promotion.
|
||||||
bool PromoteOperand(SDNode *N, unsigned OperandNo);
|
bool PromoteOperand(SDNode *N, unsigned OperandNo);
|
||||||
SDOperand PromoteOperand_ANY_EXTEND(SDNode *N);
|
SDOperand PromoteOperand_ANY_EXTEND(SDNode *N);
|
||||||
@@ -232,7 +237,7 @@ private:
|
|||||||
void ExpandSetCCOperands(SDOperand &NewLHS, SDOperand &NewRHS,
|
void ExpandSetCCOperands(SDOperand &NewLHS, SDOperand &NewRHS,
|
||||||
ISD::CondCode &CCCode);
|
ISD::CondCode &CCCode);
|
||||||
|
|
||||||
// Operand Vector Scalarization <1 x ty> -> ty.
|
// Operand Vector Scalarization: <1 x ty> -> ty.
|
||||||
bool ScalarizeOperand(SDNode *N, unsigned OpNo);
|
bool ScalarizeOperand(SDNode *N, unsigned OpNo);
|
||||||
SDOperand ScalarizeOp_EXTRACT_VECTOR_ELT(SDNode *N, unsigned OpNo);
|
SDOperand ScalarizeOp_EXTRACT_VECTOR_ELT(SDNode *N, unsigned OpNo);
|
||||||
|
|
||||||
@@ -278,12 +283,20 @@ void DAGTypeLegalizer::run() {
|
|||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
unsigned NumResults = N->getNumValues();
|
unsigned NumResults = N->getNumValues();
|
||||||
do {
|
do {
|
||||||
LegalizeAction Action = getTypeAction(N->getValueType(i));
|
MVT::ValueType ResultVT = N->getValueType(i);
|
||||||
|
LegalizeAction Action = getTypeAction(ResultVT);
|
||||||
if (Action == Promote) {
|
if (Action == Promote) {
|
||||||
PromoteResult(N, i);
|
PromoteResult(N, i);
|
||||||
goto NodeDone;
|
goto NodeDone;
|
||||||
} else if (Action == Expand) {
|
} else if (Action == Expand) {
|
||||||
|
// Expand can mean 1) split integer in half 2) scalarize single-element
|
||||||
|
// vector 3) split vector in half.
|
||||||
|
if (!MVT::isVector(ResultVT))
|
||||||
ExpandResult(N, i);
|
ExpandResult(N, i);
|
||||||
|
else if (MVT::getVectorNumElements(ResultVT) == 1)
|
||||||
|
ScalarizeResult(N, i); // Scalarize the single-element vector.
|
||||||
|
else // Split the vector in half.
|
||||||
|
assert(0 && "Vector splitting not implemented");
|
||||||
goto NodeDone;
|
goto NodeDone;
|
||||||
} else {
|
} else {
|
||||||
assert(Action == Legal && "Unknown action!");
|
assert(Action == Legal && "Unknown action!");
|
||||||
@@ -306,16 +319,13 @@ void DAGTypeLegalizer::run() {
|
|||||||
// vector 3) split vector in half.
|
// vector 3) split vector in half.
|
||||||
if (!MVT::isVector(OpVT)) {
|
if (!MVT::isVector(OpVT)) {
|
||||||
NeedsRevisit = ExpandOperand(N, i);
|
NeedsRevisit = ExpandOperand(N, i);
|
||||||
} else {
|
} else if (MVT::getVectorNumElements(OpVT) == 1) {
|
||||||
unsigned NumElts = MVT::getVectorNumElements(OpVT);
|
|
||||||
if (NumElts == 1) {
|
|
||||||
// Scalarize the single-element vector.
|
// Scalarize the single-element vector.
|
||||||
NeedsRevisit = ScalarizeOperand(N, i);
|
NeedsRevisit = ScalarizeOperand(N, i);
|
||||||
} else {
|
} else {
|
||||||
// Split the vector in half.
|
// Split the vector in half.
|
||||||
assert(0 && "Vector splitting not implemented");
|
assert(0 && "Vector splitting not implemented");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
assert(Action == Legal && "Unknown action!");
|
assert(Action == Legal && "Unknown action!");
|
||||||
@@ -1584,6 +1594,65 @@ ExpandShiftWithKnownAmountBit(SDNode *N, SDOperand &Lo, SDOperand &Hi) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// Result Vector Scalarization: <1 x ty> -> ty.
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
|
||||||
|
void DAGTypeLegalizer::ScalarizeResult(SDNode *N, unsigned ResNo) {
|
||||||
|
DEBUG(cerr << "Scalarize node result " << ResNo << ": "; N->dump(&DAG);
|
||||||
|
cerr << "\n");
|
||||||
|
SDOperand R = SDOperand();
|
||||||
|
|
||||||
|
// FIXME: Custom lowering for scalarization?
|
||||||
|
#if 0
|
||||||
|
// See if the target wants to custom expand this node.
|
||||||
|
if (TLI.getOperationAction(N->getOpcode(), N->getValueType(0)) ==
|
||||||
|
TargetLowering::Custom) {
|
||||||
|
// If the target wants to, allow it to lower this itself.
|
||||||
|
if (SDNode *P = TLI.ExpandOperationResult(N, DAG)) {
|
||||||
|
// Everything that once used N now uses P. We are guaranteed that the
|
||||||
|
// result value types of N and the result value types of P match.
|
||||||
|
ReplaceNodeWith(N, P);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
switch (N->getOpcode()) {
|
||||||
|
default:
|
||||||
|
#ifndef NDEBUG
|
||||||
|
cerr << "ScalarizeResult #" << ResNo << ": ";
|
||||||
|
N->dump(&DAG); cerr << "\n";
|
||||||
|
#endif
|
||||||
|
assert(0 && "Do not know how to expand the result of this operator!");
|
||||||
|
abort();
|
||||||
|
|
||||||
|
case ISD::UNDEF: R = ScalarizeRes_UNDEF(N); break;
|
||||||
|
case ISD::LOAD: R = ScalarizeRes_LOAD(cast<LoadSDNode>(N)); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If R is null, the sub-method took care of registering the resul.
|
||||||
|
if (R.Val)
|
||||||
|
SetScalarizedOp(SDOperand(N, ResNo), R);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDOperand DAGTypeLegalizer::ScalarizeRes_UNDEF(SDNode *N) {
|
||||||
|
return DAG.getNode(ISD::UNDEF, MVT::getVectorElementType(N->getValueType(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
SDOperand DAGTypeLegalizer::ScalarizeRes_LOAD(LoadSDNode *N) {
|
||||||
|
SDOperand Result = DAG.getLoad(MVT::getVectorElementType(N->getValueType(0)),
|
||||||
|
N->getChain(), N->getBasePtr(),
|
||||||
|
N->getSrcValue(), N->getSrcValueOffset(),
|
||||||
|
N->isVolatile(), N->getAlignment());
|
||||||
|
|
||||||
|
// Legalized the chain result - switch anything that used the old chain to
|
||||||
|
// use the new one.
|
||||||
|
ReplaceValueWith(SDOperand(N, 1), Result.getValue(1));
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// Operand Promotion
|
// Operand Promotion
|
||||||
|
Reference in New Issue
Block a user