//===- FunctionComparator.h - Function Comparator ---------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file defines the FunctionComparator and GlobalNumberState classes which // are used by the MergeFunctions pass for comparing functions. // //===----------------------------------------------------------------------===// #ifndef LLVM_TRANSFORMS_UTILS_FUNCTIONCOMPARATOR_H #define LLVM_TRANSFORMS_UTILS_FUNCTIONCOMPARATOR_H #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Operator.h" #include "llvm/IR/ValueMap.h" #include "llvm/Support/AtomicOrdering.h" #include "llvm/Support/Casting.h" #include <cstdint> #include <tuple> namespace llvm { class APFloat; class AttributeList; class APInt; class BasicBlock; class Constant; class Function; class GlobalValue; class InlineAsm; class Instruction; class MDNode; class Type; class Value; /// GlobalNumberState assigns an integer to each global value in the program, /// which is used by the comparison routine to order references to globals. This /// state must be preserved throughout the pass, because Functions and other /// globals need to maintain their relative order. Globals are assigned a number /// when they are first visited. This order is deterministic, and so the /// assigned numbers are as well. When two functions are merged, neither number /// is updated. If the symbols are weak, this would be incorrect. If they are /// strong, then one will be replaced at all references to the other, and so /// direct callsites will now see one or the other symbol, and no update is /// necessary. Note that if we were guaranteed unique names, we could just /// compare those, but this would not work for stripped bitcodes or for those /// few symbols without a name. class GlobalNumberState { … }; /// FunctionComparator - Compares two functions to determine whether or not /// they will generate machine code with the same behaviour. DataLayout is /// used if available. The comparator always fails conservatively (erring on the /// side of claiming that two functions are different). class FunctionComparator { … }; } // end namespace llvm #endif // LLVM_TRANSFORMS_UTILS_FUNCTIONCOMPARATOR_H