From 1a7ac8b804f6ff1cf52e073c9f37f322e85e2d82 Mon Sep 17 00:00:00 2001 From: Dmitry Babokin Date: Fri, 17 May 2013 22:15:57 +0400 Subject: [PATCH] Enable memory alignment management via compiler options --- builtins.cpp | 5 +++++ ispc.cpp | 1 + ispc.h | 4 ++++ main.cpp | 4 ++++ 4 files changed, 14 insertions(+) diff --git a/builtins.cpp b/builtins.cpp index 085c1ea3..68d955f8 100644 --- a/builtins.cpp +++ b/builtins.cpp @@ -996,6 +996,11 @@ DefineStdlib(SymbolTable *symbolTable, llvm::LLVMContext *ctx, llvm::Module *mod lDefineConstantInt("__have_native_transcendentals", g->target->hasTranscendentals(), module, symbolTable); + if (g->forceAlignment != -1) { + llvm::GlobalVariable *alignment = module->getGlobalVariable("memory_alignment", true); + alignment->setInitializer(LLVMInt32(g->forceAlignment)); + } + if (includeStdlibISPC) { // If the user wants the standard library to be included, parse the // serialized version of the stdlib.ispc file to get its diff --git a/ispc.cpp b/ispc.cpp index 40bf0020..dccbe423 100644 --- a/ispc.cpp +++ b/ispc.cpp @@ -747,6 +747,7 @@ Globals::Globals() { if (getcwd(currentDirectory, sizeof(currentDirectory)) == NULL) FATAL("Current directory path too long!"); #endif + forceAlignment = -1; } /////////////////////////////////////////////////////////////////////////// diff --git a/ispc.h b/ispc.h index 3582e2fc..784cb7cc 100644 --- a/ispc.h +++ b/ispc.h @@ -551,6 +551,10 @@ struct Globals { /** Additional user-provided directories to search when processing #include directives in the preprocessor. */ std::vector includePath; + + /** Indicates that alignment in memory allocation routines should be + forced to have given value. -1 value means natural alignment for the platforms. */ + int forceAlignment; }; enum { diff --git a/main.cpp b/main.cpp index cc005fde..80f77683 100644 --- a/main.cpp +++ b/main.cpp @@ -98,6 +98,7 @@ usage(int ret) { printf(" [--emit-c++]\t\t\tEmit a C++ source file as output\n"); printf(" [--emit-llvm]\t\t\tEmit LLVM bitode file as output\n"); printf(" [--emit-obj]\t\t\tGenerate object file file as output (default)\n"); + printf(" [--force-alignment=]\t\tForce alignment in memory allocations routine to be \n"); printf(" [-g]\t\t\t\tGenerate debugging information\n"); printf(" [--help]\t\t\t\tPrint help\n"); printf(" [--help-dev]\t\t\tPrint help for developer options\n"); @@ -393,6 +394,9 @@ int main(int Argc, char *Argv[]) { usage(1); } } + else if (!strncmp(argv[i], "--force-alignment=", 18)) { + g->forceAlignment = atoi(argv[i] + 18); + } else if (!strcmp(argv[i], "--woff") || !strcmp(argv[i], "-woff")) { g->disableWarnings = true; g->emitPerfWarnings = false;