Skip to content
Snippets Groups Projects
  1. Sep 09, 2015
    • Chandler Carruth's avatar
      [PM/AA] Rebuild LLVM's alias analysis infrastructure in a way compatible · 7b560d40
      Chandler Carruth authored
      with the new pass manager, and no longer relying on analysis groups.
      
      This builds essentially a ground-up new AA infrastructure stack for
      LLVM. The core ideas are the same that are used throughout the new pass
      manager: type erased polymorphism and direct composition. The design is
      as follows:
      
      - FunctionAAResults is a type-erasing alias analysis results aggregation
        interface to walk a single query across a range of results from
        different alias analyses. Currently this is function-specific as we
        always assume that aliasing queries are *within* a function.
      
      - AAResultBase is a CRTP utility providing stub implementations of
        various parts of the alias analysis result concept, notably in several
        cases in terms of other more general parts of the interface. This can
        be used to implement only a narrow part of the interface rather than
        the entire interface. This isn't really ideal, this logic should be
        hoisted into FunctionAAResults as currently it will cause
        a significant amount of redundant work, but it faithfully models the
        behavior of the prior infrastructure.
      
      - All the alias analysis passes are ported to be wrapper passes for the
        legacy PM and new-style analysis passes for the new PM with a shared
        result object. In some cases (most notably CFL), this is an extremely
        naive approach that we should revisit when we can specialize for the
        new pass manager.
      
      - BasicAA has been restructured to reflect that it is much more
        fundamentally a function analysis because it uses dominator trees and
        loop info that need to be constructed for each function.
      
      All of the references to getting alias analysis results have been
      updated to use the new aggregation interface. All the preservation and
      other pass management code has been updated accordingly.
      
      The way the FunctionAAResultsWrapperPass works is to detect the
      available alias analyses when run, and add them to the results object.
      This means that we should be able to continue to respect when various
      passes are added to the pipeline, for example adding CFL or adding TBAA
      passes should just cause their results to be available and to get folded
      into this. The exception to this rule is BasicAA which really needs to
      be a function pass due to using dominator trees and loop info. As
      a consequence, the FunctionAAResultsWrapperPass directly depends on
      BasicAA and always includes it in the aggregation.
      
      This has significant implications for preserving analyses. Generally,
      most passes shouldn't bother preserving FunctionAAResultsWrapperPass
      because rebuilding the results just updates the set of known AA passes.
      The exception to this rule are LoopPass instances which need to preserve
      all the function analyses that the loop pass manager will end up
      needing. This means preserving both BasicAAWrapperPass and the
      aggregating FunctionAAResultsWrapperPass.
      
      Now, when preserving an alias analysis, you do so by directly preserving
      that analysis. This is only necessary for non-immutable-pass-provided
      alias analyses though, and there are only three of interest: BasicAA,
      GlobalsAA (formerly GlobalsModRef), and SCEVAA. Usually BasicAA is
      preserved when needed because it (like DominatorTree and LoopInfo) is
      marked as a CFG-only pass. I've expanded GlobalsAA into the preserved
      set everywhere we previously were preserving all of AliasAnalysis, and
      I've added SCEVAA in the intersection of that with where we preserve
      SCEV itself.
      
      One significant challenge to all of this is that the CGSCC passes were
      actually using the alias analysis implementations by taking advantage of
      a pretty amazing set of loop holes in the old pass manager's analysis
      management code which allowed analysis groups to slide through in many
      cases. Moving away from analysis groups makes this problem much more
      obvious. To fix it, I've leveraged the flexibility the design of the new
      PM components provides to just directly construct the relevant alias
      analyses for the relevant functions in the IPO passes that need them.
      This is a bit hacky, but should go away with the new pass manager, and
      is already in many ways cleaner than the prior state.
      
      Another significant challenge is that various facilities of the old
      alias analysis infrastructure just don't fit any more. The most
      significant of these is the alias analysis 'counter' pass. That pass
      relied on the ability to snoop on AA queries at different points in the
      analysis group chain. Instead, I'm planning to build printing
      functionality directly into the aggregation layer. I've not included
      that in this patch merely to keep it smaller.
      
      Note that all of this needs a nearly complete rewrite of the AA
      documentation. I'm planning to do that, but I'd like to make sure the
      new design settles, and to flesh out a bit more of what it looks like in
      the new pass manager first.
      
      Differential Revision: http://reviews.llvm.org/D12080
      
      llvm-svn: 247167
      7b560d40
  2. Aug 11, 2015
  3. Aug 05, 2015
  4. Aug 04, 2015
    • Sanjay Patel's avatar
      wrap OptSize and MinSize attributes for easier and consistent access (NFCI) · 924879ad
      Sanjay Patel authored
      Create wrapper methods in the Function class for the OptimizeForSize and MinSize
      attributes. We want to hide the logic of "or'ing" them together when optimizing
      just for size (-Os).
      
      Currently, we are not consistent about this and rely on a front-end to always set
      OptimizeForSize (-Os) if MinSize (-Oz) is on. Thus, there are 18 FIXME changes here
      that should be added as follow-on patches with regression tests.
      
      This patch is NFC-intended: it just replaces existing direct accesses of the attributes
      by the equivalent wrapper call.
      
      Differential Revision: http://reviews.llvm.org/D11734
      
      llvm-svn: 243994
      924879ad
  5. Jul 19, 2015
  6. Jul 02, 2015
  7. Jun 25, 2015
  8. Jun 20, 2015
  9. Jun 15, 2015
    • Peter Collingbourne's avatar
      Protection against stack-based memory corruption errors using SafeStack · 82437bf7
      Peter Collingbourne authored
      This patch adds the safe stack instrumentation pass to LLVM, which separates
      the program stack into a safe stack, which stores return addresses, register
      spills, and local variables that are statically verified to be accessed
      in a safe way, and the unsafe stack, which stores everything else. Such
      separation makes it much harder for an attacker to corrupt objects on the
      safe stack, including function pointers stored in spilled registers and
      return addresses. You can find more information about the safe stack, as
      well as other parts of or control-flow hijack protection technique in our
      OSDI paper on code-pointer integrity (http://dslab.epfl.ch/pubs/cpi.pdf)
      and our project website (http://levee.epfl.ch).
      
      The overhead of our implementation of the safe stack is very close to zero
      (0.01% on the Phoronix benchmarks). This is lower than the overhead of
      stack cookies, which are supported by LLVM and are commonly used today,
      yet the security guarantees of the safe stack are strictly stronger than
      stack cookies. In some cases, the safe stack improves performance due to
      better cache locality.
      
      Our current implementation of the safe stack is stable and robust, we
      used it to recompile multiple projects on Linux including Chromium, and
      we also recompiled the entire FreeBSD user-space system and more than 100
      packages. We ran unit tests on the FreeBSD system and many of the packages
      and observed no errors caused by the safe stack. The safe stack is also fully
      binary compatible with non-instrumented code and can be applied to parts of
      a program selectively.
      
      This patch is our implementation of the safe stack on top of LLVM. The
      patches make the following changes:
      
      - Add the safestack function attribute, similar to the ssp, sspstrong and
        sspreq attributes.
      
      - Add the SafeStack instrumentation pass that applies the safe stack to all
        functions that have the safestack attribute. This pass moves all unsafe local
        variables to the unsafe stack with a separate stack pointer, whereas all
        safe variables remain on the regular stack that is managed by LLVM as usual.
      
      - Invoke the pass as the last stage before code generation (at the same time
        the existing cookie-based stack protector pass is invoked).
      
      - Add unit tests for the safe stack.
      
      Original patch by Volodymyr Kuznetsov and others at the Dependable Systems
      Lab at EPFL; updates and upstreaming by myself.
      
      Differential Revision: http://reviews.llvm.org/D6094
      
      llvm-svn: 239761
      82437bf7
  10. May 05, 2015
    • David Majnemer's avatar
      [Inliner] Discard empty COMDAT groups · ac256cfe
      David Majnemer authored
      COMDAT groups which have become rendered unused because of inline are
      discardable if we can prove that we've made the group empty.
      
      This fixes PR22285.
      
      llvm-svn: 236539
      ac256cfe
  11. Mar 23, 2015
  12. Mar 10, 2015
  13. Mar 04, 2015
    • Mehdi Amini's avatar
      Make DataLayout Non-Optional in the Module · 46a43556
      Mehdi Amini authored
      Summary:
      DataLayout keeps the string used for its creation.
      
      As a side effect it is no longer needed in the Module.
      This is "almost" NFC, the string is no longer
      canonicalized, you can't rely on two "equals" DataLayout
      having the same string returned by getStringRepresentation().
      
      Get rid of DataLayoutPass: the DataLayout is in the Module
      
      The DataLayout is "per-module", let's enforce this by not
      duplicating it more than necessary.
      One more step toward non-optionality of the DataLayout in the
      module.
      
      Make DataLayout Non-Optional in the Module
      
      Module->getDataLayout() will never returns nullptr anymore.
      
      Reviewers: echristo
      
      Subscribers: resistor, llvm-commits, jholewinski
      
      Differential Revision: http://reviews.llvm.org/D7992
      
      From: Mehdi Amini <mehdi.amini@apple.com>
      llvm-svn: 231270
      46a43556
  14. Feb 14, 2015
  15. Jan 15, 2015
    • Chandler Carruth's avatar
      [PM] Separate the TargetLibraryInfo object from the immutable pass. · b98f63db
      Chandler Carruth authored
      The pass is really just a means of accessing a cached instance of the
      TargetLibraryInfo object, and this way we can re-use that object for the
      new pass manager as its result.
      
      Lots of delta, but nothing interesting happening here. This is the
      common pattern that is developing to allow analyses to live in both the
      old and new pass manager -- a wrapper pass in the old pass manager
      emulates the separation intrinsic to the new pass manager between the
      result and pass for analyses.
      
      llvm-svn: 226157
      b98f63db
    • Chandler Carruth's avatar
      [PM] Move TargetLibraryInfo into the Analysis library. · 62d4215b
      Chandler Carruth authored
      While the term "Target" is in the name, it doesn't really have to do
      with the LLVM Target library -- this isn't an abstraction which LLVM
      targets generally need to implement or extend. It has much more to do
      with modeling the various runtime libraries on different OSes and with
      different runtime environments. The "target" in this sense is the more
      general sense of a target of cross compilation.
      
      This is in preparation for porting this analysis to the new pass
      manager.
      
      No functionality changed, and updates inbound for Clang and Polly.
      
      llvm-svn: 226078
      62d4215b
  16. Jan 04, 2015
    • Chandler Carruth's avatar
      [PM] Split the AssumptionTracker immutable pass into two separate APIs: · 66b3130c
      Chandler Carruth authored
      a cache of assumptions for a single function, and an immutable pass that
      manages those caches.
      
      The motivation for this change is two fold. Immutable analyses are
      really hacks around the current pass manager design and don't exist in
      the new design. This is usually OK, but it requires that the core logic
      of an immutable pass be reasonably partitioned off from the pass logic.
      This change does precisely that. As a consequence it also paves the way
      for the *many* utility functions that deal in the assumptions to live in
      both pass manager worlds by creating an separate non-pass object with
      its own independent API that they all rely on. Now, the only bits of the
      system that deal with the actual pass mechanics are those that actually
      need to deal with the pass mechanics.
      
      Once this separation is made, several simplifications become pretty
      obvious in the assumption cache itself. Rather than using a set and
      callback value handles, it can just be a vector of weak value handles.
      The callers can easily skip the handles that are null, and eventually we
      can wrap all of this up behind a filter iterator.
      
      For now, this adds boiler plate to the various passes, but this kind of
      boiler plate will end up making it possible to port these passes to the
      new pass manager, and so it will end up factored away pretty reasonably.
      
      llvm-svn: 225131
      66b3130c
  17. Nov 19, 2014
  18. Oct 08, 2014
  19. Sep 07, 2014
    • 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
  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. Jul 30, 2014
  22. May 22, 2014
    • Diego Novillo's avatar
      Add support for missed and analysis optimization remarks. · 7f8af8bf
      Diego Novillo authored
      Summary:
      This adds two new diagnostics: -pass-remarks-missed and
      -pass-remarks-analysis. They take the same values as -pass-remarks but
      are intended to be triggered in different contexts.
      
      -pass-remarks-missed is used by LLVMContext::emitOptimizationRemarkMissed,
      which passes call when they tried to apply a transformation but
      couldn't.
      
      -pass-remarks-analysis is used by LLVMContext::emitOptimizationRemarkAnalysis,
      which passes call when they want to inform the user about analysis
      results.
      
      The patch also:
      
      1- Adds support in the inliner for the two new remarks and a
         test case.
      
      2- Moves emitOptimizationRemark* functions to the llvm namespace.
      
      3- Adds an LLVMContext argument instead of making them member functions
         of LLVMContext.
      
      Reviewers: qcolombet
      
      Subscribers: llvm-commits
      
      Differential Revision: http://reviews.llvm.org/D3682
      
      llvm-svn: 209442
      7f8af8bf
  23. Apr 25, 2014
  24. Apr 22, 2014
    • Chandler Carruth's avatar
      [Modules] Fix potential ODR violations by sinking the DEBUG_TYPE · 964daaaf
      Chandler Carruth authored
      definition below all of the header #include lines, lib/Transforms/...
      edition.
      
      This one is tricky for two reasons. We again have a couple of passes
      that define something else before the includes as well. I've sunk their
      name macros with the DEBUG_TYPE.
      
      Also, InstCombine contains headers that need DEBUG_TYPE, so now those
      headers #define and #undef DEBUG_TYPE around their code, leaving them
      well formed modular headers. Fixing these headers was a large motivation
      for all of these changes, as "leaky" macros of this form are hard on the
      modules implementation.
      
      llvm-svn: 206844
      964daaaf
  25. Apr 17, 2014
    • NAKAMURA Takumi's avatar
      Inliner::OptimizationRemark: Fix crash in... · cd1fc4bc
      NAKAMURA Takumi authored
      Inliner::OptimizationRemark: Fix crash in clang/test/Frontend/optimization-remark.c on some hosts, including --vg.
      
      DebugLoc in Callsite would not live after Inliner. It should be copied before Inliner.
      
      llvm-svn: 206459
      cd1fc4bc
  26. Apr 08, 2014
    • Diego Novillo's avatar
      Add support for optimization reports. · a9298b22
      Diego Novillo authored
      Summary:
      This patch adds backend support for -Rpass=, which indicates the name
      of the optimization pass that should emit remarks stating when it
      made a transformation to the code.
      
      Pass names are taken from their DEBUG_NAME definitions.
      
      When emitting an optimization report diagnostic, the lack of debug
      information causes the diagnostic to use "<unknown>:0:0" as the
      location string.
      
      This is the back end counterpart for
      
      http://llvm-reviews.chandlerc.com/D3226
      
      Reviewers: qcolombet
      
      CC: llvm-commits
      
      Differential Revision: http://llvm-reviews.chandlerc.com/D3227
      
      llvm-svn: 205774
      a9298b22
  27. Mar 09, 2014
    • Chandler Carruth's avatar
      [C++11] Add range based accessors for the Use-Def chain of a Value. · cdf47884
      Chandler Carruth authored
      This requires a number of steps.
      1) Move value_use_iterator into the Value class as an implementation
         detail
      2) Change it to actually be a *Use* iterator rather than a *User*
         iterator.
      3) Add an adaptor which is a User iterator that always looks through the
         Use to the User.
      4) Wrap these in Value::use_iterator and Value::user_iterator typedefs.
      5) Add the range adaptors as Value::uses() and Value::users().
      6) Update *all* of the callers to correctly distinguish between whether
         they wanted a use_iterator (and to explicitly dig out the User when
         needed), or a user_iterator which makes the Use itself totally
         opaque.
      
      Because #6 requires churning essentially everything that walked the
      Use-Def chains, I went ahead and added all of the range adaptors and
      switched them to range-based loops where appropriate. Also because the
      renaming requires at least churning every line of code, it didn't make
      any sense to split these up into multiple commits -- all of which would
      touch all of the same lies of code.
      
      The result is still not quite optimal. The Value::use_iterator is a nice
      regular iterator, but Value::user_iterator is an iterator over User*s
      rather than over the User objects themselves. As a consequence, it fits
      a bit awkwardly into the range-based world and it has the weird
      extra-dereferencing 'operator->' that so many of our iterators have.
      I think this could be fixed by providing something which transforms
      a range of T&s into a range of T*s, but that *can* be separated into
      another patch, and it isn't yet 100% clear whether this is the right
      move.
      
      However, this change gets us most of the benefit and cleans up
      a substantial amount of code around Use and User. =]
      
      llvm-svn: 203364
      cdf47884
  28. Mar 04, 2014
  29. Feb 25, 2014
  30. Feb 21, 2014
  31. Feb 06, 2014
    • Manman Ren's avatar
      Set default of inlinecold-threshold to 225. · d4612449
      Manman Ren authored
      225 is the default value of inline-threshold. This change will make sure
      we have the same inlining behavior as prior to r200886.
      
      As Chandler points out, even though we don't have code in our testing
      suite that uses cold attribute, there are larger applications that do
      use cold attribute.
      
      r200886 + this commit intend to keep the same behavior as prior to r200886.
      We can later on tune the inlinecold-threshold.
      
      The main purpose of r200886 is to help performance of instrumentation based
      PGO before we actually hook up inliner with analysis passes such as BPI and BFI.
      For instrumentation based PGO, we try to increase inlining of hot functions and
      reduce inlining of cold functions by setting inlinecold-threshold.
      
      Another option suggested by Chandler is to use a boolean flag that controls
      if we should use OptSizeThreshold for cold functions. The default value
      of the boolean flag should not change the current behavior. But it gives us
      less freedom in controlling inlining of cold functions.
      
      llvm-svn: 200898
      d4612449
  32. Feb 05, 2014
  33. Nov 26, 2013
    • Chandler Carruth's avatar
      [PM] Split the CallGraph out from the ModulePass which creates the · 6378cf53
      Chandler Carruth authored
      CallGraph.
      
      This makes the CallGraph a totally generic analysis object that is the
      container for the graph data structure and the primary interface for
      querying and manipulating it. The pass logic is separated into its own
      class. For compatibility reasons, the pass provides wrapper methods for
      most of the methods on CallGraph -- they all just forward.
      
      This will allow the new pass manager infrastructure to provide its own
      analysis pass that constructs the same CallGraph object and makes it
      available. The idea is that in the new pass manager, the analysis pass's
      'run' method returns a concrete analysis 'result'. Here, that result is
      a 'CallGraph'. The 'run' method will typically do only minimal work,
      deferring much of the work into the implementation of the result object
      in order to be lazy about computing things, but when (like DomTree)
      there is *some* up-front computation, the analysis does it prior to
      handing the result back to the querying pass.
      
      I know some of this is fairly ugly. I'm happy to change it around if
      folks can suggest a cleaner interim state, but there is going to be some
      amount of unavoidable ugliness during the transition period. The good
      thing is that this is very limited and will naturally go away when the
      old pass infrastructure goes away. It won't hang around to bother us
      later.
      
      Next up is the initial new-PM-style call graph analysis. =]
      
      llvm-svn: 195722
      6378cf53
  34. Jul 17, 2013
  35. Jul 16, 2013
    • Hal Finkel's avatar
      When the inliner merges allocas, it must keep the larger alignment · 9caa8f7b
      Hal Finkel authored
      For safety, the inliner cannot decrease the allignment on an alloca when
      merging it with another.
      
      I've included two variants of the test case for this: one with DataLayout
      available, and one without. When DataLayout is not available, if only one of
      the allocas uses the default alignment (getAlignment() == 0), then they cannot
      be safely merged.
      
      llvm-svn: 186425
      9caa8f7b
  36. Jan 23, 2013
    • Bill Wendling's avatar
      Add the IR attribute 'sspstrong'. · d154e283
      Bill Wendling authored
      SSPStrong applies a heuristic to insert stack protectors in these situations:
      
      * A Protector is required for functions which contain an array, regardless of
        type or length.
      
      * A Protector is required for functions which contain a structure/union which
        contains an array, regardless of type or length.  Note, there is no limit to
        the depth of nesting.
      
      * A protector is required when the address of a local variable (i.e., stack
        based variable) is exposed. (E.g., such as through a local whose address is
        taken as part of the RHS of an assignment or a local whose address is taken as
        part of a function argument.)
      
      This patch implements the SSPString attribute to be equivalent to
      SSPRequired. This will change in a subsequent patch.
      
      llvm-svn: 173230
      d154e283
  37. Jan 02, 2013
    • Chandler Carruth's avatar
      Move all of the header files which are involved in modelling the LLVM IR · 9fb823bb
      Chandler Carruth authored
      into their new header subdirectory: include/llvm/IR. This matches the
      directory structure of lib, and begins to correct a long standing point
      of file layout clutter in LLVM.
      
      There are still more header files to move here, but I wanted to handle
      them in separate commits to make tracking what files make sense at each
      layer easier.
      
      The only really questionable files here are the target intrinsic
      tablegen files. But that's a battle I'd rather not fight today.
      
      I've updated both CMake and Makefile build systems (I think, and my
      tests think, but I may have missed something).
      
      I've also re-sorted the includes throughout the project. I'll be
      committing updates to Clang, DragonEgg, and Polly momentarily.
      
      llvm-svn: 171366
      9fb823bb
Loading