1 //===-- DifferenceEngine.h - Module comparator ------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This header defines the interface to the LLVM difference engine,
10 // which structurally compares functions within a module.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TOOLS_LLVM_DIFF_DIFFERENCEENGINE_H
15 #define LLVM_TOOLS_LLVM_DIFF_DIFFERENCEENGINE_H
17 #include "DiffConsumer.h"
19 #include "llvm/ADT/StringRef.h"
31 /// A class for performing structural comparisons of LLVM assembly.
32 class DifferenceEngine
{
34 /// A RAII object for recording the current context.
36 Context(DifferenceEngine
&Engine
, Value
*L
, Value
*R
) : Engine(Engine
) {
37 Engine
.consumer
.enterContext(L
, R
);
41 Engine
.consumer
.exitContext();
45 DifferenceEngine
&Engine
;
48 /// An oracle for answering whether two values are equivalent as
51 virtual void anchor();
53 virtual bool operator()(Value
*L
, Value
*R
) = 0;
59 DifferenceEngine(Consumer
&consumer
)
60 : consumer(consumer
), globalValueOracle(nullptr) {}
62 void diff(Module
*L
, Module
*R
);
63 void diff(Function
*L
, Function
*R
);
64 void log(StringRef text
) {
67 LogBuilder
logf(StringRef text
) {
68 return LogBuilder(consumer
, text
);
70 Consumer
& getConsumer() const { return consumer
; }
72 /// Installs an oracle to decide whether two global values are
73 /// equivalent as operands. Without an oracle, global values are
74 /// considered equivalent as operands precisely when they have the
76 void setGlobalValueOracle(Oracle
*oracle
) {
77 globalValueOracle
= oracle
;
80 /// Determines whether two global values are equivalent.
81 bool equivalentAsOperands(GlobalValue
*L
, GlobalValue
*R
);
85 Oracle
*globalValueOracle
;