14
14
// /
15
15
// ===----------------------------------------------------------------------===//
16
16
17
+ #include " clang/Driver/OffloadBundler.h"
17
18
#include " clang/Basic/Cuda.h"
18
19
#include " clang/Basic/TargetID.h"
19
20
#include " clang/Basic/Version.h"
20
- #include " clang/Driver/OffloadBundler.h"
21
21
#include " llvm/ADT/ArrayRef.h"
22
22
#include " llvm/ADT/SmallString.h"
23
23
#include " llvm/ADT/SmallVector.h"
@@ -63,14 +63,13 @@ using namespace clang;
63
63
64
64
OffloadTargetInfo::OffloadTargetInfo (const StringRef Target,
65
65
const OffloadBundlerConfig &BC)
66
- : BundlerConfig(BC) {
66
+ : BundlerConfig(BC) {
67
67
68
68
// TODO: Add error checking from ClangOffloadBundler.cpp
69
69
auto TargetFeatures = Target.split (' :' );
70
70
auto TripleOrGPU = TargetFeatures.first .rsplit (' -' );
71
71
72
- if (clang::StringToCudaArch (TripleOrGPU.second ) !=
73
- clang::CudaArch::UNKNOWN) {
72
+ if (clang::StringToCudaArch (TripleOrGPU.second ) != clang::CudaArch::UNKNOWN) {
74
73
auto KindTriple = TripleOrGPU.first .split (' -' );
75
74
this ->OffloadKind = KindTriple.first ;
76
75
this ->Triple = llvm::Triple (KindTriple.second );
@@ -89,20 +88,19 @@ bool OffloadTargetInfo::hasHostKind() const {
89
88
90
89
bool OffloadTargetInfo::isOffloadKindValid () const {
91
90
return OffloadKind == " host" || OffloadKind == " openmp" ||
92
- OffloadKind == " hip" || OffloadKind == " hipv4" ;
91
+ OffloadKind == " hip" || OffloadKind == " hipv4" ;
93
92
}
94
93
95
94
bool OffloadTargetInfo::isOffloadKindCompatible (
96
- const StringRef TargetOffloadKind) const {
95
+ const StringRef TargetOffloadKind) const {
97
96
if (OffloadKind == TargetOffloadKind)
98
97
return true ;
99
98
if (BundlerConfig.HipOpenmpCompatible ) {
100
- bool HIPCompatibleWithOpenMP =
101
- OffloadKind.startswith_insensitive (" hip" ) &&
102
- TargetOffloadKind == " openmp" ;
99
+ bool HIPCompatibleWithOpenMP = OffloadKind.startswith_insensitive (" hip" ) &&
100
+ TargetOffloadKind == " openmp" ;
103
101
bool OpenMPCompatibleWithHIP =
104
- OffloadKind == " openmp" &&
105
- TargetOffloadKind.startswith_insensitive (" hip" );
102
+ OffloadKind == " openmp" &&
103
+ TargetOffloadKind.startswith_insensitive (" hip" );
106
104
return HIPCompatibleWithOpenMP || OpenMPCompatibleWithHIP;
107
105
}
108
106
return false ;
@@ -670,18 +668,16 @@ class ObjectFileHandler final : public FileHandler {
670
668
InputFile = *TempFileOrErr;
671
669
}
672
670
673
- ObjcopyArgs.push_back (SS.save (Twine (" --add-section=" ) +
674
- OFFLOAD_BUNDLER_MAGIC_STR +
675
- BundlerConfig.TargetNames [I] +
676
- " =" + InputFile));
677
- ObjcopyArgs.push_back (SS.save (Twine (" --set-section-flags=" ) +
678
- OFFLOAD_BUNDLER_MAGIC_STR +
679
- BundlerConfig.TargetNames [I] +
680
- " =readonly,exclude" ));
671
+ ObjcopyArgs.push_back (
672
+ SS.save (Twine (" --add-section=" ) + OFFLOAD_BUNDLER_MAGIC_STR +
673
+ BundlerConfig.TargetNames [I] + " =" + InputFile));
674
+ ObjcopyArgs.push_back (
675
+ SS.save (Twine (" --set-section-flags=" ) + OFFLOAD_BUNDLER_MAGIC_STR +
676
+ BundlerConfig.TargetNames [I] + " =readonly,exclude" ));
681
677
}
682
678
ObjcopyArgs.push_back (" --" );
683
679
ObjcopyArgs.push_back (
684
- BundlerConfig.InputFileNames [BundlerConfig.HostInputIndex ]);
680
+ BundlerConfig.InputFileNames [BundlerConfig.HostInputIndex ]);
685
681
ObjcopyArgs.push_back (BundlerConfig.OutputFileNames .front ());
686
682
687
683
if (Error Err = executeObjcopy (BundlerConfig.ObjcopyPath , ObjcopyArgs))
@@ -884,8 +880,8 @@ CreateFileHandler(MemoryBuffer &FirstInput,
884
880
}
885
881
886
882
// List bundle IDs. Return true if an error was found.
887
- Error OffloadBundler::ListBundleIDsInFile (StringRef InputFileName,
888
- const OffloadBundlerConfig &BundlerConfig) {
883
+ Error OffloadBundler::ListBundleIDsInFile (
884
+ StringRef InputFileName, const OffloadBundlerConfig &BundlerConfig) {
889
885
// Open Input file.
890
886
ErrorOr<std::unique_ptr<MemoryBuffer>> CodeOrErr =
891
887
MemoryBuffer::getFileOrSTDIN (InputFileName);
@@ -910,8 +906,8 @@ Error OffloadBundler::BundleFiles() {
910
906
std::error_code EC;
911
907
912
908
// Create output file.
913
- raw_fd_ostream OutputFile (BundlerConfig.OutputFileNames .front (),
914
- EC, sys::fs::OF_None);
909
+ raw_fd_ostream OutputFile (BundlerConfig.OutputFileNames .front (), EC,
910
+ sys::fs::OF_None);
915
911
if (EC)
916
912
return createFileError (BundlerConfig.OutputFileNames .front (), EC);
917
913
@@ -929,10 +925,10 @@ Error OffloadBundler::BundleFiles() {
929
925
// Get the file handler. We use the host buffer as reference.
930
926
assert ((BundlerConfig.HostInputIndex != ~0u || BundlerConfig.AllowNoHost ) &&
931
927
" Host input index undefined??" );
932
- Expected<std::unique_ptr<FileHandler>> FileHandlerOrErr =
933
- CreateFileHandler ( *InputBuffers[BundlerConfig.AllowNoHost ? 0
934
- : BundlerConfig.HostInputIndex ],
935
- BundlerConfig);
928
+ Expected<std::unique_ptr<FileHandler>> FileHandlerOrErr = CreateFileHandler (
929
+ *InputBuffers[BundlerConfig.AllowNoHost ? 0
930
+ : BundlerConfig.HostInputIndex ],
931
+ BundlerConfig);
936
932
if (!FileHandlerOrErr)
937
933
return FileHandlerOrErr.takeError ();
938
934
@@ -1202,8 +1198,7 @@ Error OffloadBundler::UnbundleArchive() {
1202
1198
auto CodeObjectInfo = OffloadTargetInfo (CodeObject, BundlerConfig);
1203
1199
if (CodeObjectInfo.hasHostKind ()) {
1204
1200
// Do nothing, we don't extract host code yet.
1205
- } else if (getCompatibleOffloadTargets (CodeObjectInfo,
1206
- CompatibleTargets,
1201
+ } else if (getCompatibleOffloadTargets (CodeObjectInfo, CompatibleTargets,
1207
1202
BundlerConfig)) {
1208
1203
std::string BundleData;
1209
1204
raw_string_ostream DataStream (BundleData);
0 commit comments