summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Transforms/Utils/VFABIUtils.cpp
diff options
context:
space:
mode:
authorFrancesco Petrogalli <francesco.petrogalli@arm.com>2019-10-30 19:08:21 +0000
committerFrancesco Petrogalli <francesco.petrogalli@arm.com>2019-11-12 03:40:42 +0000
commite9a06e06064145e0baf723187ab023dd91e914f9 (patch)
treeaebaac7cdf012ca7d3e2d5297ab75ab54470728b /llvm/unittests/Transforms/Utils/VFABIUtils.cpp
parent31ea714e9a94d3912988c06139cb987e14478e84 (diff)
downloadbcm5719-llvm-e9a06e06064145e0baf723187ab023dd91e914f9.tar.gz
bcm5719-llvm-e9a06e06064145e0baf723187ab023dd91e914f9.zip
[VFABI] Read/Write functions for the VFABI attribute.
The attribute is stored at the `FunctionIndex` attribute set, with the name "vector-function-abi-variant". The get/set methods of the attribute have assertion to verify that: 1. Each name in the attribute is a valid VFABI mangled name. 2. Each name in the attribute correspond to a function declared in the module. Differential Revision: https://reviews.llvm.org/D69976
Diffstat (limited to 'llvm/unittests/Transforms/Utils/VFABIUtils.cpp')
-rw-r--r--llvm/unittests/Transforms/Utils/VFABIUtils.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/llvm/unittests/Transforms/Utils/VFABIUtils.cpp b/llvm/unittests/Transforms/Utils/VFABIUtils.cpp
new file mode 100644
index 00000000000..f69e31cd610
--- /dev/null
+++ b/llvm/unittests/Transforms/Utils/VFABIUtils.cpp
@@ -0,0 +1,55 @@
+//===------- VFABIUtils.cpp - VFABI Unittests ----------------------------===//
+//
+// 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/AsmParser/Parser.h"
+#include "llvm/IR/InstIterator.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Support/SourceMgr.h"
+#include "llvm/Transforms/Utils/ModuleUtils.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+class VFABIAttrTest : public testing::Test {
+protected:
+ void SetUp() override {
+ M = parseAssemblyString(IR, Err, Ctx);
+ // Get the only call instruction in the block, which is the first
+ // instruction.
+ CI = dyn_cast<CallInst>(&*(instructions(M->getFunction("f")).begin()));
+ }
+ const char *IR = "define i32 @f(i32 %a) {\n"
+ " %1 = call i32 @g(i32 %a) #0\n"
+ " ret i32 %1\n"
+ "}\n"
+ "declare i32 @g(i32)\n"
+ "declare <2 x i32> @custom_vg(<2 x i32>)"
+ "declare <4 x i32> @_ZGVnN4v_g(<4 x i32>)"
+ "declare <8 x i32> @_ZGVnN8v_g(<8 x i32>)"
+ "attributes #0 = { "
+ "\"vector-function-abi-variant\"=\""
+ "_ZGVnN2v_g(custom_vg),_ZGVnN4v_g\" }";
+ LLVMContext Ctx;
+ SMDiagnostic Err;
+ std::unique_ptr<Module> M;
+ CallInst *CI;
+ SmallVector<std::string, 8> Mappings;
+};
+
+TEST_F(VFABIAttrTest, Write) {
+ Mappings.push_back("_ZGVnN8v_g");
+ Mappings.push_back("_ZGVnN2v_g(custom_vg)");
+ VFABI::setVectorVariantNames(CI, Mappings);
+ const AttributeList Attrs = CI->getAttributes();
+ const AttributeSet FnAttrs = Attrs.getFnAttributes();
+ const StringRef S = CI->getAttribute(AttributeList::FunctionIndex,
+ "vector-function-abi-variant")
+ .getValueAsString();
+ EXPECT_EQ(S, "_ZGVnN8v_g,_ZGVnN2v_g(custom_vg)");
+}
OpenPOWER on IntegriCloud