forked from OSchip/llvm-project
Added some eye-candy for Subtarget type checking
Added X86 StdCall & FastCall calling conventions. Codegen will follow. llvm-svn: 30446
This commit is contained in:
parent
f16dc007e6
commit
6f7072c66a
|
@ -1636,11 +1636,31 @@ that people test.</p>
|
|||
<li><b>i386-unknown-freebsd5.3</b> - FreeBSD 5.3</li>
|
||||
<li><b>i686-pc-cygwin</b> - Cygwin on Win32</li>
|
||||
<li><b>i686-pc-mingw32</b> - MingW on Win32</li>
|
||||
<li><b>i386-pc-mingw32msvc</b> - MingW crosscompiler on Linux</li>
|
||||
<li><b>i686-apple-darwin*</b> - Apple Darwin on X86</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- _______________________________________________________________________ -->
|
||||
<div class="doc_subsubsection">
|
||||
<a name="x86_cc">X86 Calling Conventions supported</a>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="doc_text">
|
||||
|
||||
<p>The folowing target-specific calling conventions are known to backend:</p>
|
||||
|
||||
<ul>
|
||||
<li><b>x86_StdCall</b> - stdcall calling convention seen on Microsoft Windows
|
||||
platform (CC ID = 64).</li>
|
||||
<li><b>x86_FastCall</b> - fastcall calling convention seen on Microsoft Windows
|
||||
platform (CC ID = 65).</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- _______________________________________________________________________ -->
|
||||
<div class="doc_subsubsection">
|
||||
<a name="x86_memory">Representing X86 addressing modes in MachineInstrs</a>
|
||||
|
|
|
@ -24,10 +24,10 @@ namespace CallingConv {
|
|||
/// calling conventions.
|
||||
/// @brief LLVM Calling Convention Representation
|
||||
enum ID {
|
||||
// C - The default llvm calling convention, compatible with C. This
|
||||
// convention is the only calling convention that supports varargs calls.
|
||||
// As with typical C calling conventions, the callee/caller have to tolerate
|
||||
// certain amounts of prototype mismatch.
|
||||
/// C - The default llvm calling convention, compatible with C. This
|
||||
/// convention is the only calling convention that supports varargs calls.
|
||||
/// As with typical C calling conventions, the callee/caller have to tolerate
|
||||
/// certain amounts of prototype mismatch.
|
||||
C = 0,
|
||||
|
||||
/// CSRet - C Struct Return calling convention. This convention requires
|
||||
|
@ -42,8 +42,8 @@ namespace CallingConv {
|
|||
// support varargs calls, and all assume that the caller and callee
|
||||
// prototype exactly match.
|
||||
|
||||
// Fast - This calling convention attempts to make calls as fast as possible
|
||||
// (e.g. by passing things in registers).
|
||||
/// Fast - This calling convention attempts to make calls as fast as possible
|
||||
/// (e.g. by passing things in registers).
|
||||
Fast = 8,
|
||||
|
||||
// Cold - This calling convention attempts to make code in the caller as
|
||||
|
@ -54,7 +54,18 @@ namespace CallingConv {
|
|||
|
||||
// Target - This is the start of the target-specific calling conventions,
|
||||
// e.g. fastcall and thiscall on X86.
|
||||
FirstTargetCC = 64
|
||||
FirstTargetCC = 64,
|
||||
|
||||
/// X86_StdCall - stdcall is the calling conventions mostly used by the
|
||||
/// Win32 API. It is basically the same as the C convention with the
|
||||
/// difference in that the callee is responsible for popping the arguments
|
||||
/// from the stack.
|
||||
X86_StdCall = 64,
|
||||
|
||||
/// X86_FastCall - 'fast' analog of X86_StdCall. Passes first two arguments
|
||||
/// in ECX:EDX registers, others - via stack. Callee is responsible for
|
||||
/// stack cleaning.
|
||||
X86_FastCall = 65
|
||||
};
|
||||
} // End CallingConv namespace
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -224,6 +224,8 @@ ccc { return CCC_TOK; }
|
|||
csretcc { return CSRETCC_TOK; }
|
||||
fastcc { return FASTCC_TOK; }
|
||||
coldcc { return COLDCC_TOK; }
|
||||
x86_stdcallcc { return X86_STDCALLCC_TOK; }
|
||||
x86_fastcallcc { return X86_FASTCALLCC_TOK; }
|
||||
|
||||
void { llvmAsmlval.PrimType = Type::VoidTy ; return VOID; }
|
||||
bool { llvmAsmlval.PrimType = Type::BoolTy ; return BOOL; }
|
||||
|
|
|
@ -224,6 +224,8 @@ ccc { return CCC_TOK; }
|
|||
csretcc { return CSRETCC_TOK; }
|
||||
fastcc { return FASTCC_TOK; }
|
||||
coldcc { return COLDCC_TOK; }
|
||||
x86_stdcallcc { return X86_STDCALLCC_TOK; }
|
||||
x86_fastcallcc { return X86_FASTCALLCC_TOK; }
|
||||
|
||||
void { llvmAsmlval.PrimType = Type::VoidTy ; return VOID; }
|
||||
bool { llvmAsmlval.PrimType = Type::BoolTy ; return BOOL; }
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -105,43 +105,45 @@
|
|||
CSRETCC_TOK = 321,
|
||||
FASTCC_TOK = 322,
|
||||
COLDCC_TOK = 323,
|
||||
RET = 324,
|
||||
BR = 325,
|
||||
SWITCH = 326,
|
||||
INVOKE = 327,
|
||||
UNWIND = 328,
|
||||
UNREACHABLE = 329,
|
||||
ADD = 330,
|
||||
SUB = 331,
|
||||
MUL = 332,
|
||||
DIV = 333,
|
||||
REM = 334,
|
||||
AND = 335,
|
||||
OR = 336,
|
||||
XOR = 337,
|
||||
SETLE = 338,
|
||||
SETGE = 339,
|
||||
SETLT = 340,
|
||||
SETGT = 341,
|
||||
SETEQ = 342,
|
||||
SETNE = 343,
|
||||
MALLOC = 344,
|
||||
ALLOCA = 345,
|
||||
FREE = 346,
|
||||
LOAD = 347,
|
||||
STORE = 348,
|
||||
GETELEMENTPTR = 349,
|
||||
PHI_TOK = 350,
|
||||
CAST = 351,
|
||||
SELECT = 352,
|
||||
SHL = 353,
|
||||
SHR = 354,
|
||||
VAARG = 355,
|
||||
EXTRACTELEMENT = 356,
|
||||
INSERTELEMENT = 357,
|
||||
SHUFFLEVECTOR = 358,
|
||||
VAARG_old = 359,
|
||||
VANEXT_old = 360
|
||||
X86_STDCALLCC_TOK = 324,
|
||||
X86_FASTCALLCC_TOK = 325,
|
||||
RET = 326,
|
||||
BR = 327,
|
||||
SWITCH = 328,
|
||||
INVOKE = 329,
|
||||
UNWIND = 330,
|
||||
UNREACHABLE = 331,
|
||||
ADD = 332,
|
||||
SUB = 333,
|
||||
MUL = 334,
|
||||
DIV = 335,
|
||||
REM = 336,
|
||||
AND = 337,
|
||||
OR = 338,
|
||||
XOR = 339,
|
||||
SETLE = 340,
|
||||
SETGE = 341,
|
||||
SETLT = 342,
|
||||
SETGT = 343,
|
||||
SETEQ = 344,
|
||||
SETNE = 345,
|
||||
MALLOC = 346,
|
||||
ALLOCA = 347,
|
||||
FREE = 348,
|
||||
LOAD = 349,
|
||||
STORE = 350,
|
||||
GETELEMENTPTR = 351,
|
||||
PHI_TOK = 352,
|
||||
CAST = 353,
|
||||
SELECT = 354,
|
||||
SHL = 355,
|
||||
SHR = 356,
|
||||
VAARG = 357,
|
||||
EXTRACTELEMENT = 358,
|
||||
INSERTELEMENT = 359,
|
||||
SHUFFLEVECTOR = 360,
|
||||
VAARG_old = 361,
|
||||
VANEXT_old = 362
|
||||
};
|
||||
#endif
|
||||
/* Tokens. */
|
||||
|
@ -211,43 +213,45 @@
|
|||
#define CSRETCC_TOK 321
|
||||
#define FASTCC_TOK 322
|
||||
#define COLDCC_TOK 323
|
||||
#define RET 324
|
||||
#define BR 325
|
||||
#define SWITCH 326
|
||||
#define INVOKE 327
|
||||
#define UNWIND 328
|
||||
#define UNREACHABLE 329
|
||||
#define ADD 330
|
||||
#define SUB 331
|
||||
#define MUL 332
|
||||
#define DIV 333
|
||||
#define REM 334
|
||||
#define AND 335
|
||||
#define OR 336
|
||||
#define XOR 337
|
||||
#define SETLE 338
|
||||
#define SETGE 339
|
||||
#define SETLT 340
|
||||
#define SETGT 341
|
||||
#define SETEQ 342
|
||||
#define SETNE 343
|
||||
#define MALLOC 344
|
||||
#define ALLOCA 345
|
||||
#define FREE 346
|
||||
#define LOAD 347
|
||||
#define STORE 348
|
||||
#define GETELEMENTPTR 349
|
||||
#define PHI_TOK 350
|
||||
#define CAST 351
|
||||
#define SELECT 352
|
||||
#define SHL 353
|
||||
#define SHR 354
|
||||
#define VAARG 355
|
||||
#define EXTRACTELEMENT 356
|
||||
#define INSERTELEMENT 357
|
||||
#define SHUFFLEVECTOR 358
|
||||
#define VAARG_old 359
|
||||
#define VANEXT_old 360
|
||||
#define X86_STDCALLCC_TOK 324
|
||||
#define X86_FASTCALLCC_TOK 325
|
||||
#define RET 326
|
||||
#define BR 327
|
||||
#define SWITCH 328
|
||||
#define INVOKE 329
|
||||
#define UNWIND 330
|
||||
#define UNREACHABLE 331
|
||||
#define ADD 332
|
||||
#define SUB 333
|
||||
#define MUL 334
|
||||
#define DIV 335
|
||||
#define REM 336
|
||||
#define AND 337
|
||||
#define OR 338
|
||||
#define XOR 339
|
||||
#define SETLE 340
|
||||
#define SETGE 341
|
||||
#define SETLT 342
|
||||
#define SETGT 343
|
||||
#define SETEQ 344
|
||||
#define SETNE 345
|
||||
#define MALLOC 346
|
||||
#define ALLOCA 347
|
||||
#define FREE 348
|
||||
#define LOAD 349
|
||||
#define STORE 350
|
||||
#define GETELEMENTPTR 351
|
||||
#define PHI_TOK 352
|
||||
#define CAST 353
|
||||
#define SELECT 354
|
||||
#define SHL 355
|
||||
#define SHR 356
|
||||
#define VAARG 357
|
||||
#define EXTRACTELEMENT 358
|
||||
#define INSERTELEMENT 359
|
||||
#define SHUFFLEVECTOR 360
|
||||
#define VAARG_old 361
|
||||
#define VANEXT_old 362
|
||||
|
||||
|
||||
|
||||
|
@ -295,7 +299,7 @@ typedef union YYSTYPE
|
|||
llvm::Module::Endianness Endianness;
|
||||
}
|
||||
/* Line 1528 of yacc.c. */
|
||||
#line 299 "llvmAsmParser.tab.h"
|
||||
#line 303 "llvmAsmParser.tab.h"
|
||||
YYSTYPE;
|
||||
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
|
|
|
@ -1006,6 +1006,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
|
|||
%token OPAQUE NOT EXTERNAL TARGET TRIPLE ENDIAN POINTERSIZE LITTLE BIG ALIGN
|
||||
%token DEPLIBS CALL TAIL ASM_TOK MODULE SIDEEFFECT
|
||||
%token CC_TOK CCC_TOK CSRETCC_TOK FASTCC_TOK COLDCC_TOK
|
||||
%token X86_STDCALLCC_TOK X86_FASTCALLCC_TOK
|
||||
%type <UIntVal> OptCallingConv
|
||||
|
||||
// Basic Block Terminating Operators
|
||||
|
@ -1083,12 +1084,14 @@ OptLinkage : INTERNAL { $$ = GlobalValue::InternalLinkage; } |
|
|||
EXTERN_WEAK { $$ = GlobalValue::ExternalWeakLinkage; } |
|
||||
/*empty*/ { $$ = GlobalValue::ExternalLinkage; };
|
||||
|
||||
OptCallingConv : /*empty*/ { $$ = CallingConv::C; } |
|
||||
CCC_TOK { $$ = CallingConv::C; } |
|
||||
CSRETCC_TOK { $$ = CallingConv::CSRet; } |
|
||||
FASTCC_TOK { $$ = CallingConv::Fast; } |
|
||||
COLDCC_TOK { $$ = CallingConv::Cold; } |
|
||||
CC_TOK EUINT64VAL {
|
||||
OptCallingConv : /*empty*/ { $$ = CallingConv::C; } |
|
||||
CCC_TOK { $$ = CallingConv::C; } |
|
||||
CSRETCC_TOK { $$ = CallingConv::CSRet; } |
|
||||
FASTCC_TOK { $$ = CallingConv::Fast; } |
|
||||
COLDCC_TOK { $$ = CallingConv::Cold; } |
|
||||
X86_STDCALLCC_TOK { $$ = CallingConv::X86_StdCall; } |
|
||||
X86_FASTCALLCC_TOK { $$ = CallingConv::X86_FastCall; } |
|
||||
CC_TOK EUINT64VAL {
|
||||
if ((unsigned)$2 != $2)
|
||||
GEN_ERROR("Calling conv too large!");
|
||||
$$ = $2;
|
||||
|
|
|
@ -1006,6 +1006,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
|
|||
%token OPAQUE NOT EXTERNAL TARGET TRIPLE ENDIAN POINTERSIZE LITTLE BIG ALIGN
|
||||
%token DEPLIBS CALL TAIL ASM_TOK MODULE SIDEEFFECT
|
||||
%token CC_TOK CCC_TOK CSRETCC_TOK FASTCC_TOK COLDCC_TOK
|
||||
%token X86_STDCALLCC_TOK X86_FASTCALLCC_TOK
|
||||
%type <UIntVal> OptCallingConv
|
||||
|
||||
// Basic Block Terminating Operators
|
||||
|
@ -1083,12 +1084,14 @@ OptLinkage : INTERNAL { $$ = GlobalValue::InternalLinkage; } |
|
|||
EXTERN_WEAK { $$ = GlobalValue::ExternalWeakLinkage; } |
|
||||
/*empty*/ { $$ = GlobalValue::ExternalLinkage; };
|
||||
|
||||
OptCallingConv : /*empty*/ { $$ = CallingConv::C; } |
|
||||
CCC_TOK { $$ = CallingConv::C; } |
|
||||
CSRETCC_TOK { $$ = CallingConv::CSRet; } |
|
||||
FASTCC_TOK { $$ = CallingConv::Fast; } |
|
||||
COLDCC_TOK { $$ = CallingConv::Cold; } |
|
||||
CC_TOK EUINT64VAL {
|
||||
OptCallingConv : /*empty*/ { $$ = CallingConv::C; } |
|
||||
CCC_TOK { $$ = CallingConv::C; } |
|
||||
CSRETCC_TOK { $$ = CallingConv::CSRet; } |
|
||||
FASTCC_TOK { $$ = CallingConv::Fast; } |
|
||||
COLDCC_TOK { $$ = CallingConv::Cold; } |
|
||||
X86_STDCALLCC_TOK { $$ = CallingConv::X86_StdCall; } |
|
||||
X86_FASTCALLCC_TOK { $$ = CallingConv::X86_FastCall; } |
|
||||
CC_TOK EUINT64VAL {
|
||||
if ((unsigned)$2 != $2)
|
||||
GEN_ERROR("Calling conv too large!");
|
||||
$$ = $2;
|
||||
|
|
|
@ -1278,7 +1278,15 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
|
|||
if (F->hasInternalLinkage()) Out << "static ";
|
||||
if (F->hasDLLImportLinkage()) Out << "__declspec(dllimport) ";
|
||||
if (F->hasDLLExportLinkage()) Out << "__declspec(dllexport) ";
|
||||
|
||||
switch (F->getCallingConv()) {
|
||||
case CallingConv::X86_StdCall:
|
||||
Out << "__stdcall ";
|
||||
break;
|
||||
case CallingConv::X86_FastCall:
|
||||
Out << "__fastcall ";
|
||||
break;
|
||||
}
|
||||
|
||||
// Loop over the arguments, printing them...
|
||||
const FunctionType *FT = cast<FunctionType>(F->getFunctionType());
|
||||
|
||||
|
|
|
@ -707,3 +707,29 @@ etc.
|
|||
|
||||
//===---------------------------------------------------------------------===//
|
||||
|
||||
Currently we don't have elimination of redundant stack manipulations. Consider
|
||||
the code:
|
||||
|
||||
int %main() {
|
||||
entry:
|
||||
call fastcc void %test1( )
|
||||
call fastcc void %test2( sbyte* cast (void ()* %test1 to sbyte*) )
|
||||
ret int 0
|
||||
}
|
||||
|
||||
declare fastcc void %test1()
|
||||
|
||||
declare fastcc void %test2(sbyte*)
|
||||
|
||||
|
||||
This currently compiles to:
|
||||
|
||||
subl $16, %esp
|
||||
call _test5
|
||||
addl $12, %esp
|
||||
subl $16, %esp
|
||||
movl $_test5, (%esp)
|
||||
call _test6
|
||||
addl $12, %esp
|
||||
|
||||
The add\sub pair is really unneeded here.
|
||||
|
|
|
@ -63,7 +63,7 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|||
".section __TEXT,__textcoal_nt,coalesced,pure_instructions", F);
|
||||
O << "\t.globl\t" << CurrentFnName << "\n";
|
||||
O << "\t.weak_definition\t" << CurrentFnName << "\n";
|
||||
} else if (Subtarget->TargetType == X86Subtarget::isCygwin) {
|
||||
} else if (Subtarget->isTargetCygwin()) {
|
||||
EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
|
||||
O << "\t.section\t.llvm.linkonce.t." << CurrentFnName
|
||||
<< ",\"ax\"\n";
|
||||
|
|
|
@ -83,7 +83,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
|
|||
} else
|
||||
O << TAI->getCOMMDirective() << name << "," << Size;
|
||||
} else {
|
||||
if (Subtarget->TargetType != X86Subtarget::isCygwin) {
|
||||
if (!Subtarget->isTargetCygwin()) {
|
||||
if (I->hasInternalLinkage())
|
||||
O << "\t.local\t" << name << "\n";
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
|
|||
O << "\t.globl " << name << "\n"
|
||||
<< "\t.weak_definition " << name << "\n";
|
||||
SwitchToDataSection(".section __DATA,__const_coal,coalesced", I);
|
||||
} else if (Subtarget->TargetType == X86Subtarget::isCygwin) {
|
||||
} else if (Subtarget->isTargetCygwin()) {
|
||||
O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\"\n"
|
||||
<< "\t.weak " << name << "\n";
|
||||
} else {
|
||||
|
|
|
@ -468,7 +468,7 @@ void X86DAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
|
|||
/// the main function.
|
||||
void X86DAGToDAGISel::EmitSpecialCodeForMain(MachineBasicBlock *BB,
|
||||
MachineFrameInfo *MFI) {
|
||||
if (Subtarget->TargetType == X86Subtarget::isCygwin)
|
||||
if (Subtarget->isTargetCygwin())
|
||||
BuildMI(BB, X86::CALLpcrel32, 1).addExternalSymbol("__main");
|
||||
|
||||
// Switch the FPU to 64-bit precision mode for better compatibility and speed.
|
||||
|
|
|
@ -3907,7 +3907,7 @@ X86TargetLowering::LowerFORMAL_ARGUMENTS(SDOperand Op, SelectionDAG &DAG) {
|
|||
MachineFunction &MF = DAG.getMachineFunction();
|
||||
const Function* Fn = MF.getFunction();
|
||||
if (Fn->hasExternalLinkage() &&
|
||||
Subtarget->TargetType == X86Subtarget::isCygwin &&
|
||||
Subtarget->isTargetCygwin() &&
|
||||
Fn->getName() == "main")
|
||||
MF.getInfo<X86FunctionInfo>()->setForceFramePointer(true);
|
||||
|
||||
|
|
|
@ -993,7 +993,7 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const {
|
|||
MFI->setStackSize(NumBytes);
|
||||
|
||||
if (NumBytes) { // adjust stack pointer: ESP -= numbytes
|
||||
if (NumBytes >= 4096 && Subtarget->TargetType == X86Subtarget::isCygwin) {
|
||||
if (NumBytes >= 4096 && Subtarget->isTargetCygwin()) {
|
||||
// Function prologue calls _alloca to probe the stack when allocating
|
||||
// more than 4k bytes in one go. Touching the stack at 4K increments is
|
||||
// necessary to ensure that the guard pages used by the OS virtual memory
|
||||
|
@ -1035,7 +1035,7 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const {
|
|||
|
||||
// If it's main() on Cygwin\Mingw32 we should align stack as well
|
||||
if (Fn->hasExternalLinkage() && Fn->getName() == "main" &&
|
||||
Subtarget->TargetType == X86Subtarget::isCygwin) {
|
||||
Subtarget->isTargetCygwin()) {
|
||||
MI = BuildMI(X86::AND32ri, 2, X86::ESP).addReg(X86::ESP).addImm(-Align);
|
||||
MBB.insert(MBBI, MI);
|
||||
|
||||
|
|
|
@ -332,6 +332,7 @@ void Verifier::visitFunction(Function &F) {
|
|||
break;
|
||||
case CallingConv::Fast:
|
||||
case CallingConv::Cold:
|
||||
case CallingConv::X86_FastCall:
|
||||
Assert1(!F.isVarArg(),
|
||||
"Varargs functions must have C calling conventions!", &F);
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue