Skip to content

Commit

Permalink
Add AIX Target Info
Browse files Browse the repository at this point in the history
Summary:
A first pass over platform-specific properties of the C API/ABI
on AIX for both 32-bit and 64-bit modes.
This is a continuation of D18360 by Andrew Paprocki and further work by Wu Zhao.

Patch by Andus Yu

Reviewers: apaprocki, chandlerc, hubert.reinterpretcast, jasonliu,
xingxue, sfertile

Reviewed by: hubert.reinterpretcast, apaprocki, sfertile

Differential Revision: https://reviews.llvm.org/D59048

llvm-svn: 356060
  • Loading branch information
jasonliudev committed Mar 13, 2019
1 parent 3f4870b commit 4e192d0
Show file tree
Hide file tree
Showing 8 changed files with 520 additions and 1 deletion.
4 changes: 4 additions & 0 deletions clang/lib/Basic/Targets.cpp
Expand Up @@ -332,6 +332,8 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple,
return new OpenBSDTargetInfo<PPC32TargetInfo>(Triple, Opts);
case llvm::Triple::RTEMS:
return new RTEMSTargetInfo<PPC32TargetInfo>(Triple, Opts);
case llvm::Triple::AIX:
return new AIXPPC32TargetInfo(Triple, Opts);
default:
return new PPC32TargetInfo(Triple, Opts);
}
Expand All @@ -348,6 +350,8 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple,
return new FreeBSDTargetInfo<PPC64TargetInfo>(Triple, Opts);
case llvm::Triple::NetBSD:
return new NetBSDTargetInfo<PPC64TargetInfo>(Triple, Opts);
case llvm::Triple::AIX:
return new AIXPPC64TargetInfo(Triple, Opts);
default:
return new PPC64TargetInfo(Triple, Opts);
}
Expand Down
47 changes: 47 additions & 0 deletions clang/lib/Basic/Targets/OSTargets.h
Expand Up @@ -613,6 +613,53 @@ class LLVM_LIBRARY_VISIBILITY SolarisTargetInfo : public OSTargetInfo<Target> {
}
};

// AIX Target
template <typename Target>
class AIXTargetInfo : public OSTargetInfo<Target> {
protected:
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
MacroBuilder &Builder) const override {
DefineStd(Builder, "unix", Opts);
Builder.defineMacro("_IBMR2");
Builder.defineMacro("_POWER");

// FIXME: Define AIX OS-Version Macros.
Builder.defineMacro("_AIX");

// FIXME: Do not define _LONG_LONG when -fno-long-long is specified.
Builder.defineMacro("_LONG_LONG");

if (Opts.POSIXThreads) {
Builder.defineMacro("_THREAD_SAFE");
}

if (this->PointerWidth == 64) {
Builder.defineMacro("__64BIT__");
}

// Define _WCHAR_T when it is a fundamental type
// (i.e., for C++ without -fno-wchar).
if (Opts.CPlusPlus && Opts.WChar) {
Builder.defineMacro("_WCHAR_T");
}
}

public:
AIXTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
: OSTargetInfo<Target>(Triple, Opts) {
if (this->PointerWidth == 64) {
this->WCharType = this->UnsignedInt;
} else {
this->WCharType = this->UnsignedShort;
}
this->UseZeroLengthBitfieldAlignment = true;
}

// AIX sets FLT_EVAL_METHOD to be 1.
unsigned getFloatEvalMethod() const override { return 1; }
bool hasInt128Type() const override { return false; }
};

