aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-04-19 06:27:11 +0200
committerGravatar Klaus Aehlig <aehlig@google.com>2017-04-19 10:51:22 +0200
commitbb752ad0d85c9bfcb1359f091e956ab88544a7ef (patch)
tree55a992677ae867122f48a46a0508620a8a00409f /src/main/java
parentcdcd27cb17ff16cca428d5269cbd5dd41fba39bf (diff)
Support using minimized bitcode for ThinLTO LTO indexing step
This is the Blaze side of the support for emitting and using minimized bitcode files during the LTO indexing (thin link) step of a ThinLTO build. The llvm support has already been released to stable, and this needs to be submitted after the companion Crosstool support (unknown commit, will send for review once this larger part is reviewed). This enables large applications successfully build using ThinLTO and -g, otherwise the bitcode files that are input to the LTO indexing step are huge and the maximum input size is exceeded. PiperOrigin-RevId: 153549687
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationOutputs.java27
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java12
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java9
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java101
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java46
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java1
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/LinkerInputs.java29
9 files changed, 176 insertions, 58 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationOutputs.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationOutputs.java
index f70a4ed28b..4b48783ccf 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationOutputs.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationOutputs.java
@@ -15,6 +15,7 @@
package com.google.devtools.build.lib.rules.cpp;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
@@ -41,9 +42,10 @@ public class CcCompilationOutputs {
private final ImmutableList<Artifact> picObjectFiles;
/**
- * All .o files coming from a C(++) compilation under our control.
+ * Maps all .o bitcode files coming from a ThinLTO C(++) compilation under our control to the
+ * corresponding minimized bitcode files that can be used for the LTO indexing step.
*/
- private final ImmutableList<Artifact> ltoBitcodeFiles;
+ private final ImmutableMap<Artifact, Artifact> ltoBitcodeFiles;
/**
* All .dwo files built by the target, corresponding to .o outputs.
@@ -70,8 +72,7 @@ public class CcCompilationOutputs {
private CcCompilationOutputs(
ImmutableList<Artifact> objectFiles,
ImmutableList<Artifact> picObjectFiles,
- ImmutableList<Artifact> ltoBitcodeFiles,
-
+ ImmutableMap<Artifact, Artifact> ltoBitcodeFiles,
ImmutableList<Artifact> dwoFiles,
ImmutableList<Artifact> picDwoFiles,
NestedSet<Artifact> temps,
@@ -103,10 +104,8 @@ public class CcCompilationOutputs {
return usePic ? picObjectFiles : objectFiles;
}
- /**
- * Returns unmodifiable view of object files resulting from compilation.
- */
- public ImmutableList<Artifact> getLtoBitcodeFiles() {
+ /** Returns unmodifiable map of bitcode object files resulting from compilation. */
+ public ImmutableMap<Artifact, Artifact> getLtoBitcodeFiles() {
return ltoBitcodeFiles;
}
@@ -166,7 +165,7 @@ public class CcCompilationOutputs {
public static final class Builder {
private final Set<Artifact> objectFiles = new LinkedHashSet<>();
private final Set<Artifact> picObjectFiles = new LinkedHashSet<>();
- private final Set<Artifact> ltoBitcodeFiles = new LinkedHashSet<>();
+ private final ImmutableMap.Builder<Artifact, Artifact> ltoBitcodeFiles = ImmutableMap.builder();
private final Set<Artifact> dwoFiles = new LinkedHashSet<>();
private final Set<Artifact> picDwoFiles = new LinkedHashSet<>();
private final NestedSetBuilder<Artifact> temps = NestedSetBuilder.stableOrder();
@@ -177,7 +176,7 @@ public class CcCompilationOutputs {
return new CcCompilationOutputs(
ImmutableList.copyOf(objectFiles),
ImmutableList.copyOf(picObjectFiles),
- ImmutableList.copyOf(ltoBitcodeFiles),
+ ltoBitcodeFiles.build(),
ImmutableList.copyOf(dwoFiles),
ImmutableList.copyOf(picDwoFiles),
temps.build(),
@@ -224,13 +223,13 @@ public class CcCompilationOutputs {
return this;
}
- public Builder addLTOBitcodeFile(Artifact a) {
- ltoBitcodeFiles.add(a);
+ public Builder addLTOBitcodeFile(Artifact fullBitcode, Artifact ltoIndexingBitcode) {
+ ltoBitcodeFiles.put(fullBitcode, ltoIndexingBitcode);
return this;
}
- public Builder addLTOBitcodeFile(Iterable<Artifact> artifacts) {
- Iterables.addAll(ltoBitcodeFiles, artifacts);
+ public Builder addLTOBitcodeFile(ImmutableMap<Artifact, Artifact> artifacts) {
+ ltoBitcodeFiles.putAll(artifacts);
return this;
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java
index 305a6b39ee..2593881203 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java
@@ -293,6 +293,7 @@ public class CppCompileAction extends AbstractAction
DotdFile dotdFile,
@Nullable Artifact gcnoFile,
@Nullable Artifact dwoFile,
+ @Nullable Artifact ltoIndexingFile,
Artifact optionalSourceFile,
ImmutableMap<String, String> localShellEnvironment,
CppConfiguration cppConfiguration,
@@ -313,7 +314,11 @@ public class CppCompileAction extends AbstractAction
owner,
allInputs,
CollectionUtils.asListWithoutNulls(
- outputFile, (dotdFile == null ? null : dotdFile.artifact()), gcnoFile, dwoFile));
+ outputFile,
+ (dotdFile == null ? null : dotdFile.artifact()),
+ gcnoFile,
+ dwoFile,
+ ltoIndexingFile));
this.localShellEnvironment = localShellEnvironment;
this.sourceLabel = sourceLabel;
this.sourceFile = sourceFile;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java
index 2b7669f17b..693970c42e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java
@@ -61,6 +61,7 @@ public class CppCompileActionBuilder {
private Artifact optionalSourceFile;
private Artifact outputFile;
private Artifact dwoFile;
+ private Artifact ltoIndexingFile;
private PathFragment tempOutputFile;
private DotdFile dotdFile;
private Artifact gcnoFile;
@@ -168,6 +169,7 @@ public class CppCompileActionBuilder {
this.optionalSourceFile = other.optionalSourceFile;
this.outputFile = other.outputFile;
this.dwoFile = other.dwoFile;
+ this.ltoIndexingFile = other.ltoIndexingFile;
this.tempOutputFile = other.tempOutputFile;
this.dotdFile = other.dotdFile;
this.gcnoFile = other.gcnoFile;
@@ -404,6 +406,7 @@ public class CppCompileActionBuilder {
dotdFile,
gcnoFile,
dwoFile,
+ ltoIndexingFile,
optionalSourceFile,
localShellEnvironment,
cppConfiguration,
@@ -605,6 +608,15 @@ public class CppCompileActionBuilder {
return this;
}
+ /**
+ * Set the minimized bitcode file emitted by this (ThinLTO) compilation that can be used in place
+ * of the full bitcode outputFile in the LTO indexing step.
+ */
+ public CppCompileActionBuilder setLTOIndexingFile(Artifact ltoIndexingFile) {
+ this.ltoIndexingFile = ltoIndexingFile;
+ return this;
+ }
+
Artifact getOutputFile() {
return outputFile;
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java
index b819aae443..eb0de2cd29 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java
@@ -127,6 +127,8 @@ public final class CppFileTypes {
}
};
+ // Minimized bitcode file emitted by the ThinLTO compile step and used just for LTO indexing.
+ public static final FileType LTO_INDEXING_OBJECT_FILE = FileType.of(".indexing.o");
public static final FileType SHARED_LIBRARY = FileType.of(".so", ".dylib", ".dll");
public static final FileType INTERFACE_SHARED_LIBRARY = FileType.of(".ifso");
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java
index f11891df8c..1f80548f02 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java
@@ -552,7 +552,7 @@ public final class CppLinkAction extends AbstractAction
final ImmutableSet<Artifact> nonCodeInputs;
final NestedSet<LibraryToLink> libraries;
final NestedSet<Artifact> crosstoolInputs;
- final ImmutableList<Artifact> ltoBitcodeFiles;
+ final ImmutableMap<Artifact, Artifact> ltoBitcodeFiles;
final Artifact runtimeMiddleman;
final NestedSet<Artifact> runtimeInputs;
final ArtifactCategory runtimeType;
@@ -578,7 +578,7 @@ public final class CppLinkAction extends AbstractAction
.addTransitive(builder.getLibraries().build()).build();
this.crosstoolInputs =
NestedSetBuilder.<Artifact>stableOrder().addTransitive(builder.getCrosstoolInputs()).build();
- this.ltoBitcodeFiles = ImmutableList.copyOf(builder.getLtoBitcodeFiles());
+ this.ltoBitcodeFiles = ImmutableMap.copyOf(builder.getLtoBitcodeFiles());
this.runtimeMiddleman = builder.getRuntimeMiddleman();
this.runtimeInputs =
NestedSetBuilder.<Artifact>stableOrder().addTransitive(builder.getRuntimeInputs()).build();
@@ -615,11 +615,6 @@ public final class CppLinkAction extends AbstractAction
return this.crosstoolInputs;
}
- /** Returns linker inputs that are lto bitcode files. */
- public ImmutableList<Artifact> getLtoBitcodeFiles() {
- return this.ltoBitcodeFiles;
- }
-
/**
* Returns the runtime middleman artifact.
*/
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java
index fe8989b8cc..b2a67113f8 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java
@@ -87,6 +87,13 @@ public class CppLinkActionBuilder {
public static final String THINLTO_PREFIX_REPLACE_VARIABLE = "thinlto_prefix_replace";
/**
+ * A build variable to let the LTO indexing step know how to map from the minimized bitcode file
+ * to the full bitcode file used by the LTO Backends.
+ */
+ public static final String THINLTO_OBJECT_SUFFIX_REPLACE_VARIABLE =
+ "thinlto_object_suffix_replace";
+
+ /**
* A build variable for linker param file created by Bazel to overcome the command line length
* limit.
*/
@@ -175,7 +182,7 @@ public class CppLinkActionBuilder {
private LinkTargetType linkType = LinkTargetType.STATIC_LIBRARY;
private LinkStaticness linkStaticness = LinkStaticness.FULLY_STATIC;
private String libraryIdentifier = null;
- private List<Artifact> ltoBitcodeFiles = new ArrayList<>();
+ private ImmutableMap<Artifact, Artifact> ltoBitcodeFiles;
private boolean fake;
private boolean isNativeDeps;
@@ -296,7 +303,7 @@ public class CppLinkActionBuilder {
this.nonCodeInputs.addAll(linkContext.nonCodeInputs);
this.libraries.addTransitive(linkContext.libraries);
this.crosstoolInputs = linkContext.crosstoolInputs;
- this.ltoBitcodeFiles.addAll(linkContext.ltoBitcodeFiles);
+ this.ltoBitcodeFiles = linkContext.ltoBitcodeFiles;
this.runtimeMiddleman = linkContext.runtimeMiddleman;
this.runtimeInputs = linkContext.runtimeInputs;
this.runtimeType = linkContext.runtimeType;
@@ -396,9 +403,10 @@ public class CppLinkActionBuilder {
return this.linkStaticness;
}
/**
- * Returns lto bitcode files for this link action.
+ * Returns linker inputs that are lto bitcode files in a map from the full bitcode file used by
+ * the LTO Backend to the minimized bitcode used by the LTO indexing.
*/
- public List<Artifact> getLtoBitcodeFiles() {
+ public ImmutableMap<Artifact, Artifact> getLtoBitcodeFiles() {
return this.ltoBitcodeFiles;
}
@@ -428,11 +436,54 @@ public class CppLinkActionBuilder {
return this.useTestOnlyFlags;
}
+ /**
+ * Maps bitcode object files used by the LTO backends to the corresponding minimized bitcode file
+ * used as input to the LTO indexing step.
+ */
+ private ImmutableSet<LinkerInput> computeLTOIndexingObjectFileInputs() {
+ ImmutableSet.Builder<LinkerInput> objectFileInputsBuilder = ImmutableSet.<LinkerInput>builder();
+ for (LinkerInput input : objectFiles) {
+ Artifact objectFile = input.getArtifact();
+ objectFileInputsBuilder.add(
+ LinkerInputs.simpleLinkerInput(
+ this.ltoBitcodeFiles.getOrDefault(objectFile, objectFile),
+ ArtifactCategory.OBJECT_FILE));
+ }
+ return objectFileInputsBuilder.build();
+ }
+
+ /**
+ * Maps bitcode library files used by the LTO backends to the corresponding minimized bitcode file
+ * used as input to the LTO indexing step.
+ */
+ private static NestedSet<LibraryToLink> computeLTOIndexingUniqueLibraries(
+ NestedSet<LibraryToLink> originalUniqueLibraries) {
+ NestedSetBuilder<LibraryToLink> uniqueLibrariesBuilder = NestedSetBuilder.linkOrder();
+ for (LibraryToLink lib : originalUniqueLibraries) {
+ if (!lib.containsObjectFiles()) {
+ uniqueLibrariesBuilder.add(lib);
+ continue;
+ }
+ ImmutableSet.Builder<Artifact> newObjectFilesBuilder = ImmutableSet.<Artifact>builder();
+ for (Artifact a : lib.getObjectFiles()) {
+ newObjectFilesBuilder.add(lib.getLTOBitcodeFiles().getOrDefault(a, a));
+ }
+ uniqueLibrariesBuilder.add(
+ LinkerInputs.newInputLibrary(
+ lib.getArtifact(),
+ lib.getArtifactCategory(),
+ lib.getLibraryIdentifier(),
+ newObjectFilesBuilder.build(),
+ lib.getLTOBitcodeFiles()));
+ }
+ return uniqueLibrariesBuilder.build();
+ }
+
private Iterable<LTOBackendArtifacts> createLTOArtifacts(
PathFragment ltoOutputRootPrefix, NestedSet<LibraryToLink> uniqueLibraries) {
Set<Artifact> compiled = new LinkedHashSet<>();
for (LibraryToLink lib : uniqueLibraries) {
- Iterables.addAll(compiled, lib.getLTOBitcodeFiles());
+ compiled.addAll(lib.getLTOBitcodeFiles().keySet());
}
// This flattens the set of object files, so for M binaries and N .o files,
@@ -449,7 +500,7 @@ public class CppLinkActionBuilder {
}
}
for (LinkerInput input : objectFiles) {
- if (this.ltoBitcodeFiles.contains(input.getArtifact())) {
+ if (this.ltoBitcodeFiles.containsKey(input.getArtifact())) {
allBitcode.put(input.getArtifact().getExecPath(), input.getArtifact());
}
}
@@ -512,12 +563,25 @@ public class CppLinkActionBuilder {
wholeArchive
|| needWholeArchive(linkStaticness, linkType, linkopts, isNativeDeps, cppConfiguration);
- NestedSet<LibraryToLink> uniqueLibraries = libraries.build();
- final Iterable<Artifact> objectArtifacts = LinkerInputs.toLibraryArtifacts(objectFiles);
+ NestedSet<LibraryToLink> originalUniqueLibraries = libraries.build();
+
+ // Get the set of object files and libraries containing the correct
+ // inputs for this link, depending on whether this is LTO indexing or
+ // a native link.
+ NestedSet<LibraryToLink> uniqueLibraries;
+ ImmutableSet<LinkerInput> objectFileInputs;
+ if (isLTOIndexing) {
+ objectFileInputs = computeLTOIndexingObjectFileInputs();
+ uniqueLibraries = computeLTOIndexingUniqueLibraries(originalUniqueLibraries);
+ } else {
+ objectFileInputs = ImmutableSet.copyOf(objectFiles);
+ uniqueLibraries = originalUniqueLibraries;
+ }
+ final Iterable<Artifact> objectArtifacts = LinkerInputs.toLibraryArtifacts(objectFileInputs);
final Iterable<LinkerInput> linkerInputs =
IterablesChain.<LinkerInput>builder()
- .add(ImmutableList.copyOf(objectFiles))
+ .add(objectFileInputs)
.add(
ImmutableIterable.from(
Link.mergeInputsCmdLine(
@@ -561,7 +625,10 @@ public class CppLinkActionBuilder {
ltoOutputRootPrefix =
FileSystemUtils.appendExtension(
output.getRootRelativePath(), ".lto");
- allLTOArtifacts = createLTOArtifacts(ltoOutputRootPrefix, uniqueLibraries);
+ // Use the originalUniqueLibraries which contains the full bitcode files
+ // needed by the LTO backends (as opposed to the minimized bitcode files
+ // that can be used by the LTO indexing step).
+ allLTOArtifacts = createLTOArtifacts(ltoOutputRootPrefix, originalUniqueLibraries);
}
PathFragment linkerParamFileRootPath = null;
@@ -718,7 +785,7 @@ public class CppLinkActionBuilder {
LinkerInputs.toLibraryArtifacts(
Link.mergeInputsDependencies(
uniqueLibraries, needWholeArchive, cppConfiguration.archiveType()));
- Iterable<Artifact> expandedNonLibraryInputs = LinkerInputs.toLibraryArtifacts(objectFiles);
+ Iterable<Artifact> expandedNonLibraryInputs = LinkerInputs.toLibraryArtifacts(objectFileInputs);
if (!isLTOIndexing && allLTOArtifacts != null) {
// We are doing LTO, and this is the real link, so substitute
@@ -1007,10 +1074,9 @@ public class CppLinkActionBuilder {
this.objectFiles.add(input);
}
- public CppLinkActionBuilder addLTOBitcodeFiles(Iterable<Artifact> files) {
- for (Artifact a : files) {
- ltoBitcodeFiles.add(a);
- }
+ public CppLinkActionBuilder addLTOBitcodeFiles(ImmutableMap<Artifact, Artifact> files) {
+ Preconditions.checkState(ltoBitcodeFiles == null);
+ ltoBitcodeFiles = files;
return this;
}
@@ -1414,6 +1480,11 @@ public class CppLinkActionBuilder {
configuration.getBinDirectory().getExecPathString()
+ ";"
+ configuration.getBinDirectory().getExecPath().getRelative(ltoOutputRootPrefix));
+ buildVariables.addStringVariable(
+ THINLTO_OBJECT_SUFFIX_REPLACE_VARIABLE,
+ Iterables.getOnlyElement(CppFileTypes.LTO_INDEXING_OBJECT_FILE.getExtensions())
+ + ";"
+ + Iterables.getOnlyElement(CppFileTypes.OBJECT_FILE.getExtensions()));
} else {
if (thinltoParamFile != null) {
// This is a normal link action and we need to use param file created by lto-indexing.
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java
index 1acc9b4909..c3702dbc0e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java
@@ -17,6 +17,7 @@ package com.google.devtools.build.lib.rules.cpp;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.FailAction;
import com.google.devtools.build.lib.analysis.AnalysisEnvironment;
@@ -111,6 +112,11 @@ public final class CppModel {
return ruleContext.getRelatedArtifact(outputFile.getRootRelativePath(), ".dwo");
}
+ private Artifact getLTOIndexingFile(Artifact outputFile) {
+ String ext = Iterables.getOnlyElement(CppFileTypes.LTO_INDEXING_OBJECT_FILE.getExtensions());
+ return ruleContext.getRelatedArtifact(outputFile.getRootRelativePath(), ext);
+ }
+
/**
* If the cpp compilation is a fake, then it creates only a single compile action without PIC.
* Defaults to false.
@@ -371,6 +377,7 @@ public final class CppModel {
PathFragment autoFdoImportPath,
Artifact gcnoFile,
Artifact dwoFile,
+ Artifact ltoIndexingFile,
CppModuleMap cppModuleMap,
Map<String, String> sourceSpecificBuildVariables) {
CcToolchainFeatures.Variables.Builder buildVariables =
@@ -473,6 +480,11 @@ public final class CppModel {
buildVariables.addStringVariable("per_object_debug_info_file", dwoFile.getExecPathString());
}
+ if (ltoIndexingFile != null) {
+ buildVariables.addStringVariable(
+ "lto_indexing_bitcode_file", ltoIndexingFile.getExecPathString());
+ }
+
buildVariables.addAllStringVariables(ccToolchain.getBuildVariables());
buildVariables.addAllStringVariables(sourceSpecificBuildVariables);
@@ -594,6 +606,7 @@ public final class CppModel {
/*autoFdoImportPath=*/ null,
/*gcnoFile=*/ null,
/*dwoFile=*/ null,
+ /*ltoIndexingFile=*/ null,
builder.getContext().getCppModuleMap(),
ImmutableMap.<String, String>of());
semantics.finalizeCompileActionBuilder(ruleContext, builder);
@@ -639,6 +652,11 @@ public final class CppModel {
boolean generateDwo = cppConfiguration.useFission();
Artifact dwoFile = generateDwo ? getDwoFile(builder.getOutputFile()) : null;
+ // TODO(tejohnson): Add support for ThinLTO if needed.
+ boolean bitcodeOutput =
+ featureConfiguration.isEnabled(CppRuleClasses.THIN_LTO)
+ && CppFileTypes.LTO_SOURCE.matches(module.getFilename());
+ Preconditions.checkState(!bitcodeOutput);
setupCompileBuildVariables(
builder,
@@ -647,6 +665,7 @@ public final class CppModel {
module.getExecPath(),
gcnoFile,
dwoFile,
+ /*ltoIndexingFile=*/ null,
builder.getContext().getCppModuleMap(),
ImmutableMap.<String, String>of());
@@ -709,6 +728,7 @@ public final class CppModel {
/*autoFdoImportPath=*/ null,
/*gcnoFile=*/ null,
/*dwoFile=*/ null,
+ /*ltoIndexingFile=*/ null,
builder.getContext().getCppModuleMap(),
/*sourceSpecificBuildVariables=*/ ImmutableMap.<String, String>of());
semantics.finalizeCompileActionBuilder(ruleContext, builder);
@@ -749,6 +769,10 @@ public final class CppModel {
createFakeSourceAction(outputName, result, env, builder, outputCategory, addObject,
ccRelativeName, sourceArtifact.getExecPath(), usePic, generateDotd);
} else {
+ boolean bitcodeOutput =
+ featureConfiguration.isEnabled(CppRuleClasses.THIN_LTO)
+ && CppFileTypes.LTO_SOURCE.matches(sourceArtifact.getFilename());
+
// Create PIC compile actions (same as non-PIC, but use -fPIC and
// generate .pic.o, .pic.d, .pic.gcno instead of .o, .d, .gcno.)
if (generatePicAction) {
@@ -762,6 +786,8 @@ public final class CppModel {
? CppHelper.getCompileOutputArtifact(ruleContext, gcnoFileName, configuration)
: null;
Artifact dwoFile = generateDwo ? getDwoFile(picBuilder.getOutputFile()) : null;
+ Artifact ltoIndexingFile =
+ bitcodeOutput ? getLTOIndexingFile(picBuilder.getOutputFile()) : null;
setupCompileBuildVariables(
picBuilder,
@@ -770,6 +796,7 @@ public final class CppModel {
sourceArtifact.getExecPath(),
gcnoFile,
dwoFile,
+ ltoIndexingFile,
cppModuleMap,
sourceSpecificBuildVariables);
@@ -781,6 +808,7 @@ public final class CppModel {
picBuilder.setGcnoFile(gcnoFile);
picBuilder.setDwoFile(dwoFile);
+ picBuilder.setLTOIndexingFile(ltoIndexingFile);
semantics.finalizeCompileActionBuilder(ruleContext, picBuilder);
CppCompileAction picAction = picBuilder.buildAndValidate(ruleContext);
@@ -789,9 +817,8 @@ public final class CppModel {
if (addObject) {
result.addPicObjectFile(picAction.getOutputFile());
- if (featureConfiguration.isEnabled(CppRuleClasses.THIN_LTO)
- && CppFileTypes.LTO_SOURCE.matches(sourceArtifact.getFilename())) {
- result.addLTOBitcodeFile(picAction.getOutputFile());
+ if (bitcodeOutput) {
+ result.addLTOBitcodeFile(picAction.getOutputFile(), ltoIndexingFile);
}
}
if (dwoFile != null) {
@@ -820,6 +847,8 @@ public final class CppModel {
: null;
Artifact noPicDwoFile = generateDwo ? getDwoFile(noPicOutputFile) : null;
+ Artifact ltoIndexingFile =
+ bitcodeOutput ? getLTOIndexingFile(builder.getOutputFile()) : null;
setupCompileBuildVariables(
builder,
@@ -828,6 +857,7 @@ public final class CppModel {
sourceArtifact.getExecPath(),
gcnoFile,
noPicDwoFile,
+ ltoIndexingFile,
cppModuleMap,
sourceSpecificBuildVariables);
@@ -844,6 +874,7 @@ public final class CppModel {
builder.setGcnoFile(gcnoFile);
builder.setDwoFile(noPicDwoFile);
+ builder.setLTOIndexingFile(ltoIndexingFile);
semantics.finalizeCompileActionBuilder(ruleContext, builder);
CppCompileAction compileAction = builder.buildAndValidate(ruleContext);
@@ -852,9 +883,8 @@ public final class CppModel {
directOutputs.add(objectFile);
if (addObject) {
result.addObjectFile(objectFile);
- if (featureConfiguration.isEnabled(CppRuleClasses.THIN_LTO)
- && CppFileTypes.LTO_SOURCE.matches(sourceArtifact.getFilename())) {
- result.addLTOBitcodeFile(objectFile);
+ if (bitcodeOutput) {
+ result.addLTOBitcodeFile(objectFile, ltoIndexingFile);
}
}
if (noPicDwoFile != null) {
@@ -883,6 +913,7 @@ public final class CppModel {
/*autoFdoImportPath=*/ null,
/*gcnoFile=*/ null,
/*dwoFile=*/ null,
+ /*ltoIndexingFile=*/ null,
builder.getContext().getCppModuleMap(),
source.getBuildVariables());
semantics.finalizeCompileActionBuilder(ruleContext, builder);
@@ -928,6 +959,7 @@ public final class CppModel {
execPath,
/*gcnoFile=*/ null,
/*dwoFile=*/ null,
+ /*ltoIndexingFile=*/ null,
builder.getContext().getCppModuleMap(),
ImmutableMap.<String, String>of());
semantics.finalizeCompileActionBuilder(ruleContext, builder);
@@ -1263,6 +1295,7 @@ public final class CppModel {
source.getExecPath(),
null,
null,
+ /*ltoIndexingFile=*/ null,
builder.getContext().getCppModuleMap(),
ImmutableMap.<String, String>of());
semantics.finalizeCompileActionBuilder(ruleContext, dBuilder);
@@ -1279,6 +1312,7 @@ public final class CppModel {
source.getExecPath(),
null,
null,
+ /*ltoIndexingFile=*/ null,
builder.getContext().getCppModuleMap(),
ImmutableMap.<String, String>of());
semantics.finalizeCompileActionBuilder(ruleContext, sdBuilder);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java
index 9fac16bb5e..720c9d24a6 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java
@@ -102,6 +102,7 @@ public class FakeCppCompileAction extends CppCompileAction {
null,
null,
null,
+ null,
localShellEnvironment,
cppConfiguration,
// We only allow inclusion of header files explicitly declared in
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkerInputs.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkerInputs.java
index bb65c34002..fd3dce6dee 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkerInputs.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkerInputs.java
@@ -15,7 +15,7 @@
package com.google.devtools.build.lib.rules.cpp;
import com.google.common.base.Function;
-import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.collect.CollectionUtils;
@@ -137,7 +137,7 @@ public abstract class LinkerInputs {
* has a library identifier.
*/
public interface LibraryToLink extends LinkerInput {
- Iterable<Artifact> getLTOBitcodeFiles();
+ ImmutableMap<Artifact, Artifact> getLTOBitcodeFiles();
/**
* Return the identifier for the library. This is used for de-duplication of linker inputs: two
@@ -193,8 +193,8 @@ public abstract class LinkerInputs {
}
@Override
- public Iterable<Artifact> getLTOBitcodeFiles() {
- return ImmutableList.of();
+ public ImmutableMap<Artifact, Artifact> getLTOBitcodeFiles() {
+ return ImmutableMap.of();
}
@Override
@@ -244,14 +244,14 @@ public abstract class LinkerInputs {
private final ArtifactCategory category;
private final String libraryIdentifier;
private final Iterable<Artifact> objectFiles;
- private final Iterable<Artifact> ltoBitcodeFiles;
+ private final ImmutableMap<Artifact, Artifact> ltoBitcodeFiles;
private CompoundLibraryToLink(
Artifact libraryArtifact,
ArtifactCategory category,
String libraryIdentifier,
Iterable<Artifact> objectFiles,
- Iterable<Artifact> ltoBitcodeFiles) {
+ ImmutableMap<Artifact, Artifact> ltoBitcodeFiles) {
String basename = libraryArtifact.getFilename();
switch (category) {
case ALWAYSLINK_STATIC_LIBRARY:
@@ -275,9 +275,7 @@ public abstract class LinkerInputs {
this.libraryIdentifier = libraryIdentifier;
this.objectFiles = objectFiles == null ? null : CollectionUtils.makeImmutable(objectFiles);
this.ltoBitcodeFiles =
- (ltoBitcodeFiles == null)
- ? ImmutableList.<Artifact>of()
- : CollectionUtils.makeImmutable(ltoBitcodeFiles);
+ (ltoBitcodeFiles == null) ? ImmutableMap.<Artifact, Artifact>of() : ltoBitcodeFiles;
}
@Override
@@ -322,7 +320,7 @@ public abstract class LinkerInputs {
}
@Override
- public Iterable<Artifact> getLTOBitcodeFiles() {
+ public ImmutableMap<Artifact, Artifact> getLTOBitcodeFiles() {
return ltoBitcodeFiles;
}
@@ -420,12 +418,13 @@ public abstract class LinkerInputs {
return new CompoundLibraryToLink(artifact, category, libraryIdentifier, null, null);
}
- /**
- * Creates a library to link with the specified object files.
- */
+ /** Creates a library to link with the specified object files. */
public static LibraryToLink newInputLibrary(
- Artifact library, ArtifactCategory category, String libraryIdentifier,
- Iterable<Artifact> objectFiles, Iterable<Artifact> ltoBitcodeFiles) {
+ Artifact library,
+ ArtifactCategory category,
+ String libraryIdentifier,
+ Iterable<Artifact> objectFiles,
+ ImmutableMap<Artifact, Artifact> ltoBitcodeFiles) {
return new CompoundLibraryToLink(
library, category, libraryIdentifier, objectFiles, ltoBitcodeFiles);
}