Skip to content

Commit 1832a64

Browse files
committed
add flag for structure parsing
1 parent e6280df commit 1832a64

File tree

11 files changed

+23
-13
lines changed

11 files changed

+23
-13
lines changed

include/shady/driver.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ typedef enum {
2626
} SourceLanguage;
2727

2828
SourceLanguage guess_source_language(const char* filename);
29-
ShadyErrorCodes driver_load_source_file(SourceLanguage lang, size_t, const char* file_contents, Module* mod);
30-
ShadyErrorCodes driver_load_source_file_from_filename(const char* filename, Module* mod);
29+
ShadyErrorCodes driver_load_source_file(const CompilerConfig* config, SourceLanguage lang, size_t, const char* file_contents, Module* mod);
30+
ShadyErrorCodes driver_load_source_file_from_filename(const CompilerConfig* config, const char* filename, Module* mod);
3131

3232
typedef enum {
3333
TgtAuto,

include/shady/ir.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ struct CompilerConfig_ {
281281
bool force_join_point_lifting;
282282
bool assume_no_physical_global_ptrs;
283283
bool restructure_everything;
284+
bool recover_structure;
284285
} hacks;
285286

286287
struct {

samples/checkerboard/checkerboard.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int main(int argc, char **argv)
6969

7070
IrArena* a = new_ir_arena(default_arena_config());
7171
Module* m = new_module(a, "checkerboard");
72-
driver_load_source_file(SrcSlim, sizeof(checkerboard_kernel_src), checkerboard_kernel_src, m);
72+
driver_load_source_file(&compiler_config, SrcSlim, sizeof(checkerboard_kernel_src), checkerboard_kernel_src, m);
7373
Program* program = new_program_from_module(runtime, &compiler_config, m);
7474

7575
wait_completion(launch_kernel(program, device, "main", 16, 16, 1, 1, (void*[]) { &buf_addr }));

src/driver/cli.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ F(logging.print_generated, print-generated) \
100100
F(lower.simt_to_explicit_simd, lower-simt-to-simd) \
101101
F(optimisations.inline_everything, inline-everything) \
102102
F(hacks.restructure_everything, restructure-everything) \
103+
F(hacks.recover_structure, recover-structure) \
103104

104105
void cli_parse_compiler_config_args(CompilerConfig* config, int* pargc, char** argv) {
105106
int argc = *pargc;

src/driver/driver.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ SourceLanguage guess_source_language(const char* filename) {
3737
return SrcSlim;
3838
}
3939

40-
ShadyErrorCodes driver_load_source_file(SourceLanguage lang, size_t len, const char* file_contents, Module* mod) {
40+
ShadyErrorCodes driver_load_source_file(const CompilerConfig* config, SourceLanguage lang, size_t len, const char* file_contents, Module* mod) {
4141
switch (lang) {
4242
case SrcLLVM: {
4343
#ifdef LLVM_PARSER_PRESENT
44-
parse_llvm_into_shady(mod, len, file_contents);
44+
parse_llvm_into_shady(config, mod, len, file_contents);
4545
#else
4646
assert(false && "LLVM front-end missing in this version");
4747
#endif
@@ -67,7 +67,7 @@ ShadyErrorCodes driver_load_source_file(SourceLanguage lang, size_t len, const c
6767
return NoError;
6868
}
6969

70-
ShadyErrorCodes driver_load_source_file_from_filename(const char* filename, Module* mod) {
70+
ShadyErrorCodes driver_load_source_file_from_filename(const CompilerConfig* config, const char* filename, Module* mod) {
7171
ShadyErrorCodes err;
7272
SourceLanguage lang = guess_source_language(filename);
7373
size_t len;
@@ -84,7 +84,7 @@ ShadyErrorCodes driver_load_source_file_from_filename(const char* filename, Modu
8484
err = InputFileDoesNotExist;
8585
goto exit;
8686
}
87-
err = driver_load_source_file(lang, len, contents, mod);
87+
err = driver_load_source_file(config, lang, len, contents, mod);
8888
exit:
8989
free((void*) contents);
9090
return err;
@@ -98,7 +98,7 @@ ShadyErrorCodes driver_load_source_files(DriverConfig* args, Module* mod) {
9898

9999
size_t num_source_files = entries_count_list(args->input_filenames);
100100
for (size_t i = 0; i < num_source_files; i++) {
101-
int err = driver_load_source_file_from_filename(read_list(const char*, args->input_filenames)[i], mod);
101+
int err = driver_load_source_file_from_filename(&args->config, read_list(const char*, args->input_filenames)[i], mod);
102102
if (err)
103103
return err;
104104
}

src/driver/vcc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ int main(int argc, char** argv) {
5555
.tmp_filename = NULL,
5656
.delete_tmp_file = true
5757
};
58+
args.config.hacks.recover_structure = true;
59+
5860
cli_parse_driver_arguments(&args, &argc, argv);
5961
cli_parse_common_args(&argc, argv);
6062
cli_parse_compiler_config_args(&args.config, &argc, argv);
@@ -143,7 +145,7 @@ int main(int argc, char** argv) {
143145
char* llvm_ir;
144146
if (!read_file(vcc_options.tmp_filename, &len, &llvm_ir))
145147
exit(InputFileIOError);
146-
driver_load_source_file(SrcLLVM, len, llvm_ir, mod);
148+
driver_load_source_file(&args.config, SrcLLVM, len, llvm_ir, mod);
147149
free(llvm_ir);
148150

149151
if (vcc_options.delete_tmp_file)

src/frontends/llvm/l2s.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ const Node* convert_global(Parser* p, LLVMValueRef global) {
230230
return r;
231231
}
232232

233-
bool parse_llvm_into_shady(Module* dst, size_t len, const char* data) {
233+
bool parse_llvm_into_shady(const CompilerConfig* config, Module* dst, size_t len, const char* data) {
234234
LLVMContextRef context = LLVMContextCreate();
235235
LLVMModuleRef src;
236236
LLVMMemoryBufferRef mem = LLVMCreateMemoryBufferWithMemoryRange(data, len, "my_great_buffer", false);
@@ -248,6 +248,7 @@ bool parse_llvm_into_shady(Module* dst, size_t len, const char* data) {
248248
Module* dirty = new_module(get_module_arena(dst), "dirty");
249249
Parser p = {
250250
.ctx = context,
251+
.config = config,
251252
.map = new_dict(LLVMValueRef, const Node*, (HashFn) hash_opaque_ptr, (CmpFn) cmp_opaque_ptr),
252253
.annotations = new_dict(LLVMValueRef, ParsedAnnotation, (HashFn) hash_opaque_ptr, (CmpFn) cmp_opaque_ptr),
253254
.scopes = new_dict(const Node*, Nodes, (HashFn) hash_node, (CmpFn) compare_node),

src/frontends/llvm/l2s.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
#include "shady/ir.h"
55
#include <stdbool.h>
66

7-
bool parse_llvm_into_shady(Module* dst, size_t len, const char* data);
7+
bool parse_llvm_into_shady(const CompilerConfig*, Module* dst, size_t len, const char* data);
88

99
#endif

src/frontends/llvm/l2s_postprocess.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
typedef struct {
1313
Rewriter rewriter;
14+
const CompilerConfig* config;
1415
Parser* p;
1516
Scope* curr_scope;
1617
const Node* old_fn_or_bb;
@@ -138,6 +139,8 @@ static const Node* process_op(Context* ctx, NodeClass op_class, String op_name,
138139
assert(src && dst);
139140
rewrite_node(&ctx->rewriter, dst);
140141

142+
if (!ctx->config->hacks.recover_structure)
143+
break;
141144
Nodes* src_lexical_scope = find_value_dict(const Node*, Nodes, ctx->p->scopes, src);
142145
Nodes* dst_lexical_scope = find_value_dict(const Node*, Nodes, ctx->p->scopes, dst);
143146
if (!src_lexical_scope) {
@@ -251,6 +254,7 @@ void postprocess(Parser* p, Module* src, Module* dst) {
251254
assert(src != dst);
252255
Context ctx = {
253256
.rewriter = create_rewriter(src, dst, (RewriteNodeFn) process_node),
257+
.config = p->config,
254258
.p = p,
255259
.controls = new_dict(const Node*, Controls*, (HashFn) hash_node, (CmpFn) compare_node),
256260
};

src/frontends/llvm/l2s_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <string.h>
1212

1313
typedef struct {
14+
const CompilerConfig* config;
1415
LLVMContextRef ctx;
1516
struct Dict* map;
1617
struct Dict* annotations;

0 commit comments

Comments
 (0)