From: Renato Golin Date: Wed, 26 Mar 2014 15:36:05 +0000 (+0000) Subject: Add support for __builtin___clear_cache in Clang X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=51da10e76e2a903f0f6813678fe99892ee60550d;p=clang Add support for __builtin___clear_cache in Clang Adding the mapping between __builtin___clear_cache into @llvm.clear_cache git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204820 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/Builtins.def b/include/clang/Basic/Builtins.def index a44a7a2d21..53bec2ab83 100644 --- a/include/clang/Basic/Builtins.def +++ b/include/clang/Basic/Builtins.def @@ -445,6 +445,7 @@ BUILTIN(__builtin_strstr, "c*cC*cC*", "nF") BUILTIN(__builtin_return_address, "v*IUi", "n") BUILTIN(__builtin_extract_return_addr, "v*v*", "n") BUILTIN(__builtin_frame_address, "v*IUi", "n") +BUILTIN(__builtin___clear_cache, "vc*c*", "n") BUILTIN(__builtin_flt_rounds, "i", "nc") BUILTIN(__builtin_setjmp, "iv**", "j") BUILTIN(__builtin_longjmp, "vv**i", "r") diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp index fc93b7719f..c105d80bf7 100644 --- a/lib/CodeGen/CGBuiltin.cpp +++ b/lib/CodeGen/CGBuiltin.cpp @@ -429,6 +429,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, Value *F = CGM.getIntrinsic(Intrinsic::readcyclecounter); return RValue::get(Builder.CreateCall(F)); } + case Builtin::BI__builtin___clear_cache: { + Value *Begin = EmitScalarExpr(E->getArg(0)); + Value *End = EmitScalarExpr(E->getArg(1)); + Value *F = CGM.getIntrinsic(Intrinsic::clear_cache); + return RValue::get(Builder.CreateCall2(F, Begin, End)); + } case Builtin::BI__builtin_trap: { Value *F = CGM.getIntrinsic(Intrinsic::trap); return RValue::get(Builder.CreateCall(F)); diff --git a/test/CodeGen/clear_cache.c b/test/CodeGen/clear_cache.c new file mode 100644 index 0000000000..f859d7fdc9 --- /dev/null +++ b/test/CodeGen/clear_cache.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s + +char buffer[32] = "This is a largely unused buffer"; + +// __builtin___clear_cache always maps to @llvm.clear_cache, but what +// each back-end produces is different, and this is tested in LLVM + +int main() { + __builtin___clear_cache(buffer, buffer+32); +// CHECK: @llvm.clear_cache(i8* getelementptr {{.*}}, i8* getelementptr {{.*}} (i8* getelementptr {{.*}} 32)) + return 0; +}