1*9880d681SAndroid Build Coastguard Worker //=======- CallGraphTest.cpp - Unit tests for the CG analysis -------------===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker
10*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/CallGraph.h"
11*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/LLVMContext.h"
12*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/Module.h"
13*9880d681SAndroid Build Coastguard Worker #include "gtest/gtest.h"
14*9880d681SAndroid Build Coastguard Worker
15*9880d681SAndroid Build Coastguard Worker using namespace llvm;
16*9880d681SAndroid Build Coastguard Worker
17*9880d681SAndroid Build Coastguard Worker namespace {
18*9880d681SAndroid Build Coastguard Worker
canSpecializeGraphTraitsIterators(Ty * G)19*9880d681SAndroid Build Coastguard Worker template <typename Ty> void canSpecializeGraphTraitsIterators(Ty *G) {
20*9880d681SAndroid Build Coastguard Worker typedef typename GraphTraits<Ty *>::NodeType NodeTy;
21*9880d681SAndroid Build Coastguard Worker
22*9880d681SAndroid Build Coastguard Worker auto I = GraphTraits<Ty *>::nodes_begin(G);
23*9880d681SAndroid Build Coastguard Worker auto E = GraphTraits<Ty *>::nodes_end(G);
24*9880d681SAndroid Build Coastguard Worker auto X = ++I;
25*9880d681SAndroid Build Coastguard Worker
26*9880d681SAndroid Build Coastguard Worker // Should be able to iterate over all nodes of the graph.
27*9880d681SAndroid Build Coastguard Worker static_assert(std::is_same<decltype(*I), NodeTy &>::value,
28*9880d681SAndroid Build Coastguard Worker "Node type does not match");
29*9880d681SAndroid Build Coastguard Worker static_assert(std::is_same<decltype(*X), NodeTy &>::value,
30*9880d681SAndroid Build Coastguard Worker "Node type does not match");
31*9880d681SAndroid Build Coastguard Worker static_assert(std::is_same<decltype(*E), NodeTy &>::value,
32*9880d681SAndroid Build Coastguard Worker "Node type does not match");
33*9880d681SAndroid Build Coastguard Worker
34*9880d681SAndroid Build Coastguard Worker NodeTy *N = GraphTraits<Ty *>::getEntryNode(G);
35*9880d681SAndroid Build Coastguard Worker
36*9880d681SAndroid Build Coastguard Worker auto S = GraphTraits<NodeTy *>::child_begin(N);
37*9880d681SAndroid Build Coastguard Worker auto F = GraphTraits<NodeTy *>::child_end(N);
38*9880d681SAndroid Build Coastguard Worker
39*9880d681SAndroid Build Coastguard Worker // Should be able to iterate over immediate successors of a node.
40*9880d681SAndroid Build Coastguard Worker static_assert(std::is_same<decltype(*S), NodeTy *>::value,
41*9880d681SAndroid Build Coastguard Worker "Node type does not match");
42*9880d681SAndroid Build Coastguard Worker static_assert(std::is_same<decltype(*F), NodeTy *>::value,
43*9880d681SAndroid Build Coastguard Worker "Node type does not match");
44*9880d681SAndroid Build Coastguard Worker }
45*9880d681SAndroid Build Coastguard Worker
TEST(CallGraphTest,GraphTraitsSpecialization)46*9880d681SAndroid Build Coastguard Worker TEST(CallGraphTest, GraphTraitsSpecialization) {
47*9880d681SAndroid Build Coastguard Worker LLVMContext Context;
48*9880d681SAndroid Build Coastguard Worker Module M("", Context);
49*9880d681SAndroid Build Coastguard Worker CallGraph CG(M);
50*9880d681SAndroid Build Coastguard Worker
51*9880d681SAndroid Build Coastguard Worker canSpecializeGraphTraitsIterators(&CG);
52*9880d681SAndroid Build Coastguard Worker }
53*9880d681SAndroid Build Coastguard Worker
TEST(CallGraphTest,GraphTraitsConstSpecialization)54*9880d681SAndroid Build Coastguard Worker TEST(CallGraphTest, GraphTraitsConstSpecialization) {
55*9880d681SAndroid Build Coastguard Worker LLVMContext Context;
56*9880d681SAndroid Build Coastguard Worker Module M("", Context);
57*9880d681SAndroid Build Coastguard Worker CallGraph CG(M);
58*9880d681SAndroid Build Coastguard Worker
59*9880d681SAndroid Build Coastguard Worker canSpecializeGraphTraitsIterators(const_cast<const CallGraph *>(&CG));
60*9880d681SAndroid Build Coastguard Worker }
61*9880d681SAndroid Build Coastguard Worker }
62