bool-ifying xe::cpu

This commit is contained in:
Ben Vanik
2015-05-05 17:21:08 -07:00
parent a38b05db24
commit ade5388728
67 changed files with 270 additions and 347 deletions

View File

@@ -27,18 +27,18 @@ void Compiler::AddPass(std::unique_ptr<CompilerPass> pass) {
void Compiler::Reset() {}
int Compiler::Compile(xe::cpu::hir::HIRBuilder* builder) {
bool Compiler::Compile(xe::cpu::hir::HIRBuilder* builder) {
// TODO(benvanik): sophisticated stuff. Run passes in parallel, run until they
// stop changing things, etc.
for (size_t i = 0; i < passes_.size(); ++i) {
auto& pass = passes_[i];
scratch_arena_.Reset();
if (pass->Run(builder)) {
return 1;
if (!pass->Run(builder)) {
return false;
}
}
return 0;
return true;
}
} // namespace compiler

View File

@@ -40,7 +40,7 @@ class Compiler {
void Reset();
int Compile(hir::HIRBuilder* builder);
bool Compile(hir::HIRBuilder* builder);
private:
Processor* processor_;

View File

@@ -19,10 +19,10 @@ CompilerPass::CompilerPass() : processor_(nullptr), compiler_(nullptr) {}
CompilerPass::~CompilerPass() = default;
int CompilerPass::Initialize(Compiler* compiler) {
bool CompilerPass::Initialize(Compiler* compiler) {
processor_ = compiler->processor();
compiler_ = compiler;
return 0;
return true;
}
Arena* CompilerPass::scratch_arena() const {

View File

@@ -30,9 +30,9 @@ class CompilerPass {
CompilerPass();
virtual ~CompilerPass();
virtual int Initialize(Compiler* compiler);
virtual bool Initialize(Compiler* compiler);
virtual int Run(hir::HIRBuilder* builder) = 0;
virtual bool Run(hir::HIRBuilder* builder) = 0;
protected:
Arena* scratch_arena() const;

View File

@@ -30,7 +30,7 @@ ConstantPropagationPass::ConstantPropagationPass() : CompilerPass() {}
ConstantPropagationPass::~ConstantPropagationPass() {}
int ConstantPropagationPass::Run(HIRBuilder* builder) {
bool 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:
@@ -98,7 +98,7 @@ int ConstantPropagationPass::Run(HIRBuilder* builder) {
case OPCODE_CALL_INDIRECT:
if (i->src1.value->IsConstant()) {
FunctionInfo* symbol_info;
if (processor_->LookupFunctionInfo(
if (!processor_->LookupFunctionInfo(
(uint32_t)i->src1.value->constant.i32, &symbol_info)) {
break;
}
@@ -468,7 +468,7 @@ int ConstantPropagationPass::Run(HIRBuilder* builder) {
block = block->next;
}
return 0;
return true;
}
void ConstantPropagationPass::PropagateCarry(Value* v, bool did_carry) {

View File

@@ -22,7 +22,7 @@ class ConstantPropagationPass : public CompilerPass {
ConstantPropagationPass();
~ConstantPropagationPass() override;
int Run(hir::HIRBuilder* builder) override;
bool Run(hir::HIRBuilder* builder) override;
private:
void PropagateCarry(hir::Value* v, bool did_carry);

View File

@@ -36,9 +36,9 @@ ContextPromotionPass::ContextPromotionPass() : CompilerPass() {}
ContextPromotionPass::~ContextPromotionPass() {}
int ContextPromotionPass::Initialize(Compiler* compiler) {
if (CompilerPass::Initialize(compiler)) {
return 1;
bool ContextPromotionPass::Initialize(Compiler* compiler) {
if (!CompilerPass::Initialize(compiler)) {
return false;
}
// This is a terrible implementation.
@@ -46,10 +46,10 @@ int ContextPromotionPass::Initialize(Compiler* compiler) {
context_values_.resize(context_info->size());
context_validity_.resize(static_cast<uint32_t>(context_info->size()));
return 0;
return true;
}
int ContextPromotionPass::Run(HIRBuilder* builder) {
bool 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:
@@ -82,7 +82,7 @@ int ContextPromotionPass::Run(HIRBuilder* builder) {
}
}
return 0;
return true;
}
void ContextPromotionPass::PromoteBlock(Block* block) {

View File

@@ -34,9 +34,9 @@ class ContextPromotionPass : public CompilerPass {
ContextPromotionPass();
virtual ~ContextPromotionPass() override;
int Initialize(Compiler* compiler) override;
bool Initialize(Compiler* compiler) override;
int Run(hir::HIRBuilder* builder) override;
bool Run(hir::HIRBuilder* builder) override;
private:
void PromoteBlock(hir::Block* block);

View File

@@ -29,7 +29,7 @@ ControlFlowAnalysisPass::ControlFlowAnalysisPass() : CompilerPass() {}
ControlFlowAnalysisPass::~ControlFlowAnalysisPass() {}
int ControlFlowAnalysisPass::Run(HIRBuilder* builder) {
bool ControlFlowAnalysisPass::Run(HIRBuilder* builder) {
// Reset edges for all blocks. Needed to be re-runnable.
// Note that this wastes a bunch of arena memory, so we shouldn't
// re-run too often.
@@ -71,7 +71,7 @@ int ControlFlowAnalysisPass::Run(HIRBuilder* builder) {
block = block->next;
}
return 0;
return true;
}
} // namespace passes

View File

@@ -22,7 +22,7 @@ class ControlFlowAnalysisPass : public CompilerPass {
ControlFlowAnalysisPass();
~ControlFlowAnalysisPass() override;
int Run(hir::HIRBuilder* builder) override;
bool Run(hir::HIRBuilder* builder) override;
private:
};

View File

@@ -30,7 +30,7 @@ ControlFlowSimplificationPass::ControlFlowSimplificationPass()
ControlFlowSimplificationPass::~ControlFlowSimplificationPass() {}
int ControlFlowSimplificationPass::Run(HIRBuilder* builder) {
bool ControlFlowSimplificationPass::Run(HIRBuilder* builder) {
// Walk backwards and merge blocks if possible.
bool merged_any = false;
auto block = builder->last_block();
@@ -52,7 +52,7 @@ int ControlFlowSimplificationPass::Run(HIRBuilder* builder) {
block = prev_block;
}
return 0;
return true;
}
} // namespace passes

View File

@@ -22,7 +22,7 @@ class ControlFlowSimplificationPass : public CompilerPass {
ControlFlowSimplificationPass();
~ControlFlowSimplificationPass() override;
int Run(hir::HIRBuilder* builder) override;
bool Run(hir::HIRBuilder* builder) override;
private:
};

View File

@@ -42,14 +42,14 @@ DataFlowAnalysisPass::DataFlowAnalysisPass() : CompilerPass() {}
DataFlowAnalysisPass::~DataFlowAnalysisPass() {}
int DataFlowAnalysisPass::Run(HIRBuilder* builder) {
bool DataFlowAnalysisPass::Run(HIRBuilder* builder) {
// Linearize blocks so that we can detect cycles and propagate dependencies.
uint32_t block_count = LinearizeBlocks(builder);
// Analyze value flow and add locals as needed.
AnalyzeFlow(builder, block_count);
return 0;
return true;
}
uint32_t DataFlowAnalysisPass::LinearizeBlocks(HIRBuilder* builder) {

View File

@@ -22,7 +22,7 @@ class DataFlowAnalysisPass : public CompilerPass {
DataFlowAnalysisPass();
~DataFlowAnalysisPass() override;
int Run(hir::HIRBuilder* builder) override;
bool Run(hir::HIRBuilder* builder) override;
private:
uint32_t LinearizeBlocks(hir::HIRBuilder* builder);

View File

@@ -27,7 +27,7 @@ DeadCodeEliminationPass::DeadCodeEliminationPass() : CompilerPass() {}
DeadCodeEliminationPass::~DeadCodeEliminationPass() {}
int DeadCodeEliminationPass::Run(HIRBuilder* builder) {
bool 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:
@@ -143,7 +143,7 @@ int DeadCodeEliminationPass::Run(HIRBuilder* builder) {
}
}
return 0;
return true;
}
void DeadCodeEliminationPass::MakeNopRecursive(Instr* i) {

View File

@@ -22,7 +22,7 @@ class DeadCodeEliminationPass : public CompilerPass {
DeadCodeEliminationPass();
~DeadCodeEliminationPass() override;
int Run(hir::HIRBuilder* builder) override;
bool Run(hir::HIRBuilder* builder) override;
private:
void MakeNopRecursive(hir::Instr* i);

View File

@@ -28,7 +28,7 @@ FinalizationPass::FinalizationPass() : CompilerPass() {}
FinalizationPass::~FinalizationPass() {}
int FinalizationPass::Run(HIRBuilder* builder) {
bool FinalizationPass::Run(HIRBuilder* builder) {
// Process the HIR and prepare it for lowering.
// After this is done the HIR should be ready for emitting.
@@ -65,7 +65,7 @@ int FinalizationPass::Run(HIRBuilder* builder) {
block = block->next;
}
return 0;
return true;
}
} // namespace passes

View File

@@ -22,7 +22,7 @@ class FinalizationPass : public CompilerPass {
FinalizationPass();
~FinalizationPass() override;
int Run(hir::HIRBuilder* builder) override;
bool Run(hir::HIRBuilder* builder) override;
private:
};

View File

@@ -69,7 +69,7 @@ RegisterAllocationPass::~RegisterAllocationPass() {
}
}
int RegisterAllocationPass::Run(HIRBuilder* builder) {
bool RegisterAllocationPass::Run(HIRBuilder* builder) {
// Simple per-block allocator that operates on SSA form.
// Registers do not move across blocks, though this could be
// optimized with some intra-block analysis (dominators/etc).
@@ -151,7 +151,7 @@ int RegisterAllocationPass::Run(HIRBuilder* builder) {
// Unable to spill anything - this shouldn't happen.
XELOGE("Unable to spill any registers");
assert_always();
return 1;
return false;
}
// Demand allocation.
@@ -159,7 +159,7 @@ int RegisterAllocationPass::Run(HIRBuilder* builder) {
// Boned.
XELOGE("Register allocation failed");
assert_always();
return 1;
return false;
}
}
}
@@ -169,7 +169,7 @@ int RegisterAllocationPass::Run(HIRBuilder* builder) {
block = block->next;
}
return 0;
return true;
}
void RegisterAllocationPass::DumpUsage(const char* name) {

View File

@@ -27,7 +27,7 @@ class RegisterAllocationPass : public CompilerPass {
RegisterAllocationPass(const backend::MachineInfo* machine_info);
~RegisterAllocationPass() override;
int Run(hir::HIRBuilder* builder) override;
bool Run(hir::HIRBuilder* builder) override;
private:
// TODO(benvanik): rewrite all this set shit -- too much indirection, the

View File

@@ -27,10 +27,10 @@ SimplificationPass::SimplificationPass() : CompilerPass() {}
SimplificationPass::~SimplificationPass() {}
int SimplificationPass::Run(HIRBuilder* builder) {
bool SimplificationPass::Run(HIRBuilder* builder) {
EliminateConversions(builder);
SimplifyAssignments(builder);
return 0;
return true;
}
void SimplificationPass::EliminateConversions(HIRBuilder* builder) {

View File

@@ -22,7 +22,7 @@ class SimplificationPass : public CompilerPass {
SimplificationPass();
~SimplificationPass() override;
int Run(hir::HIRBuilder* builder) override;
bool Run(hir::HIRBuilder* builder) override;
private:
void EliminateConversions(hir::HIRBuilder* builder);

View File

@@ -33,7 +33,7 @@ ValidationPass::ValidationPass() : CompilerPass() {}
ValidationPass::~ValidationPass() {}
int ValidationPass::Run(HIRBuilder* builder) {
bool ValidationPass::Run(HIRBuilder* builder) {
#if 0
StringBuffer str;
builder->Dump(&str);
@@ -48,15 +48,15 @@ int ValidationPass::Run(HIRBuilder* builder) {
while (label) {
assert_true(label->block == block);
if (label->block != block) {
return 1;
return false;
}
label = label->next;
}
auto instr = block->instr_head;
while (instr) {
if (ValidateInstruction(block, instr)) {
return 1;
if (!ValidateInstruction(block, instr)) {
return false;
}
instr = instr->next;
}
@@ -64,13 +64,13 @@ int ValidationPass::Run(HIRBuilder* builder) {
block = block->next;
}
return 0;
return true;
}
int ValidationPass::ValidateInstruction(Block* block, Instr* instr) {
bool ValidationPass::ValidateInstruction(Block* block, Instr* instr) {
assert_true(instr->block == block);
if (instr->block != block) {
return 1;
return false;
}
if (instr->dest) {
@@ -84,33 +84,33 @@ int ValidationPass::ValidateInstruction(Block* block, Instr* instr) {
uint32_t signature = instr->opcode->signature;
if (GET_OPCODE_SIG_TYPE_SRC1(signature) == OPCODE_SIG_TYPE_V) {
if (ValidateValue(block, instr, instr->src1.value)) {
return 1;
if (!ValidateValue(block, instr, instr->src1.value)) {
return false;
}
}
if (GET_OPCODE_SIG_TYPE_SRC2(signature) == OPCODE_SIG_TYPE_V) {
if (ValidateValue(block, instr, instr->src2.value)) {
return 1;
if (!ValidateValue(block, instr, instr->src2.value)) {
return false;
}
}
if (GET_OPCODE_SIG_TYPE_SRC3(signature) == OPCODE_SIG_TYPE_V) {
if (ValidateValue(block, instr, instr->src3.value)) {
return 1;
if (!ValidateValue(block, instr, instr->src3.value)) {
return false;
}
}
return 0;
return true;
}
int ValidationPass::ValidateValue(Block* block, Instr* instr, Value* value) {
bool ValidationPass::ValidateValue(Block* block, Instr* instr, Value* value) {
// if (value->def) {
// auto def = value->def;
// assert_true(def->block == block);
// if (def->block != block) {
// return 1;
// return false;
// }
//}
return 0;
return true;
}
} // namespace passes

View File

@@ -22,11 +22,11 @@ class ValidationPass : public CompilerPass {
ValidationPass();
~ValidationPass() override;
int Run(hir::HIRBuilder* builder) override;
bool Run(hir::HIRBuilder* builder) override;
private:
int ValidateInstruction(hir::Block* block, hir::Instr* instr);
int ValidateValue(hir::Block* block, hir::Instr* instr, hir::Value* value);
bool ValidateInstruction(hir::Block* block, hir::Instr* instr);
bool ValidateValue(hir::Block* block, hir::Instr* instr, hir::Value* value);
};
} // namespace passes

View File

@@ -58,7 +58,7 @@ void ValueReductionPass::ComputeLastUse(Value* value) {
value->last_use = last_use ? last_use->instr : nullptr;
}
int ValueReductionPass::Run(HIRBuilder* builder) {
bool ValueReductionPass::Run(HIRBuilder* builder) {
// Walk each block and reuse variable ordinals as much as possible.
llvm::BitVector ordinals(builder->max_value_ordinal());
@@ -139,7 +139,7 @@ int ValueReductionPass::Run(HIRBuilder* builder) {
block = block->next;
}
return 0;
return true;
}
} // namespace passes

View File

@@ -22,7 +22,7 @@ class ValueReductionPass : public CompilerPass {
ValueReductionPass();
~ValueReductionPass() override;
int Run(hir::HIRBuilder* builder) override;
bool Run(hir::HIRBuilder* builder) override;
private:
void ComputeLastUse(hir::Value* value);