[cfe-commits] r129870 - in /cfe/trunk: include/clang/Basic/BuiltinsPTX.def include/clang/Basic/TargetBuiltins.h lib/Basic/Targets.cpp test/CodeGen/builtins-ptx.c
Justin Holewinski
justin.holewinski at gmail.com
Wed Apr 20 12:34:15 PDT 2011
Author: jholewinski
Date: Wed Apr 20 14:34:15 2011
New Revision: 129870
URL: http://llvm.org/viewvc/llvm-project?rev=129870&view=rev
Log:
PTX: Add PTX intrinsics as builtins and add ptx32 and ptx64 as valid architectures for triples, e.g. ptx32-unknown-unknown
Added:
cfe/trunk/include/clang/Basic/BuiltinsPTX.def
cfe/trunk/test/CodeGen/builtins-ptx.c
Modified:
cfe/trunk/include/clang/Basic/TargetBuiltins.h
cfe/trunk/lib/Basic/Targets.cpp
Added: cfe/trunk/include/clang/Basic/BuiltinsPTX.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsPTX.def?rev=129870&view=auto
==============================================================================
--- cfe/trunk/include/clang/Basic/BuiltinsPTX.def (added)
+++ cfe/trunk/include/clang/Basic/BuiltinsPTX.def Wed Apr 20 14:34:15 2011
@@ -0,0 +1,62 @@
+//===--- BuiltinsPTX.def - PTX 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 PTX-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.
+
+BUILTIN(__builtin_ptx_read_tid_x, "i", "nc")
+BUILTIN(__builtin_ptx_read_tid_y, "i", "nc")
+BUILTIN(__builtin_ptx_read_tid_z, "i", "nc")
+BUILTIN(__builtin_ptx_read_tid_w, "i", "nc")
+
+BUILTIN(__builtin_ptx_read_ntid_x, "i", "nc")
+BUILTIN(__builtin_ptx_read_ntid_y, "i", "nc")
+BUILTIN(__builtin_ptx_read_ntid_z, "i", "nc")
+BUILTIN(__builtin_ptx_read_ntid_w, "i", "nc")
+
+BUILTIN(__builtin_ptx_read_ctaid_x, "i", "nc")
+BUILTIN(__builtin_ptx_read_ctaid_y, "i", "nc")
+BUILTIN(__builtin_ptx_read_ctaid_z, "i", "nc")
+BUILTIN(__builtin_ptx_read_ctaid_w, "i", "nc")
+
+BUILTIN(__builtin_ptx_read_nctaid_x, "i", "nc")
+BUILTIN(__builtin_ptx_read_nctaid_y, "i", "nc")
+BUILTIN(__builtin_ptx_read_nctaid_z, "i", "nc")
+BUILTIN(__builtin_ptx_read_nctaid_w, "i", "nc")
+
+BUILTIN(__builtin_ptx_read_laneid, "i", "nc")
+BUILTIN(__builtin_ptx_read_warpid, "i", "nc")
+BUILTIN(__builtin_ptx_read_nwarpid, "i", "nc")
+
+BUILTIN(__builtin_ptx_read_smid, "i", "nc")
+BUILTIN(__builtin_ptx_read_nsmid, "i", "nc")
+BUILTIN(__builtin_ptx_read_gridid, "i", "nc")
+
+BUILTIN(__builtin_ptx_read_lanemask_eq, "i", "nc")
+BUILTIN(__builtin_ptx_read_lanemask_le, "i", "nc")
+BUILTIN(__builtin_ptx_read_lanemask_lt, "i", "nc")
+BUILTIN(__builtin_ptx_read_lanemask_ge, "i", "nc")
+BUILTIN(__builtin_ptx_read_lanemask_gt, "i", "nc")
+
+BUILTIN(__builtin_ptx_read_clock, "i", "n")
+BUILTIN(__builtin_ptx_read_clock64, "Li", "n")
+
+BUILTIN(__builtin_ptx_read_pm0, "i", "n")
+BUILTIN(__builtin_ptx_read_pm1, "i", "n")
+BUILTIN(__builtin_ptx_read_pm2, "i", "n")
+BUILTIN(__builtin_ptx_read_pm3, "i", "n")
+
+BUILTIN(__builtin_ptx_bar_sync, "vi", "n")
+
+
+#undef BUILTIN
Modified: cfe/trunk/include/clang/Basic/TargetBuiltins.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetBuiltins.h?rev=129870&r1=129869&r2=129870&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetBuiltins.h (original)
+++ cfe/trunk/include/clang/Basic/TargetBuiltins.h Wed Apr 20 14:34:15 2011
@@ -35,6 +35,17 @@
};
}
+ /// PTX builtins
+ namespace PTX {
+ enum {
+ LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1,
+#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
+#include "clang/Basic/BuiltinsPTX.def"
+ LastTSBuiltin
+ };
+ }
+
+
/// X86 builtins
namespace X86 {
enum {
Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=129870&r1=129869&r2=129870&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Wed Apr 20 14:34:15 2011
@@ -845,6 +845,87 @@
} // end anonymous namespace.
namespace {
+ class PTXTargetInfo : public TargetInfo {
+ static const char * const GCCRegNames[];
+ static const Builtin::Info BuiltinInfo[];
+ public:
+ PTXTargetInfo(const std::string& triple) : TargetInfo(triple) {
+ TLSSupported = false;
+ LongWidth = LongAlign = 64;
+ }
+ virtual void getTargetDefines(const LangOptions &Opts,
+ MacroBuilder &Builder) const {
+ Builder.defineMacro("__PTX__");
+ }
+ virtual void getTargetBuiltins(const Builtin::Info *&Records,
+ unsigned &NumRecords) const {
+ Records = BuiltinInfo;
+ NumRecords = clang::PTX::LastTSBuiltin-Builtin::FirstTSBuiltin;
+ }
+
+ virtual void getGCCRegNames(const char * const *&Names,
+ unsigned &NumNames) const;
+ virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
+ unsigned &NumAliases) const {
+ // No aliases.
+ Aliases = 0;
+ NumAliases = 0;
+ }
+ virtual bool validateAsmConstraint(const char *&Name,
+ TargetInfo::ConstraintInfo &info) const {
+ // FIXME: implement
+ return true;
+ }
+ virtual const char *getClobbers() const {
+ // FIXME: Is this really right?
+ return "";
+ }
+ virtual const char *getVAListDeclaration() const {
+ // FIXME: implement
+ return "typedef char* __builtin_va_list;";
+ }
+ };
+
+ const Builtin::Info PTXTargetInfo::BuiltinInfo[] = {
+#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES, false },
+#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
+ ALL_LANGUAGES, false },
+#include "clang/Basic/BuiltinsPTX.def"
+ };
+
+ const char * const PTXTargetInfo::GCCRegNames[] = {
+ "r0"
+ };
+
+ void PTXTargetInfo::getGCCRegNames(const char * const *&Names,
+ unsigned &NumNames) const {
+ Names = GCCRegNames;
+ NumNames = llvm::array_lengthof(GCCRegNames);
+ }
+
+
+ class PTX32TargetInfo : public PTXTargetInfo {
+ public:
+ PTX32TargetInfo(const std::string& triple) : PTXTargetInfo(triple) {
+ PointerWidth = PointerAlign = 32;
+ SizeType = PtrDiffType = IntPtrType = TargetInfo::UnsignedInt;
+ DescriptionString
+ = "e-p:32:32-i64:64:64-f64:64:64-n1:8:16:32:64";
+ }
+ };
+
+ class PTX64TargetInfo : public PTXTargetInfo {
+ public:
+ PTX64TargetInfo(const std::string& triple) : PTXTargetInfo(triple) {
+ PointerWidth = PointerAlign = 64;
+ SizeType = PtrDiffType = IntPtrType = TargetInfo::UnsignedLongLong;
+ DescriptionString
+ = "e-p:64:64-i64:64:64-f64:64:64-n1:8:16:32:64";
+ }
+ };
+}
+
+namespace {
// MBlaze abstract base class
class MBlazeTargetInfo : public TargetInfo {
static const char * const GCCRegNames[];
@@ -2659,6 +2740,11 @@
return new FreeBSDTargetInfo<PPC64TargetInfo>(T);
return new PPC64TargetInfo(T);
+ case llvm::Triple::ptx32:
+ return new PTX32TargetInfo(T);
+ case llvm::Triple::ptx64:
+ return new PTX64TargetInfo(T);
+
case llvm::Triple::mblaze:
return new MBlazeTargetInfo(T);
Added: cfe/trunk/test/CodeGen/builtins-ptx.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-ptx.c?rev=129870&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/builtins-ptx.c (added)
+++ cfe/trunk/test/CodeGen/builtins-ptx.c Wed Apr 20 14:34:15 2011
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -triple ptx32-unknown-unknown -emit-llvm -o %t %s
+// RUN: %clang_cc1 -triple ptx64-unknown-unknown -emit-llvm -o %t %s
+
+
+int read_tid() {
+
+ int x = __builtin_ptx_read_tid_x();
+ int y = __builtin_ptx_read_tid_y();
+ int z = __builtin_ptx_read_tid_z();
+ int w = __builtin_ptx_read_tid_w();
+
+ return x + y + z + w;
+
+}
+
+int read_ntid() {
+
+ int x = __builtin_ptx_read_ntid_x();
+ int y = __builtin_ptx_read_ntid_y();
+ int z = __builtin_ptx_read_ntid_z();
+ int w = __builtin_ptx_read_ntid_w();
+
+ return x + y + z + w;
+
+}
+
+int read_ctaid() {
+
+ int x = __builtin_ptx_read_ctaid_x();
+ int y = __builtin_ptx_read_ctaid_y();
+ int z = __builtin_ptx_read_ctaid_z();
+ int w = __builtin_ptx_read_ctaid_w();
+
+ return x + y + z + w;
+
+}
+
+int read_nctaid() {
+
+ int x = __builtin_ptx_read_nctaid_x();
+ int y = __builtin_ptx_read_nctaid_y();
+ int z = __builtin_ptx_read_nctaid_z();
+ int w = __builtin_ptx_read_nctaid_w();
+
+ return x + y + z + w;
+
+}
+
+int read_ids() {
+
+ int a = __builtin_ptx_read_laneid();
+ int b = __builtin_ptx_read_warpid();
+ int c = __builtin_ptx_read_nwarpid();
+ int d = __builtin_ptx_read_smid();
+ int e = __builtin_ptx_read_nsmid();
+ int f = __builtin_ptx_read_gridid();
+
+ return a + b + c + d + e + f;
+
+}
+
+int read_lanemasks() {
+
+ int a = __builtin_ptx_read_lanemask_eq();
+ int b = __builtin_ptx_read_lanemask_le();
+ int c = __builtin_ptx_read_lanemask_lt();
+ int d = __builtin_ptx_read_lanemask_ge();
+ int e = __builtin_ptx_read_lanemask_gt();
+
+ return a + b + c + d + e;
+
+}
+
+
+long read_clocks() {
+
+ int a = __builtin_ptx_read_clock();
+ long b = __builtin_ptx_read_clock64();
+
+ return (long)a + b;
+
+}
+
+int read_pms() {
+
+ int a = __builtin_ptx_read_pm0();
+ int b = __builtin_ptx_read_pm1();
+ int c = __builtin_ptx_read_pm2();
+ int d = __builtin_ptx_read_pm3();
+
+ return a + b + c + d;
+
+}
+
+void sync() {
+
+ __builtin_ptx_bar_sync(0);
+
+}
More information about the cfe-commits
mailing list