64d528e56d065a95388380dfa295d3860663787a
[oota-llvm.git] / include / llvm / Analysis / ValueNumbering.h
1 //===- llvm/Analysis/ValueNumbering.h - Value #'ing Interface ---*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the abstract ValueNumbering interface, which is used as the
11 // common interface used by all clients of value numbering information, and
12 // implemented by all value numbering implementations.
13 //
14 // Implementations of this interface must implement the various virtual methods,
15 // which automatically provides functionality for the entire suite of client
16 // APIs.
17 //
18 //===----------------------------------------------------------------------===//
19
20 #ifndef LLVM_ANALYSIS_VALUE_NUMBERING_H
21 #define LLVM_ANALYSIS_VALUE_NUMBERING_H
22
23 #include <vector>
24 #include "llvm/Pass.h"
25
26 namespace llvm {
27
28 class Value;
29 class Instruction;
30
31 struct ValueNumbering {
32   static char ID; // Class identification, replacement for typeinfo
33   virtual ~ValueNumbering();    // We want to be subclassed
34
35   /// getEqualNumberNodes - Return nodes with the same value number as the
36   /// specified Value.  This fills in the argument vector with any equal values.
37   ///
38   virtual void getEqualNumberNodes(Value *V1,
39                                    std::vector<Value*> &RetVals) const = 0;
40
41   ///===-------------------------------------------------------------------===//
42   /// Interfaces to update value numbering analysis information as the client
43   /// changes the program.
44   ///
45
46   /// deleteValue - This method should be called whenever an LLVM Value is
47   /// deleted from the program, for example when an instruction is found to be
48   /// redundant and is eliminated.
49   ///
50   virtual void deleteValue(Value *V) {}
51
52   /// copyValue - This method should be used whenever a preexisting value in the
53   /// program is copied or cloned, introducing a new value.  Note that analysis
54   /// implementations should tolerate clients that use this method to introduce
55   /// the same value multiple times: if the analysis already knows about a
56   /// value, it should ignore the request.
57   ///
58   virtual void copyValue(Value *From, Value *To) {}
59
60   /// replaceWithNewValue - This method is the obvious combination of the two
61   /// above, and it provided as a helper to simplify client code.
62   ///
63   void replaceWithNewValue(Value *Old, Value *New) {
64     copyValue(Old, New);
65     deleteValue(Old);
66   }
67 };
68
69 } // End llvm namespace
70
71 // Force any file including this header to get the implementation as well
72 FORCE_DEFINING_FILE_TO_BE_LINKED(BasicValueNumbering)
73
74 #endif