[clang] 39d8e6e - Add missing StringExtras.h includes

2023-07-08 Thread Elliot Goodrich via cfe-commits
Author: Elliot Goodrich
Date: 2023-07-08T10:19:07+01:00
New Revision: 39d8e6e22cd192db6ace37a4c842265058dcddb8

URL: 
https://github.com/llvm/llvm-project/commit/39d8e6e22cd192db6ace37a4c842265058dcddb8
DIFF: 
https://github.com/llvm/llvm-project/commit/39d8e6e22cd192db6ace37a4c842265058dcddb8.diff

LOG: Add missing StringExtras.h includes

In preparation for removing the `#include "llvm/ADT/StringExtras.h"`
from the header to source file of `llvm/Support/Error.h`, first add in
all the missing includes that were previously included transitively
through this header.

This is fixing all files missed in b0abd4893fa1.

Differential Revision: https://reviews.llvm.org/D154543

Added: 


Modified: 
clang/lib/Driver/ToolChain.cpp
clang/lib/Driver/ToolChains/BareMetal.cpp
llvm/lib/Analysis/VectorUtils.cpp
llvm/lib/Transforms/IPO/Internalize.cpp
llvm/lib/Transforms/Scalar/MergeICmps.cpp
llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
llvm/lib/Transforms/Utils/ModuleUtils.cpp
llvm/tools/llvm-objdump/XCOFFDump.cpp
llvm/unittests/Support/CompressionTest.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 425045801dc217..d60fdbc179683b 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -26,6 +26,7 @@
 #include "clang/Driver/XRayArgs.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Config/llvm-config.h"

diff  --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 470b477a181d01..850d7c59c3474a 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -18,6 +18,7 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/MultilibBuilder.h"
 #include "clang/Driver/Options.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/VirtualFileSystem.h"

diff  --git a/llvm/lib/Analysis/VectorUtils.cpp 
b/llvm/lib/Analysis/VectorUtils.cpp
index 04387221cf8e01..f350c6088b6f20 100644
--- a/llvm/lib/Analysis/VectorUtils.cpp
+++ b/llvm/lib/Analysis/VectorUtils.cpp
@@ -12,6 +12,7 @@
 
 #include "llvm/Analysis/VectorUtils.h"
 #include "llvm/ADT/EquivalenceClasses.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/Analysis/DemandedBits.h"
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Analysis/LoopIterator.h"

diff  --git a/llvm/lib/Transforms/IPO/Internalize.cpp 
b/llvm/lib/Transforms/IPO/Internalize.cpp
index 1181886494caa0..0b8fde6489f8e7 100644
--- a/llvm/lib/Transforms/IPO/Internalize.cpp
+++ b/llvm/lib/Transforms/IPO/Internalize.cpp
@@ -19,6 +19,7 @@
 
//===--===//
 
 #include "llvm/Transforms/IPO/Internalize.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Analysis/CallGraph.h"

diff  --git a/llvm/lib/Transforms/Scalar/MergeICmps.cpp 
b/llvm/lib/Transforms/Scalar/MergeICmps.cpp
index 9e41d5500d801a..311a6435ba7c57 100644
--- a/llvm/lib/Transforms/Scalar/MergeICmps.cpp
+++ b/llvm/lib/Transforms/Scalar/MergeICmps.cpp
@@ -42,6 +42,7 @@
 
//===--===//
 
 #include "llvm/Transforms/Scalar/MergeICmps.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/Analysis/DomTreeUpdater.h"
 #include "llvm/Analysis/GlobalsModRef.h"
 #include "llvm/Analysis/Loads.h"

diff  --git a/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp 
b/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
index a1992d2d63bf4f..531b0a624dafab 100644
--- a/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
+++ b/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
@@ -11,6 +11,7 @@
 
//===--===//
 
 #include "llvm/Transforms/Utils/MemoryOpRemark.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
 #include "llvm/Analysis/ValueTracking.h"
 #include "llvm/IR/DebugInfo.h"

