Avoid going through the LLVMContext for type equality where it's safe to dereference the type pointer.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92726 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2010-01-05 13:12:22 +00:00
parent 804272c8d6
commit f012705c7e
25 changed files with 46 additions and 58 deletions

View File

@ -1715,8 +1715,7 @@ Value *LLParser::PerFunctionState::GetVal(const std::string &Name,
}
// Don't make placeholders with invalid type.
if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty) &&
Ty != Type::getLabelTy(F.getContext())) {
if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty) && !Ty->isLabelTy()) {
P.Error(Loc, "invalid use of a non-first-class type");
return 0;
}
@ -1757,8 +1756,7 @@ Value *LLParser::PerFunctionState::GetVal(unsigned ID, const Type *Ty,
return 0;
}
if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty) &&
Ty != Type::getLabelTy(F.getContext())) {
if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty) && !Ty->isLabelTy()) {
P.Error(Loc, "invalid use of a non-first-class type");
return 0;
}
@ -2663,8 +2661,7 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) {
AttrListPtr PAL = AttrListPtr::get(Attrs.begin(), Attrs.end());
if (PAL.paramHasAttr(1, Attribute::StructRet) &&
RetType != Type::getVoidTy(Context))
if (PAL.paramHasAttr(1, Attribute::StructRet) && !RetType->isVoidTy())
return Error(RetTypeLoc, "functions with 'sret' argument must return void");
const FunctionType *FT =

View File

@ -808,7 +808,7 @@ bool BitcodeReader::ParseMetadata() {
const Type *Ty = getTypeByID(Record[i], false);
if (Ty->isMetadataTy())
Elts.push_back(MDValueList.getValueFwdRef(Record[i+1]));
else if (Ty != Type::getVoidTy(Context))
else if (!Ty->isVoidTy())
Elts.push_back(ValueList.getValueFwdRef(Record[i+1], Ty));
else
Elts.push_back(NULL);
@ -2238,7 +2238,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
}
// Non-void values get registered in the value table for future use.
if (I && I->getType() != Type::getVoidTy(Context))
if (I && !I->getType()->isVoidTy())
ValueList.AssignValue(I, NextValueNo++);
}

View File

@ -382,7 +382,7 @@ void ValueEnumerator::incorporateFunction(const Function &F) {
// Add all of the instructions.
for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) {
if (I->getType() != Type::getVoidTy(F.getContext()))
if (!I->getType()->isVoidTy())
EnumerateValue(I);
}
}

View File

@ -349,12 +349,12 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
case Intrinsic::setjmp: {
Value *V = ReplaceCallWith("setjmp", CI, CI->op_begin() + 1, CI->op_end(),
Type::getInt32Ty(Context));
if (CI->getType() != Type::getVoidTy(Context))
if (!CI->getType()->isVoidTy())
CI->replaceAllUsesWith(V);
break;
}
case Intrinsic::sigsetjmp:
if (CI->getType() != Type::getVoidTy(Context))
if (!CI->getType()->isVoidTy())
CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
break;
@ -508,7 +508,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
}
case Intrinsic::flt_rounds:
// Lower to "round to the nearest"
if (CI->getType() != Type::getVoidTy(Context))
if (!CI->getType()->isVoidTy())
CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1));
break;
case Intrinsic::invariant_start:

View File

@ -113,7 +113,7 @@ void llvm::ComputeValueVTs(const TargetLowering &TLI, const Type *Ty,
return;
}
// Interpret void as zero return values.
if (Ty == Type::getVoidTy(Ty->getContext()))
if (Ty->isVoidTy())
return;
// Base case: we can get an EVT for this LLVM IR type.
ValueVTs.push_back(TLI.getValueType(Ty));

View File

