Use BranchProbability instead of floating points in IfConverter.
[llvm/stm8.git] / tools / llvm-diff / DiffConsumer.h
blobb95d42713a643c5d818f8e21b0f1cb934905d53e
1 //===-- DiffConsumer.h - Difference Consumer --------------------*- 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 header defines the interface to the LLVM difference Consumer
12 //===----------------------------------------------------------------------===//
14 #ifndef _LLVM_DIFFCONSUMER_H_
15 #define _LLVM_DIFFCONSUMER_H_
17 #include "DiffLog.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/Support/raw_ostream.h"
23 #include "llvm/Support/Casting.h"
25 namespace llvm {
26 class Module;
27 class Value;
28 class Function;
30 /// The interface for consumers of difference data.
31 class Consumer {
32 public:
33 /// Record that a local context has been entered. Left and
34 /// Right are IR "containers" of some sort which are being
35 /// considered for structural equivalence: global variables,
36 /// functions, blocks, instructions, etc.
37 virtual void enterContext(Value *Left, Value *Right) = 0;
39 /// Record that a local context has been exited.
40 virtual void exitContext() = 0;
42 /// Record a difference within the current context.
43 virtual void log(StringRef Text) = 0;
45 /// Record a formatted difference within the current context.
46 virtual void logf(const LogBuilder &Log) = 0;
48 /// Record a line-by-line instruction diff.
49 virtual void logd(const DiffLogBuilder &Log) = 0;
51 protected:
52 virtual ~Consumer() {}
55 class DiffConsumer : public Consumer {
56 private:
57 struct DiffContext {
58 DiffContext(Value *L, Value *R)
59 : L(L), R(R), Differences(false), IsFunction(isa<Function>(L)) {}
60 Value *L;
61 Value *R;
62 bool Differences;
63 bool IsFunction;
64 DenseMap<Value*,unsigned> LNumbering;
65 DenseMap<Value*,unsigned> RNumbering;
68 raw_ostream &out;
69 Module *LModule;
70 Module *RModule;
71 SmallVector<DiffContext, 5> contexts;
72 bool Differences;
73 unsigned Indent;
75 void printValue(Value *V, bool isL);
76 void header();
77 void indent();
79 public:
80 DiffConsumer(Module *L, Module *R)
81 : out(errs()), LModule(L), RModule(R), Differences(false), Indent(0) {}
83 bool hadDifferences() const;
84 void enterContext(Value *L, Value *R);
85 void exitContext();
86 void log(StringRef text);
87 void logf(const LogBuilder &Log);
88 void logd(const DiffLogBuilder &Log);
92 #endif