Index: llvm/include/llvm/CodeGen/CommandFlags.inc =================================================================== --- llvm/include/llvm/CodeGen/CommandFlags.inc +++ llvm/include/llvm/CodeGen/CommandFlags.inc @@ -238,6 +238,12 @@ cl::desc("Emit functions into separate sections"), cl::init(false)); +static cl::opt + BBSections("basicblock-sections", + cl::desc("Emit basic blocks into separate sections"), + cl::value_desc("all | | none"), + cl::init("none")); + static cl::opt TLSSize("tls-size", cl::desc("Bit size of immediate TLS offsets"), cl::init(0)); @@ -251,6 +257,11 @@ cl::desc("Give unique names to every section"), cl::init(true)); +static cl::opt UniqueBBSectionNames( + "unique-bb-section-names", + cl::desc("Give unique names to every basic block section"), + cl::init(false)); + static cl::opt EABIVersion("meabi", cl::desc("Set EABI type (default depends on triple):"), cl::init(EABI::Default), @@ -285,6 +296,20 @@ cl::desc("Always emit a debug frame section."), cl::init(false)); +static llvm::BasicBlockSection::SectionMode +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 { + Options.BBSectionsFuncList = BBSections; + 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() { @@ -308,7 +333,9 @@ 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; Index: llvm/include/llvm/Target/TargetMachine.h =================================================================== --- llvm/include/llvm/Target/TargetMachine.h +++ llvm/include/llvm/Target/TargetMachine.h @@ -242,6 +242,9 @@ 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 { @@ -254,6 +257,18 @@ return Options.FunctionSections; } + /// If basic blocks should be emitted into their own section, + /// corresponding to -fbasicblock-sections. + llvm::BasicBlockSection::SectionMode getBBSectionsType() const { + return Options.BBSections; + } + + /// Get the file that contains the list of functions and basic block ids that + /// need unique sections. + std::string getBBSectionsFuncList() const { + return Options.BBSectionsFuncList; + } + /// Get a \c TargetIRAnalysis appropriate for the target. /// /// This is used to construct the new pass manager's target IR analysis pass, Index: llvm/include/llvm/Target/TargetOptions.h =================================================================== --- llvm/include/llvm/Target/TargetOptions.h +++ llvm/include/llvm/Target/TargetOptions.h @@ -63,6 +63,15 @@ }; } + namespace BasicBlockSection { + enum SectionMode { + None, // Do not use Basic Block Sections. + All, // Use Basic Block Sections for all functions. + Labels, // Do not use Basic Block Sections but label basic blocks. + List // Get list of functions & BBs from a file + }; + } + enum class EABI { Unknown, Default, // Default means not specified @@ -114,9 +123,9 @@ 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), EnableDebugEntryValues(false), ForceDwarfFrameSection(false) {} @@ -224,6 +233,9 @@ 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; @@ -256,6 +268,12 @@ /// Emit address-significance table. unsigned EmitAddrsig : 1; + /// Emit basic blocks into separate sections. + BasicBlockSection::SectionMode BBSections = BasicBlockSection::None; + + /// Profile file that contains information on sampled basic blocks. + std::string BBSectionsFuncList; + /// Emit debug info about parameter's entry values. unsigned EnableDebugEntryValues : 1;