#ifndef LLVM_INSTRUCTIONS_H
#define LLVM_INSTRUCTIONS_H
-#include "llvm/InstrTypes.h"
-#include "llvm/DerivedTypes.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/Attributes.h"
#include "llvm/CallingConv.h"
+#include "llvm/DerivedTypes.h"
+#include "llvm/InstrTypes.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/IntegersSubset.h"
#include "llvm/Support/IntegersSubsetMapping.h"
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/ErrorHandling.h"
#include <iterator>
namespace llvm {
+class APInt;
class ConstantInt;
class ConstantRange;
-class APInt;
+class DataLayout;
class LLVMContext;
enum AtomicOrdering {
return reinterpret_cast<PointerType*>(Instruction::getType());
}
+ /// \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();
+ }
+
/// getIndexedType - Returns the type of the element that would be loaded with
/// a load instruction with the specified parameters.
///
/// isInBounds - Determine whether the GEP has the inbounds flag.
bool isInBounds() const;
+ /// \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;
+
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const Instruction *I) {
return (I->getOpcode() == Instruction::GetElementPtr);
/// hold the calling convention of the call.
///
class CallInst : public Instruction {
- AttrListPtr AttributeList; ///< parameter attributes for call
+ AttributeSet AttributeList; ///< parameter attributes for call
CallInst(const CallInst &CI);
void init(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr);
void init(Value *Func, const Twine &NameStr);
/// getAttributes - Return the parameter attributes for this call.
///
- const AttrListPtr &getAttributes() const { return AttributeList; }
+ const AttributeSet &getAttributes() const { return AttributeList; }
/// setAttributes - Set the parameter attributes for this call.
///
- void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
+ void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
/// addAttribute - adds the attribute to the list of attributes.
void addAttribute(unsigned i, Attributes attr);
/// \brief Return true if the call should not be inlined.
bool isNoInline() const { return hasFnAttr(Attributes::NoInline); }
void setIsNoInline() {
- addAttribute(AttrListPtr::FunctionIndex,
+ addAttribute(AttributeSet::FunctionIndex,
Attributes::get(getContext(), Attributes::NoInline));
}
return hasFnAttr(Attributes::ReturnsTwice);
}
void setCanReturnTwice() {
- addAttribute(AttrListPtr::FunctionIndex,
+ addAttribute(AttributeSet::FunctionIndex,
Attributes::get(getContext(), Attributes::ReturnsTwice));
}
return hasFnAttr(Attributes::ReadNone);
}
void setDoesNotAccessMemory() {
- addAttribute(AttrListPtr::FunctionIndex,
+ addAttribute(AttributeSet::FunctionIndex,
Attributes::get(getContext(), Attributes::ReadNone));
}
return doesNotAccessMemory() || hasFnAttr(Attributes::ReadOnly);
}
void setOnlyReadsMemory() {
- addAttribute(AttrListPtr::FunctionIndex,
+ addAttribute(AttributeSet::FunctionIndex,
Attributes::get(getContext(), Attributes::ReadOnly));
}
/// \brief Determine if the call cannot return.
bool doesNotReturn() const { return hasFnAttr(Attributes::NoReturn); }
void setDoesNotReturn() {
- addAttribute(AttrListPtr::FunctionIndex,
+ addAttribute(AttributeSet::FunctionIndex,
Attributes::get(getContext(), Attributes::NoReturn));
}
/// \brief Determine if the call cannot unwind.
bool doesNotThrow() const { return hasFnAttr(Attributes::NoUnwind); }
void setDoesNotThrow() {
- addAttribute(AttrListPtr::FunctionIndex,
+ addAttribute(AttributeSet::FunctionIndex,
Attributes::get(getContext(), Attributes::NoUnwind));
}
/// calling convention of the call.
///
class InvokeInst : public TerminatorInst {
- AttrListPtr AttributeList;
+ AttributeSet AttributeList;
InvokeInst(const InvokeInst &BI);
void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
ArrayRef<Value *> Args, const Twine &NameStr);
/// getAttributes - Return the parameter attributes for this invoke.
///
- const AttrListPtr &getAttributes() const { return AttributeList; }
+ const AttributeSet &getAttributes() const { return AttributeList; }
/// setAttributes - Set the parameter attributes for this invoke.
///
- void setAttributes(const AttrListPtr &Attrs) { AttributeList = Attrs; }
+ void setAttributes(const AttributeSet &Attrs) { AttributeList = Attrs; }
/// addAttribute - adds the attribute to the list of attributes.
void addAttribute(unsigned i, Attributes attr);
/// \brief Return true if the call should not be inlined.
bool isNoInline() const { return hasFnAttr(Attributes::NoInline); }
void setIsNoInline() {
- addAttribute(AttrListPtr::FunctionIndex,
+ addAttribute(AttributeSet::FunctionIndex,
Attributes::get(getContext(), Attributes::NoInline));
}
return hasFnAttr(Attributes::ReadNone);
}
void setDoesNotAccessMemory() {
- addAttribute(AttrListPtr::FunctionIndex,
+ addAttribute(AttributeSet::FunctionIndex,
Attributes::get(getContext(), Attributes::ReadNone));
}
return doesNotAccessMemory() || hasFnAttr(Attributes::ReadOnly);
}
void setOnlyReadsMemory() {
- addAttribute(AttrListPtr::FunctionIndex,
+ addAttribute(AttributeSet::FunctionIndex,
Attributes::get(getContext(), Attributes::ReadOnly));
}
/// \brief Determine if the call cannot return.
bool doesNotReturn() const { return hasFnAttr(Attributes::NoReturn); }
void setDoesNotReturn() {
- addAttribute(AttrListPtr::FunctionIndex,
+ addAttribute(AttributeSet::FunctionIndex,
Attributes::get(getContext(), Attributes::NoReturn));
}
/// \brief Determine if the call cannot unwind.
bool doesNotThrow() const { return hasFnAttr(Attributes::NoUnwind); }
void setDoesNotThrow() {
- addAttribute(AttrListPtr::FunctionIndex,
+ addAttribute(AttributeSet::FunctionIndex,
Attributes::get(getContext(), Attributes::NoUnwind));
}
/// \brief Clone an identical IntToPtrInst
virtual IntToPtrInst *clone_impl() const;
- /// \brief return the address space of the pointer.
+ /// \brief Returns the address space of this instruction's pointer type.
unsigned getAddressSpace() const {
return getType()->getPointerAddressSpace();
}