diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:50:12 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:50:12 +0000 |
commit | e6d1592492a3a379186bfb02bd0f4eda0669c0d5 (patch) | |
tree | 599ab169a01f1c86eda9adc774edaedde2f2db5b /lib/Transforms/IPO/Internalize.cpp | |
parent | 1a56a5ead7a2e84bee8240f5f6b033b5f1707154 (diff) |
Diffstat (limited to 'lib/Transforms/IPO/Internalize.cpp')
-rw-r--r-- | lib/Transforms/IPO/Internalize.cpp | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/lib/Transforms/IPO/Internalize.cpp b/lib/Transforms/IPO/Internalize.cpp index a6542d28dfd8..2e269604e379 100644 --- a/lib/Transforms/IPO/Internalize.cpp +++ b/lib/Transforms/IPO/Internalize.cpp @@ -1,9 +1,8 @@ //===-- Internalize.cpp - Mark functions internal -------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// // @@ -28,11 +27,11 @@ #include "llvm/Pass.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/LineIterator.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/Utils/GlobalStatus.h" -#include <fstream> -#include <set> using namespace llvm; #define DEBUG_TYPE "internalize" @@ -73,18 +72,15 @@ private: void LoadFile(StringRef Filename) { // Load the APIFile... - std::ifstream In(Filename.data()); - if (!In.good()) { + ErrorOr<std::unique_ptr<MemoryBuffer>> Buf = + MemoryBuffer::getFile(Filename); + if (!Buf) { errs() << "WARNING: Internalize couldn't load file '" << Filename << "'! Continuing as if it's empty.\n"; return; // Just continue as if the file were empty } - while (In) { - std::string Symbol; - In >> Symbol; - if (!Symbol.empty()) - ExternalNames.insert(Symbol); - } + for (line_iterator I(*Buf->get(), true), E; I != E; ++I) + ExternalNames.insert(*I); } }; } // end anonymous namespace @@ -114,7 +110,7 @@ bool InternalizePass::shouldPreserveGV(const GlobalValue &GV) { } bool InternalizePass::maybeInternalize( - GlobalValue &GV, const std::set<const Comdat *> &ExternalComdats) { + GlobalValue &GV, const DenseSet<const Comdat *> &ExternalComdats) { if (Comdat *C = GV.getComdat()) { if (ExternalComdats.count(C)) return false; @@ -141,7 +137,7 @@ bool InternalizePass::maybeInternalize( // If GV is part of a comdat and is externally visible, keep track of its // comdat so that we don't internalize any of its members. void InternalizePass::checkComdatVisibility( - GlobalValue &GV, std::set<const Comdat *> &ExternalComdats) { + GlobalValue &GV, DenseSet<const Comdat *> &ExternalComdats) { Comdat *C = GV.getComdat(); if (!C) return; @@ -158,7 +154,7 @@ bool InternalizePass::internalizeModule(Module &M, CallGraph *CG) { collectUsedGlobalVariables(M, Used, false); // Collect comdat visiblity information for the module. - std::set<const Comdat *> ExternalComdats; + DenseSet<const Comdat *> ExternalComdats; if (!M.getComdatSymbolTable().empty()) { for (Function &F : M) checkComdatVisibility(F, ExternalComdats); |