Index: include/llvm/IR/IRBuilder.h =================================================================== --- include/llvm/IR/IRBuilder.h +++ include/llvm/IR/IRBuilder.h @@ -445,6 +445,9 @@ /// assume that the provided condition will be true. CallInst *CreateAssumption(Value *Cond); + /// \brief Create an noalias intrinsic. + Instruction *CreateNoAlias(Value *Ptr, MDNode *ScopeTag); + /// \brief Create a call to the experimental.gc.statepoint intrinsic to /// start a new statepoint sequence. CallInst *CreateGCStatepoint(Value *ActualCallee, Index: lib/IR/IRBuilder.cpp =================================================================== --- lib/IR/IRBuilder.cpp +++ lib/IR/IRBuilder.cpp @@ -17,6 +17,7 @@ #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Metadata.h" using namespace llvm; /// CreateGlobalString - Make a new global variable with an initializer that @@ -185,6 +186,33 @@ return createCallHelper(FnAssume, Ops, this); } +Instruction *IRBuilderBase::CreateNoAlias(Value *Ptr, MDNode *ScopeTag) { + // FIXME: We can currently mangle just about everything, but not literal + // structs (for those, bitcast to i8*). + Value *CPtr = Ptr; + if (StructType* STyp = + dyn_cast(CPtr->getType()->getPointerElementType())) { + if (STyp->isLiteral()) + CPtr = getCastedInt8PtrValue(CPtr); + } + + Type *Types[] = { CPtr->getType() }; + Value *Ops[] = { CPtr, MetadataAsValue::get(Context, ScopeTag) }; + Module *M = BB->getParent()->getParent(); + Value *FnNoAlias = Intrinsic::getDeclaration(M, Intrinsic::noalias, Types); + Instruction *Ret = createCallHelper(FnNoAlias, Ops, this); + cast(Ret)->setDoesNotThrow(); + + if (Ret->getType() != Ptr->getType()) { + BitCastInst *BCI = new BitCastInst(Ret, Ptr->getType(), ""); + BB->getInstList().insert(InsertPt, BCI); + SetInstDebugLocation(BCI); + Ret = BCI; + } + + return Ret; +} + /// Create a call to a Masked Load intrinsic. /// Ptr - the base pointer for the load /// Align - alignment of the source location