2003-01-27 22:08:52 +00:00
|
|
|
//===-- llvm/Instructions.h - Instruction subclass definitions --*- C++ -*-===//
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-01-27 22:08:52 +00:00
|
|
|
//
|
|
|
|
// This file exposes the class definitions of all of the subclasses of the
|
|
|
|
// Instruction class. This is meant to be an easy way to get access to all
|
|
|
|
// instruction subclasses.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-10 00:45:19 +00:00
|
|
|
#ifndef LLVM_IR_INSTRUCTIONS_H
|
|
|
|
#define LLVM_IR_INSTRUCTIONS_H
|
2003-01-27 22:08:52 +00:00
|
|
|
|
2012-12-03 17:02:12 +00:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2014-03-26 18:18:02 +00:00
|
|
|
#include "llvm/ADT/iterator_range.h"
|
2012-12-03 17:02:12 +00:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Attributes.h"
|
|
|
|
#include "llvm/IR/CallingConv.h"
|
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
|
|
|
#include "llvm/IR/InstrTypes.h"
|
2012-12-03 17:02:12 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-01-05 17:59:02 +00:00
|
|
|
#include <iterator>
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2012-12-11 10:29:10 +00:00
|
|
|
class APInt;
|
2005-02-24 05:32:09 +00:00
|
|
|
class ConstantInt;
|
2007-02-28 22:00:54 +00:00
|
|
|
class ConstantRange;
|
2012-12-11 10:29:10 +00:00
|
|
|
class DataLayout;
|
2009-08-11 17:45:13 +00:00
|
|
|
class LLVMContext;
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2011-07-25 23:16:38 +00:00
|
|
|
enum AtomicOrdering {
|
|
|
|
NotAtomic = 0,
|
|
|
|
Unordered = 1,
|
|
|
|
Monotonic = 2,
|
|
|
|
// Consume = 3, // Not specified yet.
|
|
|
|
Acquire = 4,
|
|
|
|
Release = 5,
|
|
|
|
AcquireRelease = 6,
|
|
|
|
SequentiallyConsistent = 7
|
|
|
|
};
|
|
|
|
|
|
|
|
enum SynchronizationScope {
|
|
|
|
SingleThread = 0,
|
|
|
|
CrossThread = 1
|
|
|
|
};
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-10-23 21:09:37 +00:00
|
|
|
// AllocaInst Class
|
2004-07-29 12:17:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-10-23 21:09:37 +00:00
|
|
|
/// AllocaInst - an instruction to allocate memory on the stack
|
2004-07-29 12:17:34 +00:00
|
|
|
///
|
2009-10-23 21:09:37 +00:00
|
|
|
class AllocaInst : public UnaryInstruction {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
AllocaInst *clone_impl() const override;
|
2004-07-29 12:17:34 +00:00
|
|
|
public:
|
2014-04-09 06:08:46 +00:00
|
|
|
explicit AllocaInst(Type *Ty, Value *ArraySize = nullptr,
|
|
|
|
const Twine &Name = "",
|
|
|
|
Instruction *InsertBefore = nullptr);
|
2011-07-18 04:54:35 +00:00
|
|
|
AllocaInst(Type *Ty, Value *ArraySize,
|
2009-10-23 21:09:37 +00:00
|
|
|
const Twine &Name, BasicBlock *InsertAtEnd);
|
|
|
|
|
2014-04-09 06:08:46 +00:00
|
|
|
AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = nullptr);
|
2011-07-18 04:54:35 +00:00
|
|
|
AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
|
2009-10-23 21:09:37 +00:00
|
|
|
|
2011-07-18 04:54:35 +00:00
|
|
|
AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
|
2014-04-09 06:08:46 +00:00
|
|
|
const Twine &Name = "", Instruction *InsertBefore = nullptr);
|
2011-07-18 04:54:35 +00:00
|
|
|
AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
|
2009-10-23 21:09:37 +00:00
|
|
|
const Twine &Name, BasicBlock *InsertAtEnd);
|
|
|
|
|
2008-04-06 20:25:17 +00:00
|
|
|
// Out of line virtual method, so the vtable, etc. has a home.
|
2009-10-23 21:09:37 +00:00
|
|
|
virtual ~AllocaInst();
|
2007-12-10 02:14:30 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
/// isArrayAllocation - Return true if there is an allocation size parameter
|
|
|
|
/// to the allocation instruction that is not 1.
|
|
|
|
///
|
|
|
|
bool isArrayAllocation() const;
|
|
|
|
|
2009-07-07 20:47:48 +00:00
|
|
|
/// getArraySize - Get the number of elements allocated. For a simple
|
2004-07-29 12:17:34 +00:00
|
|
|
/// allocation of a single element, this will return a constant 1 value.
|
|
|
|
///
|
2008-02-23 01:11:02 +00:00
|
|
|
const Value *getArraySize() const { return getOperand(0); }
|
|
|
|
Value *getArraySize() { return getOperand(0); }
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
/// getType - Overload to return most specific pointer type
|
|
|
|
///
|
2011-07-18 04:54:35 +00:00
|
|
|
PointerType *getType() const {
|
2013-02-18 18:49:44 +00:00
|
|
|
return cast<PointerType>(Instruction::getType());
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getAllocatedType - Return the type that is being allocated by the
|
|
|
|
/// instruction.
|
|
|
|
///
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134829 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-09 17:41:24 +00:00
|
|
|
Type *getAllocatedType() const;
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2005-11-05 09:21:28 +00:00
|
|
|
/// getAlignment - Return the alignment of the memory that is being allocated
|
|
|
|
/// by the instruction.
|
|
|
|
///
|
2009-12-29 02:14:09 +00:00
|
|
|
unsigned getAlignment() const {
|
2014-01-17 23:58:17 +00:00
|
|
|
return (1u << (getSubclassDataFromInstruction() & 31)) >> 1;
|
2009-12-29 02:14:09 +00:00
|
|
|
}
|
2008-03-24 16:55:58 +00:00
|
|
|
void setAlignment(unsigned Align);
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2008-11-26 02:54:17 +00:00
|
|
|
/// isStaticAlloca - Return true if this alloca is in the entry block of the
|
|
|
|
/// function and is a constant size. If so, the code generator will fold it
|
|
|
|
/// into the prolog/epilog code, so it is basically free.
|
|
|
|
bool isStaticAlloca() const;
|
2009-10-23 21:09:37 +00:00
|
|
|
|
2014-01-17 23:58:17 +00:00
|
|
|
/// \brief Return true if this alloca is used as an inalloca argument to a
|
|
|
|
/// call. Such allocas are never considered static even if they are in the
|
|
|
|
/// entry block.
|
|
|
|
bool isUsedWithInAlloca() const {
|
|
|
|
return getSubclassDataFromInstruction() & 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Specify whether this alloca is used to represent a the arguments to
|
|
|
|
/// a call.
|
|
|
|
void setUsedWithInAlloca(bool V) {
|
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~32) |
|
|
|
|
(V ? 32 : 0));
|
|
|
|
}
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::Alloca);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2009-12-29 02:14:09 +00:00
|
|
|
private:
|
2009-12-29 02:46:09 +00:00
|
|
|
// Shadow Instruction::setInstructionSubclassData with a private forwarding
|
|
|
|
// method so that subclasses cannot accidentally use it.
|
|
|
|
void setInstructionSubclassData(unsigned short D) {
|
|
|
|
Instruction::setInstructionSubclassData(D);
|
2009-12-29 02:14:09 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// LoadInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2005-02-05 01:44:18 +00:00
|
|
|
/// LoadInst - an instruction for reading from memory. This uses the
|
|
|
|
/// SubclassData field in Value to store whether or not the load is volatile.
|
2004-07-29 12:17:34 +00:00
|
|
|
///
|
2005-01-29 00:31:36 +00:00
|
|
|
class LoadInst : public UnaryInstruction {
|
|
|
|
void AssertOK();
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
LoadInst *clone_impl() const override;
|
2004-07-29 12:17:34 +00:00
|
|
|
public:
|
2009-07-25 04:41:11 +00:00
|
|
|
LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
|
|
|
|
LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
|
2009-08-11 18:11:15 +00:00
|
|
|
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr);
|
2009-07-25 04:41:11 +00:00
|
|
|
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
|
2007-07-18 20:51:11 +00:00
|
|
|
BasicBlock *InsertAtEnd);
|
2011-08-09 23:02:53 +00:00
|
|
|
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
|
2014-04-09 06:08:46 +00:00
|
|
|
unsigned Align, Instruction *InsertBefore = nullptr);
|
2009-07-25 04:41:11 +00:00
|
|
|
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
|
2008-07-24 00:08:56 +00:00
|
|
|
unsigned Align, BasicBlock *InsertAtEnd);
|
2011-08-09 23:02:53 +00:00
|
|
|
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
|
|
|
|
unsigned Align, AtomicOrdering Order,
|
|
|
|
SynchronizationScope SynchScope = CrossThread,
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr);
|
2011-08-09 23:02:53 +00:00
|
|
|
LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
|
|
|
|
unsigned Align, AtomicOrdering Order,
|
|
|
|
SynchronizationScope SynchScope,
|
|
|
|
BasicBlock *InsertAtEnd);
|
2008-07-24 00:08:56 +00:00
|
|
|
|
2009-08-11 18:11:15 +00:00
|
|
|
LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
|
|
|
|
LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
|
2014-04-09 06:08:46 +00:00
|
|
|
explicit LoadInst(Value *Ptr, const char *NameStr = nullptr,
|
|
|
|
bool isVolatile = false,
|
|
|
|
Instruction *InsertBefore = nullptr);
|
2009-08-11 18:11:15 +00:00
|
|
|
LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
|
|
|
|
BasicBlock *InsertAtEnd);
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
/// isVolatile - Return true if this is a load from a volatile memory
|
|
|
|
/// location.
|
|
|
|
///
|
2009-12-29 02:46:09 +00:00
|
|
|
bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
/// setVolatile - Specify whether this is a volatile load or not.
|
|
|
|
///
|
2009-02-09 17:11:05 +00:00
|
|
|
void setVolatile(bool V) {
|
2009-12-29 02:46:09 +00:00
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
|
|
|
|
(V ? 1 : 0));
|
2007-04-22 19:24:39 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2007-04-22 19:24:39 +00:00
|
|
|
/// getAlignment - Return the alignment of the access that is being performed
|
|
|
|
///
|
|
|
|
unsigned getAlignment() const {
|
2011-08-09 23:02:53 +00:00
|
|
|
return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
|
2007-04-22 19:24:39 +00:00
|
|
|
}
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2007-04-22 19:24:39 +00:00
|
|
|
void setAlignment(unsigned Align);
|
|
|
|
|
2011-08-09 23:02:53 +00:00
|
|
|
/// Returns the ordering effect of this fence.
|
|
|
|
AtomicOrdering getOrdering() const {
|
|
|
|
return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Set the ordering constraint on this load. May not be Release or
|
|
|
|
/// AcquireRelease.
|
|
|
|
void setOrdering(AtomicOrdering Ordering) {
|
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
|
|
|
|
(Ordering << 7));
|
|
|
|
}
|
|
|
|
|
|
|
|
SynchronizationScope getSynchScope() const {
|
|
|
|
return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Specify whether this load is ordered with respect to all
|
|
|
|
/// concurrently executing threads, or only with respect to signal handlers
|
|
|
|
/// executing in the same thread.
|
|
|
|
void setSynchScope(SynchronizationScope xthread) {
|
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
|
|
|
|
(xthread << 6));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isAtomic() const { return getOrdering() != NotAtomic; }
|
|
|
|
void setAtomic(AtomicOrdering Ordering,
|
|
|
|
SynchronizationScope SynchScope = CrossThread) {
|
|
|
|
setOrdering(Ordering);
|
|
|
|
setSynchScope(SynchScope);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isSimple() const { return !isAtomic() && !isVolatile(); }
|
|
|
|
bool isUnordered() const {
|
|
|
|
return getOrdering() <= Unordered && !isVolatile();
|
|
|
|
}
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
Value *getPointerOperand() { return getOperand(0); }
|
|
|
|
const Value *getPointerOperand() const { return getOperand(0); }
|
|
|
|
static unsigned getPointerOperandIndex() { return 0U; }
|
|
|
|
|
2012-11-01 11:25:28 +00:00
|
|
|
/// \brief Returns the address space of the pointer operand.
|
2009-08-30 19:45:21 +00:00
|
|
|
unsigned getPointerAddressSpace() const {
|
2012-11-01 09:37:49 +00:00
|
|
|
return getPointerOperand()->getType()->getPointerAddressSpace();
|
2009-08-30 19:45:21 +00:00
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::Load;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2009-12-29 02:14:09 +00:00
|
|
|
private:
|
2009-12-29 02:46:09 +00:00
|
|
|
// Shadow Instruction::setInstructionSubclassData with a private forwarding
|
|
|
|
// method so that subclasses cannot accidentally use it.
|
|
|
|
void setInstructionSubclassData(unsigned short D) {
|
|
|
|
Instruction::setInstructionSubclassData(D);
|
2009-12-29 02:14:09 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// StoreInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2005-04-21 20:19:05 +00:00
|
|
|
/// StoreInst - an instruction for storing to memory
|
2004-07-29 12:17:34 +00:00
|
|
|
///
|
|
|
|
class StoreInst : public Instruction {
|
2012-09-18 03:25:49 +00:00
|
|
|
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
|
2005-01-29 00:31:36 +00:00
|
|
|
void AssertOK();
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
StoreInst *clone_impl() const override;
|
2004-07-29 12:17:34 +00:00
|
|
|
public:
|
2008-04-06 20:25:17 +00:00
|
|
|
// allocate space for exactly two operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 2);
|
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
|
|
|
|
StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
|
|
|
|
StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr);
|
2011-08-09 23:02:53 +00:00
|
|
|
StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
|
2007-04-22 19:24:39 +00:00
|
|
|
StoreInst(Value *Val, Value *Ptr, bool isVolatile,
|
2014-04-09 06:08:46 +00:00
|
|
|
unsigned Align, Instruction *InsertBefore = nullptr);
|
2007-07-18 20:51:11 +00:00
|
|
|
StoreInst(Value *Val, Value *Ptr, bool isVolatile,
|
|
|
|
unsigned Align, BasicBlock *InsertAtEnd);
|
2011-08-09 23:02:53 +00:00
|
|
|
StoreInst(Value *Val, Value *Ptr, bool isVolatile,
|
|
|
|
unsigned Align, AtomicOrdering Order,
|
|
|
|
SynchronizationScope SynchScope = CrossThread,
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr);
|
2011-08-09 23:02:53 +00:00
|
|
|
StoreInst(Value *Val, Value *Ptr, bool isVolatile,
|
|
|
|
unsigned Align, AtomicOrdering Order,
|
|
|
|
SynchronizationScope SynchScope,
|
|
|
|
BasicBlock *InsertAtEnd);
|
2013-03-07 20:04:17 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2011-08-09 23:02:53 +00:00
|
|
|
/// isVolatile - Return true if this is a store to a volatile memory
|
2004-07-29 12:17:34 +00:00
|
|
|
/// location.
|
|
|
|
///
|
2009-12-29 02:46:09 +00:00
|
|
|
bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2011-08-09 23:02:53 +00:00
|
|
|
/// setVolatile - Specify whether this is a volatile store or not.
|
2004-07-29 12:17:34 +00:00
|
|
|
///
|
2009-02-09 17:11:05 +00:00
|
|
|
void setVolatile(bool V) {
|
2009-12-29 02:46:09 +00:00
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
|
|
|
|
(V ? 1 : 0));
|
2007-04-22 19:24:39 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
2008-05-10 08:32:32 +00:00
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2005-01-29 00:31:36 +00:00
|
|
|
|
2007-04-22 19:24:39 +00:00
|
|
|
/// getAlignment - Return the alignment of the access that is being performed
|
|
|
|
///
|
|
|
|
unsigned getAlignment() const {
|
2011-08-09 23:02:53 +00:00
|
|
|
return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
|
2007-04-22 19:24:39 +00:00
|
|
|
}
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2007-04-22 19:24:39 +00:00
|
|
|
void setAlignment(unsigned Align);
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2011-08-09 23:02:53 +00:00
|
|
|
/// Returns the ordering effect of this store.
|
|
|
|
AtomicOrdering getOrdering() const {
|
|
|
|
return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Set the ordering constraint on this store. May not be Acquire or
|
|
|
|
/// AcquireRelease.
|
|
|
|
void setOrdering(AtomicOrdering Ordering) {
|
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
|
|
|
|
(Ordering << 7));
|
|
|
|
}
|
|
|
|
|
|
|
|
SynchronizationScope getSynchScope() const {
|
|
|
|
return SynchronizationScope((getSubclassDataFromInstruction() >> 6) & 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Specify whether this store instruction is ordered with respect to all
|
|
|
|
/// concurrently executing threads, or only with respect to signal handlers
|
|
|
|
/// executing in the same thread.
|
|
|
|
void setSynchScope(SynchronizationScope xthread) {
|
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~(1 << 6)) |
|
|
|
|
(xthread << 6));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isAtomic() const { return getOrdering() != NotAtomic; }
|
|
|
|
void setAtomic(AtomicOrdering Ordering,
|
|
|
|
SynchronizationScope SynchScope = CrossThread) {
|
|
|
|
setOrdering(Ordering);
|
|
|
|
setSynchScope(SynchScope);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isSimple() const { return !isAtomic() && !isVolatile(); }
|
|
|
|
bool isUnordered() const {
|
|
|
|
return getOrdering() <= Unordered && !isVolatile();
|
|
|
|
}
|
|
|
|
|
2010-06-26 23:26:37 +00:00
|
|
|
Value *getValueOperand() { return getOperand(0); }
|
|
|
|
const Value *getValueOperand() const { return getOperand(0); }
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
Value *getPointerOperand() { return getOperand(1); }
|
|
|
|
const Value *getPointerOperand() const { return getOperand(1); }
|
|
|
|
static unsigned getPointerOperandIndex() { return 1U; }
|
|
|
|
|
2012-11-01 11:25:28 +00:00
|
|
|
/// \brief Returns the address space of the pointer operand.
|
2009-08-30 19:45:21 +00:00
|
|
|
unsigned getPointerAddressSpace() const {
|
2012-11-01 09:37:49 +00:00
|
|
|
return getPointerOperand()->getType()->getPointerAddressSpace();
|
2009-08-30 19:45:21 +00:00
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::Store;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2009-12-29 02:14:09 +00:00
|
|
|
private:
|
2009-12-29 02:46:09 +00:00
|
|
|
// Shadow Instruction::setInstructionSubclassData with a private forwarding
|
|
|
|
// method so that subclasses cannot accidentally use it.
|
|
|
|
void setInstructionSubclassData(unsigned short D) {
|
|
|
|
Instruction::setInstructionSubclassData(D);
|
2009-12-29 02:14:09 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2011-01-11 15:07:38 +00:00
|
|
|
struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2011-07-25 23:16:38 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FenceInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// FenceInst - an instruction for ordering other memory operations
|
|
|
|
///
|
|
|
|
class FenceInst : public Instruction {
|
2012-09-18 03:25:49 +00:00
|
|
|
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
|
2011-07-25 23:16:38 +00:00
|
|
|
void Init(AtomicOrdering Ordering, SynchronizationScope SynchScope);
|
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
FenceInst *clone_impl() const override;
|
2011-07-25 23:16:38 +00:00
|
|
|
public:
|
|
|
|
// allocate space for exactly zero operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ordering may only be Acquire, Release, AcquireRelease, or
|
|
|
|
// SequentiallyConsistent.
|
|
|
|
FenceInst(LLVMContext &C, AtomicOrdering Ordering,
|
|
|
|
SynchronizationScope SynchScope = CrossThread,
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr);
|
2011-07-25 23:16:38 +00:00
|
|
|
FenceInst(LLVMContext &C, AtomicOrdering Ordering,
|
|
|
|
SynchronizationScope SynchScope,
|
|
|
|
BasicBlock *InsertAtEnd);
|
|
|
|
|
|
|
|
/// Returns the ordering effect of this fence.
|
|
|
|
AtomicOrdering getOrdering() const {
|
|
|
|
return AtomicOrdering(getSubclassDataFromInstruction() >> 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Set the ordering constraint on this fence. May only be Acquire, Release,
|
|
|
|
/// AcquireRelease, or SequentiallyConsistent.
|
|
|
|
void setOrdering(AtomicOrdering Ordering) {
|
2011-08-09 23:02:53 +00:00
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
|
|
|
|
(Ordering << 1));
|
2011-07-25 23:16:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SynchronizationScope getSynchScope() const {
|
|
|
|
return SynchronizationScope(getSubclassDataFromInstruction() & 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Specify whether this fence orders other operations with respect to all
|
|
|
|
/// concurrently executing threads, or only with respect to signal handlers
|
|
|
|
/// executing in the same thread.
|
|
|
|
void setSynchScope(SynchronizationScope xthread) {
|
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
|
|
|
|
xthread);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::Fence;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
// Shadow Instruction::setInstructionSubclassData with a private forwarding
|
|
|
|
// method so that subclasses cannot accidentally use it.
|
|
|
|
void setInstructionSubclassData(unsigned short D) {
|
|
|
|
Instruction::setInstructionSubclassData(D);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-07-28 21:48:00 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// AtomicCmpXchgInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// AtomicCmpXchgInst - an instruction that atomically checks whether a
|
|
|
|
/// specified value is in a memory location, and, if it is, stores a new value
|
|
|
|
/// there. Returns the value that was loaded.
|
|
|
|
///
|
|
|
|
class AtomicCmpXchgInst : public Instruction {
|
2012-09-18 03:25:49 +00:00
|
|
|
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
|
2011-07-28 21:48:00 +00:00
|
|
|
void Init(Value *Ptr, Value *Cmp, Value *NewVal,
|
2014-03-11 10:48:52 +00:00
|
|
|
AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
|
|
|
|
SynchronizationScope SynchScope);
|
2011-07-28 21:48:00 +00:00
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
AtomicCmpXchgInst *clone_impl() const override;
|
2011-07-28 21:48:00 +00:00
|
|
|
public:
|
|
|
|
// allocate space for exactly three operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 3);
|
|
|
|
}
|
|
|
|
AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
|
2014-03-11 10:48:52 +00:00
|
|
|
AtomicOrdering SuccessOrdering,
|
|
|
|
AtomicOrdering FailureOrdering,
|
|
|
|
SynchronizationScope SynchScope,
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr);
|
2011-07-28 21:48:00 +00:00
|
|
|
AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
|
2014-03-11 10:48:52 +00:00
|
|
|
AtomicOrdering SuccessOrdering,
|
|
|
|
AtomicOrdering FailureOrdering,
|
|
|
|
SynchronizationScope SynchScope,
|
2011-07-28 21:48:00 +00:00
|
|
|
BasicBlock *InsertAtEnd);
|
|
|
|
|
|
|
|
/// isVolatile - Return true if this is a cmpxchg from a volatile memory
|
|
|
|
/// location.
|
|
|
|
///
|
|
|
|
bool isVolatile() const {
|
|
|
|
return getSubclassDataFromInstruction() & 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// setVolatile - Specify whether this is a volatile cmpxchg.
|
|
|
|
///
|
|
|
|
void setVolatile(bool V) {
|
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
|
|
|
|
(unsigned)V);
|
|
|
|
}
|
|
|
|
|
IR: add "cmpxchg weak" variant to support permitted failure.
This commit adds a weak variant of the cmpxchg operation, as described
in C++11. A cmpxchg instruction with this modifier is permitted to
fail to store, even if the comparison indicated it should.
As a result, cmpxchg instructions must return a flag indicating
success in addition to their original iN value loaded. Thus, for
uniformity *all* cmpxchg instructions now return "{ iN, i1 }". The
second flag is 1 when the store succeeded.
At the DAG level, a new ATOMIC_CMP_SWAP_WITH_SUCCESS node has been
added as the natural representation for the new cmpxchg instructions.
It is a strong cmpxchg.
By default this gets Expanded to the existing ATOMIC_CMP_SWAP during
Legalization, so existing backends should see no change in behaviour.
If they wish to deal with the enhanced node instead, they can call
setOperationAction on it. Beware: as a node with 2 results, it cannot
be selected from TableGen.
Currently, no use is made of the extra information provided in this
patch. Test updates are almost entirely adapting the input IR to the
new scheme.
Summary for out of tree users:
------------------------------
+ Legacy Bitcode files are upgraded during read.
+ Legacy assembly IR files will be invalid.
+ Front-ends must adapt to different type for "cmpxchg".
+ Backends should be unaffected by default.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210903 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-13 14:24:07 +00:00
|
|
|
/// Return true if this cmpxchg may spuriously fail.
|
|
|
|
bool isWeak() const {
|
|
|
|
return getSubclassDataFromInstruction() & 0x100;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setWeak(bool IsWeak) {
|
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x100) |
|
|
|
|
(IsWeak << 8));
|
|
|
|
}
|
|
|
|
|
2011-07-28 21:48:00 +00:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
|
|
|
|
|
|
|
/// Set the ordering constraint on this cmpxchg.
|
2014-03-11 10:48:52 +00:00
|
|
|
void setSuccessOrdering(AtomicOrdering Ordering) {
|
2011-07-28 21:48:00 +00:00
|
|
|
assert(Ordering != NotAtomic &&
|
|
|
|
"CmpXchg instructions can only be atomic.");
|
2014-03-11 10:48:52 +00:00
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x1c) |
|
2011-07-28 21:48:00 +00:00
|
|
|
(Ordering << 2));
|
|
|
|
}
|
|
|
|
|
2014-03-11 10:48:52 +00:00
|
|
|
void setFailureOrdering(AtomicOrdering Ordering) {
|
|
|
|
assert(Ordering != NotAtomic &&
|
|
|
|
"CmpXchg instructions can only be atomic.");
|
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~0xe0) |
|
|
|
|
(Ordering << 5));
|
|
|
|
}
|
|
|
|
|
2011-07-28 21:48:00 +00:00
|
|
|
/// Specify whether this cmpxchg is atomic and orders other operations with
|
|
|
|
/// respect to all concurrently executing threads, or only with respect to
|
|
|
|
/// signal handlers executing in the same thread.
|
|
|
|
void setSynchScope(SynchronizationScope SynchScope) {
|
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
|
|
|
|
(SynchScope << 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the ordering constraint on this cmpxchg.
|
2014-03-11 10:48:52 +00:00
|
|
|
AtomicOrdering getSuccessOrdering() const {
|
|
|
|
return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the ordering constraint on this cmpxchg.
|
|
|
|
AtomicOrdering getFailureOrdering() const {
|
|
|
|
return AtomicOrdering((getSubclassDataFromInstruction() >> 5) & 7);
|
2011-07-28 21:48:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns whether this cmpxchg is atomic between threads or only within a
|
|
|
|
/// single thread.
|
|
|
|
SynchronizationScope getSynchScope() const {
|
|
|
|
return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *getPointerOperand() { return getOperand(0); }
|
|
|
|
const Value *getPointerOperand() const { return getOperand(0); }
|
|
|
|
static unsigned getPointerOperandIndex() { return 0U; }
|
|
|
|
|
|
|
|
Value *getCompareOperand() { return getOperand(1); }
|
|
|
|
const Value *getCompareOperand() const { return getOperand(1); }
|
2013-03-07 20:04:17 +00:00
|
|
|
|
2011-07-28 21:48:00 +00:00
|
|
|
Value *getNewValOperand() { return getOperand(2); }
|
|
|
|
const Value *getNewValOperand() const { return getOperand(2); }
|
2013-03-07 20:04:17 +00:00
|
|
|
|
2012-11-01 11:25:28 +00:00
|
|
|
/// \brief Returns the address space of the pointer operand.
|
2011-07-28 21:48:00 +00:00
|
|
|
unsigned getPointerAddressSpace() const {
|
2012-11-01 09:37:49 +00:00
|
|
|
return getPointerOperand()->getType()->getPointerAddressSpace();
|
2011-07-28 21:48:00 +00:00
|
|
|
}
|
2013-03-07 20:04:17 +00:00
|
|
|
|
2014-03-11 10:48:52 +00:00
|
|
|
/// \brief Returns the strongest permitted ordering on failure, given the
|
|
|
|
/// desired ordering on success.
|
|
|
|
///
|
|
|
|
/// If the comparison in a cmpxchg operation fails, there is no atomic store
|
|
|
|
/// so release semantics cannot be provided. So this function drops explicit
|
|
|
|
/// Release requests from the AtomicOrdering. A SequentiallyConsistent
|
|
|
|
/// operation would remain SequentiallyConsistent.
|
|
|
|
static AtomicOrdering
|
|
|
|
getStrongestFailureOrdering(AtomicOrdering SuccessOrdering) {
|
|
|
|
switch (SuccessOrdering) {
|
|
|
|
default: llvm_unreachable("invalid cmpxchg success ordering");
|
|
|
|
case Release:
|
|
|
|
case Monotonic:
|
|
|
|
return Monotonic;
|
|
|
|
case AcquireRelease:
|
|
|
|
case Acquire:
|
|
|
|
return Acquire;
|
|
|
|
case SequentiallyConsistent:
|
|
|
|
return SequentiallyConsistent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-28 21:48:00 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::AtomicCmpXchg;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
// Shadow Instruction::setInstructionSubclassData with a private forwarding
|
|
|
|
// method so that subclasses cannot accidentally use it.
|
|
|
|
void setInstructionSubclassData(unsigned short D) {
|
|
|
|
Instruction::setInstructionSubclassData(D);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct OperandTraits<AtomicCmpXchgInst> :
|
|
|
|
public FixedNumOperandTraits<AtomicCmpXchgInst, 3> {
|
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicCmpXchgInst, Value)
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// AtomicRMWInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// AtomicRMWInst - an instruction that atomically reads a memory location,
|
|
|
|
/// combines it with another value, and then stores the result back. Returns
|
|
|
|
/// the old value.
|
|
|
|
///
|
|
|
|
class AtomicRMWInst : public Instruction {
|
2012-09-18 03:25:49 +00:00
|
|
|
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
|
2011-07-28 21:48:00 +00:00
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
AtomicRMWInst *clone_impl() const override;
|
2011-07-28 21:48:00 +00:00
|
|
|
public:
|
|
|
|
/// This enumeration lists the possible modifications atomicrmw can make. In
|
|
|
|
/// the descriptions, 'p' is the pointer to the instruction's memory location,
|
|
|
|
/// 'old' is the initial value of *p, and 'v' is the other value passed to the
|
|
|
|
/// instruction. These instructions always return 'old'.
|
|
|
|
enum BinOp {
|
|
|
|
/// *p = v
|
|
|
|
Xchg,
|
|
|
|
/// *p = old + v
|
|
|
|
Add,
|
|
|
|
/// *p = old - v
|
|
|
|
Sub,
|
|
|
|
/// *p = old & v
|
|
|
|
And,
|
|
|
|
/// *p = ~old & v
|
|
|
|
Nand,
|
|
|
|
/// *p = old | v
|
|
|
|
Or,
|
|
|
|
/// *p = old ^ v
|
|
|
|
Xor,
|
|
|
|
/// *p = old >signed v ? old : v
|
|
|
|
Max,
|
|
|
|
/// *p = old <signed v ? old : v
|
|
|
|
Min,
|
|
|
|
/// *p = old >unsigned v ? old : v
|
|
|
|
UMax,
|
|
|
|
/// *p = old <unsigned v ? old : v
|
|
|
|
UMin,
|
|
|
|
|
|
|
|
FIRST_BINOP = Xchg,
|
|
|
|
LAST_BINOP = UMin,
|
|
|
|
BAD_BINOP
|
|
|
|
};
|
|
|
|
|
|
|
|
// allocate space for exactly two operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 2);
|
|
|
|
}
|
|
|
|
AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
|
|
|
|
AtomicOrdering Ordering, SynchronizationScope SynchScope,
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr);
|
2011-07-28 21:48:00 +00:00
|
|
|
AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
|
|
|
|
AtomicOrdering Ordering, SynchronizationScope SynchScope,
|
|
|
|
BasicBlock *InsertAtEnd);
|
|
|
|
|
|
|
|
BinOp getOperation() const {
|
|
|
|
return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setOperation(BinOp Operation) {
|
|
|
|
unsigned short SubclassData = getSubclassDataFromInstruction();
|
|
|
|
setInstructionSubclassData((SubclassData & 31) |
|
|
|
|
(Operation << 5));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// isVolatile - Return true if this is a RMW on a volatile memory location.
|
|
|
|
///
|
|
|
|
bool isVolatile() const {
|
|
|
|
return getSubclassDataFromInstruction() & 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// setVolatile - Specify whether this is a volatile RMW or not.
|
|
|
|
///
|
|
|
|
void setVolatile(bool V) {
|
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
|
|
|
|
(unsigned)V);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Transparently provide more efficient getOperand methods.
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
|
|
|
|
|
|
|
/// Set the ordering constraint on this RMW.
|
|
|
|
void setOrdering(AtomicOrdering Ordering) {
|
|
|
|
assert(Ordering != NotAtomic &&
|
|
|
|
"atomicrmw instructions can only be atomic.");
|
2011-08-09 23:02:53 +00:00
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) |
|
2011-07-28 21:48:00 +00:00
|
|
|
(Ordering << 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Specify whether this RMW orders other operations with respect to all
|
|
|
|
/// concurrently executing threads, or only with respect to signal handlers
|
|
|
|
/// executing in the same thread.
|
|
|
|
void setSynchScope(SynchronizationScope SynchScope) {
|
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~2) |
|
|
|
|
(SynchScope << 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the ordering constraint on this RMW.
|
|
|
|
AtomicOrdering getOrdering() const {
|
2011-08-09 23:02:53 +00:00
|
|
|
return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
|
2011-07-28 21:48:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns whether this RMW is atomic between threads or only within a
|
|
|
|
/// single thread.
|
|
|
|
SynchronizationScope getSynchScope() const {
|
|
|
|
return SynchronizationScope((getSubclassDataFromInstruction() & 2) >> 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *getPointerOperand() { return getOperand(0); }
|
|
|
|
const Value *getPointerOperand() const { return getOperand(0); }
|
|
|
|
static unsigned getPointerOperandIndex() { return 0U; }
|
|
|
|
|
|
|
|
Value *getValOperand() { return getOperand(1); }
|
|
|
|
const Value *getValOperand() const { return getOperand(1); }
|
|
|
|
|
2012-11-01 11:25:28 +00:00
|
|
|
/// \brief Returns the address space of the pointer operand.
|
2011-07-28 21:48:00 +00:00
|
|
|
unsigned getPointerAddressSpace() const {
|
2012-11-01 09:37:49 +00:00
|
|
|
return getPointerOperand()->getType()->getPointerAddressSpace();
|
2011-07-28 21:48:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::AtomicRMW;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
void Init(BinOp Operation, Value *Ptr, Value *Val,
|
|
|
|
AtomicOrdering Ordering, SynchronizationScope SynchScope);
|
|
|
|
// Shadow Instruction::setInstructionSubclassData with a private forwarding
|
|
|
|
// method so that subclasses cannot accidentally use it.
|
|
|
|
void setInstructionSubclassData(unsigned short D) {
|
|
|
|
Instruction::setInstructionSubclassData(D);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct OperandTraits<AtomicRMWInst>
|
|
|
|
: public FixedNumOperandTraits<AtomicRMWInst,2> {
|
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicRMWInst, Value)
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// GetElementPtrInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
Land the long talked about "type system rewrite" patch. This
patch brings numerous advantages to LLVM. One way to look at it
is through diffstat:
109 files changed, 3005 insertions(+), 5906 deletions(-)
Removing almost 3K lines of code is a good thing. Other advantages
include:
1. Value::getType() is a simple load that can be CSE'd, not a mutating
union-find operation.
2. Types a uniqued and never move once created, defining away PATypeHolder.
3. Structs can be "named" now, and their name is part of the identity that
uniques them. This means that the compiler doesn't merge them structurally
which makes the IR much less confusing.
4. Now that there is no way to get a cycle in a type graph without a named
struct type, "upreferences" go away.
5. Type refinement is completely gone, which should make LTO much MUCH faster
in some common cases with C++ code.
6. Types are now generally immutable, so we can use "Type *" instead
"const Type *" everywhere.
Downsides of this patch are that it removes some functions from the C API,
so people using those will have to upgrade to (not yet added) new API.
"LLVM 3.0" is the right time to do this.
There are still some cleanups pending after this, this patch is large enough
as-is.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134829 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-09 17:41:24 +00:00
|
|
|
// checkGEPType - Simple wrapper function to give a better assertion failure
|
2007-09-04 15:46:09 +00:00
|
|
|
// message on bad indexes for a gep instruction.
|
|
|
|
//
|
2012-06-20 08:39:33 +00:00
|
|
|
inline Type *checkGEPType(Type *Ty) {
|
2007-09-04 15:46:09 +00:00
|
|
|
assert(Ty && "Invalid GetElementPtrInst indices for type!");
|
|
|
|
return Ty;
|
|
|
|
}
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
/// GetElementPtrInst - an instruction for type-safe pointer arithmetic to
|
|
|
|
/// access elements of arrays and structs
|
|
|
|
///
|
|
|
|
class GetElementPtrInst : public Instruction {
|
2008-05-10 08:32:32 +00:00
|
|
|
GetElementPtrInst(const GetElementPtrInst &GEPI);
|
2011-07-25 09:48:08 +00:00
|
|
|
void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
|
2007-09-04 15:46:09 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
/// Constructors - Create a getelementptr instruction with a base pointer an
|
2010-10-27 07:39:54 +00:00
|
|
|
/// list of indices. The first ctor can optionally insert before an existing
|
2004-07-29 12:17:34 +00:00
|
|
|
/// instruction, the second appends the new instruction to the specified
|
|
|
|
/// BasicBlock.
|
2011-07-25 09:48:08 +00:00
|
|
|
inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
|
|
|
|
unsigned Values, const Twine &NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
Instruction *InsertBefore);
|
2011-07-25 09:48:08 +00:00
|
|
|
inline GetElementPtrInst(Value *Ptr, ArrayRef<Value *> IdxList,
|
|
|
|
unsigned Values, const Twine &NameStr,
|
|
|
|
BasicBlock *InsertAtEnd);
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
GetElementPtrInst *clone_impl() const override;
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
2011-07-25 09:48:08 +00:00
|
|
|
static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr) {
|
2011-07-25 09:48:08 +00:00
|
|
|
unsigned Values = 1 + unsigned(IdxList.size());
|
2008-05-10 08:32:32 +00:00
|
|
|
return new(Values)
|
2011-07-25 09:48:08 +00:00
|
|
|
GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2011-07-25 09:48:08 +00:00
|
|
|
static GetElementPtrInst *Create(Value *Ptr, ArrayRef<Value *> IdxList,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
2011-07-25 09:48:08 +00:00
|
|
|
unsigned Values = 1 + unsigned(IdxList.size());
|
2008-05-10 08:32:32 +00:00
|
|
|
return new(Values)
|
2011-07-25 09:48:08 +00:00
|
|
|
GetElementPtrInst(Ptr, IdxList, Values, NameStr, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2009-08-11 17:57:01 +00:00
|
|
|
/// Create an "inbounds" getelementptr. See the documentation for the
|
|
|
|
/// "inbounds" flag in LangRef.html for details.
|
2010-10-27 07:39:54 +00:00
|
|
|
static GetElementPtrInst *CreateInBounds(Value *Ptr,
|
2011-07-25 09:48:08 +00:00
|
|
|
ArrayRef<Value *> IdxList,
|
2009-08-11 17:57:01 +00:00
|
|
|
const Twine &NameStr = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr){
|
2011-07-25 09:48:08 +00:00
|
|
|
GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertBefore);
|
2009-09-07 23:54:19 +00:00
|
|
|
GEP->setIsInBounds(true);
|
2009-08-11 17:57:01 +00:00
|
|
|
return GEP;
|
|
|
|
}
|
|
|
|
static GetElementPtrInst *CreateInBounds(Value *Ptr,
|
2011-07-25 09:48:08 +00:00
|
|
|
ArrayRef<Value *> IdxList,
|
2009-08-11 17:57:01 +00:00
|
|
|
const Twine &NameStr,
|
|
|
|
BasicBlock *InsertAtEnd) {
|
2011-07-25 09:48:08 +00:00
|
|
|
GetElementPtrInst *GEP = Create(Ptr, IdxList, NameStr, InsertAtEnd);
|
2009-09-07 23:54:19 +00:00
|
|
|
GEP->setIsInBounds(true);
|
2009-08-11 17:57:01 +00:00
|
|
|
return GEP;
|
|
|
|
}
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
|
|
|
|
2013-02-18 18:49:44 +00:00
|
|
|
// getType - Overload to return most specific sequential type.
|
|
|
|
SequentialType *getType() const {
|
|
|
|
return cast<SequentialType>(Instruction::getType());
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
2012-11-01 11:25:55 +00:00
|
|
|
/// \brief Returns the address space of this instruction's pointer type.
|
|
|
|
unsigned getAddressSpace() const {
|
|
|
|
// Note that this is always the same as the pointer operand's address space
|
|
|
|
// and that is cheaper to compute, so cheat here.
|
|
|
|
return getPointerAddressSpace();
|
|
|
|
}
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
/// getIndexedType - Returns the type of the element that would be loaded with
|
|
|
|
/// a load instruction with the specified parameters.
|
|
|
|
///
|
2008-05-15 23:35:32 +00:00
|
|
|
/// Null is returned if the indices are invalid for the specified
|
2004-07-29 12:17:34 +00:00
|
|
|
/// pointer type.
|
|
|
|
///
|
2011-07-25 09:48:08 +00:00
|
|
|
static Type *getIndexedType(Type *Ptr, ArrayRef<Value *> IdxList);
|
|
|
|
static Type *getIndexedType(Type *Ptr, ArrayRef<Constant *> IdxList);
|
|
|
|
static Type *getIndexedType(Type *Ptr, ArrayRef<uint64_t> IdxList);
|
2005-04-21 20:19:05 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
inline op_iterator idx_begin() { return op_begin()+1; }
|
|
|
|
inline const_op_iterator idx_begin() const { return op_begin()+1; }
|
|
|
|
inline op_iterator idx_end() { return op_end(); }
|
|
|
|
inline const_op_iterator idx_end() const { return op_end(); }
|
|
|
|
|
|
|
|
Value *getPointerOperand() {
|
|
|
|
return getOperand(0);
|
|
|
|
}
|
|
|
|
const Value *getPointerOperand() const {
|
|
|
|
return getOperand(0);
|
|
|
|
}
|
|
|
|
static unsigned getPointerOperandIndex() {
|
2011-12-05 06:29:09 +00:00
|
|
|
return 0U; // get index for modifying correct operand.
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-01-09 05:27:40 +00:00
|
|
|
/// getPointerOperandType - Method to return the pointer operand as a
|
|
|
|
/// PointerType.
|
2011-12-05 06:29:09 +00:00
|
|
|
Type *getPointerOperandType() const {
|
|
|
|
return getPointerOperand()->getType();
|
2009-01-09 05:27:40 +00:00
|
|
|
}
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2012-11-01 11:25:28 +00:00
|
|
|
/// \brief Returns the address space of the pointer operand.
|
2012-11-01 10:59:30 +00:00
|
|
|
unsigned getPointerAddressSpace() const {
|
|
|
|
return getPointerOperandType()->getPointerAddressSpace();
|
|
|
|
}
|
|
|
|
|
2011-12-05 06:29:09 +00:00
|
|
|
/// GetGEPReturnType - Returns the pointer type returned by the GEP
|
|
|
|
/// instruction, which may be a vector of pointers.
|
|
|
|
static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) {
|
|
|
|
Type *PtrTy = PointerType::get(checkGEPType(
|
|
|
|
getIndexedType(Ptr->getType(), IdxList)),
|
2012-11-01 10:59:30 +00:00
|
|
|
Ptr->getType()->getPointerAddressSpace());
|
2011-12-05 06:29:09 +00:00
|
|
|
// Vector GEP
|
|
|
|
if (Ptr->getType()->isVectorTy()) {
|
|
|
|
unsigned NumElem = cast<VectorType>(Ptr->getType())->getNumElements();
|
|
|
|
return VectorType::get(PtrTy, NumElem);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scalar GEP
|
|
|
|
return PtrTy;
|
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2008-02-23 01:11:02 +00:00
|
|
|
unsigned getNumIndices() const { // Note: always non-negative
|
2004-07-29 12:17:34 +00:00
|
|
|
return getNumOperands() - 1;
|
|
|
|
}
|
2005-04-21 20:19:05 +00:00
|
|
|
|
2008-02-23 01:11:02 +00:00
|
|
|
bool hasIndices() const {
|
2004-07-29 12:17:34 +00:00
|
|
|
return getNumOperands() > 1;
|
|
|
|
}
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2007-04-14 00:12:57 +00:00
|
|
|
/// hasAllZeroIndices - Return true if all of the indices of this GEP are
|
|
|
|
/// zeros. If so, the result pointer and the first operand have the same
|
|
|
|
/// value, just potentially different types.
|
|
|
|
bool hasAllZeroIndices() const;
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2007-04-27 20:35:56 +00:00
|
|
|
/// hasAllConstantIndices - Return true if all of the indices of this GEP are
|
|
|
|
/// constant integers. If so, the result pointer and the first operand have
|
|
|
|
/// a constant offset between them.
|
|
|
|
bool hasAllConstantIndices() const;
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2009-09-07 23:54:19 +00:00
|
|
|
/// setIsInBounds - Set or clear the inbounds flag on this GEP instruction.
|
|
|
|
/// See LangRef.html for the meaning of inbounds on a getelementptr.
|
2009-09-27 21:33:04 +00:00
|
|
|
void setIsInBounds(bool b = true);
|
|
|
|
|
|
|
|
/// isInBounds - Determine whether the GEP has the inbounds flag.
|
|
|
|
bool isInBounds() const;
|
2009-09-07 23:54:19 +00:00
|
|
|
|
2012-12-11 10:29:10 +00:00
|
|
|
/// \brief Accumulate the constant address offset of this GEP if possible.
|
|
|
|
///
|
|
|
|
/// This routine accepts an APInt into which it will accumulate the constant
|
|
|
|
/// offset of this GEP if the GEP is in fact constant. If the GEP is not
|
|
|
|
/// all-constant, it returns false and the value of the offset APInt is
|
|
|
|
/// undefined (it is *not* preserved!). The APInt passed into this routine
|
|
|
|
/// must be at least as wide as the IntPtr type for the address space of
|
|
|
|
/// the base GEP pointer.
|
|
|
|
bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const;
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::GetElementPtr);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2011-01-11 15:07:38 +00:00
|
|
|
struct OperandTraits<GetElementPtrInst> :
|
|
|
|
public VariadicOperandTraits<GetElementPtrInst, 1> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GetElementPtrInst::GetElementPtrInst(Value *Ptr,
|
2011-07-25 09:48:08 +00:00
|
|
|
ArrayRef<Value *> IdxList,
|
2008-05-10 08:32:32 +00:00
|
|
|
unsigned Values,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
Instruction *InsertBefore)
|
2011-12-05 06:29:09 +00:00
|
|
|
: Instruction(getGEPReturnType(Ptr, IdxList),
|
2008-05-10 08:32:32 +00:00
|
|
|
GetElementPtr,
|
|
|
|
OperandTraits<GetElementPtrInst>::op_end(this) - Values,
|
|
|
|
Values, InsertBefore) {
|
2011-07-25 09:48:08 +00:00
|
|
|
init(Ptr, IdxList, NameStr);
|
2008-05-10 08:32:32 +00:00
|
|
|
}
|
|
|
|
GetElementPtrInst::GetElementPtrInst(Value *Ptr,
|
2011-07-25 09:48:08 +00:00
|
|
|
ArrayRef<Value *> IdxList,
|
2008-05-10 08:32:32 +00:00
|
|
|
unsigned Values,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
BasicBlock *InsertAtEnd)
|
2011-12-05 06:29:09 +00:00
|
|
|
: Instruction(getGEPReturnType(Ptr, IdxList),
|
2008-05-10 08:32:32 +00:00
|
|
|
GetElementPtr,
|
|
|
|
OperandTraits<GetElementPtrInst>::op_end(this) - Values,
|
|
|
|
Values, InsertAtEnd) {
|
2011-07-25 09:48:08 +00:00
|
|
|
init(Ptr, IdxList, NameStr);
|
2008-05-10 08:32:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
|
|
|
|
|
|
|
|
|
2006-11-20 01:22:35 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ICmpInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// This instruction compares its operands according to the predicate given
|
2008-05-12 19:01:56 +00:00
|
|
|
/// to the constructor. It only operates on integers or pointers. The operands
|
|
|
|
/// must be identical types.
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Represent an integer comparison operator.
|
2006-11-20 01:22:35 +00:00
|
|
|
class ICmpInst: public CmpInst {
|
2013-10-08 21:11:12 +00:00
|
|
|
void AssertOK() {
|
|
|
|
assert(getPredicate() >= CmpInst::FIRST_ICMP_PREDICATE &&
|
|
|
|
getPredicate() <= CmpInst::LAST_ICMP_PREDICATE &&
|
|
|
|
"Invalid ICmp predicate value");
|
|
|
|
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
|
|
|
|
"Both operands to ICmp instruction are not of the same type!");
|
|
|
|
// Check that the operands are the right type
|
|
|
|
assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||
|
|
|
|
getOperand(0)->getType()->isPtrOrPtrVectorTy()) &&
|
|
|
|
"Invalid operand types for ICmp instruction");
|
|
|
|
}
|
|
|
|
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Clone an identical ICmpInst
|
2014-03-05 06:35:38 +00:00
|
|
|
ICmpInst *clone_impl() const override;
|
2006-11-20 01:22:35 +00:00
|
|
|
public:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-before-instruction semantics.
|
2006-11-20 01:22:35 +00:00
|
|
|
ICmpInst(
|
2009-07-09 23:48:35 +00:00
|
|
|
Instruction *InsertBefore, ///< Where to insert
|
2006-11-20 01:22:35 +00:00
|
|
|
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
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "" ///< Name of the instruction
|
2009-07-29 22:17:13 +00:00
|
|
|
) : CmpInst(makeCmpResultType(LHS->getType()),
|
2008-09-09 01:02:47 +00:00
|
|
|
Instruction::ICmp, pred, LHS, RHS, NameStr,
|
2008-05-12 19:01:56 +00:00
|
|
|
InsertBefore) {
|
2013-10-08 21:11:12 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
AssertOK();
|
|
|
|
#endif
|
2006-11-20 01:22:35 +00:00
|
|
|
}
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-at-end semantics.
|
2009-07-09 23:48:35 +00:00
|
|
|
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
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "" ///< Name of the instruction
|
2009-07-29 22:17:13 +00:00
|
|
|
) : CmpInst(makeCmpResultType(LHS->getType()),
|
2009-07-09 23:48:35 +00:00
|
|
|
Instruction::ICmp, pred, LHS, RHS, NameStr,
|
|
|
|
&InsertAtEnd) {
|
2013-10-08 21:11:12 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
AssertOK();
|
|
|
|
#endif
|
2009-07-09 23:48:35 +00:00
|
|
|
}
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with no-insertion semantics
|
2006-11-20 01:22:35 +00:00
|
|
|
ICmpInst(
|
|
|
|
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
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "" ///< Name of the instruction
|
2009-07-29 22:17:13 +00:00
|
|
|
) : CmpInst(makeCmpResultType(LHS->getType()),
|
2009-07-09 23:48:35 +00:00
|
|
|
Instruction::ICmp, pred, LHS, RHS, NameStr) {
|
2013-10-08 21:11:12 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
AssertOK();
|
|
|
|
#endif
|
2006-11-20 01:22:35 +00:00
|
|
|
}
|
|
|
|
|
2006-12-23 06:05:41 +00:00
|
|
|
/// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
|
|
|
|
/// @returns the predicate that would be the result if the operand were
|
|
|
|
/// regarded as signed.
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Return the signed version of the predicate
|
2006-12-23 06:05:41 +00:00
|
|
|
Predicate getSignedPredicate() const {
|
|
|
|
return getSignedPredicate(getPredicate());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This is a static version that you can use without an instruction.
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Return the signed version of the predicate.
|
2006-12-23 06:05:41 +00:00
|
|
|
static Predicate getSignedPredicate(Predicate pred);
|
2006-11-20 01:22:35 +00:00
|
|
|
|
2008-01-28 03:48:02 +00:00
|
|
|
/// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
|
|
|
|
/// @returns the predicate that would be the result if the operand were
|
|
|
|
/// regarded as unsigned.
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Return the unsigned version of the predicate
|
2008-01-28 03:48:02 +00:00
|
|
|
Predicate getUnsignedPredicate() const {
|
|
|
|
return getUnsignedPredicate(getPredicate());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This is a static version that you can use without an instruction.
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Return the unsigned version of the predicate.
|
2008-01-28 03:48:02 +00:00
|
|
|
static Predicate getUnsignedPredicate(Predicate pred);
|
|
|
|
|
2007-11-22 23:43:29 +00:00
|
|
|
/// isEquality - Return true if this predicate is either EQ or NE. This also
|
|
|
|
/// tests for commutativity.
|
|
|
|
static bool isEquality(Predicate P) {
|
|
|
|
return P == ICMP_EQ || P == ICMP_NE;
|
|
|
|
}
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2007-11-22 23:43:29 +00:00
|
|
|
/// isEquality - Return true if this predicate is either EQ or NE. This also
|
|
|
|
/// tests for commutativity.
|
2006-11-20 01:22:35 +00:00
|
|
|
bool isEquality() const {
|
2007-11-22 23:43:29 +00:00
|
|
|
return isEquality(getPredicate());
|
2006-11-20 01:22:35 +00:00
|
|
|
}
|
2006-12-23 06:05:41 +00:00
|
|
|
|
|
|
|
/// @returns true if the predicate of this ICmpInst is commutative
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Determine if this relation is commutative.
|
2006-11-20 01:22:35 +00:00
|
|
|
bool isCommutative() const { return isEquality(); }
|
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
/// isRelational - Return true if the predicate is relational (not EQ or NE).
|
2007-11-22 23:43:29 +00:00
|
|
|
///
|
2006-11-20 01:22:35 +00:00
|
|
|
bool isRelational() const {
|
|
|
|
return !isEquality();
|
|
|
|
}
|
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
/// isRelational - Return true if the predicate is relational (not EQ or NE).
|
2007-11-22 23:43:29 +00:00
|
|
|
///
|
|
|
|
static bool isRelational(Predicate P) {
|
|
|
|
return !isEquality(P);
|
|
|
|
}
|
2009-02-09 17:11:05 +00:00
|
|
|
|
|
|
|
/// Initialize a set of values that all satisfy the predicate with C.
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Make a ConstantRange for a relation with a constant value.
|
2007-02-28 22:00:54 +00:00
|
|
|
static ConstantRange makeConstantRange(Predicate pred, const APInt &C);
|
|
|
|
|
2006-11-20 01:22:35 +00:00
|
|
|
/// Exchange the two operands to this instruction in such a way that it does
|
|
|
|
/// not modify the semantics of the instruction. The predicate value may be
|
|
|
|
/// changed to retain the same result if the predicate is order dependent
|
2009-02-09 17:11:05 +00:00
|
|
|
/// (e.g. ult).
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Swap operands and adjust predicate.
|
2006-11-20 01:22:35 +00:00
|
|
|
void swapOperands() {
|
2009-12-29 02:14:09 +00:00
|
|
|
setPredicate(getSwappedPredicate());
|
2008-05-13 22:51:52 +00:00
|
|
|
Op<0>().swap(Op<1>());
|
2006-11-20 01:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::ICmp;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2008-09-09 01:02:47 +00:00
|
|
|
|
2006-11-20 01:22:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FCmpInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// This instruction compares its operands according to the predicate given
|
2009-02-09 17:11:05 +00:00
|
|
|
/// to the constructor. It only operates on floating point values or packed
|
2006-11-20 01:22:35 +00:00
|
|
|
/// vectors of floating point values. The operands must be identical types.
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Represents a floating point comparison operator.
|
2006-11-20 01:22:35 +00:00
|
|
|
class FCmpInst: public CmpInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Clone an identical FCmpInst
|
2014-03-05 06:35:38 +00:00
|
|
|
FCmpInst *clone_impl() const override;
|
2006-11-20 01:22:35 +00:00
|
|
|
public:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-before-instruction semantics.
|
2006-11-20 01:22:35 +00:00
|
|
|
FCmpInst(
|
2009-07-09 23:48:35 +00:00
|
|
|
Instruction *InsertBefore, ///< Where to insert
|
2006-11-20 01:22:35 +00:00
|
|
|
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
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "" ///< Name of the instruction
|
2009-07-29 22:17:13 +00:00
|
|
|
) : CmpInst(makeCmpResultType(LHS->getType()),
|
2008-09-09 01:02:47 +00:00
|
|
|
Instruction::FCmp, pred, LHS, RHS, NameStr,
|
2008-05-12 19:01:56 +00:00
|
|
|
InsertBefore) {
|
|
|
|
assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
|
|
|
|
"Invalid FCmp predicate value");
|
2008-05-14 20:28:31 +00:00
|
|
|
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
|
2008-05-12 19:01:56 +00:00
|
|
|
"Both operands to FCmp instruction are not of the same type!");
|
|
|
|
// Check that the operands are the right type
|
2010-02-15 16:12:20 +00:00
|
|
|
assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
|
2008-05-12 19:01:56 +00:00
|
|
|
"Invalid operand types for FCmp instruction");
|
2006-11-20 01:22:35 +00:00
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-at-end semantics.
|
2009-07-09 23:48:35 +00:00
|
|
|
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
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "" ///< Name of the instruction
|
2009-07-29 22:17:13 +00:00
|
|
|
) : CmpInst(makeCmpResultType(LHS->getType()),
|
2009-07-09 23:48:35 +00:00
|
|
|
Instruction::FCmp, pred, LHS, RHS, NameStr,
|
|
|
|
&InsertAtEnd) {
|
|
|
|
assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
|
|
|
|
"Invalid FCmp predicate value");
|
|
|
|
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
|
|
|
|
"Both operands to FCmp instruction are not of the same type!");
|
|
|
|
// Check that the operands are the right type
|
2010-02-15 16:12:20 +00:00
|
|
|
assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
|
2009-07-09 23:48:35 +00:00
|
|
|
"Invalid operand types for FCmp instruction");
|
|
|
|
}
|
2006-11-20 01:22:35 +00:00
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with no-insertion semantics
|
2006-11-20 01:22:35 +00:00
|
|
|
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
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "" ///< Name of the instruction
|
2009-07-29 22:17:13 +00:00
|
|
|
) : CmpInst(makeCmpResultType(LHS->getType()),
|
2009-07-09 23:48:35 +00:00
|
|
|
Instruction::FCmp, pred, LHS, RHS, NameStr) {
|
2008-05-12 19:01:56 +00:00
|
|
|
assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
|
|
|
|
"Invalid FCmp predicate value");
|
2008-05-14 20:28:31 +00:00
|
|
|
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
|
2008-05-12 19:01:56 +00:00
|
|
|
"Both operands to FCmp instruction are not of the same type!");
|
|
|
|
// Check that the operands are the right type
|
2010-02-15 16:12:20 +00:00
|
|
|
assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&
|
2008-05-12 19:01:56 +00:00
|
|
|
"Invalid operand types for FCmp instruction");
|
2006-11-20 01:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @returns true if the predicate of this instruction is EQ or NE.
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Determine if this is an equality predicate.
|
2006-11-20 01:22:35 +00:00
|
|
|
bool isEquality() const {
|
2009-12-29 02:14:09 +00:00
|
|
|
return getPredicate() == FCMP_OEQ || getPredicate() == FCMP_ONE ||
|
|
|
|
getPredicate() == FCMP_UEQ || getPredicate() == FCMP_UNE;
|
2006-11-20 01:22:35 +00:00
|
|
|
}
|
2008-09-16 16:44:00 +00:00
|
|
|
|
|
|
|
/// @returns true if the predicate of this instruction is commutative.
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Determine if this is a commutative predicate.
|
2008-09-16 16:44:00 +00:00
|
|
|
bool isCommutative() const {
|
|
|
|
return isEquality() ||
|
2009-12-29 02:14:09 +00:00
|
|
|
getPredicate() == FCMP_FALSE ||
|
|
|
|
getPredicate() == FCMP_TRUE ||
|
|
|
|
getPredicate() == FCMP_ORD ||
|
|
|
|
getPredicate() == FCMP_UNO;
|
2008-09-16 16:44:00 +00:00
|
|
|
}
|
2006-11-20 01:22:35 +00:00
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
/// @returns true if the predicate is relational (not EQ or NE).
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Determine if this a relational predicate.
|
2006-11-20 01:22:35 +00:00
|
|
|
bool isRelational() const { return !isEquality(); }
|
|
|
|
|
|
|
|
/// Exchange the two operands to this instruction in such a way that it does
|
|
|
|
/// not modify the semantics of the instruction. The predicate value may be
|
|
|
|
/// changed to retain the same result if the predicate is order dependent
|
2009-02-09 17:11:05 +00:00
|
|
|
/// (e.g. ult).
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Swap operands and adjust predicate.
|
2006-11-20 01:22:35 +00:00
|
|
|
void swapOperands() {
|
2009-12-29 02:14:09 +00:00
|
|
|
setPredicate(getSwappedPredicate());
|
2008-05-13 22:51:52 +00:00
|
|
|
Op<0>().swap(Op<1>());
|
2006-11-20 01:22:35 +00:00
|
|
|
}
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
2006-11-20 01:22:35 +00:00
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::FCmp;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// CallInst - This class represents a function call, abstracting a target
|
2005-05-06 20:26:26 +00:00
|
|
|
/// machine's calling convention. This class uses low bit of the SubClassData
|
|
|
|
/// field to indicate whether or not this is a tail call. The rest of the bits
|
|
|
|
/// hold the calling convention of the call.
|
2004-07-29 12:17:34 +00:00
|
|
|
///
|
|
|
|
class CallInst : public Instruction {
|
2012-12-07 23:16:57 +00:00
|
|
|
AttributeSet AttributeList; ///< parameter attributes for call
|
2004-07-29 12:17:34 +00:00
|
|
|
CallInst(const CallInst &CI);
|
2011-07-15 08:37:34 +00:00
|
|
|
void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr);
|
|
|
|
void init(Value *Func, const Twine &NameStr);
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2011-07-15 08:37:34 +00:00
|
|
|
/// Construct a CallInst given a range of arguments.
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Construct a CallInst from a range of arguments
|
2011-07-15 08:37:34 +00:00
|
|
|
inline CallInst(Value *Func, ArrayRef<Value *> Args,
|
|
|
|
const Twine &NameStr, Instruction *InsertBefore);
|
|
|
|
|
|
|
|
/// Construct a CallInst given a range of arguments.
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Construct a CallInst from a range of arguments
|
2011-07-15 08:37:34 +00:00
|
|
|
inline CallInst(Value *Func, ArrayRef<Value *> Args,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd);
|
2007-08-01 03:43:44 +00:00
|
|
|
|
2009-07-25 04:41:11 +00:00
|
|
|
explicit CallInst(Value *F, const Twine &NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
Instruction *InsertBefore);
|
2009-07-25 04:41:11 +00:00
|
|
|
CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
CallInst *clone_impl() const override;
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
2008-05-10 08:32:32 +00:00
|
|
|
static CallInst *Create(Value *Func,
|
2011-07-15 08:37:34 +00:00
|
|
|
ArrayRef<Value *> Args,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr) {
|
2011-07-15 08:37:34 +00:00
|
|
|
return new(unsigned(Args.size() + 1))
|
|
|
|
CallInst(Func, Args, NameStr, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2008-05-10 08:32:32 +00:00
|
|
|
static CallInst *Create(Value *Func,
|
2011-07-15 08:37:34 +00:00
|
|
|
ArrayRef<Value *> Args,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd) {
|
2011-07-15 08:37:34 +00:00
|
|
|
return new(unsigned(Args.size() + 1))
|
|
|
|
CallInst(Func, Args, NameStr, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2009-07-25 04:41:11 +00:00
|
|
|
static CallInst *Create(Value *F, const Twine &NameStr = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr) {
|
2008-07-24 00:08:56 +00:00
|
|
|
return new(1) CallInst(F, NameStr, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2009-07-25 04:41:11 +00:00
|
|
|
static CallInst *Create(Value *F, const Twine &NameStr,
|
2008-05-05 18:30:58 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
2008-07-24 00:08:56 +00:00
|
|
|
return new(1) CallInst(F, NameStr, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2009-09-10 04:36:43 +00:00
|
|
|
/// CreateMalloc - Generate the IR for a call to malloc:
|
|
|
|
/// 1. Compute the malloc call's argument as the specified type's size,
|
|
|
|
/// possibly multiplied by the array size if the array size is not
|
|
|
|
/// constant 1.
|
|
|
|
/// 2. Call malloc with that argument.
|
|
|
|
/// 3. Bitcast the result of the malloc call to the specified type.
|
2009-10-17 23:52:26 +00:00
|
|
|
static Instruction *CreateMalloc(Instruction *InsertBefore,
|
2011-07-18 04:54:35 +00:00
|
|
|
Type *IntPtrTy, Type *AllocTy,
|
2014-04-09 06:08:46 +00:00
|
|
|
Value *AllocSize, Value *ArraySize = nullptr,
|
|
|
|
Function* MallocF = nullptr,
|
2009-10-17 23:52:26 +00:00
|
|
|
const Twine &Name = "");
|
|
|
|
static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
|
2011-07-18 04:54:35 +00:00
|
|
|
Type *IntPtrTy, Type *AllocTy,
|
2014-04-09 06:08:46 +00:00
|
|
|
Value *AllocSize, Value *ArraySize = nullptr,
|
|
|
|
Function* MallocF = nullptr,
|
2009-10-17 23:52:26 +00:00
|
|
|
const Twine &Name = "");
|
2009-10-24 04:23:03 +00:00
|
|
|
/// CreateFree - Generate the IR for a call to the builtin free function.
|
2010-07-12 00:57:28 +00:00
|
|
|
static Instruction* CreateFree(Value* Source, Instruction *InsertBefore);
|
2009-10-24 04:23:03 +00:00
|
|
|
static Instruction* CreateFree(Value* Source, BasicBlock *InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
|
2007-12-10 02:14:30 +00:00
|
|
|
~CallInst();
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2014-04-24 20:14:34 +00:00
|
|
|
// Note that 'musttail' implies 'tail'.
|
|
|
|
enum TailCallKind { TCK_None = 0, TCK_Tail = 1, TCK_MustTail = 2 };
|
|
|
|
TailCallKind getTailCallKind() const {
|
|
|
|
return TailCallKind(getSubclassDataFromInstruction() & 3);
|
|
|
|
}
|
|
|
|
bool isTailCall() const {
|
|
|
|
return (getSubclassDataFromInstruction() & 3) != TCK_None;
|
|
|
|
}
|
|
|
|
bool isMustTailCall() const {
|
|
|
|
return (getSubclassDataFromInstruction() & 3) == TCK_MustTail;
|
|
|
|
}
|
2008-07-24 00:08:56 +00:00
|
|
|
void setTailCall(bool isTC = true) {
|
2014-04-24 20:14:34 +00:00
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
|
|
|
|
unsigned(isTC ? TCK_Tail : TCK_None));
|
|
|
|
}
|
|
|
|
void setTailCallKind(TailCallKind TCK) {
|
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
|
|
|
|
unsigned(TCK));
|
2005-05-06 20:26:26 +00:00
|
|
|
}
|
|
|
|
|
2008-09-26 21:38:45 +00:00
|
|
|
/// Provide fast operand accessors
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2010-07-31 08:35:21 +00:00
|
|
|
/// getNumArgOperands - Return the number of call arguments.
|
|
|
|
///
|
2010-06-07 19:05:06 +00:00
|
|
|
unsigned getNumArgOperands() const { return getNumOperands() - 1; }
|
2010-07-31 08:35:21 +00:00
|
|
|
|
|
|
|
/// getArgOperand/setArgOperand - Return/set the i-th call argument.
|
|
|
|
///
|
2010-07-16 09:38:02 +00:00
|
|
|
Value *getArgOperand(unsigned i) const { return getOperand(i); }
|
|
|
|
void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
|
2010-06-07 19:05:06 +00:00
|
|
|
|
2014-03-26 18:18:02 +00:00
|
|
|
/// arg_operands - iteration adapter for range-for loops.
|
|
|
|
iterator_range<op_iterator> arg_operands() {
|
2014-03-26 20:41:15 +00:00
|
|
|
// The last operand in the op list is the callee - it's not one of the args
|
|
|
|
// so we don't want to iterate over it.
|
|
|
|
return iterator_range<op_iterator>(op_begin(), op_end() - 1);
|
2014-03-26 18:18:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// arg_operands - iteration adapter for range-for loops.
|
|
|
|
iterator_range<const_op_iterator> arg_operands() const {
|
2014-03-26 20:41:15 +00:00
|
|
|
return iterator_range<const_op_iterator>(op_begin(), op_end() - 1);
|
2014-03-26 18:18:02 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 03:34:17 +00:00
|
|
|
/// \brief Wrappers for getting the \c Use of a call argument.
|
|
|
|
const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
|
|
|
|
Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
|
|
|
|
|
2005-05-06 20:26:26 +00:00
|
|
|
/// getCallingConv/setCallingConv - Get or set the calling convention of this
|
|
|
|
/// function call.
|
2009-09-02 08:44:58 +00:00
|
|
|
CallingConv::ID getCallingConv() const {
|
2014-04-24 20:14:34 +00:00
|
|
|
return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 2);
|
2009-09-02 08:44:58 +00:00
|
|
|
}
|
|
|
|
void setCallingConv(CallingConv::ID CC) {
|
2014-04-24 20:14:34 +00:00
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & 3) |
|
|
|
|
(static_cast<unsigned>(CC) << 2));
|
2005-05-06 20:26:26 +00:00
|
|
|
}
|
2005-05-06 05:51:46 +00:00
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// getAttributes - Return the parameter attributes for this call.
|
2008-03-13 04:33:03 +00:00
|
|
|
///
|
2012-12-07 23:16:57 +00:00
|
|
|
const AttributeSet &getAttributes() const { return AttributeList; }
|
2007-04-09 15:01:12 +00:00
|
|
|
|
2008-09-26 21:38:45 +00:00
|
|
|
/// setAttributes - Set the parameter attributes for this call.
|
|
|
|
///
|
2012-12-07 23:16:57 +00:00
|
|
|
void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// addAttribute - adds the attribute to the list of attributes.
|
2013-03-02 01:20:18 +00:00
|
|
|
void addAttribute(unsigned i, Attribute::AttrKind attr);
|
2007-11-27 13:23:08 +00:00
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// removeAttribute - removes the attribute from the list of attributes.
|
2012-12-19 07:18:57 +00:00
|
|
|
void removeAttribute(unsigned i, Attribute attr);
|
2008-07-08 08:38:44 +00:00
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Determine whether this call has the given attribute.
|
2013-06-27 00:25:01 +00:00
|
|
|
bool hasFnAttr(Attribute::AttrKind A) const {
|
|
|
|
assert(A != Attribute::NoBuiltin &&
|
|
|
|
"Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
|
|
|
|
return hasFnAttrImpl(A);
|
|
|
|
}
|
2012-10-09 00:28:54 +00:00
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Determine whether the call or the callee has the given attributes.
|
2012-12-22 00:37:52 +00:00
|
|
|
bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
|
2012-10-03 17:54:26 +00:00
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Extract the alignment for a call or parameter (0=unknown).
|
2008-03-13 05:00:21 +00:00
|
|
|
unsigned getParamAlignment(unsigned i) const {
|
2008-09-25 21:00:45 +00:00
|
|
|
return AttributeList.getParamAlignment(i);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2013-06-27 00:25:01 +00:00
|
|
|
/// \brief Return true if the call should not be treated as a call to a
|
|
|
|
/// builtin.
|
|
|
|
bool isNoBuiltin() const {
|
|
|
|
return hasFnAttrImpl(Attribute::NoBuiltin) &&
|
|
|
|
!hasFnAttrImpl(Attribute::Builtin);
|
|
|
|
}
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Return true if the call should not be inlined.
|
2012-12-19 07:18:57 +00:00
|
|
|
bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
|
2012-10-09 23:40:31 +00:00
|
|
|
void setIsNoInline() {
|
2013-03-02 01:20:18 +00:00
|
|
|
addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
|
2010-03-25 04:49:10 +00:00
|
|
|
}
|
2008-02-22 17:49:45 +00:00
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Return true if the call can return twice
|
2011-10-05 20:05:13 +00:00
|
|
|
bool canReturnTwice() const {
|
2012-12-19 07:18:57 +00:00
|
|
|
return hasFnAttr(Attribute::ReturnsTwice);
|
2011-10-05 20:05:13 +00:00
|
|
|
}
|
2012-10-09 23:40:31 +00:00
|
|
|
void setCanReturnTwice() {
|
2013-03-02 01:20:18 +00:00
|
|
|
addAttribute(AttributeSet::FunctionIndex, Attribute::ReturnsTwice);
|
2011-10-05 20:05:13 +00:00
|
|
|
}
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Determine if the call does not access memory.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool doesNotAccessMemory() const {
|
2012-12-19 07:18:57 +00:00
|
|
|
return hasFnAttr(Attribute::ReadNone);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2012-10-09 23:40:31 +00:00
|
|
|
void setDoesNotAccessMemory() {
|
2013-03-02 01:20:18 +00:00
|
|
|
addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
|
2008-07-08 08:38:44 +00:00
|
|
|
}
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Determine if the call does not access or only reads memory.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool onlyReadsMemory() const {
|
2012-12-19 07:18:57 +00:00
|
|
|
return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2012-10-09 23:40:31 +00:00
|
|
|
void setOnlyReadsMemory() {
|
2013-03-02 01:20:18 +00:00
|
|
|
addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
|
2008-07-08 08:38:44 +00:00
|
|
|
}
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Determine if the call cannot return.
|
2012-12-19 07:18:57 +00:00
|
|
|
bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
|
2012-10-09 23:40:31 +00:00
|
|
|
void setDoesNotReturn() {
|
2013-03-02 01:20:18 +00:00
|
|
|
addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
|
2008-07-08 08:38:44 +00:00
|
|
|
}
|
2007-12-10 19:09:40 +00:00
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Determine if the call cannot unwind.
|
2012-12-19 07:18:57 +00:00
|
|
|
bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
|
2012-10-10 18:02:57 +00:00
|
|
|
void setDoesNotThrow() {
|
2013-03-02 01:20:18 +00:00
|
|
|
addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
|
2008-07-08 08:38:44 +00:00
|
|
|
}
|
2007-12-03 20:06:50 +00:00
|
|
|
|
2012-12-20 16:04:27 +00:00
|
|
|
/// \brief Determine if the call cannot be duplicated.
|
|
|
|
bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
|
|
|
|
void setCannotDuplicate() {
|
2013-03-02 01:20:18 +00:00
|
|
|
addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
|
2012-12-20 16:04:27 +00:00
|
|
|
}
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Determine if the call returns a structure through first
|
2008-03-03 21:46:28 +00:00
|
|
|
/// pointer argument.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool hasStructRetAttr() const {
|
|
|
|
// Be friendly and also check the callee.
|
2012-12-19 07:18:57 +00:00
|
|
|
return paramHasAttr(1, Attribute::StructRet);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2007-04-09 15:01:12 +00:00
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Determine if any call argument is an aggregate passed by value.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool hasByValArgument() const {
|
2012-12-31 00:49:59 +00:00
|
|
|
return AttributeList.hasAttrSomewhere(Attribute::ByVal);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2008-01-12 18:57:32 +00:00
|
|
|
|
2008-09-26 21:38:45 +00:00
|
|
|
/// getCalledFunction - Return the function called, or null if this is an
|
|
|
|
/// indirect function invocation.
|
|
|
|
///
|
2004-11-18 17:46:57 +00:00
|
|
|
Function *getCalledFunction() const {
|
2010-07-16 09:38:02 +00:00
|
|
|
return dyn_cast<Function>(Op<-1>());
|
2004-11-18 17:46:57 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
/// getCalledValue - Get a pointer to the function that is invoked by this
|
2009-10-18 05:08:07 +00:00
|
|
|
/// instruction.
|
2010-07-16 09:38:02 +00:00
|
|
|
const Value *getCalledValue() const { return Op<-1>(); }
|
|
|
|
Value *getCalledValue() { return Op<-1>(); }
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2009-10-18 05:08:07 +00:00
|
|
|
/// setCalledFunction - Set the function called.
|
2009-10-17 00:00:19 +00:00
|
|
|
void setCalledFunction(Value* Fn) {
|
2010-07-16 09:38:02 +00:00
|
|
|
Op<-1>() = Fn;
|
2009-10-17 00:00:19 +00:00
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2010-08-07 00:19:59 +00:00
|
|
|
/// isInlineAsm - Check if this call is an inline asm statement.
|
|
|
|
bool isInlineAsm() const {
|
|
|
|
return isa<InlineAsm>(Op<-1>());
|
|
|
|
}
|
2009-10-17 00:00:19 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
2005-04-21 20:19:05 +00:00
|
|
|
return I->getOpcode() == Instruction::Call;
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2009-12-29 02:14:09 +00:00
|
|
|
private:
|
2013-06-27 00:25:01 +00:00
|
|
|
|
|
|
|
bool hasFnAttrImpl(Attribute::AttrKind A) const;
|
|
|
|
|
2009-12-29 02:46:09 +00:00
|
|
|
// Shadow Instruction::setInstructionSubclassData with a private forwarding
|
|
|
|
// method so that subclasses cannot accidentally use it.
|
|
|
|
void setInstructionSubclassData(unsigned short D) {
|
|
|
|
Instruction::setInstructionSubclassData(D);
|
2009-12-29 02:14:09 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2011-01-11 15:07:38 +00:00
|
|
|
struct OperandTraits<CallInst> : public VariadicOperandTraits<CallInst, 1> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
2011-07-15 08:37:34 +00:00
|
|
|
CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd)
|
2008-05-10 08:32:32 +00:00
|
|
|
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
|
|
|
|
->getElementType())->getReturnType(),
|
|
|
|
Instruction::Call,
|
2011-07-15 08:37:34 +00:00
|
|
|
OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
|
|
|
|
unsigned(Args.size() + 1), InsertAtEnd) {
|
|
|
|
init(Func, Args, NameStr);
|
2008-05-10 08:32:32 +00:00
|
|
|
}
|
|
|
|
|
2011-07-15 08:37:34 +00:00
|
|
|
CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, Instruction *InsertBefore)
|
2008-05-10 08:32:32 +00:00
|
|
|
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
|
|
|
|
->getElementType())->getReturnType(),
|
|
|
|
Instruction::Call,
|
2011-07-15 08:37:34 +00:00
|
|
|
OperandTraits<CallInst>::op_end(this) - (Args.size() + 1),
|
|
|
|
unsigned(Args.size() + 1), InsertBefore) {
|
|
|
|
init(Func, Args, NameStr);
|
2008-05-10 08:32:32 +00:00
|
|
|
}
|
|
|
|
|
2010-07-06 15:44:11 +00:00
|
|
|
|
|
|
|
// Note: if you get compile errors about private methods then
|
|
|
|
// please update your code to use the high-level operand
|
|
|
|
// interfaces. See line 943 above.
|
2008-05-10 08:32:32 +00:00
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CallInst, Value)
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// SelectInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// SelectInst - This class represents the LLVM 'select' instruction.
|
|
|
|
///
|
|
|
|
class SelectInst : public Instruction {
|
|
|
|
void init(Value *C, Value *S1, Value *S2) {
|
2008-12-29 00:12:50 +00:00
|
|
|
assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select");
|
2008-05-10 08:32:32 +00:00
|
|
|
Op<0>() = C;
|
|
|
|
Op<1>() = S1;
|
|
|
|
Op<2>() = S2;
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
2009-07-25 04:41:11 +00:00
|
|
|
SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
|
2008-05-10 08:32:32 +00:00
|
|
|
Instruction *InsertBefore)
|
|
|
|
: Instruction(S1->getType(), Instruction::Select,
|
|
|
|
&Op<0>(), 3, InsertBefore) {
|
2004-07-29 12:17:34 +00:00
|
|
|
init(C, S1, S2);
|
2008-07-24 00:08:56 +00:00
|
|
|
setName(NameStr);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2009-07-25 04:41:11 +00:00
|
|
|
SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
|
2004-07-29 12:17:34 +00:00
|
|
|
BasicBlock *InsertAtEnd)
|
2008-05-10 08:32:32 +00:00
|
|
|
: Instruction(S1->getType(), Instruction::Select,
|
|
|
|
&Op<0>(), 3, InsertAtEnd) {
|
2004-07-29 12:17:34 +00:00
|
|
|
init(C, S1, S2);
|
2008-07-24 00:08:56 +00:00
|
|
|
setName(NameStr);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
SelectInst *clone_impl() const override;
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
2008-05-05 17:41:03 +00:00
|
|
|
static SelectInst *Create(Value *C, Value *S1, Value *S2,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr) {
|
2008-07-24 00:08:56 +00:00
|
|
|
return new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2008-05-05 17:41:03 +00:00
|
|
|
static SelectInst *Create(Value *C, Value *S1, Value *S2,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-07-24 00:08:56 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
|
|
|
return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2009-09-08 03:32:53 +00:00
|
|
|
const Value *getCondition() const { return Op<0>(); }
|
|
|
|
const Value *getTrueValue() const { return Op<1>(); }
|
|
|
|
const Value *getFalseValue() const { return Op<2>(); }
|
|
|
|
Value *getCondition() { return Op<0>(); }
|
|
|
|
Value *getTrueValue() { return Op<1>(); }
|
|
|
|
Value *getFalseValue() { return Op<2>(); }
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2008-12-29 00:12:50 +00:00
|
|
|
/// areInvalidOperands - Return a string if the specified operands are invalid
|
|
|
|
/// for a select operation, otherwise return null.
|
|
|
|
static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
|
2005-01-29 00:31:36 +00:00
|
|
|
|
|
|
|
/// Transparently provide more efficient getOperand methods.
|
2008-05-10 08:32:32 +00:00
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
OtherOps getOpcode() const {
|
|
|
|
return static_cast<OtherOps>(Instruction::getOpcode());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::Select;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2011-01-11 15:07:38 +00:00
|
|
|
struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// VAArgInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// VAArgInst - This class represents the va_arg llvm instruction, which returns
|
2005-06-18 18:31:30 +00:00
|
|
|
/// an argument of the specified type given a va_list and increments that list
|
2004-07-29 12:17:34 +00:00
|
|
|
///
|
2005-01-29 00:31:36 +00:00
|
|
|
class VAArgInst : public UnaryInstruction {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
VAArgInst *clone_impl() const override;
|
2009-10-27 22:16:29 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
public:
|
2011-07-18 04:54:35 +00:00
|
|
|
VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr)
|
2007-02-24 00:55:48 +00:00
|
|
|
: UnaryInstruction(Ty, VAArg, List, InsertBefore) {
|
2008-07-24 00:08:56 +00:00
|
|
|
setName(NameStr);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2011-07-18 04:54:35 +00:00
|
|
|
VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
|
2004-07-29 12:17:34 +00:00
|
|
|
BasicBlock *InsertAtEnd)
|
2007-02-24 00:55:48 +00:00
|
|
|
: UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
|
2008-07-24 00:08:56 +00:00
|
|
|
setName(NameStr);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
2010-09-09 18:32:40 +00:00
|
|
|
Value *getPointerOperand() { return getOperand(0); }
|
|
|
|
const Value *getPointerOperand() const { return getOperand(0); }
|
|
|
|
static unsigned getPointerOperandIndex() { return 0U; }
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == VAArg;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-01-10 19:04:13 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ExtractElementInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// ExtractElementInst - This instruction extracts a single (scalar)
|
2007-02-15 02:26:10 +00:00
|
|
|
/// element from a VectorType value
|
2006-01-10 19:04:13 +00:00
|
|
|
///
|
|
|
|
class ExtractElementInst : public Instruction {
|
2009-07-25 04:41:11 +00:00
|
|
|
ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr);
|
2009-07-25 04:41:11 +00:00
|
|
|
ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
|
2006-04-08 01:15:18 +00:00
|
|
|
BasicBlock *InsertAtEnd);
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
ExtractElementInst *clone_impl() const override;
|
2009-10-27 22:16:29 +00:00
|
|
|
|
2009-07-25 02:28:41 +00:00
|
|
|
public:
|
|
|
|
static ExtractElementInst *Create(Value *Vec, Value *Idx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr) {
|
2009-07-25 02:28:41 +00:00
|
|
|
return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
|
|
|
|
}
|
|
|
|
static ExtractElementInst *Create(Value *Vec, Value *Idx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2009-07-25 02:28:41 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
|
|
|
return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
|
|
|
|
}
|
2006-01-10 19:04:13 +00:00
|
|
|
|
2006-04-08 04:04:54 +00:00
|
|
|
/// isValidOperands - Return true if an extractelement instruction can be
|
|
|
|
/// formed with the specified operands.
|
|
|
|
static bool isValidOperands(const Value *Vec, const Value *Idx);
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2009-09-08 03:32:53 +00:00
|
|
|
Value *getVectorOperand() { return Op<0>(); }
|
|
|
|
Value *getIndexOperand() { return Op<1>(); }
|
|
|
|
const Value *getVectorOperand() const { return Op<0>(); }
|
|
|
|
const Value *getIndexOperand() const { return Op<1>(); }
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2011-07-18 04:54:35 +00:00
|
|
|
VectorType *getVectorOperandType() const {
|
2013-02-18 18:49:44 +00:00
|
|
|
return cast<VectorType>(getVectorOperand()->getType());
|
2009-09-08 03:32:53 +00:00
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
|
|
|
|
2006-01-10 19:04:13 +00:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
2008-05-10 08:32:32 +00:00
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2006-01-10 19:04:13 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::ExtractElement;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2011-01-11 15:07:38 +00:00
|
|
|
struct OperandTraits<ExtractElementInst> :
|
|
|
|
public FixedNumOperandTraits<ExtractElementInst, 2> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)
|
|
|
|
|
2006-01-17 20:05:59 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// InsertElementInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// InsertElementInst - This instruction inserts a single (scalar)
|
2007-02-15 02:26:10 +00:00
|
|
|
/// element into a VectorType value
|
2006-01-17 20:05:59 +00:00
|
|
|
///
|
|
|
|
class InsertElementInst : public Instruction {
|
2006-04-08 01:15:18 +00:00
|
|
|
InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr);
|
2006-04-08 01:15:18 +00:00
|
|
|
InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd);
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
InsertElementInst *clone_impl() const override;
|
2009-10-27 22:16:29 +00:00
|
|
|
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
|
|
|
static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr) {
|
2008-07-24 00:08:56 +00:00
|
|
|
return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
|
|
|
static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-05 17:41:03 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
2008-07-24 00:08:56 +00:00
|
|
|
return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2006-01-17 20:05:59 +00:00
|
|
|
|
2006-04-08 04:04:54 +00:00
|
|
|
/// isValidOperands - Return true if an insertelement instruction can be
|
|
|
|
/// formed with the specified operands.
|
|
|
|
static bool isValidOperands(const Value *Vec, const Value *NewElt,
|
|
|
|
const Value *Idx);
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2007-02-15 03:39:18 +00:00
|
|
|
/// getType - Overload to return most specific vector type.
|
2006-04-14 22:20:07 +00:00
|
|
|
///
|
2011-07-18 04:54:35 +00:00
|
|
|
VectorType *getType() const {
|
2013-02-18 18:49:44 +00:00
|
|
|
return cast<VectorType>(Instruction::getType());
|
2006-04-14 22:20:07 +00:00
|
|
|
}
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2006-01-17 20:05:59 +00:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
2008-05-10 08:32:32 +00:00
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2006-01-17 20:05:59 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::InsertElement;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2011-01-11 15:07:38 +00:00
|
|
|
struct OperandTraits<InsertElementInst> :
|
|
|
|
public FixedNumOperandTraits<InsertElementInst, 3> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)
|
|
|
|
|
2006-04-08 01:15:18 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ShuffleVectorInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// ShuffleVectorInst - This instruction constructs a fixed permutation of two
|
|
|
|
/// input vectors.
|
|
|
|
///
|
|
|
|
class ShuffleVectorInst : public Instruction {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
ShuffleVectorInst *clone_impl() const override;
|
2009-10-27 22:16:29 +00:00
|
|
|
|
2006-04-08 01:15:18 +00:00
|
|
|
public:
|
2008-04-06 20:25:17 +00:00
|
|
|
// allocate space for exactly three operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 3);
|
|
|
|
}
|
2006-04-08 01:15:18 +00:00
|
|
|
ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefor = nullptr);
|
2006-04-08 01:15:18 +00:00
|
|
|
ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd);
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2006-04-08 04:04:54 +00:00
|
|
|
/// isValidOperands - Return true if a shufflevector instruction can be
|
2006-04-08 01:15:18 +00:00
|
|
|
/// formed with the specified operands.
|
|
|
|
static bool isValidOperands(const Value *V1, const Value *V2,
|
|
|
|
const Value *Mask);
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2007-02-15 03:39:18 +00:00
|
|
|
/// getType - Overload to return most specific vector type.
|
2006-04-14 22:20:07 +00:00
|
|
|
///
|
2011-07-18 04:54:35 +00:00
|
|
|
VectorType *getType() const {
|
2013-02-18 18:49:44 +00:00
|
|
|
return cast<VectorType>(Instruction::getType());
|
2006-04-14 22:20:07 +00:00
|
|
|
}
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2006-04-08 01:15:18 +00:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
2008-05-10 08:32:32 +00:00
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2012-01-25 23:49:49 +00:00
|
|
|
Constant *getMask() const {
|
2013-02-18 18:49:44 +00:00
|
|
|
return cast<Constant>(getOperand(2));
|
2012-01-25 23:49:49 +00:00
|
|
|
}
|
2013-03-07 20:04:17 +00:00
|
|
|
|
2008-03-02 05:28:33 +00:00
|
|
|
/// getMaskValue - Return the index from the shuffle mask for the specified
|
|
|
|
/// output result. This is either -1 if the element is undef or a number less
|
|
|
|
/// than 2*numelements.
|
2012-01-26 02:51:13 +00:00
|
|
|
static int getMaskValue(Constant *Mask, unsigned i);
|
|
|
|
|
|
|
|
int getMaskValue(unsigned i) const {
|
|
|
|
return getMaskValue(getMask(), i);
|
|
|
|
}
|
2013-03-07 20:04:17 +00:00
|
|
|
|
2012-01-25 23:49:49 +00:00
|
|
|
/// getShuffleMask - Return the full mask for this instruction, where each
|
|
|
|
/// element is the element number and undef's are returned as -1.
|
2012-01-26 02:51:13 +00:00
|
|
|
static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
|
|
|
|
|
|
|
|
void getShuffleMask(SmallVectorImpl<int> &Result) const {
|
|
|
|
return getShuffleMask(getMask(), Result);
|
|
|
|
}
|
2012-01-25 23:49:49 +00:00
|
|
|
|
|
|
|
SmallVector<int, 16> getShuffleMask() const {
|
|
|
|
SmallVector<int, 16> Mask;
|
|
|
|
getShuffleMask(Mask);
|
|
|
|
return Mask;
|
|
|
|
}
|
|
|
|
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2006-04-08 01:15:18 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::ShuffleVector;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2011-01-11 15:07:38 +00:00
|
|
|
struct OperandTraits<ShuffleVectorInst> :
|
|
|
|
public FixedNumOperandTraits<ShuffleVectorInst, 3> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)
|
2006-04-08 01:15:18 +00:00
|
|
|
|
2008-05-15 19:50:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ExtractValueInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-05-15 23:35:32 +00:00
|
|
|
/// ExtractValueInst - This instruction extracts a struct member or array
|
|
|
|
/// element value from an aggregate value.
|
2008-05-15 19:50:34 +00:00
|
|
|
///
|
2008-06-06 20:28:12 +00:00
|
|
|
class ExtractValueInst : public UnaryInstruction {
|
2008-05-31 00:58:22 +00:00
|
|
|
SmallVector<unsigned, 4> Indices;
|
|
|
|
|
2008-05-15 19:50:34 +00:00
|
|
|
ExtractValueInst(const ExtractValueInst &EVI);
|
2011-07-13 10:26:04 +00:00
|
|
|
void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
|
2008-05-15 19:50:34 +00:00
|
|
|
|
2008-05-15 23:35:32 +00:00
|
|
|
/// Constructors - Create a extractvalue instruction with a base aggregate
|
|
|
|
/// value and a list of indices. The first ctor can optionally insert before
|
|
|
|
/// an existing instruction, the second appends the new instruction to the
|
|
|
|
/// specified BasicBlock.
|
2010-10-27 07:39:54 +00:00
|
|
|
inline ExtractValueInst(Value *Agg,
|
2011-07-13 10:26:04 +00:00
|
|
|
ArrayRef<unsigned> Idxs,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-15 19:50:34 +00:00
|
|
|
Instruction *InsertBefore);
|
|
|
|
inline ExtractValueInst(Value *Agg,
|
2011-07-13 10:26:04 +00:00
|
|
|
ArrayRef<unsigned> Idxs,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd);
|
2008-05-15 19:50:34 +00:00
|
|
|
|
2008-05-31 19:09:47 +00:00
|
|
|
// allocate space for exactly one operand
|
2008-05-31 00:58:22 +00:00
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 1);
|
|
|
|
}
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
ExtractValueInst *clone_impl() const override;
|
2008-05-31 00:58:22 +00:00
|
|
|
|
2008-06-06 20:28:12 +00:00
|
|
|
public:
|
2010-10-27 07:39:54 +00:00
|
|
|
static ExtractValueInst *Create(Value *Agg,
|
2011-07-13 10:26:04 +00:00
|
|
|
ArrayRef<unsigned> Idxs,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr) {
|
2008-05-31 00:58:22 +00:00
|
|
|
return new
|
2011-07-13 10:26:04 +00:00
|
|
|
ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
|
|
|
static ExtractValueInst *Create(Value *Agg,
|
2011-07-13 10:26:04 +00:00
|
|
|
ArrayRef<unsigned> Idxs,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-15 19:50:34 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
2011-07-13 10:26:04 +00:00
|
|
|
return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getIndexedType - Returns the type of the element that would be extracted
|
|
|
|
/// with an extractvalue instruction with the specified parameters.
|
|
|
|
///
|
2010-12-03 14:54:33 +00:00
|
|
|
/// Null is returned if the indices are invalid for the specified type.
|
2011-07-18 04:54:35 +00:00
|
|
|
static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
|
2008-05-15 19:50:34 +00:00
|
|
|
|
2008-06-19 17:15:57 +00:00
|
|
|
typedef const unsigned* idx_iterator;
|
|
|
|
inline idx_iterator idx_begin() const { return Indices.begin(); }
|
|
|
|
inline idx_iterator idx_end() const { return Indices.end(); }
|
2008-05-15 19:50:34 +00:00
|
|
|
|
|
|
|
Value *getAggregateOperand() {
|
|
|
|
return getOperand(0);
|
|
|
|
}
|
|
|
|
const Value *getAggregateOperand() const {
|
|
|
|
return getOperand(0);
|
|
|
|
}
|
|
|
|
static unsigned getAggregateOperandIndex() {
|
|
|
|
return 0U; // get index for modifying correct operand
|
|
|
|
}
|
|
|
|
|
2011-07-13 10:26:04 +00:00
|
|
|
ArrayRef<unsigned> getIndices() const {
|
|
|
|
return Indices;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getNumIndices() const {
|
2008-06-05 07:35:27 +00:00
|
|
|
return (unsigned)Indices.size();
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool hasIndices() const {
|
2008-05-31 19:09:08 +00:00
|
|
|
return true;
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2008-05-15 19:50:34 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::ExtractValue;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-23 00:36:11 +00:00
|
|
|
ExtractValueInst::ExtractValueInst(Value *Agg,
|
2011-07-13 10:26:04 +00:00
|
|
|
ArrayRef<unsigned> Idxs,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-23 00:36:11 +00:00
|
|
|
Instruction *InsertBefore)
|
2011-07-13 10:26:04 +00:00
|
|
|
: UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
|
2008-07-22 07:14:12 +00:00
|
|
|
ExtractValue, Agg, InsertBefore) {
|
2011-07-13 10:26:04 +00:00
|
|
|
init(Idxs, NameStr);
|
2008-05-23 00:36:11 +00:00
|
|
|
}
|
|
|
|
ExtractValueInst::ExtractValueInst(Value *Agg,
|
2011-07-13 10:26:04 +00:00
|
|
|
ArrayRef<unsigned> Idxs,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-23 00:36:11 +00:00
|
|
|
BasicBlock *InsertAtEnd)
|
2011-07-13 10:26:04 +00:00
|
|
|
: UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
|
2008-07-22 07:14:12 +00:00
|
|
|
ExtractValue, Agg, InsertAtEnd) {
|
2011-07-13 10:26:04 +00:00
|
|
|
init(Idxs, NameStr);
|
2008-05-23 00:36:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-15 19:50:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// InsertValueInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-05-15 23:35:32 +00:00
|
|
|
/// InsertValueInst - This instruction inserts a struct field of array element
|
|
|
|
/// value into an aggregate value.
|
2008-05-15 19:50:34 +00:00
|
|
|
///
|
|
|
|
class InsertValueInst : public Instruction {
|
2008-05-31 00:58:22 +00:00
|
|
|
SmallVector<unsigned, 4> Indices;
|
|
|
|
|
2012-09-18 03:25:49 +00:00
|
|
|
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
|
2008-05-15 19:50:34 +00:00
|
|
|
InsertValueInst(const InsertValueInst &IVI);
|
2011-07-13 10:26:04 +00:00
|
|
|
void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr);
|
2008-05-15 19:50:34 +00:00
|
|
|
|
2008-05-15 23:35:32 +00:00
|
|
|
/// Constructors - Create a insertvalue instruction with a base aggregate
|
|
|
|
/// value, a value to insert, and a list of indices. The first ctor can
|
|
|
|
/// optionally insert before an existing instruction, the second appends
|
|
|
|
/// the new instruction to the specified BasicBlock.
|
2010-10-27 07:39:54 +00:00
|
|
|
inline InsertValueInst(Value *Agg, Value *Val,
|
2011-07-13 10:26:04 +00:00
|
|
|
ArrayRef<unsigned> Idxs,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-15 23:35:32 +00:00
|
|
|
Instruction *InsertBefore);
|
2008-05-15 19:50:34 +00:00
|
|
|
inline InsertValueInst(Value *Agg, Value *Val,
|
2011-07-13 10:26:04 +00:00
|
|
|
ArrayRef<unsigned> Idxs,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd);
|
2008-05-15 19:50:34 +00:00
|
|
|
|
|
|
|
/// Constructors - These two constructors are convenience methods because one
|
|
|
|
/// and two index insertvalue instructions are so common.
|
|
|
|
InsertValueInst(Value *Agg, Value *Val,
|
2009-07-25 04:41:11 +00:00
|
|
|
unsigned Idx, const Twine &NameStr = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr);
|
2008-05-31 00:58:22 +00:00
|
|
|
InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd);
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
InsertValueInst *clone_impl() const override;
|
2008-05-15 19:50:34 +00:00
|
|
|
public:
|
2008-05-31 00:58:22 +00:00
|
|
|
// allocate space for exactly two operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 2);
|
|
|
|
}
|
|
|
|
|
2010-10-27 07:39:54 +00:00
|
|
|
static InsertValueInst *Create(Value *Agg, Value *Val,
|
2011-07-13 10:26:04 +00:00
|
|
|
ArrayRef<unsigned> Idxs,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr) {
|
2011-07-13 10:26:04 +00:00
|
|
|
return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
|
|
|
static InsertValueInst *Create(Value *Agg, Value *Val,
|
2011-07-13 10:26:04 +00:00
|
|
|
ArrayRef<unsigned> Idxs,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-15 19:50:34 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
2011-07-13 10:26:04 +00:00
|
|
|
return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Transparently provide more efficient getOperand methods.
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
|
|
|
|
2008-06-19 17:15:57 +00:00
|
|
|
typedef const unsigned* idx_iterator;
|
|
|
|
inline idx_iterator idx_begin() const { return Indices.begin(); }
|
|
|
|
inline idx_iterator idx_end() const { return Indices.end(); }
|
2008-05-15 19:50:34 +00:00
|
|
|
|
|
|
|
Value *getAggregateOperand() {
|
|
|
|
return getOperand(0);
|
|
|
|
}
|
|
|
|
const Value *getAggregateOperand() const {
|
|
|
|
return getOperand(0);
|
|
|
|
}
|
|
|
|
static unsigned getAggregateOperandIndex() {
|
|
|
|
return 0U; // get index for modifying correct operand
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *getInsertedValueOperand() {
|
|
|
|
return getOperand(1);
|
|
|
|
}
|
|
|
|
const Value *getInsertedValueOperand() const {
|
|
|
|
return getOperand(1);
|
|
|
|
}
|
|
|
|
static unsigned getInsertedValueOperandIndex() {
|
|
|
|
return 1U; // get index for modifying correct operand
|
|
|
|
}
|
|
|
|
|
2011-07-13 10:26:04 +00:00
|
|
|
ArrayRef<unsigned> getIndices() const {
|
|
|
|
return Indices;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getNumIndices() const {
|
2008-06-05 07:35:27 +00:00
|
|
|
return (unsigned)Indices.size();
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool hasIndices() const {
|
2008-05-31 19:09:08 +00:00
|
|
|
return true;
|
2008-05-15 19:50:34 +00:00
|
|
|
}
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2008-05-15 19:50:34 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::InsertValue;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
2011-01-11 15:07:38 +00:00
|
|
|
struct OperandTraits<InsertValueInst> :
|
|
|
|
public FixedNumOperandTraits<InsertValueInst, 2> {
|
2008-05-15 19:50:34 +00:00
|
|
|
};
|
|
|
|
|
2008-05-23 00:36:11 +00:00
|
|
|
InsertValueInst::InsertValueInst(Value *Agg,
|
|
|
|
Value *Val,
|
2011-07-13 10:26:04 +00:00
|
|
|
ArrayRef<unsigned> Idxs,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-23 00:36:11 +00:00
|
|
|
Instruction *InsertBefore)
|
2008-05-31 00:58:22 +00:00
|
|
|
: Instruction(Agg->getType(), InsertValue,
|
|
|
|
OperandTraits<InsertValueInst>::op_begin(this),
|
|
|
|
2, InsertBefore) {
|
2011-07-13 10:26:04 +00:00
|
|
|
init(Agg, Val, Idxs, NameStr);
|
2008-05-23 00:36:11 +00:00
|
|
|
}
|
|
|
|
InsertValueInst::InsertValueInst(Value *Agg,
|
|
|
|
Value *Val,
|
2011-07-13 10:26:04 +00:00
|
|
|
ArrayRef<unsigned> Idxs,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr,
|
2008-05-23 00:36:11 +00:00
|
|
|
BasicBlock *InsertAtEnd)
|
2008-05-31 00:58:22 +00:00
|
|
|
: Instruction(Agg->getType(), InsertValue,
|
|
|
|
OperandTraits<InsertValueInst>::op_begin(this),
|
|
|
|
2, InsertAtEnd) {
|
2011-07-13 10:26:04 +00:00
|
|
|
init(Agg, Val, Idxs, NameStr);
|
2008-05-23 00:36:11 +00:00
|
|
|
}
|
|
|
|
|
2008-05-15 19:50:34 +00:00
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PHINode Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// PHINode - The PHINode class is used to represent the magical mystical PHI
|
|
|
|
// node, that can not exist in nature, but can be synthesized in a computer
|
|
|
|
// scientist's overactive imagination.
|
|
|
|
//
|
|
|
|
class PHINode : public Instruction {
|
2012-09-18 03:25:49 +00:00
|
|
|
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
|
2005-01-29 00:31:36 +00:00
|
|
|
/// ReservedSpace - The number of operands actually allocated. NumOperands is
|
|
|
|
/// the number actually in use.
|
|
|
|
unsigned ReservedSpace;
|
2004-07-29 12:17:34 +00:00
|
|
|
PHINode(const PHINode &PN);
|
2008-04-06 20:25:17 +00:00
|
|
|
// allocate space for exactly zero operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 0);
|
|
|
|
}
|
2011-07-18 04:54:35 +00:00
|
|
|
explicit PHINode(Type *Ty, unsigned NumReservedValues,
|
2014-04-09 06:08:46 +00:00
|
|
|
const Twine &NameStr = "",
|
|
|
|
Instruction *InsertBefore = nullptr)
|
|
|
|
: Instruction(Ty, Instruction::PHI, nullptr, 0, InsertBefore),
|
2011-06-23 09:09:15 +00:00
|
|
|
ReservedSpace(NumReservedValues) {
|
2008-07-24 00:08:56 +00:00
|
|
|
setName(NameStr);
|
2011-03-30 11:28:46 +00:00
|
|
|
OperandList = allocHungoffUses(ReservedSpace);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
2011-07-18 04:54:35 +00:00
|
|
|
PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
|
2011-03-30 11:28:46 +00:00
|
|
|
BasicBlock *InsertAtEnd)
|
2014-04-09 06:08:46 +00:00
|
|
|
: Instruction(Ty, Instruction::PHI, nullptr, 0, InsertAtEnd),
|
2011-06-23 09:09:15 +00:00
|
|
|
ReservedSpace(NumReservedValues) {
|
2008-07-24 00:08:56 +00:00
|
|
|
setName(NameStr);
|
2011-03-30 11:28:46 +00:00
|
|
|
OperandList = allocHungoffUses(ReservedSpace);
|
2005-01-29 00:31:36 +00:00
|
|
|
}
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2011-06-23 09:09:15 +00:00
|
|
|
// allocHungoffUses - this is more complicated than the generic
|
|
|
|
// User::allocHungoffUses, because we have to allocate Uses for the incoming
|
|
|
|
// values and pointers to the incoming blocks, all in one allocation.
|
|
|
|
Use *allocHungoffUses(unsigned) const;
|
|
|
|
|
2014-03-05 06:35:38 +00:00
|
|
|
PHINode *clone_impl() const override;
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
2011-03-30 13:29:06 +00:00
|
|
|
/// 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).
|
2011-07-18 04:54:35 +00:00
|
|
|
static PHINode *Create(Type *Ty, unsigned NumReservedValues,
|
2011-03-30 11:28:46 +00:00
|
|
|
const Twine &NameStr = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr) {
|
2011-03-30 11:28:46 +00:00
|
|
|
return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2013-03-07 20:04:17 +00:00
|
|
|
static PHINode *Create(Type *Ty, unsigned NumReservedValues,
|
2011-03-30 11:28:46 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd) {
|
|
|
|
return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2007-12-10 02:14:30 +00:00
|
|
|
~PHINode();
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
/// Provide fast operand accessors
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
|
|
|
|
2011-06-23 09:09:15 +00:00
|
|
|
// Block iterator interface. This provides access to the list of incoming
|
|
|
|
// basic blocks, which parallels the list of incoming values.
|
|
|
|
|
|
|
|
typedef BasicBlock **block_iterator;
|
|
|
|
typedef BasicBlock * const *const_block_iterator;
|
|
|
|
|
|
|
|
block_iterator block_begin() {
|
|
|
|
Use::UserRef *ref =
|
|
|
|
reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
|
|
|
|
return reinterpret_cast<block_iterator>(ref + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const_block_iterator block_begin() const {
|
|
|
|
const Use::UserRef *ref =
|
|
|
|
reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
|
|
|
|
return reinterpret_cast<const_block_iterator>(ref + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
block_iterator block_end() {
|
|
|
|
return block_begin() + getNumOperands();
|
|
|
|
}
|
|
|
|
|
|
|
|
const_block_iterator block_end() const {
|
|
|
|
return block_begin() + getNumOperands();
|
|
|
|
}
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
/// getNumIncomingValues - Return the number of incoming edges
|
|
|
|
///
|
2011-06-23 09:09:15 +00:00
|
|
|
unsigned getNumIncomingValues() const { return getNumOperands(); }
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2006-05-19 19:07:54 +00:00
|
|
|
/// getIncomingValue - Return incoming value number x
|
2004-07-29 12:17:34 +00:00
|
|
|
///
|
|
|
|
Value *getIncomingValue(unsigned i) const {
|
2011-06-23 09:09:15 +00:00
|
|
|
return getOperand(i);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
void setIncomingValue(unsigned i, Value *V) {
|
2011-06-23 09:09:15 +00:00
|
|
|
setOperand(i, V);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2009-03-23 15:48:29 +00:00
|
|
|
static unsigned getOperandNumForIncomingValue(unsigned i) {
|
2011-06-23 09:09:15 +00:00
|
|
|
return i;
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2009-03-23 15:48:29 +00:00
|
|
|
static unsigned getIncomingValueNumForOperand(unsigned i) {
|
2011-06-23 09:09:15 +00:00
|
|
|
return i;
|
2009-03-23 15:48:29 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2010-02-22 04:10:52 +00:00
|
|
|
/// getIncomingBlock - Return incoming basic block number @p i.
|
2009-10-10 07:42:42 +00:00
|
|
|
///
|
|
|
|
BasicBlock *getIncomingBlock(unsigned i) const {
|
2011-06-23 09:09:15 +00:00
|
|
|
return block_begin()[i];
|
2009-10-10 07:42:42 +00:00
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-01-23 19:40:15 +00:00
|
|
|
/// getIncomingBlock - Return incoming basic block corresponding
|
2009-10-10 07:42:42 +00:00
|
|
|
/// to an operand of the PHI.
|
2009-01-23 19:40:15 +00:00
|
|
|
///
|
2009-10-10 07:42:42 +00:00
|
|
|
BasicBlock *getIncomingBlock(const Use &U) const {
|
|
|
|
assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?");
|
2011-06-23 09:09:15 +00:00
|
|
|
return getIncomingBlock(unsigned(&U - op_begin()));
|
2009-01-23 19:40:15 +00:00
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-10-10 07:42:42 +00:00
|
|
|
/// getIncomingBlock - Return incoming basic block corresponding
|
|
|
|
/// to value use iterator.
|
2004-07-29 12:17:34 +00:00
|
|
|
///
|
2014-03-09 03:16:01 +00:00
|
|
|
BasicBlock *getIncomingBlock(Value::const_user_iterator I) const {
|
2009-10-10 07:42:42 +00:00
|
|
|
return getIncomingBlock(I.getUse());
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
void setIncomingBlock(unsigned i, BasicBlock *BB) {
|
2011-06-23 09:09:15 +00:00
|
|
|
block_begin()[i] = BB;
|
2009-03-23 15:48:29 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
/// addIncoming - Add an incoming value to the end of the PHI list
|
|
|
|
///
|
|
|
|
void addIncoming(Value *V, BasicBlock *BB) {
|
2008-02-27 22:37:28 +00:00
|
|
|
assert(V && "PHI node got a null value!");
|
|
|
|
assert(BB && "PHI node got a null basic block!");
|
2004-07-29 12:17:34 +00:00
|
|
|
assert(getType() == V->getType() &&
|
|
|
|
"All operands to PHI node must be the same type as the PHI node!");
|
2011-06-23 09:09:15 +00:00
|
|
|
if (NumOperands == ReservedSpace)
|
2011-04-01 08:00:58 +00:00
|
|
|
growOperands(); // Get more space!
|
2005-01-29 00:31:36 +00:00
|
|
|
// Initialize some new operands.
|
2011-06-23 09:09:15 +00:00
|
|
|
++NumOperands;
|
|
|
|
setIncomingValue(NumOperands - 1, V);
|
|
|
|
setIncomingBlock(NumOperands - 1, BB);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2005-04-21 20:19:05 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
/// removeIncomingValue - Remove an incoming value. This is useful if a
|
|
|
|
/// predecessor basic block is deleted. The value removed is returned.
|
|
|
|
///
|
|
|
|
/// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
|
|
|
|
/// is true), the PHI node is destroyed and any uses of it are replaced with
|
|
|
|
/// dummy values. The only time there should be zero incoming values to a PHI
|
|
|
|
/// node is when the block is dead, so this strategy is sound.
|
|
|
|
///
|
|
|
|
Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
|
2004-07-29 12:17:34 +00:00
|
|
|
int Idx = getBasicBlockIndex(BB);
|
|
|
|
assert(Idx >= 0 && "Invalid basic block argument to remove!");
|
|
|
|
return removeIncomingValue(Idx, DeletePHIIfEmpty);
|
|
|
|
}
|
|
|
|
|
2005-04-21 20:19:05 +00:00
|
|
|
/// getBasicBlockIndex - Return the first index of the specified basic
|
2004-07-29 12:17:34 +00:00
|
|
|
/// block in the value list for this PHI. Returns -1 if no instance.
|
|
|
|
///
|
|
|
|
int getBasicBlockIndex(const BasicBlock *BB) const {
|
2011-06-23 09:09:15 +00:00
|
|
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
|
|
|
|
if (block_begin()[i] == BB)
|
|
|
|
return i;
|
2004-07-29 12:17:34 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *getIncomingValueForBlock(const BasicBlock *BB) const {
|
2011-06-23 09:09:15 +00:00
|
|
|
int Idx = getBasicBlockIndex(BB);
|
|
|
|
assert(Idx >= 0 && "Invalid basic block argument!");
|
|
|
|
return getIncomingValue(Idx);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
2006-10-03 17:09:12 +00:00
|
|
|
/// hasConstantValue - If the specified PHI node always merges together the
|
2005-08-04 23:24:19 +00:00
|
|
|
/// same value, return the value, otherwise return null.
|
2010-11-17 04:30:22 +00:00
|
|
|
Value *hasConstantValue() const;
|
2006-10-03 17:09:12 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
2005-04-21 20:19:05 +00:00
|
|
|
return I->getOpcode() == Instruction::PHI;
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
private:
|
2011-04-01 08:00:58 +00:00
|
|
|
void growOperands();
|
2004-07-29 12:17:34 +00:00
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2009-09-06 08:55:57 +00:00
|
|
|
struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)
|
2008-05-10 08:32:32 +00:00
|
|
|
|
2011-08-12 20:24:12 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// LandingPadInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
/// LandingPadInst - The landingpad instruction holds all of the information
|
|
|
|
/// necessary to generate correct exception handling. The landingpad instruction
|
|
|
|
/// cannot be moved from the top of a landing pad block, which itself is
|
|
|
|
/// accessible only from the 'unwind' edge of an invoke. This uses the
|
|
|
|
/// SubclassData field in Value to store whether or not the landingpad is a
|
|
|
|
/// cleanup.
|
|
|
|
///
|
|
|
|
class LandingPadInst : public Instruction {
|
|
|
|
/// ReservedSpace - The number of operands actually allocated. NumOperands is
|
|
|
|
/// the number actually in use.
|
|
|
|
unsigned ReservedSpace;
|
|
|
|
LandingPadInst(const LandingPadInst &LP);
|
|
|
|
public:
|
|
|
|
enum ClauseType { Catch, Filter };
|
|
|
|
private:
|
2012-09-18 03:25:49 +00:00
|
|
|
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
|
2011-08-12 20:24:12 +00:00
|
|
|
// Allocate space for exactly zero operands.
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 0);
|
|
|
|
}
|
|
|
|
void growOperands(unsigned Size);
|
|
|
|
void init(Value *PersFn, unsigned NumReservedValues, const Twine &NameStr);
|
|
|
|
|
|
|
|
explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
|
|
|
|
unsigned NumReservedValues, const Twine &NameStr,
|
|
|
|
Instruction *InsertBefore);
|
|
|
|
explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
|
|
|
|
unsigned NumReservedValues, const Twine &NameStr,
|
|
|
|
BasicBlock *InsertAtEnd);
|
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
LandingPadInst *clone_impl() const override;
|
2011-08-12 20:24:12 +00:00
|
|
|
public:
|
|
|
|
/// 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, Value *PersonalityFn,
|
|
|
|
unsigned NumReservedClauses,
|
|
|
|
const Twine &NameStr = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr);
|
2011-08-12 20:24:12 +00:00
|
|
|
static LandingPadInst *Create(Type *RetTy, Value *PersonalityFn,
|
|
|
|
unsigned NumReservedClauses,
|
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd);
|
|
|
|
~LandingPadInst();
|
|
|
|
|
|
|
|
/// Provide fast operand accessors
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
|
|
|
|
|
|
|
/// getPersonalityFn - Get the personality function associated with this
|
|
|
|
/// landing pad.
|
|
|
|
Value *getPersonalityFn() const { return getOperand(0); }
|
|
|
|
|
|
|
|
/// isCleanup - Return 'true' if this landingpad instruction is a
|
|
|
|
/// cleanup. I.e., it should be run when unwinding even if its landing pad
|
|
|
|
/// doesn't catch the exception.
|
|
|
|
bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
|
|
|
|
|
|
|
|
/// setCleanup - Indicate that this landingpad instruction is a cleanup.
|
|
|
|
void setCleanup(bool V) {
|
|
|
|
setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
|
|
|
|
(V ? 1 : 0));
|
|
|
|
}
|
|
|
|
|
2014-06-04 18:51:31 +00:00
|
|
|
/// Add a catch or filter clause to the landing pad.
|
|
|
|
void addClause(Constant *ClauseVal);
|
2011-08-12 20:24:12 +00:00
|
|
|
|
2014-06-04 18:51:31 +00:00
|
|
|
/// Get the value of the clause at index Idx. Use isCatch/isFilter to
|
|
|
|
/// determine what type of clause this is.
|
|
|
|
Constant *getClause(unsigned Idx) const {
|
|
|
|
return cast<Constant>(OperandList[Idx + 1]);
|
|
|
|
}
|
2011-08-12 20:24:12 +00:00
|
|
|
|
|
|
|
/// isCatch - Return 'true' if the clause and index Idx is a catch clause.
|
|
|
|
bool isCatch(unsigned Idx) const {
|
|
|
|
return !isa<ArrayType>(OperandList[Idx + 1]->getType());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// isFilter - Return 'true' if the clause and index Idx is a filter clause.
|
|
|
|
bool isFilter(unsigned Idx) const {
|
|
|
|
return isa<ArrayType>(OperandList[Idx + 1]->getType());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getNumClauses - Get the number of clauses for this landing pad.
|
|
|
|
unsigned getNumClauses() const { return getNumOperands() - 1; }
|
|
|
|
|
2012-06-02 10:20:22 +00:00
|
|
|
/// reserveClauses - Grow the size of the operand list to accommodate the new
|
2011-08-12 20:24:12 +00:00
|
|
|
/// number of clauses.
|
|
|
|
void reserveClauses(unsigned Size) { growOperands(Size); }
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::LandingPad;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<2> {
|
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)
|
2008-05-10 08:32:32 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ReturnInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
/// ReturnInst - Return a value (possibly void), from a function. Execution
|
|
|
|
/// does not continue in this function any longer.
|
|
|
|
///
|
|
|
|
class ReturnInst : public TerminatorInst {
|
2007-02-24 00:55:48 +00:00
|
|
|
ReturnInst(const ReturnInst &RI);
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2008-04-06 20:25:17 +00:00
|
|
|
private:
|
2004-07-29 12:17:34 +00:00
|
|
|
// ReturnInst constructors:
|
|
|
|
// ReturnInst() - 'ret void' instruction
|
2004-11-17 21:02:25 +00:00
|
|
|
// ReturnInst( null) - 'ret void' instruction
|
2004-07-29 12:17:34 +00:00
|
|
|
// ReturnInst(Value* X) - 'ret X' instruction
|
2008-05-10 08:32:32 +00:00
|
|
|
// ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
|
2004-07-29 12:17:34 +00:00
|
|
|
// ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
|
2008-05-10 08:32:32 +00:00
|
|
|
// ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
|
|
|
|
// ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
|
2004-11-17 21:02:25 +00:00
|
|
|
//
|
|
|
|
// NOTE: If the Value* passed is of type void then the constructor behaves as
|
|
|
|
// if it was passed NULL.
|
2014-04-09 06:08:46 +00:00
|
|
|
explicit ReturnInst(LLVMContext &C, Value *retVal = nullptr,
|
|
|
|
Instruction *InsertBefore = nullptr);
|
2009-08-13 21:58:54 +00:00
|
|
|
ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
|
|
|
|
explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
ReturnInst *clone_impl() const override;
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
2014-04-09 06:08:46 +00:00
|
|
|
static ReturnInst* Create(LLVMContext &C, Value *retVal = nullptr,
|
|
|
|
Instruction *InsertBefore = nullptr) {
|
2009-08-13 21:58:54 +00:00
|
|
|
return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2009-08-13 21:58:54 +00:00
|
|
|
static ReturnInst* Create(LLVMContext &C, Value *retVal,
|
|
|
|
BasicBlock *InsertAtEnd) {
|
|
|
|
return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2009-08-13 21:58:54 +00:00
|
|
|
static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
|
|
|
|
return new(0) ReturnInst(C, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2008-02-23 00:35:18 +00:00
|
|
|
virtual ~ReturnInst();
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
/// Provide fast operand accessors
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2008-02-26 17:56:20 +00:00
|
|
|
|
2010-10-06 16:59:24 +00:00
|
|
|
/// Convenience accessor. Returns null if there is no return value.
|
|
|
|
Value *getReturnValue() const {
|
2014-04-09 06:08:46 +00:00
|
|
|
return getNumOperands() != 0 ? getOperand(0) : nullptr;
|
2008-03-11 17:35:03 +00:00
|
|
|
}
|
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
unsigned getNumSuccessors() const { return 0; }
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::Ret);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
private:
|
2014-03-05 06:35:38 +00:00
|
|
|
BasicBlock *getSuccessorV(unsigned idx) const override;
|
|
|
|
unsigned getNumSuccessorsV() const override;
|
|
|
|
void setSuccessorV(unsigned idx, BasicBlock *B) override;
|
2004-07-29 12:17:34 +00:00
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2011-01-11 15:07:38 +00:00
|
|
|
struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// BranchInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
/// BranchInst - Conditional or Unconditional Branch instruction.
|
|
|
|
///
|
|
|
|
class BranchInst : public TerminatorInst {
|
2005-01-29 00:31:36 +00:00
|
|
|
/// Ops list - Branches are strange. The operands are ordered:
|
2009-03-12 18:34:49 +00:00
|
|
|
/// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
|
|
|
|
/// they don't have to check for cond/uncond branchness. These are mostly
|
|
|
|
/// accessed relative from op_end().
|
2004-07-29 12:17:34 +00:00
|
|
|
BranchInst(const BranchInst &BI);
|
2005-01-29 00:31:36 +00:00
|
|
|
void AssertOK();
|
2004-07-29 12:17:34 +00:00
|
|
|
// BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
|
|
|
|
// BranchInst(BB *B) - 'br B'
|
|
|
|
// BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
|
|
|
|
// BranchInst(BB* B, Inst *I) - 'br B' insert before I
|
|
|
|
// 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
|
2014-04-09 06:08:46 +00:00
|
|
|
explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = nullptr);
|
2004-07-29 12:17:34 +00:00
|
|
|
BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr);
|
2007-02-24 00:55:48 +00:00
|
|
|
BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
|
2004-07-29 12:17:34 +00:00
|
|
|
BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
|
2007-02-24 00:55:48 +00:00
|
|
|
BasicBlock *InsertAtEnd);
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
BranchInst *clone_impl() const override;
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
2014-04-09 06:08:46 +00:00
|
|
|
static BranchInst *Create(BasicBlock *IfTrue,
|
|
|
|
Instruction *InsertBefore = nullptr) {
|
2011-01-07 20:29:02 +00:00
|
|
|
return new(1) BranchInst(IfTrue, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2008-05-10 08:32:32 +00:00
|
|
|
static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
|
2014-04-09 06:08:46 +00:00
|
|
|
Value *Cond, Instruction *InsertBefore = nullptr) {
|
2008-04-06 20:25:17 +00:00
|
|
|
return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
|
|
|
|
}
|
|
|
|
static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
|
2011-01-07 20:29:02 +00:00
|
|
|
return new(1) BranchInst(IfTrue, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2008-05-10 08:32:32 +00:00
|
|
|
static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
|
|
|
|
Value *Cond, BasicBlock *InsertAtEnd) {
|
2008-04-06 20:25:17 +00:00
|
|
|
return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
|
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
/// Transparently provide more efficient getOperand methods.
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
|
|
|
|
2008-02-23 01:11:02 +00:00
|
|
|
bool isUnconditional() const { return getNumOperands() == 1; }
|
|
|
|
bool isConditional() const { return getNumOperands() == 3; }
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2008-02-23 01:11:02 +00:00
|
|
|
Value *getCondition() const {
|
2004-07-29 12:17:34 +00:00
|
|
|
assert(isConditional() && "Cannot get condition of an uncond branch!");
|
2009-03-12 18:34:49 +00:00
|
|
|
return Op<-3>();
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void setCondition(Value *V) {
|
|
|
|
assert(isConditional() && "Cannot set condition of unconditional branch!");
|
2009-03-12 18:34:49 +00:00
|
|
|
Op<-3>() = V;
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
unsigned getNumSuccessors() const { return 1+isConditional(); }
|
|
|
|
|
|
|
|
BasicBlock *getSuccessor(unsigned i) const {
|
2004-07-29 12:17:34 +00:00
|
|
|
assert(i < getNumSuccessors() && "Successor # out of range for Branch!");
|
2009-03-12 18:34:49 +00:00
|
|
|
return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
|
2004-07-29 12:17:34 +00:00
|
|
|
assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
|
2009-10-27 16:49:53 +00:00
|
|
|
*(&Op<-1>() - idx) = (Value*)NewSucc;
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 01:11:57 +00:00
|
|
|
/// \brief Swap the successors of this branch instruction.
|
|
|
|
///
|
|
|
|
/// Swaps the successors of the branch instruction. This also swaps any
|
|
|
|
/// branch weight metadata associated with the instruction so that it
|
|
|
|
/// continues to map correctly to each operand.
|
|
|
|
void swapSuccessors();
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::Br);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
private:
|
2014-03-05 06:35:38 +00:00
|
|
|
BasicBlock *getSuccessorV(unsigned idx) const override;
|
|
|
|
unsigned getNumSuccessorsV() const override;
|
|
|
|
void setSuccessorV(unsigned idx, BasicBlock *B) override;
|
2004-07-29 12:17:34 +00:00
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2011-01-11 15:07:38 +00:00
|
|
|
struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
|
|
|
|
};
|
2008-05-10 08:32:32 +00:00
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// SwitchInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
/// SwitchInst - Multiway switch
|
|
|
|
///
|
|
|
|
class SwitchInst : public TerminatorInst {
|
2012-09-18 03:25:49 +00:00
|
|
|
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
|
2005-01-29 00:31:36 +00:00
|
|
|
unsigned ReservedSpace;
|
2004-07-29 12:17:34 +00:00
|
|
|
// Operand[0] = Value to switch on
|
|
|
|
// Operand[1] = Default basic block destination
|
|
|
|
// Operand[2n ] = Value to match
|
|
|
|
// Operand[2n+1] = BasicBlock to go to on match
|
2009-10-27 19:13:16 +00:00
|
|
|
SwitchInst(const SwitchInst &SI);
|
2010-11-17 05:41:46 +00:00
|
|
|
void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
|
2011-04-01 08:00:58 +00:00
|
|
|
void growOperands();
|
2008-05-10 08:32:32 +00:00
|
|
|
// allocate space for exactly zero operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 0);
|
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
/// 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(Value *Value, BasicBlock *Default, unsigned NumCases,
|
2009-10-27 19:13:16 +00:00
|
|
|
Instruction *InsertBefore);
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
/// 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(Value *Value, BasicBlock *Default, unsigned NumCases,
|
2007-02-24 00:55:48 +00:00
|
|
|
BasicBlock *InsertAtEnd);
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
SwitchInst *clone_impl() const override;
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
2013-03-07 20:04:17 +00:00
|
|
|
|
2012-05-28 10:11:27 +00:00
|
|
|
// -2
|
|
|
|
static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
|
2013-03-07 20:04:17 +00:00
|
|
|
|
Revert patches to add case-range support for PR1255.
The work on this project was left in an unfinished and inconsistent state.
Hopefully someone will eventually get a chance to implement this feature, but
in the meantime, it is better to put things back the way the were. I have
left support in the bitcode reader to handle the case-range bitcode format,
so that we do not lose bitcode compatibility with the llvm 3.3 release.
This reverts the following commits: 155464, 156374, 156377, 156613, 156704,
156757, 156804 156808, 156985, 157046, 157112, 157183, 157315, 157384, 157575,
157576, 157586, 157612, 157810, 157814, 157815, 157880, 157881, 157882, 157884,
157887, 157901, 158979, 157987, 157989, 158986, 158997, 159076, 159101, 159100,
159200, 159201, 159207, 159527, 159532, 159540, 159583, 159618, 159658, 159659,
159660, 159661, 159703, 159704, 160076, 167356, 172025, 186736
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190328 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-09 19:14:35 +00:00
|
|
|
template <class SwitchInstTy, class ConstantIntTy, class BasicBlockTy>
|
|
|
|
class CaseIteratorT {
|
|
|
|
protected:
|
|
|
|
|
|
|
|
SwitchInstTy *SI;
|
|
|
|
unsigned Index;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef CaseIteratorT<SwitchInstTy, ConstantIntTy, BasicBlockTy> Self;
|
|
|
|
|
|
|
|
/// Initializes case iterator for given SwitchInst and for given
|
|
|
|
/// case number.
|
|
|
|
CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum) {
|
|
|
|
this->SI = SI;
|
|
|
|
Index = CaseNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Initializes case iterator for given SwitchInst and for given
|
|
|
|
/// TerminatorInst's successor index.
|
|
|
|
static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex) {
|
|
|
|
assert(SuccessorIndex < SI->getNumSuccessors() &&
|
|
|
|
"Successor index # out of range!");
|
|
|
|
return SuccessorIndex != 0 ?
|
|
|
|
Self(SI, SuccessorIndex - 1) :
|
|
|
|
Self(SI, DefaultPseudoIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Resolves case value for current case.
|
|
|
|
ConstantIntTy *getCaseValue() {
|
|
|
|
assert(Index < SI->getNumCases() && "Index out the number of cases.");
|
|
|
|
return reinterpret_cast<ConstantIntTy*>(SI->getOperand(2 + Index*2));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Resolves successor for current case.
|
|
|
|
BasicBlockTy *getCaseSuccessor() {
|
|
|
|
assert((Index < SI->getNumCases() ||
|
|
|
|
Index == DefaultPseudoIndex) &&
|
|
|
|
"Index out the number of cases.");
|
|
|
|
return SI->getSuccessor(getSuccessorIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns number of current case.
|
|
|
|
unsigned getCaseIndex() const { return Index; }
|
|
|
|
|
|
|
|
/// Returns TerminatorInst's successor index for current case successor.
|
|
|
|
unsigned getSuccessorIndex() const {
|
|
|
|
assert((Index == DefaultPseudoIndex || Index < SI->getNumCases()) &&
|
|
|
|
"Index out the number of cases.");
|
|
|
|
return Index != DefaultPseudoIndex ? Index + 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Self operator++() {
|
|
|
|
// Check index correctness after increment.
|
|
|
|
// Note: Index == getNumCases() means end().
|
|
|
|
assert(Index+1 <= SI->getNumCases() && "Index out the number of cases.");
|
|
|
|
++Index;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Self operator++(int) {
|
|
|
|
Self tmp = *this;
|
|
|
|
++(*this);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
Self operator--() {
|
|
|
|
// Check index correctness after decrement.
|
|
|
|
// Note: Index == getNumCases() means end().
|
|
|
|
// Also allow "-1" iterator here. That will became valid after ++.
|
|
|
|
assert((Index == 0 || Index-1 <= SI->getNumCases()) &&
|
|
|
|
"Index out the number of cases.");
|
|
|
|
--Index;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Self operator--(int) {
|
|
|
|
Self tmp = *this;
|
|
|
|
--(*this);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
bool operator==(const Self& RHS) const {
|
|
|
|
assert(RHS.SI == SI && "Incompatible operators.");
|
|
|
|
return RHS.Index == Index;
|
|
|
|
}
|
|
|
|
bool operator!=(const Self& RHS) const {
|
|
|
|
assert(RHS.SI == SI && "Incompatible operators.");
|
|
|
|
return RHS.Index != Index;
|
|
|
|
}
|
2014-07-02 05:32:13 +00:00
|
|
|
Self &operator*() {
|
|
|
|
return *this;
|
|
|
|
}
|
Revert patches to add case-range support for PR1255.
The work on this project was left in an unfinished and inconsistent state.
Hopefully someone will eventually get a chance to implement this feature, but
in the meantime, it is better to put things back the way the were. I have
left support in the bitcode reader to handle the case-range bitcode format,
so that we do not lose bitcode compatibility with the llvm 3.3 release.
This reverts the following commits: 155464, 156374, 156377, 156613, 156704,
156757, 156804 156808, 156985, 157046, 157112, 157183, 157315, 157384, 157575,
157576, 157586, 157612, 157810, 157814, 157815, 157880, 157881, 157882, 157884,
157887, 157901, 158979, 157987, 157989, 158986, 158997, 159076, 159101, 159100,
159200, 159201, 159207, 159527, 159532, 159540, 159583, 159618, 159658, 159659,
159660, 159661, 159703, 159704, 160076, 167356, 172025, 186736
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190328 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-09 19:14:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef CaseIteratorT<const SwitchInst, const ConstantInt, const BasicBlock>
|
|
|
|
ConstCaseIt;
|
|
|
|
|
|
|
|
class CaseIt : public CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> {
|
|
|
|
|
|
|
|
typedef CaseIteratorT<SwitchInst, ConstantInt, BasicBlock> ParentTy;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
CaseIt(const ParentTy& Src) : ParentTy(Src) {}
|
|
|
|
CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {}
|
|
|
|
|
|
|
|
/// Sets the new value for current case.
|
|
|
|
void setValue(ConstantInt *V) {
|
|
|
|
assert(Index < SI->getNumCases() && "Index out the number of cases.");
|
|
|
|
SI->setOperand(2 + Index*2, reinterpret_cast<Value*>(V));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Sets the new successor for current case.
|
|
|
|
void setSuccessor(BasicBlock *S) {
|
|
|
|
SI->setSuccessor(getSuccessorIndex(), S);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
static SwitchInst *Create(Value *Value, BasicBlock *Default,
|
2014-04-09 06:08:46 +00:00
|
|
|
unsigned NumCases,
|
|
|
|
Instruction *InsertBefore = nullptr) {
|
2008-05-10 08:32:32 +00:00
|
|
|
return new SwitchInst(Value, Default, NumCases, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2008-05-10 08:32:32 +00:00
|
|
|
static SwitchInst *Create(Value *Value, BasicBlock *Default,
|
|
|
|
unsigned NumCases, BasicBlock *InsertAtEnd) {
|
|
|
|
return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2013-03-07 20:04:17 +00:00
|
|
|
|
2007-12-10 02:14:30 +00:00
|
|
|
~SwitchInst();
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
/// Provide fast operand accessors
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
// Accessor Methods for Switch stmt
|
2008-02-23 01:11:02 +00:00
|
|
|
Value *getCondition() const { return getOperand(0); }
|
2005-01-29 00:31:36 +00:00
|
|
|
void setCondition(Value *V) { setOperand(0, V); }
|
2004-12-10 20:35:47 +00:00
|
|
|
|
2008-02-23 01:11:02 +00:00
|
|
|
BasicBlock *getDefaultDest() const {
|
2005-01-29 00:31:36 +00:00
|
|
|
return cast<BasicBlock>(getOperand(1));
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
SwitchInst refactoring.
The purpose of refactoring is to hide operand roles from SwitchInst user (programmer). If you want to play with operands directly, probably you will need lower level methods than SwitchInst ones (TerminatorInst or may be User). After this patch we can reorganize SwitchInst operands and successors as we want.
What was done:
1. Changed semantics of index inside the getCaseValue method:
getCaseValue(0) means "get first case", not a condition. Use getCondition() if you want to resolve the condition. I propose don't mix SwitchInst case indexing with low level indexing (TI successors indexing, User's operands indexing), since it may be dangerous.
2. By the same reason findCaseValue(ConstantInt*) returns actual number of case value. 0 means first case, not default. If there is no case with given value, ErrorIndex will returned.
3. Added getCaseSuccessor method. I propose to avoid usage of TerminatorInst::getSuccessor if you want to resolve case successor BB. Use getCaseSuccessor instead, since internal SwitchInst organization of operands/successors is hidden and may be changed in any moment.
4. Added resolveSuccessorIndex and resolveCaseIndex. The main purpose of these methods is to see how case successors are really mapped in TerminatorInst.
4.1 "resolveSuccessorIndex" was created if you need to level down from SwitchInst to TerminatorInst. It returns TerminatorInst's successor index for given case successor.
4.2 "resolveCaseIndex" converts low level successors index to case index that curresponds to the given successor.
Note: There are also related compatability fix patches for dragonegg, klee, llvm-gcc-4.0, llvm-gcc-4.2, safecode, clang.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149481 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-01 07:49:51 +00:00
|
|
|
void setDefaultDest(BasicBlock *DefaultCase) {
|
|
|
|
setOperand(1, reinterpret_cast<Value*>(DefaultCase));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getNumCases - return the number of 'cases' in this switch instruction,
|
|
|
|
/// except the default case
|
2004-07-29 12:17:34 +00:00
|
|
|
unsigned getNumCases() const {
|
SwitchInst refactoring.
The purpose of refactoring is to hide operand roles from SwitchInst user (programmer). If you want to play with operands directly, probably you will need lower level methods than SwitchInst ones (TerminatorInst or may be User). After this patch we can reorganize SwitchInst operands and successors as we want.
What was done:
1. Changed semantics of index inside the getCaseValue method:
getCaseValue(0) means "get first case", not a condition. Use getCondition() if you want to resolve the condition. I propose don't mix SwitchInst case indexing with low level indexing (TI successors indexing, User's operands indexing), since it may be dangerous.
2. By the same reason findCaseValue(ConstantInt*) returns actual number of case value. 0 means first case, not default. If there is no case with given value, ErrorIndex will returned.
3. Added getCaseSuccessor method. I propose to avoid usage of TerminatorInst::getSuccessor if you want to resolve case successor BB. Use getCaseSuccessor instead, since internal SwitchInst organization of operands/successors is hidden and may be changed in any moment.
4. Added resolveSuccessorIndex and resolveCaseIndex. The main purpose of these methods is to see how case successors are really mapped in TerminatorInst.
4.1 "resolveSuccessorIndex" was created if you need to level down from SwitchInst to TerminatorInst. It returns TerminatorInst's successor index for given case successor.
4.2 "resolveCaseIndex" converts low level successors index to case index that curresponds to the given successor.
Note: There are also related compatability fix patches for dragonegg, klee, llvm-gcc-4.0, llvm-gcc-4.2, safecode, clang.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149481 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-01 07:49:51 +00:00
|
|
|
return getNumOperands()/2 - 1;
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
2012-03-08 07:06:20 +00:00
|
|
|
/// Returns a read/write iterator that points to the first
|
|
|
|
/// case in SwitchInst.
|
2012-03-11 06:09:17 +00:00
|
|
|
CaseIt case_begin() {
|
Revert patches to add case-range support for PR1255.
The work on this project was left in an unfinished and inconsistent state.
Hopefully someone will eventually get a chance to implement this feature, but
in the meantime, it is better to put things back the way the were. I have
left support in the bitcode reader to handle the case-range bitcode format,
so that we do not lose bitcode compatibility with the llvm 3.3 release.
This reverts the following commits: 155464, 156374, 156377, 156613, 156704,
156757, 156804 156808, 156985, 157046, 157112, 157183, 157315, 157384, 157575,
157576, 157586, 157612, 157810, 157814, 157815, 157880, 157881, 157882, 157884,
157887, 157901, 158979, 157987, 157989, 158986, 158997, 159076, 159101, 159100,
159200, 159201, 159207, 159527, 159532, 159540, 159583, 159618, 159658, 159659,
159660, 159661, 159703, 159704, 160076, 167356, 172025, 186736
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190328 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-09 19:14:35 +00:00
|
|
|
return CaseIt(this, 0);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2012-03-08 07:06:20 +00:00
|
|
|
/// Returns a read-only iterator that points to the first
|
|
|
|
/// case in the SwitchInst.
|
2012-03-11 06:09:17 +00:00
|
|
|
ConstCaseIt case_begin() const {
|
Revert patches to add case-range support for PR1255.
The work on this project was left in an unfinished and inconsistent state.
Hopefully someone will eventually get a chance to implement this feature, but
in the meantime, it is better to put things back the way the were. I have
left support in the bitcode reader to handle the case-range bitcode format,
so that we do not lose bitcode compatibility with the llvm 3.3 release.
This reverts the following commits: 155464, 156374, 156377, 156613, 156704,
156757, 156804 156808, 156985, 157046, 157112, 157183, 157315, 157384, 157575,
157576, 157586, 157612, 157810, 157814, 157815, 157880, 157881, 157882, 157884,
157887, 157901, 158979, 157987, 157989, 158986, 158997, 159076, 159101, 159100,
159200, 159201, 159207, 159527, 159532, 159540, 159583, 159618, 159658, 159659,
159660, 159661, 159703, 159704, 160076, 167356, 172025, 186736
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190328 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-09 19:14:35 +00:00
|
|
|
return ConstCaseIt(this, 0);
|
SwitchInst refactoring.
The purpose of refactoring is to hide operand roles from SwitchInst user (programmer). If you want to play with operands directly, probably you will need lower level methods than SwitchInst ones (TerminatorInst or may be User). After this patch we can reorganize SwitchInst operands and successors as we want.
What was done:
1. Changed semantics of index inside the getCaseValue method:
getCaseValue(0) means "get first case", not a condition. Use getCondition() if you want to resolve the condition. I propose don't mix SwitchInst case indexing with low level indexing (TI successors indexing, User's operands indexing), since it may be dangerous.
2. By the same reason findCaseValue(ConstantInt*) returns actual number of case value. 0 means first case, not default. If there is no case with given value, ErrorIndex will returned.
3. Added getCaseSuccessor method. I propose to avoid usage of TerminatorInst::getSuccessor if you want to resolve case successor BB. Use getCaseSuccessor instead, since internal SwitchInst organization of operands/successors is hidden and may be changed in any moment.
4. Added resolveSuccessorIndex and resolveCaseIndex. The main purpose of these methods is to see how case successors are really mapped in TerminatorInst.
4.1 "resolveSuccessorIndex" was created if you need to level down from SwitchInst to TerminatorInst. It returns TerminatorInst's successor index for given case successor.
4.2 "resolveCaseIndex" converts low level successors index to case index that curresponds to the given successor.
Note: There are also related compatability fix patches for dragonegg, klee, llvm-gcc-4.0, llvm-gcc-4.2, safecode, clang.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149481 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-01 07:49:51 +00:00
|
|
|
}
|
2013-03-07 20:04:17 +00:00
|
|
|
|
2012-03-08 07:06:20 +00:00
|
|
|
/// Returns a read/write iterator that points one past the last
|
|
|
|
/// in the SwitchInst.
|
2012-03-11 06:09:17 +00:00
|
|
|
CaseIt case_end() {
|
Revert patches to add case-range support for PR1255.
The work on this project was left in an unfinished and inconsistent state.
Hopefully someone will eventually get a chance to implement this feature, but
in the meantime, it is better to put things back the way the were. I have
left support in the bitcode reader to handle the case-range bitcode format,
so that we do not lose bitcode compatibility with the llvm 3.3 release.
This reverts the following commits: 155464, 156374, 156377, 156613, 156704,
156757, 156804 156808, 156985, 157046, 157112, 157183, 157315, 157384, 157575,
157576, 157586, 157612, 157810, 157814, 157815, 157880, 157881, 157882, 157884,
157887, 157901, 158979, 157987, 157989, 158986, 158997, 159076, 159101, 159100,
159200, 159201, 159207, 159527, 159532, 159540, 159583, 159618, 159658, 159659,
159660, 159661, 159703, 159704, 160076, 167356, 172025, 186736
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190328 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-09 19:14:35 +00:00
|
|
|
return CaseIt(this, getNumCases());
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2012-03-08 07:06:20 +00:00
|
|
|
/// Returns a read-only iterator that points one past the last
|
|
|
|
/// in the SwitchInst.
|
2012-03-11 06:09:17 +00:00
|
|
|
ConstCaseIt case_end() const {
|
Revert patches to add case-range support for PR1255.
The work on this project was left in an unfinished and inconsistent state.
Hopefully someone will eventually get a chance to implement this feature, but
in the meantime, it is better to put things back the way the were. I have
left support in the bitcode reader to handle the case-range bitcode format,
so that we do not lose bitcode compatibility with the llvm 3.3 release.
This reverts the following commits: 155464, 156374, 156377, 156613, 156704,
156757, 156804 156808, 156985, 157046, 157112, 157183, 157315, 157384, 157575,
157576, 157586, 157612, 157810, 157814, 157815, 157880, 157881, 157882, 157884,
157887, 157901, 158979, 157987, 157989, 158986, 158997, 159076, 159101, 159100,
159200, 159201, 159207, 159527, 159532, 159540, 159583, 159618, 159658, 159659,
159660, 159661, 159703, 159704, 160076, 167356, 172025, 186736
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190328 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-09 19:14:35 +00:00
|
|
|
return ConstCaseIt(this, getNumCases());
|
SwitchInst refactoring.
The purpose of refactoring is to hide operand roles from SwitchInst user (programmer). If you want to play with operands directly, probably you will need lower level methods than SwitchInst ones (TerminatorInst or may be User). After this patch we can reorganize SwitchInst operands and successors as we want.
What was done:
1. Changed semantics of index inside the getCaseValue method:
getCaseValue(0) means "get first case", not a condition. Use getCondition() if you want to resolve the condition. I propose don't mix SwitchInst case indexing with low level indexing (TI successors indexing, User's operands indexing), since it may be dangerous.
2. By the same reason findCaseValue(ConstantInt*) returns actual number of case value. 0 means first case, not default. If there is no case with given value, ErrorIndex will returned.
3. Added getCaseSuccessor method. I propose to avoid usage of TerminatorInst::getSuccessor if you want to resolve case successor BB. Use getCaseSuccessor instead, since internal SwitchInst organization of operands/successors is hidden and may be changed in any moment.
4. Added resolveSuccessorIndex and resolveCaseIndex. The main purpose of these methods is to see how case successors are really mapped in TerminatorInst.
4.1 "resolveSuccessorIndex" was created if you need to level down from SwitchInst to TerminatorInst. It returns TerminatorInst's successor index for given case successor.
4.2 "resolveCaseIndex" converts low level successors index to case index that curresponds to the given successor.
Note: There are also related compatability fix patches for dragonegg, klee, llvm-gcc-4.0, llvm-gcc-4.2, safecode, clang.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149481 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-01 07:49:51 +00:00
|
|
|
}
|
2014-07-02 05:32:13 +00:00
|
|
|
|
|
|
|
/// cases - iteration adapter for range-for loops.
|
|
|
|
iterator_range<CaseIt> cases() {
|
|
|
|
return iterator_range<CaseIt>(case_begin(), case_end());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// cases - iteration adapter for range-for loops.
|
|
|
|
iterator_range<ConstCaseIt> cases() const {
|
|
|
|
return iterator_range<ConstCaseIt>(case_begin(), case_end());
|
|
|
|
}
|
|
|
|
|
2012-03-11 06:09:17 +00:00
|
|
|
/// Returns an iterator that points to the default case.
|
2012-03-08 07:06:20 +00:00
|
|
|
/// Note: this iterator allows to resolve successor only. Attempt
|
|
|
|
/// to resolve case value causes an assertion.
|
2012-03-11 06:09:17 +00:00
|
|
|
/// Also note, that increment and decrement also causes an assertion and
|
2013-03-07 20:04:17 +00:00
|
|
|
/// makes iterator invalid.
|
2012-03-11 06:09:17 +00:00
|
|
|
CaseIt case_default() {
|
Revert patches to add case-range support for PR1255.
The work on this project was left in an unfinished and inconsistent state.
Hopefully someone will eventually get a chance to implement this feature, but
in the meantime, it is better to put things back the way the were. I have
left support in the bitcode reader to handle the case-range bitcode format,
so that we do not lose bitcode compatibility with the llvm 3.3 release.
This reverts the following commits: 155464, 156374, 156377, 156613, 156704,
156757, 156804 156808, 156985, 157046, 157112, 157183, 157315, 157384, 157575,
157576, 157586, 157612, 157810, 157814, 157815, 157880, 157881, 157882, 157884,
157887, 157901, 158979, 157987, 157989, 158986, 158997, 159076, 159101, 159100,
159200, 159201, 159207, 159527, 159532, 159540, 159583, 159618, 159658, 159659,
159660, 159661, 159703, 159704, 160076, 167356, 172025, 186736
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190328 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-09 19:14:35 +00:00
|
|
|
return CaseIt(this, DefaultPseudoIndex);
|
2012-03-08 07:06:20 +00:00
|
|
|
}
|
2012-03-11 06:09:17 +00:00
|
|
|
ConstCaseIt case_default() const {
|
Revert patches to add case-range support for PR1255.
The work on this project was left in an unfinished and inconsistent state.
Hopefully someone will eventually get a chance to implement this feature, but
in the meantime, it is better to put things back the way the were. I have
left support in the bitcode reader to handle the case-range bitcode format,
so that we do not lose bitcode compatibility with the llvm 3.3 release.
This reverts the following commits: 155464, 156374, 156377, 156613, 156704,
156757, 156804 156808, 156985, 157046, 157112, 157183, 157315, 157384, 157575,
157576, 157586, 157612, 157810, 157814, 157815, 157880, 157881, 157882, 157884,
157887, 157901, 158979, 157987, 157989, 158986, 158997, 159076, 159101, 159100,
159200, 159201, 159207, 159527, 159532, 159540, 159583, 159618, 159658, 159659,
159660, 159661, 159703, 159704, 160076, 167356, 172025, 186736
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190328 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-09 19:14:35 +00:00
|
|
|
return ConstCaseIt(this, DefaultPseudoIndex);
|
SwitchInst refactoring.
The purpose of refactoring is to hide operand roles from SwitchInst user (programmer). If you want to play with operands directly, probably you will need lower level methods than SwitchInst ones (TerminatorInst or may be User). After this patch we can reorganize SwitchInst operands and successors as we want.
What was done:
1. Changed semantics of index inside the getCaseValue method:
getCaseValue(0) means "get first case", not a condition. Use getCondition() if you want to resolve the condition. I propose don't mix SwitchInst case indexing with low level indexing (TI successors indexing, User's operands indexing), since it may be dangerous.
2. By the same reason findCaseValue(ConstantInt*) returns actual number of case value. 0 means first case, not default. If there is no case with given value, ErrorIndex will returned.
3. Added getCaseSuccessor method. I propose to avoid usage of TerminatorInst::getSuccessor if you want to resolve case successor BB. Use getCaseSuccessor instead, since internal SwitchInst organization of operands/successors is hidden and may be changed in any moment.
4. Added resolveSuccessorIndex and resolveCaseIndex. The main purpose of these methods is to see how case successors are really mapped in TerminatorInst.
4.1 "resolveSuccessorIndex" was created if you need to level down from SwitchInst to TerminatorInst. It returns TerminatorInst's successor index for given case successor.
4.2 "resolveCaseIndex" converts low level successors index to case index that curresponds to the given successor.
Note: There are also related compatability fix patches for dragonegg, klee, llvm-gcc-4.0, llvm-gcc-4.2, safecode, clang.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149481 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-01 07:49:51 +00:00
|
|
|
}
|
2013-03-07 20:04:17 +00:00
|
|
|
|
2012-03-08 07:06:20 +00:00
|
|
|
/// findCaseValue - Search all of the case values for the specified constant.
|
|
|
|
/// If it is explicitly handled, return the case iterator of it, otherwise
|
|
|
|
/// return default case iterator to indicate
|
|
|
|
/// that it is handled by the default handler.
|
|
|
|
CaseIt findCaseValue(const ConstantInt *C) {
|
2012-03-11 06:09:17 +00:00
|
|
|
for (CaseIt i = case_begin(), e = case_end(); i != e; ++i)
|
Revert patches to add case-range support for PR1255.
The work on this project was left in an unfinished and inconsistent state.
Hopefully someone will eventually get a chance to implement this feature, but
in the meantime, it is better to put things back the way the were. I have
left support in the bitcode reader to handle the case-range bitcode format,
so that we do not lose bitcode compatibility with the llvm 3.3 release.
This reverts the following commits: 155464, 156374, 156377, 156613, 156704,
156757, 156804 156808, 156985, 157046, 157112, 157183, 157315, 157384, 157575,
157576, 157586, 157612, 157810, 157814, 157815, 157880, 157881, 157882, 157884,
157887, 157901, 158979, 157987, 157989, 158986, 158997, 159076, 159101, 159100,
159200, 159201, 159207, 159527, 159532, 159540, 159583, 159618, 159658, 159659,
159660, 159661, 159703, 159704, 160076, 167356, 172025, 186736
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190328 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-09 19:14:35 +00:00
|
|
|
if (i.getCaseValue() == C)
|
2012-03-08 07:06:20 +00:00
|
|
|
return i;
|
2012-03-11 06:09:17 +00:00
|
|
|
return case_default();
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2012-03-08 07:06:20 +00:00
|
|
|
ConstCaseIt findCaseValue(const ConstantInt *C) const {
|
2012-03-11 06:09:17 +00:00
|
|
|
for (ConstCaseIt i = case_begin(), e = case_end(); i != e; ++i)
|
Revert patches to add case-range support for PR1255.
The work on this project was left in an unfinished and inconsistent state.
Hopefully someone will eventually get a chance to implement this feature, but
in the meantime, it is better to put things back the way the were. I have
left support in the bitcode reader to handle the case-range bitcode format,
so that we do not lose bitcode compatibility with the llvm 3.3 release.
This reverts the following commits: 155464, 156374, 156377, 156613, 156704,
156757, 156804 156808, 156985, 157046, 157112, 157183, 157315, 157384, 157575,
157576, 157586, 157612, 157810, 157814, 157815, 157880, 157881, 157882, 157884,
157887, 157901, 158979, 157987, 157989, 158986, 158997, 159076, 159101, 159100,
159200, 159201, 159207, 159527, 159532, 159540, 159583, 159618, 159658, 159659,
159660, 159661, 159703, 159704, 160076, 167356, 172025, 186736
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190328 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-09 19:14:35 +00:00
|
|
|
if (i.getCaseValue() == C)
|
2012-03-08 07:06:20 +00:00
|
|
|
return i;
|
2012-03-11 06:09:17 +00:00
|
|
|
return case_default();
|
2013-03-07 20:04:17 +00:00
|
|
|
}
|
|
|
|
|
2006-09-18 19:03:59 +00:00
|
|
|
/// findCaseDest - Finds the unique case value for a given successor. Returns
|
|
|
|
/// null if the successor is not found, not unique, or is the default case.
|
|
|
|
ConstantInt *findCaseDest(BasicBlock *BB) {
|
2014-04-09 06:08:46 +00:00
|
|
|
if (BB == getDefaultDest()) return nullptr;
|
2006-09-18 20:44:37 +00:00
|
|
|
|
2014-04-09 06:08:46 +00:00
|
|
|
ConstantInt *CI = nullptr;
|
2012-03-11 06:09:17 +00:00
|
|
|
for (CaseIt i = case_begin(), e = case_end(); i != e; ++i) {
|
2012-03-08 07:06:20 +00:00
|
|
|
if (i.getCaseSuccessor() == BB) {
|
2014-04-09 06:08:46 +00:00
|
|
|
if (CI) return nullptr; // Multiple cases lead to BB.
|
2012-03-08 07:06:20 +00:00
|
|
|
else CI = i.getCaseValue();
|
2006-09-18 19:03:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return CI;
|
|
|
|
}
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
/// addCase - Add an entry to the switch instruction...
|
2012-03-13 12:37:10 +00:00
|
|
|
/// Note:
|
|
|
|
/// This action invalidates case_end(). Old case_end() iterator will
|
|
|
|
/// point to the added case.
|
2005-02-24 05:32:09 +00:00
|
|
|
void addCase(ConstantInt *OnVal, BasicBlock *Dest);
|
2013-03-07 20:04:17 +00:00
|
|
|
|
SwitchInst refactoring.
The purpose of refactoring is to hide operand roles from SwitchInst user (programmer). If you want to play with operands directly, probably you will need lower level methods than SwitchInst ones (TerminatorInst or may be User). After this patch we can reorganize SwitchInst operands and successors as we want.
What was done:
1. Changed semantics of index inside the getCaseValue method:
getCaseValue(0) means "get first case", not a condition. Use getCondition() if you want to resolve the condition. I propose don't mix SwitchInst case indexing with low level indexing (TI successors indexing, User's operands indexing), since it may be dangerous.
2. By the same reason findCaseValue(ConstantInt*) returns actual number of case value. 0 means first case, not default. If there is no case with given value, ErrorIndex will returned.
3. Added getCaseSuccessor method. I propose to avoid usage of TerminatorInst::getSuccessor if you want to resolve case successor BB. Use getCaseSuccessor instead, since internal SwitchInst organization of operands/successors is hidden and may be changed in any moment.
4. Added resolveSuccessorIndex and resolveCaseIndex. The main purpose of these methods is to see how case successors are really mapped in TerminatorInst.
4.1 "resolveSuccessorIndex" was created if you need to level down from SwitchInst to TerminatorInst. It returns TerminatorInst's successor index for given case successor.
4.2 "resolveCaseIndex" converts low level successors index to case index that curresponds to the given successor.
Note: There are also related compatability fix patches for dragonegg, klee, llvm-gcc-4.0, llvm-gcc-4.2, safecode, clang.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149481 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-01 07:49:51 +00:00
|
|
|
/// removeCase - This method removes the specified case and its successor
|
|
|
|
/// from the switch instruction. Note that this operation may reorder the
|
2011-02-01 09:22:34 +00:00
|
|
|
/// remaining cases at index idx and above.
|
2012-03-13 12:37:10 +00:00
|
|
|
/// Note:
|
|
|
|
/// This action invalidates iterators for all cases following the one removed,
|
|
|
|
/// including the case_end() iterator.
|
Revert patches to add case-range support for PR1255.
The work on this project was left in an unfinished and inconsistent state.
Hopefully someone will eventually get a chance to implement this feature, but
in the meantime, it is better to put things back the way the were. I have
left support in the bitcode reader to handle the case-range bitcode format,
so that we do not lose bitcode compatibility with the llvm 3.3 release.
This reverts the following commits: 155464, 156374, 156377, 156613, 156704,
156757, 156804 156808, 156985, 157046, 157112, 157183, 157315, 157384, 157575,
157576, 157586, 157612, 157810, 157814, 157815, 157880, 157881, 157882, 157884,
157887, 157901, 158979, 157987, 157989, 158986, 158997, 159076, 159101, 159100,
159200, 159201, 159207, 159527, 159532, 159540, 159583, 159618, 159658, 159659,
159660, 159661, 159703, 159704, 160076, 167356, 172025, 186736
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190328 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-09 19:14:35 +00:00
|
|
|
void removeCase(CaseIt i);
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
unsigned getNumSuccessors() const { return getNumOperands()/2; }
|
|
|
|
BasicBlock *getSuccessor(unsigned idx) const {
|
2004-07-29 12:17:34 +00:00
|
|
|
assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!");
|
2005-01-29 00:31:36 +00:00
|
|
|
return cast<BasicBlock>(getOperand(idx*2+1));
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
|
2004-07-29 12:17:34 +00:00
|
|
|
assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
|
2009-10-27 16:49:53 +00:00
|
|
|
setOperand(idx*2+1, (Value*)NewSucc);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2013-03-07 20:04:17 +00:00
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
2005-02-24 05:32:09 +00:00
|
|
|
return I->getOpcode() == Instruction::Switch;
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
private:
|
2014-03-05 06:35:38 +00:00
|
|
|
BasicBlock *getSuccessorV(unsigned idx) const override;
|
|
|
|
unsigned getNumSuccessorsV() const override;
|
|
|
|
void setSuccessorV(unsigned idx, BasicBlock *B) override;
|
2004-07-29 12:17:34 +00:00
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2009-09-06 08:55:57 +00:00
|
|
|
struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)
|
2008-05-10 08:32:32 +00:00
|
|
|
|
|
|
|
|
2009-10-27 19:13:16 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-10-28 00:19:10 +00:00
|
|
|
// IndirectBrInst Class
|
2009-10-27 19:13:16 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
2009-10-28 00:19:10 +00:00
|
|
|
/// IndirectBrInst - Indirect Branch Instruction.
|
2009-10-27 19:13:16 +00:00
|
|
|
///
|
2009-10-28 00:19:10 +00:00
|
|
|
class IndirectBrInst : public TerminatorInst {
|
2012-09-18 03:25:49 +00:00
|
|
|
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
|
2009-10-27 19:13:16 +00:00
|
|
|
unsigned ReservedSpace;
|
|
|
|
// Operand[0] = Value to switch on
|
|
|
|
// Operand[1] = Default basic block destination
|
|
|
|
// Operand[2n ] = Value to match
|
|
|
|
// Operand[2n+1] = BasicBlock to go to on match
|
2009-10-28 00:19:10 +00:00
|
|
|
IndirectBrInst(const IndirectBrInst &IBI);
|
2009-10-27 19:13:16 +00:00
|
|
|
void init(Value *Address, unsigned NumDests);
|
2011-04-01 08:00:58 +00:00
|
|
|
void growOperands();
|
2009-10-27 19:13:16 +00:00
|
|
|
// allocate space for exactly zero operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 0);
|
|
|
|
}
|
2009-10-28 00:19:10 +00:00
|
|
|
/// IndirectBrInst ctor - 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
|
2009-10-27 19:13:16 +00:00
|
|
|
/// autoinsert before another instruction.
|
2009-10-28 00:19:10 +00:00
|
|
|
IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-10-28 00:19:10 +00:00
|
|
|
/// IndirectBrInst ctor - 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);
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
IndirectBrInst *clone_impl() const override;
|
2009-10-27 19:13:16 +00:00
|
|
|
public:
|
2009-10-28 00:19:10 +00:00
|
|
|
static IndirectBrInst *Create(Value *Address, unsigned NumDests,
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr) {
|
2009-10-28 00:19:10 +00:00
|
|
|
return new IndirectBrInst(Address, NumDests, InsertBefore);
|
2009-10-27 19:13:16 +00:00
|
|
|
}
|
2009-10-28 00:19:10 +00:00
|
|
|
static IndirectBrInst *Create(Value *Address, unsigned NumDests,
|
|
|
|
BasicBlock *InsertAtEnd) {
|
|
|
|
return new IndirectBrInst(Address, NumDests, InsertAtEnd);
|
2009-10-27 19:13:16 +00:00
|
|
|
}
|
2009-10-28 00:19:10 +00:00
|
|
|
~IndirectBrInst();
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-10-27 19:13:16 +00:00
|
|
|
/// Provide fast operand accessors.
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-10-28 00:19:10 +00:00
|
|
|
// Accessor Methods for IndirectBrInst instruction.
|
2009-10-27 19:13:16 +00:00
|
|
|
Value *getAddress() { return getOperand(0); }
|
|
|
|
const Value *getAddress() const { return getOperand(0); }
|
|
|
|
void setAddress(Value *V) { setOperand(0, V); }
|
2010-10-27 07:39:48 +00:00
|
|
|
|
|
|
|
|
2009-10-27 19:13:16 +00:00
|
|
|
/// getNumDestinations - return the number of possible destinations in this
|
2009-10-28 00:19:10 +00:00
|
|
|
/// indirectbr instruction.
|
2009-10-27 19:13:16 +00:00
|
|
|
unsigned getNumDestinations() const { return getNumOperands()-1; }
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-10-27 19:13:16 +00:00
|
|
|
/// getDestination - Return the specified destination.
|
|
|
|
BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
|
|
|
|
const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-10-27 19:13:16 +00:00
|
|
|
/// addDestination - Add a destination.
|
|
|
|
///
|
|
|
|
void addDestination(BasicBlock *Dest);
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-10-27 19:13:16 +00:00
|
|
|
/// removeDestination - This method removes the specified successor from the
|
2009-10-28 00:19:10 +00:00
|
|
|
/// indirectbr instruction.
|
2009-10-27 19:13:16 +00:00
|
|
|
void removeDestination(unsigned i);
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-10-27 19:13:16 +00:00
|
|
|
unsigned getNumSuccessors() const { return getNumOperands()-1; }
|
|
|
|
BasicBlock *getSuccessor(unsigned i) const {
|
|
|
|
return cast<BasicBlock>(getOperand(i+1));
|
|
|
|
}
|
|
|
|
void setSuccessor(unsigned i, BasicBlock *NewSucc) {
|
|
|
|
setOperand(i+1, (Value*)NewSucc);
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-10-27 19:13:16 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
2009-10-28 00:19:10 +00:00
|
|
|
return I->getOpcode() == Instruction::IndirectBr;
|
2009-10-27 19:13:16 +00:00
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
private:
|
2014-03-05 06:35:38 +00:00
|
|
|
BasicBlock *getSuccessorV(unsigned idx) const override;
|
|
|
|
unsigned getNumSuccessorsV() const override;
|
|
|
|
void setSuccessorV(unsigned idx, BasicBlock *B) override;
|
2009-10-27 19:13:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
2009-10-28 00:19:10 +00:00
|
|
|
struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
|
2009-10-27 19:13:16 +00:00
|
|
|
};
|
|
|
|
|
2009-10-28 00:19:10 +00:00
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)
|
2010-10-27 07:39:48 +00:00
|
|
|
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// InvokeInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2005-05-06 20:26:26 +00:00
|
|
|
/// InvokeInst - Invoke instruction. The SubclassData field is used to hold the
|
|
|
|
/// calling convention of the call.
|
2004-07-29 12:17:34 +00:00
|
|
|
///
|
|
|
|
class InvokeInst : public TerminatorInst {
|
2012-12-07 23:16:57 +00:00
|
|
|
AttributeSet AttributeList;
|
2004-07-29 12:17:34 +00:00
|
|
|
InvokeInst(const InvokeInst &BI);
|
2007-08-27 19:04:21 +00:00
|
|
|
void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
|
2011-07-15 08:37:34 +00:00
|
|
|
ArrayRef<Value *> Args, const Twine &NameStr);
|
2007-08-27 19:04:21 +00:00
|
|
|
|
|
|
|
/// Construct an InvokeInst given a range of arguments.
|
|
|
|
///
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Construct an InvokeInst from a range of arguments
|
2008-05-10 08:32:32 +00:00
|
|
|
inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
|
2011-07-15 08:37:34 +00:00
|
|
|
ArrayRef<Value *> Args, unsigned Values,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, Instruction *InsertBefore);
|
2007-08-27 19:04:21 +00:00
|
|
|
|
|
|
|
/// Construct an InvokeInst given a range of arguments.
|
|
|
|
///
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Construct an InvokeInst from a range of arguments
|
2008-05-10 08:32:32 +00:00
|
|
|
inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
|
2011-07-15 08:37:34 +00:00
|
|
|
ArrayRef<Value *> Args, unsigned Values,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd);
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
InvokeInst *clone_impl() const override;
|
2008-04-06 20:25:17 +00:00
|
|
|
public:
|
2008-05-10 08:32:32 +00:00
|
|
|
static InvokeInst *Create(Value *Func,
|
|
|
|
BasicBlock *IfNormal, BasicBlock *IfException,
|
2011-07-15 08:37:34 +00:00
|
|
|
ArrayRef<Value *> Args, const Twine &NameStr = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
Instruction *InsertBefore = nullptr) {
|
2011-07-15 08:37:34 +00:00
|
|
|
unsigned Values = unsigned(Args.size()) + 3;
|
|
|
|
return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
|
2008-07-24 00:08:56 +00:00
|
|
|
Values, NameStr, InsertBefore);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2008-05-10 08:32:32 +00:00
|
|
|
static InvokeInst *Create(Value *Func,
|
|
|
|
BasicBlock *IfNormal, BasicBlock *IfException,
|
2011-07-15 08:37:34 +00:00
|
|
|
ArrayRef<Value *> Args, const Twine &NameStr,
|
2008-07-24 00:08:56 +00:00
|
|
|
BasicBlock *InsertAtEnd) {
|
2011-07-15 08:37:34 +00:00
|
|
|
unsigned Values = unsigned(Args.size()) + 3;
|
|
|
|
return new(Values) InvokeInst(Func, IfNormal, IfException, Args,
|
2008-07-24 00:08:56 +00:00
|
|
|
Values, NameStr, InsertAtEnd);
|
2008-04-06 20:25:17 +00:00
|
|
|
}
|
2007-08-27 19:04:21 +00:00
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
/// Provide fast operand accessors
|
|
|
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
2009-02-09 17:11:05 +00:00
|
|
|
|
2010-07-31 08:35:21 +00:00
|
|
|
/// getNumArgOperands - Return the number of invoke arguments.
|
|
|
|
///
|
2010-06-07 19:05:06 +00:00
|
|
|
unsigned getNumArgOperands() const { return getNumOperands() - 3; }
|
2010-07-31 08:35:21 +00:00
|
|
|
|
|
|
|
/// getArgOperand/setArgOperand - Return/set the i-th invoke argument.
|
|
|
|
///
|
2010-06-07 19:05:06 +00:00
|
|
|
Value *getArgOperand(unsigned i) const { return getOperand(i); }
|
2010-06-28 12:23:36 +00:00
|
|
|
void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
|
2010-06-07 19:05:06 +00:00
|
|
|
|
2014-03-26 18:18:02 +00:00
|
|
|
/// arg_operands - iteration adapter for range-for loops.
|
|
|
|
iterator_range<op_iterator> arg_operands() {
|
2014-03-26 20:41:15 +00:00
|
|
|
return iterator_range<op_iterator>(op_begin(), op_end() - 3);
|
2014-03-26 18:18:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// arg_operands - iteration adapter for range-for loops.
|
|
|
|
iterator_range<const_op_iterator> arg_operands() const {
|
2014-03-26 20:41:15 +00:00
|
|
|
return iterator_range<const_op_iterator>(op_begin(), op_end() - 3);
|
2014-03-26 18:18:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Wrappers for getting the \c Use of a invoke argument.
|
2014-02-25 03:34:17 +00:00
|
|
|
const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
|
|
|
|
Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
|
|
|
|
|
2005-05-06 20:26:26 +00:00
|
|
|
/// getCallingConv/setCallingConv - Get or set the calling convention of this
|
|
|
|
/// function call.
|
2009-09-02 08:44:58 +00:00
|
|
|
CallingConv::ID getCallingConv() const {
|
2009-12-29 02:46:09 +00:00
|
|
|
return static_cast<CallingConv::ID>(getSubclassDataFromInstruction());
|
2009-09-02 08:44:58 +00:00
|
|
|
}
|
|
|
|
void setCallingConv(CallingConv::ID CC) {
|
2009-12-29 02:46:09 +00:00
|
|
|
setInstructionSubclassData(static_cast<unsigned>(CC));
|
2005-05-06 20:26:26 +00:00
|
|
|
}
|
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// getAttributes - Return the parameter attributes for this invoke.
|
2008-03-12 17:45:29 +00:00
|
|
|
///
|
2012-12-07 23:16:57 +00:00
|
|
|
const AttributeSet &getAttributes() const { return AttributeList; }
|
2007-04-09 18:00:57 +00:00
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// setAttributes - Set the parameter attributes for this invoke.
|
2008-03-12 17:45:29 +00:00
|
|
|
///
|
2012-12-07 23:16:57 +00:00
|
|
|
void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
|
2007-11-27 13:23:08 +00:00
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// addAttribute - adds the attribute to the list of attributes.
|
2013-03-02 01:20:18 +00:00
|
|
|
void addAttribute(unsigned i, Attribute::AttrKind attr);
|
2007-11-28 17:07:01 +00:00
|
|
|
|
2008-09-25 21:00:45 +00:00
|
|
|
/// removeAttribute - removes the attribute from the list of attributes.
|
2012-12-19 07:18:57 +00:00
|
|
|
void removeAttribute(unsigned i, Attribute attr);
|
2008-07-08 08:38:44 +00:00
|
|
|
|
2013-10-31 17:25:22 +00:00
|
|
|
/// \brief Determine whether this call has the given attribute.
|
2013-06-27 00:25:01 +00:00
|
|
|
bool hasFnAttr(Attribute::AttrKind A) const {
|
|
|
|
assert(A != Attribute::NoBuiltin &&
|
|
|
|
"Use CallInst::isNoBuiltin() to check for Attribute::NoBuiltin");
|
|
|
|
return hasFnAttrImpl(A);
|
|
|
|
}
|
2012-10-09 00:28:54 +00:00
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Determine whether the call or the callee has the given attributes.
|
2012-12-22 00:37:52 +00:00
|
|
|
bool paramHasAttr(unsigned i, Attribute::AttrKind A) const;
|
2012-10-03 17:54:26 +00:00
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Extract the alignment for a call or parameter (0=unknown).
|
2008-03-13 05:00:21 +00:00
|
|
|
unsigned getParamAlignment(unsigned i) const {
|
2008-09-25 21:00:45 +00:00
|
|
|
return AttributeList.getParamAlignment(i);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2008-02-22 17:49:45 +00:00
|
|
|
|
2013-06-27 00:25:01 +00:00
|
|
|
/// \brief Return true if the call should not be treated as a call to a
|
|
|
|
/// builtin.
|
|
|
|
bool isNoBuiltin() const {
|
|
|
|
// We assert in hasFnAttr if one passes in Attribute::NoBuiltin, so we have
|
|
|
|
// to check it by hand.
|
|
|
|
return hasFnAttrImpl(Attribute::NoBuiltin) &&
|
|
|
|
!hasFnAttrImpl(Attribute::Builtin);
|
|
|
|
}
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Return true if the call should not be inlined.
|
2012-12-19 07:18:57 +00:00
|
|
|
bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
|
2012-10-09 23:40:31 +00:00
|
|
|
void setIsNoInline() {
|
2013-03-02 01:20:18 +00:00
|
|
|
addAttribute(AttributeSet::FunctionIndex, Attribute::NoInline);
|
2010-03-25 04:49:10 +00:00
|
|
|
}
|
2010-07-06 03:53:22 +00:00
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Determine if the call does not access memory.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool doesNotAccessMemory() const {
|
2012-12-19 07:18:57 +00:00
|
|
|
return hasFnAttr(Attribute::ReadNone);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2012-10-09 23:40:31 +00:00
|
|
|
void setDoesNotAccessMemory() {
|
2013-03-02 01:20:18 +00:00
|
|
|
addAttribute(AttributeSet::FunctionIndex, Attribute::ReadNone);
|
2008-07-08 08:38:44 +00:00
|
|
|
}
|
2007-12-03 20:06:50 +00:00
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Determine if the call does not access or only reads memory.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool onlyReadsMemory() const {
|
2012-12-19 07:18:57 +00:00
|
|
|
return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2012-10-09 23:40:31 +00:00
|
|
|
void setOnlyReadsMemory() {
|
2013-03-02 01:20:18 +00:00
|
|
|
addAttribute(AttributeSet::FunctionIndex, Attribute::ReadOnly);
|
2008-07-08 08:38:44 +00:00
|
|
|
}
|
2007-12-03 20:06:50 +00:00
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Determine if the call cannot return.
|
2012-12-19 07:18:57 +00:00
|
|
|
bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
|
2012-10-09 23:40:31 +00:00
|
|
|
void setDoesNotReturn() {
|
2013-03-02 01:20:18 +00:00
|
|
|
addAttribute(AttributeSet::FunctionIndex, Attribute::NoReturn);
|
2008-07-08 08:38:44 +00:00
|
|
|
}
|
2007-12-10 19:09:40 +00:00
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Determine if the call cannot unwind.
|
2012-12-19 07:18:57 +00:00
|
|
|
bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
|
2012-10-09 23:40:31 +00:00
|
|
|
void setDoesNotThrow() {
|
2013-03-02 01:20:18 +00:00
|
|
|
addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
|
2008-07-08 08:38:44 +00:00
|
|
|
}
|
2007-12-03 20:06:50 +00:00
|
|
|
|
2014-03-17 16:19:07 +00:00
|
|
|
/// \brief Determine if the invoke cannot be duplicated.
|
|
|
|
bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
|
|
|
|
void setCannotDuplicate() {
|
|
|
|
addAttribute(AttributeSet::FunctionIndex, Attribute::NoDuplicate);
|
|
|
|
}
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Determine if the call returns a structure through first
|
2008-03-03 21:46:28 +00:00
|
|
|
/// pointer argument.
|
2008-03-13 05:00:21 +00:00
|
|
|
bool hasStructRetAttr() const {
|
|
|
|
// Be friendly and also check the callee.
|
2012-12-19 07:18:57 +00:00
|
|
|
return paramHasAttr(1, Attribute::StructRet);
|
2008-03-13 05:00:21 +00:00
|
|
|
}
|
2007-04-09 18:00:57 +00:00
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Determine if any call argument is an aggregate passed by value.
|
2008-09-26 21:38:45 +00:00
|
|
|
bool hasByValArgument() const {
|
2012-12-31 00:49:59 +00:00
|
|
|
return AttributeList.hasAttrSomewhere(Attribute::ByVal);
|
2008-09-26 21:38:45 +00:00
|
|
|
}
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
/// getCalledFunction - Return the function called, or null if this is an
|
2004-11-18 17:46:57 +00:00
|
|
|
/// indirect function invocation.
|
2004-07-29 12:17:34 +00:00
|
|
|
///
|
2004-11-18 17:46:57 +00:00
|
|
|
Function *getCalledFunction() const {
|
2010-03-24 13:21:49 +00:00
|
|
|
return dyn_cast<Function>(Op<-3>());
|
2004-11-18 17:46:57 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2009-02-09 17:11:05 +00:00
|
|
|
/// getCalledValue - Get a pointer to the function that is invoked by this
|
2008-09-26 21:38:45 +00:00
|
|
|
/// instruction
|
2010-03-24 13:21:49 +00:00
|
|
|
const Value *getCalledValue() const { return Op<-3>(); }
|
|
|
|
Value *getCalledValue() { return Op<-3>(); }
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2010-03-20 21:00:25 +00:00
|
|
|
/// setCalledFunction - Set the function called.
|
|
|
|
void setCalledFunction(Value* Fn) {
|
2010-03-24 13:21:49 +00:00
|
|
|
Op<-3>() = Fn;
|
2010-03-20 21:00:25 +00:00
|
|
|
}
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
// get*Dest - Return the destination basic blocks...
|
2005-01-29 00:31:36 +00:00
|
|
|
BasicBlock *getNormalDest() const {
|
2010-03-24 13:21:49 +00:00
|
|
|
return cast<BasicBlock>(Op<-2>());
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
BasicBlock *getUnwindDest() const {
|
2010-03-24 13:21:49 +00:00
|
|
|
return cast<BasicBlock>(Op<-1>());
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
void setNormalDest(BasicBlock *B) {
|
2010-03-24 13:21:49 +00:00
|
|
|
Op<-2>() = reinterpret_cast<Value*>(B);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
void setUnwindDest(BasicBlock *B) {
|
2010-03-24 13:21:49 +00:00
|
|
|
Op<-1>() = reinterpret_cast<Value*>(B);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
2011-08-12 20:24:12 +00:00
|
|
|
/// getLandingPadInst - Get the landingpad instruction from the landing pad
|
|
|
|
/// block (the unwind destination).
|
|
|
|
LandingPadInst *getLandingPadInst() const;
|
|
|
|
|
2008-02-23 01:11:02 +00:00
|
|
|
BasicBlock *getSuccessor(unsigned i) const {
|
2004-07-29 12:17:34 +00:00
|
|
|
assert(i < 2 && "Successor # out of range for invoke!");
|
|
|
|
return i == 0 ? getNormalDest() : getUnwindDest();
|
|
|
|
}
|
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
|
2004-07-29 12:17:34 +00:00
|
|
|
assert(idx < 2 && "Successor # out of range for invoke!");
|
2010-03-24 13:21:49 +00:00
|
|
|
*(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
|
2004-07-29 12:17:34 +00:00
|
|
|
}
|
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
unsigned getNumSuccessors() const { return 2; }
|
2004-07-29 12:17:34 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return (I->getOpcode() == Instruction::Invoke);
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2010-03-24 13:21:49 +00:00
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
private:
|
2014-03-05 06:35:38 +00:00
|
|
|
BasicBlock *getSuccessorV(unsigned idx) const override;
|
|
|
|
unsigned getNumSuccessorsV() const override;
|
|
|
|
void setSuccessorV(unsigned idx, BasicBlock *B) override;
|
2009-12-29 02:14:09 +00:00
|
|
|
|
2013-06-27 00:25:01 +00:00
|
|
|
bool hasFnAttrImpl(Attribute::AttrKind A) const;
|
|
|
|
|
2009-12-29 02:46:09 +00:00
|
|
|
// Shadow Instruction::setInstructionSubclassData with a private forwarding
|
|
|
|
// method so that subclasses cannot accidentally use it.
|
|
|
|
void setInstructionSubclassData(unsigned short D) {
|
|
|
|
Instruction::setInstructionSubclassData(D);
|
2009-12-29 02:14:09 +00:00
|
|
|
}
|
2004-07-29 12:17:34 +00:00
|
|
|
};
|
|
|
|
|
2008-05-10 08:32:32 +00:00
|
|
|
template <>
|
2011-01-11 15:07:38 +00:00
|
|
|
struct OperandTraits<InvokeInst> : public VariadicOperandTraits<InvokeInst, 3> {
|
2008-05-10 08:32:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
InvokeInst::InvokeInst(Value *Func,
|
|
|
|
BasicBlock *IfNormal, BasicBlock *IfException,
|
2011-07-15 08:37:34 +00:00
|
|
|
ArrayRef<Value *> Args, unsigned Values,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, Instruction *InsertBefore)
|
2008-05-10 08:32:32 +00:00
|
|
|
: TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
|
|
|
|
->getElementType())->getReturnType(),
|
|
|
|
Instruction::Invoke,
|
|
|
|
OperandTraits<InvokeInst>::op_end(this) - Values,
|
|
|
|
Values, InsertBefore) {
|
2011-07-15 08:37:34 +00:00
|
|
|
init(Func, IfNormal, IfException, Args, NameStr);
|
2008-05-10 08:32:32 +00:00
|
|
|
}
|
|
|
|
InvokeInst::InvokeInst(Value *Func,
|
|
|
|
BasicBlock *IfNormal, BasicBlock *IfException,
|
2011-07-15 08:37:34 +00:00
|
|
|
ArrayRef<Value *> Args, unsigned Values,
|
2009-07-25 04:41:11 +00:00
|
|
|
const Twine &NameStr, BasicBlock *InsertAtEnd)
|
2008-05-10 08:32:32 +00:00
|
|
|
: TerminatorInst(cast<FunctionType>(cast<PointerType>(Func->getType())
|
|
|
|
->getElementType())->getReturnType(),
|
|
|
|
Instruction::Invoke,
|
|
|
|
OperandTraits<InvokeInst>::op_end(this) - Values,
|
|
|
|
Values, InsertAtEnd) {
|
2011-07-15 08:37:34 +00:00
|
|
|
init(Func, IfNormal, IfException, Args, NameStr);
|
2008-05-10 08:32:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InvokeInst, Value)
|
2004-07-29 12:17:34 +00:00
|
|
|
|
2004-10-16 18:05:54 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2011-07-31 06:30:59 +00:00
|
|
|
// ResumeInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
/// ResumeInst - Resume the propagation of an exception.
|
|
|
|
///
|
|
|
|
class ResumeInst : public TerminatorInst {
|
|
|
|
ResumeInst(const ResumeInst &RI);
|
|
|
|
|
2014-04-09 06:08:46 +00:00
|
|
|
explicit ResumeInst(Value *Exn, Instruction *InsertBefore=nullptr);
|
2011-07-31 06:30:59 +00:00
|
|
|
ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
|
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
ResumeInst *clone_impl() const override;
|
2011-07-31 06:30:59 +00:00
|
|
|
public:
|
2014-04-09 06:08:46 +00:00
|
|
|
static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = nullptr) {
|
2011-07-31 06:30:59 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
/// Convenience accessor.
|
|
|
|
Value *getValue() const { return Op<0>(); }
|
|
|
|
|
|
|
|
unsigned getNumSuccessors() const { return 0; }
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::Resume;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
private:
|
2014-03-05 06:35:38 +00:00
|
|
|
BasicBlock *getSuccessorV(unsigned idx) const override;
|
|
|
|
unsigned getNumSuccessorsV() const override;
|
|
|
|
void setSuccessorV(unsigned idx, BasicBlock *B) override;
|
2011-07-31 06:30:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct OperandTraits<ResumeInst> :
|
|
|
|
public FixedNumOperandTraits<ResumeInst, 1> {
|
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2004-10-16 18:05:54 +00:00
|
|
|
// UnreachableInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===---------------------------------------------------------------------------
|
|
|
|
/// UnreachableInst - This function has undefined behavior. In particular, the
|
|
|
|
/// presence of this instruction indicates some higher level knowledge that the
|
|
|
|
/// end of the block cannot be reached.
|
|
|
|
///
|
2004-10-27 16:14:51 +00:00
|
|
|
class UnreachableInst : public TerminatorInst {
|
2012-09-18 03:25:49 +00:00
|
|
|
void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION;
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2014-03-05 06:35:38 +00:00
|
|
|
UnreachableInst *clone_impl() const override;
|
2009-10-27 22:16:29 +00:00
|
|
|
|
2004-10-27 16:14:51 +00:00
|
|
|
public:
|
2008-04-06 20:25:17 +00:00
|
|
|
// allocate space for exactly zero operands
|
|
|
|
void *operator new(size_t s) {
|
|
|
|
return User::operator new(s, 0);
|
|
|
|
}
|
2014-04-09 06:08:46 +00:00
|
|
|
explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = nullptr);
|
2009-08-13 21:58:54 +00:00
|
|
|
explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
|
2004-10-16 18:05:54 +00:00
|
|
|
|
2005-01-29 00:31:36 +00:00
|
|
|
unsigned getNumSuccessors() const { return 0; }
|
2004-10-16 18:05:54 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Instruction::Unreachable;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
2005-01-29 00:31:36 +00:00
|
|
|
private:
|
2014-03-05 06:35:38 +00:00
|
|
|
BasicBlock *getSuccessorV(unsigned idx) const override;
|
|
|
|
unsigned getNumSuccessorsV() const override;
|
|
|
|
void setSuccessorV(unsigned idx, BasicBlock *B) override;
|
2004-10-16 18:05:54 +00:00
|
|
|
};
|
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TruncInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief This class represents a truncation of integer types.
|
2006-11-27 01:05:10 +00:00
|
|
|
class TruncInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Clone an identical TruncInst
|
2014-03-05 06:35:38 +00:00
|
|
|
TruncInst *clone_impl() const override;
|
2009-10-27 22:16:29 +00:00
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-before-instruction semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
TruncInst(
|
2014-04-09 06:08:46 +00:00
|
|
|
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
|
2006-11-27 01:05:10 +00:00
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-at-end-of-block semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
TruncInst(
|
|
|
|
Value *S, ///< The value to be truncated
|
2014-04-09 06:08:46 +00:00
|
|
|
Type *Ty, ///< The (smaller) type to truncate to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
2006-11-27 01:05:10 +00:00
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == Trunc;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ZExtInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief This class represents zero extension of integer types.
|
2006-11-27 01:05:10 +00:00
|
|
|
class ZExtInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Clone an identical ZExtInst
|
2014-03-05 06:35:38 +00:00
|
|
|
ZExtInst *clone_impl() const override;
|
2009-10-27 22:16:29 +00:00
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-before-instruction semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
ZExtInst(
|
2014-04-09 06:08:46 +00:00
|
|
|
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
|
2006-11-27 01:05:10 +00:00
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-at-end semantics.
|
2006-11-27 01:05:10 +00:00
|
|
|
ZExtInst(
|
|
|
|
Value *S, ///< The value to be zero extended
|
2014-04-09 06:08:46 +00:00
|
|
|
Type *Ty, ///< The type to zero extend to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
2006-11-27 01:05:10 +00:00
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == ZExt;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// SExtInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief This class represents a sign extension of integer types.
|
2006-11-27 01:05:10 +00:00
|
|
|
class SExtInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Clone an identical SExtInst
|
2014-03-05 06:35:38 +00:00
|
|
|
SExtInst *clone_impl() const override;
|
2009-10-27 22:16:29 +00:00
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-before-instruction semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
SExtInst(
|
2014-04-09 06:08:46 +00:00
|
|
|
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
|
2006-11-27 01:05:10 +00:00
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-at-end-of-block semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
SExtInst(
|
|
|
|
Value *S, ///< The value to be sign extended
|
2014-04-09 06:08:46 +00:00
|
|
|
Type *Ty, ///< The type to sign extend to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
2006-11-27 01:05:10 +00:00
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == SExt;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FPTruncInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief This class represents a truncation of floating point types.
|
2006-11-27 01:05:10 +00:00
|
|
|
class FPTruncInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Clone an identical FPTruncInst
|
2014-03-05 06:35:38 +00:00
|
|
|
FPTruncInst *clone_impl() const override;
|
2009-10-27 22:16:29 +00:00
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-before-instruction semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
FPTruncInst(
|
2014-04-09 06:08:46 +00:00
|
|
|
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
|
2006-11-27 01:05:10 +00:00
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-before-instruction semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
FPTruncInst(
|
|
|
|
Value *S, ///< The value to be truncated
|
2014-04-09 06:08:46 +00:00
|
|
|
Type *Ty, ///< The type to truncate to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
2006-11-27 01:05:10 +00:00
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == FPTrunc;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FPExtInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief This class represents an extension of floating point types.
|
2006-11-27 01:05:10 +00:00
|
|
|
class FPExtInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Clone an identical FPExtInst
|
2014-03-05 06:35:38 +00:00
|
|
|
FPExtInst *clone_impl() const override;
|
2009-10-27 22:16:29 +00:00
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-before-instruction semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
FPExtInst(
|
2014-04-09 06:08:46 +00:00
|
|
|
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
|
2006-11-27 01:05:10 +00:00
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-at-end-of-block semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
FPExtInst(
|
|
|
|
Value *S, ///< The value to be extended
|
2014-04-09 06:08:46 +00:00
|
|
|
Type *Ty, ///< The type to extend to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
2006-11-27 01:05:10 +00:00
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == FPExt;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// UIToFPInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief This class represents a cast unsigned integer to floating point.
|
2006-11-27 01:05:10 +00:00
|
|
|
class UIToFPInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Clone an identical UIToFPInst
|
2014-03-05 06:35:38 +00:00
|
|
|
UIToFPInst *clone_impl() const override;
|
2009-10-27 22:16:29 +00:00
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-before-instruction semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
UIToFPInst(
|
2014-04-09 06:08:46 +00:00
|
|
|
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
|
2006-11-27 01:05:10 +00:00
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-at-end-of-block semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
UIToFPInst(
|
|
|
|
Value *S, ///< The value to be converted
|
2014-04-09 06:08:46 +00:00
|
|
|
Type *Ty, ///< The type to convert to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
2006-11-27 01:05:10 +00:00
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == UIToFP;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// SIToFPInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief This class represents a cast from signed integer to floating point.
|
2006-11-27 01:05:10 +00:00
|
|
|
class SIToFPInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Clone an identical SIToFPInst
|
2014-03-05 06:35:38 +00:00
|
|
|
SIToFPInst *clone_impl() const override;
|
2009-10-27 22:16:29 +00:00
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-before-instruction semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
SIToFPInst(
|
2014-04-09 06:08:46 +00:00
|
|
|
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
|
2006-11-27 01:05:10 +00:00
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-at-end-of-block semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
SIToFPInst(
|
|
|
|
Value *S, ///< The value to be converted
|
2014-04-09 06:08:46 +00:00
|
|
|
Type *Ty, ///< The type to convert to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
2006-11-27 01:05:10 +00:00
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == SIToFP;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FPToUIInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief This class represents a cast from floating point to unsigned integer
|
2006-11-27 01:05:10 +00:00
|
|
|
class FPToUIInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Clone an identical FPToUIInst
|
2014-03-05 06:35:38 +00:00
|
|
|
FPToUIInst *clone_impl() const override;
|
2009-10-27 22:16:29 +00:00
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-before-instruction semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
FPToUIInst(
|
2014-04-09 06:08:46 +00:00
|
|
|
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
|
2006-11-27 01:05:10 +00:00
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-at-end-of-block semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
FPToUIInst(
|
|
|
|
Value *S, ///< The value to be converted
|
2014-04-09 06:08:46 +00:00
|
|
|
Type *Ty, ///< The type to convert to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< Where to insert the new instruction
|
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
2006-11-27 01:05:10 +00:00
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == FPToUI;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FPToSIInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief This class represents a cast from floating point to signed integer.
|
2006-11-27 01:05:10 +00:00
|
|
|
class FPToSIInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Clone an identical FPToSIInst
|
2014-03-05 06:35:38 +00:00
|
|
|
FPToSIInst *clone_impl() const override;
|
2009-10-27 22:16:29 +00:00
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-before-instruction semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
FPToSIInst(
|
2014-04-09 06:08:46 +00:00
|
|
|
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
|
2006-11-27 01:05:10 +00:00
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-at-end-of-block semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
FPToSIInst(
|
|
|
|
Value *S, ///< The value to be converted
|
2014-04-09 06:08:46 +00:00
|
|
|
Type *Ty, ///< The type to convert to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
|
2006-11-27 01:05:10 +00:00
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == FPToSI;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// IntToPtrInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief This class represents a cast from an integer to a pointer.
|
2006-11-27 01:05:10 +00:00
|
|
|
class IntToPtrInst : public CastInst {
|
|
|
|
public:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-before-instruction semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
IntToPtrInst(
|
2014-04-09 06:08:46 +00:00
|
|
|
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
|
2006-11-27 01:05:10 +00:00
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-at-end-of-block semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
IntToPtrInst(
|
|
|
|
Value *S, ///< The value to be converted
|
2014-04-09 06:08:46 +00:00
|
|
|
Type *Ty, ///< The type to convert to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Clone an identical IntToPtrInst
|
2014-03-05 06:35:38 +00:00
|
|
|
IntToPtrInst *clone_impl() const override;
|
2006-11-27 01:05:10 +00:00
|
|
|
|
2012-11-01 11:25:55 +00:00
|
|
|
/// \brief Returns the address space of this instruction's pointer type.
|
2012-10-09 22:27:29 +00:00
|
|
|
unsigned getAddressSpace() const {
|
2012-11-01 09:37:49 +00:00
|
|
|
return getType()->getPointerAddressSpace();
|
2012-10-09 22:27:29 +00:00
|
|
|
}
|
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == IntToPtr;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PtrToIntInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief This class represents a cast from a pointer to an integer
|
2006-11-27 01:05:10 +00:00
|
|
|
class PtrToIntInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Clone an identical PtrToIntInst
|
2014-03-05 06:35:38 +00:00
|
|
|
PtrToIntInst *clone_impl() const override;
|
2009-10-27 22:16:29 +00:00
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-before-instruction semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
PtrToIntInst(
|
2014-04-09 06:08:46 +00:00
|
|
|
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
|
2006-11-27 01:05:10 +00:00
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-at-end-of-block semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
PtrToIntInst(
|
|
|
|
Value *S, ///< The value to be converted
|
2014-04-09 06:08:46 +00:00
|
|
|
Type *Ty, ///< The type to convert to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
2012-11-01 11:16:47 +00:00
|
|
|
/// \brief Gets the pointer operand.
|
|
|
|
Value *getPointerOperand() { return getOperand(0); }
|
|
|
|
/// \brief Gets the pointer operand.
|
|
|
|
const Value *getPointerOperand() const { return getOperand(0); }
|
|
|
|
/// \brief Gets the operand index of the pointer operand.
|
|
|
|
static unsigned getPointerOperandIndex() { return 0U; }
|
|
|
|
|
|
|
|
/// \brief Returns the address space of the pointer operand.
|
2012-10-09 22:27:29 +00:00
|
|
|
unsigned getPointerAddressSpace() const {
|
2012-11-01 11:16:47 +00:00
|
|
|
return getPointerOperand()->getType()->getPointerAddressSpace();
|
2012-10-09 22:27:29 +00:00
|
|
|
}
|
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == PtrToInt;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// BitCastInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief This class represents a no-op cast from one type to another.
|
2006-11-27 01:05:10 +00:00
|
|
|
class BitCastInst : public CastInst {
|
2009-10-27 22:16:29 +00:00
|
|
|
protected:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Clone an identical BitCastInst
|
2014-03-05 06:35:38 +00:00
|
|
|
BitCastInst *clone_impl() const override;
|
2009-10-27 22:16:29 +00:00
|
|
|
|
2006-11-27 01:05:10 +00:00
|
|
|
public:
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-before-instruction semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
BitCastInst(
|
2014-04-09 06:08:46 +00:00
|
|
|
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
|
2006-11-27 01:05:10 +00:00
|
|
|
);
|
|
|
|
|
2012-11-01 10:46:54 +00:00
|
|
|
/// \brief Constructor with insert-at-end-of-block semantics
|
2006-11-27 01:05:10 +00:00
|
|
|
BitCastInst(
|
|
|
|
Value *S, ///< The value to be casted
|
2014-04-09 06:08:46 +00:00
|
|
|
Type *Ty, ///< The type to casted to
|
2010-07-21 08:25:55 +00:00
|
|
|
const Twine &NameStr, ///< A name for the new instruction
|
2006-11-27 01:05:10 +00:00
|
|
|
BasicBlock *InsertAtEnd ///< The block to insert the instruction into
|
|
|
|
);
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == BitCast;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-15 01:34:59 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// AddrSpaceCastInst Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// \brief This class represents a conversion between pointers from
|
|
|
|
/// one address space to another.
|
|
|
|
class AddrSpaceCastInst : public CastInst {
|
|
|
|
protected:
|
|
|
|
/// \brief Clone an identical AddrSpaceCastInst
|
2014-03-05 06:35:38 +00:00
|
|
|
AddrSpaceCastInst *clone_impl() const override;
|
2013-11-15 01:34:59 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/// \brief Constructor with insert-before-instruction semantics
|
|
|
|
AddrSpaceCastInst(
|
2014-04-09 06:08:46 +00:00
|
|
|
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
|
2013-11-15 01:34:59 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
/// \brief 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
|
|
|
|
);
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const Instruction *I) {
|
|
|
|
return I->getOpcode() == AddrSpaceCast;
|
|
|
|
}
|
|
|
|
static inline bool classof(const Value *V) {
|
|
|
|
return isa<Instruction>(V) && classof(cast<Instruction>(V));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-07-29 12:17:34 +00:00
|
|
|
} // End llvm namespace
|
2003-01-27 22:08:52 +00:00
|
|
|
|
|
|
|
#endif
|