1 //===- CallLowering.cpp - CallLowering unit tests -------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/CodeGen/GlobalISel/CallLowering.h"
10 #include "llvm/ADT/StringRef.h"
11 #include "llvm/AsmParser/Parser.h"
12 #include "llvm/IR/LLVMContext.h"
13 #include "llvm/IR/Module.h"
14 #include "llvm/Support/SourceMgr.h"
15 #include "gtest/gtest.h"
20 struct TargetCallLoweringTest
: public CallLowering
, testing::Test
{
24 TargetCallLoweringTest() : CallLowering(nullptr) {}
26 std::unique_ptr
<Module
> parseIR(const char *IR
) {
28 std::unique_ptr
<Module
> Mod
= parseAssemblyString(IR
, Err
, C
);
30 Err
.print("TestTargetCallLoweringTest", errs());
36 TEST_F(TargetCallLoweringTest
, ArgByRef
) {
37 std::unique_ptr
<Module
> M
= parseIR(R
"(
38 define void @foo(ptr %p0, ptr byref(i32) align(4) %p1) {
42 const DataLayout
&DL
= M
->getDataLayout();
43 Function
*F
= M
->getFunction("foo");
45 SmallVector
<Register
, 4> VRegs(1, 1);
47 CallLowering::ArgInfo
Arg0(VRegs
, F
->getArg(0)->getType(), 0);
48 setArgFlags(Arg0
, AttributeList::FirstArgIndex
+ 0, DL
, *F
);
49 EXPECT_TRUE(Arg0
.Flags
[0].isPointer());
50 EXPECT_FALSE(Arg0
.Flags
[0].isByRef());
52 CallLowering::ArgInfo
Arg1(VRegs
, F
->getArg(1)->getType(), 1);
53 setArgFlags(Arg1
, AttributeList::FirstArgIndex
+ 1, DL
, *F
);
54 EXPECT_TRUE(Arg1
.Flags
[0].isPointer());
55 EXPECT_TRUE(Arg1
.Flags
[0].isByRef());
56 EXPECT_EQ(Arg1
.Flags
[0].getByRefSize(), 4U);