Skip to content

Commit

Permalink
Consistent use of the noduplicate attribute.
Browse files Browse the repository at this point in the history
The "noduplicate" attribute of call instructions is sometimes queried directly
and sometimes through the cannotDuplicate() predicate. This patch streamlines
all queries to use the cannotDuplicate() predicate. It also adds this predicate
to InvokeInst, to mirror what CallInst has.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204049 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
eliben committed Mar 17, 2014
1 parent 133aacf commit bbbc2b1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions include/llvm/IR/Instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -3026,6 +3026,12 @@ class InvokeInst : public TerminatorInst {
addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
}

/// \brief Determine if the invoke cannot be duplicated.
bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
void setCannotDuplicate() {
addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
}

/// \brief Determine if the call returns a structure through first
/// pointer argument.
bool hasStructRetAttr() const {
Expand Down
4 changes: 2 additions & 2 deletions lib/Analysis/CodeMetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ void CodeMetrics::analyzeBasicBlock(const BasicBlock *BB,
++NumVectorInsts;

if (const CallInst *CI = dyn_cast<CallInst>(II))
if (CI->hasFnAttr(Attribute::NoDuplicate))
if (CI->cannotDuplicate())
notDuplicatable = true;

if (const InvokeInst *InvI = dyn_cast<InvokeInst>(II))
if (InvI->hasFnAttr(Attribute::NoDuplicate))
if (InvI->cannotDuplicate())
notDuplicatable = true;

NumInsts += TTI.getUserCost(&*II);
Expand Down
2 changes: 1 addition & 1 deletion lib/Analysis/IPA/InlineCost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ bool CallAnalyzer::visitCallSite(CallSite CS) {
return false;
}
if (CS.isCall() &&
cast<CallInst>(CS.getInstruction())->hasFnAttr(Attribute::NoDuplicate))
cast<CallInst>(CS.getInstruction())->cannotDuplicate())
ContainsNoDuplicateCall = true;

if (Function *F = CS.getCalledFunction()) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Analysis/LoopInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ bool Loop::isSafeToClone() const {
return false;

if (const InvokeInst *II = dyn_cast<InvokeInst>((*I)->getTerminator()))
if (II->hasFnAttr(Attribute::NoDuplicate))
if (II->cannotDuplicate())
return false;

for (BasicBlock::iterator BI = (*I)->begin(), BE = (*I)->end(); BI != BE; ++BI) {
if (const CallInst *CI = dyn_cast<CallInst>(BI)) {
if (CI->hasFnAttr(Attribute::NoDuplicate))
if (CI->cannotDuplicate())
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Transforms/Scalar/JumpThreading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ static unsigned getJumpThreadDuplicationCost(const BasicBlock *BB,
// as having cost of 2 total, and if they are a vector intrinsic, we model
// them as having cost 1.
if (const CallInst *CI = dyn_cast<CallInst>(I)) {
if (CI->hasFnAttr(Attribute::NoDuplicate))
if (CI->cannotDuplicate())
// Blocks with NoDuplicate are modelled as having infinite cost, so they
// are never duplicated.
return ~0U;
Expand Down

0 comments on commit bbbc2b1

Please sign in to comment.