Skip to content

Commit 7747d81

Browse files
committed
rebase
Created using spr 1.3.4
2 parents baac1a7 + be98428 commit 7747d81

26 files changed

+364
-204
lines changed

compiler-rt/lib/profile/InstrProfiling.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,17 @@ int __llvm_profile_get_padding_sizes_for_counters(
304304
*/
305305
void __llvm_profile_set_dumped(void);
306306

307+
/*!
308+
* \brief Write custom target-specific profiling data to a seperate file.
309+
* Used by offload PGO.
310+
*/
311+
int __llvm_write_custom_profile(const char *Target,
312+
const __llvm_profile_data *DataBegin,
313+
const __llvm_profile_data *DataEnd,
314+
const char *CountersBegin,
315+
const char *CountersEnd, const char *NamesBegin,
316+
const char *NamesEnd);
317+
307318
/*!
308319
* This variable is defined in InstrProfilingRuntime.cpp as a hidden
309320
* symbol. Its main purpose is to enable profile runtime user to

compiler-rt/lib/profile/InstrProfilingFile.c

Lines changed: 115 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,17 @@ static FILE *getFileObject(const char *OutputName) {
541541
return fopen(OutputName, "ab");
542542
}
543543

544+
static void closeFileObject(FILE *OutputFile) {
545+
if (OutputFile == getProfileFile()) {
546+
fflush(OutputFile);
547+
if (doMerging() && !__llvm_profile_is_continuous_mode_enabled()) {
548+
lprofUnlockFileHandle(OutputFile);
549+
}
550+
} else {
551+
fclose(OutputFile);
552+
}
553+
}
554+
544555
/* Write profile data to file \c OutputName. */
545556
static int writeFile(const char *OutputName) {
546557
int RetVal;
@@ -562,15 +573,7 @@ static int writeFile(const char *OutputName) {
562573
initFileWriter(&fileWriter, OutputFile);
563574
RetVal = lprofWriteData(&fileWriter, lprofGetVPDataReader(), MergeDone);
564575

565-
if (OutputFile == getProfileFile()) {
566-
fflush(OutputFile);
567-
if (doMerging() && !__llvm_profile_is_continuous_mode_enabled()) {
568-
lprofUnlockFileHandle(OutputFile);
569-
}
570-
} else {
571-
fclose(OutputFile);
572-
}
573-
576+
closeFileObject(OutputFile);
574577
return RetVal;
575578
}
576579

@@ -1359,4 +1362,107 @@ COMPILER_RT_VISIBILITY int __llvm_profile_set_file_object(FILE *File,
13591362
return 0;
13601363
}
13611364

1365+
int __llvm_write_custom_profile(const char *Target,
1366+
const __llvm_profile_data *DataBegin,
1367+
const __llvm_profile_data *DataEnd,
1368+
const char *CountersBegin,
1369+
const char *CountersEnd, const char *NamesBegin,
1370+
const char *NamesEnd) {
1371+
int ReturnValue = 0, FilenameLength, TargetLength;
1372+
char *FilenameBuf, *TargetFilename;
1373+
const char *Filename;
1374+
1375+
/* Save old profile data */
1376+
FILE *oldFile = getProfileFile();
1377+
1378+
// Temporarily suspend getting SIGKILL when the parent exits.
1379+
int PDeathSig = lprofSuspendSigKill();
1380+
1381+
if (lprofProfileDumped() || __llvm_profile_is_continuous_mode_enabled()) {
1382+
PROF_NOTE("Profile data not written to file: %s.\n", "already written");
1383+
if (PDeathSig == 1)
1384+
lprofRestoreSigKill();
1385+
return 0;
1386+
}
1387+
1388+
/* Check if there is llvm/runtime version mismatch. */
1389+
if (GET_VERSION(__llvm_profile_get_version()) != INSTR_PROF_RAW_VERSION) {
1390+
PROF_ERR("Runtime and instrumentation version mismatch : "
1391+
"expected %d, but get %d\n",
1392+
INSTR_PROF_RAW_VERSION,
1393+
(int)GET_VERSION(__llvm_profile_get_version()));
1394+
if (PDeathSig == 1)
1395+
lprofRestoreSigKill();
1396+
return -1;
1397+
}
1398+
1399+
/* Get current filename */
1400+
FilenameLength = getCurFilenameLength();
1401+
FilenameBuf = (char *)COMPILER_RT_ALLOCA(FilenameLength + 1);
1402+
Filename = getCurFilename(FilenameBuf, 0);
1403+
1404+
/* Check the filename. */
1405+
if (!Filename) {
1406+
PROF_ERR("Failed to write file : %s\n", "Filename not set");
1407+
if (PDeathSig == 1)
1408+
lprofRestoreSigKill();
1409+
return -1;
1410+
}
1411+
1412+
/* Allocate new space for our target-specific PGO filename */
1413+
TargetLength = strlen(Target);
1414+
TargetFilename =
1415+
(char *)COMPILER_RT_ALLOCA(FilenameLength + TargetLength + 2);
1416+
1417+
/* Find file basename and path sizes */
1418+
int32_t DirEnd = FilenameLength - 1;
1419+
while (DirEnd >= 0 && !IS_DIR_SEPARATOR(Filename[DirEnd])) {
1420+
DirEnd--;
1421+
}
1422+
uint32_t DirSize = DirEnd + 1, BaseSize = FilenameLength - DirSize;
1423+
1424+
/* Prepend "TARGET." to current filename */
1425+
if (DirSize > 0) {
1426+
memcpy(TargetFilename, Filename, DirSize);
1427+
}
1428+
memcpy(TargetFilename + DirSize, Target, TargetLength);
1429+
TargetFilename[TargetLength + DirSize] = '.';
1430+
memcpy(TargetFilename + DirSize + 1 + TargetLength, Filename + DirSize,
1431+
BaseSize);
1432+
TargetFilename[FilenameLength + 1 + TargetLength] = 0;
1433+
1434+
/* Open and truncate target-specific PGO file */
1435+
FILE *OutputFile = fopen(TargetFilename, "w");
1436+
setProfileFile(OutputFile);
1437+
1438+
if (!OutputFile) {
1439+
PROF_ERR("Failed to open file : %s\n", TargetFilename);
1440+
if (PDeathSig == 1)
1441+
lprofRestoreSigKill();
1442+
return -1;
1443+
}
1444+
1445+
FreeHook = &free;
1446+
setupIOBuffer();
1447+
1448+
/* Write custom data */
1449+
ProfDataWriter fileWriter;
1450+
initFileWriter(&fileWriter, OutputFile);
1451+
1452+
/* Write custom data to the file */
1453+
ReturnValue = lprofWriteDataImpl(
1454+
&fileWriter, DataBegin, DataEnd, CountersBegin, CountersEnd, NULL, NULL,
1455+
lprofGetVPDataReader(), NULL, NULL, NULL, NULL, NamesBegin, NamesEnd, 0);
1456+
closeFileObject(OutputFile);
1457+
1458+
// Restore SIGKILL.
1459+
if (PDeathSig == 1)
1460+
lprofRestoreSigKill();
1461+
1462+
/* Restore old profiling file */
1463+
setProfileFile(oldFile);
1464+
1465+
return ReturnValue;
1466+
}
1467+
13621468
#endif

llvm/include/llvm/MC/MCContext.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -527,13 +527,6 @@ class MCContext {
527527
/// \name Section Management
528528
/// @{
529529

530-
enum : unsigned {
531-
/// Pass this value as the UniqueID during section creation to get the
532-
/// generic section with the given name and characteristics. The usual
533-
/// sections such as .text use this ID.
534-
GenericSectionID = ~0U
535-
};
536-
537530
/// Return the MCSection for the specified mach-o section. This requires
538531
/// the operands to be valid.
539532
MCSectionMachO *getMachOSection(StringRef Segment, StringRef Section,
@@ -611,7 +604,7 @@ class MCContext {
611604

612605
MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics,
613606
StringRef COMDATSymName, int Selection,
614-
unsigned UniqueID = GenericSectionID);
607+
unsigned UniqueID = MCSection::NonUniqueID);
615608

616609
MCSectionCOFF *getCOFFSection(StringRef Section, unsigned Characteristics);
617610

@@ -621,7 +614,7 @@ class MCContext {
621614
/// as Sec and the function symbol as KeySym.
622615
MCSectionCOFF *
623616
getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym,
624-
unsigned UniqueID = GenericSectionID);
617+
unsigned UniqueID = MCSection::NonUniqueID);
625618

626619
MCSectionSPIRV *getSPIRVSection();
627620

llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,13 @@ struct ParseInstructionInfo {
122122
: AsmRewrites(rewrites) {}
123123
};
124124

125-
enum OperandMatchResultTy {
126-
MatchOperand_Success, // operand matched successfully
127-
MatchOperand_NoMatch, // operand did not match
128-
MatchOperand_ParseFail // operand matched but had errors
129-
};
130-
131125
/// Ternary parse status returned by various parse* methods.
132126
class ParseStatus {
133-
enum class StatusTy { Success, Failure, NoMatch } Status;
127+
enum class StatusTy {
128+
Success, // Parsing Succeeded
129+
Failure, // Parsing Failed after consuming some tokens
130+
NoMatch, // Parsing Failed without consuming any tokens
131+
} Status;
134132

135133
public:
136134
#if __cplusplus >= 202002L
@@ -152,19 +150,6 @@ class ParseStatus {
152150
constexpr bool isSuccess() const { return Status == StatusTy::Success; }
153151
constexpr bool isFailure() const { return Status == StatusTy::Failure; }
154152
constexpr bool isNoMatch() const { return Status == StatusTy::NoMatch; }
155-
156-
// Allow implicit conversions to / from OperandMatchResultTy.
157-
LLVM_DEPRECATED("Migrate to ParseStatus", "")
158-
constexpr ParseStatus(OperandMatchResultTy R)
159-
: Status(R == MatchOperand_Success ? Success
160-
: R == MatchOperand_ParseFail ? Failure
161-
: NoMatch) {}
162-
LLVM_DEPRECATED("Migrate to ParseStatus", "")
163-
constexpr operator OperandMatchResultTy() const {
164-
return isSuccess() ? MatchOperand_Success
165-
: isFailure() ? MatchOperand_ParseFail
166-
: MatchOperand_NoMatch;
167-
}
168153
};
169154

170155
enum class DiagnosticPredicateTy {

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
758758
if (!SupportsUnique) {
759759
Flags &= ~ELF::SHF_MERGE;
760760
EntrySize = 0;
761-
return MCContext::GenericSectionID;
761+
return MCSection::NonUniqueID;
762762
}
763763

764764
const bool SymbolMergeable = Flags & ELF::SHF_MERGE;
@@ -770,16 +770,16 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
770770
if (TM.getSeparateNamedSections())
771771
return NextUniqueID++;
772772
else
773-
return MCContext::GenericSectionID;
773+
return MCSection::NonUniqueID;
774774
}
775775

776776
// Symbols must be placed into sections with compatible entry sizes. Generate
777777
// unique sections for symbols that have not been assigned to compatible
778778
// sections.
779779
const auto PreviousID =
780780
Ctx.getELFUniqueIDForEntsize(SectionName, Flags, EntrySize);
781-
if (PreviousID && (!TM.getSeparateNamedSections() ||
782-
*PreviousID == MCContext::GenericSectionID))
781+
if (PreviousID &&
782+
(!TM.getSeparateNamedSections() || *PreviousID == MCSection::NonUniqueID))
783783
return *PreviousID;
784784

785785
// If the user has specified the same section name as would be created
@@ -791,7 +791,7 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
791791
if (SymbolMergeable &&
792792
Ctx.isELFImplicitMergeableSectionNamePrefix(SectionName) &&
793793
SectionName.starts_with(ImplicitSectionNameStem))
794-
return MCContext::GenericSectionID;
794+
return MCSection::NonUniqueID;
795795

796796
// We have seen this section name before, but with different flags or entity
797797
// size. Create a new unique ID.
@@ -903,7 +903,7 @@ static MCSectionELF *selectELFSectionForGlobal(
903903
unsigned EntrySize = getEntrySizeForKind(Kind);
904904

905905
bool UniqueSectionName = false;
906-
unsigned UniqueID = MCContext::GenericSectionID;
906+
unsigned UniqueID = MCSection::NonUniqueID;
907907
if (EmitUniqueSection) {
908908
if (TM.getUniqueSectionNames()) {
909909
UniqueSectionName = true;
@@ -1073,7 +1073,7 @@ MCSection *TargetLoweringObjectFileELF::getSectionForMachineBasicBlock(
10731073
const Function &F, const MachineBasicBlock &MBB,
10741074
const TargetMachine &TM) const {
10751075
assert(MBB.isBeginSection() && "Basic block does not start a section!");
1076-
unsigned UniqueID = MCContext::GenericSectionID;
1076+
unsigned UniqueID = MCSection::NonUniqueID;
10771077

10781078
// For cold sections use the .text.split. prefix along with the parent
10791079
// function name. All cold blocks for the same function go to the same
@@ -1774,7 +1774,7 @@ MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal(
17741774
else
17751775
ComdatGV = GO;
17761776

1777-
unsigned UniqueID = MCContext::GenericSectionID;
1777+
unsigned UniqueID = MCSection::NonUniqueID;
17781778
if (EmitUniquedSection)
17791779
UniqueID = NextUniqueID++;
17801780

@@ -2220,8 +2220,8 @@ MCSection *TargetLoweringObjectFileWasm::getExplicitSectionGlobal(
22202220
}
22212221

22222222
unsigned Flags = getWasmSectionFlags(Kind, Used.count(GO));
2223-
MCSectionWasm *Section = getContext().getWasmSection(
2224-
Name, Kind, Flags, Group, MCContext::GenericSectionID);
2223+
MCSectionWasm *Section = getContext().getWasmSection(Name, Kind, Flags, Group,
2224+
MCSection::NonUniqueID);
22252225

22262226
return Section;
22272227
}
@@ -2249,7 +2249,7 @@ selectWasmSectionForGlobal(MCContext &Ctx, const GlobalObject *GO,
22492249
Name.push_back('.');
22502250
TM.getNameWithPrefix(Name, GO, Mang, true);
22512251
}
2252-
unsigned UniqueID = MCContext::GenericSectionID;
2252+
unsigned UniqueID = MCSection::NonUniqueID;
22532253
if (EmitUniqueSection && !UniqueSectionNames) {
22542254
UniqueID = *NextUniqueID;
22552255
(*NextUniqueID)++;

llvm/lib/MC/MCContext.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ void MCContext::recordELFMergeableSectionInfo(StringRef SectionName,
636636
unsigned Flags, unsigned UniqueID,
637637
unsigned EntrySize) {
638638
bool IsMergeable = Flags & ELF::SHF_MERGE;
639-
if (UniqueID == GenericSectionID) {
639+
if (UniqueID == MCSection::NonUniqueID) {
640640
ELFSeenGenericMergeableSections.insert(SectionName);
641641
// Minor performance optimization: avoid hash map lookup in
642642
// isELFGenericMergeableSection, which will return true for SectionName.
@@ -727,14 +727,15 @@ MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
727727

728728
MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
729729
unsigned Characteristics) {
730-
return getCOFFSection(Section, Characteristics, "", 0, GenericSectionID);
730+
return getCOFFSection(Section, Characteristics, "", 0,
731+
MCSection::NonUniqueID);
731732
}
732733

733734
MCSectionCOFF *MCContext::getAssociativeCOFFSection(MCSectionCOFF *Sec,
734735
const MCSymbol *KeySym,
735736
unsigned UniqueID) {
736737
// Return the normal section if we don't have to be associative or unique.
737-
if (!KeySym && UniqueID == GenericSectionID)
738+
if (!KeySym && UniqueID == MCSection::NonUniqueID)
738739
return Sec;
739740

740741
// If we have a key symbol, make an associative section with the same name and

llvm/lib/MC/MCObjectFileInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,
10661066
utostr(Hash), /*IsComdat=*/true);
10671067
case Triple::Wasm:
10681068
return Ctx->getWasmSection(Name, SectionKind::getMetadata(), 0,
1069-
utostr(Hash), MCContext::GenericSectionID);
1069+
utostr(Hash), MCSection::NonUniqueID);
10701070
case Triple::MachO:
10711071
case Triple::COFF:
10721072
case Triple::GOFF:

llvm/lib/MC/MCParser/WasmAsmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class WasmAsmParser : public MCAsmParserExtension {
193193

194194
// TODO: Parse UniqueID
195195
MCSectionWasm *WS = getContext().getWasmSection(
196-
Name, *Kind, Flags, GroupName, MCContext::GenericSectionID);
196+
Name, *Kind, Flags, GroupName, MCSection::NonUniqueID);
197197

198198
if (WS->getSegmentFlags() != Flags)
199199
Parser->Error(loc, "changed section flags for " + Name +

llvm/lib/Target/AMDGPU/AMDGPU.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ extern char &GCNPreRAOptimizationsID;
460460
FunctionPass *createAMDGPUSetWavePriorityPass();
461461
void initializeAMDGPUSetWavePriorityPass(PassRegistry &);
462462

463-
void initializeGCNRewritePartialRegUsesPass(llvm::PassRegistry &);
463+
void initializeGCNRewritePartialRegUsesLegacyPass(llvm::PassRegistry &);
464464
extern char &GCNRewritePartialRegUsesID;
465465

466466
void initializeAMDGPUWaitSGPRHazardsLegacyPass(PassRegistry &);

llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ FUNCTION_PASS_WITH_PARAMS(
9898
#endif
9999
MACHINE_FUNCTION_PASS("amdgpu-isel", AMDGPUISelDAGToDAGPass(*this))
100100
MACHINE_FUNCTION_PASS("amdgpu-pre-ra-long-branch-reg", GCNPreRALongBranchRegPass())
101+
MACHINE_FUNCTION_PASS("amdgpu-rewrite-partial-reg-uses", GCNRewritePartialRegUsesPass())
101102
MACHINE_FUNCTION_PASS("amdgpu-pre-ra-optimizations", GCNPreRAOptimizationsPass())
102103
MACHINE_FUNCTION_PASS("gcn-dpp-combine", GCNDPPCombinePass())
103104
MACHINE_FUNCTION_PASS("si-fix-sgpr-copies", SIFixSGPRCopiesPass())
@@ -119,6 +120,7 @@ MACHINE_FUNCTION_PASS("si-wqm", SIWholeQuadModePass())
119120
#define DUMMY_MACHINE_FUNCTION_PASS(NAME, CREATE_PASS)
120121
DUMMY_MACHINE_FUNCTION_PASS("amdgpu-insert-delay-alu", AMDGPUInsertDelayAluPass())
121122
DUMMY_MACHINE_FUNCTION_PASS("amdgpu-nsa-reassign", GCNNSAReassignPass())
123+
DUMMY_MACHINE_FUNCTION_PASS("amdgpu-pre-ra-optimizations", GCNPreRAOptimizationsPass())
122124
DUMMY_MACHINE_FUNCTION_PASS("amdgpu-rewrite-partial-reg-uses", GCNRewritePartialRegUsesPass())
123125
DUMMY_MACHINE_FUNCTION_PASS("amdgpu-set-wave-priority", AMDGPUSetWavePriorityPass())
124126

0 commit comments

Comments
 (0)