1 //===------- VFABIUtils.cpp - VFABI Unittests ----------------------------===//
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/AsmParser/Parser.h"
10 #include "llvm/IR/InstIterator.h"
11 #include "llvm/IR/Instructions.h"
12 #include "llvm/IR/Module.h"
13 #include "llvm/Support/SourceMgr.h"
14 #include "llvm/Transforms/Utils/ModuleUtils.h"
15 #include "gtest/gtest.h"
19 class VFABIAttrTest
: public testing::Test
{
21 void SetUp() override
{
22 M
= parseAssemblyString(IR
, Err
, Ctx
);
23 // Get the only call instruction in the block, which is the first
25 CI
= dyn_cast
<CallInst
>(&*(instructions(M
->getFunction("f")).begin()));
27 const char *IR
= "define i32 @f(i32 %a) {\n"
28 " %1 = call i32 @g(i32 %a) #0\n"
31 "declare i32 @g(i32)\n"
32 "declare <2 x i32> @custom_vg(<2 x i32>)"
33 "declare <4 x i32> @_ZGVnN4v_g(<4 x i32>)"
34 "declare <8 x i32> @_ZGVnN8v_g(<8 x i32>)"
36 "\"vector-function-abi-variant\"=\""
37 "_ZGVnN2v_g(custom_vg),_ZGVnN4v_g\" }";
40 std::unique_ptr
<Module
> M
;
42 SmallVector
<std::string
, 8> Mappings
;
45 TEST_F(VFABIAttrTest
, Write
) {
46 Mappings
.push_back("_ZGVnN8v_g");
47 Mappings
.push_back("_ZGVnN2v_g(custom_vg)");
48 VFABI::setVectorVariantNames(CI
, Mappings
);
50 CI
->getFnAttr("vector-function-abi-variant").getValueAsString();
51 EXPECT_EQ(S
, "_ZGVnN8v_g,_ZGVnN2v_g(custom_vg)");