Skip to content

Commit 04c6e54

Browse files
committedSep 12, 2011
First pass at ABI description.
1 parent d6a3f34 commit 04c6e54

File tree

1 file changed

+88
-1
lines changed

1 file changed

+88
-1
lines changed
 

‎lib/CodeGen/TargetInfo.cpp

+88-1
Original file line numberDiff line numberDiff line change
@@ -2982,21 +2982,108 @@ void MSP430TargetCodeGenInfo::SetTargetAttributes(const Decl *D,
29822982

29832983
namespace {
29842984

2985+
class Mico32ABIInfo : public ABIInfo {
2986+
public:
2987+
Mico32ABIInfo(CodeGenTypes &CGT) : ABIInfo(CGT) {}
2988+
2989+
bool isPromotableIntegerType(QualType Ty) const;
2990+
2991+
ABIArgInfo classifyReturnType(QualType RetTy) const;
2992+
ABIArgInfo classifyArgumentType(QualType RetTy) const;
2993+
virtual void computeInfo(CGFunctionInfo &FI) const;
2994+
virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
2995+
CodeGenFunction &CGF) const;
2996+
};
2997+
29852998
class Mico32TargetCodeGenInfo : public TargetCodeGenInfo {
29862999
public:
29873000
Mico32TargetCodeGenInfo(CodeGenTypes &CGT)
2988-
: TargetCodeGenInfo(new DefaultABIInfo(CGT)) {}
3001+
: TargetCodeGenInfo(new Mico32ABIInfo(CGT)) {}
29893002
void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
29903003
CodeGen::CodeGenModule &M) const;
29913004
};
29923005

29933006
}
29943007

3008+
// Copied from MBlaze
3009+
bool Mico32ABIInfo::isPromotableIntegerType(QualType Ty) const {
3010+
// Extend all 8 and 16 bit quantities.
3011+
if (const BuiltinType *BT = Ty->getAs<BuiltinType>())
3012+
switch (BT->getKind()) {
3013+
case BuiltinType::Bool:
3014+
case BuiltinType::Char_S:
3015+
case BuiltinType::Char_U:
3016+
case BuiltinType::SChar:
3017+
case BuiltinType::UChar:
3018+
case BuiltinType::Short:
3019+
case BuiltinType::UShort:
3020+
return true;
3021+
default:
3022+
return false;
3023+
}
3024+
return false;
3025+
}
3026+
3027+
void Mico32ABIInfo::computeInfo(CGFunctionInfo &FI) const {
3028+
FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
3029+
for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
3030+
it != ie; ++it)
3031+
it->info = classifyArgumentType(it->type);
3032+
}
3033+
3034+
// Copied from MIPS
3035+
ABIArgInfo Mico32ABIInfo::classifyArgumentType(QualType Ty) const {
3036+
if (isAggregateTypeForABI(Ty)) {
3037+
// Ignore empty aggregates.
3038+
if (getContext().getTypeSize(Ty) == 0)
3039+
return ABIArgInfo::getIgnore();
3040+
3041+
// Records with non trivial destructors/constructors should not be passed
3042+
// by value.
3043+
if (isRecordWithNonTrivialDestructorOrCopyConstructor(Ty))
3044+
return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
3045+
3046+
return ABIArgInfo::getIndirect(0);
3047+
}
3048+
3049+
// Treat an enum type as its underlying type.
3050+
if (const EnumType *EnumTy = Ty->getAs<EnumType>())
3051+
Ty = EnumTy->getDecl()->getIntegerType();
3052+
3053+
return (isPromotableIntegerType(Ty) ?
3054+
ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
3055+
}
3056+
3057+
// Copied from MIPS
3058+
ABIArgInfo Mico32ABIInfo::classifyReturnType(QualType RetTy) const {
3059+
if (RetTy->isVoidType())
3060+
return ABIArgInfo::getIgnore();
3061+
3062+
if (isAggregateTypeForABI(RetTy)) {
3063+
// FIXME: Do we want to do a direct return of aggregates of < 8 bytes.
3064+
return ABIArgInfo::getIndirect(0);
3065+
}
3066+
3067+
// Treat an enum type as its underlying type.
3068+
if (const EnumType *EnumTy = RetTy->getAs<EnumType>())
3069+
RetTy = EnumTy->getDecl()->getIntegerType();
3070+
3071+
return (RetTy->isPromotableIntegerType() ?
3072+
ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
3073+
}
3074+
3075+
29953076
void Mico32TargetCodeGenInfo::SetTargetAttributes(const Decl *D,
29963077
llvm::GlobalValue *GV,
29973078
CodeGen::CodeGenModule &M) const {
29983079
}
29993080

3081+
llvm::Value *Mico32ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
3082+
CodeGenFunction &CFG) const {
3083+
llvm_unreachable("Mico32 does not support varargs");
3084+
return 0;
3085+
}
3086+
30003087

30013088
//===----------------------------------------------------------------------===//
30023089
// MIPS ABI Implementation. This works for both little-endian and

0 commit comments

Comments
 (0)
Please sign in to comment.