IncludeGuardian created this revision. IncludeGuardian added a reviewer: aaron.ballman. Herald added subscribers: mtrofin, Enna1, ormris, foad, jdoerfert, kerbowa, hiraditya, jvesely, arsenm, qcolombet, MatzeB. Herald added a project: All. IncludeGuardian requested review of this revision. Herald added projects: clang, LLVM. Herald added subscribers: llvm-commits, cfe-commits.
Move `AttributeMask` out of `llvm/IR/Attributes.h` to a new file `llvm/IR/AttributeMask.h`. After doing this we can remove the `#include <bitset>` and `#include <set>` directives from `Attributes.h`. Since there are many headers including `Attributes.h`, but not needing the definition of `AttributeMask`, this causes unnecessary bloating of the translation units and slows down compilation. Additionally, the `llvm/ADT/SmallString.h` include directive was not needed and has been removed. This commit adds the include directive for `llvm/IR/AttributeMask.h` to the handful of source files that need to see the definition. This reduces the total number of preprocessing tokens across the LLVM source files in lib from (roughly) 1,917,509,187 to 1,902,982,273 - a reduction of ~0.76%. This should result in a small improvement in compilation time. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D153728 Files: clang/lib/CodeGen/CGCall.cpp clang/lib/CodeGen/CodeGenModule.cpp llvm/include/llvm/IR/AttributeMask.h llvm/include/llvm/IR/Attributes.h llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp llvm/lib/Bitcode/Reader/BitcodeReader.cpp llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp llvm/lib/IR/Attributes.cpp llvm/lib/IR/AutoUpgrade.cpp llvm/lib/IR/Instruction.cpp llvm/lib/IR/Verifier.cpp llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp llvm/lib/Target/DirectX/DXILPrepare.cpp llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp llvm/lib/Transforms/IPO/SCCP.cpp llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp llvm/lib/Transforms/Utils/CallPromotionUtils.cpp llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp llvm/tools/llvm-reduce/deltas/ReduceInstructions.cpp llvm/unittests/IR/AttributesTest.cpp
Index: llvm/unittests/IR/AttributesTest.cpp =================================================================== --- llvm/unittests/IR/AttributesTest.cpp +++ llvm/unittests/IR/AttributesTest.cpp @@ -8,6 +8,7 @@ #include "llvm/IR/Attributes.h" #include "llvm/AsmParser/Parser.h" +#include "llvm/IR/AttributeMask.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/LLVMContext.h" Index: llvm/tools/llvm-reduce/deltas/ReduceInstructions.cpp =================================================================== --- llvm/tools/llvm-reduce/deltas/ReduceInstructions.cpp +++ llvm/tools/llvm-reduce/deltas/ReduceInstructions.cpp @@ -14,6 +14,7 @@ #include "ReduceInstructions.h" #include "Utils.h" #include "llvm/IR/Constants.h" +#include <set> using namespace llvm; Index: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp =================================================================== --- llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -19,6 +19,7 @@ #include "llvm/Analysis/Loads.h" #include "llvm/Analysis/OptimizationRemarkEmitter.h" #include "llvm/Analysis/ValueTracking.h" +#include "llvm/IR/AttributeMask.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/Function.h" #include "llvm/IR/IRBuilder.h" Index: llvm/lib/Transforms/Utils/CallPromotionUtils.cpp =================================================================== --- llvm/lib/Transforms/Utils/CallPromotionUtils.cpp +++ llvm/lib/Transforms/Utils/CallPromotionUtils.cpp @@ -14,6 +14,7 @@ #include "llvm/Transforms/Utils/CallPromotionUtils.h" #include "llvm/Analysis/Loads.h" #include "llvm/Analysis/TypeMetadataUtils.h" +#include "llvm/IR/AttributeMask.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Instructions.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" Index: llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp =================================================================== --- llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp +++ llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp @@ -27,6 +27,7 @@ #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/IR/Argument.h" +#include "llvm/IR/AttributeMask.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/CallingConv.h" Index: llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -160,6 +160,7 @@ #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/IR/Argument.h" +#include "llvm/IR/AttributeMask.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/CallingConv.h" Index: llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp @@ -73,6 +73,7 @@ #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/IR/Argument.h" +#include "llvm/IR/AttributeMask.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constant.h" Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -27,6 +27,7 @@ #include "llvm/Analysis/MemoryBuiltins.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/Analysis/VectorUtils.h" +#include "llvm/IR/AttributeMask.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constant.h" Index: llvm/lib/Transforms/IPO/SCCP.cpp =================================================================== --- llvm/lib/Transforms/IPO/SCCP.cpp +++ llvm/lib/Transforms/IPO/SCCP.cpp @@ -20,6 +20,7 @@ #include "llvm/Analysis/ValueLattice.h" #include "llvm/Analysis/ValueLatticeUtils.h" #include "llvm/Analysis/ValueTracking.h" +#include "llvm/IR/AttributeMask.h" #include "llvm/IR/Constants.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/Support/CommandLine.h" Index: llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp =================================================================== --- llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -16,9 +16,11 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Transforms/IPO/DeadArgumentElimination.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" #include "llvm/IR/Argument.h" +#include "llvm/IR/AttributeMask.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constants.h" @@ -43,7 +45,6 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/IPO.h" -#include "llvm/Transforms/IPO/DeadArgumentElimination.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include <cassert> #include <utility> Index: llvm/lib/Target/DirectX/DXILPrepare.cpp =================================================================== --- llvm/lib/Target/DirectX/DXILPrepare.cpp +++ llvm/lib/Target/DirectX/DXILPrepare.cpp @@ -16,6 +16,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/CodeGen/Passes.h" +#include "llvm/IR/AttributeMask.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/Module.h" Index: llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp +++ llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp @@ -46,6 +46,7 @@ #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/Statistic.h" #include "llvm/Analysis/MemoryDependenceAnalysis.h" +#include "llvm/IR/AttributeMask.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Instructions.h" #include "llvm/InitializePasses.h" Index: llvm/lib/IR/Verifier.cpp =================================================================== --- llvm/lib/IR/Verifier.cpp +++ llvm/lib/IR/Verifier.cpp @@ -58,6 +58,7 @@ #include "llvm/ADT/Twine.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/IR/Argument.h" +#include "llvm/IR/AttributeMask.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/CFG.h" Index: llvm/lib/IR/Instruction.cpp =================================================================== --- llvm/lib/IR/Instruction.cpp +++ llvm/lib/IR/Instruction.cpp @@ -12,6 +12,7 @@ #include "llvm/IR/Instruction.h" #include "llvm/ADT/DenseSet.h" +#include "llvm/IR/AttributeMask.h" #include "llvm/IR/Constants.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/IntrinsicInst.h" Index: llvm/lib/IR/AutoUpgrade.cpp =================================================================== --- llvm/lib/IR/AutoUpgrade.cpp +++ llvm/lib/IR/AutoUpgrade.cpp @@ -16,6 +16,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/BinaryFormat/Dwarf.h" +#include "llvm/IR/AttributeMask.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DebugInfo.h" #include "llvm/IR/DebugInfoMetadata.h" Index: llvm/lib/IR/Attributes.cpp =================================================================== --- llvm/lib/IR/Attributes.cpp +++ llvm/lib/IR/Attributes.cpp @@ -23,6 +23,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Config/llvm-config.h" +#include "llvm/IR/AttributeMask.h" #include "llvm/IR/Function.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Type.h" Index: llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp =================================================================== --- llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp +++ llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp @@ -39,6 +39,7 @@ #include "llvm/Support/ErrorHandling.h" #include <array> +#include <bitset> #include <memory> using namespace llvm; Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp =================================================================== --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -23,6 +23,7 @@ #include "llvm/Bitstream/BitstreamReader.h" #include "llvm/Config/llvm-config.h" #include "llvm/IR/Argument.h" +#include "llvm/IR/AttributeMask.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/AutoUpgrade.h" #include "llvm/IR/BasicBlock.h" Index: llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp =================================================================== --- llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp +++ llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp @@ -14,6 +14,7 @@ #include "llvm/ADT/APInt.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SCCIterator.h" +#include "llvm/ADT/SmallString.h" #include "llvm/Config/llvm-config.h" #include "llvm/IR/Function.h" #include "llvm/Support/BlockFrequency.h" Index: llvm/include/llvm/IR/Attributes.h =================================================================== --- llvm/include/llvm/IR/Attributes.h +++ llvm/include/llvm/IR/Attributes.h @@ -18,17 +18,14 @@ #include "llvm-c/Types.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/BitmaskEnum.h" -#include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringRef.h" #include "llvm/Config/llvm-config.h" #include "llvm/Support/Alignment.h" #include "llvm/Support/CodeGen.h" #include "llvm/Support/PointerLikeTypeTraits.h" -#include <bitset> #include <cassert> #include <cstdint> #include <optional> -#include <set> #include <string> #include <utility> @@ -984,65 +981,6 @@ } }; -//===----------------------------------------------------------------------===// -/// \class -/// This class stores enough information to efficiently remove some attributes -/// from an existing AttrBuilder, AttributeSet or AttributeList. -class AttributeMask { - std::bitset<Attribute::EndAttrKinds> Attrs; - std::set<SmallString<32>, std::less<>> TargetDepAttrs; - -public: - AttributeMask() = default; - AttributeMask(const AttributeMask &) = delete; - AttributeMask(AttributeMask &&) = default; - - AttributeMask(AttributeSet AS) { - for (Attribute A : AS) - addAttribute(A); - } - - /// Add an attribute to the mask. - AttributeMask &addAttribute(Attribute::AttrKind Val) { - assert((unsigned)Val < Attribute::EndAttrKinds && - "Attribute out of range!"); - Attrs[Val] = true; - return *this; - } - - /// Add the Attribute object to the builder. - AttributeMask &addAttribute(Attribute A) { - if (A.isStringAttribute()) - addAttribute(A.getKindAsString()); - else - addAttribute(A.getKindAsEnum()); - return *this; - } - - /// Add the target-dependent attribute to the builder. - AttributeMask &addAttribute(StringRef A) { - TargetDepAttrs.insert(A); - return *this; - } - - /// Return true if the builder has the specified attribute. - bool contains(Attribute::AttrKind A) const { - assert((unsigned)A < Attribute::EndAttrKinds && "Attribute out of range!"); - return Attrs[A]; - } - - /// Return true if the builder has the specified target-dependent - /// attribute. - bool contains(StringRef A) const { return TargetDepAttrs.count(A); } - - /// Return true if the mask contains the specified attribute. - bool contains(Attribute A) const { - if (A.isStringAttribute()) - return contains(A.getKindAsString()); - return contains(A.getKindAsEnum()); - } -}; - //===----------------------------------------------------------------------===// /// \class /// This class is used in conjunction with the Attribute::get method to Index: llvm/include/llvm/IR/AttributeMask.h =================================================================== --- /dev/null +++ llvm/include/llvm/IR/AttributeMask.h @@ -0,0 +1,86 @@ +//===- llvm/AttributeMask.h - Mask for Attributes ---------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// +/// \file +// This file declares the AttributeMask class. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_IR_ATTRIBUTEMASK_H +#define LLVM_IR_ATTRIBUTEMASK_H + +#include "llvm/ADT/SmallString.h" +#include "llvm/IR/Attributes.h" +#include <bitset> +#include <cassert> +#include <set> + +namespace llvm { + +//===----------------------------------------------------------------------===// +/// \class +/// This class stores enough information to efficiently remove some attributes +/// from an existing AttrBuilder, AttributeSet or AttributeList. +class AttributeMask { + std::bitset<Attribute::EndAttrKinds> Attrs; + std::set<SmallString<32>, std::less<>> TargetDepAttrs; + +public: + AttributeMask() = default; + AttributeMask(const AttributeMask &) = delete; + AttributeMask(AttributeMask &&) = default; + + AttributeMask(AttributeSet AS) { + for (Attribute A : AS) + addAttribute(A); + } + + /// Add an attribute to the mask. + AttributeMask &addAttribute(Attribute::AttrKind Val) { + assert((unsigned)Val < Attribute::EndAttrKinds && + "Attribute out of range!"); + Attrs[Val] = true; + return *this; + } + + /// Add the Attribute object to the builder. + AttributeMask &addAttribute(Attribute A) { + if (A.isStringAttribute()) + addAttribute(A.getKindAsString()); + else + addAttribute(A.getKindAsEnum()); + return *this; + } + + /// Add the target-dependent attribute to the builder. + AttributeMask &addAttribute(StringRef A) { + TargetDepAttrs.insert(A); + return *this; + } + + /// Return true if the builder has the specified attribute. + bool contains(Attribute::AttrKind A) const { + assert((unsigned)A < Attribute::EndAttrKinds && "Attribute out of range!"); + return Attrs[A]; + } + + /// Return true if the builder has the specified target-dependent + /// attribute. + bool contains(StringRef A) const { return TargetDepAttrs.count(A); } + + /// Return true if the mask contains the specified attribute. + bool contains(Attribute A) const { + if (A.isStringAttribute()) + return contains(A.getKindAsString()); + return contains(A.getKindAsEnum()); + } +}; + +} // end namespace llvm + +#endif // LLVM_IR_ATTRIBUTEMASK_H Index: clang/lib/CodeGen/CodeGenModule.cpp =================================================================== --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -52,6 +52,7 @@ #include "llvm/ADT/StringSwitch.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Frontend/OpenMP/OMPIRBuilder.h" +#include "llvm/IR/AttributeMask.h" #include "llvm/IR/CallingConv.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/Intrinsics.h" Index: clang/lib/CodeGen/CGCall.cpp =================================================================== --- clang/lib/CodeGen/CGCall.cpp +++ clang/lib/CodeGen/CGCall.cpp @@ -31,6 +31,7 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/IR/Assumptions.h" +#include "llvm/IR/AttributeMask.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/CallingConv.h" #include "llvm/IR/DataLayout.h"
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits