2015-12-10 15:19:35 +01:00
|
|
|
//===- IRMover.h ------------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// 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
|
2015-12-10 15:19:35 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LINKER_IRMOVER_H
|
|
|
|
#define LLVM_LINKER_IRMOVER_H
|
|
|
|
|
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2015-12-15 00:39:05 +01:00
|
|
|
#include <functional>
|
2015-12-10 15:19:35 +01:00
|
|
|
|
|
|
|
namespace llvm {
|
2016-05-27 07:21:35 +02:00
|
|
|
class Error;
|
2015-12-10 15:19:35 +01:00
|
|
|
class GlobalValue;
|
2016-04-18 01:30:31 +02:00
|
|
|
class Metadata;
|
2015-12-10 15:19:35 +01:00
|
|
|
class Module;
|
|
|
|
class StructType;
|
2016-04-18 01:30:31 +02:00
|
|
|
class TrackingMDRef;
|
2015-12-10 15:19:35 +01:00
|
|
|
class Type;
|
|
|
|
|
|
|
|
class IRMover {
|
|
|
|
struct StructTypeKeyInfo {
|
|
|
|
struct KeyTy {
|
|
|
|
ArrayRef<Type *> ETypes;
|
|
|
|
bool IsPacked;
|
|
|
|
KeyTy(ArrayRef<Type *> E, bool P);
|
|
|
|
KeyTy(const StructType *ST);
|
|
|
|
bool operator==(const KeyTy &that) const;
|
|
|
|
bool operator!=(const KeyTy &that) const;
|
|
|
|
};
|
|
|
|
static StructType *getEmptyKey();
|
|
|
|
static StructType *getTombstoneKey();
|
|
|
|
static unsigned getHashValue(const KeyTy &Key);
|
|
|
|
static unsigned getHashValue(const StructType *ST);
|
|
|
|
static bool isEqual(const KeyTy &LHS, const StructType *RHS);
|
|
|
|
static bool isEqual(const StructType *LHS, const StructType *RHS);
|
|
|
|
};
|
|
|
|
|
2016-04-18 01:30:31 +02:00
|
|
|
/// Type of the Metadata map in \a ValueToValueMapTy.
|
|
|
|
typedef DenseMap<const Metadata *, TrackingMDRef> MDMapT;
|
|
|
|
|
2015-12-10 15:19:35 +01:00
|
|
|
public:
|
|
|
|
class IdentifiedStructTypeSet {
|
|
|
|
// The set of opaque types is the composite module.
|
|
|
|
DenseSet<StructType *> OpaqueStructTypes;
|
|
|
|
|
2018-02-21 21:12:18 +01:00
|
|
|
// The set of identified but non opaque structures in the composite module.
|
|
|
|
DenseSet<StructType *, StructTypeKeyInfo> NonOpaqueStructTypes;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void addNonOpaque(StructType *Ty);
|
|
|
|
void switchToNonOpaque(StructType *Ty);
|
|
|
|
void addOpaque(StructType *Ty);
|
|
|
|
StructType *findNonOpaque(ArrayRef<Type *> ETypes, bool IsPacked);
|
|
|
|
bool hasType(StructType *Ty);
|
|
|
|
};
|
|
|
|
|
2015-12-15 00:17:03 +01:00
|
|
|
IRMover(Module &M);
|
2015-12-10 15:19:35 +01:00
|
|
|
|
|
|
|
typedef std::function<void(GlobalValue &)> ValueAdder;
|
2016-03-11 23:19:06 +01:00
|
|
|
|
|
|
|
/// Move in the provide values in \p ValuesToLink from \p Src.
|
|
|
|
///
|
|
|
|
/// - \p AddLazyFor is a call back that the IRMover will call when a global
|
|
|
|
/// value is referenced by one of the ValuesToLink (transitively) but was
|
|
|
|
/// not present in ValuesToLink. The GlobalValue and a ValueAdder callback
|
|
|
|
/// are passed as an argument, and the callback is expected to be called
|
|
|
|
/// if the GlobalValue needs to be added to the \p ValuesToLink and linked.
|
2016-12-12 17:09:30 +01:00
|
|
|
/// - \p IsPerformingImport is true when this IR link is to perform ThinLTO
|
|
|
|
/// function importing from Src.
|
2016-05-27 07:21:35 +02:00
|
|
|
Error move(std::unique_ptr<Module> Src, ArrayRef<GlobalValue *> ValuesToLink,
|
2016-10-12 20:39:29 +02:00
|
|
|
std::function<void(GlobalValue &GV, ValueAdder Add)> AddLazyFor,
|
2017-02-03 18:01:14 +01:00
|
|
|
bool IsPerformingImport);
|
2015-12-10 15:19:35 +01:00
|
|
|
Module &getModule() { return Composite; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Module &Composite;
|
|
|
|
IdentifiedStructTypeSet IdentifiedStructTypes;
|
2016-04-18 01:30:31 +02:00
|
|
|
MDMapT SharedMDs; ///< A Metadata map to use for all calls to \a move().
|
2015-12-10 15:19:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|