[llvm] [SandboxIR][NFC] Fixes for functions LoadInst::create (PR #100955)
Julius Alexandre via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 28 17:47:28 PDT 2024
https://github.com/medievalghoul created https://github.com/llvm/llvm-project/pull/100955
Changes were discussed here: https://github.com/llvm/llvm-project/pull/100850#discussion_r1694054361
cc: @vporpo
>From 7d3a9347530ea506cc9638536212ffdb4dd01e95 Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Sun, 28 Jul 2024 20:42:04 -0400
Subject: [PATCH] [SandboxIR][NFC] Fixes for functions
---
llvm/include/llvm/SandboxIR/SandboxIR.h | 11 +++++++--
llvm/lib/SandboxIR/SandboxIR.cpp | 27 ++++++++++++++++++++--
llvm/unittests/SandboxIR/SandboxIRTest.cpp | 13 +++++------
3 files changed, 40 insertions(+), 11 deletions(-)
diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h
index 667aeba1bda1f..3b5a17ccc9522 100644
--- a/llvm/include/llvm/SandboxIR/SandboxIR.h
+++ b/llvm/include/llvm/SandboxIR/SandboxIR.h
@@ -772,10 +772,17 @@ 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 = "");
+ const Twine &Name = "");
+ static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
+ Instruction *InsertBefore, bool IsVolatile,
+ Context &Ctx, const Twine &Name = "");
static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
BasicBlock *InsertAtEnd, Context &Ctx,
- bool IsVolatile = false, const Twine &Name = "");
+ const Twine &Name = "");
+ static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
+ BasicBlock *InsertAtEnd, bool IsVolatile,
+ Context &Ctx, 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 d2b4fb207ba3a..cf926de8a75bd 100644
--- a/llvm/lib/SandboxIR/SandboxIR.cpp
+++ b/llvm/lib/SandboxIR/SandboxIR.cpp
@@ -612,7 +612,19 @@ void BranchInst::dump() const {
LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align,
Instruction *InsertBefore, Context &Ctx,
- bool IsVolatile, const Twine &Name) {
+ 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);
+ auto *NewSBI = Ctx.createLoadInst(NewLI);
+ return NewSBI;
+}
+
+LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align,
+ Instruction *InsertBefore, bool IsVolatile,
+ Context &Ctx, const Twine &Name) {
llvm::Instruction *BeforeIR = InsertBefore->getTopmostLLVMInstruction();
auto &Builder = Ctx.getLLVMIRBuilder();
Builder.SetInsertPoint(BeforeIR);
@@ -624,7 +636,18 @@ LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align,
LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align,
BasicBlock *InsertAtEnd, Context &Ctx,
- bool IsVolatile, const Twine &Name) {
+ 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);
+ auto *NewSBI = Ctx.createLoadInst(NewLI);
+ return NewSBI;
+}
+
+LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align,
+ BasicBlock *InsertAtEnd, bool IsVolatile,
+ Context &Ctx, const Twine &Name) {
auto &Builder = Ctx.getLLVMIRBuilder();
Builder.SetInsertPoint(cast<llvm::BasicBlock>(InsertAtEnd->Val));
auto *NewLI =
diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
index 122508d15194f..4ef867c2af418 100644
--- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp
+++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
@@ -750,13 +750,13 @@ define void @foo(ptr %arg0, ptr %arg1) {
auto *BB = &*F->begin();
auto It = BB->begin();
auto *Ld = cast<sandboxir::LoadInst>(&*It++);
- auto *Vld = cast<sandboxir::LoadInst>(&*It++);
+ auto *VLd = cast<sandboxir::LoadInst>(&*It++);
auto *Ret = cast<sandboxir::ReturnInst>(&*It++);
// Check isVolatile()
EXPECT_FALSE(Ld->isVolatile());
// Check isVolatile()
- EXPECT_TRUE(Vld->isVolatile());
+ EXPECT_TRUE(VLd->isVolatile());
// Check getPointerOperand()
EXPECT_EQ(Ld->getPointerOperand(), Arg0);
// Check getAlign()
@@ -764,8 +764,7 @@ define void @foo(ptr %arg0, ptr %arg1) {
// Check create(InsertBefore)
sandboxir::LoadInst *NewLd =
sandboxir::LoadInst::create(Ld->getType(), Arg1, Align(8),
- /*InsertBefore=*/Ret, Ctx,
- /*IsVolatile=*/false, "NewLd");
+ /*InsertBefore=*/Ret, Ctx, "NewLd");
// Checking if create() was volatile
EXPECT_FALSE(NewLd->isVolatile());
EXPECT_EQ(NewLd->getType(), Ld->getType());
@@ -774,9 +773,9 @@ define void @foo(ptr %arg0, ptr %arg1) {
EXPECT_EQ(NewLd->getName(), "NewLd");
sandboxir::LoadInst *NewVLd =
- sandboxir::LoadInst::create(Vld->getType(), Arg1, Align(8),
- /*InsertBefore=*/Ret, Ctx,
- /*IsVolatile=*/true, "NewVLd");
+ sandboxir::LoadInst::create(VLd->getType(), Arg1, Align(8),
+ /*InsertBefore=*/Ret,
+ /*IsVolatile=*/true, Ctx, "NewVLd");
// Checking if create() was volatile
EXPECT_TRUE(NewVLd->isVolatile());
More information about the llvm-commits
mailing list