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

Eli Bendersky eliben at google.com
Wed Jun 24 08:08:28 PDT 2015


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

================
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);
----------------
You can just "return RValue::get(MakeBinary...)" -- similarly to how it's done below, for consistency

================
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();
----------------
Please document all function parameters in the comment (especially ReturnBool)

================
Comment at: lib/CodeGen/CGBuiltin.cpp:174
@@ +173,3 @@
+
+  Value *Args[3];
+  Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType);
----------------
Would universal initialization be simpler here?

Value *Args[3] = {CGF.Builder.CreateBi......, CGF.EmitScalar...}



================
Comment at: lib/CodeGen/CGBuiltin.cpp:6865
@@ +6864,3 @@
+
+Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID,
+                                             const CallExpr *E) {
----------------
I'm wondering if there's some unwritten rule saying that all target builtins should be crammed into a single file... It's closing in on 7KLOC now and no end in sight. Would it be very bad for NVPTX to have its own CGBuiltinNVPTX or something like that? Clang splits classes to multiple files (Sema, CodeGenFunction, etc) already... 

Eric?

http://reviews.llvm.org/D10666

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






More information about the cfe-commits mailing list