1//===-- AssignGUID.cpp - Unique identifier assignment pass ------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file provides a pass which assigns GUID (globally unique identifier)
10// metadata to every GlobalValue in the module, according to its current name,
11// linkage, and originating file. It is idempotent -- if GUID metadata is
12// already present, it does nothing.
13//
14//===----------------------------------------------------------------------===//
15
16#include "llvm/Transforms/Utils/AssignGUID.h"
17
18using namespace llvm;
19
20void AssignGUIDPass::runOnModule(Module &M) {
21 for (auto &GV : M.globals()) {
22 if (GV.isDeclaration())
23 continue;
24 GV.assignGUID();
25 }
26 for (auto &F : M.functions()) {
27 if (F.isDeclaration())
28 continue;
29 F.assignGUID();
30 }
31}
32
33void AssignGUIDPass::assignGUIDForMergedGV(GlobalVariable &GV) {
34 // FIXME: merging adds all the guids of the original GVs. We currently drop
35 // that metadata from GV first, but we may want to remember those later, if
36 // we had a motivation for that. In that case, we need some other metadata
37 // to maintain that association.
38 GV.eraseMetadata(KindID: LLVMContext::MD_guid);
39 GV.assignGUID();
40}
41