mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[sil-module] Create SILFunctionBuilder and hide creation/erasing functions on SILModule.
This commit does not modify those APIs or their usage. It just: 1. Moves the APIs onto SILFunctionBuilder and makes SILFunctionBuilder a friend of SILModule. 2. Hides the APIs on SILModule so all users need to use SILFunctionBuilder to create/destroy functions. I am doing this in order to allow for adding/removing function notifications to be enforced via the type system in the SILOptimizer. In the process of finishing off CallerAnalysis for FSO, I discovered that we were not doing this everywhere we need to. After considering various other options such as: 1. Verifying after all passes that the notifications were sent correctly and asserting. Turned out to be expensive. 2. Putting a callback in SILModule. This would add an unnecessary virtual call. I realized that by using a builder we can: 1. Enforce that users of SILFunctionBuilder can only construct composed function builders by making the composed function builder's friends of SILFunctionBuilder (notice I did not use the word subclass, I am talking about a pure composition). 2. Refactor a huge amount of code in SILOpt/SILGen that involve function creation onto a SILGenFunctionBuilder/SILOptFunctionBuilder struct. Many of the SILFunction creation code in question are straight up copies of each other with small variations. A builder would be a great way to simplify that code. 3. Reduce the size of SILModule.cpp by 25% from ~30k -> ~23k making the whole file easier to read. NOTE: In this commit, I do not hide the constructor of SILFunctionBuilder since I have not created the derived builder structs yet. Once I have created those in a subsequent commit, I will hide that constructor. rdar://42301529
This commit is contained in:
@@ -11,11 +11,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#define DEBUG_TYPE "objectoutliner"
|
||||
#include "swift/AST/ASTMangler.h"
|
||||
#include "swift/SIL/DebugUtils.h"
|
||||
#include "swift/SIL/SILBuilder.h"
|
||||
#include "swift/SIL/SILFunctionBuilder.h"
|
||||
#include "swift/SILOptimizer/PassManager/Transforms.h"
|
||||
#include "swift/SILOptimizer/Utils/Local.h"
|
||||
#include "swift/AST/ASTMangler.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
using namespace swift;
|
||||
|
||||
@@ -431,7 +432,8 @@ void ObjectOutliner::replaceFindStringCall(ApplyInst *FindStringCall) {
|
||||
return;
|
||||
|
||||
SILDeclRef declRef(FD, SILDeclRef::Kind::Func);
|
||||
SILFunction *replacementFunc = Module->getOrCreateFunction(
|
||||
SILFunctionBuilder builder(*Module);
|
||||
SILFunction *replacementFunc = builder.getOrCreateFunction(
|
||||
FindStringCall->getLoc(), declRef, NotForDefinition);
|
||||
|
||||
SILFunctionType *FTy = replacementFunc->getLoweredFunctionType();
|
||||
|
||||
Reference in New Issue
Block a user