From 2e4b16a0f1d3de5f7c871211bed1af3134075e77 Mon Sep 17 00:00:00 2001 From: wesuRage Date: Sat, 21 Dec 2024 23:33:15 -0300 Subject: [PATCH 1/7] misc(dev): tests --- examples/a.glx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/a.glx b/examples/a.glx index 284c749..add9142 100644 --- a/examples/a.glx +++ b/examples/a.glx @@ -1,8 +1,12 @@ -extern int writeln( string) ; -extern string strrep( string, int) ; +extern int writeln( string) ; -def main( ) -> int: - writeln( "oi" * 20 ) ; +def main( ) -> int: - return 0; -end; + int N := 100000; + + for parallel static ( int i := 0; i < N; ++ i) -> 8: + writeln( "hello") ; + end; + + return 0; +end; \ No newline at end of file From 35b75e8158745f41f83bd108383f27ed550ae61e Mon Sep 17 00:00:00 2001 From: wesuRage Date: Sat, 21 Dec 2024 23:34:13 -0300 Subject: [PATCH 2/7] feat(parallel): added parallel for --- .../statements/generate_outlined_for.hpp | 16 ++ .../statements/generate_outlined_for.cpp | 167 ++++++++++++++++++ 2 files changed, 183 insertions(+) create mode 100644 include/backend/generator/statements/generate_outlined_for.hpp create mode 100644 src/backend/generator/statements/generate_outlined_for.cpp diff --git a/include/backend/generator/statements/generate_outlined_for.hpp b/include/backend/generator/statements/generate_outlined_for.hpp new file mode 100644 index 0000000..2016051 --- /dev/null +++ b/include/backend/generator/statements/generate_outlined_for.hpp @@ -0,0 +1,16 @@ +#ifndef GENERATE_OUTLINED_FOR_H +#define GENERATE_OUTLINED_FOR_H + +extern "C" { + #include "frontend/ast/definitions.h" +} + +#include +#include +#include +#include +#include + +llvm::Function* generate_outlined_for(ForNode *node, llvm::LLVMContext &Context, llvm::Module &Module, llvm::GlobalVariable *ompIdent, char *schedule_policy); + +#endif // GENERATE_OUTLINED_FOR_H \ No newline at end of file diff --git a/src/backend/generator/statements/generate_outlined_for.cpp b/src/backend/generator/statements/generate_outlined_for.cpp new file mode 100644 index 0000000..cbb0d27 --- /dev/null +++ b/src/backend/generator/statements/generate_outlined_for.cpp @@ -0,0 +1,167 @@ +#include "backend/generator/statements/generate_outlined_for.hpp" +#include "backend/generator/statements/generate_stmt.hpp" +#include "backend/generator/statements/generate_variable_declaration_stmt.hpp" +#include "backend/generator/expressions/generate_expr.hpp" +#include "backend/generator/utils/generate_stop.hpp" + +llvm::Function* generate_outlined_for(ForNode *node, llvm::LLVMContext &Context, llvm::Module &Module, llvm::GlobalVariable *ompIdent, char *schedule_policy) { + // Criando a assinatura da função for.omp_outlined + llvm::FunctionType* funcType = llvm::FunctionType::get(llvm::Type::getVoidTy(Context), + { llvm::PointerType::get(llvm::Type::getInt8Ty(Context), 0) }, false); + + llvm::Function* outlinedFunc = llvm::Function::Create(funcType, llvm::Function::PrivateLinkage, "for.omp_outlined", &Module); + + llvm::BasicBlock *entry = llvm::BasicBlock::Create(Context, "entry", outlinedFunc); + llvm::IRBuilder<> Builder(Context); + Builder.SetInsertPoint(entry); + + // Declarar e inicializar a variável do loop + llvm::Value *startVal = generate_expr(node->start, Context, Builder, Module); + llvm::AllocaInst *loopVar = Builder.CreateAlloca(startVal->getType(), nullptr, node->variable); + Builder.CreateStore(startVal, loopVar); // Inicializar a variável do loop + + llvm::Value *loopVarVal = Builder.CreateLoad(loopVar->getAllocatedType(), loopVar, node->variable); + llvm::Value *stopVal = generate_stop(node->stop, Context, Builder, Module); + + // Certifique-se de que ambos são do tipo i32 + if (loopVarVal->getType() != llvm::Type::getInt32Ty(Context)) { + loopVarVal = Builder.CreateSExt(loopVarVal, llvm::Type::getInt32Ty(Context)); + } + + if (stopVal->getType() != llvm::Type::getInt32Ty(Context)) { + stopVal = Builder.CreateSExt(stopVal, llvm::Type::getInt32Ty(Context)); + } + + // Definir as variáveis OpenMP para o loop + llvm::AllocaInst *ompLb = Builder.CreateAlloca(llvm::Type::getInt32Ty(Context), nullptr, "omp.lb"); + llvm::AllocaInst *ompUb = Builder.CreateAlloca(llvm::Type::getInt32Ty(Context), nullptr, "omp.ub"); + llvm::AllocaInst *ompStride = Builder.CreateAlloca(llvm::Type::getInt32Ty(Context), nullptr, "omp.stride"); + llvm::AllocaInst *ompIsLast = Builder.CreateAlloca(llvm::Type::getInt32Ty(Context), nullptr, "omp.is_last"); + + // Inicializar variáveis OpenMP + Builder.CreateStore(loopVarVal, ompLb); // Limite inferior + Builder.CreateStore(stopVal, ompUb); // Limite superior + Builder.CreateStore(llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 1), ompStride); // Incremento + Builder.CreateStore(llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 0), ompIsLast); // Última iteração (inicialmente 0) + + llvm::BasicBlock *preLoopBB = llvm::BasicBlock::Create(Context, "preloop", outlinedFunc); + llvm::BasicBlock *condBB = llvm::BasicBlock::Create(Context, "cond", outlinedFunc); + llvm::BasicBlock *bodyBB = llvm::BasicBlock::Create(Context, "body", outlinedFunc); + llvm::BasicBlock *updateBB = llvm::BasicBlock::Create(Context, "update", outlinedFunc); + llvm::BasicBlock *endBB = llvm::BasicBlock::Create(Context, "endloop", outlinedFunc); + + Builder.CreateBr(preLoopBB); + Builder.SetInsertPoint(preLoopBB); + + Builder.CreateBr(condBB); + + Builder.SetInsertPoint(condBB); + llvm::Value *loopVarValLoad = Builder.CreateLoad(loopVarVal->getType(), loopVar, node->variable); + llvm::Value *cond = Builder.CreateICmpSLT(loopVarValLoad, stopVal, "loopcond"); + + Builder.CreateCondBr(cond, bodyBB, endBB); + + Builder.SetInsertPoint(bodyBB); + + // Determinar o tipo de agendamento com base na política + llvm::Value *scheduleType = nullptr; + if (strcmp(schedule_policy, "static") == 0) { + scheduleType = llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 33); + } else if (strcmp(schedule_policy, "dynamic") == 0) { + scheduleType = llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 35); + } else if (strcmp(schedule_policy, "guided") == 0) { + scheduleType = llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 36); + } else { + throw std::invalid_argument("Unsupported schedule policy"); + } + + // Parâmetros específicos para dynamic e guided + llvm::Value *gtid = llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 0); + llvm::Value *chunkSize = llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 4); // Tamanho do chunk + + // Inserir chamada para OpenMP + if (strcmp(schedule_policy, "static") == 0) { + // Para agendamento estático, usar __kmpc_for_static_init_4 + llvm::FunctionCallee kmpcForStaticInit = Module.getOrInsertFunction( + "__kmpc_for_static_init_4", + llvm::FunctionType::get( + llvm::Type::getVoidTy(Context), + { + llvm::PointerType::get(llvm::Type::getInt8Ty(Context), 0), // ident + llvm::Type::getInt32Ty(Context), // gtid + llvm::Type::getInt32Ty(Context), // schedule_type + llvm::PointerType::get(llvm::Type::getInt32Ty(Context), 0), // is_last + llvm::PointerType::get(llvm::Type::getInt32Ty(Context), 0), // lb + llvm::PointerType::get(llvm::Type::getInt32Ty(Context), 0), // ub + llvm::PointerType::get(llvm::Type::getInt32Ty(Context), 0), // stride + llvm::Type::getInt32Ty(Context), // chunk + llvm::Type::getInt32Ty(Context) // increment + }, + false + ) + ); + + Builder.CreateCall(kmpcForStaticInit, { + ompIdent, + gtid, + scheduleType, + ompIsLast, + ompLb, + ompUb, + ompStride, + chunkSize, // Usado para dynamic/guided + llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 1) // Incremento + }); + } else if (strcmp(schedule_policy, "dynamic") == 0 || strcmp(schedule_policy, "guided") == 0) { + // Para dynamic/guided, usar __kmpc_dispatch_init_4 e __kmpc_dispatch_next_4 + llvm::FunctionCallee kmpcDispatchInit = Module.getOrInsertFunction( + "__kmpc_dispatch_init_4", + llvm::FunctionType::get( + llvm::Type::getVoidTy(Context), + { + llvm::PointerType::get(llvm::Type::getInt8Ty(Context), 0), // ident + llvm::Type::getInt32Ty(Context), // gtid + llvm::Type::getInt32Ty(Context), // schedule_type + llvm::Type::getInt32Ty(Context), // lb + llvm::Type::getInt32Ty(Context), // ub + llvm::Type::getInt32Ty(Context), // stride + llvm::Type::getInt32Ty(Context) // chunk + }, + false + ) + ); + + llvm::Value *scheduleType = strcmp(schedule_policy, "dynamic") == 0 + ? llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 35) + : llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 36); + + Builder.CreateCall(kmpcDispatchInit, { + ompIdent, + gtid, + scheduleType, + llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 0), // lb + llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 100), // ub (exemplo) + llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 1), // stride + chunkSize + }); + } + + for (size_t i = 0; i < node->body_count; i++) { + generate_stmt(node->body[i], Context, Module, Builder); + } + + Builder.CreateBr(updateBB); // Jump to the update block + + // Update loop variable + Builder.SetInsertPoint(updateBB); + llvm::Value *inc = Builder.CreateAdd(loopVarValLoad, llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 1), "inc"); + Builder.CreateStore(inc, loopVar); // Update %i + + Builder.CreateBr(condBB); // Jump back to the condition block + + // Finalize the loop + Builder.SetInsertPoint(endBB); + Builder.CreateRetVoid(); + + return outlinedFunc; +} From 10cf1376cf739d422a51c13ac9eeac0c627d41fb Mon Sep 17 00:00:00 2001 From: wesuRage Date: Sat, 21 Dec 2024 23:34:51 -0300 Subject: [PATCH 3/7] feat(util): generate only the stop value of for statement --- include/backend/generator/utils/generate_stop.hpp | 12 ++++++++++++ src/backend/generator/utils/generate_stop.cpp | 7 +++++++ 2 files changed, 19 insertions(+) create mode 100644 include/backend/generator/utils/generate_stop.hpp create mode 100644 src/backend/generator/utils/generate_stop.cpp diff --git a/include/backend/generator/utils/generate_stop.hpp b/include/backend/generator/utils/generate_stop.hpp new file mode 100644 index 0000000..6c52e15 --- /dev/null +++ b/include/backend/generator/utils/generate_stop.hpp @@ -0,0 +1,12 @@ +#ifndef GENERATE_STOP_H +#define GENERATE_STOP_H + +extern "C" { + #include "frontend/ast/definitions.h" +} +#include +#include + +llvm::Value *generate_stop(AstNode *node, llvm::LLVMContext &Context, llvm::IRBuilder<> &Builder, llvm::Module &Module); + +#endif // GENERATE_STOP_H \ No newline at end of file diff --git a/src/backend/generator/utils/generate_stop.cpp b/src/backend/generator/utils/generate_stop.cpp new file mode 100644 index 0000000..d7f85de --- /dev/null +++ b/src/backend/generator/utils/generate_stop.cpp @@ -0,0 +1,7 @@ +#include "backend/generator/expressions/generate_expr.hpp" +#include "backend/generator/utils/generate_stop.hpp" + +llvm::Value *generate_stop(AstNode *node, llvm::LLVMContext &Context, llvm::IRBuilder<> &Builder, llvm::Module &Module) { + BinaryExprNode *bin_expr = (BinaryExprNode *)node->data; + return generate_expr(bin_expr->right, Context, Builder, Module); +} \ No newline at end of file From 25cd9f6688265f4082ddec028e26b73e41c7a3f7 Mon Sep 17 00:00:00 2001 From: wesuRage Date: Sat, 21 Dec 2024 23:35:38 -0300 Subject: [PATCH 4/7] feat(parallel): implemented parallelization on for --- .../statements/generate_for_stmt.cpp | 195 +++++++++++++----- 1 file changed, 147 insertions(+), 48 deletions(-) diff --git a/src/backend/generator/statements/generate_for_stmt.cpp b/src/backend/generator/statements/generate_for_stmt.cpp index 47351b9..df72c07 100644 --- a/src/backend/generator/statements/generate_for_stmt.cpp +++ b/src/backend/generator/statements/generate_for_stmt.cpp @@ -1,24 +1,15 @@ +#include "backend/generator/utils/generate_stop.hpp" #include "backend/generator/expressions/generate_expr.hpp" #include "backend/generator/statements/generate_stmt.hpp" #include "backend/generator/statements/generate_for_stmt.hpp" #include "backend/generator/statements/generate_variable_declaration_stmt.hpp" +#include "backend/generator/statements/generate_outlined_for.hpp" #include "backend/generator/symbols/identifier_symbol_table.hpp" llvm::Value* generate_for_stmt(ForNode *node, llvm::LLVMContext &Context, llvm::IRBuilder<> &Builder, llvm::Module &Module) { llvm::Function *currentFunction = Builder.GetInsertBlock()->getParent(); - - // Blocos básicos do loop - llvm::BasicBlock *preLoopBB = llvm::BasicBlock::Create(Context, "preloop", currentFunction); - llvm::BasicBlock *condBB = llvm::BasicBlock::Create(Context, "cond", currentFunction); - llvm::BasicBlock *bodyBB = llvm::BasicBlock::Create(Context, "body", currentFunction); - llvm::BasicBlock *updateBB = llvm::BasicBlock::Create(Context, "update", currentFunction); - llvm::BasicBlock *endBB = llvm::BasicBlock::Create(Context, "endloop", currentFunction); - - // Cria o salto para o bloco de pré-loop - Builder.CreateBr(preLoopBB); - Builder.SetInsertPoint(preLoopBB); - - // Declaração da variável do loop (%i) e inicialização + + // Declarar e inicializar a variável do loop VariableNode iteratorVar; iteratorVar.name = node->variable; iteratorVar.varType = node->var_type; @@ -26,49 +17,157 @@ llvm::Value* generate_for_stmt(ForNode *node, llvm::LLVMContext &Context, llvm:: iteratorVar.isConst = false; iteratorVar.value = node->start; - generate_variable_declaration_stmt(&iteratorVar, Context, Builder, Module); - + if (node->iterator){ + generate_variable_declaration_stmt(&iteratorVar, Context, Builder, Module); + } + llvm::Value *startVal = generate_expr(node->start, Context, Builder, Module); llvm::AllocaInst *loopVar = Builder.CreateAlloca(startVal->getType(), nullptr, node->variable); - Builder.CreateStore(startVal, loopVar); // Inicializa %i - - Builder.CreateBr(condBB); + Builder.CreateStore(startVal, loopVar); // Inicializar a variável do loop - // Condição do loop - Builder.SetInsertPoint(condBB); + llvm::Value *loopVarVal = Builder.CreateLoad(loopVar->getAllocatedType(), loopVar, node->variable); + llvm::Value *stopVal = generate_stop(node->stop, Context, Builder, Module); - BinaryExprNode *binaryNode = (BinaryExprNode *)node->stop->data; - llvm::Value *rightOperand = generate_expr(binaryNode->right, Context, Builder, Module); - llvm::Value *stopVal = rightOperand; - - if (stopVal->getType()->isPointerTy()) { - const SymbolInfo *id = find_identifier(stopVal->getName().str()); - stopVal = id->value; + // Certifique-se de que ambos são do tipo i32 + if (loopVarVal->getType() != llvm::Type::getInt32Ty(Context)) { + loopVarVal = Builder.CreateSExt(loopVarVal, llvm::Type::getInt32Ty(Context)); } - llvm::Value *cond = Builder.CreateICmpSLT(loopVarVal, stopVal, "loopcond"); - - Builder.CreateCondBr(cond, bodyBB, endBB); // Se a condição for verdadeira, vai para o corpo; senão, para o final. - - // Corpo do loop - Builder.SetInsertPoint(bodyBB); - for (size_t i = 0; i < node->body_count; ++i) { - generate_stmt(node->body[i], Context, Module, Builder); // Gerar as declarações no corpo do loop + if (stopVal->getType() != llvm::Type::getInt32Ty(Context)) { + stopVal = Builder.CreateSExt(stopVal, llvm::Type::getInt32Ty(Context)); } - Builder.CreateBr(updateBB); // Salta para o bloco de atualização - - // Atualiza o valor de %i - Builder.SetInsertPoint(updateBB); - llvm::Value *loopVarValUpdate = Builder.CreateLoad(loopVar->getAllocatedType(), loopVar, node->variable); - llvm::Value *inc = Builder.CreateAdd(loopVarValUpdate, llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 1), "inc"); - Builder.CreateStore(inc, loopVar); // Atualiza %i - - Builder.CreateBr(condBB); // Salta de volta para a condição - - // Finaliza o loop - Builder.SetInsertPoint(endBB); - return Builder.CreateLoad(loopVar->getAllocatedType(), loopVar, node->variable); + if (node->is_parallel) { + // Definir funções OpenMP + llvm::Constant *ompString = llvm::ConstantDataArray::getString(Context, ";unknown;unknown;0;0;;", true); + + llvm::GlobalVariable *ompGlobalString = new llvm::GlobalVariable( + Module, + ompString->getType(), + true, + llvm::GlobalValue::PrivateLinkage, + ompString, + "omp_global_string" + ); + + llvm::StructType *identTy = llvm::StructType::get( + Context, + { + llvm::Type::getInt32Ty(Context), // Reserved + llvm::Type::getInt32Ty(Context), // Flags + llvm::Type::getInt32Ty(Context), // Reserved + llvm::Type::getInt32Ty(Context), // Source Info + llvm::PointerType::get(llvm::Type::getInt8Ty(Context), 0) // String Pointer + } + ); + + + auto create_omp_ident = [&](int flags, llvm::StringRef name) { + llvm::Constant *ident = llvm::ConstantStruct::get( + identTy, + { + llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 0), + llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), flags), + llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 0), + llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 22), + llvm::ConstantExpr::getBitCast(ompGlobalString, llvm::PointerType::get(llvm::Type::getInt8Ty(Context), 0)) + } + ); + return new llvm::GlobalVariable( + Module, + identTy, + true, + llvm::GlobalValue::PrivateLinkage, + ident, + name + ); + }; + + llvm::FunctionCallee kmpcGlobalThreadNum = Module.getOrInsertFunction( + "__kmpc_global_thread_num", + llvm::FunctionType::get( + llvm::Type::getInt32Ty(Context), + { llvm::PointerType::get(identTy, 0) }, + false + ) + ); + + llvm::FunctionCallee kmpcPushNumThreads = Module.getOrInsertFunction( + "__kmpc_push_num_threads", + llvm::FunctionType::get( + llvm::Type::getVoidTy(Context), + { + llvm::PointerType::get(identTy, 0), + llvm::Type::getInt32Ty(Context), + llvm::Type::getInt32Ty(Context) + }, + false + ) + ); + + llvm::FunctionCallee kmpcForkCall = Module.getOrInsertFunction( + "__kmpc_fork_call", + llvm::FunctionType::get( + llvm::Type::getVoidTy(Context), + { + llvm::PointerType::get(identTy, 0), + llvm::Type::getInt32Ty(Context), + llvm::PointerType::get(llvm::Type::getVoidTy(Context), 0) + }, + true + ) + ); + + + llvm::GlobalVariable *ompIdent0 = create_omp_ident(514, "omp_ident0"); + llvm::GlobalVariable *ompIdent1 = create_omp_ident(2, "omp_ident1"); + + llvm::GlobalVariable *ompIdent = create_omp_ident(514, "omp_ident"); + + llvm::Value *threadNum = Builder.CreateCall(kmpcGlobalThreadNum, { ompIdent1 }); + + Builder.CreateCall(kmpcPushNumThreads, { ompIdent1, threadNum, llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 1) }); + + llvm::Function* ompOutlined = generate_outlined_for(node, Context, Module, ompIdent, node->schedule_policy); + + Builder.CreateCall(kmpcForkCall, { ompIdent1, llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 0), ompOutlined }); + } else { + llvm::BasicBlock *preLoopBB = llvm::BasicBlock::Create(Context, "preloop", currentFunction); + llvm::BasicBlock *condBB = llvm::BasicBlock::Create(Context, "cond", currentFunction); + llvm::BasicBlock *bodyBB = llvm::BasicBlock::Create(Context, "body", currentFunction); + llvm::BasicBlock *updateBB = llvm::BasicBlock::Create(Context, "update", currentFunction); + llvm::BasicBlock *endBB = llvm::BasicBlock::Create(Context, "endloop", currentFunction); + + Builder.CreateBr(preLoopBB); + Builder.SetInsertPoint(preLoopBB); + + Builder.CreateBr(condBB); + + Builder.SetInsertPoint(condBB); + llvm::Value *loopVarValLoad = Builder.CreateLoad(loopVarVal->getType(), loopVar, node->variable); + llvm::Value *cond = Builder.CreateICmpSLT(loopVarValLoad, stopVal, "loopcond"); + + Builder.CreateCondBr(cond, bodyBB, endBB); + + Builder.SetInsertPoint(bodyBB); + + for (size_t i = 0; i < node->body_count; i++) { + generate_stmt(node->body[i], Context, Module, Builder); + } + + Builder.CreateBr(updateBB); // Jump to the update block + + // Update loop variable + Builder.SetInsertPoint(updateBB); + llvm::Value *inc = Builder.CreateAdd(loopVarValLoad, llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 1), "inc"); + Builder.CreateStore(inc, loopVar); // Update %i + + Builder.CreateBr(condBB); // Jump back to the condition block + + // Finalize the loop + Builder.SetInsertPoint(endBB); + } + return nullptr; } From 9916e5d204801b114510d3830fd4b29e29fc64ff Mon Sep 17 00:00:00 2001 From: wesuRage Date: Sat, 21 Dec 2024 23:36:48 -0300 Subject: [PATCH 5/7] feat(guided): added guided schedule to for node --- include/frontend/ast/definitions.h | 11 +---------- include/frontend/lexer/core.h | 1 + 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/include/frontend/ast/definitions.h b/include/frontend/ast/definitions.h index 7471ec5..6b8c9d7 100644 --- a/include/frontend/ast/definitions.h +++ b/include/frontend/ast/definitions.h @@ -95,19 +95,10 @@ typedef struct { AstNode *updater; AstNode *iterator; bool is_parallel; - char *schedule_policy; // "static", "dynamic" + char *schedule_policy; // "static", "dynamic", "guided" AstNode *num_threads; } ForNode; -typedef struct { - char *type; // "barrier", "atomic" -} SyncNode; - -typedef struct { - char *name; - char *memory_type; // "private", "shared", "pgas" -} MemoryNode; - typedef struct { AstNode *condition; AstNode **consequent; diff --git a/include/frontend/lexer/core.h b/include/frontend/lexer/core.h index d288a99..d0c11c2 100644 --- a/include/frontend/lexer/core.h +++ b/include/frontend/lexer/core.h @@ -76,6 +76,7 @@ typedef enum { TOKEN_STATIC, TOKEN_DYNAMIC, TOKEN_PARALLEL, + TOKEN_GUIDED, TOKEN_UNKNOWN, } TokenType; From 2191a384d8ae575b25b2cde753300b701c333784 Mon Sep 17 00:00:00 2001 From: wesuRage Date: Sat, 21 Dec 2024 23:37:19 -0300 Subject: [PATCH 6/7] feat(guided): added guided token --- src/frontend/lexer/lexer.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/frontend/lexer/lexer.c b/src/frontend/lexer/lexer.c index 7f338e7..390ec82 100644 --- a/src/frontend/lexer/lexer.c +++ b/src/frontend/lexer/lexer.c @@ -130,6 +130,7 @@ TokenType match_keyword(const char *lexeme) { if (strcmp(lexeme, "parallel") == 0) return TOKEN_PARALLEL; if (strcmp(lexeme, "static") == 0) return TOKEN_STATIC; if (strcmp(lexeme, "dynamic") == 0) return TOKEN_DYNAMIC; + if (strcmp(lexeme, "guided") == 0) return TOKEN_GUIDED; if (strcmp(lexeme, "for") == 0) return TOKEN_FOR; if (strcmp(lexeme, "if") == 0) return TOKEN_IF; if (strcmp(lexeme, "elif") == 0) return TOKEN_ELIF; From c7b5b9a8ada1d579231b91c1e3199f9581bf06d4 Mon Sep 17 00:00:00 2001 From: wesuRage Date: Sat, 21 Dec 2024 23:37:45 -0300 Subject: [PATCH 7/7] feat(guided): added guided policy --- src/frontend/parser/statements/parse_for_stmt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/frontend/parser/statements/parse_for_stmt.c b/src/frontend/parser/statements/parse_for_stmt.c index 1a4df75..7cc361d 100644 --- a/src/frontend/parser/statements/parse_for_stmt.c +++ b/src/frontend/parser/statements/parse_for_stmt.c @@ -33,7 +33,11 @@ AstNode *parse_for_stmt(Parser *parser) { consume_token(parser); is_parallel = true; - if (current_token(parser).type != TOKEN_STATIC && current_token(parser).type != TOKEN_DYNAMIC) { + if ( + current_token(parser).type != TOKEN_STATIC + && current_token(parser).type != TOKEN_DYNAMIC + && current_token(parser).type != TOKEN_GUIDED + ) { error(parser, "Expected schedule policy"); exit(EXIT_FAILURE); }