LLVM IR对于多值返回(multiple return value)的支持
------------------自问自答-----------------LLVM 3.9没有显示支持多值返回机制,但是LLVM 提供了Aggregate Type,可以使用这个类型去实现多值返回。在chris lattner的开发日记中,也有关于使用FCA(first-class aggregates)来取代多值返回的想法(在以前的版本中,first-class value只包含Integer、Floating point、Pointer等),其中Chris latter历数了FCA的多种好处,例如对small structure的直接支持,但是 http://clang-developers.42468.n3.nabble.com/Passing-StructType-arguments-directly-td3345267.html (见Dan Gohman的回答)上也有有不同的看法,自己对LLVM了解的还不够深入,如果有对这方面熟悉的还请多多指教。说实话,纠结LLVM是否支持多值返回意义不大,register或memory都可以作为中间媒介,只要caller和callee遵循calling convention即可(就像zephyr z所说,取决于目标体系的ABI)。Clang的IRBuilder.h文件中有相关描述:/// \\brief Create a sequence of N insertvalue instructions, with one Value from the/// retVals array each, that build a aggregate return value one value at a time, /// and a ret instruction to return the resulting aggregate value.////// This is a convenience function for code that uses aggregate return values as a /// vehicle for having multiple return values.ReturnInst *CreateAggregateRet(Value *const *retVals, unsigned N){ Value *V = UdefValue::get(getCurrentFunctionReturnType()); for (unsigned i = 0; i != N; ++i) V = CreateInsertValue(V, retVals, i, "mrv"); return Insert(ReturnInst::Create(Context, V));}从最后一句注释中我们可以看到,该函数就是用来实现多值返回(MRV)的method,也就是虽然LLVM没有显示支持MRV,但还是有相应的Aggregate Type供我们使用。
■网友
IR基本是独立于目标体系的和ABI的而怎么返回多个值主要由ABI决定所以具体的汇编会在Targer Lowering 决定
推荐阅读
- 5.1声道片源对于没有5.1硬件系统的用户来说有意义吗
- |常州天宁:检察建议让“忙道”回归盲道
- 英雄联盟快捷键Q、E、R咋操作呢
- 2017年iPhone性价比最高的是哪款产品
- 友盟对于日活是怎么样统计的
- 贵州对于大数据有哪些方面的地域优势为啥都是贵州呢
- 对于一个程序员、靠拿工资攒钱买房、是不是太遥远
- 趣头条|2011年左右的二手丰田花冠,3万多值得买吗?
- 客服对于一个电商平台起到多大的作用
- 综艺|
