mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-13 22:48:43 +03:00
Incorporate LTO stuff in GCC ArgsBuilder
This commit is contained in:
parent
9c86ae9ad0
commit
1339c02598
1 changed files with 30 additions and 27 deletions
|
@ -27,13 +27,35 @@ static llvm::cl::opt<std::string>
|
||||||
"LLVMgold.so (Unixes) or libLTO.dylib (Darwin))"),
|
"LLVMgold.so (Unixes) or libLTO.dylib (Darwin))"),
|
||||||
llvm::cl::value_desc("file"));
|
llvm::cl::value_desc("file"));
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
class ArgsBuilder {
|
||||||
|
public:
|
||||||
|
std::vector<std::string> args;
|
||||||
|
|
||||||
|
void build(llvm::StringRef outputPath,
|
||||||
|
llvm::cl::boolOrDefault fullyStaticFlag);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void addSanitizers();
|
||||||
|
void addUserSwitches();
|
||||||
|
void addDefaultLibs();
|
||||||
|
void addArch();
|
||||||
|
|
||||||
|
#if LDC_LLVM_VER >= 309
|
||||||
|
void addLTOGoldPluginFlags();
|
||||||
|
void addDarwinLTOFlags();
|
||||||
|
void addLTOLinkFlags();
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
// LTO functionality
|
// LTO functionality
|
||||||
|
|
||||||
#if LDC_LLVM_VER >= 309
|
#if LDC_LLVM_VER >= 309
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
void addLinkerFlag(std::vector<std::string> &args, const llvm::Twine &flag) {
|
void addLinkerFlag(std::vector<std::string> &args, const llvm::Twine &flag) {
|
||||||
args.push_back("-Xlinker");
|
args.push_back("-Xlinker");
|
||||||
args.push_back(flag.str());
|
args.push_back(flag.str());
|
||||||
|
@ -75,7 +97,7 @@ std::string getLTOGoldPluginPath() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addLTOGoldPluginFlags(std::vector<std::string> &args) {
|
void ArgsBuilder::addLTOGoldPluginFlags() {
|
||||||
addLinkerFlag(args, "-plugin");
|
addLinkerFlag(args, "-plugin");
|
||||||
addLinkerFlag(args, getLTOGoldPluginPath());
|
addLinkerFlag(args, getLTOGoldPluginPath());
|
||||||
|
|
||||||
|
@ -118,7 +140,7 @@ std::string getLTOdylibPath() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addDarwinLTOFlags(std::vector<std::string> &args) {
|
void ArgsBuilder::addDarwinLTOFlags() {
|
||||||
std::string dylibPath = getLTOdylibPath();
|
std::string dylibPath = getLTOdylibPath();
|
||||||
if (!dylibPath.empty()) {
|
if (!dylibPath.empty()) {
|
||||||
args.push_back("-lto_library");
|
args.push_back("-lto_library");
|
||||||
|
@ -127,42 +149,23 @@ void addDarwinLTOFlags(std::vector<std::string> &args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds the required linker flags for LTO builds to args.
|
/// Adds the required linker flags for LTO builds to args.
|
||||||
void addLTOLinkFlags(std::vector<std::string> &args) {
|
void ArgsBuilder::addLTOLinkFlags() {
|
||||||
if (global.params.targetTriple->isOSLinux() ||
|
if (global.params.targetTriple->isOSLinux() ||
|
||||||
global.params.targetTriple->isOSFreeBSD() ||
|
global.params.targetTriple->isOSFreeBSD() ||
|
||||||
global.params.targetTriple->isOSNetBSD() ||
|
global.params.targetTriple->isOSNetBSD() ||
|
||||||
global.params.targetTriple->isOSOpenBSD() ||
|
global.params.targetTriple->isOSOpenBSD() ||
|
||||||
global.params.targetTriple->isOSDragonFly()) {
|
global.params.targetTriple->isOSDragonFly()) {
|
||||||
// Assume that ld.gold or ld.bfd is used with plugin support.
|
// Assume that ld.gold or ld.bfd is used with plugin support.
|
||||||
addLTOGoldPluginFlags(args);
|
addLTOGoldPluginFlags();
|
||||||
} else if (global.params.targetTriple->isOSDarwin()) {
|
} else if (global.params.targetTriple->isOSDarwin()) {
|
||||||
addDarwinLTOFlags(args);
|
addDarwinLTOFlags();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // anonymous namespace
|
|
||||||
|
|
||||||
#endif // LDC_LLVM_VER >= 309
|
#endif // LDC_LLVM_VER >= 309
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
class ArgsBuilder {
|
|
||||||
public:
|
|
||||||
std::vector<std::string> args;
|
|
||||||
|
|
||||||
void build(llvm::StringRef outputPath,
|
|
||||||
llvm::cl::boolOrDefault fullyStaticFlag);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void addSanitizers();
|
|
||||||
void addUserSwitches();
|
|
||||||
void addDefaultLibs();
|
|
||||||
void addArch();
|
|
||||||
};
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
void ArgsBuilder::build(llvm::StringRef outputPath,
|
void ArgsBuilder::build(llvm::StringRef outputPath,
|
||||||
llvm::cl::boolOrDefault fullyStaticFlag) {
|
llvm::cl::boolOrDefault fullyStaticFlag) {
|
||||||
// object files
|
// object files
|
||||||
|
@ -205,7 +208,7 @@ void ArgsBuilder::build(llvm::StringRef outputPath,
|
||||||
// Add LTO link flags before adding the user link switches, such that the user
|
// Add LTO link flags before adding the user link switches, such that the user
|
||||||
// can pass additional options to the LTO plugin.
|
// can pass additional options to the LTO plugin.
|
||||||
if (opts::isUsingLTO())
|
if (opts::isUsingLTO())
|
||||||
addLTOLinkFlags(args);
|
addLTOLinkFlags();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
addUserSwitches();
|
addUserSwitches();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue