2017-10-17 23:27:42 +02:00
|
|
|
//===- Local.h - Functions to perform local transformations -----*- C++ -*-===//
|
2005-04-21 22:59:05 +02:00
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2005-04-21 22:59:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-05-07 20:52:48 +02:00
|
|
|
//
|
|
|
|
// This family of functions perform various local transformations to the
|
|
|
|
// program.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-06-04 23:23:21 +02:00
|
|
|
#ifndef LLVM_TRANSFORMS_UTILS_LOCAL_H
|
|
|
|
#define LLVM_TRANSFORMS_UTILS_LOCAL_H
|
2002-05-07 20:52:48 +02:00
|
|
|
|
2017-10-17 23:27:42 +02:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2018-06-20 18:50:25 +02:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2017-06-06 13:49:48 +02:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2017-10-17 23:27:42 +02:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2017-09-21 21:52:03 +02:00
|
|
|
#include "llvm/ADT/TinyPtrVector.h"
|
[PM/AA] Rebuild LLVM's alias analysis infrastructure in a way compatible
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
2015-09-09 19:55:00 +02:00
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
2019-02-06 03:52:52 +01:00
|
|
|
#include "llvm/Analysis/DomTreeUpdater.h"
|
2018-06-04 23:23:21 +02:00
|
|
|
#include "llvm/Analysis/Utils/Local.h"
|
2017-10-17 23:27:42 +02:00
|
|
|
#include "llvm/IR/Constant.h"
|
|
|
|
#include "llvm/IR/Constants.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
2015-05-23 01:53:24 +02:00
|
|
|
#include "llvm/IR/Dominators.h"
|
2014-03-04 11:40:04 +01:00
|
|
|
#include "llvm/IR/GetElementPtrTypeIterator.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/Operator.h"
|
2017-10-17 23:27:42 +02:00
|
|
|
#include "llvm/IR/Type.h"
|
|
|
|
#include "llvm/IR/User.h"
|
|
|
|
#include "llvm/IR/Value.h"
|
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include <cstdint>
|
|
|
|
#include <limits>
|
2012-05-22 19:19:09 +02:00
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
namespace llvm {
|
|
|
|
|
2017-10-17 23:27:42 +02:00
|
|
|
class AllocaInst;
|
|
|
|
class AssumptionCache;
|
2009-01-05 18:59:02 +01:00
|
|
|
class BasicBlock;
|
2009-06-27 23:30:38 +02:00
|
|
|
class BranchInst;
|
2016-06-18 12:10:37 +02:00
|
|
|
class CallInst;
|
[Coroutines] Use dbg.declare for frame variables
Summary:
https://gist.github.com/modocache/ed7c62f6e570766c0f39b35dad675c2f
is an example of a small C++ program that uses C++20 coroutines that
is difficult to debug, due to the loss of debug info for variables that
"spill" across coroutine suspension boundaries. This patch addresses
that issue by inserting 'llvm.dbg.declare' intrinsics that point the
debugger to the variables' location at an offset to the coroutine frame.
With this patch, I confirmed that running the 'frame variable' commands in
https://gist.github.com/modocache/ed7c62f6e570766c0f39b35dad675c2f at
the specified breakpoints results in the correct values being printed
for coroutine frame variables 'i' and 'j' when using an lldb built from
trunk, as well as with gdb 8.3 (lldb 9.0.1, however, could not print the
values). The added test case also verifies this improved behavior.
The existing coro-debug.ll test case is also modified to reflect the
locations at which Clang actually places calls to 'dbg.declare', and
additional checks are added to ensure this patch works as intended in that
example as well.
Reviewers: vsk, jmorse, GorNishanov, lewissbaker, wenlei
Subscribers: EricWF, aprantl, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D75338
2020-02-27 00:08:00 +01:00
|
|
|
class DbgDeclareInst;
|
2018-08-06 05:59:47 +02:00
|
|
|
class DbgVariableIntrinsic;
|
2016-09-22 16:13:25 +02:00
|
|
|
class DbgValueInst;
|
2017-10-17 23:27:42 +02:00
|
|
|
class DIBuilder;
|
|
|
|
class Function;
|
|
|
|
class Instruction;
|
|
|
|
class LazyValueInfo;
|
2011-03-19 00:45:43 +01:00
|
|
|
class LoadInst;
|
2017-10-17 23:27:42 +02:00
|
|
|
class MDNode;
|
2018-08-16 23:58:44 +02:00
|
|
|
class MemorySSAUpdater;
|
2003-12-19 06:56:28 +01:00
|
|
|
class PHINode;
|
2017-10-17 23:27:42 +02:00
|
|
|
class StoreInst;
|
2012-08-29 17:32:21 +02:00
|
|
|
class TargetLibraryInfo;
|
2012-10-30 12:23:25 +01:00
|
|
|
class TargetTransformInfo;
|
2013-08-02 20:33:34 +02:00
|
|
|
|
2017-09-27 16:54:16 +02:00
|
|
|
/// A set of parameters used to control the transforms in the SimplifyCFG pass.
|
|
|
|
/// Options may change depending on the position in the optimization pipeline.
|
|
|
|
/// For example, canonical form that includes switches and branches may later be
|
|
|
|
/// replaced by lookup tables and selects.
|
|
|
|
struct SimplifyCFGOptions {
|
|
|
|
int BonusInstThreshold;
|
2017-10-22 21:10:07 +02:00
|
|
|
bool ForwardSwitchCondToPhi;
|
2017-09-27 16:54:16 +02:00
|
|
|
bool ConvertSwitchToLookupTable;
|
|
|
|
bool NeedCanonicalLoop;
|
2017-12-14 23:05:20 +01:00
|
|
|
bool SinkCommonInsts;
|
2017-10-04 22:26:25 +02:00
|
|
|
AssumptionCache *AC;
|
2017-09-27 16:54:16 +02:00
|
|
|
|
2017-10-28 20:43:07 +02:00
|
|
|
SimplifyCFGOptions(unsigned BonusThreshold = 1,
|
|
|
|
bool ForwardSwitchCond = false,
|
2017-10-22 21:10:07 +02:00
|
|
|
bool SwitchToLookup = false, bool CanonicalLoops = true,
|
2017-12-14 23:05:20 +01:00
|
|
|
bool SinkCommon = false,
|
2017-10-04 22:26:25 +02:00
|
|
|
AssumptionCache *AssumpCache = nullptr)
|
2017-09-27 16:54:16 +02:00
|
|
|
: BonusInstThreshold(BonusThreshold),
|
2017-10-22 21:10:07 +02:00
|
|
|
ForwardSwitchCondToPhi(ForwardSwitchCond),
|
2017-09-27 16:54:16 +02:00
|
|
|
ConvertSwitchToLookupTable(SwitchToLookup),
|
2017-12-14 23:05:20 +01:00
|
|
|
NeedCanonicalLoop(CanonicalLoops),
|
|
|
|
SinkCommonInsts(SinkCommon),
|
|
|
|
AC(AssumpCache) {}
|
2017-10-28 20:43:07 +02:00
|
|
|
|
|
|
|
// Support 'builder' pattern to set members by name at construction time.
|
|
|
|
SimplifyCFGOptions &bonusInstThreshold(int I) {
|
|
|
|
BonusInstThreshold = I;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
SimplifyCFGOptions &forwardSwitchCondToPhi(bool B) {
|
|
|
|
ForwardSwitchCondToPhi = B;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
SimplifyCFGOptions &convertSwitchToLookupTable(bool B) {
|
|
|
|
ConvertSwitchToLookupTable = B;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
SimplifyCFGOptions &needCanonicalLoops(bool B) {
|
|
|
|
NeedCanonicalLoop = B;
|
|
|
|
return *this;
|
|
|
|
}
|
2017-12-14 23:05:20 +01:00
|
|
|
SimplifyCFGOptions &sinkCommonInsts(bool B) {
|
|
|
|
SinkCommonInsts = B;
|
|
|
|
return *this;
|
|
|
|
}
|
2017-10-28 20:43:07 +02:00
|
|
|
SimplifyCFGOptions &setAssumptionCache(AssumptionCache *Cache) {
|
|
|
|
AC = Cache;
|
|
|
|
return *this;
|
|
|
|
}
|
2017-09-27 16:54:16 +02:00
|
|
|
};
|
|
|
|
|
2002-05-07 20:52:48 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-11-27 23:57:53 +01:00
|
|
|
// Local constant propagation.
|
2002-05-07 20:52:48 +02:00
|
|
|
//
|
|
|
|
|
2016-02-25 16:55:28 +01:00
|
|
|
/// If a terminator instruction is predicated on a constant value, convert it
|
|
|
|
/// into an unconditional branch to the constant destination.
|
|
|
|
/// This is a nontrivial operation because the successors of this basic block
|
|
|
|
/// must have their PHI nodes updated.
|
2011-05-22 18:24:18 +02:00
|
|
|
/// Also calls RecursivelyDeleteTriviallyDeadInstructions() on any branch/switch
|
|
|
|
/// conditions and indirectbr addresses this might make dead if
|
|
|
|
/// DeleteDeadConditions is true.
|
2012-08-29 17:32:21 +02:00
|
|
|
bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions = false,
|
2018-01-12 22:06:48 +01:00
|
|
|
const TargetLibraryInfo *TLI = nullptr,
|
2018-08-03 07:08:17 +02:00
|
|
|
DomTreeUpdater *DTU = nullptr);
|
2002-05-07 20:52:48 +02:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2008-11-27 23:57:53 +01:00
|
|
|
// Local dead code elimination.
|
2002-05-07 20:52:48 +02:00
|
|
|
//
|
|
|
|
|
2016-02-25 16:55:28 +01:00
|
|
|
/// Return true if the result produced by the instruction is not used, and the
|
|
|
|
/// instruction has no side effects.
|
2014-04-14 02:51:57 +02:00
|
|
|
bool isInstructionTriviallyDead(Instruction *I,
|
|
|
|
const TargetLibraryInfo *TLI = nullptr);
|
2002-05-07 20:52:48 +02:00
|
|
|
|
2017-03-10 01:32:33 +01:00
|
|
|
/// Return true if the result produced by the instruction would have no side
|
|
|
|
/// effects if it was not used. This is equivalent to checking whether
|
|
|
|
/// isInstructionTriviallyDead would be true if the use count was 0.
|
|
|
|
bool wouldInstructionBeTriviallyDead(Instruction *I,
|
|
|
|
const TargetLibraryInfo *TLI = nullptr);
|
|
|
|
|
2016-02-25 16:55:28 +01:00
|
|
|
/// If the specified value is a trivially dead instruction, delete it.
|
|
|
|
/// If that makes any of its operands trivially dead, delete them too,
|
|
|
|
/// recursively. Return true if any instructions were deleted.
|
2018-08-16 23:58:44 +02:00
|
|
|
bool RecursivelyDeleteTriviallyDeadInstructions(
|
|
|
|
Value *V, const TargetLibraryInfo *TLI = nullptr,
|
|
|
|
MemorySSAUpdater *MSSAU = nullptr);
|
2009-05-02 20:29:22 +02:00
|
|
|
|
[LoopInstSimplify] Re-implement the core logic of loop-instsimplify to
be both simpler and substantially more efficient.
Rather than use a hand-rolled iteration technique that isn't quite the
same as RPO, use the pre-built RPO loop body traversal utility.
Once visiting the loop body in RPO, we can assert that we visit defs
before uses reliably. When this is the case, the only need to iterate is
when simplifying a def that is used by a PHI node along a back-edge.
With this patch, the first pass over the loop body is just a complete
simplification of every instruction across the loop body. When we
encounter a use of a simplified instruction that stems from a PHI node
in the loop body that has already been visited (due to some cyclic CFG,
potentially the loop itself, or a nested loop, or unstructured control
flow), we recall that specific PHI node for the second iteration.
Nothing else needs to be preserved from iteration to iteration.
On the second and later iterations, only instructions known to have
simplified inputs are considered, each time starting from a set of PHIs
that had simplified inputs along the backedges.
Dead instructions are collected along the way, but deleted in a batch at
the end of each iteration making the iterations themselves substantially
simpler. This uses a new batch API for recursively deleting dead
instructions.
This alsa changes the routine to visit subloops. Because simplification
is fundamentally transitive, we may need to visit the entire loop body,
including subloops, to handle knock-on simplification.
I've added a basic test file that helps demonstrate that all of these
changes work. It includes both straight-forward loops with
simplifications as well as interesting PHI-structures, CFG-structures,
and a nested loop case.
Differential Revision: https://reviews.llvm.org/D47407
llvm-svn: 333461
2018-05-29 22:15:38 +02:00
|
|
|
/// Delete all of the instructions in `DeadInsts`, and all other instructions
|
|
|
|
/// that deleting these in turn causes to be trivially dead.
|
|
|
|
///
|
|
|
|
/// The initial instructions in the provided vector must all have empty use
|
|
|
|
/// lists and satisfy `isInstructionTriviallyDead`.
|
|
|
|
///
|
|
|
|
/// `DeadInsts` will be used as scratch storage for this routine and will be
|
|
|
|
/// empty afterward.
|
|
|
|
void RecursivelyDeleteTriviallyDeadInstructions(
|
2020-01-23 23:21:08 +01:00
|
|
|
SmallVectorImpl<WeakTrackingVH> &DeadInsts,
|
2018-08-16 23:58:44 +02:00
|
|
|
const TargetLibraryInfo *TLI = nullptr, MemorySSAUpdater *MSSAU = nullptr);
|
[LoopInstSimplify] Re-implement the core logic of loop-instsimplify to
be both simpler and substantially more efficient.
Rather than use a hand-rolled iteration technique that isn't quite the
same as RPO, use the pre-built RPO loop body traversal utility.
Once visiting the loop body in RPO, we can assert that we visit defs
before uses reliably. When this is the case, the only need to iterate is
when simplifying a def that is used by a PHI node along a back-edge.
With this patch, the first pass over the loop body is just a complete
simplification of every instruction across the loop body. When we
encounter a use of a simplified instruction that stems from a PHI node
in the loop body that has already been visited (due to some cyclic CFG,
potentially the loop itself, or a nested loop, or unstructured control
flow), we recall that specific PHI node for the second iteration.
Nothing else needs to be preserved from iteration to iteration.
On the second and later iterations, only instructions known to have
simplified inputs are considered, each time starting from a set of PHIs
that had simplified inputs along the backedges.
Dead instructions are collected along the way, but deleted in a batch at
the end of each iteration making the iterations themselves substantially
simpler. This uses a new batch API for recursively deleting dead
instructions.
This alsa changes the routine to visit subloops. Because simplification
is fundamentally transitive, we may need to visit the entire loop body,
including subloops, to handle knock-on simplification.
I've added a basic test file that helps demonstrate that all of these
changes work. It includes both straight-forward loops with
simplifications as well as interesting PHI-structures, CFG-structures,
and a nested loop case.
Differential Revision: https://reviews.llvm.org/D47407
llvm-svn: 333461
2018-05-29 22:15:38 +02:00
|
|
|
|
2020-01-24 00:45:37 +01:00
|
|
|
/// Same functionality as RecursivelyDeleteTriviallyDeadInstructions, but allow
|
|
|
|
/// instructions that are not trivially dead. These will be ignored.
|
|
|
|
/// Returns true if any changes were made, i.e. any instructions trivially dead
|
|
|
|
/// were found and deleted.
|
|
|
|
bool RecursivelyDeleteTriviallyDeadInstructionsPermissive(
|
|
|
|
SmallVectorImpl<WeakTrackingVH> &DeadInsts,
|
|
|
|
const TargetLibraryInfo *TLI = nullptr, MemorySSAUpdater *MSSAU = nullptr);
|
|
|
|
|
2016-02-25 16:55:28 +01:00
|
|
|
/// If the specified value is an effectively dead PHI node, due to being a
|
|
|
|
/// def-use chain of single-use nodes that either forms a cycle or is terminated
|
|
|
|
/// by a trivially dead instruction, delete it. If that makes any of its
|
|
|
|
/// operands trivially dead, delete them too, recursively. Return true if a
|
|
|
|
/// change was made.
|
2014-04-14 02:51:57 +02:00
|
|
|
bool RecursivelyDeleteDeadPHINode(PHINode *PN,
|
2020-01-23 19:25:50 +01:00
|
|
|
const TargetLibraryInfo *TLI = nullptr,
|
|
|
|
MemorySSAUpdater *MSSAU = nullptr);
|
2009-05-02 20:29:22 +02:00
|
|
|
|
2016-02-25 16:55:28 +01:00
|
|
|
/// Scan the specified basic block and try to simplify any instructions in it
|
|
|
|
/// and recursively delete dead instructions.
|
2010-01-12 20:40:54 +01:00
|
|
|
///
|
|
|
|
/// This returns true if it changed the code, note that it can delete
|
|
|
|
/// instructions in other blocks as well in this block.
|
2015-03-10 03:37:25 +01:00
|
|
|
bool SimplifyInstructionsInBlock(BasicBlock *BB,
|
2014-04-14 02:51:57 +02:00
|
|
|
const TargetLibraryInfo *TLI = nullptr);
|
2013-08-02 20:33:34 +02:00
|
|
|
|
2018-12-10 23:17:04 +01:00
|
|
|
/// Replace all the uses of an SSA value in @llvm.dbg intrinsics with
|
|
|
|
/// undef. This is useful for signaling that a variable, e.g. has been
|
|
|
|
/// found dead and hence it's unavailable at a given program point.
|
|
|
|
/// Returns true if the dbg values have been changed.
|
|
|
|
bool replaceDbgUsesWithUndef(Instruction *I);
|
|
|
|
|
2002-05-07 20:52:48 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-12-03 20:44:02 +01:00
|
|
|
// Control Flow Graph Restructuring.
|
2002-05-07 20:52:48 +02:00
|
|
|
//
|
|
|
|
|
2016-02-25 16:55:28 +01:00
|
|
|
/// Like BasicBlock::removePredecessor, this method is called when we're about
|
|
|
|
/// to delete Pred as a predecessor of BB. If BB contains any PHI nodes, this
|
|
|
|
/// drops the entries in the PHI nodes for Pred.
|
2009-11-10 23:26:15 +01:00
|
|
|
///
|
|
|
|
/// Unlike the removePredecessor method, this attempts to simplify uses of PHI
|
|
|
|
/// nodes that collapse into identity values. For example, if we have:
|
|
|
|
/// x = phi(1, 0, 0, 0)
|
|
|
|
/// y = and x, z
|
|
|
|
///
|
|
|
|
/// .. and delete the predecessor corresponding to the '1', this will attempt to
|
|
|
|
/// recursively fold the 'and' to 0.
|
2018-01-12 22:06:48 +01:00
|
|
|
void RemovePredecessorAndSimplify(BasicBlock *BB, BasicBlock *Pred,
|
2018-08-03 07:08:17 +02:00
|
|
|
DomTreeUpdater *DTU = nullptr);
|
2013-08-02 20:33:34 +02:00
|
|
|
|
2016-02-25 16:55:28 +01:00
|
|
|
/// BB is a block with one predecessor and its predecessor is known to have one
|
|
|
|
/// successor (BB!). Eliminate the edge between them, moving the instructions in
|
|
|
|
/// the predecessor into BB. This deletes the predecessor block.
|
2018-08-03 07:08:17 +02:00
|
|
|
void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DomTreeUpdater *DTU = nullptr);
|
2013-08-02 20:33:34 +02:00
|
|
|
|
2016-02-25 16:55:28 +01:00
|
|
|
/// BB is known to contain an unconditional branch, and contains no instructions
|
|
|
|
/// other than PHI nodes, potential debug intrinsics and the branch. If
|
|
|
|
/// possible, eliminate BB by rewriting all the predecessors to branch to the
|
|
|
|
/// successor block and return true. If we can't transform, return false.
|
2018-01-12 22:06:48 +01:00
|
|
|
bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB,
|
2018-08-03 07:08:17 +02:00
|
|
|
DomTreeUpdater *DTU = nullptr);
|
2009-11-19 03:02:10 +01:00
|
|
|
|
2016-02-25 16:55:28 +01:00
|
|
|
/// Check for and eliminate duplicate PHI nodes in this block. This doesn't try
|
|
|
|
/// to be clever about PHI nodes which differ only in the order of the incoming
|
|
|
|
/// values, but instcombine orders them so it usually won't matter.
|
2009-11-19 03:02:10 +01:00
|
|
|
bool EliminateDuplicatePHINodes(BasicBlock *BB);
|
|
|
|
|
2017-09-27 16:54:16 +02:00
|
|
|
/// This function is used to do simplification of a CFG. For example, it
|
|
|
|
/// adjusts branches to branches to eliminate the extra hop, it eliminates
|
|
|
|
/// unreachable basic blocks, and does other peephole optimization of the CFG.
|
|
|
|
/// It returns true if a modification was made, possibly deleting the basic
|
|
|
|
/// block that was pointed to. LoopHeaders is an optional input parameter
|
|
|
|
/// providing the set of loop headers that SimplifyCFG should not eliminate.
|
2017-10-04 22:26:25 +02:00
|
|
|
bool simplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI,
|
2017-09-27 16:54:16 +02:00
|
|
|
const SimplifyCFGOptions &Options = {},
|
|
|
|
SmallPtrSetImpl<BasicBlock *> *LoopHeaders = nullptr);
|
2013-08-06 04:43:45 +02:00
|
|
|
|
2016-02-25 16:55:28 +01:00
|
|
|
/// This function is used to flatten a CFG. For example, it uses parallel-and
|
|
|
|
/// and parallel-or mode to collapse if-conditions and merge if-regions with
|
|
|
|
/// identical statements.
|
2014-04-14 02:51:57 +02:00
|
|
|
bool FlattenCFG(BasicBlock *BB, AliasAnalysis *AA = nullptr);
|
2002-05-07 20:52:48 +02:00
|
|
|
|
2016-02-25 16:55:28 +01:00
|
|
|
/// If this basic block is ONLY a setcc and a branch, and if a predecessor
|
|
|
|
/// branches to us and one of our successors, fold the setcc into the
|
|
|
|
/// predecessor and use logical operations to pick the right destination.
|
[MemorySSA] Teach LoopSimplify to preserve MemorySSA.
Summary:
Preserve MemorySSA in LoopSimplify, in the old pass manager, if the analysis is available.
Do not preserve it in the new pass manager.
Update tests.
Subscribers: nemanjai, jlebar, javed.absar, Prazek, kbarton, zzheng, jsji, llvm-commits, george.burgess.iv, chandlerc
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60833
llvm-svn: 360270
2019-05-08 19:05:36 +02:00
|
|
|
bool FoldBranchToCommonDest(BranchInst *BI, MemorySSAUpdater *MSSAU = nullptr,
|
|
|
|
unsigned BonusInstThreshold = 1);
|
2009-06-27 23:30:38 +02:00
|
|
|
|
2016-02-25 16:55:28 +01:00
|
|
|
/// This function takes a virtual register computed by an Instruction and
|
|
|
|
/// replaces it with a slot in the stack frame, allocated via alloca.
|
|
|
|
/// This allows the CFG to be changed around without fear of invalidating the
|
|
|
|
/// SSA information for the value. It returns the pointer to the alloca inserted
|
|
|
|
/// to create a stack slot for X.
|
2009-07-16 01:53:25 +02:00
|
|
|
AllocaInst *DemoteRegToStack(Instruction &X,
|
2009-07-15 01:09:55 +02:00
|
|
|
bool VolatileLoads = false,
|
2014-04-14 02:51:57 +02:00
|
|
|
Instruction *AllocaPoint = nullptr);
|
2004-03-14 03:13:07 +01:00
|
|
|
|
2016-02-25 16:55:28 +01:00
|
|
|
/// This function takes a virtual register computed by a phi node and replaces
|
|
|
|
/// it with a slot in the stack frame, allocated via alloca. The phi node is
|
|
|
|
/// deleted and it returns the pointer to the alloca inserted.
|
2014-04-14 02:51:57 +02:00
|
|
|
AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = nullptr);
|
2007-07-11 20:41:34 +02:00
|
|
|
|
2016-09-13 18:39:43 +02:00
|
|
|
/// Try to ensure that the alignment of \p V is at least \p PrefAlign bytes. If
|
|
|
|
/// the owning object can be modified and has an alignment less than \p
|
|
|
|
/// PrefAlign, it will be increased and \p PrefAlign returned. If the alignment
|
|
|
|
/// cannot be increased, the known alignment of the value is returned.
|
|
|
|
///
|
|
|
|
/// It is not always possible to modify the alignment of the underlying object,
|
|
|
|
/// so if alignment is important, a more reliable approach is to simply align
|
|
|
|
/// all global variables and allocation instructions to their preferred
|
|
|
|
/// alignment from the beginning.
|
2010-12-25 21:37:57 +01:00
|
|
|
unsigned getOrEnforceKnownAlignment(Value *V, unsigned PrefAlign,
|
2015-03-10 03:37:25 +01:00
|
|
|
const DataLayout &DL,
|
Make use of @llvm.assume in ValueTracking (computeKnownBits, etc.)
This change, which allows @llvm.assume to be used from within computeKnownBits
(and other associated functions in ValueTracking), adds some (optional)
parameters to computeKnownBits and friends. These functions now (optionally)
take a "context" instruction pointer, an AssumptionTracker pointer, and also a
DomTree pointer, and most of the changes are just to pass this new information
when it is easily available from InstSimplify, InstCombine, etc.
As explained below, the significant conceptual change is that known properties
of a value might depend on the control-flow location of the use (because we
care that the @llvm.assume dominates the use because assumptions have
control-flow dependencies). This means that, when we ask if bits are known in a
value, we might get different answers for different uses.
The significant changes are all in ValueTracking. Two main changes: First, as
with the rest of the code, new parameters need to be passed around. To make
this easier, I grouped them into a structure, and I made internal static
versions of the relevant functions that take this structure as a parameter. The
new code does as you might expect, it looks for @llvm.assume calls that make
use of the value we're trying to learn something about (often indirectly),
attempts to pattern match that expression, and uses the result if successful.
By making use of the AssumptionTracker, the process of finding @llvm.assume
calls is not expensive.
Part of the structure being passed around inside ValueTracking is a set of
already-considered @llvm.assume calls. This is to prevent a query using, for
example, the assume(a == b), to recurse on itself. The context and DT params
are used to find applicable assumptions. An assumption needs to dominate the
context instruction, or come after it deterministically. In this latter case we
only handle the specific case where both the assumption and the context
instruction are in the same block, and we need to exclude assumptions from
being used to simplify their own ephemeral values (those which contribute only
to the assumption) because otherwise the assumption would prove its feeding
comparison trivial and would be removed.
This commit adds the plumbing and the logic for a simple masked-bit propagation
(just enough to write a regression test). Future commits add more patterns
(and, correspondingly, more regression tests).
llvm-svn: 217342
2014-09-07 20:57:58 +02:00
|
|
|
const Instruction *CxtI = nullptr,
|
2016-12-19 09:22:17 +01:00
|
|
|
AssumptionCache *AC = nullptr,
|
Make use of @llvm.assume in ValueTracking (computeKnownBits, etc.)
This change, which allows @llvm.assume to be used from within computeKnownBits
(and other associated functions in ValueTracking), adds some (optional)
parameters to computeKnownBits and friends. These functions now (optionally)
take a "context" instruction pointer, an AssumptionTracker pointer, and also a
DomTree pointer, and most of the changes are just to pass this new information
when it is easily available from InstSimplify, InstCombine, etc.
As explained below, the significant conceptual change is that known properties
of a value might depend on the control-flow location of the use (because we
care that the @llvm.assume dominates the use because assumptions have
control-flow dependencies). This means that, when we ask if bits are known in a
value, we might get different answers for different uses.
The significant changes are all in ValueTracking. Two main changes: First, as
with the rest of the code, new parameters need to be passed around. To make
this easier, I grouped them into a structure, and I made internal static
versions of the relevant functions that take this structure as a parameter. The
new code does as you might expect, it looks for @llvm.assume calls that make
use of the value we're trying to learn something about (often indirectly),
attempts to pattern match that expression, and uses the result if successful.
By making use of the AssumptionTracker, the process of finding @llvm.assume
calls is not expensive.
Part of the structure being passed around inside ValueTracking is a set of
already-considered @llvm.assume calls. This is to prevent a query using, for
example, the assume(a == b), to recurse on itself. The context and DT params
are used to find applicable assumptions. An assumption needs to dominate the
context instruction, or come after it deterministically. In this latter case we
only handle the specific case where both the assumption and the context
instruction are in the same block, and we need to exclude assumptions from
being used to simplify their own ephemeral values (those which contribute only
to the assumption) because otherwise the assumption would prove its feeding
comparison trivial and would be removed.
This commit adds the plumbing and the logic for a simple masked-bit propagation
(just enough to write a regression test). Future commits add more patterns
(and, correspondingly, more regression tests).
llvm-svn: 217342
2014-09-07 20:57:58 +02:00
|
|
|
const DominatorTree *DT = nullptr);
|
2010-12-25 21:37:57 +01:00
|
|
|
|
2016-02-25 16:55:28 +01:00
|
|
|
/// Try to infer an alignment for the specified pointer.
|
2017-10-24 23:29:20 +02:00
|
|
|
inline unsigned getKnownAlignment(Value *V, const DataLayout &DL,
|
|
|
|
const Instruction *CxtI = nullptr,
|
|
|
|
AssumptionCache *AC = nullptr,
|
|
|
|
const DominatorTree *DT = nullptr) {
|
2016-12-19 09:22:17 +01:00
|
|
|
return getOrEnforceKnownAlignment(V, 0, DL, CxtI, AC, DT);
|
2010-12-25 21:37:57 +01:00
|
|
|
}
|
|
|
|
|
2019-08-05 23:35:02 +02:00
|
|
|
/// Create a call that matches the invoke \p II in terms of arguments,
|
|
|
|
/// attributes, debug information, etc. The call is not placed in a block and it
|
|
|
|
/// will not have a name. The invoke instruction is not removed, nor are the
|
|
|
|
/// uses replaced by the new call.
|
|
|
|
CallInst *createCallMatchingInvoke(InvokeInst *II);
|
|
|
|
|
2019-07-23 01:58:23 +02:00
|
|
|
/// This function converts the specified invoek into a normall call.
|
|
|
|
void changeToCall(InvokeInst *II, DomTreeUpdater *DTU = nullptr);
|
|
|
|
|
2011-03-17 22:58:19 +01:00
|
|
|
///===---------------------------------------------------------------------===//
|
|
|
|
/// Dbg Intrinsic utilities
|
|
|
|
///
|
|
|
|
|
2013-04-26 20:10:50 +02:00
|
|
|
/// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value
|
2017-09-21 21:52:03 +02:00
|
|
|
/// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
|
2018-08-06 05:59:47 +02:00
|
|
|
void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
|
2011-03-17 22:58:19 +01:00
|
|
|
StoreInst *SI, DIBuilder &Builder);
|
|
|
|
|
2013-04-26 20:10:50 +02:00
|
|
|
/// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value
|
2017-09-21 21:52:03 +02:00
|
|
|
/// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
|
2018-08-06 05:59:47 +02:00
|
|
|
void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
|
2011-03-19 00:45:43 +01:00
|
|
|
LoadInst *LI, DIBuilder &Builder);
|
|
|
|
|
2017-09-21 21:52:03 +02:00
|
|
|
/// Inserts a llvm.dbg.value intrinsic after a phi that has an associated
|
|
|
|
/// llvm.dbg.declare or llvm.dbg.addr intrinsic.
|
2018-08-06 05:59:47 +02:00
|
|
|
void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
|
2016-09-22 16:13:25 +02:00
|
|
|
PHINode *LI, DIBuilder &Builder);
|
|
|
|
|
2016-02-25 16:55:28 +01:00
|
|
|
/// Lowers llvm.dbg.declare intrinsics into appropriate set of
|
|
|
|
/// llvm.dbg.value intrinsics.
|
2011-03-17 23:18:16 +01:00
|
|
|
bool LowerDbgDeclare(Function &F);
|
|
|
|
|
2018-01-25 22:37:05 +01:00
|
|
|
/// Propagate dbg.value intrinsics through the newly inserted PHIs.
|
|
|
|
void insertDebugValuesForPHIs(BasicBlock *BB,
|
|
|
|
SmallVectorImpl<PHINode *> &InsertedPHIs);
|
|
|
|
|
2017-09-21 21:52:03 +02:00
|
|
|
/// Finds all intrinsics declaring local variables as living in the memory that
|
|
|
|
/// 'V' points to. This may include a mix of dbg.declare and
|
|
|
|
/// dbg.addr intrinsics.
|
2018-08-06 05:59:47 +02:00
|
|
|
TinyPtrVector<DbgVariableIntrinsic *> FindDbgAddrUses(Value *V);
|
2011-05-24 05:10:43 +02:00
|
|
|
|
[Coroutines] Use dbg.declare for frame variables
Summary:
https://gist.github.com/modocache/ed7c62f6e570766c0f39b35dad675c2f
is an example of a small C++ program that uses C++20 coroutines that
is difficult to debug, due to the loss of debug info for variables that
"spill" across coroutine suspension boundaries. This patch addresses
that issue by inserting 'llvm.dbg.declare' intrinsics that point the
debugger to the variables' location at an offset to the coroutine frame.
With this patch, I confirmed that running the 'frame variable' commands in
https://gist.github.com/modocache/ed7c62f6e570766c0f39b35dad675c2f at
the specified breakpoints results in the correct values being printed
for coroutine frame variables 'i' and 'j' when using an lldb built from
trunk, as well as with gdb 8.3 (lldb 9.0.1, however, could not print the
values). The added test case also verifies this improved behavior.
The existing coro-debug.ll test case is also modified to reflect the
locations at which Clang actually places calls to 'dbg.declare', and
additional checks are added to ensure this patch works as intended in that
example as well.
Reviewers: vsk, jmorse, GorNishanov, lewissbaker, wenlei
Subscribers: EricWF, aprantl, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D75338
2020-02-27 00:08:00 +01:00
|
|
|
/// Like \c FindDbgAddrUses, but only returns dbg.declare intrinsics, not
|
|
|
|
/// dbg.addr.
|
|
|
|
TinyPtrVector<DbgDeclareInst *> FindDbgDeclareUses(Value *V);
|
|
|
|
|
Salvage debug info from instructions about to be deleted
[Reapplies r297971 and punting on finding a better API for findDbgValues()]
This patch improves debug info quality in InstCombine by looking at
values that are about to be deleted, checking whether there are any
dbg.value instrinsics referring to them, and potentially encoding the
semantics of the deleted instruction into the dbg.value's
DIExpression.
In the example in the testcase (which was extracted from XNU) there is a sequence of
%4 = load %struct.entry*, %struct.entry** %next2, align 8, !dbg !41
%5 = bitcast %struct.entry* %4 to i8*, !dbg !42
%add.ptr4 = getelementptr inbounds i8, i8* %5, i64 -8, !dbg !43
%6 = bitcast i8* %add.ptr4 to %struct.entry*, !dbg !44
call void @llvm.dbg.value(metadata %struct.entry* %6, i64 0, metadata !20, metadata !21), !dbg 34
When these instructions are eliminated by instcombine one after
another, we can still salvage the otherwise dead debug info:
- Bitcasts have no effect, so have the dbg.value point to operand(0)
- Loads can be expressed via a DW_OP_deref
- Constant gep instructions can be replaced by DWARF expression arithmetic
The API introduced by this patch is not specific to instcombine and
can be useful in other places, too.
rdar://problem/30725338
Differential Revision: https://reviews.llvm.org/D30919
llvm-svn: 297994
2017-03-16 22:14:09 +01:00
|
|
|
/// Finds the llvm.dbg.value intrinsics describing a value.
|
2017-03-16 21:11:54 +01:00
|
|
|
void findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues, Value *V);
|
2016-09-22 16:13:25 +02:00
|
|
|
|
2018-01-06 00:27:02 +01:00
|
|
|
/// Finds the debug info intrinsics describing a value.
|
2018-08-06 05:59:47 +02:00
|
|
|
void findDbgUsers(SmallVectorImpl<DbgVariableIntrinsic *> &DbgInsts, Value *V);
|
2018-01-06 00:27:02 +01:00
|
|
|
|
2017-12-08 22:58:18 +01:00
|
|
|
/// Replaces llvm.dbg.declare instruction when the address it
|
|
|
|
/// describes is replaced with a new value. If Deref is true, an
|
|
|
|
/// additional DW_OP_deref is prepended to the expression. If Offset
|
|
|
|
/// is non-zero, a constant displacement is added to the expression
|
|
|
|
/// (between the optional Deref operations). Offset can be negative.
|
2020-02-11 00:37:56 +01:00
|
|
|
bool replaceDbgDeclare(Value *Address, Value *NewAddress, DIBuilder &Builder,
|
2019-05-20 12:35:57 +02:00
|
|
|
uint8_t DIExprFlags, int Offset);
|
2015-12-01 01:40:05 +01:00
|
|
|
|
2016-06-17 00:34:00 +02:00
|
|
|
/// Replaces multiple llvm.dbg.value instructions when the alloca it describes
|
|
|
|
/// is replaced with a new value. If Offset is non-zero, a constant displacement
|
|
|
|
/// is added to the expression (after the mandatory Deref). Offset can be
|
|
|
|
/// negative. New llvm.dbg.value instructions are inserted at the locations of
|
|
|
|
/// the instructions they replace.
|
|
|
|
void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
|
|
|
|
DIBuilder &Builder, int Offset = 0);
|
|
|
|
|
2019-04-15 10:59:56 +02:00
|
|
|
/// Finds alloca where the value comes from.
|
|
|
|
AllocaInst *findAllocaForValue(Value *V,
|
|
|
|
DenseMap<Value *, AllocaInst *> &AllocaForValue);
|
|
|
|
|
2018-07-06 19:32:39 +02:00
|
|
|
/// Assuming the instruction \p I is going to be deleted, attempt to salvage
|
|
|
|
/// debug users of \p I by writing the effect of \p I in a DIExpression.
|
|
|
|
/// Returns true if any debug users were updated.
|
|
|
|
bool salvageDebugInfo(Instruction &I);
|
|
|
|
|
2019-11-07 20:19:41 +01:00
|
|
|
/// Salvage all debug users of the instruction \p I or mark it as undef if it
|
|
|
|
/// cannot be salvaged.
|
|
|
|
void salvageDebugInfoOrMarkUndef(Instruction &I);
|
|
|
|
|
2019-02-05 12:11:28 +01:00
|
|
|
/// Implementation of salvageDebugInfo, applying only to instructions in
|
|
|
|
/// \p Insns, rather than all debug users of \p I.
|
|
|
|
bool salvageDebugInfoForDbgValues(Instruction &I,
|
|
|
|
ArrayRef<DbgVariableIntrinsic *> Insns);
|
|
|
|
|
|
|
|
/// Given an instruction \p I and DIExpression \p DIExpr operating on it, write
|
|
|
|
/// the effects of \p I into the returned DIExpression, or return nullptr if
|
|
|
|
/// it cannot be salvaged. \p StackVal: whether DW_OP_stack_value should be
|
|
|
|
/// appended to the expression.
|
|
|
|
DIExpression *salvageDebugInfoImpl(Instruction &I, DIExpression *DIExpr,
|
|
|
|
bool StackVal);
|
|
|
|
|
2018-07-06 19:32:39 +02:00
|
|
|
/// Point debug users of \p From to \p To or salvage them. Use this function
|
|
|
|
/// only when replacing all uses of \p From with \p To, with a guarantee that
|
|
|
|
/// \p From is going to be deleted.
|
|
|
|
///
|
|
|
|
/// Follow these rules to prevent use-before-def of \p To:
|
|
|
|
/// . If \p To is a linked Instruction, set \p DomPoint to \p To.
|
|
|
|
/// . If \p To is an unlinked Instruction, set \p DomPoint to the Instruction
|
|
|
|
/// \p To will be inserted after.
|
|
|
|
/// . If \p To is not an Instruction (e.g a Constant), the choice of
|
|
|
|
/// \p DomPoint is arbitrary. Pick \p From for simplicity.
|
|
|
|
///
|
|
|
|
/// If a debug user cannot be preserved without reordering variable updates or
|
|
|
|
/// introducing a use-before-def, it is either salvaged (\ref salvageDebugInfo)
|
|
|
|
/// or deleted. Returns true if any debug users were updated.
|
|
|
|
bool replaceAllDbgUsesWith(Instruction &From, Value &To, Instruction &DomPoint,
|
|
|
|
DominatorTree &DT);
|
2018-06-26 20:44:53 +02:00
|
|
|
|
2016-02-25 16:55:28 +01:00
|
|
|
/// Remove all instructions from a basic block other than it's terminator
|
2016-01-24 06:26:18 +01:00
|
|
|
/// and any present EH pad instructions.
|
|
|
|
unsigned removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB);
|
|
|
|
|
2016-02-25 16:55:28 +01:00
|
|
|
/// Insert an unreachable instruction before the specified
|
2015-12-15 22:27:27 +01:00
|
|
|
/// instruction, making it and the rest of the code in the block dead.
|
2016-11-18 22:01:12 +01:00
|
|
|
unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap,
|
2018-01-12 22:06:48 +01:00
|
|
|
bool PreserveLCSSA = false,
|
[MemorySSA] Teach LoopSimplify to preserve MemorySSA.
Summary:
Preserve MemorySSA in LoopSimplify, in the old pass manager, if the analysis is available.
Do not preserve it in the new pass manager.
Update tests.
Subscribers: nemanjai, jlebar, javed.absar, Prazek, kbarton, zzheng, jsji, llvm-commits, george.burgess.iv, chandlerc
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60833
llvm-svn: 360270
2019-05-08 19:05:36 +02:00
|
|
|
DomTreeUpdater *DTU = nullptr,
|
|
|
|
MemorySSAUpdater *MSSAU = nullptr);
|
2015-12-15 22:27:27 +01:00
|
|
|
|
2016-11-14 22:41:13 +01:00
|
|
|
/// Convert the CallInst to InvokeInst with the specified unwind edge basic
|
|
|
|
/// block. This also splits the basic block where CI is located, because
|
|
|
|
/// InvokeInst is a terminator instruction. Returns the newly split basic
|
|
|
|
/// block.
|
|
|
|
BasicBlock *changeToInvokeAndSplitBasicBlock(CallInst *CI,
|
|
|
|
BasicBlock *UnwindEdge);
|
|
|
|
|
2015-09-27 03:47:46 +02:00
|
|
|
/// Replace 'BB's terminator with one that does not have an unwind successor
|
2016-02-25 16:55:28 +01:00
|
|
|
/// block. Rewrites `invoke` to `call`, etc. Updates any PHIs in unwind
|
2015-12-14 19:34:23 +01:00
|
|
|
/// successor.
|
2015-09-27 03:47:46 +02:00
|
|
|
///
|
|
|
|
/// \param BB Block whose terminator will be replaced. Its terminator must
|
|
|
|
/// have an unwind successor.
|
2018-08-03 07:08:17 +02:00
|
|
|
void removeUnwindEdge(BasicBlock *BB, DomTreeUpdater *DTU = nullptr);
|
2015-09-27 03:47:46 +02:00
|
|
|
|
2016-02-25 16:55:28 +01:00
|
|
|
/// Remove all blocks that can not be reached from the function's entry.
|
2012-12-21 12:18:49 +01:00
|
|
|
///
|
|
|
|
/// Returns true if any basic block was removed.
|
2019-10-02 18:58:13 +02:00
|
|
|
bool removeUnreachableBlocks(Function &F, DomTreeUpdater *DTU = nullptr,
|
2018-08-16 23:58:44 +02:00
|
|
|
MemorySSAUpdater *MSSAU = nullptr);
|
2012-12-21 12:18:49 +01:00
|
|
|
|
2018-08-07 17:36:11 +02:00
|
|
|
/// Combine the metadata of two instructions so that K can replace J. Some
|
|
|
|
/// metadata kinds can only be kept if K does not move, meaning it dominated
|
|
|
|
/// J in the original IR.
|
2014-08-15 17:46:38 +02:00
|
|
|
///
|
|
|
|
/// Metadata not listed as known via KnownIDs is removed
|
2018-08-07 17:36:11 +02:00
|
|
|
void combineMetadata(Instruction *K, const Instruction *J,
|
2018-08-24 13:40:04 +02:00
|
|
|
ArrayRef<unsigned> KnownIDs, bool DoesKMove);
|
2014-08-15 17:46:38 +02:00
|
|
|
|
2016-08-08 06:10:22 +02:00
|
|
|
/// Combine the metadata of two instructions so that K can replace J. This
|
2018-08-24 13:40:04 +02:00
|
|
|
/// specifically handles the case of CSE-like transformations. Some
|
|
|
|
/// metadata can only be kept if K dominates J. For this to be correct,
|
|
|
|
/// K cannot be hoisted.
|
2016-08-08 06:10:22 +02:00
|
|
|
///
|
|
|
|
/// Unknown metadata is removed.
|
2018-08-24 13:40:04 +02:00
|
|
|
void combineMetadataForCSE(Instruction *K, const Instruction *J,
|
|
|
|
bool DoesKMove);
|
2016-08-08 06:10:22 +02:00
|
|
|
|
2019-07-25 00:11:11 +02:00
|
|
|
/// Copy the metadata from the source instruction to the destination (the
|
|
|
|
/// replacement for the source instruction).
|
|
|
|
void copyMetadataForLoad(LoadInst &Dest, const LoadInst &Source);
|
|
|
|
|
2018-08-07 15:27:33 +02:00
|
|
|
/// Patch the replacement so that it is not more restrictive than the value
|
2018-08-07 17:36:11 +02:00
|
|
|
/// being replaced. It assumes that the replacement does not get moved from
|
|
|
|
/// its original position.
|
2018-08-07 15:27:33 +02:00
|
|
|
void patchReplacementInstruction(Instruction *I, Value *Repl);
|
|
|
|
|
2017-05-23 15:36:25 +02:00
|
|
|
// Replace each use of 'From' with 'To', if that use does not belong to basic
|
|
|
|
// block where 'From' is defined. Returns the number of replacements made.
|
|
|
|
unsigned replaceNonLocalUsesWith(Instruction *From, Value *To);
|
|
|
|
|
2016-02-25 16:55:28 +01:00
|
|
|
/// Replace each use of 'From' with 'To' if that use is dominated by
|
2015-05-23 01:53:24 +02:00
|
|
|
/// the given edge. Returns the number of replacements made.
|
|
|
|
unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
|
|
|
|
const BasicBlockEdge &Edge);
|
2016-02-25 16:55:28 +01:00
|
|
|
/// Replace each use of 'From' with 'To' if that use is dominated by
|
2016-09-08 17:25:12 +02:00
|
|
|
/// the end of the given BasicBlock. Returns the number of replacements made.
|
2015-09-02 21:59:59 +02:00
|
|
|
unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT,
|
2016-09-08 17:25:12 +02:00
|
|
|
const BasicBlock *BB);
|
2015-10-09 01:18:30 +02:00
|
|
|
|
2019-02-11 08:42:30 +01:00
|
|
|
/// Return true if this call calls a gc leaf function.
|
2015-10-09 01:18:30 +02:00
|
|
|
///
|
|
|
|
/// A leaf function is a function that does not safepoint the thread during its
|
|
|
|
/// execution. During a call or invoke to such a function, the callers stack
|
|
|
|
/// does not have to be made parseable.
|
|
|
|
///
|
|
|
|
/// Most passes can and should ignore this information, and it is only used
|
|
|
|
/// during lowering by the GC infrastructure.
|
2019-02-11 08:42:30 +01:00
|
|
|
bool callsGCLeafFunction(const CallBase *Call, const TargetLibraryInfo &TLI);
|
2015-10-09 01:18:30 +02:00
|
|
|
|
2017-06-26 05:31:31 +02:00
|
|
|
/// Copy a nonnull metadata node to a new load instruction.
|
|
|
|
///
|
|
|
|
/// This handles mapping it to range metadata if the new load is an integer
|
|
|
|
/// load instead of a pointer load.
|
|
|
|
void copyNonnullMetadata(const LoadInst &OldLI, MDNode *N, LoadInst &NewLI);
|
|
|
|
|
|
|
|
/// Copy a range metadata node to a new load instruction.
|
|
|
|
///
|
|
|
|
/// This handles mapping it to nonnull metadata if the new load is a pointer
|
|
|
|
/// load instead of an integer load and the range doesn't cover null.
|
|
|
|
void copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, MDNode *N,
|
|
|
|
LoadInst &NewLI);
|
|
|
|
|
2018-09-19 10:16:56 +02:00
|
|
|
/// Remove the debug intrinsic instructions for the given instruction.
|
|
|
|
void dropDebugUsers(Instruction &I);
|
|
|
|
|
2018-10-25 11:58:59 +02:00
|
|
|
/// Hoist all of the instructions in the \p IfBlock to the dominant block
|
|
|
|
/// \p DomBlock, by moving its instructions to the insertion point \p InsertPt.
|
|
|
|
///
|
|
|
|
/// The moved instructions receive the insertion point debug location values
|
2019-02-08 11:57:26 +01:00
|
|
|
/// (DILocations) and their debug intrinsic instructions are removed.
|
2018-10-25 11:58:59 +02:00
|
|
|
void hoistAllInstructionsInto(BasicBlock *DomBlock, Instruction *InsertPt,
|
|
|
|
BasicBlock *BB);
|
|
|
|
|
2016-01-15 10:20:19 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Intrinsic pattern matching
|
|
|
|
//
|
|
|
|
|
2017-12-15 19:25:13 +01:00
|
|
|
/// Try to match a bswap or bitreverse idiom.
|
2016-01-15 10:20:19 +01:00
|
|
|
///
|
|
|
|
/// If an idiom is matched, an intrinsic call is inserted before \c I. Any added
|
|
|
|
/// instructions are returned in \c InsertedInsts. They will all have been added
|
|
|
|
/// to a basic block.
|
|
|
|
///
|
|
|
|
/// A bitreverse idiom normally requires around 2*BW nodes to be searched (where
|
|
|
|
/// BW is the bitwidth of the integer type). A bswap idiom requires anywhere up
|
|
|
|
/// to BW / 4 nodes to be searched, so is significantly faster.
|
|
|
|
///
|
|
|
|
/// This function returns true on a successful match or false otherwise.
|
2016-05-25 18:22:14 +02:00
|
|
|
bool recognizeBSwapOrBitReverseIdiom(
|
2016-01-15 10:20:19 +01:00
|
|
|
Instruction *I, bool MatchBSwaps, bool MatchBitReversals,
|
|
|
|
SmallVectorImpl<Instruction *> &InsertedInsts);
|
|
|
|
|
2016-06-18 12:10:37 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Sanitizer utilities
|
|
|
|
//
|
|
|
|
|
|
|
|
/// Given a CallInst, check if it calls a string function known to CodeGen,
|
|
|
|
/// and mark it with NoBuiltin if so. To be used by sanitizers that intend
|
|
|
|
/// to intercept string functions and want to avoid converting them to target
|
|
|
|
/// specific instructions.
|
|
|
|
void maybeMarkSanitizerLibraryCallNoBuiltin(CallInst *CI,
|
|
|
|
const TargetLibraryInfo *TLI);
|
|
|
|
|
[GVNSink] GVNSink pass
This patch provides an initial prototype for a pass that sinks instructions based on GVN information, similar to GVNHoist. It is not yet ready for commiting but I've uploaded it to gather some initial thoughts.
This pass attempts to sink instructions into successors, reducing static
instruction count and enabling if-conversion.
We use a variant of global value numbering to decide what can be sunk.
Consider:
[ %a1 = add i32 %b, 1 ] [ %c1 = add i32 %d, 1 ]
[ %a2 = xor i32 %a1, 1 ] [ %c2 = xor i32 %c1, 1 ]
\ /
[ %e = phi i32 %a2, %c2 ]
[ add i32 %e, 4 ]
GVN would number %a1 and %c1 differently because they compute different
results - the VN of an instruction is a function of its opcode and the
transitive closure of its operands. This is the key property for hoisting
and CSE.
What we want when sinking however is for a numbering that is a function of
the *uses* of an instruction, which allows us to answer the question "if I
replace %a1 with %c1, will it contribute in an equivalent way to all
successive instructions?". The (new) PostValueTable class in GVN provides this
mapping.
This pass has some shown really impressive improvements especially for codesize already on internal benchmarks, so I have high hopes it can replace all the sinking logic in SimplifyCFG.
Differential revision: https://reviews.llvm.org/D24805
llvm-svn: 303850
2017-05-25 14:51:11 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Transform predicates
|
|
|
|
//
|
|
|
|
|
|
|
|
/// Given an instruction, is it legal to set operand OpIdx to a non-constant
|
|
|
|
/// value?
|
|
|
|
bool canReplaceOperandWithVariable(const Instruction *I, unsigned OpIdx);
|
|
|
|
|
2017-10-17 23:27:42 +02:00
|
|
|
} // end namespace llvm
|
2003-11-11 23:41:34 +01:00
|
|
|
|
2017-10-17 23:27:42 +02:00
|
|
|
#endif // LLVM_TRANSFORMS_UTILS_LOCAL_H
|