[PATCH] D68490: [PATCH 07/38] [noalias] D9378: Add IRBuilder support
Jeroen Dobbelaere via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 4 14:30:57 PDT 2019
jeroen.dobbelaere created this revision.
jeroen.dobbelaere added reviewers: hfinkel, jdoerfert.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
This is part of the series started by D68484 <https://reviews.llvm.org/D68484>.
Rebase of D9378 <https://reviews.llvm.org/D9378>.
https://reviews.llvm.org/D68490
Files:
llvm/include/llvm/IR/IRBuilder.h
llvm/lib/IR/IRBuilder.cpp
llvm/unittests/IR/IRBuilderTest.cpp
Index: llvm/unittests/IR/IRBuilderTest.cpp
===================================================================
--- llvm/unittests/IR/IRBuilderTest.cpp
+++ llvm/unittests/IR/IRBuilderTest.cpp
@@ -284,6 +284,30 @@
EXPECT_FALSE(verifyModule(*M));
}
+TEST_F(IRBuilderTest, NoAlias) {
+ IRBuilder<> Builder(BB);
+ AllocaInst *Var1 = Builder.CreateAlloca(Builder.getInt8Ty());
+
+ MDBuilder MDB(BB->getContext());
+ MDNode *NewDomain =
+ MDB.createAnonymousAliasScopeDomain("Test Domain");
+ MDNode *AScope =
+ MDB.createAnonymousAliasScope(NewDomain, "Test Scope");
+
+ CallInst *NAP = cast<CallInst>(Builder.CreateNoAliasPointer(Var1, AScope));
+
+ EXPECT_EQ(NAP->getArgOperand(0), Var1);
+ EXPECT_EQ(cast<MetadataAsValue>(NAP->getArgOperand(1))->getMetadata(),
+ AScope);
+
+ IntrinsicInst *II_NAP = dyn_cast<IntrinsicInst>(NAP);
+ ASSERT_TRUE(II_NAP != nullptr);
+ EXPECT_EQ(II_NAP->getIntrinsicID(), Intrinsic::noalias);
+
+ EXPECT_TRUE(NAP->onlyAccessesArgMemory());
+ EXPECT_TRUE(NAP->doesNotThrow());
+}
+
TEST_F(IRBuilderTest, SideChannel) {
IRBuilder<> Builder(BB);
Index: llvm/lib/IR/IRBuilder.cpp
===================================================================
--- llvm/lib/IR/IRBuilder.cpp
+++ llvm/lib/IR/IRBuilder.cpp
@@ -23,6 +23,7 @@
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Metadata.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/Statepoint.h"
#include "llvm/IR/Type.h"
@@ -457,6 +458,32 @@
return createCallHelper(FnAssume, Ops, this);
}
+Instruction *IRBuilderBase::CreateNoAliasPointer(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 (auto *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->getModule();
+ Function *FnNoAlias = Intrinsic::getDeclaration(M, Intrinsic::noalias, Types);
+ Instruction *Ret = createCallHelper(FnNoAlias, Ops, this);
+
+ 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.
/// \p Ptr - base pointer for the load
/// \p Align - alignment of the source location
Index: llvm/include/llvm/IR/IRBuilder.h
===================================================================
--- llvm/include/llvm/IR/IRBuilder.h
+++ llvm/include/llvm/IR/IRBuilder.h
@@ -641,6 +641,9 @@
/// assume that the provided condition will be true.
CallInst *CreateAssumption(Value *Cond);
+ /// \brief Create an noalias intrinsic.
+ Instruction *CreateNoAliasPointer(Value *Ptr, MDNode *ScopeTag);
+
/// Create a call to the experimental.gc.statepoint intrinsic to
/// start a new statepoint sequence.
CallInst *CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68490.223290.patch
Type: text/x-patch
Size: 3246 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191004/697ae149/attachment.bin>
More information about the llvm-commits
mailing list