[llvm] r267319 - Reorganize GlobalValueSummary with a "Flags" bitfield.

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 24 07:32:36 PDT 2016


> On 2016-Apr-23, at 20:18, Mehdi Amini via llvm-commits <llvm-commits at lists.llvm.org> wrote:
> 
> Modified: llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h?rev=267319&r1=267318&r2=267319&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h (original)
> +++ llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h Sat Apr 23 22:18:18 2016
> @@ -92,6 +92,22 @@ public:
>   /// \brief Sububclass discriminator (for dyn_cast<> et al.)
>   enum SummaryKind { AliasKind, FunctionKind, GlobalVarKind };
> 
> +  /// Group flags (Linkage, hasSection, isOptSize, etc.) as a bitfield.
> +  struct GVFlags {
> +    /// \brief The linkage type of the associated global value.
> +    ///
> +    /// One use is to flag values that have local linkage types and need to
> +    /// have module identifier appended before placing into the combined
> +    /// index, to disambiguate from other values with the same name.
> +    /// In the future this will be used to update and optimize linkage
> +    /// types based on global summary-based analysis.
> +    GlobalValue::LinkageTypes Linkage : 4;

Most bitfields do different things on MSVC than one expects.  Enums have
special portability concerns because:

  - On MSVC, enums are signed by default.
  - On MSVC, bitfields of signed integers cut off the sign bit.

You should just use `unsigned Linkage : 4` here.  Fixed in r267342.

> +
> +    /// Convenience Constructors
> +    explicit GVFlags(GlobalValue::LinkageTypes Linkage) : Linkage(Linkage) {}
> +    GVFlags(const GlobalValue &GV) : Linkage(GV.getLinkage()) {}
> +  };
> +
> private:
>   /// Kind of summary for use in dyn_cast<> et al.
>   SummaryKind Kind;
> @@ -110,14 +126,7 @@ private:
>   /// module path string table.
>   StringRef ModulePath;
> 
> -  /// \brief The linkage type of the associated global value.
> -  ///
> -  /// One use is to flag values that have local linkage types and need to
> -  /// have module identifier appended before placing into the combined
> -  /// index, to disambiguate from other values with the same name.
> -  /// In the future this will be used to update and optimize linkage
> -  /// types based on global summary-based analysis.
> -  GlobalValue::LinkageTypes Linkage;
> +  GVFlags Flags;
> 
>   /// List of values referenced by this global value's definition
>   /// (either by the initializer of a global variable, or referenced
> @@ -127,8 +136,7 @@ private:
> 
> protected:
>   /// GlobalValueSummary constructor.
> -  GlobalValueSummary(SummaryKind K, GlobalValue::LinkageTypes Linkage)
> -      : Kind(K), Linkage(Linkage) {}
> +  GlobalValueSummary(SummaryKind K, GVFlags Flags) : Kind(K), Flags(Flags) {}
> 
> public:
>   virtual ~GlobalValueSummary() = default;
> @@ -150,8 +158,11 @@ public:
>   /// Get the path to the module containing this function.
>   StringRef modulePath() const { return ModulePath; }
> 
> +  /// Get the flags for this GlobalValue (see \p struct GVFlags).
> +  GVFlags flags() { return Flags; }
> +
>   /// Return linkage type recorded for this global value.
> -  GlobalValue::LinkageTypes linkage() const { return Linkage; }
> +  GlobalValue::LinkageTypes linkage() const { return Flags.Linkage; }
> 
>   /// Record a reference from this global value to the global value identified
>   /// by \p RefGUID.
> @@ -179,8 +190,7 @@ class AliasSummary : public GlobalValueS
> 
> public:
>   /// Summary constructors.
> -  AliasSummary(GlobalValue::LinkageTypes Linkage)
> -      : GlobalValueSummary(AliasKind, Linkage) {}
> +  AliasSummary(GVFlags Flags) : GlobalValueSummary(AliasKind, Flags) {}
> 
>   /// Check if this is an alias summary.
>   static bool classof(const GlobalValueSummary *GVS) {
> @@ -216,8 +226,8 @@ private:
> 
> public:
>   /// Summary constructors.
> -  FunctionSummary(GlobalValue::LinkageTypes Linkage, unsigned NumInsts)
> -      : GlobalValueSummary(FunctionKind, Linkage), InstCount(NumInsts) {}
> +  FunctionSummary(GVFlags Flags, unsigned NumInsts)
> +      : GlobalValueSummary(FunctionKind, Flags), InstCount(NumInsts) {}
> 
>   /// Check if this is a function summary.
>   static bool classof(const GlobalValueSummary *GVS) {
> @@ -263,8 +273,7 @@ class GlobalVarSummary : public GlobalVa
> 
> public:
>   /// Summary constructors.
> -  GlobalVarSummary(GlobalValue::LinkageTypes Linkage)
> -      : GlobalValueSummary(GlobalVarKind, Linkage) {}
> +  GlobalVarSummary(GVFlags Flags) : GlobalValueSummary(GlobalVarKind, Flags) {}
> 
>   /// Check if this is a global variable summary.
>   static bool classof(const GlobalValueSummary *GVS) {
> 



More information about the llvm-commits mailing list