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#include "llvm/Support/Debug.h"
18
19using namespace llvm;
20
21void AssignGUIDPass::runOnModule(Module &M) {
22 for (auto &GV : M.globals()) {
23 if (GV.isDeclaration())
24 continue;
25 GV.assignGUID();
26 }
27 for (auto &F : M.functions()) {
28 if (F.isDeclaration())
29 continue;
30 F.assignGUID();
31 }
32}
33
34void AssignGUIDPass::assignGUIDForMergedGV(GlobalVariable &GV) {
35 // FIXME: merging adds all the guids of the original GVs. We currently drop
36 // that metadata from GV first, but we may want to remember those later, if
37 // we had a motivation for that. In that case, we need some other metadata
38 // to maintain that association.
39 GV.eraseMetadata(KindID: LLVMContext::MD_guid);
40 GV.assignGUID();
41}
42