From: Duncan Sands Date: Wed, 7 Jan 2009 19:10:21 +0000 (+0000) Subject: Use a switch rather than a sequence of "isa" tests. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=00e7ea98c0fd4a568fe974e79fb44913f173fa77;p=oota-llvm.git Use a switch rather than a sequence of "isa" tests. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61872 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/IPO/FunctionAttrs.cpp b/lib/Transforms/IPO/FunctionAttrs.cpp index 453b3c51aa2..97f82ad8512 100644 --- a/lib/Transforms/IPO/FunctionAttrs.cpp +++ b/lib/Transforms/IPO/FunctionAttrs.cpp @@ -210,7 +210,8 @@ bool FunctionAttrs::isCaptured(Function &F, Value *V) { // be tracked because if it is captured then so is the original pointer. unsigned Depth = UD.getInt(); - if (isa(I)) { + switch (I->getOpcode()) { + case Instruction::Store: if (V == I->getOperand(0)) { // Stored the pointer - it may be captured. If it is stored to a local // object (alloca) then track that object. Otherwise give up. @@ -230,14 +231,17 @@ bool FunctionAttrs::isCaptured(Function &F, Value *V) { } } // Storing to the pointee does not cause the pointer to be captured. - } else if (isa(I)) { + break; + case Instruction::Free: // Freeing a pointer does not cause it to be captured. - } else if (isa(I) || isa(I)) { + break; + case Instruction::Call: + case Instruction::Invoke: { CallSite CS = CallSite::get(I); // Not captured if the callee is readonly and doesn't return a copy // through its return value. if (CS.onlyReadsMemory() && I->getType() == Type::VoidTy) - continue; + break; // Not captured if only passed via 'nocapture' arguments. Note that // calling a function pointer does not in itself cause the pointer to @@ -253,22 +257,33 @@ bool FunctionAttrs::isCaptured(Function &F, Value *V) { return true; // Only passed via 'nocapture' arguments, or is the called function - not // captured. - } else if (isa(I) || isa(I) || isa(I) || - // Play safe and exclude GEP indices. - (isa(I) && V == I->getOperand(0)) || - // Play safe and exclude the select condition. - (isa(I) && V != I->getOperand(0))) { - - // Usually loads can be ignored because they dereference the original - // pointer. However the loaded value needs to be tracked if loading - // from an object that the original pointer was stored to. - if (isa(I)) { + break; + } + case Instruction::BitCast: + case Instruction::GetElementPtr: + case Instruction::Load: + case Instruction::PHI: + case Instruction::Select: + // Track any uses of this instruction to see if they are captured. + // First handle any special cases. + if (isa(I)) { + // Play safe and do not accept being used as an index. + if (V != I->getOperand(0)) + return true; + } else if (isa(I)) { + // Play safe and do not accept being used as the condition. + if (V == I->getOperand(0)) + return true; + } else if (isa(I)) { + // Usually loads can be ignored because they dereference the original + // pointer. However the loaded value needs to be tracked if loading + // from an object that the original pointer was stored to. if (Depth == 0) // Loading the original pointer or a variation of it. This does not // cause the pointer to be captured. Note that the loaded value might // be the pointer itself (think of self-referential objects), but that // is fine as long as it's not this function that stored it there. - continue; + break; // Loading a pointer to (a pointer to...) the original pointer or a // variation of it. Track uses of the loaded value, noting that one // dereference was performed. Note that the loaded value need not be @@ -284,7 +299,8 @@ bool FunctionAttrs::isCaptured(Function &F, Value *V) { if (Visited.insert(UD)) Worklist.push_back(UD); } - } else { + break; + default: // Something else - be conservative and say it is captured. return true; }