[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.

Tried adding a stack trace print when compiler crashes, not sure it's working though.
Changed data layouts to match that of llvm-gcc.
Fixed casting function pointers.
Added support checks in AsmStatement.
This commit is contained in:
Tomas Lindquist Olsen
2008-06-08 19:09:24 +02:00
parent c1d240582d
commit 6ededdd9e3
14 changed files with 85 additions and 46 deletions

View File

@@ -8,6 +8,7 @@
// See the included readme.txt for details.
#include "llvm/Target/TargetMachineRegistry.h"
#include "llvm/System/Signals.h"
#include <stdio.h>
#include <stdlib.h>
@@ -180,6 +181,7 @@ Usage:\n\
-debuglib=name set symbolic debug library to name\n\
-defaultlib=name set default library to name\n\
-dis disassemble module after compiling\n\
-fp80 enable 80bit reals on x86 32bit (EXPERIMENTAL)\n\
-g add symbolic debug info\n\
-gc add symbolic debug info, pretend to be C\n\
-H generate 'header' file\n\
@@ -193,6 +195,7 @@ Usage:\n\
-Llinkerflag pass linkerflag to link\n\
-m<arch> emit code specific to <arch>\n\
x86 x86-64 ppc32 ppc64\n\
-noasm do not allow use of inline asm\n\
-nofloat do not emit reference to floating point\n\
-noruntime do not allow code that generates implicit runtime calls\n\
-noverify do not run the validation pass before writing bitcode\n\
@@ -215,10 +218,6 @@ Usage:\n\
-version=level compile in version code >= level\n\
-version=ident compile in version code identified by ident\n\
-w enable warnings\n\
\n\
Experimental features:\n\
-inlineasm allow use of inline asm\n\
-fp80 enable 80bit reals on x86 32bit\n\
",
#if WIN32
" @cmdfile read arguments from cmdfile\n"
@@ -230,6 +229,8 @@ Experimental features:\n\
int main(int argc, char *argv[])
{
llvm::sys::PrintStackTraceOnErrorSignal();
int i;
Array files;
char *p;
@@ -300,6 +301,7 @@ int main(int argc, char *argv[])
global.params.novalidate = 0;
global.params.optimizeLevel = -1;
global.params.runtimeImppath = 0;
global.params.useInlineAsm = 1;
global.params.defaultlibname = "phobos";
global.params.debuglibname = global.params.defaultlibname;
@@ -402,8 +404,8 @@ int main(int argc, char *argv[])
global.params.llvmAnnotate = 1;
else if (strcmp(p + 1, "fp80") == 0)
global.params.useFP80 = 1;
else if (strcmp(p + 1, "inlineasm") == 0)
global.params.useInlineAsm = 1;
else if (strcmp(p + 1, "noasm") == 0)
global.params.useInlineAsm = 0;
else if (p[1] == 'o')
{
switch (p[2])
@@ -710,31 +712,36 @@ int main(int argc, char *argv[])
//VersionCondition::addPredefinedGlobalIdent("LLVM_InlineAsm_X86");
global.params.isLE = true;
global.params.is64bit = false;
global.params.cpu = ARCHx86;
tt_arch = "i686";
data_layout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:8";
data_layout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-f80:32:32-v64:64:64-v128:128:128-a0:0:64";
is_x86 = true;
}
else if (strcmp(global.params.llvmArch,"x86-64")==0) {
VersionCondition::addPredefinedGlobalIdent("X86_64");
//VersionCondition::addPredefinedGlobalIdent("LLVM_InlineAsm_X86_64");
global.params.isLE = true;
global.params.is64bit = true;
global.params.cpu = ARCHx86_64;
tt_arch = "x86_64";
data_layout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:8";
data_layout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64";
}
else if (strcmp(global.params.llvmArch,"ppc32")==0) {
VersionCondition::addPredefinedGlobalIdent("PPC");
global.params.isLE = false;
global.params.is64bit = false;
global.params.cpu = ARCHppc;
tt_arch = "powerpc";
data_layout = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:8";
data_layout = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64";
}
else if (strcmp(global.params.llvmArch,"ppc64")==0) {
VersionCondition::addPredefinedGlobalIdent("PPC64");
global.params.isLE = false;
global.params.is64bit = true;
global.params.cpu = ARCHppc_64;
tt_arch = "powerpc64";
data_layout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:8";
data_layout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64";
}
else {
assert(0 && "Invalid arch");
@@ -755,15 +762,14 @@ int main(int argc, char *argv[])
VersionCondition::addPredefinedGlobalIdent("LLVM64");
}
if (!is_x86 && (global.params.useFP80 || global.params.useInlineAsm)) {
error("the -fp80 option is only valid for the x86 32bit architecture");
fatal();
}
if (global.params.useFP80) {
if (!is_x86) {
error("the -fp80 option is only valid for the x86 32bit architecture");
fatal();
}
VersionCondition::addPredefinedGlobalIdent("LLVM_X86_FP80");
}
if (global.params.useInlineAsm) {
if (is_x86 && global.params.useInlineAsm) {
VersionCondition::addPredefinedGlobalIdent("D_InlineAsm");
VersionCondition::addPredefinedGlobalIdent("D_InlineAsm_X86");
}

View File

@@ -291,6 +291,14 @@ enum MATCH
MATCHexact // exact match
};
enum ARCH
{
ARCHx86,
ARCHx86_64,
ARCHppc,
ARCHppc_64
};
void error(Loc loc, const char *format, ...);
void verror(Loc loc, const char *format, va_list);
void fatal();

View File

@@ -198,7 +198,20 @@ bool d_have_inline_asm() { return true; }
Statement *AsmStatement::semantic(Scope *sc)
{
bool err = false;
if (global.params.cpu != ARCHx86)
{
error("inline asm is not supported for the \"%s\" architecture", global.params.llvmArch);
err = true;
}
if (!global.params.useInlineAsm)
{
error("inline asm is not allowed when the -noasm switch is used");
err = true;
}
if (err)
fatal();
sc->func->inlineAsm = 1;
sc->func->inlineStatus = ILSno; // %% not sure
// %% need to set DECL_UNINLINABLE too?
@@ -262,8 +275,6 @@ AsmStatement::toIR(IRState * irs)
LLValue* arg_val = 0;
std::string cns;
std::cout << std::endl;
switch (arg->type) {
case Arg_Integer:
arg_val = arg->expr->toElem(irs)->getRVal();
@@ -379,7 +390,7 @@ assert(0);
++p;
}
printf("final: %.*s\n", code->insnTemplateLen, code->insnTemplate);
Logger::println("final asm: %.*s", code->insnTemplateLen, code->insnTemplate);
std::string insnt(code->insnTemplate, code->insnTemplateLen);

View File

@@ -1117,7 +1117,7 @@ DValue* DtoCastPtr(DValue* val, Type* to)
Type* totype = DtoDType(to);
Type* fromtype = DtoDType(val->getType());
assert(fromtype->ty == Tpointer);
assert(fromtype->ty == Tpointer || fromtype->ty == Tfunction);
LLValue* rval;
@@ -1256,7 +1256,7 @@ DValue* DtoCast(DValue* val, Type* to)
else if (fromtype->ty == Tarray || fromtype->ty == Tsarray) {
return DtoCastArray(val, to);
}
else if (fromtype->ty == Tpointer) {
else if (fromtype->ty == Tpointer || fromtype->ty == Tfunction) {
return DtoCastPtr(val, to);
}
else {

View File

@@ -118,6 +118,7 @@ gen/functions.cpp
gen/functions.h
gen/irstate.cpp
gen/irstate.h
gen/linker.h
gen/llvm.h
gen/logger.cpp
gen/logger.h
@@ -749,6 +750,7 @@ tangotests/a.d
tangotests/aa1.d
tangotests/aa2.d
tangotests/align1.d
tangotests/apply1.d
tangotests/arrays1.d
tangotests/asm1.d
tangotests/asm2.d

View File

@@ -26,7 +26,7 @@ package.excludes = { "dmd/idgen.c", "dmd/impcnvgen.c" }
package.buildoptions = { "-x c++", "`llvm-config --cxxflags`" }
package.linkoptions = {
-- long but it's faster than just 'all'
"`llvm-config --libs core asmparser bitreader bitwriter support target transformutils scalaropts ipo instrumentation x86 powerpc`",
"`llvm-config --libs core asmparser bitreader bitwriter linker support target transformutils scalaropts ipo instrumentation x86 powerpc`",
"`llvm-config --ldflags`",
}
package.defines = {

View File

@@ -2260,7 +2260,10 @@ private
{
version( D_InlineAsm_X86 )
{
version( X86_64 )
version( LLVMDC )
{
}
else version( X86_64 )
{
}

View File

@@ -22,14 +22,14 @@ MD=mkdir -p
ADD_CFLAGS=
ADD_DFLAGS=
#CFLAGS=-O $(ADD_CFLAGS)
#CFLAGS=-O3 $(ADD_CFLAGS)
CFLAGS=-g $(ADD_CFLAGS)
#DFLAGS=-release -O -inline -w $(ADD_DFLAGS)
DFLAGS=-g -w $(ADD_DFLAGS)
#DFLAGS=-release -O3 -inline -w $(ADD_DFLAGS)
DFLAGS=-g -w -noasm $(ADD_DFLAGS)
#TFLAGS=-O -inline -w $(ADD_DFLAGS)
TFLAGS=-g -w $(ADD_DFLAGS)
#TFLAGS=-O3 -inline -w $(ADD_DFLAGS)
TFLAGS=-g -w -noasm $(ADD_DFLAGS)
DOCFLAGS=-version=DDoc

View File

@@ -473,7 +473,11 @@ unittest
extern (C) int _adCmpChar(Array a1, Array a2)
{
version (D_InlineAsm_X86)
version(D_InlineAsm_X86)
{
//version = Asm86;
}
version (Asm86)
{
asm
{ naked ;

View File

@@ -29,6 +29,9 @@ module lifetime;
//debug=PRINTF;
//debug=PRINTF2;
// we're not allowed to jump out of asm blocks
//version(D_InlineAsm_X86) version = Asm86;
private
{
import tango.stdc.stdlib;
@@ -210,7 +213,7 @@ extern (C) void* _d_newarrayT(TypeInfo ti, size_t length)
if (length == 0 || size == 0)
return null;
version (D_InlineAsm_X86)
version (Asm86)
{
asm
{
@@ -249,7 +252,7 @@ extern (C) void* _d_newarrayiT(TypeInfo ti, size_t length)
auto initializer = ti.next.init();
auto isize = initializer.length;
auto q = initializer.ptr;
version (D_InlineAsm_X86)
version (Asm86)
{
asm
{
@@ -520,7 +523,7 @@ body
if (newlength)
{
version (D_InlineAsm_X86)
version (Asm86)
{
size_t newsize = void;
@@ -619,7 +622,7 @@ body
if (newlength)
{
version (D_InlineAsm_X86)
version (Asm86)
{
size_t newsize = void;

View File

@@ -24,10 +24,10 @@ MD=mkdir -p
CFLAGS=-g $(ADD_CFLAGS)
#DFLAGS=-release -O3 -inline -w $(ADD_DFLAGS)
DFLAGS=-g -w $(ADD_DFLAGS)
DFLAGS=-g -w -noasm $(ADD_DFLAGS)
#TFLAGS=-O3 -inline -w $(ADD_DFLAGS)
TFLAGS=-g -w $(ADD_DFLAGS)
TFLAGS=-g -w -noasm $(ADD_DFLAGS)
DOCFLAGS=-version=DDoc

View File

@@ -39,6 +39,10 @@ else version (GNU)
{
// use the unoptimized version
}
else version(LLVMDC)
{
// ditto
}
else version (D_InlineAsm_X86)
{
version = Asm86;

View File

@@ -20,14 +20,14 @@ MD=mkdir -p
ADD_CFLAGS=
ADD_DFLAGS=
#CFLAGS=-O $(ADD_CFLAGS)
#CFLAGS=-O3 $(ADD_CFLAGS)
CFLAGS=-g $(ADD_CFLAGS)
#DFLAGS=-release -O -inline -w -nofloat $(ADD_DFLAGS)
DFLAGS=-g -w -nofloat $(ADD_DFLAGS)
#DFLAGS=-release -O3 -inline -w -nofloat $(ADD_DFLAGS)
DFLAGS=-g -w -nofloat -noasm $(ADD_DFLAGS)
TFLAGS=-O -inline -w -nofloat $(ADD_DFLAGS)
#TFLAGS=-g -w -nofloat $(ADD_DFLAGS)
#TFLAGS=-O3 -inline -w -nofloat $(ADD_DFLAGS)
TFLAGS=-g -w -nofloat -noasm $(ADD_DFLAGS)
DOCFLAGS=-version=DDoc

View File

@@ -20,15 +20,13 @@ MD=mkdir -p
ADD_CFLAGS=
ADD_DFLAGS=
#CFLAGS=-O $(ADD_CFLAGS)
#CFLAGS=-O3 $(ADD_CFLAGS)
CFLAGS=-g $(ADD_CFLAGS)
### warnings disabled because gcx has issues ###
#DFLAGS=-release -O -inline $(ADD_DFLAGS)
#DFLAGS=-release -O3 -inline -w $(ADD_DFLAGS)
DFLAGS=-g $(ADD_DFLAGS)
#TFLAGS=-O -inline $(ADD_DFLAGS)
#TFLAGS=-O3 -inline $(ADD_DFLAGS)
TFLAGS=-g $(ADD_DFLAGS)
DOCFLAGS=-version=DDoc