[PATCH] D77039: [clang-format] Don't break multi block parameters on ObjCBreakBeforeNestedBlockParam

2020-04-06 Thread Jin Lin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG28ecd7f0b086: [clang-format] Don't break multi block 
parameters on… (authored by ghvg1313, committed by jinlin).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77039/new/

https://reviews.llvm.org/D77039

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/lib/Format/ContinuationIndenter.cpp
  clang/unittests/Format/FormatTestObjC.cpp


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -1420,6 +1420,10 @@
"*b, NSNumber *c) {\n"
"  b = c;\n"
"}]");
+  verifyFormat("[self.test1 t:self w:self callback:^(typeof(self) self, "
+   "NSNumber *u, NSNumber *v) {\n"
+   "  u = v;\n"
+   "} z:self]");
 
   Style.ColumnLimit = 80;
   verifyFormat(
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -342,6 +342,7 @@
   if (Previous.is(tok::semi) && State.LineContainsContinuedForLoopSection)
 return true;
   if (Style.Language == FormatStyle::LK_ObjC &&
+  Style.ObjCBreakBeforeNestedBlockParam &&
   Current.ObjCSelectorNameParts > 1 &&
   Current.startsSequence(TT_SelectorName, tok::colon, tok::caret)) {
 return true;
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -2072,8 +2072,8 @@
  - (void)_aMethod
  {
 [self.test1 t:self
- w:self
-callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
+w:self
+ callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
  u = c;
  }]
  }


Index: clang/unittests/Format/FormatTestObjC.cpp
===
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -1420,6 +1420,10 @@
"*b, NSNumber *c) {\n"
"  b = c;\n"
"}]");
+  verifyFormat("[self.test1 t:self w:self callback:^(typeof(self) self, "
+   "NSNumber *u, NSNumber *v) {\n"
+   "  u = v;\n"
+   "} z:self]");
 
   Style.ColumnLimit = 80;
   verifyFormat(
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -342,6 +342,7 @@
   if (Previous.is(tok::semi) && State.LineContainsContinuedForLoopSection)
 return true;
   if (Style.Language == FormatStyle::LK_ObjC &&
+  Style.ObjCBreakBeforeNestedBlockParam &&
   Current.ObjCSelectorNameParts > 1 &&
   Current.startsSequence(TT_SelectorName, tok::colon, tok::caret)) {
 return true;
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -2072,8 +2072,8 @@
  - (void)_aMethod
  {
 [self.test1 t:self
- w:self
-callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
+w:self
+ callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
  u = c;
  }]
  }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71219: Fix conflict value for metadata "Objective-C Garbage Collection" in the mix of swift and Objective-C bitcode

2020-03-11 Thread Jin Lin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa0cacb60549f: Fix conflict value for metadata 
"Objective-C Garbage Collection" in the mix of… (authored by jinlin).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71219/new/

https://reviews.llvm.org/D71219

Files:
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/test/CodeGenObjC/image-info.m
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/test/Bitcode/upgrade-garbage-collection-for-objc.ll
  llvm/test/Bitcode/upgrade-garbage-collection-for-swift.ll
  llvm/test/Linker/Inputs/empty-objc.ll
  llvm/test/Linker/empty-swift.ll
  llvm/test/Object/objc-swift-mixed-imageinfo-macho.ll

Index: llvm/test/Object/objc-swift-mixed-imageinfo-macho.ll
===
--- /dev/null
+++ llvm/test/Object/objc-swift-mixed-imageinfo-macho.ll
@@ -0,0 +1,46 @@
+; RUN: llc -mtriple x86_64-apple-ios -filetype asm -o - %s | FileCheck %s
+; REQUIRES: x86-registered-target
+
+; It checks whether the backend generates IMAGE_INFO from Swift ABI version + major + minor + "Objective-C Garbage Collection".
+
+target triple = "x86_64-apple-macosx10.15.0"
+
+@llvm.used = appending global [1 x i8*] [i8* bitcast (i16* @__swift_reflection_version to i8*)], section "llvm.metadata", align 8
+@__swift_reflection_version = linkonce_odr hidden constant i16 3
+
+define i32 @main(i32 %0, i8** %1) #0 {
+  %3 = bitcast i8** %1 to i8*
+  ret i32 0
+}
+
+attributes #0 = { "frame-pointer"="all" "target-cpu"="penryn" "target-features"="+cx16,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" }
+
+!swift.module.flags = !{!0}
+!llvm.linker.options = !{!1, !2, !3}
+!llvm.asan.globals = !{!4}
+!llvm.module.flags = !{!5, !6, !7, !8, !9, !10, !11, !12, !13, !14, !15, !16}
+!llvm.ident = !{!17}
+
+!0 = !{!"standard-library", i1 false}
+!1 = !{!"-lswiftSwiftOnoneSupport"}
+!2 = !{!"-lswiftCore"}
+!3 = !{!"-lobjc"}
+!4 = !{[1 x i8*]* @llvm.used, null, null, i1 false, i1 true}
+!5 = !{i32 2, !"SDK Version", [2 x i32] [i32 10, i32 15]}
+!6 = !{i32 1, !"Objective-C Version", i32 2}
+!7 = !{i32 1, !"Objective-C Image Info Version", i32 0}
+!8 = !{i32 1, !"Objective-C Image Info Section", !"__DATA,__objc_imageinfo,regular,no_dead_strip"}
+!9 = !{i32 1, !"Objective-C Garbage Collection", i8 0}
+!10 = !{i32 1, !"Objective-C Class Properties", i32 64}
+!11 = !{i32 1, !"wchar_size", i32 4}
+!12 = !{i32 7, !"PIC Level", i32 2}
+!13 = !{i32 1, !"Swift Version", i32 7}
+!14 = !{i32 1, !"Swift ABI Version", i32 7}
+!15 = !{i32 1, !"Swift Major Version", i8 5}
+!16 = !{i32 1, !"Swift Minor Version", i8 1}
+!17 = !{!"Apple clang version 11.0.0 (clang-1100.0.33.12)"}
+
+; CHECK: .section	__DATA,__objc_imageinfo,regular,no_dead_strip
+; CHECK: L_OBJC_IMAGE_INFO:
+; CHECK:   .long 0
+; CHECK:   .long 83953472
Index: llvm/test/Linker/empty-swift.ll
===
--- /dev/null
+++ llvm/test/Linker/empty-swift.ll
@@ -0,0 +1,42 @@
+; RUN: llvm-link %s %p/Inputs/empty-objc.ll -S | FileCheck %s
+
+; It tests whether Swift bitcode can be successfully linked with Objecitive-C bitcode.
+; During the process, the IRUpgrader turns a i32 type "Objective-C Garbage Collection"
+; into i8 value. If the higher bits are set, it adds the module flag for swift info.
+
+target triple = "x86_64-apple-macosx10.15.0"
+
+@__swift_reflection_version = linkonce_odr hidden constant i16 3
+@llvm.used = appending global [1 x i8*] [i8* bitcast (i16* @__swift_reflection_version to i8*)], section "llvm.metadata", align 8
+
+define i32 @main(i32 %0, i8** %1) #0 {
+  %3 = bitcast i8** %1 to i8*
+  ret i32 0
+}
+
+attributes #0 = { "frame-pointer"="all" "target-cpu"="penryn" "target-features"="+cx16,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" }
+
+!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6, !7, !8}
+!swift.module.flags = !{!9}
+!llvm.linker.options = !{!10, !11, !12}
+!llvm.asan.globals = !{!13}
+
+!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 10, i32 15]}
+!1 = !{i32 1, !"Objective-C Version", i32 2}
+!2 = !{i32 1, !"Objective-C Image Info Version", i32 0}
+!3 = !{i32 1, !"Objective-C Image Info Section", !"__DATA,__objc_imageinfo,regular,no_dead_strip"}
+!4 = !{i32 4, !"Objective-C Garbage Collection", i32 83953408}
+!5 = !{i32 1, !"Objective-C Class Properties", i32 64}
+!6 = !{i32 1, !"wchar_size", i32 4}
+!7 = !{i32 7, !"PIC Level", i32 2}
+!8 = !{i32 1, !"Swift Version", i32 7}
+!9 = !{!"standard-library", i1 false}
+!10 = !{!"-lswiftSwiftOnoneSupport"}
+!11 = !{!"-lswiftCore"}
+!12 = !{!"-lobjc"}
+!13 = !{[1 x i8*]* @llvm.used, null, null, i1 false, i1 true}
+
+; CHECK: !{{[0-9]+}} = !{i32 1, !"Objective-C Garbage Collection", i8 0}
+; CHECK: !{{[0-9]+}} = !{i32 1, !"Swift ABI Version", i32 7}
+; CHECK: !{{[0-9]+}} = !{i32 1, !"Swift Major Vers

[PATCH] D46074: Representing the target device information in the LLVM IR ( CLANG changes)

2018-04-25 Thread Jin Lin via Phabricator via cfe-commits
jinlin created this revision.
jinlin added a reviewer: hfinkel.
Herald added a subscriber: cfe-commits.

The target device information needs to be passed to the LLVM backend when the 
OMP backend outlining is enabled. For example, for multiple target devices, the 
target compilation has to generate one single host to support all the targets. 
In order to make sure all the target outline function have the same interface, 
the information of all the target architecture are needed during host and 
target compilation. In the following example, the firstprivate variable d is 
represented as passing by value under x86_64 mic and passing by reference under 
i386-pc-linux-gnu. In order to fix this inconsistency issue, the compiler can 
change the form of firstprivate d from passing by value under x86_64 mic to 
passing by reference after the compiler has all the target architecture 
information.

Existing code: 64-bit firstprivate variable

void foo() {
 double d = 1.0;
 #pragma omp target firstprivate(d)
 {}
}

$clang –fopenmp-backend -fopenmp-targets=x86_64-mic, i386-pc-linux-gnu …

x86_64-mic

define void @__omp_offloading…(i64 %d) #0 {
entry:
…
}

