[SIL] Cache Builtin Kind and type lookup in SILModule and speed up CCP

Swift SVN r7354
This commit is contained in:
Anna Zaks
2013-08-20 01:31:48 +00:00
parent b0dd877454
commit 2870c53a54
4 changed files with 44 additions and 17 deletions

View File

@@ -11,9 +11,10 @@
//===----------------------------------------------------------------------===//
#include "swift/SIL/SILModule.h"
#include "swift/AST/Builtins.h"
#include "swift/SIL/SILValue.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/StringSwitch.h"
using namespace swift;
namespace swift {
@@ -104,4 +105,23 @@ llvm::Intrinsic::ID SILModule::getIntrinsicID(const FuncDecl* FD) {
return IntrinsicIDCache[FD];
}
const BuiltinInfo &SILModule::getBuiltinInfo(const FuncDecl* FD) {
unsigned OldSize = BuiltinIDCache.size();
BuiltinInfo &Info = BuiltinIDCache[FD];
// If the element was not in the cache, lookup the ID and Type.
if (OldSize != BuiltinIDCache.size()) {
// Find the matching ID.
StringRef OperationName = getBuiltinBaseName(getASTContext(),
FD->getName().str(),
Info.Types);
Info.ID = llvm::StringSwitch<BuiltinValueKind>(OperationName)
#define BUILTIN(id, name) \
.Case(name, BuiltinValueKind::id)
#include "swift/AST/Builtins.def"
.Default(BuiltinValueKind::None);
}
return Info;
}