OSDN Git Service

Make Argument::getArgNo() constant time, not O(#args)
authorReid Kleckner <rnk@google.com>
Thu, 16 Mar 2017 22:25:45 +0000 (22:25 +0000)
committerReid Kleckner <rnk@google.com>
Thu, 16 Mar 2017 22:25:45 +0000 (22:25 +0000)
commit36d60de9d64cf228d80bf61fe67ae4c28d869e9d
tree0b414966f26e229c266b600648c3c6a4ae556389
parent7762f59a0da50f331d37e75312ec684fdad374f2
Make Argument::getArgNo() constant time, not O(#args)

getArgNo is actually hot in LLVM, because its how we check for
attributes on arguments:
  bool Argument::hasNonNullAttr() const {
    if (!getType()->isPointerTy()) return false;
    if (getParent()->getAttributes().
          hasAttribute(getArgNo()+1, Attribute::NonNull))
      return true;

It actually shows up as the 23rd hottest leaf function in a 13s sample
of LTO of llc.

This grows Argument by four bytes, but I have another pending patch to
shrink it by removing its ilist_node base.

Reviewed By: chandlerc

Subscribers: inglorion, llvm-commits, mehdi_amini

Differential Revision: https://reviews.llvm.org/D31057

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298003 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/IR/Argument.h
lib/IR/Function.cpp