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
2 changes: 0 additions & 2 deletions src/backend/analysis/address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include "ir/opcode.h"
#include "ir/type.h"

#include <algorithm>

namespace rat {
namespace {
// extract a compile-time constant value; false if n is not a constant
Expand Down
15 changes: 6 additions & 9 deletions src/backend/analysis/alias_analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define RAT_ANALYSIS_ALIASANALYSIS_H

#include "core.h"
#include "hash.h"

namespace rat {
struct Node;
Expand Down Expand Up @@ -37,16 +38,12 @@ namespace rat {

struct MustAliasKeyHash {
U64 operator()(const MustAliasKey& k) const {
U64 h = 1469598103934665603ull; // FNV-1a
auto mix = [&](U64 v) {
h ^= v;
h *= 1099511628211ull;
};
mix(reinterpret_cast<U64>(k.base));
mix((U64)k.constant);
mix((U64)k.size);
U64 h = kFnvBasis;
hashMix(h, reinterpret_cast<U64>(k.base));
hashMix(h, (U64)k.constant);
hashMix(h, (U64)k.size);
for(Node* s : k.symbolic)
mix(reinterpret_cast<U64>(s));
hashMix(h, reinterpret_cast<U64>(s));
return h;
}
};
Expand Down
3 changes: 3 additions & 0 deletions src/backend/ir/text_parser.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "ir/text_parser.h"

#include <cctype>
#include <cerrno>
#include <cstdlib>
#include <sstream>

#include "ir/function.h"
#include "ir/module.h"
Expand Down
2 changes: 2 additions & 0 deletions src/backend/ir/text_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "core.h"
#include "ir/opcode.h"

#include <iosfwd>

namespace rat {
struct Module;
struct Type;
Expand Down
2 changes: 2 additions & 0 deletions src/backend/ir/type.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "ir/type.h"

#include <sstream>

namespace rat {
Type::Type(Kind kind, U32 bits, List<Type*> elements)
: kind(kind),
Expand Down
2 changes: 2 additions & 0 deletions src/backend/ir/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "core.h"

#include <iosfwd>

namespace rat {
struct Type {
enum Kind {
Expand Down
2 changes: 2 additions & 0 deletions src/backend/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "cli.h"
#include "ir/text_parser.h"

#include <iostream>

using namespace rat;

namespace detail {
Expand Down
2 changes: 2 additions & 0 deletions src/backend/pass/emit/graph_emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "ir/module.h"
#include "ir/node.h"

#include <ostream>

namespace rat {
namespace detail {
void writeId(std::ostream& os, U32 fnIndex, const Node* n) {
Expand Down
2 changes: 2 additions & 0 deletions src/backend/pass/emit/graph_emitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "core.h"
#include "pass/pass.h"

#include <iosfwd>

namespace rat {
struct Function;
struct Node;
Expand Down
2 changes: 2 additions & 0 deletions src/backend/pass/emit/text_emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "ir/module.h"
#include "ir/node.h"

#include <ostream>

namespace rat {
void TextEmitterPass::comment(std::ostream& os, const C8* text) { os << Green << text << Reset; }

Expand Down
2 changes: 2 additions & 0 deletions src/backend/pass/emit/text_emitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "core.h"
#include "pass/pass.h"

#include <iosfwd>

namespace rat {
struct Function;
struct Module;
Expand Down
2 changes: 2 additions & 0 deletions src/backend/pass/emit/x86/x86_encode.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "pass/pass.h"
#include "target/x86/x86_asm.h"

#include <iosfwd>

namespace rat {
struct Global;
struct ObjectFile;
Expand Down
10 changes: 5 additions & 5 deletions src/backend/pass/emit/x86/x86_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "pass/emit/x86/x86_op.h"

namespace rat {
namespace {
namespace detail {
B32 isPureTestBlock(const MachineBlock& b) {
if(b.insts.empty() || b.insts.size() > 3)
return false;
Expand Down Expand Up @@ -172,15 +172,15 @@ namespace rat {
}
mf.blocks = std::move(arranged);
}
} // namespace
} // namespace detail

B32 X86LayoutPass::run(Module& module, MachineModule& mm, const TargetInfo&) {
U32 changed = 0;
for(const Function* fn : module) {
MachineFunc& mf = mm.get(fn);
changed += runOnFunction(mf);
changed += forwardJumpChains(mf);
chainLayout(mf);
changed += detail::runOnFunction(mf);
changed += detail::forwardJumpChains(mf);
detail::chainLayout(mf);
}
return changed != 0;
}
Expand Down
2 changes: 0 additions & 2 deletions src/backend/pass/emit/x86/x86_lower.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include "pass/emit/x86/x86_op.h"
#include "pass/pass.h"

#include <cstdint>

namespace rat {
struct BinaryNode;
struct CallNode;
Expand Down
9 changes: 4 additions & 5 deletions src/backend/pass/emit/x86/x86_lower_ops.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "pass/emit/x86/x86_lower.h"

#include "codegen/machine_function.h"
#include "hash.h"
#include "ir/function.h"
#include "ir/module.h"
#include "ir/node.h"
Expand Down Expand Up @@ -273,11 +274,9 @@ namespace rat {

String X86LowerPass::vecPoolSym(const List<U8>& bytes) {
C8 buf[48];
U64 h = 1469598103934665603ull;
for(U8 x : bytes) {
h ^= x;
h *= 1099511628211ull;
}
U64 h = kFnvBasis;
for(U8 x : bytes)
hashMix(h, x);
std::snprintf(buf, sizeof buf, "__rat_vec_%016lx", (U64)h);
String name(buf);
if(!mod->getGlobal(name)) {
Expand Down
19 changes: 8 additions & 11 deletions src/backend/pass/opt/gvn.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define RAT_PASS_OPT_GVN_H

#include "core.h"
#include "hash.h"
#include "pass/pass.h"

namespace rat {
Expand All @@ -32,18 +33,14 @@ namespace rat {

struct GVNKeyHash {
U64 operator()(const GVNKey& k) const {
U64 h = 1469598103934665603ull;
auto mix = [&](U64 v) {
h ^= v;
h *= 1099511628211ull;
};
mix(k.op);
mix(k.type);
mix((U64)k.payload);
mix(k.in0);
mix(((U64)k.in1) << 32);
U64 h = kFnvBasis;
hashMix(h, k.op);
hashMix(h, k.type);
hashMix(h, (U64)k.payload);
hashMix(h, k.in0);
hashMix(h, ((U64)k.in1) << 32);
if(k.sym)
mix(std::hash<String>{}(*k.sym));
hashMix(h, std::hash<String>{}(*k.sym));
return (U64)h;
}
};
Expand Down
5 changes: 3 additions & 2 deletions src/backend/pass/opt/inline.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "pass/opt/inline.h"

#include "hash.h"
#include "ir/function.h"
#include "ir/module.h"
#include "ir/node.h"
Expand Down Expand Up @@ -236,9 +237,9 @@ namespace rat {

// caller version folded with its direct callees' versions
U64 InlinePass::quietStamp(const Function& caller, const Info& info) const {
U64 stamp = 14695981039346656037ull ^ caller.getVersion();
U64 stamp = kFnvBasis ^ caller.getVersion();
for(Info* callee : info.callees)
stamp = stamp * 1099511628211ull + callee->fn->getVersion();
stamp = stamp * kFnvPrime + callee->fn->getVersion();
return stamp;
}

Expand Down
2 changes: 1 addition & 1 deletion src/backend/pass/pass_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include "ir/module.h"

#include <chrono>
#include <cstring>
#include <iomanip>
#include <ostream>

namespace rat {
Pass* PassManager::add(UniquePtr<Pass> pass) {
Expand Down
1 change: 1 addition & 0 deletions src/backend/pass/pass_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "core.h"
#include "pass/pass.h"

#include <iosfwd>
#include <type_traits>

namespace rat {
Expand Down
1 change: 1 addition & 0 deletions src/backend/pass/pass_registry.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "pass/pass_registry.h"

#include <iomanip>
#include <ostream>

#include "pass/pass.h"
#include "string.h"
Expand Down
2 changes: 2 additions & 0 deletions src/backend/pass/pass_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "core.h"
#include "pass/pass_manager.h"

#include <iosfwd>

namespace rat {
UniquePtr<Pass> createPass(const String& name, std::ostream& out);
UniquePtr<MachinePass> createMachinePass(const String& name, std::ostream& out);
Expand Down
2 changes: 2 additions & 0 deletions src/backend/pass/verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "ir/node.h"
#include "ir/type.h"

#include <sstream>

namespace rat {
VerifyPass::FunctionVerifier::FunctionVerifier(const Function& fn, List<String>& e)
: fn(fn),
Expand Down
2 changes: 2 additions & 0 deletions src/backend/pass/verify.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "core.h"
#include "pass/pass.h"

#include <iosfwd>

namespace rat {
struct Function;
struct Module;
Expand Down
2 changes: 2 additions & 0 deletions src/backend/target/object_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "target/target.h"

#include <iosfwd>

namespace rat {
enum class RelocKind : U32 {
Abs64 = 1, // absolute 64-bit address (S + A)
Expand Down
2 changes: 2 additions & 0 deletions src/backend/target/x86/x86_coff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "byte_io.h"

#include <ostream>

namespace rat {
namespace detail {
constexpr U16 IMAGE_FILE_MACHINE_AMD64 = 0x8664;
Expand Down
2 changes: 2 additions & 0 deletions src/backend/target/x86/x86_elf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "byte_io.h"
#include "elf_file.h"

#include <ostream>

namespace rat {
namespace detail {
constexpr U8 kElfMag[4] = {0x7f, 'E', 'L', 'F'};
Expand Down
1 change: 1 addition & 0 deletions src/backend/test/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "string.h"
#include "test_harness.h"
#include <fstream>
#include <sstream>

#include "rat.h"

Expand Down
2 changes: 2 additions & 0 deletions src/base/cli.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#ifndef RAT_BASE_CLI_H
#define RAT_BASE_CLI_H

#include <cstdlib>
#include <fstream>
#include <iostream>

#include "core.h"
#include "git_hash.h"
Expand Down
6 changes: 1 addition & 5 deletions src/base/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <memory>
#include <ostream>
#include <sstream>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
Expand Down
17 changes: 17 additions & 0 deletions src/base/hash.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef RAT_BASE_HASH_H
#define RAT_BASE_HASH_H

#include "core.h"

namespace rat {
// FNV-1a 64-bit
constexpr U64 kFnvBasis = 14695981039346656037ull;
constexpr U64 kFnvPrime = 1099511628211ull;

inline void hashMix(U64& h, U64 v) {
h ^= v;
h *= kFnvPrime;
}
} // namespace rat

#endif
3 changes: 3 additions & 0 deletions src/base/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include "core.h"

#include <cctype>
#include <sstream>

namespace rat {
inline B32 readAll(std::istream& in, String& out) {
std::ostringstream ss;
Expand Down
2 changes: 2 additions & 0 deletions src/base/test_harness.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "test_harness.h"

#include <atomic>
#include <cstdlib>
#include <filesystem>
#include <iostream>
#include <mutex>
#include <thread>

Expand Down
Loading
Loading