[Openmp-dev] Experimental SPIR-V back-end using OpenCL 2.1

Marcio Machado Pereira via Openmp-dev openmp-dev at lists.llvm.org
Wed Nov 1 08:21:05 PDT 2017


Dear Daniel,

I was very interested in getting to know your work. I realized that a
visual inspection is not enough, so I decided to build the tools to inspect
how you are generating code for spir-v. I downloaded clang, llvm and openmp
indicated by you in the email and start the build process. It happened that
in this process I encountered a series of inconsistencies, and differences
in functions signature, etc. I tried to solve them by modifying some of the
files I set out below. This allowed me to continue a little, but as the
changes started to require more meaningful changes, I decided to write to
you counting with your help. I'm sorry if the email is large but I tried to
describe the problems and solution alternatives I used. To facilitate your
analysis, I used the git diff tool that explains my modifications. At the
end of the text, I put the final result of the make process in two
situations (for 1 thread and 4 threads). I would greatly appreciate
feedback from you to complete this build process.

Follow the informations:

==============================================
file clang/utils/TableGen/ClangAttrEmitter.cpp
==============================================

$ git diff utils/TableGen/ClangAttrEmitter.cpp
diff --git a/utils/TableGen/ClangAttrEmitter.cpp
b/utils/TableGen/ClangAttrEmitter.cpp
index effabcc..39ae476 100644
--- a/utils/TableGen/ClangAttrEmitter.cpp
+++ b/utils/TableGen/ClangAttrEmitter.cpp
@@ -41,6 +41,7 @@
 #include <vector>

 using namespace llvm;
