aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvporpo <vporpodas@google.com>2024-07-31 10:37:54 -0700
committerGitHub <noreply@github.com>2024-07-31 10:37:54 -0700
commit8b17b12912ff59b0c9f2825ac2cc258418ed349b (patch)
tree2bae704f8f41a6dc106eff62a7349212c67aba9c
parent9fe455fd0c7d6f2107b33b37c04bbd3b12fe65b3 (diff)
downloadllvm-8b17b12912ff59b0c9f2825ac2cc258418ed349b.zip
llvm-8b17b12912ff59b0c9f2825ac2cc258418ed349b.tar.gz
llvm-8b17b12912ff59b0c9f2825ac2cc258418ed349b.tar.bz2
[SandboxIR] Implement FPToUIInst (#101369)
This patch implements sandboxir::FPToUIInst which mirrors llvm::FPToUIInst.
-rw-r--r--llvm/include/llvm/SandboxIR/SandboxIR.h23
-rw-r--r--llvm/lib/SandboxIR/SandboxIR.cpp28
-rw-r--r--llvm/unittests/SandboxIR/SandboxIRTest.cpp70
3 files changed, 121 insertions, 0 deletions
diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h
index 190225e..a0a31e6 100644
--- a/llvm/include/llvm/SandboxIR/SandboxIR.h
+++ b/llvm/include/llvm/SandboxIR/SandboxIR.h
@@ -34,6 +34,8 @@
// | |
// | +- FPToSIInst
// | |
+// | +- FPToUIInst
+// | |
// | +- IntToPtrInst
// | |
// | +- PtrToIntInst
@@ -1376,6 +1378,27 @@ public:
#endif
};
+class FPToUIInst final : public CastInst {
+public:
+ static Value *create(Value *Src, Type *DestTy, BBIterator WhereIt,
+ BasicBlock *WhereBB, Context &Ctx,
+ const Twine &Name = "");
+ static Value *create(Value *Src, Type *DestTy, Instruction *InsertBefore,
+ Context &Ctx, const Twine &Name = "");
+ static Value *create(Value *Src, Type *DestTy, BasicBlock *InsertAtEnd,
+ Context &Ctx, const Twine &Name = "");
+
+ static bool classof(const Value *From) {
+ if (auto *I = dyn_cast<Instruction>(From))
+ return I->getOpcode() == Opcode::FPToUI;
+ return false;
+ }
+#ifndef NDEBUG
+ void dump(raw_ostream &OS) const final;
+ LLVM_DUMP_METHOD void dump() const final;
+#endif // NDEBUG
+};
+
class FPToSIInst final : public CastInst {
public:
static Value *create(Value *Src, Type *DestTy, BBIterator WhereIt,
diff --git a/llvm/lib/SandboxIR/SandboxIR.cpp b/llvm/lib/SandboxIR/SandboxIR.cpp
index 9ba168f..a6de4467 100644
--- a/llvm/lib/SandboxIR/SandboxIR.cpp
+++ b/llvm/lib/SandboxIR/SandboxIR.cpp
@@ -1143,6 +1143,34 @@ void CastInst::dump() const {
}
#endif // NDEBUG
+Value *FPToUIInst::create(Value *Src, Type *DestTy, BBIterator WhereIt,
+ BasicBlock *WhereBB, Context &Ctx,
+ const Twine &Name) {
+ return CastInst::create(DestTy, Instruction::Opcode::FPToUI, Src, WhereIt,
+ WhereBB, Ctx, Name);
+}
+Value *FPToUIInst::create(Value *Src, Type *DestTy, Instruction *InsertBefore,
+ Context &Ctx, const Twine &Name) {
+ return create(Src, DestTy, InsertBefore->getIterator(),
+ InsertBefore->getParent(), Ctx, Name);
+}
+Value *FPToUIInst::create(Value *Src, Type *DestTy, BasicBlock *InsertAtEnd,
+ Context &Ctx, const Twine &Name) {
+ return create(Src, DestTy, InsertAtEnd->end(), InsertAtEnd, Ctx, Name);
+}
+
+#ifndef NDEBUG
+void FPToUIInst::dump(raw_ostream &OS) const {
+ dumpCommonPrefix(OS);
+ dumpCommonSuffix(OS);
+}
+
+void FPToUIInst::dump() const {
+ dump(dbgs());
+ dbgs() << "\n";
+}
+#endif // NDEBUG
+
Value *FPToSIInst::create(Value *Src, Type *DestTy, BBIterator WhereIt,
BasicBlock *WhereBB, Context &Ctx,
const Twine &Name) {
diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
index c9c7fe0..f405bc1 100644
--- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp
+++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
@@ -1499,6 +1499,7 @@ define void @foo(i32 %arg, float %farg, double %darg, ptr %ptr) {
EXPECT_EQ(SExt->getDestTy(), Ti64);
auto *FPToUI = cast<sandboxir::CastInst>(&*It++);
+ EXPECT_TRUE(isa<sandboxir::FPToUIInst>(FPToUI));
EXPECT_EQ(FPToUI->getOpcode(), sandboxir::Instruction::Opcode::FPToUI);
EXPECT_EQ(FPToUI->getSrcTy(), Tfloat);
EXPECT_EQ(FPToUI->getDestTy(), Ti32);
@@ -1618,6 +1619,75 @@ define void @foo(i32 %arg, float %farg, double %darg, ptr %ptr) {
}
}
+TEST_F(SandboxIRTest, FPToUIInst) {
+ parseIR(C, R"IR(
+define void @foo(float %arg) {
+ %fptoui = fptoui float %arg to i32
+ ret void
+}
+)IR");
+ Function &LLVMF = *M->getFunction("foo");
+ sandboxir::Context Ctx(C);
+ sandboxir::Function *F = Ctx.createFunction(&LLVMF);
+ unsigned ArgIdx = 0;
+ auto *Arg = F->getArg(ArgIdx++);
+ auto *BB = &*F->begin();
+ auto It = BB->begin();
+ Type *Ti32 = Type::getInt32Ty(C);
+ Type *Tfloat = Type::getFloatTy(C);
+
+ auto *FPToUI = cast<sandboxir::FPToUIInst>(&*It++);
+ EXPECT_EQ(FPToUI->getOpcode(), sandboxir::Instruction::Opcode::FPToUI);
+ EXPECT_EQ(FPToUI->getSrcTy(), Tfloat);
+ EXPECT_EQ(FPToUI->getDestTy(), Ti32);
+ auto *Ret = cast<sandboxir::ReturnInst>(&*It++);
+
+ {
+ // Check create() WhereIt, WhereBB
+ auto *NewI = cast<sandboxir::FPToUIInst>(
+ sandboxir::FPToUIInst::create(Arg, Ti32, /*WhereIt=*/BB->end(),
+ /*WhereBB=*/BB, Ctx, "FPToUI"));
+ // Check getOpcode().
+ EXPECT_EQ(NewI->getOpcode(), sandboxir::Instruction::Opcode::FPToUI);
+ // Check getSrcTy().
+ EXPECT_EQ(NewI->getSrcTy(), Arg->getType());
+ // Check getDestTy().
+ EXPECT_EQ(NewI->getDestTy(), Ti32);
+ // Check instr position.
+ EXPECT_EQ(NewI->getNextNode(), nullptr);
+ EXPECT_EQ(NewI->getPrevNode(), Ret);
+ }
+ {
+ // Check create() InsertBefore.
+ auto *NewI = cast<sandboxir::FPToUIInst>(
+ sandboxir::FPToUIInst::create(Arg, Ti32,
+ /*InsertBefore=*/Ret, Ctx, "FPToUI"));
+ // Check getOpcode().
+ EXPECT_EQ(NewI->getOpcode(), sandboxir::Instruction::Opcode::FPToUI);
+ // Check getSrcTy().
+ EXPECT_EQ(NewI->getSrcTy(), Arg->getType());
+ // Check getDestTy().
+ EXPECT_EQ(NewI->getDestTy(), Ti32);
+ // Check instr position.
+ EXPECT_EQ(NewI->getNextNode(), Ret);
+ }
+ {
+ // Check create() InsertAtEnd.
+ auto *NewI = cast<sandboxir::FPToUIInst>(
+ sandboxir::FPToUIInst::create(Arg, Ti32,
+ /*InsertAtEnd=*/BB, Ctx, "FPToUI"));
+ // Check getOpcode().
+ EXPECT_EQ(NewI->getOpcode(), sandboxir::Instruction::Opcode::FPToUI);
+ // Check getSrcTy().
+ EXPECT_EQ(NewI->getSrcTy(), Arg->getType());
+ // Check getDestTy().
+ EXPECT_EQ(NewI->getDestTy(), Ti32);
+ // Check instr position.
+ EXPECT_EQ(NewI->getNextNode(), nullptr);
+ EXPECT_EQ(NewI->getParent(), BB);
+ }
+}
+
TEST_F(SandboxIRTest, FPToSIInst) {
parseIR(C, R"IR(
define void @foo(float %arg) {