[cfe-dev] Passing StructType arguments directly
David Meyer
pdox at google.com
Sat Sep 17 15:49:04 PDT 2011
Hello,
I am working with Ivan Krasin on the PNaCl target in Clang. Our ABI
requires that aggregates are passed as first class types in bitcode.
For example:
void foo(struct bar x);
Should compile to:
declare void foo(%struct.bar %x)
To implement this, I added a custom ABIInfo for PNaCl which uses
ABIArgInfo::Direct for aggregate arguments. However, the result of
this is:
define void @foo(i32 %x.coerce0, i32 %x.coerce1)
This reason appears to be code in lib/CodeGen/CGCall.cpp which always
coerces structure types:
// If the coerce-to type is a first class aggregate, we flatten it and
// pass the elements. Either way is semantically identical, but fast-isel
// and the optimizer generally likes scalar values better than FCAs.
if (llvm::StructType *STy =
dyn_cast<llvm::StructType>(ArgI.getCoerceToType())) {
Ptr = Builder.CreateBitCast(Ptr, llvm::PointerType::getUnqual(STy));
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
assert(AI != Fn->arg_end() && "Argument mismatch!");
AI->setName(Arg->getName() + ".coerce" + Twine(i));
llvm::Value *EltPtr = Builder.CreateConstGEP2_32(Ptr, 0, i);
Builder.CreateStore(AI++, EltPtr);
}
}
What's the right way to bypass this step (only for target PNaCl) so
that I can actually pass aggregates directly?
Thanks,
- pdox
More information about the cfe-dev
mailing list