2003-09-30 20:37:50 +02:00
|
|
|
//===-- llvm/BasicBlock.h - Represent a basic block in the VM ---*- C++ -*-===//
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2004-01-15 05:37:10 +01:00
|
|
|
//
|
2006-06-05 18:29:06 +02:00
|
|
|
// This file contains the declaration of the BasicBlock class.
|
2008-05-23 23:05:58 +02:00
|
|
|
//
|
2001-06-06 22:29:01 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-10 01:45:19 +01:00
|
|
|
#ifndef LLVM_IR_BASICBLOCK_H
|
|
|
|
#define LLVM_IR_BASICBLOCK_H
|
2001-06-06 22:29:01 +02:00
|
|
|
|
2012-12-03 18:02:12 +01:00
|
|
|
#include "llvm/ADT/ilist.h"
|
2016-12-06 23:00:57 +01:00
|
|
|
#include "llvm/ADT/ilist_node.h"
|
|
|
|
#include "llvm/ADT/Twine.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/Instruction.h"
|
|
|
|
#include "llvm/IR/SymbolTableListTraits.h"
|
2016-12-06 23:00:57 +01:00
|
|
|
#include "llvm/IR/Value.h"
|
2013-05-01 22:59:00 +02:00
|
|
|
#include "llvm/Support/CBindingWrapping.h"
|
2017-05-06 00:30:37 +02:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2016-12-06 23:00:57 +01:00
|
|
|
#include "llvm-c/Types.h"
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstddef>
|
2001-06-06 22:29:01 +02:00
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
namespace llvm {
|
|
|
|
|
2014-08-12 02:05:15 +02:00
|
|
|
class CallInst;
|
2016-12-06 23:00:57 +01:00
|
|
|
class Function;
|
2011-08-12 22:24:12 +02:00
|
|
|
class LandingPadInst;
|
2009-08-11 19:45:13 +02:00
|
|
|
class LLVMContext;
|
2017-05-06 00:30:37 +02:00
|
|
|
class Module;
|
2016-12-06 23:00:57 +01:00
|
|
|
class TerminatorInst;
|
2017-05-06 00:30:37 +02:00
|
|
|
class ValueSymbolTable;
|
2015-04-03 03:20:33 +02:00
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief LLVM Basic Block Representation
|
|
|
|
///
|
2006-06-05 18:29:06 +02:00
|
|
|
/// This represents a single basic block in LLVM. A basic block is simply a
|
|
|
|
/// container of instructions that execute sequentially. Basic blocks are Values
|
|
|
|
/// because they are referenced by instructions such as branches and switch
|
|
|
|
/// tables. The type of a BasicBlock is "Type::LabelTy" because the basic block
|
|
|
|
/// represents a label to which a branch can jump.
|
|
|
|
///
|
2010-11-29 19:16:10 +01:00
|
|
|
/// A well formed basic block is formed of a list of non-terminating
|
|
|
|
/// instructions followed by a single TerminatorInst instruction.
|
|
|
|
/// TerminatorInst's may not occur in the middle of basic blocks, and must
|
2006-06-05 18:29:06 +02:00
|
|
|
/// terminate the blocks. The BasicBlock class allows malformed basic blocks to
|
|
|
|
/// occur because it may be useful in the intermediate stage of constructing or
|
|
|
|
/// modifying a program. However, the verifier will ensure that basic blocks
|
|
|
|
/// are "well formed".
|
[IR] De-virtualize ~Value to save a vptr
Summary:
Implements PR889
Removing the virtual table pointer from Value saves 1% of RSS when doing
LTO of llc on Linux. The impact on time was positive, but too noisy to
conclusively say that performance improved. Here is a link to the
spreadsheet with the original data:
https://docs.google.com/spreadsheets/d/1F4FHir0qYnV0MEp2sYYp_BuvnJgWlWPhWOwZ6LbW7W4/edit?usp=sharing
This change makes it invalid to directly delete a Value, User, or
Instruction pointer. Instead, such code can be rewritten to a null check
and a call Value::deleteValue(). Value objects tend to have their
lifetimes managed through iplist, so for the most part, this isn't a big
deal. However, there are some places where LLVM deletes values, and
those places had to be migrated to deleteValue. I have also created
llvm::unique_value, which has a custom deleter, so it can be used in
place of std::unique_ptr<Value>.
I had to add the "DerivedUser" Deleter escape hatch for MemorySSA, which
derives from User outside of lib/IR. Code in IR cannot include MemorySSA
headers or call the MemoryAccess object destructors without introducing
a circular dependency, so we need some level of indirection.
Unfortunately, no class derived from User may have any virtual methods,
because adding a virtual method would break User::getHungOffOperands(),
which assumes that it can find the use list immediately prior to the
User object. I've added a static_assert to the appropriate OperandTraits
templates to help people avoid this trap.
Reviewers: chandlerc, mehdi_amini, pete, dberlin, george.burgess.iv
Reviewed By: chandlerc
Subscribers: krytarowski, eraman, george.burgess.iv, mzolotukhin, Prazek, nlewycky, hans, inglorion, pcc, tejohnson, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D31261
llvm-svn: 303362
2017-05-18 19:24:10 +02:00
|
|
|
class BasicBlock final : public Value, // Basic blocks are data objects also
|
|
|
|
public ilist_node_with_parent<BasicBlock, Function> {
|
2004-10-27 18:14:51 +02:00
|
|
|
public:
|
2017-05-06 00:30:37 +02:00
|
|
|
using InstListType = SymbolTableList<Instruction>;
|
2015-10-07 22:05:10 +02:00
|
|
|
|
2009-02-27 09:41:37 +01:00
|
|
|
private:
|
2016-12-06 23:00:57 +01:00
|
|
|
friend class BlockAddress;
|
|
|
|
friend class SymbolTableListTraits<BasicBlock>;
|
|
|
|
|
2001-06-06 22:29:01 +02:00
|
|
|
InstListType InstList;
|
2007-04-17 05:26:42 +02:00
|
|
|
Function *Parent;
|
2002-06-25 18:12:52 +02:00
|
|
|
|
2002-09-06 23:31:57 +02:00
|
|
|
void setParent(Function *parent);
|
2001-06-06 22:29:01 +02:00
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Constructor.
|
2002-09-06 23:31:57 +02:00
|
|
|
///
|
2013-01-20 06:03:42 +01:00
|
|
|
/// If the function parameter is specified, the basic block is automatically
|
|
|
|
/// inserted at either the end of the function (if InsertBefore is null), or
|
|
|
|
/// before the specified basic block.
|
2009-08-13 23:58:54 +02:00
|
|
|
explicit BasicBlock(LLVMContext &C, const Twine &Name = "",
|
2014-04-09 08:08:46 +02:00
|
|
|
Function *Parent = nullptr,
|
|
|
|
BasicBlock *InsertBefore = nullptr);
|
2016-12-06 23:00:57 +01:00
|
|
|
|
2008-04-06 22:25:17 +02:00
|
|
|
public:
|
2016-12-06 23:00:57 +01:00
|
|
|
BasicBlock(const BasicBlock &) = delete;
|
|
|
|
BasicBlock &operator=(const BasicBlock &) = delete;
|
[IR] De-virtualize ~Value to save a vptr
Summary:
Implements PR889
Removing the virtual table pointer from Value saves 1% of RSS when doing
LTO of llc on Linux. The impact on time was positive, but too noisy to
conclusively say that performance improved. Here is a link to the
spreadsheet with the original data:
https://docs.google.com/spreadsheets/d/1F4FHir0qYnV0MEp2sYYp_BuvnJgWlWPhWOwZ6LbW7W4/edit?usp=sharing
This change makes it invalid to directly delete a Value, User, or
Instruction pointer. Instead, such code can be rewritten to a null check
and a call Value::deleteValue(). Value objects tend to have their
lifetimes managed through iplist, so for the most part, this isn't a big
deal. However, there are some places where LLVM deletes values, and
those places had to be migrated to deleteValue. I have also created
llvm::unique_value, which has a custom deleter, so it can be used in
place of std::unique_ptr<Value>.
I had to add the "DerivedUser" Deleter escape hatch for MemorySSA, which
derives from User outside of lib/IR. Code in IR cannot include MemorySSA
headers or call the MemoryAccess object destructors without introducing
a circular dependency, so we need some level of indirection.
Unfortunately, no class derived from User may have any virtual methods,
because adding a virtual method would break User::getHungOffOperands(),
which assumes that it can find the use list immediately prior to the
User object. I've added a static_assert to the appropriate OperandTraits
templates to help people avoid this trap.
Reviewers: chandlerc, mehdi_amini, pete, dberlin, george.burgess.iv
Reviewed By: chandlerc
Subscribers: krytarowski, eraman, george.burgess.iv, mzolotukhin, Prazek, nlewycky, hans, inglorion, pcc, tejohnson, dberlin, llvm-commits
Differential Revision: https://reviews.llvm.org/D31261
llvm-svn: 303362
2017-05-18 19:24:10 +02:00
|
|
|
~BasicBlock();
|
2016-12-06 23:00:57 +01:00
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Get the context in which this basic block lives.
|
2009-07-22 02:24:57 +02:00
|
|
|
LLVMContext &getContext() const;
|
2010-11-29 19:16:10 +01:00
|
|
|
|
2008-04-06 22:25:17 +02:00
|
|
|
/// Instruction iterators...
|
2017-05-06 00:30:37 +02:00
|
|
|
using iterator = InstListType::iterator;
|
|
|
|
using const_iterator = InstListType::const_iterator;
|
|
|
|
using reverse_iterator = InstListType::reverse_iterator;
|
|
|
|
using const_reverse_iterator = InstListType::const_reverse_iterator;
|
2008-04-06 22:25:17 +02:00
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Creates a new BasicBlock.
|
|
|
|
///
|
|
|
|
/// If the Parent parameter is specified, the basic block is automatically
|
|
|
|
/// inserted at either the end of the function (if InsertBefore is 0), or
|
|
|
|
/// before the specified basic block.
|
2010-11-29 19:16:10 +01:00
|
|
|
static BasicBlock *Create(LLVMContext &Context, const Twine &Name = "",
|
2014-04-09 08:08:46 +02:00
|
|
|
Function *Parent = nullptr,
|
|
|
|
BasicBlock *InsertBefore = nullptr) {
|
2009-08-13 23:58:54 +02:00
|
|
|
return new BasicBlock(Context, Name, Parent, InsertBefore);
|
2008-04-06 22:25:17 +02:00
|
|
|
}
|
2001-06-06 22:29:01 +02:00
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Return the enclosing method, or null if none.
|
2007-04-17 05:26:42 +02:00
|
|
|
const Function *getParent() const { return Parent; }
|
|
|
|
Function *getParent() { return Parent; }
|
2001-06-06 22:29:01 +02:00
|
|
|
|
2015-03-03 23:01:13 +01:00
|
|
|
/// \brief Return the module owning the function this basic block belongs to,
|
|
|
|
/// or nullptr it the function does not have a module.
|
|
|
|
///
|
|
|
|
/// Note: this is undefined behavior if the block does not have a parent.
|
2017-03-27 04:38:17 +02:00
|
|
|
const Module *getModule() const;
|
|
|
|
Module *getModule() {
|
|
|
|
return const_cast<Module *>(
|
|
|
|
static_cast<const BasicBlock *>(this)->getModule());
|
2017-01-22 07:53:04 +01:00
|
|
|
}
|
2014-02-26 00:25:17 +01:00
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Returns the terminator instruction if the block is well formed or
|
|
|
|
/// null if the block is not well formed.
|
2017-03-27 04:38:17 +02:00
|
|
|
const TerminatorInst *getTerminator() const LLVM_READONLY;
|
|
|
|
TerminatorInst *getTerminator() {
|
|
|
|
return const_cast<TerminatorInst *>(
|
|
|
|
static_cast<const BasicBlock *>(this)->getTerminator());
|
2017-01-22 07:53:04 +01:00
|
|
|
}
|
2010-11-29 19:16:10 +01:00
|
|
|
|
Introduce @llvm.experimental.deoptimize
Summary:
This intrinsic, together with deoptimization operand bundles, allow
frontends to express transfer of control and frame-local state from
one (typically more specialized, hence faster) version of a function
into another (typically more generic, hence slower) version.
In languages with a fully integrated managed runtime this intrinsic can
be used to implement "uncommon trap" like functionality. In unmanaged
languages like C and C++, this intrinsic can be used to represent the
slow paths of specialized functions.
Note: this change does not address how `@llvm.experimental_deoptimize`
is lowered. That will be done in a later change.
Reviewers: chandlerc, rnk, atrick, reames
Subscribers: llvm-commits, kmod, mjacob, maksfb, mcrosier, JosephTremoulet
Differential Revision: http://reviews.llvm.org/D17732
llvm-svn: 263281
2016-03-11 20:08:34 +01:00
|
|
|
/// \brief Returns the call instruction calling @llvm.experimental.deoptimize
|
|
|
|
/// prior to the terminating return instruction of this basic block, if such a
|
|
|
|
/// call is present. Otherwise, returns null.
|
2017-03-27 04:38:17 +02:00
|
|
|
const CallInst *getTerminatingDeoptimizeCall() const;
|
|
|
|
CallInst *getTerminatingDeoptimizeCall() {
|
|
|
|
return const_cast<CallInst *>(
|
|
|
|
static_cast<const BasicBlock *>(this)->getTerminatingDeoptimizeCall());
|
Introduce @llvm.experimental.deoptimize
Summary:
This intrinsic, together with deoptimization operand bundles, allow
frontends to express transfer of control and frame-local state from
one (typically more specialized, hence faster) version of a function
into another (typically more generic, hence slower) version.
In languages with a fully integrated managed runtime this intrinsic can
be used to implement "uncommon trap" like functionality. In unmanaged
languages like C and C++, this intrinsic can be used to represent the
slow paths of specialized functions.
Note: this change does not address how `@llvm.experimental_deoptimize`
is lowered. That will be done in a later change.
Reviewers: chandlerc, rnk, atrick, reames
Subscribers: llvm-commits, kmod, mjacob, maksfb, mcrosier, JosephTremoulet
Differential Revision: http://reviews.llvm.org/D17732
llvm-svn: 263281
2016-03-11 20:08:34 +01:00
|
|
|
}
|
|
|
|
|
2014-08-12 02:05:15 +02:00
|
|
|
/// \brief Returns the call instruction marked 'musttail' prior to the
|
|
|
|
/// terminating return instruction of this basic block, if such a call is
|
|
|
|
/// present. Otherwise, returns null.
|
2017-03-27 04:38:17 +02:00
|
|
|
const CallInst *getTerminatingMustTailCall() const;
|
|
|
|
CallInst *getTerminatingMustTailCall() {
|
|
|
|
return const_cast<CallInst *>(
|
|
|
|
static_cast<const BasicBlock *>(this)->getTerminatingMustTailCall());
|
2014-08-12 02:05:15 +02:00
|
|
|
}
|
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Returns a pointer to the first instruction in this block that is
|
|
|
|
/// not a PHINode instruction.
|
|
|
|
///
|
|
|
|
/// When adding instructions to the beginning of the basic block, they should
|
|
|
|
/// be added before the returned value, not before the first instruction,
|
|
|
|
/// which might be PHI. Returns 0 is there's no non-PHI instruction.
|
2017-03-27 04:38:17 +02:00
|
|
|
const Instruction* getFirstNonPHI() const;
|
|
|
|
Instruction* getFirstNonPHI() {
|
|
|
|
return const_cast<Instruction *>(
|
|
|
|
static_cast<const BasicBlock *>(this)->getFirstNonPHI());
|
2008-05-23 23:05:58 +02:00
|
|
|
}
|
2010-04-02 23:49:27 +02:00
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Returns a pointer to the first instruction in this block that is not
|
|
|
|
/// a PHINode or a debug intrinsic.
|
2017-03-27 04:38:17 +02:00
|
|
|
const Instruction* getFirstNonPHIOrDbg() const;
|
|
|
|
Instruction* getFirstNonPHIOrDbg() {
|
|
|
|
return const_cast<Instruction *>(
|
|
|
|
static_cast<const BasicBlock *>(this)->getFirstNonPHIOrDbg());
|
2010-04-02 23:49:27 +02:00
|
|
|
}
|
2010-11-29 19:16:10 +01:00
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Returns a pointer to the first instruction in this block that is not
|
|
|
|
/// a PHINode, a debug intrinsic, or a lifetime intrinsic.
|
2017-03-27 04:38:17 +02:00
|
|
|
const Instruction* getFirstNonPHIOrDbgOrLifetime() const;
|
|
|
|
Instruction* getFirstNonPHIOrDbgOrLifetime() {
|
|
|
|
return const_cast<Instruction *>(
|
|
|
|
static_cast<const BasicBlock *>(this)->getFirstNonPHIOrDbgOrLifetime());
|
2011-06-30 22:14:24 +02:00
|
|
|
}
|
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Returns an iterator to the first instruction in this block that is
|
|
|
|
/// suitable for inserting a non-PHI instruction.
|
|
|
|
///
|
|
|
|
/// In particular, it skips all PHIs and LandingPad instructions.
|
2017-03-27 04:38:17 +02:00
|
|
|
const_iterator getFirstInsertionPt() const;
|
|
|
|
iterator getFirstInsertionPt() {
|
|
|
|
return static_cast<const BasicBlock *>(this)
|
|
|
|
->getFirstInsertionPt().getNonConst();
|
2011-08-16 22:42:52 +02:00
|
|
|
}
|
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Unlink 'this' from the containing function, but do not delete it.
|
2004-10-12 00:21:13 +02:00
|
|
|
void removeFromParent();
|
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Unlink 'this' from the containing function and delete it.
|
2015-04-03 03:20:33 +02:00
|
|
|
///
|
|
|
|
// \returns an iterator pointing to the element after the erased one.
|
2015-10-07 22:05:10 +02:00
|
|
|
SymbolTableList<BasicBlock>::iterator eraseFromParent();
|
2010-11-29 19:16:10 +01:00
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Unlink this basic block from its current function and insert it
|
|
|
|
/// into the function that \p MovePos lives in, right before \p MovePos.
|
2005-08-13 00:13:27 +02:00
|
|
|
void moveBefore(BasicBlock *MovePos);
|
2010-11-29 19:16:10 +01:00
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Unlink this basic block from its current function and insert it
|
|
|
|
/// right after \p MovePos in the function \p MovePos lives in.
|
2006-09-23 06:03:45 +02:00
|
|
|
void moveAfter(BasicBlock *MovePos);
|
2010-11-29 19:16:10 +01:00
|
|
|
|
2014-08-01 23:22:04 +02:00
|
|
|
/// \brief Insert unlinked basic block into a function.
|
|
|
|
///
|
|
|
|
/// Inserts an unlinked basic block into \c Parent. If \c InsertBefore is
|
|
|
|
/// provided, inserts before that basic block, otherwise inserts at the end.
|
|
|
|
///
|
|
|
|
/// \pre \a getParent() is \c nullptr.
|
|
|
|
void insertInto(Function *Parent, BasicBlock *InsertBefore = nullptr);
|
2004-10-12 00:21:13 +02:00
|
|
|
|
2014-05-06 07:05:59 +02:00
|
|
|
/// \brief Return the predecessor of this block if it has a single predecessor
|
|
|
|
/// block. Otherwise return a null pointer.
|
2017-03-27 04:38:17 +02:00
|
|
|
const BasicBlock *getSinglePredecessor() const;
|
|
|
|
BasicBlock *getSinglePredecessor() {
|
|
|
|
return const_cast<BasicBlock *>(
|
|
|
|
static_cast<const BasicBlock *>(this)->getSinglePredecessor());
|
2005-02-24 03:37:26 +01:00
|
|
|
}
|
2004-10-12 00:21:13 +02:00
|
|
|
|
2014-05-06 07:05:59 +02:00
|
|
|
/// \brief Return the predecessor of this block if it has a unique predecessor
|
|
|
|
/// block. Otherwise return a null pointer.
|
2013-01-20 06:03:42 +01:00
|
|
|
///
|
2010-11-29 19:16:10 +01:00
|
|
|
/// Note that unique predecessor doesn't mean single edge, there can be
|
2013-01-20 06:03:42 +01:00
|
|
|
/// multiple edges from the unique predecessor to this block (for example a
|
|
|
|
/// switch statement with multiple cases having the same destination).
|
2017-03-27 04:38:17 +02:00
|
|
|
const BasicBlock *getUniquePredecessor() const;
|
|
|
|
BasicBlock *getUniquePredecessor() {
|
|
|
|
return const_cast<BasicBlock *>(
|
|
|
|
static_cast<const BasicBlock *>(this)->getUniquePredecessor());
|
2008-12-11 11:36:07 +01:00
|
|
|
}
|
|
|
|
|
2015-05-15 19:54:48 +02:00
|
|
|
/// \brief Return the successor of this block if it has a single successor.
|
|
|
|
/// Otherwise return a null pointer.
|
|
|
|
///
|
|
|
|
/// This method is analogous to getSinglePredecessor above.
|
2017-03-27 04:38:17 +02:00
|
|
|
const BasicBlock *getSingleSuccessor() const;
|
|
|
|
BasicBlock *getSingleSuccessor() {
|
|
|
|
return const_cast<BasicBlock *>(
|
|
|
|
static_cast<const BasicBlock *>(this)->getSingleSuccessor());
|
2015-05-15 19:54:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Return the successor of this block if it has a unique successor.
|
|
|
|
/// Otherwise return a null pointer.
|
|
|
|
///
|
|
|
|
/// This method is analogous to getUniquePredecessor above.
|
2017-03-27 04:38:17 +02:00
|
|
|
const BasicBlock *getUniqueSuccessor() const;
|
|
|
|
BasicBlock *getUniqueSuccessor() {
|
|
|
|
return const_cast<BasicBlock *>(
|
|
|
|
static_cast<const BasicBlock *>(this)->getUniqueSuccessor());
|
Add a pass for inserting safepoints into (nearly) arbitrary IR
This pass is responsible for figuring out where to place call safepoints and safepoint polls. It doesn't actually make the relocations explicit; that's the job of the RewriteStatepointsForGC pass (http://reviews.llvm.org/D6975).
Note that this code is not yet finalized. Its moving in tree for incremental development, but further cleanup is needed and will happen over the next few days. It is not yet part of the standard pass order.
Planned changes in the near future:
- I plan on restructuring the statepoint rewrite to use the functions add to the IRBuilder a while back.
- In the current pass, the function "gc.safepoint_poll" is treated specially but is not an intrinsic. I plan to make identifying the poll function a property of the GCStrategy at some point in the near future.
- As follow on patches, I will be separating a collection of test cases we have out of tree and submitting them upstream.
- It's not explicit in the code, but these two patches are introducing a new state for a statepoint which looks a lot like a patchpoint. There's no a transient form which doesn't yet have the relocations explicitly represented, but does prevent reordering of memory operations. Once this is in, I need to update actually make this explicit by reserving the 'unused' argument of the statepoint as a flag, updating the docs, and making the code explicitly check for such a thing. This wasn't really planned, but once I split the two passes - which was done for other reasons - the intermediate state fell out. Just reminds us once again that we need to merge statepoints and patchpoints at some point in the not that distant future.
Future directions planned:
- Identifying more cases where a backedge safepoint isn't required to ensure timely execution of a safepoint poll.
- Tweaking the insertion process to generate easier to optimize IR. (For example, investigating making SplitBackedge) the default.
- Adding opt-in flags for a GCStrategy to use this pass. Once done, add this pass to the actual pass ordering.
Differential Revision: http://reviews.llvm.org/D6981
llvm-svn: 228090
2015-02-04 01:37:33 +01:00
|
|
|
}
|
|
|
|
|
2001-06-28 01:26:41 +02:00
|
|
|
//===--------------------------------------------------------------------===//
|
2002-09-06 23:31:57 +02:00
|
|
|
/// Instruction iterator methods
|
|
|
|
///
|
2001-06-28 01:26:41 +02:00
|
|
|
inline iterator begin() { return InstList.begin(); }
|
|
|
|
inline const_iterator begin() const { return InstList.begin(); }
|
|
|
|
inline iterator end () { return InstList.end(); }
|
|
|
|
inline const_iterator end () const { return InstList.end(); }
|
|
|
|
|
2012-12-27 13:00:56 +01:00
|
|
|
inline reverse_iterator rbegin() { return InstList.rbegin(); }
|
|
|
|
inline const_reverse_iterator rbegin() const { return InstList.rbegin(); }
|
|
|
|
inline reverse_iterator rend () { return InstList.rend(); }
|
|
|
|
inline const_reverse_iterator rend () const { return InstList.rend(); }
|
|
|
|
|
2004-11-15 20:02:35 +01:00
|
|
|
inline size_t size() const { return InstList.size(); }
|
2001-06-28 01:26:41 +02:00
|
|
|
inline bool empty() const { return InstList.empty(); }
|
2002-06-25 18:12:52 +02:00
|
|
|
inline const Instruction &front() const { return InstList.front(); }
|
|
|
|
inline Instruction &front() { return InstList.front(); }
|
2004-05-18 00:28:21 +02:00
|
|
|
inline const Instruction &back() const { return InstList.back(); }
|
|
|
|
inline Instruction &back() { return InstList.back(); }
|
2001-06-28 01:26:41 +02:00
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Return the underlying instruction list container.
|
2002-08-26 00:54:55 +02:00
|
|
|
///
|
2013-01-20 06:03:42 +01:00
|
|
|
/// Currently you need to access the underlying instruction list container
|
|
|
|
/// directly if you want to modify it.
|
2001-06-28 01:26:41 +02:00
|
|
|
const InstListType &getInstList() const { return InstList; }
|
|
|
|
InstListType &getInstList() { return InstList; }
|
2009-03-07 13:33:24 +01:00
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Returns a pointer to a member of the instruction list.
|
2015-10-06 20:33:43 +02:00
|
|
|
static InstListType BasicBlock::*getSublistAccess(Instruction*) {
|
2009-03-07 11:00:35 +01:00
|
|
|
return &BasicBlock::InstList;
|
|
|
|
}
|
2001-06-28 01:26:41 +02:00
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Returns a pointer to the symbol table if one exists.
|
2009-03-07 13:33:24 +01:00
|
|
|
ValueSymbolTable *getValueSymbolTable();
|
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Methods for support type inquiry through isa, cast, and dyn_cast.
|
2001-10-02 05:41:24 +02:00
|
|
|
static inline bool classof(const Value *V) {
|
2007-04-13 20:12:09 +02:00
|
|
|
return V->getValueID() == Value::BasicBlockVal;
|
2001-10-01 18:18:37 +02:00
|
|
|
}
|
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Cause all subinstructions to "let go" of all the references that
|
|
|
|
/// said subinstructions are maintaining.
|
2002-08-26 00:54:55 +02:00
|
|
|
///
|
2013-01-20 06:03:42 +01:00
|
|
|
/// This allows one to 'delete' a whole class at a time, even though there may
|
|
|
|
/// be circular references... first all references are dropped, and all use
|
|
|
|
/// counts go to zero. Then everything is delete'd for real. Note that no
|
|
|
|
/// operations are valid on an object that has "dropped all references",
|
|
|
|
/// except operator delete.
|
2001-06-06 22:29:01 +02:00
|
|
|
void dropAllReferences();
|
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Notify the BasicBlock that the predecessor \p Pred is no longer
|
|
|
|
/// able to reach it.
|
2002-08-26 00:54:55 +02:00
|
|
|
///
|
2013-01-20 06:03:42 +01:00
|
|
|
/// This is actually not used to update the Predecessor list, but is actually
|
|
|
|
/// used to update the PHI nodes that reside in the block. Note that this
|
|
|
|
/// should be called while the predecessor still refers to this block.
|
2008-04-25 18:53:59 +02:00
|
|
|
void removePredecessor(BasicBlock *Pred, bool DontDeleteUselessPHIs = false);
|
2001-06-29 07:21:42 +02:00
|
|
|
|
2015-07-31 19:58:14 +02:00
|
|
|
bool canSplitPredecessors() const;
|
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Split the basic block into two basic blocks at the specified
|
|
|
|
/// instruction.
|
|
|
|
///
|
|
|
|
/// Note that all instructions BEFORE the specified iterator stay as part of
|
|
|
|
/// the original basic block, an unconditional branch is added to the original
|
|
|
|
/// BB, and the rest of the instructions in the BB are moved to the new BB,
|
|
|
|
/// including the old terminator. The newly formed BasicBlock is returned.
|
|
|
|
/// This function invalidates the specified iterator.
|
2002-08-26 00:54:55 +02:00
|
|
|
///
|
2005-04-21 22:19:05 +02:00
|
|
|
/// Note that this only works on well formed basic blocks (must have a
|
2002-08-26 00:54:55 +02:00
|
|
|
/// terminator), and 'I' must not be the end of instruction list (which would
|
|
|
|
/// cause a degenerate basic block to be formed, having a terminator inside of
|
|
|
|
/// the basic block).
|
|
|
|
///
|
2009-09-02 03:14:16 +02:00
|
|
|
/// Also note that this doesn't preserve any passes. To split blocks while
|
|
|
|
/// keeping loop information consistent, use the SplitBlock utility function.
|
2009-07-25 06:41:11 +02:00
|
|
|
BasicBlock *splitBasicBlock(iterator I, const Twine &BBName = "");
|
2015-10-20 00:06:09 +02:00
|
|
|
BasicBlock *splitBasicBlock(Instruction *I, const Twine &BBName = "") {
|
|
|
|
return splitBasicBlock(I->getIterator(), BBName);
|
|
|
|
}
|
2009-10-29 01:09:08 +01:00
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Returns true if there are any uses of this basic block other than
|
|
|
|
/// direct branches, switches, etc. to it.
|
2009-12-29 03:14:09 +01:00
|
|
|
bool hasAddressTaken() const { return getSubclassDataFromValue() != 0; }
|
2010-11-29 19:16:10 +01:00
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Update all phi nodes in this basic block's successors to refer to
|
|
|
|
/// basic block \p New instead of to it.
|
2011-06-23 11:09:15 +02:00
|
|
|
void replaceSuccessorsPhiUsesWith(BasicBlock *New);
|
|
|
|
|
2015-07-31 19:58:14 +02:00
|
|
|
/// \brief Return true if this basic block is an exception handling block.
|
|
|
|
bool isEHPad() const { return getFirstNonPHI()->isEHPad(); }
|
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Return true if this basic block is a landing pad.
|
|
|
|
///
|
|
|
|
/// Being a ``landing pad'' means that the basic block is the destination of
|
|
|
|
/// the 'unwind' edge of an invoke instruction.
|
2011-08-12 22:24:12 +02:00
|
|
|
bool isLandingPad() const;
|
|
|
|
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Return the landingpad instruction associated with the landing pad.
|
2012-01-31 01:26:24 +01:00
|
|
|
const LandingPadInst *getLandingPadInst() const;
|
2017-03-27 07:46:58 +02:00
|
|
|
LandingPadInst *getLandingPadInst() {
|
|
|
|
return const_cast<LandingPadInst *>(
|
|
|
|
static_cast<const BasicBlock *>(this)->getLandingPadInst());
|
|
|
|
}
|
2011-08-12 22:24:12 +02:00
|
|
|
|
2009-10-30 23:33:29 +01:00
|
|
|
private:
|
2013-01-20 06:03:42 +01:00
|
|
|
/// \brief Increment the internal refcount of the number of BlockAddresses
|
|
|
|
/// referencing this BasicBlock by \p Amt.
|
|
|
|
///
|
|
|
|
/// This is almost always 0, sometimes one possibly, but almost never 2, and
|
|
|
|
/// inconceivably 3 or more.
|
2009-10-30 23:33:29 +01:00
|
|
|
void AdjustBlockAddressRefCount(int Amt) {
|
2009-12-29 03:14:09 +01:00
|
|
|
setValueSubclassData(getSubclassDataFromValue()+Amt);
|
|
|
|
assert((int)(signed char)getSubclassDataFromValue() >= 0 &&
|
|
|
|
"Refcount wrap-around");
|
|
|
|
}
|
2016-12-06 23:00:57 +01:00
|
|
|
|
2013-01-20 06:12:35 +01:00
|
|
|
/// \brief Shadow Value::setValueSubclassData with a private forwarding method
|
|
|
|
/// so that any future subclasses cannot accidentally use it.
|
2009-12-29 03:14:09 +01:00
|
|
|
void setValueSubclassData(unsigned short D) {
|
|
|
|
Value::setValueSubclassData(D);
|
2009-10-30 23:33:29 +01:00
|
|
|
}
|
2001-06-06 22:29:01 +02:00
|
|
|
};
|
|
|
|
|
2013-05-01 22:59:00 +02:00
|
|
|
// Create wrappers for C Binding types (see CBindingWrapping.h).
|
|
|
|
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock, LLVMBasicBlockRef)
|
|
|
|
|
2016-12-06 23:00:57 +01:00
|
|
|
} // end namespace llvm
|
2003-11-11 23:41:34 +01:00
|
|
|
|
2016-12-06 23:00:57 +01:00
|
|
|
#endif // LLVM_IR_BASICBLOCK_H
|