brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 4fe547c Raw
40 lines · cpp
1//===- ReduceSpecialGlobals.cpp - Specialized Delta Pass ------------------===//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-exception6//7//===----------------------------------------------------------------------===//8//9// This file implements a function which calls the Generic Delta pass in order10// to reduce special globals, like @llvm.used, in the provided Module.11//12// For more details about special globals, see13// https://llvm.org/docs/LangRef.html#intrinsic-global-variables14//15//===----------------------------------------------------------------------===//16 17#include "ReduceSpecialGlobals.h"18#include "Utils.h"19#include "llvm/ADT/StringRef.h"20#include "llvm/IR/GlobalValue.h"21 22using namespace llvm;23 24static StringRef SpecialGlobalNames[] = {"llvm.used", "llvm.compiler.used"};25 26/// Removes all special globals aren't inside any of the27/// desired Chunks.28void llvm::reduceSpecialGlobalsDeltaPass(Oracle &O, ReducerWorkItem &WorkItem) {29  Module &Program = WorkItem.getModule();30 31  for (StringRef Name : SpecialGlobalNames) {32    if (auto *Used = Program.getNamedGlobal(Name)) {33      if (!O.shouldKeep()) {34        Used->replaceAllUsesWith(getDefaultValue(Used->getType()));35        Used->eraseFromParent();36      }37    }38  }39}40