it != ie; ++it)
it->info = classifyArgumentType(it->type, Context);
}
+
+ virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
+ CodeGenFunction &CGF) const;
};
/// X86_32ABIInfo - The X86-32 ABI information.
it != ie; ++it)
it->info = classifyArgumentType(it->type, Context);
}
+
+ virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
+ CodeGenFunction &CGF) const;
};
}
}
ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty,
- ASTContext &Context) const {
+ ASTContext &Context) const {
// FIXME: Set alignment on indirect arguments.
if (CodeGenFunction::hasAggregateLLVMType(Ty)) {
// Structures with flexible arrays are always indirect.
}
}
+llvm::Value *X86_32ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
+ CodeGenFunction &CGF) const {
+ const llvm::Type *BP = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
+ const llvm::Type *BPP = llvm::PointerType::getUnqual(BP);
+
+ CGBuilderTy &Builder = CGF.Builder;
+ llvm::Value *VAListAddrAsBPP = Builder.CreateBitCast(VAListAddr, BPP,
+ "ap");
+ llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur");
+ llvm::Type *PTy =
+ llvm::PointerType::getUnqual(CGF.ConvertType(Ty));
+ llvm::Value *AddrTyped = Builder.CreateBitCast(Addr, PTy);
+
+ uint64_t SizeInBytes = CGF.getContext().getTypeSize(Ty) / 8;
+ const unsigned ArgumentSizeInBytes = 4;
+ if (SizeInBytes < ArgumentSizeInBytes)
+ SizeInBytes = ArgumentSizeInBytes;
+
+ llvm::Value *NextAddr =
+ Builder.CreateGEP(Addr,
+ llvm::ConstantInt::get(llvm::Type::Int32Ty, SizeInBytes),
+ "ap.next");
+ Builder.CreateStore(NextAddr, VAListAddrAsBPP);
+
+ return AddrTyped;
+}
+
namespace {
/// X86_64ABIInfo - The X86_64 ABI information.
class X86_64ABIInfo : public ABIInfo {
public:
virtual void computeInfo(CGFunctionInfo &FI, ASTContext &Context) const;
+
+ virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
+ CodeGenFunction &CGF) const;
};
}
}
}
+llvm::Value *X86_64ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
+ CodeGenFunction &CGF) const {
+ return 0;
+}
+
ABIArgInfo DefaultABIInfo::classifyReturnType(QualType RetTy,
- ASTContext &Context) const {
+ ASTContext &Context) const {
if (RetTy->isVoidType()) {
return ABIArgInfo::getIgnore();
} else if (CodeGenFunction::hasAggregateLLVMType(RetTy)) {
}
ABIArgInfo DefaultABIInfo::classifyArgumentType(QualType Ty,
- ASTContext &Context) const {
+ ASTContext &Context) const {
if (CodeGenFunction::hasAggregateLLVMType(Ty)) {
return ABIArgInfo::getIndirect(0);
} else {
}
}
+llvm::Value *DefaultABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
+ CodeGenFunction &CGF) const {
+ return 0;
+}
+
const ABIInfo &CodeGenTypes::getABIInfo() const {
if (TheABIInfo)
return *TheABIInfo;
assert(0 && "Unhandled ABIArgInfo::Kind");
return RValue::get(0);
}
+
+/* VarArg handling */
+
+llvm::Value *CodeGenFunction::EmitVAArg(llvm::Value *VAListAddr, QualType Ty) {
+ return CGM.getTypes().getABIInfo().EmitVAArg(VAListAddr, Ty, *this);
+}
}
}
-llvm::Value *CodeGenFunction::EmitVAArg(llvm::Value *VAListAddr, QualType Ty)
-{
- // FIXME: This entire method is hardcoded for 32-bit X86.
-
- const char *TargetPrefix = getContext().Target.getTargetPrefix();
-
- if (strcmp(TargetPrefix, "x86") != 0 ||
- getContext().Target.getPointerWidth(0) != 32)
- return 0;
-
- const llvm::Type *BP = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
- const llvm::Type *BPP = llvm::PointerType::getUnqual(BP);
-
- llvm::Value *VAListAddrAsBPP = Builder.CreateBitCast(VAListAddr, BPP,
- "ap");
- llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur");
- llvm::Value *AddrTyped =
- Builder.CreateBitCast(Addr,
- llvm::PointerType::getUnqual(ConvertType(Ty)));
-
- uint64_t SizeInBytes = getContext().getTypeSize(Ty) / 8;
- const unsigned ArgumentSizeInBytes = 4;
- if (SizeInBytes < ArgumentSizeInBytes)
- SizeInBytes = ArgumentSizeInBytes;
-
- llvm::Value *NextAddr =
- Builder.CreateGEP(Addr,
- llvm::ConstantInt::get(llvm::Type::Int32Ty, SizeInBytes),
- "ap.next");
- Builder.CreateStore(NextAddr, VAListAddrAsBPP);
-
- return AddrTyped;
-}
-
-
llvm::Value *CodeGenFunction::GetVLASize(const VariableArrayType *VAT)
{
llvm::Value *&SizeEntry = VLASizeMap[VAT];