@@ -152,14 +152,12 @@ void tools::AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
152152 addDirectoryList (Args, CmdArgs, " -L" , " LIBRARY_PATH" );
153153
154154 for (const auto &II : Inputs) {
155- // If the current tool chain refers to an OpenMP or HIP offloading host, we
156- // should ignore inputs that refer to OpenMP or HIP offloading devices -
155+ // If the current tool chain refers to an OpenMP offloading host, we
156+ // should ignore inputs that refer to OpenMP offloading devices -
157157 // they will be embedded according to a proper linker script.
158158 if (auto *IA = II.getAction ())
159159 if ((JA.isHostOffloading (Action::OFK_OpenMP) &&
160- IA->isDeviceOffloading (Action::OFK_OpenMP)) ||
161- (JA.isHostOffloading (Action::OFK_HIP) &&
162- IA->isDeviceOffloading (Action::OFK_HIP)))
160+ IA->isDeviceOffloading (Action::OFK_OpenMP)))
163161 continue ;
164162
165163 if (!TC.HasNativeLLVMSupport () && types::isLLVMIR (II.getType ()))
@@ -1298,115 +1296,6 @@ void tools::AddRunTimeLibs(const ToolChain &TC, const Driver &D,
12981296 }
12991297}
13001298
1301- // / Add HIP linker script arguments at the end of the argument list so that
1302- // / the fat binary is built by embedding the device images into the host. The
1303- // / linker script also defines a symbol required by the code generation so that
1304- // / the image can be retrieved at runtime. This should be used only in tool
1305- // / chains that support linker scripts.
1306- void tools::AddHIPLinkerScript (const ToolChain &TC, Compilation &C,
1307- const InputInfo &Output,
1308- const InputInfoList &Inputs, const ArgList &Args,
1309- ArgStringList &CmdArgs, const JobAction &JA,
1310- const Tool &T) {
1311-
1312- // If this is not a HIP host toolchain, we don't need to do anything.
1313- if (!JA.isHostOffloading (Action::OFK_HIP))
1314- return ;
1315-
1316- InputInfoList DeviceInputs;
1317- for (const auto &II : Inputs) {
1318- const Action *A = II.getAction ();
1319- // Is this a device linking action?
1320- if (A && isa<LinkJobAction>(A) && A->isDeviceOffloading (Action::OFK_HIP)) {
1321- DeviceInputs.push_back (II);
1322- }
1323- }
1324-
1325- if (DeviceInputs.empty ())
1326- return ;
1327-
1328- // Create temporary linker script. Keep it if save-temps is enabled.
1329- const char *LKS;
1330- std::string Name =
1331- std::string (llvm::sys::path::filename (Output.getFilename ()));
1332- if (C.getDriver ().isSaveTempsEnabled ()) {
1333- LKS = C.getArgs ().MakeArgString (Name + " .lk" );
1334- } else {
1335- auto TmpName = C.getDriver ().GetTemporaryPath (Name, " lk" );
1336- LKS = C.addTempFile (C.getArgs ().MakeArgString (TmpName));
1337- }
1338-
1339- // Add linker script option to the command.
1340- CmdArgs.push_back (" -T" );
1341- CmdArgs.push_back (LKS);
1342-
1343- // Create a buffer to write the contents of the linker script.
1344- std::string LksBuffer;
1345- llvm::raw_string_ostream LksStream (LksBuffer);
1346-
1347- // Get the HIP offload tool chain.
1348- auto *HIPTC = static_cast <const toolchains::HIPToolChain *>(
1349- C.getSingleOffloadToolChain <Action::OFK_HIP>());
1350- assert (HIPTC->getTriple ().getArch () == llvm::Triple::amdgcn &&
1351- " Wrong platform" );
1352- (void )HIPTC;
1353-
1354- const char *BundleFile;
1355- if (C.getDriver ().isSaveTempsEnabled ()) {
1356- BundleFile = C.getArgs ().MakeArgString (Name + " .hipfb" );
1357- } else {
1358- auto TmpName = C.getDriver ().GetTemporaryPath (Name, " hipfb" );
1359- BundleFile = C.addTempFile (C.getArgs ().MakeArgString (TmpName));
1360- }
1361- AMDGCN::constructHIPFatbinCommand (C, JA, BundleFile, DeviceInputs, Args, T);
1362-
1363- // Add commands to embed target binaries. We ensure that each section and
1364- // image is 16-byte aligned. This is not mandatory, but increases the
1365- // likelihood of data to be aligned with a cache block in several main host
1366- // machines.
1367- LksStream << " /*\n " ;
1368- LksStream << " HIP Offload Linker Script\n " ;
1369- LksStream << " *** Automatically generated by Clang ***\n " ;
1370- LksStream << " */\n " ;
1371- LksStream << " TARGET(binary)\n " ;
1372- LksStream << " INPUT(" << BundleFile << " )\n " ;
1373- LksStream << " SECTIONS\n " ;
1374- LksStream << " {\n " ;
1375- LksStream << " .hip_fatbin :\n " ;
1376- LksStream << " ALIGN(0x10)\n " ;
1377- LksStream << " {\n " ;
1378- LksStream << " PROVIDE_HIDDEN(__hip_fatbin = .);\n " ;
1379- LksStream << " " << BundleFile << " \n " ;
1380- LksStream << " }\n " ;
1381- LksStream << " /DISCARD/ :\n " ;
1382- LksStream << " {\n " ;
1383- LksStream << " * ( __CLANG_OFFLOAD_BUNDLE__* )\n " ;
1384- LksStream << " }\n " ;
1385- LksStream << " }\n " ;
1386- LksStream << " INSERT BEFORE .data\n " ;
1387- LksStream.flush ();
1388-
1389- // Dump the contents of the linker script if the user requested that. We
1390- // support this option to enable testing of behavior with -###.
1391- if (C.getArgs ().hasArg (options::OPT_fhip_dump_offload_linker_script))
1392- llvm::errs () << LksBuffer;
1393-
1394- // If this is a dry run, do not create the linker script file.
1395- if (C.getArgs ().hasArg (options::OPT__HASH_HASH_HASH))
1396- return ;
1397-
1398- // Open script file and write the contents.
1399- std::error_code EC;
1400- llvm::raw_fd_ostream Lksf (LKS, EC, llvm::sys::fs::OF_None);
1401-
1402- if (EC) {
1403- C.getDriver ().Diag (clang::diag::err_unable_to_make_temp) << EC.message ();
1404- return ;
1405- }
1406-
1407- Lksf << LksBuffer;
1408- }
1409-
14101299SmallString<128 > tools::getStatsFileName (const llvm::opt::ArgList &Args,
14111300 const InputInfo &Output,
14121301 const InputInfo &Input,
0 commit comments