diff  --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp 
b/llvm/lib/Transforms/Utils/ModuleUtils.cpp
index adc2fc0610f3bf..ecd64d8ca4a413 100644
--- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp
+++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp
@@ -12,6 +12,7 @@
 
 #include "llvm/Transforms/Utils/ModuleUtils.h"
 #include "llvm/Analysis/VectorUtils.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/IRBuilder.h"
@@ -19,6 +20,7 @@
 #include "llvm/IR/Module.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/xxhash.h"
+
 using namespace llvm;
 
 #define DEBUG_TYPE "moduleutils"

diff  --git a/llvm/tools/llvm-objdump/XCOFFDump

[clang-tools-extra] cea0eea - [llvm] Split out DenseMapInfo specialization

2023-06-21 Thread Elliot Goodrich via cfe-commits
Author: Elliot Goodrich
Date: 2023-06-22T06:50:54+01:00
New Revision: cea0eea28e71204bf8543ca94dbf185cbf597ca5

URL: 
https://github.com/llvm/llvm-project/commit/cea0eea28e71204bf8543ca94dbf185cbf597ca5
DIFF: 
https://github.com/llvm/llvm-project/commit/cea0eea28e71204bf8543ca94dbf185cbf597ca5.diff

LOG: [llvm] Split out DenseMapInfo specialization

Remove the `DenseMapInfo>` variant out from
`llvm/ADT/DenseMapInfo.h` into a separate header
`llvm/ADT/DenseMapInfoVariant.h`

This allows us to remove the `` include, which is being
transitively and unncessary included in all translation units that
include `llvm/ADT/DenseMap.h`.

There have been similar changes to move out specializations for

* `APInt.h` fd7e309e02fd226b0390888388ed732608e52c73 and
* `StringRef.h`/`ArrayRef.h`
  983565a6fe4a9f40c7caf82b65c650c20dbcc104

to reduce the compilation time. As we are unable to move the
specialization into ``, we create a separate
`DenseMapInfoVariant.h` header that can be used by anyone who needs this
specialization.

This reduces the total number of preprocessing tokens across the LLVM
source files in lib from (roughly) 1,964,876,961 to 1,936,551,496 - a
reduction of ~1.44%. This should result in a small improvement in
compilation time.

Differential Revision: https://reviews.llvm.org/D150997

Added: 
llvm/include/llvm/ADT/DenseMapInfoVariant.h

Modified: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
flang/include/flang/Optimizer/HLFIR/HLFIROps.h
llvm/include/llvm/ADT/DenseMapInfo.h
llvm/include/llvm/CodeGen/CallingConvLower.h
llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
llvm/include/llvm/Object/DXContainer.h
llvm/include/llvm/Transforms/Scalar/SROA.h
llvm/unittests/ADT/DenseMapTest.cpp
mlir/include/mlir/IR/AsmState.h
mlir/include/mlir/Transforms/SROA.h

Removed: 




diff  --git 
a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h 
b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
index 0f7fd1cfafa6b..48b018b382ba5 100644
--- a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
+++ b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
@@ -26,10 +26,12 @@
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseMapInfoVariant.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include 
 #include 
