[clang] [llvm] [LLVM] Add InsertPosition union-type to remove overloads of Instruction-creation (PR #94226)
Stephen Tozer via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 3 07:13:08 PDT 2024
https://github.com/SLTozer created https://github.com/llvm/llvm-project/pull/94226
This patch follows the previous PR https://github.com/llvm/llvm-project/pull/94224 and contains that patch's commit; to view the changes for only this patch, review only the second commit.
This patch builds off the previous PR to simplify instruction creation, by replacing all overloads of instruction constructors/Create methods that are identical other than the `Instruction *InsertBefore`/`BasicBlock *InsertAtEnd`/`BasicBlock::iterator InsertBefore` argument with a single version that takes an `InsertPosition` argument. The `InsertPosition` class can be implicitly constructed from any of the above, internally converting them to the appropriate `BasicBlock::iterator` value which can then be used to insert the instruction (or to not insert it if an invalid iterator is passed).
The upshot of this is that code will be deduplicated, and all callsites will switch to calling the new unified version without any changes needed to make the compiler happy. There is at least one exception to this; the construction of `InsertPosition` is a user-defined conversion, so any caller that was already relying on a different user-defined conversion won't work. In all of LLVM and Clang this happens exactly once: at `clang/lib/CodeGen/CGExpr.cpp:123` we try to construct an alloca with an `AssertingVH<Instruction>` argument, which must now be explicitly cast to an `Instruction*`. If this is more common elsewhere, it could be fixed by adding an appropriate constructor to `InsertPosition`.
The end result of this is [performance-neutral](http://llvm-compile-time-tracker.com/compare.php?from=b2bd024384b484647da9fd9863bf6f77b5731949&to=3950bc6991675714782e05f732ae4b1ce7b6bc25&stat=instructions%3Au), with no significant impact on the geomean performance (albeit with some specific projects seeing a compile time increase), and a slight reduction in clang build time and file size. Besides reducing line count heavily and simplifying code, this helps build towards [the proposal to rewrite the instruction-insertion interface](https://discourse.llvm.org/t/rfc-rewriting-the-instruction-insertion-interface/78494/1), which will help reduce future errors relating to incorrect instruction insertion in the presence of debug records. Getting this single large change in now will also make it much easier to deprecate the `Instruction*` insertion arguments, [as proposed on discourse](https://discourse.llvm.org/t/psa-instruction-constructors-changing-to-iterator-only-insertion/77845/1), as we can do so with a single `LLVM_DEPRECATED` tag rather than needing to update every single method.
>From 537c8f80bfed595ca3f061a2d53b5a8f5ce7802e Mon Sep 17 00:00:00 2001
From: Stephen Tozer <stephen.tozer at sony.com>
Date: Fri, 31 May 2024 18:14:06 +0100
Subject: [PATCH 1/2] Add option to store Parent-pointer in ilist_node_base
---
llvm/include/llvm/ADT/ilist_base.h | 4 +-
llvm/include/llvm/ADT/ilist_iterator.h | 10 +++++
llvm/include/llvm/ADT/ilist_node.h | 11 +++++
llvm/include/llvm/ADT/ilist_node_base.h | 51 ++++++++++++++++++++--
llvm/include/llvm/ADT/ilist_node_options.h | 43 +++++++++++++++---
llvm/include/llvm/IR/BasicBlock.h | 10 +++--
llvm/include/llvm/IR/Instruction.h | 15 ++++---
llvm/include/llvm/IR/ValueSymbolTable.h | 4 +-
llvm/lib/IR/BasicBlock.cpp | 5 ++-
llvm/lib/IR/Instruction.cpp | 25 +++++------
10 files changed, 140 insertions(+), 38 deletions(-)
diff --git a/llvm/include/llvm/ADT/ilist_base.h b/llvm/include/llvm/ADT/ilist_base.h
index b8c098b951ade..000253a26012b 100644
--- a/llvm/include/llvm/ADT/ilist_base.h
+++ b/llvm/include/llvm/ADT/ilist_base.h
@@ -15,9 +15,9 @@
namespace llvm {
/// Implementations of list algorithms using ilist_node_base.
-template <bool EnableSentinelTracking> class ilist_base {
+template <bool EnableSentinelTracking, class ParentPtrTy> class ilist_base {
public:
- using node_base_type = ilist_node_base<EnableSentinelTracking>;
+ using node_base_type = ilist_node_base<EnableSentinelTracking, ParentPtrTy>;
static void insertBeforeImpl(node_base_type &Next, node_base_type &N) {
node_base_type &Prev = *Next.getPrev();
diff --git a/llvm/include/llvm/ADT/ilist_iterator.h b/llvm/include/llvm/ADT/ilist_iterator.h
index 2393c4d2c403c..635e050e0d09a 100644
--- a/llvm/include/llvm/ADT/ilist_iterator.h
+++ b/llvm/include/llvm/ADT/ilist_iterator.h
@@ -70,6 +70,7 @@ class ilist_iterator : ilist_detail::SpecificNodeAccess<OptionsT> {
using iterator_category = std::bidirectional_iterator_tag;
using const_pointer = typename OptionsT::const_pointer;
using const_reference = typename OptionsT::const_reference;
+ using parent_ptr_ty = typename OptionsT::parent_ptr_ty;
private:
using node_pointer = typename Traits::node_pointer;
@@ -101,6 +102,8 @@ class ilist_iterator : ilist_detail::SpecificNodeAccess<OptionsT> {
return *this;
}
+ parent_ptr_ty getNodeParent() { return NodePtr->getNodeBaseParent(); }
+
/// Explicit conversion between forward/reverse iterators.
///
/// Translate between forward and reverse iterators without changing range
@@ -168,6 +171,8 @@ class ilist_iterator : ilist_detail::SpecificNodeAccess<OptionsT> {
return tmp;
}
+ bool isValid() const { return NodePtr; }
+
/// Get the underlying ilist_node.
node_pointer getNodePtr() const { return static_cast<node_pointer>(NodePtr); }
@@ -195,6 +200,7 @@ class ilist_iterator_w_bits : ilist_detail::SpecificNodeAccess<OptionsT> {
using iterator_category = std::bidirectional_iterator_tag;
using const_pointer = typename OptionsT::const_pointer;
using const_reference = typename OptionsT::const_reference;
+ using parent_ptr_ty = typename OptionsT::parent_ptr_ty;
private:
using node_pointer = typename Traits::node_pointer;
@@ -319,6 +325,10 @@ class ilist_iterator_w_bits : ilist_detail::SpecificNodeAccess<OptionsT> {
return tmp;
}
+ parent_ptr_ty getNodeParent() { return NodePtr->getNodeBaseParent(); }
+
+ bool isValid() const { return NodePtr; }
+
/// Get the underlying ilist_node.
node_pointer getNodePtr() const { return static_cast<node_pointer>(NodePtr); }
diff --git a/llvm/include/llvm/ADT/ilist_node.h b/llvm/include/llvm/ADT/ilist_node.h
index 3b6f0dcc7b5e9..ec615497abee1 100644
--- a/llvm/include/llvm/ADT/ilist_node.h
+++ b/llvm/include/llvm/ADT/ilist_node.h
@@ -118,7 +118,9 @@ template <class OptionsT> class ilist_node_impl : OptionsT::node_base_type {
}
// Under-approximation, but always available for assertions.
+ using node_base_type::getNodeBaseParent;
using node_base_type::isKnownSentinel;
+ using node_base_type::setNodeBaseParent;
/// Check whether this is the sentinel node.
///
@@ -171,6 +173,15 @@ template <class OptionsT> class ilist_node_impl : OptionsT::node_base_type {
/// }
/// \endexample
///
+/// When the \a ilist_parent<ParentTy> option is passed to an ilist_node and the
+/// owning ilist, each node contains a pointer to the ilist's owner. This
+/// pointer does not have any automatic behaviour; set it manually, including
+/// for the sentinel node when the list is created. The primary benefit of this
+/// over declaring and using this pointer in the final node class is that the
+/// pointer will be added in the sentinel, meaning that you can safely use \a
+/// ilist_iterator::getNodeParent() to get the node parent from any valid (i.e.
+/// non-null) iterator, even a sentinel value.
+///
/// See \a is_valid_option for steps on adding a new option.
template <class T, class... Options>
class ilist_node
diff --git a/llvm/include/llvm/ADT/ilist_node_base.h b/llvm/include/llvm/ADT/ilist_node_base.h
index f6c518e6eed7a..e396bb22fca02 100644
--- a/llvm/include/llvm/ADT/ilist_node_base.h
+++ b/llvm/include/llvm/ADT/ilist_node_base.h
@@ -16,9 +16,9 @@ namespace llvm {
/// Base class for ilist nodes.
///
/// Optionally tracks whether this node is the sentinel.
-template <bool EnableSentinelTracking> class ilist_node_base;
+template <bool EnableSentinelTracking, class ParentPtrTy> class ilist_node_base;
-template <> class ilist_node_base<false> {
+template <> class ilist_node_base<false, void> {
ilist_node_base *Prev = nullptr;
ilist_node_base *Next = nullptr;
@@ -28,11 +28,14 @@ template <> class ilist_node_base<false> {
ilist_node_base *getPrev() const { return Prev; }
ilist_node_base *getNext() const { return Next; }
+ void setNodeBaseParent(void) {}
+ inline void getNodeBaseParent() const {}
+
bool isKnownSentinel() const { return false; }
void initializeSentinel() {}
};
-template <> class ilist_node_base<true> {
+template <> class ilist_node_base<true, void> {
PointerIntPair<ilist_node_base *, 1> PrevAndSentinel;
ilist_node_base *Next = nullptr;
@@ -42,6 +45,48 @@ template <> class ilist_node_base<true> {
ilist_node_base *getPrev() const { return PrevAndSentinel.getPointer(); }
ilist_node_base *getNext() const { return Next; }
+ void setNodeBaseParent(void) {}
+ inline void getNodeBaseParent() const {}
+
+ bool isSentinel() const { return PrevAndSentinel.getInt(); }
+ bool isKnownSentinel() const { return isSentinel(); }
+ void initializeSentinel() { PrevAndSentinel.setInt(true); }
+};
+
+template <class ParentPtrTy> class ilist_node_base<false, ParentPtrTy> {
+ ilist_node_base *Prev = nullptr;
+ ilist_node_base *Next = nullptr;
+ ParentPtrTy Parent = nullptr;
+
+public:
+ void setPrev(ilist_node_base *Prev) { this->Prev = Prev; }
+ void setNext(ilist_node_base *Next) { this->Next = Next; }
+ ilist_node_base *getPrev() const { return Prev; }
+ ilist_node_base *getNext() const { return Next; }
+
+ void setNodeBaseParent(ParentPtrTy Parent) { this->Parent = Parent; }
+ inline const ParentPtrTy getNodeBaseParent() const { return Parent; }
+ inline ParentPtrTy getNodeBaseParent() { return Parent; }
+
+ bool isKnownSentinel() const { return false; }
+ void initializeSentinel() {}
+};
+
+template <class ParentPtrTy> class ilist_node_base<true, ParentPtrTy> {
+ PointerIntPair<ilist_node_base *, 1> PrevAndSentinel;
+ ilist_node_base *Next = nullptr;
+ ParentPtrTy Parent = nullptr;
+
+public:
+ void setPrev(ilist_node_base *Prev) { PrevAndSentinel.setPointer(Prev); }
+ void setNext(ilist_node_base *Next) { this->Next = Next; }
+ ilist_node_base *getPrev() const { return PrevAndSentinel.getPointer(); }
+ ilist_node_base *getNext() const { return Next; }
+
+ void setNodeBaseParent(ParentPtrTy Parent) { this->Parent = Parent; }
+ inline const ParentPtrTy getNodeBaseParent() const { return Parent; }
+ inline ParentPtrTy getNodeBaseParent() { return Parent; }
+
bool isSentinel() const { return PrevAndSentinel.getInt(); }
bool isKnownSentinel() const { return isSentinel(); }
void initializeSentinel() { PrevAndSentinel.setInt(true); }
diff --git a/llvm/include/llvm/ADT/ilist_node_options.h b/llvm/include/llvm/ADT/ilist_node_options.h
index e6e1068953e36..aa32162cd51e4 100644
--- a/llvm/include/llvm/ADT/ilist_node_options.h
+++ b/llvm/include/llvm/ADT/ilist_node_options.h
@@ -15,8 +15,8 @@
namespace llvm {
-template <bool EnableSentinelTracking> class ilist_node_base;
-template <bool EnableSentinelTracking> class ilist_base;
+template <bool EnableSentinelTracking, class ParentPtrTy> class ilist_node_base;
+template <bool EnableSentinelTracking, class ParentPtrTy> class ilist_base;
/// Option to choose whether to track sentinels.
///
@@ -39,6 +39,19 @@ template <class Tag> struct ilist_tag {};
/// iterator class to store that information.
template <bool ExtraIteratorBits> struct ilist_iterator_bits {};
+/// Option to add a pointer to this list's owner in every node.
+///
+/// This option causes the \a ilist_base_node for this list to contain a pointer
+/// ParentTy *Parent, returned by \a ilist_base_node::getNodeBaseParent() and
+/// set by \a ilist_base_node::setNodeBaseParent(ParentTy *Parent). The parent
+/// value is not set automatically; the ilist owner should set itself as the
+/// parent of the list sentinel, and the parent should be set on each node
+/// inserted into the list. This value is also not used by
+/// \a ilist_node_with_parent::getNodeParent(), but is used by \a
+/// ilist_iterator::getNodeParent(), which allows the parent to be fetched from
+/// any valid (non-null) iterator to this list, including the sentinel.
+template <class ParentTy> struct ilist_parent {};
+
namespace ilist_detail {
/// Helper trait for recording whether an option is specified explicitly.
@@ -114,6 +127,21 @@ template <> struct extract_iterator_bits<> : std::false_type, is_implicit {};
template <bool IteratorBits>
struct is_valid_option<ilist_iterator_bits<IteratorBits>> : std::true_type {};
+/// Extract node parent option.
+///
+/// Look through \p Options for the \a ilist_parent option, pulling out the
+/// custom parent type, using void as a default.
+template <class... Options> struct extract_parent;
+template <class ParentTy, class... Options>
+struct extract_parent<ilist_parent<ParentTy>, Options...> {
+ typedef ParentTy *type;
+};
+template <class Option1, class... Options>
+struct extract_parent<Option1, Options...> : extract_parent<Options...> {};
+template <> struct extract_parent<> { typedef void type; };
+template <class ParentTy>
+struct is_valid_option<ilist_parent<ParentTy>> : std::true_type {};
+
/// Check whether options are valid.
///
/// The conjunction of \a is_valid_option on each individual option.
@@ -128,7 +156,7 @@ struct check_options<Option1, Options...>
///
/// This is usually computed via \a compute_node_options.
template <class T, bool EnableSentinelTracking, bool IsSentinelTrackingExplicit,
- class TagT, bool HasIteratorBits>
+ class TagT, bool HasIteratorBits, class ParentPtrTy>
struct node_options {
typedef T value_type;
typedef T *pointer;
@@ -140,15 +168,18 @@ struct node_options {
static const bool is_sentinel_tracking_explicit = IsSentinelTrackingExplicit;
static const bool has_iterator_bits = HasIteratorBits;
typedef TagT tag;
- typedef ilist_node_base<enable_sentinel_tracking> node_base_type;
- typedef ilist_base<enable_sentinel_tracking> list_base_type;
+ typedef ParentPtrTy parent_ptr_ty;
+ typedef ilist_node_base<enable_sentinel_tracking, parent_ptr_ty>
+ node_base_type;
+ typedef ilist_base<enable_sentinel_tracking, parent_ptr_ty> list_base_type;
};
template <class T, class... Options> struct compute_node_options {
typedef node_options<T, extract_sentinel_tracking<Options...>::value,
extract_sentinel_tracking<Options...>::is_explicit,
typename extract_tag<Options...>::type,
- extract_iterator_bits<Options...>::value>
+ extract_iterator_bits<Options...>::value,
+ typename extract_parent<Options...>::type>
type;
};
diff --git a/llvm/include/llvm/IR/BasicBlock.h b/llvm/include/llvm/IR/BasicBlock.h
index e1220966e7e6e..80067f2652a2b 100644
--- a/llvm/include/llvm/IR/BasicBlock.h
+++ b/llvm/include/llvm/IR/BasicBlock.h
@@ -59,7 +59,8 @@ class DbgMarker;
class BasicBlock final : public Value, // Basic blocks are data objects also
public ilist_node_with_parent<BasicBlock, Function> {
public:
- using InstListType = SymbolTableList<Instruction, ilist_iterator_bits<true>>;
+ using InstListType = SymbolTableList<Instruction, ilist_iterator_bits<true>,
+ ilist_parent<BasicBlock>>;
/// Flag recording whether or not this block stores debug-info in the form
/// of intrinsic instructions (false) or non-instruction records (true).
bool IsNewDbgInfoFormat;
@@ -172,10 +173,11 @@ class BasicBlock final : public Value, // Basic blocks are data objects also
friend BasicBlock::iterator Instruction::eraseFromParent();
friend BasicBlock::iterator Instruction::insertInto(BasicBlock *BB,
BasicBlock::iterator It);
- friend class llvm::SymbolTableListTraits<llvm::Instruction,
- ilist_iterator_bits<true>>;
+ friend class llvm::SymbolTableListTraits<
+ llvm::Instruction, ilist_iterator_bits<true>, ilist_parent<BasicBlock>>;
friend class llvm::ilist_node_with_parent<llvm::Instruction, llvm::BasicBlock,
- ilist_iterator_bits<true>>;
+ ilist_iterator_bits<true>,
+ ilist_parent<BasicBlock>>;
// Friendly methods that need to access us for the maintenence of
// debug-info attachments.
diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h
index 249be2799fa93..e1cb362ad20d0 100644
--- a/llvm/include/llvm/IR/Instruction.h
+++ b/llvm/include/llvm/IR/Instruction.h
@@ -46,11 +46,13 @@ getDbgRecordRange(DbgMarker *);
class Instruction : public User,
public ilist_node_with_parent<Instruction, BasicBlock,
- ilist_iterator_bits<true>> {
+ ilist_iterator_bits<true>,
+ ilist_parent<BasicBlock>> {
public:
- using InstListType = SymbolTableList<Instruction, ilist_iterator_bits<true>>;
+ using InstListType = SymbolTableList<Instruction, ilist_iterator_bits<true>,
+ ilist_parent<BasicBlock>>;
+
private:
- BasicBlock *Parent;
DebugLoc DbgLoc; // 'dbg' Metadata cache.
/// Relative order of this instruction in its parent basic block. Used for
@@ -149,8 +151,8 @@ class Instruction : public User,
Instruction *user_back() { return cast<Instruction>(*user_begin());}
const Instruction *user_back() const { return cast<Instruction>(*user_begin());}
- inline const BasicBlock *getParent() const { return Parent; }
- inline BasicBlock *getParent() { return Parent; }
+ inline const BasicBlock *getParent() const { return getNodeBaseParent(); }
+ inline BasicBlock *getParent() { return getNodeBaseParent(); }
/// Return the module owning the function this instruction belongs to
/// or nullptr it the function does not have a module.
@@ -980,7 +982,8 @@ class Instruction : public User,
};
private:
- friend class SymbolTableListTraits<Instruction, ilist_iterator_bits<true>>;
+ friend class SymbolTableListTraits<Instruction, ilist_iterator_bits<true>,
+ ilist_parent<BasicBlock>>;
friend class BasicBlock; // For renumbering.
// Shadow Value::setValueSubclassData with a private forwarding method so that
diff --git a/llvm/include/llvm/IR/ValueSymbolTable.h b/llvm/include/llvm/IR/ValueSymbolTable.h
index 6350f6a2435e4..cd1dbbe1688a1 100644
--- a/llvm/include/llvm/IR/ValueSymbolTable.h
+++ b/llvm/include/llvm/IR/ValueSymbolTable.h
@@ -28,6 +28,7 @@ class GlobalIFunc;
class GlobalVariable;
class Instruction;
template <bool ExtraIteratorBits> struct ilist_iterator_bits;
+template <class ParentTy> struct ilist_parent;
template <unsigned InternalLen> class SmallString;
template <typename ValueSubClass, typename ... Args> class SymbolTableListTraits;
@@ -42,7 +43,8 @@ class ValueSymbolTable {
friend class SymbolTableListTraits<GlobalAlias>;
friend class SymbolTableListTraits<GlobalIFunc>;
friend class SymbolTableListTraits<GlobalVariable>;
- friend class SymbolTableListTraits<Instruction, ilist_iterator_bits<true>>;
+ friend class SymbolTableListTraits<Instruction, ilist_iterator_bits<true>,
+ ilist_parent<BasicBlock>>;
friend class Value;
/// @name Types
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index 29f2cbf611fa3..a5199f36c1cb5 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -175,8 +175,8 @@ template <> void llvm::invalidateParentIListOrdering(BasicBlock *BB) {
// Explicit instantiation of SymbolTableListTraits since some of the methods
// are not in the public header file...
-template class llvm::SymbolTableListTraits<Instruction,
- ilist_iterator_bits<true>>;
+template class llvm::SymbolTableListTraits<
+ Instruction, ilist_iterator_bits<true>, ilist_parent<BasicBlock>>;
BasicBlock::BasicBlock(LLVMContext &C, const Twine &Name, Function *NewParent,
BasicBlock *InsertBefore)
@@ -189,6 +189,7 @@ BasicBlock::BasicBlock(LLVMContext &C, const Twine &Name, Function *NewParent,
assert(!InsertBefore &&
"Cannot insert block before another block with no function!");
+ end().getNodePtr()->setNodeBaseParent(this);
setName(Name);
if (NewParent)
setIsNewDbgInfoFormat(NewParent->IsNewDbgInfoFormat);
diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp
index 29272e627a1d1..8e8131113a230 100644
--- a/llvm/lib/IR/Instruction.cpp
+++ b/llvm/lib/IR/Instruction.cpp
@@ -27,8 +27,7 @@ using namespace llvm;
Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
InstListType::iterator InsertBefore)
- : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
-
+ : User(ty, Value::InstructionVal + it, Ops, NumOps) {
// When called with an iterator, there must be a block to insert into.
BasicBlock *BB = InsertBefore->getParent();
assert(BB && "Instruction to insert before is not in a basic block!");
@@ -37,7 +36,7 @@ Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
Instruction *InsertBefore)
- : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
+ : User(ty, Value::InstructionVal + it, Ops, NumOps) {
// If requested, insert this instruction into a basic block...
if (InsertBefore) {
@@ -49,15 +48,14 @@ Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
BasicBlock *InsertAtEnd)
- : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
-
+ : User(ty, Value::InstructionVal + it, Ops, NumOps) {
// If requested, append this instruction into the basic block.
if (InsertAtEnd)
insertInto(InsertAtEnd, InsertAtEnd->end());
}
Instruction::~Instruction() {
- assert(!Parent && "Instruction still linked in the program!");
+ assert(!getParent() && "Instruction still linked in the program!");
// Replace any extant metadata uses of this instruction with undef to
// preserve debug info accuracy. Some alternatives include:
@@ -76,9 +74,7 @@ Instruction::~Instruction() {
setMetadata(LLVMContext::MD_DIAssignID, nullptr);
}
-void Instruction::setParent(BasicBlock *P) {
- Parent = P;
-}
+void Instruction::setParent(BasicBlock *P) { setNodeBaseParent(P); }
const Module *Instruction::getModule() const {
return getParent()->getModule();
@@ -96,7 +92,7 @@ void Instruction::removeFromParent() {
}
void Instruction::handleMarkerRemoval() {
- if (!Parent->IsNewDbgInfoFormat || !DebugMarker)
+ if (!getParent()->IsNewDbgInfoFormat || !DebugMarker)
return;
DebugMarker->removeMarker();
@@ -329,11 +325,12 @@ void Instruction::dropOneDbgRecord(DbgRecord *DVR) {
}
bool Instruction::comesBefore(const Instruction *Other) const {
- assert(Parent && Other->Parent &&
+ assert(getParent() && Other->getParent() &&
"instructions without BB parents have no order");
- assert(Parent == Other->Parent && "cross-BB instruction order comparison");
- if (!Parent->isInstrOrderValid())
- Parent->renumberInstructions();
+ assert(getParent() == Other->getParent() &&
+ "cross-BB instruction order comparison");
+ if (!getParent()->isInstrOrderValid())
+ const_cast<BasicBlock *>(getParent())->renumberInstructions();
return Order < Other->Order;
}
>From ffd3172798a84396c8b535d527c8c4ab1597d87b Mon Sep 17 00:00:00 2001
From: Stephen Tozer <stephen.tozer at sony.com>
Date: Fri, 31 May 2024 14:04:05 +0100
Subject: [PATCH 2/2] Use InsertPosition for insertion in all Instructions and
IRBuilder
---
clang/lib/CodeGen/CGBuilder.h | 1 -
clang/lib/CodeGen/CGExpr.cpp | 3 +-
clang/lib/CodeGen/CodeGenFunction.cpp | 7 +-
clang/lib/CodeGen/CodeGenFunction.h | 1 -
llvm/include/llvm/IR/IRBuilder.h | 11 +-
llvm/include/llvm/IR/InstrTypes.h | 413 +------
llvm/include/llvm/IR/Instruction.h | 23 +-
llvm/include/llvm/IR/Instructions.h | 1606 ++++---------------------
llvm/lib/IR/Instruction.cpp | 32 +-
llvm/lib/IR/Instructions.cpp | 1430 ++--------------------
llvm/lib/Transforms/Scalar/SROA.cpp | 4 +-
11 files changed, 408 insertions(+), 3123 deletions(-)
diff --git a/clang/lib/CodeGen/CGBuilder.h b/clang/lib/CodeGen/CGBuilder.h
index 6dd9da7c4cade..ed07476f4047f 100644
--- a/clang/lib/CodeGen/CGBuilder.h
+++ b/clang/lib/CodeGen/CGBuilder.h
@@ -35,7 +35,6 @@ class CGBuilderInserter final : public llvm::IRBuilderDefaultInserter {
/// This forwards to CodeGenFunction::InsertHelper.
void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name,
- llvm::BasicBlock *BB,
llvm::BasicBlock::iterator InsertPt) const override;
private:
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index d6478cc6835d8..4e3a96d442400 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -120,7 +120,8 @@ llvm::AllocaInst *CodeGenFunction::CreateTempAlloca(llvm::Type *Ty,
Alloca = Builder.CreateAlloca(Ty, ArraySize, Name);
else
Alloca = new llvm::AllocaInst(Ty, CGM.getDataLayout().getAllocaAddrSpace(),
- ArraySize, Name, AllocaInsertPt);
+ ArraySize, Name,
+ (llvm::Instruction *)AllocaInsertPt);
if (Allocas) {
Allocas->Add(Alloca);
}
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index f0345f3b191b8..bbec920b9868a 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2635,7 +2635,6 @@ CodeGenFunction::SanitizerScope::~SanitizerScope() {
void CodeGenFunction::InsertHelper(llvm::Instruction *I,
const llvm::Twine &Name,
- llvm::BasicBlock *BB,
llvm::BasicBlock::iterator InsertPt) const {
LoopStack.InsertHelper(I);
if (IsSanitizerScope)
@@ -2643,11 +2642,11 @@ void CodeGenFunction::InsertHelper(llvm::Instruction *I,
}
void CGBuilderInserter::InsertHelper(
- llvm::Instruction *I, const llvm::Twine &Name, llvm::BasicBlock *BB,
+ llvm::Instruction *I, const llvm::Twine &Name,
llvm::BasicBlock::iterator InsertPt) const {
- llvm::IRBuilderDefaultInserter::InsertHelper(I, Name, BB, InsertPt);
+ llvm::IRBuilderDefaultInserter::InsertHelper(I, Name, InsertPt);
if (CGF)
- CGF->InsertHelper(I, Name, BB, InsertPt);
+ CGF->InsertHelper(I, Name, InsertPt);
}
// Emits an error if we don't have a valid set of target features for the
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 45585361a4fc9..e3617395895ab 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -345,7 +345,6 @@ class CodeGenFunction : public CodeGenTypeCache {
/// CGBuilder insert helper. This function is called after an
/// instruction is created using Builder.
void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name,
- llvm::BasicBlock *BB,
llvm::BasicBlock::iterator InsertPt) const;
/// CurFuncDecl - Holds the Decl for the current outermost
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 40a9cf507248a..9a9299960a121 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -63,10 +63,10 @@ class IRBuilderDefaultInserter {
virtual ~IRBuilderDefaultInserter();
virtual void InsertHelper(Instruction *I, const Twine &Name,
- BasicBlock *BB,
BasicBlock::iterator InsertPt) const {
- if (BB)
- I->insertInto(BB, InsertPt);
+ if (InsertPt.isValid()) {
+ I->insertInto(InsertPt.getNodeParent(), InsertPt);
+ }
I->setName(Name);
}
};
@@ -83,9 +83,8 @@ class IRBuilderCallbackInserter : public IRBuilderDefaultInserter {
: Callback(std::move(Callback)) {}
void InsertHelper(Instruction *I, const Twine &Name,
- BasicBlock *BB,
BasicBlock::iterator InsertPt) const override {
- IRBuilderDefaultInserter::InsertHelper(I, Name, BB, InsertPt);
+ IRBuilderDefaultInserter::InsertHelper(I, Name, InsertPt);
Callback(I);
}
};
@@ -143,7 +142,7 @@ class IRBuilderBase {
/// Insert and return the specified instruction.
template<typename InstTy>
InstTy *Insert(InstTy *I, const Twine &Name = "") const {
- Inserter.InsertHelper(I, Name, BB, InsertPt);
+ Inserter.InsertHelper(I, Name, InsertPt);
AddMetadataToInst(I);
return I;
}
diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h
index 9dd1bb455a718..2ff1c7f9ed760 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -107,12 +107,8 @@ class UnaryOperator : public UnaryInstruction {
void AssertOK();
protected:
- UnaryOperator(UnaryOps iType, Value *S, Type *Ty,
- const Twine &Name, BasicBlock::iterator InsertBefore);
- UnaryOperator(UnaryOps iType, Value *S, Type *Ty,
- const Twine &Name, Instruction *InsertBefore);
- UnaryOperator(UnaryOps iType, Value *S, Type *Ty,
- const Twine &Name, BasicBlock *InsertAtEnd);
+ UnaryOperator(UnaryOps iType, Value *S, Type *Ty, const Twine &Name,
+ InsertPosition InsertBefore = nullptr);
// Note: Instruction needs to be a friend here to call cloneImpl.
friend class Instruction;
@@ -120,13 +116,6 @@ class UnaryOperator : public UnaryInstruction {
UnaryOperator *cloneImpl() const;
public:
- /// Construct a unary instruction, given the opcode and an operand.
- /// Insert the instruction into a BasicBlock right before the specified
- /// instruction (InsertBefore must be a valid iterator).
- ///
- static UnaryOperator *Create(UnaryOps Op, Value *S, const Twine &Name,
- BasicBlock::iterator InsertBefore);
-
/// Construct a unary instruction, given the opcode and an operand.
/// Optionally (if InstBefore is specified) insert the instruction
/// into a BasicBlock right before the specified instruction. The specified
@@ -134,15 +123,7 @@ class UnaryOperator : public UnaryInstruction {
///
static UnaryOperator *Create(UnaryOps Op, Value *S,
const Twine &Name = Twine(),
- Instruction *InsertBefore = nullptr);
-
- /// Construct a unary instruction, given the opcode and an operand.
- /// Also automatically insert this instruction to the end of the
- /// BasicBlock specified.
- ///
- static UnaryOperator *Create(UnaryOps Op, Value *S,
- const Twine &Name,
- BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
/// These methods just forward to Create, and are useful when you
/// statically know what type of instruction you're going to create. These
@@ -171,33 +152,18 @@ class UnaryOperator : public UnaryInstruction {
}
#include "llvm/IR/Instruction.def"
- static UnaryOperator *
- CreateWithCopiedFlags(UnaryOps Opc, Value *V, Instruction *CopyO,
- const Twine &Name, BasicBlock::iterator InsertBefore) {
- UnaryOperator *UO = Create(Opc, V, Name, InsertBefore);
- UO->copyIRFlags(CopyO);
- return UO;
- }
-
static UnaryOperator *
CreateWithCopiedFlags(UnaryOps Opc, Value *V, Instruction *CopyO,
const Twine &Name = "",
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
UnaryOperator *UO = Create(Opc, V, Name, InsertBefore);
UO->copyIRFlags(CopyO);
return UO;
}
- static UnaryOperator *CreateFNegFMF(Value *Op, Instruction *FMFSource,
- const Twine &Name,
- BasicBlock::iterator InsertBefore) {
- return CreateWithCopiedFlags(Instruction::FNeg, Op, FMFSource, Name,
- InsertBefore);
- }
-
static UnaryOperator *CreateFNegFMF(Value *Op, Instruction *FMFSource,
const Twine &Name = "",
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
return CreateWithCopiedFlags(Instruction::FNeg, Op, FMFSource, Name,
InsertBefore);
}
@@ -224,11 +190,7 @@ class BinaryOperator : public Instruction {
protected:
BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty,
- const Twine &Name, BasicBlock::iterator InsertBefore);
- BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty,
- const Twine &Name, Instruction *InsertBefore);
- BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty,
- const Twine &Name, BasicBlock *InsertAtEnd);
+ const Twine &Name, InsertPosition InsertBefore = nullptr);
// Note: Instruction needs to be a friend here to call cloneImpl.
friend class Instruction;
@@ -243,14 +205,6 @@ class BinaryOperator : public Instruction {
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
- /// Construct a binary instruction, given the opcode and the two
- /// operands. Insert the instruction into a BasicBlock right before the
- /// specified instruction.
- ///
- static BinaryOperator *Create(BinaryOps Op, Value *S1, Value *S2,
- const Twine &Name,
- BasicBlock::iterator InsertBefore);
-
/// Construct a binary instruction, given the opcode and the two
/// operands. Optionally (if InstBefore is specified) insert the instruction
/// into a BasicBlock right before the specified instruction. The specified
@@ -258,14 +212,7 @@ class BinaryOperator : public Instruction {
///
static BinaryOperator *Create(BinaryOps Op, Value *S1, Value *S2,
const Twine &Name = Twine(),
- Instruction *InsertBefore = nullptr);
-
- /// Construct a binary instruction, given the opcode and the two
- /// operands. Also automatically insert this instruction to the end of the
- /// BasicBlock specified.
- ///
- static BinaryOperator *Create(BinaryOps Op, Value *S1, Value *S2,
- const Twine &Name, BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
/// These methods just forward to Create, and are useful when you
/// statically know what type of instruction you're going to create. These
@@ -295,18 +242,10 @@ class BinaryOperator : public Instruction {
}
#include "llvm/IR/Instruction.def"
- static BinaryOperator *
- CreateWithCopiedFlags(BinaryOps Opc, Value *V1, Value *V2, Value *CopyO,
- const Twine &Name, BasicBlock::iterator InsertBefore) {
- BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
- BO->copyIRFlags(CopyO);
- return BO;
- }
-
static BinaryOperator *
CreateWithCopiedFlags(BinaryOps Opc, Value *V1, Value *V2, Value *CopyO,
const Twine &Name = "",
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
BO->copyIRFlags(CopyO);
return BO;
@@ -315,7 +254,7 @@ class BinaryOperator : public Instruction {
static BinaryOperator *CreateWithFMF(BinaryOps Opc, Value *V1, Value *V2,
FastMathFlags FMF,
const Twine &Name = "",
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
BinaryOperator *BO = Create(Opc, V1, V2, Name, InsertBefore);
BO->setFastMathFlags(FMF);
return BO;
@@ -493,22 +432,12 @@ class BinaryOperator : public Instruction {
///
/// Create the NEG and NOT instructions out of SUB and XOR instructions.
///
- static BinaryOperator *CreateNeg(Value *Op, const Twine &Name,
- BasicBlock::iterator InsertBefore);
static BinaryOperator *CreateNeg(Value *Op, const Twine &Name = "",
- BasicBlock *InsertAtEnd = nullptr);
- static BinaryOperator *CreateNSWNeg(Value *Op, const Twine &Name,
- BasicBlock::iterator InsertBefore);
+ InsertPosition InsertBefore = nullptr);
static BinaryOperator *CreateNSWNeg(Value *Op, const Twine &Name = "",
- Instruction *InsertBefore = nullptr);
- static BinaryOperator *CreateNSWNeg(Value *Op, const Twine &Name,
- BasicBlock *InsertAtEnd);
- static BinaryOperator *CreateNot(Value *Op, const Twine &Name,
- BasicBlock::iterator InsertBefore);
+ InsertPosition InsertBefore = nullptr);
static BinaryOperator *CreateNot(Value *Op, const Twine &Name = "",
- Instruction *InsertBefore = nullptr);
- static BinaryOperator *CreateNot(Value *Op, const Twine &Name,
- BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
BinaryOps getOpcode() const {
return static_cast<BinaryOps>(Instruction::getOpcode());
@@ -601,38 +530,13 @@ BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
class CastInst : public UnaryInstruction {
protected:
/// Constructor with insert-before-instruction semantics for subclasses
- CastInst(Type *Ty, unsigned iType, Value *S, const Twine &NameStr,
- BasicBlock::iterator InsertBefore)
+ CastInst(Type *Ty, unsigned iType, Value *S, const Twine &NameStr = "",
+ InsertPosition InsertBefore = nullptr)
: UnaryInstruction(Ty, iType, S, InsertBefore) {
setName(NameStr);
}
- /// Constructor with insert-before-instruction semantics for subclasses
- CastInst(Type *Ty, unsigned iType, Value *S,
- const Twine &NameStr = "", Instruction *InsertBefore = nullptr)
- : UnaryInstruction(Ty, iType, S, InsertBefore) {
- setName(NameStr);
- }
- /// Constructor with insert-at-end-of-block semantics for subclasses
- CastInst(Type *Ty, unsigned iType, Value *S,
- const Twine &NameStr, BasicBlock *InsertAtEnd)
- : UnaryInstruction(Ty, iType, S, InsertAtEnd) {
- setName(NameStr);
- }
public:
- /// Provides a way to construct any of the CastInst subclasses using an
- /// opcode instead of the subclass's constructor. The opcode must be in the
- /// CastOps category (Instruction::isCast(opcode) returns true). This
- /// constructor has insert-before-instruction semantics to automatically
- /// insert the new CastInst before InsertBefore, which must be a valid
- /// iterator. Construct any of the CastInst subclasses.
- static CastInst *
- Create(Instruction::CastOps, ///< The opcode of the cast instruction
- Value *S, ///< The value to be casted (operand 0)
- Type *Ty, ///< The type to which cast should be made
- const Twine &Name, ///< Name for the instruction
- BasicBlock::iterator InsertBefore ///< Place to insert the instruction
- );
/// Provides a way to construct any of the CastInst subclasses using an
/// opcode instead of the subclass's constructor. The opcode must be in the
/// CastOps category (Instruction::isCast(opcode) returns true). This
@@ -640,120 +544,43 @@ class CastInst : public UnaryInstruction {
/// insert the new CastInst before InsertBefore (if it is non-null).
/// Construct any of the CastInst subclasses
static CastInst *Create(
- Instruction::CastOps, ///< The opcode of the cast instruction
- Value *S, ///< The value to be casted (operand 0)
- Type *Ty, ///< The type to which cast should be made
- const Twine &Name = "", ///< Name for the instruction
- Instruction *InsertBefore = nullptr ///< Place to insert the instruction
- );
- /// Provides a way to construct any of the CastInst subclasses using an
- /// opcode instead of the subclass's constructor. The opcode must be in the
- /// CastOps category. This constructor has insert-at-end-of-block semantics
- /// to automatically insert the new CastInst at the end of InsertAtEnd (if
- /// its non-null).
- /// Construct any of the CastInst subclasses
- static CastInst *Create(
- Instruction::CastOps, ///< The opcode for the cast instruction
- Value *S, ///< The value to be casted (operand 0)
- Type *Ty, ///< The type to which operand is casted
- const Twine &Name, ///< The name for the instruction
- BasicBlock *InsertAtEnd ///< The block to insert the instruction into
+ Instruction::CastOps, ///< The opcode of the cast instruction
+ Value *S, ///< The value to be casted (operand 0)
+ Type *Ty, ///< The type to which cast should be made
+ const Twine &Name = "", ///< Name for the instruction
+ InsertPosition InsertBefore = nullptr ///< Place to insert the instruction
);
/// Create a ZExt or BitCast cast instruction
static CastInst *CreateZExtOrBitCast(
- Value *S, ///< The value to be casted (operand 0)
- Type *Ty, ///< The type to which cast should be made
- const Twine &Name, ///< Name for the instruction
- BasicBlock::iterator InsertBefore ///< Place to insert the instruction
- );
-
- /// Create a ZExt or BitCast cast instruction
- static CastInst *CreateZExtOrBitCast(
- Value *S, ///< The value to be casted (operand 0)
- Type *Ty, ///< The type to which cast should be made
- const Twine &Name = "", ///< Name for the instruction
- Instruction *InsertBefore = nullptr ///< Place to insert the instruction
- );
-
- /// Create a ZExt or BitCast cast instruction
- static CastInst *CreateZExtOrBitCast(
- Value *S, ///< The value to be casted (operand 0)
- Type *Ty, ///< The type to which operand is casted
- const Twine &Name, ///< The name for the instruction
- BasicBlock *InsertAtEnd ///< The block to insert the instruction into
- );
-
- /// Create a SExt or BitCast cast instruction
- static CastInst *CreateSExtOrBitCast(
- Value *S, ///< The value to be casted (operand 0)
- Type *Ty, ///< The type to which cast should be made
- const Twine &Name, ///< Name for the instruction
- BasicBlock::iterator InsertBefore ///< Place to insert the instruction
- );
-
- /// Create a SExt or BitCast cast instruction
- static CastInst *CreateSExtOrBitCast(
- Value *S, ///< The value to be casted (operand 0)
- Type *Ty, ///< The type to which cast should be made
- const Twine &Name = "", ///< Name for the instruction
- Instruction *InsertBefore = nullptr ///< Place to insert the instruction
+ Value *S, ///< The value to be casted (operand 0)
+ Type *Ty, ///< The type to which cast should be made
+ const Twine &Name = "", ///< Name for the instruction
+ InsertPosition InsertBefore = nullptr ///< Place to insert the instruction
);
/// Create a SExt or BitCast cast instruction
static CastInst *CreateSExtOrBitCast(
- Value *S, ///< The value to be casted (operand 0)
- Type *Ty, ///< The type to which operand is casted
- const Twine &Name, ///< The name for the instruction
- BasicBlock *InsertAtEnd ///< The block to insert the instruction into
- );
-
- /// Create a BitCast AddrSpaceCast, or a PtrToInt cast instruction.
- static CastInst *CreatePointerCast(
- Value *S, ///< The pointer value to be casted (operand 0)
- Type *Ty, ///< The type to which operand is casted
- const Twine &Name, ///< The name for the instruction
- BasicBlock *InsertAtEnd ///< The block to insert the instruction into
+ Value *S, ///< The value to be casted (operand 0)
+ Type *Ty, ///< The type to which cast should be made
+ const Twine &Name = "", ///< Name for the instruction
+ InsertPosition InsertBefore = nullptr ///< Place to insert the instruction
);
/// Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.
static CastInst *CreatePointerCast(
- Value *S, ///< The pointer value to be casted (operand 0)
- Type *Ty, ///< The type to which cast should be made
- const Twine &Name, ///< Name for the instruction
- BasicBlock::iterator InsertBefore ///< Place to insert the instruction
- );
-
- /// Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.
- static CastInst *CreatePointerCast(
- Value *S, ///< The pointer value to be casted (operand 0)
- Type *Ty, ///< The type to which cast should be made
- const Twine &Name = "", ///< Name for the instruction
- Instruction *InsertBefore = nullptr ///< Place to insert the instruction
- );
-
- /// Create a BitCast or an AddrSpaceCast cast instruction.
- static CastInst *CreatePointerBitCastOrAddrSpaceCast(
- Value *S, ///< The pointer value to be casted (operand 0)
- Type *Ty, ///< The type to which operand is casted
- const Twine &Name, ///< The name for the instruction
- BasicBlock *InsertAtEnd ///< The block to insert the instruction into
- );
-
- /// Create a BitCast or an AddrSpaceCast cast instruction.
- static CastInst *CreatePointerBitCastOrAddrSpaceCast(
- Value *S, ///< The pointer value to be casted (operand 0)
- Type *Ty, ///< The type to which cast should be made
- const Twine &Name, ///< Name for the instruction
- BasicBlock::iterator InsertBefore ///< Place to insert the instruction
+ Value *S, ///< The pointer value to be casted (operand 0)
+ Type *Ty, ///< The type to which cast should be made
+ const Twine &Name = "", ///< Name for the instruction
+ InsertPosition InsertBefore = nullptr ///< Place to insert the instruction
);
/// Create a BitCast or an AddrSpaceCast cast instruction.
static CastInst *CreatePointerBitCastOrAddrSpaceCast(
- Value *S, ///< The pointer value to be casted (operand 0)
- Type *Ty, ///< The type to which cast should be made
- const Twine &Name = "", ///< Name for the instruction
- Instruction *InsertBefore = nullptr ///< Place to insert the instruction
+ Value *S, ///< The pointer value to be casted (operand 0)
+ Type *Ty, ///< The type to which cast should be made
+ const Twine &Name = "", ///< Name for the instruction
+ InsertPosition InsertBefore = nullptr ///< Place to insert the instruction
);
/// Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
@@ -763,98 +590,35 @@ class CastInst : public UnaryInstruction {
/// destination a pointer type, creates an IntToPtr cast. Otherwise, creates
/// a bitcast.
static CastInst *CreateBitOrPointerCast(
- Value *S, ///< The pointer value to be casted (operand 0)
- Type *Ty, ///< The type to which cast should be made
- const Twine &Name, ///< Name for the instruction
- BasicBlock::iterator InsertBefore ///< Place to insert the instruction
- );
-
- /// Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
- ///
- /// If the value is a pointer type and the destination an integer type,
- /// creates a PtrToInt cast. If the value is an integer type and the
- /// destination a pointer type, creates an IntToPtr cast. Otherwise, creates
- /// a bitcast.
- static CastInst *CreateBitOrPointerCast(
- Value *S, ///< The pointer value to be casted (operand 0)
- Type *Ty, ///< The type to which cast should be made
- const Twine &Name = "", ///< Name for the instruction
- Instruction *InsertBefore = nullptr ///< Place to insert the instruction
- );
-
- /// Create a ZExt, BitCast, or Trunc for int -> int casts.
- static CastInst *CreateIntegerCast(
- Value *S, ///< The pointer value to be casted (operand 0)
- Type *Ty, ///< The type to which cast should be made
- bool isSigned, ///< Whether to regard S as signed or not
- const Twine &Name, ///< Name for the instruction
- BasicBlock::iterator InsertBefore ///< Place to insert the instruction
- );
-
- /// Create a ZExt, BitCast, or Trunc for int -> int casts.
- static CastInst *CreateIntegerCast(
- Value *S, ///< The pointer value to be casted (operand 0)
- Type *Ty, ///< The type to which cast should be made
- bool isSigned, ///< Whether to regard S as signed or not
- const Twine &Name = "", ///< Name for the instruction
- Instruction *InsertBefore = nullptr ///< Place to insert the instruction
+ Value *S, ///< The pointer value to be casted (operand 0)
+ Type *Ty, ///< The type to which cast should be made
+ const Twine &Name = "", ///< Name for the instruction
+ InsertPosition InsertBefore = nullptr ///< Place to insert the instruction
);
/// Create a ZExt, BitCast, or Trunc for int -> int casts.
static CastInst *CreateIntegerCast(
- Value *S, ///< The integer value to be casted (operand 0)
- Type *Ty, ///< The integer type to which operand is casted
- bool isSigned, ///< Whether to regard S as signed or not
- const Twine &Name, ///< The name for the instruction
- BasicBlock *InsertAtEnd ///< The block to insert the instruction into
+ Value *S, ///< The pointer value to be casted (operand 0)
+ Type *Ty, ///< The type to which cast should be made
+ bool isSigned, ///< Whether to regard S as signed or not
+ const Twine &Name = "", ///< Name for the instruction
+ InsertPosition InsertBefore = nullptr ///< Place to insert the instruction
);
/// Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
static CastInst *CreateFPCast(
- Value *S, ///< The floating point value to be casted
- Type *Ty, ///< The floating point type to cast to
- const Twine &Name, ///< Name for the instruction
- BasicBlock::iterator InsertBefore ///< Place to insert the instruction
- );
-
- /// Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
- static CastInst *CreateFPCast(
- Value *S, ///< The floating point value to be casted
- Type *Ty, ///< The floating point type to cast to
- const Twine &Name = "", ///< Name for the instruction
- Instruction *InsertBefore = nullptr ///< Place to insert the instruction
- );
-
- /// Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
- static CastInst *CreateFPCast(
- Value *S, ///< The floating point value to be casted
- Type *Ty, ///< The floating point type to cast to
- const Twine &Name, ///< The name for the instruction
- BasicBlock *InsertAtEnd ///< The block to insert the instruction into
+ Value *S, ///< The floating point value to be casted
+ Type *Ty, ///< The floating point type to cast to
+ const Twine &Name = "", ///< Name for the instruction
+ InsertPosition InsertBefore = nullptr ///< Place to insert the instruction
);
/// Create a Trunc or BitCast cast instruction
static CastInst *CreateTruncOrBitCast(
- Value *S, ///< The value to be casted (operand 0)
- Type *Ty, ///< The type to which cast should be made
- const Twine &Name, ///< Name for the instruction
- BasicBlock::iterator InsertBefore ///< Place to insert the instruction
- );
-
- /// Create a Trunc or BitCast cast instruction
- static CastInst *CreateTruncOrBitCast(
- Value *S, ///< The value to be casted (operand 0)
- Type *Ty, ///< The type to which cast should be made
- const Twine &Name = "", ///< Name for the instruction
- Instruction *InsertBefore = nullptr ///< Place to insert the instruction
- );
-
- /// Create a Trunc or BitCast cast instruction
- static CastInst *CreateTruncOrBitCast(
- Value *S, ///< The value to be casted (operand 0)
- Type *Ty, ///< The type to which operand is casted
- const Twine &Name, ///< The name for the instruction
- BasicBlock *InsertAtEnd ///< The block to insert the instruction into
+ Value *S, ///< The value to be casted (operand 0)
+ Type *Ty, ///< The type to which cast should be made
+ const Twine &Name = "", ///< Name for the instruction
+ InsertPosition InsertBefore = nullptr ///< Place to insert the instruction
);
/// Check whether a bitcast between these types is valid
@@ -1044,30 +808,15 @@ class CmpInst : public Instruction {
protected:
CmpInst(Type *ty, Instruction::OtherOps op, Predicate pred, Value *LHS,
- Value *RHS, const Twine &Name, BasicBlock::iterator InsertBefore,
+ Value *RHS, const Twine &Name = "",
+ InsertPosition InsertBefore = nullptr,
Instruction *FlagsSource = nullptr);
- CmpInst(Type *ty, Instruction::OtherOps op, Predicate pred,
- Value *LHS, Value *RHS, const Twine &Name = "",
- Instruction *InsertBefore = nullptr,
- Instruction *FlagsSource = nullptr);
-
- CmpInst(Type *ty, Instruction::OtherOps op, Predicate pred,
- Value *LHS, Value *RHS, const Twine &Name,
- BasicBlock *InsertAtEnd);
-
public:
// allocate space for exactly two operands
void *operator new(size_t S) { return User::operator new(S, 2); }
void operator delete(void *Ptr) { User::operator delete(Ptr); }
- /// Construct a compare instruction, given the opcode, the predicate and
- /// the two operands. Insert the instruction into a BasicBlock right before
- /// the specified instruction.
- /// Create a CmpInst
- static CmpInst *Create(OtherOps Op, Predicate Pred, Value *S1, Value *S2,
- const Twine &Name, BasicBlock::iterator InsertBefore);
-
/// Construct a compare instruction, given the opcode, the predicate and
/// the two operands. Optionally (if InstBefore is specified) insert the
/// instruction into a BasicBlock right before the specified instruction.
@@ -1075,14 +824,7 @@ class CmpInst : public Instruction {
/// Create a CmpInst
static CmpInst *Create(OtherOps Op, Predicate Pred, Value *S1, Value *S2,
const Twine &Name = "",
- Instruction *InsertBefore = nullptr);
-
- /// Construct a compare instruction, given the opcode, the predicate and the
- /// two operands. Also automatically insert this instruction to the end of
- /// the BasicBlock specified.
- /// Create a CmpInst
- static CmpInst *Create(OtherOps Op, Predicate Pred, Value *S1, Value *S2,
- const Twine &Name, BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
/// Construct a compare instruction, given the opcode, the predicate,
/// the two operands and the instruction to copy the flags from. Optionally
@@ -1094,7 +836,7 @@ class CmpInst : public Instruction {
Value *S2,
const Instruction *FlagsSource,
const Twine &Name = "",
- Instruction *InsertBefore = nullptr);
+ InsertPosition InsertBefore = nullptr);
/// Get the opcode casted to the right type
OtherOps getOpcode() const {
@@ -1542,16 +1284,7 @@ class CallBase : public Instruction {
/// the operand bundles for the new instruction are set to the operand bundles
/// in \p Bundles.
static CallBase *Create(CallBase *CB, ArrayRef<OperandBundleDef> Bundles,
- BasicBlock::iterator InsertPt);
-
- /// Create a clone of \p CB with a different set of operand bundles and
- /// insert it before \p InsertPt.
- ///
- /// The returned call instruction is identical \p CB in every way except that
- /// the operand bundles for the new instruction are set to the operand bundles
- /// in \p Bundles.
- static CallBase *Create(CallBase *CB, ArrayRef<OperandBundleDef> Bundles,
- Instruction *InsertPt = nullptr);
+ InsertPosition InsertPt = nullptr);
/// Create a clone of \p CB with the operand bundle with the tag matching
/// \p Bundle's tag replaced with Bundle, and insert it before \p InsertPt.
@@ -1559,34 +1292,16 @@ class CallBase : public Instruction {
/// The returned call instruction is identical \p CI in every way except that
/// the specified operand bundle has been replaced.
static CallBase *Create(CallBase *CB, OperandBundleDef Bundle,
- BasicBlock::iterator InsertPt);
-
- /// Create a clone of \p CB with the operand bundle with the tag matching
- /// \p Bundle's tag replaced with Bundle, and insert it before \p InsertPt.
- ///
- /// The returned call instruction is identical \p CI in every way except that
- /// the specified operand bundle has been replaced.
- static CallBase *Create(CallBase *CB,
- OperandBundleDef Bundle,
- Instruction *InsertPt = nullptr);
-
- /// Create a clone of \p CB with operand bundle \p OB added.
- static CallBase *addOperandBundle(CallBase *CB, uint32_t ID,
- OperandBundleDef OB,
- Instruction *InsertPt = nullptr);
+ InsertPosition InsertPt = nullptr);
/// Create a clone of \p CB with operand bundle \p OB added.
static CallBase *addOperandBundle(CallBase *CB, uint32_t ID,
OperandBundleDef OB,
- BasicBlock::iterator InsertPt);
-
- /// Create a clone of \p CB with operand bundle \p ID removed.
- static CallBase *removeOperandBundle(CallBase *CB, uint32_t ID,
- Instruction *InsertPt = nullptr);
+ InsertPosition InsertPt = nullptr);
/// Create a clone of \p CB with operand bundle \p ID removed.
static CallBase *removeOperandBundle(CallBase *CB, uint32_t ID,
- BasicBlock::iterator InsertPt);
+ InsertPosition InsertPt = nullptr);
static bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::Call ||
@@ -2689,13 +2404,7 @@ class FuncletPadInst : public Instruction {
explicit FuncletPadInst(Instruction::FuncletPadOps Op, Value *ParentPad,
ArrayRef<Value *> Args, unsigned Values,
const Twine &NameStr,
- BasicBlock::iterator InsertBefore);
- explicit FuncletPadInst(Instruction::FuncletPadOps Op, Value *ParentPad,
- ArrayRef<Value *> Args, unsigned Values,
- const Twine &NameStr, Instruction *InsertBefore);
- explicit FuncletPadInst(Instruction::FuncletPadOps Op, Value *ParentPad,
- ArrayRef<Value *> Args, unsigned Values,
- const Twine &NameStr, BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
void init(Value *ParentPad, ArrayRef<Value *> Args, const Twine &NameStr);
diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h
index e1cb362ad20d0..db56ba80ae1af 100644
--- a/llvm/include/llvm/IR/Instruction.h
+++ b/llvm/include/llvm/IR/Instruction.h
@@ -44,6 +44,23 @@ template <> struct ilist_alloc_traits<Instruction> {
iterator_range<simple_ilist<DbgRecord>::iterator>
getDbgRecordRange(DbgMarker *);
+class InsertPosition {
+ using InstListType = SymbolTableList<Instruction, ilist_iterator_bits<true>,
+ ilist_parent<BasicBlock>>;
+ InstListType::iterator InsertAt;
+
+public:
+ InsertPosition(std::nullopt_t) : InsertAt() {}
+ InsertPosition(std::nullptr_t) : InsertAt() {}
+ // LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",
+ // "BasicBlock::iterator")
+ InsertPosition(Instruction *InsertBefore);
+ InsertPosition(BasicBlock *InsertAtEnd);
+ InsertPosition(InstListType::iterator InsertAt) : InsertAt(InsertAt) {}
+ operator InstListType::iterator() const { return InsertAt; }
+ bool IsValid() const { return InsertAt.getNodePtr(); }
+};
+
class Instruction : public User,
public ilist_node_with_parent<Instruction, BasicBlock,
ilist_iterator_bits<true>,
@@ -1023,11 +1040,7 @@ class Instruction : public User,
}
Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps,
- InstListType::iterator InsertBefore);
- Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps,
- Instruction *InsertBefore = nullptr);
- Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps,
- BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
private:
/// Create a copy of this instruction.
diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h
index 8d7c2b0c957dd..4cd603e9058d1 100644
--- a/llvm/include/llvm/IR/Instructions.h
+++ b/llvm/include/llvm/IR/Instructions.h
@@ -75,25 +75,13 @@ class AllocaInst : public UnaryInstruction {
public:
explicit AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
- const Twine &Name, BasicBlock::iterator InsertBefore);
- explicit AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
- const Twine &Name, Instruction *InsertBefore);
- AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
- const Twine &Name, BasicBlock *InsertAtEnd);
+ const Twine &Name, InsertPosition InsertBefore = nullptr);
AllocaInst(Type *Ty, unsigned AddrSpace, const Twine &Name,
- BasicBlock::iterator InsertBefore);
- AllocaInst(Type *Ty, unsigned AddrSpace, const Twine &Name,
- Instruction *InsertBefore);
- AllocaInst(Type *Ty, unsigned AddrSpace,
- const Twine &Name, BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, Align Align,
- const Twine &Name, BasicBlock::iterator);
- AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, Align Align,
- const Twine &Name = "", Instruction *InsertBefore = nullptr);
- AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, Align Align,
- const Twine &Name, BasicBlock *InsertAtEnd);
+ const Twine &Name = "", InsertPosition InsertBefore = nullptr);
/// Return true if there is an allocation size parameter to the allocation
/// instruction that is not 1.
@@ -200,32 +188,15 @@ class LoadInst : public UnaryInstruction {
public:
LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr,
- BasicBlock::iterator InsertBefore);
- LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr,
- Instruction *InsertBefore);
- LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
- LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
- BasicBlock::iterator InsertBefore);
- LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
- Instruction *InsertBefore);
- LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
- BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
- Align Align, BasicBlock::iterator InsertBefore);
+ InsertPosition InsertBefore = nullptr);
LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
- Align Align, Instruction *InsertBefore = nullptr);
- LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
- Align Align, BasicBlock *InsertAtEnd);
- LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
- Align Align, AtomicOrdering Order, SyncScope::ID SSID,
- BasicBlock::iterator InsertBefore);
+ Align Align, InsertPosition InsertBefore = nullptr);
LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
Align Align, AtomicOrdering Order,
SyncScope::ID SSID = SyncScope::System,
- Instruction *InsertBefore = nullptr);
- LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
- Align Align, AtomicOrdering Order, SyncScope::ID SSID,
- BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
/// Return true if this is a load from a volatile memory location.
bool isVolatile() const { return getSubclassData<VolatileField>(); }
@@ -332,27 +303,14 @@ class StoreInst : public Instruction {
StoreInst *cloneImpl() const;
public:
- StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
- StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
- StoreInst(Value *Val, Value *Ptr, BasicBlock::iterator InsertBefore);
- StoreInst(Value *Val, Value *Ptr, bool isVolatile, Instruction *InsertBefore);
- StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
+ StoreInst(Value *Val, Value *Ptr, InsertPosition InsertBefore);
StoreInst(Value *Val, Value *Ptr, bool isVolatile,
- BasicBlock::iterator InsertBefore);
- StoreInst(Value *Val, Value *Ptr, bool isVolatile, Align Align,
- Instruction *InsertBefore = nullptr);
+ InsertPosition InsertBefore);
StoreInst(Value *Val, Value *Ptr, bool isVolatile, Align Align,
- BasicBlock *InsertAtEnd);
- StoreInst(Value *Val, Value *Ptr, bool isVolatile, Align Align,
- BasicBlock::iterator InsertBefore);
+ InsertPosition InsertBefore = nullptr);
StoreInst(Value *Val, Value *Ptr, bool isVolatile, Align Align,
AtomicOrdering Order, SyncScope::ID SSID = SyncScope::System,
- Instruction *InsertBefore = nullptr);
- StoreInst(Value *Val, Value *Ptr, bool isVolatile, Align Align,
- AtomicOrdering Order, SyncScope::ID SSID, BasicBlock *InsertAtEnd);
- StoreInst(Value *Val, Value *Ptr, bool isVolatile, Align Align,
- AtomicOrdering Order, SyncScope::ID SSID,
- BasicBlock::iterator InsertBefore);
+ InsertPosition InsertBefore = nullptr);
// allocate space for exactly two operands
void *operator new(size_t S) { return User::operator new(S, 2); }
@@ -472,13 +430,9 @@ class FenceInst : public Instruction {
public:
// Ordering may only be Acquire, Release, AcquireRelease, or
// SequentiallyConsistent.
- FenceInst(LLVMContext &C, AtomicOrdering Ordering, SyncScope::ID SSID,
- BasicBlock::iterator InsertBefore);
FenceInst(LLVMContext &C, AtomicOrdering Ordering,
SyncScope::ID SSID = SyncScope::System,
- Instruction *InsertBefore = nullptr);
- FenceInst(LLVMContext &C, AtomicOrdering Ordering, SyncScope::ID SSID,
- BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
// allocate space for exactly zero operands
void *operator new(size_t S) { return User::operator new(S, 0); }
@@ -557,15 +511,7 @@ class AtomicCmpXchgInst : public Instruction {
AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal, Align Alignment,
AtomicOrdering SuccessOrdering,
AtomicOrdering FailureOrdering, SyncScope::ID SSID,
- BasicBlock::iterator InsertBefore);
- AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal, Align Alignment,
- AtomicOrdering SuccessOrdering,
- AtomicOrdering FailureOrdering, SyncScope::ID SSID,
- Instruction *InsertBefore = nullptr);
- AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal, Align Alignment,
- AtomicOrdering SuccessOrdering,
- AtomicOrdering FailureOrdering, SyncScope::ID SSID,
- BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
// allocate space for exactly three operands
void *operator new(size_t S) { return User::operator new(S, 3); }
@@ -822,13 +768,7 @@ class AtomicRMWInst : public Instruction {
public:
AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val, Align Alignment,
AtomicOrdering Ordering, SyncScope::ID SSID,
- BasicBlock::iterator InsertBefore);
- AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val, Align Alignment,
- AtomicOrdering Ordering, SyncScope::ID SSID,
- Instruction *InsertBefore = nullptr);
- AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val, Align Alignment,
- AtomicOrdering Ordering, SyncScope::ID SSID,
- BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
// allocate space for exactly two operands
void *operator new(size_t S) { return User::operator new(S, 2); }
@@ -984,13 +924,7 @@ class GetElementPtrInst : public Instruction {
inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
ArrayRef<Value *> IdxList, unsigned Values,
const Twine &NameStr,
- BasicBlock::iterator InsertBefore);
- inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
- ArrayRef<Value *> IdxList, unsigned Values,
- const Twine &NameStr, Instruction *InsertBefore);
- inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
- ArrayRef<Value *> IdxList, unsigned Values,
- const Twine &NameStr, BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
@@ -1001,68 +935,28 @@ class GetElementPtrInst : public Instruction {
GetElementPtrInst *cloneImpl() const;
public:
- static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
- ArrayRef<Value *> IdxList,
- const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- unsigned Values = 1 + unsigned(IdxList.size());
- assert(PointeeType && "Must specify element type");
- return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
- NameStr, InsertBefore);
- }
-
static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
ArrayRef<Value *> IdxList,
const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
unsigned Values = 1 + unsigned(IdxList.size());
assert(PointeeType && "Must specify element type");
return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
NameStr, InsertBefore);
}
- static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
- ArrayRef<Value *> IdxList,
- const Twine &NameStr,
- BasicBlock *InsertAtEnd) {
- unsigned Values = 1 + unsigned(IdxList.size());
- assert(PointeeType && "Must specify element type");
- return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
- NameStr, InsertAtEnd);
- }
-
/// Create an "inbounds" getelementptr. See the documentation for the
/// "inbounds" flag in LangRef.html for details.
- static GetElementPtrInst *CreateInBounds(Type *PointeeType, Value *Ptr,
- ArrayRef<Value *> IdxList,
- const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- GetElementPtrInst *GEP =
- Create(PointeeType, Ptr, IdxList, NameStr, InsertBefore);
- GEP->setIsInBounds(true);
- return GEP;
- }
-
static GetElementPtrInst *
CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef<Value *> IdxList,
const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
GetElementPtrInst *GEP =
Create(PointeeType, Ptr, IdxList, NameStr, InsertBefore);
GEP->setIsInBounds(true);
return GEP;
}
- static GetElementPtrInst *CreateInBounds(Type *PointeeType, Value *Ptr,
- ArrayRef<Value *> IdxList,
- const Twine &NameStr,
- BasicBlock *InsertAtEnd) {
- GetElementPtrInst *GEP =
- Create(PointeeType, Ptr, IdxList, NameStr, InsertAtEnd);
- GEP->setIsInBounds(true);
- return GEP;
- }
-
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
@@ -1217,19 +1111,7 @@ struct OperandTraits<GetElementPtrInst> :
GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
ArrayRef<Value *> IdxList, unsigned Values,
const Twine &NameStr,
- BasicBlock::iterator InsertBefore)
- : Instruction(getGEPReturnType(Ptr, IdxList), GetElementPtr,
- OperandTraits<GetElementPtrInst>::op_end(this) - Values,
- Values, InsertBefore),
- SourceElementType(PointeeType),
- ResultElementType(getIndexedType(PointeeType, IdxList)) {
- init(Ptr, IdxList, NameStr);
-}
-
-GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
- ArrayRef<Value *> IdxList, unsigned Values,
- const Twine &NameStr,
- Instruction *InsertBefore)
+ InsertPosition InsertBefore)
: Instruction(getGEPReturnType(Ptr, IdxList), GetElementPtr,
OperandTraits<GetElementPtrInst>::op_end(this) - Values,
Values, InsertBefore),
@@ -1238,18 +1120,6 @@ GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
init(Ptr, IdxList, NameStr);
}
-GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
- ArrayRef<Value *> IdxList, unsigned Values,
- const Twine &NameStr,
- BasicBlock *InsertAtEnd)
- : Instruction(getGEPReturnType(Ptr, IdxList), GetElementPtr,
- OperandTraits<GetElementPtrInst>::op_end(this) - Values,
- Values, InsertAtEnd),
- SourceElementType(PointeeType),
- ResultElementType(getIndexedType(PointeeType, IdxList)) {
- init(Ptr, IdxList, NameStr);
-}
-
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
//===----------------------------------------------------------------------===//
@@ -1280,46 +1150,15 @@ class ICmpInst: public CmpInst {
ICmpInst *cloneImpl() const;
public:
- /// Constructor with insert-before-instruction semantics.
- ICmpInst(
- BasicBlock::iterator InsertBefore, ///< Where to insert
- Predicate pred, ///< The predicate to use for the comparison
- Value *LHS, ///< The left-hand-side of the expression
- Value *RHS, ///< The right-hand-side of the expression
- const Twine &NameStr = "" ///< Name of the instruction
- ) : CmpInst(makeCmpResultType(LHS->getType()),
- Instruction::ICmp, pred, LHS, RHS, NameStr,
- InsertBefore) {
-#ifndef NDEBUG
- AssertOK();
-#endif
- }
-
- /// Constructor with insert-before-instruction semantics.
- ICmpInst(
- Instruction *InsertBefore, ///< Where to insert
- Predicate pred, ///< The predicate to use for the comparison
- Value *LHS, ///< The left-hand-side of the expression
- Value *RHS, ///< The right-hand-side of the expression
- const Twine &NameStr = "" ///< Name of the instruction
- ) : CmpInst(makeCmpResultType(LHS->getType()),
- Instruction::ICmp, pred, LHS, RHS, NameStr,
- InsertBefore) {
-#ifndef NDEBUG
- AssertOK();
-#endif
- }
-
- /// Constructor with insert-at-end semantics.
- ICmpInst(
- BasicBlock *InsertAtEnd, ///< Block to insert into.
- Predicate pred, ///< The predicate to use for the comparison
- Value *LHS, ///< The left-hand-side of the expression
- Value *RHS, ///< The right-hand-side of the expression
- const Twine &NameStr = "" ///< Name of the instruction
- ) : CmpInst(makeCmpResultType(LHS->getType()),
- Instruction::ICmp, pred, LHS, RHS, NameStr,
- InsertAtEnd) {
+ /// Constructor with insertion semantics.
+ ICmpInst(InsertPosition InsertBefore, ///< Where to insert
+ Predicate pred, ///< The predicate to use for the comparison
+ Value *LHS, ///< The left-hand-side of the expression
+ Value *RHS, ///< The right-hand-side of the expression
+ const Twine &NameStr = "" ///< Name of the instruction
+ )
+ : CmpInst(makeCmpResultType(LHS->getType()), Instruction::ICmp, pred, LHS,
+ RHS, NameStr, InsertBefore) {
#ifndef NDEBUG
AssertOK();
#endif
@@ -1467,54 +1306,26 @@ class FCmpInst: public CmpInst {
FCmpInst *cloneImpl() const;
public:
- /// Constructor with insert-before-instruction semantics.
- FCmpInst(
- BasicBlock::iterator InsertBefore, ///< Where to insert
- Predicate pred, ///< The predicate to use for the comparison
- Value *LHS, ///< The left-hand-side of the expression
- Value *RHS, ///< The right-hand-side of the expression
- const Twine &NameStr = "" ///< Name of the instruction
- ) : CmpInst(makeCmpResultType(LHS->getType()),
- Instruction::FCmp, pred, LHS, RHS, NameStr,
- InsertBefore) {
- AssertOK();
- }
-
- /// Constructor with insert-before-instruction semantics.
- FCmpInst(
- Instruction *InsertBefore, ///< Where to insert
- Predicate pred, ///< The predicate to use for the comparison
- Value *LHS, ///< The left-hand-side of the expression
- Value *RHS, ///< The right-hand-side of the expression
- const Twine &NameStr = "" ///< Name of the instruction
- ) : CmpInst(makeCmpResultType(LHS->getType()),
- Instruction::FCmp, pred, LHS, RHS, NameStr,
- InsertBefore) {
- AssertOK();
- }
-
- /// Constructor with insert-at-end semantics.
- FCmpInst(
- BasicBlock *InsertAtEnd, ///< Block to insert into.
- Predicate pred, ///< The predicate to use for the comparison
- Value *LHS, ///< The left-hand-side of the expression
- Value *RHS, ///< The right-hand-side of the expression
- const Twine &NameStr = "" ///< Name of the instruction
- ) : CmpInst(makeCmpResultType(LHS->getType()),
- Instruction::FCmp, pred, LHS, RHS, NameStr,
- InsertAtEnd) {
+ /// Constructor with insertion semantics.
+ FCmpInst(InsertPosition InsertBefore, ///< Where to insert
+ Predicate pred, ///< The predicate to use for the comparison
+ Value *LHS, ///< The left-hand-side of the expression
+ Value *RHS, ///< The right-hand-side of the expression
+ const Twine &NameStr = "" ///< Name of the instruction
+ )
+ : CmpInst(makeCmpResultType(LHS->getType()), Instruction::FCmp, pred, LHS,
+ RHS, NameStr, InsertBefore) {
AssertOK();
}
/// Constructor with no-insertion semantics
- FCmpInst(
- Predicate Pred, ///< The predicate to use for the comparison
- Value *LHS, ///< The left-hand-side of the expression
- Value *RHS, ///< The right-hand-side of the expression
- const Twine &NameStr = "", ///< Name of the instruction
- Instruction *FlagsSource = nullptr
- ) : CmpInst(makeCmpResultType(LHS->getType()), Instruction::FCmp, Pred, LHS,
- RHS, NameStr, nullptr, FlagsSource) {
+ FCmpInst(Predicate Pred, ///< The predicate to use for the comparison
+ Value *LHS, ///< The left-hand-side of the expression
+ Value *RHS, ///< The right-hand-side of the expression
+ const Twine &NameStr = "", ///< Name of the instruction
+ Instruction *FlagsSource = nullptr)
+ : CmpInst(makeCmpResultType(LHS->getType()), Instruction::FCmp, Pred, LHS,
+ RHS, NameStr, std::nullopt, FlagsSource) {
AssertOK();
}
@@ -1582,36 +1393,14 @@ class CallInst : public CallBase {
/// Construct a CallInst from a range of arguments
inline CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
- BasicBlock::iterator InsertBefore);
-
- inline CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
- const Twine &NameStr, BasicBlock::iterator InsertBefore)
- : CallInst(Ty, Func, Args, std::nullopt, NameStr, InsertBefore) {}
-
- /// Construct a CallInst given a range of arguments.
- /// Construct a CallInst from a range of arguments
- inline CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
- Instruction *InsertBefore);
+ InsertPosition InsertBefore = nullptr);
inline CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
- const Twine &NameStr, Instruction *InsertBefore)
+ const Twine &NameStr, InsertPosition InsertBefore = nullptr)
: CallInst(Ty, Func, Args, std::nullopt, NameStr, InsertBefore) {}
- /// Construct a CallInst given a range of arguments.
- /// Construct a CallInst from a range of arguments
- inline CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
- BasicBlock *InsertAtEnd);
-
explicit CallInst(FunctionType *Ty, Value *F, const Twine &NameStr,
- BasicBlock::iterator InsertBefore);
-
- explicit CallInst(FunctionType *Ty, Value *F, const Twine &NameStr,
- Instruction *InsertBefore);
-
- CallInst(FunctionType *ty, Value *F, const Twine &NameStr,
- BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
void init(FunctionType *FTy, Value *Func, ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr);
@@ -1631,46 +1420,22 @@ class CallInst : public CallBase {
CallInst *cloneImpl() const;
public:
- static CallInst *Create(FunctionType *Ty, Value *F, const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- return new (ComputeNumOperands(0)) CallInst(Ty, F, NameStr, InsertBefore);
- }
-
static CallInst *Create(FunctionType *Ty, Value *F, const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
return new (ComputeNumOperands(0)) CallInst(Ty, F, NameStr, InsertBefore);
}
static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- return new (ComputeNumOperands(Args.size()))
- CallInst(Ty, Func, Args, std::nullopt, NameStr, InsertBefore);
- }
-
- static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
- const Twine &NameStr,
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
return new (ComputeNumOperands(Args.size()))
CallInst(Ty, Func, Args, std::nullopt, NameStr, InsertBefore);
}
- static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles,
- const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- const int NumOperands =
- ComputeNumOperands(Args.size(), CountBundleInputs(Bundles));
- const unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
-
- return new (NumOperands, DescriptorBytes)
- CallInst(Ty, Func, Args, Bundles, NameStr, InsertBefore);
- }
-
static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> Bundles = std::nullopt,
const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
const int NumOperands =
ComputeNumOperands(Args.size(), CountBundleInputs(Bundles));
const unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
@@ -1679,99 +1444,35 @@ class CallInst : public CallBase {
CallInst(Ty, Func, Args, Bundles, NameStr, InsertBefore);
}
- static CallInst *Create(FunctionType *Ty, Value *F, const Twine &NameStr,
- BasicBlock *InsertAtEnd) {
- return new (ComputeNumOperands(0)) CallInst(Ty, F, NameStr, InsertAtEnd);
- }
-
- static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
- const Twine &NameStr, BasicBlock *InsertAtEnd) {
- return new (ComputeNumOperands(Args.size()))
- CallInst(Ty, Func, Args, std::nullopt, NameStr, InsertAtEnd);
- }
-
- static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles,
- const Twine &NameStr, BasicBlock *InsertAtEnd) {
- const int NumOperands =
- ComputeNumOperands(Args.size(), CountBundleInputs(Bundles));
- const unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
-
- return new (NumOperands, DescriptorBytes)
- CallInst(Ty, Func, Args, Bundles, NameStr, InsertAtEnd);
- }
-
- static CallInst *Create(FunctionCallee Func, const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- return Create(Func.getFunctionType(), Func.getCallee(), NameStr,
- InsertBefore);
- }
-
static CallInst *Create(FunctionCallee Func, const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
return Create(Func.getFunctionType(), Func.getCallee(), NameStr,
InsertBefore);
}
- static CallInst *Create(FunctionCallee Func, ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles,
- const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- return Create(Func.getFunctionType(), Func.getCallee(), Args, Bundles,
- NameStr, InsertBefore);
- }
-
static CallInst *Create(FunctionCallee Func, ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> Bundles = std::nullopt,
const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
return Create(Func.getFunctionType(), Func.getCallee(), Args, Bundles,
NameStr, InsertBefore);
}
static CallInst *Create(FunctionCallee Func, ArrayRef<Value *> Args,
const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- return Create(Func.getFunctionType(), Func.getCallee(), Args, NameStr,
- InsertBefore);
- }
-
- static CallInst *Create(FunctionCallee Func, ArrayRef<Value *> Args,
- const Twine &NameStr,
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
return Create(Func.getFunctionType(), Func.getCallee(), Args, NameStr,
InsertBefore);
}
- static CallInst *Create(FunctionCallee Func, const Twine &NameStr,
- BasicBlock *InsertAtEnd) {
- return Create(Func.getFunctionType(), Func.getCallee(), NameStr,
- InsertAtEnd);
- }
-
- static CallInst *Create(FunctionCallee Func, ArrayRef<Value *> Args,
- const Twine &NameStr, BasicBlock *InsertAtEnd) {
- return Create(Func.getFunctionType(), Func.getCallee(), Args, NameStr,
- InsertAtEnd);
- }
-
- static CallInst *Create(FunctionCallee Func, ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles,
- const Twine &NameStr, BasicBlock *InsertAtEnd) {
- return Create(Func.getFunctionType(), Func.getCallee(), Args, Bundles,
- NameStr, InsertAtEnd);
- }
-
/// Create a clone of \p CI with a different set of operand bundles and
- /// insert it before \p InsertPt.
+ /// insert it before \p InsertBefore.
///
/// The returned call instruction is identical \p CI in every way except that
/// the operand bundles for the new instruction are set to the operand bundles
/// in \p Bundles.
static CallInst *Create(CallInst *CI, ArrayRef<OperandBundleDef> Bundles,
- BasicBlock::iterator InsertPt);
- static CallInst *Create(CallInst *CI, ArrayRef<OperandBundleDef> Bundles,
- Instruction *InsertPt = nullptr);
+ InsertPosition InsertPt = nullptr);
// Note that 'musttail' implies 'tail'.
enum TailCallKind : unsigned {
@@ -1834,29 +1535,7 @@ class CallInst : public CallBase {
CallInst::CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
- BasicBlock *InsertAtEnd)
- : CallBase(Ty->getReturnType(), Instruction::Call,
- OperandTraits<CallBase>::op_end(this) -
- (Args.size() + CountBundleInputs(Bundles) + 1),
- unsigned(Args.size() + CountBundleInputs(Bundles) + 1),
- InsertAtEnd) {
- init(Ty, Func, Args, Bundles, NameStr);
-}
-
-CallInst::CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
- BasicBlock::iterator InsertBefore)
- : CallBase(Ty->getReturnType(), Instruction::Call,
- OperandTraits<CallBase>::op_end(this) -
- (Args.size() + CountBundleInputs(Bundles) + 1),
- unsigned(Args.size() + CountBundleInputs(Bundles) + 1),
- InsertBefore) {
- init(Ty, Func, Args, Bundles, NameStr);
-}
-
-CallInst::CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
- Instruction *InsertBefore)
+ InsertPosition InsertBefore)
: CallBase(Ty->getReturnType(), Instruction::Call,
OperandTraits<CallBase>::op_end(this) -
(Args.size() + CountBundleInputs(Bundles) + 1),
@@ -1872,30 +1551,15 @@ CallInst::CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
/// This class represents the LLVM 'select' instruction.
///
class SelectInst : public Instruction {
+
SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore = nullptr)
: Instruction(S1->getType(), Instruction::Select, &Op<0>(), 3,
InsertBefore) {
init(C, S1, S2);
setName(NameStr);
}
- SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
- Instruction *InsertBefore)
- : Instruction(S1->getType(), Instruction::Select,
- &Op<0>(), 3, InsertBefore) {
- init(C, S1, S2);
- setName(NameStr);
- }
-
- SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
- BasicBlock *InsertAtEnd)
- : Instruction(S1->getType(), Instruction::Select,
- &Op<0>(), 3, InsertAtEnd) {
- init(C, S1, S2);
- setName(NameStr);
- }
-
void init(Value *C, Value *S1, Value *S2) {
assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
Op<0>() = C;
@@ -1910,19 +1574,9 @@ class SelectInst : public Instruction {
SelectInst *cloneImpl() const;
public:
- static SelectInst *Create(Value *C, Value *S1, Value *S2,
- const Twine &NameStr,
- BasicBlock::iterator InsertBefore,
- Instruction *MDFrom = nullptr) {
- SelectInst *Sel = new (3) SelectInst(C, S1, S2, NameStr, InsertBefore);
- if (MDFrom)
- Sel->copyMetadata(*MDFrom);
- return Sel;
- }
-
static SelectInst *Create(Value *C, Value *S1, Value *S2,
const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr,
+ InsertPosition InsertBefore = nullptr,
Instruction *MDFrom = nullptr) {
SelectInst *Sel = new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
if (MDFrom)
@@ -1930,12 +1584,6 @@ class SelectInst : public Instruction {
return Sel;
}
- static SelectInst *Create(Value *C, Value *S1, Value *S2,
- const Twine &NameStr,
- BasicBlock *InsertAtEnd) {
- return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
- }
-
const Value *getCondition() const { return Op<0>(); }
const Value *getTrueValue() const { return Op<1>(); }
const Value *getFalseValue() const { return Op<2>(); }
@@ -1992,21 +1640,9 @@ class VAArgInst : public UnaryInstruction {
VAArgInst *cloneImpl() const;
public:
- VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
- BasicBlock::iterator InsertBefore)
- : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
- setName(NameStr);
- }
-
VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr)
- : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
- setName(NameStr);
- }
-
- VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
- BasicBlock *InsertAtEnd)
- : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
+ InsertPosition InsertBefore = nullptr)
+ : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
setName(NameStr);
}
@@ -2031,12 +1667,8 @@ class VAArgInst : public UnaryInstruction {
/// element from a VectorType value
///
class ExtractElementInst : public Instruction {
- ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
- BasicBlock::iterator InsertBefore);
ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr);
- ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
- BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
protected:
// Note: Instruction needs to be a friend here to call cloneImpl.
@@ -2046,23 +1678,11 @@ class ExtractElementInst : public Instruction {
public:
static ExtractElementInst *Create(Value *Vec, Value *Idx,
- const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- return new (2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
- }
-
- static ExtractElementInst *Create(Value *Vec, Value *Idx,
- const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr) {
+ const Twine &NameStr = "",
+ InsertPosition InsertBefore = nullptr) {
return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
}
- static ExtractElementInst *Create(Value *Vec, Value *Idx,
- const Twine &NameStr,
- BasicBlock *InsertAtEnd) {
- return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
- }
-
/// Return true if an extractelement instruction can be
/// formed with the specified operands.
static bool isValidOperands(const Value *Vec, const Value *Idx);
@@ -2103,13 +1723,9 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
/// element into a VectorType value
///
class InsertElementInst : public Instruction {
- InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr,
- BasicBlock::iterator InsertBefore);
InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr);
- InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr,
- BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
protected:
// Note: Instruction needs to be a friend here to call cloneImpl.
@@ -2118,24 +1734,12 @@ class InsertElementInst : public Instruction {
InsertElementInst *cloneImpl() const;
public:
- static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
- const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- return new (3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
- }
-
static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
}
- static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
- const Twine &NameStr,
- BasicBlock *InsertAtEnd) {
- return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
- }
-
/// Return true if an insertelement instruction can be
/// formed with the specified operands.
static bool isValidOperands(const Value *Vec, const Value *NewElt,
@@ -2193,32 +1797,16 @@ class ShuffleVectorInst : public Instruction {
ShuffleVectorInst *cloneImpl() const;
public:
- ShuffleVectorInst(Value *V1, Value *Mask, const Twine &NameStr,
- BasicBlock::iterator InsertBefore);
ShuffleVectorInst(Value *V1, Value *Mask, const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr);
- ShuffleVectorInst(Value *V1, Value *Mask, const Twine &NameStr,
- BasicBlock *InsertAtEnd);
- ShuffleVectorInst(Value *V1, ArrayRef<int> Mask, const Twine &NameStr,
- BasicBlock::iterator InsertBefore);
+ InsertPosition InsertBefore = nullptr);
ShuffleVectorInst(Value *V1, ArrayRef<int> Mask, const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr);
- ShuffleVectorInst(Value *V1, ArrayRef<int> Mask, const Twine &NameStr,
- BasicBlock *InsertAtEnd);
- ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, const Twine &NameStr,
- BasicBlock::iterator InsertBefor);
+ InsertPosition InsertBefore = nullptr);
ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
const Twine &NameStr = "",
- Instruction *InsertBefor = nullptr);
- ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
- const Twine &NameStr, BasicBlock *InsertAtEnd);
- ShuffleVectorInst(Value *V1, Value *V2, ArrayRef<int> Mask,
- const Twine &NameStr, BasicBlock::iterator InsertBefor);
+ InsertPosition InsertBefore = nullptr);
ShuffleVectorInst(Value *V1, Value *V2, ArrayRef<int> Mask,
const Twine &NameStr = "",
- Instruction *InsertBefor = nullptr);
- ShuffleVectorInst(Value *V1, Value *V2, ArrayRef<int> Mask,
- const Twine &NameStr, BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
void *operator new(size_t S) { return User::operator new(S, 2); }
void operator delete(void *Ptr) { return User::operator delete(Ptr); }
@@ -2703,14 +2291,7 @@ class ExtractValueInst : public UnaryInstruction {
/// instruction to the specified BasicBlock.
inline ExtractValueInst(Value *Agg, ArrayRef<unsigned> Idxs,
const Twine &NameStr,
- BasicBlock::iterator InsertBefore);
- inline ExtractValueInst(Value *Agg,
- ArrayRef<unsigned> Idxs,
- const Twine &NameStr,
- Instruction *InsertBefore);
- inline ExtractValueInst(Value *Agg,
- ArrayRef<unsigned> Idxs,
- const Twine &NameStr, BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
@@ -2722,27 +2303,12 @@ class ExtractValueInst : public UnaryInstruction {
public:
static ExtractValueInst *Create(Value *Agg, ArrayRef<unsigned> Idxs,
- const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- return new
- ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
- }
-
- static ExtractValueInst *Create(Value *Agg,
- ArrayRef<unsigned> Idxs,
const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
return new
ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
}
- static ExtractValueInst *Create(Value *Agg,
- ArrayRef<unsigned> Idxs,
- const Twine &NameStr,
- BasicBlock *InsertAtEnd) {
- return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
- }
-
/// Returns the type of the element that would be extracted
/// with an extractvalue instruction with the specified parameters.
///
@@ -2790,30 +2356,12 @@ class ExtractValueInst : public UnaryInstruction {
ExtractValueInst::ExtractValueInst(Value *Agg, ArrayRef<unsigned> Idxs,
const Twine &NameStr,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore)
: UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
ExtractValue, Agg, InsertBefore) {
init(Idxs, NameStr);
}
-ExtractValueInst::ExtractValueInst(Value *Agg,
- ArrayRef<unsigned> Idxs,
- const Twine &NameStr,
- Instruction *InsertBefore)
- : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
- ExtractValue, Agg, InsertBefore) {
- init(Idxs, NameStr);
-}
-
-ExtractValueInst::ExtractValueInst(Value *Agg,
- ArrayRef<unsigned> Idxs,
- const Twine &NameStr,
- BasicBlock *InsertAtEnd)
- : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
- ExtractValue, Agg, InsertAtEnd) {
- init(Idxs, NameStr);
-}
-
//===----------------------------------------------------------------------===//
// InsertValueInst Class
//===----------------------------------------------------------------------===//
@@ -2832,24 +2380,13 @@ class InsertValueInst : public Instruction {
/// the new instruction to the specified BasicBlock.
inline InsertValueInst(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
const Twine &NameStr,
- BasicBlock::iterator InsertBefore);
- inline InsertValueInst(Value *Agg, Value *Val,
- ArrayRef<unsigned> Idxs,
- const Twine &NameStr,
- Instruction *InsertBefore);
- inline InsertValueInst(Value *Agg, Value *Val,
- ArrayRef<unsigned> Idxs,
- const Twine &NameStr, BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
/// Constructors - These three constructors are convenience methods because
/// one and two index insertvalue instructions are so common.
- InsertValueInst(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr,
- BasicBlock::iterator InsertBefore);
InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr);
- InsertValueInst(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr,
- BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
const Twine &NameStr);
@@ -2865,26 +2402,13 @@ class InsertValueInst : public Instruction {
void *operator new(size_t S) { return User::operator new(S, 2); }
void operator delete(void *Ptr) { User::operator delete(Ptr); }
- static InsertValueInst *Create(Value *Agg, Value *Val,
- ArrayRef<unsigned> Idxs, const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
- }
-
static InsertValueInst *Create(Value *Agg, Value *Val,
ArrayRef<unsigned> Idxs,
const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
}
- static InsertValueInst *Create(Value *Agg, Value *Val,
- ArrayRef<unsigned> Idxs,
- const Twine &NameStr,
- BasicBlock *InsertAtEnd) {
- return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
- }
-
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
@@ -2942,35 +2466,12 @@ struct OperandTraits<InsertValueInst> :
public FixedNumOperandTraits<InsertValueInst, 2> {
};
-InsertValueInst::InsertValueInst(Value *Agg,
- Value *Val,
- ArrayRef<unsigned> Idxs,
- const Twine &NameStr,
- BasicBlock::iterator InsertBefore)
- : Instruction(Agg->getType(), InsertValue, OperandTraits<InsertValueInst>::op_begin(this),
- 2, InsertBefore) {
- init(Agg, Val, Idxs, NameStr);
-}
-
-InsertValueInst::InsertValueInst(Value *Agg,
- Value *Val,
- ArrayRef<unsigned> Idxs,
- const Twine &NameStr,
- Instruction *InsertBefore)
- : Instruction(Agg->getType(), InsertValue,
- OperandTraits<InsertValueInst>::op_begin(this),
- 2, InsertBefore) {
- init(Agg, Val, Idxs, NameStr);
-}
-
-InsertValueInst::InsertValueInst(Value *Agg,
- Value *Val,
- ArrayRef<unsigned> Idxs,
- const Twine &NameStr,
- BasicBlock *InsertAtEnd)
- : Instruction(Agg->getType(), InsertValue,
- OperandTraits<InsertValueInst>::op_begin(this),
- 2, InsertAtEnd) {
+InsertValueInst::InsertValueInst(Value *Agg, Value *Val,
+ ArrayRef<unsigned> Idxs, const Twine &NameStr,
+ InsertPosition InsertBefore)
+ : Instruction(Agg->getType(), InsertValue,
+ OperandTraits<InsertValueInst>::op_begin(this), 2,
+ InsertBefore) {
init(Agg, Val, Idxs, NameStr);
}
@@ -2991,29 +2492,11 @@ class PHINode : public Instruction {
PHINode(const PHINode &PN);
- explicit PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
- BasicBlock::iterator InsertBefore)
- : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertBefore),
- ReservedSpace(NumReservedValues) {
- assert(!Ty->isTokenTy() && "PHI nodes cannot have token type!");
- setName(NameStr);
- allocHungoffUses(ReservedSpace);
- }
-
explicit PHINode(Type *Ty, unsigned NumReservedValues,
const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr)
- : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertBefore),
- ReservedSpace(NumReservedValues) {
- assert(!Ty->isTokenTy() && "PHI nodes cannot have token type!");
- setName(NameStr);
- allocHungoffUses(ReservedSpace);
- }
-
- PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
- BasicBlock *InsertAtEnd)
- : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertAtEnd),
- ReservedSpace(NumReservedValues) {
+ InsertPosition InsertBefore = nullptr)
+ : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertBefore),
+ ReservedSpace(NumReservedValues) {
assert(!Ty->isTokenTy() && "PHI nodes cannot have token type!");
setName(NameStr);
allocHungoffUses(ReservedSpace);
@@ -3035,23 +2518,12 @@ class PHINode : public Instruction {
public:
/// Constructors - NumReservedValues is a hint for the number of incoming
/// edges that this phi node will have (use 0 if you really have no idea).
- static PHINode *Create(Type *Ty, unsigned NumReservedValues,
- const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
- }
-
static PHINode *Create(Type *Ty, unsigned NumReservedValues,
const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
}
- static PHINode *Create(Type *Ty, unsigned NumReservedValues,
- const Twine &NameStr, BasicBlock *InsertAtEnd) {
- return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
- }
-
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
@@ -3267,11 +2739,7 @@ class LandingPadInst : public Instruction {
private:
explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
const Twine &NameStr,
- BasicBlock::iterator InsertBefore);
- explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
- const Twine &NameStr, Instruction *InsertBefore);
- explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
- const Twine &NameStr, BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
// Allocate space for exactly zero operands.
void *operator new(size_t S) { return User::operator new(S); }
@@ -3290,14 +2758,9 @@ class LandingPadInst : public Instruction {
/// Constructors - NumReservedClauses is a hint for the number of incoming
/// clauses that this landingpad will have (use 0 if you really have no idea).
- static LandingPadInst *Create(Type *RetTy, unsigned NumReservedClauses,
- const Twine &NameStr,
- BasicBlock::iterator InsertBefore);
static LandingPadInst *Create(Type *RetTy, unsigned NumReservedClauses,
const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr);
- static LandingPadInst *Create(Type *RetTy, unsigned NumReservedClauses,
- const Twine &NameStr, BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
@@ -3376,12 +2839,9 @@ class ReturnInst : public Instruction {
//
// NOTE: If the Value* passed is of type void then the constructor behaves as
// if it was passed NULL.
- explicit ReturnInst(LLVMContext &C, Value *retVal,
- BasicBlock::iterator InsertBefore);
explicit ReturnInst(LLVMContext &C, Value *retVal = nullptr,
- Instruction *InsertBefore = nullptr);
- ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
- explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
+ explicit ReturnInst(LLVMContext &C, InsertPosition InsertBefore);
protected:
// Note: Instruction needs to be a friend here to call cloneImpl.
@@ -3390,23 +2850,13 @@ class ReturnInst : public Instruction {
ReturnInst *cloneImpl() const;
public:
- static ReturnInst *Create(LLVMContext &C, Value *retVal,
- BasicBlock::iterator InsertBefore) {
- return new (!!retVal) ReturnInst(C, retVal, InsertBefore);
- }
-
- static ReturnInst* Create(LLVMContext &C, Value *retVal = nullptr,
- Instruction *InsertBefore = nullptr) {
+ static ReturnInst *Create(LLVMContext &C, Value *retVal = nullptr,
+ InsertPosition InsertBefore = nullptr) {
return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
}
- static ReturnInst* Create(LLVMContext &C, Value *retVal,
- BasicBlock *InsertAtEnd) {
- return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
- }
-
- static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
- return new(0) ReturnInst(C, InsertAtEnd);
+ static ReturnInst *Create(LLVMContext &C, InsertPosition InsertBefore) {
+ return new (0) ReturnInst(C, InsertBefore);
}
/// Provide fast operand accessors
@@ -3465,15 +2915,10 @@ class BranchInst : public Instruction {
// BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
// BranchInst(BB* B, BB *I) - 'br B' insert at end
// BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
- explicit BranchInst(BasicBlock *IfTrue, BasicBlock::iterator InsertBefore);
- BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
- BasicBlock::iterator InsertBefore);
- explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = nullptr);
+ explicit BranchInst(BasicBlock *IfTrue,
+ InsertPosition InsertBefore = nullptr);
BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
- Instruction *InsertBefore = nullptr);
- BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
- BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
- BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
void AssertOK();
@@ -3512,34 +2957,16 @@ class BranchInst : public Instruction {
};
static BranchInst *Create(BasicBlock *IfTrue,
- BasicBlock::iterator InsertBefore) {
- return new(1) BranchInst(IfTrue, InsertBefore);
- }
-
- static BranchInst *Create(BasicBlock *IfTrue,
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
return new(1) BranchInst(IfTrue, InsertBefore);
}
static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
- Value *Cond, BasicBlock::iterator InsertBefore) {
+ Value *Cond,
+ InsertPosition InsertBefore = nullptr) {
return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
}
- static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
- Value *Cond, Instruction *InsertBefore = nullptr) {
- return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
- }
-
- static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
- return new(1) BranchInst(IfTrue, InsertAtEnd);
- }
-
- static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
- Value *Cond, BasicBlock *InsertAtEnd) {
- return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
- }
-
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
@@ -3623,21 +3050,7 @@ class SwitchInst : public Instruction {
/// to make memory allocation more efficient. This constructor can also
/// auto-insert before another instruction.
SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
- BasicBlock::iterator InsertBefore);
-
- /// Create a new switch instruction, specifying a value to switch on and a
- /// default destination. The number of additional cases can be specified here
- /// to make memory allocation more efficient. This constructor can also
- /// auto-insert before another instruction.
- SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
- Instruction *InsertBefore);
-
- /// Create a new switch instruction, specifying a value to switch on and a
- /// default destination. The number of additional cases can be specified here
- /// to make memory allocation more efficient. This constructor also
- /// auto-inserts at the end of the specified BasicBlock.
- SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
- BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
// allocate space for exactly zero operands
void *operator new(size_t S) { return User::operator new(S); }
@@ -3807,21 +3220,10 @@ class SwitchInst : public Instruction {
static SwitchInst *Create(Value *Value, BasicBlock *Default,
unsigned NumCases,
- BasicBlock::iterator InsertBefore) {
+ InsertPosition InsertBefore = nullptr) {
return new SwitchInst(Value, Default, NumCases, InsertBefore);
}
- static SwitchInst *Create(Value *Value, BasicBlock *Default,
- unsigned NumCases,
- Instruction *InsertBefore = nullptr) {
- return new SwitchInst(Value, Default, NumCases, InsertBefore);
- }
-
- static SwitchInst *Create(Value *Value, BasicBlock *Default,
- unsigned NumCases, BasicBlock *InsertAtEnd) {
- return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
- }
-
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
@@ -4036,19 +3438,7 @@ class IndirectBrInst : public Instruction {
/// here to make memory allocation more efficient. This constructor can also
/// autoinsert before another instruction.
IndirectBrInst(Value *Address, unsigned NumDests,
- BasicBlock::iterator InsertBefore);
-
- /// Create a new indirectbr instruction, specifying an
- /// Address to jump to. The number of expected destinations can be specified
- /// here to make memory allocation more efficient. This constructor can also
- /// autoinsert before another instruction.
- IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
-
- /// Create a new indirectbr instruction, specifying an
- /// Address to jump to. The number of expected destinations can be specified
- /// here to make memory allocation more efficient. This constructor also
- /// autoinserts at the end of the specified BasicBlock.
- IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
// allocate space for exactly zero operands
void *operator new(size_t S) { return User::operator new(S); }
@@ -4093,20 +3483,10 @@ class IndirectBrInst : public Instruction {
};
static IndirectBrInst *Create(Value *Address, unsigned NumDests,
- BasicBlock::iterator InsertBefore) {
- return new IndirectBrInst(Address, NumDests, InsertBefore);
- }
-
- static IndirectBrInst *Create(Value *Address, unsigned NumDests,
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
return new IndirectBrInst(Address, NumDests, InsertBefore);
}
- static IndirectBrInst *Create(Value *Address, unsigned NumDests,
- BasicBlock *InsertAtEnd) {
- return new IndirectBrInst(Address, NumDests, InsertAtEnd);
- }
-
/// Provide fast operand accessors.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
@@ -4184,24 +3564,14 @@ class InvokeInst : public CallBase {
InvokeInst(const InvokeInst &BI);
- /// Construct an InvokeInst given a range of arguments.
- inline InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
- BasicBlock *IfException, ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles, int NumOperands,
- const Twine &NameStr, BasicBlock::iterator InsertBefore);
-
/// Construct an InvokeInst given a range of arguments.
///
/// Construct an InvokeInst from a range of arguments
inline InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
BasicBlock *IfException, ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> Bundles, int NumOperands,
- const Twine &NameStr, Instruction *InsertBefore);
-
- inline InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
- BasicBlock *IfException, ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles, int NumOperands,
- const Twine &NameStr, BasicBlock *InsertAtEnd);
+ const Twine &NameStr,
+ InsertPosition InsertBefore = nullptr);
void init(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
BasicBlock *IfException, ArrayRef<Value *> Args,
@@ -4224,42 +3594,18 @@ class InvokeInst : public CallBase {
static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
BasicBlock *IfException, ArrayRef<Value *> Args,
const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
+ InsertPosition InsertBefore = nullptr) {
int NumOperands = ComputeNumOperands(Args.size());
return new (NumOperands)
InvokeInst(Ty, Func, IfNormal, IfException, Args, std::nullopt,
NumOperands, NameStr, InsertBefore);
}
- static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
- BasicBlock *IfException, ArrayRef<Value *> Args,
- const Twine &NameStr,
- Instruction *InsertBefore = nullptr) {
- int NumOperands = ComputeNumOperands(Args.size());
- return new (NumOperands)
- InvokeInst(Ty, Func, IfNormal, IfException, Args, std::nullopt,
- NumOperands, NameStr, InsertBefore);
- }
-
- static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
- BasicBlock *IfException, ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles,
- const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- int NumOperands =
- ComputeNumOperands(Args.size(), CountBundleInputs(Bundles));
- unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
-
- return new (NumOperands, DescriptorBytes)
- InvokeInst(Ty, Func, IfNormal, IfException, Args, Bundles, NumOperands,
- NameStr, InsertBefore);
- }
-
static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
BasicBlock *IfException, ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> Bundles = std::nullopt,
const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
int NumOperands =
ComputeNumOperands(Args.size(), CountBundleInputs(Bundles));
unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
@@ -4269,87 +3615,31 @@ class InvokeInst : public CallBase {
NameStr, InsertBefore);
}
- static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
- BasicBlock *IfException, ArrayRef<Value *> Args,
- const Twine &NameStr, BasicBlock *InsertAtEnd) {
- int NumOperands = ComputeNumOperands(Args.size());
- return new (NumOperands)
- InvokeInst(Ty, Func, IfNormal, IfException, Args, std::nullopt,
- NumOperands, NameStr, InsertAtEnd);
- }
-
- static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
- BasicBlock *IfException, ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles,
- const Twine &NameStr, BasicBlock *InsertAtEnd) {
- int NumOperands =
- ComputeNumOperands(Args.size(), CountBundleInputs(Bundles));
- unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
-
- return new (NumOperands, DescriptorBytes)
- InvokeInst(Ty, Func, IfNormal, IfException, Args, Bundles, NumOperands,
- NameStr, InsertAtEnd);
- }
-
- static InvokeInst *Create(FunctionCallee Func, BasicBlock *IfNormal,
- BasicBlock *IfException, ArrayRef<Value *> Args,
- const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
- IfException, Args, std::nullopt, NameStr, InsertBefore);
- }
-
static InvokeInst *Create(FunctionCallee Func, BasicBlock *IfNormal,
BasicBlock *IfException, ArrayRef<Value *> Args,
const Twine &NameStr,
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
IfException, Args, std::nullopt, NameStr, InsertBefore);
}
- static InvokeInst *Create(FunctionCallee Func, BasicBlock *IfNormal,
- BasicBlock *IfException, ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles,
- const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
- IfException, Args, Bundles, NameStr, InsertBefore);
- }
-
static InvokeInst *Create(FunctionCallee Func, BasicBlock *IfNormal,
BasicBlock *IfException, ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> Bundles = std::nullopt,
const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
IfException, Args, Bundles, NameStr, InsertBefore);
}
- static InvokeInst *Create(FunctionCallee Func, BasicBlock *IfNormal,
- BasicBlock *IfException, ArrayRef<Value *> Args,
- const Twine &NameStr, BasicBlock *InsertAtEnd) {
- return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
- IfException, Args, NameStr, InsertAtEnd);
- }
-
- static InvokeInst *Create(FunctionCallee Func, BasicBlock *IfNormal,
- BasicBlock *IfException, ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles,
- const Twine &NameStr, BasicBlock *InsertAtEnd) {
- return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
- IfException, Args, Bundles, NameStr, InsertAtEnd);
- }
-
/// Create a clone of \p II with a different set of operand bundles and
- /// insert it before \p InsertPt.
+ /// insert it before \p InsertBefore.
///
/// The returned invoke instruction is identical to \p II in every way except
/// that the operand bundles for the new instruction are set to the operand
/// bundles in \p Bundles.
static InvokeInst *Create(InvokeInst *II, ArrayRef<OperandBundleDef> Bundles,
- BasicBlock::iterator InsertPt);
- static InvokeInst *Create(InvokeInst *II, ArrayRef<OperandBundleDef> Bundles,
- Instruction *InsertPt = nullptr);
+ InsertPosition InsertPt = nullptr);
// get*Dest - Return the destination basic blocks...
BasicBlock *getNormalDest() const {
@@ -4407,33 +3697,13 @@ class InvokeInst : public CallBase {
InvokeInst::InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
BasicBlock *IfException, ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> Bundles, int NumOperands,
- const Twine &NameStr, BasicBlock::iterator InsertBefore)
+ const Twine &NameStr, InsertPosition InsertBefore)
: CallBase(Ty->getReturnType(), Instruction::Invoke,
OperandTraits<CallBase>::op_end(this) - NumOperands, NumOperands,
InsertBefore) {
init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr);
}
-InvokeInst::InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
- BasicBlock *IfException, ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles, int NumOperands,
- const Twine &NameStr, Instruction *InsertBefore)
- : CallBase(Ty->getReturnType(), Instruction::Invoke,
- OperandTraits<CallBase>::op_end(this) - NumOperands, NumOperands,
- InsertBefore) {
- init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr);
-}
-
-InvokeInst::InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
- BasicBlock *IfException, ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles, int NumOperands,
- const Twine &NameStr, BasicBlock *InsertAtEnd)
- : CallBase(Ty->getReturnType(), Instruction::Invoke,
- OperandTraits<CallBase>::op_end(this) - NumOperands, NumOperands,
- InsertAtEnd) {
- init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr);
-}
-
//===----------------------------------------------------------------------===//
// CallBrInst Class
//===----------------------------------------------------------------------===//
@@ -4448,27 +3718,14 @@ class CallBrInst : public CallBase {
CallBrInst(const CallBrInst &BI);
- /// Construct a CallBrInst given a range of arguments.
- inline CallBrInst(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
- ArrayRef<BasicBlock *> IndirectDests,
- ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles,
- int NumOperands, const Twine &NameStr,
- BasicBlock::iterator InsertBefore);
-
/// Construct a CallBrInst given a range of arguments.
///
/// Construct a CallBrInst from a range of arguments
inline CallBrInst(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
ArrayRef<BasicBlock *> IndirectDests,
- ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles, int NumOperands,
- const Twine &NameStr, Instruction *InsertBefore);
-
- inline CallBrInst(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
- ArrayRef<BasicBlock *> IndirectDests,
- ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles, int NumOperands,
- const Twine &NameStr, BasicBlock *InsertAtEnd);
+ ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles,
+ int NumOperands, const Twine &NameStr,
+ InsertPosition InsertBefore = nullptr);
void init(FunctionType *FTy, Value *Func, BasicBlock *DefaultDest,
ArrayRef<BasicBlock *> IndirectDests, ArrayRef<Value *> Args,
@@ -4493,43 +3750,18 @@ class CallBrInst : public CallBase {
BasicBlock *DefaultDest,
ArrayRef<BasicBlock *> IndirectDests,
ArrayRef<Value *> Args, const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- int NumOperands = ComputeNumOperands(Args.size(), IndirectDests.size());
- return new (NumOperands)
- CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, std::nullopt,
- NumOperands, NameStr, InsertBefore);
- }
-
- static CallBrInst *Create(FunctionType *Ty, Value *Func,
- BasicBlock *DefaultDest,
- ArrayRef<BasicBlock *> IndirectDests,
- ArrayRef<Value *> Args, const Twine &NameStr,
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
int NumOperands = ComputeNumOperands(Args.size(), IndirectDests.size());
return new (NumOperands)
CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, std::nullopt,
NumOperands, NameStr, InsertBefore);
}
- static CallBrInst *
- Create(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
- ArrayRef<BasicBlock *> IndirectDests, ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- int NumOperands = ComputeNumOperands(Args.size(), IndirectDests.size(),
- CountBundleInputs(Bundles));
- unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
-
- return new (NumOperands, DescriptorBytes)
- CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, Bundles,
- NumOperands, NameStr, InsertBefore);
- }
-
static CallBrInst *
Create(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
ArrayRef<BasicBlock *> IndirectDests, ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> Bundles = std::nullopt,
- const Twine &NameStr = "", Instruction *InsertBefore = nullptr) {
+ const Twine &NameStr = "", InsertPosition InsertBefore = nullptr) {
int NumOperands = ComputeNumOperands(Args.size(), IndirectDests.size(),
CountBundleInputs(Bundles));
unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
@@ -4539,97 +3771,32 @@ class CallBrInst : public CallBase {
NumOperands, NameStr, InsertBefore);
}
- static CallBrInst *Create(FunctionType *Ty, Value *Func,
- BasicBlock *DefaultDest,
- ArrayRef<BasicBlock *> IndirectDests,
- ArrayRef<Value *> Args, const Twine &NameStr,
- BasicBlock *InsertAtEnd) {
- int NumOperands = ComputeNumOperands(Args.size(), IndirectDests.size());
- return new (NumOperands)
- CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, std::nullopt,
- NumOperands, NameStr, InsertAtEnd);
- }
-
- static CallBrInst *Create(FunctionType *Ty, Value *Func,
- BasicBlock *DefaultDest,
- ArrayRef<BasicBlock *> IndirectDests,
- ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles,
- const Twine &NameStr, BasicBlock *InsertAtEnd) {
- int NumOperands = ComputeNumOperands(Args.size(), IndirectDests.size(),
- CountBundleInputs(Bundles));
- unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
-
- return new (NumOperands, DescriptorBytes)
- CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, Bundles,
- NumOperands, NameStr, InsertAtEnd);
- }
-
static CallBrInst *Create(FunctionCallee Func, BasicBlock *DefaultDest,
ArrayRef<BasicBlock *> IndirectDests,
ArrayRef<Value *> Args, const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
+ InsertPosition InsertBefore = nullptr) {
return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
IndirectDests, Args, NameStr, InsertBefore);
}
- static CallBrInst *Create(FunctionCallee Func, BasicBlock *DefaultDest,
- ArrayRef<BasicBlock *> IndirectDests,
- ArrayRef<Value *> Args, const Twine &NameStr,
- Instruction *InsertBefore = nullptr) {
- return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
- IndirectDests, Args, NameStr, InsertBefore);
- }
-
- static CallBrInst *Create(FunctionCallee Func, BasicBlock *DefaultDest,
- ArrayRef<BasicBlock *> IndirectDests,
- ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles,
- const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
- IndirectDests, Args, Bundles, NameStr, InsertBefore);
- }
-
static CallBrInst *Create(FunctionCallee Func, BasicBlock *DefaultDest,
ArrayRef<BasicBlock *> IndirectDests,
ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> Bundles = std::nullopt,
const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
IndirectDests, Args, Bundles, NameStr, InsertBefore);
}
- static CallBrInst *Create(FunctionCallee Func, BasicBlock *DefaultDest,
- ArrayRef<BasicBlock *> IndirectDests,
- ArrayRef<Value *> Args, const Twine &NameStr,
- BasicBlock *InsertAtEnd) {
- return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
- IndirectDests, Args, NameStr, InsertAtEnd);
- }
-
- static CallBrInst *Create(FunctionCallee Func,
- BasicBlock *DefaultDest,
- ArrayRef<BasicBlock *> IndirectDests,
- ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles,
- const Twine &NameStr, BasicBlock *InsertAtEnd) {
- return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
- IndirectDests, Args, Bundles, NameStr, InsertAtEnd);
- }
-
/// Create a clone of \p CBI with a different set of operand bundles and
- /// insert it before \p InsertPt.
+ /// insert it before \p InsertBefore.
///
/// The returned callbr instruction is identical to \p CBI in every way
/// except that the operand bundles for the new instruction are set to the
/// operand bundles in \p Bundles.
static CallBrInst *Create(CallBrInst *CBI, ArrayRef<OperandBundleDef> Bundles,
- BasicBlock::iterator InsertPt);
- static CallBrInst *Create(CallBrInst *CBI,
- ArrayRef<OperandBundleDef> Bundles,
- Instruction *InsertPt = nullptr);
+ InsertPosition InsertBefore = nullptr);
/// Return the number of callbr indirect dest labels.
///
@@ -4702,35 +3869,13 @@ CallBrInst::CallBrInst(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
ArrayRef<BasicBlock *> IndirectDests,
ArrayRef<Value *> Args,
ArrayRef<OperandBundleDef> Bundles, int NumOperands,
- const Twine &NameStr, BasicBlock::iterator InsertBefore)
- : CallBase(Ty->getReturnType(), Instruction::CallBr,
- OperandTraits<CallBase>::op_end(this) - NumOperands, NumOperands,
- InsertBefore) {
- init(Ty, Func, DefaultDest, IndirectDests, Args, Bundles, NameStr);
-}
-
-CallBrInst::CallBrInst(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
- ArrayRef<BasicBlock *> IndirectDests,
- ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles, int NumOperands,
- const Twine &NameStr, Instruction *InsertBefore)
+ const Twine &NameStr, InsertPosition InsertBefore)
: CallBase(Ty->getReturnType(), Instruction::CallBr,
OperandTraits<CallBase>::op_end(this) - NumOperands, NumOperands,
InsertBefore) {
init(Ty, Func, DefaultDest, IndirectDests, Args, Bundles, NameStr);
}
-CallBrInst::CallBrInst(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
- ArrayRef<BasicBlock *> IndirectDests,
- ArrayRef<Value *> Args,
- ArrayRef<OperandBundleDef> Bundles, int NumOperands,
- const Twine &NameStr, BasicBlock *InsertAtEnd)
- : CallBase(Ty->getReturnType(), Instruction::CallBr,
- OperandTraits<CallBase>::op_end(this) - NumOperands, NumOperands,
- InsertAtEnd) {
- init(Ty, Func, DefaultDest, IndirectDests, Args, Bundles, NameStr);
-}
-
//===----------------------------------------------------------------------===//
// ResumeInst Class
//===----------------------------------------------------------------------===//
@@ -4741,9 +3886,7 @@ CallBrInst::CallBrInst(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
class ResumeInst : public Instruction {
ResumeInst(const ResumeInst &RI);
- explicit ResumeInst(Value *Exn, Instruction *InsertBefore=nullptr);
- explicit ResumeInst(Value *Exn, BasicBlock::iterator InsertBefore);
- ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
+ explicit ResumeInst(Value *Exn, InsertPosition InsertBefore = nullptr);
protected:
// Note: Instruction needs to be a friend here to call cloneImpl.
@@ -4752,18 +3895,10 @@ class ResumeInst : public Instruction {
ResumeInst *cloneImpl() const;
public:
- static ResumeInst *Create(Value *Exn, BasicBlock::iterator InsertBefore) {
- return new (1) ResumeInst(Exn, InsertBefore);
- }
-
- static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = nullptr) {
+ static ResumeInst *Create(Value *Exn, InsertPosition InsertBefore = nullptr) {
return new(1) ResumeInst(Exn, InsertBefore);
}
- static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
- return new(1) ResumeInst(Exn, InsertAtEnd);
- }
-
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
@@ -4818,23 +3953,7 @@ class CatchSwitchInst : public Instruction {
/// This constructor can also autoinsert before another instruction.
CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
unsigned NumHandlers, const Twine &NameStr,
- BasicBlock::iterator InsertBefore);
-
- /// Create a new switch instruction, specifying a
- /// default destination. The number of additional handlers can be specified
- /// here to make memory allocation more efficient.
- /// This constructor can also autoinsert before another instruction.
- CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
- unsigned NumHandlers, const Twine &NameStr,
- Instruction *InsertBefore);
-
- /// Create a new switch instruction, specifying a
- /// default destination. The number of additional handlers can be specified
- /// here to make memory allocation more efficient.
- /// This constructor also autoinserts at the end of the specified BasicBlock.
- CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
- unsigned NumHandlers, const Twine &NameStr,
- BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
// allocate space for exactly zero operands
void *operator new(size_t S) { return User::operator new(S); }
@@ -4851,28 +3970,14 @@ class CatchSwitchInst : public Instruction {
public:
void operator delete(void *Ptr) { return User::operator delete(Ptr); }
- static CatchSwitchInst *Create(Value *ParentPad, BasicBlock *UnwindDest,
- unsigned NumHandlers, const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr,
- InsertBefore);
- }
-
static CatchSwitchInst *Create(Value *ParentPad, BasicBlock *UnwindDest,
unsigned NumHandlers,
const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr,
InsertBefore);
}
- static CatchSwitchInst *Create(Value *ParentPad, BasicBlock *UnwindDest,
- unsigned NumHandlers, const Twine &NameStr,
- BasicBlock *InsertAtEnd) {
- return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr,
- InsertAtEnd);
- }
-
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
@@ -4997,45 +4102,20 @@ class CleanupPadInst : public FuncletPadInst {
private:
explicit CleanupPadInst(Value *ParentPad, ArrayRef<Value *> Args,
unsigned Values, const Twine &NameStr,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore = nullptr)
: FuncletPadInst(Instruction::CleanupPad, ParentPad, Args, Values,
NameStr, InsertBefore) {}
- explicit CleanupPadInst(Value *ParentPad, ArrayRef<Value *> Args,
- unsigned Values, const Twine &NameStr,
- Instruction *InsertBefore)
- : FuncletPadInst(Instruction::CleanupPad, ParentPad, Args, Values,
- NameStr, InsertBefore) {}
- explicit CleanupPadInst(Value *ParentPad, ArrayRef<Value *> Args,
- unsigned Values, const Twine &NameStr,
- BasicBlock *InsertAtEnd)
- : FuncletPadInst(Instruction::CleanupPad, ParentPad, Args, Values,
- NameStr, InsertAtEnd) {}
public:
- static CleanupPadInst *Create(Value *ParentPad, ArrayRef<Value *> Args,
- const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- unsigned Values = 1 + Args.size();
- return new (Values)
- CleanupPadInst(ParentPad, Args, Values, NameStr, InsertBefore);
- }
-
static CleanupPadInst *Create(Value *ParentPad,
ArrayRef<Value *> Args = std::nullopt,
const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
unsigned Values = 1 + Args.size();
return new (Values)
CleanupPadInst(ParentPad, Args, Values, NameStr, InsertBefore);
}
- static CleanupPadInst *Create(Value *ParentPad, ArrayRef<Value *> Args,
- const Twine &NameStr, BasicBlock *InsertAtEnd) {
- unsigned Values = 1 + Args.size();
- return new (Values)
- CleanupPadInst(ParentPad, Args, Values, NameStr, InsertAtEnd);
- }
-
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::CleanupPad;
@@ -5052,44 +4132,19 @@ class CatchPadInst : public FuncletPadInst {
private:
explicit CatchPadInst(Value *CatchSwitch, ArrayRef<Value *> Args,
unsigned Values, const Twine &NameStr,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore = nullptr)
: FuncletPadInst(Instruction::CatchPad, CatchSwitch, Args, Values,
NameStr, InsertBefore) {}
- explicit CatchPadInst(Value *CatchSwitch, ArrayRef<Value *> Args,
- unsigned Values, const Twine &NameStr,
- Instruction *InsertBefore)
- : FuncletPadInst(Instruction::CatchPad, CatchSwitch, Args, Values,
- NameStr, InsertBefore) {}
- explicit CatchPadInst(Value *CatchSwitch, ArrayRef<Value *> Args,
- unsigned Values, const Twine &NameStr,
- BasicBlock *InsertAtEnd)
- : FuncletPadInst(Instruction::CatchPad, CatchSwitch, Args, Values,
- NameStr, InsertAtEnd) {}
public:
- static CatchPadInst *Create(Value *CatchSwitch, ArrayRef<Value *> Args,
- const Twine &NameStr,
- BasicBlock::iterator InsertBefore) {
- unsigned Values = 1 + Args.size();
- return new (Values)
- CatchPadInst(CatchSwitch, Args, Values, NameStr, InsertBefore);
- }
-
static CatchPadInst *Create(Value *CatchSwitch, ArrayRef<Value *> Args,
const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
unsigned Values = 1 + Args.size();
return new (Values)
CatchPadInst(CatchSwitch, Args, Values, NameStr, InsertBefore);
}
- static CatchPadInst *Create(Value *CatchSwitch, ArrayRef<Value *> Args,
- const Twine &NameStr, BasicBlock *InsertAtEnd) {
- unsigned Values = 1 + Args.size();
- return new (Values)
- CatchPadInst(CatchSwitch, Args, Values, NameStr, InsertAtEnd);
- }
-
/// Convenience accessors
CatchSwitchInst *getCatchSwitch() const {
return cast<CatchSwitchInst>(Op<-1>());
@@ -5115,9 +4170,7 @@ class CatchPadInst : public FuncletPadInst {
class CatchReturnInst : public Instruction {
CatchReturnInst(const CatchReturnInst &RI);
CatchReturnInst(Value *CatchPad, BasicBlock *BB,
- BasicBlock::iterator InsertBefore);
- CatchReturnInst(Value *CatchPad, BasicBlock *BB, Instruction *InsertBefore);
- CatchReturnInst(Value *CatchPad, BasicBlock *BB, BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
void init(Value *CatchPad, BasicBlock *BB);
@@ -5129,26 +4182,12 @@ class CatchReturnInst : public Instruction {
public:
static CatchReturnInst *Create(Value *CatchPad, BasicBlock *BB,
- BasicBlock::iterator InsertBefore) {
+ InsertPosition InsertBefore = nullptr) {
assert(CatchPad);
assert(BB);
return new (2) CatchReturnInst(CatchPad, BB, InsertBefore);
}
- static CatchReturnInst *Create(Value *CatchPad, BasicBlock *BB,
- Instruction *InsertBefore = nullptr) {
- assert(CatchPad);
- assert(BB);
- return new (2) CatchReturnInst(CatchPad, BB, InsertBefore);
- }
-
- static CatchReturnInst *Create(Value *CatchPad, BasicBlock *BB,
- BasicBlock *InsertAtEnd) {
- assert(CatchPad);
- assert(BB);
- return new (2) CatchReturnInst(CatchPad, BB, InsertAtEnd);
- }
-
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
@@ -5208,11 +4247,7 @@ class CleanupReturnInst : public Instruction {
private:
CleanupReturnInst(const CleanupReturnInst &RI);
CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB, unsigned Values,
- BasicBlock::iterator InsertBefore);
- CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB, unsigned Values,
- Instruction *InsertBefore = nullptr);
- CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB, unsigned Values,
- BasicBlock *InsertAtEnd);
+ InsertPosition InsertBefore = nullptr);
void init(Value *CleanupPad, BasicBlock *UnwindBB);
@@ -5223,19 +4258,9 @@ class CleanupReturnInst : public Instruction {
CleanupReturnInst *cloneImpl() const;
public:
- static CleanupReturnInst *Create(Value *CleanupPad, BasicBlock *UnwindBB,
- BasicBlock::iterator InsertBefore) {
- assert(CleanupPad);
- unsigned Values = 1;
- if (UnwindBB)
- ++Values;
- return new (Values)
- CleanupReturnInst(CleanupPad, UnwindBB, Values, InsertBefore);
- }
-
static CleanupReturnInst *Create(Value *CleanupPad,
BasicBlock *UnwindBB = nullptr,
- Instruction *InsertBefore = nullptr) {
+ InsertPosition InsertBefore = nullptr) {
assert(CleanupPad);
unsigned Values = 1;
if (UnwindBB)
@@ -5244,16 +4269,6 @@ class CleanupReturnInst : public Instruction {
CleanupReturnInst(CleanupPad, UnwindBB, Values, InsertBefore);
}
- static CleanupReturnInst *Create(Value *CleanupPad, BasicBlock *UnwindBB,
- BasicBlock *InsertAtEnd) {
- assert(CleanupPad);
- unsigned Values = 1;
- if (UnwindBB)
- ++Values;
- return new (Values)
- CleanupReturnInst(CleanupPad, UnwindBB, Values, InsertAtEnd);
- }
-
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
@@ -5330,9 +4345,8 @@ class UnreachableInst : public Instruction {
UnreachableInst *cloneImpl() const;
public:
- explicit UnreachableInst(LLVMContext &C, BasicBlock::iterator InsertBefore);
- explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = nullptr);
- explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
+ explicit UnreachableInst(LLVMContext &C,
+ InsertPosition InsertBefore = nullptr);
// allocate space for exactly zero operands
void *operator new(size_t S) { return User::operator new(S, 0); }
@@ -5375,27 +4389,11 @@ class TruncInst : public CastInst {
enum { AnyWrap = 0, NoUnsignedWrap = (1 << 0), NoSignedWrap = (1 << 1) };
/// Constructor with insert-before-instruction semantics
- TruncInst(
- Value *S, ///< The value to be truncated
- Type *Ty, ///< The (smaller) type to truncate to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-before-instruction semantics
- TruncInst(
- Value *S, ///< The value to be truncated
- Type *Ty, ///< The (smaller) type to truncate to
- const Twine &NameStr = "", ///< A name for the new instruction
- Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-at-end-of-block semantics
- TruncInst(
- Value *S, ///< The value to be truncated
- Type *Ty, ///< The (smaller) type to truncate to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock *InsertAtEnd ///< The block to insert the instruction into
+ TruncInst(Value *S, ///< The value to be truncated
+ Type *Ty, ///< The (smaller) type to truncate to
+ const Twine &NameStr = "", ///< A name for the new instruction
+ InsertPosition InsertBefore =
+ nullptr ///< Where to insert the new instruction
);
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -5455,27 +4453,11 @@ class ZExtInst : public CastInst {
public:
/// Constructor with insert-before-instruction semantics
- ZExtInst(
- Value *S, ///< The value to be zero extended
- Type *Ty, ///< The type to zero extend to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-before-instruction semantics
- ZExtInst(
- Value *S, ///< The value to be zero extended
- Type *Ty, ///< The type to zero extend to
- const Twine &NameStr = "", ///< A name for the new instruction
- Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-at-end semantics.
- ZExtInst(
- Value *S, ///< The value to be zero extended
- Type *Ty, ///< The type to zero extend to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock *InsertAtEnd ///< The block to insert the instruction into
+ ZExtInst(Value *S, ///< The value to be zero extended
+ Type *Ty, ///< The type to zero extend to
+ const Twine &NameStr = "", ///< A name for the new instruction
+ InsertPosition InsertBefore =
+ nullptr ///< Where to insert the new instruction
);
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -5502,27 +4484,11 @@ class SExtInst : public CastInst {
public:
/// Constructor with insert-before-instruction semantics
- SExtInst(
- Value *S, ///< The value to be sign extended
- Type *Ty, ///< The type to sign extend to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-before-instruction semantics
- SExtInst(
- Value *S, ///< The value to be sign extended
- Type *Ty, ///< The type to sign extend to
- const Twine &NameStr = "", ///< A name for the new instruction
- Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-at-end-of-block semantics
- SExtInst(
- Value *S, ///< The value to be sign extended
- Type *Ty, ///< The type to sign extend to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock *InsertAtEnd ///< The block to insert the instruction into
+ SExtInst(Value *S, ///< The value to be sign extended
+ Type *Ty, ///< The type to sign extend to
+ const Twine &NameStr = "", ///< A name for the new instruction
+ InsertPosition InsertBefore =
+ nullptr ///< Where to insert the new instruction
);
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -5547,29 +4513,12 @@ class FPTruncInst : public CastInst {
/// Clone an identical FPTruncInst
FPTruncInst *cloneImpl() const;
-public:
- /// Constructor with insert-before-instruction semantics
- FPTruncInst(
- Value *S, ///< The value to be truncated
- Type *Ty, ///< The type to truncate to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-before-instruction semantics
- FPTruncInst(
- Value *S, ///< The value to be truncated
- Type *Ty, ///< The type to truncate to
- const Twine &NameStr = "", ///< A name for the new instruction
- Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-before-instruction semantics
- FPTruncInst(
- Value *S, ///< The value to be truncated
- Type *Ty, ///< The type to truncate to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock *InsertAtEnd ///< The block to insert the instruction into
+public: /// Constructor with insert-before-instruction semantics
+ FPTruncInst(Value *S, ///< The value to be truncated
+ Type *Ty, ///< The type to truncate to
+ const Twine &NameStr = "", ///< A name for the new instruction
+ InsertPosition InsertBefore =
+ nullptr ///< Where to insert the new instruction
);
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -5596,27 +4545,11 @@ class FPExtInst : public CastInst {
public:
/// Constructor with insert-before-instruction semantics
- FPExtInst(
- Value *S, ///< The value to be extended
- Type *Ty, ///< The type to extend to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-before-instruction semantics
- FPExtInst(
- Value *S, ///< The value to be extended
- Type *Ty, ///< The type to extend to
- const Twine &NameStr = "", ///< A name for the new instruction
- Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-at-end-of-block semantics
- FPExtInst(
- Value *S, ///< The value to be extended
- Type *Ty, ///< The type to extend to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock *InsertAtEnd ///< The block to insert the instruction into
+ FPExtInst(Value *S, ///< The value to be extended
+ Type *Ty, ///< The type to extend to
+ const Twine &NameStr = "", ///< A name for the new instruction
+ InsertPosition InsertBefore =
+ nullptr ///< Where to insert the new instruction
);
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -5643,27 +4576,11 @@ class UIToFPInst : public CastInst {
public:
/// Constructor with insert-before-instruction semantics
- UIToFPInst(
- Value *S, ///< The value to be converted
- Type *Ty, ///< The type to convert to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-before-instruction semantics
- UIToFPInst(
- Value *S, ///< The value to be converted
- Type *Ty, ///< The type to convert to
- const Twine &NameStr = "", ///< A name for the new instruction
- Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-at-end-of-block semantics
- UIToFPInst(
- Value *S, ///< The value to be converted
- Type *Ty, ///< The type to convert to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock *InsertAtEnd ///< The block to insert the instruction into
+ UIToFPInst(Value *S, ///< The value to be converted
+ Type *Ty, ///< The type to convert to
+ const Twine &NameStr = "", ///< A name for the new instruction
+ InsertPosition InsertBefore =
+ nullptr ///< Where to insert the new instruction
);
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -5690,27 +4607,11 @@ class SIToFPInst : public CastInst {
public:
/// Constructor with insert-before-instruction semantics
- SIToFPInst(
- Value *S, ///< The value to be converted
- Type *Ty, ///< The type to convert to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-before-instruction semantics
- SIToFPInst(
- Value *S, ///< The value to be converted
- Type *Ty, ///< The type to convert to
- const Twine &NameStr = "", ///< A name for the new instruction
- Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-at-end-of-block semantics
- SIToFPInst(
- Value *S, ///< The value to be converted
- Type *Ty, ///< The type to convert to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock *InsertAtEnd ///< The block to insert the instruction into
+ SIToFPInst(Value *S, ///< The value to be converted
+ Type *Ty, ///< The type to convert to
+ const Twine &NameStr = "", ///< A name for the new instruction
+ InsertPosition InsertBefore =
+ nullptr ///< Where to insert the new instruction
);
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -5737,27 +4638,11 @@ class FPToUIInst : public CastInst {
public:
/// Constructor with insert-before-instruction semantics
- FPToUIInst(
- Value *S, ///< The value to be converted
- Type *Ty, ///< The type to convert to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-before-instruction semantics
- FPToUIInst(
- Value *S, ///< The value to be converted
- Type *Ty, ///< The type to convert to
- const Twine &NameStr = "", ///< A name for the new instruction
- Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-at-end-of-block semantics
- FPToUIInst(
- Value *S, ///< The value to be converted
- Type *Ty, ///< The type to convert to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock *InsertAtEnd ///< Where to insert the new instruction
+ FPToUIInst(Value *S, ///< The value to be converted
+ Type *Ty, ///< The type to convert to
+ const Twine &NameStr = "", ///< A name for the new instruction
+ InsertPosition InsertBefore =
+ nullptr ///< Where to insert the new instruction
);
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -5784,27 +4669,11 @@ class FPToSIInst : public CastInst {
public:
/// Constructor with insert-before-instruction semantics
- FPToSIInst(
- Value *S, ///< The value to be converted
- Type *Ty, ///< The type to convert to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-before-instruction semantics
- FPToSIInst(
- Value *S, ///< The value to be converted
- Type *Ty, ///< The type to convert to
- const Twine &NameStr = "", ///< A name for the new instruction
- Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-at-end-of-block semantics
- FPToSIInst(
- Value *S, ///< The value to be converted
- Type *Ty, ///< The type to convert to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock *InsertAtEnd ///< The block to insert the instruction into
+ FPToSIInst(Value *S, ///< The value to be converted
+ Type *Ty, ///< The type to convert to
+ const Twine &NameStr = "", ///< A name for the new instruction
+ InsertPosition InsertBefore =
+ nullptr ///< Where to insert the new instruction
);
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -5827,27 +4696,11 @@ class IntToPtrInst : public CastInst {
friend class Instruction;
/// Constructor with insert-before-instruction semantics
- IntToPtrInst(
- Value *S, ///< The value to be converted
- Type *Ty, ///< The type to convert to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-before-instruction semantics
- IntToPtrInst(
- Value *S, ///< The value to be converted
- Type *Ty, ///< The type to convert to
- const Twine &NameStr = "", ///< A name for the new instruction
- Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-at-end-of-block semantics
- IntToPtrInst(
- Value *S, ///< The value to be converted
- Type *Ty, ///< The type to convert to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock *InsertAtEnd ///< The block to insert the instruction into
+ IntToPtrInst(Value *S, ///< The value to be converted
+ Type *Ty, ///< The type to convert to
+ const Twine &NameStr = "", ///< A name for the new instruction
+ InsertPosition InsertBefore =
+ nullptr ///< Where to insert the new instruction
);
/// Clone an identical IntToPtrInst.
@@ -5882,27 +4735,11 @@ class PtrToIntInst : public CastInst {
public:
/// Constructor with insert-before-instruction semantics
- PtrToIntInst(
- Value *S, ///< The value to be converted
- Type *Ty, ///< The type to convert to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-before-instruction semantics
- PtrToIntInst(
- Value *S, ///< The value to be converted
- Type *Ty, ///< The type to convert to
- const Twine &NameStr = "", ///< A name for the new instruction
- Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-at-end-of-block semantics
- PtrToIntInst(
- Value *S, ///< The value to be converted
- Type *Ty, ///< The type to convert to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock *InsertAtEnd ///< The block to insert the instruction into
+ PtrToIntInst(Value *S, ///< The value to be converted
+ Type *Ty, ///< The type to convert to
+ const Twine &NameStr = "", ///< A name for the new instruction
+ InsertPosition InsertBefore =
+ nullptr ///< Where to insert the new instruction
);
/// Gets the pointer operand.
@@ -5941,27 +4778,11 @@ class BitCastInst : public CastInst {
public:
/// Constructor with insert-before-instruction semantics
- BitCastInst(
- Value *S, ///< The value to be casted
- Type *Ty, ///< The type to casted to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-before-instruction semantics
- BitCastInst(
- Value *S, ///< The value to be casted
- Type *Ty, ///< The type to casted to
- const Twine &NameStr = "", ///< A name for the new instruction
- Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-at-end-of-block semantics
- BitCastInst(
- Value *S, ///< The value to be casted
- Type *Ty, ///< The type to casted to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock *InsertAtEnd ///< The block to insert the instruction into
+ BitCastInst(Value *S, ///< The value to be casted
+ Type *Ty, ///< The type to casted to
+ const Twine &NameStr = "", ///< A name for the new instruction
+ InsertPosition InsertBefore =
+ nullptr ///< Where to insert the new instruction
);
// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -5990,26 +4811,11 @@ class AddrSpaceCastInst : public CastInst {
public:
/// Constructor with insert-before-instruction semantics
AddrSpaceCastInst(
- Value *S, ///< The value to be casted
- Type *Ty, ///< The type to casted to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock::iterator InsertBefore ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-before-instruction semantics
- AddrSpaceCastInst(
- Value *S, ///< The value to be casted
- Type *Ty, ///< The type to casted to
- const Twine &NameStr = "", ///< A name for the new instruction
- Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
- );
-
- /// Constructor with insert-at-end-of-block semantics
- AddrSpaceCastInst(
- Value *S, ///< The value to be casted
- Type *Ty, ///< The type to casted to
- const Twine &NameStr, ///< A name for the new instruction
- BasicBlock *InsertAtEnd ///< The block to insert the instruction into
+ Value *S, ///< The value to be casted
+ Type *Ty, ///< The type to casted to
+ const Twine &NameStr = "", ///< A name for the new instruction
+ InsertPosition InsertBefore =
+ nullptr ///< Where to insert the new instruction
);
// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -6138,12 +4944,8 @@ class FreezeInst : public UnaryInstruction {
FreezeInst *cloneImpl() const;
public:
- explicit FreezeInst(Value *S, const Twine &NameStr,
- BasicBlock::iterator InsertBefore);
- explicit FreezeInst(Value *S,
- const Twine &NameStr = "",
- Instruction *InsertBefore = nullptr);
- FreezeInst(Value *S, const Twine &NameStr, BasicBlock *InsertAtEnd);
+ explicit FreezeInst(Value *S, const Twine &NameStr = "",
+ InsertPosition InsertBefore = nullptr);
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const Instruction *I) {
diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp
index 8e8131113a230..00e54f1fd0264 100644
--- a/llvm/lib/IR/Instruction.cpp
+++ b/llvm/lib/IR/Instruction.cpp
@@ -25,35 +25,23 @@
#include "llvm/IR/Type.h"
using namespace llvm;
-Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
- InstListType::iterator InsertBefore)
- : User(ty, Value::InstructionVal + it, Ops, NumOps) {
- // When called with an iterator, there must be a block to insert into.
- BasicBlock *BB = InsertBefore->getParent();
- assert(BB && "Instruction to insert before is not in a basic block!");
- insertInto(BB, InsertBefore);
-}
+InsertPosition::InsertPosition(Instruction *InsertBefore)
+ : InsertAt(InsertBefore ? InsertBefore->getIterator()
+ : InstListType::iterator()) {}
+InsertPosition::InsertPosition(BasicBlock *InsertAtEnd)
+ : InsertAt(InsertAtEnd ? InsertAtEnd->end() : InstListType::iterator()) {}
Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
- Instruction *InsertBefore)
+ InsertPosition InsertBefore)
: User(ty, Value::InstructionVal + it, Ops, NumOps) {
-
- // If requested, insert this instruction into a basic block...
- if (InsertBefore) {
- BasicBlock *BB = InsertBefore->getParent();
+ // When called with an iterator, there must be a block to insert into.
+ if (InstListType::iterator InsertIt = InsertBefore; InsertIt.isValid()) {
+ BasicBlock *BB = InsertIt.getNodeParent();
assert(BB && "Instruction to insert before is not in a basic block!");
- insertInto(BB, InsertBefore->getIterator());
+ insertInto(BB, InsertBefore);
}
}
-Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
- BasicBlock *InsertAtEnd)
- : User(ty, Value::InstructionVal + it, Ops, NumOps) {
- // If requested, append this instruction into the basic block.
- if (InsertAtEnd)
- insertInto(InsertAtEnd, InsertAtEnd->end());
-}
-
Instruction::~Instruction() {
assert(!getParent() && "Instruction still linked in the program!");
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index 1213f078d05ec..57ac9a3dbd78b 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -233,23 +233,11 @@ bool PHINode::hasConstantOrUndefValue() const {
LandingPadInst::LandingPadInst(Type *RetTy, unsigned NumReservedValues,
const Twine &NameStr,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore)
: Instruction(RetTy, Instruction::LandingPad, nullptr, 0, InsertBefore) {
init(NumReservedValues, NameStr);
}
-LandingPadInst::LandingPadInst(Type *RetTy, unsigned NumReservedValues,
- const Twine &NameStr, Instruction *InsertBefore)
- : Instruction(RetTy, Instruction::LandingPad, nullptr, 0, InsertBefore) {
- init(NumReservedValues, NameStr);
-}
-
-LandingPadInst::LandingPadInst(Type *RetTy, unsigned NumReservedValues,
- const Twine &NameStr, BasicBlock *InsertAtEnd)
- : Instruction(RetTy, Instruction::LandingPad, nullptr, 0, InsertAtEnd) {
- init(NumReservedValues, NameStr);
-}
-
LandingPadInst::LandingPadInst(const LandingPadInst &LP)
: Instruction(LP.getType(), Instruction::LandingPad, nullptr,
LP.getNumOperands()),
@@ -265,16 +253,10 @@ LandingPadInst::LandingPadInst(const LandingPadInst &LP)
LandingPadInst *LandingPadInst::Create(Type *RetTy, unsigned NumReservedClauses,
const Twine &NameStr,
- Instruction *InsertBefore) {
+ InsertPosition InsertBefore) {
return new LandingPadInst(RetTy, NumReservedClauses, NameStr, InsertBefore);
}
-LandingPadInst *LandingPadInst::Create(Type *RetTy, unsigned NumReservedClauses,
- const Twine &NameStr,
- BasicBlock *InsertAtEnd) {
- return new LandingPadInst(RetTy, NumReservedClauses, NameStr, InsertAtEnd);
-}
-
void LandingPadInst::init(unsigned NumReservedValues, const Twine &NameStr) {
ReservedSpace = NumReservedValues;
setNumHungOffUseOperands(0);
@@ -305,21 +287,7 @@ void LandingPadInst::addClause(Constant *Val) {
//===----------------------------------------------------------------------===//
CallBase *CallBase::Create(CallBase *CB, ArrayRef<OperandBundleDef> Bundles,
- BasicBlock::iterator InsertPt) {
- switch (CB->getOpcode()) {
- case Instruction::Call:
- return CallInst::Create(cast<CallInst>(CB), Bundles, InsertPt);
- case Instruction::Invoke:
- return InvokeInst::Create(cast<InvokeInst>(CB), Bundles, InsertPt);
- case Instruction::CallBr:
- return CallBrInst::Create(cast<CallBrInst>(CB), Bundles, InsertPt);
- default:
- llvm_unreachable("Unknown CallBase sub-class!");
- }
-}
-
-CallBase *CallBase::Create(CallBase *CB, ArrayRef<OperandBundleDef> Bundles,
- Instruction *InsertPt) {
+ InsertPosition InsertPt) {
switch (CB->getOpcode()) {
case Instruction::Call:
return CallInst::Create(cast<CallInst>(CB), Bundles, InsertPt);
@@ -333,7 +301,7 @@ CallBase *CallBase::Create(CallBase *CB, ArrayRef<OperandBundleDef> Bundles,
}
CallBase *CallBase::Create(CallBase *CI, OperandBundleDef OpB,
- Instruction *InsertPt) {
+ InsertPosition InsertPt) {
SmallVector<OperandBundleDef, 2> OpDefs;
for (unsigned i = 0, e = CI->getNumOperandBundles(); i < e; ++i) {
auto ChildOB = CI->getOperandBundleAt(i);
@@ -344,7 +312,6 @@ CallBase *CallBase::Create(CallBase *CI, OperandBundleDef OpB,
return CallBase::Create(CI, OpDefs, InsertPt);
}
-
Function *CallBase::getCaller() { return getParent()->getParent(); }
unsigned CallBase::getNumSubclassExtraOperandsDynamic() const {
@@ -582,19 +549,7 @@ CallBase::BundleOpInfo &CallBase::getBundleOpInfoForOperand(unsigned OpIdx) {
CallBase *CallBase::addOperandBundle(CallBase *CB, uint32_t ID,
OperandBundleDef OB,
- BasicBlock::iterator InsertPt) {
- if (CB->getOperandBundle(ID))
- return CB;
-
- SmallVector<OperandBundleDef, 1> Bundles;
- CB->getOperandBundlesAsDefs(Bundles);
- Bundles.push_back(OB);
- return Create(CB, Bundles, InsertPt);
-}
-
-CallBase *CallBase::addOperandBundle(CallBase *CB, uint32_t ID,
- OperandBundleDef OB,
- Instruction *InsertPt) {
+ InsertPosition InsertPt) {
if (CB->getOperandBundle(ID))
return CB;
@@ -605,24 +560,7 @@ CallBase *CallBase::addOperandBundle(CallBase *CB, uint32_t ID,
}
CallBase *CallBase::removeOperandBundle(CallBase *CB, uint32_t ID,
- BasicBlock::iterator InsertPt) {
- SmallVector<OperandBundleDef, 1> Bundles;
- bool CreateNew = false;
-
- for (unsigned I = 0, E = CB->getNumOperandBundles(); I != E; ++I) {
- auto Bundle = CB->getOperandBundleAt(I);
- if (Bundle.getTagID() == ID) {
- CreateNew = true;
- continue;
- }
- Bundles.emplace_back(Bundle);
- }
-
- return CreateNew ? Create(CB, Bundles, InsertPt) : CB;
-}
-
-CallBase *CallBase::removeOperandBundle(CallBase *CB, uint32_t ID,
- Instruction *InsertPt) {
+ InsertPosition InsertPt) {
SmallVector<OperandBundleDef, 1> Bundles;
bool CreateNew = false;
@@ -769,26 +707,12 @@ void CallInst::init(FunctionType *FTy, Value *Func, const Twine &NameStr) {
}
CallInst::CallInst(FunctionType *Ty, Value *Func, const Twine &Name,
- BasicBlock::iterator InsertBefore)
- : CallBase(Ty->getReturnType(), Instruction::Call,
- OperandTraits<CallBase>::op_end(this) - 1, 1, InsertBefore) {
- init(Ty, Func, Name);
-}
-
-CallInst::CallInst(FunctionType *Ty, Value *Func, const Twine &Name,
- Instruction *InsertBefore)
+ InsertPosition InsertBefore)
: CallBase(Ty->getReturnType(), Instruction::Call,
OperandTraits<CallBase>::op_end(this) - 1, 1, InsertBefore) {
init(Ty, Func, Name);
}
-CallInst::CallInst(FunctionType *Ty, Value *Func, const Twine &Name,
- BasicBlock *InsertAtEnd)
- : CallBase(Ty->getReturnType(), Instruction::Call,
- OperandTraits<CallBase>::op_end(this) - 1, 1, InsertAtEnd) {
- init(Ty, Func, Name);
-}
-
CallInst::CallInst(const CallInst &CI)
: CallBase(CI.Attrs, CI.FTy, CI.getType(), Instruction::Call,
OperandTraits<CallBase>::op_end(this) - CI.getNumOperands(),
@@ -803,21 +727,7 @@ CallInst::CallInst(const CallInst &CI)
}
CallInst *CallInst::Create(CallInst *CI, ArrayRef<OperandBundleDef> OpB,
- BasicBlock::iterator InsertPt) {
- std::vector<Value *> Args(CI->arg_begin(), CI->arg_end());
-
- auto *NewCI = CallInst::Create(CI->getFunctionType(), CI->getCalledOperand(),
- Args, OpB, CI->getName(), InsertPt);
- NewCI->setTailCallKind(CI->getTailCallKind());
- NewCI->setCallingConv(CI->getCallingConv());
- NewCI->SubclassOptionalData = CI->SubclassOptionalData;
- NewCI->setAttributes(CI->getAttributes());
- NewCI->setDebugLoc(CI->getDebugLoc());
- return NewCI;
-}
-
-CallInst *CallInst::Create(CallInst *CI, ArrayRef<OperandBundleDef> OpB,
- Instruction *InsertPt) {
+ InsertPosition InsertPt) {
std::vector<Value *> Args(CI->arg_begin(), CI->arg_end());
auto *NewCI = CallInst::Create(CI->getFunctionType(), CI->getCalledOperand(),
@@ -896,21 +806,7 @@ InvokeInst::InvokeInst(const InvokeInst &II)
}
InvokeInst *InvokeInst::Create(InvokeInst *II, ArrayRef<OperandBundleDef> OpB,
- BasicBlock::iterator InsertPt) {
- std::vector<Value *> Args(II->arg_begin(), II->arg_end());
-
- auto *NewII = InvokeInst::Create(
- II->getFunctionType(), II->getCalledOperand(), II->getNormalDest(),
- II->getUnwindDest(), Args, OpB, II->getName(), InsertPt);
- NewII->setCallingConv(II->getCallingConv());
- NewII->SubclassOptionalData = II->SubclassOptionalData;
- NewII->setAttributes(II->getAttributes());
- NewII->setDebugLoc(II->getDebugLoc());
- return NewII;
-}
-
-InvokeInst *InvokeInst::Create(InvokeInst *II, ArrayRef<OperandBundleDef> OpB,
- Instruction *InsertPt) {
+ InsertPosition InsertPt) {
std::vector<Value *> Args(II->arg_begin(), II->arg_end());
auto *NewII = InvokeInst::Create(
@@ -995,22 +891,7 @@ CallBrInst::CallBrInst(const CallBrInst &CBI)
}
CallBrInst *CallBrInst::Create(CallBrInst *CBI, ArrayRef<OperandBundleDef> OpB,
- BasicBlock::iterator InsertPt) {
- std::vector<Value *> Args(CBI->arg_begin(), CBI->arg_end());
-
- auto *NewCBI = CallBrInst::Create(
- CBI->getFunctionType(), CBI->getCalledOperand(), CBI->getDefaultDest(),
- CBI->getIndirectDests(), Args, OpB, CBI->getName(), InsertPt);
- NewCBI->setCallingConv(CBI->getCallingConv());
- NewCBI->SubclassOptionalData = CBI->SubclassOptionalData;
- NewCBI->setAttributes(CBI->getAttributes());
- NewCBI->setDebugLoc(CBI->getDebugLoc());
- NewCBI->NumIndirectDests = CBI->NumIndirectDests;
- return NewCBI;
-}
-
-CallBrInst *CallBrInst::Create(CallBrInst *CBI, ArrayRef<OperandBundleDef> OpB,
- Instruction *InsertPt) {
+ InsertPosition InsertPt) {
std::vector<Value *> Args(CBI->arg_begin(), CBI->arg_end());
auto *NewCBI = CallBrInst::Create(
@@ -1038,16 +919,7 @@ ReturnInst::ReturnInst(const ReturnInst &RI)
}
ReturnInst::ReturnInst(LLVMContext &C, Value *retVal,
- BasicBlock::iterator InsertBefore)
- : Instruction(Type::getVoidTy(C), Instruction::Ret,
- OperandTraits<ReturnInst>::op_end(this) - !!retVal, !!retVal,
- InsertBefore) {
- if (retVal)
- Op<0>() = retVal;
-}
-
-ReturnInst::ReturnInst(LLVMContext &C, Value *retVal,
- Instruction *InsertBefore)
+ InsertPosition InsertBefore)
: Instruction(Type::getVoidTy(C), Instruction::Ret,
OperandTraits<ReturnInst>::op_end(this) - !!retVal, !!retVal,
InsertBefore) {
@@ -1055,18 +927,6 @@ ReturnInst::ReturnInst(LLVMContext &C, Value *retVal,
Op<0>() = retVal;
}
-ReturnInst::ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd)
- : Instruction(Type::getVoidTy(C), Instruction::Ret,
- OperandTraits<ReturnInst>::op_end(this) - !!retVal, !!retVal,
- InsertAtEnd) {
- if (retVal)
- Op<0>() = retVal;
-}
-
-ReturnInst::ReturnInst(LLVMContext &Context, BasicBlock *InsertAtEnd)
- : Instruction(Type::getVoidTy(Context), Instruction::Ret,
- OperandTraits<ReturnInst>::op_end(this), 0, InsertAtEnd) {}
-
//===----------------------------------------------------------------------===//
// ResumeInst Implementation
//===----------------------------------------------------------------------===//
@@ -1077,24 +937,12 @@ ResumeInst::ResumeInst(const ResumeInst &RI)
Op<0>() = RI.Op<0>();
}
-ResumeInst::ResumeInst(Value *Exn, BasicBlock::iterator InsertBefore)
- : Instruction(Type::getVoidTy(Exn->getContext()), Instruction::Resume,
- OperandTraits<ResumeInst>::op_begin(this), 1, InsertBefore) {
- Op<0>() = Exn;
-}
-
-ResumeInst::ResumeInst(Value *Exn, Instruction *InsertBefore)
+ResumeInst::ResumeInst(Value *Exn, InsertPosition InsertBefore)
: Instruction(Type::getVoidTy(Exn->getContext()), Instruction::Resume,
OperandTraits<ResumeInst>::op_begin(this), 1, InsertBefore) {
Op<0>() = Exn;
}
-ResumeInst::ResumeInst(Value *Exn, BasicBlock *InsertAtEnd)
- : Instruction(Type::getVoidTy(Exn->getContext()), Instruction::Resume,
- OperandTraits<ResumeInst>::op_begin(this), 1, InsertAtEnd) {
- Op<0>() = Exn;
-}
-
//===----------------------------------------------------------------------===//
// CleanupReturnInst Implementation
//===----------------------------------------------------------------------===//
@@ -1122,16 +970,7 @@ void CleanupReturnInst::init(Value *CleanupPad, BasicBlock *UnwindBB) {
CleanupReturnInst::CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB,
unsigned Values,
- BasicBlock::iterator InsertBefore)
- : Instruction(Type::getVoidTy(CleanupPad->getContext()),
- Instruction::CleanupRet,
- OperandTraits<CleanupReturnInst>::op_end(this) - Values,
- Values, InsertBefore) {
- init(CleanupPad, UnwindBB);
-}
-
-CleanupReturnInst::CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB,
- unsigned Values, Instruction *InsertBefore)
+ InsertPosition InsertBefore)
: Instruction(Type::getVoidTy(CleanupPad->getContext()),
Instruction::CleanupRet,
OperandTraits<CleanupReturnInst>::op_end(this) - Values,
@@ -1139,15 +978,6 @@ CleanupReturnInst::CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB,
init(CleanupPad, UnwindBB);
}
-CleanupReturnInst::CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB,
- unsigned Values, BasicBlock *InsertAtEnd)
- : Instruction(Type::getVoidTy(CleanupPad->getContext()),
- Instruction::CleanupRet,
- OperandTraits<CleanupReturnInst>::op_end(this) - Values,
- Values, InsertAtEnd) {
- init(CleanupPad, UnwindBB);
-}
-
//===----------------------------------------------------------------------===//
// CatchReturnInst Implementation
//===----------------------------------------------------------------------===//
@@ -1164,29 +994,13 @@ CatchReturnInst::CatchReturnInst(const CatchReturnInst &CRI)
}
CatchReturnInst::CatchReturnInst(Value *CatchPad, BasicBlock *BB,
- BasicBlock::iterator InsertBefore)
- : Instruction(Type::getVoidTy(BB->getContext()), Instruction::CatchRet,
- OperandTraits<CatchReturnInst>::op_begin(this), 2,
- InsertBefore) {
- init(CatchPad, BB);
-}
-
-CatchReturnInst::CatchReturnInst(Value *CatchPad, BasicBlock *BB,
- Instruction *InsertBefore)
+ InsertPosition InsertBefore)
: Instruction(Type::getVoidTy(BB->getContext()), Instruction::CatchRet,
OperandTraits<CatchReturnInst>::op_begin(this), 2,
InsertBefore) {
init(CatchPad, BB);
}
-CatchReturnInst::CatchReturnInst(Value *CatchPad, BasicBlock *BB,
- BasicBlock *InsertAtEnd)
- : Instruction(Type::getVoidTy(BB->getContext()), Instruction::CatchRet,
- OperandTraits<CatchReturnInst>::op_begin(this), 2,
- InsertAtEnd) {
- init(CatchPad, BB);
-}
-
//===----------------------------------------------------------------------===//
// CatchSwitchInst Implementation
//===----------------------------------------------------------------------===//
@@ -1194,7 +1008,7 @@ CatchReturnInst::CatchReturnInst(Value *CatchPad, BasicBlock *BB,
CatchSwitchInst::CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
unsigned NumReservedValues,
const Twine &NameStr,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore)
: Instruction(ParentPad->getType(), Instruction::CatchSwitch, nullptr, 0,
InsertBefore) {
if (UnwindDest)
@@ -1203,29 +1017,6 @@ CatchSwitchInst::CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
setName(NameStr);
}
-CatchSwitchInst::CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
- unsigned NumReservedValues,
- const Twine &NameStr,
- Instruction *InsertBefore)
- : Instruction(ParentPad->getType(), Instruction::CatchSwitch, nullptr, 0,
- InsertBefore) {
- if (UnwindDest)
- ++NumReservedValues;
- init(ParentPad, UnwindDest, NumReservedValues + 1);
- setName(NameStr);
-}
-
-CatchSwitchInst::CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
- unsigned NumReservedValues,
- const Twine &NameStr, BasicBlock *InsertAtEnd)
- : Instruction(ParentPad->getType(), Instruction::CatchSwitch, nullptr, 0,
- InsertAtEnd) {
- if (UnwindDest)
- ++NumReservedValues;
- init(ParentPad, UnwindDest, NumReservedValues + 1);
- setName(NameStr);
-}
-
CatchSwitchInst::CatchSwitchInst(const CatchSwitchInst &CSI)
: Instruction(CSI.getType(), Instruction::CatchSwitch, nullptr,
CSI.getNumOperands()) {
@@ -1305,46 +1096,21 @@ FuncletPadInst::FuncletPadInst(const FuncletPadInst &FPI)
FuncletPadInst::FuncletPadInst(Instruction::FuncletPadOps Op, Value *ParentPad,
ArrayRef<Value *> Args, unsigned Values,
const Twine &NameStr,
- BasicBlock::iterator InsertBefore)
- : Instruction(ParentPad->getType(), Op,
- OperandTraits<FuncletPadInst>::op_end(this) - Values, Values,
- InsertBefore) {
- init(ParentPad, Args, NameStr);
-}
-
-FuncletPadInst::FuncletPadInst(Instruction::FuncletPadOps Op, Value *ParentPad,
- ArrayRef<Value *> Args, unsigned Values,
- const Twine &NameStr, Instruction *InsertBefore)
+ InsertPosition InsertBefore)
: Instruction(ParentPad->getType(), Op,
OperandTraits<FuncletPadInst>::op_end(this) - Values, Values,
InsertBefore) {
init(ParentPad, Args, NameStr);
}
-FuncletPadInst::FuncletPadInst(Instruction::FuncletPadOps Op, Value *ParentPad,
- ArrayRef<Value *> Args, unsigned Values,
- const Twine &NameStr, BasicBlock *InsertAtEnd)
- : Instruction(ParentPad->getType(), Op,
- OperandTraits<FuncletPadInst>::op_end(this) - Values, Values,
- InsertAtEnd) {
- init(ParentPad, Args, NameStr);
-}
-
//===----------------------------------------------------------------------===//
// UnreachableInst Implementation
//===----------------------------------------------------------------------===//
UnreachableInst::UnreachableInst(LLVMContext &Context,
- BasicBlock::iterator InsertBefore)
- : Instruction(Type::getVoidTy(Context), Instruction::Unreachable, nullptr,
- 0, InsertBefore) {}
-UnreachableInst::UnreachableInst(LLVMContext &Context,
- Instruction *InsertBefore)
+ InsertPosition InsertBefore)
: Instruction(Type::getVoidTy(Context), Instruction::Unreachable, nullptr,
0, InsertBefore) {}
-UnreachableInst::UnreachableInst(LLVMContext &Context, BasicBlock *InsertAtEnd)
- : Instruction(Type::getVoidTy(Context), Instruction::Unreachable, nullptr,
- 0, InsertAtEnd) {}
//===----------------------------------------------------------------------===//
// BranchInst Implementation
@@ -1356,15 +1122,7 @@ void BranchInst::AssertOK() {
"May only branch on boolean predicates!");
}
-BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock::iterator InsertBefore)
- : Instruction(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
- OperandTraits<BranchInst>::op_end(this) - 1, 1,
- InsertBefore) {
- assert(IfTrue && "Branch destination may not be null!");
- Op<-1>() = IfTrue;
-}
-
-BranchInst::BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore)
+BranchInst::BranchInst(BasicBlock *IfTrue, InsertPosition InsertBefore)
: Instruction(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
OperandTraits<BranchInst>::op_end(this) - 1, 1,
InsertBefore) {
@@ -1373,7 +1131,7 @@ BranchInst::BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore)
}
BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore)
: Instruction(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
OperandTraits<BranchInst>::op_end(this) - 3, 3,
InsertBefore) {
@@ -1386,40 +1144,6 @@ BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
#endif
}
-BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
- Instruction *InsertBefore)
- : Instruction(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
- OperandTraits<BranchInst>::op_end(this) - 3, 3,
- InsertBefore) {
- // Assign in order of operand index to make use-list order predictable.
- Op<-3>() = Cond;
- Op<-2>() = IfFalse;
- Op<-1>() = IfTrue;
-#ifndef NDEBUG
- AssertOK();
-#endif
-}
-
-BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd)
- : Instruction(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
- OperandTraits<BranchInst>::op_end(this) - 1, 1, InsertAtEnd) {
- assert(IfTrue && "Branch destination may not be null!");
- Op<-1>() = IfTrue;
-}
-
-BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
- BasicBlock *InsertAtEnd)
- : Instruction(Type::getVoidTy(IfTrue->getContext()), Instruction::Br,
- OperandTraits<BranchInst>::op_end(this) - 3, 3, InsertAtEnd) {
- // Assign in order of operand index to make use-list order predictable.
- Op<-3>() = Cond;
- Op<-2>() = IfFalse;
- Op<-1>() = IfTrue;
-#ifndef NDEBUG
- AssertOK();
-#endif
-}
-
BranchInst::BranchInst(const BranchInst &BI)
: Instruction(Type::getVoidTy(BI.getContext()), Instruction::Br,
OperandTraits<BranchInst>::op_end(this) - BI.getNumOperands(),
@@ -1460,67 +1184,29 @@ static Value *getAISize(LLVMContext &Context, Value *Amt) {
return Amt;
}
-static Align computeAllocaDefaultAlign(Type *Ty, BasicBlock *BB) {
- assert(BB && "Insertion BB cannot be null when alignment not provided!");
+static Align computeAllocaDefaultAlign(Type *Ty, InsertPosition Pos) {
+ assert(Pos.IsValid() &&
+ "Insertion position cannot be null when alignment not provided!");
+ BasicBlock *BB = ((BasicBlock::iterator)Pos).getNodeParent();
assert(BB->getParent() &&
"BB must be in a Function when alignment not provided!");
const DataLayout &DL = BB->getModule()->getDataLayout();
return DL.getPrefTypeAlign(Ty);
}
-static Align computeAllocaDefaultAlign(Type *Ty, BasicBlock::iterator It) {
- return computeAllocaDefaultAlign(Ty, It->getParent());
-}
-
-static Align computeAllocaDefaultAlign(Type *Ty, Instruction *I) {
- assert(I && "Insertion position cannot be null when alignment not provided!");
- return computeAllocaDefaultAlign(Ty, I->getParent());
-}
-
AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, const Twine &Name,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore)
: AllocaInst(Ty, AddrSpace, /*ArraySize=*/nullptr, Name, InsertBefore) {}
-AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, const Twine &Name,
- Instruction *InsertBefore)
- : AllocaInst(Ty, AddrSpace, /*ArraySize=*/nullptr, Name, InsertBefore) {}
-
-AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, const Twine &Name,
- BasicBlock *InsertAtEnd)
- : AllocaInst(Ty, AddrSpace, /*ArraySize=*/nullptr, Name, InsertAtEnd) {}
-
AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
- const Twine &Name, BasicBlock::iterator InsertBefore)
+ const Twine &Name, InsertPosition InsertBefore)
: AllocaInst(Ty, AddrSpace, ArraySize,
computeAllocaDefaultAlign(Ty, InsertBefore), Name,
InsertBefore) {}
-AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
- const Twine &Name, Instruction *InsertBefore)
- : AllocaInst(Ty, AddrSpace, ArraySize,
- computeAllocaDefaultAlign(Ty, InsertBefore), Name,
- InsertBefore) {}
-
-AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
- const Twine &Name, BasicBlock *InsertAtEnd)
- : AllocaInst(Ty, AddrSpace, ArraySize,
- computeAllocaDefaultAlign(Ty, InsertAtEnd), Name,
- InsertAtEnd) {}
-
-AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
- Align Align, const Twine &Name,
- BasicBlock::iterator InsertBefore)
- : UnaryInstruction(PointerType::get(Ty, AddrSpace), Alloca,
- getAISize(Ty->getContext(), ArraySize), InsertBefore),
- AllocatedType(Ty) {
- setAlignment(Align);
- assert(!Ty->isVoidTy() && "Cannot allocate void!");
- setName(Name);
-}
-
AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
Align Align, const Twine &Name,
- Instruction *InsertBefore)
+ InsertPosition InsertBefore)
: UnaryInstruction(PointerType::get(Ty, AddrSpace), Alloca,
getAISize(Ty->getContext(), ArraySize), InsertBefore),
AllocatedType(Ty) {
@@ -1529,17 +1215,6 @@ AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
setName(Name);
}
-AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
- Align Align, const Twine &Name, BasicBlock *InsertAtEnd)
- : UnaryInstruction(PointerType::get(Ty, AddrSpace), Alloca,
- getAISize(Ty->getContext(), ArraySize), InsertAtEnd),
- AllocatedType(Ty) {
- setAlignment(Align);
- assert(!Ty->isVoidTy() && "Cannot allocate void!");
- setName(Name);
-}
-
-
bool AllocaInst::isArrayAllocation() const {
if (ConstantInt *CI = dyn_cast<ConstantInt>(getOperand(0)))
return !CI->isOne();
@@ -1567,68 +1242,33 @@ void LoadInst::AssertOK() {
"Ptr must have pointer type.");
}
-static Align computeLoadStoreDefaultAlign(Type *Ty, BasicBlock *BB) {
- assert(BB && "Insertion BB cannot be null when alignment not provided!");
+static Align computeLoadStoreDefaultAlign(Type *Ty, InsertPosition Pos) {
+ assert(Pos.IsValid() &&
+ "Insertion position cannot be null when alignment not provided!");
+ BasicBlock *BB = ((BasicBlock::iterator)Pos).getNodeParent();
assert(BB->getParent() &&
"BB must be in a Function when alignment not provided!");
const DataLayout &DL = BB->getModule()->getDataLayout();
return DL.getABITypeAlign(Ty);
}
-static Align computeLoadStoreDefaultAlign(Type *Ty, BasicBlock::iterator It) {
- return computeLoadStoreDefaultAlign(Ty, It->getParent());
-}
-
-static Align computeLoadStoreDefaultAlign(Type *Ty, Instruction *I) {
- assert(I && "Insertion position cannot be null when alignment not provided!");
- return computeLoadStoreDefaultAlign(Ty, I->getParent());
-}
-
-LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name,
- BasicBlock::iterator InsertBef)
- : LoadInst(Ty, Ptr, Name, /*isVolatile=*/false, InsertBef) {}
-
LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name,
- Instruction *InsertBef)
+ InsertPosition InsertBef)
: LoadInst(Ty, Ptr, Name, /*isVolatile=*/false, InsertBef) {}
-LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name,
- BasicBlock *InsertAE)
- : LoadInst(Ty, Ptr, Name, /*isVolatile=*/false, InsertAE) {}
-
-LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
- BasicBlock::iterator InsertBef)
- : LoadInst(Ty, Ptr, Name, isVolatile,
- computeLoadStoreDefaultAlign(Ty, InsertBef), InsertBef) {}
-
LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
- Instruction *InsertBef)
+ InsertPosition InsertBef)
: LoadInst(Ty, Ptr, Name, isVolatile,
computeLoadStoreDefaultAlign(Ty, InsertBef), InsertBef) {}
LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
- BasicBlock *InsertAE)
- : LoadInst(Ty, Ptr, Name, isVolatile,
- computeLoadStoreDefaultAlign(Ty, InsertAE), InsertAE) {}
-
-LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
- Align Align, BasicBlock::iterator InsertBef)
- : LoadInst(Ty, Ptr, Name, isVolatile, Align, AtomicOrdering::NotAtomic,
- SyncScope::System, InsertBef) {}
-
-LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
- Align Align, Instruction *InsertBef)
+ Align Align, InsertPosition InsertBef)
: LoadInst(Ty, Ptr, Name, isVolatile, Align, AtomicOrdering::NotAtomic,
SyncScope::System, InsertBef) {}
-LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
- Align Align, BasicBlock *InsertAE)
- : LoadInst(Ty, Ptr, Name, isVolatile, Align, AtomicOrdering::NotAtomic,
- SyncScope::System, InsertAE) {}
-
LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
Align Align, AtomicOrdering Order, SyncScope::ID SSID,
- BasicBlock::iterator InsertBef)
+ InsertPosition InsertBef)
: UnaryInstruction(Ty, Load, Ptr, InsertBef) {
setVolatile(isVolatile);
setAlignment(Align);
@@ -1637,28 +1277,6 @@ LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
setName(Name);
}
-LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
- Align Align, AtomicOrdering Order, SyncScope::ID SSID,
- Instruction *InsertBef)
- : UnaryInstruction(Ty, Load, Ptr, InsertBef) {
- setVolatile(isVolatile);
- setAlignment(Align);
- setAtomic(Order, SSID);
- AssertOK();
- setName(Name);
-}
-
-LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,
- Align Align, AtomicOrdering Order, SyncScope::ID SSID,
- BasicBlock *InsertAE)
- : UnaryInstruction(Ty, Load, Ptr, InsertAE) {
- setVolatile(isVolatile);
- setAlignment(Align);
- setAtomic(Order, SSID);
- AssertOK();
- setName(Name);
-}
-
//===----------------------------------------------------------------------===//
// StoreInst Implementation
//===----------------------------------------------------------------------===//
@@ -1669,51 +1287,23 @@ void StoreInst::AssertOK() {
"Ptr must have pointer type!");
}
-StoreInst::StoreInst(Value *val, Value *addr, Instruction *InsertBefore)
- : StoreInst(val, addr, /*isVolatile=*/false, InsertBefore) {}
-
-StoreInst::StoreInst(Value *val, Value *addr, BasicBlock *InsertAtEnd)
- : StoreInst(val, addr, /*isVolatile=*/false, InsertAtEnd) {}
-
-StoreInst::StoreInst(Value *val, Value *addr, BasicBlock::iterator InsertBefore)
+StoreInst::StoreInst(Value *val, Value *addr, InsertPosition InsertBefore)
: StoreInst(val, addr, /*isVolatile=*/false, InsertBefore) {}
StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
- Instruction *InsertBefore)
+ InsertPosition InsertBefore)
: StoreInst(val, addr, isVolatile,
computeLoadStoreDefaultAlign(val->getType(), InsertBefore),
InsertBefore) {}
-StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
- BasicBlock *InsertAtEnd)
- : StoreInst(val, addr, isVolatile,
- computeLoadStoreDefaultAlign(val->getType(), InsertAtEnd),
- InsertAtEnd) {}
-
-StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
- BasicBlock::iterator InsertBefore)
- : StoreInst(val, addr, isVolatile,
- computeLoadStoreDefaultAlign(val->getType(), &*InsertBefore),
- InsertBefore) {}
-
-StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, Align Align,
- Instruction *InsertBefore)
- : StoreInst(val, addr, isVolatile, Align, AtomicOrdering::NotAtomic,
- SyncScope::System, InsertBefore) {}
-
-StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, Align Align,
- BasicBlock *InsertAtEnd)
- : StoreInst(val, addr, isVolatile, Align, AtomicOrdering::NotAtomic,
- SyncScope::System, InsertAtEnd) {}
-
StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, Align Align,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore)
: StoreInst(val, addr, isVolatile, Align, AtomicOrdering::NotAtomic,
SyncScope::System, InsertBefore) {}
StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, Align Align,
AtomicOrdering Order, SyncScope::ID SSID,
- Instruction *InsertBefore)
+ InsertPosition InsertBefore)
: Instruction(Type::getVoidTy(val->getContext()), Store,
OperandTraits<StoreInst>::op_begin(this),
OperandTraits<StoreInst>::operands(this), InsertBefore) {
@@ -1725,35 +1315,6 @@ StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, Align Align,
AssertOK();
}
-StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, Align Align,
- AtomicOrdering Order, SyncScope::ID SSID,
- BasicBlock *InsertAtEnd)
- : Instruction(Type::getVoidTy(val->getContext()), Store,
- OperandTraits<StoreInst>::op_begin(this),
- OperandTraits<StoreInst>::operands(this), InsertAtEnd) {
- Op<0>() = val;
- Op<1>() = addr;
- setVolatile(isVolatile);
- setAlignment(Align);
- setAtomic(Order, SSID);
- AssertOK();
-}
-
-StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, Align Align,
- AtomicOrdering Order, SyncScope::ID SSID,
- BasicBlock::iterator InsertBefore)
- : Instruction(Type::getVoidTy(val->getContext()), Store,
- OperandTraits<StoreInst>::op_begin(this),
- OperandTraits<StoreInst>::operands(this)) {
- Op<0>() = val;
- Op<1>() = addr;
- setVolatile(isVolatile);
- setAlignment(Align);
- setAtomic(Order, SSID);
- insertBefore(*InsertBefore->getParent(), InsertBefore);
- AssertOK();
-}
-
//===----------------------------------------------------------------------===//
// AtomicCmpXchgInst Implementation
//===----------------------------------------------------------------------===//
@@ -1783,20 +1344,7 @@ AtomicCmpXchgInst::AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
AtomicOrdering SuccessOrdering,
AtomicOrdering FailureOrdering,
SyncScope::ID SSID,
- BasicBlock::iterator InsertBefore)
- : Instruction(
- StructType::get(Cmp->getType(), Type::getInt1Ty(Cmp->getContext())),
- AtomicCmpXchg, OperandTraits<AtomicCmpXchgInst>::op_begin(this),
- OperandTraits<AtomicCmpXchgInst>::operands(this), InsertBefore) {
- Init(Ptr, Cmp, NewVal, Alignment, SuccessOrdering, FailureOrdering, SSID);
-}
-
-AtomicCmpXchgInst::AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
- Align Alignment,
- AtomicOrdering SuccessOrdering,
- AtomicOrdering FailureOrdering,
- SyncScope::ID SSID,
- Instruction *InsertBefore)
+ InsertPosition InsertBefore)
: Instruction(
StructType::get(Cmp->getType(), Type::getInt1Ty(Cmp->getContext())),
AtomicCmpXchg, OperandTraits<AtomicCmpXchgInst>::op_begin(this),
@@ -1804,19 +1352,6 @@ AtomicCmpXchgInst::AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
Init(Ptr, Cmp, NewVal, Alignment, SuccessOrdering, FailureOrdering, SSID);
}
-AtomicCmpXchgInst::AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
- Align Alignment,
- AtomicOrdering SuccessOrdering,
- AtomicOrdering FailureOrdering,
- SyncScope::ID SSID,
- BasicBlock *InsertAtEnd)
- : Instruction(
- StructType::get(Cmp->getType(), Type::getInt1Ty(Cmp->getContext())),
- AtomicCmpXchg, OperandTraits<AtomicCmpXchgInst>::op_begin(this),
- OperandTraits<AtomicCmpXchgInst>::operands(this), InsertAtEnd) {
- Init(Ptr, Cmp, NewVal, Alignment, SuccessOrdering, FailureOrdering, SSID);
-}
-
//===----------------------------------------------------------------------===//
// AtomicRMWInst Implementation
//===----------------------------------------------------------------------===//
@@ -1836,41 +1371,22 @@ void AtomicRMWInst::Init(BinOp Operation, Value *Ptr, Value *Val,
setAlignment(Alignment);
assert(getOperand(0) && getOperand(1) &&
- "All operands must be non-null!");
- assert(getOperand(0)->getType()->isPointerTy() &&
- "Ptr must have pointer type!");
- assert(Ordering != AtomicOrdering::NotAtomic &&
- "AtomicRMW instructions must be atomic!");
-}
-
-AtomicRMWInst::AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
- Align Alignment, AtomicOrdering Ordering,
- SyncScope::ID SSID,
- BasicBlock::iterator InsertBefore)
- : Instruction(Val->getType(), AtomicRMW,
- OperandTraits<AtomicRMWInst>::op_begin(this),
- OperandTraits<AtomicRMWInst>::operands(this), InsertBefore) {
- Init(Operation, Ptr, Val, Alignment, Ordering, SSID);
+ "All operands must be non-null!");
+ assert(getOperand(0)->getType()->isPointerTy() &&
+ "Ptr must have pointer type!");
+ assert(Ordering != AtomicOrdering::NotAtomic &&
+ "AtomicRMW instructions must be atomic!");
}
AtomicRMWInst::AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
Align Alignment, AtomicOrdering Ordering,
- SyncScope::ID SSID, Instruction *InsertBefore)
+ SyncScope::ID SSID, InsertPosition InsertBefore)
: Instruction(Val->getType(), AtomicRMW,
OperandTraits<AtomicRMWInst>::op_begin(this),
OperandTraits<AtomicRMWInst>::operands(this), InsertBefore) {
Init(Operation, Ptr, Val, Alignment, Ordering, SSID);
}
-AtomicRMWInst::AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
- Align Alignment, AtomicOrdering Ordering,
- SyncScope::ID SSID, BasicBlock *InsertAtEnd)
- : Instruction(Val->getType(), AtomicRMW,
- OperandTraits<AtomicRMWInst>::op_begin(this),
- OperandTraits<AtomicRMWInst>::operands(this), InsertAtEnd) {
- Init(Operation, Ptr, Val, Alignment, Ordering, SSID);
-}
-
StringRef AtomicRMWInst::getOperationName(BinOp Op) {
switch (Op) {
case AtomicRMWInst::Xchg:
@@ -1919,28 +1435,12 @@ StringRef AtomicRMWInst::getOperationName(BinOp Op) {
//===----------------------------------------------------------------------===//
FenceInst::FenceInst(LLVMContext &C, AtomicOrdering Ordering,
- SyncScope::ID SSID, BasicBlock::iterator InsertBefore)
+ SyncScope::ID SSID, InsertPosition InsertBefore)
: Instruction(Type::getVoidTy(C), Fence, nullptr, 0, InsertBefore) {
setOrdering(Ordering);
setSyncScopeID(SSID);
}
-FenceInst::FenceInst(LLVMContext &C, AtomicOrdering Ordering,
- SyncScope::ID SSID,
- Instruction *InsertBefore)
- : Instruction(Type::getVoidTy(C), Fence, nullptr, 0, InsertBefore) {
- setOrdering(Ordering);
- setSyncScopeID(SSID);
-}
-
-FenceInst::FenceInst(LLVMContext &C, AtomicOrdering Ordering,
- SyncScope::ID SSID,
- BasicBlock *InsertAtEnd)
- : Instruction(Type::getVoidTy(C), Fence, nullptr, 0, InsertAtEnd) {
- setOrdering(Ordering);
- setSyncScopeID(SSID);
-}
-
//===----------------------------------------------------------------------===//
// GetElementPtrInst Implementation
//===----------------------------------------------------------------------===//
@@ -2093,7 +1593,7 @@ bool GetElementPtrInst::collectOffset(
ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
const Twine &Name,
- BasicBlock::iterator InsertBef)
+ InsertPosition InsertBef)
: Instruction(
cast<VectorType>(Val->getType())->getElementType(), ExtractElement,
OperandTraits<ExtractElementInst>::op_begin(this), 2, InsertBef) {
@@ -2104,35 +1604,6 @@ ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
setName(Name);
}
-ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
- const Twine &Name,
- Instruction *InsertBef)
- : Instruction(cast<VectorType>(Val->getType())->getElementType(),
- ExtractElement,
- OperandTraits<ExtractElementInst>::op_begin(this),
- 2, InsertBef) {
- assert(isValidOperands(Val, Index) &&
- "Invalid extractelement instruction operands!");
- Op<0>() = Val;
- Op<1>() = Index;
- setName(Name);
-}
-
-ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
- const Twine &Name,
- BasicBlock *InsertAE)
- : Instruction(cast<VectorType>(Val->getType())->getElementType(),
- ExtractElement,
- OperandTraits<ExtractElementInst>::op_begin(this),
- 2, InsertAE) {
- assert(isValidOperands(Val, Index) &&
- "Invalid extractelement instruction operands!");
-
- Op<0>() = Val;
- Op<1>() = Index;
- setName(Name);
-}
-
bool ExtractElementInst::isValidOperands(const Value *Val, const Value *Index) {
if (!Val->getType()->isVectorTy() || !Index->getType()->isIntegerTy())
return false;
@@ -2145,7 +1616,7 @@ bool ExtractElementInst::isValidOperands(const Value *Val, const Value *Index) {
InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
const Twine &Name,
- BasicBlock::iterator InsertBef)
+ InsertPosition InsertBef)
: Instruction(Vec->getType(), InsertElement,
OperandTraits<InsertElementInst>::op_begin(this), 3,
InsertBef) {
@@ -2157,35 +1628,6 @@ InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
setName(Name);
}
-InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
- const Twine &Name,
- Instruction *InsertBef)
- : Instruction(Vec->getType(), InsertElement,
- OperandTraits<InsertElementInst>::op_begin(this),
- 3, InsertBef) {
- assert(isValidOperands(Vec, Elt, Index) &&
- "Invalid insertelement instruction operands!");
- Op<0>() = Vec;
- Op<1>() = Elt;
- Op<2>() = Index;
- setName(Name);
-}
-
-InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
- const Twine &Name,
- BasicBlock *InsertAE)
- : Instruction(Vec->getType(), InsertElement,
- OperandTraits<InsertElementInst>::op_begin(this),
- 3, InsertAE) {
- assert(isValidOperands(Vec, Elt, Index) &&
- "Invalid insertelement instruction operands!");
-
- Op<0>() = Vec;
- Op<1>() = Elt;
- Op<2>() = Index;
- setName(Name);
-}
-
bool InsertElementInst::isValidOperands(const Value *Vec, const Value *Elt,
const Value *Index) {
if (!Vec->getType()->isVectorTy())
@@ -2209,59 +1651,19 @@ static Value *createPlaceholderForShuffleVector(Value *V) {
}
ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *Mask, const Twine &Name,
- BasicBlock::iterator InsertBefore)
- : ShuffleVectorInst(V1, createPlaceholderForShuffleVector(V1), Mask, Name,
- InsertBefore) {}
-
-ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *Mask, const Twine &Name,
- Instruction *InsertBefore)
- : ShuffleVectorInst(V1, createPlaceholderForShuffleVector(V1), Mask, Name,
- InsertBefore) {}
-
-ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *Mask, const Twine &Name,
- BasicBlock *InsertAtEnd)
- : ShuffleVectorInst(V1, createPlaceholderForShuffleVector(V1), Mask, Name,
- InsertAtEnd) {}
-
-ShuffleVectorInst::ShuffleVectorInst(Value *V1, ArrayRef<int> Mask,
- const Twine &Name,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore)
: ShuffleVectorInst(V1, createPlaceholderForShuffleVector(V1), Mask, Name,
InsertBefore) {}
ShuffleVectorInst::ShuffleVectorInst(Value *V1, ArrayRef<int> Mask,
const Twine &Name,
- Instruction *InsertBefore)
+ InsertPosition InsertBefore)
: ShuffleVectorInst(V1, createPlaceholderForShuffleVector(V1), Mask, Name,
InsertBefore) {}
-ShuffleVectorInst::ShuffleVectorInst(Value *V1, ArrayRef<int> Mask,
- const Twine &Name, BasicBlock *InsertAtEnd)
- : ShuffleVectorInst(V1, createPlaceholderForShuffleVector(V1), Mask, Name,
- InsertAtEnd) {}
-
-ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
- const Twine &Name,
- BasicBlock::iterator InsertBefore)
- : Instruction(
- VectorType::get(cast<VectorType>(V1->getType())->getElementType(),
- cast<VectorType>(Mask->getType())->getElementCount()),
- ShuffleVector, OperandTraits<ShuffleVectorInst>::op_begin(this),
- OperandTraits<ShuffleVectorInst>::operands(this), InsertBefore) {
- assert(isValidOperands(V1, V2, Mask) &&
- "Invalid shuffle vector instruction operands!");
-
- Op<0>() = V1;
- Op<1>() = V2;
- SmallVector<int, 16> MaskArr;
- getShuffleMask(cast<Constant>(Mask), MaskArr);
- setShuffleMask(MaskArr);
- setName(Name);
-}
-
ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
const Twine &Name,
- Instruction *InsertBefore)
+ InsertPosition InsertBefore)
: Instruction(
VectorType::get(cast<VectorType>(V1->getType())->getElementType(),
cast<VectorType>(Mask->getType())->getElementCount()),
@@ -2278,43 +1680,9 @@ ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
setName(Name);
}
-ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
- const Twine &Name, BasicBlock *InsertAtEnd)
- : Instruction(
- VectorType::get(cast<VectorType>(V1->getType())->getElementType(),
- cast<VectorType>(Mask->getType())->getElementCount()),
- ShuffleVector, OperandTraits<ShuffleVectorInst>::op_begin(this),
- OperandTraits<ShuffleVectorInst>::operands(this), InsertAtEnd) {
- assert(isValidOperands(V1, V2, Mask) &&
- "Invalid shuffle vector instruction operands!");
-
- Op<0>() = V1;
- Op<1>() = V2;
- SmallVector<int, 16> MaskArr;
- getShuffleMask(cast<Constant>(Mask), MaskArr);
- setShuffleMask(MaskArr);
- setName(Name);
-}
-
-ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, ArrayRef<int> Mask,
- const Twine &Name,
- BasicBlock::iterator InsertBefore)
- : Instruction(
- VectorType::get(cast<VectorType>(V1->getType())->getElementType(),
- Mask.size(), isa<ScalableVectorType>(V1->getType())),
- ShuffleVector, OperandTraits<ShuffleVectorInst>::op_begin(this),
- OperandTraits<ShuffleVectorInst>::operands(this), InsertBefore) {
- assert(isValidOperands(V1, V2, Mask) &&
- "Invalid shuffle vector instruction operands!");
- Op<0>() = V1;
- Op<1>() = V2;
- setShuffleMask(Mask);
- setName(Name);
-}
-
ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, ArrayRef<int> Mask,
const Twine &Name,
- Instruction *InsertBefore)
+ InsertPosition InsertBefore)
: Instruction(
VectorType::get(cast<VectorType>(V1->getType())->getElementType(),
Mask.size(), isa<ScalableVectorType>(V1->getType())),
@@ -2328,22 +1696,6 @@ ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, ArrayRef<int> Mask,
setName(Name);
}
-ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, ArrayRef<int> Mask,
- const Twine &Name, BasicBlock *InsertAtEnd)
- : Instruction(
- VectorType::get(cast<VectorType>(V1->getType())->getElementType(),
- Mask.size(), isa<ScalableVectorType>(V1->getType())),
- ShuffleVector, OperandTraits<ShuffleVectorInst>::op_begin(this),
- OperandTraits<ShuffleVectorInst>::operands(this), InsertAtEnd) {
- assert(isValidOperands(V1, V2, Mask) &&
- "Invalid shuffle vector instruction operands!");
-
- Op<0>() = V1;
- Op<1>() = V2;
- setShuffleMask(Mask);
- setName(Name);
-}
-
void ShuffleVectorInst::commute() {
int NumOpElts = cast<FixedVectorType>(Op<0>()->getType())->getNumElements();
int NumMaskElts = ShuffleMask.size();
@@ -3165,51 +2517,18 @@ Type *ExtractValueInst::getIndexedType(Type *Agg,
//===----------------------------------------------------------------------===//
UnaryOperator::UnaryOperator(UnaryOps iType, Value *S, Type *Ty,
- const Twine &Name,
- BasicBlock::iterator InsertBefore)
+ const Twine &Name, InsertPosition InsertBefore)
: UnaryInstruction(Ty, iType, S, InsertBefore) {
Op<0>() = S;
setName(Name);
AssertOK();
}
-UnaryOperator::UnaryOperator(UnaryOps iType, Value *S,
- Type *Ty, const Twine &Name,
- Instruction *InsertBefore)
- : UnaryInstruction(Ty, iType, S, InsertBefore) {
- Op<0>() = S;
- setName(Name);
- AssertOK();
-}
-
-UnaryOperator::UnaryOperator(UnaryOps iType, Value *S,
- Type *Ty, const Twine &Name,
- BasicBlock *InsertAtEnd)
- : UnaryInstruction(Ty, iType, S, InsertAtEnd) {
- Op<0>() = S;
- setName(Name);
- AssertOK();
-}
-
UnaryOperator *UnaryOperator::Create(UnaryOps Op, Value *S, const Twine &Name,
- BasicBlock::iterator InsertBefore) {
- return new UnaryOperator(Op, S, S->getType(), Name, InsertBefore);
-}
-
-UnaryOperator *UnaryOperator::Create(UnaryOps Op, Value *S,
- const Twine &Name,
- Instruction *InsertBefore) {
+ InsertPosition InsertBefore) {
return new UnaryOperator(Op, S, S->getType(), Name, InsertBefore);
}
-UnaryOperator *UnaryOperator::Create(UnaryOps Op, Value *S,
- const Twine &Name,
- BasicBlock *InsertAtEnd) {
- UnaryOperator *Res = Create(Op, S, Name);
- Res->insertInto(InsertAtEnd, InsertAtEnd->end());
- return Res;
-}
-
void UnaryOperator::AssertOK() {
Value *LHS = getOperand(0);
(void)LHS; // Silence warnings.
@@ -3232,8 +2551,7 @@ void UnaryOperator::AssertOK() {
//===----------------------------------------------------------------------===//
BinaryOperator::BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty,
- const Twine &Name,
- BasicBlock::iterator InsertBefore)
+ const Twine &Name, InsertPosition InsertBefore)
: Instruction(Ty, iType, OperandTraits<BinaryOperator>::op_begin(this),
OperandTraits<BinaryOperator>::operands(this), InsertBefore) {
Op<0>() = S1;
@@ -3242,32 +2560,6 @@ BinaryOperator::BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty,
AssertOK();
}
-BinaryOperator::BinaryOperator(BinaryOps iType, Value *S1, Value *S2,
- Type *Ty, const Twine &Name,
- Instruction *InsertBefore)
- : Instruction(Ty, iType,
- OperandTraits<BinaryOperator>::op_begin(this),
- OperandTraits<BinaryOperator>::operands(this),
- InsertBefore) {
- Op<0>() = S1;
- Op<1>() = S2;
- setName(Name);
- AssertOK();
-}
-
-BinaryOperator::BinaryOperator(BinaryOps iType, Value *S1, Value *S2,
- Type *Ty, const Twine &Name,
- BasicBlock *InsertAtEnd)
- : Instruction(Ty, iType,
- OperandTraits<BinaryOperator>::op_begin(this),
- OperandTraits<BinaryOperator>::operands(this),
- InsertAtEnd) {
- Op<0>() = S1;
- Op<1>() = S2;
- setName(Name);
- AssertOK();
-}
-
void BinaryOperator::AssertOK() {
Value *LHS = getOperand(0), *RHS = getOperand(1);
(void)LHS; (void)RHS; // Silence warnings.
@@ -3338,76 +2630,32 @@ void BinaryOperator::AssertOK() {
BinaryOperator *BinaryOperator::Create(BinaryOps Op, Value *S1, Value *S2,
const Twine &Name,
- BasicBlock::iterator InsertBefore) {
- assert(S1->getType() == S2->getType() &&
- "Cannot create binary operator with two operands of differing type!");
- return new BinaryOperator(Op, S1, S2, S1->getType(), Name, InsertBefore);
-}
-
-BinaryOperator *BinaryOperator::Create(BinaryOps Op, Value *S1, Value *S2,
- const Twine &Name,
- Instruction *InsertBefore) {
+ InsertPosition InsertBefore) {
assert(S1->getType() == S2->getType() &&
"Cannot create binary operator with two operands of differing type!");
return new BinaryOperator(Op, S1, S2, S1->getType(), Name, InsertBefore);
}
-BinaryOperator *BinaryOperator::Create(BinaryOps Op, Value *S1, Value *S2,
- const Twine &Name,
- BasicBlock *InsertAtEnd) {
- BinaryOperator *Res = Create(Op, S1, S2, Name);
- Res->insertInto(InsertAtEnd, InsertAtEnd->end());
- return Res;
-}
-
BinaryOperator *BinaryOperator::CreateNeg(Value *Op, const Twine &Name,
- BasicBlock::iterator InsertBefore) {
+ InsertPosition InsertBefore) {
Value *Zero = ConstantInt::get(Op->getType(), 0);
return new BinaryOperator(Instruction::Sub, Zero, Op, Op->getType(), Name,
InsertBefore);
}
-BinaryOperator *BinaryOperator::CreateNeg(Value *Op, const Twine &Name,
- BasicBlock *InsertAtEnd) {
- Value *Zero = ConstantInt::get(Op->getType(), 0);
- return new BinaryOperator(Instruction::Sub,
- Zero, Op,
- Op->getType(), Name, InsertAtEnd);
-}
-
BinaryOperator *BinaryOperator::CreateNSWNeg(Value *Op, const Twine &Name,
- Instruction *InsertBefore) {
+ InsertPosition InsertBefore) {
Value *Zero = ConstantInt::get(Op->getType(), 0);
return BinaryOperator::CreateNSWSub(Zero, Op, Name, InsertBefore);
}
-BinaryOperator *BinaryOperator::CreateNSWNeg(Value *Op, const Twine &Name,
- BasicBlock *InsertAtEnd) {
- Value *Zero = ConstantInt::get(Op->getType(), 0);
- return BinaryOperator::CreateNSWSub(Zero, Op, Name, InsertAtEnd);
-}
-
-BinaryOperator *BinaryOperator::CreateNot(Value *Op, const Twine &Name,
- BasicBlock::iterator InsertBefore) {
- Constant *C = Constant::getAllOnesValue(Op->getType());
- return new BinaryOperator(Instruction::Xor, Op, C,
- Op->getType(), Name, InsertBefore);
-}
-
BinaryOperator *BinaryOperator::CreateNot(Value *Op, const Twine &Name,
- Instruction *InsertBefore) {
+ InsertPosition InsertBefore) {
Constant *C = Constant::getAllOnesValue(Op->getType());
return new BinaryOperator(Instruction::Xor, Op, C,
Op->getType(), Name, InsertBefore);
}
-BinaryOperator *BinaryOperator::CreateNot(Value *Op, const Twine &Name,
- BasicBlock *InsertAtEnd) {
- Constant *AllOnes = Constant::getAllOnesValue(Op->getType());
- return new BinaryOperator(Instruction::Xor, Op, AllOnes,
- Op->getType(), Name, InsertAtEnd);
-}
-
// Exchange the two operands to this instruction. This instruction is safe to
// use on any binary instruction and does not modify the semantics of the
// instruction. If the instruction is order-dependent (SetLT f.e.), the opcode
@@ -3714,30 +2962,7 @@ unsigned CastInst::isEliminableCastPair(
}
CastInst *CastInst::Create(Instruction::CastOps op, Value *S, Type *Ty,
- const Twine &Name,
- BasicBlock::iterator InsertBefore) {
- assert(castIsValid(op, S, Ty) && "Invalid cast!");
- // Construct and return the appropriate CastInst subclass
- switch (op) {
- case Trunc: return new TruncInst (S, Ty, Name, InsertBefore);
- case ZExt: return new ZExtInst (S, Ty, Name, InsertBefore);
- case SExt: return new SExtInst (S, Ty, Name, InsertBefore);
- case FPTrunc: return new FPTruncInst (S, Ty, Name, InsertBefore);
- case FPExt: return new FPExtInst (S, Ty, Name, InsertBefore);
- case UIToFP: return new UIToFPInst (S, Ty, Name, InsertBefore);
- case SIToFP: return new SIToFPInst (S, Ty, Name, InsertBefore);
- case FPToUI: return new FPToUIInst (S, Ty, Name, InsertBefore);
- case FPToSI: return new FPToSIInst (S, Ty, Name, InsertBefore);
- case PtrToInt: return new PtrToIntInst (S, Ty, Name, InsertBefore);
- case IntToPtr: return new IntToPtrInst (S, Ty, Name, InsertBefore);
- case BitCast: return new BitCastInst (S, Ty, Name, InsertBefore);
- case AddrSpaceCast: return new AddrSpaceCastInst (S, Ty, Name, InsertBefore);
- default: llvm_unreachable("Invalid opcode provided");
- }
-}
-
-CastInst *CastInst::Create(Instruction::CastOps op, Value *S, Type *Ty,
- const Twine &Name, Instruction *InsertBefore) {
+ const Twine &Name, InsertPosition InsertBefore) {
assert(castIsValid(op, S, Ty) && "Invalid cast!");
// Construct and return the appropriate CastInst subclass
switch (op) {
@@ -3752,142 +2977,38 @@ CastInst *CastInst::Create(Instruction::CastOps op, Value *S, Type *Ty,
case FPToSI: return new FPToSIInst (S, Ty, Name, InsertBefore);
case PtrToInt: return new PtrToIntInst (S, Ty, Name, InsertBefore);
case IntToPtr: return new IntToPtrInst (S, Ty, Name, InsertBefore);
- case BitCast: return new BitCastInst (S, Ty, Name, InsertBefore);
- case AddrSpaceCast: return new AddrSpaceCastInst (S, Ty, Name, InsertBefore);
- default: llvm_unreachable("Invalid opcode provided");
- }
-}
-
-CastInst *CastInst::Create(Instruction::CastOps op, Value *S, Type *Ty,
- const Twine &Name, BasicBlock *InsertAtEnd) {
- assert(castIsValid(op, S, Ty) && "Invalid cast!");
- // Construct and return the appropriate CastInst subclass
- switch (op) {
- case Trunc: return new TruncInst (S, Ty, Name, InsertAtEnd);
- case ZExt: return new ZExtInst (S, Ty, Name, InsertAtEnd);
- case SExt: return new SExtInst (S, Ty, Name, InsertAtEnd);
- case FPTrunc: return new FPTruncInst (S, Ty, Name, InsertAtEnd);
- case FPExt: return new FPExtInst (S, Ty, Name, InsertAtEnd);
- case UIToFP: return new UIToFPInst (S, Ty, Name, InsertAtEnd);
- case SIToFP: return new SIToFPInst (S, Ty, Name, InsertAtEnd);
- case FPToUI: return new FPToUIInst (S, Ty, Name, InsertAtEnd);
- case FPToSI: return new FPToSIInst (S, Ty, Name, InsertAtEnd);
- case PtrToInt: return new PtrToIntInst (S, Ty, Name, InsertAtEnd);
- case IntToPtr: return new IntToPtrInst (S, Ty, Name, InsertAtEnd);
- case BitCast: return new BitCastInst (S, Ty, Name, InsertAtEnd);
- case AddrSpaceCast: return new AddrSpaceCastInst (S, Ty, Name, InsertAtEnd);
- default: llvm_unreachable("Invalid opcode provided");
- }
-}
-
-CastInst *CastInst::CreateZExtOrBitCast(Value *S, Type *Ty, const Twine &Name,
- BasicBlock::iterator InsertBefore) {
- if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
- return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
- return Create(Instruction::ZExt, S, Ty, Name, InsertBefore);
-}
-
-CastInst *CastInst::CreateZExtOrBitCast(Value *S, Type *Ty,
- const Twine &Name,
- Instruction *InsertBefore) {
- if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
- return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
- return Create(Instruction::ZExt, S, Ty, Name, InsertBefore);
-}
-
-CastInst *CastInst::CreateZExtOrBitCast(Value *S, Type *Ty,
- const Twine &Name,
- BasicBlock *InsertAtEnd) {
- if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
- return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
- return Create(Instruction::ZExt, S, Ty, Name, InsertAtEnd);
-}
-
-CastInst *CastInst::CreateSExtOrBitCast(Value *S, Type *Ty, const Twine &Name,
- BasicBlock::iterator InsertBefore) {
- if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
- return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
- return Create(Instruction::SExt, S, Ty, Name, InsertBefore);
-}
-
-CastInst *CastInst::CreateSExtOrBitCast(Value *S, Type *Ty,
- const Twine &Name,
- Instruction *InsertBefore) {
- if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
- return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
- return Create(Instruction::SExt, S, Ty, Name, InsertBefore);
+ case BitCast: return new BitCastInst (S, Ty, Name, InsertBefore);
+ case AddrSpaceCast:
+ return new AddrSpaceCastInst(S, Ty, Name, InsertBefore);
+ default:
+ llvm_unreachable("Invalid opcode provided");
+ }
}
-CastInst *CastInst::CreateSExtOrBitCast(Value *S, Type *Ty,
- const Twine &Name,
- BasicBlock *InsertAtEnd) {
+CastInst *CastInst::CreateZExtOrBitCast(Value *S, Type *Ty, const Twine &Name,
+ InsertPosition InsertBefore) {
if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
- return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
- return Create(Instruction::SExt, S, Ty, Name, InsertAtEnd);
+ return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
+ return Create(Instruction::ZExt, S, Ty, Name, InsertBefore);
}
-CastInst *CastInst::CreateTruncOrBitCast(Value *S, Type *Ty, const Twine &Name,
- BasicBlock::iterator InsertBefore) {
+CastInst *CastInst::CreateSExtOrBitCast(Value *S, Type *Ty, const Twine &Name,
+ InsertPosition InsertBefore) {
if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
- return Create(Instruction::Trunc, S, Ty, Name, InsertBefore);
+ return Create(Instruction::SExt, S, Ty, Name, InsertBefore);
}
-CastInst *CastInst::CreateTruncOrBitCast(Value *S, Type *Ty,
- const Twine &Name,
- Instruction *InsertBefore) {
+CastInst *CastInst::CreateTruncOrBitCast(Value *S, Type *Ty, const Twine &Name,
+ InsertPosition InsertBefore) {
if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
return Create(Instruction::Trunc, S, Ty, Name, InsertBefore);
}
-CastInst *CastInst::CreateTruncOrBitCast(Value *S, Type *Ty,
- const Twine &Name,
- BasicBlock *InsertAtEnd) {
- if (S->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
- return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
- return Create(Instruction::Trunc, S, Ty, Name, InsertAtEnd);
-}
-
-CastInst *CastInst::CreatePointerCast(Value *S, Type *Ty,
- const Twine &Name,
- BasicBlock *InsertAtEnd) {
- assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
- assert((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) &&
- "Invalid cast");
- assert(Ty->isVectorTy() == S->getType()->isVectorTy() && "Invalid cast");
- assert((!Ty->isVectorTy() ||
- cast<VectorType>(Ty)->getElementCount() ==
- cast<VectorType>(S->getType())->getElementCount()) &&
- "Invalid cast");
-
- if (Ty->isIntOrIntVectorTy())
- return Create(Instruction::PtrToInt, S, Ty, Name, InsertAtEnd);
-
- return CreatePointerBitCastOrAddrSpaceCast(S, Ty, Name, InsertAtEnd);
-}
-
-/// Create a BitCast or a PtrToInt cast instruction
-CastInst *CastInst::CreatePointerCast(Value *S, Type *Ty, const Twine &Name,
- BasicBlock::iterator InsertBefore) {
- assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
- assert((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) &&
- "Invalid cast");
- assert(Ty->isVectorTy() == S->getType()->isVectorTy() && "Invalid cast");
- assert((!Ty->isVectorTy() ||
- cast<VectorType>(Ty)->getElementCount() ==
- cast<VectorType>(S->getType())->getElementCount()) &&
- "Invalid cast");
-
- if (Ty->isIntOrIntVectorTy())
- return Create(Instruction::PtrToInt, S, Ty, Name, InsertBefore);
-
- return CreatePointerBitCastOrAddrSpaceCast(S, Ty, Name, InsertBefore);
-}
-
/// Create a BitCast or a PtrToInt cast instruction
CastInst *CastInst::CreatePointerCast(Value *S, Type *Ty, const Twine &Name,
- Instruction *InsertBefore) {
+ InsertPosition InsertBefore) {
assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
assert((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) &&
"Invalid cast");
@@ -3904,31 +3025,7 @@ CastInst *CastInst::CreatePointerCast(Value *S, Type *Ty, const Twine &Name,
}
CastInst *CastInst::CreatePointerBitCastOrAddrSpaceCast(
- Value *S, Type *Ty,
- const Twine &Name,
- BasicBlock *InsertAtEnd) {
- assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
- assert(Ty->isPtrOrPtrVectorTy() && "Invalid cast");
-
- if (S->getType()->getPointerAddressSpace() != Ty->getPointerAddressSpace())
- return Create(Instruction::AddrSpaceCast, S, Ty, Name, InsertAtEnd);
-
- return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
-}
-
-CastInst *CastInst::CreatePointerBitCastOrAddrSpaceCast(
- Value *S, Type *Ty, const Twine &Name, BasicBlock::iterator InsertBefore) {
- assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
- assert(Ty->isPtrOrPtrVectorTy() && "Invalid cast");
-
- if (S->getType()->getPointerAddressSpace() != Ty->getPointerAddressSpace())
- return Create(Instruction::AddrSpaceCast, S, Ty, Name, InsertBefore);
-
- return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
-}
-
-CastInst *CastInst::CreatePointerBitCastOrAddrSpaceCast(
- Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore) {
+ Value *S, Type *Ty, const Twine &Name, InsertPosition InsertBefore) {
assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
assert(Ty->isPtrOrPtrVectorTy() && "Invalid cast");
@@ -3940,18 +3037,7 @@ CastInst *CastInst::CreatePointerBitCastOrAddrSpaceCast(
CastInst *CastInst::CreateBitOrPointerCast(Value *S, Type *Ty,
const Twine &Name,
- BasicBlock::iterator InsertBefore) {
- if (S->getType()->isPointerTy() && Ty->isIntegerTy())
- return Create(Instruction::PtrToInt, S, Ty, Name, InsertBefore);
- if (S->getType()->isIntegerTy() && Ty->isPointerTy())
- return Create(Instruction::IntToPtr, S, Ty, Name, InsertBefore);
-
- return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
-}
-
-CastInst *CastInst::CreateBitOrPointerCast(Value *S, Type *Ty,
- const Twine &Name,
- Instruction *InsertBefore) {
+ InsertPosition InsertBefore) {
if (S->getType()->isPointerTy() && Ty->isIntegerTy())
return Create(Instruction::PtrToInt, S, Ty, Name, InsertBefore);
if (S->getType()->isIntegerTy() && Ty->isPointerTy())
@@ -3962,21 +3048,7 @@ CastInst *CastInst::CreateBitOrPointerCast(Value *S, Type *Ty,
CastInst *CastInst::CreateIntegerCast(Value *C, Type *Ty, bool isSigned,
const Twine &Name,
- BasicBlock::iterator InsertBefore) {
- assert(C->getType()->isIntOrIntVectorTy() && Ty->isIntOrIntVectorTy() &&
- "Invalid integer cast");
- unsigned SrcBits = C->getType()->getScalarSizeInBits();
- unsigned DstBits = Ty->getScalarSizeInBits();
- Instruction::CastOps opcode =
- (SrcBits == DstBits ? Instruction::BitCast :
- (SrcBits > DstBits ? Instruction::Trunc :
- (isSigned ? Instruction::SExt : Instruction::ZExt)));
- return Create(opcode, C, Ty, Name, InsertBefore);
-}
-
-CastInst *CastInst::CreateIntegerCast(Value *C, Type *Ty,
- bool isSigned, const Twine &Name,
- Instruction *InsertBefore) {
+ InsertPosition InsertBefore) {
assert(C->getType()->isIntOrIntVectorTy() && Ty->isIntOrIntVectorTy() &&
"Invalid integer cast");
unsigned SrcBits = C->getType()->getScalarSizeInBits();
@@ -3988,35 +3060,8 @@ CastInst *CastInst::CreateIntegerCast(Value *C, Type *Ty,
return Create(opcode, C, Ty, Name, InsertBefore);
}
-CastInst *CastInst::CreateIntegerCast(Value *C, Type *Ty,
- bool isSigned, const Twine &Name,
- BasicBlock *InsertAtEnd) {
- assert(C->getType()->isIntOrIntVectorTy() && Ty->isIntOrIntVectorTy() &&
- "Invalid cast");
- unsigned SrcBits = C->getType()->getScalarSizeInBits();
- unsigned DstBits = Ty->getScalarSizeInBits();
- Instruction::CastOps opcode =
- (SrcBits == DstBits ? Instruction::BitCast :
- (SrcBits > DstBits ? Instruction::Trunc :
- (isSigned ? Instruction::SExt : Instruction::ZExt)));
- return Create(opcode, C, Ty, Name, InsertAtEnd);
-}
-
CastInst *CastInst::CreateFPCast(Value *C, Type *Ty, const Twine &Name,
- BasicBlock::iterator InsertBefore) {
- assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
- "Invalid cast");
- unsigned SrcBits = C->getType()->getScalarSizeInBits();
- unsigned DstBits = Ty->getScalarSizeInBits();
- Instruction::CastOps opcode =
- (SrcBits == DstBits ? Instruction::BitCast :
- (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt));
- return Create(opcode, C, Ty, Name, InsertBefore);
-}
-
-CastInst *CastInst::CreateFPCast(Value *C, Type *Ty,
- const Twine &Name,
- Instruction *InsertBefore) {
+ InsertPosition InsertBefore) {
assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
"Invalid cast");
unsigned SrcBits = C->getType()->getScalarSizeInBits();
@@ -4028,19 +3073,6 @@ CastInst *CastInst::CreateFPCast(Value *C, Type *Ty,
return Create(opcode, C, Ty, Name, InsertBefore);
}
-CastInst *CastInst::CreateFPCast(Value *C, Type *Ty,
- const Twine &Name,
- BasicBlock *InsertAtEnd) {
- assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
- "Invalid cast");
- unsigned SrcBits = C->getType()->getScalarSizeInBits();
- unsigned DstBits = Ty->getScalarSizeInBits();
- Instruction::CastOps opcode =
- (SrcBits == DstBits ? Instruction::BitCast :
- (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt));
- return Create(opcode, C, Ty, Name, InsertAtEnd);
-}
-
bool CastInst::isBitCastable(Type *SrcTy, Type *DestTy) {
if (!SrcTy->isFirstClassType() || !DestTy->isFirstClassType())
return false;
@@ -4306,246 +3338,90 @@ CastInst::castIsValid(Instruction::CastOps op, Type *SrcTy, Type *DstTy) {
}
TruncInst::TruncInst(Value *S, Type *Ty, const Twine &Name,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore)
: CastInst(Ty, Trunc, S, Name, InsertBefore) {
assert(castIsValid(getOpcode(), S, Ty) && "Illegal Trunc");
}
-TruncInst::TruncInst(
- Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
-) : CastInst(Ty, Trunc, S, Name, InsertBefore) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal Trunc");
-}
-
-TruncInst::TruncInst(
- Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
-) : CastInst(Ty, Trunc, S, Name, InsertAtEnd) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal Trunc");
-}
-
ZExtInst::ZExtInst(Value *S, Type *Ty, const Twine &Name,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore)
: CastInst(Ty, ZExt, S, Name, InsertBefore) {
assert(castIsValid(getOpcode(), S, Ty) && "Illegal ZExt");
}
-ZExtInst::ZExtInst(
- Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
-) : CastInst(Ty, ZExt, S, Name, InsertBefore) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal ZExt");
-}
-
-ZExtInst::ZExtInst(
- Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
-) : CastInst(Ty, ZExt, S, Name, InsertAtEnd) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal ZExt");
-}
-
SExtInst::SExtInst(Value *S, Type *Ty, const Twine &Name,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore)
: CastInst(Ty, SExt, S, Name, InsertBefore) {
assert(castIsValid(getOpcode(), S, Ty) && "Illegal SExt");
}
-SExtInst::SExtInst(
- Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
-) : CastInst(Ty, SExt, S, Name, InsertBefore) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal SExt");
-}
-
-SExtInst::SExtInst(
- Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
-) : CastInst(Ty, SExt, S, Name, InsertAtEnd) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal SExt");
-}
-
FPTruncInst::FPTruncInst(Value *S, Type *Ty, const Twine &Name,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore)
: CastInst(Ty, FPTrunc, S, Name, InsertBefore) {
assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPTrunc");
}
-FPTruncInst::FPTruncInst(
- Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
-) : CastInst(Ty, FPTrunc, S, Name, InsertBefore) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPTrunc");
-}
-
-FPTruncInst::FPTruncInst(
- Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
-) : CastInst(Ty, FPTrunc, S, Name, InsertAtEnd) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPTrunc");
-}
-
FPExtInst::FPExtInst(Value *S, Type *Ty, const Twine &Name,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore)
: CastInst(Ty, FPExt, S, Name, InsertBefore) {
assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPExt");
}
-FPExtInst::FPExtInst(
- Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
-) : CastInst(Ty, FPExt, S, Name, InsertBefore) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPExt");
-}
-
-FPExtInst::FPExtInst(
- Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
-) : CastInst(Ty, FPExt, S, Name, InsertAtEnd) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPExt");
-}
-
UIToFPInst::UIToFPInst(Value *S, Type *Ty, const Twine &Name,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore)
: CastInst(Ty, UIToFP, S, Name, InsertBefore) {
assert(castIsValid(getOpcode(), S, Ty) && "Illegal UIToFP");
}
-UIToFPInst::UIToFPInst(
- Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
-) : CastInst(Ty, UIToFP, S, Name, InsertBefore) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal UIToFP");
-}
-
-UIToFPInst::UIToFPInst(
- Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
-) : CastInst(Ty, UIToFP, S, Name, InsertAtEnd) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal UIToFP");
-}
-
SIToFPInst::SIToFPInst(Value *S, Type *Ty, const Twine &Name,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore)
: CastInst(Ty, SIToFP, S, Name, InsertBefore) {
assert(castIsValid(getOpcode(), S, Ty) && "Illegal SIToFP");
}
-SIToFPInst::SIToFPInst(
- Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
-) : CastInst(Ty, SIToFP, S, Name, InsertBefore) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal SIToFP");
-}
-
-SIToFPInst::SIToFPInst(
- Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
-) : CastInst(Ty, SIToFP, S, Name, InsertAtEnd) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal SIToFP");
-}
-
FPToUIInst::FPToUIInst(Value *S, Type *Ty, const Twine &Name,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore)
: CastInst(Ty, FPToUI, S, Name, InsertBefore) {
assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPToUI");
}
-FPToUIInst::FPToUIInst(
- Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
-) : CastInst(Ty, FPToUI, S, Name, InsertBefore) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPToUI");
-}
-
-FPToUIInst::FPToUIInst(
- Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
-) : CastInst(Ty, FPToUI, S, Name, InsertAtEnd) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPToUI");
-}
-
FPToSIInst::FPToSIInst(Value *S, Type *Ty, const Twine &Name,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore)
: CastInst(Ty, FPToSI, S, Name, InsertBefore) {
assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPToSI");
}
-FPToSIInst::FPToSIInst(
- Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
-) : CastInst(Ty, FPToSI, S, Name, InsertBefore) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPToSI");
-}
-
-FPToSIInst::FPToSIInst(
- Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
-) : CastInst(Ty, FPToSI, S, Name, InsertAtEnd) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal FPToSI");
-}
-
PtrToIntInst::PtrToIntInst(Value *S, Type *Ty, const Twine &Name,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore)
: CastInst(Ty, PtrToInt, S, Name, InsertBefore) {
assert(castIsValid(getOpcode(), S, Ty) && "Illegal PtrToInt");
}
-PtrToIntInst::PtrToIntInst(
- Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
-) : CastInst(Ty, PtrToInt, S, Name, InsertBefore) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal PtrToInt");
-}
-
-PtrToIntInst::PtrToIntInst(
- Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
-) : CastInst(Ty, PtrToInt, S, Name, InsertAtEnd) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal PtrToInt");
-}
-
IntToPtrInst::IntToPtrInst(Value *S, Type *Ty, const Twine &Name,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore)
: CastInst(Ty, IntToPtr, S, Name, InsertBefore) {
assert(castIsValid(getOpcode(), S, Ty) && "Illegal IntToPtr");
}
-IntToPtrInst::IntToPtrInst(
- Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
-) : CastInst(Ty, IntToPtr, S, Name, InsertBefore) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal IntToPtr");
-}
-
-IntToPtrInst::IntToPtrInst(
- Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
-) : CastInst(Ty, IntToPtr, S, Name, InsertAtEnd) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal IntToPtr");
-}
-
BitCastInst::BitCastInst(Value *S, Type *Ty, const Twine &Name,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore)
: CastInst(Ty, BitCast, S, Name, InsertBefore) {
assert(castIsValid(getOpcode(), S, Ty) && "Illegal BitCast");
}
-BitCastInst::BitCastInst(
- Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
-) : CastInst(Ty, BitCast, S, Name, InsertBefore) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal BitCast");
-}
-
-BitCastInst::BitCastInst(
- Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
-) : CastInst(Ty, BitCast, S, Name, InsertAtEnd) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal BitCast");
-}
-
AddrSpaceCastInst::AddrSpaceCastInst(Value *S, Type *Ty, const Twine &Name,
- BasicBlock::iterator InsertBefore)
+ InsertPosition InsertBefore)
: CastInst(Ty, AddrSpaceCast, S, Name, InsertBefore) {
assert(castIsValid(getOpcode(), S, Ty) && "Illegal AddrSpaceCast");
}
-AddrSpaceCastInst::AddrSpaceCastInst(
- Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
-) : CastInst(Ty, AddrSpaceCast, S, Name, InsertBefore) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal AddrSpaceCast");
-}
-
-AddrSpaceCastInst::AddrSpaceCastInst(
- Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
-) : CastInst(Ty, AddrSpaceCast, S, Name, InsertAtEnd) {
- assert(castIsValid(getOpcode(), S, Ty) && "Illegal AddrSpaceCast");
-}
-
//===----------------------------------------------------------------------===//
// CmpInst Classes
//===----------------------------------------------------------------------===//
CmpInst::CmpInst(Type *ty, OtherOps op, Predicate predicate, Value *LHS,
- Value *RHS, const Twine &Name,
- BasicBlock::iterator InsertBefore, Instruction *FlagsSource)
+ Value *RHS, const Twine &Name, InsertPosition InsertBefore,
+ Instruction *FlagsSource)
: Instruction(ty, op, OperandTraits<CmpInst>::op_begin(this),
OperandTraits<CmpInst>::operands(this), InsertBefore) {
Op<0>() = LHS;
@@ -4556,50 +3432,10 @@ CmpInst::CmpInst(Type *ty, OtherOps op, Predicate predicate, Value *LHS,
copyIRFlags(FlagsSource);
}
-CmpInst::CmpInst(Type *ty, OtherOps op, Predicate predicate, Value *LHS,
- Value *RHS, const Twine &Name, Instruction *InsertBefore,
- Instruction *FlagsSource)
- : Instruction(ty, op,
- OperandTraits<CmpInst>::op_begin(this),
- OperandTraits<CmpInst>::operands(this),
- InsertBefore) {
- Op<0>() = LHS;
- Op<1>() = RHS;
- setPredicate((Predicate)predicate);
- setName(Name);
- if (FlagsSource)
- copyIRFlags(FlagsSource);
-}
-
-CmpInst::CmpInst(Type *ty, OtherOps op, Predicate predicate, Value *LHS,
- Value *RHS, const Twine &Name, BasicBlock *InsertAtEnd)
- : Instruction(ty, op,
- OperandTraits<CmpInst>::op_begin(this),
- OperandTraits<CmpInst>::operands(this),
- InsertAtEnd) {
- Op<0>() = LHS;
- Op<1>() = RHS;
- setPredicate((Predicate)predicate);
- setName(Name);
-}
-
-CmpInst *
-CmpInst::Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2,
- const Twine &Name, BasicBlock::iterator InsertBefore) {
- if (Op == Instruction::ICmp) {
- return new ICmpInst(InsertBefore, CmpInst::Predicate(predicate),
- S1, S2, Name);
- }
-
- return new FCmpInst(InsertBefore, CmpInst::Predicate(predicate),
- S1, S2, Name);
-}
-
-CmpInst *
-CmpInst::Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2,
- const Twine &Name, Instruction *InsertBefore) {
+CmpInst *CmpInst::Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2,
+ const Twine &Name, InsertPosition InsertBefore) {
if (Op == Instruction::ICmp) {
- if (InsertBefore)
+ if (InsertBefore.IsValid())
return new ICmpInst(InsertBefore, CmpInst::Predicate(predicate),
S1, S2, Name);
else
@@ -4607,7 +3443,7 @@ CmpInst::Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2,
S1, S2, Name);
}
- if (InsertBefore)
+ if (InsertBefore.IsValid())
return new FCmpInst(InsertBefore, CmpInst::Predicate(predicate),
S1, S2, Name);
else
@@ -4615,22 +3451,11 @@ CmpInst::Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2,
S1, S2, Name);
}
-CmpInst *
-CmpInst::Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2,
- const Twine &Name, BasicBlock *InsertAtEnd) {
- if (Op == Instruction::ICmp) {
- return new ICmpInst(InsertAtEnd, CmpInst::Predicate(predicate),
- S1, S2, Name);
- }
- return new FCmpInst(InsertAtEnd, CmpInst::Predicate(predicate),
- S1, S2, Name);
-}
-
CmpInst *CmpInst::CreateWithCopiedFlags(OtherOps Op, Predicate Pred, Value *S1,
Value *S2,
const Instruction *FlagsSource,
const Twine &Name,
- Instruction *InsertBefore) {
+ InsertPosition InsertBefore) {
CmpInst *Inst = Create(Op, Pred, S1, S2, Name, InsertBefore);
Inst->copyIRFlags(FlagsSource);
return Inst;
@@ -5086,34 +3911,12 @@ void SwitchInst::init(Value *Value, BasicBlock *Default, unsigned NumReserved) {
/// be specified here to make memory allocation more efficient. This
/// constructor can also autoinsert before another instruction.
SwitchInst::SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
- BasicBlock::iterator InsertBefore)
- : Instruction(Type::getVoidTy(Value->getContext()), Instruction::Switch,
- nullptr, 0, InsertBefore) {
- init(Value, Default, 2 + NumCases * 2);
-}
-
-/// SwitchInst ctor - Create a new switch instruction, specifying a value to
-/// switch on and a default destination. The number of additional cases can
-/// be specified here to make memory allocation more efficient. This
-/// constructor can also autoinsert before another instruction.
-SwitchInst::SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
- Instruction *InsertBefore)
+ InsertPosition InsertBefore)
: Instruction(Type::getVoidTy(Value->getContext()), Instruction::Switch,
nullptr, 0, InsertBefore) {
init(Value, Default, 2+NumCases*2);
}
-/// SwitchInst ctor - Create a new switch instruction, specifying a value to
-/// switch on and a default destination. The number of additional cases can
-/// be specified here to make memory allocation more efficient. This
-/// constructor also autoinserts at the end of the specified BasicBlock.
-SwitchInst::SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
- BasicBlock *InsertAtEnd)
- : Instruction(Type::getVoidTy(Value->getContext()), Instruction::Switch,
- nullptr, 0, InsertAtEnd) {
- init(Value, Default, 2+NumCases*2);
-}
-
SwitchInst::SwitchInst(const SwitchInst &SI)
: Instruction(SI.getType(), Instruction::Switch, nullptr, 0) {
init(SI.getCondition(), SI.getDefaultDest(), SI.getNumOperands());
@@ -5315,26 +4118,12 @@ void IndirectBrInst::growOperands() {
}
IndirectBrInst::IndirectBrInst(Value *Address, unsigned NumCases,
- BasicBlock::iterator InsertBefore)
- : Instruction(Type::getVoidTy(Address->getContext()),
- Instruction::IndirectBr, nullptr, 0, InsertBefore) {
- init(Address, NumCases);
-}
-
-IndirectBrInst::IndirectBrInst(Value *Address, unsigned NumCases,
- Instruction *InsertBefore)
+ InsertPosition InsertBefore)
: Instruction(Type::getVoidTy(Address->getContext()),
Instruction::IndirectBr, nullptr, 0, InsertBefore) {
init(Address, NumCases);
}
-IndirectBrInst::IndirectBrInst(Value *Address, unsigned NumCases,
- BasicBlock *InsertAtEnd)
- : Instruction(Type::getVoidTy(Address->getContext()),
- Instruction::IndirectBr, nullptr, 0, InsertAtEnd) {
- init(Address, NumCases);
-}
-
IndirectBrInst::IndirectBrInst(const IndirectBrInst &IBI)
: Instruction(Type::getVoidTy(IBI.getContext()), Instruction::IndirectBr,
nullptr, IBI.getNumOperands()) {
@@ -5378,24 +4167,11 @@ void IndirectBrInst::removeDestination(unsigned idx) {
// FreezeInst Implementation
//===----------------------------------------------------------------------===//
-FreezeInst::FreezeInst(Value *S, const Twine &Name,
- BasicBlock::iterator InsertBefore)
- : UnaryInstruction(S->getType(), Freeze, S, InsertBefore) {
- setName(Name);
-}
-
-FreezeInst::FreezeInst(Value *S,
- const Twine &Name, Instruction *InsertBefore)
+FreezeInst::FreezeInst(Value *S, const Twine &Name, InsertPosition InsertBefore)
: UnaryInstruction(S->getType(), Freeze, S, InsertBefore) {
setName(Name);
}
-FreezeInst::FreezeInst(Value *S,
- const Twine &Name, BasicBlock *InsertAtEnd)
- : UnaryInstruction(S->getType(), Freeze, S, InsertAtEnd) {
- setName(Name);
-}
-
//===----------------------------------------------------------------------===//
// cloneImpl() implementations
//===----------------------------------------------------------------------===//
diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index 756daf5bb41fa..5dafcfbc50369 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -505,9 +505,9 @@ class IRBuilderPrefixedInserter final : public IRBuilderDefaultInserter {
public:
void SetNamePrefix(const Twine &P) { Prefix = P.str(); }
- void InsertHelper(Instruction *I, const Twine &Name, BasicBlock *BB,
+ void InsertHelper(Instruction *I, const Twine &Name,
BasicBlock::iterator InsertPt) const override {
- IRBuilderDefaultInserter::InsertHelper(I, getNameWithPrefix(Name), BB,
+ IRBuilderDefaultInserter::InsertHelper(I, getNameWithPrefix(Name),
InsertPt);
}
};
More information about the llvm-commits
mailing list