Skip to content

Commit 14a85f2

Browse files
elliotgoodrichChenyang-L
authored andcommitted
[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 <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. 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
1 parent a53cc8b commit 14a85f2

23 files changed

+108
-63
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "llvm/ADT/StringExtras.h"
3232
#include "llvm/Analysis/ValueTracking.h"
3333
#include "llvm/IR/Assumptions.h"
34+
#include "llvm/IR/AttributeMask.h"
3435
#include "llvm/IR/Attributes.h"
3536
#include "llvm/IR/CallingConv.h"
3637
#include "llvm/IR/DataLayout.h"

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "llvm/ADT/StringSwitch.h"
5454
#include "llvm/Analysis/TargetLibraryInfo.h"
5555
#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
56+
#include "llvm/IR/AttributeMask.h"
5657
#include "llvm/IR/CallingConv.h"
5758
#include "llvm/IR/DataLayout.h"
5859
#include "llvm/IR/Intrinsics.h"

llvm/include/llvm/IR/AttributeMask.h

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//===- llvm/AttributeMask.h - Mask for Attributes ---------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
/// \file
10+
// This file declares the AttributeMask class.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_IR_ATTRIBUTEMASK_H
15+
#define LLVM_IR_ATTRIBUTEMASK_H
16+
17+
#include "llvm/ADT/SmallString.h"
18+
#include "llvm/IR/Attributes.h"
19+
#include <bitset>
20+
#include <cassert>
21+
#include <set>
22+
23+
namespace llvm {
24+
25+
//===----------------------------------------------------------------------===//
26+
/// \class
27+
/// This class stores enough information to efficiently remove some attributes
28+
/// from an existing AttrBuilder, AttributeSet or AttributeList.
29+
class AttributeMask {
30+
std::bitset<Attribute::EndAttrKinds> Attrs;
31+
std::set<SmallString<32>, std::less<>> TargetDepAttrs;
32+
33+
public:
34+
AttributeMask() = default;
35+
AttributeMask(const AttributeMask &) = delete;
36+
AttributeMask(AttributeMask &&) = default;
37+
38+
AttributeMask(AttributeSet AS) {
39+
for (Attribute A : AS)
40+
addAttribute(A);
41+
}
42+
43+
/// Add an attribute to the mask.
44+
AttributeMask &addAttribute(Attribute::AttrKind Val) {
45+
assert((unsigned)Val < Attribute::EndAttrKinds &&
46+
"Attribute out of range!");
47+
Attrs[Val] = true;
48+
return *this;
49+
}
50+
51+
/// Add the Attribute object to the builder.
52+
AttributeMask &addAttribute(Attribute A) {
53+
if (A.isStringAttribute())
54+
addAttribute(A.getKindAsString());
55+
else
56+
addAttribute(A.getKindAsEnum());
57+
return *this;
58+
}
59+
60+
/// Add the target-dependent attribute to the builder.
61+
AttributeMask &addAttribute(StringRef A) {
62+
TargetDepAttrs.insert(A);
63+
return *this;
64+
}
65+
66+
/// Return true if the builder has the specified attribute.
67+
bool contains(Attribute::AttrKind A) const {
68+
assert((unsigned)A < Attribute::EndAttrKinds && "Attribute out of range!");
69+
return Attrs[A];
70+
}
71+
72+
/// Return true if the builder has the specified target-dependent
73+
/// attribute.
74+
bool contains(StringRef A) const { return TargetDepAttrs.count(A); }
75+
76+
/// Return true if the mask contains the specified attribute.
77+
bool contains(Attribute A) const {
78+
if (A.isStringAttribute())
79+
return contains(A.getKindAsString());
80+
return contains(A.getKindAsEnum());
81+
}
82+
};
83+
84+
} // end namespace llvm
85+
86+
#endif // LLVM_IR_ATTRIBUTEMASK_H

llvm/include/llvm/IR/Attributes.h

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,14 @@
1818
#include "llvm-c/Types.h"
1919
#include "llvm/ADT/ArrayRef.h"
2020
#include "llvm/ADT/BitmaskEnum.h"
21-
#include "llvm/ADT/SmallString.h"
2221
#include "llvm/ADT/StringRef.h"
2322
#include "llvm/Config/llvm-config.h"
2423
#include "llvm/Support/Alignment.h"
2524
#include "llvm/Support/CodeGen.h"
2625
#include "llvm/Support/PointerLikeTypeTraits.h"
27-
#include <bitset>
2826
#include <cassert>
2927
#include <cstdint>
3028
#include <optional>
31-
#include <set>
3229
#include <string>
3330
#include <utility>
3431

@@ -984,65 +981,6 @@ template <> struct DenseMapInfo<AttributeList, void> {
984981
}
985982
};
986983

