blob: 07dd1a776f2fc6c9ff5d61bed6d51882910384f5 [file] [log] [blame]
Bill Wendlingb4e6a5d2009-12-18 23:32:53 +00001//===-- llvm/CodeGen/SDNodeOrdering.h - SDNode Ordering ---------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file declares the SDNodeOrdering class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CODEGEN_SDNODEORDERING_H
15#define LLVM_CODEGEN_SDNODEORDERING_H
16
17#include "llvm/ADT/DenseMap.h"
18
19namespace llvm {
20
21/// SDNodeOrdering - Maps a unique (monotonically increasing) value to each
22/// SDNode that roughly corresponds to the ordering of the original LLVM
23/// instruction. This is used for turning off scheduling, because we'll forgo
24/// the normal scheduling algorithms and output the instructions according to
25/// this ordering.
26class SDNodeOrdering {
27 DenseMap<const SDNode*, unsigned> OrderMap;
28
29 void operator=(const SDNodeOrdering&); // Do not implement.
30 SDNodeOrdering(const SDNodeOrdering&); // Do not implement.
31public:
32 SDNodeOrdering() {}
33
34 void add(const SDNode *Node, unsigned O) {
35 assert(O && "Invalid ordering!");
36 OrderMap[Node] = O;
37 }
38 void remove(const SDNode *Node) {
39 DenseMap<const SDNode*, unsigned>::iterator Itr = OrderMap.find(Node);
40 if (Itr != OrderMap.end())
41 OrderMap.erase(Itr);
42 }
43 void clear() {
44 OrderMap.clear();
45 }
46 unsigned getOrder(const SDNode *Node) {
47 unsigned Order = OrderMap[Node];
48 assert(Order && "Node isn't in ordering map!");
49 return Order;
50 }
51};
52
53} // end llvm namespace
54
55#endif