Skip to content

Commit 805ae33

Browse files
committed
Cache LLVM attributes for intrinsics
Looking these up is slow because the attribute lists get rebuilt and reuniqued in the LLVM context each time. Saving them is a single pointer per IntrinsicInfo and IntrinsicInfos are already cached in each SILModule. This shaves about 4s off optimizing the standard library (72s out of a 3:00+ build), and probably has much less effect anywhere else. That is, it's not /really/ important after all, but it was an easy bit of the profile to hammer down.
1 parent c59f635 commit 805ae33

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

include/swift/AST/Builtins.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ class BuiltinInfo {
107107
};
108108

109109
/// \brief The information identifying the llvm intrinsic - its id and types.
110-
struct IntrinsicInfo {
110+
class IntrinsicInfo {
111+
mutable llvm::AttributeList Attrs =
112+
llvm::DenseMapInfo<llvm::AttributeList>::getEmptyKey();
113+
public:
111114
llvm::Intrinsic::ID ID;
112115
SmallVector<Type, 4> Types;
113116
bool hasAttribute(llvm::Attribute::AttrKind Kind) const;

lib/AST/Builtins.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ bool BuiltinInfo::isReadNone() const {
4545
}
4646

4747
bool IntrinsicInfo::hasAttribute(llvm::Attribute::AttrKind Kind) const {
48-
// FIXME: We should not be relying on the global LLVM context.
49-
llvm::AttributeList attrs =
50-
llvm::Intrinsic::getAttributes(getGlobalLLVMContext(), ID);
51-
return (attrs.hasAttribute(llvm::AttributeList::FunctionIndex, Kind));
48+
using DenseMapInfo = llvm::DenseMapInfo<llvm::AttributeList>;
49+
if (DenseMapInfo::isEqual(Attrs, DenseMapInfo::getEmptyKey())) {
50+
// FIXME: We should not be relying on the global LLVM context.
51+
Attrs = llvm::Intrinsic::getAttributes(getGlobalLLVMContext(), ID);
52+
}
53+
return Attrs.hasFnAttribute(Kind);
5254
}
5355

5456
Type swift::getBuiltinType(ASTContext &Context, StringRef Name) {

0 commit comments

Comments
 (0)