Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: lib/CodeGen/CGBuiltin.cpp

Issue 22294002: Treat __sync_synchronize and asm("":::"memory") as stronger fences. (Closed) Base URL: http://git.chromium.org/native_client/pnacl-clang.git@master
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | lib/CodeGen/CGStmt.cpp » ('j') | test/CodeGen/NaCl/atomics.c » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===---- CGBuiltin.cpp - Emit LLVM Code for builtins ---------------------===// 1 //===---- CGBuiltin.cpp - Emit LLVM Code for builtins ---------------------===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This contains code to emit Builtin calls as LLVM code. 10 // This contains code to emit Builtin calls as LLVM code.
11 // 11 //
12 //===----------------------------------------------------------------------===// 12 //===----------------------------------------------------------------------===//
13 13
14 #include "CodeGenFunction.h" 14 #include "CodeGenFunction.h"
15 #include "CGObjCRuntime.h" 15 #include "CGObjCRuntime.h"
16 #include "CodeGenModule.h" 16 #include "CodeGenModule.h"
17 #include "TargetInfo.h" 17 #include "TargetInfo.h"
18 #include "clang/AST/ASTContext.h" 18 #include "clang/AST/ASTContext.h"
19 #include "clang/AST/Decl.h" 19 #include "clang/AST/Decl.h"
20 #include "clang/Basic/TargetBuiltins.h" 20 #include "clang/Basic/TargetBuiltins.h"
21 #include "clang/Basic/TargetInfo.h" 21 #include "clang/Basic/TargetInfo.h"
22 #include "llvm/IR/DataLayout.h" 22 #include "llvm/IR/DataLayout.h"
23 #include "llvm/IR/InlineAsm.h" // @LOCALMOD
23 #include "llvm/IR/Intrinsics.h" 24 #include "llvm/IR/Intrinsics.h"
24 25
25 using namespace clang; 26 using namespace clang;
26 using namespace CodeGen; 27 using namespace CodeGen;
27 using namespace llvm; 28 using namespace llvm;
28 29
29 /// getBuiltinLibFunction - Given a builtin id for a function like 30 /// getBuiltinLibFunction - Given a builtin id for a function like
30 /// "__builtin_fabsf", return a Function* for "fabsf". 31 /// "__builtin_fabsf", return a Function* for "fabsf".
31 llvm::Value *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD, 32 llvm::Value *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD,
32 unsigned BuiltinID) { 33 unsigned BuiltinID) {
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 } 1028 }
1028 1029
1029 case Builtin::BI__sync_synchronize: { 1030 case Builtin::BI__sync_synchronize: {
1030 // We assume this is supposed to correspond to a C++0x-style 1031 // We assume this is supposed to correspond to a C++0x-style
1031 // sequentially-consistent fence (i.e. this is only usable for 1032 // sequentially-consistent fence (i.e. this is only usable for
1032 // synchonization, not device I/O or anything like that). This intrinsic 1033 // synchonization, not device I/O or anything like that). This intrinsic
1033 // is really badly designed in the sense that in theory, there isn't 1034 // is really badly designed in the sense that in theory, there isn't
1034 // any way to safely use it... but in practice, it mostly works 1035 // any way to safely use it... but in practice, it mostly works
1035 // to use it with non-atomic loads and stores to get acquire/release 1036 // to use it with non-atomic loads and stores to get acquire/release
1036 // semantics. 1037 // semantics.
1038 // @LOCALMOD-START
1039 // For PNaCl, surround __sync_synchronize with compiler fences. This
1040 // should enforce ordering of more than just atomic memory accesses,
1041 // though it won't guarantee that all accesses (e.g. those to
1042 // non-escaping objects) will not be reordered.
1043 llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false);
1044 std::string AsmString; // Empty.
1045 std::string Constraints("~{memory}");
1046 bool HasSideEffect = true;
1047 if (getTarget().getTriple().getArch() == llvm::Triple::le32)
eliben 2013/08/06 16:26:56 It would be cleaner to have a single LOCAMOD if-br
JF 2013/08/07 17:58:28 Done, and as suggested offline the code now uses T
1048 Builder.CreateCall(
1049 llvm::InlineAsm::get(FTy, AsmString, Constraints, HasSideEffect))->
1050 addAttribute(llvm::AttributeSet::FunctionIndex,
1051 llvm::Attribute::NoUnwind);
1037 Builder.CreateFence(llvm::SequentiallyConsistent); 1052 Builder.CreateFence(llvm::SequentiallyConsistent);
1053 if (getTarget().getTriple().getArch() == llvm::Triple::le32)
1054 Builder.CreateCall(
1055 llvm::InlineAsm::get(FTy, AsmString, Constraints, HasSideEffect))->
1056 addAttribute(llvm::AttributeSet::FunctionIndex,
1057 llvm::Attribute::NoUnwind);
1058 // @LOCALMOD-END
1038 return RValue::get(0); 1059 return RValue::get(0);
1039 } 1060 }
1040 1061
1041 case Builtin::BI__c11_atomic_is_lock_free: 1062 case Builtin::BI__c11_atomic_is_lock_free:
1042 case Builtin::BI__atomic_is_lock_free: { 1063 case Builtin::BI__atomic_is_lock_free: {
1043 // Call "bool __atomic_is_lock_free(size_t size, void *ptr)". For the 1064 // Call "bool __atomic_is_lock_free(size_t size, void *ptr)". For the
1044 // __c11 builtin, ptr is 0 (indicating a properly-aligned object), since 1065 // __c11 builtin, ptr is 0 (indicating a properly-aligned object), since
1045 // _Atomic(T) is always properly-aligned. 1066 // _Atomic(T) is always properly-aligned.
1046 const char *LibCallName = "__atomic_is_lock_free"; 1067 const char *LibCallName = "__atomic_is_lock_free";
1047 CallArgList Args; 1068 CallArgList Args;
(...skipping 1802 matching lines...) Expand 10 before | Expand all | Expand 10 after
2850 break; 2871 break;
2851 case PPC::BI__builtin_altivec_stvewx: 2872 case PPC::BI__builtin_altivec_stvewx:
2852 ID = Intrinsic::ppc_altivec_stvewx; 2873 ID = Intrinsic::ppc_altivec_stvewx;
2853 break; 2874 break;
2854 } 2875 }
2855 llvm::Function *F = CGM.getIntrinsic(ID); 2876 llvm::Function *F = CGM.getIntrinsic(ID);
2856 return Builder.CreateCall(F, Ops, ""); 2877 return Builder.CreateCall(F, Ops, "");
2857 } 2878 }
2858 } 2879 }
2859 } 2880 }
OLDNEW
« no previous file with comments | « no previous file | lib/CodeGen/CGStmt.cpp » ('j') | test/CodeGen/NaCl/atomics.c » ('J')

Powered by Google App Engine
This is Rietveld 408576698