forked from OSchip/llvm-project
AArch64: teach Clang about __clear_cache intrinsic
libgcc provides a __clear_cache intrinsic on AArch64, much like it does on 32-bit ARM. llvm-svn: 181111
This commit is contained in:
parent
fa7a7b4f36
commit
8ec8c4bf89
|
@ -0,0 +1,18 @@
|
|||
//===-- BuiltinsAArch64.def - AArch64 Builtin function database -*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines the AArch64-specific builtin function database. Users of
|
||||
// this file must define the BUILTIN macro to make use of this information.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// The format of this database matches clang/Basic/Builtins.def.
|
||||
|
||||
// In libgcc
|
||||
BUILTIN(__clear_cache, "vv*v*", "")
|
|
@ -21,6 +21,15 @@
|
|||
|
||||
namespace clang {
|
||||
|
||||
/// \brief AArch64 builtins
|
||||
namespace AArch64 {
|
||||
enum {
|
||||
LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1,
|
||||
#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
|
||||
#include "clang/Basic/BuiltinsAArch64.def"
|
||||
LastTSBuiltin
|
||||
};
|
||||
}
|
||||
/// \brief ARM builtins
|
||||
namespace ARM {
|
||||
enum {
|
||||
|
|
|
@ -3307,6 +3307,8 @@ namespace {
|
|||
class AArch64TargetInfo : public TargetInfo {
|
||||
static const char * const GCCRegNames[];
|
||||
static const TargetInfo::GCCRegAlias GCCRegAliases[];
|
||||
|
||||
static const Builtin::Info BuiltinInfo[];
|
||||
public:
|
||||
AArch64TargetInfo(const std::string& triple) : TargetInfo(triple) {
|
||||
BigEndian = false;
|
||||
|
@ -3375,8 +3377,8 @@ public:
|
|||
}
|
||||
virtual void getTargetBuiltins(const Builtin::Info *&Records,
|
||||
unsigned &NumRecords) const {
|
||||
Records = 0;
|
||||
NumRecords = 0;
|
||||
Records = BuiltinInfo;
|
||||
NumRecords = clang::AArch64::LastTSBuiltin-Builtin::FirstTSBuiltin;
|
||||
}
|
||||
virtual bool hasFeature(StringRef Feature) const {
|
||||
return Feature == "aarch64";
|
||||
|
@ -3485,6 +3487,14 @@ void AArch64TargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
|
|||
NumAliases = llvm::array_lengthof(GCCRegAliases);
|
||||
|
||||
}
|
||||
|
||||
const Builtin::Info AArch64TargetInfo::BuiltinInfo[] = {
|
||||
#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
|
||||
#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
|
||||
ALL_LANGUAGES },
|
||||
#include "clang/Basic/BuiltinsAArch64.def"
|
||||
};
|
||||
|
||||
} // end anonymous namespace
|
||||
|
||||
namespace {
|
||||
|
|
|
@ -1502,6 +1502,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
|
|||
Value *CodeGenFunction::EmitTargetBuiltinExpr(unsigned BuiltinID,
|
||||
const CallExpr *E) {
|
||||
switch (getTarget().getTriple().getArch()) {
|
||||
case llvm::Triple::aarch64:
|
||||
return EmitAArch64BuiltinExpr(BuiltinID, E);
|
||||
case llvm::Triple::arm:
|
||||
case llvm::Triple::thumb:
|
||||
return EmitARMBuiltinExpr(BuiltinID, E);
|
||||
|
@ -1621,6 +1623,25 @@ CodeGenFunction::EmitPointerWithAlignment(const Expr *Addr) {
|
|||
return std::make_pair(EmitScalarExpr(Addr), Align);
|
||||
}
|
||||
|
||||
Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
|
||||
const CallExpr *E) {
|
||||
if (BuiltinID == AArch64::BI__clear_cache) {
|
||||
assert(E->getNumArgs() == 2 &&
|
||||
"Variadic __clear_cache slipped through on AArch64");
|
||||
|
||||
const FunctionDecl *FD = E->getDirectCallee();
|
||||
SmallVector<Value *, 2> Ops;
|
||||
for (unsigned i = 0; i < E->getNumArgs(); i++)
|
||||
Ops.push_back(EmitScalarExpr(E->getArg(i)));
|
||||
llvm::Type *Ty = CGM.getTypes().ConvertType(FD->getType());
|
||||
llvm::FunctionType *FTy = cast<llvm::FunctionType>(Ty);
|
||||
StringRef Name = FD->getName();
|
||||
return EmitNounwindRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Ops);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
|
||||
const CallExpr *E) {
|
||||
if (BuiltinID == ARM::BI__clear_cache) {
|
||||
|
|
|
@ -2503,6 +2503,7 @@ public:
|
|||
/// is unhandled by the current target.
|
||||
llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
|
||||
|
||||
llvm::Value *EmitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
|
||||
llvm::Value *EmitARMBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
|
||||
llvm::Value *EmitNeonCall(llvm::Function *F,
|
||||
SmallVectorImpl<llvm::Value*> &O,
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -O3 -emit-llvm -o - %s | FileCheck %s
|
||||
|
||||
void f0(char *a, char *b) {
|
||||
__clear_cache(a,b);
|
||||
// CHECK: call {{.*}} @__clear_cache
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -fsyntax-only -verify %s
|
||||
|
||||
void test_clear_cache_chars(char *start, char *end) {
|
||||
__clear_cache(start, end);
|
||||
}
|
||||
|
||||
void test_clear_cache_voids(void *start, void *end) {
|
||||
__clear_cache(start, end);
|
||||
}
|
||||
|
||||
void test_clear_cache_no_args() {
|
||||
// AArch32 version of this is variadic (at least syntactically).
|
||||
// However, on AArch64 GCC does not permit this call and the
|
||||
// implementation I've seen would go disastrously wrong.
|
||||
__clear_cache(); // expected-error {{too few arguments to function call}}
|
||||
}
|
Loading…
Reference in New Issue