+using namespace detail;

 namespace {

@@ -733,20 +734,23 @@ namespace {
   };

   // Unique the enums, but maintain the original declaration ordering.
-  std::vector<StringRef>
-  uniqueEnumsInOrder(const std::vector<StringRef> &enums) {
-    std::vector<StringRef> uniques;
-    SmallDenseSet<StringRef, 8> unique_set;
+  std::vector<std::string>
+  uniqueEnumsInOrder(const std::vector<std::string> &enums) {
+    std::vector<std::string> uniques;
+    std::set<std::string> unique_set(enums.begin(), enums.end());
     for (const auto &i : enums) {
-      if (unique_set.insert(i).second)
+      std::set<std::string>::iterator set_i = unique_set.find(i);
+      if (set_i != unique_set.end()) {
         uniques.push_back(i);
+        unique_set.erase(set_i);
+      }
     }
     return uniques;
   }

   class EnumArgument : public Argument {
     std::string type;
-    std::vector<StringRef> values, enums, uniques;
+    std::vector<std::string> values, enums, uniques;

   public:
     EnumArgument(const Record &Arg, StringRef Attr)
@@ -866,7 +870,7 @@ namespace {

   class VariadicEnumArgument: public VariadicArgument {
     std::string type, QualifiedTypeName;
-    std::vector<StringRef> values, enums, uniques;
+    std::vector<std::string> values, enums, uniques;

   protected:
     void writeValueImpl(raw_ostream &OS) const override {
@@ -2624,7 +2628,7 @@ void EmitClangAttrPCHWrite(RecordKeeper &Records,
raw_ostream &OS) {
 // append a unique suffix to distinguish this set of target checks from
other
 // TargetSpecificAttr records.
 static void GenerateTargetSpecificAttrChecks(const Record *R,
-                                             std::vector<StringRef>
&Arches,
+                                             std::vector<std::string>
&Arches,
                                              std::string &Test,
                                              std::string *FnName) {
   // It is assumed that there will be an llvm::Triple object
@@ -2649,9 +2653,9 @@ static void GenerateTargetSpecificAttrChecks(const
Record *R,
     // We know that there was at least one arch test, so we need to and in
the
     // OS tests.
     Test += " && (";
-    std::vector<StringRef> OSes = R->getValueAsListOfStrings("OSes");
+    std::vector<std::string> OSes = R->getValueAsListOfStrings("OSes");
     for (auto I = OSes.begin(), E = OSes.end(); I != E; ++I) {
-      StringRef Part = *I;
+      std::string Part = *I;

       Test += "T.getOS() == llvm::Triple::";
       Test += Part;
@@ -2666,9 +2670,9 @@ static void GenerateTargetSpecificAttrChecks(const
Record *R,
   // If one or more CXX ABIs are specified, check those as well.
   if (!R->isValueUnset("CXXABIs")) {
     Test += " && (";
-    std::vector<StringRef> CXXABIs = R->getValueAsListOfStrings("CXXABIs");
+    std::vector<std::string> CXXABIs =
R->getValueAsListOfStrings("CXXABIs");
     for (auto I = CXXABIs.begin(), E = CXXABIs.end(); I != E; ++I) {
-      StringRef Part = *I;
+      std::string Part = *I;
       Test += "Target.getCXXABI().getKind() == TargetCXXABI::";
       Test += Part;
       if (I + 1 != E)
@@ -2708,7 +2712,7 @@ static void GenerateHasAttrSpellingStringSwitch(
     std::string Test;
     if (Attr->isSubClassOf("TargetSpecificAttr")) {
       const Record *R = Attr->getValueAsDef("Target");
-      std::vector<StringRef> Arches = R->getValueAsListOfStrings("Arches");
+      std::vector<std::string> Arches =
R->getValueAsListOfStrings("Arches");
       GenerateTargetSpecificAttrChecks(R, Arches, Test, nullptr);

       // If this is the C++11 variety, also add in the LangOpts test.
@@ -3360,7 +3364,7 @@ static std::string GenerateTargetRequirements(const
Record &Attr,

   // Get the list of architectures to be tested for.
   const Record *R = Attr.getValueAsDef("Target");
-  std::vector<StringRef> Arches = R->getValueAsListOfStrings("Arches");
+  std::vector<std::string> Arches = R->getValueAsListOfStrings("Arches");
   if (Arches.empty()) {
     PrintError(Attr.getLoc(), "Empty list of target architectures for a "
                               "target-specific attr");
@@ -3377,7 +3381,7 @@ static std::string GenerateTargetRequirements(const
Record &Attr,
     const StringRef APK = Attr.getValueAsString("ParseKind");
     for (const auto &I : Dupes) {
       if (I.first == APK) {
-        std::vector<StringRef> DA =
+        std::vector<std::string> DA =
             I.second->getValueAsDef("Target")->getValueAsListOfStrings(
                 "Arches");
         Arches.insert(Arches.end(), DA.begin(), DA.end());
@@ -3899,20 +3903,20 @@ void
EmitTestPragmaAttributeSupportedAttributes(RecordKeeper &Records,
     std::vector<Record *> Subjects =
         SubjectObj->getValueAsListOfDefs("Subjects");
     OS << " (";
-    for (const auto &Subject : llvm::enumerate(Subjects)) {
-      if (Subject.index())
+    for (auto Subject : enumerate(Subjects)) {
+      if (Subject.Index)
         OS << ", ";
       PragmaClangAttributeSupport::RuleOrAggregateRuleSet &RuleSet =
-          Support.SubjectsToRules.find(Subject.value())->getSecond();
+          Support.SubjectsToRules.find(Subject.Value)->getSecond();
       if (RuleSet.isRule()) {
         OS << RuleSet.getRule().getEnumValueName();
         continue;
       }
       OS << "(";
-      for (const auto &Rule :
llvm::enumerate(RuleSet.getAggregateRuleSet())) {
-        if (Rule.index())
+      for (auto Rule : enumerate(RuleSet.getAggregateRuleSet())) {
+        if (Rule.Index)
           OS << ", ";
-        OS << Rule.value().getEnumValueName();
+        OS << Rule.Value.getEnumValueName();
       }
       OS << ")";
     }

=====================================================
File clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
=====================================================

$ git diff utils/TableGen/ClangDiagnosticsEmitter.cpp
diff --git a/utils/TableGen/ClangDiagnosticsEmitter.cpp
b/utils/TableGen/ClangDiagnosticsEmitter.cpp
index d9d99e0..32f5317 100644
--- a/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -1278,7 +1278,7 @@ void EmitClangDiagDocs(RecordKeeper &Records,
raw_ostream &OS) {
                      GroupInfo.SubGroups.size() == 1;

     writeHeader(((IsRemarkGroup ? "-R" : "-W") +
-                    G->getValueAsString("GroupName")).str(),
+                    G->getValueAsString("GroupName")),
                 OS);

     if (!IsSynonym) {

===================================================
File clang/utils/TableGen/ClangOptionDocEmitter.cpp
===================================================

$ git diff utils/TableGen/ClangOptionDocEmitter.cpp
diff --git a/utils/TableGen/ClangOptionDocEmitter.cpp
b/utils/TableGen/ClangOptionDocEmitter.cpp
index 5931451..7e6566c 100644
--- a/utils/TableGen/ClangOptionDocEmitter.cpp
+++ b/utils/TableGen/ClangOptionDocEmitter.cpp
@@ -229,7 +229,7 @@ std::string getRSTStringWithTextFallback(const Record
*R, StringRef Primary,
 }

 void emitOptionWithArgs(StringRef Prefix, const Record *Option,
-                        ArrayRef<StringRef> Args, raw_ostream &OS) {
+                        ArrayRef<std::string> Args, raw_ostream &OS) {
   OS << Prefix << escapeRST(Option->getValueAsString("Name"));

   std::pair<StringRef, StringRef> Separators =
@@ -261,7 +261,7 @@ void emitOptionName(StringRef Prefix, const Record
*Option, raw_ostream &OS) {
     }
   }

-  emitOptionWithArgs(Prefix, Option, std::vector<StringRef>(Args.begin(),
Args.end()), OS);
+  emitOptionWithArgs(Prefix, Option,
std::vector<std::string>(Args.begin(), Args.end()), OS);

   auto AliasArgs = Option->getValueAsListOfStrings("AliasArgs");
   if (!AliasArgs.empty()) {
@@ -311,7 +311,7 @@ void emitOption(const DocumentedOption &Option, const
Record *DocInfo,
   forEachOptionName(Option, DocInfo, [&](const Record *Option) {
     for (auto &Prefix : Option->getValueAsListOfStrings("Prefixes"))
       SphinxOptionIDs.push_back(
-          getSphinxOptionID((Prefix +
Option->getValueAsString("Name")).str()));
+          getSphinxOptionID((Prefix + Option->getValueAsString("Name"))));
   });
   assert(!SphinxOptionIDs.empty() && "no flags for option");
   static std::map<std::string, int> NextSuffix;

=================================================
file llvm/include/llvm/Support/SpecialCaseList.h:
=================================================

$ git diff include/llvm/Support/SpecialCaseList.h
diff --git a/include/llvm/Support/SpecialCaseList.h
b/include/llvm/Support/SpecialCaseList.h
index ce693c5..dc8532c 100644
--- a/include/llvm/Support/SpecialCaseList.h
+++ b/include/llvm/Support/SpecialCaseList.h
@@ -82,12 +82,14 @@ public:
   bool inSection(StringRef Section, StringRef Query,
                  StringRef Category = StringRef()) const;

-private:
+
+protected:
   SpecialCaseList(SpecialCaseList const &) = delete;
   SpecialCaseList &operator=(SpecialCaseList const &) = delete;

   struct Entry;
-  StringMap<StringMap<Entry>> Entries;
+  using SectionEntries = StringMap<StringMap<Entry>>;
+  SectionEntries Entries;
   StringMap<StringMap<std::string>> Regexps;
   bool IsCompiled;




=================
Last compilation:
=================

$make
...
Scanning dependencies of target clangBasic
[ 68%] Building CXX object
tools/clang/lib/Basic/CMakeFiles/clangBasic.dir/SanitizerBlacklist.cpp.o
[ 68%] Building CXX object
tools/clang/lib/Basic/CMakeFiles/clangBasic.dir/SanitizerSpecialCaseList.cpp.o
/Users/marcio/clang-spirv/llvm/tools/clang/lib/Basic/SanitizerSpecialCaseList.cpp:23:13:
error:
      no member named 'createInternal' in 'clang::SanitizerSpecialCaseList'
  if (SSCL->createInternal(Paths, Error)) {
      ~~~~  ^
/Users/marcio/clang-spirv/llvm/tools/clang/lib/Basic/SanitizerSpecialCaseList.cpp:39:18:
error:
      use of undeclared identifier 'Sections'; did you mean 'inSection'?
  for (auto &S : Sections) {
                 ^~~~~~~~
                 inSection
/Users/marcio/clang-spirv/llvm/tools/clang/include/clang/Basic/SanitizerSpecialCaseList.h:34:8:
note:
      'inSection' declared here
  bool inSection(SanitizerMask Mask, StringRef Prefix, StringRef Query,
       ^
/Users/marcio/clang-spirv/llvm/tools/clang/lib/Basic/SanitizerSpecialCaseList.cpp:39:18:
error:
      reference to non-static member function must be called
  for (auto &S : Sections) {
                 ^~~~~~~~
/Users/marcio/clang-spirv/llvm/tools/clang/lib/Basic/SanitizerSpecialCaseList.cpp:60:62:
error:
      too many arguments to function call, expected at most 3, have 4
        SpecialCaseList::inSection(S.Entries, Prefix, Query, Category))
        ~~~~~~~~~~~~~~~~~~~~~~~~~~                           ^~~~~~~~
/Users/marcio/clang-spirv/llvm/include/llvm/Support/SpecialCaseList.h:82:3:
note:
      'inSection' declared here
  bool inSection(StringRef Section, StringRef Query,
  ^
4 errors generated.
make[2]: ***
[tools/clang/lib/Basic/CMakeFiles/clangBasic.dir/SanitizerSpecialCaseList.cpp.o]
Error 1
make[1]: *** [tools/clang/lib/Basic/CMakeFiles/clangBasic.dir/all] Error 2
make: *** [all] Error 2


$make -j4
...
[ 12%] Updating AttributesCompatFunc.inc...
[ 12%] Built target AttributeCompatFuncTableGen
/Users/marcio/clang-spirv/llvm/tools/clang/include/clang/Driver/Options.td:514:57:
[ 12%] Updating Attributes.gen...
error: Couldn't find class 'Values'
  HelpText<"OpenCL language standard to compile for.">,
Values<"cl,CL,cl1.1,CL1.1,cl1.2,CL1.2,cl2.0,CL2.0">;
                                                        ^
make[2]: *** [tools/clang/include/clang/Driver/Options.inc.tmp] Error 1
make[1]: ***
[tools/clang/include/clang/Driver/CMakeFiles/ClangDriverOptions.dir/all]
Error 2
make[1]: *** Waiting for unfinished jobs....
[ 12%] Updating Intrinsics.gen...
[ 12%] Built target intrinsics_gen
[ 12%] Built target llvm-mcmarkup
[ 12%] Built target llvm-cxxfilt
make: *** [all] Error 2

Cheers,
Marcio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/openmp-dev/attachments/20171101/4970b4d8/attachment-0001.html>


More information about the Openmp-dev mailing list