From efdf039aecf9f5dc53ac080549bf1837ea5776b7 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Thu, 22 Jul 2010 13:04:32 +0000 Subject: [PATCH] do not access arguments via low-level interface, do not multiply dereference use_iterators git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@109100 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/PartialSpecialization.cpp | 36 +++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/Transforms/IPO/PartialSpecialization.cpp b/lib/Transforms/IPO/PartialSpecialization.cpp index e7c2cfcd0d1..4e72d51c7d9 100644 --- a/lib/Transforms/IPO/PartialSpecialization.cpp +++ b/lib/Transforms/IPO/PartialSpecialization.cpp @@ -82,8 +82,9 @@ SpecializeFunction(Function* F, ii != ee; ) { Value::use_iterator i = ii; ++ii; - if (isa(i) || isa(i)) { - CallSite CS(cast(i)); + User *U = *i; + if (isa(U) || isa(U)) { + CallSite CS(cast(U)); if (CS.getCalledFunction() == F) { SmallVector args; @@ -105,13 +106,13 @@ SpecializeFunction(Function* F, } } Value* NCall; - if (CallInst *CI = dyn_cast(i)) { + if (CallInst *CI = dyn_cast(U)) { NCall = CallInst::Create(NF, args.begin(), args.end(), CI->getName(), CI); cast(NCall)->setTailCall(CI->isTailCall()); cast(NCall)->setCallingConv(CI->getCallingConv()); } else { - InvokeInst *II = cast(i); + InvokeInst *II = cast(U); NCall = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(), args.begin(), args.end(), @@ -123,8 +124,7 @@ SpecializeFunction(Function* F, ++numReplaced; } } - next_use: - ; + next_use:; } return NF; } @@ -174,14 +174,14 @@ void PartSpec::scanForInterest(Function& F, InterestingArgVector& args) { ui != ue; ++ui) { bool interesting = false; - - if (isa(ui)) interesting = true; - else if (isa(ui)) + User *U = *ui; + if (isa(U)) interesting = true; + else if (isa(U)) interesting = ui->getOperand(0) == ii; - else if (isa(ui)) + else if (isa(U)) interesting = ui->getOperand(0) == ii; - else if (isa(ui)) interesting = true; - else if (isa(ui)) interesting = true; + else if (isa(U)) interesting = true; + else if (isa(U)) interesting = true; if (interesting) { args.push_back(std::distance(F.arg_begin(), ii)); @@ -196,14 +196,16 @@ int PartSpec::scanDistribution(Function& F, int arg, std::map& dist) { bool hasIndirect = false; int total = 0; - for(Value::use_iterator ii = F.use_begin(), ee = F.use_end(); - ii != ee; ++ii) - if ((isa(ii) || isa(ii)) - && ii->getOperand(0) == &F) { - ++dist[dyn_cast(ii->getOperand(arg + 1))]; + for (Value::use_iterator ii = F.use_begin(), ee = F.use_end(); + ii != ee; ++ii) { + User *U = *ii; + CallSite CS(U); + if (CS && CS.getCalledFunction() == &F) { + ++dist[dyn_cast(CS.getArgument(arg))]; ++total; } else hasIndirect = true; + } // Preserve the original address taken function even if all other uses // will be specialized. -- 2.34.1