// Windows target
template <typename Target>
class LLVM_LIBRARY_VISIBILITY WindowsTargetInfo : public OSTargetInfo<Target> {
Expand Down
4 changes: 3 additions & 1 deletion clang/lib/Basic/Targets/PPC.cpp
Expand Up @@ -100,7 +100,9 @@ void PPCTargetInfo::getTargetDefines(const LangOptions &Opts,
Builder.defineMacro("_CALL_LINUX", "1");

// Subtarget options.
Builder.defineMacro("__NATURAL_ALIGNMENT__");
if (!getTriple().isOSAIX()){
Builder.defineMacro("__NATURAL_ALIGNMENT__");
}
Builder.defineMacro("__REGISTER_PREFIX__", "");

// FIXME: Should be controlled by command line option.
Expand Down
29 changes: 29 additions & 0 deletions clang/lib/Basic/Targets/PPC.h
Expand Up @@ -325,6 +325,12 @@ class LLVM_LIBRARY_VISIBILITY PPC32TargetInfo : public PPCTargetInfo {
PtrDiffType = SignedInt;
IntPtrType = SignedInt;
break;
case llvm::Triple::AIX:
SizeType = UnsignedLong;
PtrDiffType = SignedLong;
IntPtrType = SignedLong;
SuitableAlign = 64;
break;
default:
break;
}
Expand All @@ -333,6 +339,8 @@ class LLVM_LIBRARY_VISIBILITY PPC32TargetInfo : public PPCTargetInfo {
case llvm::Triple::FreeBSD:
case llvm::Triple::NetBSD:
case llvm::Triple::OpenBSD:
// FIXME: -mlong-double-128 is not yet supported on AIX.
case llvm::Triple::AIX:
LongDoubleWidth = LongDoubleAlign = 64;
LongDoubleFormat = &llvm::APFloat::IEEEdouble();
break;
Expand Down Expand Up @@ -373,6 +381,12 @@ class LLVM_LIBRARY_VISIBILITY PPC64TargetInfo : public PPCTargetInfo {
LongDoubleWidth = LongDoubleAlign = 64;
LongDoubleFormat = &llvm::APFloat::IEEEdouble();
break;
case llvm::Triple::AIX:
// FIXME: -mlong-double-128 is not yet supported on AIX.
LongDoubleWidth = LongDoubleAlign = 64;
LongDoubleFormat = &llvm::APFloat::IEEEdouble();
SuitableAlign = 64;
break;
default:
break;
}
Expand Down Expand Up @@ -431,6 +445,21 @@ class LLVM_LIBRARY_VISIBILITY DarwinPPC64TargetInfo
}
};

class LLVM_LIBRARY_VISIBILITY AIXPPC32TargetInfo :
public AIXTargetInfo<PPC32TargetInfo> {
public:
using AIXTargetInfo::AIXTargetInfo;
BuiltinVaListKind getBuiltinVaListKind() const override {
return TargetInfo::CharPtrBuiltinVaList;
}
};

class LLVM_LIBRARY_VISIBILITY AIXPPC64TargetInfo :
public AIXTargetInfo<PPC64TargetInfo> {
public:
using AIXTargetInfo::AIXTargetInfo;
};

} // namespace targets
} // namespace clang
#endif // LLVM_CLANG_LIB_BASIC_TARGETS_PPC_H
6 changes: 6 additions & 0 deletions clang/test/Driver/types.c
Expand Up @@ -9,6 +9,12 @@
// RUN: not %clang -c --target=riscv32-unknown-linux-gnu -fsyntax-only %s \
// RUN: -fforce-enable-int128 -fno-force-enable-int128

// RUN: not %clang -c --target=powerpc-ibm-aix -fsyntax-only %s \
// RUN: 2>&1 | FileCheck %s

// RUN: not %clang -c --target=powerpc64-ibm-aix -fsyntax-only %s \
// RUN: 2>&1 | FileCheck %s

void a() {
__int128_t s;
__uint128_t t;
Expand Down
10 changes: 10 additions & 0 deletions clang/test/Headers/max_align.c
@@ -0,0 +1,10 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics

#ifndef __BIGGEST_ALIGNMENT__
#error __BIGGEST_ALIGNMENT__ not defined
#endif

#include <stddef.h>

_Static_assert(__BIGGEST_ALIGNMENT__ == _Alignof(max_align_t), "");

0 comments on commit 4e192d0

Please sign in to comment.