@ -3169,7 +3169,7 @@ void SelectionDAGBuilder::visitTargetIntrinsic(CallInst &I,
} else if (!HasChain) {
Result = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, getCurDebugLoc(),
VTs, &Ops[0], Ops.size());
} else if (I.getType() != Type::getVoidTy(*DAG.getContext())) {
} else if (!I.getType()->isVoidTy()) {
Result = DAG.getNode(ISD::INTRINSIC_W_CHAIN, getCurDebugLoc(),
VTs, &Ops[0], Ops.size());
} else {
@ -3188,7 +3188,7 @@ void SelectionDAGBuilder::visitTargetIntrinsic(CallInst &I,
DAG.setRoot(Chain);
}
if (I.getType() != Type::getVoidTy(*DAG.getContext())) {
if (!I.getType()->isVoidTy()) {
if (const VectorType *PTy = dyn_cast<VectorType>(I.getType())) {
EVT VT = TLI.getValueType(PTy);
Result = DAG.getNode(ISD::BIT_CONVERT, getCurDebugLoc(), VT, Result);
@ -5937,7 +5937,7 @@ void SelectionDAGBuilder::visitInlineAsm(CallSite CS) {
// The return value of the call is this value. As such, there is no
// corresponding argument.
assert(CS.getType() != Type::getVoidTy(*DAG.getContext()) &&
assert(!CS.getType()->isVoidTy() &&
"Bad inline asm!");
if (const StructType *STy = dyn_cast<StructType>(CS.getType())) {
OpVT = TLI.getValueType(STy->getElementType(ResNo));
@ -6107,8 +6107,7 @@ void SelectionDAGBuilder::visitInlineAsm(CallSite CS) {
OpInfo.CallOperandVal));
} else {
// This is the result value of the call.
assert(CS.getType() != Type::getVoidTy(*DAG.getContext()) &&
"Bad inline asm!");
assert(!CS.getType()->isVoidTy() && "Bad inline asm!");
// Concatenate this output onto the outputs list.
RetValRegs.append(OpInfo.AssignedRegs);
}

View File

@ -792,7 +792,7 @@ void SelectionDAGISel::SelectAllBasicBlocks(Function &Fn,
BI->dump();
}
if (BI->getType() != Type::getVoidTy(*CurDAG->getContext())) {
if (!BI->getType()->isVoidTy()) {
unsigned &R = FuncInfo->ValueMap[BI];
if (!R)
R = FuncInfo->CreateRegForValue(BI);

View File

@ -343,9 +343,7 @@ int ExecutionEngine::runFunctionAsMain(Function *Fn,
// Check main() type
unsigned NumArgs = Fn->getFunctionType()->getNumParams();
const FunctionType *FTy = Fn->getFunctionType();
const Type* PPInt8Ty =
PointerType::getUnqual(PointerType::getUnqual(
Type::getInt8Ty(Fn->getContext())));
const Type* PPInt8Ty = Type::getInt8PtrTy(Fn->getContext())->getPointerTo();
switch (NumArgs) {
case 3:
if (FTy->getParamType(2) != PPInt8Ty) {
@ -364,7 +362,7 @@ int ExecutionEngine::runFunctionAsMain(Function *Fn,
// FALLS THROUGH
case 0:
if (!isa<IntegerType>(FTy->getReturnType()) &&
FTy->getReturnType() != Type::getVoidTy(FTy->getContext())) {
!FTy->getReturnType()->isVoidTy()) {
llvm_report_error("Invalid return type of main() supplied");
}
break;

View File

@ -602,7 +602,7 @@ void Interpreter::popStackAndReturnValueToCaller(const Type *RetTy,
ExecutionContext &CallingSF = ECStack.back();
if (Instruction *I = CallingSF.Caller.getInstruction()) {
// Save result...
if (CallingSF.Caller.getType() != Type::getVoidTy(RetTy->getContext()))
if (!CallingSF.Caller.getType()->isVoidTy())
SetValue(I, Result, CallingSF);
if (InvokeInst *II = dyn_cast<InvokeInst> (I))
SwitchToNewBasicBlock (II->getNormalDest (), CallingSF);

View File

@ -411,8 +411,7 @@ GenericValue JIT::runFunction(Function *F,
// Handle some common cases first. These cases correspond to common `main'
// prototypes.
if (RetTy == Type::getInt32Ty(F->getContext()) ||
RetTy == Type::getVoidTy(F->getContext())) {
if (RetTy == Type::getInt32Ty(F->getContext()) || RetTy->isVoidTy()) {
switch (ArgValues.size()) {
case 3:
if (FTy->getParamType(0) == Type::getInt32Ty(F->getContext()) &&
@ -548,7 +547,7 @@ GenericValue JIT::runFunction(Function *F,
"", StubBB);
TheCall->setCallingConv(F->getCallingConv());
TheCall->setTailCall();
if (TheCall->getType() != Type::getVoidTy(F->getContext()))
if (!TheCall->getType()->isVoidTy())
// Return result of the call.
ReturnInst::Create(F->getContext(), TheCall, StubBB);
else

View File

@ -1929,7 +1929,7 @@ GlobalVariable *GlobalOpt::FindGlobalCtors(Module &M) {
const PointerType *PFTy = dyn_cast<PointerType>(STy->getElementType(1));
if (!PFTy) return 0;
const FunctionType *FTy = dyn_cast<FunctionType>(PFTy->getElementType());
if (!FTy || FTy->getReturnType() != Type::getVoidTy(M.getContext()) ||
if (!FTy || !FTy->getReturnType()->isVoidTy() ||
FTy->isVarArg() || FTy->getNumParams() != 0)
return 0;

View File

@ -498,7 +498,7 @@ static void ThunkGToF(Function *F, Function *G) {
CallInst *CI = CallInst::Create(F, Args.begin(), Args.end(), "", BB);
CI->setTailCall();
CI->setCallingConv(F->getCallingConv());
if (NewG->getReturnType() == Type::getVoidTy(F->getContext())) {
if (NewG->getReturnType()->isVoidTy()) {
ReturnInst::Create(F->getContext(), BB);
} else if (CI->getType() != NewG->getReturnType()) {
Value *BCI = new BitCastInst(CI, NewG->getReturnType(), "", BB);

View File

@ -96,8 +96,7 @@ CallGraphNode *SRETPromotion::PromoteReturn(CallGraphNode *CGN) {
DEBUG(dbgs() << "SretPromotion: Looking at sret function "
<< F->getName() << "\n");
assert(F->getReturnType() == Type::getVoidTy(F->getContext()) &&
"Invalid function return type");
assert(F->getReturnType()->isVoidTy() && "Invalid function return type");
Function::arg_iterator AI = F->arg_begin();
const llvm::PointerType *FArgType = dyn_cast<PointerType>(AI->getType());
assert(FArgType && "Invalid sret parameter type");
@ -358,7 +357,7 @@ bool SRETPromotion::nestedStructType(const StructType *STy) {
unsigned Num = STy->getNumElements();
for (unsigned i = 0; i < Num; i++) {
const Type *Ty = STy->getElementType(i);
if (!Ty->isSingleValueType() && Ty != Type::getVoidTy(STy->getContext()))
if (!Ty->isSingleValueType() && !Ty->isVoidTy())
return true;
}
return false;

View File

@ -1027,7 +1027,7 @@ static Value *LookThroughFPExtensions(Value *V) {
// See if the value can be truncated to float and then reextended.
if (Value *V = FitsInFPType(CFP, APFloat::IEEEsingle))
return V;
if (CFP->getType() == Type::getDoubleTy(V->getContext()))
if (CFP->getType()->isDoubleTy())
return V; // Won't shrink.
if (Value *V = FitsInFPType(CFP, APFloat::IEEEdouble))
return V;

View File

@ -252,7 +252,7 @@ void llvm::RemoveSuccessor(TerminatorInst *TI, unsigned SuccNum) {
Value *RetVal = 0;
// Create a value to return... if the function doesn't return null...
if (BB->getParent()->getReturnType() != Type::getVoidTy(TI->getContext()))
if (!BB->getParent()->getReturnType()->isVoidTy())
RetVal = Constant::getNullValue(BB->getParent()->getReturnType());
// Create the return...

View File

@ -593,7 +593,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
// this should be rewritten as a `ret'
// Check if the function should return a value
if (OldFnRetTy == Type::getVoidTy(Context)) {
if (OldFnRetTy->isVoidTy()) {
ReturnInst::Create(Context, 0, TheSwitch); // Return void
} else if (OldFnRetTy == TheSwitch->getCondition()->getType()) {
// return what we have

View File

@ -32,7 +32,7 @@ namespace {
bool runOnFunction(Function &F) {
for (Function::arg_iterator AI = F.arg_begin(), AE = F.arg_end();
AI != AE; ++AI)
if (!AI->hasName() && AI->getType() != Type::getVoidTy(F.getContext()))
if (!AI->hasName() && !AI->getType()->isVoidTy())
AI->setName("arg");
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
@ -40,7 +40,7 @@ namespace {
BB->setName("bb");
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
if (!I->hasName() && I->getType() != Type::getVoidTy(F.getContext()))
if (!I->hasName() && !I->getType()->isVoidTy())
I->setName("tmp");
}
return true;

View File

@ -255,7 +255,7 @@ bool LowerInvoke::insertCheapEHSupport(Function &F) {
// Insert a return instruction. This really should be a "barrier", as it
// is unreachable.
ReturnInst::Create(F.getContext(),
F.getReturnType() == Type::getVoidTy(F.getContext()) ?
F.getReturnType()->isVoidTy() ?
0 : Constant::getNullValue(F.getReturnType()), UI);
// Remove the unwind instruction now.

View File

@ -416,7 +416,7 @@ bool SSIEverything::runOnFunction(Function &F) {
for (Function::iterator B = F.begin(), BE = F.end(); B != BE; ++B)
for (BasicBlock::iterator I = B->begin(), E = B->end(); I != E; ++I)
if (I->getType() != Type::getVoidTy(F.getContext()))
if (!I->getType()->isVoidTy())
Insts.push_back(I);
ssi.createSSI(Insts);

View File

@ -753,7 +753,7 @@ HoistTerminator:
// Okay, it is safe to hoist the terminator.
Instruction *NT = I1->clone();
BIParent->getInstList().insert(BI, NT);
if (NT->getType() != Type::getVoidTy(BB1->getContext())) {
if (!NT->getType()->isVoidTy()) {
I1->replaceAllUsesWith(NT);
I2->replaceAllUsesWith(NT);
NT->takeName(I1);

View File

@ -112,7 +112,7 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) {
"UnifiedReturnBlock", &F);
PHINode *PN = 0;
if (F.getReturnType() == Type::getVoidTy(F.getContext())) {
if (F.getReturnType()->isVoidTy()) {
ReturnInst::Create(F.getContext(), NULL, NewRetBlock);
} else {
// If the function doesn't return void... add a PHI node to the block...

View File

@ -189,7 +189,7 @@ void Function::BuildLazyArguments() const {
// Create the arguments vector, all arguments start out unnamed.
const FunctionType *FT = getFunctionType();
for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
assert(FT->getParamType(i) != Type::getVoidTy(FT->getContext()) &&
assert(!FT->getParamType(i)->isVoidTy() &&
"Cannot have void typed arguments!");
ArgumentList.push_back(new Argument(FT->getParamType(i)));
}

View File

@ -217,7 +217,7 @@ bool InlineAsm::Verify(const FunctionType *Ty, StringRef ConstStr) {
switch (NumOutputs) {
case 0:
if (Ty->getReturnType() != Type::getVoidTy(Ty->getContext())) return false;
if (!Ty->getReturnType()->isVoidTy()) return false;
break;
case 1:
if (isa<StructType>(Ty->getReturnType())) return false;

View File

@ -523,8 +523,7 @@ static Instruction *createMalloc(Instruction *InsertBefore,
MCall->setCallingConv(F->getCallingConv());
if (!F->doesNotAlias(0)) F->setDoesNotAlias(0);
}
assert(MCall->getType() != Type::getVoidTy(BB->getContext()) &&
"Malloc has void return type");
assert(!MCall->getType()->isVoidTy() && "Malloc has void return type");
return Result;
}
@ -904,7 +903,7 @@ AllocaInst::AllocaInst(const Type *Ty, Value *ArraySize,
: UnaryInstruction(PointerType::getUnqual(Ty), Alloca,
getAISize(Ty->getContext(), ArraySize), InsertBefore) {
setAlignment(0);
assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!");
assert(!Ty->isVoidTy() && "Cannot allocate void!");
setName(Name);
}
@ -913,7 +912,7 @@ AllocaInst::AllocaInst(const Type *Ty, Value *ArraySize,
: UnaryInstruction(PointerType::getUnqual(Ty), Alloca,
getAISize(Ty->getContext(), ArraySize), InsertAtEnd) {
setAlignment(0);
assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!");
assert(!Ty->isVoidTy() && "Cannot allocate void!");
setName(Name);
}
@ -922,7 +921,7 @@ AllocaInst::AllocaInst(const Type *Ty, const Twine &Name,
: UnaryInstruction(PointerType::getUnqual(Ty), Alloca,
getAISize(Ty->getContext(), 0), InsertBefore) {
setAlignment(0);
assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!");
assert(!Ty->isVoidTy() && "Cannot allocate void!");
setName(Name);
}
@ -931,7 +930,7 @@ AllocaInst::AllocaInst(const Type *Ty, const Twine &Name,
: UnaryInstruction(PointerType::getUnqual(Ty), Alloca,
getAISize(Ty->getContext(), 0), InsertAtEnd) {
setAlignment(0);
assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!");
assert(!Ty->isVoidTy() && "Cannot allocate void!");
setName(Name);
}
@ -940,7 +939,7 @@ AllocaInst::AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
: UnaryInstruction(PointerType::getUnqual(Ty), Alloca,
getAISize(Ty->getContext(), ArraySize), InsertBefore) {
setAlignment(Align);
assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!");
assert(!Ty->isVoidTy() && "Cannot allocate void!");
setName(Name);
}
@ -949,7 +948,7 @@ AllocaInst::AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
: UnaryInstruction(PointerType::getUnqual(Ty), Alloca,
getAISize(Ty->getContext(), ArraySize), InsertAtEnd) {
setAlignment(Align);
assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!");
assert(!Ty->isVoidTy() && "Cannot allocate void!");
setName(Name);
}

View File

@ -44,14 +44,12 @@ Value::Value(const Type *ty, unsigned scid)
SubclassOptionalData(0), SubclassData(0), VTy(checkType(ty)),
UseList(0), Name(0) {
if (isa<CallInst>(this) || isa<InvokeInst>(this))
assert((VTy->isFirstClassType() ||
VTy == Type::getVoidTy(ty->getContext()) ||
assert((VTy->isFirstClassType() || VTy->isVoidTy() ||
isa<OpaqueType>(ty) || VTy->getTypeID() == Type::StructTyID) &&
"invalid CallInst type!");
else if (!isa<Constant>(this) && !isa<BasicBlock>(this))
assert((VTy->isFirstClassType() ||
VTy == Type::getVoidTy(ty->getContext()) ||
isa<OpaqueType>(ty)) &&
assert((VTy->isFirstClassType() || VTy->isVoidTy() ||
isa<OpaqueType>(ty)) &&
"Cannot create non-first-class values except for constants!");
}
@ -181,8 +179,7 @@ void Value::setName(const Twine &NewName) {
if (getName() == StringRef(NameStr, NameLen))
return;
assert(getType() != Type::getVoidTy(getContext()) &&
"Cannot assign a name to void values!");
assert(!getType()->isVoidTy() && "Cannot assign a name to void values!");
// Get the symbol table to update for this object.
ValueSymbolTable *ST;