Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master next #131

Closed
wants to merge 5 commits into from
Closed
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
39 changes: 39 additions & 0 deletions include/swift/AST/CaptureInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
#include "llvm/ADT/PointerIntPair.h"
#include <vector>

namespace swift {
class CapturedValue;
}

namespace llvm {
class raw_ostream;
template <> struct DenseMapInfo<swift::CapturedValue>;
}

namespace swift {
Expand All @@ -30,7 +35,12 @@ class FuncDecl;
/// that indicate how it is captured.
class CapturedValue {
llvm::PointerIntPair<ValueDecl*, 2, unsigned> Value;

explicit CapturedValue(llvm::PointerIntPair<ValueDecl*, 2, unsigned> V) : Value(V) {}

public:
friend struct llvm::DenseMapInfo<CapturedValue>;

enum {
/// IsDirect is set when a VarDecl with storage *and* accessors is captured
/// by its storage address. This happens in the accessors for the VarDecl.
Expand Down Expand Up @@ -64,7 +74,36 @@ class CapturedValue {
}
};

} // end swift namespace

namespace llvm {

template <> struct DenseMapInfo<swift::CapturedValue> {
using CapturedValue = swift::CapturedValue;

using PtrIntPairDenseMapInfo =
DenseMapInfo<llvm::PointerIntPair<swift::ValueDecl *, 2, unsigned>>;

static inline swift::CapturedValue getEmptyKey() {
return CapturedValue{PtrIntPairDenseMapInfo::getEmptyKey()};
}

static inline CapturedValue getTombstoneKey() {
return CapturedValue{PtrIntPairDenseMapInfo::getTombstoneKey()};
}

static unsigned getHashValue(const CapturedValue &Val) {
return PtrIntPairDenseMapInfo::getHashValue(Val.Value);
}

static bool isEqual(const CapturedValue &LHS, const CapturedValue &RHS) {
return PtrIntPairDenseMapInfo::isEqual(LHS.Value, RHS.Value);
}
};

} // end llvm namespace

namespace swift {

/// \brief Stores information about captured variables.
class CaptureInfo {
Expand Down
3 changes: 2 additions & 1 deletion include/swift/AST/ModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ enum class KnownProtocolKind : uint8_t;

/// Records dependencies on files outside of the current module.
class DependencyTracker {
llvm::SetVector<std::string, std::vector<std::string>> paths;
llvm::SetVector<std::string, std::vector<std::string>,
llvm::SmallSet<std::string, 16>> paths;

public:
/// Adds a file as a dependency.
Expand Down
28 changes: 28 additions & 0 deletions lib/AST/LookupVisibleDecls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ static void lookupVisibleMemberDeclsImpl(
}

namespace {

struct FoundDeclTy {
ValueDecl *D;
DeclVisibilityKind Reason;
Expand All @@ -535,6 +536,33 @@ struct FoundDeclTy {
}
};

} // end anonymous namespace

namespace llvm {

template <> struct DenseMapInfo<FoundDeclTy> {
static inline FoundDeclTy getEmptyKey() {
return FoundDeclTy{nullptr, DeclVisibilityKind::LocalVariable};
}

static inline FoundDeclTy getTombstoneKey() {
return FoundDeclTy{reinterpret_cast<ValueDecl *>(0x1),
DeclVisibilityKind::LocalVariable};
}

static unsigned getHashValue(const FoundDeclTy &Val) {
return llvm::hash_combine(unsigned(Val.Reason), Val.D);
}

static bool isEqual(const FoundDeclTy &LHS, const FoundDeclTy &RHS) {
return LHS == RHS;
}
};

} // end llvm namespace

namespace {

/// Similar to swift::conflicting, but lenient about protocol extensions which
/// don't affect code completion's concept of overloading.
static bool relaxedConflicting(const OverloadSignature &sig1,
Expand Down
7 changes: 7 additions & 0 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ getNormalInvocationArguments(std::vector<std::string> &invocationArgStrs,
// Enable modules.
"-fmodules",

// Enable implicit module maps
"-fimplicit-module-maps",

// Don't emit LLVM IR.
"-fsyntax-only",

Expand Down Expand Up @@ -512,6 +515,10 @@ ClangImporter::create(ASTContext &ctx,

std::vector<std::string> invocationArgStrs;

// Clang expects this to be like an actual command line. So we need to pass in
// "clang" for argv[0]
invocationArgStrs.push_back("clang");

switch (importerOpts.Mode) {
case ClangImporterOptions::Modes::Normal:
getNormalInvocationArguments(invocationArgStrs, ctx, importerOpts);
Expand Down
4 changes: 2 additions & 2 deletions lib/IRGen/GenClangDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "IRGenModule.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclGroup.h"
#include "clang/AST/DataRecursiveASTVisitor.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/CodeGen/ModuleBuilder.h"
#include "llvm/ADT/SmallPtrSet.h"

Expand All @@ -22,7 +22,7 @@ using namespace irgen;

namespace {
class ClangDeclRefFinder
: public clang::DataRecursiveASTVisitor<ClangDeclRefFinder> {
: public clang::RecursiveASTVisitor<ClangDeclRefFinder> {
std::function<void(const clang::DeclRefExpr *)> callback;
public:
template <typename Fn>
Expand Down
33 changes: 18 additions & 15 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1306,13 +1306,13 @@ void IRGenSILFunction::emitSILFunction() {
// Map the entry bb.
LoweredBBs[&*CurSILFn->begin()] = LoweredBB(&*CurFn->begin(), {});
// Create LLVM basic blocks for the other bbs.
for (SILBasicBlock *bb = CurSILFn->begin()->getNextNode();
bb != CurSILFn->end(); bb = bb->getNextNode()) {
for (auto bi = std::next(CurSILFn->begin()), be = CurSILFn->end(); bi != be;
++bi) {
// FIXME: Use the SIL basic block's name.
llvm::BasicBlock *llBB = llvm::BasicBlock::Create(IGM.getLLVMContext());
auto phis = emitPHINodesForBBArgs(*this, bb, llBB);
auto phis = emitPHINodesForBBArgs(*this, &*bi, llBB);
CurFn->getBasicBlockList().push_back(llBB);
LoweredBBs[bb] = LoweredBB(llBB, std::move(phis));
LoweredBBs[&*bi] = LoweredBB(llBB, std::move(phis));
}

auto entry = LoweredBBs.begin();
Expand Down Expand Up @@ -3311,18 +3311,21 @@ static bool tryDeferFixedSizeBufferInitialization(IRGenSILFunction &IGF,
// if the alloc_stack is dominated by copy_addrs into it on all paths.
// For now, check only that the copy_addr is the first use within the same
// block.
const SILInstruction *inst = allocInst;
while ((inst = inst->getNextNode()) && !isa<TermInst>(inst)) {
// Does this instruction use the allocation?
for (auto &operand : inst->getAllOperands())
if (operand.get() == addressValue)
goto is_use;

continue;

is_use:
for (auto ii = std::next(allocInst->getIterator()),
ie = std::prev(allocInst->getParent()->end());
ii != ie; ++ii) {
auto *inst = &*ii;

// Does this instruction use the allocation? If not, continue.
auto Ops = inst->getAllOperands();
if (std::none_of(Ops.begin(), Ops.end(),
[&addressValue](const Operand &Op) {
return Op.get() == addressValue;
}))
continue;

// Is this a copy?
auto copy = dyn_cast<swift::CopyAddrInst>(inst);
auto *copy = dyn_cast<swift::CopyAddrInst>(inst);
if (!copy)
return false;

Expand Down
11 changes: 7 additions & 4 deletions lib/SIL/Dominance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ bool DominanceInfo::properlyDominates(SILInstruction *a, SILInstruction *b) {

// Otherwise, they're in the same block, and we just need to check
// whether B comes after A. This is a non-strict computation.
SILInstruction *f = &*aBlock->begin();
while (b != f) {
b = b->getPrevNode();
if (a == b) return true;
auto aIter = a->getIterator();
auto bIter = b->getIterator();
auto fIter = aBlock->begin();
while (bIter != fIter) {
--bIter;
if (aIter == bIter)
return true;
}

return false;
Expand Down
5 changes: 3 additions & 2 deletions lib/SILGen/SILGenStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ SILBasicBlock *SILGenFunction::createBasicBlock(FunctionSection section) {
// The end of the ordinary section is just the end of the function
// unless postmatter blocks exist.
SILBasicBlock *afterBB =
(StartOfPostmatter ? StartOfPostmatter->getPrevNode() : nullptr);
(StartOfPostmatter ? &*std::prev(StartOfPostmatter->getIterator())
: nullptr);
return new (F.getModule()) SILBasicBlock(&F, afterBB);
}

Expand All @@ -73,7 +74,7 @@ void SILGenFunction::eraseBasicBlock(SILBasicBlock *block) {
assert(block->pred_empty() && "erasing block with predecessors");
assert(block->empty() && "erasing block with content");
if (block == StartOfPostmatter) {
StartOfPostmatter = block->getNextNode();
StartOfPostmatter = &*std::next(block->getIterator());
}
block->eraseFromParent();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/SILPasses/EarlySIL/DefiniteInitialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1825,7 +1825,7 @@ SILValue LifetimeChecker::handleConditionalInitAssign() {
}

// Before the memory allocation, store zero in the control variable.
B.setInsertionPoint(TheMemory.MemoryInst->getNextNode());
B.setInsertionPoint(&*std::next(TheMemory.MemoryInst->getIterator()));
SILValue ControlVariableAddr = SILValue(ControlVariableBox, 1);
auto Zero = B.createIntegerLiteral(Loc, IVType, 0);
B.createStore(Loc, Zero, ControlVariableAddr);
Expand Down
10 changes: 6 additions & 4 deletions lib/SILPasses/IPO/CapturePromotion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,10 +778,12 @@ examineAllocBoxInst(AllocBoxInst *ABI, ReachabilityInfo &RI,
// Helper lambda function to determine if instruction b is strictly after
// instruction a, assuming both are in the same basic block.
auto isAfter = [](SILInstruction *a, SILInstruction *b) {
SILInstruction *f = &*b->getParent()->begin();
while (b != f) {
b = b->getPrevNode();
if (a == b)
auto fIter = b->getParent()->begin();
auto bIter = b->getIterator();
auto aIter = a->getIterator();
while (bIter != fIter) {
--bIter;
if (aIter == bIter)
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion lib/SILPasses/Scalar/DeadStoreElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ void DSEContext::run() {
for (SILBasicBlock &BB : *F) {
// Create the stores that are alive.
for (auto &I : getBBLocState(&BB)->LiveStores) {
SILInstruction *IT = cast<SILInstruction>(I.first)->getNextNode();
auto *IT = &*std::next(cast<SILInstruction>(I.first)->getIterator());
SILBuilderWithScope Builder(IT);
Builder.createStore(I.first.getLoc().getValue(), I.second, I.first);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/SILPasses/Scalar/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3013,7 +3013,7 @@ bool simplifySwitchEnumToSelectEnum(SILBasicBlock *BB, unsigned ArgNum,
// Do not replace the bbarg
SmallVector<SILValue, 4> Args;
Args.push_back(SelectInst);
B.setInsertionPoint(SelectInst->getNextNode());
B.setInsertionPoint(&*std::next(SelectInst->getIterator()));
B.createBranch(SEI->getLoc(), BB, Args);
// Remove switch_enum instruction
SEI->getParent()->getTerminator()->eraseFromParent();
Expand Down