2008-04-13 06:22:09 +00:00
|
|
|
//===---- llvm/Support/IRBuilder.h - Builder for LLVM Instrs ----*- C++ -*-===//
|
2007-05-27 15:09:34 +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.
|
2007-05-27 15:09:34 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2008-04-13 06:22:09 +00:00
|
|
|
// This file defines the IRBuilder class, which is used as a convenient way
|
2007-05-27 15:09:34 +00:00
|
|
|
// to create LLVM instructions with a consistent and simplified interface.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-04-13 06:22:09 +00:00
|
|
|
#ifndef LLVM_SUPPORT_IRBUILDER_H
|
|
|
|
#define LLVM_SUPPORT_IRBUILDER_H
|
2007-05-27 15:09:34 +00:00
|
|
|
|
2008-08-11 15:29:30 +00:00
|
|
|
#include "llvm/Instructions.h"
|
2009-12-28 21:50:56 +00:00
|
|
|
#include "llvm/BasicBlock.h"
|
2011-04-07 00:03:25 +00:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2011-04-12 00:29:07 +00:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2009-08-19 22:34:21 +00:00
|
|
|
#include "llvm/ADT/Twine.h"
|
2008-08-11 15:29:30 +00:00
|
|
|
#include "llvm/Support/ConstantFolder.h"
|
2007-05-27 15:09:34 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2009-12-28 21:45:40 +00:00
|
|
|
class MDNode;
|
2007-05-27 15:09:34 +00:00
|
|
|
|
2009-08-30 05:42:59 +00:00
|
|
|
/// IRBuilderDefaultInserter - This provides the default implementation of the
|
|
|
|
/// IRBuilder 'InsertHelper' method that is called whenever an instruction is
|
|
|
|
/// created by IRBuilder and needs to be inserted. By default, this inserts the
|
|
|
|
/// instruction at the insertion point.
|
|
|
|
template <bool preserveNames = true>
|
|
|
|
class IRBuilderDefaultInserter {
|
|
|
|
protected:
|
|
|
|
void InsertHelper(Instruction *I, const Twine &Name,
|
|
|
|
BasicBlock *BB, BasicBlock::iterator InsertPt) const {
|
|
|
|
if (BB) BB->getInstList().insert(InsertPt, I);
|
|
|
|
if (preserveNames)
|
|
|
|
I->setName(Name);
|
|
|
|
}
|
|
|
|
};
|
2009-12-28 21:28:46 +00:00
|
|
|
|
|
|
|
/// IRBuilderBase - Common base class shared among various IRBuilders.
|
|
|
|
class IRBuilderBase {
|
2010-04-02 20:21:22 +00:00
|
|
|
DebugLoc CurDbgLocation;
|
2009-12-28 21:28:46 +00:00
|
|
|
protected:
|
2007-05-27 15:09:34 +00:00
|
|
|
BasicBlock *BB;
|
|
|
|
BasicBlock::iterator InsertPt;
|
2009-07-08 20:50:47 +00:00
|
|
|
LLVMContext &Context;
|
2007-05-27 15:09:34 +00:00
|
|
|
public:
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-12-28 21:28:46 +00:00
|
|
|
IRBuilderBase(LLVMContext &context)
|
2010-04-01 06:31:45 +00:00
|
|
|
: Context(context) {
|
2009-08-11 15:57:42 +00:00
|
|
|
ClearInsertionPoint();
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2007-05-27 15:09:34 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Builder configuration methods
|
|
|
|
//===--------------------------------------------------------------------===//
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2007-05-27 15:09:34 +00:00
|
|
|
/// ClearInsertionPoint - Clear the insertion point: created instructions will
|
|
|
|
/// not be inserted into a block.
|
|
|
|
void ClearInsertionPoint() {
|
|
|
|
BB = 0;
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2007-05-27 15:09:34 +00:00
|
|
|
BasicBlock *GetInsertBlock() const { return BB; }
|
2009-05-20 21:45:41 +00:00
|
|
|
BasicBlock::iterator GetInsertPoint() const { return InsertPt; }
|
2010-04-01 06:31:45 +00:00
|
|
|
LLVMContext &getContext() const { return Context; }
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2007-05-27 15:09:34 +00:00
|
|
|
/// SetInsertPoint - This specifies that created instructions should be
|
|
|
|
/// appended to the end of the specified block.
|
|
|
|
void SetInsertPoint(BasicBlock *TheBB) {
|
|
|
|
BB = TheBB;
|
|
|
|
InsertPt = BB->end();
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2010-12-19 19:16:22 +00:00
|
|
|
/// SetInsertPoint - This specifies that created instructions should be
|
|
|
|
/// inserted before the specified instruction.
|
|
|
|
void SetInsertPoint(Instruction *I) {
|
|
|
|
BB = I->getParent();
|
|
|
|
InsertPt = I;
|
2011-05-18 20:58:47 +00:00
|
|
|
SetCurrentDebugLocation(I->getDebugLoc());
|
2010-12-19 19:16:22 +00:00
|
|
|
}
|
2011-06-29 22:52:51 +00:00
|
|
|
|
2007-05-27 15:09:34 +00:00
|
|
|
/// SetInsertPoint - This specifies that created instructions should be
|
|
|
|
/// inserted at the specified point.
|
|
|
|
void SetInsertPoint(BasicBlock *TheBB, BasicBlock::iterator IP) {
|
|
|
|
BB = TheBB;
|
|
|
|
InsertPt = IP;
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2011-06-29 23:01:52 +00:00
|
|
|
/// SetInsertPoint(Use) - Find the nearest point that dominates this use, and
|
|
|
|
/// specify that created instructions should be inserted at this point.
|
|
|
|
void SetInsertPoint(Use &U) {
|
|
|
|
Instruction *UseInst = cast<Instruction>(U.getUser());
|
|
|
|
if (PHINode *Phi = dyn_cast<PHINode>(UseInst)) {
|
|
|
|
BasicBlock *PredBB = Phi->getIncomingBlock(U);
|
|
|
|
assert(U != PredBB->getTerminator() && "critical edge not split");
|
|
|
|
SetInsertPoint(PredBB, PredBB->getTerminator());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SetInsertPoint(UseInst);
|
|
|
|
}
|
|
|
|
|
2009-09-23 17:20:43 +00:00
|
|
|
/// SetCurrentDebugLocation - Set location information used by debugging
|
2009-09-22 20:56:31 +00:00
|
|
|
/// information.
|
2010-04-02 20:21:22 +00:00
|
|
|
void SetCurrentDebugLocation(const DebugLoc &L) {
|
2010-03-31 04:09:11 +00:00
|
|
|
CurDbgLocation = L;
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2010-03-31 05:27:33 +00:00
|
|
|
/// getCurrentDebugLocation - Get location information used by debugging
|
2010-03-31 04:09:11 +00:00
|
|
|
/// information.
|
2011-07-12 04:14:22 +00:00
|
|
|
DebugLoc getCurrentDebugLocation() const { return CurDbgLocation; }
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-12-28 21:45:40 +00:00
|
|
|
/// SetInstDebugLocation - If this builder has a current debug location, set
|
|
|
|
/// it on the specified instruction.
|
2010-03-31 04:09:11 +00:00
|
|
|
void SetInstDebugLocation(Instruction *I) const {
|
2010-04-01 06:31:45 +00:00
|
|
|
if (!CurDbgLocation.isUnknown())
|
|
|
|
I->setDebugLoc(CurDbgLocation);
|
2010-03-31 04:09:11 +00:00
|
|
|
}
|
2009-12-28 21:45:40 +00:00
|
|
|
|
2011-05-21 23:14:36 +00:00
|
|
|
/// getCurrentFunctionReturnType - Get the return type of the current function
|
|
|
|
/// that we're emitting into.
|
2011-07-12 04:14:22 +00:00
|
|
|
Type *getCurrentFunctionReturnType() const;
|
2011-06-29 22:52:51 +00:00
|
|
|
|
2010-07-06 18:07:52 +00:00
|
|
|
/// InsertPoint - A saved insertion point.
|
|
|
|
class InsertPoint {
|
|
|
|
BasicBlock *Block;
|
|
|
|
BasicBlock::iterator Point;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// Creates a new insertion point which doesn't point to anything.
|
|
|
|
InsertPoint() : Block(0) {}
|
|
|
|
|
|
|
|
/// Creates a new insertion point at the given location.
|
|
|
|
InsertPoint(BasicBlock *InsertBlock, BasicBlock::iterator InsertPoint)
|
|
|
|
: Block(InsertBlock), Point(InsertPoint) {}
|
|
|
|
|
|
|
|
/// isSet - Returns true if this insert point is set.
|
|
|
|
bool isSet() const { return (Block != 0); }
|
|
|
|
|
|
|
|
llvm::BasicBlock *getBlock() const { return Block; }
|
|
|
|
llvm::BasicBlock::iterator getPoint() const { return Point; }
|
|
|
|
};
|
|
|
|
|
|
|
|
/// saveIP - Returns the current insert point.
|
|
|
|
InsertPoint saveIP() const {
|
|
|
|
return InsertPoint(GetInsertBlock(), GetInsertPoint());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// saveAndClearIP - Returns the current insert point, clearing it
|
|
|
|
/// in the process.
|
|
|
|
InsertPoint saveAndClearIP() {
|
|
|
|
InsertPoint IP(GetInsertBlock(), GetInsertPoint());
|
|
|
|
ClearInsertionPoint();
|
|
|
|
return IP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// restoreIP - Sets the current insert point to a previously-saved
|
|
|
|
/// location.
|
|
|
|
void restoreIP(InsertPoint IP) {
|
|
|
|
if (IP.isSet())
|
|
|
|
SetInsertPoint(IP.getBlock(), IP.getPoint());
|
|
|
|
else
|
|
|
|
ClearInsertionPoint();
|
|
|
|
}
|
|
|
|
|
2009-12-28 21:28:46 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Miscellaneous creation methods.
|
|
|
|
//===--------------------------------------------------------------------===//
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-12-28 21:28:46 +00:00
|
|
|
/// CreateGlobalString - Make a new global variable with an initializer that
|
2010-02-10 20:04:19 +00:00
|
|
|
/// has array of i8 type filled in with the nul terminated string value
|
2011-04-12 00:29:07 +00:00
|
|
|
/// specified. The new global variable will be marked mergable with any
|
|
|
|
/// others of the same contents. If Name is specified, it is the name of the
|
|
|
|
/// global variable created.
|
|
|
|
Value *CreateGlobalString(StringRef Str, const Twine &Name = "");
|
2010-07-06 18:34:49 +00:00
|
|
|
|
|
|
|
/// getInt1 - Get a constant value representing either true or false.
|
|
|
|
ConstantInt *getInt1(bool V) {
|
|
|
|
return ConstantInt::get(getInt1Ty(), V);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getTrue - Get the constant value for i1 true.
|
|
|
|
ConstantInt *getTrue() {
|
|
|
|
return ConstantInt::getTrue(Context);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getFalse - Get the constant value for i1 false.
|
|
|
|
ConstantInt *getFalse() {
|
|
|
|
return ConstantInt::getFalse(Context);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getInt8 - Get a constant 8-bit value.
|
|
|
|
ConstantInt *getInt8(uint8_t C) {
|
|
|
|
return ConstantInt::get(getInt8Ty(), C);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getInt16 - Get a constant 16-bit value.
|
|
|
|
ConstantInt *getInt16(uint16_t C) {
|
|
|
|
return ConstantInt::get(getInt16Ty(), C);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getInt32 - Get a constant 32-bit value.
|
|
|
|
ConstantInt *getInt32(uint32_t C) {
|
|
|
|
return ConstantInt::get(getInt32Ty(), C);
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2010-07-06 18:34:49 +00:00
|
|
|
/// getInt64 - Get a constant 64-bit value.
|
|
|
|
ConstantInt *getInt64(uint64_t C) {
|
|
|
|
return ConstantInt::get(getInt64Ty(), C);
|
|
|
|
}
|
2011-06-29 22:52:51 +00:00
|
|
|
|
2011-05-21 23:14:36 +00:00
|
|
|
/// getInt - Get a constant integer value.
|
2011-04-19 20:47:57 +00:00
|
|
|
ConstantInt *getInt(const APInt &AI) {
|
|
|
|
return ConstantInt::get(Context, AI);
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-08-14 00:30:41 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Type creation methods
|
|
|
|
//===--------------------------------------------------------------------===//
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-08-14 19:41:50 +00:00
|
|
|
/// getInt1Ty - Fetch the type representing a single bit
|
2011-07-12 04:14:22 +00:00
|
|
|
IntegerType *getInt1Ty() {
|
2009-08-14 00:30:41 +00:00
|
|
|
return Type::getInt1Ty(Context);
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-08-14 19:41:50 +00:00
|
|
|
/// getInt8Ty - Fetch the type representing an 8-bit integer.
|
2011-07-12 04:14:22 +00:00
|
|
|
IntegerType *getInt8Ty() {
|
2009-08-14 00:30:41 +00:00
|
|
|
return Type::getInt8Ty(Context);
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-08-14 19:41:50 +00:00
|
|
|
/// getInt16Ty - Fetch the type representing a 16-bit integer.
|
2011-07-12 04:14:22 +00:00
|
|
|
IntegerType *getInt16Ty() {
|
2009-08-14 00:30:41 +00:00
|
|
|
return Type::getInt16Ty(Context);
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-08-14 19:41:50 +00:00
|
|
|
/// getInt32Ty - Fetch the type resepresenting a 32-bit integer.
|
2011-07-12 04:14:22 +00:00
|
|
|
IntegerType *getInt32Ty() {
|
2009-08-14 00:30:41 +00:00
|
|
|
return Type::getInt32Ty(Context);
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-08-14 19:41:50 +00:00
|
|
|
/// getInt64Ty - Fetch the type representing a 64-bit integer.
|
2011-07-12 04:14:22 +00:00
|
|
|
IntegerType *getInt64Ty() {
|
2009-08-14 00:30:41 +00:00
|
|
|
return Type::getInt64Ty(Context);
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-08-14 19:41:50 +00:00
|
|
|
/// getFloatTy - Fetch the type representing a 32-bit floating point value.
|
2011-07-12 04:14:22 +00:00
|
|
|
Type *getFloatTy() {
|
2009-08-14 00:30:41 +00:00
|
|
|
return Type::getFloatTy(Context);
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-08-14 19:41:50 +00:00
|
|
|
/// getDoubleTy - Fetch the type representing a 64-bit floating point value.
|
2011-07-12 04:14:22 +00:00
|
|
|
Type *getDoubleTy() {
|
2009-08-14 00:30:41 +00:00
|
|
|
return Type::getDoubleTy(Context);
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-08-14 19:41:50 +00:00
|
|
|
/// getVoidTy - Fetch the type representing void.
|
2011-07-12 04:14:22 +00:00
|
|
|
Type *getVoidTy() {
|
2009-08-14 00:30:41 +00:00
|
|
|
return Type::getVoidTy(Context);
|
2010-03-05 22:21:58 +00:00
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2011-07-12 04:14:22 +00:00
|
|
|
PointerType *getInt8PtrTy(unsigned AddrSpace = 0) {
|
2010-12-26 22:49:25 +00:00
|
|
|
return Type::getInt8PtrTy(Context, AddrSpace);
|
2009-08-14 00:30:41 +00:00
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2011-05-21 23:14:36 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Intrinsic creation methods
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
2010-12-26 22:49:25 +00:00
|
|
|
/// CreateMemSet - Create and insert a memset to the specified pointer and the
|
|
|
|
/// specified value. If the pointer isn't an i8*, it will be converted. If a
|
|
|
|
/// TBAA tag is specified, it will be added to the instruction.
|
|
|
|
CallInst *CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, unsigned Align,
|
|
|
|
bool isVolatile = false, MDNode *TBAATag = 0) {
|
|
|
|
return CreateMemSet(Ptr, Val, getInt64(Size), Align, isVolatile, TBAATag);
|
|
|
|
}
|
2011-06-29 22:52:51 +00:00
|
|
|
|
2010-12-26 22:49:25 +00:00
|
|
|
CallInst *CreateMemSet(Value *Ptr, Value *Val, Value *Size, unsigned Align,
|
|
|
|
bool isVolatile = false, MDNode *TBAATag = 0);
|
|
|
|
|
|
|
|
/// CreateMemCpy - Create and insert a memcpy between the specified pointers.
|
|
|
|
/// If the pointers aren't i8*, they will be converted. If a TBAA tag is
|
|
|
|
/// specified, it will be added to the instruction.
|
|
|
|
CallInst *CreateMemCpy(Value *Dst, Value *Src, uint64_t Size, unsigned Align,
|
|
|
|
bool isVolatile = false, MDNode *TBAATag = 0) {
|
|
|
|
return CreateMemCpy(Dst, Src, getInt64(Size), Align, isVolatile, TBAATag);
|
|
|
|
}
|
2011-06-29 22:52:51 +00:00
|
|
|
|
2010-12-26 22:49:25 +00:00
|
|
|
CallInst *CreateMemCpy(Value *Dst, Value *Src, Value *Size, unsigned Align,
|
|
|
|
bool isVolatile = false, MDNode *TBAATag = 0);
|
|
|
|
|
|
|
|
/// CreateMemMove - Create and insert a memmove between the specified
|
|
|
|
/// pointers. If the pointers aren't i8*, they will be converted. If a TBAA
|
|
|
|
/// tag is specified, it will be added to the instruction.
|
|
|
|
CallInst *CreateMemMove(Value *Dst, Value *Src, uint64_t Size, unsigned Align,
|
|
|
|
bool isVolatile = false, MDNode *TBAATag = 0) {
|
|
|
|
return CreateMemMove(Dst, Src, getInt64(Size), Align, isVolatile, TBAATag);
|
|
|
|
}
|
2011-06-29 22:52:51 +00:00
|
|
|
|
2010-12-26 22:49:25 +00:00
|
|
|
CallInst *CreateMemMove(Value *Dst, Value *Src, Value *Size, unsigned Align,
|
2011-06-29 22:52:51 +00:00
|
|
|
bool isVolatile = false, MDNode *TBAATag = 0);
|
2011-05-21 23:14:36 +00:00
|
|
|
|
|
|
|
/// CreateLifetimeStart - Create a lifetime.start intrinsic. If the pointer
|
|
|
|
/// isn't i8* it will be converted.
|
|
|
|
CallInst *CreateLifetimeStart(Value *Ptr, ConstantInt *Size = 0);
|
|
|
|
|
|
|
|
/// CreateLifetimeEnd - Create a lifetime.end intrinsic. If the pointer isn't
|
|
|
|
/// i8* it will be converted.
|
|
|
|
CallInst *CreateLifetimeEnd(Value *Ptr, ConstantInt *Size = 0);
|
|
|
|
|
2010-12-26 22:49:25 +00:00
|
|
|
private:
|
|
|
|
Value *getCastedInt8PtrValue(Value *Ptr);
|
2009-12-28 21:28:46 +00:00
|
|
|
};
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-12-28 21:28:46 +00:00
|
|
|
/// IRBuilder - This provides a uniform API for creating instructions and
|
|
|
|
/// inserting them into a basic block: either at the end of a BasicBlock, or
|
|
|
|
/// at a specific iterator location in a block.
|
|
|
|
///
|
|
|
|
/// Note that the builder does not expose the full generality of LLVM
|
|
|
|
/// instructions. For access to extra instruction properties, use the mutators
|
|
|
|
/// (e.g. setVolatile) on the instructions after they have been created.
|
|
|
|
/// The first template argument handles whether or not to preserve names in the
|
|
|
|
/// final instruction output. This defaults to on. The second template argument
|
|
|
|
/// specifies a class to use for creating constants. This defaults to creating
|
|
|
|
/// minimally folded constants. The fourth template argument allows clients to
|
|
|
|
/// specify custom insertion hooks that are called on every newly created
|
|
|
|
/// insertion.
|
|
|
|
template<bool preserveNames = true, typename T = ConstantFolder,
|
|
|
|
typename Inserter = IRBuilderDefaultInserter<preserveNames> >
|
|
|
|
class IRBuilder : public IRBuilderBase, public Inserter {
|
|
|
|
T Folder;
|
|
|
|
public:
|
|
|
|
IRBuilder(LLVMContext &C, const T &F, const Inserter &I = Inserter())
|
|
|
|
: IRBuilderBase(C), Inserter(I), Folder(F) {
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2011-04-03 19:46:28 +00:00
|
|
|
explicit IRBuilder(LLVMContext &C) : IRBuilderBase(C), Folder() {
|
2009-12-28 21:28:46 +00:00
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-12-28 21:28:46 +00:00
|
|
|
explicit IRBuilder(BasicBlock *TheBB, const T &F)
|
|
|
|
: IRBuilderBase(TheBB->getContext()), Folder(F) {
|
|
|
|
SetInsertPoint(TheBB);
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-12-28 21:28:46 +00:00
|
|
|
explicit IRBuilder(BasicBlock *TheBB)
|
2011-04-03 19:46:28 +00:00
|
|
|
: IRBuilderBase(TheBB->getContext()), Folder() {
|
2009-12-28 21:28:46 +00:00
|
|
|
SetInsertPoint(TheBB);
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2010-12-26 22:49:25 +00:00
|
|
|
explicit IRBuilder(Instruction *IP)
|
2011-04-03 19:46:28 +00:00
|
|
|
: IRBuilderBase(IP->getContext()), Folder() {
|
2010-12-26 22:49:25 +00:00
|
|
|
SetInsertPoint(IP);
|
2011-05-04 21:57:22 +00:00
|
|
|
SetCurrentDebugLocation(IP->getDebugLoc());
|
2010-12-26 22:49:25 +00:00
|
|
|
}
|
2011-06-29 22:52:51 +00:00
|
|
|
|
2011-06-29 23:01:52 +00:00
|
|
|
explicit IRBuilder(Use &U)
|
|
|
|
: IRBuilderBase(U->getContext()), Folder() {
|
|
|
|
SetInsertPoint(U);
|
|
|
|
SetCurrentDebugLocation(cast<Instruction>(U.getUser())->getDebugLoc());
|
|
|
|
}
|
|
|
|
|
2009-12-28 21:28:46 +00:00
|
|
|
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T& F)
|
|
|
|
: IRBuilderBase(TheBB->getContext()), Folder(F) {
|
|
|
|
SetInsertPoint(TheBB, IP);
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-12-28 21:28:46 +00:00
|
|
|
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP)
|
2011-04-03 19:46:28 +00:00
|
|
|
: IRBuilderBase(TheBB->getContext()), Folder() {
|
2009-12-28 21:28:46 +00:00
|
|
|
SetInsertPoint(TheBB, IP);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getFolder - Get the constant folder being used.
|
|
|
|
const T &getFolder() { return Folder; }
|
|
|
|
|
|
|
|
/// isNamePreserving - Return true if this builder is configured to actually
|
|
|
|
/// add the requested names to IR created through it.
|
|
|
|
bool isNamePreserving() const { return preserveNames; }
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-12-28 21:28:46 +00:00
|
|
|
/// Insert - Insert and return the specified instruction.
|
|
|
|
template<typename InstTy>
|
|
|
|
InstTy *Insert(InstTy *I, const Twine &Name = "") const {
|
|
|
|
this->InsertHelper(I, Name, BB, InsertPt);
|
2010-04-01 06:31:45 +00:00
|
|
|
if (!getCurrentDebugLocation().isUnknown())
|
2009-12-28 21:45:40 +00:00
|
|
|
this->SetInstDebugLocation(I);
|
2009-12-28 21:28:46 +00:00
|
|
|
return I;
|
|
|
|
}
|
2009-08-14 00:30:41 +00:00
|
|
|
|
2010-11-18 02:15:42 +00:00
|
|
|
/// Insert - No-op overload to handle constants.
|
|
|
|
Constant *Insert(Constant *C, const Twine& = "") const {
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2007-05-27 15:09:34 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Instruction creation methods: Terminators
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// CreateRetVoid - Create a 'ret void' instruction.
|
|
|
|
ReturnInst *CreateRetVoid() {
|
2009-08-14 06:12:30 +00:00
|
|
|
return Insert(ReturnInst::Create(Context));
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
|
|
|
|
2008-08-11 15:29:30 +00:00
|
|
|
/// @verbatim
|
|
|
|
/// CreateRet - Create a 'ret <val>' instruction.
|
2007-08-06 17:10:29 +00:00
|
|
|
/// @endverbatim
|
2007-05-27 15:09:34 +00:00
|
|
|
ReturnInst *CreateRet(Value *V) {
|
2009-08-14 06:12:30 +00:00
|
|
|
return Insert(ReturnInst::Create(Context, V));
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2008-07-25 20:36:15 +00:00
|
|
|
/// CreateAggregateRet - Create a sequence of N insertvalue instructions,
|
|
|
|
/// with one Value from the retVals array each, that build a aggregate
|
|
|
|
/// return value one value at a time, and a ret instruction to return
|
|
|
|
/// the resulting aggregate value. This is a convenience function for
|
|
|
|
/// code that uses aggregate return values as a vehicle for having
|
|
|
|
/// multiple return values.
|
|
|
|
///
|
2009-12-28 21:50:56 +00:00
|
|
|
ReturnInst *CreateAggregateRet(Value *const *retVals, unsigned N) {
|
|
|
|
Value *V = UndefValue::get(getCurrentFunctionReturnType());
|
2008-07-23 00:34:11 +00:00
|
|
|
for (unsigned i = 0; i != N; ++i)
|
|
|
|
V = CreateInsertValue(V, retVals[i], i, "mrv");
|
2009-08-14 06:12:30 +00:00
|
|
|
return Insert(ReturnInst::Create(Context, V));
|
2008-04-08 07:30:13 +00:00
|
|
|
}
|
2008-08-11 15:29:30 +00:00
|
|
|
|
2007-05-27 15:09:34 +00:00
|
|
|
/// CreateBr - Create an unconditional 'br label X' instruction.
|
|
|
|
BranchInst *CreateBr(BasicBlock *Dest) {
|
2008-04-06 20:25:17 +00:00
|
|
|
return Insert(BranchInst::Create(Dest));
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// CreateCondBr - Create a conditional 'br Cond, TrueDest, FalseDest'
|
|
|
|
/// instruction.
|
|
|
|
BranchInst *CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False) {
|
2008-04-06 20:25:17 +00:00
|
|
|
return Insert(BranchInst::Create(True, False, Cond));
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2008-08-11 15:29:30 +00:00
|
|
|
|
2007-05-27 15:09:34 +00:00
|
|
|
/// CreateSwitch - Create a switch instruction with the specified value,
|
|
|
|
/// default dest, and with a hint for the number of cases that will be added
|
|
|
|
/// (for efficient allocation).
|
|
|
|
SwitchInst *CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases = 10) {
|
2008-04-06 20:25:17 +00:00
|
|
|
return Insert(SwitchInst::Create(V, Dest, NumCases));
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2008-08-11 15:29:30 +00:00
|
|
|
|
2009-10-28 23:25:00 +00:00
|
|
|
/// CreateIndirectBr - Create an indirect branch instruction with the
|
|
|
|
/// specified address operand, with an optional hint for the number of
|
|
|
|
/// destinations that will be added (for efficient allocation).
|
|
|
|
IndirectBrInst *CreateIndirectBr(Value *Addr, unsigned NumDests = 10) {
|
|
|
|
return Insert(IndirectBrInst::Create(Addr, NumDests));
|
|
|
|
}
|
|
|
|
|
2009-12-04 01:26:26 +00:00
|
|
|
InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
|
|
|
|
BasicBlock *UnwindDest, const Twine &Name = "") {
|
2011-07-15 08:37:34 +00:00
|
|
|
return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest,
|
|
|
|
ArrayRef<Value *>()),
|
|
|
|
Name);
|
2009-12-04 01:26:26 +00:00
|
|
|
}
|
|
|
|
InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
|
|
|
|
BasicBlock *UnwindDest, Value *Arg1,
|
|
|
|
const Twine &Name = "") {
|
2011-07-15 08:37:34 +00:00
|
|
|
return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Arg1),
|
|
|
|
Name);
|
2009-12-04 01:26:26 +00:00
|
|
|
}
|
2009-12-04 01:53:15 +00:00
|
|
|
InvokeInst *CreateInvoke3(Value *Callee, BasicBlock *NormalDest,
|
|
|
|
BasicBlock *UnwindDest, Value *Arg1,
|
|
|
|
Value *Arg2, Value *Arg3,
|
|
|
|
const Twine &Name = "") {
|
|
|
|
Value *Args[] = { Arg1, Arg2, Arg3 };
|
2011-07-15 08:37:34 +00:00
|
|
|
return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args),
|
|
|
|
Name);
|
2009-12-04 01:53:15 +00:00
|
|
|
}
|
2007-05-27 15:09:34 +00:00
|
|
|
/// CreateInvoke - Create an invoke instruction.
|
2008-08-11 15:29:30 +00:00
|
|
|
InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
|
2011-07-15 08:37:34 +00:00
|
|
|
BasicBlock *UnwindDest, ArrayRef<Value *> Args,
|
2010-10-27 07:39:54 +00:00
|
|
|
const Twine &Name = "") {
|
2011-07-15 08:37:34 +00:00
|
|
|
return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args),
|
|
|
|
Name);
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2008-08-11 15:29:30 +00:00
|
|
|
|
2011-07-31 06:30:59 +00:00
|
|
|
ResumeInst *CreateResume(Value *Exn) {
|
|
|
|
return Insert(ResumeInst::Create(Exn));
|
|
|
|
}
|
|
|
|
|
2007-05-27 15:09:34 +00:00
|
|
|
UnreachableInst *CreateUnreachable() {
|
2009-08-13 21:58:54 +00:00
|
|
|
return Insert(new UnreachableInst(Context));
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2008-08-11 15:29:30 +00:00
|
|
|
|
2007-05-27 15:09:34 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Instruction creation methods: Binary Operators
|
|
|
|
//===--------------------------------------------------------------------===//
|
2011-02-10 07:01:55 +00:00
|
|
|
private:
|
|
|
|
BinaryOperator *CreateInsertNUWNSWBinOp(BinaryOperator::BinaryOps Opc,
|
|
|
|
Value *LHS, Value *RHS,
|
|
|
|
const Twine &Name,
|
|
|
|
bool HasNUW, bool HasNSW) {
|
|
|
|
BinaryOperator *BO = Insert(BinaryOperator::Create(Opc, LHS, RHS), Name);
|
|
|
|
if (HasNUW) BO->setHasNoUnsignedWrap();
|
|
|
|
if (HasNSW) BO->setHasNoSignedWrap();
|
|
|
|
return BO;
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
Value *CreateAdd(Value *LHS, Value *RHS, const Twine &Name = "",
|
|
|
|
bool HasNUW = false, bool HasNSW = false) {
|
2008-04-13 06:22:09 +00:00
|
|
|
if (Constant *LC = dyn_cast<Constant>(LHS))
|
|
|
|
if (Constant *RC = dyn_cast<Constant>(RHS))
|
2011-02-10 07:01:55 +00:00
|
|
|
return Insert(Folder.CreateAdd(LC, RC, HasNUW, HasNSW), Name);
|
|
|
|
return CreateInsertNUWNSWBinOp(Instruction::Add, LHS, RHS, Name,
|
|
|
|
HasNUW, HasNSW);
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2011-02-10 07:01:55 +00:00
|
|
|
return CreateAdd(LHS, RHS, Name, false, true);
|
2009-08-11 20:20:39 +00:00
|
|
|
}
|
2010-02-02 12:53:04 +00:00
|
|
|
Value *CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2011-02-10 07:01:55 +00:00
|
|
|
return CreateAdd(LHS, RHS, Name, true, false);
|
2010-02-02 12:53:04 +00:00
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateFAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2009-06-04 22:49:04 +00:00
|
|
|
if (Constant *LC = dyn_cast<Constant>(LHS))
|
|
|
|
if (Constant *RC = dyn_cast<Constant>(RHS))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateFAdd(LC, RC), Name);
|
2009-06-04 22:49:04 +00:00
|
|
|
return Insert(BinaryOperator::CreateFAdd(LHS, RHS), Name);
|
|
|
|
}
|
2011-02-10 07:01:55 +00:00
|
|
|
Value *CreateSub(Value *LHS, Value *RHS, const Twine &Name = "",
|
|
|
|
bool HasNUW = false, bool HasNSW = false) {
|
2008-04-13 06:22:09 +00:00
|
|
|
if (Constant *LC = dyn_cast<Constant>(LHS))
|
|
|
|
if (Constant *RC = dyn_cast<Constant>(RHS))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateSub(LC, RC), Name);
|
2011-02-10 07:01:55 +00:00
|
|
|
return CreateInsertNUWNSWBinOp(Instruction::Sub, LHS, RHS, Name,
|
|
|
|
HasNUW, HasNSW);
|
2009-09-26 15:21:48 +00:00
|
|
|
}
|
|
|
|
Value *CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2011-02-10 07:01:55 +00:00
|
|
|
return CreateSub(LHS, RHS, Name, false, true);
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2010-02-02 12:53:04 +00:00
|
|
|
Value *CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2011-02-10 07:01:55 +00:00
|
|
|
return CreateSub(LHS, RHS, Name, true, false);
|
2010-02-02 12:53:04 +00:00
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateFSub(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2009-06-04 22:49:04 +00:00
|
|
|
if (Constant *LC = dyn_cast<Constant>(LHS))
|
|
|
|
if (Constant *RC = dyn_cast<Constant>(RHS))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateFSub(LC, RC), Name);
|
2009-06-04 22:49:04 +00:00
|
|
|
return Insert(BinaryOperator::CreateFSub(LHS, RHS), Name);
|
|
|
|
}
|
2011-02-10 07:01:55 +00:00
|
|
|
Value *CreateMul(Value *LHS, Value *RHS, const Twine &Name = "",
|
|
|
|
bool HasNUW = false, bool HasNSW = false) {
|
2008-04-13 06:22:09 +00:00
|
|
|
if (Constant *LC = dyn_cast<Constant>(LHS))
|
|
|
|
if (Constant *RC = dyn_cast<Constant>(RHS))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateMul(LC, RC), Name);
|
2011-02-10 07:01:55 +00:00
|
|
|
return CreateInsertNUWNSWBinOp(Instruction::Mul, LHS, RHS, Name,
|
|
|
|
HasNUW, HasNSW);
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2009-12-18 03:10:26 +00:00
|
|
|
Value *CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2011-02-10 07:01:55 +00:00
|
|
|
return CreateMul(LHS, RHS, Name, false, true);
|
2009-12-18 03:10:26 +00:00
|
|
|
}
|
2010-02-02 12:53:04 +00:00
|
|
|
Value *CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2011-02-10 07:01:55 +00:00
|
|
|
return CreateMul(LHS, RHS, Name, true, false);
|
2010-02-02 12:53:04 +00:00
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateFMul(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2009-06-04 22:49:04 +00:00
|
|
|
if (Constant *LC = dyn_cast<Constant>(LHS))
|
|
|
|
if (Constant *RC = dyn_cast<Constant>(RHS))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateFMul(LC, RC), Name);
|
2009-06-04 22:49:04 +00:00
|
|
|
return Insert(BinaryOperator::CreateFMul(LHS, RHS), Name);
|
|
|
|
}
|
2011-02-09 17:00:45 +00:00
|
|
|
Value *CreateUDiv(Value *LHS, Value *RHS, const Twine &Name = "",
|
|
|
|
bool isExact = false) {
|
2008-04-13 06:22:09 +00:00
|
|
|
if (Constant *LC = dyn_cast<Constant>(LHS))
|
|
|
|
if (Constant *RC = dyn_cast<Constant>(RHS))
|
2011-02-09 17:00:45 +00:00
|
|
|
return Insert(Folder.CreateUDiv(LC, RC, isExact), Name);
|
|
|
|
if (!isExact)
|
|
|
|
return Insert(BinaryOperator::CreateUDiv(LHS, RHS), Name);
|
|
|
|
return Insert(BinaryOperator::CreateExactUDiv(LHS, RHS), Name);
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2011-02-07 09:21:52 +00:00
|
|
|
Value *CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2011-02-09 17:00:45 +00:00
|
|
|
return CreateUDiv(LHS, RHS, Name, true);
|
2011-02-07 09:21:52 +00:00
|
|
|
}
|
2011-02-09 17:00:45 +00:00
|
|
|
Value *CreateSDiv(Value *LHS, Value *RHS, const Twine &Name = "",
|
|
|
|
bool isExact = false) {
|
2008-04-13 06:22:09 +00:00
|
|
|
if (Constant *LC = dyn_cast<Constant>(LHS))
|
|
|
|
if (Constant *RC = dyn_cast<Constant>(RHS))
|
2011-02-09 17:00:45 +00:00
|
|
|
return Insert(Folder.CreateSDiv(LC, RC, isExact), Name);
|
|
|
|
if (!isExact)
|
|
|
|
return Insert(BinaryOperator::CreateSDiv(LHS, RHS), Name);
|
|
|
|
return Insert(BinaryOperator::CreateExactSDiv(LHS, RHS), Name);
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2011-02-09 17:00:45 +00:00
|
|
|
return CreateSDiv(LHS, RHS, Name, true);
|
2009-08-11 17:05:24 +00:00
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateFDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2008-04-13 06:22:09 +00:00
|
|
|
if (Constant *LC = dyn_cast<Constant>(LHS))
|
|
|
|
if (Constant *RC = dyn_cast<Constant>(RHS))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateFDiv(LC, RC), Name);
|
2008-06-27 18:49:21 +00:00
|
|
|
return Insert(BinaryOperator::CreateFDiv(LHS, RHS), Name);
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateURem(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2008-04-13 06:22:09 +00:00
|
|
|
if (Constant *LC = dyn_cast<Constant>(LHS))
|
|
|
|
if (Constant *RC = dyn_cast<Constant>(RHS))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateURem(LC, RC), Name);
|
2008-06-27 18:49:21 +00:00
|
|
|
return Insert(BinaryOperator::CreateURem(LHS, RHS), Name);
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateSRem(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2008-04-13 06:22:09 +00:00
|
|
|
if (Constant *LC = dyn_cast<Constant>(LHS))
|
|
|
|
if (Constant *RC = dyn_cast<Constant>(RHS))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateSRem(LC, RC), Name);
|
2008-06-27 18:49:21 +00:00
|
|
|
return Insert(BinaryOperator::CreateSRem(LHS, RHS), Name);
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateFRem(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2008-04-13 06:22:09 +00:00
|
|
|
if (Constant *LC = dyn_cast<Constant>(LHS))
|
|
|
|
if (Constant *RC = dyn_cast<Constant>(RHS))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateFRem(LC, RC), Name);
|
2008-06-27 18:49:21 +00:00
|
|
|
return Insert(BinaryOperator::CreateFRem(LHS, RHS), Name);
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2010-04-13 01:38:57 +00:00
|
|
|
|
2011-02-10 07:01:55 +00:00
|
|
|
Value *CreateShl(Value *LHS, Value *RHS, const Twine &Name = "",
|
|
|
|
bool HasNUW = false, bool HasNSW = false) {
|
2008-04-13 06:22:09 +00:00
|
|
|
if (Constant *LC = dyn_cast<Constant>(LHS))
|
|
|
|
if (Constant *RC = dyn_cast<Constant>(RHS))
|
2011-02-10 07:01:55 +00:00
|
|
|
return Insert(Folder.CreateShl(LC, RC, HasNUW, HasNSW), Name);
|
|
|
|
return CreateInsertNUWNSWBinOp(Instruction::Shl, LHS, RHS, Name,
|
|
|
|
HasNUW, HasNSW);
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2011-02-10 07:01:55 +00:00
|
|
|
Value *CreateShl(Value *LHS, const APInt &RHS, const Twine &Name = "",
|
|
|
|
bool HasNUW = false, bool HasNSW = false) {
|
|
|
|
return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
|
|
|
|
HasNUW, HasNSW);
|
2010-04-13 01:38:57 +00:00
|
|
|
}
|
2011-02-10 07:01:55 +00:00
|
|
|
Value *CreateShl(Value *LHS, uint64_t RHS, const Twine &Name = "",
|
|
|
|
bool HasNUW = false, bool HasNSW = false) {
|
|
|
|
return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
|
|
|
|
HasNUW, HasNSW);
|
2009-12-06 01:56:22 +00:00
|
|
|
}
|
|
|
|
|
2011-02-09 17:00:45 +00:00
|
|
|
Value *CreateLShr(Value *LHS, Value *RHS, const Twine &Name = "",
|
|
|
|
bool isExact = false) {
|
2008-04-13 06:22:09 +00:00
|
|
|
if (Constant *LC = dyn_cast<Constant>(LHS))
|
|
|
|
if (Constant *RC = dyn_cast<Constant>(RHS))
|
2011-02-09 17:00:45 +00:00
|
|
|
return Insert(Folder.CreateLShr(LC, RC, isExact), Name);
|
|
|
|
if (!isExact)
|
|
|
|
return Insert(BinaryOperator::CreateLShr(LHS, RHS), Name);
|
|
|
|
return Insert(BinaryOperator::CreateExactLShr(LHS, RHS), Name);
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2011-02-09 17:00:45 +00:00
|
|
|
Value *CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
|
|
|
|
bool isExact = false) {
|
|
|
|
return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
|
2010-04-13 01:38:57 +00:00
|
|
|
}
|
2011-02-09 17:00:45 +00:00
|
|
|
Value *CreateLShr(Value *LHS, uint64_t RHS, const Twine &Name = "",
|
|
|
|
bool isExact = false) {
|
|
|
|
return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
|
2009-12-06 01:56:22 +00:00
|
|
|
}
|
2010-04-13 01:38:57 +00:00
|
|
|
|
2011-02-09 17:00:45 +00:00
|
|
|
Value *CreateAShr(Value *LHS, Value *RHS, const Twine &Name = "",
|
|
|
|
bool isExact = false) {
|
2008-04-13 06:22:09 +00:00
|
|
|
if (Constant *LC = dyn_cast<Constant>(LHS))
|
|
|
|
if (Constant *RC = dyn_cast<Constant>(RHS))
|
2011-02-09 17:00:45 +00:00
|
|
|
return Insert(Folder.CreateAShr(LC, RC, isExact), Name);
|
|
|
|
if (!isExact)
|
|
|
|
return Insert(BinaryOperator::CreateAShr(LHS, RHS), Name);
|
|
|
|
return Insert(BinaryOperator::CreateExactAShr(LHS, RHS), Name);
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2011-02-09 17:00:45 +00:00
|
|
|
Value *CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
|
|
|
|
bool isExact = false) {
|
|
|
|
return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
|
2010-04-13 01:38:57 +00:00
|
|
|
}
|
2011-02-09 17:00:45 +00:00
|
|
|
Value *CreateAShr(Value *LHS, uint64_t RHS, const Twine &Name = "",
|
|
|
|
bool isExact = false) {
|
|
|
|
return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
|
2009-12-06 01:56:22 +00:00
|
|
|
}
|
|
|
|
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateAnd(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2009-11-04 05:00:12 +00:00
|
|
|
if (Constant *RC = dyn_cast<Constant>(RHS)) {
|
|
|
|
if (isa<ConstantInt>(RC) && cast<ConstantInt>(RC)->isAllOnesValue())
|
|
|
|
return LHS; // LHS & -1 -> LHS
|
|
|
|
if (Constant *LC = dyn_cast<Constant>(LHS))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateAnd(LC, RC), Name);
|
2009-11-04 05:00:12 +00:00
|
|
|
}
|
2008-06-27 18:49:21 +00:00
|
|
|
return Insert(BinaryOperator::CreateAnd(LHS, RHS), Name);
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2010-04-13 01:38:57 +00:00
|
|
|
Value *CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name = "") {
|
2011-02-09 17:00:45 +00:00
|
|
|
return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
|
2010-04-13 01:38:57 +00:00
|
|
|
}
|
|
|
|
Value *CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name = "") {
|
2011-02-09 17:00:45 +00:00
|
|
|
return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
|
2010-04-13 01:38:57 +00:00
|
|
|
}
|
|
|
|
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateOr(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2009-11-04 05:00:12 +00:00
|
|
|
if (Constant *RC = dyn_cast<Constant>(RHS)) {
|
|
|
|
if (RC->isNullValue())
|
|
|
|
return LHS; // LHS | 0 -> LHS
|
|
|
|
if (Constant *LC = dyn_cast<Constant>(LHS))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateOr(LC, RC), Name);
|
2009-11-04 05:00:12 +00:00
|
|
|
}
|
2008-06-27 18:49:21 +00:00
|
|
|
return Insert(BinaryOperator::CreateOr(LHS, RHS), Name);
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2010-04-13 01:38:57 +00:00
|
|
|
Value *CreateOr(Value *LHS, const APInt &RHS, const Twine &Name = "") {
|
2011-02-09 17:00:45 +00:00
|
|
|
return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
|
2010-04-13 01:38:57 +00:00
|
|
|
}
|
|
|
|
Value *CreateOr(Value *LHS, uint64_t RHS, const Twine &Name = "") {
|
2011-02-09 17:00:45 +00:00
|
|
|
return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
|
2010-04-13 01:38:57 +00:00
|
|
|
}
|
|
|
|
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateXor(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2008-04-13 06:22:09 +00:00
|
|
|
if (Constant *LC = dyn_cast<Constant>(LHS))
|
|
|
|
if (Constant *RC = dyn_cast<Constant>(RHS))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateXor(LC, RC), Name);
|
2008-06-27 18:49:21 +00:00
|
|
|
return Insert(BinaryOperator::CreateXor(LHS, RHS), Name);
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2010-04-13 01:38:57 +00:00
|
|
|
Value *CreateXor(Value *LHS, const APInt &RHS, const Twine &Name = "") {
|
2011-02-09 17:00:45 +00:00
|
|
|
return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
|
2010-04-13 01:38:57 +00:00
|
|
|
}
|
|
|
|
Value *CreateXor(Value *LHS, uint64_t RHS, const Twine &Name = "") {
|
2011-02-09 17:00:45 +00:00
|
|
|
return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
|
2010-04-13 01:38:57 +00:00
|
|
|
}
|
2007-05-27 15:09:34 +00:00
|
|
|
|
2008-07-23 06:58:10 +00:00
|
|
|
Value *CreateBinOp(Instruction::BinaryOps Opc,
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *LHS, Value *RHS, const Twine &Name = "") {
|
2008-07-23 06:58:10 +00:00
|
|
|
if (Constant *LC = dyn_cast<Constant>(LHS))
|
|
|
|
if (Constant *RC = dyn_cast<Constant>(RHS))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateBinOp(Opc, LC, RC), Name);
|
2008-06-27 18:49:21 +00:00
|
|
|
return Insert(BinaryOperator::Create(Opc, LHS, RHS), Name);
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2008-08-11 15:29:30 +00:00
|
|
|
|
2011-02-10 07:01:55 +00:00
|
|
|
Value *CreateNeg(Value *V, const Twine &Name = "",
|
|
|
|
bool HasNUW = false, bool HasNSW = false) {
|
2008-07-23 06:58:10 +00:00
|
|
|
if (Constant *VC = dyn_cast<Constant>(V))
|
2011-02-10 07:01:55 +00:00
|
|
|
return Insert(Folder.CreateNeg(VC, HasNUW, HasNSW), Name);
|
|
|
|
BinaryOperator *BO = Insert(BinaryOperator::CreateNeg(V), Name);
|
|
|
|
if (HasNUW) BO->setHasNoUnsignedWrap();
|
|
|
|
if (HasNSW) BO->setHasNoSignedWrap();
|
|
|
|
return BO;
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2009-12-18 02:58:50 +00:00
|
|
|
Value *CreateNSWNeg(Value *V, const Twine &Name = "") {
|
2011-02-10 07:01:55 +00:00
|
|
|
return CreateNeg(V, Name, false, true);
|
2009-12-18 02:58:50 +00:00
|
|
|
}
|
2010-02-02 12:53:04 +00:00
|
|
|
Value *CreateNUWNeg(Value *V, const Twine &Name = "") {
|
2011-02-10 07:01:55 +00:00
|
|
|
return CreateNeg(V, Name, true, false);
|
2010-02-02 12:53:04 +00:00
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateFNeg(Value *V, const Twine &Name = "") {
|
2009-06-15 22:50:40 +00:00
|
|
|
if (Constant *VC = dyn_cast<Constant>(V))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateFNeg(VC), Name);
|
2009-08-12 16:23:25 +00:00
|
|
|
return Insert(BinaryOperator::CreateFNeg(V), Name);
|
2009-06-15 22:50:40 +00:00
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateNot(Value *V, const Twine &Name = "") {
|
2008-07-23 06:58:10 +00:00
|
|
|
if (Constant *VC = dyn_cast<Constant>(V))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateNot(VC), Name);
|
2009-08-12 16:23:25 +00:00
|
|
|
return Insert(BinaryOperator::CreateNot(V), Name);
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2008-08-11 15:29:30 +00:00
|
|
|
|
2007-05-27 15:09:34 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Instruction creation methods: Memory Instructions
|
|
|
|
//===--------------------------------------------------------------------===//
|
2008-08-11 15:29:30 +00:00
|
|
|
|
2011-07-18 04:54:35 +00:00
|
|
|
AllocaInst *CreateAlloca(Type *Ty, Value *ArraySize = 0,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2009-07-15 23:53:25 +00:00
|
|
|
return Insert(new AllocaInst(Ty, ArraySize), Name);
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
// Provided to resolve 'CreateLoad(Ptr, "...")' correctly, instead of
|
|
|
|
// converting the string to 'bool' for the isVolatile parameter.
|
|
|
|
LoadInst *CreateLoad(Value *Ptr, const char *Name) {
|
2008-08-09 06:26:23 +00:00
|
|
|
return Insert(new LoadInst(Ptr), Name);
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
LoadInst *CreateLoad(Value *Ptr, const Twine &Name = "") {
|
|
|
|
return Insert(new LoadInst(Ptr), Name);
|
|
|
|
}
|
2009-08-30 05:42:59 +00:00
|
|
|
LoadInst *CreateLoad(Value *Ptr, bool isVolatile, const Twine &Name = "") {
|
2008-08-09 06:26:23 +00:00
|
|
|
return Insert(new LoadInst(Ptr, 0, isVolatile), Name);
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
|
|
|
StoreInst *CreateStore(Value *Val, Value *Ptr, bool isVolatile = false) {
|
|
|
|
return Insert(new StoreInst(Val, Ptr, isVolatile));
|
|
|
|
}
|
2011-07-25 23:16:38 +00:00
|
|
|
FenceInst *CreateFence(AtomicOrdering Ordering,
|
|
|
|
SynchronizationScope SynchScope = CrossThread) {
|
|
|
|
return Insert(new FenceInst(Context, Ordering, SynchScope));
|
|
|
|
}
|
2011-08-02 00:45:35 +00:00
|
|
|
AtomicCmpXchgInst *CreateAtomicCmpXchg(Value *Ptr, Value *Cmp, Value *New,
|
|
|
|
AtomicOrdering Ordering,
|
|
|
|
SynchronizationScope SynchScope = CrossThread) {
|
2011-07-29 03:05:32 +00:00
|
|
|
return Insert(new AtomicCmpXchgInst(Ptr, Cmp, New, Ordering, SynchScope));
|
|
|
|
}
|
2011-08-02 00:45:35 +00:00
|
|
|
AtomicRMWInst *CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr, Value *Val,
|
|
|
|
AtomicOrdering Ordering,
|
|
|
|
SynchronizationScope SynchScope = CrossThread) {
|
2011-07-29 03:05:32 +00:00
|
|
|
return Insert(new AtomicRMWInst(Op, Ptr, Val, Ordering, SynchScope));
|
|
|
|
}
|
2011-07-22 08:16:57 +00:00
|
|
|
Value *CreateGEP(Value *Ptr, ArrayRef<Value *> IdxList,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2007-12-17 19:06:26 +00:00
|
|
|
if (Constant *PC = dyn_cast<Constant>(Ptr)) {
|
|
|
|
// Every index must be constant.
|
2011-07-22 08:16:57 +00:00
|
|
|
size_t i, e;
|
|
|
|
for (i = 0, e = IdxList.size(); i != e; ++i)
|
|
|
|
if (!isa<Constant>(IdxList[i]))
|
2007-12-17 19:06:26 +00:00
|
|
|
break;
|
2011-07-22 08:16:57 +00:00
|
|
|
if (i == e)
|
|
|
|
return Insert(Folder.CreateGetElementPtr(PC, IdxList), Name);
|
2008-08-11 15:29:30 +00:00
|
|
|
}
|
2011-07-25 09:48:08 +00:00
|
|
|
return Insert(GetElementPtrInst::Create(Ptr, IdxList), Name);
|
2007-12-17 19:06:26 +00:00
|
|
|
}
|
2011-07-22 08:16:57 +00:00
|
|
|
Value *CreateInBoundsGEP(Value *Ptr, ArrayRef<Value *> IdxList,
|
2010-10-27 07:39:54 +00:00
|
|
|
const Twine &Name = "") {
|
2009-08-11 17:57:01 +00:00
|
|
|
if (Constant *PC = dyn_cast<Constant>(Ptr)) {
|
|
|
|
// Every index must be constant.
|
2011-07-22 08:16:57 +00:00
|
|
|
size_t i, e;
|
|
|
|
for (i = 0, e = IdxList.size(); i != e; ++i)
|
|
|
|
if (!isa<Constant>(IdxList[i]))
|
2009-08-11 17:57:01 +00:00
|
|
|
break;
|
2011-07-22 08:16:57 +00:00
|
|
|
if (i == e)
|
|
|
|
return Insert(Folder.CreateInBoundsGetElementPtr(PC, IdxList), Name);
|
2009-08-11 17:57:01 +00:00
|
|
|
}
|
2011-07-25 09:48:08 +00:00
|
|
|
return Insert(GetElementPtrInst::CreateInBounds(Ptr, IdxList), Name);
|
2009-08-11 17:57:01 +00:00
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateGEP(Value *Ptr, Value *Idx, const Twine &Name = "") {
|
2007-12-17 19:06:26 +00:00
|
|
|
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
|
|
|
if (Constant *IC = dyn_cast<Constant>(Idx))
|
2011-07-21 07:52:17 +00:00
|
|
|
return Insert(Folder.CreateGetElementPtr(PC, IC), Name);
|
2008-06-27 18:49:21 +00:00
|
|
|
return Insert(GetElementPtrInst::Create(Ptr, Idx), Name);
|
2008-04-13 06:22:09 +00:00
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateInBoundsGEP(Value *Ptr, Value *Idx, const Twine &Name = "") {
|
2009-08-11 17:57:01 +00:00
|
|
|
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
|
|
|
if (Constant *IC = dyn_cast<Constant>(Idx))
|
2011-07-21 07:52:17 +00:00
|
|
|
return Insert(Folder.CreateInBoundsGetElementPtr(PC, IC), Name);
|
2009-08-11 17:57:01 +00:00
|
|
|
return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idx), Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const Twine &Name = "") {
|
2009-08-13 21:58:54 +00:00
|
|
|
Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
|
2009-03-06 22:26:07 +00:00
|
|
|
|
|
|
|
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
2011-07-21 07:52:17 +00:00
|
|
|
return Insert(Folder.CreateGetElementPtr(PC, Idx), Name);
|
2009-03-06 22:26:07 +00:00
|
|
|
|
2011-07-22 08:16:57 +00:00
|
|
|
return Insert(GetElementPtrInst::Create(Ptr, Idx), Name);
|
2009-03-06 22:26:07 +00:00
|
|
|
}
|
2009-08-11 17:57:01 +00:00
|
|
|
Value *CreateConstInBoundsGEP1_32(Value *Ptr, unsigned Idx0,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2009-08-13 21:58:54 +00:00
|
|
|
Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
|
2009-08-11 17:57:01 +00:00
|
|
|
|
|
|
|
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
2011-07-21 07:52:17 +00:00
|
|
|
return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idx), Name);
|
2009-08-11 17:57:01 +00:00
|
|
|
|
2011-07-22 08:16:57 +00:00
|
|
|
return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idx), Name);
|
2009-08-11 17:57:01 +00:00
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
Value *CreateConstGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2009-04-10 06:54:06 +00:00
|
|
|
Value *Idxs[] = {
|
2009-08-13 21:58:54 +00:00
|
|
|
ConstantInt::get(Type::getInt32Ty(Context), Idx0),
|
|
|
|
ConstantInt::get(Type::getInt32Ty(Context), Idx1)
|
2009-03-06 22:26:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
2011-07-21 07:52:17 +00:00
|
|
|
return Insert(Folder.CreateGetElementPtr(PC, Idxs), Name);
|
2009-03-06 22:26:07 +00:00
|
|
|
|
2011-07-25 09:48:08 +00:00
|
|
|
return Insert(GetElementPtrInst::Create(Ptr, Idxs), Name);
|
2009-03-06 22:26:07 +00:00
|
|
|
}
|
2009-08-11 17:57:01 +00:00
|
|
|
Value *CreateConstInBoundsGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2009-08-11 17:57:01 +00:00
|
|
|
Value *Idxs[] = {
|
2009-08-13 21:58:54 +00:00
|
|
|
ConstantInt::get(Type::getInt32Ty(Context), Idx0),
|
|
|
|
ConstantInt::get(Type::getInt32Ty(Context), Idx1)
|
2009-08-11 17:57:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
2011-07-21 07:52:17 +00:00
|
|
|
return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idxs), Name);
|
2009-08-11 17:57:01 +00:00
|
|
|
|
2011-07-25 09:48:08 +00:00
|
|
|
return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idxs), Name);
|
2009-08-11 17:57:01 +00:00
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name = "") {
|
2009-08-13 21:58:54 +00:00
|
|
|
Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
|
2009-03-06 22:26:07 +00:00
|
|
|
|
|
|
|
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
2011-07-21 07:52:17 +00:00
|
|
|
return Insert(Folder.CreateGetElementPtr(PC, Idx), Name);
|
2009-03-06 22:26:07 +00:00
|
|
|
|
2011-07-22 08:16:57 +00:00
|
|
|
return Insert(GetElementPtrInst::Create(Ptr, Idx), Name);
|
2009-03-06 22:26:07 +00:00
|
|
|
}
|
2009-08-11 17:57:01 +00:00
|
|
|
Value *CreateConstInBoundsGEP1_64(Value *Ptr, uint64_t Idx0,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2009-08-13 21:58:54 +00:00
|
|
|
Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
|
2009-08-11 17:57:01 +00:00
|
|
|
|
|
|
|
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
2011-07-21 07:52:17 +00:00
|
|
|
return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idx), Name);
|
2009-08-11 17:57:01 +00:00
|
|
|
|
2011-07-22 08:16:57 +00:00
|
|
|
return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idx), Name);
|
2009-08-11 17:57:01 +00:00
|
|
|
}
|
|
|
|
Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2009-04-10 06:54:06 +00:00
|
|
|
Value *Idxs[] = {
|
2009-08-13 21:58:54 +00:00
|
|
|
ConstantInt::get(Type::getInt64Ty(Context), Idx0),
|
|
|
|
ConstantInt::get(Type::getInt64Ty(Context), Idx1)
|
2008-04-13 06:22:09 +00:00
|
|
|
};
|
2008-08-11 15:29:30 +00:00
|
|
|
|
2008-04-13 06:22:09 +00:00
|
|
|
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
2011-07-21 07:52:17 +00:00
|
|
|
return Insert(Folder.CreateGetElementPtr(PC, Idxs), Name);
|
2008-08-11 15:29:30 +00:00
|
|
|
|
2011-07-25 09:48:08 +00:00
|
|
|
return Insert(GetElementPtrInst::Create(Ptr, Idxs), Name);
|
2009-03-06 22:26:07 +00:00
|
|
|
}
|
2009-08-11 17:57:01 +00:00
|
|
|
Value *CreateConstInBoundsGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2009-08-11 17:57:01 +00:00
|
|
|
Value *Idxs[] = {
|
2009-08-13 21:58:54 +00:00
|
|
|
ConstantInt::get(Type::getInt64Ty(Context), Idx0),
|
|
|
|
ConstantInt::get(Type::getInt64Ty(Context), Idx1)
|
2009-08-11 17:57:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
2011-07-21 07:52:17 +00:00
|
|
|
return Insert(Folder.CreateInBoundsGetElementPtr(PC, Idxs), Name);
|
2009-08-11 17:57:01 +00:00
|
|
|
|
2011-07-25 09:48:08 +00:00
|
|
|
return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idxs), Name);
|
2009-08-11 17:57:01 +00:00
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateStructGEP(Value *Ptr, unsigned Idx, const Twine &Name = "") {
|
2009-08-11 17:57:01 +00:00
|
|
|
return CreateConstInBoundsGEP2_32(Ptr, 0, Idx, Name);
|
2007-12-17 19:06:26 +00:00
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2009-12-28 21:28:46 +00:00
|
|
|
/// CreateGlobalStringPtr - Same as CreateGlobalString, but return a pointer
|
|
|
|
/// with "i8*" type instead of a pointer to array of i8.
|
2011-04-12 00:29:07 +00:00
|
|
|
Value *CreateGlobalStringPtr(StringRef Str, const Twine &Name = "") {
|
2008-07-02 22:57:59 +00:00
|
|
|
Value *gv = CreateGlobalString(Str, Name);
|
2009-08-13 21:58:54 +00:00
|
|
|
Value *zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
|
2008-07-02 22:57:59 +00:00
|
|
|
Value *Args[] = { zero, zero };
|
2011-07-22 08:16:57 +00:00
|
|
|
return CreateInBoundsGEP(gv, Args, Name);
|
2008-07-02 22:57:59 +00:00
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2007-12-17 19:06:26 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Instruction creation methods: Cast/Conversion Operators
|
|
|
|
//===--------------------------------------------------------------------===//
|
2008-08-11 15:29:30 +00:00
|
|
|
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *CreateTrunc(Value *V, Type *DestTy, const Twine &Name = "") {
|
2007-12-17 19:06:26 +00:00
|
|
|
return CreateCast(Instruction::Trunc, V, DestTy, Name);
|
|
|
|
}
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "") {
|
2007-12-17 19:06:26 +00:00
|
|
|
return CreateCast(Instruction::ZExt, V, DestTy, Name);
|
|
|
|
}
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *CreateSExt(Value *V, Type *DestTy, const Twine &Name = "") {
|
2007-12-17 19:06:26 +00:00
|
|
|
return CreateCast(Instruction::SExt, V, DestTy, Name);
|
|
|
|
}
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *CreateFPToUI(Value *V, Type *DestTy, const Twine &Name = ""){
|
2007-12-17 19:06:26 +00:00
|
|
|
return CreateCast(Instruction::FPToUI, V, DestTy, Name);
|
|
|
|
}
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *CreateFPToSI(Value *V, Type *DestTy, const Twine &Name = ""){
|
2007-12-17 19:06:26 +00:00
|
|
|
return CreateCast(Instruction::FPToSI, V, DestTy, Name);
|
|
|
|
}
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *CreateUIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
|
2007-12-17 19:06:26 +00:00
|
|
|
return CreateCast(Instruction::UIToFP, V, DestTy, Name);
|
|
|
|
}
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *CreateSIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
|
2007-12-17 19:06:26 +00:00
|
|
|
return CreateCast(Instruction::SIToFP, V, DestTy, Name);
|
|
|
|
}
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *CreateFPTrunc(Value *V, Type *DestTy,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2007-12-17 19:06:26 +00:00
|
|
|
return CreateCast(Instruction::FPTrunc, V, DestTy, Name);
|
|
|
|
}
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *CreateFPExt(Value *V, Type *DestTy, const Twine &Name = "") {
|
2007-12-17 19:06:26 +00:00
|
|
|
return CreateCast(Instruction::FPExt, V, DestTy, Name);
|
|
|
|
}
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *CreatePtrToInt(Value *V, Type *DestTy,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2007-12-17 19:06:26 +00:00
|
|
|
return CreateCast(Instruction::PtrToInt, V, DestTy, Name);
|
|
|
|
}
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *CreateIntToPtr(Value *V, Type *DestTy,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2007-12-17 19:06:26 +00:00
|
|
|
return CreateCast(Instruction::IntToPtr, V, DestTy, Name);
|
|
|
|
}
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *CreateBitCast(Value *V, Type *DestTy,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2007-12-17 19:06:26 +00:00
|
|
|
return CreateCast(Instruction::BitCast, V, DestTy, Name);
|
|
|
|
}
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *CreateZExtOrBitCast(Value *V, Type *DestTy,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2009-08-16 02:19:46 +00:00
|
|
|
if (V->getType() == DestTy)
|
|
|
|
return V;
|
|
|
|
if (Constant *VC = dyn_cast<Constant>(V))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateZExtOrBitCast(VC, DestTy), Name);
|
2009-08-16 02:19:46 +00:00
|
|
|
return Insert(CastInst::CreateZExtOrBitCast(V, DestTy), Name);
|
|
|
|
}
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *CreateSExtOrBitCast(Value *V, Type *DestTy,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2009-08-16 02:19:46 +00:00
|
|
|
if (V->getType() == DestTy)
|
|
|
|
return V;
|
|
|
|
if (Constant *VC = dyn_cast<Constant>(V))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateSExtOrBitCast(VC, DestTy), Name);
|
2009-08-16 02:19:46 +00:00
|
|
|
return Insert(CastInst::CreateSExtOrBitCast(V, DestTy), Name);
|
|
|
|
}
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *CreateTruncOrBitCast(Value *V, Type *DestTy,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2009-08-16 02:19:46 +00:00
|
|
|
if (V->getType() == DestTy)
|
|
|
|
return V;
|
|
|
|
if (Constant *VC = dyn_cast<Constant>(V))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateTruncOrBitCast(VC, DestTy), Name);
|
2009-08-16 02:19:46 +00:00
|
|
|
return Insert(CastInst::CreateTruncOrBitCast(V, DestTy), Name);
|
|
|
|
}
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2008-04-04 08:28:13 +00:00
|
|
|
if (V->getType() == DestTy)
|
|
|
|
return V;
|
2007-12-17 19:06:26 +00:00
|
|
|
if (Constant *VC = dyn_cast<Constant>(V))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateCast(Op, VC, DestTy), Name);
|
2008-06-27 18:49:21 +00:00
|
|
|
return Insert(CastInst::Create(Op, V, DestTy), Name);
|
2007-12-17 19:06:26 +00:00
|
|
|
}
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *CreatePointerCast(Value *V, Type *DestTy,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2009-08-16 02:19:46 +00:00
|
|
|
if (V->getType() == DestTy)
|
|
|
|
return V;
|
|
|
|
if (Constant *VC = dyn_cast<Constant>(V))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreatePointerCast(VC, DestTy), Name);
|
2009-08-16 02:19:46 +00:00
|
|
|
return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
|
|
|
|
}
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *CreateIntCast(Value *V, Type *DestTy, bool isSigned,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2008-04-04 08:28:13 +00:00
|
|
|
if (V->getType() == DestTy)
|
|
|
|
return V;
|
2007-12-17 19:06:26 +00:00
|
|
|
if (Constant *VC = dyn_cast<Constant>(V))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateIntCast(VC, DestTy, isSigned), Name);
|
2008-06-27 18:49:21 +00:00
|
|
|
return Insert(CastInst::CreateIntegerCast(V, DestTy, isSigned), Name);
|
2007-12-17 19:06:26 +00:00
|
|
|
}
|
2009-11-17 08:34:52 +00:00
|
|
|
private:
|
|
|
|
// Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a compile time
|
|
|
|
// error, instead of converting the string to bool for the isSigned parameter.
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *CreateIntCast(Value *, Type *, const char *); // DO NOT IMPLEMENT
|
2009-11-17 08:34:52 +00:00
|
|
|
public:
|
2011-07-18 04:54:35 +00:00
|
|
|
Value *CreateFPCast(Value *V, Type *DestTy, const Twine &Name = "") {
|
2009-08-16 02:19:46 +00:00
|
|
|
if (V->getType() == DestTy)
|
|
|
|
return V;
|
|
|
|
if (Constant *VC = dyn_cast<Constant>(V))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateFPCast(VC, DestTy), Name);
|
2009-08-16 02:19:46 +00:00
|
|
|
return Insert(CastInst::CreateFPCast(V, DestTy), Name);
|
|
|
|
}
|
2008-04-04 08:28:13 +00:00
|
|
|
|
2007-10-09 19:49:19 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Instruction creation methods: Compare Instructions
|
|
|
|
//===--------------------------------------------------------------------===//
|
2008-08-11 15:29:30 +00:00
|
|
|
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateICmp(ICmpInst::ICMP_EQ, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateICmp(ICmpInst::ICMP_NE, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateICmp(ICmpInst::ICMP_UGT, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateICmp(ICmpInst::ICMP_UGE, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateICmp(ICmpInst::ICMP_ULT, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateICmp(ICmpInst::ICMP_ULE, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateICmp(ICmpInst::ICMP_SGT, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateICmp(ICmpInst::ICMP_SGE, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateICmp(ICmpInst::ICMP_SLT, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateICmp(ICmpInst::ICMP_SLE, LHS, RHS, Name);
|
|
|
|
}
|
2008-08-11 15:29:30 +00:00
|
|
|
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateFCmp(FCmpInst::FCMP_OEQ, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateFCmp(FCmpInst::FCMP_OGT, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateFCmp(FCmpInst::FCMP_OGE, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateFCmp(FCmpInst::FCMP_OLT, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateFCmp(FCmpInst::FCMP_OLE, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateFCmp(FCmpInst::FCMP_ONE, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateFCmp(FCmpInst::FCMP_ORD, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateFCmp(FCmpInst::FCMP_UNO, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateFCmp(FCmpInst::FCMP_UEQ, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateFCmp(FCmpInst::FCMP_UGT, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateFCmp(FCmpInst::FCMP_UGE, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateFCmp(FCmpInst::FCMP_ULT, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateFCmp(FCmpInst::FCMP_ULE, LHS, RHS, Name);
|
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2007-10-09 19:49:19 +00:00
|
|
|
return CreateFCmp(FCmpInst::FCMP_UNE, LHS, RHS, Name);
|
|
|
|
}
|
2008-04-13 06:22:09 +00:00
|
|
|
|
2008-08-11 15:29:30 +00:00
|
|
|
Value *CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2007-10-09 21:41:00 +00:00
|
|
|
if (Constant *LC = dyn_cast<Constant>(LHS))
|
2007-10-09 19:49:19 +00:00
|
|
|
if (Constant *RC = dyn_cast<Constant>(RHS))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateICmp(P, LC, RC), Name);
|
2009-08-25 23:17:54 +00:00
|
|
|
return Insert(new ICmpInst(P, LHS, RHS), Name);
|
2007-10-09 19:49:19 +00:00
|
|
|
}
|
2008-08-11 15:29:30 +00:00
|
|
|
Value *CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2007-10-09 21:41:00 +00:00
|
|
|
if (Constant *LC = dyn_cast<Constant>(LHS))
|
2007-10-09 19:49:19 +00:00
|
|
|
if (Constant *RC = dyn_cast<Constant>(RHS))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateFCmp(P, LC, RC), Name);
|
2009-08-25 23:17:54 +00:00
|
|
|
return Insert(new FCmpInst(P, LHS, RHS), Name);
|
2007-10-09 19:49:19 +00:00
|
|
|
}
|
2007-12-17 19:06:26 +00:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Instruction creation methods: Other Instructions
|
|
|
|
//===--------------------------------------------------------------------===//
|
2008-04-13 06:22:09 +00:00
|
|
|
|
2011-07-18 04:54:35 +00:00
|
|
|
PHINode *CreatePHI(Type *Ty, unsigned NumReservedValues,
|
2011-03-30 11:28:46 +00:00
|
|
|
const Twine &Name = "") {
|
|
|
|
return Insert(PHINode::Create(Ty, NumReservedValues), Name);
|
2008-04-13 06:22:09 +00:00
|
|
|
}
|
|
|
|
|
2009-08-19 22:34:21 +00:00
|
|
|
CallInst *CreateCall(Value *Callee, const Twine &Name = "") {
|
2009-06-18 20:05:31 +00:00
|
|
|
return Insert(CallInst::Create(Callee), Name);
|
2008-04-13 06:22:09 +00:00
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
CallInst *CreateCall(Value *Callee, Value *Arg, const Twine &Name = "") {
|
2009-06-18 20:05:31 +00:00
|
|
|
return Insert(CallInst::Create(Callee, Arg), Name);
|
2008-04-13 06:22:09 +00:00
|
|
|
}
|
2008-05-01 05:11:00 +00:00
|
|
|
CallInst *CreateCall2(Value *Callee, Value *Arg1, Value *Arg2,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2008-05-01 05:11:00 +00:00
|
|
|
Value *Args[] = { Arg1, Arg2 };
|
2011-07-15 08:37:34 +00:00
|
|
|
return Insert(CallInst::Create(Callee, Args), Name);
|
2008-05-01 05:11:00 +00:00
|
|
|
}
|
2008-05-01 05:23:45 +00:00
|
|
|
CallInst *CreateCall3(Value *Callee, Value *Arg1, Value *Arg2, Value *Arg3,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2008-05-01 05:23:45 +00:00
|
|
|
Value *Args[] = { Arg1, Arg2, Arg3 };
|
2011-07-15 08:37:34 +00:00
|
|
|
return Insert(CallInst::Create(Callee, Args), Name);
|
2008-05-01 05:23:45 +00:00
|
|
|
}
|
|
|
|
CallInst *CreateCall4(Value *Callee, Value *Arg1, Value *Arg2, Value *Arg3,
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *Arg4, const Twine &Name = "") {
|
2008-05-01 05:23:45 +00:00
|
|
|
Value *Args[] = { Arg1, Arg2, Arg3, Arg4 };
|
2011-07-15 08:37:34 +00:00
|
|
|
return Insert(CallInst::Create(Callee, Args), Name);
|
2008-05-01 05:23:45 +00:00
|
|
|
}
|
Reapply address space patch after fixing an issue in MemCopyOptimizer.
Added support for address spaces and added a isVolatile field to memcpy, memmove, and memset,
e.g., llvm.memcpy.i32(i8*, i8*, i32, i32) -> llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100304 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-04 03:10:48 +00:00
|
|
|
CallInst *CreateCall5(Value *Callee, Value *Arg1, Value *Arg2, Value *Arg3,
|
|
|
|
Value *Arg4, Value *Arg5, const Twine &Name = "") {
|
|
|
|
Value *Args[] = { Arg1, Arg2, Arg3, Arg4, Arg5 };
|
2011-07-15 08:37:34 +00:00
|
|
|
return Insert(CallInst::Create(Callee, Args), Name);
|
Reapply address space patch after fixing an issue in MemCopyOptimizer.
Added support for address spaces and added a isVolatile field to memcpy, memmove, and memset,
e.g., llvm.memcpy.i32(i8*, i8*, i32, i32) -> llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100304 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-04 03:10:48 +00:00
|
|
|
}
|
2008-08-11 15:29:30 +00:00
|
|
|
|
2011-07-15 08:37:34 +00:00
|
|
|
CallInst *CreateCall(Value *Callee, ArrayRef<Value *> Args,
|
2011-04-07 00:03:25 +00:00
|
|
|
const Twine &Name = "") {
|
2011-08-10 01:10:08 +00:00
|
|
|
return Insert(CallInst::Create(Callee, Args), Name);
|
2008-04-13 06:22:09 +00:00
|
|
|
}
|
|
|
|
|
2007-12-17 19:06:26 +00:00
|
|
|
Value *CreateSelect(Value *C, Value *True, Value *False,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2007-12-17 19:06:26 +00:00
|
|
|
if (Constant *CC = dyn_cast<Constant>(C))
|
|
|
|
if (Constant *TC = dyn_cast<Constant>(True))
|
|
|
|
if (Constant *FC = dyn_cast<Constant>(False))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateSelect(CC, TC, FC), Name);
|
2008-06-27 18:49:21 +00:00
|
|
|
return Insert(SelectInst::Create(C, True, False), Name);
|
2007-12-17 19:06:26 +00:00
|
|
|
}
|
2008-04-13 06:22:09 +00:00
|
|
|
|
2011-07-18 04:54:35 +00:00
|
|
|
VAArgInst *CreateVAArg(Value *List, Type *Ty, const Twine &Name = "") {
|
2008-06-27 18:49:21 +00:00
|
|
|
return Insert(new VAArgInst(List, Ty), Name);
|
2008-04-13 06:22:09 +00:00
|
|
|
}
|
|
|
|
|
2007-12-17 19:06:26 +00:00
|
|
|
Value *CreateExtractElement(Value *Vec, Value *Idx,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2007-12-17 19:06:26 +00:00
|
|
|
if (Constant *VC = dyn_cast<Constant>(Vec))
|
|
|
|
if (Constant *IC = dyn_cast<Constant>(Idx))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateExtractElement(VC, IC), Name);
|
2009-07-25 02:28:41 +00:00
|
|
|
return Insert(ExtractElementInst::Create(Vec, Idx), Name);
|
2007-12-17 19:06:26 +00:00
|
|
|
}
|
2008-04-13 06:22:09 +00:00
|
|
|
|
2007-12-17 19:06:26 +00:00
|
|
|
Value *CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2007-12-17 19:06:26 +00:00
|
|
|
if (Constant *VC = dyn_cast<Constant>(Vec))
|
|
|
|
if (Constant *NC = dyn_cast<Constant>(NewElt))
|
|
|
|
if (Constant *IC = dyn_cast<Constant>(Idx))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateInsertElement(VC, NC, IC), Name);
|
2008-06-27 18:49:21 +00:00
|
|
|
return Insert(InsertElementInst::Create(Vec, NewElt, Idx), Name);
|
2007-12-17 19:06:26 +00:00
|
|
|
}
|
2008-04-13 06:22:09 +00:00
|
|
|
|
2007-12-17 19:06:26 +00:00
|
|
|
Value *CreateShuffleVector(Value *V1, Value *V2, Value *Mask,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2007-12-17 19:06:26 +00:00
|
|
|
if (Constant *V1C = dyn_cast<Constant>(V1))
|
|
|
|
if (Constant *V2C = dyn_cast<Constant>(V2))
|
|
|
|
if (Constant *MC = dyn_cast<Constant>(Mask))
|
2010-11-18 02:15:42 +00:00
|
|
|
return Insert(Folder.CreateShuffleVector(V1C, V2C, MC), Name);
|
2008-06-27 18:49:21 +00:00
|
|
|
return Insert(new ShuffleVectorInst(V1, V2, Mask), Name);
|
2007-12-17 19:06:26 +00:00
|
|
|
}
|
2008-07-22 18:25:25 +00:00
|
|
|
|
2008-07-22 20:19:25 +00:00
|
|
|
Value *CreateExtractValue(Value *Agg,
|
2011-07-13 10:26:04 +00:00
|
|
|
ArrayRef<unsigned> Idxs,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2008-07-22 20:19:25 +00:00
|
|
|
if (Constant *AggC = dyn_cast<Constant>(Agg))
|
2011-07-13 10:26:04 +00:00
|
|
|
return Insert(Folder.CreateExtractValue(AggC, Idxs), Name);
|
|
|
|
return Insert(ExtractValueInst::Create(Agg, Idxs), Name);
|
2008-07-22 18:25:25 +00:00
|
|
|
}
|
|
|
|
|
2008-07-22 20:19:25 +00:00
|
|
|
Value *CreateInsertValue(Value *Agg, Value *Val,
|
2011-07-13 10:26:04 +00:00
|
|
|
ArrayRef<unsigned> Idxs,
|
2009-08-19 22:34:21 +00:00
|
|
|
const Twine &Name = "") {
|
2008-07-22 20:19:25 +00:00
|
|
|
if (Constant *AggC = dyn_cast<Constant>(Agg))
|
|
|
|
if (Constant *ValC = dyn_cast<Constant>(Val))
|
2011-07-13 10:26:04 +00:00
|
|
|
return Insert(Folder.CreateInsertValue(AggC, ValC, Idxs), Name);
|
|
|
|
return Insert(InsertValueInst::Create(Agg, Val, Idxs), Name);
|
2008-07-22 18:25:25 +00:00
|
|
|
}
|
2008-09-27 23:22:55 +00:00
|
|
|
|
2011-08-12 20:24:12 +00:00
|
|
|
LandingPadInst *CreateLandingPad(Type *Ty, Value *PersFn, unsigned NumClauses,
|
|
|
|
const Twine &Name = "") {
|
|
|
|
return Insert(LandingPadInst::Create(Ty, PersFn, NumClauses, Name));
|
|
|
|
}
|
|
|
|
|
2008-09-27 23:22:55 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Utility creation methods
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// CreateIsNull - Return an i1 value testing if \arg Arg is null.
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateIsNull(Value *Arg, const Twine &Name = "") {
|
2009-07-31 20:28:14 +00:00
|
|
|
return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()),
|
2008-09-27 23:22:55 +00:00
|
|
|
Name);
|
|
|
|
}
|
|
|
|
|
2008-10-02 17:05:03 +00:00
|
|
|
/// CreateIsNotNull - Return an i1 value testing if \arg Arg is not null.
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateIsNotNull(Value *Arg, const Twine &Name = "") {
|
2009-07-31 20:28:14 +00:00
|
|
|
return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()),
|
2008-09-27 23:22:55 +00:00
|
|
|
Name);
|
|
|
|
}
|
2009-02-20 22:51:36 +00:00
|
|
|
|
2009-04-10 05:30:48 +00:00
|
|
|
/// CreatePtrDiff - Return the i64 difference between two pointer values,
|
|
|
|
/// dividing out the size of the pointed-to objects. This is intended to
|
2009-08-11 17:05:24 +00:00
|
|
|
/// implement C-style pointer subtraction. As such, the pointers must be
|
|
|
|
/// appropriately aligned for their element types and pointing into the
|
|
|
|
/// same object.
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreatePtrDiff(Value *LHS, Value *RHS, const Twine &Name = "") {
|
2009-04-10 05:30:48 +00:00
|
|
|
assert(LHS->getType() == RHS->getType() &&
|
|
|
|
"Pointer subtraction operand types must match!");
|
2011-07-12 04:14:22 +00:00
|
|
|
PointerType *ArgType = cast<PointerType>(LHS->getType());
|
2009-08-13 21:58:54 +00:00
|
|
|
Value *LHS_int = CreatePtrToInt(LHS, Type::getInt64Ty(Context));
|
|
|
|
Value *RHS_int = CreatePtrToInt(RHS, Type::getInt64Ty(Context));
|
2009-04-10 05:30:48 +00:00
|
|
|
Value *Difference = CreateSub(LHS_int, RHS_int);
|
2009-08-11 17:05:24 +00:00
|
|
|
return CreateExactSDiv(Difference,
|
|
|
|
ConstantExpr::getSizeOf(ArgType->getElementType()),
|
|
|
|
Name);
|
2009-04-10 05:30:48 +00:00
|
|
|
}
|
2007-10-09 19:49:19 +00:00
|
|
|
};
|
2008-08-11 15:29:30 +00:00
|
|
|
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|