Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions include/swift/IRGen/IRGenPublic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//===---------IRGenPublic.h - Public interface to IRGen ---------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_IRGEN_IRGENPUBLIC_H
#define SWIFT_IRGEN_IRGENPUBLIC_H

namespace llvm {
class LLVMContext;
}

namespace swift {
class SILModule;

namespace irgen {

class IRGenerator;
class IRGenModule;

/// Create an IRGen module.
std::pair<IRGenerator *, IRGenModule *>
createIRGenModule(SILModule *SILMod, llvm::LLVMContext &LLVMContext);

/// Delete the IRGenModule and IRGenerator obtained by the above call.
void deleteIRGenModule(std::pair<IRGenerator *, IRGenModule *> &Module);

} // end namespace irgen
} // end namespace swift

#endif
23 changes: 23 additions & 0 deletions include/swift/IRGen/IRGenSILPasses.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===--- IRGenSILPasses.cpp - The IRGen Prepare SIL Passes ----------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

namespace swift {

class SILFunctionTransform;

namespace irgen {

/// Create a pass to hoist alloc_stack instructions with non-fixed size.
SILFunctionTransform *createAllocStackHoisting();

} // end namespace irgen
} // end namespace swift
3 changes: 3 additions & 0 deletions include/swift/SIL/SILFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,9 @@ class SILFunction
SILBasicBlock &front() { return *begin(); }
const SILBasicBlock &front() const { return *begin(); }

SILBasicBlock *getEntryBlock() { return &front(); }
const SILBasicBlock *getEntryBlock() const { return &front(); }

SILBasicBlock *createBasicBlock();
SILBasicBlock *createBasicBlock(SILBasicBlock *After);

Expand Down
29 changes: 29 additions & 0 deletions include/swift/SILOptimizer/PassManager/PassManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,18 @@ class SILModuleTransform;
class SILOptions;
class SILTransform;

namespace irgen {
class IRGenModule;
}

