[llvm] [SandboxIR] Update visibility of IR constructors. (PR #98107)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 9 16:52:30 PDT 2024


================
@@ -58,51 +46,66 @@ define void @foo(i32 %v1) {
   llvm::BasicBlock *LLVMBB = &*LLVMF->begin();
   llvm::Instruction *LLVMAdd = &*LLVMBB->begin();
   auto *LLVMC = cast<llvm::Constant>(LLVMAdd->getOperand(1));
-  auto *LLVMArg0 = LLVMF->getArg(0);
 
   sandboxir::Context Ctx(C);
-  sandboxir::Function F(LLVMF, Ctx);
-  sandboxir::Argument Arg0(LLVMArg0, Ctx);
-  sandboxir::Constant Const0(LLVMC, Ctx);
-  sandboxir::OpaqueInst OpaqueI(LLVMAdd, Ctx);
+  sandboxir::Function *F = Ctx.createFunction(LLVMF);
+  sandboxir::Argument *Arg0 = F->getArg(0);
+  sandboxir::BasicBlock *BB = &*F->begin();
+  sandboxir::Instruction *AddI = &*BB->begin();
+  sandboxir::OpaqueInst *OpaqueI = cast<sandboxir::OpaqueInst>(AddI);
+  sandboxir::Constant *Const0 = cast<sandboxir::Constant>(Ctx.getValue(LLVMC));
 
   EXPECT_TRUE(isa<sandboxir::Function>(F));
   EXPECT_FALSE(isa<sandboxir::Function>(Arg0));
+  EXPECT_FALSE(isa<sandboxir::Function>(BB));
+  EXPECT_FALSE(isa<sandboxir::Function>(AddI));
   EXPECT_FALSE(isa<sandboxir::Function>(Const0));
   EXPECT_FALSE(isa<sandboxir::Function>(OpaqueI));
 
   EXPECT_FALSE(isa<sandboxir::Argument>(F));
   EXPECT_TRUE(isa<sandboxir::Argument>(Arg0));
+  EXPECT_FALSE(isa<sandboxir::Argument>(BB));
+  EXPECT_FALSE(isa<sandboxir::Argument>(AddI));
   EXPECT_FALSE(isa<sandboxir::Argument>(Const0));
   EXPECT_FALSE(isa<sandboxir::Argument>(OpaqueI));
 
   EXPECT_TRUE(isa<sandboxir::Constant>(F));
   EXPECT_FALSE(isa<sandboxir::Constant>(Arg0));
+  EXPECT_FALSE(isa<sandboxir::Constant>(BB));
+  EXPECT_FALSE(isa<sandboxir::Constant>(AddI));
   EXPECT_TRUE(isa<sandboxir::Constant>(Const0));
   EXPECT_FALSE(isa<sandboxir::Constant>(OpaqueI));
 
   EXPECT_FALSE(isa<sandboxir::OpaqueInst>(F));
   EXPECT_FALSE(isa<sandboxir::OpaqueInst>(Arg0));
+  EXPECT_FALSE(isa<sandboxir::OpaqueInst>(BB));
+  EXPECT_TRUE(isa<sandboxir::OpaqueInst>(AddI));
   EXPECT_FALSE(isa<sandboxir::OpaqueInst>(Const0));
   EXPECT_TRUE(isa<sandboxir::OpaqueInst>(OpaqueI));
 
   EXPECT_FALSE(isa<sandboxir::Instruction>(F));
   EXPECT_FALSE(isa<sandboxir::Instruction>(Arg0));
+  EXPECT_FALSE(isa<sandboxir::Instruction>(BB));
+  EXPECT_TRUE(isa<sandboxir::Instruction>(AddI));
   EXPECT_FALSE(isa<sandboxir::Instruction>(Const0));
   EXPECT_TRUE(isa<sandboxir::Instruction>(OpaqueI));
 
   EXPECT_FALSE(isa<sandboxir::User>(F));
   EXPECT_FALSE(isa<sandboxir::User>(Arg0));
+  EXPECT_FALSE(isa<sandboxir::User>(BB));
+  EXPECT_TRUE(isa<sandboxir::User>(AddI));
   EXPECT_TRUE(isa<sandboxir::User>(Const0));
   EXPECT_TRUE(isa<sandboxir::User>(OpaqueI));
 
 #ifndef NDEBUG
-  // The dump() functions should be very forgiving and should not crash even if
-  // sandboxir has not been built properly.
-  F.dump();
-  Arg0.dump();
-  Const0.dump();
-  OpaqueI.dump();
+  std::string Buff;
+  raw_string_ostream BS(Buff);
+  F->dump(BS);
----------------
vporpo wrote:

Yeah, I think I should add a test that checks all dumps.

https://github.com/llvm/llvm-project/pull/98107


More information about the llvm-commits mailing list