2626#include " llvm/IR/Attributes.h"
2727#include " llvm/IR/Instructions.h"
2828#include " llvm/IR/Intrinsics.h"
29- #include " llvm/IR/LLVMContext.h"
3029#include " llvm/Support/ManagedStatic.h"
3130#include < tuple>
3231
3332using namespace swift ;
3433
35- // FIXME: The "Global Context" is a holdover from LLVM's removal of the global
36- // context. LLVM's global context was used as scratch space to allocate some
37- // attributes for the routines in this file, so we just made our own to work
38- // around its removal. Really, it doesn't matter where we allocate these
39- // attributes, but it's somewhat convenient for now that they're all in one
40- // place instead of requiring a fresh context for every call. If we can
41- // sequester ownership of a context (e.g. in SILModule) we could do away with
42- // this, but there are callers of \c swift::getSwiftFunctionTypeForIntrinsic
43- // all over the compiler.
44- static llvm::ManagedStatic<llvm::LLVMContext> GlobalContext;
45- static llvm::LLVMContext &getGlobalLLVMContext () { return *GlobalContext; }
46-
4734struct BuiltinExtraInfoTy {
4835 const char *Attributes;
4936};
@@ -58,13 +45,13 @@ bool BuiltinInfo::isReadNone() const {
5845 return strchr (BuiltinExtraInfo[(unsigned )ID].Attributes , ' n' ) != nullptr ;
5946}
6047
61- bool IntrinsicInfo::hasAttribute (llvm::Attribute::AttrKind Kind) const {
48+ const llvm::AttributeList &
49+ IntrinsicInfo::getOrCreateAttributes (ASTContext &Ctx) const {
6250 using DenseMapInfo = llvm::DenseMapInfo<llvm::AttributeList>;
6351 if (DenseMapInfo::isEqual (Attrs, DenseMapInfo::getEmptyKey ())) {
64- // FIXME: We should not be relying on the global LLVM context.
65- Attrs = llvm::Intrinsic::getAttributes (getGlobalLLVMContext (), ID);
52+ Attrs = llvm::Intrinsic::getAttributes (Ctx.getIntrinsicScratchContext (), ID);
6653 }
67- return Attrs. hasFnAttribute (Kind) ;
54+ return Attrs;
6855}
6956
7057Type swift::getBuiltinType (ASTContext &Context, StringRef Name) {
@@ -1837,8 +1824,9 @@ getSwiftFunctionTypeForIntrinsic(llvm::Intrinsic::ID ID,
18371824 }
18381825
18391826 // Translate LLVM function attributes to Swift function attributes.
1840- llvm::AttributeList attrs =
1841- llvm::Intrinsic::getAttributes (getGlobalLLVMContext (), ID);
1827+ IntrinsicInfo II;
1828+ II.ID = ID;
1829+ auto attrs = II.getOrCreateAttributes (Context);
18421830 if (attrs.hasAttribute (llvm::AttributeList::FunctionIndex,
18431831 llvm::Attribute::NoReturn)) {
18441832 ResultTy = Context.getNeverType ();
0 commit comments