Commit 3462e587 authored by Kevin Modzelewski's avatar Kevin Modzelewski

separate the irgenerator into another file; unfortunately it doesn't seem to...

separate the irgenerator into another file; unfortunately it doesn't seem to improve compilation times at all
parent ae6d1c53
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -27,10 +27,6 @@ namespace pyston { ...@@ -27,10 +27,6 @@ namespace pyston {
class AST_expr; class AST_expr;
typedef std::unordered_map<std::string, CompilerVariable*> SymbolTable;
typedef std::map<std::string, CompilerVariable*> SortedSymbolTable;
typedef std::unordered_map<std::string, ConcreteCompilerVariable*> ConcreteSymbolTable;
class IREmitter; class IREmitter;
class MyInserter : public llvm::IRBuilderDefaultInserter<true> { class MyInserter : public llvm::IRBuilderDefaultInserter<true> {
private: private:
......
This diff is collapsed.
// Copyright (c) 2014 Dropbox, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef PYSTON_CODEGEN_IRGEN_IRGENERATOR_H
#define PYSTON_CODEGEN_IRGEN_IRGENERATOR_H
#include <map>
#include "core/types.h"
namespace llvm {
class AllocaInst;
class BasicBlock;
class BranchInst;
//class Function;
class MDNode;
}
namespace pyston {
class CFGBlock;
class GCBuilder;
class ScopeInfo;
class TypeAnalysis;
typedef std::unordered_map<std::string, CompilerVariable*> SymbolTable;
typedef std::map<std::string, CompilerVariable*> SortedSymbolTable;
typedef std::unordered_map<std::string, ConcreteCompilerVariable*> ConcreteSymbolTable;
// Class that holds state of the current IR generation, that might not be local
// to the specific phase or pass we're in.
// TODO this probably shouldn't be here
class IRGenState {
private:
CompiledFunction *cf;
SourceInfo* source_info;
GCBuilder *gc;
llvm::MDNode* func_dbg_info;
llvm::AllocaInst *scratch_space;
int scratch_size;
public:
IRGenState(CompiledFunction *cf, SourceInfo* source_info, GCBuilder *gc, llvm::MDNode* func_dbg_info) : cf(cf), source_info(source_info), gc(gc), func_dbg_info(func_dbg_info), scratch_space(NULL), scratch_size(0) {
assert(cf->func);
assert(!cf->clfunc); // in this case don't need to pass in sourceinfo
}
CompiledFunction* getCurFunction() {
return cf;
}
llvm::Function* getLLVMFunction() {
return cf->func;
}
EffortLevel::EffortLevel getEffortLevel() {
return cf->effort;
}
GCBuilder* getGC() {
return gc;
}
llvm::Value* getScratchSpace(int min_bytes);
ConcreteCompilerType* getReturnType() {
assert(cf->sig);
return cf->sig->rtn_type;
}
SourceInfo* getSourceInfo() {
return source_info;
}
ScopeInfo* getScopeInfo();
llvm::MDNode* getFuncDbgInfo() {
return func_dbg_info;
}
};
class GuardList {
public:
struct ExprTypeGuard {
CFGBlock *cfg_block;
llvm::BranchInst* branch;
AST_expr* ast_node;
CompilerVariable* val;
SymbolTable st;
ExprTypeGuard(CFGBlock *cfg_block, llvm::BranchInst* branch, AST_expr* ast_node, CompilerVariable* val, const SymbolTable &st);
};
struct BlockEntryGuard {
CFGBlock *cfg_block;
llvm::BranchInst* branch;
SymbolTable symbol_table;
BlockEntryGuard(CFGBlock *cfg_block, llvm::BranchInst* branch, const SymbolTable &symbol_table);
};
private:
std::unordered_map<AST_expr*, ExprTypeGuard*> expr_type_guards;
std::unordered_map<CFGBlock*, std::vector<BlockEntryGuard*> > block_begin_guards;
public:
typedef std::unordered_map<AST_expr*, ExprTypeGuard*>::iterator expr_type_guard_iterator;
typedef std::unordered_map<AST_expr*, ExprTypeGuard*>::const_iterator expr_type_guard_const_iterator;
expr_type_guard_iterator after_begin() {
return expr_type_guards.begin();
}
expr_type_guard_iterator after_end() {
return expr_type_guards.end();
}
ExprTypeGuard* getNodeTypeGuard(AST_expr* node) const {
expr_type_guard_const_iterator it = expr_type_guards.find(node);
if (it == expr_type_guards.end())
return NULL;
return it->second;
}
bool isEmpty() const {
return expr_type_guards.size() == 0;
}
void addExprTypeGuard(CFGBlock *cfg_block, llvm::BranchInst* branch, AST_expr* ast_node, CompilerVariable* val, const SymbolTable &st) {
ExprTypeGuard* &g = expr_type_guards[ast_node];
assert(g == NULL);
g = new ExprTypeGuard(cfg_block, branch, ast_node, val, st);
}
void registerGuardForBlockEntry(CFGBlock *cfg_block, llvm::BranchInst* branch, const SymbolTable &st) {
std::vector<BlockEntryGuard*> &v = block_begin_guards[cfg_block];
v.push_back(new BlockEntryGuard(cfg_block, branch, st));
}
const std::vector<BlockEntryGuard*>& getGuardsForBlock(CFGBlock *block) const {
std::unordered_map<CFGBlock*, std::vector<BlockEntryGuard*> >::const_iterator it = block_begin_guards.find(block);
if (it != block_begin_guards.end())
return it->second;
static std::vector<BlockEntryGuard*> empty_list;
return empty_list;
}
};
class IRGenerator {
private:
public:
struct EndingState {
SymbolTable* symbol_table;
ConcreteSymbolTable* phi_symbol_table;
llvm::BasicBlock* ending_block;
EndingState(SymbolTable* symbol_table, ConcreteSymbolTable* phi_symbol_table, llvm::BasicBlock* ending_block) :
symbol_table(symbol_table), phi_symbol_table(phi_symbol_table), ending_block(ending_block) {}
};
virtual void unpackArguments(const std::vector<AST_expr*> &arg_names, const std::vector<ConcreteCompilerType*> &arg_types) = 0;
virtual void giveLocalSymbol(const std::string &name, CompilerVariable *var) = 0;
virtual void copySymbolsFrom(SymbolTable* st) = 0;
virtual void run(const CFGBlock* block) = 0;
virtual EndingState getEndingSymbolTable() = 0;
};
IREmitter *createIREmitter(IRGenState *irstate);
IRGenerator *createIRGenerator(IRGenState *irstate, std::vector<llvm::BasicBlock*> &entry_blocks, CFGBlock *myblock, TypeAnalysis *types, GuardList &out_guards, const GuardList &in_guards, bool is_partial);
}
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment