//===----------------------------------------------------------------------===//
#include "LegalizeTypes.h"
+#include "llvm/CallingConv.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Support/CommandLine.h"
case Expand:
ExpandResult(N, i);
goto NodeDone;
+ case FloatToInt:
+ FloatToIntResult(N, i);
+ goto NodeDone;
case Scalarize:
ScalarizeResult(N, i);
goto NodeDone;
case Expand:
NeedsRevisit = ExpandOperand(N, i);
break;
+ case FloatToInt:
+ NeedsRevisit = FloatToIntOperand(N, i);
+ break;
case Scalarize:
NeedsRevisit = ScalarizeOperand(N, i);
break;
for (SDNode::use_iterator UI = N->use_begin(), E = N->use_end();
UI != E; ++UI) {
- SDNode *User = *UI;
+ SDNode *User = UI->getUser();
int NodeID = User->getNodeId();
assert(NodeID != ReadyToProcess && NodeID != Processed &&
"Invalid node id for user of unprocessed node!");
Worklist.push_back(N);
}
+void DAGTypeLegalizer::SanityCheck(SDNode *N) {
+ for (SmallVector<SDNode*, 128>::iterator I = Worklist.begin(),
+ E = Worklist.end(); I != E; ++I)
+ assert(*I != N);
+
+ for (DenseMap<SDOperand, SDOperand>::iterator I = ReplacedNodes.begin(),
+ E = ReplacedNodes.end(); I != E; ++I) {
+ assert(I->first.Val != N);
+ assert(I->second.Val != N);
+ }
+
+ for (DenseMap<SDOperand, SDOperand>::iterator I = PromotedNodes.begin(),
+ E = PromotedNodes.end(); I != E; ++I) {
+ assert(I->first.Val != N);
+ assert(I->second.Val != N);
+ }
+
+ for (DenseMap<SDOperand, SDOperand>::iterator
+ I = FloatToIntedNodes.begin(),
+ E = FloatToIntedNodes.end(); I != E; ++I) {
+ assert(I->first.Val != N);
+ assert(I->second.Val != N);
+ }
+
+ for (DenseMap<SDOperand, SDOperand>::iterator I = ScalarizedNodes.begin(),
+ E = ScalarizedNodes.end(); I != E; ++I) {
+ assert(I->first.Val != N);
+ assert(I->second.Val != N);
+ }
+
+ for (DenseMap<SDOperand, std::pair<SDOperand, SDOperand> >::iterator
+ I = ExpandedNodes.begin(), E = ExpandedNodes.end(); I != E; ++I) {
+ assert(I->first.Val != N);
+ assert(I->second.first.Val != N);
+ assert(I->second.second.Val != N);
+ }
+
+ for (DenseMap<SDOperand, std::pair<SDOperand, SDOperand> >::iterator
+ I = SplitNodes.begin(), E = SplitNodes.end(); I != E; ++I) {
+ assert(I->first.Val != N);
+ assert(I->second.first.Val != N);
+ assert(I->second.second.Val != N);
+ }
+}
+
namespace {
/// NodeUpdateListener - This class is a DAGUpdateListener that listens for
/// updates to nodes and recomputes their ready state.
assert(N->getNodeId() != DAGTypeLegalizer::Processed &&
N->getNodeId() != DAGTypeLegalizer::ReadyToProcess &&
"RAUW deleted processed node!");
+#ifndef NDEBUG
+ DTL.SanityCheck(N);
+#endif
}
virtual void NodeUpdated(SDNode *N) {
OpEntry = Result;
}
+void DAGTypeLegalizer::SetIntegerOp(SDOperand Op, SDOperand Result) {
+ AnalyzeNewNode(Result.Val);
+
+ SDOperand &OpEntry = FloatToIntedNodes[Op];
+ assert(OpEntry.Val == 0 && "Node is already converted to integer!");
+ OpEntry = Result;
+}
+
void DAGTypeLegalizer::SetScalarizedOp(SDOperand Op, SDOperand Result) {
AnalyzeNewNode(Result.Val);
OpEntry = Result;
}
-
void DAGTypeLegalizer::GetExpandedOp(SDOperand Op, SDOperand &Lo,
SDOperand &Hi) {
std::pair<SDOperand, SDOperand> &Entry = ExpandedNodes[Op];
}
+/// BitConvertToInteger - Convert to an integer of the same size.
+SDOperand DAGTypeLegalizer::BitConvertToInteger(SDOperand Op) {
+ return DAG.getNode(ISD::BIT_CONVERT,
+ MVT::getIntegerType(MVT::getSizeInBits(Op.getValueType())),
+ Op);
+}
+
SDOperand DAGTypeLegalizer::CreateStackStoreLoad(SDOperand Op,
MVT::ValueType DestVT) {
// Create the stack frame object.
return DAG.getLoad(DestVT, Store, FIPtr, NULL, 0);
}
-/// HandleMemIntrinsic - This handles memcpy/memset/memmove with invalid
-/// operands. This promotes or expands the operands as required.
-SDOperand DAGTypeLegalizer::HandleMemIntrinsic(SDNode *N) {
- // The chain and pointer [operands #0 and #1] are always valid types.
- SDOperand Chain = N->getOperand(0);
- SDOperand Ptr = N->getOperand(1);
- SDOperand Op2 = N->getOperand(2);
-
- // Op #2 is either a value (memset) or a pointer. Promote it if required.
- switch (getTypeAction(Op2.getValueType())) {
- default: assert(0 && "Unknown action for pointer/value operand");
- case Legal: break;
- case Promote: Op2 = GetPromotedOp(Op2); break;
- }
-
- // The length could have any action required.
- SDOperand Length = N->getOperand(3);
- switch (getTypeAction(Length.getValueType())) {
- default: assert(0 && "Unknown action for memop operand");
- case Legal: break;
- case Promote: Length = GetPromotedZExtOp(Length); break;
- case Expand:
- SDOperand Dummy; // discard the high part.
- GetExpandedOp(Length, Length, Dummy);
- break;
- }
-
- SDOperand Align = N->getOperand(4);
- switch (getTypeAction(Align.getValueType())) {
- default: assert(0 && "Unknown action for memop operand");
- case Legal: break;
- case Promote: Align = GetPromotedZExtOp(Align); break;
- }
-
- SDOperand AlwaysInline = N->getOperand(5);
- switch (getTypeAction(AlwaysInline.getValueType())) {
- default: assert(0 && "Unknown action for memop operand");
- case Legal: break;
- case Promote: AlwaysInline = GetPromotedZExtOp(AlwaysInline); break;
- }
-
- SDOperand Ops[] = { Chain, Ptr, Op2, Length, Align, AlwaysInline };
- return DAG.UpdateNodeOperands(SDOperand(N, 0), Ops, 6);
-}
-
/// JoinIntegers - Build an integer with low bits Lo and high bits Hi.
SDOperand DAGTypeLegalizer::JoinIntegers(SDOperand Lo, SDOperand Hi) {
MVT::ValueType LVT = Lo.getValueType();
SplitInteger(Op, HalfVT, HalfVT, Lo, Hi);
}
+/// MakeLibCall - Generate a libcall taking the given operands as arguments and
+/// returning a result of type RetVT.
+SDOperand DAGTypeLegalizer::MakeLibCall(RTLIB::Libcall LC, MVT::ValueType RetVT,
+ const SDOperand *Ops, unsigned NumOps,
+ bool isSigned) {
+ TargetLowering::ArgListTy Args;
+ Args.reserve(NumOps);
+
+ TargetLowering::ArgListEntry Entry;
+ for (unsigned i = 0; i != NumOps; ++i) {
+ Entry.Node = Ops[i];
+ Entry.Ty = MVT::getTypeForValueType(Entry.Node.getValueType());
+ Entry.isSExt = isSigned;
+ Entry.isZExt = !isSigned;
+ Args.push_back(Entry);
+ }
+ SDOperand Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
+ TLI.getPointerTy());
+
+ const Type *RetTy = MVT::getTypeForValueType(RetVT);
+ std::pair<SDOperand,SDOperand> CallInfo =
+ TLI.LowerCallTo(DAG.getEntryNode(), RetTy, isSigned, !isSigned, false,
+ CallingConv::C, false, Callee, Args, DAG);
+ return CallInfo.first;
+}
+
//===----------------------------------------------------------------------===//
// Entry Point
//===----------------------------------------------------------------------===//