[PATCH] D18576: Initial implementation of optimization bisect
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 14 11:44:43 PDT 2016
MatzeB added a comment.
In http://reviews.llvm.org/D18576#400442, @andrew.w.kaylor wrote:
> In http://reviews.llvm.org/D18576#399046, @MatzeB wrote:
>
> > We have to count how many passes we skipped/did not skip and compare that against the bisect number. This is global information.
>
>
> Is there a good way to get the context from a CallGraphSCC? This is what I came up with:
>
> static LLVMContext *getCGNodeContext(CallGraphNode *Node) {
> Function *F = Node->getFunction();
> if (F)
> return &F->getContext();
> for (CallGraphNode::iterator I = Node->begin(), E = Node->end(); I != E;
> ++I) {
> if (I->first)
> return &cast<Function>(I->first)->getContext();
> Function *CalledFn = I->second->getFunction();
> // A null CalledFn indicates a call to an external node.
> if (!CalledFn)
> continue;
> return &(CalledFn->getContext());
> }
> }
>
> bool CallGraphSCCPass::skipSCC(CallGraphSCC &SCC) const {
> CallGraphNode *Node = *(SCC.begin());
> assert(Node);
> if (!Node)
> return false;
> LLVMContext *Context = nullptr;
> for (CallGraphNode *Node : SCC) {
> Context = getCGNodeContext(Node);
> if (Context)
> break;
> }
> assert(Context);
> // If we can't get the context, assume the pass can't be skipped.
> if (!Context)
> return false;
> return !Context->getOptBisect().shouldRunPass(this, &SCC);
> }
>
>
> It feels awful. Is there a better way to do that?
This does indeed look ugly. The best solution I can see would be to give the CallGraphSCC class a reference to the CallGraph (from there you should be able to go CallGraph.getModule().getContext()). CallGraphSCC is only instantiated once per CallGraphSCCPassManager as far as I can see so an extra reference shouldn't hurt.
Repository:
rL LLVM
http://reviews.llvm.org/D18576
More information about the llvm-commits
mailing list