/// \brief The SIL pass manager.
class SILPassManager {
/// The module that the pass manager will transform.
SILModule *Mod;

/// An optional IRGenModule associated with this PassManager.
irgen::IRGenModule *IRMod;

/// The list of transformations to run.
llvm::SmallVector<SILTransform *, 16> Transformations;

Expand Down Expand Up @@ -90,11 +97,20 @@ class SILPassManager {
/// same function.
bool RestartPipeline = false;


/// The IRGen SIL passes. These have to be dynamically added by IRGen.
llvm::DenseMap<unsigned, SILFunctionTransform *> IRGenPasses;

public:
/// C'tor. It creates and registers all analysis passes, which are defined
/// in Analysis.def.
SILPassManager(SILModule *M, llvm::StringRef Stage = "");

/// C'tor. It creates an IRGen pass manager. Passes can query for the
/// IRGenModule.
SILPassManager(SILModule *M, irgen::IRGenModule *IRMod,
llvm::StringRef Stage = "");

const SILOptions &getOptions() const;

/// \brief Searches for an analysis of type T in the list of registered
Expand All @@ -111,6 +127,10 @@ class SILPassManager {
/// \returns the module that the pass manager owns.
SILModule *getModule() { return Mod; }

/// \returns the associated IGenModule or null if this is not an IRGen
/// pass manager.
irgen::IRGenModule *getIRGenModule() { return IRMod; }

/// \brief Run one iteration of the optimization pipeline.
void runOneIteration();

Expand Down Expand Up @@ -218,6 +238,15 @@ class SILPassManager {
}
}

void registerIRGenPass(PassKind Kind, SILFunctionTransform *Transform) {
assert(IRGenPasses.find(unsigned(Kind)) == IRGenPasses.end() &&
"Pass already registered");
assert(
IRMod &&
"Attempting to register an IRGen pass with a non-IRGen pass manager");
IRGenPasses[unsigned(Kind)] = Transform;
}

private:
void execute() {
runOneIteration();
Expand Down
1 change: 1 addition & 0 deletions include/swift/SILOptimizer/PassManager/PassPipeline.def
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ PASSPIPELINE(OwnershipEliminator, "Utility pass to just run the ownership elimin
PASSPIPELINE_WITH_OPTIONS(Performance, "Passes run at -O")
PASSPIPELINE(Onone, "Passes run at -Onone")
PASSPIPELINE(InstCount, "Utility pipeline to just run the inst count pass")
PASSPIPELINE(IRGenPrepare, "Pipeline to run during IRGen")

#undef PASSPIPELINE_WITH_OPTIONS
#undef PASSPIPELINE
11 changes: 11 additions & 0 deletions include/swift/SILOptimizer/PassManager/Passes.def
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
#error "Macro must be defined by includer"
#endif

/// IRGEN_PASS(Id, Name, Description)
/// The pass is identified by PassKind::Id.
/// An IRGen pass is created by IRGen and needs to be register with the pass
/// manager dynamically.
#ifndef IRGEN_PASS
#define IRGEN_PASS(Id, Name, Description) PASS(Id, Name, Description)
#endif

/// PASS_RANGE(RANGE_ID, START, END)
/// Pass IDs between PassKind::START and PassKind::END, inclusive,
/// fall within the set known as
Expand All @@ -36,6 +44,8 @@ PASS(ABCOpt, "abcopts",
"Optimization of array bounds checks")
PASS(AllocBoxToStack, "allocbox-to-stack",
"Promote heap allocations to stack allocations")
IRGEN_PASS(AllocStackHoisting, "alloc-stack-hoisting",
"Hoist generic alloc_stack instructions to the entry block")
PASS(ArrayCountPropagation, "array-count-propagation",
"Propagate the count of arrays")
PASS(ArrayElementPropagation, "array-element-propagation",
Expand Down Expand Up @@ -243,5 +253,6 @@ PASS(BugReducerTester, "bug-reducer-tester",
"Utility pass for testing sil-bug-reducer. Asserts when visits an apply that calls a specific function")
PASS_RANGE(AllPasses, AADumper, BugReducerTester)

#undef IRGEN_PASS
#undef PASS
#undef PASS_RANGE
5 changes: 5 additions & 0 deletions include/swift/SILOptimizer/PassManager/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ namespace swift {
class SILOptions;
class SILTransform;

namespace irgen {
class IRGenModule;
}

/// \brief Run all the SIL diagnostic passes on \p M.
///
/// \returns true if the diagnostic passes produced an error
Expand Down Expand Up @@ -74,6 +78,7 @@ namespace swift {
StringRef PassKindID(PassKind Kind);

#define PASS(ID, NAME, DESCRIPTION) SILTransform *create##ID();
#define IRGEN_PASS(ID, NAME, DESCRIPTION)
#include "Passes.def"

} // end namespace swift
Expand Down
6 changes: 6 additions & 0 deletions include/swift/SILOptimizer/PassManager/Transforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ namespace swift {
protected:
SILFunction *getFunction() { return F; }

irgen::IRGenModule *getIRGenModule() {
auto *Mod = PM->getIRGenModule();
assert(Mod && "Expecting a valid module");
return Mod;
}

void invalidateAnalysis(SILAnalysis::InvalidationKind K) {
PM->invalidateAnalysis(F, K);
}
Expand Down
27 changes: 27 additions & 0 deletions lib/IRGen/Address.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,33 @@ class ContainedAddress {
bool isValid() const { return Addr.isValid(); }
};

/// An address on the stack together with an optional stack pointer reset
/// location.
class StackAddress {
/// The address of an object of type T.
Address Addr;
/// The stack pointer location to reset to when this stack object is
/// deallocated.
llvm::Value *StackPtrResetLocation;

public:
StackAddress() : StackPtrResetLocation(nullptr) {}
StackAddress(Address address)
: Addr(address), StackPtrResetLocation(nullptr) {}
StackAddress(Address address, llvm::Value *SP)
: Addr(address), StackPtrResetLocation(SP) {}

llvm::Value *getAddressPointer() const { return Addr.getAddress(); }
Alignment getAlignment() const { return Addr.getAlignment(); }
Address getAddress() const { return Addr; }
bool needsSPRestore() const { return StackPtrResetLocation != nullptr; }
llvm::Value *getSavedSP() const {
assert(StackPtrResetLocation && "Expect a valid stacksave");
return StackPtrResetLocation; }

bool isValid() const { return Addr.isValid(); }
};

} // end namespace irgen
} // end namespace swift

Expand Down
Loading