|
| 1 | +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +use syntax::ast::NodeId; |
| 12 | +use syntax::symbol::InternedString; |
| 13 | +use ty::Instance; |
| 14 | +use util::nodemap::FxHashMap; |
| 15 | + |
| 16 | +#[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)] |
| 17 | +pub enum TransItem<'tcx> { |
| 18 | + Fn(Instance<'tcx>), |
| 19 | + Static(NodeId), |
| 20 | + GlobalAsm(NodeId), |
| 21 | +} |
| 22 | + |
| 23 | +pub struct CodegenUnit<'tcx> { |
| 24 | + /// A name for this CGU. Incremental compilation requires that |
| 25 | + /// name be unique amongst **all** crates. Therefore, it should |
| 26 | + /// contain something unique to this crate (e.g., a module path) |
| 27 | + /// as well as the crate name and disambiguator. |
| 28 | + name: InternedString, |
| 29 | + items: FxHashMap<TransItem<'tcx>, (Linkage, Visibility)>, |
| 30 | +} |
| 31 | + |
| 32 | +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] |
| 33 | +pub enum Linkage { |
| 34 | + External, |
| 35 | + AvailableExternally, |
| 36 | + LinkOnceAny, |
| 37 | + LinkOnceODR, |
| 38 | + WeakAny, |
| 39 | + WeakODR, |
| 40 | + Appending, |
| 41 | + Internal, |
| 42 | + Private, |
| 43 | + ExternalWeak, |
| 44 | + Common, |
| 45 | +} |
| 46 | + |
| 47 | +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] |
| 48 | +pub enum Visibility { |
| 49 | + Default, |
| 50 | + Hidden, |
| 51 | + Protected, |
| 52 | +} |
| 53 | + |
| 54 | +impl<'tcx> CodegenUnit<'tcx> { |
| 55 | + pub fn new(name: InternedString) -> CodegenUnit<'tcx> { |
| 56 | + CodegenUnit { |
| 57 | + name: name, |
| 58 | + items: FxHashMap(), |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + pub fn name(&self) -> &InternedString { |
| 63 | + &self.name |
| 64 | + } |
| 65 | + |
| 66 | + pub fn set_name(&mut self, name: InternedString) { |
| 67 | + self.name = name; |
| 68 | + } |
| 69 | + |
| 70 | + pub fn items(&self) -> &FxHashMap<TransItem<'tcx>, (Linkage, Visibility)> { |
| 71 | + &self.items |
| 72 | + } |
| 73 | + |
| 74 | + pub fn items_mut(&mut self) |
| 75 | + -> &mut FxHashMap<TransItem<'tcx>, (Linkage, Visibility)> |
| 76 | + { |
| 77 | + &mut self.items |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +#[derive(Clone, Default)] |
| 82 | +pub struct Stats { |
| 83 | + pub n_glues_created: usize, |
| 84 | + pub n_null_glues: usize, |
| 85 | + pub n_real_glues: usize, |
| 86 | + pub n_fns: usize, |
| 87 | + pub n_inlines: usize, |
| 88 | + pub n_closures: usize, |
| 89 | + pub n_llvm_insns: usize, |
| 90 | + pub llvm_insns: FxHashMap<String, usize>, |
| 91 | + // (ident, llvm-instructions) |
| 92 | + pub fn_stats: Vec<(String, usize)>, |
| 93 | +} |
| 94 | + |
| 95 | +impl Stats { |
| 96 | + pub fn extend(&mut self, stats: Stats) { |
| 97 | + self.n_glues_created += stats.n_glues_created; |
| 98 | + self.n_null_glues += stats.n_null_glues; |
| 99 | + self.n_real_glues += stats.n_real_glues; |
| 100 | + self.n_fns += stats.n_fns; |
| 101 | + self.n_inlines += stats.n_inlines; |
| 102 | + self.n_closures += stats.n_closures; |
| 103 | + self.n_llvm_insns += stats.n_llvm_insns; |
| 104 | + |
| 105 | + for (k, v) in stats.llvm_insns { |
| 106 | + *self.llvm_insns.entry(k).or_insert(0) += v; |
| 107 | + } |
| 108 | + self.fn_stats.extend(stats.fn_stats); |
| 109 | + } |
| 110 | +} |
0 commit comments