987-
//===----------------------------------------------------------------------===//
988-
/// \class
989-
/// This class stores enough information to efficiently remove some attributes
990-
/// from an existing AttrBuilder, AttributeSet or AttributeList.
991-
class AttributeMask {
992-
std::bitset<Attribute::EndAttrKinds> Attrs;
993-
std::set<SmallString<32>, std::less<>> TargetDepAttrs;
994-
995-
public:
996-
AttributeMask() = default;
997-
AttributeMask(const AttributeMask &) = delete;
998-
AttributeMask(AttributeMask &&) = default;
999-
1000-
AttributeMask(AttributeSet AS) {
1001-
for (Attribute A : AS)
1002-
addAttribute(A);
1003-
}
1004-
1005-
/// Add an attribute to the mask.
1006-
AttributeMask &addAttribute(Attribute::AttrKind Val) {
1007-
assert((unsigned)Val < Attribute::EndAttrKinds &&
1008-
"Attribute out of range!");
1009-
Attrs[Val] = true;
1010-
return *this;
1011-
}
1012-
1013-
/// Add the Attribute object to the builder.
1014-
AttributeMask &addAttribute(Attribute A) {
1015-
if (A.isStringAttribute())
1016-
addAttribute(A.getKindAsString());
1017-
else
1018-
addAttribute(A.getKindAsEnum());
1019-
return *this;
1020-
}
1021-
1022-
/// Add the target-dependent attribute to the builder.
1023-
AttributeMask &addAttribute(StringRef A) {
1024-
TargetDepAttrs.insert(A);
1025-
return *this;
1026-
}
1027-
1028-
/// Return true if the builder has the specified attribute.
1029-
bool contains(Attribute::AttrKind A) const {
1030-
assert((unsigned)A < Attribute::EndAttrKinds && "Attribute out of range!");
1031-
return Attrs[A];
1032-
}
1033-
1034-
/// Return true if the builder has the specified target-dependent
1035-
/// attribute.
1036-
bool contains(StringRef A) const { return TargetDepAttrs.count(A); }
1037-
1038-
/// Return true if the mask contains the specified attribute.
1039-
bool contains(Attribute A) const {
1040-
if (A.isStringAttribute())
1041-
return contains(A.getKindAsString());
1042-
return contains(A.getKindAsEnum());
1043-
}
1044-
};
1045-
1046984
//===----------------------------------------------------------------------===//
1047985
/// \class
1048986
/// This class is used in conjunction with the Attribute::get method to

llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "llvm/ADT/APInt.h"
1515
#include "llvm/ADT/DenseMap.h"
1616
#include "llvm/ADT/SCCIterator.h"
17+
#include "llvm/ADT/SmallString.h"
1718
#include "llvm/Config/llvm-config.h"
1819
#include "llvm/IR/Function.h"
1920
#include "llvm/Support/BlockFrequency.h"

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "llvm/Bitstream/BitstreamReader.h"
2424
#include "llvm/Config/llvm-config.h"
2525
#include "llvm/IR/Argument.h"
26+
#include "llvm/IR/AttributeMask.h"
2627
#include "llvm/IR/Attributes.h"
2728
#include "llvm/IR/AutoUpgrade.h"
2829
#include "llvm/IR/BasicBlock.h"

llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "llvm/Support/ErrorHandling.h"
4040

4141
#include <array>
42+
#include <bitset>
4243
#include <memory>
4344

4445
using namespace llvm;

llvm/lib/IR/Attributes.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "llvm/ADT/StringRef.h"
2424
#include "llvm/ADT/StringSwitch.h"
2525
#include "llvm/Config/llvm-config.h"
26+
#include "llvm/IR/AttributeMask.h"
2627
#include "llvm/IR/Function.h"
2728
#include "llvm/IR/LLVMContext.h"
2829
#include "llvm/IR/Type.h"

llvm/lib/IR/AutoUpgrade.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/ADT/StringRef.h"
1717
#include "llvm/ADT/StringSwitch.h"
1818
#include "llvm/BinaryFormat/Dwarf.h"
19+
#include "llvm/IR/AttributeMask.h"
1920
#include "llvm/IR/Constants.h"
2021
#include "llvm/IR/DebugInfo.h"
2122
#include "llvm/IR/DebugInfoMetadata.h"

llvm/lib/IR/Instruction.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "llvm/IR/Instruction.h"
1414
#include "llvm/ADT/DenseSet.h"
15+
#include "llvm/IR/AttributeMask.h"
1516
#include "llvm/IR/Constants.h"
1617
#include "llvm/IR/Instructions.h"
1718
#include "llvm/IR/IntrinsicInst.h"

llvm/lib/IR/Verifier.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "llvm/ADT/Twine.h"
5959
#include "llvm/BinaryFormat/Dwarf.h"
6060
#include "llvm/IR/Argument.h"
61+
#include "llvm/IR/AttributeMask.h"
6162
#include "llvm/IR/Attributes.h"
6263
#include "llvm/IR/BasicBlock.h"
6364
#include "llvm/IR/CFG.h"

llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "llvm/ADT/SmallSet.h"
4747
#include "llvm/ADT/Statistic.h"
4848
#include "llvm/Analysis/MemoryDependenceAnalysis.h"
49+
#include "llvm/IR/AttributeMask.h"
4950
#include "llvm/IR/IRBuilder.h"
5051
#include "llvm/IR/Instructions.h"
5152
#include "llvm/InitializePasses.h"

