19ff542f2cce5bf7bf3cf9f692cf3ec0690ad2b3bJim Laskey//===-- CodeGen/MachineInstr.cpp ------------------------------------------===//
2c6a0a117a63b22ac8f4ae1aaa16a4a4fb57a45f1Jim Laskey//
3c6a0a117a63b22ac8f4ae1aaa16a4a4fb57a45f1Jim Laskey//                     The LLVM Compiler Infrastructure
4c6a0a117a63b22ac8f4ae1aaa16a4a4fb57a45f1Jim Laskey//
54ee451de366474b9c228b4e5fa573795a715216dChris Lattner// This file is distributed under the University of Illinois Open Source
64ee451de366474b9c228b4e5fa573795a715216dChris Lattner// License. See LICENSE.TXT for details.
7c6a0a117a63b22ac8f4ae1aaa16a4a4fb57a45f1Jim Laskey//
8c6a0a117a63b22ac8f4ae1aaa16a4a4fb57a45f1Jim Laskey//===----------------------------------------------------------------------===//
99ff542f2cce5bf7bf3cf9f692cf3ec0690ad2b3bJim Laskey//
109ff542f2cce5bf7bf3cf9f692cf3ec0690ad2b3bJim Laskey// This file contains the machine function pass registry for register allocators
119ff542f2cce5bf7bf3cf9f692cf3ec0690ad2b3bJim Laskey// and instruction schedulers.
129ff542f2cce5bf7bf3cf9f692cf3ec0690ad2b3bJim Laskey//
139ff542f2cce5bf7bf3cf9f692cf3ec0690ad2b3bJim Laskey//===----------------------------------------------------------------------===//
14c6a0a117a63b22ac8f4ae1aaa16a4a4fb57a45f1Jim Laskey
15c6a0a117a63b22ac8f4ae1aaa16a4a4fb57a45f1Jim Laskey#include "llvm/CodeGen/MachinePassRegistry.h"
16c6a0a117a63b22ac8f4ae1aaa16a4a4fb57a45f1Jim Laskey
17c6a0a117a63b22ac8f4ae1aaa16a4a4fb57a45f1Jim Laskeyusing namespace llvm;
18c6a0a117a63b22ac8f4ae1aaa16a4a4fb57a45f1Jim Laskey
192d24e2a396a1d211baaeedf32148a3b657240170David Blaikievoid MachinePassRegistryListener::anchor() { }
20eb577ba3b815a1fa4627b060dd2345d17abf672dJim Laskey
21fc728fbdc2631ce8f343cf9b7292d218fde7419fAndrew Trick/// setDefault - Set the default constructor by name.
22fc728fbdc2631ce8f343cf9b7292d218fde7419fAndrew Trickvoid MachinePassRegistry::setDefault(StringRef Name) {
23dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  MachinePassCtor Ctor = nullptr;
24fc728fbdc2631ce8f343cf9b7292d218fde7419fAndrew Trick  for(MachinePassRegistryNode *R = getList(); R; R = R->getNext()) {
25fc728fbdc2631ce8f343cf9b7292d218fde7419fAndrew Trick    if (R->getName() == Name) {
26fc728fbdc2631ce8f343cf9b7292d218fde7419fAndrew Trick      Ctor = R->getCtor();
27fc728fbdc2631ce8f343cf9b7292d218fde7419fAndrew Trick      break;
28fc728fbdc2631ce8f343cf9b7292d218fde7419fAndrew Trick    }
29fc728fbdc2631ce8f343cf9b7292d218fde7419fAndrew Trick  }
30fc728fbdc2631ce8f343cf9b7292d218fde7419fAndrew Trick  assert(Ctor && "Unregistered pass name");
31fc728fbdc2631ce8f343cf9b7292d218fde7419fAndrew Trick  setDefault(Ctor);
32fc728fbdc2631ce8f343cf9b7292d218fde7419fAndrew Trick}
33fc728fbdc2631ce8f343cf9b7292d218fde7419fAndrew Trick
34eb577ba3b815a1fa4627b060dd2345d17abf672dJim Laskey/// Add - Adds a function pass to the registration list.
35c6a0a117a63b22ac8f4ae1aaa16a4a4fb57a45f1Jim Laskey///
36eb577ba3b815a1fa4627b060dd2345d17abf672dJim Laskeyvoid MachinePassRegistry::Add(MachinePassRegistryNode *Node) {
37eb577ba3b815a1fa4627b060dd2345d17abf672dJim Laskey  Node->setNext(List);
38eb577ba3b815a1fa4627b060dd2345d17abf672dJim Laskey  List = Node;
39eb577ba3b815a1fa4627b060dd2345d17abf672dJim Laskey  if (Listener) Listener->NotifyAdd(Node->getName(),
40eb577ba3b815a1fa4627b060dd2345d17abf672dJim Laskey                                    Node->getCtor(),
41eb577ba3b815a1fa4627b060dd2345d17abf672dJim Laskey                                    Node->getDescription());
42eb577ba3b815a1fa4627b060dd2345d17abf672dJim Laskey}
43c6a0a117a63b22ac8f4ae1aaa16a4a4fb57a45f1Jim Laskey
44c6a0a117a63b22ac8f4ae1aaa16a4a4fb57a45f1Jim Laskey
45eb577ba3b815a1fa4627b060dd2345d17abf672dJim Laskey/// Remove - Removes a function pass from the registration list.
46c6a0a117a63b22ac8f4ae1aaa16a4a4fb57a45f1Jim Laskey///
47eb577ba3b815a1fa4627b060dd2345d17abf672dJim Laskeyvoid MachinePassRegistry::Remove(MachinePassRegistryNode *Node) {
48eb577ba3b815a1fa4627b060dd2345d17abf672dJim Laskey  for (MachinePassRegistryNode **I = &List; *I; I = (*I)->getNextAddress()) {
49eb577ba3b815a1fa4627b060dd2345d17abf672dJim Laskey    if (*I == Node) {
50eb577ba3b815a1fa4627b060dd2345d17abf672dJim Laskey      if (Listener) Listener->NotifyRemove(Node->getName());
51eb577ba3b815a1fa4627b060dd2345d17abf672dJim Laskey      *I = (*I)->getNext();
52eb577ba3b815a1fa4627b060dd2345d17abf672dJim Laskey      break;
53eb577ba3b815a1fa4627b060dd2345d17abf672dJim Laskey    }
54eb577ba3b815a1fa4627b060dd2345d17abf672dJim Laskey  }
55eb577ba3b815a1fa4627b060dd2345d17abf672dJim Laskey}
56