cl::desc("Emit functions into separate sections"),
cl::init(false));
+static cl::opt<std::string>
+ BBSections("basicblock-sections",
+ cl::desc("Emit basic blocks into separate sections"),
+ cl::value_desc("all | <function list (file)> | labels | none"),
+ cl::init("none"));
+
static cl::opt<unsigned> TLSSize("tls-size",
cl::desc("Bit size of immediate TLS offsets"),
cl::init(0));
cl::desc("Give unique names to every section"),
cl::init(true));
+static cl::opt<bool> UniqueBBSectionNames(
+ "unique-bb-section-names",
+ cl::desc("Give unique names to every basic block section"),
+ cl::init(false));
+
static cl::opt<llvm::EABI>
EABIVersion("meabi", cl::desc("Set EABI type (default depends on triple):"),
cl::init(EABI::Default),
cl::desc("Always emit a debug frame section."),
cl::init(false));
+static llvm::BasicBlockSection
+getBBSectionsMode(llvm::TargetOptions &Options) {
+ if (BBSections == "all")
+ return BasicBlockSection::All;
+ else if (BBSections == "labels")
+ return BasicBlockSection::Labels;
+ else if (BBSections == "none")
+ return BasicBlockSection::None;
+ else {
+ ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
+ MemoryBuffer::getFile(BBSections);
+ if (!MBOrErr) {
+ errs() << "Error loading basic block sections function list file: "
+ << MBOrErr.getError().message() << "\n";
+ } else {
+ Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
+ }
+ return BasicBlockSection::List;
+ }
+}
+
// Common utility function tightly tied to the options listed here. Initializes
// a TargetOptions object with CodeGen flags and returns it.
static TargetOptions InitTargetOptionsFromCodeGenFlags() {
Options.RelaxELFRelocations = RelaxELFRelocations;
Options.DataSections = DataSections;
Options.FunctionSections = FunctionSections;
+ Options.BBSections = getBBSectionsMode(Options);
Options.UniqueSectionNames = UniqueSectionNames;
+ Options.UniqueBBSectionNames = UniqueBBSectionNames;
Options.TLSSize = TLSSize;
Options.EmulatedTLS = EmulatedTLS;
Options.ExplicitEmulatedTLS = EmulatedTLS.getNumOccurrences() > 0;
bool getUniqueSectionNames() const { return Options.UniqueSectionNames; }
+ /// Return true if unique basic block section names must be generated.
+ bool getUniqueBBSectionNames() const { return Options.UniqueBBSectionNames; }
+
/// Return true if data objects should be emitted into their own section,
/// corresponds to -fdata-sections.
bool getDataSections() const {
return Options.FunctionSections;
}
+ /// If basic blocks should be emitted into their own section,
+ /// corresponding to -fbasicblock-sections.
+ llvm::BasicBlockSection getBBSectionsType() const {
+ return Options.BBSections;
+ }
+
+ /// Get the list of functions and basic block ids that need unique sections.
+ const MemoryBuffer *getBBSectionsFuncListBuf() const {
+ return Options.BBSectionsFuncListBuf.get();
+ }
+
/// Get a \c TargetIRAnalysis appropriate for the target.
///
/// This is used to construct the new pass manager's target IR analysis pass,
#include "llvm/MC/MCTargetOptions.h"
+#include <memory>
+
namespace llvm {
class MachineFunction;
+ class MemoryBuffer;
class Module;
namespace FloatABI {
};
}
+ enum class BasicBlockSection {
+ All, // Use Basic Block Sections for all basic blocks. A section
+ // for every basic block can significantly bloat object file sizes.
+ List, // Get list of functions & BBs from a file. Selectively enables
+ // basic block sections for a subset of basic blocks which can be
+ // used to control object size bloats from creating sections.
+ Labels, // Do not use Basic Block Sections but label basic blocks. This
+ // is useful when associating profile counts from virtual addresses
+ // to basic blocks.
+ None // Do not use Basic Block Sections.
+ };
+
enum class EABI {
Unknown,
Default, // Default means not specified
EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false),
DisableIntegratedAS(false), RelaxELFRelocations(false),
FunctionSections(false), DataSections(false),
- UniqueSectionNames(true), TrapUnreachable(false),
- NoTrapAfterNoreturn(false), TLSSize(0), EmulatedTLS(false),
- ExplicitEmulatedTLS(false), EnableIPRA(false),
+ UniqueSectionNames(true), UniqueBBSectionNames(false),
+ TrapUnreachable(false), NoTrapAfterNoreturn(false), TLSSize(0),
+ EmulatedTLS(false), ExplicitEmulatedTLS(false), EnableIPRA(false),
EmitStackSizeSection(false), EnableMachineOutliner(false),
SupportsDefaultOutlining(false), EmitAddrsig(false),
EmitCallSiteInfo(false), EnableDebugEntryValues(false),
unsigned UniqueSectionNames : 1;
+ /// Use unique names for basic block sections.
+ unsigned UniqueBBSectionNames : 1;
+
/// Emit target-specific trap instruction for 'unreachable' IR instructions.
unsigned TrapUnreachable : 1;
/// Emit address-significance table.
unsigned EmitAddrsig : 1;
+ /// Emit basic blocks into separate sections.
+ BasicBlockSection BBSections = BasicBlockSection::None;
+
+ /// Memory Buffer that contains information on sampled basic blocks and used
+ /// to selectively generate basic block sections.
+ std::shared_ptr<MemoryBuffer> BBSectionsFuncListBuf;
+
/// The flag enables call site info production. It is used only for debug
/// info, and it is restricted only to optimized code. This can be used for
/// something else, so that should be controlled in the frontend.