Path: blob/main/contrib/llvm-project/llvm/tools/llvm-diff/lib/DifferenceEngine.h
35291 views
//===-- DifferenceEngine.h - Module comparator ------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This header defines the interface to the LLVM difference engine,9// which structurally compares functions within a module.10//11//===----------------------------------------------------------------------===//1213#ifndef LLVM_TOOLS_LLVM_DIFF_DIFFERENCEENGINE_H14#define LLVM_TOOLS_LLVM_DIFF_DIFFERENCEENGINE_H1516#include "DiffConsumer.h"17#include "DiffLog.h"18#include "llvm/ADT/StringRef.h"19#include <utility>2021namespace llvm {22class Function;23class GlobalValue;24class Instruction;25class LLVMContext;26class Module;27class Twine;28class Value;2930/// A class for performing structural comparisons of LLVM assembly.31class DifferenceEngine {32public:33/// A RAII object for recording the current context.34struct Context {35Context(DifferenceEngine &Engine, const Value *L, const Value *R)36: Engine(Engine) {37Engine.consumer.enterContext(L, R);38}3940~Context() {41Engine.consumer.exitContext();42}4344private:45DifferenceEngine &Engine;46};4748/// An oracle for answering whether two values are equivalent as49/// operands.50class Oracle {51virtual void anchor();52public:53virtual bool operator()(const Value *L, const Value *R) = 0;5455protected:56virtual ~Oracle() {}57};5859DifferenceEngine(Consumer &consumer)60: consumer(consumer), globalValueOracle(nullptr) {}6162void diff(const Module *L, const Module *R);63void diff(const Function *L, const Function *R);64void log(StringRef text) {65consumer.log(text);66}67LogBuilder logf(StringRef text) {68return LogBuilder(consumer, text);69}70Consumer& getConsumer() const { return consumer; }7172/// Installs an oracle to decide whether two global values are73/// equivalent as operands. Without an oracle, global values are74/// considered equivalent as operands precisely when they have the75/// same name.76void setGlobalValueOracle(Oracle *oracle) {77globalValueOracle = oracle;78}7980/// Determines whether two global values are equivalent.81bool equivalentAsOperands(const GlobalValue *L, const GlobalValue *R);8283private:84Consumer &consumer;85Oracle *globalValueOracle;86};87}8889#endif909192