[LLVMdev] LowerCALL (TargetLowering)
Nikhil Patil
npatil at ece.utexas.edu
Wed Nov 15 03:30:39 PST 2006
Hi,
I am trying to write a LowerCALL() function for my (custom) target ISA.
All I need to do is map a CALL instruction directly onto an SDNode that
takes an equal number of arguments (very much alike intrinsics, except
that these are custom to my target.) I do not need to implement any call
sequences, stack frames etc.
I get the following assertion failure:
llc: LegalizeDAG.cpp:834: llvm::SDOperand <unnamed>::SelectionDAGLegalize::LegalizeOp(llvm::SDOperand): Assertion `Tmp3.Val->getNumValues() == Result.Val->getNumValues() && "Lowering call/formal_arguments produced unexpected # results!"' failed.
This is what my LowerCALL looks like:
SDOperand MCTargetLowering::LowerCALL(SDOperand Op, SelectionDAG &DAG) {
SDOperand Chain = Op.getOperand(0);
bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0;
assert(!isVarArg);
bool isTailCall = cast<ConstantSDNode>(Op.getOperand(3))->getValue() != 0;
SDOperand Callee = Op.getOperand(4);
MVT::ValueType RetVT= Op.Val->getValueType(0);
unsigned NumOps = (Op.getNumOperands() - 5) / 2;
std::string Name;
if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
Name = G->getGlobal()->getName();
else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee))
Name = S->getSymbol();
unsigned opcode = funcname_to_opc[Name];
assert(opcode != 0 && "Unknown function call.");
std::vector<MVT::ValueType> Tys;
std::vector<SDOperand> Ops;
for (unsigned i = 0; i != NumOps; ++i) {
SDOperand Arg = Op.getOperand(5+2*i);
Tys.push_back(Arg.getValueType());
Ops.push_back(Arg);
}
Tys.push_back(MVT::Other);
Ops.push_back(Chain);
Chain = DAG.getNode(opcode, Tys, &Ops[0], Ops.size());
assert(RetVT == MVT::Other);
return Chain;
}
Everything works fine for functions with no arguments, but otherwise I
get this assert. Can anyone point out my mistake?
Any help will be greatly appreciated,
Thanks,
Nikhil
More information about the llvm-dev
mailing list