[SIL] Add getIntrinsicID(FuncDecl*), which lazyly looks up the llvm::IntrinsicID for it.

The cache is stored in the SILModule.
Add getIntrinsicID() as a member of BuiltinFunctionRefInst.
Test by using the new method in the CCP pass.

Swift SVN r7311
This commit is contained in:
Anna Zaks
2013-08-17 00:41:30 +00:00
parent 7ea5c4c195
commit 3ac84f3878
5 changed files with 48 additions and 11 deletions

View File

@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "swift/SIL/SILModule.h"
#include "swift/AST/Builtins.h"
#include "swift/SIL/SILValue.h"
#include "llvm/ADT/FoldingSet.h"
using namespace swift;
@@ -87,3 +88,20 @@ SILTypeList *SILModule::getSILTypeList(ArrayRef<SILType> Types) const {
return NewList;
}
llvm::Intrinsic::ID SILModule::getIntrinsicID(const FuncDecl* FD) {
if (!IntrinsicIDCache.count(FD)) {
// Find the matching ID.
SmallVector<Type, 4> Types;
StringRef NameRef = getBuiltinBaseName(getASTContext(),
FD->getName().str(), Types);
llvm::Intrinsic::ID Id =
(llvm::Intrinsic::ID)getLLVMIntrinsicID(NameRef, !Types.empty());
// Store it in the cache.
IntrinsicIDCache[FD] = Id;
return Id;
}
return IntrinsicIDCache[FD];
}