[cfe-commits] Patch: Add R600 TargetInfo

Tom Stellard thomas.stellard at amd.com
Fri Mar 16 07:15:30 PDT 2012


On Thu, Mar 15, 2012 at 03:52:20PM -0700, Eli Friedman wrote:
> On Thu, Mar 15, 2012 at 11:49 AM, Tom Stellard <thomas.stellard at amd.com> wrote:
> > On Tue, Mar 13, 2012 at 03:07:02PM -0400, Tom Stellard wrote:
> >> On Thu, Mar 08, 2012 at 01:19:31PM -0500, Tom Stellard wrote:
> >> > Hi,
> >> >
> >> > This patch adds a TargetInfo definition for the R600 target,
> >> > which represents AMD GPUs (HD2XXX-HD6XXX).  This patch depends
> >> > on the r600 target triple patch, which was sent to llvm-commits:
> >> > http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120305/138626.html
> >> >
> >> > This is the bare minimum needed to successfully compile OpenCL kernels
> >> > for the r600 target, and in the future we would like to add some target
> >> > specific builtins for handling OpenCL C functions.
> >> >
> >> > Please Review.
> >> >
> >> > Thanks,
> >> > Tom Stellard
> >>
> >> Has anyone had a chance to look at this patch yet?
> >>
> >> I have attached a second patch to this email that I would like to get
> >> committed along with the first one.  The second patch adds some builtin
> >> definitions for r600.
> >>
> >> -Tom
> >>
> >
> > Hi,
> >
> > I've quashed the previous two patches together and made some additional
> > changes, so here is an updated patch that adds a TargetInfo
> > definition for the r600 target.  This patch replaces the previous two.
> >
> > Please Review.
> 
> +//
> +// Authors: Tom Stellard <thomas.stellard at amd.com>
> 
> We don't generally put the names of developers into the source code.
> See http://llvm.org/docs/DeveloperPolicy.html .
> 
> 
> +class AMDGPUTargetInfo : public TargetInfo {
> 
> This class is pointless, since it only serves as a base class for one
> other class.
> 
> Otherwise, looks fine.
> 
> -Eli
> 

Thanks for your comments, I've attached an updated patch.

-Tom
-------------- next part --------------
diff --git include/clang/Basic/BuiltinsR600.def include/clang/Basic/BuiltinsR600.def
new file mode 100644
index 0000000..0fd2a35
--- /dev/null
+++ include/clang/Basic/BuiltinsR600.def
@@ -0,0 +1,37 @@
+//===--- BuiltinsR600.def - R600 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 R600-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_r600_read_global_size_x, "z", "nc")
+BUILTIN(__builtin_r600_read_global_size_y, "z", "nc")
+BUILTIN(__builtin_r600_read_global_size_z, "z", "nc")
+
+BUILTIN(__builtin_r600_read_local_size_x, "z", "nc")
+BUILTIN(__builtin_r600_read_local_size_y, "z", "nc")
+BUILTIN(__builtin_r600_read_local_size_z, "z", "nc")
+
+BUILTIN(__builtin_r600_read_ngroups_x, "z", "nc")
+BUILTIN(__builtin_r600_read_ngroups_y, "z", "nc")
+BUILTIN(__builtin_r600_read_ngroups_z, "z", "nc")
+
+BUILTIN(__builtin_r600_read_tidig_x, "z", "nc")
+BUILTIN(__builtin_r600_read_tidig_y, "z", "nc")
+BUILTIN(__builtin_r600_read_tidig_z, "z", "nc")
+
+BUILTIN(__builtin_r600_read_tgid_x, "z", "nc")
+BUILTIN(__builtin_r600_read_tgid_y, "z", "nc")
+BUILTIN(__builtin_r600_read_tgid_z, "z", "nc")
+
+#undef BUILTIN
diff --git include/clang/Basic/TargetBuiltins.h include/clang/Basic/TargetBuiltins.h
index 7c04bf7..3460cd5 100644
--- include/clang/Basic/TargetBuiltins.h
+++ include/clang/Basic/TargetBuiltins.h
@@ -45,6 +45,16 @@ namespace clang {
     };
   }
 
+  /// R600 builtins
+  namespace R600 {
+    enum {
+        LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1,
+#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
+#include "clang/Basic/BuiltinsR600.def"
+        LastTSBuiltin
+    };
+  }
+
 
   /// X86 builtins
   namespace X86 {
diff --git lib/Basic/Targets.cpp lib/Basic/Targets.cpp
index 85dfd78..b27a6f7 100644
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -1068,6 +1068,75 @@ namespace {
 }
 
 namespace {
+
+static const unsigned R600AddrSpaceMap[] = {
+  1,    // opencl_global
+  3,    // opencl_local
+  2     // opencl_constant
+};
+
+class R600TargetInfo : public TargetInfo {
+  static const Builtin::Info BuiltinInfo[];
+public:
+  R600TargetInfo(const std::string& triple) : TargetInfo(triple) {
+    DescriptionString =
+          "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16"
+          "-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f80:32:32"
+          "-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64"
+          "-v96:128:128-v128:128:128-v192:256:256-v256:256:256"
+          "-v512:512:512-v1024:1024:1024-v2048:2048:2048"
+          "-n8:16:32:64";
+    AddrSpaceMap = &R600AddrSpaceMap;
+  }
+
+  virtual const char * getClobbers() const {
+    return "";
+  }
+
+  virtual void getGCCRegNames(const char * const *&Names,
+                              unsigned &numNames) const  {
+    Names = NULL;
+    numNames = 0;
+  }
+
+  virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
+                                unsigned &NumAliases) const {
+    Aliases = NULL;
+    NumAliases = 0;
+  }
+
+  virtual bool validateAsmConstraint(const char *&Name,
+                                     TargetInfo::ConstraintInfo &info) const {
+    return true;
+  }
+
+  virtual void getTargetBuiltins(const Builtin::Info *&Records,
+                                 unsigned &NumRecords) const {
+    Records = BuiltinInfo;
+    NumRecords = clang::R600::LastTSBuiltin-Builtin::FirstTSBuiltin;
+  }
+
+
+  virtual void getTargetDefines(const LangOptions &Opts,
+                                MacroBuilder &Builder) const {
+    Builder.defineMacro("__R600__");
+  }
+
+  virtual const char * getVAListDeclaration() const {
+    return "";
+  }
+};
+
+const Builtin::Info R600TargetInfo::BuiltinInfo[] = {
+#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
+#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
+                                              ALL_LANGUAGES },
+#include "clang/Basic/BuiltinsR600.def"
+};
+
+} // end anonymous namespace
+
+namespace {
 // MBlaze abstract base class
 class MBlazeTargetInfo : public TargetInfo {
   static const char * const GCCRegNames[];
@@ -3963,6 +4032,9 @@ static TargetInfo *AllocateTarget(const std::string &T) {
   case llvm::Triple::mblaze:
     return new MBlazeTargetInfo(T);
 
+  case llvm::Triple::r600:
+    return new R600TargetInfo(T);
+
   case llvm::Triple::sparc:
     switch (os) {
     case llvm::Triple::Linux:


More information about the cfe-commits mailing list