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
, const Value
*L
, const Value
*R
)
38 Engine
.consumer
.enterContext(L
, R
);
42 Engine
.consumer
.exitContext();
46 DifferenceEngine
&Engine
;
49 /// An oracle for answering whether two values are equivalent as
52 virtual void anchor();
54 virtual bool operator()(const Value
*L
, const Value
*R
) = 0;
60 DifferenceEngine(Consumer
&consumer
)
61 : consumer(consumer
), globalValueOracle(nullptr) {}
63 void diff(const Module
*L
, const Module
*R
);
64 void diff(const Function
*L
, const Function
*R
);
65 void log(StringRef text
) {
68 LogBuilder
logf(StringRef text
) {
69 return LogBuilder(consumer
, text
);
71 Consumer
& getConsumer() const { return consumer
; }
73 /// Installs an oracle to decide whether two global values are
74 /// equivalent as operands. Without an oracle, global values are
75 /// considered equivalent as operands precisely when they have the
77 void setGlobalValueOracle(Oracle
*oracle
) {
78 globalValueOracle
= oracle
;
81 /// Determines whether two global values are equivalent.
82 bool equivalentAsOperands(const GlobalValue
*L
, const GlobalValue
*R
);
86 Oracle
*globalValueOracle
;