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

Jin Lin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 25 10:39:40 PDT 2018


jinlin created this revision.
Herald added subscribers: llvm-commits, mehdi_amini.

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:
  rL LLVM

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46071.143961.patch
Type: text/x-patch
Size: 6699 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180425/535c6d16/attachment.bin>


More information about the llvm-commits mailing list