blob: 8fbd20714d6a398a8af09e5b4bc100b7e1fe0236 [file] [log] [blame]
Chris Lattner67c6b6e2009-09-20 06:45:52 +00001//===-- llvm/CodeGen/X86COFFMachineModuleInfo.cpp -------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This is an MMI implementation for X86 COFF (windows) targets.
11//
12//===----------------------------------------------------------------------===//
13
14#include "X86COFFMachineModuleInfo.h"
15#include "X86MachineFunctionInfo.h"
16#include "llvm/DerivedTypes.h"
17#include "llvm/Function.h"
Chris Lattner4fb69f42010-01-16 00:51:39 +000018#include "llvm/MC/MCContext.h"
19#include "llvm/MC/MCSymbol.h"
Chris Lattner67c6b6e2009-09-20 06:45:52 +000020#include "llvm/Target/TargetData.h"
21#include "llvm/ADT/SmallString.h"
22#include "llvm/Support/raw_ostream.h"
23using namespace llvm;
24
Chris Lattnerc9747c02010-03-12 19:42:40 +000025
Chris Lattner67c6b6e2009-09-20 06:45:52 +000026X86COFFMachineModuleInfo::~X86COFFMachineModuleInfo() {
Chris Lattner67c6b6e2009-09-20 06:45:52 +000027}
28
Chris Lattnerc9747c02010-03-12 19:42:40 +000029/// DecorateCygMingName - Query FunctionInfoMap and use this information for
30/// various name decorations for Cygwin and MingW.
31void X86COFFMachineModuleInfo::DecorateCygMingName(MCSymbol *&NameSym,
32 MCContext &Ctx,
33 const Function *F,
Chris Lattner67c6b6e2009-09-20 06:45:52 +000034 const TargetData &TD) {
Chris Lattnerc9747c02010-03-12 19:42:40 +000035 SmallString<128> Name(NameSym->getName().begin(), NameSym->getName().end());
36
Chris Lattner67c6b6e2009-09-20 06:45:52 +000037 // We don't want to decorate non-stdcall or non-fastcall functions right now
38 CallingConv::ID CC = F->getCallingConv();
39 if (CC != CallingConv::X86_StdCall && CC != CallingConv::X86_FastCall)
40 return;
Chris Lattnerc9747c02010-03-12 19:42:40 +000041
Anton Korobeynikov4dd162f2010-02-12 15:28:40 +000042 unsigned ArgWords = 0;
Chris Lattner355670b2010-03-12 19:31:03 +000043
44 // Calculate arguments sizes
45 for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end();
46 AI != AE; ++AI) {
47 const Type *Ty = AI->getType();
Chris Lattnerc9747c02010-03-12 19:42:40 +000048
Chris Lattner355670b2010-03-12 19:31:03 +000049 // 'Dereference' type in case of byval parameter attribute
50 if (AI->hasByValAttr())
51 Ty = cast<PointerType>(Ty)->getElementType();
Chris Lattnerc9747c02010-03-12 19:42:40 +000052
Chris Lattner355670b2010-03-12 19:31:03 +000053 // Size should be aligned to DWORD boundary
54 ArgWords += ((TD.getTypeAllocSize(Ty) + 3)/4)*4;
55 }
Chris Lattnerc9747c02010-03-12 19:42:40 +000056
Chris Lattner67c6b6e2009-09-20 06:45:52 +000057 const FunctionType *FT = F->getFunctionType();
Chris Lattner67c6b6e2009-09-20 06:45:52 +000058 // "Pure" variadic functions do not receive @0 suffix.
59 if (!FT->isVarArg() || FT->getNumParams() == 0 ||
60 (FT->getNumParams() == 1 && F->hasStructRetAttr()))
Anton Korobeynikov4dd162f2010-02-12 15:28:40 +000061 raw_svector_ostream(Name) << '@' << ArgWords;
Chris Lattnerc9747c02010-03-12 19:42:40 +000062
Anton Korobeynikov4dd162f2010-02-12 15:28:40 +000063 if (CC == CallingConv::X86_FastCall) {
Chris Lattner67c6b6e2009-09-20 06:45:52 +000064 if (Name[0] == '_')
65 Name[0] = '@';
66 else
67 Name.insert(Name.begin(), '@');
Anton Korobeynikov4dd162f2010-02-12 15:28:40 +000068 }
Chris Lattnerc9747c02010-03-12 19:42:40 +000069
70 NameSym = Ctx.GetOrCreateSymbol(Name.str());
Chris Lattner67c6b6e2009-09-20 06:45:52 +000071}