2014-11-17 18:51:45 +01:00
|
|
|
//=======- CallGraphTest.cpp - Unit tests for the CG analysis -------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// 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
|
2014-11-17 18:51:45 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Analysis/CallGraph.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
template <typename Ty> void canSpecializeGraphTraitsIterators(Ty *G) {
|
2016-08-22 23:09:30 +02:00
|
|
|
typedef typename GraphTraits<Ty *>::NodeRef NodeRef;
|
2014-11-17 18:51:45 +01:00
|
|
|
|
|
|
|
auto I = GraphTraits<Ty *>::nodes_begin(G);
|
|
|
|
auto E = GraphTraits<Ty *>::nodes_end(G);
|
|
|
|
auto X = ++I;
|
|
|
|
|
|
|
|
// Should be able to iterate over all nodes of the graph.
|
2016-08-22 23:09:30 +02:00
|
|
|
static_assert(std::is_same<decltype(*I), NodeRef>::value,
|
2014-11-17 18:51:45 +01:00
|
|
|
"Node type does not match");
|
2016-08-22 23:09:30 +02:00
|
|
|
static_assert(std::is_same<decltype(*X), NodeRef>::value,
|
2014-11-17 18:51:45 +01:00
|
|
|
"Node type does not match");
|
2016-08-22 23:09:30 +02:00
|
|
|
static_assert(std::is_same<decltype(*E), NodeRef>::value,
|
2014-11-17 18:51:45 +01:00
|
|
|
"Node type does not match");
|
|
|
|
|
2016-08-22 23:09:30 +02:00
|
|
|
NodeRef N = GraphTraits<Ty *>::getEntryNode(G);
|
2014-11-17 18:51:45 +01:00
|
|
|
|
2016-08-22 23:09:30 +02:00
|
|
|
auto S = GraphTraits<NodeRef>::child_begin(N);
|
|
|
|
auto F = GraphTraits<NodeRef>::child_end(N);
|
2014-11-17 18:51:45 +01:00
|
|
|
|
|
|
|
// Should be able to iterate over immediate successors of a node.
|
2016-08-22 23:09:30 +02:00
|
|
|
static_assert(std::is_same<decltype(*S), NodeRef>::value,
|
2014-11-17 18:51:45 +01:00
|
|
|
"Node type does not match");
|
2016-08-22 23:09:30 +02:00
|
|
|
static_assert(std::is_same<decltype(*F), NodeRef>::value,
|
2014-11-17 18:51:45 +01:00
|
|
|
"Node type does not match");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CallGraphTest, GraphTraitsSpecialization) {
|
2016-04-14 23:59:01 +02:00
|
|
|
LLVMContext Context;
|
|
|
|
Module M("", Context);
|
2014-11-17 18:51:45 +01:00
|
|
|
CallGraph CG(M);
|
|
|
|
|
|
|
|
canSpecializeGraphTraitsIterators(&CG);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CallGraphTest, GraphTraitsConstSpecialization) {
|
2016-04-14 23:59:01 +02:00
|
|
|
LLVMContext Context;
|
|
|
|
Module M("", Context);
|
2014-11-17 18:51:45 +01:00
|
|
|
CallGraph CG(M);
|
|
|
|
|
|
|
|
canSpecializeGraphTraitsIterators(const_cast<const CallGraph *>(&CG));
|
|
|
|
}
|
|
|
|
}
|