llvm/lib/Target/DirectX/DXILPrepare.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/ADT/STLExtras.h"
1717
#include "llvm/ADT/SmallVector.h"
1818
#include "llvm/CodeGen/Passes.h"
19+
#include "llvm/IR/AttributeMask.h"
1920
#include "llvm/IR/IRBuilder.h"
2021
#include "llvm/IR/Instruction.h"
2122
#include "llvm/IR/Module.h"

llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
//
1717
//===----------------------------------------------------------------------===//
1818

19+
#include "llvm/Transforms/IPO/DeadArgumentElimination.h"
1920
#include "llvm/ADT/SmallVector.h"
2021
#include "llvm/ADT/Statistic.h"
2122
#include "llvm/IR/Argument.h"
23+
#include "llvm/IR/AttributeMask.h"
2224
#include "llvm/IR/Attributes.h"
2325
#include "llvm/IR/BasicBlock.h"
2426
#include "llvm/IR/Constants.h"
@@ -43,7 +45,6 @@
4345
#include "llvm/Support/Debug.h"
4446
#include "llvm/Support/raw_ostream.h"
4547
#include "llvm/Transforms/IPO.h"
46-
#include "llvm/Transforms/IPO/DeadArgumentElimination.h"
4748
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
4849
#include <cassert>
4950
#include <utility>

llvm/lib/Transforms/IPO/SCCP.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/Analysis/ValueLattice.h"
2121
#include "llvm/Analysis/ValueLatticeUtils.h"
2222
#include "llvm/Analysis/ValueTracking.h"
23+
#include "llvm/IR/AttributeMask.h"
2324
#include "llvm/IR/Constants.h"
2425
#include "llvm/IR/IntrinsicInst.h"
2526
#include "llvm/Support/CommandLine.h"

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "llvm/Analysis/MemoryBuiltins.h"
2828
#include "llvm/Analysis/ValueTracking.h"
2929
#include "llvm/Analysis/VectorUtils.h"
30+
#include "llvm/IR/AttributeMask.h"
3031
#include "llvm/IR/Attributes.h"
3132
#include "llvm/IR/BasicBlock.h"
3233
#include "llvm/IR/Constant.h"

llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#include "llvm/Analysis/TargetLibraryInfo.h"
7474
#include "llvm/Analysis/ValueTracking.h"
7575
#include "llvm/IR/Argument.h"
76+
#include "llvm/IR/AttributeMask.h"
7677
#include "llvm/IR/Attributes.h"
7778
#include "llvm/IR/BasicBlock.h"
7879
#include "llvm/IR/Constant.h"

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
#include "llvm/Analysis/TargetLibraryInfo.h"
161161
#include "llvm/Analysis/ValueTracking.h"
162162
#include "llvm/IR/Argument.h"
163+
#include "llvm/IR/AttributeMask.h"
163164
#include "llvm/IR/Attributes.h"
164165
#include "llvm/IR/BasicBlock.h"
165166
#include "llvm/IR/CallingConv.h"

llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "llvm/Analysis/TargetLibraryInfo.h"
2828
#include "llvm/Analysis/TargetTransformInfo.h"
2929
#include "llvm/IR/Argument.h"
30+
#include "llvm/IR/AttributeMask.h"
3031
#include "llvm/IR/Attributes.h"
3132
#include "llvm/IR/BasicBlock.h"
3233
#include "llvm/IR/CallingConv.h"

llvm/lib/Transforms/Utils/CallPromotionUtils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "llvm/Transforms/Utils/CallPromotionUtils.h"
1515
#include "llvm/Analysis/Loads.h"
1616
#include "llvm/Analysis/TypeMetadataUtils.h"
17+
#include "llvm/IR/AttributeMask.h"
1718
#include "llvm/IR/IRBuilder.h"
1819
#include "llvm/IR/Instructions.h"
1920
#include "llvm/Transforms/Utils/BasicBlockUtils.h"

llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/Analysis/Loads.h"
2020
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
2121
#include "llvm/Analysis/ValueTracking.h"
22+
#include "llvm/IR/AttributeMask.h"
2223
#include "llvm/IR/DataLayout.h"
2324
#include "llvm/IR/Function.h"
2425
#include "llvm/IR/IRBuilder.h"

llvm/tools/llvm-reduce/deltas/ReduceInstructions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "ReduceInstructions.h"
1515
#include "Utils.h"
1616
#include "llvm/IR/Constants.h"
17+
#include <set>
1718

1819
using namespace llvm;
1920

llvm/unittests/IR/AttributesTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "llvm/IR/Attributes.h"
1010
#include "llvm/AsmParser/Parser.h"
11+
#include "llvm/IR/AttributeMask.h"
1112
#include "llvm/IR/DerivedTypes.h"
1213
#include "llvm/IR/InstrTypes.h"
1314
#include "llvm/IR/LLVMContext.h"

0 commit comments

Comments
 (0)