[llvm-commits] [llvm] r109100 - /llvm/trunk/lib/Transforms/IPO/PartialSpecialization.cpp
Gabor Greif
ggreif at gmail.com
Thu Jul 22 06:30:48 PDT 2010
By chance I have caught this instance of access to
CallInst arguments via getOperand. I conjecture that
there are no tests in our regression suite that exercise
the function specialization feature. Anyone up to writing
a test?
Cheers,
Gabor
On Jul 22, 3:04 pm, Gabor Greif <ggr... at gmail.com> wrote:
> Author: ggreif
> Date: Thu Jul 22 08:04:32 2010
> New Revision: 109100
>
> URL:http://llvm.org/viewvc/llvm-project?rev=109100&view=rev
> Log:
> do not access arguments via low-level interface, do not multiply dereference use_iterators
>
> Modified:
> llvm/trunk/lib/Transforms/IPO/PartialSpecialization.cpp
>
> Modified: llvm/trunk/lib/Transforms/IPO/PartialSpecialization.cpp
> URL:http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/Par...
> ==============================================================================
> --- llvm/trunk/lib/Transforms/IPO/PartialSpecialization.cpp (original)
> +++ llvm/trunk/lib/Transforms/IPO/PartialSpecialization.cpp Thu Jul 22 08:04:32 2010
> @@ -82,8 +82,9 @@
> ii != ee; ) {
> Value::use_iterator i = ii;
> ++ii;
> - if (isa<CallInst>(i) || isa<InvokeInst>(i)) {
> - CallSite CS(cast<Instruction>(i));
> + User *U = *i;
> + if (isa<CallInst>(U) || isa<InvokeInst>(U)) {
> + CallSite CS(cast<Instruction>(U));
> if (CS.getCalledFunction() == F) {
>
> SmallVector<Value*, 6> args;
> @@ -105,13 +106,13 @@
> }
> }
> Value* NCall;
> - if (CallInst *CI = dyn_cast<CallInst>(i)) {
> + if (CallInst *CI = dyn_cast<CallInst>(U)) {
> NCall = CallInst::Create(NF, args.begin(), args.end(),
> CI->getName(), CI);
> cast<CallInst>(NCall)->setTailCall(CI->isTailCall());
> cast<CallInst>(NCall)->setCallingConv(CI->getCallingConv());
> } else {
> - InvokeInst *II = cast<InvokeInst>(i);
> + InvokeInst *II = cast<InvokeInst>(U);
> NCall = InvokeInst::Create(NF, II->getNormalDest(),
> II->getUnwindDest(),
> args.begin(), args.end(),
> @@ -123,8 +124,7 @@
> ++numReplaced;
> }
> }
> - next_use:
> - ;
> + next_use:;
> }
> return NF;
> }
> @@ -174,14 +174,14 @@
> ui != ue; ++ui) {
>
> bool interesting = false;
> -
> - if (isa<CmpInst>(ui)) interesting = true;
> - else if (isa<CallInst>(ui))
> + User *U = *ui;
> + if (isa<CmpInst>(U)) interesting = true;
> + else if (isa<CallInst>(U))
> interesting = ui->getOperand(0) == ii;
> - else if (isa<InvokeInst>(ui))
> + else if (isa<InvokeInst>(U))
> interesting = ui->getOperand(0) == ii;
> - else if (isa<SwitchInst>(ui)) interesting = true;
> - else if (isa<BranchInst>(ui)) interesting = true;
> + else if (isa<SwitchInst>(U)) interesting = true;
> + else if (isa<BranchInst>(U)) interesting = true;
>
> if (interesting) {
> args.push_back(std::distance(F.arg_begin(), ii));
> @@ -196,14 +196,16 @@
> std::map<Constant*, int>& dist) {
> bool hasIndirect = false;
> int total = 0;
> - for(Value::use_iterator ii = F.use_begin(), ee = F.use_end();
> - ii != ee; ++ii)
> - if ((isa<CallInst>(ii) || isa<InvokeInst>(ii))
> - && ii->getOperand(0) == &F) {
> - ++dist[dyn_cast<Constant>(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<Constant>(CS.getArgument(arg))];
> ++total;
> } else
> hasIndirect = true;
> + }
>
> // Preserve the original address taken function even if all other uses
> // will be specialized.
>
> _______________________________________________
> llvm-commits mailing list
> llvm-comm... at cs.uiuc.eduhttp://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list