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.

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

View File

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

View File

@ -490,12 +490,15 @@ CodeGenIntrinsic::CodeGenIntrinsic(Record *R) {
OverloadedVTs.push_back(VT); OverloadedVTs.push_back(VT);
isOverloaded |= true; isOverloaded |= true;
} }
IS.RetVTs.push_back(VT); IS.RetVTs.push_back(VT);
IS.RetTypeDefs.push_back(TyEl); IS.RetTypeDefs.push_back(TyEl);
} }
if (IS.RetVTs.size() == 0) if (IS.RetVTs.size() == 1 && IS.RetVTs[0] == MVT::isVoid) {
throw "Intrinsic '"+DefName+"' needs at least a type for the ret value!"; IS.RetVTs.pop_back();
IS.RetTypeDefs.pop_back();
}
// Parse the list of parameter types. // Parse the list of parameter types.
TypeList = R->getValueAsListInit("ParamTypes"); 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, static void EmitTypeGenerate(raw_ostream &OS,
const std::vector<Record*> &ArgTypes, const std::vector<Record*> &ArgTypes,
unsigned &ArgNo) { unsigned &ArgNo) {
if (ArgTypes.size() == 1) { if (ArgTypes.empty())
EmitTypeGenerate(OS, ArgTypes.front(), ArgNo); return EmitTypeForValueType(OS, MVT::isVoid);
return;
} if (ArgTypes.size() == 1)
return EmitTypeGenerate(OS, ArgTypes.front(), ArgNo);
OS << "StructType::get(Context, "; OS << "StructType::get(Context, ";
@ -251,11 +252,11 @@ namespace {
unsigned RHSSize = RHSVec->size(); unsigned RHSSize = RHSVec->size();
unsigned LHSSize = LHSVec->size(); unsigned LHSSize = LHSVec->size();
do { for (; i != LHSSize; ++i) {
if (i == RHSSize) return false; // RHS is shorter than LHS. if (i == RHSSize) return false; // RHS is shorter than LHS.
if ((*LHSVec)[i] != (*RHSVec)[i]) if ((*LHSVec)[i] != (*RHSVec)[i])
return (*LHSVec)[i]->getName() < (*RHSVec)[i]->getName(); return (*LHSVec)[i]->getName() < (*RHSVec)[i]->getName();
} while (++i != LHSSize); }
if (i != RHSSize) return true; if (i != RHSSize) return true;