aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordarkbuck <michael.hliao@gmail.com>2024-06-27 13:19:44 -0400
committerGitHub <noreply@github.com>2024-06-27 13:19:44 -0400
commit1ff05876fb686cfee99c31b9dd69b051e34a31fa (patch)
treebae61a38a20c7885b1c5892bda16416c81919d16
parent1448ed2000ff0be17025dab0aad7412d054425eb (diff)
downloadllvm-1ff05876fb686cfee99c31b9dd69b051e34a31fa.zip
llvm-1ff05876fb686cfee99c31b9dd69b051e34a31fa.tar.gz
llvm-1ff05876fb686cfee99c31b9dd69b051e34a31fa.tar.bz2
[GlobalISel] Add unit tests for call lowering on byref support
Reviewers: tschuett, spaits, aemerson, arsenm Reviewed By: spaits, arsenm Pull Request: https://github.com/llvm/llvm-project/pull/96805
-rw-r--r--llvm/unittests/CodeGen/GlobalISel/CMakeLists.txt2
-rw-r--r--llvm/unittests/CodeGen/GlobalISel/CallLowering.cpp57
2 files changed, 59 insertions, 0 deletions
diff --git a/llvm/unittests/CodeGen/GlobalISel/CMakeLists.txt b/llvm/unittests/CodeGen/GlobalISel/CMakeLists.txt
index 111d7f4..253b90d 100644
--- a/llvm/unittests/CodeGen/GlobalISel/CMakeLists.txt
+++ b/llvm/unittests/CodeGen/GlobalISel/CMakeLists.txt
@@ -1,5 +1,6 @@
set(LLVM_LINK_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
+ AsmParser
CodeGen
CodeGenTypes
Core
@@ -26,4 +27,5 @@ add_llvm_unittest(GlobalISelTests
KnownBitsVectorTest.cpp
GISelUtilsTest.cpp
GISelAliasTest.cpp
+ CallLowering.cpp
)
diff --git a/llvm/unittests/CodeGen/GlobalISel/CallLowering.cpp b/llvm/unittests/CodeGen/GlobalISel/CallLowering.cpp
new file mode 100644
index 0000000..1d36e5e
--- /dev/null
+++ b/llvm/unittests/CodeGen/GlobalISel/CallLowering.cpp
@@ -0,0 +1,57 @@
+//===- CallLowering.cpp - CallLowering unit tests -------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CodeGen/GlobalISel/CallLowering.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/AsmParser/Parser.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Support/SourceMgr.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+struct TargetCallLoweringTest : public CallLowering, testing::Test {
+ LLVMContext C;
+
+public:
+ TargetCallLoweringTest() : CallLowering(nullptr) {}
+
+ std::unique_ptr<Module> parseIR(const char *IR) {
+ SMDiagnostic Err;
+ std::unique_ptr<Module> Mod = parseAssemblyString(IR, Err, C);
+ if (!Mod)
+ Err.print("TestTargetCallLoweringTest", errs());
+ return Mod;
+ }
+};
+} // namespace
+
+TEST_F(TargetCallLoweringTest, ArgByRef) {
+ std::unique_ptr<Module> M = parseIR(R"(
+define void @foo(ptr %p0, ptr byref(i32) align(4) %p1) {
+ ret void
+}
+)");
+ const DataLayout &DL = M->getDataLayout();
+ Function *F = M->getFunction("foo");
+ // Dummy vregs.
+ SmallVector<Register, 4> VRegs(1, 1);
+
+ CallLowering::ArgInfo Arg0(VRegs, F->getArg(0)->getType(), 0);
+ setArgFlags(Arg0, AttributeList::FirstArgIndex + 0, DL, *F);
+ EXPECT_TRUE(Arg0.Flags[0].isPointer());
+ EXPECT_FALSE(Arg0.Flags[0].isByRef());
+
+ CallLowering::ArgInfo Arg1(VRegs, F->getArg(1)->getType(), 1);
+ setArgFlags(Arg1, AttributeList::FirstArgIndex + 1, DL, *F);
+ EXPECT_TRUE(Arg1.Flags[0].isPointer());
+ EXPECT_TRUE(Arg1.Flags[0].isByRef());
+ EXPECT_EQ(Arg1.Flags[0].getByRefSize(), 4U);
+}