2012-06-29 12:38:19 +00:00
|
|
|
//===---- llvm/IRBuilder.h - Builder for LLVM Instructions ------*- 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-10 00:45:19 +00:00
|
|
|
#ifndef LLVM_IR_IRBUILDER_H
|
|
|
|
#define LLVM_IR_IRBUILDER_H
|
2007-05-27 15:09:34 +00:00
|
|
|
|
2012-12-03 17:02:12 +00:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/ADT/Twine.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/BasicBlock.h"
|
2014-03-04 12:02:47 +00:00
|
|
|
#include "llvm/IR/ConstantFolder.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
2015-04-03 21:33:42 +00:00
|
|
|
#include "llvm/IR/GlobalVariable.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Operator.h"
|
2014-03-04 11:17:44 +00:00
|
|
|
#include "llvm/IR/ValueHandle.h"
|
2013-05-01 20:59:00 +00:00
|
|
|
#include "llvm/Support/CBindingWrapping.h"
|
2007-05-27 15:09:34 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2014-11-11 21:30:22 +00:00
|
|
|
class MDNode;
|
2007-05-27 15:09:34 +00:00
|
|
|
|
2013-01-30 22:56:31 +00:00
|
|
|
/// \brief 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.
|
2009-08-30 05:42:59 +00:00
|
|
|
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
|
|
|
|
2013-01-30 22:56:31 +00:00
|
|
|
/// \brief Common base class shared among various IRBuilders.
|
2009-12-28 21:28:46 +00:00
|
|
|
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;
|
2013-09-30 15:39:27 +00:00
|
|
|
|
|
|
|
MDNode *DefaultFPMathTag;
|
|
|
|
FastMathFlags FMF;
|
2007-05-27 15:09:34 +00:00
|
|
|
public:
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2014-04-09 06:08:46 +00:00
|
|
|
IRBuilderBase(LLVMContext &context, MDNode *FPMathTag = nullptr)
|
2013-09-30 15:39:27 +00:00
|
|
|
: Context(context), DefaultFPMathTag(FPMathTag), FMF() {
|
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
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Clear the insertion point: created instructions will not be
|
|
|
|
/// inserted into a block.
|
2007-05-27 15:09:34 +00:00
|
|
|
void ClearInsertionPoint() {
|
2014-04-09 06:08:46 +00:00
|
|
|
BB = nullptr;
|
|
|
|
InsertPt = nullptr;
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
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
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief This specifies that created instructions should be appended to the
|
|
|
|
/// end of the specified block.
|
2007-05-27 15:09:34 +00:00
|
|
|
void SetInsertPoint(BasicBlock *TheBB) {
|
|
|
|
BB = TheBB;
|
|
|
|
InsertPt = BB->end();
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief This specifies that created instructions should be inserted before
|
|
|
|
/// the specified instruction.
|
2010-12-19 19:16:22 +00:00
|
|
|
void SetInsertPoint(Instruction *I) {
|
|
|
|
BB = I->getParent();
|
|
|
|
InsertPt = I;
|
2013-07-09 17:54:22 +00:00
|
|
|
assert(I != BB->end() && "Can't read debug loc from end()");
|
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
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief This specifies that created instructions should be inserted at the
|
|
|
|
/// specified point.
|
2007-05-27 15:09:34 +00:00
|
|
|
void SetInsertPoint(BasicBlock *TheBB, BasicBlock::iterator IP) {
|
|
|
|
BB = TheBB;
|
|
|
|
InsertPt = IP;
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Find the nearest point that dominates this use, and specify that
|
|
|
|
/// created instructions should be inserted at this point.
|
2011-06-29 23:01:52 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Set location information used by debugging information.
|
2015-02-07 12:28:15 +00:00
|
|
|
void SetCurrentDebugLocation(DebugLoc L) { CurDbgLocation = std::move(L); }
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Get location information used by debugging information.
|
2015-02-07 12:28:15 +00:00
|
|
|
const DebugLoc &getCurrentDebugLocation() const { return CurDbgLocation; }
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief 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 {
|
2015-03-30 19:40:05 +00:00
|
|
|
if (CurDbgLocation)
|
2010-04-01 06:31:45 +00:00
|
|
|
I->setDebugLoc(CurDbgLocation);
|
2010-03-31 04:09:11 +00:00
|
|
|
}
|
2009-12-28 21:45:40 +00:00
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief 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:
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Creates a new insertion point which doesn't point to anything.
|
2014-04-09 06:08:46 +00:00
|
|
|
InsertPoint() : Block(nullptr) {}
|
2010-07-06 18:07:52 +00:00
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Creates a new insertion point at the given location.
|
2010-07-06 18:07:52 +00:00
|
|
|
InsertPoint(BasicBlock *InsertBlock, BasicBlock::iterator InsertPoint)
|
|
|
|
: Block(InsertBlock), Point(InsertPoint) {}
|
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Returns true if this insert point is set.
|
2014-04-09 06:08:46 +00:00
|
|
|
bool isSet() const { return (Block != nullptr); }
|
2010-07-06 18:07:52 +00:00
|
|
|
|
|
|
|
llvm::BasicBlock *getBlock() const { return Block; }
|
|
|
|
llvm::BasicBlock::iterator getPoint() const { return Point; }
|
|
|
|
};
|
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Returns the current insert point.
|
2010-07-06 18:07:52 +00:00
|
|
|
InsertPoint saveIP() const {
|
|
|
|
return InsertPoint(GetInsertBlock(), GetInsertPoint());
|
|
|
|
}
|
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Returns the current insert point, clearing it in the process.
|
2010-07-06 18:07:52 +00:00
|
|
|
InsertPoint saveAndClearIP() {
|
|
|
|
InsertPoint IP(GetInsertBlock(), GetInsertPoint());
|
|
|
|
ClearInsertionPoint();
|
|
|
|
return IP;
|
|
|
|
}
|
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Sets the current insert point to a previously-saved location.
|
2010-07-06 18:07:52 +00:00
|
|
|
void restoreIP(InsertPoint IP) {
|
|
|
|
if (IP.isSet())
|
|
|
|
SetInsertPoint(IP.getBlock(), IP.getPoint());
|
|
|
|
else
|
|
|
|
ClearInsertionPoint();
|
|
|
|
}
|
|
|
|
|
2013-09-30 15:39:27 +00:00
|
|
|
/// \brief Get the floating point math metadata being used.
|
|
|
|
MDNode *getDefaultFPMathTag() const { return DefaultFPMathTag; }
|
|
|
|
|
|
|
|
/// \brief Get the flags to be applied to created floating point ops
|
|
|
|
FastMathFlags getFastMathFlags() const { return FMF; }
|
|
|
|
|
|
|
|
/// \brief Clear the fast-math flags.
|
|
|
|
void clearFastMathFlags() { FMF.clear(); }
|
|
|
|
|
|
|
|
/// \brief Set the floating point math metadata to be used.
|
|
|
|
void SetDefaultFPMathTag(MDNode *FPMathTag) { DefaultFPMathTag = FPMathTag; }
|
|
|
|
|
|
|
|
/// \brief Set the fast-math flags to be used with generated fp-math operators
|
|
|
|
void SetFastMathFlags(FastMathFlags NewFMF) { FMF = NewFMF; }
|
|
|
|
|
2009-12-28 21:28:46 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
2013-09-30 15:39:48 +00:00
|
|
|
// RAII helpers.
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// \brief RAII object that stores the current insertion point and restores it
|
|
|
|
// when the object is destroyed. This includes the debug location.
|
|
|
|
class InsertPointGuard {
|
|
|
|
IRBuilderBase &Builder;
|
|
|
|
AssertingVH<BasicBlock> Block;
|
2013-10-08 17:44:56 +00:00
|
|
|
BasicBlock::iterator Point;
|
2013-09-30 15:39:48 +00:00
|
|
|
DebugLoc DbgLoc;
|
|
|
|
|
2015-02-15 22:54:22 +00:00
|
|
|
InsertPointGuard(const InsertPointGuard &) = delete;
|
|
|
|
InsertPointGuard &operator=(const InsertPointGuard &) = delete;
|
2013-09-30 15:39:48 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
InsertPointGuard(IRBuilderBase &B)
|
|
|
|
: Builder(B), Block(B.GetInsertBlock()), Point(B.GetInsertPoint()),
|
|
|
|
DbgLoc(B.getCurrentDebugLocation()) {}
|
|
|
|
|
|
|
|
~InsertPointGuard() {
|
2013-10-08 17:44:56 +00:00
|
|
|
Builder.restoreIP(InsertPoint(Block, Point));
|
2013-09-30 15:39:48 +00:00
|
|
|
Builder.SetCurrentDebugLocation(DbgLoc);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// \brief RAII object that stores the current fast math settings and restores
|
|
|
|
// them when the object is destroyed.
|
|
|
|
class FastMathFlagGuard {
|
|
|
|
IRBuilderBase &Builder;
|
|
|
|
FastMathFlags FMF;
|
|
|
|
MDNode *FPMathTag;
|
|
|
|
|
2015-02-15 22:54:22 +00:00
|
|
|
FastMathFlagGuard(const FastMathFlagGuard &) = delete;
|
2013-09-30 15:39:48 +00:00
|
|
|
FastMathFlagGuard &operator=(
|
2015-02-15 22:54:22 +00:00
|
|
|
const FastMathFlagGuard &) = delete;
|
2013-09-30 15:39:48 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
FastMathFlagGuard(IRBuilderBase &B)
|
|
|
|
: Builder(B), FMF(B.FMF), FPMathTag(B.DefaultFPMathTag) {}
|
|
|
|
|
|
|
|
~FastMathFlagGuard() {
|
|
|
|
Builder.FMF = FMF;
|
|
|
|
Builder.DefaultFPMathTag = FPMathTag;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
2009-12-28 21:28:46 +00:00
|
|
|
// Miscellaneous creation methods.
|
|
|
|
//===--------------------------------------------------------------------===//
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Make a new global variable with initializer type i8*
|
|
|
|
///
|
|
|
|
/// Make a new global variable with an initializer that has array of i8 type
|
|
|
|
/// filled in with the null terminated string value 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.
|
2015-04-03 21:33:42 +00:00
|
|
|
GlobalVariable *CreateGlobalString(StringRef Str, const Twine &Name = "");
|
2010-07-06 18:34:49 +00:00
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Get a constant value representing either true or false.
|
2010-07-06 18:34:49 +00:00
|
|
|
ConstantInt *getInt1(bool V) {
|
|
|
|
return ConstantInt::get(getInt1Ty(), V);
|
|
|
|
}
|
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Get the constant value for i1 true.
|
2010-07-06 18:34:49 +00:00
|
|
|
ConstantInt *getTrue() {
|
|
|
|
return ConstantInt::getTrue(Context);
|
|
|
|
}
|
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Get the constant value for i1 false.
|
2010-07-06 18:34:49 +00:00
|
|
|
ConstantInt *getFalse() {
|
|
|
|
return ConstantInt::getFalse(Context);
|
|
|
|
}
|
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Get a constant 8-bit value.
|
2010-07-06 18:34:49 +00:00
|
|
|
ConstantInt *getInt8(uint8_t C) {
|
|
|
|
return ConstantInt::get(getInt8Ty(), C);
|
|
|
|
}
|
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Get a constant 16-bit value.
|
2010-07-06 18:34:49 +00:00
|
|
|
ConstantInt *getInt16(uint16_t C) {
|
|
|
|
return ConstantInt::get(getInt16Ty(), C);
|
|
|
|
}
|
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Get a constant 32-bit value.
|
2010-07-06 18:34:49 +00:00
|
|
|
ConstantInt *getInt32(uint32_t C) {
|
|
|
|
return ConstantInt::get(getInt32Ty(), C);
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Get a constant 64-bit value.
|
2010-07-06 18:34:49 +00:00
|
|
|
ConstantInt *getInt64(uint64_t C) {
|
|
|
|
return ConstantInt::get(getInt64Ty(), C);
|
|
|
|
}
|
2011-06-29 22:52:51 +00:00
|
|
|
|
2014-02-26 10:08:11 +00:00
|
|
|
/// \brief Get a constant N-bit value, zero extended or truncated from
|
|
|
|
/// a 64-bit value.
|
|
|
|
ConstantInt *getIntN(unsigned N, uint64_t C) {
|
|
|
|
return ConstantInt::get(getIntNTy(N), C);
|
|
|
|
}
|
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief 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
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief 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
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief 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
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief 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
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Fetch the type representing 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
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief 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);
|
|
|
|
}
|
2014-02-26 10:08:11 +00:00
|
|
|
|
2015-04-17 15:32:15 +00:00
|
|
|
/// \brief Fetch the type representing a 128-bit integer.
|
|
|
|
IntegerType *getInt128Ty() {
|
|
|
|
return Type::getInt128Ty(Context);
|
|
|
|
}
|
|
|
|
|
2014-02-26 10:08:11 +00:00
|
|
|
/// \brief Fetch the type representing an N-bit integer.
|
|
|
|
IntegerType *getIntNTy(unsigned N) {
|
|
|
|
return Type::getIntNTy(Context, N);
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2014-07-02 17:33:00 +00:00
|
|
|
/// \brief Fetch the type representing a 16-bit floating point value.
|
|
|
|
Type *getHalfTy() {
|
|
|
|
return Type::getHalfTy(Context);
|
|
|
|
}
|
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief 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
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief 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
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief 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
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Fetch the type representing a pointer to an 8-bit integer value.
|
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
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Fetch the type representing a pointer to an integer value.
|
2015-03-10 02:37:25 +00:00
|
|
|
IntegerType *getIntPtrTy(const DataLayout &DL, unsigned AddrSpace = 0) {
|
|
|
|
return DL.getIntPtrType(Context, AddrSpace);
|
2012-10-31 09:50:01 +00:00
|
|
|
}
|
|
|
|
|
2011-05-21 23:14:36 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Intrinsic creation methods
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Create and insert a memset to the specified pointer and the
|
|
|
|
/// specified value.
|
|
|
|
///
|
Add scoped-noalias metadata
This commit adds scoped noalias metadata. The primary motivations for this
feature are:
1. To preserve noalias function attribute information when inlining
2. To provide the ability to model block-scope C99 restrict pointers
Neither of these two abilities are added here, only the necessary
infrastructure. In fact, there should be no change to existing functionality,
only the addition of new features. The logic that converts noalias function
parameters into this metadata during inlining will come in a follow-up commit.
What is added here is the ability to generally specify noalias memory-access
sets. Regarding the metadata, alias-analysis scopes are defined similar to TBAA
nodes:
!scope0 = metadata !{ metadata !"scope of foo()" }
!scope1 = metadata !{ metadata !"scope 1", metadata !scope0 }
!scope2 = metadata !{ metadata !"scope 2", metadata !scope0 }
!scope3 = metadata !{ metadata !"scope 2.1", metadata !scope2 }
!scope4 = metadata !{ metadata !"scope 2.2", metadata !scope2 }
Loads and stores can be tagged with an alias-analysis scope, and also, with a
noalias tag for a specific scope:
... = load %ptr1, !alias.scope !{ !scope1 }
... = load %ptr2, !alias.scope !{ !scope1, !scope2 }, !noalias !{ !scope1 }
When evaluating an aliasing query, if one of the instructions is associated
with an alias.scope id that is identical to the noalias scope associated with
the other instruction, or is a descendant (in the scope hierarchy) of the
noalias scope associated with the other instruction, then the two memory
accesses are assumed not to alias.
Note that is the first element of the scope metadata is a string, then it can
be combined accross functions and translation units. The string can be replaced
by a self-reference to create globally unqiue scope identifiers.
[Note: This overview is slightly stylized, since the metadata nodes really need
to just be numbers (!0 instead of !scope0), and the scope lists are also global
unnamed metadata.]
Existing noalias metadata in a callee is "cloned" for use by the inlined code.
This is necessary because the aliasing scopes are unique to each call site
(because of possible control dependencies on the aliasing properties). For
example, consider a function: foo(noalias a, noalias b) { *a = *b; } that gets
inlined into bar() { ... if (...) foo(a1, b1); ... if (...) foo(a2, b2); } --
now just because we know that a1 does not alias with b1 at the first call site,
and a2 does not alias with b2 at the second call site, we cannot let inlining
these functons have the metadata imply that a1 does not alias with b2.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213864 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-24 14:25:39 +00:00
|
|
|
/// If the pointer isn't an i8*, it will be converted. If a TBAA tag is
|
|
|
|
/// specified, it will be added to the instruction. Likewise with alias.scope
|
|
|
|
/// and noalias tags.
|
2010-12-26 22:49:25 +00:00
|
|
|
CallInst *CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, unsigned Align,
|
Add scoped-noalias metadata
This commit adds scoped noalias metadata. The primary motivations for this
feature are:
1. To preserve noalias function attribute information when inlining
2. To provide the ability to model block-scope C99 restrict pointers
Neither of these two abilities are added here, only the necessary
infrastructure. In fact, there should be no change to existing functionality,
only the addition of new features. The logic that converts noalias function
parameters into this metadata during inlining will come in a follow-up commit.
What is added here is the ability to generally specify noalias memory-access
sets. Regarding the metadata, alias-analysis scopes are defined similar to TBAA
nodes:
!scope0 = metadata !{ metadata !"scope of foo()" }
!scope1 = metadata !{ metadata !"scope 1", metadata !scope0 }
!scope2 = metadata !{ metadata !"scope 2", metadata !scope0 }
!scope3 = metadata !{ metadata !"scope 2.1", metadata !scope2 }
!scope4 = metadata !{ metadata !"scope 2.2", metadata !scope2 }
Loads and stores can be tagged with an alias-analysis scope, and also, with a
noalias tag for a specific scope:
... = load %ptr1, !alias.scope !{ !scope1 }
... = load %ptr2, !alias.scope !{ !scope1, !scope2 }, !noalias !{ !scope1 }
When evaluating an aliasing query, if one of the instructions is associated
with an alias.scope id that is identical to the noalias scope associated with
the other instruction, or is a descendant (in the scope hierarchy) of the
noalias scope associated with the other instruction, then the two memory
accesses are assumed not to alias.
Note that is the first element of the scope metadata is a string, then it can
be combined accross functions and translation units. The string can be replaced
by a self-reference to create globally unqiue scope identifiers.
[Note: This overview is slightly stylized, since the metadata nodes really need
to just be numbers (!0 instead of !scope0), and the scope lists are also global
unnamed metadata.]
Existing noalias metadata in a callee is "cloned" for use by the inlined code.
This is necessary because the aliasing scopes are unique to each call site
(because of possible control dependencies on the aliasing properties). For
example, consider a function: foo(noalias a, noalias b) { *a = *b; } that gets
inlined into bar() { ... if (...) foo(a1, b1); ... if (...) foo(a2, b2); } --
now just because we know that a1 does not alias with b1 at the first call site,
and a2 does not alias with b2 at the second call site, we cannot let inlining
these functons have the metadata imply that a1 does not alias with b2.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213864 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-24 14:25:39 +00:00
|
|
|
bool isVolatile = false, MDNode *TBAATag = nullptr,
|
|
|
|
MDNode *ScopeTag = nullptr,
|
|
|
|
MDNode *NoAliasTag = nullptr) {
|
|
|
|
return CreateMemSet(Ptr, Val, getInt64(Size), Align, isVolatile,
|
|
|
|
TBAATag, ScopeTag, NoAliasTag);
|
2010-12-26 22:49:25 +00:00
|
|
|
}
|
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,
|
Add scoped-noalias metadata
This commit adds scoped noalias metadata. The primary motivations for this
feature are:
1. To preserve noalias function attribute information when inlining
2. To provide the ability to model block-scope C99 restrict pointers
Neither of these two abilities are added here, only the necessary
infrastructure. In fact, there should be no change to existing functionality,
only the addition of new features. The logic that converts noalias function
parameters into this metadata during inlining will come in a follow-up commit.
What is added here is the ability to generally specify noalias memory-access
sets. Regarding the metadata, alias-analysis scopes are defined similar to TBAA
nodes:
!scope0 = metadata !{ metadata !"scope of foo()" }
!scope1 = metadata !{ metadata !"scope 1", metadata !scope0 }
!scope2 = metadata !{ metadata !"scope 2", metadata !scope0 }
!scope3 = metadata !{ metadata !"scope 2.1", metadata !scope2 }
!scope4 = metadata !{ metadata !"scope 2.2", metadata !scope2 }
Loads and stores can be tagged with an alias-analysis scope, and also, with a
noalias tag for a specific scope:
... = load %ptr1, !alias.scope !{ !scope1 }
... = load %ptr2, !alias.scope !{ !scope1, !scope2 }, !noalias !{ !scope1 }
When evaluating an aliasing query, if one of the instructions is associated
with an alias.scope id that is identical to the noalias scope associated with
the other instruction, or is a descendant (in the scope hierarchy) of the
noalias scope associated with the other instruction, then the two memory
accesses are assumed not to alias.
Note that is the first element of the scope metadata is a string, then it can
be combined accross functions and translation units. The string can be replaced
by a self-reference to create globally unqiue scope identifiers.
[Note: This overview is slightly stylized, since the metadata nodes really need
to just be numbers (!0 instead of !scope0), and the scope lists are also global
unnamed metadata.]
Existing noalias metadata in a callee is "cloned" for use by the inlined code.
This is necessary because the aliasing scopes are unique to each call site
(because of possible control dependencies on the aliasing properties). For
example, consider a function: foo(noalias a, noalias b) { *a = *b; } that gets
inlined into bar() { ... if (...) foo(a1, b1); ... if (...) foo(a2, b2); } --
now just because we know that a1 does not alias with b1 at the first call site,
and a2 does not alias with b2 at the second call site, we cannot let inlining
these functons have the metadata imply that a1 does not alias with b2.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213864 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-24 14:25:39 +00:00
|
|
|
bool isVolatile = false, MDNode *TBAATag = nullptr,
|
|
|
|
MDNode *ScopeTag = nullptr,
|
|
|
|
MDNode *NoAliasTag = nullptr);
|
2010-12-26 22:49:25 +00:00
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Create and insert a memcpy between the specified pointers.
|
|
|
|
///
|
2010-12-26 22:49:25 +00:00
|
|
|
/// If the pointers aren't i8*, they will be converted. If a TBAA tag is
|
Add scoped-noalias metadata
This commit adds scoped noalias metadata. The primary motivations for this
feature are:
1. To preserve noalias function attribute information when inlining
2. To provide the ability to model block-scope C99 restrict pointers
Neither of these two abilities are added here, only the necessary
infrastructure. In fact, there should be no change to existing functionality,
only the addition of new features. The logic that converts noalias function
parameters into this metadata during inlining will come in a follow-up commit.
What is added here is the ability to generally specify noalias memory-access
sets. Regarding the metadata, alias-analysis scopes are defined similar to TBAA
nodes:
!scope0 = metadata !{ metadata !"scope of foo()" }
!scope1 = metadata !{ metadata !"scope 1", metadata !scope0 }
!scope2 = metadata !{ metadata !"scope 2", metadata !scope0 }
!scope3 = metadata !{ metadata !"scope 2.1", metadata !scope2 }
!scope4 = metadata !{ metadata !"scope 2.2", metadata !scope2 }
Loads and stores can be tagged with an alias-analysis scope, and also, with a
noalias tag for a specific scope:
... = load %ptr1, !alias.scope !{ !scope1 }
... = load %ptr2, !alias.scope !{ !scope1, !scope2 }, !noalias !{ !scope1 }
When evaluating an aliasing query, if one of the instructions is associated
with an alias.scope id that is identical to the noalias scope associated with
the other instruction, or is a descendant (in the scope hierarchy) of the
noalias scope associated with the other instruction, then the two memory
accesses are assumed not to alias.
Note that is the first element of the scope metadata is a string, then it can
be combined accross functions and translation units. The string can be replaced
by a self-reference to create globally unqiue scope identifiers.
[Note: This overview is slightly stylized, since the metadata nodes really need
to just be numbers (!0 instead of !scope0), and the scope lists are also global
unnamed metadata.]
Existing noalias metadata in a callee is "cloned" for use by the inlined code.
This is necessary because the aliasing scopes are unique to each call site
(because of possible control dependencies on the aliasing properties). For
example, consider a function: foo(noalias a, noalias b) { *a = *b; } that gets
inlined into bar() { ... if (...) foo(a1, b1); ... if (...) foo(a2, b2); } --
now just because we know that a1 does not alias with b1 at the first call site,
and a2 does not alias with b2 at the second call site, we cannot let inlining
these functons have the metadata imply that a1 does not alias with b2.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213864 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-24 14:25:39 +00:00
|
|
|
/// specified, it will be added to the instruction. Likewise with alias.scope
|
|
|
|
/// and noalias tags.
|
2010-12-26 22:49:25 +00:00
|
|
|
CallInst *CreateMemCpy(Value *Dst, Value *Src, uint64_t Size, unsigned Align,
|
2014-04-09 06:08:46 +00:00
|
|
|
bool isVolatile = false, MDNode *TBAATag = nullptr,
|
Add scoped-noalias metadata
This commit adds scoped noalias metadata. The primary motivations for this
feature are:
1. To preserve noalias function attribute information when inlining
2. To provide the ability to model block-scope C99 restrict pointers
Neither of these two abilities are added here, only the necessary
infrastructure. In fact, there should be no change to existing functionality,
only the addition of new features. The logic that converts noalias function
parameters into this metadata during inlining will come in a follow-up commit.
What is added here is the ability to generally specify noalias memory-access
sets. Regarding the metadata, alias-analysis scopes are defined similar to TBAA
nodes:
!scope0 = metadata !{ metadata !"scope of foo()" }
!scope1 = metadata !{ metadata !"scope 1", metadata !scope0 }
!scope2 = metadata !{ metadata !"scope 2", metadata !scope0 }
!scope3 = metadata !{ metadata !"scope 2.1", metadata !scope2 }
!scope4 = metadata !{ metadata !"scope 2.2", metadata !scope2 }
Loads and stores can be tagged with an alias-analysis scope, and also, with a
noalias tag for a specific scope:
... = load %ptr1, !alias.scope !{ !scope1 }
... = load %ptr2, !alias.scope !{ !scope1, !scope2 }, !noalias !{ !scope1 }
When evaluating an aliasing query, if one of the instructions is associated
with an alias.scope id that is identical to the noalias scope associated with
the other instruction, or is a descendant (in the scope hierarchy) of the
noalias scope associated with the other instruction, then the two memory
accesses are assumed not to alias.
Note that is the first element of the scope metadata is a string, then it can
be combined accross functions and translation units. The string can be replaced
by a self-reference to create globally unqiue scope identifiers.
[Note: This overview is slightly stylized, since the metadata nodes really need
to just be numbers (!0 instead of !scope0), and the scope lists are also global
unnamed metadata.]
Existing noalias metadata in a callee is "cloned" for use by the inlined code.
This is necessary because the aliasing scopes are unique to each call site
(because of possible control dependencies on the aliasing properties). For
example, consider a function: foo(noalias a, noalias b) { *a = *b; } that gets
inlined into bar() { ... if (...) foo(a1, b1); ... if (...) foo(a2, b2); } --
now just because we know that a1 does not alias with b1 at the first call site,
and a2 does not alias with b2 at the second call site, we cannot let inlining
these functons have the metadata imply that a1 does not alias with b2.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213864 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-24 14:25:39 +00:00
|
|
|
MDNode *TBAAStructTag = nullptr,
|
|
|
|
MDNode *ScopeTag = nullptr,
|
|
|
|
MDNode *NoAliasTag = nullptr) {
|
2012-09-26 22:17:14 +00:00
|
|
|
return CreateMemCpy(Dst, Src, getInt64(Size), Align, isVolatile, TBAATag,
|
Add scoped-noalias metadata
This commit adds scoped noalias metadata. The primary motivations for this
feature are:
1. To preserve noalias function attribute information when inlining
2. To provide the ability to model block-scope C99 restrict pointers
Neither of these two abilities are added here, only the necessary
infrastructure. In fact, there should be no change to existing functionality,
only the addition of new features. The logic that converts noalias function
parameters into this metadata during inlining will come in a follow-up commit.
What is added here is the ability to generally specify noalias memory-access
sets. Regarding the metadata, alias-analysis scopes are defined similar to TBAA
nodes:
!scope0 = metadata !{ metadata !"scope of foo()" }
!scope1 = metadata !{ metadata !"scope 1", metadata !scope0 }
!scope2 = metadata !{ metadata !"scope 2", metadata !scope0 }
!scope3 = metadata !{ metadata !"scope 2.1", metadata !scope2 }
!scope4 = metadata !{ metadata !"scope 2.2", metadata !scope2 }
Loads and stores can be tagged with an alias-analysis scope, and also, with a
noalias tag for a specific scope:
... = load %ptr1, !alias.scope !{ !scope1 }
... = load %ptr2, !alias.scope !{ !scope1, !scope2 }, !noalias !{ !scope1 }
When evaluating an aliasing query, if one of the instructions is associated
with an alias.scope id that is identical to the noalias scope associated with
the other instruction, or is a descendant (in the scope hierarchy) of the
noalias scope associated with the other instruction, then the two memory
accesses are assumed not to alias.
Note that is the first element of the scope metadata is a string, then it can
be combined accross functions and translation units. The string can be replaced
by a self-reference to create globally unqiue scope identifiers.
[Note: This overview is slightly stylized, since the metadata nodes really need
to just be numbers (!0 instead of !scope0), and the scope lists are also global
unnamed metadata.]
Existing noalias metadata in a callee is "cloned" for use by the inlined code.
This is necessary because the aliasing scopes are unique to each call site
(because of possible control dependencies on the aliasing properties). For
example, consider a function: foo(noalias a, noalias b) { *a = *b; } that gets
inlined into bar() { ... if (...) foo(a1, b1); ... if (...) foo(a2, b2); } --
now just because we know that a1 does not alias with b1 at the first call site,
and a2 does not alias with b2 at the second call site, we cannot let inlining
these functons have the metadata imply that a1 does not alias with b2.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213864 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-24 14:25:39 +00:00
|
|
|
TBAAStructTag, ScopeTag, NoAliasTag);
|
2010-12-26 22:49:25 +00:00
|
|
|
}
|
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,
|
2014-04-09 06:08:46 +00:00
|
|
|
bool isVolatile = false, MDNode *TBAATag = nullptr,
|
Add scoped-noalias metadata
This commit adds scoped noalias metadata. The primary motivations for this
feature are:
1. To preserve noalias function attribute information when inlining
2. To provide the ability to model block-scope C99 restrict pointers
Neither of these two abilities are added here, only the necessary
infrastructure. In fact, there should be no change to existing functionality,
only the addition of new features. The logic that converts noalias function
parameters into this metadata during inlining will come in a follow-up commit.
What is added here is the ability to generally specify noalias memory-access
sets. Regarding the metadata, alias-analysis scopes are defined similar to TBAA
nodes:
!scope0 = metadata !{ metadata !"scope of foo()" }
!scope1 = metadata !{ metadata !"scope 1", metadata !scope0 }
!scope2 = metadata !{ metadata !"scope 2", metadata !scope0 }
!scope3 = metadata !{ metadata !"scope 2.1", metadata !scope2 }
!scope4 = metadata !{ metadata !"scope 2.2", metadata !scope2 }
Loads and stores can be tagged with an alias-analysis scope, and also, with a
noalias tag for a specific scope:
... = load %ptr1, !alias.scope !{ !scope1 }
... = load %ptr2, !alias.scope !{ !scope1, !scope2 }, !noalias !{ !scope1 }
When evaluating an aliasing query, if one of the instructions is associated
with an alias.scope id that is identical to the noalias scope associated with
the other instruction, or is a descendant (in the scope hierarchy) of the
noalias scope associated with the other instruction, then the two memory
accesses are assumed not to alias.
Note that is the first element of the scope metadata is a string, then it can
be combined accross functions and translation units. The string can be replaced
by a self-reference to create globally unqiue scope identifiers.
[Note: This overview is slightly stylized, since the metadata nodes really need
to just be numbers (!0 instead of !scope0), and the scope lists are also global
unnamed metadata.]
Existing noalias metadata in a callee is "cloned" for use by the inlined code.
This is necessary because the aliasing scopes are unique to each call site
(because of possible control dependencies on the aliasing properties). For
example, consider a function: foo(noalias a, noalias b) { *a = *b; } that gets
inlined into bar() { ... if (...) foo(a1, b1); ... if (...) foo(a2, b2); } --
now just because we know that a1 does not alias with b1 at the first call site,
and a2 does not alias with b2 at the second call site, we cannot let inlining
these functons have the metadata imply that a1 does not alias with b2.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213864 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-24 14:25:39 +00:00
|
|
|
MDNode *TBAAStructTag = nullptr,
|
|
|
|
MDNode *ScopeTag = nullptr,
|
|
|
|
MDNode *NoAliasTag = nullptr);
|
2010-12-26 22:49:25 +00:00
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Create and insert a memmove between the specified
|
|
|
|
/// pointers.
|
|
|
|
///
|
|
|
|
/// If the pointers aren't i8*, they will be converted. If a TBAA tag is
|
Add scoped-noalias metadata
This commit adds scoped noalias metadata. The primary motivations for this
feature are:
1. To preserve noalias function attribute information when inlining
2. To provide the ability to model block-scope C99 restrict pointers
Neither of these two abilities are added here, only the necessary
infrastructure. In fact, there should be no change to existing functionality,
only the addition of new features. The logic that converts noalias function
parameters into this metadata during inlining will come in a follow-up commit.
What is added here is the ability to generally specify noalias memory-access
sets. Regarding the metadata, alias-analysis scopes are defined similar to TBAA
nodes:
!scope0 = metadata !{ metadata !"scope of foo()" }
!scope1 = metadata !{ metadata !"scope 1", metadata !scope0 }
!scope2 = metadata !{ metadata !"scope 2", metadata !scope0 }
!scope3 = metadata !{ metadata !"scope 2.1", metadata !scope2 }
!scope4 = metadata !{ metadata !"scope 2.2", metadata !scope2 }
Loads and stores can be tagged with an alias-analysis scope, and also, with a
noalias tag for a specific scope:
... = load %ptr1, !alias.scope !{ !scope1 }
... = load %ptr2, !alias.scope !{ !scope1, !scope2 }, !noalias !{ !scope1 }
When evaluating an aliasing query, if one of the instructions is associated
with an alias.scope id that is identical to the noalias scope associated with
the other instruction, or is a descendant (in the scope hierarchy) of the
noalias scope associated with the other instruction, then the two memory
accesses are assumed not to alias.
Note that is the first element of the scope metadata is a string, then it can
be combined accross functions and translation units. The string can be replaced
by a self-reference to create globally unqiue scope identifiers.
[Note: This overview is slightly stylized, since the metadata nodes really need
to just be numbers (!0 instead of !scope0), and the scope lists are also global
unnamed metadata.]
Existing noalias metadata in a callee is "cloned" for use by the inlined code.
This is necessary because the aliasing scopes are unique to each call site
(because of possible control dependencies on the aliasing properties). For
example, consider a function: foo(noalias a, noalias b) { *a = *b; } that gets
inlined into bar() { ... if (...) foo(a1, b1); ... if (...) foo(a2, b2); } --
now just because we know that a1 does not alias with b1 at the first call site,
and a2 does not alias with b2 at the second call site, we cannot let inlining
these functons have the metadata imply that a1 does not alias with b2.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213864 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-24 14:25:39 +00:00
|
|
|
/// specified, it will be added to the instruction. Likewise with alias.scope
|
|
|
|
/// and noalias tags.
|
2010-12-26 22:49:25 +00:00
|
|
|
CallInst *CreateMemMove(Value *Dst, Value *Src, uint64_t Size, unsigned Align,
|
Add scoped-noalias metadata
This commit adds scoped noalias metadata. The primary motivations for this
feature are:
1. To preserve noalias function attribute information when inlining
2. To provide the ability to model block-scope C99 restrict pointers
Neither of these two abilities are added here, only the necessary
infrastructure. In fact, there should be no change to existing functionality,
only the addition of new features. The logic that converts noalias function
parameters into this metadata during inlining will come in a follow-up commit.
What is added here is the ability to generally specify noalias memory-access
sets. Regarding the metadata, alias-analysis scopes are defined similar to TBAA
nodes:
!scope0 = metadata !{ metadata !"scope of foo()" }
!scope1 = metadata !{ metadata !"scope 1", metadata !scope0 }
!scope2 = metadata !{ metadata !"scope 2", metadata !scope0 }
!scope3 = metadata !{ metadata !"scope 2.1", metadata !scope2 }
!scope4 = metadata !{ metadata !"scope 2.2", metadata !scope2 }
Loads and stores can be tagged with an alias-analysis scope, and also, with a
noalias tag for a specific scope:
... = load %ptr1, !alias.scope !{ !scope1 }
... = load %ptr2, !alias.scope !{ !scope1, !scope2 }, !noalias !{ !scope1 }
When evaluating an aliasing query, if one of the instructions is associated
with an alias.scope id that is identical to the noalias scope associated with
the other instruction, or is a descendant (in the scope hierarchy) of the
noalias scope associated with the other instruction, then the two memory
accesses are assumed not to alias.
Note that is the first element of the scope metadata is a string, then it can
be combined accross functions and translation units. The string can be replaced
by a self-reference to create globally unqiue scope identifiers.
[Note: This overview is slightly stylized, since the metadata nodes really need
to just be numbers (!0 instead of !scope0), and the scope lists are also global
unnamed metadata.]
Existing noalias metadata in a callee is "cloned" for use by the inlined code.
This is necessary because the aliasing scopes are unique to each call site
(because of possible control dependencies on the aliasing properties). For
example, consider a function: foo(noalias a, noalias b) { *a = *b; } that gets
inlined into bar() { ... if (...) foo(a1, b1); ... if (...) foo(a2, b2); } --
now just because we know that a1 does not alias with b1 at the first call site,
and a2 does not alias with b2 at the second call site, we cannot let inlining
these functons have the metadata imply that a1 does not alias with b2.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213864 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-24 14:25:39 +00:00
|
|
|
bool isVolatile = false, MDNode *TBAATag = nullptr,
|
|
|
|
MDNode *ScopeTag = nullptr,
|
|
|
|
MDNode *NoAliasTag = nullptr) {
|
|
|
|
return CreateMemMove(Dst, Src, getInt64(Size), Align, isVolatile,
|
|
|
|
TBAATag, ScopeTag, NoAliasTag);
|
2010-12-26 22:49:25 +00:00
|
|
|
}
|
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,
|
Add scoped-noalias metadata
This commit adds scoped noalias metadata. The primary motivations for this
feature are:
1. To preserve noalias function attribute information when inlining
2. To provide the ability to model block-scope C99 restrict pointers
Neither of these two abilities are added here, only the necessary
infrastructure. In fact, there should be no change to existing functionality,
only the addition of new features. The logic that converts noalias function
parameters into this metadata during inlining will come in a follow-up commit.
What is added here is the ability to generally specify noalias memory-access
sets. Regarding the metadata, alias-analysis scopes are defined similar to TBAA
nodes:
!scope0 = metadata !{ metadata !"scope of foo()" }
!scope1 = metadata !{ metadata !"scope 1", metadata !scope0 }
!scope2 = metadata !{ metadata !"scope 2", metadata !scope0 }
!scope3 = metadata !{ metadata !"scope 2.1", metadata !scope2 }
!scope4 = metadata !{ metadata !"scope 2.2", metadata !scope2 }
Loads and stores can be tagged with an alias-analysis scope, and also, with a
noalias tag for a specific scope:
... = load %ptr1, !alias.scope !{ !scope1 }
... = load %ptr2, !alias.scope !{ !scope1, !scope2 }, !noalias !{ !scope1 }
When evaluating an aliasing query, if one of the instructions is associated
with an alias.scope id that is identical to the noalias scope associated with
the other instruction, or is a descendant (in the scope hierarchy) of the
noalias scope associated with the other instruction, then the two memory
accesses are assumed not to alias.
Note that is the first element of the scope metadata is a string, then it can
be combined accross functions and translation units. The string can be replaced
by a self-reference to create globally unqiue scope identifiers.
[Note: This overview is slightly stylized, since the metadata nodes really need
to just be numbers (!0 instead of !scope0), and the scope lists are also global
unnamed metadata.]
Existing noalias metadata in a callee is "cloned" for use by the inlined code.
This is necessary because the aliasing scopes are unique to each call site
(because of possible control dependencies on the aliasing properties). For
example, consider a function: foo(noalias a, noalias b) { *a = *b; } that gets
inlined into bar() { ... if (...) foo(a1, b1); ... if (...) foo(a2, b2); } --
now just because we know that a1 does not alias with b1 at the first call site,
and a2 does not alias with b2 at the second call site, we cannot let inlining
these functons have the metadata imply that a1 does not alias with b2.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213864 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-24 14:25:39 +00:00
|
|
|
bool isVolatile = false, MDNode *TBAATag = nullptr,
|
|
|
|
MDNode *ScopeTag = nullptr,
|
|
|
|
MDNode *NoAliasTag = nullptr);
|
2011-05-21 23:14:36 +00:00
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Create a lifetime.start intrinsic.
|
|
|
|
///
|
|
|
|
/// If the pointer isn't i8* it will be converted.
|
2014-04-09 06:08:46 +00:00
|
|
|
CallInst *CreateLifetimeStart(Value *Ptr, ConstantInt *Size = nullptr);
|
2011-05-21 23:14:36 +00:00
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Create a lifetime.end intrinsic.
|
|
|
|
///
|
|
|
|
/// If the pointer isn't i8* it will be converted.
|
2014-04-09 06:08:46 +00:00
|
|
|
CallInst *CreateLifetimeEnd(Value *Ptr, ConstantInt *Size = nullptr);
|
2011-05-21 23:14:36 +00:00
|
|
|
|
2014-12-04 09:40:44 +00:00
|
|
|
/// \brief Create a call to Masked Load intrinsic
|
2014-12-30 14:28:14 +00:00
|
|
|
CallInst *CreateMaskedLoad(Value *Ptr, unsigned Align, Value *Mask,
|
|
|
|
Value *PassThru = 0, const Twine &Name = "");
|
2014-12-04 09:40:44 +00:00
|
|
|
|
|
|
|
/// \brief Create a call to Masked Store intrinsic
|
2014-12-30 14:28:14 +00:00
|
|
|
CallInst *CreateMaskedStore(Value *Val, Value *Ptr, unsigned Align,
|
|
|
|
Value *Mask);
|
2014-12-04 09:40:44 +00:00
|
|
|
|
2014-10-15 23:44:22 +00:00
|
|
|
/// \brief Create an assume intrinsic call that allows the optimizer to
|
|
|
|
/// assume that the provided condition will be true.
|
|
|
|
CallInst *CreateAssumption(Value *Cond);
|
|
|
|
|
2014-12-30 05:55:58 +00:00
|
|
|
/// \brief Create a call to the experimental.gc.statepoint intrinsic to
|
|
|
|
/// start a new statepoint sequence.
|
|
|
|
CallInst *CreateGCStatepoint(Value *ActualCallee,
|
2015-02-09 23:02:10 +00:00
|
|
|
ArrayRef<Value *> CallArgs,
|
|
|
|
ArrayRef<Value *> DeoptArgs,
|
|
|
|
ArrayRef<Value *> GCArgs,
|
2014-12-30 05:55:58 +00:00
|
|
|
const Twine &Name = "");
|
|
|
|
|
2015-02-26 00:35:56 +00:00
|
|
|
// Conveninence function for the common case when CallArgs are filled in using
|
|
|
|
// makeArrayRef(CS.arg_begin(), .arg_end()); Use needs to be .get()'ed to get
|
|
|
|
// the Value *.
|
|
|
|
CallInst *CreateGCStatepoint(Value *ActualCallee, ArrayRef<Use> CallArgs,
|
|
|
|
ArrayRef<Value *> DeoptArgs,
|
|
|
|
ArrayRef<Value *> GCArgs,
|
|
|
|
const Twine &Name = "");
|
|
|
|
|
2014-12-30 05:55:58 +00:00
|
|
|
/// \brief Create a call to the experimental.gc.result intrinsic to extract
|
|
|
|
/// the result from a call wrapped in a statepoint.
|
|
|
|
CallInst *CreateGCResult(Instruction *Statepoint,
|
|
|
|
Type *ResultType,
|
|
|
|
const Twine &Name = "");
|
|
|
|
|
|
|
|
/// \brief Create a call to the experimental.gc.relocate intrinsics to
|
|
|
|
/// project the relocated value of one pointer from the statepoint.
|
|
|
|
CallInst *CreateGCRelocate(Instruction *Statepoint,
|
|
|
|
int BaseOffset,
|
|
|
|
int DerivedOffset,
|
|
|
|
Type *ResultType,
|
|
|
|
const Twine &Name = "");
|
|
|
|
|
2010-12-26 22:49:25 +00:00
|
|
|
private:
|
2014-12-04 09:40:44 +00:00
|
|
|
/// \brief Create a call to a masked intrinsic with given Id.
|
|
|
|
/// Masked intrinsic has only one overloaded type - data type.
|
|
|
|
CallInst *CreateMaskedIntrinsic(unsigned Id, ArrayRef<Value *> Ops,
|
2014-12-30 14:28:14 +00:00
|
|
|
Type *DataTy, const Twine &Name = "");
|
2014-12-04 09:40:44 +00:00
|
|
|
|
2010-12-26 22:49:25 +00:00
|
|
|
Value *getCastedInt8PtrValue(Value *Ptr);
|
2009-12-28 21:28:46 +00:00
|
|
|
};
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2013-01-30 22:56:31 +00:00
|
|
|
/// \brief 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.
|
2009-12-28 21:28:46 +00:00
|
|
|
///
|
|
|
|
/// Note that the builder does not expose the full generality of LLVM
|
|
|
|
/// instructions. For access to extra instruction properties, use the mutators
|
2012-11-28 21:16:19 +00:00
|
|
|
/// (e.g. setVolatile) on the instructions after they have been
|
|
|
|
/// created. Convenience state exists to specify fast-math flags and fp-math
|
|
|
|
/// tags.
|
|
|
|
///
|
2009-12-28 21:28:46 +00:00
|
|
|
/// 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
|
2014-08-29 21:53:01 +00:00
|
|
|
/// minimally folded constants. The third template argument allows clients to
|
2009-12-28 21:28:46 +00:00
|
|
|
/// 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:
|
2012-04-16 16:28:59 +00:00
|
|
|
IRBuilder(LLVMContext &C, const T &F, const Inserter &I = Inserter(),
|
2014-04-09 06:08:46 +00:00
|
|
|
MDNode *FPMathTag = nullptr)
|
2013-09-30 15:39:27 +00:00
|
|
|
: IRBuilderBase(C, FPMathTag), Inserter(I), Folder(F) {
|
2009-12-28 21:28:46 +00:00
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2014-04-09 06:08:46 +00:00
|
|
|
explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = nullptr)
|
2013-09-30 15:39:27 +00:00
|
|
|
: IRBuilderBase(C, FPMathTag), Folder() {
|
2009-12-28 21:28:46 +00:00
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2014-04-09 06:08:46 +00:00
|
|
|
explicit IRBuilder(BasicBlock *TheBB, const T &F, MDNode *FPMathTag = nullptr)
|
2013-09-30 15:39:27 +00:00
|
|
|
: IRBuilderBase(TheBB->getContext(), FPMathTag), Folder(F) {
|
2009-12-28 21:28:46 +00:00
|
|
|
SetInsertPoint(TheBB);
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2014-04-09 06:08:46 +00:00
|
|
|
explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr)
|
2013-09-30 15:39:27 +00:00
|
|
|
: IRBuilderBase(TheBB->getContext(), FPMathTag), Folder() {
|
2009-12-28 21:28:46 +00:00
|
|
|
SetInsertPoint(TheBB);
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2014-04-09 06:08:46 +00:00
|
|
|
explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr)
|
2013-09-30 15:39:27 +00:00
|
|
|
: IRBuilderBase(IP->getContext(), FPMathTag), 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
|
|
|
|
2014-04-09 06:08:46 +00:00
|
|
|
explicit IRBuilder(Use &U, MDNode *FPMathTag = nullptr)
|
2013-09-30 15:39:27 +00:00
|
|
|
: IRBuilderBase(U->getContext(), FPMathTag), Folder() {
|
2011-06-29 23:01:52 +00:00
|
|
|
SetInsertPoint(U);
|
|
|
|
SetCurrentDebugLocation(cast<Instruction>(U.getUser())->getDebugLoc());
|
|
|
|
}
|
|
|
|
|
2012-04-16 16:28:59 +00:00
|
|
|
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T& F,
|
2014-04-09 06:08:46 +00:00
|
|
|
MDNode *FPMathTag = nullptr)
|
2013-09-30 15:39:27 +00:00
|
|
|
: IRBuilderBase(TheBB->getContext(), FPMathTag), Folder(F) {
|
2009-12-28 21:28:46 +00:00
|
|
|
SetInsertPoint(TheBB, IP);
|
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2014-04-09 06:08:46 +00:00
|
|
|
IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP,
|
|
|
|
MDNode *FPMathTag = nullptr)
|
2013-09-30 15:39:27 +00:00
|
|
|
: IRBuilderBase(TheBB->getContext(), FPMathTag), Folder() {
|
2009-12-28 21:28:46 +00:00
|
|
|
SetInsertPoint(TheBB, IP);
|
|
|
|
}
|
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Get the constant folder being used.
|
2009-12-28 21:28:46 +00:00
|
|
|
const T &getFolder() { return Folder; }
|
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Return true if this builder is configured to actually add the
|
|
|
|
/// requested names to IR created through it.
|
2009-12-28 21:28:46 +00:00
|
|
|
bool isNamePreserving() const { return preserveNames; }
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Insert and return the specified instruction.
|
2009-12-28 21:28:46 +00:00
|
|
|
template<typename InstTy>
|
|
|
|
InstTy *Insert(InstTy *I, const Twine &Name = "") const {
|
|
|
|
this->InsertHelper(I, Name, BB, InsertPt);
|
2013-01-26 21:55:19 +00:00
|
|
|
this->SetInstDebugLocation(I);
|
2009-12-28 21:28:46 +00:00
|
|
|
return I;
|
|
|
|
}
|
2009-08-14 00:30:41 +00:00
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief No-op overload to handle constants.
|
2010-11-18 02:15:42 +00:00
|
|
|
Constant *Insert(Constant *C, const Twine& = "") const {
|
|
|
|
return C;
|
|
|
|
}
|
|
|
|
|
2007-05-27 15:09:34 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Instruction creation methods: Terminators
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
2012-07-16 07:45:06 +00:00
|
|
|
private:
|
|
|
|
/// \brief Helper to add branch weight metadata onto an instruction.
|
|
|
|
/// \returns The annotated instruction.
|
|
|
|
template <typename InstTy>
|
|
|
|
InstTy *addBranchWeights(InstTy *I, MDNode *Weights) {
|
|
|
|
if (Weights)
|
|
|
|
I->setMetadata(LLVMContext::MD_prof, Weights);
|
|
|
|
return I;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Create a 'ret void' instruction.
|
2007-05-27 15:09:34 +00:00
|
|
|
ReturnInst *CreateRetVoid() {
|
2009-08-14 06:12:30 +00:00
|
|
|
return Insert(ReturnInst::Create(Context));
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Create a 'ret <val>' instruction.
|
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
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Create a sequence of N insertvalue instructions,
|
2008-07-25 20:36:15 +00:00
|
|
|
/// 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
|
2013-01-20 05:03:37 +00:00
|
|
|
/// the resulting aggregate value.
|
2008-07-25 20:36:15 +00:00
|
|
|
///
|
2013-01-20 05:03:37 +00:00
|
|
|
/// 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
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Create an unconditional 'br label X' instruction.
|
2007-05-27 15:09:34 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Create a conditional 'br Cond, TrueDest, FalseDest'
|
2007-05-27 15:09:34 +00:00
|
|
|
/// instruction.
|
2012-07-16 07:45:06 +00:00
|
|
|
BranchInst *CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False,
|
2014-04-09 06:08:46 +00:00
|
|
|
MDNode *BranchWeights = nullptr) {
|
2012-07-16 07:45:06 +00:00
|
|
|
return Insert(addBranchWeights(BranchInst::Create(True, False, Cond),
|
|
|
|
BranchWeights));
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2008-08-11 15:29:30 +00:00
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief 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).
|
2012-07-16 07:45:06 +00:00
|
|
|
SwitchInst *CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases = 10,
|
2014-04-09 06:08:46 +00:00
|
|
|
MDNode *BranchWeights = nullptr) {
|
2012-07-16 07:45:06 +00:00
|
|
|
return Insert(addBranchWeights(SwitchInst::Create(V, Dest, NumCases),
|
|
|
|
BranchWeights));
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
2008-08-11 15:29:30 +00:00
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief 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).
|
2009-10-28 23:25:00 +00:00
|
|
|
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 = "") {
|
2014-08-27 05:25:25 +00:00
|
|
|
return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, None),
|
2011-07-15 08:37:34 +00:00
|
|
|
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
|
|
|
}
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief 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;
|
|
|
|
}
|
2012-04-16 16:28:59 +00:00
|
|
|
|
2012-11-28 21:16:19 +00:00
|
|
|
Instruction *AddFPMathAttributes(Instruction *I,
|
|
|
|
MDNode *FPMathTag,
|
|
|
|
FastMathFlags FMF) const {
|
2012-04-16 16:28:59 +00:00
|
|
|
if (!FPMathTag)
|
|
|
|
FPMathTag = DefaultFPMathTag;
|
|
|
|
if (FPMathTag)
|
|
|
|
I->setMetadata(LLVMContext::MD_fpmath, FPMathTag);
|
2012-11-28 21:16:19 +00:00
|
|
|
I->setFastMathFlags(FMF);
|
2012-04-16 16:28:59 +00:00
|
|
|
return I;
|
|
|
|
}
|
2011-02-10 07:01:55 +00:00
|
|
|
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
|
|
|
}
|
2012-04-16 16:28:59 +00:00
|
|
|
Value *CreateFAdd(Value *LHS, Value *RHS, const Twine &Name = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
MDNode *FPMathTag = nullptr) {
|
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);
|
2012-11-28 21:16:19 +00:00
|
|
|
return Insert(AddFPMathAttributes(BinaryOperator::CreateFAdd(LHS, RHS),
|
|
|
|
FPMathTag, FMF), Name);
|
2009-06-04 22:49:04 +00:00
|
|
|
}
|
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))
|
2014-01-05 03:22:33 +00:00
|
|
|
return Insert(Folder.CreateSub(LC, RC, HasNUW, HasNSW), 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
|
|
|
}
|
2012-04-16 16:28:59 +00:00
|
|
|
Value *CreateFSub(Value *LHS, Value *RHS, const Twine &Name = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
MDNode *FPMathTag = nullptr) {
|
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);
|
2012-11-28 21:16:19 +00:00
|
|
|
return Insert(AddFPMathAttributes(BinaryOperator::CreateFSub(LHS, RHS),
|
|
|
|
FPMathTag, FMF), Name);
|
2009-06-04 22:49:04 +00:00
|
|
|
}
|
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))
|
2014-01-05 03:22:33 +00:00
|
|
|
return Insert(Folder.CreateMul(LC, RC, HasNUW, HasNSW), 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
|
|
|
}
|
2012-04-16 16:28:59 +00:00
|
|
|
Value *CreateFMul(Value *LHS, Value *RHS, const Twine &Name = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
MDNode *FPMathTag = nullptr) {
|
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);
|
2012-11-28 21:16:19 +00:00
|
|
|
return Insert(AddFPMathAttributes(BinaryOperator::CreateFMul(LHS, RHS),
|
|
|
|
FPMathTag, FMF), Name);
|
2009-06-04 22:49:04 +00:00
|
|
|
}
|
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
|
|
|
}
|
2012-04-16 16:28:59 +00:00
|
|
|
Value *CreateFDiv(Value *LHS, Value *RHS, const Twine &Name = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
MDNode *FPMathTag = nullptr) {
|
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);
|
2012-11-28 21:16:19 +00:00
|
|
|
return Insert(AddFPMathAttributes(BinaryOperator::CreateFDiv(LHS, RHS),
|
|
|
|
FPMathTag, FMF), 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
|
|
|
}
|
2012-04-16 16:28:59 +00:00
|
|
|
Value *CreateFRem(Value *LHS, Value *RHS, const Twine &Name = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
MDNode *FPMathTag = nullptr) {
|
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);
|
2012-11-28 21:16:19 +00:00
|
|
|
return Insert(AddFPMathAttributes(BinaryOperator::CreateFRem(LHS, RHS),
|
|
|
|
FPMathTag, FMF), 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,
|
2013-12-05 00:32:09 +00:00
|
|
|
Value *LHS, Value *RHS, const Twine &Name = "",
|
2014-04-09 06:08:46 +00:00
|
|
|
MDNode *FPMathTag = nullptr) {
|
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);
|
2013-12-05 00:32:09 +00:00
|
|
|
llvm::Instruction *BinOp = BinaryOperator::Create(Opc, LHS, RHS);
|
|
|
|
if (isa<FPMathOperator>(BinOp))
|
|
|
|
BinOp = AddFPMathAttributes(BinOp, FPMathTag, FMF);
|
|
|
|
return Insert(BinOp, 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
|
|
|
}
|
2014-04-09 06:08:46 +00:00
|
|
|
Value *CreateFNeg(Value *V, const Twine &Name = "",
|
|
|
|
MDNode *FPMathTag = nullptr) {
|
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);
|
2012-11-28 21:16:19 +00:00
|
|
|
return Insert(AddFPMathAttributes(BinaryOperator::CreateFNeg(V),
|
|
|
|
FPMathTag, FMF), 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
|
|
|
|
2014-04-09 06:08:46 +00:00
|
|
|
AllocaInst *CreateAlloca(Type *Ty, Value *ArraySize = nullptr,
|
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
|
|
|
}
|
2013-01-20 05:03:37 +00:00
|
|
|
// \brief Provided to resolve 'CreateLoad(Ptr, "...")' correctly, instead of
|
2009-08-19 22:34:21 +00:00
|
|
|
// 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 = "") {
|
2014-04-09 06:08:46 +00:00
|
|
|
return Insert(new LoadInst(Ptr, nullptr, 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));
|
|
|
|
}
|
2013-01-20 05:03:37 +00:00
|
|
|
// \brief Provided to resolve 'CreateAlignedLoad(Ptr, Align, "...")'
|
|
|
|
// correctly, instead of converting the string to 'bool' for the isVolatile
|
|
|
|
// parameter.
|
2012-09-26 10:27:40 +00:00
|
|
|
LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align, const char *Name) {
|
|
|
|
LoadInst *LI = CreateLoad(Ptr, Name);
|
|
|
|
LI->setAlignment(Align);
|
|
|
|
return LI;
|
|
|
|
}
|
|
|
|
LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align,
|
|
|
|
const Twine &Name = "") {
|
|
|
|
LoadInst *LI = CreateLoad(Ptr, Name);
|
|
|
|
LI->setAlignment(Align);
|
|
|
|
return LI;
|
|
|
|
}
|
|
|
|
LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align, bool isVolatile,
|
|
|
|
const Twine &Name = "") {
|
|
|
|
LoadInst *LI = CreateLoad(Ptr, isVolatile, Name);
|
|
|
|
LI->setAlignment(Align);
|
|
|
|
return LI;
|
|
|
|
}
|
|
|
|
StoreInst *CreateAlignedStore(Value *Val, Value *Ptr, unsigned Align,
|
|
|
|
bool isVolatile = false) {
|
|
|
|
StoreInst *SI = CreateStore(Val, Ptr, isVolatile);
|
|
|
|
SI->setAlignment(Align);
|
|
|
|
return SI;
|
|
|
|
}
|
2011-07-25 23:16:38 +00:00
|
|
|
FenceInst *CreateFence(AtomicOrdering Ordering,
|
2013-11-20 00:07:49 +00:00
|
|
|
SynchronizationScope SynchScope = CrossThread,
|
|
|
|
const Twine &Name = "") {
|
|
|
|
return Insert(new FenceInst(Context, Ordering, SynchScope), Name);
|
2011-07-25 23:16:38 +00:00
|
|
|
}
|
2014-03-11 10:48:52 +00:00
|
|
|
AtomicCmpXchgInst *
|
|
|
|
CreateAtomicCmpXchg(Value *Ptr, Value *Cmp, Value *New,
|
|
|
|
AtomicOrdering SuccessOrdering,
|
|
|
|
AtomicOrdering FailureOrdering,
|
|
|
|
SynchronizationScope SynchScope = CrossThread) {
|
|
|
|
return Insert(new AtomicCmpXchgInst(Ptr, Cmp, New, SuccessOrdering,
|
|
|
|
FailureOrdering, SynchScope));
|
2011-07-29 03:05:32 +00:00
|
|
|
}
|
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 = "") {
|
2015-03-15 01:03:19 +00:00
|
|
|
return CreateGEP(nullptr, Ptr, IdxList, Name);
|
|
|
|
}
|
|
|
|
Value *CreateGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
|
|
|
|
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)
|
2015-04-03 01:15:16 +00:00
|
|
|
return Insert(Folder.CreateGetElementPtr(Ty, PC, IdxList), Name);
|
2008-08-11 15:29:30 +00:00
|
|
|
}
|
2015-03-15 01:03:19 +00:00
|
|
|
return Insert(GetElementPtrInst::Create(Ty, 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 = "") {
|
2015-04-03 21:33:42 +00:00
|
|
|
return CreateInBoundsGEP(nullptr, Ptr, IdxList, Name);
|
|
|
|
}
|
|
|
|
Value *CreateInBoundsGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
|
|
|
|
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)
|
2015-04-03 21:33:42 +00:00
|
|
|
return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, IdxList),
|
2015-04-03 01:15:16 +00:00
|
|
|
Name);
|
2009-08-11 17:57:01 +00:00
|
|
|
}
|
2015-04-03 21:33:42 +00:00
|
|
|
return Insert(GetElementPtrInst::CreateInBounds(Ty, 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 = "") {
|
2015-03-30 20:42:56 +00:00
|
|
|
return CreateGEP(nullptr, Ptr, Idx, Name);
|
|
|
|
}
|
|
|
|
Value *CreateGEP(Type *Ty, 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))
|
2015-04-03 01:15:16 +00:00
|
|
|
return Insert(Folder.CreateGetElementPtr(Ty, PC, IC), Name);
|
2015-03-30 20:42:56 +00:00
|
|
|
return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name);
|
2008-04-13 06:22:09 +00:00
|
|
|
}
|
2015-04-03 19:41:44 +00:00
|
|
|
Value *CreateInBoundsGEP(Type *Ty, 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))
|
2015-04-03 19:41:44 +00:00
|
|
|
return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, IC), Name);
|
|
|
|
return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name);
|
2009-08-11 17:57:01 +00:00
|
|
|
}
|
2009-08-19 22:34:21 +00:00
|
|
|
Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const Twine &Name = "") {
|
2015-04-03 23:03:54 +00:00
|
|
|
return CreateConstGEP1_32(nullptr, Ptr, Idx0, Name);
|
|
|
|
}
|
|
|
|
Value *CreateConstGEP1_32(Type *Ty, 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))
|
2015-04-03 23:03:54 +00:00
|
|
|
return Insert(Folder.CreateGetElementPtr(Ty, PC, Idx), Name);
|
2009-03-06 22:26:07 +00:00
|
|
|
|
2015-04-03 23:03:54 +00:00
|
|
|
return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name);
|
2009-03-06 22:26:07 +00:00
|
|
|
}
|
2015-04-04 15:12:13 +00:00
|
|
|
Value *CreateConstInBoundsGEP1_32(Type *Ty, 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))
|
2015-04-04 15:12:13 +00:00
|
|
|
return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, Idx), Name);
|
2009-08-11 17:57:01 +00:00
|
|
|
|
2015-04-04 15:12:13 +00:00
|
|
|
return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name);
|
2009-08-11 17:57:01 +00:00
|
|
|
}
|
2015-04-04 21:07:10 +00:00
|
|
|
Value *CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1,
|
|
|
|
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))
|
2015-04-04 21:07:10 +00:00
|
|
|
return Insert(Folder.CreateGetElementPtr(Ty, PC, Idxs), Name);
|
2009-03-06 22:26:07 +00:00
|
|
|
|
2015-04-04 21:07:10 +00:00
|
|
|
return Insert(GetElementPtrInst::Create(Ty, Ptr, Idxs), Name);
|
2009-03-06 22:26:07 +00:00
|
|
|
}
|
2015-04-05 22:44:57 +00:00
|
|
|
Value *CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0,
|
|
|
|
unsigned Idx1, 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))
|
2015-04-05 22:44:57 +00:00
|
|
|
return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, Idxs), Name);
|
2009-08-11 17:57:01 +00:00
|
|
|
|
2015-04-05 22:41:44 +00:00
|
|
|
return Insert(GetElementPtrInst::CreateInBounds(Ty, 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))
|
2015-04-03 01:15:16 +00:00
|
|
|
return Insert(Folder.CreateGetElementPtr(nullptr, PC, Idx), Name);
|
2009-03-06 22:26:07 +00:00
|
|
|
|
2015-03-14 19:24:04 +00:00
|
|
|
return Insert(GetElementPtrInst::Create(nullptr, 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))
|
2015-04-03 01:15:16 +00:00
|
|
|
return Insert(Folder.CreateInBoundsGetElementPtr(nullptr, PC, Idx), Name);
|
2009-08-11 17:57:01 +00:00
|
|
|
|
2015-03-14 19:24:04 +00:00
|
|
|
return Insert(GetElementPtrInst::CreateInBounds(nullptr, 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))
|
2015-04-03 01:15:16 +00:00
|
|
|
return Insert(Folder.CreateGetElementPtr(nullptr, PC, Idxs), Name);
|
2008-08-11 15:29:30 +00:00
|
|
|
|
2015-03-14 19:24:04 +00:00
|
|
|
return Insert(GetElementPtrInst::Create(nullptr, 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))
|
2015-04-03 01:15:16 +00:00
|
|
|
return Insert(Folder.CreateInBoundsGetElementPtr(nullptr, PC, Idxs),
|
|
|
|
Name);
|
2009-08-11 17:57:01 +00:00
|
|
|
|
2015-03-14 19:24:04 +00:00
|
|
|
return Insert(GetElementPtrInst::CreateInBounds(nullptr, Ptr, Idxs), Name);
|
2009-08-11 17:57:01 +00:00
|
|
|
}
|
2015-04-05 22:44:57 +00:00
|
|
|
Value *CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx,
|
|
|
|
const Twine &Name = "") {
|
2015-04-05 22:41:44 +00:00
|
|
|
return CreateConstInBoundsGEP2_32(Ty, Ptr, 0, Idx, Name);
|
2007-12-17 19:06:26 +00:00
|
|
|
}
|
2010-10-27 07:39:48 +00:00
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief 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 = "") {
|
2015-04-03 21:33:42 +00:00
|
|
|
GlobalVariable *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 };
|
2015-04-03 21:33:42 +00:00
|
|
|
return CreateInBoundsGEP(gv->getValueType(), 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);
|
|
|
|
}
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Create a ZExt or Trunc from the integer value V to DestTy. Return
|
|
|
|
/// the value untouched if the type of V is already DestTy.
|
2013-01-20 07:33:26 +00:00
|
|
|
Value *CreateZExtOrTrunc(Value *V, Type *DestTy,
|
2012-09-26 14:01:53 +00:00
|
|
|
const Twine &Name = "") {
|
2013-01-20 07:33:26 +00:00
|
|
|
assert(V->getType()->isIntOrIntVectorTy() &&
|
|
|
|
DestTy->isIntOrIntVectorTy() &&
|
2013-01-20 04:19:39 +00:00
|
|
|
"Can only zero extend/truncate integers!");
|
2013-01-20 07:33:26 +00:00
|
|
|
Type *VTy = V->getType();
|
|
|
|
if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
|
2012-09-26 14:01:53 +00:00
|
|
|
return CreateZExt(V, DestTy, Name);
|
2013-01-20 07:33:26 +00:00
|
|
|
if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
|
2012-09-26 14:01:53 +00:00
|
|
|
return CreateTrunc(V, DestTy, Name);
|
|
|
|
return V;
|
|
|
|
}
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Create a SExt or Trunc from the integer value V to DestTy. Return
|
|
|
|
/// the value untouched if the type of V is already DestTy.
|
2013-01-20 07:33:26 +00:00
|
|
|
Value *CreateSExtOrTrunc(Value *V, Type *DestTy,
|
2012-09-26 14:01:53 +00:00
|
|
|
const Twine &Name = "") {
|
2013-01-20 07:33:26 +00:00
|
|
|
assert(V->getType()->isIntOrIntVectorTy() &&
|
|
|
|
DestTy->isIntOrIntVectorTy() &&
|
2013-01-20 04:19:39 +00:00
|
|
|
"Can only sign extend/truncate integers!");
|
2013-01-20 07:33:26 +00:00
|
|
|
Type *VTy = V->getType();
|
|
|
|
if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
|
2012-09-26 14:01:53 +00:00
|
|
|
return CreateSExt(V, DestTy, Name);
|
2013-01-20 07:33:26 +00:00
|
|
|
if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
|
2012-09-26 14:01:53 +00:00
|
|
|
return CreateTrunc(V, DestTy, Name);
|
|
|
|
return V;
|
|
|
|
}
|
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);
|
|
|
|
}
|
2013-11-15 01:34:59 +00:00
|
|
|
Value *CreateAddrSpaceCast(Value *V, Type *DestTy,
|
|
|
|
const Twine &Name = "") {
|
|
|
|
return CreateCast(Instruction::AddrSpaceCast, 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);
|
|
|
|
}
|
2014-07-14 17:24:35 +00:00
|
|
|
|
|
|
|
Value *CreatePointerBitCastOrAddrSpaceCast(Value *V, Type *DestTy,
|
|
|
|
const Twine &Name = "") {
|
|
|
|
if (V->getType() == DestTy)
|
|
|
|
return V;
|
|
|
|
|
|
|
|
if (Constant *VC = dyn_cast<Constant>(V)) {
|
|
|
|
return Insert(Folder.CreatePointerBitCastOrAddrSpaceCast(VC, DestTy),
|
|
|
|
Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Insert(CastInst::CreatePointerBitCastOrAddrSpaceCast(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
|
|
|
}
|
2014-11-25 08:20:27 +00:00
|
|
|
|
|
|
|
Value *CreateBitOrPointerCast(Value *V, Type *DestTy,
|
|
|
|
const Twine &Name = "") {
|
|
|
|
if (V->getType() == DestTy)
|
|
|
|
return V;
|
|
|
|
if (V->getType()->isPointerTy() && DestTy->isIntegerTy())
|
|
|
|
return CreatePtrToInt(V, DestTy, Name);
|
|
|
|
if (V->getType()->isIntegerTy() && DestTy->isPointerTy())
|
|
|
|
return CreateIntToPtr(V, DestTy, Name);
|
|
|
|
|
|
|
|
return CreateBitCast(V, DestTy, Name);
|
|
|
|
}
|
2009-11-17 08:34:52 +00:00
|
|
|
private:
|
2013-01-20 05:03:37 +00:00
|
|
|
// \brief Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a
|
|
|
|
// compile time error, instead of converting the string to bool for the
|
|
|
|
// isSigned parameter.
|
2015-02-15 22:54:22 +00:00
|
|
|
Value *CreateIntCast(Value *, Type *, const char *) = delete;
|
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 = "") {
|
2015-04-24 21:16:07 +00:00
|
|
|
return CreateCall2(cast<FunctionType>(cast<PointerType>(Callee->getType())
|
|
|
|
->getElementType()),
|
|
|
|
Callee, Arg1, Arg2, Name);
|
|
|
|
}
|
|
|
|
CallInst *CreateCall2(FunctionType *Ty, Value *Callee, Value *Arg1,
|
|
|
|
Value *Arg2, const Twine &Name = "") {
|
2008-05-01 05:11:00 +00:00
|
|
|
Value *Args[] = { Arg1, Arg2 };
|
2015-04-24 21:16:07 +00:00
|
|
|
return Insert(CallInst::Create(Ty, 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
|
|
|
|
2015-03-12 15:27:07 +00:00
|
|
|
Value *CreateShuffleVector(Value *V1, Value *V2, ArrayRef<int> IntMask,
|
|
|
|
const Twine &Name = "") {
|
|
|
|
size_t MaskSize = IntMask.size();
|
|
|
|
SmallVector<Constant*, 8> MaskVec(MaskSize);
|
|
|
|
for (size_t i = 0; i != MaskSize; ++i)
|
|
|
|
MaskVec[i] = getInt32(IntMask[i]);
|
|
|
|
Value *Mask = ConstantVector::get(MaskVec);
|
|
|
|
return CreateShuffleVector(V1, V2, Mask, Name);
|
|
|
|
}
|
|
|
|
|
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 = "") {
|
2012-12-17 12:02:36 +00:00
|
|
|
return Insert(LandingPadInst::Create(Ty, PersFn, NumClauses), Name);
|
2011-08-12 20:24:12 +00:00
|
|
|
}
|
|
|
|
|
2008-09-27 23:22:55 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Utility creation methods
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Return an i1 value testing if \p 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);
|
|
|
|
}
|
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Return an i1 value testing if \p 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
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Return the i64 difference between two pointer values, dividing out
|
|
|
|
/// the size of the pointed-to objects.
|
|
|
|
///
|
|
|
|
/// This is intended to 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
|
|
|
}
|
2013-01-01 19:55:16 +00:00
|
|
|
|
2013-01-20 05:03:37 +00:00
|
|
|
/// \brief Return a vector value that contains \arg V broadcasted to \p
|
|
|
|
/// NumElts elements.
|
2013-01-01 19:55:16 +00:00
|
|
|
Value *CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name = "") {
|
|
|
|
assert(NumElts > 0 && "Cannot splat to an empty vector!");
|
|
|
|
|
|
|
|
// First insert it into an undef vector so we can shuffle it.
|
|
|
|
Type *I32Ty = getInt32Ty();
|
|
|
|
Value *Undef = UndefValue::get(VectorType::get(V->getType(), NumElts));
|
|
|
|
V = CreateInsertElement(Undef, V, ConstantInt::get(I32Ty, 0),
|
|
|
|
Name + ".splatinsert");
|
|
|
|
|
|
|
|
// Shuffle the value across the desired number of elements.
|
|
|
|
Value *Zeros = ConstantAggregateZero::get(VectorType::get(I32Ty, NumElts));
|
|
|
|
return CreateShuffleVector(V, Undef, Zeros, Name + ".splat");
|
|
|
|
}
|
2014-05-29 01:55:07 +00:00
|
|
|
|
|
|
|
/// \brief Return a value that has been extracted from a larger integer type.
|
|
|
|
Value *CreateExtractInteger(const DataLayout &DL, Value *From,
|
|
|
|
IntegerType *ExtractedTy, uint64_t Offset,
|
|
|
|
const Twine &Name) {
|
|
|
|
IntegerType *IntTy = cast<IntegerType>(From->getType());
|
|
|
|
assert(DL.getTypeStoreSize(ExtractedTy) + Offset <=
|
|
|
|
DL.getTypeStoreSize(IntTy) &&
|
|
|
|
"Element extends past full value");
|
|
|
|
uint64_t ShAmt = 8 * Offset;
|
|
|
|
Value *V = From;
|
|
|
|
if (DL.isBigEndian())
|
|
|
|
ShAmt = 8 * (DL.getTypeStoreSize(IntTy) -
|
|
|
|
DL.getTypeStoreSize(ExtractedTy) - Offset);
|
|
|
|
if (ShAmt) {
|
|
|
|
V = CreateLShr(V, ShAmt, Name + ".shift");
|
|
|
|
}
|
|
|
|
assert(ExtractedTy->getBitWidth() <= IntTy->getBitWidth() &&
|
|
|
|
"Cannot extract to a larger integer!");
|
|
|
|
if (ExtractedTy != IntTy) {
|
|
|
|
V = CreateTrunc(V, ExtractedTy, Name + ".trunc");
|
|
|
|
}
|
|
|
|
return V;
|
|
|
|
}
|
2014-10-15 23:44:22 +00:00
|
|
|
|
|
|
|
/// \brief Create an assume intrinsic call that represents an alignment
|
|
|
|
/// assumption on the provided pointer.
|
|
|
|
///
|
|
|
|
/// An optional offset can be provided, and if it is provided, the offset
|
|
|
|
/// must be subtracted from the provided pointer to get the pointer with the
|
|
|
|
/// specified alignment.
|
|
|
|
CallInst *CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue,
|
|
|
|
unsigned Alignment,
|
|
|
|
Value *OffsetValue = nullptr) {
|
|
|
|
assert(isa<PointerType>(PtrValue->getType()) &&
|
|
|
|
"trying to create an alignment assumption on a non-pointer?");
|
|
|
|
|
|
|
|
PointerType *PtrTy = cast<PointerType>(PtrValue->getType());
|
2015-03-10 02:37:25 +00:00
|
|
|
Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace());
|
2014-10-15 23:44:22 +00:00
|
|
|
Value *PtrIntValue = CreatePtrToInt(PtrValue, IntPtrTy, "ptrint");
|
|
|
|
|
|
|
|
Value *Mask = ConstantInt::get(IntPtrTy,
|
|
|
|
Alignment > 0 ? Alignment - 1 : 0);
|
|
|
|
if (OffsetValue) {
|
|
|
|
bool IsOffsetZero = false;
|
|
|
|
if (ConstantInt *CI = dyn_cast<ConstantInt>(OffsetValue))
|
|
|
|
IsOffsetZero = CI->isZero();
|
|
|
|
|
|
|
|
if (!IsOffsetZero) {
|
|
|
|
if (OffsetValue->getType() != IntPtrTy)
|
|
|
|
OffsetValue = CreateIntCast(OffsetValue, IntPtrTy, /*isSigned*/ true,
|
|
|
|
"offsetcast");
|
|
|
|
PtrIntValue = CreateSub(PtrIntValue, OffsetValue, "offsetptr");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *Zero = ConstantInt::get(IntPtrTy, 0);
|
|
|
|
Value *MaskedPtr = CreateAnd(PtrIntValue, Mask, "maskedptr");
|
|
|
|
Value *InvCond = CreateICmpEQ(MaskedPtr, Zero, "maskcond");
|
|
|
|
|
|
|
|
return CreateAssumption(InvCond);
|
|
|
|
}
|
2007-10-09 19:49:19 +00:00
|
|
|
};
|
2008-08-11 15:29:30 +00:00
|
|
|
|
2013-05-01 20:59:00 +00:00
|
|
|
// Create wrappers for C Binding types (see CBindingWrapping.h).
|
|
|
|
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef)
|
|
|
|
|
2007-05-27 15:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|