Swift Optimizer: add the SSAUpdater utility

This commit is contained in:
Erik Eckstein
2023-07-19 13:23:02 +02:00
parent 40d41d4d82
commit 2e9de24e2a
6 changed files with 98 additions and 10 deletions

View File

@@ -452,6 +452,26 @@ struct BridgedPassContext {
invocation->getTransform());
}
// SSAUpdater
void SSAUpdater_initialize(swift::SILType type, BridgedValue::Ownership ownership) const {
invocation->initializeSSAUpdater(type, castToOwnership(ownership));
}
void SSAUpdater_addAvailableValue(BridgedBasicBlock block, BridgedValue value) const {
invocation->getSSAUpdater()->addAvailableValue(block.getBlock(), value.getSILValue());
}
SWIFT_IMPORT_UNSAFE
BridgedValue SSAUpdater_getValueAtEndOfBlock(BridgedBasicBlock block) const {
return {invocation->getSSAUpdater()->getValueAtEndOfBlock(block.getBlock())};
}
SWIFT_IMPORT_UNSAFE
BridgedValue SSAUpdater_getValueInMiddleOfBlock(BridgedBasicBlock block) const {
return {invocation->getSSAUpdater()->getValueInMiddleOfBlock(block.getBlock())};
}
// Options
bool enableStackProtection() const {

View File

@@ -17,6 +17,7 @@
#include "swift/SILOptimizer/Analysis/Analysis.h"
#include "swift/SILOptimizer/PassManager/PassPipeline.h"
#include "swift/SILOptimizer/PassManager/Passes.h"
#include "swift/SILOptimizer/Utils/SILSSAUpdater.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Casting.h"
@@ -68,6 +69,8 @@ class SwiftPassInvocation {
/// All slabs, allocated by the pass.
SILModule::SlabList allocatedSlabs;
SILSSAUpdater *ssaUpdater = nullptr;
static constexpr int BlockSetCapacity = 8;
char blockSetStorage[sizeof(BasicBlockSet) * BlockSetCapacity];
bool aliveBlockSets[BlockSetCapacity];
@@ -82,7 +85,7 @@ class SwiftPassInvocation {
bool needFixStackNesting = false;
void endPassRunChecks();
void endPass();
public:
SwiftPassInvocation(SILPassManager *passManager, SILFunction *function,
@@ -143,6 +146,17 @@ public:
void setNeedFixStackNesting(bool newValue) { needFixStackNesting = newValue; }
bool getNeedFixStackNesting() const { return needFixStackNesting; }
void initializeSSAUpdater(SILType type, ValueOwnershipKind ownership) {
if (!ssaUpdater)
ssaUpdater = new SILSSAUpdater;
ssaUpdater->initialize(type, ownership);
}
SILSSAUpdater *getSSAUpdater() const {
assert(ssaUpdater && "SSAUpdater not initialized");
return ssaUpdater;
}
};
/// The SIL pass manager.