blob: 7e7b8974be4880c34ef9eb4dae9e7b427a16e5b4 [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
Bill Wendling29b49fc2009-12-19 00:05:07 +000021class SDNode;
22
Bill Wendlingb4e6a5d2009-12-18 23:32:53 +000023/// SDNodeOrdering - Maps a unique (monotonically increasing) value to each
24/// SDNode that roughly corresponds to the ordering of the original LLVM
25/// instruction. This is used for turning off scheduling, because we'll forgo
26/// the normal scheduling algorithms and output the instructions according to
27/// this ordering.
28class SDNodeOrdering {
29 DenseMap<const SDNode*, unsigned> OrderMap;
30
Craig Topperc2945e42012-09-18 02:01:41 +000031 void operator=(const SDNodeOrdering&) LLVM_DELETED_FUNCTION;
32 SDNodeOrdering(const SDNodeOrdering&) LLVM_DELETED_FUNCTION;
Bill Wendlingb4e6a5d2009-12-18 23:32:53 +000033public:
34 SDNodeOrdering() {}
35
Justin Holewinski93c1fd42013-03-20 23:10:59 +000036 void add(const SDNode *Node, unsigned NewOrder) {
37 unsigned &OldOrder = OrderMap[Node];
38 if (OldOrder == 0 || (OldOrder > 0 && NewOrder < OldOrder))
39 OldOrder = NewOrder;
Bill Wendlingb4e6a5d2009-12-18 23:32:53 +000040 }
41 void remove(const SDNode *Node) {
42 DenseMap<const SDNode*, unsigned>::iterator Itr = OrderMap.find(Node);
43 if (Itr != OrderMap.end())
44 OrderMap.erase(Itr);
45 }
46 void clear() {
47 OrderMap.clear();
48 }
49 unsigned getOrder(const SDNode *Node) {
Bill Wendling3ea58b62009-12-22 21:35:02 +000050 return OrderMap[Node];
Bill Wendlingb4e6a5d2009-12-18 23:32:53 +000051 }
52};
53
54} // end llvm namespace
55
56#endif