[PATCH] [CUDA] Implemented __nvvm_atom_*_gen_* builtins.

Artem Belevich tra at google.com
Wed Jun 24 11:13:01 PDT 2015


================
Comment at: lib/CodeGen/CGBuiltin.cpp:112
@@ +111,3 @@
+  Result = EmitFromInt(CGF, Result, T, ValueType);
+  return Result;
+}
----------------
eliben wrote:
> Don't really need the Result temporary here?
Done.

================
Comment at: lib/CodeGen/CGBuiltin.cpp:118
@@ -87,26 +117,3 @@
                                const CallExpr *E) {
-  QualType T = E->getType();
-  assert(E->getArg(0)->getType()->isPointerType());
-  assert(CGF.getContext().hasSameUnqualifiedType(T,
-                                  E->getArg(0)->getType()->getPointeeType()));
-  assert(CGF.getContext().hasSameUnqualifiedType(T, E->getArg(1)->getType()));
-
-  llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0));
-  unsigned AddrSpace = DestPtr->getType()->getPointerAddressSpace();
-
-  llvm::IntegerType *IntType =
-    llvm::IntegerType::get(CGF.getLLVMContext(),
-                           CGF.getContext().getTypeSize(T));
-  llvm::Type *IntPtrType = IntType->getPointerTo(AddrSpace);
-
-  llvm::Value *Args[2];
-  Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType);
-  Args[1] = CGF.EmitScalarExpr(E->getArg(1));
-  llvm::Type *ValueType = Args[1]->getType();
-  Args[1] = EmitToInt(CGF, Args[1], T, IntType);
-
-  llvm::Value *Result =
-      CGF.Builder.CreateAtomicRMW(Kind, Args[0], Args[1],
-                                  llvm::SequentiallyConsistent);
-  Result = EmitFromInt(CGF, Result, T, ValueType);
+  llvm::Value *Result = MakeBinaryAtomicValue(CGF, Kind, E);
   return RValue::get(Result);
----------------
eliben wrote:
> You can just "return RValue::get(MakeBinary...)" -- similarly to how it's done below, for consistency
Done.

================
Comment at: lib/CodeGen/CGBuiltin.cpp:165
@@ +164,3 @@
+static Value *MakeAtomicCmpXchgValue(CodeGenFunction &CGF, const CallExpr *E,
+                                     bool ReturnBool) {
+  QualType T = ReturnBool ? E->getArg(1)->getType() : E->getType();
----------------
eliben wrote:
> Please document all function parameters in the comment (especially ReturnBool)
Done.

================
Comment at: lib/CodeGen/CGBuiltin.cpp:174
@@ +173,3 @@
+
+  Value *Args[3];
+  Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType);
----------------
eliben wrote:
> Would universal initialization be simpler here?
> 
> Value *Args[3] = {CGF.Builder.CreateBi......, CGF.EmitScalar...}
> 
> 
Args[1] creation is a two-step operation which gets in a way.

http://reviews.llvm.org/D10666

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list