diff --git a/ir/irfunction.cpp b/ir/irfunction.cpp index ab0a834e..c075a530 100644 --- a/ir/irfunction.cpp +++ b/ir/irfunction.cpp @@ -9,103 +9,10 @@ #include "gen/llvm.h" #include "gen/tollvm.h" -#include "gen/abi.h" -#include "gen/dvalue.h" -#include "gen/logger.h" #include "ir/irfunction.h" -#include "ir/irfuncty.h" #include -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// - -IrFuncTyArg::IrFuncTyArg(Type* t, bool bref, llvm::Attributes a) : type(t) -{ - ltype = t != Type::tvoid && bref ? DtoType(t->pointerTo()) : DtoType(t); - attrs = a; - byref = bref; - rewrite = NULL; -} - -#if LDC_LLVM_VER >= 302 -bool IrFuncTyArg::isInReg() const { return attrs.hasAttribute(llvm::Attributes::InReg); } -bool IrFuncTyArg::isSRet() const { return attrs.hasAttribute(llvm::Attributes::StructRet); } -bool IrFuncTyArg::isByVal() const { return attrs.hasAttribute(llvm::Attributes::ByVal); } -#else -bool IrFuncTyArg::isInReg() const { return (attrs & llvm::Attribute::InReg) != 0; } -bool IrFuncTyArg::isSRet() const { return (attrs & llvm::Attribute::StructRet) != 0; } -bool IrFuncTyArg::isByVal() const { return (attrs & llvm::Attribute::ByVal) != 0; } -#endif - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// - -llvm::Value* IrFuncTy::putRet(Type* dty, DValue* val) -{ - assert(!arg_sret); - if (ret->rewrite) { - Logger::println("Rewrite: putRet"); - LOG_SCOPE - return ret->rewrite->put(dty, val); - } - return val->getRVal(); -} - -llvm::Value* IrFuncTy::getRet(Type* dty, DValue* val) -{ - assert(!arg_sret); - if (ret->rewrite) { - Logger::println("Rewrite: getRet"); - LOG_SCOPE - return ret->rewrite->get(dty, val); - } - return val->getRVal(); -} - -llvm::Value* IrFuncTy::putParam(Type* dty, int idx, DValue* val) -{ - assert(idx >= 0 && idx < args.size() && "invalid putParam"); - if (args[idx]->rewrite) { - Logger::println("Rewrite: putParam"); - LOG_SCOPE - return args[idx]->rewrite->put(dty, val); - } - return val->getRVal(); -} - -llvm::Value* IrFuncTy::getParam(Type* dty, int idx, DValue* val) -{ - assert(idx >= 0 && idx < args.size() && "invalid getParam"); - if (args[idx]->rewrite) { - Logger::println("Rewrite: getParam (get)"); - LOG_SCOPE - return args[idx]->rewrite->get(dty, val); - } - return val->getRVal(); -} - -void IrFuncTy::getParam(Type* dty, int idx, DValue* val, llvm::Value* lval) -{ - assert(idx >= 0 && idx < args.size() && "invalid getParam"); - - if (args[idx]->rewrite) - { - Logger::println("Rewrite: getParam (getL)"); - LOG_SCOPE - args[idx]->rewrite->getL(dty, val, lval); - return; - } - - DtoStore(val->getRVal(), lval); -} - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// - FuncGen::FuncGen() { landingPad = NULL; diff --git a/ir/irfuncty.cpp b/ir/irfuncty.cpp new file mode 100644 index 00000000..40b0749b --- /dev/null +++ b/ir/irfuncty.cpp @@ -0,0 +1,95 @@ +//===-- irfuncty.cpp ------------------------------------------------------===// +// +// LDC – the LLVM D compiler +// +// This file is distributed under the BSD-style LDC license. See the LICENSE +// file for details. +// +//===----------------------------------------------------------------------===// + +#include "ir/irfuncty.h" + +#include "mtype.h" + +#include "gen/abi.h" +#include "gen/dvalue.h" +#include "gen/logger.h" +#include "gen/llvm.h" +#include "gen/tollvm.h" + +IrFuncTyArg::IrFuncTyArg(Type* t, bool bref, llvm::Attributes a) : type(t) +{ + ltype = t != Type::tvoid && bref ? DtoType(t->pointerTo()) : DtoType(t); + attrs = a; + byref = bref; + rewrite = NULL; +} + +#if LDC_LLVM_VER >= 302 +bool IrFuncTyArg::isInReg() const { return attrs.hasAttribute(llvm::Attributes::InReg); } +bool IrFuncTyArg::isSRet() const { return attrs.hasAttribute(llvm::Attributes::StructRet); } +bool IrFuncTyArg::isByVal() const { return attrs.hasAttribute(llvm::Attributes::ByVal); } +#else +bool IrFuncTyArg::isInReg() const { return (attrs & llvm::Attribute::InReg) != 0; } +bool IrFuncTyArg::isSRet() const { return (attrs & llvm::Attribute::StructRet) != 0; } +bool IrFuncTyArg::isByVal() const { return (attrs & llvm::Attribute::ByVal) != 0; } +#endif + +llvm::Value* IrFuncTy::putRet(Type* dty, DValue* val) +{ + assert(!arg_sret); + if (ret->rewrite) { + Logger::println("Rewrite: putRet"); + LOG_SCOPE + return ret->rewrite->put(dty, val); + } + return val->getRVal(); +} + +llvm::Value* IrFuncTy::getRet(Type* dty, DValue* val) +{ + assert(!arg_sret); + if (ret->rewrite) { + Logger::println("Rewrite: getRet"); + LOG_SCOPE + return ret->rewrite->get(dty, val); + } + return val->getRVal(); +} + +llvm::Value* IrFuncTy::putParam(Type* dty, int idx, DValue* val) +{ + assert(idx >= 0 && idx < args.size() && "invalid putParam"); + if (args[idx]->rewrite) { + Logger::println("Rewrite: putParam"); + LOG_SCOPE + return args[idx]->rewrite->put(dty, val); + } + return val->getRVal(); +} + +llvm::Value* IrFuncTy::getParam(Type* dty, int idx, DValue* val) +{ + assert(idx >= 0 && idx < args.size() && "invalid getParam"); + if (args[idx]->rewrite) { + Logger::println("Rewrite: getParam (get)"); + LOG_SCOPE + return args[idx]->rewrite->get(dty, val); + } + return val->getRVal(); +} + +void IrFuncTy::getParam(Type* dty, int idx, DValue* val, llvm::Value* lval) +{ + assert(idx >= 0 && idx < args.size() && "invalid getParam"); + + if (args[idx]->rewrite) + { + Logger::println("Rewrite: getParam (getL)"); + LOG_SCOPE + args[idx]->rewrite->getL(dty, val, lval); + return; + } + + DtoStore(val->getRVal(), lval); +} diff --git a/ir/irfuncty.h b/ir/irfuncty.h index 43c78453..2b00d7be 100644 --- a/ir/irfuncty.h +++ b/ir/irfuncty.h @@ -22,6 +22,7 @@ #include +struct DValue; struct ABIRewrite; namespace llvm { class Type;