Splitting .ll files to be compiled in two versions - 32 and 64 bit. Unix only
This commit is contained in:
25
Makefile
25
Makefile
@@ -118,9 +118,14 @@ HEADERS=ast.h builtins.h ctx.h decl.h expr.h func.h ispc.h llvmutil.h module.h \
|
|||||||
opt.h stmt.h sym.h type.h util.h
|
opt.h stmt.h sym.h type.h util.h
|
||||||
TARGETS=avx1 avx1-x2 avx11 avx11-x2 avx2 avx2-x2 sse2 sse2-x2 sse4 sse4-x2 \
|
TARGETS=avx1 avx1-x2 avx11 avx11-x2 avx2 avx2-x2 sse2 sse2-x2 sse4 sse4-x2 \
|
||||||
generic-4 generic-8 generic-16 generic-32 generic-64 generic-1
|
generic-4 generic-8 generic-16 generic-32 generic-64 generic-1
|
||||||
BUILTINS_SRC=$(addprefix builtins/target-, $(addsuffix .ll, $(TARGETS))) \
|
# These files need to be compiled in two versions - 32 and 64 bits.
|
||||||
builtins/dispatch.ll
|
BUILTINS_SRC_TARGET=$(addprefix builtins/target-, $(addsuffix .ll, $(TARGETS)))
|
||||||
BUILTINS_OBJS=$(addprefix builtins-, $(notdir $(BUILTINS_SRC:.ll=.o))) \
|
# These are files to be compiled in single version.
|
||||||
|
BUILTINS_SRC_COMMON=builtins/dispatch.ll
|
||||||
|
BUILTINS_OBJS_32=$(addprefix builtins-, $(notdir $(BUILTINS_SRC_TARGET:.ll=-32bit.o)))
|
||||||
|
BUILTINS_OBJS_64=$(addprefix builtins-, $(notdir $(BUILTINS_SRC_TARGET:.ll=-64bit.o)))
|
||||||
|
BUILTINS_OBJS=$(addprefix builtins-, $(notdir $(BUILTINS_SRC_COMMON:.ll=.o))) \
|
||||||
|
$(BUILTINS_OBJS_32) $(BUILTINS_OBJS_64) \
|
||||||
builtins-c-32.cpp builtins-c-64.cpp
|
builtins-c-32.cpp builtins-c-64.cpp
|
||||||
BISON_SRC=parse.yy
|
BISON_SRC=parse.yy
|
||||||
FLEX_SRC=lex.ll
|
FLEX_SRC=lex.ll
|
||||||
@@ -212,17 +217,25 @@ objs/lex.o: objs/lex.cpp $(HEADERS) objs/parse.cc
|
|||||||
@echo Compiling $<
|
@echo Compiling $<
|
||||||
@$(CXX) $(CXXFLAGS) -o $@ -c $<
|
@$(CXX) $(CXXFLAGS) -o $@ -c $<
|
||||||
|
|
||||||
objs/builtins-%.cpp: builtins/%.ll builtins/util.m4 $(wildcard builtins/*common.ll)
|
objs/builtins-dispatch.cpp: builtins/dispatch.ll builtins/util.m4 $(wildcard builtins/*common.ll)
|
||||||
@echo Creating C++ source from builtins definition file $<
|
@echo Creating C++ source from builtins definition file $<
|
||||||
@m4 -Ibuiltins/ -DLLVM_VERSION=$(LLVM_VERSION) -DBUILD_OS=UNIX $< | python bitcode2cpp.py $< > $@
|
@m4 -Ibuiltins/ -DLLVM_VERSION=$(LLVM_VERSION) -DBUILD_OS=UNIX $< | python bitcode2cpp.py $< > $@
|
||||||
|
|
||||||
|
objs/builtins-%-32bit.cpp: builtins/%.ll builtins/util.m4 $(wildcard builtins/*common.ll)
|
||||||
|
@echo Creating C++ source from builtins definition file $< \(32 bit version\)
|
||||||
|
@m4 -Ibuiltins/ -DLLVM_VERSION=$(LLVM_VERSION) -DBUILD_OS=UNIX -DRUNTIME=32 $< | python bitcode2cpp.py $< 32bit > $@
|
||||||
|
|
||||||
|
objs/builtins-%-64bit.cpp: builtins/%.ll builtins/util.m4 $(wildcard builtins/*common.ll)
|
||||||
|
@echo Creating C++ source from builtins definition file $< \(64 bit version\)
|
||||||
|
@m4 -Ibuiltins/ -DLLVM_VERSION=$(LLVM_VERSION) -DBUILD_OS=UNIX -DRUNTIME=64 $< | python bitcode2cpp.py $< 64bit > $@
|
||||||
|
|
||||||
objs/builtins-c-32.cpp: builtins/builtins.c
|
objs/builtins-c-32.cpp: builtins/builtins.c
|
||||||
@echo Creating C++ source from builtins definition file $<
|
@echo Creating C++ source from builtins definition file $<
|
||||||
@$(CLANG) -m32 -emit-llvm -c $< -o - | llvm-dis - | python bitcode2cpp.py c-32 > $@
|
@$(CLANG) -m32 -emit-llvm -c $< -o - | llvm-dis - | python bitcode2cpp.py c 32 > $@
|
||||||
|
|
||||||
objs/builtins-c-64.cpp: builtins/builtins.c
|
objs/builtins-c-64.cpp: builtins/builtins.c
|
||||||
@echo Creating C++ source from builtins definition file $<
|
@echo Creating C++ source from builtins definition file $<
|
||||||
@$(CLANG) -m64 -emit-llvm -c $< -o - | llvm-dis - | python bitcode2cpp.py c-64 > $@
|
@$(CLANG) -m64 -emit-llvm -c $< -o - | llvm-dis - | python bitcode2cpp.py c 64 > $@
|
||||||
|
|
||||||
objs/stdlib_generic_ispc.cpp: stdlib.ispc
|
objs/stdlib_generic_ispc.cpp: stdlib.ispc
|
||||||
@echo Creating C++ source from $< for generic
|
@echo Creating C++ source from $< for generic
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import os
|
|||||||
length=0
|
length=0
|
||||||
|
|
||||||
src=str(sys.argv[1])
|
src=str(sys.argv[1])
|
||||||
|
if (len(sys.argv) > 2):
|
||||||
|
runtime=str(sys.argv[2])
|
||||||
|
|
||||||
target = re.sub("builtins/target-", "", src)
|
target = re.sub("builtins/target-", "", src)
|
||||||
target = re.sub(r"builtins\\target-", "", target)
|
target = re.sub(r"builtins\\target-", "", target)
|
||||||
@@ -29,8 +31,11 @@ except IOError:
|
|||||||
sys.stderr.write("Couldn't open " + src)
|
sys.stderr.write("Couldn't open " + src)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
name = target
|
||||||
|
if (len(sys.argv) > 2):
|
||||||
|
name += "_" + runtime;
|
||||||
width = 16;
|
width = 16;
|
||||||
sys.stdout.write("unsigned char builtins_bitcode_" + target + "[] = {\n")
|
sys.stdout.write("unsigned char builtins_bitcode_" + name + "[] = {\n")
|
||||||
|
|
||||||
data = as_out.stdout.read()
|
data = as_out.stdout.read()
|
||||||
for i in range(0, len(data), 1):
|
for i in range(0, len(data), 1):
|
||||||
@@ -40,7 +45,7 @@ for i in range(0, len(data), 1):
|
|||||||
sys.stdout.write("\n")
|
sys.stdout.write("\n")
|
||||||
|
|
||||||
sys.stdout.write("0x00 };\n\n")
|
sys.stdout.write("0x00 };\n\n")
|
||||||
sys.stdout.write("int builtins_bitcode_" + target + "_length = " + str(i+1) + ";\n")
|
sys.stdout.write("int builtins_bitcode_" + name + "_length = " + str(i+1) + ";\n")
|
||||||
|
|
||||||
as_out.wait()
|
as_out.wait()
|
||||||
|
|
||||||
|
|||||||
212
builtins.cpp
212
builtins.cpp
@@ -776,169 +776,195 @@ lDefineProgramIndex(llvm::Module *module, SymbolTable *symbolTable) {
|
|||||||
void
|
void
|
||||||
DefineStdlib(SymbolTable *symbolTable, llvm::LLVMContext *ctx, llvm::Module *module,
|
DefineStdlib(SymbolTable *symbolTable, llvm::LLVMContext *ctx, llvm::Module *module,
|
||||||
bool includeStdlibISPC) {
|
bool includeStdlibISPC) {
|
||||||
|
bool runtime32 = g->target->is32Bit();
|
||||||
|
|
||||||
|
#define EXPORT_MODULE(export_module) \
|
||||||
|
extern unsigned char export_module[]; \
|
||||||
|
extern int export_module##_length; \
|
||||||
|
AddBitcodeToModule(export_module, export_module##_length, \
|
||||||
|
module, symbolTable);
|
||||||
|
|
||||||
// Add the definitions from the compiled builtins-c.c file
|
// Add the definitions from the compiled builtins-c.c file
|
||||||
if (g->target->is32Bit()) {
|
if (runtime32) {
|
||||||
extern unsigned char builtins_bitcode_c_32[];
|
EXPORT_MODULE(builtins_bitcode_c_32);
|
||||||
extern int builtins_bitcode_c_32_length;
|
|
||||||
AddBitcodeToModule(builtins_bitcode_c_32, builtins_bitcode_c_32_length,
|
|
||||||
module, symbolTable);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
extern unsigned char builtins_bitcode_c_64[];
|
EXPORT_MODULE(builtins_bitcode_c_64);
|
||||||
extern int builtins_bitcode_c_64_length;
|
|
||||||
AddBitcodeToModule(builtins_bitcode_c_64, builtins_bitcode_c_64_length,
|
|
||||||
module, symbolTable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next, add the target's custom implementations of the various needed
|
// Next, add the target's custom implementations of the various needed
|
||||||
// builtin functions (e.g. __masked_store_32(), etc).
|
// builtin functions (e.g. __masked_store_32(), etc).
|
||||||
switch (g->target->getISA()) {
|
switch (g->target->getISA()) {
|
||||||
case Target::SSE2:
|
case Target::SSE2: {
|
||||||
extern unsigned char builtins_bitcode_sse2[];
|
|
||||||
extern int builtins_bitcode_sse2_length;
|
|
||||||
extern unsigned char builtins_bitcode_sse2_x2[];
|
|
||||||
extern int builtins_bitcode_sse2_x2_length;
|
|
||||||
switch (g->target->getVectorWidth()) {
|
switch (g->target->getVectorWidth()) {
|
||||||
case 4:
|
case 4:
|
||||||
AddBitcodeToModule(builtins_bitcode_sse2, builtins_bitcode_sse2_length,
|
if (runtime32) {
|
||||||
module, symbolTable);
|
EXPORT_MODULE(builtins_bitcode_sse2_32bit);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
EXPORT_MODULE(builtins_bitcode_sse2_64bit);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
AddBitcodeToModule(builtins_bitcode_sse2_x2, builtins_bitcode_sse2_x2_length,
|
if (runtime32) {
|
||||||
module, symbolTable);
|
EXPORT_MODULE(builtins_bitcode_sse2_x2_32bit);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
EXPORT_MODULE(builtins_bitcode_sse2_x2_64bit);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
FATAL("logic error in DefineStdlib");
|
FATAL("logic error in DefineStdlib");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Target::SSE4:
|
}
|
||||||
extern unsigned char builtins_bitcode_sse4[];
|
case Target::SSE4: {
|
||||||
extern int builtins_bitcode_sse4_length;
|
|
||||||
extern unsigned char builtins_bitcode_sse4_x2[];
|
|
||||||
extern int builtins_bitcode_sse4_x2_length;
|
|
||||||
switch (g->target->getVectorWidth()) {
|
switch (g->target->getVectorWidth()) {
|
||||||
case 4:
|
case 4:
|
||||||
AddBitcodeToModule(builtins_bitcode_sse4,
|
if (runtime32) {
|
||||||
builtins_bitcode_sse4_length,
|
EXPORT_MODULE(builtins_bitcode_sse4_32bit);
|
||||||
module, symbolTable);
|
}
|
||||||
|
else {
|
||||||
|
EXPORT_MODULE(builtins_bitcode_sse4_64bit);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
AddBitcodeToModule(builtins_bitcode_sse4_x2,
|
if (runtime32) {
|
||||||
builtins_bitcode_sse4_x2_length,
|
EXPORT_MODULE(builtins_bitcode_sse4_x2_32bit);
|
||||||
module, symbolTable);
|
}
|
||||||
|
else {
|
||||||
|
EXPORT_MODULE(builtins_bitcode_sse4_x2_64bit);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
FATAL("logic error in DefineStdlib");
|
FATAL("logic error in DefineStdlib");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Target::AVX:
|
}
|
||||||
|
case Target::AVX: {
|
||||||
switch (g->target->getVectorWidth()) {
|
switch (g->target->getVectorWidth()) {
|
||||||
case 8:
|
case 8:
|
||||||
extern unsigned char builtins_bitcode_avx1[];
|
if (runtime32) {
|
||||||
extern int builtins_bitcode_avx1_length;
|
EXPORT_MODULE(builtins_bitcode_avx1_32bit);
|
||||||
AddBitcodeToModule(builtins_bitcode_avx1,
|
}
|
||||||
builtins_bitcode_avx1_length,
|
else {
|
||||||
module, symbolTable);
|
EXPORT_MODULE(builtins_bitcode_avx1_64bit);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
extern unsigned char builtins_bitcode_avx1_x2[];
|
if (runtime32) {
|
||||||
extern int builtins_bitcode_avx1_x2_length;
|
EXPORT_MODULE(builtins_bitcode_avx1_x2_32bit);
|
||||||
AddBitcodeToModule(builtins_bitcode_avx1_x2,
|
}
|
||||||
builtins_bitcode_avx1_x2_length,
|
else {
|
||||||
module, symbolTable);
|
EXPORT_MODULE(builtins_bitcode_avx1_x2_64bit);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
FATAL("logic error in DefineStdlib");
|
FATAL("logic error in DefineStdlib");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Target::AVX11:
|
}
|
||||||
|
case Target::AVX11: {
|
||||||
switch (g->target->getVectorWidth()) {
|
switch (g->target->getVectorWidth()) {
|
||||||
case 8:
|
case 8:
|
||||||
extern unsigned char builtins_bitcode_avx11[];
|
if (runtime32) {
|
||||||
extern int builtins_bitcode_avx11_length;
|
EXPORT_MODULE(builtins_bitcode_avx11_32bit);
|
||||||
AddBitcodeToModule(builtins_bitcode_avx11,
|
}
|
||||||
builtins_bitcode_avx11_length,
|
else {
|
||||||
module, symbolTable);
|
EXPORT_MODULE(builtins_bitcode_avx11_64bit);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
extern unsigned char builtins_bitcode_avx11_x2[];
|
if (runtime32) {
|
||||||
extern int builtins_bitcode_avx11_x2_length;
|
EXPORT_MODULE(builtins_bitcode_avx11_x2_32bit);
|
||||||
AddBitcodeToModule(builtins_bitcode_avx11_x2,
|
}
|
||||||
builtins_bitcode_avx11_x2_length,
|
else {
|
||||||
module, symbolTable);
|
EXPORT_MODULE(builtins_bitcode_avx11_x2_64bit);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
FATAL("logic error in DefineStdlib");
|
FATAL("logic error in DefineStdlib");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Target::AVX2:
|
}
|
||||||
|
case Target::AVX2: {
|
||||||
switch (g->target->getVectorWidth()) {
|
switch (g->target->getVectorWidth()) {
|
||||||
case 8:
|
case 8:
|
||||||
extern unsigned char builtins_bitcode_avx2[];
|
if (runtime32) {
|
||||||
extern int builtins_bitcode_avx2_length;
|
EXPORT_MODULE(builtins_bitcode_avx2_32bit);
|
||||||
AddBitcodeToModule(builtins_bitcode_avx2,
|
}
|
||||||
builtins_bitcode_avx2_length,
|
else {
|
||||||
module, symbolTable);
|
EXPORT_MODULE(builtins_bitcode_avx2_64bit);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
extern unsigned char builtins_bitcode_avx2_x2[];
|
if (runtime32) {
|
||||||
extern int builtins_bitcode_avx2_x2_length;
|
EXPORT_MODULE(builtins_bitcode_avx2_x2_32bit);
|
||||||
AddBitcodeToModule(builtins_bitcode_avx2_x2,
|
}
|
||||||
builtins_bitcode_avx2_x2_length,
|
else {
|
||||||
module, symbolTable);
|
EXPORT_MODULE(builtins_bitcode_avx2_x2_64bit);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
FATAL("logic error in DefineStdlib");
|
FATAL("logic error in DefineStdlib");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Target::GENERIC:
|
}
|
||||||
|
case Target::GENERIC: {
|
||||||
switch (g->target->getVectorWidth()) {
|
switch (g->target->getVectorWidth()) {
|
||||||
case 4:
|
case 4:
|
||||||
extern unsigned char builtins_bitcode_generic_4[];
|
if (runtime32) {
|
||||||
extern int builtins_bitcode_generic_4_length;
|
EXPORT_MODULE(builtins_bitcode_generic_4_32bit);
|
||||||
AddBitcodeToModule(builtins_bitcode_generic_4,
|
}
|
||||||
builtins_bitcode_generic_4_length,
|
else {
|
||||||
module, symbolTable);
|
EXPORT_MODULE(builtins_bitcode_generic_4_64bit);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
extern unsigned char builtins_bitcode_generic_8[];
|
if (runtime32) {
|
||||||
extern int builtins_bitcode_generic_8_length;
|
EXPORT_MODULE(builtins_bitcode_generic_8_32bit);
|
||||||
AddBitcodeToModule(builtins_bitcode_generic_8,
|
}
|
||||||
builtins_bitcode_generic_8_length,
|
else {
|
||||||
module, symbolTable);
|
EXPORT_MODULE(builtins_bitcode_generic_8_64bit);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
extern unsigned char builtins_bitcode_generic_16[];
|
if (runtime32) {
|
||||||
extern int builtins_bitcode_generic_16_length;
|
EXPORT_MODULE(builtins_bitcode_generic_16_32bit);
|
||||||
AddBitcodeToModule(builtins_bitcode_generic_16,
|
}
|
||||||
builtins_bitcode_generic_16_length,
|
else {
|
||||||
module, symbolTable);
|
EXPORT_MODULE(builtins_bitcode_generic_4_64bit);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 32:
|
case 32:
|
||||||
extern unsigned char builtins_bitcode_generic_32[];
|
if (runtime32) {
|
||||||
extern int builtins_bitcode_generic_32_length;
|
EXPORT_MODULE(builtins_bitcode_generic_32_32bit);
|
||||||
AddBitcodeToModule(builtins_bitcode_generic_32,
|
}
|
||||||
builtins_bitcode_generic_32_length,
|
else {
|
||||||
module, symbolTable);
|
EXPORT_MODULE(builtins_bitcode_generic_32_64bit);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 64:
|
case 64:
|
||||||
extern unsigned char builtins_bitcode_generic_64[];
|
if (runtime32) {
|
||||||
extern int builtins_bitcode_generic_64_length;
|
EXPORT_MODULE(builtins_bitcode_generic_64_32bit);
|
||||||
AddBitcodeToModule(builtins_bitcode_generic_64,
|
}
|
||||||
builtins_bitcode_generic_64_length,
|
else {
|
||||||
module, symbolTable);
|
EXPORT_MODULE(builtins_bitcode_generic_64_64bit);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
extern unsigned char builtins_bitcode_generic_1[];
|
if (runtime32) {
|
||||||
extern int builtins_bitcode_generic_1_length;
|
EXPORT_MODULE(builtins_bitcode_generic_1_32bit);
|
||||||
AddBitcodeToModule(builtins_bitcode_generic_1,
|
}
|
||||||
builtins_bitcode_generic_1_length,
|
else {
|
||||||
module, symbolTable);
|
EXPORT_MODULE(builtins_bitcode_generic_1_64bit);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
FATAL("logic error in DefineStdlib");
|
FATAL("logic error in DefineStdlib");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
FATAL("logic error");
|
FATAL("logic error");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user