Skip to content

Commit 6521692

Browse files
committed
added option to toggle generic ptr emulation, made LEA smarter
1 parent 0e654c3 commit 6521692

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

src/driver/cli.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ if (strcmp(argv[i], "--no-"#name) == 0) { \
9090

9191
#define TOGGLE_OPTIONS(F) \
9292
F(lower.emulate_physical_memory, emulate-physical-memory) \
93+
F(lower.emulate_generic_ptrs, emulate-generic-pointers) \
9394
F(dynamic_scheduling, dynamic-scheduling) \
9495
F(hacks.force_join_point_lifting, lift-join-points) \
9596
F(hacks.assume_no_physical_global_ptrs, assume-no-physical-global-ptrs) \

src/driver/driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ SourceLanguage guess_source_language(const char* filename) {
3333
else if (string_ends_with(filename, ".slim"))
3434
return SrcShadyIR;
3535

36-
warn_print("unknown filename extension '%s', interpreting as Slim sourcecode by default.");
36+
warn_print("unknown filename extension '%s', interpreting as Slim sourcecode by default.", filename);
3737
return SrcSlim;
3838
}
3939

src/shady/compile.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ CompilationResult run_compiler_passes(CompilerConfig* config, Module** pmod) {
122122
RUN_PASS(lower_alloca)
123123
}
124124
RUN_PASS(lower_stack)
125-
if (config->lower.emulate_physical_memory) {
126-
RUN_PASS(lower_lea)
127-
}
125+
RUN_PASS(lower_lea)
128126
RUN_PASS(lower_generic_globals)
129127
if (config->lower.emulate_generic_ptrs) {
130128
RUN_PASS(lower_generic_ptrs)

src/shady/passes/lower_lea.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
#include "log.h"
99
#include "portability.h"
10+
#include "shady/ir.h"
1011

1112
#include <assert.h>
1213

1314
typedef struct {
1415
Rewriter rewriter;
16+
const CompilerConfig* config;
1517
} Context;
1618

1719
static const Node* lower_ptr_arithm(Context* ctx, BodyBuilder* bb, const Type* pointer_type, const Node* base, const Node* offset, size_t n_indices, const Node** indices) {
@@ -105,8 +107,11 @@ static const Node* process(Context* ctx, const Node* old) {
105107
assert(old_base_ptr_t->tag == PtrType_TAG);
106108
const Node* old_result_t = old->type;
107109
deconstruct_qualified_type(&old_result_t);
108-
// Leave logical ptrs alone
109-
if (!is_physical_as(old_base_ptr_t->payload.ptr_type.address_space))
110+
bool must_lower = false;
111+
// we have to lower generic pointers if we emulate them using ints
112+
must_lower |= ctx->config->lower.emulate_generic_ptrs && old_base_ptr_t->payload.ptr_type.address_space == AsGeneric;
113+
must_lower |= ctx->config->lower.emulate_physical_memory && is_physical_as(old_base_ptr_t->payload.ptr_type.address_space);
114+
if (!must_lower)
110115
break;
111116
BodyBuilder* bb = begin_body(a);
112117
Nodes new_ops = rewrite_nodes(&ctx->rewriter, old_ops);
@@ -132,7 +137,8 @@ Module* lower_lea(const CompilerConfig* config, Module* src) {
132137
IrArena* a = new_ir_arena(aconfig);
133138
Module* dst = new_module(a, get_module_name(src));
134139
Context ctx = {
135-
.rewriter = create_rewriter(src, dst, (RewriteNodeFn) process)
140+
.rewriter = create_rewriter(src, dst, (RewriteNodeFn) process),
141+
.config = config,
136142
};
137143
rewrite_module(&ctx.rewriter);
138144
destroy_rewriter(&ctx.rewriter);

0 commit comments

Comments
 (0)