[llvm] [SandboxIR] Added isVolatile args to existing LoadInst::create function (PR #100850)
Julius Alexandre via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 27 17:46:17 PDT 2024
https://github.com/medievalghoul updated https://github.com/llvm/llvm-project/pull/100850
>From f66ee5e7c901bda1a2cb78a8554f7621dc96020b Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Fri, 26 Jul 2024 21:48:23 -0400
Subject: [PATCH 1/3] Added isVolatile args in LoadInst::create function
---
llvm/include/llvm/SandboxIR/SandboxIR.h | 4 ++--
llvm/lib/SandboxIR/SandboxIR.cpp | 8 ++++----
llvm/unittests/SandboxIR/SandboxIRTest.cpp | 13 ++++++++++++-
3 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h
index 5c89f165c9647..d13e547bc97cc 100644
--- a/llvm/include/llvm/SandboxIR/SandboxIR.h
+++ b/llvm/include/llvm/SandboxIR/SandboxIR.h
@@ -769,10 +769,10 @@ class LoadInst final : public Instruction {
unsigned getNumOfIRInstrs() const final { return 1u; }
static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
Instruction *InsertBefore, Context &Ctx,
- const Twine &Name = "");
+ bool isVolatile = false, const Twine &Name = "");
static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
BasicBlock *InsertAtEnd, Context &Ctx,
- const Twine &Name = "");
+ bool isVolatile = false, const Twine &Name = "");
/// For isa/dyn_cast.
static bool classof(const Value *From);
Value *getPointerOperand() const;
diff --git a/llvm/lib/SandboxIR/SandboxIR.cpp b/llvm/lib/SandboxIR/SandboxIR.cpp
index da482765c7d11..9e41bacf1a8dd 100644
--- a/llvm/lib/SandboxIR/SandboxIR.cpp
+++ b/llvm/lib/SandboxIR/SandboxIR.cpp
@@ -612,23 +612,23 @@ void BranchInst::dump() const {
LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align,
Instruction *InsertBefore, Context &Ctx,
- const Twine &Name) {
+ bool isVolatile, const Twine &Name) {
llvm::Instruction *BeforeIR = InsertBefore->getTopmostLLVMInstruction();
auto &Builder = Ctx.getLLVMIRBuilder();
Builder.SetInsertPoint(BeforeIR);
auto *NewLI = Builder.CreateAlignedLoad(Ty, Ptr->Val, Align,
- /*isVolatile=*/false, Name);
+ isVolatile, Name);
auto *NewSBI = Ctx.createLoadInst(NewLI);
return NewSBI;
}
LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align,
BasicBlock *InsertAtEnd, Context &Ctx,
- const Twine &Name) {
+ bool isVolatile, const Twine &Name) {
auto &Builder = Ctx.getLLVMIRBuilder();
Builder.SetInsertPoint(cast<llvm::BasicBlock>(InsertAtEnd->Val));
auto *NewLI = Builder.CreateAlignedLoad(Ty, Ptr->Val, Align,
- /*isVolatile=*/false, Name);
+ isVolatile, Name);
auto *NewSBI = Ctx.createLoadInst(NewLI);
return NewSBI;
}
diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
index 0565e87ce9517..d1d326dab9cbb 100644
--- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp
+++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
@@ -764,11 +764,22 @@ define void @foo(ptr %arg0, ptr %arg1) {
// Check create(InsertBefore)
sandboxir::LoadInst *NewLd =
sandboxir::LoadInst::create(Ld->getType(), Arg1, Align(8),
- /*InsertBefore=*/Ret, Ctx, "NewLd");
+ /*InsertBefore=*/Ret, Ctx,
+ Ld->isVolatile(), "NewLd");
EXPECT_EQ(NewLd->getType(), Ld->getType());
EXPECT_EQ(NewLd->getPointerOperand(), Arg1);
EXPECT_EQ(NewLd->getAlign(), 8);
EXPECT_EQ(NewLd->getName(), "NewLd");
+
+ sandboxir::LoadInst *NewVld =
+ sandboxir::LoadInst::create(Vld->getType(), Arg1, Align(8),
+ /*InsertBefore=*/Ret, Ctx,
+ Vld->isVolatile(), "NewVld");
+ EXPECT_EQ(NewVld->getType(), Vld->getType());
+ EXPECT_EQ(NewVld->getPointerOperand(), Arg1);
+ EXPECT_EQ(NewVld->isVolatile(), Vld->isVolatile());
+ EXPECT_EQ(NewVld->getAlign(), 8);
+ EXPECT_EQ(NewVld->getName(), "NewVld");
}
TEST_F(SandboxIRTest, StoreInst) {
>From 785544161e7c40349a1c910b0159041f8ce1344f Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Sat, 27 Jul 2024 18:13:30 -0400
Subject: [PATCH 2/3] removed some unneeded code and clang format
---
llvm/include/llvm/SandboxIR/SandboxIR.h | 2 +-
llvm/lib/SandboxIR/SandboxIR.cpp | 8 ++++----
llvm/unittests/SandboxIR/SandboxIRTest.cpp | 15 +++++++--------
3 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h
index d13e547bc97cc..9b102b8348ae5 100644
--- a/llvm/include/llvm/SandboxIR/SandboxIR.h
+++ b/llvm/include/llvm/SandboxIR/SandboxIR.h
@@ -65,8 +65,8 @@
#define LLVM_SANDBOXIR_SANDBOXIR_H
#include "llvm/IR/Function.h"
-#include "llvm/IR/Instruction.h"
#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Instruction.h"
#include "llvm/IR/User.h"
#include "llvm/IR/Value.h"
#include "llvm/SandboxIR/Tracker.h"
diff --git a/llvm/lib/SandboxIR/SandboxIR.cpp b/llvm/lib/SandboxIR/SandboxIR.cpp
index 9e41bacf1a8dd..fb780ed87a3c0 100644
--- a/llvm/lib/SandboxIR/SandboxIR.cpp
+++ b/llvm/lib/SandboxIR/SandboxIR.cpp
@@ -616,8 +616,8 @@ LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align,
llvm::Instruction *BeforeIR = InsertBefore->getTopmostLLVMInstruction();
auto &Builder = Ctx.getLLVMIRBuilder();
Builder.SetInsertPoint(BeforeIR);
- auto *NewLI = Builder.CreateAlignedLoad(Ty, Ptr->Val, Align,
- isVolatile, Name);
+ auto *NewLI =
+ Builder.CreateAlignedLoad(Ty, Ptr->Val, Align, isVolatile, Name);
auto *NewSBI = Ctx.createLoadInst(NewLI);
return NewSBI;
}
@@ -627,8 +627,8 @@ LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align,
bool isVolatile, const Twine &Name) {
auto &Builder = Ctx.getLLVMIRBuilder();
Builder.SetInsertPoint(cast<llvm::BasicBlock>(InsertAtEnd->Val));
- auto *NewLI = Builder.CreateAlignedLoad(Ty, Ptr->Val, Align,
- isVolatile, Name);
+ auto *NewLI =
+ Builder.CreateAlignedLoad(Ty, Ptr->Val, Align, isVolatile, Name);
auto *NewSBI = Ctx.createLoadInst(NewLI);
return NewSBI;
}
diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
index d1d326dab9cbb..266e5d3302518 100644
--- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp
+++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
@@ -764,21 +764,20 @@ define void @foo(ptr %arg0, ptr %arg1) {
// Check create(InsertBefore)
sandboxir::LoadInst *NewLd =
sandboxir::LoadInst::create(Ld->getType(), Arg1, Align(8),
- /*InsertBefore=*/Ret, Ctx,
- Ld->isVolatile(), "NewLd");
+ /*InsertBefore=*/Ret, Ctx,
+ /*IsVolatile=*/false, "NewLd");
EXPECT_EQ(NewLd->getType(), Ld->getType());
EXPECT_EQ(NewLd->getPointerOperand(), Arg1);
EXPECT_EQ(NewLd->getAlign(), 8);
EXPECT_EQ(NewLd->getName(), "NewLd");
-
+
sandboxir::LoadInst *NewVld =
sandboxir::LoadInst::create(Vld->getType(), Arg1, Align(8),
- /*InsertBefore=*/Ret, Ctx,
- Vld->isVolatile(), "NewVld");
- EXPECT_EQ(NewVld->getType(), Vld->getType());
- EXPECT_EQ(NewVld->getPointerOperand(), Arg1);
+ /*InsertBefore=*/Ret, Ctx,
+ /*IsVolatile=*/true, "NewVld");
+
+ // Checking if create() was volatile
EXPECT_EQ(NewVld->isVolatile(), Vld->isVolatile());
- EXPECT_EQ(NewVld->getAlign(), 8);
EXPECT_EQ(NewVld->getName(), "NewVld");
}
>From 8e8c94f98f6dd3f24adb60239fefcd2286833840 Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Sat, 27 Jul 2024 20:46:02 -0400
Subject: [PATCH 3/3] small changes
---
llvm/include/llvm/SandboxIR/SandboxIR.h | 4 ++--
llvm/lib/SandboxIR/SandboxIR.cpp | 8 ++++----
llvm/unittests/SandboxIR/SandboxIRTest.cpp | 8 ++++----
3 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h
index 9b102b8348ae5..7161d38397a89 100644
--- a/llvm/include/llvm/SandboxIR/SandboxIR.h
+++ b/llvm/include/llvm/SandboxIR/SandboxIR.h
@@ -769,10 +769,10 @@ class LoadInst final : public Instruction {
unsigned getNumOfIRInstrs() const final { return 1u; }
static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
Instruction *InsertBefore, Context &Ctx,
- bool isVolatile = false, const Twine &Name = "");
+ bool IsVolatile = false, const Twine &Name = "");
static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
BasicBlock *InsertAtEnd, Context &Ctx,
- bool isVolatile = false, const Twine &Name = "");
+ bool IsVolatile = false, const Twine &Name = "");
/// For isa/dyn_cast.
static bool classof(const Value *From);
Value *getPointerOperand() const;
diff --git a/llvm/lib/SandboxIR/SandboxIR.cpp b/llvm/lib/SandboxIR/SandboxIR.cpp
index fb780ed87a3c0..b055d749fd594 100644
--- a/llvm/lib/SandboxIR/SandboxIR.cpp
+++ b/llvm/lib/SandboxIR/SandboxIR.cpp
@@ -612,23 +612,23 @@ void BranchInst::dump() const {
LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align,
Instruction *InsertBefore, Context &Ctx,
- bool isVolatile, const Twine &Name) {
+ bool IsVolatile, const Twine &Name) {
llvm::Instruction *BeforeIR = InsertBefore->getTopmostLLVMInstruction();
auto &Builder = Ctx.getLLVMIRBuilder();
Builder.SetInsertPoint(BeforeIR);
auto *NewLI =
- Builder.CreateAlignedLoad(Ty, Ptr->Val, Align, isVolatile, Name);
+ Builder.CreateAlignedLoad(Ty, Ptr->Val, Align, IsVolatile, Name);
auto *NewSBI = Ctx.createLoadInst(NewLI);
return NewSBI;
}
LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align,
BasicBlock *InsertAtEnd, Context &Ctx,
- bool isVolatile, const Twine &Name) {
+ bool IsVolatile, const Twine &Name) {
auto &Builder = Ctx.getLLVMIRBuilder();
Builder.SetInsertPoint(cast<llvm::BasicBlock>(InsertAtEnd->Val));
auto *NewLI =
- Builder.CreateAlignedLoad(Ty, Ptr->Val, Align, isVolatile, Name);
+ Builder.CreateAlignedLoad(Ty, Ptr->Val, Align, IsVolatile, Name);
auto *NewSBI = Ctx.createLoadInst(NewLI);
return NewSBI;
}
diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
index 266e5d3302518..2f483609195d9 100644
--- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp
+++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
@@ -771,14 +771,14 @@ define void @foo(ptr %arg0, ptr %arg1) {
EXPECT_EQ(NewLd->getAlign(), 8);
EXPECT_EQ(NewLd->getName(), "NewLd");
- sandboxir::LoadInst *NewVld =
+ sandboxir::LoadInst *NewVLd =
sandboxir::LoadInst::create(Vld->getType(), Arg1, Align(8),
/*InsertBefore=*/Ret, Ctx,
- /*IsVolatile=*/true, "NewVld");
+ /*IsVolatile=*/true, "NewVLd");
// Checking if create() was volatile
- EXPECT_EQ(NewVld->isVolatile(), Vld->isVolatile());
- EXPECT_EQ(NewVld->getName(), "NewVld");
+ EXPECT_TRUE(NewVLd->isVolatile());
+ EXPECT_EQ(NewVLd->getName(), "NewVLd");
}
TEST_F(SandboxIRTest, StoreInst) {
More information about the llvm-commits
mailing list