Change intrinsic result type for void to store it as an empty list

instead of as a single element list with VoidTy.  Now with a fix
for the verifier.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99206 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2010-03-22 20:56:36 +00:00
parent b751418a39
commit 93dc92e412
4 changed files with 57 additions and 52 deletions

View File

@ -1683,13 +1683,11 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
/// parameters beginning with NumRets.
///
static std::string IntrinsicParam(unsigned ArgNo, unsigned NumRets) {
if (ArgNo < NumRets) {
if (NumRets == 1)
return "Intrinsic result type";
else
return "Intrinsic result type #" + utostr(ArgNo);
} else
if (ArgNo >= NumRets)
return "Intrinsic parameter #" + utostr(ArgNo - NumRets);
if (NumRets == 1)
return "Intrinsic result type";
return "Intrinsic result type #" + utostr(ArgNo);
}
bool Verifier::PerformTypeCheck(Intrinsic::ID ID, Function *F, const Type *Ty,
@ -1706,9 +1704,13 @@ bool Verifier::PerformTypeCheck(Intrinsic::ID ID, Function *F, const Type *Ty,
const Type *RetTy = FTy->getReturnType();
const StructType *ST = dyn_cast<StructType>(RetTy);
unsigned NumRets = 1;
if (ST)
NumRets = ST->getNumElements();
unsigned NumRetVals;
if (RetTy->isVoidTy())
NumRetVals = 0;
else if (ST)
NumRetVals = ST->getNumElements();
else
NumRetVals = 1;
if (VT < 0) {
int Match = ~VT;
@ -1720,7 +1722,7 @@ bool Verifier::PerformTypeCheck(Intrinsic::ID ID, Function *F, const Type *Ty,
TruncatedElementVectorType)) != 0) {
const IntegerType *IEltTy = dyn_cast<IntegerType>(EltTy);
if (!VTy || !IEltTy) {
CheckFailed(IntrinsicParam(ArgNo, NumRets) + " is not "
CheckFailed(IntrinsicParam(ArgNo, NumRetVals) + " is not "
"an integral vector type.", F);
return false;
}
@ -1728,7 +1730,7 @@ bool Verifier::PerformTypeCheck(Intrinsic::ID ID, Function *F, const Type *Ty,
// the type being matched against.
if ((Match & ExtendedElementVectorType) != 0) {
if ((IEltTy->getBitWidth() & 1) != 0) {
CheckFailed(IntrinsicParam(ArgNo, NumRets) + " vector "
CheckFailed(IntrinsicParam(ArgNo, NumRetVals) + " vector "
"element bit-width is odd.", F);
return false;
}
@ -1738,25 +1740,25 @@ bool Verifier::PerformTypeCheck(Intrinsic::ID ID, Function *F, const Type *Ty,
Match &= ~(ExtendedElementVectorType | TruncatedElementVectorType);
}
if (Match <= static_cast<int>(NumRets - 1)) {
if (Match <= static_cast<int>(NumRetVals - 1)) {
if (ST)
RetTy = ST->getElementType(Match);
if (Ty != RetTy) {
CheckFailed(IntrinsicParam(ArgNo, NumRets) + " does not "
CheckFailed(IntrinsicParam(ArgNo, NumRetVals) + " does not "
"match return type.", F);
return false;
}
} else {
if (Ty != FTy->getParamType(Match - NumRets)) {
CheckFailed(IntrinsicParam(ArgNo, NumRets) + " does not "
"match parameter %" + utostr(Match - NumRets) + ".", F);
if (Ty != FTy->getParamType(Match - NumRetVals)) {
CheckFailed(IntrinsicParam(ArgNo, NumRetVals) + " does not "
"match parameter %" + utostr(Match - NumRetVals) + ".", F);
return false;
}
}
} else if (VT == MVT::iAny) {
if (!EltTy->isIntegerTy()) {
CheckFailed(IntrinsicParam(ArgNo, NumRets) + " is not "
CheckFailed(IntrinsicParam(ArgNo, NumRetVals) + " is not "
"an integer type.", F);
return false;
}
@ -1781,7 +1783,7 @@ bool Verifier::PerformTypeCheck(Intrinsic::ID ID, Function *F, const Type *Ty,
}
} else if (VT == MVT::fAny) {
if (!EltTy->isFloatingPointTy()) {
CheckFailed(IntrinsicParam(ArgNo, NumRets) + " is not "
CheckFailed(IntrinsicParam(ArgNo, NumRetVals) + " is not "
"a floating-point type.", F);
return false;
}
@ -1794,13 +1796,14 @@ bool Verifier::PerformTypeCheck(Intrinsic::ID ID, Function *F, const Type *Ty,
Suffix += EVT::getEVT(EltTy).getEVTString();
} else if (VT == MVT::vAny) {
if (!VTy) {
CheckFailed(IntrinsicParam(ArgNo, NumRets) + " is not a vector type.", F);
CheckFailed(IntrinsicParam(ArgNo, NumRetVals) + " is not a vector type.",
F);
return false;
}
Suffix += ".v" + utostr(NumElts) + EVT::getEVT(EltTy).getEVTString();
} else if (VT == MVT::iPTR) {
if (!Ty->isPointerTy()) {
CheckFailed(IntrinsicParam(ArgNo, NumRets) + " is not a "
CheckFailed(IntrinsicParam(ArgNo, NumRetVals) + " is not a "
"pointer and a pointer is required.", F);
return false;
}
@ -1812,7 +1815,7 @@ bool Verifier::PerformTypeCheck(Intrinsic::ID ID, Function *F, const Type *Ty,
Suffix += ".p" + utostr(PTyp->getAddressSpace()) +
EVT::getEVT(PTyp->getElementType()).getEVTString();
} else {
CheckFailed(IntrinsicParam(ArgNo, NumRets) + " is not a "
CheckFailed(IntrinsicParam(ArgNo, NumRetVals) + " is not a "
"pointer and a pointer is required.", F);
return false;
}
@ -1832,10 +1835,10 @@ bool Verifier::PerformTypeCheck(Intrinsic::ID ID, Function *F, const Type *Ty,
}
} else if (EVT((MVT::SimpleValueType)VT).getTypeForEVT(Ty->getContext()) !=
EltTy) {
CheckFailed(IntrinsicParam(ArgNo, NumRets) + " is wrong!", F);
CheckFailed(IntrinsicParam(ArgNo, NumRetVals) + " is wrong!", F);
return false;
} else if (EltTy != Ty) {
CheckFailed(IntrinsicParam(ArgNo, NumRets) + " is a vector "
CheckFailed(IntrinsicParam(ArgNo, NumRetVals) + " is a vector "
"and a scalar is required.", F);
return false;
}
@ -1847,10 +1850,10 @@ bool Verifier::PerformTypeCheck(Intrinsic::ID ID, Function *F, const Type *Ty,
/// Intrinsics.gen. This implements a little state machine that verifies the
/// prototype of intrinsics.
void Verifier::VerifyIntrinsicPrototype(Intrinsic::ID ID, Function *F,
unsigned RetNum,
unsigned ParamNum, ...) {
unsigned NumRetVals,
unsigned NumParams, ...) {
va_list VA;
va_start(VA, ParamNum);
va_start(VA, NumParams);
const FunctionType *FTy = F->getFunctionType();
// For overloaded intrinsics, the Suffix of the function name must match the
@ -1858,7 +1861,7 @@ void Verifier::VerifyIntrinsicPrototype(Intrinsic::ID ID, Function *F,
// suffix, to be checked at the end.
std::string Suffix;
if (FTy->getNumParams() + FTy->isVarArg() != ParamNum) {
if (FTy->getNumParams() + FTy->isVarArg() != NumParams) {
CheckFailed("Intrinsic prototype has incorrect number of arguments!", F);
return;
}
@ -1866,23 +1869,27 @@ void Verifier::VerifyIntrinsicPrototype(Intrinsic::ID ID, Function *F,
const Type *Ty = FTy->getReturnType();
const StructType *ST = dyn_cast<StructType>(Ty);
if (NumRetVals == 0 && !Ty->isVoidTy()) {
CheckFailed("Intrinsic should return void", F);
return;
}
// Verify the return types.
if (ST && ST->getNumElements() != RetNum) {
if (ST && ST->getNumElements() != NumRetVals) {
CheckFailed("Intrinsic prototype has incorrect number of return types!", F);
return;
}
for (unsigned ArgNo = 0; ArgNo < RetNum; ++ArgNo) {
for (unsigned ArgNo = 0; ArgNo != NumRetVals; ++ArgNo) {
int VT = va_arg(VA, int); // An MVT::SimpleValueType when non-negative.
if (ST) Ty = ST->getElementType(ArgNo);
if (!PerformTypeCheck(ID, F, Ty, VT, ArgNo, Suffix))
break;
}
// Verify the parameter types.
for (unsigned ArgNo = 0; ArgNo < ParamNum; ++ArgNo) {
for (unsigned ArgNo = 0; ArgNo != NumParams; ++ArgNo) {
int VT = va_arg(VA, int); // An MVT::SimpleValueType when non-negative.
if (VT == MVT::isVoid && ArgNo > 0) {
@ -1891,8 +1898,8 @@ void Verifier::VerifyIntrinsicPrototype(Intrinsic::ID ID, Function *F,
break;
}
if (!PerformTypeCheck(ID, F, FTy->getParamType(ArgNo), VT, ArgNo + RetNum,
Suffix))
if (!PerformTypeCheck(ID, F, FTy->getParamType(ArgNo), VT,
ArgNo + NumRetVals, Suffix))
break;
}

View File

@ -754,12 +754,8 @@ static unsigned GetNumNodeResults(Record *Operator, CodeGenDAGPatterns &CDP) {
Operator->getName() == "parallel")
return 0; // All return nothing.
if (Operator->isSubClassOf("Intrinsic")) {
unsigned NumRes = CDP.getIntrinsic(Operator).IS.RetVTs.size();
if (NumRes == 1 && CDP.getIntrinsic(Operator).IS.RetVTs[0] == MVT::isVoid)
return 0;
return NumRes;
}
if (Operator->isSubClassOf("Intrinsic"))
return CDP.getIntrinsic(Operator).IS.RetVTs.size();
if (Operator->isSubClassOf("SDNode"))
return CDP.getSDNodeInfo(Operator).getNumResults();
@ -1210,8 +1206,6 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
// Apply the result type to the node.
unsigned NumRetVTs = Int->IS.RetVTs.size();
unsigned NumParamVTs = Int->IS.ParamVTs.size();
if (NumRetVTs == 1 && Int->IS.RetVTs[0] == MVT::isVoid)
NumRetVTs = 0;
for (unsigned i = 0, e = NumRetVTs; i != e; ++i)
MadeChange |= UpdateNodeType(i, Int->IS.RetVTs[i], TP);
@ -1591,7 +1585,7 @@ TreePatternNode *TreePattern::ParseTreePattern(DagInit *Dag) {
// If this intrinsic returns void, it must have side-effects and thus a
// chain.
if (Int.IS.RetVTs[0] == MVT::isVoid) {
if (Int.IS.RetVTs.empty()) {
Operator = getDAGPatterns().get_intrinsic_void_sdnode();
} else if (Int.ModRef != CodeGenIntrinsic::NoMem) {
// Has side-effects, requires chain.

View File

@ -490,12 +490,15 @@ CodeGenIntrinsic::CodeGenIntrinsic(Record *R) {
OverloadedVTs.push_back(VT);
isOverloaded |= true;
}
IS.RetVTs.push_back(VT);
IS.RetTypeDefs.push_back(TyEl);
}
if (IS.RetVTs.size() == 0)
throw "Intrinsic '"+DefName+"' needs at least a type for the ret value!";
if (IS.RetVTs.size() == 1 && IS.RetVTs[0] == MVT::isVoid) {
IS.RetVTs.pop_back();
IS.RetTypeDefs.pop_back();
}
// Parse the list of parameter types.
TypeList = R->getValueAsListInit("ParamTypes");

View File

@ -172,10 +172,11 @@ static void EmitTypeGenerate(raw_ostream &OS, const Record *ArgType,
static void EmitTypeGenerate(raw_ostream &OS,
const std::vector<Record*> &ArgTypes,
unsigned &ArgNo) {
if (ArgTypes.size() == 1) {
EmitTypeGenerate(OS, ArgTypes.front(), ArgNo);
return;
}
if (ArgTypes.empty())
return EmitTypeForValueType(OS, MVT::isVoid);
if (ArgTypes.size() == 1)
return EmitTypeGenerate(OS, ArgTypes.front(), ArgNo);
OS << "StructType::get(Context, ";
@ -251,11 +252,11 @@ namespace {
unsigned RHSSize = RHSVec->size();
unsigned LHSSize = LHSVec->size();
do {
for (; i != LHSSize; ++i) {
if (i == RHSSize) return false; // RHS is shorter than LHS.
if ((*LHSVec)[i] != (*RHSVec)[i])
return (*LHSVec)[i]->getName() < (*RHSVec)[i]->getName();
} while (++i != LHSSize);
}
if (i != RHSSize) return true;