Skip to content
  1. Dec 15, 2014
  2. Dec 09, 2014
    • Duncan P. N. Exon Smith's avatar
      IR: Split Metadata from Value · 5bf8fef5
      Duncan P. N. Exon Smith authored
      Split `Metadata` away from the `Value` class hierarchy, as part of
      PR21532.  Assembly and bitcode changes are in the wings, but this is the
      bulk of the change for the IR C++ API.
      
      I have a follow-up patch prepared for `clang`.  If this breaks other
      sub-projects, I apologize in advance :(.  Help me compile it on Darwin
      I'll try to fix it.  FWIW, the errors should be easy to fix, so it may
      be simpler to just fix it yourself.
      
      This breaks the build for all metadata-related code that's out-of-tree.
      Rest assured the transition is mechanical and the compiler should catch
      almost all of the problems.
      
      Here's a quick guide for updating your code:
      
        - `Metadata` is the root of a class hierarchy with three main classes:
          `MDNode`, `MDString`, and `ValueAsMetadata`.  It is distinct from
          the `Value` class hierarchy.  It is typeless -- i.e., instances do
          *not* have a `Type`.
      
        - `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
      
        - `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
          replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
      
          If you're referring solely to resolved `MDNode`s -- post graph
          construction -- just use `MDNode*`.
      
        - `MDNode` (and the rest of `Metadata`) have only limited support for
          `replaceAllUsesWith()`.
      
          As long as an `MDNode` is pointing at a forward declaration -- the
          result of `MDNode::getTemporary()` -- it maintains a side map of its
          uses and can RAUW itself.  Once the forward declarations are fully
          resolved RAUW support is dropped on the ground.  This means that
          uniquing collisions on changing operands cause nodes to become
          "distinct".  (This already happened fairly commonly, whenever an
          operand went to null.)
      
          If you're constructing complex (non self-reference) `MDNode` cycles,
          you need to call `MDNode::resolveCycles()` on each node (or on a
          top-level node that somehow references all of the nodes).  Also,
          don't do that.  Metadata cycles (and the RAUW machinery needed to
          construct them) are expensive.
      
        - An `MDNode` can only refer to a `Constant` through a bridge called
          `ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
      
          As a side effect, accessing an operand of an `MDNode` that is known
          to be, e.g., `ConstantInt`, takes three steps: first, cast from
          `Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
          third, cast down to `ConstantInt`.
      
          The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
          metadata schema owners transition away from using `Constant`s when
          the type isn't important (and they don't care about referring to
          `GlobalValue`s).
      
          In the meantime, I've added transitional API to the `mdconst`
          namespace that matches semantics with the old code, in order to
          avoid adding the error-prone three-step equivalent to every call
          site.  If your old code was:
      
              MDNode *N = foo();
              bar(isa             <ConstantInt>(N->getOperand(0)));
              baz(cast            <ConstantInt>(N->getOperand(1)));
              bak(cast_or_null    <ConstantInt>(N->getOperand(2)));
              bat(dyn_cast        <ConstantInt>(N->getOperand(3)));
              bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
      
          you can trivially match its semantics with:
      
              MDNode *N = foo();
              bar(mdconst::hasa               <ConstantInt>(N->getOperand(0)));
              baz(mdconst::extract            <ConstantInt>(N->getOperand(1)));
              bak(mdconst::extract_or_null    <ConstantInt>(N->getOperand(2)));
              bat(mdconst::dyn_extract        <ConstantInt>(N->getOperand(3)));
              bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
      
          and when you transition your metadata schema to `MDInt`:
      
              MDNode *N = foo();
              bar(isa             <MDInt>(N->getOperand(0)));
              baz(cast            <MDInt>(N->getOperand(1)));
              bak(cast_or_null    <MDInt>(N->getOperand(2)));
              bat(dyn_cast        <MDInt>(N->getOperand(3)));
              bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
      
        - A `CallInst` -- specifically, intrinsic instructions -- can refer to
          metadata through a bridge called `MetadataAsValue`.  This is a
          subclass of `Value` where `getType()->isMetadataTy()`.
      
          `MetadataAsValue` is the *only* class that can legally refer to a
          `LocalAsMetadata`, which is a bridged form of non-`Constant` values
          like `Argument` and `Instruction`.  It can also refer to any other
          `Metadata` subclass.
      
      (I'll break all your testcases in a follow-up commit, when I propagate
      this change to assembly.)
      
      llvm-svn: 223802
      5bf8fef5
  3. Dec 03, 2014
    • Peter Collingbourne's avatar
      Prologue support · 51d2de7b
      Peter Collingbourne authored
      Patch by Ben Gamari!
      
      This redefines the `prefix` attribute introduced previously and
      introduces a `prologue` attribute.  There are a two primary usecases
      that these attributes aim to serve,
      
        1. Function prologue sigils
      
        2. Function hot-patching: Enable the user to insert `nop` operations
           at the beginning of the function which can later be safely replaced
           with a call to some instrumentation facility
      
        3. Runtime metadata: Allow a compiler to insert data for use by the
           runtime during execution. GHC is one example of a compiler that
           needs this functionality for its tables-next-to-code functionality.
      
      Previously `prefix` served cases (1) and (2) quite well by allowing the user
      to introduce arbitrary data at the entrypoint but before the function
      body. Case (3), however, was poorly handled by this approach as it
      required that prefix data was valid executable code.
      
      Here we redefine the notion of prefix data to instead be data which
      occurs immediately before the function entrypoint (i.e. the symbol
      address). Since prefix data now occurs before the function entrypoint,
      there is no need for the data to be valid code.
      
      The previous notion of prefix data now goes under the name "prologue
      data" to emphasize its duality with the function epilogue.
      
      The intention here is to handle cases (1) and (2) with prologue data and
      case (3) with prefix data.
      
      References
      ----------
      
      This idea arose out of discussions[1] with Reid Kleckner in response to a
      proposal to introduce the notion of symbol offsets to enable handling of
      case (3).
      
      [1] http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-May/073235.html
      
      Test Plan: testsuite
      
      Differential Revision: http://reviews.llvm.org/D6454
      
      llvm-svn: 223189
      51d2de7b
  4. Nov 21, 2014
  5. Nov 19, 2014
  6. Oct 28, 2014
  7. Oct 26, 2014
    • Arnold Schwaighofer's avatar
      Add an option to the LTO code generator to disable vectorization during LTO · eb1a38fa
      Arnold Schwaighofer authored
      We used to always vectorize (slp and loop vectorize) in the LTO pass pipeline.
      
      r220345 changed it so that we used the PassManager's fields 'LoopVectorize' and
      'SLPVectorize' out of the desire to be able to disable vectorization using the
      cl::opt flags 'vectorize-loops'/'slp-vectorize' which the before mentioned
      fields default to.
      Unfortunately, this turns off vectorization because those fields
      default to false.
      This commit adds flags to the LTO library to disable lto vectorization which
      reconciles the desire to optionally disable vectorization during LTO and
      the desired behavior of defaulting to enabled vectorization.
      
      We really want tools to set PassManager flags directly to enable/disable
      vectorization and not go the route via cl::opt flags *in*
      PassManagerBuilder.cpp.
      
      llvm-svn: 220652
      eb1a38fa
  8. Oct 24, 2014
  9. Oct 22, 2014
    • JF Bastien's avatar
      LTO: respect command-line options that disable vectorization. · f42a6ea5
      JF Bastien authored
      Summary: Patches 202051 and 208013 added calls to LTO's PassManager which unconditionally add LoopVectorizePass and SLPVectorizerPass instead of following the logic in PassManagerBuilder::populateModulePassManager and honoring the -vectorize-loops -run-slp-after-loop-vectorization flags.
      
      Reviewers: nadav, aschwaighofer, yijiang
      
      Subscribers: llvm-commits
      
      Differential Revision: http://reviews.llvm.org/D5884
      
      llvm-svn: 220345
      f42a6ea5
  10. Oct 14, 2014
    • Chandler Carruth's avatar
      Add some optional passes around the vectorizer to both better prepare · 7b8297a6
      Chandler Carruth authored
      the IR going into it and to clean up the IR produced by the vectorizers.
      
      Note that these are *off by default* right now while folks collect data
      on whether the performance tradeoff is reasonable.
      
      In a build of the 'opt' binary, I see about 2% compile time regression
      due to this change on average. This is in my mind essentially the worst
      expected case: very little of the opt binary is going to *benefit* from
      these extra passes.
      
      I've seen several benchmarks improve in performance my small amounts due
      to running these passes, and there are certain (rare) cases where these
      passes make a huge difference by either enabling the vectorizer at all
      or by hoisting runtime checks out of the outer loop. My primary
      motivation is to prevent people from seeing runtime check overhead in
      benchmarks where the existing passes and optimizers would be able to
      eliminate that.
      
      I've chosen the sequence of passes based on the kinds of things that
      seem likely to be relevant for the code at each stage: rotaing loops for
      the vectorizer, finding correlated values, loop invariants, and
      unswitching opportunities from any runtime checks, and cleaning up
      commonalities exposed by the SLP vectorizer.
      
      I'll be pinging existing threads where some of these issues have come up
      and will start new threads to get folks to benchmark and collect data on
      whether this is the right tradeoff or we should do something else.
      
      llvm-svn: 219644
      7b8297a6
  11. Oct 08, 2014
  12. Oct 07, 2014
    • David Blaikie's avatar
      DebugInfo+DeadArgElimination: Ensure llvm::Function*s from debug info are... · 17364d4e
      David Blaikie authored
      DebugInfo+DeadArgElimination: Ensure llvm::Function*s from debug info are updated even when DAE removes both varargs and non-varargs arguments on the same function.
      
      After some stellar (& inspired) help from Reid Kleckner providing a test
      case for some rather unstable undefined behavior showing up as
      assertions produced by r214761, I was able to fix this issue in DAE
      involving the application of both varargs removal, followed by normal
      argument removal.
      
      Indeed I introduced this same bug into ArgumentPromotion (r212128) by
      copying the code from DAE, and when I fixed the bug in ArgPromo
      (r213805) and commented in that patch that I didn't need to address the
      same issue in DAE because it was a single pass. Turns out it's two pass,
      one for the varargs and one for the normal arguments, so the same fix is
      needed (at least during varargs removal). So here it is.
      
      (the observable/net effect of this bug, even when it didn't result in
      assertion failure, is that debug info would describe the DAE'd function
      in the abstract, but wouldn't provide high/low_pc, variable locations,
      line table, etc (it would appear as though the function had been
      entirely optimized away), see the original PR14016 for details of the
      general problem)
      
      I'm not recommitting the assertion just yet, as there's been another
      regression of it since I last tried. It might just be a few test cases
      weren't adequately updated after Adrian or Duncan's recent schema
      changes.
      
      llvm-svn: 219210
      17364d4e
    • David Majnemer's avatar
      GlobalDCE: Don't drop any COMDAT members · e025321d
      David Majnemer authored
      If we require a single member of a comdat, require all of the other
      members as well.
      
      This fixes PR20981.
      
      llvm-svn: 219191
      e025321d
    • David Blaikie's avatar
      range-for some loops in DAE · e44ee92a
      David Blaikie authored
      llvm-svn: 219167
      e44ee92a
  13. Oct 03, 2014
  14. Oct 02, 2014
    • Duncan P. N. Exon Smith's avatar
      DI: Fold constant arguments into a single MDString · 571f97bd
      Duncan P. N. Exon Smith authored
      This patch addresses the first stage of PR17891 by folding constant
      arguments together into a single MDString.  Integers are stringified and
      a `\0` character is used as a separator.
      
      Part of PR17891.
      
      Note: I've attached my testcases upgrade scripts to the PR.  If I've
      just broken your out-of-tree testcases, they might help.
      
      llvm-svn: 218914
      571f97bd
  15. Sep 13, 2014
  16. Sep 10, 2014
  17. Sep 07, 2014
    • Hal Finkel's avatar
      Add an AlignmentFromAssumptions Pass · d67e4639
      Hal Finkel authored
      This adds a ScalarEvolution-powered transformation that updates load, store and
      memory intrinsic pointer alignments based on invariant((a+q) & b == 0)
      expressions. Many of the simple cases we can get with ValueTracking, but we
      still need something like this for the more complicated cases (such as those
      with an offset) that require some algebra. Note that gcc's
      __builtin_assume_aligned's optional third argument provides exactly for this
      kind of 'misalignment' offset for which this kind of logic is necessary.
      
      The primary motivation is to fixup alignments for vector loads/stores after
      vectorization (and unrolling). This pass is added to the optimization pipeline
      just after the SLP vectorizer runs (which, admittedly, does not preserve SE,
      although I imagine it could).  Regardless, I actually don't think that the
      preservation matters too much in this case: SE computes lazily, and this pass
      won't issue any SE queries unless there are any assume intrinsics, so there
      should be no real additional cost in the common case (SLP does preserve DT and
      LoopInfo).
      
      llvm-svn: 217344
      d67e4639
    • Hal Finkel's avatar
      Add an Assumption-Tracking Pass · 74c2f355
      Hal Finkel authored
      This adds an immutable pass, AssumptionTracker, which keeps a cache of
      @llvm.assume call instructions within a module. It uses callback value handles
      to keep stale functions and intrinsics out of the map, and it relies on any
      code that creates new @llvm.assume calls to notify it of the new instructions.
      The benefit is that code needing to find @llvm.assume intrinsics can do so
      directly, without scanning the function, thus allowing the cost of @llvm.assume
      handling to be negligible when none are present.
      
      The current design is intended to be lightweight. We don't keep track of
      anything until we need a list of assumptions in some function. The first time
      this happens, we scan the function. After that, we add/remove @llvm.assume
      calls from the cache in response to registration calls and ValueHandle
      callbacks.
      
      There are no new direct test cases for this pass, but because it calls it
      validation function upon module finalization, we'll pick up detectable
      inconsistencies from the other tests that touch @llvm.assume calls.
      
      This pass will be used by follow-up commits that make use of @llvm.assume.
      
      llvm-svn: 217334
      74c2f355
  18. Sep 04, 2014
  19. Sep 03, 2014
  20. Sep 01, 2014
    • Hal Finkel's avatar
      Feed AA to the inliner and use AA->getModRefBehavior in AddAliasScopeMetadata · 0c083024
      Hal Finkel authored
      This feeds AA through the IFI structure into the inliner so that
      AddAliasScopeMetadata can use AA->getModRefBehavior to figure out which
      functions only access their arguments (instead of just hard-coding some
      knowledge of memory intrinsics). Most of the information is only available from
      BasicAA; this is important for preserving alias scoping information for
      target-specific intrinsics when doing the noalias parameter attribute to
      metadata conversion.
      
      llvm-svn: 216866
      0c083024
  21. Aug 29, 2014
    • Reid Kleckner's avatar
      Don't promote byval pointer arguments when padding matters · febb279c
      Reid Kleckner authored
      Don't promote byval pointer arguments when when their size in bits is
      not equal to their alloc size in bits. This can happen for x86_fp80,
      where the size in bits is 80 but the alloca size in bits in 128.
      Promoting these types can break passing unions of x86_fp80s and other
      types.
      
      Patch by Thomas Jablin!
      
      Reviewed By: rnk
      
      Differential Revision: http://reviews.llvm.org/D5057
      
      llvm-svn: 216693
      febb279c
  22. Aug 27, 2014
  23. Aug 26, 2014
    • Reid Kleckner's avatar
      musttail: Don't eliminate varargs packs if there is a forwarding call · 3715461b
      Reid Kleckner authored
      Also clean up and beef up this grep test for the feature.
      
      llvm-svn: 216425
      3715461b
    • Reid Kleckner's avatar
      ArgPromotion: Don't touch variadic functions · e6e88f99
      Reid Kleckner authored
      Adding, removing, or changing non-pack parameters can change the ABI
      classification of pack parameters. Clang and other frontends encode the
      classification in the IR of the call site, but the callee side
      determines it dynamically based on the number of registers consumed so
      far. Changing the prototype affects the number of registers consumed
      would break such code.
      
      Dead argument elimination performs a similar task and already has a
      similar check to avoid this problem.
      
      Patch by Thomas Jablin!
      
      llvm-svn: 216421
      e6e88f99
  24. Aug 25, 2014
Loading