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_DIFFERENCE_ENGINE_H_
16 #define _LLVM_DIFFERENCE_ENGINE_H_
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringRef.h"
21 #include "DiffConsumer.h"
34 /// A class for performing structural comparisons of LLVM assembly.
35 class DifferenceEngine
{
37 /// A RAII object for recording the current context.
39 Context(DifferenceEngine
&Engine
, Value
*L
, Value
*R
) : Engine(Engine
) {
40 Engine
.consumer
.enterContext(L
, R
);
44 Engine
.consumer
.exitContext();
48 DifferenceEngine
&Engine
;
51 /// An oracle for answering whether two values are equivalent as
54 virtual bool operator()(Value
*L
, Value
*R
) = 0;
60 DifferenceEngine(LLVMContext
&context
, Consumer
&consumer
)
61 : context(context
), consumer(consumer
), globalValueOracle(0) {}
63 void diff(Module
*L
, Module
*R
);
64 void diff(Function
*L
, 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(GlobalValue
*L
, GlobalValue
*R
);
87 Oracle
*globalValueOracle
;