+#include 
 #include 
 
 namespace llvm {

diff  --git a/flang/include/flang/Optimizer/HLFIR/HLFIROps.h 
b/flang/include/flang/Optimizer/HLFIR/HLFIROps.h
index 26bfc9a805dcc..ab426256c5aa5 100644
--- a/flang/include/flang/Optimizer/HLFIR/HLFIROps.h
+++ b/flang/include/flang/Optimizer/HLFIR/HLFIROps.h
@@ -19,6 +19,7 @@
 #include "mlir/IR/PatternMatch.h"
 #include "mlir/Interfaces/InferTypeOpInterface.h"
 #include "mlir/Interfaces/SideEffectInterfaces.h"
+#include 
 
 #include "flang/Optimizer/HLFIR/HLFIROpInterfaces.h.inc"
 #define GET_OP_CLASSES

diff  --git a/llvm/include/llvm/ADT/DenseMapInfo.h 
b/llvm/include/llvm/ADT/DenseMapInfo.h
index 2c227be0082ab..5b7dce7b53c62 100644
--- a/llvm/include/llvm/ADT/DenseMapInfo.h
+++ b/llvm/include/llvm/ADT/DenseMapInfo.h
@@ -20,7 +20,6 @@
 #include 
 #include 
 #include 
-#include 
 
 namespace llvm {
 
@@ -234,6 +233,14 @@ struct DenseMapInfo> {
 SecondInfo::getHashValue(PairVal.second));
   }
 
+  // Expose an additional function intended to be used by other
+  // specializations of DenseMapInfo without needing to know how
+  // to combine hash values manually
+  static unsigned getHashValuePiecewise(const T &First, const U &Second) {
+return detail::combineHashValue(FirstInfo::getHashValue(First),
+SecondInfo::getHashValue(Second));
+  }
+
   static bool isEqual(const Pair &LHS, const Pair &RHS) {
 return FirstInfo::isEqual(LHS.first, RHS.first) &&
SecondInfo::isEqual(LHS.second, RHS.second);
@@ -290,52 +297,6 @@ template  struct 
DenseMapInfo> {
   }
 };
 
-// Provide DenseMapInfo for variants whose all alternatives have DenseMapInfo.
-template  struct DenseMapInfo> {
-  using Variant = std::variant;
-  using FirstT = std::variant_alternative_t<0, Variant>;
-
-  static inline Variant getEmptyKey() {
-return Variant(std::in_place_index<0>, 
DenseMapInfo::getEmptyKey());
-  }
-
-  static inline Variant getTombstoneKey() {
-return Variant(std::in_place_index<0>,
-   DenseMapInfo::getTombstoneKey());
-  }
-
-  static unsigned getHashValue(const Variant &Val) {
-return std::visit(
-[&Val](auto &&Alternative) {
-  using T = std::decay_t;
-  // Include index in hash to make sure same value as 
diff erent
-  // alternatives don't collide.
-  return detail::combineHashValu

[clang-tools-extra] b0abd48 - [llvm] Add missing StringExtras.h includes

2023-06-25 Thread Elliot Goodrich via cfe-commits
Author: Elliot Goodrich
Date: 2023-06-25T15:42:22+01:00
New Revision: b0abd4893fa1bfae7f71b6b6e98770c9b1c07620

URL: 
https://github.com/llvm/llvm-project/commit/b0abd4893fa1bfae7f71b6b6e98770c9b1c07620
DIFF: 
https://github.com/llvm/llvm-project/commit/b0abd4893fa1bfae7f71b6b6e98770c9b1c07620.diff

LOG: [llvm] Add missing StringExtras.h includes

In preparation for removing the `#include "llvm/ADT/StringExtras.h"`
from the header to source file of `llvm/Support/Error.h`, first add in
all the missing includes that were previously included transitively
through this header.

Added: 


Modified: 
clang-tools-extra/clangd/ConfigCompile.cpp
clang-tools-extra/clangd/FileDistance.cpp
clang-tools-extra/clangd/Protocol.cpp
clang-tools-extra/clangd/index/SymbolID.cpp
clang-tools-extra/clangd/unittests/TestIndex.cpp
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/JSONNodeDumper.cpp
clang/lib/Basic/Sarif.cpp
clang/lib/Driver/Job.cpp
clang/lib/Driver/ToolChains/AIX.cpp
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/lib/Sema/SemaCast.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/SemaModule.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaStmtAsm.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
clang/tools/clang-offload-packager/ClangOffloadPackager.cpp
clang/tools/driver/cc1as_main.cpp
lld/COFF/Chunks.cpp
lld/COFF/DebugTypes.cpp
lld/COFF/DriverUtils.cpp
lld/Common/Strings.cpp
lld/Common/Timer.cpp
lld/ELF/AArch64ErrataFix.cpp
lld/ELF/InputSection.h
lld/ELF/Target.h
lld/wasm/WriterUtils.cpp
llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.cpp
llvm/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
llvm/include/llvm/DebugInfo/GSYM/FunctionInfo.h
llvm/include/llvm/Debuginfod/HTTPClient.h
llvm/include/llvm/ProfileData/GCOV.h
llvm/lib/Analysis/AliasSetTracker.cpp
llvm/lib/Analysis/CallGraphSCCPass.cpp
llvm/lib/Analysis/InlineAdvisor.cpp
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
llvm/lib/CodeGen/MachineBasicBlock.cpp
llvm/lib/CodeGen/MachineCheckDebugify.cpp
llvm/lib/CodeGen/RegisterBankInfo.cpp
llvm/lib/DWARFLinker/DWARFLinker.cpp
llvm/lib/DWARFLinker/DWARFLinkerCompileUnit.cpp
llvm/lib/DWARFLinkerParallel/DWARFLinkerUnit.h
llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp
llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
llvm/lib/DebugInfo/PDB/Native/NativeEnumInjectedSources.cpp
llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
llvm/lib/DebugInfo/PDB/Native/NativeSourceFile.cpp
llvm/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp
llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFAArch64.h
llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h
llvm/lib/FileCheck/FileCheck.cpp
llvm/lib/IR/DIBuilder.cpp
llvm/lib/MC/ELFObjectWriter.cpp
llvm/lib/MC/MCAsmInfo.cpp
llvm/lib/MC/MCParser/ELFAsmParser.cpp
llvm/lib/MC/MCParser/WasmAsmParser.cpp
llvm/lib/ObjCopy/COFF/COFFObjcopy.cpp
llvm/lib/Object/Decompressor.cpp
llvm/lib/Object/ELF.cpp
llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
llvm/lib/Remarks/YAMLRemarkParser.cpp
llvm/lib/Support/BinaryStreamWriter.cpp
llvm/lib/Support/DataExtractor.cpp
llvm/lib/Support/JSON.cpp
llvm/lib/Support/Path.cpp
llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h
llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp
llvm/lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.cpp
llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
llvm/lib/Target/PowerPC/PPCISelLowering.cpp
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp
llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
llvm/lib/Target/X86/X86MCInstLower.cpp
llvm/lib/Target/X86/X86PreAMXConfig.cpp
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
llvm/lib/Transforms/IPO/OpenMPOpt.cpp
llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/lib/Transforms/Vectorize/VPlan.cpp
llvm/tools/ll

[clang] f0fa2d7 - [llvm] Move AttributeMask to a separate header

2023-06-27 Thread Elliot Goodrich via cfe-commits
Author: Elliot Goodrich
Date: 2023-06-27T15:26:17+01:00
New Revision: f0fa2d7c292853b79b5bcd16be97940859a800ec

URL: 
https://github.com/llvm/llvm-project/commit/f0fa2d7c292853b79b5bcd16be97940859a800ec
DIFF: 
https://github.com/llvm/llvm-project/commit/f0fa2d7c292853b79b5bcd16be97940859a800ec.diff

LOG: [llvm] Move AttributeMask to a separate header

Move `AttributeMask` out of `llvm/IR/Attributes.h` to a new file
`llvm/IR/AttributeMask.h`.  After doing this we can remove the
`#include ` and `#include ` 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.

This commit adds in 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.

Differential Revision: https://reviews.llvm.org/D153728

Added: 
llvm/include/llvm/IR/AttributeMask.h

Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CodeGenModule.cpp
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

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 6a9be661998fc..50ef440937fd9 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/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"

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 7a4b81a48f727..b404b92bb7638 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/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"

diff  --git a/llvm/include/llvm/IR/AttributeMask.h 
b/llvm/include/llvm/IR/AttributeMask.h
new file mode 100644
index 0..857761149ff46
--- /dev/null
+++ b/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 
+#include 
+#include 
+
+namespace llvm {
+
+//===--===//
+/// \class
+/// This class stores enough information to efficiently remove some attributes
+/// from an existing AttrBuilder, AttributeSet or AttributeList.
+class AttributeMask {
+  std::bitset Attrs;
+  std::set, 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;
+