]>
git.proxmox.com Git - rustc.git/blob - src/llvm/tools/llvm-diff/DifferenceEngine.h
1 //===-- DifferenceEngine.h - Module comparator ------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This header defines the interface to the LLVM difference engine,
11 // which structurally compares functions within a module.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TOOLS_LLVM_DIFF_DIFFERENCEENGINE_H
16 #define LLVM_TOOLS_LLVM_DIFF_DIFFERENCEENGINE_H
18 #include "DiffConsumer.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringRef.h"
33 /// A class for performing structural comparisons of LLVM assembly.
34 class DifferenceEngine
{
36 /// A RAII object for recording the current context.
38 Context(DifferenceEngine
&Engine
, Value
*L
, Value
*R
) : Engine(Engine
) {
39 Engine
.consumer
.enterContext(L
, R
);
43 Engine
.consumer
.exitContext();
47 DifferenceEngine
&Engine
;
50 /// An oracle for answering whether two values are equivalent as
53 virtual void anchor();
55 virtual bool operator()(Value
*L
, Value
*R
) = 0;
61 DifferenceEngine(Consumer
&consumer
)
62 : consumer(consumer
), globalValueOracle(nullptr) {}
64 void diff(Module
*L
, Module
*R
);
65 void diff(Function
*L
, Function
*R
);
66 void log(StringRef text
) {
69 LogBuilder
logf(StringRef text
) {
70 return LogBuilder(consumer
, text
);
72 Consumer
& getConsumer() const { return consumer
; }
74 /// Installs an oracle to decide whether two global values are
75 /// equivalent as operands. Without an oracle, global values are
76 /// considered equivalent as operands precisely when they have the
78 void setGlobalValueOracle(Oracle
*oracle
) {
79 globalValueOracle
= oracle
;
82 /// Determines whether two global values are equivalent.
83 bool equivalentAsOperands(GlobalValue
*L
, GlobalValue
*R
);
87 Oracle
*globalValueOracle
;