LIR skeleton, renaming some types to prevent conflict.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <alloy/compiler/compiler.h>
|
||||
|
||||
#include <alloy/compiler/pass.h>
|
||||
#include <alloy/compiler/compiler_pass.h>
|
||||
#include <alloy/compiler/tracing.h>
|
||||
|
||||
using namespace alloy;
|
||||
@@ -26,9 +26,9 @@ Compiler::Compiler(Runtime* runtime) :
|
||||
|
||||
Compiler::~Compiler() {
|
||||
Reset();
|
||||
|
||||
for (PassList::iterator it = passes_.begin(); it != passes_.end(); ++it) {
|
||||
Pass* pass = *it;
|
||||
|
||||
for (auto it = passes_.begin(); it != passes_.end(); ++it) {
|
||||
CompilerPass* pass = *it;
|
||||
delete pass;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ Compiler::~Compiler() {
|
||||
}));
|
||||
}
|
||||
|
||||
void Compiler::AddPass(Pass* pass) {
|
||||
void Compiler::AddPass(CompilerPass* pass) {
|
||||
pass->Initialize(this);
|
||||
passes_.push_back(pass);
|
||||
}
|
||||
@@ -44,15 +44,15 @@ void Compiler::AddPass(Pass* pass) {
|
||||
void Compiler::Reset() {
|
||||
}
|
||||
|
||||
int Compiler::Compile(FunctionBuilder* builder) {
|
||||
int Compiler::Compile(HIRBuilder* builder) {
|
||||
// TODO(benvanik): sophisticated stuff. Run passes in parallel, run until they
|
||||
// stop changing things, etc.
|
||||
for (PassList::iterator it = passes_.begin(); it != passes_.end(); ++it) {
|
||||
Pass* pass = *it;
|
||||
for (auto it = passes_.begin(); it != passes_.end(); ++it) {
|
||||
CompilerPass* pass = *it;
|
||||
if (pass->Run(builder)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#define ALLOY_COMPILER_COMPILER_H_
|
||||
|
||||
#include <alloy/core.h>
|
||||
#include <alloy/hir/function_builder.h>
|
||||
#include <alloy/hir/hir_builder.h>
|
||||
|
||||
namespace alloy { namespace runtime { class Runtime; } }
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace alloy { namespace runtime { class Runtime; } }
|
||||
namespace alloy {
|
||||
namespace compiler {
|
||||
|
||||
class Pass;
|
||||
class CompilerPass;
|
||||
|
||||
|
||||
class Compiler {
|
||||
@@ -28,17 +28,17 @@ public:
|
||||
~Compiler();
|
||||
|
||||
runtime::Runtime* runtime() const { return runtime_; }
|
||||
|
||||
void AddPass(Pass* pass);
|
||||
|
||||
void AddPass(CompilerPass* pass);
|
||||
|
||||
void Reset();
|
||||
|
||||
int Compile(hir::FunctionBuilder* builder);
|
||||
int Compile(hir::HIRBuilder* builder);
|
||||
|
||||
private:
|
||||
runtime::Runtime* runtime_;
|
||||
|
||||
typedef std::vector<Pass*> PassList;
|
||||
typedef std::vector<CompilerPass*> PassList;
|
||||
PassList passes_;
|
||||
};
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <alloy/compiler/pass.h>
|
||||
#include <alloy/compiler/compiler_pass.h>
|
||||
|
||||
#include <alloy/compiler/compiler.h>
|
||||
|
||||
@@ -15,14 +15,14 @@ using namespace alloy;
|
||||
using namespace alloy::compiler;
|
||||
|
||||
|
||||
Pass::Pass() :
|
||||
CompilerPass::CompilerPass() :
|
||||
runtime_(0), compiler_(0) {
|
||||
}
|
||||
|
||||
Pass::~Pass() {
|
||||
CompilerPass::~CompilerPass() {
|
||||
}
|
||||
|
||||
int Pass::Initialize(Compiler* compiler) {
|
||||
int CompilerPass::Initialize(Compiler* compiler) {
|
||||
runtime_ = compiler->runtime();
|
||||
compiler_ = compiler;
|
||||
return 0;
|
||||
@@ -7,12 +7,12 @@
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_COMPILER_PASS_H_
|
||||
#define ALLOY_COMPILER_PASS_H_
|
||||
#ifndef ALLOY_COMPILER_COMPILER_PASS_H_
|
||||
#define ALLOY_COMPILER_COMPILER_PASS_H_
|
||||
|
||||
#include <alloy/core.h>
|
||||
|
||||
#include <alloy/hir/function_builder.h>
|
||||
#include <alloy/hir/hir_builder.h>
|
||||
|
||||
namespace alloy { namespace runtime { class Runtime; } }
|
||||
|
||||
@@ -23,14 +23,14 @@ namespace compiler {
|
||||
class Compiler;
|
||||
|
||||
|
||||
class Pass {
|
||||
class CompilerPass {
|
||||
public:
|
||||
Pass();
|
||||
virtual ~Pass();
|
||||
CompilerPass();
|
||||
virtual ~CompilerPass();
|
||||
|
||||
virtual int Initialize(Compiler* compiler);
|
||||
|
||||
virtual int Run(hir::FunctionBuilder* builder) = 0;
|
||||
virtual int Run(hir::HIRBuilder* builder) = 0;
|
||||
|
||||
protected:
|
||||
runtime::Runtime* runtime_;
|
||||
@@ -42,4 +42,4 @@ protected:
|
||||
} // namespace alloy
|
||||
|
||||
|
||||
#endif // ALLOY_COMPILER_PASS_H_
|
||||
#endif // ALLOY_COMPILER_COMPILER_PASS_H_
|
||||
@@ -7,8 +7,8 @@
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_COMPILER_PASSES_H_
|
||||
#define ALLOY_COMPILER_PASSES_H_
|
||||
#ifndef ALLOY_COMPILER_COMPILER_PASSES_H_
|
||||
#define ALLOY_COMPILER_COMPILER_PASSES_H_
|
||||
|
||||
#include <alloy/compiler/passes/constant_propagation_pass.h>
|
||||
#include <alloy/compiler/passes/context_promotion_pass.h>
|
||||
@@ -133,4 +133,4 @@
|
||||
// branch_true v5, ...
|
||||
//
|
||||
|
||||
#endif // ALLOY_COMPILER_PASSES_H_
|
||||
#endif // ALLOY_COMPILER_COMPILER_PASSES_H_
|
||||
@@ -16,13 +16,13 @@ using namespace alloy::hir;
|
||||
|
||||
|
||||
ConstantPropagationPass::ConstantPropagationPass() :
|
||||
Pass() {
|
||||
CompilerPass() {
|
||||
}
|
||||
|
||||
ConstantPropagationPass::~ConstantPropagationPass() {
|
||||
}
|
||||
|
||||
int ConstantPropagationPass::Run(FunctionBuilder* builder) {
|
||||
int ConstantPropagationPass::Run(HIRBuilder* builder) {
|
||||
// Once ContextPromotion has run there will likely be a whole slew of
|
||||
// constants that can be pushed through the function.
|
||||
// Example:
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#ifndef ALLOY_COMPILER_PASSES_CONSTANT_PROPAGATION_PASS_H_
|
||||
#define ALLOY_COMPILER_PASSES_CONSTANT_PROPAGATION_PASS_H_
|
||||
|
||||
#include <alloy/compiler/pass.h>
|
||||
#include <alloy/compiler/compiler_pass.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
@@ -18,12 +18,12 @@ namespace compiler {
|
||||
namespace passes {
|
||||
|
||||
|
||||
class ConstantPropagationPass : public Pass {
|
||||
class ConstantPropagationPass : public CompilerPass {
|
||||
public:
|
||||
ConstantPropagationPass();
|
||||
virtual ~ConstantPropagationPass();
|
||||
|
||||
virtual int Run(hir::FunctionBuilder* builder);
|
||||
virtual int Run(hir::HIRBuilder* builder);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
@@ -22,7 +22,7 @@ using namespace alloy::runtime;
|
||||
|
||||
ContextPromotionPass::ContextPromotionPass() :
|
||||
context_values_size_(0), context_values_(0),
|
||||
Pass() {
|
||||
CompilerPass() {
|
||||
}
|
||||
|
||||
ContextPromotionPass::~ContextPromotionPass() {
|
||||
@@ -32,7 +32,7 @@ ContextPromotionPass::~ContextPromotionPass() {
|
||||
}
|
||||
|
||||
int ContextPromotionPass::Initialize(Compiler* compiler) {
|
||||
if (Pass::Initialize(compiler)) {
|
||||
if (CompilerPass::Initialize(compiler)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ int ContextPromotionPass::Initialize(Compiler* compiler) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ContextPromotionPass::Run(FunctionBuilder* builder) {
|
||||
int ContextPromotionPass::Run(HIRBuilder* builder) {
|
||||
// Like mem2reg, but because context memory is unaliasable it's easier to
|
||||
// check and convert LoadContext/StoreContext into value operations.
|
||||
// Example of load->value promotion:
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#ifndef ALLOY_COMPILER_PASSES_CONTEXT_PROMOTION_PASS_H_
|
||||
#define ALLOY_COMPILER_PASSES_CONTEXT_PROMOTION_PASS_H_
|
||||
|
||||
#include <alloy/compiler/pass.h>
|
||||
#include <alloy/compiler/compiler_pass.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
@@ -18,14 +18,14 @@ namespace compiler {
|
||||
namespace passes {
|
||||
|
||||
|
||||
class ContextPromotionPass : public Pass {
|
||||
class ContextPromotionPass : public CompilerPass {
|
||||
public:
|
||||
ContextPromotionPass();
|
||||
virtual ~ContextPromotionPass();
|
||||
|
||||
virtual int Initialize(Compiler* compiler);
|
||||
|
||||
virtual int Run(hir::FunctionBuilder* builder);
|
||||
virtual int Run(hir::HIRBuilder* builder);
|
||||
|
||||
private:
|
||||
void PromoteBlock(hir::Block* block);
|
||||
|
||||
@@ -16,13 +16,13 @@ using namespace alloy::hir;
|
||||
|
||||
|
||||
DeadCodeEliminationPass::DeadCodeEliminationPass() :
|
||||
Pass() {
|
||||
CompilerPass() {
|
||||
}
|
||||
|
||||
DeadCodeEliminationPass::~DeadCodeEliminationPass() {
|
||||
}
|
||||
|
||||
int DeadCodeEliminationPass::Run(FunctionBuilder* builder) {
|
||||
int DeadCodeEliminationPass::Run(HIRBuilder* builder) {
|
||||
// ContextPromotion/DSE will likely leave around a lot of dead statements.
|
||||
// Code generated for comparison/testing produces many unused statements and
|
||||
// with proper use analysis it should be possible to remove most of them:
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#ifndef ALLOY_COMPILER_PASSES_DEAD_CODE_ELIMINATION_PASS_H_
|
||||
#define ALLOY_COMPILER_PASSES_DEAD_CODE_ELIMINATION_PASS_H_
|
||||
|
||||
#include <alloy/compiler/pass.h>
|
||||
#include <alloy/compiler/compiler_pass.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
@@ -18,12 +18,12 @@ namespace compiler {
|
||||
namespace passes {
|
||||
|
||||
|
||||
class DeadCodeEliminationPass : public Pass {
|
||||
class DeadCodeEliminationPass : public CompilerPass {
|
||||
public:
|
||||
DeadCodeEliminationPass();
|
||||
virtual ~DeadCodeEliminationPass();
|
||||
|
||||
virtual int Run(hir::FunctionBuilder* builder);
|
||||
virtual int Run(hir::HIRBuilder* builder);
|
||||
|
||||
private:
|
||||
void MakeNopRecursive(hir::Instr* i);
|
||||
|
||||
@@ -16,13 +16,13 @@ using namespace alloy::hir;
|
||||
|
||||
|
||||
SimplificationPass::SimplificationPass() :
|
||||
Pass() {
|
||||
CompilerPass() {
|
||||
}
|
||||
|
||||
SimplificationPass::~SimplificationPass() {
|
||||
}
|
||||
|
||||
int SimplificationPass::Run(FunctionBuilder* builder) {
|
||||
int SimplificationPass::Run(HIRBuilder* builder) {
|
||||
// Run over the instructions and rename assigned variables:
|
||||
// v1 = v0
|
||||
// v2 = v1
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#ifndef ALLOY_COMPILER_PASSES_SIMPLIFICATION_PASS_H_
|
||||
#define ALLOY_COMPILER_PASSES_SIMPLIFICATION_PASS_H_
|
||||
|
||||
#include <alloy/compiler/pass.h>
|
||||
#include <alloy/compiler/compiler_pass.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
@@ -18,12 +18,12 @@ namespace compiler {
|
||||
namespace passes {
|
||||
|
||||
|
||||
class SimplificationPass : public Pass {
|
||||
class SimplificationPass : public CompilerPass {
|
||||
public:
|
||||
SimplificationPass();
|
||||
virtual ~SimplificationPass();
|
||||
|
||||
virtual int Run(hir::FunctionBuilder* builder);
|
||||
virtual int Run(hir::HIRBuilder* builder);
|
||||
|
||||
private:
|
||||
hir::Value* CheckValue(hir::Value* value);
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
'sources': [
|
||||
'compiler.cc',
|
||||
'compiler.h',
|
||||
'pass.cc',
|
||||
'pass.h',
|
||||
'passes.h',
|
||||
'compiler_pass.cc',
|
||||
'compiler_pass.h',
|
||||
'compiler_passes.h',
|
||||
'tracing.h',
|
||||
],
|
||||
|
||||
|
||||
Reference in New Issue
Block a user