aboutsummaryrefslogtreecommitdiff
path: root/lib/AsmParser/LLParser.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-10-05 05:54:46 +0000
committerChris Lattner <sabre@nondot.org>2009-10-05 05:54:46 +0000
commitcf0fe8d813727383d630055bb9d1cde21b00b7e7 (patch)
tree4ed7b0bdfe761ae52997a152437d00ddaae10360 /lib/AsmParser/LLParser.cpp
parent5f7962c1b6574e6d834925158886d7c0a1bab5dc (diff)
strength reduce a ton of type equality tests to check the typeid (Through
the new predicates I added) instead of going through a context and doing a pointer comparison. Besides being cheaper, this allows a smart compiler to turn the if sequence into a switch. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83297 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AsmParser/LLParser.cpp')
-rw-r--r--lib/AsmParser/LLParser.cpp40
1 files changed, 20 insertions, 20 deletions
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp
index 42ce95347d..93f0a1848d 100644
--- a/lib/AsmParser/LLParser.cpp
+++ b/lib/AsmParser/LLParser.cpp
@@ -647,7 +647,7 @@ bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc,
return true;
}
- if (isa<FunctionType>(Ty) || Ty == Type::getLabelTy(Context))
+ if (isa<FunctionType>(Ty) || Ty->isLabelTy())
return Error(TyLoc, "invalid type for global variable");
GlobalVariable *GV = 0;
@@ -1113,7 +1113,7 @@ bool LLParser::ParseType(PATypeHolder &Result, bool AllowVoid) {
if (!UpRefs.empty())
return Error(UpRefs.back().Loc, "invalid unresolved type up reference");
- if (!AllowVoid && Result.get() == Type::getVoidTy(Context))
+ if (!AllowVoid && Result.get()->isVoidTy())
return Error(TypeLoc, "void type only allowed for function results");
return false;
@@ -1275,9 +1275,9 @@ bool LLParser::ParseTypeRec(PATypeHolder &Result) {
// TypeRec ::= TypeRec '*'
case lltok::star:
- if (Result.get() == Type::getLabelTy(Context))
+ if (Result.get()->isLabelTy())
return TokError("basic block pointers are invalid");
- if (Result.get() == Type::getVoidTy(Context))
+ if (Result.get()->isVoidTy())
return TokError("pointers to void are invalid; use i8* instead");
if (!PointerType::isValidElementType(Result.get()))
return TokError("pointer to this type is invalid");
@@ -1287,9 +1287,9 @@ bool LLParser::ParseTypeRec(PATypeHolder &Result) {
// TypeRec ::= TypeRec 'addrspace' '(' uint32 ')' '*'
case lltok::kw_addrspace: {
- if (Result.get() == Type::getLabelTy(Context))
+ if (Result.get()->isLabelTy())
return TokError("basic block pointers are invalid");
- if (Result.get() == Type::getVoidTy(Context))
+ if (Result.get()->isVoidTy())
return TokError("pointers to void are invalid; use i8* instead");
if (!PointerType::isValidElementType(Result.get()))
return TokError("pointer to this type is invalid");
@@ -1380,7 +1380,7 @@ bool LLParser::ParseArgumentList(std::vector<ArgInfo> &ArgList,
if ((inType ? ParseTypeRec(ArgTy) : ParseType(ArgTy)) ||
ParseOptionalAttrs(Attrs, 0)) return true;
- if (ArgTy == Type::getVoidTy(Context))
+ if (ArgTy->isVoidTy())
return Error(TypeLoc, "argument can not have void type");
if (Lex.getKind() == lltok::LocalVar ||
@@ -1406,7 +1406,7 @@ bool LLParser::ParseArgumentList(std::vector<ArgInfo> &ArgList,
if ((inType ? ParseTypeRec(ArgTy) : ParseType(ArgTy)) ||
ParseOptionalAttrs(Attrs, 0)) return true;
- if (ArgTy == Type::getVoidTy(Context))
+ if (ArgTy->isVoidTy())
return Error(TypeLoc, "argument can not have void type");
if (Lex.getKind() == lltok::LocalVar ||
@@ -1484,7 +1484,7 @@ bool LLParser::ParseStructType(PATypeHolder &Result, bool Packed) {
if (ParseTypeRec(Result)) return true;
ParamsList.push_back(Result);
- if (Result == Type::getVoidTy(Context))
+ if (Result->isVoidTy())
return Error(EltTyLoc, "struct element can not have void type");
if (!StructType::isValidElementType(Result))
return Error(EltTyLoc, "invalid element type for struct");
@@ -1493,7 +1493,7 @@ bool LLParser::ParseStructType(PATypeHolder &Result, bool Packed) {
EltTyLoc = Lex.getLoc();
if (ParseTypeRec(Result)) return true;
- if (Result == Type::getVoidTy(Context))
+ if (Result->isVoidTy())
return Error(EltTyLoc, "struct element can not have void type");
if (!StructType::isValidElementType(Result))
return Error(EltTyLoc, "invalid element type for struct");
@@ -1532,7 +1532,7 @@ bool LLParser::ParseArrayVectorType(PATypeHolder &Result, bool isVector) {
PATypeHolder EltTy(Type::getVoidTy(Context));
if (ParseTypeRec(EltTy)) return true;
- if (EltTy == Type::getVoidTy(Context))
+ if (EltTy->isVoidTy())
return Error(TypeLoc, "array and vector element type cannot be void");
if (ParseToken(isVector ? lltok::greater : lltok::rsquare,
@@ -1623,7 +1623,7 @@ Value *LLParser::PerFunctionState::GetVal(const std::string &Name,
// If we have the value in the symbol table or fwd-ref table, return it.
if (Val) {
if (Val->getType() == Ty) return Val;
- if (Ty == Type::getLabelTy(F.getContext()))
+ if (Ty->isLabelTy())
P.Error(Loc, "'%" + Name + "' is not a basic block");
else
P.Error(Loc, "'%" + Name + "' defined with type '" +
@@ -1640,7 +1640,7 @@ Value *LLParser::PerFunctionState::GetVal(const std::string &Name,
// Otherwise, create a new forward reference for this value and remember it.
Value *FwdVal;
- if (Ty == Type::getLabelTy(F.getContext()))
+ if (Ty->isLabelTy())
FwdVal = BasicBlock::Create(F.getContext(), Name, &F);
else
FwdVal = new Argument(Ty, Name);
@@ -1666,7 +1666,7 @@ Value *LLParser::PerFunctionState::GetVal(unsigned ID, const Type *Ty,
// If we have the value in the symbol table or fwd-ref table, return it.
if (Val) {
if (Val->getType() == Ty) return Val;
- if (Ty == Type::getLabelTy(F.getContext()))
+ if (Ty->isLabelTy())
P.Error(Loc, "'%" + utostr(ID) + "' is not a basic block");
else
P.Error(Loc, "'%" + utostr(ID) + "' defined with type '" +
@@ -1682,7 +1682,7 @@ Value *LLParser::PerFunctionState::GetVal(unsigned ID, const Type *Ty,
// Otherwise, create a new forward reference for this value and remember it.
Value *FwdVal;
- if (Ty == Type::getLabelTy(F.getContext()))
+ if (Ty->isLabelTy())
FwdVal = BasicBlock::Create(F.getContext(), "", &F);
else
FwdVal = new Argument(Ty);
@@ -1697,7 +1697,7 @@ bool LLParser::PerFunctionState::SetInstName(int NameID,
const std::string &NameStr,
LocTy NameLoc, Instruction *Inst) {
// If this instruction has void type, it cannot have a name or ID specified.
- if (Inst->getType() == Type::getVoidTy(F.getContext())) {
+ if (Inst->getType()->isVoidTy()) {
if (NameID != -1 || !NameStr.empty())
return P.Error(NameLoc, "instructions returning void cannot have a name");
return false;
@@ -2279,7 +2279,7 @@ bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID,
// The lexer has no type info, so builds all float and double FP constants
// as double. Fix this here. Long double does not need this.
if (&ID.APFloatVal.getSemantics() == &APFloat::IEEEdouble &&
- Ty == Type::getFloatTy(Context)) {
+ Ty->isFloatTy()) {
bool Ignored;
ID.APFloatVal.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven,
&Ignored);
@@ -2298,7 +2298,7 @@ bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID,
return false;
case ValID::t_Undef:
// FIXME: LabelTy should not be a first-class type.
- if ((!Ty->isFirstClassType() || Ty == Type::getLabelTy(Context)) &&
+ if ((!Ty->isFirstClassType() || Ty->isLabelTy()) &&
!isa<OpaqueType>(Ty))
return Error(ID.Loc, "invalid type for undef constant");
V = UndefValue::get(Ty);
@@ -2310,7 +2310,7 @@ bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID,
return false;
case ValID::t_Zero:
// FIXME: LabelTy should not be a first-class type.
- if (!Ty->isFirstClassType() || Ty == Type::getLabelTy(Context))
+ if (!Ty->isFirstClassType() || Ty->isLabelTy())
return Error(ID.Loc, "invalid type for null constant");
V = Constant::getNullValue(Ty);
return false;
@@ -2856,7 +2856,7 @@ bool LLParser::ParseRet(Instruction *&Inst, BasicBlock *BB,
PATypeHolder Ty(Type::getVoidTy(Context));
if (ParseType(Ty, true /*void allowed*/)) return true;
- if (Ty == Type::getVoidTy(Context)) {
+ if (Ty->isVoidTy()) {
if (EatIfPresent(lltok::comma))
if (ParseOptionalCustomMetadata()) return true;
Inst = ReturnInst::Create(Context);