Skip to content

Commit

Permalink
[ARM,CDE] Implement CDE feature test macros
Browse files Browse the repository at this point in the history
Summary:
This patch implements feature test macros for the CDE extension
according to the upcoming ACLE specification.

The following 2 macros are being added:
- __ARM_FEATURE_CDE - defined as '1' when any coprocessor is
  configured as a CDE coprocessor
- __ARM_FEATURE_CDE_COPROC - defined as an 8-bit mask, each bit of the
  mask corresponds to a coprocessor and is set when the corresponding
  coprocessor is configured as CDE (and cleared otherwise).

The patch also exposes the value of __ARM_FEATURE_CDE_COPROC in the
target-independent method TargetInfo::getARMCDECorpocMask, the method
will be used in follow-up patches implementing semantic checks of CDE
intrinsics (we want to diagnose the cases when CDE intrinsics are used
with coprocessors that are not configured as CDE).

Reviewers: simon_tatham, dmgreen, ostannard, MarkMurrayARM

Reviewed By: simon_tatham

Subscribers: kristof.beyls, danielkiss, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75843
  • Loading branch information
miyuki committed Mar 9, 2020
1 parent c3d981a commit cdeeb54
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions clang/include/clang/Basic/TargetInfo.h
Expand Up @@ -210,6 +210,8 @@ class TargetInfo : public virtual TransferrableTargetInfo,

unsigned HasAArch64SVETypes : 1;

unsigned ARMCDECoprocMask : 8;

// TargetInfo Constructor. Default initializes all fields.
TargetInfo(const llvm::Triple &T);

Expand Down Expand Up @@ -808,6 +810,10 @@ class TargetInfo : public virtual TransferrableTargetInfo,
/// available on this target.
bool hasAArch64SVETypes() const { return HasAArch64SVETypes; }

/// For ARM targets returns a mask defining which coprocessors are configured
/// as Custom Datapath.
uint32_t getARMCDECoprocMask() const { return ARMCDECoprocMask; }

/// Returns whether the passed in string is a valid clobber in an
/// inline asm statement.
///
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Basic/TargetInfo.cpp
Expand Up @@ -113,6 +113,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : TargetOpts(), Triple(T) {
HasBuiltinMSVaList = false;
IsRenderScriptTarget = false;
HasAArch64SVETypes = false;
ARMCDECoprocMask = 0;

// Default to no types using fpret.
RealTypeUsesObjCFPRet = 0;
Expand Down
13 changes: 13 additions & 0 deletions clang/lib/Basic/Targets/ARM.cpp
Expand Up @@ -154,6 +154,8 @@ bool ARMTargetInfo::hasMVEFloat() const {
return hasMVE() && (MVE & MVE_FP);
}

bool ARMTargetInfo::hasCDE() const { return getARMCDECoprocMask() != 0; }

bool ARMTargetInfo::isThumb() const {
return ArchISA == llvm::ARM::ISAKind::THUMB;
}
Expand Down Expand Up @@ -422,6 +424,7 @@ bool ARMTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
HWDiv = 0;
DotProd = 0;
HasFloat16 = true;
ARMCDECoprocMask = 0;

// This does not diagnose illegal cases like having both
// "+vfpv2" and "+vfpv3" or having "+neon" and "-fp64".
Expand Down Expand Up @@ -486,6 +489,10 @@ bool ARMTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
FPU |= FPARMV8;
MVE |= MVE_INT | MVE_FP;
HW_FP |= HW_FP_SP | HW_FP_HP;
} else if (Feature.size() == strlen("+cdecp0") && Feature >= "+cdecp0" &&
Feature <= "+cdecp7") {
unsigned Coproc = Feature.back() - '0';
ARMCDECoprocMask |= (1U << Coproc);
}
}

Expand Down Expand Up @@ -758,6 +765,12 @@ void ARMTargetInfo::getTargetDefines(const LangOptions &Opts,
Builder.defineMacro("__ARM_FEATURE_MVE", hasMVEFloat() ? "3" : "1");
}

if (hasCDE()) {
Builder.defineMacro("__ARM_FEATURE_CDE", "1");
Builder.defineMacro("__ARM_FEATURE_CDE_COPROC",
"0x" + Twine::utohexstr(getARMCDECoprocMask()));
}

Builder.defineMacro("__ARM_SIZEOF_WCHAR_T",
Twine(Opts.WCharSize ? Opts.WCharSize : 4));

Expand Down
1 change: 1 addition & 0 deletions clang/lib/Basic/Targets/ARM.h
Expand Up @@ -108,6 +108,7 @@ class LLVM_LIBRARY_VISIBILITY ARMTargetInfo : public TargetInfo {
bool supportsThumb2() const;
bool hasMVE() const;
bool hasMVEFloat() const;
bool hasCDE() const;

StringRef getCPUAttr() const;
StringRef getCPUProfile() const;
Expand Down
12 changes: 12 additions & 0 deletions clang/test/Preprocessor/arm-target-features.c
Expand Up @@ -800,6 +800,18 @@
// CHECK-V81M-MVE-NODSP-NOT: #define __ARM_FEATURE_MVE
// CHECK-V81M-MVE-NODSP-NOT: #define __ARM_FEATURE_DSP

// Test CDE (Custom Datapath Extension) feature test macros

// RUN: %clang -target arm-arm-none-eabi -march=armv8m.main -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-V8M-NOCDE %s
// CHECK-V8M-NOCDE-NOT: #define __ARM_FEATURE_CDE
// CHECK-V8M-NOCDE-NOT: #define __ARM_FEATURE_CDE_COPROC
// RUN: %clang -target arm-arm-none-eabi -march=armv8m.main+cdecp0+cdecp1+cdecp7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8M-CDE-MASK1 %s
// CHECK-V8M-CDE-MASK1: #define __ARM_FEATURE_CDE 1
// CHECK-V8M-CDE-MASK1: #define __ARM_FEATURE_CDE_COPROC 0x83
// RUN: %clang -target arm-arm-none-eabi -march=armv8m.main+cdecp0+cdecp1+cdecp2+cdecp3+cdecp4+cdecp5+cdecp6+cdecp7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8M-CDE-MASK2 %s
// CHECK-V8M-CDE-MASK2: #define __ARM_FEATURE_CDE 1
// CHECK-V8M-CDE-MASK2: #define __ARM_FEATURE_CDE_COPROC 0xff

// RUN: %clang -target armv8.1a-none-none-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81A %s
// CHECK-V81A: #define __ARM_ARCH 8
// CHECK-V81A: #define __ARM_ARCH_8_1A__ 1
Expand Down

0 comments on commit cdeeb54

Please sign in to comment.