i386-pc-linux-gnu

define void @__omp_offloading…(double* dereferenceable(8) %d) #0 {
entry:
 …
}

There is an inconsistency between host and target part(s) of the program!

We proposed new module level attribute to represent target device information.

/// Get the target device information which is a string separated by the
/// comma to describe one or more than one device.
const std::string &getTargetDevices() const { return TargetDevices; }

/// set the target device information.
void setTargetDevices(StringRef T) { TargetDevices = T; }

IR Dump (the extension indicated in red font)
target triple = "x86_64-unknown-linux-gnu"
target device_triples = "x86_64-mic,i386-pc-linux-gnu"


Repository:
  rC Clang

https://reviews.llvm.org/D46074

Files:
  lib/CodeGen/ModuleBuilder.cpp


Index: lib/CodeGen/ModuleBuilder.cpp
===
--- lib/CodeGen/ModuleBuilder.cpp
+++ lib/CodeGen/ModuleBuilder.cpp
@@ -131,6 +131,18 @@
   Ctx = &Context;
 
   M->setTargetTriple(Ctx->getTargetInfo().getTriple().getTriple());
+
+  // The target device information is represented as module level
+  // attribute.
+  SmallString<128> Res;
+  for (auto &Device : Ctx->getLangOpts().OMPTargetTriples) {
+if (!Res.empty())
+  Res += ",";
+Res += Device.getTriple();
+  }
+  if (!Res.empty())
+M->setTargetDevices(Res);
+
   M->setDataLayout(Ctx->getTargetInfo().getDataLayout());
   Builder.reset(new CodeGen::CodeGenModule(Context, HeaderSearchOpts,
PreprocessorOpts, CodeGenOpts,


Index: lib/CodeGen/ModuleBuilder.cpp
===
--- lib/CodeGen/ModuleBuilder.cpp
+++ lib/CodeGen/ModuleBuilder.cpp
@@ -131,6 +131,18 @@
   Ctx = &Context;
 
   M->setTargetTriple(Ctx->getTargetInfo().getTriple().getTriple());
+
+  // The target device information is represented as module level
+  // attribute.
+  SmallString<128> Res;
+  for (auto &Device : Ctx->getLangOpts().OMPTargetTriples) {
+if (!Res.empty())
+  Res += ",";
+Res += Device.getTriple();
+  }
+  if (!Res.empty())
+M->setTargetDevices(Res);
+
   M->setDataLayout(Ctx->getTargetInfo().getDataLayout());
   Builder.reset(new CodeGen::CodeGenModule(Context, HeaderSearchOpts,
PreprocessorOpts, CodeGenOpts,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46071: Representing the target device information in the LLVM IR

2018-04-25 Thread Jin Lin via Phabricator via cfe-commits
jinlin updated this revision to Diff 143967.

https://reviews.llvm.org/D46071

Files:
  docs/LangRef.rst
  include/llvm/Bitcode/LLVMBitCodes.h
  include/llvm/IR/Module.h
  lib/AsmParser/LLLexer.cpp
  lib/AsmParser/LLParser.cpp
  lib/AsmParser/LLToken.h
  lib/Bitcode/Reader/BitcodeReader.cpp
  lib/Bitcode/Writer/BitcodeWriter.cpp
  lib/IR/AsmWriter.cpp
  lib/Transforms/Utils/CloneModule.cpp

Index: lib/Transforms/Utils/CloneModule.cpp
===
--- lib/Transforms/Utils/CloneModule.cpp
+++ lib/Transforms/Utils/CloneModule.cpp
@@ -53,6 +53,7 @@
   New->setSourceFileName(M.getSourceFileName());
   New->setDataLayout(M.getDataLayout());
   New->setTargetTriple(M.getTargetTriple());
+  New->setTargetDevices(M.getTargetDevices());
   New->setModuleInlineAsm(M.getModuleInlineAsm());
 
   // Loop over all of the global variables, making corresponding globals in the
@@ -110,7 +111,7 @@
 GA->copyAttributesFrom(&*I);
 VMap[&*I] = GA;
   }
-  
+
   // Now that all of the things that global variable initializer can refer to
   // have been created, loop through and copy the global variable referrers
   // over...  We also set the attributes on the global now.
Index: lib/IR/AsmWriter.cpp
===
--- lib/IR/AsmWriter.cpp
+++ lib/IR/AsmWriter.cpp
@@ -2392,6 +2392,9 @@
   if (!M->getTargetTriple().empty())
 Out << "target triple = \"" << M->getTargetTriple() << "\"\n";
 
+  if (!M->getTargetDevices().empty())
+Out << "target device_triples = \"" << M->getTargetDevices() << "\"\n";
+
   if (!M->getModuleInlineAsm().empty()) {
 Out << '\n';
 
Index: lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- lib/Bitcode/Writer/BitcodeWriter.cpp
+++ lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1108,6 +1108,9 @@
   if (!M.getTargetTriple().empty())
 writeStringRecord(Stream, bitc::MODULE_CODE_TRIPLE, M.getTargetTriple(),
   0 /*TODO*/);
+  if (!M.getTargetDevices().empty())
+writeStringRecord(Stream, bitc::MODULE_CODE_DEVICES, M.getTargetDevices(),
+  0 /*TODO*/);
   const std::string &DL = M.getDataLayoutStr();
   if (!DL.empty())
 writeStringRecord(Stream, bitc::MODULE_CODE_DATALAYOUT, DL, 0 /*TODO*/);
Index: lib/Bitcode/Reader/BitcodeReader.cpp
===
--- lib/Bitcode/Reader/BitcodeReader.cpp
+++ lib/Bitcode/Reader/BitcodeReader.cpp
@@ -3257,6 +3257,13 @@
   TheModule->setTargetTriple(S);
   break;
 }
+case bitc::MODULE_CODE_DEVICES: { // TRIPLE: [strchr x N, ..., strchr x N]
+  std::string S;
+  if (convertToString(Record, 0, S))
+return error("Invalid record");
+  TheModule->setTargetDevices(S);
+  break;
+}
 case bitc::MODULE_CODE_DATALAYOUT: {  // DATALAYOUT: [strchr x N]
   std::string S;
   if (convertToString(Record, 0, S))
Index: lib/AsmParser/LLToken.h
===
--- lib/AsmParser/LLToken.h
+++ lib/AsmParser/LLToken.h
@@ -84,6 +84,7 @@
   kw_notail,
   kw_target,
   kw_triple,
+  kw_device_triples,
   kw_source_filename,
   kw_unwind,
   kw_deplibs, // FIXME: Remove in 4.0
Index: lib/AsmParser/LLParser.cpp
===
--- lib/AsmParser/LLParser.cpp
+++ lib/AsmParser/LLParser.cpp
@@ -322,6 +322,13 @@
   return true;
 M->setTargetTriple(Str);
 return false;
+  case lltok::kw_device_triples:
+Lex.Lex();
+if (ParseToken(lltok::equal, "expected '=' after target devices") ||
+ParseStringConstant(Str))
+  return true;
+M->setTargetDevices(Str);
+return false;
   case lltok::kw_datalayout:
 Lex.Lex();
 if (ParseToken(lltok::equal, "expected '=' after target datalayout") ||
Index: lib/AsmParser/LLLexer.cpp
===
--- lib/AsmParser/LLLexer.cpp
+++ lib/AsmParser/LLLexer.cpp
@@ -533,6 +533,7 @@
   KEYWORD(notail);
   KEYWORD(target);
   KEYWORD(triple);
+  KEYWORD(device_triples);
   KEYWORD(source_filename);
   KEYWORD(unwind);
   KEYWORD(deplibs); // FIXME: Remove in 4.0.
Index: include/llvm/IR/Module.h
===
--- include/llvm/IR/Module.h
+++ include/llvm/IR/Module.h
@@ -187,6 +187,8 @@
   void *NamedMDSymTab;///< NamedMDNode names.
   DataLayout DL;  ///< DataLayout associated with the module
 
+  std::string TargetDevices;  ///< Target devices
+
   friend class Constant;
 
 /// @}
@@ -232,6 +234,10 @@
   /// @returns a string containing the target triple.
   const std::string &getTargetTriple() const { return TargetTriple; }
 
+  /// Get the target device information which is a comma-separated string
+  /// describing one or more devices.
+  const std::string

[PATCH] D46071: Representing the target device information in the LLVM IR

2018-04-25 Thread Jin Lin via Phabricator via cfe-commits
jinlin updated this revision to Diff 143966.

https://reviews.llvm.org/D46071

Files:
  docs/LangRef.rst
  include/llvm/Bitcode/LLVMBitCodes.h
  include/llvm/IR/Module.h
  lib/AsmParser/LLLexer.cpp
  lib/AsmParser/LLParser.cpp
  lib/AsmParser/LLToken.h
  lib/Bitcode/Reader/BitcodeReader.cpp
  lib/Bitcode/Writer/BitcodeWriter.cpp
  lib/IR/AsmWriter.cpp
  lib/Transforms/Utils/CloneModule.cpp

Index: lib/Transforms/Utils/CloneModule.cpp
===
--- lib/Transforms/Utils/CloneModule.cpp
+++ lib/Transforms/Utils/CloneModule.cpp
@@ -53,6 +53,7 @@
   New->setSourceFileName(M.getSourceFileName());
   New->setDataLayout(M.getDataLayout());
   New->setTargetTriple(M.getTargetTriple());
+  New->setTargetDevices(M.getTargetDevices());
   New->setModuleInlineAsm(M.getModuleInlineAsm());
 
   // Loop over all of the global variables, making corresponding globals in the
@@ -110,7 +111,7 @@
 GA->copyAttributesFrom(&*I);
 VMap[&*I] = GA;
   }
-  
+
   // Now that all of the things that global variable initializer can refer to
   // have been created, loop through and copy the global variable referrers
   // over...  We also set the attributes on the global now.
Index: lib/IR/AsmWriter.cpp
===
--- lib/IR/AsmWriter.cpp
+++ lib/IR/AsmWriter.cpp
@@ -2392,6 +2392,9 @@
   if (!M->getTargetTriple().empty())
 Out << "target triple = \"" << M->getTargetTriple() << "\"\n";
 
+  if (!M->getTargetDevices().empty())
+Out << "target device_triples = \"" << M->getTargetDevices() << "\"\n";
+
   if (!M->getModuleInlineAsm().empty()) {
 Out << '\n';
 
Index: lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- lib/Bitcode/Writer/BitcodeWriter.cpp
+++ lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1108,6 +1108,9 @@
   if (!M.getTargetTriple().empty())
 writeStringRecord(Stream, bitc::MODULE_CODE_TRIPLE, M.getTargetTriple(),
   0 /*TODO*/);
+  if (!M.getTargetDevices().empty())
+writeStringRecord(Stream, bitc::MODULE_CODE_DEVICES, M.getTargetDevices(),
+  0 /*TODO*/);
   const std::string &DL = M.getDataLayoutStr();
   if (!DL.empty())
 writeStringRecord(Stream, bitc::MODULE_CODE_DATALAYOUT, DL, 0 /*TODO*/);
Index: lib/Bitcode/Reader/BitcodeReader.cpp
===
--- lib/Bitcode/Reader/BitcodeReader.cpp
+++ lib/Bitcode/Reader/BitcodeReader.cpp
@@ -3257,6 +3257,13 @@
   TheModule->setTargetTriple(S);
   break;
 }
+case bitc::MODULE_CODE_DEVICES: { // TRIPLE: [strchr x N, ..., strchr x N]
+  std::string S;
+  if (convertToString(Record, 0, S))
+return error("Invalid record");
+  TheModule->setTargetDevices(S);
+  break;
+}
 case bitc::MODULE_CODE_DATALAYOUT: {  // DATALAYOUT: [strchr x N]
   std::string S;
   if (convertToString(Record, 0, S))
Index: lib/AsmParser/LLToken.h
===
--- lib/AsmParser/LLToken.h
+++ lib/AsmParser/LLToken.h
@@ -84,6 +84,7 @@
   kw_notail,
   kw_target,
   kw_triple,
+  kw_device_triples,
   kw_source_filename,
   kw_unwind,
   kw_deplibs, // FIXME: Remove in 4.0
Index: lib/AsmParser/LLParser.cpp
===
--- lib/AsmParser/LLParser.cpp
+++ lib/AsmParser/LLParser.cpp
@@ -322,6 +322,13 @@
   return true;
 M->setTargetTriple(Str);
 return false;
+  case lltok::kw_device_triples:
+Lex.Lex();
+if (ParseToken(lltok::equal, "expected '=' after target devices") ||
+ParseStringConstant(Str))
+  return true;
+M->setTargetDevices(Str);
+return false;
   case lltok::kw_datalayout:
 Lex.Lex();
 if (ParseToken(lltok::equal, "expected '=' after target datalayout") ||
Index: lib/AsmParser/LLLexer.cpp
===
--- lib/AsmParser/LLLexer.cpp
+++ lib/AsmParser/LLLexer.cpp
@@ -533,6 +533,7 @@
   KEYWORD(notail);
   KEYWORD(target);
   KEYWORD(triple);
+  KEYWORD(device_triples);
   KEYWORD(source_filename);
   KEYWORD(unwind);
   KEYWORD(deplibs); // FIXME: Remove in 4.0.
Index: include/llvm/IR/Module.h
===
--- include/llvm/IR/Module.h
+++ include/llvm/IR/Module.h
@@ -187,6 +187,8 @@
   void *NamedMDSymTab;///< NamedMDNode names.
   DataLayout DL;  ///< DataLayout associated with the module
 
+  std::string TargetDevices;  ///< Target devices
+
   friend class Constant;
 
 /// @}
@@ -232,6 +234,10 @@
   /// @returns a string containing the target triple.
   const std::string &getTargetTriple() const { return TargetTriple; }
 
+  /// Get the target device information which is a comma-separated string
+  /// describing one or more devices.
+  const std::string

[PATCH] D46071: Representing the target device information in the LLVM IR

2018-04-25 Thread Jin Lin via Phabricator via cfe-commits
jinlin updated this revision to Diff 143965.

https://reviews.llvm.org/D46071

Files:
  docs/LangRef.rst
  include/llvm/Bitcode/LLVMBitCodes.h
  include/llvm/IR/Module.h
  lib/AsmParser/LLLexer.cpp
  lib/AsmParser/LLParser.cpp
  lib/AsmParser/LLToken.h
  lib/Bitcode/Reader/BitcodeReader.cpp
  lib/Bitcode/Writer/BitcodeWriter.cpp
  lib/IR/AsmWriter.cpp
  lib/Transforms/Utils/CloneModule.cpp

Index: lib/IR/AsmWriter.cpp
===
--- lib/IR/AsmWriter.cpp
+++ lib/IR/AsmWriter.cpp
@@ -2392,6 +2392,9 @@
   if (!M->getTargetTriple().empty())
 Out << "target triple = \"" << M->getTargetTriple() << "\"\n";
 
+  if (!M->getTargetDevices().empty())
+Out << "target device_triples = \"" << M->getTargetDevices() << "\"\n";
+
   if (!M->getModuleInlineAsm().empty()) {
 Out << '\n';
 
Index: lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- lib/Bitcode/Writer/BitcodeWriter.cpp
+++ lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1108,6 +1108,9 @@
   if (!M.getTargetTriple().empty())
 writeStringRecord(Stream, bitc::MODULE_CODE_TRIPLE, M.getTargetTriple(),
   0 /*TODO*/);
+  if (!M.getTargetDevices().empty())
+writeStringRecord(Stream, bitc::MODULE_CODE_DEVICES, M.getTargetDevices(),
+  0 /*TODO*/);
   const std::string &DL = M.getDataLayoutStr();
   if (!DL.empty())
 writeStringRecord(Stream, bitc::MODULE_CODE_DATALAYOUT, DL, 0 /*TODO*/);
Index: lib/Bitcode/Reader/BitcodeReader.cpp
===
--- lib/Bitcode/Reader/BitcodeReader.cpp
+++ lib/Bitcode/Reader/BitcodeReader.cpp
@@ -3257,6 +3257,13 @@
   TheModule->setTargetTriple(S);
   break;
 }
+case bitc::MODULE_CODE_DEVICES: { // TRIPLE: [strchr x N, ..., strchr x N]
+  std::string S;
+  if (convertToString(Record, 0, S))
+return error("Invalid record");
+  TheModule->setTargetDevices(S);
+  break;
+}
 case bitc::MODULE_CODE_DATALAYOUT: {  // DATALAYOUT: [strchr x N]
   std::string S;
   if (convertToString(Record, 0, S))
Index: lib/Transforms/Utils/CloneModule.cpp
===
--- lib/Transforms/Utils/CloneModule.cpp
+++ lib/Transforms/Utils/CloneModule.cpp
@@ -53,6 +53,7 @@
   New->setSourceFileName(M.getSourceFileName());
   New->setDataLayout(M.getDataLayout());
   New->setTargetTriple(M.getTargetTriple());
+  New->setTargetDevices(M.getTargetDevices());
   New->setModuleInlineAsm(M.getModuleInlineAsm());
 
   // Loop over all of the global variables, making corresponding globals in the
@@ -110,7 +111,7 @@
 GA->copyAttributesFrom(&*I);
 VMap[&*I] = GA;
   }
-  
+
   // Now that all of the things that global variable initializer can refer to
   // have been created, loop through and copy the global variable referrers
   // over...  We also set the attributes on the global now.
Index: lib/AsmParser/LLToken.h
===
--- lib/AsmParser/LLToken.h
+++ lib/AsmParser/LLToken.h
@@ -84,6 +84,7 @@
   kw_notail,
   kw_target,
   kw_triple,
+  kw_device_triples,
   kw_source_filename,
   kw_unwind,
   kw_deplibs, // FIXME: Remove in 4.0
Index: lib/AsmParser/LLLexer.cpp
===
--- lib/AsmParser/LLLexer.cpp
+++ lib/AsmParser/LLLexer.cpp
@@ -533,6 +533,7 @@
   KEYWORD(notail);
   KEYWORD(target);
   KEYWORD(triple);
+  KEYWORD(device_triples);
   KEYWORD(source_filename);
   KEYWORD(unwind);
   KEYWORD(deplibs); // FIXME: Remove in 4.0.
Index: lib/AsmParser/LLParser.cpp
===
--- lib/AsmParser/LLParser.cpp
+++ lib/AsmParser/LLParser.cpp
@@ -322,6 +322,13 @@
   return true;
 M->setTargetTriple(Str);
 return false;
+  case lltok::kw_device_triples:
+Lex.Lex();
+if (ParseToken(lltok::equal, "expected '=' after target devices") ||
+ParseStringConstant(Str))
+  return true;
+M->setTargetDevices(Str);
+return false;
   case lltok::kw_datalayout:
 Lex.Lex();
 if (ParseToken(lltok::equal, "expected '=' after target datalayout") ||
Index: docs/LangRef.rst
===
--- docs/LangRef.rst
+++ docs/LangRef.rst
@@ -2064,6 +2064,25 @@
 code for the proper architecture. It's possible to override this on the
 command line with the ``-mtriple`` command line option.
 
+.. _target_devices_triples:
+
+Devices Triples
+---
+A module may specify comma-separated list of triples that describes the
+OpenMP offloading targets to be supported. The list of triples is denoted
+as devices triple, whose syntax is simply:
+
+.. code-block:: llvm
+
+target device_triples = "x86_64-mic,i386-pc-linux-gnu"
+
+The *devices triples* string consists of a series of subst

[PATCH] D46071: Representing the target device information in the LLVM IR

2018-04-25 Thread Jin Lin via Phabricator via cfe-commits
jinlin updated this revision to Diff 143964.
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D46071

Files:
  lib/CodeGen/ModuleBuilder.cpp


Index: lib/CodeGen/ModuleBuilder.cpp
===
--- lib/CodeGen/ModuleBuilder.cpp
+++ lib/CodeGen/ModuleBuilder.cpp
@@ -131,6 +131,18 @@
   Ctx = &Context;
 
   M->setTargetTriple(Ctx->getTargetInfo().getTriple().getTriple());
+
+  // The target device information is represented as module level
+  // attribute.
+  SmallString<128> Res;
+  for (auto &Device : Ctx->getLangOpts().OMPTargetTriples) {
+if (!Res.empty())
+  Res += ",";
+Res += Device.getTriple();
+  }
+  if (!Res.empty())
+M->setTargetDevices(Res);
+
   M->setDataLayout(Ctx->getTargetInfo().getDataLayout());
   Builder.reset(new CodeGen::CodeGenModule(Context, HeaderSearchOpts,
PreprocessorOpts, CodeGenOpts,


Index: lib/CodeGen/ModuleBuilder.cpp
===
--- lib/CodeGen/ModuleBuilder.cpp
+++ lib/CodeGen/ModuleBuilder.cpp
@@ -131,6 +131,18 @@
   Ctx = &Context;
 
   M->setTargetTriple(Ctx->getTargetInfo().getTriple().getTriple());
+
+  // The target device information is represented as module level
+  // attribute.
+  SmallString<128> Res;
+  for (auto &Device : Ctx->getLangOpts().OMPTargetTriples) {
+if (!Res.empty())
+  Res += ",";
+Res += Device.getTriple();
+  }
+  if (!Res.empty())
+M->setTargetDevices(Res);
+
   M->setDataLayout(Ctx->getTargetInfo().getDataLayout());
   Builder.reset(new CodeGen::CodeGenModule(Context, HeaderSearchOpts,
PreprocessorOpts, CodeGenOpts,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits