[PATCH] llvm.noalias - Add IRBuilder support

hfinkel at anl.gov hfinkel at anl.gov
Thu Apr 30 08:12:41 PDT 2015


Hi chandlerc, reames,

This is part of the series started by D9375, and adds functions in IRBuilder to create the llvm.noalias intrinsics (this is used by later patches).

There is a workaround for some kinds of pointers we can't currently mangle. I don't think this is worth fixing in the mangling code because soon we'll have only an opaque pointer type and this will be irrelevant.

http://reviews.llvm.org/D9378

Files:
  include/llvm/IR/IRBuilder.h
  lib/IR/IRBuilder.cpp

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<StructType>(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<CallInst>(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

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9378.24712.patch
Type: text/x-patch
Size: 2142 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150430/bfc388e4/attachment.bin>


More information about the llvm-commits mailing list