This commit is contained in:
Robert Clipsham
2009-07-06 23:56:11 +01:00
7 changed files with 113 additions and 30 deletions

View File

@@ -53,11 +53,9 @@ execute_process(
OUTPUT_VARIABLE LLVM_LDFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(EXTRA_LLVM_MODULES "" CACHE STRING "extra llvm components to link in (see llvm-config --components)")
execute_process(
COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --libfiles bitwriter linker ipo instrumentation backend ${EXTRA_LLVM_MODULES}
OUTPUT_VARIABLE LLVM_LIBS
COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --includedir
OUTPUT_VARIABLE LLVM_INCLUDEDIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
@@ -133,7 +131,40 @@ set(LDC_GENERATED
set(DEFAULT_TARGET ${HOST_TARGET} CACHE STRING "default target")
set(DEFAULT_ALT_TARGET ${HOST_ALT_TARGET} CACHE STRING "default alt target")
include_directories(. ${DMDFE_PATH} ${DMDFE_PATH}/root ${PROJECT_BINARY_DIR}/${DMDFE_PATH} ${PROJECT_BINARY_DIR} ${LLVM_INSTDIR}/include)
include_directories(. ${DMDFE_PATH} ${DMDFE_PATH}/root ${PROJECT_BINARY_DIR}/${DMDFE_PATH} ${PROJECT_BINARY_DIR} ${LLVM_INCLUDEDIR})
set(EXTRA_LLVM_MODULES "" CACHE STRING "extra llvm components to link in (see llvm-config --components)")
separate_arguments(EXTRA_LLVM_MODULES)
execute_process(
COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --libfiles bitwriter linker ipo instrumentation backend ${EXTRA_LLVM_MODULES}
OUTPUT_VARIABLE LLVM_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# build a define that contains all LLVM targets required and is usable for
# preprocessor code generation. start with the native target.
find_path(LLVM_CONFIG_FILE_PATH config.h PATHS ${LLVM_INCLUDEDIR}/llvm/Config ${LLVM_INCLUDEDIR}/Config NO_DEFAULT_PATH)
if(LLVM_CONFIG_FILE_PATH STREQUAL "LLVM_CONFIG_FILE_PATH-NOTFOUND")
message("Couldn't find your llvm Config.h file in ${LLVM_INCLUDEDIR}, no native target will be initialized.")
else(LLVM_CONFIG_FILE_PATH STREQUAL "LLVM_CONFIG_FILE_PATH-NOTFOUND")
file(STRINGS ${LLVM_CONFIG_FILE_PATH}/config.h LLVM_NATIVE_ARCH REGEX "^#define LLVM_NATIVE_ARCH")
if(LLVM_NATIVE_ARCH)
string(REGEX REPLACE "^#define LLVM_NATIVE_ARCH (.*)Target$" "\\1" LLVM_NATIVE_ARCH ${LLVM_NATIVE_ARCH})
message("Found native target ${LLVM_NATIVE_ARCH}")
set(LLVM_MODULES_DEFINE "LLVM_TARGET(${LLVM_NATIVE_ARCH})")
else(LLVM_NATIVE_ARCH)
message("Couldn't find the LLVM_NATIVE_ARCH define in ${LLVM_CONFIG_FILE_PATH}/config.h. Probably you have an older LLVM and can ignore this warning.")
endif(LLVM_NATIVE_ARCH)
endif(LLVM_CONFIG_FILE_PATH STREQUAL "LLVM_CONFIG_FILE_PATH-NOTFOUND")
# chain the extra target list to the define
foreach(EXTRA_TARGET ${EXTRA_LLVM_MODULES})
set(LLVM_MODULES_DEFINE "${LLVM_MODULES_DEFINE} LLVM_TARGET(${EXTRA_TARGET})")
endforeach(EXTRA_TARGET)
set_source_files_properties(
${PROJECT_SOURCE_DIR}/gen/main.cpp PROPERTIES
COMPILE_DEFINITIONS LDC_TARGETS=${LLVM_MODULES_DEFINE}
)
file(GLOB FE_SRC ${DMDFE_PATH}/*.c)
file(GLOB FE_SRC_ROOT ${DMDFE_PATH}/root/*.c)

View File

@@ -397,6 +397,25 @@ LLConstant* DtoConstSlice(LLConstant* dim, LLConstant* ptr)
return llvm::ConstantStruct::get(values, 2);
}
//////////////////////////////////////////////////////////////////////////////////////////
static bool isInitialized(Type* et) {
// Strip static array types from element type
Type* bt = et->toBasetype();
while (bt->ty == Tsarray) {
et = bt->nextOf();
bt = et->toBasetype();
}
// If it's a typedef with "= void" initializer then don't initialize.
if (et->ty == Ttypedef) {
Logger::println("Typedef: %s", et->toChars());
TypedefDeclaration* tdd = ((TypeTypedef*)et)->sym;
if (tdd && tdd->init && tdd->init->isVoidInitializer())
return false;
}
// Otherwise, it's always initialized.
return true;
}
//////////////////////////////////////////////////////////////////////////////////////////
DSliceValue* DtoNewDynArray(Loc& loc, Type* arrayType, DValue* dim, bool defaultInit)
{
@@ -411,7 +430,10 @@ DSliceValue* DtoNewDynArray(Loc& loc, Type* arrayType, DValue* dim, bool default
LLValue* arrayLen = dim->getRVal();
// get runtime function
bool zeroInit = arrayType->toBasetype()->nextOf()->isZeroInit();
Type* eltType = arrayType->toBasetype()->nextOf();
if (defaultInit && !isInitialized(eltType))
defaultInit = false;
bool zeroInit = eltType->isZeroInit();
const char* fnname = defaultInit ? (zeroInit ? "_d_newarrayT" : "_d_newarrayiT") : "_d_newarrayvT";
LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, fnname);
@@ -445,6 +467,8 @@ DSliceValue* DtoNewMulDimDynArray(Loc& loc, Type* arrayType, DValue** dims, size
// get runtime function
bool zeroInit = vtype->isZeroInit();
if (defaultInit && !isInitialized(vtype))
defaultInit = false;
const char* fnname = defaultInit ? (zeroInit ? "_d_newarraymT" : "_d_newarraymiT") : "_d_newarraymvT";
LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, fnname);

View File

@@ -979,10 +979,12 @@ DValue* DtoDeclarationExp(Dsymbol* declaration)
else if (AttribDeclaration* a = declaration->isAttribDeclaration())
{
Logger::println("AttribDeclaration");
if (a->decl)
for (int i=0; i < a->decl->dim; ++i)
// choose the right set in case this is a conditional declaration
Array *d = a->include(NULL, NULL);
if (d)
for (int i=0; i < d->dim; ++i)
{
DtoDeclarationExp((Dsymbol*)a->decl->data[i]);
DtoDeclarationExp((Dsymbol*)d->data[i]);
}
}
// mixin declaration

View File

@@ -4,13 +4,20 @@
// which uses the llvm license
#include "gen/llvm.h"
#include "gen/llvm-version.h"
#include "llvm/LinkAllVMCore.h"
#include "llvm/Linker.h"
#if LLVM_REV >= 74640
#include "llvm/LLVMContext.h"
#endif
#include "llvm/System/Signals.h"
#include "llvm/Target/SubtargetFeature.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/Target/TargetMachineRegistry.h"
#if LLVM_REV >= 73610
#include "llvm/Target/TargetSelect.h"
#endif
#include <stdio.h>
#include <stdlib.h>
@@ -397,7 +404,11 @@ int main(int argc, char** argv)
if (global.errors)
fatal();
#if LLVM_REV >= 74640
llvm::Module mod("dummy", llvm::getGlobalContext());
#else
llvm::Module mod("dummy");
#endif
// override triple if needed
const char* defaultTriple = DEFAULT_TARGET_TRIPLE;
@@ -423,8 +434,17 @@ int main(int argc, char** argv)
mod.setTargetTriple(global.params.targetTriple);
// Allocate target machine. First, check whether the user has
// explicitly specified an architecture to compile for.
// Allocate target machine.
// first initialize llvm
#if LLVM_REV >= 73610
#define LLVM_TARGET(A) LLVMInitialize##A##Target(); LLVMInitialize##A##AsmPrinter();
// this is defined to be LLVM_TARGET(target name 1) LLVM_TARGET(target name 2) ...
LDC_TARGETS
#undef LLVM_TARGET
#endif
// Check whether the user has explicitly specified an architecture to compile for.
if (mArch == 0)
{
std::string Err;
@@ -908,7 +928,11 @@ int main(int argc, char** argv)
char* name = m->toChars();
char* filename = m->objfile->name->str;
#if LLVM_REV >= 74640
llvm::Linker linker(name, name, llvm::getGlobalContext());
#else
llvm::Linker linker(name, name);
#endif
std::string errormsg;
for (int i = 0; i < llvmModules.size(); i++)
{

View File

@@ -1,4 +1,8 @@
#include "gen/llvm.h"
#include "gen/llvm-version.h"
#if LLVM_REV >= 74640
#include "llvm/LLVMContext.h"
#endif
#include "llvm/Module.h"
#include "llvm/Attributes.h"
#include "llvm/Bitcode/ReaderWriter.h"
@@ -149,7 +153,11 @@ static const LLType* rt_dg2()
static void LLVM_D_BuildRuntimeModule()
{
Logger::println("building module");
#if LLVM_REV >= 74640
M = new llvm::Module("ldc internal runtime", llvm::getGlobalContext());
#else
M = new llvm::Module("ldc internal runtime");
#endif
Logger::println("building basic types");
const LLType* voidTy = LLType::VoidTy;

View File

@@ -45,23 +45,6 @@ static LLGlobalVariable* emitDwarfGlobalDecl(const LLStructType* type, const cha
//////////////////////////////////////////////////////////////////////////////////////////////////
static llvm::DIAnchor getDwarfAnchor(dwarf_constants c)
{
switch (c)
{
case DW_TAG_compile_unit:
return gIR->difactory.GetOrCreateCompileUnitAnchor();
case DW_TAG_variable:
return gIR->difactory.GetOrCreateGlobalVariableAnchor();
case DW_TAG_subprogram:
return gIR->difactory.GetOrCreateSubprogramAnchor();
default:
assert(0);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
static const llvm::StructType* getDwarfCompileUnitType() {
return isaStruct(gIR->module->getTypeByName("llvm.dbg.compile_unit.type"));
}
@@ -311,7 +294,11 @@ static llvm::DICompositeType dwarfCompositeType(Type* type, llvm::DICompileUnit
// set to handle recursive types properly
gv = emitDwarfGlobalDecl(getDwarfCompositeTypeType(), "llvm.dbg.compositetype");
// set bogus initializer to satisfy asserts in DICompositeType constructor
gv->setInitializer(LLConstant::getNullValue(getDwarfCompositeTypeType()));
std::vector<LLConstant*> initvals(11);
initvals[0] = DBG_TAG(DW_TAG_structure_type);
for (int i = 1; i < initvals.size(); ++i)
initvals[i] = LLConstant::getNullValue(getDwarfCompositeTypeType()->getContainedType(i));
gv->setInitializer(LLConstantStruct::get(getDwarfCompositeTypeType(), initvals));
ir->diCompositeType = llvm::DICompositeType(gv);
tag = DW_TAG_structure_type;

View File

@@ -11,8 +11,12 @@
#include <fstream>
#include "gen/llvm.h"
#include "gen/llvm-version.h"
#include "llvm/Analysis/Verifier.h"
#include "llvm/Bitcode/ReaderWriter.h"
#if LLVM_REV >= 74640
#include "llvm/LLVMContext.h"
#endif
#include "llvm/Module.h"
#include "llvm/ModuleProvider.h"
#include "llvm/PassManager.h"
@@ -43,7 +47,6 @@
#include "gen/functions.h"
#include "gen/irstate.h"
#include "gen/llvmhelpers.h"
#include "gen/llvm-version.h"
#include "gen/logger.h"
#include "gen/optimizer.h"
#include "gen/programs.h"
@@ -94,7 +97,11 @@ llvm::Module* Module::genLLVMModule(Ir* sir)
// create a new ir state
// TODO look at making the instance static and moving most functionality into IrModule where it belongs
#if LLVM_REV >= 74640
IRState ir(new llvm::Module(mname, llvm::getGlobalContext()));
#else
IRState ir(new llvm::Module(mname));
#endif
gIR = &ir;
ir.dmodule = this;